intelligent-system-design-language 0.3.21 → 0.3.22

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 (42) hide show
  1. package/out/_isdlStyles.scss +63 -0
  2. package/out/cli/components/_isdlStyles.scss +63 -0
  3. package/out/cli/components/chat-card-generator.js +13 -10
  4. package/out/cli/components/chat-card-generator.js.map +1 -1
  5. package/out/cli/components/datamodel-generator.js +7 -0
  6. package/out/cli/components/datamodel-generator.js.map +1 -1
  7. package/out/cli/components/language-generator.js +1 -1
  8. package/out/cli/components/language-generator.js.map +1 -1
  9. package/out/cli/components/method-generator.js +513 -421
  10. package/out/cli/components/method-generator.js.map +1 -1
  11. package/out/cli/components/vue/base-components/vue-roll-visualizer.js +262 -85
  12. package/out/cli/components/vue/base-components/vue-roll-visualizer.js.map +1 -1
  13. package/out/cli/components/vue/vue-prompt-generator.js +22 -7
  14. package/out/cli/components/vue/vue-prompt-generator.js.map +1 -1
  15. package/out/cli/components/vue/vue-sheet-application-generator.js +17 -7
  16. package/out/cli/components/vue/vue-sheet-application-generator.js.map +1 -1
  17. package/out/cli/generator.js +32 -27
  18. package/out/cli/generator.js.map +1 -1
  19. package/out/extension/github/githubAuthProvider.js +71 -29
  20. package/out/extension/github/githubAuthProvider.js.map +1 -1
  21. package/out/extension/github/githubGistManager.js +4 -3
  22. package/out/extension/github/githubGistManager.js.map +1 -1
  23. package/out/extension/github/githubManager.js +5 -3
  24. package/out/extension/github/githubManager.js.map +1 -1
  25. package/out/extension/main.cjs +909 -532
  26. package/out/extension/main.cjs.map +3 -3
  27. package/out/extension/package.json +1 -1
  28. package/out/language/generated/ast.js +51 -2
  29. package/out/language/generated/ast.js.map +1 -1
  30. package/out/language/generated/grammar.js +742 -493
  31. package/out/language/generated/grammar.js.map +1 -1
  32. package/out/language/intelligent-system-design-language-validator.js +32 -2
  33. package/out/language/intelligent-system-design-language-validator.js.map +1 -1
  34. package/out/language/isdl-scope-provider.js +14 -1
  35. package/out/language/isdl-scope-provider.js.map +1 -1
  36. package/out/language/main.cjs +913 -569
  37. package/out/language/main.cjs.map +3 -3
  38. package/out/package.json +1 -1
  39. package/out/styles.scss +30 -15
  40. package/out/test/validating/diagnostics.test.js +40 -0
  41. package/out/test/validating/diagnostics.test.js.map +1 -1
  42. package/package.json +1 -1
@@ -1,8 +1,495 @@
1
1
  import { isRollParam, isTypeParam, } from '../../language/generated/ast.js';
2
- import { isReturnExpression, isAssignment, isBinaryExpression, isGroup, isVariableExpression, isLiteral, isRef, isNegExpression, isAccess, isMethodBlock, isIfStatement, isJS, isChatCard, isFleetingAccess, isHtmlExp, isRoll, isDamageRoll, isParentAccess, isParentAssignment, isVariableAssignment, isWhenExpressions, isShorthandComparisonExpression, isItemAccess, isExpression, isResourceExp, isBooleanExp, isSelfMethod, isAttributeExp, isArrayExpression, isEach, isParameter, isPrompt, isLabelParam, isTargetParam, IntelligentSystemDesignLanguageTerminals, isMathExpression, isMathEmptyExpression, isMathSingleExpression, isMathParamExpression, isInitiativeProperty, isStatusProperty, isUpdate, isUpdateParent, isUpdateSelf, isParentTypeCheckExpression, isParentPropertyRefExp, isSelfPropertyRefExp, isLogExpression, isTrackerExp, isVisibilityValue, isFunctionCall, isAction, isDocument, isIncrementDecrementAssignment, isQuickModifyAssignment, isVariableIncrementDecrementAssignment, isVariableQuickModifyAssignment, isParentIncrementDecrementAssignment, isParentQuickModifyAssignment, isLocationParam, isWidthParam, isHeightParam, isNumberRange, isTargetTypeCheckExpression, isTargetAccess, isTargetIncrementDecrementAssignment, isTargetQuickModifyAssignment, isTargetAssignment, isWait, isPlayAudio, isPlayAudioFile, isPlayAudioVolume, isDieField, isTimeLimitParam, isCombatMethods, isCombatProperty, isUserProperty, isMacroExecute, isMeasuredTemplateField, isStringChoiceField, isDamageTypeChoiceField, isDiceField, isDieChoicesParam, isDocumentChoicesExp, isDocumentChoiceExp, isTableField, isInventoryField, isProperty } from "../../language/generated/ast.js";
2
+ import { isReturnExpression, isAssignment, isBinaryExpression, isGroup, isVariableExpression, isLiteral, isRef, isNegExpression, isAccess, isMethodBlock, isIfStatement, isJS, isChatCard, isFleetingAccess, isHtmlExp, isRoll, isDamageRoll, isParentAccess, isParentAssignment, isVariableAssignment, isWhenExpressions, isShorthandComparisonExpression, isItemAccess, isExpression, isResourceExp, isBooleanExp, isSelfMethod, isAttributeExp, isArrayExpression, isEach, isParameter, isPrompt, isLabelParam, isTargetParam, IntelligentSystemDesignLanguageTerminals, isMathExpression, isMathEmptyExpression, isMathSingleExpression, isMathParamExpression, isInitiativeProperty, isStatusProperty, isUpdate, isUpdateParent, isUpdateSelf, isParentTypeCheckExpression, isParentPropertyRefExp, isSelfPropertyRefExp, isLogExpression, isTrackerExp, isVisibilityValue, isFunctionCall, isAction, isDocument, isIncrementDecrementAssignment, isQuickModifyAssignment, isVariableIncrementDecrementAssignment, isVariableQuickModifyAssignment, isParentIncrementDecrementAssignment, isParentQuickModifyAssignment, isLocationParam, isWidthParam, isHeightParam, isNumberRange, isTargetTypeCheckExpression, isTargetAccess, isTargetIncrementDecrementAssignment, isTargetQuickModifyAssignment, isTargetAssignment, isWait, isPlayAudio, isPlayAudioFile, isPlayAudioVolume, isDieField, isTimeLimitParam, isCombatMethods, isCombatProperty, isUserProperty, isMacroExecute, isMeasuredTemplateField, isStringChoiceField, isDamageTypeChoiceField, isDiceField, isDieChoicesParam, isDocumentChoicesExp, isDocumentChoiceExp, isTableField, isInventoryField, isProperty, isRollVisualizerValueParam, isPromptInputAccess } from "../../language/generated/ast.js";
3
3
  import { expandToNode, joinToNode } from 'langium/generate';
4
4
  import { getParentDocument, getPromptRegistryKey, getPromptVariable, getSystemPath, getTargetDocument, toMachineIdentifier } from './utils.js';
5
5
  import { AstUtils } from 'langium';
