@m2c2kit/core 0.3.12 → 0.3.14

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +205 -46
  2. package/dist/index.js +1325 -1061
  3. package/package.json +19 -17
package/dist/index.d.ts CHANGED
@@ -365,7 +365,7 @@ declare enum EntityType {
365
365
  type RgbaColor = [number, number, number, number];
366
366
 
367
367
  interface DrawableOptions {
368
- /** Point within the entity that determines its position. Default is \{ x: 0.5, y: 0.5 \}, which centers the entity on its position */
368
+ /** Point within the entity that determines its position. Default is { x: 0.5, y: 0.5 }, which centers the entity on its position */
369
369
  anchorPoint?: Point;
370
370
  /** Value along the z-axis to determine drawing and tap order. Larger values are on top. */
371
371
  zPosition?: number;
@@ -422,6 +422,10 @@ 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 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;
427
+ /** Rotation of the entity around the Z axis. Unit is radians. Default is 0 (no rotation). zRotation has inheritance. In addition to this entity's zRotation, all ancestors' zRotations will be applied. */
428
+ zRotation?: number;
425
429
  /** Does the entity respond to user events, such as taps? Default is false */
426
430
  isUserInteractionEnabled?: boolean;
427
431
  /** Can the entity be dragged? */
@@ -502,6 +506,7 @@ declare class Scene extends Entity implements IDrawable, SceneOptions {
502
506
  * @param callback
503
507
  */
504
508
  onAppear(callback: (scene: Scene) => void): void;
509
+ update(): void;
505
510
  draw(canvas: Canvas): void;
506
511
  warmup(canvas: Canvas): void;
507
512
  }
@@ -1085,12 +1090,12 @@ declare class Game implements Activity {
1085
1090
  * Rather than modify the source code for the game, you can do the following
1086
1091
  * to ensure that the participant ID is saved for each trial:
1087
1092
  *
1088
- * game.addTrialSchema({
1089
- * participant_id: {
1093
+ * game.addTrialSchema(&#123
1094
+ * participant_id: &#123
1090
1095
  * type: "string",
1091
1096
  * description: "ID of the participant",
1092
- * }
1093
- * });
1097
+ * }
1098
+ * });
1094
1099
  * game.addStaticTrialData("participant_id", "12345");
1095
1100
  *
1096
1101
  * When Game.trialComplete() is called, the participant_id variable will
@@ -1295,7 +1300,6 @@ declare class Game implements Activity {
1295
1300
  * @returns true if x, y point is within the entity's bounds
1296
1301
  */
1297
1302
  private IsCanvasPointWithinEntityBounds;
1298
- private calculateEntityAbsoluteBoundingBox;
1299
1303
  prependAssetsGameIdUrl(url: string): string;
1300
1304
  }
1301
1305
 
@@ -1792,6 +1796,8 @@ declare abstract class Entity implements EntityOptions {
1792
1796
  name: string;
1793
1797
  position: Point;
1794
1798
  scale: number;
1799
+ alpha: number;
1800
+ zRotation: number;
1795
1801
  isUserInteractionEnabled: boolean;
1796
1802
  draggable: boolean;
1797
1803
  hidden: boolean;
@@ -1802,6 +1808,8 @@ declare abstract class Entity implements EntityOptions {
1802
1808
  absolutePosition: Point;
1803
1809
  size: Size;
1804
1810
  absoluteScale: number;
1811
+ absoluteAlpha: number;
1812
+ absoluteAlphaChange: number;
1805
1813
  actions: Action[];
1806
1814
  queuedAction?: Action;
1807
1815
  originalActions: Action[];
@@ -2022,6 +2030,17 @@ declare abstract class Entity implements EntityOptions {
2022
2030
  private parseLayoutConstraints;
2023
2031
  private calculateYFromConstraint;
2024
2032
  private calculateXFromConstraint;
2033
+ /**
2034
+ * Calculates the absolute alpha of the entity, taking into account the
2035
+ * alpha of all ancestor parent entities.
2036
+ *
2037
+ * @remarks Alpha has multiplicative inheritance from all ancestors.
2038
+ *
2039
+ * @param alpha - Opacity of the entity
2040
+ * @param ancestors - Array of ancestor parent entities
2041
+ * @returns
2042
+ */
2043
+ private calculateAbsoluteAlpha;
2025
2044
  update(): void;
2026
2045
  /**
2027
2046
  * Draws each child entity that is Drawable and is not hidden, by zPosition
@@ -2117,6 +2136,28 @@ interface ScaleActionOptions {
2117
2136
  runDuringTransition?: boolean;
2118
2137
  }
2119
2138
 
2139
+ interface FadeAlphaActionOptions {
2140
+ /** Opacity of the entity. 0 is fully transparent, 1 is fully opaque. */
2141
+ alpha: number;
2142
+ /** Duration of scale, in milliseconds */
2143
+ duration: number;
2144
+ /** Should the action run during screen transitions? Default is no */
2145
+ runDuringTransition?: boolean;
2146
+ }
2147
+
2148
+ interface RotateActionOptions {
2149
+ /** Relative amount to rotate the entity, in counter-clockwise radians */
2150
+ byAngle?: number;
2151
+ /** Absolute angle to which rotate the entity, in counter-clockwise radians */
2152
+ toAngle?: number;
2153
+ /** If `toAngle` is provided, should the rotation be performed in the direction that leads to the smallest rotation? Default is true */
2154
+ shortestUnitArc?: boolean;
2155
+ /** Duration of rotation, in milliseconds */
2156
+ duration: number;
2157
+ /** Should the action run during screen transitions? Default is false */
2158
+ runDuringTransition?: boolean;
2159
+ }
2160
+
2120
2161
  interface IActionContainer {
2121
2162
  children?: Array<Action>;
2122
2163
  }
@@ -2128,7 +2169,9 @@ declare enum ActionType {
2128
2169
  Wait = "Wait",
2129
2170
  Custom = "Custom",
2130
2171
  Move = "Move",
2131
- Scale = "Scale"
2172
+ Scale = "Scale",
2173
+ FadeAlpha = "FadeAlpha",
2174
+ Rotate = "Rotate"
2132
2175
  }
2133
2176
 
2134
2177
  /**
@@ -2180,6 +2223,24 @@ declare abstract class Action {
2180
2223
  * @returns The scale action
2181
2224
  */
2182
2225
  static scale(options: ScaleActionOptions): Action;
2226
+ /**
2227
+ * Creates an action that will change the entity's alpha (opacity).
2228
+ *
2229
+ * @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.
2230
+ *
2231
+ * @param options - {@link FadeAlphaActionOptions}
2232
+ * @returns The fadeAlpha action
2233
+ */
2234
+ static fadeAlpha(options: FadeAlphaActionOptions): Action;
2235
+ /**
2236
+ * Creates an action that will rotate the entity.
2237
+ *
2238
+ * @remarks Rotate actions are applied to their children. In addition to this entity's rotate action, all ancestors' rotate actions will also be applied.
2239
+ *
2240
+ * @param options - {@link RotateActionOptions}
2241
+ * @returns The rotate action
2242
+ */
2243
+ static rotate(options: RotateActionOptions): Action;
2183
2244
  /**
2184
2245
  * Creates an array of actions that will be run in order.
2185
2246
  *
@@ -2280,6 +2341,21 @@ declare class ScaleAction extends Action {
2280
2341
  delta: number;
2281
2342
  constructor(scale: number, duration: number, runDuringTransition?: boolean);
2282
2343
  }
2344
+ declare class FadeAlphaAction extends Action {
2345
+ type: ActionType;
2346
+ alpha: number;
2347
+ delta: number;
2348
+ constructor(alpha: number, duration: number, runDuringTransition?: boolean);
2349
+ }
2350
+ declare class RotateAction extends Action {
2351
+ type: ActionType;
2352
+ byAngle?: number;
2353
+ toAngle?: number;
2354
+ shortestUnitArc?: boolean;
2355
+ delta: number;
2356
+ finalValue: number;
2357
+ constructor(byAngle: number | undefined, toAngle: number | undefined, shortestUnitArc: boolean | undefined, duration: number, runDuringTransition?: boolean);
2358
+ }
2283
2359
 
2284
2360
  declare class CanvasKitHelpers {
2285
2361
  /**
@@ -2293,6 +2369,101 @@ declare class CanvasKitHelpers {
2293
2369
  static makePaint(canvasKit: CanvasKit, color: RgbaColor, style: PaintStyle, isAntialiased: boolean): Paint;
2294
2370
  }
2295
2371
 
2372
+ /**
2373
+ * A collection of lines to draw.
2374
+ */
2375
+ interface M2Path {
2376
+ /** The subpath that compose up the path */
2377
+ subpaths: Array<Array<Point>>;
2378
+ }
2379
+
2380
+ /**
2381
+ * Subpaths and methods for creating them.
2382
+ *
2383
+ * @remarks Subpaths are an array of lines that are drawn together.
2384
+ */
2385
+ declare class MutablePath implements M2Path {
2386
+ _subpaths: Point[][];
2387
+ get subpaths(): Array<Array<Point>>;
2388
+ protected currentPath: Point[];
2389
+ /**
2390
+ * Starts a new subpath at a given point.
2391
+ *
2392
+ * @param point - location at which to start the new subpath
2393
+ */
2394
+ move(point: Point): void;
2395
+ /**
2396
+ * Adds a straight line to the current subpath.
2397
+ *
2398
+ * @remarks The line is added from the last point in the current subpath to
2399
+ * the given point.
2400
+ *
2401
+ * @param point - location where the line will end
2402
+ */
2403
+ addLine(point: Point): void;
2404
+ /**
2405
+ * Removes all subpaths from the shape.
2406
+ */
2407
+ clear(): void;
2408
+ /**
2409
+ * Makes a deep copy.
2410
+ *
2411
+ * @returns a deep copy
2412
+ */
2413
+ duplicate(): MutablePath;
2414
+ }
2415
+
2416
+ /**
2417
+ * Properties that describe line colors and widths in a `M2ColorfulPath`.
2418
+ */
2419
+ interface LinePresentation {
2420
+ strokeColor: RgbaColor;
2421
+ lineWidth: number;
2422
+ subpathIndex: number;
2423
+ pointIndex: number;
2424
+ }
2425
+
2426
+ /**
2427
+ * Multi-color subpaths and methods for creating them.
2428
+ *
2429
+ * @remarks Subpaths are an array of lines that are drawn together.
2430
+ */
2431
+ declare class ColorfulMutablePath extends MutablePath {
2432
+ /** Stroke color to be applied to subsequent lines. */
2433
+ strokeColor: RgbaColor;
2434
+ /** Line width to be applied to subsequent lines. */
2435
+ lineWidth: number;
2436
+ /** Colors and widths of lines in the path. */
2437
+ linePresentations: Array<LinePresentation>;
2438
+ /**
2439
+ * Adds a straight line to the current subpath
2440
+ *
2441
+ * @remarks The line is added from the last point in the current subpath to
2442
+ * the given point, with the current stroke color and line width.
2443
+ *
2444
+ * @param point - location where the line will end
2445
+ */
2446
+ addLine(point: Point): void;
2447
+ /**
2448
+ * Checks if the current line presentation (stroke color and line width) is
2449
+ * different from the last line presentation.
2450
+ *
2451
+ * @returns true if the current line presentation is different from the last
2452
+ */
2453
+ private isNewLinePresentation;
2454
+ /**
2455
+ * Removes all subpaths from the shape and resets the stroke color and line
2456
+ * width to their default values.
2457
+ */
2458
+ clear(): void;
2459
+ /**
2460
+ * Makes a deep copy.
2461
+ *
2462
+ * @returns a deep copy
2463
+ */
2464
+ duplicate(): ColorfulMutablePath;
2465
+ }
2466
+
2296
2467
  interface CompositeOptions extends EntityOptions, DrawableOptions {
2297
2468
  }
2298
2469
 
@@ -2439,6 +2610,8 @@ declare class Label extends Entity implements IDrawable, IText, LabelOptions {
2439
2610
  private paragraph?;
2440
2611
  private paraStyle?;
2441
2612
  private builder?;
2613
+ private _fontPaint?;
2614
+ private _backgroundPaint?;
2442
2615
  private _translatedText;
2443
2616
  /**
2444
2617
  * Single or multi-line text formatted and rendered on the screen.
@@ -2467,6 +2640,10 @@ declare class Label extends Entity implements IDrawable, IText, LabelOptions {
2467
2640
  set preferredMaxLayoutWidth(preferredMaxLayoutWidth: number | undefined);
2468
2641
  get backgroundColor(): RgbaColor | undefined;
2469
2642
  set backgroundColor(backgroundColor: RgbaColor | undefined);
2643
+ private get backgroundPaint();
2644
+ private set backgroundPaint(value);
2645
+ private get fontPaint();
2646
+ private set fontPaint(value);
2470
2647
  /**
2471
2648
  * Duplicates an entity using deep copy.
2472
2649
  *
@@ -2507,40 +2684,14 @@ declare class LayoutConstraint {
2507
2684
  }
2508
2685
 
2509
2686
  /**
2510
- * A set of lines and/or shapes to draw.
2511
- */
2512
- interface M2Path {
2513
- /** The subpath that compose up the path */
2514
- subpaths: Array<Array<Point>>;
2515
- /** The size of the path. This is needed to properly position the shape that is drawn by the path */
2516
- size: Size;
2517
- }
2518
-
2519
- /**
2520
- * Lines and/or shapes, and methods for creating them.
2687
+ * A collection of multi-color lines to draw.
2688
+ *
2689
+ * @remarks Unlike `M2Path`, this interface allows for lines of different
2690
+ * colors and widths to be drawn in the same path.
2521
2691
  */
2522
- declare class MutablePath implements M2Path {
2523
- size: Size;
2524
- _subpaths: Point[][];
2525
- get subpaths(): Array<Array<Point>>;
2526
- private currentPath;
2527
- /**
2528
- * Starts a new subpath at a given point.
2529
- *
2530
- * @param point - location at which to start the new subpath
2531
- */
2532
- move(point: Point): void;
2533
- /**
2534
- * Adds a straight line to the current subpath.
2535
- *
2536
- * @remarks The line is added from the last point in the current subpath to
2537
- * the given point.
2538
- *
2539
- * @param point - location where the line will end
2540
- */
2541
- addLine(point: Point): void;
2542
- clear(): void;
2543
- duplicate(newName?: string | undefined): Entity;
2692
+ interface M2ColorfulPath extends M2Path {
2693
+ /** Colors and widths of lines in the path. */
2694
+ linePresentations: Array<LinePresentation>;
2544
2695
  }
2545
2696
 
2546
2697
  declare class RandomDraws {
@@ -2577,7 +2728,7 @@ declare class RandomDraws {
2577
2728
  * grid location to be along the diagonal, the predicate would be:
2578
2729
  * (row, column) => row === column
2579
2730
  * @returns Array of grid cells. Each cell is object in form of:
2580
- * \{ row: number, column: number \}. Grid cell locations are zero-based
2731
+ * &#123 row: number, column: number &#125;. Grid cell locations are zero-based
2581
2732
  */
2582
2733
  static FromGridWithoutReplacement(n: number, rows: number, columns: number, predicate?: (row: number, column: number) => boolean): Array<{
2583
2734
  row: number;
@@ -2611,7 +2762,9 @@ declare enum ShapeType {
2611
2762
  * A path created from an SVG string path.
2612
2763
  */
2613
2764
  interface SvgStringPath {
2614
- /** SVG string from which to create te path */
2765
+ /** SVG string from which to create the path */
2766
+ pathString?: string;
2767
+ /** SVG string from which to create the path @deprecated Use `pathString` */
2615
2768
  svgPathString?: string;
2616
2769
  /** If provided, scale the SVG path to this height, and scale the width to keep the original SVG proportions */
2617
2770
  height?: number;
@@ -2634,8 +2787,8 @@ interface ShapeOptions extends EntityOptions, DrawableOptions {
2634
2787
  /** Width of outline. Default is undefined for rectangle and circle, 2 for path. */
2635
2788
  lineWidth?: number;
2636
2789
  /** A path from which to create the shape */
2637
- path?: M2Path | SvgStringPath;
2638
- /** Size of container "view box" for path shapes. Leave undefined for circle and rectangle shapes. */
2790
+ path?: M2Path | M2ColorfulPath | SvgStringPath;
2791
+ /** Size of container "view box" for M2Path and M2ColorfulPath shapes. Leave undefined for circle, rectangle, and SvgStringPath shapes. */
2639
2792
  size?: Size;
2640
2793
  /** Should the shape be drawn with anti-aliasing. Default is yes. */
2641
2794
  isAntialiased?: boolean;
@@ -2653,7 +2806,7 @@ declare class Shape extends Entity implements IDrawable, ShapeOptions {
2653
2806
  shapeType: ShapeType;
2654
2807
  circleOfRadius?: number;
2655
2808
  rect?: RectOptions;
2656
- path?: M2Path | SvgStringPath;
2809
+ path?: M2Path | M2ColorfulPath | SvgStringPath;
2657
2810
  ckPath: Path | null;
2658
2811
  ckPathWidth?: number;
2659
2812
  ckPathHeight?: number;
@@ -2674,6 +2827,7 @@ declare class Shape extends Entity implements IDrawable, ShapeOptions {
2674
2827
  private svgPreviousAbsoluteX;
2675
2828
  private svgPreviousAbsoluteY;
2676
2829
  private svgFirstPathDraw;
2830
+ private colorfulPathPaints;
2677
2831
  /**
2678
2832
  * Rectangular, circular, or path-based shape
2679
2833
  *
@@ -2695,6 +2849,7 @@ declare class Shape extends Entity implements IDrawable, ShapeOptions {
2695
2849
  duplicate(newName?: string): Shape;
2696
2850
  update(): void;
2697
2851
  draw(canvas: Canvas): void;
2852
+ private applyAlphaToPaints;
2698
2853
  private drawPathFromM2Path;
2699
2854
  private drawPathFromSvgString;
2700
2855
  private calculateSvgPathY;
@@ -2704,6 +2859,7 @@ declare class Shape extends Entity implements IDrawable, ShapeOptions {
2704
2859
  private pathNeedsTransform;
2705
2860
  private shapeIsSvgStringPath;
2706
2861
  private shapeIsM2Path;
2862
+ private pathIsM2ColorfulPath;
2707
2863
  private drawCircle;
2708
2864
  private drawRectangle;
2709
2865
  private drawCircleWithCanvasKit;
@@ -2747,6 +2903,7 @@ declare class Sprite extends Entity implements IDrawable, SpriteOptions {
2747
2903
  zPosition: number;
2748
2904
  private _imageName;
2749
2905
  private loadedImage?;
2906
+ private _paint?;
2750
2907
  /**
2751
2908
  * Visual image displayed on the screen.
2752
2909
  *
@@ -2759,6 +2916,8 @@ declare class Sprite extends Entity implements IDrawable, SpriteOptions {
2759
2916
  dispose(): void;
2760
2917
  set imageName(imageName: string);
2761
2918
  get imageName(): string;
2919
+ private set paint(value);
2920
+ private get paint();
2762
2921
  /**
2763
2922
  * Duplicates an entity using deep copy.
2764
2923
  *
@@ -3104,4 +3263,4 @@ declare class WebGlInfo {
3104
3263
  static dispose(): void;
3105
3264
  }
3106
3265
 
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 };
3266
+ export { Action, type Activity, type ActivityKeyValueData, type ActivityLifecycleEvent, type ActivityResultsEvent, ActivityType, type BrowserImage, type CallbackOptions, CanvasKitHelpers, ColorfulMutablePath, Composite, type CompositeOptions, Constants, ConstraintType, type Constraints, CustomAction, type CustomActionOptions, type DefaultParameter, Dimensions, type DrawableOptions, type EasingFunction, Easings, Entity, type EntityEvent, type EntityEventListener, type EntityOptions, EntityType, Equals, type EventBase, type EventListenerBase, EventType, FadeAlphaAction, type FadeAlphaActionOptions, type FontData, FontManager, Game, type GameData, type GameOptions, type GameParameters, GlobalVariables, type GoToActivityOptions, GroupAction, I18n, type IDataStore, type IDrawable, type IText, ImageManager, Label, LabelHorizontalAlignmentMode, type LabelOptions, type Layout, LayoutConstraint, LoadedImage, type M2ColorfulPath, type M2DragEvent, type M2Path, type M2PointerEvent, MoveAction, type MoveActionOptions, MutablePath, NoneTransition, type Point, RandomDraws, type RectOptions, type RgbaColor, RotateAction, ScaleAction, type ScaleActionOptions, Scene, type SceneOptions, SceneTransition, SequenceAction, Session, type SessionDictionaryValues, type SessionLifecycleEvent, type SessionOptions, Shape, type ShapeOptions, ShapeType, type Size, SlideTransition, type SlideTransitionOptions, Sprite, type SpriteOptions, Story, type StoryOptions, type TapEvent, TextLine, type TextLineOptions, type TextOptions, Timer, Transition, TransitionDirection, TransitionType, type Translations, type TrialData, type TrialSchema, Uuid, WaitAction, type WaitActionOptions, WebColors, WebGlInfo, handleInterfaceOptions };