@m2c2kit/addons 0.3.3 → 0.3.5

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, Shape, LabelHorizontalAlignmentMode, Transition, StoryOptions, Story, Scene } from '@m2c2kit/core';
2
+ import { CompositeOptions, Size, RgbaColor, Composite, Entity, GlobalVariables, TextOptions, IText, EntityEvent, ShapeOptions, Point, LabelHorizontalAlignmentMode, Transition, StoryOptions, Story, Scene } from '@m2c2kit/core';
3
3
 
4
4
  interface GridOptions extends CompositeOptions {
5
5
  /** Number of rows in the grid. Must be 1 or greater */
@@ -183,7 +183,7 @@ declare class Dialog extends Composite {
183
183
  private backgroundPaint?;
184
184
  constructor(options?: DialogOptions);
185
185
  show(): void;
186
- onDialolgResult(callback: (dailogResultEvent: DialogEvent) => void, replaceExistingCallback?: boolean): void;
186
+ onDialogResult(callback: (dialogResultEvent: DialogEvent) => void, replaceExistingCallback?: boolean): void;
187
187
  initialize(): void;
188
188
  get backgroundColor(): RgbaColor;
189
189
  set backgroundColor(backgroundColor: RgbaColor);
@@ -220,8 +220,8 @@ interface KeyConfiguration {
220
220
  blank?: boolean;
221
221
  /** True is the key is a shift key. */
222
222
  isShift?: boolean;
223
- /** Icon to show on the key. */
224
- keyIcon?: Shape;
223
+ /** ShapeOptions of the optional icon to show on the key. */
224
+ keyIconShapeOptions?: ShapeOptions;
225
225
  }
226
226
  type VirtualKeyboardRow = Array<KeyConfiguration | string | Array<string>>;
227
227
  interface VirtualKeyboardOptions extends CompositeOptions {
@@ -240,10 +240,12 @@ interface VirtualKeyboardOptions extends CompositeOptions {
240
240
  keysPerRow?: number;
241
241
  /** Size of font for keys. */
242
242
  fontSize?: number;
243
+ /** The fonts for the key labels, if not the default font. */
244
+ fontNames?: Array<string> | undefined;
243
245
  /** Comma-separated list of keys to hide. */
244
246
  hiddenKeys?: string;
245
247
  /** If true, only capital letters will be shown. */
246
- captialLettersOnly?: boolean;
248
+ capitalLettersOnly?: boolean;
247
249
  /** Color of keys. */
248
250
  keyColor?: RgbaColor;
249
251
  /** Color of keys when pressed. */
@@ -262,6 +264,16 @@ interface VirtualKeyboardEvent extends EntityEvent {
262
264
  code: string;
263
265
  /** True if the Shift key is pressed. */
264
266
  shiftKey: boolean;
267
+ /** Metadata related to the key tap. */
268
+ keyTapMetadata: KeyTapMetadata;
269
+ }
270
+ interface KeyTapMetadata {
271
+ /** Size of the key. */
272
+ size: Size;
273
+ /** Point on the key where the tap event occurred. */
274
+ point: Point;
275
+ /** Buttons pressed when the key was tapped. */
276
+ buttons: number;
265
277
  }
266
278
  declare class VirtualKeyboard extends Composite {
267
279
  private keyboardHorizontalPaddingPercent;
@@ -271,8 +283,9 @@ declare class VirtualKeyboard extends Composite {
271
283
  private rowsConfiguration;
272
284
  private keysPerRow;
273
285
  private fontSize;
286
+ private fontNames;
274
287
  private hiddenKeys;
275
- private captialLettersOnly;
288
+ private capitalLettersOnly;
276
289
  private keyColor;
277
290
  private keyDownColor;
278
291
  private specialKeyDownColor;
@@ -379,31 +392,31 @@ interface InstructionsOptions extends StoryOptions {
379
392
  postInstructionsScene?: string;
380
393
  /** Array of instruction scenes that form the instructions */
381
394
  instructionScenes: Array<InstructionScene>;
382
- /** Background color for instruction scenes. Can be overriden within a single instruction scene */
395
+ /** Background color for instruction scenes. Can be overridden within a single instruction scene */
383
396
  backgroundColor?: RgbaColor;
384
- /** Scene transition when advancing to the next instruction scene. Default is push transition, to the left, 500 milliseconds duration. Can be overriden within a single instruction scene */
397
+ /** Scene transition when advancing to the next instruction scene. Default is push transition, to the left, 500 milliseconds duration. Can be overridden within a single instruction scene */
385
398
  nextSceneTransition?: Transition;
386
- /** Scene transition when returning to the previous instruction scene. Default is push transition, to the right, 500 milliseconds duration. Can be overriden within a single instruction scene */
399
+ /** Scene transition when returning to the previous instruction scene. Default is push transition, to the right, 500 milliseconds duration. Can be overridden within a single instruction scene */
387
400
  backSceneTransition?: Transition;
388
- /** Button text for the back button. Default is "Back". Can be overriden within a single instruction scene */
401
+ /** Button text for the back button. Default is "Back". Can be overridden within a single instruction scene */
389
402
  backButtonText?: string;
390
- /** Button text for the next button. Default is "Next". Can be overriden within a single instruction scene */
403
+ /** Button text for the next button. Default is "Next". Can be overridden within a single instruction scene */
391
404
  nextButtonText?: string;
392
- /** Width of back button. Default is 125. Can be overriden within a single instruction scene */
405
+ /** Width of back button. Default is 125. Can be overridden within a single instruction scene */
393
406
  backButtonWidth?: number;
394
- /** Width of next button. Default is 125. Can be overriden within a single instruction scene */
407
+ /** Width of next button. Default is 125. Can be overridden within a single instruction scene */
395
408
  nextButtonWidth?: number;
396
- /** Height of back button. Default is 50. Can be overriden within a single instruction scene */
409
+ /** Height of back button. Default is 50. Can be overridden within a single instruction scene */
397
410
  backButtonHeight?: number;
398
- /** Height of next button. Default is 50. Can be overriden within a single instruction scene */
411
+ /** Height of next button. Default is 50. Can be overridden within a single instruction scene */
399
412
  nextButtonHeight?: number;
400
- /** Color of back button. Default is WebColors.Black. Can be overriden within a single instruction scene */
413
+ /** Color of back button. Default is WebColors.Black. Can be overridden within a single instruction scene */
401
414
  backButtonBackgroundColor?: RgbaColor;
402
- /** Color of back button text. Default is WebColors.White. Can be overriden within a single instruction scene */
415
+ /** Color of back button text. Default is WebColors.White. Can be overridden within a single instruction scene */
403
416
  backButtonFontColor?: RgbaColor;
404
- /** Color of next button. Default is WebColors.Black. Can be overriden within a single instruction scene */
417
+ /** Color of next button. Default is WebColors.Black. Can be overridden within a single instruction scene */
405
418
  nextButtonBackgroundColor?: RgbaColor;
406
- /** Color of next button text. Default is WebColors.White. Can be overriden within a single instruction scene */
419
+ /** Color of next button text. Default is WebColors.White. Can be overridden within a single instruction scene */
407
420
  nextButtonFontColor?: RgbaColor;
408
421
  }
409
422
  declare class Instructions extends Story {
@@ -416,4 +429,4 @@ declare class Instructions extends Story {
416
429
  static Create(options: InstructionsOptions): Array<Scene>;
417
430
  }
418
431
 
419
- export { Button, ButtonOptions, Dialog, DialogEvent, DialogOptions, DialogResult, Grid, GridOptions, InstructionScene, Instructions, InstructionsOptions, KeyConfiguration, VirtualKeyboard, VirtualKeyboardEvent, VirtualKeyboardOptions, VirtualKeyboardRow };
432
+ export { Button, ButtonOptions, Dialog, DialogEvent, DialogOptions, DialogResult, Grid, GridOptions, InstructionScene, Instructions, InstructionsOptions, KeyConfiguration, KeyTapMetadata, VirtualKeyboard, VirtualKeyboardEvent, VirtualKeyboardOptions, VirtualKeyboardRow };
package/dist/index.js CHANGED
@@ -121,7 +121,10 @@ class Grid extends Composite {
121
121
  }
122
122
  const x = -this.size.width / 2 + this.cellWidth / 2 + gridChild.column * this.cellWidth;
123
123
  const y = -this.size.height / 2 + this.cellHeight / 2 + gridChild.row * this.cellHeight;
124
- gridChild.entity.position = { x, y };
124
+ gridChild.entity.position = {
125
+ x: x + gridChild.entity.position.x,
126
+ y: y + gridChild.entity.position.y
127
+ };
125
128
  this.gridBackground.addChild(gridChild.entity);
126
129
  });
127
130
  }
@@ -432,7 +435,7 @@ class Dialog extends Composite {
432
435
  show() {
433
436
  this.hidden = false;
434
437
  }
435
- onDialolgResult(callback, replaceExistingCallback = true) {
438
+ onDialogResult(callback, replaceExistingCallback = true) {
436
439
  const eventListener = {
437
440
  type: EventType.CompositeCustom,
438
441
  entityUuid: this.uuid,
@@ -606,12 +609,27 @@ class VirtualKeyboard extends Composite {
606
609
  this.keyHorizontalPaddingPercent = (_d = options.keyHorizontalPaddingPercent) != null ? _d : 0.1;
607
610
  this.keyVerticalPaddingPercent = (_e = options.keyVerticalPaddingPercent) != null ? _e : 0.1;
608
611
  if (options.rows !== void 0) {
609
- this.rowsConfiguration = options.rows;
612
+ this.rowsConfiguration = options.rows.map((row) => {
613
+ const internalRow = row.map((key) => {
614
+ if (key instanceof Object && !Array.isArray(key)) {
615
+ const internalKeyConfig = key;
616
+ if (key.keyIconShapeOptions) {
617
+ internalKeyConfig.keyIcon = new Shape(key.keyIconShapeOptions);
618
+ internalKeyConfig.keyIconShapeOptions = void 0;
619
+ }
620
+ return internalKeyConfig;
621
+ } else {
622
+ return key;
623
+ }
624
+ });
625
+ return internalRow;
626
+ });
610
627
  }
611
628
  this.keysPerRow = (_f = options.keysPerRow) != null ? _f : NaN;
612
629
  this.fontSize = (_g = options.fontSize) != null ? _g : NaN;
630
+ this.fontNames = options.fontNames;
613
631
  this.hiddenKeys = (_h = options.hiddenKeys) != null ? _h : "";
614
- this.captialLettersOnly = (_i = options.captialLettersOnly) != null ? _i : false;
632
+ this.capitalLettersOnly = (_i = options.capitalLettersOnly) != null ? _i : false;
615
633
  this.keyColor = (_j = options.keyColor) != null ? _j : WebColors.White;
616
634
  this.keyDownColor = (_k = options.keyDownColor) != null ? _k : WebColors.Transparent;
617
635
  this.specialKeyDownColor = (_l = options.specialKeyDownColor) != null ? _l : WebColors.LightSteelBlue;
@@ -620,26 +638,6 @@ class VirtualKeyboard extends Composite {
620
638
  }
621
639
  initialize() {
622
640
  var _a, _b, _c, _d, _e, _f, _g;
623
- const shiftArrowShape = new Shape({
624
- path: {
625
- // Public Domain from https://www.freesvg.org
626
- svgString: "m288-6.6849e-14 -288 288h144v288h288v-288h144l-288-288z",
627
- width: 24
628
- },
629
- lineWidth: 2,
630
- strokeColor: WebColors.Black,
631
- fillColor: WebColors.Transparent
632
- });
633
- const backspaceShape = new Shape({
634
- path: {
635
- // CC0 from https://www.svgrepo.com
636
- svgString: "M10.625 5.09 0 22.09l10.625 17H44.18v-34H10.625zm31.555 32H11.734l-9.375-15 9.375-15H42.18v30zm-23.293-6.293 7.293-7.293 7.293 7.293 1.414-1.414-7.293-7.293 7.293-7.293-1.414-1.414-7.293 7.293-7.293-7.293-1.414 1.414 7.293 7.293-7.293 7.293",
637
- width: 24
638
- },
639
- lineWidth: 1,
640
- strokeColor: WebColors.Black,
641
- fillColor: WebColors.Red
642
- });
643
641
  if (this.rowsConfiguration.length === 0) {
644
642
  const numKeys = [
645
643
  ["1", "!"],
@@ -676,12 +674,32 @@ class VirtualKeyboard extends Composite {
676
674
  "k",
677
675
  "l"
678
676
  ];
677
+ const shiftArrowShapeOptions = {
678
+ path: {
679
+ // Public Domain from https://www.freesvg.org
680
+ svgString: "m288-6.6849e-14 -288 288h144v288h288v-288h144l-288-288z",
681
+ width: 24
682
+ },
683
+ lineWidth: 2,
684
+ strokeColor: WebColors.Black,
685
+ fillColor: WebColors.Transparent
686
+ };
687
+ const backspaceShapeOptions = {
688
+ path: {
689
+ // CC0 from https://www.svgrepo.com
690
+ svgString: "M10.625 5.09 0 22.09l10.625 17H44.18v-34H10.625zm31.555 32H11.734l-9.375-15 9.375-15H42.18v30zm-23.293-6.293 7.293-7.293 7.293 7.293 1.414-1.414-7.293-7.293 7.293-7.293-1.414-1.414-7.293 7.293-7.293-7.293-1.414 1.414 7.293 7.293-7.293 7.293",
691
+ width: 24
692
+ },
693
+ lineWidth: 1,
694
+ strokeColor: WebColors.Black,
695
+ fillColor: WebColors.Red
696
+ };
679
697
  const row3 = [
680
698
  {
681
699
  code: "Shift",
682
700
  isShift: true,
683
701
  widthRatio: 1.5,
684
- keyIcon: shiftArrowShape
702
+ keyIcon: new Shape(shiftArrowShapeOptions)
685
703
  },
686
704
  "z",
687
705
  "x",
@@ -690,7 +708,11 @@ class VirtualKeyboard extends Composite {
690
708
  "b",
691
709
  "n",
692
710
  "m",
693
- { code: "Backspace", widthRatio: 1.5, keyIcon: backspaceShape }
711
+ {
712
+ code: "Backspace",
713
+ widthRatio: 1.5,
714
+ keyIcon: new Shape(backspaceShapeOptions)
715
+ }
694
716
  ];
695
717
  const row4 = [
696
718
  { code: " ", labelText: "SPACE", widthRatio: 5 }
@@ -726,7 +748,7 @@ class VirtualKeyboard extends Composite {
726
748
  let isShift = false;
727
749
  if (typeof key === "string") {
728
750
  code = key;
729
- if (this.captialLettersOnly) {
751
+ if (this.capitalLettersOnly) {
730
752
  label = code.toUpperCase();
731
753
  } else {
732
754
  label = code;
@@ -761,8 +783,8 @@ class VirtualKeyboard extends Composite {
761
783
  };
762
784
  const keyboardVerticalPadding = ((_a = this.keyboardVerticalPaddingPercent) != null ? _a : 0.025) * this.size.height;
763
785
  const keyboardHorizontalPadding = ((_b = this.keyboardHorizontalPaddingPercent) != null ? _b : 0.02) * this.size.width;
764
- const keyboxHeight = (this.size.height - 2 * keyboardVerticalPadding) / rows.length;
765
- const keyboxWidth = (this.size.width - 2 * keyboardHorizontalPadding) / this.keysPerRow;
786
+ const keyBoxHeight = (this.size.height - 2 * keyboardVerticalPadding) / rows.length;
787
+ const keyBoxWidth = (this.size.width - 2 * keyboardHorizontalPadding) / this.keysPerRow;
766
788
  for (let r = 0; r < rows.length; r++) {
767
789
  const row = rows[r];
768
790
  const rowSumKeyWidths = row.reduce(
@@ -774,7 +796,7 @@ class VirtualKeyboard extends Composite {
774
796
  );
775
797
  let extraPadding = 0;
776
798
  if (rowSumKeyWidths < this.keysPerRow) {
777
- extraPadding = (this.size.width - 2 * keyboardHorizontalPadding - keyboxWidth * rowSumKeyWidths) / 2;
799
+ extraPadding = (this.size.width - 2 * keyboardHorizontalPadding - keyBoxWidth * rowSumKeyWidths) / 2;
778
800
  }
779
801
  for (let k = 0; k < row.length; k++) {
780
802
  const key = row[k];
@@ -784,33 +806,33 @@ class VirtualKeyboard extends Composite {
784
806
  const keyBoxWidthsSoFar = row.slice(0, k).reduce((sum, key2) => {
785
807
  var _a2;
786
808
  return sum + ((_a2 = key2.widthRatio) != null ? _a2 : 1);
787
- }, 0) * keyboxWidth;
809
+ }, 0) * keyBoxWidth;
788
810
  const keyBox = new Shape({
789
811
  rect: {
790
812
  size: {
791
- width: keyboxWidth * ((_d = key.widthRatio) != null ? _d : 1),
792
- height: keyboxHeight
813
+ width: keyBoxWidth * ((_d = key.widthRatio) != null ? _d : 1),
814
+ height: keyBoxHeight
793
815
  }
794
816
  },
795
817
  fillColor: WebColors.Transparent,
796
818
  strokeColor: WebColors.Transparent,
797
819
  lineWidth: 1,
798
820
  position: {
799
- x: extraPadding + keyboardOrigin.x + keyboardHorizontalPadding + keyBoxWidthsSoFar + ((_e = key.widthRatio) != null ? _e : 1) * keyboxWidth / 2,
800
- y: keyboardOrigin.y + keyboardVerticalPadding + r * keyboxHeight + keyboxHeight / 2
801
- },
802
- isUserInteractionEnabled: true
821
+ x: extraPadding + keyboardOrigin.x + keyboardHorizontalPadding + keyBoxWidthsSoFar + ((_e = key.widthRatio) != null ? _e : 1) * keyBoxWidth / 2,
822
+ y: keyboardOrigin.y + keyboardVerticalPadding + r * keyBoxHeight + keyBoxHeight / 2
823
+ }
803
824
  });
804
- const keyWidth = keyboxWidth * ((_f = key.widthRatio) != null ? _f : 1) - 2 * this.keyHorizontalPaddingPercent * keyboxWidth;
805
- const keyHeight = keyboxHeight - ((_g = key.heightRatio) != null ? _g : 1) - 2 * this.keyVerticalPaddingPercent * keyboxHeight;
825
+ const keyWidth = keyBoxWidth * ((_f = key.widthRatio) != null ? _f : 1) - 2 * this.keyHorizontalPaddingPercent * keyBoxWidth;
826
+ const keyHeight = keyBoxHeight - ((_g = key.heightRatio) != null ? _g : 1) - 2 * this.keyVerticalPaddingPercent * keyBoxHeight;
806
827
  const keyShape = new Shape({
807
828
  rect: { size: { width: keyWidth, height: keyHeight } },
808
829
  cornerRadius: 4,
809
830
  fillColor: this.keyColor,
810
- lineWidth: 0
831
+ lineWidth: 0,
832
+ isUserInteractionEnabled: true
811
833
  });
812
834
  keyBox.addChild(keyShape);
813
- keyBox.onTapUp(() => {
835
+ keyShape.onTapUp((tapEvent) => {
814
836
  var _a2, _b2;
815
837
  let keyAsString = "";
816
838
  if (!key.isShift) {
@@ -818,7 +840,9 @@ class VirtualKeyboard extends Composite {
818
840
  this.shiftActivated = false;
819
841
  if (this.shiftKeyShape) {
820
842
  this.shiftKeyShape.fillColor = this.keyColor;
821
- shiftArrowShape.fillColor = WebColors.Transparent;
843
+ if (key.keyIcon) {
844
+ key.keyIcon.fillColor = WebColors.Transparent;
845
+ }
822
846
  }
823
847
  rows.flatMap((k2) => k2).forEach((k2) => {
824
848
  var _a3, _b3;
@@ -853,19 +877,26 @@ class VirtualKeyboard extends Composite {
853
877
  handled: false,
854
878
  key: keyAsString,
855
879
  code: key.code,
856
- shiftKey: this.shiftActivated
880
+ shiftKey: this.shiftActivated,
881
+ keyTapMetadata: {
882
+ size: keyShape.size,
883
+ point: tapEvent.point,
884
+ buttons: tapEvent.buttons
885
+ }
857
886
  };
858
887
  listener.callback(virtualKeyboardEvent);
859
888
  });
860
889
  }
861
890
  });
862
- keyBox.onTapDown(() => {
891
+ keyShape.onTapDown((tapEvent) => {
863
892
  var _a2, _b2, _c2, _d2;
864
893
  if (key.isShift) {
865
894
  this.shiftActivated = !this.shiftActivated;
866
895
  if (this.shiftActivated) {
867
896
  keyShape.fillColor = this.specialKeyDownColor;
868
- shiftArrowShape.fillColor = WebColors.Black;
897
+ if (key.keyIcon) {
898
+ key.keyIcon.fillColor = WebColors.Black;
899
+ }
869
900
  rows.flatMap((k2) => k2).forEach((k2) => {
870
901
  var _a3, _b3, _c3;
871
902
  if (((_a3 = k2.keyLabel) == null ? void 0 : _a3.text) !== void 0) {
@@ -874,7 +905,9 @@ class VirtualKeyboard extends Composite {
874
905
  });
875
906
  } else {
876
907
  keyShape.fillColor = this.keyColor;
877
- shiftArrowShape.fillColor = WebColors.Transparent;
908
+ if (key.keyIcon) {
909
+ key.keyIcon.fillColor = WebColors.Transparent;
910
+ }
878
911
  rows.flatMap((k2) => k2).forEach((k2) => {
879
912
  var _a3, _b3;
880
913
  if (((_a3 = k2.keyLabel) == null ? void 0 : _a3.text) !== void 0) {
@@ -915,19 +948,25 @@ class VirtualKeyboard extends Composite {
915
948
  handled: false,
916
949
  key: keyAsString,
917
950
  code: key.code,
918
- shiftKey: this.shiftActivated
951
+ shiftKey: this.shiftActivated,
952
+ keyTapMetadata: {
953
+ size: keyShape.size,
954
+ point: tapEvent.point,
955
+ buttons: tapEvent.buttons
956
+ }
919
957
  };
920
958
  listener.callback(virtualKeyboardEvent);
921
959
  });
922
960
  }
923
961
  });
924
- keyBox.onTapLeave(() => {
962
+ keyShape.onTapLeave(() => {
925
963
  keyShape.fillColor = this.keyColor;
926
964
  letterCircle.hidden = true;
927
965
  });
928
966
  const keyLabel = new Label({
929
967
  text: key.labelText,
930
- fontSize: this.fontSize
968
+ fontSize: this.fontSize,
969
+ fontNames: this.fontNames
931
970
  });
932
971
  keyBox.addChild(keyLabel);
933
972
  key.keyLabel = keyLabel;
@@ -948,7 +987,8 @@ class VirtualKeyboard extends Composite {
948
987
  keyboardRectangle.addChild(letterCircle);
949
988
  const letterCircleLabel = new Label({
950
989
  text: "",
951
- fontSize: this.fontSize
990
+ fontSize: this.fontSize,
991
+ fontNames: this.fontNames
952
992
  });
953
993
  letterCircle.addChild(letterCircleLabel);
954
994
  this.needsInitialization = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m2c2kit/addons",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "Additions to m2c2kit core functionalty, such as button, grid, and instructions",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -24,9 +24,8 @@
24
24
  },
25
25
  "devDependencies": {
26
26
  "@rollup/plugin-babel": "6.0.3",
27
- "esbuild": "0.17.17",
28
- "rimraf": "5.0.0",
29
- "rollup": "3.20.6",
27
+ "rimraf": "5.0.1",
28
+ "rollup": "3.21.0",
30
29
  "rollup-plugin-copy": "3.4.0",
31
30
  "rollup-plugin-dts": "5.3.0",
32
31
  "rollup-plugin-esbuild": "5.0.0",