@babamba2/abap-mcp-adt-powerup 4.8.12 → 4.8.14

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 (63) hide show
  1. package/CHANGELOG.md +30 -1
  2. package/dist/handlers/gui_status/high/handleGetGuiStatus.d.ts +14 -2
  3. package/dist/handlers/gui_status/high/handleGetGuiStatus.d.ts.map +1 -1
  4. package/dist/handlers/gui_status/high/handleGetGuiStatus.js +24 -11
  5. package/dist/handlers/gui_status/high/handleGetGuiStatus.js.map +1 -1
  6. package/dist/handlers/smartform/high/handleCreateSmartForm.d.ts +71 -0
  7. package/dist/handlers/smartform/high/handleCreateSmartForm.d.ts.map +1 -0
  8. package/dist/handlers/smartform/high/handleCreateSmartForm.js +163 -0
  9. package/dist/handlers/smartform/high/handleCreateSmartForm.js.map +1 -0
  10. package/dist/handlers/smartform/high/handleDeleteSmartForm.d.ts +41 -0
  11. package/dist/handlers/smartform/high/handleDeleteSmartForm.d.ts.map +1 -0
  12. package/dist/handlers/smartform/high/handleDeleteSmartForm.js +76 -0
  13. package/dist/handlers/smartform/high/handleDeleteSmartForm.js.map +1 -0
  14. package/dist/handlers/system/readonly/handleGetSmartFormContent.d.ts +77 -0
  15. package/dist/handlers/system/readonly/handleGetSmartFormContent.d.ts.map +1 -0
  16. package/dist/handlers/system/readonly/handleGetSmartFormContent.js +98 -0
  17. package/dist/handlers/system/readonly/handleGetSmartFormContent.js.map +1 -0
  18. package/dist/handlers/system/readonly/handleGetSmartFormLayout.d.ts +47 -0
  19. package/dist/handlers/system/readonly/handleGetSmartFormLayout.d.ts.map +1 -0
  20. package/dist/handlers/system/readonly/handleGetSmartFormLayout.js +70 -0
  21. package/dist/handlers/system/readonly/handleGetSmartFormLayout.js.map +1 -0
  22. package/dist/handlers/system/readonly/handleRenderSmartForm.d.ts +65 -0
  23. package/dist/handlers/system/readonly/handleRenderSmartForm.d.ts.map +1 -0
  24. package/dist/handlers/system/readonly/handleRenderSmartForm.js +111 -0
  25. package/dist/handlers/system/readonly/handleRenderSmartForm.js.map +1 -0
  26. package/dist/handlers/system/readonly/runtimeFeedsHelper.d.ts +1 -1
  27. package/dist/handlers/system/readonly/runtimeFeedsHelper.d.ts.map +1 -1
  28. package/dist/lib/cuaFilter.d.ts +38 -0
  29. package/dist/lib/cuaFilter.d.ts.map +1 -0
  30. package/dist/lib/cuaFilter.js +132 -0
  31. package/dist/lib/cuaFilter.js.map +1 -0
  32. package/dist/lib/handlers/groups/HighLevelHandlersGroup.d.ts.map +1 -1
  33. package/dist/lib/handlers/groups/HighLevelHandlersGroup.js +11 -0
  34. package/dist/lib/handlers/groups/HighLevelHandlersGroup.js.map +1 -1
  35. package/dist/lib/handlers/groups/ReadOnlyHandlersGroup.d.ts.map +1 -1
  36. package/dist/lib/handlers/groups/ReadOnlyHandlersGroup.js +15 -0
  37. package/dist/lib/handlers/groups/ReadOnlyHandlersGroup.js.map +1 -1
  38. package/dist/lib/legacyTableRead.d.ts.map +1 -1
  39. package/dist/lib/legacyTableRead.js +19 -9
  40. package/dist/lib/legacyTableRead.js.map +1 -1
  41. package/dist/lib/smartFormContent.d.ts +277 -0
  42. package/dist/lib/smartFormContent.d.ts.map +1 -0
  43. package/dist/lib/smartFormContent.js +1130 -0
  44. package/dist/lib/smartFormContent.js.map +1 -0
  45. package/dist/lib/smartFormLayout.d.ts +83 -0
  46. package/dist/lib/smartFormLayout.d.ts.map +1 -0
  47. package/dist/lib/smartFormLayout.js +236 -0
  48. package/dist/lib/smartFormLayout.js.map +1 -0
  49. package/dist/lib/smartFormRender.d.ts +17 -0
  50. package/dist/lib/smartFormRender.d.ts.map +1 -0
  51. package/dist/lib/smartFormRender.js +112 -0
  52. package/dist/lib/smartFormRender.js.map +1 -0
  53. package/dist/lib/utils.d.ts +1 -1
  54. package/dist/lib/utils.d.ts.map +1 -1
  55. package/dist/lib/utils.js +1 -1
  56. package/dist/lib/utils.js.map +1 -1
  57. package/docs/user-guide/AVAILABLE_TOOLS.md +1041 -204
  58. package/docs/user-guide/AVAILABLE_TOOLS_COMPACT.md +2 -1
  59. package/docs/user-guide/AVAILABLE_TOOLS_HIGH.md +472 -85
  60. package/docs/user-guide/AVAILABLE_TOOLS_LEGACY.md +957 -78
  61. package/docs/user-guide/AVAILABLE_TOOLS_LOW.md +271 -60
  62. package/docs/user-guide/AVAILABLE_TOOLS_READONLY.md +299 -60
  63. package/package.json +19 -19
