From c4cdc2ae2295b705675fd7134ef7e88e3a9e3c27 Mon Sep 17 00:00:00 2001 From: Roland Groza Date: Sat, 7 Nov 2020 14:33:10 +0800 Subject: [PATCH] docs: add doka integration - use flat badge for test status and gitpod - show sidebar on docs site - add favicon to docs site --- .github/FUNDING.yml | 1 + README.md | 9 ++- examples/doka/README.md | 140 ++++++++++++++++++++++++++++++++++++ styleguide.config.js | 22 +++++- vendor/doka/doka.esm.min.js | 10 +++ vendor/doka/doka.min.css | 11 +++ 6 files changed, 188 insertions(+), 5 deletions(-) create mode 100644 .github/FUNDING.yml create mode 100644 examples/doka/README.md create mode 100644 vendor/doka/doka.esm.min.js create mode 100644 vendor/doka/doka.min.css diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..01a4b9da --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +open_collective: react-dropzone diff --git a/README.md b/README.md index c0f40b34..f1e759e8 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,11 @@ # react-dropzone [![npm](https://img.shields.io/npm/v/react-dropzone.svg?style=flat-square)](https://www.npmjs.com/package/react-dropzone) -![Build Status](https://github.com/react-dropzone/react-dropzone/workflows/Test/badge.svg) +[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/react-dropzone/react-dropzone/Test?label=tests&style=flat-square)](https://github.com/react-dropzone/react-dropzone/actions?query=workflow%3ATest) [![codecov](https://img.shields.io/codecov/c/gh/react-dropzone/react-dropzone/master.svg?style=flat-square)](https://codecov.io/gh/react-dropzone/react-dropzone) [![Open Collective](https://img.shields.io/opencollective/backers/react-dropzone.svg?style=flat-square)](#backers) [![Open Collective](https://img.shields.io/opencollective/sponsors/react-dropzone.svg?style=flat-square)](#sponsors) -[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/react-dropzone/react-dropzone) +[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod&style=flat-square)](https://gitpod.io/#https://github.com/react-dropzone/react-dropzone) Simple React hook to create a HTML5-compliant drag'n'drop zone for files. @@ -292,6 +292,11 @@ function mockData(files) { More examples for this can be found in `react-dropzone`s own [test suites](https://github.com/react-dropzone/react-dropzone/blob/master/src/index.spec.js). +## Need image editing? + +React Dropzone integrates perfectly with [Doka Image Editor](https://pqina.nl/doka/?ref=react-dropzone), creating a modern image editing experience. Doka supports crop aspect ratios, resizing, rotating, cropping, annotating, filtering, and much more. + +Checkout the [integration example](https://react-dropzone.js.org/#!/Doka). ## Support diff --git a/examples/doka/README.md b/examples/doka/README.md new file mode 100644 index 00000000..9a8dcd14 --- /dev/null +++ b/examples/doka/README.md @@ -0,0 +1,140 @@ +If you'd like to integrate the dropzone with the [doka](https://pqina.nl/doka/?ref=react-dropzone) image editor, you just need to pass either of the selected images to the `create()` method exported by doka: + +```jsx harmony +import React, {useEffect, useState} from 'react'; +import {useDropzone} from 'react-dropzone'; + +import {create} from 'doka'; + +const thumbsContainer = { + display: "flex", + flexDirection: "row", + flexWrap: "wrap", + marginTop: 16, + padding: 20 +}; + +const thumb = { + position: "relative", + display: "inline-flex", + borderRadius: 2, + border: "1px solid #eaeaea", + marginBottom: 8, + marginRight: 8, + width: 100, + height: 100, + padding: 4, + boxSizing: "border-box" +}; + +const thumbInner = { + display: "flex", + minWidth: 0, + overflow: "hidden" +}; + +const img = { + display: "block", + width: "auto", + height: "100%" +}; + +const thumbButton = { + position: "absolute", + right: 10, + bottom: 10, + background: "rgba(0,0,0,.8)", + color: "#fff", + border: 0, + borderRadius: ".325em", + cursor: "pointer" +}; + +const editImage = (image, done) => { + const imageFile = image.doka ? image.doka.file : image; + const imageState = image.doka ? image.doka.data : {}; + create({ + // recreate previous state + ...imageState, + + // load original image file + src: imageFile, + outputData: true, + + onconfirm: ({ file, data }) => { + Object.assign(file, { + doka: { file: imageFile, data } + }); + done(file); + } + }); +}; + +function Doka(props) { + const [files, setFiles] = useState([]); + const { getRootProps, getInputProps } = useDropzone({ + accept: "image/*", + onDrop: (acceptedFiles) => { + setFiles( + acceptedFiles.map((file) => + Object.assign(file, { + preview: URL.createObjectURL(file) + }) + ) + ); + } + }); + + const thumbs = files.map((file, index) => ( +
+
+ +
+ +
+ )); + + useEffect( + () => () => { + // Make sure to revoke the data uris to avoid memory leaks + files.forEach((file) => URL.revokeObjectURL(file.preview)); + }, + [files] + ); + + return ( +
+
+ +

Drag 'n' drop some files here, or click to select files

+
+ +
+ ); +} + + +``` diff --git a/styleguide.config.js b/styleguide.config.js index 44d61c18..96d54a4e 100644 --- a/styleguide.config.js +++ b/styleguide.config.js @@ -6,18 +6,25 @@ const { createConfig, babel, css, devServer } = require('webpack-blocks') module.exports = { title: 'react-dropzone', styleguideDir: path.join(__dirname, 'styleguide'), + template: { + favicon: 'https://github.com/react-dropzone/react-dropzone/raw/master/logo/logo.png' + }, webpackConfig: createConfig([babel(), css(), devServer({ disableHostCheck: true, host: '0.0.0.0', })]), exampleMode: 'expand', usageMode: 'expand', - showSidebar: false, + showSidebar: true, serverPort: 8080, moduleAliases: { - 'react-dropzone': path.resolve(__dirname, './src') + 'react-dropzone': path.resolve(__dirname, './src'), + 'doka': path.resolve(__dirname, './vendor/doka/doka.esm.min.js') }, - require: [path.join(__dirname, 'examples/theme.css')], + require: [ + path.join(__dirname, 'examples/theme.css'), + path.join(__dirname, 'vendor/doka/doka.min.css'), + ], sections: [ { name: '', @@ -69,6 +76,15 @@ module.exports = { content: 'examples/plugins/README.md' } ] + }, + { + name: 'Integrations', + sections: [ + { + name: 'Doka', + content: 'examples/doka/README.md' + } + ] } ] } diff --git a/vendor/doka/doka.esm.min.js b/vendor/doka/doka.esm.min.js new file mode 100644 index 00000000..00b8c814 --- /dev/null +++ b/vendor/doka/doka.esm.min.js @@ -0,0 +1,10 @@ +/*! + * Doka Image Editor 6.16.1 + * (c) 2018-2020 PQINA Inc. - All Rights Reserved + * License: https://pqina.nl/doka/license/ + */ +/* eslint-disable */ + +/* for testing purpose only, if you're intrested in using Doka in your project please purchase a license at https://pqina.nl/doka/ */ + +function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _objectSpread(e){for(var t=1;t1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],n=_objectSpread({},e),i=[],o=[],a=function(e,t,r){r?o.push({type:e,data:t}):(s[e]&&s[e](t),i.push({type:e,data:t}))},c=function(e){for(var t,r=arguments.length,n=new Array(r>1?r-1:0),i=1;i2&&void 0!==arguments[2]?arguments[2]:null;if(null===r)return e.getAttribute(t)||e.hasAttribute(t);e.setAttribute(t,r)},ns="http://www.w3.org/2000/svg",svgElements=["svg","path"],isSVGElement=function(e){return svgElements.includes(e)},createElement=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};"object"===_typeof(t)&&(r=t,t=null);var n=isSVGElement(e)?document.createElementNS(ns,e):document.createElement(e);return t&&(isSVGElement(e)?attr(n,"class",t):n.className=t),forin(r,function(e,t){attr(n,e,t)}),n},appendChild=function(e){return function(t,r){void 0!==r&&e.children[r]?e.insertBefore(t,e.children[r]):e.appendChild(t)}},appendChildView=function(e,t){return function(e,r){return void 0!==r?t.splice(r,0,e):t.push(e),e}},removeChildView=function(e,t){return function(r){var n=t.splice(t.indexOf(r),1);return n.length&&n[0]._destroy(),r.element.parentNode&&e.removeChild(r.element),r}},getViewRect=function(e,t,r,n){var i=r[0]||e.left,o=r[1]||e.top,a=i+e.width,c=o+e.height*(n[1]||1),l={element:_objectSpread({},e),inner:{left:e.left,top:e.top,right:e.right,bottom:e.bottom},outer:{left:i,top:o,right:a,bottom:c}};return t.filter(function(e){return!e.isRectIgnored()}).map(function(e){return e.rect}).forEach(function(e){expandRect(l.inner,_objectSpread({},e.inner)),expandRect(l.outer,_objectSpread({},e.outer))}),calculateRectSize(l.inner),l.outer.bottom+=l.element.marginBottom,l.outer.right+=l.element.marginRight,calculateRectSize(l.outer),l},expandRect=function(e,t){t.top+=e.top,t.right+=e.left,t.bottom+=e.top,t.left+=e.left,t.bottom>e.bottom&&(e.bottom=t.bottom),t.right>e.right&&(e.right=t.right)},calculateRectSize=function(e){e.width=e.right-e.left,e.height=e.bottom-e.top},isNumber=function(e){return"number"==typeof e},thereYet=function(e,t,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:.001;return Math.abs(e-t)0&&void 0!==arguments[0]?arguments[0]:{},t=e.stiffness,r=void 0===t?.5:t,n=e.damping,i=void 0===n?.75:n,o=e.mass,a=void 0===o?10:o,c=e.delay,l=void 0===c?0:c,u=null,s=null,d=0,p=!1,f=null,h=createObject({interpolate:function(e){if(null===f&&(f=e),!(e-l0&&void 0!==arguments[0]?arguments[0]:{},n=r.duration,i=void 0===n?500:n,o=r.easing,a=void 0===o?easeInOutQuad:o,c=r.delay,l=void 0===c?0:c,u=null,s=!0,d=!1,p=null,f=createObject({interpolate:function(r){s||null===p||(null===u&&(u=r),r-u=0?a(d?1-t:t):0)*p)):(e=1,t=d?0:1,f.onupdate(t*p),f.oncomplete(t*p),s=!0)))},target:{get:function(){return d?0:p},set:function(e){if(null===p)return p=e,f.onupdate(e),void f.oncomplete(e);e3&&void 0!==arguments[3]&&arguments[3];(t=Array.isArray(t)?t:[t]).forEach(function(t){e.forEach(function(e){var i=e,o=function(){return r[e]},a=function(t){return r[e]=t};"object"===_typeof(e)&&(i=e.key,o=e.getter||o,a=e.setter||a),t[i]&&!n||(t[i]={get:o,set:a})})})},animations=function(e){var t=e.mixinConfig,r=e.viewProps,n=e.viewInternalAPI,i=e.viewExternalAPI,o=_objectSpread({},r),a=[];return forin(t,function(e,t){var c=createAnimator(t);c&&(c.onupdate=function(t){r[e]=t},c.target=o[e],addGetSet([{key:e,setter:function(e){c.target!==e&&(c.target=e)},getter:function(){return r[e]}}],[n,i],r,!0),a.push(c))}),{write:function(e){var t=!0;return a.forEach(function(r){r.resting||(t=!1),r.interpolate(e)}),t},destroy:function(){}}},addEvent=function(e){return function(t,r){e.addEventListener(t,r)}},removeEvent=function(e){return function(t,r){e.removeEventListener(t,r)}},listeners=function(e){var t=e.viewExternalAPI,r=e.view,n=[],i=addEvent(r.element),o=removeEvent(r.element);return t.on=function(e,t){n.push({type:e,fn:t}),i(e,t)},t.off=function(e,t){n.splice(n.findIndex(function(r){return r.type===e&&r.fn===t}),1),o(e,t)},{write:function(){return!0},destroy:function(){n.forEach(function(e){o(e.type,e.fn)})}}},apis=function(e){var t=e.mixinConfig,r=e.viewProps,n=e.viewExternalAPI;addGetSet(t,n,r)},defaults={opacity:1,scaleX:1,scaleY:1,translateX:0,translateY:0,rotateX:0,rotateY:0,rotateZ:0,originX:0,originY:0},styles=function(e){var t=e.mixinConfig,r=e.viewProps,n=e.viewInternalAPI,i=e.viewExternalAPI,o=e.view,a=_objectSpread({},r),c={};addGetSet(t,[n,i],r);var l=function(){return o.rect?getViewRect(o.rect,o.childViews,[r.translateX||0,r.translateY||0],[r.scaleX||0,r.scaleY||0]):null};return n.rect={get:l},i.rect={get:l},t.forEach(function(e){r[e]=void 0===a[e]?defaults[e]:a[e]}),{write:function(){if(propsHaveChanged(c,r))return applyStyles(o.element,r),Object.assign(c,_objectSpread({},r)),!0},destroy:function(){}}},propsHaveChanged=function(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!0;for(var r in t)if(t[r]!==e[r])return!0;return!1},applyStyles=function(e,t){var r=t.opacity,n=t.perspective,i=t.translateX,o=t.translateY,a=t.scaleX,c=t.scaleY,l=t.rotateX,u=t.rotateY,s=t.rotateZ,d=t.originX,p=t.originY,f=t.width,h=t.height,g="",m="";null==d&&null==p||(m+="transform-origin: ".concat(d||0,"px ").concat(p||0,"px;")),null!=n&&(g+="perspective(".concat(n,"px) ")),null==i&&null==o||(g+="translate3d(".concat(i||0,"px, ").concat(o||0,"px, 0) ")),null==a&&null==c||(g+="scale3d(".concat(null!=a?a:1,", ").concat(null!=c?c:1,", 1) ")),null!=s&&(g+="rotateZ(".concat(s,"rad) ")),null!=l&&(g+="rotateX(".concat(l,"rad) ")),null!=u&&(g+="rotateY(".concat(u,"rad) ")),""!=g&&(m+="transform:".concat(g,";")),null!=r&&(m+="opacity:".concat(r,";"),r<1&&(m+="pointer-events:none;"),0===r&&"BUTTON"===e.nodeName&&(m+="visibility:hidden;")),null!=f&&(m+="width:".concat(f,"px;")),null!=h&&(m+="height:".concat(h,"px;"));var v=e.elementCurrentStyle||"";m.length===v.length&&m===v||(e.style.cssText=m,e.elementCurrentStyle=m)},Mixins={styles:styles,listeners:listeners,animations:animations,apis:apis},updateRect=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return t.layoutCalculated||(e.paddingTop=parseInt(r.paddingTop,10)||0,e.marginTop=parseInt(r.marginTop,10)||0,e.marginRight=parseInt(r.marginRight,10)||0,e.marginBottom=parseInt(r.marginBottom,10)||0,e.marginLeft=parseInt(r.marginLeft,10)||0,t.layoutCalculated=!0),e.left=t.offsetLeft||0,e.top=t.offsetTop||0,e.width=t.offsetWidth||0,e.height=t.offsetHeight||0,e.right=e.left+e.width,e.bottom=e.top+e.height,e.scrollTop=t.scrollTop,e.hidden=null===t.offsetParent&&"fixed"!==r.position,e},IS_BROWSER="undefined"!=typeof window&&void 0!==window.document,isBrowser=function(){return IS_BROWSER},testElement=isBrowser()?createElement("svg"):{},getChildCount="children"in testElement?function(e){return e.children.length}:function(e){return e.childNodes.length},createView=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.tag,r=void 0===t?"div":t,n=e.name,i=void 0===n?null:n,o=e.attributes,a=void 0===o?{}:o,c=e.read,l=void 0===c?function(){}:c,u=e.write,s=void 0===u?function(){}:u,d=e.create,p=void 0===d?function(){}:d,f=e.destroy,h=void 0===f?function(){}:f,g=e.filterFrameActionsForChild,m=void 0===g?function(e,t){return t}:g,v=e.didCreateView,y=void 0===v?function(){}:v,E=e.didWriteView,T=void 0===E?function(){}:E,_=e.shouldUpdateChildViews,R=void 0===_?function(){return!0}:_,w=e.ignoreRect,A=void 0!==w&&w,I=e.ignoreRectUpdate,S=void 0!==I&&I,C=e.mixins,O=void 0===C?[]:C;return function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=createElement(r,i?"doka--".concat(i):null,a),o=window.getComputedStyle(n,null),c=updateRect(),u=null,d=!1,f=[],g=[],v={},E={},_=[s],w=[l],I=[h],C=function(){return n},x=function(){return[].concat(f)},b=function(){return u||(u=getViewRect(c,f,[0,0],[1,1]))},M=function(){return n.layoutCalculated=!1},L={element:{get:C},style:{get:function(){return o}},childViews:{get:x}},P=_objectSpread({},L,{rect:{get:b},ref:{get:function(){return v}},is:function(e){return i===e},appendChild:appendChild(n),createChildView:function(e){return function(t,r){return t(e,r)}}(e),linkView:function(e){return f.push(e),e},unlinkView:function(e){f.splice(f.indexOf(e),1)},appendChildView:appendChildView(n,f),removeChildView:removeChildView(n,f),registerWriter:function(e){return _.push(e)},registerReader:function(e){return w.push(e)},registerDestroyer:function(e){return I.push(e)},invalidateLayout:M,dispatch:e.dispatch,query:e.query}),G={element:{get:C},childViews:{get:x},rect:{get:b},resting:{get:function(){return d}},isRectIgnored:function(){return A},invalidateLayout:M,_read:function(){u=null,R({root:D,props:t})&&f.forEach(function(e){return e._read()}),!(S&&c.width&&c.height)&&updateRect(c,n,o);var e={root:D,props:t,rect:c};w.forEach(function(t){return t(e)})},_write:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=0===r.length;return _.forEach(function(i){!1===i({props:t,root:D,actions:r,timestamp:e})&&(n=!1)}),g.forEach(function(t){!1===t.write(e)&&(n=!1)}),R({props:t,root:D,actions:r,timestamp:e})&&(f.filter(function(e){return!!e.element.parentNode}).forEach(function(t){t._write(e,m(t,r))||(n=!1)}),f.forEach(function(t,i){t.element.parentNode||(D.appendChild(t.element,i),t._read(),t._write(e,m(t,r)),n=!1)})),d=n,T({props:t,root:D,actions:r,timestamp:e}),n},_destroy:function(){g.forEach(function(e){return e.destroy()}),I.forEach(function(e){e({root:D})}),f.forEach(function(e){return e._destroy()})}},k=_objectSpread({},L,{rect:{get:function(){return c}}});Object.keys(O).sort(function(e,t){return"styles"===e?1:"styles"===t?-1:0}).forEach(function(e){var r=Mixins[e]({mixinConfig:O[e],viewProps:t,viewState:E,viewInternalAPI:P,viewExternalAPI:G,view:createObject(k)});r&&g.push(r)});var D=createObject(P);p({root:D,props:t});var U=getChildCount(n)||0;return f.forEach(function(e,t){D.appendChild(e.element,U+t)}),y(D),createObject(G,t)}},createPainter=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:60,n="__framePainter";if(window[n])return window[n].readers.push(e),void window[n].writers.push(t);window[n]={readers:[e],writers:[t]};var i=window[n],o=1e3/r,a=null,c=null,l=null,u=null,s=function(){document.hidden?(l=function(){return window.setTimeout(function(){return d(performance.now())},o)},u=function(){return window.clearTimeout(c)}):(l=function(){return window.requestAnimationFrame(d)},u=function(){return window.cancelAnimationFrame(c)})};document.addEventListener("visibilitychange",function(){u&&u(),s(),d(performance.now())});var d=function e(t){c=l(e),a||(a=t);var r=t-a;r<=o||(a=t-r%o,i.readers.forEach(function(e){return e()}),i.writers.forEach(function(e){return e(t)}))};return s(),d(performance.now()),{pause:function(){u(c)}}},createRoute=function(e,t){return function(r){var n=r.root,i=r.props,o=r.actions,a=void 0===o?[]:o,c=r.timestamp;if(a.filter(function(t){return e[t.type]}).forEach(function(t){return e[t.type]({root:n,props:i,action:t.data,timestamp:c})}),t)return t({root:n,props:i,actions:a,timestamp:c})}},isArray=function(e){return Array.isArray(e)},isEmpty=function(e){return null==e},trim=function(e){return e.trim()},toString=function(e){return""+e},toArray=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:",";return isEmpty(e)?[]:isArray(e)?e:toString(e).split(t).map(trim).filter(function(e){return e.length})},isBoolean=function(e){return"boolean"==typeof e},toBoolean=function(e){return isBoolean(e)?e:"true"===e},isString=function(e){return"string"==typeof e},toNumber=function(e){return isNumber(e)?e:isString(e)?toString(e).replace(/[a-z]+/gi,""):0},toInt=function(e){return parseInt(toNumber(e),10)},toFloat=function(e){return parseFloat(toNumber(e))},isInt=function(e){return isNumber(e)&&isFinite(e)&&Math.floor(e)===e},toBytes=function(e){if(isInt(e))return e;var t=toString(e).trim();return/MB$/i.test(t)?(t=t.replace(/MB$i/,"").trim(),1e3*toInt(t)*1e3):/KB/i.test(t)?(t=t.replace(/KB$i/,"").trim(),1e3*toInt(t)):toInt(t)},isFunction=function(e){return"function"==typeof e},toFunctionReference=function(e){for(var t=self,r=e.split("."),n=null;n=r.shift();)if(!(t=t[n]))return null;return t},isNull=function(e){return null===e},getType=function(e){return isArray(e)?"array":isNull(e)?"null":isInt(e)?"int":/^[0-9]+ ?(?:GB|MB|KB)$/gi.test(e)?"bytes":_typeof(e)},replaceSingleQuotes=function(e){return e.replace(/{\s*'/g,'{"').replace(/'\s*}/g,'"}').replace(/'\s*:/g,'":').replace(/:\s*'/g,':"').replace(/,\s*'/g,',"').replace(/'\s*,/g,'",')},conversionTable={array:toArray,boolean:toBoolean,int:function(e){return"bytes"===getType(e)?toBytes(e):toInt(e)},float:toFloat,bytes:toBytes,number:toFloat,string:function(e){return isFunction(e)?e:toString(e)},object:function(e){try{return JSON.parse(replaceSingleQuotes(e))}catch(t){return e}},file:function(e){return e},function:function(e){return toFunctionReference(e)}},convertTo=function(e,t){return conversionTable[t](e)},getValueByType=function(e,t,r){if(e===t)return e;var n=getType(e);if(n!==r){var i=convertTo(e,r);if(n=getType(i),null===i)throw'Trying to assign value with incorrect type, allowed type: "'.concat(r,'"');e=i}return e},createOption=function(e,t){var r=e;return{enumerable:!0,get:function(){return r},set:function(n){r=getValueByType(n,e,t)}}},createOptions=function(e){var t={};return forin(e,function(r){var n=isString(e[r])?e[r]:r,i=e[n];t[r]=n===r?createOption(i[0],i[1]):t[n]}),createObject(t)},resetState=function(e){e.file=null,e.activeView=null,e.markup=[],e.markupToolValues={},e.rootRect={x:0,y:0,left:0,top:0,width:0,height:0},e.stage=null,e.stageOffset=null,e.image=null,e.zoomTimeoutId=null,e.instantUpdate=!1,e.filePromise=null,e.fileLoader=null,e.instructions={size:null,crop:null,filter:null,color:null},e.filter=null,e.filterName=null,e.filterValue=null,e.colorValues={},e.colorMatrices={},e.size={width:!1,height:!1,aspectRatioLocked:!0,aspectRatioPrevious:!1},e.crop={rectangle:null,transforms:null,rotation:null,flip:null,aspectRatio:null,isRotating:!1,isDirty:!1,limitToImageBounds:!0,draft:{rectangle:null,transforms:null}}},createInitialState=function(e){var t={noImageTimeout:null,options:createOptions(e)};return resetState(t),t},fromCamels=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"-";return e.split(/(?=[A-Z])/).map(function(e){return e.toLowerCase()}).join(t)},createOptionAPI=function(e,t){var r={};return forin(t,function(n){var i=isString(t[n])?t[n]:n;r[n]={get:function(){return e.getState().options[i]},set:function(t){e.dispatch("SET_".concat(fromCamels(i,"_").toUpperCase()),{value:t})}}}),r},createOptionActions=function(e){return function(t,r,n){var i={};return forin(e,function(e){var r=fromCamels(e,"_").toUpperCase();i["SET_".concat(r)]=function(i){var o;try{o=n.options[e],n.options[e]=i.value}catch(e){}t("DID_SET_".concat(r),{value:n.options[e],prevValue:o})}}),i}},createOptionQueries=function(e){return function(t){var r={};return forin(e,function(e){r["GET_".concat(fromCamels(e,"_").toUpperCase())]=function(){return t.options[e]}}),r}},getUniqueId=function(){return Math.random().toString(36).substr(2,9)},arrayRemove=function(e,t){return e.splice(t,1)},on=function(){var e=[],t=function(t,r){arrayRemove(e,e.findIndex(function(e){return e.event===t&&(e.cb===r||!r)}))};return{fire:function(t){for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;i1)&&!window.MSStream),testResult},getOptions=function(){return _objectSpread({},defaultOptions)},setOptions=function(e){forin(e,function(e,t){defaultOptions[e]&&setOption(e,t)})},correctDeprecatedOption=function(e){return isString(defaultOptions[e])?defaultOptions[e]:e},setOption=function(e,t){e=correctDeprecatedOption(e),defaultOptions[e][0]=getValueByType(t,defaultOptions[e][0],defaultOptions[e][1])},defaultOptions={id:[null,Type.STRING],className:[null,Type.STRING],src:[null,Type.FILE],storageName:["doka",Type.STRING],maxImagePreviewWidth:[1500,Type.INT],maxImagePreviewHeight:[1500,Type.INT],imagePreviewScaleMode:["stage",Type.STRING],allowPreviewFitToView:[!0,Type.BOOLEAN],allowButtonCancel:[!0,Type.BOOLEAN],allowButtonConfirm:[!0,Type.BOOLEAN],allowButtonReset:[!0,Type.BOOLEAN],allowDropFiles:[!1,Type.BOOLEAN],allowBrowseFiles:[!0,Type.BOOLEAN],allowAutoClose:[!0,Type.BOOLEAN],allowAutoDestroy:[!1,Type.BOOLEAN],utils:[["crop","filter","color","markup"],Type.ARRAY],util:[null,Type.STRING],initialState:[null,Type.OBJECT],outputData:[!1,Type.BOOLEAN],outputFile:[!0,Type.BOOLEAN],outputCorrectImageExifOrientation:[!0,Type.BOOLEAN],outputStripImageHead:[!0,Type.BOOLEAN],outputType:[null,Type.STRING],outputQuality:[null,Type.INT],outputFit:["cover",Type.STRING],outputUpscale:[!0,Type.BOOLEAN],outputWidth:[null,Type.INT],outputHeight:[null,Type.INT],outputCanvasBackgroundColor:[null,Type.STRING],outputCanvasMemoryLimit:[isBrowser()&&isIOS()?16777216:null,Type.INT],outputCanvasSyncTarget:[null,Type.OBJECT],size:[null,Type.OBJECT],sizeMin:[{width:1,height:1},Type.OBJECT],sizeMax:[{width:9999,height:9999},Type.OBJECT],filter:[null,Type.OBJECT],filters:[{original:{label:"Original",matrix:function(){return null}},chrome:{label:"Chrome",matrix:function(){return[1.398,-.316,.065,-.273,.201,-.051,1.278,-.08,-.273,.201,-.051,.119,1.151,-.29,.215,0,0,0,1,0]}},fade:{label:"Fade",matrix:function(){return[1.073,-.015,.092,-.115,-.017,.107,.859,.184,-.115,-.017,.015,.077,1.104,-.115,-.017,0,0,0,1,0]}},mono:{label:"Mono",matrix:function(){return[.212,.715,.114,0,0,.212,.715,.114,0,0,.212,.715,.114,0,0,0,0,0,1,0]}},noir:{label:"Noir",matrix:function(){return[.15,1.3,-.25,.1,-.2,.15,1.3,-.25,.1,-.2,.15,1.3,-.25,.1,-.2,0,0,0,1,0]}}},Type.OBJECT],crop:[null,Type.OBJECT],cropShowSize:[!1,Type.BOOLEAN],cropZoomTimeout:[null,Type.INT],cropMask:[null,Type.FUNCTION],cropMaskInset:[0,Type.INT],cropAllowResizeRect:[!0,Type.BOOLEAN],cropAllowImageTurnLeft:[!0,Type.BOOLEAN],cropAllowImageTurnRight:[!1,Type.BOOLEAN],cropAllowImageFlipHorizontal:[!0,Type.BOOLEAN],cropAllowImageFlipVertical:[!0,Type.BOOLEAN],cropAllowToggleLimit:[!1,Type.BOOLEAN],cropLimitToImageBounds:[!0,Type.BOOLEAN],cropAllowInstructionZoom:[!1,Type.BOOLEAN],cropAllowRotate:[!0,Type.BOOLEAN],cropResizeMatchImageAspectRatio:[!1,Type.BOOLEAN],cropResizeKeyCodes:[[18,91,92,93],Type.ARRAY],cropResizeScrollRectOnly:[!1,Type.BOOLEAN],cropAspectRatio:[null,Type.STRING],cropAspectRatioOptions:[null,Type.ARRAY],cropMinImageWidth:[1,Type.INT],cropMinImageHeight:[1,Type.INT],color:[void 0,Type.OBJECT],colorBrightness:[0,Type.NUMBER],colorBrightnessRange:[[-.25,.25],Type.ARRAY],colorContrast:[1,Type.NUMBER],colorContrastRange:[[.5,1.5],Type.ARRAY],colorExposure:[1,Type.NUMBER],colorExposureRange:[[.5,1.5],Type.ARRAY],colorSaturation:[1,Type.NUMBER],colorSaturationRange:[[0,2],Type.ARRAY],markup:[null,Type.ARRAY],markupUtil:["select",Type.STRING],markupFilter:[function(){return!0},Type.FUNCTION],markupAllowAddMarkup:[!0,Type.BOOLEAN],markupAllowCustomColor:[!0,Type.BOOLEAN],markupDrawDistance:[4,Type.NUMBER],markupColor:["#000",Type.STRING],markupColorOptions:[[["White","#fff","#f6f6f6"],["Silver","#9e9e9e"],["Black","#000","#333"],["Red","#f44336"],["Orange","#ff9800"],["Yellow","#ffeb3b"],["Green","#4caf50"],["Blue","#2196f3"],["Violet","#3f51b5"],["Purple","#9c27b0"]],Type.ARRAY],markupFontSize:[.1,Type.NUMBER],markupFontSizeOptions:[[["XL",.15],["L",.125],["M",.1],["S",.075],["XS",.05]],Type.ARRAY],markupFontFamily:["Helvetica, Arial, Verdana",Type.STRING],markupFontFamilyOptions:[[["Serif","Palatino, 'Times New Roman', serif"],["Sans Serif","Helvetica, Arial, Verdana"],["Monospaced","Monaco, 'Lucida Console', monospaced"]],Type.ARRAY],markupShapeStyle:[[.015,null],Type.ARRAY],markupShapeStyleOptions:[[["Fill",0,null,0],["Outline thick",.025,null,4],["Outline default",.015,null,2],["Outline thin",.005,null,1],["Outline dashed",.005,[.01],1]],Type.ARRAY],markupLineStyle:[[.015,null],Type.ARRAY],markupLineStyleOptions:[[["Thick",.025,null,4],["Default",.015,null,2],["Thin",.005,null,1],["Dashed",.005,[.01],1]],Type.ARRAY],markupLineDecoration:[["arrow-end"],Type.ARRAY],markupLineDecorationOptions:[[["None",[]],["Single arrow",["arrow-end"]],["Double arrow",["arrow-begin","arrow-end"]]],Type.ARRAY],stickers:[null,Type.ARRAY],beforeReset:[null,Type.FUNCTION],beforeLoadImage:[null,Type.FUNCTION],beforeCreateBlob:[null,Type.FUNCTION],afterCreateBlob:[null,Type.FUNCTION],afterCreateOutput:[null,Type.FUNCTION],onconfirm:[null,Type.FUNCTION],oncancel:[null,Type.FUNCTION],onclose:[null,Type.FUNCTION],onloadstart:[null,Type.FUNCTION],onload:[null,Type.FUNCTION],onloaderror:[null,Type.FUNCTION],oninit:[null,Type.FUNCTION],onready:[null,Type.FUNCTION],onupdate:[null,Type.FUNCTION],ondestroy:[null,Type.FUNCTION],labelButtonReset:["Reset",Type.STRING],labelButtonCancel:["Cancel",Type.STRING],labelButtonConfirm:["Done",Type.STRING],labelButtonUtilCrop:["Crop",Type.STRING],labelButtonUtilResize:["Resize",Type.STRING],labelButtonUtilFilter:["Filter",Type.STRING],labelButtonUtilColor:["Colors",Type.STRING],labelButtonUtilMarkup:["Markup",Type.STRING],labelButtonUtilSticker:["Stickers",Type.STRING],labelStatusMissingWebGL:["WebGL is required but is disabled on your browser",Type.STRING],labelStatusAwaitingImage:["Waiting for image…",Type.STRING],labelStatusLoadImageError:["Error loading image…",Type.STRING],labelStatusLoadingImage:["Loading image…",Type.STRING],labelStatusProcessingImage:["Processing image…",Type.STRING],labelColorBrightness:["Brightness",Type.STRING],labelColorContrast:["Contrast",Type.STRING],labelColorExposure:["Exposure",Type.STRING],labelColorSaturation:["Saturation",Type.STRING],labelMarkupTypeRectangle:["Square",Type.STRING],labelMarkupTypeEllipse:["Circle",Type.STRING],labelMarkupTypeText:["Text",Type.STRING],labelMarkupTypeLine:["Arrow",Type.STRING],labelMarkupSelectFontSize:["Size",Type.STRING],labelMarkupSelectFontFamily:["Font",Type.STRING],labelMarkupSelectLineDecoration:["Decoration",Type.STRING],labelMarkupSelectLineStyle:["Style",Type.STRING],labelMarkupSelectShapeStyle:["Style",Type.STRING],labelMarkupRemoveShape:["Remove",Type.STRING],labelMarkupToolSelect:["Select",Type.STRING],labelMarkupToolDraw:["Draw",Type.STRING],labelMarkupToolLine:["Arrow",Type.STRING],labelMarkupToolText:["Text",Type.STRING],labelMarkupToolRect:["Square",Type.STRING],labelMarkupToolEllipse:["Circle",Type.STRING],labelResizeWidth:["Width",Type.STRING],labelResizeHeight:["Height",Type.STRING],labelResizeApplyChanges:["Apply",Type.STRING],labelCropInstructionZoom:["Zoom in and out with your scroll wheel or touchpad.",Type.STRING],labelButtonCropZoom:["Zoom",Type.STRING],labelButtonCropRotateLeft:["Rotate left",Type.STRING],labelButtonCropRotateRight:["Rotate right",Type.STRING],labelButtonCropRotateCenter:["Center rotation",Type.STRING],labelButtonCropFlipHorizontal:["Flip horizontal",Type.STRING],labelButtonCropFlipVertical:["Flip vertical",Type.STRING],labelButtonCropAspectRatio:["Aspect ratio",Type.STRING],labelButtonCropToggleLimit:["Crop selection",Type.STRING],labelButtonCropToggleLimitEnable:["Limited to image",Type.STRING],labelButtonCropToggleLimitDisable:["Select outside image",Type.STRING],pointerEventsPolyfillScope:["root",Type.STRING],styleCropCorner:["circle",Type.STRING],styleFullscreenSafeArea:[isBrowser()&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream?"bottom":"none",Type.STRING],styleLayoutMode:[null,Type.STRING]},limit=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;return Math.min(r,Math.max(t,e))},roundFloat=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:10;return parseFloat(e.toFixed(t))},vectorEqual=function(e,t){return roundFloat(e.x)===roundFloat(t.x)&&roundFloat(e.y)===roundFloat(t.y)},roundVector=function(e,t){return{x:roundFloat(e.x,t),y:roundFloat(e.y,t)}},vectorSubtract=function(e,t){return createVector(e.x-t.x,e.y-t.y)},vectorDot=function(e,t){return e.x*t.x+e.y*t.y},vectorDistanceSquared=function(e,t){return vectorDot(vectorSubtract(e,t),vectorSubtract(e,t))},vectorDistance=function(e,t){return Math.sqrt(vectorDistanceSquared(e,t))},vectorAngleBetween=function(e,t){var r=vectorSubtract(e,t);return Math.atan2(r.y,r.x)},vectorLimit=function(e,t){return createVector(limit(e.x,t.x,t.x+t.width),limit(e.y,t.y,t.y+t.height))},vectorRotate=function(e,t,r){var n=Math.cos(t),i=Math.sin(t),o=createVector(e.x-r.x,e.y-r.y);return createVector(r.x+n*o.x-i*o.y,r.y+i*o.x+n*o.y)},createVector=function(){return{x:arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,y:arguments.length>1&&void 0!==arguments[1]?arguments[1]:0}},rectEqualsRect=function(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height},rectFitsInRect=function(e,t){var r=rectBounds(e),n=rectBounds(t);return r.left>=n.left&&r.top>=n.top&&r.bottom<=n.bottom&&r.right<=n.right},rotateRectCorners=function(e,t,r){return 0===t?{tl:e.tl,tr:e.tr,br:e.br,bl:e.bl}:{tl:vectorRotate(e.tl,t,r),tr:vectorRotate(e.tr,t,r),br:vectorRotate(e.br,t,r),bl:vectorRotate(e.bl,t,r)}},rectRotate=function(e,t,r){var n=rotateRectCorners(rectCorners(e),t,r),i=n.tl,o=n.tr,a=n.br,c=n.bl,l=Math.min(i.x,o.x,a.x,c.x),u=Math.min(i.y,o.y,a.y,c.y),s=Math.max(i.x,o.x,a.x,c.x),d=Math.max(i.y,o.y,a.y,c.y);return createRect(l,u,s-l,d-u)},rectScale=function(e,t,r){return createRect(t*(e.x-r.x)+r.x,t*(e.y-r.y)+r.y,t*e.width,t*e.height)},rectTranslate=function(e,t){return createRect(e.x+t.x,e.y+t.y,e.width,e.height)},TRANSFORM_MAP={translate:rectTranslate,rotate:rectRotate,scale:rectScale},rectTransform=function(e,t,r){return t.reduce(function(e,t){return(0,TRANSFORM_MAP[t[0]])(e,t[1],r)},e)},rectClone=function(e){return createRect(e.x,e.y,e.width,e.height)},rectBounds=function(e){return{top:e.y,right:e.x+e.width,bottom:e.y+e.height,left:e.x}},rectFromBounds=function(e){var t=e.top,r=e.right,n=e.bottom,i=e.left;return{x:i,y:t,width:r-i,height:n-t}},rectCenter=function(e){return createVector(e.x+.5*e.width,e.y+.5*e.height)},rectCorners=function(e){return{tl:{x:e.x,y:e.y},tr:{x:e.x+e.width,y:e.y},br:{x:e.x+e.width,y:e.y+e.height},bl:{x:e.x,y:e.y+e.height}}},createRect=function(e,t,r,n){return{x:e,y:t,width:r,height:n}},getNumericAspectRatioFromString=function(e){if(isEmpty(e))return e;if(/:/.test(e)){var t=e.split(":"),r=t[0];return t[1]/r}return parseFloat(e)},getCenteredCropRect=function(e,t){var r=e.width,n=r*t;return n>e.height&&(r=(n=e.height)/t),{x:.5*(e.width-r),y:.5*(e.height-n),width:r,height:n}},calculateCanvasSize=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,n=e.height/e.width,i=t,o=1,a=n;a>i&&(o=(a=i)/n);var c=Math.max(1/o,i/a),l=e.width/(r*c*o);return{width:l,height:l*t}},createVector$1=function(e,t){return{x:e,y:t}},vectorDot$1=function(e,t){return e.x*t.x+e.y*t.y},vectorSubtract$1=function(e,t){return createVector$1(e.x-t.x,e.y-t.y)},vectorDistanceSquared$1=function(e,t){return vectorDot$1(vectorSubtract$1(e,t),vectorSubtract$1(e,t))},vectorDistance$1=function(e,t){return Math.sqrt(vectorDistanceSquared$1(e,t))},getOffsetPointOnEdge=function(e,t){var r=e,n=t,i=1.5707963267948966-t,o=Math.sin(1.5707963267948966),a=Math.sin(n),c=Math.sin(i),l=Math.cos(i),u=r/o;return createVector$1(l*(u*a),l*(u*c))},getRotatedRectSize=function(e,t){var r=e.width,n=e.height,i=getOffsetPointOnEdge(r,t),o=getOffsetPointOnEdge(n,t),a=createVector$1(e.x+Math.abs(i.x),e.y-Math.abs(i.y)),c=createVector$1(e.x+e.width+Math.abs(o.y),e.y+Math.abs(o.x)),l=createVector$1(e.x-Math.abs(o.y),e.y+e.height-Math.abs(o.x));return{width:vectorDistance$1(a,c),height:vectorDistance$1(a,l)}},getImageRectZoomFactor=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{x:.5,y:.5},i=n.x>.5?1-n.x:n.x,o=n.y>.5?1-n.y:n.y,a=2*i*e.width,c=2*o*e.height,l=getRotatedRectSize(t,r);return Math.max(l.width/a,l.height/c)},getAxisAlignedImageRect=function(e,t){var r=t.origin,n=t.translation,i=t.scale;return rectTransform(e,[["scale",i],["translate",n]],r)},getOffsetPointOnEdge$1=function(e,t){var r=e,n=t,i=1.5707963267948966-t,o=Math.sin(1.5707963267948966),a=Math.sin(n),c=Math.sin(i),l=Math.cos(i),u=r/o;return createVector(l*(u*a),l*(u*c))},getRotatedRectCorners=function(e,t){var r=e.width,n=e.height,i=t%(Math.PI/2),o=getOffsetPointOnEdge$1(r,i),a=getOffsetPointOnEdge$1(n,i),c=rectCorners(e);return{tl:createVector(c.tl.x+Math.abs(o.x),c.tl.y-Math.abs(o.y)),tr:createVector(c.tr.x+Math.abs(a.y),c.tr.y+Math.abs(a.x)),br:createVector(c.br.x-Math.abs(o.x),c.br.y+Math.abs(o.y)),bl:createVector(c.bl.x-Math.abs(a.y),c.bl.y-Math.abs(a.x))}},getAxisAlignedCropRect=function(e,t,r,n){var i={x:e.x+t.x,y:e.y+t.y},o=getRotatedRectCorners(n,r),a=vectorRotate(o.tl,-r,i),c=vectorRotate(o.tr,-r,i),l=vectorRotate(o.br,-r,i);return createRect(Math.min(a.x,c.x,l.x),Math.min(a.y,c.y,l.y),Math.max(a.x,c.x,l.x)-Math.min(a.x,c.x,l.x),Math.max(a.y,c.y,l.y)-Math.min(a.y,c.y,l.y))},getCropFromView=function(e,t,r){var n=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],i=r.origin,o=r.translation,a=getAxisAlignedImageRect(e,r),c=2*Math.PI+r.rotation%(2*Math.PI),l=getAxisAlignedCropRect(i,o,c,t),u=rectCenter(l),s=t.height/t.width,d={x:(u.x-a.x)/a.width,y:(u.y-a.y)/a.height},p=d.y>.5?1-d.y:d.y,f=2*(d.x>.5?1-d.x:d.x)*a.width,h=2*p*a.height;return{center:d,zoom:n?Math.min(f/l.width,h/l.height):Math.min(a.width/l.width,a.height/l.height),rotation:r.rotation,aspectRatio:s,scaleToFit:n}},getCropFromStateRounded=function(e,t){var r=getCropFromState(e,t);return{center:{x:roundFloat(r.center.x),y:roundFloat(r.center.y)},rotation:roundFloat(r.rotation),zoom:roundFloat(r.zoom),aspectRatio:roundFloat(r.aspectRatio),flip:_objectSpread({},t.flip),scaleToFit:r.scaleToFit}},getCropFromState=function(e,t){var r=getCropFromView(e,t.rectangle,t.transforms,t.limitToImageBounds);return{center:{x:r.center.x,y:r.center.y},rotation:r.rotation,zoom:r.zoom,aspectRatio:r.aspectRatio,flip:_objectSpread({},t.flip),scaleToFit:r.scaleToFit}},limitSize=function(e,t,r,n){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"width",o=e.width,a=e.height;if(!o&&!a)return{width:o,height:a};if(o=o&&limit(o,t.width,r.width),a=a&&limit(a,t.height,r.height),!n)return{width:o,height:a};if(a)if(o)"width"===i?a=o/n:"height"===i?o=a*n:(a*nr.width?a=(o=r.width)/n:o/n>r.height&&(o=(a=r.height)*n));else{a=limit(a*n,t.width,r.width)/n}else o=limit(o/n,t.height,r.height)*n;return{width:o,height:a}},dotColorMatrix=function(e,t){var r=new Array(20);return r[0]=e[0]*t[0]+e[1]*t[5]+e[2]*t[10]+e[3]*t[15],r[1]=e[0]*t[1]+e[1]*t[6]+e[2]*t[11]+e[3]*t[16],r[2]=e[0]*t[2]+e[1]*t[7]+e[2]*t[12]+e[3]*t[17],r[3]=e[0]*t[3]+e[1]*t[8]+e[2]*t[13]+e[3]*t[18],r[4]=e[0]*t[4]+e[1]*t[9]+e[2]*t[14]+e[3]*t[19]+e[4],r[5]=e[5]*t[0]+e[6]*t[5]+e[7]*t[10]+e[8]*t[15],r[6]=e[5]*t[1]+e[6]*t[6]+e[7]*t[11]+e[8]*t[16],r[7]=e[5]*t[2]+e[6]*t[7]+e[7]*t[12]+e[8]*t[17],r[8]=e[5]*t[3]+e[6]*t[8]+e[7]*t[13]+e[8]*t[18],r[9]=e[5]*t[4]+e[6]*t[9]+e[7]*t[14]+e[8]*t[19]+e[9],r[10]=e[10]*t[0]+e[11]*t[5]+e[12]*t[10]+e[13]*t[15],r[11]=e[10]*t[1]+e[11]*t[6]+e[12]*t[11]+e[13]*t[16],r[12]=e[10]*t[2]+e[11]*t[7]+e[12]*t[12]+e[13]*t[17],r[13]=e[10]*t[3]+e[11]*t[8]+e[12]*t[13]+e[13]*t[18],r[14]=e[10]*t[4]+e[11]*t[9]+e[12]*t[14]+e[13]*t[19]+e[14],r[15]=e[15]*t[0]+e[16]*t[5]+e[17]*t[10]+e[18]*t[15],r[16]=e[15]*t[1]+e[16]*t[6]+e[17]*t[11]+e[18]*t[16],r[17]=e[15]*t[2]+e[16]*t[7]+e[17]*t[12]+e[18]*t[17],r[18]=e[15]*t[3]+e[16]*t[8]+e[17]*t[13]+e[18]*t[18],r[19]=e[15]*t[4]+e[16]*t[9]+e[17]*t[14]+e[18]*t[19]+e[19],r},toRGBColorArray=function(e){var t;if(/^#/.test(e)){if(4===e.length){var r=e.split("");e="#"+r[1]+r[1]+r[2]+r[2]+r[3]+r[3]}var n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);t=[parseInt(n[1],16),parseInt(n[2],16),parseInt(n[3],16)]}else if(/^rgb/.test(e)){(t=e.match(/\d+/g).map(function(e){return parseInt(e,10)})).length=3}return t},viewCache=[],getColorMatrixFromMatrices=function(e){var t=[];return forin(e,function(e,r){return t.push(r)}),t.length?t.reduce(function(e,t){return dotColorMatrix(_toConsumableArray(e),t)},t.shift()):[]},getImageScalar=function(e){return e.crop.draft.transforms?e.crop.draft.transforms.scale:e.crop.transforms.scale},getMinCropSize=function(e){var t=e.image.width/e.image.naturalWidth,r=getImageScalar(e);return{width:e.options.cropMinImageWidth*r*t,height:e.options.cropMinImageHeight*r*t}},getMaxCropSize=function(e){var t=getImageScalar(e);return{width:e.image.width*t,height:e.image.height*t}},getWidth=function(e){return e.options.size?e.options.size.width:null},getHeight=function(e){return e.options.size?e.options.size.height:null},getOutputSizeWidth=function(e){return!1===e.size.width?getWidth(e):e.size.width},getOutputSizeHeight=function(e){return!1===e.size.height?getHeight(e):e.size.height},getAspectRatioOptions=function(e){return e.options.cropAspectRatioOptions?e.options.cropAspectRatioOptions.map(function(e){var t={aspectRatio:null,width:null,height:null};return"number"==typeof e.value&&(t.aspectRatio=e.value),"string"==typeof e.value&&(t.aspectRatio=getNumericAspectRatioFromString(e.value)),"object"===_typeof(e.value)&&null!==e.value&&(t.width=e.value.width,t.height=e.value.height,t.aspectRatio=t.height/t.width),{label:e.label,value:t}}):null},getCropStageRect=function(e,t){t.aspectRatio||(t.aspectRatio=e.image.height/e.image.width);var r=getCurrentCropSize(e.image,t,t.scaleToFit),n=r.width/r.height;return e.stage.width1&&void 0!==arguments[1]?arguments[1]:{},r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],n=t.zoom,i=t.rotation,o=t.center,a=t.aspectRatio,c=calculateCanvasSize(e,a,n),l={x:.5*c.width,y:.5*c.height},u={x:0,y:0,width:c.width,height:c.height,center:l},s=n*getImageRectZoomFactor(e,getCenteredCropRect(u,a),i,r?o:{x:.5,y:.5});return{widthFloat:c.width/s,heightFloat:c.height/s,width:Math.round(c.width/s),height:Math.round(c.height/s)}},canZoom=function(e,t){var r=rectCenter(t),n=rectCenter(e);return!vectorEqual(n,r)},getCropView=function(e){if(!e.stage||!e.image)return null;var t=e.crop.draft.rectangle||{free:e.crop.rectangle,limited:e.crop.rectangle},r=e.crop.draft.transforms||e.crop.transforms,n=r.origin,i=r.translation,o=r.scale,a=r.interaction,c=e.crop.rotation,l=e.crop.flip,u=!(!e.crop.draft.rectangle&&!e.crop.draft.transforms),s=u||e.instantUpdate,d=canZoom(t.limited,e.stage),p=e.crop.isDirty||u,f=e.crop.isRotating,h=void 0===e.crop.limitToImageBounds||e.crop.limitToImageBounds,g={width:e.image.naturalWidth,height:e.image.naturalHeight},m=getColorMatrixFromMatrices(e.colorMatrices),v=getCropFromState(e.image,{rectangle:t.limited,transforms:{origin:n,translation:i,scale:o,rotation:c.main+c.sub},flip:l,limitToImageBounds:e.crop.limitToImageBounds}),y={props:v,crop:getCurrentCropSize(g,v,e.crop.limitToImageBounds),image:getCurrentImageSize(e,t.limited)},E=y.image,T=y.crop,_=T.width,R=T.height,w=T.widthFloat/T.heightFloat;E.width&&E.height?(_=E.width,R=E.height):E.width&&!E.height?(_=E.width,R=E.width/w):E.height&&!E.width&&(R=E.height,_=E.height*w),y.currentWidth=Math.round(_),y.currentHeight=Math.round(R);var A={x:0,y:0},I=0,S=0;if(s&&a){if(a.translation){var C=a.translation.x-i.x,O=a.translation.y-i.y;A.x=100*Math.sign(C)*Math.log10(1+Math.abs(C)/100),A.y=100*Math.sign(O)*Math.log10(1+Math.abs(O)/100)}if(a.scale){var x=a.scale-o;I=.25*Math.sign(x)*Math.log10(1+Math.abs(x)/.25)}if(a.rotation){var b=a.rotation-(c.main+c.sub);S=.05*Math.sign(b)*Math.log10(1+Math.abs(b)/.05)}}var M={},L=t.free,P=rectBounds(L),G=rectBounds(t.limited);return forin(P,function(e){var t=P[e]-G[e];M[e]=G[e]+5*Math.sign(t)*Math.log10(1+Math.abs(t)/5)}),{canRecenter:d,canReset:p,isDraft:s,isRotating:f,isLimitedToImageBounds:h,cropRect:{x:M.left,y:M.top,width:M.right-M.left,height:M.bottom-M.top},origin:n,translation:i,translationBand:A,scale:o,scaleBand:I,rotation:c,rotationBand:S,flip:l,interaction:a,cropStatus:y,colorMatrix:m,markup:e.markup,previewSize:{width:e.image.width,height:e.image.height}}},isImage=function(e){return/^image/.test(e)},MATRICES={1:function(){return[1,0,0,1,0,0]},2:function(e){return[-1,0,0,1,e,0]},3:function(e,t){return[-1,0,0,-1,e,t]},4:function(e,t){return[1,0,0,-1,0,t]},5:function(){return[0,1,1,0,0,0]},6:function(e,t){return[0,1,-1,0,t,0]},7:function(e,t){return[0,-1,-1,0,t,e]},8:function(e){return[0,-1,1,0,0,e]}},getImageOrientationMatrix=function(e,t,r){return-1===r&&(r=1),MATRICES[r](e,t)},canvasRelease=function(e){e.width=1,e.height=1,e.getContext("2d").clearRect(0,0,1,1)},isFlipped=function(e){return e&&(e.horizontal||e.vertical)},getBitmap=function(e,t,r){if(t<=1&&!isFlipped(r))return e.width=e.naturalWidth,e.height=e.naturalHeight,e;var n=document.createElement("canvas"),i=e.naturalWidth,o=e.naturalHeight,a=t>=5&&t<=8;a?(n.width=o,n.height=i):(n.width=i,n.height=o);var c=n.getContext("2d");if(t&&c.transform.apply(c,getImageOrientationMatrix(i,o,t)),isFlipped(r)){var l=[1,0,0,1,0,0];(!a&&r.horizontal||a&r.vertical)&&(l[0]=-1,l[4]=i),(!a&&r.vertical||a&&r.horizontal)&&(l[3]=-1,l[5]=o),c.transform.apply(c,l)}return c.drawImage(e,0,0,i,o),n},imageToImageData=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},i=n.canvasMemoryLimit,o=n.background,a=void 0===o?null:o,c=r.zoom||1,l=getBitmap(e,t,r.flip),u={width:l.width,height:l.height},s=r.aspectRatio||u.height/u.width,d=calculateCanvasSize(u,s,c);if(i){var p=d.width*d.height;if(p>i){var f=Math.sqrt(i)/Math.sqrt(p);u.width=Math.floor(u.width*f),u.height=Math.floor(u.height*f),d=calculateCanvasSize(u,s,c)}}var h=document.createElement("canvas"),g={x:.5*d.width,y:.5*d.height},m={x:0,y:0,width:d.width,height:d.height,center:g},v=void 0===r.scaleToFit||r.scaleToFit,y=c*getImageRectZoomFactor(u,getCenteredCropRect(m,s),r.rotation,v?r.center:{x:.5,y:.5});h.width=Math.round(d.width/y),h.height=Math.round(d.height/y),g.x/=y,g.y/=y;var E=g.x-u.width*(r.center?r.center.x:.5),T=g.y-u.height*(r.center?r.center.y:.5),_=h.getContext("2d");a&&(_.fillStyle=a,_.fillRect(0,0,h.width,h.height)),_.translate(g.x,g.y),_.rotate(r.rotation||0),_.drawImage(l,E-g.x,T-g.y,u.width,u.height);var R=_.getImageData(0,0,h.width,h.height);return canvasRelease(h),R},IS_BROWSER$1="undefined"!=typeof window&&void 0!==window.document;IS_BROWSER$1&&(HTMLCanvasElement.prototype.toBlob||Object.defineProperty(HTMLCanvasElement.prototype,"toBlob",{value:function(e,t,r){var n=this.toDataURL(t,r).split(",")[1];setTimeout(function(){for(var r=atob(n),i=r.length,o=new Uint8Array(i),a=0;a2&&void 0!==arguments[2]?arguments[2]:null;return new Promise(function(n){var i=r?r(e):e;Promise.resolve(i).then(function(e){e.toBlob(n,t.type,t.quality)})})},vectorMultiply$1=function(e,t){return createVector$2(e.x*t,e.y*t)},vectorAdd$1=function(e,t){return createVector$2(e.x+t.x,e.y+t.y)},vectorNormalize$1=function(e){var t=Math.sqrt(e.x*e.x+e.y*e.y);return 0===t?{x:0,y:0}:createVector$2(e.x/t,e.y/t)},vectorRotate$1=function(e,t,r){var n=Math.cos(t),i=Math.sin(t),o=createVector$2(e.x-r.x,e.y-r.y);return createVector$2(r.x+n*o.x-i*o.y,r.y+i*o.x+n*o.y)},createVector$2=function(){return{x:arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,y:arguments.length>1&&void 0!==arguments[1]?arguments[1]:0}},getMarkupValue=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,n=arguments.length>3?arguments[3]:void 0;return"string"==typeof e?parseFloat(e)*r:"number"==typeof e?e*(n?t[n]:Math.min(t.width,t.height)):void 0},getMarkupStyles=function(e,t,r){var n=e.borderStyle||e.lineStyle||"solid",i=e.backgroundColor||e.fontColor||"transparent",o=e.borderColor||e.lineColor||"transparent",a=getMarkupValue(e.borderWidth||e.lineWidth,t,r);return{"stroke-linecap":e.lineCap||"round","stroke-linejoin":e.lineJoin||"round","stroke-width":a||0,"stroke-dasharray":"string"==typeof n?"":n.map(function(e){return getMarkupValue(e,t,r)}).join(","),stroke:o,fill:i,opacity:e.opacity||1}},isDefined=function(e){return null!=e},getMarkupRect=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,n=getMarkupValue(e.x,t,r,"width")||getMarkupValue(e.left,t,r,"width"),i=getMarkupValue(e.y,t,r,"height")||getMarkupValue(e.top,t,r,"height"),o=getMarkupValue(e.width,t,r,"width"),a=getMarkupValue(e.height,t,r,"height"),c=getMarkupValue(e.right,t,r,"width"),l=getMarkupValue(e.bottom,t,r,"height");return isDefined(i)||(i=isDefined(a)&&isDefined(l)?t.height-a-l:l),isDefined(n)||(n=isDefined(o)&&isDefined(c)?t.width-o-c:c),isDefined(o)||(o=isDefined(n)&&isDefined(c)?t.width-n-c:0),isDefined(a)||(a=isDefined(i)&&isDefined(l)?t.height-i-l:0),{x:n||0,y:i||0,width:o||0,height:a||0}},pointsToPathShape=function(e){return e.map(function(e,t){return"".concat(0===t?"M":"L"," ").concat(e.x," ").concat(e.y)}).join(" ")},setAttributes=function(e,t){return Object.keys(t).forEach(function(r){return e.setAttribute(r,t[r])})},ns$1="http://www.w3.org/2000/svg",svg=function(e,t){var r=document.createElementNS(ns$1,e);return t&&setAttributes(r,t),r},updateRect$1=function(e){return setAttributes(e,_objectSpread({},e.rect,e.styles))},updateEllipse=function(e){var t=e.rect.x+.5*e.rect.width,r=e.rect.y+.5*e.rect.height,n=.5*e.rect.width,i=.5*e.rect.height;return setAttributes(e,_objectSpread({cx:t,cy:r,rx:n,ry:i},e.styles))},IMAGE_FIT_STYLE={contain:"xMidYMid meet",cover:"xMidYMid slice"},updateImage=function(e,t){setAttributes(e,_objectSpread({},e.rect,e.styles,{preserveAspectRatio:IMAGE_FIT_STYLE[t.fit]||"none"}))},TEXT_ANCHOR={left:"start",center:"middle",right:"end"},updateText=function(e,t,r,n){var i=getMarkupValue(t.fontSize,r,n),o=t.fontFamily||"sans-serif",a=t.fontWeight||"normal",c=TEXT_ANCHOR[t.textAlign]||"start";setAttributes(e,_objectSpread({},e.rect,e.styles,{"stroke-width":0,"font-weight":a,"font-size":i,"font-family":o,"text-anchor":c})),e.text!==t.text&&(e.text=t.text,e.textContent=t.text.length?t.text:" ")},updateLine=function(e,t,r,n){setAttributes(e,_objectSpread({},e.rect,e.styles,{fill:"none"}));var i=e.childNodes[0],o=e.childNodes[1],a=e.childNodes[2],c=e.childNodes[3],l=e.rect,u={x:e.rect.x+e.rect.width,y:e.rect.y+e.rect.height};if(setAttributes(i,{x1:l.x,y1:l.y,x2:u.x,y2:u.y}),setAttributes(c,{x1:l.x,y1:l.y,x2:u.x,y2:u.y}),t.lineDecoration){o.style.display="none",a.style.display="none";var s=vectorNormalize$1({x:u.x-l.x,y:u.y-l.y}),d=getMarkupValue(.05,r,n);if(-1!==t.lineDecoration.indexOf("arrow-begin")){var p=vectorMultiply$1(s,d),f=vectorAdd$1(l,p),h=vectorRotate$1(l,2,f),g=vectorRotate$1(l,-2,f);setAttributes(o,{style:"display:block;",d:"M".concat(h.x,",").concat(h.y," L").concat(l.x,",").concat(l.y," L").concat(g.x,",").concat(g.y)})}if(-1!==t.lineDecoration.indexOf("arrow-end")){var m=vectorMultiply$1(s,-d),v=vectorAdd$1(u,m),y=vectorRotate$1(u,2,v),E=vectorRotate$1(u,-2,v);setAttributes(a,{style:"display:block;",d:"M".concat(y.x,",").concat(y.y," L").concat(u.x,",").concat(u.y," L").concat(E.x,",").concat(E.y)})}}},updatePath=function(e,t,r,n){setAttributes(e,_objectSpread({},e.styles,{fill:"none"}));var i=e.childNodes[0],o=e.childNodes[1],a=pointsToPathShape(t.points.map(function(e){return{x:getMarkupValue(e.x,r,n,"width"),y:getMarkupValue(e.y,r,n,"height")}}));setAttributes(i,{d:a}),setAttributes(o,{d:a})},createShape=function(e){return function(t){return svg(e,{id:t.id})}},createImage=function(e){var t=svg("image",{id:e.id,"stroke-linecap":"round","stroke-linejoin":"round",opacity:"0"});return t.onload=function(){t.setAttribute("opacity",e.opacity||1)},t.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",e.src),t},createLine=function(e){var t=svg("g",{id:e.id,"stroke-linecap":"round","stroke-linejoin":"round"}),r=svg("line");t.appendChild(r);var n=svg("path");t.appendChild(n);var i=svg("path");t.appendChild(i);var o=svg("line",{style:"stroke-width: 40; stroke-opacity: 0;"});return t.appendChild(o),t},createPath=function(e){var t=svg("g",{id:e.id}),r=svg("path");t.appendChild(r);var n=svg("path",{style:"stroke-width: 40; stroke-opacity: 0;"});return t.appendChild(n),t},CREATE_TYPE_ROUTES={image:createImage,rect:createShape("rect"),ellipse:createShape("ellipse"),text:createShape("text"),path:createPath,line:createLine},UPDATE_TYPE_ROUTES={rect:updateRect$1,ellipse:updateEllipse,image:updateImage,text:updateText,path:updatePath,line:updateLine},createMarkupByType=function(e,t){return CREATE_TYPE_ROUTES[e](t)},updateMarkupByType=function(e,t,r,n,i){"path"!==t&&(e.rect=getMarkupRect(r,n,i)),e.styles=getMarkupStyles(r,n,i),UPDATE_TYPE_ROUTES[t](e,r,n,i)},sortMarkupByZIndex=function(e,t){return e[1].zIndex>t[1].zIndex?1:e[1].zIndex".concat(_.replace(/ /g," "),"\n\n")}var w=t.aspectRatio||T/E,A=E,I=A*w,S=void 0===t.scaleToFit||t.scaleToFit,C=getImageRectZoomFactor({width:E,height:T},getCenteredCropRect({width:A,height:I},w),t.rotation,S?t.center:{x:.5,y:.5}),O=t.zoom*C,x=t.rotation*(180/Math.PI),b={x:.5*A,y:.5*I},M={x:b.x-E*t.center.x,y:b.y-T*t.center.y},L=["rotate(".concat(x," ").concat(b.x," ").concat(b.y,")"),"translate(".concat(b.x," ").concat(b.y,")"),"scale(".concat(O,")"),"translate(".concat(-b.x," ").concat(-b.y,")"),"translate(".concat(M.x," ").concat(M.y,")")],P=["scale(".concat(t.flip.horizontal?-1:1," ").concat(t.flip.vertical?-1:1,")"),"translate(".concat(t.flip.horizontal?-E:0," ").concat(t.flip.vertical?-T:0,")")],G='\n\n\x3c!-- Generated by PQINA - https://pqina.nl/ --\x3e\n').concat(u?u.textContent:"",'\n\n\n').concat(o.outerHTML).concat(_,"\n\n\n");i(G)},c.readAsText(e)})},objectToImageData=function(e){var t;try{t=new ImageData(e.width,e.height)}catch(r){t=document.createElement("canvas").getContext("2d").createImageData(e.width,e.height)}return t.data.set(e.data),t},TransformWorker=function(){var e={resize:function(e,t){var r=t.mode,n=void 0===r?"contain":r,i=t.upscale,a=void 0!==i&&i,u=t.width,s=t.height,d=t.matrix;if(d=!d||c(d)?null:d,!u&&!s)return l(e,d);null===u?u=s:null===s&&(s=u);if("force"!==n){var p=u/e.width,f=s/e.height,h=1;if("cover"===n?h=Math.max(p,f):"contain"===n&&(h=Math.min(p,f)),h>1&&!1===a)return l(e,d);u=e.width*h,s=e.height*h}for(var g=e.width,m=e.height,v=Math.round(u),y=Math.round(s),E=e.data,T=new Uint8ClampedArray(v*y*4),_=g/v,R=m/y,w=Math.ceil(.5*_),A=Math.ceil(.5*R),I=0;I=-1&&z<=1&&(O=2*z*z*z-3*z*z+1)>0){var W=E[(F=4*(N+D*g))+3];G+=O*W,b+=O,W<255&&(O=O*W/250),M+=O*E[F],L+=O*E[F+1],P+=O*E[F+2],x+=O}}T[C]=M/x,T[C+1]=L/x,T[C+2]=P/x,T[C+3]=G/b,d&&o(C,T,d)}return{data:T,width:v,height:y}},filter:l},t=function(t,r){var n=t.transforms,i=null;if(n.forEach(function(e){"filter"===e.type&&(i=e)}),i){var o=null;n.forEach(function(e){"resize"===e.type&&(o=e)}),o&&(o.data.matrix=i.data,n=n.filter(function(e){return"filter"!==e.type}))}r(function(t,r){return t.forEach(function(t){r=e[t.type](r,t.data)}),r}(n,t.imageData))};self.onmessage=function(e){t(e.data.message,function(t){self.postMessage({id:e.data.id,message:t},[t.data.buffer])})};var r=1,n=1,i=1;function o(e,t,o){var a=t[e]/255,c=t[e+1]/255,l=t[e+2]/255,u=t[e+3]/255,s=a*o[0]+c*o[1]+l*o[2]+u*o[3]+o[4],d=a*o[5]+c*o[6]+l*o[7]+u*o[8]+o[9],p=a*o[10]+c*o[11]+l*o[12]+u*o[13]+o[14],f=a*o[15]+c*o[16]+l*o[17]+u*o[18]+o[19],h=Math.max(0,s*f)+r*(1-f),g=Math.max(0,d*f)+n*(1-f),m=Math.max(0,p*f)+i*(1-f);t[e]=255*Math.max(0,Math.min(1,h)),t[e+1]=255*Math.max(0,Math.min(1,g)),t[e+2]=255*Math.max(0,Math.min(1,m))}var a=self.JSON.stringify([1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0]);function c(e){return self.JSON.stringify(e||[])===a}function l(e,t){if(!t||c(t))return e;for(var o=e.data,a=o.length,l=t[0],u=t[1],s=t[2],d=t[3],p=t[4],f=t[5],h=t[6],g=t[7],m=t[8],v=t[9],y=t[10],E=t[11],T=t[12],_=t[13],R=t[14],w=t[15],A=t[16],I=t[17],S=t[18],C=t[19],O=0,x=0,b=0,M=0,L=0,P=0,G=0,k=0,D=0,U=0,B=0,V=0;O=65504&&r<=65519||65534===r))break;if(o||(o=correctOrientation(t,i,n)),i+n>t.byteLength)break;i+=n}return e.slice(0,i)},getImageHead=function(e){return new Promise(function(t){var r=new FileReader;r.onload=function(){return t(readData(r.result)||null)},r.readAsArrayBuffer(e.slice(0,262144))})},getBlobBuilder=function(){return window.BlobBuilder=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder},createBlob=function(e,t){var r=getBlobBuilder();if(r){var n=new r;return n.append(e),n.getBlob(t)}return new Blob([e],{type:t})},getUniqueId$1=function(){return Math.random().toString(36).substr(2,9)},createWorker=function(e){var t=new Blob(["(",e.toString(),")()"],{type:"application/javascript"}),r=URL.createObjectURL(t),n=new Worker(r),i=[];return{transfer:function(){},post:function(e,t,r){var o=getUniqueId$1();i[o]=t,n.onmessage=function(e){var t=i[e.data.id];t&&(t(e.data.message),delete i[e.data.id])},n.postMessage({id:o,message:e},r)},terminate:function(){n.terminate(),URL.revokeObjectURL(r)}}},loadImage=function(e){return new Promise(function(t,r){var n=new Image;n.onload=function(){t(n)},n.onerror=function(e){r(e)},n.src=e})},chain=function(e){return e.reduce(function(e,t){return e.then(function(e){return t().then(Array.prototype.concat.bind(e))})},Promise.resolve([]))},canvasApplyMarkup=function(e,t){return new Promise(function(r){var n={width:e.width,height:e.height},i=e.getContext("2d"),o=t.sort(sortMarkupByZIndex).map(function(e){return function(){return new Promise(function(t){TYPE_DRAW_ROUTES[e[0]](i,n,e[1],t)&&t()})}});chain(o).then(function(){return r(e)})})},applyMarkupStyles=function(e,t){e.beginPath(),e.lineCap=t["stroke-linecap"],e.lineJoin=t["stroke-linejoin"],e.lineWidth=t["stroke-width"],t["stroke-dasharray"].length&&e.setLineDash(t["stroke-dasharray"].split(",")),e.fillStyle=t.fill,e.strokeStyle=t.stroke,e.globalAlpha=t.opacity||1},drawMarkupStyles=function(e){e.fill(),e.stroke(),e.globalAlpha=1},drawRect=function(e,t,r){var n=getMarkupRect(r,t),i=getMarkupStyles(r,t);return applyMarkupStyles(e,i),e.rect(n.x,n.y,n.width,n.height),drawMarkupStyles(e,i),!0},drawEllipse=function(e,t,r){var n=getMarkupRect(r,t),i=getMarkupStyles(r,t);applyMarkupStyles(e,i);var o=n.x,a=n.y,c=n.width,l=n.height,u=c/2*.5522848,s=l/2*.5522848,d=o+c,p=a+l,f=o+c/2,h=a+l/2;return e.moveTo(o,h),e.bezierCurveTo(o,h-s,f-u,a,f,a),e.bezierCurveTo(f+u,a,d,h-s,d,h),e.bezierCurveTo(d,h+s,f+u,p,f,p),e.bezierCurveTo(f-u,p,o,h+s,o,h),drawMarkupStyles(e,i),!0},drawImage=function(e,t,r,n){var i=getMarkupRect(r,t),o=getMarkupStyles(r,t);applyMarkupStyles(e,o);var a=new Image;new URL(r.src,window.location.href).origin!==window.location.origin&&(a.crossOrigin=""),a.onload=function(){if("cover"===r.fit){var t=i.width/i.height,c=t>1?a.width:a.height*t,l=t>1?a.width/t:a.height,u=.5*a.width-.5*c,s=.5*a.height-.5*l;e.drawImage(a,u,s,c,l,i.x,i.y,i.width,i.height)}else if("contain"===r.fit){var d=Math.min(i.width/a.width,i.height/a.height),p=d*a.width,f=d*a.height,h=i.x+.5*i.width-.5*p,g=i.y+.5*i.height-.5*f;e.drawImage(a,0,0,a.width,a.height,h,g,p,f)}else e.drawImage(a,0,0,a.width,a.height,i.x,i.y,i.width,i.height);drawMarkupStyles(e,o),n()},a.src=r.src},drawText=function(e,t,r){var n=getMarkupRect(r,t),i=getMarkupStyles(r,t);applyMarkupStyles(e,i);var o=getMarkupValue(r.fontSize,t),a=r.fontFamily||"sans-serif",c=r.fontWeight||"normal",l=r.textAlign||"left";return e.font="".concat(c," ").concat(o,"px ").concat(a),e.textAlign=l,e.fillText(r.text,n.x,n.y),drawMarkupStyles(e,i),!0},drawPath=function(e,t,r){var n=getMarkupStyles(r,t);applyMarkupStyles(e,n),e.beginPath();var i=r.points.map(function(e){return{x:getMarkupValue(e.x,t,1,"width"),y:getMarkupValue(e.y,t,1,"height")}});e.moveTo(i[0].x,i[0].y);for(var o=i.length,a=1;a2&&void 0!==arguments[2]?arguments[2]:{};return new Promise(function(n,i){if(!e||!isImage(e.type))return i({status:"not an image file",file:e});var o=r.stripImageHead,a=r.beforeCreateBlob,c=r.afterCreateBlob,l=r.canvasMemoryLimit,u=t.crop,s=t.size,d=t.filter,p=t.markup,f=t.output,h=t.image&&t.image.orientation?Math.max(1,Math.min(8,t.image.orientation)):null,g=f&&f.quality,m=null===g?null:g/100,v=f&&f.type||null,y=f&&f.background||null,E=[];!s||"number"!=typeof s.width&&"number"!=typeof s.height||E.push({type:"resize",data:s}),d&&20===d.length&&E.push({type:"filter",data:d});var T=function(e){var t=c?c(e):e;Promise.resolve(t).then(n)},_=function(t,r){var n=imageDataToCanvas(t),c=p.length?canvasApplyMarkup(n,p):n;Promise.resolve(c).then(function(t){canvasToBlob(t,r,a).then(function(r){if(canvasRelease(t),o)return T(r);getImageHead(e).then(function(e){null!==e&&(r=new Blob([e,r.slice(20)],{type:r.type})),T(r)})}).catch(i)})};if(/svg/.test(e.type)&&null===v)return cropSVG(e,u,p,{background:y}).then(function(e){n(createBlob(e,"image/svg+xml"))});var R=URL.createObjectURL(e);loadImage(R).then(function(t){URL.revokeObjectURL(R);var r=imageToImageData(t,h,u,{canvasMemoryLimit:l,background:y}),n={quality:m,type:v||e.type};if(!E.length)return _(r,n);var i=createWorker(TransformWorker);i.post({transforms:E,imageData:r},function(e){_(objectToImageData(e),n),i.terminate()},[r.data.buffer])}).catch(i)})},readExif=function(e,t){if(1165519206!==e.getUint32(t+=2,!1))return-1;var r=18761===e.getUint16(t+=6,!1);t+=e.getUint32(t+4,r);var n=e.getUint16(t,r);t+=2;for(var i=0;i3&&void 0!==arguments[3])||arguments[3],i=e.center,o=e.zoom,a=e.aspectRatio,c=rectCenter(t),l={x:c.x-r.width*i.x,y:c.y-r.height*i.y},u=2*Math.PI+e.rotation%(2*Math.PI),s=o*getImageRectZoomFactor(r,getCenteredCropRect(t,a||r.height/r.width),u,n?i:{x:.5,y:.5});return{origin:{x:i.x*r.width,y:i.y*r.height},translation:l,scale:s,rotation:e.rotation}},copyImageTransforms=function(e){return{origin:_objectSpread({},e.origin),translation:_objectSpread({},e.translation),rotation:e.rotation,scale:e.scale}},limitImageTransformsToCropRect=function(e,t,r,n){var i=r.translation,o=r.scale,a=r.rotation,c=r.origin,l={origin:_objectSpread({},c),translation:_objectSpread({},i),scale:o,rotation:2*Math.PI+a%(2*Math.PI)},u=e.height/e.width,s=getAxisAlignedCropRect(c,i,l.rotation,t),d=rectCenter(s),p=rectBounds(s),f=getAxisAlignedImageRect(e,r),h=rectCenter(f),g={x:f.x,y:f.y},m={x:h.x,y:h.y},v=d.x,y=d.y,E={x:g.x,y:g.y,width:f.width,height:f.height};if(!rectFitsInRect(s,f))if("moving"===n){E.y>s.y?E.y=s.y:E.y+E.heights.x?E.x=s.x:E.x+E.widths.y?E.y=s.y:E.y+E.heights.x?E.x=s.x:E.x+E.widths.y?E.y=s.y:E.y+E.heights.x?E.x=s.x:E.x+E.widths.y?E.y=s.y:E.y+E.heights.x?E.x=s.x:E.x+E.widths.y){var x=E.y-s.y;E.y=s.y,E.height+=2*x,O=!0}if(E.y+E.heights.x){var M=E.x-s.x;E.x=s.x,E.width+=2*M,O=!0}if(E.x+E.widths.right||u.bottom>s.bottom||u.left=p.bottom){var y=p.bottom-p.top,E=p.right-p.left,T=Math.max(1,l.height/y),_=y*T,R=E*T-E;p.bottom=u.bottom,p.top=u.bottom-_,p.left-=.5*R,p.right+=.5*R}if(u.left<=p.left){var w=p.bottom-p.top,A=p.right-p.left,I=Math.max(1,l.width/A),S=A*I,C=w*I-w;p.right=u.left+S,p.left=u.left,p.top-=.5*C,p.bottom+=.5*C}if(u.right>=p.right){var O=p.bottom-p.top,x=p.right-p.left,b=Math.max(1,l.width/x),M=x*b,L=O*b-O;p.right=u.right,p.left=u.right-M,p.top-=.5*L,p.bottom+=.5*L}d=createRect(p.left,p.top,p.right-p.left,p.bottom-p.top)}var P=rectCorners(d),G=rectCenter(d),k=vectorRotate(P.tl,o,c),D=vectorRotate(P.br,o,c),U=k.x+.5*(D.x-k.x),B=k.y+.5*(D.y-k.y),V=rectTranslate(d,{x:U-G.x,y:B-G.y}),N=rectTranslate(l,{x:U-G.x,y:B-G.y}),F=rectCenter(N),z={x:V.x,y:V.y},W=V.width,q=V.height,H=(F.x-z.x)/W,Y=(F.y-z.y)/q,j=W/e.width,X={x:H*e.width,y:Y*e.height},Z=1-j,$=X.x*Z,K=X.y*Z,Q={x:z.x+W*H,y:z.y+q*Y},J=vectorRotate(z,o,{x:z.x+.5*W,y:z.y+.5*q}),ee=vectorRotate(z,o,Q),te=J.x-ee.x,re=J.y-ee.y;return{origin:X,translation:{x:z.x-$+te,y:z.y-K+re},scale:j,rotation:r.rotation}},getEdgeTargetRect=function(e,t,r,n,i,o,a,c,l){var u=o.left,s=o.right,d=o.top,p=o.bottom,f=s-u,h=p-d,g=i.left,m=i.right,v=i.top,y=i.bottom;if(r===Direction.VERTICAL){if(v=e.y>0?n.y:Math.min(n.y,Math.max(t.y,d)),y=e.y>0?Math.max(n.y,Math.min(t.y,p)):n.y,a){var E=(y-v)/a;g=n.x-.5*E,m=n.x+.5*E}}else if(g=e.x>0?n.x:Math.min(n.x,Math.max(t.x,u)),m=e.x>0?Math.max(n.x,Math.min(t.x,s)):n.x,a){var T=(m-g)*a;v=n.y-.5*T,y=n.y+.5*T}var _,R,w,A,I=c.width,S=c.height;if(r===Direction.VERTICAL?(_=n.x-.5*I,R=n.x+.5*I,e.y<0?(w=n.y-S,A=n.y):e.y>0&&(w=n.y,A=n.y+S)):(w=n.y-.5*S,A=n.y+.5*S,e.x<0?(_=n.x-I,R=n.x):e.x>0&&(_=n.x,R=n.x+I)),a)if(r===Direction.VERTICAL){var C=Math.min((y-v)/a,f),O=C*a;gs&&(g=(m=s)-C),n.x=g+.5*C,e.y<0?v=n.y-O:e.y>0&&(y=n.y+O)}else{var x=Math.min((m-g)*a,h),b=x/a;vp&&(v=(y=p)-x),n.y=v+.5*x,e.x<0?g=n.x-b:e.x>0&&(m=n.x+b)}var M=rectFromBounds({top:v,right:m,bottom:y,left:g}),L=function(){var t=I*a;r===Direction.HORIZONTAL?(v=n.y-.5*t,y=n.y+.5*t):e.y<0?(y=n.y,v=y-t):e.y>0&&(v=n.y,y=v+t)},P=function(){var t=S/a;r===Direction.VERTICAL?(g=n.x-.5*t,m=n.x+.5*t):e.x<0?(m=n.x,g=m-t):e.x>0&&(g=n.x,m=g+t)};m_&&(g=_,m=_+I,a&&L()),v>w&&(v=w,y=w+S,a&&P()),yG&&(e.x<0?g=n.x-G:m=n.x+G),y-v>k&&(e.y<0?v=n.y-k:y=n.y+k),m-g==0&&(e.x>0?m=n.x+2:g=n.x-2),y-v==0&&(e.y>0?y=n.y+2:v=n.y-2),Math.round(g)s||Math.round(v)p){var D=p-d,U=s-u;if(gs){m=s;var V=Math.min(m-g,U);g=m-V}if(vp){y=p;var F=Math.min(y-v,D);v=y-F}M=rectFromBounds({top:v,right:m,bottom:y,left:g})}return{free:M,limited:rectFromBounds({top:v,right:m,bottom:y,left:g})}},CornerMap={nw:function(e){return{x:e.x,y:e.y}},ne:function(e){return{x:e.x+e.width,y:e.y}},se:function(e){return{x:e.x+e.width,y:e.y+e.height}},sw:function(e){return{x:e.x,y:e.y+e.height}}},getCornerCoordinates=function(e,t){return CornerMap[e](t)},getCornerTargetRect=function(e,t,r,n,i,o,a){var c=rectBounds(n),l=c.left,u=c.right,s=c.top,d=c.bottom,p=vectorLimit({x:t.x,y:t.y},n),f=e.x>0?r.x:Math.min(p.x,r.x),h=e.x>0?Math.max(r.x,p.x):r.x,g=e.y>0?r.y:Math.min(p.y,r.y),m=e.y>0?Math.max(r.y,p.y):r.y;if(i){var v=p.x-r.x;e.x>0?h=Math.max(r.x,r.x+e.x*v):f=Math.min(r.x,r.x-e.x*v),e.y>0?m=Math.max(r.y,r.y+e.x*v*i):g=Math.min(r.y,r.y-e.x*v*i)}var y=rectFromBounds({top:g,right:h,bottom:m,left:f});rectFromBounds({top:g,right:h,bottom:m,left:f});if(o.width&&o.height){var E=o.width,T=o.height;i&&(1===i?T=E=Math.max(E,T):ET?T=E*i:E=T/i),h-f0?h=r.x+E:f=r.x-E),m-g0?m=r.y+T:g=r.y-T);var _=a.width,R=a.height;i&&(i<1?_=R/i:R=_*i),h-f>_&&(e.x<0?f=r.x-_:h=r.x+_),m-g>R&&(e.y<0?g=r.y-R:m=r.y+R)}if(h-f==0&&(e.x>0?h=r.x+2:f=r.x-2),m-g==0&&(e.y>0?m=r.y+2:g=r.y-2),Math.round(f)u||Math.round(g)d){var w=d-s,A=u-l;if(f0&&(m=r.y+I*i),e.y<0&&(g=r.y-I*i))}if(h>u){h=u;var S=Math.min(h-f,A);f=h-S,i&&(e.y>0&&(m=r.y+S*i),e.y<0&&(g=r.y-S*i))}if(g0&&(h=r.x+C/i),e.x<0&&(f=r.x-C/i))}if(m>d){m=d;var O=Math.min(m-g,w);g=m-O,i&&(e.x>0&&(h=r.x+O/i),e.x<0&&(f=r.x-O/i))}y=rectFromBounds({top:g,right:h,bottom:m,left:f})}return{free:y,limited:rectFromBounds({top:g,right:h,bottom:m,left:f})}},getTargetRect=function(e,t,r){var n=rectClone(e);return n.width=Math.min(n.height,n.width),n.height=n.width,n.height=n.width*t,n.heightt&&(o-=r,i+=r),{main:i,sub:o}},getImageSize=function(e){return new Promise(function(t,r){var n=new Image;n.src=URL.createObjectURL(e),n.onerror=function(e){clearInterval(i),r(e)};var i=setInterval(function(){n.naturalWidth&&n.naturalHeight&&(clearInterval(i),URL.revokeObjectURL(n.src),t({width:n.naturalWidth,height:n.naturalHeight}))},1)})},scaleImageSize=function(e,t){var r={width:e.width,height:e.height};if(e.width>t.width||e.height>t.height){var n=e.height/e.width,i=t.width/e.width,o=t.height/e.height;i1&&void 0!==arguments[1]?arguments[1]:"";return(t+e).slice(-t.length)},getDateString=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Date;return"".concat(e.getFullYear(),"-").concat(leftPad(e.getMonth()+1,"00"),"-").concat(leftPad(e.getDate(),"00"),"_").concat(leftPad(e.getHours(),"00"),"-").concat(leftPad(e.getMinutes(),"00"),"-").concat(leftPad(e.getSeconds(),"00"))},getBaseCropInstructions=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},i=e("GET_CROP_ASPECT_RATIO"),o={center:{x:.5,y:.5},flip:{horizontal:!1,vertical:!1},zoom:1,rotation:0,aspectRatio:null};r?Object.assign(o,r):t.options.crop?Object.assign(o,t.options.crop):o.aspectRatio=i;var a=n.width,c=n.height;if(a&&c)o.aspectRatio=c/a;else if(t.instructions.size){var l=t.instructions.size,u=l.width,s=l.height;u&&s&&(o.aspectRatio=s/u)}return o},capitalizeFirstLetter=function(e){return e.charAt(0).toUpperCase()+e.slice(1)},getExtensionFromFilename=function(e){return e.split(".").pop()},guesstimateExtension=function(e){if("string"!=typeof e)return"";var t=e.split("/").pop();return/svg/.test(t)?"svg":/zip|compressed/.test(t)?"zip":/plain/.test(t)?"txt":/msword/.test(t)?"doc":/[a-z]+/.test(t)?"jpeg"===t?"jpg":t:""},getFileFromBlob=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,i="string"==typeof r?e.slice(0,e.size,r):e.slice(0,e.size,e.type);return i.lastModifiedDate=new Date,isString(t)||(t=getDateString()),t&&null===n&&getExtensionFromFilename(t)?i.name=t:(n=n||guesstimateExtension(i.type),i.name=t+(n?"."+n:"")),i},getFilenameWithoutExtension=function(e){return e.substr(0,e.lastIndexOf("."))||e},ExtensionMap={jpeg:"jpg","svg+xml":"svg"},renameFileToMatchMimeType=function(e,t){var r=getFilenameWithoutExtension(e),n=t.split("/")[1],i=ExtensionMap[n]||n;return"".concat(r,".").concat(i)},getValidOutputMimeType=function(e){return/jpeg|png|svg\+xml/.test(e)?e:"image/jpeg"},isColorMatrix=function(e){return Array.isArray(e)&&20===e.length},MARKUP_RECT=["x","y","left","top","right","bottom","width","height"],toOptionalFraction=function(e){return"string"==typeof e&&/%/.test(e)?parseFloat(e)/100:e},getUniqueId$2=function(){return Math.random().toString(36).substr(2,9)},prepareMarkup=function(e){var t=_slicedToArray(e,2),r=t[0],n=t[1],i=!1!==n.allowSelect,o=!1!==n.allowMove,a=!1!==n.allowResize,c=!1!==n.allowInput,l=!1!==n.allowDestroy,u=void 0===n.allowEdit||n.allowEdit;(!0===n.allowResize||!0===n.allowMove||!0===n.allowInput||n.allowEdit)&&(i=!0),!1===n.allowMove&&(a=!1),!0===n.allowResize&&(o=!0);var s=n.points?{}:MARKUP_RECT.reduce(function(e,t){return e[t]=toOptionalFraction(n[t]),e},{});return n.points&&(a=!1),[r,_objectSpread({zIndex:0,id:getUniqueId$2()},n,s,{isDestroyed:!1,isSelected:!1,isDirty:!0,allowDestroy:l,allowSelect:i,allowMove:o,allowResize:a,allowInput:c,allowEdit:u})]},getFilenameFromHeader=function(e){if(!e)return null;var t=e.split(/filename=|filename\*=.+''/).splice(1).map(function(e){return e.trim().replace(/^["']|[;"']{0,2}$/g,"")}).filter(function(e){return e.length});return t.length?decodeURI(t[t.length-1]):null},brightness=function(e){return[1,0,0,0,e,0,1,0,0,e,0,0,1,0,e,0,0,0,1,0]},contrast=function(e){return[e,0,0,0,.5*(1-e),0,e,0,0,.5*(1-e),0,0,e,0,.5*(1-e),0,0,0,1,0]},saturation=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return[.213+.787*e,.715-.715*e,.072-.072*e,0,0,.213-.213*e,.715+.285*e,.072-.072*e,0,0,.213-.213*e,.715-.715*e,.072+.928*e,0,0,0,0,0,1,0]},exposure=function(e){return[e,0,0,0,0,0,e,0,0,0,0,0,e,0,0,0,0,0,1,0]},testSrc="data:image/jpg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/4QA6RXhpZgAATU0AKgAAAAgAAwESAAMAAAABAAYAAAEoAAMAAAABAAIAAAITAAMAAAABAAEAAAAAAAD/2wBDAP//////////////////////////////////////////////////////////////////////////////////////wAALCAABAAIBASIA/8QAJgABAAAAAAAAAAAAAAAAAAAAAxABAAAAAAAAAAAAAAAAAAAAAP/aAAgBAQAAPwBH/9k=",shouldCorrect=void 0,testImage=isBrowser()?new Image:{};testImage.onload=function(){shouldCorrect=testImage.naturalWidth>testImage.naturalHeight,testImage=void 0},testImage.src=testSrc;var shouldCorrectImageExifOrientation=function(){return shouldCorrect},testResult$1=null,isIE=function(){return null===testResult$1&&(testResult$1=/MSIE|Trident/.test(window.navigator.userAgent)),testResult$1},COLOR_TOOLS={contrast:contrast,exposure:exposure,brightness:brightness,saturation:saturation},getColorProperty=function(e){return e.borderWidth?"borderColor":e.lineWidth?"lineColor":e.fontColor?"fontColor":e.backgroundColor?"backgroundColor":void 0},getColor=function(e){var t=e.fontColor,r=e.backgroundColor,n=e.lineColor,i=e.borderColor;return t||r||n||i},TURN$1=Math.PI/2,getOutputSize=function(e){var t={upscale:e("GET_OUTPUT_UPSCALE"),mode:e("GET_OUTPUT_FIT"),width:e("GET_OUTPUT_WIDTH"),height:e("GET_OUTPUT_HEIGHT")},r=e("GET_SIZE_INPUT");if(r.width||r.height){var n=r.width,i=r.height,o=e("GET_CROP_RECTANGLE_ASPECT_RATIO");n&&!i?i=n/o:i&&!n&&(n=i*o),t.width=n,t.height=i,t.upscale=!0,t.mode="force"}return t},getPreparedImageSize=function(e,t){var r=t("GET_UID"),n=t("GET_CROP",r,Date.now()),i={width:n.cropStatus.currentWidth,height:n.cropStatus.currentHeight},o=e.mode,a=e.width,c=e.height,l=e.upscale;if(!a&&!c)return i;if(null===a?a=c:null===c&&(c=a),"force"!==o){var u=a/i.width,s=c/i.height,d=1;if("cover"===o?d=Math.max(u,s):"contain"===o&&(d=Math.min(u,s)),d>1&&!1===l)return i;a=i.width*d,c=i.height*d}return{width:Math.round(a),height:Math.round(c)}},getActiveMarkupFromState=function(e){return e.markup.filter(function(e){return!e[1].isDestroyed})},cleanMarkupForExport=function(e){return e.map(function(e){var t=_objectSpread({},e[1]);return Object.keys(t).forEach(function(e){void 0===t[e]&&delete t[e]}),delete t.isDestroyed,delete t.isSelected,delete t.isDirty,[e[0],t]})},prepareOutput=function(e,t,r){return new Promise(function(n,i){var o={data:null,file:null},a=getCropFromStateRounded(t.image,t.crop),c=getOutputSize(r),l={crop:a,image:_objectSpread({},getPreparedImageSize(c,r),{orientation:t.file.orientation}),size:c,output:{type:r("GET_OUTPUT_TYPE"),quality:r("GET_OUTPUT_QUALITY"),background:t.options.outputCanvasBackgroundColor},filter:t.colorMatrices.filter?{id:t.filterName,value:t.filterValue,matrix:t.colorMatrices.filter}:null,color:Object.keys(t.colorValues).length?Object.keys(t.colorValues).reduce(function(e,r){return e[r]={value:t.colorValues[r],matrix:t.colorMatrices[r].map(function(e){return roundFloat(e,5)})},e},{}):null,markup:cleanMarkupForExport(getActiveMarkupFromState(t).map(function(e){return[e[0],_objectSpread({},e[1])]})),colorMatrix:r("GET_COLOR_MATRIX")};if(e.data&&(o.data=l),e.file){var u={beforeCreateBlob:r("GET_BEFORE_CREATE_BLOB"),afterCreateBlob:r("GET_AFTER_CREATE_BLOB"),stripImageHead:r("GET_OUTPUT_STRIP_IMAGE_HEAD"),canvasMemoryLimit:r("GET_OUTPUT_CANVAS_MEMORY_LIMIT")},s=t.file.data,d=_objectSpread({},l,{filter:l.colorMatrix,markup:l.markup});transformImage(s,d,u).then(function(e){o.file=getFileFromBlob(e,renameFileToMatchMimeType(s.name,getValidOutputMimeType(e.type))),n(o)}).catch(i)}else n(o)})},resetRotationScale=function(e){e.crop.draft.rotateMinScale=null},storeRotationScale=function(e){e.crop.draft.rotateMinScale||(e.crop.draft.rotateMinScale=e.crop.transforms.scale)},rotate=function(e,t,r){var n=arguments.length>3&&void 0!==arguments[3]&&arguments[3],i=!(arguments.length>4&&void 0!==arguments[4])||arguments[4];storeRotationScale(e);var o=_objectSpread({},e.crop.transforms,{scale:e.crop.draft.rotateMinScale});e.crop.draft.transforms=getRotateTransforms(e.image,e.crop.rectangle,o,t.main+t.sub,r,e.crop.draft.transforms?e.crop.draft.transforms.rotation:e.crop.rotation.main+e.crop.rotation.sub,n,i),e.crop.rotation=splitRotation(e.crop.draft.transforms.rotation)},resetCrop=function(e,t){if(null!==e.stage){var r=void 0===e.instructions.crop.scaleToFit?void 0===e.crop.limitToImageBounds?e.options.cropLimitToImageBounds:e.crop.limitToImageBounds:e.instructions.crop.scaleToFit,n=t("GET_STAGE_RECT",e.instructions.crop);e.crop.rectangle=getCenteredCropRect(n.fits?n:e.stage,e.instructions.crop.aspectRatio||e.image.aspectRatio),e.crop.draft.rectangle=null,"stage"!==n.mode&&n.fits&&(e.crop.rectangle.x=n.x,e.crop.rectangle.y=n.y),e.crop.transforms=getImageTransformsFromCrop(e.instructions.crop,n,e.image,r),e.crop.draft.transforms=null,e.crop.rotation=splitRotation(e.instructions.crop.rotation),e.crop.flip=_objectSpread({},e.instructions.crop.flip);var i=t("GET_CROP_ASPECT_RATIO_OPTIONS")||[],o=i.map(function(e){return e.value.aspectRatio}).find(function(t){return t===e.instructions.crop.aspectRatio}),a=i.find(function(e){return null===e.value.aspectRatio});o?e.crop.aspectRatio=o:a&&i.length?e.crop.aspectRatio=null:e.crop.aspectRatio=t("GET_CROP_ASPECT_RATIO"),e.crop.isDirty=!1}},reset=function(e,t,r){if(null!==e.stage){clearCenterTimeout(e),e.size.width=!!e.instructions.size&&e.instructions.size.width,e.size.height=!!e.instructions.size&&e.instructions.size.height,e.size.aspectRatioLocked=!0,e.size.aspectRatioPrevious=!1;var n=void 0===e.instructions.crop.scaleToFit?void 0===e.crop.limitToImageBounds?e.options.cropLimitToImageBounds:e.crop.limitToImageBounds:e.instructions.crop.scaleToFit;resetCrop(e,t),e.instructions.markup&&r("MARKUP_SET_VALUE",{value:e.instructions.markup}),r("CROP_SET_LIMIT",{value:n,silent:!0}),Object.keys(e.instructions.color).forEach(function(t){return r("COLOR_SET_VALUE",{key:t,value:e.instructions.color[t]})}),r("FILTER_SET_VALUE",{value:e.instructions.filter}),resetRotationScale(e)}},recenter=function(e,t){if(e.stage){clearCenterTimeout(e);var r=e.crop.rectangle,n=r.height/r.width,i=e.crop.aspectRatio;if(null!==i&&roundFloat(n,3)!==roundFloat(i,3)){var o=t("GET_MIN_CROP_SIZE");o.width=roundFloat(o.width),o.height=roundFloat(o.height);var a=Math.min(r.width,r.height);Math.min(a*i,a/i)roundFloat(s,5)?(a&&(o+=2*a),_objectSpread({},copyImageTransforms(r),{rotation:o,interaction:{rotation:u.rotation}})):(u.scale=Math.min(s,u.scale),u.interaction={rotation:u.rotation},u)},getResizeTransforms=function(e,t,r,n,i,o){var a=Math.max(1e-10,n),c=_objectSpread({},copyImageTransforms(r),{scale:a}),l=o?limitImageTransformsToCropRect(e,t,c,"resizing"):c,u=getMinScale(t,i);return l.scale=Math.min(u,l.scale),l.interaction={scale:a},l},getTranslateTransforms=function(e,t,r,n,i){var o={x:r.translation.x+n.x,y:r.translation.y+n.y},a=_objectSpread({},copyImageTransforms(r),{translation:o}),c=i?limitImageTransformsToCropRect(e,t,a,"moving"):a;return c.interaction={translation:o},c},correctCropRectangleByResize=function(e,t){var r=roundFloat(e.crop.draft.transforms.scale,5);if(!(roundFloat(e.crop.draft.targetSize,5)=0?e.getResponseHeader(t):null},ImageExtensionMap={svg:"svg+xml",jpg:"jpeg"},getImageMimeType=function(e,t){if(isImage(e))return e;if(!t)return e;var r=getExtensionFromFilename(t);return r?"image/".concat(ImageExtensionMap[r]||r):e},getFilenameFromURL=function(e){return e.split("/").pop().split("?").shift()},loadImageFromURL=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.progress,n=void 0===r?function(e){}:r,i=t.load,o=void 0===i?function(e,t){}:i,a=t.error,c=void 0===a?function(){}:a,l=new XMLHttpRequest;l.onprogress=function(e){return n(e.lengthComputable?e.loaded/e.total:null)},l.onerror=function(){return c(l)},l.onload=function(){var t=l.status>=200&&l.status<300,r=l.response;if(!t||!r)return c(l);var n=getResponseHeaderSilent(l,"Content-Disposition"),i=n?getFilenameFromHeader(n):getFilenameFromURL(e),a=getImageMimeType(l.getResponseHeader("Content-Type"),i),u=getResponseHeaderSilent(l,"Content-Doka"),s=null;if(u)try{s=JSON.parse(u)}catch(e){}!isImage(r.type)&&a&&(r=r.slice(0,r.size,a)),"name"in r||!i||(r.name=i),o(r,s)},l.open("GET",e),l.responseType="blob",l.send()},dataURIToBlob=function(e){for(var t=e.split(","),r=t[0].match(/([a-z]+\/[a-z]+)/)[0],n=atob(t[1]),i=n.length,o=new ArrayBuffer(n.length),a=new Uint8Array(o),c=0;c-1){var d=u.width,p=u.height;s>=5&&s<=8&&(u.width=p,u.height=d)}var f=t("GET_MIN_IMAGE_SIZE");if(u.width1?.5/o:.5,c=o>1?.5:.5*o,l=function(){return{width:a,height:c,x:.5+.5*i()-.5*a,y:.5+.5*i()-.5*c}},u=function(e){return t("GET_MARKUP_TOOL_VALUES")[e]},s=function(){var e=u("shapeStyle"),t=u("color"),r=e[0]||e[1]?null:t;return{backgroundColor:r,borderWidth:e[0],borderStyle:e[1]?e[1]:null,borderColor:null!==r?null:t}},d={rect:function(){return _objectSpread({},l(),s())},ellipse:function(){return _objectSpread({},l(),s())},text:function(){return{x:.5+.5*i()-.1,y:.5+.5*i(),width:0,height:0,fontColor:u("color"),fontSize:u("fontSize"),fontFamily:u("fontFamily"),text:"Text"}},line:function(){var e=u("lineStyle");return _objectSpread({},l(),{lineColor:u("color"),lineWidth:e[0],lineStyle:e[1]?e[1]:null,lineDecoration:u("lineDecoration")})}}[n]();e("MARKUP_ADD",[n,d])},MARKUP_ADD:function(n){r.markup.forEach(function(e){return e[1].isSelected=!1}),r.markup=r.markup.filter(function(e){return!e[1].isDestroyed});var i=prepareMarkup(n);r.markup.push(i),r.markup.sort(sortMarkupByZIndex),"draw"!==t("GET_MARKUP_UTIL")&&e("MARKUP_SELECT",{id:i[1].id}),r.crop.isDirty=!0},MARKUP_SELECT:function(e){var t=e.id;r.markup.forEach(function(e){e[1].isSelected=e[1].id===t,e[1].isDirty=!0})},MARKUP_ELEMENT_DRAG:function(e){var t=e.id,n=e.origin,i=e.offset,o=e.size,a=r.markup.find(function(e){return e[1].id===t});if(a){var c=a[1],l=n.x/o.width,u=n.y/o.height,s=n.width/o.width,d=n.height/o.height,p=i.x/o.width,f=i.y/o.height;c.x=l+p,c.y=u+f,c.width=s,c.height=d,c.left=void 0,c.top=void 0,c.right=void 0,c.bottom=void 0,c.isDirty=!0,r.crop.isDirty=!0}},MARKUP_ELEMENT_RESIZE:function(e){var t=e.id,n=e.corner,i=e.origin,o=e.offset,a=e.size,c=r.markup.find(function(e){return e[1].id===t});if(c){var l=_slicedToArray(c,2),u=l[0],s=l[1],d=(i.x+o.x)/a.width,p=(i.y+o.y)/a.height;if(/n/.test(n))if("line"===u)s.height=s.height-(p-s.y),s.y=p;else{var f=s.y+s.height;p>f&&(p=f),s.height=s.height-(p-s.y),s.y=p}if(/w/.test(n))if("line"===u)s.width=s.width-(d-s.x),s.x=d;else{var h=s.x+s.width;d>h&&(d=h),s.width=s.width-(d-s.x),s.x=d}/s/.test(n)&&(s.height="line"===u?p-s.y:Math.max(0,p-s.y)),/e/.test(n)&&(s.width="line"===u?d-s.x:Math.max(0,d-s.x)),s.left=void 0,s.top=void 0,s.right=void 0,s.bottom=void 0,s.isDirty=!0,r.crop.isDirty=!0}},MARKUP_DELETE:function(t){var n=t.id,i=r.markup.find(function(e){return e[1].id===n});if(i){var o=i[1];o.allowDestroy&&(o.isDestroyed=!0,o.isSelected=!1,o.isDirty=!0);for(var a=null,c=r.markup.length;c>0;){c--;var l=r.markup[c][1];if(!l.isDestroyed&&l.allowDestroy){a=l.id;break}}e("MARKUP_SELECT",{id:a})}},MARKUP_UPDATE:function(e){var t=e.style,n=e.value;r.markupToolValues[t]=n,r.markup.map(function(e){return e[1]}).filter(function(e){return e.isSelected}).forEach(function(e){if("color"===t)e[getColorProperty(e)]=n;else if("shapeStyle"===t){var r=getColor(e);e.borderColor=r,e.borderWidth=n[0],e.borderStyle=n[1],e.backgroundColor=n[0]||n[1]?null:r,null!==e.backgroundColor&&(e.borderColor=null)}else"lineStyle"===t?(e.lineWidth=n[0],e.lineStyle=n[1]):e[t]=n;e.isDirty=!0}),r.crop.isDirty=!0}},["color","shapeStyle","lineStyle","textDecoration","fontSize","fontFamily"].reduce(function(t,n){var i=n.split(/(?=[A-Z])/).join("_").toUpperCase(),o=capitalizeFirstLetter(n);return t["SET_MARKUP_"+i]=function(t){var i=t.value;i!==t.prevValue&&(r.options["markup".concat(o)]=i,e("MARKUP_UPDATE",{style:n,value:i}))},t},{}),{DID_SET_CROP:function(t){var r=t.value;r!==t.prevValue&&e("SET_DATA",{crop:r})},COLOR_SET_COLOR_VALUE:function(t){var n=t.key,i=t.value;r.crop.isDirty=!0,e("COLOR_SET_VALUE",{key:n,value:i})},COLOR_SET_VALUE:function(t){var n=t.key,i=t.value;r.colorValues[n]=i,e("SET_COLOR_MATRIX",{key:n,matrix:COLOR_TOOLS[n](i)})}},Object.keys(COLOR_TOOLS).reduce(function(n,i){var o=i.toUpperCase(),a=capitalizeFirstLetter(i);return n["SET_COLOR_".concat(o)]=function(n){var c=n.value;if(c!==n.prevValue){var l=_slicedToArray(t("GET_COLOR_".concat(o,"_RANGE")),2),u=l[0],s=l[1],d=limit(c,u,s);r.options["color".concat(a)]=d,r.instructions.color||(r.instructions.color={}),r.instructions.color[i]=d,e("COLOR_SET_VALUE",{key:i,value:d})}},n},{}),{SET_COLOR_MATRIX:function(t){var n=t.key,i=t.matrix;i?r.colorMatrices[n]=_toConsumableArray(i):delete r.colorMatrices[n],e("DID_SET_COLOR_MATRIX",{key:n,matrix:i})},FILTER_SET_FILTER:function(t){var n=t.value;r.crop.isDirty=!0,e("FILTER_SET_VALUE",{value:n})},FILTER_SET_VALUE:function(n){var i=n.value,o=isColorMatrix(i)?i:null;if(isString(i)){var a=t("GET_FILTERS");forin(a,function(e,t){e===i&&(o=t.matrix())})}r.filter=i,r.filterName=isString(i)?i:null,e("SET_COLOR_MATRIX",{key:"filter",matrix:o})},DID_SET_UTIL:function(t){var n=t.value;t.prevValue;-1!==r.options.utils.indexOf(n)&&e("CHANGE_VIEW",{id:n})},DID_SET_FILTER:function(t){var r=t.value;r!==t.prevValue&&(r&&r.id&&(r=r.id),e("FILTER_SET_VALUE",{value:r}),e("SET_DATA",{filter:r}))},DID_SET_SIZE:function(t){var r=t.value;r!==t.prevValue&&e("SET_DATA",{size:r})},DID_SET_MARKUP_UTIL:function(t){var r=t.value;r!==t.prevValue&&r&&(/^(draw|line|text|rect|ellipse)$/.test(r)||(r="select"),e("SWITCH_MARKUP_UTIL",{util:r}))},DID_SET_MARKUP:function(t){var r=t.value,n=t.prevValue;r!==n&&JSON.stringify(r)===JSON.stringify(n)||(e("MARKUP_SET_VALUE",{value:r}),e("SET_DATA",{markup:r}))},SET_DATA:function(n){if(n.size){var i=_objectSpread({width:null,height:null},n.size),o=limitSize(i,t("GET_SIZE_MIN"),t("GET_SIZE_MAX"),null);r.instructions.size=_objectSpread({},o),e("RESIZE_SET_OUTPUT_SIZE",o)}n.filter&&(r.instructions.filter=n.filter?n.filter.id||n.filter.matrix:n.colorMatrix),r.instructions.markup=n.markup||[],r.instructions.markup.forEach(function(e){return e[1].isDirty=!0}),r.instructions.color=Object.keys(COLOR_TOOLS).reduce(function(e,t){var i=void 0===n.color||void 0===n.color[t],o=r.options["color".concat(capitalizeFirstLetter(t))];return e[t]=i?o:isNumber(n.color[t])?n.color[t]:n.color[t].value,e},{}),n.crop&&(r.instructions.crop=getBaseCropInstructions(t,r,n.crop,r.size),r.crop.limitToImageBounds=r.options.cropLimitToImageBounds,!1===r.instructions.crop.scaleToFit&&(r.crop.limitToImageBounds=r.instructions.crop.scaleToFit),resetCrop(r,t))},DID_SET_INITIAL_STATE:function(e){var n=e.value||{},i=n.crop,o=n.filter,a=n.color,c=n.size,l=void 0===c?{}:c,u=n.markup,s=void 0===u?[]:u,d=_objectSpread({width:null,height:null},l),p=limitSize(d,t("GET_SIZE_MIN"),t("GET_SIZE_MAX"),null);r.instructions.size=_objectSpread({},p),r.instructions.crop=getBaseCropInstructions(t,r,i),r.crop.limitToImageBounds=r.options.cropLimitToImageBounds,!1===r.instructions.crop.scaleToFit&&(r.crop.limitToImageBounds=r.instructions.crop.scaleToFit),r.instructions.filter=o||null,r.instructions.color=Object.keys(COLOR_TOOLS).reduce(function(e,t){return e[t]=void 0===a||void 0===a[t]?r.options["color".concat(capitalizeFirstLetter(t))]:a[t],e},{}),r.instructions.markup=s,r.crop.isDirty=!0},GET_DATA:function(n){var i=n.success,o=n.failure,a=n.file,c=n.data;if(!r.file)return o("no-image-source");if(!r.stage)return o("image-not-fully-loaded");var l={file:isBoolean(a)?a:t("GET_OUTPUT_FILE"),data:isBoolean(c)?c:t("GET_OUTPUT_DATA"),success:i,failure:o};e(l.file?"REQUEST_PREPARE_OUTPUT":"PREPARE_OUTPUT",l)},REQUEST_PREPARE_OUTPUT:function(t){var r=t.file,n=t.data,i=t.success,o=t.failure;e("PREPARE_OUTPUT",{file:r,data:n,success:i,failure:o},!0),e("DID_REQUEST_PREPARE_OUTPUT")},PREPARE_OUTPUT:function(n){var i=n.file,o=n.data,a=n.success,c=void 0===a?function(){}:a,l=n.failure,u=void 0===l?function(){}:l;if(shouldAbortImageLoad(r))return e("ABORT_IMAGE");var s=function(t){if(e("DID_PREPARE_OUTPUT"),shouldAbortImageLoad(r))return e("ABORT_IMAGE");c(t)};prepareOutput({file:i,data:o},r,t).then(function(t){var n=r.options.afterCreateOutput,i=n?n(t,function(t,r){return e("DID_REQUEST_POSTPROCESS_OUTPUT",{label:t,progress:r}),function(t){e("DID_MAKE_PROGRESS",{progress:t})}}):t;Promise.resolve(i).then(s).catch(function(t){e("DID_REQUEST_POSTPROCESS_OUTPUT_ERROR",{error:t})})}).catch(function(t){if(shouldAbortImageLoad(r))return e("ABORT_IMAGE");u(t)})},EDIT_RESET:function(){clearCenterTimeout(r),reset(r,t,e)},EDIT_CONFIRM:function(){if(r.file&&r.stage){clearCenterTimeout(r),e("CROP_ZOOM");var n={file:t("GET_OUTPUT_FILE"),data:t("GET_OUTPUT_DATA"),success:function(t){r.filePromise.resolveOnConfirm&&r.filePromise.success(t),e("DID_CONFIRM",{output:t})},failure:console.error};e(n.file?"REQUEST_PREPARE_OUTPUT":"PREPARE_OUTPUT",n)}},EDIT_CANCEL:function(){r.filePromise&&r.filePromise.success(null),e("DID_CANCEL")},EDIT_CLOSE:function(){clearCenterTimeout(r)},EDIT_DESTROY:function(){resetState(r)},SET_OPTIONS:function(t){var r=t.options;forin(r,function(t,r){e("SET_".concat(fromCamels(t,"_").toUpperCase()),{value:r})})}})},createIcon=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:24;return'")},button=createView({ignoreRect:!0,ignoreRectUpdate:!0,name:"button",mixins:{styles:["opacity"],animations:{opacity:{type:"tween",duration:250}},apis:["id"],listeners:!0},tag:"button",create:function(e){var t=e.root,r=e.props;t.element.innerHTML="".concat(r.icon||"","").concat(r.label,""),t.element.setAttribute("type",r.type||"button"),r.name&&r.name.split(" ").forEach(function(e){t.element.className+=" doka--button-".concat(e)}),t.ref.handleClick=function(){"string"==typeof r.action?t.dispatch(r.action):r.action()},t.element.addEventListener("click",t.ref.handleClick),t.ref.handlePointer=function(e){return e.stopPropagation()},t.element.addEventListener("pointerdown",t.ref.handlePointer),r.create&&r.create({root:t,props:r})},destroy:function(e){var t=e.root;t.element.removeEventListener("pointerdown",t.ref.handlePointer),t.element.removeEventListener("click",t.ref.handleClick)}}),textNode=function(e){return createView({ignoreRect:!0,tag:e,create:function(e){var t=e.root,r=e.props;t.element.textContent=r.text}})},progressIndicator=createView({name:"status-progress",tag:"svg",ignoreRect:!0,ignoreRectUpdate:!0,mixins:{apis:["progress"],animations:{progress:{type:"spring",stiffness:.25,damping:.25,mass:2.5}}},create:function(e){var t=e.root,r=e.props;t.element.setAttribute("data-value",0),t.element.setAttribute("width",24),t.element.setAttribute("height",24),t.element.setAttribute("viewBox","0 0 20 20");var n=t.ref.circle=document.createElementNS("http://www.w3.org/2000/svg","circle"),i={r:5,cx:10,cy:10,fill:"none",stroke:"currentColor","stroke-width":10,transform:"rotate(-90) translate(-20)"};t.element.appendChild(n),Object.keys(i).forEach(function(e){n.setAttribute(e,i[e])}),t.ref.updateStroke=function(e){t.ref.circle.setAttribute("stroke-dasharray","".concat(31.42*Math.min(1,e)," 31.42"))},"number"==typeof r.progress?(t.progress=r.progress,t.element.setAttribute("data-value",Math.max(r.progress,.001)),t.ref.updateStroke(t.progress)):t.progress=0},write:createRoute({DID_MAKE_PROGRESS:function(e){var t=e.root,r=e.action;t.progress=r.progress,t.element.setAttribute("data-value",Math.max(r.progress,.001))}},function(e){var t=e.root;t.ref.updateStroke(t.progress)})}),statusBubbleInner=createView({name:"status-bubble-inner",create:function(e){var t=e.root,r=e.props;r.onClose?t.appendChildView(t.createChildView(button,{label:"Close",name:"icon-only status-bubble-close",icon:createIcon(''),action:r.onClose})):t.ref.progressIndicator=t.appendChildView(t.createChildView(progressIndicator,{progress:r.progress})),t.appendChildView(t.createChildView(textNode("p"),{text:r.label}))}}),statusBubble=createView({name:"status-bubble",mixins:{styles:["opacity","translateY"],apis:["markedForRemoval"],animations:{opacity:{type:"tween",duration:500},translateY:{type:"spring",mass:20}}},create:function(e){var t=e.root,r=e.props;return t.appendChildView(t.createChildView(statusBubbleInner,r))}}),hideBusyIndicators=function(e){e.element.dataset.viewStatus="idle",hideBusyIndicatorsAnimated(e)},hideBusyIndicatorsAnimated=function(e){e.ref.busyIndicators.forEach(function(e){e.translateY=-10,e.opacity=0,e.markedForRemoval=!0})},showBusyIndicator=function(e,t,r,n){e.element.dataset.viewStatus="busy";var i=addBusyIndicator(e,t,r,n);hideBusyIndicatorsAnimated(e),e.ref.busyIndicators.push(i),i.markedForRemoval=!1,i.translateY=0,i.opacity=1},addBusyIndicator=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;return e.appendChildView(e.createChildView(statusBubble,{translateY:20,opacity:0,label:t,onClose:r,progress:n}))},editStatus=createView({name:"edit-status",ignoreRect:!0,create:function(e){var t=e.root;t.ref.busyIndicators=[],t.element.setAttribute("tabindex",-1)},write:createRoute({MISSING_WEBGL:function(e){var t=e.root,r=/fullscreen/.test(t.query("GET_STYLE_LAYOUT_MODE"));showBusyIndicator(t,t.query("GET_LABEL_STATUS_MISSING_WEB_G_L"),r?function(){t.dispatch("EDIT_CANCEL")}:null)},AWAITING_IMAGE:function(e){var t=e.root;showBusyIndicator(t,t.query("GET_LABEL_STATUS_AWAITING_IMAGE"))},DID_PRESENT_IMAGE:function(e){var t=e.root;hideBusyIndicators(t)},DID_LOAD_IMAGE_ERROR:function(e){var t=e.root,r=e.action,n=/fullscreen/.test(t.query("GET_STYLE_LAYOUT_MODE")),i=t.query("GET_LABEL_STATUS_LOAD_IMAGE_ERROR"),o="function"==typeof i?i(r.error):i;showBusyIndicator(t,o,n?function(){t.dispatch("EDIT_CANCEL")}:null)},DID_REQUEST_LOAD_IMAGE:function(e){var t=e.root;showBusyIndicator(t,t.query("GET_LABEL_STATUS_LOADING_IMAGE"))},DID_REQUEST_PREPARE_OUTPUT:function(e){var t=e.root;showBusyIndicator(t,t.query("GET_LABEL_STATUS_PROCESSING_IMAGE"))},DID_REQUEST_POSTPROCESS_OUTPUT:function(e){var t=e.root,r=e.action;showBusyIndicator(t,r.label,null,r.progress)},DID_REQUEST_POSTPROCESS_OUTPUT_ERROR:function(e){var t=e.root,r=e.action.error;showBusyIndicator(t,r,function(){return t.dispatch("DID_PREPARE_OUTPUT")})},DID_PREPARE_OUTPUT:function(e){var t=e.root;hideBusyIndicators(t)}}),didWriteView:function(e){var t=e.root;t.ref.busyIndicators=t.ref.busyIndicators.filter(function(e){return!e.markedForRemoval||0!==e.opacity||(t.removeChildView(e),!1)})}}),Interaction={down:"pointerdown",move:"pointermove",up:"pointerup"},createPointerRegistry=function(){var e=[],t=function(t){return e.findIndex(function(e){return e.pointerId===t.pointerId})};return{update:function(r){var n=t(r);n<0||(e[n]=r)},multiple:function(){return e.length>1},count:function(){return e.length},active:function(){return e.concat()},push:function(r){(function(e){return t(e)>=0})(r)||e.push(r)},pop:function(r){var n=t(r);n<0||e.splice(n,1)}}},addEvent$1=function(e,t,r,n){return e.addEventListener(Interaction[t],r,n)},removeEvent$1=function(e,t,r){return e.removeEventListener(Interaction[t],r)},contains=function(e,t){if("contains"in e)return e.contains(t);var r=t;do{if(r===e)return!0}while(r=r.parentNode);return!1},createDragger=function(e,t,r,n){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{stopPropagation:!0,cancelOnMultiple:!1},o={x:0,y:0},a={enabled:!0,origin:null,cancel:!1,cancelled:!1,pointers:createPointerRegistry()},c=null,l=function(e,t){t&&(c||u(e,t),cancelAnimationFrame(c),c=requestAnimationFrame(function(){u(e,t),c=null}))},u=function(e,t){return t.apply(null,[e,function(e){return{x:e.pageX-o.x,y:e.pageY-o.y}}(e)])},s=function(r){var n=0===a.pointers.count();n&&(a.active=!1,a.cancel=!1,a.cancelled=!1),(e===r.target||contains(e,r.target))&&(n?r.isPrimary&&(a.pointers.push(r),addEvent$1(document.documentElement,"up",p),r.preventDefault(),i.stopPropagation&&(r.stopPropagation(),r.stopImmediatePropagation()),a.active=!0,o.x=r.pageX,o.y=r.pageY,addEvent$1(document.documentElement,"move",d),t(r)):i.cancelOnMultiple&&(a.cancel=!0))},d=function(e){e.isPrimary&&(a.cancelled||(e.preventDefault(),i.stopPropagation&&e.stopPropagation(),l(e,r),a.cancel&&(a.cancelled=!0,l(e,n))))},p=function e(t){a.pointers.pop(t),0===a.pointers.count()&&(removeEvent$1(document.documentElement,"move",d),removeEvent$1(document.documentElement,"up",e)),a.active&&(a.cancelled||(t.preventDefault(),i.stopPropagation&&t.stopPropagation(),l(t,r),l(t,n)))};return addEvent$1(document.documentElement,"down",s),{enable:function(){a.enabled||addEvent$1(document.documentElement,"down",s),a.enabled=!0},disable:function(){a.enabled&&removeEvent$1(document.documentElement,"down",s),a.enabled=!1},destroy:function(){removeEvent$1(document.documentElement,"up",p),removeEvent$1(document.documentElement,"move",d),removeEvent$1(document.documentElement,"down",s)}}},imageOverlaySpring={type:"spring",stiffness:.4,damping:.65,mass:7},activateMarkupUtil=function(e,t,r){if(/^(line|text|ellipse|rect)$/.test(r))e.dispatch("MARKUP_ADD_DEFAULT",{value:r}),e.dispatch("SET_MARKUP_UTIL",{value:"select"});else if("draw"===r&&!e.ref.drawInput){var n=e.ref,i=n.drawState,o=n.viewSize,a=0,c=0,l={},u=e.query("GET_MARKUP_DRAW_DISTANCE");e.ref.drawInput=createDragger(e.element,function(r){var n=e.query("GET_MARKUP_TOOL_VALUES"),u=n.lineStyle[0],s=n.lineStyle[1];i.lineColor=n.color,i.lineWidth=u,i.lineStyle=s;var d=e.query("GET_ROOT"),p=void 0!==r.offsetX?r.offsetX:r.pageX-d.x-t.stageOffsetX-window.pageXOffset,f=void 0!==r.offsetY?r.offsetY:r.pageY-d.y-t.stageOffsetY-window.pageYOffset;a=p-e.markupX,c=f-e.markupY,l.x=0,l.y=0,i.points.push({x:a/o.width,y:c/o.height})},function(t,r){if(e.dispatch("KICK"),u){var n=vectorDistance(r,l);if(n>u){var s=vectorAngleBetween(l,r)+Math.PI/2,d=u-n;l.x+=Math.sin(s)*d,l.y-=Math.cos(s)*d,i.points.push({x:(a+l.x)/o.width,y:(c+l.y)/o.height})}}else i.points.push({x:(a+r.x)/o.width,y:(c+r.y)/o.height})},function(t,r){i.points.length>1&&e.dispatch("MARKUP_ADD",["path",_objectSpread({},i)]),i.points=[]})}"draw"!==r&&e.ref.drawInput&&(e.ref.drawInput.destroy(),e.ref.drawInput=null)},getColor$1=function(e){var t=e.fontColor,r=e.backgroundColor,n=e.lineColor,i=e.borderColor;return t||r||n||i},MARKUP_MARGIN=10,setAttributes$1=function(e,t){return Object.keys(t).forEach(function(r){e.setAttribute(r,t[r])})},ns$2="http://www.w3.org/2000/svg",svg$1=function(e,t){var r=document.createElementNS(ns$2,e);return t&&setAttributes$1(r,t),r},LINE_CORNERS=["nw","se"],RECT_CORNERS=["nw","n","ne","w","e","sw","s","se"],CORNER_CURSOR={nw:"nwse",n:"ns",ne:"nesw",w:"ew",e:"ew",sw:"nesw",s:"ns",se:"nwse"},CORNER_COORDINATES={nw:function(e){return{x:e.x,y:e.y}},n:function(e){return{x:e.x+.5*e.width,y:e.y}},ne:function(e){return{x:e.x+e.width,y:e.y}},w:function(e){return{x:e.x,y:e.y+.5*e.height}},e:function(e){return{x:e.x+e.width,y:e.y+.5*e.height}},sw:function(e){return{x:e.x,y:e.y+e.height}},s:function(e){return{x:e.x+.5*e.width,y:e.y+e.height}},se:function(e){return{x:e.x+e.width,y:e.y+e.height}}},HITBOX_OFFSET=5,HITBOX_COORDINATES={nw:function(e){return{x:e.x-HITBOX_OFFSET,y:e.y-HITBOX_OFFSET}},n:function(e){return{x:e.x+.5*e.width,y:e.y-HITBOX_OFFSET}},ne:function(e){return{x:e.x+e.width+HITBOX_OFFSET,y:e.y-HITBOX_OFFSET}},w:function(e){return{x:e.x-HITBOX_OFFSET,y:e.y+.5*e.height}},e:function(e){return{x:e.x+e.width+HITBOX_OFFSET,y:e.y+.5*e.height}},sw:function(e){return{x:e.x-HITBOX_OFFSET,y:e.y+e.height+HITBOX_OFFSET}},s:function(e){return{x:e.x+.5*e.width,y:e.y+e.height+HITBOX_OFFSET}},se:function(e){return{x:e.x+e.width+HITBOX_OFFSET,y:e.y+e.height+HITBOX_OFFSET}}},imageMarkup=createView({tag:"div",name:"image-markup",ignoreRect:!0,mixins:{styles:["opacity"],animations:{opacity:"spring",markupX:imageOverlaySpring,markupY:imageOverlaySpring,markupWidth:imageOverlaySpring,markupHeight:imageOverlaySpring},listeners:!0,apis:["toolsReference","onSelect","onDrag","markupX","markupY","markupWidth","markupHeight","allowInteraction","stageOffsetX","stageOffsetY"]},create:function(e){var t=e.root,r=e.props,n=r.onSelect,i=void 0===n?function(){}:n,o=r.onUpdate,a=void 0===o?function(){}:o,c=svg$1("svg",{xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink"});t.ref.canvas=c;var l=t.query("GET_ROOT_SIZE");c.setAttribute("width",l.width),c.setAttribute("height",l.height);var u=document.createElement("input");setAttributes$1(u,{type:"text",autocomplete:"off",autocapitalize:"off"}),u.addEventListener("keydown",function(e){e.stopPropagation(),13===e.keyCode||9===e.keyCode?(e.target.blur(),d()):8!==e.keyCode||t.ref.input.value.length||t.dispatch("MARKUP_DELETE",{id:t.ref.selected.id})}),t.ref.input=u,t.ref.elements=[],t.ref.viewSize={width:0,height:0,scale:0},t.ref.resetSelected=function(){return t.ref.selected={id:null,type:null,settings:{}},t.ref.selected},t.ref.resetSelected();var s=function(e){return e.id?e:e.parentNode},d=function(){t.ref.resetSelected(),i(null)};t.ref.handleDeselect=function(e){var n;(t.query("IS_ACTIVE_VIEW","markup")||t.query("IS_ACTIVE_VIEW","sticker"))&&(t.ref.selected.id&&e.target!==t.ref.removeButton.element&&(n=e.target,t.ref.selected.id!==s(n).id&&(function(e){return contains(t.ref.manipulatorGroup,e)||e===t.ref.input}(e.target)||r.isMarkupUtil(e.target)||d())))},addEvent$1(document.body,"down",t.ref.handleDeselect),t.ref.handleTextInput=function(){return a("text",t.ref.input.value)},t.ref.input.addEventListener("input",t.ref.handleTextInput),t.ref.handleAttemptDelete=function(e){(t.query("IS_ACTIVE_VIEW","markup")||t.query("IS_ACTIVE_VIEW","sticker"))&&(!t.ref.selected.id||8!==e.keyCode&&46!==e.keyCode||(e.stopPropagation(),e.preventDefault(),t.dispatch("MARKUP_DELETE",{id:t.ref.selected.id})))},document.body.addEventListener("keydown",t.ref.handleAttemptDelete);var p=svg$1("g"),f=svg$1("g",{class:"doka--shape-group"});p.appendChild(f),t.ref.shapeGroup=f;var h=svg$1("g",{fill:"none",class:"doka--manipulator-group"}),g=svg$1("rect",{x:0,y:0,width:0,height:0,fill:"none"}),m=svg$1("path");h.appendChild(m),h.appendChild(g),t.ref.manipulatorPath=m,t.ref.manipulatorRect=g,t.ref.manipulators=[];for(var v=0;v<10;v++){var y=svg$1("circle",{r:6,"stroke-width":2}),E=svg$1("circle",{r:22,class:"doka--hitbox",style:"opacity: 0"});h.appendChild(E),h.appendChild(y),t.ref.manipulators.push({visual:y,hitbox:E,dragger:null})}p.appendChild(h),t.ref.manipulatorGroup=h,c.appendChild(p),t.ref.shapeOffsetGroup=p,t.ref.removeButton=t.appendChildView(t.createChildView(button,{label:t.query("GET_LABEL_MARKUP_REMOVE_SHAPE"),name:"destroy-shape",action:function(){t.dispatch("MARKUP_DELETE",{id:t.ref.selected.id})}})),(t.query("IS_ACTIVE_VIEW","markup")||t.query("IS_ACTIVE_VIEW","sticker"))&&(t.element.dataset.active=!0),t.ref.drawInput=null,t.ref.drawState={lineColor:null,lineWidth:null,lineStyle:null,points:[]};var T=svg$1("path",{fill:"none",class:"doka--draw-path"});t.ref.drawPath=T,c.appendChild(T);var _=createElement("div","doka--image-markup-clip");_.appendChild(u),_.appendChild(c),t.ref.clip=_,t.element.appendChild(_),"draw"===t.query("GET_MARKUP_UTIL")&&activateMarkupUtil(t,r,"draw")},destroy:function(e){var t=e.root;t.ref.elements.concat(t.ref.manipulators).forEach(function(e){e.dragger&&e.dragger.destroy()}),t.ref.input.removeEventListener("input",t.ref.handleTextInput),document.body.removeEventListener("keydown",t.ref.handleAttemptDelete),removeEvent$1(document.body,"down",t.ref.handleDeselect)},read:function(e){var t=e.root;if(!t.rect.element.hidden)for(var r in t.ref.elements){var n=t.ref.elements[r];if(n&&"text"===n.nodeName&&n.parentNode){var i=n.getBBox();n.bbox={x:i.x,y:i.y,width:i.width,height:i.height}}}},write:createRoute({SHOW_VIEW:function(e){var t=e.root,r=e.props,n=e.action;"markup"===n.id||"sticker"===n.id?t.element.dataset.active=!0:(t.element.dataset.active=!1,r.onSelect(null))},MARKUP_SET_VALUE:function(e){var t=e.root;forin(t.ref.elements,function(e,t){t&&t.dragger&&t.dragger.destroy()}),t.ref.elements=[],t.ref.shapeGroup.innerHTML=""},UPDATE_ROOT_RECT:function(e){var t=e.root,r=e.action,n=t.ref.canvas;n.setAttribute("width",r.rect.width),n.setAttribute("height",r.rect.height),t.ref.previousScale=null},SWITCH_MARKUP_UTIL:function(e){var t=e.root,r=e.action,n=e.props,i=r.util;activateMarkupUtil(t,n,i)}},function(e){var t=e.root,r=e.props,n=e.timestamp;if(!(t.opacity<=0)){var i=t.query("GET_CROP",r.id,n);if(i){var o=t.query("GET_MARKUP_UTIL");t.element.dataset.util=o||"";var a=i.markup,c=i.cropStatus,l=r.onSelect,u=r.onDrag,s=t.ref,d=s.clip,p=s.manipulatorGroup,f=s.drawPath,h=s.viewSize,g=s.shapeOffsetGroup,m=s.manipulators,v=s.manipulatorPath,y=s.manipulatorRect,E=s.removeButton,T=s.drawState,_=t.query("GET_OUTPUT_WIDTH"),R=t.query("GET_OUTPUT_HEIGHT"),w=c.image,A=c.crop,I=A.width,S=A.height,C=A.widthFloat/A.heightFloat;if(_||R){var O=t.query("GET_OUTPUT_FIT");_&&!R&&(R=_),R&&!_&&(_=R);var x,b=_/I,M=R/S;if("force"===O)I=_,S=R;else"cover"===O?x=Math.max(b,M):"contain"===O&&(x=Math.min(b,M)),I*=x,S*=x}else w.width&&w.height?(I=w.width,S=w.height):w.width&&!w.height?(I=w.width,S=w.width/C):w.height&&!w.width&&(S=w.height,I=w.height*C);var L=T.points.length,P=roundFloat(t.markupX,3),G=roundFloat(t.markupY,3),k=roundFloat(t.markupWidth,3),D=roundFloat(t.markupHeight,3),U=roundFloat(Math.min(t.markupWidth/I,t.markupHeight/S),4);if(h.width=k,h.height=D,h.scale=U,stateHasChanged(t,{drawLength:L,markupX:P,markupY:G,scale:U,markup:a,currentWidth:I,currentHeight:S})){var B=P,V=t.rect.element.width-P-k,N=G,F=t.rect.element.height-G-D,z="inset(".concat(N,"px ").concat(V,"px ").concat(F,"px ").concat(B,"px)");if(d.style.clipPath=z,d.style.webkitClipPath=z,g.setAttribute("transform","translate(".concat(P," ").concat(G,")")),t.ref.previousDrawLength=L,t.ref.previousX=P,t.ref.previousY=G,t.ref.previousScale=U,t.ref.previousCurrentHeight=S,t.ref.previousCurrentWidth=I,t.ref.previousMarkupLength=a.length,!(h.width<1||h.height<1)){var W,q=a.find(function(e){return e[1].isSelected}),H=q&&t.ref.selected.id!==q[1].id||t.ref.selected.id&&!q;if(W=q?t.ref.selected={id:q[1].id,type:q[0],settings:q[1]}:t.ref.resetSelected(),T.points.length){var Y=getMarkupStyles(T,h,U);return Y.d=pointsToPathShape(T.points.map(function(e){return{x:P+e.x*h.width,y:G+e.y*h.height}})),void setAttributes$1(f,Y)}f.removeAttribute("d"),t.ref.input.hidden="text"!==t.ref.selected.type||!t.ref.selected.settings.allowInput,E.element.dataset.active=null!==t.ref.selected.id,v.setAttribute("style","opacity:0"),y.setAttribute("style","opacity:0"),m.forEach(function(e){e.visual.setAttribute("style","opacity:0; pointer-events:none;"),e.hitbox.setAttribute("style","pointer-events:none;")});var j=t.query("GET_MARKUP_FILTER");a.filter(j).sort(sortMarkupByZIndex).forEach(function(e,n){var i=_slicedToArray(e,2),o=i[0],a=i[1],c=a.id,s=a.isDestroyed,d=a.isDirty,f=a.isSelected,g=a.allowSelect,T=a.allowMove,_=a.allowResize,R=a.allowInput;if(s){var w=t.ref.elements[c];w&&(w.dragger&&w.dragger.destroy(),t.ref.elements[c]=null,w.parentNode.removeChild(w))}else{var A,I,S,C=t.ref.elements[c];if(!C)if(C=createMarkupByType(o,a),t.ref.elements[c]=C,g)C.dragger=createDragger(C,function(){I=Date.now(),A=_objectSpread({},C.rect),(S=c===t.ref.selected.id)||l(c)},function(e,t){T&&u(c,A,t,h,U)},function(e,r){if(R&&"text"===o&&S){var n=vectorDistanceSquared({x:0,y:0},r),i=Date.now()-I;if(!(n>10||i>750)){t.ref.input.focus();var a=t.markupX+C.bbox.x,c=C.bbox.width,l=(e.offsetX-a)/c,u=Math.round(t.ref.input.value.length*l);t.ref.input.setSelectionRange(u,u)}}}),C.dragger.disable();else C.setAttribute("style","pointer-events:none;");if(C.dragger&&(r.allowInteraction?C.dragger.enable():C.dragger.disable()),n!==C.index){C.index=n;var O=t.ref.shapeGroup;O.insertBefore(C,O.childNodes[n+1])}if(d&&updateMarkupByType(C,o,a,h,U),f){var x=E.rect.element.width,b=E.rect.element.height,M=t.markupX-.5*x,L=t.markupY-b-15,P="text"===o?C.bbox:C.rect,G=!1,k=getColor$1(a);if(k){var D=toRGBColorArray(k);G=(.2126*D[0]+.7152*D[1]+.0722*D[2])/255>.65,p.setAttribute("is-bright-color",G)}"line"===o?(M+=P.x,L+=P.y,setAttributes$1(v,{d:"M ".concat(P.x," ").concat(P.y," L ").concat(P.x+P.width," ").concat(P.y+P.height),style:"opacity:1"})):"path"===o?(M+=(P={x:a.points[0].x*h.width,y:a.points[0].y*h.height,width:0,height:0}).x,L+=P.y,setAttributes$1(v,{d:pointsToPathShape(a.points.map(function(e){return{x:e.x*h.width,y:e.y*h.height}})),style:"opacity:1"})):P&&(M+=P.x+.5*P.width,L+=P.y,setAttributes$1(y,{x:P.x-("text"===o?5:0),y:P.y,width:P.width+("text"===o?10:0),height:P.height,style:"opacity:1"}));var B=t.markupY+MARKUP_MARGIN,V=t.markupY+t.markupHeight-MARKUP_MARGIN,N=t.markupX+MARKUP_MARGIN,F=t.markupX+t.markupWidth-MARKUP_MARGIN;if(LV&&(L=V-b),MF&&(M=F-x),P||(E.element.dataset.active="false"),E.element.setAttribute("style","transform: translate3d(".concat(M,"px, ").concat(L,"px, 0)")),"text"===o&&P&&R){var z=P.width+65,W=t.markupWidth-P.x,q="\n width: ".concat(Math.min(z,W),"px;\n height: ").concat(P.height,"px;\n color: ").concat(C.getAttribute("fill"),";\n font-family: ").concat(C.getAttribute("font-family"),";\n font-size: ").concat(C.getAttribute("font-size").replace(/px/,""),"px;\n font-weight: ").concat(C.getAttribute("font-weight")||"normal",";\n ");isIOS()?q+="\n left: ".concat(Math.round(t.markupX+P.x),"px;\n top: ").concat(Math.round(t.markupY+P.y),"px;\n "):q+="\n transform: translate3d(".concat(Math.round(t.markupX+P.x),"px,").concat(Math.round(t.markupY+P.y),"px,0);\n "),t.ref.input.setAttribute("style",q),C.setAttribute("fill","none")}if("text"===o)return;if(!_)return;var H="line"===o?LINE_CORNERS:RECT_CORNERS;m.forEach(function(e,t){var r=H[t];if(r){var n="line"===o?"move":"".concat(CORNER_CURSOR[r],"-resize"),i=CORNER_COORDINATES[r](C.rect),a=C.rect.width<100||C.rect.height<100,c=2===r.length?1:a?0:1;setAttributes$1(e.visual,{cx:i.x,cy:i.y,style:"opacity:".concat(c)});var l=HITBOX_COORDINATES[r](C.rect);setAttributes$1(e.hitbox,{cx:l.x,cy:l.y,style:"cursor:".concat(n,";")})}})}a.isDirty=!1}}),H&&(destroyElementControls(t),"text"===W.type&&t.ref.selected.settings.allowInput?t.ref.input.value=W.settings.text:t.ref.selected.id&&setupElementControls(t,r.onResize))}}}}})}),markAllAsDirty=function(e){return e.forEach(function(e){return e[1].isDirty=!0})},stateHasChanged=function(e,t){var r=t.drawLength,n=t.markup,i=t.markupX,o=t.markupY,a=t.currentWidth,c=t.currentHeight,l=t.scale;return r!==e.ref.previousDrawLength||(i!==e.ref.previousX?(markAllAsDirty(n),!0):o!==e.ref.previousY?(markAllAsDirty(n),!0):l!==e.ref.previousScale?(markAllAsDirty(n),!0):c!==e.ref.previousCurrentHeight?(markAllAsDirty(n),!0):a!==e.ref.previousCurrentWidth?(markAllAsDirty(n),!0):n.length!==e.ref.previousMarkupLength||!!n.find(function(e){return e[1].isDirty}))},setupElementControls=function(e,t){var r=e.ref.selected.id,n="g"===e.ref.elements[r].nodeName?LINE_CORNERS:RECT_CORNERS;e.ref.manipulators.forEach(function(i,o){var a=n[o];if(a){var c=null;i.dragger=createDragger(i.hitbox,function(){c={x:parseFloat(attr(i.hitbox,"cx")),y:parseFloat(attr(i.hitbox,"cy"))}},function(n,i){t(r,a,c,i,e.ref.viewSize)},null,{stopPropagation:!0})}})},destroyElementControls=function(e){e.ref.manipulators.forEach(function(e){e.dragger&&(e.dragger.destroy(),e.dragger=null)})},KEY_MAP={38:"up",40:"down",37:"left",39:"right",189:"minus",187:"plus",72:"h",76:"l",81:"q",82:"r",84:"t",86:"v",90:"z",219:"left_bracket",221:"right_bracket"},createKeyboard=function(e,t,r,n,i){var o=null,a=!0,c={enabled:!0},l=function(e){var i=KEY_MAP[e.keyCode]||e.keyCode;r[i]&&(e.stopPropagation(),a&&(o=t(i),a=!1),r[i](o),n(o))},u=function(e){var t=KEY_MAP[e.keyCode]||e.keyCode;r[t]&&(e.stopPropagation(),i(o),a=!0)};return e.addEventListener("keydown",l),e.addEventListener("keyup",u),{enable:function(){c.enabled||(e.addEventListener("keydown",l),e.addEventListener("keyup",u)),c.enabled=!0},disable:function(){c.enabled&&(e.removeEventListener("keydown",l),e.removeEventListener("keyup",u)),c.enabled=!1},destroy:function(){e.removeEventListener("keydown",l),e.removeEventListener("keyup",u)}}},createPreviewImage=function(e,t,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,i=arguments.length>4?arguments[4]:void 0;t=Math.round(t),r=Math.round(r);var o=i||document.createElement("canvas"),a=o.getContext("2d");return n>=5&&n<=8?(o.width=r,o.height=t):(o.width=t,o.height=r),a.save(),-1!==n&&a.transform.apply(a,getImageOrientationMatrix(t,r,n)),a.drawImage(e,0,0,t,r),a.restore(),o},BitmapWorker=function(){self.onmessage=function(e){createImageBitmap(e.data.message.file).then(function(t){self.postMessage({id:e.data.id,message:t},[t])})}},isBitmap=function(e){return/^image/.test(e.type)&&!/svg/.test(e.type)},canCreateImageBitmap=function(e){var t=window.navigator.userAgent.match(/Firefox\/([0-9]+)\./);return!((t?parseInt(t[1]):null)<=58)&&("createImageBitmap"in window&&isBitmap(e))},loadImage$2=function(e){return new Promise(function(t,r){var n=new Image;n.onload=function(){t(n)},n.onerror=function(e){r(e)},n.src=e})},compileShader=function(e,t,r){var n=e.createShader(r);return e.shaderSource(n,t),e.compileShader(n),n},createProgram=function(e,t,r){var n=e.createProgram();return e.attachShader(n,compileShader(e,t,e.VERTEX_SHADER)),e.attachShader(n,compileShader(e,r,e.FRAGMENT_SHADER)),e.linkProgram(n),n},createTexture=function(e,t,r,n,i){var o=e.createTexture();e.activeTexture(e.TEXTURE0+n),e.bindTexture(e.TEXTURE_2D,o),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.uniform1i(t,n),e.uniform2f(r,i.width,i.height);try{e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,i)}catch(t){e.texImage2D(e.TEXTURE_2D,0,e.RGBA,i.width,i.height,0,e.RGBA,e.UNSIGNED_BYTE,null)}return o},create=function(){var e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e},perspective=function(e,t,r,n,i){var o=1/Math.tan(t/2),a=1/(n-i);e[0]=o/r,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=o,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=-1,e[12]=0,e[13]=0,e[15]=0,e[10]=(i+n)*a,e[14]=2*i*n*a},translate=function(e,t){var r=t[0],n=t[1],i=t[2];e[12]=e[0]*r+e[4]*n+e[8]*i+e[12],e[13]=e[1]*r+e[5]*n+e[9]*i+e[13],e[14]=e[2]*r+e[6]*n+e[10]*i+e[14],e[15]=e[3]*r+e[7]*n+e[11]*i+e[15]},scale=function(e,t){var r=t[0],n=t[1],i=t[2];e[0]=e[0]*r,e[1]=e[1]*r,e[2]=e[2]*r,e[3]=e[3]*r,e[4]=e[4]*n,e[5]=e[5]*n,e[6]=e[6]*n,e[7]=e[7]*n,e[8]=e[8]*i,e[9]=e[9]*i,e[10]=e[10]*i,e[11]=e[11]*i},rotateX=function(e,t){var r=Math.sin(t),n=Math.cos(t),i=e[4],o=e[5],a=e[6],c=e[7],l=e[8],u=e[9],s=e[10],d=e[11];e[4]=i*n+l*r,e[5]=o*n+u*r,e[6]=a*n+s*r,e[7]=c*n+d*r,e[8]=l*n-i*r,e[9]=u*n-o*r,e[10]=s*n-a*r,e[11]=d*n-c*r},rotateY=function(e,t){var r=Math.sin(t),n=Math.cos(t),i=e[0],o=e[1],a=e[2],c=e[3],l=e[8],u=e[9],s=e[10],d=e[11];e[0]=i*n-l*r,e[1]=o*n-u*r,e[2]=a*n-s*r,e[3]=c*n-d*r,e[8]=i*r+l*n,e[9]=o*r+u*n,e[10]=a*r+s*n,e[11]=c*r+d*n},rotateZ=function(e,t){var r=Math.sin(t),n=Math.cos(t),i=e[0],o=e[1],a=e[2],c=e[3],l=e[4],u=e[5],s=e[6],d=e[7];e[0]=i*n+l*r,e[1]=o*n+u*r,e[2]=a*n+s*r,e[3]=c*n+d*r,e[4]=l*n-i*r,e[5]=u*n-o*r,e[6]=s*n-a*r,e[7]=d*n-c*r},mat4={create:create,perspective:perspective,translate:translate,scale:scale,rotateX:rotateX,rotateY:rotateY,rotateZ:rotateZ},degToRad=function(e){return e*Math.PI/180},imageFragmentShader="\nprecision mediump float;\n\nuniform sampler2D uTexture;\nuniform vec2 uTextureSize;\n\nuniform float uColorOpacity;\nuniform mat4 uColorMatrix;\nuniform vec4 uColorOffset;\n\nuniform vec4 uOverlayColor;\nuniform vec2 uOverlayLeftTop;\nuniform vec2 uOverlayRightBottom;\n\nvarying vec2 vTexCoord;\nvarying vec4 vPosition;\n\nvoid main () {\n\n vec3 cB = vec3(1.0);\n\n\tvec4 cF = texture2D(uTexture, vTexCoord);\n\t\n\tvec4 cM = (cF * uColorMatrix) + uColorOffset;\n\n float r = max(0.0, cM.r * cM.a) + (cB.r * (1.0 - cM.a));\n float g = max(0.0, cM.g * cM.a) + (cB.g * (1.0 - cM.a));\n float b = max(0.0, cM.b * cM.a) + (cB.b * (1.0 - cM.a));\n\n\tvec4 color = vec4(r, g, b, cF.a);\n\t\n\t// test if falls within\n if ((gl_FragCoord.x < uOverlayLeftTop.x || gl_FragCoord.x > uOverlayRightBottom.x) || \n (gl_FragCoord.y > uOverlayLeftTop.y || gl_FragCoord.y < uOverlayRightBottom.y)) {\n\t\tcolor *= uOverlayColor;\n\t}\n\t\n gl_FragColor = color * uColorOpacity;\n}\n",imageVertexShader="\nattribute vec4 aPosition;\nattribute vec2 aTexCoord;\nuniform mat4 uMatrix;\n\n// send to fragment shader\nvarying vec2 vTexCoord;\nvarying vec4 vPosition;\n\nvoid main () {\n vPosition = uMatrix * aPosition;\n gl_Position = vPosition;\n vTexCoord = aTexCoord;\n}\n",backgroundFragmentShader="\nprecision mediump float;\n\nuniform vec2 uViewportSize;\nuniform vec3 uColorStart;\nuniform vec3 uColorEnd;\nuniform vec2 uOverlayLeftTop;\nuniform vec2 uOverlayRightBottom;\nuniform vec4 uColorCanvasBackground;\n\nvoid main() {\n\n\tfloat x = gl_FragCoord.x;\n\tfloat y = gl_FragCoord.y;\n\n\tvec2 center = vec2(.5, .5);\n\tvec2 st = vec2(x / uViewportSize.x, y / uViewportSize.y);\n\tfloat mixValue = distance(st, center) * 1.5; // expand outside view (same as doka--root::after)\n\tvec3 color = mix(uColorStart, uColorEnd, mixValue);\n\n\tif (uColorCanvasBackground[3] == 1.0) {\n\n\t\tfloat innerLeft = uOverlayLeftTop.x;\n\t\tfloat innerRight = uOverlayRightBottom.x;\n\t\tfloat innerTop = uOverlayRightBottom.y;\n\t\tfloat innerBottom = uOverlayLeftTop.y;\n\n\t\tif (x < innerLeft || x > innerRight || y < innerTop || y > innerBottom) {\n\t\t\tgl_FragColor = vec4(color, 1.0);\n\t\t\treturn;\n\t\t}\n\n\t\tgl_FragColor = uColorCanvasBackground;\n\t\treturn;\n\t}\n\t\n\tgl_FragColor = vec4(color, 1.0);\n}\n",outlineFragmentShader="\nprecision mediump float;\n\nuniform vec2 uOverlayLeftTop;\nuniform vec2 uOverlayRightBottom;\nuniform vec4 uOutlineColor;\nuniform float uOutlineWidth;\n\nvoid main() {\n\n\tfloat x = gl_FragCoord.x;\n\tfloat y = gl_FragCoord.y;\n\n\tfloat innerLeft = uOverlayLeftTop.x;\n\tfloat innerRight = uOverlayRightBottom.x;\n\tfloat innerTop = uOverlayRightBottom.y;\n\tfloat innerBottom = uOverlayLeftTop.y;\n\n\tfloat outerLeft = innerLeft - uOutlineWidth;\n\tfloat outerRight = innerRight + uOutlineWidth;\n\tfloat outerTop = innerTop - uOutlineWidth;\n\tfloat outerBottom = innerBottom + uOutlineWidth;\n\t\n\tif (x < outerLeft || x >= outerRight || y < outerTop || y >= outerBottom) {\n\t\tdiscard;\n\t}\n\n\tif (x < innerLeft || x >= innerRight || y < innerTop || y >= innerBottom) {\n\t\tgl_FragColor = uOutlineColor;\n\t}\n}\n",simpleVertexShader="\nattribute vec4 aPosition;\nvoid main() {\n\tgl_Position = aPosition;\n}\n",setup=function(e,t,r){var n={width:0,height:0},i={x:0,y:0},o=null,a=degToRad(30),c=Math.tan(a/2),l={antialias:!1,alpha:!1},u=e.getContext("webgl",l)||e.getContext("experimental-webgl",l);if(!u)return null;u.enable(u.BLEND),u.blendFunc(u.SRC_ALPHA,u.ONE_MINUS_SRC_ALPHA);var s=createProgram(u,simpleVertexShader,backgroundFragmentShader),d=u.getUniformLocation(s,"uColorStart"),p=u.getUniformLocation(s,"uColorEnd"),f=u.getUniformLocation(s,"uViewportSize"),h=u.getAttribLocation(s,"aPosition"),g=u.getUniformLocation(s,"uOverlayLeftTop"),m=u.getUniformLocation(s,"uOverlayRightBottom"),v=u.getUniformLocation(s,"uColorCanvasBackground"),y=u.createBuffer(),E=new Float32Array([1,-1,1,1,-1,-1,-1,1]);u.bindBuffer(u.ARRAY_BUFFER,y),u.bufferData(u.ARRAY_BUFFER,E,u.STATIC_DRAW),u.bindBuffer(u.ARRAY_BUFFER,null);var T=createProgram(u,simpleVertexShader,outlineFragmentShader),_=u.getAttribLocation(T,"aPosition"),R=u.getUniformLocation(T,"uOutlineWidth"),w=u.getUniformLocation(T,"uOutlineColor"),A=u.getUniformLocation(T,"uOverlayLeftTop"),I=u.getUniformLocation(T,"uOverlayRightBottom"),S=u.createBuffer(),C=new Float32Array([1,-1,1,1,-1,-1,-1,1]);u.bindBuffer(u.ARRAY_BUFFER,S),u.bufferData(u.ARRAY_BUFFER,C,u.STATIC_DRAW),u.bindBuffer(u.ARRAY_BUFFER,null);var O=createProgram(u,imageVertexShader,imageFragmentShader);u.useProgram(O);var x=u.getUniformLocation(O,"uMatrix"),b=u.getUniformLocation(O,"uTexture"),M=u.getUniformLocation(O,"uTextureSize"),L=u.getUniformLocation(O,"uOverlayColor"),P=u.getUniformLocation(O,"uOverlayLeftTop"),G=u.getUniformLocation(O,"uOverlayRightBottom"),k=u.getUniformLocation(O,"uColorOpacity"),D=u.getUniformLocation(O,"uColorOffset"),U=u.getUniformLocation(O,"uColorMatrix"),B=u.getAttribLocation(O,"aPosition"),V=u.getAttribLocation(O,"aTexCoord"),N=createTexture(u,b,M,0,t),F=t.width*r,z=t.height*r,W=-.5*F,q=.5*z,H=.5*F,Y=-.5*z,j=new Float32Array([W,q,W,Y,H,q,H,Y]),X=new Float32Array([0,0,0,1,1,0,1,1]),Z=j.length/2,$=u.createBuffer();u.bindBuffer(u.ARRAY_BUFFER,$),u.bufferData(u.ARRAY_BUFFER,j,u.STATIC_DRAW),u.bindBuffer(u.ARRAY_BUFFER,null);var K=u.createBuffer();u.bindBuffer(u.ARRAY_BUFFER,K),u.bufferData(u.ARRAY_BUFFER,X,u.STATIC_DRAW),u.bindBuffer(u.ARRAY_BUFFER,null);var Q=0,J=0,ee={release:function(){e.width=1,e.height=1},resize:function(t,a){e.width=t*r,e.height=a*r,e.style.width="".concat(t,"px"),e.style.height="".concat(a,"px"),n.width=t*r,n.height=a*r,i.x=.5*n.width,i.y=.5*n.height,o=n.width/n.height,u.viewport(0,0,u.canvas.width,u.canvas.height)},update:function(e,l,E,C,b,M,F,z,W,q,H,Y,j,X,te,re,ne,ie,oe){var ae=H?H.height*r:n.height;Q=t.width*r,J=t.height*r,e*=r,l*=r,E*=r,C*=r;var ce=J/2/c*(n.height/ae)*-1;ce/=-c*ce*2/n.height;var le=.5*Q,ue=.5*J;e-=le,l-=ue;var se=z,de=-(i.x-le)+E,pe=i.y-ue-C,fe=mat4.create();mat4.perspective(fe,a,o,1,2*-ce),mat4.translate(fe,[de,pe,ce]),mat4.translate(fe,[e,-l,0]),mat4.scale(fe,[se,se,se]),mat4.rotateZ(fe,-F),mat4.translate(fe,[-e,l,0]),mat4.rotateY(fe,M),mat4.rotateX(fe,b),u.clearColor(X[0],X[1],X[2],1),u.clear(u.COLOR_BUFFER_BIT);var he=Y.x*r,ge=Y.y*r,me=Y.width*r,ve=Y.height*r,ye=he,Ee=ye+me,Te=n.height-ge,_e=n.height-(ge+ve);u.useProgram(s),u.uniform3fv(d,te),u.uniform3fv(p,re),u.uniform4fv(v,oe.map(function(e,t){return t<3?e/255:e})),u.uniform2f(f,n.width,n.height),u.uniform2f(g,ye,Te),u.uniform2f(m,Ee,_e),u.bindBuffer(u.ARRAY_BUFFER,y),u.vertexAttribPointer(h,2,u.FLOAT,!1,0,0),u.enableVertexAttribArray(h),u.drawArrays(u.TRIANGLE_STRIP,0,4),u.useProgram(O),u.bindFramebuffer(u.FRAMEBUFFER,null),u.bindTexture(u.TEXTURE_2D,N),u.bindBuffer(u.ARRAY_BUFFER,$),u.vertexAttribPointer(B,2,u.FLOAT,!1,0,0),u.enableVertexAttribArray(B),u.bindBuffer(u.ARRAY_BUFFER,K),u.vertexAttribPointer(V,2,u.FLOAT,!1,0,0),u.enableVertexAttribArray(V),u.uniformMatrix4fv(x,!1,fe),u.uniform2f(P,ye,Te),u.uniform2f(G,Ee,_e),u.uniform4fv(L,j),u.uniform1f(k,q),u.uniform4f(D,W[4],W[9],W[14],W[19]),u.uniformMatrix4fv(U,!1,[].concat(_toConsumableArray(W.slice(0,4)),_toConsumableArray(W.slice(5,9)),_toConsumableArray(W.slice(10,14)),_toConsumableArray(W.slice(15,19)))),u.drawArrays(u.TRIANGLE_STRIP,0,Z),u.useProgram(T),u.uniform1f(R,ne),u.uniform4fv(w,ie),u.uniform2f(A,ye,Te),u.uniform2f(I,Ee,_e),u.bindBuffer(u.ARRAY_BUFFER,S),u.vertexAttribPointer(_,2,u.FLOAT,!1,0,0),u.enableVertexAttribArray(_),u.drawArrays(u.TRIANGLE_STRIP,0,4),ee.onupdate(u)},onupdate:function(){}};return ee},createSpringRect=function(e){var t=0,r={},n=spring(e),i=spring(e),o=spring(e),a=spring(e);return n.onupdate=function(e){return r.x=e},n.oncomplete=function(){return t++},i.onupdate=function(e){return r.y=e},i.oncomplete=function(){return t++},o.onupdate=function(e){return r.width=e},o.oncomplete=function(){return t++},a.onupdate=function(e){return r.height=e},a.oncomplete=function(){return t++},{interpolate:function(e){n.interpolate(e),i.interpolate(e),o.interpolate(e),a.interpolate(e)},setTarget:function(e){t=0,n.target=e?e.x:null,i.target=e?e.y:null,o.target=e?e.width:null,a.target=e?e.height:null},getRect:function(){return r},isStable:function(){return 4===t}}},createSpringColor=function(e){var t=0,r={},n=spring(e),i=spring(e),o=spring(e);return n.onupdate=function(e){return r.r=e},n.oncomplete=function(){return t++},i.onupdate=function(e){return r.g=e},i.oncomplete=function(){return t++},o.onupdate=function(e){return r.b=e},o.oncomplete=function(){return t++},{interpolate:function(e){n.interpolate(e),i.interpolate(e),o.interpolate(e)},setTarget:function(e){t=0,n.target=e?e[0]:null,i.target=e?e[1]:null,o.target=e?e[2]:null},getColor:function(){return[r.r,r.g,r.b]},isStable:function(){return 3===t}}},ColorSpring={stiffness:.25,damping:.25,mass:2.5},IdentityMatrix=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],imageGL=createView({name:"image-gl",ignoreRect:!0,ignoreRectUpdate:!0,mixins:{apis:["top","left","width","height","xOrigin","yOrigin","xTranslation","yTranslation","xRotation","yRotation","zRotation","scale","overlay","stage","colorMatrix","colorOpacity","overlayOpacity","outlineWidth","isDraft"],animations:{xTranslation:imageOverlaySpring,yTranslation:imageOverlaySpring,xOrigin:imageOverlaySpring,yOrigin:imageOverlaySpring,scale:imageOverlaySpring,xRotation:{type:"spring",stiffness:.25,damping:.25,mass:2.5},yRotation:{type:"spring",stiffness:.25,damping:.25,mass:2.5},zRotation:{type:"spring",stiffness:.25,damping:.25,mass:2.5},colorOpacity:{type:"tween",delay:150,duration:750},overlayOpacity:"spring",introScale:{type:"spring",stiffness:.25,damping:.75,mass:15},outlineWidth:imageOverlaySpring}},create:function(e){var t=e.root;t.ref.canvas=document.createElement("canvas"),t.ref.canvas.width=0,t.ref.canvas.height=0,t.appendChild(t.ref.canvas),t.ref.gl=null,t.introScale=1,t.ref.isPreview="preview"===t.query("GET_STYLE_LAYOUT_MODE"),t.ref.shouldZoom=!t.ref.isPreview,t.ref.didZoom=!1,t.ref.backgroundColor=null,t.ref.backgroundColorSpring=createSpringColor(ColorSpring),t.ref.backgroundColorCenter=null,t.ref.backgroundColorCenterSpring=createSpringColor(ColorSpring),t.ref.overlaySpring=createSpringRect(imageOverlaySpring),t.ref.stageSpring=createSpringRect(imageOverlaySpring),t.ref.outlineSpring=spring(imageOverlaySpring),t.ref.colorMatrixSpring=[],t.ref.colorMatrixStable=!0,t.ref.colorMatrixStableCount=0,t.ref.colorMatrixPositions=[];for(var r=0;r<20;r++)!function(){var e=r,n=spring(ColorSpring);n.target=IdentityMatrix[e],n.onupdate=function(r){t.ref.colorMatrixPositions[e]=r},n.oncomplete=function(){t.ref.colorMatrixStableCount++},t.ref.colorMatrixSpring[e]=n}();t.ref.dragger=createDragger(t.element,function(){t.dispatch("CROP_IMAGE_DRAG_GRAB")},function(e,r){t.dispatch("CROP_IMAGE_DRAG",{value:r})},function(){t.dispatch("CROP_IMAGE_DRAG_RELEASE")},{cancelOnMultiple:!0});var n=0,i=0;t.ref.keyboard=createKeyboard(t.element,function(){return n=0,i=0,{x:0,y:0}},{up:function(e){e.y-=20},down:function(e){e.y+=20},left:function(e){e.x-=20},right:function(e){e.x+=20},plus:function(){n+=.1,t.dispatch("CROP_IMAGE_RESIZE_AMOUNT",{value:n}),t.dispatch("CROP_IMAGE_RESIZE_RELEASE")},minus:function(){n-=.1,t.dispatch("CROP_IMAGE_RESIZE_AMOUNT",{value:n}),t.dispatch("CROP_IMAGE_RESIZE_RELEASE")},left_bracket:function(){i-=Math.PI/128,t.dispatch("CROP_IMAGE_ROTATE_ADJUST",{value:i})},right_bracket:function(){i+=Math.PI/128,t.dispatch("CROP_IMAGE_ROTATE_ADJUST",{value:i})},h:function(){t.dispatch("CROP_IMAGE_FLIP_HORIZONTAL")},l:function(){t.dispatch("CROP_IMAGE_ROTATE_LEFT")},q:function(){t.dispatch("CROP_RESET")},r:function(){t.dispatch("CROP_IMAGE_ROTATE_RIGHT")},v:function(){t.dispatch("CROP_IMAGE_FLIP_VERTICAL")},z:function(){t.dispatch("CROP_ZOOM")}},function(e){e&&t.dispatch("CROP_IMAGE_DRAG",{value:e})},function(e){e&&t.dispatch("CROP_IMAGE_DRAG_RELEASE")});var o=t.query("GET_FILE"),a=URL.createObjectURL(o.data),c=function(e){var r=scaleImageSize(e,{width:t.query("GET_MAX_IMAGE_PREVIEW_WIDTH"),height:t.query("GET_MAX_IMAGE_PREVIEW_HEIGHT")}),n=createPreviewImage(e,r.width,r.height,o.orientation),i=Math.max(1,.75*window.devicePixelRatio),a=n.height/n.width,c=96*i,l=createPreviewImage(n,a>1?c:c/a,a>1?c*a:c),u=n.getContext("2d").getImageData(0,0,n.width,n.height),s=l.getContext("2d").getImageData(0,0,l.width,l.height);canvasRelease(n),canvasRelease(l),t.ref.gl=setup(t.ref.canvas,u,i);var d=t.query("GET_OUTPUT_CANVAS_SYNC_TARGET");d&&(t.ref.gl.onupdate=function(){var e=t.ref.overlaySpring.getRect();d.getContext("2d").drawImage(t.ref.canvas,e.x*i,e.y*i,e.width*i,e.height*i,0,0,d.width,d.height)}),t.ref.gl?(t.dispatch("DID_RECEIVE_IMAGE_DATA",{previewData:u,thumbData:s}),t.dispatch("DID_PRESENT_IMAGE")):t.dispatch("MISSING_WEBGL")},l=function(){loadImage$2(a).then(c)};if(canCreateImageBitmap(o.data)){var u=createWorker(BitmapWorker);u.post({file:o.data},function(e){u.terminate(),e?c(e):l()})}else l();t.ref.canvasStyle=getComputedStyle(t.ref.canvas),t.ref.previousBackgroundColor,t.ref.previousLeft,t.ref.previousTop,t.ref.previousWidth,t.ref.previousHeight,t.element.dataset.showInteractionIndicator=!1,t.ref.handleFocus=function(e){9===e.keyCode&&(t.element.dataset.showInteractionIndicator=!0)},t.ref.handleBlur=function(e){t.element.dataset.showInteractionIndicator=!1},addEvent(t.element)("keyup",t.ref.handleFocus),addEvent(t.element)("blur",t.ref.handleBlur)},destroy:function(e){var t=e.root;t.ref.gl&&(t.ref.gl.release(),t.ref.gl=null),t.ref.dragger.destroy(),removeEvent(t.element)("keyup",t.ref.handleFocus),removeEvent(t.element)("blur",t.ref.handleBlur)},read:function(e){var t=e.root,r=t.ref.canvasStyle.backgroundColor,n=t.ref.canvasStyle.color;if("transparent"!==n&&""!==n||(n=null),"transparent"!==r&&""!==r||(r=null),r&&r!==t.ref.previousBackgroundColor){var i=toRGBColorArray(r).map(function(e){return e/255}),o=(i[0]+i[1]+i[2])/3;t.ref.backgroundColor=i,t.ref.backgroundColorCenter=i.map(function(e){return o>.5?e-.15:e+.15}),t.ref.previousBackgroundColor=r}n&&n!==t.ref.previousOutlineColor&&(t.ref.outlineColor=toRGBColorArray(n).map(function(e){return e/255}).concat(1),t.ref.previousOutlineColor=n)},write:createRoute({SHOW_VIEW:function(e){var t=e.root;"crop"===e.action.id?(t.ref.dragger.enable(),t.element.setAttribute("tabindex","0")):(t.ref.dragger.disable(),t.element.removeAttribute("tabindex"))}},function(e){var t=e.root,r=e.props,n=(e.actions,e.timestamp);if(t.ref.gl&&r.width&&r.height){var i=t.ref,o=i.gl,a=i.previousWidth,c=i.previousHeight,l=i.shouldZoom,u=i.stageSpring,s=i.overlaySpring,d=i.backgroundColorSpring,p=i.backgroundColorCenterSpring;r.width===a&&r.height===c||(t.ref.gl.resize(r.width,r.height),t.ref.previousWidth=r.width,t.ref.previousHeight=r.height),r.left===t.ref.previousLeft&&r.top===t.ref.previousTop||(t.ref.canvas.style.transform="translate(".concat(-r.left,"px, ").concat(-r.top,"px)"),t.ref.previousLeft=r.left,t.ref.previousTop=r.top),l&&!t.ref.didZoom&&(t.introScale=null,t.introScale=1.15,t.introScale=1,t.ref.didZoom=!0),d.setTarget(t.ref.backgroundColor),d.interpolate(n);var f=d.isStable();p.setTarget(t.ref.backgroundColorCenter),p.interpolate(n);var h=p.isStable();t.ref.colorMatrixStableCount=0;var g=r.colorMatrix||IdentityMatrix,m=t.ref.colorMatrixSpring.map(function(e,r){return e.target=g[r],e.interpolate(n),t.ref.colorMatrixPositions[r]}),v=20===t.ref.colorMatrixStableCount;r.isDraft&&s.setTarget(null),s.setTarget(r.overlay),s.interpolate(n);var y=s.isStable();r.isDraft&&u.setTarget(null),u.setTarget(r.stage),u.interpolate(n);var E=u.isStable();return o.update(t.xOrigin,t.yOrigin,t.xTranslation+r.left,t.yTranslation+r.top,t.xRotation,t.yRotation,t.zRotation,t.scale*t.introScale,m,t.ref.isPreview?1:t.colorOpacity,u.getRect(),s.getRect(),[1,1,1,1-t.overlayOpacity],d.getColor(),p.getColor(),d.getColor(),t.outlineWidth,t.ref.outlineColor,t.query("GET_BACKGROUND_COLOR")),y&&E&&v&&f&&h}})}),image=createView({name:"image",ignoreRect:!0,mixins:{apis:["offsetTop"]},create:function(e){var t=e.root,r=e.props;t.ref.imageGL=t.appendChildView(t.createChildView(imageGL)),/markup|sticker/.test(t.query("GET_UTILS"))&&(t.ref.markup=t.appendChildView(t.createChildView(imageMarkup,{id:r.id,opacity:0,onSelect:function(e){t.dispatch("MARKUP_SELECT",{id:e})},onDrag:function(e,r,n,i,o){t.dispatch("MARKUP_ELEMENT_DRAG",{id:e,origin:r,offset:n,size:i,scale:o})},onResize:function(e,r,n,i,o){t.dispatch("MARKUP_ELEMENT_RESIZE",{id:e,corner:r,origin:n,offset:i,size:o})},onUpdate:function(e,r){t.dispatch("MARKUP_UPDATE",{style:e,value:r})},isMarkupUtil:function(e){var t=e;do{if("doka--markup-tools"===t.className)return!0}while(t=t.parentNode);return!1}}))),t.ref.isModal=/modal/.test(t.query("GET_STYLE_LAYOUT_MODE"))},write:createRoute({DID_PRESENT_IMAGE:function(e){e.root.ref.imageGL.colorOpacity=1}},function(e){var t=e.root,r=e.props,n=e.timestamp,i=t.ref.imageGL,o=t.ref.markup,a=t.query("GET_CROP",r.id,n);if(a){var c=a.isDraft,l=a.cropRect,u=a.cropStatus,s=a.origin,d=a.translation,p=a.translationBand,f=a.scale,h=a.scaleBand,g=a.rotation,m=a.rotationBand,v=a.flip,y=a.colorMatrix,E=t.query("GET_ROOT"),T=t.query("GET_STAGE"),_=T.x,R=T.y;c&&(i.scale=null,i.zRotation=null,i.xTranslation=null,i.yTranslation=null,i.xOrigin=null,i.yOrigin=null),i.colorMatrix=y;var w=t.query("IS_ACTIVE_VIEW","crop"),A=t.query("IS_ACTIVE_VIEW","markup")||t.query("IS_ACTIVE_VIEW","sticker"),I=w?.75:.95,S=_objectSpread({},l),C=1,O=w?1:5;if(t.query("IS_ACTIVE_VIEW","resize")){var x=u.image.width,b=u.image.height;C=null===x&&null===b?u.crop.width/l.width:null===x?b/l.height:x/l.width,C/=window.devicePixelRatio;var M=l.width*C,L=l.height*C;S.x=S.x+(.5*l.width-.5*M),S.y=S.y+(.5*l.height-.5*L),S.width=M,S.height=L}var P=t.ref.isModal?0:E.left,G=t.ref.isModal?0:E.top,k=t.ref.isModal?0:E.width-t.rect.element.width,D=t.ref.isModal?0:E.height-t.rect.element.height-r.offsetTop,U=(f+h)*C;i.isDraft=c,i.overlayOpacity=I,i.xOrigin=s.x,i.yOrigin=s.y,i.xTranslation=d.x+p.x+_,i.yTranslation=d.y+p.y+R,i.left=P,i.top=G+r.offsetTop,i.width=t.rect.element.width+k,i.height=t.rect.element.height+D+r.offsetTop,i.scale=U,i.xRotation=v.vertical?Math.PI:0,i.yRotation=v.horizontal?Math.PI:0,i.zRotation=g.main+g.sub+m,i.stage={x:T.x+P,y:T.y+G+r.offsetTop,width:T.width,height:T.height},i.overlay={x:S.x+_+P,y:S.y+R+G+r.offsetTop,width:S.width,height:S.height},i.outlineWidth=O,o&&(c&&(o.translateX=null,o.translateY=null,o.markupX=null,o.markupY=null,o.markupWidth=null,o.markupHeight=null),o.opacity=w?.3:1,o.stageOffsetX=_,o.stageOffsetY=R,o.markupX=S.x+_,o.markupY=S.y+R,o.markupWidth=S.width,o.markupHeight=S.height,o.allowInteraction=A)}})}),createGroup=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"group",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:["opacity"],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return createView({ignoreRect:!0,name:e,mixins:{styles:["opacity"].concat(_toConsumableArray(t)),animations:_objectSpread({opacity:{type:"spring",stiffness:.25,damping:.5,mass:5}},r)},create:function(e){var t=e.root,r=e.props;(r.controls||[]).map(function(e){var r=t.createChildView(e.view,e);e.didCreateView&&e.didCreateView(r),t.appendChildView(r)}),r.element&&t.element.appendChild(r.element)}})},list=createView({ignoreRect:!0,tag:"div",name:"dropdown-list",mixins:{styles:["translateY","opacity"],apis:["selectedValue","options","onSelect"],animations:{translateY:"spring",opacity:{type:"tween",duration:250}}},create:function(e){var t=e.root,r=e.props;t.element.setAttribute("role","list"),t.ref.handleClick=function(){return r.action&&r.action()},t.element.addEventListener("click",t.ref.handleClick),t.ref.activeOptions=null,t.ref.activeSelectedValue},write:function(e){var t=e.root,r=e.props;if(r.options!==t.ref.activeOptions&&(t.ref.activeOptions=r.options,t.childViews.forEach(function(e){return t.removeChildView(e)}),r.options.map(function(e){var n=t.createChildView(button,_objectSpread({},e,{action:function(){return r.onSelect(e.value)}}));return t.appendChildView(n)})),r.selectedValue!==t.ref.activeSelectedValue){t.ref.activeSelectedValue=r.selectedValue;var n=r.options.findIndex(function(e){return"object"===_typeof(e.value)&&r.selectedValue?e.value[0]===e.label&&JSON.stringify(e.value.slice(1))===JSON.stringify(r.selectedValue)||JSON.stringify(e.value)===JSON.stringify(r.selectedValue):e.value===r.selectedValue});t.childViews.forEach(function(e,t){e.element.setAttribute("aria-selected",t===n)})}},destroy:function(e){var t=e.root;t.element.removeEventListener("click",t.ref.handleClick)}}),dropdown=createView({ignoreRect:!0,tag:"div",name:"dropdown",mixins:{styles:["opacity"],animations:{opacity:"spring"},apis:["direction","selectedValue","options","onSelect"]},create:function(e){var t=e.root,r=e.props;t.ref.open=!1;var n=function(e){t.ref.open=e,t.dispatch("KICK")};t.ref.button=t.appendChildView(t.createChildView(button,_objectSpread({},r,{action:function(){n(!t.ref.open)}}))),t.ref.list=t.appendChildView(t.createChildView(list,_objectSpread({},r,{opacity:0,action:function(){n(!1)}}))),t.ref.handleBodyClick=function(e){contains(t.element,e.target)||n(!1)},t.element.addEventListener("focusin",function(e){e.target!==t.ref.button.element&&n(!0)}),t.element.addEventListener("focusout",function(e){e.relatedTarget&&(contains(t.element,e.relatedTarget)||n(!1))}),document.body.addEventListener("click",t.ref.handleBodyClick)},destroy:function(e){var t=e.root;document.body.removeEventListener("click",t.ref.handleBodyClick)},write:function(e){var t=e.root,r=e.props;if(t.ref.list.opacity=t.ref.open?1:0,t.ref.list.selectedValue=r.selectedValue,t.ref.list.options=r.options,"up"===r.direction){var n=t.ref.list.rect.element.height;t.ref.list.translateY=(t.ref.open?-(n+5):-n)-t.rect.element.height}else t.ref.list.translateY=t.ref.open?0:-5}}),MAGIC=312,createDiv=function(e,t){return createView({name:e,ignoreRect:!0,create:t})},cropRotatorLine=createView({name:"crop-rotator-line",ignoreRect:!0,ignoreRectUpdate:!0,mixins:{styles:["translateX"],animations:{translateX:"spring"}},create:function(e){for(var t=e.root,r='",t.element.innerHTML=r}}),cropRotator=createView({name:"crop-rotator",ignoreRect:!0,mixins:{styles:["opacity","translateY"],animations:{opacity:{type:"spring",damping:.5,mass:5},translateY:"spring"},apis:["rotation","animate","setAllowInteraction"]},create:function(e){var t=e.root,r=e.props;t.element.setAttribute("tabindex",0);var n=document.createElement("button");n.innerHTML="".concat(t.query("GET_LABEL_BUTTON_CROP_ROTATE_CENTER"),""),n.className="doka--crop-rotator-center",n.addEventListener("click",function(){t.dispatch("CROP_IMAGE_ROTATE_CENTER")}),t.appendChild(n);var i=null;t.appendChildView(t.createChildView(createDiv("crop-rotator-line-mask",function(e){var t=e.root,r=e.props;i=t.appendChildView(t.createChildView(cropRotatorLine,{translateX:Math.round(r.rotation*MAGIC)}))}),r)),t.ref.line=i;var o=document.createElement("div");o.className="doka--crop-rotator-bar",t.appendChild(o);var a=Math.PI/4,c=0;t.ref.dragger=createDragger(o,function(){c=i.translateX/MAGIC,t.dispatch("CROP_IMAGE_ROTATE_GRAB")},function(e,r){var n=r.x/t.rect.element.width*(Math.PI/2),i=limit(c+n,-a,a);t.dispatch("CROP_IMAGE_ROTATE",{value:-i})},function(){t.dispatch("CROP_IMAGE_ROTATE_RELEASE")},{stopPropagation:!0}),r.setAllowInteraction=function(e){e?t.ref.dragger.enable():t.ref.dragger.disable()},t.ref.keyboard=createKeyboard(t.element,function(){c=0},{left:function(){c+=Math.PI/128,t.dispatch("CROP_IMAGE_ROTATE_ADJUST",{value:c})},right:function(){c-=Math.PI/128,t.dispatch("CROP_IMAGE_ROTATE_ADJUST",{value:c})}},function(){},function(){}),t.ref.prevRotation},destroy:function(e){var t=e.root;t.ref.dragger.destroy(),t.ref.keyboard.destroy()},write:function(e){var t=e.root,r=e.props,n=e.timestamp,i=r.animate,o=r.rotation;if(t.ref.prevRotation!==o){t.ref.prevRotation=o,i||0===o||(t.ref.line.translateX=null);var a=0,c=t.query("GET_CROP",r.id,n);if(c&&c.interaction&&c.interaction.rotation){var l=splitRotation(c.interaction.rotation).sub-o;a=.025*Math.sign(l)*Math.log10(1+Math.abs(l)/.025)}t.ref.line.translateX=Math.round((-o-a)*MAGIC)}}}),corners=["nw","ne","se","sw"],getOppositeCorner=function(e){return corners[(corners.indexOf(e)+2)%corners.length]},edges=["n","e","s","w"],getOppositeEdge=function(e){return edges[(edges.indexOf(e)+2)%edges.length]},autoPrecision=isBrowser()&&1===window.devicePixelRatio?function(e){return Math.round(e)}:function(e){return e},line=createView({ignoreRect:!0,ignoreRectUpdate:!0,name:"crop-rect-focal-line",mixins:{styles:["translateX","translateY","scaleX","scaleY","opacity"],animations:{translateX:"spring",translateY:"spring",scaleX:"spring",scaleY:"spring",opacity:"spring"}}}),createEdge=function(e){return createView({ignoreRect:!0,ignoreRectUpdate:!0,tag:"div",name:"crop-rect-edge-".concat(e),mixins:{styles:["translateX","translateY","scaleX","scaleY"],apis:["setAllowInteraction"]},create:function(t){var r=t.root,n=t.props;r.element.classList.add("doka--crop-rect-edge"),r.element.setAttribute("tabindex",0),r.element.setAttribute("role","button");var i=e,o=getOppositeEdge(e);r.ref.dragger=createDragger(r.element,function(){r.dispatch("CROP_RECT_DRAG_GRAB")},function(e,t){return r.dispatch("CROP_RECT_EDGE_DRAG",{offset:t,origin:i,anchor:o})},function(){return r.dispatch("CROP_RECT_DRAG_RELEASE")},{stopPropagation:!0,cancelOnMultiple:!0}),n.setAllowInteraction=function(e){e?r.ref.dragger.enable():r.ref.dragger.disable()},r.ref.keyboard=createKeyboard(r.element,function(){return{x:0,y:0}},{up:function(e){e.y-=20},down:function(e){e.y+=20},left:function(e){e.x-=20},right:function(e){e.x+=20}},function(e){r.dispatch("CROP_RECT_DRAG_GRAB"),r.dispatch("CROP_RECT_EDGE_DRAG",{offset:e,origin:i,anchor:o})},function(){r.dispatch("CROP_RECT_DRAG_RELEASE")})},destroy:function(e){var t=e.root;t.ref.keyboard.destroy(),t.ref.dragger.destroy()}})},createCorner=function(e,t,r){return createView({ignoreRect:!0,ignoreRectUpdate:!0,tag:"div",name:"crop-rect-corner-".concat(e),mixins:{styles:["translateX","translateY","scaleX","scaleY"],animations:{translateX:imageOverlaySpring,translateY:imageOverlaySpring,scaleX:{type:"spring",delay:r},scaleY:{type:"spring",delay:r},opacity:{type:"spring",delay:t}},apis:["setAllowInteraction"]},create:function(t){var r=t.root,n=t.props;r.element.classList.add("doka--crop-rect-corner"),r.element.setAttribute("role","button"),r.element.setAttribute("tabindex",-1);var i=e,o=getOppositeCorner(e);r.ref.dragger=createDragger(r.element,function(){r.dispatch("CROP_RECT_DRAG_GRAB")},function(e,t){r.dispatch("CROP_RECT_CORNER_DRAG",{offset:t,origin:i,anchor:o})},function(){r.dispatch("CROP_RECT_DRAG_RELEASE")},{stopPropagation:!0,cancelOnMultiple:!0}),n.setAllowInteraction=function(e){e?r.ref.dragger.enable():r.ref.dragger.disable()}},destroy:function(e){e.root.ref.dragger.destroy()}})},cropRect=createView({ignoreRect:!0,ignoreRectUpdate:!0,name:"crop-rect",mixins:{apis:["rectangle","draft","rotating","enabled"]},create:function(e){var t=e.root;t.ref.wasRotating=!1;corners.forEach(function(e,r){var n=10*r,i=250+n+50,o=250+n;t.ref[e]=t.appendChildView(t.createChildView(createCorner(e,i,o),{opacity:0,scaleX:.5,scaleY:.5}))}),edges.forEach(function(e){t.ref[e]=t.appendChildView(t.createChildView(createEdge(e)))}),t.ref.lines=[];for(var r=0;r<10;r++)t.ref.lines.push(t.appendChildView(t.createChildView(line,{opacity:0})));t.ref.animationDir=null,t.ref.previousRotating,t.ref.previousRect={},t.ref.previousEnabled,t.ref.previousDraft},write:function(e){var t=e.root,r=e.props,n=r.rectangle,i=r.draft,o=r.rotating,a=r.enabled;if(n&&(!rectEqualsRect(n,t.ref.previousRect)||o!==t.ref.previousRotating||a!==t.ref.previousEnabled||i!==t.ref.previousDraft)){t.ref.previousRect=n,t.ref.previousRotating=o,t.ref.previousEnabled=a,t.ref.previousDraft=i;var c=t.ref,l=c.n,u=c.e,s=c.s,d=c.w,p=c.nw,f=c.ne,h=c.se,g=c.sw,m=c.lines,v=c.animationDir,y=n.x,E=n.y,T=n.x+n.width,_=n.y+n.height,R=_-E,w=T-y,A=Math.min(w,R);t.element.dataset.indicatorSize=A<80?"none":"default",edges.forEach(function(e){return t.ref[e].setAllowInteraction(a)}),corners.forEach(function(e){return t.ref[e].setAllowInteraction(a)});var I=t.query("IS_ACTIVE_VIEW","crop");if(I&&"in"!==v?(t.ref.animationDir="in",corners.map(function(e){return t.ref[e]}).forEach(function(e){e.opacity=1,e.scaleX=1,e.scaleY=1})):I||"out"===v||(t.ref.animationDir="out",corners.map(function(e){return t.ref[e]}).forEach(function(e){e.opacity=0,e.scaleX=.5,e.scaleY=.5})),transformTranslate(i,p,y,E),transformTranslate(i,f,T,E),transformTranslate(i,h,T,_),transformTranslate(i,g,y,_),transformTranslateScale(i,l,y,E,w/100,1),transformTranslateScale(i,u,T,E,1,R/100),transformTranslateScale(i,s,y,_,w/100,1),transformTranslateScale(i,d,y,E,1,R/100),o){t.ref.wasRotating=!0;var S=m.slice(0,5),C=1/S.length;S.forEach(function(e,t){transformTranslateScale(i,e,y,E+R*(C+t*C),w/100,.01),e.opacity=.5});var O=m.slice(5);C=1/O.length,O.forEach(function(e,t){transformTranslateScale(i,e,y+w*(C+t*C),E,.01,R/100),e.opacity=.5})}else if(i){t.ref.wasRotating=!1;var x=m[0],b=m[1],M=m[2],L=m[3];transformTranslateScale(i,x,y,E+.333*R,w/100,.01),transformTranslateScale(i,b,y,E+.666*R,w/100,.01),transformTranslateScale(i,M,y+.333*w,E,.01,R/100),transformTranslateScale(i,L,y+.666*w,E,.01,R/100),x.opacity=.5,b.opacity=.5,M.opacity=.5,L.opacity=.5}else{var P=m[0],G=m[1],k=m[2],D=m[3];!t.ref.wasRotating&&P.opacity>0&&(transformTranslateScale(i,P,y,E+.333*R,w/100,.01),transformTranslateScale(i,G,y,E+.666*R,w/100,.01),transformTranslateScale(i,k,y+.333*w,E,.01,R/100),transformTranslateScale(i,D,y+.666*w,E,.01,R/100)),m.forEach(function(e){return e.opacity=0})}}}}),transformTranslateScale=function(e,t,r,n,i,o){e&&(t.translateX=null,t.translateY=null,t.scaleX=null,t.scaleY=null),t.translateX=autoPrecision(r),t.translateY=autoPrecision(n),t.scaleX=i,t.scaleY=o},transformTranslate=function(e,t,r,n){e&&(t.translateX=null,t.translateY=null),t.translateX=autoPrecision(r),t.translateY=autoPrecision(n)},setInnerHTML=function(e,t){if(!/svg/.test(e.namespaceURI)||"innerHTML"in e)e.innerHTML=t;else{var r=document.createElement("div");r.innerHTML=""+t+"";for(var n=r.firstChild;n.firstChild;)e.appendChild(n.firstChild)}},cropMask=createView({ignoreRect:!0,ignoreRectUpdate:!0,name:"crop-mask",tag:"svg",mixins:{styles:["opacity","translateX","translateY"],animations:{scale:imageOverlaySpring,maskWidth:imageOverlaySpring,maskHeight:imageOverlaySpring,translateX:imageOverlaySpring,translateY:imageOverlaySpring,opacity:{type:"tween",delay:0,duration:1e3}},apis:["rectangle","animate","maskWidth","maskHeight","scale"]},create:function(e){e.root.ref.writer=null},write:function(e){var t=e.root,r=t.query("GET_CROP_MASK");r!==t.ref.writer&&(t.ref.writer=r,t.ref.writerFn=r?r(t.element,setInnerHTML):null,t.ref.writer||setInnerHTML(t.element,""))},didWriteView:function(e){var t=e.root,r=e.props,n=r.maskWidth,i=r.maskHeight,o=r.scale;if(t.ref.writer&&n&&i&&(t.element.setAttribute("width",autoPrecision(n)),t.element.setAttribute("height",autoPrecision(i)),t.ref.writerFn)){var a=t.query("GET_CROP_MASK_INSET");t.ref.writerFn({x:o*a,y:o*a,width:n-o*a*2,height:i-o*a*2},{width:n,height:i})}}}),updateText$1=function(e,t){var r=e.childNodes[0];r?t!==r.nodeValue&&(r.nodeValue=t):(r=document.createTextNode(t),e.appendChild(r))},sizeSpring={type:"spring",stiffness:.25,damping:.1,mass:1},cropSize=createView({ignoreRect:!0,name:"crop-size",mixins:{styles:["translateX","translateY","opacity"],animations:{translateX:"spring",translateY:"spring",opacity:"spring",sizeWidth:sizeSpring,sizeHeight:sizeSpring},apis:["sizeWidth","sizeHeight"],listeners:!0},create:function(e){var t=e.root,r=createElement("span");r.className="doka--crop-size-info doka--crop-resize-percentage",t.ref.resizePercentage=r,t.appendChild(r);var n=createElement("span");n.className="doka--crop-size-info";var i=createElement("span");i.className="doka--crop-size-multiply",i.textContent="×";var o=createElement("span"),a=createElement("span");t.ref.outputWidth=o,t.ref.outputHeight=a,n.appendChild(o),n.appendChild(i),n.appendChild(a),t.appendChild(n),t.ref.previousValues={width:0,height:0,percentage:0}},write:function(e){var t=e.root,r=e.props,n=e.timestamp;if(!(t.opacity<=0)){var i=t.query("GET_CROP",r.id,n);if(i){var o=i.cropStatus,a=i.isDraft,c=t.ref,l=c.outputWidth,u=c.outputHeight,s=c.resizePercentage,d=c.previousValues,p=o.image,f=o.crop,h=o.currentWidth,g=o.currentHeight,m=p.width?Math.round(p.width/f.width*100):0;a&&(t.sizeWidth=null,t.sizeHeight=null),t.sizeWidth=h,t.sizeHeight=g;var v=Math.round(t.sizeWidth),y=Math.round(t.sizeHeight);v!==d.width&&(updateText$1(l,v),d.width=v),y!==d.height&&(updateText$1(u,y),d.height=y),m!==d.percentage&&(p.width?updateText$1(s,"".concat(m,"%")):updateText$1(s,""),d.percentage=m)}}}}),wrapper=function(e,t){return createView({ignoreRect:!0,name:e,mixins:t,create:function(e){var t=e.root,r=e.props;r.className&&t.element.classList.add(r.className),r.controls.map(function(e){var r=t.createChildView(e.view,e);e.didCreateView&&e.didCreateView(r),t.appendChildView(r)})}})},warn=function(){return console.log("Doka: localStorage not available")},getData=function(e){try{JSON.parse(localStorage.getItem(e)||"{}")}catch(e){warn()}return{}},setStoredValue=function(e,t,r){var n=getData(e);n[t]=r;try{localStorage.setItem(e,JSON.stringify(n))}catch(e){warn()}return r},getStoredValue=function(e,t,r){var n=getData(e);return void 0===n[t]?r:n[t]},canHover=function(){return window.matchMedia("(pointer: fine) and (hover: hover)").matches},instructionsBubble=createView({ignoreRect:!0,ignoreRectUpdate:!0,name:"instructions-bubble",mixins:{styles:["opacity","translateX","translateY"],animations:{opacity:{type:"tween",duration:400}},apis:["seen"]},create:function(e){var t=e.root,r=e.props;return t.element.innerHTML=(r.iconBefore||"")+r.text},write:function(e){var t=e.root;e.props.seen&&(t.opacity=0)}}),SPRING_TRANSLATE={type:"spring",stiffness:.4,damping:.65,mass:7},cropSubject=createView({name:"crop-subject",ignoreRect:!0,mixins:{styles:["opacity","translateX","translateY"],animations:{opacity:{type:"tween",duration:250},translateX:SPRING_TRANSLATE,translateY:SPRING_TRANSLATE}},create:function(e){var t=e.root,r=e.props;(t.opacity=1,t.ref.timestampOffset=null,t.query("GET_CROP_ALLOW_INSTRUCTION_ZOOM")&&canHover())&&(getStoredValue(t.query("GET_STORAGE_NAME"),"instruction_zoom_shown",!1)||(t.ref.instructions=t.appendChildView(t.createChildView(instructionsBubble,{opacity:0,seen:!1,text:t.query("GET_LABEL_CROP_INSTRUCTION_ZOOM"),iconBefore:createIcon('')}))));t.ref.maskView=t.appendChildView(t.createChildView(cropMask)),t.query("GET_CROP_ALLOW_RESIZE_RECT")&&(t.ref.cropView=t.appendChildView(t.createChildView(cropRect))),t.query("GET_CROP_SHOW_SIZE")&&(t.ref.cropSize=t.appendChildView(t.createChildView(cropSize,{id:r.id,opacity:1,scaleX:1,scaleY:1,translateX:null}))),t.query("GET_CROP_ZOOM_TIMEOUT")||(t.ref.btnZoom=t.appendChildView(t.createChildView(wrapper("zoom-wrapper",{styles:["opacity","translateX","translateY"],animations:{opacity:{type:"tween",duration:250}}}),{opacity:0,controls:[{view:button,label:t.query("GET_LABEL_BUTTON_CROP_ZOOM"),name:"zoom",icon:createIcon('',26),action:function(){return t.dispatch("CROP_ZOOM")}}]})))},write:createRoute({CROP_IMAGE_RESIZE_MULTIPLY:function(e){var t=e.root,r=t.ref.instructions;r&&!r.seen&&(r.seen=!0,setStoredValue(t.query("GET_STORAGE_NAME"),"instruction_zoom_shown",!0))},CROP_RECT_DRAG_RELEASE:function(e){var t=e.root,r=e.props,n=e.timestamp,i=t.ref.btnZoom;if(i){var o=t.query("GET_CROP",r.id,n).cropRect,a=o.x+.5*o.width,c=o.y+.5*o.height;i.translateX=a,i.translateY=c}}},function(e){var t=e.root,r=e.props,n=e.timestamp,i=t.ref,o=i.cropView,a=i.maskView,c=i.btnZoom,l=i.cropSize,u=i.instructions;if(!t.query("IS_ACTIVE_VIEW","crop")&&o)return o.enabled=!1,t.ref.timestampOffset=null,void(l&&(l.opacity=0));t.ref.timestampOffset||(t.ref.timestampOffset=n);var s=t.query("GET_CROP",r.id,n);if(s){var d=s.cropRect,p=s.isRotating,f=s.isDraft,h=s.scale,g=t.query("GET_STAGE");if(t.translateX=g.x-t.rect.element.left,t.translateY=g.y-t.rect.element.top,o&&(o.draft=f,o.rotating=p,o.rectangle=d,o.enabled=!0),l){l.opacity=1,f&&(l.translateX=null,l.translateY=null);var m=getCropSizeOffset(t.rect.element,l.rect.element,d);l.translateX=f?m.x:autoPrecision(m.x),l.translateY=f?m.y:autoPrecision(m.y)}if(t.query("GET_CROP_MASK")&&(f&&(a.translateX=null,a.translateY=null,a.maskWidth=null,a.maskHeight=null),a.translateX=autoPrecision(d.x),a.translateY=autoPrecision(d.y),a.maskWidth=d.width,a.maskHeight=d.height,a.scale=h),s.canRecenter)u&&(u.opacity=0),c&&(c.opacity=s.isDraft?0:1);else if(c&&(c.opacity=0),u&&!u.seen&&!s.isDraft){var v=d.x+.5*d.width,y=d.y+.5*d.height;u.translateX=Math.round(v-.5*u.rect.element.width),u.translateY=Math.round(y-.5*u.rect.element.height),n-t.ref.timestampOffset>2e3&&(u.opacity=1)}}})}),getCropSizeOffset=function(e,t,r){var n=r.x,i=r.x+r.width,o=r.y+r.height,a=i-t.width-16,c=o-t.height-16;return t.width>r.width-32&&(a=n+(.5*r.width-.5*t.width),(c=o+16)>e.height-t.height&&(c=o-t.height-16)),{x:a=Math.max(0,Math.min(a,e.width-t.width)),y:c}},now=function(){return performance.now()},throttle=function(e,t){var r=null,n=null;return function(){var i=arguments;if(!n)return e.apply(null,Array.from(arguments)),void(n=now());clearTimeout(r),r=setTimeout(function(){now()-n>=t&&(e.apply(null,Array.from(i)),n=now())},t-(now()-n))}},climb=function(e,t){for(;1===e.nodeType&&!t(e);)e=e.parentNode;return 1===e.nodeType?e:null},isMyTarget=function(e,t){var r=climb(t,function(e){return e.classList.contains("doka--root")});return!!r&&contains(r,e)},updateIndicators=function(e){var t=e.root,r=e.props,n=e.action.position,i=r.pivotPoint,o=t.ref,a=o.indicatorA,c=o.indicatorB,l=i.x-n.x,u=i.y-n.y,s={x:i.x+l,y:i.y+u},d={x:i.x-l,y:i.y-u};a.style.cssText="transform: translate3d(".concat(s.x,"px, ").concat(s.y,"px, 0)"),c.style.cssText="transform: translate3d(".concat(d.x,"px, ").concat(d.y,"px, 0)")},getPositionFromEvent=function(e){return{x:e.pageX,y:e.pageY}},cropResize=createView({ignoreRect:!0,ignoreRectUpdate:!0,name:"crop-resizer",mixins:{apis:["pivotPoint","scrollRect"]},create:function(e){var t=e.root,r=e.props;t.ref.isActive=!1,t.ref.isCropping=!1,t.ref.indicatorA=document.createElement("div"),t.appendChild(t.ref.indicatorA),t.ref.indicatorB=document.createElement("div"),t.appendChild(t.ref.indicatorB);var n=t.query("GET_CROP_RESIZE_KEY_CODES");t.ref.hasEnabledResizeModifier=n.length>0;var i={origin:{x:null,y:null},position:{x:null,y:null},selecting:!1,enabled:!1,scrollY:0,offsetX:0,offsetY:0},o=now();t.ref.state=i;var a=createPointerRegistry(),c=0,l=!1;t.ref.resizeStart=function(e){if(t.ref.isActive&&(0===a.count()&&(l=!1),isMyTarget(t.element,e.target)&&(a.push(e),addEvent$1(document.documentElement,"up",t.ref.resizeEnd),a.multiple()))){e.stopPropagation(),e.preventDefault();var r=a.active(),n=getPositionFromEvent(r[0]),i=getPositionFromEvent(r[1]);c=vectorDistance(n,i),addEvent$1(document.documentElement,"move",t.ref.resizeMove),l=!0}},t.ref.resizeMove=function(e){if(t.ref.isActive&&l&&(e.preventDefault(),2===a.count())){a.update(e);var r=a.active(),n=getPositionFromEvent(r[0]),i=getPositionFromEvent(r[1]),o=(vectorDistance(n,i)-c)/c;t.dispatch("CROP_IMAGE_RESIZE",{value:o})}},t.ref.resizeEnd=function(e){if(t.ref.isActive){a.pop(e);var r=0===a.count();r&&(removeEvent$1(document.documentElement,"move",t.ref.resizeMove),removeEvent$1(document.documentElement,"up",t.ref.resizeEnd)),l&&(e.preventDefault(),r&&t.dispatch("CROP_IMAGE_RESIZE_RELEASE"))}},addEvent$1(document.documentElement,"down",t.ref.resizeStart);var u=performance.now(),s=0,d=1,p=throttle(function(e){if(!t.ref.isCropping){var r=Math.sign(e.wheelDelta||e.deltaY),n=now(),i=n-u;u=n,(i>750||s!==r)&&(d=1,s=r),d+=.05*r,t.dispatch("CROP_IMAGE_RESIZE_MULTIPLY",{value:Math.max(.1,d)}),t.dispatch("CROP_IMAGE_RESIZE_RELEASE")}},100);t.ref.wheel=function(e){if(t.ref.isActive&&isMyTarget(t.element,e.target)){if(r.scrollRect){var n=r.scrollRect,i=t.query("GET_ROOT"),o=getPositionFromEvent(e),a={x:o.x-i.leftScroll,y:o.y-i.topScroll};if(a.xn.x+n.width||a.yn.y+n.height)return}e.preventDefault(),p(e)}},document.addEventListener("wheel",t.ref.wheel,{passive:!1}),t.ref.hasEnabledResizeModifier&&(t.ref.move=function(e){if(t.ref.isActive&&!t.ref.isCropping&&(i.position.x=e.pageX-t.ref.state.offsetX,i.position.y=e.pageY-t.ref.state.scrollY-t.ref.state.offsetY,i.enabled))if(isMyTarget(t.element,e.target)){"idle"===t.element.dataset.state&&t.dispatch("RESIZER_SHOW",{position:_objectSpread({},i.position)}),e.preventDefault(),t.dispatch("RESIZER_MOVE",{position:_objectSpread({},i.position)});var n=r.pivotPoint,a=n.x-i.position.x,l=n.y-i.position.y,u={x:n.x+a,y:n.y+l},s=_objectSpread({},i.position);if(i.selecting){var d=(vectorDistance(u,s)-c)/c,p=performance.now();p-o>25&&(o=p,t.dispatch("CROP_IMAGE_RESIZE",{value:d}))}}else t.dispatch("RESIZER_CANCEL")},t.ref.select=function(e){if(t.ref.isActive&&isMyTarget(t.element,e.target)){var n=r.pivotPoint,o=n.x-i.position.x,a=n.y-i.position.y,l={x:n.x+o,y:n.y+a},u=i.position;c=vectorDistance(l,u),i.selecting=!0,i.origin.x=e.pageX,i.origin.y=e.pageY,t.dispatch("CROP_IMAGE_RESIZE_GRAB")}},t.ref.confirm=function(e){t.ref.isActive&&isMyTarget(t.element,e.target)&&(i.selecting=!1,t.dispatch("CROP_IMAGE_RESIZE_RELEASE"))},t.ref.blur=function(){t.ref.isActive&&(i.selecting=!1,i.enabled=!1,document.removeEventListener("mousedown",t.ref.select),document.removeEventListener("mouseup",t.ref.confirm),t.dispatch("RESIZER_CANCEL"))},window.addEventListener("blur",t.ref.blur),document.addEventListener("mousemove",t.ref.move),t.ref.keyDown=function(e){t.ref.isActive&&n.includes(e.keyCode)&&i.position&&(i.enabled=!0,document.addEventListener("mousedown",t.ref.select),document.addEventListener("mouseup",t.ref.confirm),t.dispatch("RESIZER_SHOW",{position:_objectSpread({},i.position)}))},t.ref.keyUp=function(e){t.ref.isActive&&n.includes(e.keyCode)&&(i.enabled=!1,document.removeEventListener("mousedown",t.ref.select),document.removeEventListener("mouseup",t.ref.confirm),t.dispatch("RESIZER_CANCEL"))},document.body.addEventListener("keydown",t.ref.keyDown),document.body.addEventListener("keyup",t.ref.keyUp))},destroy:function(e){var t=e.root;document.removeEventListener("touchmove",t.ref.resizeMove),document.removeEventListener("touchend",t.ref.resizeEnd),document.removeEventListener("touchstart",t.ref.resizeStart),document.removeEventListener("wheel",t.ref.wheel),document.removeEventListener("mousedown",t.ref.select),document.removeEventListener("mouseup",t.ref.confirm),t.ref.hasEnabledResizeModifier&&(document.removeEventListener("mousemove",t.ref.move),document.body.removeEventListener("keydown",t.ref.keyDown),document.body.removeEventListener("keyup",t.ref.keyUp),window.removeEventListener("blur",t.ref.blur))},read:function(e){var t=e.root;t.ref.state.scrollY=window.scrollY;var r=t.element.getBoundingClientRect();t.ref.state.offsetX=r.x,t.ref.state.offsetY=r.y},write:createRoute({CROP_RECT_DRAG_GRAB:function(e){e.root.ref.isCropping=!0},CROP_RECT_DRAG_RELEASE:function(e){e.root.ref.isCropping=!1},SHOW_VIEW:function(e){var t=e.root,r=e.action;t.ref.isActive="crop"===r.id},RESIZER_SHOW:function(e){var t=e.root,r=e.props,n=e.action;t.element.dataset.state="multi-touch",updateIndicators({root:t,props:r,action:n})},RESIZER_CANCEL:function(e){e.root.element.dataset.state="idle"},RESIZER_MOVE:updateIndicators})}),setOpacity=function(e,t){return e.style.opacity=t},updateImageBoundsIcon=function(e,t){var r=Array.from(e.element.querySelectorAll(".doka--icon-crop-limit rect"));r.length&&(setOpacity(r[0],t?.3:0),setOpacity(r[1],t?1:0),setOpacity(r[2],t?0:.3),setOpacity(r[3],t?0:1))},updateAspectRatioIcon=function(e,t){var r=e.element.querySelectorAll(".doka--icon-aspect-ratio rect");if(r.length){if(!t)return setOpacity(r[0],.2),setOpacity(r[1],.3),void setOpacity(r[2],.4);setOpacity(r[0],t>1?1:.3),setOpacity(r[1],1===t?.85:.5),setOpacity(r[2],t<1?1:.3)}},updateTurnIcons=function(e,t){Array.from(e.element.querySelectorAll(".doka--icon-turn rect")).forEach(function(e){t>1&&(e.setAttribute("x",e.previousElementSibling?5:4),e.setAttribute("width",9)),t<1&&(e.setAttribute("y",11),e.setAttribute("height",10))})},createRectangle=function(e){var t,r;e>1?(r=14,t=Math.round(r/e)):(t=14,r=Math.round(t*e));var n=Math.round(.5*(23-t)),i=Math.round(.5*(23-r));return'')},cropRoot=createView({name:"crop",ignoreRect:!0,mixins:{apis:["viewId","stagePosition","hidden","offsetTop"]},create:function(e){var t=e.root,r=e.props;r.viewId="crop",r.hidden=!1,t.ref.isHiding=!1;var n=[];t.query("GET_CROP_ALLOW_IMAGE_TURN_LEFT")&&n.push({view:button,name:"tool",label:t.query("GET_LABEL_BUTTON_CROP_ROTATE_LEFT"),icon:createIcon('',26),action:function(){return t.dispatch("CROP_IMAGE_ROTATE_LEFT")}}),t.query("GET_CROP_ALLOW_IMAGE_TURN_RIGHT")&&n.push({view:button,name:"tool",label:t.query("GET_LABEL_BUTTON_CROP_ROTATE_RIGHT"),icon:createIcon('',26),action:function(){return t.dispatch("CROP_IMAGE_ROTATE_RIGHT")}}),t.query("GET_CROP_ALLOW_IMAGE_FLIP_HORIZONTAL")&&n.push({view:button,name:"tool",label:t.query("GET_LABEL_BUTTON_CROP_FLIP_HORIZONTAL"),icon:createIcon('',26),action:function(){return t.dispatch("CROP_IMAGE_FLIP_HORIZONTAL")}}),t.query("GET_CROP_ALLOW_IMAGE_FLIP_VERTICAL")&&n.push({view:button,name:"tool",label:t.query("GET_LABEL_BUTTON_CROP_FLIP_VERTICAL"),icon:createIcon('',26),action:function(){return t.dispatch("CROP_IMAGE_FLIP_VERTICAL")}});var i=t.query("GET_CROP_ASPECT_RATIO_OPTIONS");i&&i.length&&n.push({view:dropdown,name:"tool",label:t.query("GET_LABEL_BUTTON_CROP_ASPECT_RATIO"),icon:createIcon('',26),options:null,onSelect:function(e){e.width&&e.height?t.dispatch("RESIZE_SET_OUTPUT_SIZE",{width:e.width,height:e.height}):(t.query("GET_CROP_ASPECT_RATIO_OPTIONS").find(function(e){return e.value&&e.value.width||e.value.height})&&t.dispatch("RESIZE_SET_OUTPUT_SIZE",{width:null,height:null}),t.dispatch("CROP_SET_ASPECT_RATIO",{value:e.aspectRatio}))},didCreateView:function(e){t.ref.aspectRatioDropdown=e}}),t.query("GET_CROP_ALLOW_TOGGLE_LIMIT")&&n.push({view:dropdown,name:"tool",label:t.query("GET_LABEL_BUTTON_CROP_TOGGLE_LIMIT"),icon:createIcon('\n \n \n \n \n ',26),options:[{value:!0,label:t.query("GET_LABEL_BUTTON_CROP_TOGGLE_LIMIT_ENABLE"),icon:''},{value:!1,label:t.query("GET_LABEL_BUTTON_CROP_TOGGLE_LIMIT_DISABLE"),icon:''}],onSelect:function(e){t.dispatch("CROP_SET_LIMIT",{value:e})},didCreateView:function(e){t.ref.cropToggleLimitDropdown=e}}),t.ref.menu=t.appendChildView(t.createChildView(createGroup("toolbar",["opacity"],{opacity:{type:"spring",mass:15,delay:50}}),{opacity:0,controls:n})),t.ref.menuItemsRequiredWidth=null,t.ref.subject=t.appendChildView(t.createChildView(cropSubject,_objectSpread({},r))),t.query("GET_CROP_ALLOW_ROTATE")&&(t.ref.rotator=t.appendChildView(t.createChildView(cropRotator,{rotation:0,opacity:0,translateY:20,id:r.id}))),t.ref.resizer=t.appendChildView(t.createChildView(cropResize,{pivotPoint:{x:0,y:0}})),t.ref.updateControls=function(){var e=t.query("GET_IMAGE");if(updateTurnIcons(t,e.height/e.width),t.ref.cropToggleLimitDropdown&&(t.ref.isLimitedToImageBounds=t.query("GET_CROP_LIMIT_TO_IMAGE_BOUNDS"),updateImageBoundsIcon(t,t.ref.isLimitedToImageBounds),t.ref.cropToggleLimitDropdown.selectedValue=t.ref.isLimitedToImageBounds),t.ref.aspectRatioDropdown){var r=t.query("GET_MIN_IMAGE_SIZE"),n=i.filter(function(t){if(!t.value.aspectRatio)return!0;if(t.value.aspectRatio<1){if(e.naturalWidth*t.value.aspectRatiot.ref.menu.rect.element.width?"compact":"spacious",t.query("GET_CROP_RESIZE_SCROLL_RECT_ONLY")){var y=t.query("GET_STAGE"),E=y.x,T=y.y,_=t.query("GET_ROOT"),R=t.ref.isModal?_.left:0,w=t.ref.isModal?_.top:0;o.scrollRect={x:R+E+h.cropRect.x,y:w+T+h.cropRect.y+r.offsetTop,width:h.cropRect.width,height:h.cropRect.height}}}}})}),sizeInput=createView({name:"size-input",mixins:{listeners:!0,apis:["id","value","placeholder","getValue","setValue","setPlaceholder","hasFocus","onChange"]},create:function(e){var t=e.root,r=e.props,n=r.id,i=r.min,o=r.max,a=r.value,c=r.placeholder,l=r.onChange,u=void 0===l?function(){}:l,s=r.onBlur,d=void 0===s?function(){}:s,p="doka--".concat(n,"-").concat(getUniqueId()),f=createElement("input",{type:"number",step:1,id:p,min:i,max:o,value:a,placeholder:c}),h=f.getAttribute("max").length,g=createElement("label",{for:p});g.textContent=r.label;var m=function(e,t,r){return isString(e)?((e=e.replace(/[^0-9]/g,"")).length>h&&(e=e.slice(0,h)),e=parseInt(e,10)):e=Math.round(e),isNaN(e)?null:limit(e,t,r)},v=function(e){return e.length?parseInt(f.value,10):null};t.ref.handleInput=function(){f.value=m(f.value,1,o),u(v(f.value))},t.ref.handleBlur=function(){f.value=m(f.value,i,o),d(v(f.value))},f.addEventListener("input",t.ref.handleInput),f.addEventListener("blur",t.ref.handleBlur),t.appendChild(f),t.appendChild(g),t.ref.input=f,r.hasFocus=function(){return f===document.activeElement},r.getValue=function(){return v(f.value)},r.setValue=function(e){return f.value=e?m(e,1,999999):null},r.setPlaceholder=function(e){return f.placeholder=e}},destroy:function(e){var t=e.root;t.ref.input.removeEventListener("input",t.ref.handleInput),t.ref.input.removeEventListener("blur",t.ref.handleBlur)}}),checkboxInput=createView({name:"checkable",tag:"span",mixins:{listeners:!0,apis:["id","checked","onChange","onSetValue","setValue","getValue"]},create:function(e){var t=e.root,r=e.props,n=r.id,i=r.checked,o=r.onChange,a=void 0===o?function(){}:o,c=r.onSetValue,l=void 0===c?function(){}:c,u="doka--".concat(n,"-").concat(getUniqueId()),s=createElement("input",{type:"checkbox",value:1,id:u});s.checked=i,t.ref.input=s;var d=createElement("label",{for:u});d.innerHTML=r.label,t.appendChild(s),t.appendChild(d),t.ref.handleChange=function(){l(s.checked),a(s.checked)},s.addEventListener("change",t.ref.handleChange),r.getValue=function(){return s.checked},r.setValue=function(e){s.checked=e,l(s.checked)},setTimeout(function(){l(s.checked)},0)},destroy:function(e){var t=e.root;t.ref.input.removeEventListener("change",t.ref.handleChange)}}),testResult$2=null,isAndroid=function(){return null===testResult$2&&(testResult$2=/Android/i.test(navigator.userAgent)),testResult$2},resizeForm=createView({ignoreRect:!0,name:"resize-form",tag:"form",mixins:{styles:["opacity"],animations:{opacity:{type:"spring",mass:15,delay:150}}},create:function(e){var t=e.root;t.element.setAttribute("novalidate","novalidate"),t.element.setAttribute("action","#"),t.ref.shouldBlurKeyboard=isIOS()||isAndroid();var r=t.query("GET_SIZE_MAX"),n=t.query("GET_SIZE_MIN"),i=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=e.axisLock,o=void 0===i?"none":i,a=e.enforceLimits,c=void 0!==a&&a,l=t.ref,u=l.inputImageWidth,s=l.inputImageHeight,d=l.buttonConfirm,p=t.query("GET_SIZE_ASPECT_RATIO_LOCK"),f=t.query("GET_CROP_RECTANGLE_ASPECT_RATIO"),h={width:u.getValue(),height:s.getValue()},g=limitSize(h,c?n:{width:1,height:1},c?r:{width:999999,height:999999},p?f:null,o);if(p)"width"===o?s.setValue(g.width/f):"height"===o?u.setValue(g.height*f):(u.setValue(g.width||g.height*f),s.setValue(g.height||g.width/f));else if(g.width&&!g.height){var m=Math.round(g.width/f),v=limitSize({width:g.width,height:m},c?n:{width:1,height:1},c?r:{width:999999,height:999999},f,o);c&&u.setValue(Math.round(v.width)),s.setPlaceholder(Math.round(v.height))}else if(g.height&&!g.width){var y=Math.round(g.height*f);u.setPlaceholder(y)}var E=t.query("GET_SIZE_INPUT"),T=E.width,_=E.height,R=isNumber(T)?Math.round(T):null,w=isNumber(_)?Math.round(_):null,A=u.getValue(),I=s.getValue(),S=A!==R||I!==w;return d.opacity=S?1:0,t.dispatch("KICK"),{width:u.getValue(),height:s.getValue()}},o=t;t.appendChildView(t.createChildView(createFieldGroup("Image size",function(e){var t=e.root,a=t.query("GET_SIZE"),c=t.appendChildView(t.createChildView(sizeInput,{id:"image-width",label:t.query("GET_LABEL_RESIZE_WIDTH"),value:isNumber(a.width)?Math.round(a.width):null,min:n.width,max:r.width,placeholder:0,onChange:function(){return i({axisLock:"width"})},onBlur:function(){return i({enforceLimits:!1})}})),l=t.appendChildView(t.createChildView(checkboxInput,{id:"aspect-ratio-lock",label:createIcon(''),checked:t.query("GET_SIZE_ASPECT_RATIO_LOCK"),onSetValue:function(e){var t=e?0:-3;l.element.querySelector(".doka--aspect-ratio-lock-ring").setAttribute("transform","translate(0 ".concat(t,")"))},onChange:function(e){t.dispatch("RESIZE_SET_OUTPUT_SIZE_ASPECT_RATIO_LOCK",{value:e}),i()}})),u=t.appendChildView(t.createChildView(sizeInput,{id:"image-height",label:t.query("GET_LABEL_RESIZE_HEIGHT"),value:isNumber(a.height)?Math.round(a.height):null,min:n.height,max:r.height,placeholder:0,onChange:function(){return i({axisLock:"height"})},onBlur:function(){return i({enforceLimits:!1})}}));o.ref.aspectRatioLock=l,o.ref.inputImageWidth=c,o.ref.inputImageHeight=u}))),t.ref.buttonConfirm=t.appendChildView(t.createChildView(button,{name:"app action-confirm icon-only",label:t.query("GET_LABEL_RESIZE_APPLY_CHANGES"),action:function(){},opacity:0,icon:createIcon(''),type:"submit"})),t.ref.confirmForm=function(e){var r=i({enforceLimits:!0});e.preventDefault();var n=t.ref,o=n.shouldBlurKeyboard,a=n.buttonConfirm;o&&(document.activeElement.blur(),a.element.focus()),a.opacity=0,t.dispatch("RESIZE_SET_OUTPUT_SIZE",r)},t.element.addEventListener("submit",t.ref.confirmForm)},destroy:function(e){var t=e.root;t.element.removeEventListener("submit",t.ref.confirmForm)},write:createRoute({EDIT_RESET:function(e){var t=e.root,r=t.query("GET_SIZE"),n=t.ref,i=n.inputImageWidth,o=n.inputImageHeight,a=n.aspectRatioLock,c=n.buttonConfirm;i.setValue(r.width),o.setValue(r.height),a.setValue(t.query("GET_SIZE_ASPECT_RATIO_LOCK")),c.opacity=0},RESIZE_SET_OUTPUT_SIZE:function(e){var t=e.root,r=e.action,n=t.ref,i=n.inputImageWidth,o=n.inputImageHeight;i.setValue(r.width),o.setValue(r.height)},CROP_SET_ASPECT_RATIO:function(e){var t=e.root,r=e.props,n=e.action,i=e.timestamp,o=t.query("GET_CROP",r.id,i);if(o){var a=o.cropStatus,c=t.ref,l=c.inputImageWidth,u=c.inputImageHeight;null!==n.value?(l.setValue(a.image.width),l.setPlaceholder(a.crop.width),u.setValue(a.image.height),u.setPlaceholder(a.crop.height)):l.getValue()&&u.getValue()&&(u.setValue(null),u.setPlaceholder(a.crop.height))}}},function(e){var t=e.root,r=e.props,n=e.timestamp,i=t.query("GET_CROP",r.id,n);if(i){t.opacity;var o=i.cropStatus,a=t.ref,c=a.inputImageWidth,l=a.inputImageHeight;if(!c.hasFocus()&&!l.hasFocus()){var u=t.query("GET_CROP_RECTANGLE_ASPECT_RATIO");if(null===c.getValue()&&null===l.getValue())c.setPlaceholder(o.crop.width),l.setPlaceholder(o.crop.height);else if(null===c.getValue()&&null!==o.image.height){var s=Math.round(o.image.height*u);c.setPlaceholder(s)}else if(null===l.getValue()&&null!==o.image.width){var d=Math.round(o.image.width/u);l.setPlaceholder(d)}}}})}),createFieldGroup=function(e,t){return createView({tag:"fieldset",create:function(r){var n=r.root,i=createElement("legend");i.textContent=e,n.element.appendChild(i),t({root:n})}})},resizeRoot=createView({name:"resize",ignoreRect:!0,mixins:{apis:["viewId","stagePosition","hidden"]},create:function(e){var t=e.root,r=e.props;r.viewId="resize",r.hidden=!1,t.ref.isHiding=!1,t.ref.form=t.appendChildView(t.createChildView(resizeForm,{opacity:0,id:r.id}))},read:function(e){var t=e.root,r=e.props;if(!r.hidden){var n=t.rect;if(0!==n.element.width&&0!==n.element.height){var i=t.ref.form.rect;r.stagePosition={x:n.element.left,y:n.element.top+i.element.height,width:n.element.width,height:n.element.height-i.element.height}}}},shouldUpdateChildViews:function(e){var t=e.props,r=e.actions;return!t.hidden||t.hidden&&r&&r.length},write:createRoute({SHOW_VIEW:function(e){var t=e.root,r=e.action,n=e.props;r.id===n.viewId?(t.ref.isHiding=!1,t.ref.form.opacity=1):(t.ref.isHiding=!0,t.ref.form.opacity=0)}},function(e){var t=e.root,r=e.props,n=t.ref,i=n.form,o=n.isHiding,a=r.hidden;o&&0===i.opacity&&!a?r.hidden=!0:r.hidden=!1})}),rangeInput=createView({name:"range-input",tag:"span",mixins:{listeners:!0,apis:["onUpdate","setValue","getValue","setAllowInteraction"]},create:function(e){var t=e.root,r=e.props,n=r.id,i=r.min,o=r.max,a=r.step,c=r.value,l=r.onUpdate,u=void 0===l?function(){}:l,s="doka--".concat(n,"-").concat(getUniqueId()),d=createElement("input",{type:"range",id:s,min:i,max:o,step:a});d.value=c,t.ref.input=d;var p=createElement("span");p.className="doka--range-input-inner";var f=createElement("label",{for:s});f.innerHTML=r.label;var h=i+.5*(o-i);t.element.dataset.centered=c===h,t.ref.handleRecenter=function(){r.setValue(h),t.ref.handleChange()};var g=createElement("button",{type:"button"});g.textContent="center",g.addEventListener("click",t.ref.handleRecenter),t.ref.recenter=g,p.appendChild(d),p.appendChild(g),t.appendChild(f),t.appendChild(p),t.ref.handleChange=function(){var e=r.getValue();t.element.dataset.centered=e===h,u(e)},d.addEventListener("input",t.ref.handleChange);var m=null;t.ref.dragger=createDragger(p,function(){m=d.getBoundingClientRect()},function(e){var r=(e.pageX-m.left)/m.width;d.value=i+r*(o-i),t.ref.handleChange()},function(){},{stopPropagation:!0}),r.getValue=function(){return parseFloat(d.value)},r.setValue=function(e){return d.value=e},r.setAllowInteraction=function(e){e?t.ref.dragger.enable():t.ref.dragger.disable()}},destroy:function(e){var t=e.root;t.ref.dragger.destroy(),t.ref.recenter.removeEventListener("click",t.ref.handleRecenter),t.ref.input.removeEventListener("input",t.ref.handleChange)}}),COLOR_TOOLS$1={brightness:{icon:createIcon('')},contrast:{icon:createIcon('')},exposure:{icon:createIcon('')},saturation:{icon:createIcon('')}},colorForm=createView({ignoreRect:!0,name:"color-form",tag:"form",mixins:{styles:["opacity"],animations:{opacity:{type:"spring",mass:15}}},create:function(e){var t=e.root;t.element.setAttribute("novalidate","novalidate");var r=t.query("GET_COLOR_VALUES");t.ref.tools=Object.keys(COLOR_TOOLS$1).reduce(function(e,n){var i=n,o=COLOR_TOOLS$1[n].icon,a=t.query("GET_LABEL_COLOR_".concat(n.toUpperCase())),c=t.query("GET_COLOR_".concat(n.toUpperCase(),"_RANGE")),l=r[n];return e[i]={view:t.appendChildView(t.createChildView(rangeInput,{id:i,label:"".concat(o,"").concat(a,""),min:c[0],max:c[1],step:.01,value:l,onUpdate:function(e){return t.dispatch("COLOR_SET_COLOR_VALUE",{key:i,value:e})}}))},e},{})},write:createRoute({COLOR_SET_VALUE:function(e){var t=e.root,r=e.action;t.ref.tools[r.key].view.setValue(r.value)},SHOW_VIEW:function(e){var t=e.root,r=e.action;Object.keys(t.ref.tools).forEach(function(e){t.ref.tools[e].view.setAllowInteraction("color"===r.id)})}})}),tilePreviewWorker=null,tilePreviewWorkerTerminationTimeout=null,updateColors=function(e,t){var r=t.brightness,n=t.exposure,i=t.contrast,o=t.saturation;if(0!==r){var a=r<0,c=a?"multiply":"overlay",l=a?0:255,u=a?Math.abs(r):1-r;e.ref.imageOverlay.style.cssText="mix-blend-mode: ".concat(c,"; background: rgba(").concat(l,",").concat(l,",").concat(l,",").concat(u,")")}return e.ref.imageOverlay.style.cssText="background:transparent",e.ref.image.style.cssText="filter: brightness(".concat(n,") contrast(").concat(i,") saturate(").concat(o,")"),t},colorKeys=Object.keys(COLOR_TOOLS$1),colorEquals=function(e,t){return colorKeys.findIndex(function(r){return e[r]!==t[r]})<0},createFilterTile=function(e){return createView({ignoreRect:!0,tag:"li",name:"filter-tile",mixins:{styles:["opacity","translateY"],animations:{translateY:{type:"spring",delay:10*e},opacity:{type:"spring",delay:30*e}}},create:function(e){var t=e.root,r=e.props,n="doka--filter-".concat(r.style,"-").concat(getUniqueId()),i=createElement("input",{id:n,type:"radio",name:"filter"});t.appendChild(i),i.checked=r.selected,i.value=r.style,i.addEventListener("change",function(){i.checked&&r.onSelect()});var o=createElement("label",{for:n});o.textContent=r.label,t.appendChild(o);var a=r.imageData,c=Math.min(a.width,a.height),l=c,u=createElement("canvas");u.width=c,u.height=l;var s=u.getContext("2d");t.ref.image=u;var d=createElement("div");t.ref.imageOverlay=d;var p={x:.5*c-.5*a.width,y:.5*l-.5*a.height},f=createElement("div");f.appendChild(u),f.appendChild(d),t.appendChild(f),t.ref.imageWrapper=f,r.matrix?(tilePreviewWorker||(tilePreviewWorker=createWorker(TransformWorker)),clearTimeout(tilePreviewWorkerTerminationTimeout),tilePreviewWorker.post({transforms:[{type:"filter",data:r.matrix}],imageData:a},function(e){s.putImageData(e,p.x,p.y),clearTimeout(tilePreviewWorkerTerminationTimeout),tilePreviewWorkerTerminationTimeout=setTimeout(function(){tilePreviewWorker.terminate(),tilePreviewWorker=null},1e3)},[a.data.buffer]),t.ref.activeColors=updateColors(t,t.query("GET_COLOR_VALUES"))):s.putImageData(a,p.x,p.y)},write:function(e){var t=e.root;if(!(t.opacity<=0)){var r=t.query("GET_COLOR_VALUES"),n=t.ref.activeColors;(!n&&r||!colorEquals(n,r))&&(t.ref.activeColors=r,updateColors(t,r))}}})},cloneImageData=function(e){var t;try{t=new ImageData(e.width,e.height)}catch(r){t=document.createElement("canvas").getContext("2d").createImageData(e.width,e.height)}return t.data.set(new Uint8ClampedArray(e.data)),t},arrayEqual=function(e,t){return Array.isArray(e)&&Array.isArray(t)&&e.length===t.length&&e.every(function(e,r){return e===t[r]})},filterList=createView({ignoreRect:!0,tag:"ul",name:"filter-list",mixins:{apis:["filterOpacity","hidden"]},create:function(e){var t=e.root,r=e.props;t.element.setAttribute("role","list"),t.ref.tiles=[];var n=t.query("GET_THUMB_IMAGE_DATA"),i=t.query("GET_FILTERS"),o=[];forin(i,function(e,t){o.push(_objectSpread({id:e},t))}),t.ref.activeFilter=t.query("GET_FILTER"),t.ref.tiles=o.map(function(e,i){var o=e.matrix(),a=t.ref.activeFilter===e.id||arrayEqual(t.ref.activeFilter,o)||0===i;return t.appendChildView(t.createChildView(createFilterTile(i),{opacity:0,translateY:-5,id:r.id,style:e.id,label:e.label,matrix:o,imageData:cloneImageData(n),selected:a,onSelect:function(){return t.dispatch("FILTER_SET_FILTER",{value:o?e.id:null})}}))})},write:function(e){var t=e.root,r=e.props;if(!r.hidden){var n=t.query("GET_FILTER");if(n!==t.ref.activeFilter){t.ref.activeFilter=n;var i=t.query("GET_FILTERS"),o=n?isString(n)?n:isColorMatrix(n)?Object.keys(i).find(function(e){return arrayEqual(i[e].matrix(),n)}):null:"original";Array.from(t.element.querySelectorAll("input")).forEach(function(e){return e.checked=e.value===o})}t.query("IS_ACTIVE_VIEW","filter")?t.ref.tiles.forEach(function(e){e.opacity=1,e.translateY=0}):t.ref.tiles.forEach(function(e){e.opacity=0,e.translateY=-5}),r.filterOpacity=t.ref.tiles.reduce(function(e,t){return e+t.opacity},0)/t.ref.tiles.length}}}),createScroller=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];return createView({name:"scroller doka--".concat(e,"-scroller"),ignoreRect:!0,ignoreRectUpdate:!0,mixins:{styles:["opacity"],animations:{opacity:{type:"spring"}},apis:r},create:function(e){var r,n=e.root,i=e.props;(n.ref.content=n.appendChildView(n.createChildView(t,{id:i.id})),n.element.isScrollContainer=!0,canHover())&&(n.ref.handleMouseWheel=function(e){var t=n.element.scrollLeft,r=n.ref.scrollWidth-n.rect.element.width,i=t+e.deltaX;(i<0||i>r)&&(n.element.scrollLeft=Math.min(Math.max(i,0),r),e.preventDefault())},n.element.addEventListener("mousewheel",n.ref.handleMouseWheel),n.element.dataset.dragState="end",n.ref.dragger=createDragger(n.ref.content.element,function(){n.element.dataset.dragState="start",r=n.element.scrollLeft},function(e,t){n.element.scrollLeft=r-t.x,n.ref.scrollWidth-n.rect.element.width!=0&&vectorDistanceSquared({x:0,y:0},t)>0&&(n.element.dataset.dragState="dragging")},function(){n.element.dataset.dragState="end"},{stopPropagation:!0}))},destroy:function(e){var t=e.root;t.ref.handleMouseWheel&&t.element.removeEventListener("mousewheel",t.ref.handleMouseWheel),t.ref.dragger&&t.ref.dragger.destroy()},read:function(e){var t=e.root;t.ref.scrollWidth=t.element.scrollWidth},write:function(e){var t=e.root,r=e.props;t.ref.content.hidden=r.hidden,r.contentOpacity=t.ref.content.contentOpacity}})},createSelectionView=function(e,t){return createView({name:e,ignoreRect:!0,mixins:{apis:["viewId","stagePosition","hidden"]},create:function(r){var n=r.root,i=r.props;i.viewId=e,i.hidden=!1,n.ref.isHiding=!1,n.ref.content=n.appendChildView(n.createChildView(createScroller(e,t,["hidden","contentOpacity"]),{id:i.id}))},read:function(e){var t=e.root,r=e.props;if(t.ref.content&&!r.hidden){var n=t.rect;if(0!==n.element.width&&0!==n.element.height){var i=t.ref.content.rect,o=0===i.element.top,a=o?n.element.top+i.element.height+i.element.marginBottom:n.element.top,c=o?n.element.height-i.element.height-i.element.marginBottom:n.element.height-i.element.height-n.element.top;r.stagePosition={x:n.element.left,y:a,width:n.element.width,height:c}}}},shouldUpdateChildViews:function(e){var t=e.props,r=e.actions;return!t.hidden||t.hidden&&r&&r.length},write:createRoute({SHOW_VIEW:function(e){var t=e.root,r=e.action,n=e.props;t.ref.content&&(r.id===n.viewId?(t.ref.isHiding=!1,n.hidden=!1,t.ref.content.hidden=!1):t.ref.isHiding=!0)}},function(e){var t=e.root,r=e.props;t.ref.content.opacity=t.ref.isHiding||t.ref.content.hidden?0:1,t.ref.isHiding&&t.ref.content.contentOpacity<=0&&(t.ref.isHiding=!1,r.hidden=!0,t.ref.content.hidden=!0)})})},filterRoot=createSelectionView("filter",filterList),colorRoot=createView({name:"color",ignoreRect:!0,mixins:{apis:["viewId","stagePosition","hidden"]},create:function(e){var t=e.root,r=e.props;r.viewId="color",r.hidden=!1,t.ref.isHiding=!1,t.ref.form=t.appendChildView(t.createChildView(colorForm,{opacity:0,id:r.id}))},read:function(e){var t=e.root,r=e.props;if(!r.hidden){var n=t.rect;if(0!==n.element.width&&0!==n.element.height){var i=t.ref.form.rect,o=i.element.height,a=0===i.element.top,c=a?n.element.top+o:n.element.top,l=a?n.element.height-o:n.element.height-o-n.element.top;r.stagePosition={x:n.element.left,y:c,width:n.element.width,height:l}}}},shouldUpdateChildViews:function(e){var t=e.props,r=e.actions;return!t.hidden||t.hidden&&r&&r.length},write:createRoute({SHOW_VIEW:function(e){var t=e.root,r=e.action,n=e.props;r.id===n.viewId?(t.ref.isHiding=!1,t.ref.form.opacity=1,n.hidden=!1):(t.ref.isHiding=!0,t.ref.form.opacity=0)}},function(e){var t=e.root,r=e.props;t.ref.isHiding&&0===t.ref.form.opacity&&(t.ref.isHiding=!1,r.hidden=!0)})}),supportsColorPicker=function(){try{var e=createElement("input",{type:"color"}),t="color"===e.type;return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)?t:t&&"number"!=typeof e.selectionStart}catch(e){return!1}},toHSL=function(e,t,r){var n,i=Math.max(e,t,r),o=Math.min(e,t,r),a=i-o,c=0===i?0:a/i,l=i/255;switch(i){case o:n=0;break;case e:n=t-r+a*(t