@m2c2kit/core 0.3.33 → 0.3.35

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
@@ -4509,9 +4509,6 @@ interface FontData {
4509
4509
  isDefault: boolean;
4510
4510
  }
4511
4511
 
4512
- declare global {
4513
- var m2c2Globals: GlobalVariables;
4514
- }
4515
4512
  interface GlobalVariables {
4516
4513
  now: number;
4517
4514
  iso8601Now: string;
@@ -4867,6 +4864,12 @@ interface PluginEvent extends M2Event<Plugin> {
4867
4864
  }
4868
4865
 
4869
4866
  declare class RandomDraws {
4867
+ /** Number of milliseconds before a warning is logged if sampling takes too long. Tuneable for tests. */
4868
+ static samplingWarnMs: number;
4869
+ /** Number of milliseconds before sampling times out. Tuneable for tests or legitimate edge use cases. */
4870
+ static samplingTimeoutMs: number;
4871
+ /** Number of loop iterations between checks. Tuneable for tests. */
4872
+ static samplingCheckInterval: number;
4870
4873
  private static randomFunction;
4871
4874
  private static seededPRNG;
4872
4875
  /**
package/dist/index.js CHANGED
@@ -6426,6 +6426,10 @@ class Shape extends M2Node {
6426
6426
  this.savePropertyChangeEvent("zPosition", zPosition);
6427
6427
  }
6428
6428
  dispose() {
6429
+ const colorfulPathPaintsToDispose = [];
6430
+ for (const p of this.colorfulPathPaints.values()) {
6431
+ colorfulPathPaintsToDispose.push(p);
6432
+ }
6429
6433
  CanvasKitHelpers.Dispose([
6430
6434
  // use backing fields, since paints may be undefined
6431
6435
  this._strokeColorPaintAntialiased,
@@ -6433,7 +6437,12 @@ class Shape extends M2Node {
6433
6437
  this._fillColorPaintAntialiased,
6434
6438
  this._fillColorPaintNotAntialiased,
6435
6439
  this.ckPath,
6436
- ...Array.from(this.colorfulPathPaints.values())
6440
+ // Originally, below was `...Array.from(this.colorfulPathPaints.values())`.
6441
+ // I changed the approach because one of our execution environments
6442
+ // (Qualtrics) is using a library that pollutes the global namespace and
6443
+ // adds a broken implementation of `Array.from()` that does not work with
6444
+ // iterables.
6445
+ ...colorfulPathPaintsToDispose
6437
6446
  ]);
6438
6447
  }
6439
6448
  /**
@@ -7990,7 +7999,7 @@ var hasRequiredCanvaskit;
7990
7999
  function requireCanvaskit () {
7991
8000
  if (hasRequiredCanvaskit) return canvaskit.exports;
7992
8001
  hasRequiredCanvaskit = 1;
7993
- (function (module, exports) {
8002
+ (function (module, exports$1) {
7994
8003
  var CanvasKitInit = (() => {
7995
8004
  var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined;
7996
8005
  if (typeof __filename !== 'undefined') _scriptDir = _scriptDir || __filename;
@@ -12872,7 +12881,7 @@ const _RandomDraws = class _RandomDraws {
12872
12881
  selected.add(t);
12873
12882
  }
12874
12883
  }
12875
- return Array.from(selected);
12884
+ return [...selected];
12876
12885
  }
12877
12886
  /**
12878
12887
  * @deprecated Use `fromRangeWithoutReplacement()` instead.
@@ -12904,6 +12913,9 @@ const _RandomDraws = class _RandomDraws {
12904
12913
  const result = new Array();
12905
12914
  const maximumInclusive = rows * columns - 1;
12906
12915
  const draws = this.fromRangeWithoutReplacement(n, 0, maximumInclusive);
12916
+ const start = Date.now();
12917
+ let warned = false;
12918
+ let loopCounter = 0;
12907
12919
  let i = 0;
12908
12920
  let replacementCell = NaN;
12909
12921
  while (i < n) {
@@ -12922,6 +12934,20 @@ const _RandomDraws = class _RandomDraws {
12922
12934
  } while (draws.includes(replacementCell));
12923
12935
  draws[i] = replacementCell;
12924
12936
  }
12937
+ if (++loopCounter % this.samplingCheckInterval === 0) {
12938
+ const elapsed = Date.now() - start;
12939
+ if (!warned && elapsed > this.samplingWarnMs) {
12940
+ console.warn(
12941
+ `RandomDraws.fromGridWithoutReplacement(): sampling exceeded ${this.samplingWarnMs} ms; predicate may be impossible or expensive.`
12942
+ );
12943
+ warned = true;
12944
+ }
12945
+ if (elapsed > this.samplingTimeoutMs) {
12946
+ throw new M2Error(
12947
+ `RandomDraws.fromGridWithoutReplacement(): sampling exceeded timeout of ${this.samplingTimeoutMs} ms; predicate may be impossible or expensive.`
12948
+ );
12949
+ }
12950
+ }
12925
12951
  }
12926
12952
  return result;
12927
12953
  }
@@ -12932,6 +12958,12 @@ const _RandomDraws = class _RandomDraws {
12932
12958
  return this.fromGridWithoutReplacement(n, rows, columns, predicate);
12933
12959
  }
12934
12960
  };
12961
+ /** Number of milliseconds before a warning is logged if sampling takes too long. Tuneable for tests. */
12962
+ _RandomDraws.samplingWarnMs = 1e3;
12963
+ /** Number of milliseconds before sampling times out. Tuneable for tests or legitimate edge use cases. */
12964
+ _RandomDraws.samplingTimeoutMs = 5e3;
12965
+ /** Number of loop iterations between checks. Tuneable for tests. */
12966
+ _RandomDraws.samplingCheckInterval = 4096;
12935
12967
  _RandomDraws.randomFunction = Math.random;
12936
12968
  _RandomDraws.seededPRNG = null;
12937
12969
  let RandomDraws = _RandomDraws;
@@ -13476,7 +13508,7 @@ class Story {
13476
13508
  }
13477
13509
  }
13478
13510
 
13479
- console.log("\u26AA @m2c2kit/core version 0.3.33 (92cfffbe)");
13511
+ console.log("\u26AA @m2c2kit/core version 0.3.35 (c86b5047)");
13480
13512
 
13481
13513
  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, M2Error, 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 };
13482
13514
  //# sourceMappingURL=index.js.map