Comparing version 5.1.0 to 5.2.0
@@ -5,2 +5,8 @@ # Changelog | ||
## [5.2.0] 2021-03-01 | ||
### Fixed | ||
- Unbundling ES code to facilitate code-splitting in Webpack. | ||
## [5.1.0] 2021-02-22 | ||
@@ -7,0 +13,0 @@ |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = global || self, factory(global.framesync = {})); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.framesync = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
var defaultTimestep = (1 / 60) * 1000; | ||
var getCurrentTime = typeof performance !== "undefined" | ||
? function () { return performance.now(); } | ||
: function () { return Date.now(); }; | ||
var onNextFrame = typeof window !== "undefined" | ||
? function (callback) { | ||
return window.requestAnimationFrame(callback); | ||
} | ||
: function (callback) { | ||
return setTimeout(function () { return callback(getCurrentTime()); }, defaultTimestep); | ||
}; | ||
var defaultTimestep = (1 / 60) * 1000; | ||
var getCurrentTime = typeof performance !== "undefined" | ||
? function () { return performance.now(); } | ||
: function () { return Date.now(); }; | ||
var onNextFrame = typeof window !== "undefined" | ||
? function (callback) { | ||
return window.requestAnimationFrame(callback); | ||
} | ||
: function (callback) { | ||
return setTimeout(function () { return callback(getCurrentTime()); }, defaultTimestep); | ||
}; | ||
function createRenderStep(runNextFrame) { | ||
var toRun = []; | ||
var toRunNextFrame = []; | ||
var numToRun = 0; | ||
var isProcessing = false; | ||
var toKeepAlive = new WeakSet(); | ||
var step = { | ||
schedule: function (callback, keepAlive, immediate) { | ||
if (keepAlive === void 0) { keepAlive = false; } | ||
if (immediate === void 0) { immediate = false; } | ||
var addToCurrentFrame = immediate && isProcessing; | ||
var buffer = addToCurrentFrame ? toRun : toRunNextFrame; | ||
if (keepAlive) | ||
toKeepAlive.add(callback); | ||
if (buffer.indexOf(callback) === -1) { | ||
buffer.push(callback); | ||
if (addToCurrentFrame && isProcessing) | ||
numToRun = toRun.length; | ||
} | ||
return callback; | ||
}, | ||
cancel: function (callback) { | ||
var index = toRunNextFrame.indexOf(callback); | ||
if (index !== -1) | ||
toRunNextFrame.splice(index, 1); | ||
toKeepAlive.delete(callback); | ||
}, | ||
process: function (frameData) { | ||
var _a; | ||
isProcessing = true; | ||
_a = [toRunNextFrame, toRun], toRun = _a[0], toRunNextFrame = _a[1]; | ||
toRunNextFrame.length = 0; | ||
numToRun = toRun.length; | ||
if (numToRun) { | ||
for (var i = 0; i < numToRun; i++) { | ||
var callback = toRun[i]; | ||
callback(frameData); | ||
if (toKeepAlive.has(callback)) { | ||
step.schedule(callback); | ||
runNextFrame(); | ||
} | ||
} | ||
} | ||
isProcessing = false; | ||
}, | ||
}; | ||
return step; | ||
} | ||
function createRenderStep(runNextFrame) { | ||
var toRun = []; | ||
var toRunNextFrame = []; | ||
var numToRun = 0; | ||
var isProcessing = false; | ||
var toKeepAlive = new WeakSet(); | ||
var step = { | ||
schedule: function (callback, keepAlive, immediate) { | ||
if (keepAlive === void 0) { keepAlive = false; } | ||
if (immediate === void 0) { immediate = false; } | ||
var addToCurrentFrame = immediate && isProcessing; | ||
var buffer = addToCurrentFrame ? toRun : toRunNextFrame; | ||
if (keepAlive) | ||
toKeepAlive.add(callback); | ||
if (buffer.indexOf(callback) === -1) { | ||
buffer.push(callback); | ||
if (addToCurrentFrame && isProcessing) | ||
numToRun = toRun.length; | ||
} | ||
return callback; | ||
}, | ||
cancel: function (callback) { | ||
var index = toRunNextFrame.indexOf(callback); | ||
if (index !== -1) | ||
toRunNextFrame.splice(index, 1); | ||
toKeepAlive.delete(callback); | ||
}, | ||
process: function (frameData) { | ||
var _a; | ||
isProcessing = true; | ||
_a = [toRunNextFrame, toRun], toRun = _a[0], toRunNextFrame = _a[1]; | ||
toRunNextFrame.length = 0; | ||
numToRun = toRun.length; | ||
if (numToRun) { | ||
for (var i = 0; i < numToRun; i++) { | ||
var callback = toRun[i]; | ||
callback(frameData); | ||
if (toKeepAlive.has(callback)) { | ||
step.schedule(callback); | ||
runNextFrame(); | ||
} | ||
} | ||
} | ||
isProcessing = false; | ||
}, | ||
}; | ||
return step; | ||
} | ||
var maxElapsed = 40; | ||
var useDefaultElapsed = true; | ||
var runNextFrame = false; | ||
var isProcessing = false; | ||
var frame = { | ||
delta: 0, | ||
timestamp: 0, | ||
}; | ||
var stepsOrder = [ | ||
"read", | ||
"update", | ||
"preRender", | ||
"render", | ||
"postRender", | ||
]; | ||
var steps = stepsOrder.reduce(function (acc, key) { | ||
acc[key] = createRenderStep(function () { return (runNextFrame = true); }); | ||
return acc; | ||
}, {}); | ||
var sync = stepsOrder.reduce(function (acc, key) { | ||
var step = steps[key]; | ||
acc[key] = function (process, keepAlive, immediate) { | ||
if (keepAlive === void 0) { keepAlive = false; } | ||
if (immediate === void 0) { immediate = false; } | ||
if (!runNextFrame) | ||
startLoop(); | ||
return step.schedule(process, keepAlive, immediate); | ||
}; | ||
return acc; | ||
}, {}); | ||
var cancelSync = stepsOrder.reduce(function (acc, key) { | ||
acc[key] = steps[key].cancel; | ||
return acc; | ||
}, {}); | ||
var processStep = function (stepId) { return steps[stepId].process(frame); }; | ||
var processFrame = function (timestamp) { | ||
runNextFrame = false; | ||
frame.delta = useDefaultElapsed | ||
? defaultTimestep | ||
: Math.max(Math.min(timestamp - frame.timestamp, maxElapsed), 1); | ||
frame.timestamp = timestamp; | ||
isProcessing = true; | ||
stepsOrder.forEach(processStep); | ||
isProcessing = false; | ||
if (runNextFrame) { | ||
useDefaultElapsed = false; | ||
onNextFrame(processFrame); | ||
} | ||
}; | ||
var startLoop = function () { | ||
runNextFrame = true; | ||
useDefaultElapsed = true; | ||
if (!isProcessing) | ||
onNextFrame(processFrame); | ||
}; | ||
var getFrameData = function () { return frame; }; | ||
var maxElapsed = 40; | ||
var useDefaultElapsed = true; | ||
var runNextFrame = false; | ||
var isProcessing = false; | ||
var frame = { | ||
delta: 0, | ||
timestamp: 0, | ||
}; | ||
var stepsOrder = [ | ||
"read", | ||
"update", | ||
"preRender", | ||
"render", | ||
"postRender", | ||
]; | ||
var steps = stepsOrder.reduce(function (acc, key) { | ||
acc[key] = createRenderStep(function () { return (runNextFrame = true); }); | ||
return acc; | ||
}, {}); | ||
var sync = stepsOrder.reduce(function (acc, key) { | ||
var step = steps[key]; | ||
acc[key] = function (process, keepAlive, immediate) { | ||
if (keepAlive === void 0) { keepAlive = false; } | ||
if (immediate === void 0) { immediate = false; } | ||
if (!runNextFrame) | ||
startLoop(); | ||
return step.schedule(process, keepAlive, immediate); | ||
}; | ||
return acc; | ||
}, {}); | ||
var cancelSync = stepsOrder.reduce(function (acc, key) { | ||
acc[key] = steps[key].cancel; | ||
return acc; | ||
}, {}); | ||
var processStep = function (stepId) { return steps[stepId].process(frame); }; | ||
var processFrame = function (timestamp) { | ||
runNextFrame = false; | ||
frame.delta = useDefaultElapsed | ||
? defaultTimestep | ||
: Math.max(Math.min(timestamp - frame.timestamp, maxElapsed), 1); | ||
frame.timestamp = timestamp; | ||
isProcessing = true; | ||
stepsOrder.forEach(processStep); | ||
isProcessing = false; | ||
if (runNextFrame) { | ||
useDefaultElapsed = false; | ||
onNextFrame(processFrame); | ||
} | ||
}; | ||
var startLoop = function () { | ||
runNextFrame = true; | ||
useDefaultElapsed = true; | ||
if (!isProcessing) | ||
onNextFrame(processFrame); | ||
}; | ||
var getFrameData = function () { return frame; }; | ||
exports.cancelSync = cancelSync; | ||
exports.default = sync; | ||
exports.getFrameData = getFrameData; | ||
exports.cancelSync = cancelSync; | ||
exports.default = sync; | ||
exports.getFrameData = getFrameData; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); |
@@ -1,1 +0,1 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e=e||self).framesync={})}(this,function(e){"use strict";var n=1/60*1e3,t="undefined"!=typeof performance?function(){return performance.now()}:function(){return Date.now()},r="undefined"!=typeof window?function(e){return window.requestAnimationFrame(e)}:function(e){return setTimeout(function(){return e(t())},n)};function u(e){return a[e].process(c)}var o=!0,s=!1,i=!1,c={delta:0,timestamp:0},f=["read","update","preRender","render","postRender"],a=f.reduce(function(e,n){var u,o,i,c,f,a,d;return e[n]=(u=function(){return s=!0},o=[],c=0,f=!(i=[]),a=new WeakSet,d={schedule:function(e,n,t){void 0===n&&(n=!1),void 0===t&&(t=!1);var r=t&&f,t=r?o:i;return n&&a.add(e),-1===t.indexOf(e)&&(t.push(e),r&&f&&(c=o.length)),e},cancel:function(e){var n=i.indexOf(e);-1!==n&&i.splice(n,1),a.delete(e)},process:function(e){var n;if(f=!0,o=(n=[i,o])[0],(i=n[1]).length=0,c=o.length)for(var t=0;t<c;t++){var r=o[t];r(e),a.has(r)&&(d.schedule(r),u())}f=!1}}),e},{}),d=f.reduce(function(e,n){var r=a[n];return e[n]=function(e,n,t){return void 0===n&&(n=!1),void 0===t&&(t=!1),s||m(),r.schedule(e,n,t)},e},{}),p=f.reduce(function(e,n){return e[n]=a[n].cancel,e},{}),l=function(e){s=!1,c.delta=o?n:Math.max(Math.min(e-c.timestamp,40),1),c.timestamp=e,i=!0,f.forEach(u),i=!1,s&&(o=!1,r(l))},m=function(){o=s=!0,i||r(l)};e.cancelSync=p,e.default=d,e.getFrameData=function(){return c},Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).framesync={})}(this,(function(e){"use strict";var n=1/60*1e3,t="undefined"!=typeof performance?function(){return performance.now()}:function(){return Date.now()},r="undefined"!=typeof window?function(e){return window.requestAnimationFrame(e)}:function(e){return setTimeout((function(){return e(t())}),n)};var u=!0,o=!1,i=!1,f={delta:0,timestamp:0},c=["read","update","preRender","render","postRender"],a=c.reduce((function(e,n){return e[n]=function(e){var n=[],t=[],r=0,u=!1,o=new WeakSet,i={schedule:function(e,i,f){void 0===i&&(i=!1),void 0===f&&(f=!1);var c=f&&u,a=c?n:t;return i&&o.add(e),-1===a.indexOf(e)&&(a.push(e),c&&u&&(r=n.length)),e},cancel:function(e){var n=t.indexOf(e);-1!==n&&t.splice(n,1),o.delete(e)},process:function(f){var c;if(u=!0,n=(c=[t,n])[0],(t=c[1]).length=0,r=n.length)for(var a=0;a<r;a++){var d=n[a];d(f),o.has(d)&&(i.schedule(d),e())}u=!1}};return i}((function(){return o=!0})),e}),{}),d=c.reduce((function(e,n){var t=a[n];return e[n]=function(e,n,r){return void 0===n&&(n=!1),void 0===r&&(r=!1),o||m(),t.schedule(e,n,r)},e}),{}),s=c.reduce((function(e,n){return e[n]=a[n].cancel,e}),{}),l=function(e){return a[e].process(f)},p=function(e){o=!1,f.delta=u?n:Math.max(Math.min(e-f.timestamp,40),1),f.timestamp=e,i=!0,c.forEach(l),i=!1,o&&(u=!1,r(p))},m=function(){o=!0,u=!0,i||r(p)};e.cancelSync=s,e.default=d,e.getFrameData=function(){return f},Object.defineProperty(e,"__esModule",{value:!0})})); |
@@ -0,0 +0,0 @@ 'use strict'; |
{ | ||
"name": "framesync", | ||
"version": "5.1.0", | ||
"version": "5.2.0", | ||
"description": "A frame-synced render loop for JavaScript", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"module": "dist/framesync.es.js", | ||
"jsnext:main": "dist/framesync.es.js", | ||
"module": "dist/es/index.js", | ||
"jsnext:main": "dist/es/index.js", | ||
"unpkg": "./dist/framesync.min.js", | ||
"scripts": { | ||
"build": "rollup -c && tsc --emitDeclarationOnly && yarn measure", | ||
"build": "tsc -p . && rollup -c && yarn measure", | ||
"postbuild": "babel $npm_package_module --out-file $npm_package_module --no-babelrc --plugins annotate-pure-calls", | ||
@@ -13,0 +13,0 @@ "watch": "rollup -c -w", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44550
30
752