glitch-canvas-browser
Advanced tools
Comparing version 1.1.7 to 1.1.8
@@ -347,10 +347,11 @@ (function (global, factory) { | ||
* See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE | ||
* @version 4.1.0 | ||
* @version v4.2.8+1e68dce6 | ||
*/ | ||
(function (global, factory) { | ||
module.exports = factory() ; | ||
module.exports = factory() ; | ||
}(commonjsGlobal, (function () { | ||
function objectOrFunction(x) { | ||
return typeof x === 'function' || typeof x === 'object' && x !== null; | ||
var type = typeof x; | ||
return x !== null && (type === 'object' || type === 'function'); | ||
} | ||
@@ -362,9 +363,11 @@ | ||
var _isArray = undefined; | ||
if (!Array.isArray) { | ||
var _isArray = void 0; | ||
if (Array.isArray) { | ||
_isArray = Array.isArray; | ||
} else { | ||
_isArray = function (x) { | ||
return Object.prototype.toString.call(x) === '[object Array]'; | ||
}; | ||
} else { | ||
_isArray = Array.isArray; | ||
} | ||
@@ -375,4 +378,4 @@ | ||
var len = 0; | ||
var vertxNext = undefined; | ||
var customSchedulerFn = undefined; | ||
var vertxNext = void 0; | ||
var customSchedulerFn = void 0; | ||
@@ -406,3 +409,3 @@ var asap = function asap(callback, arg) { | ||
var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver; | ||
var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && ({}).toString.call(process) === '[object process]'; | ||
var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && {}.toString.call(process) === '[object process]'; | ||
@@ -478,4 +481,3 @@ // test for web worker but not in IE10 | ||
try { | ||
var r = commonjsRequire; | ||
var vertx = r('vertx'); | ||
var vertx = Function('return this')().require('vertx'); | ||
vertxNext = vertx.runOnLoop || vertx.runOnContext; | ||
@@ -488,3 +490,3 @@ return useVertxTimer(); | ||
var scheduleFlush = undefined; | ||
var scheduleFlush = void 0; | ||
// Decide what async method to use to triggering processing of queued callbacks: | ||
@@ -504,4 +506,2 @@ if (isNode) { | ||
function then(onFulfillment, onRejection) { | ||
var _arguments = arguments; | ||
var parent = this; | ||
@@ -517,9 +517,8 @@ | ||
if (_state) { | ||
(function () { | ||
var callback = _arguments[_state - 1]; | ||
asap(function () { | ||
return invokeCallback(_state, child, callback, parent._result); | ||
}); | ||
})(); | ||
var callback = arguments[_state - 1]; | ||
asap(function () { | ||
return invokeCallback(_state, child, callback, parent._result); | ||
}); | ||
} else { | ||
@@ -563,3 +562,3 @@ subscribe(parent, child, onFulfillment, onRejection); | ||
*/ | ||
function resolve(object) { | ||
function resolve$1(object) { | ||
/*jshint validthis:true */ | ||
@@ -573,7 +572,7 @@ var Constructor = this; | ||
var promise = new Constructor(noop); | ||
_resolve(promise, object); | ||
resolve(promise, object); | ||
return promise; | ||
} | ||
var PROMISE_ID = Math.random().toString(36).substring(16); | ||
var PROMISE_ID = Math.random().toString(36).substring(2); | ||
@@ -586,4 +585,2 @@ function noop() {} | ||
var GET_THEN_ERROR = new ErrorObject(); | ||
function selfFulfillment() { | ||
@@ -597,14 +594,5 @@ return new TypeError("You cannot resolve a promise with itself"); | ||
function getThen(promise) { | ||
function tryThen(then$$1, value, fulfillmentHandler, rejectionHandler) { | ||
try { | ||
return promise.then; | ||
} catch (error) { | ||
GET_THEN_ERROR.error = error; | ||
return GET_THEN_ERROR; | ||
} | ||
} | ||
function tryThen(then, value, fulfillmentHandler, rejectionHandler) { | ||
try { | ||
then.call(value, fulfillmentHandler, rejectionHandler); | ||
then$$1.call(value, fulfillmentHandler, rejectionHandler); | ||
} catch (e) { | ||
@@ -615,6 +603,6 @@ return e; | ||
function handleForeignThenable(promise, thenable, then) { | ||
function handleForeignThenable(promise, thenable, then$$1) { | ||
asap(function (promise) { | ||
var sealed = false; | ||
var error = tryThen(then, thenable, function (value) { | ||
var error = tryThen(then$$1, thenable, function (value) { | ||
if (sealed) { | ||
@@ -625,3 +613,3 @@ return; | ||
if (thenable !== value) { | ||
_resolve(promise, value); | ||
resolve(promise, value); | ||
} else { | ||
@@ -636,3 +624,3 @@ fulfill(promise, value); | ||
_reject(promise, reason); | ||
reject(promise, reason); | ||
}, 'Settle: ' + (promise._label || ' unknown promise')); | ||
@@ -642,3 +630,3 @@ | ||
sealed = true; | ||
_reject(promise, error); | ||
reject(promise, error); | ||
} | ||
@@ -652,8 +640,8 @@ }, promise); | ||
} else if (thenable._state === REJECTED) { | ||
_reject(promise, thenable._result); | ||
reject(promise, thenable._result); | ||
} else { | ||
subscribe(thenable, undefined, function (value) { | ||
return _resolve(promise, value); | ||
return resolve(promise, value); | ||
}, function (reason) { | ||
return _reject(promise, reason); | ||
return reject(promise, reason); | ||
}); | ||
@@ -663,13 +651,10 @@ } | ||
function handleMaybeThenable(promise, maybeThenable, then$$) { | ||
if (maybeThenable.constructor === promise.constructor && then$$ === then && maybeThenable.constructor.resolve === resolve) { | ||
function handleMaybeThenable(promise, maybeThenable, then$$1) { | ||
if (maybeThenable.constructor === promise.constructor && then$$1 === then && maybeThenable.constructor.resolve === resolve$1) { | ||
handleOwnThenable(promise, maybeThenable); | ||
} else { | ||
if (then$$ === GET_THEN_ERROR) { | ||
_reject(promise, GET_THEN_ERROR.error); | ||
GET_THEN_ERROR.error = null; | ||
} else if (then$$ === undefined) { | ||
if (then$$1 === undefined) { | ||
fulfill(promise, maybeThenable); | ||
} else if (isFunction(then$$)) { | ||
handleForeignThenable(promise, maybeThenable, then$$); | ||
} else if (isFunction(then$$1)) { | ||
handleForeignThenable(promise, maybeThenable, then$$1); | ||
} else { | ||
@@ -681,7 +666,14 @@ fulfill(promise, maybeThenable); | ||
function _resolve(promise, value) { | ||
function resolve(promise, value) { | ||
if (promise === value) { | ||
_reject(promise, selfFulfillment()); | ||
reject(promise, selfFulfillment()); | ||
} else if (objectOrFunction(value)) { | ||
handleMaybeThenable(promise, value, getThen(value)); | ||
var then$$1 = void 0; | ||
try { | ||
then$$1 = value.then; | ||
} catch (error) { | ||
reject(promise, error); | ||
return; | ||
} | ||
handleMaybeThenable(promise, value, then$$1); | ||
} else { | ||
@@ -713,3 +705,3 @@ fulfill(promise, value); | ||
function _reject(promise, reason) { | ||
function reject(promise, reason) { | ||
if (promise._state !== PENDING) { | ||
@@ -728,2 +720,3 @@ return; | ||
parent._onerror = null; | ||
@@ -748,4 +741,4 @@ | ||
var child = undefined, | ||
callback = undefined, | ||
var child = void 0, | ||
callback = void 0, | ||
detail = promise._result; | ||
@@ -767,37 +760,18 @@ | ||
function ErrorObject() { | ||
this.error = null; | ||
} | ||
var TRY_CATCH_ERROR = new ErrorObject(); | ||
function tryCatch(callback, detail) { | ||
try { | ||
return callback(detail); | ||
} catch (e) { | ||
TRY_CATCH_ERROR.error = e; | ||
return TRY_CATCH_ERROR; | ||
} | ||
} | ||
function invokeCallback(settled, promise, callback, detail) { | ||
var hasCallback = isFunction(callback), | ||
value = undefined, | ||
error = undefined, | ||
succeeded = undefined, | ||
failed = undefined; | ||
value = void 0, | ||
error = void 0, | ||
succeeded = true; | ||
if (hasCallback) { | ||
value = tryCatch(callback, detail); | ||
if (value === TRY_CATCH_ERROR) { | ||
failed = true; | ||
error = value.error; | ||
value.error = null; | ||
} else { | ||
succeeded = true; | ||
try { | ||
value = callback(detail); | ||
} catch (e) { | ||
succeeded = false; | ||
error = e; | ||
} | ||
if (promise === value) { | ||
_reject(promise, cannotReturnOwn()); | ||
reject(promise, cannotReturnOwn()); | ||
return; | ||
@@ -807,14 +781,13 @@ } | ||
value = detail; | ||
succeeded = true; | ||
} | ||
if (promise._state !== PENDING) ; else if (hasCallback && succeeded) { | ||
_resolve(promise, value); | ||
} else if (failed) { | ||
_reject(promise, error); | ||
} else if (settled === FULFILLED) { | ||
fulfill(promise, value); | ||
} else if (settled === REJECTED) { | ||
_reject(promise, value); | ||
} | ||
resolve(promise, value); | ||
} else if (succeeded === false) { | ||
reject(promise, error); | ||
} else if (settled === FULFILLED) { | ||
fulfill(promise, value); | ||
} else if (settled === REJECTED) { | ||
reject(promise, value); | ||
} | ||
} | ||
@@ -825,8 +798,8 @@ | ||
resolver(function resolvePromise(value) { | ||
_resolve(promise, value); | ||
resolve(promise, value); | ||
}, function rejectPromise(reason) { | ||
_reject(promise, reason); | ||
reject(promise, reason); | ||
}); | ||
} catch (e) { | ||
_reject(promise, e); | ||
reject(promise, e); | ||
} | ||
@@ -847,97 +820,112 @@ } | ||
function Enumerator(Constructor, input) { | ||
this._instanceConstructor = Constructor; | ||
this.promise = new Constructor(noop); | ||
function validationError() { | ||
return new Error('Array Methods must be provided an Array'); | ||
} | ||
if (!this.promise[PROMISE_ID]) { | ||
makePromise(this.promise); | ||
} | ||
var Enumerator = function () { | ||
function Enumerator(Constructor, input) { | ||
this._instanceConstructor = Constructor; | ||
this.promise = new Constructor(noop); | ||
if (isArray(input)) { | ||
this._input = input; | ||
this.length = input.length; | ||
this._remaining = input.length; | ||
if (!this.promise[PROMISE_ID]) { | ||
makePromise(this.promise); | ||
} | ||
this._result = new Array(this.length); | ||
if (isArray(input)) { | ||
this.length = input.length; | ||
this._remaining = input.length; | ||
if (this.length === 0) { | ||
fulfill(this.promise, this._result); | ||
} else { | ||
this.length = this.length || 0; | ||
this._enumerate(); | ||
if (this._remaining === 0) { | ||
this._result = new Array(this.length); | ||
if (this.length === 0) { | ||
fulfill(this.promise, this._result); | ||
} else { | ||
this.length = this.length || 0; | ||
this._enumerate(input); | ||
if (this._remaining === 0) { | ||
fulfill(this.promise, this._result); | ||
} | ||
} | ||
} else { | ||
reject(this.promise, validationError()); | ||
} | ||
} else { | ||
_reject(this.promise, validationError()); | ||
} | ||
} | ||
function validationError() { | ||
return new Error('Array Methods must be provided an Array'); | ||
} | ||
Enumerator.prototype._enumerate = function () { | ||
var length = this.length; | ||
var _input = this._input; | ||
Enumerator.prototype._enumerate = function _enumerate(input) { | ||
for (var i = 0; this._state === PENDING && i < input.length; i++) { | ||
this._eachEntry(input[i], i); | ||
} | ||
}; | ||
for (var i = 0; this._state === PENDING && i < length; i++) { | ||
this._eachEntry(_input[i], i); | ||
} | ||
}; | ||
Enumerator.prototype._eachEntry = function _eachEntry(entry, i) { | ||
var c = this._instanceConstructor; | ||
var resolve$$1 = c.resolve; | ||
Enumerator.prototype._eachEntry = function (entry, i) { | ||
var c = this._instanceConstructor; | ||
var resolve$$ = c.resolve; | ||
if (resolve$$ === resolve) { | ||
var _then = getThen(entry); | ||
if (resolve$$1 === resolve$1) { | ||
var _then = void 0; | ||
var error = void 0; | ||
var didError = false; | ||
try { | ||
_then = entry.then; | ||
} catch (e) { | ||
didError = true; | ||
error = e; | ||
} | ||
if (_then === then && entry._state !== PENDING) { | ||
this._settledAt(entry._state, i, entry._result); | ||
} else if (typeof _then !== 'function') { | ||
this._remaining--; | ||
this._result[i] = entry; | ||
} else if (c === Promise) { | ||
var promise = new c(noop); | ||
handleMaybeThenable(promise, entry, _then); | ||
this._willSettleAt(promise, i); | ||
if (_then === then && entry._state !== PENDING) { | ||
this._settledAt(entry._state, i, entry._result); | ||
} else if (typeof _then !== 'function') { | ||
this._remaining--; | ||
this._result[i] = entry; | ||
} else if (c === Promise$1) { | ||
var promise = new c(noop); | ||
if (didError) { | ||
reject(promise, error); | ||
} else { | ||
handleMaybeThenable(promise, entry, _then); | ||
} | ||
this._willSettleAt(promise, i); | ||
} else { | ||
this._willSettleAt(new c(function (resolve$$1) { | ||
return resolve$$1(entry); | ||
}), i); | ||
} | ||
} else { | ||
this._willSettleAt(new c(function (resolve$$) { | ||
return resolve$$(entry); | ||
}), i); | ||
this._willSettleAt(resolve$$1(entry), i); | ||
} | ||
} else { | ||
this._willSettleAt(resolve$$(entry), i); | ||
} | ||
}; | ||
}; | ||
Enumerator.prototype._settledAt = function (state, i, value) { | ||
var promise = this.promise; | ||
Enumerator.prototype._settledAt = function _settledAt(state, i, value) { | ||
var promise = this.promise; | ||
if (promise._state === PENDING) { | ||
this._remaining--; | ||
if (state === REJECTED) { | ||
_reject(promise, value); | ||
} else { | ||
this._result[i] = value; | ||
if (promise._state === PENDING) { | ||
this._remaining--; | ||
if (state === REJECTED) { | ||
reject(promise, value); | ||
} else { | ||
this._result[i] = value; | ||
} | ||
} | ||
} | ||
if (this._remaining === 0) { | ||
fulfill(promise, this._result); | ||
} | ||
}; | ||
if (this._remaining === 0) { | ||
fulfill(promise, this._result); | ||
} | ||
}; | ||
Enumerator.prototype._willSettleAt = function (promise, i) { | ||
var enumerator = this; | ||
Enumerator.prototype._willSettleAt = function _willSettleAt(promise, i) { | ||
var enumerator = this; | ||
subscribe(promise, undefined, function (value) { | ||
return enumerator._settledAt(FULFILLED, i, value); | ||
}, function (reason) { | ||
return enumerator._settledAt(REJECTED, i, reason); | ||
}); | ||
}; | ||
subscribe(promise, undefined, function (value) { | ||
return enumerator._settledAt(FULFILLED, i, value); | ||
}, function (reason) { | ||
return enumerator._settledAt(REJECTED, i, reason); | ||
}); | ||
}; | ||
return Enumerator; | ||
}(); | ||
/** | ||
@@ -1111,7 +1099,7 @@ `Promise.all` accepts an array of promises, and returns a new promise which | ||
*/ | ||
function reject(reason) { | ||
function reject$1(reason) { | ||
/*jshint validthis:true */ | ||
var Constructor = this; | ||
var promise = new Constructor(noop); | ||
_reject(promise, reason); | ||
reject(promise, reason); | ||
return promise; | ||
@@ -1227,296 +1215,325 @@ } | ||
@class Promise | ||
@param {function} resolver | ||
@param {Function} resolver | ||
Useful for tooling. | ||
@constructor | ||
*/ | ||
function Promise(resolver) { | ||
this[PROMISE_ID] = nextId(); | ||
this._result = this._state = undefined; | ||
this._subscribers = []; | ||
if (noop !== resolver) { | ||
typeof resolver !== 'function' && needsResolver(); | ||
this instanceof Promise ? initializePromise(this, resolver) : needsNew(); | ||
var Promise$1 = function () { | ||
function Promise(resolver) { | ||
this[PROMISE_ID] = nextId(); | ||
this._result = this._state = undefined; | ||
this._subscribers = []; | ||
if (noop !== resolver) { | ||
typeof resolver !== 'function' && needsResolver(); | ||
this instanceof Promise ? initializePromise(this, resolver) : needsNew(); | ||
} | ||
} | ||
} | ||
Promise.all = all; | ||
Promise.race = race; | ||
Promise.resolve = resolve; | ||
Promise.reject = reject; | ||
Promise._setScheduler = setScheduler; | ||
Promise._setAsap = setAsap; | ||
Promise._asap = asap; | ||
Promise.prototype = { | ||
constructor: Promise, | ||
/** | ||
The primary way of interacting with a promise is through its `then` method, | ||
which registers callbacks to receive either a promise's eventual value or the | ||
reason why the promise cannot be fulfilled. | ||
```js | ||
findUser().then(function(user){ | ||
// user is available | ||
}, function(reason){ | ||
// user is unavailable, and you are given the reason why | ||
}); | ||
``` | ||
Chaining | ||
-------- | ||
The return value of `then` is itself a promise. This second, 'downstream' | ||
promise is resolved with the return value of the first promise's fulfillment | ||
or rejection handler, or rejected if the handler throws an exception. | ||
```js | ||
findUser().then(function (user) { | ||
return user.name; | ||
}, function (reason) { | ||
return 'default name'; | ||
}).then(function (userName) { | ||
// If `findUser` fulfilled, `userName` will be the user's name, otherwise it | ||
// will be `'default name'` | ||
}); | ||
findUser().then(function (user) { | ||
throw new Error('Found user, but still unhappy'); | ||
}, function (reason) { | ||
throw new Error('`findUser` rejected and we're unhappy'); | ||
}).then(function (value) { | ||
// never reached | ||
}, function (reason) { | ||
// if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'. | ||
// If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'. | ||
}); | ||
``` | ||
If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream. | ||
```js | ||
findUser().then(function (user) { | ||
throw new PedagogicalException('Upstream error'); | ||
}).then(function (value) { | ||
// never reached | ||
}).then(function (value) { | ||
// never reached | ||
}, function (reason) { | ||
// The `PedgagocialException` is propagated all the way down to here | ||
}); | ||
``` | ||
Assimilation | ||
------------ | ||
Sometimes the value you want to propagate to a downstream promise can only be | ||
retrieved asynchronously. This can be achieved by returning a promise in the | ||
fulfillment or rejection handler. The downstream promise will then be pending | ||
until the returned promise is settled. This is called *assimilation*. | ||
```js | ||
findUser().then(function (user) { | ||
return findCommentsByAuthor(user); | ||
}).then(function (comments) { | ||
// The user's comments are now available | ||
}); | ||
``` | ||
If the assimliated promise rejects, then the downstream promise will also reject. | ||
```js | ||
findUser().then(function (user) { | ||
return findCommentsByAuthor(user); | ||
}).then(function (comments) { | ||
// If `findCommentsByAuthor` fulfills, we'll have the value here | ||
}, function (reason) { | ||
// If `findCommentsByAuthor` rejects, we'll have the reason here | ||
}); | ||
``` | ||
Simple Example | ||
-------------- | ||
Synchronous Example | ||
```javascript | ||
let result; | ||
try { | ||
result = findResult(); | ||
The primary way of interacting with a promise is through its `then` method, | ||
which registers callbacks to receive either a promise's eventual value or the | ||
reason why the promise cannot be fulfilled. | ||
```js | ||
findUser().then(function(user){ | ||
// user is available | ||
}, function(reason){ | ||
// user is unavailable, and you are given the reason why | ||
}); | ||
``` | ||
Chaining | ||
-------- | ||
The return value of `then` is itself a promise. This second, 'downstream' | ||
promise is resolved with the return value of the first promise's fulfillment | ||
or rejection handler, or rejected if the handler throws an exception. | ||
```js | ||
findUser().then(function (user) { | ||
return user.name; | ||
}, function (reason) { | ||
return 'default name'; | ||
}).then(function (userName) { | ||
// If `findUser` fulfilled, `userName` will be the user's name, otherwise it | ||
// will be `'default name'` | ||
}); | ||
findUser().then(function (user) { | ||
throw new Error('Found user, but still unhappy'); | ||
}, function (reason) { | ||
throw new Error('`findUser` rejected and we're unhappy'); | ||
}).then(function (value) { | ||
// never reached | ||
}, function (reason) { | ||
// if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'. | ||
// If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'. | ||
}); | ||
``` | ||
If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream. | ||
```js | ||
findUser().then(function (user) { | ||
throw new PedagogicalException('Upstream error'); | ||
}).then(function (value) { | ||
// never reached | ||
}).then(function (value) { | ||
// never reached | ||
}, function (reason) { | ||
// The `PedgagocialException` is propagated all the way down to here | ||
}); | ||
``` | ||
Assimilation | ||
------------ | ||
Sometimes the value you want to propagate to a downstream promise can only be | ||
retrieved asynchronously. This can be achieved by returning a promise in the | ||
fulfillment or rejection handler. The downstream promise will then be pending | ||
until the returned promise is settled. This is called *assimilation*. | ||
```js | ||
findUser().then(function (user) { | ||
return findCommentsByAuthor(user); | ||
}).then(function (comments) { | ||
// The user's comments are now available | ||
}); | ||
``` | ||
If the assimliated promise rejects, then the downstream promise will also reject. | ||
```js | ||
findUser().then(function (user) { | ||
return findCommentsByAuthor(user); | ||
}).then(function (comments) { | ||
// If `findCommentsByAuthor` fulfills, we'll have the value here | ||
}, function (reason) { | ||
// If `findCommentsByAuthor` rejects, we'll have the reason here | ||
}); | ||
``` | ||
Simple Example | ||
-------------- | ||
Synchronous Example | ||
```javascript | ||
let result; | ||
try { | ||
result = findResult(); | ||
// success | ||
} catch(reason) { | ||
// failure | ||
} | ||
``` | ||
Errback Example | ||
```js | ||
findResult(function(result, err){ | ||
if (err) { | ||
// failure | ||
} else { | ||
// success | ||
} catch(reason) { | ||
} | ||
}); | ||
``` | ||
Promise Example; | ||
```javascript | ||
findResult().then(function(result){ | ||
// success | ||
}, function(reason){ | ||
// failure | ||
}); | ||
``` | ||
Advanced Example | ||
-------------- | ||
Synchronous Example | ||
```javascript | ||
let author, books; | ||
try { | ||
author = findAuthor(); | ||
books = findBooksByAuthor(author); | ||
// success | ||
} catch(reason) { | ||
// failure | ||
} | ||
``` | ||
Errback Example | ||
```js | ||
function foundBooks(books) { | ||
} | ||
function failure(reason) { | ||
} | ||
findAuthor(function(author, err){ | ||
if (err) { | ||
failure(err); | ||
// failure | ||
} else { | ||
try { | ||
findBoooksByAuthor(author, function(books, err) { | ||
if (err) { | ||
failure(err); | ||
} else { | ||
try { | ||
foundBooks(books); | ||
} catch(reason) { | ||
failure(reason); | ||
} | ||
} | ||
}); | ||
} catch(error) { | ||
failure(err); | ||
} | ||
// success | ||
} | ||
``` | ||
}); | ||
``` | ||
Promise Example; | ||
```javascript | ||
findAuthor(). | ||
then(findBooksByAuthor). | ||
then(function(books){ | ||
// found books | ||
}).catch(function(reason){ | ||
// something went wrong | ||
}); | ||
``` | ||
@method then | ||
@param {Function} onFulfilled | ||
@param {Function} onRejected | ||
Useful for tooling. | ||
@return {Promise} | ||
*/ | ||
/** | ||
`catch` is simply sugar for `then(undefined, onRejection)` which makes it the same | ||
as the catch block of a try/catch statement. | ||
```js | ||
function findAuthor(){ | ||
throw new Error('couldn't find that author'); | ||
} | ||
// synchronous | ||
try { | ||
findAuthor(); | ||
} catch(reason) { | ||
// something went wrong | ||
} | ||
// async with promises | ||
findAuthor().catch(function(reason){ | ||
// something went wrong | ||
}); | ||
``` | ||
@method catch | ||
@param {Function} onRejection | ||
Useful for tooling. | ||
@return {Promise} | ||
*/ | ||
Promise.prototype.catch = function _catch(onRejection) { | ||
return this.then(null, onRejection); | ||
}; | ||
/** | ||
`finally` will be invoked regardless of the promise's fate just as native | ||
try/catch/finally behaves | ||
Errback Example | ||
Synchronous example: | ||
```js | ||
findResult(function(result, err){ | ||
if (err) { | ||
// failure | ||
} else { | ||
// success | ||
findAuthor() { | ||
if (Math.random() > 0.5) { | ||
throw new Error(); | ||
} | ||
}); | ||
``` | ||
return new Author(); | ||
} | ||
Promise Example; | ||
```javascript | ||
findResult().then(function(result){ | ||
// success | ||
}, function(reason){ | ||
// failure | ||
}); | ||
``` | ||
Advanced Example | ||
-------------- | ||
Synchronous Example | ||
```javascript | ||
let author, books; | ||
try { | ||
author = findAuthor(); | ||
books = findBooksByAuthor(author); | ||
// success | ||
} catch(reason) { | ||
// failure | ||
return findAuthor(); // succeed or fail | ||
} catch(error) { | ||
return findOtherAuther(); | ||
} finally { | ||
// always runs | ||
// doesn't affect the return value | ||
} | ||
``` | ||
Errback Example | ||
Asynchronous example: | ||
```js | ||
function foundBooks(books) { | ||
} | ||
function failure(reason) { | ||
} | ||
findAuthor(function(author, err){ | ||
if (err) { | ||
failure(err); | ||
// failure | ||
} else { | ||
try { | ||
findBoooksByAuthor(author, function(books, err) { | ||
if (err) { | ||
failure(err); | ||
} else { | ||
try { | ||
foundBooks(books); | ||
} catch(reason) { | ||
failure(reason); | ||
} | ||
} | ||
}); | ||
} catch(error) { | ||
failure(err); | ||
} | ||
// success | ||
} | ||
findAuthor().catch(function(reason){ | ||
return findOtherAuther(); | ||
}).finally(function(){ | ||
// author was either found, or not | ||
}); | ||
``` | ||
Promise Example; | ||
```javascript | ||
findAuthor(). | ||
then(findBooksByAuthor). | ||
then(function(books){ | ||
// found books | ||
}).catch(function(reason){ | ||
// something went wrong | ||
}); | ||
``` | ||
@method then | ||
@param {Function} onFulfilled | ||
@param {Function} onRejected | ||
Useful for tooling. | ||
@method finally | ||
@param {Function} callback | ||
@return {Promise} | ||
*/ | ||
then: then, | ||
/** | ||
`catch` is simply sugar for `then(undefined, onRejection)` which makes it the same | ||
as the catch block of a try/catch statement. | ||
```js | ||
function findAuthor(){ | ||
throw new Error('couldn't find that author'); | ||
Promise.prototype.finally = function _finally(callback) { | ||
var promise = this; | ||
var constructor = promise.constructor; | ||
if (isFunction(callback)) { | ||
return promise.then(function (value) { | ||
return constructor.resolve(callback()).then(function () { | ||
return value; | ||
}); | ||
}, function (reason) { | ||
return constructor.resolve(callback()).then(function () { | ||
throw reason; | ||
}); | ||
}); | ||
} | ||
// synchronous | ||
return promise.then(callback, callback); | ||
}; | ||
return Promise; | ||
}(); | ||
Promise$1.prototype.then = then; | ||
Promise$1.all = all; | ||
Promise$1.race = race; | ||
Promise$1.resolve = resolve$1; | ||
Promise$1.reject = reject$1; | ||
Promise$1._setScheduler = setScheduler; | ||
Promise$1._setAsap = setAsap; | ||
Promise$1._asap = asap; | ||
/*global self*/ | ||
function polyfill() { | ||
var local = void 0; | ||
if (typeof commonjsGlobal !== 'undefined') { | ||
local = commonjsGlobal; | ||
} else if (typeof self !== 'undefined') { | ||
local = self; | ||
} else { | ||
try { | ||
findAuthor(); | ||
} catch(reason) { | ||
// something went wrong | ||
local = Function('return this')(); | ||
} catch (e) { | ||
throw new Error('polyfill failed because global object is unavailable in this environment'); | ||
} | ||
// async with promises | ||
findAuthor().catch(function(reason){ | ||
// something went wrong | ||
}); | ||
``` | ||
@method catch | ||
@param {Function} onRejection | ||
Useful for tooling. | ||
@return {Promise} | ||
*/ | ||
'catch': function _catch(onRejection) { | ||
return this.then(null, onRejection); | ||
} | ||
}; | ||
function polyfill() { | ||
var local = undefined; | ||
var P = local.Promise; | ||
if (typeof commonjsGlobal !== 'undefined') { | ||
local = commonjsGlobal; | ||
} else if (typeof self !== 'undefined') { | ||
local = self; | ||
} else { | ||
try { | ||
local = Function('return this')(); | ||
} catch (e) { | ||
throw new Error('polyfill failed because global object is unavailable in this environment'); | ||
} | ||
if (P) { | ||
var promiseToString = null; | ||
try { | ||
promiseToString = Object.prototype.toString.call(P.resolve()); | ||
} catch (e) { | ||
// silently ignored | ||
} | ||
var P = local.Promise; | ||
if (P) { | ||
var promiseToString = null; | ||
try { | ||
promiseToString = Object.prototype.toString.call(P.resolve()); | ||
} catch (e) { | ||
// silently ignored | ||
} | ||
if (promiseToString === '[object Promise]' && !P.cast) { | ||
return; | ||
} | ||
if (promiseToString === '[object Promise]' && !P.cast) { | ||
return; | ||
} | ||
} | ||
local.Promise = Promise; | ||
local.Promise = Promise$1; | ||
} | ||
// Strange compat.. | ||
Promise.polyfill = polyfill; | ||
Promise.Promise = Promise; | ||
Promise$1.polyfill = polyfill; | ||
Promise$1.Promise = Promise$1; | ||
return Promise; | ||
return Promise$1; | ||
}))); | ||
}); | ||
@@ -1523,0 +1540,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self,t.glitch=e())}(this,function(){"use strict";function t(t,e,n){return t<e?e:t>n?n:t}function e(t){var e=!1;if(void 0!==t)try{e=JSON.parse(JSON.stringify(t))}catch(t){}return e}function n(n){return"object"!=typeof(n=e(n))&&(n={}),Object.keys(p).filter(function(t){return"iterations"!==t}).forEach(function(e){"number"!=typeof n[e]||isNaN(n[e])?n[e]=p[e]:n[e]=t(n[e],0,100),n[e]=Math.round(n[e])}),("number"!=typeof n.iterations||isNaN(n.iterations)||n.iterations<=0)&&(n.iterations=p.iterations),n.iterations=Math.round(n.iterations),n}function r(t){if(t instanceof HTMLImageElement){if(!t.naturalWidth||!t.naturalHeight||!1===t.complete)throw new Error("This this image hasn't finished loading: "+t.src);var e=new d(t.naturalWidth,t.naturalHeight),n=e.getContext("2d");n.drawImage(t,0,0,e.width,e.height);var r=n.getImageData(0,0,e.width,e.height);return r.data&&r.data.length&&(void 0===r.width&&(r.width=t.naturalWidth),void 0===r.height&&(r.height=t.naturalHeight)),r}throw new Error("This object does not seem to be an image.")}function i(t){return new Promise(function(e,n){var r=new v;r.onload=function(){e(r)},r.onerror=n;try{r.src=t}catch(t){n(t)}})}function a(t,e,n,r){i(t).then(n,r)}function o(t){return{width:t.width||t.naturalWidth,height:t.height||t.naturalHeight}}function s(t){var e=o(t),n=new d(e.width,e.height),r=n.getContext("2d");return r.drawImage(t,0,0,e.width,e.height),{canvas:n,ctx:r}}function u(t,e,n,r){i(t).then(function(t){var e=o(t),r=s(t).ctx.getImageData(0,0,e.width,e.height);r.width||(r.width=e.width),r.height||(r.height=e.height),n(r)},r)}function c(t){return t&&"number"==typeof t.width&&"number"==typeof t.height&&t.data&&"number"==typeof t.data.length&&"object"==typeof t.data}function f(t,e){return new Promise(function(n,r){if(c(t)){var i=new d(t.width,t.height);i.getContext("2d").putImageData(t,0,0),n(i.toDataURL("image/jpeg",e/100))}else r(new Error("object is not valid imageData"))})}function h(t){if(null===t||void 0===t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}function l(){throw new Error("Dynamic requires are not currently supported by rollup-plugin-commonjs")}var p={amount:35,iterations:20,quality:30,seed:25},d=function(t,e){void 0===t&&(t=300),void 0===e&&(e=150),"undefined"==typeof window?(this.canvasEl={width:t,height:e},this.ctx=null):(this.canvasEl=document.createElement("canvas"),this.canvasEl.width=t,this.canvasEl.height=e,this.ctx=this.canvasEl.getContext("2d"))},g={width:{configurable:!0},height:{configurable:!0}};d.prototype.getContext=function(){return this.ctx},d.prototype.toDataURL=function(t,e,n){if("function"!=typeof n)return this.canvasEl.toDataURL(t,e);n(this.canvasEl.toDataURL(t,e))},g.width.get=function(){return this.canvasEl.width},g.width.set=function(t){this.canvasEl.width=t},g.height.get=function(){return this.canvasEl.height},g.height.set=function(t){this.canvasEl.height=t},Object.defineProperties(d.prototype,g),"undefined"!=typeof window&&(d.Image=Image);var v=d.Image,m=Object.getOwnPropertySymbols,b=Object.prototype.hasOwnProperty,y=Object.prototype.propertyIsEnumerable,w=function(){try{if(!Object.assign)return!1;var t=new String("abc");if(t[5]="de","5"===Object.getOwnPropertyNames(t)[0])return!1;for(var e={},n=0;n<10;n++)e["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(e).map(function(t){return e[t]}).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach(function(t){r[t]=t}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(t){return!1}}()?Object.assign:function(t,e){for(var n,r,i=arguments,a=h(t),o=1;o<arguments.length;o++){n=Object(i[o]);for(var s in n)b.call(n,s)&&(a[s]=n[s]);if(m){r=m(n);for(var u=0;u<r.length;u++)y.call(n,r[u])&&(a[r[u]]=n[r[u]])}}return a},_="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};return function(t,e){return e={exports:{}},t(e,e.exports),e.exports}(function(t,e){!function(e,n){t.exports=n()}(0,function(){function t(t){return"function"==typeof t||"object"==typeof t&&null!==t}function e(t){return"function"==typeof t}function n(){return void 0!==U?function(){U(i)}:r()}function r(){var t=setTimeout;return function(){return t(i,1)}}function i(){for(var t=0;t<k;t+=2)(0,F[t])(F[t+1]),F[t]=void 0,F[t+1]=void 0;k=0}function a(t,e){var n=arguments,r=this,i=new this.constructor(s);void 0===i[K]&&x(i);var a=r._state;return a?function(){var t=n[a-1];H(function(){return D(a,i,t,r._result)})}():w(r,i,t,e),i}function o(t){var e=this;if(t&&"object"==typeof t&&t.constructor===e)return t;var n=new e(s);return v(n,t),n}function s(){}function u(){return new TypeError("You cannot resolve a promise with itself")}function c(){return new TypeError("A promises callback cannot return that same promise.")}function f(t){try{return t.then}catch(t){return V.error=t,V}}function h(t,e,n,r){try{t.call(e,n,r)}catch(t){return t}}function p(t,e,n){H(function(t){var r=!1,i=h(n,e,function(n){r||(r=!0,e!==n?v(t,n):b(t,n))},function(e){r||(r=!0,y(t,e))},"Settle: "+(t._label||" unknown promise"));!r&&i&&(r=!0,y(t,i))},t)}function d(t,e){e._state===G?b(t,e._result):e._state===Q?y(t,e._result):w(e,void 0,function(e){return v(t,e)},function(e){return y(t,e)})}function g(t,n,r){n.constructor===t.constructor&&r===a&&n.constructor.resolve===o?d(t,n):r===V?(y(t,V.error),V.error=null):void 0===r?b(t,n):e(r)?p(t,n,r):b(t,n)}function v(e,n){e===n?y(e,u()):t(n)?g(e,n,f(n)):b(e,n)}function m(t){t._onerror&&t._onerror(t._result),j(t)}function b(t,e){t._state===z&&(t._result=e,t._state=G,0!==t._subscribers.length&&H(j,t))}function y(t,e){t._state===z&&(t._state=Q,t._result=e,H(m,t))}function w(t,e,n,r){var i=t._subscribers,a=i.length;t._onerror=null,i[a]=e,i[a+G]=n,i[a+Q]=r,0===a&&t._state&&H(j,t)}function j(t){var e=t._subscribers,n=t._state;if(0!==e.length){for(var r=void 0,i=void 0,a=t._result,o=0;o<e.length;o+=3)r=e[o],i=e[o+n],r?D(n,r,i,a):i(a);t._subscribers.length=0}}function E(){this.error=null}function M(t,e){try{return t(e)}catch(t){return X.error=t,X}}function D(t,n,r,i){var a=e(r),o=void 0,s=void 0,u=void 0,f=void 0;if(a){if((o=M(r,i))===X?(f=!0,s=o.error,o.error=null):u=!0,n===o)return void y(n,c())}else o=i,u=!0;n._state!==z||(a&&u?v(n,o):f?y(n,s):t===G?b(n,o):t===Q&&y(n,o))}function O(t,e){try{e(function(e){v(t,e)},function(e){y(t,e)})}catch(e){y(t,e)}}function A(){return Z++}function x(t){t[K]=Z++,t._state=void 0,t._result=void 0,t._subscribers=[]}function I(t,e){this._instanceConstructor=t,this.promise=new t(s),this.promise[K]||x(this.promise),B(e)?(this._input=e,this.length=e.length,this._remaining=e.length,this._result=new Array(this.length),0===this.length?b(this.promise,this._result):(this.length=this.length||0,this._enumerate(),0===this._remaining&&b(this.promise,this._result))):y(this.promise,P())}function P(){return new Error("Array Methods must be provided an Array")}function T(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function L(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function S(t){this[K]=A(),this._result=this._state=void 0,this._subscribers=[],s!==t&&("function"!=typeof t&&T(),this instanceof S?O(this,t):L())}var C=void 0,B=C=Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)},k=0,U=void 0,R=void 0,H=function(t,e){F[k]=t,F[k+1]=e,2===(k+=2)&&(R?R(i):J())},N="undefined"!=typeof window?window:void 0,W=N||{},$=W.MutationObserver||W.WebKitMutationObserver,q="undefined"==typeof self&&"undefined"!=typeof process&&"[object process]"==={}.toString.call(process),Y="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,F=new Array(1e3),J=void 0;J=q?function(){return process.nextTick(i)}:$?function(){var t=0,e=new $(i),n=document.createTextNode("");return e.observe(n,{characterData:!0}),function(){n.data=t=++t%2}}():Y?function(){var t=new MessageChannel;return t.port1.onmessage=i,function(){return t.port2.postMessage(0)}}():void 0===N&&"function"==typeof l?function(){try{var t=l("vertx");return U=t.runOnLoop||t.runOnContext,n()}catch(t){return r()}}():r();var K=Math.random().toString(36).substring(16),z=void 0,G=1,Q=2,V=new E,X=new E,Z=0;return I.prototype._enumerate=function(){for(var t=this.length,e=this._input,n=0;this._state===z&&n<t;n++)this._eachEntry(e[n],n)},I.prototype._eachEntry=function(t,e){var n=this._instanceConstructor,r=n.resolve;if(r===o){var i=f(t);if(i===a&&t._state!==z)this._settledAt(t._state,e,t._result);else if("function"!=typeof i)this._remaining--,this._result[e]=t;else if(n===S){var u=new n(s);g(u,t,i),this._willSettleAt(u,e)}else this._willSettleAt(new n(function(e){return e(t)}),e)}else this._willSettleAt(r(t),e)},I.prototype._settledAt=function(t,e,n){var r=this.promise;r._state===z&&(this._remaining--,t===Q?y(r,n):this._result[e]=n),0===this._remaining&&b(r,this._result)},I.prototype._willSettleAt=function(t,e){var n=this;w(t,void 0,function(t){return n._settledAt(G,e,t)},function(t){return n._settledAt(Q,e,t)})},S.all=function(t){return new I(this,t).promise},S.race=function(t){var e=this;return new e(B(t)?function(n,r){for(var i=t.length,a=0;a<i;a++)e.resolve(t[a]).then(n,r)}:function(t,e){return e(new TypeError("You must pass an array to race."))})},S.resolve=o,S.reject=function(t){var e=new this(s);return y(e,t),e},S._setScheduler=function(t){R=t},S._setAsap=function(t){H=t},S._asap=H,S.prototype={constructor:S,then:a,catch:function(t){return this.then(null,t)}},S.polyfill=function(){var t=void 0;if(void 0!==_)t=_;else if("undefined"!=typeof self)t=self;else try{t=Function("return this")()}catch(t){throw new Error("polyfill failed because global object is unavailable in this environment")}var e=t.Promise;if(e){var n=null;try{n=Object.prototype.toString.call(e.resolve())}catch(t){}if("[object Promise]"===n&&!e.cast)return}t.Promise=S},S.Promise=S,S})}).polyfill(),function(t){function e(){var t=w({},b);return g||w(t,y),t}function i(){var t=w({},b);return v||w(t,_),t}function o(t){return t}function s(t,e,n){return g=function(){return new Promise(function(r,i){if(n)t(e,r,i);else if(t===o)r(e);else try{r(t(e,r,i))}catch(t){i(t)}})},h()?l():i()}function c(t,n,r){return v=function(e){return new Promise(function(i,a){r?t(e,n,i,a):t===o?i(e):t(e,n).then(i,a)})},h()?l():e()}function h(){return g&&v}function l(){return new Promise(function(e,n){g().then(function(e){return p(e,t)},n).then(function(t){v(t).then(e,n)},n)})}function p(t,e){return new Promise(function(n,r){f(t,e.quality).then(function(n){return d(t,n,e)},r).then(n,r)})}function d(t,e,n){return new Promise(function(r,i){m.addEventListener("message",function(t){t.data&&t.data.base64URL?r(t.data.base64URL):i(t.data&&t.data.err?t.data.err:t)}),m.postMessage({params:n,base64URL:e,imageData:t,imageDataWidth:t.width,imageDataHeight:t.height})})}t=n(t);var g,v,m=new Worker(URL.createObjectURL(new Blob(['function isImageData(a){return a&&"number"==typeof a.width&&"number"==typeof a.height&&a.data&&"number"==typeof a.data.length&&"object"==typeof a.data}function base64ToByteArray(a){for(var e,s=[],t=a.replace("data:image/jpeg;base64,",""),r=0,i=t.length;r<i;r++){t[r];var p=reversedBase64Map$1[t[r]];switch(r%4){case 1:s.push(e<<2|p>>4);break;case 2:s.push((15&e)<<4|p>>2);break;case 3:s.push((3&e)<<6|p)}e=p}return s}function jpgHeaderLength(a){for(var e=417,s=0,t=a.length;s<t;s++)if(255===a[s]&&218===a[s+1]){e=s+2;break}return e}function glitchByteArray(a,e,s,t){for(var r=jpgHeaderLength(a),i=a.length-r-4,p=s/100,n=e/100,h=0;h<t;h++){var g=i/t*h|0,o=g+((i/t*(h+1)|0)-g)*n|0;o>i&&(o=i),a[~~(r+o)]=~~(256*p)}return a}function byteArrayToBase64(a){for(var e,s,t=["data:image/jpeg;base64,"],r=0,i=a.length;r<i;r++){var p=a[r];switch(e=r%3){case 0:t.push(base64Map$1[p>>2]);break;case 1:t.push(base64Map$1[(3&s)<<4|p>>4]);break;case 2:t.push(base64Map$1[(15&s)<<2|p>>6]),t.push(base64Map$1[63&p])}s=p}return 0===e?(t.push(base64Map$1[(3&s)<<4]),t.push("==")):1===e&&(t.push(base64Map$1[(15&s)<<2]),t.push("=")),t.join("")}function glitchImageData(a,e,s){if(isImageData(a))return byteArrayToBase64(glitchByteArray(base64ToByteArray(e),s.seed,s.amount,s.iterations));throw new Error("glitchImageData: imageData seems to be corrupt.")}function fail(a){self.postMessage({err:a.message||a})}function success(a){self.postMessage({base64URL:a})}var base64Chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",base64Map=base64Chars.split(""),reversedBase64Map={};base64Map.forEach(function(a,e){reversedBase64Map[a]=e});var maps={base64Map:base64Map,reversedBase64Map:reversedBase64Map},reversedBase64Map$1=maps.reversedBase64Map,base64Map$1=maps.base64Map;onmessage=function(a){var e=a.data.imageData,s=a.data.params,t=a.data.base64URL;if(e&&t&&s)try{void 0===e.width&&"number"==typeof a.data.imageDataWidth&&(e.width=a.data.imageDataWidth),void 0===e.height&&"number"==typeof a.data.imageDataHeight&&(e.height=a.data.imageDataHeight),success(glitchImageData(e,t,s))}catch(a){fail(a)}else fail(a.data.imageData?"Parameters are missing.":"ImageData is missing.");self.close()};'],{type:"text/javascript"}))),b={getParams:function(){return t},getInput:e,getOutput:i},y={fromImageData:function(t){return s(o,t)},fromImage:function(t){return s(r,t)}},_={toImage:function(t){return c(a,t,!0)},toDataURL:function(t){return c(o)},toImageData:function(t){return c(u,t,!0)}};return e()}}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).glitch=e()}(this,function(){"use strict";var a={amount:35,iterations:20,quality:30,seed:25};function p(i){return"object"!=typeof(i=function(t){var e=!1;if(void 0!==t)try{e=JSON.parse(JSON.stringify(t))}catch(t){}return e}(i))&&(i={}),Object.keys(a).filter(function(t){return"iterations"!==t}).forEach(function(t){var e,n,r;"number"!=typeof i[t]||isNaN(i[t])?i[t]=a[t]:i[t]=(e=i[t],r=100,e<(n=0)?n:r<e?r:e),i[t]=Math.round(i[t])}),("number"!=typeof i.iterations||isNaN(i.iterations)||i.iterations<=0)&&(i.iterations=a.iterations),i.iterations=Math.round(i.iterations),i}var u=function(t,e){void 0===t&&(t=300),void 0===e&&(e=150),"undefined"==typeof window?(this.canvasEl={width:t,height:e},this.ctx=null):(this.canvasEl=document.createElement("canvas"),this.canvasEl.width=t,this.canvasEl.height=e,this.ctx=this.canvasEl.getContext("2d"))},t={width:{configurable:!0},height:{configurable:!0}};function g(t){if(t instanceof HTMLImageElement){if(!t.naturalWidth||!t.naturalHeight||!1===t.complete)throw new Error("This this image hasn't finished loading: "+t.src);var e=new u(t.naturalWidth,t.naturalHeight),n=e.getContext("2d");n.drawImage(t,0,0,e.width,e.height);var r=n.getImageData(0,0,e.width,e.height);return r.data&&r.data.length&&(void 0===r.width&&(r.width=t.naturalWidth),void 0===r.height&&(r.height=t.naturalHeight)),r}throw new Error("This object does not seem to be an image.")}u.prototype.getContext=function(){return this.ctx},u.prototype.toDataURL=function(t,e,n){if("function"!=typeof n)return this.canvasEl.toDataURL(t,e);n(this.canvasEl.toDataURL(t,e))},t.width.get=function(){return this.canvasEl.width},t.width.set=function(t){this.canvasEl.width=t},t.height.get=function(){return this.canvasEl.height},t.height.set=function(t){this.canvasEl.height=t},Object.defineProperties(u.prototype,t),"undefined"!=typeof window&&(u.Image=Image);var i=u.Image;function o(r){return new Promise(function(t,e){var n=new i;n.onload=function(){t(n)},n.onerror=e;try{n.src=r}catch(t){e(t)}})}function v(t,e,n,r){o(t).then(n,r)}function f(t){return{width:t.width||t.naturalWidth,height:t.height||t.naturalHeight}}function m(t,e,s,n){o(t).then(function(t){var e,n,r,i,a=f(t),o=(n=f(e=t),r=new u(n.width,n.height),(i=r.getContext("2d")).drawImage(e,0,0,n.width,n.height),{canvas:r,ctx:i}.ctx.getImageData(0,0,a.width,a.height));o.width||(o.width=a.width),o.height||(o.height=a.height),s(o)},n)}function y(i,a){return new Promise(function(t,e){if((r=i)&&"number"==typeof r.width&&"number"==typeof r.height&&r.data&&"number"==typeof r.data.length&&"object"==typeof r.data){var n=new u(i.width,i.height);n.getContext("2d").putImageData(i,0,0),t(n.toDataURL("image/jpeg",a/100))}else e(new Error("object is not valid imageData"));var r})}var c=Object.getOwnPropertySymbols,h=Object.prototype.hasOwnProperty,l=Object.prototype.propertyIsEnumerable;var e,b=function(){try{if(!Object.assign)return;var t=new String("abc");if(t[5]="de","5"===Object.getOwnPropertyNames(t)[0])return;for(var e={},n=0;n<10;n++)e["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(e).map(function(t){return e[t]}).join(""))return;var r={};return"abcdefghijklmnopqrst".split("").forEach(function(t){r[t]=t}),"abcdefghijklmnopqrst"!==Object.keys(Object.assign({},r)).join("")?void 0:1}catch(t){return}}()?Object.assign:function(t,e){for(var n,r,i=arguments,a=function(t){if(null==t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}(t),o=1;o<arguments.length;o++){for(var s in n=Object(i[o]))h.call(n,s)&&(a[s]=n[s]);if(c){r=c(n);for(var u=0;u<r.length;u++)l.call(n,r[u])&&(a[r[u]]=n[r[u]])}}return a},rt="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function it(){throw new Error("Dynamic requires are not currently supported by rollup-plugin-commonjs")}return(function(t){t.exports=function(){function r(t){var e=typeof t;return t!==null&&(e==="object"||e==="function")}function u(t){return typeof t==="function"}var t=void 0;if(Array.isArray){t=Array.isArray}else{t=function(t){return Object.prototype.toString.call(t)==="[object Array]"}}var n=t,i=0,e=void 0,a=void 0,o=function t(e,n){w[i]=e;w[i+1]=n;i+=2;if(i===2){if(a){a(_)}else{E()}}};function s(t){a=t}function f(t){o=t}var c=typeof window!=="undefined"?window:undefined,h=c||{},l=h.MutationObserver||h.WebKitMutationObserver,d=typeof self==="undefined"&&typeof process!=="undefined"&&{}.toString.call(process)==="[object process]",p=typeof Uint8ClampedArray!=="undefined"&&typeof importScripts!=="undefined"&&typeof MessageChannel!=="undefined";function g(){return function(){return process.nextTick(_)}}function v(){if(typeof e!=="undefined"){return function(){e(_)}}return b()}function m(){var t=0;var e=new l(_);var n=document.createTextNode("");e.observe(n,{characterData:true});return function(){n.data=t=++t%2}}function y(){var t=new MessageChannel;t.port1.onmessage=_;return function(){return t.port2.postMessage(0)}}function b(){var t=setTimeout;return function(){return t(_,1)}}var w=new Array(1e3);function _(){for(var t=0;t<i;t+=2){var e=w[t];var n=w[t+1];e(n);w[t]=undefined;w[t+1]=undefined}i=0}function j(){try{var t=Function("return this")().require("vertx");e=t.runOnLoop||t.runOnContext;return v()}catch(t){return b()}}var E=void 0;if(d){E=g()}else if(l){E=m()}else if(p){E=y()}else if(c===undefined&&typeof it==="function"){E=j()}else{E=b()}function M(t,e){var n=this;var r=new this.constructor(A);if(r[O]===undefined){K(r)}var i=n._state;if(i){var a=arguments[i-1];o(function(){return q(i,r,a,n._result)})}else{W(n,r,t,e)}return r}function D(t){var e=this;if(t&&typeof t==="object"&&t.constructor===e){return t}var n=new e(A);U(n,t);return n}var O=Math.random().toString(36).substring(2);function A(){}var P=void 0,I=1,x=2;function T(){return new TypeError("You cannot resolve a promise with itself")}function L(){return new TypeError("A promises callback cannot return that same promise.")}function S(t,e,n,r){try{t.call(e,n,r)}catch(t){return t}}function C(t,r,i){o(function(e){var n=false;var t=S(i,r,function(t){if(n){return}n=true;if(r!==t){U(e,t)}else{H(e,t)}},function(t){if(n){return}n=true;N(e,t)},"Settle: "+(e._label||" unknown promise"));if(!n&&t){n=true;N(e,t)}},t)}function B(e,t){if(t._state===I){H(e,t._result)}else if(t._state===x){N(e,t._result)}else{W(t,undefined,function(t){return U(e,t)},function(t){return N(e,t)})}}function k(t,e,n){if(e.constructor===t.constructor&&n===M&&e.constructor.resolve===D){B(t,e)}else{if(n===undefined){H(t,e)}else if(u(n)){C(t,e,n)}else{H(t,e)}}}function U(e,t){if(e===t){N(e,T())}else if(r(t)){var n=void 0;try{n=t.then}catch(t){N(e,t);return}k(e,t,n)}else{H(e,t)}}function R(t){if(t._onerror){t._onerror(t._result)}$(t)}function H(t,e){if(t._state!==P){return}t._result=e;t._state=I;if(t._subscribers.length!==0){o($,t)}}function N(t,e){if(t._state!==P){return}t._state=x;t._result=e;o(R,t)}function W(t,e,n,r){var i=t._subscribers;var a=i.length;t._onerror=null;i[a]=e;i[a+I]=n;i[a+x]=r;if(a===0&&t._state){o($,t)}}function $(t){var e=t._subscribers;var n=t._state;if(e.length===0){return}var r=void 0,i=void 0,a=t._result;for(var o=0;o<e.length;o+=3){r=e[o];i=e[o+n];if(r){q(n,r,i,a)}else{i(a)}}t._subscribers.length=0}function q(t,e,n,r){var i=u(n),a=void 0,o=void 0,s=true;if(i){try{a=n(r)}catch(t){s=false;o=t}if(e===a){N(e,L());return}}else{a=r}if(e._state!==P);else if(i&&s){U(e,a)}else if(s===false){N(e,o)}else if(t===I){H(e,a)}else if(t===x){N(e,a)}}function F(n,t){try{t(function t(e){U(n,e)},function t(e){N(n,e)})}catch(t){N(n,t)}}var Y=0;function J(){return Y++}function K(t){t[O]=Y++;t._state=undefined;t._result=undefined;t._subscribers=[]}function z(){return new Error("Array Methods must be provided an Array")}var G=function(){function t(t,e){this._instanceConstructor=t;this.promise=new t(A);if(!this.promise[O]){K(this.promise)}if(n(e)){this.length=e.length;this._remaining=e.length;this._result=new Array(this.length);if(this.length===0){H(this.promise,this._result)}else{this.length=this.length||0;this._enumerate(e);if(this._remaining===0){H(this.promise,this._result)}}}else{N(this.promise,z())}}t.prototype._enumerate=function t(e){for(var n=0;this._state===P&&n<e.length;n++){this._eachEntry(e[n],n)}};t.prototype._eachEntry=function t(e,n){var r=this._instanceConstructor;var i=r.resolve;if(i===D){var a=void 0;var o=void 0;var s=false;try{a=e.then}catch(t){s=true;o=t}if(a===M&&e._state!==P){this._settledAt(e._state,n,e._result)}else if(typeof a!=="function"){this._remaining--;this._result[n]=e}else if(r===et){var u=new r(A);if(s){N(u,o)}else{k(u,e,a)}this._willSettleAt(u,n)}else{this._willSettleAt(new r(function(t){return t(e)}),n)}}else{this._willSettleAt(i(e),n)}};t.prototype._settledAt=function t(e,n,r){var i=this.promise;if(i._state===P){this._remaining--;if(e===x){N(i,r)}else{this._result[n]=r}}if(this._remaining===0){H(i,this._result)}};t.prototype._willSettleAt=function t(e,n){var r=this;W(e,undefined,function(t){return r._settledAt(I,n,t)},function(t){return r._settledAt(x,n,t)})};return t}();function Q(t){return new G(this,t).promise}function V(i){var a=this;if(n(i))return new a(function(t,e){for(var n=i.length,r=0;r<n;r++)a.resolve(i[r]).then(t,e)});else return new a(function(t,e){return e(new TypeError("You must pass an array to race."))})}function X(t){var e=new this(A);return N(e,t),e}function Z(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function tt(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}var et=function(){function e(t){this[O]=J();this._result=this._state=undefined;this._subscribers=[];if(A!==t){typeof t!=="function"&&Z();this instanceof e?F(this,t):tt()}}e.prototype.catch=function t(e){return this.then(null,e)};e.prototype.finally=function t(e){var n=this;var r=n.constructor;if(u(e)){return n.then(function(t){return r.resolve(e()).then(function(){return t})},function(t){return r.resolve(e()).then(function(){throw t})})}return n.then(e,e)};return e}();function nt(){var t=void 0;if(void 0!==rt)t=rt;else if("undefined"!=typeof self)t=self;else try{t=Function("return this")()}catch(t){throw new Error("polyfill failed because global object is unavailable in this environment")}var e=t.Promise;if(e){var n=null;try{n=Object.prototype.toString.call(e.resolve())}catch(t){}if("[object Promise]"===n&&!e.cast)return}t.Promise=et}return et.prototype.then=M,et.all=function(t){return new G(this,t).promise},et.race=function(i){var a=this;return n(i)?new a(function(t,e){for(var n=i.length,r=0;r<n;r++)a.resolve(i[r]).then(t,e)}):new a(function(t,e){return e(new TypeError("You must pass an array to race."))})},et.resolve=D,et.reject=function(t){var e=new this(A);return N(e,t),e},et._setScheduler=function(t){a=t},et._setAsap=function(t){o=t},et._asap=o,et.polyfill=function(){var t=void 0;if(void 0!==rt)t=rt;else if("undefined"!=typeof self)t=self;else try{t=Function("return this")()}catch(t){throw new Error("polyfill failed because global object is unavailable in this environment")}var e=t.Promise;if(e){var n=null;try{n=Object.prototype.toString.call(e.resolve())}catch(t){}if("[object Promise]"===n&&!e.cast)return}t.Promise=et},et.Promise=et}()}(e={exports:{}}),e.exports).polyfill(),function(r){var a,o;r=p(r);var s=new Worker(URL.createObjectURL(new Blob(['function isImageData(a){return a&&"number"==typeof a.width&&"number"==typeof a.height&&a.data&&"number"==typeof a.data.length&&"object"==typeof a.data}var base64Chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",base64Map=base64Chars.split(""),reversedBase64Map={};base64Map.forEach(function(a,e){reversedBase64Map[a]=e});var maps={base64Map:base64Map,reversedBase64Map:reversedBase64Map},reversedBase64Map$1=maps.reversedBase64Map;function base64ToByteArray(a){for(var e,s=[],t=a.replace("data:image/jpeg;base64,",""),r=0,i=t.length;r<i;r++){t[r];var p=reversedBase64Map$1[t[r]];switch(r%4){case 1:s.push(e<<2|p>>4);break;case 2:s.push((15&e)<<4|p>>2);break;case 3:s.push((3&e)<<6|p)}e=p}return s}function jpgHeaderLength(a){for(var e=417,s=0,t=a.length;s<t;s++)if(255===a[s]&&218===a[s+1]){e=s+2;break}return e}function glitchByteArray(a,e,s,t){for(var r=jpgHeaderLength(a),i=a.length-r-4,p=s/100,n=e/100,h=0;h<t;h++){var g=i/t*h|0,o=g+((i/t*(h+1)|0)-g)*n|0;i<o&&(o=i),a[~~(r+o)]=~~(256*p)}return a}var base64Map$1=maps.base64Map;function byteArrayToBase64(a){for(var e,s,t=["data:image/jpeg;base64,"],r=0,i=a.length;r<i;r++){var p=a[r];switch(e=r%3){case 0:t.push(base64Map$1[p>>2]);break;case 1:t.push(base64Map$1[(3&s)<<4|p>>4]);break;case 2:t.push(base64Map$1[(15&s)<<2|p>>6]),t.push(base64Map$1[63&p])}s=p}return 0===e?(t.push(base64Map$1[(3&s)<<4]),t.push("==")):1===e&&(t.push(base64Map$1[(15&s)<<2]),t.push("=")),t.join("")}function glitchImageData(a,e,s){if(isImageData(a))return byteArrayToBase64(glitchByteArray(base64ToByteArray(e),s.seed,s.amount,s.iterations));throw new Error("glitchImageData: imageData seems to be corrupt.")}function fail(a){self.postMessage({err:a.message||a})}function success(a){self.postMessage({base64URL:a})}onmessage=function(a){var e=a.data.imageData,s=a.data.params,t=a.data.base64URL;if(e&&t&&s)try{void 0===e.width&&"number"==typeof a.data.imageDataWidth&&(e.width=a.data.imageDataWidth),void 0===e.height&&"number"==typeof a.data.imageDataHeight&&(e.height=a.data.imageDataHeight),success(glitchImageData(e,t,s))}catch(a){fail(a)}else a.data.imageData?fail("Parameters are missing."):fail("ImageData is missing.");self.close()};'],{type:"text/javascript"}))),e={getParams:function(){return r},getInput:t,getOutput:u},n={fromImageData:function(t){return c(f,t)},fromImage:function(t){return c(g,t)}},i={toImage:function(t){return h(v,t,!0)},toDataURL:function(t){return h(f)},toImageData:function(t){return h(m,t,!0)}};function t(){var t=b({},e);return a||b(t,n),t}function u(){var t=b({},e);return o||b(t,i),t}function f(t){return t}function c(n,r,i){return a=function(){return new Promise(function(t,e){if(i)n(r,t,e);else if(n===f)t(r);else try{t(n(r,t,e))}catch(t){e(t)}})},(l()?d:u)()}function h(r,i,a){return o=function(n){return new Promise(function(t,e){a?r(n,i,t,e):r===f?t(n):r(n,i).then(t,e)})},(l()?d:t)()}function l(){return a&&o}function d(){return new Promise(function(e,n){a().then(function(t){return n=t,o=r,new Promise(function(t,e){y(n,o.quality).then(function(t){return r=n,i=t,a=o,new Promise(function(e,n){s.addEventListener("message",function(t){t.data&&t.data.base64URL?e(t.data.base64URL):t.data&&t.data.err?n(t.data.err):n(t)}),s.postMessage({params:a,base64URL:i,imageData:r,imageDataWidth:r.width,imageDataHeight:r.height})});var r,i,a},e).then(t,e)});var n,o},n).then(function(t){o(t).then(e,n)},n)})}return t()}}); |
@@ -1,1 +0,1 @@ | ||
function clamp(e,a,t){return e<a?a:e>t?t:e}function clone(e){let a=!1;if(void 0!==e)try{a=JSON.parse(JSON.stringify(e))}catch(e){}return a}function sanitizeInput(e){return"object"!=typeof(e=clone(e))&&(e={}),Object.keys(defaultParams).filter(e=>"iterations"!==e).forEach(a=>{"number"!=typeof e[a]||isNaN(e[a])?e[a]=defaultParams[a]:e[a]=clamp(e[a],0,100),e[a]=Math.round(e[a])}),("number"!=typeof e.iterations||isNaN(e.iterations)||e.iterations<=0)&&(e.iterations=defaultParams.iterations),e.iterations=Math.round(e.iterations),e}function imageToImageData(e){if(e instanceof HTMLImageElement){if(!e.naturalWidth||!e.naturalHeight||!1===e.complete)throw new Error("This this image hasn't finished loading: "+e.src);const a=new Canvas(e.naturalWidth,e.naturalHeight),t=a.getContext("2d");t.drawImage(e,0,0,a.width,a.height);const n=t.getImageData(0,0,a.width,a.height);return n.data&&n.data.length&&(void 0===n.width&&(n.width=e.naturalWidth),void 0===n.height&&(n.height=e.naturalHeight)),n}throw new Error("This object does not seem to be an image.")}function loadBase64Image(e){return new Promise((a,t)=>{const n=new Image$1;n.onload=(()=>{a(n)}),n.onerror=t;try{n.src=e}catch(e){t(e)}})}function base64URLToImage(e,a,t,n){loadBase64Image(e).then(t,n)}function getImageSize(e){return{width:e.width||e.naturalWidth,height:e.height||e.naturalHeight}}function canvasFromImage(e){const a=getImageSize(e),t=new Canvas(a.width,a.height),n=t.getContext("2d");return n.drawImage(e,0,0,a.width,a.height),{canvas:t,ctx:n}}function base64URLToImageData(e,a,t,n){loadBase64Image(e).then(e=>{const a=getImageSize(e),n=canvasFromImage(e).ctx.getImageData(0,0,a.width,a.height);n.width||(n.width=a.width),n.height||(n.height=a.height),t(n)},n)}function isImageData(e){return e&&"number"==typeof e.width&&"number"==typeof e.height&&e.data&&"number"==typeof e.data.length&&"object"==typeof e.data}function imageDataToBase64(e,a){return new Promise((t,n)=>{if(isImageData(e)){const n=new Canvas(e.width,e.height);n.getContext("2d").putImageData(e,0,0),t(n.toDataURL("image/jpeg",a/100))}else n(new Error("object is not valid imageData"))})}function glitch(e){function a(){const e=objectAssign({},d);return c||objectAssign(e,f),e}function t(){const e=objectAssign({},d);return u||objectAssign(e,l),e}function n(e){return e}function s(e,a,s){return c=(()=>new Promise((t,i)=>{if(s)e(a,t,i);else if(e===n)t(a);else try{t(e(a,t,i))}catch(e){i(e)}})),r()?o():t()}function i(e,t,s){return u=(a=>new Promise((i,r)=>{s?e(a,t,i,r):e===n?i(a):e(a,t).then(i,r)})),r()?o():a()}function r(){return c&&u}function o(){return new Promise((a,t)=>{c().then(a=>h(a,e),t).then(e=>{u(e).then(a,t)},t)})}function h(e,a){return new Promise((t,n)=>{imageDataToBase64(e,a.quality).then(t=>g(e,t,a),n).then(t,n)})}function g(e,a,t){return new Promise((n,s)=>{m.addEventListener("message",e=>{e.data&&e.data.base64URL?n(e.data.base64URL):s(e.data&&e.data.err?e.data.err:e)}),m.postMessage({params:t,base64URL:a,imageData:e,imageDataWidth:e.width,imageDataHeight:e.height})})}e=sanitizeInput(e);let c,u;const m=new Worker(URL.createObjectURL(new Blob(['function isImageData(a){return a&&"number"==typeof a.width&&"number"==typeof a.height&&a.data&&"number"==typeof a.data.length&&"object"==typeof a.data}function base64ToByteArray(a){const e=[];let s;const t=a.replace("data:image/jpeg;base64,","");for(var r=0,i=t.length;r<i;r++){t[r];const a=reversedBase64Map$1[t[r]];switch(r%4){case 1:e.push(s<<2|a>>4);break;case 2:e.push((15&s)<<4|a>>2);break;case 3:e.push((3&s)<<6|a)}s=a}return e}function jpgHeaderLength(a){let e=417;for(let s=0,t=a.length;s<t;s++)if(255===a[s]&&218===a[s+1]){e=s+2;break}return e}function glitchByteArray(a,e,s,t){const r=jpgHeaderLength(a),i=a.length-r-4,n=s/100,p=e/100;for(var o=0;o<t;o++){const e=i/t*o|0;let s=e+((i/t*(o+1)|0)-e)*p|0;s>i&&(s=i),a[~~(r+s)]=~~(256*n)}return a}function byteArrayToBase64(a){const e=["data:image/jpeg;base64,"];let s,t;for(let r=0,i=a.length;r<i;r++){const i=a[r];switch(s=r%3){case 0:e.push(base64Map$1[i>>2]);break;case 1:e.push(base64Map$1[(3&t)<<4|i>>4]);break;case 2:e.push(base64Map$1[(15&t)<<2|i>>6]),e.push(base64Map$1[63&i])}t=i}return 0===s?(e.push(base64Map$1[(3&t)<<4]),e.push("==")):1===s&&(e.push(base64Map$1[(15&t)<<2]),e.push("=")),e.join("")}function glitchImageData(a,e,s){if(isImageData(a))return byteArrayToBase64(glitchByteArray(base64ToByteArray(e),s.seed,s.amount,s.iterations));throw new Error("glitchImageData: imageData seems to be corrupt.")}function fail(a){self.postMessage({err:a.message||a})}function success(a){self.postMessage({base64URL:a})}const base64Chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",base64Map=base64Chars.split(""),reversedBase64Map={};base64Map.forEach((a,e)=>{reversedBase64Map[a]=e});var maps={base64Map:base64Map,reversedBase64Map:reversedBase64Map};const reversedBase64Map$1=maps.reversedBase64Map,base64Map$1=maps.base64Map;onmessage=(a=>{const e=a.data.imageData,s=a.data.params,t=a.data.base64URL;if(e&&t&&s)try{void 0===e.width&&"number"==typeof a.data.imageDataWidth&&(e.width=a.data.imageDataWidth),void 0===e.height&&"number"==typeof a.data.imageDataHeight&&(e.height=a.data.imageDataHeight),success(glitchImageData(e,t,s))}catch(a){fail(a)}else fail(a.data.imageData?"Parameters are missing.":"ImageData is missing.");self.close()});'],{type:"text/javascript"}))),d={getParams:function(){return e},getInput:a,getOutput:t},f={fromImageData:function(e){return s(n,e)},fromImage:function(e){return s(imageToImageData,e)}},l={toImage:function(e){return i(base64URLToImage,e,!0)},toDataURL:function(e){return i(n)},toImageData:function(e){return i(base64URLToImageData,e,!0)}};return a()}var defaultParams={amount:35,iterations:20,quality:30,seed:25};class Canvas{constructor(e=300,a=150){"undefined"==typeof window?(this.canvasEl={width:e,height:a},this.ctx=null):(this.canvasEl=document.createElement("canvas"),this.canvasEl.width=e,this.canvasEl.height=a,this.ctx=this.canvasEl.getContext("2d"))}getContext(){return this.ctx}toDataURL(e,a,t){if("function"!=typeof t)return this.canvasEl.toDataURL(e,a);t(this.canvasEl.toDataURL(e,a))}get width(){return this.canvasEl.width}set width(e){this.canvasEl.width=e}get height(){return this.canvasEl.height}set height(e){this.canvasEl.height=e}}"undefined"!=typeof window&&(Canvas.Image=Image);const Image$1=Canvas.Image,objectAssign=Object.assign;export default glitch; | ||
function clamp(e,a,t){return e<a?a:e>t?t:e}function clone(e){let a=!1;if(void 0!==e)try{a=JSON.parse(JSON.stringify(e))}catch(e){}return a}var defaultParams={amount:35,iterations:20,quality:30,seed:25};function sanitizeInput(e){return"object"!=typeof(e=clone(e))&&(e={}),Object.keys(defaultParams).filter(e=>"iterations"!==e).forEach(a=>{"number"!=typeof e[a]||isNaN(e[a])?e[a]=defaultParams[a]:e[a]=clamp(e[a],0,100),e[a]=Math.round(e[a])}),("number"!=typeof e.iterations||isNaN(e.iterations)||e.iterations<=0)&&(e.iterations=defaultParams.iterations),e.iterations=Math.round(e.iterations),e}class Canvas{constructor(e=300,a=150){"undefined"==typeof window?(this.canvasEl={width:e,height:a},this.ctx=null):(this.canvasEl=document.createElement("canvas"),this.canvasEl.width=e,this.canvasEl.height=a,this.ctx=this.canvasEl.getContext("2d"))}getContext(){return this.ctx}toDataURL(e,a,t){if("function"!=typeof t)return this.canvasEl.toDataURL(e,a);t(this.canvasEl.toDataURL(e,a))}get width(){return this.canvasEl.width}set width(e){this.canvasEl.width=e}get height(){return this.canvasEl.height}set height(e){this.canvasEl.height=e}}function imageToImageData(e){if(e instanceof HTMLImageElement){if(!e.naturalWidth||!e.naturalHeight||!1===e.complete)throw new Error("This this image hasn't finished loading: "+e.src);const a=new Canvas(e.naturalWidth,e.naturalHeight),t=a.getContext("2d");t.drawImage(e,0,0,a.width,a.height);const n=t.getImageData(0,0,a.width,a.height);return n.data&&n.data.length&&(void 0===n.width&&(n.width=e.naturalWidth),void 0===n.height&&(n.height=e.naturalHeight)),n}throw new Error("This object does not seem to be an image.")}"undefined"!=typeof window&&(Canvas.Image=Image);const Image$1=Canvas.Image;function loadBase64Image(e){return new Promise((a,t)=>{const n=new Image$1;n.onload=(()=>{a(n)}),n.onerror=t;try{n.src=e}catch(e){t(e)}})}function base64URLToImage(e,a,t,n){loadBase64Image(e).then(t,n)}function getImageSize(e){return{width:e.width||e.naturalWidth,height:e.height||e.naturalHeight}}function canvasFromImage(e){const a=getImageSize(e),t=new Canvas(a.width,a.height),n=t.getContext("2d");return n.drawImage(e,0,0,a.width,a.height),{canvas:t,ctx:n}}function base64URLToImageData(e,a,t,n){loadBase64Image(e).then(e=>{const a=getImageSize(e),n=canvasFromImage(e).ctx.getImageData(0,0,a.width,a.height);n.width||(n.width=a.width),n.height||(n.height=a.height),t(n)},n)}function isImageData(e){return e&&"number"==typeof e.width&&"number"==typeof e.height&&e.data&&"number"==typeof e.data.length&&"object"==typeof e.data}function imageDataToBase64(e,a){return new Promise((t,n)=>{if(isImageData(e)){const n=new Canvas(e.width,e.height);n.getContext("2d").putImageData(e,0,0),t(n.toDataURL("image/jpeg",a/100))}else n(new Error("object is not valid imageData"))})}const objectAssign=Object.assign;function glitch(e){let a,t;e=sanitizeInput(e);const n=new Worker(URL.createObjectURL(new Blob(['function isImageData(a){return a&&"number"==typeof a.width&&"number"==typeof a.height&&a.data&&"number"==typeof a.data.length&&"object"==typeof a.data}const base64Chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",base64Map=base64Chars.split(""),reversedBase64Map={};base64Map.forEach((a,e)=>{reversedBase64Map[a]=e});var maps={base64Map:base64Map,reversedBase64Map:reversedBase64Map};const reversedBase64Map$1=maps.reversedBase64Map;function base64ToByteArray(a){const e=[];let s;const t=a.replace("data:image/jpeg;base64,","");for(var r=0,i=t.length;r<i;r++){t[r];const a=reversedBase64Map$1[t[r]];switch(r%4){case 1:e.push(s<<2|a>>4);break;case 2:e.push((15&s)<<4|a>>2);break;case 3:e.push((3&s)<<6|a)}s=a}return e}function jpgHeaderLength(a){let e=417;for(let s=0,t=a.length;s<t;s++)if(255===a[s]&&218===a[s+1]){e=s+2;break}return e}function glitchByteArray(a,e,s,t){const r=jpgHeaderLength(a),i=a.length-r-4,n=s/100,p=e/100;for(var o=0;o<t;o++){const e=i/t*o|0;let s=e+((i/t*(o+1)|0)-e)*p|0;s>i&&(s=i),a[~~(r+s)]=~~(256*n)}return a}const base64Map$1=maps.base64Map;function byteArrayToBase64(a){const e=["data:image/jpeg;base64,"];let s,t;for(let r=0,i=a.length;r<i;r++){const i=a[r];switch(s=r%3){case 0:e.push(base64Map$1[i>>2]);break;case 1:e.push(base64Map$1[(3&t)<<4|i>>4]);break;case 2:e.push(base64Map$1[(15&t)<<2|i>>6]),e.push(base64Map$1[63&i])}t=i}return 0===s?(e.push(base64Map$1[(3&t)<<4]),e.push("==")):1===s&&(e.push(base64Map$1[(15&t)<<2]),e.push("=")),e.join("")}function glitchImageData(a,e,s){if(isImageData(a)){return byteArrayToBase64(glitchByteArray(base64ToByteArray(e),s.seed,s.amount,s.iterations))}throw new Error("glitchImageData: imageData seems to be corrupt.")}function fail(a){self.postMessage({err:a.message||a})}function success(a){self.postMessage({base64URL:a})}onmessage=(a=>{const e=a.data.imageData,s=a.data.params,t=a.data.base64URL;if(e&&t&&s)try{void 0===e.width&&"number"==typeof a.data.imageDataWidth&&(e.width=a.data.imageDataWidth),void 0===e.height&&"number"==typeof a.data.imageDataHeight&&(e.height=a.data.imageDataHeight),success(glitchImageData(e,t,s))}catch(a){fail(a)}else a.data.imageData?fail("Parameters are missing."):fail("ImageData is missing.");self.close()});'],{type:"text/javascript"}))),s={getParams:function(){return e},getInput:o,getOutput:h},i={fromImageData:function(e){return c(g,e)},fromImage:function(e){return c(imageToImageData,e)}},r={toImage:function(e){return u(base64URLToImage,e,!0)},toDataURL:function(e){return u(g)},toImageData:function(e){return u(base64URLToImageData,e,!0)}};function o(){const e=objectAssign({},s);return a||objectAssign(e,i),e}function h(){const e=objectAssign({},s);return t||objectAssign(e,r),e}function g(e){return e}function c(e,t,n){return a=(()=>new Promise((a,s)=>{if(n)e(t,a,s);else if(e===g)a(t);else try{a(e(t,a,s))}catch(e){s(e)}})),m()?d():h()}function u(e,a,n){return t=(t=>new Promise((s,i)=>{n?e(t,a,s,i):e===g?s(t):e(t,a).then(s,i)})),m()?d():o()}function m(){return a&&t}function d(){return new Promise((s,i)=>{a().then(a=>(function(e,a){return new Promise((t,s)=>{imageDataToBase64(e,a.quality).then(t=>(function(e,a,t){return new Promise((s,i)=>{n.addEventListener("message",e=>{e.data&&e.data.base64URL?s(e.data.base64URL):e.data&&e.data.err?i(e.data.err):i(e)}),n.postMessage({params:t,base64URL:a,imageData:e,imageDataWidth:e.width,imageDataHeight:e.height})})})(e,t,a),s).then(t,s)})})(a,e),i).then(e=>{t(e).then(s,i)},i)})}return o()}export default glitch; |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self,t.glitch=e())}(this,function(){"use strict";function t(t,e,a){return t<e?e:t>a?a:t}function e(t){let e=!1;if(void 0!==t)try{e=JSON.parse(JSON.stringify(t))}catch(t){}return e}function a(a){return"object"!=typeof(a=e(a))&&(a={}),Object.keys(g).filter(t=>"iterations"!==t).forEach(e=>{"number"!=typeof a[e]||isNaN(a[e])?a[e]=g[e]:a[e]=t(a[e],0,100),a[e]=Math.round(a[e])}),("number"!=typeof a.iterations||isNaN(a.iterations)||a.iterations<=0)&&(a.iterations=g.iterations),a.iterations=Math.round(a.iterations),a}function n(t){if(t instanceof HTMLImageElement){if(!t.naturalWidth||!t.naturalHeight||!1===t.complete)throw new Error("This this image hasn't finished loading: "+t.src);const e=new d(t.naturalWidth,t.naturalHeight),a=e.getContext("2d");a.drawImage(t,0,0,e.width,e.height);const n=a.getImageData(0,0,e.width,e.height);return n.data&&n.data.length&&(void 0===n.width&&(n.width=t.naturalWidth),void 0===n.height&&(n.height=t.naturalHeight)),n}throw new Error("This object does not seem to be an image.")}function i(t){return new Promise((e,a)=>{const n=new f;n.onload=(()=>{e(n)}),n.onerror=a;try{n.src=t}catch(t){a(t)}})}function s(t,e,a,n){i(t).then(a,n)}function r(t){return{width:t.width||t.naturalWidth,height:t.height||t.naturalHeight}}function o(t){const e=r(t),a=new d(e.width,e.height),n=a.getContext("2d");return n.drawImage(t,0,0,e.width,e.height),{canvas:a,ctx:n}}function h(t,e,a,n){i(t).then(t=>{const e=r(t),n=o(t).ctx.getImageData(0,0,e.width,e.height);n.width||(n.width=e.width),n.height||(n.height=e.height),a(n)},n)}function c(t){return t&&"number"==typeof t.width&&"number"==typeof t.height&&t.data&&"number"==typeof t.data.length&&"object"==typeof t.data}function u(t,e){return new Promise((a,n)=>{if(c(t)){const n=new d(t.width,t.height);n.getContext("2d").putImageData(t,0,0),a(n.toDataURL("image/jpeg",e/100))}else n(new Error("object is not valid imageData"))})}var g={amount:35,iterations:20,quality:30,seed:25};class d{constructor(t=300,e=150){"undefined"==typeof window?(this.canvasEl={width:t,height:e},this.ctx=null):(this.canvasEl=document.createElement("canvas"),this.canvasEl.width=t,this.canvasEl.height=e,this.ctx=this.canvasEl.getContext("2d"))}getContext(){return this.ctx}toDataURL(t,e,a){if("function"!=typeof a)return this.canvasEl.toDataURL(t,e);a(this.canvasEl.toDataURL(t,e))}get width(){return this.canvasEl.width}set width(t){this.canvasEl.width=t}get height(){return this.canvasEl.height}set height(t){this.canvasEl.height=t}}"undefined"!=typeof window&&(d.Image=Image);const f=d.Image,m=Object.assign;return function(t){function e(){const t=m({},y);return l||m(t,v),t}function i(){const t=m({},y);return b||m(t,D),t}function r(t){return t}function o(t,e,a){return l=(()=>new Promise((n,i)=>{if(a)t(e,n,i);else if(t===r)n(e);else try{n(t(e,n,i))}catch(t){i(t)}})),g()?d():i()}function c(t,a,n){return b=(e=>new Promise((i,s)=>{n?t(e,a,i,s):t===r?i(e):t(e,a).then(i,s)})),g()?d():e()}function g(){return l&&b}function d(){return new Promise((e,a)=>{l().then(e=>f(e,t),a).then(t=>{b(t).then(e,a)},a)})}function f(t,e){return new Promise((a,n)=>{u(t,e.quality).then(a=>p(t,a,e),n).then(a,n)})}function p(t,e,a){return new Promise((n,i)=>{w.addEventListener("message",t=>{t.data&&t.data.base64URL?n(t.data.base64URL):i(t.data&&t.data.err?t.data.err:t)}),w.postMessage({params:a,base64URL:e,imageData:t,imageDataWidth:t.width,imageDataHeight:t.height})})}t=a(t);let l,b;const w=new Worker(URL.createObjectURL(new Blob(['function isImageData(a){return a&&"number"==typeof a.width&&"number"==typeof a.height&&a.data&&"number"==typeof a.data.length&&"object"==typeof a.data}function base64ToByteArray(a){const e=[];let s;const t=a.replace("data:image/jpeg;base64,","");for(var r=0,i=t.length;r<i;r++){t[r];const a=reversedBase64Map$1[t[r]];switch(r%4){case 1:e.push(s<<2|a>>4);break;case 2:e.push((15&s)<<4|a>>2);break;case 3:e.push((3&s)<<6|a)}s=a}return e}function jpgHeaderLength(a){let e=417;for(let s=0,t=a.length;s<t;s++)if(255===a[s]&&218===a[s+1]){e=s+2;break}return e}function glitchByteArray(a,e,s,t){const r=jpgHeaderLength(a),i=a.length-r-4,n=s/100,p=e/100;for(var o=0;o<t;o++){const e=i/t*o|0;let s=e+((i/t*(o+1)|0)-e)*p|0;s>i&&(s=i),a[~~(r+s)]=~~(256*n)}return a}function byteArrayToBase64(a){const e=["data:image/jpeg;base64,"];let s,t;for(let r=0,i=a.length;r<i;r++){const i=a[r];switch(s=r%3){case 0:e.push(base64Map$1[i>>2]);break;case 1:e.push(base64Map$1[(3&t)<<4|i>>4]);break;case 2:e.push(base64Map$1[(15&t)<<2|i>>6]),e.push(base64Map$1[63&i])}t=i}return 0===s?(e.push(base64Map$1[(3&t)<<4]),e.push("==")):1===s&&(e.push(base64Map$1[(15&t)<<2]),e.push("=")),e.join("")}function glitchImageData(a,e,s){if(isImageData(a))return byteArrayToBase64(glitchByteArray(base64ToByteArray(e),s.seed,s.amount,s.iterations));throw new Error("glitchImageData: imageData seems to be corrupt.")}function fail(a){self.postMessage({err:a.message||a})}function success(a){self.postMessage({base64URL:a})}const base64Chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",base64Map=base64Chars.split(""),reversedBase64Map={};base64Map.forEach((a,e)=>{reversedBase64Map[a]=e});var maps={base64Map:base64Map,reversedBase64Map:reversedBase64Map};const reversedBase64Map$1=maps.reversedBase64Map,base64Map$1=maps.base64Map;onmessage=(a=>{const e=a.data.imageData,s=a.data.params,t=a.data.base64URL;if(e&&t&&s)try{void 0===e.width&&"number"==typeof a.data.imageDataWidth&&(e.width=a.data.imageDataWidth),void 0===e.height&&"number"==typeof a.data.imageDataHeight&&(e.height=a.data.imageDataHeight),success(glitchImageData(e,t,s))}catch(a){fail(a)}else fail(a.data.imageData?"Parameters are missing.":"ImageData is missing.");self.close()});'],{type:"text/javascript"}))),y={getParams:function(){return t},getInput:e,getOutput:i},v={fromImageData:function(t){return o(r,t)},fromImage:function(t){return o(n,t)}},D={toImage:function(t){return c(s,t,!0)},toDataURL:function(t){return c(r)},toImageData:function(t){return c(h,t,!0)}};return e()}}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).glitch=e()}(this,function(){"use strict";var t={amount:35,iterations:20,quality:30,seed:25};function e(e){var a,n,i;return"object"!=typeof(e=function(t){let e=!1;if(void 0!==t)try{e=JSON.parse(JSON.stringify(t))}catch(t){}return e}(e))&&(e={}),Object.keys(t).filter(t=>"iterations"!==t).forEach(s=>{"number"!=typeof e[s]||isNaN(e[s])?e[s]=t[s]:e[s]=(a=e[s],i=100,a<(n=0)?n:a>i?i:a),e[s]=Math.round(e[s])}),("number"!=typeof e.iterations||isNaN(e.iterations)||e.iterations<=0)&&(e.iterations=t.iterations),e.iterations=Math.round(e.iterations),e}class a{constructor(t=300,e=150){"undefined"==typeof window?(this.canvasEl={width:t,height:e},this.ctx=null):(this.canvasEl=document.createElement("canvas"),this.canvasEl.width=t,this.canvasEl.height=e,this.ctx=this.canvasEl.getContext("2d"))}getContext(){return this.ctx}toDataURL(t,e,a){if("function"!=typeof a)return this.canvasEl.toDataURL(t,e);a(this.canvasEl.toDataURL(t,e))}get width(){return this.canvasEl.width}set width(t){this.canvasEl.width=t}get height(){return this.canvasEl.height}set height(t){this.canvasEl.height=t}}function n(t){if(t instanceof HTMLImageElement){if(!t.naturalWidth||!t.naturalHeight||!1===t.complete)throw new Error("This this image hasn't finished loading: "+t.src);const e=new a(t.naturalWidth,t.naturalHeight),n=e.getContext("2d");n.drawImage(t,0,0,e.width,e.height);const i=n.getImageData(0,0,e.width,e.height);return i.data&&i.data.length&&(void 0===i.width&&(i.width=t.naturalWidth),void 0===i.height&&(i.height=t.naturalHeight)),i}throw new Error("This object does not seem to be an image.")}"undefined"!=typeof window&&(a.Image=Image);const i=a.Image;function s(t){return new Promise((e,a)=>{const n=new i;n.onload=(()=>{e(n)}),n.onerror=a;try{n.src=t}catch(t){a(t)}})}function r(t,e,a,n){s(t).then(a,n)}function o(t){return{width:t.width||t.naturalWidth,height:t.height||t.naturalHeight}}function h(t,e,n,i){s(t).then(t=>{const e=o(t),i=function(t){const e=o(t),n=new a(e.width,e.height),i=n.getContext("2d");return i.drawImage(t,0,0,e.width,e.height),{canvas:n,ctx:i}}(t).ctx.getImageData(0,0,e.width,e.height);i.width||(i.width=e.width),i.height||(i.height=e.height),n(i)},i)}const c=Object.assign;return function(t){let i,s;t=e(t);const o=new Worker(URL.createObjectURL(new Blob(['function isImageData(a){return a&&"number"==typeof a.width&&"number"==typeof a.height&&a.data&&"number"==typeof a.data.length&&"object"==typeof a.data}const base64Chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",base64Map=base64Chars.split(""),reversedBase64Map={};base64Map.forEach((a,e)=>{reversedBase64Map[a]=e});var maps={base64Map:base64Map,reversedBase64Map:reversedBase64Map};const reversedBase64Map$1=maps.reversedBase64Map;function base64ToByteArray(a){const e=[];let s;const t=a.replace("data:image/jpeg;base64,","");for(var r=0,i=t.length;r<i;r++){t[r];const a=reversedBase64Map$1[t[r]];switch(r%4){case 1:e.push(s<<2|a>>4);break;case 2:e.push((15&s)<<4|a>>2);break;case 3:e.push((3&s)<<6|a)}s=a}return e}function jpgHeaderLength(a){let e=417;for(let s=0,t=a.length;s<t;s++)if(255===a[s]&&218===a[s+1]){e=s+2;break}return e}function glitchByteArray(a,e,s,t){const r=jpgHeaderLength(a),i=a.length-r-4,n=s/100,p=e/100;for(var o=0;o<t;o++){const e=i/t*o|0;let s=e+((i/t*(o+1)|0)-e)*p|0;s>i&&(s=i),a[~~(r+s)]=~~(256*n)}return a}const base64Map$1=maps.base64Map;function byteArrayToBase64(a){const e=["data:image/jpeg;base64,"];let s,t;for(let r=0,i=a.length;r<i;r++){const i=a[r];switch(s=r%3){case 0:e.push(base64Map$1[i>>2]);break;case 1:e.push(base64Map$1[(3&t)<<4|i>>4]);break;case 2:e.push(base64Map$1[(15&t)<<2|i>>6]),e.push(base64Map$1[63&i])}t=i}return 0===s?(e.push(base64Map$1[(3&t)<<4]),e.push("==")):1===s&&(e.push(base64Map$1[(15&t)<<2]),e.push("=")),e.join("")}function glitchImageData(a,e,s){if(isImageData(a)){return byteArrayToBase64(glitchByteArray(base64ToByteArray(e),s.seed,s.amount,s.iterations))}throw new Error("glitchImageData: imageData seems to be corrupt.")}function fail(a){self.postMessage({err:a.message||a})}function success(a){self.postMessage({base64URL:a})}onmessage=(a=>{const e=a.data.imageData,s=a.data.params,t=a.data.base64URL;if(e&&t&&s)try{void 0===e.width&&"number"==typeof a.data.imageDataWidth&&(e.width=a.data.imageDataWidth),void 0===e.height&&"number"==typeof a.data.imageDataHeight&&(e.height=a.data.imageDataHeight),success(glitchImageData(e,t,s))}catch(a){fail(a)}else a.data.imageData?fail("Parameters are missing."):fail("ImageData is missing.");self.close()});'],{type:"text/javascript"}))),u={getParams:function(){return t},getInput:f,getOutput:m},g={fromImageData:function(t){return l(p,t)},fromImage:function(t){return l(n,t)}},d={toImage:function(t){return b(r,t,!0)},toDataURL:function(t){return b(p)},toImageData:function(t){return b(h,t,!0)}};function f(){const t=c({},u);return i||c(t,g),t}function m(){const t=c({},u);return s||c(t,d),t}function p(t){return t}function l(t,e,a){return i=(()=>new Promise((n,i)=>{if(a)t(e,n,i);else if(t===p)n(e);else try{n(t(e,n,i))}catch(t){i(t)}})),w()?y():m()}function b(t,e,a){return s=(n=>new Promise((i,s)=>{a?t(n,e,i,s):t===p?i(n):t(n,e).then(i,s)})),w()?y():f()}function w(){return i&&s}function y(){return new Promise((e,n)=>{i().then(e=>(function(t,e){return new Promise((n,i)=>{(function(t,e){return new Promise((n,i)=>{if(function(t){return t&&"number"==typeof t.width&&"number"==typeof t.height&&t.data&&"number"==typeof t.data.length&&"object"==typeof t.data}(t)){const i=new a(t.width,t.height);i.getContext("2d").putImageData(t,0,0),n(i.toDataURL("image/jpeg",e/100))}else i(new Error("object is not valid imageData"))})})(t,e.quality).then(a=>(function(t,e,a){return new Promise((n,i)=>{o.addEventListener("message",t=>{t.data&&t.data.base64URL?n(t.data.base64URL):t.data&&t.data.err?i(t.data.err):i(t)}),o.postMessage({params:a,base64URL:e,imageData:t,imageDataWidth:t.width,imageDataHeight:t.height})})})(t,a,e),i).then(n,i)})})(e,t),n).then(t=>{s(t).then(e,n)},n)})}return f()}}); |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self,t.glitch=e())}(this,function(){"use strict";function t(t,e,a){return t<e?e:t>a?a:t}function e(t){var e=!1;if(void 0!==t)try{e=JSON.parse(JSON.stringify(t))}catch(t){}return e}function a(a){return"object"!=typeof(a=e(a))&&(a={}),Object.keys(f).filter(function(t){return"iterations"!==t}).forEach(function(e){"number"!=typeof a[e]||isNaN(a[e])?a[e]=f[e]:a[e]=t(a[e],0,100),a[e]=Math.round(a[e])}),("number"!=typeof a.iterations||isNaN(a.iterations)||a.iterations<=0)&&(a.iterations=f.iterations),a.iterations=Math.round(a.iterations),a}function n(t){if(t instanceof HTMLImageElement){if(!t.naturalWidth||!t.naturalHeight||!1===t.complete)throw new Error("This this image hasn't finished loading: "+t.src);var e=new g(t.naturalWidth,t.naturalHeight),a=e.getContext("2d");a.drawImage(t,0,0,e.width,e.height);var n=a.getImageData(0,0,e.width,e.height);return n.data&&n.data.length&&(void 0===n.width&&(n.width=t.naturalWidth),void 0===n.height&&(n.height=t.naturalHeight)),n}throw new Error("This object does not seem to be an image.")}function i(t){return new Promise(function(e,a){var n=new p;n.onload=function(){e(n)},n.onerror=a;try{n.src=t}catch(t){a(t)}})}function r(t,e,a,n){i(t).then(a,n)}function s(t){return{width:t.width||t.naturalWidth,height:t.height||t.naturalHeight}}function o(t){var e=s(t),a=new g(e.width,e.height),n=a.getContext("2d");return n.drawImage(t,0,0,e.width,e.height),{canvas:a,ctx:n}}function h(t,e,a,n){i(t).then(function(t){var e=s(t),n=o(t).ctx.getImageData(0,0,e.width,e.height);n.width||(n.width=e.width),n.height||(n.height=e.height),a(n)},n)}function u(t){return t&&"number"==typeof t.width&&"number"==typeof t.height&&t.data&&"number"==typeof t.data.length&&"object"==typeof t.data}function c(t,e){return new Promise(function(a,n){if(u(t)){var i=new g(t.width,t.height);i.getContext("2d").putImageData(t,0,0),a(i.toDataURL("image/jpeg",e/100))}else n(new Error("object is not valid imageData"))})}var f={amount:35,iterations:20,quality:30,seed:25},g=function(t,e){void 0===t&&(t=300),void 0===e&&(e=150),"undefined"==typeof window?(this.canvasEl={width:t,height:e},this.ctx=null):(this.canvasEl=document.createElement("canvas"),this.canvasEl.width=t,this.canvasEl.height=e,this.ctx=this.canvasEl.getContext("2d"))},d={width:{configurable:!0},height:{configurable:!0}};g.prototype.getContext=function(){return this.ctx},g.prototype.toDataURL=function(t,e,a){if("function"!=typeof a)return this.canvasEl.toDataURL(t,e);a(this.canvasEl.toDataURL(t,e))},d.width.get=function(){return this.canvasEl.width},d.width.set=function(t){this.canvasEl.width=t},d.height.get=function(){return this.canvasEl.height},d.height.set=function(t){this.canvasEl.height=t},Object.defineProperties(g.prototype,d),"undefined"!=typeof window&&(g.Image=Image);var p=g.Image,m=Object.assign;return function(t){function e(){var t=m({},v);return l||m(t,y),t}function i(){var t=m({},v);return b||m(t,D),t}function s(t){return t}function o(t,e,a){return l=function(){return new Promise(function(n,i){if(a)t(e,n,i);else if(t===s)n(e);else try{n(t(e,n,i))}catch(t){i(t)}})},f()?g():i()}function u(t,a,n){return b=function(e){return new Promise(function(i,r){n?t(e,a,i,r):t===s?i(e):t(e,a).then(i,r)})},f()?g():e()}function f(){return l&&b}function g(){return new Promise(function(e,a){l().then(function(e){return d(e,t)},a).then(function(t){b(t).then(e,a)},a)})}function d(t,e){return new Promise(function(a,n){c(t,e.quality).then(function(a){return p(t,a,e)},n).then(a,n)})}function p(t,e,a){return new Promise(function(n,i){w.addEventListener("message",function(t){t.data&&t.data.base64URL?n(t.data.base64URL):i(t.data&&t.data.err?t.data.err:t)}),w.postMessage({params:a,base64URL:e,imageData:t,imageDataWidth:t.width,imageDataHeight:t.height})})}t=a(t);var l,b,w=new Worker(URL.createObjectURL(new Blob(['function isImageData(a){return a&&"number"==typeof a.width&&"number"==typeof a.height&&a.data&&"number"==typeof a.data.length&&"object"==typeof a.data}function base64ToByteArray(a){for(var e,s=[],t=a.replace("data:image/jpeg;base64,",""),r=0,i=t.length;r<i;r++){t[r];var p=reversedBase64Map$1[t[r]];switch(r%4){case 1:s.push(e<<2|p>>4);break;case 2:s.push((15&e)<<4|p>>2);break;case 3:s.push((3&e)<<6|p)}e=p}return s}function jpgHeaderLength(a){for(var e=417,s=0,t=a.length;s<t;s++)if(255===a[s]&&218===a[s+1]){e=s+2;break}return e}function glitchByteArray(a,e,s,t){for(var r=jpgHeaderLength(a),i=a.length-r-4,p=s/100,n=e/100,h=0;h<t;h++){var g=i/t*h|0,o=g+((i/t*(h+1)|0)-g)*n|0;o>i&&(o=i),a[~~(r+o)]=~~(256*p)}return a}function byteArrayToBase64(a){for(var e,s,t=["data:image/jpeg;base64,"],r=0,i=a.length;r<i;r++){var p=a[r];switch(e=r%3){case 0:t.push(base64Map$1[p>>2]);break;case 1:t.push(base64Map$1[(3&s)<<4|p>>4]);break;case 2:t.push(base64Map$1[(15&s)<<2|p>>6]),t.push(base64Map$1[63&p])}s=p}return 0===e?(t.push(base64Map$1[(3&s)<<4]),t.push("==")):1===e&&(t.push(base64Map$1[(15&s)<<2]),t.push("=")),t.join("")}function glitchImageData(a,e,s){if(isImageData(a))return byteArrayToBase64(glitchByteArray(base64ToByteArray(e),s.seed,s.amount,s.iterations));throw new Error("glitchImageData: imageData seems to be corrupt.")}function fail(a){self.postMessage({err:a.message||a})}function success(a){self.postMessage({base64URL:a})}var base64Chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",base64Map=base64Chars.split(""),reversedBase64Map={};base64Map.forEach(function(a,e){reversedBase64Map[a]=e});var maps={base64Map:base64Map,reversedBase64Map:reversedBase64Map},reversedBase64Map$1=maps.reversedBase64Map,base64Map$1=maps.base64Map;onmessage=function(a){var e=a.data.imageData,s=a.data.params,t=a.data.base64URL;if(e&&t&&s)try{void 0===e.width&&"number"==typeof a.data.imageDataWidth&&(e.width=a.data.imageDataWidth),void 0===e.height&&"number"==typeof a.data.imageDataHeight&&(e.height=a.data.imageDataHeight),success(glitchImageData(e,t,s))}catch(a){fail(a)}else fail(a.data.imageData?"Parameters are missing.":"ImageData is missing.");self.close()};'],{type:"text/javascript"}))),v={getParams:function(){return t},getInput:e,getOutput:i},y={fromImageData:function(t){return o(s,t)},fromImage:function(t){return o(n,t)}},D={toImage:function(t){return u(r,t,!0)},toDataURL:function(t){return u(s)},toImageData:function(t){return u(h,t,!0)}};return e()}}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).glitch=e()}(this,function(){"use strict";var r={amount:35,iterations:20,quality:30,seed:25};function p(i){return"object"!=typeof(i=function(t){var e=!1;if(void 0!==t)try{e=JSON.parse(JSON.stringify(t))}catch(t){}return e}(i))&&(i={}),Object.keys(r).filter(function(t){return"iterations"!==t}).forEach(function(t){var e,a,n;"number"!=typeof i[t]||isNaN(i[t])?i[t]=r[t]:i[t]=(e=i[t],n=100,e<(a=0)?a:n<e?n:e),i[t]=Math.round(i[t])}),("number"!=typeof i.iterations||isNaN(i.iterations)||i.iterations<=0)&&(i.iterations=r.iterations),i.iterations=Math.round(i.iterations),i}var h=function(t,e){void 0===t&&(t=300),void 0===e&&(e=150),"undefined"==typeof window?(this.canvasEl={width:t,height:e},this.ctx=null):(this.canvasEl=document.createElement("canvas"),this.canvasEl.width=t,this.canvasEl.height=e,this.ctx=this.canvasEl.getContext("2d"))},t={width:{configurable:!0},height:{configurable:!0}};function m(t){if(t instanceof HTMLImageElement){if(!t.naturalWidth||!t.naturalHeight||!1===t.complete)throw new Error("This this image hasn't finished loading: "+t.src);var e=new h(t.naturalWidth,t.naturalHeight),a=e.getContext("2d");a.drawImage(t,0,0,e.width,e.height);var n=a.getImageData(0,0,e.width,e.height);return n.data&&n.data.length&&(void 0===n.width&&(n.width=t.naturalWidth),void 0===n.height&&(n.height=t.naturalHeight)),n}throw new Error("This object does not seem to be an image.")}h.prototype.getContext=function(){return this.ctx},h.prototype.toDataURL=function(t,e,a){if("function"!=typeof a)return this.canvasEl.toDataURL(t,e);a(this.canvasEl.toDataURL(t,e))},t.width.get=function(){return this.canvasEl.width},t.width.set=function(t){this.canvasEl.width=t},t.height.get=function(){return this.canvasEl.height},t.height.set=function(t){this.canvasEl.height=t},Object.defineProperties(h.prototype,t),"undefined"!=typeof window&&(h.Image=Image);var i=h.Image;function s(n){return new Promise(function(t,e){var a=new i;a.onload=function(){t(a)},a.onerror=e;try{a.src=n}catch(t){e(t)}})}function l(t,e,a,n){s(t).then(a,n)}function u(t){return{width:t.width||t.naturalWidth,height:t.height||t.naturalHeight}}function v(t,e,o,a){s(t).then(function(t){var e,a,n,i,r=u(t),s=(a=u(e=t),n=new h(a.width,a.height),(i=n.getContext("2d")).drawImage(e,0,0,a.width,a.height),{canvas:n,ctx:i}.ctx.getImageData(0,0,r.width,r.height));s.width||(s.width=r.width),s.height||(s.height=r.height),o(s)},a)}function b(i,r){return new Promise(function(t,e){if((n=i)&&"number"==typeof n.width&&"number"==typeof n.height&&n.data&&"number"==typeof n.data.length&&"object"==typeof n.data){var a=new h(i.width,i.height);a.getContext("2d").putImageData(i,0,0),t(a.toDataURL("image/jpeg",r/100))}else e(new Error("object is not valid imageData"));var n})}var w=Object.assign;return function(n){var r,s;n=p(n);var o=new Worker(URL.createObjectURL(new Blob(['function isImageData(a){return a&&"number"==typeof a.width&&"number"==typeof a.height&&a.data&&"number"==typeof a.data.length&&"object"==typeof a.data}var base64Chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",base64Map=base64Chars.split(""),reversedBase64Map={};base64Map.forEach(function(a,e){reversedBase64Map[a]=e});var maps={base64Map:base64Map,reversedBase64Map:reversedBase64Map},reversedBase64Map$1=maps.reversedBase64Map;function base64ToByteArray(a){for(var e,s=[],t=a.replace("data:image/jpeg;base64,",""),r=0,i=t.length;r<i;r++){t[r];var p=reversedBase64Map$1[t[r]];switch(r%4){case 1:s.push(e<<2|p>>4);break;case 2:s.push((15&e)<<4|p>>2);break;case 3:s.push((3&e)<<6|p)}e=p}return s}function jpgHeaderLength(a){for(var e=417,s=0,t=a.length;s<t;s++)if(255===a[s]&&218===a[s+1]){e=s+2;break}return e}function glitchByteArray(a,e,s,t){for(var r=jpgHeaderLength(a),i=a.length-r-4,p=s/100,n=e/100,h=0;h<t;h++){var g=i/t*h|0,o=g+((i/t*(h+1)|0)-g)*n|0;i<o&&(o=i),a[~~(r+o)]=~~(256*p)}return a}var base64Map$1=maps.base64Map;function byteArrayToBase64(a){for(var e,s,t=["data:image/jpeg;base64,"],r=0,i=a.length;r<i;r++){var p=a[r];switch(e=r%3){case 0:t.push(base64Map$1[p>>2]);break;case 1:t.push(base64Map$1[(3&s)<<4|p>>4]);break;case 2:t.push(base64Map$1[(15&s)<<2|p>>6]),t.push(base64Map$1[63&p])}s=p}return 0===e?(t.push(base64Map$1[(3&s)<<4]),t.push("==")):1===e&&(t.push(base64Map$1[(15&s)<<2]),t.push("=")),t.join("")}function glitchImageData(a,e,s){if(isImageData(a))return byteArrayToBase64(glitchByteArray(base64ToByteArray(e),s.seed,s.amount,s.iterations));throw new Error("glitchImageData: imageData seems to be corrupt.")}function fail(a){self.postMessage({err:a.message||a})}function success(a){self.postMessage({base64URL:a})}onmessage=function(a){var e=a.data.imageData,s=a.data.params,t=a.data.base64URL;if(e&&t&&s)try{void 0===e.width&&"number"==typeof a.data.imageDataWidth&&(e.width=a.data.imageDataWidth),void 0===e.height&&"number"==typeof a.data.imageDataHeight&&(e.height=a.data.imageDataHeight),success(glitchImageData(e,t,s))}catch(a){fail(a)}else a.data.imageData?fail("Parameters are missing."):fail("ImageData is missing.");self.close()};'],{type:"text/javascript"}))),e={getParams:function(){return n},getInput:t,getOutput:h},a={fromImageData:function(t){return c(u,t)},fromImage:function(t){return c(m,t)}},i={toImage:function(t){return f(l,t,!0)},toDataURL:function(t){return f(u)},toImageData:function(t){return f(v,t,!0)}};function t(){var t=w({},e);return r||w(t,a),t}function h(){var t=w({},e);return s||w(t,i),t}function u(t){return t}function c(a,n,i){return r=function(){return new Promise(function(t,e){if(i)a(n,t,e);else if(a===u)t(n);else try{t(a(n,t,e))}catch(t){e(t)}})},(g()?d:h)()}function f(n,i,r){return s=function(a){return new Promise(function(t,e){r?n(a,i,t,e):n===u?t(a):n(a,i).then(t,e)})},(g()?d:t)()}function g(){return r&&s}function d(){return new Promise(function(e,a){r().then(function(t){return a=t,s=n,new Promise(function(t,e){b(a,s.quality).then(function(t){return n=a,i=t,r=s,new Promise(function(e,a){o.addEventListener("message",function(t){t.data&&t.data.base64URL?e(t.data.base64URL):t.data&&t.data.err?a(t.data.err):a(t)}),o.postMessage({params:r,base64URL:i,imageData:n,imageDataWidth:n.width,imageDataHeight:n.height})});var n,i,r},e).then(t,e)});var a,s},a).then(function(t){s(t).then(e,a)},a)})}return t()}}); |
{ | ||
"name": "glitch-canvas-browser", | ||
"version": "1.1.7", | ||
"version": "1.1.8", | ||
"description": "JavaScript library for applying a glitch effect to a canvas element", | ||
@@ -5,0 +5,0 @@ "main": "glitch-canvas-browser.js", |
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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
128721
10
2435
1
15