@doenet/v06-to-v07 0.7.20-dev.308 → 0.7.20-dev.310

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.
@@ -40963,7 +40963,7 @@ async function cidFromArrayBuffer(data) {
40963
40963
  await crypto.subtle.digest("SHA-256", new Uint8Array());
40964
40964
  digest = (data2) => crypto.subtle.digest("SHA-256", data2);
40965
40965
  } catch (e22) {
40966
- const sha256 = (await import("./sha256-C0vj3HDn-Cy4MoSBb-D7vYyaIg.js").then((n2) => n2.s)).default;
40966
+ const sha256 = (await import("./sha256-C0vj3HDn-C8N7qkQo-_aAug7Di.js").then((n2) => n2.s)).default;
40967
40967
  digest = (data2) => sha256(data2, {
40968
40968
  asBytes: true
40969
40969
  });
@@ -49616,6 +49616,54 @@ const PRIMITIVE_TO_COMPONENT_TYPE = {
49616
49616
  stringArray: "textList",
49617
49617
  numberArray: "numberList"
49618
49618
  };
49619
+ const SHARED_STATE_VARIABLE_DEFINITIONS = /* @__PURE__ */ Symbol(
49620
+ "sharedStateVariableDefinitions"
49621
+ );
49622
+ const classStateVariableDefinitionsCache = /* @__PURE__ */ new WeakMap();
49623
+ function getClassStateVariableDefinitions(core2, componentClass) {
49624
+ let perCore = classStateVariableDefinitionsCache.get(core2);
49625
+ if (!perCore) {
49626
+ perCore = /* @__PURE__ */ new Map();
49627
+ classStateVariableDefinitionsCache.set(core2, perCore);
49628
+ }
49629
+ let entry = perCore.get(componentClass);
49630
+ if (!entry) {
49631
+ const combined = {};
49632
+ createAttributeStateVariableDefinitions({
49633
+ core: core2,
49634
+ stateVariableDefinitions: combined,
49635
+ componentClass
49636
+ });
49637
+ const normalized = componentClass.returnNormalizedStateVariableDefinitions(
49638
+ core2.numerics
49639
+ );
49640
+ Object.assign(combined, normalized);
49641
+ combined[SHARED_STATE_VARIABLE_DEFINITIONS] = true;
49642
+ entry = { combined, normalized };
49643
+ perCore.set(componentClass, entry);
49644
+ }
49645
+ return entry;
49646
+ }
49647
+ function cloneStateVariableDefinition(def) {
49648
+ const clone2 = Object.assign({}, def);
49649
+ if (clone2.shadowingInstructions) {
49650
+ clone2.shadowingInstructions = Object.assign(
49651
+ {},
49652
+ clone2.shadowingInstructions
49653
+ );
49654
+ }
49655
+ if (clone2.additionalStateVariablesDefined) {
49656
+ clone2.additionalStateVariablesDefined = [
49657
+ ...clone2.additionalStateVariablesDefined
49658
+ ];
49659
+ }
49660
+ if (clone2.stateVariablesDeterminingDependencies) {
49661
+ clone2.stateVariablesDeterminingDependencies = [
49662
+ ...clone2.stateVariablesDeterminingDependencies
49663
+ ];
49664
+ }
49665
+ return clone2;
49666
+ }
49619
49667
  async function createStateVariableDefinitions({
49620
49668
  core: core2,
49621
49669
  componentClass,
@@ -49659,32 +49707,33 @@ async function createStateVariableDefinitions({
49659
49707
  }
49660
49708
  }
49661
49709
  }
49662
- let stateVariableDefinitions = {};
49710
+ const classDefinitions = getClassStateVariableDefinitions(
49711
+ core2,
49712
+ componentClass
49713
+ );
49663
49714
  if (!redefineDependencies) {
49664
- createAttributeStateVariableDefinitions({
49715
+ return classDefinitions.combined;
49716
+ }
49717
+ let stateVariableDefinitions = {};
49718
+ for (const varName in classDefinitions.normalized) {
49719
+ stateVariableDefinitions[varName] = cloneStateVariableDefinition(
49720
+ classDefinitions.normalized[varName]
49721
+ );
49722
+ }
49723
+ if (redefineDependencies.linkSource === "adapter") {
49724
+ createAdapterStateVariableDefinitions({
49665
49725
  core: core2,
49726
+ redefineDependencies,
49727
+ stateVariableDefinitions,
49728
+ componentClass
49729
+ });
49730
+ } else {
49731
+ await createReferenceShadowStateVariableDefinitions({
49732
+ core: core2,
49733
+ redefineDependencies,
49666
49734
  stateVariableDefinitions,
49667
49735
  componentClass
49668
49736
  });
49669
- }
49670
- let newDefinitions = componentClass.returnNormalizedStateVariableDefinitions(core2.numerics);
49671
- Object.assign(stateVariableDefinitions, newDefinitions);
49672
- if (redefineDependencies) {
49673
- if (redefineDependencies.linkSource === "adapter") {
49674
- createAdapterStateVariableDefinitions({
49675
- core: core2,
49676
- redefineDependencies,
49677
- stateVariableDefinitions,
49678
- componentClass
49679
- });
49680
- } else {
49681
- await createReferenceShadowStateVariableDefinitions({
49682
- core: core2,
49683
- redefineDependencies,
49684
- stateVariableDefinitions,
49685
- componentClass
49686
- });
49687
- }
49688
49737
  }
49689
49738
  return stateVariableDefinitions;
49690
49739
  }
@@ -53011,6 +53060,7 @@ function cloneChangeMetadataIfNeeded({
53011
53060
  }) {
53012
53061
  return consumeChanges ? changeMetadata : deepClone(changeMetadata);
53013
53062
  }
53063
+ const INITIAL_CHANGE_RECORD = Object.freeze({ changed: true });
53014
53064
  const _Dependency = class _Dependency2 {
53015
53065
  constructor({
53016
53066
  component,
@@ -53025,7 +53075,7 @@ const _Dependency = class _Dependency2 {
53025
53075
  this.dependencyHandler = dependencyHandler;
53026
53076
  this.upstreamComponentIdx = component.componentIdx;
53027
53077
  this.upstreamVariableNames = allStateVariablesAffected;
53028
- this.definition = Object.assign({}, dependencyDefinition);
53078
+ this.definition = dependencyDefinition;
53029
53079
  this.representativeStateVariable = stateVariable;
53030
53080
  if (dependencyDefinition.doNotProxy) {
53031
53081
  this.doNotProxy = true;
@@ -53181,6 +53231,9 @@ const _Dependency = class _Dependency2 {
53181
53231
  }
53182
53232
  let downVarNames = mappedVarNames;
53183
53233
  if (originalVarNames.length > 0 || this.originalVariablesByComponent) {
53234
+ mappedVarNames = this.dependencyHandler.internVariableNameList(
53235
+ mappedVarNames
53236
+ );
53184
53237
  this.mappedDownstreamVariableNamesByComponent.splice(
53185
53238
  index2,
53186
53239
  0,
@@ -53188,7 +53241,7 @@ const _Dependency = class _Dependency2 {
53188
53241
  );
53189
53242
  let valsChanged = {};
53190
53243
  for (let downVar of mappedVarNames) {
53191
- valsChanged[downVar] = { changed: true };
53244
+ valsChanged[downVar] = INITIAL_CHANGE_RECORD;
53192
53245
  }
53193
53246
  this.valuesChanged.splice(index2, 0, valsChanged);
53194
53247
  if (this.variablesOptional) {
@@ -53288,9 +53341,10 @@ const _Dependency = class _Dependency2 {
53288
53341
  );
53289
53342
  this.valuesChanged.splice(indexToRemove, 1);
53290
53343
  if (this.variablesOptional) {
53291
- affectedDownstreamVariableNames.push(
53344
+ affectedDownstreamVariableNames = [
53345
+ ...affectedDownstreamVariableNames,
53292
53346
  this.downstreamVariableNameIfNoVariables
53293
- );
53347
+ ];
53294
53348
  }
53295
53349
  }
53296
53350
  for (let vName of affectedDownstreamVariableNames) {
@@ -53511,7 +53565,7 @@ const _Dependency = class _Dependency2 {
53511
53565
  if (!mappedStateVarObj.deferred) {
53512
53566
  componentObj.stateValues[nameForOutput] = await mappedStateVarObj.value;
53513
53567
  let valueChanged = this.valuesChanged[componentInd][mappedVarName];
53514
- if (valueChanged.changed) {
53568
+ if (valueChanged?.changed) {
53515
53569
  if (!changes.valuesChanged) {
53516
53570
  changes.valuesChanged = {};
53517
53571
  }
@@ -53524,7 +53578,7 @@ const _Dependency = class _Dependency2 {
53524
53578
  });
53525
53579
  }
53526
53580
  if (consumeChanges) {
53527
- this.valuesChanged[componentInd][mappedVarName] = {};
53581
+ delete this.valuesChanged[componentInd][mappedVarName];
53528
53582
  }
53529
53583
  if (mappedStateVarObj.usedDefault) {
53530
53584
  usedDefaultObj[nameForOutput] = true;
@@ -54093,7 +54147,7 @@ const _StateVariableComponentTypeDependency = class _StateVariableComponentTypeD
54093
54147
  }
54094
54148
  }
54095
54149
  let valueChanged0 = this.valuesChanged[0][mappedVarName];
54096
- if (valueChanged0.changed) {
54150
+ if (valueChanged0?.changed) {
54097
54151
  if (!changes.valuesChanged) {
54098
54152
  changes.valuesChanged = {};
54099
54153
  }
@@ -54106,7 +54160,7 @@ const _StateVariableComponentTypeDependency = class _StateVariableComponentTypeD
54106
54160
  });
54107
54161
  }
54108
54162
  if (consumeChanges) {
54109
- this.valuesChanged[0][mappedVarName] = {};
54163
+ delete this.valuesChanged[0][mappedVarName];
54110
54164
  }
54111
54165
  let hasVariableComponentType = stateVarObj.shadowingInstructions?.hasVariableComponentType;
54112
54166
  if (!hasVariableComponentType && stateVarObj.isArrayEntry) {
@@ -58495,6 +58549,7 @@ const dependencyTypeClasses = [
58495
58549
  DetermineDependenciesDependency,
58496
58550
  FileDependency
58497
58551
  ];
58552
+ const EMPTY_BLOCKERS = Object.freeze({});
58498
58553
  class DependencyHandler {
58499
58554
  constructor({
58500
58555
  _components,
@@ -58529,6 +58584,16 @@ class DependencyHandler {
58529
58584
  resolveBlockedBy: {}
58530
58585
  };
58531
58586
  this.attributeRefResolutionDependenciesByReferenced = {};
58587
+ this._internedVariableNameLists = /* @__PURE__ */ new Map();
58588
+ }
58589
+ internVariableNameList(names) {
58590
+ const key = names.join("\n");
58591
+ let interned = this._internedVariableNameLists.get(key);
58592
+ if (!interned) {
58593
+ interned = Object.freeze(names);
58594
+ this._internedVariableNameLists.set(key, interned);
58595
+ }
58596
+ return interned;
58532
58597
  }
58533
58598
  async setUpComponentDependencies(component) {
58534
58599
  if (this.downstreamDependencies[component.componentIdx]) {
@@ -59244,26 +59309,11 @@ class DependencyHandler {
59244
59309
  let ind = upDep.downstreamComponentIndices.indexOf(componentIdx);
59245
59310
  let upValuesChanged = upDep.valuesChanged[ind][varName];
59246
59311
  if (!upValuesChanged) {
59247
- if (component.stateVarAliases) {
59248
- for (let alias in component.stateVarAliases) {
59249
- if (component.stateVarAliases[alias] === varName && // @ts-expect-error see "Note (dated July 20, 2023)" above:
59250
- // `upValuesChangedSub` is undefined; keeping the
59251
- // reference verbatim so behavior matches the JS source.
59252
- alias in upValuesChangedSub) {
59253
- upValuesChanged = // @ts-expect-error same as above
59254
- upValuesChangedSub[alias];
59255
- }
59256
- }
59257
- }
59258
- }
59259
- if (!upValuesChanged) {
59260
- if (!component.state[varName].isArrayEntry) {
59261
- throw Error(
59262
- `Something is wrong, as a variable ${varName} of ${component.componentIdx} actually changed, but wasn't marked with a potential change`
59263
- );
59264
- }
59265
- upValuesChanged = // @ts-expect-error same as above
59266
- upValuesChangedSub[varName] = { changed: {} };
59312
+ upValuesChanged = upDep.valuesChanged[ind][varName] = {};
59313
+ } else if (Object.isFrozen(upValuesChanged)) {
59314
+ upValuesChanged = upDep.valuesChanged[ind][varName] = {
59315
+ changed: upValuesChanged.changed
59316
+ };
59267
59317
  }
59268
59318
  if (component.state[varName] && component.state[varName].isArray) {
59269
59319
  if (upValuesChanged.changed === void 0) {
@@ -59381,6 +59431,45 @@ class DependencyHandler {
59381
59431
  finishedPropagation: parentResult.finishedPropagation
59382
59432
  };
59383
59433
  }
59434
+ /**
59435
+ * Non-creating variant of `getNeededToResolve`: returns the nested entry
59436
+ * if it exists, else `EMPTY_BLOCKERS`, without materializing intermediate
59437
+ * levels. `getNeededToResolve` creates the whole nested chain on every
59438
+ * lookup, and read-only callers used to leave tens of thousands of empty
59439
+ * `{cIdx: {type: {stateVariable: {}}}}` chains behind — the bulk of
59440
+ * `resolveBlockers`' retained memory.
59441
+ */
59442
+ peekNeededToResolve({
59443
+ componentIdx,
59444
+ type,
59445
+ stateVariable,
59446
+ dependency
59447
+ }) {
59448
+ let neededToResolve = this.resolveBlockers.neededToResolve[componentIdx]?.[type];
59449
+ if (neededToResolve && stateVariable) {
59450
+ neededToResolve = neededToResolve[stateVariable];
59451
+ if (neededToResolve && dependency) {
59452
+ neededToResolve = neededToResolve[dependency];
59453
+ }
59454
+ }
59455
+ return neededToResolve ?? EMPTY_BLOCKERS;
59456
+ }
59457
+ /** Non-creating variant of `getResolveBlockedBy`; see `peekNeededToResolve`. */
59458
+ peekResolveBlockedBy({
59459
+ componentIdx,
59460
+ type,
59461
+ stateVariable,
59462
+ dependency
59463
+ }) {
59464
+ let resolveBlockedBy = this.resolveBlockers.resolveBlockedBy[componentIdx]?.[type];
59465
+ if (resolveBlockedBy && stateVariable) {
59466
+ resolveBlockedBy = resolveBlockedBy[stateVariable];
59467
+ if (resolveBlockedBy && dependency) {
59468
+ resolveBlockedBy = resolveBlockedBy[dependency];
59469
+ }
59470
+ }
59471
+ return resolveBlockedBy ?? EMPTY_BLOCKERS;
59472
+ }
59384
59473
  getNeededToResolve({ componentIdx, type, stateVariable, dependency }) {
59385
59474
  let neededToResolveForComponent = this.resolveBlockers.neededToResolve[componentIdx];
59386
59475
  if (!neededToResolveForComponent) {
@@ -59890,7 +59979,7 @@ class DependencyHandler {
59890
59979
  } catch (e32) {
59891
59980
  }
59892
59981
  if (dep) {
59893
- let neededForItem = this.getNeededToResolve({
59982
+ let neededForItem = this.peekNeededToResolve({
59894
59983
  componentIdx: componentIdxNewlyResolved,
59895
59984
  type: "stateVariable",
59896
59985
  stateVariable: stateVariableNewlyResolved
@@ -59981,7 +60070,7 @@ class DependencyHandler {
59981
60070
  );
59982
60071
  }
59983
60072
  }
59984
- let resolveBlockedByNewlyResolved = this.getResolveBlockedBy({
60073
+ let resolveBlockedByNewlyResolved = this.peekResolveBlockedBy({
59985
60074
  componentIdx: componentIdxNewlyResolved,
59986
60075
  type: typeNewlyResolved,
59987
60076
  stateVariable: stateVariableNewlyResolved,
@@ -60083,7 +60172,7 @@ class DependencyHandler {
60083
60172
  expandComposites = true,
60084
60173
  numPreviouslyNeeded
60085
60174
  }) {
60086
- let neededForItem = this.getNeededToResolve({
60175
+ let neededForItem = this.peekNeededToResolve({
60087
60176
  componentIdx,
60088
60177
  type,
60089
60178
  stateVariable,
@@ -60125,7 +60214,7 @@ class DependencyHandler {
60125
60214
  break;
60126
60215
  }
60127
60216
  if (nFailures > 0) {
60128
- neededForItem = this.getNeededToResolve({
60217
+ neededForItem = this.peekNeededToResolve({
60129
60218
  componentIdx,
60130
60219
  type,
60131
60220
  stateVariable,
@@ -60165,7 +60254,7 @@ class DependencyHandler {
60165
60254
  }
60166
60255
  }
60167
60256
  if (nFailures > 0) {
60168
- neededForItem = this.getNeededToResolve({
60257
+ neededForItem = this.peekNeededToResolve({
60169
60258
  componentIdx,
60170
60259
  type,
60171
60260
  stateVariable,
@@ -60213,7 +60302,7 @@ class DependencyHandler {
60213
60302
  expandComposites
60214
60303
  });
60215
60304
  if (!finalResult.success) {
60216
- let stillNeededForItem = this.getNeededToResolve({
60305
+ let stillNeededForItem = this.peekNeededToResolve({
60217
60306
  componentIdx,
60218
60307
  type,
60219
60308
  stateVariable,
@@ -60265,7 +60354,7 @@ class DependencyHandler {
60265
60354
  }
60266
60355
  if (!this.circularResolveBlockedCheckPassed[identifier]) {
60267
60356
  this.circularResolveBlockedCheckPassed[identifier] = true;
60268
- let neededForItem = this.getNeededToResolve({
60357
+ let neededForItem = this.peekNeededToResolve({
60269
60358
  componentIdx,
60270
60359
  type,
60271
60360
  stateVariable,
@@ -60380,7 +60469,7 @@ class DependencyHandler {
60380
60469
  let identifier = code + "|" + type;
60381
60470
  if (this.circularResolveBlockedCheckPassed[identifier]) {
60382
60471
  delete this.circularResolveBlockedCheckPassed[identifier];
60383
- let resolveBlockedBy = this.getResolveBlockedBy({
60472
+ let resolveBlockedBy = this.peekResolveBlockedBy({
60384
60473
  componentIdx,
60385
60474
  type,
60386
60475
  stateVariable,
@@ -63834,12 +63923,13 @@ class StalenessPropagator {
63834
63923
  if (!upDep.valuesChanged[componentInd]) {
63835
63924
  upDep.valuesChanged[componentInd] = {};
63836
63925
  }
63837
- if (!upDep.valuesChanged[componentInd][varName]) {
63838
- upDep.valuesChanged[componentInd][varName] = {};
63926
+ let changeRecord = upDep.valuesChanged[componentInd][varName];
63927
+ if (!changeRecord || Object.isFrozen(changeRecord)) {
63928
+ changeRecord = upDep.valuesChanged[componentInd][varName] = changeRecord ? { changed: changeRecord.changed } : {};
63839
63929
  }
63840
- upDep.valuesChanged[componentInd][varName].potentialChange = true;
63930
+ changeRecord.potentialChange = true;
63841
63931
  if (freshnessInfo) {
63842
- upDep.valuesChanged[componentInd][varName].freshnessInfo = freshnessInfo;
63932
+ changeRecord.freshnessInfo = freshnessInfo;
63843
63933
  }
63844
63934
  foundVarChange = true;
63845
63935
  } else if (varName === upDep.downstreamVariableNameIfNoVariables) {
@@ -68465,11 +68555,52 @@ class BaseComponent {
68465
68555
  this.refResolution = refResolution;
68466
68556
  }
68467
68557
  this.state = {};
68468
- for (let stateVariable in stateVariableDefinitions) {
68469
- this.state[stateVariable] = Object.assign(
68470
- {},
68471
- stateVariableDefinitions[stateVariable]
68472
- );
68558
+ if (stateVariableDefinitions[SHARED_STATE_VARIABLE_DEFINITIONS]) {
68559
+ for (let stateVariable in stateVariableDefinitions) {
68560
+ let def = Object.create(
68561
+ stateVariableDefinitions[stateVariable]
68562
+ );
68563
+ if (def.shadowingInstructions) {
68564
+ def.shadowingInstructions = Object.assign(
68565
+ {},
68566
+ def.shadowingInstructions
68567
+ );
68568
+ }
68569
+ if (def.additionalStateVariablesDefined) {
68570
+ def.additionalStateVariablesDefined = [
68571
+ ...def.additionalStateVariablesDefined
68572
+ ];
68573
+ }
68574
+ if (def.stateVariablesDeterminingDependencies) {
68575
+ def.stateVariablesDeterminingDependencies = [
68576
+ ...def.stateVariablesDeterminingDependencies
68577
+ ];
68578
+ }
68579
+ this.state[stateVariable] = def;
68580
+ }
68581
+ } else {
68582
+ for (let stateVariable in stateVariableDefinitions) {
68583
+ this.state[stateVariable] = stateVariableDefinitions[stateVariable];
68584
+ }
68585
+ }
68586
+ let workspaceAssigned = /* @__PURE__ */ new Set();
68587
+ for (let stateVariable in this.state) {
68588
+ let def = this.state[stateVariable];
68589
+ if (!def.createWorkspace || workspaceAssigned.has(stateVariable)) {
68590
+ continue;
68591
+ }
68592
+ let workspace = {};
68593
+ def.workspace = workspace;
68594
+ workspaceAssigned.add(stateVariable);
68595
+ if (def.additionalStateVariablesDefined) {
68596
+ for (let otherVar of def.additionalStateVariablesDefined) {
68597
+ let otherDef = this.state[otherVar];
68598
+ if (otherDef?.createWorkspace) {
68599
+ otherDef.workspace = workspace;
68600
+ workspaceAssigned.add(otherVar);
68601
+ }
68602
+ }
68603
+ }
68473
68604
  }
68474
68605
  this.stateValues = new Proxy(this.state, createStateProxyHandler());
68475
68606
  this.essentialState = {};
@@ -73280,6 +73411,14 @@ class Label extends InlineComponent {
73280
73411
  public: true,
73281
73412
  forRenderer: true
73282
73413
  };
73414
+ attributes.maskLabel = {
73415
+ description: "Whether to give the label an opaque background so it stays legible when it overlaps an axis, grid line, or another object. Set to false to restore a transparent label background.",
73416
+ createComponentOfType: "boolean",
73417
+ createStateVariable: "maskLabel",
73418
+ defaultValue: true,
73419
+ public: true,
73420
+ forRenderer: true
73421
+ };
73283
73422
  Object.assign(attributes, returnAnchorAttributes());
73284
73423
  return attributes;
73285
73424
  }
@@ -81862,6 +82001,14 @@ class GraphicalComponent extends BaseComponent {
81862
82001
  forRenderer: true,
81863
82002
  description: "Whether to apply this component's selected style to its label."
81864
82003
  };
82004
+ attributes.maskLabel = {
82005
+ createComponentOfType: "boolean",
82006
+ createStateVariable: "maskLabel",
82007
+ defaultValue: true,
82008
+ public: true,
82009
+ forRenderer: true,
82010
+ description: "Whether to give the label an opaque background so it stays legible when it overlaps an axis, grid line, or another object. Set to false to restore a transparent label background."
82011
+ };
81865
82012
  attributes.layer = {
81866
82013
  createComponentOfType: "integer",
81867
82014
  createStateVariable: "layer",
@@ -228723,4 +228870,4 @@ export {
228723
228870
  getDefaultExportFromCjs as g,
228724
228871
  updateSyntaxFromV06toV07 as u
228725
228872
  };
228726
- //# sourceMappingURL=index-BmXW0q7U.js.map
228873
+ //# sourceMappingURL=index-Bur65SYm.js.map