@doenet/v06-to-v07 0.7.21-dev.351 → 0.7.21-dev.353

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.
@@ -40982,6 +40982,14 @@ function contrastAccessibilityDiagnosticsForStyleDefinitions(styleDefinitions) {
40982
40982
  }
40983
40983
  return diagnostics;
40984
40984
  }
40985
+ function resolveReaderPaletteName(overrides2) {
40986
+ const raw = overrides2?.palette;
40987
+ if (typeof raw !== "string") {
40988
+ return null;
40989
+ }
40990
+ const name2 = raw.trim().toLowerCase();
40991
+ return name2 in STYLE_PALETTES ? name2 : null;
40992
+ }
40985
40993
  let styleAttributes$1 = {
40986
40994
  lineColor: {
40987
40995
  componentType: "text",
@@ -41498,6 +41506,77 @@ function childrenExpandingSetups(dependencyValues, mixedChildren, perSetupPrefix
41498
41506
  }
41499
41507
  return out;
41500
41508
  }
41509
+ function normalizeReaderStyleValue(key, value) {
41510
+ switch (styleAttributes$1[key]?.componentType) {
41511
+ case "number": {
41512
+ const num = typeof value === "number" ? value : typeof value === "string" && value.trim() !== "" ? Number(value) : NaN;
41513
+ return Number.isFinite(num) ? num : void 0;
41514
+ }
41515
+ case "boolean": {
41516
+ if (typeof value === "boolean") {
41517
+ return value;
41518
+ }
41519
+ if (typeof value === "string") {
41520
+ const lowered = value.toLowerCase();
41521
+ if (lowered === "true") {
41522
+ return true;
41523
+ }
41524
+ if (lowered === "false") {
41525
+ return false;
41526
+ }
41527
+ }
41528
+ return void 0;
41529
+ }
41530
+ default:
41531
+ return typeof value === "string" ? value.toLowerCase() : void 0;
41532
+ }
41533
+ }
41534
+ function applyReaderStyleOverrides(styleDefinitions, overrides2) {
41535
+ const hasOwn = Object.prototype.hasOwnProperty;
41536
+ const readerPaletteName = resolveReaderPaletteName(overrides2);
41537
+ if (readerPaletteName != null) {
41538
+ for (const styleNumber of Object.keys(styleDefinitions)) {
41539
+ delete styleDefinitions[styleNumber];
41540
+ }
41541
+ Object.assign(
41542
+ styleDefinitions,
41543
+ returnPaletteStyleDefinitions(readerPaletteName)
41544
+ );
41545
+ }
41546
+ const styles = overrides2?.styles;
41547
+ if (!styles || typeof styles !== "object") {
41548
+ return;
41549
+ }
41550
+ for (const [styleNumber, valueOverrides] of Object.entries(styles)) {
41551
+ if (!hasOwn.call(styleDefinitions, styleNumber)) {
41552
+ continue;
41553
+ }
41554
+ const target = styleDefinitions[styleNumber];
41555
+ if (!target || !valueOverrides || typeof valueOverrides !== "object") {
41556
+ continue;
41557
+ }
41558
+ const block = {};
41559
+ for (const [key, value] of Object.entries(valueOverrides)) {
41560
+ if (!hasOwn.call(styleAttributes$1, key) || key.includes("Word")) {
41561
+ continue;
41562
+ }
41563
+ const normalized = normalizeReaderStyleValue(
41564
+ key,
41565
+ value
41566
+ );
41567
+ if (normalized === void 0) {
41568
+ continue;
41569
+ }
41570
+ setStyleValue(block, key, normalized);
41571
+ }
41572
+ if (Object.keys(block).length === 0) {
41573
+ continue;
41574
+ }
41575
+ addMissingChildStyleColorFields(block);
41576
+ deriveMissingStyleWords(block);
41577
+ Object.assign(target, block);
41578
+ }
41579
+ }
41501
41580
  function returnStyleDefinitionStateVariables() {
41502
41581
  let stateVariableDefinitions = {};
41503
41582
  stateVariableDefinitions.setupChildren = {
@@ -41514,6 +41593,56 @@ function returnStyleDefinitionStateVariables() {
41514
41593
  };
41515
41594
  }
41516
41595
  };
41596
+ stateVariableDefinitions.readerStyleOverrides = {
41597
+ hasEssential: true,
41598
+ defaultValue: null,
41599
+ returnDependencies: () => ({
41600
+ documentAncestor: {
41601
+ dependencyType: "ancestor",
41602
+ componentType: "document",
41603
+ variableNames: ["readerStyleOverrides"]
41604
+ }
41605
+ }),
41606
+ definition({ dependencyValues }) {
41607
+ if (dependencyValues.documentAncestor) {
41608
+ return {
41609
+ setValue: {
41610
+ readerStyleOverrides: dependencyValues.documentAncestor.stateValues.readerStyleOverrides
41611
+ }
41612
+ };
41613
+ } else {
41614
+ return {
41615
+ useEssentialOrDefaultValue: { readerStyleOverrides: true }
41616
+ };
41617
+ }
41618
+ },
41619
+ inverseDefinition({
41620
+ desiredStateVariableValues,
41621
+ dependencyValues
41622
+ }) {
41623
+ if (dependencyValues.documentAncestor) {
41624
+ return {
41625
+ success: true,
41626
+ instructions: [
41627
+ {
41628
+ setDependency: "documentAncestor",
41629
+ desiredValue: desiredStateVariableValues.readerStyleOverrides
41630
+ }
41631
+ ]
41632
+ };
41633
+ } else {
41634
+ return {
41635
+ success: true,
41636
+ instructions: [
41637
+ {
41638
+ setEssentialValue: "readerStyleOverrides",
41639
+ value: desiredStateVariableValues.readerStyleOverrides
41640
+ }
41641
+ ]
41642
+ };
41643
+ }
41644
+ }
41645
+ };
41517
41646
  stateVariableDefinitions.localStylePaletteName = {
41518
41647
  stateVariablesDeterminingDependencies: ["setupChildren"],
41519
41648
  returnDependencies({ stateValues }) {
@@ -41578,14 +41707,15 @@ function returnStyleDefinitionStateVariables() {
41578
41707
  return { setValue: { activeStylePaletteName } };
41579
41708
  }
41580
41709
  };
41581
- stateVariableDefinitions.styleDefinitions = {
41710
+ stateVariableDefinitions.authoredStyleDefinitions = {
41711
+ // Always evaluated so the diagnostics side effect reliably runs.
41582
41712
  mustEvaluate: true,
41583
41713
  stateVariablesDeterminingDependencies: ["setupChildren"],
41584
41714
  returnDependencies({ stateValues }) {
41585
41715
  let dependencies2 = {
41586
41716
  ancestorWithStyle: {
41587
41717
  dependencyType: "ancestor",
41588
- variableNames: ["styleDefinitions"]
41718
+ variableNames: ["authoredStyleDefinitions"]
41589
41719
  },
41590
41720
  localStylePaletteName: {
41591
41721
  dependencyType: "stateVariable",
@@ -41621,7 +41751,7 @@ function returnStyleDefinitionStateVariables() {
41621
41751
  dependencyValues.localStylePaletteName
41622
41752
  );
41623
41753
  } else if (dependencyValues.ancestorWithStyle) {
41624
- startingStateVariableDefinitions = dependencyValues.ancestorWithStyle.stateValues.styleDefinitions;
41754
+ startingStateVariableDefinitions = dependencyValues.ancestorWithStyle.stateValues.authoredStyleDefinitions;
41625
41755
  }
41626
41756
  if (!startingStateVariableDefinitions) {
41627
41757
  startingStateVariableDefinitions = returnDefaultStyleDefinitions();
@@ -41681,11 +41811,44 @@ function returnStyleDefinitionStateVariables() {
41681
41811
  styleDefinitions
41682
41812
  );
41683
41813
  return {
41684
- setValue: { styleDefinitions },
41814
+ setValue: { authoredStyleDefinitions: styleDefinitions },
41685
41815
  sendDiagnostics: diagnostics
41686
41816
  };
41687
41817
  }
41688
41818
  };
41819
+ stateVariableDefinitions.styleDefinitions = {
41820
+ returnDependencies: () => ({
41821
+ authoredStyleDefinitions: {
41822
+ dependencyType: "stateVariable",
41823
+ variableName: "authoredStyleDefinitions"
41824
+ },
41825
+ readerStyleOverrides: {
41826
+ dependencyType: "stateVariable",
41827
+ variableName: "readerStyleOverrides"
41828
+ }
41829
+ }),
41830
+ definition({ dependencyValues }) {
41831
+ if (dependencyValues.readerStyleOverrides == null) {
41832
+ return {
41833
+ setValue: {
41834
+ styleDefinitions: dependencyValues.authoredStyleDefinitions
41835
+ }
41836
+ };
41837
+ }
41838
+ const styleDefinitions = {};
41839
+ for (const styleNumber in dependencyValues.authoredStyleDefinitions) {
41840
+ styleDefinitions[styleNumber] = Object.assign(
41841
+ {},
41842
+ dependencyValues.authoredStyleDefinitions[styleNumber]
41843
+ );
41844
+ }
41845
+ applyReaderStyleOverrides(
41846
+ styleDefinitions,
41847
+ dependencyValues.readerStyleOverrides
41848
+ );
41849
+ return { setValue: { styleDefinitions } };
41850
+ }
41851
+ };
41689
41852
  return stateVariableDefinitions;
41690
41853
  }
41691
41854
  function returnSelectedStyleStateVariableDefinition(options = {}) {
@@ -41704,7 +41867,8 @@ function returnSelectedStyleStateVariableDefinition(options = {}) {
41704
41867
  dependencyType: "ancestor",
41705
41868
  variableNames: [
41706
41869
  "styleDefinitions",
41707
- "activeStylePaletteName"
41870
+ "activeStylePaletteName",
41871
+ "readerStyleOverrides"
41708
41872
  ]
41709
41873
  }
41710
41874
  };
@@ -41726,11 +41890,13 @@ function returnSelectedStyleStateVariableDefinition(options = {}) {
41726
41890
  }
41727
41891
  let selectedStyle = styleDefinitions[dependencyValues.styleNumber];
41728
41892
  if (selectedStyle === void 0) {
41729
- const activeStylePaletteName = dependencyValues.ancestorWithStyle?.stateValues.activeStylePaletteName;
41730
- if (activeStylePaletteName != null) {
41893
+ const effectivePaletteName = resolveReaderPaletteName(
41894
+ dependencyValues.ancestorWithStyle?.stateValues.readerStyleOverrides
41895
+ ) ?? dependencyValues.ancestorWithStyle?.stateValues.activeStylePaletteName;
41896
+ if (effectivePaletteName != null) {
41731
41897
  selectedStyle = styleDefinitions[cycleStyleNumberForPalette(
41732
41898
  dependencyValues.styleNumber,
41733
- activeStylePaletteName
41899
+ effectivePaletteName
41734
41900
  )];
41735
41901
  }
41736
41902
  }
@@ -42339,7 +42505,7 @@ async function cidFromArrayBuffer(data) {
42339
42505
  await crypto.subtle.digest("SHA-256", new Uint8Array());
42340
42506
  digest = (data2) => crypto.subtle.digest("SHA-256", data2);
42341
42507
  } catch (e22) {
42342
- const sha256 = (await import("./sha256-BbJ5TZns-Cy0oPV4j-D0PQMZYb.js").then((n2) => n2.s)).default;
42508
+ const sha256 = (await import("./sha256-a7S5PDuo-CKxUBTt--B9I1uHhS.js").then((n2) => n2.s)).default;
42343
42509
  digest = (data2) => sha256(data2, {
42344
42510
  asBytes: true
42345
42511
  });
@@ -65473,7 +65639,17 @@ class RendererInstructionBuilder {
65473
65639
  id: this.getRendererId(component),
65474
65640
  componentType: component.componentType,
65475
65641
  rendererType: component.rendererType,
65476
- actions: requestActions
65642
+ actions: requestActions,
65643
+ // Source range in the original DoenetML, used by hosts (e.g. the
65644
+ // VS Code preview) to sync cursor/click position with the
65645
+ // editor. Absent for components with no direct source origin.
65646
+ // Note: a copy's replacement gets the copy reference's own range
65647
+ // (e.g. `$g`'s), while descendants that already carried a
65648
+ // position keep the original definition's range — see
65649
+ // `assignDoenetMLRange`'s `init` flag. The viewer compensates
65650
+ // when attributing clicks on copied content (`containsRange` in
65651
+ // DocViewer).
65652
+ position: component.position
65477
65653
  };
65478
65654
  this.componentsToRender[componentIdx] = {
65479
65655
  children: childrenToRender
@@ -67084,6 +67260,22 @@ class UpdateExecutor {
67084
67260
  });
67085
67261
  return { actionId: args.actionId };
67086
67262
  }
67263
+ if (actionName === "setStyleOverrides" && componentIdx === void 0) {
67264
+ await this.performUpdate({
67265
+ updateInstructions: [
67266
+ {
67267
+ updateType: "updateValue",
67268
+ componentIdx: this.core.documentIdx,
67269
+ stateVariable: "readerStyleOverrides",
67270
+ value: args.styleOverrides ?? null
67271
+ }
67272
+ ],
67273
+ actionId: args.actionId,
67274
+ doNotSave: true
67275
+ // this isn't an interaction, so don't save doc state
67276
+ });
67277
+ return { actionId: args.actionId };
67278
+ }
67087
67279
  let component = this.core._components[componentIdx];
67088
67280
  if (component && component.actions) {
67089
67281
  let action = component.actions[actionName];
@@ -69236,6 +69428,7 @@ class Core {
69236
69428
  requestedVariantIndex,
69237
69429
  initializeCounters = {},
69238
69430
  theme,
69431
+ styleOverrides,
69239
69432
  prerender = false,
69240
69433
  stateVariableChanges: stateVariableChangesString,
69241
69434
  coreId,
@@ -69281,6 +69474,7 @@ class Core {
69281
69474
  this.numerics = new Numerics();
69282
69475
  this.flags = flags;
69283
69476
  this.theme = theme;
69477
+ this.styleOverrides = styleOverrides;
69284
69478
  this.getStateVariableValue = this.getStateVariableValue.bind(this);
69285
69479
  this.componentInfoObjects = componentInfoObjects2;
69286
69480
  this.initializeCounters = initializeCounters;
@@ -69384,6 +69578,9 @@ class Core {
69384
69578
  serializedComponents[0].state = {};
69385
69579
  }
69386
69580
  serializedComponents[0].state.theme = this.theme;
69581
+ if (this.styleOverrides != null) {
69582
+ serializedComponents[0].state.readerStyleOverrides = this.styleOverrides;
69583
+ }
69387
69584
  serializedComponents[0].doenetAttributes.cid = this.cid;
69388
69585
  this._components = [];
69389
69586
  this.componentIdxByStateId = {};
@@ -231920,4 +232117,4 @@ export {
231920
232117
  getDefaultExportFromCjs as g,
231921
232118
  updateSyntaxFromV06toV07 as u
231922
232119
  };
231923
- //# sourceMappingURL=index-B7dZK3j_.js.map
232120
+ //# sourceMappingURL=index-L-CvJFQy.js.map