@m2c2kit/core 0.3.20 → 0.3.21

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
@@ -3666,7 +3666,8 @@ declare class Constants {
3666
3666
  /** Placeholder that will be populated during the build process. */
3667
3667
  static readonly MODULE_METADATA_PLACEHOLDER: ModuleMetadata;
3668
3668
  static readonly DEFAULT_ROOT_ELEMENT_ID = "m2c2kit";
3669
- static readonly ERUDA_URL = "https://cdn.jsdelivr.net/npm/eruda@3.2.1/eruda.js";
3669
+ static readonly ERUDA_URL = "https://cdn.jsdelivr.net/npm/eruda@3.2.3/eruda.js";
3670
+ static readonly ERUDA_SRI = "sha384-KlRzgy/c+nZSV+eiFqoTkkbZ5pUqToho7HsNuebTbOsYTh4m0m/PAqkGsTMLXK14";
3670
3671
  }
3671
3672
 
3672
3673
  /**
@@ -3842,6 +3843,25 @@ declare class M2c2KitHelpers {
3842
3843
  * "https://", "file://", etc.)
3843
3844
  */
3844
3845
  static urlHasScheme(url: string): boolean;
3846
+ /**
3847
+ * Converts a value to a JSON schema type or one of types.
3848
+ *
3849
+ * @remarks The value can be of the target type, or a string that can be
3850
+ * parsed into the target type. For example, a string `"3"` can be converted
3851
+ * to a number, and a string `'{ "color" : "red" }'` can be converted to an
3852
+ * object. If the target type if an object or array, the value can be a
3853
+ * string parsable into the target type: this string can be the string
3854
+ * representation of the object or array, or the URI encoded string.
3855
+ * Throws an error if the value cannot be converted to the type or one of the
3856
+ * types. Converting an object, null, or array to a string is often not the
3857
+ * desired behavior, so a warning is logged if this occurs.
3858
+ *
3859
+ * @param value - the value to convert
3860
+ * @param type - A JSON Schema type or types to convert the value to, e.g.,
3861
+ * "string" or ["string", "null"]
3862
+ * @returns the converted value
3863
+ */
3864
+ static convertValueToType(value: string | number | boolean | Array<unknown> | object | null, type: JsonSchemaDataType | JsonSchemaDataType[] | undefined): unknown;
3845
3865
  /**
3846
3866
  * Load scripts from URLs.
3847
3867
  *
package/dist/index.js CHANGED
@@ -681,7 +681,8 @@ Constants.MODULE_METADATA_PLACEHOLDER = {
681
681
  dependencies: {}
682
682
  };
683
683
  Constants.DEFAULT_ROOT_ELEMENT_ID = "m2c2kit";
684
- Constants.ERUDA_URL = "https://cdn.jsdelivr.net/npm/eruda@3.2.1/eruda.js";
684
+ Constants.ERUDA_URL = "https://cdn.jsdelivr.net/npm/eruda@3.2.3/eruda.js";
685
+ Constants.ERUDA_SRI = "sha384-KlRzgy/c+nZSV+eiFqoTkkbZ5pUqToho7HsNuebTbOsYTh4m0m/PAqkGsTMLXK14";
685
686
 
686
687
  class M2c2KitHelpers {
687
688
  /**
@@ -710,6 +711,254 @@ class M2c2KitHelpers {
710
711
  static urlHasScheme(url) {
711
712
  return /^[a-z]+:\/\//i.test(url);
712
713
  }
714
+ /**
715
+ * Converts a value to a JSON schema type or one of types.
716
+ *
717
+ * @remarks The value can be of the target type, or a string that can be
718
+ * parsed into the target type. For example, a string `"3"` can be converted
719
+ * to a number, and a string `'{ "color" : "red" }'` can be converted to an
720
+ * object. If the target type if an object or array, the value can be a
721
+ * string parsable into the target type: this string can be the string
722
+ * representation of the object or array, or the URI encoded string.
723
+ * Throws an error if the value cannot be converted to the type or one of the
724
+ * types. Converting an object, null, or array to a string is often not the
725
+ * desired behavior, so a warning is logged if this occurs.
726
+ *
727
+ * @param value - the value to convert
728
+ * @param type - A JSON Schema type or types to convert the value to, e.g.,
729
+ * "string" or ["string", "null"]
730
+ * @returns the converted value
731
+ */
732
+ static convertValueToType(value, type) {
733
+ function canBeString(value2) {
734
+ if (typeof value2 === "string") {
735
+ return true;
736
+ }
737
+ if (typeof value2 === "object") {
738
+ return true;
739
+ }
740
+ if (!Number.isNaN(parseFloat(value2))) {
741
+ return true;
742
+ }
743
+ if (typeof value2 === "boolean") {
744
+ return true;
745
+ }
746
+ return false;
747
+ }
748
+ function asString(value2) {
749
+ if (typeof value2 === "string") {
750
+ return value2;
751
+ }
752
+ if (typeof value2 === "object") {
753
+ console.warn(
754
+ `convertValueToType() converted an object to a string. This may not be the desired behavior. The object was: ${JSON.stringify(value2)}`
755
+ );
756
+ return JSON.stringify(value2);
757
+ }
758
+ if (!Number.isNaN(parseFloat(value2))) {
759
+ return value2;
760
+ }
761
+ if (typeof value2 === "boolean") {
762
+ return value2.toString();
763
+ }
764
+ throw new Error(`Error parsing "${value2}" as a string.`);
765
+ }
766
+ function canBeNumber(value2) {
767
+ if (typeof value2 === "number") {
768
+ return true;
769
+ }
770
+ if (typeof value2 !== "string") {
771
+ return false;
772
+ }
773
+ const n = parseFloat(value2);
774
+ if (Number.isNaN(n)) {
775
+ return false;
776
+ }
777
+ return true;
778
+ }
779
+ function asNumber(value2) {
780
+ if (typeof value2 === "number") {
781
+ return value2;
782
+ }
783
+ if (typeof value2 !== "string") {
784
+ throw new Error(`Error parsing "${value2}" as a number.`);
785
+ }
786
+ const n = parseFloat(value2);
787
+ if (Number.isNaN(n)) {
788
+ throw new Error(`Error parsing "${value2}" as a number.`);
789
+ }
790
+ return n;
791
+ }
792
+ function canBeInteger(value2) {
793
+ if (typeof value2 === "number") {
794
+ return true;
795
+ }
796
+ if (typeof value2 !== "string") {
797
+ return false;
798
+ }
799
+ const n = parseInt(value2);
800
+ if (Number.isNaN(n)) {
801
+ return false;
802
+ }
803
+ return true;
804
+ }
805
+ function asInteger(value2) {
806
+ if (typeof value2 === "number") {
807
+ return value2;
808
+ }
809
+ if (typeof value2 !== "string") {
810
+ throw new Error(`Error parsing "${value2}" as an integer.`);
811
+ }
812
+ const n = parseInt(value2);
813
+ if (Number.isNaN(n)) {
814
+ throw new Error(`Error parsing "${value2}" as an integer.`);
815
+ }
816
+ return n;
817
+ }
818
+ function canBeBoolean(value2) {
819
+ if (typeof value2 === "boolean") {
820
+ return true;
821
+ }
822
+ if (value2 !== "true" && value2 !== "false") {
823
+ return false;
824
+ }
825
+ return true;
826
+ }
827
+ function asBoolean(value2) {
828
+ if (typeof value2 === "boolean") {
829
+ return value2;
830
+ }
831
+ if (value2 !== "true" && value2 !== "false") {
832
+ throw new Error(`Error parsing "${value2}" as a boolean.`);
833
+ }
834
+ return value2 === "true";
835
+ }
836
+ function canBeArray(value2) {
837
+ if (Array.isArray(value2)) {
838
+ return true;
839
+ }
840
+ if (typeof value2 !== "string") {
841
+ return false;
842
+ }
843
+ try {
844
+ const a = JSON.parse(value2);
845
+ if (Array.isArray(a)) {
846
+ return true;
847
+ }
848
+ } catch {
849
+ const a = JSON.parse(decodeURIComponent(value2));
850
+ if (Array.isArray(a)) {
851
+ return true;
852
+ }
853
+ }
854
+ return false;
855
+ }
856
+ function asArray(value2) {
857
+ if (Array.isArray(value2)) {
858
+ return value2;
859
+ }
860
+ if (typeof value2 !== "string") {
861
+ throw new Error(`Error parsing "${value2}" as an array.`);
862
+ }
863
+ try {
864
+ const a = JSON.parse(value2);
865
+ if (Array.isArray(a)) {
866
+ return a;
867
+ }
868
+ } catch {
869
+ const a = JSON.parse(decodeURIComponent(value2));
870
+ if (Array.isArray(a)) {
871
+ return a;
872
+ }
873
+ }
874
+ throw new Error(`Error parsing "${value2}" as an array.`);
875
+ }
876
+ function canBeObject(value2) {
877
+ if (typeof value2 === "object" && !Array.isArray(value2) && value2 !== null) {
878
+ return true;
879
+ }
880
+ if (typeof value2 !== "string") {
881
+ return false;
882
+ }
883
+ try {
884
+ const o = JSON.parse(value2);
885
+ if (typeof o === "object" && !Array.isArray(o) && o !== null) {
886
+ return true;
887
+ }
888
+ } catch {
889
+ const o = JSON.parse(decodeURIComponent(value2));
890
+ if (typeof o === "object" && !Array.isArray(o) && o !== null) {
891
+ return true;
892
+ }
893
+ }
894
+ return false;
895
+ }
896
+ function asObject(value2) {
897
+ if (typeof value2 === "object" && !Array.isArray(value2) && value2 !== null) {
898
+ return value2;
899
+ }
900
+ if (typeof value2 !== "string") {
901
+ throw new Error(`Error parsing "${value2}" as an object.`);
902
+ }
903
+ try {
904
+ const o = JSON.parse(value2);
905
+ if (typeof o === "object" && !Array.isArray(o) && o !== null) {
906
+ return o;
907
+ }
908
+ } catch {
909
+ const o = JSON.parse(decodeURIComponent(value2));
910
+ if (typeof o === "object" && !Array.isArray(o) && o !== null) {
911
+ return o;
912
+ }
913
+ }
914
+ throw new Error(`Error parsing "${value2}" as an object.`);
915
+ }
916
+ function canBeNull(value2) {
917
+ if (value2 === null || value2 === "null") {
918
+ return true;
919
+ }
920
+ return false;
921
+ }
922
+ function asNull(value2) {
923
+ if (value2 !== "null" && value2 !== null) {
924
+ throw new Error(`Error parsing "${value2}" as null.`);
925
+ }
926
+ return null;
927
+ }
928
+ const typeCheckers = {
929
+ string: canBeString,
930
+ number: canBeNumber,
931
+ integer: canBeInteger,
932
+ boolean: canBeBoolean,
933
+ array: canBeArray,
934
+ object: canBeObject,
935
+ null: canBeNull
936
+ };
937
+ const typeConverters = {
938
+ string: asString,
939
+ number: asNumber,
940
+ integer: asInteger,
941
+ boolean: asBoolean,
942
+ array: asArray,
943
+ object: asObject,
944
+ null: asNull
945
+ };
946
+ if (type === void 0) {
947
+ throw new Error(`Error with "${value}" as a target type.`);
948
+ }
949
+ if (!Array.isArray(type)) {
950
+ if (typeCheckers[type](value)) {
951
+ return typeConverters[type](value);
952
+ }
953
+ throw new Error(`Error parsing "${value}" as a ${type}.`);
954
+ }
955
+ for (const t of type) {
956
+ if (typeCheckers[t](value)) {
957
+ return typeConverters[t](value);
958
+ }
959
+ }
960
+ throw new Error(`Error parsing "${value}" as one of ${type}.`);
961
+ }
713
962
  /**
714
963
  * Load scripts from URLs.
715
964
  *
@@ -756,6 +1005,8 @@ class M2c2KitHelpers {
756
1005
  console.log(`\u26AA added eruda script: ${Constants.ERUDA_URL}`);
757
1006
  const script = document.createElement("script");
758
1007
  script.src = Constants.ERUDA_URL;
1008
+ script.integrity = Constants.ERUDA_SRI;
1009
+ script.crossOrigin = "anonymous";
759
1010
  script.async = true;
760
1011
  document.head.appendChild(script);
761
1012
  m2c2Globals.erudaRequested = true;
@@ -8808,7 +9059,23 @@ class Game {
8808
9059
  additionalParameters[key]} will be ignored`
8809
9060
  );
8810
9061
  } else if (this.options.parameters && this.options.parameters[key]) {
8811
- this.options.parameters[key].default = additionalParameters[key];
9062
+ const providedValue = additionalParameters[key];
9063
+ let value;
9064
+ if (this.options.parameters[key].type !== void 0 && providedValue !== void 0) {
9065
+ try {
9066
+ value = M2c2KitHelpers.convertValueToType(
9067
+ providedValue,
9068
+ this.options.parameters[key].type
9069
+ );
9070
+ } catch (e) {
9071
+ throw new Error(
9072
+ "Error setting parameter " + key + ": " + e.message
9073
+ );
9074
+ }
9075
+ } else {
9076
+ value = providedValue;
9077
+ }
9078
+ this.options.parameters[key].default = value;
8812
9079
  }
8813
9080
  if (this.additionalParameters === void 0) {
8814
9081
  this.additionalParameters = {};
@@ -10618,8 +10885,8 @@ class Game {
10618
10885
  handled: false,
10619
10886
  ...M2c2KitHelpers.createTimestamps()
10620
10887
  };
10621
- this.processDomPointerDown(scene, nodeEvent, domPointerEvent);
10622
10888
  this.processDomPointerDown(this.freeNodesScene, nodeEvent, domPointerEvent);
10889
+ this.processDomPointerDown(scene, nodeEvent, domPointerEvent);
10623
10890
  }
10624
10891
  htmlCanvasPointerUpHandler(domPointerEvent) {
10625
10892
  domPointerEvent.preventDefault();
@@ -10633,8 +10900,8 @@ class Game {
10633
10900
  handled: false,
10634
10901
  ...M2c2KitHelpers.createTimestamps()
10635
10902
  };
10636
- this.processDomPointerUp(scene, nodeEvent, domPointerEvent);
10637
10903
  this.processDomPointerUp(this.freeNodesScene, nodeEvent, domPointerEvent);
10904
+ this.processDomPointerUp(scene, nodeEvent, domPointerEvent);
10638
10905
  }
10639
10906
  htmlCanvasPointerMoveHandler(domPointerEvent) {
10640
10907
  domPointerEvent.preventDefault();
@@ -10648,8 +10915,8 @@ class Game {
10648
10915
  handled: false,
10649
10916
  ...M2c2KitHelpers.createTimestamps()
10650
10917
  };
10651
- this.processDomPointerMove(scene, nodeEvent, domPointerEvent);
10652
10918
  this.processDomPointerMove(this.freeNodesScene, nodeEvent, domPointerEvent);
10919
+ this.processDomPointerMove(scene, nodeEvent, domPointerEvent);
10653
10920
  }
10654
10921
  htmlCanvasPointerLeaveHandler(domPointerEvent) {
10655
10922
  if (!this.currentScene) {
@@ -10666,12 +10933,12 @@ class Game {
10666
10933
  handled: false,
10667
10934
  ...M2c2KitHelpers.createTimestamps()
10668
10935
  };
10669
- this.processDomPointerLeave(scene, nodeEvent, domPointerEvent);
10670
10936
  this.processDomPointerLeave(
10671
10937
  this.freeNodesScene,
10672
10938
  nodeEvent,
10673
10939
  domPointerEvent
10674
10940
  );
10941
+ this.processDomPointerLeave(scene, nodeEvent, domPointerEvent);
10675
10942
  }
10676
10943
  /**
10677
10944
  * Determines if/how m2c2kit nodes respond to the DOM PointerDown event
@@ -11763,7 +12030,7 @@ class Story {
11763
12030
  }
11764
12031
  }
11765
12032
 
11766
- console.log("\u26AA @m2c2kit/core version 0.3.20 (33cadc6d)");
12033
+ console.log("\u26AA @m2c2kit/core version 0.3.21 (05ed0dd2)");
11767
12034
 
11768
12035
  export { Action, ActivityType, CanvasKitHelpers, ColorfulMutablePath, Composite, Constants, ConstraintType, CustomAction, Dimensions, Easings, Equal, Equals, EventStore, EventStoreMode, FadeAlphaAction, FontManager, Game, GroupAction, I18n, ImageManager, Label, LabelHorizontalAlignmentMode, LayoutConstraint, LegacyTimer, M2EventType, M2ImageStatus, M2Node, M2NodeFactory, M2NodeType, M2SoundStatus, M2c2KitHelpers, MoveAction, MutablePath, NoneTransition, PlayAction, RandomDraws, RepeatAction, RepeatForeverAction, RotateAction, ScaleAction, Scene, SceneTransition, SequenceAction, Shape, ShapeType, SlideTransition, SoundManager, SoundPlayer, SoundRecorder, Sprite, Story, TextLine, Timer, Transition, TransitionDirection, TransitionType, Uuid, WaitAction, WebColors, WebGlInfo, handleInterfaceOptions };
11769
12036
  //# sourceMappingURL=index.js.map