modern-canvas 0.6.13 → 0.7.0

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,8 +1,8 @@
1
- import { defineProperty, EventEmitter, getDeclarations, parseColor, property, RawWeakMap as RawWeakMap$1, isGradient, clearUndef, idGenerator, isColorFillObject, normalizeFill, isNone, normalizeBackground, normalizeForeground, normalizeOutline, normalizeShadow, normalizeShape, getDefaultStyle, normalizeText } from 'modern-idoc';
1
+ import { defineProperty, EventEmitter, getDeclarations, parseColor, property, RawWeakMap as RawWeakMap$1, isGradient, isColorFillObject, clearUndef, idGenerator, normalizeFill, isNone, normalizeBackground, normalizeForeground, normalizeOutline, normalizeShadow, normalizeShape, getDefaultStyle, normalizeText } from 'modern-idoc';
2
2
  import { extend } from 'colord';
3
3
  import namesPlugin from 'colord/plugins/names';
4
4
  import { Path2D, Path2DSet, svgToDom, svgToPath2DSet, Matrix3 as Matrix3$1 } from 'modern-path2d';
5
- import { Text, textDefaultStyle } from 'modern-text';
5
+ import { Text } 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
8
  const customNodes = /* @__PURE__ */ new Map();
@@ -1899,6 +1899,14 @@ class Rect2 {
1899
1899
  toArray() {
1900
1900
  return [this.x, this.y, this.width, this.height];
1901
1901
  }
1902
+ toJSON() {
1903
+ return {
1904
+ x: this.x,
1905
+ y: this.y,
1906
+ width: this.width,
1907
+ height: this.height
1908
+ };
1909
+ }
1902
1910
  }
1903
1911
 
