@m2c2kit/core 0.3.26 → 0.3.28

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
@@ -403,6 +403,32 @@ interface SceneOptions extends M2NodeOptions, DrawableOptions {
403
403
  backgroundColor?: RgbaColor;
404
404
  }
405
405
 
406
+ /**
407
+ * Describes an event on the device's built-in keyboard.
408
+ *
409
+ * @remarks The built-in keyboard is defined as the hardware keyboard on a
410
+ * desktop/laptop or the built-in soft keyboard on a tablet or phone. The
411
+ * latter is not used in m2c2kit. On tablet or phone, the `VirtualKeyboard`
412
+ * in the `@m2c2kit/addons` package should be used for key events.
413
+ * @remarks Key events can occur only on a `Scene` node.
414
+ */
415
+ interface M2KeyboardEvent extends M2NodeEvent {
416
+ /** String that is generated when key is pressed, with any modifiers (e.g., Shift) applied. */
417
+ key: string;
418
+ /** Code for the key, not taking into account any modifiers. */
419
+ code: string;
420
+ /** True if the Shift key is pressed. */
421
+ shiftKey: boolean;
422
+ /** True if the Control key is pressed. */
423
+ ctrlKey: boolean;
424
+ /** True if the Alt key is pressed. */
425
+ altKey: boolean;
426
+ /** True if the Meta key is pressed. */
427
+ metaKey: boolean;
428
+ /** True if the event is being repeated. */
429
+ repeat: boolean;
430
+ }
431
+
406
432
  declare class Scene extends M2Node implements IDrawable, SceneOptions {
407
433
  readonly type = M2NodeType.Scene;
408
434
  isDrawable: boolean;
@@ -485,6 +511,34 @@ declare class Scene extends M2Node implements IDrawable, SceneOptions {
485
511
  * @param options - {@link CallbackOptions}
486
512
  */
487
513
  onAppear(callback: (nodeEvent: M2NodeEvent) => void, options?: CallbackOptions): void;
514
+ /**
515
+ * Code that will be called after a key is pressed on the device's
516
+ * built-in keyboard.
517
+ *
518
+ * @remarks The built-in keyboard is defined as the hardware keyboard on a
519
+ * desktop/laptop or the built-in soft keyboard on a tablet or phone. The
520
+ * latter is not used in m2c2kit. On tablet or phone, the `VirtualKeyboard`
521
+ * in the `@m2c2kit/addons` package should be used for key events.
522
+ * @remarks Key events can occur only on a `Scene` node.
523
+ *
524
+ * @param callback - function to execute
525
+ * @param options - {@link CallbackOptions}
526
+ */
527
+ onKeyDown(callback: (m2KeyboardEvent: M2KeyboardEvent) => void, options?: CallbackOptions): void;
528
+ /**
529
+ * Code that will be called after a key is released on the device's
530
+ * built-in keyboard.
531
+ *
532
+ * @remarks The built-in keyboard is defined as the hardware keyboard on a
533
+ * desktop/laptop or the built-in soft keyboard on a tablet or phone. The
534
+ * latter is not used in m2c2kit. On tablet or phone, the `VirtualKeyboard`
535
+ * in the `@m2c2kit/addons` package should be used for key events.
536
+ * @remarks Key events can occur only on a `Scene` node.
537
+ *
538
+ * @param callback - function to execute
539
+ * @param options - {@link CallbackOptions}
540
+ */
541
+ onKeyUp(callback: (m2KeyboardEvent: M2KeyboardEvent) => void, options?: CallbackOptions): void;
488
542
  update(): void;
489
543
  draw(canvas: Canvas): void;
490
544
  warmup(canvas: Canvas): void;
@@ -2111,6 +2165,8 @@ declare class Game implements Activity {
2111
2165
  private htmlCanvasPointerUpHandler;
2112
2166
  private htmlCanvasPointerMoveHandler;
2113
2167
  private htmlCanvasPointerLeaveHandler;
2168
+ private documentKeyDownHandler;
2169
+ private documentKeyUpHandler;
2114
2170
  /**
2115
2171
  * Determines if/how m2c2kit nodes respond to the DOM PointerDown event
2116
2172
  *
@@ -2428,6 +2484,8 @@ declare const M2EventType: {
2428
2484
  readonly PointerUp: "PointerUp";
2429
2485
  readonly PointerMove: "PointerMove";
2430
2486
  readonly PointerLeave: "PointerLeave";
2487
+ readonly KeyDown: "KeyDown";
2488
+ readonly KeyUp: "KeyUp";
2431
2489
  readonly Drag: "Drag";
2432
2490
  readonly DragStart: "DragStart";
2433
2491
  readonly DragEnd: "DragEnd";
@@ -3676,8 +3734,8 @@ declare class Constants {
3676
3734
  /** Placeholder that will be populated during the build process. */
3677
3735
  static readonly MODULE_METADATA_PLACEHOLDER: ModuleMetadata;
3678
3736
  static readonly DEFAULT_ROOT_ELEMENT_ID = "m2c2kit";
3679
- static readonly ERUDA_URL = "https://cdn.jsdelivr.net/npm/eruda@3.2.3/eruda.js";
3680
- static readonly ERUDA_SRI = "sha384-KlRzgy/c+nZSV+eiFqoTkkbZ5pUqToho7HsNuebTbOsYTh4m0m/PAqkGsTMLXK14";
3737
+ static readonly ERUDA_URL = "https://cdn.jsdelivr.net/npm/eruda@3.4.1/eruda.js";
3738
+ static readonly ERUDA_SRI = "sha384-daS5bEfWdSq146t9c4BureB/fQWO3lHohseXBelPqKvbOUx2D6PE3TxcQ9jrKZDM";
3681
3739
  }
3682
3740
 
3683
3741
  /**
@@ -4739,10 +4797,49 @@ declare class SoundRecorder extends M2Node implements Omit<SoundRecorderOptions,
4739
4797
  */
4740
4798
  constructor(options?: SoundRecorderOptions);
4741
4799
  initialize(): void;
4800
+ /**
4801
+ * Starts recording audio from the microphone.
4802
+ *
4803
+ * @remarks If the `SoundRecorder` is already recording, an error will be
4804
+ * thrown. If permission to use the microphone has not been granted, the
4805
+ * browser will prompt the user to allow or deny access. Denial of access
4806
+ * will result in an error being thrown. To avoid this, use the
4807
+ * `queryPermission()` and `requestPermission()` methods to check and request
4808
+ * permission, respectively, and handle the results accordingly.
4809
+ */
4742
4810
  start(): Promise<void>;
4811
+ /**
4812
+ * Stops recording audio from the microphone.
4813
+ *
4814
+ * @remarks If the `stop()` method is not awaited, the method returns a
4815
+ * Promise and the useable data will be lost.
4816
+ *
4817
+ * @returns A promise that resolves to a {@link SoundRecorderResults} object.
4818
+ * The `audioBase64` property of the object contains the recorded audio as a
4819
+ * base64 string.
4820
+ */
4743
4821
  stop(): Promise<SoundRecorderResults>;
4744
4822
  pause(): void;
4745
4823
  resume(): void;
4824
+ /**
4825
+ * Checks if the microphone permission is granted.
4826
+ *
4827
+ * @remarks This does not request permission from the user. It only queries
4828
+ * the current microphone permission state.
4829
+ *
4830
+ * @returns The `state` property ("granted", "denied", or "prompt") of
4831
+ * `PermissionStatus` or undefined if the browser does not support the
4832
+ * "microphone" permission.
4833
+ * See https://developer.mozilla.org/en-US/docs/Web/API/PermissionStatus/state
4834
+ */
4835
+ queryPermission(): Promise<string | undefined>;
4836
+ /**
4837
+ * Requests permission to use the microphone, and possibly prompts the user
4838
+ * to allow or deny access.
4839
+ *
4840
+ * @returns true if the microphone permission is granted, false if denied.
4841
+ */
4842
+ requestPermission(): Promise<boolean>;
4746
4843
  /** Is the `SoundRecorder` currently recording? */
4747
4844
  get isRecording(): boolean;
4748
4845
  /** Is the `SoundRecorder` currently paused? */
@@ -5244,4 +5341,4 @@ declare class WebGlInfo {
5244
5341
  static dispose(): void;
5245
5342
  }
5246
5343
 
5247
- export { Action, type Activity, type ActivityCallbacks, type ActivityEvent, type ActivityEventListener, type ActivityKeyValueData, type ActivityLifecycleEvent, type ActivityResultsEvent, ActivityType, type BrowserImage, type BrowserImageDataReadyEvent, type CallbackOptions, CanvasKitHelpers, ColorfulMutablePath, Composite, type CompositeEvent, type CompositeOptions, Constants, ConstraintType, type Constraints, CustomAction, type CustomActionOptions, type DefaultParameter, Dimensions, type DomPointerDownEvent, type DrawableOptions, type EasingFunction, Easings, Equal, Equals, EventStore, EventStoreMode, FadeAlphaAction, type FadeAlphaActionOptions, type FontAsset, type FontData, FontManager, Game, type GameData, type GameEvent, type GameOptions, type GameParameters, type GlobalVariables, GroupAction, I18n, type I18nDataReadyEvent, type IDataStore, type IDrawable, type IText, ImageManager, Label, LabelHorizontalAlignmentMode, type LabelOptions, type Layout, LayoutConstraint, LegacyTimer, type LocaleSvg, type M2ColorfulPath, type M2DragEvent, type M2Event, type M2EventListener, M2EventType, type M2Image, M2ImageStatus, M2Node, type M2NodeAddChildEvent, type M2NodeConstructor, type M2NodeEvent, type M2NodeEventListener, M2NodeFactory, type M2NodeNewEvent, type M2NodeOptions, type M2NodePropertyChangeEvent, type M2NodeRemoveChildEvent, M2NodeType, type M2Path, type M2PointerEvent, type M2Sound, M2SoundStatus, M2c2KitHelpers, MoveAction, type MoveActionOptions, MutablePath, NoneTransition, PlayAction, type PlayActionOptions, type Plugin, type PluginEvent, type Point, RandomDraws, type RectOptions, RepeatAction, RepeatForeverAction, type RgbaColor, RotateAction, ScaleAction, type ScaleActionOptions, Scene, type SceneOptions, type ScenePresentEvent, SceneTransition, type ScoringSchema, SequenceAction, Shape, type ShapeOptions, ShapeType, type Size, SlideTransition, type SlideTransitionOptions, type SoundAsset, SoundManager, SoundPlayer, type SoundPlayerOptions, SoundRecorder, type SoundRecorderOptions, type SoundRecorderResults, Sprite, type SpriteOptions, Story, type StoryOptions, type StringInterpolationMap, type TapEvent, type TextAndFont, TextLine, type TextLineOptions, type TextLocalizationResult, type TextOptions, type TextWithFontCustomization, Timer, Transition, TransitionDirection, TransitionType, type Translation, type TranslationConfiguration, type TranslationOptions, type TrialData, type TrialSchema, Uuid, WaitAction, type WaitActionOptions, WebColors, WebGlInfo, handleInterfaceOptions };
5344
+ export { Action, type Activity, type ActivityCallbacks, type ActivityEvent, type ActivityEventListener, type ActivityKeyValueData, type ActivityLifecycleEvent, type ActivityResultsEvent, ActivityType, type BrowserImage, type BrowserImageDataReadyEvent, type CallbackOptions, CanvasKitHelpers, ColorfulMutablePath, Composite, type CompositeEvent, type CompositeOptions, Constants, ConstraintType, type Constraints, CustomAction, type CustomActionOptions, type DefaultParameter, Dimensions, type DomPointerDownEvent, type DrawableOptions, type EasingFunction, Easings, Equal, Equals, EventStore, EventStoreMode, FadeAlphaAction, type FadeAlphaActionOptions, type FontAsset, type FontData, FontManager, Game, type GameData, type GameEvent, type GameOptions, type GameParameters, type GlobalVariables, GroupAction, I18n, type I18nDataReadyEvent, type IDataStore, type IDrawable, type IText, ImageManager, Label, LabelHorizontalAlignmentMode, type LabelOptions, type Layout, LayoutConstraint, LegacyTimer, type LocaleSvg, type M2ColorfulPath, type M2DragEvent, type M2Event, type M2EventListener, M2EventType, type M2Image, M2ImageStatus, type M2KeyboardEvent, M2Node, type M2NodeAddChildEvent, type M2NodeConstructor, type M2NodeEvent, type M2NodeEventListener, M2NodeFactory, type M2NodeNewEvent, type M2NodeOptions, type M2NodePropertyChangeEvent, type M2NodeRemoveChildEvent, M2NodeType, type M2Path, type M2PointerEvent, type M2Sound, M2SoundStatus, M2c2KitHelpers, MoveAction, type MoveActionOptions, MutablePath, NoneTransition, PlayAction, type PlayActionOptions, type Plugin, type PluginEvent, type Point, RandomDraws, type RectOptions, RepeatAction, RepeatForeverAction, type RgbaColor, RotateAction, ScaleAction, type ScaleActionOptions, Scene, type SceneOptions, type ScenePresentEvent, SceneTransition, type ScoringSchema, SequenceAction, Shape, type ShapeOptions, ShapeType, type Size, SlideTransition, type SlideTransitionOptions, type SoundAsset, SoundManager, SoundPlayer, type SoundPlayerOptions, SoundRecorder, type SoundRecorderOptions, type SoundRecorderResults, Sprite, type SpriteOptions, Story, type StoryOptions, type StringInterpolationMap, type TapEvent, type TextAndFont, TextLine, type TextLineOptions, type TextLocalizationResult, type TextOptions, type TextWithFontCustomization, Timer, Transition, TransitionDirection, TransitionType, type Translation, type TranslationConfiguration, type TranslationOptions, type TrialData, type TrialSchema, Uuid, WaitAction, type WaitActionOptions, WebColors, WebGlInfo, handleInterfaceOptions };