modern-canvas 0.6.6 → 0.6.7
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.
- package/dist/index.cjs +6 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +6 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -13485,7 +13485,12 @@ class Assets {
|
|
|
13485
13485
|
});
|
|
13486
13486
|
}
|
|
13487
13487
|
async waitUntilLoad() {
|
|
13488
|
-
await Promise.all(
|
|
13488
|
+
await Promise.all(
|
|
13489
|
+
Array.from(this._handleing.values()).map((v) => v.catch((err) => {
|
|
13490
|
+
console.error(err);
|
|
13491
|
+
return void 0;
|
|
13492
|
+
}))
|
|
13493
|
+
);
|
|
13489
13494
|
}
|
|
13490
13495
|
gc() {
|
|
13491
13496
|
this._handled.forEach((_, id) => {
|
package/dist/index.js
CHANGED
|
@@ -1046,4 +1046,4 @@ void main(void) {
|
|
|
1046
1046
|
coord = twist(coord, radius - (progress * radius));
|
|
1047
1047
|
coord = unmapCoord(coord);
|
|
1048
1048
|
gl_FragColor = texture2D(sampler, coord);
|
|
1049
|
-
}`})),h.TwistTransition=tE([nt("TwistTransition")],h.TwistTransition);class au extends eA{install(t){const e=async A=>{const{decodeFrames:i}=await import("modern-gif");return await t.fetch(A).then(s=>s.arrayBuffer()).then(s=>i(s)).then(s=>new gr(s.map(n=>({duration:n.delay,texture:new Ms(n.data,n.width,n.height)}))))};return this.load=A=>t.loadBy(A,()=>e(A)),["image/gif"].forEach(A=>{t.register(A,e)}),t.gif=this,this}}class lu extends eA{install(t){const e=A=>t.fetch(A).then(i=>i.json());return this.load=A=>t.loadBy(A,()=>e(A)),["json"].forEach(A=>{t.register(A,e)}),t.json=this,this}}class uu extends eA{install(t){const e=async(A,i)=>(await import("lottie-web").then(n=>n.default)).loadAnimation({container:null,renderer:"canvas",rendererSettings:{context:i.getContext("2d")},loop:!1,autoplay:!1,animationData:await t.fetch(A).then(n=>n.json())});return this.load=(A,i)=>t.loadBy(A,()=>e(A,i)),["lottie"].forEach(A=>{t.register(A,e)}),t.lottie=this,this}}class cu extends eA{install(t){const e=async A=>await t.fetch(A).then(i=>i.text());return this.load=A=>t.loadBy(A,()=>e(A)),t.text=this,this}}class hu extends eA{install(t){const e=A=>t.fetchImageBitmap(A,{premultiplyAlpha:"premultiply"}).then(i=>new mt(i));return this.load=A=>t.loadBy(A,()=>e(A)),["image/gif","image/jpeg","image/png","image/tiff","image/vnd.wap.wbmp","image/x-icon","image/x-jng","image/x-ms-bmp","image/svg+xml","image/webp"].forEach(A=>{t.register(A,e)}),t.texture=this,this}}class gu extends eA{install(t){const e=A=>new ga(A).load();return this.load=A=>t.loadBy(A,()=>e(A)),["video/3gpp","video/mpeg","video/quicktime","video/x-flv","video/x-mng","video/x-ms-asf","video/x-ms-wmv","video/x-msvideo","video/mp4"].forEach(A=>{t.register(A,e)}),t.video=this,this}}const AE=Object.entries({"text/html":["html","htm","shtml"],"text/css":["css"],"text/xml":["xml"],"image/gif":["gif"],"image/jpeg":["jpeg","jpg"],"application/x-javascript":["js"],"application/atom+xml":["atom"],"application/rss+xml":["rss"],"text/mathml":["mml"],"text/plain":["txt"],"text/vnd.sun.j2me.app-descriptor":["jad"],"text/vnd.wap.wml":["wml"],"text/x-component":["htc"],"image/png":["png"],"image/tiff":["tif","tiff"],"image/vnd.wap.wbmp":["wbmp"],"image/x-icon":["ico"],"image/x-jng":["jng"],"image/x-ms-bmp":["bmp"],"image/svg+xml":["svg"],"image/webp":["webp"],"application/java-archive":["jar","war","ear"],"application/mac-binhex40":["hqx"],"application/msword":["doc"],"application/pdf":["pdf"],"application/postscript":["ps","eps","ai"],"application/rtf":["rtf"],"application/vnd.ms-excel":["xls"],"application/vnd.ms-powerpoint":["ppt"],"application/vnd.wap.wmlc":["wmlc"],"application/vnd.google-earth.kml+xml":["kml"],"application/vnd.google-earth.kmz":["kmz"],"application/x-7z-compressed":["7z"],"application/x-cocoa":["cco"],"application/x-java-archive-diff":["jardiff"],"application/x-java-jnlp-file":["jnlp"],"application/x-makeself":["run"],"application/x-perl":["pl","pm"],"application/x-pilot":["prc","pdb"],"application/x-rar-compressed":["rar"],"application/x-redhat-package-manager":["rpm"],"application/x-sea":["sea"],"application/x-shockwave-flash":["swf"],"application/x-stuffit":["sit"],"application/x-tcl":["tcl","tk"],"application/x-x509-ca-cert":["der","pem","crt"],"application/x-xpinstall":["xpi"],"application/xhtml+xml":["xhtml"],"application/zip":["zip"],"application/octet-stream":["bin","exe","dll","deb","dmg","eot","iso","img","msi","msp","msm"],"audio/midi":["mid","midi","kar"],"audio/mpeg":["mp3"],"audio/ogg":["ogg"],"audio/x-realaudio":["ra"],"video/3gpp":["3gpp","3gp"],"video/mpeg":["mpeg","mpg"],"video/quicktime":["mov"],"video/x-flv":["flv"],"video/x-mng":["mng"],"video/x-ms-asf":["asx","asf"],"video/x-ms-wmv":["wmv"],"video/x-msvideo":["avi"],"video/mp4":["m4v","mp4"]});function iE(r){for(const[t,e]of AE)if(e.includes(r))return t}async function rE(r){let t;if(r.startsWith("data:"))t=r.match(/^data:(.+?);/)?.[1];else if(r.startsWith("http")){const e=r.split(/[#?]/)[0].split(".").pop()?.trim();e&&(t=iE(e))}return t??await fetch(r).then(e=>e.headers.get("Content-Type"))??""}const qr="WeakRef"in globalThis;class fu{defaultHandler=t=>this.fetch(t);_handlers=new Map;_handleing=new Map;_handled=new Map;_gc=qr?new FinalizationRegistry(t=>{const e=this.get(t);e&&"free"in e&&e.free(),this._handled.delete(t)}):void 0;constructor(){qr||Kt.on(this.gc.bind(this),{sort:2})}use(t){return t.install(this),this}register(t,e){return this._handlers.set(t,e),this}fetch(t){return fetch(t)}_fixSVG(t){let e;t.includes(";base64,")?e=atob(t.split(",")[1]):e=decodeURIComponent(t.split(",")[1]);const A=new DOMParser().parseFromString(e,"image/svg+xml").documentElement,i=A.getAttribute("width"),s=A.getAttribute("height"),n=i&&/^[\d.]+$/.test(i),o=s&&/^[\d.]+$/.test(s);if(!n||!o){const a=A.getAttribute("viewBox")?.split(" ").map(l=>Number(l));n||A.setAttribute("width",String(a?a[2]-a[0]:512)),o||A.setAttribute("height",String(a?a[3]-a[1]:512))}return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(A.outerHTML)}`}async fetchImageBitmap(t,e){return t.startsWith("http")?await this.fetch(t).then(A=>A.blob()).then(A=>A.type==="image/svg+xml"?A.text().then(i=>this.fetchImageBitmap(this._fixSVG(`data:image/svg+xml;charset=utf-8,${encodeURIComponent(i)}`),e)):createImageBitmap(A,e)):(t.startsWith("data:image/svg+xml;")&&(t=this._fixSVG(t)),new Promise(A=>{const i=new Image;i.src=t,i.onload=()=>{i.decode().finally(()=>{A(i)})}}).then(A=>createImageBitmap(A,e)))}get(t){let e=this._handled.get(t);return qr&&e instanceof WeakRef&&(e=e.deref(),e||this._handleing.delete(t)),e}set(t,e){let A=e;qr&&typeof e=="object"&&(this._gc.register(e,t),A=new WeakRef(e)),this._handled.set(t,A)}async loadBy(t,e){const A=this.get(t)??this._handleing.get(t);if(A)return A;const i=e().then(s=>(this.set(t,s),s)).finally(()=>{this._handleing.delete(t)});return this._handleing.set(t,i),i}async load(t,e){return this.loadBy(t,async()=>{const A=await rE(t);return(this._handlers.get(A)??this.defaultHandler)(t,e)})}async waitUntilLoad(){await Promise.all(Array.from(this._handleing.values()))}gc(){this._handled.forEach((t,e)=>{const A=this.get(e);A&&"free"in A&&A.free()}),this._handled.clear()}}const Ue=new fu().use(new ra).use(new au).use(new lu).use(new uu).use(new cu).use(new hu).use(new gu);class sE extends h.Control{_pointerStart;_pointerOffset;selected;dragging;hovered;hover=new h.Element2D({name:"hover",internalMode:"back",style:{visibility:"hidden",outlineStyle:"solid",outlineColor:"#00FF00FF",outlineWidth:2,pointerEvents:"none"}});transformRect=new Nn({name:"transformRect",internalMode:"back",style:{visibility:"hidden",pointerEvents:"none"}});scaler=new h.Scaler({internalMode:"back"}).on("updateScale",t=>{this.ruler.gapScale=t,this._updateScrollbars(),this._updateSelectionRect()});xScrollBar=new h.XScrollBar({internalMode:"back",style:{visibility:"hidden"}});yScrollBar=new h.YScrollBar({internalMode:"back",style:{visibility:"hidden"}});drawboard=new h.Element2D({name:"drawboard",style:{width:500,height:500,backgroundColor:"#FFFFFFFF",overflow:"hidden",pointerEvents:"none",boxShadow:"2px 2px 2px 1px rgba(0, 0, 0, 0.2)"}},[this.scaler]);ruler=new h.Ruler({name:"ruler",offsetX:100,offsetY:100,style:{pointerEvents:"none"}},[this.drawboard,this.hover,this.transformRect,this.xScrollBar,this.yScrollBar]);constructor(){super(),this._onPointerdown=this._onPointerdown.bind(this),this._onPointermove=this._onPointermove.bind(this),this._onPointerup=this._onPointerup.bind(this),this.append(this.ruler)}_updateStyleProperty(t,e,A,i){switch(super._updateStyleProperty(t,e,A,i),t){case"width":this.drawboard.style.left=(this.size.width-this.drawboard.size.width)/2,this.ruler.offsetX=this.drawboard.style.left;break;case"height":this.drawboard.style.top=(this.size.height-this.drawboard.size.height)/2,this.ruler.offsetY=this.drawboard.style.top;break}}_guiInput(t,e){switch(super._guiInput(t,e),e){case"pointerdown":this._onPointerdown(t);break;case"pointermove":this._onPointermove(t);break;case"pointerup":this._onPointerup();break}}_onPointerdown(t){let e=t.target;e?.is(this)&&(e=void 0),e?.is(this.transformRect)&&(e=this.selected),this._pointerOffset={x:t.offsetX,y:t.offsetY},this.selected=e,this.dragging=e,e instanceof h.Element2D?this._pointerStart=e.style.clone():this._pointerStart=void 0,this._updateHover(),this._updateSelectionRect()}_onPointermove(t){let e=t.target;e?.is(this)&&(e=void 0),e?.is(this.transformRect)&&(e=this.selected);const{selected:A,dragging:i,_pointerStart:s,_pointerOffset:n}=this;A&&e?.is(A)?this.hovered=void 0:this.hovered=e;const o=n?{x:t.offsetX-n.x,y:t.offsetY-n.y}:{x:0,y:0};i&&s&&(i.style.left=s.left+o.x/this.scaler.value,i.style.top=s.top+o.y/this.scaler.value,i.update()),this._updateHover(),this._updateSelectionRect()}_onPointerup(){this.dragging=void 0,this._updateHover(),this._updateSelectionRect()}_copyGlobalTransform(t,e){t.style.visibility="visible",t.style.width=e.globalScale.x*e.size.x,t.style.height=e.globalScale.y*e.size.y,t.style.left=e.globalPosition.x,t.style.top=e.globalPosition.y,t.style.rotate=e.globalRotation,t.update()}_updateHover(){const t=this.hovered;t instanceof h.Element2D?(this.hover.style.visibility="visible",this._copyGlobalTransform(this.hover,t),this.hover.requestRedraw()):this.hover.style.visibility="hidden"}_updateSelectionRect(){this.selected?(this.transformRect.style.visibility="visible",this._copyGlobalTransform(this.transformRect,this.selected)):this.transformRect.style.visibility="hidden"}_updateScrollbars(){const t=this.ruler.gapScale,e=this.drawboard.size.height*t,A=this.drawboard.size.width*t;e>this.size.height?(this.yScrollBar.style.visibility="visible",this.yScrollBar.maxValue=e,this.yScrollBar.page=this.size.height):this.yScrollBar.style.visibility="hidden",A>this.size.width?(this.xScrollBar.style.visibility="visible",this.xScrollBar.maxValue=A,this.xScrollBar.page=this.size.width):this.xScrollBar.style.visibility="hidden"}}const du={alpha:!0,stencil:!0,antialias:!1,premultipliedAlpha:!0,preserveDrawingBuffer:!1,powerPreference:"default"};class Iu extends Fi{renderer;get view(){return this.renderer.view}get gl(){return this.renderer.gl}get screen(){return this.renderer.screen}get width(){return this.screen.width}get height(){return this.screen.height}get pixelRatio(){return this.renderer.pixelRatio}set pixelRatio(t){this.renderer.pixelRatio=t,this.resize(this.width,this.height),this.view&&(this.view.dataset.pixelRatio=String(t))}_resizeObserver=mo?new ResizeObserver(t=>{const e=t[0];if(e.target===this.view){const{inlineSize:A,blockSize:i}=Array.isArray(e.contentBoxSize)?e.contentBoxSize[0]:e.contentBoxSize;this.resize(A,i)}}):void 0;constructor(t={}){const{debug:e=!1,view:A,width:i,height:s,pixelRatio:n=Ds,backgroundColor:o=0,autoResize:a,autoStart:l,timeline:u,...c}=t;super(u),this.debug=e,this.renderer=new ia(A,{...du,...c}),this._setupInput(),this.pixelRatio=n,this.backgroundColor=o,a?(!A&&this.renderer.view&&(this.renderer.view.style.width="100%",this.renderer.view.style.height="100%"),this.enableAutoResize(a)):this.resize(i||this.gl.drawingBufferWidth||this.view?.clientWidth||200,s||this.gl.drawingBufferHeight||this.view?.clientHeight||200,!A),l&&this.start()}_setupInput(){return this.view&&(this.input.setTarget(this.view),["pointerdown","pointerover","pointermove","pointerup","wheel"].forEach(t=>{this.input.on(t,e=>{this.root.input(e,t),this.emit(t,e)})})),this}enableAutoResize(t=!0){return this.view&&(t?this._resizeObserver?.observe(this.view):this._resizeObserver?.unobserve(this.view)),this}resize(t,e,A=!1){return this.renderer.resize(t,e,A),this.root.width=t,this.root.height=e,this.root.requestUpload(),this.render(),this}nextTick(){return Is()}async waitUntilLoad(){await Ue.waitUntilLoad(),await this.nextTick()}async waitAndRender(t=0){await Ue.waitUntilLoad(),this._process(t),await this.nextTick(),this._render(this.renderer)}render(t=0){this._process(t),this._render(this.renderer)}async start(){await this.waitAndRender(),super.start(t=>{this._process(t),this._render(this.renderer)})}free(){super.free(),this.enableAutoResize(!1),this.renderer.free()}toPixels(){return this.renderer.toPixels()}toImageData(){return new ImageData(this.toPixels(),this.gl.drawingBufferWidth,this.gl.drawingBufferHeight)}toCanvas2D(){const t=this.toImageData(),e=document.createElement("canvas");e.width=t.width,e.height=t.height,e.getContext("2d")?.putImageData(t,0,0);const A=document.createElement("canvas");return A.width=this.width,A.height=this.height,A.getContext("2d")?.drawImage(e,0,0,e.width,e.height,0,0,A.width,A.height),A}}let Ne;const Ln=[];let Gn=!1;async function nE(r=100){if(!Gn){for(Gn=!0;Ln.length;){const t=Ln.shift();if(t)try{await t()}catch(e){console.error(e)}else await new Promise(e=>setTimeout(e,r))}Gn=!1}}async function oE(r){const{data:t,width:e,height:A,debug:i=!1,time:s=0}=r;return Ne??=new Iu({width:1,height:1,preserveDrawingBuffer:!0}),Ne.debug=i,Ne.root.removeChildren(),Ne.timeline.currentTime=s,Ne.resize(e,A,!0),(Array.isArray(t)?t:[t]).forEach(n=>{n instanceof h.Node?(n.parent=void 0,Ne.root.appendChild(n)):Ne.root.appendChild(h.Node.parse(n))}),await r.onBeforeRender?.(Ne),await Ne.waitAndRender(),Ne.toCanvas2D()}async function aE(r){return new Promise(t=>{Ln.push(async()=>t(await oE(r))),nE()})}h.AnimatedTexture=gr,h.Assets=fu,h.AudioPipeline=Tn,h.AudioProcessor=cp,h.AudioSpectrum=Bp,h.BaseElement2DBackground=$s,h.BaseElement2DFill=Vt,h.BaseElement2DForeground=tn,h.BaseElement2DOutline=Mi,h.BaseElement2DShadow=DA,h.BaseElement2DShape=mA,h.BaseElement2DStyle=ki,h.BaseElement2DText=FA,h.CanvasContext=Wa,h.CanvasItemEditor=sE,h.CanvasTexture=pi,h.Color=Je,h.ColorMatrix=_s,h.ColorTexture=ca,h.CoreObject=tA,h.DEG_TO_RAD=Go,h.DEVICE_PIXEL_RATIO=Ds,h.EffectMaterial=di,h.Element2DStyle=kn,h.Engine=Iu,h.FlexElement2DStyle=Hl,h.FlexLayout=Jr,h.FontLoader=ra,h.GIFLoader=au,h.Geometry=hr,h.GradientTexture=fr,h.HTMLAudio=ru,h.HTMLAudioContext=Vr,h.HTMLSound=Zi,h.IN_BROWSER=fi,h.ImageTexture=sh,h.IndexBuffer=UA,h.Input=No,h.InputEvent=ur,h.JSONLoader=lu,h.Loader=eA,h.LottieLoader=uu,h.MainLoop=cr,h.Material=Ct,h.Matrix=ve,h.Matrix2=Hc,h.Matrix3=bs,h.Matrix4=Lo,h.MouseInputEvent=vs,h.PI=lr,h.PI_2=oe,h.PixelsTexture=Ms,h.PointerInputEvent=ko,h.Projection2D=Ho,h.QuadGeometry=Xc,h.QuadUvGeometry=gt,h.RAD_TO_DEG=Gc,h.RawWeakMap=ws,h.Rect2=xs,h.RefCounted=To,h.Renderer=Ko,h.Resource=He,h.SUPPORTS_AUDIO_CONTEXT=Cs,h.SUPPORTS_CLICK_EVENTS=vo,h.SUPPORTS_CREATE_IMAGE_BITMAP=Bs,h.SUPPORTS_IMAGE_BITMAP=Do,h.SUPPORTS_MOUSE_EVENTS=kc,h.SUPPORTS_OFFLINE_AUDIO_CONTEXT=ys,h.SUPPORTS_POINTER_EVENTS=PA,h.SUPPORTS_RESIZE_OBSERVER=mo,h.SUPPORTS_TOUCH_EVENTS=Oe,h.SUPPORTS_WEBGL2=yo,h.SUPPORTS_WEBKIT_AUDIO_CONTEXT=Qs,h.SUPPORTS_WEBKIT_OFFLINE_AUDIO_CONTEXT=_o,h.SUPPORTS_WEB_AUDIO=bo,h.SUPPORTS_WHEEL_EVENTS=wo,h.SceneTree=Fi,h.TextLoader=cu,h.Texture2D=mt,h.TextureLoader=hu,h.TextureRect2D=Kr,h.Ticker=Kt,h.Transform2D=Yt,h.TransformRect2D=Nn,h.UvGeometry=th,h.UvMaterial=Ii,h.Vector=Ee,h.Vector2=ae,h.Vector3=Jc,h.Vector4=Oo,h.VertexAttribute=le,h.VertexBuffer=Ye,h.VideoLoader=gu,h.VideoTexture=ga,h.ViewportTexture=Ps,h.WebAudio=nu,h.WebAudioContext=gA,h.WebGLBatch2DModule=zo,h.WebGLBlendMode=kA,h.WebGLBufferModule=Wo,h.WebGLFramebufferModule=qo,h.WebGLMaskModule=Xo,h.WebGLModule=de,h.WebGLProgramModule=jo,h.WebGLRenderer=ia,h.WebGLScissorModule=Zo,h.WebGLState=BA,h.WebGLStateModule=Vo,h.WebGLStencilModule=$o,h.WebGLTextureModule=ta,h.WebGLVertexArrayModule=ea,h.WebGLViewportModule=Aa,h.WebSound=su,h.WheelInputEvent=Uo,h.assets=Ue,h.clamp=Ke,h.clampFrag=rl,h.createHTMLCanvas=Mo,h.createNode=xc,h.crossOrigin=Po,h.cubicBezier=si,h.curves=Oc,h.customNode=nt,h.customNodes=ar,h.defaultOptions=du,h.determineCrossOrigin=Ro,h.ease=tu,h.easeIn=eu,h.easeInOut=iu,h.easeOut=Au,h.frag=il,h.getDefaultCssPropertyValue=Es,h.isCanvasElement=Fo,h.isElementNode=ms,h.isImageElement=Uc,h.isPow2=ps,h.isVideoElement=xo,h.isWebgl2=So,h.lerp=bt,h.linear=$l,h.log2=Ss,h.mapWebGLBlendModes=Yo,h.nextPow2=Fs,h.nextTick=Is,h.parseCSSFilter=na,h.parseCSSTransform=oa,h.parseCSSTransformOrigin=aa,h.parseCssFunctions=gi,h.parseCssProperty=hi,h.render=aE,h.timingFunctions=Yr,h.uid=Co,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
|
1049
|
+
}`})),h.TwistTransition=tE([nt("TwistTransition")],h.TwistTransition);class au extends eA{install(t){const e=async A=>{const{decodeFrames:i}=await import("modern-gif");return await t.fetch(A).then(s=>s.arrayBuffer()).then(s=>i(s)).then(s=>new gr(s.map(n=>({duration:n.delay,texture:new Ms(n.data,n.width,n.height)}))))};return this.load=A=>t.loadBy(A,()=>e(A)),["image/gif"].forEach(A=>{t.register(A,e)}),t.gif=this,this}}class lu extends eA{install(t){const e=A=>t.fetch(A).then(i=>i.json());return this.load=A=>t.loadBy(A,()=>e(A)),["json"].forEach(A=>{t.register(A,e)}),t.json=this,this}}class uu extends eA{install(t){const e=async(A,i)=>(await import("lottie-web").then(n=>n.default)).loadAnimation({container:null,renderer:"canvas",rendererSettings:{context:i.getContext("2d")},loop:!1,autoplay:!1,animationData:await t.fetch(A).then(n=>n.json())});return this.load=(A,i)=>t.loadBy(A,()=>e(A,i)),["lottie"].forEach(A=>{t.register(A,e)}),t.lottie=this,this}}class cu extends eA{install(t){const e=async A=>await t.fetch(A).then(i=>i.text());return this.load=A=>t.loadBy(A,()=>e(A)),t.text=this,this}}class hu extends eA{install(t){const e=A=>t.fetchImageBitmap(A,{premultiplyAlpha:"premultiply"}).then(i=>new mt(i));return this.load=A=>t.loadBy(A,()=>e(A)),["image/gif","image/jpeg","image/png","image/tiff","image/vnd.wap.wbmp","image/x-icon","image/x-jng","image/x-ms-bmp","image/svg+xml","image/webp"].forEach(A=>{t.register(A,e)}),t.texture=this,this}}class gu extends eA{install(t){const e=A=>new ga(A).load();return this.load=A=>t.loadBy(A,()=>e(A)),["video/3gpp","video/mpeg","video/quicktime","video/x-flv","video/x-mng","video/x-ms-asf","video/x-ms-wmv","video/x-msvideo","video/mp4"].forEach(A=>{t.register(A,e)}),t.video=this,this}}const AE=Object.entries({"text/html":["html","htm","shtml"],"text/css":["css"],"text/xml":["xml"],"image/gif":["gif"],"image/jpeg":["jpeg","jpg"],"application/x-javascript":["js"],"application/atom+xml":["atom"],"application/rss+xml":["rss"],"text/mathml":["mml"],"text/plain":["txt"],"text/vnd.sun.j2me.app-descriptor":["jad"],"text/vnd.wap.wml":["wml"],"text/x-component":["htc"],"image/png":["png"],"image/tiff":["tif","tiff"],"image/vnd.wap.wbmp":["wbmp"],"image/x-icon":["ico"],"image/x-jng":["jng"],"image/x-ms-bmp":["bmp"],"image/svg+xml":["svg"],"image/webp":["webp"],"application/java-archive":["jar","war","ear"],"application/mac-binhex40":["hqx"],"application/msword":["doc"],"application/pdf":["pdf"],"application/postscript":["ps","eps","ai"],"application/rtf":["rtf"],"application/vnd.ms-excel":["xls"],"application/vnd.ms-powerpoint":["ppt"],"application/vnd.wap.wmlc":["wmlc"],"application/vnd.google-earth.kml+xml":["kml"],"application/vnd.google-earth.kmz":["kmz"],"application/x-7z-compressed":["7z"],"application/x-cocoa":["cco"],"application/x-java-archive-diff":["jardiff"],"application/x-java-jnlp-file":["jnlp"],"application/x-makeself":["run"],"application/x-perl":["pl","pm"],"application/x-pilot":["prc","pdb"],"application/x-rar-compressed":["rar"],"application/x-redhat-package-manager":["rpm"],"application/x-sea":["sea"],"application/x-shockwave-flash":["swf"],"application/x-stuffit":["sit"],"application/x-tcl":["tcl","tk"],"application/x-x509-ca-cert":["der","pem","crt"],"application/x-xpinstall":["xpi"],"application/xhtml+xml":["xhtml"],"application/zip":["zip"],"application/octet-stream":["bin","exe","dll","deb","dmg","eot","iso","img","msi","msp","msm"],"audio/midi":["mid","midi","kar"],"audio/mpeg":["mp3"],"audio/ogg":["ogg"],"audio/x-realaudio":["ra"],"video/3gpp":["3gpp","3gp"],"video/mpeg":["mpeg","mpg"],"video/quicktime":["mov"],"video/x-flv":["flv"],"video/x-mng":["mng"],"video/x-ms-asf":["asx","asf"],"video/x-ms-wmv":["wmv"],"video/x-msvideo":["avi"],"video/mp4":["m4v","mp4"]});function iE(r){for(const[t,e]of AE)if(e.includes(r))return t}async function rE(r){let t;if(r.startsWith("data:"))t=r.match(/^data:(.+?);/)?.[1];else if(r.startsWith("http")){const e=r.split(/[#?]/)[0].split(".").pop()?.trim();e&&(t=iE(e))}return t??await fetch(r).then(e=>e.headers.get("Content-Type"))??""}const qr="WeakRef"in globalThis;class fu{defaultHandler=t=>this.fetch(t);_handlers=new Map;_handleing=new Map;_handled=new Map;_gc=qr?new FinalizationRegistry(t=>{const e=this.get(t);e&&"free"in e&&e.free(),this._handled.delete(t)}):void 0;constructor(){qr||Kt.on(this.gc.bind(this),{sort:2})}use(t){return t.install(this),this}register(t,e){return this._handlers.set(t,e),this}fetch(t){return fetch(t)}_fixSVG(t){let e;t.includes(";base64,")?e=atob(t.split(",")[1]):e=decodeURIComponent(t.split(",")[1]);const A=new DOMParser().parseFromString(e,"image/svg+xml").documentElement,i=A.getAttribute("width"),s=A.getAttribute("height"),n=i&&/^[\d.]+$/.test(i),o=s&&/^[\d.]+$/.test(s);if(!n||!o){const a=A.getAttribute("viewBox")?.split(" ").map(l=>Number(l));n||A.setAttribute("width",String(a?a[2]-a[0]:512)),o||A.setAttribute("height",String(a?a[3]-a[1]:512))}return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(A.outerHTML)}`}async fetchImageBitmap(t,e){return t.startsWith("http")?await this.fetch(t).then(A=>A.blob()).then(A=>A.type==="image/svg+xml"?A.text().then(i=>this.fetchImageBitmap(this._fixSVG(`data:image/svg+xml;charset=utf-8,${encodeURIComponent(i)}`),e)):createImageBitmap(A,e)):(t.startsWith("data:image/svg+xml;")&&(t=this._fixSVG(t)),new Promise(A=>{const i=new Image;i.src=t,i.onload=()=>{i.decode().finally(()=>{A(i)})}}).then(A=>createImageBitmap(A,e)))}get(t){let e=this._handled.get(t);return qr&&e instanceof WeakRef&&(e=e.deref(),e||this._handleing.delete(t)),e}set(t,e){let A=e;qr&&typeof e=="object"&&(this._gc.register(e,t),A=new WeakRef(e)),this._handled.set(t,A)}async loadBy(t,e){const A=this.get(t)??this._handleing.get(t);if(A)return A;const i=e().then(s=>(this.set(t,s),s)).finally(()=>{this._handleing.delete(t)});return this._handleing.set(t,i),i}async load(t,e){return this.loadBy(t,async()=>{const A=await rE(t);return(this._handlers.get(A)??this.defaultHandler)(t,e)})}async waitUntilLoad(){await Promise.all(Array.from(this._handleing.values()).map(t=>t.catch(e=>{console.error(e)})))}gc(){this._handled.forEach((t,e)=>{const A=this.get(e);A&&"free"in A&&A.free()}),this._handled.clear()}}const Ue=new fu().use(new ra).use(new au).use(new lu).use(new uu).use(new cu).use(new hu).use(new gu);class sE extends h.Control{_pointerStart;_pointerOffset;selected;dragging;hovered;hover=new h.Element2D({name:"hover",internalMode:"back",style:{visibility:"hidden",outlineStyle:"solid",outlineColor:"#00FF00FF",outlineWidth:2,pointerEvents:"none"}});transformRect=new Nn({name:"transformRect",internalMode:"back",style:{visibility:"hidden",pointerEvents:"none"}});scaler=new h.Scaler({internalMode:"back"}).on("updateScale",t=>{this.ruler.gapScale=t,this._updateScrollbars(),this._updateSelectionRect()});xScrollBar=new h.XScrollBar({internalMode:"back",style:{visibility:"hidden"}});yScrollBar=new h.YScrollBar({internalMode:"back",style:{visibility:"hidden"}});drawboard=new h.Element2D({name:"drawboard",style:{width:500,height:500,backgroundColor:"#FFFFFFFF",overflow:"hidden",pointerEvents:"none",boxShadow:"2px 2px 2px 1px rgba(0, 0, 0, 0.2)"}},[this.scaler]);ruler=new h.Ruler({name:"ruler",offsetX:100,offsetY:100,style:{pointerEvents:"none"}},[this.drawboard,this.hover,this.transformRect,this.xScrollBar,this.yScrollBar]);constructor(){super(),this._onPointerdown=this._onPointerdown.bind(this),this._onPointermove=this._onPointermove.bind(this),this._onPointerup=this._onPointerup.bind(this),this.append(this.ruler)}_updateStyleProperty(t,e,A,i){switch(super._updateStyleProperty(t,e,A,i),t){case"width":this.drawboard.style.left=(this.size.width-this.drawboard.size.width)/2,this.ruler.offsetX=this.drawboard.style.left;break;case"height":this.drawboard.style.top=(this.size.height-this.drawboard.size.height)/2,this.ruler.offsetY=this.drawboard.style.top;break}}_guiInput(t,e){switch(super._guiInput(t,e),e){case"pointerdown":this._onPointerdown(t);break;case"pointermove":this._onPointermove(t);break;case"pointerup":this._onPointerup();break}}_onPointerdown(t){let e=t.target;e?.is(this)&&(e=void 0),e?.is(this.transformRect)&&(e=this.selected),this._pointerOffset={x:t.offsetX,y:t.offsetY},this.selected=e,this.dragging=e,e instanceof h.Element2D?this._pointerStart=e.style.clone():this._pointerStart=void 0,this._updateHover(),this._updateSelectionRect()}_onPointermove(t){let e=t.target;e?.is(this)&&(e=void 0),e?.is(this.transformRect)&&(e=this.selected);const{selected:A,dragging:i,_pointerStart:s,_pointerOffset:n}=this;A&&e?.is(A)?this.hovered=void 0:this.hovered=e;const o=n?{x:t.offsetX-n.x,y:t.offsetY-n.y}:{x:0,y:0};i&&s&&(i.style.left=s.left+o.x/this.scaler.value,i.style.top=s.top+o.y/this.scaler.value,i.update()),this._updateHover(),this._updateSelectionRect()}_onPointerup(){this.dragging=void 0,this._updateHover(),this._updateSelectionRect()}_copyGlobalTransform(t,e){t.style.visibility="visible",t.style.width=e.globalScale.x*e.size.x,t.style.height=e.globalScale.y*e.size.y,t.style.left=e.globalPosition.x,t.style.top=e.globalPosition.y,t.style.rotate=e.globalRotation,t.update()}_updateHover(){const t=this.hovered;t instanceof h.Element2D?(this.hover.style.visibility="visible",this._copyGlobalTransform(this.hover,t),this.hover.requestRedraw()):this.hover.style.visibility="hidden"}_updateSelectionRect(){this.selected?(this.transformRect.style.visibility="visible",this._copyGlobalTransform(this.transformRect,this.selected)):this.transformRect.style.visibility="hidden"}_updateScrollbars(){const t=this.ruler.gapScale,e=this.drawboard.size.height*t,A=this.drawboard.size.width*t;e>this.size.height?(this.yScrollBar.style.visibility="visible",this.yScrollBar.maxValue=e,this.yScrollBar.page=this.size.height):this.yScrollBar.style.visibility="hidden",A>this.size.width?(this.xScrollBar.style.visibility="visible",this.xScrollBar.maxValue=A,this.xScrollBar.page=this.size.width):this.xScrollBar.style.visibility="hidden"}}const du={alpha:!0,stencil:!0,antialias:!1,premultipliedAlpha:!0,preserveDrawingBuffer:!1,powerPreference:"default"};class Iu extends Fi{renderer;get view(){return this.renderer.view}get gl(){return this.renderer.gl}get screen(){return this.renderer.screen}get width(){return this.screen.width}get height(){return this.screen.height}get pixelRatio(){return this.renderer.pixelRatio}set pixelRatio(t){this.renderer.pixelRatio=t,this.resize(this.width,this.height),this.view&&(this.view.dataset.pixelRatio=String(t))}_resizeObserver=mo?new ResizeObserver(t=>{const e=t[0];if(e.target===this.view){const{inlineSize:A,blockSize:i}=Array.isArray(e.contentBoxSize)?e.contentBoxSize[0]:e.contentBoxSize;this.resize(A,i)}}):void 0;constructor(t={}){const{debug:e=!1,view:A,width:i,height:s,pixelRatio:n=Ds,backgroundColor:o=0,autoResize:a,autoStart:l,timeline:u,...c}=t;super(u),this.debug=e,this.renderer=new ia(A,{...du,...c}),this._setupInput(),this.pixelRatio=n,this.backgroundColor=o,a?(!A&&this.renderer.view&&(this.renderer.view.style.width="100%",this.renderer.view.style.height="100%"),this.enableAutoResize(a)):this.resize(i||this.gl.drawingBufferWidth||this.view?.clientWidth||200,s||this.gl.drawingBufferHeight||this.view?.clientHeight||200,!A),l&&this.start()}_setupInput(){return this.view&&(this.input.setTarget(this.view),["pointerdown","pointerover","pointermove","pointerup","wheel"].forEach(t=>{this.input.on(t,e=>{this.root.input(e,t),this.emit(t,e)})})),this}enableAutoResize(t=!0){return this.view&&(t?this._resizeObserver?.observe(this.view):this._resizeObserver?.unobserve(this.view)),this}resize(t,e,A=!1){return this.renderer.resize(t,e,A),this.root.width=t,this.root.height=e,this.root.requestUpload(),this.render(),this}nextTick(){return Is()}async waitUntilLoad(){await Ue.waitUntilLoad(),await this.nextTick()}async waitAndRender(t=0){await Ue.waitUntilLoad(),this._process(t),await this.nextTick(),this._render(this.renderer)}render(t=0){this._process(t),this._render(this.renderer)}async start(){await this.waitAndRender(),super.start(t=>{this._process(t),this._render(this.renderer)})}free(){super.free(),this.enableAutoResize(!1),this.renderer.free()}toPixels(){return this.renderer.toPixels()}toImageData(){return new ImageData(this.toPixels(),this.gl.drawingBufferWidth,this.gl.drawingBufferHeight)}toCanvas2D(){const t=this.toImageData(),e=document.createElement("canvas");e.width=t.width,e.height=t.height,e.getContext("2d")?.putImageData(t,0,0);const A=document.createElement("canvas");return A.width=this.width,A.height=this.height,A.getContext("2d")?.drawImage(e,0,0,e.width,e.height,0,0,A.width,A.height),A}}let Ne;const Ln=[];let Gn=!1;async function nE(r=100){if(!Gn){for(Gn=!0;Ln.length;){const t=Ln.shift();if(t)try{await t()}catch(e){console.error(e)}else await new Promise(e=>setTimeout(e,r))}Gn=!1}}async function oE(r){const{data:t,width:e,height:A,debug:i=!1,time:s=0}=r;return Ne??=new Iu({width:1,height:1,preserveDrawingBuffer:!0}),Ne.debug=i,Ne.root.removeChildren(),Ne.timeline.currentTime=s,Ne.resize(e,A,!0),(Array.isArray(t)?t:[t]).forEach(n=>{n instanceof h.Node?(n.parent=void 0,Ne.root.appendChild(n)):Ne.root.appendChild(h.Node.parse(n))}),await r.onBeforeRender?.(Ne),await Ne.waitAndRender(),Ne.toCanvas2D()}async function aE(r){return new Promise(t=>{Ln.push(async()=>t(await oE(r))),nE()})}h.AnimatedTexture=gr,h.Assets=fu,h.AudioPipeline=Tn,h.AudioProcessor=cp,h.AudioSpectrum=Bp,h.BaseElement2DBackground=$s,h.BaseElement2DFill=Vt,h.BaseElement2DForeground=tn,h.BaseElement2DOutline=Mi,h.BaseElement2DShadow=DA,h.BaseElement2DShape=mA,h.BaseElement2DStyle=ki,h.BaseElement2DText=FA,h.CanvasContext=Wa,h.CanvasItemEditor=sE,h.CanvasTexture=pi,h.Color=Je,h.ColorMatrix=_s,h.ColorTexture=ca,h.CoreObject=tA,h.DEG_TO_RAD=Go,h.DEVICE_PIXEL_RATIO=Ds,h.EffectMaterial=di,h.Element2DStyle=kn,h.Engine=Iu,h.FlexElement2DStyle=Hl,h.FlexLayout=Jr,h.FontLoader=ra,h.GIFLoader=au,h.Geometry=hr,h.GradientTexture=fr,h.HTMLAudio=ru,h.HTMLAudioContext=Vr,h.HTMLSound=Zi,h.IN_BROWSER=fi,h.ImageTexture=sh,h.IndexBuffer=UA,h.Input=No,h.InputEvent=ur,h.JSONLoader=lu,h.Loader=eA,h.LottieLoader=uu,h.MainLoop=cr,h.Material=Ct,h.Matrix=ve,h.Matrix2=Hc,h.Matrix3=bs,h.Matrix4=Lo,h.MouseInputEvent=vs,h.PI=lr,h.PI_2=oe,h.PixelsTexture=Ms,h.PointerInputEvent=ko,h.Projection2D=Ho,h.QuadGeometry=Xc,h.QuadUvGeometry=gt,h.RAD_TO_DEG=Gc,h.RawWeakMap=ws,h.Rect2=xs,h.RefCounted=To,h.Renderer=Ko,h.Resource=He,h.SUPPORTS_AUDIO_CONTEXT=Cs,h.SUPPORTS_CLICK_EVENTS=vo,h.SUPPORTS_CREATE_IMAGE_BITMAP=Bs,h.SUPPORTS_IMAGE_BITMAP=Do,h.SUPPORTS_MOUSE_EVENTS=kc,h.SUPPORTS_OFFLINE_AUDIO_CONTEXT=ys,h.SUPPORTS_POINTER_EVENTS=PA,h.SUPPORTS_RESIZE_OBSERVER=mo,h.SUPPORTS_TOUCH_EVENTS=Oe,h.SUPPORTS_WEBGL2=yo,h.SUPPORTS_WEBKIT_AUDIO_CONTEXT=Qs,h.SUPPORTS_WEBKIT_OFFLINE_AUDIO_CONTEXT=_o,h.SUPPORTS_WEB_AUDIO=bo,h.SUPPORTS_WHEEL_EVENTS=wo,h.SceneTree=Fi,h.TextLoader=cu,h.Texture2D=mt,h.TextureLoader=hu,h.TextureRect2D=Kr,h.Ticker=Kt,h.Transform2D=Yt,h.TransformRect2D=Nn,h.UvGeometry=th,h.UvMaterial=Ii,h.Vector=Ee,h.Vector2=ae,h.Vector3=Jc,h.Vector4=Oo,h.VertexAttribute=le,h.VertexBuffer=Ye,h.VideoLoader=gu,h.VideoTexture=ga,h.ViewportTexture=Ps,h.WebAudio=nu,h.WebAudioContext=gA,h.WebGLBatch2DModule=zo,h.WebGLBlendMode=kA,h.WebGLBufferModule=Wo,h.WebGLFramebufferModule=qo,h.WebGLMaskModule=Xo,h.WebGLModule=de,h.WebGLProgramModule=jo,h.WebGLRenderer=ia,h.WebGLScissorModule=Zo,h.WebGLState=BA,h.WebGLStateModule=Vo,h.WebGLStencilModule=$o,h.WebGLTextureModule=ta,h.WebGLVertexArrayModule=ea,h.WebGLViewportModule=Aa,h.WebSound=su,h.WheelInputEvent=Uo,h.assets=Ue,h.clamp=Ke,h.clampFrag=rl,h.createHTMLCanvas=Mo,h.createNode=xc,h.crossOrigin=Po,h.cubicBezier=si,h.curves=Oc,h.customNode=nt,h.customNodes=ar,h.defaultOptions=du,h.determineCrossOrigin=Ro,h.ease=tu,h.easeIn=eu,h.easeInOut=iu,h.easeOut=Au,h.frag=il,h.getDefaultCssPropertyValue=Es,h.isCanvasElement=Fo,h.isElementNode=ms,h.isImageElement=Uc,h.isPow2=ps,h.isVideoElement=xo,h.isWebgl2=So,h.lerp=bt,h.linear=$l,h.log2=Ss,h.mapWebGLBlendModes=Yo,h.nextPow2=Fs,h.nextTick=Is,h.parseCSSFilter=na,h.parseCSSTransform=oa,h.parseCSSTransformOrigin=aa,h.parseCssFunctions=gi,h.parseCssProperty=hi,h.render=aE,h.timingFunctions=Yr,h.uid=Co,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
package/dist/index.mjs
CHANGED
|
@@ -13479,7 +13479,12 @@ class Assets {
|
|
|
13479
13479
|
});
|
|
13480
13480
|
}
|
|
13481
13481
|
async waitUntilLoad() {
|
|
13482
|
-
await Promise.all(
|
|
13482
|
+
await Promise.all(
|
|
13483
|
+
Array.from(this._handleing.values()).map((v) => v.catch((err) => {
|
|
13484
|
+
console.error(err);
|
|
13485
|
+
return void 0;
|
|
13486
|
+
}))
|
|
13487
|
+
);
|
|
13483
13488
|
}
|
|
13484
13489
|
gc() {
|
|
13485
13490
|
this._handled.forEach((_, id) => {
|