@m2c2kit/addons 0.3.4 → 0.3.6
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 +17 -4
- package/dist/index.js +77 -37
- package/package.json +4 -4
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,
|
|
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 */
|
|
@@ -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
|
-
/**
|
|
224
|
-
|
|
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,6 +240,8 @@ 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. */
|
|
@@ -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,6 +283,7 @@ 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
288
|
private capitalLettersOnly;
|
|
276
289
|
private keyColor;
|
|
@@ -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 = {
|
|
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
|
}
|
|
@@ -606,10 +609,25 @@ 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
632
|
this.capitalLettersOnly = (_i = options.capitalLettersOnly) != null ? _i : false;
|
|
615
633
|
this.keyColor = (_j = options.keyColor) != null ? _j : WebColors.White;
|
|
@@ -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:
|
|
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
|
-
{
|
|
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 }
|
|
@@ -798,8 +820,7 @@ class VirtualKeyboard extends Composite {
|
|
|
798
820
|
position: {
|
|
799
821
|
x: extraPadding + keyboardOrigin.x + keyboardHorizontalPadding + keyBoxWidthsSoFar + ((_e = key.widthRatio) != null ? _e : 1) * keyBoxWidth / 2,
|
|
800
822
|
y: keyboardOrigin.y + keyboardVerticalPadding + r * keyBoxHeight + keyBoxHeight / 2
|
|
801
|
-
}
|
|
802
|
-
isUserInteractionEnabled: true
|
|
823
|
+
}
|
|
803
824
|
});
|
|
804
825
|
const keyWidth = keyBoxWidth * ((_f = key.widthRatio) != null ? _f : 1) - 2 * this.keyHorizontalPaddingPercent * keyBoxWidth;
|
|
805
826
|
const keyHeight = keyBoxHeight - ((_g = key.heightRatio) != null ? _g : 1) - 2 * this.keyVerticalPaddingPercent * keyBoxHeight;
|
|
@@ -807,10 +828,11 @@ class VirtualKeyboard extends Composite {
|
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
+
"version": "0.3.6",
|
|
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,11 +24,11 @@
|
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@rollup/plugin-babel": "6.0.3",
|
|
27
|
-
"rimraf": "5.0.
|
|
28
|
-
"rollup": "3.
|
|
27
|
+
"rimraf": "5.0.1",
|
|
28
|
+
"rollup": "3.21.0",
|
|
29
29
|
"rollup-plugin-copy": "3.4.0",
|
|
30
30
|
"rollup-plugin-dts": "5.3.0",
|
|
31
31
|
"rollup-plugin-esbuild": "5.0.0",
|
|
32
|
-
"typescript": "5.
|
|
32
|
+
"typescript": "5.1.3"
|
|
33
33
|
}
|
|
34
34
|
}
|