@m2c2kit/core 0.3.13 → 0.3.15

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 +154 -47
  2. package/dist/index.js +1217 -1054
  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,8 +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 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. */
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
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;
427
429
  /** Does the entity respond to user events, such as taps? Default is false */
428
430
  isUserInteractionEnabled?: boolean;
429
431
  /** Can the entity be dragged? */
@@ -1088,12 +1090,12 @@ declare class Game implements Activity {
1088
1090
  * Rather than modify the source code for the game, you can do the following
1089
1091
  * to ensure that the participant ID is saved for each trial:
1090
1092
  *
1091
- * game.addTrialSchema({
1092
- * participant_id: {
1093
+ * game.addTrialSchema(&#123
1094
+ * participant_id: &#123
1093
1095
  * type: "string",
1094
1096
  * description: "ID of the participant",
1095
- * }
1096
- * });
1097
+ * }
1098
+ * });
1097
1099
  * game.addStaticTrialData("participant_id", "12345");
1098
1100
  *
1099
1101
  * When Game.trialComplete() is called, the participant_id variable will
@@ -1298,7 +1300,6 @@ declare class Game implements Activity {
1298
1300
  * @returns true if x, y point is within the entity's bounds
1299
1301
  */
1300
1302
  private IsCanvasPointWithinEntityBounds;
1301
- private calculateEntityAbsoluteBoundingBox;
1302
1303
  prependAssetsGameIdUrl(url: string): string;
1303
1304
  }
1304
1305
 
