modern-canvas 0.4.51 → 0.4.53
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 +483 -544
- package/dist/index.d.cts +34 -38
- package/dist/index.d.mts +34 -38
- package/dist/index.d.ts +34 -38
- package/dist/index.js +45 -44
- package/dist/index.mjs +334 -392
- package/package.json +7 -7
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 * -
|
|
1500
|
-
lumG + cos * -
|
|
1501
|
-
lumB + cos * -
|
|
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 * -
|
|
1445
|
+
lumR + cos * -lumR + sin * 0.143,
|
|
1505
1446
|
lumG + cos * (1 - lumG) + sin * 0.14,
|
|
1506
|
-
lumB + cos * -
|
|
1447
|
+
lumB + cos * -lumB + sin * -0.283,
|
|
1507
1448
|
0,
|
|
1508
1449
|
0,
|
|
1509
|
-
lumR + cos * -
|
|
1510
|
-
lumG + cos * -
|
|
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
|
}
|
|
@@ -7144,13 +7085,15 @@ ColorReplaceEffect = __decorateClass$J([
|
|
|
7144
7085
|
], ColorReplaceEffect);
|
|
7145
7086
|
|
|
7146
7087
|
class CanvasContext extends Path2D {
|
|
7147
|
-
textureTransform;
|
|
7148
7088
|
fillStyle;
|
|
7149
7089
|
strokeStyle;
|
|
7150
7090
|
lineCap;
|
|
7151
7091
|
lineJoin;
|
|
7152
7092
|
lineWidth;
|
|
7153
7093
|
miterLimit;
|
|
7094
|
+
// custom
|
|
7095
|
+
uvTransform;
|
|
7096
|
+
vertTransform;
|
|
7154
7097
|
_defaultStyle = Texture2D.EMPTY;
|
|
7155
7098
|
_draws = [];
|
|
7156
7099
|
_toTexture(source) {
|
|
@@ -7172,7 +7115,8 @@ class CanvasContext extends Path2D {
|
|
|
7172
7115
|
type: "stroke",
|
|
7173
7116
|
path,
|
|
7174
7117
|
texture,
|
|
7175
|
-
|
|
7118
|
+
uvTransform: this.uvTransform,
|
|
7119
|
+
vertTransform: this.vertTransform,
|
|
7176
7120
|
style: {
|
|
7177
7121
|
alignment: 0.5,
|
|
7178
7122
|
cap: this.lineCap ?? "butt",
|
|
@@ -7201,7 +7145,8 @@ class CanvasContext extends Path2D {
|
|
|
7201
7145
|
type: "fill",
|
|
7202
7146
|
path,
|
|
7203
7147
|
texture,
|
|
7204
|
-
|
|
7148
|
+
uvTransform: this.uvTransform,
|
|
7149
|
+
vertTransform: this.vertTransform
|
|
7205
7150
|
});
|
|
7206
7151
|
super.reset();
|
|
7207
7152
|
}
|
|
@@ -7209,7 +7154,8 @@ class CanvasContext extends Path2D {
|
|
|
7209
7154
|
super.copy(source);
|
|
7210
7155
|
this.strokeStyle = source.strokeStyle;
|
|
7211
7156
|
this.fillStyle = source.fillStyle;
|
|
7212
|
-
this.
|
|
7157
|
+
this.uvTransform = source.uvTransform;
|
|
7158
|
+
this.vertTransform = source.vertTransform;
|
|
7213
7159
|
this.lineCap = source.lineCap;
|
|
7214
7160
|
this.lineJoin = source.lineJoin;
|
|
7215
7161
|
this.lineWidth = source.lineWidth;
|
|
@@ -7221,7 +7167,8 @@ class CanvasContext extends Path2D {
|
|
|
7221
7167
|
super.reset();
|
|
7222
7168
|
this.strokeStyle = void 0;
|
|
7223
7169
|
this.fillStyle = void 0;
|
|
7224
|
-
this.
|
|
7170
|
+
this.uvTransform = void 0;
|
|
7171
|
+
this.vertTransform = void 0;
|
|
7225
7172
|
this.lineCap = void 0;
|
|
7226
7173
|
this.lineJoin = void 0;
|
|
7227
7174
|
this.lineWidth = void 0;
|
|
@@ -7229,8 +7176,9 @@ class CanvasContext extends Path2D {
|
|
|
7229
7176
|
this._draws.length = 0;
|
|
7230
7177
|
return this;
|
|
7231
7178
|
}
|
|
7232
|
-
buildUvs(start, vertices, uvs, texture,
|
|
7179
|
+
buildUvs(start, vertices, uvs, texture, uvTransform) {
|
|
7233
7180
|
if (texture) {
|
|
7181
|
+
const _uvTransform = uvTransform ? typeof uvTransform === "function" ? uvTransform : (x, y) => uvTransform.applyToPoint(x, y) : uvTransform;
|
|
7234
7182
|
const w = texture.width;
|
|
7235
7183
|
const h = texture.height;
|
|
7236
7184
|
for (let len = vertices.length, i = start; i < len; i += 2) {
|
|
@@ -7238,8 +7186,8 @@ class CanvasContext extends Path2D {
|
|
|
7238
7186
|
const y = vertices[i + 1];
|
|
7239
7187
|
let uvX;
|
|
7240
7188
|
let uvY;
|
|
7241
|
-
if (
|
|
7242
|
-
[uvX, uvY] =
|
|
7189
|
+
if (_uvTransform) {
|
|
7190
|
+
[uvX, uvY] = _uvTransform(x, y);
|
|
7243
7191
|
} else {
|
|
7244
7192
|
[uvX, uvY] = [x / w, y / h];
|
|
7245
7193
|
}
|
|
@@ -7253,59 +7201,35 @@ class CanvasContext extends Path2D {
|
|
|
7253
7201
|
}
|
|
7254
7202
|
toBatchables() {
|
|
7255
7203
|
const batchables = [];
|
|
7256
|
-
let vertices = [];
|
|
7257
|
-
let indices = [];
|
|
7258
|
-
let uvs = [];
|
|
7259
|
-
let texture;
|
|
7260
|
-
const push = (draw) => {
|
|
7261
|
-
batchables.push({
|
|
7262
|
-
vertices,
|
|
7263
|
-
indices,
|
|
7264
|
-
uvs,
|
|
7265
|
-
texture,
|
|
7266
|
-
type: draw.type,
|
|
7267
|
-
disableWrapMode: draw.disableWrapMode
|
|
7268
|
-
});
|
|
7269
|
-
vertices = [];
|
|
7270
|
-
indices = [];
|
|
7271
|
-
uvs = [];
|
|
7272
|
-
texture = void 0;
|
|
7273
|
-
};
|
|
7274
7204
|
for (let len = this._draws.length, i = 0; i < len; i++) {
|
|
7275
|
-
const
|
|
7276
|
-
const
|
|
7277
|
-
|
|
7278
|
-
|
|
7279
|
-
|
|
7280
|
-
|
|
7281
|
-
if (!oldTexture) {
|
|
7282
|
-
texture = draw.texture;
|
|
7283
|
-
}
|
|
7284
|
-
if (vertices.length && oldTexture !== draw.texture && !oldTexture?.is(draw.texture)) {
|
|
7285
|
-
push(draw);
|
|
7286
|
-
texture = draw.texture;
|
|
7287
|
-
}
|
|
7288
|
-
const start = vertices.length;
|
|
7289
|
-
if (draw.type === "fill") {
|
|
7290
|
-
draw.path.fillTriangulate({
|
|
7205
|
+
const current = this._draws[i];
|
|
7206
|
+
const vertices = [];
|
|
7207
|
+
const indices = [];
|
|
7208
|
+
const uvs = [];
|
|
7209
|
+
if (current.type === "fill") {
|
|
7210
|
+
current.path.fillTriangulate({
|
|
7291
7211
|
vertices,
|
|
7292
7212
|
indices
|
|
7293
7213
|
});
|
|
7294
|
-
this.buildUvs(start, vertices, uvs, draw.texture, draw.textureTransform);
|
|
7295
7214
|
} else {
|
|
7296
|
-
|
|
7215
|
+
current.path.strokeTriangulate({
|
|
7297
7216
|
vertices,
|
|
7298
7217
|
indices,
|
|
7299
|
-
lineStyle:
|
|
7218
|
+
lineStyle: current.style,
|
|
7300
7219
|
flipAlignment: false,
|
|
7301
7220
|
closed: true
|
|
7302
7221
|
});
|
|
7303
|
-
this.buildUvs(start, vertices, uvs, draw.texture, draw.textureTransform);
|
|
7304
7222
|
}
|
|
7305
|
-
|
|
7306
|
-
|
|
7307
|
-
|
|
7308
|
-
|
|
7223
|
+
this.buildUvs(0, vertices, uvs, current.texture, current.uvTransform);
|
|
7224
|
+
batchables.push({
|
|
7225
|
+
vertices,
|
|
7226
|
+
indices,
|
|
7227
|
+
uvs,
|
|
7228
|
+
texture: current.texture,
|
|
7229
|
+
type: current.type,
|
|
7230
|
+
disableWrapMode: current.disableWrapMode,
|
|
7231
|
+
vertTransform: current.vertTransform
|
|
7232
|
+
});
|
|
7309
7233
|
}
|
|
7310
7234
|
return batchables;
|
|
7311
7235
|
}
|
|
@@ -7384,11 +7308,6 @@ let CanvasItem = class extends TimelineNode {
|
|
|
7384
7308
|
requestRelayout() {
|
|
7385
7309
|
this._relayouting = true;
|
|
7386
7310
|
this.requestUpdate();
|
|
7387
|
-
this.forEachChild((node) => {
|
|
7388
|
-
if (node instanceof CanvasItem) {
|
|
7389
|
-
node.requestRelayout();
|
|
7390
|
-
}
|
|
7391
|
-
});
|
|
7392
7311
|
}
|
|
7393
7312
|
requestRepaint() {
|
|
7394
7313
|
this._repainting = true;
|
|
@@ -7438,7 +7357,8 @@ let CanvasItem = class extends TimelineNode {
|
|
|
7438
7357
|
this.requestUpdate();
|
|
7439
7358
|
}
|
|
7440
7359
|
}
|
|
7441
|
-
_update() {
|
|
7360
|
+
_update(changed) {
|
|
7361
|
+
super._update(changed);
|
|
7442
7362
|
const parent = this.getParent();
|
|
7443
7363
|
if (this._parentGlobalVisible !== parent?.globalVisible) {
|
|
7444
7364
|
this._updateGlobalVisible();
|
|
@@ -9018,7 +8938,7 @@ class BaseElement2DFill extends CoreObject {
|
|
|
9018
8938
|
_getDrawOptions() {
|
|
9019
8939
|
let disableWrapMode = false;
|
|
9020
8940
|
const { width, height } = this.parent.size;
|
|
9021
|
-
const
|
|
8941
|
+
const uvTransform = new Transform2D().scale(1 / width, 1 / height);
|
|
9022
8942
|
if (this.cropRect) {
|
|
9023
8943
|
const {
|
|
9024
8944
|
left = 0,
|
|
@@ -9026,7 +8946,7 @@ class BaseElement2DFill extends CoreObject {
|
|
|
9026
8946
|
right = 0,
|
|
9027
8947
|
bottom = 0
|
|
9028
8948
|
} = this.cropRect;
|
|
9029
|
-
|
|
8949
|
+
uvTransform.scale(
|
|
9030
8950
|
Math.abs(1 - (left + right)),
|
|
9031
8951
|
Math.abs(1 - (top + bottom))
|
|
9032
8952
|
).translate(left, top);
|
|
@@ -9041,24 +8961,26 @@ class BaseElement2DFill extends CoreObject {
|
|
|
9041
8961
|
// flip, TODO
|
|
9042
8962
|
// alignment, TODO
|
|
9043
8963
|
} = this.tile;
|
|
9044
|
-
|
|
8964
|
+
uvTransform.translate(-translateX / width, -translateY / height).scale(1 / scaleX, 1 / scaleY);
|
|
9045
8965
|
disableWrapMode = true;
|
|
9046
8966
|
} else if (this.stretchRect) {
|
|
9047
8967
|
const { left = 0, top = 0, right = 0, bottom = 0 } = this.stretchRect;
|
|
9048
|
-
|
|
8968
|
+
uvTransform.scale(
|
|
9049
8969
|
Math.abs(1 - (-left + -right)),
|
|
9050
8970
|
Math.abs(1 - (-top + -bottom))
|
|
9051
8971
|
).translate(-left, -top);
|
|
9052
8972
|
disableWrapMode = true;
|
|
9053
8973
|
}
|
|
9054
|
-
return { disableWrapMode,
|
|
8974
|
+
return { disableWrapMode, uvTransform };
|
|
9055
8975
|
}
|
|
9056
8976
|
draw() {
|
|
9057
8977
|
const ctx = this.parent.context;
|
|
9058
|
-
const {
|
|
9059
|
-
ctx.
|
|
8978
|
+
const { uvTransform, disableWrapMode } = this._getDrawOptions();
|
|
8979
|
+
ctx.uvTransform = uvTransform;
|
|
9060
8980
|
ctx.fillStyle = this._texture ?? this.color;
|
|
9061
|
-
ctx.fill({
|
|
8981
|
+
ctx.fill({
|
|
8982
|
+
disableWrapMode
|
|
8983
|
+
});
|
|
9062
8984
|
}
|
|
9063
8985
|
}
|
|
9064
8986
|
__decorateClass$u([
|
|
@@ -9163,9 +9085,9 @@ class BaseElement2DOutline extends BaseElement2DFill {
|
|
|
9163
9085
|
}
|
|
9164
9086
|
draw() {
|
|
9165
9087
|
const ctx = this.parent.context;
|
|
9166
|
-
const {
|
|
9088
|
+
const { uvTransform, disableWrapMode } = this._getDrawOptions();
|
|
9167
9089
|
ctx.lineWidth = this.width || 1;
|
|
9168
|
-
ctx.
|
|
9090
|
+
ctx.uvTransform = uvTransform;
|
|
9169
9091
|
ctx.strokeStyle = this._texture ?? this.color;
|
|
9170
9092
|
ctx.stroke({ disableWrapMode });
|
|
9171
9093
|
}
|
|
@@ -9363,11 +9285,8 @@ class BaseElement2DText extends CoreObject {
|
|
|
9363
9285
|
super();
|
|
9364
9286
|
this.parent = parent;
|
|
9365
9287
|
}
|
|
9366
|
-
|
|
9367
|
-
measureDom;
|
|
9368
|
-
fonts;
|
|
9288
|
+
base = new Text();
|
|
9369
9289
|
texture = new CanvasTexture();
|
|
9370
|
-
baseText = new Text();
|
|
9371
9290
|
measureResult;
|
|
9372
9291
|
setProperties(properties) {
|
|
9373
9292
|
return super.setProperties(
|
|
@@ -9379,7 +9298,7 @@ class BaseElement2DText extends CoreObject {
|
|
|
9379
9298
|
switch (key) {
|
|
9380
9299
|
case "content":
|
|
9381
9300
|
case "effects":
|
|
9382
|
-
case "
|
|
9301
|
+
case "measureDOM":
|
|
9383
9302
|
case "fonts":
|
|
9384
9303
|
case "split":
|
|
9385
9304
|
this.parent.requestRedraw();
|
|
@@ -9387,21 +9306,17 @@ class BaseElement2DText extends CoreObject {
|
|
|
9387
9306
|
}
|
|
9388
9307
|
}
|
|
9389
9308
|
_updateText() {
|
|
9390
|
-
this.
|
|
9309
|
+
this.base.style = {
|
|
9391
9310
|
justifyContent: "center",
|
|
9392
9311
|
alignItems: "center",
|
|
9393
9312
|
textAlign: "center",
|
|
9394
9313
|
...this.parent.style.toJSON()
|
|
9395
9314
|
};
|
|
9396
|
-
this.
|
|
9397
|
-
this.baseText.effects = this.effects;
|
|
9398
|
-
this.baseText.fonts = this.fonts;
|
|
9399
|
-
this.baseText.measureDom = this.measureDom;
|
|
9400
|
-
this.baseText.requestUpdate();
|
|
9315
|
+
this.base.requestUpdate();
|
|
9401
9316
|
}
|
|
9402
9317
|
measure() {
|
|
9403
9318
|
this._updateText();
|
|
9404
|
-
return this.
|
|
9319
|
+
return this.base.measure();
|
|
9405
9320
|
}
|
|
9406
9321
|
updateMeasure() {
|
|
9407
9322
|
this.measureResult = this.measure();
|
|
@@ -9409,34 +9324,42 @@ class BaseElement2DText extends CoreObject {
|
|
|
9409
9324
|
}
|
|
9410
9325
|
canDraw() {
|
|
9411
9326
|
return Boolean(
|
|
9412
|
-
this.
|
|
9327
|
+
!/^\s*$/.test(this.base.toString()) && this.texture?.valid
|
|
9413
9328
|
);
|
|
9414
9329
|
}
|
|
9415
9330
|
draw() {
|
|
9416
|
-
|
|
9417
|
-
this.baseText.render({
|
|
9331
|
+
this.base.render({
|
|
9418
9332
|
pixelRatio: this.texture.pixelRatio,
|
|
9419
9333
|
view: this.texture.source
|
|
9420
9334
|
});
|
|
9421
9335
|
this.texture.requestUpload();
|
|
9422
9336
|
const textWidth = this.measureResult?.boundingBox.width ?? this.parent.size.width;
|
|
9423
9337
|
const textHeight = this.measureResult?.boundingBox.height ?? this.parent.size.height;
|
|
9338
|
+
const ctx = this.parent.context;
|
|
9424
9339
|
ctx.fillStyle = this.texture;
|
|
9425
|
-
ctx.
|
|
9340
|
+
ctx.uvTransform = new Transform2D().scale(1 / textWidth, 1 / textHeight);
|
|
9341
|
+
ctx.vertTransform = () => {
|
|
9342
|
+
const parent = this.parent;
|
|
9343
|
+
const origin = parent.getTransformOrigin();
|
|
9344
|
+
return new Transform2D().translate(-origin.x, -origin.y).scale(
|
|
9345
|
+
parent.globalScale.x > 0 ? 1 : -1,
|
|
9346
|
+
parent.globalScale.y > 0 ? 1 : -1
|
|
9347
|
+
).translate(origin.x, origin.y);
|
|
9348
|
+
};
|
|
9426
9349
|
ctx.fill();
|
|
9427
9350
|
}
|
|
9428
9351
|
}
|
|
9429
9352
|
__decorateClass$o([
|
|
9430
|
-
property({
|
|
9353
|
+
property({ alias: "base.content" })
|
|
9431
9354
|
], BaseElement2DText.prototype, "content");
|
|
9432
9355
|
__decorateClass$o([
|
|
9433
|
-
property()
|
|
9356
|
+
property({ alias: "base.effects" })
|
|
9434
9357
|
], BaseElement2DText.prototype, "effects");
|
|
9435
9358
|
__decorateClass$o([
|
|
9436
|
-
protectedProperty()
|
|
9437
|
-
], BaseElement2DText.prototype, "
|
|
9359
|
+
protectedProperty({ alias: "base.measureDOM" })
|
|
9360
|
+
], BaseElement2DText.prototype, "measureDOM");
|
|
9438
9361
|
__decorateClass$o([
|
|
9439
|
-
protectedProperty()
|
|
9362
|
+
protectedProperty({ alias: "base.fonts" })
|
|
9440
9363
|
], BaseElement2DText.prototype, "fonts");
|
|
9441
9364
|
|
|
9442
9365
|
var __getOwnPropDesc$m = Object.getOwnPropertyDescriptor;
|
|
@@ -9463,8 +9386,19 @@ let Node2D = class extends CanvasItem {
|
|
|
9463
9386
|
super();
|
|
9464
9387
|
this.setProperties(properties).append(nodes);
|
|
9465
9388
|
}
|
|
9389
|
+
getTransformOrigin() {
|
|
9390
|
+
return new Vector2(0, 0);
|
|
9391
|
+
}
|
|
9392
|
+
getTransform(cb) {
|
|
9393
|
+
const origin = this.getTransformOrigin();
|
|
9394
|
+
const transform = new Transform2D();
|
|
9395
|
+
transform.translate(-origin.x, -origin.y).scale(this.scale.x, this.scale.y).skew(this.skew.x, this.skew.y).rotate(this.rotation);
|
|
9396
|
+
cb?.(transform);
|
|
9397
|
+
transform.translate(this.position.x, this.position.y).translate(origin.x, origin.y);
|
|
9398
|
+
return transform;
|
|
9399
|
+
}
|
|
9466
9400
|
_updateTransform() {
|
|
9467
|
-
this.transform.
|
|
9401
|
+
this.transform.copy(this.getTransform());
|
|
9468
9402
|
}
|
|
9469
9403
|
_updateGlobalTransform() {
|
|
9470
9404
|
const parent = this.getParent();
|
|
@@ -9491,8 +9425,17 @@ let Node2D = class extends CanvasItem {
|
|
|
9491
9425
|
this.globalSkew.y = Math.atan2(b, d) - this.globalRotation;
|
|
9492
9426
|
this.requestRelayout();
|
|
9493
9427
|
}
|
|
9494
|
-
_transformVertices(vertices) {
|
|
9495
|
-
|
|
9428
|
+
_transformVertices(vertices, vertTransform) {
|
|
9429
|
+
let a, c, tx, b, d, ty;
|
|
9430
|
+
if (vertTransform) {
|
|
9431
|
+
const globalTransform = this.globalTransform.clone();
|
|
9432
|
+
globalTransform.multiply(
|
|
9433
|
+
typeof vertTransform === "function" ? vertTransform?.() : vertTransform
|
|
9434
|
+
);
|
|
9435
|
+
[a, c, tx, b, d, ty] = globalTransform.toArray();
|
|
9436
|
+
} else {
|
|
9437
|
+
[a, c, tx, b, d, ty] = this.globalTransform.toArray();
|
|
9438
|
+
}
|
|
9496
9439
|
const newVertices = vertices.slice();
|
|
9497
9440
|
for (let len = vertices.length, i = 0; i < len; i += 2) {
|
|
9498
9441
|
const x = vertices[i];
|
|
@@ -9508,7 +9451,7 @@ let Node2D = class extends CanvasItem {
|
|
|
9508
9451
|
return super._relayout(batchables).map((batchable) => {
|
|
9509
9452
|
return {
|
|
9510
9453
|
...batchable,
|
|
9511
|
-
vertices: this._transformVertices(batchable.vertices)
|
|
9454
|
+
vertices: this._transformVertices(batchable.vertices, batchable.vertTransform)
|
|
9512
9455
|
};
|
|
9513
9456
|
});
|
|
9514
9457
|
}
|
|
@@ -9715,14 +9658,17 @@ let BaseElement2D = class extends Node2D {
|
|
|
9715
9658
|
}
|
|
9716
9659
|
}
|
|
9717
9660
|
}
|
|
9718
|
-
|
|
9661
|
+
getTransformOrigin() {
|
|
9719
9662
|
const { width, height } = this.size;
|
|
9720
9663
|
const [originX, originY] = parseCSSTransformOrigin(this.style.transformOrigin);
|
|
9721
|
-
|
|
9722
|
-
|
|
9723
|
-
|
|
9724
|
-
|
|
9725
|
-
|
|
9664
|
+
return new Vector2(originX * width, originY * height);
|
|
9665
|
+
}
|
|
9666
|
+
getTransform(cb) {
|
|
9667
|
+
const { width, height } = this.size;
|
|
9668
|
+
return super.getTransform((transform) => {
|
|
9669
|
+
parseCSSTransform(this.style.transform ?? "", width, height, transform);
|
|
9670
|
+
cb?.(transform);
|
|
9671
|
+
});
|
|
9726
9672
|
}
|
|
9727
9673
|
_updateGlobalTransform() {
|
|
9728
9674
|
super._updateGlobalTransform();
|
|
@@ -10514,7 +10460,7 @@ let Image2D = class extends Element2D {
|
|
|
10514
10460
|
const sy = 1 / h;
|
|
10515
10461
|
const tx = left * width * sx;
|
|
10516
10462
|
const ty = top * height * sy;
|
|
10517
|
-
this.context.
|
|
10463
|
+
this.context.uvTransform = new Transform2D().scale(sx, sy).translate(tx, ty);
|
|
10518
10464
|
this.shape.draw();
|
|
10519
10465
|
this.context.fill();
|
|
10520
10466
|
}
|
|
@@ -10554,7 +10500,7 @@ class TextureRect2D extends Element2D {
|
|
|
10554
10500
|
if (this.texture?.valid) {
|
|
10555
10501
|
const { width, height } = this.size;
|
|
10556
10502
|
this.context.fillStyle = this.texture;
|
|
10557
|
-
this.context.
|
|
10503
|
+
this.context.uvTransform = new Transform2D().scale(
|
|
10558
10504
|
1 / width,
|
|
10559
10505
|
1 / height
|
|
10560
10506
|
);
|
|
@@ -10652,7 +10598,7 @@ let Text2D = class extends TextureRect2D {
|
|
|
10652
10598
|
switch (key) {
|
|
10653
10599
|
case "content":
|
|
10654
10600
|
case "effects":
|
|
10655
|
-
case "
|
|
10601
|
+
case "measureDOM":
|
|
10656
10602
|
case "fonts":
|
|
10657
10603
|
case "split":
|
|
10658
10604
|
this._updateSplit();
|
|
@@ -10667,10 +10613,6 @@ let Text2D = class extends TextureRect2D {
|
|
|
10667
10613
|
}
|
|
10668
10614
|
_updateBase() {
|
|
10669
10615
|
this.base.style = this.style.toJSON();
|
|
10670
|
-
this.base.content = this.content ?? "";
|
|
10671
|
-
this.base.effects = this.effects;
|
|
10672
|
-
this.base.fonts = this.fonts;
|
|
10673
|
-
this.base.measureDom = this.measureDom;
|
|
10674
10616
|
this.emit("updateBase", this.base);
|
|
10675
10617
|
this.base.requestUpdate();
|
|
10676
10618
|
}
|
|
@@ -10786,16 +10728,16 @@ __decorateClass$g([
|
|
|
10786
10728
|
property({ default: false })
|
|
10787
10729
|
], Text2D.prototype, "split", 2);
|
|
10788
10730
|
__decorateClass$g([
|
|
10789
|
-
property({
|
|
10731
|
+
property({ alias: "base.content" })
|
|
10790
10732
|
], Text2D.prototype, "content", 2);
|
|
10791
10733
|
__decorateClass$g([
|
|
10792
|
-
property()
|
|
10734
|
+
property({ alias: "base.effects" })
|
|
10793
10735
|
], Text2D.prototype, "effects", 2);
|
|
10794
10736
|
__decorateClass$g([
|
|
10795
|
-
protectedProperty()
|
|
10796
|
-
], Text2D.prototype, "
|
|
10737
|
+
protectedProperty({ alias: "base.measureDOM" })
|
|
10738
|
+
], Text2D.prototype, "measureDOM", 2);
|
|
10797
10739
|
__decorateClass$g([
|
|
10798
|
-
protectedProperty()
|
|
10740
|
+
protectedProperty({ alias: "base.fonts" })
|
|
10799
10741
|
], Text2D.prototype, "fonts", 2);
|
|
10800
10742
|
Text2D = __decorateClass$g([
|
|
10801
10743
|
customNode("Text2D")
|
|
@@ -10995,7 +10937,7 @@ let Animation = class extends TimelineNode {
|
|
|
10995
10937
|
easing;
|
|
10996
10938
|
_keyframes = [];
|
|
10997
10939
|
_isFirstUpdatePosition = false;
|
|
10998
|
-
_cachedProps = new RawWeakMap();
|
|
10940
|
+
_cachedProps = new RawWeakMap$1();
|
|
10999
10941
|
_stoped = false;
|
|
11000
10942
|
constructor(properties, children = []) {
|
|
11001
10943
|
super();
|
|
@@ -12464,7 +12406,7 @@ let AudioWaveform = class extends Element2D {
|
|
|
12464
12406
|
const src = this._src;
|
|
12465
12407
|
if (src?.valid) {
|
|
12466
12408
|
this.context.fillStyle = src;
|
|
12467
|
-
this.context.
|
|
12409
|
+
this.context.uvTransform = new Transform2D().scale(
|
|
12468
12410
|
1 / this.style.width,
|
|
12469
12411
|
1 / this.style.height
|
|
12470
12412
|
);
|
|
@@ -12738,7 +12680,7 @@ let Ruler = class extends Control {
|
|
|
12738
12680
|
const texture = this.texture;
|
|
12739
12681
|
if (texture?.valid) {
|
|
12740
12682
|
this.context.fillStyle = texture;
|
|
12741
|
-
this.context.
|
|
12683
|
+
this.context.uvTransform = new Transform2D().scale(
|
|
12742
12684
|
1 / this.size.width,
|
|
12743
12685
|
1 / this.size.height
|
|
12744
12686
|
);
|
|
@@ -13671,7 +13613,7 @@ class CanvasItemEditor extends Control {
|
|
|
13671
13613
|
style: {
|
|
13672
13614
|
visibility: "hidden",
|
|
13673
13615
|
outlineStyle: "solid",
|
|
13674
|
-
outlineColor:
|
|
13616
|
+
outlineColor: "#00FF00FF",
|
|
13675
13617
|
outlineWidth: 2,
|
|
13676
13618
|
pointerEvents: "none"
|
|
13677
13619
|
}
|
|
@@ -13708,7 +13650,7 @@ class CanvasItemEditor extends Control {
|
|
|
13708
13650
|
style: {
|
|
13709
13651
|
width: 500,
|
|
13710
13652
|
height: 500,
|
|
13711
|
-
backgroundColor:
|
|
13653
|
+
backgroundColor: "#FFFFFFFF",
|
|
13712
13654
|
overflow: "hidden",
|
|
13713
13655
|
pointerEvents: "none",
|
|
13714
13656
|
boxShadow: "2px 2px 2px 1px rgba(0, 0, 0, 0.2)"
|
|
@@ -14084,4 +14026,4 @@ async function render(options) {
|
|
|
14084
14026
|
});
|
|
14085
14027
|
}
|
|
14086
14028
|
|
|
14087
|
-
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,
|
|
14029
|
+
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 };
|