@formfeed/engine 0.3.11 → 0.3.12
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.
- package/index.cjs +2414 -241
- package/index.js +2414 -241
- package/package.json +3 -2
- package/types/frame/text-edit.d.cts +8 -1
- package/types/frame/text-edit.d.ts +8 -1
- package/types/index.d.cts +3 -1
- package/types/index.d.ts +3 -1
- package/types/lib/assemble.d.cts +8 -0
- package/types/lib/assemble.d.ts +8 -0
- package/types/lib/einvoice/check.d.cts +181 -0
- package/types/lib/einvoice/check.d.ts +181 -0
- package/types/lib/einvoice/cii.d.cts +18 -0
- package/types/lib/einvoice/cii.d.ts +18 -0
- package/types/lib/einvoice/codes.generated.d.cts +14 -0
- package/types/lib/einvoice/codes.generated.d.ts +14 -0
- package/types/lib/einvoice/decimal.d.cts +29 -0
- package/types/lib/einvoice/decimal.d.ts +29 -0
- package/types/lib/einvoice/display.d.cts +43 -0
- package/types/lib/einvoice/display.d.ts +43 -0
- package/types/lib/einvoice/html-text.d.cts +17 -0
- package/types/lib/einvoice/html-text.d.ts +17 -0
- package/types/lib/einvoice/index.d.cts +45 -0
- package/types/lib/einvoice/index.d.ts +45 -0
- package/types/lib/einvoice/locate.d.cts +21 -0
- package/types/lib/einvoice/locate.d.ts +21 -0
- package/types/lib/einvoice/report.d.cts +59 -0
- package/types/lib/einvoice/report.d.ts +59 -0
- package/types/lib/einvoice/schema.d.cts +293 -0
- package/types/lib/einvoice/schema.d.ts +293 -0
- package/types/lib/einvoice/skeleton.d.cts +10 -0
- package/types/lib/einvoice/skeleton.d.ts +10 -0
- package/types/lib/generated/frames.d.cts +2 -2
- package/types/lib/generated/frames.d.ts +2 -2
- package/types/lib/preview.d.cts +6 -0
- package/types/lib/preview.d.ts +6 -0
- package/types/lib/source-edit.d.cts +5 -0
- package/types/lib/source-edit.d.ts +5 -0
package/index.cjs
CHANGED
|
@@ -30,16 +30,28 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// packages/engine/src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
CII_GUIDELINES: () => CII_GUIDELINES,
|
|
34
|
+
CODE_LIST_RELEASE: () => CODE_LIST_RELEASE,
|
|
33
35
|
DEFAULT_CHROME_PADDING: () => DEFAULT_CHROME_PADDING,
|
|
34
36
|
DESIGN_LIMITS: () => DESIGN_LIMITS,
|
|
35
37
|
DESIGN_VERSION: () => DESIGN_VERSION,
|
|
38
|
+
DISPLAY_TERMS: () => DISPLAY_TERMS,
|
|
36
39
|
DefaultHelperRegistry: () => DefaultHelperRegistry,
|
|
40
|
+
EINVOICE_FLAVOURS: () => EINVOICE_FLAVOURS,
|
|
41
|
+
EINVOICE_FLAVOUR_NAMES: () => EINVOICE_FLAVOUR_NAMES,
|
|
42
|
+
EINVOICE_MAX_MESSAGES: () => EINVOICE_MAX_MESSAGES,
|
|
43
|
+
EINVOICE_PROFILES: () => EINVOICE_PROFILES,
|
|
44
|
+
EINVOICE_PROFILE_NAMES: () => EINVOICE_PROFILE_NAMES,
|
|
45
|
+
EINVOICE_SPEC_VERSIONS: () => EINVOICE_SPEC_VERSIONS,
|
|
46
|
+
EINVOICE_XML_NAME: () => EINVOICE_XML_NAME,
|
|
37
47
|
EPC_MAX_BYTES: () => EPC_MAX_BYTES,
|
|
38
48
|
EngineSyntaxError: () => EngineSyntaxError,
|
|
49
|
+
INVOICE_DATA_KEY: () => INVOICE_DATA_KEY,
|
|
39
50
|
OFFICE_FILLED_MAX_BYTES: () => OFFICE_FILLED_MAX_BYTES,
|
|
40
51
|
OfficeTemplateError: () => OfficeTemplateError,
|
|
41
52
|
RenderError: () => RenderError,
|
|
42
53
|
RenderLimitError: () => RenderLimitError,
|
|
54
|
+
VAT_CATEGORIES: () => VAT_CATEGORIES,
|
|
43
55
|
analyzeHandlebars: () => analyzeHandlebars,
|
|
44
56
|
analyzeJinja2: () => analyzeJinja2,
|
|
45
57
|
analyzeLiquid: () => analyzeLiquid,
|
|
@@ -51,13 +63,16 @@ __export(index_exports, {
|
|
|
51
63
|
brandCss: () => brandCss,
|
|
52
64
|
builtinHelpers: () => builtinHelpers,
|
|
53
65
|
canvasDocument: () => canvasDocument,
|
|
66
|
+
capMessages: () => capMessages,
|
|
54
67
|
chartInitScript: () => chartInitScript,
|
|
55
68
|
chartMarkup: () => chartMarkup,
|
|
56
69
|
chartPayload: () => chartPayload,
|
|
70
|
+
checkInvoice: () => checkInvoice,
|
|
57
71
|
chipValues: () => chipValues,
|
|
58
72
|
convertScss: () => convertScss,
|
|
59
73
|
createHelperRegistry: () => createHelperRegistry,
|
|
60
74
|
dataPathPattern: () => dataPathPattern,
|
|
75
|
+
defaultEinvoiceOptions: () => defaultEinvoiceOptions,
|
|
61
76
|
defaultHelpers: () => defaultHelpers,
|
|
62
77
|
defaultLayer: () => defaultLayer,
|
|
63
78
|
defaultLimits: () => defaultLimits,
|
|
@@ -68,9 +83,14 @@ __export(index_exports, {
|
|
|
68
83
|
designOutputHash: () => designOutputHash,
|
|
69
84
|
designStarters: () => designStarters,
|
|
70
85
|
diffSchemas: () => diffSchemas,
|
|
86
|
+
displayCheck: () => displayCheck,
|
|
87
|
+
displayMissingText: () => displayMissingText,
|
|
71
88
|
editAttribute: () => editAttribute,
|
|
72
89
|
editableRegion: () => editableRegion,
|
|
73
90
|
editableRegionAt: () => editableRegionAt,
|
|
91
|
+
einvoiceOptionsSchema: () => einvoiceOptionsSchema,
|
|
92
|
+
einvoiceResult: () => einvoiceResult,
|
|
93
|
+
einvoiceXml: () => einvoiceXml,
|
|
74
94
|
emitDesign: () => emitDesign,
|
|
75
95
|
emptyBrand: () => emptyBrand,
|
|
76
96
|
emptyDesign: () => emptyDesign,
|
|
@@ -90,6 +110,7 @@ __export(index_exports, {
|
|
|
90
110
|
googleFontsUrl: () => googleFontsUrl,
|
|
91
111
|
handlebarsEngine: () => handlebarsEngine,
|
|
92
112
|
helperDocs: () => helperDocs,
|
|
113
|
+
htmlText: () => htmlText,
|
|
93
114
|
ibanChecksum: () => ibanChecksum,
|
|
94
115
|
imageIsEmpty: () => imageIsEmpty,
|
|
95
116
|
imageMarkup: () => imageMarkup,
|
|
@@ -100,6 +121,12 @@ __export(index_exports, {
|
|
|
100
121
|
importPdfmonkey: () => importPdfmonkey,
|
|
101
122
|
inferSchema: () => inferSchema,
|
|
102
123
|
inferSchemaFromDataSets: () => inferSchemaFromDataSets,
|
|
124
|
+
invoiceAmountText: () => invoiceAmountText,
|
|
125
|
+
invoiceLineOf: () => invoiceLineOf,
|
|
126
|
+
invoicePathSegments: () => invoicePathSegments,
|
|
127
|
+
invoiceSchema: () => invoiceSchema,
|
|
128
|
+
invoiceSkeleton: () => invoiceSkeleton,
|
|
129
|
+
invoiceToCii: () => invoiceToCii,
|
|
103
130
|
isApitemplateHtmlTemplate: () => isApitemplateHtmlTemplate,
|
|
104
131
|
isApitemplateRegion: () => isApitemplateRegion,
|
|
105
132
|
isOfficeKind: () => isOfficeKind,
|
|
@@ -113,6 +140,7 @@ __export(index_exports, {
|
|
|
113
140
|
liquidBuiltinFilters: () => liquidBuiltinFilters,
|
|
114
141
|
liquidEngine: () => liquidEngine,
|
|
115
142
|
liquidTags: () => liquidTags,
|
|
143
|
+
locateJsonPath: () => locateJsonPath,
|
|
116
144
|
mergeSampleData: () => mergeSampleData,
|
|
117
145
|
mergeSettings: () => mergeSettings,
|
|
118
146
|
mergeSnippetCss: () => mergeSnippetCss,
|
|
@@ -139,12 +167,15 @@ __export(index_exports, {
|
|
|
139
167
|
readJsreportExport: () => readJsreportExport,
|
|
140
168
|
regionChips: () => regionChips,
|
|
141
169
|
regionItems: () => regionItems,
|
|
170
|
+
regionPosition: () => regionPosition,
|
|
142
171
|
renderOffice: () => renderOffice,
|
|
143
172
|
renderVersion: () => renderVersion,
|
|
173
|
+
resolveEinvoiceOptions: () => resolveEinvoiceOptions,
|
|
144
174
|
resolvePath: () => resolvePath,
|
|
145
175
|
resolveTranslation: () => resolveTranslation,
|
|
146
176
|
scanBlocks: () => scanBlocks,
|
|
147
177
|
schemaPaths: () => schemaPaths,
|
|
178
|
+
shownAmounts: () => shownAmounts,
|
|
148
179
|
slugFromName: () => slugFromName,
|
|
149
180
|
snippetText: () => snippetText,
|
|
150
181
|
snippets: () => snippets,
|
|
@@ -167,10 +198,10 @@ module.exports = __toCommonJS(index_exports);
|
|
|
167
198
|
|
|
168
199
|
// packages/engine/src/lib/errors.ts
|
|
169
200
|
var EngineSyntaxError = class extends Error {
|
|
170
|
-
constructor(engine, message,
|
|
201
|
+
constructor(engine, message, line2, column) {
|
|
171
202
|
super(message);
|
|
172
203
|
this.engine = engine;
|
|
173
|
-
this.line =
|
|
204
|
+
this.line = line2;
|
|
174
205
|
this.column = column;
|
|
175
206
|
}
|
|
176
207
|
name = "EngineSyntaxError";
|
|
@@ -186,10 +217,10 @@ var RenderLimitError = class extends Error {
|
|
|
186
217
|
name = "RenderLimitError";
|
|
187
218
|
};
|
|
188
219
|
var RenderError = class extends Error {
|
|
189
|
-
constructor(engine, message,
|
|
220
|
+
constructor(engine, message, line2, column) {
|
|
190
221
|
super(message);
|
|
191
222
|
this.engine = engine;
|
|
192
|
-
this.line =
|
|
223
|
+
this.line = line2;
|
|
193
224
|
this.column = column;
|
|
194
225
|
}
|
|
195
226
|
name = "RenderError";
|
|
@@ -258,7 +289,7 @@ function toNumber(value) {
|
|
|
258
289
|
|
|
259
290
|
// packages/engine/src/lib/codes/epc.ts
|
|
260
291
|
function epcPayload(input) {
|
|
261
|
-
const
|
|
292
|
+
const amount2 = input.amount === void 0 || input.amount === "" ? "" : `EUR${toNumber(input.amount).toFixed(2)}`;
|
|
262
293
|
return [
|
|
263
294
|
"BCD",
|
|
264
295
|
"002",
|
|
@@ -267,7 +298,7 @@ function epcPayload(input) {
|
|
|
267
298
|
(input.bic ?? "").replace(/\s/g, ""),
|
|
268
299
|
String(input.name ?? "").slice(0, 70),
|
|
269
300
|
String(input.iban ?? "").replace(/\s/g, ""),
|
|
270
|
-
|
|
301
|
+
amount2,
|
|
271
302
|
(input.purpose ?? "").slice(0, 4),
|
|
272
303
|
(input.reference ?? "").slice(0, 35),
|
|
273
304
|
input.reference ? "" : (input.text ?? "").slice(0, 140),
|
|
@@ -317,9 +348,9 @@ var IBAN_LENGTHS = {
|
|
|
317
348
|
};
|
|
318
349
|
var EPC_MAX_BYTES = 331;
|
|
319
350
|
var byteLength = (value) => new TextEncoder().encode(value).length;
|
|
320
|
-
var normaliseIban = (
|
|
321
|
-
function ibanChecksum(
|
|
322
|
-
const rearranged = normaliseIban(
|
|
351
|
+
var normaliseIban = (iban2) => iban2.replace(/\s/g, "").toUpperCase();
|
|
352
|
+
function ibanChecksum(iban2) {
|
|
353
|
+
const rearranged = normaliseIban(iban2).slice(4) + normaliseIban(iban2).slice(0, 4);
|
|
323
354
|
const digits = [...rearranged].map((c) => c >= "A" && c <= "Z" ? String(c.charCodeAt(0) - 55) : c).join("");
|
|
324
355
|
let remainder = 0;
|
|
325
356
|
for (const digit of digits) remainder = (remainder * 10 + Number(digit)) % 97;
|
|
@@ -330,30 +361,30 @@ function validateEpc(input) {
|
|
|
330
361
|
const name = String(input.name ?? "").trim();
|
|
331
362
|
if (!name) problems.push({ field: "name", code: "required" });
|
|
332
363
|
else if (name.length > 70) problems.push({ field: "name", code: "too_long", max: 70, actual: name.length });
|
|
333
|
-
const
|
|
334
|
-
if (!
|
|
335
|
-
else if (!/^[A-Z]{2}[0-9]{2}[A-Z0-9]{11,30}$/.test(
|
|
364
|
+
const iban2 = normaliseIban(String(input.iban ?? ""));
|
|
365
|
+
if (!iban2) problems.push({ field: "iban", code: "required" });
|
|
366
|
+
else if (!/^[A-Z]{2}[0-9]{2}[A-Z0-9]{11,30}$/.test(iban2)) problems.push({ field: "iban", code: "iban_characters" });
|
|
336
367
|
else {
|
|
337
|
-
const expected = IBAN_LENGTHS[
|
|
338
|
-
if (expected !== void 0 &&
|
|
339
|
-
problems.push({ field: "iban", code: "iban_country_length", max: expected, actual:
|
|
340
|
-
else if (!ibanChecksum(
|
|
368
|
+
const expected = IBAN_LENGTHS[iban2.slice(0, 2)];
|
|
369
|
+
if (expected !== void 0 && iban2.length !== expected)
|
|
370
|
+
problems.push({ field: "iban", code: "iban_country_length", max: expected, actual: iban2.length });
|
|
371
|
+
else if (!ibanChecksum(iban2)) problems.push({ field: "iban", code: "iban_checksum" });
|
|
341
372
|
}
|
|
342
373
|
const bic = String(input.bic ?? "").replace(/\s/g, "").toUpperCase();
|
|
343
374
|
if (bic && !/^[A-Z]{6}[A-Z0-9]{2}([A-Z0-9]{3})?$/.test(bic)) problems.push({ field: "bic", code: "bic_format" });
|
|
344
375
|
if (input.amount !== void 0 && input.amount !== "") {
|
|
345
|
-
const
|
|
346
|
-
if (Number.isNaN(
|
|
347
|
-
else if (
|
|
376
|
+
const amount2 = toNumber(input.amount);
|
|
377
|
+
if (Number.isNaN(amount2)) problems.push({ field: "amount", code: "not_a_number" });
|
|
378
|
+
else if (amount2 < 0.01 || amount2 > 99999999999e-2) problems.push({ field: "amount", code: "out_of_range" });
|
|
348
379
|
}
|
|
349
380
|
const purpose = String(input.purpose ?? "");
|
|
350
381
|
if (purpose.length > 4) problems.push({ field: "purpose", code: "too_long", max: 4, actual: purpose.length });
|
|
351
382
|
const reference = String(input.reference ?? "").trim();
|
|
352
|
-
const
|
|
353
|
-
if (reference &&
|
|
383
|
+
const text3 = String(input.text ?? "").trim();
|
|
384
|
+
if (reference && text3) problems.push({ field: "reference", code: "reference_or_text" });
|
|
354
385
|
if (reference.length > 35)
|
|
355
386
|
problems.push({ field: "reference", code: "too_long", max: 35, actual: reference.length });
|
|
356
|
-
if (
|
|
387
|
+
if (text3.length > 140) problems.push({ field: "text", code: "too_long", max: 140, actual: text3.length });
|
|
357
388
|
const bytes = byteLength(epcPayload(input));
|
|
358
389
|
if (bytes > EPC_MAX_BYTES)
|
|
359
390
|
problems.push({ field: "payload", code: "too_long", max: EPC_MAX_BYTES, actual: bytes });
|
|
@@ -391,9 +422,9 @@ var barcodeTypes = {
|
|
|
391
422
|
};
|
|
392
423
|
var ownTextLayout = /* @__PURE__ */ new Set(["ean13", "ean8", "upca"]);
|
|
393
424
|
function codeText(helper, value) {
|
|
394
|
-
const
|
|
395
|
-
if (
|
|
396
|
-
return
|
|
425
|
+
const text3 = value === void 0 || value === null ? "" : String(value);
|
|
426
|
+
if (text3 === "") throw new Error(`${helper}: nothing to encode, the value is empty or missing from the data`);
|
|
427
|
+
return text3;
|
|
397
428
|
}
|
|
398
429
|
var codeHelpers = [
|
|
399
430
|
{
|
|
@@ -431,17 +462,17 @@ var codeHelpers = [
|
|
|
431
462
|
fn: (ctx, value, options) => {
|
|
432
463
|
const o = options ?? {};
|
|
433
464
|
const bcid = barcodeTypes[String(o.type ?? "code128").toLowerCase()] ?? "code128";
|
|
434
|
-
const
|
|
465
|
+
const text3 = codeText("barcode", value);
|
|
435
466
|
const svg = (0, import_bwip_js.toSVG)({
|
|
436
467
|
bcid,
|
|
437
|
-
text:
|
|
468
|
+
text: text3,
|
|
438
469
|
height: o.height ?? 12,
|
|
439
470
|
...o.width === void 0 ? {} : { width: o.width },
|
|
440
471
|
scale: o.scale ?? 2,
|
|
441
472
|
includetext: o.text !== false,
|
|
442
473
|
...ownTextLayout.has(bcid) ? {} : { textxalign: "center" }
|
|
443
474
|
});
|
|
444
|
-
if (ctx.drawing) return ctx.drawing({ kind: "svg", svg, alt: `Barcode ${
|
|
475
|
+
if (ctx.drawing) return ctx.drawing({ kind: "svg", svg, alt: `Barcode ${text3}` });
|
|
445
476
|
return svgDataUri(svg);
|
|
446
477
|
}
|
|
447
478
|
},
|
|
@@ -467,12 +498,12 @@ var codeHelpers = [
|
|
|
467
498
|
...input && typeof input === "object" ? input : typeof input === "string" && input ? { iban: input } : {},
|
|
468
499
|
...options ?? {}
|
|
469
500
|
};
|
|
470
|
-
const
|
|
501
|
+
const payment2 = {};
|
|
471
502
|
const qr = {};
|
|
472
503
|
for (const [key, value] of Object.entries(fields))
|
|
473
|
-
(EPC_FIELDS.has(key) ?
|
|
504
|
+
(EPC_FIELDS.has(key) ? payment2 : qr)[key] = value;
|
|
474
505
|
const o = { ecc: "M", ...qr };
|
|
475
|
-
const svg = qrSvg(epcPayload(
|
|
506
|
+
const svg = qrSvg(epcPayload(payment2), o);
|
|
476
507
|
if (ctx.drawing) return ctx.drawing({ kind: "svg", svg, width: o.size, height: o.size, alt: "GiroCode" });
|
|
477
508
|
return svgDataUri(svg);
|
|
478
509
|
}
|
|
@@ -496,8 +527,8 @@ var import_nl = require("n2words/nl");
|
|
|
496
527
|
function resolveTranslation(dictionaries, locale, key) {
|
|
497
528
|
const lang = locale.split("-")[0] ?? locale;
|
|
498
529
|
for (const candidate of [locale, lang, "en"]) {
|
|
499
|
-
const
|
|
500
|
-
if (typeof
|
|
530
|
+
const text3 = dictionaries?.[candidate]?.[key];
|
|
531
|
+
if (typeof text3 === "string") return { text: text3, from: candidate };
|
|
501
532
|
}
|
|
502
533
|
return { text: key, from: null };
|
|
503
534
|
}
|
|
@@ -645,10 +676,10 @@ var formatHelpers = [
|
|
|
645
676
|
},
|
|
646
677
|
category: "format"
|
|
647
678
|
},
|
|
648
|
-
fn: (ctx, value,
|
|
679
|
+
fn: (ctx, value, amount2, unit) => {
|
|
649
680
|
const d = toDate(value, ctx.timezone);
|
|
650
681
|
if (!d) return str(value);
|
|
651
|
-
const n = toNumber(
|
|
682
|
+
const n = toNumber(amount2);
|
|
652
683
|
const u = str(unit || "days").replace(/s?$/, "s");
|
|
653
684
|
return (0, import_date_fns.add)(d, { [u]: n }).toISOString();
|
|
654
685
|
}
|
|
@@ -977,9 +1008,9 @@ var formatHelpers = [
|
|
|
977
1008
|
category: "text"
|
|
978
1009
|
},
|
|
979
1010
|
fn: (ctx, key, params) => {
|
|
980
|
-
const { text:
|
|
1011
|
+
const { text: text3 } = resolveTranslation(ctx.i18n, ctx.locale, str(key));
|
|
981
1012
|
const p = params ?? {};
|
|
982
|
-
return
|
|
1013
|
+
return text3.replace(/\{(\w+)\}/g, (_, name) => str(p[name]));
|
|
983
1014
|
}
|
|
984
1015
|
},
|
|
985
1016
|
{
|
|
@@ -1510,22 +1541,22 @@ function unavailableHelper(name) {
|
|
|
1510
1541
|
}
|
|
1511
1542
|
|
|
1512
1543
|
// packages/engine/src/lib/analysis/tags.ts
|
|
1513
|
-
function rangeAt(
|
|
1544
|
+
function rangeAt(line2, column, length) {
|
|
1514
1545
|
return {
|
|
1515
|
-
start: { line, column },
|
|
1516
|
-
end: { line, column: column + Math.max(1, length) }
|
|
1546
|
+
start: { line: line2, column },
|
|
1547
|
+
end: { line: line2, column: column + Math.max(1, length) }
|
|
1517
1548
|
};
|
|
1518
1549
|
}
|
|
1519
1550
|
function positionOf(source, offset) {
|
|
1520
|
-
let
|
|
1551
|
+
let line2 = 1;
|
|
1521
1552
|
let last = -1;
|
|
1522
1553
|
for (let i = 0; i < offset && i < source.length; i++) {
|
|
1523
1554
|
if (source.charCodeAt(i) === 10) {
|
|
1524
|
-
|
|
1555
|
+
line2++;
|
|
1525
1556
|
last = i;
|
|
1526
1557
|
}
|
|
1527
1558
|
}
|
|
1528
|
-
return { line, column: offset - last };
|
|
1559
|
+
return { line: line2, column: offset - last };
|
|
1529
1560
|
}
|
|
1530
1561
|
function rangeOf(source, start, end) {
|
|
1531
1562
|
return { start: positionOf(source, start), end: positionOf(source, end) };
|
|
@@ -1771,12 +1802,12 @@ function toSyntaxError(e) {
|
|
|
1771
1802
|
const err2 = e;
|
|
1772
1803
|
const message = String(err2.message ?? e);
|
|
1773
1804
|
const m = /Parse error on line (\d+)/.exec(message);
|
|
1774
|
-
const
|
|
1805
|
+
const line2 = err2.lineNumber ?? (m ? Number(m[1]) : 1);
|
|
1775
1806
|
const column = typeof err2.column === "number" ? err2.column + 1 : 1;
|
|
1776
1807
|
return new EngineSyntaxError(
|
|
1777
1808
|
"handlebars",
|
|
1778
1809
|
message.split("\n")[0] ?? message,
|
|
1779
|
-
|
|
1810
|
+
line2,
|
|
1780
1811
|
column
|
|
1781
1812
|
);
|
|
1782
1813
|
}
|
|
@@ -2086,48 +2117,48 @@ var SPEC = /^(?:([\s\S])?([<>=^]))?([+\- ])?(#)?(0)?(\d+)?([,_])?(?:\.(\d+))?([b
|
|
|
2086
2117
|
function group(digits, separator) {
|
|
2087
2118
|
return digits.replace(/\B(?=(\d{3})+(?!\d))/g, separator);
|
|
2088
2119
|
}
|
|
2089
|
-
function pythonExponent(
|
|
2090
|
-
return
|
|
2120
|
+
function pythonExponent(text3) {
|
|
2121
|
+
return text3.replace(/e([+-])(\d)$/i, (m, sign, digit) => `${m[0]}${sign}0${digit}`);
|
|
2091
2122
|
}
|
|
2092
2123
|
function formatNumber(value, type, precision, alternate) {
|
|
2093
2124
|
if (!Number.isFinite(value)) return Number.isNaN(value) ? "nan" : "inf";
|
|
2094
|
-
const
|
|
2125
|
+
const abs2 = Math.abs(value);
|
|
2095
2126
|
switch (type) {
|
|
2096
2127
|
case "f":
|
|
2097
2128
|
case "F":
|
|
2098
|
-
return
|
|
2129
|
+
return abs2.toFixed(precision ?? 6);
|
|
2099
2130
|
case "%":
|
|
2100
|
-
return `${(
|
|
2131
|
+
return `${(abs2 * 100).toFixed(precision ?? 6)}%`;
|
|
2101
2132
|
case "e":
|
|
2102
2133
|
case "E": {
|
|
2103
|
-
const
|
|
2104
|
-
return type === "E" ?
|
|
2134
|
+
const text3 = pythonExponent(abs2.toExponential(precision ?? 6));
|
|
2135
|
+
return type === "E" ? text3.toUpperCase() : text3;
|
|
2105
2136
|
}
|
|
2106
2137
|
case "g":
|
|
2107
2138
|
case "G": {
|
|
2108
2139
|
const p = precision === 0 ? 1 : precision ?? 6;
|
|
2109
|
-
const exp =
|
|
2110
|
-
let
|
|
2140
|
+
const exp = abs2 === 0 ? 0 : Math.floor(Math.log10(abs2));
|
|
2141
|
+
let text3 = exp < -4 || exp >= p ? pythonExponent(abs2.toExponential(p - 1)) : abs2.toFixed(Math.max(0, p - 1 - exp));
|
|
2111
2142
|
if (!alternate) {
|
|
2112
|
-
const [mantissa = "", exponent] =
|
|
2143
|
+
const [mantissa = "", exponent] = text3.split("e");
|
|
2113
2144
|
const trimmed = mantissa.includes(".") ? mantissa.replace(/0+$/, "").replace(/\.$/, "") : mantissa;
|
|
2114
|
-
|
|
2145
|
+
text3 = exponent === void 0 ? trimmed : `${trimmed}e${exponent}`;
|
|
2115
2146
|
}
|
|
2116
|
-
return type === "G" ?
|
|
2147
|
+
return type === "G" ? text3.toUpperCase() : text3;
|
|
2117
2148
|
}
|
|
2118
2149
|
case "d":
|
|
2119
2150
|
case "n":
|
|
2120
|
-
return String(Math.trunc(
|
|
2151
|
+
return String(Math.trunc(abs2));
|
|
2121
2152
|
case "b":
|
|
2122
|
-
return (alternate ? "0b" : "") + Math.trunc(
|
|
2153
|
+
return (alternate ? "0b" : "") + Math.trunc(abs2).toString(2);
|
|
2123
2154
|
case "o":
|
|
2124
|
-
return (alternate ? "0o" : "") + Math.trunc(
|
|
2155
|
+
return (alternate ? "0o" : "") + Math.trunc(abs2).toString(8);
|
|
2125
2156
|
case "x":
|
|
2126
|
-
return (alternate ? "0x" : "") + Math.trunc(
|
|
2157
|
+
return (alternate ? "0x" : "") + Math.trunc(abs2).toString(16);
|
|
2127
2158
|
case "X":
|
|
2128
|
-
return (alternate ? "0X" : "") + Math.trunc(
|
|
2159
|
+
return (alternate ? "0X" : "") + Math.trunc(abs2).toString(16).toUpperCase();
|
|
2129
2160
|
default:
|
|
2130
|
-
return precision === void 0 ? String(
|
|
2161
|
+
return precision === void 0 ? String(abs2) : formatNumber(abs2, "g", precision, alternate);
|
|
2131
2162
|
}
|
|
2132
2163
|
}
|
|
2133
2164
|
function formatValue(value, spec) {
|
|
@@ -2182,35 +2213,35 @@ function lookupField(name, positional, named, next) {
|
|
|
2182
2213
|
function pythonFormat(template, positional, named = {}) {
|
|
2183
2214
|
let auto = 0;
|
|
2184
2215
|
const next = () => auto++;
|
|
2185
|
-
const render = (
|
|
2216
|
+
const render = (text3) => {
|
|
2186
2217
|
let out = "";
|
|
2187
|
-
for (let i = 0; i <
|
|
2188
|
-
const ch =
|
|
2218
|
+
for (let i = 0; i < text3.length; i++) {
|
|
2219
|
+
const ch = text3[i];
|
|
2189
2220
|
if (ch === "}") {
|
|
2190
2221
|
out += "}";
|
|
2191
|
-
if (
|
|
2222
|
+
if (text3[i + 1] === "}") i++;
|
|
2192
2223
|
continue;
|
|
2193
2224
|
}
|
|
2194
2225
|
if (ch !== "{") {
|
|
2195
2226
|
out += ch;
|
|
2196
2227
|
continue;
|
|
2197
2228
|
}
|
|
2198
|
-
if (
|
|
2229
|
+
if (text3[i + 1] === "{") {
|
|
2199
2230
|
out += "{";
|
|
2200
2231
|
i++;
|
|
2201
2232
|
continue;
|
|
2202
2233
|
}
|
|
2203
2234
|
let depth = 1;
|
|
2204
2235
|
let j = i + 1;
|
|
2205
|
-
for (; j <
|
|
2206
|
-
if (
|
|
2207
|
-
else if (
|
|
2236
|
+
for (; j < text3.length && depth > 0; j++) {
|
|
2237
|
+
if (text3[j] === "{") depth++;
|
|
2238
|
+
else if (text3[j] === "}") depth--;
|
|
2208
2239
|
}
|
|
2209
2240
|
if (depth > 0) {
|
|
2210
|
-
out +=
|
|
2241
|
+
out += text3.slice(i);
|
|
2211
2242
|
break;
|
|
2212
2243
|
}
|
|
2213
|
-
const field =
|
|
2244
|
+
const field = text3.slice(i + 1, j - 1);
|
|
2214
2245
|
const colon = field.indexOf(":");
|
|
2215
2246
|
const head = colon < 0 ? field : field.slice(0, colon);
|
|
2216
2247
|
const name = head.replace(/![rsa]$/, "");
|
|
@@ -2314,7 +2345,7 @@ var stringMethods = {
|
|
|
2314
2345
|
return out;
|
|
2315
2346
|
},
|
|
2316
2347
|
split: (s, sep, max2) => sep === void 0 || sep === null ? s.trim().split(/\s+/) : s.split(String(sep), max2 === void 0 ? void 0 : Number(max2) + 1),
|
|
2317
|
-
join: (s,
|
|
2348
|
+
join: (s, list3) => Array.isArray(list3) ? list3.join(s) : String(list3),
|
|
2318
2349
|
format: (s, ...args) => {
|
|
2319
2350
|
const named = keywordArgs(args);
|
|
2320
2351
|
return pythonFormat(s, named ? args.slice(0, -1) : args, named ?? {});
|
|
@@ -2548,9 +2579,9 @@ function toSyntaxError2(e, fallbackLine = 1) {
|
|
|
2548
2579
|
const fromMessage = /\[Line (\d+), Column (\d+)\]/.exec(
|
|
2549
2580
|
String(err2.message ?? "")
|
|
2550
2581
|
);
|
|
2551
|
-
const
|
|
2582
|
+
const line2 = typeof err2.lineno === "number" ? err2.lineno + 1 : fromMessage ? Number(fromMessage[1]) : fallbackLine;
|
|
2552
2583
|
const column = typeof err2.colno === "number" ? err2.colno + 1 : fromMessage ? Number(fromMessage[2]) : 1;
|
|
2553
|
-
return new EngineSyntaxError("jinja2", message,
|
|
2584
|
+
return new EngineSyntaxError("jinja2", message, line2, column);
|
|
2554
2585
|
}
|
|
2555
2586
|
function nodeRange(node, length = 1) {
|
|
2556
2587
|
return rangeAt(node.lineno + 1, node.colno + 1, length);
|
|
@@ -3045,12 +3076,12 @@ var validationContext3 = {
|
|
|
3045
3076
|
};
|
|
3046
3077
|
function toSyntaxError3(e) {
|
|
3047
3078
|
const err2 = e;
|
|
3048
|
-
let
|
|
3079
|
+
let line2 = err2.line ?? 1;
|
|
3049
3080
|
let column = err2.col ?? 1;
|
|
3050
3081
|
const pos = err2.token?.getPosition?.();
|
|
3051
|
-
if (pos) [
|
|
3082
|
+
if (pos) [line2, column] = pos;
|
|
3052
3083
|
const message = String(err2.message ?? e).replace(/,\s*line:\d+,\s*col:\d+/, "").trim();
|
|
3053
|
-
return new EngineSyntaxError("liquid", message,
|
|
3084
|
+
return new EngineSyntaxError("liquid", message, line2, column);
|
|
3054
3085
|
}
|
|
3055
3086
|
var identifier = /(?<![\w."'])([A-Za-z_][\w]*)((?:\.[A-Za-z_]\w*|\[\d+\])*)/g;
|
|
3056
3087
|
function pathsIn(expression, base, source, out, scopes) {
|
|
@@ -3561,8 +3592,8 @@ function unionTypes(a, b) {
|
|
|
3561
3592
|
...Array.isArray(b) ? b : b ? [b] : []
|
|
3562
3593
|
]);
|
|
3563
3594
|
if (set.has("number")) set.delete("integer");
|
|
3564
|
-
const
|
|
3565
|
-
return
|
|
3595
|
+
const list3 = [...set];
|
|
3596
|
+
return list3.length === 1 ? list3[0] : list3;
|
|
3566
3597
|
}
|
|
3567
3598
|
function merge(a, b) {
|
|
3568
3599
|
if (!a) return b;
|
|
@@ -3733,9 +3764,9 @@ function layeredPartials(own, shared2, onShared) {
|
|
|
3733
3764
|
}
|
|
3734
3765
|
|
|
3735
3766
|
// packages/engine/src/lib/dialect.ts
|
|
3736
|
-
var loop = (engine, item,
|
|
3767
|
+
var loop = (engine, item, list3, body) => engine === "handlebars" ? `{{#each ${list3}}}
|
|
3737
3768
|
${body.replace(new RegExp(`(?<![\\w.])${item}\\.`, "g"), "")}
|
|
3738
|
-
{{/each}}` : `{% for ${item} in ${
|
|
3769
|
+
{{/each}}` : `{% for ${item} in ${list3} %}
|
|
3739
3770
|
${body}
|
|
3740
3771
|
{% endfor %}`;
|
|
3741
3772
|
var val = (engine, expr, filter) => {
|
|
@@ -4304,12 +4335,12 @@ var stripComments = (css2) => css2.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
|
4304
4335
|
var selectorKey = (prelude) => (prelude.split(";").pop() ?? "").trim().replace(/\s*,\s*/g, ", ").replace(/\s+/g, " ");
|
|
4305
4336
|
function mergeSnippetCss(css2, snippetCss) {
|
|
4306
4337
|
if (!snippetCss?.trim()) return css2;
|
|
4307
|
-
const
|
|
4338
|
+
const defined2 = new Set(
|
|
4308
4339
|
[...stripComments(css2).matchAll(/([^{}]+)\{/g)].map(
|
|
4309
4340
|
(m) => selectorKey(m[1] ?? "")
|
|
4310
4341
|
)
|
|
4311
4342
|
);
|
|
4312
|
-
const missing = [...stripComments(snippetCss).matchAll(/([^{}]+)\{[^{}]*\}/g)].filter((m) => !
|
|
4343
|
+
const missing = [...stripComments(snippetCss).matchAll(/([^{}]+)\{[^{}]*\}/g)].filter((m) => !defined2.has(selectorKey(m[1] ?? ""))).map((m) => m[0].trim());
|
|
4313
4344
|
if (!missing.length) return css2;
|
|
4314
4345
|
const base = css2.trimEnd();
|
|
4315
4346
|
return `${base}${base ? "\n\n" : ""}${missing.join("\n")}
|
|
@@ -4355,9 +4386,9 @@ function pick(input, ...keys) {
|
|
|
4355
4386
|
function toLength(value) {
|
|
4356
4387
|
if (value === void 0 || value === null || value === "") return void 0;
|
|
4357
4388
|
if (typeof value === "number") return `${value}mm`;
|
|
4358
|
-
const
|
|
4359
|
-
if (/^-?\d+(\.\d+)?$/.test(
|
|
4360
|
-
if (/^-?\d+(\.\d+)?(mm|cm|in|px|pt)$/i.test(
|
|
4389
|
+
const text3 = String(value).trim();
|
|
4390
|
+
if (/^-?\d+(\.\d+)?$/.test(text3)) return `${text3}mm`;
|
|
4391
|
+
if (/^-?\d+(\.\d+)?(mm|cm|in|px|pt)$/i.test(text3)) return text3.toLowerCase();
|
|
4361
4392
|
return void 0;
|
|
4362
4393
|
}
|
|
4363
4394
|
function toMarginLength(value) {
|
|
@@ -4377,7 +4408,7 @@ function convertHeaderFooter(html) {
|
|
|
4377
4408
|
if (typeof html !== "string" || !html.trim()) return void 0;
|
|
4378
4409
|
return chromePlaceholders.reduce((out, [pattern, span]) => out.replace(pattern, span), html);
|
|
4379
4410
|
}
|
|
4380
|
-
var escapeText = (
|
|
4411
|
+
var escapeText = (text3) => text3.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
4381
4412
|
var visibleMarkup = (html) => html.replace(/<style[\s\S]*?<\/style>/gi, "").trim();
|
|
4382
4413
|
function apitemplateChrome(take, kind) {
|
|
4383
4414
|
const custom = take(`custom_${kind}`);
|
|
@@ -4391,7 +4422,7 @@ function apitemplateChrome(take, kind) {
|
|
|
4391
4422
|
if (!slots.some(Boolean)) return { fromSlots: false };
|
|
4392
4423
|
const sizeText = size === void 0 ? "" : String(size).trim();
|
|
4393
4424
|
const fontSize2 = /^\d+(\.\d+)?$/.test(sizeText) ? `${sizeText}px` : /^\d+(\.\d+)?(px|pt|mm)$/.test(sizeText) ? sizeText : "9px";
|
|
4394
|
-
const cells = slots.map((
|
|
4425
|
+
const cells = slots.map((text3, i) => `<span style="flex:1;text-align:${["left", "center", "right"][i]}">${escapeText(text3)}</span>`).join("");
|
|
4395
4426
|
const styles = customHtml.match(/<style[\s\S]*?<\/style>/gi)?.join("") ?? "";
|
|
4396
4427
|
return {
|
|
4397
4428
|
html: convertHeaderFooter(`${styles}<div style="display:flex;gap:4mm;font-size:${fontSize2}">${cells}</div>`),
|
|
@@ -4511,15 +4542,15 @@ function parseSample(value) {
|
|
|
4511
4542
|
}
|
|
4512
4543
|
function positionOf2(source, index) {
|
|
4513
4544
|
const before = source.slice(0, index);
|
|
4514
|
-
const
|
|
4545
|
+
const line2 = before.split("\n").length;
|
|
4515
4546
|
const column = index - before.lastIndexOf("\n");
|
|
4516
|
-
return { line, column };
|
|
4547
|
+
return { line: line2, column };
|
|
4517
4548
|
}
|
|
4518
|
-
function notesFor(source, pattern,
|
|
4549
|
+
function notesFor(source, pattern, note2, { once = false } = {}) {
|
|
4519
4550
|
const global = new RegExp(pattern.source, pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`);
|
|
4520
4551
|
const out = [];
|
|
4521
4552
|
for (const m of source.matchAll(global)) {
|
|
4522
|
-
out.push({ ...
|
|
4553
|
+
out.push({ ...note2, ...positionOf2(source, m.index ?? 0) });
|
|
4523
4554
|
if (once) break;
|
|
4524
4555
|
}
|
|
4525
4556
|
return out;
|
|
@@ -4542,19 +4573,19 @@ function checkTemplate(engineId, html, sampleData, name, docs) {
|
|
|
4542
4573
|
docs: d.code === "unknown-filter" ? docs.filters : d.code.startsWith("missing-") ? docs.sampleData : docs.syntax
|
|
4543
4574
|
});
|
|
4544
4575
|
for (const d of engine.analyze(html, { sampleData }).diagnostics) {
|
|
4545
|
-
const
|
|
4576
|
+
const note2 = fromDiagnostic(d);
|
|
4546
4577
|
if (d.severity === "error") {
|
|
4547
|
-
if (!errors.some((x) => x.code ===
|
|
4548
|
-
} else warnings.push(
|
|
4578
|
+
if (!errors.some((x) => x.code === note2.code && x.line === note2.line)) errors.push(note2);
|
|
4579
|
+
} else warnings.push(note2);
|
|
4549
4580
|
}
|
|
4550
4581
|
return { errors, warnings };
|
|
4551
4582
|
}
|
|
4552
4583
|
function lengthMm(value) {
|
|
4553
4584
|
if (value === void 0 || value === null || value === "") return void 0;
|
|
4554
4585
|
if (typeof value === "number" && Number.isFinite(value)) return `${value}mm`;
|
|
4555
|
-
const
|
|
4556
|
-
if (/^-?\d+(\.\d+)?$/.test(
|
|
4557
|
-
if (/^-?\d+(\.\d+)?(mm|cm|in|px|pt)$/i.test(
|
|
4586
|
+
const text3 = String(value).trim();
|
|
4587
|
+
if (/^-?\d+(\.\d+)?$/.test(text3)) return `${text3}mm`;
|
|
4588
|
+
if (/^-?\d+(\.\d+)?(mm|cm|in|px|pt)$/i.test(text3)) return text3.toLowerCase();
|
|
4558
4589
|
return void 0;
|
|
4559
4590
|
}
|
|
4560
4591
|
function toBase64(value) {
|
|
@@ -4641,17 +4672,17 @@ var STYLE_BLOCK = /<style\b[^>]*>([\s\S]*?)<\/style\s*>/gi;
|
|
|
4641
4672
|
var HEAD_MARKUP = /<script\b[\s\S]*?<\/script\s*>|<!--[\s\S]*?-->|<(?:link|meta|base)\b[^>]*>/gi;
|
|
4642
4673
|
var TEMPLATED = /\{\{|\{%/;
|
|
4643
4674
|
function splitApitemplateCss(source) {
|
|
4644
|
-
const styleElement = (
|
|
4645
|
-
${
|
|
4675
|
+
const styleElement = (rules2) => `<style>
|
|
4676
|
+
${rules2}
|
|
4646
4677
|
</style>`;
|
|
4647
4678
|
if (!/<\/?(style|link|script|meta|base)\b|<!--/i.test(source))
|
|
4648
4679
|
return TEMPLATED.test(source) ? { css: "", head: "", body: styleElement(source.trim()) } : { css: source, head: "", body: "" };
|
|
4649
4680
|
const styles = [];
|
|
4650
4681
|
const head = [];
|
|
4651
4682
|
const body = [];
|
|
4652
|
-
let rest = source.replace(STYLE_BLOCK, (block,
|
|
4653
|
-
if (TEMPLATED.test(
|
|
4654
|
-
else styles.push(
|
|
4683
|
+
let rest = source.replace(STYLE_BLOCK, (block, rules2) => {
|
|
4684
|
+
if (TEMPLATED.test(rules2)) body.push(block.trim());
|
|
4685
|
+
else styles.push(rules2.replace(/^\n+|\s+$/g, ""));
|
|
4655
4686
|
return "\n";
|
|
4656
4687
|
});
|
|
4657
4688
|
rest = rest.replace(HEAD_MARKUP, (tag) => {
|
|
@@ -4674,7 +4705,7 @@ function importApitemplate(input) {
|
|
|
4674
4705
|
if (kind === "image") changes.push(`${format} template imported as an image template`);
|
|
4675
4706
|
const mapped = mapApitemplateSettings(input.settings ?? void 0);
|
|
4676
4707
|
const settings = mapped.settings;
|
|
4677
|
-
for (const
|
|
4708
|
+
for (const note2 of mapped.notes) changes.push(note2);
|
|
4678
4709
|
for (const key of mapped.ignored)
|
|
4679
4710
|
warnings.push({ code: "setting-ignored", message: `Setting "${key}" has no Formfeed equivalent and was dropped.`, docs: "/migrate/apitemplate-io#settings" });
|
|
4680
4711
|
if (settings.header?.html || settings.footer?.html) changes.push("header and footer templates moved to the Header and Footer tabs");
|
|
@@ -5071,11 +5102,11 @@ function inlineIncludes(source, blocks, errors, changes) {
|
|
|
5071
5102
|
}
|
|
5072
5103
|
var cssPaperFormats = { a3: "A3", a4: "A4", a5: "A5", letter: "Letter" };
|
|
5073
5104
|
var isoSizes = { a0: [841, 1189], a1: [594, 841], a2: [420, 594], a6: [105, 148] };
|
|
5074
|
-
var escapeHtml2 = (
|
|
5105
|
+
var escapeHtml2 = (text3) => text3.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
5075
5106
|
function simpleHeaderFooter(part, margin) {
|
|
5076
5107
|
const cells = ["left", "center", "right"].map((side) => part[side] ?? "");
|
|
5077
5108
|
if (!cells.some((c) => c.trim())) return void 0;
|
|
5078
|
-
const cell3 = (
|
|
5109
|
+
const cell3 = (text3, align) => `<div style="flex: 1; text-align: ${align}">${escapeHtml2(text3).replace(/\[page\]/g, '<span class="pageNumber"></span>').replace(/\[topage\]/g, '<span class="totalPages"></span>')}</div>`;
|
|
5079
5110
|
return `<div style="display: flex; width: 100%; font-size: 10px; padding: 0 ${margin.right} 0 ${margin.left}">${cell3(cells[0] ?? "", "left")}${cell3(cells[1] ?? "", "center")}${cell3(cells[2] ?? "", "right")}</div>`;
|
|
5080
5111
|
}
|
|
5081
5112
|
function mapSettings(input, kind, warnings, changes) {
|
|
@@ -5244,11 +5275,11 @@ var DOCS3 = "/migrate/jsreport";
|
|
|
5244
5275
|
var COLLECTIONS = ["templates", "data", "assets", "components", "scripts", "folders"];
|
|
5245
5276
|
function readJsreportExport(files) {
|
|
5246
5277
|
const bundle = { templates: [], data: [], assets: [], components: [], scripts: [], folders: [] };
|
|
5247
|
-
for (const [path,
|
|
5278
|
+
for (const [path, text3] of Object.entries(files)) {
|
|
5248
5279
|
const normalized = path.replace(/\\/g, "/").replace(/^\.?\//, "");
|
|
5249
5280
|
if (normalized === "metadata.json") {
|
|
5250
5281
|
try {
|
|
5251
|
-
bundle.version = String(JSON.parse(
|
|
5282
|
+
bundle.version = String(JSON.parse(text3).reporterVersion ?? "");
|
|
5252
5283
|
} catch {
|
|
5253
5284
|
}
|
|
5254
5285
|
continue;
|
|
@@ -5256,7 +5287,7 @@ function readJsreportExport(files) {
|
|
|
5256
5287
|
const collection = normalized.split("/")[0];
|
|
5257
5288
|
if (!COLLECTIONS.includes(collection) || !normalized.endsWith(".json")) continue;
|
|
5258
5289
|
try {
|
|
5259
|
-
bundle[collection].push(JSON.parse(
|
|
5290
|
+
bundle[collection].push(JSON.parse(text3));
|
|
5260
5291
|
} catch {
|
|
5261
5292
|
}
|
|
5262
5293
|
}
|
|
@@ -5281,9 +5312,9 @@ function pathOf2(bundle, entity) {
|
|
|
5281
5312
|
function jsreportTemplates(bundle) {
|
|
5282
5313
|
return bundle.templates.map((t) => ({ ref: t.shortid ?? t._id ?? t.name ?? "", name: t.name ?? "", path: pathOf2(bundle, t), engine: t.engine ?? "", recipe: t.recipe ?? "" })).sort((a, b) => a.path.localeCompare(b.path));
|
|
5283
5314
|
}
|
|
5284
|
-
function byPath(bundle,
|
|
5315
|
+
function byPath(bundle, list3, ref) {
|
|
5285
5316
|
const wanted = ref.replace(/^\.?\/+/, "");
|
|
5286
|
-
return
|
|
5317
|
+
return list3.find((e) => pathOf2(bundle, e) === wanted) ?? list3.find((e) => e.name === wanted.split("/").pop());
|
|
5287
5318
|
}
|
|
5288
5319
|
function decodeText(base64) {
|
|
5289
5320
|
const binary = atob(base64);
|
|
@@ -5298,7 +5329,7 @@ function assetBase64(content) {
|
|
|
5298
5329
|
}
|
|
5299
5330
|
return toBase64(content);
|
|
5300
5331
|
}
|
|
5301
|
-
var escapeMustaches = (
|
|
5332
|
+
var escapeMustaches = (text3) => text3.replace(/\{\{/g, "\\{{");
|
|
5302
5333
|
function resolveAssets(source, bundle, options, warnings, changes) {
|
|
5303
5334
|
const v3 = /\{\{\{?\s*asset\s+(["'])([^"']+)\1(?:\s+(["'])([^"']+)\3)?\s*\}?\}\}/g;
|
|
5304
5335
|
const v2 = /\{#asset\s+([^\s}]+)(?:\s+@encoding=(\w+))?\s*\}/g;
|
|
@@ -5536,9 +5567,9 @@ function importJsreport(bundle, ref, options = {}) {
|
|
|
5536
5567
|
}
|
|
5537
5568
|
|
|
5538
5569
|
// packages/engine/src/lib/generated/frames.ts
|
|
5539
|
-
var textEditRuntime = '"use strict";(()=>{var
|
|
5570
|
+
var textEditRuntime = '"use strict";(()=>{var O=`\nhtml.ff-edit-mode [data-ff-edit] { cursor: text; }\nhtml.ff-edit-mode [data-ff-edit]:hover { outline: 1px dashed rgba(37,99,235,.85); outline-offset: 2px; }\nhtml.ff-edit-mode [data-ff-edit="t"]:hover { outline-color: rgba(147,51,234,.9); }\n.ff-editing { outline: 2px solid #2563eb !important; outline-offset: 2px; cursor: text; }\n.ff-editing .ff-chip { background: rgba(37,99,235,.14) !important; box-shadow: inset 0 0 0 1px rgba(37,99,235,.45) !important; border-radius: 3px !important; padding: 0 1px !important; cursor: default; }\n.ff-edit-badge { position: absolute; z-index: 2147483647; font: 500 11px/1.4 system-ui, sans-serif !important; color: #fff !important; background: #2563eb !important; padding: 1px 6px !important; border-radius: 4px !important; pointer-events: none; white-space: nowrap; }\n`;function F(l,d={}){let m=d.clicks!==!1,g=d.live===!0,o=l.document,i=null,s=null,f=e=>{try{l.parent.postMessage(e,"*")}catch{}},v=m?o.querySelector(\'meta[name="formfeed:document"]\')?.getAttribute("content")??null:null,h=!1;l.addEventListener("blur",()=>{h=!0}),l.addEventListener("focus",()=>{h=!1});let y=o.createElement("style");y.setAttribute("data-formfeed","edit"),y.setAttribute("data-pagedjs-ignore",""),y.textContent=O,(o.head??o.documentElement).appendChild(y),m&&o.documentElement.classList.add("ff-edit-mode");let M=e=>(e&&typeof e.closest=="function"?e:null)?.closest("[data-ff-edit]")??null;o.addEventListener("click",e=>{if(!m)return;if(i&&!i.done&&i.element.contains(e.target)){e.stopImmediatePropagation();return}let t=M(e.target);t&&(e.preventDefault(),e.stopImmediatePropagation(),C(t,{x:e.clientX,y:e.clientY}))},!0);function C(e,t){i&&!i.done&&x();let n=e.getAttribute("data-ff-src")??"",r=e.getBoundingClientRect(),u=Array.from(o.querySelectorAll(`[data-ff-src="${n.replace(/"/g,"")}"]`));s={src:n,element:e,point:t},f({type:"formfeed:edit-request",src:n,doc:v,edit:e.getAttribute("data-ff-edit"),text:e.textContent??"",elements:e.childElementCount,count:u.length,index:Math.max(0,u.indexOf(e)),split:e.hasAttribute("data-split-from")||e.hasAttribute("data-split-to"),rect:{left:r.left,top:r.top,width:r.width,height:r.height}})}o.addEventListener("keydown",e=>{if(!m||i&&!i.done||!(e.ctrlKey||e.metaKey)||e.altKey)return;let t=e.key.toLowerCase();(t==="z"||t==="y")&&(e.preventDefault(),f({type:t==="y"||e.shiftKey?"formfeed:redo":"formfeed:undo"}))}),l.addEventListener("message",e=>{if(e.source!==l.parent)return;let t=e.data;!t||typeof t.type!="string"||(t.type==="formfeed:edit-begin"?P(t):t.type==="formfeed:edit-refuse"||t.type==="formfeed:edit-end"?(s=null,i&&!i.done&&E(!1)):t.type==="formfeed:edit-open"&&B(t))});function B(e){if(!m||typeof e.src!="string"||i&&!i.done)return;let t=Array.from(o.querySelectorAll(`[data-ff-src="${e.src.replace(/"/g,"")}"][data-ff-edit]`)),n=Number.isInteger(e.index)?Number(e.index):0,r=t[n]??t[0];r&&C(r,null)}if(m){let e=()=>f({type:"formfeed:edit-ready",doc:v}),t=l;t.PagedConfig?t.formfeedEditReady=e:o.readyState==="loading"?o.addEventListener("DOMContentLoaded",e):e()}function P(e){i&&!i.done&&E(!1);let t=e.layer?o.querySelector(`[data-ff-layer="${String(e.layer).replace(/"/g,"")}"] > .ff-text`):s&&s.src===e.src?s.element:o.querySelector(`[data-ff-src="${String(e.src).replace(/"/g,"")}"]`),n=e.at,r=e.layer?n&&Number.isFinite(n.x)&&Number.isFinite(n.y)?{x:Number(n.x),y:Number(n.y)}:null:s&&s.src===e.src?s.point:null;s=null;let u=h&&!o.hasFocus();if(!t||!Array.isArray(e.items)||u){f({type:"formfeed:edit-cancel",token:String(e.token)});return}let c=Array.from(t.childNodes),b=o.createDocumentFragment();for(let a of e.items)if(a.kind==="text")b.appendChild(o.createTextNode(String(a.text)));else if(a.kind==="break")b.appendChild(o.createElement("br"));else if(a.kind==="chip"){let p=o.createElement("span");p.className="ff-chip",p.setAttribute("data-ff-chip",String(a.index)),p.setAttribute("contenteditable","false"),a.title&&(p.title=String(a.title)),p.textContent=String(a.text),b.appendChild(p)}for(let a of c)t.removeChild(a);t.appendChild(b),t.contentEditable="true",t.classList.add("ff-editing"),t.setAttribute("role","textbox"),e.label&&t.setAttribute("aria-label",String(e.label)),t.spellcheck=!0,i={token:String(e.token),element:t,saved:c,allowBreaks:e.allowBreaks===!0,badge:e.note?H(t,String(e.note)):null,done:!1},t.addEventListener("keydown",A),t.addEventListener("beforeinput",T),t.addEventListener("paste",S),t.addEventListener("drop",N),t.addEventListener("focusout",R),g&&t.addEventListener("input",k),t.focus(),e.select==="all"?I(t):K(t,r),f({type:"formfeed:edit-started",token:i.token}),typeof e.insert=="string"&&e.insert&&L(e.insert.replace(/\\r\\n?|\\n/g," "))}function L(e){if(typeof o.execCommand=="function"&&o.execCommand("insertText",!1,e))return;let t=l.getSelection(),n=t&&t.rangeCount?t.getRangeAt(0):null;n&&(n.deleteContents(),n.insertNode(o.createTextNode(e)),n.collapse(!1),g&&k())}function k(){i&&!i.done&&f({type:"formfeed:edit-input",token:i.token,items:D(i.element)})}function H(e,t){let n=o.createElement("div");n.className="ff-edit-badge",n.textContent=t;let r=e.getBoundingClientRect();return n.style.left=`${r.left+l.scrollX}px`,n.style.top=`${Math.max(0,r.top+l.scrollY-22)}px`,o.body.appendChild(n),n}function I(e){let t=l.getSelection();if(!t)return;let n=o.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}function K(e,t){let n=l.getSelection();if(!n)return;let r=null,u=o;if(t){if(u.caretRangeFromPoint)r=u.caretRangeFromPoint(t.x,t.y);else if(u.caretPositionFromPoint){let c=u.caretPositionFromPoint(t.x,t.y);c&&(r=o.createRange(),r.setStart(c.offsetNode,c.offset))}}if(!r||!e.contains(r.startContainer))r=o.createRange(),r.selectNodeContents(e),r.collapse(!1);else if(t){let c=r.startContainer,a=(c.nodeType===1?c:c.parentElement)?.closest("[data-ff-chip]")??null;if(a&&a!==e&&e.contains(a)){let p=a.getBoundingClientRect();r=o.createRange(),t.x<p.left+p.width/2?r.setStartBefore(a):r.setStartAfter(a),r.collapse(!0)}}n.removeAllRanges(),n.addRange(r)}function A(e){let t=e.key;t==="Escape"?(e.preventDefault(),E(!0)):t==="Enter"&&!e.shiftKey?(e.preventDefault(),x()):t==="Enter"?(e.preventDefault(),i?.allowBreaks&&q()):t==="Tab"?(e.preventDefault(),x()):(e.ctrlKey||e.metaKey)&&["b","i","u"].includes(t.toLowerCase())&&(e.preventDefault(),g&&i&&!e.altKey&&f({type:"formfeed:edit-style",token:i.token,key:t.toLowerCase()}))}function T(e){let t=e.inputType??"";(t.startsWith("format")||t==="insertFromDrop"||t==="insertParagraph"||t==="insertLineBreak")&&e.preventDefault()}function S(e){e.preventDefault(),L((e.clipboardData?.getData("text/plain")??"").replace(/\\r\\n?|\\n/g," "))}function N(e){e.preventDefault()}function R(){l.setTimeout(()=>{i&&!i.done&&(!o.hasFocus()||!i.element.contains(o.activeElement))&&x()},0)}function q(){let e=l.getSelection();if(!e||!e.rangeCount)return;let t=e.getRangeAt(0);t.deleteContents();let n=o.createElement("br");t.insertNode(n),n.nextSibling||n.parentNode?.appendChild(o.createElement("br"));let r=o.createRange();r.setStartAfter(n),r.collapse(!0),e.removeAllRanges(),e.addRange(r)}function w(e){e.done=!0;let t=e.element;t.removeEventListener("keydown",A),t.removeEventListener("beforeinput",T),t.removeEventListener("paste",S),t.removeEventListener("drop",N),t.removeEventListener("focusout",R),t.removeEventListener("input",k),t.removeAttribute("contenteditable"),t.removeAttribute("role"),t.removeAttribute("aria-label"),t.classList.remove("ff-editing"),e.badge?.remove(),i===e&&(i=null)}function x(){let e=i;if(!e||e.done)return;let t=D(e.element);w(e),f({type:"formfeed:edit-commit",token:e.token,items:t})}function E(e){let t=i;if(!t||t.done)return;let n=t.element;for(;n.firstChild;)n.removeChild(n.firstChild);for(let r of t.saved)n.appendChild(r);w(t),e&&f({type:"formfeed:edit-cancel",token:t.token})}}function D(l){let d=[],m=o=>{let i=d[d.length-1];i?.kind==="text"?i.text+=o:o&&d.push({kind:"text",text:o})},g=o=>{for(let i of Array.from(o.childNodes))if(i.nodeType===3)m(i.data);else if(i.nodeType===1){let s=i,f=s.getAttribute("data-ff-chip");f!==null?d.push({kind:"chip",index:Number(f)}):s.tagName==="BR"?d.push({kind:"break"}):((s.tagName==="DIV"||s.tagName==="P")&&d.length&&d.push({kind:"break"}),g(s))}};for(g(l);d[d.length-1]?.kind==="break";)d.pop();return d}F(window);})();';
|
|
5540
5571
|
var fitRuntime = '"use strict";(()=>{function a(t,e,n){if(e===t)return t.scrollHeight<=t.clientHeight+.5&&t.scrollWidth<=t.clientWidth+.5;let o=n.getComputedStyle(t),i=t.clientHeight-(parseFloat(o.paddingTop)||0)-(parseFloat(o.paddingBottom)||0);return e.scrollHeight<=i+.5&&e.scrollWidth<=e.clientWidth+.5}function m(t,e){let n=t.firstElementChild??t;n.style.fontSize="";let o=parseFloat(e.getComputedStyle(n).fontSize)||16,i=Math.min(o,parseFloat(t.getAttribute("data-ff-fit-min")??"")||o/2);if(a(t,n,e))return o;let l=i,s=o;for(let d=0;d<14;d++){let r=(l+s)/2;n.style.fontSize=`${r}px`,a(t,n,e)?l=r:s=r}let f=Math.floor(l*100)/100;return n.style.fontSize=`${f}px`,f}function c(t){let e=()=>{for(let o of Array.from(t.document.querySelectorAll(\'[data-ff-fit="shrink"]\')))m(o,t);t.document.documentElement.setAttribute("data-ff-fit","done")};t.formfeedFit=e;let n=t.document.fonts;n?n.ready.then(e):t.addEventListener("load",e)}c(window);})();';
|
|
5541
|
-
var stageRuntime = '"use strict";(()=>{var
|
|
5572
|
+
var stageRuntime = '"use strict";(()=>{var W=`\nhtml.ff-edit-mode [data-ff-edit] { cursor: text; }\nhtml.ff-edit-mode [data-ff-edit]:hover { outline: 1px dashed rgba(37,99,235,.85); outline-offset: 2px; }\nhtml.ff-edit-mode [data-ff-edit="t"]:hover { outline-color: rgba(147,51,234,.9); }\n.ff-editing { outline: 2px solid #2563eb !important; outline-offset: 2px; cursor: text; }\n.ff-editing .ff-chip { background: rgba(37,99,235,.14) !important; box-shadow: inset 0 0 0 1px rgba(37,99,235,.45) !important; border-radius: 3px !important; padding: 0 1px !important; cursor: default; }\n.ff-edit-badge { position: absolute; z-index: 2147483647; font: 500 11px/1.4 system-ui, sans-serif !important; color: #fff !important; background: #2563eb !important; padding: 1px 6px !important; border-radius: 4px !important; pointer-events: none; white-space: nowrap; }\n`;function H(a,l={}){let f=l.clicks!==!1,p=l.live===!0,n=a.document,o=null,d=null,u=e=>{try{a.parent.postMessage(e,"*")}catch{}},m=f?n.querySelector(\'meta[name="formfeed:document"]\')?.getAttribute("content")??null:null,s=!1;a.addEventListener("blur",()=>{s=!0}),a.addEventListener("focus",()=>{s=!1});let g=n.createElement("style");g.setAttribute("data-formfeed","edit"),g.setAttribute("data-pagedjs-ignore",""),g.textContent=W,(n.head??n.documentElement).appendChild(g),f&&n.documentElement.classList.add("ff-edit-mode");let x=e=>(e&&typeof e.closest=="function"?e:null)?.closest("[data-ff-edit]")??null;n.addEventListener("click",e=>{if(!f)return;if(o&&!o.done&&o.element.contains(e.target)){e.stopImmediatePropagation();return}let t=x(e.target);t&&(e.preventDefault(),e.stopImmediatePropagation(),v(t,{x:e.clientX,y:e.clientY}))},!0);function v(e,t){o&&!o.done&&L();let r=e.getAttribute("data-ff-src")??"",i=e.getBoundingClientRect(),b=Array.from(n.querySelectorAll(`[data-ff-src="${r.replace(/"/g,"")}"]`));d={src:r,element:e,point:t},u({type:"formfeed:edit-request",src:r,doc:m,edit:e.getAttribute("data-ff-edit"),text:e.textContent??"",elements:e.childElementCount,count:b.length,index:Math.max(0,b.indexOf(e)),split:e.hasAttribute("data-split-from")||e.hasAttribute("data-split-to"),rect:{left:i.left,top:i.top,width:i.width,height:i.height}})}n.addEventListener("keydown",e=>{if(!f||o&&!o.done||!(e.ctrlKey||e.metaKey)||e.altKey)return;let t=e.key.toLowerCase();(t==="z"||t==="y")&&(e.preventDefault(),u({type:t==="y"||e.shiftKey?"formfeed:redo":"formfeed:undo"}))}),a.addEventListener("message",e=>{if(e.source!==a.parent)return;let t=e.data;!t||typeof t.type!="string"||(t.type==="formfeed:edit-begin"?B(t):t.type==="formfeed:edit-refuse"||t.type==="formfeed:edit-end"?(d=null,o&&!o.done&&S(!1)):t.type==="formfeed:edit-open"&&E(t))});function E(e){if(!f||typeof e.src!="string"||o&&!o.done)return;let t=Array.from(n.querySelectorAll(`[data-ff-src="${e.src.replace(/"/g,"")}"][data-ff-edit]`)),r=Number.isInteger(e.index)?Number(e.index):0,i=t[r]??t[0];i&&v(i,null)}if(f){let e=()=>u({type:"formfeed:edit-ready",doc:m}),t=a;t.PagedConfig?t.formfeedEditReady=e:n.readyState==="loading"?n.addEventListener("DOMContentLoaded",e):e()}function B(e){o&&!o.done&&S(!1);let t=e.layer?n.querySelector(`[data-ff-layer="${String(e.layer).replace(/"/g,"")}"] > .ff-text`):d&&d.src===e.src?d.element:n.querySelector(`[data-ff-src="${String(e.src).replace(/"/g,"")}"]`),r=e.at,i=e.layer?r&&Number.isFinite(r.x)&&Number.isFinite(r.y)?{x:Number(r.x),y:Number(r.y)}:null:d&&d.src===e.src?d.point:null;d=null;let b=s&&!n.hasFocus();if(!t||!Array.isArray(e.items)||b){u({type:"formfeed:edit-cancel",token:String(e.token)});return}let y=Array.from(t.childNodes),k=n.createDocumentFragment();for(let c of e.items)if(c.kind==="text")k.appendChild(n.createTextNode(String(c.text)));else if(c.kind==="break")k.appendChild(n.createElement("br"));else if(c.kind==="chip"){let h=n.createElement("span");h.className="ff-chip",h.setAttribute("data-ff-chip",String(c.index)),h.setAttribute("contenteditable","false"),c.title&&(h.title=String(c.title)),h.textContent=String(c.text),k.appendChild(h)}for(let c of y)t.removeChild(c);t.appendChild(k),t.contentEditable="true",t.classList.add("ff-editing"),t.setAttribute("role","textbox"),e.label&&t.setAttribute("aria-label",String(e.label)),t.spellcheck=!0,o={token:String(e.token),element:t,saved:y,allowBreaks:e.allowBreaks===!0,badge:e.note?I(t,String(e.note)):null,done:!1},t.addEventListener("keydown",T),t.addEventListener("beforeinput",N),t.addEventListener("paste",w),t.addEventListener("drop",R),t.addEventListener("focusout",F),p&&t.addEventListener("input",C),t.focus(),e.select==="all"?q(t):K(t,i),u({type:"formfeed:edit-started",token:o.token}),typeof e.insert=="string"&&e.insert&&A(e.insert.replace(/\\r\\n?|\\n/g," "))}function A(e){if(typeof n.execCommand=="function"&&n.execCommand("insertText",!1,e))return;let t=a.getSelection(),r=t&&t.rangeCount?t.getRangeAt(0):null;r&&(r.deleteContents(),r.insertNode(n.createTextNode(e)),r.collapse(!1),p&&C())}function C(){o&&!o.done&&u({type:"formfeed:edit-input",token:o.token,items:D(o.element)})}function I(e,t){let r=n.createElement("div");r.className="ff-edit-badge",r.textContent=t;let i=e.getBoundingClientRect();return r.style.left=`${i.left+a.scrollX}px`,r.style.top=`${Math.max(0,i.top+a.scrollY-22)}px`,n.body.appendChild(r),r}function q(e){let t=a.getSelection();if(!t)return;let r=n.createRange();r.selectNodeContents(e),t.removeAllRanges(),t.addRange(r)}function K(e,t){let r=a.getSelection();if(!r)return;let i=null,b=n;if(t){if(b.caretRangeFromPoint)i=b.caretRangeFromPoint(t.x,t.y);else if(b.caretPositionFromPoint){let y=b.caretPositionFromPoint(t.x,t.y);y&&(i=n.createRange(),i.setStart(y.offsetNode,y.offset))}}if(!i||!e.contains(i.startContainer))i=n.createRange(),i.selectNodeContents(e),i.collapse(!1);else if(t){let y=i.startContainer,c=(y.nodeType===1?y:y.parentElement)?.closest("[data-ff-chip]")??null;if(c&&c!==e&&e.contains(c)){let h=c.getBoundingClientRect();i=n.createRange(),t.x<h.left+h.width/2?i.setStartBefore(c):i.setStartAfter(c),i.collapse(!0)}}r.removeAllRanges(),r.addRange(i)}function T(e){let t=e.key;t==="Escape"?(e.preventDefault(),S(!0)):t==="Enter"&&!e.shiftKey?(e.preventDefault(),L()):t==="Enter"?(e.preventDefault(),o?.allowBreaks&&$()):t==="Tab"?(e.preventDefault(),L()):(e.ctrlKey||e.metaKey)&&["b","i","u"].includes(t.toLowerCase())&&(e.preventDefault(),p&&o&&!e.altKey&&u({type:"formfeed:edit-style",token:o.token,key:t.toLowerCase()}))}function N(e){let t=e.inputType??"";(t.startsWith("format")||t==="insertFromDrop"||t==="insertParagraph"||t==="insertLineBreak")&&e.preventDefault()}function w(e){e.preventDefault(),A((e.clipboardData?.getData("text/plain")??"").replace(/\\r\\n?|\\n/g," "))}function R(e){e.preventDefault()}function F(){a.setTimeout(()=>{o&&!o.done&&(!n.hasFocus()||!o.element.contains(n.activeElement))&&L()},0)}function $(){let e=a.getSelection();if(!e||!e.rangeCount)return;let t=e.getRangeAt(0);t.deleteContents();let r=n.createElement("br");t.insertNode(r),r.nextSibling||r.parentNode?.appendChild(n.createElement("br"));let i=n.createRange();i.setStartAfter(r),i.collapse(!0),e.removeAllRanges(),e.addRange(i)}function M(e){e.done=!0;let t=e.element;t.removeEventListener("keydown",T),t.removeEventListener("beforeinput",N),t.removeEventListener("paste",w),t.removeEventListener("drop",R),t.removeEventListener("focusout",F),t.removeEventListener("input",C),t.removeAttribute("contenteditable"),t.removeAttribute("role"),t.removeAttribute("aria-label"),t.classList.remove("ff-editing"),e.badge?.remove(),o===e&&(o=null)}function L(){let e=o;if(!e||e.done)return;let t=D(e.element);M(e),u({type:"formfeed:edit-commit",token:e.token,items:t})}function S(e){let t=o;if(!t||t.done)return;let r=t.element;for(;r.firstChild;)r.removeChild(r.firstChild);for(let i of t.saved)r.appendChild(i);M(t),e&&u({type:"formfeed:edit-cancel",token:t.token})}}function D(a){let l=[],f=n=>{let o=l[l.length-1];o?.kind==="text"?o.text+=n:n&&l.push({kind:"text",text:n})},p=n=>{for(let o of Array.from(n.childNodes))if(o.nodeType===3)f(o.data);else if(o.nodeType===1){let d=o,u=d.getAttribute("data-ff-chip");u!==null?l.push({kind:"chip",index:Number(u)}):d.tagName==="BR"?l.push({kind:"break"}):((d.tagName==="DIV"||d.tagName==="P")&&l.length&&l.push({kind:"break"}),p(d))}};for(p(a);l[l.length-1]?.kind==="break";)l.pop();return l}function O(a,l){return Array.from(a.querySelectorAll("[data-ff-layer]")).map(f=>{let p=f.querySelector(":scope > .ff-text"),n=!1;if(p&&f.style.height!=="auto"){let o=l.getComputedStyle(f),d=f.clientHeight-(parseFloat(o.paddingTop)||0)-(parseFloat(o.paddingBottom)||0);n=o.overflow==="hidden"&&(p.scrollHeight>d+1||p.scrollWidth>p.clientWidth+1)}return{id:f.getAttribute("data-ff-layer")??"",width:f.offsetWidth,height:f.offsetHeight,overflow:n}})}function P(a){let l=a.document,f=m=>{try{a.parent.postMessage(m,"*")}catch{}},p=m=>typeof m=="string"?l.querySelector(`[data-ff-layer="${m.replace(/"/g,"")}"]`):null,n=()=>{for(let m of Array.from(l.querySelectorAll("[data-ff-layer]")))for(let s of["left","top","width","height","transform"])m.style.removeProperty(s)},o=()=>{a.formfeedFit?.(),f({type:"formfeed:ready",layers:O(l,a)})};a.addEventListener("message",m=>{if(m.source!==a.parent)return;let s=m.data;if(!(!s||typeof s.type!="string")){if(s.type==="formfeed:layer-style"){let g=p(s.id);if(!g)return;let x=(v,E)=>{typeof E=="number"&&Number.isFinite(E)&&g.style.setProperty(v,`${E}px`)};x("left",s.left),x("top",s.top),x("width",s.width),x("height",s.height),typeof s.rotation=="number"&&Number.isFinite(s.rotation)&&g.style.setProperty("transform",s.rotation?`rotate(${s.rotation}deg)`:"none")}else if(s.type==="formfeed:layer-style-clear")n();else if(s.type==="formfeed:css"&&typeof s.css=="string"){let g=l.querySelector(\'style[data-formfeed="template"]\');g&&(g.textContent=s.css),n(),o()}}}),H(a,{clicks:!1,live:!0});let d=l.fonts,u=()=>d?void d.ready.then(o):o();l.readyState==="complete"?u():a.addEventListener("load",u)}P(window);})();';
|
|
5542
5573
|
|
|
5543
5574
|
// packages/engine/src/lib/assemble.ts
|
|
5544
5575
|
var DEFAULT_CHROME_PADDING = "0 10mm";
|
|
@@ -5773,6 +5804,13 @@ document.addEventListener('click', function (event) {
|
|
|
5773
5804
|
if (!el || el.nodeType !== 1) return;
|
|
5774
5805
|
try {
|
|
5775
5806
|
var annotated = el.closest ? el.closest('[data-ff-src]') : null;
|
|
5807
|
+
// the paper around the template (the page's margins, the pane behind it) is no element of it:
|
|
5808
|
+
// a click there asks for nothing
|
|
5809
|
+
if (!annotated && (
|
|
5810
|
+
el === document.documentElement || el === document.body ||
|
|
5811
|
+
el.querySelector('[data-ff-src]') ||
|
|
5812
|
+
(el.closest && el.closest('[class*="pagedjs_"]') === el)
|
|
5813
|
+
)) return;
|
|
5776
5814
|
parent.postMessage({
|
|
5777
5815
|
type: 'formfeed:inspect',
|
|
5778
5816
|
src: annotated ? annotated.getAttribute('data-ff-src') : null,
|
|
@@ -5786,6 +5824,10 @@ document.addEventListener('click', function (event) {
|
|
|
5786
5824
|
}, true);
|
|
5787
5825
|
</script>`;
|
|
5788
5826
|
var textEditScript = `<script>${textEditRuntime.replace(/<\/script/gi, "<\\/script")}</script>`;
|
|
5827
|
+
function documentMeta(options) {
|
|
5828
|
+
const name = (options.document ?? "").replace(/[^A-Za-z0-9_-]/g, "");
|
|
5829
|
+
return name ? `<meta name="formfeed:document" content="${name}">` : "";
|
|
5830
|
+
}
|
|
5789
5831
|
var pageNavScript = `<script>
|
|
5790
5832
|
(function () {
|
|
5791
5833
|
var pages = function () { return document.querySelectorAll('.pagedjs_page'); };
|
|
@@ -5920,7 +5962,7 @@ body.formfeed-preview { position: relative; box-sizing: border-box; width: ${pap
|
|
|
5920
5962
|
const footer = footerHtml ? `<div class="formfeed-chrome" style="${pdf ? flowChromeStyle(settings, "footer") : `${chromeBoxStyle(settings, "footer")}margin-top:8px`}">${pageNumberSpans(footerHtml, "1", "1")}</div>` : "";
|
|
5921
5963
|
return intoHead(
|
|
5922
5964
|
draft.document,
|
|
5923
|
-
`${chrome}${options.editing ? textEditScript : ""}${inspectScript}${zoomGestureScript}${pdf ? overflowScript("flow") : ""}`
|
|
5965
|
+
`${documentMeta(options)}${chrome}${options.editing ? textEditScript : ""}${inspectScript}${zoomGestureScript}${pdf ? overflowScript("flow") : ""}`
|
|
5924
5966
|
).replace(/(<body[^>]*>)/, `$1${header}`).replace("</body>", `${footer}</body>`);
|
|
5925
5967
|
}
|
|
5926
5968
|
function canvasDocument(draft) {
|
|
@@ -5948,13 +5990,13 @@ html { background: #e5e7eb; }
|
|
|
5948
5990
|
`;
|
|
5949
5991
|
const selectorGuard = `<script>(function(){var q=DocumentFragment.prototype.querySelectorAll;DocumentFragment.prototype.querySelectorAll=function(s){try{return q.call(this,s);}catch(e){console.warn('formfeed paged preview: skipped a selector Paged.js could not use:',s);return q.call(this,':not(*)');}};})();</script>`;
|
|
5950
5992
|
const boxSizingGuard = `<script>(function(){var rule='.pagedjs_pagebox *';var o=new MutationObserver(function(ms){ms.forEach(function(m){m.addedNodes.forEach(function(n){if(n.nodeName==='STYLE'&&n.textContent&&n.textContent.indexOf(rule)>=0){n.textContent=n.textContent.split(rule).join('.pagedjs_pagebox [class*="pagedjs_"]');o.disconnect();}});});});o.observe(document.documentElement,{childList:true,subtree:true});})();</script>`;
|
|
5951
|
-
const config = `<script>window.PagedConfig = { auto: true, after: function (flow) { try { if (window.formfeedDrawCharts) window.formfeedDrawCharts(); } catch (e) {} try { if (window.formfeedFit) window.formfeedFit(); } catch (e) {} try { parent.postMessage({ type: 'formfeed:pages', pages: flow.total }, '*'); } catch (e) {} if (window.formfeedCheckOverflow) window.formfeedCheckOverflow(); } };</script>`;
|
|
5993
|
+
const config = `<script>window.PagedConfig = { auto: true, after: function (flow) { try { if (window.formfeedDrawCharts) window.formfeedDrawCharts(); } catch (e) {} try { if (window.formfeedFit) window.formfeedFit(); } catch (e) {} try { parent.postMessage({ type: 'formfeed:pages', pages: flow.total }, '*'); } catch (e) {} if (window.formfeedCheckOverflow) window.formfeedCheckOverflow(); try { if (window.formfeedEditReady) window.formfeedEditReady(); } catch (e) {} } };</script>`;
|
|
5952
5994
|
const script = `<script src="${options.pagedScriptUrl}"></script>`;
|
|
5953
5995
|
const header = headerHtml ? `<div class="ff-running-header">${pageNumberSpans(headerHtml, '<span class="ff-page-no"></span>', '<span class="ff-page-total"></span>')}</div>` : "";
|
|
5954
5996
|
const footer = footerHtml ? `<div class="ff-running-footer">${pageNumberSpans(footerHtml, '<span class="ff-page-no"></span>', '<span class="ff-page-total"></span>')}</div>` : "";
|
|
5955
5997
|
return intoHead(
|
|
5956
5998
|
draft.document,
|
|
5957
|
-
|
|
5999
|
+
`${documentMeta(options)}<style data-formfeed="paged">${runningCss}</style>${selectorGuard}${boxSizingGuard}${overflowScript("paged")}${config}${script}${options.editing ? textEditScript : ""}${inspectScript}${pageNavScript}${zoomGestureScript}`
|
|
5958
6000
|
).replace(/(<body[^>]*>)/, `$1${header}${footer}`);
|
|
5959
6001
|
}
|
|
5960
6002
|
|
|
@@ -6187,11 +6229,11 @@ function locate(starts, offset) {
|
|
|
6187
6229
|
}
|
|
6188
6230
|
return { line: low + 1, column: offset - (starts[low] ?? 0) + 1 };
|
|
6189
6231
|
}
|
|
6190
|
-
function offsetOf(starts, sourceLength,
|
|
6191
|
-
const start = starts[
|
|
6232
|
+
function offsetOf(starts, sourceLength, line2, column) {
|
|
6233
|
+
const start = starts[line2 - 1];
|
|
6192
6234
|
if (start === void 0 || column < 1) return null;
|
|
6193
6235
|
const offset = start + column - 1;
|
|
6194
|
-
const next = starts[
|
|
6236
|
+
const next = starts[line2] ?? sourceLength + 1;
|
|
6195
6237
|
return offset < next ? offset : null;
|
|
6196
6238
|
}
|
|
6197
6239
|
|
|
@@ -6347,7 +6389,10 @@ function editableRegionAt(source, engine, at) {
|
|
|
6347
6389
|
const hasText = region.parts.some(
|
|
6348
6390
|
(p) => p.kind === "text" && decodeText2(source.slice(p.start, p.end)).text.trim() !== ""
|
|
6349
6391
|
);
|
|
6350
|
-
|
|
6392
|
+
const hasField = region.parts.some(
|
|
6393
|
+
(p) => p.kind === "chip" && p.chip === "expression"
|
|
6394
|
+
);
|
|
6395
|
+
return hasText || hasField ? region : { reason: "no-text" };
|
|
6351
6396
|
}
|
|
6352
6397
|
function findRegionAgain(source, engine, outer) {
|
|
6353
6398
|
const first = source.indexOf(outer);
|
|
@@ -6355,6 +6400,9 @@ function findRegionAgain(source, engine, outer) {
|
|
|
6355
6400
|
const found = editableRegionAt(source, engine, first);
|
|
6356
6401
|
return "reason" in found ? null : found;
|
|
6357
6402
|
}
|
|
6403
|
+
function regionPosition(source, region) {
|
|
6404
|
+
return locate(lineStarts(source), region.tagStart);
|
|
6405
|
+
}
|
|
6358
6406
|
function regionChips(source, region) {
|
|
6359
6407
|
const chips = [];
|
|
6360
6408
|
for (const part of region.parts)
|
|
@@ -6439,18 +6487,18 @@ function applyRegionEdit(source, engine, region, items) {
|
|
|
6439
6487
|
const rewritten = source.slice(0, region.start) + whole + source.slice(region.end);
|
|
6440
6488
|
return readsBack(rewritten, engine, region.tagStart, expected) ? { source: rewritten } : { error: "invalid" };
|
|
6441
6489
|
}
|
|
6442
|
-
function translationItems(
|
|
6490
|
+
function translationItems(text3) {
|
|
6443
6491
|
const items = [];
|
|
6444
6492
|
const names = [];
|
|
6445
6493
|
let last = 0;
|
|
6446
|
-
for (const match of
|
|
6494
|
+
for (const match of text3.matchAll(/\{(\w+)\}/g)) {
|
|
6447
6495
|
if (match.index > last)
|
|
6448
|
-
items.push({ kind: "text", text:
|
|
6496
|
+
items.push({ kind: "text", text: text3.slice(last, match.index) });
|
|
6449
6497
|
items.push({ kind: "chip", index: names.length });
|
|
6450
6498
|
names.push(match[1] ?? "");
|
|
6451
6499
|
last = match.index + match[0].length;
|
|
6452
6500
|
}
|
|
6453
|
-
if (last <
|
|
6501
|
+
if (last < text3.length) items.push({ kind: "text", text: text3.slice(last) });
|
|
6454
6502
|
return { items, names };
|
|
6455
6503
|
}
|
|
6456
6504
|
function translationText(items, names) {
|
|
@@ -6694,9 +6742,9 @@ function translationCall(engine, inner) {
|
|
|
6694
6742
|
);
|
|
6695
6743
|
return match ? { key: match[2] ?? "", params: parseParams(match[3] ?? "", "=", " ") } : null;
|
|
6696
6744
|
}
|
|
6697
|
-
function parseParams(
|
|
6745
|
+
function parseParams(text3, assign, separator) {
|
|
6698
6746
|
const params = {};
|
|
6699
|
-
for (const piece of splitTopLevel(
|
|
6747
|
+
for (const piece of splitTopLevel(text3, separator)) {
|
|
6700
6748
|
const at = piece.indexOf(assign);
|
|
6701
6749
|
if (at <= 0) continue;
|
|
6702
6750
|
const name = piece.slice(0, at).trim().replace(/^['"]|['"]$/g, "");
|
|
@@ -6704,12 +6752,12 @@ function parseParams(text2, assign, separator) {
|
|
|
6704
6752
|
}
|
|
6705
6753
|
return params;
|
|
6706
6754
|
}
|
|
6707
|
-
function splitTopLevel(
|
|
6755
|
+
function splitTopLevel(text3, separator) {
|
|
6708
6756
|
const pieces = [];
|
|
6709
6757
|
let depth = 0;
|
|
6710
6758
|
let quote2 = null;
|
|
6711
6759
|
let current = "";
|
|
6712
|
-
for (const ch of
|
|
6760
|
+
for (const ch of text3) {
|
|
6713
6761
|
if (quote2) {
|
|
6714
6762
|
if (ch === quote2) quote2 = null;
|
|
6715
6763
|
} else if (ch === '"' || ch === "'") quote2 = ch;
|
|
@@ -6734,7 +6782,7 @@ function entityChar(reference) {
|
|
|
6734
6782
|
return code === void 0 ? null : String.fromCharCode(code);
|
|
6735
6783
|
}
|
|
6736
6784
|
function decodeText2(raw) {
|
|
6737
|
-
let
|
|
6785
|
+
let text3 = "";
|
|
6738
6786
|
const map = [];
|
|
6739
6787
|
let i = 0;
|
|
6740
6788
|
while (i < raw.length) {
|
|
@@ -6744,23 +6792,23 @@ function decodeText2(raw) {
|
|
|
6744
6792
|
const decoded = match ? entityChar(match[1] ?? "") : null;
|
|
6745
6793
|
if (match && decoded !== null) {
|
|
6746
6794
|
for (let u = 0; u < decoded.length; u++) map.push(i);
|
|
6747
|
-
|
|
6795
|
+
text3 += decoded;
|
|
6748
6796
|
i += match[0].length;
|
|
6749
6797
|
continue;
|
|
6750
6798
|
}
|
|
6751
6799
|
}
|
|
6752
|
-
|
|
6800
|
+
text3 += raw[i];
|
|
6753
6801
|
map.push(i);
|
|
6754
6802
|
i++;
|
|
6755
6803
|
}
|
|
6756
6804
|
map.push(raw.length);
|
|
6757
|
-
return { text:
|
|
6805
|
+
return { text: text3, map };
|
|
6758
6806
|
}
|
|
6759
|
-
function encodeText(
|
|
6807
|
+
function encodeText(text3, keepNbsp, allBraces = false) {
|
|
6760
6808
|
let out = "";
|
|
6761
|
-
for (let k = 0; k <
|
|
6762
|
-
const ch =
|
|
6763
|
-
const next =
|
|
6809
|
+
for (let k = 0; k < text3.length; k++) {
|
|
6810
|
+
const ch = text3[k] ?? "";
|
|
6811
|
+
const next = text3[k + 1];
|
|
6764
6812
|
if (ch === "&") out += "&";
|
|
6765
6813
|
else if (ch === "<") out += "<";
|
|
6766
6814
|
else if (ch === ">") out += ">";
|
|
@@ -6772,8 +6820,8 @@ function encodeText(text2, keepNbsp, allBraces = false) {
|
|
|
6772
6820
|
}
|
|
6773
6821
|
return out;
|
|
6774
6822
|
}
|
|
6775
|
-
function encodeTemplateText(
|
|
6776
|
-
return encodeText(
|
|
6823
|
+
function encodeTemplateText(text3) {
|
|
6824
|
+
return encodeText(text3, true);
|
|
6777
6825
|
}
|
|
6778
6826
|
function spanOf(part) {
|
|
6779
6827
|
return part ? [part.start, part.end] : [0, 0];
|
|
@@ -6807,7 +6855,7 @@ function rewriteSegment(source, segStart, segEnd, parts, next, breakSpelling) {
|
|
|
6807
6855
|
const to = map[old.length - suffix] ?? segEnd;
|
|
6808
6856
|
const middle = next.slice(prefix, next.length - suffix);
|
|
6809
6857
|
const keepNbsp = old.slice(prefix, old.length - suffix).includes(NBSP);
|
|
6810
|
-
const written = middle.split(BREAK).map((
|
|
6858
|
+
const written = middle.split(BREAK).map((text3) => encodeText(text3, keepNbsp)).join(breakSpelling);
|
|
6811
6859
|
return source.slice(segStart, from) + written + source.slice(to, segEnd);
|
|
6812
6860
|
}
|
|
6813
6861
|
var isHighSurrogate = (code) => code >= 55296 && code <= 56319;
|
|
@@ -6836,10 +6884,10 @@ var editAttribute = "data-ff-edit";
|
|
|
6836
6884
|
function parseSourceAttribute(value) {
|
|
6837
6885
|
const match = /^(body|header|footer):(\d+):(\d+)$/.exec(value ?? "");
|
|
6838
6886
|
if (!match) return null;
|
|
6839
|
-
const
|
|
6887
|
+
const line2 = Number(match[2]);
|
|
6840
6888
|
const column = Number(match[3]);
|
|
6841
|
-
if (
|
|
6842
|
-
return { file: match[1], line, column };
|
|
6889
|
+
if (line2 < 1 || column < 1) return null;
|
|
6890
|
+
return { file: match[1], line: line2, column };
|
|
6843
6891
|
}
|
|
6844
6892
|
function annotateSourcePositions(source, engine, file, options = {}) {
|
|
6845
6893
|
const scanner = new Scanner(source, engine);
|
|
@@ -6886,12 +6934,12 @@ function annotateSourcePositions(source, engine, file, options = {}) {
|
|
|
6886
6934
|
const after = source[nameEnd];
|
|
6887
6935
|
const plainName = after === void 0 || after === ">" || after === "/" || /\s/.test(after);
|
|
6888
6936
|
if (plainName && !source.slice(nameEnd, end).toLowerCase().includes(sourceAttribute)) {
|
|
6889
|
-
const { line, column } = locate(lines, i);
|
|
6937
|
+
const { line: line2, column } = locate(lines, i);
|
|
6890
6938
|
const region = options.editable ? editableRegionAt(source, engine, i) : null;
|
|
6891
6939
|
const edit = region && !("reason" in region) ? ` ${editAttribute}="${region.kind}"` : "";
|
|
6892
6940
|
out.push(
|
|
6893
6941
|
source.slice(copied, nameEnd),
|
|
6894
|
-
` ${sourceAttribute}="${file}:${
|
|
6942
|
+
` ${sourceAttribute}="${file}:${line2}:${column}"${edit}`
|
|
6895
6943
|
);
|
|
6896
6944
|
copied = nameEnd;
|
|
6897
6945
|
}
|
|
@@ -7011,8 +7059,8 @@ function parseDesign(value) {
|
|
|
7011
7059
|
let guides;
|
|
7012
7060
|
const g = v["guides"];
|
|
7013
7061
|
if (g && typeof g === "object") {
|
|
7014
|
-
const
|
|
7015
|
-
guides = { x:
|
|
7062
|
+
const list3 = (x) => (Array.isArray(x) ? x : []).filter((n) => typeof n === "number" && Number.isFinite(n)).slice(0, 100);
|
|
7063
|
+
guides = { x: list3(g["x"]), y: list3(g["y"]) };
|
|
7016
7064
|
}
|
|
7017
7065
|
if (problems.length) return { design: null, problems };
|
|
7018
7066
|
return {
|
|
@@ -7562,11 +7610,11 @@ function googleFontsUrl(uses) {
|
|
|
7562
7610
|
|
|
7563
7611
|
// packages/engine/src/lib/design/hash.ts
|
|
7564
7612
|
function designOutputHash(html, css2) {
|
|
7565
|
-
const
|
|
7613
|
+
const text3 = `${html}\0${css2}`;
|
|
7566
7614
|
let a = 2166136261;
|
|
7567
7615
|
let b = 16777619 ^ 2654435769;
|
|
7568
|
-
for (let i = 0; i <
|
|
7569
|
-
const code =
|
|
7616
|
+
for (let i = 0; i < text3.length; i++) {
|
|
7617
|
+
const code = text3.charCodeAt(i);
|
|
7570
7618
|
if (code === 13) continue;
|
|
7571
7619
|
a = Math.imul(a ^ code, 16777619) >>> 0;
|
|
7572
7620
|
b = Math.imul(b ^ code, 16777619) >>> 0;
|
|
@@ -7676,7 +7724,7 @@ var tokenPattern2 = /^[a-z][a-z0-9-]{0,31}$/;
|
|
|
7676
7724
|
function emitDesign(design2, engine, size) {
|
|
7677
7725
|
const lines = ['<div class="ff-design">'];
|
|
7678
7726
|
const map = {};
|
|
7679
|
-
const
|
|
7727
|
+
const rules2 = [];
|
|
7680
7728
|
for (const layer of design2.layers) {
|
|
7681
7729
|
if (!layer.visible) continue;
|
|
7682
7730
|
const markup = layerHtml(layer, engine);
|
|
@@ -7684,7 +7732,7 @@ function emitDesign(design2, engine, size) {
|
|
|
7684
7732
|
` ${layer.showWhen?.path ? ifBlock(engine, layer.showWhen.path, markup) : markup}`
|
|
7685
7733
|
);
|
|
7686
7734
|
map[layer.id] = { start: lines.length, end: lines.length };
|
|
7687
|
-
|
|
7735
|
+
rules2.push(...layerCss(layer));
|
|
7688
7736
|
}
|
|
7689
7737
|
lines.push("</div>");
|
|
7690
7738
|
const html = `${lines.join("\n")}
|
|
@@ -7709,7 +7757,7 @@ function emitDesign(design2, engine, size) {
|
|
|
7709
7757
|
})} }`,
|
|
7710
7758
|
".ff-layer { position: absolute; box-sizing: border-box; margin: 0; }"
|
|
7711
7759
|
];
|
|
7712
|
-
const css2 = `${[...head, ...
|
|
7760
|
+
const css2 = `${[...head, ...rules2].join("\n")}
|
|
7713
7761
|
`;
|
|
7714
7762
|
return { html, css: css2, map, output: designOutputHash(html, css2) };
|
|
7715
7763
|
}
|
|
@@ -7793,32 +7841,32 @@ function imageSource(source, engine) {
|
|
|
7793
7841
|
return `{{ brand.logo.${source.brandLogo} }}`;
|
|
7794
7842
|
}
|
|
7795
7843
|
function layerCss(layer) {
|
|
7796
|
-
const
|
|
7844
|
+
const text3 = layer.type === "text" ? layer : null;
|
|
7797
7845
|
const box = {
|
|
7798
7846
|
left: px(layer.x),
|
|
7799
7847
|
top: px(layer.y),
|
|
7800
7848
|
width: px(layer.width),
|
|
7801
|
-
height:
|
|
7849
|
+
height: text3?.sizing === "grow" ? void 0 : px(layer.height),
|
|
7802
7850
|
opacity: layer.opacity < 1 ? num(layer.opacity) : void 0,
|
|
7803
7851
|
transform: layer.rotation ? `rotate(${num(layer.rotation)}deg)` : void 0,
|
|
7804
7852
|
"border-radius": layer.type === "shape" && layer.shape === "ellipse" ? "50%" : layer.radius ? px(layer.radius) : void 0,
|
|
7805
7853
|
border: layer.stroke && layer.stroke.width > 0 ? `${px(layer.stroke.width)} solid ${paint(layer.stroke.paint)}` : void 0,
|
|
7806
|
-
"box-shadow": layer.shadow && !
|
|
7854
|
+
"box-shadow": layer.shadow && !text3 ? shadow(layer.shadow) : void 0
|
|
7807
7855
|
};
|
|
7808
|
-
if (
|
|
7856
|
+
if (text3) {
|
|
7809
7857
|
Object.assign(box, {
|
|
7810
7858
|
display: "flex",
|
|
7811
7859
|
"flex-direction": "column",
|
|
7812
|
-
"justify-content":
|
|
7813
|
-
overflow:
|
|
7814
|
-
padding:
|
|
7815
|
-
background:
|
|
7860
|
+
"justify-content": text3.valign === "middle" ? "center" : text3.valign === "bottom" ? "flex-end" : "flex-start",
|
|
7861
|
+
overflow: text3.sizing === "grow" ? void 0 : "hidden",
|
|
7862
|
+
padding: text3.padding ? px(text3.padding) : void 0,
|
|
7863
|
+
background: text3.fill ? paint(text3.fill) : void 0
|
|
7816
7864
|
});
|
|
7817
|
-
const s =
|
|
7818
|
-
const clamp =
|
|
7865
|
+
const s = text3.style;
|
|
7866
|
+
const clamp = text3.maxLines ? {
|
|
7819
7867
|
display: "-webkit-box",
|
|
7820
7868
|
"-webkit-box-orient": "vertical",
|
|
7821
|
-
"-webkit-line-clamp": String(
|
|
7869
|
+
"-webkit-line-clamp": String(text3.maxLines),
|
|
7822
7870
|
overflow: "hidden"
|
|
7823
7871
|
} : {};
|
|
7824
7872
|
const inner = decl({
|
|
@@ -7834,7 +7882,7 @@ function layerCss(layer) {
|
|
|
7834
7882
|
"font-style": s.italic ? "italic" : void 0,
|
|
7835
7883
|
"text-transform": s.uppercase ? "uppercase" : void 0,
|
|
7836
7884
|
"text-decoration": [s.underline && "underline", s.strike && "line-through"].filter(Boolean).join(" ") || void 0,
|
|
7837
|
-
"text-shadow":
|
|
7885
|
+
"text-shadow": text3.shadow ? shadow(text3.shadow) : void 0,
|
|
7838
7886
|
"overflow-wrap": "break-word",
|
|
7839
7887
|
...clamp
|
|
7840
7888
|
});
|
|
@@ -8173,6 +8221,2131 @@ var designStarters = [
|
|
|
8173
8221
|
}
|
|
8174
8222
|
];
|
|
8175
8223
|
|
|
8224
|
+
// packages/engine/src/lib/einvoice/codes.generated.ts
|
|
8225
|
+
var list2 = (codes) => new Set(codes.split(" "));
|
|
8226
|
+
var CODE_LIST_RELEASE = "1.09.2";
|
|
8227
|
+
var documentTypeCodes = list2(
|
|
8228
|
+
"71 80 81 82 83 84 102 130 202 203 204 211 218 219 261 262 295 296 308 325 326 331 380 381 382 383 384 385 386 387 388 389 390 393 394 395 396 420 456 457 458 471 472 473 500 501 502 503 527 532 553 575 623 633 751 780 817 870 875 876 877 935"
|
|
8229
|
+
);
|
|
8230
|
+
var countryCodes = list2(
|
|
8231
|
+
"1A AD AE AF AG AI AL AM AO AQ AR AS AT AU AW AX AZ BA BB BD BE BF BG BH BI BJ BL BM BN BO BQ BR BS BT BV BW BY BZ CA CC CD CF CG CH CI CK CL CM CN CO CR CU CV CW CX CY CZ DE DJ DK DM DO DZ EC EE EG EH ER ES ET FI FJ FK FM FO FR GA GB GD GE GF GG GH GI GL GM GN GP GQ GR GS GT GU GW GY HK HM HN HR HT HU ID IE IL IM IN IO IQ IR IS IT JE JM JO JP KE KG KH KI KM KN KP KR KW KY KZ LA LB LC LI LK LR LS LT LU LV LY MA MC MD ME MF MG MH MK ML MM MN MO MP MQ MR MS MT MU MV MW MX MY MZ NA NC NE NF NG NI NL NO NP NR NU NZ OM PA PE PF PG PH PK PL PM PN PR PS PT PW PY QA RE RO RS RU RW SA SB SC SD SE SG SH SI SJ SK SL SM SN SO SR SS ST SV SX SY SZ TC TD TF TG TH TJ TK TL TM TN TO TR TT TV TW TZ UA UG UM US UY UZ VA VC VE VG VI VN VU WF WS XI YE YT ZA ZM ZW 1A XI"
|
|
8232
|
+
);
|
|
8233
|
+
var unitCodes = list2(
|
|
8234
|
+
"10 11 13 14 15 20 21 22 23 24 25 27 28 33 34 35 37 38 40 41 56 57 58 59 60 61 74 77 80 81 85 87 89 91 1I 2A 2B 2C 2G 2H 2I 2J 2K 2L 2M 2N 2P 2Q 2R 2U 2X 2Y 2Z 3B 3C 4C 4G 4H 4K 4L 4M 4N 4O 4P 4Q 4R 4T 4U 4W 4X 5A 5B 5E 5J A10 A11 A12 A13 A14 A15 A16 A17 A18 A19 A2 A20 A21 A22 A23 A24 A26 A27 A28 A29 A3 A30 A31 A32 A33 A34 A35 A36 A37 A38 A39 A4 A40 A41 A42 A43 A44 A45 A47 A48 A49 A5 A53 A54 A55 A56 A59 A6 A68 A69 A7 A70 A71 A73 A74 A75 A76 A8 A84 A85 A86 A87 A88 A89 A9 A90 A91 A93 A94 A95 A96 A97 A98 A99 AA AB ACR ACT AD AE AH AI AK AL AMH AMP ANN APZ AQ AS ASM ASU ATM AWG AY AZ B1 B10 B11 B12 B13 B14 B15 B16 B17 B18 B19 B20 B21 B22 B23 B24 B25 B26 B27 B28 B29 B3 B30 B31 B32 B33 B34 B35 B4 B41 B42 B43 B44 B45 B46 B47 B48 B49 B50 B52 B53 B54 B55 B56 B57 B58 B59 B60 B61 B62 B63 B64 B66 B67 B68 B69 B7 B70 B71 B72 B73 B74 B75 B76 B77 B78 B79 B8 B80 B81 B82 B83 B84 B85 B86 B87 B88 B89 B90 B91 B92 B93 B94 B95 B96 B97 B98 B99 BAR BB BFT BHP BIL BLD BLL BP BPM BQL BTU BUA BUI C0 C10 C11 C12 C13 C14 C15 C16 C17 C18 C19 C20 C21 C22 C23 C24 C25 C26 C27 C28 C29 C3 C30 C31 C32 C33 C34 C35 C36 C37 C38 C39 C40 C41 C42 C43 C44 C45 C46 C47 C48 C49 C50 C51 C52 C53 C54 C55 C56 C57 C58 C59 C60 C61 C62 C63 C64 C65 C66 C67 C68 C69 C7 C70 C71 C72 C73 C74 C75 C76 C78 C79 C8 C80 C81 C82 C83 C84 C85 C86 C87 C88 C89 C9 C90 C91 C92 C93 C94 C95 C96 C97 C99 CCT CDL CEL CEN CG CGM CKG CLF CLT CMK CMQ CMT CNP CNT COU CTG CTM CTN CUR CWA CWI D03 D04 D1 D10 D11 D12 D13 D15 D16 D17 D18 D19 D2 D20 D21 D22 D23 D24 D25 D26 D27 D29 D30 D31 D32 D33 D34 D36 D41 D42 D43 D44 D45 D46 D47 D48 D49 D5 D50 D51 D52 D53 D54 D55 D56 D57 D58 D59 D6 D60 D61 D62 D63 D65 D68 D69 D73 D74 D77 D78 D80 D81 D82 D83 D85 D86 D87 D88 D89 D91 D93 D94 D95 DAA DAD DAY DB DBM DBW DD DEC DG DJ DLT DMA DMK DMO DMQ DMT DN DPC DPR DPT DRA DRI DRL DT DTN DWT DZN DZP E01 E07 E08 E09 E10 E12 E14 E15 E16 E17 E18 E19 E20 E21 E22 E23 E25 E27 E28 E30 E31 E32 E33 E34 E35 E36 E37 E38 E39 E4 E40 E41 E42 E43 E44 E45 E46 E47 E48 E49 E50 E51 E52 E53 E54 E55 E56 E57 E58 E59 E60 E61 E62 E63 E64 E65 E66 E67 E68 E69 E70 E71 E72 E73 E74 E75 E76 E77 E78 E79 E80 E81 E82 E83 E84 E85 E86 E87 E88 E89 E90 E91 E92 E93 E94 E95 E96 E97 E98 E99 EA EB EQ F01 F02 F03 F04 F05 F06 F07 F08 F10 F11 F12 F13 F14 F15 F16 F17 F18 F19 F20 F21 F22 F23 F24 F25 F26 F27 F28 F29 F30 F31 F32 F33 F34 F35 F36 F37 F38 F39 F40 F41 F42 F43 F44 F45 F46 F47 F48 F49 F50 F51 F52 F53 F54 F55 F56 F57 F58 F59 F60 F61 F62 F63 F64 F65 F66 F67 F68 F69 F70 F71 F72 F73 F74 F75 F76 F77 F78 F79 F80 F81 F82 F83 F84 F85 F86 F87 F88 F89 F90 F91 F92 F93 F94 F95 F96 F97 F98 F99 FAH FAR FBM FC FF FH FIT FL FNU FOT FP FR FS FTK FTQ G01 G04 G05 G06 G08 G09 G10 G11 G12 G13 G14 G15 G16 G17 G18 G19 G2 G20 G21 G23 G24 G25 G26 G27 G28 G29 G3 G30 G31 G32 G33 G34 G35 G36 G37 G38 G39 G40 G41 G42 G43 G44 G45 G46 G47 G48 G49 G50 G51 G52 G53 G54 G55 G56 G57 G58 G59 G60 G61 G62 G63 G64 G65 G66 G67 G68 G69 G70 G71 G72 G73 G74 G75 G76 G77 G78 G79 G80 G81 G82 G83 G84 G85 G86 G87 G88 G89 G90 G91 G92 G93 G94 G95 G96 G97 G98 G99 GB GBQ GDW GE GF GFI GGR GIA GIC GII GIP GJ GL GLD GLI GLL GM GO GP GQ GRM GRN GRO GV GWH H03 H04 H05 H06 H07 H08 H09 H10 H11 H12 H13 H14 H15 H16 H18 H19 H20 H21 H22 H23 H24 H25 H26 H27 H28 H29 H30 H31 H32 H33 H34 H35 H36 H37 H38 H39 H40 H41 H42 H43 H44 H45 H46 H47 H48 H49 H50 H51 H52 H53 H54 H55 H56 H57 H58 H59 H60 H61 H62 H63 H64 H65 H66 H67 H68 H69 H70 H71 H72 H73 H74 H75 H76 H77 H79 H80 H81 H82 H83 H84 H85 H87 H88 H89 H90 H91 H92 H93 H94 H95 H96 H98 H99 HA HAD HBA HBX HC HDW HEA HGM HH HIU HKM HLT HM HMO HMQ HMT HPA HTZ HUR HWE IA IE INH INK INQ ISD IU IUG IV J10 J12 J13 J14 J15 J16 J17 J18 J19 J2 J20 J21 J22 J23 J24 J25 J26 J27 J28 J29 J30 J31 J32 J33 J34 J35 J36 J38 J39 J40 J41 J42 J43 J44 J45 J46 J47 J48 J49 J50 J51 J52 J53 J54 J55 J56 J57 J58 J59 J60 J61 J62 J63 J64 J65 J66 J67 J68 J69 J70 J71 J72 J73 J74 J75 J76 J78 J79 J81 J82 J83 J84 J85 J87 J90 J91 J92 J93 J95 J96 J97 J98 J99 JE JK JM JNT JOU JPS JWL K1 K10 K11 K12 K13 K14 K15 K16 K17 K18 K19 K2 K20 K21 K22 K23 K26 K27 K28 K3 K30 K31 K32 K33 K34 K35 K36 K37 K38 K39 K40 K41 K42 K43 K45 K46 K47 K48 K49 K50 K51 K52 K53 K54 K55 K58 K59 K6 K60 K61 K62 K63 K64 K65 K66 K67 K68 K69 K70 K71 K73 K74 K75 K76 K77 K78 K79 K80 K81 K82 K83 K84 K85 K86 K87 K88 K89 K90 K91 K92 K93 K94 K95 K96 K97 K98 K99 KA KAT KB KBA KCC KDW KEL KGM KGS KHY KHZ KI KIC KIP KJ KJO KL KLK KLX KMA KMH KMK KMQ KMT KNI KNM KNS KNT KO KPA KPH KPO KPP KR KSD KSH KT KTN KUR KVA KVR KVT KW KWH KWN KWO KWS KWT KWY KX L10 L11 L12 L13 L14 L15 L16 L17 L18 L19 L2 L20 L21 L23 L24 L25 L26 L27 L28 L29 L30 L31 L32 L33 L34 L35 L36 L37 L38 L39 L40 L41 L42 L43 L44 L45 L46 L47 L48 L49 L50 L51 L52 L53 L54 L55 L56 L57 L58 L59 L60 L63 L64 L65 L66 L67 L68 L69 L70 L71 L72 L73 L74 L75 L76 L77 L78 L79 L80 L81 L82 L83 L84 L85 L86 L87 L88 L89 L90 L91 L92 L93 L94 L95 L96 L98 L99 LA LAC LBR LBT LD LEF LF LH LK LM LN LO LP LPA LR LS LTN LTR LUB LUM LUX LY M1 M10 M11 M12 M13 M14 M15 M16 M17 M18 M19 M20 M21 M22 M23 M24 M25 M26 M27 M29 M30 M31 M32 M33 M34 M35 M36 M37 M38 M39 M4 M40 M41 M42 M43 M44 M45 M46 M47 M48 M49 M5 M50 M51 M52 M53 M55 M56 M57 M58 M59 M60 M61 M62 M63 M64 M65 M66 M67 M68 M69 M7 M70 M71 M72 M73 M74 M75 M76 M77 M78 M79 M80 M81 M82 M83 M84 M85 M86 M87 M88 M89 M9 M90 M91 M92 M93 M94 M95 M96 M97 M98 M99 MAH MAL MAM MAR MAW MBE MBF MBR MC MCU MD MGM MHZ MIK MIL MIN MIO MIU MKD MKM MKW MLD MLT MMK MMQ MMT MND MNJ MON MPA MQD MQH MQM MQS MQW MRD MRM MRW MSK MTK MTQ MTR MTS MTZ MVA MWH N1 N10 N11 N12 N13 N14 N15 N16 N17 N18 N19 N20 N21 N22 N23 N24 N25 N26 N27 N28 N29 N3 N30 N31 N32 N33 N34 N35 N36 N37 N38 N39 N40 N41 N42 N43 N44 N45 N46 N47 N48 N49 N50 N51 N52 N53 N54 N55 N56 N57 N58 N59 N60 N61 N62 N63 N64 N65 N66 N67 N68 N69 N70 N71 N72 N73 N74 N75 N76 N77 N78 N79 N80 N81 N82 N83 N84 N85 N86 N87 N88 N89 N90 N91 N92 N93 N94 N95 N96 N97 N98 N99 NA NAR NCL NEW NF NIL NIU NL NM3 NMI NMP NPT NT NTU NU NX OA ODE ODG ODK ODM OHM ON ONZ OPM OT OZA OZI P1 P10 P11 P12 P13 P14 P15 P16 P17 P18 P19 P2 P20 P21 P22 P23 P24 P25 P26 P27 P28 P29 P30 P31 P32 P33 P34 P35 P36 P37 P38 P39 P40 P41 P42 P43 P44 P45 P46 P47 P48 P49 P5 P50 P51 P52 P53 P54 P55 P56 P57 P58 P59 P60 P61 P62 P63 P64 P65 P66 P67 P68 P69 P70 P71 P72 P73 P74 P75 P76 P77 P78 P79 P80 P81 P82 P83 P84 P85 P86 P87 P88 P89 P90 P91 P92 P93 P94 P95 P96 P97 P98 P99 PAL PD PFL PGL PI PLA PO PQ PR PS PTD PTI PTL PTN Q10 Q11 Q12 Q13 Q14 Q15 Q16 Q17 Q18 Q19 Q20 Q21 Q22 Q23 Q24 Q25 Q26 Q27 Q28 Q29 Q3 Q30 Q31 Q32 Q33 Q34 Q35 Q36 Q37 Q38 Q39 Q40 Q41 Q42 QA QAN QB QR QTD QTI QTL QTR R1 R9 RH RM ROM RP RPM RPS RT S3 S4 SAN SCO SCR SEC SET SG SIE SM3 SMI SQ SQR SR STC STI STK STL STN STW SW SX SYR T0 T3 TAH TAN TI TIC TIP TKM TMS TNE TP TPI TPR TQD TRL TST TTS U1 U2 UB UC VA VLT VP W2 WA WB WCD WE WEB WEE WG WHR WM WSD WTT X1 X1A X1B X1D X1F X1G X1W X2C X3A X3H X43 X44 X4A X4B X4C X4D X4F X4G X4H X5H X5L X5M X6H X6P X7A X7B X8A X8B X8C XAA XAB XAC XAD XAE XAF XAG XAH XAI XAJ XAL XAM XAP XAT XAV XB4 XBA XBB XBC XBD XBE XBF XBG XBH XBI XBJ XBK XBL XBM XBN XBO XBP XBQ XBR XBS XBT XBU XBV XBW XBX XBY XBZ XCA XCB XCC XCD XCE XCF XCG XCH XCI XCJ XCK XCL XCM XCN XCO XCP XCQ XCR XCS XCT XCU XCV XCW XCX XCY XCZ XDA XDB XDC XDG XDH XDI XDJ XDK XDL XDM XDN XDP XDR XDS XDT XDU XDV XDW XDX XDY XEC XED XEE XEF XEG XEH XEI XEN XFB XFC XFD XFE XFI XFL XFO XFP XFR XFT XFW XFX XGB XGI XGL XGR XGU XGY XGZ XHA XHB XHC XHG XHN XHR XIA XIB XIC XID XIE XIF XIG XIH XIK XIL XIN XIZ XJB XJC XJG XJR XJT XJY XKG XKI XLE XLG XLT XLU XLV XLZ XMA XMB XMC XME XMR XMS XMT XMW XMX XNA XNE XNF XNG XNS XNT XNU XNV XO1 XO2 XO3 XO4 XO5 XO6 XO7 XO8 XO9 XOA XOB XOC XOD XOE XOF XOG XOH XOI XOJ XOK XOL XOM XON XOP XOQ XOR XOS XOT XOU XOV XOW XOX XOY XOZ XP1 XP2 XP3 XP4 XPA XPB XPC XPD XPE XPF XPG XPH XPI XPJ XPK XPL XPN XPO XPP XPR XPT XPU XPV XPX XPY XPZ XQA XQB XQC XQD XQF XQG XQH XQJ XQK XQL XQM XQN XQP XQQ XQR XQS XRD XRG XRJ XRK XRL XRO XRT XRZ XSA XSB XSC XSD XSE XSH XSI XSK XSL XSM XSO XSP XSS XST XSU XSV XSW XSX XSY XSZ XT1 XTB XTC XTD XTE XTG XTI XTK XTL XTN XTO XTR XTS XTT XTU XTV XTW XTY XTZ XUC XUN XVA XVG XVI XVK XVL XVN XVO XVP XVQ XVR XVS XVY XWA XWB XWC XWD XWF XWG XWH XWJ XWK XWL XWM XWN XWP XWQ XWR XWS XWT XWU XWV XWW XWX XWY XWZ XXA XXB XXC XXD XXF XXG XXH XXJ XXK XYA XYB XYC XYD XYF XYG XYH XYJ XYK XYL XYM XYN XYP XYQ XYR XYS XYT XYV XYW XYX XYY XYZ XZA XZB XZC XZD XZF XZG XZH XZJ XZK XZL XZM XZN XZP XZQ XZR XZS XZT XZU XZV XZW XZX XZY XZZ YDK YDQ YRD Z11 Z9 ZP ZZ"
|
|
8235
|
+
);
|
|
8236
|
+
var electronicAddressSchemes = list2(
|
|
8237
|
+
"0002 0007 0009 0037 0060 0088 0096 0097 0106 0130 0135 0142 0147 0151 0154 0158 0170 0177 0183 0184 0188 0190 0191 0192 0193 0194 0195 0196 0198 0199 0200 0201 0202 0203 0204 0205 0208 0209 0210 0211 0212 0213 0215 0216 0217 0218 0221 0225 0230 0235 0240 0242 0244 0245 0246 0248 9910 9913 9914 9915 9918 9919 9920 9922 9923 9924 9925 9926 9927 9928 9929 9930 9931 9932 9933 9934 9935 9936 9937 9938 9939 9940 9941 9942 9943 9944 9945 9946 9947 9948 9949 9950 9951 9952 9953 9957 9959 AN AQ AS AU EM"
|
|
8238
|
+
);
|
|
8239
|
+
var currencyCodes = list2(
|
|
8240
|
+
"AED AFN ALL AMD AOA ARS AUD AWG AZN BAM BBD BDT BHD BIF BMD BND BOB BOV BRL BSD BTN BWP BYN BZD CAD CDF CHE CHF CHW CLF CLP CNH CNY COP COU CRC CUP CVE CZK DJF DKK DOP DZD EGP ERN ETB EUR FJD FKP GBP GEL GHS GIP GMD GNF GTQ GYD HKD HNL HTG HUF IDR ILS INR IQD IRR ISK JMD JOD JPY KES KGS KHR KMF KPW KRW KWD KYD KZT LAK LBP LKR LRD LSL LYD MAD MDL MGA MKD MMK MNT MOP MRU MUR MVR MWK MXN MXV MYR MZN NAD NGN NIO NOK NPR NZD OMR PAB PEN PGK PHP PKR PLN PYG QAR RON RSD RUB RWF SAR SBD SCR SDG SEK SGD SHP SLE SOS SRD SSP STN SVC SYP SZL THB TJS TMT TND TOP TRY TTD TWD TZS UAH UGX USD USN UYI UYU UYW UZS VED VES VND VUV WST XAF XAG XAU XBA XBB XBC XBD XCD XCG XDR XOF XPD XPF XPT XSU XTS XUA XXX YER ZAR ZMW ZWG"
|
|
8241
|
+
);
|
|
8242
|
+
var paymentMeansCodes = list2(
|
|
8243
|
+
"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 62 63 64 65 66 67 68 69 70 74 75 76 77 78 91 92 93 94 95 96 97 98 ZZZ"
|
|
8244
|
+
);
|
|
8245
|
+
|
|
8246
|
+
// packages/engine/src/lib/einvoice/decimal.ts
|
|
8247
|
+
function decimalText(value) {
|
|
8248
|
+
if (typeof value === "string") {
|
|
8249
|
+
const text4 = value.trim();
|
|
8250
|
+
return /^-?\d+(\.\d+)?$/.test(text4) ? trimZeros(text4) : null;
|
|
8251
|
+
}
|
|
8252
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return null;
|
|
8253
|
+
const text3 = value.toPrecision(15);
|
|
8254
|
+
return /^-?\d+(\.\d+)?$/.test(text3) ? trimZeros(text3) : null;
|
|
8255
|
+
}
|
|
8256
|
+
function trimZeros(text3) {
|
|
8257
|
+
const trimmed = text3.includes(".") ? text3.replace(/0+$/, "").replace(/\.$/, "") : text3;
|
|
8258
|
+
return trimmed === "-0" ? "0" : trimmed;
|
|
8259
|
+
}
|
|
8260
|
+
function decimalPlaces(text3) {
|
|
8261
|
+
const dot = text3.indexOf(".");
|
|
8262
|
+
return dot === -1 ? 0 : text3.length - dot - 1;
|
|
8263
|
+
}
|
|
8264
|
+
function toUnits(text3, scale) {
|
|
8265
|
+
const negative = text3.startsWith("-");
|
|
8266
|
+
const [whole = "0", fraction = ""] = (negative ? text3.slice(1) : text3).split(
|
|
8267
|
+
"."
|
|
8268
|
+
);
|
|
8269
|
+
const units = BigInt(whole + fraction.padEnd(scale, "0").slice(0, scale));
|
|
8270
|
+
return negative ? -units : units;
|
|
8271
|
+
}
|
|
8272
|
+
function fromUnits(units, scale, places = scale) {
|
|
8273
|
+
const negative = units < 0n;
|
|
8274
|
+
const digits = (negative ? -units : units).toString().padStart(scale + 1, "0");
|
|
8275
|
+
const whole = digits.slice(0, digits.length - scale);
|
|
8276
|
+
const fraction = digits.slice(digits.length - scale).padEnd(places, "0");
|
|
8277
|
+
const text3 = places > 0 ? `${whole}.${fraction.slice(0, places)}` : whole;
|
|
8278
|
+
return negative && /[1-9]/.test(text3) ? `-${text3}` : text3;
|
|
8279
|
+
}
|
|
8280
|
+
function withPlaces(text3, min) {
|
|
8281
|
+
const places = decimalPlaces(text3);
|
|
8282
|
+
if (places >= min) return text3;
|
|
8283
|
+
return places === 0 ? `${text3}.${"0".repeat(min)}` : text3 + "0".repeat(min - places);
|
|
8284
|
+
}
|
|
8285
|
+
function divideRounded(value, divisor) {
|
|
8286
|
+
const negative = value < 0n !== divisor < 0n;
|
|
8287
|
+
const a = value < 0n ? -value : value;
|
|
8288
|
+
const b = divisor < 0n ? -divisor : divisor;
|
|
8289
|
+
const quotient = (a * 2n + b) / (b * 2n);
|
|
8290
|
+
return negative ? -quotient : quotient;
|
|
8291
|
+
}
|
|
8292
|
+
var abs = (value) => value < 0n ? -value : value;
|
|
8293
|
+
|
|
8294
|
+
// packages/engine/src/lib/einvoice/schema.ts
|
|
8295
|
+
var import_zod = require("zod");
|
|
8296
|
+
var numeric = import_zod.z.union([import_zod.z.number(), import_zod.z.string()]);
|
|
8297
|
+
var text2 = import_zod.z.string().trim().min(1);
|
|
8298
|
+
var isoDate2 = import_zod.z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "Expected a date as YYYY-MM-DD");
|
|
8299
|
+
var identifier2 = import_zod.z.union([
|
|
8300
|
+
text2,
|
|
8301
|
+
import_zod.z.object({ value: text2, scheme: text2.optional() })
|
|
8302
|
+
]);
|
|
8303
|
+
var address = import_zod.z.object({
|
|
8304
|
+
street: text2.optional(),
|
|
8305
|
+
street2: text2.optional(),
|
|
8306
|
+
street3: text2.optional(),
|
|
8307
|
+
postcode: text2.optional(),
|
|
8308
|
+
city: text2.optional(),
|
|
8309
|
+
/** ISO 3166-1 alpha-2 (BT-40, BT-55, BT-80). */
|
|
8310
|
+
country: text2,
|
|
8311
|
+
/** Region or province (BT-39, BT-54, BT-79). */
|
|
8312
|
+
subdivision: text2.optional()
|
|
8313
|
+
});
|
|
8314
|
+
var contact = import_zod.z.object({
|
|
8315
|
+
name: text2.optional(),
|
|
8316
|
+
phone: text2.optional(),
|
|
8317
|
+
email: text2.optional()
|
|
8318
|
+
});
|
|
8319
|
+
var party = import_zod.z.object({
|
|
8320
|
+
name: text2,
|
|
8321
|
+
/** The name the business trades under, where it differs (BT-28, BT-45). */
|
|
8322
|
+
trading_name: text2.optional(),
|
|
8323
|
+
/** An identifier of the party (BT-29, BT-46). */
|
|
8324
|
+
id: identifier2.optional(),
|
|
8325
|
+
/** The register entry (BT-30, BT-47): a SIREN, a company number. */
|
|
8326
|
+
legal_registration: identifier2.optional(),
|
|
8327
|
+
vat_id: text2.optional(),
|
|
8328
|
+
address,
|
|
8329
|
+
contact: contact.optional(),
|
|
8330
|
+
/** Where the party receives electronic invoices (BT-34, BT-49); a bare e-mail address is scheme EM. */
|
|
8331
|
+
electronic_address: identifier2.optional()
|
|
8332
|
+
});
|
|
8333
|
+
var period = import_zod.z.object({ start: isoDate2.optional(), end: isoDate2.optional() });
|
|
8334
|
+
var VAT_CATEGORIES = ["S", "Z", "E", "AE", "K", "G", "O"];
|
|
8335
|
+
var vatCategory = import_zod.z.enum(VAT_CATEGORIES);
|
|
8336
|
+
var lineTax = import_zod.z.object({
|
|
8337
|
+
category: vatCategory,
|
|
8338
|
+
/** Percent, `19` for 19 %. Left out for category O only. */
|
|
8339
|
+
rate: numeric.optional()
|
|
8340
|
+
});
|
|
8341
|
+
var allowanceOrCharge = import_zod.z.object({
|
|
8342
|
+
amount: numeric,
|
|
8343
|
+
reason: text2.optional(),
|
|
8344
|
+
/** UNTDID 5189 for an allowance, UNTDID 7161 for a charge. */
|
|
8345
|
+
reason_code: text2.optional(),
|
|
8346
|
+
base_amount: numeric.optional(),
|
|
8347
|
+
percent: numeric.optional()
|
|
8348
|
+
});
|
|
8349
|
+
var line = import_zod.z.object({
|
|
8350
|
+
id: import_zod.z.union([text2, import_zod.z.number()]),
|
|
8351
|
+
name: text2,
|
|
8352
|
+
description: text2.optional(),
|
|
8353
|
+
quantity: numeric,
|
|
8354
|
+
/** UN/ECE Recommendation 20: C62 a piece, HUR an hour, DAY a day, KGM a kilogram. */
|
|
8355
|
+
unit_code: text2.default("C62"),
|
|
8356
|
+
net_price: numeric,
|
|
8357
|
+
/** The quantity the price is for, where it is not one unit (BT-149). */
|
|
8358
|
+
price_base_quantity: numeric.optional(),
|
|
8359
|
+
net_amount: numeric,
|
|
8360
|
+
tax: lineTax,
|
|
8361
|
+
period: period.optional(),
|
|
8362
|
+
allowances: import_zod.z.array(allowanceOrCharge).optional(),
|
|
8363
|
+
charges: import_zod.z.array(allowanceOrCharge).optional(),
|
|
8364
|
+
buyer_accounting_reference: text2.optional(),
|
|
8365
|
+
note: text2.optional(),
|
|
8366
|
+
/** The seller's and the buyer's article numbers (BT-155, BT-156), a GTIN and the like (BT-157). */
|
|
8367
|
+
seller_item_id: text2.optional(),
|
|
8368
|
+
buyer_item_id: text2.optional(),
|
|
8369
|
+
standard_item_id: identifier2.optional(),
|
|
8370
|
+
/** The line of the buyer's order this one answers (BT-132). */
|
|
8371
|
+
order_line_reference: text2.optional()
|
|
8372
|
+
});
|
|
8373
|
+
var breakdown = import_zod.z.object({
|
|
8374
|
+
category: vatCategory,
|
|
8375
|
+
rate: numeric.optional(),
|
|
8376
|
+
basis: numeric,
|
|
8377
|
+
amount: numeric,
|
|
8378
|
+
exemption_reason: text2.optional(),
|
|
8379
|
+
/** A VATEX code (BT-121), for example VATEX-EU-AE for reverse charge. */
|
|
8380
|
+
exemption_reason_code: text2.optional()
|
|
8381
|
+
});
|
|
8382
|
+
var totals = import_zod.z.object({
|
|
8383
|
+
line_net: numeric,
|
|
8384
|
+
allowances: numeric.optional(),
|
|
8385
|
+
charges: numeric.optional(),
|
|
8386
|
+
tax_basis: numeric,
|
|
8387
|
+
tax_total: numeric,
|
|
8388
|
+
/** The VAT total in the accounting currency (BT-111). */
|
|
8389
|
+
tax_total_accounting: numeric.optional(),
|
|
8390
|
+
grand: numeric,
|
|
8391
|
+
prepaid: numeric.optional(),
|
|
8392
|
+
rounding: numeric.optional(),
|
|
8393
|
+
due: numeric
|
|
8394
|
+
});
|
|
8395
|
+
var payment = import_zod.z.object({
|
|
8396
|
+
/** UNTDID 4461: 58 SEPA credit transfer, 59 SEPA direct debit, 30 credit transfer, 48 card. */
|
|
8397
|
+
means_code: import_zod.z.union([text2, import_zod.z.number()]).optional(),
|
|
8398
|
+
iban: text2.optional(),
|
|
8399
|
+
bic: text2.optional(),
|
|
8400
|
+
account_name: text2.optional(),
|
|
8401
|
+
/** What the payer quotes with the payment (BT-83). */
|
|
8402
|
+
reference: text2.optional(),
|
|
8403
|
+
terms: text2.optional(),
|
|
8404
|
+
due_date: isoDate2.optional(),
|
|
8405
|
+
/** Direct debit: the mandate (BT-89), the creditor's identifier (BT-90), the account debited (BT-91). */
|
|
8406
|
+
mandate_id: text2.optional(),
|
|
8407
|
+
creditor_id: text2.optional(),
|
|
8408
|
+
debited_iban: text2.optional()
|
|
8409
|
+
});
|
|
8410
|
+
var note = import_zod.z.object({
|
|
8411
|
+
text: text2,
|
|
8412
|
+
/** UNTDID 4451, which French invoices use for their statutory mentions (PMT, PMD, AAB). */
|
|
8413
|
+
subject_code: text2.optional()
|
|
8414
|
+
});
|
|
8415
|
+
var invoiceSchema = import_zod.z.object({
|
|
8416
|
+
number: text2,
|
|
8417
|
+
issue_date: isoDate2,
|
|
8418
|
+
/** UNTDID 1001: 380 invoice, 381 credit note, 384 corrected invoice, 389 self-billed. */
|
|
8419
|
+
type_code: import_zod.z.union([text2, import_zod.z.number()]).default("380"),
|
|
8420
|
+
currency: text2,
|
|
8421
|
+
/** The currency the VAT is accounted in, where the invoice is in another (BT-6); goes with `totals.tax_total_accounting`. */
|
|
8422
|
+
accounting_currency: text2.optional(),
|
|
8423
|
+
/** The buyer's routing reference (BT-10); a German authority's Leitweg-ID goes here. */
|
|
8424
|
+
buyer_reference: text2.optional(),
|
|
8425
|
+
order_reference: text2.optional(),
|
|
8426
|
+
contract_reference: text2.optional(),
|
|
8427
|
+
note: text2.optional(),
|
|
8428
|
+
notes: import_zod.z.array(note).optional(),
|
|
8429
|
+
period: period.optional(),
|
|
8430
|
+
/** The invoices a credit note or a correction refers to (BG-3). */
|
|
8431
|
+
preceding_invoices: import_zod.z.array(import_zod.z.object({ number: text2, issue_date: isoDate2.optional() })).optional(),
|
|
8432
|
+
/** France (spec 17 §4.4): what was sold, and the billing framework's code where the plain case does not fit. */
|
|
8433
|
+
operation: import_zod.z.enum(["goods", "services", "mixed"]).optional(),
|
|
8434
|
+
operation_code: text2.optional(),
|
|
8435
|
+
seller: party.extend({
|
|
8436
|
+
tax_number: text2.optional(),
|
|
8437
|
+
/** Further legal information the invoice must state (BT-33): register court, capital. */
|
|
8438
|
+
legal_info: text2.optional(),
|
|
8439
|
+
/** France: VAT is owed when the invoice is issued, not when it is paid. */
|
|
8440
|
+
vat_on_debits: import_zod.z.boolean().optional()
|
|
8441
|
+
}),
|
|
8442
|
+
buyer: party.extend({
|
|
8443
|
+
/** France: the buyer's SIREN, nine digits. */
|
|
8444
|
+
siren: text2.optional()
|
|
8445
|
+
}),
|
|
8446
|
+
delivery: import_zod.z.object({
|
|
8447
|
+
name: text2.optional(),
|
|
8448
|
+
date: isoDate2.optional(),
|
|
8449
|
+
address: address.optional()
|
|
8450
|
+
}).optional(),
|
|
8451
|
+
lines: import_zod.z.array(line).min(1),
|
|
8452
|
+
/** Allowances and charges on the whole document (BG-20, BG-21), each with the VAT it falls under. */
|
|
8453
|
+
allowances: import_zod.z.array(allowanceOrCharge.extend({ tax: lineTax })).optional(),
|
|
8454
|
+
charges: import_zod.z.array(allowanceOrCharge.extend({ tax: lineTax })).optional(),
|
|
8455
|
+
tax: import_zod.z.object({ breakdown: import_zod.z.array(breakdown).min(1) }),
|
|
8456
|
+
totals,
|
|
8457
|
+
payment: payment.optional()
|
|
8458
|
+
});
|
|
8459
|
+
var EINVOICE_PROFILES = ["basic", "en16931"];
|
|
8460
|
+
var EINVOICE_FLAVOURS = ["factur-x", "zugferd"];
|
|
8461
|
+
var einvoiceOptionsSchema = import_zod.z.object({
|
|
8462
|
+
profile: import_zod.z.string().optional(),
|
|
8463
|
+
flavour: import_zod.z.string().optional(),
|
|
8464
|
+
xml: import_zod.z.enum(["embedded", "both"]).optional(),
|
|
8465
|
+
display_check: import_zod.z.enum(["warn", "strict"]).optional()
|
|
8466
|
+
}).strict();
|
|
8467
|
+
var defaultEinvoiceOptions = {
|
|
8468
|
+
profile: "en16931",
|
|
8469
|
+
flavour: "factur-x",
|
|
8470
|
+
xml: "embedded",
|
|
8471
|
+
display_check: "warn"
|
|
8472
|
+
};
|
|
8473
|
+
var knownUnsupported = {
|
|
8474
|
+
minimum: "MINIMUM carries no invoice lines and is not an invoice on its own; use basic or en16931",
|
|
8475
|
+
"basic-wl": "BASIC WL carries no invoice lines and is not an invoice on its own; use basic or en16931",
|
|
8476
|
+
basicwl: "BASIC WL carries no invoice lines and is not an invoice on its own; use basic or en16931",
|
|
8477
|
+
extended: "EXTENDED is not offered; use en16931, which carries the full European standard",
|
|
8478
|
+
xrechnung: "XRechnung is not offered yet; use en16931"
|
|
8479
|
+
};
|
|
8480
|
+
function resolveEinvoiceOptions(...layers) {
|
|
8481
|
+
let merged = null;
|
|
8482
|
+
for (const layer of layers) {
|
|
8483
|
+
if (layer === false) merged = null;
|
|
8484
|
+
else if (layer) merged = { ...merged ?? {}, ...definedOnly(layer) };
|
|
8485
|
+
}
|
|
8486
|
+
if (!merged) return { ok: true, options: null };
|
|
8487
|
+
const profile = (merged.profile ?? defaultEinvoiceOptions.profile).trim().toLowerCase();
|
|
8488
|
+
const flavour = (merged.flavour ?? defaultEinvoiceOptions.flavour).trim().toLowerCase();
|
|
8489
|
+
if (!EINVOICE_PROFILES.includes(profile))
|
|
8490
|
+
return {
|
|
8491
|
+
ok: false,
|
|
8492
|
+
field: "profile",
|
|
8493
|
+
value: profile,
|
|
8494
|
+
reason: knownUnsupported[profile] ?? `Unknown profile; use ${EINVOICE_PROFILES.join(" or ")}`
|
|
8495
|
+
};
|
|
8496
|
+
if (!EINVOICE_FLAVOURS.includes(flavour))
|
|
8497
|
+
return {
|
|
8498
|
+
ok: false,
|
|
8499
|
+
field: "flavour",
|
|
8500
|
+
value: flavour,
|
|
8501
|
+
reason: `Unknown flavour; use ${EINVOICE_FLAVOURS.join(" or ")}`
|
|
8502
|
+
};
|
|
8503
|
+
return {
|
|
8504
|
+
ok: true,
|
|
8505
|
+
options: {
|
|
8506
|
+
profile,
|
|
8507
|
+
flavour,
|
|
8508
|
+
xml: merged.xml ?? defaultEinvoiceOptions.xml,
|
|
8509
|
+
display_check: merged.display_check ?? defaultEinvoiceOptions.display_check
|
|
8510
|
+
}
|
|
8511
|
+
};
|
|
8512
|
+
}
|
|
8513
|
+
function definedOnly(layer) {
|
|
8514
|
+
return Object.fromEntries(
|
|
8515
|
+
Object.entries(layer).filter(([, value]) => value !== void 0)
|
|
8516
|
+
);
|
|
8517
|
+
}
|
|
8518
|
+
|
|
8519
|
+
// packages/engine/src/lib/einvoice/check.ts
|
|
8520
|
+
var REQUIRED = {
|
|
8521
|
+
number: ["BR-02", "BT-1"],
|
|
8522
|
+
issue_date: ["BR-03", "BT-2"],
|
|
8523
|
+
currency: ["BR-05", "BT-5"],
|
|
8524
|
+
seller: ["BR-06", "BG-4"],
|
|
8525
|
+
"seller.name": ["BR-06", "BT-27"],
|
|
8526
|
+
"seller.address": ["BR-08", "BG-5"],
|
|
8527
|
+
"seller.address.country": ["BR-09", "BT-40"],
|
|
8528
|
+
buyer: ["BR-07", "BG-7"],
|
|
8529
|
+
"buyer.name": ["BR-07", "BT-44"],
|
|
8530
|
+
"buyer.address": ["BR-10", "BG-8"],
|
|
8531
|
+
"buyer.address.country": ["BR-11", "BT-55"],
|
|
8532
|
+
lines: ["BR-16", "BG-25"],
|
|
8533
|
+
"lines[].id": ["BR-21", "BT-126"],
|
|
8534
|
+
"lines[].quantity": ["BR-22", "BT-129"],
|
|
8535
|
+
"lines[].net_amount": ["BR-24", "BT-131"],
|
|
8536
|
+
"lines[].name": ["BR-25", "BT-153"],
|
|
8537
|
+
"lines[].net_price": ["BR-26", "BT-146"],
|
|
8538
|
+
"lines[].tax": ["BR-CO-04", "BT-151"],
|
|
8539
|
+
"lines[].tax.category": ["BR-CO-04", "BT-151"],
|
|
8540
|
+
tax: ["BR-CO-18", "BG-23"],
|
|
8541
|
+
"tax.breakdown": ["BR-CO-18", "BG-23"],
|
|
8542
|
+
"tax.breakdown[].basis": ["BR-45", "BT-116"],
|
|
8543
|
+
"tax.breakdown[].amount": ["BR-46", "BT-117"],
|
|
8544
|
+
"tax.breakdown[].category": ["BR-47", "BT-118"],
|
|
8545
|
+
totals: ["BR-12", "BG-22"],
|
|
8546
|
+
"totals.line_net": ["BR-12", "BT-106"],
|
|
8547
|
+
"totals.tax_basis": ["BR-13", "BT-109"],
|
|
8548
|
+
"totals.tax_total": ["BR-CO-14", "BT-110"],
|
|
8549
|
+
"totals.grand": ["BR-14", "BT-112"],
|
|
8550
|
+
"totals.due": ["BR-15", "BT-115"],
|
|
8551
|
+
"allowances[].amount": ["BR-31", "BT-92"],
|
|
8552
|
+
"allowances[].tax": ["BR-32", "BT-95"],
|
|
8553
|
+
"allowances[].tax.category": ["BR-32", "BT-95"],
|
|
8554
|
+
"charges[].amount": ["BR-36", "BT-99"],
|
|
8555
|
+
"charges[].tax": ["BR-37", "BT-102"],
|
|
8556
|
+
"charges[].tax.category": ["BR-37", "BT-102"],
|
|
8557
|
+
"lines[].allowances[].amount": ["BR-41", "BT-136"],
|
|
8558
|
+
"lines[].charges[].amount": ["BR-43", "BT-141"],
|
|
8559
|
+
"delivery.address.country": ["BR-57", "BT-80"],
|
|
8560
|
+
"preceding_invoices[].number": ["BR-55", "BT-25"]
|
|
8561
|
+
};
|
|
8562
|
+
var RULE_PREFIX = {
|
|
8563
|
+
S: "BR-S",
|
|
8564
|
+
Z: "BR-Z",
|
|
8565
|
+
E: "BR-E",
|
|
8566
|
+
AE: "BR-AE",
|
|
8567
|
+
K: "BR-IC",
|
|
8568
|
+
G: "BR-G",
|
|
8569
|
+
O: "BR-O"
|
|
8570
|
+
};
|
|
8571
|
+
var UNIT_SUGGESTIONS = {
|
|
8572
|
+
piece: "C62",
|
|
8573
|
+
pieces: "C62",
|
|
8574
|
+
pcs: "C62",
|
|
8575
|
+
pc: "C62",
|
|
8576
|
+
stk: "C62",
|
|
8577
|
+
st\u00FCck: "C62",
|
|
8578
|
+
unit: "C62",
|
|
8579
|
+
units: "C62",
|
|
8580
|
+
each: "C62",
|
|
8581
|
+
hour: "HUR",
|
|
8582
|
+
hours: "HUR",
|
|
8583
|
+
h: "HUR",
|
|
8584
|
+
std: "HUR",
|
|
8585
|
+
stunde: "HUR",
|
|
8586
|
+
stunden: "HUR",
|
|
8587
|
+
day: "DAY",
|
|
8588
|
+
days: "DAY",
|
|
8589
|
+
tag: "DAY",
|
|
8590
|
+
tage: "DAY",
|
|
8591
|
+
month: "MON",
|
|
8592
|
+
months: "MON",
|
|
8593
|
+
monat: "MON",
|
|
8594
|
+
year: "ANN",
|
|
8595
|
+
min: "MIN",
|
|
8596
|
+
minute: "MIN",
|
|
8597
|
+
minutes: "MIN",
|
|
8598
|
+
kg: "KGM",
|
|
8599
|
+
g: "GRM",
|
|
8600
|
+
t: "TNE",
|
|
8601
|
+
l: "LTR",
|
|
8602
|
+
litre: "LTR",
|
|
8603
|
+
liter: "LTR",
|
|
8604
|
+
m: "MTR",
|
|
8605
|
+
km: "KMT",
|
|
8606
|
+
m2: "MTK",
|
|
8607
|
+
qm: "MTK",
|
|
8608
|
+
m3: "MTQ",
|
|
8609
|
+
kwh: "KWH",
|
|
8610
|
+
flat: "LS",
|
|
8611
|
+
pauschal: "LS"
|
|
8612
|
+
};
|
|
8613
|
+
var FRENCH_FRAMEWORKS = /* @__PURE__ */ new Set([
|
|
8614
|
+
"B1",
|
|
8615
|
+
"S1",
|
|
8616
|
+
"M1",
|
|
8617
|
+
"B2",
|
|
8618
|
+
"S2",
|
|
8619
|
+
"M2",
|
|
8620
|
+
"B4",
|
|
8621
|
+
"S4",
|
|
8622
|
+
"M4",
|
|
8623
|
+
"S5",
|
|
8624
|
+
"S6",
|
|
8625
|
+
"B7",
|
|
8626
|
+
"S7"
|
|
8627
|
+
]);
|
|
8628
|
+
var FRENCH_OPERATION = { goods: "B1", services: "S1", mixed: "M1" };
|
|
8629
|
+
var CREDIT_TRANSFER = /* @__PURE__ */ new Set(["30", "58"]);
|
|
8630
|
+
function checkInvoice(data, options = {}) {
|
|
8631
|
+
const problems = [];
|
|
8632
|
+
const add2 = (code, path, message, extra = {}) => {
|
|
8633
|
+
problems.push({
|
|
8634
|
+
code,
|
|
8635
|
+
path,
|
|
8636
|
+
...extra.rule ? { rule: extra.rule } : {},
|
|
8637
|
+
message: extra.rule ? `${message} (${extra.rule})` : message,
|
|
8638
|
+
args: {
|
|
8639
|
+
path,
|
|
8640
|
+
...extra.rule ? { rule: extra.rule } : {},
|
|
8641
|
+
...extra.args
|
|
8642
|
+
}
|
|
8643
|
+
});
|
|
8644
|
+
};
|
|
8645
|
+
const parsed = invoiceSchema.safeParse(data);
|
|
8646
|
+
if (!parsed.success) {
|
|
8647
|
+
for (const issue of parsed.error.issues) {
|
|
8648
|
+
const path = pathText(issue.path);
|
|
8649
|
+
const required = REQUIRED[path.replace(/\[\d+\]/g, "[]")];
|
|
8650
|
+
const absent = valueAt(data, issue.path) === void 0;
|
|
8651
|
+
if (absent && required)
|
|
8652
|
+
add2("missing", path, `_invoice.${path} is missing (${required[1]})`, {
|
|
8653
|
+
rule: required[0],
|
|
8654
|
+
args: { term: required[1] }
|
|
8655
|
+
});
|
|
8656
|
+
else if (absent) add2("missing", path, `_invoice.${path} is missing`);
|
|
8657
|
+
else if (issue.code === "too_small" && path === "lines")
|
|
8658
|
+
add2(
|
|
8659
|
+
"missing",
|
|
8660
|
+
path,
|
|
8661
|
+
"_invoice.lines is empty: an invoice has at least one line (BG-25)",
|
|
8662
|
+
{
|
|
8663
|
+
rule: "BR-16",
|
|
8664
|
+
args: { term: "BG-25" }
|
|
8665
|
+
}
|
|
8666
|
+
);
|
|
8667
|
+
else if (issue.code === "too_small" && path === "tax.breakdown")
|
|
8668
|
+
add2(
|
|
8669
|
+
"missing",
|
|
8670
|
+
path,
|
|
8671
|
+
"_invoice.tax.breakdown is empty: an invoice has at least one VAT breakdown (BG-23)",
|
|
8672
|
+
{
|
|
8673
|
+
rule: "BR-CO-18",
|
|
8674
|
+
args: { term: "BG-23" }
|
|
8675
|
+
}
|
|
8676
|
+
);
|
|
8677
|
+
else
|
|
8678
|
+
add2("invalid", path, `_invoice.${path}: ${issue.message}`, {
|
|
8679
|
+
args: { detail: issue.message }
|
|
8680
|
+
});
|
|
8681
|
+
}
|
|
8682
|
+
return { ok: false, invoice: null, problems };
|
|
8683
|
+
}
|
|
8684
|
+
const invoice = normalise(parsed.data, add2, options);
|
|
8685
|
+
if (problems.length > 0) return { ok: false, invoice: null, problems };
|
|
8686
|
+
rules(invoice, add2);
|
|
8687
|
+
return problems.length > 0 ? { ok: false, invoice: null, problems } : { ok: true, invoice, problems: [] };
|
|
8688
|
+
}
|
|
8689
|
+
function pathText(path) {
|
|
8690
|
+
let out = "";
|
|
8691
|
+
for (const key of path)
|
|
8692
|
+
out += typeof key === "number" ? `[${key}]` : out ? `.${String(key)}` : String(key);
|
|
8693
|
+
return out;
|
|
8694
|
+
}
|
|
8695
|
+
function valueAt(data, path) {
|
|
8696
|
+
let value = data;
|
|
8697
|
+
for (const key of path) {
|
|
8698
|
+
if (value === null || typeof value !== "object") return void 0;
|
|
8699
|
+
value = value[key];
|
|
8700
|
+
}
|
|
8701
|
+
return value === null ? void 0 : value;
|
|
8702
|
+
}
|
|
8703
|
+
function normalise(input, add2, options) {
|
|
8704
|
+
const amount2 = (value, path) => {
|
|
8705
|
+
const text3 = decimalText(value);
|
|
8706
|
+
if (text3 === null) {
|
|
8707
|
+
add2("not_a_number", path, `_invoice.${path} is not a number`);
|
|
8708
|
+
return "0";
|
|
8709
|
+
}
|
|
8710
|
+
if (decimalPlaces(text3) > 2) {
|
|
8711
|
+
add2(
|
|
8712
|
+
"decimals",
|
|
8713
|
+
path,
|
|
8714
|
+
`_invoice.${path} has more than 2 decimals; an amount of the invoice is exact to the cent`,
|
|
8715
|
+
{
|
|
8716
|
+
args: { max: 2, value: text3 }
|
|
8717
|
+
}
|
|
8718
|
+
);
|
|
8719
|
+
return "0";
|
|
8720
|
+
}
|
|
8721
|
+
return text3;
|
|
8722
|
+
};
|
|
8723
|
+
const number = (value, path, max2) => {
|
|
8724
|
+
const text3 = decimalText(value);
|
|
8725
|
+
if (text3 === null) {
|
|
8726
|
+
add2("not_a_number", path, `_invoice.${path} is not a number`);
|
|
8727
|
+
return "0";
|
|
8728
|
+
}
|
|
8729
|
+
if (decimalPlaces(text3) > max2) {
|
|
8730
|
+
add2("decimals", path, `_invoice.${path} has more than ${max2} decimals`, {
|
|
8731
|
+
args: { max: max2, value: text3 }
|
|
8732
|
+
});
|
|
8733
|
+
return "0";
|
|
8734
|
+
}
|
|
8735
|
+
return text3;
|
|
8736
|
+
};
|
|
8737
|
+
const optionalAmount = (value, path) => value === void 0 ? void 0 : amount2(value, path);
|
|
8738
|
+
const date2 = (value, path) => {
|
|
8739
|
+
if (value === void 0) return void 0;
|
|
8740
|
+
const [year = 0, month = 0, day = 0] = value.split("-").map(Number);
|
|
8741
|
+
const real = new Date(Date.UTC(year, month - 1, day));
|
|
8742
|
+
if (real.getUTCFullYear() !== year || real.getUTCMonth() !== month - 1 || real.getUTCDate() !== day) {
|
|
8743
|
+
add2("date", path, `_invoice.${path} is not a date of the calendar`, {
|
|
8744
|
+
args: { value }
|
|
8745
|
+
});
|
|
8746
|
+
}
|
|
8747
|
+
return value;
|
|
8748
|
+
};
|
|
8749
|
+
const code = (value, path, list3, name, rule2) => {
|
|
8750
|
+
const upper = value.trim().toUpperCase();
|
|
8751
|
+
if (!list3.has(upper))
|
|
8752
|
+
add2(
|
|
8753
|
+
"code_list",
|
|
8754
|
+
path,
|
|
8755
|
+
`_invoice.${path}: "${value}" is not a code of ${name}`,
|
|
8756
|
+
{
|
|
8757
|
+
rule: rule2,
|
|
8758
|
+
args: { value, list: name }
|
|
8759
|
+
}
|
|
8760
|
+
);
|
|
8761
|
+
return upper;
|
|
8762
|
+
};
|
|
8763
|
+
const period3 = (value, path, rule2) => {
|
|
8764
|
+
if (!value || value.start === void 0 && value.end === void 0)
|
|
8765
|
+
return void 0;
|
|
8766
|
+
const start = date2(value.start, `${path}.start`);
|
|
8767
|
+
const end = date2(value.end, `${path}.end`);
|
|
8768
|
+
if (start && end && end < start)
|
|
8769
|
+
add2("date_order", path, `_invoice.${path} ends before it starts`, {
|
|
8770
|
+
rule: rule2
|
|
8771
|
+
});
|
|
8772
|
+
return { ...start ? { start } : {}, ...end ? { end } : {} };
|
|
8773
|
+
};
|
|
8774
|
+
const identifier4 = (value) => {
|
|
8775
|
+
if (value === void 0) return void 0;
|
|
8776
|
+
if (typeof value === "string") return { value };
|
|
8777
|
+
return {
|
|
8778
|
+
value: value.value,
|
|
8779
|
+
...value.scheme ? { scheme: value.scheme } : {}
|
|
8780
|
+
};
|
|
8781
|
+
};
|
|
8782
|
+
const address3 = (value, path) => ({
|
|
8783
|
+
...defined({
|
|
8784
|
+
street: value.street,
|
|
8785
|
+
street2: value.street2,
|
|
8786
|
+
street3: value.street3,
|
|
8787
|
+
postcode: value.postcode,
|
|
8788
|
+
city: value.city,
|
|
8789
|
+
subdivision: value.subdivision
|
|
8790
|
+
}),
|
|
8791
|
+
country: code(
|
|
8792
|
+
value.country,
|
|
8793
|
+
`${path}.country`,
|
|
8794
|
+
countryCodes,
|
|
8795
|
+
"ISO 3166-1 (two letters, as in DE)",
|
|
8796
|
+
"BR-CL-14"
|
|
8797
|
+
)
|
|
8798
|
+
});
|
|
8799
|
+
const vatId = (value, path) => {
|
|
8800
|
+
if (value === void 0) return void 0;
|
|
8801
|
+
const id = value.replace(/\s/g, "").toUpperCase();
|
|
8802
|
+
const prefix = id.slice(0, 2);
|
|
8803
|
+
if (!(countryCodes.has(prefix) || prefix === "EL") || !/^[A-Z]{2}/.test(id))
|
|
8804
|
+
add2(
|
|
8805
|
+
"vat_id_prefix",
|
|
8806
|
+
path,
|
|
8807
|
+
`_invoice.${path} must start with the country code of the VAT ID, as in DE123456789`,
|
|
8808
|
+
{
|
|
8809
|
+
rule: "BR-CO-09",
|
|
8810
|
+
args: { value }
|
|
8811
|
+
}
|
|
8812
|
+
);
|
|
8813
|
+
return id;
|
|
8814
|
+
};
|
|
8815
|
+
const electronicAddress = (value, path, rule2) => {
|
|
8816
|
+
const id = identifier4(value);
|
|
8817
|
+
if (!id) return void 0;
|
|
8818
|
+
const scheme = id.scheme?.trim().toUpperCase() ?? (/^[^@\s]+@[^@\s]+$/.test(id.value) ? "EM" : void 0);
|
|
8819
|
+
if (!scheme) {
|
|
8820
|
+
add2(
|
|
8821
|
+
"scheme_required",
|
|
8822
|
+
path,
|
|
8823
|
+
`_invoice.${path} needs its scheme: write { "value": \u2026, "scheme": \u2026 } with a code of the EAS list, or an e-mail address`,
|
|
8824
|
+
{ rule: rule2 }
|
|
8825
|
+
);
|
|
8826
|
+
return void 0;
|
|
8827
|
+
}
|
|
8828
|
+
if (!electronicAddressSchemes.has(scheme))
|
|
8829
|
+
add2(
|
|
8830
|
+
"code_list",
|
|
8831
|
+
`${path}.scheme`,
|
|
8832
|
+
`_invoice.${path}.scheme: "${scheme}" is not a code of the EAS list (EM is an e-mail address)`,
|
|
8833
|
+
{
|
|
8834
|
+
rule: "BR-CL-25",
|
|
8835
|
+
args: { value: scheme, list: "the EAS list" }
|
|
8836
|
+
}
|
|
8837
|
+
);
|
|
8838
|
+
return { value: id.value, scheme };
|
|
8839
|
+
};
|
|
8840
|
+
const party3 = (value, path, addressRule) => {
|
|
8841
|
+
const id = identifier4(value.id);
|
|
8842
|
+
const registration = identifier4(value.legal_registration);
|
|
8843
|
+
const electronic = electronicAddress(
|
|
8844
|
+
value.electronic_address,
|
|
8845
|
+
`${path}.electronic_address`,
|
|
8846
|
+
addressRule
|
|
8847
|
+
);
|
|
8848
|
+
const vat = vatId(value.vat_id, `${path}.vat_id`);
|
|
8849
|
+
return {
|
|
8850
|
+
name: value.name,
|
|
8851
|
+
...defined({ trading_name: value.trading_name, vat_id: vat }),
|
|
8852
|
+
...id ? { id } : {},
|
|
8853
|
+
...registration ? { legal_registration: registration } : {},
|
|
8854
|
+
address: address3(value.address, `${path}.address`),
|
|
8855
|
+
...value.contact && Object.values(value.contact).some((v) => v !== void 0) ? { contact: defined(value.contact) } : {},
|
|
8856
|
+
...electronic ? { electronic_address: electronic } : {}
|
|
8857
|
+
};
|
|
8858
|
+
};
|
|
8859
|
+
const tax = (value, path) => ({
|
|
8860
|
+
category: value.category,
|
|
8861
|
+
...value.rate === void 0 || value.rate === null ? {} : { rate: number(value.rate, `${path}.rate`, 4) }
|
|
8862
|
+
});
|
|
8863
|
+
const allowance = (value, path) => ({
|
|
8864
|
+
amount: amount2(value.amount, `${path}.amount`),
|
|
8865
|
+
...defined({
|
|
8866
|
+
reason: value.reason,
|
|
8867
|
+
reason_code: value.reason_code?.trim().toUpperCase(),
|
|
8868
|
+
base_amount: optionalAmount(value.base_amount, `${path}.base_amount`),
|
|
8869
|
+
percent: value.percent === void 0 ? void 0 : number(value.percent, `${path}.percent`, 4)
|
|
8870
|
+
})
|
|
8871
|
+
});
|
|
8872
|
+
const seller = party3(input.seller, "seller", "BR-62");
|
|
8873
|
+
const buyer = party3(input.buyer, "buyer", "BR-63");
|
|
8874
|
+
if (input.buyer.siren !== void 0) {
|
|
8875
|
+
const siren = input.buyer.siren.replace(/\s/g, "");
|
|
8876
|
+
if (buyer.legal_registration && buyer.legal_registration.value.replace(/\s/g, "") !== siren)
|
|
8877
|
+
add2(
|
|
8878
|
+
"siren_mismatch",
|
|
8879
|
+
"buyer.siren",
|
|
8880
|
+
"_invoice.buyer.siren and _invoice.buyer.legal_registration name different registrations; state one of them"
|
|
8881
|
+
);
|
|
8882
|
+
else
|
|
8883
|
+
buyer.legal_registration = {
|
|
8884
|
+
value: siren,
|
|
8885
|
+
scheme: buyer.legal_registration?.scheme ?? "0002"
|
|
8886
|
+
};
|
|
8887
|
+
}
|
|
8888
|
+
const notes = [
|
|
8889
|
+
...input.note ? [{ text: input.note }] : [],
|
|
8890
|
+
...(input.notes ?? []).map((note2) => ({
|
|
8891
|
+
text: note2.text,
|
|
8892
|
+
...note2.subject_code ? { subject_code: note2.subject_code.trim().toUpperCase() } : {}
|
|
8893
|
+
}))
|
|
8894
|
+
];
|
|
8895
|
+
const delivery = input.delivery ? defined({
|
|
8896
|
+
name: input.delivery.name,
|
|
8897
|
+
date: date2(input.delivery.date, "delivery.date"),
|
|
8898
|
+
address: input.delivery.address ? address3(input.delivery.address, "delivery.address") : void 0
|
|
8899
|
+
}) : void 0;
|
|
8900
|
+
let businessProcess;
|
|
8901
|
+
if (input.operation_code !== void 0)
|
|
8902
|
+
businessProcess = input.operation_code.trim().toUpperCase();
|
|
8903
|
+
else if (input.operation !== void 0)
|
|
8904
|
+
businessProcess = FRENCH_OPERATION[input.operation];
|
|
8905
|
+
const payment2 = input.payment ? defined({
|
|
8906
|
+
means_code: input.payment.means_code === void 0 ? void 0 : code(
|
|
8907
|
+
String(input.payment.means_code),
|
|
8908
|
+
"payment.means_code",
|
|
8909
|
+
paymentMeansCodes,
|
|
8910
|
+
"UNTDID 4461 (58 is a SEPA credit transfer)",
|
|
8911
|
+
"BR-CL-16"
|
|
8912
|
+
),
|
|
8913
|
+
iban: iban(input.payment.iban, "payment.iban", add2),
|
|
8914
|
+
bic: input.payment.bic?.replace(/\s/g, "").toUpperCase(),
|
|
8915
|
+
account_name: input.payment.account_name,
|
|
8916
|
+
reference: input.payment.reference,
|
|
8917
|
+
terms: input.payment.terms,
|
|
8918
|
+
due_date: date2(input.payment.due_date, "payment.due_date"),
|
|
8919
|
+
mandate_id: input.payment.mandate_id,
|
|
8920
|
+
creditor_id: input.payment.creditor_id,
|
|
8921
|
+
debited_iban: iban(
|
|
8922
|
+
input.payment.debited_iban,
|
|
8923
|
+
"payment.debited_iban",
|
|
8924
|
+
add2
|
|
8925
|
+
)
|
|
8926
|
+
}) : void 0;
|
|
8927
|
+
const rounding = optionalAmount(input.totals.rounding, "totals.rounding");
|
|
8928
|
+
if (options.profile === "basic" && rounding !== void 0 && toUnits(rounding, 2) !== 0n)
|
|
8929
|
+
add2(
|
|
8930
|
+
"profile",
|
|
8931
|
+
"totals.rounding",
|
|
8932
|
+
"_invoice.totals.rounding cannot be carried by the profile basic, which has no rounding amount (BT-114); use en16931",
|
|
8933
|
+
{
|
|
8934
|
+
args: { profile: "basic", term: "BT-114" }
|
|
8935
|
+
}
|
|
8936
|
+
);
|
|
8937
|
+
return {
|
|
8938
|
+
number: input.number,
|
|
8939
|
+
issue_date: date2(input.issue_date, "issue_date") ?? input.issue_date,
|
|
8940
|
+
type_code: code(
|
|
8941
|
+
String(input.type_code),
|
|
8942
|
+
"type_code",
|
|
8943
|
+
documentTypeCodes,
|
|
8944
|
+
"UNTDID 1001 (380 is an invoice, 381 a credit note)",
|
|
8945
|
+
"BR-CL-01"
|
|
8946
|
+
),
|
|
8947
|
+
currency: code(
|
|
8948
|
+
input.currency,
|
|
8949
|
+
"currency",
|
|
8950
|
+
currencyCodes,
|
|
8951
|
+
"ISO 4217 (three letters, as in EUR)",
|
|
8952
|
+
"BR-CL-04"
|
|
8953
|
+
),
|
|
8954
|
+
...defined({
|
|
8955
|
+
accounting_currency: input.accounting_currency === void 0 ? void 0 : code(
|
|
8956
|
+
input.accounting_currency,
|
|
8957
|
+
"accounting_currency",
|
|
8958
|
+
currencyCodes,
|
|
8959
|
+
"ISO 4217 (three letters, as in EUR)",
|
|
8960
|
+
"BR-CL-05"
|
|
8961
|
+
),
|
|
8962
|
+
buyer_reference: input.buyer_reference,
|
|
8963
|
+
order_reference: input.order_reference,
|
|
8964
|
+
contract_reference: input.contract_reference,
|
|
8965
|
+
period: period3(input.period, "period", "BR-29"),
|
|
8966
|
+
business_process: businessProcess
|
|
8967
|
+
}),
|
|
8968
|
+
notes,
|
|
8969
|
+
preceding_invoices: (input.preceding_invoices ?? []).map(
|
|
8970
|
+
(reference, i) => ({
|
|
8971
|
+
number: reference.number,
|
|
8972
|
+
...defined({
|
|
8973
|
+
issue_date: date2(
|
|
8974
|
+
reference.issue_date,
|
|
8975
|
+
`preceding_invoices[${i}].issue_date`
|
|
8976
|
+
)
|
|
8977
|
+
})
|
|
8978
|
+
})
|
|
8979
|
+
),
|
|
8980
|
+
seller: {
|
|
8981
|
+
...seller,
|
|
8982
|
+
...defined({
|
|
8983
|
+
tax_number: input.seller.tax_number,
|
|
8984
|
+
legal_info: input.seller.legal_info,
|
|
8985
|
+
vat_on_debits: input.seller.vat_on_debits
|
|
8986
|
+
})
|
|
8987
|
+
},
|
|
8988
|
+
buyer,
|
|
8989
|
+
...delivery && Object.keys(delivery).length > 0 ? { delivery } : {},
|
|
8990
|
+
lines: input.lines.map((line2, i) => {
|
|
8991
|
+
const path = `lines[${i}]`;
|
|
8992
|
+
const unit = line2.unit_code.trim();
|
|
8993
|
+
const known = unitCodes.has(unit.toUpperCase()) || unitCodes.has(unit);
|
|
8994
|
+
if (!known) {
|
|
8995
|
+
const suggestion = UNIT_SUGGESTIONS[unit.toLowerCase()];
|
|
8996
|
+
add2(
|
|
8997
|
+
"code_list",
|
|
8998
|
+
`${path}.unit_code`,
|
|
8999
|
+
`_invoice.${path}.unit_code: "${unit}" is not a code of UN/ECE Recommendation 20${suggestion ? `; ${suggestion} is the code for it` : " (C62 is a piece, HUR an hour, DAY a day)"}`,
|
|
9000
|
+
{
|
|
9001
|
+
rule: "BR-CL-23",
|
|
9002
|
+
args: {
|
|
9003
|
+
value: unit,
|
|
9004
|
+
list: "UN/ECE Recommendation 20",
|
|
9005
|
+
...suggestion ? { suggestion } : {}
|
|
9006
|
+
}
|
|
9007
|
+
}
|
|
9008
|
+
);
|
|
9009
|
+
}
|
|
9010
|
+
const price = number(line2.net_price, `${path}.net_price`, 6);
|
|
9011
|
+
if (price.startsWith("-"))
|
|
9012
|
+
add2(
|
|
9013
|
+
"negative",
|
|
9014
|
+
`${path}.net_price`,
|
|
9015
|
+
`_invoice.${path}.net_price must not be negative; a credit is a negative quantity`,
|
|
9016
|
+
{ rule: "BR-27" }
|
|
9017
|
+
);
|
|
9018
|
+
const standard = identifier4(line2.standard_item_id);
|
|
9019
|
+
if (standard && !standard.scheme)
|
|
9020
|
+
add2(
|
|
9021
|
+
"scheme_required",
|
|
9022
|
+
`${path}.standard_item_id`,
|
|
9023
|
+
`_invoice.${path}.standard_item_id needs its scheme: write { "value": \u2026, "scheme": \u2026 }, 0160 for a GTIN`,
|
|
9024
|
+
{ rule: "BR-64" }
|
|
9025
|
+
);
|
|
9026
|
+
return {
|
|
9027
|
+
id: String(line2.id),
|
|
9028
|
+
name: line2.name,
|
|
9029
|
+
quantity: number(line2.quantity, `${path}.quantity`, 6),
|
|
9030
|
+
unit_code: unitCodes.has(unit) ? unit : unit.toUpperCase(),
|
|
9031
|
+
net_price: price,
|
|
9032
|
+
net_amount: amount2(line2.net_amount, `${path}.net_amount`),
|
|
9033
|
+
tax: tax(line2.tax, `${path}.tax`),
|
|
9034
|
+
allowances: (line2.allowances ?? []).map(
|
|
9035
|
+
(a, j) => allowance(a, `${path}.allowances[${j}]`)
|
|
9036
|
+
),
|
|
9037
|
+
charges: (line2.charges ?? []).map(
|
|
9038
|
+
(c, j) => allowance(c, `${path}.charges[${j}]`)
|
|
9039
|
+
),
|
|
9040
|
+
...defined({
|
|
9041
|
+
description: line2.description,
|
|
9042
|
+
price_base_quantity: line2.price_base_quantity === void 0 ? void 0 : number(
|
|
9043
|
+
line2.price_base_quantity,
|
|
9044
|
+
`${path}.price_base_quantity`,
|
|
9045
|
+
6
|
|
9046
|
+
),
|
|
9047
|
+
period: period3(line2.period, `${path}.period`, "BR-30"),
|
|
9048
|
+
buyer_accounting_reference: line2.buyer_accounting_reference,
|
|
9049
|
+
note: line2.note,
|
|
9050
|
+
seller_item_id: line2.seller_item_id,
|
|
9051
|
+
buyer_item_id: line2.buyer_item_id,
|
|
9052
|
+
standard_item_id: standard,
|
|
9053
|
+
order_line_reference: line2.order_line_reference
|
|
9054
|
+
})
|
|
9055
|
+
};
|
|
9056
|
+
}),
|
|
9057
|
+
allowances: (input.allowances ?? []).map((a, i) => ({
|
|
9058
|
+
...allowance(a, `allowances[${i}]`),
|
|
9059
|
+
tax: tax(a.tax, `allowances[${i}].tax`)
|
|
9060
|
+
})),
|
|
9061
|
+
charges: (input.charges ?? []).map((c, i) => ({
|
|
9062
|
+
...allowance(c, `charges[${i}]`),
|
|
9063
|
+
tax: tax(c.tax, `charges[${i}].tax`)
|
|
9064
|
+
})),
|
|
9065
|
+
breakdown: input.tax.breakdown.map((row2, i) => ({
|
|
9066
|
+
...tax(row2, `tax.breakdown[${i}]`),
|
|
9067
|
+
basis: amount2(row2.basis, `tax.breakdown[${i}].basis`),
|
|
9068
|
+
amount: amount2(row2.amount, `tax.breakdown[${i}].amount`),
|
|
9069
|
+
...defined({
|
|
9070
|
+
exemption_reason: row2.exemption_reason,
|
|
9071
|
+
exemption_reason_code: row2.exemption_reason_code?.trim()
|
|
9072
|
+
})
|
|
9073
|
+
})),
|
|
9074
|
+
totals: {
|
|
9075
|
+
line_net: amount2(input.totals.line_net, "totals.line_net"),
|
|
9076
|
+
tax_basis: amount2(input.totals.tax_basis, "totals.tax_basis"),
|
|
9077
|
+
tax_total: amount2(input.totals.tax_total, "totals.tax_total"),
|
|
9078
|
+
grand: amount2(input.totals.grand, "totals.grand"),
|
|
9079
|
+
due: amount2(input.totals.due, "totals.due"),
|
|
9080
|
+
...defined({
|
|
9081
|
+
allowances: optionalAmount(
|
|
9082
|
+
input.totals.allowances,
|
|
9083
|
+
"totals.allowances"
|
|
9084
|
+
),
|
|
9085
|
+
charges: optionalAmount(input.totals.charges, "totals.charges"),
|
|
9086
|
+
prepaid: optionalAmount(input.totals.prepaid, "totals.prepaid"),
|
|
9087
|
+
tax_total_accounting: optionalAmount(
|
|
9088
|
+
input.totals.tax_total_accounting,
|
|
9089
|
+
"totals.tax_total_accounting"
|
|
9090
|
+
),
|
|
9091
|
+
rounding
|
|
9092
|
+
})
|
|
9093
|
+
},
|
|
9094
|
+
...payment2 && Object.keys(payment2).length > 0 ? { payment: payment2 } : {}
|
|
9095
|
+
};
|
|
9096
|
+
}
|
|
9097
|
+
function iban(value, path, add2) {
|
|
9098
|
+
if (value === void 0) return void 0;
|
|
9099
|
+
const normalised = normaliseIban(value);
|
|
9100
|
+
if (!/^[A-Z]{2}[0-9]{2}[A-Z0-9]{11,30}$/.test(normalised) || !ibanChecksum(normalised))
|
|
9101
|
+
add2(
|
|
9102
|
+
"iban",
|
|
9103
|
+
path,
|
|
9104
|
+
`_invoice.${path} is not a valid IBAN: its check digits do not match`
|
|
9105
|
+
);
|
|
9106
|
+
return normalised;
|
|
9107
|
+
}
|
|
9108
|
+
function defined(value) {
|
|
9109
|
+
return Object.fromEntries(
|
|
9110
|
+
Object.entries(value).filter(([, v]) => v !== void 0)
|
|
9111
|
+
);
|
|
9112
|
+
}
|
|
9113
|
+
var cents = (text3) => text3 === void 0 ? 0n : toUnits(text3, 2);
|
|
9114
|
+
var money = (value) => fromUnits(value, 2);
|
|
9115
|
+
var rateKey = (tax) => `${tax.category}|${tax.rate ?? ""}`;
|
|
9116
|
+
function rules(invoice, add2) {
|
|
9117
|
+
const { totals: totals2 } = invoice;
|
|
9118
|
+
const sum = (path, stated, expected, rule2, formula) => {
|
|
9119
|
+
if (stated !== expected)
|
|
9120
|
+
add2(
|
|
9121
|
+
"sum",
|
|
9122
|
+
path,
|
|
9123
|
+
`_invoice.${path} is ${money(stated)}, but ${formula} ${money(expected)}`,
|
|
9124
|
+
{
|
|
9125
|
+
rule: rule2,
|
|
9126
|
+
args: { value: money(stated), expected: money(expected) }
|
|
9127
|
+
}
|
|
9128
|
+
);
|
|
9129
|
+
};
|
|
9130
|
+
const lineNet = invoice.lines.reduce(
|
|
9131
|
+
(total, line2) => total + cents(line2.net_amount),
|
|
9132
|
+
0n
|
|
9133
|
+
);
|
|
9134
|
+
const allowanceSum = invoice.allowances.reduce(
|
|
9135
|
+
(total, a) => total + cents(a.amount),
|
|
9136
|
+
0n
|
|
9137
|
+
);
|
|
9138
|
+
const chargeSum = invoice.charges.reduce(
|
|
9139
|
+
(total, c) => total + cents(c.amount),
|
|
9140
|
+
0n
|
|
9141
|
+
);
|
|
9142
|
+
const taxSum = invoice.breakdown.reduce(
|
|
9143
|
+
(total, row2) => total + cents(row2.amount),
|
|
9144
|
+
0n
|
|
9145
|
+
);
|
|
9146
|
+
sum(
|
|
9147
|
+
"totals.line_net",
|
|
9148
|
+
cents(totals2.line_net),
|
|
9149
|
+
lineNet,
|
|
9150
|
+
"BR-CO-10",
|
|
9151
|
+
"the net amounts of the lines add up to"
|
|
9152
|
+
);
|
|
9153
|
+
sum(
|
|
9154
|
+
"totals.allowances",
|
|
9155
|
+
cents(totals2.allowances),
|
|
9156
|
+
allowanceSum,
|
|
9157
|
+
"BR-CO-11",
|
|
9158
|
+
"the allowances of the document add up to"
|
|
9159
|
+
);
|
|
9160
|
+
sum(
|
|
9161
|
+
"totals.charges",
|
|
9162
|
+
cents(totals2.charges),
|
|
9163
|
+
chargeSum,
|
|
9164
|
+
"BR-CO-12",
|
|
9165
|
+
"the charges of the document add up to"
|
|
9166
|
+
);
|
|
9167
|
+
sum(
|
|
9168
|
+
"totals.tax_basis",
|
|
9169
|
+
cents(totals2.tax_basis),
|
|
9170
|
+
cents(totals2.line_net) - cents(totals2.allowances) + cents(totals2.charges),
|
|
9171
|
+
"BR-CO-13",
|
|
9172
|
+
"line_net less allowances plus charges is"
|
|
9173
|
+
);
|
|
9174
|
+
sum(
|
|
9175
|
+
"totals.tax_total",
|
|
9176
|
+
cents(totals2.tax_total),
|
|
9177
|
+
taxSum,
|
|
9178
|
+
"BR-CO-14",
|
|
9179
|
+
"the VAT amounts of the breakdown add up to"
|
|
9180
|
+
);
|
|
9181
|
+
sum(
|
|
9182
|
+
"totals.grand",
|
|
9183
|
+
cents(totals2.grand),
|
|
9184
|
+
cents(totals2.tax_basis) + cents(totals2.tax_total),
|
|
9185
|
+
"BR-CO-15",
|
|
9186
|
+
"tax_basis plus tax_total is"
|
|
9187
|
+
);
|
|
9188
|
+
sum(
|
|
9189
|
+
"totals.due",
|
|
9190
|
+
cents(totals2.due),
|
|
9191
|
+
cents(totals2.grand) - cents(totals2.prepaid) + cents(totals2.rounding),
|
|
9192
|
+
"BR-CO-16",
|
|
9193
|
+
"grand less prepaid plus rounding is"
|
|
9194
|
+
);
|
|
9195
|
+
if (invoice.accounting_currency !== void 0 && totals2.tax_total_accounting === void 0)
|
|
9196
|
+
add2(
|
|
9197
|
+
"missing",
|
|
9198
|
+
"totals.tax_total_accounting",
|
|
9199
|
+
`_invoice.totals.tax_total_accounting is missing: with accounting_currency ${invoice.accounting_currency} the invoice states its VAT total in that currency (BT-111)`,
|
|
9200
|
+
{
|
|
9201
|
+
rule: "BR-53",
|
|
9202
|
+
args: { term: "BT-111" }
|
|
9203
|
+
}
|
|
9204
|
+
);
|
|
9205
|
+
if (invoice.accounting_currency === void 0 && totals2.tax_total_accounting !== void 0)
|
|
9206
|
+
add2(
|
|
9207
|
+
"missing",
|
|
9208
|
+
"accounting_currency",
|
|
9209
|
+
"_invoice.accounting_currency is missing: totals.tax_total_accounting needs the currency it is stated in (BT-6)",
|
|
9210
|
+
{
|
|
9211
|
+
rule: "BR-53",
|
|
9212
|
+
args: { term: "BT-6" }
|
|
9213
|
+
}
|
|
9214
|
+
);
|
|
9215
|
+
const used = /* @__PURE__ */ new Map();
|
|
9216
|
+
const use = (tax, value, path) => {
|
|
9217
|
+
const entry = used.get(rateKey(tax)) ?? {
|
|
9218
|
+
tax,
|
|
9219
|
+
basis: 0n,
|
|
9220
|
+
items: 0,
|
|
9221
|
+
first: path
|
|
9222
|
+
};
|
|
9223
|
+
entry.basis += value;
|
|
9224
|
+
entry.items += 1;
|
|
9225
|
+
used.set(rateKey(tax), entry);
|
|
9226
|
+
};
|
|
9227
|
+
invoice.lines.forEach(
|
|
9228
|
+
(line2, i) => use(line2.tax, cents(line2.net_amount), `lines[${i}]`)
|
|
9229
|
+
);
|
|
9230
|
+
invoice.allowances.forEach(
|
|
9231
|
+
(a, i) => use(a.tax, -cents(a.amount), `allowances[${i}]`)
|
|
9232
|
+
);
|
|
9233
|
+
invoice.charges.forEach(
|
|
9234
|
+
(c, i) => use(c.tax, cents(c.amount), `charges[${i}]`)
|
|
9235
|
+
);
|
|
9236
|
+
const seen = /* @__PURE__ */ new Set();
|
|
9237
|
+
invoice.breakdown.forEach((row2, i) => {
|
|
9238
|
+
const path = `tax.breakdown[${i}]`;
|
|
9239
|
+
const prefix = RULE_PREFIX[row2.category];
|
|
9240
|
+
const shown = row2.rate === void 0 ? row2.category : `${row2.category} at ${row2.rate} %`;
|
|
9241
|
+
if (seen.has(rateKey(row2)))
|
|
9242
|
+
add2(
|
|
9243
|
+
"breakdown_duplicate",
|
|
9244
|
+
path,
|
|
9245
|
+
`_invoice.tax.breakdown lists category ${shown} twice; one entry per category and rate`,
|
|
9246
|
+
{
|
|
9247
|
+
args: { category: row2.category, rate: row2.rate ?? "" }
|
|
9248
|
+
}
|
|
9249
|
+
);
|
|
9250
|
+
seen.add(rateKey(row2));
|
|
9251
|
+
const entry = used.get(rateKey(row2));
|
|
9252
|
+
const expected = entry?.basis ?? 0n;
|
|
9253
|
+
if (cents(row2.basis) !== expected)
|
|
9254
|
+
add2(
|
|
9255
|
+
"sum",
|
|
9256
|
+
`${path}.basis`,
|
|
9257
|
+
`_invoice.${path}.basis is ${money(cents(row2.basis))}, but the lines, charges and allowances of category ${shown} come to ${money(expected)}`,
|
|
9258
|
+
{
|
|
9259
|
+
rule: `${prefix}-08`,
|
|
9260
|
+
args: {
|
|
9261
|
+
value: money(cents(row2.basis)),
|
|
9262
|
+
expected: money(expected),
|
|
9263
|
+
category: row2.category,
|
|
9264
|
+
rate: row2.rate ?? ""
|
|
9265
|
+
}
|
|
9266
|
+
}
|
|
9267
|
+
);
|
|
9268
|
+
if (row2.rate !== void 0) {
|
|
9269
|
+
const computed = divideRounded(
|
|
9270
|
+
cents(row2.basis) * toUnits(row2.rate, 4),
|
|
9271
|
+
1000000n
|
|
9272
|
+
);
|
|
9273
|
+
const items = BigInt(Math.max(1, entry?.items ?? 1));
|
|
9274
|
+
const tolerance = (items + 1n) / 2n > 100n ? 100n : (items + 1n) / 2n;
|
|
9275
|
+
if (abs(cents(row2.amount) - computed) > tolerance)
|
|
9276
|
+
add2(
|
|
9277
|
+
"sum",
|
|
9278
|
+
`${path}.amount`,
|
|
9279
|
+
`_invoice.${path}.amount is ${money(cents(row2.amount))}, but ${row2.rate} % of ${money(cents(row2.basis))} is ${money(computed)}`,
|
|
9280
|
+
{
|
|
9281
|
+
rule: "BR-CO-17",
|
|
9282
|
+
args: {
|
|
9283
|
+
value: money(cents(row2.amount)),
|
|
9284
|
+
expected: money(computed),
|
|
9285
|
+
rate: row2.rate,
|
|
9286
|
+
basis: money(cents(row2.basis))
|
|
9287
|
+
}
|
|
9288
|
+
}
|
|
9289
|
+
);
|
|
9290
|
+
}
|
|
9291
|
+
});
|
|
9292
|
+
for (const [key, entry] of used) {
|
|
9293
|
+
if (seen.has(key)) continue;
|
|
9294
|
+
const shown = entry.tax.rate === void 0 ? entry.tax.category : `${entry.tax.category} at ${entry.tax.rate} %`;
|
|
9295
|
+
add2(
|
|
9296
|
+
"breakdown_missing",
|
|
9297
|
+
"tax.breakdown",
|
|
9298
|
+
`_invoice.tax.breakdown has no entry for category ${shown}, which _invoice.${entry.first} falls under`,
|
|
9299
|
+
{
|
|
9300
|
+
rule: `${RULE_PREFIX[entry.tax.category]}-01`,
|
|
9301
|
+
args: {
|
|
9302
|
+
category: entry.tax.category,
|
|
9303
|
+
rate: entry.tax.rate ?? "",
|
|
9304
|
+
used: entry.first
|
|
9305
|
+
}
|
|
9306
|
+
}
|
|
9307
|
+
);
|
|
9308
|
+
}
|
|
9309
|
+
const rate = (tax, path, at) => {
|
|
9310
|
+
const prefix = RULE_PREFIX[tax.category];
|
|
9311
|
+
const number = at === "line" || at === "breakdown" ? "05" : at === "allowance" ? "06" : "07";
|
|
9312
|
+
if (tax.category === "O") {
|
|
9313
|
+
if (tax.rate !== void 0)
|
|
9314
|
+
add2(
|
|
9315
|
+
"rate_forbidden",
|
|
9316
|
+
`${path}.rate`,
|
|
9317
|
+
`_invoice.${path}.rate must be left out: category O is not subject to VAT and has no rate`,
|
|
9318
|
+
{ rule: `${prefix}-${number}` }
|
|
9319
|
+
);
|
|
9320
|
+
return;
|
|
9321
|
+
}
|
|
9322
|
+
if (tax.rate === void 0) {
|
|
9323
|
+
add2(
|
|
9324
|
+
"rate_required",
|
|
9325
|
+
`${path}.rate`,
|
|
9326
|
+
`_invoice.${path}.rate is missing: category ${tax.category} states its rate${tax.category === "S" ? "" : ", which is 0"}`,
|
|
9327
|
+
{
|
|
9328
|
+
rule: at === "breakdown" ? "BR-48" : `${prefix}-${number}`,
|
|
9329
|
+
args: { category: tax.category }
|
|
9330
|
+
}
|
|
9331
|
+
);
|
|
9332
|
+
return;
|
|
9333
|
+
}
|
|
9334
|
+
const value = toUnits(tax.rate, 4);
|
|
9335
|
+
if (tax.category === "S" && value <= 0n)
|
|
9336
|
+
add2(
|
|
9337
|
+
"rate_positive",
|
|
9338
|
+
`${path}.rate`,
|
|
9339
|
+
`_invoice.${path}.rate is ${tax.rate}: category S is standard rated and needs a rate above 0; a rate of 0 is category Z or E`,
|
|
9340
|
+
{
|
|
9341
|
+
rule: `${prefix}-${number}`,
|
|
9342
|
+
args: { rate: tax.rate }
|
|
9343
|
+
}
|
|
9344
|
+
);
|
|
9345
|
+
if (tax.category !== "S" && value !== 0n)
|
|
9346
|
+
add2(
|
|
9347
|
+
"rate_zero",
|
|
9348
|
+
`${path}.rate`,
|
|
9349
|
+
`_invoice.${path}.rate is ${tax.rate}: category ${tax.category} carries a rate of 0`,
|
|
9350
|
+
{
|
|
9351
|
+
rule: `${prefix}-${number}`,
|
|
9352
|
+
args: { rate: tax.rate, category: tax.category }
|
|
9353
|
+
}
|
|
9354
|
+
);
|
|
9355
|
+
};
|
|
9356
|
+
invoice.lines.forEach((line2, i) => rate(line2.tax, `lines[${i}].tax`, "line"));
|
|
9357
|
+
invoice.allowances.forEach(
|
|
9358
|
+
(a, i) => rate(a.tax, `allowances[${i}].tax`, "allowance")
|
|
9359
|
+
);
|
|
9360
|
+
invoice.charges.forEach((c, i) => rate(c.tax, `charges[${i}].tax`, "charge"));
|
|
9361
|
+
const categories = new Set(
|
|
9362
|
+
[...used.values()].map((entry) => entry.tax.category)
|
|
9363
|
+
);
|
|
9364
|
+
invoice.breakdown.forEach((row2, i) => {
|
|
9365
|
+
const path = `tax.breakdown[${i}]`;
|
|
9366
|
+
const prefix = RULE_PREFIX[row2.category];
|
|
9367
|
+
rate(row2, path, "breakdown");
|
|
9368
|
+
categories.add(row2.category);
|
|
9369
|
+
const reason = row2.exemption_reason !== void 0 || row2.exemption_reason_code !== void 0;
|
|
9370
|
+
if (row2.category === "S" || row2.category === "Z") {
|
|
9371
|
+
if (reason)
|
|
9372
|
+
add2(
|
|
9373
|
+
"exemption_reason_forbidden",
|
|
9374
|
+
`${path}.exemption_reason`,
|
|
9375
|
+
`_invoice.${path} must not state an exemption reason: category ${row2.category} is not an exemption`,
|
|
9376
|
+
{
|
|
9377
|
+
rule: `${prefix}-10`,
|
|
9378
|
+
args: { category: row2.category }
|
|
9379
|
+
}
|
|
9380
|
+
);
|
|
9381
|
+
} else if (!reason) {
|
|
9382
|
+
add2(
|
|
9383
|
+
"exemption_reason_required",
|
|
9384
|
+
`${path}.exemption_reason`,
|
|
9385
|
+
`_invoice.${path}.exemption_reason is missing: category ${row2.category} says why no VAT is charged, as text or as exemption_reason_code`,
|
|
9386
|
+
{
|
|
9387
|
+
rule: `${prefix}-10`,
|
|
9388
|
+
args: { category: row2.category }
|
|
9389
|
+
}
|
|
9390
|
+
);
|
|
9391
|
+
}
|
|
9392
|
+
if (row2.category !== "S" && cents(row2.amount) !== 0n)
|
|
9393
|
+
add2(
|
|
9394
|
+
"amount_zero",
|
|
9395
|
+
`${path}.amount`,
|
|
9396
|
+
`_invoice.${path}.amount is ${money(cents(row2.amount))}: category ${row2.category} carries no VAT, so the amount is 0`,
|
|
9397
|
+
{
|
|
9398
|
+
rule: `${prefix}-09`,
|
|
9399
|
+
args: { value: money(cents(row2.amount)), category: row2.category }
|
|
9400
|
+
}
|
|
9401
|
+
);
|
|
9402
|
+
});
|
|
9403
|
+
const sellerTaxId = invoice.seller.vat_id !== void 0 || invoice.seller.tax_number !== void 0;
|
|
9404
|
+
for (const category of categories) {
|
|
9405
|
+
const prefix = RULE_PREFIX[category];
|
|
9406
|
+
if (category === "O") {
|
|
9407
|
+
if (invoice.seller.vat_id !== void 0)
|
|
9408
|
+
add2(
|
|
9409
|
+
"vat_id_forbidden",
|
|
9410
|
+
"seller.vat_id",
|
|
9411
|
+
"_invoice.seller.vat_id must be left out: an invoice of category O is not subject to VAT; the seller is named by tax_number or legal_registration",
|
|
9412
|
+
{ rule: "BR-O-02" }
|
|
9413
|
+
);
|
|
9414
|
+
if (invoice.buyer.vat_id !== void 0)
|
|
9415
|
+
add2(
|
|
9416
|
+
"vat_id_forbidden",
|
|
9417
|
+
"buyer.vat_id",
|
|
9418
|
+
"_invoice.buyer.vat_id must be left out: an invoice of category O is not subject to VAT",
|
|
9419
|
+
{ rule: "BR-O-02" }
|
|
9420
|
+
);
|
|
9421
|
+
if (categories.size > 1)
|
|
9422
|
+
add2(
|
|
9423
|
+
"only_category",
|
|
9424
|
+
"tax.breakdown",
|
|
9425
|
+
"_invoice mixes category O with others: an invoice that is not subject to VAT has that one category only",
|
|
9426
|
+
{ rule: "BR-O-11" }
|
|
9427
|
+
);
|
|
9428
|
+
continue;
|
|
9429
|
+
}
|
|
9430
|
+
if (category === "K" || category === "G") {
|
|
9431
|
+
if (invoice.seller.vat_id === void 0)
|
|
9432
|
+
add2(
|
|
9433
|
+
"seller_tax_id_required",
|
|
9434
|
+
"seller.vat_id",
|
|
9435
|
+
`_invoice.seller.vat_id is missing: category ${category} names the seller's VAT ID`,
|
|
9436
|
+
{
|
|
9437
|
+
rule: `${prefix}-02`,
|
|
9438
|
+
args: { category }
|
|
9439
|
+
}
|
|
9440
|
+
);
|
|
9441
|
+
} else if (!sellerTaxId) {
|
|
9442
|
+
add2(
|
|
9443
|
+
"seller_tax_id_required",
|
|
9444
|
+
"seller.vat_id",
|
|
9445
|
+
`_invoice.seller.vat_id is missing: category ${category} names the seller's VAT ID, or tax_number where there is none`,
|
|
9446
|
+
{
|
|
9447
|
+
rule: `${prefix}-02`,
|
|
9448
|
+
args: { category }
|
|
9449
|
+
}
|
|
9450
|
+
);
|
|
9451
|
+
}
|
|
9452
|
+
if (category === "AE" && invoice.buyer.vat_id === void 0 && invoice.buyer.legal_registration === void 0)
|
|
9453
|
+
add2(
|
|
9454
|
+
"buyer_tax_id_required",
|
|
9455
|
+
"buyer.vat_id",
|
|
9456
|
+
"_invoice.buyer.vat_id is missing: with reverse charge the buyer owes the VAT, so the invoice names the buyer's VAT ID or legal_registration",
|
|
9457
|
+
{
|
|
9458
|
+
rule: "BR-AE-02",
|
|
9459
|
+
args: { category }
|
|
9460
|
+
}
|
|
9461
|
+
);
|
|
9462
|
+
if (category === "K") {
|
|
9463
|
+
if (invoice.buyer.vat_id === void 0)
|
|
9464
|
+
add2(
|
|
9465
|
+
"buyer_tax_id_required",
|
|
9466
|
+
"buyer.vat_id",
|
|
9467
|
+
"_invoice.buyer.vat_id is missing: an intra-community supply names the buyer's VAT ID",
|
|
9468
|
+
{
|
|
9469
|
+
rule: "BR-IC-02",
|
|
9470
|
+
args: { category }
|
|
9471
|
+
}
|
|
9472
|
+
);
|
|
9473
|
+
if (invoice.delivery?.date === void 0 && invoice.period === void 0)
|
|
9474
|
+
add2(
|
|
9475
|
+
"delivery_required",
|
|
9476
|
+
"delivery.date",
|
|
9477
|
+
"_invoice.delivery.date is missing: an intra-community supply states when it was delivered, or the invoicing period",
|
|
9478
|
+
{ rule: "BR-IC-11" }
|
|
9479
|
+
);
|
|
9480
|
+
if (invoice.delivery?.address === void 0)
|
|
9481
|
+
add2(
|
|
9482
|
+
"delivery_required",
|
|
9483
|
+
"delivery.address.country",
|
|
9484
|
+
"_invoice.delivery.address.country is missing: an intra-community supply states the country it was delivered to",
|
|
9485
|
+
{ rule: "BR-IC-12" }
|
|
9486
|
+
);
|
|
9487
|
+
}
|
|
9488
|
+
}
|
|
9489
|
+
if (invoice.seller.id === void 0 && invoice.seller.legal_registration === void 0 && invoice.seller.vat_id === void 0)
|
|
9490
|
+
add2(
|
|
9491
|
+
"seller_identifier_required",
|
|
9492
|
+
"seller.vat_id",
|
|
9493
|
+
"_invoice.seller needs an identifier the buyer can match: vat_id, legal_registration or id",
|
|
9494
|
+
{ rule: "BR-CO-26" }
|
|
9495
|
+
);
|
|
9496
|
+
const payment2 = invoice.payment;
|
|
9497
|
+
const account = payment2?.iban !== void 0 || payment2?.bic !== void 0 || payment2?.account_name !== void 0;
|
|
9498
|
+
if (payment2 && payment2.means_code === void 0 && (account || payment2.mandate_id !== void 0 || payment2.debited_iban !== void 0))
|
|
9499
|
+
add2(
|
|
9500
|
+
"means_code_required",
|
|
9501
|
+
"payment.means_code",
|
|
9502
|
+
"_invoice.payment.means_code is missing: payment details say how the invoice is paid, 58 for a SEPA credit transfer, 59 for a SEPA direct debit",
|
|
9503
|
+
{ rule: "BR-49" }
|
|
9504
|
+
);
|
|
9505
|
+
if (payment2?.means_code !== void 0 && CREDIT_TRANSFER.has(payment2.means_code) && payment2.iban === void 0)
|
|
9506
|
+
add2(
|
|
9507
|
+
"account_required",
|
|
9508
|
+
"payment.iban",
|
|
9509
|
+
`_invoice.payment.iban is missing: a payment by credit transfer (code ${payment2.means_code}) names the account`,
|
|
9510
|
+
{
|
|
9511
|
+
rule: "BR-61",
|
|
9512
|
+
args: { means: payment2.means_code }
|
|
9513
|
+
}
|
|
9514
|
+
);
|
|
9515
|
+
if (cents(totals2.due) > 0n && payment2?.due_date === void 0 && payment2?.terms === void 0)
|
|
9516
|
+
add2(
|
|
9517
|
+
"due_or_terms_required",
|
|
9518
|
+
"payment.due_date",
|
|
9519
|
+
"_invoice.payment.due_date is missing: an invoice with an amount due states when it is due, or its payment terms",
|
|
9520
|
+
{ rule: "BR-CO-25" }
|
|
9521
|
+
);
|
|
9522
|
+
if (invoice.seller.address.country === "FR" && invoice.buyer.address.country === "FR") {
|
|
9523
|
+
const digits = (id) => (id?.value ?? "").replace(/\s/g, "");
|
|
9524
|
+
if (!/^\d{9}$/.test(digits(invoice.seller.legal_registration)))
|
|
9525
|
+
add2(
|
|
9526
|
+
"fr_seller_siren",
|
|
9527
|
+
"seller.legal_registration",
|
|
9528
|
+
"_invoice.seller.legal_registration is missing or not nine digits: an invoice between French businesses names the seller's SIREN (BT-30)",
|
|
9529
|
+
{ rule: "BR-FR-10" }
|
|
9530
|
+
);
|
|
9531
|
+
if (!/^\d{9}$/.test(digits(invoice.buyer.legal_registration)))
|
|
9532
|
+
add2(
|
|
9533
|
+
"fr_buyer_siren",
|
|
9534
|
+
"buyer.siren",
|
|
9535
|
+
"_invoice.buyer.siren is missing or not nine digits: an invoice between French businesses names the buyer's SIREN (BT-47)",
|
|
9536
|
+
{ rule: "BR-FR-11" }
|
|
9537
|
+
);
|
|
9538
|
+
if (invoice.business_process === void 0)
|
|
9539
|
+
add2(
|
|
9540
|
+
"fr_operation",
|
|
9541
|
+
"operation",
|
|
9542
|
+
"_invoice.operation is missing: an invoice between French businesses says whether it is for goods, services or mixed (BT-23)",
|
|
9543
|
+
{ rule: "BR-FR-08" }
|
|
9544
|
+
);
|
|
9545
|
+
else if (!FRENCH_FRAMEWORKS.has(invoice.business_process))
|
|
9546
|
+
add2(
|
|
9547
|
+
"code_list",
|
|
9548
|
+
"operation_code",
|
|
9549
|
+
`_invoice.operation_code: "${invoice.business_process}" is not a billing framework of the French specifications (B1, S1, M1 and their variants)`,
|
|
9550
|
+
{
|
|
9551
|
+
rule: "BR-FR-08",
|
|
9552
|
+
args: {
|
|
9553
|
+
value: invoice.business_process,
|
|
9554
|
+
list: "the French billing frameworks"
|
|
9555
|
+
}
|
|
9556
|
+
}
|
|
9557
|
+
);
|
|
9558
|
+
if (invoice.seller.vat_on_debits === void 0)
|
|
9559
|
+
add2(
|
|
9560
|
+
"fr_vat_on_debits",
|
|
9561
|
+
"seller.vat_on_debits",
|
|
9562
|
+
"_invoice.seller.vat_on_debits is missing: an invoice between French businesses says whether the seller pays VAT on invoicing (true) or on payment (false)"
|
|
9563
|
+
);
|
|
9564
|
+
}
|
|
9565
|
+
}
|
|
9566
|
+
|
|
9567
|
+
// packages/engine/src/lib/einvoice/cii.ts
|
|
9568
|
+
var CII_GUIDELINES = {
|
|
9569
|
+
basic: "urn:cen.eu:en16931:2017#compliant#urn:factur-x.eu:1p0:basic",
|
|
9570
|
+
en16931: "urn:cen.eu:en16931:2017"
|
|
9571
|
+
};
|
|
9572
|
+
var EINVOICE_XML_NAME = "factur-x.xml";
|
|
9573
|
+
function leaf(name, text3, attributes) {
|
|
9574
|
+
if (text3 === void 0 || text3 === "") return void 0;
|
|
9575
|
+
const kept = Object.entries(attributes ?? {}).filter(
|
|
9576
|
+
(entry) => entry[1] !== void 0
|
|
9577
|
+
);
|
|
9578
|
+
return {
|
|
9579
|
+
name,
|
|
9580
|
+
text: text3,
|
|
9581
|
+
...kept.length > 0 ? { attributes: Object.fromEntries(kept) } : {}
|
|
9582
|
+
};
|
|
9583
|
+
}
|
|
9584
|
+
function group2(name, children) {
|
|
9585
|
+
const kept = children.filter((child2) => !!child2);
|
|
9586
|
+
return kept.length > 0 ? { name, children: kept } : void 0;
|
|
9587
|
+
}
|
|
9588
|
+
var date = (name, value) => value === void 0 ? void 0 : group2(name, [
|
|
9589
|
+
leaf("udt:DateTimeString", value.replace(/-/g, ""), { format: "102" })
|
|
9590
|
+
]);
|
|
9591
|
+
var amount = (name, value, attributes) => value === void 0 ? void 0 : leaf(name, withPlaces(value, 2), attributes);
|
|
9592
|
+
var identifier3 = (plain, withScheme, id) => id === void 0 ? void 0 : id.scheme ? leaf(withScheme, id.value, { schemeID: id.scheme }) : leaf(plain, id.value);
|
|
9593
|
+
function address2(value) {
|
|
9594
|
+
if (!value) return void 0;
|
|
9595
|
+
return group2("ram:PostalTradeAddress", [
|
|
9596
|
+
leaf("ram:PostcodeCode", value.postcode),
|
|
9597
|
+
leaf("ram:LineOne", value.street),
|
|
9598
|
+
leaf("ram:LineTwo", value.street2),
|
|
9599
|
+
leaf("ram:LineThree", value.street3),
|
|
9600
|
+
leaf("ram:CityName", value.city),
|
|
9601
|
+
leaf("ram:CountryID", value.country),
|
|
9602
|
+
leaf("ram:CountrySubDivisionName", value.subdivision)
|
|
9603
|
+
]);
|
|
9604
|
+
}
|
|
9605
|
+
function party2(name, value, full) {
|
|
9606
|
+
return group2(name, [
|
|
9607
|
+
identifier3("ram:ID", "ram:GlobalID", value.id),
|
|
9608
|
+
leaf("ram:Name", value.name),
|
|
9609
|
+
full ? leaf("ram:Description", value.legal_info) : void 0,
|
|
9610
|
+
group2("ram:SpecifiedLegalOrganization", [
|
|
9611
|
+
value.legal_registration ? leaf("ram:ID", value.legal_registration.value, {
|
|
9612
|
+
schemeID: value.legal_registration.scheme
|
|
9613
|
+
}) : void 0,
|
|
9614
|
+
leaf("ram:TradingBusinessName", value.trading_name)
|
|
9615
|
+
]),
|
|
9616
|
+
full && value.contact ? group2("ram:DefinedTradeContact", [
|
|
9617
|
+
leaf("ram:PersonName", value.contact.name),
|
|
9618
|
+
group2("ram:TelephoneUniversalCommunication", [
|
|
9619
|
+
leaf("ram:CompleteNumber", value.contact.phone)
|
|
9620
|
+
]),
|
|
9621
|
+
group2("ram:EmailURIUniversalCommunication", [
|
|
9622
|
+
leaf("ram:URIID", value.contact.email)
|
|
9623
|
+
])
|
|
9624
|
+
]) : void 0,
|
|
9625
|
+
address2(value.address),
|
|
9626
|
+
value.electronic_address ? group2("ram:URIUniversalCommunication", [
|
|
9627
|
+
leaf("ram:URIID", value.electronic_address.value, {
|
|
9628
|
+
schemeID: value.electronic_address.scheme
|
|
9629
|
+
})
|
|
9630
|
+
]) : void 0,
|
|
9631
|
+
group2("ram:SpecifiedTaxRegistration", [
|
|
9632
|
+
leaf("ram:ID", value.vat_id, { schemeID: "VA" })
|
|
9633
|
+
]),
|
|
9634
|
+
group2("ram:SpecifiedTaxRegistration", [
|
|
9635
|
+
leaf("ram:ID", value.tax_number, { schemeID: "FC" })
|
|
9636
|
+
])
|
|
9637
|
+
]);
|
|
9638
|
+
}
|
|
9639
|
+
var taxOf = (tax) => [
|
|
9640
|
+
leaf("ram:TypeCode", "VAT"),
|
|
9641
|
+
leaf("ram:CategoryCode", tax.category),
|
|
9642
|
+
leaf("ram:RateApplicablePercent", tax.rate)
|
|
9643
|
+
];
|
|
9644
|
+
function allowanceOrCharge2(value, charge) {
|
|
9645
|
+
return group2("ram:SpecifiedTradeAllowanceCharge", [
|
|
9646
|
+
group2("ram:ChargeIndicator", [
|
|
9647
|
+
leaf("udt:Indicator", charge ? "true" : "false")
|
|
9648
|
+
]),
|
|
9649
|
+
leaf("ram:CalculationPercent", value.percent),
|
|
9650
|
+
amount("ram:BasisAmount", value.base_amount),
|
|
9651
|
+
amount("ram:ActualAmount", value.amount),
|
|
9652
|
+
leaf("ram:ReasonCode", value.reason_code),
|
|
9653
|
+
leaf("ram:Reason", value.reason),
|
|
9654
|
+
value.tax ? group2("ram:CategoryTradeTax", taxOf(value.tax)) : void 0
|
|
9655
|
+
]);
|
|
9656
|
+
}
|
|
9657
|
+
var period2 = (value) => value === void 0 ? void 0 : group2("ram:BillingSpecifiedPeriod", [
|
|
9658
|
+
date("ram:StartDateTime", value.start),
|
|
9659
|
+
date("ram:EndDateTime", value.end)
|
|
9660
|
+
]);
|
|
9661
|
+
function invoiceToCii(invoice, options) {
|
|
9662
|
+
const full = options.profile === "en16931";
|
|
9663
|
+
const { totals: totals2, payment: payment2 } = invoice;
|
|
9664
|
+
const lines = invoice.lines.map(
|
|
9665
|
+
(line2) => group2("ram:IncludedSupplyChainTradeLineItem", [
|
|
9666
|
+
group2("ram:AssociatedDocumentLineDocument", [
|
|
9667
|
+
leaf("ram:LineID", line2.id),
|
|
9668
|
+
group2("ram:IncludedNote", [leaf("ram:Content", line2.note)])
|
|
9669
|
+
]),
|
|
9670
|
+
group2("ram:SpecifiedTradeProduct", [
|
|
9671
|
+
line2.standard_item_id ? leaf("ram:GlobalID", line2.standard_item_id.value, {
|
|
9672
|
+
schemeID: line2.standard_item_id.scheme
|
|
9673
|
+
}) : void 0,
|
|
9674
|
+
full ? leaf("ram:SellerAssignedID", line2.seller_item_id) : void 0,
|
|
9675
|
+
full ? leaf("ram:BuyerAssignedID", line2.buyer_item_id) : void 0,
|
|
9676
|
+
leaf("ram:Name", line2.name),
|
|
9677
|
+
full ? leaf("ram:Description", line2.description) : void 0
|
|
9678
|
+
]),
|
|
9679
|
+
group2("ram:SpecifiedLineTradeAgreement", [
|
|
9680
|
+
full ? group2("ram:BuyerOrderReferencedDocument", [
|
|
9681
|
+
leaf("ram:LineID", line2.order_line_reference)
|
|
9682
|
+
]) : void 0,
|
|
9683
|
+
group2("ram:NetPriceProductTradePrice", [
|
|
9684
|
+
leaf("ram:ChargeAmount", withPlaces(line2.net_price, 2)),
|
|
9685
|
+
leaf("ram:BasisQuantity", line2.price_base_quantity, {
|
|
9686
|
+
unitCode: line2.unit_code
|
|
9687
|
+
})
|
|
9688
|
+
])
|
|
9689
|
+
]),
|
|
9690
|
+
group2("ram:SpecifiedLineTradeDelivery", [
|
|
9691
|
+
leaf("ram:BilledQuantity", line2.quantity, { unitCode: line2.unit_code })
|
|
9692
|
+
]),
|
|
9693
|
+
group2("ram:SpecifiedLineTradeSettlement", [
|
|
9694
|
+
group2("ram:ApplicableTradeTax", taxOf(line2.tax)),
|
|
9695
|
+
period2(line2.period),
|
|
9696
|
+
...line2.allowances.map((a) => allowanceOrCharge2(a, false)),
|
|
9697
|
+
...line2.charges.map((c) => allowanceOrCharge2(c, true)),
|
|
9698
|
+
group2("ram:SpecifiedTradeSettlementLineMonetarySummation", [
|
|
9699
|
+
amount("ram:LineTotalAmount", line2.net_amount)
|
|
9700
|
+
]),
|
|
9701
|
+
full ? group2("ram:ReceivableSpecifiedTradeAccountingAccount", [
|
|
9702
|
+
leaf("ram:ID", line2.buyer_accounting_reference)
|
|
9703
|
+
]) : void 0
|
|
9704
|
+
])
|
|
9705
|
+
])
|
|
9706
|
+
);
|
|
9707
|
+
const agreement = group2("ram:ApplicableHeaderTradeAgreement", [
|
|
9708
|
+
leaf("ram:BuyerReference", invoice.buyer_reference),
|
|
9709
|
+
party2("ram:SellerTradeParty", invoice.seller, full),
|
|
9710
|
+
party2("ram:BuyerTradeParty", invoice.buyer, full),
|
|
9711
|
+
group2("ram:BuyerOrderReferencedDocument", [
|
|
9712
|
+
leaf("ram:IssuerAssignedID", invoice.order_reference)
|
|
9713
|
+
]),
|
|
9714
|
+
group2("ram:ContractReferencedDocument", [
|
|
9715
|
+
leaf("ram:IssuerAssignedID", invoice.contract_reference)
|
|
9716
|
+
])
|
|
9717
|
+
]);
|
|
9718
|
+
const shipTo = invoice.delivery;
|
|
9719
|
+
const delivery = group2("ram:ApplicableHeaderTradeDelivery", [
|
|
9720
|
+
group2("ram:ShipToTradeParty", [
|
|
9721
|
+
leaf("ram:Name", shipTo?.name),
|
|
9722
|
+
address2(shipTo?.address)
|
|
9723
|
+
]),
|
|
9724
|
+
group2("ram:ActualDeliverySupplyChainEvent", [
|
|
9725
|
+
date("ram:OccurrenceDateTime", shipTo?.date)
|
|
9726
|
+
])
|
|
9727
|
+
]) ?? { name: "ram:ApplicableHeaderTradeDelivery" };
|
|
9728
|
+
const settlement = group2("ram:ApplicableHeaderTradeSettlement", [
|
|
9729
|
+
leaf("ram:CreditorReferenceID", payment2?.creditor_id),
|
|
9730
|
+
leaf("ram:PaymentReference", payment2?.reference),
|
|
9731
|
+
leaf("ram:TaxCurrencyCode", invoice.accounting_currency),
|
|
9732
|
+
leaf("ram:InvoiceCurrencyCode", invoice.currency),
|
|
9733
|
+
payment2?.means_code ? group2("ram:SpecifiedTradeSettlementPaymentMeans", [
|
|
9734
|
+
leaf("ram:TypeCode", payment2.means_code),
|
|
9735
|
+
group2("ram:PayerPartyDebtorFinancialAccount", [
|
|
9736
|
+
leaf("ram:IBANID", payment2.debited_iban)
|
|
9737
|
+
]),
|
|
9738
|
+
group2("ram:PayeePartyCreditorFinancialAccount", [
|
|
9739
|
+
leaf("ram:IBANID", payment2.iban),
|
|
9740
|
+
full ? leaf("ram:AccountName", payment2.account_name) : void 0
|
|
9741
|
+
]),
|
|
9742
|
+
full ? group2("ram:PayeeSpecifiedCreditorFinancialInstitution", [
|
|
9743
|
+
leaf("ram:BICID", payment2.bic)
|
|
9744
|
+
]) : void 0
|
|
9745
|
+
]) : void 0,
|
|
9746
|
+
...invoice.breakdown.map(
|
|
9747
|
+
(row2) => group2("ram:ApplicableTradeTax", [
|
|
9748
|
+
amount("ram:CalculatedAmount", row2.amount),
|
|
9749
|
+
leaf("ram:TypeCode", "VAT"),
|
|
9750
|
+
leaf("ram:ExemptionReason", row2.exemption_reason),
|
|
9751
|
+
amount("ram:BasisAmount", row2.basis),
|
|
9752
|
+
leaf("ram:CategoryCode", row2.category),
|
|
9753
|
+
leaf("ram:ExemptionReasonCode", row2.exemption_reason_code),
|
|
9754
|
+
// France: VAT owed on invoicing rather than on payment is the code for "date of the
|
|
9755
|
+
// invoice" (BT-8). Nothing is written for the default, which the specifications leave unsaid.
|
|
9756
|
+
invoice.seller.vat_on_debits ? leaf("ram:DueDateTypeCode", "5") : void 0,
|
|
9757
|
+
leaf("ram:RateApplicablePercent", row2.rate)
|
|
9758
|
+
])
|
|
9759
|
+
),
|
|
9760
|
+
period2(invoice.period),
|
|
9761
|
+
...invoice.allowances.map((a) => allowanceOrCharge2(a, false)),
|
|
9762
|
+
...invoice.charges.map((c) => allowanceOrCharge2(c, true)),
|
|
9763
|
+
group2("ram:SpecifiedTradePaymentTerms", [
|
|
9764
|
+
leaf("ram:Description", payment2?.terms),
|
|
9765
|
+
date("ram:DueDateDateTime", payment2?.due_date),
|
|
9766
|
+
leaf("ram:DirectDebitMandateID", payment2?.mandate_id)
|
|
9767
|
+
]),
|
|
9768
|
+
group2("ram:SpecifiedTradeSettlementHeaderMonetarySummation", [
|
|
9769
|
+
amount("ram:LineTotalAmount", totals2.line_net),
|
|
9770
|
+
amount("ram:ChargeTotalAmount", totals2.charges),
|
|
9771
|
+
amount("ram:AllowanceTotalAmount", totals2.allowances),
|
|
9772
|
+
amount("ram:TaxBasisTotalAmount", totals2.tax_basis),
|
|
9773
|
+
amount("ram:TaxTotalAmount", totals2.tax_total, {
|
|
9774
|
+
currencyID: invoice.currency
|
|
9775
|
+
}),
|
|
9776
|
+
invoice.accounting_currency ? amount("ram:TaxTotalAmount", totals2.tax_total_accounting, {
|
|
9777
|
+
currencyID: invoice.accounting_currency
|
|
9778
|
+
}) : void 0,
|
|
9779
|
+
full ? amount("ram:RoundingAmount", totals2.rounding) : void 0,
|
|
9780
|
+
amount("ram:GrandTotalAmount", totals2.grand),
|
|
9781
|
+
amount("ram:TotalPrepaidAmount", totals2.prepaid),
|
|
9782
|
+
amount("ram:DuePayableAmount", totals2.due)
|
|
9783
|
+
]),
|
|
9784
|
+
...invoice.preceding_invoices.map(
|
|
9785
|
+
(reference) => group2("ram:InvoiceReferencedDocument", [
|
|
9786
|
+
leaf("ram:IssuerAssignedID", reference.number),
|
|
9787
|
+
reference.issue_date ? group2("ram:FormattedIssueDateTime", [
|
|
9788
|
+
leaf(
|
|
9789
|
+
"qdt:DateTimeString",
|
|
9790
|
+
reference.issue_date.replace(/-/g, ""),
|
|
9791
|
+
{ format: "102" }
|
|
9792
|
+
)
|
|
9793
|
+
]) : void 0
|
|
9794
|
+
])
|
|
9795
|
+
)
|
|
9796
|
+
]);
|
|
9797
|
+
const root = {
|
|
9798
|
+
name: "rsm:CrossIndustryInvoice",
|
|
9799
|
+
attributes: {
|
|
9800
|
+
"xmlns:rsm": "urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100",
|
|
9801
|
+
"xmlns:qdt": "urn:un:unece:uncefact:data:standard:QualifiedDataType:100",
|
|
9802
|
+
"xmlns:ram": "urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100",
|
|
9803
|
+
"xmlns:udt": "urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100"
|
|
9804
|
+
},
|
|
9805
|
+
children: [
|
|
9806
|
+
group2("rsm:ExchangedDocumentContext", [
|
|
9807
|
+
group2("ram:BusinessProcessSpecifiedDocumentContextParameter", [
|
|
9808
|
+
leaf("ram:ID", invoice.business_process)
|
|
9809
|
+
]),
|
|
9810
|
+
group2("ram:GuidelineSpecifiedDocumentContextParameter", [
|
|
9811
|
+
leaf("ram:ID", CII_GUIDELINES[options.profile])
|
|
9812
|
+
])
|
|
9813
|
+
]),
|
|
9814
|
+
group2("rsm:ExchangedDocument", [
|
|
9815
|
+
leaf("ram:ID", invoice.number),
|
|
9816
|
+
leaf("ram:TypeCode", invoice.type_code),
|
|
9817
|
+
date("ram:IssueDateTime", invoice.issue_date),
|
|
9818
|
+
...invoice.notes.map(
|
|
9819
|
+
(note2) => group2("ram:IncludedNote", [
|
|
9820
|
+
leaf("ram:Content", note2.text),
|
|
9821
|
+
leaf("ram:SubjectCode", note2.subject_code)
|
|
9822
|
+
])
|
|
9823
|
+
)
|
|
9824
|
+
]),
|
|
9825
|
+
group2("rsm:SupplyChainTradeTransaction", [
|
|
9826
|
+
...lines,
|
|
9827
|
+
agreement,
|
|
9828
|
+
delivery,
|
|
9829
|
+
settlement
|
|
9830
|
+
])
|
|
9831
|
+
].filter((child2) => !!child2)
|
|
9832
|
+
};
|
|
9833
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
9834
|
+
${serialise(root, 0)}`;
|
|
9835
|
+
}
|
|
9836
|
+
var xmlCharacter = (code) => code === 9 || code === 10 || code === 13 || code >= 32 && !(code >= 55296 && code <= 57343) && code !== 65534 && code !== 65535;
|
|
9837
|
+
function carried(text3) {
|
|
9838
|
+
let out = "";
|
|
9839
|
+
for (const character of text3)
|
|
9840
|
+
if (xmlCharacter(character.codePointAt(0) ?? 0)) out += character;
|
|
9841
|
+
return out;
|
|
9842
|
+
}
|
|
9843
|
+
var escapeText2 = (text3) => carried(text3).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
9844
|
+
var escapeAttribute2 = (text3) => escapeText2(text3).replace(/"/g, """);
|
|
9845
|
+
function serialise(element, depth) {
|
|
9846
|
+
const indent = " ".repeat(depth);
|
|
9847
|
+
const attributes = Object.entries(element.attributes ?? {}).map(([name, value]) => ` ${name}="${escapeAttribute2(value)}"`).join("");
|
|
9848
|
+
if (element.children === void 0) {
|
|
9849
|
+
return element.text === void 0 ? `${indent}<${element.name}${attributes}/>
|
|
9850
|
+
` : `${indent}<${element.name}${attributes}>${escapeText2(element.text)}</${element.name}>
|
|
9851
|
+
`;
|
|
9852
|
+
}
|
|
9853
|
+
const children = element.children.map((child2) => serialise(child2, depth + 1)).join("");
|
|
9854
|
+
return `${indent}<${element.name}${attributes}>
|
|
9855
|
+
${children}${indent}</${element.name}>
|
|
9856
|
+
`;
|
|
9857
|
+
}
|
|
9858
|
+
|
|
9859
|
+
// packages/engine/src/lib/einvoice/display.ts
|
|
9860
|
+
var DISPLAY_TERMS = {
|
|
9861
|
+
"BT-1": "invoice number",
|
|
9862
|
+
"BT-109": "net total",
|
|
9863
|
+
"BT-110": "VAT total",
|
|
9864
|
+
"BT-112": "total",
|
|
9865
|
+
"BT-115": "amount due",
|
|
9866
|
+
"BT-117": "VAT amount"
|
|
9867
|
+
};
|
|
9868
|
+
var DIGIT_0 = 48;
|
|
9869
|
+
var DIGIT_9 = 57;
|
|
9870
|
+
var DOT = 46;
|
|
9871
|
+
var COMMA = 44;
|
|
9872
|
+
var SPACES = /* @__PURE__ */ new Set([32, 160, 8239, 8201]);
|
|
9873
|
+
var APOSTROPHES = /* @__PURE__ */ new Set([39, 8217]);
|
|
9874
|
+
var DASHES = /* @__PURE__ */ new Set([45, 8208, 8209, 8210, 8211, 8722]);
|
|
9875
|
+
var INVISIBLE = /* @__PURE__ */ new Set([173, 8203, 8204, 8205, 8288, 65279]);
|
|
9876
|
+
var isDigit = (code) => code >= DIGIT_0 && code <= DIGIT_9;
|
|
9877
|
+
var MAX_GROUPS = 6;
|
|
9878
|
+
function shownAmounts(text3) {
|
|
9879
|
+
const found = /* @__PURE__ */ new Set();
|
|
9880
|
+
let run2 = "";
|
|
9881
|
+
const flush = () => {
|
|
9882
|
+
const trimmed = run2.replace(/[^0-9]+$/, "");
|
|
9883
|
+
run2 = "";
|
|
9884
|
+
if (!trimmed) return;
|
|
9885
|
+
const parts = trimmed.split(" ").map((part) => part.replace(/[.,]+$/, "")).filter((part) => part !== "");
|
|
9886
|
+
for (let start = 0; start < parts.length; start += 1) {
|
|
9887
|
+
for (const cents2 of readings(parts[start] ?? "")) found.add(cents2);
|
|
9888
|
+
const first = parts[start] ?? "";
|
|
9889
|
+
if (!/^\d{1,3}$/.test(first)) continue;
|
|
9890
|
+
let whole = first;
|
|
9891
|
+
for (let end = start + 1; end < parts.length && end - start < MAX_GROUPS; end += 1) {
|
|
9892
|
+
const part = parts[end] ?? "";
|
|
9893
|
+
const last = /^(\d{3})(?:[.,](\d+))?$/.exec(part);
|
|
9894
|
+
if (!last) break;
|
|
9895
|
+
const cents2 = toCents(whole + last[1], last[2] ?? "");
|
|
9896
|
+
if (cents2 !== null) found.add(cents2);
|
|
9897
|
+
if (last[2] !== void 0) break;
|
|
9898
|
+
whole += last[1];
|
|
9899
|
+
}
|
|
9900
|
+
}
|
|
9901
|
+
};
|
|
9902
|
+
for (const character of text3) {
|
|
9903
|
+
const code = character.codePointAt(0) ?? 0;
|
|
9904
|
+
if (INVISIBLE.has(code)) continue;
|
|
9905
|
+
if (isDigit(code)) run2 += character;
|
|
9906
|
+
else if (run2 && (code === DOT || code === COMMA)) run2 += character;
|
|
9907
|
+
else if (run2 && SPACES.has(code)) run2 += " ";
|
|
9908
|
+
else if (run2 && APOSTROPHES.has(code)) continue;
|
|
9909
|
+
else flush();
|
|
9910
|
+
}
|
|
9911
|
+
flush();
|
|
9912
|
+
return found;
|
|
9913
|
+
}
|
|
9914
|
+
function readings(part) {
|
|
9915
|
+
if (/^\d+$/.test(part)) {
|
|
9916
|
+
const cents2 = toCents(part, "");
|
|
9917
|
+
return cents2 === null ? [] : [cents2];
|
|
9918
|
+
}
|
|
9919
|
+
const out = [];
|
|
9920
|
+
for (const [group3, decimal] of [
|
|
9921
|
+
[".", ","],
|
|
9922
|
+
[",", "."]
|
|
9923
|
+
]) {
|
|
9924
|
+
const pieces = part.split(decimal);
|
|
9925
|
+
if (pieces.length > 2) continue;
|
|
9926
|
+
const [whole = "", fraction] = pieces;
|
|
9927
|
+
if (fraction !== void 0 && !/^\d+$/.test(fraction)) continue;
|
|
9928
|
+
const groups = whole.split(group3);
|
|
9929
|
+
const grouped = groups.every(
|
|
9930
|
+
(digits, index) => /^\d+$/.test(digits) && (index === 0 ? groups.length === 1 || digits.length <= 3 : digits.length === 3)
|
|
9931
|
+
);
|
|
9932
|
+
if (!grouped) continue;
|
|
9933
|
+
const cents2 = toCents(groups.join(""), fraction ?? "");
|
|
9934
|
+
if (cents2 !== null) out.push(cents2);
|
|
9935
|
+
}
|
|
9936
|
+
return out;
|
|
9937
|
+
}
|
|
9938
|
+
function toCents(whole, fraction) {
|
|
9939
|
+
if (whole.length > 18 || /[1-9]/.test(fraction.slice(2))) return null;
|
|
9940
|
+
return BigInt(whole) * 100n + BigInt((fraction + "00").slice(0, 2));
|
|
9941
|
+
}
|
|
9942
|
+
function squeeze(text3) {
|
|
9943
|
+
let out = "";
|
|
9944
|
+
for (const character of text3) {
|
|
9945
|
+
const code = character.codePointAt(0) ?? 0;
|
|
9946
|
+
if (INVISIBLE.has(code) || /\s/.test(character) || SPACES.has(code))
|
|
9947
|
+
continue;
|
|
9948
|
+
out += DASHES.has(code) ? "-" : character.toLowerCase();
|
|
9949
|
+
}
|
|
9950
|
+
return out;
|
|
9951
|
+
}
|
|
9952
|
+
function displayCheck(text3, invoice) {
|
|
9953
|
+
const whole = typeof text3 === "string" ? text3 : text3.join("\n");
|
|
9954
|
+
const amounts = shownAmounts(whole);
|
|
9955
|
+
const squeezed = squeeze(whole);
|
|
9956
|
+
const values = [];
|
|
9957
|
+
values.push({
|
|
9958
|
+
term: "BT-1",
|
|
9959
|
+
path: "number",
|
|
9960
|
+
value: invoice.number,
|
|
9961
|
+
shown: squeezed.includes(squeeze(invoice.number))
|
|
9962
|
+
});
|
|
9963
|
+
const amount2 = (term, path, value) => {
|
|
9964
|
+
const cents2 = abs(toUnits(value, 2));
|
|
9965
|
+
if (cents2 === 0n) return;
|
|
9966
|
+
values.push({
|
|
9967
|
+
term,
|
|
9968
|
+
path,
|
|
9969
|
+
// as the XML writes it and a reader expects it: `3760.40`, not `3760.4`
|
|
9970
|
+
value: withPlaces(value, 2),
|
|
9971
|
+
shown: amounts.has(cents2)
|
|
9972
|
+
});
|
|
9973
|
+
};
|
|
9974
|
+
const { totals: totals2 } = invoice;
|
|
9975
|
+
amount2("BT-109", "totals.tax_basis", totals2.tax_basis);
|
|
9976
|
+
amount2("BT-110", "totals.tax_total", totals2.tax_total);
|
|
9977
|
+
amount2("BT-112", "totals.grand", totals2.grand);
|
|
9978
|
+
if (toUnits(totals2.due, 2) !== toUnits(totals2.grand, 2))
|
|
9979
|
+
amount2("BT-115", "totals.due", totals2.due);
|
|
9980
|
+
if (invoice.breakdown.length > 1)
|
|
9981
|
+
invoice.breakdown.forEach(
|
|
9982
|
+
(row2, index) => amount2("BT-117", `tax.breakdown[${index}].amount`, row2.amount)
|
|
9983
|
+
);
|
|
9984
|
+
const unique = (terms) => [...new Set(terms)];
|
|
9985
|
+
return {
|
|
9986
|
+
checked: unique(values.map((value) => value.term)),
|
|
9987
|
+
missing: unique(
|
|
9988
|
+
values.filter((value) => !value.shown).map((value) => value.term)
|
|
9989
|
+
),
|
|
9990
|
+
values
|
|
9991
|
+
};
|
|
9992
|
+
}
|
|
9993
|
+
function displayMissingText(check) {
|
|
9994
|
+
const missing = check.values.filter((value) => !value.shown);
|
|
9995
|
+
if (missing.length === 0) return null;
|
|
9996
|
+
const named = missing.map(
|
|
9997
|
+
(value) => `the ${DISPLAY_TERMS[value.term] ?? value.term} ${value.value} (${value.term})`
|
|
9998
|
+
);
|
|
9999
|
+
const list3 = named.length === 1 ? named[0] : `${named.slice(0, -1).join(", ")} and ${named[named.length - 1]}`;
|
|
10000
|
+
return `The PDF does not show ${list3} of the e-invoice`;
|
|
10001
|
+
}
|
|
10002
|
+
|
|
10003
|
+
// packages/engine/src/lib/einvoice/locate.ts
|
|
10004
|
+
function invoicePathSegments(path) {
|
|
10005
|
+
const segments = [];
|
|
10006
|
+
for (const part of path.split(".")) {
|
|
10007
|
+
if (!part) continue;
|
|
10008
|
+
const match = /^([^[\]]*)((?:\[\d+\])*)$/.exec(part);
|
|
10009
|
+
if (!match) {
|
|
10010
|
+
segments.push(part);
|
|
10011
|
+
continue;
|
|
10012
|
+
}
|
|
10013
|
+
if (match[1]) segments.push(match[1]);
|
|
10014
|
+
for (const index of match[2]?.matchAll(/\[(\d+)\]/g) ?? [])
|
|
10015
|
+
segments.push(Number(index[1]));
|
|
10016
|
+
}
|
|
10017
|
+
return segments;
|
|
10018
|
+
}
|
|
10019
|
+
function locateJsonPath(text3, path) {
|
|
10020
|
+
let offset = skipSpace(text3, 0);
|
|
10021
|
+
if (offset >= text3.length) return null;
|
|
10022
|
+
let best = { offset, depth: 0 };
|
|
10023
|
+
try {
|
|
10024
|
+
for (let depth = 0; depth < path.length; depth += 1) {
|
|
10025
|
+
const segment = path[depth];
|
|
10026
|
+
const found = typeof segment === "number" ? arrayItem(text3, offset, segment) : objectMember(text3, offset, String(segment));
|
|
10027
|
+
if (!found) break;
|
|
10028
|
+
best = { offset: found.at, depth: depth + 1 };
|
|
10029
|
+
offset = found.value;
|
|
10030
|
+
}
|
|
10031
|
+
} catch {
|
|
10032
|
+
}
|
|
10033
|
+
return { ...positionAt(text3, best.offset), depth: best.depth };
|
|
10034
|
+
}
|
|
10035
|
+
function positionAt(text3, offset) {
|
|
10036
|
+
let line2 = 1;
|
|
10037
|
+
let lineStart = 0;
|
|
10038
|
+
for (let i = 0; i < offset; i += 1)
|
|
10039
|
+
if (text3.charCodeAt(i) === 10) {
|
|
10040
|
+
line2 += 1;
|
|
10041
|
+
lineStart = i + 1;
|
|
10042
|
+
}
|
|
10043
|
+
return { line: line2, column: offset - lineStart + 1 };
|
|
10044
|
+
}
|
|
10045
|
+
function skipSpace(text3, from) {
|
|
10046
|
+
let i = from;
|
|
10047
|
+
while (i < text3.length && /\s/.test(text3[i] ?? "")) i += 1;
|
|
10048
|
+
return i;
|
|
10049
|
+
}
|
|
10050
|
+
function stringEnd(text3, from) {
|
|
10051
|
+
if (text3[from] !== '"') throw new Error("string");
|
|
10052
|
+
for (let i = from + 1; i < text3.length; i += 1) {
|
|
10053
|
+
if (text3[i] === "\\") i += 1;
|
|
10054
|
+
else if (text3[i] === '"') return i + 1;
|
|
10055
|
+
}
|
|
10056
|
+
throw new Error("string");
|
|
10057
|
+
}
|
|
10058
|
+
function valueEnd(text3, from) {
|
|
10059
|
+
const start = skipSpace(text3, from);
|
|
10060
|
+
const first = text3[start];
|
|
10061
|
+
if (first === '"') return stringEnd(text3, start);
|
|
10062
|
+
if (first === "{" || first === "[") {
|
|
10063
|
+
const close = first === "{" ? "}" : "]";
|
|
10064
|
+
let i2 = skipSpace(text3, start + 1);
|
|
10065
|
+
if (text3[i2] === close) return i2 + 1;
|
|
10066
|
+
for (; ; ) {
|
|
10067
|
+
if (first === "{") {
|
|
10068
|
+
i2 = skipSpace(text3, stringEnd(text3, skipSpace(text3, i2)));
|
|
10069
|
+
if (text3[i2] !== ":") throw new Error("colon");
|
|
10070
|
+
i2 += 1;
|
|
10071
|
+
}
|
|
10072
|
+
i2 = skipSpace(text3, valueEnd(text3, i2));
|
|
10073
|
+
if (text3[i2] === close) return i2 + 1;
|
|
10074
|
+
if (text3[i2] !== ",") throw new Error("comma");
|
|
10075
|
+
i2 += 1;
|
|
10076
|
+
}
|
|
10077
|
+
}
|
|
10078
|
+
let i = start;
|
|
10079
|
+
while (i < text3.length && !/[\s,\]}]/.test(text3[i] ?? "")) i += 1;
|
|
10080
|
+
if (i === start) throw new Error("value");
|
|
10081
|
+
return i;
|
|
10082
|
+
}
|
|
10083
|
+
function objectMember(text3, from, key) {
|
|
10084
|
+
const start = skipSpace(text3, from);
|
|
10085
|
+
if (text3[start] !== "{") return null;
|
|
10086
|
+
let i = skipSpace(text3, start + 1);
|
|
10087
|
+
while (text3[i] !== "}") {
|
|
10088
|
+
const at = skipSpace(text3, i);
|
|
10089
|
+
const end = stringEnd(text3, at);
|
|
10090
|
+
const colon = skipSpace(text3, end);
|
|
10091
|
+
if (text3[colon] !== ":") throw new Error("colon");
|
|
10092
|
+
const value = skipSpace(text3, colon + 1);
|
|
10093
|
+
if (JSON.parse(text3.slice(at, end)) === key) return { at, value };
|
|
10094
|
+
i = skipSpace(text3, valueEnd(text3, value));
|
|
10095
|
+
if (text3[i] === ",") i = skipSpace(text3, i + 1);
|
|
10096
|
+
else if (text3[i] !== "}") throw new Error("comma");
|
|
10097
|
+
}
|
|
10098
|
+
return null;
|
|
10099
|
+
}
|
|
10100
|
+
function arrayItem(text3, from, index) {
|
|
10101
|
+
const start = skipSpace(text3, from);
|
|
10102
|
+
if (text3[start] !== "[") return null;
|
|
10103
|
+
let i = skipSpace(text3, start + 1);
|
|
10104
|
+
for (let n = 0; text3[i] !== "]"; n += 1) {
|
|
10105
|
+
const at = skipSpace(text3, i);
|
|
10106
|
+
if (n === index) return { at, value: at };
|
|
10107
|
+
i = skipSpace(text3, valueEnd(text3, at));
|
|
10108
|
+
if (text3[i] === ",") i = skipSpace(text3, i + 1);
|
|
10109
|
+
else if (text3[i] !== "]") throw new Error("comma");
|
|
10110
|
+
}
|
|
10111
|
+
return null;
|
|
10112
|
+
}
|
|
10113
|
+
|
|
10114
|
+
// packages/engine/src/lib/einvoice/report.ts
|
|
10115
|
+
var EINVOICE_MAX_MESSAGES = 50;
|
|
10116
|
+
function capMessages(messages, max2 = EINVOICE_MAX_MESSAGES) {
|
|
10117
|
+
const sorted = [
|
|
10118
|
+
...messages.filter((message) => message.severity === "error"),
|
|
10119
|
+
...messages.filter((message) => message.severity !== "error")
|
|
10120
|
+
];
|
|
10121
|
+
return sorted.length > max2 ? { messages: sorted.slice(0, max2), truncated: true } : { messages: sorted };
|
|
10122
|
+
}
|
|
10123
|
+
function einvoiceResult(options, specVersion, validation, display) {
|
|
10124
|
+
return {
|
|
10125
|
+
profile: options.profile,
|
|
10126
|
+
flavour: options.flavour,
|
|
10127
|
+
spec_version: specVersion,
|
|
10128
|
+
validation: validation ? {
|
|
10129
|
+
valid: validation.valid,
|
|
10130
|
+
schematron: validation.schematron,
|
|
10131
|
+
pdfa: validation.pdfa,
|
|
10132
|
+
...capMessages(validation.messages)
|
|
10133
|
+
} : null,
|
|
10134
|
+
display: display ? { checked: display.checked, missing: display.missing } : null
|
|
10135
|
+
};
|
|
10136
|
+
}
|
|
10137
|
+
var EINVOICE_FLAVOUR_NAMES = {
|
|
10138
|
+
"factur-x": "Factur-X",
|
|
10139
|
+
zugferd: "ZUGFeRD"
|
|
10140
|
+
};
|
|
10141
|
+
var EINVOICE_PROFILE_NAMES = {
|
|
10142
|
+
basic: "Basic",
|
|
10143
|
+
en16931: "EN 16931"
|
|
10144
|
+
};
|
|
10145
|
+
function invoiceLineOf(location) {
|
|
10146
|
+
if (!location) return null;
|
|
10147
|
+
const match = /IncludedSupplyChainTradeLineItem\[(\d+)\]/.exec(location);
|
|
10148
|
+
return match ? Number(match[1]) : null;
|
|
10149
|
+
}
|
|
10150
|
+
|
|
10151
|
+
// packages/engine/src/lib/einvoice/html-text.ts
|
|
10152
|
+
var INLINE = /* @__PURE__ */ new Set([
|
|
10153
|
+
"a",
|
|
10154
|
+
"abbr",
|
|
10155
|
+
"b",
|
|
10156
|
+
"bdi",
|
|
10157
|
+
"bdo",
|
|
10158
|
+
"cite",
|
|
10159
|
+
"code",
|
|
10160
|
+
"data",
|
|
10161
|
+
"del",
|
|
10162
|
+
"dfn",
|
|
10163
|
+
"em",
|
|
10164
|
+
"font",
|
|
10165
|
+
"i",
|
|
10166
|
+
"ins",
|
|
10167
|
+
"kbd",
|
|
10168
|
+
"label",
|
|
10169
|
+
"mark",
|
|
10170
|
+
"nobr",
|
|
10171
|
+
"output",
|
|
10172
|
+
"q",
|
|
10173
|
+
"s",
|
|
10174
|
+
"samp",
|
|
10175
|
+
"small",
|
|
10176
|
+
"span",
|
|
10177
|
+
"strong",
|
|
10178
|
+
"sub",
|
|
10179
|
+
"sup",
|
|
10180
|
+
"time",
|
|
10181
|
+
"tt",
|
|
10182
|
+
"u",
|
|
10183
|
+
"var",
|
|
10184
|
+
"wbr"
|
|
10185
|
+
]);
|
|
10186
|
+
var SKIPPED = ["script", "style", "template", "noscript", "head", "title"];
|
|
10187
|
+
var ENTITIES = {
|
|
10188
|
+
amp: 38,
|
|
10189
|
+
lt: 60,
|
|
10190
|
+
gt: 62,
|
|
10191
|
+
quot: 34,
|
|
10192
|
+
apos: 39,
|
|
10193
|
+
nbsp: 160,
|
|
10194
|
+
ensp: 8194,
|
|
10195
|
+
emsp: 8195,
|
|
10196
|
+
thinsp: 8201,
|
|
10197
|
+
shy: 173,
|
|
10198
|
+
minus: 8722,
|
|
10199
|
+
ndash: 8211,
|
|
10200
|
+
mdash: 8212,
|
|
10201
|
+
hyphen: 8208,
|
|
10202
|
+
euro: 8364,
|
|
10203
|
+
pound: 163,
|
|
10204
|
+
yen: 165,
|
|
10205
|
+
cent: 162,
|
|
10206
|
+
sect: 167,
|
|
10207
|
+
middot: 183,
|
|
10208
|
+
bull: 8226,
|
|
10209
|
+
times: 215,
|
|
10210
|
+
auml: 228,
|
|
10211
|
+
ouml: 246,
|
|
10212
|
+
uuml: 252,
|
|
10213
|
+
Auml: 196,
|
|
10214
|
+
Ouml: 214,
|
|
10215
|
+
Uuml: 220,
|
|
10216
|
+
szlig: 223,
|
|
10217
|
+
eacute: 233,
|
|
10218
|
+
egrave: 232,
|
|
10219
|
+
agrave: 224,
|
|
10220
|
+
ccedil: 231
|
|
10221
|
+
};
|
|
10222
|
+
function decodeEntities(text3) {
|
|
10223
|
+
return text3.replace(
|
|
10224
|
+
/&(#x[0-9a-f]+|#\d+|[a-z][a-z0-9]*);/gi,
|
|
10225
|
+
(whole, reference) => {
|
|
10226
|
+
const code = reference.startsWith("#") ? reference[1] === "x" || reference[1] === "X" ? Number.parseInt(reference.slice(2), 16) : Number.parseInt(reference.slice(1), 10) : ENTITIES[reference];
|
|
10227
|
+
return code !== void 0 && Number.isFinite(code) && code > 0 && code <= 1114111 ? String.fromCodePoint(code) : whole;
|
|
10228
|
+
}
|
|
10229
|
+
);
|
|
10230
|
+
}
|
|
10231
|
+
function htmlText(html) {
|
|
10232
|
+
let source = html.replace(/<!--[\s\S]*?-->/g, "");
|
|
10233
|
+
for (const tag2 of SKIPPED)
|
|
10234
|
+
source = source.replace(
|
|
10235
|
+
new RegExp(`<${tag2}\\b[^>]*>[\\s\\S]*?</${tag2}\\s*>`, "gi"),
|
|
10236
|
+
"\n"
|
|
10237
|
+
);
|
|
10238
|
+
let out = "";
|
|
10239
|
+
let position = 0;
|
|
10240
|
+
const tag = /<\/?([a-zA-Z][a-zA-Z0-9-]*)(?:"[^"]*"|'[^']*'|[^'">])*>/g;
|
|
10241
|
+
for (let match = tag.exec(source); match; match = tag.exec(source)) {
|
|
10242
|
+
out += source.slice(position, match.index);
|
|
10243
|
+
position = match.index + match[0].length;
|
|
10244
|
+
const name = (match[1] ?? "").toLowerCase();
|
|
10245
|
+
if (name === "br" || !INLINE.has(name)) out += "\n";
|
|
10246
|
+
}
|
|
10247
|
+
out += source.slice(position);
|
|
10248
|
+
return decodeEntities(out).split("\n").map((line2) => line2.replace(/[ \t\r\f]+/g, " ").trim()).filter((line2) => line2 !== "").join("\n");
|
|
10249
|
+
}
|
|
10250
|
+
|
|
10251
|
+
// packages/engine/src/lib/einvoice/skeleton.ts
|
|
10252
|
+
function invoiceSkeleton(issueDate = "2026-01-15") {
|
|
10253
|
+
const due = /* @__PURE__ */ new Date(`${issueDate}T00:00:00Z`);
|
|
10254
|
+
due.setUTCDate(due.getUTCDate() + 14);
|
|
10255
|
+
const number = `RE-${issueDate.slice(0, 4)}-0001`;
|
|
10256
|
+
return {
|
|
10257
|
+
number,
|
|
10258
|
+
issue_date: issueDate,
|
|
10259
|
+
type_code: "380",
|
|
10260
|
+
currency: "EUR",
|
|
10261
|
+
seller: {
|
|
10262
|
+
name: "Fennlor Studio GmbH",
|
|
10263
|
+
vat_id: "DE000000000",
|
|
10264
|
+
address: {
|
|
10265
|
+
street: "Musterstra\xDFe 1",
|
|
10266
|
+
postcode: "12345",
|
|
10267
|
+
city: "Musterstadt",
|
|
10268
|
+
country: "DE"
|
|
10269
|
+
},
|
|
10270
|
+
contact: {
|
|
10271
|
+
name: "Erika Mustermann",
|
|
10272
|
+
email: "rechnung@fennlor.example",
|
|
10273
|
+
phone: "+49 30 0000000"
|
|
10274
|
+
}
|
|
10275
|
+
},
|
|
10276
|
+
buyer: {
|
|
10277
|
+
name: "Olvarest GmbH",
|
|
10278
|
+
address: {
|
|
10279
|
+
street: "Beispielweg 2",
|
|
10280
|
+
postcode: "54321",
|
|
10281
|
+
city: "Beispielstadt",
|
|
10282
|
+
country: "DE"
|
|
10283
|
+
}
|
|
10284
|
+
},
|
|
10285
|
+
delivery: { date: issueDate },
|
|
10286
|
+
lines: [
|
|
10287
|
+
{
|
|
10288
|
+
id: "1",
|
|
10289
|
+
name: "Consulting",
|
|
10290
|
+
quantity: 8,
|
|
10291
|
+
unit_code: "HUR",
|
|
10292
|
+
net_price: 120,
|
|
10293
|
+
net_amount: 960,
|
|
10294
|
+
tax: { category: "S", rate: 19 }
|
|
10295
|
+
}
|
|
10296
|
+
],
|
|
10297
|
+
tax: {
|
|
10298
|
+
breakdown: [{ category: "S", rate: 19, basis: 960, amount: 182.4 }]
|
|
10299
|
+
},
|
|
10300
|
+
totals: {
|
|
10301
|
+
line_net: 960,
|
|
10302
|
+
tax_basis: 960,
|
|
10303
|
+
tax_total: 182.4,
|
|
10304
|
+
grand: 1142.4,
|
|
10305
|
+
due: 1142.4
|
|
10306
|
+
},
|
|
10307
|
+
payment: {
|
|
10308
|
+
means_code: "58",
|
|
10309
|
+
iban: "DE36000000000000000000",
|
|
10310
|
+
reference: number,
|
|
10311
|
+
terms: "Zahlbar innerhalb von 14 Tagen ohne Abzug",
|
|
10312
|
+
due_date: due.toISOString().slice(0, 10)
|
|
10313
|
+
}
|
|
10314
|
+
};
|
|
10315
|
+
}
|
|
10316
|
+
|
|
10317
|
+
// packages/engine/src/lib/einvoice/index.ts
|
|
10318
|
+
var INVOICE_DATA_KEY = "_invoice";
|
|
10319
|
+
var EINVOICE_SPEC_VERSIONS = {
|
|
10320
|
+
"factur-x": "1.09",
|
|
10321
|
+
zugferd: "2.5"
|
|
10322
|
+
};
|
|
10323
|
+
function invoiceAmountText(amount2) {
|
|
10324
|
+
return withPlaces(amount2, 2);
|
|
10325
|
+
}
|
|
10326
|
+
function einvoiceXml(data, options) {
|
|
10327
|
+
const block = data !== null && typeof data === "object" ? data[INVOICE_DATA_KEY] : void 0;
|
|
10328
|
+
if (block === void 0 || block === null)
|
|
10329
|
+
return {
|
|
10330
|
+
ok: false,
|
|
10331
|
+
problems: [
|
|
10332
|
+
{
|
|
10333
|
+
code: "missing",
|
|
10334
|
+
path: "",
|
|
10335
|
+
message: "The data has no _invoice block: an e-invoice is built from it",
|
|
10336
|
+
args: { path: "" }
|
|
10337
|
+
}
|
|
10338
|
+
]
|
|
10339
|
+
};
|
|
10340
|
+
const check = checkInvoice(block, options);
|
|
10341
|
+
if (!check.ok) return { ok: false, problems: check.problems };
|
|
10342
|
+
return {
|
|
10343
|
+
ok: true,
|
|
10344
|
+
xml: invoiceToCii(check.invoice, options),
|
|
10345
|
+
invoice: check.invoice
|
|
10346
|
+
};
|
|
10347
|
+
}
|
|
10348
|
+
|
|
8176
10349
|
// packages/engine/src/lib/office/errors.ts
|
|
8177
10350
|
var OfficeError = class extends Error {
|
|
8178
10351
|
constructor(code, message, details = {}) {
|
|
@@ -9492,12 +11665,12 @@ function assertWellFormed(tokens, part) {
|
|
|
9492
11665
|
}
|
|
9493
11666
|
var FORBIDDEN = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;
|
|
9494
11667
|
var ENTITY = /&(?:#x[0-9A-Fa-f]+|#\d+|amp|lt|gt|quot|apos);/y;
|
|
9495
|
-
function checkText(
|
|
9496
|
-
if (FORBIDDEN.test(
|
|
9497
|
-
if (
|
|
9498
|
-
for (let i =
|
|
11668
|
+
function checkText(text3, part) {
|
|
11669
|
+
if (FORBIDDEN.test(text3)) throw invalid2("a character XML does not allow", part);
|
|
11670
|
+
if (text3.includes("<")) throw invalid2("unescaped < in text", part);
|
|
11671
|
+
for (let i = text3.indexOf("&"); i !== -1; i = text3.indexOf("&", i + 1)) {
|
|
9499
11672
|
ENTITY.lastIndex = i;
|
|
9500
|
-
if (!ENTITY.test(
|
|
11673
|
+
if (!ENTITY.test(text3)) throw invalid2(`invalid entity reference near "${text3.slice(i, i + 12)}"`, part);
|
|
9501
11674
|
}
|
|
9502
11675
|
}
|
|
9503
11676
|
function checkAttributes(raw, part) {
|
|
@@ -9532,13 +11705,13 @@ function decodeText3(raw) {
|
|
|
9532
11705
|
}
|
|
9533
11706
|
});
|
|
9534
11707
|
}
|
|
9535
|
-
function
|
|
9536
|
-
return
|
|
11708
|
+
function escapeText3(text3) {
|
|
11709
|
+
return text3.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
9537
11710
|
}
|
|
9538
11711
|
var FORBIDDEN_GLOBAL = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g;
|
|
9539
|
-
function stripForbidden(
|
|
11712
|
+
function stripForbidden(text3) {
|
|
9540
11713
|
let removed = 0;
|
|
9541
|
-
const out =
|
|
11714
|
+
const out = text3.replace(FORBIDDEN_GLOBAL, () => {
|
|
9542
11715
|
removed++;
|
|
9543
11716
|
return "";
|
|
9544
11717
|
});
|
|
@@ -9751,7 +11924,7 @@ function textWidthEmu(xml2) {
|
|
|
9751
11924
|
function inlinePicture(picture, rId, id) {
|
|
9752
11925
|
const a = "http://schemas.openxmlformats.org/drawingml/2006/main";
|
|
9753
11926
|
const name = `Formfeed picture ${id}`;
|
|
9754
|
-
const alt =
|
|
11927
|
+
const alt = escapeText3(picture.alt).replace(/"/g, """);
|
|
9755
11928
|
const { widthEmu: cx, heightEmu: cy } = picture;
|
|
9756
11929
|
return `<w:drawing><wp:inline xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" distT="0" distB="0" distL="0" distR="0"><wp:extent cx="${cx}" cy="${cy}"/><wp:effectExtent l="0" t="0" r="0" b="0"/><wp:docPr id="${id}" name="${name}" descr="${alt}"/><wp:cNvGraphicFramePr><a:graphicFrameLocks xmlns:a="${a}" noChangeAspect="1"/></wp:cNvGraphicFramePr><a:graphic xmlns:a="${a}"><a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture"><pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"><pic:nvPicPr><pic:cNvPr id="${id}" name="${name}" descr="${alt}"/><pic:cNvPicPr/></pic:nvPicPr><pic:blipFill><a:blip r:embed="${rId}"/><a:stretch><a:fillRect/></a:stretch></pic:blipFill><pic:spPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="${cx}" cy="${cy}"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></pic:spPr></pic:pic></a:graphicData></a:graphic></wp:inline></w:drawing>`;
|
|
9757
11930
|
}
|
|
@@ -9789,13 +11962,13 @@ function placeDrawings(xml2, pattern, markupFor) {
|
|
|
9789
11962
|
pattern.lastIndex = 0;
|
|
9790
11963
|
if (pattern.test(t.raw)) {
|
|
9791
11964
|
const segments = t.raw.split(pattern);
|
|
9792
|
-
let
|
|
11965
|
+
let text3 = segments[0];
|
|
9793
11966
|
for (let s = 1; s < segments.length; s += 2) {
|
|
9794
11967
|
const index = Number(segments[s]);
|
|
9795
|
-
|
|
11968
|
+
text3 += `</w:t></w:r><w:r>${runProps}${markupFor(index)}</w:r>${runOpen}${runProps}<w:t xml:space="preserve">` + segments[s + 1];
|
|
9796
11969
|
}
|
|
9797
11970
|
out[textOpen] = withPreserve(out[textOpen]);
|
|
9798
|
-
out.push(
|
|
11971
|
+
out.push(text3);
|
|
9799
11972
|
continue;
|
|
9800
11973
|
}
|
|
9801
11974
|
}
|
|
@@ -9808,7 +11981,7 @@ function withPreserve(openTag) {
|
|
|
9808
11981
|
}
|
|
9809
11982
|
function withRelationships(rels2, relationships) {
|
|
9810
11983
|
const type = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image";
|
|
9811
|
-
const added = relationships.map((r) => `<Relationship Id="${r.id}" Type="${type}" Target="${
|
|
11984
|
+
const added = relationships.map((r) => `<Relationship Id="${r.id}" Type="${type}" Target="${escapeText3(r.target)}"/>`).join("");
|
|
9812
11985
|
if (!rels2)
|
|
9813
11986
|
return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">${added}</Relationships>`;
|
|
9814
11987
|
const end = rels2.lastIndexOf("</Relationships>");
|
|
@@ -10050,11 +12223,11 @@ function fromTemplateOutput(output, template, part) {
|
|
|
10050
12223
|
let last = 0;
|
|
10051
12224
|
let inText = false;
|
|
10052
12225
|
const emit = (segment) => {
|
|
10053
|
-
const { text:
|
|
12226
|
+
const { text: text3, removed } = stripForbidden(segment);
|
|
10054
12227
|
removedCharacters += removed;
|
|
10055
|
-
if (!inText &&
|
|
10056
|
-
throw new OfficeError("office_document_invalid", `${part ?? "part"}: text outside a text element: "${
|
|
10057
|
-
xml2 +=
|
|
12228
|
+
if (!inText && text3.trim() !== "")
|
|
12229
|
+
throw new OfficeError("office_document_invalid", `${part ?? "part"}: text outside a text element: "${text3.trim().slice(0, 40)}"`);
|
|
12230
|
+
xml2 += escapeText3(text3);
|
|
10058
12231
|
};
|
|
10059
12232
|
for (const m of output.matchAll(placeholder)) {
|
|
10060
12233
|
emit(output.slice(last, m.index));
|
|
@@ -10096,15 +12269,15 @@ function layoutText(xml2, flavour, part) {
|
|
|
10096
12269
|
out.push(token2.raw);
|
|
10097
12270
|
continue;
|
|
10098
12271
|
}
|
|
10099
|
-
const
|
|
12272
|
+
const text3 = token2.raw.replace(/\r\n?/g, "\n");
|
|
10100
12273
|
if (flavour === "wordprocessing") {
|
|
10101
|
-
const pieces =
|
|
10102
|
-
if (pieces.length > 1 || /^\s|\s$/.test(
|
|
12274
|
+
const pieces = text3.split(/(\n|\t)/);
|
|
12275
|
+
if (pieces.length > 1 || /^\s|\s$/.test(text3)) out[textOpenIndex] = preserveSpace(out[textOpenIndex]);
|
|
10103
12276
|
out.push(
|
|
10104
12277
|
pieces.map((p) => p === "\n" ? '</w:t><w:br/><w:t xml:space="preserve">' : p === " " ? '</w:t><w:tab/><w:t xml:space="preserve">' : p).join("")
|
|
10105
12278
|
);
|
|
10106
12279
|
} else {
|
|
10107
|
-
out.push(
|
|
12280
|
+
out.push(text3.split("\n").join(`</a:t></a:r><a:br>${runProperties}</a:br><a:r>${runProperties}<a:t>`));
|
|
10108
12281
|
}
|
|
10109
12282
|
}
|
|
10110
12283
|
return out.join("");
|
|
@@ -10137,17 +12310,17 @@ var AUTOCORRECTED = [
|
|
|
10137
12310
|
[/\u200B|\u200C|\u200D|\uFEFF/g, ""]
|
|
10138
12311
|
];
|
|
10139
12312
|
function normaliseTags(template, part) {
|
|
10140
|
-
const { text:
|
|
12313
|
+
const { text: text3, origin, placeholders } = stripPlaceholders(template);
|
|
10141
12314
|
const sourceRange = (from, to) => [
|
|
10142
12315
|
origin[from] ?? template.source.length,
|
|
10143
12316
|
(origin[to - 1] ?? template.source.length - 1) + 1
|
|
10144
12317
|
];
|
|
10145
12318
|
const diagnostics = [];
|
|
10146
12319
|
const edits = [];
|
|
10147
|
-
for (const tag of findTags(
|
|
12320
|
+
for (const tag of findTags(text3)) {
|
|
10148
12321
|
const inside = placeholders.filter((p) => p.at > tag.start && p.at < tag.end);
|
|
10149
12322
|
const paragraph2 = paragraphOf(template, placeholders, tag.start);
|
|
10150
|
-
const raw =
|
|
12323
|
+
const raw = text3.slice(tag.start, tag.end);
|
|
10151
12324
|
const unsafe = inside.filter((p) => {
|
|
10152
12325
|
const piece = template.markup[p.index];
|
|
10153
12326
|
return !piece || piece.paragraphBoundary || piece.containerBoundary;
|
|
@@ -10183,7 +12356,7 @@ function normaliseTags(template, part) {
|
|
|
10183
12356
|
for (const p of placeholders) {
|
|
10184
12357
|
const raw = template.markup[p.index]?.raw ?? "";
|
|
10185
12358
|
for (const m of raw.matchAll(/<w:instrText\b[^>]*>([^<]*)<\/w:instrText>/g)) {
|
|
10186
|
-
const code =
|
|
12359
|
+
const code = decodeEntities2(m[1] ?? "");
|
|
10187
12360
|
if (!/\{\{|\{%|\{#/.test(code)) continue;
|
|
10188
12361
|
const paragraph2 = paragraphOf(template, placeholders, p.at);
|
|
10189
12362
|
if (reported.has(paragraph2)) continue;
|
|
@@ -10200,38 +12373,38 @@ function normaliseTags(template, part) {
|
|
|
10200
12373
|
}
|
|
10201
12374
|
return { template: { ...template, source: applyEdits(template.source, edits) }, diagnostics };
|
|
10202
12375
|
}
|
|
10203
|
-
var
|
|
10204
|
-
function
|
|
10205
|
-
return
|
|
10206
|
-
if (name[0] !== "#") return
|
|
12376
|
+
var ENTITIES2 = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'" };
|
|
12377
|
+
function decodeEntities2(text3) {
|
|
12378
|
+
return text3.replace(/&(#x[0-9a-f]+|#\d+|amp|lt|gt|quot|apos);/gi, (whole, name) => {
|
|
12379
|
+
if (name[0] !== "#") return ENTITIES2[name.toLowerCase()] ?? whole;
|
|
10207
12380
|
const code = name[1] === "x" || name[1] === "X" ? parseInt(name.slice(2), 16) : parseInt(name.slice(1), 10);
|
|
10208
12381
|
return Number.isFinite(code) ? String.fromCodePoint(code) : whole;
|
|
10209
12382
|
});
|
|
10210
12383
|
}
|
|
10211
12384
|
function stripPlaceholders(template) {
|
|
10212
12385
|
const pattern = placeholderPattern(template.nonce);
|
|
10213
|
-
let
|
|
12386
|
+
let text3 = "";
|
|
10214
12387
|
const origin = [];
|
|
10215
12388
|
const placeholders = [];
|
|
10216
12389
|
let last = 0;
|
|
10217
12390
|
for (const m of template.source.matchAll(pattern)) {
|
|
10218
12391
|
for (let i = last; i < (m.index ?? 0); i++) {
|
|
10219
|
-
|
|
12392
|
+
text3 += template.source[i];
|
|
10220
12393
|
origin.push(i);
|
|
10221
12394
|
}
|
|
10222
|
-
placeholders.push({ index: Number(m[1]), at:
|
|
12395
|
+
placeholders.push({ index: Number(m[1]), at: text3.length, from: m.index ?? 0, to: (m.index ?? 0) + m[0].length });
|
|
10223
12396
|
last = (m.index ?? 0) + m[0].length;
|
|
10224
12397
|
}
|
|
10225
12398
|
for (let i = last; i < template.source.length; i++) {
|
|
10226
|
-
|
|
12399
|
+
text3 += template.source[i];
|
|
10227
12400
|
origin.push(i);
|
|
10228
12401
|
}
|
|
10229
|
-
return { text:
|
|
12402
|
+
return { text: text3, origin, placeholders };
|
|
10230
12403
|
}
|
|
10231
12404
|
function listTags(template, part) {
|
|
10232
|
-
const { text:
|
|
10233
|
-
return findTags(
|
|
10234
|
-
const raw =
|
|
12405
|
+
const { text: text3, placeholders } = stripPlaceholders(template);
|
|
12406
|
+
return findTags(text3).map((tag) => {
|
|
12407
|
+
const raw = text3.slice(tag.start, tag.end);
|
|
10235
12408
|
const kind = raw.startsWith("{#") ? "comment" : raw.startsWith("{%") || /^\{\{~?\s*[#/^]/.test(raw) || /^\{\{~?\s*else\b/.test(raw) ? "block" : "output";
|
|
10236
12409
|
return { part, paragraph: paragraphOf(template, placeholders, tag.start), text: raw.replace(/\s+/g, " ").trim(), kind };
|
|
10237
12410
|
});
|
|
@@ -10252,15 +12425,15 @@ function undoAutocorrect(tag) {
|
|
|
10252
12425
|
for (const [pattern, replacement] of AUTOCORRECTED) out = out.replace(pattern, replacement);
|
|
10253
12426
|
return out;
|
|
10254
12427
|
}
|
|
10255
|
-
function findTags(
|
|
12428
|
+
function findTags(text3) {
|
|
10256
12429
|
const tags = [];
|
|
10257
|
-
for (let i = 0; i <
|
|
10258
|
-
const opener = OPENERS.find((o) =>
|
|
12430
|
+
for (let i = 0; i < text3.length - 1; i++) {
|
|
12431
|
+
const opener = OPENERS.find((o) => text3.startsWith(o, i));
|
|
10259
12432
|
if (!opener) continue;
|
|
10260
12433
|
const closer = CLOSERS[opener];
|
|
10261
|
-
const end =
|
|
12434
|
+
const end = text3.indexOf(closer, i + opener.length);
|
|
10262
12435
|
if (end === -1) continue;
|
|
10263
|
-
const stop = end + closer.length + (opener === "{{" &&
|
|
12436
|
+
const stop = end + closer.length + (opener === "{{" && text3[end + closer.length] === "}" ? 1 : 0);
|
|
10264
12437
|
tags.push({ start: i, end: stop });
|
|
10265
12438
|
i = stop - 1;
|
|
10266
12439
|
}
|
|
@@ -10290,8 +12463,8 @@ var CONTENT = /* @__PURE__ */ new Set(["w:drawing", "w:pict", "w:object", "w:fld
|
|
|
10290
12463
|
var JINJA_OPEN = /^(for|if|unless|case|capture|raw|with|macro|call|filter|block|tablerow|comment|autoescape)\b/;
|
|
10291
12464
|
var JINJA_CLOSE = /^end(for|if|unless|case|capture|raw|with|macro|call|filter|block|tablerow|comment|autoescape)\b/;
|
|
10292
12465
|
var JINJA_MIDDLE = /^(else|elif|elsif|when)\b/;
|
|
10293
|
-
function blockRole(
|
|
10294
|
-
const t =
|
|
12466
|
+
function blockRole(text3) {
|
|
12467
|
+
const t = text3.trim();
|
|
10295
12468
|
let m = /^\{%-?\s*([\s\S]*?)\s*-?%\}$/.exec(t);
|
|
10296
12469
|
if (m && !t.slice(2, -2).includes("%}")) {
|
|
10297
12470
|
const body = m[1] ?? "";
|
|
@@ -10323,14 +12496,14 @@ function dropTaggedFallbacks(xml2, part) {
|
|
|
10323
12496
|
if (t.kind === "open" && t.name === "mc:Fallback" && !t.selfClosing) {
|
|
10324
12497
|
let depth = 1;
|
|
10325
12498
|
let j = i + 1;
|
|
10326
|
-
let
|
|
12499
|
+
let text3 = "";
|
|
10327
12500
|
for (; j < tokens.length && depth > 0; j++) {
|
|
10328
12501
|
const u = tokens[j];
|
|
10329
12502
|
if (u.kind === "open" && u.name === "mc:Fallback" && !u.selfClosing) depth++;
|
|
10330
12503
|
else if (u.kind === "close" && u.name === "mc:Fallback") depth--;
|
|
10331
|
-
else if (u.kind === "text")
|
|
12504
|
+
else if (u.kind === "text") text3 += decodeText3(u.raw);
|
|
10332
12505
|
}
|
|
10333
|
-
if (/\{\{|\{%|\{#/.test(
|
|
12506
|
+
if (/\{\{|\{%|\{#/.test(text3)) {
|
|
10334
12507
|
i = j - 1;
|
|
10335
12508
|
continue;
|
|
10336
12509
|
}
|
|
@@ -10397,15 +12570,15 @@ function applyStructure(xml2, part) {
|
|
|
10397
12570
|
}
|
|
10398
12571
|
}
|
|
10399
12572
|
const replacements = [];
|
|
10400
|
-
const element = (tag) => `<${STRUCTURAL_ELEMENT}>${
|
|
12573
|
+
const element = (tag) => `<${STRUCTURAL_ELEMENT}>${escapeText3(tag)}</${STRUCTURAL_ELEMENT}>`;
|
|
10401
12574
|
for (const [row2, tag] of replacedRows) replacements.push({ start: row2.start, end: row2.end, text: element(tag) });
|
|
10402
12575
|
const cellsEmptied = /* @__PURE__ */ new Map();
|
|
10403
12576
|
for (const [span, s] of structural) {
|
|
10404
12577
|
if (rowOf.has(span)) continue;
|
|
10405
12578
|
const keep = s.info.sectionProperties;
|
|
10406
|
-
let
|
|
10407
|
-
if (keep)
|
|
10408
|
-
replacements.push({ start: span.start, end: span.end, text:
|
|
12579
|
+
let text3 = element(s.tag);
|
|
12580
|
+
if (keep) text3 = s.role === "open" ? `<w:p>${keep}</w:p>${text3}` : `${text3}<w:p>${keep}</w:p>`;
|
|
12581
|
+
replacements.push({ start: span.start, end: span.end, text: text3 });
|
|
10409
12582
|
const holder = span.parent && BODIES.has(span.parent.name) ? span.parent : null;
|
|
10410
12583
|
if (holder && !keep) cellsEmptied.set(holder, (cellsEmptied.get(holder) ?? 0) + 1);
|
|
10411
12584
|
}
|
|
@@ -10459,7 +12632,7 @@ function collectParagraphs(tokens, root) {
|
|
|
10459
12632
|
const out = [];
|
|
10460
12633
|
const walk3 = (span) => {
|
|
10461
12634
|
if (PARAGRAPH.has(span.name)) {
|
|
10462
|
-
let
|
|
12635
|
+
let text3 = "";
|
|
10463
12636
|
let hasContent = false;
|
|
10464
12637
|
let sectionProperties = null;
|
|
10465
12638
|
let inText = false;
|
|
@@ -10470,10 +12643,10 @@ function collectParagraphs(tokens, root) {
|
|
|
10470
12643
|
else if (CONTENT.has(t.name)) hasContent = true;
|
|
10471
12644
|
else if (t.name === "w:sectPr") sectionProperties = "";
|
|
10472
12645
|
} else if (t.kind === "close" && TEXT.has(t.name)) inText = false;
|
|
10473
|
-
else if (t.kind === "text" && inText)
|
|
12646
|
+
else if (t.kind === "text" && inText) text3 += decodeText3(t.raw);
|
|
10474
12647
|
}
|
|
10475
12648
|
if (sectionProperties !== null) sectionProperties = propertiesOf(tokens, span);
|
|
10476
|
-
out.push({ span, number: out.length + 1, text:
|
|
12649
|
+
out.push({ span, number: out.length + 1, text: text3, hasContent, sectionProperties });
|
|
10477
12650
|
}
|
|
10478
12651
|
for (const child2 of span.children) walk3(child2);
|
|
10479
12652
|
};
|
|
@@ -10495,9 +12668,9 @@ function isInside(span, container) {
|
|
|
10495
12668
|
function rewrite(tokens, replacements) {
|
|
10496
12669
|
const byStart = /* @__PURE__ */ new Map();
|
|
10497
12670
|
for (const r of replacements) {
|
|
10498
|
-
const
|
|
10499
|
-
|
|
10500
|
-
byStart.set(r.start,
|
|
12671
|
+
const list3 = byStart.get(r.start) ?? [];
|
|
12672
|
+
list3.push({ end: r.end, text: r.text });
|
|
12673
|
+
byStart.set(r.start, list3);
|
|
10501
12674
|
}
|
|
10502
12675
|
let out = "";
|
|
10503
12676
|
for (let i = 0; i < tokens.length; i++) {
|
|
@@ -10546,7 +12719,7 @@ function boxOf(container, tokens) {
|
|
|
10546
12719
|
return x === null || y === null || cx === null || cy === null ? null : { x, y, cx, cy };
|
|
10547
12720
|
}
|
|
10548
12721
|
function slidePicture(picture, rId, id, box) {
|
|
10549
|
-
const alt =
|
|
12722
|
+
const alt = escapeText3(picture.alt).replace(/"/g, """);
|
|
10550
12723
|
return `<p:pic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><p:nvPicPr><p:cNvPr id="${id}" name="Formfeed picture ${id}" descr="${alt}"/><p:cNvPicPr><a:picLocks noChangeAspect="1"/></p:cNvPicPr><p:nvPr/></p:nvPicPr><p:blipFill><a:blip r:embed="${rId}"/><a:stretch><a:fillRect/></a:stretch></p:blipFill><p:spPr><a:xfrm><a:off x="${box.x}" y="${box.y}"/><a:ext cx="${box.cx}" cy="${box.cy}"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></p:spPr></p:pic>`;
|
|
10551
12724
|
}
|
|
10552
12725
|
function layoutPictures(pictures, box, growsWithText = false) {
|
|
@@ -10581,7 +12754,7 @@ function placeSlidePictures(xml2, pattern, drawingFor, pictureMarkup, slide) {
|
|
|
10581
12754
|
for (const container of containers) {
|
|
10582
12755
|
const indexes = [];
|
|
10583
12756
|
const edits = [];
|
|
10584
|
-
let
|
|
12757
|
+
let text3 = "";
|
|
10585
12758
|
let inText = false;
|
|
10586
12759
|
for (let i = container.start + 1; i < container.end; i++) {
|
|
10587
12760
|
const t = tokens[i];
|
|
@@ -10590,7 +12763,7 @@ function placeSlidePictures(xml2, pattern, drawingFor, pictureMarkup, slide) {
|
|
|
10590
12763
|
else if (t.kind === "text" && inText) {
|
|
10591
12764
|
pattern.lastIndex = 0;
|
|
10592
12765
|
if (!pattern.test(t.raw)) {
|
|
10593
|
-
|
|
12766
|
+
text3 += decodeText3(t.raw);
|
|
10594
12767
|
continue;
|
|
10595
12768
|
}
|
|
10596
12769
|
const segments = t.raw.split(pattern);
|
|
@@ -10599,7 +12772,7 @@ function placeSlidePictures(xml2, pattern, drawingFor, pictureMarkup, slide) {
|
|
|
10599
12772
|
if (s % 2 === 1) indexes.push(Number(segments[s]));
|
|
10600
12773
|
else kept += segments[s];
|
|
10601
12774
|
}
|
|
10602
|
-
|
|
12775
|
+
text3 += decodeText3(kept);
|
|
10603
12776
|
edits.push({ at: i, raw: kept });
|
|
10604
12777
|
}
|
|
10605
12778
|
}
|
|
@@ -10618,7 +12791,7 @@ function placeSlidePictures(xml2, pattern, drawingFor, pictureMarkup, slide) {
|
|
|
10618
12791
|
}
|
|
10619
12792
|
const autoFit = tokens.slice(container.start, container.end).some((t) => t.kind === "open" && t.name === "a:spAutoFit");
|
|
10620
12793
|
const placed = layoutPictures(pictures, box, autoFit).map((b, i) => pictureMarkup(pictures[i], b)).join("");
|
|
10621
|
-
const onlyPictures = container.name === "p:sp" &&
|
|
12794
|
+
const onlyPictures = container.name === "p:sp" && text3.trim() === "";
|
|
10622
12795
|
if (onlyPictures) replacements.push({ start: container.start, end: container.end, text: placed });
|
|
10623
12796
|
else {
|
|
10624
12797
|
for (const edit of edits) replacements.push({ start: edit.at, end: edit.at, text: edit.raw });
|
|
@@ -10891,8 +13064,8 @@ function starterTags(engine) {
|
|
|
10891
13064
|
codeFit: engine === "liquid" ? "{{ offer.url | qrcode }}" : "{{ qrcode(offer.url) }}"
|
|
10892
13065
|
};
|
|
10893
13066
|
}
|
|
10894
|
-
var paragraph = (
|
|
10895
|
-
var cell = (
|
|
13067
|
+
var paragraph = (text3, style2, bold = false) => `<w:p>${style2 ? `<w:pPr><w:pStyle w:val="${style2}"/></w:pPr>` : ""}<w:r>${bold ? "<w:rPr><w:b/></w:rPr>" : ""}<w:t xml:space="preserve">${escapeText3(text3)}</w:t></w:r></w:p>`;
|
|
13068
|
+
var cell = (text3, width, bold = false) => `<w:tc><w:tcPr><w:tcW w:w="${width}" w:type="dxa"/></w:tcPr>${paragraph(text3, void 0, bold)}</w:tc>`;
|
|
10896
13069
|
var row = (cells) => `<w:tr>${cells}</w:tr>`;
|
|
10897
13070
|
function starterDocument(engine) {
|
|
10898
13071
|
const t = starterTags(engine);
|
|
@@ -10935,7 +13108,7 @@ function starterDocument(engine) {
|
|
|
10935
13108
|
["word/document.xml", `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w:document xmlns:w="${W}"><w:body>${body}</w:body></w:document>`]
|
|
10936
13109
|
];
|
|
10937
13110
|
return {
|
|
10938
|
-
bytes: writeZip(files.map(([name,
|
|
13111
|
+
bytes: writeZip(files.map(([name, text3]) => ({ name, data: encoder2.encode(text3) }))),
|
|
10939
13112
|
sampleData: starterSampleData()
|
|
10940
13113
|
};
|
|
10941
13114
|
}
|
|
@@ -10963,15 +13136,15 @@ var CM = 36e4;
|
|
|
10963
13136
|
var FONT = "Carlito";
|
|
10964
13137
|
var ACCENT = "0F766E";
|
|
10965
13138
|
var emptyTree = '<p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr><p:grpSpPr/>';
|
|
10966
|
-
var run = (
|
|
10967
|
-
var para = (
|
|
13139
|
+
var run = (text3, size, options = {}) => `<a:r><a:rPr lang="en-GB" sz="${size * 100}"${options.bold ? ' b="1"' : ""} dirty="0">${options.color ? `<a:solidFill><a:srgbClr val="${options.color}"/></a:solidFill>` : ""}<a:latin typeface="${FONT}"/></a:rPr><a:t>${escapeText3(text3)}</a:t></a:r>`;
|
|
13140
|
+
var para = (text3, size, options = {}) => `<a:p>${run(text3, size, options)}</a:p>`;
|
|
10968
13141
|
function textBox(id, name, x, y, cx, cy, paragraphs) {
|
|
10969
13142
|
return `<p:sp><p:nvSpPr><p:cNvPr id="${id}" name="${name}"/><p:cNvSpPr txBox="1"/><p:nvPr/></p:nvSpPr><p:spPr><a:xfrm><a:off x="${x}" y="${y}"/><a:ext cx="${cx}" cy="${cy}"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom><a:noFill/></p:spPr><p:txBody><a:bodyPr wrap="square" rtlCol="0"><a:noAutofit/></a:bodyPr><a:lstStyle/>${paragraphs}</p:txBody></p:sp>`;
|
|
10970
13143
|
}
|
|
10971
|
-
function cell2(
|
|
13144
|
+
function cell2(text3, header) {
|
|
10972
13145
|
const fill = header ? `<a:solidFill><a:srgbClr val="${ACCENT}"/></a:solidFill>` : "<a:noFill/>";
|
|
10973
|
-
const
|
|
10974
|
-
return `<a:tc><a:txBody><a:bodyPr/><a:lstStyle/>${para(
|
|
13146
|
+
const line2 = `<a:lnB w="6350"><a:solidFill><a:srgbClr val="BFBFBF"/></a:solidFill></a:lnB>`;
|
|
13147
|
+
return `<a:tc><a:txBody><a:bodyPr/><a:lstStyle/>${para(text3, 14, header ? { bold: true, color: "FFFFFF" } : {})}</a:txBody><a:tcPr marL="91440" marR="91440" marT="45720" marB="45720">${line2}${fill}</a:tcPr></a:tc>`;
|
|
10975
13148
|
}
|
|
10976
13149
|
var tableRow = (a, b, header = false) => `<a:tr h="${Math.round(0.9 * CM)}">${cell2(a, header)}${cell2(b, header)}</a:tr>`;
|
|
10977
13150
|
function table2(id, x, y, rows) {
|
|
@@ -10981,8 +13154,8 @@ function table2(id, x, y, rows) {
|
|
|
10981
13154
|
function theme() {
|
|
10982
13155
|
const scheme = (name, color) => `<a:${name}><a:srgbClr val="${color}"/></a:${name}>`;
|
|
10983
13156
|
const fill = `<a:solidFill><a:schemeClr val="phClr"/></a:solidFill>`;
|
|
10984
|
-
const
|
|
10985
|
-
return `<a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="Formfeed"><a:themeElements><a:clrScheme name="Formfeed">${scheme("dk1", "000000")}${scheme("lt1", "FFFFFF")}${scheme("dk2", "1F2937")}${scheme("lt2", "F3F4F6")}${scheme("accent1", ACCENT)}${scheme("accent2", "F59E0B")}${scheme("accent3", "2563EB")}${scheme("accent4", "DC2626")}${scheme("accent5", "7C3AED")}${scheme("accent6", "059669")}${scheme("hlink", "2563EB")}${scheme("folHlink", "7C3AED")}</a:clrScheme><a:fontScheme name="Formfeed"><a:majorFont><a:latin typeface="${FONT}"/><a:ea typeface=""/><a:cs typeface=""/></a:majorFont><a:minorFont><a:latin typeface="${FONT}"/><a:ea typeface=""/><a:cs typeface=""/></a:minorFont></a:fontScheme><a:fmtScheme name="Formfeed"><a:fillStyleLst>${fill}${fill}${fill}</a:fillStyleLst><a:lnStyleLst>${
|
|
13157
|
+
const line2 = `<a:ln w="6350"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:ln>`;
|
|
13158
|
+
return `<a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="Formfeed"><a:themeElements><a:clrScheme name="Formfeed">${scheme("dk1", "000000")}${scheme("lt1", "FFFFFF")}${scheme("dk2", "1F2937")}${scheme("lt2", "F3F4F6")}${scheme("accent1", ACCENT)}${scheme("accent2", "F59E0B")}${scheme("accent3", "2563EB")}${scheme("accent4", "DC2626")}${scheme("accent5", "7C3AED")}${scheme("accent6", "059669")}${scheme("hlink", "2563EB")}${scheme("folHlink", "7C3AED")}</a:clrScheme><a:fontScheme name="Formfeed"><a:majorFont><a:latin typeface="${FONT}"/><a:ea typeface=""/><a:cs typeface=""/></a:majorFont><a:minorFont><a:latin typeface="${FONT}"/><a:ea typeface=""/><a:cs typeface=""/></a:minorFont></a:fontScheme><a:fmtScheme name="Formfeed"><a:fillStyleLst>${fill}${fill}${fill}</a:fillStyleLst><a:lnStyleLst>${line2}${line2}${line2}</a:lnStyleLst><a:effectStyleLst><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle></a:effectStyleLst><a:bgFillStyleLst>${fill}${fill}${fill}</a:bgFillStyleLst></a:fmtScheme></a:themeElements></a:theme>`;
|
|
10986
13159
|
}
|
|
10987
13160
|
var xml = (body) => `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>${body}`;
|
|
10988
13161
|
var rels = (entries) => xml(
|
|
@@ -11061,7 +13234,7 @@ function starterPresentation(engine) {
|
|
|
11061
13234
|
];
|
|
11062
13235
|
const encoder2 = new TextEncoder();
|
|
11063
13236
|
return {
|
|
11064
|
-
bytes: writeZip(files.map(([name,
|
|
13237
|
+
bytes: writeZip(files.map(([name, text3]) => ({ name, data: encoder2.encode(text3) }))),
|
|
11065
13238
|
sampleData: starterSampleData()
|
|
11066
13239
|
};
|
|
11067
13240
|
}
|