modern-canvas 0.4.4 → 0.4.5

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 CHANGED
@@ -13115,8 +13115,9 @@ class Engine extends SceneTree {
13115
13115
  nextTick() {
13116
13116
  return nextTick();
13117
13117
  }
13118
- waitUntilLoad() {
13119
- return assets.waitUntilLoad();
13118
+ async waitUntilLoad() {
13119
+ await assets.waitUntilLoad();
13120
+ await this.nextTick();
13120
13121
  }
13121
13122
  render(delta = 0) {
13122
13123
  return this._render(this.renderer, delta);
package/dist/index.js CHANGED
@@ -909,4 +909,4 @@ void main(void) {
909
909
  coord = twist(coord, radius - (progress * radius));
910
910
  coord = unmapCoord(coord);
911
911
  gl_FragColor = texture2D(sampler, coord);
912
- }`})),u.TwistTransition=BI([re("TwistTransition")],u.TwistTransition);class El extends $t{install(A){const e=async t=>{const{decodeFrames:i}=await import("modern-gif");return await A.fetch(t).then(s=>s.arrayBuffer()).then(s=>i(s)).then(s=>new Zi(s.map(n=>({duration:n.delay,texture:new Cs(n.data,n.width,n.height)}))))};return this.load=t=>A.loadBy(t,()=>e(t)),["image/gif"].forEach(t=>{A.register(t,e)}),A.gif=this,this}}class pl extends $t{install(A){const e=t=>A.fetch(t).then(i=>i.json());return this.load=t=>A.loadBy(t,()=>e(t)),["json"].forEach(t=>{A.register(t,e)}),A.json=this,this}}class Cl extends $t{install(A){const e=async(t,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 A.fetch(t).then(n=>n.json())});return this.load=(t,i)=>A.loadBy(t,()=>e(t,i)),["lottie"].forEach(t=>{A.register(t,e)}),A.lottie=this,this}}class Ql extends $t{install(A){const e=async t=>await A.fetch(t).then(i=>i.text());return this.load=t=>A.loadBy(t,()=>e(t)),A.text=this,this}}class yl extends $t{install(A){const e=t=>A.fetchImageBitmap(t,{premultiplyAlpha:"premultiply"}).then(i=>new ve(i));return this.load=t=>A.loadBy(t,()=>e(t)),["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(t=>{A.register(t,e)}),A.texture=this,this}}class ml extends $t{install(A){const e=t=>new To(t).load();return this.load=t=>A.loadBy(t,()=>e(t)),["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(t=>{A.register(t,e)}),A.video=this,this}}const pI=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 CI(r){for(const[A,e]of pI)if(e.includes(r))return A}async function QI(r){var e,t;let A;if(r.startsWith("data:"))A=(e=r.match(/^data:(.+?);/))==null?void 0:e[1];else if(r.startsWith("http")){const i=(t=r.split(/[#?]/)[0].split(".").pop())==null?void 0:t.trim();i&&(A=CI(i))}return A??await fetch(r).then(i=>i.headers.get("Content-Type"))??""}const Pr="WeakRef"in globalThis;class wl{constructor(){h(this,"defaultHandler",A=>this.fetch(A));h(this,"_handlers",new Map);h(this,"_handleing",new Map);h(this,"_handled",new Map);h(this,"_gc",Pr?new FinalizationRegistry(A=>{const e=this.get(A);e&&"free"in e&&e.free(),this._handled.delete(A)}):void 0);Pr||xe.on(this.gc.bind(this),{sort:2})}use(A){return A.install(this),this}register(A,e){return this._handlers.set(A,e),this}fetch(A){return fetch(A)}_fixSVG(A){const e=new DOMParser().parseFromString(decodeURIComponent(A.split(",")[1]),"image/svg+xml").documentElement;return e.setAttribute("width","512"),e.setAttribute("height","512"),`data:image/svg+xml;charset=utf-8,${encodeURIComponent(e.outerHTML)}`}async fetchImageBitmap(A,e){return A.startsWith("http")?await this.fetch(A).then(t=>t.blob()).then(t=>t.type==="image/svg+xml"?t.text().then(i=>this.fetchImageBitmap(this._fixSVG(`data:image/svg+xml;charset=utf-8,${encodeURIComponent(i)}`),e)):createImageBitmap(t,e)):(A.startsWith("data:image/svg+xml;charset=utf-8,")&&(A=this._fixSVG(A)),new Promise(t=>{const i=new Image;i.src=A,i.onload=()=>{i.decode().finally(()=>{t(i)})}}).then(t=>createImageBitmap(t,e)))}get(A){let e=this._handled.get(A);return Pr&&e instanceof WeakRef&&(e=e.deref(),e||this._handleing.delete(A)),e}set(A,e){let t=e;Pr&&typeof e=="object"&&(this._gc.register(e,A),t=new WeakRef(e)),this._handled.set(A,t)}async loadBy(A,e){const t=this.get(A)??this._handleing.get(A);if(t)return t;const i=e().then(s=>(this.set(A,s),s)).finally(()=>{this._handleing.delete(A)});return this._handleing.set(A,i),i}async load(A,e){return this.loadBy(A,async()=>{const t=await QI(A);return(this._handlers.get(t)??this.defaultHandler)(A,e)})}async waitUntilLoad(){await Promise.all(Array.from(this._handleing.values()))}gc(){this._handled.forEach((A,e)=>{const t=this.get(e);t&&"free"in t&&t.free()}),this._handled.clear()}}const Vt=new wl().use(new So).use(new El).use(new pl).use(new Cl).use(new Ql).use(new yl).use(new ml);class yI extends u.Control{constructor(){super();h(this,"_pointerStart");h(this,"_pointerOffset");h(this,"selected");h(this,"dragging");h(this,"hovered");h(this,"hover",new u.Element2D({name:"hover",internalMode:"back",style:{visibility:"hidden",outlineStyle:"solid",outlineColor:16711935,outlineWidth:2,pointerEvents:"none"}}));h(this,"transformRect",new Qn({name:"transformRect",internalMode:"back",style:{visibility:"hidden",pointerEvents:"none"}}));h(this,"scaler",new u.Scaler({internalMode:"back"}).on("updateScale",e=>{this.ruler.gapScale=e,this._updateScrollbars(),this._updateSelectionRect()}));h(this,"xScrollBar",new u.XScrollBar({internalMode:"back",style:{visibility:"hidden"}}));h(this,"yScrollBar",new u.YScrollBar({internalMode:"back",style:{visibility:"hidden"}}));h(this,"drawboard",new u.Element2D({name:"drawboard",style:{width:500,height:500,backgroundColor:4294967295,overflow:"hidden",pointerEvents:"none",boxShadow:"2px 2px 2px 1px rgba(0, 0, 0, 0.2)"}},[this.scaler]));h(this,"ruler",new u.Ruler({name:"ruler",offsetX:100,offsetY:100,style:{pointerEvents:"none"}},[this.drawboard,this.hover,this.transformRect,this.xScrollBar,this.yScrollBar]));this._onPointerdown=this._onPointerdown.bind(this),this._onPointermove=this._onPointermove.bind(this),this._onPointerup=this._onPointerup.bind(this),this.append(this.ruler)}_updateStyleProperty(e,t,i,s){switch(super._updateStyleProperty(e,t,i,s),e){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(e,t){switch(super._guiInput(e,t),t){case"pointerdown":this._onPointerdown(e);break;case"pointermove":this._onPointermove(e);break;case"pointerup":this._onPointerup();break}}_onPointerdown(e){let t=e.target;t!=null&&t.is(this)&&(t=void 0),t!=null&&t.is(this.transformRect)&&(t=this.selected),this._pointerOffset={x:e.offsetX,y:e.offsetY},this.selected=t,this.dragging=t,t instanceof u.Element2D?this._pointerStart=t.style.clone():this._pointerStart=void 0,this._updateHover(),this._updateSelectionRect()}_onPointermove(e){let t=e.target;t!=null&&t.is(this)&&(t=void 0),t!=null&&t.is(this.transformRect)&&(t=this.selected);const{selected:i,dragging:s,_pointerStart:n,_pointerOffset:o}=this;i&&(t!=null&&t.is(i))?this.hovered=void 0:this.hovered=t;const a=o?{x:e.offsetX-o.x,y:e.offsetY-o.y}:{x:0,y:0};s&&n&&(s.style.left=n.left+a.x/this.scaler.value,s.style.top=n.top+a.y/this.scaler.value,s.update()),this._updateHover(),this._updateSelectionRect()}_onPointerup(){this.dragging=void 0,this._updateHover(),this._updateSelectionRect()}_copyGlobalTransform(e,t){e.style.visibility="visible",e.style.width=t.globalScale.x*t.size.x,e.style.height=t.globalScale.y*t.size.y,e.style.left=t.globalPosition.x,e.style.top=t.globalPosition.y,e.style.rotate=t.globalRotation,e.update()}_updateHover(){const e=this.hovered;e instanceof u.Element2D?(this.hover.style.visibility="visible",this._copyGlobalTransform(this.hover,e),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 e=this.ruler.gapScale,t=this.drawboard.size.height*e,i=this.drawboard.size.width*e;t>this.size.height?(this.yScrollBar.style.visibility="visible",this.yScrollBar.maxValue=t,this.yScrollBar.page=this.size.height):this.yScrollBar.style.visibility="hidden",i>this.size.width?(this.xScrollBar.style.visibility="visible",this.xScrollBar.maxValue=i,this.xScrollBar.page=this.size.width):this.xScrollBar.style.visibility="hidden"}}const vl={alpha:!0,stencil:!0,antialias:!1,premultipliedAlpha:!0,preserveDrawingBuffer:!1,powerPreference:"default"};class _l extends nr{constructor(e={}){var f,I;const{view:t,width:i,height:s,pixelRatio:n=ss,backgroundColor:o=0,autoResize:a,autoStart:l,timeline:g,...c}=e;super(g);h(this,"renderer");h(this,"_resizeObserver",Ln?new ResizeObserver(e=>{const t=e[0];if(t.target===this.view){const{inlineSize:i,blockSize:s}=Array.isArray(t.contentBoxSize)?t.contentBoxSize[0]:t.contentBoxSize;this.resize(i,s)}}):void 0);this.renderer=new xo(t,{...vl,...c}),this._setupInput(),this.pixelRatio=n,this.backgroundColor=o,a?(!t&&this.renderer.view&&(this.renderer.view.style.width="100%",this.renderer.view.style.height="100%"),this.enableAutoResize(a)):this.resize(i||this.gl.drawingBufferWidth||((f=this.view)==null?void 0:f.clientWidth)||200,s||this.gl.drawingBufferHeight||((I=this.view)==null?void 0:I.clientHeight)||200,!t),l&&this.start()}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(e){this.renderer.pixelRatio=e,this.resize(this.width,this.height),this.view&&(this.view.dataset.pixelRatio=String(e))}_setupInput(){return this.view&&(this.input.setTarget(this.view),["pointerdown","pointerover","pointermove","pointerup","wheel"].forEach(e=>{this.input.on(e,t=>{this.root.input(t,e),this.emit(e,t)})})),this}enableAutoResize(e=!0){var t,i;return this.view&&(e?(t=this._resizeObserver)==null||t.observe(this.view):(i=this._resizeObserver)==null||i.unobserve(this.view)),this}resize(e,t,i=!1){return this.renderer.resize(e,t,i),this.root.width=e,this.root.height=t,this.renderer.program.uniforms.projectionMatrix=this.root.toProjectionArray(!0),this}nextTick(){return os()}waitUntilLoad(){return Vt.waitUntilLoad()}render(e=0){return this._render(this.renderer,e)}start(){return this.render(),super.start(e=>{this.render(e)})}free(){super.free(),this.enableAutoResize(!1),this.renderer.free()}toPixels(){return this.render(),this.renderer.toPixels()}toImageData(){return new ImageData(this.toPixels(),this.gl.drawingBufferWidth,this.gl.drawingBufferHeight)}toCanvas2D(){var s,n;const e=this.toImageData(),t=document.createElement("canvas");t.width=e.width,t.height=e.height,(s=t.getContext("2d"))==null||s.putImageData(e,0,0);const i=document.createElement("canvas");return i.width=this.width,i.height=this.height,(n=i.getContext("2d"))==null||n.drawImage(t,0,0,t.width,t.height,0,0,i.width,i.height),i}}let Li,mI;const Dl=[];async function wI(r=100){for(;;){const A=Dl.shift();if(A)try{await A()}catch(e){console.error(e)}else await new Promise(e=>setTimeout(e,r))}}async function vI(r){Li??(Li=new _l({width:1,height:1}));const A=Li.root;A.removeChildren();const{data:e,width:t,height:i}=r;return Li.resize(t,i),(Array.isArray(e)?e:[e]).forEach(s=>{s instanceof u.Node?A.appendChild(s):A.appendChild(u.Node.parse(s))}),await Li.waitUntilLoad(),Li.toCanvas2D()}async function _I(r){return mI??(mI=wI()),new Promise(A=>{Dl.push(async()=>A(await vI(r)))})}u.AnimatedTexture=Zi,u.Assets=wl,u.AudioPipeline=yn,u.AudioProcessor=bd,u.AudioSpectrum=Nd,u.BaseElement2DStyle=Qi,u.CanvasContext=xa,u.CanvasItemEditor=yI,u.CanvasTexture=ai,u.Color=Zt,u.ColorMatrix=fs,u.ColorTexture=ps,u.CoreObject=Wi,u.DEG_TO_RAD=ho,u.DEVICE_PIXEL_RATIO=ss,u.EffectMaterial=ji,u.Element2DStyle=Ls,u.Engine=_l,u.EventEmitter=Gt,u.FlexElement2DStyle=Os,u.FlexLayout=lr,u.FontLoader=So,u.GIFLoader=El,u.Geometry=Xi,u.HTMLAudio=fl,u.HTMLAudioContext=Mr,u.HTMLSound=Rr,u.IN_BROWSER=si,u.ImageTexture=bg,u.IndexBuffer=MA,u.Input=$n,u.InputEvent=Vi,u.JSONLoader=pl,u.Loader=$t,u.LottieLoader=Cl,u.MainLoop=qi,u.Material=Qe,u.Matrix=Dt,u.Matrix2=hg,u.Matrix3=ds,u.Matrix4=go,u.MouseInputEvent=as,u.PI=Tt,u.PI_2=ze,u.PixelsTexture=Cs,u.PointerInputEvent=Zn,u.Projection2D=uo,u.QuadGeometry=pg,u.QuadUvGeometry=fe,u.RAD_TO_DEG=lg,u.RawWeakMap=bA,u.Rect2=Is,u.RefCounted=jn,u.Renderer=Io,u.Resource=Ot,u.SUPPORTS_AUDIO_CONTEXT=As,u.SUPPORTS_CLICK_EVENTS=On,u.SUPPORTS_CREATE_IMAGE_BITMAP=ts,u.SUPPORTS_IMAGE_BITMAP=Tn,u.SUPPORTS_MOUSE_EVENTS=ql,u.SUPPORTS_OFFLINE_AUDIO_CONTEXT=rs,u.SUPPORTS_POINTER_EVENTS=DA,u.SUPPORTS_RESIZE_OBSERVER=Ln,u.SUPPORTS_TOUCH_EVENTS=Lt,u.SUPPORTS_WEBGL2=Fn,u.SUPPORTS_WEBKIT_AUDIO_CONTEXT=is,u.SUPPORTS_WEBKIT_OFFLINE_AUDIO_CONTEXT=Hn,u.SUPPORTS_WEB_AUDIO=Jn,u.SUPPORTS_WHEEL_EVENTS=Gn,u.SceneTree=nr,u.TextLoader=Ql,u.Texture2D=ve,u.TextureLoader=yl,u.TextureRect2D=gr,u.Ticker=xe,u.Transform2D=xt,u.TransformRect2D=Qn,u.UvGeometry=mg,u.UvMaterial=RA,u.Vector=Ct,u.Vector2=Qt,u.Vector3=cg,u.Vector4=co,u.VertexAttribute=gt,u.VertexBuffer=Jt,u.VideoLoader=ml,u.VideoTexture=To,u.ViewportTexture=ys,u.WebAudio=Il,u.WebAudioContext=lA,u.WebGLBatch2DModule=po,u.WebGLBlendMode=SA,u.WebGLBufferModule=Co,u.WebGLFramebufferModule=Qo,u.WebGLMaskModule=yo,u.WebGLModule=It,u.WebGLProgramModule=mo,u.WebGLRenderer=xo,u.WebGLScissorModule=wo,u.WebGLState=fA,u.WebGLStateModule=Eo,u.WebGLStencilModule=vo,u.WebGLTextureModule=_o,u.WebGLVertexArrayModule=Do,u.WebGLViewportModule=bo,u.WebSound=dl,u.WheelInputEvent=ni,u.assets=Vt,u.clamp=bt,u.createHTMLCanvas=Vn,u.createNode=jl,u.crossOrigin=qn,u.cubicBezier=$A,u.curves=gg,u.customNode=re,u.customNodes=Yi,u.defaultOptions=vl,u.defineProperty=xA,u.determineCrossOrigin=zn,u.ease=gl,u.easeIn=hl,u.easeInOut=ul,u.easeOut=cl,u.getDeclarations=Ki,u.getDefaultCssPropertyValue=es,u.isCanvasElement=Yn,u.isElementNode=ns,u.isImageElement=Xl,u.isPow2=$r,u.isVideoElement=Kn,u.isWebgl2=Wn,u.lerp=Se,u.linear=ll,u.log2=Es,u.mapWebGLBlendModes=Bo,u.nextPow2=Bs,u.nextTick=os,u.parseCSSFilter=Ro,u.parseCSSTransform=Uo,u.parseCSSTransformOrigin=ko,u.parseCssFunctions=ri,u.parseCssProperty=ii,u.property=k,u.protectedProperty=Ce,u.render=_I,u.timingFunctions=Sr,u.uid=Pn,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
912
+ }`})),u.TwistTransition=BI([re("TwistTransition")],u.TwistTransition);class El extends $t{install(A){const e=async t=>{const{decodeFrames:i}=await import("modern-gif");return await A.fetch(t).then(s=>s.arrayBuffer()).then(s=>i(s)).then(s=>new Zi(s.map(n=>({duration:n.delay,texture:new Cs(n.data,n.width,n.height)}))))};return this.load=t=>A.loadBy(t,()=>e(t)),["image/gif"].forEach(t=>{A.register(t,e)}),A.gif=this,this}}class pl extends $t{install(A){const e=t=>A.fetch(t).then(i=>i.json());return this.load=t=>A.loadBy(t,()=>e(t)),["json"].forEach(t=>{A.register(t,e)}),A.json=this,this}}class Cl extends $t{install(A){const e=async(t,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 A.fetch(t).then(n=>n.json())});return this.load=(t,i)=>A.loadBy(t,()=>e(t,i)),["lottie"].forEach(t=>{A.register(t,e)}),A.lottie=this,this}}class Ql extends $t{install(A){const e=async t=>await A.fetch(t).then(i=>i.text());return this.load=t=>A.loadBy(t,()=>e(t)),A.text=this,this}}class yl extends $t{install(A){const e=t=>A.fetchImageBitmap(t,{premultiplyAlpha:"premultiply"}).then(i=>new ve(i));return this.load=t=>A.loadBy(t,()=>e(t)),["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(t=>{A.register(t,e)}),A.texture=this,this}}class ml extends $t{install(A){const e=t=>new To(t).load();return this.load=t=>A.loadBy(t,()=>e(t)),["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(t=>{A.register(t,e)}),A.video=this,this}}const pI=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 CI(r){for(const[A,e]of pI)if(e.includes(r))return A}async function QI(r){var e,t;let A;if(r.startsWith("data:"))A=(e=r.match(/^data:(.+?);/))==null?void 0:e[1];else if(r.startsWith("http")){const i=(t=r.split(/[#?]/)[0].split(".").pop())==null?void 0:t.trim();i&&(A=CI(i))}return A??await fetch(r).then(i=>i.headers.get("Content-Type"))??""}const Pr="WeakRef"in globalThis;class wl{constructor(){h(this,"defaultHandler",A=>this.fetch(A));h(this,"_handlers",new Map);h(this,"_handleing",new Map);h(this,"_handled",new Map);h(this,"_gc",Pr?new FinalizationRegistry(A=>{const e=this.get(A);e&&"free"in e&&e.free(),this._handled.delete(A)}):void 0);Pr||xe.on(this.gc.bind(this),{sort:2})}use(A){return A.install(this),this}register(A,e){return this._handlers.set(A,e),this}fetch(A){return fetch(A)}_fixSVG(A){const e=new DOMParser().parseFromString(decodeURIComponent(A.split(",")[1]),"image/svg+xml").documentElement;return e.setAttribute("width","512"),e.setAttribute("height","512"),`data:image/svg+xml;charset=utf-8,${encodeURIComponent(e.outerHTML)}`}async fetchImageBitmap(A,e){return A.startsWith("http")?await this.fetch(A).then(t=>t.blob()).then(t=>t.type==="image/svg+xml"?t.text().then(i=>this.fetchImageBitmap(this._fixSVG(`data:image/svg+xml;charset=utf-8,${encodeURIComponent(i)}`),e)):createImageBitmap(t,e)):(A.startsWith("data:image/svg+xml;charset=utf-8,")&&(A=this._fixSVG(A)),new Promise(t=>{const i=new Image;i.src=A,i.onload=()=>{i.decode().finally(()=>{t(i)})}}).then(t=>createImageBitmap(t,e)))}get(A){let e=this._handled.get(A);return Pr&&e instanceof WeakRef&&(e=e.deref(),e||this._handleing.delete(A)),e}set(A,e){let t=e;Pr&&typeof e=="object"&&(this._gc.register(e,A),t=new WeakRef(e)),this._handled.set(A,t)}async loadBy(A,e){const t=this.get(A)??this._handleing.get(A);if(t)return t;const i=e().then(s=>(this.set(A,s),s)).finally(()=>{this._handleing.delete(A)});return this._handleing.set(A,i),i}async load(A,e){return this.loadBy(A,async()=>{const t=await QI(A);return(this._handlers.get(t)??this.defaultHandler)(A,e)})}async waitUntilLoad(){await Promise.all(Array.from(this._handleing.values()))}gc(){this._handled.forEach((A,e)=>{const t=this.get(e);t&&"free"in t&&t.free()}),this._handled.clear()}}const Vt=new wl().use(new So).use(new El).use(new pl).use(new Cl).use(new Ql).use(new yl).use(new ml);class yI extends u.Control{constructor(){super();h(this,"_pointerStart");h(this,"_pointerOffset");h(this,"selected");h(this,"dragging");h(this,"hovered");h(this,"hover",new u.Element2D({name:"hover",internalMode:"back",style:{visibility:"hidden",outlineStyle:"solid",outlineColor:16711935,outlineWidth:2,pointerEvents:"none"}}));h(this,"transformRect",new Qn({name:"transformRect",internalMode:"back",style:{visibility:"hidden",pointerEvents:"none"}}));h(this,"scaler",new u.Scaler({internalMode:"back"}).on("updateScale",e=>{this.ruler.gapScale=e,this._updateScrollbars(),this._updateSelectionRect()}));h(this,"xScrollBar",new u.XScrollBar({internalMode:"back",style:{visibility:"hidden"}}));h(this,"yScrollBar",new u.YScrollBar({internalMode:"back",style:{visibility:"hidden"}}));h(this,"drawboard",new u.Element2D({name:"drawboard",style:{width:500,height:500,backgroundColor:4294967295,overflow:"hidden",pointerEvents:"none",boxShadow:"2px 2px 2px 1px rgba(0, 0, 0, 0.2)"}},[this.scaler]));h(this,"ruler",new u.Ruler({name:"ruler",offsetX:100,offsetY:100,style:{pointerEvents:"none"}},[this.drawboard,this.hover,this.transformRect,this.xScrollBar,this.yScrollBar]));this._onPointerdown=this._onPointerdown.bind(this),this._onPointermove=this._onPointermove.bind(this),this._onPointerup=this._onPointerup.bind(this),this.append(this.ruler)}_updateStyleProperty(e,t,i,s){switch(super._updateStyleProperty(e,t,i,s),e){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(e,t){switch(super._guiInput(e,t),t){case"pointerdown":this._onPointerdown(e);break;case"pointermove":this._onPointermove(e);break;case"pointerup":this._onPointerup();break}}_onPointerdown(e){let t=e.target;t!=null&&t.is(this)&&(t=void 0),t!=null&&t.is(this.transformRect)&&(t=this.selected),this._pointerOffset={x:e.offsetX,y:e.offsetY},this.selected=t,this.dragging=t,t instanceof u.Element2D?this._pointerStart=t.style.clone():this._pointerStart=void 0,this._updateHover(),this._updateSelectionRect()}_onPointermove(e){let t=e.target;t!=null&&t.is(this)&&(t=void 0),t!=null&&t.is(this.transformRect)&&(t=this.selected);const{selected:i,dragging:s,_pointerStart:n,_pointerOffset:o}=this;i&&(t!=null&&t.is(i))?this.hovered=void 0:this.hovered=t;const a=o?{x:e.offsetX-o.x,y:e.offsetY-o.y}:{x:0,y:0};s&&n&&(s.style.left=n.left+a.x/this.scaler.value,s.style.top=n.top+a.y/this.scaler.value,s.update()),this._updateHover(),this._updateSelectionRect()}_onPointerup(){this.dragging=void 0,this._updateHover(),this._updateSelectionRect()}_copyGlobalTransform(e,t){e.style.visibility="visible",e.style.width=t.globalScale.x*t.size.x,e.style.height=t.globalScale.y*t.size.y,e.style.left=t.globalPosition.x,e.style.top=t.globalPosition.y,e.style.rotate=t.globalRotation,e.update()}_updateHover(){const e=this.hovered;e instanceof u.Element2D?(this.hover.style.visibility="visible",this._copyGlobalTransform(this.hover,e),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 e=this.ruler.gapScale,t=this.drawboard.size.height*e,i=this.drawboard.size.width*e;t>this.size.height?(this.yScrollBar.style.visibility="visible",this.yScrollBar.maxValue=t,this.yScrollBar.page=this.size.height):this.yScrollBar.style.visibility="hidden",i>this.size.width?(this.xScrollBar.style.visibility="visible",this.xScrollBar.maxValue=i,this.xScrollBar.page=this.size.width):this.xScrollBar.style.visibility="hidden"}}const vl={alpha:!0,stencil:!0,antialias:!1,premultipliedAlpha:!0,preserveDrawingBuffer:!1,powerPreference:"default"};class _l extends nr{constructor(e={}){var f,I;const{view:t,width:i,height:s,pixelRatio:n=ss,backgroundColor:o=0,autoResize:a,autoStart:l,timeline:g,...c}=e;super(g);h(this,"renderer");h(this,"_resizeObserver",Ln?new ResizeObserver(e=>{const t=e[0];if(t.target===this.view){const{inlineSize:i,blockSize:s}=Array.isArray(t.contentBoxSize)?t.contentBoxSize[0]:t.contentBoxSize;this.resize(i,s)}}):void 0);this.renderer=new xo(t,{...vl,...c}),this._setupInput(),this.pixelRatio=n,this.backgroundColor=o,a?(!t&&this.renderer.view&&(this.renderer.view.style.width="100%",this.renderer.view.style.height="100%"),this.enableAutoResize(a)):this.resize(i||this.gl.drawingBufferWidth||((f=this.view)==null?void 0:f.clientWidth)||200,s||this.gl.drawingBufferHeight||((I=this.view)==null?void 0:I.clientHeight)||200,!t),l&&this.start()}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(e){this.renderer.pixelRatio=e,this.resize(this.width,this.height),this.view&&(this.view.dataset.pixelRatio=String(e))}_setupInput(){return this.view&&(this.input.setTarget(this.view),["pointerdown","pointerover","pointermove","pointerup","wheel"].forEach(e=>{this.input.on(e,t=>{this.root.input(t,e),this.emit(e,t)})})),this}enableAutoResize(e=!0){var t,i;return this.view&&(e?(t=this._resizeObserver)==null||t.observe(this.view):(i=this._resizeObserver)==null||i.unobserve(this.view)),this}resize(e,t,i=!1){return this.renderer.resize(e,t,i),this.root.width=e,this.root.height=t,this.renderer.program.uniforms.projectionMatrix=this.root.toProjectionArray(!0),this}nextTick(){return os()}async waitUntilLoad(){await Vt.waitUntilLoad(),await this.nextTick()}render(e=0){return this._render(this.renderer,e)}start(){return this.render(),super.start(e=>{this.render(e)})}free(){super.free(),this.enableAutoResize(!1),this.renderer.free()}toPixels(){return this.render(),this.renderer.toPixels()}toImageData(){return new ImageData(this.toPixels(),this.gl.drawingBufferWidth,this.gl.drawingBufferHeight)}toCanvas2D(){var s,n;const e=this.toImageData(),t=document.createElement("canvas");t.width=e.width,t.height=e.height,(s=t.getContext("2d"))==null||s.putImageData(e,0,0);const i=document.createElement("canvas");return i.width=this.width,i.height=this.height,(n=i.getContext("2d"))==null||n.drawImage(t,0,0,t.width,t.height,0,0,i.width,i.height),i}}let Li,mI;const Dl=[];async function wI(r=100){for(;;){const A=Dl.shift();if(A)try{await A()}catch(e){console.error(e)}else await new Promise(e=>setTimeout(e,r))}}async function vI(r){Li??(Li=new _l({width:1,height:1}));const A=Li.root;A.removeChildren();const{data:e,width:t,height:i}=r;return Li.resize(t,i),(Array.isArray(e)?e:[e]).forEach(s=>{s instanceof u.Node?A.appendChild(s):A.appendChild(u.Node.parse(s))}),await Li.waitUntilLoad(),Li.toCanvas2D()}async function _I(r){return mI??(mI=wI()),new Promise(A=>{Dl.push(async()=>A(await vI(r)))})}u.AnimatedTexture=Zi,u.Assets=wl,u.AudioPipeline=yn,u.AudioProcessor=bd,u.AudioSpectrum=Nd,u.BaseElement2DStyle=Qi,u.CanvasContext=xa,u.CanvasItemEditor=yI,u.CanvasTexture=ai,u.Color=Zt,u.ColorMatrix=fs,u.ColorTexture=ps,u.CoreObject=Wi,u.DEG_TO_RAD=ho,u.DEVICE_PIXEL_RATIO=ss,u.EffectMaterial=ji,u.Element2DStyle=Ls,u.Engine=_l,u.EventEmitter=Gt,u.FlexElement2DStyle=Os,u.FlexLayout=lr,u.FontLoader=So,u.GIFLoader=El,u.Geometry=Xi,u.HTMLAudio=fl,u.HTMLAudioContext=Mr,u.HTMLSound=Rr,u.IN_BROWSER=si,u.ImageTexture=bg,u.IndexBuffer=MA,u.Input=$n,u.InputEvent=Vi,u.JSONLoader=pl,u.Loader=$t,u.LottieLoader=Cl,u.MainLoop=qi,u.Material=Qe,u.Matrix=Dt,u.Matrix2=hg,u.Matrix3=ds,u.Matrix4=go,u.MouseInputEvent=as,u.PI=Tt,u.PI_2=ze,u.PixelsTexture=Cs,u.PointerInputEvent=Zn,u.Projection2D=uo,u.QuadGeometry=pg,u.QuadUvGeometry=fe,u.RAD_TO_DEG=lg,u.RawWeakMap=bA,u.Rect2=Is,u.RefCounted=jn,u.Renderer=Io,u.Resource=Ot,u.SUPPORTS_AUDIO_CONTEXT=As,u.SUPPORTS_CLICK_EVENTS=On,u.SUPPORTS_CREATE_IMAGE_BITMAP=ts,u.SUPPORTS_IMAGE_BITMAP=Tn,u.SUPPORTS_MOUSE_EVENTS=ql,u.SUPPORTS_OFFLINE_AUDIO_CONTEXT=rs,u.SUPPORTS_POINTER_EVENTS=DA,u.SUPPORTS_RESIZE_OBSERVER=Ln,u.SUPPORTS_TOUCH_EVENTS=Lt,u.SUPPORTS_WEBGL2=Fn,u.SUPPORTS_WEBKIT_AUDIO_CONTEXT=is,u.SUPPORTS_WEBKIT_OFFLINE_AUDIO_CONTEXT=Hn,u.SUPPORTS_WEB_AUDIO=Jn,u.SUPPORTS_WHEEL_EVENTS=Gn,u.SceneTree=nr,u.TextLoader=Ql,u.Texture2D=ve,u.TextureLoader=yl,u.TextureRect2D=gr,u.Ticker=xe,u.Transform2D=xt,u.TransformRect2D=Qn,u.UvGeometry=mg,u.UvMaterial=RA,u.Vector=Ct,u.Vector2=Qt,u.Vector3=cg,u.Vector4=co,u.VertexAttribute=gt,u.VertexBuffer=Jt,u.VideoLoader=ml,u.VideoTexture=To,u.ViewportTexture=ys,u.WebAudio=Il,u.WebAudioContext=lA,u.WebGLBatch2DModule=po,u.WebGLBlendMode=SA,u.WebGLBufferModule=Co,u.WebGLFramebufferModule=Qo,u.WebGLMaskModule=yo,u.WebGLModule=It,u.WebGLProgramModule=mo,u.WebGLRenderer=xo,u.WebGLScissorModule=wo,u.WebGLState=fA,u.WebGLStateModule=Eo,u.WebGLStencilModule=vo,u.WebGLTextureModule=_o,u.WebGLVertexArrayModule=Do,u.WebGLViewportModule=bo,u.WebSound=dl,u.WheelInputEvent=ni,u.assets=Vt,u.clamp=bt,u.createHTMLCanvas=Vn,u.createNode=jl,u.crossOrigin=qn,u.cubicBezier=$A,u.curves=gg,u.customNode=re,u.customNodes=Yi,u.defaultOptions=vl,u.defineProperty=xA,u.determineCrossOrigin=zn,u.ease=gl,u.easeIn=hl,u.easeInOut=ul,u.easeOut=cl,u.getDeclarations=Ki,u.getDefaultCssPropertyValue=es,u.isCanvasElement=Yn,u.isElementNode=ns,u.isImageElement=Xl,u.isPow2=$r,u.isVideoElement=Kn,u.isWebgl2=Wn,u.lerp=Se,u.linear=ll,u.log2=Es,u.mapWebGLBlendModes=Bo,u.nextPow2=Bs,u.nextTick=os,u.parseCSSFilter=Ro,u.parseCSSTransform=Uo,u.parseCSSTransformOrigin=ko,u.parseCssFunctions=ri,u.parseCssProperty=ii,u.property=k,u.protectedProperty=Ce,u.render=_I,u.timingFunctions=Sr,u.uid=Pn,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
package/dist/index.mjs CHANGED
@@ -13109,8 +13109,9 @@ class Engine extends SceneTree {
13109
13109
  nextTick() {
13110
13110
  return nextTick();
13111
13111
  }
13112
- waitUntilLoad() {
13113
- return assets.waitUntilLoad();
13112
+ async waitUntilLoad() {
13113
+ await assets.waitUntilLoad();
13114
+ await this.nextTick();
13114
13115
  }
13115
13116
  render(delta = 0) {
13116
13117
  return this._render(this.renderer, delta);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-canvas",
3
3
  "type": "module",
4
- "version": "0.4.4",
4
+ "version": "0.4.5",
5
5
  "packageManager": "pnpm@9.15.1",
6
6
  "description": "A JavaScript WebGL rendering engine.",
7
7
  "author": "wxm",