base-screen 0.3.0 → 0.4.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.
Files changed (210) hide show
  1. package/dist/_internal/contracts/document/schema.d.ts +7 -0
  2. package/dist/_internal/contracts/document/schema.js +1 -1
  3. package/dist/_internal/contracts/document/validate-value-ref.js +6 -1
  4. package/dist/_internal/contracts/screen-document.schema.json +15 -3
  5. package/dist/_internal/contracts/types/diagnostics.d.ts +1 -1
  6. package/dist/_internal/contracts/types/document.d.ts +3 -1
  7. package/dist/_internal/core/blueprint/runtime-simulate.d.ts +57 -0
  8. package/dist/_internal/core/blueprint/runtime-simulate.js +177 -0
  9. package/dist/_internal/core/blueprint/runtime.d.ts +1 -0
  10. package/dist/_internal/core/blueprint/runtime.js +1 -0
  11. package/dist/_internal/core/commands/apply-collection-commands.d.ts +32 -0
  12. package/dist/_internal/core/commands/apply-collection-commands.js +174 -0
  13. package/dist/_internal/core/commands/apply.js +13 -0
  14. package/dist/_internal/core/commands/parse-command.js +12 -0
  15. package/dist/_internal/core/commands/types.d.ts +29 -1
  16. package/dist/_internal/core/data/data-candidates.d.ts +38 -0
  17. package/dist/_internal/core/data/data-candidates.js +186 -0
  18. package/dist/_internal/core/data/dataset-profile.d.ts +71 -0
  19. package/dist/_internal/core/data/dataset-profile.js +170 -0
  20. package/dist/_internal/core/data/sample-values.d.ts +25 -0
  21. package/dist/_internal/core/data/sample-values.js +45 -0
  22. package/dist/_internal/core/diff/screen-diff.js +6 -0
  23. package/dist/_internal/core/index.d.ts +7 -1
  24. package/dist/_internal/core/index.js +7 -1
  25. package/dist/_internal/core/state/state-preset.d.ts +32 -0
  26. package/dist/_internal/core/state/state-preset.js +37 -0
  27. package/dist/_internal/core/validation/layout-audit.d.ts +17 -0
  28. package/dist/_internal/core/validation/layout-audit.js +228 -0
  29. package/dist/_internal/core/validation/legibility.d.ts +9 -0
  30. package/dist/_internal/core/validation/legibility.js +33 -0
  31. package/dist/_internal/engine/browser/controllers/dataset/designer-dataset-draft-controller.d.ts +6 -1
  32. package/dist/_internal/engine/browser/controllers/designer-change-controller.d.ts +27 -0
  33. package/dist/_internal/engine/browser/dom/change/designer-change-dom.d.ts +21 -5
  34. package/dist/_internal/engine/browser/dom/dataset/designer-data-section-diff.d.ts +4 -6
  35. package/dist/_internal/engine/browser/dom/value-ref/designer-value-ref-types.d.ts +2 -0
  36. package/dist/_internal/engine/browser/viewport/designer-canvas-aids-types.d.ts +3 -3
  37. package/dist/_internal/engine/browser/viewport/designer-canvas-aids.d.ts +5 -3
  38. package/dist/_internal/engine/browser/viewport/designer-canvas-measurements.d.ts +2 -14
  39. package/dist/_internal/engine/browser/viewport/designer-guide-overlay-nodes.d.ts +2 -0
  40. package/dist/_internal/engine/browser/viewport/designer-snap-tuning.d.ts +14 -0
  41. package/dist/_internal/engine/common/operations/change/designer-change-events.d.ts +2 -0
  42. package/dist/_internal/engine/common/operations/change/designer-change-proposal.d.ts +35 -2
  43. package/dist/_internal/engine/common/operations/display/designer-target-display.d.ts +2 -2
  44. package/dist/_internal/engine/common/operations/style/designer-component-states.d.ts +7 -2
  45. package/dist/_internal/engine/common/ui-text/designer-ui-text.d.ts +42 -2
  46. package/dist/_internal/engine/{designer-blueprint-workbench-panel-CJ3iZo5v.js → designer-blueprint-workbench-panel-BWSglfAb.js} +210 -290
  47. package/dist/_internal/engine/{designer-dataset-controller-CrfOg2Ys.js → designer-dataset-controller-DdbY4ILC.js} +619 -561
  48. package/dist/_internal/engine/designer-element/api/designer-element-change.d.ts +24 -0
  49. package/dist/_internal/engine/designer-element/base-screen-designer-element.d.ts +12 -0
  50. package/dist/_internal/engine/designer-element/designer-element-public-api.d.ts +2 -1
  51. package/dist/_internal/engine/designer-element/runtime/designer-element-rendering.d.ts +1 -1
  52. package/dist/_internal/engine/designer-element/runtime/designer-element-runtime.d.ts +4 -1
  53. package/dist/_internal/engine/designer-element/runtime/designer-element-sample-data.d.ts +23 -0
  54. package/dist/_internal/engine/{designer-field-primitives-KBZuWN_D.js → designer-field-primitives-Crn464Qg.js} +44 -3
  55. package/dist/_internal/engine/{designer-left-panel-groups-dom-N2OHOWjl.js → designer-left-panel-groups-dom-DFdLWxxY.js} +2 -2
  56. package/dist/_internal/engine/{host-resource-selection-xo2mLCD4.js → host-resource-selection-CWrPLVOc.js} +2 -2
  57. package/dist/_internal/engine/index.js +4742 -4360
  58. package/dist/_internal/host-kit/index.d.ts +1 -0
  59. package/dist/_internal/host-kit/index.js +1 -0
  60. package/dist/_internal/host-kit/intent/index.d.ts +16 -0
  61. package/dist/_internal/host-kit/intent/index.js +13 -0
  62. package/dist/_internal/host-kit/intent/intent-behavior.d.ts +59 -0
  63. package/dist/_internal/host-kit/intent/intent-behavior.js +812 -0
  64. package/dist/_internal/host-kit/intent/intent-block.d.ts +59 -0
  65. package/dist/_internal/host-kit/intent/intent-block.js +359 -0
  66. package/dist/_internal/host-kit/intent/intent-catalog.d.ts +105 -0
  67. package/dist/_internal/host-kit/intent/intent-catalog.js +60 -0
  68. package/dist/_internal/host-kit/intent/intent-compile-types.d.ts +222 -0
  69. package/dist/_internal/host-kit/intent/intent-compile-types.js +10 -0
  70. package/dist/_internal/host-kit/intent/intent-compile.d.ts +35 -0
  71. package/dist/_internal/host-kit/intent/intent-compile.js +465 -0
  72. package/dist/_internal/host-kit/intent/intent-data-check.d.ts +50 -0
  73. package/dist/_internal/host-kit/intent/intent-data-check.js +163 -0
  74. package/dist/_internal/host-kit/intent/intent-data-context.d.ts +53 -0
  75. package/dist/_internal/host-kit/intent/intent-data-context.js +200 -0
  76. package/dist/_internal/host-kit/intent/intent-dataset.d.ts +52 -0
  77. package/dist/_internal/host-kit/intent/intent-dataset.js +125 -0
  78. package/dist/_internal/host-kit/intent/intent-format.d.ts +33 -0
  79. package/dist/_internal/host-kit/intent/intent-format.js +94 -0
  80. package/dist/_internal/host-kit/intent/intent-kpi-bind.d.ts +29 -0
  81. package/dist/_internal/host-kit/intent/intent-kpi-bind.js +59 -0
  82. package/dist/_internal/host-kit/intent/intent-layout.d.ts +102 -0
  83. package/dist/_internal/host-kit/intent/intent-layout.js +264 -0
  84. package/dist/_internal/host-kit/intent/intent-parse.d.ts +39 -0
  85. package/dist/_internal/host-kit/intent/intent-parse.js +930 -0
  86. package/dist/_internal/host-kit/intent/intent-prepare.d.ts +52 -0
  87. package/dist/_internal/host-kit/intent/intent-prepare.js +104 -0
  88. package/dist/_internal/host-kit/intent/intent-session.d.ts +202 -0
  89. package/dist/_internal/host-kit/intent/intent-session.js +1001 -0
  90. package/dist/_internal/host-kit/intent/intent-stream.d.ts +28 -0
  91. package/dist/_internal/host-kit/intent/intent-stream.js +183 -0
  92. package/dist/_internal/host-kit/intent/intent-style.d.ts +37 -0
  93. package/dist/_internal/host-kit/intent/intent-style.js +77 -0
  94. package/dist/_internal/host-kit/intent/intent-types.d.ts +234 -0
  95. package/dist/_internal/host-kit/intent/intent-types.js +10 -0
  96. package/dist/_internal/material/chart.js +34 -12
  97. package/dist/_internal/material/table.js +52 -21
  98. package/dist/_internal/plugin-sdk/index.d.ts +6 -0
  99. package/dist/_internal/plugin-sdk/index.js +6 -0
  100. package/dist/_internal/plugin-sdk/material-isolated-csp.d.ts +38 -0
  101. package/dist/_internal/plugin-sdk/material-isolated-csp.js +67 -0
  102. package/dist/_internal/plugin-sdk/material-isolated-runtime.d.ts +22 -0
  103. package/dist/_internal/plugin-sdk/material-isolated-runtime.js +262 -0
  104. package/dist/_internal/plugin-sdk/material-isolated.d.ts +94 -0
  105. package/dist/_internal/plugin-sdk/material-isolated.js +1024 -0
  106. package/dist/_internal/plugin-sdk/material-rendered-element.d.ts +10 -2
  107. package/dist/_internal/plugin-sdk/material-rendered-element.js +71 -7
  108. package/dist/_internal/plugin-sdk/material-spec-audit.d.ts +2 -0
  109. package/dist/_internal/plugin-sdk/material-spec-audit.js +26 -6
  110. package/dist/_internal/plugin-sdk/material-spec.d.ts +20 -0
  111. package/dist/_internal/plugin-sdk/material-spec.js +78 -3
  112. package/dist/_internal/plugin-sdk/material-template-audit.d.ts +12 -0
  113. package/dist/_internal/plugin-sdk/material-template-audit.js +302 -0
  114. package/dist/_internal/plugin-sdk/material-template-expression.d.ts +98 -0
  115. package/dist/_internal/plugin-sdk/material-template-expression.js +549 -0
  116. package/dist/_internal/plugin-sdk/material-template-render.d.ts +32 -0
  117. package/dist/_internal/plugin-sdk/material-template-render.js +579 -0
  118. package/dist/_internal/plugin-sdk/material-template.d.ts +185 -0
  119. package/dist/_internal/plugin-sdk/material-template.js +879 -0
  120. package/dist/auto-register.js +10 -10
  121. package/dist/contracts.js +5 -5
  122. package/dist/contrast-DRPezUIl.js +131 -0
  123. package/dist/contrast-DRPezUIl.js.map +1 -0
  124. package/dist/core.js +156 -136
  125. package/dist/core.js.map +1 -1
  126. package/dist/dataset-profile-Dk6xdtsM.js +261 -0
  127. package/dist/dataset-profile-Dk6xdtsM.js.map +1 -0
  128. package/dist/{designer-3Tb0EIDV.js → designer-CFOvOmLn.js} +2 -2
  129. package/dist/{designer-3Tb0EIDV.js.map → designer-CFOvOmLn.js.map} +1 -1
  130. package/dist/designer-auto-register.js +5 -5
  131. package/dist/{designer-blueprint-workbench-panel-CJ3iZo5v-BebifP4x.js → designer-blueprint-workbench-panel-BWSglfAb-ktaj6Ci9.js} +452 -531
  132. package/dist/designer-blueprint-workbench-panel-BWSglfAb-ktaj6Ci9.js.map +1 -0
  133. package/dist/{designer-dataset-controller-CrfOg2Ys-DhKUEJJe.js → designer-dataset-controller-DdbY4ILC-CMdGdGbr.js} +862 -804
  134. package/dist/designer-dataset-controller-DdbY4ILC-CMdGdGbr.js.map +1 -0
  135. package/dist/{designer-field-primitives-KBZuWN_D-B3h4jpYe.js → designer-field-primitives-Crn464Qg-Bi7q8s5J.js} +45 -4
  136. package/dist/designer-field-primitives-Crn464Qg-Bi7q8s5J.js.map +1 -0
  137. package/dist/{designer-left-panel-groups-dom-N2OHOWjl-D8CzGwbF.js → designer-left-panel-groups-dom-DFdLWxxY-BarlWMLY.js} +4 -4
  138. package/dist/{designer-left-panel-groups-dom-N2OHOWjl-D8CzGwbF.js.map → designer-left-panel-groups-dom-DFdLWxxY-BarlWMLY.js.map} +1 -1
  139. package/dist/designer.js +5 -5
  140. package/dist/{dist-6GRboBs-.js → dist-B2bW2Tru.js} +4 -4
  141. package/dist/{dist-6GRboBs-.js.map → dist-B2bW2Tru.js.map} +1 -1
  142. package/dist/{dist-BjLjFUy1.js → dist-CHK9BTXX.js} +3833 -3453
  143. package/dist/dist-CHK9BTXX.js.map +1 -0
  144. package/dist/engine.js +5 -5
  145. package/dist/{fragment-Y6YnW6wy.js → fragment-B-oP0Fru.js} +3 -3
  146. package/dist/{fragment-Y6YnW6wy.js.map → fragment-B-oP0Fru.js.map} +1 -1
  147. package/dist/host-kit.js +3963 -187
  148. package/dist/host-kit.js.map +1 -1
  149. package/dist/{host-resource-selection-xo2mLCD4-BR5XCcim.js → host-resource-selection-CWrPLVOc-DPDq3jau.js} +5 -5
  150. package/dist/{host-resource-selection-xo2mLCD4-BR5XCcim.js.map → host-resource-selection-CWrPLVOc-DPDq3jau.js.map} +1 -1
  151. package/dist/index.js +10 -10
  152. package/dist/legibility-CS28ivEz.js +12 -0
  153. package/dist/legibility-CS28ivEz.js.map +1 -0
  154. package/dist/{level-scale-BzUjE31V.js → level-scale-CwHqFEVd.js} +2 -2
  155. package/dist/{level-scale-BzUjE31V.js.map → level-scale-CwHqFEVd.js.map} +1 -1
  156. package/dist/{manager-Ch0RTu_i.js → manager-CeB4Jnr9.js} +3 -3
  157. package/dist/{manager-Ch0RTu_i.js.map → manager-CeB4Jnr9.js.map} +1 -1
  158. package/dist/{material-UbSfiuZq.js → material-DeVkzSoT.js} +2 -2
  159. package/dist/{material-UbSfiuZq.js.map → material-DeVkzSoT.js.map} +1 -1
  160. package/dist/material-auto-register.js +1 -1
  161. package/dist/material.js +2 -2
  162. package/dist/{migrate-document-D3HhCVlZ.js → migrate-document-BM888PtC.js} +2 -2
  163. package/dist/{migrate-document-D3HhCVlZ.js.map → migrate-document-BM888PtC.js.map} +1 -1
  164. package/dist/{parse-AOTE9WnD.js → parse-Ji7kE9ZT.js} +9 -4
  165. package/dist/parse-Ji7kE9ZT.js.map +1 -0
  166. package/dist/{parse-B1OD1teS.js → parse-aZat9tAS.js} +3 -3
  167. package/dist/{parse-B1OD1teS.js.map → parse-aZat9tAS.js.map} +1 -1
  168. package/dist/{parse-parts-BNrpdG5o.js → parse-parts-qzl4suzk.js} +2 -2
  169. package/dist/{parse-parts-BNrpdG5o.js.map → parse-parts-qzl4suzk.js.map} +1 -1
  170. package/dist/{plugin-DHgh9uHh.js → plugin-CstHQ5ws.js} +4 -4
  171. package/dist/{plugin-DHgh9uHh.js.map → plugin-CstHQ5ws.js.map} +1 -1
  172. package/dist/plugin-core.js +2 -2
  173. package/dist/plugin-manager.js +1 -1
  174. package/dist/plugin-package-DWifuHi1.js +4206 -0
  175. package/dist/plugin-package-DWifuHi1.js.map +1 -0
  176. package/dist/{plugin-registration-rsmb4GvS.js → plugin-registration-DTwBvnHX.js} +2 -2
  177. package/dist/{plugin-registration-rsmb4GvS.js.map → plugin-registration-DTwBvnHX.js.map} +1 -1
  178. package/dist/plugin-sdk.js +6 -6
  179. package/dist/{plugins-DGRHgREK.js → plugins-QDL0yIql.js} +2 -2
  180. package/dist/{plugins-DGRHgREK.js.map → plugins-QDL0yIql.js.map} +1 -1
  181. package/dist/plugins.js +8 -8
  182. package/dist/renderer.js +1 -1
  183. package/dist/{runtime-dispatch-BfnRDtMe.js → runtime-dispatch-C0gyIrTv.js} +2 -2
  184. package/dist/{runtime-dispatch-BfnRDtMe.js.map → runtime-dispatch-C0gyIrTv.js.map} +1 -1
  185. package/dist/runtime-simulate-aSYO9yDX.js +147 -0
  186. package/dist/runtime-simulate-aSYO9yDX.js.map +1 -0
  187. package/dist/{src-Bm7u11mN-_0u6cMEw.js → src-Bm7u11mN-Bi1hDVkh.js} +39 -39
  188. package/dist/{src-Bm7u11mN-_0u6cMEw.js.map → src-Bm7u11mN-Bi1hDVkh.js.map} +1 -1
  189. package/dist/state-preset-DtpygJOH.js +22 -0
  190. package/dist/state-preset-DtpygJOH.js.map +1 -0
  191. package/dist/{text-BNksUr5J.js → text-BSTz0pFQ.js} +87 -34
  192. package/dist/text-BSTz0pFQ.js.map +1 -0
  193. package/dist/{value-ref-BG_MV9C-.js → value-ref-XkLuckGV.js} +2 -2
  194. package/dist/{value-ref-BG_MV9C-.js.map → value-ref-XkLuckGV.js.map} +1 -1
  195. package/dist/{viewer-CrJupI8I-D9dVcNw4.js → viewer-CrJupI8I-BJiz1cvW.js} +4 -4
  196. package/dist/{viewer-CrJupI8I-D9dVcNw4.js.map → viewer-CrJupI8I-BJiz1cvW.js.map} +1 -1
  197. package/dist/viewer-auto-register.js +2 -2
  198. package/dist/viewer.js +2 -2
  199. package/dist/{viewport-CiCKeAQH.js → viewport-BNIRWjiT.js} +354 -155
  200. package/dist/viewport-BNIRWjiT.js.map +1 -0
  201. package/package.json +12 -12
  202. package/dist/designer-blueprint-workbench-panel-CJ3iZo5v-BebifP4x.js.map +0 -1
  203. package/dist/designer-dataset-controller-CrfOg2Ys-DhKUEJJe.js.map +0 -1
  204. package/dist/designer-field-primitives-KBZuWN_D-B3h4jpYe.js.map +0 -1
  205. package/dist/dist-BjLjFUy1.js.map +0 -1
  206. package/dist/parse-AOTE9WnD.js.map +0 -1
  207. package/dist/plugin-package-Dr5ro6h6.js +0 -1221
  208. package/dist/plugin-package-Dr5ro6h6.js.map +0 -1
  209. package/dist/text-BNksUr5J.js.map +0 -1
  210. package/dist/viewport-CiCKeAQH.js.map +0 -1
