@dialecte/core 0.4.15 → 0.4.17

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.
@@ -216,8 +216,142 @@ function d(e, t) {
216
216
  return [...n, ...r];
217
217
  }
218
218
  //#endregion
219
+ //#region src/utils/format-xml.ts
220
+ function f(e, t = {}) {
221
+ let n = t.indent ?? " ", r = t.baseIndent ?? "", i = h(m(e.trim())), a = [];
222
+ for (let e of i) _(e, r, n, a);
223
+ return a.join("\n");
224
+ }
225
+ function p(e, t) {
226
+ let n = t;
227
+ for (; n < e.length && !/[\s/>]/.test(e[n]);) n++;
228
+ return e.slice(t, n);
229
+ }
230
+ function m(e) {
231
+ let t = [], n = 0;
232
+ for (; n < e.length;) {
233
+ if (e[n] === "<") {
234
+ if (e.startsWith("<!--", n)) {
235
+ let r = e.indexOf("-->", n + 4), i = r === -1 ? e.length : r + 3;
236
+ t.push({
237
+ type: "comment",
238
+ raw: e.slice(n, i)
239
+ }), n = i;
240
+ continue;
241
+ }
242
+ if (e[n + 1] === "!" || e[n + 1] === "?") {
243
+ let r = e.indexOf(">", n), i = r === -1 ? e.length : r + 1;
244
+ t.push({
245
+ type: "other",
246
+ raw: e.slice(n, i)
247
+ }), n = i;
248
+ continue;
249
+ }
250
+ let r = n + 1, i;
251
+ for (; r < e.length;) {
252
+ let t = e[r];
253
+ if (i) t === i && (i = void 0);
254
+ else if (t === "\"" || t === "'") i = t;
255
+ else if (t === ">") break;
256
+ r++;
257
+ }
258
+ let a = r < e.length ? r + 1 : e.length, o = e.slice(n, a);
259
+ n = a, o[1] === "/" ? t.push({
260
+ type: "close",
261
+ name: p(o, 2),
262
+ raw: o
263
+ }) : o.endsWith("/>") ? t.push({
264
+ type: "selfclose",
265
+ name: p(o, 1),
266
+ raw: o
267
+ }) : t.push({
268
+ type: "open",
269
+ name: p(o, 1),
270
+ raw: o
271
+ });
272
+ continue;
273
+ }
274
+ let r = e.indexOf("<", n), i = r === -1 ? e.length : r;
275
+ t.push({
276
+ type: "text",
277
+ raw: e.slice(n, i)
278
+ }), n = i;
279
+ }
280
+ return t;
281
+ }
282
+ function h(e) {
283
+ let t = 0, n = () => {
284
+ let r = [];
285
+ for (; t < e.length;) {
286
+ let i = e[t];
287
+ if (i.type === "close") return r;
288
+ if (t++, i.type === "open") {
289
+ let a = {
290
+ kind: "element",
291
+ name: i.name,
292
+ openRaw: i.raw,
293
+ selfClosing: !1,
294
+ children: n()
295
+ };
296
+ e[t]?.type === "close" && t++, r.push(a);
297
+ } else i.type === "selfclose" ? r.push({
298
+ kind: "element",
299
+ name: i.name,
300
+ openRaw: i.raw,
301
+ selfClosing: !0,
302
+ children: []
303
+ }) : r.push({
304
+ kind: i.type,
305
+ raw: i.raw
306
+ });
307
+ }
308
+ return r;
309
+ };
310
+ return n();
311
+ }
312
+ function g(e) {
313
+ return e.kind === "element" ? e.selfClosing ? e.openRaw : `${e.openRaw}${e.children.map(g).join("")}</${e.name}>` : e.raw;
314
+ }
315
+ function _(e, t, n, r) {
316
+ if (e.kind === "text") {
317
+ e.raw.trim() !== "" && r.push(t + e.raw.trim());
318
+ return;
319
+ }
320
+ if (e.kind === "comment" || e.kind === "other") {
321
+ r.push(t + e.raw.trim());
322
+ return;
323
+ }
324
+ if (e.selfClosing) {
325
+ r.push(t + e.openRaw);
326
+ return;
327
+ }
328
+ let i = `</${e.name}>`, a = e.children.some((e) => e.kind !== "text"), o = e.children.some((e) => e.kind === "text" && e.raw.trim() !== "");
329
+ if (!a) {
330
+ let n = e.children.map((e) => e.kind === "text" ? e.raw : "").join("");
331
+ r.push(t + e.openRaw + n + i);
332
+ return;
333
+ }
334
+ if (o) {
335
+ r.push(t + e.openRaw + e.children.map(g).join("") + i);
336
+ return;
337
+ }
338
+ r.push(t + e.openRaw);
339
+ for (let i of e.children) i.kind !== "text" && _(i, t + n, n, r);
340
+ r.push(t + i);
341
+ }
342
+ function v(e, t = {}) {
343
+ let n = t.indent ?? " ";
344
+ return e.replace(/^([ \t]*)(.*?\/\*\s*xml\s*\*\/[ \t]*)`([\s\S]*?)`/gm, (e, t, r, i) => {
345
+ let a = f(i, {
346
+ indent: n,
347
+ baseIndent: t + n
348
+ });
349
+ return a.includes("\n") ? `${t}${r}\`\n${a}\n${t}\`` : `${t}${r}\`${a.trim()}\``;
350
+ });
351
+ }
352
+ //#endregion
219
353
  //#region src/utils/invariant.ts
