@sketch-hq/sketch-web-renderer 6.2.0 → 6.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/module-debug.wasm +0 -0
  3. package/dist/{module-release-98b4d357.js → module-release-75cbbdeb.js} +1 -1
  4. package/dist/{module-release-a5595310.js → module-release-a16ef8da.js} +1 -1
  5. package/dist/module-release.wasm +0 -0
  6. package/dist/ts/canvas-renderer/CanvasRenderer.d.ts.map +1 -1
  7. package/dist/ts/canvas-renderer/react/CanvasRendererProvider.d.ts.map +1 -1
  8. package/dist/ts/canvas-renderer/react/contexts.d.ts +1 -1
  9. package/dist/ts/canvas-renderer/react/contexts.d.ts.map +1 -1
  10. package/dist/ts/canvas-renderer/react/hooks/state.d.ts +1 -1
  11. package/dist/ts/canvas-renderer/react/hooks/state.d.ts.map +1 -1
  12. package/dist/ts/canvas-renderer/react/types.d.ts +2 -2
  13. package/dist/ts/canvas-renderer/react/types.d.ts.map +1 -1
  14. package/dist/ts/prototype-renderer/PrototypeRenderer.d.ts.map +1 -1
  15. package/dist/ts/prototype-renderer/react/PrototypeRendererProvider.d.ts.map +1 -1
  16. package/dist/ts/prototype-renderer/react/contexts.d.ts +1 -1
  17. package/dist/ts/prototype-renderer/react/contexts.d.ts.map +1 -1
  18. package/dist/ts/prototype-renderer/react/hooks/state.d.ts +1 -1
  19. package/dist/ts/prototype-renderer/react/hooks/state.d.ts.map +1 -1
  20. package/dist/ts/prototype-renderer/react/types.d.ts +2 -2
  21. package/dist/ts/prototype-renderer/react/types.d.ts.map +1 -1
  22. package/dist/ts/types/PresentationManifest.d.ts +25 -16
  23. package/dist/ts/types/PresentationManifest.d.ts.map +1 -1
  24. package/dist/ts/types/Status.d.ts +3 -1
  25. package/dist/ts/types/Status.d.ts.map +1 -1
  26. package/dist/ts/types/wasm/Emscripten.d.ts +1 -0
  27. package/dist/ts/types/wasm/Emscripten.d.ts.map +1 -1
  28. package/dist/ts/types/wasm/WasmModule.d.ts +4 -3
  29. package/dist/ts/types/wasm/WasmModule.d.ts.map +1 -1
  30. package/dist/ts/utils/WasmModule.d.ts.map +1 -1
  31. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import t,{createContext as e,useContext as n,useRef as o,useReducer as r,useCallback as i,useMemo as a,useEffect as s,useState as u}from"react";var c=function(t,e){return c=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},c(t,e)};function l(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}c(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var d=function(){return d=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},d.apply(this,arguments)};function h(t,e,n,o){return new(n||(n=Promise))((function(r,i){function a(t){try{u(o.next(t))}catch(t){i(t)}}function s(t){try{u(o.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((o=o.apply(t,e||[])).next())}))}function p(t,e){var n,o,r,i,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,o&&(r=2&s[0]?o.return:s[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,s[1])).done)return r;switch(o=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,o=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){a.label=s[1];break}if(6===s[0]&&a.label<r[1]){a.label=r[1],r=s;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(s);break}r[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],o=0}finally{n=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}function v(t,e,n){if(n||2===arguments.length)for(var o,r=0,i=e.length;r<i;r++)!o&&r in e||(o||(o=Array.prototype.slice.call(e,0,r)),o[r]=e[r]);return t.concat(o||Array.prototype.slice.call(e))}function f(t,e,n,o){return new(n||(n=Promise))((function(r,i){function a(t){try{u(o.next(t))}catch(t){i(t)}}function s(t){try{u(o.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((o=o.apply(t,e||[])).next())}))}const g=["geforce 320m","geforce 8600","geforce 8600m gt","geforce 8800 gs","geforce 8800 gt","geforce 9400","geforce 9400m g","geforce 9400m","geforce 9600m gt","geforce 9600m","geforce fx go5200","geforce gt 120","geforce gt 130","geforce gt 330m","geforce gtx 285","google swiftshader","intel g41","intel g45","intel gma 4500mhd","intel gma x3100","intel hd 3000","intel q45","legacy","mali-2","mali-3","mali-4","quadro fx 1500","quadro fx 4","quadro fx 5","radeon hd 2400","radeon hd 2600","radeon hd 4670","radeon hd 4850","radeon hd 4870","radeon hd 5670","radeon hd 5750","radeon hd 6290","radeon hd 6300","radeon hd 6310","radeon hd 6320","radeon hd 6490m","radeon hd 6630m","radeon hd 6750m","radeon hd 6770m","radeon hd 6970m","sgx 543","sgx543"];function m(t){return t.toLowerCase().replace(/.*angle ?\((.+)\)(?: on vulkan [0-9.]+)?$/i,"$1").replace(/\s(\d{1,2}gb|direct3d.+$)|\(r\)| \([^)]+\)$/g,"").replace(/(?:vulkan|opengl) \d+\.\d+(?:\.\d+)?(?: \((.*)\))?/,"$1")}const y="undefined"==typeof window,C=(()=>{if(y)return;const{userAgent:t,platform:e,maxTouchPoints:n}=window.navigator,o=/(iphone|ipod|ipad)/i.test(t),r="iPad"===e||"MacIntel"===e&&n>0&&!window.MSStream;return{isIpad:r,isMobile:/android/i.test(t)||o||r,isSafari12:/Version\/12.+Safari/.test(t)}})();class w extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype)}}const b=[],P=[];function M(t,e){if(t===e)return 0;const n=t;t.length>e.length&&(t=e,e=n);let o=t.length,r=e.length;for(;o>0&&t.charCodeAt(~-o)===e.charCodeAt(~-r);)o--,r--;let i,a=0;for(;a<o&&t.charCodeAt(a)===e.charCodeAt(a);)a++;if(o-=a,r-=a,0===o)return r;let s,u,c=0,l=0,d=0;for(;l<o;)P[l]=t.charCodeAt(a+l),b[l]=++l;for(;d<r;)for(i=e.charCodeAt(a+d),s=d++,c=d,l=0;l<o;l++)u=i===P[l]?s:s+1,s=b[l],c=b[l]=s>c?u>c?c+1:u:u>s?s+1:u;return c}function E(t){return null!=t}const L=({mobileTiers:t=[0,15,30,60],desktopTiers:e=[0,15,30,60],override:n={},glContext:o,failIfMajorPerformanceCaveat:r=!1,benchmarksURL:i="https://unpkg.com/detect-gpu@5.0.12/dist/benchmarks"}={})=>f(void 0,void 0,void 0,(function*(){const a={};if(y)return{tier:0,type:"SSR"};const{isIpad:s=!!(null==C?void 0:C.isIpad),isMobile:u=!!(null==C?void 0:C.isMobile),screenSize:c=window.screen,loadBenchmarks:l=(t=>f(void 0,void 0,void 0,(function*(){const e=yield fetch(`${i}/${t}`).then((t=>t.json()));if(parseInt(e.shift().split(".")[0],10)<4)throw new w("Detect GPU benchmark data is out of date. Please update to version 4x");return e})))}=n;let{renderer:d}=n;const h=(t,e,n,o,r)=>({device:r,fps:o,gpu:n,isMobile:u,tier:t,type:e});let p,v="";if(d)d=m(d),p=[d];else{const t=o||function(t,e=!1){const n={alpha:!1,antialias:!1,depth:!1,failIfMajorPerformanceCaveat:e,powerPreference:"high-performance",stencil:!1};t&&delete n.powerPreference;const o=window.document.createElement("canvas"),r=o.getContext("webgl",n)||o.getContext("experimental-webgl",n);return null!=r?r:void 0}(null==C?void 0:C.isSafari12,r);if(!t)return h(0,"WEBGL_UNSUPPORTED");const e=t.getExtension("WEBGL_debug_renderer_info");if(e&&(d=t.getParameter(e.UNMASKED_RENDERER_WEBGL)),!d)return h(1,"FALLBACK");v=d,d=m(d),p=function(t,e,n){return"apple gpu"===e?function(t,e,n){if(!n)return[e];const o=function(t){const e=t.createShader(35633),n=t.createShader(35632),o=t.createProgram();if(!(n&&e&&o))return;t.shaderSource(e,"\n precision highp float;\n attribute vec3 aPosition;\n varying float vvv;\n void main() {\n vvv = 0.31622776601683794;\n gl_Position = vec4(aPosition, 1.0);\n }\n "),t.shaderSource(n,"\n precision highp float;\n varying float vvv;\n void main() {\n vec4 enc = vec4(1.0, 255.0, 65025.0, 16581375.0) * vvv;\n enc = fract(enc);\n enc -= enc.yzww * vec4(1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0, 0.0);\n gl_FragColor = enc;\n }\n "),t.compileShader(e),t.compileShader(n),t.attachShader(o,e),t.attachShader(o,n),t.linkProgram(o),t.detachShader(o,e),t.detachShader(o,n),t.deleteShader(e),t.deleteShader(n),t.useProgram(o);const r=t.createBuffer();t.bindBuffer(34962,r),t.bufferData(34962,new Float32Array([-1,-1,0,3,-1,0,-1,3,0]),35044);const i=t.getAttribLocation(o,"aPosition");t.vertexAttribPointer(i,3,5126,!1,0,0),t.enableVertexAttribArray(i),t.clearColor(1,1,1,1),t.clear(16384),t.viewport(0,0,1,1),t.drawArrays(4,0,3);const a=new Uint8Array(4);return t.readPixels(0,0,1,1,6408,5121,a),t.deleteProgram(o),t.deleteBuffer(r),a.join("")}(t),r="801621810",i="8016218135",a="80162181161",s=(null==C?void 0:C.isIpad)?[["a7",a,12],["a8",i,15],["a8x",i,15],["a9",i,15],["a9x",i,15],["a10",i,15],["a10x",i,15],["a12",r,15],["a12x",r,15],["a12z",r,15],["a14",r,15],["m1",r,15]]:[["a7",a,12],["a8",i,12],["a9",i,15],["a10",i,15],["a11",r,15],["a12",r,15],["a13",r,15],["a14",r,15]];let u;return"80162181255"===o?u=s.filter((([,,t])=>t>=14)):(u=s.filter((([,t])=>t===o)),u.length||(u=s)),u.map((([t])=>`apple ${t} gpu`))}(t,e,n):[e]}(t,d,u)}const b=(yield Promise.all(p.map((function(t){var e;return f(this,void 0,void 0,(function*(){const n=(t=>{const e=u?["adreno","apple","mali-t","mali","nvidia","powervr","samsung"]:["intel","apple","amd","radeon","nvidia","geforce"];for(const n of e)if(t.includes(n))return n})(t);if(!n)return;const o=`${u?"m":"d"}-${n}${s?"-ipad":""}.json`,r=a[o]=null!==(e=a[o])&&void 0!==e?e:l(o);let i;try{i=yield r}catch(n){if(n instanceof w)throw n;return}const d=function(t){var e;const n=(t=t.replace(/\([^)]+\)/,"")).match(/\d+/)||t.match(/(\W|^)([A-Za-z]{1,3})(\W|$)/g);return null!==(e=null==n?void 0:n.join("").replace(/\W|amd/g,""))&&void 0!==e?e:""}(t);let h=i.filter((([,t])=>t===d));h.length||(h=i.filter((([e])=>e.includes(t))));const p=h.length;if(0===p)return;const v=t.split(/[.,()\[\]/\s]/g).sort().filter(((t,e,n)=>0===e||t!==n[e-1])).join(" ");let f,[g,,,,m]=p>1?h.map((t=>[t,M(v,t[2])])).sort((([,t],[,e])=>t-e))[0][0]:h[0],y=Number.MAX_VALUE;const{devicePixelRatio:C}=window,b=c.width*C*c.height*C;for(const t of m){const[e,n]=t,o=e*n,r=Math.abs(b-o);r<y&&(y=r,f=t)}if(!f)return;const[,,P,E]=f;return[y,P,g,E]}))})))).filter(E).sort((([t=Number.MAX_VALUE,e],[n=Number.MAX_VALUE,o])=>t===n?e-o:t-n));if(!b.length){const t=g.find((t=>d.includes(t)));return t?h(0,"BLOCKLISTED",t):h(1,"FALLBACK",`${d} (${v})`)}const[,P,L,R]=b[0];if(-1===P)return h(0,"BLOCKLISTED",L,P,R);const W=u?t:e;let x=0;for(let t=0;t<W.length;t++)P>=W[t]&&(x=t);return h(x,"BENCHMARK",L,P,R)}));var R,W=function(t){function e(n,o,r){var i=this.constructor,a=t.call(this,"(".concat(n,") ").concat(o))||this;return a.code=n,a.cause=r,a.name=e.name,Object.setPrototypeOf(a,i.prototype),a}return l(e,t),e}(Error);!function(t){t.debug="debug",t.release="release"}(R||(R={}));var x=function(){function t(){this.listeners={}}return t.prototype.on=function(t,e){var n,o;this.listeners[t]=null!==(n=this.listeners[t])&&void 0!==n?n:new Set,null===(o=this.listeners[t])||void 0===o||o.add(e)},t.prototype.off=function(t,e){var n;null===(n=this.listeners[t])||void 0===n||n.delete(e)},t.prototype.forwardEvent=function(t,e){this.on(e,(function(){for(var n=[],o=0;o<arguments.length;o++)n[o]=arguments[o];t.emit.apply(t,v([e],n,!1))}))},t.prototype.emit=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var o=this.listeners[t];(null==o?void 0:o.size)&&o.forEach((function(t){Promise.resolve().then((function(){t.apply(void 0,e)}))}))},t.prototype.detachAllListeners=function(){this.listeners={}},t}(),S=function(){function t(){this.removeListenerCallbacks=[]}return t.prototype.add=function(t,e,n,o){t.addEventListener(e,n,o);var r=function(){t.removeEventListener(e,n,o)};return this.removeListenerCallbacks.push(r),r},t.prototype.dispose=function(){this.removeListenerCallbacks.forEach((function(t){return t()}))},t}(),I={delayedDraw:!0,offscreenCanvas:!1,useDirtyRectsRendering:!0,safariWebGL2:!1,pageBoundariesLimit:!1},T=function(t){return parseFloat((""+(/CPU.*OS ([0-9_]{1,5})|(CPU like).*AppleWebKit.*Mobile/i.exec(t)||[0,""])[1]).replace("undefined","3_2").replace("_",".").replace("_",""))||!1},D=/(iPhone|Macintosh|iPad)(.*)(Version)\/(0|[1-9]\d*)\.(0|[1-9]\d*)\.?(0|[1-9]\d*)?/,k=function(t){if(void 0===t&&(t=window.navigator.userAgent),t.includes("Chrome/")||t.includes("Chromium/")||t.includes("Opera/")||t.includes("Firefox/"))return null;var e=t.match(D);if(!e)return null;var n=e[1];return"Macintosh"!==n&&"iPad"!==n&&"iPhone"!==n?null:{hardware:n,version:{major:parseInt(e[4])||0,minor:parseInt(e[5])||0,patch:parseInt(e[6])||0}}};function F(t,e){var n;function o(){for(var o=[],r=0;r<arguments.length;r++)o[r]=arguments[r];clearTimeout(n),n=setTimeout((function(){t.apply(void 0,o)}),e)}return o.cancel=function(){n&&clearTimeout(n)},o}function U(t){var e,n,o,r,i,a=null!==(n=null===(e=t.touches)||void 0===e?void 0:e[0])&&void 0!==n?n:null===(o=t.changedTouches)||void 0===o?void 0:o[0];return{x:null!==(r=null==a?void 0:a.clientX)&&void 0!==r?r:t.clientX,y:null!==(i=null==a?void 0:a.clientY)&&void 0!==i?i:t.clientY}}function A(t,e,n){return Math.max(e,Math.min(n,t))}function B(){return k()&&!I.safariWebGL2?1:"undefined"!=typeof WebGL2RenderingContext?2:1}function G(t){for(var e=t.size(),n=[],o=0;o<e;++o){var r=t.get(o);if(null==r)throw Error("Error converting embind vector to array");n.push(r)}return n}function Z(){return"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0}function z(t){var e=t;return Object.keys(e).forEach((function(t){void 0===e[t]&&delete e[t]})),e}function O(t){return Z()?{onTouchEnd:t}:{onClick:t}}var _=function(t){function e(e){var n=t.call(this)||this;return n.listenersCollector=new S,n.state={pinchToZoomLastDistance:0,lastGestureScale:1,isCtrlPressed:!1},n.handleGestureStart=function(t){t.preventDefault(),n.state.lastGestureScale=t.scale},n.handleGestureChange=function(t){t.preventDefault();var e=t.scale/n.state.lastGestureScale;n.state.lastGestureScale=t.scale;var o=n.getCorrectPointerPosition(t);n.emitZoomEvent(e,o)},n.handleGestureEnd=function(t){t.preventDefault()},n.handleTouchStart=function(t){t.preventDefault(),n.handleTouchPinchToZoomStart(t),n.emit("pointerdown",{type:"touch",position:n.getCorrectPointerPosition(t),button:0,touchesCount:t.touches.length})},n.handleMouseDown=function(t){t.ctrlKey||(t.preventDefault(),n.emit("pointerdown",{type:"mouse",position:n.getCorrectPointerPosition(t),button:t.button,touchesCount:0}))},n.handleTouchMove=function(t){n.handleTouchPinchToZoomChange(t),n.emit("pointermove",{type:"touch",position:n.getCorrectPointerPosition(t),button:0,touchesCount:t.touches.length})},n.handleMouseMove=function(t){n.updateMousePosition(t)},n.handleGlobalTouchMove=function(t){n.emit("globalpointermove",{type:"touch",position:n.getCorrectPointerPosition(t),button:0,touchesCount:t.touches.length})},n.handleGlobalMouseMove=function(t){n.updateGlobalMousePosition(t)},n.handleTouchPinchToZoomStart=function(t){var e;!t.touches||(null===(e=t.touches)||void 0===e?void 0:e.length)<2||(n.state.pinchToZoomLastDistance=n.calculateDistanceBetweenTouches(t.touches[0],t.touches[1]))},n.handleTouchPinchToZoomChange=function(t){var e;if(t.touches&&!((null===(e=t.touches)||void 0===e?void 0:e.length)<2)){var o=n.calculateDistanceBetweenTouches(t.touches[0],t.touches[1]),r=n.getCorrectPointerPosition(t),i=1+.004*(o-n.state.pinchToZoomLastDistance);n.state.pinchToZoomLastDistance=o,n.emitZoomEvent(i,r)}},n.handleTouchEnd=function(t){var e=n.getCorrectPointerPosition(t);n.emit("pointerup",{position:e,type:"touch",button:0,touchesCount:t.touches.length})},n.handleMouseUp=function(t){n.emit("pointerup",{type:"mouse",position:n.getCorrectPointerPosition(t),button:t.button,touchesCount:0})},n.handleMouseWheel=function(t){t.preventDefault();var e=t.ctrlKey&&!n.state.isCtrlPressed,o=t.metaKey||e||n.state.isCtrlPressed;if(n.updateMousePosition(t),n.updateGlobalMousePosition(t),o){var r=e?-1:1,i=n.getCorrectPointerPosition(t),a=1+.005*t.deltaY*r;n.emitZoomEvent(a,i)}else n.emit("wheel",{x:-t.deltaX,y:-t.deltaY},{type:"mouse",position:n.getCorrectPointerPosition(t),button:t.button,touchesCount:0})},n.target=e,n.targetBounds=e.getBoundingClientRect(),n.addListeners(),n}return l(e,t),e.prototype.updateTargetBounds=function(){this.targetBounds=this.target.getBoundingClientRect()},e.prototype.addListeners=function(){this.addTouchEventListeners(),this.addMouseEventListeners(),this.addKeyboardEventListeners(),this.addSafariGesturesEventListeners()},e.prototype.addKeyboardEventListeners=function(){var t=this;this.listenersCollector.add(document,"keydown",(function(e){"Control"===e.key&&(t.state.isCtrlPressed=!0)})),this.listenersCollector.add(document,"keyup",(function(e){"Control"===e.key&&(t.state.isCtrlPressed=!1)})),this.listenersCollector.add(document,"contextmenu",(function(e){e.ctrlKey&&(t.state.isCtrlPressed=!1)}))},e.prototype.addMouseEventListeners=function(){this.listenersCollector.add(this.target,"mousedown",this.handleMouseDown),this.listenersCollector.add(this.target,"mousemove",this.handleMouseMove),this.listenersCollector.add(document,"mousemove",this.handleGlobalMouseMove),this.listenersCollector.add(document,"mouseup",this.handleMouseUp),this.listenersCollector.add(this.target,"wheel",this.handleMouseWheel)},e.prototype.addTouchEventListeners=function(){this.listenersCollector.add(this.target,"touchstart",this.handleTouchStart),this.listenersCollector.add(document,"touchmove",this.handleGlobalTouchMove,{passive:!0,capture:!0}),this.listenersCollector.add(this.target,"touchmove",this.handleTouchMove,{passive:!0,capture:!0}),this.listenersCollector.add(document,"touchcancel",this.handleTouchEnd),this.listenersCollector.add(document,"touchend",this.handleTouchEnd)},e.prototype.addSafariGesturesEventListeners=function(){Z()||(this.listenersCollector.add(this.target,"gesturestart",this.handleGestureStart,{capture:!0}),this.listenersCollector.add(this.target,"gesturechange",this.handleGestureChange,{capture:!0}),this.listenersCollector.add(this.target,"gestureend",this.handleGestureEnd,{capture:!0}))},e.prototype.clampPointerToTargetBounds=function(t){return{x:A(t.x-this.targetBounds.x,0,this.target.clientWidth),y:A(t.y-this.targetBounds.y,0,this.target.clientHeight)}},e.prototype.getCorrectPointerPosition=function(t){var e,n={x:0,y:0};if((null===(e=t.touches)||void 0===e?void 0:e.length)>1){var o=t,r=o.touches[0],i=o.touches[1];n={x:(r.clientX+i.clientX)/2,y:(r.clientY+i.clientY)/2}}else n=U(t);return this.clampPointerToTargetBounds(n)},e.prototype.updateMousePosition=function(t){this.emit("pointermove",{type:"mouse",position:this.getCorrectPointerPosition(t),button:t.button,touchesCount:0})},e.prototype.updateGlobalMousePosition=function(t){this.emit("globalpointermove",{type:"mouse",position:this.getCorrectPointerPosition(t),button:t.button,touchesCount:0})},e.prototype.calculateDistanceBetweenTouches=function(t,e){return Math.hypot(t.clientX-e.clientX,t.clientY-e.clientY)},e.prototype.emitZoomEvent=function(t,e){this.emit("pinchToZoom",t,e)},e.prototype.dispose=function(){this.listenersCollector.dispose()},e}(x),j=function(t){function e(e){var n=t.call(this)||this;return n.listenersCollector=new S,n.handleKeyUp=function(t){n.emit("keyUp",t.code)},n.target=e,n.addListeners(),n}return l(e,t),e.prototype.addListeners=function(){this.listenersCollector.add(this.target,"keyup",this.handleKeyUp)},e.prototype.dispose=function(){this.listenersCollector.dispose()},e}(x),N=function(){function t(t){this.label=t,this.startTime=performance.now(),this.startTimestamp=Date.now()}return t.prototype.measure=function(){return{duration:performance.now()-this.startTime,end:Date.now(),start:this.startTimestamp,id:this.label}},t.prototype.printMeasurement=function(){var t=this.measure().duration;if(t<1e3){var e=t.toFixed(2);return"[Performance] ".concat(this.label," -> ").concat(e," ms")}var n=(t/1e3).toFixed(2);return"[Performance] ".concat(this.label," -> ").concat(n," s")},t}();function K(t){setTimeout((function(){t()}),0)}var $=new(function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return l(e,t),e.prototype.logDebug=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.emit.apply(this,v(["log","debug"],t,!1))},e.prototype.logWarning=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.emit.apply(this,v(["log","warn"],t,!1))},e.prototype.logError=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.emit.apply(this,v(["log","error"],t,!1))},e}(x)),V=function(t){function e(e){var n=t.call(this)||this;return n.listenersCollector=new S,n.size={width:0,height:0},n.pixelRatio=1,n.handleCanvasResizeObserver=function(t){n.resizeCanvas(t[0].contentRect)},n.resizeCanvas=function(t){var e=t.width,o=t.height;window.requestAnimationFrame((function(){n.setSize(e,o),n.emit("resize",e,o,n.getDevicePixelRatio())}))},n.getCanvasCenterPoint=function(){var t=n.getBoundingClientRect();return{x:t.width/2+t.x,y:t.height/2+t.y}},n.container=e.container,n.canvas=e.canvas,n.canvasResizeObserver=new ResizeObserver(n.handleCanvasResizeObserver),n.canvasResizeObserver.observe(n.container),n.listenersCollector.add(window,"orientationchange",n.handleDeviceOrientationChange),n.setSize(n.container.clientWidth,n.container.clientHeight),n}return l(e,t),e.prototype.setSize=function(t,e){this.pixelRatio=this.getDevicePixelRatio(),this.canvas.style.width="".concat(t,"px"),this.canvas.style.height="".concat(e,"px"),this.size.width=t*this.pixelRatio,this.size.height=e*this.pixelRatio,this.canvas.width=this.size.width,this.canvas.height=this.size.height},e.prototype.handleDeviceOrientationChange=function(){this.resizeCanvas({width:this.container.clientWidth,height:this.container.clientHeight})},e.prototype.getDevicePixelRatio=function(){return A(window.devicePixelRatio,1,2)},e.prototype.getBoundingClientRect=function(){return this.canvas.getBoundingClientRect()},e.prototype.dispose=function(){this.detachAllListeners(),this.canvasResizeObserver.disconnect(),this.listenersCollector.dispose()},e}(x),Y=function(){function t(t){this.settings=t}return t.prototype.isReleaseMode=function(){return this.settings.mode===R.release},t.prototype.init=function(){return h(this,void 0,void 0,(function(){var t,e,n,o,r,i=this;return p(this,(function(a){switch(a.label){case 0:return[4,this.importModule()];case 1:t=a.sent(),e=t.default,a.label=2;case 2:return a.trys.push([2,4,,5]),n=this,[4,e({FeatureFlags:this.settings.featureFlags,currentWebGLVersion:B(),bridge:this.settings.jsBridge,locateFile:function(t){return i.settings.locateFile.replace("{file}",t)}})];case 3:return n.instance=a.sent(),[3,5];case 4:throw o=a.sent(),new W("WASM_ERROR","An error occurred while trying to create the wasm module.",o);case 5:return this.pointerTypeToWASMMap={unset:this.instance.PRUserPointerType.Unset,mouse:this.instance.PRUserPointerType.Mouse,touch:this.instance.PRUserPointerType.Touch},this.prCursorTypeToCSSCursorMap=((r={})[this.instance.PRCursorType.Auto.value]="auto",r[this.instance.PRCursorType.Default.value]="default",r[this.instance.PRCursorType.Pointer.value]="pointer",r[this.instance.PRCursorType.Grab.value]="grab",r[this.instance.PRCursorType.Grabbing.value]="grabbing",r),[2]}}))}))},t.prototype.makeWebGLContext=function(t,e){void 0===e&&(e={});var n=d({antialias:!1,alpha:!1,stencil:!1,depth:!1,powerPreference:"high-performance",preserveDrawingBuffer:!1,desynchronized:!0},e),o=this.instance.GL.createContext(t,n);if(!o)throw new W("WEBGL_ERROR","Unable to create WebGL context. WebGL might be unsupported, disabled, or this device is not able to run WebGL correctly.");return o},t.prototype.destroyWebGLContext=function(t){var e,n=null===(e=this.instance)||void 0===e?void 0:e.GL.getContext(t);if(n){var o=n.GLctx.getExtension("WEBGL_lose_context");if(o)return o.loseContext(),!0}},t.prototype.importModule=function(){return this.isReleaseMode()?import("./module-release-98b4d357.js"):import("./module-debug-ef74ce0a.js")},t.prototype.mapToCSSCursor=function(t){return this.prCursorTypeToCSSCursorMap[t.value]},t.prototype.mapToPRPointerType=function(t){var e;return null!==(e=this.pointerTypeToWASMMap[t])&&void 0!==e?e:this.instance.PRUserPointerType.Unset},t.prototype.mapPointerInfo=function(t){return d(d({},t),{type:this.mapToPRPointerType(t.type)})},t}(),H=function(t){function e(e){var n=t.call(this)||this;return n.status={type:"INIT"},n.disposed=!1,n.handleCanvasResize=function(t,e,o){var r;null===(r=n.pageCanvasWasm)||void 0===r||r.resize(t,e,o)},n.handleWebGLContextLost=function(){n.setStatus({type:"WEBGL_CONTEXT_LOST"})},n.handlePinchToZoomEvent=function(t,e){var o;null===(o=n.userEventsCollectorWasm)||void 0===o||o.dispatchPinchToZoomEvent(t,e.x,e.y)},n.handleWheelEvent=function(t,e){var o;n.wasmModule&&(null===(o=n.userEventsCollectorWasm)||void 0===o||o.dispatchWheelEvent(t.x,t.y,n.wasmModule.mapPointerInfo(e)))},n.handlePointerDownEvent=function(t){var e;n.wasmModule&&(null===(e=n.userEventsCollectorWasm)||void 0===e||e.dispatchPointerDownEvent(n.wasmModule.mapPointerInfo(t)))},n.handlePointerMoveEvent=function(t){var e;n.wasmModule&&(null===(e=n.userEventsCollectorWasm)||void 0===e||e.dispatchPointerMoveEvent(n.wasmModule.mapPointerInfo(t)))},n.handleGlobalPointerMoveEvent=function(t){var e;n.wasmModule&&(null===(e=n.userEventsCollectorWasm)||void 0===e||e.dispatchGlobalPointerMoveEvent(n.wasmModule.mapPointerInfo(t)))},n.handlePointerUpEvent=function(t){var e;n.wasmModule&&(null===(e=n.userEventsCollectorWasm)||void 0===e||e.dispatchPointerUpEvent(n.wasmModule.mapPointerInfo(t)))},n.settings=d(d({backgroundColor:{r:1,g:1,b:1,a:1},showTilesBorders:!1,preserveDrawingBuffer:!1,panBoundariesPadding:0},z(e)),{featureFlags:d(d({},I),e.featureFlags)}),n.gestureManager=new _(n.settings.container),n.canvasManager=new V({container:n.settings.container,canvas:n.settings.canvas}),n.wasmModule=new Y({mode:n.settings.mode,locateFile:n.settings.locateFile,jsBridge:n.createJSBridge(),featureFlags:n.settings.featureFlags}),n.fetchWorker=new Worker(n.settings.locateFile.replace("{file}","fetch-worker.js")),n.settings.manualInitialization||n.init(),n}return l(e,t),e.prototype.addListeners=function(){this.canvasManager.on("resize",this.handleCanvasResize),this.gestureManager.on("wheel",this.handleWheelEvent),this.gestureManager.on("pointerup",this.handlePointerUpEvent),this.gestureManager.on("pointermove",this.handlePointerMoveEvent),this.gestureManager.on("globalpointermove",this.handleGlobalPointerMoveEvent),this.gestureManager.on("pointerdown",this.handlePointerDownEvent),this.gestureManager.on("pinchToZoom",this.handlePinchToZoomEvent),this.settings.canvas.addEventListener("webglcontextlost",this.handleWebGLContextLost)},e.prototype.collectAndEmitDeviceInfo=function(){return h(this,void 0,void 0,(function(){var t;return p(this,(function(e){switch(e.label){case 0:return[4,L()];case 1:return t=e.sent(),this.deviceInfo=d(d({},t),{hardwareConcurrency:navigator.hardwareConcurrency}),this.emit("deviceInfo",this.deviceInfo),[2]}}))}))},e.prototype.init=function(){return h(this,void 0,void 0,(function(){var t;return p(this,(function(e){switch(e.label){case 0:this.traceFirstPaint=new N("FirstPaint"),this.setStatus({type:"INIT"}),this.collectAndEmitDeviceInfo(),e.label=1;case 1:return e.trys.push([1,5,,6]),[4,this.initWasmModule()];case 2:return e.sent(),[4,this.initCanvasRendererWasm()];case 3:return e.sent(),[4,this.setFile(this.settings.filePath)];case 4:return e.sent(),[3,6];case 5:return t=e.sent(),[2,this.fail(t instanceof W?t:new W("ERROR","Unexpected exception initializing the web renderer",t))];case 6:return this.setInitialCameraState(),this.startRendering(),this.addListeners(),[2]}}))}))},e.prototype.setInitialCameraState=function(){var t,e,n,o=void 0!==this.settings.initialZoom,r=void 0!==this.settings.initialPan;o||r?(o&&this.setZoom(this.settings.initialZoom||1),r&&this.setPan((null===(t=this.settings.initialPan)||void 0===t?void 0:t.x)||0,(null===(e=this.settings.initialPan)||void 0===e?void 0:e.y)||0,null===(n=this.settings.initialPan)||void 0===n?void 0:n.centerPointInViewport)):this.zoomToFit()},e.prototype.startRendering=function(){var t;this.traceInitialRender=new N("InitialRender"),this.setStatus({type:"DRAWING_FILE"}),null===(t=this.pageCanvasWasm)||void 0===t||t.startRenderLoop()},e.prototype.createJSBridge=function(){var t=this;return{logDebug:function(t){$.logDebug("[C++] ".concat(t))},logWarning:function(t){$.logWarning("[C++] ".concat(t))},logError:function(t){$.logError("[C++] ".concat(t))},emitMetric:function(e,n,o,r){t.emit("metric",{id:e,start:n,end:o,duration:r})},resolveImageUrl:function(e){return t.settings.imagesURLFormat?t.settings.imagesURLFormat.replace(":imageId",e):t.settings.imagesURLMap&&t.settings.imagesURLMap[e]?t.settings.imagesURLMap[e]:($.logWarning("Not able to resolve the url for the image with UUID: ".concat(e)),"")},resolveFragmentUrl:function(e){return t.settings.fragmentsURLFormat?t.settings.fragmentsURLFormat.replace(":fragmentId",e):t.settings.fragmentsURLMap&&t.settings.fragmentsURLMap[e]?t.settings.fragmentsURLMap[e]:($.logWarning("Not able to resolve the url for the fragment with UUID: ".concat(e)),"")},onDrawComplete:this.handleDrawComplete.bind(this),onAllImagesReady:function(){t.emit("allImagesReady")},onCameraMoveStart:function(){t.emit("cameraMoveStart")},onCameraMoveEnd:function(){t.emit("cameraMoveEnd")},onCameraZoomStart:function(){t.emit("cameraZoomStart")},onCameraZoomEnd:function(){t.emit("cameraZoomEnd")},onCameraZoomChange:function(e){t.emit("cameraZoomChange",e)},onCameraPanChange:function(){var e=t.getPan();t.emit("cameraPanChange",(null==e?void 0:e.x)||0,(null==e?void 0:e.y)||0)},onCursorChange:function(e){var n,o=null===(n=t.wasmModule)||void 0===n?void 0:n.mapToCSSCursor(e);o&&t.emit("cursorChange",o)},onPrototypeStateChange:function(){},fetch:this.handleJSBridgeFetch.bind(this),abortFetch:this.handleJSBridgeAbortFetch.bind(this)}},e.prototype.handleJSBridgeFetch=function(t,e){var n=this,o=e.clone(),r=function(e){var i,a,s,u;if(!n.disposed&&e.data.url===t){switch(e.data.type){case"success":o.exec(new Uint8Array(e.data.buffer),200,"");break;case"error":$.logError("Error while fetching ".concat(t),e.data.error),o.exec(new Uint8Array(0),null!==(a=null===(i=e.data.error)||void 0===i?void 0:i.statusCode)&&void 0!==a?a:500,null!==(u=null===(s=e.data.error)||void 0===s?void 0:s.statusText)&&void 0!==u?u:"Unknown error")}n.fetchWorker.removeEventListener("message",r)}};this.fetchWorker.addEventListener("message",r),this.fetchWorker.postMessage({type:"fetch",url:t})},e.prototype.handleJSBridgeAbortFetch=function(t){this.fetchWorker.postMessage({type:"abort",url:t})},e.prototype.initWasmModule=function(){var t;return h(this,void 0,void 0,(function(){var e;return p(this,(function(n){switch(n.label){case 0:return this.disposed?[2]:(e=new N("WasmModuleDownload"),[4,null===(t=this.wasmModule)||void 0===t?void 0:t.init()]);case 1:return n.sent(),$.logDebug(e.printMeasurement()),this.emit("metric",e.measure()),[2]}}))}))},e.prototype.initCanvasRendererWasm=function(){return h(this,void 0,void 0,(function(){var t;return p(this,(function(e){if(this.disposed)return[2];try{if(!this.wasmModule)throw Error("WASM module not initialized");t=B(),$.logDebug("Using WebGL ".concat(t)),this.webglCtxHandle=this.wasmModule.makeWebGLContext(this.settings.canvas,{preserveDrawingBuffer:this.settings.preserveDrawingBuffer,majorVersion:t}),this.renderTarget=this.wasmModule.instance.RenderTarget.MakeWebGL(this.webglCtxHandle,this.canvasManager.size.width,this.canvasManager.size.height,this.canvasManager.pixelRatio),this.pageCanvasWasm=new this.wasmModule.instance.CanvasRenderer(this.renderTarget,{showTilesBorders:this.settings.showTilesBorders})}catch(t){throw new W("WASM_ERROR","An error occurred while trying to create the wasm object.",t)}return this.userEventsCollectorWasm=this.pageCanvasWasm.getUserEventsCollector(),this.pageCanvasWasm.setBackgroundColor(this.settings.backgroundColor.r,this.settings.backgroundColor.g,this.settings.backgroundColor.b,this.settings.backgroundColor.a),this.pageCanvasWasm.setZoomLevels(this.settings.minimumZoomLevel,this.settings.maximumZoomLevel),this.pageCanvasWasm.setPanBoundariesPadding(this.settings.panBoundariesPadding),[2]}))}))},e.prototype.setIsCameraLocked=function(t){var e;null===(e=this.pageCanvasWasm)||void 0===e||e.setIsCameraLocked(t)},e.prototype.setBackgroundColor=function(t){var e;t.r===this.settings.backgroundColor.r&&t.g===this.settings.backgroundColor.g&&t.b===this.settings.backgroundColor.b&&t.a===this.settings.backgroundColor.a||(null===(e=this.pageCanvasWasm)||void 0===e||e.setBackgroundColor(t.r,t.g,t.b,t.a),this.settings.backgroundColor=t)},e.prototype.generateDocumentPNG=function(){var t;return h(this,void 0,void 0,(function(){return p(this,(function(e){return[2,null===(t=this.pageCanvasWasm)||void 0===t?void 0:t.generateDocumentPNG()]}))}))},e.prototype.handleDrawComplete=function(){"DRAWING_FILE"===this.status.type&&($.logDebug(this.traceInitialRender.printMeasurement()),this.emit("metric",this.traceInitialRender.measure()),$.logDebug(this.traceFirstPaint.printMeasurement()),this.emit("metric",this.traceFirstPaint.measure()),this.setStatus({type:"READY"}))},e.prototype.looseWebGLContext=function(){var t;(null===(t=this.wasmModule)||void 0===t?void 0:t.destroyWebGLContext(this.webglCtxHandle))||$.logWarning("Failed to loose WebGL context"),this.webglCtxHandle=-1},e.prototype.zoomToFit=function(){var t;null===(t=this.pageCanvasWasm)||void 0===t||t.scaleDocumentToFit()},e.prototype.setFile=function(t){return h(this,void 0,void 0,(function(){var e=this;return p(this,(function(n){return this.disposed?[2]:(this.setStatus({type:"LOADING_FILE"}),[2,new Promise((function(n,o){var r;null===(r=e.pageCanvasWasm)||void 0===r||r.setFile(t,(function(t,o,r){e.setStatus({type:"FILE_READY"});var i="".concat(t,"-v").concat("6.2.0");e.emit("fileReady",e.getDocument(),i,o,r),n()}),(function(){return o(new W("FILE_ERROR","Error encountered while fetching and parsing the file"))}))}))])}))}))},e.prototype.fail=function(t){this.setStatus({type:"FAILURE",code:t.code,message:"".concat(t.toString()).concat(t.cause?"\nWrapped Error: ".concat(t.cause.toString()):"")}),$.logError(t),t.cause&&$.logError(t.cause)},e.prototype.setStatus=function(t){"FAILURE"!==this.status.type&&($.logDebug("Status transition ".concat(this.status.type," => ").concat(t.type)),this.status=t,this.emit("status",t))},e.prototype.getDocument=function(){if(!this.pageCanvasWasm)return{artboards:[],bounds:{x:0,y:0,width:0,height:0}};if(!this.cachedDocumentInfo||this.cachedDocumentInfo.filePath!==this.settings.filePath){var t=this.pageCanvasWasm.getPRFile();this.cachedDocumentInfo={filePath:this.settings.filePath,document:d(d({},t),{artboards:G(t.artboards)})}}return this.cachedDocumentInfo.document},e.prototype.getArtboardAtPosition=function(t,e){if(this.pageCanvasWasm){var n=this.getDocument();if(n){for(var o=this.pageCanvasWasm.getPan(),r=this.pageCanvasWasm.getZoom(),i=(t-o.x)/r,a=(e-o.y)/r,s=0,u=n.artboards;s<u.length;s++){var c=u[s],l=c.bounds.x+c.bounds.width,d=c.bounds.y+c.bounds.height;if(i>=c.bounds.x&&a>=c.bounds.y&&i<=l&&a<=d)return c.objectId}return null}}},e.prototype.getPanAtPosition=function(t,e){var n=this.getPan(),o=Math.max(this.getZoom(),Number.EPSILON),r=t/o,i=e/o;return{x:n.x-r,y:n.y-i}},e.prototype.getStatus=function(){return this.status},e.prototype.setZoom=function(t,e){var n,o=null!=e?e:this.canvasManager.getCanvasCenterPoint();null===(n=this.pageCanvasWasm)||void 0===n||n.setZoom(t,o.x,o.y)},e.prototype.getPan=function(){var t,e,n=this.getDocument().bounds,o=null===(t=this.pageCanvasWasm)||void 0===t?void 0:t.getPan(),r=null===(e=this.pageCanvasWasm)||void 0===e?void 0:e.getZoom();return o&&r?{x:o.x/r+n.x,y:o.y/r+n.y}:{x:0,y:0}},e.prototype.getZoom=function(){var t;return(null===(t=this.pageCanvasWasm)||void 0===t?void 0:t.getZoom())||0},e.prototype.setPan=function(t,e,n){var o;void 0===n&&(n=!1);var r=t,i=e,a=this.getDocument().bounds,s=this.getZoom();if(n){var u=Math.max(2*s*this.canvasManager.pixelRatio,Number.EPSILON);r+=this.canvasManager.size.width/u,i+=this.canvasManager.size.height/u}var c=(r-a.x)*s,l=(i-a.y)*s;null===(o=this.pageCanvasWasm)||void 0===o||o.setPan(c,l)},e.prototype.disposeFetchWorker=function(){this.fetchWorker.postMessage({type:"abort-all"}),this.fetchWorker.terminate()},e.prototype.dispose=function(){var t,e,n;try{this.disposed=!0,this.detachAllListeners(),this.canvasManager.dispose(),this.gestureManager.dispose(),null===(t=this.pageCanvasWasm)||void 0===t||t.stopRenderLoop(),null===(e=this.pageCanvasWasm)||void 0===e||e.delete(),null===(n=this.renderTarget)||void 0===n||n.delete(),this.disposeFetchWorker(),this.fetchWorker.terminate(),this.pageCanvasWasm=void 0,this.wasmModule=void 0}catch(t){this.fail(new W("ERROR","Unexpected exception while disposing the wasm object",t))}},e}(x),J=e(void 0),X=e(void 0),q=e(void 0),Q=e(void 0),tt=e(void 0),et=e(void 0),nt=e("auto"),ot=e(void 0),rt=function(){var t=n(ot);if(void 0===t)throw Error("useInternalContext must be used within a provider");return t},it=function(t,e){switch(e.type){case"on-status":return d(d({},t),{status:e.status});case"on-file-ready":return d(d({},t),{document:e.document});case"on-zoom":return d(d({},t),{zoom:e.zoom});case"on-pan":return d(d({},t),{pan:e.pan});case"dispose":return d(d({},t),{status:null,zoom:null,pan:null,cursor:"auto"});case"on-camera-zoom-start":return d(d({},t),{isCameraZooming:!0});case"on-camera-zoom-end":return d(d({},t),{isCameraZooming:!1});case"on-camera-move-start":return d(d({},t),{isCameraMoving:!0});case"on-camera-move-end":return d(d({},t),{isCameraMoving:!1});case"on-cursor-change":return d(d({},t),{cursor:e.cursor});default:return t}},at=function(e){var n=o(null),s=o(null),u=r(it,{pan:null,zoom:null,status:null,document:null,isCameraZooming:!1,isCameraMoving:!1,cursor:"auto"}),c=u[0],l=c.status,h=c.document,p=c.zoom,v=c.pan,f=c.isCameraZooming,g=c.isCameraMoving,m=c.cursor,y=u[1],C=i((function(t){return y({type:"on-zoom",zoom:t})}),[]),w=i((function(t,e){return y({type:"on-pan",pan:{x:t,y:e}})}),[]),b=i((function(t){y({type:"on-status",status:t})}),[]),P=i((function(t){y({type:"on-file-ready",document:t})}),[]),M=i((function(){return y({type:"on-camera-zoom-start"})}),[]),E=i((function(){return y({type:"on-camera-zoom-end"})}),[]),L=i((function(){return y({type:"on-camera-move-start"})}),[]),R=i((function(){return y({type:"on-camera-move-end"})}),[]),W=i((function(t){return y({type:"on-cursor-change",cursor:t})}),[]),x=i((function(){var t=n.current;t&&($.logDebug("Provider dispose"),t.off("status",b),t.off("fileReady",P),t.off("cameraZoomChange",C),t.off("cameraPanChange",w),t.off("cameraZoomStart",M),t.off("cameraZoomEnd",E),t.off("cameraMoveStart",L),t.off("cameraMoveEnd",R),t.off("cursorChange",W),t.dispose(),n.current=null,y({type:"dispose"}))}),[b,P,w,C,M,E,L,R,W]),S=i((function(t,e,o){if(""!==t&&e&&o&&s.current){$.logDebug("Provider init");var r=new H(d(d({},s.current),{filePath:t,container:o,canvas:e}));r.on("status",b),r.on("fileReady",P),r.on("cameraZoomChange",C),r.on("cameraPanChange",w),r.on("cameraZoomStart",M),r.on("cameraZoomEnd",E),r.on("cameraMoveStart",L),r.on("cameraMoveEnd",R),r.on("cursorChange",W),n.current=r}}),[b,P,C,w,M,E,L,R,W]),I=i((function(t){var e;$.logDebug("Provider setSettings",t),t.backgroundColor&&(null===(e=n.current)||void 0===e||e.setBackgroundColor(t.backgroundColor)),s.current=t}),[]),T=i((function(){return n.current}),[]),D=a((function(){return{dispose:x,init:S,setSettings:I,getInstance:T,dispatch:y}}),[x,S,I,T]);return t.createElement(ot.Provider,{value:D},t.createElement(J.Provider,{value:l},t.createElement(X.Provider,{value:h},t.createElement(q.Provider,{value:p},t.createElement(et.Provider,{value:v},t.createElement(Q.Provider,{value:f},t.createElement(tt.Provider,{value:g},t.createElement(nt.Provider,{value:m},e.children))))))))},st=function(){var t=n(J);if(void 0===t)throw Error("useStatus must be used within a provider");return t},ut=function(){var t=n(X);if(void 0===t)throw Error("useDocument must be used within a provider");return t},ct=function(){var t=n(q);if(void 0===t)throw Error("useZoom must be used within a provider");return t},lt=function(){var t=n(et);if(void 0===t)throw Error("usePan must be used within a provider");return t},dt=function(){var t=n(nt);if(void 0===t)throw Error("useCursor must be used within a provider");return t},ht=function(){var t=n(Q);if(void 0===status)throw Error("useIsCameraZooming must be used within a provider");return t},pt=function(){var t=n(tt);if(void 0===status)throw Error("useIsCameraMoving must be used within a provider");return t},vt=function(){var t=(0,rt().getInstance)();return i((function(e){null==t||t.setZoom(e)}),[t])},ft=function(){var t=vt(),e=ct();return i((function(){var n;"number"==typeof e&&(n=e>=1?Math.round(2*e):e>.5?1:2*e,t(n))}),[t,e])},gt=function(){var t=vt(),e=ct();return i((function(){"number"==typeof e&&t(e/2)}),[t,e])},mt=function(){var t=(0,rt().getInstance)();return i((function(e){var n=e.x,o=e.y,r=e.centerPointInViewport;null==t||t.setPan(n,o,r)}),[t])},yt=function(){var t=(0,rt().getInstance)();return i((function(){null==t||t.zoomToFit()}),[t])},Ct=function(){var t=(0,rt().getInstance)();return i((function(){null==t||t.looseWebGLContext()}),[t])},wt=function(){var t=(0,rt().getInstance)();return i((function(){return h(void 0,void 0,void 0,(function(){return p(this,(function(e){switch(e.label){case 0:return[4,null==t?void 0:t.generateDocumentPNG()];case 1:return[2,e.sent()]}}))}))}),[t])},bt=function(){var t=(0,rt().getInstance)();return i((function(e,n){return h(void 0,void 0,void 0,(function(){return p(this,(function(o){switch(o.label){case 0:return[4,null==t?void 0:t.getArtboardAtPosition(e,n)];case 1:return[2,o.sent()||null]}}))}))}),[t])},Pt=function(){var t=(0,rt().getInstance)();return i((function(e,n){return h(void 0,void 0,void 0,(function(){return p(this,(function(o){switch(o.label){case 0:return[4,null==t?void 0:t.getPanAtPosition(e,n)];case 1:return[2,o.sent()||null]}}))}))}),[t])},Mt=function(){var t=(0,rt().getInstance)();return i((function(e){null==t||t.setIsCameraLocked(e)}),[t])},Et=function(t,e){var n=(0,rt().getInstance)();s((function(){return null==n||n.on(t,e),function(){null==n||n.off(t,e)}}),[t,n,e])};function Lt(t){var e=o(t);e.current=t;var n=i((function(t){for(var n=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];e.current.apply(e,v([t],n,!1))}),[]);s((function(){return $.on("log",n),function(){$.off("log",n)}}),[])}var Rt={position:"relative",width:"100%",height:"100%",touchAction:"manipulation"},Wt={position:"absolute",top:0,left:0},xt=function(e){var n=e.filePath,r=e.locateFile,c=e.imagesURLFormat,l=e.imagesURLMap,h=e.fragmentsURLFormat,p=e.fragmentsURLMap,v=e.backgroundColor,f=e.mode,g=e.showTilesBorders,m=e.minimumZoomLevel,y=e.maximumZoomLevel,C=e.preserveDrawingBuffer,w=e.panBoundariesPadding,b=e.initialPan,P=e.initialZoom,M=e.children,E=e.containerProps,L=void 0===E?{}:E,R=e.canvasProps,W=void 0===R?{}:R,x=e.featureFlags,S=void 0===x?{}:x,I=o(null),T=o(null),D=u(!1),k=D[0],F=D[1],U=i((function(){return F(!0)}),[]),A=rt(),B=A.dispose,G=A.init,Z=A.setSettings,z=dt(),O=st();Et("allImagesReady",U),s((function(){return $.logDebug("WebRenderer mounted"),function(){return $.logDebug("WebRenderer unmounted")}}),[]),s((function(){Z({locateFile:r,imagesURLFormat:c,imagesURLMap:l,fragmentsURLFormat:h,fragmentsURLMap:p,backgroundColor:v,mode:f,showTilesBorders:g,minimumZoomLevel:m,maximumZoomLevel:y,preserveDrawingBuffer:C,panBoundariesPadding:w,initialPan:b,initialZoom:P,featureFlags:S})}),[Z,r,c,l,h,p,v,f,g,m,y,C,w,b,P,S]),s((function(){if(n)return G(n,I.current,T.current),function(){B()}}),[B,G,n]);var _=a((function(){var t;return null!==(t=e.cursor)&&void 0!==t?t:z}),[e.cursor,z]),j=a((function(){return d(d({},Rt),{cursor:_})}),[_]);return t.createElement("div",d({},L,{ref:T,style:j}),n&&t.createElement("canvas",d({},W,{key:n,ref:I,"data-sketchweb-all-images-ready":k,"data-testid":"sketchweb-canvas","data-sketchweb-status":"sketchweb-status-".concat((null==O?void 0:O.type.toLowerCase())||"null"),style:Wt})),"READY"===(null==O?void 0:O.type)&&M)},St=function(t){function e(e){var n=t.call(this)||this;return n.status={type:"INIT"},n.disposed=!1,n.handleCanvasResize=function(t,e,o){var r;null===(r=n.playerWasm)||void 0===r||r.resize(t,e,o)},n.handleWebGLContextLost=function(){n.setStatus({type:"WEBGL_CONTEXT_LOST"})},n.handlePinchToZoomEvent=function(t,e){var o;null===(o=n.userEventsCollectorWasm)||void 0===o||o.dispatchPinchToZoomEvent(t,e.x,e.y)},n.handleWheelEvent=function(t,e){var o;n.wasmModule&&n.userEventsCollectorWasm.dispatchWheelEvent(t.x,t.y,null===(o=n.wasmModule)||void 0===o?void 0:o.mapPointerInfo(e))},n.handlePointerDownEvent=function(t){var e;n.wasmModule&&n.userEventsCollectorWasm.dispatchPointerDownEvent(null===(e=n.wasmModule)||void 0===e?void 0:e.mapPointerInfo(t))},n.handlePointerMoveEvent=function(t){var e;n.wasmModule&&n.userEventsCollectorWasm.dispatchPointerMoveEvent(null===(e=n.wasmModule)||void 0===e?void 0:e.mapPointerInfo(t))},n.handleGlobalPointerMoveEvent=function(t){var e;n.wasmModule&&n.userEventsCollectorWasm.dispatchGlobalPointerMoveEvent(null===(e=n.wasmModule)||void 0===e?void 0:e.mapPointerInfo(t))},n.handlePointerUpEvent=function(t){var e;n.wasmModule&&n.userEventsCollectorWasm.dispatchPointerUpEvent(null===(e=n.wasmModule)||void 0===e?void 0:e.mapPointerInfo(t))},n.restartPrototype=function(t){var e;null===(e=n.playerWasm)||void 0===e||e.restartPrototype(t)},n.goBack=function(){var t;null===(t=n.playerWasm)||void 0===t||t.goBack()},n.goForwards=function(){var t;null===(t=n.playerWasm)||void 0===t||t.goForwards()},n.settings=d(d({backgroundColor:{r:1,g:1,b:1,a:1},showTilesBorders:!1,preserveDrawingBuffer:!1},z(e)),{featureFlags:d(d({},I),e.featureFlags)}),n.gestureManager=new _(n.settings.container),n.canvasManager=new V({container:n.settings.container,canvas:n.settings.canvas}),n.wasmModule=new Y({mode:n.settings.mode,locateFile:n.settings.locateFile,jsBridge:n.createJSBridge(),featureFlags:n.settings.featureFlags}),n.fetchWorker=new Worker(n.settings.locateFile.replace("{file}","fetch-worker.js")),n.settings.manualInitialization||n.init(),n}return l(e,t),e.prototype.addListeners=function(){this.canvasManager.on("resize",this.handleCanvasResize),this.gestureManager.on("wheel",this.handleWheelEvent),this.gestureManager.on("pointerup",this.handlePointerUpEvent),this.gestureManager.on("pointermove",this.handlePointerMoveEvent),this.gestureManager.on("globalpointermove",this.handleGlobalPointerMoveEvent),this.gestureManager.on("pointerdown",this.handlePointerDownEvent),this.gestureManager.on("pinchToZoom",this.handlePinchToZoomEvent),this.settings.canvas.addEventListener("webglcontextlost",this.handleWebGLContextLost)},e.prototype.collectAndEmitDeviceInfo=function(){return h(this,void 0,void 0,(function(){var t;return p(this,(function(e){switch(e.label){case 0:return[4,L()];case 1:return t=e.sent(),this.deviceInfo=d(d({},t),{hardwareConcurrency:navigator.hardwareConcurrency}),this.emit("deviceInfo",this.deviceInfo),[2]}}))}))},e.prototype.init=function(){return h(this,void 0,void 0,(function(){var t;return p(this,(function(e){switch(e.label){case 0:this.traceFirstPaint=new N("FirstPaint"),this.setStatus({type:"INIT"}),this.collectAndEmitDeviceInfo(),e.label=1;case 1:return e.trys.push([1,5,,6]),[4,this.initWasmModule()];case 2:return e.sent(),[4,this.initPlayerWasm()];case 3:return e.sent(),[4,this.startDownload()];case 4:return e.sent(),[3,6];case 5:return t=e.sent(),[2,this.fail(t instanceof W?t:new W("ERROR","Unexpected exception initializing the web renderer",t))];case 6:return this.startRendering(),this.addListeners(),[2]}}))}))},e.prototype.initWasmModule=function(){var t;return h(this,void 0,void 0,(function(){var e;return p(this,(function(n){switch(n.label){case 0:return e=new N("WasmModuleDownload"),[4,null===(t=this.wasmModule)||void 0===t?void 0:t.init()];case 1:return n.sent(),e.printMeasurement(),this.emit("metric",e.measure()),[2]}}))}))},e.prototype.startDownload=function(){var t=this;return this.setStatus({type:"LOADING_FILE"}),new Promise((function(e){var n;null===(n=t.playerWasm)||void 0===n||n.startDownload((function(){e()}),(function(){console.error("Error loading file")}))}))},e.prototype.startRendering=function(){var t;this.traceInitialRender=new N("InitialRender"),this.setStatus({type:"DRAWING_FILE"}),null===(t=this.playerWasm)||void 0===t||t.startRenderLoop()},e.prototype.createJSBridge=function(){var t=this;return{logDebug:function(t){$.logDebug("[C++] ".concat(t))},logWarning:function(t){$.logWarning("[C++] ".concat(t))},logError:function(t){$.logError("[C++] ".concat(t))},emitMetric:function(e,n,o,r){t.emit("metric",{id:e,start:n,end:o,duration:r})},resolveImageUrl:function(e){return t.settings.imagesURLFormat?t.settings.imagesURLFormat.replace(":imageId",e):t.settings.imagesURLMap&&t.settings.imagesURLMap[e]?t.settings.imagesURLMap[e]:($.logWarning("Not able to resolve the url for the image with UUID: ".concat(e)),"")},resolveFragmentUrl:function(e){return t.settings.fragmentsURLFormat?t.settings.fragmentsURLFormat.replace(":fragmentId",e):t.settings.fragmentsURLMap&&t.settings.fragmentsURLMap[e]?t.settings.fragmentsURLMap[e]:($.logWarning("Not able to resolve the url for the fragment with UUID: ".concat(e)),"")},onDrawComplete:this.handleDrawComplete.bind(this),onAllImagesReady:function(){t.emit("allImagesReady")},onCameraMoveStart:function(){t.emit("cameraMoveStart")},onCameraMoveEnd:function(){t.emit("cameraMoveEnd")},onCameraZoomStart:function(){t.emit("cameraZoomStart")},onCameraZoomEnd:function(){t.emit("cameraZoomEnd")},onCameraZoomChange:function(e){t.emit("cameraZoomChange",e)},onCameraPanChange:function(e,n){t.emit("cameraPanChange",e,n)},onCursorChange:function(e){var n,o=null===(n=t.wasmModule)||void 0===n?void 0:n.mapToCSSCursor(e);o&&t.emit("cursorChange",o)},onPrototypeStateChange:function(e,n,o){t.emit("prototypeStateChange",{currentArtboardId:e,canGoBack:n,canGoForwards:o})},fetch:this.handleJSBridgeFetch.bind(this),abortFetch:this.handleJSBridgeAbortFetch.bind(this)}},e.prototype.handleJSBridgeFetch=function(t,e){var n=this,o=e.clone(),r=function(e){var i,a,s,u;if(!n.disposed&&e.data.url===t){switch(e.data.type){case"success":o.exec(new Uint8Array(e.data.buffer),200,"");break;case"error":$.logError("Error while fetching ".concat(t),e.data.error),o.exec(new Uint8Array(0),null!==(a=null===(i=e.data.error)||void 0===i?void 0:i.statusCode)&&void 0!==a?a:500,null!==(u=null===(s=e.data.error)||void 0===s?void 0:s.statusText)&&void 0!==u?u:"Unknown error")}n.fetchWorker.removeEventListener("message",r)}};this.fetchWorker.addEventListener("message",r),this.fetchWorker.postMessage({type:"fetch",url:t})},e.prototype.handleJSBridgeAbortFetch=function(t){this.fetchWorker.postMessage({type:"abort",url:t})},e.prototype.initPlayerWasm=function(){return h(this,void 0,void 0,(function(){var t,e,n,o,r,i,a,s,u,c,l,h,v;return p(this,(function(p){try{if(!this.wasmModule)throw Error("WASM module not initialized");for(this.webglCtxHandle=this.wasmModule.makeWebGLContext(this.settings.canvas,{preserveDrawingBuffer:this.settings.preserveDrawingBuffer,majorVersion:B()}),t=this.wasmModule.instance,e=t.RenderTarget,n=t.PrototypeRenderer,o=t.PrototypeArtboardVector,r=t.PrototypeFlowVector,this.renderTarget=e.MakeWebGL(this.webglCtxHandle,this.canvasManager.size.width,this.canvasManager.size.height,this.canvasManager.pixelRatio),i={artboards:new o},a=0,s=this.settings.prototypeStructure.artboards;a<s.length;a++){for(u=s[a],c=new r,l=0,h=u.flows;l<h.length;l++)v=h[l],c.push_back(v);i.artboards.push_back(d(d({},u),{flows:c}))}this.playerWasm=new n(this.renderTarget,{showTilesBorders:this.settings.showTilesBorders},this.settings.startArtboardUUID,i)}catch(t){throw new W("WASM_ERROR","An error occurred while trying to create the WebRendererWasm object.",t)}return this.userEventsCollectorWasm=this.playerWasm.getUserEventsCollector(),this.playerWasm.setBackgroundColor(this.settings.backgroundColor.r,this.settings.backgroundColor.g,this.settings.backgroundColor.b,this.settings.backgroundColor.a),this.playerWasm.setZoomLevels(this.settings.minimumZoomLevel,this.settings.maximumZoomLevel),[2]}))}))},e.prototype.setIsCameraLocked=function(t){var e;null===(e=this.playerWasm)||void 0===e||e.setIsCameraLocked(t)},e.prototype.setBackgroundColor=function(t){var e;t.r===this.settings.backgroundColor.r&&t.g===this.settings.backgroundColor.g&&t.b===this.settings.backgroundColor.b&&t.a===this.settings.backgroundColor.a||(null===(e=this.playerWasm)||void 0===e||e.setBackgroundColor(t.r,t.g,t.b,t.a),this.settings.backgroundColor=t)},e.prototype.handleDrawComplete=function(){"DRAWING_FILE"===this.status.type&&(this.traceInitialRender.printMeasurement(),this.emit("metric",this.traceInitialRender.measure()),this.traceFirstPaint.printMeasurement(),this.emit("metric",this.traceFirstPaint.measure()),this.setStatus({type:"READY"}))},e.prototype.looseWebGLContext=function(){var t;null===(t=this.wasmModule)||void 0===t||t.destroyWebGLContext(this.webglCtxHandle),this.webglCtxHandle=-1},e.prototype.fail=function(t){this.setStatus({type:"FAILURE",code:t.code,message:"".concat(t.toString()).concat(t.cause?"\nWrapped Error: ".concat(t.cause.toString()):"")}),$.logError(t),t.cause&&$.logError(t.cause)},e.prototype.setStatus=function(t){"FAILURE"!==this.status.type&&($.logDebug("Status transition ".concat(this.status.type," => ").concat(t.type)),this.status=t,this.emit("status",t))},e.prototype.getStatus=function(){return this.status},e.prototype.dispose=function(){var t,e;try{this.detachAllListeners(),this.canvasManager.dispose(),this.gestureManager.dispose(),null===(t=this.playerWasm)||void 0===t||t.stopRenderLoop(),null===(e=this.playerWasm)||void 0===e||e.delete(),this.renderTarget.delete(),this.playerWasm=void 0,this.wasmModule=void 0,this.disposed=!0}catch(t){this.fail(new W("ERROR","Unexpected exception while disposing the WebRendererWasm object",t))}},e}(x),It=e(void 0),Tt=e("auto"),Dt=e(void 0),kt=e(void 0),Ft=function(){var t=n(kt);if(void 0===t)throw Error("useInternalContext must be used within a provider");return t},Ut=function(t,e){switch(e.type){case"on-status":return d(d({},t),{status:e.status});case"dispose":return d(d({},t),{status:null,cursor:"auto"});case"on-cursor-change":return d(d({},t),{cursor:e.cursor});case"on-prototype-state-change":return d(d({},t),{prototypeState:d(d({},t.prototypeState),e.prototypeState)});default:return t}},At=function(e){var n=o(null),s=o(null),u=r(Ut,{status:null,cursor:"auto",prototypeState:{currentArtboardId:"",canGoBack:!1,canGoForwards:!1}}),c=u[0],l=c.status,h=c.cursor,p=c.prototypeState,v=u[1],f=i((function(t){v({type:"on-status",status:t})}),[]),g=i((function(t){return v({type:"on-cursor-change",cursor:t})}),[]),m=i((function(t){return v({type:"on-prototype-state-change",prototypeState:t})}),[]),y=i((function(){var t=n.current;t&&($.logDebug("Provider dispose"),t.off("status",f),t.off("cursorChange",g),t.off("prototypeStateChange",m),t.dispose(),n.current=null,v({type:"dispose"}))}),[f,g,m]),C=i((function(t,e){if(t&&e&&s.current){$.logDebug("Provider init");var o=new St(d(d({},s.current),{container:e,canvas:t}));o.on("status",f),o.on("cursorChange",g),o.on("prototypeStateChange",m),n.current=o}}),[f,g,m]),w=i((function(t){var e;$.logDebug("Provider setSettings",t),t.backgroundColor&&(null===(e=n.current)||void 0===e||e.setBackgroundColor(t.backgroundColor)),s.current=t}),[]),b=i((function(){return n.current}),[]),P=a((function(){return{dispose:y,init:C,setSettings:w,getInstance:b,dispatch:v}}),[y,C,w,b]);return t.createElement(kt.Provider,{value:P},t.createElement(It.Provider,{value:l},t.createElement(Tt.Provider,{value:h},t.createElement(Dt.Provider,{value:p},e.children))))},Bt=function(){var t=(0,Ft().getInstance)();return i((function(e){null==t||t.restartPrototype(e)}),[t])},Gt=function(){var t=(0,Ft().getInstance)();return i((function(){null==t||t.goBack()}),[t])},Zt=function(){var t=(0,Ft().getInstance)();return i((function(){null==t||t.goForwards()}),[t])},zt=function(){var t=n(It);if(void 0===t)throw Error("usePrototypeStatus must be used within a provider");return t},Ot=function(){var t=n(Tt);if(void 0===t)throw Error("usePrototypeCursor must be used within a provider");return t},_t=function(){var t=n(Dt);if(void 0===t)throw Error("usePrototypeState must be used within a provider");return t},jt=function(t,e){var n=(0,Ft().getInstance)();s((function(){return null==n||n.on(t,e),function(){null==n||n.off(t,e)}}),[t,n,e])},Nt={position:"relative",width:"100%",height:"100%",touchAction:"manipulation"},Kt={position:"absolute",top:0,left:0},$t=function(e){var n=e.locateFile,r=e.imagesURLFormat,i=e.imagesURLMap,u=e.backgroundColor,c=e.mode,l=e.showTilesBorders,h=e.minimumZoomLevel,p=e.maximumZoomLevel,v=e.preserveDrawingBuffer,f=e.children,g=e.containerProps,m=void 0===g?{}:g,y=e.canvasProps,C=void 0===y?{}:y,w=e.featureFlags,b=void 0===w?{}:w,P=e.startArtboardUUID,M=e.prototypeStructure,E=e.fragmentsURLFormat,L=e.fragmentsURLMap,R=o(null),W=o(null),x=Ft(),S=x.dispose,I=x.init,T=x.setSettings,D=Ot(),k=zt();s((function(){T({locateFile:n,imagesURLFormat:r,imagesURLMap:i,backgroundColor:u,mode:c,showTilesBorders:l,minimumZoomLevel:h,maximumZoomLevel:p,preserveDrawingBuffer:v,featureFlags:b,startArtboardUUID:P,prototypeStructure:M,fragmentsURLFormat:E,fragmentsURLMap:L})}),[T,n,r,i,u,c,l,h,p,v,b,P]),s((function(){return I(R.current,W.current),function(){S()}}),[S,I]);var F=a((function(){return d(d({},Nt),{cursor:D})}),[D]);return t.createElement("div",d({},m,{ref:W,style:F}),t.createElement("canvas",d({},C,{ref:R,"data-testid":"prototype-canvas","data-prototype-status":"prototype-status-".concat((null==k?void 0:k.type.toLowerCase())||"null"),style:Kt})),"READY"===(null==k?void 0:k.type)&&f)};export{tt as CameraMoveContext,Q as CameraZoomingContext,H as CanvasRenderer,at as CanvasRendererProvider,xt as CanvasRendererReact,nt as CursorContext,I as DefaultFeatureFlags,X as DocumentContext,x as EventEmitter,_ as GestureManager,j as KeyboardManager,S as ListenersCollector,et as PanContext,N as Performance,St as PrototypeRenderer,At as PrototypeRendererProvider,$t as PrototypeRendererReact,J as StatusContext,W as WebRendererError,R as WebRendererMode,q as ZoomContext,A as clamp,G as convertEmbindVectorToArray,F as debounce,U as extractPointer,B as getSupportedWebGLVersion,T as getiOSVersion,Z as isTouchDevice,$ as logger,K as nextTick,k as parseSafariUserAgent,it as reducer,z as removeUndefinedKeys,O as touchableClick,dt as useCursor,gt as useDecrementZoom,ut as useDocument,Et as useEvent,wt as useGenerateDocumentPNG,bt as useGetArtboardAtPosititon,Pt as useGetPanAtPosition,Gt as useGoBack,Zt as useGoForwards,ft as useIncrementZoom,pt as useIsCameraMoving,ht as useIsCameraZooming,Mt as useLockCamera,Lt as useLogEvent,Ct as useLooseWebGLContext,lt as usePan,Ot as usePrototypeCursor,jt as usePrototypeEvent,_t as usePrototypeState,zt as usePrototypeStatus,Bt as useRestartPrototype,mt as useSetPan,vt as useSetZoom,st as useStatus,ct as useZoom,yt as useZoomToFit};
1
+ import t,{createContext as e,useContext as n,useRef as o,useReducer as r,useCallback as i,useMemo as a,useEffect as s,useState as u}from"react";var c=function(t,e){return c=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},c(t,e)};function l(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}c(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var d=function(){return d=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},d.apply(this,arguments)};function h(t,e,n,o){return new(n||(n=Promise))((function(r,i){function a(t){try{u(o.next(t))}catch(t){i(t)}}function s(t){try{u(o.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((o=o.apply(t,e||[])).next())}))}function p(t,e){var n,o,r,i,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,o&&(r=2&s[0]?o.return:s[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,s[1])).done)return r;switch(o=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,o=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){a.label=s[1];break}if(6===s[0]&&a.label<r[1]){a.label=r[1],r=s;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(s);break}r[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],o=0}finally{n=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}function v(t,e,n){if(n||2===arguments.length)for(var o,r=0,i=e.length;r<i;r++)!o&&r in e||(o||(o=Array.prototype.slice.call(e,0,r)),o[r]=e[r]);return t.concat(o||Array.prototype.slice.call(e))}function g(t,e,n,o){return new(n||(n=Promise))((function(r,i){function a(t){try{u(o.next(t))}catch(t){i(t)}}function s(t){try{u(o.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((o=o.apply(t,e||[])).next())}))}const f=["geforce 320m","geforce 8600","geforce 8600m gt","geforce 8800 gs","geforce 8800 gt","geforce 9400","geforce 9400m g","geforce 9400m","geforce 9600m gt","geforce 9600m","geforce fx go5200","geforce gt 120","geforce gt 130","geforce gt 330m","geforce gtx 285","google swiftshader","intel g41","intel g45","intel gma 4500mhd","intel gma x3100","intel hd 3000","intel q45","legacy","mali-2","mali-3","mali-4","quadro fx 1500","quadro fx 4","quadro fx 5","radeon hd 2400","radeon hd 2600","radeon hd 4670","radeon hd 4850","radeon hd 4870","radeon hd 5670","radeon hd 5750","radeon hd 6290","radeon hd 6300","radeon hd 6310","radeon hd 6320","radeon hd 6490m","radeon hd 6630m","radeon hd 6750m","radeon hd 6770m","radeon hd 6970m","sgx 543","sgx543"];function m(t){return t.toLowerCase().replace(/.*angle ?\((.+)\)(?: on vulkan [0-9.]+)?$/i,"$1").replace(/\s(\d{1,2}gb|direct3d.+$)|\(r\)| \([^)]+\)$/g,"").replace(/(?:vulkan|opengl) \d+\.\d+(?:\.\d+)?(?: \((.*)\))?/,"$1")}const y="undefined"==typeof window,C=(()=>{if(y)return;const{userAgent:t,platform:e,maxTouchPoints:n}=window.navigator,o=/(iphone|ipod|ipad)/i.test(t),r="iPad"===e||"MacIntel"===e&&n>0&&!window.MSStream;return{isIpad:r,isMobile:/android/i.test(t)||o||r,isSafari12:/Version\/12.+Safari/.test(t)}})();class w extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype)}}const b=[],P=[];function E(t,e){if(t===e)return 0;const n=t;t.length>e.length&&(t=e,e=n);let o=t.length,r=e.length;for(;o>0&&t.charCodeAt(~-o)===e.charCodeAt(~-r);)o--,r--;let i,a=0;for(;a<o&&t.charCodeAt(a)===e.charCodeAt(a);)a++;if(o-=a,r-=a,0===o)return r;let s,u,c=0,l=0,d=0;for(;l<o;)P[l]=t.charCodeAt(a+l),b[l]=++l;for(;d<r;)for(i=e.charCodeAt(a+d),s=d++,c=d,l=0;l<o;l++)u=i===P[l]?s:s+1,s=b[l],c=b[l]=s>c?u>c?c+1:u:u>s?s+1:u;return c}function M(t){return null!=t}const L=({mobileTiers:t=[0,15,30,60],desktopTiers:e=[0,15,30,60],override:n={},glContext:o,failIfMajorPerformanceCaveat:r=!1,benchmarksURL:i="https://unpkg.com/detect-gpu@5.0.12/dist/benchmarks"}={})=>g(void 0,void 0,void 0,(function*(){const a={};if(y)return{tier:0,type:"SSR"};const{isIpad:s=!!(null==C?void 0:C.isIpad),isMobile:u=!!(null==C?void 0:C.isMobile),screenSize:c=window.screen,loadBenchmarks:l=(t=>g(void 0,void 0,void 0,(function*(){const e=yield fetch(`${i}/${t}`).then((t=>t.json()));if(parseInt(e.shift().split(".")[0],10)<4)throw new w("Detect GPU benchmark data is out of date. Please update to version 4x");return e})))}=n;let{renderer:d}=n;const h=(t,e,n,o,r)=>({device:r,fps:o,gpu:n,isMobile:u,tier:t,type:e});let p,v="";if(d)d=m(d),p=[d];else{const t=o||function(t,e=!1){const n={alpha:!1,antialias:!1,depth:!1,failIfMajorPerformanceCaveat:e,powerPreference:"high-performance",stencil:!1};t&&delete n.powerPreference;const o=window.document.createElement("canvas"),r=o.getContext("webgl",n)||o.getContext("experimental-webgl",n);return null!=r?r:void 0}(null==C?void 0:C.isSafari12,r);if(!t)return h(0,"WEBGL_UNSUPPORTED");const e=t.getExtension("WEBGL_debug_renderer_info");if(e&&(d=t.getParameter(e.UNMASKED_RENDERER_WEBGL)),!d)return h(1,"FALLBACK");v=d,d=m(d),p=function(t,e,n){return"apple gpu"===e?function(t,e,n){if(!n)return[e];const o=function(t){const e=t.createShader(35633),n=t.createShader(35632),o=t.createProgram();if(!(n&&e&&o))return;t.shaderSource(e,"\n precision highp float;\n attribute vec3 aPosition;\n varying float vvv;\n void main() {\n vvv = 0.31622776601683794;\n gl_Position = vec4(aPosition, 1.0);\n }\n "),t.shaderSource(n,"\n precision highp float;\n varying float vvv;\n void main() {\n vec4 enc = vec4(1.0, 255.0, 65025.0, 16581375.0) * vvv;\n enc = fract(enc);\n enc -= enc.yzww * vec4(1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0, 0.0);\n gl_FragColor = enc;\n }\n "),t.compileShader(e),t.compileShader(n),t.attachShader(o,e),t.attachShader(o,n),t.linkProgram(o),t.detachShader(o,e),t.detachShader(o,n),t.deleteShader(e),t.deleteShader(n),t.useProgram(o);const r=t.createBuffer();t.bindBuffer(34962,r),t.bufferData(34962,new Float32Array([-1,-1,0,3,-1,0,-1,3,0]),35044);const i=t.getAttribLocation(o,"aPosition");t.vertexAttribPointer(i,3,5126,!1,0,0),t.enableVertexAttribArray(i),t.clearColor(1,1,1,1),t.clear(16384),t.viewport(0,0,1,1),t.drawArrays(4,0,3);const a=new Uint8Array(4);return t.readPixels(0,0,1,1,6408,5121,a),t.deleteProgram(o),t.deleteBuffer(r),a.join("")}(t),r="801621810",i="8016218135",a="80162181161",s=(null==C?void 0:C.isIpad)?[["a7",a,12],["a8",i,15],["a8x",i,15],["a9",i,15],["a9x",i,15],["a10",i,15],["a10x",i,15],["a12",r,15],["a12x",r,15],["a12z",r,15],["a14",r,15],["m1",r,15]]:[["a7",a,12],["a8",i,12],["a9",i,15],["a10",i,15],["a11",r,15],["a12",r,15],["a13",r,15],["a14",r,15]];let u;return"80162181255"===o?u=s.filter((([,,t])=>t>=14)):(u=s.filter((([,t])=>t===o)),u.length||(u=s)),u.map((([t])=>`apple ${t} gpu`))}(t,e,n):[e]}(t,d,u)}const b=(yield Promise.all(p.map((function(t){var e;return g(this,void 0,void 0,(function*(){const n=(t=>{const e=u?["adreno","apple","mali-t","mali","nvidia","powervr","samsung"]:["intel","apple","amd","radeon","nvidia","geforce"];for(const n of e)if(t.includes(n))return n})(t);if(!n)return;const o=`${u?"m":"d"}-${n}${s?"-ipad":""}.json`,r=a[o]=null!==(e=a[o])&&void 0!==e?e:l(o);let i;try{i=yield r}catch(n){if(n instanceof w)throw n;return}const d=function(t){var e;const n=(t=t.replace(/\([^)]+\)/,"")).match(/\d+/)||t.match(/(\W|^)([A-Za-z]{1,3})(\W|$)/g);return null!==(e=null==n?void 0:n.join("").replace(/\W|amd/g,""))&&void 0!==e?e:""}(t);let h=i.filter((([,t])=>t===d));h.length||(h=i.filter((([e])=>e.includes(t))));const p=h.length;if(0===p)return;const v=t.split(/[.,()\[\]/\s]/g).sort().filter(((t,e,n)=>0===e||t!==n[e-1])).join(" ");let g,[f,,,,m]=p>1?h.map((t=>[t,E(v,t[2])])).sort((([,t],[,e])=>t-e))[0][0]:h[0],y=Number.MAX_VALUE;const{devicePixelRatio:C}=window,b=c.width*C*c.height*C;for(const t of m){const[e,n]=t,o=e*n,r=Math.abs(b-o);r<y&&(y=r,g=t)}if(!g)return;const[,,P,M]=g;return[y,P,f,M]}))})))).filter(M).sort((([t=Number.MAX_VALUE,e],[n=Number.MAX_VALUE,o])=>t===n?e-o:t-n));if(!b.length){const t=f.find((t=>d.includes(t)));return t?h(0,"BLOCKLISTED",t):h(1,"FALLBACK",`${d} (${v})`)}const[,P,L,R]=b[0];if(-1===P)return h(0,"BLOCKLISTED",L,P,R);const W=u?t:e;let x=0;for(let t=0;t<W.length;t++)P>=W[t]&&(x=t);return h(x,"BENCHMARK",L,P,R)}));var R,W=function(t){function e(n,o,r){var i=this.constructor,a=t.call(this,"(".concat(n,") ").concat(o))||this;return a.code=n,a.cause=r,a.name=e.name,Object.setPrototypeOf(a,i.prototype),a}return l(e,t),e}(Error);!function(t){t.debug="debug",t.release="release"}(R||(R={}));var x=function(){function t(){this.listeners={}}return t.prototype.on=function(t,e){var n,o;this.listeners[t]=null!==(n=this.listeners[t])&&void 0!==n?n:new Set,null===(o=this.listeners[t])||void 0===o||o.add(e)},t.prototype.off=function(t,e){var n;null===(n=this.listeners[t])||void 0===n||n.delete(e)},t.prototype.forwardEvent=function(t,e){this.on(e,(function(){for(var n=[],o=0;o<arguments.length;o++)n[o]=arguments[o];t.emit.apply(t,v([e],n,!1))}))},t.prototype.emit=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var o=this.listeners[t];(null==o?void 0:o.size)&&o.forEach((function(t){Promise.resolve().then((function(){t.apply(void 0,e)}))}))},t.prototype.detachAllListeners=function(){this.listeners={}},t}(),S=function(){function t(){this.removeListenerCallbacks=[]}return t.prototype.add=function(t,e,n,o){t.addEventListener(e,n,o);var r=function(){t.removeEventListener(e,n,o)};return this.removeListenerCallbacks.push(r),r},t.prototype.dispose=function(){this.removeListenerCallbacks.forEach((function(t){return t()}))},t}(),I={delayedDraw:!0,offscreenCanvas:!1,useDirtyRectsRendering:!0,safariWebGL2:!1,pageBoundariesLimit:!1},D=function(t){return parseFloat((""+(/CPU.*OS ([0-9_]{1,5})|(CPU like).*AppleWebKit.*Mobile/i.exec(t)||[0,""])[1]).replace("undefined","3_2").replace("_",".").replace("_",""))||!1},T=/(iPhone|Macintosh|iPad)(.*)(Version)\/(0|[1-9]\d*)\.(0|[1-9]\d*)\.?(0|[1-9]\d*)?/,k=function(t){if(void 0===t&&(t=window.navigator.userAgent),t.includes("Chrome/")||t.includes("Chromium/")||t.includes("Opera/")||t.includes("Firefox/"))return null;var e=t.match(T);if(!e)return null;var n=e[1];return"Macintosh"!==n&&"iPad"!==n&&"iPhone"!==n?null:{hardware:n,version:{major:parseInt(e[4])||0,minor:parseInt(e[5])||0,patch:parseInt(e[6])||0}}};function F(t,e){var n;function o(){for(var o=[],r=0;r<arguments.length;r++)o[r]=arguments[r];clearTimeout(n),n=setTimeout((function(){t.apply(void 0,o)}),e)}return o.cancel=function(){n&&clearTimeout(n)},o}function U(t){var e,n,o,r,i,a=null!==(n=null===(e=t.touches)||void 0===e?void 0:e[0])&&void 0!==n?n:null===(o=t.changedTouches)||void 0===o?void 0:o[0];return{x:null!==(r=null==a?void 0:a.clientX)&&void 0!==r?r:t.clientX,y:null!==(i=null==a?void 0:a.clientY)&&void 0!==i?i:t.clientY}}function A(t,e,n){return Math.max(e,Math.min(n,t))}function B(){return k()&&!I.safariWebGL2?1:"undefined"!=typeof WebGL2RenderingContext?2:1}function G(t){for(var e=t.size(),n=[],o=0;o<e;++o){var r=t.get(o);if(null==r)throw Error("Error converting embind vector to array");n.push(r)}return n}function Z(){return"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0}function z(t){var e=t;return Object.keys(e).forEach((function(t){void 0===e[t]&&delete e[t]})),e}function _(t){return Z()?{onTouchEnd:t}:{onClick:t}}var O=function(t){function e(e){var n=t.call(this)||this;return n.listenersCollector=new S,n.state={pinchToZoomLastDistance:0,lastGestureScale:1,isCtrlPressed:!1},n.handleGestureStart=function(t){t.preventDefault(),n.state.lastGestureScale=t.scale},n.handleGestureChange=function(t){t.preventDefault();var e=t.scale/n.state.lastGestureScale;n.state.lastGestureScale=t.scale;var o=n.getCorrectPointerPosition(t);n.emitZoomEvent(e,o)},n.handleGestureEnd=function(t){t.preventDefault()},n.handleTouchStart=function(t){t.preventDefault(),n.handleTouchPinchToZoomStart(t),n.emit("pointerdown",{type:"touch",position:n.getCorrectPointerPosition(t),button:0,touchesCount:t.touches.length})},n.handleMouseDown=function(t){t.ctrlKey||(t.preventDefault(),n.emit("pointerdown",{type:"mouse",position:n.getCorrectPointerPosition(t),button:t.button,touchesCount:0}))},n.handleTouchMove=function(t){n.handleTouchPinchToZoomChange(t),n.emit("pointermove",{type:"touch",position:n.getCorrectPointerPosition(t),button:0,touchesCount:t.touches.length})},n.handleMouseMove=function(t){n.updateMousePosition(t)},n.handleGlobalTouchMove=function(t){n.emit("globalpointermove",{type:"touch",position:n.getCorrectPointerPosition(t),button:0,touchesCount:t.touches.length})},n.handleGlobalMouseMove=function(t){n.updateGlobalMousePosition(t)},n.handleTouchPinchToZoomStart=function(t){var e;!t.touches||(null===(e=t.touches)||void 0===e?void 0:e.length)<2||(n.state.pinchToZoomLastDistance=n.calculateDistanceBetweenTouches(t.touches[0],t.touches[1]))},n.handleTouchPinchToZoomChange=function(t){var e;if(t.touches&&!((null===(e=t.touches)||void 0===e?void 0:e.length)<2)){var o=n.calculateDistanceBetweenTouches(t.touches[0],t.touches[1]),r=n.getCorrectPointerPosition(t),i=1+.004*(o-n.state.pinchToZoomLastDistance);n.state.pinchToZoomLastDistance=o,n.emitZoomEvent(i,r)}},n.handleTouchEnd=function(t){var e=n.getCorrectPointerPosition(t);n.emit("pointerup",{position:e,type:"touch",button:0,touchesCount:t.touches.length})},n.handleMouseUp=function(t){n.emit("pointerup",{type:"mouse",position:n.getCorrectPointerPosition(t),button:t.button,touchesCount:0})},n.handleMouseWheel=function(t){t.preventDefault();var e=t.ctrlKey&&!n.state.isCtrlPressed,o=t.metaKey||e||n.state.isCtrlPressed;if(n.updateMousePosition(t),n.updateGlobalMousePosition(t),o){var r=e?-1:1,i=n.getCorrectPointerPosition(t),a=1+.005*t.deltaY*r;n.emitZoomEvent(a,i)}else n.emit("wheel",{x:-t.deltaX,y:-t.deltaY},{type:"mouse",position:n.getCorrectPointerPosition(t),button:t.button,touchesCount:0})},n.target=e,n.targetBounds=e.getBoundingClientRect(),n.addListeners(),n}return l(e,t),e.prototype.updateTargetBounds=function(){this.targetBounds=this.target.getBoundingClientRect()},e.prototype.addListeners=function(){this.addTouchEventListeners(),this.addMouseEventListeners(),this.addKeyboardEventListeners(),this.addSafariGesturesEventListeners()},e.prototype.addKeyboardEventListeners=function(){var t=this;this.listenersCollector.add(document,"keydown",(function(e){"Control"===e.key&&(t.state.isCtrlPressed=!0)})),this.listenersCollector.add(document,"keyup",(function(e){"Control"===e.key&&(t.state.isCtrlPressed=!1)})),this.listenersCollector.add(document,"contextmenu",(function(e){e.ctrlKey&&(t.state.isCtrlPressed=!1)}))},e.prototype.addMouseEventListeners=function(){this.listenersCollector.add(this.target,"mousedown",this.handleMouseDown),this.listenersCollector.add(this.target,"mousemove",this.handleMouseMove),this.listenersCollector.add(document,"mousemove",this.handleGlobalMouseMove),this.listenersCollector.add(document,"mouseup",this.handleMouseUp),this.listenersCollector.add(this.target,"wheel",this.handleMouseWheel)},e.prototype.addTouchEventListeners=function(){this.listenersCollector.add(this.target,"touchstart",this.handleTouchStart),this.listenersCollector.add(document,"touchmove",this.handleGlobalTouchMove,{passive:!0,capture:!0}),this.listenersCollector.add(this.target,"touchmove",this.handleTouchMove,{passive:!0,capture:!0}),this.listenersCollector.add(document,"touchcancel",this.handleTouchEnd),this.listenersCollector.add(document,"touchend",this.handleTouchEnd)},e.prototype.addSafariGesturesEventListeners=function(){Z()||(this.listenersCollector.add(this.target,"gesturestart",this.handleGestureStart,{capture:!0}),this.listenersCollector.add(this.target,"gesturechange",this.handleGestureChange,{capture:!0}),this.listenersCollector.add(this.target,"gestureend",this.handleGestureEnd,{capture:!0}))},e.prototype.clampPointerToTargetBounds=function(t){return{x:A(t.x-this.targetBounds.x,0,this.target.clientWidth),y:A(t.y-this.targetBounds.y,0,this.target.clientHeight)}},e.prototype.getCorrectPointerPosition=function(t){var e,n={x:0,y:0};if((null===(e=t.touches)||void 0===e?void 0:e.length)>1){var o=t,r=o.touches[0],i=o.touches[1];n={x:(r.clientX+i.clientX)/2,y:(r.clientY+i.clientY)/2}}else n=U(t);return this.clampPointerToTargetBounds(n)},e.prototype.updateMousePosition=function(t){this.emit("pointermove",{type:"mouse",position:this.getCorrectPointerPosition(t),button:t.button,touchesCount:0})},e.prototype.updateGlobalMousePosition=function(t){this.emit("globalpointermove",{type:"mouse",position:this.getCorrectPointerPosition(t),button:t.button,touchesCount:0})},e.prototype.calculateDistanceBetweenTouches=function(t,e){return Math.hypot(t.clientX-e.clientX,t.clientY-e.clientY)},e.prototype.emitZoomEvent=function(t,e){this.emit("pinchToZoom",t,e)},e.prototype.dispose=function(){this.listenersCollector.dispose()},e}(x),N=function(t){function e(e){var n=t.call(this)||this;return n.listenersCollector=new S,n.handleKeyUp=function(t){n.emit("keyUp",t.code)},n.target=e,n.addListeners(),n}return l(e,t),e.prototype.addListeners=function(){this.listenersCollector.add(this.target,"keyup",this.handleKeyUp)},e.prototype.dispose=function(){this.listenersCollector.dispose()},e}(x),j=function(){function t(t){this.label=t,this.startTime=performance.now(),this.startTimestamp=Date.now()}return t.prototype.measure=function(){return{duration:performance.now()-this.startTime,end:Date.now(),start:this.startTimestamp,id:this.label}},t.prototype.printMeasurement=function(){var t=this.measure().duration;if(t<1e3){var e=t.toFixed(2);return"[Performance] ".concat(this.label," -> ").concat(e," ms")}var n=(t/1e3).toFixed(2);return"[Performance] ".concat(this.label," -> ").concat(n," s")},t}();function K(t){setTimeout((function(){t()}),0)}var H=new(function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return l(e,t),e.prototype.logDebug=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.emit.apply(this,v(["log","debug"],t,!1))},e.prototype.logWarning=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.emit.apply(this,v(["log","warn"],t,!1))},e.prototype.logError=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.emit.apply(this,v(["log","error"],t,!1))},e}(x)),V=function(t){function e(e){var n=t.call(this)||this;return n.listenersCollector=new S,n.size={width:0,height:0},n.pixelRatio=1,n.handleCanvasResizeObserver=function(t){n.resizeCanvas(t[0].contentRect)},n.resizeCanvas=function(t){var e=t.width,o=t.height;window.requestAnimationFrame((function(){n.setSize(e,o),n.emit("resize",e,o,n.getDevicePixelRatio())}))},n.getCanvasCenterPoint=function(){var t=n.getBoundingClientRect();return{x:t.width/2+t.x,y:t.height/2+t.y}},n.container=e.container,n.canvas=e.canvas,n.canvasResizeObserver=new ResizeObserver(n.handleCanvasResizeObserver),n.canvasResizeObserver.observe(n.container),n.listenersCollector.add(window,"orientationchange",n.handleDeviceOrientationChange),n.setSize(n.container.clientWidth,n.container.clientHeight),n}return l(e,t),e.prototype.setSize=function(t,e){this.pixelRatio=this.getDevicePixelRatio(),this.canvas.style.width="".concat(t,"px"),this.canvas.style.height="".concat(e,"px"),this.size.width=t*this.pixelRatio,this.size.height=e*this.pixelRatio,this.canvas.width=this.size.width,this.canvas.height=this.size.height},e.prototype.handleDeviceOrientationChange=function(){this.resizeCanvas({width:this.container.clientWidth,height:this.container.clientHeight})},e.prototype.getDevicePixelRatio=function(){return A(window.devicePixelRatio,1,2)},e.prototype.getBoundingClientRect=function(){return this.canvas.getBoundingClientRect()},e.prototype.dispose=function(){this.detachAllListeners(),this.canvasResizeObserver.disconnect(),this.listenersCollector.dispose()},e}(x),$=function(){function t(t){this.settings=t}return t.prototype.isReleaseMode=function(){return this.settings.mode===R.release},t.prototype.init=function(){return h(this,void 0,void 0,(function(){var t,e,n,o,r,i=this;return p(this,(function(a){switch(a.label){case 0:return[4,this.importModule()];case 1:t=a.sent(),e=t.default,a.label=2;case 2:return a.trys.push([2,4,,5]),n=this,[4,e({FeatureFlags:this.settings.featureFlags,currentWebGLVersion:B(),bridge:this.settings.jsBridge,locateFile:function(t){return i.settings.locateFile.replace("{file}",t)}})];case 3:return n.instance=a.sent(),[3,5];case 4:throw o=a.sent(),new W("WASM_ERROR","An error occurred while trying to create the wasm module.",o);case 5:return this.pointerTypeToWASMMap={unset:this.instance.PRUserPointerType.Unset,mouse:this.instance.PRUserPointerType.Mouse,touch:this.instance.PRUserPointerType.Touch},this.prCursorTypeToCSSCursorMap=((r={})[this.instance.PRCursorType.Auto.value]="auto",r[this.instance.PRCursorType.Default.value]="default",r[this.instance.PRCursorType.Pointer.value]="pointer",r[this.instance.PRCursorType.Grab.value]="grab",r[this.instance.PRCursorType.Grabbing.value]="grabbing",r),[2]}}))}))},t.prototype.makeWebGLContext=function(t,e){void 0===e&&(e={});var n=d({antialias:!1,alpha:!1,stencil:!1,depth:!1,powerPreference:"high-performance",preserveDrawingBuffer:!1,desynchronized:!0},e),o=this.instance.GL.createContext(t,n);if(!o)throw new W("WEBGL_ERROR","Unable to create WebGL context. WebGL might be unsupported, disabled, or this device is not able to run WebGL correctly.");return o},t.prototype.destroyWebGLContext=function(t){var e;H.logDebug("Destroying WebGL context");var n=null===(e=this.instance)||void 0===e?void 0:e.GL.getContext(t);if(n){this.instance.GL.deleteContext(t);var o=n.GLctx.getExtension("WEBGL_lose_context");if(o)return o.loseContext(),H.logDebug("WebGL destroyed"),!0;H.logError("WEBGL_lose_context not available. Not possible to destroy WebGL context manually.")}else H.logError("WebGL context not found while trying to destroy it")},t.prototype.importModule=function(){return this.isReleaseMode()?import("./module-release-75cbbdeb.js"):import("./module-debug-ef74ce0a.js")},t.prototype.mapToCSSCursor=function(t){return this.prCursorTypeToCSSCursorMap[t.value]},t.prototype.mapToPRPointerType=function(t){var e;return null!==(e=this.pointerTypeToWASMMap[t])&&void 0!==e?e:this.instance.PRUserPointerType.Unset},t.prototype.mapPointerInfo=function(t){return d(d({},t),{type:this.mapToPRPointerType(t.type)})},t}(),Y=function(t){function e(e){var n=t.call(this)||this;return n.status={type:"IDLE"},n.disposed=!1,n.handleCanvasResize=function(t,e,o){var r;null===(r=n.pageCanvasWasm)||void 0===r||r.resize(t,e,o)},n.handleWebGLContextLost=function(){n.setStatus({type:"WEBGL_CONTEXT_LOST"})},n.handlePinchToZoomEvent=function(t,e){var o;null===(o=n.userEventsCollectorWasm)||void 0===o||o.dispatchPinchToZoomEvent(t,e.x,e.y)},n.handleWheelEvent=function(t,e){var o;n.wasmModule&&(null===(o=n.userEventsCollectorWasm)||void 0===o||o.dispatchWheelEvent(t.x,t.y,n.wasmModule.mapPointerInfo(e)))},n.handlePointerDownEvent=function(t){var e;n.wasmModule&&(null===(e=n.userEventsCollectorWasm)||void 0===e||e.dispatchPointerDownEvent(n.wasmModule.mapPointerInfo(t)))},n.handlePointerMoveEvent=function(t){var e;n.wasmModule&&(null===(e=n.userEventsCollectorWasm)||void 0===e||e.dispatchPointerMoveEvent(n.wasmModule.mapPointerInfo(t)))},n.handleGlobalPointerMoveEvent=function(t){var e;n.wasmModule&&(null===(e=n.userEventsCollectorWasm)||void 0===e||e.dispatchGlobalPointerMoveEvent(n.wasmModule.mapPointerInfo(t)))},n.handlePointerUpEvent=function(t){var e;n.wasmModule&&(null===(e=n.userEventsCollectorWasm)||void 0===e||e.dispatchPointerUpEvent(n.wasmModule.mapPointerInfo(t)))},n.settings=d(d({backgroundColor:{r:1,g:1,b:1,a:1},showTilesBorders:!1,preserveDrawingBuffer:!1,panBoundariesPadding:0},z(e)),{featureFlags:d(d({},I),e.featureFlags)}),n.gestureManager=new O(n.settings.container),n.canvasManager=new V({container:n.settings.container,canvas:n.settings.canvas}),n.wasmModule=new $({mode:n.settings.mode,locateFile:n.settings.locateFile,jsBridge:n.createJSBridge(),featureFlags:n.settings.featureFlags}),n.fetchWorker=new Worker(n.settings.locateFile.replace("{file}","fetch-worker.js")),n.settings.manualInitialization||n.init(),n}return l(e,t),e.prototype.addListeners=function(){this.canvasManager.on("resize",this.handleCanvasResize),this.gestureManager.on("wheel",this.handleWheelEvent),this.gestureManager.on("pointerup",this.handlePointerUpEvent),this.gestureManager.on("pointermove",this.handlePointerMoveEvent),this.gestureManager.on("globalpointermove",this.handleGlobalPointerMoveEvent),this.gestureManager.on("pointerdown",this.handlePointerDownEvent),this.gestureManager.on("pinchToZoom",this.handlePinchToZoomEvent),this.settings.canvas.addEventListener("webglcontextlost",this.handleWebGLContextLost)},e.prototype.collectAndEmitDeviceInfo=function(){return h(this,void 0,void 0,(function(){var t;return p(this,(function(e){switch(e.label){case 0:return[4,L()];case 1:return t=e.sent(),this.deviceInfo=d(d({},t),{hardwareConcurrency:navigator.hardwareConcurrency}),this.emit("deviceInfo",this.deviceInfo),[2]}}))}))},e.prototype.init=function(){return h(this,void 0,void 0,(function(){var t;return p(this,(function(e){switch(e.label){case 0:this.traceFirstPaint=new j("FirstPaint"),this.setStatus({type:"INITIALIZING"}),this.collectAndEmitDeviceInfo(),e.label=1;case 1:return e.trys.push([1,5,,6]),[4,this.initWasmModule()];case 2:return e.sent(),[4,this.initCanvasRendererWasm()];case 3:return e.sent(),[4,this.setFile(this.settings.filePath)];case 4:return e.sent(),[3,6];case 5:return t=e.sent(),[2,this.fail(t instanceof W?t:new W("ERROR","Unexpected exception initializing the web renderer",t))];case 6:return this.setInitialCameraState(),this.startRendering(),this.addListeners(),[2]}}))}))},e.prototype.setInitialCameraState=function(){var t,e,n,o=void 0!==this.settings.initialZoom,r=void 0!==this.settings.initialPan;o||r?(o&&this.setZoom(this.settings.initialZoom||1),r&&this.setPan((null===(t=this.settings.initialPan)||void 0===t?void 0:t.x)||0,(null===(e=this.settings.initialPan)||void 0===e?void 0:e.y)||0,null===(n=this.settings.initialPan)||void 0===n?void 0:n.centerPointInViewport)):this.zoomToFit()},e.prototype.startRendering=function(){var t;this.traceInitialRender=new j("InitialRender"),this.setStatus({type:"DRAWING_FILE"}),null===(t=this.pageCanvasWasm)||void 0===t||t.startRenderLoop()},e.prototype.createJSBridge=function(){var t=this;return{logDebug:function(t){H.logDebug("[C++] ".concat(t))},logWarning:function(t){H.logWarning("[C++] ".concat(t))},logError:function(t){H.logError("[C++] ".concat(t))},emitMetric:function(e,n,o,r){t.emit("metric",{id:e,start:n,end:o,duration:r})},resolveImageUrl:function(e){return t.settings.imagesURLFormat?t.settings.imagesURLFormat.replace(":imageId",e):t.settings.imagesURLMap&&t.settings.imagesURLMap[e]?t.settings.imagesURLMap[e]:(H.logWarning("Not able to resolve the url for the image with UUID: ".concat(e)),"")},resolveFragmentUrl:function(e){return t.settings.fragmentsURLFormat?t.settings.fragmentsURLFormat.replace(":fragmentId",e):t.settings.fragmentsURLMap&&t.settings.fragmentsURLMap[e]?t.settings.fragmentsURLMap[e]:(H.logWarning("Not able to resolve the url for the fragment with UUID: ".concat(e)),"")},onDrawComplete:this.handleDrawComplete.bind(this),onAllImagesReady:function(){t.emit("allImagesReady")},onCameraMoveStart:function(){t.emit("cameraMoveStart")},onCameraMoveEnd:function(){t.emit("cameraMoveEnd")},onCameraZoomStart:function(){t.emit("cameraZoomStart")},onCameraZoomEnd:function(){t.emit("cameraZoomEnd")},onCameraZoomChange:function(e){t.emit("cameraZoomChange",e)},onCameraPanChange:function(){var e=t.getPan();t.emit("cameraPanChange",(null==e?void 0:e.x)||0,(null==e?void 0:e.y)||0)},onCursorChange:function(e){var n,o=null===(n=t.wasmModule)||void 0===n?void 0:n.mapToCSSCursor(e);o&&t.emit("cursorChange",o)},onPrototypeStateChange:function(){},fetch:this.handleJSBridgeFetch.bind(this),abortFetch:this.handleJSBridgeAbortFetch.bind(this)}},e.prototype.handleJSBridgeFetch=function(t,e){var n=this,o=e.clone(),r=function(e){var i,a,s,u;if(!n.disposed&&e.data.url===t){switch(e.data.type){case"success":o.exec(new Uint8Array(e.data.buffer),200,"");break;case"error":H.logError("Error while fetching ".concat(t),e.data.error),o.exec(new Uint8Array(0),null!==(a=null===(i=e.data.error)||void 0===i?void 0:i.statusCode)&&void 0!==a?a:500,null!==(u=null===(s=e.data.error)||void 0===s?void 0:s.statusText)&&void 0!==u?u:"Unknown error")}n.fetchWorker.removeEventListener("message",r)}};this.fetchWorker.addEventListener("message",r),this.fetchWorker.postMessage({type:"fetch",url:t})},e.prototype.handleJSBridgeAbortFetch=function(t){this.fetchWorker.postMessage({type:"abort",url:t})},e.prototype.initWasmModule=function(){var t;return h(this,void 0,void 0,(function(){var e;return p(this,(function(n){switch(n.label){case 0:return this.disposed?[2]:(e=new j("WasmModuleDownload"),[4,null===(t=this.wasmModule)||void 0===t?void 0:t.init()]);case 1:return n.sent(),H.logDebug(e.printMeasurement()),this.emit("metric",e.measure()),[2]}}))}))},e.prototype.initCanvasRendererWasm=function(){return h(this,void 0,void 0,(function(){var t;return p(this,(function(e){if(this.disposed)return[2];try{if(!this.wasmModule)throw Error("WASM module not initialized");t=B(),H.logDebug("Using WebGL ".concat(t)),this.webglCtxHandle=this.wasmModule.makeWebGLContext(this.settings.canvas,{preserveDrawingBuffer:this.settings.preserveDrawingBuffer,majorVersion:t}),this.renderTarget=this.wasmModule.instance.RenderTarget.MakeWebGL(this.webglCtxHandle,this.canvasManager.size.width,this.canvasManager.size.height,this.canvasManager.pixelRatio),this.pageCanvasWasm=new this.wasmModule.instance.CanvasRenderer(this.renderTarget,{showTilesBorders:this.settings.showTilesBorders})}catch(t){throw new W("WASM_ERROR","An error occurred while trying to create the wasm object.",t)}return this.userEventsCollectorWasm=this.pageCanvasWasm.getUserEventsCollector(),this.pageCanvasWasm.setBackgroundColor(this.settings.backgroundColor.r,this.settings.backgroundColor.g,this.settings.backgroundColor.b,this.settings.backgroundColor.a),this.pageCanvasWasm.setZoomLevels(this.settings.minimumZoomLevel,this.settings.maximumZoomLevel),this.pageCanvasWasm.setPanBoundariesPadding(this.settings.panBoundariesPadding),[2]}))}))},e.prototype.setIsCameraLocked=function(t){var e;null===(e=this.pageCanvasWasm)||void 0===e||e.setIsCameraLocked(t)},e.prototype.setBackgroundColor=function(t){var e;t.r===this.settings.backgroundColor.r&&t.g===this.settings.backgroundColor.g&&t.b===this.settings.backgroundColor.b&&t.a===this.settings.backgroundColor.a||(null===(e=this.pageCanvasWasm)||void 0===e||e.setBackgroundColor(t.r,t.g,t.b,t.a),this.settings.backgroundColor=t)},e.prototype.generateDocumentPNG=function(){var t;return h(this,void 0,void 0,(function(){return p(this,(function(e){return[2,null===(t=this.pageCanvasWasm)||void 0===t?void 0:t.generateDocumentPNG()]}))}))},e.prototype.handleDrawComplete=function(){"DRAWING_FILE"===this.status.type&&(H.logDebug(this.traceInitialRender.printMeasurement()),this.emit("metric",this.traceInitialRender.measure()),H.logDebug(this.traceFirstPaint.printMeasurement()),this.emit("metric",this.traceFirstPaint.measure()),this.setStatus({type:"READY"}))},e.prototype.looseWebGLContext=function(){var t;(null===(t=this.wasmModule)||void 0===t?void 0:t.destroyWebGLContext(this.webglCtxHandle))||H.logWarning("Failed to loose WebGL context"),this.webglCtxHandle=-1},e.prototype.zoomToFit=function(){var t;null===(t=this.pageCanvasWasm)||void 0===t||t.scaleDocumentToFit()},e.prototype.setFile=function(t){return h(this,void 0,void 0,(function(){var e=this;return p(this,(function(n){return this.disposed?[2]:(this.setStatus({type:"LOADING_FILE"}),[2,new Promise((function(n,o){var r;null===(r=e.pageCanvasWasm)||void 0===r||r.setFile(t,(function(t,o,r){e.setStatus({type:"FILE_READY"});var i="".concat(t,"-v").concat("6.3.0");e.emit("fileReady",e.getDocument(),i,o,r),n()}),(function(){return o(new W("FILE_ERROR","Error encountered while fetching and parsing the file"))}))}))])}))}))},e.prototype.fail=function(t){this.setStatus({type:"FAILURE",code:t.code,message:"".concat(t.toString()).concat(t.cause?"\nWrapped Error: ".concat(t.cause.toString()):"")}),H.logError(t),t.cause&&H.logError(t.cause)},e.prototype.setStatus=function(t){"FAILURE"!==this.status.type&&(H.logDebug("Status transition ".concat(this.status.type," => ").concat(t.type)),this.status=t,this.emit("status",t))},e.prototype.getDocument=function(){if(!this.pageCanvasWasm)return{artboards:[],bounds:{x:0,y:0,width:0,height:0}};if(!this.cachedDocumentInfo||this.cachedDocumentInfo.filePath!==this.settings.filePath){var t=this.pageCanvasWasm.getPRFile();this.cachedDocumentInfo={filePath:this.settings.filePath,document:d(d({},t),{artboards:G(t.artboards)})}}return this.cachedDocumentInfo.document},e.prototype.getArtboardAtPosition=function(t,e){if(this.pageCanvasWasm){var n=this.getDocument();if(n){for(var o=this.pageCanvasWasm.getPan(),r=this.pageCanvasWasm.getZoom(),i=(t-o.x)/r,a=(e-o.y)/r,s=0,u=n.artboards;s<u.length;s++){var c=u[s],l=c.bounds.x+c.bounds.width,d=c.bounds.y+c.bounds.height;if(i>=c.bounds.x&&a>=c.bounds.y&&i<=l&&a<=d)return c.objectId}return null}}},e.prototype.getPanAtPosition=function(t,e){var n=this.getPan(),o=Math.max(this.getZoom(),Number.EPSILON),r=t/o,i=e/o;return{x:n.x-r,y:n.y-i}},e.prototype.getStatus=function(){return this.status},e.prototype.setZoom=function(t,e){var n,o=null!=e?e:this.canvasManager.getCanvasCenterPoint();null===(n=this.pageCanvasWasm)||void 0===n||n.setZoom(t,o.x,o.y)},e.prototype.getPan=function(){var t,e,n=this.getDocument().bounds,o=null===(t=this.pageCanvasWasm)||void 0===t?void 0:t.getPan(),r=null===(e=this.pageCanvasWasm)||void 0===e?void 0:e.getZoom();return o&&r?{x:o.x/r+n.x,y:o.y/r+n.y}:{x:0,y:0}},e.prototype.getZoom=function(){var t;return(null===(t=this.pageCanvasWasm)||void 0===t?void 0:t.getZoom())||0},e.prototype.setPan=function(t,e,n){var o;void 0===n&&(n=!1);var r=t,i=e,a=this.getDocument().bounds,s=this.getZoom();if(n){var u=Math.max(2*s*this.canvasManager.pixelRatio,Number.EPSILON);r+=this.canvasManager.size.width/u,i+=this.canvasManager.size.height/u}var c=(r-a.x)*s,l=(i-a.y)*s;null===(o=this.pageCanvasWasm)||void 0===o||o.setPan(c,l)},e.prototype.disposeFetchWorker=function(){this.fetchWorker.postMessage({type:"abort-all"}),this.fetchWorker.terminate()},e.prototype.dispose=function(){var t,e,n,o;try{this.disposed=!0,this.detachAllListeners(),null===(t=this.wasmModule)||void 0===t||t.destroyWebGLContext(this.webglCtxHandle),this.canvasManager.dispose(),this.gestureManager.dispose(),null===(e=this.pageCanvasWasm)||void 0===e||e.stopRenderLoop(),null===(n=this.pageCanvasWasm)||void 0===n||n.delete(),null===(o=this.renderTarget)||void 0===o||o.delete(),this.disposeFetchWorker(),this.fetchWorker.terminate(),this.pageCanvasWasm=void 0,this.wasmModule=void 0}catch(t){this.fail(new W("ERROR","Unexpected exception while disposing the wasm object",t))}},e}(x),J=e(void 0),X=e(void 0),q=e(void 0),Q=e(void 0),tt=e(void 0),et=e(void 0),nt=e("auto"),ot=e(void 0),rt=function(){var t=n(ot);if(void 0===t)throw Error("useInternalContext must be used within a provider");return t},it=function(t,e){switch(e.type){case"on-status":return d(d({},t),{status:e.status});case"on-file-ready":return d(d({},t),{document:e.document});case"on-zoom":return d(d({},t),{zoom:e.zoom});case"on-pan":return d(d({},t),{pan:e.pan});case"dispose":return d(d({},t),{status:{type:"DISPOSED"},zoom:null,pan:null,cursor:"auto"});case"on-camera-zoom-start":return d(d({},t),{isCameraZooming:!0});case"on-camera-zoom-end":return d(d({},t),{isCameraZooming:!1});case"on-camera-move-start":return d(d({},t),{isCameraMoving:!0});case"on-camera-move-end":return d(d({},t),{isCameraMoving:!1});case"on-cursor-change":return d(d({},t),{cursor:e.cursor});default:return t}},at=function(e){var n=o(null),s=o(null),u=r(it,{pan:null,zoom:null,status:{type:"IDLE"},document:null,isCameraZooming:!1,isCameraMoving:!1,cursor:"auto"}),c=u[0],l=c.status,h=c.document,p=c.zoom,v=c.pan,g=c.isCameraZooming,f=c.isCameraMoving,m=c.cursor,y=u[1],C=i((function(t){return y({type:"on-zoom",zoom:t})}),[]),w=i((function(t,e){return y({type:"on-pan",pan:{x:t,y:e}})}),[]),b=i((function(t){y({type:"on-status",status:t})}),[]),P=i((function(t){y({type:"on-file-ready",document:t})}),[]),E=i((function(){return y({type:"on-camera-zoom-start"})}),[]),M=i((function(){return y({type:"on-camera-zoom-end"})}),[]),L=i((function(){return y({type:"on-camera-move-start"})}),[]),R=i((function(){return y({type:"on-camera-move-end"})}),[]),W=i((function(t){return y({type:"on-cursor-change",cursor:t})}),[]),x=i((function(){var t=n.current;t&&(H.logDebug("Provider dispose"),t.off("status",b),t.off("fileReady",P),t.off("cameraZoomChange",C),t.off("cameraPanChange",w),t.off("cameraZoomStart",E),t.off("cameraZoomEnd",M),t.off("cameraMoveStart",L),t.off("cameraMoveEnd",R),t.off("cursorChange",W),t.dispose(),n.current=null,y({type:"dispose"}))}),[b,P,w,C,E,M,L,R,W]),S=i((function(t,e,o){if(""!==t&&e&&o&&s.current){H.logDebug("Provider init");var r=new Y(d(d({},s.current),{filePath:t,container:o,canvas:e,manualInitialization:!0}));r.on("status",b),r.on("fileReady",P),r.on("cameraZoomChange",C),r.on("cameraPanChange",w),r.on("cameraZoomStart",E),r.on("cameraZoomEnd",M),r.on("cameraMoveStart",L),r.on("cameraMoveEnd",R),r.on("cursorChange",W),n.current=r,r.init()}}),[b,P,C,w,E,M,L,R,W]),I=i((function(t){var e;H.logDebug("Provider setSettings",t),t.backgroundColor&&(null===(e=n.current)||void 0===e||e.setBackgroundColor(t.backgroundColor)),s.current=t}),[]),D=i((function(){return n.current}),[]),T=a((function(){return{dispose:x,init:S,setSettings:I,getInstance:D,dispatch:y}}),[x,S,I,D]);return t.createElement(ot.Provider,{value:T},t.createElement(J.Provider,{value:l},t.createElement(X.Provider,{value:h},t.createElement(q.Provider,{value:p},t.createElement(et.Provider,{value:v},t.createElement(Q.Provider,{value:g},t.createElement(tt.Provider,{value:f},t.createElement(nt.Provider,{value:m},e.children))))))))},st=function(){var t=n(J);if(void 0===t)throw Error("useStatus must be used within a provider");return t},ut=function(){var t=n(X);if(void 0===t)throw Error("useDocument must be used within a provider");return t},ct=function(){var t=n(q);if(void 0===t)throw Error("useZoom must be used within a provider");return t},lt=function(){var t=n(et);if(void 0===t)throw Error("usePan must be used within a provider");return t},dt=function(){var t=n(nt);if(void 0===t)throw Error("useCursor must be used within a provider");return t},ht=function(){var t=n(Q);if(void 0===status)throw Error("useIsCameraZooming must be used within a provider");return t},pt=function(){var t=n(tt);if(void 0===status)throw Error("useIsCameraMoving must be used within a provider");return t},vt=function(){var t=(0,rt().getInstance)();return i((function(e){null==t||t.setZoom(e)}),[t])},gt=function(){var t=vt(),e=ct();return i((function(){var n;"number"==typeof e&&(n=e>=1?Math.round(2*e):e>.5?1:2*e,t(n))}),[t,e])},ft=function(){var t=vt(),e=ct();return i((function(){"number"==typeof e&&t(e/2)}),[t,e])},mt=function(){var t=(0,rt().getInstance)();return i((function(e){var n=e.x,o=e.y,r=e.centerPointInViewport;null==t||t.setPan(n,o,r)}),[t])},yt=function(){var t=(0,rt().getInstance)();return i((function(){null==t||t.zoomToFit()}),[t])},Ct=function(){var t=(0,rt().getInstance)();return i((function(){null==t||t.looseWebGLContext()}),[t])},wt=function(){var t=(0,rt().getInstance)();return i((function(){return h(void 0,void 0,void 0,(function(){return p(this,(function(e){switch(e.label){case 0:return[4,null==t?void 0:t.generateDocumentPNG()];case 1:return[2,e.sent()]}}))}))}),[t])},bt=function(){var t=(0,rt().getInstance)();return i((function(e,n){return h(void 0,void 0,void 0,(function(){return p(this,(function(o){switch(o.label){case 0:return[4,null==t?void 0:t.getArtboardAtPosition(e,n)];case 1:return[2,o.sent()||null]}}))}))}),[t])},Pt=function(){var t=(0,rt().getInstance)();return i((function(e,n){return h(void 0,void 0,void 0,(function(){return p(this,(function(o){switch(o.label){case 0:return[4,null==t?void 0:t.getPanAtPosition(e,n)];case 1:return[2,o.sent()||null]}}))}))}),[t])},Et=function(){var t=(0,rt().getInstance)();return i((function(e){null==t||t.setIsCameraLocked(e)}),[t])},Mt=function(t,e){var n=(0,rt().getInstance)();s((function(){return null==n||n.on(t,e),function(){null==n||n.off(t,e)}}),[t,n,e])};function Lt(t){var e=o(t);e.current=t;var n=i((function(t){for(var n=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];e.current.apply(e,v([t],n,!1))}),[]);s((function(){return H.on("log",n),function(){H.off("log",n)}}),[])}var Rt={position:"relative",width:"100%",height:"100%",touchAction:"manipulation"},Wt={position:"absolute",top:0,left:0},xt=function(e){var n=e.filePath,r=e.locateFile,c=e.imagesURLFormat,l=e.imagesURLMap,h=e.fragmentsURLFormat,p=e.fragmentsURLMap,v=e.backgroundColor,g=e.mode,f=e.showTilesBorders,m=e.minimumZoomLevel,y=e.maximumZoomLevel,C=e.preserveDrawingBuffer,w=e.panBoundariesPadding,b=e.initialPan,P=e.initialZoom,E=e.children,M=e.containerProps,L=void 0===M?{}:M,R=e.canvasProps,W=void 0===R?{}:R,x=e.featureFlags,S=void 0===x?{}:x,I=o(null),D=o(null),T=u(!1),k=T[0],F=T[1],U=i((function(){return F(!0)}),[]),A=rt(),B=A.dispose,G=A.init,Z=A.setSettings,z=dt(),_=st();Mt("allImagesReady",U),s((function(){return H.logDebug("WebRenderer mounted"),function(){return H.logDebug("WebRenderer unmounted")}}),[]),s((function(){Z({locateFile:r,imagesURLFormat:c,imagesURLMap:l,fragmentsURLFormat:h,fragmentsURLMap:p,backgroundColor:v,mode:g,showTilesBorders:f,minimumZoomLevel:m,maximumZoomLevel:y,preserveDrawingBuffer:C,panBoundariesPadding:w,initialPan:b,initialZoom:P,featureFlags:S})}),[Z,r,c,l,h,p,v,g,f,m,y,C,w,b,P,S]),s((function(){if(n)return G(n,I.current,D.current),function(){B()}}),[B,G,n]);var O=a((function(){var t;return null!==(t=e.cursor)&&void 0!==t?t:z}),[e.cursor,z]),N=a((function(){return d(d({},Rt),{cursor:O})}),[O]);return t.createElement("div",d({},L,{ref:D,style:N}),n&&t.createElement("canvas",d({},W,{key:n,ref:I,"data-sketchweb-all-images-ready":k,"data-testid":"sketchweb-canvas","data-sketchweb-status":"sketchweb-status-".concat((null==_?void 0:_.type.toLowerCase())||"null"),style:Wt})),"READY"===(null==_?void 0:_.type)&&E)},St=function(t){function e(e){var n=t.call(this)||this;return n.status={type:"IDLE"},n.disposed=!1,n.handleCanvasResize=function(t,e,o){var r;null===(r=n.playerWasm)||void 0===r||r.resize(t,e,o)},n.handleWebGLContextLost=function(){n.setStatus({type:"WEBGL_CONTEXT_LOST"})},n.handlePinchToZoomEvent=function(t,e){var o;null===(o=n.userEventsCollectorWasm)||void 0===o||o.dispatchPinchToZoomEvent(t,e.x,e.y)},n.handleWheelEvent=function(t,e){var o;n.wasmModule&&n.userEventsCollectorWasm.dispatchWheelEvent(t.x,t.y,null===(o=n.wasmModule)||void 0===o?void 0:o.mapPointerInfo(e))},n.handlePointerDownEvent=function(t){var e;n.wasmModule&&n.userEventsCollectorWasm.dispatchPointerDownEvent(null===(e=n.wasmModule)||void 0===e?void 0:e.mapPointerInfo(t))},n.handlePointerMoveEvent=function(t){var e;n.wasmModule&&n.userEventsCollectorWasm.dispatchPointerMoveEvent(null===(e=n.wasmModule)||void 0===e?void 0:e.mapPointerInfo(t))},n.handleGlobalPointerMoveEvent=function(t){var e;n.wasmModule&&n.userEventsCollectorWasm.dispatchGlobalPointerMoveEvent(null===(e=n.wasmModule)||void 0===e?void 0:e.mapPointerInfo(t))},n.handlePointerUpEvent=function(t){var e;n.wasmModule&&n.userEventsCollectorWasm.dispatchPointerUpEvent(null===(e=n.wasmModule)||void 0===e?void 0:e.mapPointerInfo(t))},n.restartPrototype=function(t){var e;null===(e=n.playerWasm)||void 0===e||e.restartPrototype(t)},n.goBack=function(){var t;null===(t=n.playerWasm)||void 0===t||t.goBack()},n.goForwards=function(){var t;null===(t=n.playerWasm)||void 0===t||t.goForwards()},n.settings=d(d({backgroundColor:{r:1,g:1,b:1,a:1},showTilesBorders:!1,preserveDrawingBuffer:!1},z(e)),{featureFlags:d(d({},I),e.featureFlags)}),n.gestureManager=new O(n.settings.container),n.canvasManager=new V({container:n.settings.container,canvas:n.settings.canvas}),n.wasmModule=new $({mode:n.settings.mode,locateFile:n.settings.locateFile,jsBridge:n.createJSBridge(),featureFlags:n.settings.featureFlags}),n.fetchWorker=new Worker(n.settings.locateFile.replace("{file}","fetch-worker.js")),n.settings.manualInitialization||n.init(),n}return l(e,t),e.prototype.addListeners=function(){this.canvasManager.on("resize",this.handleCanvasResize),this.gestureManager.on("wheel",this.handleWheelEvent),this.gestureManager.on("pointerup",this.handlePointerUpEvent),this.gestureManager.on("pointermove",this.handlePointerMoveEvent),this.gestureManager.on("globalpointermove",this.handleGlobalPointerMoveEvent),this.gestureManager.on("pointerdown",this.handlePointerDownEvent),this.gestureManager.on("pinchToZoom",this.handlePinchToZoomEvent),this.settings.canvas.addEventListener("webglcontextlost",this.handleWebGLContextLost)},e.prototype.collectAndEmitDeviceInfo=function(){return h(this,void 0,void 0,(function(){var t;return p(this,(function(e){switch(e.label){case 0:return[4,L()];case 1:return t=e.sent(),this.deviceInfo=d(d({},t),{hardwareConcurrency:navigator.hardwareConcurrency}),this.emit("deviceInfo",this.deviceInfo),[2]}}))}))},e.prototype.init=function(){return h(this,void 0,void 0,(function(){var t;return p(this,(function(e){switch(e.label){case 0:this.traceFirstPaint=new j("FirstPaint"),this.setStatus({type:"INITIALIZING"}),this.collectAndEmitDeviceInfo(),e.label=1;case 1:return e.trys.push([1,5,,6]),[4,this.initWasmModule()];case 2:return e.sent(),[4,this.initPlayerWasm()];case 3:return e.sent(),[4,this.startDownload()];case 4:return e.sent(),[3,6];case 5:return t=e.sent(),[2,this.fail(t instanceof W?t:new W("ERROR","Unexpected exception initializing the web renderer",t))];case 6:return this.startRendering(),this.addListeners(),[2]}}))}))},e.prototype.initWasmModule=function(){var t;return h(this,void 0,void 0,(function(){var e;return p(this,(function(n){switch(n.label){case 0:return e=new j("WasmModuleDownload"),[4,null===(t=this.wasmModule)||void 0===t?void 0:t.init()];case 1:return n.sent(),e.printMeasurement(),this.emit("metric",e.measure()),[2]}}))}))},e.prototype.startDownload=function(){var t=this;return this.setStatus({type:"LOADING_FILE"}),new Promise((function(e){var n;null===(n=t.playerWasm)||void 0===n||n.startDownload((function(){e()}),(function(){console.error("Error loading file")}))}))},e.prototype.startRendering=function(){var t;this.traceInitialRender=new j("InitialRender"),this.setStatus({type:"DRAWING_FILE"}),null===(t=this.playerWasm)||void 0===t||t.startRenderLoop()},e.prototype.createJSBridge=function(){var t=this;return{logDebug:function(t){H.logDebug("[C++] ".concat(t))},logWarning:function(t){H.logWarning("[C++] ".concat(t))},logError:function(t){H.logError("[C++] ".concat(t))},emitMetric:function(e,n,o,r){t.emit("metric",{id:e,start:n,end:o,duration:r})},resolveImageUrl:function(e){return t.settings.imagesURLFormat?t.settings.imagesURLFormat.replace(":imageId",e):t.settings.imagesURLMap&&t.settings.imagesURLMap[e]?t.settings.imagesURLMap[e]:(H.logWarning("Not able to resolve the url for the image with UUID: ".concat(e)),"")},resolveFragmentUrl:function(e){return t.settings.fragmentsURLFormat?t.settings.fragmentsURLFormat.replace(":fragmentId",e):t.settings.fragmentsURLMap&&t.settings.fragmentsURLMap[e]?t.settings.fragmentsURLMap[e]:(H.logWarning("Not able to resolve the url for the fragment with UUID: ".concat(e)),"")},onDrawComplete:this.handleDrawComplete.bind(this),onAllImagesReady:function(){t.emit("allImagesReady")},onCameraMoveStart:function(){t.emit("cameraMoveStart")},onCameraMoveEnd:function(){t.emit("cameraMoveEnd")},onCameraZoomStart:function(){t.emit("cameraZoomStart")},onCameraZoomEnd:function(){t.emit("cameraZoomEnd")},onCameraZoomChange:function(e){t.emit("cameraZoomChange",e)},onCameraPanChange:function(e,n){t.emit("cameraPanChange",e,n)},onCursorChange:function(e){var n,o=null===(n=t.wasmModule)||void 0===n?void 0:n.mapToCSSCursor(e);o&&t.emit("cursorChange",o)},onPrototypeStateChange:function(e,n,o){t.emit("prototypeStateChange",{currentArtboardId:e,canGoBack:n,canGoForwards:o})},fetch:this.handleJSBridgeFetch.bind(this),abortFetch:this.handleJSBridgeAbortFetch.bind(this)}},e.prototype.handleJSBridgeFetch=function(t,e){var n=this,o=e.clone(),r=function(e){var i,a,s,u;if(!n.disposed&&e.data.url===t){switch(e.data.type){case"success":o.exec(new Uint8Array(e.data.buffer),200,"");break;case"error":H.logError("Error while fetching ".concat(t),e.data.error),o.exec(new Uint8Array(0),null!==(a=null===(i=e.data.error)||void 0===i?void 0:i.statusCode)&&void 0!==a?a:500,null!==(u=null===(s=e.data.error)||void 0===s?void 0:s.statusText)&&void 0!==u?u:"Unknown error")}n.fetchWorker.removeEventListener("message",r)}};this.fetchWorker.addEventListener("message",r),this.fetchWorker.postMessage({type:"fetch",url:t})},e.prototype.handleJSBridgeAbortFetch=function(t){this.fetchWorker.postMessage({type:"abort",url:t})},e.prototype.initPlayerWasm=function(){var t,e;return h(this,void 0,void 0,(function(){var n,o,r,i,a,s,u,c,l,h,v,g,f,m,y,C,w,b;return p(this,(function(p){try{if(!this.wasmModule)throw Error("WASM module not initialized");for(this.webglCtxHandle=this.wasmModule.makeWebGLContext(this.settings.canvas,{preserveDrawingBuffer:this.settings.preserveDrawingBuffer,majorVersion:B()}),n=this.wasmModule.instance,o=n.RenderTarget,r=n.PrototypeRenderer,i=n.PrototypeStructureArtboardVector,a=n.PrototypeStructureFlowVector,s=n.PrototypeStructureAssetVector,this.renderTarget=o.MakeWebGL(this.webglCtxHandle,this.canvasManager.size.width,this.canvasManager.size.height,this.canvasManager.pixelRatio),u={artboards:new i},c=0,l=this.settings.prototypeStructure.artboards;c<l.length;c++){for(h=l[c],v=new a,g=0,f=null!==(t=h.flows)&&void 0!==t?t:[];g<f.length;g++)m=f[g],v.push_back(m);for(y=new s,C=0,w=null!==(e=h.assets)&&void 0!==e?e:[];C<w.length;C++)b=w[C],y.push_back(b);u.artboards.push_back(d(d({},h),{flows:v,assets:y}))}this.playerWasm=new r(this.renderTarget,{showTilesBorders:this.settings.showTilesBorders},this.settings.startArtboardUUID,u)}catch(t){throw new W("WASM_ERROR","An error occurred while trying to create the PrototypeRenderer WASM object.",t)}return this.userEventsCollectorWasm=this.playerWasm.getUserEventsCollector(),this.playerWasm.setBackgroundColor(this.settings.backgroundColor.r,this.settings.backgroundColor.g,this.settings.backgroundColor.b,this.settings.backgroundColor.a),this.playerWasm.setZoomLevels(this.settings.minimumZoomLevel,this.settings.maximumZoomLevel),[2]}))}))},e.prototype.setIsCameraLocked=function(t){var e;null===(e=this.playerWasm)||void 0===e||e.setIsCameraLocked(t)},e.prototype.setBackgroundColor=function(t){var e;t.r===this.settings.backgroundColor.r&&t.g===this.settings.backgroundColor.g&&t.b===this.settings.backgroundColor.b&&t.a===this.settings.backgroundColor.a||(null===(e=this.playerWasm)||void 0===e||e.setBackgroundColor(t.r,t.g,t.b,t.a),this.settings.backgroundColor=t)},e.prototype.handleDrawComplete=function(){"DRAWING_FILE"===this.status.type&&(this.traceInitialRender.printMeasurement(),this.emit("metric",this.traceInitialRender.measure()),this.traceFirstPaint.printMeasurement(),this.emit("metric",this.traceFirstPaint.measure()),this.setStatus({type:"READY"}))},e.prototype.looseWebGLContext=function(){var t;null===(t=this.wasmModule)||void 0===t||t.destroyWebGLContext(this.webglCtxHandle),this.webglCtxHandle=-1},e.prototype.fail=function(t){this.setStatus({type:"FAILURE",code:t.code,message:"".concat(t.toString()).concat(t.cause?"\nWrapped Error: ".concat(t.cause.toString()):"")}),H.logError(t),t.cause&&H.logError(t.cause)},e.prototype.setStatus=function(t){"FAILURE"!==this.status.type&&(H.logDebug("Status transition ".concat(this.status.type," => ").concat(t.type)),this.status=t,this.emit("status",t))},e.prototype.getStatus=function(){return this.status},e.prototype.dispose=function(){var t,e,n;try{this.detachAllListeners(),null===(t=this.wasmModule)||void 0===t||t.destroyWebGLContext(this.webglCtxHandle),this.canvasManager.dispose(),this.gestureManager.dispose(),null===(e=this.playerWasm)||void 0===e||e.stopRenderLoop(),null===(n=this.playerWasm)||void 0===n||n.delete(),this.renderTarget.delete(),this.playerWasm=void 0,this.wasmModule=void 0,this.disposed=!0}catch(t){this.fail(new W("ERROR","Unexpected exception while disposing the WebRendererWasm object",t))}},e}(x),It=e(void 0),Dt=e("auto"),Tt=e(void 0),kt=e(void 0),Ft=function(){var t=n(kt);if(void 0===t)throw Error("useInternalContext must be used within a provider");return t},Ut=function(t,e){switch(e.type){case"on-status":return d(d({},t),{status:e.status});case"dispose":return d(d({},t),{status:{type:"DISPOSED"},cursor:"auto"});case"on-cursor-change":return d(d({},t),{cursor:e.cursor});case"on-prototype-state-change":return d(d({},t),{prototypeState:d(d({},t.prototypeState),e.prototypeState)});default:return t}},At=function(e){var n=o(null),s=o(null),u=r(Ut,{status:{type:"IDLE"},cursor:"auto",prototypeState:{currentArtboardId:"",canGoBack:!1,canGoForwards:!1}}),c=u[0],l=c.status,h=c.cursor,p=c.prototypeState,v=u[1],g=i((function(t){v({type:"on-status",status:t})}),[]),f=i((function(t){return v({type:"on-cursor-change",cursor:t})}),[]),m=i((function(t){return v({type:"on-prototype-state-change",prototypeState:t})}),[]),y=i((function(){var t=n.current;t&&(H.logDebug("Provider dispose"),t.off("status",g),t.off("cursorChange",f),t.off("prototypeStateChange",m),t.dispose(),n.current=null,v({type:"dispose"}))}),[g,f,m]),C=i((function(t,e){if(t&&e&&s.current){H.logDebug("Provider init");var o=new St(d(d({},s.current),{container:e,canvas:t,manualInitialization:!0}));o.on("status",g),o.on("cursorChange",f),o.on("prototypeStateChange",m),n.current=o,o.init()}}),[g,f,m]),w=i((function(t){var e;H.logDebug("Provider setSettings",t),t.backgroundColor&&(null===(e=n.current)||void 0===e||e.setBackgroundColor(t.backgroundColor)),s.current=t}),[]),b=i((function(){return n.current}),[]),P=a((function(){return{dispose:y,init:C,setSettings:w,getInstance:b,dispatch:v}}),[y,C,w,b]);return t.createElement(kt.Provider,{value:P},t.createElement(It.Provider,{value:l},t.createElement(Dt.Provider,{value:h},t.createElement(Tt.Provider,{value:p},e.children))))},Bt=function(){var t=(0,Ft().getInstance)();return i((function(e){null==t||t.restartPrototype(e)}),[t])},Gt=function(){var t=(0,Ft().getInstance)();return i((function(){null==t||t.goBack()}),[t])},Zt=function(){var t=(0,Ft().getInstance)();return i((function(){null==t||t.goForwards()}),[t])},zt=function(){var t=n(It);if(void 0===t)throw Error("usePrototypeStatus must be used within a provider");return t},_t=function(){var t=n(Dt);if(void 0===t)throw Error("usePrototypeCursor must be used within a provider");return t},Ot=function(){var t=n(Tt);if(void 0===t)throw Error("usePrototypeState must be used within a provider");return t},Nt=function(t,e){var n=(0,Ft().getInstance)();s((function(){return null==n||n.on(t,e),function(){null==n||n.off(t,e)}}),[t,n,e])},jt={position:"relative",width:"100%",height:"100%",touchAction:"manipulation"},Kt={position:"absolute",top:0,left:0},Ht=function(e){var n=e.locateFile,r=e.imagesURLFormat,i=e.imagesURLMap,u=e.backgroundColor,c=e.mode,l=e.showTilesBorders,h=e.minimumZoomLevel,p=e.maximumZoomLevel,v=e.preserveDrawingBuffer,g=e.children,f=e.containerProps,m=void 0===f?{}:f,y=e.canvasProps,C=void 0===y?{}:y,w=e.featureFlags,b=void 0===w?{}:w,P=e.startArtboardUUID,E=e.prototypeStructure,M=e.fragmentsURLFormat,L=e.fragmentsURLMap,R=o(null),W=o(null),x=Ft(),S=x.dispose,I=x.init,D=x.setSettings,T=_t(),k=zt();s((function(){D({locateFile:n,imagesURLFormat:r,imagesURLMap:i,backgroundColor:u,mode:c,showTilesBorders:l,minimumZoomLevel:h,maximumZoomLevel:p,preserveDrawingBuffer:v,featureFlags:b,startArtboardUUID:P,prototypeStructure:E,fragmentsURLFormat:M,fragmentsURLMap:L})}),[D,n,r,i,u,c,l,h,p,v,b,P]),s((function(){return I(R.current,W.current),function(){S()}}),[S,I]);var F=a((function(){return d(d({},jt),{cursor:T})}),[T]);return t.createElement("div",d({},m,{ref:W,style:F}),t.createElement("canvas",d({},C,{ref:R,"data-testid":"prototype-canvas","data-prototype-status":"prototype-status-".concat((null==k?void 0:k.type.toLowerCase())||"null"),style:Kt})),"READY"===(null==k?void 0:k.type)&&g)};export{tt as CameraMoveContext,Q as CameraZoomingContext,Y as CanvasRenderer,at as CanvasRendererProvider,xt as CanvasRendererReact,nt as CursorContext,I as DefaultFeatureFlags,X as DocumentContext,x as EventEmitter,O as GestureManager,N as KeyboardManager,S as ListenersCollector,et as PanContext,j as Performance,St as PrototypeRenderer,At as PrototypeRendererProvider,Ht as PrototypeRendererReact,J as StatusContext,W as WebRendererError,R as WebRendererMode,q as ZoomContext,A as clamp,G as convertEmbindVectorToArray,F as debounce,U as extractPointer,B as getSupportedWebGLVersion,D as getiOSVersion,Z as isTouchDevice,H as logger,K as nextTick,k as parseSafariUserAgent,it as reducer,z as removeUndefinedKeys,_ as touchableClick,dt as useCursor,ft as useDecrementZoom,ut as useDocument,Mt as useEvent,wt as useGenerateDocumentPNG,bt as useGetArtboardAtPosititon,Pt as useGetPanAtPosition,Gt as useGoBack,Zt as useGoForwards,gt as useIncrementZoom,pt as useIsCameraMoving,ht as useIsCameraZooming,Et as useLockCamera,Lt as useLogEvent,Ct as useLooseWebGLContext,lt as usePan,_t as usePrototypeCursor,Nt as usePrototypeEvent,Ot as usePrototypeState,zt as usePrototypeStatus,Bt as useRestartPrototype,mt as useSetPan,vt as useSetZoom,st as useStatus,ct as useZoom,yt as useZoomToFit};
Binary file