@m2c2kit/core 0.3.12 → 0.3.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.d.ts CHANGED
@@ -422,6 +422,8 @@ interface EntityOptions {
422
422
  position?: Point;
423
423
  /** Scale of the entity. Default is 1.0 */
424
424
  scale?: number;
425
+ /** Opacity of the entity. 0 is fully transparent, 1 is fully opaque. Default is 1.0. Alpha has multiplicative in inheritance. For example, if the entity's parent is alpha .5 and this entity's is alpha .4, then the entity will appear with alpha .2. */
426
+ alpha?: number;
425
427
  /** Does the entity respond to user events, such as taps? Default is false */
426
428
  isUserInteractionEnabled?: boolean;
427
429
  /** Can the entity be dragged? */
@@ -502,6 +504,7 @@ declare class Scene extends Entity implements IDrawable, SceneOptions {
502
504
  * @param callback
503
505
  */
504
506
  onAppear(callback: (scene: Scene) => void): void;
507
+ update(): void;
505
508
  draw(canvas: Canvas): void;
506
509
  warmup(canvas: Canvas): void;
507
510
  }
@@ -1792,6 +1795,7 @@ declare abstract class Entity implements EntityOptions {
1792
1795
  name: string;
1793
1796
  position: Point;
1794
1797
  scale: number;
1798
+ alpha: number;
1795
1799
  isUserInteractionEnabled: boolean;
1796
1800
  draggable: boolean;
1797
1801
  hidden: boolean;
@@ -1802,6 +1806,8 @@ declare abstract class Entity implements EntityOptions {
1802
1806
  absolutePosition: Point;
1803
1807
  size: Size;
1804
1808
  absoluteScale: number;
1809
+ absoluteAlpha: number;
1810
+ absoluteAlphaChange: number;
1805
1811
  actions: Action[];
1806
1812
  queuedAction?: Action;
1807
1813
  originalActions: Action[];
@@ -2022,6 +2028,17 @@ declare abstract class Entity implements EntityOptions {
2022
2028
  private parseLayoutConstraints;
2023
2029
  private calculateYFromConstraint;
2024
2030
  private calculateXFromConstraint;
2031
+ /**
2032
+ * Calculates the absolute alpha of the entity, taking into account the
2033
+ * alpha of all ancestor parent entities.
2034
+ *
2035
+ * @remarks Alpha has multiplicative inheritance from all ancestors.
2036
+ *
2037
+ * @param alpha - Opacity of the entity
2038
+ * @param ancestors - Array of ancestor parent entities
2039
+ * @returns
2040
+ */
2041
+ private calculateAbsoluteAlpha;
2025
2042
  update(): void;
2026
2043
  /**
2027
2044
  * Draws each child entity that is Drawable and is not hidden, by zPosition
@@ -2117,6 +2134,15 @@ interface ScaleActionOptions {
2117
2134
  runDuringTransition?: boolean;
2118
2135
  }
2119
2136
 
2137
+ interface FadeAlphaActionOptions {
2138
+ /** Opacity of the entity. 0 is fully transparent, 1 is fully opaque. */
2139
+ alpha: number;
2140
+ /** Duration of scale, in milliseconds */
2141
+ duration: number;
2142
+ /** Should the action run during screen transitions? Default is no */
2143
+ runDuringTransition?: boolean;
2144
+ }
2145
+
2120
2146
  interface IActionContainer {
2121
2147
  children?: Array<Action>;
2122
2148
  }
@@ -2128,7 +2154,8 @@ declare enum ActionType {
2128
2154
  Wait = "Wait",
2129
2155
  Custom = "Custom",
2130
2156
  Move = "Move",
2131
- Scale = "Scale"
2157
+ Scale = "Scale",
2158
+ FadeAlpha = "FadeAlpha"
2132
2159
  }
2133
2160
 
2134
2161
  /**
@@ -2180,6 +2207,15 @@ declare abstract class Action {
2180
2207
  * @returns The scale action
2181
2208
  */
2182
2209
  static scale(options: ScaleActionOptions): Action;
2210
+ /**
2211
+ * Creates an action that will change the entity's alpha (opacity).
2212
+ *
2213
+ * @remarks Alpha has multiplicative inheritance. For example, if the entity's parent is alpha .5 and this entity's action fades alpha to .4, then the entity will appear with alpha .2.
2214
+ *
2215
+ * @param options - {@link FadeAlphaActionOptions}
2216
+ * @returns The fadeAlpha action
2217
+ */
2218
+ static fadeAlpha(options: FadeAlphaActionOptions): Action;
2183
2219
  /**
2184
2220
  * Creates an array of actions that will be run in order.
2185
2221
  *
@@ -2280,6 +2316,12 @@ declare class ScaleAction extends Action {
2280
2316
  delta: number;
2281
2317
  constructor(scale: number, duration: number, runDuringTransition?: boolean);
2282
2318
  }
2319
+ declare class FadeAlphaAction extends Action {
2320
+ type: ActionType;
2321
+ alpha: number;
2322
+ delta: number;
2323
+ constructor(alpha: number, duration: number, runDuringTransition?: boolean);
2324
+ }
2283
2325
 
2284
2326
  declare class CanvasKitHelpers {
2285
2327
  /**
@@ -2439,6 +2481,8 @@ declare class Label extends Entity implements IDrawable, IText, LabelOptions {
2439
2481
  private paragraph?;
2440
2482
  private paraStyle?;
2441
2483
  private builder?;
2484
+ private _fontPaint?;
2485
+ private _backgroundPaint?;
2442
2486
  private _translatedText;
2443
2487
  /**
2444
2488
  * Single or multi-line text formatted and rendered on the screen.
@@ -2467,6 +2511,10 @@ declare class Label extends Entity implements IDrawable, IText, LabelOptions {
2467
2511
  set preferredMaxLayoutWidth(preferredMaxLayoutWidth: number | undefined);
2468
2512
  get backgroundColor(): RgbaColor | undefined;
2469
2513
  set backgroundColor(backgroundColor: RgbaColor | undefined);
2514
+ private get backgroundPaint();
2515
+ private set backgroundPaint(value);
2516
+ private get fontPaint();
2517
+ private set fontPaint(value);
2470
2518
  /**
2471
2519
  * Duplicates an entity using deep copy.
2472
2520
  *
@@ -2695,6 +2743,7 @@ declare class Shape extends Entity implements IDrawable, ShapeOptions {
2695
2743
  duplicate(newName?: string): Shape;
2696
2744
  update(): void;
2697
2745
  draw(canvas: Canvas): void;
2746
+ private applyAlphaToPaints;
2698
2747
  private drawPathFromM2Path;
2699
2748
  private drawPathFromSvgString;
2700
2749
  private calculateSvgPathY;
@@ -2747,6 +2796,7 @@ declare class Sprite extends Entity implements IDrawable, SpriteOptions {
2747
2796
  zPosition: number;
2748
2797
  private _imageName;
2749
2798
  private loadedImage?;
2799
+ private _paint?;
2750
2800
  /**
2751
2801
  * Visual image displayed on the screen.
2752
2802
  *
@@ -2759,6 +2809,8 @@ declare class Sprite extends Entity implements IDrawable, SpriteOptions {
2759
2809
  dispose(): void;
2760
2810
  set imageName(imageName: string);
2761
2811
  get imageName(): string;
2812
+ private set paint(value);
2813
+ private get paint();
2762
2814
  /**
2763
2815
  * Duplicates an entity using deep copy.
2764
2816
  *
@@ -3104,4 +3156,4 @@ declare class WebGlInfo {
3104
3156
  static dispose(): void;
3105
3157
  }
3106
3158
 
3107
- export { Action, Activity, ActivityKeyValueData, ActivityLifecycleEvent, ActivityResultsEvent, ActivityType, BrowserImage, CallbackOptions, CanvasKitHelpers, Composite, CompositeOptions, Constants, ConstraintType, Constraints, CustomAction, CustomActionOptions, DefaultParameter, Dimensions, DrawableOptions, EasingFunction, Easings, Entity, EntityEvent, EntityEventListener, EntityOptions, EntityType, Equals, EventBase, EventListenerBase, EventType, FontData, FontManager, Game, GameData, GameOptions, GameParameters, GlobalVariables, GoToActivityOptions, GroupAction, I18n, IDataStore, IDrawable, IText, ImageManager, Label, LabelHorizontalAlignmentMode, LabelOptions, Layout, LayoutConstraint, LoadedImage, M2DragEvent, M2Path, M2PointerEvent, MoveAction, MoveActionOptions, MutablePath, NoneTransition, Point, RandomDraws, RectOptions, RgbaColor, ScaleAction, ScaleActionOptions, Scene, SceneOptions, SceneTransition, SequenceAction, Session, SessionDictionaryValues, SessionLifecycleEvent, SessionOptions, Shape, ShapeOptions, ShapeType, Size, SlideTransition, SlideTransitionOptions, Sprite, SpriteOptions, Story, StoryOptions, TapEvent, TextLine, TextLineOptions, TextOptions, Timer, Transition, TransitionDirection, TransitionType, Translations, TrialData, TrialSchema, Uuid, WaitAction, WaitActionOptions, WebColors, WebGlInfo, handleInterfaceOptions };
3159
+ export { Action, Activity, ActivityKeyValueData, ActivityLifecycleEvent, ActivityResultsEvent, ActivityType, BrowserImage, CallbackOptions, CanvasKitHelpers, Composite, CompositeOptions, Constants, ConstraintType, Constraints, CustomAction, CustomActionOptions, DefaultParameter, Dimensions, DrawableOptions, EasingFunction, Easings, Entity, EntityEvent, EntityEventListener, EntityOptions, EntityType, Equals, EventBase, EventListenerBase, EventType, FadeAlphaAction, FadeAlphaActionOptions, FontData, FontManager, Game, GameData, GameOptions, GameParameters, GlobalVariables, GoToActivityOptions, GroupAction, I18n, IDataStore, IDrawable, IText, ImageManager, Label, LabelHorizontalAlignmentMode, LabelOptions, Layout, LayoutConstraint, LoadedImage, M2DragEvent, M2Path, M2PointerEvent, MoveAction, MoveActionOptions, MutablePath, NoneTransition, Point, RandomDraws, RectOptions, RgbaColor, ScaleAction, ScaleActionOptions, Scene, SceneOptions, SceneTransition, SequenceAction, Session, SessionDictionaryValues, SessionLifecycleEvent, SessionOptions, Shape, ShapeOptions, ShapeType, Size, SlideTransition, SlideTransitionOptions, Sprite, SpriteOptions, Story, StoryOptions, TapEvent, TextLine, TextLineOptions, TextOptions, Timer, Transition, TransitionDirection, TransitionType, Translations, TrialData, TrialSchema, Uuid, WaitAction, WaitActionOptions, WebColors, WebGlInfo, handleInterfaceOptions };
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ var ActionType = /* @__PURE__ */ ((ActionType2) => {
5
5
  ActionType2["Custom"] = "Custom";
6
6
  ActionType2["Move"] = "Move";
7
7
  ActionType2["Scale"] = "Scale";
8
+ ActionType2["FadeAlpha"] = "FadeAlpha";
8
9
  return ActionType2;
9
10
  })(ActionType || {});
10
11
 
@@ -218,6 +219,21 @@ class Action {
218
219
  options.runDuringTransition
219
220
  );
220
221
  }
222
+ /**
223
+ * Creates an action that will change the entity's alpha (opacity).
224
+ *
225
+ * @remarks Alpha has multiplicative inheritance. For example, if the entity's parent is alpha .5 and this entity's action fades alpha to .4, then the entity will appear with alpha .2.
226
+ *
227
+ * @param options - {@link FadeAlphaActionOptions}
228
+ * @returns The fadeAlpha action
229
+ */
230
+ static fadeAlpha(options) {
231
+ return new FadeAlphaAction(
232
+ options.alpha,
233
+ options.duration,
234
+ options.runDuringTransition
235
+ );
236
+ }
221
237
  /**
222
238
  * Creates an array of actions that will be run in order.
223
239
  *
@@ -304,6 +320,15 @@ class Action {
304
320
  });
305
321
  break;
306
322
  }
323
+ case ActionType.FadeAlpha: {
324
+ const fadeAlpha = action;
325
+ cloned = Action.fadeAlpha({
326
+ alpha: fadeAlpha.alpha,
327
+ duration: fadeAlpha.duration,
328
+ runDuringTransition: fadeAlpha.runDuringTransition
329
+ });
330
+ break;
331
+ }
307
332
  case ActionType.Wait: {
308
333
  const wait = action;
309
334
  cloned = Action.wait({
@@ -391,6 +416,20 @@ class Action {
391
416
  scaleAction.completed = true;
392
417
  }
393
418
  }
419
+ if (action.type === ActionType.FadeAlpha) {
420
+ const fadeAlphaAction = action;
421
+ if (!fadeAlphaAction.started) {
422
+ fadeAlphaAction.delta = fadeAlphaAction.alpha - entity.alpha;
423
+ fadeAlphaAction.started = true;
424
+ }
425
+ if (elapsed < fadeAlphaAction.duration) {
426
+ entity.alpha = entity.alpha + fadeAlphaAction.delta * (dt / fadeAlphaAction.duration);
427
+ } else {
428
+ entity.alpha = fadeAlphaAction.alpha;
429
+ fadeAlphaAction.running = false;
430
+ fadeAlphaAction.completed = true;
431
+ }
432
+ }
394
433
  }
395
434
  /**
396
435
  * Calculates the duration of an action, including any children actions
@@ -572,6 +611,17 @@ class ScaleAction extends Action {
572
611
  this.isParent = false;
573
612
  }
574
613
  }
614
+ class FadeAlphaAction extends Action {
615
+ constructor(alpha, duration, runDuringTransition = false) {
616
+ super(runDuringTransition);
617
+ __publicField$j(this, "type", ActionType.FadeAlpha);
618
+ __publicField$j(this, "alpha");
619
+ __publicField$j(this, "delta", 0);
620
+ this.duration = duration;
621
+ this.alpha = alpha;
622
+ this.isParent = false;
623
+ }
624
+ }
575
625
 
576
626
  var ActivityType = /* @__PURE__ */ ((ActivityType2) => {
577
627
  ActivityType2["Game"] = "Game";
@@ -588,7 +638,7 @@ class CanvasKitHelpers {
588
638
  * free these wasm objects.
589
639
  */
590
640
  static Dispose(objects) {
591
- objects.filter((o) => !(o == null ? void 0 : o.isDeleted)).forEach((o) => o == null ? void 0 : o.delete());
641
+ objects.filter((o) => !(o == null ? void 0 : o.isDeleted())).forEach((o) => o == null ? void 0 : o.delete());
592
642
  }
593
643
  static makePaint(canvasKit, color, style, isAntialiased) {
594
644
  const paint = new canvasKit.Paint();
@@ -782,21 +832,21 @@ function handleDrawableOptions(drawable, options) {
782
832
  if (options.anchorPoint) {
783
833
  drawable.anchorPoint = options.anchorPoint;
784
834
  }
785
- if (options.zPosition) {
835
+ if (options.zPosition !== void 0) {
786
836
  drawable.zPosition = options.zPosition;
787
837
  }
788
838
  }
789
839
  function handleTextOptions(text, options) {
790
- if (options.text) {
840
+ if (options.text !== void 0) {
791
841
  text.text = options.text;
792
842
  }
793
- if (options.fontName) {
843
+ if (options.fontName !== void 0) {
794
844
  text.fontName = options.fontName;
795
845
  }
796
846
  if (options.fontColor) {
797
847
  text.fontColor = options.fontColor;
798
848
  }
799
- if (options.fontSize) {
849
+ if (options.fontSize !== void 0) {
800
850
  text.fontSize = options.fontSize;
801
851
  }
802
852
  }
@@ -822,6 +872,7 @@ class Entity {
822
872
  __publicField$g(this, "position", { x: 0, y: 0 });
823
873
  // position of the entity in the parent coordinate system
824
874
  __publicField$g(this, "scale", 1);
875
+ __publicField$g(this, "alpha", 1);
825
876
  __publicField$g(this, "isUserInteractionEnabled", false);
826
877
  __publicField$g(this, "draggable", false);
827
878
  __publicField$g(this, "hidden", false);
@@ -833,6 +884,8 @@ class Entity {
833
884
  // position within the root coordinate system
834
885
  __publicField$g(this, "size", { width: 0, height: 0 });
835
886
  __publicField$g(this, "absoluteScale", 1);
887
+ __publicField$g(this, "absoluteAlpha", 1);
888
+ __publicField$g(this, "absoluteAlphaChange", 0);
836
889
  __publicField$g(this, "actions", new Array());
837
890
  __publicField$g(this, "queuedAction");
838
891
  __publicField$g(this, "originalActions", new Array());
@@ -882,22 +935,25 @@ class Entity {
882
935
  } else {
883
936
  this.name = options.name;
884
937
  }
885
- if (options.position) {
938
+ if (options.position !== void 0) {
886
939
  this.position = options.position;
887
940
  }
888
- if (options.scale) {
941
+ if (options.scale !== void 0) {
889
942
  this.scale = options.scale;
890
943
  }
891
- if (options.isUserInteractionEnabled) {
944
+ if (options.alpha !== void 0) {
945
+ this.alpha = options.alpha;
946
+ }
947
+ if (options.isUserInteractionEnabled !== void 0) {
892
948
  this.isUserInteractionEnabled = options.isUserInteractionEnabled;
893
949
  }
894
- if (options.draggable) {
950
+ if (options.draggable !== void 0) {
895
951
  this.draggable = options.draggable;
896
952
  }
897
- if (options.hidden) {
953
+ if (options.hidden !== void 0) {
898
954
  this.hidden = options.hidden;
899
955
  }
900
- if (options.layout) {
956
+ if (options.layout !== void 0) {
901
957
  this.layout = options.layout;
902
958
  }
903
959
  }
@@ -1383,12 +1439,30 @@ class Entity {
1383
1439
  }
1384
1440
  return x;
1385
1441
  }
1442
+ /**
1443
+ * Calculates the absolute alpha of the entity, taking into account the
1444
+ * alpha of all ancestor parent entities.
1445
+ *
1446
+ * @remarks Alpha has multiplicative inheritance from all ancestors.
1447
+ *
1448
+ * @param alpha - Opacity of the entity
1449
+ * @param ancestors - Array of ancestor parent entities
1450
+ * @returns
1451
+ */
1452
+ calculateAbsoluteAlpha(alpha, ancestors) {
1453
+ const inheritedAlpha = ancestors.reduce((acc, ancestor) => {
1454
+ return acc * ancestor.alpha;
1455
+ }, 1);
1456
+ return alpha * inheritedAlpha;
1457
+ }
1386
1458
  update() {
1387
1459
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
1388
1460
  if (this.needsInitialization) {
1389
1461
  this.initialize();
1390
1462
  this.needsInitialization = false;
1391
1463
  }
1464
+ this.absoluteAlphaChange = this.calculateAbsoluteAlpha(this.alpha, this.ancestors) - this.absoluteAlpha;
1465
+ this.absoluteAlpha += this.absoluteAlphaChange;
1392
1466
  if (this.parent === void 0) {
1393
1467
  this.absolutePosition.x = this.position.x * this.scale;
1394
1468
  this.absolutePosition.y = this.position.y * this.scale;
@@ -2343,8 +2417,9 @@ class Sprite extends Entity {
2343
2417
  __publicField$b(this, "_imageName", "");
2344
2418
  // public getter/setter is below
2345
2419
  __publicField$b(this, "loadedImage");
2420
+ __publicField$b(this, "_paint");
2346
2421
  handleInterfaceOptions(this, options);
2347
- if (options.imageName) {
2422
+ if (options.imageName !== void 0) {
2348
2423
  this.imageName = options.imageName;
2349
2424
  }
2350
2425
  }
@@ -2363,11 +2438,14 @@ class Sprite extends Entity {
2363
2438
  }
2364
2439
  this.size.width = this.loadedImage.width;
2365
2440
  this.size.height = this.loadedImage.height;
2441
+ if (!this._paint) {
2442
+ this.paint = new this.canvasKit.Paint();
2443
+ }
2366
2444
  this.needsInitialization = false;
2367
2445
  }
2368
2446
  dispose() {
2369
2447
  var _a;
2370
- CanvasKitHelpers.Dispose([(_a = this.loadedImage) == null ? void 0 : _a.image]);
2448
+ CanvasKitHelpers.Dispose([(_a = this.loadedImage) == null ? void 0 : _a.image, this._paint]);
2371
2449
  }
2372
2450
  set imageName(imageName) {
2373
2451
  this._imageName = imageName;
@@ -2376,6 +2454,17 @@ class Sprite extends Entity {
2376
2454
  get imageName() {
2377
2455
  return this._imageName;
2378
2456
  }
2457
+ set paint(paint) {
2458
+ this._paint = paint;
2459
+ }
2460
+ get paint() {
2461
+ if (!this._paint) {
2462
+ throw new Error(
2463
+ `in paint getter: Sprite entity ${this.toString()} paint is undefined.`
2464
+ );
2465
+ }
2466
+ return this._paint;
2467
+ }
2379
2468
  /**
2380
2469
  * Duplicates an entity using deep copy.
2381
2470
  *
@@ -2411,7 +2500,10 @@ class Sprite extends Entity {
2411
2500
  canvas.scale(1 / drawScale, 1 / drawScale);
2412
2501
  const x = (this.absolutePosition.x - this.size.width * this.anchorPoint.x * this.absoluteScale) * drawScale;
2413
2502
  const y = (this.absolutePosition.y - this.size.height * this.anchorPoint.y * this.absoluteScale) * drawScale;
2414
- canvas.drawImage(this.loadedImage.image, x, y);
2503
+ if (this.absoluteAlphaChange !== 0) {
2504
+ this.paint.setAlphaf(this.absoluteAlpha);
2505
+ }
2506
+ canvas.drawImage(this.loadedImage.image, x, y, this.paint);
2415
2507
  canvas.restore();
2416
2508
  }
2417
2509
  super.drawChildren(canvas);
@@ -2496,16 +2588,15 @@ class Scene extends Entity {
2496
2588
  this.scale = Globals.rootScale;
2497
2589
  this.size.width = this.game.canvasCssWidth;
2498
2590
  this.size.height = this.game.canvasCssHeight;
2499
- this.backgroundPaint = new this.canvasKit.Paint();
2500
- this.backgroundPaint.setColor(
2501
- this.canvasKit.Color(
2502
- this.backgroundColor[0],
2503
- this.backgroundColor[1],
2504
- this.backgroundColor[2],
2505
- this.backgroundColor[3]
2506
- )
2591
+ if (this.backgroundPaint) {
2592
+ this.backgroundPaint.delete();
2593
+ }
2594
+ this.backgroundPaint = CanvasKitHelpers.makePaint(
2595
+ this.canvasKit,
2596
+ this.backgroundColor,
2597
+ this.canvasKit.PaintStyle.Fill,
2598
+ false
2507
2599
  );
2508
- this.backgroundPaint.setStyle(this.canvasKit.PaintStyle.Fill);
2509
2600
  this.needsInitialization = false;
2510
2601
  }
2511
2602
  dispose() {
@@ -2582,6 +2673,9 @@ class Scene extends Entity {
2582
2673
  onAppear(callback) {
2583
2674
  this._appearCallback = callback;
2584
2675
  }
2676
+ update() {
2677
+ super.update();
2678
+ }
2585
2679
  draw(canvas) {
2586
2680
  canvas.save();
2587
2681
  const drawScale = Globals.canvasScale / this.absoluteScale;
@@ -2589,6 +2683,9 @@ class Scene extends Entity {
2589
2683
  if (!this.backgroundPaint) {
2590
2684
  throw new Error(`in Scene ${this}, background paint is undefined.`);
2591
2685
  }
2686
+ if (this.absoluteAlphaChange !== 0) {
2687
+ this.backgroundPaint.setAlphaf(this.absoluteAlpha);
2688
+ }
2592
2689
  canvas.drawRect(
2593
2690
  [
2594
2691
  this.position.x * drawScale * Globals.rootScale,
@@ -6080,6 +6177,8 @@ class Label extends Entity {
6080
6177
  __publicField$4(this, "paragraph");
6081
6178
  __publicField$4(this, "paraStyle");
6082
6179
  __publicField$4(this, "builder");
6180
+ __publicField$4(this, "_fontPaint");
6181
+ __publicField$4(this, "_backgroundPaint");
6083
6182
  __publicField$4(this, "_translatedText", "");
6084
6183
  handleInterfaceOptions(this, options);
6085
6184
  if (options.horizontalAlignmentMode) {
@@ -6188,24 +6287,63 @@ class Label extends Entity {
6188
6287
  fontFamilies.push(defaultTypeface.fontFamily);
6189
6288
  }
6190
6289
  this.paraStyle = new this.canvasKit.ParagraphStyle({
6191
- textStyle: {
6192
- color: textColor,
6193
- backgroundColor: this.backgroundColor ? this.canvasKit.Color(
6194
- this.backgroundColor[0],
6195
- this.backgroundColor[1],
6196
- this.backgroundColor[2],
6197
- this.backgroundColor[3]
6198
- ) : void 0,
6199
- fontFamilies,
6200
- fontSize: this.fontSize * Globals.canvasScale
6201
- },
6290
+ textStyle: {},
6202
6291
  textAlign: ckTextAlign
6203
6292
  });
6293
+ if (this.builder) {
6294
+ this.builder.delete();
6295
+ }
6204
6296
  this.builder = this.canvasKit.ParagraphBuilder.Make(
6205
6297
  this.paraStyle,
6206
6298
  fontManager.fontMgr
6207
6299
  );
6300
+ if (!this._backgroundPaint) {
6301
+ this._backgroundPaint = new this.canvasKit.Paint();
6302
+ }
6303
+ if (!this._fontPaint) {
6304
+ this._fontPaint = new this.canvasKit.Paint();
6305
+ }
6306
+ this.fontPaint.setColor(textColor);
6307
+ this.fontPaint.setAlphaf(this.absoluteAlpha);
6308
+ if (this.backgroundColor) {
6309
+ this.backgroundPaint.setColor(this.backgroundColor);
6310
+ this.backgroundPaint.setAlphaf(this.absoluteAlpha);
6311
+ } else {
6312
+ this.backgroundPaint.setColor(this.canvasKit.Color(0, 0, 0, 0));
6313
+ }
6314
+ this.builder.pushPaintStyle(
6315
+ {
6316
+ fontFamilies,
6317
+ fontSize: this.fontSize * Globals.canvasScale,
6318
+ // set default values for below properties as well.
6319
+ fontStyle: {
6320
+ weight: this.canvasKit.FontWeight.Normal,
6321
+ width: this.canvasKit.FontWidth.Normal,
6322
+ slant: this.canvasKit.FontSlant.Oblique
6323
+ },
6324
+ // Normal font style
6325
+ decoration: 0,
6326
+ // No decoration
6327
+ decorationThickness: 1,
6328
+ // Default decoration thickness
6329
+ decorationStyle: this.canvasKit.DecorationStyle.Solid,
6330
+ // Solid decoration style
6331
+ heightMultiplier: -1,
6332
+ // Providing -1, rather than 1.0, gives default height multiplier
6333
+ halfLeading: false,
6334
+ // Default half leading
6335
+ letterSpacing: 0,
6336
+ // Default letter spacing
6337
+ wordSpacing: 0
6338
+ // Default word spacing
6339
+ },
6340
+ this.fontPaint,
6341
+ this.backgroundPaint
6342
+ );
6208
6343
  this.builder.addText(textForParagraph);
6344
+ if (this.paragraph) {
6345
+ this.paragraph.delete();
6346
+ }
6209
6347
  this.paragraph = this.builder.build();
6210
6348
  const preferredWidth = (
6211
6349
  //this.preferredMaxLayoutWidth ?? this.parentScene.game.canvasCssWidth;
@@ -6233,7 +6371,14 @@ class Label extends Entity {
6233
6371
  this.needsInitialization = false;
6234
6372
  }
6235
6373
  dispose() {
6236
- CanvasKitHelpers.Dispose([this.paragraph, this.builder]);
6374
+ CanvasKitHelpers.Dispose([
6375
+ this.paragraph,
6376
+ this.builder,
6377
+ this._fontPaint,
6378
+ // use backing field since it may be undefined
6379
+ this._backgroundPaint
6380
+ // use backing field since it may be undefined
6381
+ ]);
6237
6382
  }
6238
6383
  get text() {
6239
6384
  return this._text;
@@ -6294,6 +6439,24 @@ class Label extends Entity {
6294
6439
  this._backgroundColor = backgroundColor;
6295
6440
  this.needsInitialization = true;
6296
6441
  }
6442
+ get backgroundPaint() {
6443
+ if (!this._backgroundPaint) {
6444
+ throw new Error("backgroundPaint cannot be undefined");
6445
+ }
6446
+ return this._backgroundPaint;
6447
+ }
6448
+ set backgroundPaint(backgroundPaint) {
6449
+ this._backgroundPaint = backgroundPaint;
6450
+ }
6451
+ get fontPaint() {
6452
+ if (!this._fontPaint) {
6453
+ throw new Error("fontPaint cannot be undefined");
6454
+ }
6455
+ return this._fontPaint;
6456
+ }
6457
+ set fontPaint(fontPaint) {
6458
+ this._fontPaint = fontPaint;
6459
+ }
6297
6460
  /**
6298
6461
  * Duplicates an entity using deep copy.
6299
6462
  *
@@ -6322,6 +6485,9 @@ class Label extends Entity {
6322
6485
  }
6323
6486
  update() {
6324
6487
  super.update();
6488
+ if (this.absoluteAlphaChange !== 0) {
6489
+ this.initialize();
6490
+ }
6325
6491
  }
6326
6492
  draw(canvas) {
6327
6493
  if (this.parent && this.text !== "") {
@@ -7103,7 +7269,7 @@ class Session {
7103
7269
  __publicField$2(this, "sessionDictionary", /* @__PURE__ */ new Map());
7104
7270
  __publicField$2(this, "canvasKit");
7105
7271
  __publicField$2(this, "initialized", false);
7106
- __publicField$2(this, "version", "0.3.12 (291d0cee)");
7272
+ __publicField$2(this, "version", "0.3.13 (f05b4c6d)");
7107
7273
  this.options = options;
7108
7274
  for (const activity of this.options.activities) {
7109
7275
  if (this.options.activities.filter((a) => a === activity).length > 1) {
@@ -7711,7 +7877,7 @@ class Shape extends Entity {
7711
7877
  throw new Error("Size cannot be specified for rectangle shape");
7712
7878
  }
7713
7879
  }
7714
- if (options.cornerRadius) {
7880
+ if (options.cornerRadius !== void 0) {
7715
7881
  this.cornerRadius = options.cornerRadius;
7716
7882
  }
7717
7883
  if (options.fillColor) {
@@ -7726,9 +7892,9 @@ class Shape extends Entity {
7726
7892
  if (options.isAntialiased !== void 0) {
7727
7893
  this.isAntialiased = options.isAntialiased;
7728
7894
  }
7729
- if (options.strokeColor && options.lineWidth === void 0) {
7895
+ if (options.strokeColor && !options.lineWidth) {
7730
7896
  console.warn(
7731
- `warning: for entity ${this}, strokeColor = ${options.strokeColor} but lineWidth is undefined. In normal usage, both would be set or both would be undefined.`
7897
+ `warning: for entity ${this}, strokeColor = ${options.strokeColor} but lineWidth is non-zero. In normal usage, both would be set or both would be undefined.`
7732
7898
  );
7733
7899
  }
7734
7900
  if (options.strokeColor === void 0 && options.lineWidth) {
@@ -7795,6 +7961,7 @@ class Shape extends Entity {
7795
7961
  }
7796
7962
  dispose() {
7797
7963
  CanvasKitHelpers.Dispose([
7964
+ // use backing fields, since paints may be undefined
7798
7965
  this._strokeColorPaintAntialiased,
7799
7966
  this._strokeColorPaintNotAntialiased,
7800
7967
  this._fillColorPaintAntialiased,
@@ -7839,6 +8006,14 @@ class Shape extends Entity {
7839
8006
  canvas.save();
7840
8007
  const drawScale = Globals.canvasScale / this.absoluteScale;
7841
8008
  canvas.scale(1 / drawScale, 1 / drawScale);
8009
+ if (this.absoluteAlphaChange !== 0) {
8010
+ this.applyAlphaToPaints(this.absoluteAlpha, [
8011
+ this._fillColorPaintAntialiased,
8012
+ this._fillColorPaintNotAntialiased,
8013
+ this._strokeColorPaintAntialiased,
8014
+ this._strokeColorPaintNotAntialiased
8015
+ ]);
8016
+ }
7842
8017
  if (this.shapeIsM2Path()) {
7843
8018
  this.drawPathFromM2Path(canvas);
7844
8019
  }
@@ -7854,6 +8029,13 @@ class Shape extends Entity {
7854
8029
  canvas.restore();
7855
8030
  super.drawChildren(canvas);
7856
8031
  }
8032
+ applyAlphaToPaints(alpha, paints) {
8033
+ paints.forEach((paint) => {
8034
+ if (paint) {
8035
+ paint.setAlphaf(alpha);
8036
+ }
8037
+ });
8038
+ }
7857
8039
  drawPathFromM2Path(canvas) {
7858
8040
  const drawScale = Globals.canvasScale / this.absoluteScale;
7859
8041
  const pathOriginX = (this.absolutePosition.x - this.anchorPoint.x * this.size.width * this.absoluteScale) * drawScale;
@@ -8227,6 +8409,9 @@ class TextLine extends Entity {
8227
8409
  super.update();
8228
8410
  }
8229
8411
  initialize() {
8412
+ if (this.paint) {
8413
+ this.paint.delete();
8414
+ }
8230
8415
  this.paint = new this.canvasKit.Paint();
8231
8416
  this.paint.setColor(
8232
8417
  this.canvasKit.Color(
@@ -8266,6 +8451,9 @@ class TextLine extends Entity {
8266
8451
  this.typeface = fontManager.getTypeface(gameUuid, fontNames[0]);
8267
8452
  }
8268
8453
  }
8454
+ if (this.font) {
8455
+ this.font.delete();
8456
+ }
8269
8457
  this.font = new this.canvasKit.Font(
8270
8458
  this.typeface,
8271
8459
  this.fontSize * Globals.canvasScale
@@ -8341,6 +8529,9 @@ class TextLine extends Entity {
8341
8529
  `in TextLine entity ${this}, Paint or Font is undefined.`
8342
8530
  );
8343
8531
  }
8532
+ if (this.absoluteAlphaChange !== 0) {
8533
+ paintForDraw.setAlphaf(this.absoluteAlpha);
8534
+ }
8344
8535
  canvas.drawText(textForDraw, x, y, paintForDraw, this.font);
8345
8536
  canvas.restore();
8346
8537
  }
@@ -8357,5 +8548,5 @@ class TextLine extends Entity {
8357
8548
  }
8358
8549
  }
8359
8550
 
8360
- export { Action, ActivityType, CanvasKitHelpers, Composite, Constants, ConstraintType, CustomAction, Dimensions, Easings, Entity, EntityType, Equals, EventType, FontManager, Game, GlobalVariables, GroupAction, I18n, ImageManager, Label, LabelHorizontalAlignmentMode, LayoutConstraint, LoadedImage, MoveAction, MutablePath, NoneTransition, RandomDraws, ScaleAction, Scene, SceneTransition, SequenceAction, Session, Shape, ShapeType, SlideTransition, Sprite, Story, TextLine, Timer, Transition, TransitionDirection, TransitionType, Uuid, WaitAction, WebColors, WebGlInfo, handleInterfaceOptions };
8551
+ export { Action, ActivityType, CanvasKitHelpers, Composite, Constants, ConstraintType, CustomAction, Dimensions, Easings, Entity, EntityType, Equals, EventType, FadeAlphaAction, FontManager, Game, GlobalVariables, GroupAction, I18n, ImageManager, Label, LabelHorizontalAlignmentMode, LayoutConstraint, LoadedImage, MoveAction, MutablePath, NoneTransition, RandomDraws, ScaleAction, Scene, SceneTransition, SequenceAction, Session, Shape, ShapeType, SlideTransition, Sprite, Story, TextLine, Timer, Transition, TransitionDirection, TransitionType, Uuid, WaitAction, WebColors, WebGlInfo, handleInterfaceOptions };
8361
8552
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m2c2kit/core",
3
- "version": "0.3.12",
3
+ "version": "0.3.13",
4
4
  "description": "The m2c2kit core functionality",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",