6
+ // Module-scoped copy used by the lifted translateDiceParts/translateDiceData.
7
+ // (translateExpression keeps its own identical nested humanize for its other call sites.)
8
+ function humanize(string) {
9
+ if (string == undefined) {
10
+ return "";
11
+ }
12
+ // Turn TitleCase into Title Case
13
+ // Ensure first letter of the string is capitalized
14
+ string = string.charAt(0).toUpperCase() + string.slice(1);
15
+ return string.replace(/([a-z])([A-Z])/g, '$1 $2');
16
+ }
17
+ // Build the subproperty key for a fleeting access (e.g. `opts.Boons` -> "Boons" / "boons").
18
+ // Prompt results are resolved with lowercased field-name keys (the datamodel stores prompt
19
+ // fields lowercased), so subproperty access on a prompt-backed fleeting must lowercase to
20
+ // match -- otherwise `opts.Boons` reads `undefined`. Other fleetings (rolls, etc.) expose
21
+ // real JS properties whose case must be preserved (e.g. `amount.total`), so the gate matters.
22
+ function fleetingSubProperty(expression) {
23
+ var _a;
24
+ if (expression.subProperty == undefined)
25
+ return undefined;
26
+ return isPrompt((_a = expression.variable.ref) === null || _a === void 0 ? void 0 : _a.value) ? expression.subProperty.toLowerCase() : expression.subProperty;
27
+ }
28
+ export function translateDiceParts(expression, noLabels = false) {
29
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37;
30
+ console.log("Translating Dice Part: ", expression.$type);
31
+ if (isLiteral(expression)) {
32
+ if (typeof expression.val == "string") {
33
+ return expandToNode `
34
+ "${expression.val}"
35
+ `;
36
+ }
37
+ return expandToNode `
38
+ "${expression.val}"
39
+ `;
40
+ }
41
+ if (isRef(expression)) {
42
+ // If string or number, return the value
43
+ if (typeof expression.val == "string" || typeof expression.val == "number") {
44
+ return expandToNode `
45
+ "${expression.val}"
46
+ `;
47
+ }
48
+ if (expression.val.ref == undefined) {
49
+ return;
50
+ }
51
+ if (expression.subProperties != undefined && expression.subProperties.length > 0) {
52
+ const subLabel = noLabels ? "" : `[${humanize(expression.subProperties[0])}]`;
53
+ return expandToNode `
54
+ "@${(_a = expression.val.ref) === null || _a === void 0 ? void 0 : _a.name}${expression.subProperties[0].toLowerCase()}${subLabel}"
55
+ `;
56
+ }
57
+ console.log("Ref:", `${expression.val.$refText}`);
58
+ if (IntelligentSystemDesignLanguageTerminals.DICE.test(`${expression.val}`)) {
59
+ return expandToNode `
60
+ "${expression.val}"
61
+ `;
62
+ }
63
+ const refLabel = noLabels ? "" : `[${humanize((_c = (_b = expression.val.ref) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : expression.val.$refText)}]`;
64
+ return expandToNode `
65
+ "@${(_f = (_e = (_d = expression.val.ref) === null || _d === void 0 ? void 0 : _d.name) === null || _e === void 0 ? void 0 : _e.toLowerCase()) !== null && _f !== void 0 ? _f : expression.val.$refText}${refLabel}"
66
+ `;
67
+ }
68
+ if (isParentAccess(expression)) {
69
+ let path = (_j = (_h = (_g = expression.property) === null || _g === void 0 ? void 0 : _g.ref) === null || _h === void 0 ? void 0 : _h.name) !== null && _j !== void 0 ? _j : "";
70
+ let label = humanize((_m = (_l = (_k = expression.property) === null || _k === void 0 ? void 0 : _k.ref) === null || _l === void 0 ? void 0 : _l.name) !== null && _m !== void 0 ? _m : "");
71
+ const document = getParentDocument(expression);
72
+ if (document != undefined) {
73
+ path = `${document.name.toLowerCase()}${path}`;
74
+ label = `${humanize(document.name)} ${label}`;
75
+ }
76
+ // else if ( expression.propertyLookup != undefined ) {
77
+ // path = `${path}${expression.propertyLookup.ref?.name.toLowerCase()}`;
78
+ // label = `${label} \${context.object.system.${expression.propertyLookup.ref?.name.toLowerCase()}\}`;
79
+ // }
80
+ else {
81
+ path = `${path}${(_p = (_o = expression.property) === null || _o === void 0 ? void 0 : _o.ref) === null || _p === void 0 ? void 0 : _p.name.toLowerCase()}`;
82
+ label = `${label} ${humanize((_s = (_r = (_q = expression.property) === null || _q === void 0 ? void 0 : _q.ref) === null || _r === void 0 ? void 0 : _r.name) !== null && _s !== void 0 ? _s : "")}`;
83
+ }
84
+ for (const subProperty of (_t = expression.subProperties) !== null && _t !== void 0 ? _t : []) {
85
+ path = `${path}${subProperty}`;
86
+ label = `${label} ${humanize(subProperty)}`;
87
+ }
88
+ label = label.trim();
89
+ const parentLabelSuffix = noLabels ? "" : `[${label}]`;
90
+ return expandToNode `
91
+ \`@${path.replaceAll(".", "").toLowerCase()}${parentLabelSuffix}\`
92
+ `;
93
+ }
94
+ if (isTargetAccess(expression)) {
95
+ let path = (_w = (_v = (_u = expression.property) === null || _u === void 0 ? void 0 : _u.ref) === null || _v === void 0 ? void 0 : _v.name) !== null && _w !== void 0 ? _w : "";
96
+ let label = humanize((_z = (_y = (_x = expression.property) === null || _x === void 0 ? void 0 : _x.ref) === null || _y === void 0 ? void 0 : _y.name) !== null && _z !== void 0 ? _z : "");
97
+ const document = getTargetDocument(expression);
98
+ if (document != undefined) {
99
+ path = `${document.name.toLowerCase()}${path}`;
100
+ label = `${humanize(document.name)} ${label}`;
101
+ }
102
+ // else if ( expression.propertyLookup != undefined ) {
103
+ // path = `${path}${expression.propertyLookup.ref?.name.toLowerCase()}`;
104
+ // label = `${label} \${context.object.system.${expression.propertyLookup.ref?.name.toLowerCase()}\}`;
105
+ // }
106
+ else {
107
+ path = `${path}${(_1 = (_0 = expression.property) === null || _0 === void 0 ? void 0 : _0.ref) === null || _1 === void 0 ? void 0 : _1.name.toLowerCase()}`;
108
+ label = `${label} ${humanize((_4 = (_3 = (_2 = expression.property) === null || _2 === void 0 ? void 0 : _2.ref) === null || _3 === void 0 ? void 0 : _3.name) !== null && _4 !== void 0 ? _4 : "")}`;
109
+ }
110
+ for (const subProperty of (_5 = expression.subProperties) !== null && _5 !== void 0 ? _5 : []) {
111
+ path = `${path}${subProperty}`;
112
+ label = `${label} ${humanize(subProperty)}`;
113
+ }
114
+ label = label.trim();
115
+ const targetLabelSuffix = noLabels ? "" : `[${label}]`;
116
+ return expandToNode `
117
+ \`@${path.replaceAll(".", "").toLowerCase()}${targetLabelSuffix}\`
118
+ `;
119
+ }
120
+ if (isPromptInputAccess(expression)) {
121
+ // `input.X` inside a prompt -> @<field> ref token (resolved at runtime from
122
+ // the live reactive prompt data, see translateDiceData).
123
+ let key = (_9 = (_8 = (_7 = (_6 = expression.property) === null || _6 === void 0 ? void 0 : _6.ref) === null || _7 === void 0 ? void 0 : _7.name) === null || _8 === void 0 ? void 0 : _8.toLowerCase()) !== null && _9 !== void 0 ? _9 : "";
124
+ for (const subProperty of (_10 = expression.subProperties) !== null && _10 !== void 0 ? _10 : []) {
125
+ key = `${key}.${subProperty}`;
126
+ }
127
+ return expandToNode `
128
+ \`@${key.replaceAll(".", "").toLowerCase()}\`
129
+ `;
130
+ }
131
+ if (isAccess(expression)) {
132
+ let path = (_18 = (_14 = (_13 = (_12 = (_11 = expression.property) === null || _11 === void 0 ? void 0 : _11.ref) === null || _12 === void 0 ? void 0 : _12.name) === null || _13 === void 0 ? void 0 : _13.toLowerCase()) !== null && _14 !== void 0 ? _14 : (_17 = (_16 = (_15 = expression.propertyLookup) === null || _15 === void 0 ? void 0 : _15.ref) === null || _16 === void 0 ? void 0 : _16.name) === null || _17 === void 0 ? void 0 : _17.toLowerCase()) !== null && _18 !== void 0 ? _18 : "";
133
+ let label = humanize((_24 = (_21 = (_20 = (_19 = expression.property) === null || _19 === void 0 ? void 0 : _19.ref) === null || _20 === void 0 ? void 0 : _20.name) !== null && _21 !== void 0 ? _21 : (_23 = (_22 = expression.propertyLookup) === null || _22 === void 0 ? void 0 : _22.ref) === null || _23 === void 0 ? void 0 : _23.name) !== null && _24 !== void 0 ? _24 : "");
134
+ // if (isDieField(expression.property?.ref)) {
135
+ // return expandToNode`
136
+ // \'@${path.replaceAll(".", "")}\'
137
+ // `;
138
+ // }
139
+ // Special handling for document choices - expand into individual terms
140
+ if (expression.property && isDocumentChoicesExp(expression.property.ref) && expression.subProperties && expression.subProperties.length > 0) {
141
+ const choicesFieldName = expression.property.ref.name.toLowerCase();
142
+ const subPropertyName = expression.subProperties[0].toLowerCase();
143
+ const subPropertyLabel = humanize(expression.subProperties[0]);
144
+ // Generate dynamic expansion for each document in the choices array
145
+ return expandToNode `
146
+ context.object.system.${choicesFieldName}.map((doc, index) => {
147
+ if (!doc || !doc.system) return '';
148
+ return '@' + doc.uuid.replace(/[^a-zA-Z0-9]/g, '').toLowerCase() + '${subPropertyName}[' + doc.name + ' ${subPropertyLabel}]';
149
+ }).filter(Boolean).join(' + ')
150
+ `;
151
+ }
152
+ if (isParentPropertyRefExp((_25 = expression.property) === null || _25 === void 0 ? void 0 : _25.ref)) {
153
+ label = `${label} - \${context.object.system.${(_27 = (_26 = expression.property) === null || _26 === void 0 ? void 0 : _26.ref) === null || _27 === void 0 ? void 0 : _27.name.toLowerCase()}.replace("system.", "").replaceAll(".", " ").titleCase()\}`;
154
+ }
155
+ else if (isSelfPropertyRefExp((_28 = expression.property) === null || _28 === void 0 ? void 0 : _28.ref)) {
156
+ label = `${label} - \${context.object.system.${(_30 = (_29 = expression.property) === null || _29 === void 0 ? void 0 : _29.ref) === null || _30 === void 0 ? void 0 : _30.name.toLowerCase()}.replace("system.", "").replaceAll(".", " ").titleCase()\}`;
157
+ }
158
+ else {
159
+ for (const subProperty of (_31 = expression.subProperties) !== null && _31 !== void 0 ? _31 : []) {
160
+ path = `${path}.${subProperty}`;
161
+ label = `${label} ${humanize(subProperty)}`;
162
+ }
163
+ }
164
+ console.log("Access:", path, label);
165
+ const accessLabelSuffix = noLabels ? "" : `[${label}]`;
166
+ return expandToNode `
167
+ \`@${path.replaceAll(".", "").toLowerCase()}${accessLabelSuffix}\`
168
+ `;
169
+ }
170
+ if (isFleetingAccess(expression)) {
171
+ // If this is a roll expression, just output it directly
172
+ if (isRoll((_32 = expression.variable.ref) === null || _32 === void 0 ? void 0 : _32.value)) {
173
+ return expandToNode `
174
+ ${(_33 = expression.variable.ref) === null || _33 === void 0 ? void 0 : _33.name}
175
+ `;
176
+ }
177
+ let path = (_35 = (_34 = expression.variable.ref) === null || _34 === void 0 ? void 0 : _34.name) !== null && _35 !== void 0 ? _35 : "";
178
+ let label = humanize((_37 = (_36 = expression.variable.ref) === null || _36 === void 0 ? void 0 : _36.name) !== null && _37 !== void 0 ? _37 : "");
179
+ if (expression.subProperty != undefined) {
180
+ path = `${path}.${fleetingSubProperty(expression)}`;
181
+ label = `${label} ${humanize(expression.subProperty)}`;
182
+ }
183
+ const fleetingLabelSuffix = noLabels ? "" : `[${label}]`;
184
+ return expandToNode `
185
+ \`@${path.replaceAll(".", "").toLowerCase()}${fleetingLabelSuffix}\`
186
+ `;
187
+ }
188
+ if (isBinaryExpression(expression)) {
189
+ return expandToNode `
190
+ ${translateDiceParts(expression.e1, noLabels)} + "${expression.op}" + ${translateDiceParts(expression.e2, noLabels)}
191
+ `;
192
+ }
193
+ if (isGroup(expression)) {
194
+ return expandToNode `
195
+ "(" + ${translateDiceParts(expression.ge, noLabels)} + ")"
196
+ `;
197
+ }
198
+ return;
199
+ }
200
+ function translateDisplayFormula(expression) {
201
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
202
+ if (isLiteral(expression)) {
203
+ return `${expression.val}`;
204
+ }
205
+ if (isGroup(expression)) {
206
+ const inner = translateDisplayFormula(expression.ge);
207
+ return inner != null ? `(${inner})` : undefined;
208
+ }
209
+ if (isBinaryExpression(expression)) {
210
+ const left = translateDisplayFormula(expression.e1);
211
+ const right = translateDisplayFormula(expression.e2);
212
+ return left != null && right != null ? `${left} ${expression.op} ${right}` : undefined;
213
+ }
214
+ if (isAccess(expression)) {
215
+ if (isParentPropertyRefExp((_a = expression.property) === null || _a === void 0 ? void 0 : _a.ref) || isSelfPropertyRefExp((_b = expression.property) === null || _b === void 0 ? void 0 : _b.ref)) {
216
+ return undefined;
217
+ }
218
+ let label = humanize((_h = (_e = (_d = (_c = expression.property) === null || _c === void 0 ? void 0 : _c.ref) === null || _d === void 0 ? void 0 : _d.name) !== null && _e !== void 0 ? _e : (_g = (_f = expression.propertyLookup) === null || _f === void 0 ? void 0 : _f.ref) === null || _g === void 0 ? void 0 : _g.name) !== null && _h !== void 0 ? _h : "");
219
+ for (const sub of (_j = expression.subProperties) !== null && _j !== void 0 ? _j : []) {
220
+ label += ` ${humanize(sub)}`;
221
+ }
222
+ return label.trim();
223
+ }
224
+ if (isParentAccess(expression)) {
225
+ return humanize((_m = (_l = (_k = expression.property) === null || _k === void 0 ? void 0 : _k.ref) === null || _l === void 0 ? void 0 : _l.name) !== null && _m !== void 0 ? _m : "");
226
+ }
227
+ if (isTargetAccess(expression)) {
228
+ return humanize((_q = (_p = (_o = expression.property) === null || _o === void 0 ? void 0 : _o.ref) === null || _p === void 0 ? void 0 : _p.name) !== null && _q !== void 0 ? _q : "");
229
+ }
230
+ if (isFleetingAccess(expression)) {
231
+ return humanize((_s = (_r = expression.variable.ref) === null || _r === void 0 ? void 0 : _r.name) !== null && _s !== void 0 ? _s : "");
232
+ }
233
+ return undefined;
234
+ }
235
+ export function translateDiceData(expression, entry, id, preDerived, generatingProperty) {
236
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61;
237
+ console.log("Translating Dice Data: ", expression.$type);
238
+ if (isParentAccess(expression)) {
239
+ let path = "context.object.parent.system";
240
+ let label = (_c = (_b = (_a = expression.property) === null || _a === void 0 ? void 0 : _a.ref) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : "";
241
+ console.log("Parent Access:", (_e = (_d = expression.property) === null || _d === void 0 ? void 0 : _d.ref) === null || _e === void 0 ? void 0 : _e.name);
242
+ const document = getParentDocument(expression);
243
+ if (document != undefined) {
244
+ path = `${path}.${(_h = (_g = (_f = expression.property) === null || _f === void 0 ? void 0 : _f.ref) === null || _g === void 0 ? void 0 : _g.name) === null || _h === void 0 ? void 0 : _h.toLowerCase()}`;
245
+ label = `${humanize(document.name)}.${label}`;
246
+ }
247
+ else {
248
+ path = `${path}.${(_l = (_k = (_j = expression.property) === null || _j === void 0 ? void 0 : _j.ref) === null || _k === void 0 ? void 0 : _k.name) === null || _l === void 0 ? void 0 : _l.toLowerCase()}`;
249
+ label = `${label}.${expression.property}`;
250
+ }
251
+ for (const subProperty of (_m = expression.subProperties) !== null && _m !== void 0 ? _m : []) {
252
+ path = `${path}.${subProperty}`;
253
+ label = `${label}.${subProperty}`;
254
+ }
255
+ return expandToNode `
256
+ "${label.replaceAll(".", "").toLowerCase()}": ${path}
257
+ `;
258
+ }
259
+ if (isTargetAccess(expression)) {
260
+ let path = "context.target.system";
261
+ let label = (_q = (_p = (_o = expression.property) === null || _o === void 0 ? void 0 : _o.ref) === null || _p === void 0 ? void 0 : _p.name) !== null && _q !== void 0 ? _q : "";
262
+ console.log("Target Access:", (_s = (_r = expression.property) === null || _r === void 0 ? void 0 : _r.ref) === null || _s === void 0 ? void 0 : _s.name);
263
+ const document = getTargetDocument(expression);
264
+ if (document != undefined) {
265
+ path = `${path}.${(_v = (_u = (_t = expression.property) === null || _t === void 0 ? void 0 : _t.ref) === null || _u === void 0 ? void 0 : _u.name) === null || _v === void 0 ? void 0 : _v.toLowerCase()}`;
266
+ label = `${humanize(document.name)}.${label}`;
267
+ }
268
+ else {
269
+ path = `${path}.${(_y = (_x = (_w = expression.property) === null || _w === void 0 ? void 0 : _w.ref) === null || _x === void 0 ? void 0 : _x.name) === null || _y === void 0 ? void 0 : _y.toLowerCase()}`;
270
+ label = `${label}.${expression.property}`;
271
+ }
272
+ for (const subProperty of (_z = expression.subProperties) !== null && _z !== void 0 ? _z : []) {
273
+ path = `${path}.${subProperty}`;
274
+ label = `${label}.${subProperty}`;
275
+ }
276
+ return expandToNode `
277
+ "${label.replaceAll(".", "").toLowerCase()}": ${path}
278
+ `;
279
+ }
280
+ if (isPromptInputAccess(expression)) {
281
+ // Resolve `input.X` to the LIVE reactive prompt path the input writes to:
282
+ // context.system.<action><variable>.<field>. Editing the input recomputes
283
+ // any binding that reads this (the rollVisualizer's :rollData).
284
+ const prompt = AstUtils.getContainerOfType(expression, isPrompt);
285
+ const variable = AstUtils.getContainerOfType(prompt === null || prompt === void 0 ? void 0 : prompt.$container, isVariableExpression);
286
+ const action = AstUtils.getContainerOfType(prompt === null || prompt === void 0 ? void 0 : prompt.$container, isAction);
287
+ const promptPath = `${(_0 = action === null || action === void 0 ? void 0 : action.name.toLowerCase()) !== null && _0 !== void 0 ? _0 : ""}${(_1 = variable === null || variable === void 0 ? void 0 : variable.name.toLowerCase()) !== null && _1 !== void 0 ? _1 : ""}`;
288
+ const ref = (_2 = expression.property) === null || _2 === void 0 ? void 0 : _2.ref;
289
+ const fieldName = (_4 = (_3 = ref === null || ref === void 0 ? void 0 : ref.name) === null || _3 === void 0 ? void 0 : _3.toLowerCase()) !== null && _4 !== void 0 ? _4 : "";
290
+ const base = `context.system.${promptPath}.${fieldName}`;
291
+ const hasSub = ((_6 = (_5 = expression.subProperties) === null || _5 === void 0 ? void 0 : _5.length) !== null && _6 !== void 0 ? _6 : 0) > 0;
292
+ // A dice prompt input is stored as {die, number} (its `.value` formula is derived
293
+ // data, which a prompt doesn't compute). Build the "<number><die>" formula string
294
+ // so it drops into the roll as e.g. "2d6"; reading both keeps it reactive.
295
+ if (isDiceField(ref) && !hasSub) {
296
+ return expandToNode `
297
+ "${fieldName}": \`\${${base}.number}\${${base}.die}\`
298
+ `;
299
+ }
300
+ // A die prompt input is stored as the die string itself (e.g. "d8").
301
+ if (isDieField(ref) && !hasSub) {
302
+ return expandToNode `
303
+ "${fieldName}": ${base}
304
+ `;
305
+ }
306
+ let key = fieldName;
307
+ let dataPath = base;
308
+ for (const subProperty of (_7 = expression.subProperties) !== null && _7 !== void 0 ? _7 : []) {
309
+ key = `${key}.${subProperty}`;
310
+ dataPath = `${dataPath}.${subProperty.toLowerCase()}`;
311
+ }
312
+ return expandToNode `
313
+ "${key.replaceAll(".", "").toLowerCase()}": ${dataPath} ?? 0
314
+ `;
315
+ }
316
+ if (isAccess(expression)) {
317
+ let path = "context.object.system";
318
+ let label = "";
319
+ console.log("Access:", (_9 = (_8 = expression.property) === null || _8 === void 0 ? void 0 : _8.ref) === null || _9 === void 0 ? void 0 : _9.name, (_11 = (_10 = expression.propertyLookup) === null || _10 === void 0 ? void 0 : _10.ref) === null || _11 === void 0 ? void 0 : _11.name);
320
+ if (expression.propertyLookup != undefined) {
321
+ path = `${path}[context.object.${getSystemPath(expression.propertyLookup.ref)}.toLowerCase()]`;
322
+ label = `${(_12 = expression.propertyLookup.ref) === null || _12 === void 0 ? void 0 : _12.name}`;
323
+ }
324
+ else if (isParentPropertyRefExp((_13 = expression.property) === null || _13 === void 0 ? void 0 : _13.ref)) {
325
+ path = `${path}.${(_15 = (_14 = expression.property) === null || _14 === void 0 ? void 0 : _14.ref) === null || _15 === void 0 ? void 0 : _15.name.toLowerCase()}`;
326
+ label = `${(_17 = (_16 = expression.property) === null || _16 === void 0 ? void 0 : _16.ref) === null || _17 === void 0 ? void 0 : _17.name}`;
327
+ let subProperty = "";
328
+ if (((_18 = expression.property) === null || _18 === void 0 ? void 0 : _18.ref.propertyType) == "resource" || ((_19 = expression.property) === null || _19 === void 0 ? void 0 : _19.ref.propertyType) == "tracker" || ((_20 = expression.property) === null || _20 === void 0 ? void 0 : _20.ref.propertyType) == "choice"
329
+ && (expression.subProperties == undefined || expression.subProperties.length == 0 || expression.subProperties[0] !== "value")) {
330
+ subProperty = "?.value";
331
+ }
332
+ if (((_21 = expression.property) === null || _21 === void 0 ? void 0 : _21.ref.propertyType) == "attribute" && (expression.subProperties == undefined || expression.subProperties.length == 0 || expression.subProperties[0] !== "mod")) {
333
+ subProperty = "?.mod";
334
+ }
335
+ console.log(label, path);
336
+ return expandToNode `
337
+ "${label.replaceAll(".", "").replaceAll(" ", "").toLowerCase()}": foundry.utils.getProperty(context.object.parent, ${path}.toLowerCase())${subProperty}
338
+ `;
339
+ }
340
+ else if (isSelfPropertyRefExp((_22 = expression.property) === null || _22 === void 0 ? void 0 : _22.ref)) {
341
+ // For self property references, we dynamically resolve the property path
342
+ let selfPropertyPath = `context.object.system.${(_24 = (_23 = expression.property) === null || _23 === void 0 ? void 0 : _23.ref) === null || _24 === void 0 ? void 0 : _24.name.toLowerCase()}`;
343
+ let subProperty = "";
344
+ label = `${(_26 = (_25 = expression.property) === null || _25 === void 0 ? void 0 : _25.ref) === null || _26 === void 0 ? void 0 : _26.name}`;
345
+ if (((_27 = expression.property) === null || _27 === void 0 ? void 0 : _27.ref.propertyType) == "resource" || ((_28 = expression.property) === null || _28 === void 0 ? void 0 : _28.ref.propertyType) == "tracker" || ((_29 = expression.property) === null || _29 === void 0 ? void 0 : _29.ref.propertyType) == "choice"
346
+ && (expression.subProperties == undefined || expression.subProperties.length == 0 || expression.subProperties[0] !== "value")) {
347
+ subProperty = "?.value";
348
+ }
349
+ if (((_30 = expression.property) === null || _30 === void 0 ? void 0 : _30.ref.propertyType) == "attribute" && (expression.subProperties == undefined || expression.subProperties.length == 0 || expression.subProperties[0] !== "mod")) {
350
+ subProperty = "?.mod";
351
+ }
352
+ console.log(label, selfPropertyPath);
353
+ return expandToNode `
354
+ "${label.replaceAll(".", "").replaceAll(" ", "").toLowerCase()}": foundry.utils.getProperty(context.object, "system." + ${selfPropertyPath}.toLowerCase())${subProperty}
355
+ `;
356
+ }
357
+ else {
358
+ // Special handling for document choices - expand into individual data entries
359
+ if (expression.property && isDocumentChoicesExp(expression.property.ref) && expression.subProperties && expression.subProperties.length > 0) {
360
+ const choicesFieldName = expression.property.ref.name.toLowerCase();
361
+ const subPropertyName = expression.subProperties[0].toLowerCase();
362
+ // Generate data for each document in the choices array
363
+ return expandToNode `
364
+ ...Object.fromEntries(context.object.system.${choicesFieldName}.map((doc, index) => {
365
+ if (!doc || !doc.system) return null;
366
+
367
+ // Determine the accessor based on property type
368
+ let accessor = '.${subPropertyName}';
369
+ ${isResourceExp((_31 = expression.property) === null || _31 === void 0 ? void 0 : _31.ref) || isTrackerExp((_32 = expression.property) === null || _32 === void 0 ? void 0 : _32.ref) ? `
370
+ if (doc.system.${subPropertyName} && typeof doc.system.${subPropertyName} === 'object' && 'value' in doc.system.${subPropertyName}) {
371
+ accessor = '.${subPropertyName}.value';
372
+ }` : ''}
373
+ ${isAttributeExp((_33 = expression.property) === null || _33 === void 0 ? void 0 : _33.ref) ? `
374
+ if (doc.system.${subPropertyName} && typeof doc.system.${subPropertyName} === 'object' && 'mod' in doc.system.${subPropertyName}) {
375
+ accessor = '.${subPropertyName}.mod';
376
+ }` : ''}
377
+
378
+ const key = doc.uuid.replace(/[^a-zA-Z0-9]/g, '').toLowerCase() + '${subPropertyName}';
379
+ const value = foundry.utils.getProperty(doc, 'system' + accessor) ?? 0;
380
+ return [key, value];
381
+ }).filter(Boolean))
382
+ `;
383
+ }
384
+ path = `${path}.${(_35 = (_34 = expression.property) === null || _34 === void 0 ? void 0 : _34.ref) === null || _35 === void 0 ? void 0 : _35.name.toLowerCase()}`;
385
+ label = `${(_37 = (_36 = expression.property) === null || _36 === void 0 ? void 0 : _36.ref) === null || _37 === void 0 ? void 0 : _37.name}`;
386
+ if ((isResourceExp((_38 = expression.property) === null || _38 === void 0 ? void 0 : _38.ref) || isTrackerExp((_39 = expression.property) === null || _39 === void 0 ? void 0 : _39.ref) || isStringChoiceField((_40 = expression.property) === null || _40 === void 0 ? void 0 : _40.ref))
387
+ && (expression.subProperties == undefined || expression.subProperties.length == 0 || expression.subProperties[0] == "value")) {
388
+ path = `${path}.value`;
389
+ }
390
+ if (isDiceField((_41 = expression.property) === null || _41 === void 0 ? void 0 : _41.ref) && (expression.subProperties == undefined || expression.subProperties.length == 0)) {
391
+ // For dice fields without subproperties, use the dice value
392
+ path = `${path}.value`;
393
+ }
394
+ if (isDieField((_42 = expression.property) === null || _42 === void 0 ? void 0 : _42.ref)) {
395
+ // For die fields, the value is just the die size (e.g., "d6"), we want to use the field name as label
396
+ // Don't change the path, just ensure the label is the field name
397
+ }
398
+ if (isAttributeExp((_43 = expression.property) === null || _43 === void 0 ? void 0 : _43.ref) && (expression.subProperties == undefined || expression.subProperties.length == 0 || expression.subProperties[0] !== "mod")) {
399
+ path = `${path}.mod`;
400
+ }
401
+ }
402
+ for (const subProperty of (_44 = expression.subProperties) !== null && _44 !== void 0 ? _44 : []) {
403
+ path = `${path}.${subProperty}`;
404
+ label = `${label} ${humanize(subProperty)}`;
405
+ }
406
+ console.log(label, path);
407
+ return expandToNode `
408
+ "${label.replaceAll(".", "").replaceAll(" ", "").toLowerCase()}": ${path} ?? 0
409
+ `;
410
+ }
411
+ if (isFleetingAccess(expression)) {
412
+ console.log("Fleeting Access:", (_45 = expression.variable.ref) === null || _45 === void 0 ? void 0 : _45.name);
413
+ // If this is a roll expression, just skip it
414
+ if (isRoll((_46 = expression.variable.ref) === null || _46 === void 0 ? void 0 : _46.value)) {
415
+ return;
416
+ }
417
+ let path = (_47 = expression.variable.ref) === null || _47 === void 0 ? void 0 : _47.name;
418
+ // The roll-data key must match the formula's `@`-reference, which collapses the
419
+ // dotted path and lowercases it (see translateDiceParts: `@answer.bonus` -> `@answerbonus`).
420
+ let label = (_50 = (_49 = (_48 = expression.variable.ref) === null || _48 === void 0 ? void 0 : _48.name) === null || _49 === void 0 ? void 0 : _49.toLowerCase()) !== null && _50 !== void 0 ? _50 : "";
421
+ if (expression.subProperty != undefined) {
422
+ path = `${path}.${fleetingSubProperty(expression)}`;
423
+ label = `${label}${expression.subProperty.toLowerCase()}`;
424
+ }
425
+ if (expression.arrayAccess != undefined) {
426
+ console.log("Array Access:", expression.arrayAccess.$type);
427
+ let accessExp = translateExpression(entry, id, expression.arrayAccess, preDerived, generatingProperty);
428
+ path = `${path}[${(_51 = accessExp === null || accessExp === void 0 ? void 0 : accessExp.contents) === null || _51 === void 0 ? void 0 : _51.toString()}]`;
429
+ }
430
+ console.log(label, path);
431
+ return expandToNode `
432
+ "${label}": ${path} ?? 0
433
+ `;
434
+ }
435
+ // if (isVariableAccess(expression)) {
436
+ // console.log("Variable Access:", expression.name);
437
+ // if (isParameter(expression)) {
438
+ // console.log("Parameter:", expression.name);
439
+ // return expandToNode`
440
+ // "${expression.name}": ${expression.name}
441
+ // `;
442
+ // }
443
+ // if (isVariableExpression(expression)) {
444
+ // console.log("Variable Expression:", expression.name);
445
+ // if (isExpression(expression.value)) {
446
+ // console.log("Expression:", expression.name);
447
+ // return translateDiceData(expression.value);
448
+ // }
449
+ // if (isPrompt(expression.value)) {
450
+ // console.log("Prompt:", expression.name);
451
+ // return expandToNode`
452
+ // "${expression.name}": ${expression.name}
453
+ // `;
454
+ // }
455
+ // }
456
+ // throw new Error("Variable Access not implemented");
457
+ // }
458
+ if (isRef(expression)) {
459
+ console.log("Ref:", (_52 = expression.val.ref) === null || _52 === void 0 ? void 0 : _52.name);
460
+ // If string or number, return the value
461
+ if (typeof expression.val == "string" || typeof expression.val == "number") {
462
+ console.log(expression.val);
463
+ return expandToNode `
464
+ "${expression.val}": ${expression.val}
465
+ `;
466
+ }
467
+ if (expression.val.ref == undefined) {
468
+ return;
469
+ }
470
+ if (expression.subProperties != undefined && expression.subProperties.length > 0) {
471
+ return expandToNode `
472
+ "${(_53 = expression.val.ref) === null || _53 === void 0 ? void 0 : _53.name.toLowerCase()}${expression.subProperties[0].toLowerCase()}": ${(_54 = expression.val.ref) === null || _54 === void 0 ? void 0 : _54.name}.${expression.subProperties[0].toLowerCase()} ?? 0
473
+ `;
474
+ }
475
+ console.log((_55 = expression.val.ref) === null || _55 === void 0 ? void 0 : _55.name, (_56 = expression.val.ref) === null || _56 === void 0 ? void 0 : _56.$type);
476
+ return expandToNode `
477
+ "${(_59 = (_58 = (_57 = expression.val.ref) === null || _57 === void 0 ? void 0 : _57.name) === null || _58 === void 0 ? void 0 : _58.toLowerCase()) !== null && _59 !== void 0 ? _59 : expression.val.$refText}": ${(_61 = (_60 = expression.val.ref) === null || _60 === void 0 ? void 0 : _60.name) !== null && _61 !== void 0 ? _61 : expression.val.$refText} ?? 0
478
+ `;
479
+ }
480
+ if (isBinaryExpression(expression)) {
481
+ const expressions = [expression.e1, expression.e2];
482
+ return expandToNode `
483
+ ${joinToNode(expressions, e => translateDiceData(e, entry, id, preDerived, generatingProperty), { separator: ", " })}
484
+ `;
485
+ }
486
+ if (isGroup(expression)) {
487
+ return expandToNode `
488
+ ${translateDiceData(expression.ge, entry, id, preDerived, generatingProperty)}
489
+ `;
490
+ }
491
+ return undefined;
492
+ }
6
493
  export function translateExpression(entry, id, expression, preDerived = false, generatingProperty = undefined) {
7
494
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2;
8
495
  function humanize(string) {
@@ -702,7 +1189,7 @@ export function translateExpression(entry, id, expression, preDerived = false, g
702
1189
  if (isFleetingAccess(expression)) {
703
1190
  let accessPath = (_h = expression.variable.ref) === null || _h === void 0 ? void 0 : _h.name;
704
1191
  if (expression.subProperty != undefined) {
705
- accessPath = `${accessPath}.${expression.subProperty}`;
1192
+ accessPath = `${accessPath}.${fleetingSubProperty(expression)}`;
706
1193
  }
707
1194
  else if (expression.arrayAccess != undefined) {
708
1195
  accessPath = `${accessPath}[${translateExpression(entry, id, expression.arrayAccess, preDerived, generatingProperty)}]`;
@@ -780,7 +1267,7 @@ export function translateExpression(entry, id, expression, preDerived = false, g
780
1267
  if (isFleetingAccess(expression)) {
781
1268
  let accessPath = (_u = expression.variable.ref) === null || _u === void 0 ? void 0 : _u.name;
782
1269
  if (expression.subProperty != undefined) {
783
- accessPath = `${accessPath}.${expression.subProperty}`;
1270
+ accessPath = `${accessPath}.${fleetingSubProperty(expression)}`;
784
1271
  }
785
1272
  let roll = false;
786
1273
  let wide = expression.type == "wide" ? true : false;
@@ -847,7 +1334,7 @@ export function translateExpression(entry, id, expression, preDerived = false, g
847
1334
  if (isFleetingAccess(expression)) {
848
1335
  let accessPath = (_c = expression.variable.ref) === null || _c === void 0 ? void 0 : _c.name;
849
1336
  if (expression.subProperty != undefined) {
850
- accessPath = `${accessPath}.${expression.subProperty}`;
1337
+ accessPath = `${accessPath}.${fleetingSubProperty(expression)}`;
851
1338
  }
852
1339
  return expandToNode `
853
1340
  ${accessPath}
@@ -894,421 +1381,6 @@ export function translateExpression(entry, id, expression, preDerived = false, g
894
1381
  }
895
1382
  if (isRoll(expression) || isDamageRoll(expression)) {
896
1383
  console.log("Translating Roll Expression");
897
- function translateDiceParts(expression, noLabels = false) {
898
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32;
899
- console.log("Translating Dice Part: ", expression.$type);
900
- if (isLiteral(expression)) {
901
- if (typeof expression.val == "string") {
902
- return expandToNode `
903
- "${expression.val}"
904
- `;
905
- }
906
- return expandToNode `
907
- "${expression.val}"
908
- `;
909
- }
910
- if (isRef(expression)) {
911
- // If string or number, return the value
912
- if (typeof expression.val == "string" || typeof expression.val == "number") {
913
- return expandToNode `
914
- "${expression.val}"
915
- `;
916
- }
917
- if (expression.val.ref == undefined) {
918
- return;
919
- }
920
- if (expression.subProperties != undefined && expression.subProperties.length > 0) {
921
- const subLabel = noLabels ? "" : `[${humanize(expression.subProperties[0])}]`;
922
- return expandToNode `
923
- "@${(_a = expression.val.ref) === null || _a === void 0 ? void 0 : _a.name}${expression.subProperties[0].toLowerCase()}${subLabel}"
924
- `;
925
- }
926
- console.log("Ref:", `${expression.val.$refText}`);
927
- if (IntelligentSystemDesignLanguageTerminals.DICE.test(`${expression.val}`)) {
928
- return expandToNode `
929
- "${expression.val}"
930
- `;
931
- }
932
- const refLabel = noLabels ? "" : `[${humanize((_c = (_b = expression.val.ref) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : expression.val.$refText)}]`;
933
- return expandToNode `
934
- "@${(_f = (_e = (_d = expression.val.ref) === null || _d === void 0 ? void 0 : _d.name) === null || _e === void 0 ? void 0 : _e.toLowerCase()) !== null && _f !== void 0 ? _f : expression.val.$refText}${refLabel}"
935
- `;
936
- }
937
- if (isParentAccess(expression)) {
938
- let path = (_j = (_h = (_g = expression.property) === null || _g === void 0 ? void 0 : _g.ref) === null || _h === void 0 ? void 0 : _h.name) !== null && _j !== void 0 ? _j : "";
939
- let label = humanize((_m = (_l = (_k = expression.property) === null || _k === void 0 ? void 0 : _k.ref) === null || _l === void 0 ? void 0 : _l.name) !== null && _m !== void 0 ? _m : "");
940
- const document = getParentDocument(expression);
941
- if (document != undefined) {
942
- path = `${document.name.toLowerCase()}${path}`;
943
- label = `${humanize(document.name)} ${label}`;
944
- }
945
- // else if ( expression.propertyLookup != undefined ) {
946
- // path = `${path}${expression.propertyLookup.ref?.name.toLowerCase()}`;
947
- // label = `${label} \${context.object.system.${expression.propertyLookup.ref?.name.toLowerCase()}\}`;
948
- // }
949
- else {
950
- path = `${path}${(_p = (_o = expression.property) === null || _o === void 0 ? void 0 : _o.ref) === null || _p === void 0 ? void 0 : _p.name.toLowerCase()}`;
951
- label = `${label} ${humanize((_s = (_r = (_q = expression.property) === null || _q === void 0 ? void 0 : _q.ref) === null || _r === void 0 ? void 0 : _r.name) !== null && _s !== void 0 ? _s : "")}`;
952
- }
953
- for (const subProperty of (_t = expression.subProperties) !== null && _t !== void 0 ? _t : []) {
954
- path = `${path}${subProperty}`;
955
- label = `${label} ${humanize(subProperty)}`;
956
- }
957
- label = label.trim();
958
- const parentLabelSuffix = noLabels ? "" : `[${label}]`;
959
- return expandToNode `
960
- \`@${path.replaceAll(".", "").toLowerCase()}${parentLabelSuffix}\`
961
- `;
962
- }
963
- if (isTargetAccess(expression)) {
964
- let path = (_w = (_v = (_u = expression.property) === null || _u === void 0 ? void 0 : _u.ref) === null || _v === void 0 ? void 0 : _v.name) !== null && _w !== void 0 ? _w : "";
965
- let label = humanize((_z = (_y = (_x = expression.property) === null || _x === void 0 ? void 0 : _x.ref) === null || _y === void 0 ? void 0 : _y.name) !== null && _z !== void 0 ? _z : "");
966
- const document = getTargetDocument(expression);
967
- if (document != undefined) {
968
- path = `${document.name.toLowerCase()}${path}`;
969
- label = `${humanize(document.name)} ${label}`;
970
- }
971
- // else if ( expression.propertyLookup != undefined ) {
972
- // path = `${path}${expression.propertyLookup.ref?.name.toLowerCase()}`;
973
- // label = `${label} \${context.object.system.${expression.propertyLookup.ref?.name.toLowerCase()}\}`;
974
- // }
975
- else {
976
- path = `${path}${(_1 = (_0 = expression.property) === null || _0 === void 0 ? void 0 : _0.ref) === null || _1 === void 0 ? void 0 : _1.name.toLowerCase()}`;
977
- label = `${label} ${humanize((_4 = (_3 = (_2 = expression.property) === null || _2 === void 0 ? void 0 : _2.ref) === null || _3 === void 0 ? void 0 : _3.name) !== null && _4 !== void 0 ? _4 : "")}`;
978
- }
979
- for (const subProperty of (_5 = expression.subProperties) !== null && _5 !== void 0 ? _5 : []) {
980
- path = `${path}${subProperty}`;
981
- label = `${label} ${humanize(subProperty)}`;
982
- }
983
- label = label.trim();
984
- const targetLabelSuffix = noLabels ? "" : `[${label}]`;
985
- return expandToNode `
986
- \`@${path.replaceAll(".", "").toLowerCase()}${targetLabelSuffix}\`
987
- `;
988
- }
989
- if (isAccess(expression)) {
990
- let path = (_13 = (_9 = (_8 = (_7 = (_6 = expression.property) === null || _6 === void 0 ? void 0 : _6.ref) === null || _7 === void 0 ? void 0 : _7.name) === null || _8 === void 0 ? void 0 : _8.toLowerCase()) !== null && _9 !== void 0 ? _9 : (_12 = (_11 = (_10 = expression.propertyLookup) === null || _10 === void 0 ? void 0 : _10.ref) === null || _11 === void 0 ? void 0 : _11.name) === null || _12 === void 0 ? void 0 : _12.toLowerCase()) !== null && _13 !== void 0 ? _13 : "";
991
- let label = humanize((_19 = (_16 = (_15 = (_14 = expression.property) === null || _14 === void 0 ? void 0 : _14.ref) === null || _15 === void 0 ? void 0 : _15.name) !== null && _16 !== void 0 ? _16 : (_18 = (_17 = expression.propertyLookup) === null || _17 === void 0 ? void 0 : _17.ref) === null || _18 === void 0 ? void 0 : _18.name) !== null && _19 !== void 0 ? _19 : "");
992
- // if (isDieField(expression.property?.ref)) {
993
- // return expandToNode`
994
- // \'@${path.replaceAll(".", "")}\'
995
- // `;
996
- // }
997
- // Special handling for document choices - expand into individual terms
998
- if (expression.property && isDocumentChoicesExp(expression.property.ref) && expression.subProperties && expression.subProperties.length > 0) {
999
- const choicesFieldName = expression.property.ref.name.toLowerCase();
1000
- const subPropertyName = expression.subProperties[0].toLowerCase();
1001
- const subPropertyLabel = humanize(expression.subProperties[0]);
1002
- // Generate dynamic expansion for each document in the choices array
1003
- return expandToNode `
1004
- context.object.system.${choicesFieldName}.map((doc, index) => {
1005
- if (!doc || !doc.system) return '';
1006
- return '@' + doc.uuid.replace(/[^a-zA-Z0-9]/g, '').toLowerCase() + '${subPropertyName}[' + doc.name + ' ${subPropertyLabel}]';
1007
- }).filter(Boolean).join(' + ')
1008
- `;
1009
- }
1010
- if (isParentPropertyRefExp((_20 = expression.property) === null || _20 === void 0 ? void 0 : _20.ref)) {
1011
- label = `${label} - \${context.object.system.${(_22 = (_21 = expression.property) === null || _21 === void 0 ? void 0 : _21.ref) === null || _22 === void 0 ? void 0 : _22.name.toLowerCase()}.replace("system.", "").replaceAll(".", " ").titleCase()\}`;
1012
- }
1013
- else if (isSelfPropertyRefExp((_23 = expression.property) === null || _23 === void 0 ? void 0 : _23.ref)) {
1014
- label = `${label} - \${context.object.system.${(_25 = (_24 = expression.property) === null || _24 === void 0 ? void 0 : _24.ref) === null || _25 === void 0 ? void 0 : _25.name.toLowerCase()}.replace("system.", "").replaceAll(".", " ").titleCase()\}`;
1015
- }
1016
- else {
1017
- for (const subProperty of (_26 = expression.subProperties) !== null && _26 !== void 0 ? _26 : []) {
1018
- path = `${path}.${subProperty}`;
1019
- label = `${label} ${humanize(subProperty)}`;
1020
- }
1021
- }
1022
- console.log("Access:", path, label);
1023
- const accessLabelSuffix = noLabels ? "" : `[${label}]`;
1024
- return expandToNode `
1025
- \`@${path.replaceAll(".", "").toLowerCase()}${accessLabelSuffix}\`
1026
- `;
1027
- }
1028
- if (isFleetingAccess(expression)) {
1029
- // If this is a roll expression, just output it directly
1030
- if (isRoll((_27 = expression.variable.ref) === null || _27 === void 0 ? void 0 : _27.value)) {
1031
- return expandToNode `
1032
- ${(_28 = expression.variable.ref) === null || _28 === void 0 ? void 0 : _28.name}
1033
- `;
1034
- }
1035
- let path = (_30 = (_29 = expression.variable.ref) === null || _29 === void 0 ? void 0 : _29.name) !== null && _30 !== void 0 ? _30 : "";
1036
- let label = humanize((_32 = (_31 = expression.variable.ref) === null || _31 === void 0 ? void 0 : _31.name) !== null && _32 !== void 0 ? _32 : "");
1037
- if (expression.subProperty != undefined) {
1038
- path = `${path}.${expression.subProperty}`;
1039
- label = `${label} ${humanize(expression.subProperty)}`;
1040
- }
1041
- const fleetingLabelSuffix = noLabels ? "" : `[${label}]`;
1042
- return expandToNode `
1043
- \`@${path.replaceAll(".", "").toLowerCase()}${fleetingLabelSuffix}\`
1044
- `;
1045
- }
1046
- if (isBinaryExpression(expression)) {
1047
- return expandToNode `
1048
- ${translateDiceParts(expression.e1, noLabels)} + "${expression.op}" + ${translateDiceParts(expression.e2, noLabels)}
1049
- `;
1050
- }
1051
- if (isGroup(expression)) {
1052
- return expandToNode `
1053
- "(" + ${translateDiceParts(expression.ge, noLabels)} + ")"
1054
- `;
1055
- }
1056
- return;
1057
- }
1058
- function translateDisplayFormula(expression) {
1059
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
1060
- if (isLiteral(expression)) {
1061
- return `${expression.val}`;
1062
- }
1063
- if (isGroup(expression)) {
1064
- const inner = translateDisplayFormula(expression.ge);
1065
- return inner != null ? `(${inner})` : undefined;
1066
- }
1067
- if (isBinaryExpression(expression)) {
1068
- const left = translateDisplayFormula(expression.e1);
1069
- const right = translateDisplayFormula(expression.e2);
1070
- return left != null && right != null ? `${left} ${expression.op} ${right}` : undefined;
1071
- }
1072
- if (isAccess(expression)) {
1073
- if (isParentPropertyRefExp((_a = expression.property) === null || _a === void 0 ? void 0 : _a.ref) || isSelfPropertyRefExp((_b = expression.property) === null || _b === void 0 ? void 0 : _b.ref)) {
1074
- return undefined;
1075
- }
1076
- let label = humanize((_h = (_e = (_d = (_c = expression.property) === null || _c === void 0 ? void 0 : _c.ref) === null || _d === void 0 ? void 0 : _d.name) !== null && _e !== void 0 ? _e : (_g = (_f = expression.propertyLookup) === null || _f === void 0 ? void 0 : _f.ref) === null || _g === void 0 ? void 0 : _g.name) !== null && _h !== void 0 ? _h : "");
1077
- for (const sub of (_j = expression.subProperties) !== null && _j !== void 0 ? _j : []) {
1078
- label += ` ${humanize(sub)}`;
1079
- }
1080
- return label.trim();
1081
- }
1082
- if (isParentAccess(expression)) {
1083
- return humanize((_m = (_l = (_k = expression.property) === null || _k === void 0 ? void 0 : _k.ref) === null || _l === void 0 ? void 0 : _l.name) !== null && _m !== void 0 ? _m : "");
1084
- }
1085
- if (isTargetAccess(expression)) {
1086
- return humanize((_q = (_p = (_o = expression.property) === null || _o === void 0 ? void 0 : _o.ref) === null || _p === void 0 ? void 0 : _p.name) !== null && _q !== void 0 ? _q : "");
1087
- }
1088
- if (isFleetingAccess(expression)) {
1089
- return humanize((_s = (_r = expression.variable.ref) === null || _r === void 0 ? void 0 : _r.name) !== null && _s !== void 0 ? _s : "");
1090
- }
1091
- return undefined;
1092
- }
1093
- function translateDiceData(expression) {
1094
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52;
1095
- console.log("Translating Dice Data: ", expression.$type);
1096
- if (isParentAccess(expression)) {
1097
- let path = "context.object.parent.system";
1098
- let label = (_c = (_b = (_a = expression.property) === null || _a === void 0 ? void 0 : _a.ref) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : "";
1099
- console.log("Parent Access:", (_e = (_d = expression.property) === null || _d === void 0 ? void 0 : _d.ref) === null || _e === void 0 ? void 0 : _e.name);
1100
- const document = getParentDocument(expression);
1101
- if (document != undefined) {
1102
- path = `${path}.${(_h = (_g = (_f = expression.property) === null || _f === void 0 ? void 0 : _f.ref) === null || _g === void 0 ? void 0 : _g.name) === null || _h === void 0 ? void 0 : _h.toLowerCase()}`;
1103
- label = `${humanize(document.name)}.${label}`;
1104
- }
1105
- else {
1106
- path = `${path}.${(_l = (_k = (_j = expression.property) === null || _j === void 0 ? void 0 : _j.ref) === null || _k === void 0 ? void 0 : _k.name) === null || _l === void 0 ? void 0 : _l.toLowerCase()}`;
1107
- label = `${label}.${expression.property}`;
1108
- }
1109
- for (const subProperty of (_m = expression.subProperties) !== null && _m !== void 0 ? _m : []) {
1110
- path = `${path}.${subProperty}`;
1111
- label = `${label}.${subProperty}`;
1112
- }
1113
- return expandToNode `
1114
- "${label.replaceAll(".", "").toLowerCase()}": ${path}
1115
- `;
1116
- }
1117
- if (isTargetAccess(expression)) {
1118
- let path = "context.target.system";
1119
- let label = (_q = (_p = (_o = expression.property) === null || _o === void 0 ? void 0 : _o.ref) === null || _p === void 0 ? void 0 : _p.name) !== null && _q !== void 0 ? _q : "";
1120
- console.log("Target Access:", (_s = (_r = expression.property) === null || _r === void 0 ? void 0 : _r.ref) === null || _s === void 0 ? void 0 : _s.name);
1121
- const document = getTargetDocument(expression);
1122
- if (document != undefined) {
1123
- path = `${path}.${(_v = (_u = (_t = expression.property) === null || _t === void 0 ? void 0 : _t.ref) === null || _u === void 0 ? void 0 : _u.name) === null || _v === void 0 ? void 0 : _v.toLowerCase()}`;
1124
- label = `${humanize(document.name)}.${label}`;
1125
- }
1126
- else {
1127
- path = `${path}.${(_y = (_x = (_w = expression.property) === null || _w === void 0 ? void 0 : _w.ref) === null || _x === void 0 ? void 0 : _x.name) === null || _y === void 0 ? void 0 : _y.toLowerCase()}`;
1128
- label = `${label}.${expression.property}`;
1129
- }
1130
- for (const subProperty of (_z = expression.subProperties) !== null && _z !== void 0 ? _z : []) {
1131
- path = `${path}.${subProperty}`;
1132
- label = `${label}.${subProperty}`;
1133
- }
1134
- return expandToNode `
1135
- "${label.replaceAll(".", "").toLowerCase()}": ${path}
1136
- `;
1137
- }
1138
- if (isAccess(expression)) {
1139
- let path = "context.object.system";
1140
- let label = "";
1141
- console.log("Access:", (_1 = (_0 = expression.property) === null || _0 === void 0 ? void 0 : _0.ref) === null || _1 === void 0 ? void 0 : _1.name, (_3 = (_2 = expression.propertyLookup) === null || _2 === void 0 ? void 0 : _2.ref) === null || _3 === void 0 ? void 0 : _3.name);
1142
- if (expression.propertyLookup != undefined) {
1143
- path = `${path}[context.object.${getSystemPath(expression.propertyLookup.ref)}.toLowerCase()]`;
1144
- label = `${(_4 = expression.propertyLookup.ref) === null || _4 === void 0 ? void 0 : _4.name}`;
1145
- }
1146
- else if (isParentPropertyRefExp((_5 = expression.property) === null || _5 === void 0 ? void 0 : _5.ref)) {
1147
- path = `${path}.${(_7 = (_6 = expression.property) === null || _6 === void 0 ? void 0 : _6.ref) === null || _7 === void 0 ? void 0 : _7.name.toLowerCase()}`;
1148
- label = `${(_9 = (_8 = expression.property) === null || _8 === void 0 ? void 0 : _8.ref) === null || _9 === void 0 ? void 0 : _9.name}`;
1149
- let subProperty = "";
1150
- if (((_10 = expression.property) === null || _10 === void 0 ? void 0 : _10.ref.propertyType) == "resource" || ((_11 = expression.property) === null || _11 === void 0 ? void 0 : _11.ref.propertyType) == "tracker" || ((_12 = expression.property) === null || _12 === void 0 ? void 0 : _12.ref.propertyType) == "choice"
1151
- && (expression.subProperties == undefined || expression.subProperties.length == 0 || expression.subProperties[0] !== "value")) {
1152
- subProperty = "?.value";
1153
- }
1154
- if (((_13 = expression.property) === null || _13 === void 0 ? void 0 : _13.ref.propertyType) == "attribute" && (expression.subProperties == undefined || expression.subProperties.length == 0 || expression.subProperties[0] !== "mod")) {
1155
- subProperty = "?.mod";
1156
- }
1157
- console.log(label, path);
1158
- return expandToNode `
1159
- "${label.replaceAll(".", "").replaceAll(" ", "").toLowerCase()}": foundry.utils.getProperty(context.object.parent, ${path}.toLowerCase())${subProperty}
1160
- `;
1161
- }
1162
- else if (isSelfPropertyRefExp((_14 = expression.property) === null || _14 === void 0 ? void 0 : _14.ref)) {
1163
- // For self property references, we dynamically resolve the property path
1164
- let selfPropertyPath = `context.object.system.${(_16 = (_15 = expression.property) === null || _15 === void 0 ? void 0 : _15.ref) === null || _16 === void 0 ? void 0 : _16.name.toLowerCase()}`;
1165
- let subProperty = "";
1166
- label = `${(_18 = (_17 = expression.property) === null || _17 === void 0 ? void 0 : _17.ref) === null || _18 === void 0 ? void 0 : _18.name}`;
1167
- if (((_19 = expression.property) === null || _19 === void 0 ? void 0 : _19.ref.propertyType) == "resource" || ((_20 = expression.property) === null || _20 === void 0 ? void 0 : _20.ref.propertyType) == "tracker" || ((_21 = expression.property) === null || _21 === void 0 ? void 0 : _21.ref.propertyType) == "choice"
1168
- && (expression.subProperties == undefined || expression.subProperties.length == 0 || expression.subProperties[0] !== "value")) {
1169
- subProperty = "?.value";
1170
- }
1171
- if (((_22 = expression.property) === null || _22 === void 0 ? void 0 : _22.ref.propertyType) == "attribute" && (expression.subProperties == undefined || expression.subProperties.length == 0 || expression.subProperties[0] !== "mod")) {
1172
- subProperty = "?.mod";
1173
- }
1174
- console.log(label, selfPropertyPath);
1175
- return expandToNode `
1176
- "${label.replaceAll(".", "").replaceAll(" ", "").toLowerCase()}": foundry.utils.getProperty(context.object, "system." + ${selfPropertyPath}.toLowerCase())${subProperty}
1177
- `;
1178
- }
1179
- else {
1180
- // Special handling for document choices - expand into individual data entries
1181
- if (expression.property && isDocumentChoicesExp(expression.property.ref) && expression.subProperties && expression.subProperties.length > 0) {
1182
- const choicesFieldName = expression.property.ref.name.toLowerCase();
1183
- const subPropertyName = expression.subProperties[0].toLowerCase();
1184
- // Generate data for each document in the choices array
1185
- return expandToNode `
1186
- ...Object.fromEntries(context.object.system.${choicesFieldName}.map((doc, index) => {
1187
- if (!doc || !doc.system) return null;
1188
-
1189
- // Determine the accessor based on property type
1190
- let accessor = '.${subPropertyName}';
1191
- ${isResourceExp((_23 = expression.property) === null || _23 === void 0 ? void 0 : _23.ref) || isTrackerExp((_24 = expression.property) === null || _24 === void 0 ? void 0 : _24.ref) ? `
1192
- if (doc.system.${subPropertyName} && typeof doc.system.${subPropertyName} === 'object' && 'value' in doc.system.${subPropertyName}) {
1193
- accessor = '.${subPropertyName}.value';
1194
- }` : ''}
1195
- ${isAttributeExp((_25 = expression.property) === null || _25 === void 0 ? void 0 : _25.ref) ? `
1196
- if (doc.system.${subPropertyName} && typeof doc.system.${subPropertyName} === 'object' && 'mod' in doc.system.${subPropertyName}) {
1197
- accessor = '.${subPropertyName}.mod';
1198
- }` : ''}
1199
-
1200
- const key = doc.uuid.replace(/[^a-zA-Z0-9]/g, '').toLowerCase() + '${subPropertyName}';
1201
- const value = foundry.utils.getProperty(doc, 'system' + accessor) ?? 0;
1202
- return [key, value];
1203
- }).filter(Boolean))
1204
- `;
1205
- }
1206
- path = `${path}.${(_27 = (_26 = expression.property) === null || _26 === void 0 ? void 0 : _26.ref) === null || _27 === void 0 ? void 0 : _27.name.toLowerCase()}`;
1207
- label = `${(_29 = (_28 = expression.property) === null || _28 === void 0 ? void 0 : _28.ref) === null || _29 === void 0 ? void 0 : _29.name}`;
1208
- if ((isResourceExp((_30 = expression.property) === null || _30 === void 0 ? void 0 : _30.ref) || isTrackerExp((_31 = expression.property) === null || _31 === void 0 ? void 0 : _31.ref) || isStringChoiceField((_32 = expression.property) === null || _32 === void 0 ? void 0 : _32.ref))
1209
- && (expression.subProperties == undefined || expression.subProperties.length == 0 || expression.subProperties[0] == "value")) {
1210
- path = `${path}.value`;
1211
- }
1212
- if (isDiceField((_33 = expression.property) === null || _33 === void 0 ? void 0 : _33.ref) && (expression.subProperties == undefined || expression.subProperties.length == 0)) {
1213
- // For dice fields without subproperties, use the dice value
1214
- path = `${path}.value`;
1215
- }
1216
- if (isDieField((_34 = expression.property) === null || _34 === void 0 ? void 0 : _34.ref)) {
1217
- // For die fields, the value is just the die size (e.g., "d6"), we want to use the field name as label
1218
- // Don't change the path, just ensure the label is the field name
1219
- }
1220
- if (isAttributeExp((_35 = expression.property) === null || _35 === void 0 ? void 0 : _35.ref) && (expression.subProperties == undefined || expression.subProperties.length == 0 || expression.subProperties[0] !== "mod")) {
1221
- path = `${path}.mod`;
1222
- }
1223
- }
1224
- for (const subProperty of (_36 = expression.subProperties) !== null && _36 !== void 0 ? _36 : []) {
1225
- path = `${path}.${subProperty}`;
1226
- label = `${label} ${humanize(subProperty)}`;
1227
- }
1228
- console.log(label, path);
1229
- return expandToNode `
1230
- "${label.replaceAll(".", "").replaceAll(" ", "").toLowerCase()}": ${path} ?? 0
1231
- `;
1232
- }
1233
- if (isFleetingAccess(expression)) {
1234
- console.log("Fleeting Access:", (_37 = expression.variable.ref) === null || _37 === void 0 ? void 0 : _37.name);
1235
- // If this is a roll expression, just skip it
1236
- if (isRoll((_38 = expression.variable.ref) === null || _38 === void 0 ? void 0 : _38.value)) {
1237
- return;
1238
- }
1239
- let path = (_39 = expression.variable.ref) === null || _39 === void 0 ? void 0 : _39.name;
1240
- if (expression.subProperty != undefined) {
1241
- path = `${path}.${expression.subProperty}`;
1242
- }
1243
- if (expression.arrayAccess != undefined) {
1244
- console.log("Array Access:", expression.arrayAccess.$type);
1245
- let accessExp = translateExpression(entry, id, expression.arrayAccess, preDerived, generatingProperty);
1246
- path = `${path}[${(_40 = accessExp === null || accessExp === void 0 ? void 0 : accessExp.contents) === null || _40 === void 0 ? void 0 : _40.toString()}]`;
1247
- }
1248
- const label = (_42 = (_41 = expression.variable.ref) === null || _41 === void 0 ? void 0 : _41.name.toLowerCase()) !== null && _42 !== void 0 ? _42 : "";
1249
- console.log(label, path);
1250
- return expandToNode `
1251
- "${label}": ${path} ?? 0
1252
- `;
1253
- }
1254
- // if (isVariableAccess(expression)) {
1255
- // console.log("Variable Access:", expression.name);
1256
- // if (isParameter(expression)) {
1257
- // console.log("Parameter:", expression.name);
1258
- // return expandToNode`
1259
- // "${expression.name}": ${expression.name}
1260
- // `;
1261
- // }
1262
- // if (isVariableExpression(expression)) {
1263
- // console.log("Variable Expression:", expression.name);
1264
- // if (isExpression(expression.value)) {
1265
- // console.log("Expression:", expression.name);
1266
- // return translateDiceData(expression.value);
1267
- // }
1268
- // if (isPrompt(expression.value)) {
1269
- // console.log("Prompt:", expression.name);
1270
- // return expandToNode`
1271
- // "${expression.name}": ${expression.name}
1272
- // `;
1273
- // }
1274
- // }
1275
- // throw new Error("Variable Access not implemented");
1276
- // }
1277
- if (isRef(expression)) {
1278
- console.log("Ref:", (_43 = expression.val.ref) === null || _43 === void 0 ? void 0 : _43.name);
1279
- // If string or number, return the value
1280
- if (typeof expression.val == "string" || typeof expression.val == "number") {
1281
- console.log(expression.val);
1282
- return expandToNode `
1283
- "${expression.val}": ${expression.val}
1284
- `;
1285
- }
1286
- if (expression.val.ref == undefined) {
1287
- return;
1288
- }
1289
- if (expression.subProperties != undefined && expression.subProperties.length > 0) {
1290
- return expandToNode `
1291
- "${(_44 = expression.val.ref) === null || _44 === void 0 ? void 0 : _44.name.toLowerCase()}${expression.subProperties[0].toLowerCase()}": ${(_45 = expression.val.ref) === null || _45 === void 0 ? void 0 : _45.name}.${expression.subProperties[0].toLowerCase()} ?? 0
1292
- `;
1293
- }
1294
- console.log((_46 = expression.val.ref) === null || _46 === void 0 ? void 0 : _46.name, (_47 = expression.val.ref) === null || _47 === void 0 ? void 0 : _47.$type);
1295
- return expandToNode `
1296
- "${(_50 = (_49 = (_48 = expression.val.ref) === null || _48 === void 0 ? void 0 : _48.name) === null || _49 === void 0 ? void 0 : _49.toLowerCase()) !== null && _50 !== void 0 ? _50 : expression.val.$refText}": ${(_52 = (_51 = expression.val.ref) === null || _51 === void 0 ? void 0 : _51.name) !== null && _52 !== void 0 ? _52 : expression.val.$refText} ?? 0
1297
- `;
1298
- }
1299
- if (isBinaryExpression(expression)) {
1300
- const expressions = [expression.e1, expression.e2];
1301
- return expandToNode `
1302
- ${joinToNode(expressions, e => translateDiceData(e), { separator: ", " })}
1303
- `;
1304
- }
1305
- if (isGroup(expression)) {
1306
- return expandToNode `
1307
- ${translateDiceData(expression.ge)}
1308
- `;
1309
- }
1310
- return undefined;
1311
- }
1312
1384
  if (isDamageRoll(expression)) {
1313
1385
  const rollParam = expression.params.find(isRollParam);
1314
1386
  const rollExpression = rollParam.value;
@@ -1325,7 +1397,7 @@ export function translateExpression(entry, id, expression, preDerived = false, g
1325
1397
  return expandToNode `
1326
1398
  await new ${entry.config.name}DamageRoll(
1327
1399
  ${joinToNode(rollExpression.parts, e => translateDiceParts(e), { separator: " + " })},
1328
- {${joinToNode(rollExpression.parts, e => translateDiceData(e), { separator: ", " })},
1400
+ {${joinToNode(rollExpression.parts, e => translateDiceData(e, entry, id, preDerived, generatingProperty), { separator: ", " })},
1329
1401
  actor: context.actor},
1330
1402
  { type: ${damageTypeDataAccess} }
1331
1403
  ).roll()
@@ -1341,7 +1413,7 @@ export function translateExpression(entry, id, expression, preDerived = false, g
1341
1413
  const nextPart = rollParts[idx + 1];
1342
1414
  const nextIsDice = nextPart != null && isLiteral(nextPart) && typeof nextPart.val === 'string' && IntelligentSystemDesignLanguageTerminals.DICE.test(nextPart.val);
1343
1415
  return translateDiceParts(e, nextIsDice);
1344
- }, { separator: " + " })}, {${joinToNode(rollParts, e => translateDiceData(e), { separator: ", " })}}).roll(), ${displayFormula != null ? `{_displayFormula: "${displayFormula}"}` : '{}'})
1416
+ }, { separator: " + " })}, {${joinToNode(rollParts, e => translateDiceData(e, entry, id, preDerived, generatingProperty), { separator: ", " })}}).roll(), ${displayFormula != null ? `{_displayFormula: "${displayFormula}"}` : '{}'})
1345
1417
  `;
1346
1418
  }
1347
1419
  if (isSelfMethod(expression)) {
@@ -1796,4 +1868,24 @@ export function translateBodyExpressionToJavascript(entry, id, body, preDerived
1796
1868
  // */
1797
1869
  return joinToNode(body, (expression) => translateExpression(entry, id, expression, preDerived, generatingProperty), { appendNewLineIfNotEmpty: true });
1798
1870
  }
1871
+ // Compile a rollVisualizer field's value: expression into a Foundry roll formula
1872
+ // string (containing @refs) plus the data object that resolves those refs from the
1873
+ // live, reactive document/prompt context. This mirrors the roll() codegen path but
1874
+ // returns the two pieces separately, so the visualizer component can ANALYZE the
1875
+ // formula (convolve / simulate) rather than evaluate it as a roll.
1876
+ //
1877
+ // Phase 1 supports Expression values (including an explicit roll(...) node). A
1878
+ // MethodBlock value yields an empty formula -- there is nothing to visualize from a
1879
+ // statically-unknown computed string -- and the component renders its empty state.
1880
+ export function compileVisualizerFormula(entry, id, field) {
1881
+ const valueParam = field.params.find(isRollVisualizerValueParam);
1882
+ const value = valueParam === null || valueParam === void 0 ? void 0 : valueParam.value;
1883
+ if (!value || isMethodBlock(value)) {
1884
+ return { formula: expandToNode `""`, data: expandToNode `{}` };
1885
+ }
1886
+ const parts = isRoll(value) ? value.parts : [value];
1887
+ const formula = expandToNode `${joinToNode(parts, e => translateDiceParts(e, true), { separator: " + " })}`;
1888
+ const data = expandToNode `{${joinToNode(parts, e => translateDiceData(e, entry, id, false, undefined), { separator: ", " })}}`;
1889
+ return { formula, data };
1890
+ }
1799
1891
  //# sourceMappingURL=method-generator.js.map