modern-canvas 0.1.6 → 0.1.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 CHANGED
@@ -254,10 +254,12 @@ class EventEmitter {
254
254
 
255
255
  class RawWeakMap {
256
256
  _map = /* @__PURE__ */ new WeakMap();
257
+ // fix: vue reactive object
257
258
  _toRaw(value) {
258
259
  if (value && typeof value === "object") {
259
- if ("__v_raw" in value) {
260
- value = value.__v_raw;
260
+ const raw = value.__v_raw;
261
+ if (raw) {
262
+ value = this._toRaw(raw);
261
263
  }
262
264
  }
263
265
  return value;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(g,Te){typeof exports=="object"&&typeof module<"u"?Te(exports):typeof define=="function"&&define.amd?define(["exports"],Te):(g=typeof globalThis<"u"?globalThis:g||self,Te(g.modernCanvas={}))})(this,function(g){"use strict";var tp=Object.defineProperty;var rp=(g,Te,le)=>Te in g?tp(g,Te,{enumerable:!0,configurable:!0,writable:!0,value:le}):g[Te]=le;var u=(g,Te,le)=>rp(g,typeof Te!="symbol"?Te+"":Te,le);var Zt,Rt;const Te=Math.PI,le=Te*2;let ll=0;function cn(n){var r;return((r=n==null?void 0:n.__SPECTOR_Object_TAG)==null?void 0:r.id)??++ll}function Vi(n){return!(n&n-1)&&!!n}const hl=/([\w-]+)\((.+?)\)/g,cl=/[^,]+/g,ul=/([-e.\d]+)(.*)/;function ji(n){return Array.isArray(n)?n.map(r=>({name:r.name,args:r.args.map(e=>({...e,normalizedIntValue:e.normalizedDefaultIntValue}))})):{...n,normalizedIntValue:n.normalizedDefaultIntValue}}function mr(n,r,e={}){const t=yr(r,e);return t.length?t:un(n,r,e)}function yr(n,r={}){const e=[];let t;for(;(t=hl.exec(n))!==null;){const[,i,s]=t;i&&e.push({name:i,args:fl(i,s,r)})}return e}function fl(n,r,e={}){const t=[];let i,s=0;for(;(i=cl.exec(r))!==null;)t.push(un(n,i[0],{...e,index:s++}));return t}function un(n,r,e={}){const{width:t=1,height:i=1,index:s=0}=e,o=r.match(ul),a={unit:(o==null?void 0:o[2])??null,value:r,intValue:Number(o==null?void 0:o[1]),normalizedIntValue:0,normalizedDefaultIntValue:0};switch(n){case"scale":case"scaleX":case"scaleY":case"scale3d":a.normalizedDefaultIntValue=1;break}switch(a.unit){case"%":a.normalizedIntValue=a.intValue/100;break;case"rad":a.normalizedIntValue=a.intValue/le;break;case"deg":a.normalizedIntValue=a.intValue/360;break;case"px":switch(s){case 0:a.normalizedIntValue=a.intValue/t;break;case 1:a.normalizedIntValue=a.intValue/i;break}break;case"turn":case"em":case"rem":default:a.normalizedIntValue=a.intValue;break}return a}const fn="WebGL2RenderingContext"in globalThis,dn="ImageBitmap"in globalThis,pn="ResizeObserver"in globalThis,Jt="PointerEvent"in globalThis,gn="WheelEvent"in globalThis,dl="MouseEvent"in globalThis,ft="ontouchstart"in globalThis,mn="onclick"in globalThis,Gi="createImageBitmap"in globalThis,qi="AudioContext"in globalThis,Wi="webkitAudioContext"in globalThis,Xi="OfflineAudioContext"in globalThis,yn="webkitOfflineAudioContext"in globalThis,_n=qi||Wi,_r=typeof window<"u",Hi=globalThis.devicePixelRatio||1,Yi=n=>n!==null&&typeof n=="object"&&n.nodeType===1,vn=n=>Yi(n)&&n.tagName==="VIDEO",pl=n=>Yi(n)&&n.tagName==="IMG";function bn(n){return typeof n=="object"&&n!==null&&n.nodeType===1&&n.tagName==="CANVAS"}function wn(n){return fn&&n instanceof globalThis.WebGL2RenderingContext}function xn(){if(_r)return globalThis.document.createElement("canvas")}function Pn(n,r=globalThis.location){if(n.startsWith("data:"))return"";r=r||globalThis.location;const e=new URL(n,document.baseURI);return e.hostname!==r.hostname||e.port!==r.port||e.protocol!==r.protocol?"anonymous":""}function Cn(n,r,e){e===null&&!r.startsWith("data:")?n.crossOrigin=Pn(r):e!==!1&&(n.crossOrigin=typeof e=="string"?e:"anonymous")}let dt=class{constructor(){u(this,"eventListeners",new Map)}removeAllListeners(){return this.eventListeners.clear(),this}hasEventListener(r){return this.eventListeners.has(r)}on(r,e,t){const i={value:e,options:t},s=this.eventListeners.get(r);return s?Array.isArray(s)?s.push(i):this.eventListeners.set(r,[s,i]):this.eventListeners.set(r,i),this}once(r,e){return this.on(r,e,{once:!0})}off(r,e,t){var s,o;if(!e)return this.eventListeners.delete(r),this;const i=this.eventListeners.get(r);if(!i)return this;if(Array.isArray(i)){const a=[];for(let l=0,h=i.length;l<h;l++){const c=i[l];(c.value!==e||typeof t=="object"&&(t!=null&&t.once)&&(typeof c.options=="boolean"||!((s=c.options)!=null&&s.once)))&&a.push(c)}a.length?this.eventListeners.set(r,a.length===1?a[0]:a):this.eventListeners.delete(r)}else i.value===e&&(typeof t=="boolean"||!(t!=null&&t.once)||typeof i.options=="boolean"||(o=i.options)!=null&&o.once)&&this.eventListeners.delete(r);return this}emit(r,...e){var i,s;const t=this.eventListeners.get(r);if(t){if(Array.isArray(t))for(let o=t.length,a=0;a<o;a++){const l=t[a];typeof l.options=="object"&&((i=l.options)!=null&&i.once)&&this.off(r,l.value,l.options),l.value.apply(this,e)}else typeof t.options=="object"&&((s=t.options)!=null&&s.once)&&this.off(r,t.value,t.options),t.value.apply(this,e);return!0}else return!1}};class Qt{constructor(){u(this,"_map",new WeakMap)}_toRaw(r){return r&&typeof r=="object"&&"__v_raw"in r&&(r=r.__v_raw),r}delete(r){return this._map.delete(this._toRaw(r))}get(r){return this._map.get(this._toRaw(r))}has(r){return this._map.has(this._toRaw(r))}set(r,e){return this._map.set(this._toRaw(r),this._toRaw(e)),this}}const Zr=new Map;function H(n){let r,e;return typeof n=="string"?r=n:{tag:r,renderable:e}=n,function(t){Object.defineProperty(t.prototype,"tag",{value:r,enumerable:!0,configurable:!0}),typeof e<"u"&&Object.defineProperty(t,"renderable",{value:e,enumerable:!1,configurable:!1}),Zr.set(r,t)}}const En=new Qt;function Kr(n){let r=En.get(n);if(!r){const e=Object.getPrototypeOf(n);r=new Map(e?Kr(e):void 0),En.set(n,r)}return r}function bt(n,r,e={}){Kr(n).set(r,e);const{default:t,alias:i}=e;let s=Object.getOwnPropertyDescriptor(n.prototype,r);if(!s){const o=i??Symbol.for(String(r));s={get(){return this[o]},set(a){this[o]=a}}}Object.defineProperty(n.prototype,r,{get(){var o;return((o=s.get)==null?void 0:o.call(this))??t},set(o){var l,h,c;const a=((l=s.get)==null?void 0:l.call(this))??t;(h=s.set)==null||h.call(this,o),(c=this.requestUpdate)==null||c.call(this,r,a,e)},configurable:!0,enumerable:!0})}function A(n){return function(r,e){bt(r.constructor,e,n)}}function ee(n){return A({...n,protected:!0})}function gl(n="node",r={}){const e=Zr.get(n);if(!e)throw new Error(`Failed to createNode, tag: ${n}`);return new e().setProperties(r)}class ue{static get currentTime(){return this._currentTime}static get elapsed(){return this._elapsed}static on(r,e={}){const{sort:t=0,once:i=!1}=e;this._queue[t]||(this._queue[t]=[]),this._queue[t].push({cb:r,once:i})}static off(r,e={}){const{sort:t=0}=e,i=this._queue[t];if(!i)return;const s=[];for(let o=i.length,a=0;a<o;a++){const l=i[a];l.cb!==r&&s.push(l)}s.length?this._queue[t]=s:this._queue.splice(t,1)}static start(){"requestAnimationFrame"in globalThis&&(this._currentTime=performance.now(),this._requestId=requestAnimationFrame(r=>this._update(r)))}static stop(){this._requestId&&(cancelAnimationFrame(this._requestId),this._requestId=void 0)}static _update(r){this._elapsed=r-this._currentTime,this._currentTime=r,this._requestId=requestAnimationFrame(e=>this._update(e)),this._performUpdate()}static _performUpdate(){const r=this._queue,e=[];for(let t=r.length,i=t;i>=0;i--){const s=r[i];if(!s)continue;const o=[];for(let a=s.length,l=0;l<a;l++){const h=s[l];try{h.cb()}catch(c){console.warn(c)}h.once||o.push(h)}o.length&&(e[i]=o)}this._queue=e}}u(ue,"_queue",[]),u(ue,"_currentTime",0),u(ue,"_elapsed",0),u(ue,"_requestId"),ue.start();async function Zi(n){return new Promise(r=>{ue.on(()=>{n==null||n(),r()},{sort:1,once:!0})})}let ml=0;class Jr extends dt{constructor(){super(...arguments);u(this,"instanceId",++ml);u(this,"_defaultProperties");u(this,"_updatedProperties",new Map);u(this,"_changedProperties",new Set);u(this,"_updatePending",Promise.resolve());u(this,"_isUpdatePending",!1)}async _enqueueUpdate(){this._isUpdatePending=!0;try{await this._updatePending}catch(e){Promise.reject(e)}await Zi(),this._performUpdate()}_performUpdate(){this._isUpdatePending&&(this._onUpdate(this._updatedProperties),this._updatedProperties=new Map,this._isUpdatePending=!1)}_onUpdate(e){}_onUpdateProperty(e,t,i,s){}isDirty(e){return this._updatedProperties.has(e)}getPropertyDeclarations(){return Kr(this.constructor)}getPropertyDeclaration(e){return this.getPropertyDeclarations().get(e)}getDefaultProperties(){if(!this._defaultProperties){this._defaultProperties={};for(const[e,t]of this.getPropertyDeclarations())!t.protected&&!t.alias&&(this._defaultProperties[e]=t.default)}return this._defaultProperties}getProperty(e){return this[e]}setProperty(e,t){return this[e]=t,this}getProperties(e){const t={};for(const[i,s]of this.getPropertyDeclarations())!s.protected&&!s.alias&&(!e||e.includes(i))&&(t[i]=this.getProperty(i));return t}setProperties(e){if(e)for(const[t]of this.getPropertyDeclarations())t in e&&this.setProperty(t,e[t]);return this}requestUpdate(e,t,i){if(e!==void 0){const s=this[e];if(!Object.is(s,t))this._updatedProperties.set(e,t),this._changedProperties.add(e),i??(i=this.getPropertyDeclaration(e)),this._onUpdateProperty(e,s,t,i),this.emit("updateProperty",e,s,t,i);else return}this._isUpdatePending||(this._updatePending=this._enqueueUpdate())}toJSON(){return this.getProperties(Array.from(this._changedProperties))}destroy(){}}class Ki extends Jr{constructor(){super(...arguments);u(this,"_refCount",0)}}class wt extends Ki{}class Qr extends wt{constructor(e={}){super();u(this,"vertexAttributes");u(this,"indexBuffer");u(this,"instanceCount");u(this,"mode");u(this,"_materialWeakMap",new Qt);this.vertexAttributes=new Map(Object.entries((e==null?void 0:e.vertexAttributes)??{})),this.indexBuffer=e==null?void 0:e.indexBuffer,this.instanceCount=e==null?void 0:e.instanceCount,this.mode=(e==null?void 0:e.mode)??"triangles"}_glVertexArray(e){var t;return{attributes:Object.fromEntries(Array.from(this.vertexAttributes).map(([i,s])=>[i,{buffer:s.buffer._glBuffer(e),size:s.size,type:s.type,normalized:s.normalized,stride:s.stride,offset:s.offset,divisor:s.divisor}])),elementArrayBuffer:(t=this.indexBuffer)==null?void 0:t._glBuffer(e)}}_glVertexArrayObject(e,t){let i=this._materialWeakMap.get(t);return i||(i={material:t.instanceId,geometry:this.instanceId},this._materialWeakMap.set(t,i)),e.getRelated(i,()=>e.vertexArray.create(t._glProgram(e),this._glVertexArray(e)))}draw(e,t,i){var l;e.flush(),t.activate(e,i);const s=this._glVertexArrayObject(e,t);let o=!1,a;this.vertexAttributes.forEach(h=>{(a==null?void 0:a.instanceId)!==h.buffer.instanceId&&(a=h.buffer,a.upload(e)&&(o=!0)),h.upload()&&(o=!0)}),(l=this.indexBuffer)!=null&&l.upload(e)&&(o=!0),o&&s&&e.vertexArray.update(t._glProgram(e),s,this._glVertexArray(e)),e.vertexArray.bind(s??this._glVertexArray(e)),e.draw({mode:this.mode,instanceCount:this.instanceCount}),e.vertexArray.unbind()}}var yl=Object.defineProperty,Tn=(n,r,e,t)=>{for(var i=void 0,s=n.length-1,o;s>=0;s--)(o=n[s])&&(i=o(r,e,i)||i);return i&&yl(r,e,i),i};class er extends wt{constructor(e){super();u(this,"needsUpload",!1);this.setProperties(e)}_glBufferOptions(){return{target:"element_array_buffer",data:this.data,usage:this.dynamic?"dynamic_draw":"static_draw"}}_glBuffer(e){return e.getRelated(this,()=>e.buffer.create(this._glBufferOptions()))}_onUpdateProperty(e,t,i){switch(super._onUpdateProperty(e,t,i),e){case"data":case"dynamic":this.needsUpload=!0;break}}upload(e){const t=this.needsUpload;return t&&(this.needsUpload=!1,e.buffer.update(this._glBuffer(e),this._glBufferOptions())),t}}Tn([ee({default:null})],er.prototype,"data"),Tn([ee({default:!1})],er.prototype,"dynamic");var _l=Object.defineProperty,Sn=(n,r,e,t)=>{for(var i=void 0,s=n.length-1,o;s>=0;s--)(o=n[s])&&(i=o(r,e,i)||i);return i&&_l(r,e,i),i};class pt extends wt{constructor(e){super();u(this,"needsUpload",!1);this.setProperties(e)}_glBufferOptions(){return{target:"array_buffer",data:this.data,usage:this.dynamic?"dynamic_draw":"static_draw"}}_glBuffer(e){return e.getRelated(this,()=>e.buffer.create(this._glBufferOptions()))}_onUpdateProperty(e,t,i){switch(super._onUpdateProperty(e,t,i),e){case"data":case"dynamic":this.needsUpload=!0;break}}upload(e){const t=this.needsUpload;return t&&(this.needsUpload=!1,e.buffer.update(this._glBuffer(e),this._glBufferOptions())),t}}Sn([ee({default:null})],pt.prototype,"data"),Sn([ee({default:!1})],pt.prototype,"dynamic");var vl=Object.defineProperty,Bt=(n,r,e,t)=>{for(var i=void 0,s=n.length-1,o;s>=0;s--)(o=n[s])&&(i=o(r,e,i)||i);return i&&vl(r,e,i),i};class ze extends wt{constructor(e){super();u(this,"stride");u(this,"offset");u(this,"divisor");u(this,"needsUpload",!1);this.setProperties({buffer:new pt,...e})}_onUpdateProperty(e,t,i){switch(super._onUpdateProperty(e,t,i),e){case"buffer":case"size":case"normalized":case"type":case"stride":case"offset":case"divisor":this.needsUpload=!0;break}}upload(){const e=this.needsUpload;return e&&(this.needsUpload=!1),e}}Bt([ee()],ze.prototype,"buffer"),Bt([ee({default:0})],ze.prototype,"size"),Bt([ee({default:!1})],ze.prototype,"normalized"),Bt([ee({default:"float"})],ze.prototype,"type"),Bt([ee()],ze.prototype,"stride"),Bt([ee()],ze.prototype,"offset"),Bt([ee()],ze.prototype,"divisor");class bl extends Qr{constructor(){super({vertexAttributes:{position:new ze({buffer:new pt({data:new Float32Array([0,0,1,0,1,1,0,1]),dynamic:!1}),size:2,normalized:!1,type:"float"})},indexBuffer:new er({data:new Uint16Array([0,1,3,2]),dynamic:!1}),mode:"triangle_strip"})}}const Li=class Li extends wt{constructor(e={}){super();u(this,"vert");u(this,"frag");u(this,"uniforms");this.vert=e.vert??`precision highp float;
1
+ (function(g,Te){typeof exports=="object"&&typeof module<"u"?Te(exports):typeof define=="function"&&define.amd?define(["exports"],Te):(g=typeof globalThis<"u"?globalThis:g||self,Te(g.modernCanvas={}))})(this,function(g){"use strict";var tp=Object.defineProperty;var rp=(g,Te,le)=>Te in g?tp(g,Te,{enumerable:!0,configurable:!0,writable:!0,value:le}):g[Te]=le;var u=(g,Te,le)=>rp(g,typeof Te!="symbol"?Te+"":Te,le);var Zt,Rt;const Te=Math.PI,le=Te*2;let ll=0;function cn(n){var r;return((r=n==null?void 0:n.__SPECTOR_Object_TAG)==null?void 0:r.id)??++ll}function Vi(n){return!(n&n-1)&&!!n}const hl=/([\w-]+)\((.+?)\)/g,cl=/[^,]+/g,ul=/([-e.\d]+)(.*)/;function ji(n){return Array.isArray(n)?n.map(r=>({name:r.name,args:r.args.map(e=>({...e,normalizedIntValue:e.normalizedDefaultIntValue}))})):{...n,normalizedIntValue:n.normalizedDefaultIntValue}}function mr(n,r,e={}){const t=yr(r,e);return t.length?t:un(n,r,e)}function yr(n,r={}){const e=[];let t;for(;(t=hl.exec(n))!==null;){const[,i,s]=t;i&&e.push({name:i,args:fl(i,s,r)})}return e}function fl(n,r,e={}){const t=[];let i,s=0;for(;(i=cl.exec(r))!==null;)t.push(un(n,i[0],{...e,index:s++}));return t}function un(n,r,e={}){const{width:t=1,height:i=1,index:s=0}=e,o=r.match(ul),a={unit:(o==null?void 0:o[2])??null,value:r,intValue:Number(o==null?void 0:o[1]),normalizedIntValue:0,normalizedDefaultIntValue:0};switch(n){case"scale":case"scaleX":case"scaleY":case"scale3d":a.normalizedDefaultIntValue=1;break}switch(a.unit){case"%":a.normalizedIntValue=a.intValue/100;break;case"rad":a.normalizedIntValue=a.intValue/le;break;case"deg":a.normalizedIntValue=a.intValue/360;break;case"px":switch(s){case 0:a.normalizedIntValue=a.intValue/t;break;case 1:a.normalizedIntValue=a.intValue/i;break}break;case"turn":case"em":case"rem":default:a.normalizedIntValue=a.intValue;break}return a}const fn="WebGL2RenderingContext"in globalThis,dn="ImageBitmap"in globalThis,pn="ResizeObserver"in globalThis,Jt="PointerEvent"in globalThis,gn="WheelEvent"in globalThis,dl="MouseEvent"in globalThis,ft="ontouchstart"in globalThis,mn="onclick"in globalThis,Gi="createImageBitmap"in globalThis,qi="AudioContext"in globalThis,Wi="webkitAudioContext"in globalThis,Xi="OfflineAudioContext"in globalThis,yn="webkitOfflineAudioContext"in globalThis,_n=qi||Wi,_r=typeof window<"u",Hi=globalThis.devicePixelRatio||1,Yi=n=>n!==null&&typeof n=="object"&&n.nodeType===1,vn=n=>Yi(n)&&n.tagName==="VIDEO",pl=n=>Yi(n)&&n.tagName==="IMG";function bn(n){return typeof n=="object"&&n!==null&&n.nodeType===1&&n.tagName==="CANVAS"}function wn(n){return fn&&n instanceof globalThis.WebGL2RenderingContext}function xn(){if(_r)return globalThis.document.createElement("canvas")}function Pn(n,r=globalThis.location){if(n.startsWith("data:"))return"";r=r||globalThis.location;const e=new URL(n,document.baseURI);return e.hostname!==r.hostname||e.port!==r.port||e.protocol!==r.protocol?"anonymous":""}function Cn(n,r,e){e===null&&!r.startsWith("data:")?n.crossOrigin=Pn(r):e!==!1&&(n.crossOrigin=typeof e=="string"?e:"anonymous")}let dt=class{constructor(){u(this,"eventListeners",new Map)}removeAllListeners(){return this.eventListeners.clear(),this}hasEventListener(r){return this.eventListeners.has(r)}on(r,e,t){const i={value:e,options:t},s=this.eventListeners.get(r);return s?Array.isArray(s)?s.push(i):this.eventListeners.set(r,[s,i]):this.eventListeners.set(r,i),this}once(r,e){return this.on(r,e,{once:!0})}off(r,e,t){var s,o;if(!e)return this.eventListeners.delete(r),this;const i=this.eventListeners.get(r);if(!i)return this;if(Array.isArray(i)){const a=[];for(let l=0,h=i.length;l<h;l++){const c=i[l];(c.value!==e||typeof t=="object"&&(t!=null&&t.once)&&(typeof c.options=="boolean"||!((s=c.options)!=null&&s.once)))&&a.push(c)}a.length?this.eventListeners.set(r,a.length===1?a[0]:a):this.eventListeners.delete(r)}else i.value===e&&(typeof t=="boolean"||!(t!=null&&t.once)||typeof i.options=="boolean"||(o=i.options)!=null&&o.once)&&this.eventListeners.delete(r);return this}emit(r,...e){var i,s;const t=this.eventListeners.get(r);if(t){if(Array.isArray(t))for(let o=t.length,a=0;a<o;a++){const l=t[a];typeof l.options=="object"&&((i=l.options)!=null&&i.once)&&this.off(r,l.value,l.options),l.value.apply(this,e)}else typeof t.options=="object"&&((s=t.options)!=null&&s.once)&&this.off(r,t.value,t.options),t.value.apply(this,e);return!0}else return!1}};class Qt{constructor(){u(this,"_map",new WeakMap)}_toRaw(r){if(r&&typeof r=="object"){const e=r.__v_raw;e&&(r=this._toRaw(e))}return r}delete(r){return this._map.delete(this._toRaw(r))}get(r){return this._map.get(this._toRaw(r))}has(r){return this._map.has(this._toRaw(r))}set(r,e){return this._map.set(this._toRaw(r),this._toRaw(e)),this}}const Zr=new Map;function H(n){let r,e;return typeof n=="string"?r=n:{tag:r,renderable:e}=n,function(t){Object.defineProperty(t.prototype,"tag",{value:r,enumerable:!0,configurable:!0}),typeof e<"u"&&Object.defineProperty(t,"renderable",{value:e,enumerable:!1,configurable:!1}),Zr.set(r,t)}}const En=new Qt;function Kr(n){let r=En.get(n);if(!r){const e=Object.getPrototypeOf(n);r=new Map(e?Kr(e):void 0),En.set(n,r)}return r}function bt(n,r,e={}){Kr(n).set(r,e);const{default:t,alias:i}=e;let s=Object.getOwnPropertyDescriptor(n.prototype,r);if(!s){const o=i??Symbol.for(String(r));s={get(){return this[o]},set(a){this[o]=a}}}Object.defineProperty(n.prototype,r,{get(){var o;return((o=s.get)==null?void 0:o.call(this))??t},set(o){var l,h,c;const a=((l=s.get)==null?void 0:l.call(this))??t;(h=s.set)==null||h.call(this,o),(c=this.requestUpdate)==null||c.call(this,r,a,e)},configurable:!0,enumerable:!0})}function A(n){return function(r,e){bt(r.constructor,e,n)}}function ee(n){return A({...n,protected:!0})}function gl(n="node",r={}){const e=Zr.get(n);if(!e)throw new Error(`Failed to createNode, tag: ${n}`);return new e().setProperties(r)}class ue{static get currentTime(){return this._currentTime}static get elapsed(){return this._elapsed}static on(r,e={}){const{sort:t=0,once:i=!1}=e;this._queue[t]||(this._queue[t]=[]),this._queue[t].push({cb:r,once:i})}static off(r,e={}){const{sort:t=0}=e,i=this._queue[t];if(!i)return;const s=[];for(let o=i.length,a=0;a<o;a++){const l=i[a];l.cb!==r&&s.push(l)}s.length?this._queue[t]=s:this._queue.splice(t,1)}static start(){"requestAnimationFrame"in globalThis&&(this._currentTime=performance.now(),this._requestId=requestAnimationFrame(r=>this._update(r)))}static stop(){this._requestId&&(cancelAnimationFrame(this._requestId),this._requestId=void 0)}static _update(r){this._elapsed=r-this._currentTime,this._currentTime=r,this._requestId=requestAnimationFrame(e=>this._update(e)),this._performUpdate()}static _performUpdate(){const r=this._queue,e=[];for(let t=r.length,i=t;i>=0;i--){const s=r[i];if(!s)continue;const o=[];for(let a=s.length,l=0;l<a;l++){const h=s[l];try{h.cb()}catch(c){console.warn(c)}h.once||o.push(h)}o.length&&(e[i]=o)}this._queue=e}}u(ue,"_queue",[]),u(ue,"_currentTime",0),u(ue,"_elapsed",0),u(ue,"_requestId"),ue.start();async function Zi(n){return new Promise(r=>{ue.on(()=>{n==null||n(),r()},{sort:1,once:!0})})}let ml=0;class Jr extends dt{constructor(){super(...arguments);u(this,"instanceId",++ml);u(this,"_defaultProperties");u(this,"_updatedProperties",new Map);u(this,"_changedProperties",new Set);u(this,"_updatePending",Promise.resolve());u(this,"_isUpdatePending",!1)}async _enqueueUpdate(){this._isUpdatePending=!0;try{await this._updatePending}catch(e){Promise.reject(e)}await Zi(),this._performUpdate()}_performUpdate(){this._isUpdatePending&&(this._onUpdate(this._updatedProperties),this._updatedProperties=new Map,this._isUpdatePending=!1)}_onUpdate(e){}_onUpdateProperty(e,t,i,s){}isDirty(e){return this._updatedProperties.has(e)}getPropertyDeclarations(){return Kr(this.constructor)}getPropertyDeclaration(e){return this.getPropertyDeclarations().get(e)}getDefaultProperties(){if(!this._defaultProperties){this._defaultProperties={};for(const[e,t]of this.getPropertyDeclarations())!t.protected&&!t.alias&&(this._defaultProperties[e]=t.default)}return this._defaultProperties}getProperty(e){return this[e]}setProperty(e,t){return this[e]=t,this}getProperties(e){const t={};for(const[i,s]of this.getPropertyDeclarations())!s.protected&&!s.alias&&(!e||e.includes(i))&&(t[i]=this.getProperty(i));return t}setProperties(e){if(e)for(const[t]of this.getPropertyDeclarations())t in e&&this.setProperty(t,e[t]);return this}requestUpdate(e,t,i){if(e!==void 0){const s=this[e];if(!Object.is(s,t))this._updatedProperties.set(e,t),this._changedProperties.add(e),i??(i=this.getPropertyDeclaration(e)),this._onUpdateProperty(e,s,t,i),this.emit("updateProperty",e,s,t,i);else return}this._isUpdatePending||(this._updatePending=this._enqueueUpdate())}toJSON(){return this.getProperties(Array.from(this._changedProperties))}destroy(){}}class Ki extends Jr{constructor(){super(...arguments);u(this,"_refCount",0)}}class wt extends Ki{}class Qr extends wt{constructor(e={}){super();u(this,"vertexAttributes");u(this,"indexBuffer");u(this,"instanceCount");u(this,"mode");u(this,"_materialWeakMap",new Qt);this.vertexAttributes=new Map(Object.entries((e==null?void 0:e.vertexAttributes)??{})),this.indexBuffer=e==null?void 0:e.indexBuffer,this.instanceCount=e==null?void 0:e.instanceCount,this.mode=(e==null?void 0:e.mode)??"triangles"}_glVertexArray(e){var t;return{attributes:Object.fromEntries(Array.from(this.vertexAttributes).map(([i,s])=>[i,{buffer:s.buffer._glBuffer(e),size:s.size,type:s.type,normalized:s.normalized,stride:s.stride,offset:s.offset,divisor:s.divisor}])),elementArrayBuffer:(t=this.indexBuffer)==null?void 0:t._glBuffer(e)}}_glVertexArrayObject(e,t){let i=this._materialWeakMap.get(t);return i||(i={material:t.instanceId,geometry:this.instanceId},this._materialWeakMap.set(t,i)),e.getRelated(i,()=>e.vertexArray.create(t._glProgram(e),this._glVertexArray(e)))}draw(e,t,i){var l;e.flush(),t.activate(e,i);const s=this._glVertexArrayObject(e,t);let o=!1,a;this.vertexAttributes.forEach(h=>{(a==null?void 0:a.instanceId)!==h.buffer.instanceId&&(a=h.buffer,a.upload(e)&&(o=!0)),h.upload()&&(o=!0)}),(l=this.indexBuffer)!=null&&l.upload(e)&&(o=!0),o&&s&&e.vertexArray.update(t._glProgram(e),s,this._glVertexArray(e)),e.vertexArray.bind(s??this._glVertexArray(e)),e.draw({mode:this.mode,instanceCount:this.instanceCount}),e.vertexArray.unbind()}}var yl=Object.defineProperty,Tn=(n,r,e,t)=>{for(var i=void 0,s=n.length-1,o;s>=0;s--)(o=n[s])&&(i=o(r,e,i)||i);return i&&yl(r,e,i),i};class er extends wt{constructor(e){super();u(this,"needsUpload",!1);this.setProperties(e)}_glBufferOptions(){return{target:"element_array_buffer",data:this.data,usage:this.dynamic?"dynamic_draw":"static_draw"}}_glBuffer(e){return e.getRelated(this,()=>e.buffer.create(this._glBufferOptions()))}_onUpdateProperty(e,t,i){switch(super._onUpdateProperty(e,t,i),e){case"data":case"dynamic":this.needsUpload=!0;break}}upload(e){const t=this.needsUpload;return t&&(this.needsUpload=!1,e.buffer.update(this._glBuffer(e),this._glBufferOptions())),t}}Tn([ee({default:null})],er.prototype,"data"),Tn([ee({default:!1})],er.prototype,"dynamic");var _l=Object.defineProperty,Sn=(n,r,e,t)=>{for(var i=void 0,s=n.length-1,o;s>=0;s--)(o=n[s])&&(i=o(r,e,i)||i);return i&&_l(r,e,i),i};class pt extends wt{constructor(e){super();u(this,"needsUpload",!1);this.setProperties(e)}_glBufferOptions(){return{target:"array_buffer",data:this.data,usage:this.dynamic?"dynamic_draw":"static_draw"}}_glBuffer(e){return e.getRelated(this,()=>e.buffer.create(this._glBufferOptions()))}_onUpdateProperty(e,t,i){switch(super._onUpdateProperty(e,t,i),e){case"data":case"dynamic":this.needsUpload=!0;break}}upload(e){const t=this.needsUpload;return t&&(this.needsUpload=!1,e.buffer.update(this._glBuffer(e),this._glBufferOptions())),t}}Sn([ee({default:null})],pt.prototype,"data"),Sn([ee({default:!1})],pt.prototype,"dynamic");var vl=Object.defineProperty,Bt=(n,r,e,t)=>{for(var i=void 0,s=n.length-1,o;s>=0;s--)(o=n[s])&&(i=o(r,e,i)||i);return i&&vl(r,e,i),i};class ze extends wt{constructor(e){super();u(this,"stride");u(this,"offset");u(this,"divisor");u(this,"needsUpload",!1);this.setProperties({buffer:new pt,...e})}_onUpdateProperty(e,t,i){switch(super._onUpdateProperty(e,t,i),e){case"buffer":case"size":case"normalized":case"type":case"stride":case"offset":case"divisor":this.needsUpload=!0;break}}upload(){const e=this.needsUpload;return e&&(this.needsUpload=!1),e}}Bt([ee()],ze.prototype,"buffer"),Bt([ee({default:0})],ze.prototype,"size"),Bt([ee({default:!1})],ze.prototype,"normalized"),Bt([ee({default:"float"})],ze.prototype,"type"),Bt([ee()],ze.prototype,"stride"),Bt([ee()],ze.prototype,"offset"),Bt([ee()],ze.prototype,"divisor");class bl extends Qr{constructor(){super({vertexAttributes:{position:new ze({buffer:new pt({data:new Float32Array([0,0,1,0,1,1,0,1]),dynamic:!1}),size:2,normalized:!1,type:"float"})},indexBuffer:new er({data:new Uint16Array([0,1,3,2]),dynamic:!1}),mode:"triangle_strip"})}}const Li=class Li extends wt{constructor(e={}){super();u(this,"vert");u(this,"frag");u(this,"uniforms");this.vert=e.vert??`precision highp float;
2
2
  attribute vec2 position;
3
3
  uniform mat3 projectionMatrix;
4
4
  uniform mat3 modelViewMatrix;
package/dist/index.mjs CHANGED
@@ -248,10 +248,12 @@ class EventEmitter {
248
248
 
249
249
  class RawWeakMap {
250
250
  _map = /* @__PURE__ */ new WeakMap();
251
+ // fix: vue reactive object
251
252
  _toRaw(value) {
252
253
  if (value && typeof value === "object") {
253
- if ("__v_raw" in value) {
254
- value = value.__v_raw;
254
+ const raw = value.__v_raw;
255
+ if (raw) {
256
+ value = this._toRaw(raw);
255
257
  }
256
258
  }
257
259
  return value;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-canvas",
3
3
  "type": "module",
4
- "version": "0.1.6",
4
+ "version": "0.1.7",
5
5
  "packageManager": "pnpm@9.15.1",
6
6
  "description": "A JavaScript WebGL rendering engine.",
7
7
  "author": "wxm",