@airalogy/aimd-recorder 1.14.1

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 (178) hide show
  1. package/README.md +240 -0
  2. package/README.zh-CN.md +224 -0
  3. package/dist/AimdCodeField-DC3DPvgc.js +172 -0
  4. package/dist/AimdDnaSequenceField-__jdnFS9.js +59466 -0
  5. package/dist/AimdEditor.vue_vue_type_style_index_0_lang-Bq79rKNw.js +28370 -0
  6. package/dist/AimdMarkdownField-98ImHGbc.js +66 -0
  7. package/dist/AimdMarkdownNoteField-CuUJZkgT.js +185 -0
  8. package/dist/_.contribution-IP0cDNhs.js +38 -0
  9. package/dist/_commonjsHelpers-CZXJ37nu.js +40 -0
  10. package/dist/abap-Bs8kvjsq.js +1398 -0
  11. package/dist/aimd-recorder.css +1 -0
  12. package/dist/apex-Dspwrl5m.js +326 -0
  13. package/dist/assets/css.worker-Dmf38jDD.js +79 -0
  14. package/dist/assets/editor.worker-CpuX8TSY.js +12 -0
  15. package/dist/assets/html.worker-DotaEs7v.js +456 -0
  16. package/dist/assets/json.worker-B4VHhH6h.js +44 -0
  17. package/dist/assets/ts.worker-sl17zBDo.js +51316 -0
  18. package/dist/azcli-k1BiOau1.js +68 -0
  19. package/dist/bat-BIP72KWc.js +100 -0
  20. package/dist/bicep-VhQeYhS3.js +102 -0
  21. package/dist/cameligo-DnuAXtHg.js +174 -0
  22. package/dist/clojure-BAuDPsal.js +761 -0
  23. package/dist/coffee-BV06qSnj.js +232 -0
  24. package/dist/components.js +3595 -0
  25. package/dist/composables.js +72 -0
  26. package/dist/cpp-Cz8Jeyrf.js +389 -0
  27. package/dist/csharp-F6hhlXFb.js +326 -0
  28. package/dist/csp-KzlEHCyI.js +53 -0
  29. package/dist/css-e4FKntZ3.js +187 -0
  30. package/dist/cssMode-uz9U6SUU.js +1571 -0
  31. package/dist/cypher-CpvDGKRr.js +263 -0
  32. package/dist/dart-DdHeFWR0.js +281 -0
  33. package/dist/dockerfile-aoNXDcio.js +130 -0
  34. package/dist/ecl-C4Q0DYuA.js +456 -0
  35. package/dist/editor.api-CgD9w0gG.js +77091 -0
  36. package/dist/editor.main-Du02abDl.js +33783 -0
  37. package/dist/elixir-C9X42b0T.js +569 -0
  38. package/dist/flow9-Bff42pfB.js +142 -0
  39. package/dist/freemarker2-DFLX4iQ-.js +989 -0
  40. package/dist/fsharp-C6vPAsHG.js +217 -0
  41. package/dist/go-DEr8zx9f.js +218 -0
  42. package/dist/graphql-BiNBBRFh.js +151 -0
  43. package/dist/handlebars-aiZbIuWY.js +419 -0
  44. package/dist/hcl-2T9lKuFg.js +183 -0
  45. package/dist/html-phzTMObN.js +308 -0
  46. package/dist/htmlMode-BF7wMi3N.js +1581 -0
  47. package/dist/index.js +89 -0
  48. package/dist/ini-CZGtssYM.js +71 -0
  49. package/dist/ini.contribution-DyWtiacL.js +8 -0
  50. package/dist/java-B260NeH3.js +232 -0
  51. package/dist/javascript-BKKOItMi.js +70 -0
  52. package/dist/jsonMode-CDYK4B5l.js +1996 -0
  53. package/dist/julia-kuNLM9c5.js +511 -0
  54. package/dist/kotlin-Bz6kAefA.js +253 -0
  55. package/dist/less-AZUtS89I.js +162 -0
  56. package/dist/lexon-BcmgnyRb.js +157 -0
  57. package/dist/liquid-B2eRz5SA.js +240 -0
  58. package/dist/lua-Dz1RbATg.js +162 -0
  59. package/dist/m3-CIMooLFn.js +210 -0
  60. package/dist/markdown-C1BsCK9P.js +229 -0
  61. package/dist/markdown.contribution-DYYk6zUU.js +7 -0
  62. package/dist/mdx-BfV1HDRG.js +165 -0
  63. package/dist/mips-BovsnfLQ.js +198 -0
  64. package/dist/monaco.contribution-C-bQhUTI.js +114 -0
  65. package/dist/monaco.contribution-CCVvl3Jx.js +72 -0
  66. package/dist/monaco.contribution-Col-f0XR.js +164 -0
  67. package/dist/monaco.contribution-b5xkgQ-s.js +112 -0
  68. package/dist/msdax-CiRB2ZB-.js +375 -0
  69. package/dist/mysql-BwdpPE19.js +878 -0
  70. package/dist/objective-c-D4nfHfso.js +183 -0
  71. package/dist/pascal--j5-PYtz.js +251 -0
  72. package/dist/pascaligo-C7TcJxNL.js +164 -0
  73. package/dist/perl-BzEWqUb5.js +626 -0
  74. package/dist/pgsql-B_KZ0mGX.js +851 -0
  75. package/dist/php-A19QHzQV.js +500 -0
  76. package/dist/pla-COeKY1hA.js +137 -0
  77. package/dist/postiats-BfMp7zJL.js +907 -0
  78. package/dist/powerquery-B0TS_5Gb.js +890 -0
  79. package/dist/powershell-5jSbKdYB.js +239 -0
  80. package/dist/protobuf-YgnOutn3.js +420 -0
  81. package/dist/pug-DLej6kn5.js +402 -0
  82. package/dist/python-CQrZx9mR.js +301 -0
  83. package/dist/python.contribution-CcKs2Ktm.js +8 -0
  84. package/dist/qsharp-AhjqtSHB.js +301 -0
  85. package/dist/r-D-F4P80w.js +243 -0
  86. package/dist/razor-DWmpHMcx.js +550 -0
  87. package/dist/redis-hwwIlMnV.js +302 -0
  88. package/dist/redshift-Bcm_kjEG.js +809 -0
  89. package/dist/restructuredtext-CrdzfPP-.js +174 -0
  90. package/dist/ruby-QC2UNm1s.js +511 -0
  91. package/dist/rust-5aqiQ3L5.js +343 -0
  92. package/dist/sb-B1g1ZfLJ.js +115 -0
  93. package/dist/scala-C2U4R5Gb.js +370 -0
  94. package/dist/scheme-DeFRbslr.js +108 -0
  95. package/dist/scss-RSTCiCmI.js +262 -0
  96. package/dist/shell-BpF-iNu8.js +221 -0
  97. package/dist/shell.contribution-B80NZ3iO.js +7 -0
  98. package/dist/solidity-C00r2mbQ.js +1367 -0
  99. package/dist/sophia-DVW5ZKDB.js +199 -0
  100. package/dist/sparql-B0nmpxeX.js +201 -0
  101. package/dist/sql-CJwKPERn.js +853 -0
  102. package/dist/sql.contribution-DQy36aE5.js +7 -0
  103. package/dist/st-DPlKG5DT.js +416 -0
  104. package/dist/swift-YZBAbVHV.js +309 -0
  105. package/dist/systemverilog-CDQSaH63.js +576 -0
  106. package/dist/tcl-Dlu8sp6Q.js +232 -0
  107. package/dist/tsMode-Bh-v12OL.js +887 -0
  108. package/dist/twig-C5TO7-kw.js +392 -0
  109. package/dist/typescript-c7y6IZVP.js +343 -0
  110. package/dist/typespec-BsmjDEu7.js +117 -0
  111. package/dist/useFieldRendering-BIqeE3qo.js +6083 -0
  112. package/dist/vb-ChHvIDrk.js +372 -0
  113. package/dist/wgsl-XEp1ju8c.js +439 -0
  114. package/dist/xml-MAEprTnF.js +95 -0
  115. package/dist/xml.contribution-XMOaon8i.js +27 -0
  116. package/dist/yaml-C1p8rXG7.js +206 -0
  117. package/dist/yaml.contribution-DRRVhJmJ.js +8 -0
  118. package/package.json +88 -0
  119. package/src/__tests__/client-assigner.test.ts +341 -0
  120. package/src/__tests__/code-types.test.ts +30 -0
  121. package/src/__tests__/markdown-field.test.ts +34 -0
  122. package/src/__tests__/markdown-note-field.test.ts +135 -0
  123. package/src/__tests__/quiz-recorder.test.ts +195 -0
  124. package/src/__tests__/recorder-editor-content-sync.test.ts +172 -0
  125. package/src/__tests__/recorder-editor.test.ts +143 -0
  126. package/src/__tests__/recorder-render.test.ts +57 -0
  127. package/src/__tests__/recorder-wysiwyg-field-host.test.ts +33 -0
  128. package/src/__tests__/step-field.test.ts +270 -0
  129. package/src/__tests__/type-plugins.test.ts +59 -0
  130. package/src/__tests__/var-field-render.test.ts +26 -0
  131. package/src/client-assigner.ts +269 -0
  132. package/src/code-types.ts +94 -0
  133. package/src/components/AimdCodeField.vue +228 -0
  134. package/src/components/AimdDnaSequenceField.vue +983 -0
  135. package/src/components/AimdMarkdownField.vue +168 -0
  136. package/src/components/AimdMarkdownNoteField.vue +457 -0
  137. package/src/components/AimdQuizRecorder.vue +792 -0
  138. package/src/components/AimdRecorder.vue +1959 -0
  139. package/src/components/AimdRecorderEditor.vue +2281 -0
  140. package/src/components/AimdRecorderWysiwygFieldHost.vue +93 -0
  141. package/src/components/AimdRecorderWysiwygSurface.vue +487 -0
  142. package/src/components/AimdSeqVizViewer.vue +122 -0
  143. package/src/components/AimdStepCheckField.vue +453 -0
  144. package/src/components/AimdVarField.vue +213 -0
  145. package/src/components/AimdVarTableField.vue +516 -0
  146. package/src/components/DnaAnnotationEditor.vue +477 -0
  147. package/src/components/DnaSequenceEditor.vue +44 -0
  148. package/src/components/DnaSequenceToolbar.vue +98 -0
  149. package/src/components/DnaSequenceViewer.vue +162 -0
  150. package/src/components/index.ts +21 -0
  151. package/src/components/recorderMilkdownPlugin.ts +632 -0
  152. package/src/composables/__tests__/useDnaSequence.test.ts +467 -0
  153. package/src/composables/__tests__/useFieldAdapters.test.ts +115 -0
  154. package/src/composables/__tests__/useFocusManagement.test.ts +66 -0
  155. package/src/composables/__tests__/useRecordState.test.ts +586 -0
  156. package/src/composables/__tests__/useStepTimers.test.ts +64 -0
  157. package/src/composables/__tests__/useVarHelpers.test.ts +424 -0
  158. package/src/composables/__tests__/workbenchFieldEditing.test.ts +97 -0
  159. package/src/composables/index.ts +94 -0
  160. package/src/composables/useClientAssignerRunner.ts +74 -0
  161. package/src/composables/useDnaSequence.ts +400 -0
  162. package/src/composables/useDnaSequenceField.ts +316 -0
  163. package/src/composables/useFieldAdapters.ts +61 -0
  164. package/src/composables/useFieldRendering.ts +269 -0
  165. package/src/composables/useFocusManagement.ts +144 -0
  166. package/src/composables/useRecordState.ts +429 -0
  167. package/src/composables/useStepTimers.ts +243 -0
  168. package/src/composables/useVarHelpers.ts +545 -0
  169. package/src/composables/useVarTableDragDrop.ts +236 -0
  170. package/src/composables/workbenchFieldEditing.ts +705 -0
  171. package/src/css.d.ts +9 -0
  172. package/src/index.ts +65 -0
  173. package/src/locales.ts +559 -0
  174. package/src/monaco-code.ts +75 -0
  175. package/src/styles/aimd.css +994 -0
  176. package/src/type-plugins.ts +132 -0
  177. package/src/type-utils.ts +3 -0
  178. package/src/types.ts +191 -0
