@fuaran-ui/ops 0.8.0 → 0.19.0

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.js CHANGED
@@ -1,4 +1,4 @@
1
- import { FORM_FIELD_KIND_NAMES, NODE_KIND_GROUPS, defaults, projectSelectionField, controlValueDefaults } from '@fuaran-ui/schema';
1
+ import { FORM_FIELD_KIND_NAMES, NODE_KIND_GROUPS, defaults, controlValueDefaults, MAX_NODE_DEPTH, MAX_NODES, MAX_STRING_LENGTH, MAX_JSON_DEPTH, MAX_ARRAY_LENGTH, narrows, admitAll, NODE_KIND_NAMES, admits, policyHint, projectSelectionField } from '@fuaran-ui/schema';
2
2
 
3
3
  // src/encode.ts
4
4
  var assertNever = (x) => {
@@ -78,10 +78,11 @@ var formatFiniteDouble = (n) => {
78
78
  return neg ? "-" + out : out;
79
79
  };
80
80
  var num = (n) => {
81
- if (Number.isNaN(n)) return '"NaN"';
82
- if (n === Infinity) return '"Infinity"';
83
- if (n === -Infinity) return '"-Infinity"';
84
- return formatFiniteDouble(n);
81
+ const v = Number(n);
82
+ if (Number.isNaN(v)) return '"NaN"';
83
+ if (v === Infinity) return '"Infinity"';
84
+ if (v === -Infinity) return '"-Infinity"';
85
+ return formatFiniteDouble(v);
85
86
  };
86
87
  var bool = (b) => b ? "true" : "false";
87
88
  var jObject = (fields) => {
@@ -591,6 +592,9 @@ var pushWeightOptional = (fields, w) => {
591
592
  var pushEmphasisOptional = (fields, e) => {
592
593
  if (e !== "Normal") fields.push(["emphasis", str(e)]);
593
594
  };
595
+ var pushTrendPolarityOptional = (fields, p) => {
596
+ if (p !== "HigherIsBetter") fields.push(["trendPolarity", str(p)]);
597
+ };
594
598
  var pushCellFormatOptional = (fields, key, f) => {
595
599
  if (f.kind !== "None") fields.push([key, cellFormat(f)]);
596
600
  };
@@ -608,6 +612,7 @@ var metricSpec = (s) => {
608
612
  pushEmphasisOptional(fields, s.emphasis);
609
613
  if (s.trend !== void 0) fields.push(["trend", binding(s.trend)]);
610
614
  if (s.trendFormat !== void 0) fields.push(["trendFormat", cellFormat(s.trendFormat)]);
615
+ pushTrendPolarityOptional(fields, s.trendPolarity);
611
616
  if (s.icon !== void 0) fields.push(["icon", str(s.icon)]);
612
617
  if (s.subtext !== void 0) fields.push(["subtext", textSource(s.subtext)]);
613
618
  return jObject(fields);
@@ -654,11 +659,40 @@ var linkSpec = (s) => {
654
659
  if (s.protection !== void 0) fields.push(["protection", str(s.protection)]);
655
660
  return jObject(fields);
656
661
  };
657
- var imageSpec = (s) => jObject([
658
- ["alt", textSource(s.alt)],
659
- ["src", binding(s.src)],
660
- ["variant", str(s.variant)]
662
+ var srcSetEntry = (e) => jObject([
663
+ ["src", binding(e.src)],
664
+ ["width", num(e.width)]
661
665
  ]);
666
+ var imageSpec = (s) => {
667
+ const fields = [
668
+ ["alt", textSource(s.alt)],
669
+ ["src", binding(s.src)],
670
+ ["variant", str(s.variant)]
671
+ ];
672
+ if (s.fit !== "Natural") fields.push(["fit", str(s.fit)]);
673
+ if (s.aspectRatio !== "Natural") fields.push(["aspectRatio", str(s.aspectRatio)]);
674
+ if (s.loading !== "Eager") fields.push(["loading", str(s.loading)]);
675
+ if (s.caption !== void 0) fields.push(["caption", textSource(s.caption)]);
676
+ if (s.srcSet.length > 0) fields.push(["srcSet", jArray(s.srcSet.map(srcSetEntry))]);
677
+ if (s.expandable) fields.push(["expandable", bool(true)]);
678
+ return jObject(fields);
679
+ };
680
+ var mediaKind = (k) => {
681
+ if (k.$type === "Audio") return caseObj("Audio", []);
682
+ const fields = [];
683
+ if (k.autoplay) fields.push(["autoplay", bool(true)]);
684
+ if (k.poster !== void 0) fields.push(["poster", binding(k.poster)]);
685
+ return caseObj("Video", fields);
686
+ };
687
+ var mediaSpec = (s) => {
688
+ const fields = [];
689
+ if (!s.controls) fields.push(["controls", bool(false)]);
690
+ fields.push(["kind", mediaKind(s.kind)]);
691
+ fields.push(["label", textSource(s.label)]);
692
+ if (s.loop) fields.push(["loop", bool(true)]);
693
+ fields.push(["src", binding(s.src)]);
694
+ return jObject(fields);
695
+ };
662
696
  var listSpec = (s) => jObject([
663
697
  ["items", jArray(s.items.map(textSource))],
664
698
  ["ordered", bool(s.ordered)]
@@ -867,6 +901,8 @@ var displayKind = (d) => {
867
901
  return hoistSpec("Link", linkSpec(d.spec));
868
902
  case "Image":
869
903
  return hoistSpec("Image", imageSpec(d.spec));
904
+ case "Media":
905
+ return hoistSpec("Media", mediaSpec(d.spec));
870
906
  case "List":
871
907
  return hoistSpec("List", listSpec(d.spec));
872
908
  case "Toast":
@@ -994,6 +1030,20 @@ var formFieldKind = (autoBind, k) => {
994
1030
  return assertNever(k);
995
1031
  }
996
1032
  };
1033
+ var compareRule = (c) => jObject([
1034
+ ["against", binding(c.against)],
1035
+ ["op", str(c.op)]
1036
+ ]);
1037
+ var fieldRule = (r) => {
1038
+ const fields = [];
1039
+ if (r.compare !== void 0) fields.push(["compare", compareRule(r.compare)]);
1040
+ if (r.format !== void 0) fields.push(["format", str(r.format)]);
1041
+ if (r.maxLength !== void 0) fields.push(["maxLength", intLit(r.maxLength)]);
1042
+ if (r.message !== void 0) fields.push(["message", textSource(r.message)]);
1043
+ if (r.minLength !== void 0) fields.push(["minLength", intLit(r.minLength)]);
1044
+ if (r.pattern !== void 0) fields.push(["pattern", str(r.pattern)]);
1045
+ return jObject(fields);
1046
+ };
997
1047
  var formField = (f) => {
998
1048
  const fields = [
999
1049
  ["id", str(f.id)],
@@ -1002,6 +1052,7 @@ var formField = (f) => {
1002
1052
  ["required", bool(f.required)]
1003
1053
  ];
1004
1054
  if (f.help !== void 0) fields.push(["help", textSource(f.help)]);
1055
+ if (f.rule !== void 0) fields.push(["rule", fieldRule(f.rule)]);
1005
1056
  return jObject(fields);
1006
1057
  };
1007
1058
  var formSpec = (s) => {
@@ -1179,6 +1230,8 @@ var gridSpec = (s) => {
1179
1230
  ["columns", jArray(s.columns.map(columnErased))],
1180
1231
  // 0.2.0 omitted-when-false.
1181
1232
  ...s.editable ? [["editable", bool(true)]] : [],
1233
+ // Phase 934 — omit-when-false, exactly as `editable` above.
1234
+ ...s.reorderable ? [["reorderable", bool(true)]] : [],
1182
1235
  // fuaran#665 — rows are a typed Static payload now, not the opaque residual.
1183
1236
  ["source", binding(s.source, staticRowSeq)]
1184
1237
  ];
@@ -1267,6 +1320,11 @@ var boxLayout = (l) => {
1267
1320
  if (l.templateColumns !== void 0) fields.push(["templateColumns", str(l.templateColumns)]);
1268
1321
  return caseObj("Grid", fields);
1269
1322
  }
1323
+ case "Masonry": {
1324
+ const fields = [["cols", intLit(l.cols)]];
1325
+ if (l.gap !== void 0) fields.push(["gap", intLit(l.gap)]);
1326
+ return caseObj("Masonry", fields);
1327
+ }
1270
1328
  case "Auto":
1271
1329
  return caseObj("Auto", []);
1272
1330
  default:
@@ -2679,8 +2737,6 @@ var stepParams = (t) => {
2679
2737
  var pipelineParams = (pipeline) => [
2680
2738
  ...new Set(pipeline.flatMap((t) => stepParams(t)))
2681
2739
  ];
2682
-
2683
- // src/parse.ts
2684
2740
  var peek = (s) => s.pos < s.text.length ? s.text[s.pos] : " ";
2685
2741
  var advance = (s) => {
2686
2742
  s.pos += 1;
@@ -2695,6 +2751,10 @@ var skipWs = (s) => {
2695
2751
  }
2696
2752
  }
2697
2753
  };
2754
+ var failLimit = (s, message) => ({
2755
+ ok: false,
2756
+ error: { message, offset: s.pos, limit: true }
2757
+ });
2698
2758
  var fail = (s, message) => ({
2699
2759
  ok: false,
2700
2760
  error: { message, offset: s.pos }
@@ -2717,7 +2777,14 @@ var parseStringRaw = (s) => {
2717
2777
  advance(s);
2718
2778
  if (c === '"') {
2719
2779
  return { ok: true, value: out };
2720
- } else if (c === "\\") {
2780
+ }
2781
+ if (out.length > MAX_STRING_LENGTH) {
2782
+ return failLimit(
2783
+ s,
2784
+ `string is longer than the wire limit MAX_STRING_LENGTH = ${MAX_STRING_LENGTH}`
2785
+ );
2786
+ }
2787
+ if (c === "\\") {
2721
2788
  if (s.pos >= s.text.length) return fail(s, "unterminated escape");
2722
2789
  const esc = s.text[s.pos];
2723
2790
  advance(s);
@@ -2817,6 +2884,12 @@ var parseValue = (s) => {
2817
2884
  }
2818
2885
  };
2819
2886
  var parseObjectValue = (s) => {
2887
+ if (s.depth >= MAX_JSON_DEPTH) {
2888
+ return failLimit(
2889
+ s,
2890
+ `JSON nesting deeper than the wire limit MAX_JSON_DEPTH = ${MAX_JSON_DEPTH}`
2891
+ );
2892
+ }
2820
2893
  const open = expectChar(s, "{");
2821
2894
  if (!open.ok) return open;
2822
2895
  skipWs(s);
@@ -2825,15 +2898,34 @@ var parseObjectValue = (s) => {
2825
2898
  advance(s);
2826
2899
  return { ok: true, value: { kind: "JObject", fields } };
2827
2900
  }
2901
+ s.depth += 1;
2902
+ let count = 0;
2828
2903
  for (; ; ) {
2829
2904
  skipWs(s);
2830
2905
  const keyR = parseStringRaw(s);
2831
- if (!keyR.ok) return keyR;
2906
+ if (!keyR.ok) {
2907
+ s.depth -= 1;
2908
+ return keyR;
2909
+ }
2832
2910
  skipWs(s);
2833
2911
  const colon = expectChar(s, ":");
2834
- if (!colon.ok) return colon;
2912
+ if (!colon.ok) {
2913
+ s.depth -= 1;
2914
+ return colon;
2915
+ }
2835
2916
  const valR = parseValue(s);
2836
- if (!valR.ok) return valR;
2917
+ if (!valR.ok) {
2918
+ s.depth -= 1;
2919
+ return valR;
2920
+ }
2921
+ count += 1;
2922
+ if (count > MAX_ARRAY_LENGTH) {
2923
+ s.depth -= 1;
2924
+ return failLimit(
2925
+ s,
2926
+ `object has more members than the wire limit MAX_ARRAY_LENGTH = ${MAX_ARRAY_LENGTH}`
2927
+ );
2928
+ }
2837
2929
  fields.set(keyR.value, valR.value);
2838
2930
  skipWs(s);
2839
2931
  const c = peek(s);
@@ -2841,13 +2933,21 @@ var parseObjectValue = (s) => {
2841
2933
  advance(s);
2842
2934
  } else if (c === "}") {
2843
2935
  advance(s);
2936
+ s.depth -= 1;
2844
2937
  return { ok: true, value: { kind: "JObject", fields } };
2845
2938
  } else {
2939
+ s.depth -= 1;
2846
2940
  return fail(s, `expected ',' or '}' but found '${c}'`);
2847
2941
  }
2848
2942
  }
2849
2943
  };
2850
2944
  var parseArrayValue = (s) => {
2945
+ if (s.depth >= MAX_JSON_DEPTH) {
2946
+ return failLimit(
2947
+ s,
2948
+ `JSON nesting deeper than the wire limit MAX_JSON_DEPTH = ${MAX_JSON_DEPTH}`
2949
+ );
2950
+ }
2851
2951
  const open = expectChar(s, "[");
2852
2952
  if (!open.ok) return open;
2853
2953
  skipWs(s);
@@ -2856,24 +2956,37 @@ var parseArrayValue = (s) => {
2856
2956
  advance(s);
2857
2957
  return { ok: true, value: { kind: "JArray", items } };
2858
2958
  }
2959
+ s.depth += 1;
2859
2960
  for (; ; ) {
2860
2961
  const valR = parseValue(s);
2861
- if (!valR.ok) return valR;
2962
+ if (!valR.ok) {
2963
+ s.depth -= 1;
2964
+ return valR;
2965
+ }
2862
2966
  items.push(valR.value);
2967
+ if (items.length > MAX_ARRAY_LENGTH) {
2968
+ s.depth -= 1;
2969
+ return failLimit(
2970
+ s,
2971
+ `array is longer than the wire limit MAX_ARRAY_LENGTH = ${MAX_ARRAY_LENGTH}`
2972
+ );
2973
+ }
2863
2974
  skipWs(s);
2864
2975
  const c = peek(s);
2865
2976
  if (c === ",") {
2866
2977
  advance(s);
2867
2978
  } else if (c === "]") {
2868
2979
  advance(s);
2980
+ s.depth -= 1;
2869
2981
  return { ok: true, value: { kind: "JArray", items } };
2870
2982
  } else {
2983
+ s.depth -= 1;
2871
2984
  return fail(s, `expected ',' or ']' but found '${c}'`);
2872
2985
  }
2873
2986
  }
2874
2987
  };
2875
2988
  var parse = (input) => {
2876
- const s = { text: input, pos: 0 };
2989
+ const s = { text: input, pos: 0, depth: 0 };
2877
2990
  skipWs(s);
2878
2991
  if (s.pos >= s.text.length) {
2879
2992
  return { ok: false, error: { message: "input is empty", offset: 0 } };
@@ -2891,6 +3004,7 @@ var makeError = (code, path, message, expectedShape) => ({
2891
3004
  var missingField = (path, key, expected) => makeError("MISSING_FIELD", `${path}.${key}`, `missing required field '${key}'`, expected);
2892
3005
  var wrongType = (path, expected) => makeError("WRONG_TYPE", path, `expected ${expected}`, expected);
2893
3006
  var unknownDuCase = (path, got, expected) => makeError("UNKNOWN_DU_CASE", `${path}.$type`, `unknown discriminator '${got}'`, expected);
3007
+ var unknownEnumCase = (path, got, expected) => makeError("UNKNOWN_DU_CASE", path, `unknown discriminator '${got}'`, expected);
2894
3008
  var CLOSURE2 = "<closure>";
2895
3009
  var OPAQUE2 = "<opaque>";
2896
3010
  var requireObject = (path, j) => j.kind === "JObject" ? ok(j.fields) : wrongType(path, "JSON object");
@@ -3043,7 +3157,7 @@ var decodeJValMap = (path, j) => {
3043
3157
  var bareEnum = (path, j, valid, label) => {
3044
3158
  if (j.kind !== "JString") return wrongType(path, `JSON string (${label})`);
3045
3159
  if (valid.includes(j.value)) return ok(j.value);
3046
- return unknownDuCase(path, j.value, valid.join(" | "));
3160
+ return unknownEnumCase(path, j.value, valid.join(" | "));
3047
3161
  };
3048
3162
  var ORIENTATION_ALIASES = {
3049
3163
  // CSS flex-direction prior: a row lays out horizontally, a column vertically.
@@ -3081,6 +3195,14 @@ var decodeHeadingVariant = (p, j) => {
3081
3195
  return bareEnum(p, j, ["Standard", "Eyebrow", "Caption", "Lead"], "HeadingVariant");
3082
3196
  };
3083
3197
  var decodeImageVariant = (p, j) => bareEnum(p, j, ["Default", "Avatar", "Rounded"], "ImageVariant");
3198
+ var decodeImageFit = (p, j) => bareEnum(p, j, ["Natural", "Cover", "Contain"], "ImageFit");
3199
+ var decodeImageAspect = (p, j) => bareEnum(
3200
+ p,
3201
+ j,
3202
+ ["Natural", "Square", "FourThree", "ThreeTwo", "SixteenNine"],
3203
+ "ImageAspect"
3204
+ );
3205
+ var decodeImageLoading = (p, j) => bareEnum(p, j, ["Eager", "Lazy"], "ImageLoading");
3084
3206
  var decodeScrollOrientation = (p, j) => bareEnum(p, j, ["Vertical", "Horizontal", "Both"], "ScrollOrientation");
3085
3207
  var decodeDateVariant = (p, j) => bareEnum(p, j, ["Date", "Time", "DateTime"], "DateVariant");
3086
3208
  var decodeMathDisplay = (p, j) => bareEnum(p, j, ["Inline", "Block"], "MathDisplay");
@@ -3114,6 +3236,7 @@ var decodeWeight = (p, j) => (
3114
3236
  // Compact|Standard|Spacious means density (WIRE_FORMAT.md §3.6).
3115
3237
  bareEnum(p, j, ["Compact", "Standard", "Spacious"], "StyleWeight")
3116
3238
  );
3239
+ var decodeTrendPolarity = (p, j) => bareEnum(p, j, ["HigherIsBetter", "LowerIsBetter"], "TrendPolarity");
3117
3240
  var decodeEmphasis = (p, j) => {
3118
3241
  if (j.kind === "JString" && j.value in EMPHASIS_ALIASES) return ok(EMPHASIS_ALIASES[j.value]);
3119
3242
  if (j.kind === "JBool") return ok(j.value ? "Loud" : "Normal");
@@ -4315,29 +4438,43 @@ var decodeBinding = (path, j, parseStatic = (_p, v) => ok(decodeAstValue(v)), pl
4315
4438
  if (!pipeJ.ok) return pipeJ;
4316
4439
  const liveTagAst = srcJ.value.kind === "JObject" ? srcJ.value.fields.get("$type") : void 0;
4317
4440
  const liveTag = liveTagAst !== void 0 && liveTagAst.kind === "JString" && (liveTagAst.value === "State" || liveTagAst.value === "Selection" || liveTagAst.value === "Query") ? liveTagAst.value : void 0;
4318
- const hasCarried = srcJ.value.kind === "JObject" && srcJ.value.fields.has("defaultValue");
4319
4441
  let source;
4320
- if (liveTag === void 0 || liveTag === "State" && !hasCarried) {
4442
+ if (liveTag === void 0) {
4321
4443
  const src = decodeDataSource(normaliseTransformSource(srcJ.value));
4322
4444
  if (!src.ok) return makeError("WRONG_TYPE", `${path}.source`, src.error);
4323
4445
  source = { kind: "Data", source: src.value };
4324
4446
  } else {
4325
4447
  const b2 = decodeBinding(`${path}.source`, srcJ.value, decodeJVal, void 0);
4326
4448
  if (!b2.ok) return b2;
4449
+ const liveBinding = (() => {
4450
+ const raw = b2.value;
4451
+ const declared = srcJ.value.kind === "JObject" && srcJ.value.fields.has("defaultValue");
4452
+ return raw.kind === "State" && !declared ? { ...raw, defaultValue: void 0 } : raw;
4453
+ })();
4327
4454
  if (liveTag === "State") {
4328
- const snap = decodeDataSource(normaliseTransformSource(srcJ.value));
4329
- if (!snap.ok) return makeError("WRONG_TYPE", `${path}.source`, snap.error);
4330
- source = {
4331
- kind: "Live",
4332
- binding: b2.value,
4333
- initial: snap.value
4334
- };
4455
+ const carriedJ = srcJ.value.kind === "JObject" ? srcJ.value.fields.get("defaultValue") : void 0;
4456
+ const carriesNoData = carriedJ === void 0 || carriedJ.kind === "JArray" && carriedJ.items.length === 0;
4457
+ if (carriesNoData) {
4458
+ source = {
4459
+ kind: "Live",
4460
+ binding: liveBinding,
4461
+ initial: { kind: "Embedded", table: { schema: [], columns: [] } }
4462
+ };
4463
+ } else {
4464
+ const snap = decodeDataSource(normaliseTransformSource(srcJ.value));
4465
+ if (!snap.ok) return makeError("WRONG_TYPE", `${path}.source`, snap.error);
4466
+ source = {
4467
+ kind: "Live",
4468
+ binding: liveBinding,
4469
+ initial: snap.value
4470
+ };
4471
+ }
4335
4472
  } else {
4336
4473
  const dv = srcJ.value.kind === "JObject" ? srcJ.value.fields.get("defaultValue") : void 0;
4337
4474
  const snap = dv !== void 0 ? decodeDataSource(normaliseTransformSource(dv)) : void 0;
4338
4475
  source = {
4339
4476
  kind: "Live",
4340
- binding: b2.value,
4477
+ binding: liveBinding,
4341
4478
  initial: snap !== void 0 && snap.ok ? snap.value : { kind: "Embedded", table: { schema: [], columns: [] } }
4342
4479
  };
4343
4480
  }
@@ -4494,8 +4631,10 @@ var decodeBindingArgs = (path, j) => {
4494
4631
  }
4495
4632
  return ok(out);
4496
4633
  };
4497
- var decodeBindingString = (p, j) => decodeBinding(p, j);
4498
- var decodeBindingBool = (p, j) => decodeBinding(p, j);
4634
+ var decodeBindingString = (p, j) => decodeBinding(p, j, requireString, "");
4635
+ var decodeBindingBool = (p, j) => decodeBinding(p, j, requireBool, false);
4636
+ var decodeBindingFloat = (p, j) => decodeBinding(p, j, requireFloat, 0);
4637
+ var decodeBindingInt = (p, j) => decodeBinding(p, j, requireInt, 0);
4499
4638
  var OPTIONS_PLACEHOLDER = [
4500
4639
  { value: OPAQUE2, label: { kind: "Literal", value: OPAQUE2 } }
4501
4640
  ];
@@ -4838,7 +4977,14 @@ var decodeMetricSpec = (path, j) => {
4838
4977
  const f = fo.value;
4839
4978
  const label = reqField(path, f, "label", "Metric label TextSource", decodeTextSource);
4840
4979
  if (!label.ok) return label;
4841
- const source = reqFieldAliased(path, f, "value", ["data"], "Metric value binding", decodeBinding);
4980
+ const source = reqFieldAliased(
4981
+ path,
4982
+ f,
4983
+ "value",
4984
+ ["data"],
4985
+ "Metric value binding",
4986
+ decodeBindingFloat
4987
+ );
4842
4988
  if (!source.ok) {
4843
4989
  if (source.error.message.includes("expected JSON number")) {
4844
4990
  return {
@@ -4859,10 +5005,12 @@ var decodeMetricSpec = (path, j) => {
4859
5005
  if (!weight.ok) return weight;
4860
5006
  const emphasis = optField(path, f, "emphasis", decodeEmphasis);
4861
5007
  if (!emphasis.ok) return emphasis;
4862
- const trend = optField(path, f, "trend", decodeBinding);
5008
+ const trend = optField(path, f, "trend", decodeBindingFloat);
4863
5009
  if (!trend.ok) return trend;
4864
5010
  const trendFormat = optField(path, f, "trendFormat", decodeCellFormat);
4865
5011
  if (!trendFormat.ok) return trendFormat;
5012
+ const trendPolarity = optField(path, f, "trendPolarity", decodeTrendPolarity);
5013
+ if (!trendPolarity.ok) return trendPolarity;
4866
5014
  const icon = optField(path, f, "icon", decodeIconSource);
4867
5015
  if (!icon.ok) return icon;
4868
5016
  const subtext = optField(path, f, "subtext", decodeTextSource);
@@ -4876,6 +5024,7 @@ var decodeMetricSpec = (path, j) => {
4876
5024
  emphasis: emphasis.value ?? "Normal",
4877
5025
  ...trend.value !== void 0 ? { trend: trend.value } : {},
4878
5026
  ...trendFormat.value !== void 0 ? { trendFormat: trendFormat.value } : {},
5027
+ trendPolarity: trendPolarity.value ?? "HigherIsBetter",
4879
5028
  ...icon.value !== void 0 ? { icon: icon.value } : {},
4880
5029
  ...subtext.value !== void 0 ? { subtext: subtext.value } : {}
4881
5030
  });
@@ -4904,7 +5053,7 @@ var decodeLabelValueRowSpec = (path, j) => {
4904
5053
  "value",
4905
5054
  ["data"],
4906
5055
  "row Binding<float> value",
4907
- decodeBinding
5056
+ decodeBindingFloat
4908
5057
  );
4909
5058
  if (!source.ok) return source;
4910
5059
  const format = optField(path, f, "format", decodeCellFormat);
@@ -4993,6 +5142,23 @@ var decodeLinkSpec = (path, j) => {
4993
5142
  });
4994
5143
  };
4995
5144
  var decodeLinkProtection = (p, j) => bareEnum(p, j, ["email"], "LinkProtection");
5145
+ var decodeSrcSetEntry = (path, j) => {
5146
+ const fo = requireObject(path, j);
5147
+ if (!fo.ok) return fo;
5148
+ const src = reqField(
5149
+ path,
5150
+ fo.value,
5151
+ "src",
5152
+ "srcSet entry Binding<string> src",
5153
+ decodeBindingString
5154
+ );
5155
+ if (!src.ok) return src;
5156
+ const widthJ = tryField(fo.value, "width");
5157
+ if (widthJ === void 0) return missingField(path, "width", "positive intrinsic pixel width");
5158
+ if (widthJ.kind !== "JNumber" || widthJ.value <= 0 || !Number.isInteger(widthJ.value))
5159
+ return wrongType(`${path}.width`, "JSON number (positive integer pixel width)");
5160
+ return ok({ src: src.value, width: widthJ.value });
5161
+ };
4996
5162
  var decodeImageSpec = (path, j) => {
4997
5163
  const fo = requireObject(path, j);
4998
5164
  if (!fo.ok) return fo;
@@ -5003,7 +5169,90 @@ var decodeImageSpec = (path, j) => {
5003
5169
  if (!src.ok) return src;
5004
5170
  const variant = reqField(path, f, "variant", "ImageVariant", decodeImageVariant);
5005
5171
  if (!variant.ok) return variant;
5006
- return ok({ alt: alt.value, src: src.value, variant: variant.value });
5172
+ const fitJ = tryField(f, "fit");
5173
+ const fit = fitJ === void 0 ? ok("Natural") : decodeImageFit(`${path}.fit`, fitJ);
5174
+ if (!fit.ok) return fit;
5175
+ const aspectJ = tryField(f, "aspectRatio");
5176
+ const aspectRatio = aspectJ === void 0 ? ok("Natural") : decodeImageAspect(`${path}.aspectRatio`, aspectJ);
5177
+ if (!aspectRatio.ok) return aspectRatio;
5178
+ const loadingJ = tryField(f, "loading");
5179
+ const loading = loadingJ === void 0 ? ok("Eager") : decodeImageLoading(`${path}.loading`, loadingJ);
5180
+ if (!loading.ok) return loading;
5181
+ const caption = optField(path, f, "caption", decodeTextSource);
5182
+ if (!caption.ok) return caption;
5183
+ const srcSetJ = tryField(f, "srcSet");
5184
+ const srcSet = srcSetJ === void 0 ? ok([]) : (() => {
5185
+ const arr = requireArray(`${path}.srcSet`, srcSetJ);
5186
+ if (!arr.ok) return arr;
5187
+ return traverseIndexed(
5188
+ arr.value,
5189
+ (i, el) => decodeSrcSetEntry(`${path}.srcSet[${i}]`, el)
5190
+ );
5191
+ })();
5192
+ if (!srcSet.ok) return srcSet;
5193
+ const expandableJ = tryField(f, "expandable");
5194
+ const expandable = expandableJ === void 0 ? ok(false) : requireBool(`${path}.expandable`, expandableJ);
5195
+ if (!expandable.ok) return expandable;
5196
+ return ok({
5197
+ alt: alt.value,
5198
+ src: src.value,
5199
+ variant: variant.value,
5200
+ fit: fit.value,
5201
+ aspectRatio: aspectRatio.value,
5202
+ loading: loading.value,
5203
+ srcSet: srcSet.value,
5204
+ expandable: expandable.value,
5205
+ ...caption.value !== void 0 ? { caption: caption.value } : {}
5206
+ });
5207
+ };
5208
+ var decodeMediaKind = (path, j) => {
5209
+ const fo = requireObject(path, j);
5210
+ if (!fo.ok) return fo;
5211
+ const f = fo.value;
5212
+ const d = requireDiscriminator(path, f);
5213
+ if (!d.ok) return d;
5214
+ switch (d.value) {
5215
+ case "Video": {
5216
+ const autoplayJ = tryField(f, "autoplay");
5217
+ const autoplay = autoplayJ === void 0 ? ok(false) : requireBool(`${path}.autoplay`, autoplayJ);
5218
+ if (!autoplay.ok) return autoplay;
5219
+ const poster = optField(path, f, "poster", decodeBindingString);
5220
+ if (!poster.ok) return poster;
5221
+ return ok({
5222
+ $type: "Video",
5223
+ autoplay: autoplay.value,
5224
+ ...poster.value !== void 0 ? { poster: poster.value } : {}
5225
+ });
5226
+ }
5227
+ case "Audio":
5228
+ return ok({ $type: "Audio" });
5229
+ default:
5230
+ return unknownDuCase(path, d.value, "Video | Audio");
5231
+ }
5232
+ };
5233
+ var decodeMediaSpec = (path, j) => {
5234
+ const fo = requireObject(path, j);
5235
+ if (!fo.ok) return fo;
5236
+ const f = fo.value;
5237
+ const src = reqField(path, f, "src", "Media Binding<string> Src", decodeBindingString);
5238
+ if (!src.ok) return src;
5239
+ const label = reqField(path, f, "label", "Media accessible label TextSource", decodeTextSource);
5240
+ if (!label.ok) return label;
5241
+ const kind = reqField(path, f, "kind", "MediaKind (Video | Audio)", decodeMediaKind);
5242
+ if (!kind.ok) return kind;
5243
+ const controlsJ = tryField(f, "controls");
5244
+ const controls = controlsJ === void 0 ? ok(true) : requireBool(`${path}.controls`, controlsJ);
5245
+ if (!controls.ok) return controls;
5246
+ const loopJ = tryField(f, "loop");
5247
+ const loop = loopJ === void 0 ? ok(false) : requireBool(`${path}.loop`, loopJ);
5248
+ if (!loop.ok) return loop;
5249
+ return ok({
5250
+ src: src.value,
5251
+ label: label.value,
5252
+ controls: controls.value,
5253
+ loop: loop.value,
5254
+ kind: kind.value
5255
+ });
5007
5256
  };
5008
5257
  var decodeListSpec = (path, j) => {
5009
5258
  const fo = requireObject(path, j);
@@ -5147,7 +5396,7 @@ var decodeProgressSpec = (path, j) => {
5147
5396
  const fo = requireObject(path, j);
5148
5397
  if (!fo.ok) return fo;
5149
5398
  const f = fo.value;
5150
- const fraction = reqField(path, f, "fraction", "Progress fraction binding", decodeBinding);
5399
+ const fraction = reqField(path, f, "fraction", "Progress fraction binding", decodeBindingFloat);
5151
5400
  if (!fraction.ok) return fraction;
5152
5401
  const indeterminate = optField(path, f, "indeterminate", requireBool);
5153
5402
  if (!indeterminate.ok) return indeterminate;
@@ -5197,9 +5446,9 @@ var decodeDrawStyle = (path, j) => {
5197
5446
  if (!fill.ok) return fill;
5198
5447
  const stroke = optField(path, f, "stroke", decodeBindingString);
5199
5448
  if (!stroke.ok) return stroke;
5200
- const strokeWidth = optField(path, f, "strokeWidth", decodeBinding);
5449
+ const strokeWidth = optField(path, f, "strokeWidth", decodeBindingFloat);
5201
5450
  if (!strokeWidth.ok) return strokeWidth;
5202
- const opacity = optField(path, f, "opacity", decodeBinding);
5451
+ const opacity = optField(path, f, "opacity", decodeBindingFloat);
5203
5452
  if (!opacity.ok) return opacity;
5204
5453
  const textAnchor = optField(path, f, "textAnchor", decodeTextAnchor);
5205
5454
  if (!textAnchor.ok) return textAnchor;
@@ -5478,6 +5727,10 @@ var decodeDisplayKind = (path, j) => {
5478
5727
  const r = decodeImageSpec(path, j);
5479
5728
  return r.ok ? ok({ kind: "Image", spec: r.value }) : r;
5480
5729
  }
5730
+ case "Media": {
5731
+ const r = decodeMediaSpec(path, j);
5732
+ return r.ok ? ok({ kind: "Media", spec: r.value }) : r;
5733
+ }
5481
5734
  case "List": {
5482
5735
  const r = decodeListSpec(path, j);
5483
5736
  return r.ok ? ok({ kind: "List", spec: r.value }) : r;
@@ -5529,7 +5782,11 @@ var decodeFormFieldKind = (autoBind, path, j) => {
5529
5782
  return v.ok ? ok({ kind: "Text", value: v.value, ...onChangeField }) : v;
5530
5783
  }
5531
5784
  case "Number": {
5532
- const v = valueOr(decodeBinding, controlValueDefaults.number, "Number value binding");
5785
+ const v = valueOr(
5786
+ decodeBindingFloat,
5787
+ controlValueDefaults.number,
5788
+ "Number value binding"
5789
+ );
5533
5790
  return v.ok ? ok({ kind: "Number", value: v.value, ...onChangeField }) : v;
5534
5791
  }
5535
5792
  case "Checkbox": {
@@ -5581,7 +5838,7 @@ var decodeFormFieldKind = (autoBind, path, j) => {
5581
5838
  }
5582
5839
  case "RangedNumber": {
5583
5840
  const value = valueOr(
5584
- decodeBinding,
5841
+ decodeBindingFloat,
5585
5842
  controlValueDefaults.number,
5586
5843
  "RangedNumber value binding"
5587
5844
  );
@@ -5695,6 +5952,77 @@ var decodeFormFieldKind = (autoBind, path, j) => {
5695
5952
  return unknownDuCase(path, d.value, WRONG_FORM_FIELD_KIND_HINT);
5696
5953
  }
5697
5954
  };
5955
+ var TEXT_FORMATS = ["email", "url", "tel"];
5956
+ var COMPARE_OPS = ["eq", "neq", "lt", "lte", "gt", "gte"];
5957
+ var decodeTextFormat = (path, j) => bareEnum(path, j, TEXT_FORMATS, "TextFormat");
5958
+ var decodeCompareOp = (path, j) => bareEnum(path, j, COMPARE_OPS, "CompareOp");
5959
+ var decodeCompareRule = (path, j) => {
5960
+ const fo = requireObject(path, j);
5961
+ if (!fo.ok) return fo;
5962
+ const f = fo.value;
5963
+ const op = reqField(path, f, "op", "CompareOp", decodeCompareOp);
5964
+ if (!op.ok) return op;
5965
+ const against = reqField(path, f, "against", "Binding", (p, v) => decodeBinding(p, v));
5966
+ if (!against.ok) return against;
5967
+ return ok({ op: op.value, against: against.value });
5968
+ };
5969
+ var decodeFieldRule = (path, j) => {
5970
+ const fo = requireObject(path, j);
5971
+ if (!fo.ok) return fo;
5972
+ const f = fo.value;
5973
+ const format = optField(path, f, "format", decodeTextFormat);
5974
+ if (!format.ok) return format;
5975
+ const pattern = optField(path, f, "pattern", requireString);
5976
+ if (!pattern.ok) return pattern;
5977
+ const minLength = optField(path, f, "minLength", requireInt);
5978
+ if (!minLength.ok) return minLength;
5979
+ const maxLength = optField(path, f, "maxLength", requireInt);
5980
+ if (!maxLength.ok) return maxLength;
5981
+ const compare = optField(path, f, "compare", decodeCompareRule);
5982
+ if (!compare.ok) return compare;
5983
+ const message = optField(path, f, "message", decodeTextSource);
5984
+ if (!message.ok) return message;
5985
+ const constrains = format.value !== void 0 || pattern.value !== void 0 || minLength.value !== void 0 || maxLength.value !== void 0 || compare.value !== void 0;
5986
+ if (!constrains)
5987
+ return makeError(
5988
+ "WRONG_TYPE",
5989
+ path,
5990
+ "a rule that constrains nothing is a defect, not a no-op \u2014 declare at least one of format / pattern / minLength / maxLength / compare, or omit 'rule' entirely",
5991
+ "FieldRule with at least one constraint slot"
5992
+ );
5993
+ if (minLength.value !== void 0 && maxLength.value !== void 0 && minLength.value > maxLength.value)
5994
+ return makeError(
5995
+ "WRONG_TYPE",
5996
+ path,
5997
+ `minLength ${minLength.value} is above maxLength ${maxLength.value} \u2014 an inverted length bound admits no value at all, so the field could never be submitted`,
5998
+ "minLength <= maxLength"
5999
+ );
6000
+ return ok({
6001
+ ...format.value !== void 0 ? { format: format.value } : {},
6002
+ ...pattern.value !== void 0 ? { pattern: pattern.value } : {},
6003
+ ...minLength.value !== void 0 ? { minLength: minLength.value } : {},
6004
+ ...maxLength.value !== void 0 ? { maxLength: maxLength.value } : {},
6005
+ ...compare.value !== void 0 ? { compare: compare.value } : {},
6006
+ ...message.value !== void 0 ? { message: message.value } : {}
6007
+ });
6008
+ };
6009
+ var FORM_FIELD_NEAR_MISSES = [
6010
+ ["validation", "rule"],
6011
+ ["constraints", "rule"],
6012
+ ["validate", "rule"]
6013
+ ];
6014
+ var checkFormFieldNearMisses = (path, f) => {
6015
+ for (const [name, canonical] of FORM_FIELD_NEAR_MISSES) {
6016
+ if (tryField(f, name) !== void 0)
6017
+ return makeError(
6018
+ "WRONG_TYPE",
6019
+ `${path}.${name}`,
6020
+ `'${name}' is not part of the form vocabulary \u2014 it would be ignored, not honoured, and the field would accept anything`,
6021
+ canonical
6022
+ );
6023
+ }
6024
+ return ok(void 0);
6025
+ };
5698
6026
  var decodeFormField = (path, j) => {
5699
6027
  const fo = requireObject(path, j);
5700
6028
  if (!fo.ok) return fo;
@@ -5716,12 +6044,17 @@ var decodeFormField = (path, j) => {
5716
6044
  if (!required.ok) return required;
5717
6045
  const help = optField(path, f, "help", decodeTextSource);
5718
6046
  if (!help.ok) return help;
6047
+ const nm = checkFormFieldNearMisses(path, f);
6048
+ if (!nm.ok) return nm;
6049
+ const rule = optField(path, f, "rule", decodeFieldRule);
6050
+ if (!rule.ok) return rule;
5719
6051
  return ok({
5720
6052
  id: id.value,
5721
6053
  kind: kind.value,
5722
6054
  label: label.value,
5723
6055
  required: required.value,
5724
- ...help.value !== void 0 ? { help: help.value } : {}
6056
+ ...help.value !== void 0 ? { help: help.value } : {},
6057
+ ...rule.value !== void 0 ? { rule: rule.value } : {}
5725
6058
  });
5726
6059
  };
5727
6060
  var decodeFormSpec = (path, j) => {
@@ -6215,6 +6548,8 @@ var decodeGridSpec = (path, j) => {
6215
6548
  if (!columns.ok) return columns;
6216
6549
  const editable = optField(path, f, "editable", requireBool);
6217
6550
  if (!editable.ok) return editable;
6551
+ const reorderable = optField(path, f, "reorderable", requireBool);
6552
+ if (!reorderable.ok) return reorderable;
6218
6553
  const source = reqFieldAliased(
6219
6554
  path,
6220
6555
  f,
@@ -6280,6 +6615,7 @@ var decodeGridSpec = (path, j) => {
6280
6615
  return ok({
6281
6616
  columns: columns.value,
6282
6617
  editable: editable.value ?? false,
6618
+ reorderable: reorderable.value ?? false,
6283
6619
  source: source.value,
6284
6620
  ...hasRowClick ? { onRowClick: () => placeholderAction } : {},
6285
6621
  ...hasRowKey ? { rowKey: () => CLOSURE2 } : {},
@@ -6457,10 +6793,23 @@ var decodeBoxLayout = (path, j) => {
6457
6793
  ...templateColumns.value !== void 0 ? { templateColumns: templateColumns.value } : {}
6458
6794
  });
6459
6795
  }
6796
+ case "Masonry": {
6797
+ const colsJ = tryField(f, "cols") ?? tryField(f, "columns");
6798
+ if (colsJ === void 0) return missingField(path, "cols", "positive integer column count");
6799
+ if (colsJ.kind !== "JNumber" || colsJ.value <= 0 || !Number.isInteger(colsJ.value))
6800
+ return wrongType(`${path}.cols`, "JSON number (positive integer column count)");
6801
+ const masonryGap = optField(path, f, "gap", requireInt);
6802
+ if (!masonryGap.ok) return masonryGap;
6803
+ return ok({
6804
+ kind: "Masonry",
6805
+ cols: colsJ.value,
6806
+ ...masonryGap.value !== void 0 ? { gap: masonryGap.value } : {}
6807
+ });
6808
+ }
6460
6809
  case "Auto":
6461
6810
  return ok({ kind: "Auto" });
6462
6811
  default:
6463
- return unknownDuCase(path, d.value, "Flex | Grid | Auto");
6812
+ return unknownDuCase(path, d.value, "Flex | Grid | Masonry | Auto");
6464
6813
  }
6465
6814
  };
6466
6815
  var decodeBoxRole = (path, j) => {
@@ -6473,7 +6822,7 @@ var decodeBoxRole = (path, j) => {
6473
6822
  case "Separator":
6474
6823
  return ok(s.value);
6475
6824
  default:
6476
- return unknownDuCase(path, s.value, "Group | Card | Dashboard | Separator");
6825
+ return unknownEnumCase(path, s.value, "Group | Card | Dashboard | Separator");
6477
6826
  }
6478
6827
  };
6479
6828
  var decodeBox = (path, j) => {
@@ -6556,7 +6905,7 @@ var decodeTabsSpec = (path, j) => {
6556
6905
  }
6557
6906
  const activeTag = optField(path, f, "activeTag", decodeBindingString);
6558
6907
  if (!activeTag.ok) return activeTag;
6559
- const activeIndex = optField(path, f, "activeIndex", decodeBinding);
6908
+ const activeIndex = optField(path, f, "activeIndex", decodeBindingInt);
6560
6909
  if (!activeIndex.ok) return activeIndex;
6561
6910
  return ok({
6562
6911
  children: children.value,
@@ -6573,7 +6922,7 @@ var decodeStepperSpec = (path, j) => {
6573
6922
  const fo = requireObject(path, j);
6574
6923
  if (!fo.ok) return fo;
6575
6924
  const f = fo.value;
6576
- const activeStep = reqField(path, f, "activeStep", "activeStep binding", decodeBinding);
6925
+ const activeStep = reqField(path, f, "activeStep", "activeStep binding", decodeBindingInt);
6577
6926
  if (!activeStep.ok) return activeStep;
6578
6927
  const children = decodeChildren(path, f);
6579
6928
  if (!children.ok) return children;
@@ -6738,7 +7087,7 @@ var decodeContentHash = (path, j) => {
6738
7087
  if (!strictnessR.ok) return strictnessR;
6739
7088
  const s = strictnessR.value;
6740
7089
  if (s !== "StrictReplay" && s !== "AdvisoryWarning" && s !== "Enforced") {
6741
- return unknownDuCase(`${path}.strictness`, s, "StrictReplay | AdvisoryWarning | Enforced");
7090
+ return unknownEnumCase(`${path}.strictness`, s, "StrictReplay | AdvisoryWarning | Enforced");
6742
7091
  }
6743
7092
  return ok({ algorithm: algorithm.value, hash: hash.value, strictness: s });
6744
7093
  };
@@ -6869,11 +7218,11 @@ var decodeEffectClass = (path, j) => {
6869
7218
  const host = reqField(path, fo.value, "hostEffect", "EffectClass hostEffect", requireString);
6870
7219
  if (!host.ok) return host;
6871
7220
  if (host.value !== "Pure" && host.value !== "ReadsHost" && host.value !== "WritesHost")
6872
- return unknownDuCase(`${path}.hostEffect`, host.value, "Pure | ReadsHost | WritesHost");
7221
+ return unknownEnumCase(`${path}.hostEffect`, host.value, "Pure | ReadsHost | WritesHost");
6873
7222
  const det = reqField(path, fo.value, "determinism", "EffectClass determinism", requireString);
6874
7223
  if (!det.ok) return det;
6875
7224
  if (det.value !== "Deterministic" && det.value !== "Clock" && det.value !== "Random" && det.value !== "Network")
6876
- return unknownDuCase(
7225
+ return unknownEnumCase(
6877
7226
  `${path}.determinism`,
6878
7227
  det.value,
6879
7228
  "Deterministic | Clock | Random | Network"
@@ -6893,6 +7242,14 @@ var decodeNodeKind = (path, j) => {
6893
7242
  const f = fo.value;
6894
7243
  const d = requireDiscriminator(path, f);
6895
7244
  if (!d.ok) return d;
7245
+ if (narrows(walkPolicy) && NODE_KIND_NAMES.includes(d.value) && !admits(walkPolicy, d.value)) {
7246
+ return makeError(
7247
+ "KIND_NOT_ADMITTED",
7248
+ `${path}.$type`,
7249
+ `node kind '${d.value}' is not admitted by decode policy '${walkPolicy.identity}'`,
7250
+ policyHint(walkPolicy)
7251
+ );
7252
+ }
6896
7253
  switch (d.value) {
6897
7254
  // The four behavioural categories are flat on the wire (WIRE_FORMAT §3.2):
6898
7255
  // the `kind` object carries the primitive discriminator directly, so route
@@ -6922,6 +7279,7 @@ var decodeNodeKind = (path, j) => {
6922
7279
  case "Fact":
6923
7280
  case "Link":
6924
7281
  case "Image":
7282
+ case "Media":
6925
7283
  case "List":
6926
7284
  case "Toast":
6927
7285
  case "CodeBlock":
@@ -7197,10 +7555,54 @@ var decodeSemanticStyle = (path, j) => {
7197
7555
  voice: voice.value ?? "Default"
7198
7556
  });
7199
7557
  };
7558
+ var A11Y_NEAR_MISSES = [
7559
+ [
7560
+ "aria-label",
7561
+ "label \u2014 the accessible name, a Binding<string> (a bare string is the \xA73.6 shorthand)"
7562
+ ],
7563
+ [
7564
+ "ariaLabel",
7565
+ "label \u2014 the accessible name, a Binding<string> (a bare string is the \xA73.6 shorthand)"
7566
+ ],
7567
+ ["aria-labelledby", "labelledBy \u2014 the id of a sibling node whose text carries the name"],
7568
+ ["ariaLabelledBy", "labelledBy \u2014 the id of a sibling node whose text carries the name"],
7569
+ [
7570
+ "labelledby",
7571
+ "labelledBy \u2014 the slot name is camelCase on the wire, not the ARIA attribute spelling"
7572
+ ],
7573
+ ["aria-describedby", "describedBy \u2014 the id of a sibling node whose text carries the description"],
7574
+ ["ariaDescribedBy", "describedBy \u2014 the id of a sibling node whose text carries the description"],
7575
+ [
7576
+ "describedby",
7577
+ "describedBy \u2014 the slot name is camelCase on the wire, not the ARIA attribute spelling"
7578
+ ],
7579
+ ["aria-role", "role \u2014 the ARIA role NAME as a bare string"],
7580
+ ["ariaRole", "role \u2014 the ARIA role NAME as a bare string"],
7581
+ ["aria-live", 'liveRegion \u2014 the closed token set "polite" / "assertive" / "off"'],
7582
+ ["ariaLive", 'liveRegion \u2014 the closed token set "polite" / "assertive" / "off"'],
7583
+ ["live", 'liveRegion \u2014 the closed token set "polite" / "assertive" / "off"'],
7584
+ ["liveregion", 'liveRegion \u2014 the closed token set "polite" / "assertive" / "off"'],
7585
+ ["aria-hidden", "hidden \u2014 a Binding<bool> (a bare bool is the \xA73.6 shorthand)"],
7586
+ ["ariaHidden", "hidden \u2014 a Binding<bool> (a bare bool is the \xA73.6 shorthand)"]
7587
+ ];
7588
+ var checkA11yNearMisses = (path, f) => {
7589
+ for (const [name, canonical] of A11Y_NEAR_MISSES) {
7590
+ if (tryField(f, name) !== void 0)
7591
+ return makeError(
7592
+ "WRONG_TYPE",
7593
+ `${path}.${name}`,
7594
+ `'${name}' is not part of the accessibility vocabulary \u2014 it would be ignored, not honoured, and the intent would reach assistive technology as nothing at all`,
7595
+ canonical
7596
+ );
7597
+ }
7598
+ return ok(void 0);
7599
+ };
7200
7600
  var decodeAccessibility = (path, j) => {
7201
7601
  const fo = requireObject(path, j);
7202
7602
  if (!fo.ok) return fo;
7203
7603
  const f = fo.value;
7604
+ const nearMiss2 = checkA11yNearMisses(path, f);
7605
+ if (!nearMiss2.ok) return nearMiss2;
7204
7606
  const label = optField(path, f, "label", decodeBindingString);
7205
7607
  if (!label.ok) return label;
7206
7608
  const labelledBy = optField(path, f, "labelledBy", requireString);
@@ -7245,7 +7647,39 @@ var placeholderClosureNode = {
7245
7647
  voice: "Default"
7246
7648
  }
7247
7649
  };
7650
+ var walkDepth = 0;
7651
+ var walkNodes = 0;
7652
+ var opDepth = 0;
7653
+ var walkPolicy = admitAll;
7654
+ var resetWalk = (policy = admitAll) => {
7655
+ walkDepth = 0;
7656
+ walkNodes = 0;
7657
+ opDepth = 0;
7658
+ walkPolicy = policy;
7659
+ };
7660
+ var limitError = (path, message, expected) => makeError("LIMIT_EXCEEDED", path, message, expected);
7248
7661
  var decodeNodeAst = (path, j) => {
7662
+ if (walkDepth >= MAX_NODE_DEPTH) {
7663
+ return limitError(
7664
+ path,
7665
+ `node nesting deeper than the wire limit MAX_NODE_DEPTH = ${MAX_NODE_DEPTH}`,
7666
+ `a tree nesting nodes no more than ${MAX_NODE_DEPTH} levels deep`
7667
+ );
7668
+ }
7669
+ walkNodes += 1;
7670
+ if (walkNodes > MAX_NODES) {
7671
+ return limitError(
7672
+ path,
7673
+ `the document holds more than the wire limit MAX_NODES = ${MAX_NODES} nodes`,
7674
+ `a tree of no more than ${MAX_NODES} nodes in total`
7675
+ );
7676
+ }
7677
+ walkDepth += 1;
7678
+ const r = decodeNodeAstInner(path, j);
7679
+ walkDepth -= 1;
7680
+ return r;
7681
+ };
7682
+ var decodeNodeAstInner = (path, j) => {
7249
7683
  const fo = requireObject(path, j);
7250
7684
  if (!fo.ok) return fo;
7251
7685
  const f = fo.value;
@@ -7273,6 +7707,25 @@ var decodeNodeAst = (path, j) => {
7273
7707
  });
7274
7708
  };
7275
7709
  var decodeTreeOpAst = (path, j) => {
7710
+ if (opDepth >= MAX_NODE_DEPTH) {
7711
+ return limitError(
7712
+ path,
7713
+ `op nesting deeper than the wire limit MAX_NODE_DEPTH = ${MAX_NODE_DEPTH}`,
7714
+ `a Batch nesting ops no more than ${MAX_NODE_DEPTH} levels deep`
7715
+ );
7716
+ }
7717
+ opDepth += 1;
7718
+ const r = decodeTreeOpAstInner(path, j);
7719
+ opDepth -= 1;
7720
+ return r;
7721
+ };
7722
+ var retiredPositionalField = (path, f, name, opKind) => tryField(f, name) !== void 0 ? makeError(
7723
+ "WRONG_TYPE",
7724
+ `${path}.${name}`,
7725
+ `'${name}' was removed from the wire format \u2014 ${opKind} appends, and order is stated by naming ids with ReorderChildren`,
7726
+ "a Batch of the structural op followed by ReorderChildren"
7727
+ ) : ok(void 0);
7728
+ var decodeTreeOpAstInner = (path, j) => {
7276
7729
  const fo = requireObject(path, j);
7277
7730
  if (!fo.ok) return fo;
7278
7731
  const f = fo.value;
@@ -7325,6 +7778,8 @@ var decodeTreeOpAst = (path, j) => {
7325
7778
  return state.ok ? ok({ kind: "UpdateState", target: t.value, state: state.value }) : state;
7326
7779
  }
7327
7780
  case "InsertChild": {
7781
+ const retired = retiredPositionalField(path, f, "position", "InsertChild");
7782
+ if (!retired.ok) return retired;
7328
7783
  const parentJ = reqField(path, f, "parentId", "parent NodeId", requireString);
7329
7784
  if (!parentJ.ok) return parentJ;
7330
7785
  const child = reqField(path, f, "child", "child Node object", decodeNodeAst);
@@ -7339,6 +7794,8 @@ var decodeTreeOpAst = (path, j) => {
7339
7794
  return t.ok ? ok({ kind: "RemoveNode", target: t.value }) : t;
7340
7795
  }
7341
7796
  case "MoveNode": {
7797
+ const retired = retiredPositionalField(path, f, "newPosition", "MoveNode");
7798
+ if (!retired.ok) return retired;
7342
7799
  const t = target();
7343
7800
  if (!t.ok) return t;
7344
7801
  const newParent = reqField(path, f, "newParentId", "new parent NodeId", requireString);
@@ -7420,6 +7877,8 @@ var coerce = {
7420
7877
  tone: (v) => viaAst(v, decodeTone),
7421
7878
  weight: (v) => viaAst(v, decodeWeight),
7422
7879
  emphasis: (v) => viaAst(v, decodeEmphasis),
7880
+ /** `Metric.TrendPolarity` (Phase 867) - the UpdateProp twin of `decodeTrendPolarity`. */
7881
+ trendPolarity: (v) => viaAst(v, decodeTrendPolarity),
7423
7882
  /**
7424
7883
  * The behavioural `emphasis` BOOL on Fact / LabelValueRow — the UpdateProp
7425
7884
  * twin of `decodeEmphasisFlag`, so a TreeOp edit gets the same
@@ -7440,13 +7899,18 @@ var invalidJson = (parseMessage) => makeError(
7440
7899
  `input is not valid JSON: ${parseMessage}`,
7441
7900
  "well-formed JSON object per the canonical-JSON shape"
7442
7901
  );
7443
- var decodeNode = (json) => {
7902
+ var parseFailure = (e) => e.limit === true ? makeError("LIMIT_EXCEEDED", "$", e.message, "a document within the WIRE_FORMAT \xA721 limits") : invalidJson(e.message);
7903
+ var decodeNode = (json, policy) => {
7444
7904
  const parsed = parse(json);
7445
- return parsed.ok ? decodeNodeAst("$", parsed.value) : invalidJson(parsed.error.message);
7905
+ if (!parsed.ok) return parseFailure(parsed.error);
7906
+ resetWalk(policy);
7907
+ return decodeNodeAst("$", parsed.value);
7446
7908
  };
7447
- var decodeOp = (json) => {
7909
+ var decodeOp = (json, policy) => {
7448
7910
  const parsed = parse(json);
7449
- return parsed.ok ? decodeTreeOpAst("$", parsed.value) : invalidJson(parsed.error.message);
7911
+ if (!parsed.ok) return parseFailure(parsed.error);
7912
+ resetWalk(policy);
7913
+ return decodeTreeOpAst("$", parsed.value);
7450
7914
  };
7451
7915
 
7452
7916
  // src/apply.ts
@@ -7613,6 +8077,11 @@ var updateField = (field2, value, kind) => {
7613
8077
  coerce.cellFormat(value),
7614
8078
  (x) => disp({ kind: "Metric", spec: { ...s, trendFormat: x } })
7615
8079
  );
8080
+ case "TrendPolarity":
8081
+ return patch(
8082
+ coerce.trendPolarity(value),
8083
+ (x) => disp({ kind: "Metric", spec: { ...s, trendPolarity: x } })
8084
+ );
7616
8085
  case "Icon":
7617
8086
  return patch(
7618
8087
  coerce.iconSource(value),
@@ -7896,6 +8365,12 @@ var updateField = (field2, value, kind) => {
7896
8365
  (x) => lay({ kind: "Box", spec: { ...s, layout: { ...mode, cols: x } } })
7897
8366
  );
7898
8367
  }
8368
+ if (field2 === "Cols" && mode.kind === "Masonry") {
8369
+ return patch(
8370
+ coerce.int(value),
8371
+ (x) => lay({ kind: "Box", spec: { ...s, layout: { ...mode, cols: x } } })
8372
+ );
8373
+ }
7899
8374
  if (field2 === "TemplateColumns" && mode.kind === "Grid") {
7900
8375
  return patch(
7901
8376
  coerce.string(value),
@@ -9760,7 +10235,61 @@ var validateAnswerDocument = (json) => {
9760
10235
  if (!answer.ok) return answer;
9761
10236
  return validateAnswerAt("$.answer", contract.value, answer.value);
9762
10237
  };
10238
+ var HOST_RESERVED_PREFIX = "host.";
10239
+ var isHostReserved = (key) => typeof key === "string" && key.startsWith(HOST_RESERVED_PREFIX);
10240
+ var isPlainObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
10241
+ var isStateDeclaration = (v) => isPlainObject(v) && v["kind"] === "State" && typeof v["key"] === "string" && "defaultValue" in v && v["defaultValue"] !== void 0;
10242
+ var controlDefaults = Object.values(controlValueDefaults);
10243
+ var deepEqual = (a, b) => {
10244
+ try {
10245
+ return JSON.stringify(a) === JSON.stringify(b);
10246
+ } catch {
10247
+ return false;
10248
+ }
10249
+ };
10250
+ var isAutoBoundFieldValue = (binding2, fieldId) => binding2.key === fieldId && controlDefaults.some((d) => deepEqual(d, binding2.defaultValue));
10251
+ var isEmptyDeclaration = (value) => {
10252
+ if (Array.isArray(value)) return value.length === 0;
10253
+ if (isPlainObject(value)) {
10254
+ const columns = value["columns"];
10255
+ if (isPlainObject(columns)) return Object.keys(columns).length === 0;
10256
+ }
10257
+ return false;
10258
+ };
10259
+ var collectStateSeeds = (tree) => {
10260
+ const seeds = {};
10261
+ const seen = /* @__PURE__ */ new Set();
10262
+ const visit = (value, autoBindFieldId) => {
10263
+ if (value === null || typeof value !== "object") return;
10264
+ if (seen.has(value)) return;
10265
+ seen.add(value);
10266
+ if (Array.isArray(value)) {
10267
+ for (const item of value) visit(item, autoBindFieldId);
10268
+ return;
10269
+ }
10270
+ const obj = value;
10271
+ if (isStateDeclaration(obj)) {
10272
+ const key = obj.key;
10273
+ const shouldSkip = isHostReserved(key) || Object.prototype.hasOwnProperty.call(seeds, key) || isEmptyDeclaration(obj.defaultValue) || autoBindFieldId !== void 0 && isAutoBoundFieldValue(obj, autoBindFieldId);
10274
+ if (!shouldSkip) seeds[key] = obj.defaultValue;
10275
+ }
10276
+ const record = obj;
10277
+ const ownId = record["id"];
10278
+ const fieldId = typeof ownId === "string" && typeof record["required"] === "boolean" ? ownId : void 0;
10279
+ for (const [k, v] of Object.entries(obj)) {
10280
+ const established = k === "kind" && fieldId !== void 0 ? fieldId : void 0;
10281
+ visit(v, established ?? autoBindFieldId);
10282
+ }
10283
+ };
10284
+ visit(tree, void 0);
10285
+ return seeds;
10286
+ };
10287
+ var withStateSeeds = (tree, sources) => {
10288
+ const seeds = collectStateSeeds(tree);
10289
+ if (Object.keys(seeds).length === 0) return sources;
10290
+ return { ...sources, state: { ...seeds, ...sources.state ?? {} } };
10291
+ };
9763
10292
 
9764
- export { ELICITATION_KEY, ELICITATION_VERSION, PAYLOAD_KEY, PROFILE_KEY, REQUIRED_PROFILE_KEY, apply, canPlace, cellString, coerce, coreV1, decodeDagRecord, decodeElicitation, decodeElicitationOutcome, decodeEnvelope, decodeEnvelopeAst, decodeNode, decodeNodeTolerant, decodeOp, decodeTolerant, derivedFreshIds, duplicateOp, duplicateOpWith, encodeCell, encodeColExpr, encodeDagRecord, encodeDataSource, encodeElicitation, encodeElicitationOutcome, encodeEnvelope2 as encodeEnvelope, encodeNode, encodeOp, encodePipeline, evalErrorString, evalPipeline, evalPipelineInEnv, evalPipelineWith, evalPipelineWithInEnv, evalSource, field as jsonField, liveValueToTable, merge3Way, moveOp, negotiate, negotiateEnvelope, noResolve, nudgeOp, parse, pasteOp, pasteOpWith, pipelineParams, placeOp, reencodeNode, renderAstCanonical, renderProfile, sequentialFreshIds, stepParams, tryParseProfile, validateAnswer, validateAnswerAt, validateAnswerDocument };
10293
+ export { ELICITATION_KEY, ELICITATION_VERSION, HOST_RESERVED_PREFIX, PAYLOAD_KEY, PROFILE_KEY, REQUIRED_PROFILE_KEY, apply, canPlace, cellString, coerce, collectStateSeeds, coreV1, decodeDagRecord, decodeElicitation, decodeElicitationOutcome, decodeEnvelope, decodeEnvelopeAst, decodeNode, decodeNodeTolerant, decodeOp, decodeTolerant, derivedFreshIds, duplicateOp, duplicateOpWith, encodeCell, encodeColExpr, encodeDagRecord, encodeDataSource, encodeElicitation, encodeElicitationOutcome, encodeEnvelope2 as encodeEnvelope, encodeNode, encodeOp, encodePipeline, evalErrorString, evalPipeline, evalPipelineInEnv, evalPipelineWith, evalPipelineWithInEnv, evalSource, field as jsonField, liveValueToTable, merge3Way, moveOp, negotiate, negotiateEnvelope, noResolve, nudgeOp, parse, pasteOp, pasteOpWith, pipelineParams, placeOp, reencodeNode, renderAstCanonical, renderProfile, sequentialFreshIds, stepParams, tryParseProfile, validateAnswer, validateAnswerAt, validateAnswerDocument, withStateSeeds };
9765
10294
  //# sourceMappingURL=index.js.map
9766
10295
  //# sourceMappingURL=index.js.map