@@ -0,0 +1,549 @@
1
+ export const BASE_SCREEN_MATERIAL_TEMPLATE_EXPRESSION_LIMITS = {
2
+ sourceLength: 400,
3
+ depth: 16,
4
+ nodes: 64,
5
+ concatLength: 256,
6
+ };
7
+ /** 一次渲染的求值步数上限(ADR-0116 §2.3)。 */
8
+ export const BASE_SCREEN_MATERIAL_TEMPLATE_STEP_BUDGET = 20_000;
9
+ const FUNCTIONS = {
10
+ min: { min: 2, max: 8 },
11
+ max: { min: 2, max: 8 },
12
+ clamp: { min: 3, max: 3 },
13
+ abs: { min: 1, max: 1 },
14
+ round: { min: 1, max: 2 },
15
+ floor: { min: 1, max: 1 },
16
+ ceil: { min: 1, max: 1 },
17
+ sqrt: { min: 1, max: 1 },
18
+ sin: { min: 1, max: 1 },
19
+ cos: { min: 1, max: 1 },
20
+ scale: { min: 5, max: 5 },
21
+ pct: { min: 1, max: 3 },
22
+ format: { min: 1, max: 1 },
23
+ fixed: { min: 2, max: 2 },
24
+ concat: { min: 1, max: 8 },
25
+ pick: { min: 4, max: 24, even: true },
26
+ len: { min: 1, max: 1 },
27
+ charAt: { min: 2, max: 2 },
28
+ maxOf: { min: 2, max: 2, aggregate: true },
29
+ minOf: { min: 2, max: 2, aggregate: true },
30
+ sumOf: { min: 2, max: 2, aggregate: true },
31
+ };
32
+ /** 闭集函数名(体检与提示词列出用)。 */
33
+ export const BASE_SCREEN_MATERIAL_TEMPLATE_FUNCTIONS = Object.keys(FUNCTIONS);
34
+ const OPERATORS = [
35
+ '==',
36
+ '!=',
37
+ '<=',
38
+ '>=',
39
+ '&&',
40
+ '||',
41
+ '<',
42
+ '>',
43
+ '+',
44
+ '-',
45
+ '*',
46
+ '/',
47
+ '%',
48
+ '!',
49
+ '?',
50
+ ':',
51
+ '(',
52
+ ')',
53
+ ',',
54
+ '.',
55
+ ];
56
+ function tokenize(source) {
57
+ const tokens = [];
58
+ let at = 0;
59
+ while (at < source.length) {
60
+ const char = source[at];
61
+ if (char === ' ' || char === '\t' || char === '\n' || char === '\r') {
62
+ at += 1;
63
+ continue;
64
+ }
65
+ if (/[0-9]/.test(char) || (char === '.' && /[0-9]/.test(source[at + 1] ?? ''))) {
66
+ const match = /^(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?/.exec(source.slice(at));
67
+ if (match === null)
68
+ return `第 ${at + 1} 个字符不是合法的数字。`;
69
+ tokens.push({ t: 'num', v: Number(match[0]) });
70
+ at += match[0].length;
71
+ continue;
72
+ }
73
+ if (char === "'" || char === '"') {
74
+ let end = at + 1;
75
+ let text = '';
76
+ while (end < source.length && source[end] !== char) {
77
+ if (source[end] === '\\')
78
+ return '字符串里不支持转义。';
79
+ text += source[end];
80
+ end += 1;
81
+ }
82
+ if (end >= source.length)
83
+ return '字符串缺少结束引号。';
84
+ tokens.push({ t: 'str', v: text });
85
+ at = end + 1;
86
+ continue;
87
+ }
88
+ if (/[A-Za-z_]/.test(char)) {
89
+ const match = /^[A-Za-z_][A-Za-z0-9_]*/.exec(source.slice(at));
90
+ tokens.push({ t: 'id', v: match[0] });
91
+ at += match[0].length;
92
+ continue;
93
+ }
94
+ const op = OPERATORS.find((item) => source.startsWith(item, at));
95
+ if (op === undefined)
96
+ return `不认识的符号「${char}」。`;
97
+ tokens.push({ t: 'op', v: op });
98
+ at += op.length;
99
+ }
100
+ tokens.push({ t: 'end' });
101
+ return tokens;
102
+ }
103
+ class ParseError extends Error {
104
+ }
105
+ const BINARY_PRECEDENCE = {
106
+ '||': 1,
107
+ '&&': 2,
108
+ '==': 3,
109
+ '!=': 3,
110
+ '<': 4,
111
+ '<=': 4,
112
+ '>': 4,
113
+ '>=': 4,
114
+ '+': 5,
115
+ '-': 5,
116
+ '*': 6,
117
+ '/': 6,
118
+ '%': 6,
119
+ };
120
+ class Parser {
121
+ tokens;
122
+ scope;
123
+ #at = 0;
124
+ #nodes = 0;
125
+ constructor(tokens, scope) {
126
+ this.tokens = tokens;
127
+ this.scope = scope;
128
+ }
129
+ parse() {
130
+ const expression = this.#ternary(0);
131
+ if (this.#peek().t !== 'end')
132
+ throw new ParseError('表达式结尾有多余内容。');
133
+ return expression;
134
+ }
135
+ #peek() {
136
+ return this.tokens[this.#at];
137
+ }
138
+ #next() {
139
+ const token = this.tokens[this.#at];
140
+ this.#at += 1;
141
+ return token;
142
+ }
143
+ #isOp(value) {
144
+ const token = this.#peek();
145
+ return token.t === 'op' && token.v === value;
146
+ }
147
+ #expect(value) {
148
+ if (!this.#isOp(value))
149
+ throw new ParseError(`缺少「${value}」。`);
150
+ this.#at += 1;
151
+ }
152
+ #node(node, depth) {
153
+ this.#nodes += 1;
154
+ if (this.#nodes > BASE_SCREEN_MATERIAL_TEMPLATE_EXPRESSION_LIMITS.nodes) {
155
+ throw new ParseError(`表达式过长(最多 ${BASE_SCREEN_MATERIAL_TEMPLATE_EXPRESSION_LIMITS.nodes} 个节点)。`);
156
+ }
157
+ if (depth > BASE_SCREEN_MATERIAL_TEMPLATE_EXPRESSION_LIMITS.depth) {
158
+ throw new ParseError(`表达式嵌套过深(最多 ${BASE_SCREEN_MATERIAL_TEMPLATE_EXPRESSION_LIMITS.depth} 层)。`);
159
+ }
160
+ return node;
161
+ }
162
+ #ternary(depth) {
163
+ const test = this.#binary(1, depth);
164
+ if (!this.#isOp('?'))
165
+ return test;
166
+ this.#at += 1;
167
+ const a = this.#ternary(depth + 1);
168
+ this.#expect(':');
169
+ const b = this.#ternary(depth + 1);
170
+ return this.#node({ k: 'cond', t: test, a, b }, depth);
171
+ }
172
+ #binary(minPrecedence, depth) {
173
+ let left = this.#unary(depth + 1);
174
+ for (;;) {
175
+ const token = this.#peek();
176
+ if (token.t !== 'op')
177
+ return left;
178
+ const precedence = BINARY_PRECEDENCE[token.v];
179
+ if (precedence === undefined || precedence < minPrecedence)
180
+ return left;
181
+ this.#at += 1;
182
+ const right = this.#binary(precedence + 1, depth + 1);
183
+ left = this.#node({
184
+ k: 'bin',
185
+ op: token.v,
186
+ a: left,
187
+ b: right,
188
+ }, depth);
189
+ }
190
+ }
191
+ #unary(depth) {
192
+ if (this.#isOp('-') || this.#isOp('!')) {
193
+ const op = this.#next().v;
194
+ return this.#node({ k: 'un', op, a: this.#unary(depth + 1) }, depth);
195
+ }
196
+ return this.#primary(depth);
197
+ }
198
+ #primary(depth) {
199
+ const token = this.#next();
200
+ if (token.t === 'num')
201
+ return this.#node({ k: 'lit', v: token.v }, depth);
202
+ if (token.t === 'str')
203
+ return this.#node({ k: 'lit', v: token.v }, depth);
204
+ if (token.t === 'op' && token.v === '(') {
205
+ const inner = this.#ternary(depth + 1);
206
+ this.#expect(')');
207
+ return inner;
208
+ }
209
+ if (token.t === 'id') {
210
+ if (token.v === 'true' || token.v === 'false') {
211
+ return this.#node({ k: 'lit', v: token.v === 'true' }, depth);
212
+ }
213
+ if (token.v === 'null')
214
+ return this.#node({ k: 'lit', v: null }, depth);
215
+ if (this.#isOp('('))
216
+ return this.#call(token.v, depth);
217
+ return this.#reference(token.v, depth);
218
+ }
219
+ throw new ParseError('表达式不完整。');
220
+ }
221
+ #call(name, depth) {
222
+ const spec = FUNCTIONS[name];
223
+ if (spec === undefined) {
224
+ throw new ParseError(`不支持函数 ${name}(可用:${BASE_SCREEN_MATERIAL_TEMPLATE_FUNCTIONS.join('、')})。`);
225
+ }
226
+ this.#expect('(');
227
+ const args = [];
228
+ if (!this.#isOp(')')) {
229
+ for (;;) {
230
+ if (spec.aggregate === true && args.length === 0) {
231
+ args.push(this.#rowsArgument(name, depth + 1));
232
+ }
233
+ else {
234
+ args.push(this.#ternary(depth + 1));
235
+ }
236
+ if (!this.#isOp(','))
237
+ break;
238
+ this.#at += 1;
239
+ }
240
+ }
241
+ this.#expect(')');
242
+ if (args.length < spec.min || args.length > spec.max) {
243
+ throw new ParseError(spec.min === spec.max
244
+ ? `${name} 需要 ${spec.min} 个参数。`
245
+ : `${name} 需要 ${spec.min}–${spec.max} 个参数。`);
246
+ }
247
+ if (spec.even === true && args.length % 2 !== 0) {
248
+ throw new ParseError(`${name} 的参数是「取值, 键1, 值1, …, 缺省值」,个数应为偶数。`);
249
+ }
250
+ if (spec.aggregate === true) {
251
+ const role = args[1];
252
+ if (role?.k !== 'lit' || typeof role.v !== 'string' || !this.scope.roles.has(role.v)) {
253
+ throw new ParseError(`${name} 的第二个参数必须是已声明的数据角色名(用引号写)。`);
254
+ }
255
+ }
256
+ return this.#node({ k: 'call', fn: name, args }, depth);
257
+ }
258
+ #rowsArgument(name, depth) {
259
+ const token = this.#next();
260
+ if (token.t !== 'id' || token.v !== 'rows') {
261
+ throw new ParseError(`${name} 的第一个参数必须是 rows。`);
262
+ }
263
+ if (this.scope.data !== 'rows')
264
+ throw new ParseError('组件不是多行数据,不能读 rows。');
265
+ return this.#node({ k: 'ref', root: 'rows' }, depth);
266
+ }
267
+ #reference(root, depth) {
268
+ let key;
269
+ if (this.#isOp('.')) {
270
+ this.#at += 1;
271
+ const next = this.#next();
272
+ if (next.t !== 'id')
273
+ throw new ParseError(`${root}. 后面缺少字段名。`);
274
+ key = next.v;
275
+ if (this.#isOp('.'))
276
+ throw new ParseError('引用只能有一层(如 props.showLabel)。');
277
+ }
278
+ const scope = this.scope;
279
+ switch (root) {
280
+ case 'value':
281
+ if (key !== undefined)
282
+ throw new ParseError('value 后面不能再接字段。');
283
+ if (scope.data !== 'scalar')
284
+ throw new ParseError('组件不是单值数据,不能读 value。');
285
+ return this.#node({ k: 'ref', root: 'value' }, depth);
286
+ case 'index':
287
+ case 'count':
288
+ if (key !== undefined)
289
+ throw new ParseError(`${root} 后面不能再接字段。`);
290
+ if (!scope.inRepeat)
291
+ throw new ParseError(`${root} 只能用在 repeat 里。`);
292
+ return this.#node({ k: 'ref', root }, depth);
293
+ case 'rows':
294
+ throw new ParseError('rows 只能交给 maxOf / minOf / sumOf。');
295
+ case 'row':
296
+ if (!scope.inRowRepeat)
297
+ throw new ParseError('row 只能用在遍历 rows 的 repeat 里。');
298
+ if (key === undefined || !scope.roles.has(key)) {
299
+ throw new ParseError(`row.${key ?? ''} 不是已声明的数据角色。`);
300
+ }
301
+ return this.#node({ k: 'ref', root: 'row', key }, depth);
302
+ case 'props':
303
+ case 'style': {
304
+ const declared = root === 'props' ? scope.props : scope.style;
305
+ if (key === undefined || !declared.has(key)) {
306
+ throw new ParseError(`${root}.${key ?? ''} 不是规格里声明的${root === 'props' ? '参数' : '样式'}字段。`);
307
+ }
308
+ return this.#node({ k: 'ref', root, key }, depth);
309
+ }
310
+ case 'size':
311
+ if (key !== 'width' && key !== 'height')
312
+ throw new ParseError('size 只有 width / height。');
313
+ return this.#node({ k: 'ref', root: 'size', key }, depth);
314
+ default:
315
+ throw new ParseError(`不认识的名字 ${root}(可用:value、row.<角色>、index、count、props.<键>、style.<键>、size.width / height)。`);
316
+ }
317
+ }
318
+ }
319
+ /** 解析一条表达式;失败返回给作者(与模型修复轮)看的中文原因。 */
320
+ export function parseBaseScreenMaterialTemplateExpression(source, scope) {
321
+ if (source.length > BASE_SCREEN_MATERIAL_TEMPLATE_EXPRESSION_LIMITS.sourceLength) {
322
+ return {
323
+ ok: false,
324
+ message: `表达式最多 ${BASE_SCREEN_MATERIAL_TEMPLATE_EXPRESSION_LIMITS.sourceLength} 个字符。`,
325
+ };
326
+ }
327
+ const tokens = tokenize(source);
328
+ if (typeof tokens === 'string')
329
+ return { ok: false, message: tokens };
330
+ try {
331
+ return { ok: true, value: new Parser(tokens, scope).parse() };
332
+ }
333
+ catch (error) {
334
+ if (error instanceof ParseError)
335
+ return { ok: false, message: error.message };
336
+ throw error;
337
+ }
338
+ }
339
+ /** 求值超出步数预算(ADR-0116 §2.3):调用方让该组件进入错误视图。 */
340
+ export class BaseScreenMaterialTemplateBudgetError extends Error {
341
+ constructor() {
342
+ super('模板求值超出步数上限。');
343
+ this.name = 'BaseScreenMaterialTemplateBudgetError';
344
+ }
345
+ }
346
+ export function evaluateBaseScreenMaterialTemplateExpression(expression, env) {
347
+ env.budget.steps -= 1;
348
+ if (env.budget.steps < 0)
349
+ throw new BaseScreenMaterialTemplateBudgetError();
350
+ switch (expression.k) {
351
+ case 'lit':
352
+ return expression.v;
353
+ case 'ref':
354
+ return readReference(expression.root, expression.key, env);
355
+ case 'un': {
356
+ const value = evaluateBaseScreenMaterialTemplateExpression(expression.a, env);
357
+ return expression.op === '-' ? -toNumber(value) : !truthy(value);
358
+ }
359
+ case 'cond':
360
+ return truthy(evaluateBaseScreenMaterialTemplateExpression(expression.t, env))
361
+ ? evaluateBaseScreenMaterialTemplateExpression(expression.a, env)
362
+ : evaluateBaseScreenMaterialTemplateExpression(expression.b, env);
363
+ case 'bin':
364
+ return evaluateBinary(expression, env);
365
+ case 'call':
366
+ return evaluateCall(expression.fn, expression.args, env);
367
+ }
368
+ }
369
+ function readReference(root, key, env) {
370
+ switch (root) {
371
+ case 'value':
372
+ return env.value;
373
+ case 'index':
374
+ return env.index ?? null;
375
+ case 'count':
376
+ return env.count ?? null;
377
+ case 'row':
378
+ return scalar(key === undefined ? undefined : env.row?.[key]);
379
+ case 'props':
380
+ return scalar(key === undefined ? undefined : env.props[key]);
381
+ case 'style':
382
+ return scalar(key === undefined ? undefined : env.style[key]);
383
+ case 'size':
384
+ return key === 'height' ? env.size.height : env.size.width;
385
+ case 'rows':
386
+ return null;
387
+ }
388
+ }
389
+ function evaluateBinary(expression, env) {
390
+ if (expression.op === '&&') {
391
+ const left = evaluateBaseScreenMaterialTemplateExpression(expression.a, env);
392
+ return truthy(left) ? evaluateBaseScreenMaterialTemplateExpression(expression.b, env) : left;
393
+ }
394
+ if (expression.op === '||') {
395
+ const left = evaluateBaseScreenMaterialTemplateExpression(expression.a, env);
396
+ return truthy(left) ? left : evaluateBaseScreenMaterialTemplateExpression(expression.b, env);
397
+ }
398
+ const a = evaluateBaseScreenMaterialTemplateExpression(expression.a, env);
399
+ const b = evaluateBaseScreenMaterialTemplateExpression(expression.b, env);
400
+ switch (expression.op) {
401
+ case '==':
402
+ return looseEquals(a, b);
403
+ case '!=':
404
+ return !looseEquals(a, b);
405
+ case '<':
406
+ return toNumber(a) < toNumber(b);
407
+ case '<=':
408
+ return toNumber(a) <= toNumber(b);
409
+ case '>':
410
+ return toNumber(a) > toNumber(b);
411
+ case '>=':
412
+ return toNumber(a) >= toNumber(b);
413
+ case '+':
414
+ return toNumber(a) + toNumber(b);
415
+ case '-':
416
+ return toNumber(a) - toNumber(b);
417
+ case '*':
418
+ return toNumber(a) * toNumber(b);
419
+ case '/':
420
+ return toNumber(a) / toNumber(b);
421
+ case '%':
422
+ return toNumber(a) % toNumber(b);
423
+ }
424
+ }
425
+ function evaluateCall(name, args, env) {
426
+ if (name === 'maxOf' || name === 'minOf' || name === 'sumOf') {
427
+ const role = args[1].v;
428
+ const numbers = env.rows.map((row) => toNumber(scalar(row[role]))).filter(Number.isFinite);
429
+ env.budget.steps -= env.rows.length;
430
+ if (env.budget.steps < 0)
431
+ throw new BaseScreenMaterialTemplateBudgetError();
432
+ if (numbers.length === 0)
433
+ return null;
434
+ if (name === 'sumOf')
435
+ return numbers.reduce((sum, item) => sum + item, 0);
436
+ return name === 'maxOf' ? Math.max(...numbers) : Math.min(...numbers);
437
+ }
438
+ if (name === 'pick') {
439
+ const key = evaluateBaseScreenMaterialTemplateExpression(args[0], env);
440
+ // 参数形如 [取值, 键1, 值1, …, 键n, 值n, 缺省值]:成对的键值位于 1..length-2。
441
+ for (let at = 1; at <= args.length - 3; at += 2) {
442
+ const candidate = evaluateBaseScreenMaterialTemplateExpression(args[at], env);
443
+ if (looseEquals(key, candidate)) {
444
+ return evaluateBaseScreenMaterialTemplateExpression(args[at + 1], env);
445
+ }
446
+ }
447
+ return evaluateBaseScreenMaterialTemplateExpression(args[args.length - 1], env);
448
+ }
449
+ const values = args.map((arg) => evaluateBaseScreenMaterialTemplateExpression(arg, env));
450
+ const n = (index) => toNumber(values[index] ?? null);
451
+ switch (name) {
452
+ case 'min':
453
+ return Math.min(...values.map((value) => toNumber(value)));
454
+ case 'max':
455
+ return Math.max(...values.map((value) => toNumber(value)));
456
+ case 'clamp':
457
+ return Math.min(Math.max(n(0), n(1)), n(2));
458
+ case 'abs':
459
+ return Math.abs(n(0));
460
+ case 'round': {
461
+ const digits = values.length > 1 ? Math.max(0, Math.min(6, Math.trunc(n(1)))) : 0;
462
+ const factor = 10 ** digits;
463
+ return Math.round(n(0) * factor) / factor;
464
+ }
465
+ case 'floor':
466
+ return Math.floor(n(0));
467
+ case 'ceil':
468
+ return Math.ceil(n(0));
469
+ case 'sqrt':
470
+ return Math.sqrt(n(0));
471
+ case 'sin':
472
+ return Math.sin((n(0) * Math.PI) / 180);
473
+ case 'cos':
474
+ return Math.cos((n(0) * Math.PI) / 180);
475
+ case 'scale': {
476
+ const [v, d0, d1, r0, r1] = [n(0), n(1), n(2), n(3), n(4)];
477
+ if (d1 === d0)
478
+ return r0;
479
+ return r0 + ((v - d0) / (d1 - d0)) * (r1 - r0);
480
+ }
481
+ case 'pct': {
482
+ const low = values.length > 1 ? n(1) : 0;
483
+ const high = values.length > 2 ? n(2) : 100;
484
+ if (high === low)
485
+ return 0;
486
+ return Math.min(1, Math.max(0, (n(0) - low) / (high - low)));
487
+ }
488
+ case 'format':
489
+ return env.formatNumber(values[0]);
490
+ case 'fixed': {
491
+ const value = n(0);
492
+ if (!Number.isFinite(value))
493
+ return '--';
494
+ return value.toFixed(Math.max(0, Math.min(6, Math.trunc(n(1)))));
495
+ }
496
+ case 'concat':
497
+ return values
498
+ .map((value) => (value === null ? '' : String(value)))
499
+ .join('')
500
+ .slice(0, BASE_SCREEN_MATERIAL_TEMPLATE_EXPRESSION_LIMITS.concatLength);
501
+ case 'len':
502
+ return values[0] === null ? 0 : [...String(values[0])].length;
503
+ case 'charAt': {
504
+ const chars = values[0] === null ? [] : [...String(values[0])];
505
+ return chars[Math.trunc(n(1))] ?? '';
506
+ }
507
+ default:
508
+ return null;
509
+ }
510
+ }
511
+ function scalar(value) {
512
+ if (value === undefined || value === null)
513
+ return null;
514
+ if (typeof value === 'number' || typeof value === 'string' || typeof value === 'boolean') {
515
+ return value;
516
+ }
517
+ return null;
518
+ }
519
+ export function toTemplateNumber(value) {
520
+ return toNumber(value);
521
+ }
522
+ function toNumber(value) {
523
+ if (typeof value === 'number')
524
+ return value;
525
+ if (typeof value === 'boolean')
526
+ return value ? 1 : 0;
527
+ if (typeof value === 'string' && value.trim() !== '')
528
+ return Number(value);
529
+ return Number.NaN;
530
+ }
531
+ export function isTemplateTruthy(value) {
532
+ return truthy(value);
533
+ }
534
+ function truthy(value) {
535
+ if (typeof value === 'number')
536
+ return value !== 0 && !Number.isNaN(value);
537
+ return value !== null && value !== false && value !== '';
538
+ }
539
+ /** 相等:同类型严格比较;数字与数字字符串按数值比较(数据集里状态码常是字符串)。 */
540
+ function looseEquals(a, b) {
541
+ if (typeof a === typeof b)
542
+ return a === b;
543
+ if ((typeof a === 'number' && typeof b === 'string') ||
544
+ (typeof a === 'string' && typeof b === 'number')) {
545
+ return toNumber(a) === toNumber(b);
546
+ }
547
+ return false;
548
+ }
549
+ //# sourceMappingURL=material-template-expression.js.map
@@ -0,0 +1,32 @@
1
+ import type { ScreenJsonObject, ScreenJsonValue } from '../contracts/index.js';
2
+ import { type CompiledBaseScreenMaterialTemplate } from './material-template.js';
3
+ /**
4
+ * L2 模板解释器(base-screen-docs ADR-0116 §2.2 / §2.5)。
5
+ *
6
+ * - 只用 `createElementNS` 构造白名单内的元素与属性;文字走 `textContent`;不生成、也不解析字符串;
7
+ * - 渐变与裁剪的 id 按实例加命名空间(同一页多个实例、同一 Shadow root 里也不串);
8
+ * - 颜色表达式的结果再按字面量颜色正则校验一次:数据或样式里混进 `url(...)` 时直接丢弃该属性;
9
+ * - 动画只动组件内部:循环(平移 / 旋转 / 缩放 / 透明度)用 WAAPI 作用在一个包裹层上;读数变化过渡
10
+ * 补间节点参数(不是 DOM 属性),每帧按插值后的参数重建该节点的几何;
11
+ * - 设计态(`interactive === false`)与 `prefers-reduced-motion` 下一律不播放、不派发事件。
12
+ */
13
+ export interface BaseScreenMaterialTemplateRenderInput {
14
+ readonly document: Document;
15
+ readonly root: HTMLElement;
16
+ readonly props: ScreenJsonObject;
17
+ readonly style: ScreenJsonObject;
18
+ readonly size: {
19
+ readonly width: number;
20
+ readonly height: number;
21
+ };
22
+ readonly interactive: boolean;
23
+ readonly value: number | string | null;
24
+ readonly rows: readonly Readonly<Record<string, ScreenJsonValue>>[];
25
+ formatNumber(value: unknown): string;
26
+ }
27
+ export type BaseScreenMaterialTemplateRenderer = (input: BaseScreenMaterialTemplateRenderInput) => void;
28
+ /** 为一个物料实例创建渲染函数:实例持有上一帧参数,用于读数变化过渡。 */
29
+ export declare function createBaseScreenMaterialTemplateRenderer(template: CompiledBaseScreenMaterialTemplate): BaseScreenMaterialTemplateRenderer;
30
+ /** 弧:角度以正上方为 0、顺时针为正;扫过 ≥ 360° 时画成整圆(两段半圆)。 */
31
+ export declare function arcPath(cx: number, cy: number, r: number, start: number, end: number): string;
32
+ //# sourceMappingURL=material-template-render.d.ts.map