@m2c2kit/addons 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.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Canvas } from 'canvaskit-wasm';
2
- import { CompositeOptions, Size, RgbaColor, Composite, Entity, GlobalVariables, TextOptions, IText, EntityEvent, Point, CallbackOptions, ShapeOptions, LabelHorizontalAlignmentMode, Transition, StoryOptions, Story, Scene } from '@m2c2kit/core';
2
+ import { CompositeOptions, Size, RgbaColor, Composite, M2Node, GlobalVariables, TextOptions, IText, M2NodeEvent, CallbackOptions, Point, ShapeOptions, LabelHorizontalAlignmentMode, Transition, StoryOptions, Story, Scene, SceneOptions } from '@m2c2kit/core';
3
3
 
4
4
  interface GridOptions extends CompositeOptions {
5
5
  /** Number of rows in the grid. Must be 1 or greater */
@@ -16,7 +16,7 @@ interface GridOptions extends CompositeOptions {
16
16
  gridLineColor?: RgbaColor;
17
17
  }
18
18
  interface GridChild {
19
- entity: Entity;
19
+ node: M2Node;
20
20
  row: number;
21
21
  column: number;
22
22
  }
@@ -32,11 +32,11 @@ declare class Grid extends Composite {
32
32
  gridChildren: GridChild[];
33
33
  private _gridBackground?;
34
34
  /**
35
- * A rectangular grid that supports placement of entities within the grid's
35
+ * A rectangular grid that supports placement of nodes within the grid's
36
36
  * cells.
37
37
  *
38
- * @remarks This composite entity is composed of rectangles and lines. It
39
- * has convenience functions for placing and clearing entities on the grid
38
+ * @remarks This composite node is composed of rectangles and lines. It
39
+ * has convenience functions for placing and clearing nodes on the grid
40
40
  * by row and column position (zero-based indexing)
41
41
  *
42
42
  * @param options - {@link GridOptions}
@@ -47,13 +47,13 @@ declare class Grid extends Composite {
47
47
  private set gridBackground(value);
48
48
  dispose(): void;
49
49
  /**
50
- * Duplicates an entity using deep copy.
50
+ * Duplicates a node using deep copy.
51
51
  *
52
- * @remarks This is a deep recursive clone (entity and children).
53
- * The uuid property of all duplicated entities will be newly created,
52
+ * @remarks This is a deep recursive clone (node and children).
53
+ * The uuid property of all duplicated nodes will be newly created,
54
54
  * because uuid must be unique.
55
55
  *
56
- * @param newName - optional name of the new, duplicated entity. If not
56
+ * @param newName - optional name of the new, duplicated node. If not
57
57
  * provided, name will be the new uuid
58
58
  */
59
59
  duplicate(newName?: string): Grid;
@@ -65,26 +65,26 @@ declare class Grid extends Composite {
65
65
  */
66
66
  removeAllChildren(): void;
67
67
  /**
68
- * Adds an entity to the grid at the specified row and column position.
68
+ * Adds a node to the grid at the specified row and column position.
69
69
  *
70
- * @param entity - entity to add to the grid
71
- * @param row - row position within grid to add entity; zero-based indexing
72
- * @param column - column position within grid to add entity; zero-based indexing
70
+ * @param node - node to add to the grid
71
+ * @param row - row position within grid to add node; zero-based indexing
72
+ * @param column - column position within grid to add node; zero-based indexing
73
73
  */
74
- addAtCell(entity: Entity, row: number, column: number): void;
74
+ addAtCell(node: M2Node, row: number, column: number): void;
75
75
  /**
76
- * Removes all child entities at the specified row and column position.
76
+ * Removes all child nodes at the specified row and column position.
77
77
  *
78
78
  * @param row - row position within grid at which to remove children; zero-based indexing
79
79
  * @param column - column position within grid at which to remove children; zero-based indexing
80
80
  */
81
81
  removeAllAtCell(row: number, column: number): void;
82
82
  /**
83
- * Removes the child entity from the grid.
83
+ * Removes the child node from the grid.
84
84
  *
85
- * @param entity - entity to remove
85
+ * @param node - node to remove
86
86
  */
87
- removeChild(entity: Entity): void;
87
+ removeChild(node: M2Node): void;
88
88
  }
89
89
 
90
90
  declare global {
@@ -111,13 +111,13 @@ declare class Button extends Composite implements IText {
111
111
  };
112
112
  cornerRadius: number;
113
113
  fontSize: number;
114
- text: string;
114
+ private _text;
115
115
  private _fontColor;
116
116
  private backgroundPaint?;
117
117
  /**
118
118
  * A simple button of rectangle with text centered inside.
119
119
  *
120
- * @remarks This composite entity is composed of a rectangle and text. To
120
+ * @remarks This composite node is composed of a rectangle and text. To
121
121
  * respond to user taps, the isUserInteractionEnabled property must be set
122
122
  * to true and an appropriate callback must be set to handle the tap event.
123
123
  *
@@ -126,18 +126,20 @@ declare class Button extends Composite implements IText {
126
126
  constructor(options: ButtonOptions);
127
127
  initialize(): void;
128
128
  dispose(): void;
129
+ get text(): string;
130
+ set text(text: string);
129
131
  get backgroundColor(): RgbaColor;
130
132
  set backgroundColor(backgroundColor: RgbaColor);
131
133
  get fontColor(): RgbaColor;
132
134
  set fontColor(fontColor: RgbaColor);
133
135
  /**
134
- * Duplicates an entity using deep copy.
136
+ * Duplicates a node using deep copy.
135
137
  *
136
- * @remarks This is a deep recursive clone (entity and children).
137
- * The uuid property of all duplicated entities will be newly created,
138
+ * @remarks This is a deep recursive clone (node and children).
139
+ * The uuid property of all duplicated nodes will be newly created,
138
140
  * because uuid must be unique.
139
141
  *
140
- * @param newName - optional name of the new, duplicated entity. If not
142
+ * @param newName - optional name of the new, duplicated node. If not
141
143
  * provided, name will be the new uuid
142
144
  */
143
145
  duplicate(newName?: string): Button;
@@ -167,7 +169,7 @@ declare enum DialogResult {
167
169
  Positive = "Positive",
168
170
  Negative = "Negative"
169
171
  }
170
- interface DialogEvent extends EntityEvent {
172
+ interface DialogEvent extends M2NodeEvent {
171
173
  dialogResult: DialogResult;
172
174
  }
173
175
  declare class Dialog extends Composite {
@@ -184,20 +186,20 @@ declare class Dialog extends Composite {
184
186
  private backgroundPaint?;
185
187
  constructor(options?: DialogOptions);
186
188
  show(): void;
187
- onDialogResult(callback: (dialogResultEvent: DialogEvent) => void, replaceExistingCallback?: boolean): void;
189
+ onDialogResult(callback: (dialogResultEvent: DialogEvent) => void, options?: CallbackOptions): void;
188
190
  initialize(): void;
189
191
  get backgroundColor(): RgbaColor;
190
192
  set backgroundColor(backgroundColor: RgbaColor);
191
193
  get fontColor(): RgbaColor;
192
194
  set fontColor(fontColor: RgbaColor);
193
195
  /**
194
- * Duplicates an entity using deep copy.
196
+ * Duplicates a node using deep copy.
195
197
  *
196
- * @remarks This is a deep recursive clone (entity and children).
197
- * The uuid property of all duplicated entities will be newly created,
198
+ * @remarks This is a deep recursive clone (node and children).
199
+ * The uuid property of all duplicated nodes will be newly created,
198
200
  * because uuid must be unique.
199
201
  *
200
- * @param newName - optional name of the new, duplicated entity. If not
202
+ * @param newName - optional name of the new, duplicated node. If not
201
203
  * provided, name will be the new uuid
202
204
  */
203
205
  duplicate(newName?: string): Dialog;
@@ -234,7 +236,7 @@ declare const DrawPadEventType: {
234
236
  readonly StrokeEnd: "StrokeEnd";
235
237
  };
236
238
  type DrawPadEventType = (typeof DrawPadEventType)[keyof typeof DrawPadEventType];
237
- interface DrawPadEvent extends EntityEvent {
239
+ interface DrawPadEvent extends M2NodeEvent {
238
240
  type: DrawPadEventType;
239
241
  position: Point;
240
242
  }
@@ -243,7 +245,7 @@ declare const DrawPadItemEventType: {
243
245
  readonly StrokeLeave: "StrokeLeave";
244
246
  };
245
247
  type DrawPadItemEventType = (typeof DrawPadItemEventType)[keyof typeof DrawPadItemEventType];
246
- interface DrawPadItemEvent extends EntityEvent {
248
+ interface DrawPadItemEvent extends M2NodeEvent {
247
249
  type: DrawPadItemEventType;
248
250
  }
249
251
  interface StrokeInteraction {
@@ -253,6 +255,8 @@ interface StrokeInteraction {
253
255
  position: Point;
254
256
  /** Device ISO8601 Timestamp of the interaction. */
255
257
  iso8601Timestamp: string;
258
+ /** Was the interaction's position interpolated? (clipped to DrawPad boundary) because the user drew out of bounds? @remarks Only StrokeMove and StrokeEnd can be interpolated. A StrokeStart position can never begin out of bounds. */
259
+ interpolated: boolean;
256
260
  }
257
261
  type DrawPadStroke = Array<StrokeInteraction>;
258
262
  interface DrawPadItem {
@@ -299,7 +303,7 @@ declare class DrawPad extends Composite {
299
303
  /**
300
304
  * A rectangular area on which the user can draw strokes (lines).
301
305
  *
302
- * @remarks This composite entity is composed of a rectangle Shape and
306
+ * @remarks This composite node is composed of a rectangle Shape and
303
307
  * another Shape that is formed from a path of points.
304
308
  *
305
309
  * @param options - {@link DrawPadOptions}
@@ -310,6 +314,7 @@ declare class DrawPad extends Composite {
310
314
  private initializeDrawArea;
311
315
  private dist;
312
316
  private handleTapDown;
317
+ private addInterpolatedStrokeMove;
313
318
  private handleTapLeave;
314
319
  private handleTapUpAny;
315
320
  private handlePointerMove;
@@ -344,20 +349,20 @@ declare class DrawPad extends Composite {
344
349
  */
345
350
  onStrokeEnd(callback: (ev: DrawPadEvent) => void, options?: CallbackOptions): void;
346
351
  /**
347
- * Adds an entity to the DrawPad.
352
+ * Adds a node to the DrawPad.
348
353
  *
349
- * @remarks After the entity is added to the DrawPad, its
354
+ * @remarks After the node is added to the DrawPad, its
350
355
  * position is adjusted to be relative to the DrawPad's coordinate
351
356
  * system, and it is made interactive. The method returns an object
352
- * which is the entity as a DrawPadItem, which has additional methods,
353
- * properties, and events specific to it now being on a DrawPad. The entity
357
+ * which is the node as a DrawPadItem, which has additional methods,
358
+ * properties, and events specific to it now being on a DrawPad. The node
354
359
  * now **must** be manipulated only using the DrawPadItem object. Using
355
- * the original entity object will result in undefined behavior.
360
+ * the original node object will result in undefined behavior.
356
361
  *
357
- * @param entity - the entity to add to the DrawPad
358
- * @returns the entity as a DrawPadItem
362
+ * @param node - the node to add to the DrawPad
363
+ * @returns the node as a DrawPadItem
359
364
  */
360
- addItem<T extends Entity>(entity: T): T & DrawPadItem;
365
+ addItem<T extends M2Node>(node: T): T & DrawPadItem;
361
366
  /**
362
367
  * Takes a screenshot of the DrawPad.
363
368
  *
@@ -365,6 +370,24 @@ declare class DrawPad extends Composite {
365
370
  * PNG format.
366
371
  */
367
372
  takeScreenshot(): string;
373
+ /**
374
+ * Determines whether a point is within the DrawPad.
375
+ *
376
+ * @param point - The point to check
377
+ * @returns True - if the point is within the DrawPad, false otherwise
378
+ */
379
+ private isPointWithinDrawPad;
380
+ /**
381
+ * Interpolates a point to the border of the DrawPad based on a line that
382
+ * crosses the DrawPad border. The line is formed by the current "out of
383
+ * bounds" point the and previous "within bounds" point.
384
+ *
385
+ * @param currentPoint - The current point
386
+ * @param previousPoint - The previous point
387
+ * @param drawPadSize - The size of the DrawPad
388
+ * @returns A new point on the border of the DrawPad
389
+ */
390
+ private interpolateToDrawPadBorder;
368
391
  private arrayBufferToBase64String;
369
392
  get backgroundColor(): RgbaColor;
370
393
  set backgroundColor(backgroundColor: RgbaColor);
@@ -431,7 +454,7 @@ interface VirtualKeyboardOptions extends CompositeOptions {
431
454
  /** If true, a preview of the key that will be pressed will be shown. */
432
455
  showKeyDownPreview?: boolean;
433
456
  }
434
- interface VirtualKeyboardEvent extends EntityEvent {
457
+ interface VirtualKeyboardEvent extends M2NodeEvent {
435
458
  /** String that is generated when key is pressed, with any modifiers (e.g., Shift) applied. */
436
459
  key: string;
437
460
  /** Code for the key, not taking into account any modifiers. */
@@ -478,29 +501,21 @@ declare class VirtualKeyboard extends Composite {
478
501
  * Executes a callback when the user presses down on a key.
479
502
  *
480
503
  * @param callback - function to execute
481
- * @param replaceExistingCallback - should the provided callback replace
482
- * any existing callbacks of the same event type on this entity? Usually
483
- * there should be only one callback defined, instead of chaining multiple
484
- * ones. It is strongly recommended not to change this, unless you have a
485
- * special use case. Default is true.
504
+ * @param options
486
505
  */
487
- onKeyDown(callback: (virtualKeyboardEvent: VirtualKeyboardEvent) => void, replaceExistingCallback?: boolean): void;
506
+ onKeyDown(callback: (virtualKeyboardEvent: VirtualKeyboardEvent) => void, options?: CallbackOptions): void;
488
507
  /**
489
508
  * Executes a callback when the user releases a key.
490
509
  *
491
510
  * @param callback - function to execute
492
- * @param replaceExistingCallback - should the provided callback replace
493
- * any existing callbacks of the same event type on this entity? Usually
494
- * there should be only one callback defined, instead of chaining multiple
495
- * ones. It is strongly recommended not to change this, unless you have a
496
- * special use case. Default is true.
511
+ * @param options
497
512
  */
498
- onKeyUp(callback: (virtualKeyboardEvent: VirtualKeyboardEvent) => void, replaceExistingCallback?: boolean): void;
513
+ onKeyUp(callback: (virtualKeyboardEvent: VirtualKeyboardEvent) => void, options?: CallbackOptions): void;
499
514
  private addVirtualKeyboardEventListener;
500
515
  update(): void;
501
516
  draw(canvas: Canvas): void;
502
517
  warmup(canvas: Canvas): void;
503
- duplicate(newName?: string | undefined): Entity;
518
+ duplicate(newName?: string | undefined): M2Node;
504
519
  }
505
520
 
506
521
  interface InstructionScene {
@@ -595,12 +610,78 @@ interface InstructionsOptions extends StoryOptions {
595
610
  }
596
611
  declare class Instructions extends Story {
597
612
  /**
598
- * Create an array of scenes containing instructions on how to complete the task
613
+ * Creates an array of scenes containing instructions on how to complete the assessment
599
614
  *
600
615
  * @param options - {@link InstructionsOptions}
601
- * @returns
616
+ * @returns instruction scenes
617
+ */
618
+ static create(options: InstructionsOptions): Array<Scene>;
619
+ /**
620
+ * Creates an array of scenes containing instructions on how to complete the assessment
621
+ *
622
+ * @deprecated Use {@link Instructions.create} instead (lower case method name "create")
623
+ *
624
+ * @param options - {@link InstructionsOptions}
625
+ * @returns instruction scenes
602
626
  */
603
627
  static Create(options: InstructionsOptions): Array<Scene>;
604
628
  }
605
629
 
606
- export { Button, type ButtonOptions, Dialog, type DialogEvent, type DialogOptions, DialogResult, DrawPad, type DrawPadEvent, DrawPadEventType, type DrawPadItem, type DrawPadItemEvent, DrawPadItemEventType, type DrawPadOptions, type DrawPadStroke, Grid, type GridOptions, type InstructionScene, Instructions, type InstructionsOptions, type KeyConfiguration, type KeyTapMetadata, type StrokeInteraction, VirtualKeyboard, type VirtualKeyboardEvent, type VirtualKeyboardOptions, type VirtualKeyboardRow };
630
+ interface CountdownSceneOptions extends SceneOptions {
631
+ /** Duration of the countdown, in milliseconds. */
632
+ milliseconds: number;
633
+ /** Duration of the slide transition, in milliseconds, to the next scene after the countdown completes. Default is 500. */
634
+ transitionDurationMilliseconds?: number;
635
+ /** A custom transition to use to present next scene after the countdown completes. */
636
+ transition?: Transition;
637
+ /** Duration in milliseconds to stay on zero before transitioning to the next scene. Default is zero. This option should be used if `transition` is set to `Transition.none()`. Otherwise, the zero will flash for a single frame before presenting the next scene. */
638
+ zeroDwellMilliseconds?: number;
639
+ /** Text shown below the countdown shape. Default is "GET READY". */
640
+ text?: string;
641
+ /** Font name for text */
642
+ textFontName?: string;
643
+ /** Font size for text. Default is 50. */
644
+ textFontSize?: number;
645
+ /** Font color for text. Default is black. */
646
+ textFontColor?: RgbaColor;
647
+ /** Distance between bottom of countdown shape and text. Default is 32. */
648
+ textMarginTop?: number;
649
+ /** Font name for timer numbers. */
650
+ timerNumbersFontName?: string;
651
+ /** Font size for timer numbers. Default is 50. */
652
+ timerNumbersFontSize?: number;
653
+ /** Font size for timer numbers. Default is white. */
654
+ timerNumbersFontColor?: RgbaColor;
655
+ /** String to show when the timer reaches zero. Default is "0". This could be changed to another value, such as "GO!" */
656
+ timerZeroString?: string;
657
+ /** Shape of the timer. Default is a Royal Blue circle with a radius of 100 centered vertically. */
658
+ timerShape?: TimerShape;
659
+ }
660
+ interface TimerShape {
661
+ circle?: {
662
+ /** Radius of the circle timer shape. */
663
+ radius: number;
664
+ };
665
+ rectangle?: {
666
+ /** Width of the rectangle timer shape. */
667
+ width: number;
668
+ /** Height of the rectangle timer shape. */
669
+ height: number;
670
+ /** Corner radius of the rectangle timer shape. Default is 0. */
671
+ cornerRadius?: number;
672
+ };
673
+ /** Color of the timer shape. Default is Royal Blue. */
674
+ fillColor?: RgbaColor;
675
+ /** Default is to center the timer shape vertically within the scene (verticalBias = .5). Setting verticalBias less than .5 will pull the shape towards the top. Setting verticalBias greater than .5 will pull the shape towards the bottom. */
676
+ verticalBias?: number;
677
+ }
678
+ declare class CountdownScene extends Scene {
679
+ /**
680
+ * A scene that counts down from a specified number to zero, then transitions to the next scene.
681
+ *
682
+ * @param options - {@link CountdownSceneOptions}
683
+ */
684
+ constructor(options: CountdownSceneOptions);
685
+ }
686
+
687
+ export { Button, type ButtonOptions, CountdownScene, type CountdownSceneOptions, Dialog, type DialogEvent, type DialogOptions, DialogResult, DrawPad, type DrawPadEvent, DrawPadEventType, type DrawPadItem, type DrawPadItemEvent, DrawPadItemEventType, type DrawPadOptions, type DrawPadStroke, Grid, type GridOptions, type InstructionScene, Instructions, type InstructionsOptions, type KeyConfiguration, type KeyTapMetadata, type StrokeInteraction, type TimerShape, VirtualKeyboard, type VirtualKeyboardEvent, type VirtualKeyboardOptions, type VirtualKeyboardRow };