@m2c2kit/addons 0.3.27 → 0.3.29

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/LICENSE CHANGED
@@ -1,21 +1,13 @@
1
- MIT License
1
+ Copyright 2023 Scott T. Yabiku
2
2
 
3
- Copyright (c) 2023 Scott T. Yabiku
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
4
6
 
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
7
+ http://www.apache.org/licenses/LICENSE-2.0
11
8
 
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @m2c2kit/addons
2
2
 
3
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
3
+ [![License: Apache-2.0](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://opensource.org/license/apache-2-0)
4
4
  [![CI/CD](https://github.com/m2c2-project/m2c2kit/actions/workflows/ci.yml/badge.svg)](https://github.com/m2c2-project/m2c2kit/actions/workflows/ci.yml)
5
5
  [![npm version](https://img.shields.io/npm/v/@m2c2kit/addons.svg)](https://www.npmjs.com/package/@m2c2kit/addons)
6
6
 
package/dist/index.d.ts CHANGED
@@ -1366,4 +1366,5 @@ declare class Slider extends Composite implements SliderOptions {
1366
1366
  warmup(canvas: Canvas): void;
1367
1367
  }
1368
1368
 
1369
- export { Button, type ButtonOptions, CountdownScene, type CountdownSceneOptions, CountdownTimer, type CountdownTimerEvent, type CountdownTimerOptions, Dialog, type DialogEvent, type DialogOptions, DialogResult, DrawPad, type DrawPadEvent, DrawPadEventType, type DrawPadItem, type DrawPadItemEvent, DrawPadItemEventType, type DrawPadOptions, type DrawPadStroke, Grid, type GridChild, type GridOptions, type InstructionScene, Instructions, type InstructionsOptions, type KeyConfiguration, type KeyTapMetadata, type LocaleOption, LocalePicker, type LocalePickerEvent, type LocalePickerIcon, type LocalePickerOptions, type LocalePickerResult, Slider, type SliderEvent, type SliderOptions, type StrokeInteraction, type TimerShape, VirtualKeyboard, type VirtualKeyboardEvent, type VirtualKeyboardOptions, type VirtualKeyboardRow };
1369
+ export { Button, CountdownScene, CountdownTimer, Dialog, DialogResult, DrawPad, DrawPadEventType, DrawPadItemEventType, Grid, Instructions, LocalePicker, Slider, VirtualKeyboard };
1370
+ export type { ButtonOptions, CountdownSceneOptions, CountdownTimerEvent, CountdownTimerOptions, DialogEvent, DialogOptions, DrawPadEvent, DrawPadItem, DrawPadItemEvent, DrawPadOptions, DrawPadStroke, GridChild, GridOptions, InstructionScene, InstructionsOptions, KeyConfiguration, KeyTapMetadata, LocaleOption, LocalePickerEvent, LocalePickerIcon, LocalePickerOptions, LocalePickerResult, SliderEvent, SliderOptions, StrokeInteraction, TimerShape, VirtualKeyboardEvent, VirtualKeyboardOptions, VirtualKeyboardRow };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { M2c2KitHelpers, Composite, WebColors, Shape, EventStoreMode, Equal, Label, CanvasKitHelpers, M2EventType, Timer, MutablePath, Easings, Story, Transition, TransitionDirection, LabelHorizontalAlignmentMode, Scene, Dimensions, Sprite, Action } from '@m2c2kit/core';
1
+ import { M2c2KitHelpers, Composite, WebColors, M2Error, Shape, EventStoreMode, Equal, Label, CanvasKitHelpers, M2EventType, Timer, MutablePath, Easings, Story, Transition, TransitionDirection, LabelHorizontalAlignmentMode, Scene, Dimensions, Sprite, Action } from '@m2c2kit/core';
2
2
 
3
3
  class Grid extends Composite {
4
4
  /**
@@ -26,25 +26,25 @@ class Grid extends Composite {
26
26
  if (options.size) {
27
27
  this.size = options.size;
28
28
  } else {
29
- throw new Error("grid size must be specified");
29
+ throw new M2Error("grid size must be specified");
30
30
  }
31
31
  if (options.rows) {
32
32
  if (options.rows >= 1) {
33
33
  this.rows = options.rows;
34
34
  } else {
35
- throw new Error("grid rows must be at least 1");
35
+ throw new M2Error("grid rows must be at least 1");
36
36
  }
37
37
  } else {
38
- throw new Error("grid rows must be specified");
38
+ throw new M2Error("grid rows must be specified");
39
39
  }
40
40
  if (options.columns) {
41
41
  if (options.columns >= 1) {
42
42
  this.columns = options.columns;
43
43
  } else {
44
- throw new Error("grid columns must be at least 1");
44
+ throw new M2Error("grid columns must be at least 1");
45
45
  }
46
46
  } else {
47
- throw new Error("grid columns must be specified");
47
+ throw new M2Error("grid columns must be specified");
48
48
  }
49
49
  if (options.backgroundColor) {
50
50
  this.gridBackgroundColor = options.backgroundColor;
@@ -138,7 +138,7 @@ class Grid extends Composite {
138
138
  if (this.gridChildren.length > 0) {
139
139
  this.gridChildren.forEach((gridChild) => {
140
140
  if (!this.cellWidth || !this.cellHeight || !this.gridBackground) {
141
- throw new Error(
141
+ throw new M2Error(
142
142
  "cellWidth, cellHeight, or gridBackground undefined or null"
143
143
  );
144
144
  }
@@ -153,7 +153,7 @@ class Grid extends Composite {
153
153
  )
154
154
  );
155
155
  if (!childNode) {
156
- throw new Error("grid: child node not found");
156
+ throw new M2Error("grid: child node not found");
157
157
  }
158
158
  childNode?.parent?.removeChild(childNode);
159
159
  this.cellContainers[gridChild.row][gridChild.column].addChild(
@@ -171,7 +171,7 @@ class Grid extends Composite {
171
171
  }
172
172
  get gridBackground() {
173
173
  if (!this._gridBackground) {
174
- throw new Error("gridBackground is null or undefined");
174
+ throw new M2Error("gridBackground is null or undefined");
175
175
  }
176
176
  return this._gridBackground;
177
177
  }
@@ -853,7 +853,7 @@ class Dialog extends Composite {
853
853
  * provided, name will be the new uuid
854
854
  */
855
855
  duplicate(newName) {
856
- throw new Error(`duplicate not implemented. ${newName}`);
856
+ throw new M2Error(`duplicate not implemented. ${newName}`);
857
857
  }
858
858
  update() {
859
859
  super.update();
@@ -909,7 +909,7 @@ class DrawPad extends Composite {
909
909
  this.isUserInteractionEnabled = true;
910
910
  }
911
911
  if (!options.size) {
912
- throw new Error("DrawPad size must be specified");
912
+ throw new M2Error("DrawPad size must be specified");
913
913
  }
914
914
  this.size = options.size;
915
915
  if (options.lineColor) {
@@ -994,7 +994,7 @@ class DrawPad extends Composite {
994
994
  handleTapDown(e) {
995
995
  if (this.isUserInteractionEnabled) {
996
996
  if (!this.drawShape?.path) {
997
- throw new Error("DrawPad.handleTapDown(): no drawShape.path");
997
+ throw new M2Error("DrawPad.handleTapDown(): no drawShape.path");
998
998
  }
999
999
  const path = this.drawShape.path;
1000
1000
  if (this.continuousDrawingOnly && path.subpaths.length !== 0) {
@@ -1036,7 +1036,9 @@ class DrawPad extends Composite {
1036
1036
  this.size
1037
1037
  );
1038
1038
  if (!this.drawShape?.path) {
1039
- throw new Error("DrawPad.addInterpolatedStrokeMove(): no drawShape.path");
1039
+ throw new M2Error(
1040
+ "DrawPad.addInterpolatedStrokeMove(): no drawShape.path"
1041
+ );
1040
1042
  }
1041
1043
  const path = this.drawShape.path;
1042
1044
  path.addLine(interpolatedPoint);
@@ -1119,7 +1121,7 @@ class DrawPad extends Composite {
1119
1121
  handlePointerMove(e) {
1120
1122
  if (this.isUserInteractionEnabled && this.isDrawingPointerDown) {
1121
1123
  if (!this.drawShape?.path) {
1122
- throw new Error("DrawPad.handlePointerMove(): no drawShape.path");
1124
+ throw new M2Error("DrawPad.handlePointerMove(): no drawShape.path");
1123
1125
  }
1124
1126
  const path = this.drawShape.path;
1125
1127
  if (this.isDrawingPointerDown && !this.pointerIsDownAndPointerLeftDrawAreaWhenDown) {
@@ -1171,7 +1173,7 @@ class DrawPad extends Composite {
1171
1173
  */
1172
1174
  clear() {
1173
1175
  if (!this.drawShape?.path) {
1174
- throw new Error("DrawPad.clear(): no drawShape.path");
1176
+ throw new M2Error("DrawPad.clear(): no drawShape.path");
1175
1177
  }
1176
1178
  const path = this.drawShape.path;
1177
1179
  path.clear();
@@ -1349,7 +1351,7 @@ class DrawPad extends Composite {
1349
1351
  takeScreenshot() {
1350
1352
  const drawArea = this.drawArea;
1351
1353
  if (!drawArea) {
1352
- throw new Error("DrawPad.takeScreenshot(): no drawArea");
1354
+ throw new M2Error("DrawPad.takeScreenshot(): no drawArea");
1353
1355
  }
1354
1356
  const sx = (drawArea.absolutePosition.x - drawArea.size.width / 2) * m2c2Globals.canvasScale;
1355
1357
  const sy = (drawArea.absolutePosition.y - drawArea.size.height / 2) * m2c2Globals.canvasScale;
@@ -1370,11 +1372,11 @@ class DrawPad extends Composite {
1370
1372
  pixelData.length / sh
1371
1373
  );
1372
1374
  if (!croppedImage) {
1373
- throw new Error("DrawPad.takeScreenshot(): no croppedImage");
1375
+ throw new M2Error("DrawPad.takeScreenshot(): no croppedImage");
1374
1376
  }
1375
1377
  const bytes = croppedImage.encodeToBytes();
1376
1378
  if (!bytes) {
1377
- throw new Error(
1379
+ throw new M2Error(
1378
1380
  "DrawPad.takeScreenshot(): croppedImage.encodeToBytes() failed"
1379
1381
  );
1380
1382
  }
@@ -1493,7 +1495,9 @@ class DrawPad extends Composite {
1493
1495
  this.needsInitialization = true;
1494
1496
  }
1495
1497
  duplicate(newName) {
1496
- throw new Error(`DrawPad.duplicate(): Method not implemented. ${newName}`);
1498
+ throw new M2Error(
1499
+ `DrawPad.duplicate(): Method not implemented. ${newName}`
1500
+ );
1497
1501
  }
1498
1502
  }
1499
1503
  M2c2KitHelpers.registerM2NodeClass(DrawPad);
@@ -1741,7 +1745,7 @@ class VirtualKeyboard extends Composite {
1741
1745
  });
1742
1746
  }
1743
1747
  duplicate(newName) {
1744
- throw new Error(`Method not implemented. ${newName}`);
1748
+ throw new M2Error(`Method not implemented. ${newName}`);
1745
1749
  }
1746
1750
  handleKeyShapeTapDown(key, keyShape, tapEvent) {
1747
1751
  if (key.isShift) {
@@ -1899,7 +1903,7 @@ class VirtualKeyboard extends Composite {
1899
1903
  );
1900
1904
  const keyShape = this.keyShapes.find((k) => k.userData.code === event.code);
1901
1905
  if (!keyShape) {
1902
- throw new Error("keyShape is not defined");
1906
+ throw new M2Error("keyShape is not defined");
1903
1907
  }
1904
1908
  this.shiftActivated = event.shiftKey;
1905
1909
  switch (event.compositeEventType) {
@@ -1916,7 +1920,7 @@ class VirtualKeyboard extends Composite {
1916
1920
  break;
1917
1921
  }
1918
1922
  default: {
1919
- throw new Error(
1923
+ throw new M2Error(
1920
1924
  `Unknown VirtualKeyboardEvent: ${event.compositeEventType}`
1921
1925
  );
1922
1926
  }
@@ -1935,13 +1939,13 @@ class VirtualKeyboard extends Composite {
1935
1939
  keyShape.fillColor = this.keyDownColor;
1936
1940
  if (this.showKeyDownPreview) {
1937
1941
  if (!this.letterCircle || !this.letterCircleLabel) {
1938
- throw new Error("letterCircle is not defined");
1942
+ throw new M2Error("letterCircle is not defined");
1939
1943
  }
1940
1944
  this.letterCircle.hidden = false;
1941
1945
  const keyBox = keyShape.parent;
1942
1946
  this.letterCircle.position.x = keyBox.position.x;
1943
1947
  if (keyShape.rect?.size?.height === void 0) {
1944
- throw new Error("keyShape.rect.height is undefined");
1948
+ throw new M2Error("keyShape.rect.height is undefined");
1945
1949
  }
1946
1950
  this.letterCircle.position.y = keyBox.position.y - keyShape.rect.size.height * 1.2;
1947
1951
  const keyboard2 = this.internalKeyboardRowsToInternalKeyboardConfiguration(
@@ -1949,7 +1953,7 @@ class VirtualKeyboard extends Composite {
1949
1953
  );
1950
1954
  const key = keyboard2.flat().find((k) => k.code === event.code);
1951
1955
  if (!key) {
1952
- throw new Error("key is not defined");
1956
+ throw new M2Error("key is not defined");
1953
1957
  }
1954
1958
  if (this.shiftActivated) {
1955
1959
  this.letterCircleLabel.text = key.labelTextShifted ?? key.code;
@@ -1970,7 +1974,7 @@ class VirtualKeyboard extends Composite {
1970
1974
  }
1971
1975
  keyShape.fillColor = this.keyColor;
1972
1976
  if (!this.letterCircle) {
1973
- throw new Error("letterCircle is not defined");
1977
+ throw new M2Error("letterCircle is not defined");
1974
1978
  }
1975
1979
  this.letterCircle.hidden = true;
1976
1980
  if (!event.code.toLowerCase().includes("shift") && event.shiftKey) {
@@ -1991,7 +1995,7 @@ class VirtualKeyboard extends Composite {
1991
1995
  }
1992
1996
  keyShape.fillColor = this.keyColor;
1993
1997
  if (!this.letterCircle) {
1994
- throw new Error("letterCircle is not defined");
1998
+ throw new M2Error("letterCircle is not defined");
1995
1999
  }
1996
2000
  this.letterCircle.hidden = true;
1997
2001
  }
@@ -2011,7 +2015,7 @@ class VirtualKeyboard extends Composite {
2011
2015
  keyboard.flatMap((k) => k).forEach((k) => {
2012
2016
  const keyLabel = this.keyLabels.find((l) => l.userData.code === k.code);
2013
2017
  if (!keyLabel) {
2014
- throw new Error("keyLabel is not defined");
2018
+ throw new M2Error("keyLabel is not defined");
2015
2019
  }
2016
2020
  if (keyLabel.text !== void 0) {
2017
2021
  keyLabel.text = k.labelTextShifted ?? "";
@@ -2034,7 +2038,7 @@ class VirtualKeyboard extends Composite {
2034
2038
  keyboard.flatMap((k) => k).forEach((k) => {
2035
2039
  const keyLabel = this.keyLabels.find((l) => l.userData.code === k.code);
2036
2040
  if (!keyLabel) {
2037
- throw new Error("keyLabel is not defined");
2041
+ throw new M2Error("keyLabel is not defined");
2038
2042
  }
2039
2043
  if (keyLabel.text !== void 0) {
2040
2044
  keyLabel.text = k.labelText ?? "";
@@ -2389,7 +2393,7 @@ class CountdownScene extends Scene {
2389
2393
  constructor(options) {
2390
2394
  super(options);
2391
2395
  if (options?.transitionDurationMilliseconds !== void 0 && options?.transition) {
2392
- throw new Error(
2396
+ throw new M2Error(
2393
2397
  "Both transition and transitionDurationMilliseconds options were provided. Only one should be provided. If using a custom transition, then the duration of that transition must be specified within the custom transition."
2394
2398
  );
2395
2399
  }
@@ -2429,7 +2433,7 @@ class CountdownScene extends Scene {
2429
2433
  });
2430
2434
  this.addChild(timerShape);
2431
2435
  } else {
2432
- throw new Error("Invalid timer shape options.");
2436
+ throw new M2Error("Invalid timer shape options.");
2433
2437
  }
2434
2438
  const timerInitialNumber = Math.floor(options.milliseconds / 1e3);
2435
2439
  const timerNumberLabel = new Label({
@@ -2628,7 +2632,7 @@ class LocalePicker extends Composite {
2628
2632
  });
2629
2633
  }
2630
2634
  if (this.localeOptions.length === 0) {
2631
- throw new Error("No locales available for LocalePicker");
2635
+ throw new M2Error("No locales available for LocalePicker");
2632
2636
  }
2633
2637
  this.children.filter((child) => child.name !== "localePickerIcon").forEach((child) => this.removeChild(child));
2634
2638
  this.game.imageManager.loadImages([
@@ -3037,7 +3041,7 @@ class LocalePicker extends Composite {
3037
3041
  * provided, name will be the new uuid
3038
3042
  */
3039
3043
  duplicate(newName) {
3040
- throw new Error(`duplicate not implemented. ${newName}`);
3044
+ throw new M2Error(`duplicate not implemented. ${newName}`);
3041
3045
  }
3042
3046
  }
3043
3047
 
@@ -3123,11 +3127,11 @@ class CountdownTimer extends Composite {
3123
3127
  });
3124
3128
  this.addChild(this.timerShapeNode);
3125
3129
  } else {
3126
- throw new Error("Invalid timer shape options.");
3130
+ throw new M2Error("Invalid timer shape options.");
3127
3131
  }
3128
3132
  this.size = this.timerShapeNode.size;
3129
3133
  if (this.milliseconds % 1e3 !== 0) {
3130
- throw new Error(
3134
+ throw new M2Error(
3131
3135
  "CountdownTimer milliseconds must be a multiple of 1000."
3132
3136
  );
3133
3137
  }
@@ -3220,10 +3224,10 @@ class CountdownTimer extends Composite {
3220
3224
  */
3221
3225
  start() {
3222
3226
  if (this.isRunning) {
3223
- throw new Error("CountdownTimer: cannot start. It is already running.");
3227
+ throw new M2Error("CountdownTimer: cannot start. It is already running.");
3224
3228
  }
3225
3229
  if (this.hasStopped) {
3226
- throw new Error(
3230
+ throw new M2Error(
3227
3231
  "CountdownTimer: It has stopped. You cannot start a stopped CountdownTimer. Instead, create a new CountdownTimer or call CountdownTimer.reset() before starting."
3228
3232
  );
3229
3233
  }
@@ -3269,7 +3273,7 @@ class CountdownTimer extends Composite {
3269
3273
  }
3270
3274
  handleCompositeEvent(event) {
3271
3275
  if (!this.timerNumberLabel) {
3272
- throw new Error("Timer number label not found.");
3276
+ throw new M2Error("Timer number label not found.");
3273
3277
  }
3274
3278
  switch (event.compositeEventType) {
3275
3279
  case "CountdownTimerTick": {
@@ -3283,7 +3287,7 @@ class CountdownTimer extends Composite {
3283
3287
  break;
3284
3288
  }
3285
3289
  default:
3286
- throw new Error(
3290
+ throw new M2Error(
3287
3291
  `Invalid TimerCountdown event type: ${event.compositeEventType}`
3288
3292
  );
3289
3293
  }
@@ -3434,7 +3438,7 @@ class CountdownTimer extends Composite {
3434
3438
  * provided, name will be the new uuid
3435
3439
  */
3436
3440
  duplicate(newName) {
3437
- throw new Error(`Method not implemented. ${newName}`);
3441
+ throw new M2Error(`Method not implemented. ${newName}`);
3438
3442
  }
3439
3443
  update() {
3440
3444
  super.update();
@@ -3497,7 +3501,7 @@ class Slider extends Composite {
3497
3501
  }
3498
3502
  get thumbShape() {
3499
3503
  if (this._thumbShape === void 0) {
3500
- throw new Error("thumbShape is not defined.");
3504
+ throw new M2Error("thumbShape is not defined.");
3501
3505
  }
3502
3506
  return this._thumbShape;
3503
3507
  }
@@ -3729,7 +3733,7 @@ class Slider extends Composite {
3729
3733
  * provided, name will be the new uuid
3730
3734
  */
3731
3735
  duplicate(newName) {
3732
- throw new Error(`Method not implemented. ${newName}`);
3736
+ throw new M2Error(`Method not implemented. ${newName}`);
3733
3737
  }
3734
3738
  update() {
3735
3739
  super.update();
@@ -3745,7 +3749,7 @@ class Slider extends Composite {
3745
3749
  }
3746
3750
  }
3747
3751
 
3748
- console.log("\u26AA @m2c2kit/addons version 0.3.27 (622f7241)");
3752
+ console.log("\u26AA @m2c2kit/addons version 0.3.29 (9f27c146)");
3749
3753
 
3750
3754
  export { Button, CountdownScene, CountdownTimer, Dialog, DialogResult, DrawPad, DrawPadEventType, DrawPadItemEventType, Grid, Instructions, LocalePicker, Slider, VirtualKeyboard };
3751
3755
  //# sourceMappingURL=index.js.map