1904
1912
  class Transform2D extends Matrix3 {
@@ -2074,7 +2082,7 @@ class Vector3 extends Vector {
2074
2082
  }
2075
2083
 
2076
2084
  var __defProp$Q = Object.defineProperty;
2077
- var __decorateClass$Y = (decorators, target, key, kind) => {
2085
+ var __decorateClass$Z = (decorators, target, key, kind) => {
2078
2086
  var result = void 0 ;
2079
2087
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
2080
2088
  if (decorator = decorators[i])
@@ -2122,10 +2130,10 @@ class MainLoop extends CoreObject {
2122
2130
  this.stop();
2123
2131
  }
2124
2132
  }
2125
- __decorateClass$Y([
2126
- property({ fallback: 24 })
2133
+ __decorateClass$Z([
2134
+ property({ fallback: 60 })
2127
2135
  ], MainLoop.prototype, "fps");
2128
- __decorateClass$Y([
2136
+ __decorateClass$Z([
2129
2137
  property({ fallback: 1 })
2130
2138
  ], MainLoop.prototype, "speed");
2131
2139
 
@@ -3451,6 +3459,33 @@ function getVarTypeSize(type) {
3451
3459
  }
3452
3460
  }
3453
3461
 
3462
+ function applyMatrixToPoint(m, x, y) {
3463
+ const [a, d, g, b, e, h, c, f, i] = m;
3464
+ const xp = a * x + b * y + c;
3465
+ const yp = d * x + e * y + f;
3466
+ const wp = g * x + h * y + i;
3467
+ return { x: xp / wp, y: yp / wp };
3468
+ }
3469
+ function transformRectToAABB(m, rect) {
3470
+ const { x, y, width, height } = rect;
3471
+ const p1 = applyMatrixToPoint(m, x, y);
3472
+ const p2 = applyMatrixToPoint(m, x + width, y);
3473
+ const p3 = applyMatrixToPoint(m, x + width, y + height);
3474
+ const p4 = applyMatrixToPoint(m, x, y + height);
3475
+ const pts = [p1, p2, p3, p4];
3476
+ const xs = pts.map((p) => p.x);
3477
+ const ys = pts.map((p) => p.y);
3478
+ const minX = Math.min(...xs);
3479
+ const maxX = Math.max(...xs);
3480
+ const minY = Math.min(...ys);
3481
+ const maxY = Math.max(...ys);
3482
+ return {
3483
+ x: minX,
3484
+ y: minY,
3485
+ width: maxX - minX,
3486
+ height: maxY - minY
3487
+ };
3488
+ }
3454
3489
  class WebGLScissorModule extends WebGLModule {
3455
3490
  install(renderer) {
3456
3491
  super.install(renderer);
@@ -3476,19 +3511,21 @@ class WebGLScissorModule extends WebGLModule {
3476
3511
  }
3477
3512
  use() {
3478
3513
  const renderer = this._renderer;
3479
- const { pixelRatio, mask, viewport, screen, gl } = renderer;
3480
- const rect = mask.last.mask;
3481
- let y;
3514
+ const { pixelRatio, mask, viewport, screen, gl, program } = renderer;
3515
+ const { worldTransformMatrix } = program.uniforms;
3516
+ const rect = transformRectToAABB(worldTransformMatrix, mask.last.mask);
3517
+ const { x, y, width, height } = rect;
3518
+ let scissorY;
3482
3519
  if (viewport.boundViewport) {
3483
- y = viewport.boundViewport.height - (rect.height + rect.y) * pixelRatio;
3520
+ scissorY = viewport.boundViewport.height - (height + y) * pixelRatio;
3484
3521
  } else {
3485
- y = (screen.height - (rect.height + rect.y)) * pixelRatio;
3522
+ scissorY = (screen.height - (height + y)) * pixelRatio;
3486
3523
  }
3487
3524
  gl.scissor(
3488
- rect.x * pixelRatio,
3489
- y,
3490
- rect.width * pixelRatio,
3491
- rect.height * pixelRatio
3525
+ x * pixelRatio,
3526
+ scissorY,
3527
+ width * pixelRatio,
3528
+ height * pixelRatio
3492
3529
  );
3493
3530
  }
3494
3531
  }
@@ -4165,15 +4202,13 @@ class WebGLRenderer extends Renderer {
4165
4202
  this.view?.removeEventListener("webglcontextrestored", this._onContextRestored, false);
4166
4203
  this.extensions.loseContext?.loseContext();
4167
4204
  }
4168
- toPixels() {
4169
- const width = this.gl.drawingBufferWidth;
4170
- const height = this.gl.drawingBufferHeight;
4205
+ toPixels(x = 0, y = 0, width = this.gl.drawingBufferWidth, height = this.gl.drawingBufferHeight) {
4171
4206
  const length = width * height * 4;
4172
4207
  const row = width * 4;
4173
4208
  const end = (height - 1) * row;
4174
4209
  const flipedPixels = new Uint8Array(length);
4175
4210
  const pixels = new Uint8ClampedArray(length);
4176
- this.gl.readPixels(0, 0, width, height, this.gl.RGBA, this.gl.UNSIGNED_BYTE, flipedPixels);
4211
+ this.gl.readPixels(x, y, width, height, this.gl.RGBA, this.gl.UNSIGNED_BYTE, flipedPixels);
4177
4212
  for (let i = 0; i < length; i += row) {
4178
4213
  pixels.set(flipedPixels.subarray(i, i + row), end - i);
4179
4214
  }
@@ -4205,152 +4240,6 @@ class FontLoader extends Loader {
4205
4240
  }
4206
4241
  }
4207
4242
 
4208
- const defaultFilters = {
4209
- "brightness": 1,
4210
- "contrast": 1,
4211
- "grayscale": 0,
4212
- "hue-rotate": 0,
4213
- "invert": 0,
4214
- "opacity": 1,
4215
- "saturate": 1,
4216
- "sepia": 0
4217
- };
4218
- function parseCSSFilter(filter) {
4219
- const m = new ColorMatrix();
4220
- if (filter === "none") {
4221
- return m;
4222
- }
4223
- const filters = parseCssFunctions(filter).reduce((filter2, { name, args }) => {
4224
- filter2[name] = args[0].normalizedIntValue;
4225
- return filter2;
4226
- }, {});
4227
- Object.keys(defaultFilters).forEach((name) => {
4228
- filters[name] = filters[name] ?? defaultFilters[name];
4229
- });
4230
- for (const name in filters) {
4231
- const value = filters[name];
4232
- switch (name) {
4233
- case "hue-rotate":
4234
- m.hueRotate(value * PI_2);
4235
- break;
4236
- case "saturate":
4237
- m.saturate(value);
4238
- break;
4239
- case "brightness":
4240
- m.brightness(value);
4241
- break;
4242
- case "contrast":
4243
- m.contrast(value);
4244
- break;
4245
- case "invert":
4246
- m.invert(value);
4247
- break;
4248
- case "sepia":
4249
- m.sepia(value);
4250
- break;
4251
- case "opacity":
4252
- m.opacity(value);
4253
- break;
4254
- case "grayscale":
4255
- m.grayscale(value);
4256
- break;
4257
- }
4258
- }
4259
- return m;
4260
- }
4261
-
4262
- function parseCSSTransform(transform, width, height, output = new Transform2D()) {
4263
- transform = !transform || transform === "none" ? "" : transform;
4264
- parseCssFunctions(transform, { width, height }).reverse().forEach(({ name, args }) => {
4265
- const values = args.map((arg) => arg.normalizedIntValue);
4266
- switch (name) {
4267
- case "translate":
4268
- output.translate(values[0] * width, (values[1] ?? values[0]) * height);
4269
- break;
4270
- case "translateX":
4271
- output.translateX(values[0] * width);
4272
- break;
4273
- case "translateY":
4274
- output.translateY(values[0] * height);
4275
- break;
4276
- case "translateZ":
4277
- output.translateZ(values[0]);
4278
- break;
4279
- case "translate3d":
4280
- output.translate3d(
4281
- values[0] * width,
4282
- (values[1] ?? values[0]) * height,
4283
- values[2] ?? values[1] ?? values[0]
4284
- );
4285
- break;
4286
- case "scale":
4287
- output.scale(values[0], values[1] ?? values[0]);
4288
- break;
4289
- case "scaleX":
4290
- output.scaleX(values[0]);
4291
- break;
4292
- case "scaleY":
4293
- output.scaleY(values[0]);
4294
- break;
4295
- case "scale3d":
4296
- output.scale3d(values[0], values[1] ?? values[0], values[2] ?? values[1] ?? values[0]);
4297
- break;
4298
- case "rotate":
4299
- output.rotate(values[0] * PI_2);
4300
- break;
4301
- case "rotateX":
4302
- output.rotateX(values[0] * PI_2);
4303
- break;
4304
- case "rotateY":
4305
- output.rotateY(values[0] * PI_2);
4306
- break;
4307
- case "rotateZ":
4308
- output.rotateZ(values[0] * PI_2);
4309
- break;
4310
- case "rotate3d":
4311
- output.rotate3d(
4312
- values[0] * PI_2,
4313
- (values[1] ?? values[0]) * PI_2,
4314
- (values[2] ?? values[1] ?? values[0]) * PI_2,
4315
- (values[3] ?? values[2] ?? values[1] ?? values[0]) * PI_2
4316
- );
4317
- break;
4318
- case "skew":
4319
- output.skew(values[0], values[0] ?? values[1]);
4320
- break;
4321
- case "skewX":
4322
- output.skewX(values[0]);
4323
- break;
4324
- case "skewY":
4325
- output.skewY(values[0]);
4326
- break;
4327
- case "matrix":
4328
- output.set(values);
4329
- break;
4330
- }
4331
- });
4332
- return output;
4333
- }
4334
-
4335
- function parseCSSTransformOrigin(transformOrigin) {
4336
- const [originX, originY = originX] = transformOrigin.split(" ");
4337
- return [originX, originY].map((val) => {
4338
- val = val.trim();
4339
- switch (val) {
4340
- case "left":
4341
- case "top":
4342
- return 0;
4343
- case "center":
4344
- return 0.5;
4345
- case "right":
4346
- case "bottom":
4347
- return 1;
4348
- default:
4349
- return Number(val);
4350
- }
4351
- });
4352
- }
4353
-
4354
4243
  class Geometry extends Resource {
4355
4244
  vertexAttributes;
4356
4245
  indexBuffer;
@@ -4437,7 +4326,7 @@ class Geometry extends Resource {
4437
4326
  }
4438
4327
 
4439
4328
  var __defProp$P = Object.defineProperty;
4440
- var __decorateClass$X = (decorators, target, key, kind) => {
4329
+ var __decorateClass$Y = (decorators, target, key, kind) => {
4441
4330
  var result = void 0 ;
4442
4331
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
4443
4332
  if (decorator = decorators[i])
@@ -4486,15 +4375,15 @@ class IndexBuffer extends Resource {
4486
4375
  return result;
4487
4376
  }
4488
4377
  }
4489
- __decorateClass$X([
4378
+ __decorateClass$Y([
4490
4379
  property({ protected: true, default: null })
4491
4380
  ], IndexBuffer.prototype, "data");
4492
- __decorateClass$X([
4381
+ __decorateClass$Y([
4493
4382
  property({ protected: true, fallback: false })
4494
4383
  ], IndexBuffer.prototype, "dynamic");
4495
4384
 
4496
4385
  var __defProp$O = Object.defineProperty;
4497
- var __decorateClass$W = (decorators, target, key, kind) => {
4386
+ var __decorateClass$X = (decorators, target, key, kind) => {
4498
4387
  var result = void 0 ;
4499
4388
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
4500
4389
  if (decorator = decorators[i])
@@ -4543,15 +4432,15 @@ class VertexBuffer extends Resource {
4543
4432
  return result;
4544
4433
  }
4545
4434
  }
4546
- __decorateClass$W([
4435
+ __decorateClass$X([
4547
4436
  property({ protected: true, default: null })
4548
4437
  ], VertexBuffer.prototype, "data");
4549
- __decorateClass$W([
4438
+ __decorateClass$X([
4550
4439
  property({ protected: true, fallback: false })
4551
4440
  ], VertexBuffer.prototype, "dynamic");
4552
4441
 
4553
4442
  var __defProp$N = Object.defineProperty;
4554
- var __decorateClass$V = (decorators, target, key, kind) => {
4443
+ var __decorateClass$W = (decorators, target, key, kind) => {
4555
4444
  var result = void 0 ;
4556
4445
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
4557
4446
  if (decorator = decorators[i])
@@ -4590,25 +4479,25 @@ class VertexAttribute extends Resource {
4590
4479
  return result;
4591
4480
  }
4592
4481
  }
4593
- __decorateClass$V([
4482
+ __decorateClass$W([
4594
4483
  property({ protected: true })
4595
4484
  ], VertexAttribute.prototype, "buffer");
4596
- __decorateClass$V([
4485
+ __decorateClass$W([
4597
4486
  property({ fallback: 0 })
4598
4487
  ], VertexAttribute.prototype, "size");
4599
- __decorateClass$V([
4488
+ __decorateClass$W([
4600
4489
  property({ fallback: false })
4601
4490
  ], VertexAttribute.prototype, "normalized");
4602
- __decorateClass$V([
4491
+ __decorateClass$W([
4603
4492
  property({ fallback: "float" })
4604
4493
  ], VertexAttribute.prototype, "type");
4605
- __decorateClass$V([
4494
+ __decorateClass$W([
4606
4495
  property()
4607
4496
  ], VertexAttribute.prototype, "stride");
4608
- __decorateClass$V([
4497
+ __decorateClass$W([
4609
4498
  property()
4610
4499
  ], VertexAttribute.prototype, "offset");
4611
- __decorateClass$V([
4500
+ __decorateClass$W([
4612
4501
  property()
4613
4502
  ], VertexAttribute.prototype, "divisor");
4614
4503
 
@@ -4853,7 +4742,7 @@ class UvGeometry extends Geometry {
4853
4742
  }
4854
4743
 
4855
4744
  var __defProp$M = Object.defineProperty;
4856
- var __decorateClass$U = (decorators, target, key, kind) => {
4745
+ var __decorateClass$V = (decorators, target, key, kind) => {
4857
4746
  var result = void 0 ;
4858
4747
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
4859
4748
  if (decorator = decorators[i])
@@ -4984,22 +4873,22 @@ class Texture2D extends Resource {
4984
4873
  }
4985
4874
  }
4986
4875
  }
4987
- __decorateClass$U([
4876
+ __decorateClass$V([
4988
4877
  property({ protected: true })
4989
4878
  ], Texture2D.prototype, "source");
4990
- __decorateClass$U([
4879
+ __decorateClass$V([
4991
4880
  property({ fallback: 0 })
4992
4881
  ], Texture2D.prototype, "width");
4993
- __decorateClass$U([
4882
+ __decorateClass$V([
4994
4883
  property({ fallback: 0 })
4995
4884
  ], Texture2D.prototype, "height");
4996
- __decorateClass$U([
4885
+ __decorateClass$V([
4997
4886
  property({ fallback: "linear" })
4998
4887
  ], Texture2D.prototype, "filterMode");
4999
- __decorateClass$U([
4888
+ __decorateClass$V([
5000
4889
  property({ fallback: "clamp_to_edge" })
5001
4890
  ], Texture2D.prototype, "wrapMode");
5002
- __decorateClass$U([
4891
+ __decorateClass$V([
5003
4892
  property({ fallback: 1 })
5004
4893
  ], Texture2D.prototype, "pixelRatio");
5005
4894
 
@@ -5030,7 +4919,7 @@ class AnimatedTexture extends Resource {
5030
4919
  }
5031
4920
 
5032
4921
  var __defProp$L = Object.defineProperty;
5033
- var __decorateClass$T = (decorators, target, key, kind) => {
4922
+ var __decorateClass$U = (decorators, target, key, kind) => {
5034
4923
  var result = void 0 ;
5035
4924
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
5036
4925
  if (decorator = decorators[i])
@@ -5054,7 +4943,7 @@ class CanvasTexture extends Texture2D {
5054
4943
  super._updateProperty(key, value, oldValue, declaration);
5055
4944
  }
5056
4945
  }
5057
- __decorateClass$T([
4946
+ __decorateClass$U([
5058
4947
  property({ fallback: 2 })
5059
4948
  ], CanvasTexture.prototype, "pixelRatio");
5060
4949
 
@@ -5275,7 +5164,7 @@ class PixelsTexture extends Texture2D {
5275
5164
  }
5276
5165
 
5277
5166
  var __defProp$K = Object.defineProperty;
5278
- var __decorateClass$S = (decorators, target, key, kind) => {
5167
+ var __decorateClass$T = (decorators, target, key, kind) => {
5279
5168
  var result = void 0 ;
5280
5169
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
5281
5170
  if (decorator = decorators[i])
@@ -5524,10 +5413,10 @@ const _VideoTexture = class _VideoTexture extends Texture2D {
5524
5413
  }
5525
5414
  }
5526
5415
  };
5527
- __decorateClass$S([
5416
+ __decorateClass$T([
5528
5417
  property({ protected: true, fallback: true })
5529
5418
  ], _VideoTexture.prototype, "autoUpdate");
5530
- __decorateClass$S([
5419
+ __decorateClass$T([
5531
5420
  property({ protected: true, fallback: 0 })
5532
5421
  ], _VideoTexture.prototype, "fps");
5533
5422
  let VideoTexture = _VideoTexture;
@@ -5536,35 +5425,206 @@ class ViewportTexture extends PixelsTexture {
5536
5425
  //
5537
5426
  }
5538
5427
 
5539
- class Children extends Array {
5540
- front = [];
5541
- back = [];
5542
- get internal() {
5543
- return [
5544
- ...this.front,
5545
- ...this,
5546
- ...this.back
5547
- ];
5548
- }
5549
- constructor(...items) {
5550
- super();
5551
- this.set(items);
5428
+ class CanvasContext extends Path2D {
5429
+ fillStyle;
5430
+ strokeStyle;
5431
+ lineCap;
5432
+ lineJoin;
5433
+ lineWidth;
5434
+ miterLimit;
5435
+ // custom
5436
+ uvTransform;
5437
+ vertTransform;
5438
+ _defaultStyle = Texture2D.EMPTY;
5439
+ _draws = [];
5440
+ _toTexture(source) {
5441
+ if (source instanceof Texture2D) {
5442
+ return source;
5443
+ } else {
5444
+ return ColorTexture.get(source);
5445
+ }
5552
5446
  }
5553
- set(items) {
5554
- this.front.length = 0;
5555
- this.length = 0;
5556
- this.back.length = 0;
5557
- items.forEach((item) => {
5558
- switch (item.internalMode) {
5559
- case "front":
5560
- this.front.push(item);
5561
- break;
5562
- case "default":
5563
- this.push(item);
5564
- break;
5565
- case "back":
5566
- this.back.push(item);
5567
- break;
5447
+ stroke(options) {
5448
+ if (!this.curves.length) {
5449
+ return;
5450
+ }
5451
+ let strokeStyle = this.strokeStyle;
5452
+ if (!strokeStyle && this.style.stroke) {
5453
+ switch (typeof this.style.stroke) {
5454
+ case "string":
5455
+ strokeStyle = this.style.stroke;
5456
+ break;
5457
+ case "object":
5458
+ if (isColorFillObject(this.style.stroke)) {
5459
+ strokeStyle = this.style.stroke.color;
5460
+ }
5461
+ break;
5462
+ }
5463
+ }
5464
+ this._draws.push({
5465
+ ...options,
5466
+ type: "stroke",
5467
+ path: new Path2D(this),
5468
+ texture: strokeStyle ? this._toTexture(strokeStyle) : this._defaultStyle,
5469
+ uvTransform: this.uvTransform,
5470
+ vertTransform: this.vertTransform,
5471
+ style: {
5472
+ alignment: 0.5,
5473
+ cap: this.lineCap ?? "butt",
5474
+ join: this.lineJoin ?? "miter",
5475
+ width: this.lineWidth ?? 1,
5476
+ miterLimit: this.miterLimit ?? 10
5477
+ }
5478
+ });
5479
+ super.reset();
5480
+ }
5481
+ fillRect(x, y, width, height) {
5482
+ this.rect(x, y, width, height).fill();
5483
+ }
5484
+ strokeRect(x, y, width, height) {
5485
+ this.rect(x, y, width, height).stroke();
5486
+ }
5487
+ fill(options) {
5488
+ if (!this.curves.length) {
5489
+ return;
5490
+ }
5491
+ let fillStyle = this.fillStyle;
5492
+ if (!fillStyle && this.style.fill) {
5493
+ switch (typeof this.style.fill) {
5494
+ case "string":
5495
+ fillStyle = this.style.fill;
5496
+ break;
5497
+ case "object":
5498
+ if (isColorFillObject(this.style.fill)) {
5499
+ fillStyle = this.style.fill.color;
5500
+ }
5501
+ break;
5502
+ }
5503
+ }
5504
+ this._draws.push({
5505
+ ...options,
5506
+ type: "fill",
5507
+ path: new Path2D(this),
5508
+ texture: fillStyle ? this._toTexture(fillStyle) : this._defaultStyle,
5509
+ uvTransform: this.uvTransform,
5510
+ vertTransform: this.vertTransform
5511
+ });
5512
+ super.reset();
5513
+ }
5514
+ copy(source) {
5515
+ super.copy(source);
5516
+ this.strokeStyle = source.strokeStyle;
5517
+ this.fillStyle = source.fillStyle;
5518
+ this.uvTransform = source.uvTransform;
5519
+ this.vertTransform = source.vertTransform;
5520
+ this.lineCap = source.lineCap;
5521
+ this.lineJoin = source.lineJoin;
5522
+ this.lineWidth = source.lineWidth;
5523
+ this.miterLimit = source.miterLimit;
5524
+ this._draws = source._draws.slice();
5525
+ return this;
5526
+ }
5527
+ reset() {
5528
+ super.reset();
5529
+ this.strokeStyle = void 0;
5530
+ this.fillStyle = void 0;
5531
+ this.uvTransform = void 0;
5532
+ this.vertTransform = void 0;
5533
+ this.lineCap = void 0;
5534
+ this.lineJoin = void 0;
5535
+ this.lineWidth = void 0;
5536
+ this.miterLimit = void 0;
5537
+ this._draws.length = 0;
5538
+ return this;
5539
+ }
5540
+ buildUvs(start, vertices, uvs, texture, uvTransform) {
5541
+ if (texture) {
5542
+ const _uvTransform = uvTransform ? typeof uvTransform === "function" ? uvTransform : (x, y) => uvTransform.applyToPoint(x, y) : uvTransform;
5543
+ const w = texture.width;
5544
+ const h = texture.height;
5545
+ for (let len = vertices.length, i = start; i < len; i += 2) {
5546
+ const x = vertices[i];
5547
+ const y = vertices[i + 1];
5548
+ let uvX;
5549
+ let uvY;
5550
+ if (_uvTransform) {
5551
+ [uvX, uvY] = _uvTransform(x, y);
5552
+ } else {
5553
+ [uvX, uvY] = [x / w, y / h];
5554
+ }
5555
+ uvs.push(uvX, uvY);
5556
+ }
5557
+ } else {
5558
+ for (let len = vertices.length, i = start; i < len; i += 2) {
5559
+ uvs.push(0, 0);
5560
+ }
5561
+ }
5562
+ }
5563
+ toBatchables() {
5564
+ const batchables = [];
5565
+ for (let len = this._draws.length, i = 0; i < len; i++) {
5566
+ const current = this._draws[i];
5567
+ const vertices = [];
5568
+ const indices = [];
5569
+ const uvs = [];
5570
+ if (current.type === "fill") {
5571
+ current.path.fillTriangulate({
5572
+ vertices,
5573
+ indices
5574
+ });
5575
+ } else {
5576
+ current.path.strokeTriangulate({
5577
+ vertices,
5578
+ indices,
5579
+ lineStyle: current.style,
5580
+ flipAlignment: false,
5581
+ closed: true
5582
+ });
5583
+ }
5584
+ this.buildUvs(0, vertices, uvs, current.texture, current.uvTransform);
5585
+ batchables.push({
5586
+ vertices,
5587
+ indices,
5588
+ uvs,
5589
+ texture: current.texture,
5590
+ type: current.type,
5591
+ disableWrapMode: current.disableWrapMode,
5592
+ vertTransform: current.vertTransform
5593
+ });
5594
+ }
5595
+ return batchables;
5596
+ }
5597
+ }
5598
+
5599
+ class Children extends Array {
5600
+ front = [];
5601
+ back = [];
5602
+ get internal() {
5603
+ return [
5604
+ ...this.front,
5605
+ ...this,
5606
+ ...this.back
5607
+ ];
5608
+ }
5609
+ constructor(...items) {
5610
+ super();
5611
+ this.set(items);
5612
+ }
5613
+ set(items) {
5614
+ this.front.length = 0;
5615
+ this.length = 0;
5616
+ this.back.length = 0;
5617
+ items.forEach((item) => {
5618
+ switch (item.internalMode) {
5619
+ case "front":
5620
+ this.front.push(item);
5621
+ break;
5622
+ case "default":
5623
+ this.push(item);
5624
+ break;
5625
+ case "back":
5626
+ this.back.push(item);
5627
+ break;
5568
5628
  }
5569
5629
  });
5570
5630
  return this;
@@ -5587,9 +5647,9 @@ class Children extends Array {
5587
5647
  }
5588
5648
 
5589
5649
  var __defProp$J = Object.defineProperty;
5590
- var __getOwnPropDesc$I = Object.getOwnPropertyDescriptor;
5591
- var __decorateClass$R = (decorators, target, key, kind) => {
5592
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$I(target, key) : target;
5650
+ var __getOwnPropDesc$J = Object.getOwnPropertyDescriptor;
5651
+ var __decorateClass$S = (decorators, target, key, kind) => {
5652
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$J(target, key) : target;
5593
5653
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
5594
5654
  if (decorator = decorators[i])
5595
5655
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
@@ -5654,7 +5714,7 @@ let Node = class extends CoreObject {
5654
5714
  return this._tree;
5655
5715
  }
5656
5716
  getViewport() {
5657
- return this._tree?.getCurrentViewport();
5717
+ return this.parent?.getViewport() ?? this.getWindow();
5658
5718
  }
5659
5719
  getWindow() {
5660
5720
  return this._tree?.root;
@@ -6077,38 +6137,38 @@ let Node = class extends CoreObject {
6077
6137
  return node;
6078
6138
  }
6079
6139
  };
6080
- __decorateClass$R([
6140
+ __decorateClass$S([
6081
6141
  property({ fallback: idGenerator() })
6082
6142
  ], Node.prototype, "id", 2);
6083
- __decorateClass$R([
6143
+ __decorateClass$S([
6084
6144
  property({ fallback: idGenerator() })
6085
6145
  ], Node.prototype, "name", 2);
6086
- __decorateClass$R([
6146
+ __decorateClass$S([
6087
6147
  property({ fallback: "inherit" })
6088
6148
  ], Node.prototype, "processMode", 2);
6089
- __decorateClass$R([
6149
+ __decorateClass$S([
6090
6150
  property({ fallback: "default" })
6091
6151
  ], Node.prototype, "processSortMode", 2);
6092
- __decorateClass$R([
6152
+ __decorateClass$S([
6093
6153
  property({ fallback: "inherit" })
6094
6154
  ], Node.prototype, "renderMode", 2);
6095
- __decorateClass$R([
6155
+ __decorateClass$S([
6096
6156
  property({ fallback: "default" })
6097
6157
  ], Node.prototype, "internalMode", 2);
6098
- __decorateClass$R([
6158
+ __decorateClass$S([
6099
6159
  property({ default: () => ({}) })
6100
6160
  ], Node.prototype, "meta", 2);
6101
- __decorateClass$R([
6161
+ __decorateClass$S([
6102
6162
  property({ protected: true })
6103
6163
  ], Node.prototype, "mask", 2);
6104
- Node = __decorateClass$R([
6164
+ Node = __decorateClass$S([
6105
6165
  customNode("Node")
6106
6166
  ], Node);
6107
6167
 
6108
6168
  var __defProp$I = Object.defineProperty;
6109
- var __getOwnPropDesc$H = Object.getOwnPropertyDescriptor;
6110
- var __decorateClass$Q = (decorators, target, key, kind) => {
6111
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$H(target, key) : target;
6169
+ var __getOwnPropDesc$I = Object.getOwnPropertyDescriptor;
6170
+ var __decorateClass$R = (decorators, target, key, kind) => {
6171
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$I(target, key) : target;
6112
6172
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
6113
6173
  if (decorator = decorators[i])
6114
6174
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
@@ -6172,53 +6232,232 @@ let TimelineNode = class extends Node {
6172
6232
  this._updateCurrentTime();
6173
6233
  }
6174
6234
  };
6175
- __decorateClass$Q([
6235
+ __decorateClass$R([
6176
6236
  property({ fallback: 0 })
6177
6237
  ], TimelineNode.prototype, "delay", 2);
6178
- __decorateClass$Q([
6238
+ __decorateClass$R([
6179
6239
  property({ fallback: 0 })
6180
6240
  ], TimelineNode.prototype, "duration", 2);
6181
- __decorateClass$Q([
6241
+ __decorateClass$R([
6182
6242
  property({ fallback: false })
6183
6243
  ], TimelineNode.prototype, "paused", 2);
6184
- __decorateClass$Q([
6244
+ __decorateClass$R([
6185
6245
  property({ protected: true, fallback: false })
6186
6246
  ], TimelineNode.prototype, "insideTimeRange", 2);
6187
- TimelineNode = __decorateClass$Q([
6247
+ TimelineNode = __decorateClass$R([
6188
6248
  customNode("TimelineNode")
6189
6249
  ], TimelineNode);
6190
6250
 
6191
6251
  var __defProp$H = Object.defineProperty;
6192
- var __getOwnPropDesc$G = Object.getOwnPropertyDescriptor;
6193
- var __decorateClass$P = (decorators, target, key, kind) => {
6194
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$G(target, key) : target;
6252
+ var __getOwnPropDesc$H = Object.getOwnPropertyDescriptor;
6253
+ var __decorateClass$Q = (decorators, target, key, kind) => {
6254
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$H(target, key) : target;
6195
6255
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
6196
6256
  if (decorator = decorators[i])
6197
6257
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
6198
6258
  if (kind && result) __defProp$H(target, key, result);
6199
6259
  return result;
6200
6260
  };
6201
- let Viewport = class extends Node {
6202
- constructor(flipY = false) {
6203
- super();
6204
- this.flipY = flipY;
6205
- this._projection.flipY(flipY);
6261
+ let CanvasItem = class extends TimelineNode {
6262
+ _parentGlobalVisible;
6263
+ _globalVisible;
6264
+ get globalVisible() {
6265
+ return this._globalVisible ?? true;
6206
6266
  }
6207
- _projection = new Projection2D();
6208
- _framebufferIndex = 0;
6209
- _framebuffers = [
6210
- { texture: new ViewportTexture(), needsUpload: false },
6211
- { texture: new ViewportTexture(), needsUpload: false }
6212
- ];
6213
- get valid() {
6214
- return Boolean(this.width && this.height);
6267
+ _parentGlobalOpacity;
6268
+ _globalOpacity;
6269
+ get globalOpacity() {
6270
+ return this._globalOpacity ?? 1;
6215
6271
  }
6216
- get framebuffer() {
6217
- return this._framebuffers[this._framebufferIndex];
6272
+ _modulate = new Color(4294967295);
6273
+ // Batch render
6274
+ context = new CanvasContext();
6275
+ _resetContext = true;
6276
+ _redrawing = true;
6277
+ _relayouting = false;
6278
+ _repainting = false;
6279
+ _originalBatchables = [];
6280
+ _layoutedBatchables = [];
6281
+ _batchables = [];
6282
+ constructor(properties, nodes = []) {
6283
+ super();
6284
+ this.setProperties(properties).append(nodes);
6285
+ }
6286
+ _updateProperty(key, value, oldValue, declaration) {
6287
+ super._updateProperty(key, value, oldValue, declaration);
6288
+ switch (key) {
6289
+ case "modulate":
6290
+ this._modulate.value = value;
6291
+ this.requestRepaint();
6292
+ break;
6293
+ case "blendMode":
6294
+ this.requestRepaint();
6295
+ break;
6296
+ case "opacity":
6297
+ this._updateGlobalOpacity();
6298
+ break;
6299
+ case "visible":
6300
+ case "insideTimeRange":
6301
+ this._updateGlobalVisible();
6302
+ break;
6303
+ }
6304
+ }
6305
+ show() {
6306
+ this.visible = true;
6307
+ }
6308
+ hide() {
6309
+ this.visible = false;
6310
+ }
6311
+ isVisibleInTree() {
6312
+ return this.globalOpacity > 0 && this.globalVisible;
6313
+ }
6314
+ canRender() {
6315
+ return super.canRender() && this.isVisibleInTree();
6316
+ }
6317
+ requestRedraw() {
6318
+ this._redrawing = true;
6319
+ }
6320
+ requestRelayout() {
6321
+ this._relayouting = true;
6322
+ }
6323
+ requestRepaint() {
6324
+ this._repainting = true;
6325
+ }
6326
+ _updateGlobalVisible() {
6327
+ this._parentGlobalVisible = this.getParent()?.globalVisible;
6328
+ this._globalVisible = (this._parentGlobalVisible ?? true) && this.visible && this.insideTimeRange;
6329
+ }
6330
+ _updateGlobalOpacity() {
6331
+ this._parentGlobalOpacity = this.getParent()?.opacity;
6332
+ const globalOpacity = clamp(0, this.opacity, 1) * (this._parentGlobalOpacity ?? 1);
6333
+ if (this._globalOpacity !== globalOpacity) {
6334
+ this._globalOpacity = globalOpacity;
6335
+ this.requestRepaint();
6336
+ }
6337
+ }
6338
+ _draw() {
6339
+ this.emit("draw");
6340
+ }
6341
+ _redraw() {
6342
+ this.log(this.name, "drawing");
6343
+ this._draw();
6344
+ return this.context.toBatchables();
6345
+ }
6346
+ _relayout(batchables) {
6347
+ this.log(this.name, "layouting");
6348
+ return batchables;
6349
+ }
6350
+ _repaint(batchables) {
6351
+ this.log(this.name, "painting");
6352
+ return batchables.map((batchable) => {
6353
+ return {
6354
+ ...batchable,
6355
+ modulate: this._modulate.toArgb(this.globalOpacity, true),
6356
+ blendMode: this.blendMode
6357
+ };
6358
+ });
6359
+ }
6360
+ _process(delta) {
6361
+ super._process(delta);
6362
+ const parent = this.getParent();
6363
+ if (this._parentGlobalVisible !== parent?.globalVisible) {
6364
+ this._updateGlobalVisible();
6365
+ }
6366
+ if (this._parentGlobalOpacity !== parent?.globalOpacity) {
6367
+ this._updateGlobalOpacity();
6368
+ }
6369
+ }
6370
+ _updateBatchables() {
6371
+ const redrawing = this._redrawing;
6372
+ let relayouting = this._relayouting;
6373
+ let repainting = this._repainting;
6374
+ let batchables;
6375
+ if (redrawing) {
6376
+ this._originalBatchables = this._redraw();
6377
+ relayouting = true;
6378
+ }
6379
+ if (relayouting) {
6380
+ this._layoutedBatchables = this._relayout(this._originalBatchables);
6381
+ repainting = true;
6382
+ }
6383
+ if (repainting) {
6384
+ batchables = this._repaint(this._layoutedBatchables);
6385
+ }
6386
+ if (redrawing) {
6387
+ if (this._resetContext) {
6388
+ this.context.reset();
6389
+ }
6390
+ }
6391
+ if (batchables) {
6392
+ this._batchables = batchables;
6393
+ this._redrawing = false;
6394
+ this._relayouting = false;
6395
+ this._repainting = false;
6396
+ }
6397
+ }
6398
+ _render(renderer) {
6399
+ this._updateBatchables();
6400
+ this._batchables.forEach((batchable) => {
6401
+ batchable.texture?.upload(renderer);
6402
+ renderer.batch2D.render({
6403
+ ...batchable,
6404
+ texture: batchable.texture?._glTexture(renderer)
6405
+ });
6406
+ });
6407
+ super._render(renderer);
6408
+ }
6409
+ };
6410
+ __decorateClass$Q([
6411
+ property()
6412
+ ], CanvasItem.prototype, "modulate", 2);
6413
+ __decorateClass$Q([
6414
+ property()
6415
+ ], CanvasItem.prototype, "blendMode", 2);
6416
+ __decorateClass$Q([
6417
+ property({ protected: true, fallback: true })
6418
+ ], CanvasItem.prototype, "visible", 2);
6419
+ __decorateClass$Q([
6420
+ property({ protected: true, fallback: 1 })
6421
+ ], CanvasItem.prototype, "opacity", 2);
6422
+ CanvasItem = __decorateClass$Q([
6423
+ customNode("CanvasItem")
6424
+ ], CanvasItem);
6425
+
6426
+ var __defProp$G = Object.defineProperty;
6427
+ var __getOwnPropDesc$G = Object.getOwnPropertyDescriptor;
6428
+ var __decorateClass$P = (decorators, target, key, kind) => {
6429
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$G(target, key) : target;
6430
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
6431
+ if (decorator = decorators[i])
6432
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
6433
+ if (kind && result) __defProp$G(target, key, result);
6434
+ return result;
6435
+ };
6436
+ let Viewport = class extends Node {
6437
+ constructor(flipY = false) {
6438
+ super();
6439
+ this.flipY = flipY;
6440
+ this.projection.flipY(flipY);
6441
+ }
6442
+ projection = new Projection2D();
6443
+ canvasTransform = new Transform2D();
6444
+ _framebufferIndex = 0;
6445
+ _framebuffers = [
6446
+ { texture: new ViewportTexture(), needsUpload: false },
6447
+ { texture: new ViewportTexture(), needsUpload: false }
6448
+ ];
6449
+ get valid() {
6450
+ return Boolean(this.width && this.height);
6451
+ }
6452
+ get framebuffer() {
6453
+ return this._framebuffers[this._framebufferIndex];
6218
6454
  }
6219
6455
  get texture() {
6220
6456
  return this.framebuffer.texture;
6221
6457
  }
6458
+ getViewport() {
6459
+ return this;
6460
+ }
6222
6461
  /** @internal */
6223
6462
  _glFramebufferOptions(renderer) {
6224
6463
  const { width, height } = this;
@@ -6250,13 +6489,13 @@ let Viewport = class extends Node {
6250
6489
  case "x":
6251
6490
  case "y":
6252
6491
  this.requestUpload();
6253
- this._projection.translate(this.x, this.y);
6492
+ this.projection.translate(this.x, this.y);
6254
6493
  this.emit("updateRect");
6255
6494
  break;
6256
6495
  case "width":
6257
6496
  case "height":
6258
6497
  this.requestUpload();
6259
- this._projection.resize(this.width, this.height);
6498
+ this.projection.resize(this.width, this.height);
6260
6499
  this.emit("updateRect");
6261
6500
  break;
6262
6501
  }
@@ -6315,6 +6554,8 @@ let Viewport = class extends Node {
6315
6554
  }
6316
6555
  render(renderer, next) {
6317
6556
  const oldViewport = this._tree?.getCurrentViewport();
6557
+ renderer.program.uniforms.projectionMatrix = this.projection.toArray(true);
6558
+ renderer.program.uniforms.worldTransformMatrix = this.canvasTransform.toArray(true);
6318
6559
  this.activate(renderer);
6319
6560
  renderer.clear();
6320
6561
  super.render(renderer, next);
@@ -6329,9 +6570,6 @@ let Viewport = class extends Node {
6329
6570
  getRect() {
6330
6571
  return new Rect2(this.x, this.y, this.width, this.height);
6331
6572
  }
6332
- toProjectionArray(transpose = false) {
6333
- return this._projection.toArray(transpose);
6334
- }
6335
6573
  };
6336
6574
  __decorateClass$P([
6337
6575
  property({ fallback: 0 })
@@ -6349,14 +6587,14 @@ Viewport = __decorateClass$P([
6349
6587
  customNode("Viewport")
6350
6588
  ], Viewport);
6351
6589
 
6352
- var __defProp$G = Object.defineProperty;
6590
+ var __defProp$F = Object.defineProperty;
6353
6591
  var __getOwnPropDesc$F = Object.getOwnPropertyDescriptor;
6354
6592
  var __decorateClass$O = (decorators, target, key, kind) => {
6355
6593
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$F(target, key) : target;
6356
6594
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
6357
6595
  if (decorator = decorators[i])
6358
6596
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
6359
- if (kind && result) __defProp$G(target, key, result);
6597
+ if (kind && result) __defProp$F(target, key, result);
6360
6598
  return result;
6361
6599
  };
6362
6600
  let Effect = class extends TimelineNode {
@@ -6614,295 +6852,228 @@ Effect = __decorateClass$O([
6614
6852
  customNode("Effect")
6615
6853
  ], Effect);
6616
6854
 
6617
- var __defProp$F = Object.defineProperty;
6855
+ class RenderStack {
6856
+ currentCall;
6857
+ calls = [];
6858
+ createCall(renderable) {
6859
+ return {
6860
+ renderable,
6861
+ parentCall: this.currentCall,
6862
+ fn: renderable.render.bind(renderable),
6863
+ calls: []
6864
+ };
6865
+ }
6866
+ push(renderable) {
6867
+ const call = this.createCall(renderable);
6868
+ (this.currentCall?.calls ?? this.calls).push(call);
6869
+ return call;
6870
+ }
6871
+ render(renderer) {
6872
+ this.calls.forEach(function render(call) {
6873
+ call.fn(renderer, () => {
6874
+ call.calls.forEach(render);
6875
+ });
6876
+ });
6877
+ this.calls = [];
6878
+ }
6879
+ }
6880
+
6881
+ var __defProp$E = Object.defineProperty;
6618
6882
  var __getOwnPropDesc$E = Object.getOwnPropertyDescriptor;
6619
- var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$F(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6620
6883
  var __decorateClass$N = (decorators, target, key, kind) => {
6621
6884
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$E(target, key) : target;
6622
6885
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
6623
6886
  if (decorator = decorators[i])
6624
6887
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
6625
- if (kind && result) __defProp$F(target, key, result);
6888
+ if (kind && result) __defProp$E(target, key, result);
6626
6889
  return result;
6627
6890
  };
6628
- var __publicField$i = (obj, key, value) => __defNormalProp$i(obj, key + "" , value);
6629
- let ColorAdjustEffect = class extends Effect {
6630
- constructor(properties, children = []) {
6891
+ let Timeline = class extends Node {
6892
+ static from(range, loop = false) {
6893
+ const [startTime, endTime] = range ? Array.isArray(range) ? range : [0, range] : [];
6894
+ return new Timeline({
6895
+ startTime,
6896
+ endTime,
6897
+ loop
6898
+ });
6899
+ }
6900
+ constructor(properties) {
6631
6901
  super();
6632
- this.setProperties(properties).append(children);
6902
+ this.setProperties(properties);
6633
6903
  }
6634
- apply(renderer, source) {
6635
- source.redraw(renderer, () => {
6636
- QuadUvGeometry.draw(renderer, ColorAdjustEffect.material, {
6637
- sampler: 0,
6638
- saturation: this.saturation,
6639
- contrast: this.contrast,
6640
- brightness: this.brightness,
6641
- red: this.red,
6642
- green: this.green,
6643
- blue: this.blue,
6644
- alpha: this.alpha,
6645
- gamma: Math.max(this.gamma ?? 1, 1e-4)
6646
- });
6647
- });
6904
+ _updateProperty(key, value, oldValue) {
6905
+ super._updateProperty(key, value, oldValue);
6906
+ switch (key) {
6907
+ case "startTime":
6908
+ this.startTime = Math.min(value, this.endTime);
6909
+ break;
6910
+ case "endTime":
6911
+ this.endTime = value || Number.MAX_SAFE_INTEGER;
6912
+ break;
6913
+ }
6648
6914
  }
6649
- };
6650
- __publicField$i(ColorAdjustEffect, "material", new Material({
6651
- vert: `precision mediump float;
6652
- attribute vec2 position;
6653
- attribute vec2 uv;
6654
- varying vec2 vUv;
6655
- void main() {
6656
- gl_Position = vec4(position, 0.0, 1.0);
6657
- vUv = uv;
6658
- }`,
6659
- frag: `varying vec2 vUv;
6660
- uniform sampler2D sampler;
6661
- uniform float gamma;
6662
- uniform float contrast;
6663
- uniform float saturation;
6664
- uniform float brightness;
6665
- uniform float red;
6666
- uniform float green;
6667
- uniform float blue;
6668
- uniform float alpha;
6669
-
6670
- void main(void) {
6671
- vec4 c = texture2D(sampler, vUv);
6672
- if (c.a > 0.0) {
6673
- c.rgb /= c.a;
6674
- vec3 rgb = pow(c.rgb, vec3(1. / gamma));
6675
- rgb = mix(vec3(.5), mix(vec3(dot(vec3(.2125, .7154, .0721), rgb)), rgb, saturation), contrast);
6676
- rgb.r *= red;
6677
- rgb.g *= green;
6678
- rgb.b *= blue;
6679
- c.rgb = rgb * brightness;
6680
- c.rgb *= c.a;
6915
+ addTime(delta) {
6916
+ const start = this.startTime;
6917
+ const end = this.endTime;
6918
+ let current = this.currentTime;
6919
+ current = current + delta;
6920
+ if (this.loop && current > end) {
6921
+ current = start + current % end;
6922
+ }
6923
+ current = clamp(start, current, end);
6924
+ this.currentTime = current;
6925
+ this.emit("updateCurrentTime", current, delta);
6926
+ return this;
6681
6927
  }
6682
- gl_FragColor = c * alpha;
6683
- }`
6684
- }));
6685
- __decorateClass$N([
6686
- property()
6687
- ], ColorAdjustEffect.prototype, "saturation", 2);
6688
- __decorateClass$N([
6689
- property()
6690
- ], ColorAdjustEffect.prototype, "contrast", 2);
6691
- __decorateClass$N([
6692
- property()
6693
- ], ColorAdjustEffect.prototype, "brightness", 2);
6694
- __decorateClass$N([
6695
- property()
6696
- ], ColorAdjustEffect.prototype, "red", 2);
6928
+ _process(delta) {
6929
+ super._process(delta);
6930
+ this.addTime(delta);
6931
+ }
6932
+ };
6697
6933
  __decorateClass$N([
6698
- property()
6699
- ], ColorAdjustEffect.prototype, "green", 2);
6934
+ property({ fallback: 0 })
6935
+ ], Timeline.prototype, "startTime", 2);
6700
6936
  __decorateClass$N([
6701
- property()
6702
- ], ColorAdjustEffect.prototype, "blue", 2);
6937
+ property({ fallback: 0 })
6938
+ ], Timeline.prototype, "currentTime", 2);
6703
6939
  __decorateClass$N([
6704
- property()
6705
- ], ColorAdjustEffect.prototype, "alpha", 2);
6940
+ property({ fallback: Number.MAX_SAFE_INTEGER })
6941
+ ], Timeline.prototype, "endTime", 2);
6706
6942
  __decorateClass$N([
6707
- property()
6708
- ], ColorAdjustEffect.prototype, "gamma", 2);
6709
- ColorAdjustEffect = __decorateClass$N([
6710
- customNode("ColorAdjustEffect")
6711
- ], ColorAdjustEffect);
6943
+ property({ fallback: false })
6944
+ ], Timeline.prototype, "loop", 2);
6945
+ Timeline = __decorateClass$N([
6946
+ customNode("Timeline")
6947
+ ], Timeline);
6712
6948
 
6713
- var __defProp$E = Object.defineProperty;
6714
6949
  var __getOwnPropDesc$D = Object.getOwnPropertyDescriptor;
6715
- var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$E(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6716
6950
  var __decorateClass$M = (decorators, target, key, kind) => {
6717
6951
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$D(target, key) : target;
6718
6952
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
6719
6953
  if (decorator = decorators[i])
6720
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
6721
- if (kind && result) __defProp$E(target, key, result);
6954
+ result = (decorator(result)) || result;
6722
6955
  return result;
6723
6956
  };
6724
- var __publicField$h = (obj, key, value) => __defNormalProp$h(obj, key + "" , value);
6725
- let ColorFilterEffect = class extends Effect {
6726
- _colorMatrix = new ColorMatrix();
6727
- constructor(properties, children = []) {
6957
+ let Window = class extends Viewport {
6958
+ //
6959
+ };
6960
+ Window = __decorateClass$M([
6961
+ customNode("Window")
6962
+ ], Window);
6963
+
6964
+ var __defProp$D = Object.defineProperty;
6965
+ var __decorateClass$L = (decorators, target, key, kind) => {
6966
+ var result = void 0 ;
6967
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
6968
+ if (decorator = decorators[i])
6969
+ result = (decorator(target, key, result) ) || result;
6970
+ if (result) __defProp$D(target, key, result);
6971
+ return result;
6972
+ };
6973
+ class SceneTree extends MainLoop {
6974
+ input = new Input();
6975
+ renderStack = new RenderStack();
6976
+ root = new Window(true).setTree(this);
6977
+ timeline;
6978
+ _backgroundColor = new Color();
6979
+ _currentViewport;
6980
+ getCurrentViewport() {
6981
+ return this._currentViewport;
6982
+ }
6983
+ setCurrentViewport(viewport) {
6984
+ this._currentViewport = viewport;
6985
+ }
6986
+ constructor(timeline = new Timeline()) {
6728
6987
  super();
6729
- this.setProperties(properties).append(children);
6988
+ this.timeline = timeline.setTree(this);
6730
6989
  }
6731
- apply(renderer, source) {
6732
- if (!this.filter)
6733
- return;
6734
- const funs = parseCssFunctions(this.filter);
6735
- const matrix = this._colorMatrix.identity();
6736
- funs.forEach(({ name, args }) => {
6737
- const values = args.map((arg) => arg.normalizedIntValue);
6738
- switch (name) {
6739
- case "hue-rotate":
6740
- case "hueRotate":
6741
- matrix.hueRotate(values[0] * PI_2);
6742
- break;
6743
- case "saturate":
6744
- matrix.saturate(values[0]);
6745
- break;
6746
- case "brightness":
6747
- matrix.brightness(values[0]);
6748
- break;
6749
- case "contrast":
6750
- matrix.contrast(values[0]);
6751
- break;
6752
- case "invert":
6753
- matrix.invert(values[0]);
6754
- break;
6755
- case "sepia":
6756
- matrix.sepia(values[0]);
6757
- break;
6758
- case "opacity":
6759
- matrix.opacity(values[0]);
6760
- break;
6761
- case "grayscale":
6762
- matrix.grayscale(values[0]);
6763
- break;
6764
- }
6765
- });
6766
- source.redraw(renderer, () => {
6767
- QuadUvGeometry.draw(renderer, ColorFilterEffect.material, {
6768
- sampler: 0,
6769
- m: matrix.toArray()
6770
- });
6990
+ _updateProperty(key, value, oldValue, declaration) {
6991
+ super._updateProperty(key, value, oldValue, declaration);
6992
+ switch (key) {
6993
+ case "backgroundColor":
6994
+ this._backgroundColor.value = value;
6995
+ break;
6996
+ }
6997
+ }
6998
+ log(...args) {
6999
+ if (this.debug) {
7000
+ console.log(`[modern-canvas][${performance.now().toFixed(4)}ms]`, ...args);
7001
+ }
7002
+ }
7003
+ _process(delta = 0) {
7004
+ this.timeline.emit("process", delta);
7005
+ this.emit("processing");
7006
+ this.root.emit("process", delta);
7007
+ this.emit("processed");
7008
+ }
7009
+ _render(renderer) {
7010
+ this.emit("rendering");
7011
+ this.renderStack.render(renderer);
7012
+ this._renderScreen(renderer);
7013
+ this.emit("rendered");
7014
+ }
7015
+ _renderScreen(renderer) {
7016
+ renderer.state.reset();
7017
+ renderer.framebuffer.bind(null);
7018
+ renderer.viewport.bind({
7019
+ x: 0,
7020
+ y: 0,
7021
+ width: this.root.width * renderer.pixelRatio,
7022
+ height: this.root.height * renderer.pixelRatio
6771
7023
  });
7024
+ if (this.backgroundColor) {
7025
+ renderer.gl.clearColor(...this._backgroundColor.toArray());
7026
+ }
7027
+ renderer.clear();
7028
+ if (this.backgroundColor) {
7029
+ renderer.gl.clearColor(0, 0, 0, 0);
7030
+ }
7031
+ const texture = this.root.texture;
7032
+ texture.activate(renderer, 0);
7033
+ QuadUvGeometry.draw(renderer);
7034
+ renderer.texture.unbind(texture);
6772
7035
  }
6773
- };
6774
- __publicField$h(ColorFilterEffect, "material", new Material({
6775
- vert: `precision mediump float;
6776
- attribute vec2 position;
6777
- attribute vec2 uv;
6778
- varying vec2 vUv;
6779
- void main() {
6780
- gl_Position = vec4(position, 0.0, 1.0);
6781
- vUv = uv;
6782
- }`,
6783
- frag: `precision highp float;
6784
- varying vec2 vUv;
6785
- uniform sampler2D sampler;
6786
- uniform float m[20];
6787
-
6788
- void main(void) {
6789
- vec4 c = texture2D(sampler, vUv);
6790
- if (c.a > 0.0) {
6791
- c.rgb /= c.a;
7036
+ free() {
7037
+ super.free();
7038
+ this.root.children.internal.forEach((node) => this.root.removeChild(node));
7039
+ this.input.removeEventListeners();
6792
7040
  }
6793
- gl_FragColor = vec4(
6794
- m[0] * c.r + m[1] * c.g + m[2] * c.b + m[3] * c.a + m[4] / 255.0,
6795
- m[5] * c.r + m[6] * c.g + m[7] * c.b + m[8] * c.a + m[9] / 255.0,
6796
- m[10] * c.r + m[11] * c.g + m[12] * c.b + m[13] * c.a + m[14] / 255.0,
6797
- m[15] * c.r + m[16] * c.g + m[17] * c.b + m[18] * c.a + m[19] / 255.0
6798
- );
6799
- }`
6800
- }));
6801
- __decorateClass$M([
7041
+ }
7042
+ __decorateClass$L([
7043
+ property({ fallback: false })
7044
+ ], SceneTree.prototype, "processPaused");
7045
+ __decorateClass$L([
6802
7046
  property()
6803
- ], ColorFilterEffect.prototype, "filter", 2);
6804
- ColorFilterEffect = __decorateClass$M([
6805
- customNode("ColorFilterEffect")
6806
- ], ColorFilterEffect);
7047
+ ], SceneTree.prototype, "backgroundColor");
7048
+ __decorateClass$L([
7049
+ property({ protected: true, fallback: false })
7050
+ ], SceneTree.prototype, "debug");
6807
7051
 
6808
- var __defProp$D = Object.defineProperty;
6809
7052
  var __getOwnPropDesc$C = Object.getOwnPropertyDescriptor;
6810
- var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$D(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6811
- var __decorateClass$L = (decorators, target, key, kind) => {
7053
+ var __decorateClass$K = (decorators, target, key, kind) => {
6812
7054
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$C(target, key) : target;
6813
7055
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
6814
7056
  if (decorator = decorators[i])
6815
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
6816
- if (kind && result) __defProp$D(target, key, result);
7057
+ result = (decorator(result)) || result;
6817
7058
  return result;
6818
7059
  };
6819
- var __publicField$g = (obj, key, value) => __defNormalProp$g(obj, key + "" , value);
6820
- const MAX_COLORS$1 = 50;
6821
- let ColorOverlayEffect = class extends Effect {
6822
- _color = new Color();
7060
+ let Transition = class extends Effect {
6823
7061
  constructor(properties, children = []) {
6824
7062
  super();
6825
7063
  this.setProperties(properties).append(children);
6826
7064
  }
6827
- apply(renderer, source) {
6828
- source.redraw(renderer, () => {
6829
- const colors = this.colors.map((val) => {
6830
- this._color.value = val;
6831
- const rgba = this._color.toArray();
6832
- rgba[3] = this.alpha;
6833
- return rgba;
6834
- });
6835
- while (colors.length < MAX_COLORS$1) {
6836
- colors.push([0, 0, 0, 0]);
6837
- }
6838
- QuadUvGeometry.draw(renderer, ColorOverlayEffect.material, {
6839
- sampler: 0,
6840
- colors: colors.slice(0, MAX_COLORS$1).flatMap((item) => item)
6841
- });
6842
- });
6843
- }
6844
7065
  };
6845
- __publicField$g(ColorOverlayEffect, "material", new Material({
6846
- vert: `precision mediump float;
6847
- attribute vec2 position;
6848
- attribute vec2 uv;
6849
- varying vec2 vUv;
6850
- void main() {
6851
- gl_Position = vec4(position, 0.0, 1.0);
6852
- vUv = uv;
6853
- }`,
6854
- frag: `precision mediump float;
6855
- uniform sampler2D sampler;
6856
- uniform vec4 colors[${MAX_COLORS$1}];
6857
- varying vec2 vUv;
6858
-
6859
- float calcWidth() {
6860
- return distance(vec2(0, 0), vec2(1, 0));
6861
- }
6862
-
6863
- int calcCount() {
6864
- int count = 0;
6865
- for (int i = 0; i < ${MAX_COLORS$1}; i++) {
6866
- if (colors[i] != vec4(0,0,0,0)){
6867
- count++;
6868
- }
6869
- }
6870
- return count;
6871
- }
6872
-
6873
- vec4 calcColor(float x) {
6874
- float perUnit = calcWidth() / float(calcCount());
6875
- int index = int(x / perUnit);
6876
-
6877
- for(int i=0; i<${MAX_COLORS$1}; i++){
6878
- if(i==index){
6879
- return colors[i];
6880
- }
6881
- }
6882
-
6883
- return vec4(0, 0, 0, 0);
6884
- }
6885
-
6886
- void main(void) {
6887
- vec4 color = texture2D(sampler, vUv);
6888
- vec4 mask = calcColor(vUv.x);
6889
- gl_FragColor = vec4(mix(color.rgb, mask.rgb, color.a * mask.a), color.a);
6890
- }`
6891
- }));
6892
- __decorateClass$L([
6893
- property()
6894
- ], ColorOverlayEffect.prototype, "colors", 2);
6895
- __decorateClass$L([
6896
- property()
6897
- ], ColorOverlayEffect.prototype, "alpha", 2);
6898
- ColorOverlayEffect = __decorateClass$L([
6899
- customNode("ColorOverlayEffect")
6900
- ], ColorOverlayEffect);
7066
+ Transition = __decorateClass$K([
7067
+ customNode("Transition", {
7068
+ effectMode: "transition",
7069
+ processMode: "pausable",
7070
+ duration: 2e3
7071
+ })
7072
+ ], Transition);
6901
7073
 
6902
7074
  var __defProp$C = Object.defineProperty;
6903
7075
  var __getOwnPropDesc$B = Object.getOwnPropertyDescriptor;
6904
- var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$C(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6905
- var __decorateClass$K = (decorators, target, key, kind) => {
7076
+ var __decorateClass$J = (decorators, target, key, kind) => {
6906
7077
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$B(target, key) : target;
6907
7078
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
6908
7079
  if (decorator = decorators[i])
@@ -6910,84 +7081,119 @@ var __decorateClass$K = (decorators, target, key, kind) => {
6910
7081
  if (kind && result) __defProp$C(target, key, result);
6911
7082
  return result;
6912
7083
  };
6913
- var __publicField$f = (obj, key, value) => __defNormalProp$f(obj, key + "" , value);
6914
- let ColorRemoveEffect = class extends Effect {
6915
- _color = new Color();
6916
- constructor(properties, children = []) {
7084
+ let Node2D = class extends CanvasItem {
7085
+ position = new Vector2().on("update", () => this.updateGlobalTransform());
7086
+ scale = new Vector2(1, 1).on("update", () => this.updateGlobalTransform());
7087
+ skew = new Vector2().on("update", () => this.updateGlobalTransform());
7088
+ transform = new Transform2D();
7089
+ globalPosition = new Vector2();
7090
+ globalScale = new Vector2();
7091
+ globalSkew = new Vector2();
7092
+ globalTransform = new Transform2D();
7093
+ _parentTransformDirtyId;
7094
+ constructor(properties, nodes = []) {
6917
7095
  super();
6918
- this.setProperties(properties).append(children);
7096
+ this.setProperties(properties).append(nodes);
6919
7097
  }
6920
- apply(renderer, source) {
6921
- const maxColors = 50;
6922
- const originalColors = new Float32Array(maxColors * 3);
6923
- const colors = this.colors.map((val) => {
6924
- this._color.value = val;
6925
- return this._color.toArray().slice(0, 3);
6926
- });
6927
- while (colors.length < maxColors) {
6928
- colors.push([-1, 0, 0]);
7098
+ _updateProperty(key, value, oldValue, declaration) {
7099
+ super._updateProperty(key, value, oldValue, declaration);
7100
+ switch (key) {
7101
+ case "rotation":
7102
+ this.requestRelayout();
7103
+ break;
6929
7104
  }
6930
- colors.slice(0, maxColors).forEach((originalColor, i) => {
6931
- originalColors[i * 3] = originalColor[0];
6932
- originalColors[i * 3 + 1] = originalColor[1];
6933
- originalColors[i * 3 + 2] = originalColor[2];
6934
- });
6935
- source.redraw(renderer, () => {
6936
- QuadUvGeometry.draw(renderer, ColorRemoveEffect.material, {
6937
- sampler: 0,
6938
- epsilon: this.epsilon,
6939
- originalColors
6940
- });
6941
- });
6942
7105
  }
6943
- };
6944
- __publicField$f(ColorRemoveEffect, "material", new Material({
6945
- vert: `precision mediump float;
6946
- attribute vec2 position;
6947
- attribute vec2 uv;
6948
- varying vec2 vUv;
6949
- void main() {
6950
- gl_Position = vec4(position, 0.0, 1.0);
6951
- vUv = uv;
6952
- }`,
6953
- frag: `varying vec2 vUv;
6954
- uniform sampler2D sampler;
6955
- uniform float epsilon;
6956
- const int MAX_COLORS = 50;
6957
- uniform vec3 originalColors[MAX_COLORS];
6958
-
6959
- void main(void) {
6960
- vec4 color = texture2D(sampler, vUv);
6961
-
6962
- for (int i = 0; i < MAX_COLORS; i++) {
6963
- vec3 origColor = originalColors[i];
6964
- if (origColor.r < 0.0) {
6965
- break;
7106
+ getTransformOrigin() {
7107
+ return new Vector2(0, 0);
7108
+ }
7109
+ getTransform(cb) {
7110
+ const origin = this.getTransformOrigin();
7111
+ const transform = new Transform2D();
7112
+ transform.translate(-origin.x, -origin.y).scale(this.scale.x, this.scale.y).skew(this.skew.x, this.skew.y).rotate(this.rotation);
7113
+ cb?.(transform);
7114
+ transform.translate(this.position.x, this.position.y).translate(origin.x, origin.y);
7115
+ return transform;
7116
+ }
7117
+ updateTransform() {
7118
+ this.transform.copy(this.getTransform());
7119
+ }
7120
+ updateGlobalTransform() {
7121
+ this.updateTransform();
7122
+ const parent = this.getParent();
7123
+ if (parent?.globalTransform) {
7124
+ this._parentTransformDirtyId = parent.globalTransform.dirtyId;
7125
+ this.globalScale.set(parent.globalScale.x * this.scale.x, parent.globalScale.y * this.scale.y);
7126
+ this.globalRotation = parent.globalRotation + this.rotation;
7127
+ parent.globalTransform.multiply(this.transform, this.globalTransform);
7128
+ } else {
7129
+ this.globalScale.copy(this.scale);
7130
+ this.globalRotation = this.rotation;
7131
+ this.globalTransform.copy(this.transform);
6966
7132
  }
6967
- vec3 colorDiff = origColor - color.rgb;
6968
- if (length(colorDiff) < epsilon) {
6969
- gl_FragColor = vec4(0, 0, 0, 0);
6970
- return;
7133
+ const [
7134
+ a,
7135
+ c,
7136
+ tx,
7137
+ b,
7138
+ d,
7139
+ ty
7140
+ ] = this.globalTransform.toArray();
7141
+ this.globalPosition.set(tx, ty);
7142
+ this.globalSkew.x = Math.atan2(c, a) - this.globalRotation;
7143
+ this.globalSkew.y = Math.atan2(b, d) - this.globalRotation;
7144
+ this.requestRelayout();
7145
+ }
7146
+ _transformVertices(vertices, vertTransform) {
7147
+ let a, c, tx, b, d, ty;
7148
+ if (vertTransform) {
7149
+ const globalTransform = this.globalTransform.clone();
7150
+ globalTransform.multiply(
7151
+ typeof vertTransform === "function" ? vertTransform?.() : vertTransform
7152
+ );
7153
+ [a, c, tx, b, d, ty] = globalTransform.toArray();
7154
+ } else {
7155
+ [a, c, tx, b, d, ty] = this.globalTransform.toArray();
7156
+ }
7157
+ const newVertices = vertices.slice();
7158
+ for (let len = vertices.length, i = 0; i < len; i += 2) {
7159
+ const x = vertices[i];
7160
+ const y = vertices[i + 1];
7161
+ newVertices[i] = a * x + c * y + tx;
7162
+ newVertices[i + 1] = b * x + d * y + ty;
6971
7163
  }
7164
+ return newVertices;
6972
7165
  }
6973
-
6974
- gl_FragColor = color;
6975
- }`
6976
- }));
6977
- __decorateClass$K([
6978
- property()
6979
- ], ColorRemoveEffect.prototype, "colors", 2);
6980
- __decorateClass$K([
6981
- property()
6982
- ], ColorRemoveEffect.prototype, "epsilon", 2);
6983
- ColorRemoveEffect = __decorateClass$K([
6984
- customNode("ColorRemoveEffect")
6985
- ], ColorRemoveEffect);
7166
+ _relayout(batchables) {
7167
+ batchables = super._relayout(batchables);
7168
+ this.updateGlobalTransform();
7169
+ return batchables.map((batchable) => {
7170
+ return {
7171
+ ...batchable,
7172
+ vertices: this._transformVertices(batchable.vertices, batchable.vertTransform)
7173
+ };
7174
+ });
7175
+ }
7176
+ _process(delta) {
7177
+ super._process(delta);
7178
+ const parent = this.getParent();
7179
+ if (parent?.globalTransform && this._parentTransformDirtyId !== parent?.globalTransform?.dirtyId) {
7180
+ this.requestRelayout();
7181
+ }
7182
+ }
7183
+ };
7184
+ __decorateClass$J([
7185
+ property({ protected: true, fallback: 0 })
7186
+ ], Node2D.prototype, "rotation", 2);
7187
+ __decorateClass$J([
7188
+ property({ protected: true, fallback: 0 })
7189
+ ], Node2D.prototype, "globalRotation", 2);
7190
+ Node2D = __decorateClass$J([
7191
+ customNode("Node2D")
7192
+ ], Node2D);
6986
7193
 
6987
7194
  var __defProp$B = Object.defineProperty;
6988
7195
  var __getOwnPropDesc$A = Object.getOwnPropertyDescriptor;
6989
- var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$B(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6990
- var __decorateClass$J = (decorators, target, key, kind) => {
7196
+ var __decorateClass$I = (decorators, target, key, kind) => {
6991
7197
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$A(target, key) : target;
6992
7198
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
6993
7199
  if (decorator = decorators[i])
@@ -6995,53 +7201,242 @@ var __decorateClass$J = (decorators, target, key, kind) => {
6995
7201
  if (kind && result) __defProp$B(target, key, result);
6996
7202
  return result;
6997
7203
  };
6998
- var __publicField$e = (obj, key, value) => __defNormalProp$e(obj, key + "" , value);
6999
- const MAX_COLORS = 50;
7000
- let ColorReplaceEffect = class extends Effect {
7001
- _color = new Color();
7002
- constructor(properties, children = []) {
7204
+ let Camera2D = class extends Node2D {
7205
+ zoom = new Vector2(1, 1).on("update", () => this.updateCanvasTransform());
7206
+ constructor(properties, nodes = []) {
7003
7207
  super();
7004
- this.setProperties(properties).append(children);
7208
+ this.setProperties(properties).append(nodes);
7005
7209
  }
7006
- apply(renderer, source) {
7007
- const colors = this.colors.map((val) => {
7008
- this._color.value = val[0];
7009
- const color0 = this._color.toArray().slice(0, 3);
7010
- this._color.value = val[1];
7011
- const color1 = this._color.toArray().slice(0, 3);
7012
- return [
7013
- color0,
7014
- color1
7015
- ];
7016
- });
7017
- const epsilon = this.epsilon;
7018
- const originalColors = new Float32Array(MAX_COLORS * 3);
7019
- const targetColors = new Float32Array(MAX_COLORS * 3);
7020
- while (colors.length < MAX_COLORS) {
7021
- colors.push([
7022
- [-1, 0, 0],
7023
- [0, 0, 0, 1]
7024
- ]);
7210
+ _input(event, key) {
7211
+ super._input(event, key);
7212
+ if (key === "wheel") {
7213
+ const e = event;
7214
+ if (e.ctrlKey) {
7215
+ const isTouchPad = e.wheelDeltaY ? Math.abs(Math.abs(e.wheelDeltaY) - Math.abs(3 * e.deltaY)) < 3 : e.deltaMode === 0;
7216
+ if (!isTouchPad) {
7217
+ e.preventDefault();
7218
+ const value = this.zoom.x + e.deltaY * -0.015;
7219
+ const zoom = Math.min(this.maxZoom, Math.max(this.minZoom, value));
7220
+ const ratio = 1 - zoom / this.zoom.x;
7221
+ this.zoom.set([
7222
+ zoom,
7223
+ zoom
7224
+ ]);
7225
+ this.position.add([
7226
+ (e.screenX - this.position.x) * ratio,
7227
+ (e.screenY - this.position.y) * ratio
7228
+ ]);
7229
+ }
7230
+ } else {
7231
+ e.preventDefault();
7232
+ this.position.add([
7233
+ -e.deltaX,
7234
+ -e.deltaY
7235
+ ]);
7236
+ }
7025
7237
  }
7026
- colors.slice(0, MAX_COLORS).forEach(([originalColor, targetColor], i) => {
7027
- originalColors[i * 3] = originalColor[0];
7028
- originalColors[i * 3 + 1] = originalColor[1];
7029
- originalColors[i * 3 + 2] = originalColor[2];
7030
- targetColors[i * 3] = targetColor[0];
7031
- targetColors[i * 3 + 1] = targetColor[1];
7032
- targetColors[i * 3 + 2] = targetColor[2];
7033
- });
7238
+ }
7239
+ updateTransform() {
7240
+ super.updateTransform();
7241
+ this.updateCanvasTransform();
7242
+ }
7243
+ updateCanvasTransform() {
7244
+ const viewport = this.getViewport();
7245
+ if (!viewport)
7246
+ return;
7247
+ viewport.canvasTransform.identity().scale(this.zoom.x, this.zoom.y).translate(this.position.x, this.position.y);
7248
+ }
7249
+ };
7250
+ __decorateClass$I([
7251
+ property({ fallback: 6 })
7252
+ ], Camera2D.prototype, "maxZoom", 2);
7253
+ __decorateClass$I([
7254
+ property({ fallback: 0.1 })
7255
+ ], Camera2D.prototype, "minZoom", 2);
7256
+ Camera2D = __decorateClass$I([
7257
+ customNode("Camera2D")
7258
+ ], Camera2D);
7259
+
7260
+ const defaultFilters = {
7261
+ "brightness": 1,
7262
+ "contrast": 1,
7263
+ "grayscale": 0,
7264
+ "hue-rotate": 0,
7265
+ "invert": 0,
7266
+ "opacity": 1,
7267
+ "saturate": 1,
7268
+ "sepia": 0
7269
+ };
7270
+ function parseCSSFilter(filter) {
7271
+ const m = new ColorMatrix();
7272
+ if (filter === "none") {
7273
+ return m;
7274
+ }
7275
+ const filters = parseCssFunctions(filter).reduce((filter2, { name, args }) => {
7276
+ filter2[name] = args[0].normalizedIntValue;
7277
+ return filter2;
7278
+ }, {});
7279
+ Object.keys(defaultFilters).forEach((name) => {
7280
+ filters[name] = filters[name] ?? defaultFilters[name];
7281
+ });
7282
+ for (const name in filters) {
7283
+ const value = filters[name];
7284
+ switch (name) {
7285
+ case "hue-rotate":
7286
+ m.hueRotate(value * PI_2);
7287
+ break;
7288
+ case "saturate":
7289
+ m.saturate(value);
7290
+ break;
7291
+ case "brightness":
7292
+ m.brightness(value);
7293
+ break;
7294
+ case "contrast":
7295
+ m.contrast(value);
7296
+ break;
7297
+ case "invert":
7298
+ m.invert(value);
7299
+ break;
7300
+ case "sepia":
7301
+ m.sepia(value);
7302
+ break;
7303
+ case "opacity":
7304
+ m.opacity(value);
7305
+ break;
7306
+ case "grayscale":
7307
+ m.grayscale(value);
7308
+ break;
7309
+ }
7310
+ }
7311
+ return m;
7312
+ }
7313
+
7314
+ function parseCSSTransform(transform, width, height, output = new Transform2D()) {
7315
+ transform = !transform || transform === "none" ? "" : transform;
7316
+ parseCssFunctions(transform, { width, height }).reverse().forEach(({ name, args }) => {
7317
+ const values = args.map((arg) => arg.normalizedIntValue);
7318
+ switch (name) {
7319
+ case "translate":
7320
+ output.translate(values[0] * width, (values[1] ?? values[0]) * height);
7321
+ break;
7322
+ case "translateX":
7323
+ output.translateX(values[0] * width);
7324
+ break;
7325
+ case "translateY":
7326
+ output.translateY(values[0] * height);
7327
+ break;
7328
+ case "translateZ":
7329
+ output.translateZ(values[0]);
7330
+ break;
7331
+ case "translate3d":
7332
+ output.translate3d(
7333
+ values[0] * width,
7334
+ (values[1] ?? values[0]) * height,
7335
+ values[2] ?? values[1] ?? values[0]
7336
+ );
7337
+ break;
7338
+ case "scale":
7339
+ output.scale(values[0], values[1] ?? values[0]);
7340
+ break;
7341
+ case "scaleX":
7342
+ output.scaleX(values[0]);
7343
+ break;
7344
+ case "scaleY":
7345
+ output.scaleY(values[0]);
7346
+ break;
7347
+ case "scale3d":
7348
+ output.scale3d(values[0], values[1] ?? values[0], values[2] ?? values[1] ?? values[0]);
7349
+ break;
7350
+ case "rotate":
7351
+ output.rotate(values[0] * PI_2);
7352
+ break;
7353
+ case "rotateX":
7354
+ output.rotateX(values[0] * PI_2);
7355
+ break;
7356
+ case "rotateY":
7357
+ output.rotateY(values[0] * PI_2);
7358
+ break;
7359
+ case "rotateZ":
7360
+ output.rotateZ(values[0] * PI_2);
7361
+ break;
7362
+ case "rotate3d":
7363
+ output.rotate3d(
7364
+ values[0] * PI_2,
7365
+ (values[1] ?? values[0]) * PI_2,
7366
+ (values[2] ?? values[1] ?? values[0]) * PI_2,
7367
+ (values[3] ?? values[2] ?? values[1] ?? values[0]) * PI_2
7368
+ );
7369
+ break;
7370
+ case "skew":
7371
+ output.skew(values[0], values[0] ?? values[1]);
7372
+ break;
7373
+ case "skewX":
7374
+ output.skewX(values[0]);
7375
+ break;
7376
+ case "skewY":
7377
+ output.skewY(values[0]);
7378
+ break;
7379
+ case "matrix":
7380
+ output.set(values);
7381
+ break;
7382
+ }
7383
+ });
7384
+ return output;
7385
+ }
7386
+
7387
+ function parseCSSTransformOrigin(transformOrigin) {
7388
+ const [originX, originY = originX] = transformOrigin.split(" ");
7389
+ return [originX, originY].map((val) => {
7390
+ val = val.trim();
7391
+ switch (val) {
7392
+ case "left":
7393
+ case "top":
7394
+ return 0;
7395
+ case "center":
7396
+ return 0.5;
7397
+ case "right":
7398
+ case "bottom":
7399
+ return 1;
7400
+ default:
7401
+ return Number(val);
7402
+ }
7403
+ });
7404
+ }
7405
+
7406
+ var __defProp$A = Object.defineProperty;
7407
+ var __getOwnPropDesc$z = Object.getOwnPropertyDescriptor;
7408
+ var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$A(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7409
+ var __decorateClass$H = (decorators, target, key, kind) => {
7410
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$z(target, key) : target;
7411
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
7412
+ if (decorator = decorators[i])
7413
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
7414
+ if (kind && result) __defProp$A(target, key, result);
7415
+ return result;
7416
+ };
7417
+ var __publicField$i = (obj, key, value) => __defNormalProp$i(obj, key + "" , value);
7418
+ let ColorAdjustEffect = class extends Effect {
7419
+ constructor(properties, children = []) {
7420
+ super();
7421
+ this.setProperties(properties).append(children);
7422
+ }
7423
+ apply(renderer, source) {
7034
7424
  source.redraw(renderer, () => {
7035
- QuadUvGeometry.draw(renderer, ColorReplaceEffect.material, {
7425
+ QuadUvGeometry.draw(renderer, ColorAdjustEffect.material, {
7036
7426
  sampler: 0,
7037
- epsilon,
7038
- originalColors,
7039
- targetColors
7427
+ saturation: this.saturation,
7428
+ contrast: this.contrast,
7429
+ brightness: this.brightness,
7430
+ red: this.red,
7431
+ green: this.green,
7432
+ blue: this.blue,
7433
+ alpha: this.alpha,
7434
+ gamma: Math.max(this.gamma ?? 1, 1e-4)
7040
7435
  });
7041
7436
  });
7042
7437
  }
7043
7438
  };
7044
- __publicField$e(ColorReplaceEffect, "material", new Material({
7439
+ __publicField$i(ColorAdjustEffect, "material", new Material({
7045
7440
  vert: `precision mediump float;
7046
7441
  attribute vec2 position;
7047
7442
  attribute vec2 uv;
@@ -7052,606 +7447,448 @@ void main() {
7052
7447
  }`,
7053
7448
  frag: `varying vec2 vUv;
7054
7449
  uniform sampler2D sampler;
7055
- uniform float epsilon;
7056
- const int MAX_COLORS = ${MAX_COLORS};
7057
- uniform vec3 originalColors[MAX_COLORS];
7058
- uniform vec3 targetColors[MAX_COLORS];
7450
+ uniform float gamma;
7451
+ uniform float contrast;
7452
+ uniform float saturation;
7453
+ uniform float brightness;
7454
+ uniform float red;
7455
+ uniform float green;
7456
+ uniform float blue;
7457
+ uniform float alpha;
7059
7458
 
7060
7459
  void main(void) {
7061
- gl_FragColor = texture2D(sampler, vUv);
7062
-
7063
- float alpha = gl_FragColor.a;
7064
- if (alpha < 0.0001) {
7065
- return;
7066
- }
7067
-
7068
- vec3 color = gl_FragColor.rgb / alpha;
7069
-
7070
- for(int i = 0; i < MAX_COLORS; i++) {
7071
- vec3 origColor = originalColors[i];
7072
- if (origColor.r < 0.0) {
7073
- break;
7074
- }
7075
- vec3 colorDiff = origColor - color;
7076
- if (length(colorDiff) < epsilon) {
7077
- vec3 targetColor = targetColors[i];
7078
- gl_FragColor = vec4((targetColor + colorDiff) * alpha, alpha);
7079
- return;
7080
- }
7460
+ vec4 c = texture2D(sampler, vUv);
7461
+ if (c.a > 0.0) {
7462
+ c.rgb /= c.a;
7463
+ vec3 rgb = pow(c.rgb, vec3(1. / gamma));
7464
+ rgb = mix(vec3(.5), mix(vec3(dot(vec3(.2125, .7154, .0721), rgb)), rgb, saturation), contrast);
7465
+ rgb.r *= red;
7466
+ rgb.g *= green;
7467
+ rgb.b *= blue;
7468
+ c.rgb = rgb * brightness;
7469
+ c.rgb *= c.a;
7081
7470
  }
7471
+ gl_FragColor = c * alpha;
7082
7472
  }`
7083
7473
  }));
7084
- __decorateClass$J([
7474
+ __decorateClass$H([
7085
7475
  property()
7086
- ], ColorReplaceEffect.prototype, "colors", 2);
7087
- __decorateClass$J([
7476
+ ], ColorAdjustEffect.prototype, "saturation", 2);
7477
+ __decorateClass$H([
7088
7478
  property()
7089
- ], ColorReplaceEffect.prototype, "epsilon", 2);
7090
- ColorReplaceEffect = __decorateClass$J([
7091
- customNode("ColorReplaceEffect")
7092
- ], ColorReplaceEffect);
7093
-
7094
- class CanvasContext extends Path2D {
7095
- fillStyle;
7096
- strokeStyle;
7097
- lineCap;
7098
- lineJoin;
7099
- lineWidth;
7100
- miterLimit;
7101
- // custom
7102
- uvTransform;
7103
- vertTransform;
7104
- _defaultStyle = Texture2D.EMPTY;
7105
- _draws = [];
7106
- _toTexture(source) {
7107
- if (source instanceof Texture2D) {
7108
- return source;
7109
- } else {
7110
- return ColorTexture.get(source);
7111
- }
7112
- }
7113
- stroke(options) {
7114
- if (!this.curves.length) {
7115
- return;
7116
- }
7117
- let strokeStyle = this.strokeStyle;
7118
- if (!strokeStyle && this.style.stroke) {
7119
- switch (typeof this.style.stroke) {
7120
- case "string":
7121
- strokeStyle = this.style.stroke;
7122
- break;
7123
- case "object":
7124
- if (isColorFillObject(this.style.stroke)) {
7125
- strokeStyle = this.style.stroke.color;
7126
- }
7127
- break;
7128
- }
7129
- }
7130
- this._draws.push({
7131
- ...options,
7132
- type: "stroke",
7133
- path: new Path2D(this),
7134
- texture: strokeStyle ? this._toTexture(strokeStyle) : this._defaultStyle,
7135
- uvTransform: this.uvTransform,
7136
- vertTransform: this.vertTransform,
7137
- style: {
7138
- alignment: 0.5,
7139
- cap: this.lineCap ?? "butt",
7140
- join: this.lineJoin ?? "miter",
7141
- width: this.lineWidth ?? 1,
7142
- miterLimit: this.miterLimit ?? 10
7143
- }
7144
- });
7145
- super.reset();
7146
- }
7147
- fillRect(x, y, width, height) {
7148
- this.rect(x, y, width, height).fill();
7149
- }
7150
- strokeRect(x, y, width, height) {
7151
- this.rect(x, y, width, height).stroke();
7152
- }
7153
- fill(options) {
7154
- if (!this.curves.length) {
7155
- return;
7156
- }
7157
- let fillStyle = this.fillStyle;
7158
- if (!fillStyle && this.style.fill) {
7159
- switch (typeof this.style.fill) {
7160
- case "string":
7161
- fillStyle = this.style.fill;
7162
- break;
7163
- case "object":
7164
- if (isColorFillObject(this.style.fill)) {
7165
- fillStyle = this.style.fill.color;
7166
- }
7167
- break;
7168
- }
7169
- }
7170
- this._draws.push({
7171
- ...options,
7172
- type: "fill",
7173
- path: new Path2D(this),
7174
- texture: fillStyle ? this._toTexture(fillStyle) : this._defaultStyle,
7175
- uvTransform: this.uvTransform,
7176
- vertTransform: this.vertTransform
7177
- });
7178
- super.reset();
7179
- }
7180
- copy(source) {
7181
- super.copy(source);
7182
- this.strokeStyle = source.strokeStyle;
7183
- this.fillStyle = source.fillStyle;
7184
- this.uvTransform = source.uvTransform;
7185
- this.vertTransform = source.vertTransform;
7186
- this.lineCap = source.lineCap;
7187
- this.lineJoin = source.lineJoin;
7188
- this.lineWidth = source.lineWidth;
7189
- this.miterLimit = source.miterLimit;
7190
- this._draws = source._draws.slice();
7191
- return this;
7192
- }
7193
- reset() {
7194
- super.reset();
7195
- this.strokeStyle = void 0;
7196
- this.fillStyle = void 0;
7197
- this.uvTransform = void 0;
7198
- this.vertTransform = void 0;
7199
- this.lineCap = void 0;
7200
- this.lineJoin = void 0;
7201
- this.lineWidth = void 0;
7202
- this.miterLimit = void 0;
7203
- this._draws.length = 0;
7204
- return this;
7205
- }
7206
- buildUvs(start, vertices, uvs, texture, uvTransform) {
7207
- if (texture) {
7208
- const _uvTransform = uvTransform ? typeof uvTransform === "function" ? uvTransform : (x, y) => uvTransform.applyToPoint(x, y) : uvTransform;
7209
- const w = texture.width;
7210
- const h = texture.height;
7211
- for (let len = vertices.length, i = start; i < len; i += 2) {
7212
- const x = vertices[i];
7213
- const y = vertices[i + 1];
7214
- let uvX;
7215
- let uvY;
7216
- if (_uvTransform) {
7217
- [uvX, uvY] = _uvTransform(x, y);
7218
- } else {
7219
- [uvX, uvY] = [x / w, y / h];
7220
- }
7221
- uvs.push(uvX, uvY);
7222
- }
7223
- } else {
7224
- for (let len = vertices.length, i = start; i < len; i += 2) {
7225
- uvs.push(0, 0);
7226
- }
7227
- }
7228
- }
7229
- toBatchables() {
7230
- const batchables = [];
7231
- for (let len = this._draws.length, i = 0; i < len; i++) {
7232
- const current = this._draws[i];
7233
- const vertices = [];
7234
- const indices = [];
7235
- const uvs = [];
7236
- if (current.type === "fill") {
7237
- current.path.fillTriangulate({
7238
- vertices,
7239
- indices
7240
- });
7241
- } else {
7242
- current.path.strokeTriangulate({
7243
- vertices,
7244
- indices,
7245
- lineStyle: current.style,
7246
- flipAlignment: false,
7247
- closed: true
7248
- });
7249
- }
7250
- this.buildUvs(0, vertices, uvs, current.texture, current.uvTransform);
7251
- batchables.push({
7252
- vertices,
7253
- indices,
7254
- uvs,
7255
- texture: current.texture,
7256
- type: current.type,
7257
- disableWrapMode: current.disableWrapMode,
7258
- vertTransform: current.vertTransform
7259
- });
7260
- }
7261
- return batchables;
7262
- }
7263
- }
7479
+ ], ColorAdjustEffect.prototype, "contrast", 2);
7480
+ __decorateClass$H([
7481
+ property()
7482
+ ], ColorAdjustEffect.prototype, "brightness", 2);
7483
+ __decorateClass$H([
7484
+ property()
7485
+ ], ColorAdjustEffect.prototype, "red", 2);
7486
+ __decorateClass$H([
7487
+ property()
7488
+ ], ColorAdjustEffect.prototype, "green", 2);
7489
+ __decorateClass$H([
7490
+ property()
7491
+ ], ColorAdjustEffect.prototype, "blue", 2);
7492
+ __decorateClass$H([
7493
+ property()
7494
+ ], ColorAdjustEffect.prototype, "alpha", 2);
7495
+ __decorateClass$H([
7496
+ property()
7497
+ ], ColorAdjustEffect.prototype, "gamma", 2);
7498
+ ColorAdjustEffect = __decorateClass$H([
7499
+ customNode("ColorAdjustEffect")
7500
+ ], ColorAdjustEffect);
7264
7501
 
7265
- var __defProp$A = Object.defineProperty;
7266
- var __getOwnPropDesc$z = Object.getOwnPropertyDescriptor;
7267
- var __decorateClass$I = (decorators, target, key, kind) => {
7268
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$z(target, key) : target;
7502
+ var __defProp$z = Object.defineProperty;
7503
+ var __getOwnPropDesc$y = Object.getOwnPropertyDescriptor;
7504
+ var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$z(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7505
+ var __decorateClass$G = (decorators, target, key, kind) => {
7506
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$y(target, key) : target;
7269
7507
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
7270
7508
  if (decorator = decorators[i])
7271
7509
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
7272
- if (kind && result) __defProp$A(target, key, result);
7510
+ if (kind && result) __defProp$z(target, key, result);
7273
7511
  return result;
7274
7512
  };
7275
- let CanvasItem = class extends TimelineNode {
7276
- _parentGlobalVisible;
7277
- _globalVisible;
7278
- get globalVisible() {
7279
- return this._globalVisible ?? true;
7280
- }
7281
- _parentGlobalOpacity;
7282
- _globalOpacity;
7283
- get globalOpacity() {
7284
- return this._globalOpacity ?? 1;
7285
- }
7286
- _modulate = new Color(4294967295);
7287
- // Batch render
7288
- context = new CanvasContext();
7289
- _resetContext = true;
7290
- _redrawing = true;
7291
- _relayouting = false;
7292
- _repainting = false;
7293
- _originalBatchables = [];
7294
- _layoutedBatchables = [];
7295
- _batchables = [];
7296
- constructor(properties, nodes = []) {
7513
+ var __publicField$h = (obj, key, value) => __defNormalProp$h(obj, key + "" , value);
7514
+ let ColorFilterEffect = class extends Effect {
7515
+ _colorMatrix = new ColorMatrix();
7516
+ constructor(properties, children = []) {
7297
7517
  super();
7298
- this.setProperties(properties).append(nodes);
7299
- }
7300
- _updateProperty(key, value, oldValue, declaration) {
7301
- super._updateProperty(key, value, oldValue, declaration);
7302
- switch (key) {
7303
- case "modulate":
7304
- this._modulate.value = value;
7305
- this.requestRepaint();
7306
- break;
7307
- case "blendMode":
7308
- this.requestRepaint();
7309
- break;
7310
- case "opacity":
7311
- this._updateGlobalOpacity();
7312
- break;
7313
- case "visible":
7314
- case "insideTimeRange":
7315
- this._updateGlobalVisible();
7316
- break;
7317
- }
7318
- }
7319
- show() {
7320
- this.visible = true;
7321
- }
7322
- hide() {
7323
- this.visible = false;
7324
- }
7325
- isVisibleInTree() {
7326
- return this.globalOpacity > 0 && this.globalVisible;
7327
- }
7328
- canRender() {
7329
- return super.canRender() && this.isVisibleInTree();
7330
- }
7331
- requestRedraw() {
7332
- this._redrawing = true;
7333
- }
7334
- requestRelayout() {
7335
- this._relayouting = true;
7336
- }
7337
- requestRepaint() {
7338
- this._repainting = true;
7339
- }
7340
- _updateGlobalVisible() {
7341
- this._parentGlobalVisible = this.getParent()?.globalVisible;
7342
- this._globalVisible = (this._parentGlobalVisible ?? true) && this.visible && this.insideTimeRange;
7343
- }
7344
- _updateGlobalOpacity() {
7345
- this._parentGlobalOpacity = this.getParent()?.opacity;
7346
- const globalOpacity = clamp(0, this.opacity, 1) * (this._parentGlobalOpacity ?? 1);
7347
- if (this._globalOpacity !== globalOpacity) {
7348
- this._globalOpacity = globalOpacity;
7349
- this.requestRepaint();
7350
- }
7351
- }
7352
- _draw() {
7353
- this.emit("draw");
7354
- }
7355
- _redraw() {
7356
- this.log(this.name, "drawing");
7357
- this._draw();
7358
- return this.context.toBatchables();
7359
- }
7360
- _relayout(batchables) {
7361
- this.log(this.name, "layouting");
7362
- return batchables;
7363
- }
7364
- _repaint(batchables) {
7365
- this.log(this.name, "painting");
7366
- return batchables.map((batchable) => {
7367
- return {
7368
- ...batchable,
7369
- modulate: this._modulate.toArgb(this.globalOpacity, true),
7370
- blendMode: this.blendMode
7371
- };
7372
- });
7373
- }
7374
- _process(delta) {
7375
- super._process(delta);
7376
- const parent = this.getParent();
7377
- if (this._parentGlobalVisible !== parent?.globalVisible) {
7378
- this._updateGlobalVisible();
7379
- }
7380
- if (this._parentGlobalOpacity !== parent?.globalOpacity) {
7381
- this._updateGlobalOpacity();
7382
- }
7518
+ this.setProperties(properties).append(children);
7383
7519
  }
7384
- _updateBatchables() {
7385
- const redrawing = this._redrawing;
7386
- let relayouting = this._relayouting;
7387
- let repainting = this._repainting;
7388
- let batchables;
7389
- if (redrawing) {
7390
- this._originalBatchables = this._redraw();
7391
- relayouting = true;
7392
- }
7393
- if (relayouting) {
7394
- this._layoutedBatchables = this._relayout(this._originalBatchables);
7395
- repainting = true;
7396
- }
7397
- if (repainting) {
7398
- batchables = this._repaint(this._layoutedBatchables);
7399
- }
7400
- if (redrawing) {
7401
- if (this._resetContext) {
7402
- this.context.reset();
7520
+ apply(renderer, source) {
7521
+ if (!this.filter)
7522
+ return;
7523
+ const funs = parseCssFunctions(this.filter);
7524
+ const matrix = this._colorMatrix.identity();
7525
+ funs.forEach(({ name, args }) => {
7526
+ const values = args.map((arg) => arg.normalizedIntValue);
7527
+ switch (name) {
7528
+ case "hue-rotate":
7529
+ case "hueRotate":
7530
+ matrix.hueRotate(values[0] * PI_2);
7531
+ break;
7532
+ case "saturate":
7533
+ matrix.saturate(values[0]);
7534
+ break;
7535
+ case "brightness":
7536
+ matrix.brightness(values[0]);
7537
+ break;
7538
+ case "contrast":
7539
+ matrix.contrast(values[0]);
7540
+ break;
7541
+ case "invert":
7542
+ matrix.invert(values[0]);
7543
+ break;
7544
+ case "sepia":
7545
+ matrix.sepia(values[0]);
7546
+ break;
7547
+ case "opacity":
7548
+ matrix.opacity(values[0]);
7549
+ break;
7550
+ case "grayscale":
7551
+ matrix.grayscale(values[0]);
7552
+ break;
7403
7553
  }
7404
- }
7405
- if (batchables) {
7406
- this._batchables = batchables;
7407
- this._redrawing = false;
7408
- this._relayouting = false;
7409
- this._repainting = false;
7410
- }
7411
- }
7412
- _render(renderer) {
7413
- this._updateBatchables();
7414
- this._batchables.forEach((batchable) => {
7415
- batchable.texture?.upload(renderer);
7416
- renderer.batch2D.render({
7417
- ...batchable,
7418
- texture: batchable.texture?._glTexture(renderer)
7554
+ });
7555
+ source.redraw(renderer, () => {
7556
+ QuadUvGeometry.draw(renderer, ColorFilterEffect.material, {
7557
+ sampler: 0,
7558
+ m: matrix.toArray()
7419
7559
  });
7420
7560
  });
7421
- super._render(renderer);
7422
7561
  }
7423
7562
  };
7424
- __decorateClass$I([
7425
- property()
7426
- ], CanvasItem.prototype, "modulate", 2);
7427
- __decorateClass$I([
7428
- property()
7429
- ], CanvasItem.prototype, "blendMode", 2);
7430
- __decorateClass$I([
7431
- property({ protected: true, fallback: true })
7432
- ], CanvasItem.prototype, "visible", 2);
7433
- __decorateClass$I([
7434
- property({ protected: true, fallback: 1 })
7435
- ], CanvasItem.prototype, "opacity", 2);
7436
- CanvasItem = __decorateClass$I([
7437
- customNode("CanvasItem")
7438
- ], CanvasItem);
7439
-
7440
- class RenderStack {
7441
- currentCall;
7442
- calls = [];
7443
- createCall(renderable) {
7444
- return {
7445
- renderable,
7446
- parentCall: this.currentCall,
7447
- fn: renderable.render.bind(renderable),
7448
- calls: []
7449
- };
7450
- }
7451
- push(renderable) {
7452
- const call = this.createCall(renderable);
7453
- (this.currentCall?.calls ?? this.calls).push(call);
7454
- return call;
7455
- }
7456
- render(renderer) {
7457
- this.calls.forEach(function render(call) {
7458
- call.fn(renderer, () => {
7459
- call.calls.forEach(render);
7460
- });
7461
- });
7462
- this.calls = [];
7563
+ __publicField$h(ColorFilterEffect, "material", new Material({
7564
+ vert: `precision mediump float;
7565
+ attribute vec2 position;
7566
+ attribute vec2 uv;
7567
+ varying vec2 vUv;
7568
+ void main() {
7569
+ gl_Position = vec4(position, 0.0, 1.0);
7570
+ vUv = uv;
7571
+ }`,
7572
+ frag: `precision highp float;
7573
+ varying vec2 vUv;
7574
+ uniform sampler2D sampler;
7575
+ uniform float m[20];
7576
+
7577
+ void main(void) {
7578
+ vec4 c = texture2D(sampler, vUv);
7579
+ if (c.a > 0.0) {
7580
+ c.rgb /= c.a;
7463
7581
  }
7464
- }
7582
+ gl_FragColor = vec4(
7583
+ m[0] * c.r + m[1] * c.g + m[2] * c.b + m[3] * c.a + m[4] / 255.0,
7584
+ m[5] * c.r + m[6] * c.g + m[7] * c.b + m[8] * c.a + m[9] / 255.0,
7585
+ m[10] * c.r + m[11] * c.g + m[12] * c.b + m[13] * c.a + m[14] / 255.0,
7586
+ m[15] * c.r + m[16] * c.g + m[17] * c.b + m[18] * c.a + m[19] / 255.0
7587
+ );
7588
+ }`
7589
+ }));
7590
+ __decorateClass$G([
7591
+ property()
7592
+ ], ColorFilterEffect.prototype, "filter", 2);
7593
+ ColorFilterEffect = __decorateClass$G([
7594
+ customNode("ColorFilterEffect")
7595
+ ], ColorFilterEffect);
7465
7596
 
7466
- var __defProp$z = Object.defineProperty;
7467
- var __getOwnPropDesc$y = Object.getOwnPropertyDescriptor;
7468
- var __decorateClass$H = (decorators, target, key, kind) => {
7469
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$y(target, key) : target;
7597
+ var __defProp$y = Object.defineProperty;
7598
+ var __getOwnPropDesc$x = Object.getOwnPropertyDescriptor;
7599
+ var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$y(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7600
+ var __decorateClass$F = (decorators, target, key, kind) => {
7601
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$x(target, key) : target;
7470
7602
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
7471
7603
  if (decorator = decorators[i])
7472
7604
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
7473
- if (kind && result) __defProp$z(target, key, result);
7605
+ if (kind && result) __defProp$y(target, key, result);
7474
7606
  return result;
7475
7607
  };
7476
- let Timeline = class extends Node {
7477
- static from(range, loop = false) {
7478
- const [startTime, endTime] = range ? Array.isArray(range) ? range : [0, range] : [];
7479
- return new Timeline({
7480
- startTime,
7481
- endTime,
7482
- loop
7483
- });
7484
- }
7485
- constructor(properties) {
7608
+ var __publicField$g = (obj, key, value) => __defNormalProp$g(obj, key + "" , value);
7609
+ const MAX_COLORS$1 = 50;
7610
+ let ColorOverlayEffect = class extends Effect {
7611
+ _color = new Color();
7612
+ constructor(properties, children = []) {
7486
7613
  super();
7487
- this.setProperties(properties);
7614
+ this.setProperties(properties).append(children);
7488
7615
  }
7489
- _updateProperty(key, value, oldValue) {
7490
- super._updateProperty(key, value, oldValue);
7491
- switch (key) {
7492
- case "startTime":
7493
- this.startTime = Math.min(value, this.endTime);
7494
- break;
7495
- case "endTime":
7496
- this.endTime = value || Number.MAX_SAFE_INTEGER;
7497
- break;
7498
- }
7616
+ apply(renderer, source) {
7617
+ source.redraw(renderer, () => {
7618
+ const colors = this.colors.map((val) => {
7619
+ this._color.value = val;
7620
+ const rgba = this._color.toArray();
7621
+ rgba[3] = this.alpha;
7622
+ return rgba;
7623
+ });
7624
+ while (colors.length < MAX_COLORS$1) {
7625
+ colors.push([0, 0, 0, 0]);
7626
+ }
7627
+ QuadUvGeometry.draw(renderer, ColorOverlayEffect.material, {
7628
+ sampler: 0,
7629
+ colors: colors.slice(0, MAX_COLORS$1).flatMap((item) => item)
7630
+ });
7631
+ });
7499
7632
  }
7500
- addTime(delta) {
7501
- const start = this.startTime;
7502
- const end = this.endTime;
7503
- let current = this.currentTime;
7504
- current = current + delta;
7505
- if (this.loop && current > end) {
7506
- current = start + current % end;
7633
+ };
7634
+ __publicField$g(ColorOverlayEffect, "material", new Material({
7635
+ vert: `precision mediump float;
7636
+ attribute vec2 position;
7637
+ attribute vec2 uv;
7638
+ varying vec2 vUv;
7639
+ void main() {
7640
+ gl_Position = vec4(position, 0.0, 1.0);
7641
+ vUv = uv;
7642
+ }`,
7643
+ frag: `precision mediump float;
7644
+ uniform sampler2D sampler;
7645
+ uniform vec4 colors[${MAX_COLORS$1}];
7646
+ varying vec2 vUv;
7647
+
7648
+ float calcWidth() {
7649
+ return distance(vec2(0, 0), vec2(1, 0));
7650
+ }
7651
+
7652
+ int calcCount() {
7653
+ int count = 0;
7654
+ for (int i = 0; i < ${MAX_COLORS$1}; i++) {
7655
+ if (colors[i] != vec4(0,0,0,0)){
7656
+ count++;
7657
+ }
7658
+ }
7659
+ return count;
7660
+ }
7661
+
7662
+ vec4 calcColor(float x) {
7663
+ float perUnit = calcWidth() / float(calcCount());
7664
+ int index = int(x / perUnit);
7665
+
7666
+ for(int i=0; i<${MAX_COLORS$1}; i++){
7667
+ if(i==index){
7668
+ return colors[i];
7507
7669
  }
7508
- current = clamp(start, current, end);
7509
- this.currentTime = current;
7510
- this.emit("updateCurrentTime", current, delta);
7511
- return this;
7512
- }
7513
- _process(delta) {
7514
- super._process(delta);
7515
- this.addTime(delta);
7516
7670
  }
7517
- };
7518
- __decorateClass$H([
7519
- property({ fallback: 0 })
7520
- ], Timeline.prototype, "startTime", 2);
7521
- __decorateClass$H([
7522
- property({ fallback: 0 })
7523
- ], Timeline.prototype, "currentTime", 2);
7524
- __decorateClass$H([
7525
- property({ fallback: Number.MAX_SAFE_INTEGER })
7526
- ], Timeline.prototype, "endTime", 2);
7527
- __decorateClass$H([
7528
- property({ fallback: false })
7529
- ], Timeline.prototype, "loop", 2);
7530
- Timeline = __decorateClass$H([
7531
- customNode("Timeline")
7532
- ], Timeline);
7533
7671
 
7534
- var __defProp$y = Object.defineProperty;
7535
- var __decorateClass$G = (decorators, target, key, kind) => {
7536
- var result = void 0 ;
7672
+ return vec4(0, 0, 0, 0);
7673
+ }
7674
+
7675
+ void main(void) {
7676
+ vec4 color = texture2D(sampler, vUv);
7677
+ vec4 mask = calcColor(vUv.x);
7678
+ gl_FragColor = vec4(mix(color.rgb, mask.rgb, color.a * mask.a), color.a);
7679
+ }`
7680
+ }));
7681
+ __decorateClass$F([
7682
+ property()
7683
+ ], ColorOverlayEffect.prototype, "colors", 2);
7684
+ __decorateClass$F([
7685
+ property()
7686
+ ], ColorOverlayEffect.prototype, "alpha", 2);
7687
+ ColorOverlayEffect = __decorateClass$F([
7688
+ customNode("ColorOverlayEffect")
7689
+ ], ColorOverlayEffect);
7690
+
7691
+ var __defProp$x = Object.defineProperty;
7692
+ var __getOwnPropDesc$w = Object.getOwnPropertyDescriptor;
7693
+ var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$x(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7694
+ var __decorateClass$E = (decorators, target, key, kind) => {
7695
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$w(target, key) : target;
7537
7696
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
7538
7697
  if (decorator = decorators[i])
7539
- result = (decorator(target, key, result) ) || result;
7540
- if (result) __defProp$y(target, key, result);
7698
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
7699
+ if (kind && result) __defProp$x(target, key, result);
7541
7700
  return result;
7542
7701
  };
7543
- class SceneTree extends MainLoop {
7544
- input = new Input();
7545
- renderStack = new RenderStack();
7546
- root = new Viewport(true).setTree(this);
7547
- timeline;
7548
- nodes = /* @__PURE__ */ new Map();
7549
- _backgroundColor = new Color();
7550
- _currentViewport;
7551
- getCurrentViewport() {
7552
- return this._currentViewport;
7553
- }
7554
- setCurrentViewport(viewport) {
7555
- this._currentViewport = viewport;
7556
- }
7557
- constructor(timeline = new Timeline()) {
7702
+ var __publicField$f = (obj, key, value) => __defNormalProp$f(obj, key + "" , value);
7703
+ let ColorRemoveEffect = class extends Effect {
7704
+ _color = new Color();
7705
+ constructor(properties, children = []) {
7558
7706
  super();
7559
- this.timeline = timeline.setTree(this);
7560
- }
7561
- _updateProperty(key, value, oldValue, declaration) {
7562
- super._updateProperty(key, value, oldValue, declaration);
7563
- switch (key) {
7564
- case "backgroundColor":
7565
- this._backgroundColor.value = value;
7566
- break;
7567
- }
7707
+ this.setProperties(properties).append(children);
7568
7708
  }
7569
- log(...args) {
7570
- if (this.debug) {
7571
- console.log(`[modern-canvas][${performance.now().toFixed(4)}ms]`, ...args);
7709
+ apply(renderer, source) {
7710
+ const maxColors = 50;
7711
+ const originalColors = new Float32Array(maxColors * 3);
7712
+ const colors = this.colors.map((val) => {
7713
+ this._color.value = val;
7714
+ return this._color.toArray().slice(0, 3);
7715
+ });
7716
+ while (colors.length < maxColors) {
7717
+ colors.push([-1, 0, 0]);
7572
7718
  }
7573
- }
7574
- _process(delta = 0) {
7575
- this.timeline.emit("process", delta);
7576
- this.emit("processing");
7577
- this.root.emit("process", delta);
7578
- this.emit("processed");
7579
- }
7580
- _render(renderer) {
7581
- this.emit("rendering");
7582
- renderer.program.uniforms.projectionMatrix = this.root.toProjectionArray(true);
7583
- this.renderStack.render(renderer);
7584
- this._renderScreen(renderer);
7585
- this.emit("rendered");
7586
- }
7587
- _renderScreen(renderer) {
7588
- renderer.state.reset();
7589
- renderer.framebuffer.bind(null);
7590
- renderer.viewport.bind({
7591
- x: 0,
7592
- y: 0,
7593
- width: this.root.width * renderer.pixelRatio,
7594
- height: this.root.height * renderer.pixelRatio
7719
+ colors.slice(0, maxColors).forEach((originalColor, i) => {
7720
+ originalColors[i * 3] = originalColor[0];
7721
+ originalColors[i * 3 + 1] = originalColor[1];
7722
+ originalColors[i * 3 + 2] = originalColor[2];
7595
7723
  });
7596
- if (this.backgroundColor) {
7597
- renderer.gl.clearColor(...this._backgroundColor.toArray());
7724
+ source.redraw(renderer, () => {
7725
+ QuadUvGeometry.draw(renderer, ColorRemoveEffect.material, {
7726
+ sampler: 0,
7727
+ epsilon: this.epsilon,
7728
+ originalColors
7729
+ });
7730
+ });
7731
+ }
7732
+ };
7733
+ __publicField$f(ColorRemoveEffect, "material", new Material({
7734
+ vert: `precision mediump float;
7735
+ attribute vec2 position;
7736
+ attribute vec2 uv;
7737
+ varying vec2 vUv;
7738
+ void main() {
7739
+ gl_Position = vec4(position, 0.0, 1.0);
7740
+ vUv = uv;
7741
+ }`,
7742
+ frag: `varying vec2 vUv;
7743
+ uniform sampler2D sampler;
7744
+ uniform float epsilon;
7745
+ const int MAX_COLORS = 50;
7746
+ uniform vec3 originalColors[MAX_COLORS];
7747
+
7748
+ void main(void) {
7749
+ vec4 color = texture2D(sampler, vUv);
7750
+
7751
+ for (int i = 0; i < MAX_COLORS; i++) {
7752
+ vec3 origColor = originalColors[i];
7753
+ if (origColor.r < 0.0) {
7754
+ break;
7598
7755
  }
7599
- renderer.clear();
7600
- if (this.backgroundColor) {
7601
- renderer.gl.clearColor(0, 0, 0, 0);
7756
+ vec3 colorDiff = origColor - color.rgb;
7757
+ if (length(colorDiff) < epsilon) {
7758
+ gl_FragColor = vec4(0, 0, 0, 0);
7759
+ return;
7602
7760
  }
7603
- const texture = this.root.texture;
7604
- texture.activate(renderer, 0);
7605
- QuadUvGeometry.draw(renderer);
7606
- renderer.texture.unbind(texture);
7607
- }
7608
- free() {
7609
- super.free();
7610
- this.root.children.internal.forEach((node) => this.root.removeChild(node));
7611
- this.input.removeEventListeners();
7612
7761
  }
7613
- }
7614
- __decorateClass$G([
7615
- property({ fallback: false })
7616
- ], SceneTree.prototype, "processPaused");
7617
- __decorateClass$G([
7762
+
7763
+ gl_FragColor = color;
7764
+ }`
7765
+ }));
7766
+ __decorateClass$E([
7618
7767
  property()
7619
- ], SceneTree.prototype, "backgroundColor");
7620
- __decorateClass$G([
7621
- property({ protected: true, fallback: false })
7622
- ], SceneTree.prototype, "debug");
7768
+ ], ColorRemoveEffect.prototype, "colors", 2);
7769
+ __decorateClass$E([
7770
+ property()
7771
+ ], ColorRemoveEffect.prototype, "epsilon", 2);
7772
+ ColorRemoveEffect = __decorateClass$E([
7773
+ customNode("ColorRemoveEffect")
7774
+ ], ColorRemoveEffect);
7623
7775
 
7624
- var __getOwnPropDesc$x = Object.getOwnPropertyDescriptor;
7625
- var __decorateClass$F = (decorators, target, key, kind) => {
7626
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$x(target, key) : target;
7776
+ var __defProp$w = Object.defineProperty;
7777
+ var __getOwnPropDesc$v = Object.getOwnPropertyDescriptor;
7778
+ var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$w(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7779
+ var __decorateClass$D = (decorators, target, key, kind) => {
7780
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$v(target, key) : target;
7627
7781
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
7628
7782
  if (decorator = decorators[i])
7629
- result = (decorator(result)) || result;
7783
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
7784
+ if (kind && result) __defProp$w(target, key, result);
7630
7785
  return result;
7631
7786
  };
7632
- let Transition = class extends Effect {
7787
+ var __publicField$e = (obj, key, value) => __defNormalProp$e(obj, key + "" , value);
7788
+ const MAX_COLORS = 50;
7789
+ let ColorReplaceEffect = class extends Effect {
7790
+ _color = new Color();
7633
7791
  constructor(properties, children = []) {
7634
7792
  super();
7635
7793
  this.setProperties(properties).append(children);
7636
7794
  }
7795
+ apply(renderer, source) {
7796
+ const colors = this.colors.map((val) => {
7797
+ this._color.value = val[0];
7798
+ const color0 = this._color.toArray().slice(0, 3);
7799
+ this._color.value = val[1];
7800
+ const color1 = this._color.toArray().slice(0, 3);
7801
+ return [
7802
+ color0,
7803
+ color1
7804
+ ];
7805
+ });
7806
+ const epsilon = this.epsilon;
7807
+ const originalColors = new Float32Array(MAX_COLORS * 3);
7808
+ const targetColors = new Float32Array(MAX_COLORS * 3);
7809
+ while (colors.length < MAX_COLORS) {
7810
+ colors.push([
7811
+ [-1, 0, 0],
7812
+ [0, 0, 0, 1]
7813
+ ]);
7814
+ }
7815
+ colors.slice(0, MAX_COLORS).forEach(([originalColor, targetColor], i) => {
7816
+ originalColors[i * 3] = originalColor[0];
7817
+ originalColors[i * 3 + 1] = originalColor[1];
7818
+ originalColors[i * 3 + 2] = originalColor[2];
7819
+ targetColors[i * 3] = targetColor[0];
7820
+ targetColors[i * 3 + 1] = targetColor[1];
7821
+ targetColors[i * 3 + 2] = targetColor[2];
7822
+ });
7823
+ source.redraw(renderer, () => {
7824
+ QuadUvGeometry.draw(renderer, ColorReplaceEffect.material, {
7825
+ sampler: 0,
7826
+ epsilon,
7827
+ originalColors,
7828
+ targetColors
7829
+ });
7830
+ });
7831
+ }
7637
7832
  };
7638
- Transition = __decorateClass$F([
7639
- customNode("Transition", {
7640
- effectMode: "transition",
7641
- processMode: "pausable",
7642
- duration: 2e3
7643
- })
7644
- ], Transition);
7833
+ __publicField$e(ColorReplaceEffect, "material", new Material({
7834
+ vert: `precision mediump float;
7835
+ attribute vec2 position;
7836
+ attribute vec2 uv;
7837
+ varying vec2 vUv;
7838
+ void main() {
7839
+ gl_Position = vec4(position, 0.0, 1.0);
7840
+ vUv = uv;
7841
+ }`,
7842
+ frag: `varying vec2 vUv;
7843
+ uniform sampler2D sampler;
7844
+ uniform float epsilon;
7845
+ const int MAX_COLORS = ${MAX_COLORS};
7846
+ uniform vec3 originalColors[MAX_COLORS];
7847
+ uniform vec3 targetColors[MAX_COLORS];
7645
7848
 
7646
- var __defProp$x = Object.defineProperty;
7647
- var __getOwnPropDesc$w = Object.getOwnPropertyDescriptor;
7648
- var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$x(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7649
- var __decorateClass$E = (decorators, target, key, kind) => {
7650
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$w(target, key) : target;
7849
+ void main(void) {
7850
+ gl_FragColor = texture2D(sampler, vUv);
7851
+
7852
+ float alpha = gl_FragColor.a;
7853
+ if (alpha < 0.0001) {
7854
+ return;
7855
+ }
7856
+
7857
+ vec3 color = gl_FragColor.rgb / alpha;
7858
+
7859
+ for(int i = 0; i < MAX_COLORS; i++) {
7860
+ vec3 origColor = originalColors[i];
7861
+ if (origColor.r < 0.0) {
7862
+ break;
7863
+ }
7864
+ vec3 colorDiff = origColor - color;
7865
+ if (length(colorDiff) < epsilon) {
7866
+ vec3 targetColor = targetColors[i];
7867
+ gl_FragColor = vec4((targetColor + colorDiff) * alpha, alpha);
7868
+ return;
7869
+ }
7870
+ }
7871
+ }`
7872
+ }));
7873
+ __decorateClass$D([
7874
+ property()
7875
+ ], ColorReplaceEffect.prototype, "colors", 2);
7876
+ __decorateClass$D([
7877
+ property()
7878
+ ], ColorReplaceEffect.prototype, "epsilon", 2);
7879
+ ColorReplaceEffect = __decorateClass$D([
7880
+ customNode("ColorReplaceEffect")
7881
+ ], ColorReplaceEffect);
7882
+
7883
+ var __defProp$v = Object.defineProperty;
7884
+ var __getOwnPropDesc$u = Object.getOwnPropertyDescriptor;
7885
+ var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$v(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7886
+ var __decorateClass$C = (decorators, target, key, kind) => {
7887
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$u(target, key) : target;
7651
7888
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
7652
7889
  if (decorator = decorators[i])
7653
7890
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
7654
- if (kind && result) __defProp$x(target, key, result);
7891
+ if (kind && result) __defProp$v(target, key, result);
7655
7892
  return result;
7656
7893
  };
7657
7894
  var __publicField$d = (obj, key, value) => __defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
@@ -7757,25 +7994,25 @@ void main(void) {
7757
7994
  }`,
7758
7995
  frag: frag$2
7759
7996
  }));
7760
- __decorateClass$E([
7997
+ __decorateClass$C([
7761
7998
  property({ default: 4 })
7762
7999
  ], GaussianBlurEffect.prototype, "strength", 2);
7763
- __decorateClass$E([
8000
+ __decorateClass$C([
7764
8001
  property({ default: 3 })
7765
8002
  ], GaussianBlurEffect.prototype, "quality", 2);
7766
- GaussianBlurEffect = __decorateClass$E([
8003
+ GaussianBlurEffect = __decorateClass$C([
7767
8004
  customNode("GaussianBlurEffect")
7768
8005
  ], GaussianBlurEffect);
7769
8006
 
7770
- var __defProp$w = Object.defineProperty;
7771
- var __getOwnPropDesc$v = Object.getOwnPropertyDescriptor;
7772
- var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$w(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7773
- var __decorateClass$D = (decorators, target, key, kind) => {
7774
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$v(target, key) : target;
8007
+ var __defProp$u = Object.defineProperty;
8008
+ var __getOwnPropDesc$t = Object.getOwnPropertyDescriptor;
8009
+ var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$u(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8010
+ var __decorateClass$B = (decorators, target, key, kind) => {
8011
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$t(target, key) : target;
7775
8012
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
7776
8013
  if (decorator = decorators[i])
7777
8014
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
7778
- if (kind && result) __defProp$w(target, key, result);
8015
+ if (kind && result) __defProp$u(target, key, result);
7779
8016
  return result;
7780
8017
  };
7781
8018
  var __publicField$c = (obj, key, value) => __defNormalProp$c(obj, key + "" , value);
@@ -7839,34 +8076,34 @@ void main(void) {
7839
8076
  gl_FragColor = sample;
7840
8077
  }`
7841
8078
  }));
7842
- __decorateClass$D([
8079
+ __decorateClass$B([
7843
8080
  property()
7844
8081
  ], DropShadowEffect.prototype, "color", 2);
7845
- __decorateClass$D([
8082
+ __decorateClass$B([
7846
8083
  property()
7847
8084
  ], DropShadowEffect.prototype, "blur", 2);
7848
- __decorateClass$D([
8085
+ __decorateClass$B([
7849
8086
  property()
7850
8087
  ], DropShadowEffect.prototype, "offsetX", 2);
7851
- __decorateClass$D([
8088
+ __decorateClass$B([
7852
8089
  property()
7853
8090
  ], DropShadowEffect.prototype, "offsetY", 2);
7854
- __decorateClass$D([
8091
+ __decorateClass$B([
7855
8092
  property()
7856
8093
  ], DropShadowEffect.prototype, "shadowOnly", 2);
7857
- DropShadowEffect = __decorateClass$D([
8094
+ DropShadowEffect = __decorateClass$B([
7858
8095
  customNode("DropShadowEffect")
7859
8096
  ], DropShadowEffect);
7860
8097
 
7861
- var __defProp$v = Object.defineProperty;
7862
- var __getOwnPropDesc$u = Object.getOwnPropertyDescriptor;
7863
- var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$v(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7864
- var __decorateClass$C = (decorators, target, key, kind) => {
7865
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$u(target, key) : target;
8098
+ var __defProp$t = Object.defineProperty;
8099
+ var __getOwnPropDesc$s = Object.getOwnPropertyDescriptor;
8100
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$t(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8101
+ var __decorateClass$A = (decorators, target, key, kind) => {
8102
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$s(target, key) : target;
7866
8103
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
7867
8104
  if (decorator = decorators[i])
7868
8105
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
7869
- if (kind && result) __defProp$v(target, key, result);
8106
+ if (kind && result) __defProp$t(target, key, result);
7870
8107
  return result;
7871
8108
  };
7872
8109
  var __publicField$b = (obj, key, value) => __defNormalProp$b(obj, key + "" , value);
@@ -7911,22 +8148,22 @@ void main(void) {
7911
8148
  gl_FragColor = vec4(color.rgb * alpha, alpha);
7912
8149
  }`
7913
8150
  }));
7914
- __decorateClass$C([
8151
+ __decorateClass$A([
7915
8152
  property()
7916
8153
  ], EmbossEffect.prototype, "strength", 2);
7917
- EmbossEffect = __decorateClass$C([
8154
+ EmbossEffect = __decorateClass$A([
7918
8155
  customNode("EmbossEffect")
7919
8156
  ], EmbossEffect);
7920
8157
 
7921
- var __defProp$u = Object.defineProperty;
7922
- var __getOwnPropDesc$t = Object.getOwnPropertyDescriptor;
7923
- var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$u(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7924
- var __decorateClass$B = (decorators, target, key, kind) => {
7925
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$t(target, key) : target;
8158
+ var __defProp$s = Object.defineProperty;
8159
+ var __getOwnPropDesc$r = Object.getOwnPropertyDescriptor;
8160
+ var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$s(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8161
+ var __decorateClass$z = (decorators, target, key, kind) => {
8162
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$r(target, key) : target;
7926
8163
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
7927
8164
  if (decorator = decorators[i])
7928
8165
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
7929
- if (kind && result) __defProp$u(target, key, result);
8166
+ if (kind && result) __defProp$s(target, key, result);
7930
8167
  return result;
7931
8168
  };
7932
8169
  var __publicField$a = (obj, key, value) => __defNormalProp$a(obj, key + "" , value);
@@ -8100,46 +8337,46 @@ void main(void) {
8100
8337
  gl_FragColor.a = texture2D(sampler, coord).a;
8101
8338
  }`
8102
8339
  }));
8103
- __decorateClass$B([
8340
+ __decorateClass$z([
8104
8341
  property()
8105
8342
  ], GlitchEffect.prototype, "slices", 2);
8106
- __decorateClass$B([
8343
+ __decorateClass$z([
8107
8344
  property()
8108
8345
  ], GlitchEffect.prototype, "sampleSize", 2);
8109
- __decorateClass$B([
8346
+ __decorateClass$z([
8110
8347
  property()
8111
8348
  ], GlitchEffect.prototype, "offset", 2);
8112
- __decorateClass$B([
8349
+ __decorateClass$z([
8113
8350
  property()
8114
8351
  ], GlitchEffect.prototype, "direction", 2);
8115
- __decorateClass$B([
8352
+ __decorateClass$z([
8116
8353
  property()
8117
8354
  ], GlitchEffect.prototype, "fillMode", 2);
8118
- __decorateClass$B([
8355
+ __decorateClass$z([
8119
8356
  property()
8120
8357
  ], GlitchEffect.prototype, "seed", 2);
8121
- __decorateClass$B([
8358
+ __decorateClass$z([
8122
8359
  property()
8123
8360
  ], GlitchEffect.prototype, "red", 2);
8124
- __decorateClass$B([
8361
+ __decorateClass$z([
8125
8362
  property()
8126
8363
  ], GlitchEffect.prototype, "green", 2);
8127
- __decorateClass$B([
8364
+ __decorateClass$z([
8128
8365
  property()
8129
8366
  ], GlitchEffect.prototype, "blue", 2);
8130
- GlitchEffect = __decorateClass$B([
8367
+ GlitchEffect = __decorateClass$z([
8131
8368
  customNode("GlitchEffect")
8132
8369
  ], GlitchEffect);
8133
8370
 
8134
- var __defProp$t = Object.defineProperty;
8135
- var __getOwnPropDesc$s = Object.getOwnPropertyDescriptor;
8136
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$t(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8137
- var __decorateClass$A = (decorators, target, key, kind) => {
8138
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$s(target, key) : target;
8371
+ var __defProp$r = Object.defineProperty;
8372
+ var __getOwnPropDesc$q = Object.getOwnPropertyDescriptor;
8373
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$r(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8374
+ var __decorateClass$y = (decorators, target, key, kind) => {
8375
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$q(target, key) : target;
8139
8376
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
8140
8377
  if (decorator = decorators[i])
8141
8378
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8142
- if (kind && result) __defProp$t(target, key, result);
8379
+ if (kind && result) __defProp$r(target, key, result);
8143
8380
  return result;
8144
8381
  };
8145
8382
  var __publicField$9 = (obj, key, value) => __defNormalProp$9(obj, key + "" , value);
@@ -8317,39 +8554,39 @@ void main(void) {
8317
8554
  gl_FragColor = vec4(color.rgb + mist.rgb, color.a);
8318
8555
  }`
8319
8556
  }));
8320
- __decorateClass$A([
8557
+ __decorateClass$y([
8321
8558
  property()
8322
8559
  ], GodrayEffect.prototype, "time", 2);
8323
- __decorateClass$A([
8560
+ __decorateClass$y([
8324
8561
  property()
8325
8562
  ], GodrayEffect.prototype, "angle", 2);
8326
- __decorateClass$A([
8563
+ __decorateClass$y([
8327
8564
  property()
8328
8565
  ], GodrayEffect.prototype, "gain", 2);
8329
- __decorateClass$A([
8566
+ __decorateClass$y([
8330
8567
  property()
8331
8568
  ], GodrayEffect.prototype, "lacunarity", 2);
8332
- __decorateClass$A([
8569
+ __decorateClass$y([
8333
8570
  property()
8334
8571
  ], GodrayEffect.prototype, "parallel", 2);
8335
- __decorateClass$A([
8572
+ __decorateClass$y([
8336
8573
  property()
8337
8574
  ], GodrayEffect.prototype, "center", 2);
8338
- __decorateClass$A([
8575
+ __decorateClass$y([
8339
8576
  property()
8340
8577
  ], GodrayEffect.prototype, "alpha", 2);
8341
- GodrayEffect = __decorateClass$A([
8578
+ GodrayEffect = __decorateClass$y([
8342
8579
  customNode("GodrayEffect")
8343
8580
  ], GodrayEffect);
8344
8581
 
8345
- var __defProp$s = Object.defineProperty;
8346
- var __getOwnPropDesc$r = Object.getOwnPropertyDescriptor;
8347
- var __decorateClass$z = (decorators, target, key, kind) => {
8348
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$r(target, key) : target;
8582
+ var __defProp$q = Object.defineProperty;
8583
+ var __getOwnPropDesc$p = Object.getOwnPropertyDescriptor;
8584
+ var __decorateClass$x = (decorators, target, key, kind) => {
8585
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$p(target, key) : target;
8349
8586
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
8350
8587
  if (decorator = decorators[i])
8351
8588
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8352
- if (kind && result) __defProp$s(target, key, result);
8589
+ if (kind && result) __defProp$q(target, key, result);
8353
8590
  return result;
8354
8591
  };
8355
8592
  const frag$1 = `varying vec2 vUv;
@@ -8439,28 +8676,28 @@ void main() {
8439
8676
  });
8440
8677
  }
8441
8678
  };
8442
- __decorateClass$z([
8679
+ __decorateClass$x([
8443
8680
  property()
8444
8681
  ], KawaseBlurEffect.prototype, "strength", 2);
8445
- __decorateClass$z([
8682
+ __decorateClass$x([
8446
8683
  property()
8447
8684
  ], KawaseBlurEffect.prototype, "quality", 2);
8448
- __decorateClass$z([
8685
+ __decorateClass$x([
8449
8686
  property()
8450
8687
  ], KawaseBlurEffect.prototype, "pixelSize", 2);
8451
- KawaseBlurEffect = __decorateClass$z([
8688
+ KawaseBlurEffect = __decorateClass$x([
8452
8689
  customNode("KawaseBlurEffect")
8453
8690
  ], KawaseBlurEffect);
8454
8691
 
8455
- var __defProp$r = Object.defineProperty;
8456
- var __getOwnPropDesc$q = Object.getOwnPropertyDescriptor;
8457
- var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$r(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8458
- var __decorateClass$y = (decorators, target, key, kind) => {
8459
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$q(target, key) : target;
8692
+ var __defProp$p = Object.defineProperty;
8693
+ var __getOwnPropDesc$o = Object.getOwnPropertyDescriptor;
8694
+ var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$p(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8695
+ var __decorateClass$w = (decorators, target, key, kind) => {
8696
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$o(target, key) : target;
8460
8697
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
8461
8698
  if (decorator = decorators[i])
8462
8699
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8463
- if (kind && result) __defProp$r(target, key, result);
8700
+ if (kind && result) __defProp$p(target, key, result);
8464
8701
  return result;
8465
8702
  };
8466
8703
  var __publicField$8 = (obj, key, value) => __defNormalProp$8(obj, key + "" , value);
@@ -8548,25 +8785,25 @@ void main(void) {
8548
8785
  }
8549
8786
  }`
8550
8787
  }));
8551
- __decorateClass$y([
8788
+ __decorateClass$w([
8552
8789
  property({ protected: true })
8553
8790
  ], MaskEffect.prototype, "texture", 2);
8554
- __decorateClass$y([
8791
+ __decorateClass$w([
8555
8792
  property({ default: "" })
8556
8793
  ], MaskEffect.prototype, "src", 2);
8557
- MaskEffect = __decorateClass$y([
8794
+ MaskEffect = __decorateClass$w([
8558
8795
  customNode("MaskEffect")
8559
8796
  ], MaskEffect);
8560
8797
 
8561
- var __defProp$q = Object.defineProperty;
8562
- var __getOwnPropDesc$p = Object.getOwnPropertyDescriptor;
8563
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$q(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8564
- var __decorateClass$x = (decorators, target, key, kind) => {
8565
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$p(target, key) : target;
8798
+ var __defProp$o = Object.defineProperty;
8799
+ var __getOwnPropDesc$n = Object.getOwnPropertyDescriptor;
8800
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$o(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8801
+ var __decorateClass$v = (decorators, target, key, kind) => {
8802
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$n(target, key) : target;
8566
8803
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
8567
8804
  if (decorator = decorators[i])
8568
8805
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8569
- if (kind && result) __defProp$q(target, key, result);
8806
+ if (kind && result) __defProp$o(target, key, result);
8570
8807
  return result;
8571
8808
  };
8572
8809
  var __publicField$7 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
@@ -8653,40 +8890,40 @@ void main() {
8653
8890
  };
8654
8891
  __publicField$7(OutlineEffect, "MIN_SAMPLES", 1);
8655
8892
  __publicField$7(OutlineEffect, "MAX_SAMPLES", 100);
8656
- __decorateClass$x([
8893
+ __decorateClass$v([
8657
8894
  property()
8658
8895
  ], OutlineEffect.prototype, "color", 2);
8659
- __decorateClass$x([
8896
+ __decorateClass$v([
8660
8897
  property()
8661
8898
  ], OutlineEffect.prototype, "width", 2);
8662
- __decorateClass$x([
8899
+ __decorateClass$v([
8663
8900
  property()
8664
8901
  ], OutlineEffect.prototype, "style", 2);
8665
- __decorateClass$x([
8902
+ __decorateClass$v([
8666
8903
  property()
8667
8904
  ], OutlineEffect.prototype, "image", 2);
8668
- __decorateClass$x([
8905
+ __decorateClass$v([
8669
8906
  property()
8670
8907
  ], OutlineEffect.prototype, "opacity", 2);
8671
- __decorateClass$x([
8908
+ __decorateClass$v([
8672
8909
  property()
8673
8910
  ], OutlineEffect.prototype, "quality", 2);
8674
- __decorateClass$x([
8911
+ __decorateClass$v([
8675
8912
  property()
8676
8913
  ], OutlineEffect.prototype, "knockout", 2);
8677
- OutlineEffect = __decorateClass$x([
8914
+ OutlineEffect = __decorateClass$v([
8678
8915
  customNode("OutlineEffect")
8679
8916
  ], OutlineEffect);
8680
8917
 
8681
- var __defProp$p = Object.defineProperty;
8682
- var __getOwnPropDesc$o = Object.getOwnPropertyDescriptor;
8683
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$p(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8684
- var __decorateClass$w = (decorators, target, key, kind) => {
8685
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$o(target, key) : target;
8918
+ var __defProp$n = Object.defineProperty;
8919
+ var __getOwnPropDesc$m = Object.getOwnPropertyDescriptor;
8920
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$n(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8921
+ var __decorateClass$u = (decorators, target, key, kind) => {
8922
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$m(target, key) : target;
8686
8923
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
8687
8924
  if (decorator = decorators[i])
8688
8925
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8689
- if (kind && result) __defProp$p(target, key, result);
8926
+ if (kind && result) __defProp$n(target, key, result);
8690
8927
  return result;
8691
8928
  };
8692
8929
  var __publicField$6 = (obj, key, value) => __defNormalProp$6(obj, key + "" , value);
@@ -8742,22 +8979,22 @@ void main(void) {
8742
8979
  gl_FragColor = texture2D(sampler, coord);
8743
8980
  }`
8744
8981
  }));
8745
- __decorateClass$w([
8982
+ __decorateClass$u([
8746
8983
  property()
8747
8984
  ], PixelateEffect.prototype, "strength", 2);
8748
- PixelateEffect = __decorateClass$w([
8985
+ PixelateEffect = __decorateClass$u([
8749
8986
  customNode("PixelateEffect")
8750
8987
  ], PixelateEffect);
8751
8988
 
8752
- var __defProp$o = Object.defineProperty;
8753
- var __getOwnPropDesc$n = Object.getOwnPropertyDescriptor;
8754
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$o(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8755
- var __decorateClass$v = (decorators, target, key, kind) => {
8756
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$n(target, key) : target;
8989
+ var __defProp$m = Object.defineProperty;
8990
+ var __getOwnPropDesc$l = Object.getOwnPropertyDescriptor;
8991
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$m(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8992
+ var __decorateClass$t = (decorators, target, key, kind) => {
8993
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$l(target, key) : target;
8757
8994
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
8758
8995
  if (decorator = decorators[i])
8759
8996
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8760
- if (kind && result) __defProp$o(target, key, result);
8997
+ if (kind && result) __defProp$m(target, key, result);
8761
8998
  return result;
8762
8999
  };
8763
9000
  var __publicField$5 = (obj, key, value) => __defNormalProp$5(obj, key + "" , value);
@@ -8870,29 +9107,29 @@ void main() {
8870
9107
  gl_FragColor = color;
8871
9108
  }`
8872
9109
  }));
8873
- __decorateClass$v([
9110
+ __decorateClass$t([
8874
9111
  property()
8875
9112
  ], ZoomBlurEffect.prototype, "center", 2);
8876
- __decorateClass$v([
9113
+ __decorateClass$t([
8877
9114
  property()
8878
9115
  ], ZoomBlurEffect.prototype, "innerRadius", 2);
8879
- __decorateClass$v([
9116
+ __decorateClass$t([
8880
9117
  property()
8881
9118
  ], ZoomBlurEffect.prototype, "radius", 2);
8882
- __decorateClass$v([
9119
+ __decorateClass$t([
8883
9120
  property()
8884
9121
  ], ZoomBlurEffect.prototype, "strength", 2);
8885
- ZoomBlurEffect = __decorateClass$v([
9122
+ ZoomBlurEffect = __decorateClass$t([
8886
9123
  customNode("ZoomBlurEffect")
8887
9124
  ], ZoomBlurEffect);
8888
9125
 
8889
- var __defProp$n = Object.defineProperty;
8890
- var __decorateClass$u = (decorators, target, key, kind) => {
9126
+ var __defProp$l = Object.defineProperty;
9127
+ var __decorateClass$s = (decorators, target, key, kind) => {
8891
9128
  var result = void 0 ;
8892
9129
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
8893
9130
  if (decorator = decorators[i])
8894
9131
  result = (decorator(target, key, result) ) || result;
8895
- if (result) __defProp$n(target, key, result);
9132
+ if (result) __defProp$l(target, key, result);
8896
9133
  return result;
8897
9134
  };
8898
9135
  class BaseElement2DFill extends CoreObject {
@@ -9000,47 +9237,47 @@ class BaseElement2DFill extends CoreObject {
9000
9237
  });
9001
9238
  }
9002
9239
  }
9003
- __decorateClass$u([
9240
+ __decorateClass$s([
9004
9241
  property({ fallback: true })
9005
9242
  ], BaseElement2DFill.prototype, "enabled");
9006
- __decorateClass$u([
9243
+ __decorateClass$s([
9007
9244
  property()
9008
9245
  ], BaseElement2DFill.prototype, "color");
9009
- __decorateClass$u([
9246
+ __decorateClass$s([
9010
9247
  property()
9011
9248
  ], BaseElement2DFill.prototype, "image");
9012
- __decorateClass$u([
9249
+ __decorateClass$s([
9013
9250
  property()
9014
9251
  ], BaseElement2DFill.prototype, "linearGradient");
9015
- __decorateClass$u([
9252
+ __decorateClass$s([
9016
9253
  property()
9017
9254
  ], BaseElement2DFill.prototype, "radialGradient");
9018
- __decorateClass$u([
9255
+ __decorateClass$s([
9019
9256
  property()
9020
9257
  ], BaseElement2DFill.prototype, "cropRect");
9021
- __decorateClass$u([
9258
+ __decorateClass$s([
9022
9259
  property()
9023
9260
  ], BaseElement2DFill.prototype, "stretchRect");
9024
- __decorateClass$u([
9261
+ __decorateClass$s([
9025
9262
  property()
9026
9263
  ], BaseElement2DFill.prototype, "dpi");
9027
- __decorateClass$u([
9264
+ __decorateClass$s([
9028
9265
  property()
9029
9266
  ], BaseElement2DFill.prototype, "rotateWithShape");
9030
- __decorateClass$u([
9267
+ __decorateClass$s([
9031
9268
  property()
9032
9269
  ], BaseElement2DFill.prototype, "tile");
9033
- __decorateClass$u([
9270
+ __decorateClass$s([
9034
9271
  property()
9035
9272
  ], BaseElement2DFill.prototype, "opacity");
9036
9273
 
9037
- var __defProp$m = Object.defineProperty;
9038
- var __decorateClass$t = (decorators, target, key, kind) => {
9274
+ var __defProp$k = Object.defineProperty;
9275
+ var __decorateClass$r = (decorators, target, key, kind) => {
9039
9276
  var result = void 0 ;
9040
9277
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
9041
9278
  if (decorator = decorators[i])
9042
9279
  result = (decorator(target, key, result) ) || result;
9043
- if (result) __defProp$m(target, key, result);
9280
+ if (result) __defProp$k(target, key, result);
9044
9281
  return result;
9045
9282
  };
9046
9283
  class BaseElement2DBackground extends BaseElement2DFill {
@@ -9050,17 +9287,17 @@ class BaseElement2DBackground extends BaseElement2DFill {
9050
9287
  );
9051
9288
  }
9052
9289
  }
9053
- __decorateClass$t([
9290
+ __decorateClass$r([
9054
9291
  property()
9055
9292
  ], BaseElement2DBackground.prototype, "fillWithShape");
9056
9293
 
9057
- var __defProp$l = Object.defineProperty;
9058
- var __decorateClass$s = (decorators, target, key, kind) => {
9294
+ var __defProp$j = Object.defineProperty;
9295
+ var __decorateClass$q = (decorators, target, key, kind) => {
9059
9296
  var result = void 0 ;
9060
9297
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
9061
9298
  if (decorator = decorators[i])
9062
9299
  result = (decorator(target, key, result) ) || result;
9063
- if (result) __defProp$l(target, key, result);
9300
+ if (result) __defProp$j(target, key, result);
9064
9301
  return result;
9065
9302
  };
9066
9303
  class BaseElement2DForeground extends BaseElement2DFill {
@@ -9070,17 +9307,17 @@ class BaseElement2DForeground extends BaseElement2DFill {
9070
9307
  );
9071
9308
  }
9072
9309
  }
9073
- __decorateClass$s([
9310
+ __decorateClass$q([
9074
9311
  property()
9075
9312
  ], BaseElement2DForeground.prototype, "fillWithShape");
9076
9313
 
9077
- var __defProp$k = Object.defineProperty;
9078
- var __decorateClass$r = (decorators, target, key, kind) => {
9314
+ var __defProp$i = Object.defineProperty;
9315
+ var __decorateClass$p = (decorators, target, key, kind) => {
9079
9316
  var result = void 0 ;
9080
9317
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
9081
9318
  if (decorator = decorators[i])
9082
9319
  result = (decorator(target, key, result) ) || result;
9083
- if (result) __defProp$k(target, key, result);
9320
+ if (result) __defProp$i(target, key, result);
9084
9321
  return result;
9085
9322
  };
9086
9323
  class BaseElement2DOutline extends BaseElement2DFill {
@@ -9113,23 +9350,23 @@ class BaseElement2DOutline extends BaseElement2DFill {
9113
9350
  ctx.stroke({ disableWrapMode });
9114
9351
  }
9115
9352
  }
9116
- __decorateClass$r([
9353
+ __decorateClass$p([
9117
9354
  property({ fallback: "#00000000" })
9118
9355
  ], BaseElement2DOutline.prototype, "color");
9119
- __decorateClass$r([
9356
+ __decorateClass$p([
9120
9357
  property({ fallback: 0 })
9121
9358
  ], BaseElement2DOutline.prototype, "width");
9122
- __decorateClass$r([
9359
+ __decorateClass$p([
9123
9360
  property({ fallback: "solid" })
9124
9361
  ], BaseElement2DOutline.prototype, "style");
9125
9362
 
9126
- var __defProp$j = Object.defineProperty;
9127
- var __decorateClass$q = (decorators, target, key, kind) => {
9363
+ var __defProp$h = Object.defineProperty;
9364
+ var __decorateClass$o = (decorators, target, key, kind) => {
9128
9365
  var result = void 0 ;
9129
9366
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
9130
9367
  if (decorator = decorators[i])
9131
9368
  result = (decorator(target, key, result) ) || result;
9132
- if (result) __defProp$j(target, key, result);
9369
+ if (result) __defProp$h(target, key, result);
9133
9370
  return result;
9134
9371
  };
9135
9372
  class BaseElement2DShadow extends CoreObject {
@@ -9169,29 +9406,29 @@ class BaseElement2DShadow extends CoreObject {
9169
9406
  }
9170
9407
  }
9171
9408
  }
9172
- __decorateClass$q([
9409
+ __decorateClass$o([
9173
9410
  property({ fallback: true })
9174
9411
  ], BaseElement2DShadow.prototype, "enabled");
9175
- __decorateClass$q([
9412
+ __decorateClass$o([
9176
9413
  property({ fallback: "#000000FF" })
9177
9414
  ], BaseElement2DShadow.prototype, "color");
9178
- __decorateClass$q([
9415
+ __decorateClass$o([
9179
9416
  property({ fallback: 0 })
9180
9417
  ], BaseElement2DShadow.prototype, "blur");
9181
- __decorateClass$q([
9418
+ __decorateClass$o([
9182
9419
  property({ fallback: 0 })
9183
9420
  ], BaseElement2DShadow.prototype, "offsetY");
9184
- __decorateClass$q([
9421
+ __decorateClass$o([
9185
9422
  property({ fallback: 0 })
9186
9423
  ], BaseElement2DShadow.prototype, "offsetX");
9187
9424
 
9188
- var __defProp$i = Object.defineProperty;
9189
- var __decorateClass$p = (decorators, target, key, kind) => {
9425
+ var __defProp$g = Object.defineProperty;
9426
+ var __decorateClass$n = (decorators, target, key, kind) => {
9190
9427
  var result = void 0 ;
9191
9428
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
9192
9429
  if (decorator = decorators[i])
9193
9430
  result = (decorator(target, key, result) ) || result;
9194
- if (result) __defProp$i(target, key, result);
9431
+ if (result) __defProp$g(target, key, result);
9195
9432
  return result;
9196
9433
  };
9197
9434
  class BaseElement2DShape extends CoreObject {
@@ -9266,19 +9503,19 @@ class BaseElement2DShape extends CoreObject {
9266
9503
  }
9267
9504
  }
9268
9505
  }
9269
- __decorateClass$p([
9506
+ __decorateClass$n([
9270
9507
  property({ fallback: true })
9271
9508
  ], BaseElement2DShape.prototype, "enabled");
9272
- __decorateClass$p([
9509
+ __decorateClass$n([
9273
9510
  property()
9274
9511
  ], BaseElement2DShape.prototype, "preset");
9275
- __decorateClass$p([
9512
+ __decorateClass$n([
9276
9513
  property()
9277
9514
  ], BaseElement2DShape.prototype, "svg");
9278
- __decorateClass$p([
9515
+ __decorateClass$n([
9279
9516
  property()
9280
9517
  ], BaseElement2DShape.prototype, "viewBox");
9281
- __decorateClass$p([
9518
+ __decorateClass$n([
9282
9519
  property()
9283
9520
  ], BaseElement2DShape.prototype, "paths");
9284
9521
 
@@ -9294,13 +9531,13 @@ for (const key in defaultStyles$1) {
9294
9531
  defineProperty(BaseElement2DStyle, key, { fallback });
9295
9532
  }
9296
9533
 
9297
- var __defProp$h = Object.defineProperty;
9298
- var __decorateClass$o = (decorators, target, key, kind) => {
9534
+ var __defProp$f = Object.defineProperty;
9535
+ var __decorateClass$m = (decorators, target, key, kind) => {
9299
9536
  var result = void 0 ;
9300
9537
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
9301
9538
  if (decorator = decorators[i])
9302
9539
  result = (decorator(target, key, result) ) || result;
9303
- if (result) __defProp$h(target, key, result);
9540
+ if (result) __defProp$f(target, key, result);
9304
9541
  return result;
9305
9542
  };
9306
9543
  class BaseElement2DText extends CoreObject {
@@ -9348,180 +9585,60 @@ class BaseElement2DText extends CoreObject {
9348
9585
  textAlign: "center",
9349
9586
  ...this.parent.style.toJSON()
9350
9587
  };
9351
- this.base.requestUpdate();
9352
- }
9353
- measure() {
9354
- this._updateText();
9355
- return this.base.measure();
9356
- }
9357
- updateMeasure() {
9358
- this.measureResult = this.measure();
9359
- return this;
9360
- }
9361
- canDraw() {
9362
- return Boolean(
9363
- this.enabled && !/^\s*$/.test(this.base.toString())
9364
- );
9365
- }
9366
- draw() {
9367
- const ctx = this.parent.context;
9368
- this.base.update();
9369
- this.base.pathSets.forEach((pathSet) => {
9370
- pathSet.paths.forEach((path) => {
9371
- ctx.addPath(path);
9372
- ctx.style = { ...path.style };
9373
- ctx.fillStyle = void 0;
9374
- ctx.strokeStyle = void 0;
9375
- ctx.fill();
9376
- });
9377
- });
9378
- }
9379
- }
9380
- __decorateClass$o([
9381
- property({ fallback: true })
9382
- ], BaseElement2DText.prototype, "enabled");
9383
- __decorateClass$o([
9384
- property({ alias: "base.content", fallback: () => [] })
9385
- ], BaseElement2DText.prototype, "content");
9386
- __decorateClass$o([
9387
- property({ alias: "base.effects" })
9388
- ], BaseElement2DText.prototype, "effects");
9389
- __decorateClass$o([
9390
- property({ alias: "base.fill" })
9391
- ], BaseElement2DText.prototype, "fill");
9392
- __decorateClass$o([
9393
- property({ alias: "base.outline" })
9394
- ], BaseElement2DText.prototype, "outline");
9395
- __decorateClass$o([
9396
- property({ protected: true, alias: "base.measureDom" })
9397
- ], BaseElement2DText.prototype, "measureDom");
9398
- __decorateClass$o([
9399
- property({ protected: true, alias: "base.fonts" })
9400
- ], BaseElement2DText.prototype, "fonts");
9401
-
9402
- var __defProp$g = Object.defineProperty;
9403
- var __getOwnPropDesc$m = Object.getOwnPropertyDescriptor;
9404
- var __decorateClass$n = (decorators, target, key, kind) => {
9405
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$m(target, key) : target;
9406
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
9407
- if (decorator = decorators[i])
9408
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
9409
- if (kind && result) __defProp$g(target, key, result);
9410
- return result;
9411
- };
9412
- let Node2D = class extends CanvasItem {
9413
- position = new Vector2().on("update", () => this.updateGlobalTransform());
9414
- scale = new Vector2(1, 1).on("update", () => this.updateGlobalTransform());
9415
- skew = new Vector2().on("update", () => this.updateGlobalTransform());
9416
- transform = new Transform2D();
9417
- globalPosition = new Vector2();
9418
- globalScale = new Vector2();
9419
- globalSkew = new Vector2();
9420
- globalTransform = new Transform2D();
9421
- _parentTransformDirtyId;
9422
- constructor(properties, nodes = []) {
9423
- super();
9424
- this.setProperties(properties).append(nodes);
9425
- }
9426
- _updateProperty(key, value, oldValue, declaration) {
9427
- super._updateProperty(key, value, oldValue, declaration);
9428
- switch (key) {
9429
- case "rotation":
9430
- this.requestRelayout();
9431
- break;
9432
- }
9433
- }
9434
- getTransformOrigin() {
9435
- return new Vector2(0, 0);
9436
- }
9437
- getTransform(cb) {
9438
- const origin = this.getTransformOrigin();
9439
- const transform = new Transform2D();
9440
- transform.translate(-origin.x, -origin.y).scale(this.scale.x, this.scale.y).skew(this.skew.x, this.skew.y).rotate(this.rotation);
9441
- cb?.(transform);
9442
- transform.translate(this.position.x, this.position.y).translate(origin.x, origin.y);
9443
- return transform;
9588
+ this.base.requestUpdate();
9444
9589
  }
9445
- updateTransform() {
9446
- this.transform.copy(this.getTransform());
9590
+ measure() {
9591
+ this._updateText();
9592
+ return this.base.measure();
9447
9593
  }
9448
- updateGlobalTransform() {
9449
- this.updateTransform();
9450
- const parent = this.getParent();
9451
- if (parent?.globalTransform) {
9452
- this._parentTransformDirtyId = parent.globalTransform.dirtyId;
9453
- this.globalScale.set(parent.globalScale.x * this.scale.x, parent.globalScale.y * this.scale.y);
9454
- this.globalRotation = parent.globalRotation + this.rotation;
9455
- parent.globalTransform.multiply(this.transform, this.globalTransform);
9456
- } else {
9457
- this.globalScale.copy(this.scale);
9458
- this.globalRotation = this.rotation;
9459
- this.globalTransform.copy(this.transform);
9460
- }
9461
- const [
9462
- a,
9463
- c,
9464
- tx,
9465
- b,
9466
- d,
9467
- ty
9468
- ] = this.globalTransform.toArray();
9469
- this.globalPosition.set(tx, ty);
9470
- this.globalSkew.x = Math.atan2(c, a) - this.globalRotation;
9471
- this.globalSkew.y = Math.atan2(b, d) - this.globalRotation;
9472
- this.requestRelayout();
9594
+ updateMeasure() {
9595
+ this.measureResult = this.measure();
9596
+ return this;
9473
9597
  }
9474
- _transformVertices(vertices, vertTransform) {
9475
- let a, c, tx, b, d, ty;
9476
- if (vertTransform) {
9477
- const globalTransform = this.globalTransform.clone();
9478
- globalTransform.multiply(
9479
- typeof vertTransform === "function" ? vertTransform?.() : vertTransform
9480
- );
9481
- [a, c, tx, b, d, ty] = globalTransform.toArray();
9482
- } else {
9483
- [a, c, tx, b, d, ty] = this.globalTransform.toArray();
9484
- }
9485
- const newVertices = vertices.slice();
9486
- for (let len = vertices.length, i = 0; i < len; i += 2) {
9487
- const x = vertices[i];
9488
- const y = vertices[i + 1];
9489
- newVertices[i] = a * x + c * y + tx;
9490
- newVertices[i + 1] = b * x + d * y + ty;
9491
- }
9492
- return newVertices;
9598
+ canDraw() {
9599
+ return Boolean(
9600
+ this.enabled && !/^\s*$/.test(this.base.toString())
9601
+ );
9493
9602
  }
9494
- _relayout(batchables) {
9495
- batchables = super._relayout(batchables);
9496
- this.updateGlobalTransform();
9497
- return batchables.map((batchable) => {
9498
- return {
9499
- ...batchable,
9500
- vertices: this._transformVertices(batchable.vertices, batchable.vertTransform)
9501
- };
9603
+ draw() {
9604
+ const ctx = this.parent.context;
9605
+ this.base.update();
9606
+ this.base.pathSets.forEach((pathSet) => {
9607
+ pathSet.paths.forEach((path) => {
9608
+ ctx.addPath(path);
9609
+ ctx.style = { ...path.style };
9610
+ ctx.fillStyle = void 0;
9611
+ ctx.strokeStyle = void 0;
9612
+ ctx.fill();
9613
+ });
9502
9614
  });
9503
9615
  }
9504
- _process(delta) {
9505
- super._process(delta);
9506
- const parent = this.getParent();
9507
- if (parent?.globalTransform && this._parentTransformDirtyId !== parent?.globalTransform?.dirtyId) {
9508
- this.requestRelayout();
9509
- }
9510
- }
9511
- };
9512
- __decorateClass$n([
9513
- property({ protected: true, fallback: 0 })
9514
- ], Node2D.prototype, "rotation", 2);
9515
- __decorateClass$n([
9516
- property({ protected: true, fallback: 0 })
9517
- ], Node2D.prototype, "globalRotation", 2);
9518
- Node2D = __decorateClass$n([
9519
- customNode("Node2D")
9520
- ], Node2D);
9616
+ }
9617
+ __decorateClass$m([
9618
+ property({ fallback: true })
9619
+ ], BaseElement2DText.prototype, "enabled");
9620
+ __decorateClass$m([
9621
+ property({ alias: "base.content", fallback: () => [] })
9622
+ ], BaseElement2DText.prototype, "content");
9623
+ __decorateClass$m([
9624
+ property({ alias: "base.effects" })
9625
+ ], BaseElement2DText.prototype, "effects");
9626
+ __decorateClass$m([
9627
+ property({ alias: "base.fill" })
9628
+ ], BaseElement2DText.prototype, "fill");
9629
+ __decorateClass$m([
9630
+ property({ alias: "base.outline" })
9631
+ ], BaseElement2DText.prototype, "outline");
9632
+ __decorateClass$m([
9633
+ property({ protected: true, alias: "base.measureDom" })
9634
+ ], BaseElement2DText.prototype, "measureDom");
9635
+ __decorateClass$m([
9636
+ property({ protected: true, alias: "base.fonts" })
9637
+ ], BaseElement2DText.prototype, "fonts");
9521
9638
 
9522
- var __getOwnPropDesc$l = Object.getOwnPropertyDescriptor;
9523
- var __decorateClass$m = (decorators, target, key, kind) => {
9524
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$l(target, key) : target;
9639
+ var __getOwnPropDesc$k = Object.getOwnPropertyDescriptor;
9640
+ var __decorateClass$l = (decorators, target, key, kind) => {
9641
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$k(target, key) : target;
9525
9642
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
9526
9643
  if (decorator = decorators[i])
9527
9644
  result = (decorator(result)) || result;
@@ -9745,15 +9862,46 @@ let BaseElement2D = class extends Node2D {
9745
9862
  maxY - minY
9746
9863
  );
9747
9864
  }
9865
+ // protected _rectsOverlap(r1: any, r2: any): boolean {
9866
+ // return (
9867
+ // r1.x < r2.x + r2.width
9868
+ // && r1.x + r1.width > r2.x
9869
+ // && r1.y < r2.y + r2.height
9870
+ // && r1.y + r1.height > r2.y
9871
+ // )
9872
+ // }
9873
+ // TODO
9874
+ // override isVisibleInTree(): boolean {
9875
+ // if (this._tree) {
9876
+ // const root = this._tree.root
9877
+ // const camera = root.canvasTransform.inverse()
9878
+ // const { x, y, width, height } = root
9879
+ // const p1 = camera.applyToPoint(x, y)
9880
+ // const p2 = camera.applyToPoint(x + width, y)
9881
+ // const p3 = camera.applyToPoint(x + width, y + height)
9882
+ // const p4 = camera.applyToPoint(x, y + height)
9883
+ // const pts = [p1, p2, p3, p4]
9884
+ // const xs = pts.map(p => p[0])
9885
+ // const ys = pts.map(p => p[1])
9886
+ // const minX = Math.min(...xs)
9887
+ // const maxX = Math.max(...xs)
9888
+ // const minY = Math.min(...ys)
9889
+ // const maxY = Math.max(...ys)
9890
+ // const rect2 = {
9891
+ // x: minX,
9892
+ // y: minY,
9893
+ // width: maxX - minX,
9894
+ // height: maxY - minY,
9895
+ // }
9896
+ // if (!this._rectsOverlap(rect2, this.getRect())) {
9897
+ // return false
9898
+ // }
9899
+ // }
9900
+ // return super.isVisibleInTree()
9901
+ // }
9748
9902
  _updateOverflow() {
9749
9903
  if (this.style.overflow === "hidden") {
9750
- const rect = this.getRect();
9751
- this.mask = {
9752
- x: rect.x,
9753
- y: rect.y,
9754
- width: rect.width,
9755
- height: rect.height
9756
- };
9904
+ this.mask = this.getRect().toJSON();
9757
9905
  } else {
9758
9906
  this.mask = void 0;
9759
9907
  }
@@ -9856,7 +10004,7 @@ let BaseElement2D = class extends Node2D {
9856
10004
  });
9857
10005
  }
9858
10006
  };
9859
- BaseElement2D = __decorateClass$m([
10007
+ BaseElement2D = __decorateClass$l([
9860
10008
  customNode("BaseElement2D")
9861
10009
  ], BaseElement2D);
9862
10010
 
@@ -9876,9 +10024,16 @@ for (const key in defaultStyles) {
9876
10024
  defineProperty(Element2DStyle, key, { fallback: defaultStyles[key] });
9877
10025
  }
9878
10026
 
9879
- var __getOwnPropDesc$k = Object.getOwnPropertyDescriptor;
9880
- var __decorateClass$l = (decorators, target, key, kind) => {
9881
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$k(target, key) : target;
10027
+ class FlexElement2DStyle extends BaseElement2DStyle {
10028
+ constructor(properties) {
10029
+ super();
10030
+ this.setProperties(properties);
10031
+ }
10032
+ }
10033
+
10034
+ var __getOwnPropDesc$j = Object.getOwnPropertyDescriptor;
10035
+ var __decorateClass$k = (decorators, target, key, kind) => {
10036
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$j(target, key) : target;
9882
10037
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
9883
10038
  if (decorator = decorators[i])
9884
10039
  result = (decorator(result)) || result;
@@ -9929,17 +10084,10 @@ let Element2D = class extends BaseElement2D {
9929
10084
  }
9930
10085
  }
9931
10086
  };
9932
- Element2D = __decorateClass$l([
10087
+ Element2D = __decorateClass$k([
9933
10088
  customNode("Element2D")
9934
10089
  ], Element2D);
9935
10090
 
9936
- class FlexElement2DStyle extends BaseElement2DStyle {
9937
- constructor(properties) {
9938
- super();
9939
- this.setProperties(properties);
9940
- }
9941
- }
9942
-
9943
10091
  const alignMap = {
9944
10092
  "auto": Align.Auto,
9945
10093
  "flex-start": Align.FlexStart,
@@ -10181,9 +10329,9 @@ class FlexLayout {
10181
10329
  }
10182
10330
  }
10183
10331
 
10184
- var __getOwnPropDesc$j = Object.getOwnPropertyDescriptor;
10185
- var __decorateClass$k = (decorators, target, key, kind) => {
10186
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$j(target, key) : target;
10332
+ var __getOwnPropDesc$i = Object.getOwnPropertyDescriptor;
10333
+ var __decorateClass$j = (decorators, target, key, kind) => {
10334
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$i(target, key) : target;
10187
10335
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
10188
10336
  if (decorator = decorators[i])
10189
10337
  result = (decorator(result)) || result;
@@ -10260,18 +10408,18 @@ let FlexElement2D = class extends BaseElement2D {
10260
10408
  }
10261
10409
  }
10262
10410
  };
10263
- FlexElement2D = __decorateClass$k([
10411
+ FlexElement2D = __decorateClass$j([
10264
10412
  customNode("FlexElement2D")
10265
10413
  ], FlexElement2D);
10266
10414
 
10267
- var __defProp$f = Object.defineProperty;
10268
- var __getOwnPropDesc$i = Object.getOwnPropertyDescriptor;
10269
- var __decorateClass$j = (decorators, target, key, kind) => {
10270
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$i(target, key) : target;
10415
+ var __defProp$e = Object.defineProperty;
10416
+ var __getOwnPropDesc$h = Object.getOwnPropertyDescriptor;
10417
+ var __decorateClass$i = (decorators, target, key, kind) => {
10418
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$h(target, key) : target;
10271
10419
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
10272
10420
  if (decorator = decorators[i])
10273
10421
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
10274
- if (kind && result) __defProp$f(target, key, result);
10422
+ if (kind && result) __defProp$e(target, key, result);
10275
10423
  return result;
10276
10424
  };
10277
10425
  let Image2D = class extends Element2D {
@@ -10407,19 +10555,19 @@ let Image2D = class extends Element2D {
10407
10555
  });
10408
10556
  }
10409
10557
  };
10410
- __decorateClass$j([
10558
+ __decorateClass$i([
10411
10559
  property({ protected: true })
10412
10560
  ], Image2D.prototype, "texture", 2);
10413
- __decorateClass$j([
10561
+ __decorateClass$i([
10414
10562
  property({ fallback: "" })
10415
10563
  ], Image2D.prototype, "src", 2);
10416
- __decorateClass$j([
10564
+ __decorateClass$i([
10417
10565
  property()
10418
10566
  ], Image2D.prototype, "srcRect", 2);
10419
- __decorateClass$j([
10567
+ __decorateClass$i([
10420
10568
  property({ fallback: false })
10421
10569
  ], Image2D.prototype, "gif", 2);
10422
- Image2D = __decorateClass$j([
10570
+ Image2D = __decorateClass$i([
10423
10571
  customNode("Image2D")
10424
10572
  ], Image2D);
10425
10573
 
@@ -10443,14 +10591,14 @@ class TextureRect2D extends Element2D {
10443
10591
  }
10444
10592
  }
10445
10593
 
10446
- var __defProp$e = Object.defineProperty;
10447
- var __getOwnPropDesc$h = Object.getOwnPropertyDescriptor;
10448
- var __decorateClass$i = (decorators, target, key, kind) => {
10449
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$h(target, key) : target;
10594
+ var __defProp$d = Object.defineProperty;
10595
+ var __getOwnPropDesc$g = Object.getOwnPropertyDescriptor;
10596
+ var __decorateClass$h = (decorators, target, key, kind) => {
10597
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$g(target, key) : target;
10450
10598
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
10451
10599
  if (decorator = decorators[i])
10452
10600
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
10453
- if (kind && result) __defProp$e(target, key, result);
10601
+ if (kind && result) __defProp$d(target, key, result);
10454
10602
  return result;
10455
10603
  };
10456
10604
  let Lottie2D = class extends TextureRect2D {
@@ -10493,189 +10641,13 @@ let Lottie2D = class extends TextureRect2D {
10493
10641
  super._process(delta);
10494
10642
  }
10495
10643
  };
10496
- __decorateClass$i([
10644
+ __decorateClass$h([
10497
10645
  property({ fallback: "" })
10498
10646
  ], Lottie2D.prototype, "src", 2);
10499
- Lottie2D = __decorateClass$i([
10647
+ Lottie2D = __decorateClass$h([
10500
10648
  customNode("Lottie2D")
10501
10649
  ], Lottie2D);
10502
10650
 
10503
- var __defProp$d = Object.defineProperty;
10504
- var __getOwnPropDesc$g = Object.getOwnPropertyDescriptor;
10505
- var __decorateClass$h = (decorators, target, key, kind) => {
10506
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$g(target, key) : target;
10507
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
10508
- if (decorator = decorators[i])
10509
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
10510
- if (kind && result) __defProp$d(target, key, result);
10511
- return result;
10512
- };
10513
- const textStyles = new Set(Object.keys(textDefaultStyle));
10514
- let Text2D = class extends TextureRect2D {
10515
- texture = new CanvasTexture();
10516
- base = new Text();
10517
- measureResult;
10518
- _subTextsCount = 0;
10519
- constructor(properties, children = []) {
10520
- super();
10521
- this.setProperties(properties);
10522
- this.append(children);
10523
- if (properties?.plugins) {
10524
- properties.plugins.forEach((plugin) => {
10525
- this.base.use(plugin);
10526
- });
10527
- }
10528
- }
10529
- _updateProperty(key, value, oldValue, declaration) {
10530
- super._updateProperty(key, value, oldValue, declaration);
10531
- switch (key) {
10532
- case "content":
10533
- case "effects":
10534
- case "measureDOM":
10535
- case "fonts":
10536
- case "split":
10537
- this._updateSplit();
10538
- this.requestRedraw();
10539
- break;
10540
- }
10541
- if (this._subTextsCount && key === "effects") {
10542
- this._getSubTexts().forEach((child) => {
10543
- child.setProperties({ [key]: value });
10544
- });
10545
- }
10546
- }
10547
- _updateBase() {
10548
- this.base.style = this.style.toJSON();
10549
- this.emit("updateBase", this.base);
10550
- this.base.requestUpdate();
10551
- }
10552
- _updateStyleProperty(key, value, oldValue) {
10553
- switch (key) {
10554
- case "left":
10555
- case "top":
10556
- case "width":
10557
- case "height":
10558
- this.requestRedraw();
10559
- break;
10560
- default:
10561
- super._updateStyleProperty(key, value, oldValue);
10562
- break;
10563
- }
10564
- switch (key) {
10565
- case "width":
10566
- if (this.split) {
10567
- this._updateSubTexts();
10568
- }
10569
- break;
10570
- }
10571
- if (typeof key === "string" && textStyles.has(key)) {
10572
- if (this._subTextsCount && key !== "width" && key !== "height") {
10573
- this._getSubTexts().forEach((child) => {
10574
- child.style.setProperties({ [key]: value });
10575
- });
10576
- }
10577
- this.requestRedraw();
10578
- }
10579
- }
10580
- _getSubTexts() {
10581
- return this.children.front.filter((node) => node instanceof Text2D);
10582
- }
10583
- _updateSubTexts() {
10584
- const subTexts = this._getSubTexts();
10585
- let i = 0;
10586
- if (this.split) {
10587
- this.updateMeasure().measureResult?.paragraphs.forEach((p) => {
10588
- p.fragments.forEach((f) => {
10589
- f.characters.forEach((c) => {
10590
- const child = subTexts[i];
10591
- if (child) {
10592
- child.style.left = c.inlineBox.left;
10593
- child.style.top = c.inlineBox.top;
10594
- }
10595
- i++;
10596
- });
10597
- });
10598
- });
10599
- }
10600
- }
10601
- measure() {
10602
- this._updateBase();
10603
- return this.base.measure();
10604
- }
10605
- updateMeasure() {
10606
- this.measureResult = this.measure();
10607
- const { boundingBox } = this.measureResult;
10608
- const { left, top } = this.style;
10609
- this.position.x = left + Math.min(0, boundingBox.left);
10610
- this.position.y = top + Math.min(0, boundingBox.top);
10611
- this.size.width = boundingBox.width;
10612
- this.size.height = boundingBox.height;
10613
- return this;
10614
- }
10615
- _updateSplit() {
10616
- if (this._subTextsCount) {
10617
- this.children.front.forEach((child) => this.removeChild(child));
10618
- this._subTextsCount = 0;
10619
- }
10620
- if (this.split) {
10621
- this.measure().paragraphs.forEach((p) => {
10622
- p.fragments.forEach((f) => {
10623
- f.characters.forEach((c) => {
10624
- this.append(
10625
- new Text2D({
10626
- internalMode: "front",
10627
- style: {
10628
- ...c.computedStyle,
10629
- left: c.inlineBox.x,
10630
- top: c.inlineBox.y,
10631
- width: 0,
10632
- height: 0
10633
- },
10634
- content: c.content,
10635
- effects: this.effects,
10636
- fonts: this.fonts
10637
- })
10638
- );
10639
- this._subTextsCount++;
10640
- });
10641
- });
10642
- });
10643
- }
10644
- }
10645
- _redraw() {
10646
- this.updateMeasure();
10647
- return super._redraw();
10648
- }
10649
- _drawContent() {
10650
- if (!this.split) {
10651
- this.base.render({
10652
- pixelRatio: this.texture.pixelRatio,
10653
- view: this.texture.source
10654
- });
10655
- this.texture.requestUpload();
10656
- super._drawContent();
10657
- }
10658
- }
10659
- };
10660
- __decorateClass$h([
10661
- property({ fallback: false })
10662
- ], Text2D.prototype, "split", 2);
10663
- __decorateClass$h([
10664
- property({ alias: "base.content" })
10665
- ], Text2D.prototype, "content", 2);
10666
- __decorateClass$h([
10667
- property({ alias: "base.effects" })
10668
- ], Text2D.prototype, "effects", 2);
10669
- __decorateClass$h([
10670
- property({ protected: true, alias: "base.measureDOM" })
10671
- ], Text2D.prototype, "measureDOM", 2);
10672
- __decorateClass$h([
10673
- property({ protected: true, alias: "base.fonts" })
10674
- ], Text2D.prototype, "fonts", 2);
10675
- Text2D = __decorateClass$h([
10676
- customNode("Text2D")
10677
- ], Text2D);
10678
-
10679
10651
  var __defProp$c = Object.defineProperty;
10680
10652
  var __decorateClass$g = (decorators, target, key, kind) => {
10681
10653
  var result = void 0 ;
@@ -14002,4 +13974,4 @@ async function render(options) {
14002
13974
  });
14003
13975
  }
14004
13976
 
14005
- 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, FlexElement2D, FlexElement2DStyle, FlexLayout, FontLoader, GIFLoader, GaussianBlurEffect, Geometry, GlitchEffect, GodrayEffect, GradientTexture, 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, render, timingFunctions, uid };
13977
+ export { AnimatedTexture, Animation, Assets, Audio, AudioPipeline, AudioProcessor, AudioSpectrum, AudioWaveform, BaseElement2D, BaseElement2DBackground, BaseElement2DFill, BaseElement2DForeground, BaseElement2DOutline, BaseElement2DShadow, BaseElement2DShape, BaseElement2DStyle, BaseElement2DText, Camera2D, 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, FlexElement2D, FlexElement2DStyle, FlexLayout, FontLoader, GIFLoader, GaussianBlurEffect, Geometry, GlitchEffect, GodrayEffect, GradientTexture, 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, 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, Window, 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, render, timingFunctions, uid };