220
- function f(e, n) {
354
+ function y(e, n) {
221
355
  if (e) return;
222
356
  let { detail: r, key: i = "ASSERTION_FAILED", ref: a } = n;
223
357
  t(i, {
@@ -227,7 +361,7 @@ function f(e, n) {
227
361
  }
228
362
  //#endregion
229
363
  //#region src/utils/order-children.ts
230
- function p(e) {
364
+ function b(e) {
231
365
  let { parentTagName: t, children: n, childrenConfig: r } = e, i = r[t];
232
366
  if (!i || i.length === 0) return n;
233
367
  let a = new Set(i), o = /* @__PURE__ */ new Map();
@@ -246,7 +380,7 @@ function p(e) {
246
380
  }
247
381
  //#endregion
248
382
  //#region src/utils/save-to-disk.ts
249
- async function m(e) {
383
+ async function x(e) {
250
384
  let { data: t, filename: n, pickerType: r } = e;
251
385
  if ("showSaveFilePicker" in window) try {
252
386
  let e = await (await window.showSaveFilePicker({
@@ -264,4 +398,4 @@ async function m(e) {
264
398
  a.href = i, a.download = n, document.body.appendChild(a), a.click(), a.remove(), URL.revokeObjectURL(i);
265
399
  }
266
400
  //#endregion
267
- export { o as a, d as c, l as d, i as f, u as i, s as l, e as m, p as n, r as o, t as p, f as r, a as s, m as t, c as u };
401
+ export { f as a, r as c, s as d, c as f, e as g, t as h, v as i, a as l, i as m, b as n, u as o, l as p, y as r, o as s, x as t, d as u };
package/dist/utils.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as e, c as t, d as n, f as r, i, l as a, n as o, o as s, r as c, s as l, t as u, u as d } from "./utils-C5_11hqg.js";
2
- export { i as compareQualifiedAttributes, e as extractLocalName, s as getAttributeRules, c as invariant, l as isSchemaDefaultValue, t as orderAttributesBySequence, o as orderByConfigSequence, a as resolveNamespaceByPrefix, d as resolveNamespaceByScope, n as resolvePrefixByNamespaceScope, r as resolveSchemaAttributeValue, u as saveToDisk };
1
+ import { a as e, c as t, d as n, f as r, i, l as a, m as o, n as s, o as c, p as l, r as u, s as d, t as f, u as p } from "./utils-BiEx1x59.js";
2
+ export { c as compareQualifiedAttributes, d as extractLocalName, i as formatEmbeddedXml, e as formatXml, t as getAttributeRules, u as invariant, a as isSchemaDefaultValue, p as orderAttributesBySequence, s as orderByConfigSequence, n as resolveNamespaceByPrefix, r as resolveNamespaceByScope, l as resolvePrefixByNamespaceScope, o as resolveSchemaAttributeValue, f as saveToDisk };
package/package.json CHANGED
@@ -1,15 +1,19 @@
1
1
  {
2
2
  "name": "@dialecte/core",
3
- "version": "0.4.15",
3
+ "version": "0.4.17",
4
4
  "description": "Dialecte - Core functionality for Dialecte SDK",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/dialecte/core.git"
9
9
  },
10
+ "bin": {
11
+ "dialecte-xmlfmt": "bin/xmlfmt.mjs"
12
+ },
10
13
  "source": "src/index.ts",
11
14
  "files": [
12
- "dist"
15
+ "dist",
16
+ "bin"
13
17
  ],
14
18
  "type": "module",
15
19
  "exports": {