modern-canvas 0.4.52 → 0.4.54

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.mjs CHANGED
@@ -1,274 +1,10 @@
1
+ import { defineProperty, property, getDeclarations, parseColor, RawWeakMap as RawWeakMap$1, isGradient, normalizeFill, isNone, normalizeBackground, normalizeForeground, normalizeOutline, normalizeShadow, normalizeShape, getDefaultStyle, normalizeText } from 'modern-idoc';
1
2
  import { extend } from 'colord';
2
3
  import namesPlugin from 'colord/plugins/names';
3
- import { parseColor, isGradient, normalizeFill, isNone, normalizeBackground, normalizeForeground, normalizeOutline, normalizeShadow, normalizeShape, getDefaultStyle, normalizeText } from 'modern-idoc';
4
4
  import { Path2D, Path2DSet, svgToDOM, svgToPath2DSet, Matrix3 as Matrix3$1 } from 'modern-path2d';
5
5
  import { Text, textDefaultStyle } from 'modern-text';
6
6
  import { loadYoga, BoxSizing, PositionType, Edge, Overflow, Gutter, Justify, Wrap, FlexDirection, Display, Direction, Align } from 'yoga-layout/load';
7
7
 
8
- const PI = Math.PI;
9
- const PI_2 = PI * 2;
10
- let UID$1 = 0;
11
- function uid(object) {
12
- return object?.__SPECTOR_Object_TAG?.id ?? ++UID$1;
13
- }
14
- function isPow2(v) {
15
- return !(v & v - 1) && !!v;
16
- }
17
-
18
- const FUNCTIONS_RE = /([\w-]+)\((.+?)\)/g;
19
- const ARGS_RE = /[^,]+/g;
20
- const ARG_RE = /([-e.\d]+)(.*)/;
21
- function getDefaultCssPropertyValue(value) {
22
- if (Array.isArray(value)) {
23
- return value.map((func) => {
24
- return {
25
- name: func.name,
26
- args: func.args.map((arg) => {
27
- return {
28
- ...arg,
29
- normalizedIntValue: arg.normalizedDefaultIntValue
30
- };
31
- })
32
- };
33
- });
34
- } else {
35
- return {
36
- ...value,
37
- normalizedIntValue: value.normalizedDefaultIntValue
38
- };
39
- }
40
- }
41
- function parseCssProperty(name, propertyValue, context = {}) {
42
- const functions = parseCssFunctions(propertyValue, context);
43
- return functions.length ? functions : parseArgument(name, propertyValue, context);
44
- }
45
- function parseCssFunctions(propertyValue, context = {}) {
46
- const functions = [];
47
- let match;
48
- while ((match = FUNCTIONS_RE.exec(propertyValue)) !== null) {
49
- const [, name, value] = match;
50
- if (name) {
51
- functions.push({
52
- name,
53
- args: parseArguments(name, value, context)
54
- });
55
- }
56
- }
57
- return functions;
58
- }
59
- function parseArguments(name, value, context = {}) {
60
- const values = [];
61
- let match;
62
- let i = 0;
63
- while ((match = ARGS_RE.exec(value)) !== null) {
64
- values.push(
65
- parseArgument(name, match[0], {
66
- ...context,
67
- index: i++
68
- })
69
- );
70
- }
71
- return values;
72
- }
73
- function parseArgument(name, value, context = {}) {
74
- const { width = 1, height = 1, index = 0 } = context;
75
- const matched = value.match(ARG_RE);
76
- const result = {
77
- unit: matched?.[2] ?? null,
78
- value,
79
- intValue: Number(matched?.[1]),
80
- normalizedIntValue: 0,
81
- normalizedDefaultIntValue: 0
82
- };
83
- switch (name) {
84
- case "scale":
85
- case "scaleX":
86
- case "scaleY":
87
- case "scale3d":
88
- result.normalizedDefaultIntValue = 1;
89
- break;
90
- }
91
- switch (result.unit) {
92
- case "%":
93
- result.normalizedIntValue = result.intValue / 100;
94
- break;
95
- case "rad":
96
- result.normalizedIntValue = result.intValue / PI_2;
97
- break;
98
- case "deg":
99
- result.normalizedIntValue = result.intValue / 360;
100
- break;
101
- case "px":
102
- switch (index) {
103
- case 0:
104
- result.normalizedIntValue = result.intValue / width;
105
- break;
106
- case 1:
107
- result.normalizedIntValue = result.intValue / height;
108
- break;
109
- }
110
- break;
111
- case "turn":
112
- case "em":
113
- // div fontSize
114
- case "rem":
115
- // div fontSize
116
- default:
117
- result.normalizedIntValue = result.intValue;
118
- break;
119
- }
120
- return result;
121
- }
122
-
123
- const SUPPORTS_WEBGL2 = "WebGL2RenderingContext" in globalThis;
124
- const SUPPORTS_IMAGE_BITMAP = "ImageBitmap" in globalThis;
125
- const SUPPORTS_RESIZE_OBSERVER = "ResizeObserver" in globalThis;
126
- const SUPPORTS_POINTER_EVENTS = "PointerEvent" in globalThis;
127
- const SUPPORTS_WHEEL_EVENTS = "WheelEvent" in globalThis;
128
- const SUPPORTS_MOUSE_EVENTS = "MouseEvent" in globalThis;
129
- const SUPPORTS_TOUCH_EVENTS = "ontouchstart" in globalThis;
130
- const SUPPORTS_CLICK_EVENTS = "onclick" in globalThis;
131
- const SUPPORTS_CREATE_IMAGE_BITMAP = "createImageBitmap" in globalThis;
132
- const SUPPORTS_AUDIO_CONTEXT = "AudioContext" in globalThis;
133
- const SUPPORTS_WEBKIT_AUDIO_CONTEXT = "webkitAudioContext" in globalThis;
134
- const SUPPORTS_OFFLINE_AUDIO_CONTEXT = "OfflineAudioContext" in globalThis;
135
- const SUPPORTS_WEBKIT_OFFLINE_AUDIO_CONTEXT = "webkitOfflineAudioContext" in globalThis;
136
- const SUPPORTS_WEB_AUDIO = SUPPORTS_AUDIO_CONTEXT || SUPPORTS_WEBKIT_AUDIO_CONTEXT;
137
- const IN_BROWSER = typeof window !== "undefined";
138
- const DEVICE_PIXEL_RATIO = globalThis.devicePixelRatio || 1;
139
- const isElementNode = (node) => node !== null && typeof node === "object" && node.nodeType === 1;
140
- const isVideoElement = (node) => isElementNode(node) && node.tagName === "VIDEO";
141
- const isImageElement = (node) => isElementNode(node) && node.tagName === "IMG";
142
- function isCanvasElement(node) {
143
- return typeof node === "object" && node !== null && node.nodeType === 1 && node.tagName === "CANVAS";
144
- }
145
- function isWebgl2(gl) {
146
- return SUPPORTS_WEBGL2 && gl instanceof globalThis.WebGL2RenderingContext;
147
- }
148
- function createHTMLCanvas() {
149
- if (IN_BROWSER) {
150
- return globalThis.document.createElement("canvas");
151
- }
152
- return void 0;
153
- }
154
- function determineCrossOrigin(url, loc = globalThis.location) {
155
- if (url.startsWith("data:")) {
156
- return "";
157
- }
158
- loc = loc || globalThis.location;
159
- const parsedUrl = new URL(url, document.baseURI);
160
- if (parsedUrl.hostname !== loc.hostname || parsedUrl.port !== loc.port || parsedUrl.protocol !== loc.protocol) {
161
- return "anonymous";
162
- }
163
- return "";
164
- }
165
- function crossOrigin(element, url, crossorigin) {
166
- if (crossorigin === null && !url.startsWith("data:")) {
167
- element.crossOrigin = determineCrossOrigin(url);
168
- } else if (crossorigin !== false) {
169
- element.crossOrigin = typeof crossorigin === "string" ? crossorigin : "anonymous";
170
- }
171
- }
172
-
173
- class RawWeakMap {
174
- _map = /* @__PURE__ */ new WeakMap();
175
- // fix: vue reactive object
176
- _toRaw(value) {
177
- if (value && typeof value === "object") {
178
- const raw = value.__v_raw;
179
- if (raw) {
180
- value = this._toRaw(raw);
181
- }
182
- }
183
- return value;
184
- }
185
- /**
186
- * Removes the specified element from the WeakMap.
187
- * @returns true if the element was successfully removed, or false if it was not present.
188
- */
189
- delete(key) {
190
- return this._map.delete(this._toRaw(key));
191
- }
192
- /**
193
- * @returns a specified element.
194
- */
195
- get(key) {
196
- return this._map.get(this._toRaw(key));
197
- }
198
- /**
199
- * @returns a boolean indicating whether an element with the specified key exists or not.
200
- */
201
- has(key) {
202
- return this._map.has(this._toRaw(key));
203
- }
204
- /**
205
- * Adds a new element with a specified key and value.
206
- * @param key Must be an object or symbol.
207
- */
208
- set(key, value) {
209
- this._map.set(this._toRaw(key), this._toRaw(value));
210
- return this;
211
- }
212
- }
213
-
214
- const declarationMap = new RawWeakMap();
215
- function getDeclarations(constructor) {
216
- let declarations = declarationMap.get(constructor);
217
- if (!declarations) {
218
- const superConstructor = Object.getPrototypeOf(constructor);
219
- declarations = new Map(superConstructor ? getDeclarations(superConstructor) : void 0);
220
- declarationMap.set(constructor, declarations);
221
- }
222
- return declarations;
223
- }
224
- function defineProperty(constructor, name, declaration = {}) {
225
- getDeclarations(constructor).set(name, declaration);
226
- const {
227
- default: defaultValue,
228
- alias
229
- } = declaration;
230
- let descriptor = Object.getOwnPropertyDescriptor(constructor.prototype, name);
231
- if (!descriptor) {
232
- const key = alias ?? Symbol.for(String(name));
233
- descriptor = {
234
- get() {
235
- return this[key];
236
- },
237
- set(v) {
238
- this[key] = v;
239
- }
240
- };
241
- }
242
- const getDefaultValue = () => typeof defaultValue === "function" ? defaultValue() : defaultValue;
243
- Object.defineProperty(constructor.prototype, name, {
244
- get() {
245
- let value = descriptor.get?.call(this);
246
- if (value === void 0) {
247
- value = getDefaultValue();
248
- if (value !== void 0) {
249
- descriptor.set?.call(this, value);
250
- }
251
- }
252
- return value;
253
- },
254
- set(value) {
255
- let oldValue = descriptor.get?.call(this);
256
- if (oldValue === void 0) {
257
- oldValue = getDefaultValue();
258
- }
259
- descriptor.set?.call(this, value);
260
- this.requestUpdate?.(name, oldValue, declaration);
261
- },
262
- configurable: true,
263
- enumerable: true
264
- });
265
- }
266
- function property(options) {
267
- return function(proto, name) {
268
- defineProperty(proto.constructor, name, options);
269
- };
270
- }
271
-
272
8
  const customNodes = /* @__PURE__ */ new Map();