@@ -0,0 +1,545 @@
1
+ /**
2
+ * Pure helper functions for AIMD var field rendering.
3
+ *
4
+ * Extracted from AimdRecorder.vue to enable reuse across
5
+ * the recorder and the host-app rendering pipeline.
6
+ */
7
+
8
+ import { resolveAimdTypePlugin } from '../type-plugins'
9
+ import { isAimdCodeEditorType } from '../code-types'
10
+ import { normalizeAimdTypeName } from '../type-utils'
11
+ import type { AimdTypePlugin, AimdTypePluginParseContext, AimdTypePluginValueContext, AimdVarInputKind } from '../types'
12
+
13
+ // ---------------------------------------------------------------------------
14
+ // Types
15
+ // ---------------------------------------------------------------------------
16
+
17
+ export type VarInputKind = AimdVarInputKind
18
+
19
+ export interface VarInputKindOptions {
20
+ inputType?: string
21
+ codeLanguage?: string
22
+ typePlugin?: AimdTypePlugin
23
+ typePlugins?: AimdTypePlugin[]
24
+ }
25
+
26
+ export interface VarInputValueOptions extends VarInputKindOptions {
27
+ type?: string
28
+ nodeFieldKey?: string
29
+ fieldMeta?: Record<string, unknown>
30
+ }
31
+
32
+ function resolveOverrideInputKind(inputType: string | undefined, codeLanguage: string | undefined): VarInputKind | undefined {
33
+ if (isAimdCodeEditorType(undefined, { inputType, codeLanguage })) {
34
+ return 'code'
35
+ }
36
+
37
+ const normalized = normalizeAimdTypeName(inputType)
38
+
39
+ if (!normalized) {
40
+ return undefined
41
+ }
42
+
43
+ if (normalized === 'float' || normalized === 'int' || normalized === 'integer' || normalized === 'number') {
44
+ return 'number'
45
+ }
46
+
47
+ if (normalized === 'bool' || normalized === 'boolean' || normalized === 'checkbox') {
48
+ return 'checkbox'
49
+ }
50
+
51
+ if (normalized === 'date') {
52
+ return 'date'
53
+ }
54
+
55
+ if (normalized === 'datetime') {
56
+ return 'datetime'
57
+ }
58
+
59
+ if (normalized === 'time') {
60
+ return 'time'
61
+ }
62
+
63
+ if (normalized === 'markdown' || normalized === 'textarea' || normalized === 'md') {
64
+ return 'textarea'
65
+ }
66
+
67
+ if (normalized === 'dna') {
68
+ return 'dna'
69
+ }
70
+
71
+ if (normalized === 'file') {
72
+ return 'text'
73
+ }
74
+
75
+ if (normalized === 'text' || normalized === 'string') {
76
+ return 'text'
77
+ }
78
+
79
+ return undefined
80
+ }
81
+
82
+ // ---------------------------------------------------------------------------
83
+ // Type normalisation & input-kind resolution
84
+ // ---------------------------------------------------------------------------
85
+
86
+ export function normalizeVarTypeName(type: string | undefined): string {
87
+ return normalizeAimdTypeName(type)
88
+ }
89
+
90
+ export function getVarInputKind(type: string | undefined, options: VarInputKindOptions = {}): VarInputKind {
91
+ const override = resolveOverrideInputKind(options.inputType, options.codeLanguage)
92
+ if (override) {
93
+ return override
94
+ }
95
+
96
+ const typePlugin = options.typePlugin ?? resolveAimdTypePlugin(type, options.typePlugins)
97
+ if (typePlugin?.inputKind) {
98
+ return typePlugin.inputKind
99
+ }
100
+
101
+ const normalized = normalizeVarTypeName(type)
102
+
103
+ if (normalized === "float" || normalized === "int" || normalized === "integer" || normalized === "number") {
104
+ return "number"
105
+ }
106
+
107
+ if (normalized === "bool" || normalized === "boolean" || normalized === "checkbox") {
108
+ return "checkbox"
109
+ }
110
+
111
+ if (normalized === "date") {
112
+ return "date"
113
+ }
114
+
115
+ if (normalized === "datetime" || normalized === "currenttime") {
116
+ return "datetime"
117
+ }
118
+
119
+ if (normalized === "time" || normalized === "duration") {
120
+ return "time"
121
+ }
122
+
123
+ if (normalized === "dnasequence") {
124
+ return "dna"
125
+ }
126
+
127
+ if (normalized === "md" || normalized === "markdown" || normalized === "airalogymarkdown") {
128
+ return "textarea"
129
+ }
130
+
131
+ if (isAimdCodeEditorType(type, { codeLanguage: options.codeLanguage })) {
132
+ return 'code'
133
+ }
134
+
135
+ return "text"
136
+ }
137
+
138
+ // ---------------------------------------------------------------------------
139
+ // Structured-value helpers
140
+ // ---------------------------------------------------------------------------
141
+
142
+ export function unwrapStructuredValue(value: unknown): unknown {
143
+ if (value && typeof value === "object" && !Array.isArray(value) && "value" in value) {
144
+ return (value as { value: unknown }).value
145
+ }
146
+ return value
147
+ }
148
+
149
+ export function toBooleanValue(value: unknown): boolean {
150
+ const normalized = unwrapStructuredValue(value)
151
+
152
+ if (typeof normalized === "boolean") {
153
+ return normalized
154
+ }
155
+ if (typeof normalized === "number") {
156
+ return normalized !== 0
157
+ }
158
+ if (typeof normalized === "string") {
159
+ const text = normalized.trim().toLowerCase()
160
+ if (text === "" || text === "false" || text === "0" || text === "no" || text === "off") {
161
+ return false
162
+ }
163
+ if (text === "true" || text === "1" || text === "yes" || text === "on") {
164
+ return true
165
+ }
166
+ }
167
+ return Boolean(normalized)
168
+ }
169
+
170
+ export function toDateValue(value: unknown): Date | null {
171
+ const normalized = unwrapStructuredValue(value)
172
+
173
+ if (normalized instanceof Date) {
174
+ return Number.isNaN(normalized.getTime()) ? null : normalized
175
+ }
176
+
177
+ if (typeof normalized === "number") {
178
+ const date = new Date(normalized)
179
+ return Number.isNaN(date.getTime()) ? null : date
180
+ }
181
+
182
+ if (typeof normalized === "string" && normalized.trim()) {
183
+ const text = normalized.trim().replace(/\s+/, "T")
184
+ const date = new Date(text)
185
+ return Number.isNaN(date.getTime()) ? null : date
186
+ }
187
+
188
+ return null
189
+ }
190
+
191
+ // ---------------------------------------------------------------------------
192
+ // Date formatting
193
+ // ---------------------------------------------------------------------------
194
+
195
+ function pad2(value: number): string {
196
+ return String(value).padStart(2, "0")
197
+ }
198
+
199
+ function formatTimezoneOffset(date: Date): string {
200
+ const totalMinutes = -date.getTimezoneOffset()
201
+ const sign = totalMinutes >= 0 ? "+" : "-"
202
+ const absMinutes = Math.abs(totalMinutes)
203
+ const hours = Math.floor(absMinutes / 60)
204
+ const minutes = absMinutes % 60
205
+ return `${sign}${pad2(hours)}:${pad2(minutes)}`
206
+ }
207
+
208
+ export function formatDateTimeWithTimezone(date: Date): string {
209
+ const year = date.getFullYear()
210
+ const month = pad2(date.getMonth() + 1)
211
+ const day = pad2(date.getDate())
212
+ const hour = pad2(date.getHours())
213
+ const minute = pad2(date.getMinutes())
214
+ return `${year}-${month}-${day}T${hour}:${minute}${formatTimezoneOffset(date)}`
215
+ }
216
+
217
+ export function normalizeDateTimeValueWithTimezone(value: unknown): unknown {
218
+ const normalized = unwrapStructuredValue(value)
219
+
220
+ if (typeof normalized === "string") {
221
+ const text = normalized.trim()
222
+ if (!text) {
223
+ return ""
224
+ }
225
+
226
+ const normalizedText = text.replace(" ", "T")
227
+ if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/.test(normalizedText)) {
228
+ return normalizedText
229
+ }
230
+
231
+ const parsed = new Date(normalizedText)
232
+ return Number.isNaN(parsed.getTime()) ? value : formatDateTimeWithTimezone(parsed)
233
+ }
234
+
235
+ if (normalized === null || typeof normalized === "undefined") {
236
+ return ""
237
+ }
238
+
239
+ const parsed = toDateValue(normalized)
240
+ return parsed ? formatDateTimeWithTimezone(parsed) : value
241
+ }
242
+
243
+ export function formatDateForInput(value: unknown, kind: "date" | "datetime" | "time"): string {
244
+ const normalized = unwrapStructuredValue(value)
245
+
246
+ if (typeof normalized === "string" && normalized.trim()) {
247
+ const text = normalized.trim()
248
+
249
+ if (kind === "date" && /^\d{4}-\d{2}-\d{2}/.test(text)) {
250
+ return text.slice(0, 10)
251
+ }
252
+
253
+ if (kind === "datetime") {
254
+ const normalizedText = text.replace(" ", "T")
255
+ if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(normalizedText)) {
256
+ return normalizedText.slice(0, 16)
257
+ }
258
+ }
259
+
260
+ if (kind === "time" && /^\d{2}:\d{2}/.test(text)) {
261
+ return text.slice(0, 8)
262
+ }
263
+ }
264
+
265
+ const date = toDateValue(normalized)
266
+ if (!date) {
267
+ return ""
268
+ }
269
+
270
+ const year = date.getFullYear()
271
+ const month = pad2(date.getMonth() + 1)
272
+ const day = pad2(date.getDate())
273
+ const hour = pad2(date.getHours())
274
+ const minute = pad2(date.getMinutes())
275
+ const second = pad2(date.getSeconds())
276
+
277
+ if (kind === "date") {
278
+ return `${year}-${month}-${day}`
279
+ }
280
+ if (kind === "time") {
281
+ return `${hour}:${minute}:${second}`
282
+ }
283
+ return `${year}-${month}-${day}T${hour}:${minute}`
284
+ }
285
+
286
+ // ---------------------------------------------------------------------------
287
+ // Display / parse values
288
+ // ---------------------------------------------------------------------------
289
+
290
+ export function getVarInputDisplayValue(
291
+ value: unknown,
292
+ kind: VarInputKind,
293
+ options: VarInputValueOptions = {},
294
+ ): string | number {
295
+ const typePlugin = options.typePlugin
296
+ if (typePlugin?.getDisplayValue) {
297
+ const context: AimdTypePluginValueContext = {
298
+ type: options.type || 'str',
299
+ normalizedType: normalizeVarTypeName(options.type),
300
+ fieldKey: options.nodeFieldKey ?? '',
301
+ node: {} as never,
302
+ value,
303
+ inputKind: kind,
304
+ fieldMeta: options.fieldMeta as never,
305
+ }
306
+ return typePlugin.getDisplayValue(context)
307
+ }
308
+
309
+ const normalized = unwrapStructuredValue(value)
310
+
311
+ if (kind === "date" || kind === "datetime" || kind === "time") {
312
+ return formatDateForInput(normalized, kind)
313
+ }
314
+
315
+ if (kind === "number") {
316
+ return typeof normalized === "number" ? normalized : (typeof normalized === "string" ? normalized : "")
317
+ }
318
+
319
+ if (kind === "dna") {
320
+ return typeof normalized === "string" ? normalized : JSON.stringify(normalized)
321
+ }
322
+
323
+ if (typeof normalized === "string") {
324
+ return normalized
325
+ }
326
+
327
+ if (normalized === null || typeof normalized === "undefined") {
328
+ return ""
329
+ }
330
+
331
+ return String(normalized)
332
+ }
333
+
334
+ export function parseVarInputValue(
335
+ rawValue: string,
336
+ type: string | undefined,
337
+ kind: VarInputKind,
338
+ options: VarInputValueOptions = {},
339
+ ): unknown {
340
+ const typePlugin = options.typePlugin ?? resolveAimdTypePlugin(type, options.typePlugins)
341
+ if (typePlugin?.parseInputValue) {
342
+ const context: AimdTypePluginParseContext = {
343
+ type: type || 'str',
344
+ normalizedType: normalizeVarTypeName(type),
345
+ fieldKey: options.nodeFieldKey ?? '',
346
+ node: {} as never,
347
+ rawValue,
348
+ inputKind: kind,
349
+ fieldMeta: options.fieldMeta as never,
350
+ }
351
+ return typePlugin.parseInputValue(context)
352
+ }
353
+
354
+ const normalizedType = normalizeVarTypeName(type)
355
+
356
+ if (kind === "datetime") {
357
+ return normalizeDateTimeValueWithTimezone(rawValue)
358
+ }
359
+
360
+ if (kind === "number") {
361
+ const text = rawValue.trim()
362
+ if (!text) {
363
+ return ""
364
+ }
365
+ const parsed = normalizedType === "int" || normalizedType === "integer"
366
+ ? Number.parseInt(text, 10)
367
+ : Number.parseFloat(text)
368
+ return Number.isNaN(parsed) ? rawValue : parsed
369
+ }
370
+
371
+ return rawValue
372
+ }
373
+
374
+ // ---------------------------------------------------------------------------
375
+ // Width calculation helpers
376
+ // ---------------------------------------------------------------------------
377
+
378
+ function getVarControlMinWidth(inputKind: VarInputKind): number {
379
+ switch (inputKind) {
380
+ case "textarea":
381
+ case "dna":
382
+ case "code":
383
+ return 160
384
+ default:
385
+ return 0
386
+ }
387
+ }
388
+
389
+ function getVarControlExtraWidth(inputKind: VarInputKind): number {
390
+ switch (inputKind) {
391
+ case "datetime":
392
+ return 36
393
+ case "date":
394
+ return 32
395
+ case "time":
396
+ return 28
397
+ default:
398
+ return 4
399
+ }
400
+ }
401
+
402
+ export function calculateVarStackWidth(name: string, inputKind: VarInputKind): string {
403
+ const labelChars = Math.max(name.length + 7, 10)
404
+ const approximateCharWidth = 8
405
+ const horizontalPadding = 16
406
+ const widthPx = Math.round(labelChars * approximateCharWidth + horizontalPadding)
407
+ const minWidthPx = getVarControlMinWidth(inputKind)
408
+ const finalWidthPx = Math.max(minWidthPx, widthPx)
409
+
410
+ return `${finalWidthPx}px`
411
+ }
412
+
413
+ function parsePx(value: string): number {
414
+ const parsed = Number.parseFloat(value)
415
+ return Number.isFinite(parsed) ? parsed : 0
416
+ }
417
+
418
+ let varTextMeasureCanvas: HTMLCanvasElement | null = null
419
+
420
+ function getMeasureContext(): CanvasRenderingContext2D | null {
421
+ if (typeof window === "undefined") {
422
+ return null
423
+ }
424
+
425
+ if (!varTextMeasureCanvas) {
426
+ varTextMeasureCanvas = document.createElement("canvas")
427
+ }
428
+
429
+ return varTextMeasureCanvas.getContext("2d")
430
+ }
431
+
432
+ function measureStyledTextWidth(text: string, computed: CSSStyleDeclaration): number {
433
+ const ctx = getMeasureContext()
434
+ if (!ctx) {
435
+ return 0
436
+ }
437
+
438
+ const fontSize = computed.fontSize || "16px"
439
+ const fontFamily = computed.fontFamily || "sans-serif"
440
+ const fontWeight = computed.fontWeight || "400"
441
+ const fontStyle = computed.fontStyle || "normal"
442
+ ctx.font = `${fontStyle} ${fontWeight} ${fontSize} ${fontFamily}`
443
+
444
+ return ctx.measureText(text).width
445
+ }
446
+
447
+ function measureLabelTokenWidth(token: HTMLElement): number {
448
+ if (typeof window === "undefined") {
449
+ return token.scrollWidth
450
+ }
451
+
452
+ const computed = window.getComputedStyle(token)
453
+ const text = (token.textContent || "").trim()
454
+ const textWidth = measureStyledTextWidth(text, computed)
455
+ const horizontal =
456
+ parsePx(computed.paddingLeft)
457
+ + parsePx(computed.paddingRight)
458
+ + parsePx(computed.borderLeftWidth)
459
+ + parsePx(computed.borderRightWidth)
460
+ + parsePx(computed.marginLeft)
461
+ + parsePx(computed.marginRight)
462
+
463
+ return textWidth + horizontal
464
+ }
465
+
466
+ export function measureVarLabelWidth(wrapper: HTMLElement): number {
467
+ const scope = wrapper.querySelector(".aimd-field__scope--var") as HTMLElement | null
468
+ const id = wrapper.querySelector(".aimd-field__id") as HTMLElement | null
469
+ if (scope && id) {
470
+ return measureLabelTokenWidth(scope) + measureLabelTokenWidth(id) + 4
471
+ }
472
+
473
+ const fallbackLabel = wrapper.querySelector(".aimd-field__label") as HTMLElement | null
474
+ return fallbackLabel ? fallbackLabel.scrollWidth + 2 : 0
475
+ }
476
+
477
+ export function measureSingleLineControlWidth(input: HTMLInputElement | HTMLTextAreaElement): number {
478
+ if (typeof window === "undefined") {
479
+ return input.scrollWidth
480
+ }
481
+
482
+ const ctx = getMeasureContext()
483
+ if (!ctx) {
484
+ return input.scrollWidth
485
+ }
486
+
487
+ const computed = window.getComputedStyle(input)
488
+ const fontSize = computed.fontSize || "16px"
489
+ const fontFamily = computed.fontFamily || "sans-serif"
490
+ const fontWeight = computed.fontWeight || "400"
491
+ const fontStyle = computed.fontStyle || "normal"
492
+ ctx.font = `${fontStyle} ${fontWeight} ${fontSize} ${fontFamily}`
493
+
494
+ const text = input.value || input.placeholder || ""
495
+ const textWidth = ctx.measureText(text).width
496
+ const padding = parsePx(computed.paddingLeft) + parsePx(computed.paddingRight)
497
+ return textWidth + padding + 2
498
+ }
499
+
500
+ // ---------------------------------------------------------------------------
501
+ // Textarea auto-height
502
+ // ---------------------------------------------------------------------------
503
+
504
+ export function syncAutoWrapTextareaHeight(textarea: HTMLTextAreaElement) {
505
+ if (typeof window === "undefined") {
506
+ return
507
+ }
508
+
509
+ const isCompactText = textarea.classList.contains("aimd-rec-inline__textarea--stacked-text")
510
+ textarea.style.height = "auto"
511
+ const computed = window.getComputedStyle(textarea)
512
+ const minHeight = isCompactText
513
+ ? (parsePx(computed.getPropertyValue("--rec-var-control-height")) || parsePx(computed.height))
514
+ : (parsePx(computed.minHeight) || parsePx(computed.height))
515
+
516
+ if (isCompactText && textarea.value.length === 0) {
517
+ textarea.style.height = `${Math.ceil(minHeight)}px`
518
+ return
519
+ }
520
+
521
+ const borderHeight = parsePx(computed.borderTopWidth) + parsePx(computed.borderBottomWidth)
522
+ const nextHeight = Math.max(minHeight, textarea.scrollHeight + borderHeight)
523
+ textarea.style.height = `${Math.ceil(nextHeight)}px`
524
+ }
525
+
526
+ export function applyVarStackWidth(target: HTMLElement, inputKind: VarInputKind) {
527
+ const wrapper = target.closest(".aimd-rec-inline--var-stacked") as HTMLElement | null
528
+ if (!wrapper || typeof window === "undefined") {
529
+ return
530
+ }
531
+
532
+ const labelWidth = measureVarLabelWidth(wrapper)
533
+
534
+ const minWidthPx = getVarControlMinWidth(inputKind)
535
+ let controlWidth = 0
536
+ const input = wrapper.querySelector(".aimd-rec-inline__input--stacked, .aimd-rec-inline__textarea--stacked-text") as
537
+ HTMLInputElement | HTMLTextAreaElement | null
538
+ if (input) {
539
+ controlWidth = measureSingleLineControlWidth(input) + getVarControlExtraWidth(inputKind)
540
+ }
541
+
542
+ const measuredWidth = Math.max(minWidthPx, labelWidth, controlWidth)
543
+ wrapper.style.width = `${Math.ceil(measuredWidth)}px`
544
+ wrapper.style.maxWidth = "100%"
545
+ }