modern-canvas 0.6.13 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1081,7 +1081,7 @@ class Vector extends modernIdoc.EventEmitter {
1081
1081
  get length() {
1082
1082
  return this.dim;
1083
1083
  }
1084
- _operate(operator, target, output) {
1084
+ operate(operator, target, output) {
1085
1085
  const { dim: length, _array: array } = this;
1086
1086
  let targetArray;
1087
1087
  if (typeof target === "number") {
@@ -1167,29 +1167,41 @@ class Vector extends modernIdoc.EventEmitter {
1167
1167
  }
1168
1168
  return outputObject?.set(outputArray) ?? outputArray;
1169
1169
  }
1170
- add(value, output) {
1171
- return this._operate("+", value, output);
1170
+ add(value, ...args) {
1171
+ if (args.length && typeof value === "number") {
1172
+ value = [value, ...args];
1173
+ }
1174
+ return this.operate("+", value);
1172
1175
  }
1173
- sub(value, output) {
1174
- return this._operate("-", value, output);
1176
+ sub(value, ...args) {
1177
+ if (args.length && typeof value === "number") {
1178
+ value = [value, ...args];
1179
+ }
1180
+ return this.operate("-", value);
1175
1181
  }
1176
- multiply(value, output) {
1177
- return this._operate("*", value, output);
1182
+ multiply(value, ...args) {
1183
+ if (args.length && typeof value === "number") {
1184
+ value = [value, ...args];
1185
+ }
1186
+ return this.operate("*", value);
1178
1187
  }
1179
- divide(value, output) {
1180
- return this._operate("/", value, output);
1188
+ divide(value, ...args) {
1189
+ if (args.length && typeof value === "number") {
1190
+ value = [value, ...args];
1191
+ }
1192
+ return this.operate("/", value);
1181
1193
  }
1182
1194
  rotate(angle) {
1183
- return this._operate("rot", angle);
1195
+ return this.operate("rot", angle);
1184
1196
  }
1185
1197
  set(value, ...args) {
1186
1198
  if (args.length && typeof value === "number") {
1187
1199
  value = [value, ...args];
1188
1200
  }
1189
- return this._operate("=", value);
1201
+ return this.operate("=", value);
1190
1202
  }
1191
1203
  equals(value) {
1192
- return this._operate("==", value);
1204
+ return this.operate("==", value);
1193
1205
  }
1194
1206
  copy(value) {
1195
1207
  return this.set(value);
@@ -1201,11 +1213,14 @@ class Vector extends modernIdoc.EventEmitter {
1201
1213
  }
1202
1214
  _onUpdate(_array) {
1203
1215
  }
1216
+ toName() {
1217
+ return `Vector${this.dim}`;
1218
+ }
1204
1219
  toArray() {
1205
1220
  return this._array.slice();
1206
1221
  }
1207
- toName() {
1208
- return `Vector${this.dim}`;
1222
+ toJSON() {
1223
+ return this.toArray();
1209
1224
  }
1210
1225
  }
1211
1226
 
@@ -1225,7 +1240,7 @@ class Matrix extends modernIdoc.EventEmitter {
1225
1240
  get length() {
1226
1241
  return this.cols * this.rows;
1227
1242
  }
1228
- _operate(operator, target, output) {
1243
+ operate(operator, target, output) {
1229
1244
  const { cols, rows, length, _array: array } = this;
1230
1245
  let targetArray;
1231
1246
  if (typeof target === "number") {
@@ -1312,7 +1327,7 @@ class Matrix extends modernIdoc.EventEmitter {
1312
1327
  return this.set(array);
1313
1328
  }
1314
1329
  set(value) {
1315
- return this._operate("=", value);
1330
+ return this.operate("=", value);
1316
1331
  }
1317
1332
  copy(value) {
1318
1333
  return this.set(value);
@@ -1323,7 +1338,7 @@ class Matrix extends modernIdoc.EventEmitter {
1323
1338
  return cloned;
1324
1339
  }
1325
1340
  multiply(value, output) {
1326
- return this._operate("*", value, output);
1341
+ return this.operate("*", value, output);
1327
1342
  }
1328
1343
  _onUpdate(_array) {
1329
1344
  this.dirtyId++;
@@ -1345,7 +1360,7 @@ class Matrix extends modernIdoc.EventEmitter {
1345
1360
  return `Matrix${this.rows}(${this.rows}x${this.cols})`;
1346
1361
  }
1347
1362
  toJSON() {
1348
- return this._array;
1363
+ return this._array.slice();
1349
1364
  }
1350
1365
  }
1351
1366
 
@@ -1357,7 +1372,7 @@ class Matrix4 extends Matrix {
1357
1372
 
1358
1373
  const DEG_TO_RAD = PI / 180;
1359
1374
  const RAD_TO_DEG = 180 / PI;
1360
- function clamp(min, val, max) {
1375
+ function clamp(val, min, max) {
1361
1376
  return Math.max(min, Math.min(val, max));
1362
1377
  }
1363
1378
  function lerp(a, b, weight) {
@@ -1386,7 +1401,7 @@ const curves = {
1386
1401
  class Vector4 extends Vector {
1387
1402
  constructor(x = 0, y = 0, z = 0, m = 0) {
1388
1403
  super(4);
1389
- this.set([x, y, z, m]);
1404
+ this.set(x, y, z, m);
1390
1405
  }
1391
1406
  }
1392
1407
 
@@ -1527,7 +1542,7 @@ class ColorMatrix extends Matrix {
1527
1542
  ]);
1528
1543
  }
1529
1544
  sepia(amount = 1) {
1530
- const v = clamp(0, amount, 1);
1545
+ const v = clamp(amount, 0, 1);
1531
1546
  return this.multiply([
1532
1547
  lerp(1, 0.393, v),
1533
1548
  lerp(0, 0.7689999, v),
@@ -1576,7 +1591,7 @@ class ColorMatrix extends Matrix {
1576
1591
  ]);
1577
1592
  }
1578
1593
  grayscale(amount = 1) {
1579
- const v = clamp(0, amount, 1);
1594
+ const v = clamp(amount, 0, 1);
1580
1595
  const r = lerp(1, 0.3, v);
1581
1596
  const rr = lerp(0, 0.3, v);
1582
1597
  const g = lerp(1, 0.59, v);
@@ -1839,7 +1854,7 @@ class Vector2 extends Vector {
1839
1854
  return this;
1840
1855
  }
1841
1856
  static lerp(a, b, t) {
1842
- return new Vector2(b).clone().sub(new Vector2(a)).multiply(t).add(new Vector2(a));
1857
+ return new Vector2(b).clone().sub(a).multiply(t).add(a);
1843
1858
  }
1844
1859
  }
1845
1860
 
@@ -1905,6 +1920,14 @@ class Rect2 {
1905
1920
  toArray() {
1906
1921
  return [this.x, this.y, this.width, this.height];
1907
1922
  }
1923
+ toJSON() {
1924
+ return {
1925
+ x: this.x,
1926
+ y: this.y,
1927
+ width: this.width,
1928
+ height: this.height
1929
+ };
1930
+ }
1908
1931
  }
1909
1932
 
1910
1933
  class Transform2D extends Matrix3 {
@@ -2079,13 +2102,13 @@ class Vector3 extends Vector {
2079
2102
  }
2080
2103
  }
2081
2104
 
2082
- var __defProp$Q = Object.defineProperty;
2083
- var __decorateClass$Y = (decorators, target, key, kind) => {
2105
+ var __defProp$P = Object.defineProperty;
2106
+ var __decorateClass$Z = (decorators, target, key, kind) => {
2084
2107
  var result = void 0 ;
2085
2108
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
2086
2109
  if (decorator = decorators[i])
2087
2110
  result = (decorator(target, key, result) ) || result;
2088
- if (result) __defProp$Q(target, key, result);
2111
+ if (result) __defProp$P(target, key, result);
2089
2112
  return result;
2090
2113
  };
2091
2114
  class MainLoop extends CoreObject {
@@ -2128,10 +2151,10 @@ class MainLoop extends CoreObject {
2128
2151
  this.stop();
2129
2152
  }
2130
2153
  }
2131
- __decorateClass$Y([
2132
- modernIdoc.property({ fallback: 24 })
2154
+ __decorateClass$Z([
2155
+ modernIdoc.property({ fallback: 60 })
2133
2156
  ], MainLoop.prototype, "fps");
2134
- __decorateClass$Y([
2157
+ __decorateClass$Z([
2135
2158
  modernIdoc.property({ fallback: 1 })
2136
2159
  ], MainLoop.prototype, "speed");
2137
2160
 
@@ -3457,6 +3480,33 @@ function getVarTypeSize(type) {
3457
3480
  }
3458
3481
  }
3459
3482
 
3483
+ function applyMatrixToPoint(m, x, y) {
3484
+ const [a, d, g, b, e, h, c, f, i] = m;
3485
+ const xp = a * x + b * y + c;
3486
+ const yp = d * x + e * y + f;
3487
+ const wp = g * x + h * y + i;
3488
+ return { x: xp / wp, y: yp / wp };
3489
+ }
3490
+ function transformRectToAABB(m, rect) {
3491
+ const { x, y, width, height } = rect;
3492
+ const p1 = applyMatrixToPoint(m, x, y);
3493
+ const p2 = applyMatrixToPoint(m, x + width, y);
3494
+ const p3 = applyMatrixToPoint(m, x + width, y + height);
3495
+ const p4 = applyMatrixToPoint(m, x, y + height);
3496
+ const pts = [p1, p2, p3, p4];
3497
+ const xs = pts.map((p) => p.x);
3498
+ const ys = pts.map((p) => p.y);
3499
+ const minX = Math.min(...xs);
3500
+ const maxX = Math.max(...xs);
3501
+ const minY = Math.min(...ys);
3502
+ const maxY = Math.max(...ys);
3503
+ return {
3504
+ x: minX,
3505
+ y: minY,
3506
+ width: maxX - minX,
3507
+ height: maxY - minY
3508
+ };
3509
+ }
3460
3510
  class WebGLScissorModule extends WebGLModule {
3461
3511
  install(renderer) {
3462
3512
  super.install(renderer);
@@ -3482,19 +3532,21 @@ class WebGLScissorModule extends WebGLModule {
3482
3532
  }
3483
3533
  use() {
3484
3534
  const renderer = this._renderer;
3485
- const { pixelRatio, mask, viewport, screen, gl } = renderer;
3486
- const rect = mask.last.mask;
3487
- let y;
3535
+ const { pixelRatio, mask, viewport, screen, gl, program } = renderer;
3536
+ const { worldTransformMatrix } = program.uniforms;
3537
+ const rect = transformRectToAABB(worldTransformMatrix, mask.last.mask);
3538
+ const { x, y, width, height } = rect;
3539
+ let scissorY;
3488
3540
  if (viewport.boundViewport) {
3489
- y = viewport.boundViewport.height - (rect.height + rect.y) * pixelRatio;
3541
+ scissorY = viewport.boundViewport.height - (height + y) * pixelRatio;
3490
3542
  } else {
3491
- y = (screen.height - (rect.height + rect.y)) * pixelRatio;
3543
+ scissorY = (screen.height - (height + y)) * pixelRatio;
3492
3544
  }
3493
3545
  gl.scissor(
3494
- rect.x * pixelRatio,
3495
- y,
3496
- rect.width * pixelRatio,
3497
- rect.height * pixelRatio
3546
+ x * pixelRatio,
3547
+ scissorY,
3548
+ width * pixelRatio,
3549
+ height * pixelRatio
3498
3550
  );
3499
3551
  }
3500
3552
  }
@@ -4171,15 +4223,13 @@ class WebGLRenderer extends Renderer {
4171
4223
  this.view?.removeEventListener("webglcontextrestored", this._onContextRestored, false);
4172
4224
  this.extensions.loseContext?.loseContext();
4173
4225
  }
4174
- toPixels() {
4175
- const width = this.gl.drawingBufferWidth;
4176
- const height = this.gl.drawingBufferHeight;
4226
+ toPixels(x = 0, y = 0, width = this.gl.drawingBufferWidth, height = this.gl.drawingBufferHeight) {
4177
4227
  const length = width * height * 4;
4178
4228
  const row = width * 4;
4179
4229
  const end = (height - 1) * row;
4180
4230
  const flipedPixels = new Uint8Array(length);
4181
4231
  const pixels = new Uint8ClampedArray(length);
4182
- this.gl.readPixels(0, 0, width, height, this.gl.RGBA, this.gl.UNSIGNED_BYTE, flipedPixels);
4232
+ this.gl.readPixels(x, y, width, height, this.gl.RGBA, this.gl.UNSIGNED_BYTE, flipedPixels);
4183
4233
  for (let i = 0; i < length; i += row) {
4184
4234
  pixels.set(flipedPixels.subarray(i, i + row), end - i);
4185
4235
  }
@@ -4211,152 +4261,6 @@ class FontLoader extends Loader {
4211
4261
  }
4212
4262
  }
4213
4263
 
4214
- const defaultFilters = {
4215
- "brightness": 1,
4216
- "contrast": 1,
4217
- "grayscale": 0,
4218
- "hue-rotate": 0,
4219
- "invert": 0,
4220
- "opacity": 1,
4221
- "saturate": 1,
4222
- "sepia": 0
4223
- };
4224
- function parseCSSFilter(filter) {
4225
- const m = new ColorMatrix();
4226
- if (filter === "none") {
4227
- return m;
4228
- }
4229
- const filters = parseCssFunctions(filter).reduce((filter2, { name, args }) => {
4230
- filter2[name] = args[0].normalizedIntValue;
4231
- return filter2;
4232
- }, {});
4233
- Object.keys(defaultFilters).forEach((name) => {
4234
- filters[name] = filters[name] ?? defaultFilters[name];
4235
- });
4236
- for (const name in filters) {
4237
- const value = filters[name];
4238
- switch (name) {
4239
- case "hue-rotate":
4240
- m.hueRotate(value * PI_2);
4241
- break;
4242
- case "saturate":
4243
- m.saturate(value);
4244
- break;
4245
- case "brightness":
4246
- m.brightness(value);
4247
- break;
4248
- case "contrast":
4249
- m.contrast(value);
4250
- break;
4251
- case "invert":
4252
- m.invert(value);
4253
- break;
4254
- case "sepia":
4255
- m.sepia(value);
4256
- break;
4257
- case "opacity":
4258
- m.opacity(value);
4259
- break;
4260
- case "grayscale":
4261
- m.grayscale(value);
4262
- break;
4263
- }
4264
- }
4265
- return m;
4266
- }
4267
-
4268
- function parseCSSTransform(transform, width, height, output = new Transform2D()) {
4269
- transform = !transform || transform === "none" ? "" : transform;
4270
- parseCssFunctions(transform, { width, height }).reverse().forEach(({ name, args }) => {
4271
- const values = args.map((arg) => arg.normalizedIntValue);
4272
- switch (name) {
4273
- case "translate":
4274
- output.translate(values[0] * width, (values[1] ?? values[0]) * height);
4275
- break;
4276
- case "translateX":
4277
- output.translateX(values[0] * width);
4278
- break;
4279
- case "translateY":
4280
- output.translateY(values[0] * height);
4281
- break;
4282
- case "translateZ":
4283
- output.translateZ(values[0]);
4284
- break;
4285
- case "translate3d":
4286
- output.translate3d(
4287
- values[0] * width,
4288
- (values[1] ?? values[0]) * height,
4289
- values[2] ?? values[1] ?? values[0]
4290
- );
4291
- break;
4292
- case "scale":
4293
- output.scale(values[0], values[1] ?? values[0]);
4294
- break;
4295
- case "scaleX":
4296
- output.scaleX(values[0]);
4297
- break;
4298
- case "scaleY":
4299
- output.scaleY(values[0]);
4300
- break;
4301
- case "scale3d":
4302
- output.scale3d(values[0], values[1] ?? values[0], values[2] ?? values[1] ?? values[0]);
4303
- break;
4304
- case "rotate":
4305
- output.rotate(values[0] * PI_2);
4306
- break;
4307
- case "rotateX":
4308
- output.rotateX(values[0] * PI_2);
4309
- break;
4310
- case "rotateY":
4311
- output.rotateY(values[0] * PI_2);
4312
- break;
4313
- case "rotateZ":
4314
- output.rotateZ(values[0] * PI_2);
4315
- break;
4316
- case "rotate3d":
4317
- output.rotate3d(
4318
- values[0] * PI_2,
4319
- (values[1] ?? values[0]) * PI_2,
4320
- (values[2] ?? values[1] ?? values[0]) * PI_2,
4321
- (values[3] ?? values[2] ?? values[1] ?? values[0]) * PI_2
4322
- );
4323
- break;
4324
- case "skew":
4325
- output.skew(values[0], values[0] ?? values[1]);
4326
- break;
4327
- case "skewX":
4328
- output.skewX(values[0]);
4329
- break;
4330
- case "skewY":
4331
- output.skewY(values[0]);
4332
- break;
4333
- case "matrix":
4334
- output.set(values);
4335
- break;
4336
- }
4337
- });
4338
- return output;
4339
- }
4340
-
4341
- function parseCSSTransformOrigin(transformOrigin) {
4342
- const [originX, originY = originX] = transformOrigin.split(" ");
4343
- return [originX, originY].map((val) => {
4344
- val = val.trim();
4345
- switch (val) {
4346
- case "left":
4347
- case "top":
4348
- return 0;
4349
- case "center":
4350
- return 0.5;
4351
- case "right":
4352
- case "bottom":
4353
- return 1;
4354
- default:
4355
- return Number(val);
4356
- }
4357
- });
4358
- }
4359
-
4360
4264
  class Geometry extends Resource {
4361
4265
  vertexAttributes;
4362
4266
  indexBuffer;
@@ -4442,13 +4346,13 @@ class Geometry extends Resource {
4442
4346
  }
4443
4347
  }
4444
4348
 
4445
- var __defProp$P = Object.defineProperty;
4446
- var __decorateClass$X = (decorators, target, key, kind) => {
4349
+ var __defProp$O = Object.defineProperty;
4350
+ var __decorateClass$Y = (decorators, target, key, kind) => {
4447
4351
  var result = void 0 ;
4448
4352
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
4449
4353
  if (decorator = decorators[i])
4450
4354
  result = (decorator(target, key, result) ) || result;
4451
- if (result) __defProp$P(target, key, result);
4355
+ if (result) __defProp$O(target, key, result);
4452
4356
  return result;
4453
4357
  };
4454
4358
  class IndexBuffer extends Resource {
@@ -4492,20 +4396,20 @@ class IndexBuffer extends Resource {
4492
4396
  return result;
4493
4397
  }
4494
4398
  }
4495
- __decorateClass$X([
4399
+ __decorateClass$Y([
4496
4400
  modernIdoc.property({ protected: true, default: null })
4497
4401
  ], IndexBuffer.prototype, "data");
4498
- __decorateClass$X([
4402
+ __decorateClass$Y([
4499
4403
  modernIdoc.property({ protected: true, fallback: false })
4500
4404
  ], IndexBuffer.prototype, "dynamic");
4501
4405
 
4502
- var __defProp$O = Object.defineProperty;
4503
- var __decorateClass$W = (decorators, target, key, kind) => {
4406
+ var __defProp$N = Object.defineProperty;
4407
+ var __decorateClass$X = (decorators, target, key, kind) => {
4504
4408
  var result = void 0 ;
4505
4409
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
4506
4410
  if (decorator = decorators[i])
4507
4411
  result = (decorator(target, key, result) ) || result;
4508
- if (result) __defProp$O(target, key, result);
4412
+ if (result) __defProp$N(target, key, result);
4509
4413
  return result;
4510
4414
  };
4511
4415
  class VertexBuffer extends Resource {
@@ -4549,20 +4453,20 @@ class VertexBuffer extends Resource {
4549
4453
  return result;
4550
4454
  }
4551
4455
  }
4552
- __decorateClass$W([
4456
+ __decorateClass$X([
4553
4457
  modernIdoc.property({ protected: true, default: null })
4554
4458
  ], VertexBuffer.prototype, "data");
4555
- __decorateClass$W([
4459
+ __decorateClass$X([
4556
4460
  modernIdoc.property({ protected: true, fallback: false })
4557
4461
  ], VertexBuffer.prototype, "dynamic");
4558
4462
 
4559
- var __defProp$N = Object.defineProperty;
4560
- var __decorateClass$V = (decorators, target, key, kind) => {
4463
+ var __defProp$M = Object.defineProperty;
4464
+ var __decorateClass$W = (decorators, target, key, kind) => {
4561
4465
  var result = void 0 ;
4562
4466
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
4563
4467
  if (decorator = decorators[i])
4564
4468
  result = (decorator(target, key, result) ) || result;
4565
- if (result) __defProp$N(target, key, result);
4469
+ if (result) __defProp$M(target, key, result);
4566
4470
  return result;
4567
4471
  };
4568
4472
  class VertexAttribute extends Resource {
@@ -4596,25 +4500,25 @@ class VertexAttribute extends Resource {
4596
4500
  return result;
4597
4501
  }
4598
4502
  }
4599
- __decorateClass$V([
4503
+ __decorateClass$W([
4600
4504
  modernIdoc.property({ protected: true })
4601
4505
  ], VertexAttribute.prototype, "buffer");
4602
- __decorateClass$V([
4506
+ __decorateClass$W([
4603
4507
  modernIdoc.property({ fallback: 0 })
4604
4508
  ], VertexAttribute.prototype, "size");
4605
- __decorateClass$V([
4509
+ __decorateClass$W([
4606
4510
  modernIdoc.property({ fallback: false })
4607
4511
  ], VertexAttribute.prototype, "normalized");
4608
- __decorateClass$V([
4512
+ __decorateClass$W([
4609
4513
  modernIdoc.property({ fallback: "float" })
4610
4514
  ], VertexAttribute.prototype, "type");
4611
- __decorateClass$V([
4515
+ __decorateClass$W([
4612
4516
  modernIdoc.property()
4613
4517
  ], VertexAttribute.prototype, "stride");
4614
- __decorateClass$V([
4518
+ __decorateClass$W([
4615
4519
  modernIdoc.property()
4616
4520
  ], VertexAttribute.prototype, "offset");
4617
- __decorateClass$V([
4521
+ __decorateClass$W([
4618
4522
  modernIdoc.property()
4619
4523
  ], VertexAttribute.prototype, "divisor");
4620
4524
 
@@ -4858,13 +4762,13 @@ class UvGeometry extends Geometry {
4858
4762
  }
4859
4763
  }
4860
4764
 
4861
- var __defProp$M = Object.defineProperty;
4862
- var __decorateClass$U = (decorators, target, key, kind) => {
4765
+ var __defProp$L = Object.defineProperty;
4766
+ var __decorateClass$V = (decorators, target, key, kind) => {
4863
4767
  var result = void 0 ;
4864
4768
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
4865
4769
  if (decorator = decorators[i])
4866
4770
  result = (decorator(target, key, result) ) || result;
4867
- if (result) __defProp$M(target, key, result);
4771
+ if (result) __defProp$L(target, key, result);
4868
4772
  return result;
4869
4773
  };
4870
4774
  class Texture2D extends Resource {
@@ -4990,22 +4894,22 @@ class Texture2D extends Resource {
4990
4894
  }
4991
4895
  }
4992
4896
  }
4993
- __decorateClass$U([
4897
+ __decorateClass$V([
4994
4898
  modernIdoc.property({ protected: true })
4995
4899
  ], Texture2D.prototype, "source");
4996
- __decorateClass$U([
4900
+ __decorateClass$V([
4997
4901
  modernIdoc.property({ fallback: 0 })
4998
4902
  ], Texture2D.prototype, "width");
4999
- __decorateClass$U([
4903
+ __decorateClass$V([
5000
4904
  modernIdoc.property({ fallback: 0 })
5001
4905
  ], Texture2D.prototype, "height");
5002
- __decorateClass$U([
4906
+ __decorateClass$V([
5003
4907
  modernIdoc.property({ fallback: "linear" })
5004
4908
  ], Texture2D.prototype, "filterMode");
5005
- __decorateClass$U([
4909
+ __decorateClass$V([
5006
4910
  modernIdoc.property({ fallback: "clamp_to_edge" })
5007
4911
  ], Texture2D.prototype, "wrapMode");
5008
- __decorateClass$U([
4912
+ __decorateClass$V([
5009
4913
  modernIdoc.property({ fallback: 1 })
5010
4914
  ], Texture2D.prototype, "pixelRatio");
5011
4915
 
@@ -5035,13 +4939,13 @@ class AnimatedTexture extends Resource {
5035
4939
  }
5036
4940
  }
5037
4941
 
5038
- var __defProp$L = Object.defineProperty;
5039
- var __decorateClass$T = (decorators, target, key, kind) => {
4942
+ var __defProp$K = Object.defineProperty;
4943
+ var __decorateClass$U = (decorators, target, key, kind) => {
5040
4944
  var result = void 0 ;
5041
4945
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
5042
4946
  if (decorator = decorators[i])
5043
4947
  result = (decorator(target, key, result) ) || result;
5044
- if (result) __defProp$L(target, key, result);
4948
+ if (result) __defProp$K(target, key, result);
5045
4949
  return result;
5046
4950
  };
5047
4951
  class CanvasTexture extends Texture2D {
@@ -5060,7 +4964,7 @@ class CanvasTexture extends Texture2D {
5060
4964
  super._updateProperty(key, value, oldValue, declaration);
5061
4965
  }
5062
4966
  }
5063
- __decorateClass$T([
4967
+ __decorateClass$U([
5064
4968
  modernIdoc.property({ fallback: 2 })
5065
4969
  ], CanvasTexture.prototype, "pixelRatio");
5066
4970
 
@@ -5280,13 +5184,13 @@ class PixelsTexture extends Texture2D {
5280
5184
  }
5281
5185
  }
5282
5186
 
5283
- var __defProp$K = Object.defineProperty;
5284
- var __decorateClass$S = (decorators, target, key, kind) => {
5187
+ var __defProp$J = Object.defineProperty;
5188
+ var __decorateClass$T = (decorators, target, key, kind) => {
5285
5189
  var result = void 0 ;
5286
5190
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
5287
5191
  if (decorator = decorators[i])
5288
5192
  result = (decorator(target, key, result) ) || result;
5289
- if (result) __defProp$K(target, key, result);
5193
+ if (result) __defProp$J(target, key, result);
5290
5194
  return result;
5291
5195
  };
5292
5196
  function resolveOptions(options) {
@@ -5530,10 +5434,10 @@ const _VideoTexture = class _VideoTexture extends Texture2D {
5530
5434
  }
5531
5435
  }
5532
5436
  };
5533
- __decorateClass$S([
5437
+ __decorateClass$T([
5534
5438
  modernIdoc.property({ protected: true, fallback: true })
5535
5439
  ], _VideoTexture.prototype, "autoUpdate");
5536
- __decorateClass$S([
5440
+ __decorateClass$T([
5537
5441
  modernIdoc.property({ protected: true, fallback: 0 })
5538
5442
  ], _VideoTexture.prototype, "fps");
5539
5443
  let VideoTexture = _VideoTexture;
@@ -5542,7 +5446,178 @@ class ViewportTexture extends PixelsTexture {
5542
5446
  //
5543
5447
  }
5544
5448
 
5545
- class Children extends Array {
5449
+ class CanvasContext extends modernPath2d.Path2D {
5450
+ fillStyle;
5451
+ strokeStyle;
5452
+ lineCap;
5453
+ lineJoin;
5454
+ lineWidth;
5455
+ miterLimit;
5456
+ // custom
5457
+ uvTransform;
5458
+ vertTransform;
5459
+ _defaultStyle = Texture2D.EMPTY;
5460
+ _draws = [];
5461
+ _toTexture(source) {
5462
+ if (source instanceof Texture2D) {
5463
+ return source;
5464
+ } else {
5465
+ return ColorTexture.get(source);
5466
+ }
5467
+ }
5468
+ stroke(options) {
5469
+ if (!this.curves.length) {
5470
+ return;
5471
+ }
5472
+ let strokeStyle = this.strokeStyle;
5473
+ if (!strokeStyle && this.style.stroke) {
5474
+ switch (typeof this.style.stroke) {
5475
+ case "string":
5476
+ strokeStyle = this.style.stroke;
5477
+ break;
5478
+ case "object":
5479
+ if (modernIdoc.isColorFillObject(this.style.stroke)) {
5480
+ strokeStyle = this.style.stroke.color;
5481
+ }
5482
+ break;
5483
+ }
5484
+ }
5485
+ this._draws.push({
5486
+ ...options,
5487
+ type: "stroke",
5488
+ path: new modernPath2d.Path2D(this),
5489
+ texture: strokeStyle ? this._toTexture(strokeStyle) : this._defaultStyle,
5490
+ uvTransform: this.uvTransform,
5491
+ vertTransform: this.vertTransform,
5492
+ style: {
5493
+ alignment: 0.5,
5494
+ cap: this.lineCap ?? "butt",
5495
+ join: this.lineJoin ?? "miter",
5496
+ width: this.lineWidth ?? 1,
5497
+ miterLimit: this.miterLimit ?? 10
5498
+ }
5499
+ });
5500
+ super.reset();
5501
+ }
5502
+ fillRect(x, y, width, height) {
5503
+ this.rect(x, y, width, height).fill();
5504
+ }
5505
+ strokeRect(x, y, width, height) {
5506
+ this.rect(x, y, width, height).stroke();
5507
+ }
5508
+ fill(options) {
5509
+ if (!this.curves.length) {
5510
+ return;
5511
+ }
5512
+ let fillStyle = this.fillStyle;
5513
+ if (!fillStyle && this.style.fill) {
5514
+ switch (typeof this.style.fill) {
5515
+ case "string":
5516
+ fillStyle = this.style.fill;
5517
+ break;
5518
+ case "object":
5519
+ if (modernIdoc.isColorFillObject(this.style.fill)) {
5520
+ fillStyle = this.style.fill.color;
5521
+ }
5522
+ break;
5523
+ }
5524
+ }
5525
+ this._draws.push({
5526
+ ...options,
5527
+ type: "fill",
5528
+ path: new modernPath2d.Path2D(this),
5529
+ texture: fillStyle ? this._toTexture(fillStyle) : this._defaultStyle,
5530
+ uvTransform: this.uvTransform,
5531
+ vertTransform: this.vertTransform
5532
+ });
5533
+ super.reset();
5534
+ }
5535
+ copy(source) {
5536
+ super.copy(source);
5537
+ this.strokeStyle = source.strokeStyle;
5538
+ this.fillStyle = source.fillStyle;
5539
+ this.uvTransform = source.uvTransform;
5540
+ this.vertTransform = source.vertTransform;
5541
+ this.lineCap = source.lineCap;
5542
+ this.lineJoin = source.lineJoin;
5543
+ this.lineWidth = source.lineWidth;
5544
+ this.miterLimit = source.miterLimit;
5545
+ this._draws = source._draws.slice();
5546
+ return this;
5547
+ }
5548
+ reset() {
5549
+ super.reset();
5550
+ this.strokeStyle = void 0;
5551
+ this.fillStyle = void 0;
5552
+ this.uvTransform = void 0;
5553
+ this.vertTransform = void 0;
5554
+ this.lineCap = void 0;
5555
+ this.lineJoin = void 0;
5556
+ this.lineWidth = void 0;
5557
+ this.miterLimit = void 0;
5558
+ this._draws.length = 0;
5559
+ return this;
5560
+ }
5561
+ buildUvs(start, vertices, uvs, texture, uvTransform) {
5562
+ if (texture) {
5563
+ const _uvTransform = uvTransform ? typeof uvTransform === "function" ? uvTransform : (x, y) => uvTransform.applyToPoint(x, y) : uvTransform;
5564
+ const w = texture.width;
5565
+ const h = texture.height;
5566
+ for (let len = vertices.length, i = start; i < len; i += 2) {
5567
+ const x = vertices[i];
5568
+ const y = vertices[i + 1];
5569
+ let uvX;
5570
+ let uvY;
5571
+ if (_uvTransform) {
5572
+ [uvX, uvY] = _uvTransform(x, y);
5573
+ } else {
5574
+ [uvX, uvY] = [x / w, y / h];
5575
+ }
5576
+ uvs.push(uvX, uvY);
5577
+ }
5578
+ } else {
5579
+ for (let len = vertices.length, i = start; i < len; i += 2) {
5580
+ uvs.push(0, 0);
5581
+ }
5582
+ }
5583
+ }
5584
+ toBatchables() {
5585
+ const batchables = [];
5586
+ for (let len = this._draws.length, i = 0; i < len; i++) {
5587
+ const current = this._draws[i];
5588
+ const vertices = [];
5589
+ const indices = [];
5590
+ const uvs = [];
5591
+ if (current.type === "fill") {
5592
+ current.path.fillTriangulate({
5593
+ vertices,
5594
+ indices
5595
+ });
5596
+ } else {
5597
+ current.path.strokeTriangulate({
5598
+ vertices,
5599
+ indices,
5600
+ lineStyle: current.style,
5601
+ flipAlignment: false,
5602
+ closed: true
5603
+ });
5604
+ }
5605
+ this.buildUvs(0, vertices, uvs, current.texture, current.uvTransform);
5606
+ batchables.push({
5607
+ vertices,
5608
+ indices,
5609
+ uvs,
5610
+ texture: current.texture,
5611
+ type: current.type,
5612
+ disableWrapMode: current.disableWrapMode,
5613
+ vertTransform: current.vertTransform
5614
+ });
5615
+ }
5616
+ return batchables;
5617
+ }
5618
+ }
5619
+
5620
+ class Children extends Array {
5546
5621
  front = [];
5547
5622
  back = [];
5548
5623
  get internal() {
@@ -5592,14 +5667,14 @@ class Children extends Array {
5592
5667
  }
5593
5668
  }
5594
5669
 
5595
- var __defProp$J = Object.defineProperty;
5596
- var __getOwnPropDesc$I = Object.getOwnPropertyDescriptor;
5597
- var __decorateClass$R = (decorators, target, key, kind) => {
5598
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$I(target, key) : target;
5670
+ var __defProp$I = Object.defineProperty;
5671
+ var __getOwnPropDesc$J = Object.getOwnPropertyDescriptor;
5672
+ var __decorateClass$S = (decorators, target, key, kind) => {
5673
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$J(target, key) : target;
5599
5674
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
5600
5675
  if (decorator = decorators[i])
5601
5676
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
5602
- if (kind && result) __defProp$J(target, key, result);
5677
+ if (kind && result) __defProp$I(target, key, result);
5603
5678
  return result;
5604
5679
  };
5605
5680
  const iidMap = {};
@@ -5660,7 +5735,7 @@ exports.Node = class Node extends CoreObject {
5660
5735
  return this._tree;
5661
5736
  }
5662
5737
  getViewport() {
5663
- return this._tree?.getCurrentViewport();
5738
+ return this.parent?.getViewport() ?? this.getWindow();
5664
5739
  }
5665
5740
  getWindow() {
5666
5741
  return this._tree?.root;
@@ -6083,42 +6158,42 @@ exports.Node = class Node extends CoreObject {
6083
6158
  return node;
6084
6159
  }
6085
6160
  };
6086
- __decorateClass$R([
6161
+ __decorateClass$S([
6087
6162
  modernIdoc.property({ fallback: modernIdoc.idGenerator() })
6088
6163
  ], exports.Node.prototype, "id", 2);
6089
- __decorateClass$R([
6164
+ __decorateClass$S([
6090
6165
  modernIdoc.property({ fallback: modernIdoc.idGenerator() })
6091
6166
  ], exports.Node.prototype, "name", 2);
6092
- __decorateClass$R([
6167
+ __decorateClass$S([
6093
6168
  modernIdoc.property({ fallback: "inherit" })
6094
6169
  ], exports.Node.prototype, "processMode", 2);
6095
- __decorateClass$R([
6170
+ __decorateClass$S([
6096
6171
  modernIdoc.property({ fallback: "default" })
6097
6172
  ], exports.Node.prototype, "processSortMode", 2);
6098
- __decorateClass$R([
6173
+ __decorateClass$S([
6099
6174
  modernIdoc.property({ fallback: "inherit" })
6100
6175
  ], exports.Node.prototype, "renderMode", 2);
6101
- __decorateClass$R([
6176
+ __decorateClass$S([
6102
6177
  modernIdoc.property({ fallback: "default" })
6103
6178
  ], exports.Node.prototype, "internalMode", 2);
6104
- __decorateClass$R([
6179
+ __decorateClass$S([
6105
6180
  modernIdoc.property({ default: () => ({}) })
6106
6181
  ], exports.Node.prototype, "meta", 2);
6107
- __decorateClass$R([
6182
+ __decorateClass$S([
6108
6183
  modernIdoc.property({ protected: true })
6109
6184
  ], exports.Node.prototype, "mask", 2);
6110
- exports.Node = __decorateClass$R([
6185
+ exports.Node = __decorateClass$S([
6111
6186
  customNode("Node")
6112
6187
  ], exports.Node);
6113
6188
 
6114
- var __defProp$I = Object.defineProperty;
6115
- var __getOwnPropDesc$H = Object.getOwnPropertyDescriptor;
6116
- var __decorateClass$Q = (decorators, target, key, kind) => {
6117
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$H(target, key) : target;
6189
+ var __defProp$H = Object.defineProperty;
6190
+ var __getOwnPropDesc$I = Object.getOwnPropertyDescriptor;
6191
+ var __decorateClass$R = (decorators, target, key, kind) => {
6192
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$I(target, key) : target;
6118
6193
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
6119
6194
  if (decorator = decorators[i])
6120
6195
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
6121
- if (kind && result) __defProp$I(target, key, result);
6196
+ if (kind && result) __defProp$H(target, key, result);
6122
6197
  return result;
6123
6198
  };
6124
6199
  exports.TimelineNode = class TimelineNode extends exports.Node {
@@ -6140,7 +6215,7 @@ exports.TimelineNode = class TimelineNode extends exports.Node {
6140
6215
  return this._parent?.startTime ?? 0;
6141
6216
  }
6142
6217
  get currentTime() {
6143
- return clamp(0, this._currentTime, this.computedDuration);
6218
+ return clamp(this._currentTime, 0, this.computedDuration);
6144
6219
  }
6145
6220
  get startTime() {
6146
6221
  return this._startTime;
@@ -6153,7 +6228,7 @@ exports.TimelineNode = class TimelineNode extends exports.Node {
6153
6228
  return this._startTime + this.computedDuration;
6154
6229
  }
6155
6230
  get currentTimeProgress() {
6156
- return this.computedDuration ? clamp(0, this._currentTime / this.computedDuration, 1) : 0;
6231
+ return this.computedDuration ? clamp(this._currentTime / this.computedDuration, 0, 1) : 0;
6157
6232
  }
6158
6233
  isInsideTimeRange() {
6159
6234
  const current = this._currentTime;
@@ -6178,60 +6253,239 @@ exports.TimelineNode = class TimelineNode extends exports.Node {
6178
6253
  this._updateCurrentTime();
6179
6254
  }
6180
6255
  };
6181
- __decorateClass$Q([
6256
+ __decorateClass$R([
6182
6257
  modernIdoc.property({ fallback: 0 })
6183
6258
  ], exports.TimelineNode.prototype, "delay", 2);
6184
- __decorateClass$Q([
6259
+ __decorateClass$R([
6185
6260
  modernIdoc.property({ fallback: 0 })
6186
6261
  ], exports.TimelineNode.prototype, "duration", 2);
6187
- __decorateClass$Q([
6262
+ __decorateClass$R([
6188
6263
  modernIdoc.property({ fallback: false })
6189
6264
  ], exports.TimelineNode.prototype, "paused", 2);
6190
- __decorateClass$Q([
6265
+ __decorateClass$R([
6191
6266
  modernIdoc.property({ protected: true, fallback: false })
6192
6267
  ], exports.TimelineNode.prototype, "insideTimeRange", 2);
6193
- exports.TimelineNode = __decorateClass$Q([
6268
+ exports.TimelineNode = __decorateClass$R([
6194
6269
  customNode("TimelineNode")
6195
6270
  ], exports.TimelineNode);
6196
6271
 
6197
- var __defProp$H = Object.defineProperty;
6198
- var __getOwnPropDesc$G = Object.getOwnPropertyDescriptor;
6199
- var __decorateClass$P = (decorators, target, key, kind) => {
6200
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$G(target, key) : target;
6272
+ var __defProp$G = Object.defineProperty;
6273
+ var __getOwnPropDesc$H = Object.getOwnPropertyDescriptor;
6274
+ var __decorateClass$Q = (decorators, target, key, kind) => {
6275
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$H(target, key) : target;
6201
6276
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
6202
6277
  if (decorator = decorators[i])
6203
6278
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
6204
- if (kind && result) __defProp$H(target, key, result);
6279
+ if (kind && result) __defProp$G(target, key, result);
6205
6280
  return result;
6206
6281
  };
6207
- exports.Viewport = class Viewport extends exports.Node {
6208
- constructor(flipY = false) {
6209
- super();
6210
- this.flipY = flipY;
6211
- this._projection.flipY(flipY);
6212
- }
6213
- _projection = new Projection2D();
6214
- _framebufferIndex = 0;
6215
- _framebuffers = [
6216
- { texture: new ViewportTexture(), needsUpload: false },
6217
- { texture: new ViewportTexture(), needsUpload: false }
6218
- ];
6219
- get valid() {
6220
- return Boolean(this.width && this.height);
6221
- }
6222
- get framebuffer() {
6223
- return this._framebuffers[this._framebufferIndex];
6282
+ exports.CanvasItem = class CanvasItem extends exports.TimelineNode {
6283
+ _parentGlobalVisible;
6284
+ _globalVisible;
6285
+ get globalVisible() {
6286
+ return this._globalVisible ?? true;
6224
6287
  }
6225
- get texture() {
6226
- return this.framebuffer.texture;
6288
+ _parentGlobalOpacity;
6289
+ _globalOpacity;
6290
+ get globalOpacity() {
6291
+ return this._globalOpacity ?? 1;
6227
6292
  }
6228
- /** @internal */
6229
- _glFramebufferOptions(renderer) {
6230
- const { width, height } = this;
6231
- const { pixelRatio } = renderer;
6232
- this._framebuffers.forEach((framebuffer) => {
6233
- const texture = framebuffer.texture;
6234
- texture.width = width;
6293
+ _modulate = new Color(4294967295);
6294
+ // Batch render
6295
+ context = new CanvasContext();
6296
+ _resetContext = true;
6297
+ _redrawing = true;
6298
+ _relayouting = false;
6299
+ _repainting = false;
6300
+ _originalBatchables = [];
6301
+ _layoutedBatchables = [];
6302
+ _batchables = [];
6303
+ constructor(properties, nodes = []) {
6304
+ super();
6305
+ this.setProperties(properties).append(nodes);
6306
+ }
6307
+ _updateProperty(key, value, oldValue, declaration) {
6308
+ super._updateProperty(key, value, oldValue, declaration);
6309
+ switch (key) {
6310
+ case "modulate":
6311
+ this._modulate.value = value;
6312
+ this.requestRepaint();
6313
+ break;
6314
+ case "blendMode":
6315
+ this.requestRepaint();
6316
+ break;
6317
+ case "opacity":
6318
+ this._updateGlobalOpacity();
6319
+ break;
6320
+ case "visible":
6321
+ case "insideTimeRange":
6322
+ this._updateGlobalVisible();
6323
+ break;
6324
+ }
6325
+ }
6326
+ show() {
6327
+ this.visible = true;
6328
+ }
6329
+ hide() {
6330
+ this.visible = false;
6331
+ }
6332
+ isVisibleInTree() {
6333
+ return this.globalOpacity > 0 && this.globalVisible;
6334
+ }
6335
+ canRender() {
6336
+ return super.canRender() && this.isVisibleInTree();
6337
+ }
6338
+ requestRedraw() {
6339
+ this._redrawing = true;
6340
+ }
6341
+ requestRelayout() {
6342
+ this._relayouting = true;
6343
+ }
6344
+ requestRepaint() {
6345
+ this._repainting = true;
6346
+ }
6347
+ _updateGlobalVisible() {
6348
+ this._parentGlobalVisible = this.getParent()?.globalVisible;
6349
+ this._globalVisible = (this._parentGlobalVisible ?? true) && this.visible && this.insideTimeRange;
6350
+ }
6351
+ _updateGlobalOpacity() {
6352
+ this._parentGlobalOpacity = this.getParent()?.opacity;
6353
+ const globalOpacity = clamp(this.opacity, 0, 1) * (this._parentGlobalOpacity ?? 1);
6354
+ if (this._globalOpacity !== globalOpacity) {
6355
+ this._globalOpacity = globalOpacity;
6356
+ this.requestRepaint();
6357
+ }
6358
+ }
6359
+ _draw() {
6360
+ this.emit("draw");
6361
+ }
6362
+ _redraw() {
6363
+ this.log(this.name, "drawing");
6364
+ this._draw();
6365
+ return this.context.toBatchables();
6366
+ }
6367
+ _relayout(batchables) {
6368
+ this.log(this.name, "layouting");
6369
+ return batchables;
6370
+ }
6371
+ _repaint(batchables) {
6372
+ this.log(this.name, "painting");
6373
+ return batchables.map((batchable) => {
6374
+ return {
6375
+ ...batchable,
6376
+ modulate: this._modulate.toArgb(this.globalOpacity, true),
6377
+ blendMode: this.blendMode
6378
+ };
6379
+ });
6380
+ }
6381
+ _process(delta) {
6382
+ super._process(delta);
6383
+ const parent = this.getParent();
6384
+ if (this._parentGlobalVisible !== parent?.globalVisible) {
6385
+ this._updateGlobalVisible();
6386
+ }
6387
+ if (this._parentGlobalOpacity !== parent?.globalOpacity) {
6388
+ this._updateGlobalOpacity();
6389
+ }
6390
+ }
6391
+ _updateBatchables() {
6392
+ const redrawing = this._redrawing;
6393
+ let relayouting = this._relayouting;
6394
+ let repainting = this._repainting;
6395
+ let batchables;
6396
+ if (redrawing) {
6397
+ this._originalBatchables = this._redraw();
6398
+ relayouting = true;
6399
+ }
6400
+ if (relayouting) {
6401
+ this._layoutedBatchables = this._relayout(this._originalBatchables);
6402
+ repainting = true;
6403
+ }
6404
+ if (repainting) {
6405
+ batchables = this._repaint(this._layoutedBatchables);
6406
+ }
6407
+ if (redrawing) {
6408
+ if (this._resetContext) {
6409
+ this.context.reset();
6410
+ }
6411
+ }
6412
+ if (batchables) {
6413
+ this._batchables = batchables;
6414
+ this._redrawing = false;
6415
+ this._relayouting = false;
6416
+ this._repainting = false;
6417
+ }
6418
+ }
6419
+ _render(renderer) {
6420
+ this._updateBatchables();
6421
+ this._batchables.forEach((batchable) => {
6422
+ batchable.texture?.upload(renderer);
6423
+ renderer.batch2D.render({
6424
+ ...batchable,
6425
+ texture: batchable.texture?._glTexture(renderer)
6426
+ });
6427
+ });
6428
+ super._render(renderer);
6429
+ }
6430
+ };
6431
+ __decorateClass$Q([
6432
+ modernIdoc.property()
6433
+ ], exports.CanvasItem.prototype, "modulate", 2);
6434
+ __decorateClass$Q([
6435
+ modernIdoc.property()
6436
+ ], exports.CanvasItem.prototype, "blendMode", 2);
6437
+ __decorateClass$Q([
6438
+ modernIdoc.property({ protected: true, fallback: true })
6439
+ ], exports.CanvasItem.prototype, "visible", 2);
6440
+ __decorateClass$Q([
6441
+ modernIdoc.property({ protected: true, fallback: 1 })
6442
+ ], exports.CanvasItem.prototype, "opacity", 2);
6443
+ exports.CanvasItem = __decorateClass$Q([
6444
+ customNode("CanvasItem")
6445
+ ], exports.CanvasItem);
6446
+
6447
+ var __defProp$F = Object.defineProperty;
6448
+ var __getOwnPropDesc$G = Object.getOwnPropertyDescriptor;
6449
+ var __decorateClass$P = (decorators, target, key, kind) => {
6450
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$G(target, key) : target;
6451
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
6452
+ if (decorator = decorators[i])
6453
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
6454
+ if (kind && result) __defProp$F(target, key, result);
6455
+ return result;
6456
+ };
6457
+ exports.Viewport = class Viewport extends exports.Node {
6458
+ constructor(flipY = false) {
6459
+ super();
6460
+ this.flipY = flipY;
6461
+ this.projection.flipY(flipY);
6462
+ }
6463
+ projection = new Projection2D();
6464
+ canvasTransform = new Transform2D();
6465
+ _framebufferIndex = 0;
6466
+ _framebuffers = [
6467
+ { texture: new ViewportTexture(), needsUpload: false },
6468
+ { texture: new ViewportTexture(), needsUpload: false }
6469
+ ];
6470
+ get valid() {
6471
+ return Boolean(this.width && this.height);
6472
+ }
6473
+ get framebuffer() {
6474
+ return this._framebuffers[this._framebufferIndex];
6475
+ }
6476
+ get texture() {
6477
+ return this.framebuffer.texture;
6478
+ }
6479
+ getViewport() {
6480
+ return this;
6481
+ }
6482
+ /** @internal */
6483
+ _glFramebufferOptions(renderer) {
6484
+ const { width, height } = this;
6485
+ const { pixelRatio } = renderer;
6486
+ this._framebuffers.forEach((framebuffer) => {
6487
+ const texture = framebuffer.texture;
6488
+ texture.width = width;
6235
6489
  texture.height = height;
6236
6490
  texture.pixelRatio = pixelRatio;
6237
6491
  texture.upload(renderer);
@@ -6256,13 +6510,13 @@ exports.Viewport = class Viewport extends exports.Node {
6256
6510
  case "x":
6257
6511
  case "y":
6258
6512
  this.requestUpload();
6259
- this._projection.translate(this.x, this.y);
6513
+ this.projection.translate(this.x, this.y);
6260
6514
  this.emit("updateRect");
6261
6515
  break;
6262
6516
  case "width":
6263
6517
  case "height":
6264
6518
  this.requestUpload();
6265
- this._projection.resize(this.width, this.height);
6519
+ this.projection.resize(this.width, this.height);
6266
6520
  this.emit("updateRect");
6267
6521
  break;
6268
6522
  }
@@ -6321,6 +6575,8 @@ exports.Viewport = class Viewport extends exports.Node {
6321
6575
  }
6322
6576
  render(renderer, next) {
6323
6577
  const oldViewport = this._tree?.getCurrentViewport();
6578
+ renderer.program.uniforms.projectionMatrix = this.projection.toArray(true);
6579
+ renderer.program.uniforms.worldTransformMatrix = this.canvasTransform.toArray(true);
6324
6580
  this.activate(renderer);
6325
6581
  renderer.clear();
6326
6582
  super.render(renderer, next);
@@ -6335,9 +6591,6 @@ exports.Viewport = class Viewport extends exports.Node {
6335
6591
  getRect() {
6336
6592
  return new Rect2(this.x, this.y, this.width, this.height);
6337
6593
  }
6338
- toProjectionArray(transpose = false) {
6339
- return this._projection.toArray(transpose);
6340
- }
6341
6594
  };
6342
6595
  __decorateClass$P([
6343
6596
  modernIdoc.property({ fallback: 0 })
@@ -6355,14 +6608,14 @@ exports.Viewport = __decorateClass$P([
6355
6608
  customNode("Viewport")
6356
6609
  ], exports.Viewport);
6357
6610
 
6358
- var __defProp$G = Object.defineProperty;
6611
+ var __defProp$E = Object.defineProperty;
6359
6612
  var __getOwnPropDesc$F = Object.getOwnPropertyDescriptor;
6360
6613
  var __decorateClass$O = (decorators, target, key, kind) => {
6361
6614
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$F(target, key) : target;
6362
6615
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
6363
6616
  if (decorator = decorators[i])
6364
6617
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
6365
- if (kind && result) __defProp$G(target, key, result);
6618
+ if (kind && result) __defProp$E(target, key, result);
6366
6619
  return result;
6367
6620
  };
6368
6621
  exports.Effect = class Effect extends exports.TimelineNode {
@@ -6620,1044 +6873,1048 @@ exports.Effect = __decorateClass$O([
6620
6873
  customNode("Effect")
6621
6874
  ], exports.Effect);
6622
6875
 
6623
- var __defProp$F = Object.defineProperty;
6876
+ class RenderStack {
6877
+ currentCall;
6878
+ calls = [];
6879
+ createCall(renderable) {
6880
+ return {
6881
+ renderable,
6882
+ parentCall: this.currentCall,
6883
+ fn: renderable.render.bind(renderable),
6884
+ calls: []
6885
+ };
6886
+ }
6887
+ push(renderable) {
6888
+ const call = this.createCall(renderable);
6889
+ (this.currentCall?.calls ?? this.calls).push(call);
6890
+ return call;
6891
+ }
6892
+ render(renderer) {
6893
+ this.calls.forEach(function render(call) {
6894
+ call.fn(renderer, () => {
6895
+ call.calls.forEach(render);
6896
+ });
6897
+ });
6898
+ this.calls = [];
6899
+ }
6900
+ }
6901
+
6902
+ var __defProp$D = Object.defineProperty;
6624
6903
  var __getOwnPropDesc$E = Object.getOwnPropertyDescriptor;
6625
- var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$F(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6626
6904
  var __decorateClass$N = (decorators, target, key, kind) => {
6627
6905
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$E(target, key) : target;
6628
6906
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
6629
6907
  if (decorator = decorators[i])
6630
6908
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
6631
- if (kind && result) __defProp$F(target, key, result);
6909
+ if (kind && result) __defProp$D(target, key, result);
6632
6910
  return result;
6633
6911
  };
6634
- var __publicField$i = (obj, key, value) => __defNormalProp$i(obj, key + "" , value);
6635
- exports.ColorAdjustEffect = class ColorAdjustEffect extends exports.Effect {
6636
- constructor(properties, children = []) {
6637
- super();
6638
- this.setProperties(properties).append(children);
6639
- }
6640
- apply(renderer, source) {
6641
- source.redraw(renderer, () => {
6642
- QuadUvGeometry.draw(renderer, exports.ColorAdjustEffect.material, {
6643
- sampler: 0,
6644
- saturation: this.saturation,
6645
- contrast: this.contrast,
6646
- brightness: this.brightness,
6647
- red: this.red,
6648
- green: this.green,
6649
- blue: this.blue,
6650
- alpha: this.alpha,
6651
- gamma: Math.max(this.gamma ?? 1, 1e-4)
6652
- });
6912
+ exports.Timeline = class Timeline extends exports.Node {
6913
+ static from(range, loop = false) {
6914
+ const [startTime, endTime] = range ? Array.isArray(range) ? range : [0, range] : [];
6915
+ return new exports.Timeline({
6916
+ startTime,
6917
+ endTime,
6918
+ loop
6653
6919
  });
6654
6920
  }
6655
- };
6656
- __publicField$i(exports.ColorAdjustEffect, "material", new Material({
6657
- vert: `precision mediump float;
6658
- attribute vec2 position;
6659
- attribute vec2 uv;
6660
- varying vec2 vUv;
6661
- void main() {
6662
- gl_Position = vec4(position, 0.0, 1.0);
6663
- vUv = uv;
6664
- }`,
6665
- frag: `varying vec2 vUv;
6666
- uniform sampler2D sampler;
6667
- uniform float gamma;
6668
- uniform float contrast;
6669
- uniform float saturation;
6670
- uniform float brightness;
6671
- uniform float red;
6672
- uniform float green;
6673
- uniform float blue;
6674
- uniform float alpha;
6675
-
6676
- void main(void) {
6677
- vec4 c = texture2D(sampler, vUv);
6678
- if (c.a > 0.0) {
6679
- c.rgb /= c.a;
6680
- vec3 rgb = pow(c.rgb, vec3(1. / gamma));
6681
- rgb = mix(vec3(.5), mix(vec3(dot(vec3(.2125, .7154, .0721), rgb)), rgb, saturation), contrast);
6682
- rgb.r *= red;
6683
- rgb.g *= green;
6684
- rgb.b *= blue;
6685
- c.rgb = rgb * brightness;
6686
- c.rgb *= c.a;
6921
+ constructor(properties) {
6922
+ super();
6923
+ this.setProperties(properties);
6687
6924
  }
6688
- gl_FragColor = c * alpha;
6689
- }`
6690
- }));
6691
- __decorateClass$N([
6692
- modernIdoc.property()
6693
- ], exports.ColorAdjustEffect.prototype, "saturation", 2);
6694
- __decorateClass$N([
6695
- modernIdoc.property()
6696
- ], exports.ColorAdjustEffect.prototype, "contrast", 2);
6697
- __decorateClass$N([
6698
- modernIdoc.property()
6699
- ], exports.ColorAdjustEffect.prototype, "brightness", 2);
6700
- __decorateClass$N([
6701
- modernIdoc.property()
6702
- ], exports.ColorAdjustEffect.prototype, "red", 2);
6925
+ _updateProperty(key, value, oldValue) {
6926
+ super._updateProperty(key, value, oldValue);
6927
+ switch (key) {
6928
+ case "startTime":
6929
+ this.startTime = Math.min(value, this.endTime);
6930
+ break;
6931
+ case "endTime":
6932
+ this.endTime = value || Number.MAX_SAFE_INTEGER;
6933
+ break;
6934
+ }
6935
+ }
6936
+ addTime(delta) {
6937
+ const start = this.startTime;
6938
+ const end = this.endTime;
6939
+ let current = this.currentTime;
6940
+ current = current + delta;
6941
+ if (this.loop && current > end) {
6942
+ current = start + current % end;
6943
+ }
6944
+ current = clamp(current, start, end);
6945
+ this.currentTime = current;
6946
+ this.emit("updateCurrentTime", current, delta);
6947
+ return this;
6948
+ }
6949
+ _process(delta) {
6950
+ super._process(delta);
6951
+ this.addTime(delta);
6952
+ }
6953
+ };
6703
6954
  __decorateClass$N([
6704
- modernIdoc.property()
6705
- ], exports.ColorAdjustEffect.prototype, "green", 2);
6955
+ modernIdoc.property({ fallback: 0 })
6956
+ ], exports.Timeline.prototype, "startTime", 2);
6706
6957
  __decorateClass$N([
6707
- modernIdoc.property()
6708
- ], exports.ColorAdjustEffect.prototype, "blue", 2);
6958
+ modernIdoc.property({ fallback: 0 })
6959
+ ], exports.Timeline.prototype, "currentTime", 2);
6709
6960
  __decorateClass$N([
6710
- modernIdoc.property()
6711
- ], exports.ColorAdjustEffect.prototype, "alpha", 2);
6961
+ modernIdoc.property({ fallback: Number.MAX_SAFE_INTEGER })
6962
+ ], exports.Timeline.prototype, "endTime", 2);
6712
6963
  __decorateClass$N([
6713
- modernIdoc.property()
6714
- ], exports.ColorAdjustEffect.prototype, "gamma", 2);
6715
- exports.ColorAdjustEffect = __decorateClass$N([
6716
- customNode("ColorAdjustEffect")
6717
- ], exports.ColorAdjustEffect);
6964
+ modernIdoc.property({ fallback: false })
6965
+ ], exports.Timeline.prototype, "loop", 2);
6966
+ exports.Timeline = __decorateClass$N([
6967
+ customNode("Timeline")
6968
+ ], exports.Timeline);
6718
6969
 
6719
- var __defProp$E = Object.defineProperty;
6720
6970
  var __getOwnPropDesc$D = Object.getOwnPropertyDescriptor;
6721
- var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$E(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6722
6971
  var __decorateClass$M = (decorators, target, key, kind) => {
6723
6972
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$D(target, key) : target;
6724
6973
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
6725
6974
  if (decorator = decorators[i])
6726
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
6727
- if (kind && result) __defProp$E(target, key, result);
6975
+ result = (decorator(result)) || result;
6728
6976
  return result;
6729
6977
  };
6730
- var __publicField$h = (obj, key, value) => __defNormalProp$h(obj, key + "" , value);
6731
- exports.ColorFilterEffect = class ColorFilterEffect extends exports.Effect {
6732
- _colorMatrix = new ColorMatrix();
6733
- constructor(properties, children = []) {
6734
- super();
6735
- this.setProperties(properties).append(children);
6736
- }
6737
- apply(renderer, source) {
6738
- if (!this.filter)
6739
- return;
6740
- const funs = parseCssFunctions(this.filter);
6741
- const matrix = this._colorMatrix.identity();
6742
- funs.forEach(({ name, args }) => {
6743
- const values = args.map((arg) => arg.normalizedIntValue);
6744
- switch (name) {
6745
- case "hue-rotate":
6746
- case "hueRotate":
6747
- matrix.hueRotate(values[0] * PI_2);
6748
- break;
6749
- case "saturate":
6750
- matrix.saturate(values[0]);
6751
- break;
6752
- case "brightness":
6753
- matrix.brightness(values[0]);
6754
- break;
6755
- case "contrast":
6756
- matrix.contrast(values[0]);
6757
- break;
6758
- case "invert":
6759
- matrix.invert(values[0]);
6760
- break;
6761
- case "sepia":
6762
- matrix.sepia(values[0]);
6763
- break;
6764
- case "opacity":
6765
- matrix.opacity(values[0]);
6766
- break;
6767
- case "grayscale":
6768
- matrix.grayscale(values[0]);
6769
- break;
6770
- }
6771
- });
6772
- source.redraw(renderer, () => {
6773
- QuadUvGeometry.draw(renderer, exports.ColorFilterEffect.material, {
6774
- sampler: 0,
6775
- m: matrix.toArray()
6776
- });
6777
- });
6778
- }
6978
+ exports.Window = class Window extends exports.Viewport {
6979
+ //
6779
6980
  };
6780
- __publicField$h(exports.ColorFilterEffect, "material", new Material({
6781
- vert: `precision mediump float;
6782
- attribute vec2 position;
6783
- attribute vec2 uv;
6784
- varying vec2 vUv;
6785
- void main() {
6786
- gl_Position = vec4(position, 0.0, 1.0);
6787
- vUv = uv;
6788
- }`,
6789
- frag: `precision highp float;
6790
- varying vec2 vUv;
6791
- uniform sampler2D sampler;
6792
- uniform float m[20];
6793
-
6794
- void main(void) {
6795
- vec4 c = texture2D(sampler, vUv);
6796
- if (c.a > 0.0) {
6797
- c.rgb /= c.a;
6798
- }
6799
- gl_FragColor = vec4(
6800
- m[0] * c.r + m[1] * c.g + m[2] * c.b + m[3] * c.a + m[4] / 255.0,
6801
- m[5] * c.r + m[6] * c.g + m[7] * c.b + m[8] * c.a + m[9] / 255.0,
6802
- m[10] * c.r + m[11] * c.g + m[12] * c.b + m[13] * c.a + m[14] / 255.0,
6803
- m[15] * c.r + m[16] * c.g + m[17] * c.b + m[18] * c.a + m[19] / 255.0
6804
- );
6805
- }`
6806
- }));
6807
- __decorateClass$M([
6808
- modernIdoc.property()
6809
- ], exports.ColorFilterEffect.prototype, "filter", 2);
6810
- exports.ColorFilterEffect = __decorateClass$M([
6811
- customNode("ColorFilterEffect")
6812
- ], exports.ColorFilterEffect);
6981
+ exports.Window = __decorateClass$M([
6982
+ customNode("Window")
6983
+ ], exports.Window);
6813
6984
 
6814
- var __defProp$D = Object.defineProperty;
6815
- var __getOwnPropDesc$C = Object.getOwnPropertyDescriptor;
6816
- var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$D(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6985
+ var __defProp$C = Object.defineProperty;
6817
6986
  var __decorateClass$L = (decorators, target, key, kind) => {
6818
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$C(target, key) : target;
6987
+ var result = void 0 ;
6819
6988
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
6820
6989
  if (decorator = decorators[i])
6821
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
6822
- if (kind && result) __defProp$D(target, key, result);
6990
+ result = (decorator(target, key, result) ) || result;
6991
+ if (result) __defProp$C(target, key, result);
6823
6992
  return result;
6824
6993
  };
6825
- var __publicField$g = (obj, key, value) => __defNormalProp$g(obj, key + "" , value);
6826
- const MAX_COLORS$1 = 50;
6827
- exports.ColorOverlayEffect = class ColorOverlayEffect extends exports.Effect {
6828
- _color = new Color();
6829
- constructor(properties, children = []) {
6830
- super();
6831
- this.setProperties(properties).append(children);
6994
+ class SceneTree extends MainLoop {
6995
+ input = new Input();
6996
+ renderStack = new RenderStack();
6997
+ root = new exports.Window(true).setTree(this);
6998
+ timeline;
6999
+ _backgroundColor = new Color();
7000
+ _currentViewport;
7001
+ getCurrentViewport() {
7002
+ return this._currentViewport;
6832
7003
  }
6833
- apply(renderer, source) {
6834
- source.redraw(renderer, () => {
6835
- const colors = this.colors.map((val) => {
6836
- this._color.value = val;
6837
- const rgba = this._color.toArray();
6838
- rgba[3] = this.alpha;
6839
- return rgba;
6840
- });
6841
- while (colors.length < MAX_COLORS$1) {
6842
- colors.push([0, 0, 0, 0]);
6843
- }
6844
- QuadUvGeometry.draw(renderer, exports.ColorOverlayEffect.material, {
6845
- sampler: 0,
6846
- colors: colors.slice(0, MAX_COLORS$1).flatMap((item) => item)
6847
- });
6848
- });
7004
+ setCurrentViewport(viewport) {
7005
+ this._currentViewport = viewport;
6849
7006
  }
6850
- };
6851
- __publicField$g(exports.ColorOverlayEffect, "material", new Material({
6852
- vert: `precision mediump float;
6853
- attribute vec2 position;
6854
- attribute vec2 uv;
6855
- varying vec2 vUv;
6856
- void main() {
6857
- gl_Position = vec4(position, 0.0, 1.0);
6858
- vUv = uv;
6859
- }`,
6860
- frag: `precision mediump float;
6861
- uniform sampler2D sampler;
6862
- uniform vec4 colors[${MAX_COLORS$1}];
6863
- varying vec2 vUv;
6864
-
6865
- float calcWidth() {
6866
- return distance(vec2(0, 0), vec2(1, 0));
6867
- }
6868
-
6869
- int calcCount() {
6870
- int count = 0;
6871
- for (int i = 0; i < ${MAX_COLORS$1}; i++) {
6872
- if (colors[i] != vec4(0,0,0,0)){
6873
- count++;
6874
- }
7007
+ constructor(timeline = new exports.Timeline()) {
7008
+ super();
7009
+ this.timeline = timeline.setTree(this);
7010
+ }
7011
+ _updateProperty(key, value, oldValue, declaration) {
7012
+ super._updateProperty(key, value, oldValue, declaration);
7013
+ switch (key) {
7014
+ case "backgroundColor":
7015
+ this._backgroundColor.value = value;
7016
+ break;
6875
7017
  }
6876
- return count;
6877
- }
6878
-
6879
- vec4 calcColor(float x) {
6880
- float perUnit = calcWidth() / float(calcCount());
6881
- int index = int(x / perUnit);
6882
-
6883
- for(int i=0; i<${MAX_COLORS$1}; i++){
6884
- if(i==index){
6885
- return colors[i];
7018
+ }
7019
+ log(...args) {
7020
+ if (this.debug) {
7021
+ console.log(`[modern-canvas][${performance.now().toFixed(4)}ms]`, ...args);
6886
7022
  }
6887
7023
  }
6888
-
6889
- return vec4(0, 0, 0, 0);
7024
+ _process(delta = 0) {
7025
+ this.timeline.emit("process", delta);
7026
+ this.emit("processing");
7027
+ this.root.emit("process", delta);
7028
+ this.emit("processed");
7029
+ }
7030
+ _render(renderer) {
7031
+ this.emit("rendering");
7032
+ this.renderStack.render(renderer);
7033
+ this._renderScreen(renderer);
7034
+ this.emit("rendered");
7035
+ }
7036
+ _renderScreen(renderer) {
7037
+ renderer.state.reset();
7038
+ renderer.framebuffer.bind(null);
7039
+ renderer.viewport.bind({
7040
+ x: 0,
7041
+ y: 0,
7042
+ width: this.root.width * renderer.pixelRatio,
7043
+ height: this.root.height * renderer.pixelRatio
7044
+ });
7045
+ if (this.backgroundColor) {
7046
+ renderer.gl.clearColor(...this._backgroundColor.toArray());
7047
+ }
7048
+ renderer.clear();
7049
+ if (this.backgroundColor) {
7050
+ renderer.gl.clearColor(0, 0, 0, 0);
7051
+ }
7052
+ const texture = this.root.texture;
7053
+ texture.activate(renderer, 0);
7054
+ QuadUvGeometry.draw(renderer);
7055
+ renderer.texture.unbind(texture);
7056
+ }
7057
+ free() {
7058
+ super.free();
7059
+ this.root.children.internal.forEach((node) => this.root.removeChild(node));
7060
+ this.input.removeEventListeners();
7061
+ }
6890
7062
  }
6891
-
6892
- void main(void) {
6893
- vec4 color = texture2D(sampler, vUv);
6894
- vec4 mask = calcColor(vUv.x);
6895
- gl_FragColor = vec4(mix(color.rgb, mask.rgb, color.a * mask.a), color.a);
6896
- }`
6897
- }));
6898
7063
  __decorateClass$L([
6899
- modernIdoc.property()
6900
- ], exports.ColorOverlayEffect.prototype, "colors", 2);
7064
+ modernIdoc.property({ fallback: false })
7065
+ ], SceneTree.prototype, "processPaused");
6901
7066
  __decorateClass$L([
6902
7067
  modernIdoc.property()
6903
- ], exports.ColorOverlayEffect.prototype, "alpha", 2);
6904
- exports.ColorOverlayEffect = __decorateClass$L([
6905
- customNode("ColorOverlayEffect")
6906
- ], exports.ColorOverlayEffect);
7068
+ ], SceneTree.prototype, "backgroundColor");
7069
+ __decorateClass$L([
7070
+ modernIdoc.property({ protected: true, fallback: false })
7071
+ ], SceneTree.prototype, "debug");
6907
7072
 
6908
- var __defProp$C = Object.defineProperty;
6909
- var __getOwnPropDesc$B = Object.getOwnPropertyDescriptor;
6910
- var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$C(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7073
+ var __getOwnPropDesc$C = Object.getOwnPropertyDescriptor;
6911
7074
  var __decorateClass$K = (decorators, target, key, kind) => {
6912
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$B(target, key) : target;
7075
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$C(target, key) : target;
6913
7076
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
6914
7077
  if (decorator = decorators[i])
6915
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
6916
- if (kind && result) __defProp$C(target, key, result);
7078
+ result = (decorator(result)) || result;
6917
7079
  return result;
6918
7080
  };
6919
- var __publicField$f = (obj, key, value) => __defNormalProp$f(obj, key + "" , value);
6920
- exports.ColorRemoveEffect = class ColorRemoveEffect extends exports.Effect {
6921
- _color = new Color();
7081
+ exports.Transition = class Transition extends exports.Effect {
6922
7082
  constructor(properties, children = []) {
6923
7083
  super();
6924
7084
  this.setProperties(properties).append(children);
6925
7085
  }
6926
- apply(renderer, source) {
6927
- const maxColors = 50;
6928
- const originalColors = new Float32Array(maxColors * 3);
6929
- const colors = this.colors.map((val) => {
6930
- this._color.value = val;
6931
- return this._color.toArray().slice(0, 3);
6932
- });
6933
- while (colors.length < maxColors) {
6934
- colors.push([-1, 0, 0]);
6935
- }
6936
- colors.slice(0, maxColors).forEach((originalColor, i) => {
6937
- originalColors[i * 3] = originalColor[0];
6938
- originalColors[i * 3 + 1] = originalColor[1];
6939
- originalColors[i * 3 + 2] = originalColor[2];
6940
- });
6941
- source.redraw(renderer, () => {
6942
- QuadUvGeometry.draw(renderer, exports.ColorRemoveEffect.material, {
6943
- sampler: 0,
6944
- epsilon: this.epsilon,
6945
- originalColors
6946
- });
6947
- });
6948
- }
6949
7086
  };
6950
- __publicField$f(exports.ColorRemoveEffect, "material", new Material({
6951
- vert: `precision mediump float;
6952
- attribute vec2 position;
6953
- attribute vec2 uv;
6954
- varying vec2 vUv;
6955
- void main() {
6956
- gl_Position = vec4(position, 0.0, 1.0);
6957
- vUv = uv;
6958
- }`,
6959
- frag: `varying vec2 vUv;
6960
- uniform sampler2D sampler;
6961
- uniform float epsilon;
6962
- const int MAX_COLORS = 50;
6963
- uniform vec3 originalColors[MAX_COLORS];
6964
-
6965
- void main(void) {
6966
- vec4 color = texture2D(sampler, vUv);
6967
-
6968
- for (int i = 0; i < MAX_COLORS; i++) {
6969
- vec3 origColor = originalColors[i];
6970
- if (origColor.r < 0.0) {
6971
- break;
6972
- }
6973
- vec3 colorDiff = origColor - color.rgb;
6974
- if (length(colorDiff) < epsilon) {
6975
- gl_FragColor = vec4(0, 0, 0, 0);
6976
- return;
6977
- }
6978
- }
6979
-
6980
- gl_FragColor = color;
6981
- }`
6982
- }));
6983
- __decorateClass$K([
6984
- modernIdoc.property()
6985
- ], exports.ColorRemoveEffect.prototype, "colors", 2);
6986
- __decorateClass$K([
6987
- modernIdoc.property()
6988
- ], exports.ColorRemoveEffect.prototype, "epsilon", 2);
6989
- exports.ColorRemoveEffect = __decorateClass$K([
6990
- customNode("ColorRemoveEffect")
6991
- ], exports.ColorRemoveEffect);
7087
+ exports.Transition = __decorateClass$K([
7088
+ customNode("Transition", {
7089
+ effectMode: "transition",
7090
+ processMode: "pausable",
7091
+ duration: 2e3
7092
+ })
7093
+ ], exports.Transition);
6992
7094
 
6993
7095
  var __defProp$B = Object.defineProperty;
6994
- var __getOwnPropDesc$A = Object.getOwnPropertyDescriptor;
6995
- var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$B(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7096
+ var __getOwnPropDesc$B = Object.getOwnPropertyDescriptor;
6996
7097
  var __decorateClass$J = (decorators, target, key, kind) => {
6997
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$A(target, key) : target;
7098
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$B(target, key) : target;
6998
7099
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
6999
7100
  if (decorator = decorators[i])
7000
7101
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
7001
7102
  if (kind && result) __defProp$B(target, key, result);
7002
7103
  return result;
7003
7104
  };
7004
- var __publicField$e = (obj, key, value) => __defNormalProp$e(obj, key + "" , value);
7005
- const MAX_COLORS = 50;
7006
- exports.ColorReplaceEffect = class ColorReplaceEffect extends exports.Effect {
7007
- _color = new Color();
7008
- constructor(properties, children = []) {
7105
+ exports.Node2D = class Node2D extends exports.CanvasItem {
7106
+ position = new Vector2().on("update", () => this.updateGlobalTransform());
7107
+ scale = new Vector2(1, 1).on("update", () => this.updateGlobalTransform());
7108
+ skew = new Vector2().on("update", () => this.updateGlobalTransform());
7109
+ transform = new Transform2D();
7110
+ globalPosition = new Vector2();
7111
+ globalScale = new Vector2();
7112
+ globalSkew = new Vector2();
7113
+ globalTransform = new Transform2D();
7114
+ _parentTransformDirtyId;
7115
+ constructor(properties, nodes = []) {
7009
7116
  super();
7010
- this.setProperties(properties).append(children);
7117
+ this.setProperties(properties).append(nodes);
7011
7118
  }
7012
- apply(renderer, source) {
7013
- const colors = this.colors.map((val) => {
7014
- this._color.value = val[0];
7015
- const color0 = this._color.toArray().slice(0, 3);
7016
- this._color.value = val[1];
7017
- const color1 = this._color.toArray().slice(0, 3);
7018
- return [
7019
- color0,
7020
- color1
7021
- ];
7022
- });
7023
- const epsilon = this.epsilon;
7024
- const originalColors = new Float32Array(MAX_COLORS * 3);
7025
- const targetColors = new Float32Array(MAX_COLORS * 3);
7026
- while (colors.length < MAX_COLORS) {
7027
- colors.push([
7028
- [-1, 0, 0],
7029
- [0, 0, 0, 1]
7030
- ]);
7119
+ _updateProperty(key, value, oldValue, declaration) {
7120
+ super._updateProperty(key, value, oldValue, declaration);
7121
+ switch (key) {
7122
+ case "rotation":
7123
+ this.requestRelayout();
7124
+ break;
7031
7125
  }
7032
- colors.slice(0, MAX_COLORS).forEach(([originalColor, targetColor], i) => {
7033
- originalColors[i * 3] = originalColor[0];
7034
- originalColors[i * 3 + 1] = originalColor[1];
7035
- originalColors[i * 3 + 2] = originalColor[2];
7036
- targetColors[i * 3] = targetColor[0];
7037
- targetColors[i * 3 + 1] = targetColor[1];
7038
- targetColors[i * 3 + 2] = targetColor[2];
7039
- });
7040
- source.redraw(renderer, () => {
7041
- QuadUvGeometry.draw(renderer, exports.ColorReplaceEffect.material, {
7042
- sampler: 0,
7043
- epsilon,
7044
- originalColors,
7045
- targetColors
7046
- });
7047
- });
7048
- }
7049
- };
7050
- __publicField$e(exports.ColorReplaceEffect, "material", new Material({
7051
- vert: `precision mediump float;
7052
- attribute vec2 position;
7053
- attribute vec2 uv;
7054
- varying vec2 vUv;
7055
- void main() {
7056
- gl_Position = vec4(position, 0.0, 1.0);
7057
- vUv = uv;
7058
- }`,
7059
- frag: `varying vec2 vUv;
7060
- uniform sampler2D sampler;
7061
- uniform float epsilon;
7062
- const int MAX_COLORS = ${MAX_COLORS};
7063
- uniform vec3 originalColors[MAX_COLORS];
7064
- uniform vec3 targetColors[MAX_COLORS];
7065
-
7066
- void main(void) {
7067
- gl_FragColor = texture2D(sampler, vUv);
7068
-
7069
- float alpha = gl_FragColor.a;
7070
- if (alpha < 0.0001) {
7071
- return;
7072
7126
  }
7073
-
7074
- vec3 color = gl_FragColor.rgb / alpha;
7075
-
7076
- for(int i = 0; i < MAX_COLORS; i++) {
7077
- vec3 origColor = originalColors[i];
7078
- if (origColor.r < 0.0) {
7079
- break;
7080
- }
7081
- vec3 colorDiff = origColor - color;
7082
- if (length(colorDiff) < epsilon) {
7083
- vec3 targetColor = targetColors[i];
7084
- gl_FragColor = vec4((targetColor + colorDiff) * alpha, alpha);
7085
- return;
7086
- }
7127
+ getTransformOrigin() {
7128
+ return new Vector2(0, 0);
7087
7129
  }
7088
- }`
7089
- }));
7090
- __decorateClass$J([
7091
- modernIdoc.property()
7092
- ], exports.ColorReplaceEffect.prototype, "colors", 2);
7093
- __decorateClass$J([
7094
- modernIdoc.property()
7095
- ], exports.ColorReplaceEffect.prototype, "epsilon", 2);
7096
- exports.ColorReplaceEffect = __decorateClass$J([
7097
- customNode("ColorReplaceEffect")
7098
- ], exports.ColorReplaceEffect);
7099
-
7100
- class CanvasContext extends modernPath2d.Path2D {
7101
- fillStyle;
7102
- strokeStyle;
7103
- lineCap;
7104
- lineJoin;
7105
- lineWidth;
7106
- miterLimit;
7107
- // custom
7108
- uvTransform;
7109
- vertTransform;
7110
- _defaultStyle = Texture2D.EMPTY;
7111
- _draws = [];
7112
- _toTexture(source) {
7113
- if (source instanceof Texture2D) {
7114
- return source;
7130
+ getTransform(cb) {
7131
+ const origin = this.getTransformOrigin();
7132
+ const transform = new Transform2D();
7133
+ transform.translate(-origin.x, -origin.y).scale(this.scale.x, this.scale.y).skew(this.skew.x, this.skew.y).rotate(this.rotation);
7134
+ cb?.(transform);
7135
+ transform.translate(this.position.x, this.position.y).translate(origin.x, origin.y);
7136
+ return transform;
7137
+ }
7138
+ updateTransform() {
7139
+ this.transform.copy(this.getTransform());
7140
+ }
7141
+ updateGlobalTransform() {
7142
+ this.updateTransform();
7143
+ const parent = this.getParent();
7144
+ if (parent?.globalTransform) {
7145
+ this._parentTransformDirtyId = parent.globalTransform.dirtyId;
7146
+ this.globalScale.set(parent.globalScale.x * this.scale.x, parent.globalScale.y * this.scale.y);
7147
+ this.globalRotation = parent.globalRotation + this.rotation;
7148
+ parent.globalTransform.multiply(this.transform, this.globalTransform);
7115
7149
  } else {
7116
- return ColorTexture.get(source);
7150
+ this.globalScale.copy(this.scale);
7151
+ this.globalRotation = this.rotation;
7152
+ this.globalTransform.copy(this.transform);
7117
7153
  }
7154
+ const [
7155
+ a,
7156
+ c,
7157
+ tx,
7158
+ b,
7159
+ d,
7160
+ ty
7161
+ ] = this.globalTransform.toArray();
7162
+ this.globalPosition.set(tx, ty);
7163
+ this.globalSkew.x = Math.atan2(c, a) - this.globalRotation;
7164
+ this.globalSkew.y = Math.atan2(b, d) - this.globalRotation;
7165
+ this.requestRelayout();
7118
7166
  }
7119
- stroke(options) {
7120
- if (!this.curves.length) {
7121
- return;
7167
+ _transformVertices(vertices, vertTransform) {
7168
+ let a, c, tx, b, d, ty;
7169
+ if (vertTransform) {
7170
+ const globalTransform = this.globalTransform.clone();
7171
+ globalTransform.multiply(
7172
+ typeof vertTransform === "function" ? vertTransform?.() : vertTransform
7173
+ );
7174
+ [a, c, tx, b, d, ty] = globalTransform.toArray();
7175
+ } else {
7176
+ [a, c, tx, b, d, ty] = this.globalTransform.toArray();
7122
7177
  }
7123
- let strokeStyle = this.strokeStyle;
7124
- if (!strokeStyle && this.style.stroke) {
7125
- switch (typeof this.style.stroke) {
7126
- case "string":
7127
- strokeStyle = this.style.stroke;
7128
- break;
7129
- case "object":
7130
- if (modernIdoc.isColorFillObject(this.style.stroke)) {
7131
- strokeStyle = this.style.stroke.color;
7132
- }
7133
- break;
7134
- }
7178
+ const newVertices = vertices.slice();
7179
+ for (let len = vertices.length, i = 0; i < len; i += 2) {
7180
+ const x = vertices[i];
7181
+ const y = vertices[i + 1];
7182
+ newVertices[i] = a * x + c * y + tx;
7183
+ newVertices[i + 1] = b * x + d * y + ty;
7135
7184
  }
7136
- this._draws.push({
7137
- ...options,
7138
- type: "stroke",
7139
- path: new modernPath2d.Path2D(this),
7140
- texture: strokeStyle ? this._toTexture(strokeStyle) : this._defaultStyle,
7141
- uvTransform: this.uvTransform,
7142
- vertTransform: this.vertTransform,
7143
- style: {
7144
- alignment: 0.5,
7145
- cap: this.lineCap ?? "butt",
7146
- join: this.lineJoin ?? "miter",
7147
- width: this.lineWidth ?? 1,
7148
- miterLimit: this.miterLimit ?? 10
7149
- }
7150
- });
7151
- super.reset();
7152
- }
7153
- fillRect(x, y, width, height) {
7154
- this.rect(x, y, width, height).fill();
7185
+ return newVertices;
7155
7186
  }
7156
- strokeRect(x, y, width, height) {
7157
- this.rect(x, y, width, height).stroke();
7187
+ _relayout(batchables) {
7188
+ batchables = super._relayout(batchables);
7189
+ this.updateGlobalTransform();
7190
+ return batchables.map((batchable) => {
7191
+ return {
7192
+ ...batchable,
7193
+ vertices: this._transformVertices(batchable.vertices, batchable.vertTransform)
7194
+ };
7195
+ });
7158
7196
  }
7159
- fill(options) {
7160
- if (!this.curves.length) {
7161
- return;
7162
- }
7163
- let fillStyle = this.fillStyle;
7164
- if (!fillStyle && this.style.fill) {
7165
- switch (typeof this.style.fill) {
7166
- case "string":
7167
- fillStyle = this.style.fill;
7168
- break;
7169
- case "object":
7170
- if (modernIdoc.isColorFillObject(this.style.fill)) {
7171
- fillStyle = this.style.fill.color;
7172
- }
7173
- break;
7174
- }
7197
+ _process(delta) {
7198
+ super._process(delta);
7199
+ const parent = this.getParent();
7200
+ if (parent?.globalTransform && this._parentTransformDirtyId !== parent?.globalTransform?.dirtyId) {
7201
+ this.requestRelayout();
7175
7202
  }
7176
- this._draws.push({
7177
- ...options,
7178
- type: "fill",
7179
- path: new modernPath2d.Path2D(this),
7180
- texture: fillStyle ? this._toTexture(fillStyle) : this._defaultStyle,
7181
- uvTransform: this.uvTransform,
7182
- vertTransform: this.vertTransform
7183
- });
7184
- super.reset();
7185
7203
  }
7186
- copy(source) {
7187
- super.copy(source);
7188
- this.strokeStyle = source.strokeStyle;
7189
- this.fillStyle = source.fillStyle;
7190
- this.uvTransform = source.uvTransform;
7191
- this.vertTransform = source.vertTransform;
7192
- this.lineCap = source.lineCap;
7193
- this.lineJoin = source.lineJoin;
7194
- this.lineWidth = source.lineWidth;
7195
- this.miterLimit = source.miterLimit;
7196
- this._draws = source._draws.slice();
7204
+ };
7205
+ __decorateClass$J([
7206
+ modernIdoc.property({ protected: true, fallback: 0 })
7207
+ ], exports.Node2D.prototype, "rotation", 2);
7208
+ __decorateClass$J([
7209
+ modernIdoc.property({ protected: true, fallback: 0 })
7210
+ ], exports.Node2D.prototype, "globalRotation", 2);
7211
+ exports.Node2D = __decorateClass$J([
7212
+ customNode("Node2D")
7213
+ ], exports.Node2D);
7214
+
7215
+ var __getOwnPropDesc$A = Object.getOwnPropertyDescriptor;
7216
+ var __decorateClass$I = (decorators, target, key, kind) => {
7217
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$A(target, key) : target;
7218
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
7219
+ if (decorator = decorators[i])
7220
+ result = (decorator(result)) || result;
7221
+ return result;
7222
+ };
7223
+ exports.Camera2D = class Camera2D extends exports.Node2D {
7224
+ zoom = new Vector2(1, 1).on("update", () => this.updateCanvasTransform());
7225
+ maxZoom = new Vector2(6, 6);
7226
+ minZoom = new Vector2(0.1, 0.1);
7227
+ constructor(properties, nodes = []) {
7228
+ super();
7229
+ this.setProperties(properties).append(nodes);
7230
+ }
7231
+ addZoom(x, y = x) {
7232
+ this.zoom.set(
7233
+ clamp(this.zoom.x + x, this.minZoom.x, this.maxZoom.x),
7234
+ clamp(this.zoom.y + y, this.minZoom.y, this.maxZoom.y)
7235
+ );
7197
7236
  return this;
7198
7237
  }
7199
- reset() {
7200
- super.reset();
7201
- this.strokeStyle = void 0;
7202
- this.fillStyle = void 0;
7203
- this.uvTransform = void 0;
7204
- this.vertTransform = void 0;
7205
- this.lineCap = void 0;
7206
- this.lineJoin = void 0;
7207
- this.lineWidth = void 0;
7208
- this.miterLimit = void 0;
7209
- this._draws.length = 0;
7238
+ setZoom(x, y = x) {
7239
+ this.zoom.set(
7240
+ clamp(x, this.minZoom.x, this.maxZoom.x),
7241
+ clamp(y, this.minZoom.y, this.maxZoom.y)
7242
+ );
7210
7243
  return this;
7211
7244
  }
7212
- buildUvs(start, vertices, uvs, texture, uvTransform) {
7213
- if (texture) {
7214
- const _uvTransform = uvTransform ? typeof uvTransform === "function" ? uvTransform : (x, y) => uvTransform.applyToPoint(x, y) : uvTransform;
7215
- const w = texture.width;
7216
- const h = texture.height;
7217
- for (let len = vertices.length, i = start; i < len; i += 2) {
7218
- const x = vertices[i];
7219
- const y = vertices[i + 1];
7220
- let uvX;
7221
- let uvY;
7222
- if (_uvTransform) {
7223
- [uvX, uvY] = _uvTransform(x, y);
7224
- } else {
7225
- [uvX, uvY] = [x / w, y / h];
7245
+ _input(event, key) {
7246
+ super._input(event, key);
7247
+ if (key === "wheel") {
7248
+ const e = event;
7249
+ if (e.ctrlKey) {
7250
+ const isTouchPad = e.wheelDeltaY ? Math.abs(Math.abs(e.wheelDeltaY) - Math.abs(3 * e.deltaY)) < 3 : e.deltaMode === 0;
7251
+ if (!isTouchPad) {
7252
+ e.preventDefault();
7253
+ const oldZoom = this.zoom.x;
7254
+ this.addZoom(e.deltaY * -0.015);
7255
+ const ratio = 1 - this.zoom.x / oldZoom;
7256
+ this.position.add(
7257
+ (e.screenX - this.position.x) * ratio,
7258
+ (e.screenY - this.position.y) * ratio
7259
+ );
7226
7260
  }
7227
- uvs.push(uvX, uvY);
7228
- }
7229
- } else {
7230
- for (let len = vertices.length, i = start; i < len; i += 2) {
7231
- uvs.push(0, 0);
7232
- }
7233
- }
7234
- }
7235
- toBatchables() {
7236
- const batchables = [];
7237
- for (let len = this._draws.length, i = 0; i < len; i++) {
7238
- const current = this._draws[i];
7239
- const vertices = [];
7240
- const indices = [];
7241
- const uvs = [];
7242
- if (current.type === "fill") {
7243
- current.path.fillTriangulate({
7244
- vertices,
7245
- indices
7246
- });
7247
7261
  } else {
7248
- current.path.strokeTriangulate({
7249
- vertices,
7250
- indices,
7251
- lineStyle: current.style,
7252
- flipAlignment: false,
7253
- closed: true
7254
- });
7262
+ e.preventDefault();
7263
+ this.position.add(-e.deltaX, -e.deltaY);
7255
7264
  }
7256
- this.buildUvs(0, vertices, uvs, current.texture, current.uvTransform);
7257
- batchables.push({
7258
- vertices,
7259
- indices,
7260
- uvs,
7261
- texture: current.texture,
7262
- type: current.type,
7263
- disableWrapMode: current.disableWrapMode,
7264
- vertTransform: current.vertTransform
7265
- });
7266
7265
  }
7267
- return batchables;
7268
7266
  }
7269
- }
7270
-
7271
- var __defProp$A = Object.defineProperty;
7272
- var __getOwnPropDesc$z = Object.getOwnPropertyDescriptor;
7273
- var __decorateClass$I = (decorators, target, key, kind) => {
7274
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$z(target, key) : target;
7275
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
7276
- if (decorator = decorators[i])
7277
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
7278
- if (kind && result) __defProp$A(target, key, result);
7279
- return result;
7280
- };
7281
- exports.CanvasItem = class CanvasItem extends exports.TimelineNode {
7282
- _parentGlobalVisible;
7283
- _globalVisible;
7284
- get globalVisible() {
7285
- return this._globalVisible ?? true;
7267
+ updateTransform() {
7268
+ super.updateTransform();
7269
+ this.updateCanvasTransform();
7286
7270
  }
7287
- _parentGlobalOpacity;
7288
- _globalOpacity;
7289
- get globalOpacity() {
7290
- return this._globalOpacity ?? 1;
7271
+ updateCanvasTransform() {
7272
+ const viewport = this.getViewport();
7273
+ if (!viewport)
7274
+ return;
7275
+ viewport.canvasTransform.identity().scale(this.zoom.x, this.zoom.y).translate(this.position.x, this.position.y);
7276
+ this.emit("updateCanvasTransform");
7291
7277
  }
7292
- _modulate = new Color(4294967295);
7293
- // Batch render
7294
- context = new CanvasContext();
7295
- _resetContext = true;
7296
- _redrawing = true;
7297
- _relayouting = false;
7298
- _repainting = false;
7299
- _originalBatchables = [];
7300
- _layoutedBatchables = [];
7301
- _batchables = [];
7302
- constructor(properties, nodes = []) {
7303
- super();
7304
- this.setProperties(properties).append(nodes);
7278
+ };
7279
+ exports.Camera2D = __decorateClass$I([
7280
+ customNode("Camera2D", {
7281
+ processMode: "disabled",
7282
+ renderMode: "disabled"
7283
+ })
7284
+ ], exports.Camera2D);
7285
+
7286
+ const defaultFilters = {
7287
+ "brightness": 1,
7288
+ "contrast": 1,
7289
+ "grayscale": 0,
7290
+ "hue-rotate": 0,
7291
+ "invert": 0,
7292
+ "opacity": 1,
7293
+ "saturate": 1,
7294
+ "sepia": 0
7295
+ };
7296
+ function parseCSSFilter(filter) {
7297
+ const m = new ColorMatrix();
7298
+ if (filter === "none") {
7299
+ return m;
7305
7300
  }
7306
- _updateProperty(key, value, oldValue, declaration) {
7307
- super._updateProperty(key, value, oldValue, declaration);
7308
- switch (key) {
7309
- case "modulate":
7310
- this._modulate.value = value;
7311
- this.requestRepaint();
7301
+ const filters = parseCssFunctions(filter).reduce((filter2, { name, args }) => {
7302
+ filter2[name] = args[0].normalizedIntValue;
7303
+ return filter2;
7304
+ }, {});
7305
+ Object.keys(defaultFilters).forEach((name) => {
7306
+ filters[name] = filters[name] ?? defaultFilters[name];
7307
+ });
7308
+ for (const name in filters) {
7309
+ const value = filters[name];
7310
+ switch (name) {
7311
+ case "hue-rotate":
7312
+ m.hueRotate(value * PI_2);
7312
7313
  break;
7313
- case "blendMode":
7314
- this.requestRepaint();
7314
+ case "saturate":
7315
+ m.saturate(value);
7316
+ break;
7317
+ case "brightness":
7318
+ m.brightness(value);
7319
+ break;
7320
+ case "contrast":
7321
+ m.contrast(value);
7322
+ break;
7323
+ case "invert":
7324
+ m.invert(value);
7325
+ break;
7326
+ case "sepia":
7327
+ m.sepia(value);
7315
7328
  break;
7316
7329
  case "opacity":
7317
- this._updateGlobalOpacity();
7330
+ m.opacity(value);
7318
7331
  break;
7319
- case "visible":
7320
- case "insideTimeRange":
7321
- this._updateGlobalVisible();
7332
+ case "grayscale":
7333
+ m.grayscale(value);
7322
7334
  break;
7323
7335
  }
7324
7336
  }
7325
- show() {
7326
- this.visible = true;
7327
- }
7328
- hide() {
7329
- this.visible = false;
7330
- }
7331
- isVisibleInTree() {
7332
- return this.globalOpacity > 0 && this.globalVisible;
7333
- }
7334
- canRender() {
7335
- return super.canRender() && this.isVisibleInTree();
7336
- }
7337
- requestRedraw() {
7338
- this._redrawing = true;
7339
- }
7340
- requestRelayout() {
7341
- this._relayouting = true;
7342
- }
7343
- requestRepaint() {
7344
- this._repainting = true;
7345
- }
7346
- _updateGlobalVisible() {
7347
- this._parentGlobalVisible = this.getParent()?.globalVisible;
7348
- this._globalVisible = (this._parentGlobalVisible ?? true) && this.visible && this.insideTimeRange;
7349
- }
7350
- _updateGlobalOpacity() {
7351
- this._parentGlobalOpacity = this.getParent()?.opacity;
7352
- const globalOpacity = clamp(0, this.opacity, 1) * (this._parentGlobalOpacity ?? 1);
7353
- if (this._globalOpacity !== globalOpacity) {
7354
- this._globalOpacity = globalOpacity;
7355
- this.requestRepaint();
7356
- }
7357
- }
7358
- _draw() {
7359
- this.emit("draw");
7360
- }
7361
- _redraw() {
7362
- this.log(this.name, "drawing");
7363
- this._draw();
7364
- return this.context.toBatchables();
7365
- }
7366
- _relayout(batchables) {
7367
- this.log(this.name, "layouting");
7368
- return batchables;
7369
- }
7370
- _repaint(batchables) {
7371
- this.log(this.name, "painting");
7372
- return batchables.map((batchable) => {
7373
- return {
7374
- ...batchable,
7375
- modulate: this._modulate.toArgb(this.globalOpacity, true),
7376
- blendMode: this.blendMode
7377
- };
7378
- });
7379
- }
7380
- _process(delta) {
7381
- super._process(delta);
7382
- const parent = this.getParent();
7383
- if (this._parentGlobalVisible !== parent?.globalVisible) {
7384
- this._updateGlobalVisible();
7385
- }
7386
- if (this._parentGlobalOpacity !== parent?.globalOpacity) {
7387
- this._updateGlobalOpacity();
7388
- }
7389
- }
7390
- _updateBatchables() {
7391
- const redrawing = this._redrawing;
7392
- let relayouting = this._relayouting;
7393
- let repainting = this._repainting;
7394
- let batchables;
7395
- if (redrawing) {
7396
- this._originalBatchables = this._redraw();
7397
- relayouting = true;
7398
- }
7399
- if (relayouting) {
7400
- this._layoutedBatchables = this._relayout(this._originalBatchables);
7401
- repainting = true;
7402
- }
7403
- if (repainting) {
7404
- batchables = this._repaint(this._layoutedBatchables);
7405
- }
7406
- if (redrawing) {
7407
- if (this._resetContext) {
7408
- this.context.reset();
7409
- }
7337
+ return m;
7338
+ }
7339
+
7340
+ function parseCSSTransform(transform, width, height, output = new Transform2D()) {
7341
+ transform = !transform || transform === "none" ? "" : transform;
7342
+ parseCssFunctions(transform, { width, height }).reverse().forEach(({ name, args }) => {
7343
+ const values = args.map((arg) => arg.normalizedIntValue);
7344
+ switch (name) {
7345
+ case "translate":
7346
+ output.translate(values[0] * width, (values[1] ?? values[0]) * height);
7347
+ break;
7348
+ case "translateX":
7349
+ output.translateX(values[0] * width);
7350
+ break;
7351
+ case "translateY":
7352
+ output.translateY(values[0] * height);
7353
+ break;
7354
+ case "translateZ":
7355
+ output.translateZ(values[0]);
7356
+ break;
7357
+ case "translate3d":
7358
+ output.translate3d(
7359
+ values[0] * width,
7360
+ (values[1] ?? values[0]) * height,
7361
+ values[2] ?? values[1] ?? values[0]
7362
+ );
7363
+ break;
7364
+ case "scale":
7365
+ output.scale(values[0], values[1] ?? values[0]);
7366
+ break;
7367
+ case "scaleX":
7368
+ output.scaleX(values[0]);
7369
+ break;
7370
+ case "scaleY":
7371
+ output.scaleY(values[0]);
7372
+ break;
7373
+ case "scale3d":
7374
+ output.scale3d(values[0], values[1] ?? values[0], values[2] ?? values[1] ?? values[0]);
7375
+ break;
7376
+ case "rotate":
7377
+ output.rotate(values[0] * PI_2);
7378
+ break;
7379
+ case "rotateX":
7380
+ output.rotateX(values[0] * PI_2);
7381
+ break;
7382
+ case "rotateY":
7383
+ output.rotateY(values[0] * PI_2);
7384
+ break;
7385
+ case "rotateZ":
7386
+ output.rotateZ(values[0] * PI_2);
7387
+ break;
7388
+ case "rotate3d":
7389
+ output.rotate3d(
7390
+ values[0] * PI_2,
7391
+ (values[1] ?? values[0]) * PI_2,
7392
+ (values[2] ?? values[1] ?? values[0]) * PI_2,
7393
+ (values[3] ?? values[2] ?? values[1] ?? values[0]) * PI_2
7394
+ );
7395
+ break;
7396
+ case "skew":
7397
+ output.skew(values[0], values[0] ?? values[1]);
7398
+ break;
7399
+ case "skewX":
7400
+ output.skewX(values[0]);
7401
+ break;
7402
+ case "skewY":
7403
+ output.skewY(values[0]);
7404
+ break;
7405
+ case "matrix":
7406
+ output.set(values);
7407
+ break;
7410
7408
  }
7411
- if (batchables) {
7412
- this._batchables = batchables;
7413
- this._redrawing = false;
7414
- this._relayouting = false;
7415
- this._repainting = false;
7409
+ });
7410
+ return output;
7411
+ }
7412
+
7413
+ function parseCSSTransformOrigin(transformOrigin) {
7414
+ const [originX, originY = originX] = transformOrigin.split(" ");
7415
+ return [originX, originY].map((val) => {
7416
+ val = val.trim();
7417
+ switch (val) {
7418
+ case "left":
7419
+ case "top":
7420
+ return 0;
7421
+ case "center":
7422
+ return 0.5;
7423
+ case "right":
7424
+ case "bottom":
7425
+ return 1;
7426
+ default:
7427
+ return Number(val);
7416
7428
  }
7429
+ });
7430
+ }
7431
+
7432
+ var __defProp$A = Object.defineProperty;
7433
+ var __getOwnPropDesc$z = Object.getOwnPropertyDescriptor;
7434
+ var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$A(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7435
+ var __decorateClass$H = (decorators, target, key, kind) => {
7436
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$z(target, key) : target;
7437
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
7438
+ if (decorator = decorators[i])
7439
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
7440
+ if (kind && result) __defProp$A(target, key, result);
7441
+ return result;
7442
+ };
7443
+ var __publicField$i = (obj, key, value) => __defNormalProp$i(obj, key + "" , value);
7444
+ exports.ColorAdjustEffect = class ColorAdjustEffect extends exports.Effect {
7445
+ constructor(properties, children = []) {
7446
+ super();
7447
+ this.setProperties(properties).append(children);
7417
7448
  }
7418
- _render(renderer) {
7419
- this._updateBatchables();
7420
- this._batchables.forEach((batchable) => {
7421
- batchable.texture?.upload(renderer);
7422
- renderer.batch2D.render({
7423
- ...batchable,
7424
- texture: batchable.texture?._glTexture(renderer)
7449
+ apply(renderer, source) {
7450
+ source.redraw(renderer, () => {
7451
+ QuadUvGeometry.draw(renderer, exports.ColorAdjustEffect.material, {
7452
+ sampler: 0,
7453
+ saturation: this.saturation,
7454
+ contrast: this.contrast,
7455
+ brightness: this.brightness,
7456
+ red: this.red,
7457
+ green: this.green,
7458
+ blue: this.blue,
7459
+ alpha: this.alpha,
7460
+ gamma: Math.max(this.gamma ?? 1, 1e-4)
7425
7461
  });
7426
7462
  });
7427
- super._render(renderer);
7428
7463
  }
7429
7464
  };
7430
- __decorateClass$I([
7465
+ __publicField$i(exports.ColorAdjustEffect, "material", new Material({
7466
+ vert: `precision mediump float;
7467
+ attribute vec2 position;
7468
+ attribute vec2 uv;
7469
+ varying vec2 vUv;
7470
+ void main() {
7471
+ gl_Position = vec4(position, 0.0, 1.0);
7472
+ vUv = uv;
7473
+ }`,
7474
+ frag: `varying vec2 vUv;
7475
+ uniform sampler2D sampler;
7476
+ uniform float gamma;
7477
+ uniform float contrast;
7478
+ uniform float saturation;
7479
+ uniform float brightness;
7480
+ uniform float red;
7481
+ uniform float green;
7482
+ uniform float blue;
7483
+ uniform float alpha;
7484
+
7485
+ void main(void) {
7486
+ vec4 c = texture2D(sampler, vUv);
7487
+ if (c.a > 0.0) {
7488
+ c.rgb /= c.a;
7489
+ vec3 rgb = pow(c.rgb, vec3(1. / gamma));
7490
+ rgb = mix(vec3(.5), mix(vec3(dot(vec3(.2125, .7154, .0721), rgb)), rgb, saturation), contrast);
7491
+ rgb.r *= red;
7492
+ rgb.g *= green;
7493
+ rgb.b *= blue;
7494
+ c.rgb = rgb * brightness;
7495
+ c.rgb *= c.a;
7496
+ }
7497
+ gl_FragColor = c * alpha;
7498
+ }`
7499
+ }));
7500
+ __decorateClass$H([
7431
7501
  modernIdoc.property()
7432
- ], exports.CanvasItem.prototype, "modulate", 2);
7433
- __decorateClass$I([
7502
+ ], exports.ColorAdjustEffect.prototype, "saturation", 2);
7503
+ __decorateClass$H([
7434
7504
  modernIdoc.property()
7435
- ], exports.CanvasItem.prototype, "blendMode", 2);
7436
- __decorateClass$I([
7437
- modernIdoc.property({ protected: true, fallback: true })
7438
- ], exports.CanvasItem.prototype, "visible", 2);
7439
- __decorateClass$I([
7440
- modernIdoc.property({ protected: true, fallback: 1 })
7441
- ], exports.CanvasItem.prototype, "opacity", 2);
7442
- exports.CanvasItem = __decorateClass$I([
7443
- customNode("CanvasItem")
7444
- ], exports.CanvasItem);
7505
+ ], exports.ColorAdjustEffect.prototype, "contrast", 2);
7506
+ __decorateClass$H([
7507
+ modernIdoc.property()
7508
+ ], exports.ColorAdjustEffect.prototype, "brightness", 2);
7509
+ __decorateClass$H([
7510
+ modernIdoc.property()
7511
+ ], exports.ColorAdjustEffect.prototype, "red", 2);
7512
+ __decorateClass$H([
7513
+ modernIdoc.property()
7514
+ ], exports.ColorAdjustEffect.prototype, "green", 2);
7515
+ __decorateClass$H([
7516
+ modernIdoc.property()
7517
+ ], exports.ColorAdjustEffect.prototype, "blue", 2);
7518
+ __decorateClass$H([
7519
+ modernIdoc.property()
7520
+ ], exports.ColorAdjustEffect.prototype, "alpha", 2);
7521
+ __decorateClass$H([
7522
+ modernIdoc.property()
7523
+ ], exports.ColorAdjustEffect.prototype, "gamma", 2);
7524
+ exports.ColorAdjustEffect = __decorateClass$H([
7525
+ customNode("ColorAdjustEffect")
7526
+ ], exports.ColorAdjustEffect);
7445
7527
 
7446
- class RenderStack {
7447
- currentCall;
7448
- calls = [];
7449
- createCall(renderable) {
7450
- return {
7451
- renderable,
7452
- parentCall: this.currentCall,
7453
- fn: renderable.render.bind(renderable),
7454
- calls: []
7455
- };
7456
- }
7457
- push(renderable) {
7458
- const call = this.createCall(renderable);
7459
- (this.currentCall?.calls ?? this.calls).push(call);
7460
- return call;
7528
+ var __defProp$z = Object.defineProperty;
7529
+ var __getOwnPropDesc$y = Object.getOwnPropertyDescriptor;
7530
+ var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$z(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7531
+ var __decorateClass$G = (decorators, target, key, kind) => {
7532
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$y(target, key) : target;
7533
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
7534
+ if (decorator = decorators[i])
7535
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
7536
+ if (kind && result) __defProp$z(target, key, result);
7537
+ return result;
7538
+ };
7539
+ var __publicField$h = (obj, key, value) => __defNormalProp$h(obj, key + "" , value);
7540
+ exports.ColorFilterEffect = class ColorFilterEffect extends exports.Effect {
7541
+ _colorMatrix = new ColorMatrix();
7542
+ constructor(properties, children = []) {
7543
+ super();
7544
+ this.setProperties(properties).append(children);
7461
7545
  }
7462
- render(renderer) {
7463
- this.calls.forEach(function render(call) {
7464
- call.fn(renderer, () => {
7465
- call.calls.forEach(render);
7546
+ apply(renderer, source) {
7547
+ if (!this.filter)
7548
+ return;
7549
+ const funs = parseCssFunctions(this.filter);
7550
+ const matrix = this._colorMatrix.identity();
7551
+ funs.forEach(({ name, args }) => {
7552
+ const values = args.map((arg) => arg.normalizedIntValue);
7553
+ switch (name) {
7554
+ case "hue-rotate":
7555
+ case "hueRotate":
7556
+ matrix.hueRotate(values[0] * PI_2);
7557
+ break;
7558
+ case "saturate":
7559
+ matrix.saturate(values[0]);
7560
+ break;
7561
+ case "brightness":
7562
+ matrix.brightness(values[0]);
7563
+ break;
7564
+ case "contrast":
7565
+ matrix.contrast(values[0]);
7566
+ break;
7567
+ case "invert":
7568
+ matrix.invert(values[0]);
7569
+ break;
7570
+ case "sepia":
7571
+ matrix.sepia(values[0]);
7572
+ break;
7573
+ case "opacity":
7574
+ matrix.opacity(values[0]);
7575
+ break;
7576
+ case "grayscale":
7577
+ matrix.grayscale(values[0]);
7578
+ break;
7579
+ }
7580
+ });
7581
+ source.redraw(renderer, () => {
7582
+ QuadUvGeometry.draw(renderer, exports.ColorFilterEffect.material, {
7583
+ sampler: 0,
7584
+ m: matrix.toArray()
7466
7585
  });
7467
7586
  });
7468
- this.calls = [];
7469
7587
  }
7470
- }
7588
+ };
7589
+ __publicField$h(exports.ColorFilterEffect, "material", new Material({
7590
+ vert: `precision mediump float;
7591
+ attribute vec2 position;
7592
+ attribute vec2 uv;
7593
+ varying vec2 vUv;
7594
+ void main() {
7595
+ gl_Position = vec4(position, 0.0, 1.0);
7596
+ vUv = uv;
7597
+ }`,
7598
+ frag: `precision highp float;
7599
+ varying vec2 vUv;
7600
+ uniform sampler2D sampler;
7601
+ uniform float m[20];
7471
7602
 
7472
- var __defProp$z = Object.defineProperty;
7473
- var __getOwnPropDesc$y = Object.getOwnPropertyDescriptor;
7474
- var __decorateClass$H = (decorators, target, key, kind) => {
7475
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$y(target, key) : target;
7603
+ void main(void) {
7604
+ vec4 c = texture2D(sampler, vUv);
7605
+ if (c.a > 0.0) {
7606
+ c.rgb /= c.a;
7607
+ }
7608
+ gl_FragColor = vec4(
7609
+ m[0] * c.r + m[1] * c.g + m[2] * c.b + m[3] * c.a + m[4] / 255.0,
7610
+ m[5] * c.r + m[6] * c.g + m[7] * c.b + m[8] * c.a + m[9] / 255.0,
7611
+ m[10] * c.r + m[11] * c.g + m[12] * c.b + m[13] * c.a + m[14] / 255.0,
7612
+ m[15] * c.r + m[16] * c.g + m[17] * c.b + m[18] * c.a + m[19] / 255.0
7613
+ );
7614
+ }`
7615
+ }));
7616
+ __decorateClass$G([
7617
+ modernIdoc.property()
7618
+ ], exports.ColorFilterEffect.prototype, "filter", 2);
7619
+ exports.ColorFilterEffect = __decorateClass$G([
7620
+ customNode("ColorFilterEffect")
7621
+ ], exports.ColorFilterEffect);
7622
+
7623
+ var __defProp$y = Object.defineProperty;
7624
+ var __getOwnPropDesc$x = Object.getOwnPropertyDescriptor;
7625
+ var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$y(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7626
+ var __decorateClass$F = (decorators, target, key, kind) => {
7627
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$x(target, key) : target;
7476
7628
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
7477
7629
  if (decorator = decorators[i])
7478
7630
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
7479
- if (kind && result) __defProp$z(target, key, result);
7631
+ if (kind && result) __defProp$y(target, key, result);
7480
7632
  return result;
7481
7633
  };
7482
- exports.Timeline = class Timeline extends exports.Node {
7483
- static from(range, loop = false) {
7484
- const [startTime, endTime] = range ? Array.isArray(range) ? range : [0, range] : [];
7485
- return new exports.Timeline({
7486
- startTime,
7487
- endTime,
7488
- loop
7489
- });
7490
- }
7491
- constructor(properties) {
7634
+ var __publicField$g = (obj, key, value) => __defNormalProp$g(obj, key + "" , value);
7635
+ const MAX_COLORS$1 = 50;
7636
+ exports.ColorOverlayEffect = class ColorOverlayEffect extends exports.Effect {
7637
+ _color = new Color();
7638
+ constructor(properties, children = []) {
7492
7639
  super();
7493
- this.setProperties(properties);
7640
+ this.setProperties(properties).append(children);
7494
7641
  }
7495
- _updateProperty(key, value, oldValue) {
7496
- super._updateProperty(key, value, oldValue);
7497
- switch (key) {
7498
- case "startTime":
7499
- this.startTime = Math.min(value, this.endTime);
7500
- break;
7501
- case "endTime":
7502
- this.endTime = value || Number.MAX_SAFE_INTEGER;
7503
- break;
7504
- }
7642
+ apply(renderer, source) {
7643
+ source.redraw(renderer, () => {
7644
+ const colors = this.colors.map((val) => {
7645
+ this._color.value = val;
7646
+ const rgba = this._color.toArray();
7647
+ rgba[3] = this.alpha;
7648
+ return rgba;
7649
+ });
7650
+ while (colors.length < MAX_COLORS$1) {
7651
+ colors.push([0, 0, 0, 0]);
7652
+ }
7653
+ QuadUvGeometry.draw(renderer, exports.ColorOverlayEffect.material, {
7654
+ sampler: 0,
7655
+ colors: colors.slice(0, MAX_COLORS$1).flatMap((item) => item)
7656
+ });
7657
+ });
7505
7658
  }
7506
- addTime(delta) {
7507
- const start = this.startTime;
7508
- const end = this.endTime;
7509
- let current = this.currentTime;
7510
- current = current + delta;
7511
- if (this.loop && current > end) {
7512
- current = start + current % end;
7659
+ };
7660
+ __publicField$g(exports.ColorOverlayEffect, "material", new Material({
7661
+ vert: `precision mediump float;
7662
+ attribute vec2 position;
7663
+ attribute vec2 uv;
7664
+ varying vec2 vUv;
7665
+ void main() {
7666
+ gl_Position = vec4(position, 0.0, 1.0);
7667
+ vUv = uv;
7668
+ }`,
7669
+ frag: `precision mediump float;
7670
+ uniform sampler2D sampler;
7671
+ uniform vec4 colors[${MAX_COLORS$1}];
7672
+ varying vec2 vUv;
7673
+
7674
+ float calcWidth() {
7675
+ return distance(vec2(0, 0), vec2(1, 0));
7676
+ }
7677
+
7678
+ int calcCount() {
7679
+ int count = 0;
7680
+ for (int i = 0; i < ${MAX_COLORS$1}; i++) {
7681
+ if (colors[i] != vec4(0,0,0,0)){
7682
+ count++;
7683
+ }
7684
+ }
7685
+ return count;
7686
+ }
7687
+
7688
+ vec4 calcColor(float x) {
7689
+ float perUnit = calcWidth() / float(calcCount());
7690
+ int index = int(x / perUnit);
7691
+
7692
+ for(int i=0; i<${MAX_COLORS$1}; i++){
7693
+ if(i==index){
7694
+ return colors[i];
7513
7695
  }
7514
- current = clamp(start, current, end);
7515
- this.currentTime = current;
7516
- this.emit("updateCurrentTime", current, delta);
7517
- return this;
7518
- }
7519
- _process(delta) {
7520
- super._process(delta);
7521
- this.addTime(delta);
7522
7696
  }
7523
- };
7524
- __decorateClass$H([
7525
- modernIdoc.property({ fallback: 0 })
7526
- ], exports.Timeline.prototype, "startTime", 2);
7527
- __decorateClass$H([
7528
- modernIdoc.property({ fallback: 0 })
7529
- ], exports.Timeline.prototype, "currentTime", 2);
7530
- __decorateClass$H([
7531
- modernIdoc.property({ fallback: Number.MAX_SAFE_INTEGER })
7532
- ], exports.Timeline.prototype, "endTime", 2);
7533
- __decorateClass$H([
7534
- modernIdoc.property({ fallback: false })
7535
- ], exports.Timeline.prototype, "loop", 2);
7536
- exports.Timeline = __decorateClass$H([
7537
- customNode("Timeline")
7538
- ], exports.Timeline);
7539
7697
 
7540
- var __defProp$y = Object.defineProperty;
7541
- var __decorateClass$G = (decorators, target, key, kind) => {
7542
- var result = void 0 ;
7698
+ return vec4(0, 0, 0, 0);
7699
+ }
7700
+
7701
+ void main(void) {
7702
+ vec4 color = texture2D(sampler, vUv);
7703
+ vec4 mask = calcColor(vUv.x);
7704
+ gl_FragColor = vec4(mix(color.rgb, mask.rgb, color.a * mask.a), color.a);
7705
+ }`
7706
+ }));
7707
+ __decorateClass$F([
7708
+ modernIdoc.property()
7709
+ ], exports.ColorOverlayEffect.prototype, "colors", 2);
7710
+ __decorateClass$F([
7711
+ modernIdoc.property()
7712
+ ], exports.ColorOverlayEffect.prototype, "alpha", 2);
7713
+ exports.ColorOverlayEffect = __decorateClass$F([
7714
+ customNode("ColorOverlayEffect")
7715
+ ], exports.ColorOverlayEffect);
7716
+
7717
+ var __defProp$x = Object.defineProperty;
7718
+ var __getOwnPropDesc$w = Object.getOwnPropertyDescriptor;
7719
+ var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$x(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7720
+ var __decorateClass$E = (decorators, target, key, kind) => {
7721
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$w(target, key) : target;
7543
7722
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
7544
7723
  if (decorator = decorators[i])
7545
- result = (decorator(target, key, result) ) || result;
7546
- if (result) __defProp$y(target, key, result);
7724
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
7725
+ if (kind && result) __defProp$x(target, key, result);
7547
7726
  return result;
7548
7727
  };
7549
- class SceneTree extends MainLoop {
7550
- input = new Input();
7551
- renderStack = new RenderStack();
7552
- root = new exports.Viewport(true).setTree(this);
7553
- timeline;
7554
- nodes = /* @__PURE__ */ new Map();
7555
- _backgroundColor = new Color();
7556
- _currentViewport;
7557
- getCurrentViewport() {
7558
- return this._currentViewport;
7559
- }
7560
- setCurrentViewport(viewport) {
7561
- this._currentViewport = viewport;
7562
- }
7563
- constructor(timeline = new exports.Timeline()) {
7728
+ var __publicField$f = (obj, key, value) => __defNormalProp$f(obj, key + "" , value);
7729
+ exports.ColorRemoveEffect = class ColorRemoveEffect extends exports.Effect {
7730
+ _color = new Color();
7731
+ constructor(properties, children = []) {
7564
7732
  super();
7565
- this.timeline = timeline.setTree(this);
7566
- }
7567
- _updateProperty(key, value, oldValue, declaration) {
7568
- super._updateProperty(key, value, oldValue, declaration);
7569
- switch (key) {
7570
- case "backgroundColor":
7571
- this._backgroundColor.value = value;
7572
- break;
7573
- }
7574
- }
7575
- log(...args) {
7576
- if (this.debug) {
7577
- console.log(`[modern-canvas][${performance.now().toFixed(4)}ms]`, ...args);
7578
- }
7579
- }
7580
- _process(delta = 0) {
7581
- this.timeline.emit("process", delta);
7582
- this.emit("processing");
7583
- this.root.emit("process", delta);
7584
- this.emit("processed");
7585
- }
7586
- _render(renderer) {
7587
- this.emit("rendering");
7588
- renderer.program.uniforms.projectionMatrix = this.root.toProjectionArray(true);
7589
- this.renderStack.render(renderer);
7590
- this._renderScreen(renderer);
7591
- this.emit("rendered");
7733
+ this.setProperties(properties).append(children);
7592
7734
  }
7593
- _renderScreen(renderer) {
7594
- renderer.state.reset();
7595
- renderer.framebuffer.bind(null);
7596
- renderer.viewport.bind({
7597
- x: 0,
7598
- y: 0,
7599
- width: this.root.width * renderer.pixelRatio,
7600
- height: this.root.height * renderer.pixelRatio
7735
+ apply(renderer, source) {
7736
+ const maxColors = 50;
7737
+ const originalColors = new Float32Array(maxColors * 3);
7738
+ const colors = this.colors.map((val) => {
7739
+ this._color.value = val;
7740
+ return this._color.toArray().slice(0, 3);
7601
7741
  });
7602
- if (this.backgroundColor) {
7603
- renderer.gl.clearColor(...this._backgroundColor.toArray());
7604
- }
7605
- renderer.clear();
7606
- if (this.backgroundColor) {
7607
- renderer.gl.clearColor(0, 0, 0, 0);
7742
+ while (colors.length < maxColors) {
7743
+ colors.push([-1, 0, 0]);
7608
7744
  }
7609
- const texture = this.root.texture;
7610
- texture.activate(renderer, 0);
7611
- QuadUvGeometry.draw(renderer);
7612
- renderer.texture.unbind(texture);
7613
- }
7614
- free() {
7615
- super.free();
7616
- this.root.children.internal.forEach((node) => this.root.removeChild(node));
7617
- this.input.removeEventListeners();
7745
+ colors.slice(0, maxColors).forEach((originalColor, i) => {
7746
+ originalColors[i * 3] = originalColor[0];
7747
+ originalColors[i * 3 + 1] = originalColor[1];
7748
+ originalColors[i * 3 + 2] = originalColor[2];
7749
+ });
7750
+ source.redraw(renderer, () => {
7751
+ QuadUvGeometry.draw(renderer, exports.ColorRemoveEffect.material, {
7752
+ sampler: 0,
7753
+ epsilon: this.epsilon,
7754
+ originalColors
7755
+ });
7756
+ });
7618
7757
  }
7619
- }
7620
- __decorateClass$G([
7621
- modernIdoc.property({ fallback: false })
7622
- ], SceneTree.prototype, "processPaused");
7623
- __decorateClass$G([
7758
+ };
7759
+ __publicField$f(exports.ColorRemoveEffect, "material", new Material({
7760
+ vert: `precision mediump float;
7761
+ attribute vec2 position;
7762
+ attribute vec2 uv;
7763
+ varying vec2 vUv;
7764
+ void main() {
7765
+ gl_Position = vec4(position, 0.0, 1.0);
7766
+ vUv = uv;
7767
+ }`,
7768
+ frag: `varying vec2 vUv;
7769
+ uniform sampler2D sampler;
7770
+ uniform float epsilon;
7771
+ const int MAX_COLORS = 50;
7772
+ uniform vec3 originalColors[MAX_COLORS];
7773
+
7774
+ void main(void) {
7775
+ vec4 color = texture2D(sampler, vUv);
7776
+
7777
+ for (int i = 0; i < MAX_COLORS; i++) {
7778
+ vec3 origColor = originalColors[i];
7779
+ if (origColor.r < 0.0) {
7780
+ break;
7781
+ }
7782
+ vec3 colorDiff = origColor - color.rgb;
7783
+ if (length(colorDiff) < epsilon) {
7784
+ gl_FragColor = vec4(0, 0, 0, 0);
7785
+ return;
7786
+ }
7787
+ }
7788
+
7789
+ gl_FragColor = color;
7790
+ }`
7791
+ }));
7792
+ __decorateClass$E([
7624
7793
  modernIdoc.property()
7625
- ], SceneTree.prototype, "backgroundColor");
7626
- __decorateClass$G([
7627
- modernIdoc.property({ protected: true, fallback: false })
7628
- ], SceneTree.prototype, "debug");
7794
+ ], exports.ColorRemoveEffect.prototype, "colors", 2);
7795
+ __decorateClass$E([
7796
+ modernIdoc.property()
7797
+ ], exports.ColorRemoveEffect.prototype, "epsilon", 2);
7798
+ exports.ColorRemoveEffect = __decorateClass$E([
7799
+ customNode("ColorRemoveEffect")
7800
+ ], exports.ColorRemoveEffect);
7629
7801
 
7630
- var __getOwnPropDesc$x = Object.getOwnPropertyDescriptor;
7631
- var __decorateClass$F = (decorators, target, key, kind) => {
7632
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$x(target, key) : target;
7802
+ var __defProp$w = Object.defineProperty;
7803
+ var __getOwnPropDesc$v = Object.getOwnPropertyDescriptor;
7804
+ var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$w(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7805
+ var __decorateClass$D = (decorators, target, key, kind) => {
7806
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$v(target, key) : target;
7633
7807
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
7634
7808
  if (decorator = decorators[i])
7635
- result = (decorator(result)) || result;
7809
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
7810
+ if (kind && result) __defProp$w(target, key, result);
7636
7811
  return result;
7637
7812
  };
7638
- exports.Transition = class Transition extends exports.Effect {
7813
+ var __publicField$e = (obj, key, value) => __defNormalProp$e(obj, key + "" , value);
7814
+ const MAX_COLORS = 50;
7815
+ exports.ColorReplaceEffect = class ColorReplaceEffect extends exports.Effect {
7816
+ _color = new Color();
7639
7817
  constructor(properties, children = []) {
7640
7818
  super();
7641
7819
  this.setProperties(properties).append(children);
7642
7820
  }
7821
+ apply(renderer, source) {
7822
+ const colors = this.colors.map((val) => {
7823
+ this._color.value = val[0];
7824
+ const color0 = this._color.toArray().slice(0, 3);
7825
+ this._color.value = val[1];
7826
+ const color1 = this._color.toArray().slice(0, 3);
7827
+ return [
7828
+ color0,
7829
+ color1
7830
+ ];
7831
+ });
7832
+ const epsilon = this.epsilon;
7833
+ const originalColors = new Float32Array(MAX_COLORS * 3);
7834
+ const targetColors = new Float32Array(MAX_COLORS * 3);
7835
+ while (colors.length < MAX_COLORS) {
7836
+ colors.push([
7837
+ [-1, 0, 0],
7838
+ [0, 0, 0, 1]
7839
+ ]);
7840
+ }
7841
+ colors.slice(0, MAX_COLORS).forEach(([originalColor, targetColor], i) => {
7842
+ originalColors[i * 3] = originalColor[0];
7843
+ originalColors[i * 3 + 1] = originalColor[1];
7844
+ originalColors[i * 3 + 2] = originalColor[2];
7845
+ targetColors[i * 3] = targetColor[0];
7846
+ targetColors[i * 3 + 1] = targetColor[1];
7847
+ targetColors[i * 3 + 2] = targetColor[2];
7848
+ });
7849
+ source.redraw(renderer, () => {
7850
+ QuadUvGeometry.draw(renderer, exports.ColorReplaceEffect.material, {
7851
+ sampler: 0,
7852
+ epsilon,
7853
+ originalColors,
7854
+ targetColors
7855
+ });
7856
+ });
7857
+ }
7643
7858
  };
7644
- exports.Transition = __decorateClass$F([
7645
- customNode("Transition", {
7646
- effectMode: "transition",
7647
- processMode: "pausable",
7648
- duration: 2e3
7649
- })
7650
- ], exports.Transition);
7859
+ __publicField$e(exports.ColorReplaceEffect, "material", new Material({
7860
+ vert: `precision mediump float;
7861
+ attribute vec2 position;
7862
+ attribute vec2 uv;
7863
+ varying vec2 vUv;
7864
+ void main() {
7865
+ gl_Position = vec4(position, 0.0, 1.0);
7866
+ vUv = uv;
7867
+ }`,
7868
+ frag: `varying vec2 vUv;
7869
+ uniform sampler2D sampler;
7870
+ uniform float epsilon;
7871
+ const int MAX_COLORS = ${MAX_COLORS};
7872
+ uniform vec3 originalColors[MAX_COLORS];
7873
+ uniform vec3 targetColors[MAX_COLORS];
7651
7874
 
7652
- var __defProp$x = Object.defineProperty;
7653
- var __getOwnPropDesc$w = Object.getOwnPropertyDescriptor;
7654
- var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$x(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7655
- var __decorateClass$E = (decorators, target, key, kind) => {
7656
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$w(target, key) : target;
7875
+ void main(void) {
7876
+ gl_FragColor = texture2D(sampler, vUv);
7877
+
7878
+ float alpha = gl_FragColor.a;
7879
+ if (alpha < 0.0001) {
7880
+ return;
7881
+ }
7882
+
7883
+ vec3 color = gl_FragColor.rgb / alpha;
7884
+
7885
+ for(int i = 0; i < MAX_COLORS; i++) {
7886
+ vec3 origColor = originalColors[i];
7887
+ if (origColor.r < 0.0) {
7888
+ break;
7889
+ }
7890
+ vec3 colorDiff = origColor - color;
7891
+ if (length(colorDiff) < epsilon) {
7892
+ vec3 targetColor = targetColors[i];
7893
+ gl_FragColor = vec4((targetColor + colorDiff) * alpha, alpha);
7894
+ return;
7895
+ }
7896
+ }
7897
+ }`
7898
+ }));
7899
+ __decorateClass$D([
7900
+ modernIdoc.property()
7901
+ ], exports.ColorReplaceEffect.prototype, "colors", 2);
7902
+ __decorateClass$D([
7903
+ modernIdoc.property()
7904
+ ], exports.ColorReplaceEffect.prototype, "epsilon", 2);
7905
+ exports.ColorReplaceEffect = __decorateClass$D([
7906
+ customNode("ColorReplaceEffect")
7907
+ ], exports.ColorReplaceEffect);
7908
+
7909
+ var __defProp$v = Object.defineProperty;
7910
+ var __getOwnPropDesc$u = Object.getOwnPropertyDescriptor;
7911
+ var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$v(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7912
+ var __decorateClass$C = (decorators, target, key, kind) => {
7913
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$u(target, key) : target;
7657
7914
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
7658
7915
  if (decorator = decorators[i])
7659
7916
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
7660
- if (kind && result) __defProp$x(target, key, result);
7917
+ if (kind && result) __defProp$v(target, key, result);
7661
7918
  return result;
7662
7919
  };
7663
7920
  var __publicField$d = (obj, key, value) => __defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
@@ -7763,25 +8020,25 @@ void main(void) {
7763
8020
  }`,
7764
8021
  frag: frag$2
7765
8022
  }));
7766
- __decorateClass$E([
8023
+ __decorateClass$C([
7767
8024
  modernIdoc.property({ default: 4 })
7768
8025
  ], exports.GaussianBlurEffect.prototype, "strength", 2);
7769
- __decorateClass$E([
8026
+ __decorateClass$C([
7770
8027
  modernIdoc.property({ default: 3 })
7771
8028
  ], exports.GaussianBlurEffect.prototype, "quality", 2);
7772
- exports.GaussianBlurEffect = __decorateClass$E([
8029
+ exports.GaussianBlurEffect = __decorateClass$C([
7773
8030
  customNode("GaussianBlurEffect")
7774
8031
  ], exports.GaussianBlurEffect);
7775
8032
 
7776
- var __defProp$w = Object.defineProperty;
7777
- var __getOwnPropDesc$v = Object.getOwnPropertyDescriptor;
7778
- var __defNormalProp$c = (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;
8033
+ var __defProp$u = Object.defineProperty;
8034
+ var __getOwnPropDesc$t = Object.getOwnPropertyDescriptor;
8035
+ var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$u(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8036
+ var __decorateClass$B = (decorators, target, key, kind) => {
8037
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$t(target, key) : target;
7781
8038
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
7782
8039
  if (decorator = decorators[i])
7783
8040
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
7784
- if (kind && result) __defProp$w(target, key, result);
8041
+ if (kind && result) __defProp$u(target, key, result);
7785
8042
  return result;
7786
8043
  };
7787
8044
  var __publicField$c = (obj, key, value) => __defNormalProp$c(obj, key + "" , value);
@@ -7845,34 +8102,34 @@ void main(void) {
7845
8102
  gl_FragColor = sample;
7846
8103
  }`
7847
8104
  }));
7848
- __decorateClass$D([
8105
+ __decorateClass$B([
7849
8106
  modernIdoc.property()
7850
8107
  ], exports.DropShadowEffect.prototype, "color", 2);
7851
- __decorateClass$D([
8108
+ __decorateClass$B([
7852
8109
  modernIdoc.property()
7853
8110
  ], exports.DropShadowEffect.prototype, "blur", 2);
7854
- __decorateClass$D([
8111
+ __decorateClass$B([
7855
8112
  modernIdoc.property()
7856
8113
  ], exports.DropShadowEffect.prototype, "offsetX", 2);
7857
- __decorateClass$D([
8114
+ __decorateClass$B([
7858
8115
  modernIdoc.property()
7859
8116
  ], exports.DropShadowEffect.prototype, "offsetY", 2);
7860
- __decorateClass$D([
8117
+ __decorateClass$B([
7861
8118
  modernIdoc.property()
7862
8119
  ], exports.DropShadowEffect.prototype, "shadowOnly", 2);
7863
- exports.DropShadowEffect = __decorateClass$D([
8120
+ exports.DropShadowEffect = __decorateClass$B([
7864
8121
  customNode("DropShadowEffect")
7865
8122
  ], exports.DropShadowEffect);
7866
8123
 
7867
- var __defProp$v = Object.defineProperty;
7868
- var __getOwnPropDesc$u = Object.getOwnPropertyDescriptor;
7869
- var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$v(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7870
- var __decorateClass$C = (decorators, target, key, kind) => {
7871
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$u(target, key) : target;
8124
+ var __defProp$t = Object.defineProperty;
8125
+ var __getOwnPropDesc$s = Object.getOwnPropertyDescriptor;
8126
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$t(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8127
+ var __decorateClass$A = (decorators, target, key, kind) => {
8128
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$s(target, key) : target;
7872
8129
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
7873
8130
  if (decorator = decorators[i])
7874
8131
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
7875
- if (kind && result) __defProp$v(target, key, result);
8132
+ if (kind && result) __defProp$t(target, key, result);
7876
8133
  return result;
7877
8134
  };
7878
8135
  var __publicField$b = (obj, key, value) => __defNormalProp$b(obj, key + "" , value);
@@ -7917,22 +8174,22 @@ void main(void) {
7917
8174
  gl_FragColor = vec4(color.rgb * alpha, alpha);
7918
8175
  }`
7919
8176
  }));
7920
- __decorateClass$C([
8177
+ __decorateClass$A([
7921
8178
  modernIdoc.property()
7922
8179
  ], exports.EmbossEffect.prototype, "strength", 2);
7923
- exports.EmbossEffect = __decorateClass$C([
8180
+ exports.EmbossEffect = __decorateClass$A([
7924
8181
  customNode("EmbossEffect")
7925
8182
  ], exports.EmbossEffect);
7926
8183
 
7927
- var __defProp$u = Object.defineProperty;
7928
- var __getOwnPropDesc$t = Object.getOwnPropertyDescriptor;
7929
- var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$u(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7930
- var __decorateClass$B = (decorators, target, key, kind) => {
7931
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$t(target, key) : target;
8184
+ var __defProp$s = Object.defineProperty;
8185
+ var __getOwnPropDesc$r = Object.getOwnPropertyDescriptor;
8186
+ var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$s(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8187
+ var __decorateClass$z = (decorators, target, key, kind) => {
8188
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$r(target, key) : target;
7932
8189
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
7933
8190
  if (decorator = decorators[i])
7934
8191
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
7935
- if (kind && result) __defProp$u(target, key, result);
8192
+ if (kind && result) __defProp$s(target, key, result);
7936
8193
  return result;
7937
8194
  };
7938
8195
  var __publicField$a = (obj, key, value) => __defNormalProp$a(obj, key + "" , value);
@@ -8106,46 +8363,46 @@ void main(void) {
8106
8363
  gl_FragColor.a = texture2D(sampler, coord).a;
8107
8364
  }`
8108
8365
  }));
8109
- __decorateClass$B([
8366
+ __decorateClass$z([
8110
8367
  modernIdoc.property()
8111
8368
  ], exports.GlitchEffect.prototype, "slices", 2);
8112
- __decorateClass$B([
8369
+ __decorateClass$z([
8113
8370
  modernIdoc.property()
8114
8371
  ], exports.GlitchEffect.prototype, "sampleSize", 2);
8115
- __decorateClass$B([
8372
+ __decorateClass$z([
8116
8373
  modernIdoc.property()
8117
8374
  ], exports.GlitchEffect.prototype, "offset", 2);
8118
- __decorateClass$B([
8375
+ __decorateClass$z([
8119
8376
  modernIdoc.property()
8120
8377
  ], exports.GlitchEffect.prototype, "direction", 2);
8121
- __decorateClass$B([
8378
+ __decorateClass$z([
8122
8379
  modernIdoc.property()
8123
8380
  ], exports.GlitchEffect.prototype, "fillMode", 2);
8124
- __decorateClass$B([
8381
+ __decorateClass$z([
8125
8382
  modernIdoc.property()
8126
8383
  ], exports.GlitchEffect.prototype, "seed", 2);
8127
- __decorateClass$B([
8384
+ __decorateClass$z([
8128
8385
  modernIdoc.property()
8129
8386
  ], exports.GlitchEffect.prototype, "red", 2);
8130
- __decorateClass$B([
8387
+ __decorateClass$z([
8131
8388
  modernIdoc.property()
8132
8389
  ], exports.GlitchEffect.prototype, "green", 2);
8133
- __decorateClass$B([
8390
+ __decorateClass$z([
8134
8391
  modernIdoc.property()
8135
8392
  ], exports.GlitchEffect.prototype, "blue", 2);
8136
- exports.GlitchEffect = __decorateClass$B([
8393
+ exports.GlitchEffect = __decorateClass$z([
8137
8394
  customNode("GlitchEffect")
8138
8395
  ], exports.GlitchEffect);
8139
8396
 
8140
- var __defProp$t = Object.defineProperty;
8141
- var __getOwnPropDesc$s = Object.getOwnPropertyDescriptor;
8142
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$t(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8143
- var __decorateClass$A = (decorators, target, key, kind) => {
8144
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$s(target, key) : target;
8397
+ var __defProp$r = Object.defineProperty;
8398
+ var __getOwnPropDesc$q = Object.getOwnPropertyDescriptor;
8399
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$r(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8400
+ var __decorateClass$y = (decorators, target, key, kind) => {
8401
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$q(target, key) : target;
8145
8402
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
8146
8403
  if (decorator = decorators[i])
8147
8404
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8148
- if (kind && result) __defProp$t(target, key, result);
8405
+ if (kind && result) __defProp$r(target, key, result);
8149
8406
  return result;
8150
8407
  };
8151
8408
  var __publicField$9 = (obj, key, value) => __defNormalProp$9(obj, key + "" , value);
@@ -8323,39 +8580,39 @@ void main(void) {
8323
8580
  gl_FragColor = vec4(color.rgb + mist.rgb, color.a);
8324
8581
  }`
8325
8582
  }));
8326
- __decorateClass$A([
8583
+ __decorateClass$y([
8327
8584
  modernIdoc.property()
8328
8585
  ], exports.GodrayEffect.prototype, "time", 2);
8329
- __decorateClass$A([
8586
+ __decorateClass$y([
8330
8587
  modernIdoc.property()
8331
8588
  ], exports.GodrayEffect.prototype, "angle", 2);
8332
- __decorateClass$A([
8589
+ __decorateClass$y([
8333
8590
  modernIdoc.property()
8334
8591
  ], exports.GodrayEffect.prototype, "gain", 2);
8335
- __decorateClass$A([
8592
+ __decorateClass$y([
8336
8593
  modernIdoc.property()
8337
8594
  ], exports.GodrayEffect.prototype, "lacunarity", 2);
8338
- __decorateClass$A([
8595
+ __decorateClass$y([
8339
8596
  modernIdoc.property()
8340
8597
  ], exports.GodrayEffect.prototype, "parallel", 2);
8341
- __decorateClass$A([
8598
+ __decorateClass$y([
8342
8599
  modernIdoc.property()
8343
8600
  ], exports.GodrayEffect.prototype, "center", 2);
8344
- __decorateClass$A([
8601
+ __decorateClass$y([
8345
8602
  modernIdoc.property()
8346
8603
  ], exports.GodrayEffect.prototype, "alpha", 2);
8347
- exports.GodrayEffect = __decorateClass$A([
8604
+ exports.GodrayEffect = __decorateClass$y([
8348
8605
  customNode("GodrayEffect")
8349
8606
  ], exports.GodrayEffect);
8350
8607
 
8351
- var __defProp$s = Object.defineProperty;
8352
- var __getOwnPropDesc$r = Object.getOwnPropertyDescriptor;
8353
- var __decorateClass$z = (decorators, target, key, kind) => {
8354
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$r(target, key) : target;
8608
+ var __defProp$q = Object.defineProperty;
8609
+ var __getOwnPropDesc$p = Object.getOwnPropertyDescriptor;
8610
+ var __decorateClass$x = (decorators, target, key, kind) => {
8611
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$p(target, key) : target;
8355
8612
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
8356
8613
  if (decorator = decorators[i])
8357
8614
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8358
- if (kind && result) __defProp$s(target, key, result);
8615
+ if (kind && result) __defProp$q(target, key, result);
8359
8616
  return result;
8360
8617
  };
8361
8618
  const frag$1 = `varying vec2 vUv;
@@ -8445,28 +8702,28 @@ void main() {
8445
8702
  });
8446
8703
  }
8447
8704
  };
8448
- __decorateClass$z([
8705
+ __decorateClass$x([
8449
8706
  modernIdoc.property()
8450
8707
  ], exports.KawaseBlurEffect.prototype, "strength", 2);
8451
- __decorateClass$z([
8708
+ __decorateClass$x([
8452
8709
  modernIdoc.property()
8453
8710
  ], exports.KawaseBlurEffect.prototype, "quality", 2);
8454
- __decorateClass$z([
8711
+ __decorateClass$x([
8455
8712
  modernIdoc.property()
8456
8713
  ], exports.KawaseBlurEffect.prototype, "pixelSize", 2);
8457
- exports.KawaseBlurEffect = __decorateClass$z([
8714
+ exports.KawaseBlurEffect = __decorateClass$x([
8458
8715
  customNode("KawaseBlurEffect")
8459
8716
  ], exports.KawaseBlurEffect);
8460
8717
 
8461
- var __defProp$r = Object.defineProperty;
8462
- var __getOwnPropDesc$q = Object.getOwnPropertyDescriptor;
8463
- var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$r(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8464
- var __decorateClass$y = (decorators, target, key, kind) => {
8465
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$q(target, key) : target;
8718
+ var __defProp$p = Object.defineProperty;
8719
+ var __getOwnPropDesc$o = Object.getOwnPropertyDescriptor;
8720
+ var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$p(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8721
+ var __decorateClass$w = (decorators, target, key, kind) => {
8722
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$o(target, key) : target;
8466
8723
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
8467
8724
  if (decorator = decorators[i])
8468
8725
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8469
- if (kind && result) __defProp$r(target, key, result);
8726
+ if (kind && result) __defProp$p(target, key, result);
8470
8727
  return result;
8471
8728
  };
8472
8729
  var __publicField$8 = (obj, key, value) => __defNormalProp$8(obj, key + "" , value);
@@ -8554,25 +8811,25 @@ void main(void) {
8554
8811
  }
8555
8812
  }`
8556
8813
  }));
8557
- __decorateClass$y([
8814
+ __decorateClass$w([
8558
8815
  modernIdoc.property({ protected: true })
8559
8816
  ], exports.MaskEffect.prototype, "texture", 2);
8560
- __decorateClass$y([
8817
+ __decorateClass$w([
8561
8818
  modernIdoc.property({ default: "" })
8562
8819
  ], exports.MaskEffect.prototype, "src", 2);
8563
- exports.MaskEffect = __decorateClass$y([
8820
+ exports.MaskEffect = __decorateClass$w([
8564
8821
  customNode("MaskEffect")
8565
8822
  ], exports.MaskEffect);
8566
-
8567
- var __defProp$q = Object.defineProperty;
8568
- var __getOwnPropDesc$p = Object.getOwnPropertyDescriptor;
8569
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$q(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8570
- var __decorateClass$x = (decorators, target, key, kind) => {
8571
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$p(target, key) : target;
8823
+
8824
+ var __defProp$o = Object.defineProperty;
8825
+ var __getOwnPropDesc$n = Object.getOwnPropertyDescriptor;
8826
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$o(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8827
+ var __decorateClass$v = (decorators, target, key, kind) => {
8828
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$n(target, key) : target;
8572
8829
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
8573
8830
  if (decorator = decorators[i])
8574
8831
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8575
- if (kind && result) __defProp$q(target, key, result);
8832
+ if (kind && result) __defProp$o(target, key, result);
8576
8833
  return result;
8577
8834
  };
8578
8835
  var __publicField$7 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
@@ -8659,40 +8916,40 @@ void main() {
8659
8916
  };
8660
8917
  __publicField$7(exports.OutlineEffect, "MIN_SAMPLES", 1);
8661
8918
  __publicField$7(exports.OutlineEffect, "MAX_SAMPLES", 100);
8662
- __decorateClass$x([
8919
+ __decorateClass$v([
8663
8920
  modernIdoc.property()
8664
8921
  ], exports.OutlineEffect.prototype, "color", 2);
8665
- __decorateClass$x([
8922
+ __decorateClass$v([
8666
8923
  modernIdoc.property()
8667
8924
  ], exports.OutlineEffect.prototype, "width", 2);
8668
- __decorateClass$x([
8925
+ __decorateClass$v([
8669
8926
  modernIdoc.property()
8670
8927
  ], exports.OutlineEffect.prototype, "style", 2);
8671
- __decorateClass$x([
8928
+ __decorateClass$v([
8672
8929
  modernIdoc.property()
8673
8930
  ], exports.OutlineEffect.prototype, "image", 2);
8674
- __decorateClass$x([
8931
+ __decorateClass$v([
8675
8932
  modernIdoc.property()
8676
8933
  ], exports.OutlineEffect.prototype, "opacity", 2);
8677
- __decorateClass$x([
8934
+ __decorateClass$v([
8678
8935
  modernIdoc.property()
8679
8936
  ], exports.OutlineEffect.prototype, "quality", 2);
8680
- __decorateClass$x([
8937
+ __decorateClass$v([
8681
8938
  modernIdoc.property()
8682
8939
  ], exports.OutlineEffect.prototype, "knockout", 2);
8683
- exports.OutlineEffect = __decorateClass$x([
8940
+ exports.OutlineEffect = __decorateClass$v([
8684
8941
  customNode("OutlineEffect")
8685
8942
  ], exports.OutlineEffect);
8686
8943
 
8687
- var __defProp$p = Object.defineProperty;
8688
- var __getOwnPropDesc$o = Object.getOwnPropertyDescriptor;
8689
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$p(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8690
- var __decorateClass$w = (decorators, target, key, kind) => {
8691
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$o(target, key) : target;
8944
+ var __defProp$n = Object.defineProperty;
8945
+ var __getOwnPropDesc$m = Object.getOwnPropertyDescriptor;
8946
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$n(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8947
+ var __decorateClass$u = (decorators, target, key, kind) => {
8948
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$m(target, key) : target;
8692
8949
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
8693
8950
  if (decorator = decorators[i])
8694
8951
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8695
- if (kind && result) __defProp$p(target, key, result);
8952
+ if (kind && result) __defProp$n(target, key, result);
8696
8953
  return result;
8697
8954
  };
8698
8955
  var __publicField$6 = (obj, key, value) => __defNormalProp$6(obj, key + "" , value);
@@ -8748,22 +9005,22 @@ void main(void) {
8748
9005
  gl_FragColor = texture2D(sampler, coord);
8749
9006
  }`
8750
9007
  }));
8751
- __decorateClass$w([
9008
+ __decorateClass$u([
8752
9009
  modernIdoc.property()
8753
9010
  ], exports.PixelateEffect.prototype, "strength", 2);
8754
- exports.PixelateEffect = __decorateClass$w([
9011
+ exports.PixelateEffect = __decorateClass$u([
8755
9012
  customNode("PixelateEffect")
8756
9013
  ], exports.PixelateEffect);
8757
9014
 
8758
- var __defProp$o = Object.defineProperty;
8759
- var __getOwnPropDesc$n = Object.getOwnPropertyDescriptor;
8760
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$o(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8761
- var __decorateClass$v = (decorators, target, key, kind) => {
8762
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$n(target, key) : target;
9015
+ var __defProp$m = Object.defineProperty;
9016
+ var __getOwnPropDesc$l = Object.getOwnPropertyDescriptor;
9017
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$m(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9018
+ var __decorateClass$t = (decorators, target, key, kind) => {
9019
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$l(target, key) : target;
8763
9020
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
8764
9021
  if (decorator = decorators[i])
8765
9022
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8766
- if (kind && result) __defProp$o(target, key, result);
9023
+ if (kind && result) __defProp$m(target, key, result);
8767
9024
  return result;
8768
9025
  };
8769
9026
  var __publicField$5 = (obj, key, value) => __defNormalProp$5(obj, key + "" , value);
@@ -8876,29 +9133,29 @@ void main() {
8876
9133
  gl_FragColor = color;
8877
9134
  }`
8878
9135
  }));
8879
- __decorateClass$v([
9136
+ __decorateClass$t([
8880
9137
  modernIdoc.property()
8881
9138
  ], exports.ZoomBlurEffect.prototype, "center", 2);
8882
- __decorateClass$v([
9139
+ __decorateClass$t([
8883
9140
  modernIdoc.property()
8884
9141
  ], exports.ZoomBlurEffect.prototype, "innerRadius", 2);
8885
- __decorateClass$v([
9142
+ __decorateClass$t([
8886
9143
  modernIdoc.property()
8887
9144
  ], exports.ZoomBlurEffect.prototype, "radius", 2);
8888
- __decorateClass$v([
9145
+ __decorateClass$t([
8889
9146
  modernIdoc.property()
8890
9147
  ], exports.ZoomBlurEffect.prototype, "strength", 2);
8891
- exports.ZoomBlurEffect = __decorateClass$v([
9148
+ exports.ZoomBlurEffect = __decorateClass$t([
8892
9149
  customNode("ZoomBlurEffect")
8893
9150
  ], exports.ZoomBlurEffect);
8894
9151
 
8895
- var __defProp$n = Object.defineProperty;
8896
- var __decorateClass$u = (decorators, target, key, kind) => {
9152
+ var __defProp$l = Object.defineProperty;
9153
+ var __decorateClass$s = (decorators, target, key, kind) => {
8897
9154
  var result = void 0 ;
8898
9155
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
8899
9156
  if (decorator = decorators[i])
8900
9157
  result = (decorator(target, key, result) ) || result;
8901
- if (result) __defProp$n(target, key, result);
9158
+ if (result) __defProp$l(target, key, result);
8902
9159
  return result;
8903
9160
  };
8904
9161
  class BaseElement2DFill extends CoreObject {
@@ -9006,47 +9263,47 @@ class BaseElement2DFill extends CoreObject {
9006
9263
  });
9007
9264
  }
9008
9265
  }
9009
- __decorateClass$u([
9266
+ __decorateClass$s([
9010
9267
  modernIdoc.property({ fallback: true })
9011
9268
  ], BaseElement2DFill.prototype, "enabled");
9012
- __decorateClass$u([
9269
+ __decorateClass$s([
9013
9270
  modernIdoc.property()
9014
9271
  ], BaseElement2DFill.prototype, "color");
9015
- __decorateClass$u([
9272
+ __decorateClass$s([
9016
9273
  modernIdoc.property()
9017
9274
  ], BaseElement2DFill.prototype, "image");
9018
- __decorateClass$u([
9275
+ __decorateClass$s([
9019
9276
  modernIdoc.property()
9020
9277
  ], BaseElement2DFill.prototype, "linearGradient");
9021
- __decorateClass$u([
9278
+ __decorateClass$s([
9022
9279
  modernIdoc.property()
9023
9280
  ], BaseElement2DFill.prototype, "radialGradient");
9024
- __decorateClass$u([
9281
+ __decorateClass$s([
9025
9282
  modernIdoc.property()
9026
9283
  ], BaseElement2DFill.prototype, "cropRect");
9027
- __decorateClass$u([
9284
+ __decorateClass$s([
9028
9285
  modernIdoc.property()
9029
9286
  ], BaseElement2DFill.prototype, "stretchRect");
9030
- __decorateClass$u([
9287
+ __decorateClass$s([
9031
9288
  modernIdoc.property()
9032
9289
  ], BaseElement2DFill.prototype, "dpi");
9033
- __decorateClass$u([
9290
+ __decorateClass$s([
9034
9291
  modernIdoc.property()
9035
9292
  ], BaseElement2DFill.prototype, "rotateWithShape");
9036
- __decorateClass$u([
9293
+ __decorateClass$s([
9037
9294
  modernIdoc.property()
9038
9295
  ], BaseElement2DFill.prototype, "tile");
9039
- __decorateClass$u([
9296
+ __decorateClass$s([
9040
9297
  modernIdoc.property()
9041
9298
  ], BaseElement2DFill.prototype, "opacity");
9042
9299
 
9043
- var __defProp$m = Object.defineProperty;
9044
- var __decorateClass$t = (decorators, target, key, kind) => {
9300
+ var __defProp$k = Object.defineProperty;
9301
+ var __decorateClass$r = (decorators, target, key, kind) => {
9045
9302
  var result = void 0 ;
9046
9303
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
9047
9304
  if (decorator = decorators[i])
9048
9305
  result = (decorator(target, key, result) ) || result;
9049
- if (result) __defProp$m(target, key, result);
9306
+ if (result) __defProp$k(target, key, result);
9050
9307
  return result;
9051
9308
  };
9052
9309
  class BaseElement2DBackground extends BaseElement2DFill {
@@ -9056,17 +9313,17 @@ class BaseElement2DBackground extends BaseElement2DFill {
9056
9313
  );
9057
9314
  }
9058
9315
  }
9059
- __decorateClass$t([
9316
+ __decorateClass$r([
9060
9317
  modernIdoc.property()
9061
9318
  ], BaseElement2DBackground.prototype, "fillWithShape");
9062
9319
 
9063
- var __defProp$l = Object.defineProperty;
9064
- var __decorateClass$s = (decorators, target, key, kind) => {
9320
+ var __defProp$j = Object.defineProperty;
9321
+ var __decorateClass$q = (decorators, target, key, kind) => {
9065
9322
  var result = void 0 ;
9066
9323
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
9067
9324
  if (decorator = decorators[i])
9068
9325
  result = (decorator(target, key, result) ) || result;
9069
- if (result) __defProp$l(target, key, result);
9326
+ if (result) __defProp$j(target, key, result);
9070
9327
  return result;
9071
9328
  };
9072
9329
  class BaseElement2DForeground extends BaseElement2DFill {
@@ -9076,17 +9333,17 @@ class BaseElement2DForeground extends BaseElement2DFill {
9076
9333
  );
9077
9334
  }
9078
9335
  }
9079
- __decorateClass$s([
9336
+ __decorateClass$q([
9080
9337
  modernIdoc.property()
9081
9338
  ], BaseElement2DForeground.prototype, "fillWithShape");
9082
9339
 
9083
- var __defProp$k = Object.defineProperty;
9084
- var __decorateClass$r = (decorators, target, key, kind) => {
9340
+ var __defProp$i = Object.defineProperty;
9341
+ var __decorateClass$p = (decorators, target, key, kind) => {
9085
9342
  var result = void 0 ;
9086
9343
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
9087
9344
  if (decorator = decorators[i])
9088
9345
  result = (decorator(target, key, result) ) || result;
9089
- if (result) __defProp$k(target, key, result);
9346
+ if (result) __defProp$i(target, key, result);
9090
9347
  return result;
9091
9348
  };
9092
9349
  class BaseElement2DOutline extends BaseElement2DFill {
@@ -9119,23 +9376,23 @@ class BaseElement2DOutline extends BaseElement2DFill {
9119
9376
  ctx.stroke({ disableWrapMode });
9120
9377
  }
9121
9378
  }
9122
- __decorateClass$r([
9379
+ __decorateClass$p([
9123
9380
  modernIdoc.property({ fallback: "#00000000" })
9124
9381
  ], BaseElement2DOutline.prototype, "color");
9125
- __decorateClass$r([
9382
+ __decorateClass$p([
9126
9383
  modernIdoc.property({ fallback: 0 })
9127
9384
  ], BaseElement2DOutline.prototype, "width");
9128
- __decorateClass$r([
9385
+ __decorateClass$p([
9129
9386
  modernIdoc.property({ fallback: "solid" })
9130
9387
  ], BaseElement2DOutline.prototype, "style");
9131
9388
 
9132
- var __defProp$j = Object.defineProperty;
9133
- var __decorateClass$q = (decorators, target, key, kind) => {
9389
+ var __defProp$h = Object.defineProperty;
9390
+ var __decorateClass$o = (decorators, target, key, kind) => {
9134
9391
  var result = void 0 ;
9135
9392
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
9136
9393
  if (decorator = decorators[i])
9137
9394
  result = (decorator(target, key, result) ) || result;
9138
- if (result) __defProp$j(target, key, result);
9395
+ if (result) __defProp$h(target, key, result);
9139
9396
  return result;
9140
9397
  };
9141
9398
  class BaseElement2DShadow extends CoreObject {
@@ -9175,29 +9432,29 @@ class BaseElement2DShadow extends CoreObject {
9175
9432
  }
9176
9433
  }
9177
9434
  }
9178
- __decorateClass$q([
9435
+ __decorateClass$o([
9179
9436
  modernIdoc.property({ fallback: true })
9180
9437
  ], BaseElement2DShadow.prototype, "enabled");
9181
- __decorateClass$q([
9438
+ __decorateClass$o([
9182
9439
  modernIdoc.property({ fallback: "#000000FF" })
9183
9440
  ], BaseElement2DShadow.prototype, "color");
9184
- __decorateClass$q([
9441
+ __decorateClass$o([
9185
9442
  modernIdoc.property({ fallback: 0 })
9186
9443
  ], BaseElement2DShadow.prototype, "blur");
9187
- __decorateClass$q([
9444
+ __decorateClass$o([
9188
9445
  modernIdoc.property({ fallback: 0 })
9189
9446
  ], BaseElement2DShadow.prototype, "offsetY");
9190
- __decorateClass$q([
9447
+ __decorateClass$o([
9191
9448
  modernIdoc.property({ fallback: 0 })
9192
9449
  ], BaseElement2DShadow.prototype, "offsetX");
9193
9450
 
9194
- var __defProp$i = Object.defineProperty;
9195
- var __decorateClass$p = (decorators, target, key, kind) => {
9451
+ var __defProp$g = Object.defineProperty;
9452
+ var __decorateClass$n = (decorators, target, key, kind) => {
9196
9453
  var result = void 0 ;
9197
9454
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
9198
9455
  if (decorator = decorators[i])
9199
9456
  result = (decorator(target, key, result) ) || result;
9200
- if (result) __defProp$i(target, key, result);
9457
+ if (result) __defProp$g(target, key, result);
9201
9458
  return result;
9202
9459
  };
9203
9460
  class BaseElement2DShape extends CoreObject {
@@ -9272,19 +9529,19 @@ class BaseElement2DShape extends CoreObject {
9272
9529
  }
9273
9530
  }
9274
9531
  }
9275
- __decorateClass$p([
9532
+ __decorateClass$n([
9276
9533
  modernIdoc.property({ fallback: true })
9277
9534
  ], BaseElement2DShape.prototype, "enabled");
9278
- __decorateClass$p([
9535
+ __decorateClass$n([
9279
9536
  modernIdoc.property()
9280
9537
  ], BaseElement2DShape.prototype, "preset");
9281
- __decorateClass$p([
9538
+ __decorateClass$n([
9282
9539
  modernIdoc.property()
9283
9540
  ], BaseElement2DShape.prototype, "svg");
9284
- __decorateClass$p([
9541
+ __decorateClass$n([
9285
9542
  modernIdoc.property()
9286
9543
  ], BaseElement2DShape.prototype, "viewBox");
9287
- __decorateClass$p([
9544
+ __decorateClass$n([
9288
9545
  modernIdoc.property()
9289
9546
  ], BaseElement2DShape.prototype, "paths");
9290
9547
 
@@ -9300,13 +9557,13 @@ for (const key in defaultStyles$1) {
9300
9557
  modernIdoc.defineProperty(BaseElement2DStyle, key, { fallback });
9301
9558
  }
9302
9559
 
9303
- var __defProp$h = Object.defineProperty;
9304
- var __decorateClass$o = (decorators, target, key, kind) => {
9560
+ var __defProp$f = Object.defineProperty;
9561
+ var __decorateClass$m = (decorators, target, key, kind) => {
9305
9562
  var result = void 0 ;
9306
9563
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
9307
9564
  if (decorator = decorators[i])
9308
9565
  result = (decorator(target, key, result) ) || result;
9309
- if (result) __defProp$h(target, key, result);
9566
+ if (result) __defProp$f(target, key, result);
9310
9567
  return result;
9311
9568
  };
9312
9569
  class BaseElement2DText extends CoreObject {
@@ -9347,187 +9604,67 @@ class BaseElement2DText extends CoreObject {
9347
9604
  break;
9348
9605
  }
9349
9606
  }
9350
- _updateText() {
9351
- this.base.style = {
9352
- justifyContent: "center",
9353
- alignItems: "center",
9354
- textAlign: "center",
9355
- ...this.parent.style.toJSON()
9356
- };
9357
- this.base.requestUpdate();
9358
- }
9359
- measure() {
9360
- this._updateText();
9361
- return this.base.measure();
9362
- }
9363
- updateMeasure() {
9364
- this.measureResult = this.measure();
9365
- return this;
9366
- }
9367
- canDraw() {
9368
- return Boolean(
9369
- this.enabled && !/^\s*$/.test(this.base.toString())
9370
- );
9371
- }
9372
- draw() {
9373
- const ctx = this.parent.context;
9374
- this.base.update();
9375
- this.base.pathSets.forEach((pathSet) => {
9376
- pathSet.paths.forEach((path) => {
9377
- ctx.addPath(path);
9378
- ctx.style = { ...path.style };
9379
- ctx.fillStyle = void 0;
9380
- ctx.strokeStyle = void 0;
9381
- ctx.fill();
9382
- });
9383
- });
9384
- }
9385
- }
9386
- __decorateClass$o([
9387
- modernIdoc.property({ fallback: true })
9388
- ], BaseElement2DText.prototype, "enabled");
9389
- __decorateClass$o([
9390
- modernIdoc.property({ alias: "base.content", fallback: () => [] })
9391
- ], BaseElement2DText.prototype, "content");
9392
- __decorateClass$o([
9393
- modernIdoc.property({ alias: "base.effects" })
9394
- ], BaseElement2DText.prototype, "effects");
9395
- __decorateClass$o([
9396
- modernIdoc.property({ alias: "base.fill" })
9397
- ], BaseElement2DText.prototype, "fill");
9398
- __decorateClass$o([
9399
- modernIdoc.property({ alias: "base.outline" })
9400
- ], BaseElement2DText.prototype, "outline");
9401
- __decorateClass$o([
9402
- modernIdoc.property({ protected: true, alias: "base.measureDom" })
9403
- ], BaseElement2DText.prototype, "measureDom");
9404
- __decorateClass$o([
9405
- modernIdoc.property({ protected: true, alias: "base.fonts" })
9406
- ], BaseElement2DText.prototype, "fonts");
9407
-
9408
- var __defProp$g = Object.defineProperty;
9409
- var __getOwnPropDesc$m = Object.getOwnPropertyDescriptor;
9410
- var __decorateClass$n = (decorators, target, key, kind) => {
9411
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$m(target, key) : target;
9412
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
9413
- if (decorator = decorators[i])
9414
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
9415
- if (kind && result) __defProp$g(target, key, result);
9416
- return result;
9417
- };
9418
- exports.Node2D = class Node2D extends exports.CanvasItem {
9419
- position = new Vector2().on("update", () => this.updateGlobalTransform());
9420
- scale = new Vector2(1, 1).on("update", () => this.updateGlobalTransform());
9421
- skew = new Vector2().on("update", () => this.updateGlobalTransform());
9422
- transform = new Transform2D();
9423
- globalPosition = new Vector2();
9424
- globalScale = new Vector2();
9425
- globalSkew = new Vector2();
9426
- globalTransform = new Transform2D();
9427
- _parentTransformDirtyId;
9428
- constructor(properties, nodes = []) {
9429
- super();
9430
- this.setProperties(properties).append(nodes);
9431
- }
9432
- _updateProperty(key, value, oldValue, declaration) {
9433
- super._updateProperty(key, value, oldValue, declaration);
9434
- switch (key) {
9435
- case "rotation":
9436
- this.requestRelayout();
9437
- break;
9438
- }
9439
- }
9440
- getTransformOrigin() {
9441
- return new Vector2(0, 0);
9442
- }
9443
- getTransform(cb) {
9444
- const origin = this.getTransformOrigin();
9445
- const transform = new Transform2D();
9446
- transform.translate(-origin.x, -origin.y).scale(this.scale.x, this.scale.y).skew(this.skew.x, this.skew.y).rotate(this.rotation);
9447
- cb?.(transform);
9448
- transform.translate(this.position.x, this.position.y).translate(origin.x, origin.y);
9449
- return transform;
9450
- }
9451
- updateTransform() {
9452
- this.transform.copy(this.getTransform());
9453
- }
9454
- updateGlobalTransform() {
9455
- this.updateTransform();
9456
- const parent = this.getParent();
9457
- if (parent?.globalTransform) {
9458
- this._parentTransformDirtyId = parent.globalTransform.dirtyId;
9459
- this.globalScale.set(parent.globalScale.x * this.scale.x, parent.globalScale.y * this.scale.y);
9460
- this.globalRotation = parent.globalRotation + this.rotation;
9461
- parent.globalTransform.multiply(this.transform, this.globalTransform);
9462
- } else {
9463
- this.globalScale.copy(this.scale);
9464
- this.globalRotation = this.rotation;
9465
- this.globalTransform.copy(this.transform);
9466
- }
9467
- const [
9468
- a,
9469
- c,
9470
- tx,
9471
- b,
9472
- d,
9473
- ty
9474
- ] = this.globalTransform.toArray();
9475
- this.globalPosition.set(tx, ty);
9476
- this.globalSkew.x = Math.atan2(c, a) - this.globalRotation;
9477
- this.globalSkew.y = Math.atan2(b, d) - this.globalRotation;
9478
- this.requestRelayout();
9479
- }
9480
- _transformVertices(vertices, vertTransform) {
9481
- let a, c, tx, b, d, ty;
9482
- if (vertTransform) {
9483
- const globalTransform = this.globalTransform.clone();
9484
- globalTransform.multiply(
9485
- typeof vertTransform === "function" ? vertTransform?.() : vertTransform
9486
- );
9487
- [a, c, tx, b, d, ty] = globalTransform.toArray();
9488
- } else {
9489
- [a, c, tx, b, d, ty] = this.globalTransform.toArray();
9490
- }
9491
- const newVertices = vertices.slice();
9492
- for (let len = vertices.length, i = 0; i < len; i += 2) {
9493
- const x = vertices[i];
9494
- const y = vertices[i + 1];
9495
- newVertices[i] = a * x + c * y + tx;
9496
- newVertices[i + 1] = b * x + d * y + ty;
9497
- }
9498
- return newVertices;
9607
+ _updateText() {
9608
+ this.base.style = {
9609
+ justifyContent: "center",
9610
+ alignItems: "center",
9611
+ textAlign: "center",
9612
+ ...this.parent.style.toJSON()
9613
+ };
9614
+ this.base.requestUpdate();
9499
9615
  }
9500
- _relayout(batchables) {
9501
- batchables = super._relayout(batchables);
9502
- this.updateGlobalTransform();
9503
- return batchables.map((batchable) => {
9504
- return {
9505
- ...batchable,
9506
- vertices: this._transformVertices(batchable.vertices, batchable.vertTransform)
9507
- };
9508
- });
9616
+ measure() {
9617
+ this._updateText();
9618
+ return this.base.measure();
9509
9619
  }
9510
- _process(delta) {
9511
- super._process(delta);
9512
- const parent = this.getParent();
9513
- if (parent?.globalTransform && this._parentTransformDirtyId !== parent?.globalTransform?.dirtyId) {
9514
- this.requestRelayout();
9515
- }
9620
+ updateMeasure() {
9621
+ this.measureResult = this.measure();
9622
+ return this;
9516
9623
  }
9517
- };
9518
- __decorateClass$n([
9519
- modernIdoc.property({ protected: true, fallback: 0 })
9520
- ], exports.Node2D.prototype, "rotation", 2);
9521
- __decorateClass$n([
9522
- modernIdoc.property({ protected: true, fallback: 0 })
9523
- ], exports.Node2D.prototype, "globalRotation", 2);
9524
- exports.Node2D = __decorateClass$n([
9525
- customNode("Node2D")
9526
- ], exports.Node2D);
9624
+ canDraw() {
9625
+ return Boolean(
9626
+ this.enabled && !/^\s*$/.test(this.base.toString())
9627
+ );
9628
+ }
9629
+ draw() {
9630
+ const ctx = this.parent.context;
9631
+ this.base.update();
9632
+ this.base.pathSets.forEach((pathSet) => {
9633
+ pathSet.paths.forEach((path) => {
9634
+ ctx.addPath(path);
9635
+ ctx.style = { ...path.style };
9636
+ ctx.fillStyle = void 0;
9637
+ ctx.strokeStyle = void 0;
9638
+ ctx.fill();
9639
+ });
9640
+ });
9641
+ }
9642
+ }
9643
+ __decorateClass$m([
9644
+ modernIdoc.property({ fallback: true })
9645
+ ], BaseElement2DText.prototype, "enabled");
9646
+ __decorateClass$m([
9647
+ modernIdoc.property({ alias: "base.content", fallback: () => [] })
9648
+ ], BaseElement2DText.prototype, "content");
9649
+ __decorateClass$m([
9650
+ modernIdoc.property({ alias: "base.effects" })
9651
+ ], BaseElement2DText.prototype, "effects");
9652
+ __decorateClass$m([
9653
+ modernIdoc.property({ alias: "base.fill" })
9654
+ ], BaseElement2DText.prototype, "fill");
9655
+ __decorateClass$m([
9656
+ modernIdoc.property({ alias: "base.outline" })
9657
+ ], BaseElement2DText.prototype, "outline");
9658
+ __decorateClass$m([
9659
+ modernIdoc.property({ protected: true, alias: "base.measureDom" })
9660
+ ], BaseElement2DText.prototype, "measureDom");
9661
+ __decorateClass$m([
9662
+ modernIdoc.property({ protected: true, alias: "base.fonts" })
9663
+ ], BaseElement2DText.prototype, "fonts");
9527
9664
 
9528
- var __getOwnPropDesc$l = Object.getOwnPropertyDescriptor;
9529
- var __decorateClass$m = (decorators, target, key, kind) => {
9530
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$l(target, key) : target;
9665
+ var __getOwnPropDesc$k = Object.getOwnPropertyDescriptor;
9666
+ var __decorateClass$l = (decorators, target, key, kind) => {
9667
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$k(target, key) : target;
9531
9668
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
9532
9669
  if (decorator = decorators[i])
9533
9670
  result = (decorator(result)) || result;
@@ -9751,15 +9888,46 @@ exports.BaseElement2D = class BaseElement2D extends exports.Node2D {
9751
9888
  maxY - minY
9752
9889
  );
9753
9890
  }
9891
+ // protected _rectsOverlap(r1: any, r2: any): boolean {
9892
+ // return (
9893
+ // r1.x < r2.x + r2.width
9894
+ // && r1.x + r1.width > r2.x
9895
+ // && r1.y < r2.y + r2.height
9896
+ // && r1.y + r1.height > r2.y
9897
+ // )
9898
+ // }
9899
+ // TODO
9900
+ // override isVisibleInTree(): boolean {
9901
+ // if (this._tree) {
9902
+ // const root = this._tree.root
9903
+ // const camera = root.canvasTransform.inverse()
9904
+ // const { x, y, width, height } = root
9905
+ // const p1 = camera.applyToPoint(x, y)
9906
+ // const p2 = camera.applyToPoint(x + width, y)
9907
+ // const p3 = camera.applyToPoint(x + width, y + height)
9908
+ // const p4 = camera.applyToPoint(x, y + height)
9909
+ // const pts = [p1, p2, p3, p4]
9910
+ // const xs = pts.map(p => p[0])
9911
+ // const ys = pts.map(p => p[1])
9912
+ // const minX = Math.min(...xs)
9913
+ // const maxX = Math.max(...xs)
9914
+ // const minY = Math.min(...ys)
9915
+ // const maxY = Math.max(...ys)
9916
+ // const rect2 = {
9917
+ // x: minX,
9918
+ // y: minY,
9919
+ // width: maxX - minX,
9920
+ // height: maxY - minY,
9921
+ // }
9922
+ // if (!this._rectsOverlap(rect2, this.getRect())) {
9923
+ // return false
9924
+ // }
9925
+ // }
9926
+ // return super.isVisibleInTree()
9927
+ // }
9754
9928
  _updateOverflow() {
9755
9929
  if (this.style.overflow === "hidden") {
9756
- const rect = this.getRect();
9757
- this.mask = {
9758
- x: rect.x,
9759
- y: rect.y,
9760
- width: rect.width,
9761
- height: rect.height
9762
- };
9930
+ this.mask = this.getRect().toJSON();
9763
9931
  } else {
9764
9932
  this.mask = void 0;
9765
9933
  }
@@ -9830,10 +9998,14 @@ exports.BaseElement2D = class BaseElement2D extends exports.Node2D {
9830
9998
  case "pointermove":
9831
9999
  case "pointerup": {
9832
10000
  if (this.canPointerEvents()) {
9833
- const { screenX, screenY } = event;
10001
+ let { screenX, screenY } = event;
9834
10002
  if (screenX && screenY) {
9835
- const [x, y] = this.globalTransform.inverse().applyToPoint(screenX, screenY);
9836
- if (this._pointerInput({ x, y }, key)) {
10003
+ const viewport = this.getViewport();
10004
+ if (viewport) {
10005
+ [screenX, screenY] = viewport.canvasTransform.inverse().applyToPoint(screenX, screenY);
10006
+ }
10007
+ [screenX, screenY] = this.globalTransform.inverse().applyToPoint(screenX, screenY);
10008
+ if (this._pointerInput({ x: screenX, y: screenY }, key)) {
9837
10009
  if (!event.target) {
9838
10010
  event.target = this;
9839
10011
  }
@@ -9862,7 +10034,7 @@ exports.BaseElement2D = class BaseElement2D extends exports.Node2D {
9862
10034
  });
9863
10035
  }
9864
10036
  };
9865
- exports.BaseElement2D = __decorateClass$m([
10037
+ exports.BaseElement2D = __decorateClass$l([
9866
10038
  customNode("BaseElement2D")
9867
10039
  ], exports.BaseElement2D);
9868
10040
 
@@ -9882,9 +10054,16 @@ for (const key in defaultStyles) {
9882
10054
  modernIdoc.defineProperty(Element2DStyle, key, { fallback: defaultStyles[key] });
9883
10055
  }
9884
10056
 
9885
- var __getOwnPropDesc$k = Object.getOwnPropertyDescriptor;
9886
- var __decorateClass$l = (decorators, target, key, kind) => {
9887
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$k(target, key) : target;
10057
+ class FlexElement2DStyle extends BaseElement2DStyle {
10058
+ constructor(properties) {
10059
+ super();
10060
+ this.setProperties(properties);
10061
+ }
10062
+ }
10063
+
10064
+ var __getOwnPropDesc$j = Object.getOwnPropertyDescriptor;
10065
+ var __decorateClass$k = (decorators, target, key, kind) => {
10066
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$j(target, key) : target;
9888
10067
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
9889
10068
  if (decorator = decorators[i])
9890
10069
  result = (decorator(result)) || result;
@@ -9935,17 +10114,10 @@ exports.Element2D = class Element2D extends exports.BaseElement2D {
9935
10114
  }
9936
10115
  }
9937
10116
  };
9938
- exports.Element2D = __decorateClass$l([
10117
+ exports.Element2D = __decorateClass$k([
9939
10118
  customNode("Element2D")
9940
10119
  ], exports.Element2D);
9941
10120
 
9942
- class FlexElement2DStyle extends BaseElement2DStyle {
9943
- constructor(properties) {
9944
- super();
9945
- this.setProperties(properties);
9946
- }
9947
- }
9948
-
9949
10121
  const alignMap = {
9950
10122
  "auto": load.Align.Auto,
9951
10123
  "flex-start": load.Align.FlexStart,
@@ -10187,9 +10359,9 @@ class FlexLayout {
10187
10359
  }
10188
10360
  }
10189
10361
 
10190
- var __getOwnPropDesc$j = Object.getOwnPropertyDescriptor;
10191
- var __decorateClass$k = (decorators, target, key, kind) => {
10192
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$j(target, key) : target;
10362
+ var __getOwnPropDesc$i = Object.getOwnPropertyDescriptor;
10363
+ var __decorateClass$j = (decorators, target, key, kind) => {
10364
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$i(target, key) : target;
10193
10365
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
10194
10366
  if (decorator = decorators[i])
10195
10367
  result = (decorator(result)) || result;
@@ -10266,18 +10438,18 @@ exports.FlexElement2D = class FlexElement2D extends exports.BaseElement2D {
10266
10438
  }
10267
10439
  }
10268
10440
  };
10269
- exports.FlexElement2D = __decorateClass$k([
10441
+ exports.FlexElement2D = __decorateClass$j([
10270
10442
  customNode("FlexElement2D")
10271
10443
  ], exports.FlexElement2D);
10272
10444
 
10273
- var __defProp$f = Object.defineProperty;
10274
- var __getOwnPropDesc$i = Object.getOwnPropertyDescriptor;
10275
- var __decorateClass$j = (decorators, target, key, kind) => {
10276
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$i(target, key) : target;
10445
+ var __defProp$e = Object.defineProperty;
10446
+ var __getOwnPropDesc$h = Object.getOwnPropertyDescriptor;
10447
+ var __decorateClass$i = (decorators, target, key, kind) => {
10448
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$h(target, key) : target;
10277
10449
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
10278
10450
  if (decorator = decorators[i])
10279
10451
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
10280
- if (kind && result) __defProp$f(target, key, result);
10452
+ if (kind && result) __defProp$e(target, key, result);
10281
10453
  return result;
10282
10454
  };
10283
10455
  exports.Image2D = class Image2D extends exports.Element2D {
@@ -10413,19 +10585,19 @@ exports.Image2D = class Image2D extends exports.Element2D {
10413
10585
  });
10414
10586
  }
10415
10587
  };
10416
- __decorateClass$j([
10588
+ __decorateClass$i([
10417
10589
  modernIdoc.property({ protected: true })
10418
10590
  ], exports.Image2D.prototype, "texture", 2);
10419
- __decorateClass$j([
10591
+ __decorateClass$i([
10420
10592
  modernIdoc.property({ fallback: "" })
10421
10593
  ], exports.Image2D.prototype, "src", 2);
10422
- __decorateClass$j([
10594
+ __decorateClass$i([
10423
10595
  modernIdoc.property()
10424
10596
  ], exports.Image2D.prototype, "srcRect", 2);
10425
- __decorateClass$j([
10597
+ __decorateClass$i([
10426
10598
  modernIdoc.property({ fallback: false })
10427
10599
  ], exports.Image2D.prototype, "gif", 2);
10428
- exports.Image2D = __decorateClass$j([
10600
+ exports.Image2D = __decorateClass$i([
10429
10601
  customNode("Image2D")
10430
10602
  ], exports.Image2D);
10431
10603
 
@@ -10449,14 +10621,14 @@ class TextureRect2D extends exports.Element2D {
10449
10621
  }
10450
10622
  }
10451
10623
 
10452
- var __defProp$e = Object.defineProperty;
10453
- var __getOwnPropDesc$h = Object.getOwnPropertyDescriptor;
10454
- var __decorateClass$i = (decorators, target, key, kind) => {
10455
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$h(target, key) : target;
10624
+ var __defProp$d = Object.defineProperty;
10625
+ var __getOwnPropDesc$g = Object.getOwnPropertyDescriptor;
10626
+ var __decorateClass$h = (decorators, target, key, kind) => {
10627
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$g(target, key) : target;
10456
10628
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
10457
10629
  if (decorator = decorators[i])
10458
10630
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
10459
- if (kind && result) __defProp$e(target, key, result);
10631
+ if (kind && result) __defProp$d(target, key, result);
10460
10632
  return result;
10461
10633
  };
10462
10634
  exports.Lottie2D = class Lottie2D extends TextureRect2D {
@@ -10499,189 +10671,13 @@ exports.Lottie2D = class Lottie2D extends TextureRect2D {
10499
10671
  super._process(delta);
10500
10672
  }
10501
10673
  };
10502
- __decorateClass$i([
10674
+ __decorateClass$h([
10503
10675
  modernIdoc.property({ fallback: "" })
10504
10676
  ], exports.Lottie2D.prototype, "src", 2);
10505
- exports.Lottie2D = __decorateClass$i([
10677
+ exports.Lottie2D = __decorateClass$h([
10506
10678
  customNode("Lottie2D")
10507
10679
  ], exports.Lottie2D);
10508
10680
 
10509
- var __defProp$d = Object.defineProperty;
10510
- var __getOwnPropDesc$g = Object.getOwnPropertyDescriptor;
10511
- var __decorateClass$h = (decorators, target, key, kind) => {
10512
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$g(target, key) : target;
10513
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
10514
- if (decorator = decorators[i])
10515
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
10516
- if (kind && result) __defProp$d(target, key, result);
10517
- return result;
10518
- };
10519
- const textStyles = new Set(Object.keys(modernText.textDefaultStyle));
10520
- exports.Text2D = class Text2D extends TextureRect2D {
10521
- texture = new CanvasTexture();
10522
- base = new modernText.Text();
10523
- measureResult;
10524
- _subTextsCount = 0;
10525
- constructor(properties, children = []) {
10526
- super();
10527
- this.setProperties(properties);
10528
- this.append(children);
10529
- if (properties?.plugins) {
10530
- properties.plugins.forEach((plugin) => {
10531
- this.base.use(plugin);
10532
- });
10533
- }
10534
- }
10535
- _updateProperty(key, value, oldValue, declaration) {
10536
- super._updateProperty(key, value, oldValue, declaration);
10537
- switch (key) {
10538
- case "content":
10539
- case "effects":
10540
- case "measureDOM":
10541
- case "fonts":
10542
- case "split":
10543
- this._updateSplit();
10544
- this.requestRedraw();
10545
- break;
10546
- }
10547
- if (this._subTextsCount && key === "effects") {
10548
- this._getSubTexts().forEach((child) => {
10549
- child.setProperties({ [key]: value });
10550
- });
10551
- }
10552
- }
10553
- _updateBase() {
10554
- this.base.style = this.style.toJSON();
10555
- this.emit("updateBase", this.base);
10556
- this.base.requestUpdate();
10557
- }
10558
- _updateStyleProperty(key, value, oldValue) {
10559
- switch (key) {
10560
- case "left":
10561
- case "top":
10562
- case "width":
10563
- case "height":
10564
- this.requestRedraw();
10565
- break;
10566
- default:
10567
- super._updateStyleProperty(key, value, oldValue);
10568
- break;
10569
- }
10570
- switch (key) {
10571
- case "width":
10572
- if (this.split) {
10573
- this._updateSubTexts();
10574
- }
10575
- break;
10576
- }
10577
- if (typeof key === "string" && textStyles.has(key)) {
10578
- if (this._subTextsCount && key !== "width" && key !== "height") {
10579
- this._getSubTexts().forEach((child) => {
10580
- child.style.setProperties({ [key]: value });
10581
- });
10582
- }
10583
- this.requestRedraw();
10584
- }
10585
- }
10586
- _getSubTexts() {
10587
- return this.children.front.filter((node) => node instanceof exports.Text2D);
10588
- }
10589
- _updateSubTexts() {
10590
- const subTexts = this._getSubTexts();
10591
- let i = 0;
10592
- if (this.split) {
10593
- this.updateMeasure().measureResult?.paragraphs.forEach((p) => {
10594
- p.fragments.forEach((f) => {
10595
- f.characters.forEach((c) => {
10596
- const child = subTexts[i];
10597
- if (child) {
10598
- child.style.left = c.inlineBox.left;
10599
- child.style.top = c.inlineBox.top;
10600
- }
10601
- i++;
10602
- });
10603
- });
10604
- });
10605
- }
10606
- }
10607
- measure() {
10608
- this._updateBase();
10609
- return this.base.measure();
10610
- }
10611
- updateMeasure() {
10612
- this.measureResult = this.measure();
10613
- const { boundingBox } = this.measureResult;
10614
- const { left, top } = this.style;
10615
- this.position.x = left + Math.min(0, boundingBox.left);
10616
- this.position.y = top + Math.min(0, boundingBox.top);
10617
- this.size.width = boundingBox.width;
10618
- this.size.height = boundingBox.height;
10619
- return this;
10620
- }
10621
- _updateSplit() {
10622
- if (this._subTextsCount) {
10623
- this.children.front.forEach((child) => this.removeChild(child));
10624
- this._subTextsCount = 0;
10625
- }
10626
- if (this.split) {
10627
- this.measure().paragraphs.forEach((p) => {
10628
- p.fragments.forEach((f) => {
10629
- f.characters.forEach((c) => {
10630
- this.append(
10631
- new exports.Text2D({
10632
- internalMode: "front",
10633
- style: {
10634
- ...c.computedStyle,
10635
- left: c.inlineBox.x,
10636
- top: c.inlineBox.y,
10637
- width: 0,
10638
- height: 0
10639
- },
10640
- content: c.content,
10641
- effects: this.effects,
10642
- fonts: this.fonts
10643
- })
10644
- );
10645
- this._subTextsCount++;
10646
- });
10647
- });
10648
- });
10649
- }
10650
- }
10651
- _redraw() {
10652
- this.updateMeasure();
10653
- return super._redraw();
10654
- }
10655
- _drawContent() {
10656
- if (!this.split) {
10657
- this.base.render({
10658
- pixelRatio: this.texture.pixelRatio,
10659
- view: this.texture.source
10660
- });
10661
- this.texture.requestUpload();
10662
- super._drawContent();
10663
- }
10664
- }
10665
- };
10666
- __decorateClass$h([
10667
- modernIdoc.property({ fallback: false })
10668
- ], exports.Text2D.prototype, "split", 2);
10669
- __decorateClass$h([
10670
- modernIdoc.property({ alias: "base.content" })
10671
- ], exports.Text2D.prototype, "content", 2);
10672
- __decorateClass$h([
10673
- modernIdoc.property({ alias: "base.effects" })
10674
- ], exports.Text2D.prototype, "effects", 2);
10675
- __decorateClass$h([
10676
- modernIdoc.property({ protected: true, alias: "base.measureDOM" })
10677
- ], exports.Text2D.prototype, "measureDOM", 2);
10678
- __decorateClass$h([
10679
- modernIdoc.property({ protected: true, alias: "base.fonts" })
10680
- ], exports.Text2D.prototype, "fonts", 2);
10681
- exports.Text2D = __decorateClass$h([
10682
- customNode("Text2D")
10683
- ], exports.Text2D);
10684
-
10685
10681
  var __defProp$c = Object.defineProperty;
10686
10682
  var __decorateClass$g = (decorators, target, key, kind) => {
10687
10683
  var result = void 0 ;
@@ -10966,7 +10962,7 @@ exports.Animation = class Animation extends exports.TimelineNode {
10966
10962
  const offset = 1 / targets.length;
10967
10963
  const progress = this.currentTimeProgress;
10968
10964
  targets.forEach((target, i) => {
10969
- const tiem = offset === 1 ? progress : clamp(0, Math.max(0, progress - offset * i) / offset, 1);
10965
+ const tiem = offset === 1 ? progress : clamp(Math.max(0, progress - offset * i) / offset, 0, 1);
10970
10966
  const startProps = this._cachedProps.get(target);
10971
10967
  if (!startProps)
10972
10968
  return;
@@ -11132,13 +11128,13 @@ exports.Animation = class Animation extends exports.TimelineNode {
11132
11128
  }
11133
11129
  };
11134
11130
  __decorateClass$e([
11135
- modernIdoc.property()
11131
+ modernIdoc.property({ fallback: "parent" })
11136
11132
  ], exports.Animation.prototype, "effectMode", 2);
11137
11133
  __decorateClass$e([
11138
- modernIdoc.property()
11134
+ modernIdoc.property({ fallback: false })
11139
11135
  ], exports.Animation.prototype, "loop", 2);
11140
11136
  __decorateClass$e([
11141
- modernIdoc.property()
11137
+ modernIdoc.property({ default: () => [] })
11142
11138
  ], exports.Animation.prototype, "keyframes", 2);
11143
11139
  __decorateClass$e([
11144
11140
  modernIdoc.property()
@@ -12798,7 +12794,7 @@ exports.Scaler = class Scaler extends exports.Node {
12798
12794
  case "scale":
12799
12795
  case "min":
12800
12796
  case "max": {
12801
- this.scale = clamp(this.minScale, this.scale, this.maxScale);
12797
+ this.scale = clamp(this.scale, this.minScale, this.maxScale);
12802
12798
  this._updateTarget();
12803
12799
  break;
12804
12800
  }