modern-canvas 0.6.11 → 0.6.13

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
@@ -961,6 +961,8 @@ class CoreObject extends modernIdoc.EventEmitter {
961
961
  if (value && typeof value === "object") {
962
962
  if ("toJSON" in value && typeof value.toJSON === "function") {
963
963
  json[key] = value.toJSON();
964
+ } else if (Array.isArray(value)) {
965
+ json[key] = [...value];
964
966
  } else {
965
967
  json[key] = { ...value };
966
968
  }
@@ -2445,7 +2447,7 @@ attribute vec4 aColorMatrixOffset;
2445
2447
  attribute vec4 aDisableWrapMode;
2446
2448
 
2447
2449
  uniform mat3 projectionMatrix;
2448
- uniform mat3 translationMatrix;
2450
+ uniform mat3 worldTransformMatrix;
2449
2451
  uniform vec4 modulate;
2450
2452
 
2451
2453
  varying float vTextureId;
@@ -2457,8 +2459,14 @@ varying vec4 vColorMatrixOffset;
2457
2459
  varying vec4 vDisableWrapMode;
2458
2460
 
2459
2461
  void main(void) {
2462
+ mat3 modelMatrix = mat3(
2463
+ 1.0, 0.0, 0.0,
2464
+ 0.0, 1.0, 0.0,
2465
+ 0.0, 0.0, 1.0
2466
+ );
2460
2467
  vTextureId = aTextureId;
2461
- gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aPosition, 1.0)).xy, 0.0, 1.0);
2468
+ mat3 modelViewProjectionMatrix = projectionMatrix * worldTransformMatrix * modelMatrix;
2469
+ gl_Position = vec4((modelViewProjectionMatrix * vec3(aPosition, 1.0)).xy, 0.0, 1.0);
2462
2470
  vUv = aUv;
2463
2471
  vModulate = aModulate * modulate;
2464
2472
  vBackgroundColor = aBackgroundColor;