@@ -0,0 +1,1130 @@
1
+ "use strict";
2
+ /**
3
+ * SmartForm content — what each window prints, for preview rendering.
4
+ *
5
+ * SAP side: ZMCP_ADT_DISPATCH action SSF_CONTENT → FM ZMCP_SSF_CONTENT
6
+ * (sc4sap/abap/zmcp_ssf_content.abap), read-only, four parts:
7
+ * FORM Form Builder XML of the active version (FB_CONVERT_FORM_TO_XML,
8
+ * texts in the logon language), base64
9
+ * STYLE SmartStyle as CSS (SSF_CONVERT_STYLE_TO_CSS), base64
10
+ * GRAPHIC SE78 graphic as BMP + STXBITMAPS size data, base64
11
+ * STDTEXT SO10 / include text lines (READ_TEXT)
12
+ *
13
+ * This module parses the XML into pages → windows → content nodes (text,
14
+ * table / template / loop / folder sections, graphics, addresses, code
15
+ * markers, conditions), then fetches the styles, the graphics with a fixed
16
+ * key and the include texts with a fixed key. Files (XML, CSS, BMP) are
17
+ * written under the MCP output directory; the JSON carries their paths.
18
+ */
19
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k;
21
+ var desc = Object.getOwnPropertyDescriptor(m, k);
22
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
23
+ desc = { enumerable: true, get: function() { return m[k]; } };
24
+ }
25
+ Object.defineProperty(o, k2, desc);
26
+ }) : (function(o, m, k, k2) {
27
+ if (k2 === undefined) k2 = k;
28
+ o[k2] = m[k];
29
+ }));
30
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
31
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
32
+ }) : function(o, v) {
33
+ o["default"] = v;
34
+ });
35
+ var __importStar = (this && this.__importStar) || (function () {
36
+ var ownKeys = function(o) {
37
+ ownKeys = Object.getOwnPropertyNames || function (o) {
38
+ var ar = [];
39
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
40
+ return ar;
41
+ };
42
+ return ownKeys(o);
43
+ };
44
+ return function (mod) {
45
+ if (mod && mod.__esModule) return mod;
46
+ var result = {};
47
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
48
+ __setModuleDefault(result, mod);
49
+ return result;
50
+ };
51
+ })();
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ exports.SSF_CONTENT_INSTALL_HINT = void 0;
54
+ exports.hasSymbol = hasSymbol;
55
+ exports.plain = plain;
56
+ exports.parseSmartFormXml = parseSmartFormXml;
57
+ exports.translateSmartFormContentError = translateSmartFormContentError;
58
+ exports.symbolsOf = symbolsOf;
59
+ exports.summarizeSmartFormContent = summarizeSmartFormContent;
60
+ exports.getSmartFormContent = getSmartFormContent;
61
+ const fs = __importStar(require("node:fs"));
62
+ const path = __importStar(require("node:path"));
63
+ const fast_xml_parser_1 = require("fast-xml-parser");
64
+ const rfcBackend_1 = require("./rfcBackend");
65
+ const smartFormLayout_1 = require("./smartFormLayout");
66
+ const sourceOutput_1 = require("./sourceOutput");
67
+ exports.SSF_CONTENT_INSTALL_HINT = 'The SAP side of GetSmartFormContent is not installed on this system: it needs FM ZMCP_SSF_CONTENT ' +
68
+ '(function group ZMCP_ADT_UTILS, next to ZMCP_SSF_LAYOUT) and the SSF_CONTENT branch in ZMCP_ADT_DISPATCH. ' +
69
+ 'Sources and install steps: sc4sap/abap/README.md (zmcp_ssf_content.abap, zmcp_adt_dispatch_ssf_content_branch.abap).';
70
+ /** A field value contains a symbol such as &GV_LOGO& — resolved only at print time. */
71
+ function hasSymbol(v) {
72
+ return /&[^&\s]+&/.test(String(v ?? ''));
73
+ }
74
+ function asArray(v) {
75
+ if (v === undefined || v === null)
76
+ return [];
77
+ return Array.isArray(v) ? v : [v];
78
+ }
79
+ function str(v) {
80
+ if (v === undefined || v === null)
81
+ return '';
82
+ if (typeof v === 'object') {
83
+ const t = v['#text'];
84
+ return t === undefined || t === null ? '' : String(t);
85
+ }
86
+ return String(v);
87
+ }
88
+ function trimmed(v) {
89
+ return str(v).trim();
90
+ }
91
+ /**
92
+ * Turn a field element into a plain value: `<X><item>…</item>…</X>` → array,
93
+ * an element with children → object, a leaf → string. Attributes are kept
94
+ * only for ID / IDREF.
95
+ */
96
+ function plain(v) {
97
+ if (v === undefined || v === null)
98
+ return '';
99
+ if (Array.isArray(v))
100
+ return v.map(plain);
101
+ if (typeof v !== 'object')
102
+ return String(v);
103
+ const o = v;
104
+ const keys = Object.keys(o).filter((k) => !k.startsWith('@_') && k !== '#text');
105
+ if (keys.length === 0)
106
+ return str(o);
107
+ if (keys.length === 1 && keys[0] === 'item')
108
+ return asArray(o.item).map(plain);
109
+ const out = {};
110
+ for (const k of keys)
111
+ out[k] = plain(o[k]);
112
+ return out;
113
+ }
114
+ /** Scalar fields of an object element that are not empty. */
115
+ function scalars(o) {
116
+ const out = {};
117
+ for (const [k, v] of Object.entries(o ?? {})) {
118
+ if (k.startsWith('@_') || k === '#text')
119
+ continue;
120
+ if (v === null || v === undefined)
121
+ continue;
122
+ if (typeof v === 'object' && !('#text' in v))
123
+ continue;
124
+ const s = trimmed(v);
125
+ if (s !== '')
126
+ out[k] = s;
127
+ }
128
+ return out;
129
+ }
130
+ // ---------------------------------------------------------------------------
131
+ // XML parsing
132
+ // ---------------------------------------------------------------------------
133
+ const OBJECT_KINDS = [
134
+ 'PAGE',
135
+ 'WINDOW',
136
+ 'TEXT',
137
+ 'SECTION',
138
+ 'GRAPHIC',
139
+ 'ADDRESS',
140
+ 'CODE',
141
+ 'COMMAND',
142
+ 'CONDITION',
143
+ 'EVENT',
144
+ ];
145
+ /** Section types (SECTTYPE). */
146
+ const SECTION_KINDS = {
147
+ S: 'template',
148
+ L: 'loop',
149
+ T: 'table46',
150
+ };
151
+ function sectionKind(code) {
152
+ return SECTION_KINDS[code] ?? (code ? `section-${code}` : 'folder');
153
+ }
154
+ const TEXT_TYPES = {
155
+ '': 'inline',
156
+ I: 'include',
157
+ R: 'reference',
158
+ D: 'dynamic',
159
+ A: 'application',
160
+ F: 'form',
161
+ };
162
+ function objectOf(node) {
163
+ const objEl = node?.OBJ;
164
+ if (!objEl || typeof objEl !== 'object')
165
+ return null;
166
+ for (const k of OBJECT_KINDS) {
167
+ if (objEl[k] !== undefined) {
168
+ const o = Array.isArray(objEl[k]) ? objEl[k][0] : objEl[k];
169
+ return { kind: k, obj: (o ?? {}) };
170
+ }
171
+ }
172
+ const first = Object.keys(objEl).find((k) => !k.startsWith('@_') && k !== '#text');
173
+ if (!first)
174
+ return null;
175
+ return { kind: first, obj: (objEl[first] ?? {}) };
176
+ }
177
+ /** Node name: `<NAME><INAME>%TEXT1</INAME></NAME>`, or a plain INAME / NAME. */
178
+ function nameOf(obj) {
179
+ const n = obj?.NAME;
180
+ if (n && typeof n === 'object' && !('#text' in n))
181
+ return trimmed(n.INAME);
182
+ return trimmed(obj?.INAME ?? n);
183
+ }
184
+ function num(v) {
185
+ const s = trimmed(v);
186
+ if (s === '')
187
+ return null;
188
+ const n = Number(s);
189
+ return Number.isFinite(n) ? n : null;
190
+ }
191
+ /** A length in mm from a value and its unit field (CM / MM / IN / PT / TW). */
192
+ function mmOf(value, unit) {
193
+ const v = trimmed(value);
194
+ if (v === '')
195
+ return null;
196
+ return (0, smartFormLayout_1.toMm)(v, trimmed(unit).toUpperCase(), smartFormLayout_1.DEFAULT_LPI, smartFormLayout_1.DEFAULT_CPI);
197
+ }
198
+ /** RGB as #rrggbb, blended toward white when the intensity (%) is below 100. */
199
+ function colorOf(c, intensity = 100) {
200
+ if (!c || typeof c !== 'object')
201
+ return undefined;
202
+ const k = Math.max(0, Math.min(100, intensity)) / 100;
203
+ const hex = (x) => {
204
+ const v = Math.max(0, Math.min(255, Number(trimmed(x)) || 0));
205
+ return Math.round(255 - (255 - v) * k)
206
+ .toString(16)
207
+ .padStart(2, '0');
208
+ };
209
+ return `#${hex(c.RED)}${hex(c.GREEN)}${hex(c.BLUE)}`;
210
+ }
211
+ /** Template lines (STATLINES): line name, line range, height. */
212
+ function templateLinesOf(v) {
213
+ return asArray(v?.item).map((it) => ({
214
+ name: trimmed(it?.NAME),
215
+ from: num(it?.LINEFROM),
216
+ to: num(it?.LINETO),
217
+ heightMm: mmOf(it?.LHEIGHT, it?.U_LHEIGHT),
218
+ shading: num(it?.SHADING) ?? 0,
219
+ // a line type that refers to another one takes its height when it has none
220
+ ...(trimmed(it?.REFERENCE) ? { reference: trimmed(it?.REFERENCE) } : {}),
221
+ }));
222
+ }
223
+ /** Cells (CELLS): line name, column, width, fill and border widths (mm, 0 = none). */
224
+ function cellsOf(v) {
225
+ // A line type that covers a row range (LINEFROM..LINETO) has one BORDERS item
226
+ // per row (IDX 001 = first row of the range): each row may draw other lines.
227
+ const look = (b) => {
228
+ const side = (w, c) => {
229
+ const mm = mmOf(b[w], b[`${w}_U`]) ?? 0;
230
+ return mm > 0 && trimmed(b[c]?.USED) === 'X' ? mm : 0;
231
+ };
232
+ // INTENSITY = shading in % of the colour: 0 means no fill even when USED = X.
233
+ const intensity = num(b.INTENSITY) ?? 100;
234
+ const fill = trimmed(b.FILLCOLOR?.USED) === 'X' && intensity > 0
235
+ ? colorOf(b.FILLCOLOR, intensity)
236
+ : undefined;
237
+ return {
238
+ ...(fill ? { fill } : {}),
239
+ borders: {
240
+ left: side('LLEFT', 'CLEFT'),
241
+ top: side('LTOP', 'CTOP'),
242
+ right: side('LRIGHT', 'CRIGHT'),
243
+ bottom: side('LBOTTOM', 'CBOTTOM'),
244
+ },
245
+ };
246
+ };
247
+ return asArray(v?.item).map((it) => {
248
+ const items = asArray(it?.BORDERS?.item);
249
+ const first = look((items[0] ?? {}));
250
+ const rows = items.map(look);
251
+ const varies = rows.some((r) => JSON.stringify(r) !== JSON.stringify(first));
252
+ return {
253
+ line: trimmed(it?.NAME),
254
+ column: num(it?.COLUMNNR),
255
+ widthMm: mmOf(it?.CWIDTH, it?.U_CWIDTH),
256
+ ...first,
257
+ ...(varies ? { rows } : {}),
258
+ };
259
+ });
260
+ }
261
+ function captionOf(obj) {
262
+ const c = obj?.CAPTION;
263
+ if (c !== undefined && typeof c !== 'object')
264
+ return trimmed(c);
265
+ if (c && typeof c === 'object' && '#text' in c)
266
+ return trimmed(c);
267
+ // T_CAPTION: [{LANGU / SPRAS, CAPTION / TEXT}] — first entry
268
+ const items = asArray(obj?.T_CAPTION?.item);
269
+ for (const it of items) {
270
+ const t = trimmed(it?.CAPTION ?? it?.TEXT ?? it?.TDCAPTION);
271
+ if (t)
272
+ return t;
273
+ }
274
+ return '';
275
+ }
276
+ function textLines(v) {
277
+ const items = asArray(v?.item);
278
+ return items.map((it) => ({
279
+ format: trimmed(it?.TDFORMAT),
280
+ text: str(it?.TDLINE).replace(/\s+$/, ''),
281
+ }));
282
+ }
283
+ function outputAttrs(node) {
284
+ const oa = node?.OUTATTR;
285
+ if (!oa || typeof oa !== 'object')
286
+ return undefined;
287
+ const inner = oa.OUTATTR ?? oa[Object.keys(oa).find((k) => !k.startsWith('@_')) ?? ''];
288
+ const s = scalars((inner ?? oa));
289
+ return Object.keys(s).length ? s : undefined;
290
+ }
291
+ /**
292
+ * Box of a window / node (output options → Box and shading): per side the
293
+ * line thickness and the distance of the text from it, in mm; shading as a
294
+ * colour blended toward white by its intensity. Undefined when nothing is drawn.
295
+ */
296
+ function boxOf(node) {
297
+ const oa = node?.OUTATTR;
298
+ if (!oa || typeof oa !== 'object')
299
+ return undefined;
300
+ const inner = (oa.OUTATTR ??
301
+ oa[Object.keys(oa).find((k) => !k.startsWith('@_')) ?? '']);
302
+ const b = (inner?.BORDER ?? {});
303
+ // a side is drawn only with its <LEFT|TOP|RIGHT|BOTTOM>LINE flag; the
304
+ // thickness is there (default 15 TW) whether the line is on or not.
305
+ // Thickness 0 with the flag on is the printer's thinnest line, not "off"
306
+ // (ZSDRA0390_CI_T %WINDOW3 / %WINDOW7 hairline frames).
307
+ const side = (k) => {
308
+ const a = (b[k] ?? {});
309
+ const on = trimmed(b[k.replace('ATTR', 'LINE')]) === 'X';
310
+ const c = (a.COLOR ?? {});
311
+ return {
312
+ mm: on ? ((0, smartFormLayout_1.toMm)(trimmed(a.THICKNESS), trimmed(a.THICKNESSU)) ?? 0) : 0,
313
+ ...(on ? { on: true } : {}),
314
+ distanceMm: (0, smartFormLayout_1.toMm)(trimmed(a.DISTANCE), trimmed(a.DISTANCEU)) ?? 0,
315
+ color: rgbHex(c),
316
+ };
317
+ };
318
+ const box = {
319
+ left: side('LEFTATTR'),
320
+ top: side('TOPATTR'),
321
+ right: side('RIGHTATTR'),
322
+ bottom: side('BOTTOMATTR'),
323
+ };
324
+ const sh = (inner?.SHADING ?? b.SHADING);
325
+ const fill = sh && typeof sh === 'object' && trimmed(sh.USED) === 'X'
326
+ ? blend(rgbHex((sh.COLOR ?? sh)), num(sh.INTENSITY) ?? 100)
327
+ : undefined;
328
+ const any = Object.values(box).some((s) => s.mm > 0 || s.on);
329
+ if (!any && !fill)
330
+ return undefined;
331
+ return { ...box, ...(fill ? { fill } : {}) };
332
+ }
333
+ function rgbHex(c) {
334
+ const h = (v) => Math.max(0, Math.min(255, Number(v) || 0))
335
+ .toString(16)
336
+ .padStart(2, '0');
337
+ return `#${h(c?.RED)}${h(c?.GREEN)}${h(c?.BLUE)}`;
338
+ }
339
+ function blend(hex, intensity) {
340
+ const p = Math.max(0, Math.min(100, intensity)) / 100;
341
+ const ch = (i) => Math.round(255 - (255 - parseInt(hex.slice(i, i + 2), 16)) * p)
342
+ .toString(16)
343
+ .padStart(2, '0');
344
+ return `#${ch(1)}${ch(3)}${ch(5)}`;
345
+ }
346
+ // The four checkboxes of a node's Conditions tab: only on first page / only on
347
+ // subsequent pages / only after / only before the end of the main window.
348
+ // (L = end of the main window, not the last page: an NLPAGE node of the main
349
+ // window prints on a one-page document.)
350
+ const OCOND_NAMES = {
351
+ FPAGE: 'firstPage',
352
+ NFPAGE: 'notFirstPage',
353
+ LPAGE: 'afterMainEnd',
354
+ NLPAGE: 'beforeMainEnd',
355
+ };
356
+ /**
357
+ * Print condition of a node (`<COND><CONDITION>`): the page flags of OCOND
358
+ * by name, other condition fields (field comparisons) raw.
359
+ */
360
+ function conditionOf(node) {
361
+ const c = node?.COND;
362
+ if (!c || typeof c !== 'object')
363
+ return undefined;
364
+ const cd = (c.CONDITION ?? c);
365
+ const out = {};
366
+ for (const [k, v] of Object.entries(scalars((cd.OCOND ?? {})))) {
367
+ if (v === 'X')
368
+ out[OCOND_NAMES[k] ?? k] = true;
369
+ else
370
+ out[k] = v;
371
+ }
372
+ for (const [k, v] of Object.entries(cd)) {
373
+ if (k.startsWith('@_') ||
374
+ ['NAME', 'CAPTION', 'T_CAPTION', 'OCOND'].includes(k))
375
+ continue;
376
+ const p = plain(v);
377
+ if (p === '' || (Array.isArray(p) && p.length === 0))
378
+ continue;
379
+ out[k] = p;
380
+ }
381
+ return Object.keys(out).length ? out : undefined;
382
+ }
383
+ const KNOWN_TEXT_FIELDS = new Set([
384
+ 'INAME',
385
+ 'CAPTION',
386
+ 'T_CAPTION',
387
+ 'TEXT',
388
+ 'T_TEXT',
389
+ 'TTYPE',
390
+ 'TKEY',
391
+ 'STYLE_NAME',
392
+ 'TABLINE',
393
+ 'INP_FIELDS',
394
+ ]);
395
+ class Walker {
396
+ ids = new Map();
397
+ graphicKeys = new Map();
398
+ /** graphics whose key holds a &symbol& (resolved later from sample values) */
399
+ dynamicGraphics = [];
400
+ textKeys = new Map();
401
+ styles = new Set();
402
+ dynamic = [];
403
+ constructor(root) {
404
+ this.index(root, 0);
405
+ }
406
+ index(v, depth) {
407
+ if (depth > 200 || !v || typeof v !== 'object')
408
+ return;
409
+ if (Array.isArray(v)) {
410
+ for (const x of v)
411
+ this.index(x, depth + 1);
412
+ return;
413
+ }
414
+ const o = v;
415
+ const id = o['@_ID'];
416
+ if (id !== undefined && !this.ids.has(String(id)))
417
+ this.ids.set(String(id), o);
418
+ for (const [k, x] of Object.entries(o)) {
419
+ if (!k.startsWith('@_'))
420
+ this.index(x, depth + 1);
421
+ }
422
+ }
423
+ /** A NODE element may be a reference (IDREF) to a node written earlier. */
424
+ resolve(node) {
425
+ const ref = node?.['@_IDREF'];
426
+ if (ref !== undefined)
427
+ return this.ids.get(String(ref)) ?? node;
428
+ return node;
429
+ }
430
+ succ(node) {
431
+ const s = node?.SUCC;
432
+ if (!s || typeof s !== 'object')
433
+ return [];
434
+ const items = asArray(s.item ?? s.NODE);
435
+ const out = [];
436
+ for (const it of items) {
437
+ // item may wrap a NODE element or be the node itself
438
+ const n = it?.NODE ?? it;
439
+ for (const x of asArray(n))
440
+ out.push(this.resolve(x));
441
+ }
442
+ return out;
443
+ }
444
+ /** Nodes under PROC_CTRL of an object (a window's content). */
445
+ procCtrl(obj) {
446
+ const pc = obj?.PROC_CTRL;
447
+ if (!pc || typeof pc !== 'object')
448
+ return [];
449
+ return asArray(pc.NODE).map((n) => this.resolve(n));
450
+ }
451
+ /**
452
+ * Content nodes for a list of XML nodes. Structural nodes without an
453
+ * object (the RC root container of a window) are replaced by their
454
+ * children.
455
+ */
456
+ contents(nodes, depth) {
457
+ const out = [];
458
+ for (const n of nodes) {
459
+ if (depth > 60)
460
+ break;
461
+ if (!objectOf(n) && !n?.COND) {
462
+ out.push(...this.contents(this.succ(n), depth + 1));
463
+ continue;
464
+ }
465
+ const c = this.content(n, depth);
466
+ if (c)
467
+ out.push(c);
468
+ }
469
+ return out;
470
+ }
471
+ content(node, depth) {
472
+ if (depth > 60)
473
+ return null;
474
+ const ob = objectOf(node);
475
+ const children = this.contents([...(ob ? this.procCtrl(ob.obj) : []), ...this.succ(node)], depth + 1);
476
+ if (!ob) {
477
+ // structural node without object but with a condition
478
+ if (children.length === 0)
479
+ return null;
480
+ const g = { kind: 'group', name: '', caption: '', children };
481
+ const cond = conditionOf(node);
482
+ if (cond !== undefined)
483
+ g.condition = cond;
484
+ return g;
485
+ }
486
+ const { kind, obj } = ob;
487
+ const out = {
488
+ kind: kind.toLowerCase(),
489
+ name: nameOf(obj),
490
+ caption: captionOf(obj),
491
+ children,
492
+ };
493
+ const cond = conditionOf(node);
494
+ if (cond !== undefined)
495
+ out.condition = cond;
496
+ const nbox = boxOf(node);
497
+ if (nbox)
498
+ out.box = nbox;
499
+ // alternative: its test (COND lines) decides between the TRUE (+) and FALSE (-) events
500
+ if (kind === 'CONDITION' && obj.COND) {
501
+ const t = plain(obj.COND);
502
+ if (Array.isArray(t) && t.length)
503
+ out.test = t;
504
+ }
505
+ const oa = outputAttrs(node);
506
+ if (oa) {
507
+ // inside a table / template the output attributes carry the cell
508
+ const line = oa.T_LINENR;
509
+ const cell = oa.T_CELLNR;
510
+ if (line || cell) {
511
+ out.tableCell = { line: num(line), cell: num(cell) };
512
+ delete oa.T_LINENR;
513
+ delete oa.T_CELLNR;
514
+ }
515
+ // unit fields alone say nothing
516
+ const meaningful = Object.keys(oa).filter((k) => !k.startsWith('U_'));
517
+ if (meaningful.length)
518
+ out.output = oa;
519
+ // a style named only in the output options (template / window STDSTYLE) is read too:
520
+ // texts whose own style is missing print in it (ZSDM43020_SHIPPING ZSDM43020_CMR_STYLE)
521
+ const std = trimmed(oa.STDSTYLE);
522
+ if (std)
523
+ this.styles.add(std);
524
+ }
525
+ switch (kind) {
526
+ case 'TEXT': {
527
+ const tt = trimmed(obj.TTYPE);
528
+ out.textType = TEXT_TYPES[tt] ?? tt;
529
+ const style = trimmed(obj.STYLE_NAME);
530
+ if (style) {
531
+ out.style = style;
532
+ this.styles.add(style);
533
+ }
534
+ if (obj.TEXT && typeof obj.TEXT === 'object')
535
+ out.lines = textLines(obj.TEXT);
536
+ if (tt === 'I' || tt === 'R') {
537
+ const k = (obj.TKEY ?? {});
538
+ const key = {
539
+ object: trimmed(k.OBJECT) || 'TEXT',
540
+ name: trimmed(k.NAME),
541
+ id: trimmed(k.ID) || 'ST',
542
+ language: trimmed(k.LANG),
543
+ resolved: false,
544
+ };
545
+ if (tt === 'R')
546
+ key.name = key.name || trimmed(obj.REF_NAME);
547
+ out.include = key;
548
+ const dyn = [key.object, key.name, key.id, key.language].some(hasSymbol);
549
+ if (key.name && !dyn) {
550
+ this.textKeys.set(`${key.object}|${key.name}|${key.id}|${key.language}`, key);
551
+ }
552
+ else if (key.name) {
553
+ this.dynamic.push(`text ${out.name}: ${key.object} ${key.name} ${key.id} ${key.language}`);
554
+ }
555
+ }
556
+ const tabline = plain(obj.TABLINE);
557
+ if (!out.tableCell &&
558
+ tabline &&
559
+ !(Array.isArray(tabline) && tabline.length === 0))
560
+ out.tableCell = tabline;
561
+ const rest = {};
562
+ for (const [k, v] of Object.entries(scalars(obj))) {
563
+ if (!KNOWN_TEXT_FIELDS.has(k))
564
+ rest[k] = v;
565
+ }
566
+ if (Object.keys(rest).length)
567
+ out.attrs = rest;
568
+ break;
569
+ }
570
+ case 'SECTION': {
571
+ const st = trimmed(obj.SECTTYPE);
572
+ out.kind = sectionKind(st);
573
+ out.sectionType = st;
574
+ const tab = trimmed(obj.TABNAME);
575
+ if (tab)
576
+ out.dataTable = tab;
577
+ // loop / table WHERE (WCOND lines: OP1 a field of the row, OP2 a value or another field)
578
+ const wc = plain(obj.WCOND);
579
+ if (Array.isArray(wc) && wc.length)
580
+ out.where = wc;
581
+ const w = trimmed(obj.WIDTH);
582
+ if (w) {
583
+ const u = trimmed(obj.U_WIDTH).toUpperCase();
584
+ out.width = {
585
+ value: w,
586
+ unit: u,
587
+ mm: (0, smartFormLayout_1.toMm)(w, u, smartFormLayout_1.DEFAULT_LPI, smartFormLayout_1.DEFAULT_CPI),
588
+ };
589
+ }
590
+ // table line types (DYNLINES) and template lines (STATLINES) share a shape
591
+ const dyn = templateLinesOf(obj.DYNLINES);
592
+ if (dyn.length)
593
+ out.lineTypes = dyn;
594
+ const stat = templateLinesOf(obj.STATLINES);
595
+ if (stat.length)
596
+ out.templateLines = stat;
597
+ const cells = cellsOf(obj.CELLS);
598
+ if (cells.length)
599
+ out.cells = cells;
600
+ // Pattern + frame of the whole template / table. PATTERN-BORDER = 'X' draws the outer
601
+ // frame for any pattern but 0000 (the pattern gives the inner lines); USEBORDER is the
602
+ // "use cell borders" switch, not the frame.
603
+ const pat = obj.PATTERN;
604
+ if (pat && typeof pat === 'object') {
605
+ out.frame = {
606
+ pattern: trimmed(pat.PATTNUM),
607
+ lineMm: (0, smartFormLayout_1.toMm)(trimmed(pat.FRAME), trimmed(pat.U_FRAME)) ?? 0,
608
+ outer: trimmed(obj.USEBORDER) === 'X',
609
+ border: trimmed(pat.BORDER) === 'X',
610
+ };
611
+ }
612
+ const s = scalars(obj);
613
+ for (const k of ['INAME', 'SECTTYPE', 'TABNAME', 'WIDTH', 'U_WIDTH'])
614
+ delete s[k];
615
+ if (Object.keys(s).length)
616
+ out.attrs = s;
617
+ break;
618
+ }
619
+ case 'GRAPHIC': {
620
+ const k = (obj.GKEYBDS ?? {});
621
+ const g = {
622
+ object: trimmed(k.OBJECT) || 'GRAPHICS',
623
+ name: trimmed(k.NAME),
624
+ id: trimmed(k.ID) || 'BMAP',
625
+ btype: trimmed(k.BTYPE) || 'BCOL',
626
+ resolution: trimmed(obj.RESOLUTION),
627
+ dynamic: false,
628
+ };
629
+ g.dynamic = [g.object, g.name, g.id, g.btype].some(hasSymbol);
630
+ out.graphic = g;
631
+ if (g.name && !g.dynamic) {
632
+ this.graphicKeys.set(`${g.object}|${g.name}|${g.id}|${g.btype}`, g);
633
+ }
634
+ else if (g.name) {
635
+ this.dynamicGraphics.push(g);
636
+ this.dynamic.push(`graphic ${out.name}: ${g.object} ${g.name} ${g.id} ${g.btype}`);
637
+ }
638
+ const s = scalars(obj);
639
+ delete s.INAME;
640
+ if (Object.keys(s).length)
641
+ out.attrs = s;
642
+ break;
643
+ }
644
+ case 'CODE': {
645
+ // Program lines are never returned — only that a code node is here.
646
+ out.attrs = undefined;
647
+ break;
648
+ }
649
+ default: {
650
+ const s = scalars(obj);
651
+ delete s.INAME;
652
+ if (Object.keys(s).length)
653
+ out.attrs = s;
654
+ }
655
+ }
656
+ return out;
657
+ }
658
+ }
659
+ function orientationName(raw) {
660
+ const o = raw.toUpperCase();
661
+ if (o === '' || o === 'P')
662
+ return 'portrait';
663
+ if (o === 'L')
664
+ return 'landscape';
665
+ return o;
666
+ }
667
+ function lengthMm(attrs, key, lpi, cpi) {
668
+ if (!attrs || attrs[key] === undefined)
669
+ return null;
670
+ return (0, smartFormLayout_1.toMm)(attrs[key], attrs[`U_${key}`], lpi, cpi);
671
+ }
672
+ const IO_SCOPE = {
673
+ I: 'import',
674
+ E: 'export',
675
+ C: 'changing',
676
+ T: 'tables',
677
+ };
678
+ /** INTERFACE (minus standard parameters and exceptions) + GDATA of the form root. */
679
+ function dataDeclsOf(sf) {
680
+ const out = [];
681
+ for (const it of asArray(sf.INTERFACE?.item)) {
682
+ const scope = IO_SCOPE[trimmed(it?.IOTYPE).toUpperCase()];
683
+ if (!scope || trimmed(it?.STANDARD) === 'X')
684
+ continue;
685
+ out.push({
686
+ name: trimmed(it?.NAME),
687
+ scope,
688
+ typing: trimmed(it?.TYPING),
689
+ typeName: trimmed(it?.TYPENAME),
690
+ });
691
+ }
692
+ for (const it of asArray(sf.GDATA?.item)) {
693
+ out.push({
694
+ name: trimmed(it?.NAME),
695
+ scope: 'global',
696
+ typing: trimmed(it?.TYPING),
697
+ typeName: trimmed(it?.TYPENAME),
698
+ });
699
+ }
700
+ return out.filter((d) => d.name);
701
+ }
702
+ /** Parse the Form Builder XML of FB_CONVERT_FORM_TO_XML. */
703
+ function parseSmartFormXml(xml) {
704
+ const parser = new fast_xml_parser_1.XMLParser({
705
+ ignoreAttributes: false,
706
+ attributeNamePrefix: '@_',
707
+ removeNSPrefix: true,
708
+ parseTagValue: false,
709
+ parseAttributeValue: false,
710
+ trimValues: false,
711
+ isArray: (name) => name === 'item',
712
+ });
713
+ const doc = parser.parse(xml);
714
+ const sf = (doc.SMARTFORM ?? doc);
715
+ const walker = new Walker(sf);
716
+ const pages = [];
717
+ const stdStyles = [];
718
+ const variants = asArray(sf.VARHEADER?.item);
719
+ for (const v of variants) {
720
+ const lpi = Number(trimmed(v.LPI)) || smartFormLayout_1.DEFAULT_LPI;
721
+ const cpi = Number(trimmed(v.CPI)) || smartFormLayout_1.DEFAULT_CPI;
722
+ const std = trimmed(v.STDSTYLE);
723
+ if (std && !stdStyles.includes(std))
724
+ stdStyles.push(std);
725
+ const tree = v.PAGETREE;
726
+ const roots = asArray((tree?.NODE ?? tree)).map((n) => walker.resolve(n));
727
+ const visit = (node, depth) => {
728
+ if (depth > 40)
729
+ return;
730
+ const ob = objectOf(node);
731
+ if (ob?.kind === 'PAGE') {
732
+ const p = ob.obj;
733
+ const page = {
734
+ variant: trimmed(v.VARI),
735
+ name: nameOf(p),
736
+ caption: captionOf(p),
737
+ format: trimmed(v.PAGEFORMAT),
738
+ orientation: orientationName(trimmed(p.PAGEORTN)),
739
+ nextPage: p.NEXTPAGE && typeof p.NEXTPAGE === 'object'
740
+ ? nameOf({ NAME: p.NEXTPAGE })
741
+ : trimmed(p.NEXTPAGE),
742
+ stdStyle: std,
743
+ windows: [],
744
+ };
745
+ for (const child of walker.succ(node)) {
746
+ const cob = objectOf(child);
747
+ if (!cob)
748
+ continue;
749
+ const oa = outputAttrs(child);
750
+ const isWindow = cob.kind === 'WINDOW';
751
+ const typeCode = isWindow
752
+ ? trimmed(cob.obj.WTYPE).toUpperCase()
753
+ : cob.kind === 'GRAPHIC'
754
+ ? 'G'
755
+ : cob.kind === 'ADDRESS'
756
+ ? 'A'
757
+ : '';
758
+ const win = {
759
+ name: nameOf(cob.obj),
760
+ caption: captionOf(cob.obj),
761
+ type: (0, smartFormLayout_1.windowTypeName)(typeCode) || cob.kind,
762
+ typeCode,
763
+ leftMm: lengthMm(oa, 'WLEFT', lpi, cpi),
764
+ topMm: lengthMm(oa, 'WTOP', lpi, cpi),
765
+ widthMm: lengthMm(oa, 'WWIDTH', lpi, cpi),
766
+ heightMm: lengthMm(oa, 'WHEIGHT', lpi, cpi),
767
+ content: [],
768
+ };
769
+ const cond = conditionOf(child);
770
+ if (cond !== undefined)
771
+ win.condition = cond;
772
+ const wbox = boxOf(child);
773
+ if (wbox)
774
+ win.box = wbox;
775
+ if (isWindow) {
776
+ // window content hangs under WINDOW/PROC_CTRL
777
+ win.content = walker.contents([...walker.procCtrl(cob.obj), ...walker.succ(child)], 0);
778
+ }
779
+ else {
780
+ // graphic / address placed directly on the page: the node itself
781
+ const self = walker.content({ ...child, SUCC: undefined }, 0);
782
+ if (self)
783
+ win.content = [self];
784
+ }
785
+ page.windows.push(win);
786
+ }
787
+ pages.push(page);
788
+ return;
789
+ }
790
+ for (const c of walker.succ(node))
791
+ visit(c, depth + 1);
792
+ };
793
+ for (const r of roots)
794
+ visit(r, 0);
795
+ }
796
+ return {
797
+ data: dataDeclsOf(sf),
798
+ stdStyles,
799
+ pages,
800
+ graphicKeys: [...walker.graphicKeys.values()],
801
+ dynamicGraphics: walker.dynamicGraphics,
802
+ textKeys: [...walker.textKeys.values()],
803
+ styles: [...walker.styles],
804
+ dynamic: walker.dynamic,
805
+ };
806
+ }
807
+ // ---------------------------------------------------------------------------
808
+ // SAP calls
809
+ // ---------------------------------------------------------------------------
810
+ function translateSmartFormContentError(error) {
811
+ const msg = error instanceof Error ? error.message : String(error);
812
+ if (/Unknown action:\s*SSF_CONTENT/i.test(msg) ||
813
+ /SOAP Fault:[\s\S]*(FU_NOT_FOUND|ZMCP_ADT_DISPATCH)/i.test(msg) ||
814
+ /ZMCP_SSF_CONTENT[\s\S]*(not found|does not exist|not exist)|(CALL_FUNCTION_NOT_FOUND|FU_NOT_FOUND)[\s\S]*ZMCP_SSF_CONTENT/i.test(msg)) {
815
+ return `${exports.SSF_CONTENT_INSTALL_HINT} (SAP said: ${msg})`;
816
+ }
817
+ const m = msg.match(/subrc=(\d+)\):\s*([\s\S]*)$/);
818
+ if (m)
819
+ return m[2].trim() || msg;
820
+ return msg;
821
+ }
822
+ async function part(connection, params) {
823
+ let result;
824
+ try {
825
+ ({ result } = await (0, rfcBackend_1.callDispatch)(connection, 'SSF_CONTENT', params));
826
+ }
827
+ catch (error) {
828
+ throw new Error(translateSmartFormContentError(error));
829
+ }
830
+ if (result === null || typeof result !== 'object') {
831
+ throw new Error(`SSF_CONTENT ${params.part} returned no JSON object: ${String(result).substring(0, 200)}`);
832
+ }
833
+ return result;
834
+ }
835
+ function fileSafe(s) {
836
+ return s
837
+ .trim()
838
+ .toLowerCase()
839
+ .replace(/\//g, '#')
840
+ .replace(/[^a-z0-9_#.-]/g, '_');
841
+ }
842
+ function writeOut(rel, data) {
843
+ const abs = (0, sourceOutput_1.safeOutputPath)(rel);
844
+ fs.mkdirSync(path.dirname(abs), { recursive: true });
845
+ fs.writeFileSync(abs, data);
846
+ return abs;
847
+ }
848
+ /** Every &symbol& printed by text lines of the form (system symbols included), sorted. */
849
+ function symbolsOf(pages) {
850
+ const set = new Set();
851
+ const visit = (n) => {
852
+ for (const l of n.lines ?? [])
853
+ for (const m of l.text.matchAll(/&([^&\s][^&]*?)&/g))
854
+ set.add(m[1].replace(/\(.*\)$/, '').trim());
855
+ for (const c of n.children ?? [])
856
+ visit(c);
857
+ };
858
+ for (const p of pages)
859
+ for (const w of p.windows)
860
+ for (const n of w.content)
861
+ visit(n);
862
+ return [...set].sort();
863
+ }
864
+ /** Compact view for the tool answer when the full content is read from files.content. */
865
+ function summarizeSmartFormContent(c) {
866
+ const count = (list) => list.reduce((n, x) => n + 1 + count(x.children ?? []), 0);
867
+ return {
868
+ form: c.form,
869
+ language: c.language,
870
+ data: c.data,
871
+ stdStyles: c.stdStyles,
872
+ pages: c.pages.map((p) => ({
873
+ name: p.name,
874
+ format: p.format,
875
+ orientation: p.orientation,
876
+ windows: p.windows.map((w) => ({
877
+ name: w.name,
878
+ caption: w.caption,
879
+ type: w.type,
880
+ leftMm: w.leftMm,
881
+ topMm: w.topMm,
882
+ widthMm: w.widthMm,
883
+ heightMm: w.heightMm,
884
+ ...(w.condition !== undefined ? { condition: w.condition } : {}),
885
+ nodes: count(w.content),
886
+ })),
887
+ })),
888
+ styles: c.styles.map(({ css, ...rest }) => rest),
889
+ graphics: c.graphics,
890
+ includeTexts: c.includeTexts.map(({ lines, ...rest }) => ({
891
+ ...rest,
892
+ lines: lines?.length ?? 0,
893
+ })),
894
+ symbols: symbolsOf(c.pages),
895
+ dynamicReferences: c.dynamicReferences,
896
+ files: c.files,
897
+ path: c.path,
898
+ };
899
+ }
900
+ async function getSmartFormContent(connection, formName, options = {}) {
901
+ const form = String(formName ?? '')
902
+ .trim()
903
+ .toUpperCase();
904
+ const formRes = await part(connection, { part: 'FORM', form_name: form });
905
+ const xml = Buffer.from(String(formRes.xml ?? ''), 'base64').toString('utf8');
906
+ if (!xml.trim())
907
+ throw new Error(`SSF_CONTENT FORM returned an empty XML for ${form}`);
908
+ const dir = `smartforms/${fileSafe(form)}`;
909
+ const xmlFile = writeOut(`${dir}/${fileSafe(form)}.xml`, xml);
910
+ const parsed = parseSmartFormXml(xml);
911
+ const language = trimmed(formRes.language);
912
+ // A text with no translation in the logon language prints in the form's master language
913
+ // (ZEARC_F001: master T, logon E — SAP printed the Turkish texts). The XML carries the
914
+ // logon language only, so the texts that came back empty are taken from the master's XML.
915
+ const master = (/<MASTERLANG>([^<]*)<\/MASTERLANG>/.exec(xml)?.[1] ?? '').trim();
916
+ if (master && language && master !== language) {
917
+ const empty = [];
918
+ const walk = (n) => {
919
+ if (n.kind === 'text' && n.textType === 'inline' && !n.lines?.length)
920
+ empty.push(n);
921
+ for (const c of n.children ?? [])
922
+ walk(c);
923
+ };
924
+ for (const p of parsed.pages)
925
+ for (const w of p.windows)
926
+ for (const n of w.content)
927
+ walk(n);
928
+ if (empty.length) {
929
+ try {
930
+ const mRes = await part(connection, {
931
+ part: 'FORM',
932
+ form_name: form,
933
+ language: master,
934
+ });
935
+ const mXml = Buffer.from(String(mRes.xml ?? ''), 'base64').toString('utf8');
936
+ if (mXml.trim() && trimmed(mRes.language) === master) {
937
+ const byName = new Map();
938
+ const index = (n) => {
939
+ if (n.kind === 'text' && n.lines?.length)
940
+ byName.set(n.name, n);
941
+ for (const c of n.children ?? [])
942
+ index(c);
943
+ };
944
+ for (const p of parseSmartFormXml(mXml).pages)
945
+ for (const w of p.windows)
946
+ for (const n of w.content)
947
+ index(n);
948
+ for (const n of empty) {
949
+ const m = byName.get(n.name);
950
+ if (m?.lines)
951
+ n.lines = m.lines;
952
+ }
953
+ }
954
+ }
955
+ catch {
956
+ // an older ZMCP_SSF_CONTENT without IV_LANGUAGE for FORM: keep the logon-language texts
957
+ }
958
+ }
959
+ }
960
+ const out = {
961
+ form,
962
+ language,
963
+ data: parsed.data,
964
+ stdStyles: parsed.stdStyles,
965
+ pages: parsed.pages,
966
+ styles: [],
967
+ graphics: [],
968
+ includeTexts: [],
969
+ dynamicReferences: parsed.dynamic,
970
+ files: { xml: xmlFile },
971
+ path: `dispatch-${(0, rfcBackend_1.getBackend)()}`,
972
+ };
973
+ if (options.includeStyles !== false) {
974
+ const names = [...new Set([...parsed.stdStyles, ...parsed.styles])];
975
+ for (const name of names) {
976
+ if (hasSymbol(name))
977
+ continue;
978
+ try {
979
+ const r = await part(connection, { part: 'STYLE', name });
980
+ const css = Buffer.from(String(r.css ?? ''), 'base64').toString('utf8');
981
+ const file = writeOut(`${dir}/style_${fileSafe(name)}.css`, css);
982
+ out.styles.push({
983
+ name,
984
+ file,
985
+ css,
986
+ ...(r.firstParagraph !== undefined
987
+ ? {
988
+ firstParagraph: String(r.firstParagraph).trim(),
989
+ font: {
990
+ family: String(r.fontFamily ?? '').trim(),
991
+ pt: Number(r.fontSize ?? 0) / 10,
992
+ bold: String(r.bold ?? '').trim() === 'X',
993
+ },
994
+ lpi: Number(r.lpi) || undefined,
995
+ cpi: Number(r.cpi) || undefined,
996
+ tabDistance: String(r.tabDistance ?? '').trim() || undefined,
997
+ ...(Array.isArray(r.paragraphs)
998
+ ? { paragraphs: r.paragraphs }
999
+ : {}),
1000
+ ...(Array.isArray(r.strings) ? { strings: r.strings } : {}),
1001
+ }
1002
+ : {}),
1003
+ });
1004
+ }
1005
+ catch (e) {
1006
+ out.styles.push({
1007
+ name,
1008
+ error: e instanceof Error ? e.message : String(e),
1009
+ });
1010
+ }
1011
+ }
1012
+ // The printer the form would go to and its fonts for the form's families:
1013
+ // a family / size the device type lacks prints in a substitute font.
1014
+ const families = new Set();
1015
+ for (const s of out.styles) {
1016
+ if (s.font?.family)
1017
+ families.add(s.font.family.toUpperCase());
1018
+ for (const p of s.paragraphs ?? [])
1019
+ if (p.family)
1020
+ families.add(String(p.family).trim().toUpperCase());
1021
+ for (const c of s.strings ?? [])
1022
+ if (String(c.family ?? '').trim())
1023
+ families.add(String(c.family).trim().toUpperCase());
1024
+ }
1025
+ if (families.size) {
1026
+ try {
1027
+ const r = await part(connection, {
1028
+ part: 'FONTS',
1029
+ name: [...families].join(','),
1030
+ object: options.device ?? '',
1031
+ });
1032
+ out.printer = {
1033
+ device: String(r.device ?? '').trim(),
1034
+ deviceType: String(r.deviceType ?? '').trim(),
1035
+ families: Array.isArray(r.families) ? r.families : [],
1036
+ fonts: Array.isArray(r.fonts) ? r.fonts : [],
1037
+ };
1038
+ }
1039
+ catch (e) {
1040
+ out.printer = { error: e instanceof Error ? e.message : String(e) };
1041
+ }
1042
+ }
1043
+ }
1044
+ if (options.includeGraphics !== false) {
1045
+ // graphics named by a variable: fetched under the name the sample value gives
1046
+ const sub = (v) => String(v).replace(/&([^&]+)&/g, (m, k) => {
1047
+ const key = String(k).trim().toUpperCase();
1048
+ const hit = Object.entries(options.values ?? {}).find(([n]) => n.toUpperCase() === key);
1049
+ return hit ? String(hit[1]) : m;
1050
+ });
1051
+ const resolved = parsed.dynamicGraphics
1052
+ .map((g) => ({
1053
+ ...g,
1054
+ object: sub(g.object),
1055
+ name: sub(g.name),
1056
+ id: sub(g.id),
1057
+ btype: sub(g.btype),
1058
+ dynamic: false,
1059
+ }))
1060
+ .filter((g) => ![g.object, g.name, g.id, g.btype].some(hasSymbol));
1061
+ for (const g of [...parsed.graphicKeys, ...resolved]) {
1062
+ const entry = {
1063
+ object: g.object,
1064
+ name: g.name,
1065
+ id: g.id,
1066
+ btype: g.btype,
1067
+ };
1068
+ try {
1069
+ const r = await part(connection, {
1070
+ part: 'GRAPHIC',
1071
+ object: g.object,
1072
+ name: g.name,
1073
+ id: g.id,
1074
+ btype: g.btype,
1075
+ });
1076
+ const bmp = Buffer.from(String(r.bmp ?? ''), 'base64');
1077
+ entry.widthPix = Number(r.widthPix) || undefined;
1078
+ entry.heightPix = Number(r.heightPix) || undefined;
1079
+ entry.widthTw = Number(r.widthTw) || undefined;
1080
+ entry.heightTw = Number(r.heightTw) || undefined;
1081
+ entry.resolution = Number(r.resolution) || undefined;
1082
+ if (entry.widthTw)
1083
+ entry.widthMm = Math.round((entry.widthTw * 25.4 * 100) / 1440) / 100;
1084
+ if (entry.heightTw)
1085
+ entry.heightMm =
1086
+ Math.round((entry.heightTw * 25.4 * 100) / 1440) / 100;
1087
+ entry.file = writeOut(`${dir}/graphic_${fileSafe(g.name)}_${fileSafe(g.btype)}.bmp`, bmp);
1088
+ }
1089
+ catch (e) {
1090
+ entry.error = e instanceof Error ? e.message : String(e);
1091
+ }
1092
+ out.graphics.push(entry);
1093
+ }
1094
+ }
1095
+ if (options.includeTexts !== false) {
1096
+ for (const t of parsed.textKeys) {
1097
+ const lang = t.language || options.textLanguage || language;
1098
+ const entry = {
1099
+ object: t.object,
1100
+ name: t.name,
1101
+ id: t.id,
1102
+ language: lang,
1103
+ };
1104
+ try {
1105
+ const r = await part(connection, {
1106
+ part: 'STDTEXT',
1107
+ object: t.object,
1108
+ name: t.name,
1109
+ id: t.id,
1110
+ language: lang,
1111
+ });
1112
+ entry.lines = asArray(r.lines).map((l) => ({
1113
+ format: trimmed(l?.f),
1114
+ text: str(l?.l).replace(/\s+$/, ''),
1115
+ }));
1116
+ t.resolved = true;
1117
+ }
1118
+ catch (e) {
1119
+ entry.error = e instanceof Error ? e.message : String(e);
1120
+ }
1121
+ out.includeTexts.push(entry);
1122
+ }
1123
+ }
1124
+ // the whole result next to the XML, so preview builders read one file
1125
+ const contentRel = `${dir}/${fileSafe(form)}.content.json`;
1126
+ out.files.content = (0, sourceOutput_1.safeOutputPath)(contentRel);
1127
+ writeOut(contentRel, JSON.stringify(out, null, 1));
1128
+ return out;
1129
+ }
1130
+ //# sourceMappingURL=smartFormContent.js.map