Skip to content

Commit

Permalink
port to ES modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Oct 8, 2016
1 parent 39d2763 commit a54c77a
Show file tree
Hide file tree
Showing 31 changed files with 126 additions and 126 deletions.
2 changes: 1 addition & 1 deletion lib/attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function AttributeRecord () {
this.divisor = 0
}

module.exports = function wrapAttributeState (
export default function wrapAttributeState (
gl,
extensions,
limits,
Expand Down
20 changes: 10 additions & 10 deletions lib/buffer.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
var check = require('./util/check')
var isTypedArray = require('./util/is-typed-array')
var isNDArrayLike = require('./util/is-ndarray')
var values = require('./util/values')
var pool = require('./util/pool')
var flattenUtil = require('./util/flatten')
import check from './util/check'
import isTypedArray from './util/is-typed-array'
import isNDArrayLike from './util/is-ndarray'
import values from './util/values'
import * as pool from './util/pool'
import flattenUtil from './util/flatten'

var arrayFlatten = flattenUtil.flatten
var arrayShape = flattenUtil.shape

var arrayTypes = require('./constants/arraytypes.json')
var bufferTypes = require('./constants/dtypes.json')
var usageTypes = require('./constants/usage.json')
import arrayTypes from './constants/arraytypes.json'
import bufferTypes from './constants/dtypes.json'
import usageTypes from './constants/usage.json'

var GL_STATIC_DRAW = 0x88E4
var GL_STREAM_DRAW = 0x88E0
Expand Down Expand Up @@ -47,7 +47,7 @@ function transpose (
}
}

module.exports = function wrapBufferState (gl, stats, config) {
export default function wrapBufferState (gl, stats, config) {
var bufferCount = 0
var bufferSet = {}

Expand Down
20 changes: 10 additions & 10 deletions lib/core.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
var check = require('./util/check')
var createEnvironment = require('./util/codegen')
var loop = require('./util/loop')
var isTypedArray = require('./util/is-typed-array')
var isNDArray = require('./util/is-ndarray')
var isArrayLike = require('./util/is-array-like')
var dynamic = require('./dynamic')
import check from './util/check'
import createEnvironment from './util/codegen'
import loop from './util/loop'
import isTypedArray from './util/is-typed-array'
import isNDArray from './util/is-ndarray'
import isArrayLike from './util/is-array-like'
import * as dynamic from './dynamic'

var primTypes = require('./constants/primitives.json')
var glTypes = require('./constants/dtypes.json')
import primTypes from './constants/primitives.json'
import glTypes from './constants/dtypes.json'

// "cute" names for vector components
var CUTE_COMPONENTS = 'xyzw'.split('')
Expand Down Expand Up @@ -276,7 +276,7 @@ function createDynamicDecl (dyn, append) {

var SCOPE_DECL = new Declaration(false, false, false, function () {})

module.exports = function reglCore (
export default function reglCore (
gl,
stringStore,
extensions,
Expand Down
12 changes: 6 additions & 6 deletions lib/dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ function unbox (x, path) {
return x
}

module.exports = {
DynamicVariable: DynamicVariable,
define: defineDynamic,
isDynamic: isDynamic,
unbox: unbox,
accessor: toAccessorString
export {
DynamicVariable,
defineDynamic as define,
isDynamic,
unbox,
toAccessorString as accessor
}
14 changes: 7 additions & 7 deletions lib/elements.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var check = require('./util/check')
var isTypedArray = require('./util/is-typed-array')
var isNDArrayLike = require('./util/is-ndarray')
var values = require('./util/values')
import check from './util/check'
import isTypedArray from './util/is-typed-array'
import isNDArrayLike from './util/is-ndarray'
import values from './util/values'

var primTypes = require('./constants/primitives.json')
var usageTypes = require('./constants/usage.json')
import primTypes from './constants/primitives.json'
import usageTypes from './constants/usage.json'

var GL_POINTS = 0
var GL_LINES = 1
Expand All @@ -22,7 +22,7 @@ var GL_ELEMENT_ARRAY_BUFFER = 34963
var GL_STREAM_DRAW = 0x88E0
var GL_STATIC_DRAW = 0x88E4

module.exports = function wrapElementsState (gl, extensions, bufferState, stats) {
export default function wrapElementsState (gl, extensions, bufferState, stats) {
var elementSet = {}
var elementCount = 0

Expand Down
4 changes: 2 additions & 2 deletions lib/extension.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var check = require('./util/check')
import check from './util/check'

module.exports = function createExtensionCache (gl, config) {
export default function createExtensionCache (gl, config) {
var extensions = {}

function tryLoadExtension (name_) {
Expand Down
8 changes: 4 additions & 4 deletions lib/framebuffer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var check = require('./util/check')
var values = require('./util/values')
var extend = require('./util/extend')
import check from './util/check'
import values from './util/values'
import extend from './util/extend'

// We store these constants so that the minifier can inline them
var GL_FRAMEBUFFER = 0x8D40
Expand Down Expand Up @@ -75,7 +75,7 @@ statusCode[GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS] = 'incomplete dimensions'
statusCode[GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT] = 'incomplete, missing attachment'
statusCode[GL_FRAMEBUFFER_UNSUPPORTED] = 'unsupported'

module.exports = function wrapFBOState (
export default function wrapFBOState (
gl,
extensions,
limits,
Expand Down
2 changes: 1 addition & 1 deletion lib/limits.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT = 0x84FF
var GL_MAX_COLOR_ATTACHMENTS_WEBGL = 0x8CDF
var GL_MAX_DRAW_BUFFERS_WEBGL = 0x8824

module.exports = function (gl, extensions) {
export default function limits (gl, extensions) {
var maxAnisotropic = 1
if (extensions.ext_texture_filter_anisotropic) {
maxAnisotropic = gl.getParameter(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT)
Expand Down
6 changes: 3 additions & 3 deletions lib/read.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
var check = require('./util/check')
var isTypedArray = require('./util/is-typed-array')
import check from './util/check'
import isTypedArray from './util/is-typed-array'

var GL_RGBA = 6408
var GL_UNSIGNED_BYTE = 5121
var GL_PACK_ALIGNMENT = 0x0D05
var GL_FLOAT = 0x1406 // 5126

module.exports = function wrapReadPixels (
export default function wrapReadPixels (
gl,
framebufferState,
reglPoll,
Expand Down
6 changes: 3 additions & 3 deletions lib/renderbuffer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var check = require('./util/check')
var values = require('./util/values')
import check from './util/check'
import values from './util/values'

var GL_RENDERBUFFER = 0x8D41

Expand Down Expand Up @@ -36,7 +36,7 @@ function getRenderbufferSize (format, width, height) {
return FORMAT_SIZES[format] * width * height
}

module.exports = function (gl, extensions, limits, stats, config) {
export default function (gl, extensions, limits, stats, config) {
var formatTypes = {
'rgba4': GL_RGBA4,
'rgb565': GL_RGB565,
Expand Down
6 changes: 3 additions & 3 deletions lib/shader.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
var check = require('./util/check')
var values = require('./util/values')
import check from './util/check'
import values from './util/values'

var GL_FRAGMENT_SHADER = 35632
var GL_VERTEX_SHADER = 35633

var GL_ACTIVE_UNIFORMS = 0x8B86
var GL_ACTIVE_ATTRIBUTES = 0x8B89

module.exports = function wrapShaderState (gl, stringStore, stats, config) {
export default function wrapShaderState (gl, stringStore, stats, config) {
// ===================================================
// glsl compilation and linking
// ===================================================
Expand Down
3 changes: 1 addition & 2 deletions lib/stats.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

module.exports = function stats () {
export default function stats () {
return {
bufferCount: 0,
elementsCount: 0,
Expand Down
2 changes: 1 addition & 1 deletion lib/strings.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function createStringStore () {
export default function createStringStore () {
var stringIds = {'': 0}
var stringValues = ['']
return {
Expand Down
26 changes: 13 additions & 13 deletions lib/texture.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
var check = require('./util/check')
var extend = require('./util/extend')
var values = require('./util/values')
var isTypedArray = require('./util/is-typed-array')
var isNDArrayLike = require('./util/is-ndarray')
var pool = require('./util/pool')
var convertToHalfFloat = require('./util/to-half-float')
var isArrayLike = require('./util/is-array-like')
var flattenUtils = require('./util/flatten')

var dtypes = require('./constants/arraytypes.json')
var arrayTypes = require('./constants/arraytypes.json')
import check from './util/check'
import extend from './util/extend'
import values from './util/values'
import isTypedArray from './util/is-typed-array'
import isNDArrayLike from './util/is-ndarray'
import * as pool from './util/pool'
import convertToHalfFloat from './util/to-half-float'
import isArrayLike from './util/is-array-like'
import flattenUtils from './util/flatten'

import dtypes from './constants/arraytypes.json'
import arrayTypes from './constants/arraytypes.json'

var GL_COMPRESSED_TEXTURE_FORMATS = 0x86A3

Expand Down Expand Up @@ -317,7 +317,7 @@ function getTextureSize (format, type, width, height, isMipmap, isCube) {
}
}

module.exports = function createTextureSet (
export default function createTextureSet (
gl, extensions, limits, reglPoll, contextState, stats, config) {
// -------------------------------------------------------
// Initialize constants and parameter tables here
Expand Down
2 changes: 1 addition & 1 deletion lib/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var GL_QUERY_RESULT_EXT = 0x8866
var GL_QUERY_RESULT_AVAILABLE_EXT = 0x8867
var GL_TIME_ELAPSED_EXT = 0x88BF

module.exports = function (gl, extensions) {
export default function timer (gl, extensions) {
var extTimer = extensions.ext_disjoint_timer_query

if (!extTimer) {
Expand Down
6 changes: 3 additions & 3 deletions lib/util/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// a browserify transform for optimized/minified bundles.
//
/* globals btoa */
var isTypedArray = require('./is-typed-array')
var extend = require('./extend')
import isTypedArray from './is-typed-array'
import extend from './extend'

// only used for extracting shader names. if btoa not present, then errors
// will be slightly crappier
Expand Down Expand Up @@ -613,7 +613,7 @@ function checkTextureCube (texture, info, faces, limits) {
}
}

module.exports = extend(check, {
export default extend(check, {
optional: checkOptional,
raise: raise,
commandRaise: commandRaise,
Expand Down
2 changes: 1 addition & 1 deletion lib/util/clock.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* globals performance */
module.exports =
export default
(typeof performance !== 'undefined' && performance.now)
? function () { return performance.now() }
: function () { return +(new Date()) }
4 changes: 2 additions & 2 deletions lib/util/codegen.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var extend = require('./extend')
import extend from './extend'

function slice (x) {
return Array.prototype.slice.call(x)
Expand All @@ -8,7 +8,7 @@ function join (x) {
return slice(x).join('')
}

module.exports = function createEnvironment () {
export default function createEnvironment () {
// Unique variable id counter
var varCounter = 0

Expand Down
2 changes: 1 addition & 1 deletion lib/util/extend.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function (base, opts) {
export default function extend (base, opts) {
var keys = Object.keys(opts)
for (var i = 0; i < keys.length; ++i) {
base[keys[i]] = opts[keys[i]]
Expand Down
4 changes: 2 additions & 2 deletions lib/util/flatten.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var pool = require('./pool')
import * as pool from './pool'

module.exports = {
export default {
shape: arrayShape,
flatten: flattenArray
}
Expand Down
4 changes: 2 additions & 2 deletions lib/util/is-array-like.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var isTypedArray = require('./is-typed-array')
module.exports = function isArrayLike (s) {
import isTypedArray from './is-typed-array'
export default function isArrayLike (s) {
return Array.isArray(s) || isTypedArray(s)
}
4 changes: 2 additions & 2 deletions lib/util/is-ndarray.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var isTypedArray = require('./is-typed-array')
import isTypedArray from './is-typed-array'

module.exports = function isNDArrayLike (obj) {
export default function isNDArrayLike (obj) {
return (
!!obj &&
typeof obj === 'object' &&
Expand Down
4 changes: 2 additions & 2 deletions lib/util/is-typed-array.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var dtypes = require('../constants/arraytypes.json')
module.exports = function (x) {
import dtypes from '../constants/arraytypes.json'
export default function (x) {
return Object.prototype.toString.call(x) in dtypes
}
2 changes: 1 addition & 1 deletion lib/util/loop.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function loop (n, f) {
export default function loop (n, f) {
var result = Array(n)
for (var i = 0; i < n; ++i) {
result[i] = f(i)
Expand Down
12 changes: 6 additions & 6 deletions lib/util/pool.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var loop = require('./loop')
import loop from './loop'

var GL_BYTE = 5120
var GL_UNSIGNED_BYTE = 5121
Expand Down Expand Up @@ -84,9 +84,9 @@ function freeType (array) {
free(array.buffer)
}

module.exports = {
alloc: alloc,
free: free,
allocType: allocType,
freeType: freeType
export {
alloc,
free,
allocType,
freeType
}
8 changes: 6 additions & 2 deletions lib/util/raf.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
let raf;

/* globals requestAnimationFrame, cancelAnimationFrame */
if (typeof requestAnimationFrame === 'function' &&
typeof cancelAnimationFrame === 'function') {
module.exports = {
raf = {
next: function (x) { return requestAnimationFrame(x) },
cancel: function (x) { return cancelAnimationFrame(x) }
}
} else {
module.exports = {
raf = {
next: function (cb) {
return setTimeout(cb, 16)
},
cancel: clearTimeout
}
}

export default raf;
Loading

0 comments on commit a54c77a

Please sign in to comment.