xmlui 0.9.31 → 0.9.32

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.
@@ -1,542 +1,51 @@
1
- import { X as COMPOUND_COMP_ID } from "./transform-DC0Gy6qw.mjs";
2
- import { al, Y, aa, a6, a4, a9, a3, a7, _, a8, a5, a1, a0, a2, $, Q, R, ac, S, aj, ae, N, Z, ad, ap, ai, af, ah, ag, O, ak, ab, am, ao, an } from "./transform-DC0Gy6qw.mjs";
3
- import { d, L, a, c, g, e, l, b, m, p } from "./lint-CYAUfk0_.mjs";
4
- const attrBreakRegex = /[\r\n<>'"&]/;
5
- class XmlUiHelper {
6
- /**
7
- * Serialize the specified XML fragment into a string
8
- * @param xml XML fragment to serialize
9
- * @param options Formatting options to use
10
- */
11
- serialize(xml, options) {
12
- const fragment = Array.isArray(xml) ? xml : [xml];
13
- return serializeFragment(fragment, 0);
14
- function serializeFragment(nodes, depth) {
15
- return nodes.map((n) => serializeNode(n, depth)).join((options == null ? void 0 : options.prettify) ? "\n" + getIndent(depth) : "");
16
- }
17
- function serializeNode(node, depth) {
18
- switch (node.type) {
19
- case "XmlUiComment":
20
- return serializeXmlComment(node, depth);
21
- case "XmlUiElement":
22
- return serializeXmlElement(node, depth);
23
- default:
24
- return "";
25
- }
26
- }
27
- function getIndent(depth) {
28
- return (options == null ? void 0 : options.prettify) ? "".padEnd(((options == null ? void 0 : options.indents) ?? 2) * depth, " ") : "";
29
- }
30
- function serializeXmlComment(node, depth) {
31
- return `${getIndent(depth)}<!--${node.text}-->`;
32
- }
33
- function serializeXmlElement(node, depth) {
34
- var _a, _b;
35
- let elementStr = `${getIndent(depth)}<${nodeName()}`;
36
- const hasAttrs = (((_a = node.attributes) == null ? void 0 : _a.length) ?? 0) > 0;
37
- const hasChildren = (((_b = node.childNodes) == null ? void 0 : _b.length) ?? 0) > 0;
38
- if (node.text || hasAttrs || hasChildren) {
39
- if (hasAttrs) {
40
- const attrTexts = node.attributes.map((a10) => serializeXmlAttribute(a10));
41
- if (!(options == null ? void 0 : options.prettify)) {
42
- elementStr += " " + attrTexts.join(" ");
43
- } else {
44
- const nodeLength = elementStr.length + 1 + // --- Space after
45
- attrTexts.join(" ").length + // --- Attributes total length
46
- (hasChildren ? 1 : (options == null ? void 0 : options.useSpaceBeforeClose) ?? false ? 3 : 2);
47
- if (nodeLength > ((options == null ? void 0 : options.lineLength) ?? 80)) {
48
- attrTexts.forEach((text) => {
49
- elementStr += "\n" + getIndent(depth + 1) + text;
50
- });
51
- if ((options == null ? void 0 : options.breakClosingTag) ?? false) {
52
- elementStr += "\n" + getIndent(depth);
53
- }
54
- } else {
55
- elementStr += " " + attrTexts.join(" ");
56
- }
57
- }
58
- }
59
- if (node.text || hasChildren) {
60
- elementStr += ">";
61
- if (node.text) {
62
- const textContents = node.preserveSpaces ? serializeQuotedText(node.text) : serializeText(node.text);
63
- if ((options == null ? void 0 : options.prettify) && elementStr.length + textContents.length + node.name.length + 3 > ((options == null ? void 0 : options.lineLength) ?? 80)) {
64
- elementStr += "\n" + getIndent(depth + 1) + textContents + "\n";
65
- } else {
66
- elementStr += textContents;
67
- }
68
- }
69
- if (hasChildren) {
70
- const childrenTexts = node.childNodes.map((c2) => serializeNode(c2, depth + 1));
71
- if (!(options == null ? void 0 : options.prettify)) {
72
- elementStr += childrenTexts.join("");
73
- } else {
74
- childrenTexts.forEach((text) => {
75
- elementStr += "\n" + text;
76
- });
77
- elementStr += "\n";
78
- }
79
- }
80
- elementStr += `${getIndent(depth)}</${node.name}>`;
81
- } else {
82
- elementStr += ((options == null ? void 0 : options.useSpaceBeforeClose) ?? false ? " " : "") + "/>";
83
- }
84
- } else {
85
- elementStr += ((options == null ? void 0 : options.useSpaceBeforeClose) ?? false ? " " : "") + "/>";
86
- if (node.text === "") {
87
- elementStr += `""</${nodeName()}>`;
88
- }
89
- }
90
- return elementStr;
91
- function nodeName() {
92
- return node.namespace ? `${node.namespace}:${node.name}` : node.name;
93
- }
94
- }
95
- function serializeXmlAttribute(node) {
96
- if (node.value === void 0 || node.value === null) {
97
- return `${nodeName()}`;
98
- }
99
- if (node.preserveSpaces) {
100
- return `${nodeName()}=${serializeQuotedText(node.value)}`;
101
- }
102
- const value = node.value ?? "";
103
- return `${nodeName()}=${serializeQuotedText(value)}`;
104
- function nodeName() {
105
- return node.namespace ? `${node.namespace}:${node.name}` : node.name;
106
- }
107
- }
108
- function serializeText(text) {
109
- return (options == null ? void 0 : options.useQuotes) || attrBreakRegex.test(text) ? serializeQuotedText(text) : text;
110
- }
111
- function serializeQuotedText(text) {
112
- const containsQuote = text.indexOf("'") >= 0;
113
- const containsDQuote = text.indexOf('"') >= 0;
114
- if (!containsQuote && !containsDQuote || containsQuote && !containsDQuote) {
115
- return `"${text.replaceAll("`", "\\`")}"`;
116
- }
117
- if (containsDQuote && !containsQuote) {
118
- return `'${text.replaceAll("`", "\\`")}'`;
119
- }
120
- return `\`${text.replaceAll("`", "\\`")}\``;
121
- }
122
- }
123
- /**
124
- * Transform the specified component definition into an XMLUI node
125
- * @param def Component definitions
126
- * @param options Transformation options
127
- */
128
- transformComponentDefinition(def, options) {
129
- return def.type ? this.transformSimpleComponentDefinition(def, options) : this.transformCompoundComponentDefinition(def, options);
130
- }
131
- /**
132
- * Transform the specified object into an XMLUI nodes
133
- * @param def Object definition
134
- * @param options Transformation options
135
- */
136
- transformObject(def, options) {
137
- const transformed = this.transformValue("Object", "", def, options);
138
- if (!transformed) {
139
- return null;
140
- }
141
- return transformed.childNodes ?? [];
142
- }
143
- /**
144
- * Transforms the specified simple component definition into an XMLUI node
145
- * @param def Component definition
146
- * @param options Transformation options
147
- */
148
- transformSimpleComponentDefinition(def, options) {
149
- const componentNode = {
150
- type: "XmlUiElement",
151
- name: def.type
152
- };
153
- if (def.uid !== void 0) {
154
- this.addProperty(componentNode, "id", def.uid, options);
155
- }
156
- if (def.testId !== void 0) {
157
- this.addProperty(componentNode, "testId", def.testId, options);
158
- }
159
- if (def.when !== void 0) {
160
- this.addProperty(componentNode, "when", def.when, options);
161
- }
162
- if (def.vars) {
163
- Object.keys(def.vars).forEach((key) => {
164
- const varElement = this.transformValue("var", key, def.vars[key], options);
165
- if (varElement === null) return;
166
- componentNode.childNodes ?? (componentNode.childNodes = []);
167
- componentNode.childNodes.push(varElement);
168
- });
169
- }
170
- if (def.props) {
171
- Object.keys(def.props).forEach((key) => {
172
- const propValue = def.props[key];
173
- if (key.endsWith("Template") && propValue.type) {
174
- componentNode.childNodes ?? (componentNode.childNodes = []);
175
- const propWrapper = {
176
- type: "XmlUiElement",
177
- name: "property",
178
- attributes: [
179
- {
180
- type: "XmlUiAttribute",
181
- name: "name",
182
- value: key
183
- }
184
- ]
185
- };
186
- this.addComponentElement(propWrapper, propValue);
187
- componentNode.childNodes.push(propWrapper);
188
- } else {
189
- if (propValue === void 0) {
190
- return;
191
- }
192
- if (propValue === null) {
193
- const nullPropElement = {
194
- type: "XmlUiElement",
195
- name: "property",
196
- attributes: [
197
- {
198
- type: "XmlUiAttribute",
199
- name: "name",
200
- value: key
201
- }
202
- ]
203
- };
204
- componentNode.childNodes ?? (componentNode.childNodes = []);
205
- componentNode.childNodes.push(nullPropElement);
206
- return;
207
- }
208
- if (key === "id" || key === "when" || key === "testId" || (options == null ? void 0 : options.extractProps)) {
209
- const idPropElement = {
210
- type: "XmlUiElement",
211
- name: "property"
212
- };
213
- this.addProperty(idPropElement, key, propValue, options);
214
- componentNode.childNodes ?? (componentNode.childNodes = []);
215
- componentNode.childNodes.push(idPropElement);
216
- return;
217
- }
218
- this.addProperty(componentNode, key, propValue, options);
219
- }
220
- });
221
- }
222
- if (def.events) {
223
- Object.keys(def.events).forEach((key) => {
224
- const eventElement = this.transformValue("event", key, def.events[key], options);
225
- if (eventElement === null) return;
226
- componentNode.childNodes ?? (componentNode.childNodes = []);
227
- componentNode.childNodes.push(eventElement);
228
- });
229
- }
230
- if (def.loaders) {
231
- this.addComponentList(componentNode, "loaders", def.loaders);
232
- }
233
- if (def.api) {
234
- Object.keys(def.api).forEach((key) => {
235
- const apiElement = this.transformValue("api", key, def.api[key], options);
236
- if (apiElement === null) return;
237
- componentNode.childNodes ?? (componentNode.childNodes = []);
238
- componentNode.childNodes.push(apiElement);
239
- });
240
- }
241
- if (def.uses) {
242
- this.addList(componentNode, "uses", "", def.uses, options);
243
- }
244
- if (def.children) {
245
- if (typeof def.children === "string") {
246
- this.addProperty(componentNode, "children", def.children, options);
247
- } else {
248
- def.children.forEach((ch) => {
249
- this.addComponentElement(componentNode, ch);
250
- });
251
- }
252
- }
253
- return componentNode;
254
- }
255
- /**
256
- * Transforms the specified simple component definition into an Xml node
257
- * @param def Compound component definition
258
- * @param options Transformation options
259
- */
260
- transformCompoundComponentDefinition(def, options) {
261
- if (typeof def === "string") {
262
- return {
263
- type: "XmlUiElement",
264
- name: def
265
- };
266
- }
267
- const nested = this.transformSimpleComponentDefinition(
268
- def.component,
269
- options
270
- );
271
- const componentNode = {
272
- type: "XmlUiElement",
273
- name: COMPOUND_COMP_ID,
274
- attributes: [
275
- {
276
- type: "XmlUiAttribute",
277
- name: "name",
278
- value: def.name
279
- }
280
- ],
281
- childNodes: Array.isArray(nested) ? [...nested] : [nested]
282
- };
283
- if (def.api) {
284
- Object.keys(def.api).forEach((key) => {
285
- const apiElement = this.transformValue("api", key, def.api[key], options);
286
- if (apiElement === null) return;
287
- componentNode.childNodes ?? (componentNode.childNodes = []);
288
- componentNode.childNodes.push(apiElement);
289
- });
290
- }
291
- return componentNode;
292
- }
293
- /**
294
- * Transforms a value into an XMLUI element
295
- * @param nodeName Name of the value node
296
- * @param name Optional (property) name
297
- * @param value Value to transform
298
- * @param options Transformation options
299
- */
300
- transformValue(nodeName, name, value, options) {
301
- if (value === void 0) return null;
302
- const valueNode = {
303
- type: "XmlUiElement",
304
- name: nodeName
305
- };
306
- if (name) {
307
- valueNode.attributes = [
308
- {
309
- type: "XmlUiAttribute",
310
- name: "name",
311
- value: name
312
- }
313
- ];
314
- }
315
- if (value === null) {
316
- return valueNode;
317
- }
318
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
319
- const strValue = typeof value === "string" ? value.toString() : `{${value.toString()}}`;
320
- const preserveSpaces = attrBreakRegex.test(strValue) || strValue.trim().length != strValue.length;
321
- if (options == null ? void 0 : options.preferTextToValue) {
322
- valueNode.text = strValue;
323
- valueNode.preserveSpaces = preserveSpaces;
324
- } else {
325
- valueNode.attributes ?? (valueNode.attributes = []);
326
- valueNode.attributes.push({
327
- type: "XmlUiAttribute",
328
- name: "value",
329
- value: strValue,
330
- preserveSpaces
331
- });
332
- }
333
- return valueNode;
334
- }
335
- if (Array.isArray(value)) {
336
- if (value.length === 0) {
337
- valueNode.attributes ?? (valueNode.attributes = []);
338
- valueNode.attributes.push({
339
- type: "XmlUiAttribute",
340
- name: "value",
341
- value: "{[]}"
342
- });
343
- } else {
344
- value.forEach((item) => {
345
- const itemElement = this.transformValue("item", void 0, item, options);
346
- if (!itemElement) return;
347
- valueNode.childNodes ?? (valueNode.childNodes = []);
348
- valueNode.childNodes.push(itemElement);
349
- });
350
- }
351
- } else if (typeof value === "object") {
352
- const keys = Object.keys(value);
353
- if (keys.length === 0) {
354
- valueNode.attributes ?? (valueNode.attributes = []);
355
- valueNode.attributes.push({
356
- type: "XmlUiAttribute",
357
- name: "value",
358
- value: "{{}}"
359
- });
360
- } else {
361
- keys.forEach((key) => {
362
- const fieldElement = this.transformValue("field", key, value[key], options);
363
- if (!fieldElement) return;
364
- valueNode.childNodes ?? (valueNode.childNodes = []);
365
- valueNode.childNodes.push(fieldElement);
366
- });
367
- }
368
- } else {
369
- throw new Error(`Cannot serialize '${typeof value}' value`);
370
- }
371
- return valueNode;
372
- }
373
- /**
374
- * Transforms the specified simple component definition into an Xml node
375
- * @param name Element name
376
- * @param value Value to transform
377
- * @param options Transformation options
378
- */
379
- transformObjectValue(name, value, options) {
380
- const componentNode = {
381
- type: "XmlUiElement",
382
- name
383
- };
384
- if (value) {
385
- Object.keys(value).forEach(
386
- (key) => this.addProperty(componentNode, key, value[key], options)
387
- );
388
- }
389
- return componentNode;
390
- }
391
- /**
392
- * Add a property to the specified XMLUI element
393
- * @param element XML element
394
- * @param name Element name
395
- * @param value Element value
396
- * @param options Transformation options
397
- */
398
- addProperty(element, name, value, options) {
399
- switch (typeof value) {
400
- case "undefined":
401
- break;
402
- case "string":
403
- element.attributes ?? (element.attributes = []);
404
- element.attributes.push({
405
- type: "XmlUiAttribute",
406
- name,
407
- value: value == null ? void 0 : value.toString(),
408
- preserveQuotes: (options == null ? void 0 : options.removeQuotes) ?? false,
409
- preserveSpaces: attrBreakRegex.test(value.toString())
410
- });
411
- break;
412
- case "boolean":
413
- case "number":
414
- case "object":
415
- const objElement = this.transformValue("property", name, value, options);
416
- if (objElement) {
417
- element.childNodes ?? (element.childNodes = []);
418
- element.childNodes.push(objElement);
419
- }
420
- break;
421
- default:
422
- throw new Error(`'${typeof value}' transformation is not implemented yet`);
423
- }
424
- }
425
- addComponentElement(element, component) {
426
- element.childNodes ?? (element.childNodes = []);
427
- const childDef = this.transformComponentDefinition(component);
428
- if (Array.isArray(childDef)) {
429
- element.childNodes.push(...childDef);
430
- } else {
431
- element.childNodes.push(childDef);
432
- }
433
- }
434
- /**
435
- * Adds a list to the specified XML element
436
- * @param element XML element
437
- * @param name Name of the list (child in `element`)
438
- * @param prefix Prefix to use for the list
439
- * @param list List with items
440
- * @param options Transformation options
441
- */
442
- addList(element, name, prefix, list, options) {
443
- const nodeName = `${prefix ? prefix + "." : ""}${name}`;
444
- element.childNodes ?? (element.childNodes = []);
445
- list.forEach((item) => {
446
- if (typeof item === "string") {
447
- element.childNodes.push({
448
- type: "XmlUiElement",
449
- name: nodeName,
450
- text: item,
451
- preserveSpaces: attrBreakRegex.test(item) || item !== item.trim() || item === ""
452
- });
453
- } else if (item === null) {
454
- element.childNodes.push({
455
- type: "XmlUiElement",
456
- name: nodeName
457
- });
458
- } else {
459
- const transformed = this.transformObjectValue(nodeName, item, options);
460
- if (Array.isArray(transformed)) {
461
- element.childNodes.push(...transformed);
462
- } else {
463
- element.childNodes.push(transformed);
464
- }
465
- }
466
- });
467
- }
468
- /**
469
- * Adds a component list to the specified element
470
- * @param element XML element
471
- * @param name Name to use for the wrapper element
472
- * @param list List with component items
473
- * @private
474
- */
475
- addComponentList(element, name, list) {
476
- const children = [];
477
- list.forEach((item) => {
478
- const fragment = this.transformSimpleComponentDefinition(item);
479
- if (Array.isArray(fragment)) {
480
- children.push(...fragment);
481
- } else {
482
- children.push(fragment);
483
- }
484
- });
485
- const listElement = {
486
- type: "XmlUiElement",
487
- name,
488
- childNodes: children
489
- };
490
- element.childNodes ?? (element.childNodes = []);
491
- element.childNodes.push(listElement);
492
- }
493
- }
1
+ import { w, y, C, n, j, h, m, g, k, a, l, i, e, c, f, b, D, E, P, S, U, r, o, d, q, G, v, s, u, t, z, x, p, A, F, B } from "./transform-B-MhfH46.mjs";
2
+ import { b as b2, L, X, a as a2, c as c2, g as g2, e as e2, l as l2, d as d2, m as m2, p as p2 } from "./lint-B5OU130e.mjs";
494
3
  export {
495
- COMPOUND_COMP_ID,
496
- al as CORE_NAMESPACE_VALUE,
497
- Y as CharacterCodes,
498
- aa as Diag_Attr_Identifier_Expected,
499
- a6 as Diag_Attr_Value_Expected,
500
- a4 as Diag_CloseNodeStart_Token_Expected,
501
- a9 as Diag_End_Or_Close_Token_Expected,
502
- a3 as Diag_End_Token_Expected,
503
- a7 as Diag_Eq_Token_Expected,
504
- _ as Diag_Invalid_Character,
505
- a8 as Diag_OpenNodeStart_Token_Expected,
506
- a5 as Diag_Tag_Identifier_Expected,
507
- a1 as Diag_Unterminated_CData,
508
- a0 as Diag_Unterminated_Comment,
509
- a2 as Diag_Unterminated_Script,
510
- $ as Diag_Unterminated_String_Literal,
511
- Q as DiagnosticCategory,
512
- R as ErrCodes,
513
- d as LintDiagKind,
4
+ w as COMPOUND_COMP_ID,
5
+ y as CORE_NAMESPACE_VALUE,
6
+ C as CharacterCodes,
7
+ n as Diag_Attr_Identifier_Expected,
8
+ j as Diag_Attr_Value_Expected,
9
+ h as Diag_CloseNodeStart_Token_Expected,
10
+ m as Diag_End_Or_Close_Token_Expected,
11
+ g as Diag_End_Token_Expected,
12
+ k as Diag_Eq_Token_Expected,
13
+ a as Diag_Invalid_Character,
14
+ l as Diag_OpenNodeStart_Token_Expected,
15
+ i as Diag_Tag_Identifier_Expected,
16
+ e as Diag_Unterminated_CData,
17
+ c as Diag_Unterminated_Comment,
18
+ f as Diag_Unterminated_Script,
19
+ b as Diag_Unterminated_String_Literal,
20
+ D as DiagnosticCategory,
21
+ E as ErrCodes,
22
+ b2 as LintDiagKind,
514
23
  L as LintSeverity,
515
- ac as ParserError,
24
+ P as ParserError,
516
25
  S as SyntaxKind,
517
- aj as UCRegex,
518
- XmlUiHelper,
519
- a as codeBehindFileExtension,
520
- c as componentFileExtension,
521
- ae as createScanner,
522
- N as createXmlUiParser,
523
- Z as diagnosticCategoryName,
524
- ad as errorMessages,
525
- ap as findTokenAtPos,
526
- g as getLintSeverity,
527
- ai as getSyntaxKindStrRepr,
528
- af as isIdentifierStart,
529
- ah as isInnerNode,
530
- ag as isTrivia,
531
- e as lint,
532
- l as lintApp,
533
- b as lintErrorsComponent,
534
- m as moduleFileExtension,
535
- O as nodeToComponentDef,
536
- ak as onPrefixRegex,
537
- ab as parseXmlUiMarkup,
538
- p as printComponentLints,
539
- am as stripOnPrefix,
540
- ao as tagNameNodesWithoutErrorsMatch,
541
- an as toDbgString
26
+ U as UCRegex,
27
+ X as XmlUiHelper,
28
+ a2 as codeBehindFileExtension,
29
+ c2 as componentFileExtension,
30
+ r as createScanner,
31
+ o as createXmlUiParser,
32
+ d as diagnosticCategoryName,
33
+ q as errorMessages,
34
+ G as findTokenAtPos,
35
+ g2 as getLintSeverity,
36
+ v as getSyntaxKindStrRepr,
37
+ s as isIdentifierStart,
38
+ u as isInnerNode,
39
+ t as isTrivia,
40
+ e2 as lint,
41
+ l2 as lintApp,
42
+ d2 as lintErrorsComponent,
43
+ m2 as moduleFileExtension,
44
+ z as nodeToComponentDef,
45
+ x as onPrefixRegex,
46
+ p as parseXmlUiMarkup,
47
+ p2 as printComponentLints,
48
+ A as stripOnPrefix,
49
+ F as tagNameNodesWithoutErrorsMatch,
50
+ B as toDbgString
542
51
  };