273
9
  function customNode(tag, defaultProperties) {
274
10
  return function(constructor) {
@@ -468,9 +204,9 @@ class EventEmitter {
468
204
  }
469
205
  }
470
206
 
471
- let UID = 0;
207
+ let UID$1 = 0;
472
208
  class CoreObject extends EventEmitter {
473
- instanceId = ++UID;
209
+ instanceId = ++UID$1;
474
210
  _defaultProperties;
475
211
  _updatedProperties = /* @__PURE__ */ new Map();
476
212
  _changedProperties = /* @__PURE__ */ new Set();
@@ -554,9 +290,8 @@ class CoreObject extends EventEmitter {
554
290
  }
555
291
  return this;
556
292
  }
557
- requestUpdate(key, oldValue, declaration) {
293
+ requestUpdate(key, newValue, oldValue, declaration) {
558
294
  if (key !== void 0) {
559
- const newValue = this[key];
560
295
  if (!Object.is(newValue, oldValue)) {
561
296
  this._updatedProperties.set(key, oldValue);
562
297
  this._changedProperties.add(key);
@@ -600,6 +335,212 @@ class RefCounted extends CoreObject {
600
335
  //
601
336
  }
602
337
 
338
+ const PI = Math.PI;
339
+ const PI_2 = PI * 2;
340
+ let UID = 0;
341
+ function uid(object) {
342
+ return object?.__SPECTOR_Object_TAG?.id ?? ++UID;
343
+ }
344
+ function isPow2(v) {
345
+ return !(v & v - 1) && !!v;
346
+ }
347
+
348
+ const FUNCTIONS_RE = /([\w-]+)\((.+?)\)/g;
349
+ const ARGS_RE = /[^,]+/g;
350
+ const ARG_RE = /([-e.\d]+)(.*)/;
351
+ function getDefaultCssPropertyValue(value) {
352
+ if (Array.isArray(value)) {
353
+ return value.map((func) => {
354
+ return {
355
+ name: func.name,
356
+ args: func.args.map((arg) => {
357
+ return {
358
+ ...arg,
359
+ normalizedIntValue: arg.normalizedDefaultIntValue
360
+ };
361
+ })
362
+ };
363
+ });
364
+ } else {
365
+ return {
366
+ ...value,
367
+ normalizedIntValue: value.normalizedDefaultIntValue
368
+ };
369
+ }
370
+ }
371
+ function parseCssProperty(name, propertyValue, context = {}) {
372
+ const functions = parseCssFunctions(propertyValue, context);
373
+ return functions.length ? functions : parseArgument(name, propertyValue, context);
374
+ }
375
+ function parseCssFunctions(propertyValue, context = {}) {
376
+ const functions = [];
377
+ let match;
378
+ while ((match = FUNCTIONS_RE.exec(propertyValue)) !== null) {
379
+ const [, name, value] = match;
380
+ if (name) {
381
+ functions.push({
382
+ name,
383
+ args: parseArguments(name, value, context)
384
+ });
385
+ }
386
+ }
387
+ return functions;
388
+ }
389
+ function parseArguments(name, value, context = {}) {
390
+ const values = [];
391
+ let match;
392
+ let i = 0;
393
+ while ((match = ARGS_RE.exec(value)) !== null) {
394
+ values.push(
395
+ parseArgument(name, match[0], {
396
+ ...context,
397
+ index: i++
398
+ })
399
+ );
400
+ }
401
+ return values;
402
+ }
403
+ function parseArgument(name, value, context = {}) {
404
+ const { width = 1, height = 1, index = 0 } = context;
405
+ const matched = value.match(ARG_RE);
406
+ const result = {
407
+ unit: matched?.[2] ?? null,
408
+ value,
409
+ intValue: Number(matched?.[1]),
410
+ normalizedIntValue: 0,
411
+ normalizedDefaultIntValue: 0
412
+ };
413
+ switch (name) {
414
+ case "scale":
415
+ case "scaleX":
416
+ case "scaleY":
417
+ case "scale3d":
418
+ result.normalizedDefaultIntValue = 1;
419
+ break;
420
+ }
421
+ switch (result.unit) {
422
+ case "%":
423
+ result.normalizedIntValue = result.intValue / 100;
424
+ break;
425
+ case "rad":
426
+ result.normalizedIntValue = result.intValue / PI_2;
427
+ break;
428
+ case "deg":
429
+ result.normalizedIntValue = result.intValue / 360;
430
+ break;
431
+ case "px":
432
+ switch (index) {
433
+ case 0:
434
+ result.normalizedIntValue = result.intValue / width;
435
+ break;
436
+ case 1:
437
+ result.normalizedIntValue = result.intValue / height;
438
+ break;
439
+ }
440
+ break;
441
+ case "turn":
442
+ case "em":
443
+ // div fontSize
444
+ case "rem":
445
+ // div fontSize
446
+ default:
447
+ result.normalizedIntValue = result.intValue;
448
+ break;
449
+ }
450
+ return result;
451
+ }
452
+
453
+ const SUPPORTS_WEBGL2 = "WebGL2RenderingContext" in globalThis;
454
+ const SUPPORTS_IMAGE_BITMAP = "ImageBitmap" in globalThis;
455
+ const SUPPORTS_RESIZE_OBSERVER = "ResizeObserver" in globalThis;
456
+ const SUPPORTS_POINTER_EVENTS = "PointerEvent" in globalThis;
457
+ const SUPPORTS_WHEEL_EVENTS = "WheelEvent" in globalThis;
458
+ const SUPPORTS_MOUSE_EVENTS = "MouseEvent" in globalThis;
459
+ const SUPPORTS_TOUCH_EVENTS = "ontouchstart" in globalThis;
460
+ const SUPPORTS_CLICK_EVENTS = "onclick" in globalThis;
461
+ const SUPPORTS_CREATE_IMAGE_BITMAP = "createImageBitmap" in globalThis;
462
+ const SUPPORTS_AUDIO_CONTEXT = "AudioContext" in globalThis;
463
+ const SUPPORTS_WEBKIT_AUDIO_CONTEXT = "webkitAudioContext" in globalThis;
464
+ const SUPPORTS_OFFLINE_AUDIO_CONTEXT = "OfflineAudioContext" in globalThis;
465
+ const SUPPORTS_WEBKIT_OFFLINE_AUDIO_CONTEXT = "webkitOfflineAudioContext" in globalThis;
466
+ const SUPPORTS_WEB_AUDIO = SUPPORTS_AUDIO_CONTEXT || SUPPORTS_WEBKIT_AUDIO_CONTEXT;
467
+ const IN_BROWSER = typeof window !== "undefined";
468
+ const DEVICE_PIXEL_RATIO = globalThis.devicePixelRatio || 1;
469
+ const isElementNode = (node) => node !== null && typeof node === "object" && node.nodeType === 1;
470
+ const isVideoElement = (node) => isElementNode(node) && node.tagName === "VIDEO";
471
+ const isImageElement = (node) => isElementNode(node) && node.tagName === "IMG";
472
+ function isCanvasElement(node) {
473
+ return typeof node === "object" && node !== null && node.nodeType === 1 && node.tagName === "CANVAS";
474
+ }
475
+ function isWebgl2(gl) {
476
+ return SUPPORTS_WEBGL2 && gl instanceof globalThis.WebGL2RenderingContext;
477
+ }
478
+ function createHTMLCanvas() {
479
+ if (IN_BROWSER) {
480
+ return globalThis.document.createElement("canvas");
481
+ }
482
+ return void 0;
483
+ }
484
+ function determineCrossOrigin(url, loc = globalThis.location) {
485
+ if (url.startsWith("data:")) {
486
+ return "";
487
+ }
488
+ loc = loc || globalThis.location;
489
+ const parsedUrl = new URL(url, document.baseURI);
490
+ if (parsedUrl.hostname !== loc.hostname || parsedUrl.port !== loc.port || parsedUrl.protocol !== loc.protocol) {
491
+ return "anonymous";
492
+ }
493
+ return "";
494
+ }
495
+ function crossOrigin(element, url, crossorigin) {
496
+ if (crossorigin === null && !url.startsWith("data:")) {
497
+ element.crossOrigin = determineCrossOrigin(url);
498
+ } else if (crossorigin !== false) {
499
+ element.crossOrigin = typeof crossorigin === "string" ? crossorigin : "anonymous";
500
+ }
501
+ }
502
+
503
+ class RawWeakMap {
504
+ _map = /* @__PURE__ */ new WeakMap();
505
+ // fix: vue reactive object
506
+ _toRaw(value) {
507
+ if (value && typeof value === "object") {
508
+ const raw = value.__v_raw;
509
+ if (raw) {
510
+ value = this._toRaw(raw);
511
+ }
512
+ }
513
+ return value;
514
+ }
515
+ /**
516
+ * Removes the specified element from the WeakMap.
517
+ * @returns true if the element was successfully removed, or false if it was not present.
518
+ */
519
+ delete(key) {
520
+ return this._map.delete(this._toRaw(key));
521
+ }
522
+ /**
523
+ * @returns a specified element.
524
+ */
525
+ get(key) {
526
+ return this._map.get(this._toRaw(key));
527
+ }
528
+ /**
529
+ * @returns a boolean indicating whether an element with the specified key exists or not.
530
+ */
531
+ has(key) {
532
+ return this._map.has(this._toRaw(key));
533
+ }
534
+ /**
535
+ * Adds a new element with a specified key and value.
536
+ * @param key Must be an object or symbol.
537
+ */
538
+ set(key, value) {
539
+ this._map.set(this._toRaw(key), this._toRaw(value));
540
+ return this;
541
+ }
542
+ }
543
+
603
544
  class InputEvent {
604
545
  bubbles = true;
605
546
  cancelable = false;
@@ -1496,18 +1437,18 @@ class ColorMatrix extends Matrix {
1496
1437
  const lumG = 0.715;
1497
1438
  const lumB = 0.072;
1498
1439
  return this.multiply([
1499
- lumR + cos * (1 - lumR) + sin * -0.213,
1500
- lumG + cos * -0.715 + sin * -0.715,
1501
- lumB + cos * -0.072 + sin * (1 - lumB),
1440
+ lumR + cos * (1 - lumR) + sin * -lumR,
1441
+ lumG + cos * -lumG + sin * -lumG,
1442
+ lumB + cos * -lumB + sin * (1 - lumB),
1502
1443
  0,
1503
1444
  0,
1504
- lumR + cos * -0.213 + sin * 0.143,
1445
+ lumR + cos * -lumR + sin * 0.143,
1505
1446
  lumG + cos * (1 - lumG) + sin * 0.14,
1506
- lumB + cos * -0.072 + sin * -0.283,
1447
+ lumB + cos * -lumB + sin * -0.283,
1507
1448
  0,
1508
1449
  0,
1509
- lumR + cos * -0.213 + sin * -0.787,
1510
- lumG + cos * -0.715 + sin * lumG,
1450
+ lumR + cos * -lumR + sin * -0.787,
1451
+ lumG + cos * -lumG + sin * lumG,
1511
1452
  lumB + cos * (1 - lumB) + sin * lumB,
1512
1453
  0,
1513
1454
  0,
@@ -3318,7 +3259,7 @@ class WebGLProgramModule extends WebGLModule {
3318
3259
  return {
3319
3260
  attributes: /* @__PURE__ */ new Map(),
3320
3261
  uniforms: /* @__PURE__ */ new Map(),
3321
- boundUniforms: new RawWeakMap()
3262
+ boundUniforms: new RawWeakMap$1()
3322
3263
  };
3323
3264
  });
3324
3265
  }
@@ -7416,7 +7357,8 @@ let CanvasItem = class extends TimelineNode {
7416
7357
  this.requestUpdate();
7417
7358
  }
7418
7359
  }
7419
- _update() {
7360
+ _update(changed) {
7361
+ super._update(changed);
7420
7362
  const parent = this.getParent();
7421
7363
  if (this._parentGlobalVisible !== parent?.globalVisible) {
7422
7364
  this._updateGlobalVisible();
@@ -8962,6 +8904,7 @@ class BaseElement2DFill extends CoreObject {
8962
8904
  case "rotateWithShape":
8963
8905
  case "tile":
8964
8906
  case "opacity":
8907
+ case "enabled":
8965
8908
  this.parent.requestRedraw();
8966
8909
  break;
8967
8910
  case "image":
@@ -8990,7 +8933,7 @@ class BaseElement2DFill extends CoreObject {
8990
8933
  }
8991
8934
  canDraw() {
8992
8935
  return Boolean(
8993
- this._texture || this.color
8936
+ this.enabled && (this._texture || this.color)
8994
8937
  );
8995
8938
  }
8996
8939
  _getDrawOptions() {
@@ -9041,6 +8984,9 @@ class BaseElement2DFill extends CoreObject {
9041
8984
  });
9042
8985
  }
9043
8986
  }
8987
+ __decorateClass$u([
8988
+ property({ default: true })
8989
+ ], BaseElement2DFill.prototype, "enabled");
9044
8990
  __decorateClass$u([
9045
8991
  property()
9046
8992
  ], BaseElement2DFill.prototype, "color");
@@ -9132,13 +9078,14 @@ class BaseElement2DOutline extends BaseElement2DFill {
9132
9078
  switch (key) {
9133
9079
  case "width":
9134
9080
  case "style":
9081
+ case "enabled":
9135
9082
  this.parent.requestRedraw();
9136
9083
  break;
9137
9084
  }
9138
9085
  }
9139
9086
  canDraw() {
9140
9087
  return Boolean(
9141
- this.width || this.color || super.canDraw()
9088
+ this.enabled && (this.width || this.color || super.canDraw())
9142
9089
  );
9143
9090
  }
9144
9091
  draw() {
@@ -9150,6 +9097,9 @@ class BaseElement2DOutline extends BaseElement2DFill {
9150
9097
  ctx.stroke({ disableWrapMode });
9151
9098
  }
9152
9099
  }
9100
+ __decorateClass$r([
9101
+ property({ default: true })
9102
+ ], BaseElement2DOutline.prototype, "enabled");
9153
9103
  __decorateClass$r([
9154
9104
  property({ default: 0 })
9155
9105
  ], BaseElement2DOutline.prototype, "color");
@@ -9206,6 +9156,9 @@ class BaseElement2DShadow extends CoreObject {
9206
9156
  }
9207
9157
  }
9208
9158
  }
9159
+ __decorateClass$q([
9160
+ property({ default: true })
9161
+ ], BaseElement2DShadow.prototype, "enabled");
9209
9162
  __decorateClass$q([
9210
9163
  property({ default: "#000000" })
9211
9164
  ], BaseElement2DShadow.prototype, "color");
@@ -9246,6 +9199,7 @@ class BaseElement2DShape extends CoreObject {
9246
9199
  case "svg":
9247
9200
  case "paths":
9248
9201
  case "viewBox":
9202
+ case "enabled":
9249
9203
  this._updatePath2DSet();
9250
9204
  this.parent.requestRedraw();
9251
9205
  break;
@@ -9276,7 +9230,7 @@ class BaseElement2DShape extends CoreObject {
9276
9230
  });
9277
9231
  }
9278
9232
  draw() {
9279
- if (this._path2DSet.paths.length) {
9233
+ if (this.enabled && this._path2DSet.paths.length) {
9280
9234
  const ctx = this.parent.context;
9281
9235
  const { width, height } = this.parent.size;
9282
9236
  this._path2DSet.paths.forEach((path) => {
@@ -9299,6 +9253,9 @@ class BaseElement2DShape extends CoreObject {
9299
9253
  }
9300
9254
  }
9301
9255
  }
9256
+ __decorateClass$p([
9257
+ property({ default: true })
9258
+ ], BaseElement2DShape.prototype, "enabled");
9302
9259
  __decorateClass$p([
9303
9260
  property()
9304
9261
  ], BaseElement2DShape.prototype, "preset");
@@ -9343,11 +9300,8 @@ class BaseElement2DText extends CoreObject {
9343
9300
  super();
9344
9301
  this.parent = parent;
9345
9302
  }
9346
- effects;
9347
- measureDom;
9348
- fonts;
9303
+ base = new Text();
9349
9304
  texture = new CanvasTexture();
9350
- baseText = new Text();
9351
9305
  measureResult;
9352
9306
  setProperties(properties) {
9353
9307
  return super.setProperties(
@@ -9359,29 +9313,26 @@ class BaseElement2DText extends CoreObject {
9359
9313
  switch (key) {
9360
9314
  case "content":
9361
9315
  case "effects":
9362
- case "measureDom":
9316
+ case "measureDOM":
9363
9317
  case "fonts":
9364
9318
  case "split":
9319
+ case "enabled":
9365
9320
  this.parent.requestRedraw();
9366
9321
  break;
9367
9322
  }
9368
9323
  }
9369
9324
  _updateText() {
9370
- this.baseText.style = {
9325
+ this.base.style = {
9371
9326
  justifyContent: "center",
9372
9327
  alignItems: "center",
9373
9328
  textAlign: "center",
9374
9329
  ...this.parent.style.toJSON()
9375
9330
  };
9376
- this.baseText.content = this.content ?? "";
9377
- this.baseText.effects = this.effects;
9378
- this.baseText.fonts = this.fonts;
9379
- this.baseText.measureDom = this.measureDom;
9380
- this.baseText.requestUpdate();
9331
+ this.base.requestUpdate();
9381
9332
  }
9382
9333
  measure() {
9383
9334
  this._updateText();
9384
- return this.baseText.measure();
9335
+ return this.base.measure();
9385
9336
  }
9386
9337
  updateMeasure() {
9387
9338
  this.measureResult = this.measure();
@@ -9389,11 +9340,11 @@ class BaseElement2DText extends CoreObject {
9389
9340
  }
9390
9341
  canDraw() {
9391
9342
  return Boolean(
9392
- this.content && this.texture?.valid
9343
+ this.enabled && !/^\s*$/.test(this.base.toString()) && this.texture?.valid
9393
9344
  );
9394
9345
  }
9395
9346
  draw() {
9396
- this.baseText.render({
9347
+ this.base.render({
9397
9348
  pixelRatio: this.texture.pixelRatio,
9398
9349
  view: this.texture.source
9399
9350
  });
@@ -9415,16 +9366,19 @@ class BaseElement2DText extends CoreObject {
9415
9366
  }
9416
9367
  }
9417
9368
  __decorateClass$o([
9418
- property({ default: "" })
9369
+ property({ default: true })
9370
+ ], BaseElement2DText.prototype, "enabled");
9371
+ __decorateClass$o([
9372
+ property({ alias: "base.content" })
9419
9373
  ], BaseElement2DText.prototype, "content");
9420
9374
  __decorateClass$o([
9421
- property()
9375
+ property({ alias: "base.effects" })
9422
9376
  ], BaseElement2DText.prototype, "effects");
9423
9377
  __decorateClass$o([
9424
- protectedProperty()
9425
- ], BaseElement2DText.prototype, "measureDom");
9378
+ protectedProperty({ alias: "base.measureDOM" })
9379
+ ], BaseElement2DText.prototype, "measureDOM");
9426
9380
  __decorateClass$o([
9427
- protectedProperty()
9381
+ protectedProperty({ alias: "base.fonts" })
9428
9382
  ], BaseElement2DText.prototype, "fonts");
9429
9383
 
9430
9384
  var __getOwnPropDesc$m = Object.getOwnPropertyDescriptor;
@@ -10663,7 +10617,7 @@ let Text2D = class extends TextureRect2D {
10663
10617
  switch (key) {
10664
10618
  case "content":
10665
10619
  case "effects":
10666
- case "measureDom":
10620
+ case "measureDOM":
10667
10621
  case "fonts":
10668
10622
  case "split":
10669
10623
  this._updateSplit();
@@ -10678,10 +10632,6 @@ let Text2D = class extends TextureRect2D {
10678
10632
  }
10679
10633
  _updateBase() {
10680
10634
  this.base.style = this.style.toJSON();
10681
- this.base.content = this.content ?? "";
10682
- this.base.effects = this.effects;
10683
- this.base.fonts = this.fonts;
10684
- this.base.measureDom = this.measureDom;
10685
10635
  this.emit("updateBase", this.base);
10686
10636
  this.base.requestUpdate();
10687
10637
  }
@@ -10797,16 +10747,16 @@ __decorateClass$g([
10797
10747
  property({ default: false })
10798
10748
  ], Text2D.prototype, "split", 2);
10799
10749
  __decorateClass$g([
10800
- property({ default: "" })
10750
+ property({ alias: "base.content" })
10801
10751
  ], Text2D.prototype, "content", 2);
10802
10752
  __decorateClass$g([
10803
- property()
10753
+ property({ alias: "base.effects" })
10804
10754
  ], Text2D.prototype, "effects", 2);
10805
10755
  __decorateClass$g([
10806
- protectedProperty()
10807
- ], Text2D.prototype, "measureDom", 2);
10756
+ protectedProperty({ alias: "base.measureDOM" })
10757
+ ], Text2D.prototype, "measureDOM", 2);
10808
10758
  __decorateClass$g([
10809
- protectedProperty()
10759
+ protectedProperty({ alias: "base.fonts" })
10810
10760
  ], Text2D.prototype, "fonts", 2);
10811
10761
  Text2D = __decorateClass$g([
10812
10762
  customNode("Text2D")
@@ -11006,7 +10956,7 @@ let Animation = class extends TimelineNode {
11006
10956
  easing;
11007
10957
  _keyframes = [];
11008
10958
  _isFirstUpdatePosition = false;
11009
- _cachedProps = new RawWeakMap();
10959
+ _cachedProps = new RawWeakMap$1();
11010
10960
  _stoped = false;
11011
10961
  constructor(properties, children = []) {
11012
10962
  super();
@@ -13585,9 +13535,26 @@ class Assets {
13585
13535
  return fetch(url);
13586
13536
  }
13587
13537
  _fixSVG(dataURI) {
13588
- const svg = new DOMParser().parseFromString(decodeURIComponent(dataURI.split(",")[1]), "image/svg+xml").documentElement;
13589
- svg.setAttribute("width", "512");
13590
- svg.setAttribute("height", "512");
13538
+ let xml;
13539
+ if (dataURI.includes(";base64,")) {
13540
+ xml = atob(dataURI.split(",")[1]);
13541
+ } else {
13542
+ xml = decodeURIComponent(dataURI.split(",")[1]);
13543
+ }
13544
+ const svg = new DOMParser().parseFromString(xml, "image/svg+xml").documentElement;
13545
+ const width = svg.getAttribute("width");
13546
+ const height = svg.getAttribute("height");
13547
+ const isValidWidth = width && /^[\d.]+$/.test(width);
13548
+ const isValidHeight = height && /^[\d.]+$/.test(height);
13549
+ if (!isValidWidth || !isValidHeight) {
13550
+ const viewBox = svg.getAttribute("viewBox")?.split(" ").map((v) => Number(v));
13551
+ if (!isValidWidth) {
13552
+ svg.setAttribute("width", String(viewBox ? viewBox[2] - viewBox[0] : 512));
13553
+ }
13554
+ if (!isValidHeight) {
13555
+ svg.setAttribute("height", String(viewBox ? viewBox[3] - viewBox[1] : 512));
13556
+ }
13557
+ }
13591
13558
  return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg.outerHTML)}`;
13592
13559
  }
13593
13560
  async fetchImageBitmap(url, options) {
@@ -13604,7 +13571,7 @@ class Assets {
13604
13571
  return createImageBitmap(blob, options);
13605
13572
  });
13606
13573
  } else {
13607
- if (url.startsWith("data:image/svg+xml;charset=utf-8,")) {
13574
+ if (url.startsWith("data:image/svg+xml;")) {
13608
13575
  url = this._fixSVG(url);
13609
13576
  }
13610
13577
  return new Promise((resolve) => {
@@ -13682,7 +13649,7 @@ class CanvasItemEditor extends Control {
13682
13649
  style: {
13683
13650
  visibility: "hidden",
13684
13651
  outlineStyle: "solid",
13685
- outlineColor: 16711935,
13652
+ outlineColor: "#00FF00FF",
13686
13653
  outlineWidth: 2,
13687
13654
  pointerEvents: "none"
13688
13655
  }
@@ -13719,7 +13686,7 @@ class CanvasItemEditor extends Control {
13719
13686
  style: {
13720
13687
  width: 500,
13721
13688
  height: 500,
13722
- backgroundColor: 4294967295,
13689
+ backgroundColor: "#FFFFFFFF",
13723
13690
  overflow: "hidden",
13724
13691
  pointerEvents: "none",
13725
13692
  boxShadow: "2px 2px 2px 1px rgba(0, 0, 0, 0.2)"
@@ -14079,6 +14046,7 @@ async function task(options) {
14079
14046
  engine.resize(width, height, true);
14080
14047
  (Array.isArray(data) ? data : [data]).forEach((v) => {
14081
14048
  if (v instanceof Node) {
14049
+ v.parent = void 0;
14082
14050
  engine.root.appendChild(v);
14083
14051
  } else {
14084
14052
  engine.root.appendChild(Node.parse(v));
@@ -14095,4 +14063,4 @@ async function render(options) {
14095
14063
  });
14096
14064
  }
14097
14065
 
14098
- export { AnimatedTexture, Animation, Assets, Audio, AudioPipeline, AudioProcessor, AudioSpectrum, AudioWaveform, BaseElement2D, BaseElement2DBackground, BaseElement2DFill, BaseElement2DForeground, BaseElement2DOutline, BaseElement2DShadow, BaseElement2DShape, BaseElement2DStyle, BaseElement2DText, CanvasContext, CanvasItem, CanvasItemEditor, CanvasTexture, Color, ColorAdjustEffect, ColorFilterEffect, ColorMatrix, ColorOverlayEffect, ColorRemoveEffect, ColorReplaceEffect, ColorTexture, Control, CoreObject, DEG_TO_RAD, DEVICE_PIXEL_RATIO, DropShadowEffect, Effect, EffectMaterial, Element2D, Element2DStyle, EmbossEffect, Engine, EventEmitter, FlexElement2D, FlexElement2DStyle, FlexLayout, FontLoader, GIFLoader, GaussianBlurEffect, Geometry, GlitchEffect, GodrayEffect, GradientTexture, Graphics2D, HTMLAudio, HTMLAudioContext, HTMLSound, IN_BROWSER, Image2D, ImageTexture, IndexBuffer, Input, InputEvent, JSONLoader, KawaseBlurEffect, KawaseTransition, LeftEraseTransition, Loader, Lottie2D, LottieLoader, MainLoop, MaskEffect, Material, Matrix, Matrix2, Matrix3, Matrix4, MouseInputEvent, Node, Node2D, OutlineEffect, PI, PI_2, PixelateEffect, PixelsTexture, PointerInputEvent, Projection2D, QuadGeometry, QuadUvGeometry, RAD_TO_DEG, Range, RawWeakMap, Rect2, RefCounted, Renderer, Resource, Ruler, SUPPORTS_AUDIO_CONTEXT, SUPPORTS_CLICK_EVENTS, SUPPORTS_CREATE_IMAGE_BITMAP, SUPPORTS_IMAGE_BITMAP, SUPPORTS_MOUSE_EVENTS, SUPPORTS_OFFLINE_AUDIO_CONTEXT, SUPPORTS_POINTER_EVENTS, SUPPORTS_RESIZE_OBSERVER, SUPPORTS_TOUCH_EVENTS, SUPPORTS_WEBGL2, SUPPORTS_WEBKIT_AUDIO_CONTEXT, SUPPORTS_WEBKIT_OFFLINE_AUDIO_CONTEXT, SUPPORTS_WEB_AUDIO, SUPPORTS_WHEEL_EVENTS, Scaler, SceneTree, ScrollBar, Text2D, TextLoader, Texture2D, TextureLoader, TextureRect2D, Ticker, TiltShiftTransition, Timeline, TimelineNode, Transform2D, TransformRect2D, Transition, TwistTransition, UvGeometry, UvMaterial, Vector, Vector2, Vector3, Vector4, VertexAttribute, VertexBuffer, Video2D, VideoLoader, VideoTexture, Viewport, ViewportTexture, WebAudio, WebAudioContext, WebGLBatch2DModule, WebGLBlendMode, WebGLBufferModule, WebGLFramebufferModule, WebGLMaskModule, WebGLModule, WebGLProgramModule, WebGLRenderer, WebGLScissorModule, WebGLState, WebGLStateModule, WebGLStencilModule, WebGLTextureModule, WebGLVertexArrayModule, WebGLViewportModule, WebSound, WheelInputEvent, XScrollBar, YScrollBar, ZoomBlurEffect, assets, clamp, clampFrag, createHTMLCanvas, createNode, crossOrigin, cubicBezier, curves, customNode, customNodes, defaultOptions, defineProperty, determineCrossOrigin, ease, easeIn, easeInOut, easeOut, frag$1 as frag, getDeclarations, getDefaultCssPropertyValue, isCanvasElement, isElementNode, isImageElement, isPow2, isVideoElement, isWebgl2, lerp, linear, log2, mapWebGLBlendModes, nextPow2, nextTick, parseCSSFilter, parseCSSTransform, parseCSSTransformOrigin, parseCssFunctions, parseCssProperty, property, protectedProperty, render, timingFunctions, uid };
14066
+ export { AnimatedTexture, Animation, Assets, Audio, AudioPipeline, AudioProcessor, AudioSpectrum, AudioWaveform, BaseElement2D, BaseElement2DBackground, BaseElement2DFill, BaseElement2DForeground, BaseElement2DOutline, BaseElement2DShadow, BaseElement2DShape, BaseElement2DStyle, BaseElement2DText, CanvasContext, CanvasItem, CanvasItemEditor, CanvasTexture, Color, ColorAdjustEffect, ColorFilterEffect, ColorMatrix, ColorOverlayEffect, ColorRemoveEffect, ColorReplaceEffect, ColorTexture, Control, CoreObject, DEG_TO_RAD, DEVICE_PIXEL_RATIO, DropShadowEffect, Effect, EffectMaterial, Element2D, Element2DStyle, EmbossEffect, Engine, EventEmitter, FlexElement2D, FlexElement2DStyle, FlexLayout, FontLoader, GIFLoader, GaussianBlurEffect, Geometry, GlitchEffect, GodrayEffect, GradientTexture, Graphics2D, HTMLAudio, HTMLAudioContext, HTMLSound, IN_BROWSER, Image2D, ImageTexture, IndexBuffer, Input, InputEvent, JSONLoader, KawaseBlurEffect, KawaseTransition, LeftEraseTransition, Loader, Lottie2D, LottieLoader, MainLoop, MaskEffect, Material, Matrix, Matrix2, Matrix3, Matrix4, MouseInputEvent, Node, Node2D, OutlineEffect, PI, PI_2, PixelateEffect, PixelsTexture, PointerInputEvent, Projection2D, QuadGeometry, QuadUvGeometry, RAD_TO_DEG, Range, RawWeakMap, Rect2, RefCounted, Renderer, Resource, Ruler, SUPPORTS_AUDIO_CONTEXT, SUPPORTS_CLICK_EVENTS, SUPPORTS_CREATE_IMAGE_BITMAP, SUPPORTS_IMAGE_BITMAP, SUPPORTS_MOUSE_EVENTS, SUPPORTS_OFFLINE_AUDIO_CONTEXT, SUPPORTS_POINTER_EVENTS, SUPPORTS_RESIZE_OBSERVER, SUPPORTS_TOUCH_EVENTS, SUPPORTS_WEBGL2, SUPPORTS_WEBKIT_AUDIO_CONTEXT, SUPPORTS_WEBKIT_OFFLINE_AUDIO_CONTEXT, SUPPORTS_WEB_AUDIO, SUPPORTS_WHEEL_EVENTS, Scaler, SceneTree, ScrollBar, Text2D, TextLoader, Texture2D, TextureLoader, TextureRect2D, Ticker, TiltShiftTransition, Timeline, TimelineNode, Transform2D, TransformRect2D, Transition, TwistTransition, UvGeometry, UvMaterial, Vector, Vector2, Vector3, Vector4, VertexAttribute, VertexBuffer, Video2D, VideoLoader, VideoTexture, Viewport, ViewportTexture, WebAudio, WebAudioContext, WebGLBatch2DModule, WebGLBlendMode, WebGLBufferModule, WebGLFramebufferModule, WebGLMaskModule, WebGLModule, WebGLProgramModule, WebGLRenderer, WebGLScissorModule, WebGLState, WebGLStateModule, WebGLStencilModule, WebGLTextureModule, WebGLVertexArrayModule, WebGLViewportModule, WebSound, WheelInputEvent, XScrollBar, YScrollBar, ZoomBlurEffect, assets, clamp, clampFrag, createHTMLCanvas, createNode, crossOrigin, cubicBezier, curves, customNode, customNodes, defaultOptions, determineCrossOrigin, ease, easeIn, easeInOut, easeOut, frag$1 as frag, getDefaultCssPropertyValue, isCanvasElement, isElementNode, isImageElement, isPow2, isVideoElement, isWebgl2, lerp, linear, log2, mapWebGLBlendModes, nextPow2, nextTick, parseCSSFilter, parseCSSTransform, parseCSSTransformOrigin, parseCssFunctions, parseCssProperty, protectedProperty, render, timingFunctions, uid };