@@ -1796,6 +1797,7 @@ declare abstract class Entity implements EntityOptions {
1796
1797
  position: Point;
1797
1798
  scale: number;
1798
1799
  alpha: number;
1800
+ zRotation: number;
1799
1801
  isUserInteractionEnabled: boolean;
1800
1802
  draggable: boolean;
1801
1803
  hidden: boolean;
@@ -2143,6 +2145,19 @@ interface FadeAlphaActionOptions {
2143
2145
  runDuringTransition?: boolean;
2144
2146
  }
2145
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
+
2146
2161
  interface IActionContainer {
2147
2162
  children?: Array<Action>;
2148
2163
  }
@@ -2155,7 +2170,8 @@ declare enum ActionType {
2155
2170
  Custom = "Custom",
2156
2171
  Move = "Move",
2157
2172
  Scale = "Scale",
2158
- FadeAlpha = "FadeAlpha"
2173
+ FadeAlpha = "FadeAlpha",
2174
+ Rotate = "Rotate"
2159
2175
  }
2160
2176
 
2161
2177
  /**
@@ -2216,6 +2232,15 @@ declare abstract class Action {
2216
2232
  * @returns The fadeAlpha action
2217
2233
  */
2218
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;
2219
2244
  /**
2220
2245
  * Creates an array of actions that will be run in order.
2221
2246
  *
@@ -2322,6 +2347,15 @@ declare class FadeAlphaAction extends Action {
2322
2347
  delta: number;
2323
2348
  constructor(alpha: number, duration: number, runDuringTransition?: boolean);
2324
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
+ }
2325
2359
 
2326
2360
  declare class CanvasKitHelpers {
2327
2361
  /**
@@ -2335,6 +2369,101 @@ declare class CanvasKitHelpers {
2335
2369
  static makePaint(canvasKit: CanvasKit, color: RgbaColor, style: PaintStyle, isAntialiased: boolean): Paint;
2336
2370
  }
2337
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
+
2338
2467
  interface CompositeOptions extends EntityOptions, DrawableOptions {
2339
2468
  }
2340
2469
 
@@ -2555,40 +2684,14 @@ declare class LayoutConstraint {
2555
2684
  }
2556
2685
 
2557
2686
  /**
2558
- * A set of lines and/or shapes to draw.
2559
- */
2560
- interface M2Path {
2561
- /** The subpath that compose up the path */
2562
- subpaths: Array<Array<Point>>;
2563
- /** The size of the path. This is needed to properly position the shape that is drawn by the path */
2564
- size: Size;
2565
- }
2566
-
2567
- /**
2568
- * 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.
2569
2691
  */
2570
- declare class MutablePath implements M2Path {
2571
- size: Size;
2572
- _subpaths: Point[][];
2573
- get subpaths(): Array<Array<Point>>;
2574
- private currentPath;
2575
- /**
2576
- * Starts a new subpath at a given point.
2577
- *
2578
- * @param point - location at which to start the new subpath
2579
- */
2580
- move(point: Point): void;
2581
- /**
2582
- * Adds a straight line to the current subpath.
2583
- *
2584
- * @remarks The line is added from the last point in the current subpath to
2585
- * the given point.
2586
- *
2587
- * @param point - location where the line will end
2588
- */
2589
- addLine(point: Point): void;
2590
- clear(): void;
2591
- duplicate(newName?: string | undefined): Entity;
2692
+ interface M2ColorfulPath extends M2Path {
2693
+ /** Colors and widths of lines in the path. */
2694
+ linePresentations: Array<LinePresentation>;
2592
2695
  }
2593
2696
 
2594
2697
  declare class RandomDraws {
@@ -2625,7 +2728,7 @@ declare class RandomDraws {
2625
2728
  * grid location to be along the diagonal, the predicate would be:
2626
2729
  * (row, column) => row === column
2627
2730
  * @returns Array of grid cells. Each cell is object in form of:
2628
- * \{ row: number, column: number \}. Grid cell locations are zero-based
2731
+ * &#123 row: number, column: number &#125;. Grid cell locations are zero-based
2629
2732
  */
2630
2733
  static FromGridWithoutReplacement(n: number, rows: number, columns: number, predicate?: (row: number, column: number) => boolean): Array<{
2631
2734
  row: number;
@@ -2659,7 +2762,9 @@ declare enum ShapeType {
2659
2762
  * A path created from an SVG string path.
2660
2763
  */
2661
2764
  interface SvgStringPath {
2662
- /** 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` */
2663
2768
  svgPathString?: string;
2664
2769
  /** If provided, scale the SVG path to this height, and scale the width to keep the original SVG proportions */
2665
2770
  height?: number;
@@ -2682,8 +2787,8 @@ interface ShapeOptions extends EntityOptions, DrawableOptions {
2682
2787
  /** Width of outline. Default is undefined for rectangle and circle, 2 for path. */
2683
2788
  lineWidth?: number;
2684
2789
  /** A path from which to create the shape */
2685
- path?: M2Path | SvgStringPath;
2686
- /** 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. */
2687
2792
  size?: Size;
2688
2793
  /** Should the shape be drawn with anti-aliasing. Default is yes. */
2689
2794
  isAntialiased?: boolean;
@@ -2701,7 +2806,7 @@ declare class Shape extends Entity implements IDrawable, ShapeOptions {
2701
2806
  shapeType: ShapeType;
2702
2807
  circleOfRadius?: number;
2703
2808
  rect?: RectOptions;
2704
- path?: M2Path | SvgStringPath;
2809
+ path?: M2Path | M2ColorfulPath | SvgStringPath;
2705
2810
  ckPath: Path | null;
2706
2811
  ckPathWidth?: number;
2707
2812
  ckPathHeight?: number;
@@ -2722,6 +2827,7 @@ declare class Shape extends Entity implements IDrawable, ShapeOptions {
2722
2827
  private svgPreviousAbsoluteX;
2723
2828
  private svgPreviousAbsoluteY;
2724
2829
  private svgFirstPathDraw;
2830
+ private colorfulPathPaints;
2725
2831
  /**
2726
2832
  * Rectangular, circular, or path-based shape
2727
2833
  *
@@ -2753,6 +2859,7 @@ declare class Shape extends Entity implements IDrawable, ShapeOptions {
2753
2859
  private pathNeedsTransform;
2754
2860
  private shapeIsSvgStringPath;
2755
2861
  private shapeIsM2Path;
2862
+ private pathIsM2ColorfulPath;
2756
2863
  private drawCircle;
2757
2864
  private drawRectangle;
2758
2865
  private drawCircleWithCanvasKit;
@@ -3156,4 +3263,4 @@ declare class WebGlInfo {
3156
3263
  static dispose(): void;
3157
3264
  }
3158
3265
 
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 };
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 };