@@ -2549,7 +2557,6 @@ void main(void) {
2549
2557
  renderer2.program.updateUniforms(program, {
2550
2558
  samplers,
2551
2559
  modulate: [1, 1, 1, 1],
2552
- translationMatrix: [1, 0, 0, 0, 1, 0, 0, 0, 1],
2553
2560
  ...renderer2.program.uniforms
2554
2561
  });
2555
2562
  renderer2.vertexArray.bind(vao ?? vertexArray);
@@ -3204,7 +3211,8 @@ class WebGLProgramModule extends WebGLModule {
3204
3211
  }
3205
3212
  boundProgram = null;
3206
3213
  uniforms = {
3207
- projectionMatrix: [1, 0, 0, 0, 1, 0, 0, 0, 1]
3214
+ projectionMatrix: [1, 0, 0, 0, 1, 0, 0, 0, 1],
3215
+ worldTransformMatrix: [1, 0, 0, 0, 1, 0, 0, 0, 1]
3208
3216
  };
3209
3217
  create(options) {
3210
3218
  const program = this.gl.createProgram();
@@ -3406,7 +3414,10 @@ ${gl.getShaderInfoLog(shader)}`);
3406
3414
  reset() {
3407
3415
  super.reset();
3408
3416
  this.boundProgram = null;
3409
- this.uniforms = {};
3417
+ this.uniforms = {
3418
+ projectionMatrix: [1, 0, 0, 0, 1, 0, 0, 0, 1],
3419
+ worldTransformMatrix: [1, 0, 0, 0, 1, 0, 0, 0, 1]
3420
+ };
3410
3421
  }
3411
3422
  free() {
3412
3423
  super.free();
@@ -6053,18 +6064,21 @@ exports.Node = class Node extends CoreObject {
6053
6064
  toJSON() {
6054
6065
  return modernIdoc.clearUndef({
6055
6066
  ...super.toJSON(),
6056
- is: this.is,
6057
6067
  children: this._children.length ? [...this._children.map((child) => child.toJSON())] : void 0,
6058
- meta: Object.keys(this.meta).length ? { ...this.meta } : void 0
6068
+ meta: {
6069
+ ...this.meta,
6070
+ inCanvasIs: this.is
6071
+ }
6059
6072
  });
6060
6073
  }
6061
6074
  static parse(value) {
6062
6075
  if (Array.isArray(value)) {
6063
6076
  return value.map((val) => this.parse(val));
6064
6077
  }
6065
- const { is, props, children } = value;
6066
- const Class = customNodes.get(is) ?? exports.Node;
6067
- const node = new Class(props);
6078
+ const { meta = {}, children, ...props } = value;
6079
+ const { inCanvasIs = "Node" } = meta;
6080
+ const Class = customNodes.get(inCanvasIs) ?? exports.Node;
6081
+ const node = new Class({ ...props, meta });
6068
6082
  children?.forEach((child) => node.appendChild(this.parse(child)));
6069
6083
  return node;
6070
6084
  }
@@ -7106,7 +7120,19 @@ class CanvasContext extends modernPath2d.Path2D {
7106
7120
  if (!this.curves.length) {
7107
7121
  return;
7108
7122
  }
7109
- const strokeStyle = this.strokeStyle ?? (typeof this.style.stroke === "string" ? this.style.stroke : void 0);
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
+ }
7135
+ }
7110
7136
  this._draws.push({
7111
7137
  ...options,
7112
7138
  type: "stroke",
@@ -7134,7 +7160,19 @@ class CanvasContext extends modernPath2d.Path2D {
7134
7160
  if (!this.curves.length) {
7135
7161
  return;
7136
7162
  }
7137
- const fillStyle = this.fillStyle ?? (typeof this.style.fill === "string" ? this.style.fill : void 0);
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
+ }
7175
+ }
7138
7176
  this._draws.push({
7139
7177
  ...options,
7140
7178
  type: "fill",
@@ -9279,6 +9317,8 @@ class BaseElement2DText extends CoreObject {
9279
9317
  switch (args[0]) {
9280
9318
  case "content":
9281
9319
  case "effects":
9320
+ case "fill":
9321
+ case "outline":
9282
9322
  this.setter(args[0], args[1]);
9283
9323
  break;
9284
9324
  }
@@ -9295,12 +9335,14 @@ class BaseElement2DText extends CoreObject {
9295
9335
  _updateProperty(key, value, oldValue, declaration) {
9296
9336
  super._updateProperty(key, value, oldValue, declaration);
9297
9337
  switch (key) {
9338
+ case "enabled":
9298
9339
  case "content":
9299
9340
  case "effects":
9300
- case "measureDOM":
9341
+ case "measureDom":
9301
9342
  case "fonts":
9343
+ case "fill":
9344
+ case "outline":
9302
9345
  case "split":
9303
- case "enabled":
9304
9346
  this.parent.requestRedraw();
9305
9347
  break;
9306
9348
  }
@@ -9351,8 +9393,14 @@ __decorateClass$o([
9351
9393
  modernIdoc.property({ alias: "base.effects" })
9352
9394
  ], BaseElement2DText.prototype, "effects");
9353
9395
  __decorateClass$o([
9354
- modernIdoc.property({ protected: true, alias: "base.measureDOM" })
9355
- ], BaseElement2DText.prototype, "measureDOM");
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");
9356
9404
  __decorateClass$o([
9357
9405
  modernIdoc.property({ protected: true, alias: "base.fonts" })
9358
9406
  ], BaseElement2DText.prototype, "fonts");
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Font } from 'modern-font';
2
- import { EventListenerOptions, EventListenerValue, EventEmitter, PropertyDeclaration, ReactiveObject, ReactiveObjectPropertyAccessorContext, Color as Color$1, RawWeakMap as RawWeakMap$1, LinearGradient, RadialGradient, NormalizedFill, Fill, NormalizedBackground, Background, NormalizedForeground, Foreground, NormalizedOutline, Outline, NormalizedShadow, Shadow, NormalizedShape, Shape, NormalizedStyle, Text as Text$1, Style, ImageFillCropRect } from 'modern-idoc';
2
+ import { EventListenerOptions, EventListenerValue, EventEmitter, PropertyDeclaration, ReactiveObject, ReactiveObjectPropertyAccessorContext, Color as Color$1, RawWeakMap as RawWeakMap$1, LinearGradient, RadialGradient, NormalizedFill, Fill, NormalizedBackground, Background, NormalizedForeground, Foreground, NormalizedOutline, Outline, NormalizedShadow, Shadow, NormalizedShape, Shape, FullStyle, Text as Text$1, Style, ImageFillCropRect } from 'modern-idoc';
3
3
  export { Color as ColorValue } from 'modern-idoc';
4
4
  import { AnimationItem } from 'lottie-web';
5
5
  import { Colord, RgbaColor, HslaColor, HsvaColor } from 'colord';
@@ -1046,7 +1046,10 @@ declare class WebGLMaskModule extends WebGLModule {
1046
1046
  declare class WebGLProgramModule extends WebGLModule {
1047
1047
  install(renderer: WebGLRenderer): void;
1048
1048
  boundProgram: WebGLProgram | null;
1049
- uniforms: Record<string, any>;
1049
+ uniforms: {
1050
+ projectionMatrix: number[];
1051
+ worldTransformMatrix: number[];
1052
+ };
1050
1053
  create(options?: WebGLProgramOptions): WebGLProgram;
1051
1054
  getMeta(program: WebGLProgram): WebGLProgramMeta;
1052
1055
  update(options: WebGLProgramOptions): void;
@@ -1607,6 +1610,7 @@ type ProcessSortMode = 'default' | 'parent_before';
1607
1610
  type RenderMode = 'inherit' | 'always' | 'disabled';
1608
1611
  type InternalMode = 'default' | 'front' | 'back';
1609
1612
  interface NodeProperties {
1613
+ id: string;
1610
1614
  name: string;
1611
1615
  mask: Maskable;
1612
1616
  processMode: ProcessMode;
@@ -1708,8 +1712,7 @@ declare class Node extends CoreObject {
1708
1712
  protected _render(renderer: WebGLRenderer): void;
1709
1713
  clone(): this;
1710
1714
  toJSON(): Record<string, any>;
1711
- static parse(value: Record<string, any>[]): Node[];
1712
- static parse(value: Record<string, any>): Node;
1715
+ static parse(value: any): any;
1713
1716
  }
1714
1717
 
1715
1718
  interface TimelineNodeProperties extends NodeProperties {
@@ -1960,7 +1963,7 @@ declare class BaseElement2DShape extends CoreObject {
1960
1963
  drawRect(): void;
1961
1964
  }
1962
1965
 
1963
- interface BaseElement2DStyleProperties extends Omit<NormalizedStyle, 'left' | 'top' | 'width' | 'height'> {
1966
+ interface BaseElement2DStyleProperties extends Omit<FullStyle, 'left' | 'top' | 'width' | 'height'> {
1964
1967
  left: number;
1965
1968
  top: number;
1966
1969
  width: number;
@@ -1977,7 +1980,9 @@ declare class BaseElement2DText extends CoreObject {
1977
1980
  enabled: boolean;
1978
1981
  content: Text['content'];
1979
1982
  effects: Text['effects'];
1980
- measureDOM: Text['measureDOM'];
1983
+ fill: Text['fill'];
1984
+ outline: Text['outline'];
1985
+ measureDom: Text['measureDom'];
1981
1986
  fonts: Text['fonts'];
1982
1987
  readonly base: Text;
1983
1988
  measureResult?: MeasureResult;
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Font } from 'modern-font';
2
- import { EventListenerOptions, EventListenerValue, EventEmitter, PropertyDeclaration, ReactiveObject, ReactiveObjectPropertyAccessorContext, Color as Color$1, RawWeakMap as RawWeakMap$1, LinearGradient, RadialGradient, NormalizedFill, Fill, NormalizedBackground, Background, NormalizedForeground, Foreground, NormalizedOutline, Outline, NormalizedShadow, Shadow, NormalizedShape, Shape, NormalizedStyle, Text as Text$1, Style, ImageFillCropRect } from 'modern-idoc';
2
+ import { EventListenerOptions, EventListenerValue, EventEmitter, PropertyDeclaration, ReactiveObject, ReactiveObjectPropertyAccessorContext, Color as Color$1, RawWeakMap as RawWeakMap$1, LinearGradient, RadialGradient, NormalizedFill, Fill, NormalizedBackground, Background, NormalizedForeground, Foreground, NormalizedOutline, Outline, NormalizedShadow, Shadow, NormalizedShape, Shape, FullStyle, Text as Text$1, Style, ImageFillCropRect } from 'modern-idoc';
3
3
  export { Color as ColorValue } from 'modern-idoc';
4
4
  import { AnimationItem } from 'lottie-web';
5
5
  import { Colord, RgbaColor, HslaColor, HsvaColor } from 'colord';
@@ -1046,7 +1046,10 @@ declare class WebGLMaskModule extends WebGLModule {
1046
1046
  declare class WebGLProgramModule extends WebGLModule {
1047
1047
  install(renderer: WebGLRenderer): void;
1048
1048
  boundProgram: WebGLProgram | null;
1049
- uniforms: Record<string, any>;
1049
+ uniforms: {
1050
+ projectionMatrix: number[];
1051
+ worldTransformMatrix: number[];
1052
+ };
1050
1053
  create(options?: WebGLProgramOptions): WebGLProgram;
1051
1054
  getMeta(program: WebGLProgram): WebGLProgramMeta;
1052
1055
  update(options: WebGLProgramOptions): void;
@@ -1607,6 +1610,7 @@ type ProcessSortMode = 'default' | 'parent_before';
1607
1610
  type RenderMode = 'inherit' | 'always' | 'disabled';
1608
1611
  type InternalMode = 'default' | 'front' | 'back';
1609
1612
  interface NodeProperties {
1613
+ id: string;
1610
1614
  name: string;
1611
1615
  mask: Maskable;
1612
1616
  processMode: ProcessMode;
@@ -1708,8 +1712,7 @@ declare class Node extends CoreObject {
1708
1712
  protected _render(renderer: WebGLRenderer): void;
1709
1713
  clone(): this;
1710
1714
  toJSON(): Record<string, any>;
1711
- static parse(value: Record<string, any>[]): Node[];
1712
- static parse(value: Record<string, any>): Node;
1715
+ static parse(value: any): any;
1713
1716
  }
1714
1717
 
1715
1718
  interface TimelineNodeProperties extends NodeProperties {
@@ -1960,7 +1963,7 @@ declare class BaseElement2DShape extends CoreObject {
1960
1963
  drawRect(): void;
1961
1964
  }
1962
1965
 
1963
- interface BaseElement2DStyleProperties extends Omit<NormalizedStyle, 'left' | 'top' | 'width' | 'height'> {
1966
+ interface BaseElement2DStyleProperties extends Omit<FullStyle, 'left' | 'top' | 'width' | 'height'> {
1964
1967
  left: number;
1965
1968
  top: number;
1966
1969
  width: number;
@@ -1977,7 +1980,9 @@ declare class BaseElement2DText extends CoreObject {
1977
1980
  enabled: boolean;
1978
1981
  content: Text['content'];
1979
1982
  effects: Text['effects'];
1980
- measureDOM: Text['measureDOM'];
1983
+ fill: Text['fill'];
1984
+ outline: Text['outline'];
1985
+ measureDom: Text['measureDom'];
1981
1986
  fonts: Text['fonts'];
1982
1987
  readonly base: Text;
1983
1988
  measureResult?: MeasureResult;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Font } from 'modern-font';
2
- import { EventListenerOptions, EventListenerValue, EventEmitter, PropertyDeclaration, ReactiveObject, ReactiveObjectPropertyAccessorContext, Color as Color$1, RawWeakMap as RawWeakMap$1, LinearGradient, RadialGradient, NormalizedFill, Fill, NormalizedBackground, Background, NormalizedForeground, Foreground, NormalizedOutline, Outline, NormalizedShadow, Shadow, NormalizedShape, Shape, NormalizedStyle, Text as Text$1, Style, ImageFillCropRect } from 'modern-idoc';
2
+ import { EventListenerOptions, EventListenerValue, EventEmitter, PropertyDeclaration, ReactiveObject, ReactiveObjectPropertyAccessorContext, Color as Color$1, RawWeakMap as RawWeakMap$1, LinearGradient, RadialGradient, NormalizedFill, Fill, NormalizedBackground, Background, NormalizedForeground, Foreground, NormalizedOutline, Outline, NormalizedShadow, Shadow, NormalizedShape, Shape, FullStyle, Text as Text$1, Style, ImageFillCropRect } from 'modern-idoc';
3
3
  export { Color as ColorValue } from 'modern-idoc';
4
4
  import { AnimationItem } from 'lottie-web';
5
5
  import { Colord, RgbaColor, HslaColor, HsvaColor } from 'colord';
@@ -1046,7 +1046,10 @@ declare class WebGLMaskModule extends WebGLModule {
1046
1046
  declare class WebGLProgramModule extends WebGLModule {
1047
1047
  install(renderer: WebGLRenderer): void;
1048
1048
  boundProgram: WebGLProgram | null;
1049
- uniforms: Record<string, any>;
1049
+ uniforms: {
1050
+ projectionMatrix: number[];
1051
+ worldTransformMatrix: number[];
1052
+ };
1050
1053
  create(options?: WebGLProgramOptions): WebGLProgram;
1051
1054
  getMeta(program: WebGLProgram): WebGLProgramMeta;
1052
1055
  update(options: WebGLProgramOptions): void;
@@ -1607,6 +1610,7 @@ type ProcessSortMode = 'default' | 'parent_before';
1607
1610
  type RenderMode = 'inherit' | 'always' | 'disabled';
1608
1611
  type InternalMode = 'default' | 'front' | 'back';
1609
1612
  interface NodeProperties {
1613
+ id: string;
1610
1614
  name: string;
1611
1615
  mask: Maskable;
1612
1616
  processMode: ProcessMode;
@@ -1708,8 +1712,7 @@ declare class Node extends CoreObject {
1708
1712
  protected _render(renderer: WebGLRenderer): void;
1709
1713
  clone(): this;
1710
1714
  toJSON(): Record<string, any>;
1711
- static parse(value: Record<string, any>[]): Node[];
1712
- static parse(value: Record<string, any>): Node;
1715
+ static parse(value: any): any;
1713
1716
  }
1714
1717
 
1715
1718
  interface TimelineNodeProperties extends NodeProperties {
@@ -1960,7 +1963,7 @@ declare class BaseElement2DShape extends CoreObject {
1960
1963
  drawRect(): void;
1961
1964
  }
1962
1965
 
1963
- interface BaseElement2DStyleProperties extends Omit<NormalizedStyle, 'left' | 'top' | 'width' | 'height'> {
1966
+ interface BaseElement2DStyleProperties extends Omit<FullStyle, 'left' | 'top' | 'width' | 'height'> {
1964
1967
  left: number;
1965
1968
  top: number;
1966
1969
  width: number;
@@ -1977,7 +1980,9 @@ declare class BaseElement2DText extends CoreObject {
1977
1980
  enabled: boolean;
1978
1981
  content: Text['content'];
1979
1982
  effects: Text['effects'];
1980
- measureDOM: Text['measureDOM'];
1983
+ fill: Text['fill'];
1984
+ outline: Text['outline'];
1985
+ measureDom: Text['measureDom'];
1981
1986
  fonts: Text['fonts'];
1982
1987
  readonly base: Text;
1983
1988
  measureResult?: MeasureResult;