@formfeed/engine 0.3.11 → 0.3.13
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 +2872 -280
- package/index.js +2872 -280
- package/package.json +3 -2
- package/types/frame/audit.d.cts +15 -0
- package/types/frame/audit.d.ts +15 -0
- package/types/frame/audit.entry.d.cts +1 -0
- package/types/frame/audit.entry.d.ts +1 -0
- package/types/frame/text-edit.d.cts +8 -1
- package/types/frame/text-edit.d.ts +8 -1
- package/types/index.d.cts +8 -1
- package/types/index.d.ts +8 -1
- package/types/lib/accessibility/index.d.cts +201 -0
- package/types/lib/accessibility/index.d.ts +201 -0
- package/types/lib/accessibility/static.d.cts +40 -0
- package/types/lib/accessibility/static.d.ts +40 -0
- package/types/lib/assemble.d.cts +16 -0
- package/types/lib/assemble.d.ts +16 -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 +4 -2
- package/types/lib/generated/frames.d.ts +4 -2
- package/types/lib/helpers/document.d.cts +5 -0
- package/types/lib/helpers/document.d.ts +5 -0
- package/types/lib/preview.d.cts +11 -0
- package/types/lib/preview.d.ts +11 -0
- package/types/lib/source-edit.d.cts +5 -0
- package/types/lib/source-edit.d.ts +5 -0
package/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// packages/engine/src/lib/errors.ts
|
|
2
2
|
var EngineSyntaxError = class extends Error {
|
|
3
|
-
constructor(engine, message,
|
|
3
|
+
constructor(engine, message, line2, column) {
|
|
4
4
|
super(message);
|
|
5
5
|
this.engine = engine;
|
|
6
|
-
this.line =
|
|
6
|
+
this.line = line2;
|
|
7
7
|
this.column = column;
|
|
8
8
|
}
|
|
9
9
|
name = "EngineSyntaxError";
|
|
@@ -19,10 +19,10 @@ var RenderLimitError = class extends Error {
|
|
|
19
19
|
name = "RenderLimitError";
|
|
20
20
|
};
|
|
21
21
|
var RenderError = class extends Error {
|
|
22
|
-
constructor(engine, message,
|
|
22
|
+
constructor(engine, message, line2, column) {
|
|
23
23
|
super(message);
|
|
24
24
|
this.engine = engine;
|
|
25
|
-
this.line =
|
|
25
|
+
this.line = line2;
|
|
26
26
|
this.column = column;
|
|
27
27
|
}
|
|
28
28
|
name = "RenderError";
|
|
@@ -91,7 +91,7 @@ function toNumber(value) {
|
|
|
91
91
|
|
|
92
92
|
// packages/engine/src/lib/codes/epc.ts
|
|
93
93
|
function epcPayload(input) {
|
|
94
|
-
const
|
|
94
|
+
const amount2 = input.amount === void 0 || input.amount === "" ? "" : `EUR${toNumber(input.amount).toFixed(2)}`;
|
|
95
95
|
return [
|
|
96
96
|
"BCD",
|
|
97
97
|
"002",
|
|
@@ -100,7 +100,7 @@ function epcPayload(input) {
|
|
|
100
100
|
(input.bic ?? "").replace(/\s/g, ""),
|
|
101
101
|
String(input.name ?? "").slice(0, 70),
|
|
102
102
|
String(input.iban ?? "").replace(/\s/g, ""),
|
|
103
|
-
|
|
103
|
+
amount2,
|
|
104
104
|
(input.purpose ?? "").slice(0, 4),
|
|
105
105
|
(input.reference ?? "").slice(0, 35),
|
|
106
106
|
input.reference ? "" : (input.text ?? "").slice(0, 140),
|
|
@@ -150,9 +150,9 @@ var IBAN_LENGTHS = {
|
|
|
150
150
|
};
|
|
151
151
|
var EPC_MAX_BYTES = 331;
|
|
152
152
|
var byteLength = (value) => new TextEncoder().encode(value).length;
|
|
153
|
-
var normaliseIban = (
|
|
154
|
-
function ibanChecksum(
|
|
155
|
-
const rearranged = normaliseIban(
|
|
153
|
+
var normaliseIban = (iban2) => iban2.replace(/\s/g, "").toUpperCase();
|
|
154
|
+
function ibanChecksum(iban2) {
|
|
155
|
+
const rearranged = normaliseIban(iban2).slice(4) + normaliseIban(iban2).slice(0, 4);
|
|
156
156
|
const digits = [...rearranged].map((c) => c >= "A" && c <= "Z" ? String(c.charCodeAt(0) - 55) : c).join("");
|
|
157
157
|
let remainder = 0;
|
|
158
158
|
for (const digit of digits) remainder = (remainder * 10 + Number(digit)) % 97;
|
|
@@ -163,30 +163,30 @@ function validateEpc(input) {
|
|
|
163
163
|
const name = String(input.name ?? "").trim();
|
|
164
164
|
if (!name) problems.push({ field: "name", code: "required" });
|
|
165
165
|
else if (name.length > 70) problems.push({ field: "name", code: "too_long", max: 70, actual: name.length });
|
|
166
|
-
const
|
|
167
|
-
if (!
|
|
168
|
-
else if (!/^[A-Z]{2}[0-9]{2}[A-Z0-9]{11,30}$/.test(
|
|
166
|
+
const iban2 = normaliseIban(String(input.iban ?? ""));
|
|
167
|
+
if (!iban2) problems.push({ field: "iban", code: "required" });
|
|
168
|
+
else if (!/^[A-Z]{2}[0-9]{2}[A-Z0-9]{11,30}$/.test(iban2)) problems.push({ field: "iban", code: "iban_characters" });
|
|
169
169
|
else {
|
|
170
|
-
const expected = IBAN_LENGTHS[
|
|
171
|
-
if (expected !== void 0 &&
|
|
172
|
-
problems.push({ field: "iban", code: "iban_country_length", max: expected, actual:
|
|
173
|
-
else if (!ibanChecksum(
|
|
170
|
+
const expected = IBAN_LENGTHS[iban2.slice(0, 2)];
|
|
171
|
+
if (expected !== void 0 && iban2.length !== expected)
|
|
172
|
+
problems.push({ field: "iban", code: "iban_country_length", max: expected, actual: iban2.length });
|
|
173
|
+
else if (!ibanChecksum(iban2)) problems.push({ field: "iban", code: "iban_checksum" });
|
|
174
174
|
}
|
|
175
175
|
const bic = String(input.bic ?? "").replace(/\s/g, "").toUpperCase();
|
|
176
176
|
if (bic && !/^[A-Z]{6}[A-Z0-9]{2}([A-Z0-9]{3})?$/.test(bic)) problems.push({ field: "bic", code: "bic_format" });
|
|
177
177
|
if (input.amount !== void 0 && input.amount !== "") {
|
|
178
|
-
const
|
|
179
|
-
if (Number.isNaN(
|
|
180
|
-
else if (
|
|
178
|
+
const amount2 = toNumber(input.amount);
|
|
179
|
+
if (Number.isNaN(amount2)) problems.push({ field: "amount", code: "not_a_number" });
|
|
180
|
+
else if (amount2 < 0.01 || amount2 > 99999999999e-2) problems.push({ field: "amount", code: "out_of_range" });
|
|
181
181
|
}
|
|
182
182
|
const purpose = String(input.purpose ?? "");
|
|
183
183
|
if (purpose.length > 4) problems.push({ field: "purpose", code: "too_long", max: 4, actual: purpose.length });
|
|
184
184
|
const reference = String(input.reference ?? "").trim();
|
|
185
|
-
const
|
|
186
|
-
if (reference &&
|
|
185
|
+
const text4 = String(input.text ?? "").trim();
|
|
186
|
+
if (reference && text4) problems.push({ field: "reference", code: "reference_or_text" });
|
|
187
187
|
if (reference.length > 35)
|
|
188
188
|
problems.push({ field: "reference", code: "too_long", max: 35, actual: reference.length });
|
|
189
|
-
if (
|
|
189
|
+
if (text4.length > 140) problems.push({ field: "text", code: "too_long", max: 140, actual: text4.length });
|
|
190
190
|
const bytes = byteLength(epcPayload(input));
|
|
191
191
|
if (bytes > EPC_MAX_BYTES)
|
|
192
192
|
problems.push({ field: "payload", code: "too_long", max: EPC_MAX_BYTES, actual: bytes });
|
|
@@ -224,9 +224,12 @@ var barcodeTypes = {
|
|
|
224
224
|
};
|
|
225
225
|
var ownTextLayout = /* @__PURE__ */ new Set(["ean13", "ean8", "upca"]);
|
|
226
226
|
function codeText(helper, value) {
|
|
227
|
-
const
|
|
228
|
-
if (
|
|
229
|
-
|
|
227
|
+
const text4 = value === void 0 || value === null ? "" : String(value);
|
|
228
|
+
if (text4 === "")
|
|
229
|
+
throw new Error(
|
|
230
|
+
`${helper}: nothing to encode, the value is empty or missing from the data`
|
|
231
|
+
);
|
|
232
|
+
return text4;
|
|
230
233
|
}
|
|
231
234
|
var codeHelpers = [
|
|
232
235
|
{
|
|
@@ -234,18 +237,25 @@ var codeHelpers = [
|
|
|
234
237
|
aliases: ["qr"],
|
|
235
238
|
doc: {
|
|
236
239
|
signature: "qrcode(value, { size = 160, ecc = 'M', margin = 1, color, background })",
|
|
237
|
-
description: "QR code as an SVG data URI for an <img> src.",
|
|
240
|
+
description: "QR code as an SVG data URI for an <img> src. Give the image an `alt` that says where the code leads: a screen reader cannot scan it.",
|
|
238
241
|
examples: {
|
|
239
|
-
jinja2: '<img src="{{ qrcode(order.url, { size: 120 }) }}">',
|
|
240
|
-
liquid: '<img src="{{ order.url | qrcode: size: 120 }}">',
|
|
241
|
-
handlebars: '<img src="{{qrcode order.url size=120}}">'
|
|
242
|
+
jinja2: '<img src="{{ qrcode(order.url, { size: 120 }) }}" alt="QR code: {{ order.url }}">',
|
|
243
|
+
liquid: '<img src="{{ order.url | qrcode: size: 120 }}" alt="QR code: {{ order.url }}">',
|
|
244
|
+
handlebars: '<img src="{{qrcode order.url size=120}}" alt="QR code: {{order.url}}">'
|
|
242
245
|
},
|
|
243
246
|
category: "code"
|
|
244
247
|
},
|
|
245
248
|
fn: (ctx, value, options) => {
|
|
246
249
|
const o = options ?? {};
|
|
247
250
|
const svg = qrSvg(codeText("qrcode", value), o);
|
|
248
|
-
if (ctx.drawing)
|
|
251
|
+
if (ctx.drawing)
|
|
252
|
+
return ctx.drawing({
|
|
253
|
+
kind: "svg",
|
|
254
|
+
svg,
|
|
255
|
+
width: o.size,
|
|
256
|
+
height: o.size,
|
|
257
|
+
alt: "QR code"
|
|
258
|
+
});
|
|
249
259
|
return svgDataUri(svg);
|
|
250
260
|
}
|
|
251
261
|
},
|
|
@@ -253,28 +263,29 @@ var codeHelpers = [
|
|
|
253
263
|
name: "barcode",
|
|
254
264
|
doc: {
|
|
255
265
|
signature: "barcode(value, { type = 'code128', height = 12, width, text = true, scale = 2 })",
|
|
256
|
-
description: "Barcode (code128, ean13, ean8, upc, itf14, code39, datamatrix, pdf417) as an SVG data URI.",
|
|
266
|
+
description: "Barcode (code128, ean13, ean8, upc, itf14, code39, datamatrix, pdf417) as an SVG data URI. Give the image an `alt` with the value it encodes.",
|
|
257
267
|
examples: {
|
|
258
|
-
jinja2: `<img src="{{ barcode(item.sku, { type: 'code128' }) }}">`,
|
|
259
|
-
liquid: `<img src="{{ item.sku | barcode: type: 'code128' }}">`,
|
|
260
|
-
handlebars: `<img src="{{barcode item.sku type='code128'}}">`
|
|
268
|
+
jinja2: `<img src="{{ barcode(item.sku, { type: 'code128' }) }}" alt="Barcode {{ item.sku }}">`,
|
|
269
|
+
liquid: `<img src="{{ item.sku | barcode: type: 'code128' }}" alt="Barcode {{ item.sku }}">`,
|
|
270
|
+
handlebars: `<img src="{{barcode item.sku type='code128'}}" alt="Barcode {{item.sku}}">`
|
|
261
271
|
},
|
|
262
272
|
category: "code"
|
|
263
273
|
},
|
|
264
274
|
fn: (ctx, value, options) => {
|
|
265
275
|
const o = options ?? {};
|
|
266
276
|
const bcid = barcodeTypes[String(o.type ?? "code128").toLowerCase()] ?? "code128";
|
|
267
|
-
const
|
|
277
|
+
const text4 = codeText("barcode", value);
|
|
268
278
|
const svg = toSVG({
|
|
269
279
|
bcid,
|
|
270
|
-
text:
|
|
280
|
+
text: text4,
|
|
271
281
|
height: o.height ?? 12,
|
|
272
282
|
...o.width === void 0 ? {} : { width: o.width },
|
|
273
283
|
scale: o.scale ?? 2,
|
|
274
284
|
includetext: o.text !== false,
|
|
275
285
|
...ownTextLayout.has(bcid) ? {} : { textxalign: "center" }
|
|
276
286
|
});
|
|
277
|
-
if (ctx.drawing)
|
|
287
|
+
if (ctx.drawing)
|
|
288
|
+
return ctx.drawing({ kind: "svg", svg, alt: `Barcode ${text4}` });
|
|
278
289
|
return svgDataUri(svg);
|
|
279
290
|
}
|
|
280
291
|
},
|
|
@@ -283,11 +294,11 @@ var codeHelpers = [
|
|
|
283
294
|
aliases: ["epc_qr", "girocode"],
|
|
284
295
|
doc: {
|
|
285
296
|
signature: "epcQr({ name, iban, bic?, amount?, reference?, text? }, { size })",
|
|
286
|
-
description: "SEPA credit transfer QR code (EPC069-12 / GiroCode) that banking apps scan to prefill a payment.",
|
|
297
|
+
description: "SEPA credit transfer QR code (EPC069-12 / GiroCode) that banking apps scan to prefill a payment. Give the image an `alt`, and print the bank details as text as well: the code is a picture.",
|
|
287
298
|
examples: {
|
|
288
|
-
jinja2: '<img src="{{ epcQr({ name: company.name, iban: company.iban, amount: invoice.total, reference: invoice.number }) }}">',
|
|
289
|
-
liquid: '<img src="{{ company.iban | epcQr: name: company.name, amount: invoice.total, reference: invoice.number }}">',
|
|
290
|
-
handlebars: '<img src="{{epcQr name=company.name iban=company.iban amount=invoice.total reference=invoice.number}}">'
|
|
299
|
+
jinja2: '<img src="{{ epcQr({ name: company.name, iban: company.iban, amount: invoice.total, reference: invoice.number }) }}" alt="QR code to pay invoice {{ invoice.number }}">',
|
|
300
|
+
liquid: '<img src="{{ company.iban | epcQr: name: company.name, amount: invoice.total, reference: invoice.number }}" alt="QR code to pay invoice {{ invoice.number }}">',
|
|
301
|
+
handlebars: '<img src="{{epcQr name=company.name iban=company.iban amount=invoice.total reference=invoice.number}}" alt="QR code to pay invoice {{invoice.number}}">'
|
|
291
302
|
},
|
|
292
303
|
category: "code"
|
|
293
304
|
},
|
|
@@ -300,18 +311,33 @@ var codeHelpers = [
|
|
|
300
311
|
...input && typeof input === "object" ? input : typeof input === "string" && input ? { iban: input } : {},
|
|
301
312
|
...options ?? {}
|
|
302
313
|
};
|
|
303
|
-
const
|
|
314
|
+
const payment2 = {};
|
|
304
315
|
const qr = {};
|
|
305
316
|
for (const [key, value] of Object.entries(fields))
|
|
306
|
-
(EPC_FIELDS.has(key) ?
|
|
317
|
+
(EPC_FIELDS.has(key) ? payment2 : qr)[key] = value;
|
|
307
318
|
const o = { ecc: "M", ...qr };
|
|
308
|
-
const svg = qrSvg(epcPayload(
|
|
309
|
-
if (ctx.drawing)
|
|
319
|
+
const svg = qrSvg(epcPayload(payment2), o);
|
|
320
|
+
if (ctx.drawing)
|
|
321
|
+
return ctx.drawing({
|
|
322
|
+
kind: "svg",
|
|
323
|
+
svg,
|
|
324
|
+
width: o.size,
|
|
325
|
+
height: o.size,
|
|
326
|
+
alt: "GiroCode"
|
|
327
|
+
});
|
|
310
328
|
return svgDataUri(svg);
|
|
311
329
|
}
|
|
312
330
|
}
|
|
313
331
|
];
|
|
314
|
-
var EPC_FIELDS = /* @__PURE__ */ new Set([
|
|
332
|
+
var EPC_FIELDS = /* @__PURE__ */ new Set([
|
|
333
|
+
"name",
|
|
334
|
+
"iban",
|
|
335
|
+
"bic",
|
|
336
|
+
"amount",
|
|
337
|
+
"reference",
|
|
338
|
+
"text",
|
|
339
|
+
"purpose"
|
|
340
|
+
]);
|
|
315
341
|
|
|
316
342
|
// packages/engine/src/lib/helpers/format.ts
|
|
317
343
|
import { TZDate } from "@date-fns/tz";
|
|
@@ -329,8 +355,8 @@ import { toCardinal as nlWords } from "n2words/nl";
|
|
|
329
355
|
function resolveTranslation(dictionaries, locale, key) {
|
|
330
356
|
const lang = locale.split("-")[0] ?? locale;
|
|
331
357
|
for (const candidate of [locale, lang, "en"]) {
|
|
332
|
-
const
|
|
333
|
-
if (typeof
|
|
358
|
+
const text4 = dictionaries?.[candidate]?.[key];
|
|
359
|
+
if (typeof text4 === "string") return { text: text4, from: candidate };
|
|
334
360
|
}
|
|
335
361
|
return { text: key, from: null };
|
|
336
362
|
}
|
|
@@ -478,10 +504,10 @@ var formatHelpers = [
|
|
|
478
504
|
},
|
|
479
505
|
category: "format"
|
|
480
506
|
},
|
|
481
|
-
fn: (ctx, value,
|
|
507
|
+
fn: (ctx, value, amount2, unit) => {
|
|
482
508
|
const d = toDate(value, ctx.timezone);
|
|
483
509
|
if (!d) return str(value);
|
|
484
|
-
const n = toNumber(
|
|
510
|
+
const n = toNumber(amount2);
|
|
485
511
|
const u = str(unit || "days").replace(/s?$/, "s");
|
|
486
512
|
return add(d, { [u]: n }).toISOString();
|
|
487
513
|
}
|
|
@@ -810,9 +836,9 @@ var formatHelpers = [
|
|
|
810
836
|
category: "text"
|
|
811
837
|
},
|
|
812
838
|
fn: (ctx, key, params) => {
|
|
813
|
-
const { text:
|
|
839
|
+
const { text: text4 } = resolveTranslation(ctx.i18n, ctx.locale, str(key));
|
|
814
840
|
const p = params ?? {};
|
|
815
|
-
return
|
|
841
|
+
return text4.replace(/\{(\w+)\}/g, (_, name) => str(p[name]));
|
|
816
842
|
}
|
|
817
843
|
},
|
|
818
844
|
{
|
|
@@ -1083,7 +1109,16 @@ var collectionHelpers = [
|
|
|
1083
1109
|
];
|
|
1084
1110
|
|
|
1085
1111
|
// packages/engine/src/lib/helpers/document.ts
|
|
1086
|
-
var CHART_PALETTE = [
|
|
1112
|
+
var CHART_PALETTE = [
|
|
1113
|
+
"#3E63DD",
|
|
1114
|
+
"#12A594",
|
|
1115
|
+
"#E5484D",
|
|
1116
|
+
"#F76B15",
|
|
1117
|
+
"#8E4EC6",
|
|
1118
|
+
"#FFC53D",
|
|
1119
|
+
"#0090FF",
|
|
1120
|
+
"#978365"
|
|
1121
|
+
];
|
|
1087
1122
|
var SLICED = /* @__PURE__ */ new Set(["pie", "doughnut", "polarArea"]);
|
|
1088
1123
|
var colour = (value) => typeof value === "string" && value ? value : Array.isArray(value) && value.length ? value.map(String) : void 0;
|
|
1089
1124
|
function chartDataFromPlain(spec) {
|
|
@@ -1097,8 +1132,13 @@ function chartDataFromPlain(spec) {
|
|
|
1097
1132
|
});
|
|
1098
1133
|
const own = colour(s.color);
|
|
1099
1134
|
const fill = SLICED.has(type) ? own ?? labels.map((_, i) => CHART_PALETTE[i % CHART_PALETTE.length]) : own ?? CHART_PALETTE[index % CHART_PALETTE.length];
|
|
1100
|
-
const dataset = {
|
|
1101
|
-
|
|
1135
|
+
const dataset = {
|
|
1136
|
+
data,
|
|
1137
|
+
backgroundColor: fill,
|
|
1138
|
+
borderColor: fill
|
|
1139
|
+
};
|
|
1140
|
+
if (s.label !== void 0 && s.label !== null && s.label !== "")
|
|
1141
|
+
dataset["label"] = String(s.label);
|
|
1102
1142
|
if (type === "line") dataset["fill"] = false;
|
|
1103
1143
|
return dataset;
|
|
1104
1144
|
});
|
|
@@ -1115,7 +1155,8 @@ function chartPayload(spec) {
|
|
|
1115
1155
|
const options = { ...spec.options ?? {} };
|
|
1116
1156
|
options["animation"] = false;
|
|
1117
1157
|
options["responsive"] = false;
|
|
1118
|
-
if (!isPlain(spec))
|
|
1158
|
+
if (!isPlain(spec))
|
|
1159
|
+
return { type: spec.type ?? "bar", data: spec.data ?? {}, options };
|
|
1119
1160
|
const data = chartDataFromPlain(spec);
|
|
1120
1161
|
const unnamed = data.datasets.length === 1 && data.datasets[0]?.["label"] === void 0;
|
|
1121
1162
|
const plugins = asObject(options["plugins"]);
|
|
@@ -1128,7 +1169,8 @@ function chartMarkup(spec, id) {
|
|
|
1128
1169
|
const height = toNumber(spec.height ?? 240) || 240;
|
|
1129
1170
|
const payload = escapeHtml(JSON.stringify(chartPayload(spec)));
|
|
1130
1171
|
const idAttr = id ? ` id="${escapeHtml(id)}"` : "";
|
|
1131
|
-
|
|
1172
|
+
const alt = typeof spec.alt === "string" && spec.alt.trim() ? ` role="img" aria-label="${escapeHtml(spec.alt.trim())}"` : "";
|
|
1173
|
+
return `<canvas class="ff-chart"${idAttr}${alt} width="${width}" height="${height}" style="width:${width}px;height:${height}px" data-ff-chart="${payload}"></canvas>`;
|
|
1132
1174
|
}
|
|
1133
1175
|
function imageMarkup(url, options = {}) {
|
|
1134
1176
|
const styles = [
|
|
@@ -1149,18 +1191,21 @@ var documentHelpers = [
|
|
|
1149
1191
|
name: "chart",
|
|
1150
1192
|
html: true,
|
|
1151
1193
|
doc: {
|
|
1152
|
-
signature: "chart({ type, labels, values, label, color } | { type, labels, series } | { type, data, options }, { width, height })",
|
|
1153
|
-
description: "Draws a Chart.js chart (bar, line, pie, doughnut, radar, \u2026) from plain data, `labels` with `values` or several `series` of `{ label, values, color }`, or from a full Chart.js `data` and `options`; animations are disabled so PDF and preview match.",
|
|
1194
|
+
signature: "chart({ type, labels, values, label, color } | { type, labels, series } | { type, data, options }, { width, height, alt })",
|
|
1195
|
+
description: "Draws a Chart.js chart (bar, line, pie, doughnut, radar, \u2026) from plain data, `labels` with `values` or several `series` of `{ label, values, color }`, or from a full Chart.js `data` and `options`; animations are disabled so PDF and preview match. `alt` says in words what the chart shows: a screen reader reads it in place of the picture, and a tagged PDF needs it.",
|
|
1154
1196
|
examples: {
|
|
1155
|
-
jinja2: "{{ chart({ type: 'line', labels: sales.labels, values: sales.quarters, width: 480 }) }}",
|
|
1156
|
-
liquid: "{{ '' | chart: type: 'line', labels: sales.labels, values: sales.quarters, width: 480 }}",
|
|
1157
|
-
handlebars: "{{chart type='line' labels=sales.labels values=sales.quarters width=480}}"
|
|
1197
|
+
jinja2: "{{ chart({ type: 'line', labels: sales.labels, values: sales.quarters, width: 480, alt: 'Sales by quarter' }) }}",
|
|
1198
|
+
liquid: "{{ '' | chart: type: 'line', labels: sales.labels, values: sales.quarters, width: 480, alt: 'Sales by quarter' }}",
|
|
1199
|
+
handlebars: "{{chart type='line' labels=sales.labels values=sales.quarters width=480 alt='Sales by quarter'}}"
|
|
1158
1200
|
},
|
|
1159
1201
|
category: "document"
|
|
1160
1202
|
},
|
|
1161
1203
|
fn: (ctx, spec, extra) => {
|
|
1162
1204
|
if (ctx.mode === "office") throw new Error(officeUnsupported("chart"));
|
|
1163
|
-
return chartMarkup({
|
|
1205
|
+
return chartMarkup({
|
|
1206
|
+
...asObject(spec),
|
|
1207
|
+
...asObject(extra)
|
|
1208
|
+
});
|
|
1164
1209
|
}
|
|
1165
1210
|
},
|
|
1166
1211
|
{
|
|
@@ -1168,18 +1213,24 @@ var documentHelpers = [
|
|
|
1168
1213
|
html: true,
|
|
1169
1214
|
doc: {
|
|
1170
1215
|
signature: "image(url, { width, height, fit, alt })",
|
|
1171
|
-
description: "Places an image with fixed size and crop mode (`cover`, `contain`, `fill`); the render-worker fetches it through its cache and blocks private hosts.",
|
|
1216
|
+
description: "Places an image with fixed size and crop mode (`cover`, `contain`, `fill`); the render-worker fetches it through its cache and blocks private hosts. `alt` says what it shows; without one the image counts as decoration and a screen reader passes over it.",
|
|
1172
1217
|
examples: {
|
|
1173
|
-
jinja2: "{{ image(product.photo, { width: 120, height: 80, fit: 'cover' }) }}",
|
|
1174
|
-
liquid: "{{ product.photo | image: width: 120, height: 80, fit: 'cover' }}",
|
|
1175
|
-
handlebars: "{{image product.photo width=120 height=80 fit='cover'}}"
|
|
1218
|
+
jinja2: "{{ image(product.photo, { width: 120, height: 80, fit: 'cover', alt: product.name }) }}",
|
|
1219
|
+
liquid: "{{ product.photo | image: width: 120, height: 80, fit: 'cover', alt: product.name }}",
|
|
1220
|
+
handlebars: "{{image product.photo width=120 height=80 fit='cover' alt=product.name}}"
|
|
1176
1221
|
},
|
|
1177
1222
|
category: "document"
|
|
1178
1223
|
},
|
|
1179
1224
|
fn: (ctx, url, options) => {
|
|
1180
1225
|
const o = asObject(options);
|
|
1181
1226
|
if (ctx.drawing)
|
|
1182
|
-
return ctx.drawing({
|
|
1227
|
+
return ctx.drawing({
|
|
1228
|
+
kind: "url",
|
|
1229
|
+
url: resolveAsset(ctx.assetBaseUrl, String(url ?? "")),
|
|
1230
|
+
width: o.width,
|
|
1231
|
+
height: o.height,
|
|
1232
|
+
alt: o.alt
|
|
1233
|
+
});
|
|
1183
1234
|
return imageMarkup(String(url ?? ""), o);
|
|
1184
1235
|
}
|
|
1185
1236
|
}
|
|
@@ -1343,22 +1394,22 @@ function unavailableHelper(name) {
|
|
|
1343
1394
|
}
|
|
1344
1395
|
|
|
1345
1396
|
// packages/engine/src/lib/analysis/tags.ts
|
|
1346
|
-
function rangeAt(
|
|
1397
|
+
function rangeAt(line2, column, length) {
|
|
1347
1398
|
return {
|
|
1348
|
-
start: { line, column },
|
|
1349
|
-
end: { line, column: column + Math.max(1, length) }
|
|
1399
|
+
start: { line: line2, column },
|
|
1400
|
+
end: { line: line2, column: column + Math.max(1, length) }
|
|
1350
1401
|
};
|
|
1351
1402
|
}
|
|
1352
1403
|
function positionOf(source, offset) {
|
|
1353
|
-
let
|
|
1404
|
+
let line2 = 1;
|
|
1354
1405
|
let last = -1;
|
|
1355
1406
|
for (let i = 0; i < offset && i < source.length; i++) {
|
|
1356
1407
|
if (source.charCodeAt(i) === 10) {
|
|
1357
|
-
|
|
1408
|
+
line2++;
|
|
1358
1409
|
last = i;
|
|
1359
1410
|
}
|
|
1360
1411
|
}
|
|
1361
|
-
return { line, column: offset - last };
|
|
1412
|
+
return { line: line2, column: offset - last };
|
|
1362
1413
|
}
|
|
1363
1414
|
function rangeOf(source, start, end) {
|
|
1364
1415
|
return { start: positionOf(source, start), end: positionOf(source, end) };
|
|
@@ -1604,12 +1655,12 @@ function toSyntaxError(e) {
|
|
|
1604
1655
|
const err2 = e;
|
|
1605
1656
|
const message = String(err2.message ?? e);
|
|
1606
1657
|
const m = /Parse error on line (\d+)/.exec(message);
|
|
1607
|
-
const
|
|
1658
|
+
const line2 = err2.lineNumber ?? (m ? Number(m[1]) : 1);
|
|
1608
1659
|
const column = typeof err2.column === "number" ? err2.column + 1 : 1;
|
|
1609
1660
|
return new EngineSyntaxError(
|
|
1610
1661
|
"handlebars",
|
|
1611
1662
|
message.split("\n")[0] ?? message,
|
|
1612
|
-
|
|
1663
|
+
line2,
|
|
1613
1664
|
column
|
|
1614
1665
|
);
|
|
1615
1666
|
}
|
|
@@ -1919,48 +1970,48 @@ var SPEC = /^(?:([\s\S])?([<>=^]))?([+\- ])?(#)?(0)?(\d+)?([,_])?(?:\.(\d+))?([b
|
|
|
1919
1970
|
function group(digits, separator) {
|
|
1920
1971
|
return digits.replace(/\B(?=(\d{3})+(?!\d))/g, separator);
|
|
1921
1972
|
}
|
|
1922
|
-
function pythonExponent(
|
|
1923
|
-
return
|
|
1973
|
+
function pythonExponent(text4) {
|
|
1974
|
+
return text4.replace(/e([+-])(\d)$/i, (m, sign, digit) => `${m[0]}${sign}0${digit}`);
|
|
1924
1975
|
}
|
|
1925
1976
|
function formatNumber(value, type, precision, alternate) {
|
|
1926
1977
|
if (!Number.isFinite(value)) return Number.isNaN(value) ? "nan" : "inf";
|
|
1927
|
-
const
|
|
1978
|
+
const abs2 = Math.abs(value);
|
|
1928
1979
|
switch (type) {
|
|
1929
1980
|
case "f":
|
|
1930
1981
|
case "F":
|
|
1931
|
-
return
|
|
1982
|
+
return abs2.toFixed(precision ?? 6);
|
|
1932
1983
|
case "%":
|
|
1933
|
-
return `${(
|
|
1984
|
+
return `${(abs2 * 100).toFixed(precision ?? 6)}%`;
|
|
1934
1985
|
case "e":
|
|
1935
1986
|
case "E": {
|
|
1936
|
-
const
|
|
1937
|
-
return type === "E" ?
|
|
1987
|
+
const text4 = pythonExponent(abs2.toExponential(precision ?? 6));
|
|
1988
|
+
return type === "E" ? text4.toUpperCase() : text4;
|
|
1938
1989
|
}
|
|
1939
1990
|
case "g":
|
|
1940
1991
|
case "G": {
|
|
1941
1992
|
const p = precision === 0 ? 1 : precision ?? 6;
|
|
1942
|
-
const exp =
|
|
1943
|
-
let
|
|
1993
|
+
const exp = abs2 === 0 ? 0 : Math.floor(Math.log10(abs2));
|
|
1994
|
+
let text4 = exp < -4 || exp >= p ? pythonExponent(abs2.toExponential(p - 1)) : abs2.toFixed(Math.max(0, p - 1 - exp));
|
|
1944
1995
|
if (!alternate) {
|
|
1945
|
-
const [mantissa = "", exponent] =
|
|
1996
|
+
const [mantissa = "", exponent] = text4.split("e");
|
|
1946
1997
|
const trimmed = mantissa.includes(".") ? mantissa.replace(/0+$/, "").replace(/\.$/, "") : mantissa;
|
|
1947
|
-
|
|
1998
|
+
text4 = exponent === void 0 ? trimmed : `${trimmed}e${exponent}`;
|
|
1948
1999
|
}
|
|
1949
|
-
return type === "G" ?
|
|
2000
|
+
return type === "G" ? text4.toUpperCase() : text4;
|
|
1950
2001
|
}
|
|
1951
2002
|
case "d":
|
|
1952
2003
|
case "n":
|
|
1953
|
-
return String(Math.trunc(
|
|
2004
|
+
return String(Math.trunc(abs2));
|
|
1954
2005
|
case "b":
|
|
1955
|
-
return (alternate ? "0b" : "") + Math.trunc(
|
|
2006
|
+
return (alternate ? "0b" : "") + Math.trunc(abs2).toString(2);
|
|
1956
2007
|
case "o":
|
|
1957
|
-
return (alternate ? "0o" : "") + Math.trunc(
|
|
2008
|
+
return (alternate ? "0o" : "") + Math.trunc(abs2).toString(8);
|
|
1958
2009
|
case "x":
|
|
1959
|
-
return (alternate ? "0x" : "") + Math.trunc(
|
|
2010
|
+
return (alternate ? "0x" : "") + Math.trunc(abs2).toString(16);
|
|
1960
2011
|
case "X":
|
|
1961
|
-
return (alternate ? "0X" : "") + Math.trunc(
|
|
2012
|
+
return (alternate ? "0X" : "") + Math.trunc(abs2).toString(16).toUpperCase();
|
|
1962
2013
|
default:
|
|
1963
|
-
return precision === void 0 ? String(
|
|
2014
|
+
return precision === void 0 ? String(abs2) : formatNumber(abs2, "g", precision, alternate);
|
|
1964
2015
|
}
|
|
1965
2016
|
}
|
|
1966
2017
|
function formatValue(value, spec) {
|
|
@@ -2015,35 +2066,35 @@ function lookupField(name, positional, named, next) {
|
|
|
2015
2066
|
function pythonFormat(template, positional, named = {}) {
|
|
2016
2067
|
let auto = 0;
|
|
2017
2068
|
const next = () => auto++;
|
|
2018
|
-
const render = (
|
|
2069
|
+
const render = (text4) => {
|
|
2019
2070
|
let out = "";
|
|
2020
|
-
for (let i = 0; i <
|
|
2021
|
-
const ch =
|
|
2071
|
+
for (let i = 0; i < text4.length; i++) {
|
|
2072
|
+
const ch = text4[i];
|
|
2022
2073
|
if (ch === "}") {
|
|
2023
2074
|
out += "}";
|
|
2024
|
-
if (
|
|
2075
|
+
if (text4[i + 1] === "}") i++;
|
|
2025
2076
|
continue;
|
|
2026
2077
|
}
|
|
2027
2078
|
if (ch !== "{") {
|
|
2028
2079
|
out += ch;
|
|
2029
2080
|
continue;
|
|
2030
2081
|
}
|
|
2031
|
-
if (
|
|
2082
|
+
if (text4[i + 1] === "{") {
|
|
2032
2083
|
out += "{";
|
|
2033
2084
|
i++;
|
|
2034
2085
|
continue;
|
|
2035
2086
|
}
|
|
2036
2087
|
let depth = 1;
|
|
2037
2088
|
let j = i + 1;
|
|
2038
|
-
for (; j <
|
|
2039
|
-
if (
|
|
2040
|
-
else if (
|
|
2089
|
+
for (; j < text4.length && depth > 0; j++) {
|
|
2090
|
+
if (text4[j] === "{") depth++;
|
|
2091
|
+
else if (text4[j] === "}") depth--;
|
|
2041
2092
|
}
|
|
2042
2093
|
if (depth > 0) {
|
|
2043
|
-
out +=
|
|
2094
|
+
out += text4.slice(i);
|
|
2044
2095
|
break;
|
|
2045
2096
|
}
|
|
2046
|
-
const field =
|
|
2097
|
+
const field = text4.slice(i + 1, j - 1);
|
|
2047
2098
|
const colon = field.indexOf(":");
|
|
2048
2099
|
const head = colon < 0 ? field : field.slice(0, colon);
|
|
2049
2100
|
const name = head.replace(/![rsa]$/, "");
|
|
@@ -2147,7 +2198,7 @@ var stringMethods = {
|
|
|
2147
2198
|
return out;
|
|
2148
2199
|
},
|
|
2149
2200
|
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),
|
|
2150
|
-
join: (s,
|
|
2201
|
+
join: (s, list3) => Array.isArray(list3) ? list3.join(s) : String(list3),
|
|
2151
2202
|
format: (s, ...args) => {
|
|
2152
2203
|
const named = keywordArgs(args);
|
|
2153
2204
|
return pythonFormat(s, named ? args.slice(0, -1) : args, named ?? {});
|
|
@@ -2381,9 +2432,9 @@ function toSyntaxError2(e, fallbackLine = 1) {
|
|
|
2381
2432
|
const fromMessage = /\[Line (\d+), Column (\d+)\]/.exec(
|
|
2382
2433
|
String(err2.message ?? "")
|
|
2383
2434
|
);
|
|
2384
|
-
const
|
|
2435
|
+
const line2 = typeof err2.lineno === "number" ? err2.lineno + 1 : fromMessage ? Number(fromMessage[1]) : fallbackLine;
|
|
2385
2436
|
const column = typeof err2.colno === "number" ? err2.colno + 1 : fromMessage ? Number(fromMessage[2]) : 1;
|
|
2386
|
-
return new EngineSyntaxError("jinja2", message,
|
|
2437
|
+
return new EngineSyntaxError("jinja2", message, line2, column);
|
|
2387
2438
|
}
|
|
2388
2439
|
function nodeRange(node, length = 1) {
|
|
2389
2440
|
return rangeAt(node.lineno + 1, node.colno + 1, length);
|
|
@@ -2878,12 +2929,12 @@ var validationContext3 = {
|
|
|
2878
2929
|
};
|
|
2879
2930
|
function toSyntaxError3(e) {
|
|
2880
2931
|
const err2 = e;
|
|
2881
|
-
let
|
|
2932
|
+
let line2 = err2.line ?? 1;
|
|
2882
2933
|
let column = err2.col ?? 1;
|
|
2883
2934
|
const pos = err2.token?.getPosition?.();
|
|
2884
|
-
if (pos) [
|
|
2935
|
+
if (pos) [line2, column] = pos;
|
|
2885
2936
|
const message = String(err2.message ?? e).replace(/,\s*line:\d+,\s*col:\d+/, "").trim();
|
|
2886
|
-
return new EngineSyntaxError("liquid", message,
|
|
2937
|
+
return new EngineSyntaxError("liquid", message, line2, column);
|
|
2887
2938
|
}
|
|
2888
2939
|
var identifier = /(?<![\w."'])([A-Za-z_][\w]*)((?:\.[A-Za-z_]\w*|\[\d+\])*)/g;
|
|
2889
2940
|
function pathsIn(expression, base, source, out, scopes) {
|
|
@@ -3394,8 +3445,8 @@ function unionTypes(a, b) {
|
|
|
3394
3445
|
...Array.isArray(b) ? b : b ? [b] : []
|
|
3395
3446
|
]);
|
|
3396
3447
|
if (set.has("number")) set.delete("integer");
|
|
3397
|
-
const
|
|
3398
|
-
return
|
|
3448
|
+
const list3 = [...set];
|
|
3449
|
+
return list3.length === 1 ? list3[0] : list3;
|
|
3399
3450
|
}
|
|
3400
3451
|
function merge(a, b) {
|
|
3401
3452
|
if (!a) return b;
|
|
@@ -3566,9 +3617,9 @@ function layeredPartials(own, shared2, onShared) {
|
|
|
3566
3617
|
}
|
|
3567
3618
|
|
|
3568
3619
|
// packages/engine/src/lib/dialect.ts
|
|
3569
|
-
var loop = (engine, item,
|
|
3620
|
+
var loop = (engine, item, list3, body) => engine === "handlebars" ? `{{#each ${list3}}}
|
|
3570
3621
|
${body.replace(new RegExp(`(?<![\\w.])${item}\\.`, "g"), "")}
|
|
3571
|
-
{{/each}}` : `{% for ${item} in ${
|
|
3622
|
+
{{/each}}` : `{% for ${item} in ${list3} %}
|
|
3572
3623
|
${body}
|
|
3573
3624
|
{% endfor %}`;
|
|
3574
3625
|
var val = (engine, expr, filter) => {
|
|
@@ -4137,12 +4188,12 @@ var stripComments = (css2) => css2.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
|
4137
4188
|
var selectorKey = (prelude) => (prelude.split(";").pop() ?? "").trim().replace(/\s*,\s*/g, ", ").replace(/\s+/g, " ");
|
|
4138
4189
|
function mergeSnippetCss(css2, snippetCss) {
|
|
4139
4190
|
if (!snippetCss?.trim()) return css2;
|
|
4140
|
-
const
|
|
4191
|
+
const defined2 = new Set(
|
|
4141
4192
|
[...stripComments(css2).matchAll(/([^{}]+)\{/g)].map(
|
|
4142
4193
|
(m) => selectorKey(m[1] ?? "")
|
|
4143
4194
|
)
|
|
4144
4195
|
);
|
|
4145
|
-
const missing = [...stripComments(snippetCss).matchAll(/([^{}]+)\{[^{}]*\}/g)].filter((m) => !
|
|
4196
|
+
const missing = [...stripComments(snippetCss).matchAll(/([^{}]+)\{[^{}]*\}/g)].filter((m) => !defined2.has(selectorKey(m[1] ?? ""))).map((m) => m[0].trim());
|
|
4146
4197
|
if (!missing.length) return css2;
|
|
4147
4198
|
const base = css2.trimEnd();
|
|
4148
4199
|
return `${base}${base ? "\n\n" : ""}${missing.join("\n")}
|
|
@@ -4188,9 +4239,9 @@ function pick(input, ...keys) {
|
|
|
4188
4239
|
function toLength(value) {
|
|
4189
4240
|
if (value === void 0 || value === null || value === "") return void 0;
|
|
4190
4241
|
if (typeof value === "number") return `${value}mm`;
|
|
4191
|
-
const
|
|
4192
|
-
if (/^-?\d+(\.\d+)?$/.test(
|
|
4193
|
-
if (/^-?\d+(\.\d+)?(mm|cm|in|px|pt)$/i.test(
|
|
4242
|
+
const text4 = String(value).trim();
|
|
4243
|
+
if (/^-?\d+(\.\d+)?$/.test(text4)) return `${text4}mm`;
|
|
4244
|
+
if (/^-?\d+(\.\d+)?(mm|cm|in|px|pt)$/i.test(text4)) return text4.toLowerCase();
|
|
4194
4245
|
return void 0;
|
|
4195
4246
|
}
|
|
4196
4247
|
function toMarginLength(value) {
|
|
@@ -4210,7 +4261,7 @@ function convertHeaderFooter(html) {
|
|
|
4210
4261
|
if (typeof html !== "string" || !html.trim()) return void 0;
|
|
4211
4262
|
return chromePlaceholders.reduce((out, [pattern, span]) => out.replace(pattern, span), html);
|
|
4212
4263
|
}
|
|
4213
|
-
var escapeText = (
|
|
4264
|
+
var escapeText = (text4) => text4.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
4214
4265
|
var visibleMarkup = (html) => html.replace(/<style[\s\S]*?<\/style>/gi, "").trim();
|
|
4215
4266
|
function apitemplateChrome(take, kind) {
|
|
4216
4267
|
const custom = take(`custom_${kind}`);
|
|
@@ -4224,7 +4275,7 @@ function apitemplateChrome(take, kind) {
|
|
|
4224
4275
|
if (!slots.some(Boolean)) return { fromSlots: false };
|
|
4225
4276
|
const sizeText = size === void 0 ? "" : String(size).trim();
|
|
4226
4277
|
const fontSize2 = /^\d+(\.\d+)?$/.test(sizeText) ? `${sizeText}px` : /^\d+(\.\d+)?(px|pt|mm)$/.test(sizeText) ? sizeText : "9px";
|
|
4227
|
-
const cells = slots.map((
|
|
4278
|
+
const cells = slots.map((text4, i) => `<span style="flex:1;text-align:${["left", "center", "right"][i]}">${escapeText(text4)}</span>`).join("");
|
|
4228
4279
|
const styles = customHtml.match(/<style[\s\S]*?<\/style>/gi)?.join("") ?? "";
|
|
4229
4280
|
return {
|
|
4230
4281
|
html: convertHeaderFooter(`${styles}<div style="display:flex;gap:4mm;font-size:${fontSize2}">${cells}</div>`),
|
|
@@ -4344,15 +4395,15 @@ function parseSample(value) {
|
|
|
4344
4395
|
}
|
|
4345
4396
|
function positionOf2(source, index) {
|
|
4346
4397
|
const before = source.slice(0, index);
|
|
4347
|
-
const
|
|
4398
|
+
const line2 = before.split("\n").length;
|
|
4348
4399
|
const column = index - before.lastIndexOf("\n");
|
|
4349
|
-
return { line, column };
|
|
4400
|
+
return { line: line2, column };
|
|
4350
4401
|
}
|
|
4351
|
-
function notesFor(source, pattern,
|
|
4402
|
+
function notesFor(source, pattern, note2, { once = false } = {}) {
|
|
4352
4403
|
const global = new RegExp(pattern.source, pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`);
|
|
4353
4404
|
const out = [];
|
|
4354
4405
|
for (const m of source.matchAll(global)) {
|
|
4355
|
-
out.push({ ...
|
|
4406
|
+
out.push({ ...note2, ...positionOf2(source, m.index ?? 0) });
|
|
4356
4407
|
if (once) break;
|
|
4357
4408
|
}
|
|
4358
4409
|
return out;
|
|
@@ -4375,19 +4426,19 @@ function checkTemplate(engineId, html, sampleData, name, docs) {
|
|
|
4375
4426
|
docs: d.code === "unknown-filter" ? docs.filters : d.code.startsWith("missing-") ? docs.sampleData : docs.syntax
|
|
4376
4427
|
});
|
|
4377
4428
|
for (const d of engine.analyze(html, { sampleData }).diagnostics) {
|
|
4378
|
-
const
|
|
4429
|
+
const note2 = fromDiagnostic(d);
|
|
4379
4430
|
if (d.severity === "error") {
|
|
4380
|
-
if (!errors.some((x) => x.code ===
|
|
4381
|
-
} else warnings.push(
|
|
4431
|
+
if (!errors.some((x) => x.code === note2.code && x.line === note2.line)) errors.push(note2);
|
|
4432
|
+
} else warnings.push(note2);
|
|
4382
4433
|
}
|
|
4383
4434
|
return { errors, warnings };
|
|
4384
4435
|
}
|
|
4385
4436
|
function lengthMm(value) {
|
|
4386
4437
|
if (value === void 0 || value === null || value === "") return void 0;
|
|
4387
4438
|
if (typeof value === "number" && Number.isFinite(value)) return `${value}mm`;
|
|
4388
|
-
const
|
|
4389
|
-
if (/^-?\d+(\.\d+)?$/.test(
|
|
4390
|
-
if (/^-?\d+(\.\d+)?(mm|cm|in|px|pt)$/i.test(
|
|
4439
|
+
const text4 = String(value).trim();
|
|
4440
|
+
if (/^-?\d+(\.\d+)?$/.test(text4)) return `${text4}mm`;
|
|
4441
|
+
if (/^-?\d+(\.\d+)?(mm|cm|in|px|pt)$/i.test(text4)) return text4.toLowerCase();
|
|
4391
4442
|
return void 0;
|
|
4392
4443
|
}
|
|
4393
4444
|
function toBase64(value) {
|
|
@@ -4474,17 +4525,17 @@ var STYLE_BLOCK = /<style\b[^>]*>([\s\S]*?)<\/style\s*>/gi;
|
|
|
4474
4525
|
var HEAD_MARKUP = /<script\b[\s\S]*?<\/script\s*>|<!--[\s\S]*?-->|<(?:link|meta|base)\b[^>]*>/gi;
|
|
4475
4526
|
var TEMPLATED = /\{\{|\{%/;
|
|
4476
4527
|
function splitApitemplateCss(source) {
|
|
4477
|
-
const styleElement = (
|
|
4478
|
-
${
|
|
4528
|
+
const styleElement = (rules2) => `<style>
|
|
4529
|
+
${rules2}
|
|
4479
4530
|
</style>`;
|
|
4480
4531
|
if (!/<\/?(style|link|script|meta|base)\b|<!--/i.test(source))
|
|
4481
4532
|
return TEMPLATED.test(source) ? { css: "", head: "", body: styleElement(source.trim()) } : { css: source, head: "", body: "" };
|
|
4482
4533
|
const styles = [];
|
|
4483
4534
|
const head = [];
|
|
4484
4535
|
const body = [];
|
|
4485
|
-
let rest = source.replace(STYLE_BLOCK, (block,
|
|
4486
|
-
if (TEMPLATED.test(
|
|
4487
|
-
else styles.push(
|
|
4536
|
+
let rest = source.replace(STYLE_BLOCK, (block, rules2) => {
|
|
4537
|
+
if (TEMPLATED.test(rules2)) body.push(block.trim());
|
|
4538
|
+
else styles.push(rules2.replace(/^\n+|\s+$/g, ""));
|
|
4488
4539
|
return "\n";
|
|
4489
4540
|
});
|
|
4490
4541
|
rest = rest.replace(HEAD_MARKUP, (tag) => {
|
|
@@ -4507,7 +4558,7 @@ function importApitemplate(input) {
|
|
|
4507
4558
|
if (kind === "image") changes.push(`${format} template imported as an image template`);
|
|
4508
4559
|
const mapped = mapApitemplateSettings(input.settings ?? void 0);
|
|
4509
4560
|
const settings = mapped.settings;
|
|
4510
|
-
for (const
|
|
4561
|
+
for (const note2 of mapped.notes) changes.push(note2);
|
|
4511
4562
|
for (const key of mapped.ignored)
|
|
4512
4563
|
warnings.push({ code: "setting-ignored", message: `Setting "${key}" has no Formfeed equivalent and was dropped.`, docs: "/migrate/apitemplate-io#settings" });
|
|
4513
4564
|
if (settings.header?.html || settings.footer?.html) changes.push("header and footer templates moved to the Header and Footer tabs");
|
|
@@ -4904,11 +4955,11 @@ function inlineIncludes(source, blocks, errors, changes) {
|
|
|
4904
4955
|
}
|
|
4905
4956
|
var cssPaperFormats = { a3: "A3", a4: "A4", a5: "A5", letter: "Letter" };
|
|
4906
4957
|
var isoSizes = { a0: [841, 1189], a1: [594, 841], a2: [420, 594], a6: [105, 148] };
|
|
4907
|
-
var escapeHtml2 = (
|
|
4958
|
+
var escapeHtml2 = (text4) => text4.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
4908
4959
|
function simpleHeaderFooter(part, margin) {
|
|
4909
4960
|
const cells = ["left", "center", "right"].map((side) => part[side] ?? "");
|
|
4910
4961
|
if (!cells.some((c) => c.trim())) return void 0;
|
|
4911
|
-
const cell3 = (
|
|
4962
|
+
const cell3 = (text4, align) => `<div style="flex: 1; text-align: ${align}">${escapeHtml2(text4).replace(/\[page\]/g, '<span class="pageNumber"></span>').replace(/\[topage\]/g, '<span class="totalPages"></span>')}</div>`;
|
|
4912
4963
|
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>`;
|
|
4913
4964
|
}
|
|
4914
4965
|
function mapSettings(input, kind, warnings, changes) {
|
|
@@ -5077,11 +5128,11 @@ var DOCS3 = "/migrate/jsreport";
|
|
|
5077
5128
|
var COLLECTIONS = ["templates", "data", "assets", "components", "scripts", "folders"];
|
|
5078
5129
|
function readJsreportExport(files) {
|
|
5079
5130
|
const bundle = { templates: [], data: [], assets: [], components: [], scripts: [], folders: [] };
|
|
5080
|
-
for (const [path,
|
|
5131
|
+
for (const [path, text4] of Object.entries(files)) {
|
|
5081
5132
|
const normalized = path.replace(/\\/g, "/").replace(/^\.?\//, "");
|
|
5082
5133
|
if (normalized === "metadata.json") {
|
|
5083
5134
|
try {
|
|
5084
|
-
bundle.version = String(JSON.parse(
|
|
5135
|
+
bundle.version = String(JSON.parse(text4).reporterVersion ?? "");
|
|
5085
5136
|
} catch {
|
|
5086
5137
|
}
|
|
5087
5138
|
continue;
|
|
@@ -5089,7 +5140,7 @@ function readJsreportExport(files) {
|
|
|
5089
5140
|
const collection = normalized.split("/")[0];
|
|
5090
5141
|
if (!COLLECTIONS.includes(collection) || !normalized.endsWith(".json")) continue;
|
|
5091
5142
|
try {
|
|
5092
|
-
bundle[collection].push(JSON.parse(
|
|
5143
|
+
bundle[collection].push(JSON.parse(text4));
|
|
5093
5144
|
} catch {
|
|
5094
5145
|
}
|
|
5095
5146
|
}
|
|
@@ -5114,9 +5165,9 @@ function pathOf2(bundle, entity) {
|
|
|
5114
5165
|
function jsreportTemplates(bundle) {
|
|
5115
5166
|
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));
|
|
5116
5167
|
}
|
|
5117
|
-
function byPath(bundle,
|
|
5168
|
+
function byPath(bundle, list3, ref) {
|
|
5118
5169
|
const wanted = ref.replace(/^\.?\/+/, "");
|
|
5119
|
-
return
|
|
5170
|
+
return list3.find((e) => pathOf2(bundle, e) === wanted) ?? list3.find((e) => e.name === wanted.split("/").pop());
|
|
5120
5171
|
}
|
|
5121
5172
|
function decodeText(base64) {
|
|
5122
5173
|
const binary = atob(base64);
|
|
@@ -5131,7 +5182,7 @@ function assetBase64(content) {
|
|
|
5131
5182
|
}
|
|
5132
5183
|
return toBase64(content);
|
|
5133
5184
|
}
|
|
5134
|
-
var escapeMustaches = (
|
|
5185
|
+
var escapeMustaches = (text4) => text4.replace(/\{\{/g, "\\{{");
|
|
5135
5186
|
function resolveAssets(source, bundle, options, warnings, changes) {
|
|
5136
5187
|
const v3 = /\{\{\{?\s*asset\s+(["'])([^"']+)\1(?:\s+(["'])([^"']+)\3)?\s*\}?\}\}/g;
|
|
5137
5188
|
const v2 = /\{#asset\s+([^\s}]+)(?:\s+@encoding=(\w+))?\s*\}/g;
|
|
@@ -5369,9 +5420,10 @@ function importJsreport(bundle, ref, options = {}) {
|
|
|
5369
5420
|
}
|
|
5370
5421
|
|
|
5371
5422
|
// packages/engine/src/lib/generated/frames.ts
|
|
5372
|
-
var textEditRuntime = '"use strict";(()=>{var
|
|
5423
|
+
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);})();';
|
|
5373
5424
|
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);})();';
|
|
5374
|
-
var stageRuntime = '"use strict";(()=>{var
|
|
5425
|
+
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);})();';
|
|
5426
|
+
var auditRuntime = '"use strict";(()=>{var I={"document-title":"error","image-alt":"error","figure-name":"error","heading-order":"error","table-rows":"error","table-cell-empty":"error","masked-text":"error","filtered-text":"warning","document-language":"warning","table-headers":"warning","link-name":"warning","generated-text":"warning","fixed-text":"warning","running-text":"warning"};var S=120;var O=".formfeed-chrome, .ff-running-header, .ff-running-footer",_=".pageNumber, .totalPages, .date, .title, .url, .ff-page-no, .ff-page-total",k=new Set(["script","style","template","noscript","head"]),j=2e4,q=10,B=new Set(["page","pages","of","seite","seiten","von","p","s"]),u=t=>(t??"").replace(/\\s+/g," ").trim(),D=t=>t.replace(/\\s+/g,"").toLowerCase(),$=t=>/[\\p{L}\\p{N}]/u.test(t),Y=/^data-(ref|id|split-(from|to|original)|(previous-|next-)?break-(before|after|inside)|(align-)?last-split-element|nth-of-type|counter-.+|page(-number)?|undisplayed|after-page|following|has-notes|children|item-num)$/;function X(t){let n=t.cloneNode(!1);n.removeAttribute("data-ff-src"),n.removeAttribute("data-ff-edit");let i=t.closest(".pagedjs_page")!==null;for(let s of Array.from(n.attributes))i&&Y.test(s.name)?n.removeAttribute(s.name):s.value.length>48&&n.setAttribute(s.name,`${s.value.slice(0,40)}\\u2026`);let o=n.outerHTML.replace(new RegExp(`</${t.tagName}>$`,"i"),"");return o.length>S?`${o.slice(0,S-1)}\\u2026`:o}function F(t,n={}){let i=t.document,o=i.body,s=[],d=new Set,a=n.findings!==!1,c=(e,r,l={})=>{if(!a)return;let m=r?.closest("[data-ff-src]")?.getAttribute("data-ff-src")??null,h=r?X(r):"",g=`${e}|${m??h}|${JSON.stringify(l)}`;d.has(g)||(d.add(g),s.push({code:e,severity:I[e],src:m,snippet:h,args:l}))},f=new WeakMap,A=e=>{let r=f.get(e);if(r!==void 0)return r;let l=t.getComputedStyle(e),m=l.display==="none"||l.visibility==="hidden"||l.visibility==="collapse"||e.parentElement!==null&&e.parentElement!==i.documentElement&&A(e.parentElement);return f.set(e,m),m},p=e=>e.closest(\'[aria-hidden="true"]\')!==null,E=e=>/^(presentation|none)$/.test(e.getAttribute("role")??""),H=e=>e.closest(O)!==null,y=e=>$(e.textContent??""),x=e=>{let r=u(e.getAttribute("aria-label"));return r||u((e.getAttribute("aria-labelledby")??"").split(/\\s+/).filter(Boolean).map(l=>e.ownerDocument.getElementById(l)?.textContent??"").join(" "))},P=e=>x(e)||u(e.textContent)||u(Array.from(e.querySelectorAll("img[alt]")).map(r=>r.getAttribute("alt")).join(" "))||u(e.getAttribute("title")),T=e=>{let r=e.getAttribute("href")??"";return{href:r.startsWith("#")?r:e.href??r,name:P(e)}};u(i.title)||c("document-title",null),!u(i.documentElement.getAttribute("lang"))&&!n.locale&&c("document-language",null);let M=n.pages??(n.pageHeight&&n.pageHeight>0?Math.ceil(i.documentElement.scrollHeight/n.pageHeight):1),C=[],v=[],R={"masked-text":[],"filtered-text":[],"fixed-text":[]},w=(e,r)=>{R[e].some(l=>l.contains(r))||(R[e].push(r),c(e,r))},V=a&&ne(i),G=o?Array.from(o.querySelectorAll("*")).slice(0,j):[];for(let e of G){let r=e.tagName.toLowerCase();if(k.has(r)||H(e)||A(e))continue;if(r==="a"&&e.hasAttribute("href")){let g=T(e);C.push(g),!g.name&&!p(e)&&c("link-name",e)}if(!a)continue;let l=t.getComputedStyle(e),m=l.getPropertyValue("mask-image")||l.getPropertyValue("-webkit-mask-image");if(m&&m!=="none"&&y(e)&&w("masked-text",e),l.filter&&l.filter!=="none"&&y(e)&&w("filtered-text",e),l.position==="fixed"&&M>1&&y(e)&&w("fixed-text",e),V)for(let g of["::before","::after"]){let U=re(t.getComputedStyle(e,g).content);U&&c("generated-text",e,{text:U})}if(p(e))continue;r==="img"&&!E(e)?e.hasAttribute("alt")||x(e)||u(e.getAttribute("title"))||c("image-alt",e):(r==="canvas"||e.getAttribute("role")==="img"&&r!=="img")&&(x(e)||u(e.getAttribute("title"))||u(e.querySelector(":scope > title")?.textContent)||c("figure-name",e,{tag:r}));let h=/^h[1-6]$/.test(r)?Number(r[1]):e.getAttribute("role")==="heading"?Number(e.getAttribute("aria-level"))||2:0;h&&v.push({element:e,level:h}),r==="table"&&!E(e)&&Q(e,c)}let b=0;for(let{element:e,level:r}of v)(b===0?r!==1:r>b+1)&&c("heading-order",e,{level:r,previous:b}),b=r;let N=[],W=a&&o?D(J(o)):"",L=0;for(let e of["header","footer"])for(let r of z(i,e,n[e])){for(let l of Array.from(r.querySelectorAll("a[href]")))N.push(T(l));if(a)for(let{text:l,element:m}of K(r)){if(L>=q||W.includes(D(l)))continue;let h=s.length;c("running-text",m,{text:l.slice(0,80),part:e}),s.length>h&&L++}}return{findings:s,links:C,templateLinks:N}}function z(t,n,i){if(i!==void 0){if(!i.trim())return[];let o=new DOMParser().parseFromString(`<!doctype html><body>${i}</body>`,"text/html");return o.body?[o.body]:[]}return Array.from(t.querySelectorAll(`.ff-running-${n}, .formfeed-chrome[data-ff-chrome="${n}"]`))}function J(t){let n=[],i=o=>{if(o.nodeType===3){n.push(o.nodeValue??"");return}if(o.nodeType!==1)return;let s=o;if(!(k.has(s.tagName.toLowerCase())||s.matches(O)))for(let d of Array.from(o.childNodes))i(d)};return i(t),n.join(" ")}function K(t){let n=[],i=o=>{let s=o.tagName.toLowerCase();if(k.has(s)||o.matches(_))return;let d=Array.from(o.children).some(a=>a.matches(_));for(let a of Array.from(o.childNodes))if(a.nodeType===1)i(a);else if(a.nodeType===3&&!d)for(let c of(a.nodeValue??"").split(/\\s*[\xB7\u2022|]\\s*|\\s{2,}|\\n/)){let f=u(c);(f.toLowerCase().match(/[\\p{L}\\p{N}]+/gu)??[]).some(p=>!B.has(p))&&n.push({text:f,element:o})}};return i(t),n}function Q(t,n){let i=Array.from(t.rows);if(!(t.querySelector(\'th, [role="columnheader"], [role="rowheader"]\')!==null)){i.length>=2&&n("table-headers",t);return}let s=te(i),d=s.find(c=>c!==s[0]);d!==void 0&&n("table-rows",t,{first:s[0]??0,other:d});let a=i.flatMap(c=>Array.from(c.cells).filter(f=>f.tagName==="TD"&&ee(f)));a[0]&&n("table-cell-empty",a[0],{count:a.length})}var Z=\'img[alt]:not([alt=""]), svg, canvas, input, select, textarea, button, meter, progress\';function ee(t){return!/[^ \\t\\n\\r\\f]/.test(t.textContent??"")&&t.querySelector(Z)===null}function te(t){let n=[];return t.map(i=>{let o=[],s=0,d=()=>{for(;(n[s]??0)>0;)o[s]=n[s]-1,s++};for(let a of Array.from(i.cells)){d();let c=Math.max(1,a.rowSpan||1)-1;for(let f=Math.max(1,a.colSpan||1);f>0;f--)o[s++]=c}d();for(let a=s;a<n.length;a++)(n[a]??0)>0&&(o[a]=n[a]-1,s=a+1);return n=o,s})}function ne(t){let n=i=>{for(let o of Array.from(i??[])){let s=o;if(s.selectorText&&/::?(before|after)/.test(s.selectorText)&&s.style?.content||o.cssRules&&n(o.cssRules))return!0}return!1};for(let i of Array.from(t.styleSheets))try{if(n(i.cssRules))return!0}catch{return!0}return!1}function re(t){if(!t||t==="none"||t==="normal")return"";let n=(t.match(/"(?:[^"\\\\]|\\\\.)*"/g)??[]).map(o=>o.slice(1,-1).replace(/\\\\(.)/g,"$1"));if(/\\bcounters?\\(/.test(t))return u(t).slice(0,80);let i=u(n.join(""));return $(i)?i.slice(0,80):""}window.formfeedAudit=t=>F(window,t);})();';
|
|
5375
5427
|
|
|
5376
5428
|
// packages/engine/src/lib/assemble.ts
|
|
5377
5429
|
var DEFAULT_CHROME_PADDING = "0 10mm";
|
|
@@ -5606,6 +5658,13 @@ document.addEventListener('click', function (event) {
|
|
|
5606
5658
|
if (!el || el.nodeType !== 1) return;
|
|
5607
5659
|
try {
|
|
5608
5660
|
var annotated = el.closest ? el.closest('[data-ff-src]') : null;
|
|
5661
|
+
// the paper around the template (the page's margins, the pane behind it) is no element of it:
|
|
5662
|
+
// a click there asks for nothing
|
|
5663
|
+
if (!annotated && (
|
|
5664
|
+
el === document.documentElement || el === document.body ||
|
|
5665
|
+
el.querySelector('[data-ff-src]') ||
|
|
5666
|
+
(el.closest && el.closest('[class*="pagedjs_"]') === el)
|
|
5667
|
+
)) return;
|
|
5609
5668
|
parent.postMessage({
|
|
5610
5669
|
type: 'formfeed:inspect',
|
|
5611
5670
|
src: annotated ? annotated.getAttribute('data-ff-src') : null,
|
|
@@ -5619,6 +5678,27 @@ document.addEventListener('click', function (event) {
|
|
|
5619
5678
|
}, true);
|
|
5620
5679
|
</script>`;
|
|
5621
5680
|
var textEditScript = `<script>${textEditRuntime.replace(/<\/script/gi, "<\\/script")}</script>`;
|
|
5681
|
+
function auditScript(mode) {
|
|
5682
|
+
return `<script>${auditRuntime.replace(/<\/script/gi, "<\\/script")}</script><script>
|
|
5683
|
+
(function () {
|
|
5684
|
+
window.formfeedRunAudit = function (pages) {
|
|
5685
|
+
try {
|
|
5686
|
+
var report = window.formfeedAudit({
|
|
5687
|
+
locale: true,
|
|
5688
|
+
pages: pages,
|
|
5689
|
+
pageHeight: parseFloat(getComputedStyle(document.body).minHeight) || 0,
|
|
5690
|
+
});
|
|
5691
|
+
parent.postMessage({ type: 'formfeed:audit', findings: report.findings }, '*');
|
|
5692
|
+
} catch (e) {}
|
|
5693
|
+
};
|
|
5694
|
+
${mode === "flow" ? "window.addEventListener('load', function () { (document.fonts ? document.fonts.ready : Promise.resolve()).then(function () { window.formfeedRunAudit(); }); });" : ""}
|
|
5695
|
+
})();
|
|
5696
|
+
</script>`;
|
|
5697
|
+
}
|
|
5698
|
+
function documentMeta(options) {
|
|
5699
|
+
const name = (options.document ?? "").replace(/[^A-Za-z0-9_-]/g, "");
|
|
5700
|
+
return name ? `<meta name="formfeed:document" content="${name}">` : "";
|
|
5701
|
+
}
|
|
5622
5702
|
var pageNavScript = `<script>
|
|
5623
5703
|
(function () {
|
|
5624
5704
|
var pages = function () { return document.querySelectorAll('.pagedjs_page'); };
|
|
@@ -5726,6 +5806,15 @@ function intoHead(document, markup) {
|
|
|
5726
5806
|
${markup}`
|
|
5727
5807
|
);
|
|
5728
5808
|
}
|
|
5809
|
+
function intoBody(document, atStart, atEnd = "") {
|
|
5810
|
+
const own = document.indexOf('<body class="formfeed-body');
|
|
5811
|
+
const open2 = own >= 0 ? own : document.search(/<body[^>]*>/);
|
|
5812
|
+
if (open2 < 0) return document;
|
|
5813
|
+
const content = document.indexOf(">", open2) + 1;
|
|
5814
|
+
const close = document.lastIndexOf("</body>");
|
|
5815
|
+
const end = close >= content ? close : document.length;
|
|
5816
|
+
return `${document.slice(0, content)}${atStart}${document.slice(content, end)}${atEnd}${document.slice(end)}`;
|
|
5817
|
+
}
|
|
5729
5818
|
function chromeBoxStyle(settings, which) {
|
|
5730
5819
|
const margin = settings.margin ?? {};
|
|
5731
5820
|
const left = margin.left ?? "0px";
|
|
@@ -5749,12 +5838,16 @@ html { background: #e5e7eb; }
|
|
|
5749
5838
|
body.formfeed-preview { position: relative; box-sizing: border-box; width: ${paper.width}; min-height: ${paper.height}; margin: 24px auto; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2), 0 8px 24px rgba(0,0,0,.08); padding: ${margin.top ?? "0"} ${margin.right ?? "0"} ${margin.bottom ?? "0"} ${margin.left ?? "0"}; }
|
|
5750
5839
|
.formfeed-chrome { color: #6b7280; font: 10px/1.3 system-ui, sans-serif; }
|
|
5751
5840
|
</style>` : `<style data-formfeed="preview">html { background: #e5e7eb; } body.formfeed-preview { margin: 24px auto; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); }</style>`;
|
|
5752
|
-
const header = headerHtml ? `<div class="formfeed-chrome" style="${pdf ? flowChromeStyle(settings, "header") : `${chromeBoxStyle(settings, "header")}margin-bottom:8px`}">${headerHtml}</div>` : "";
|
|
5753
|
-
const footer = footerHtml ? `<div class="formfeed-chrome" style="${pdf ? flowChromeStyle(settings, "footer") : `${chromeBoxStyle(settings, "footer")}margin-top:8px`}">${pageNumberSpans(footerHtml, "1", "1")}</div>` : "";
|
|
5754
|
-
return
|
|
5755
|
-
|
|
5756
|
-
|
|
5757
|
-
|
|
5841
|
+
const header = headerHtml ? `<div class="formfeed-chrome" data-ff-chrome="header" style="${pdf ? flowChromeStyle(settings, "header") : `${chromeBoxStyle(settings, "header")}margin-bottom:8px`}">${headerHtml}</div>` : "";
|
|
5842
|
+
const footer = footerHtml ? `<div class="formfeed-chrome" data-ff-chrome="footer" style="${pdf ? flowChromeStyle(settings, "footer") : `${chromeBoxStyle(settings, "footer")}margin-top:8px`}">${pageNumberSpans(footerHtml, "1", "1")}</div>` : "";
|
|
5843
|
+
return intoBody(
|
|
5844
|
+
intoHead(
|
|
5845
|
+
draft.document,
|
|
5846
|
+
`${documentMeta(options)}${chrome}${options.editing ? textEditScript : ""}${inspectScript}${zoomGestureScript}${pdf ? overflowScript("flow") : ""}${pdf && options.audit ? auditScript("flow") : ""}`
|
|
5847
|
+
),
|
|
5848
|
+
header,
|
|
5849
|
+
footer
|
|
5850
|
+
);
|
|
5758
5851
|
}
|
|
5759
5852
|
function canvasDocument(draft) {
|
|
5760
5853
|
const chrome = `<style data-formfeed="stage">html, body { background: transparent !important; margin: 0 !important; }</style>`;
|
|
@@ -5781,14 +5874,17 @@ html { background: #e5e7eb; }
|
|
|
5781
5874
|
`;
|
|
5782
5875
|
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>`;
|
|
5783
5876
|
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>`;
|
|
5784
|
-
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>`;
|
|
5877
|
+
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(); if (window.formfeedRunAudit) window.formfeedRunAudit(flow.total); try { if (window.formfeedEditReady) window.formfeedEditReady(); } catch (e) {} } };</script>`;
|
|
5785
5878
|
const script = `<script src="${options.pagedScriptUrl}"></script>`;
|
|
5786
5879
|
const header = headerHtml ? `<div class="ff-running-header">${pageNumberSpans(headerHtml, '<span class="ff-page-no"></span>', '<span class="ff-page-total"></span>')}</div>` : "";
|
|
5787
5880
|
const footer = footerHtml ? `<div class="ff-running-footer">${pageNumberSpans(footerHtml, '<span class="ff-page-no"></span>', '<span class="ff-page-total"></span>')}</div>` : "";
|
|
5788
|
-
return
|
|
5789
|
-
|
|
5790
|
-
|
|
5791
|
-
|
|
5881
|
+
return intoBody(
|
|
5882
|
+
intoHead(
|
|
5883
|
+
draft.document,
|
|
5884
|
+
`${documentMeta(options)}<style data-formfeed="paged">${runningCss}</style>${selectorGuard}${boxSizingGuard}${overflowScript("paged")}${options.audit ? auditScript("paged") : ""}${config}${script}${options.editing ? textEditScript : ""}${inspectScript}${pageNavScript}${zoomGestureScript}`
|
|
5885
|
+
),
|
|
5886
|
+
`${header}${footer}`
|
|
5887
|
+
);
|
|
5792
5888
|
}
|
|
5793
5889
|
|
|
5794
5890
|
// packages/engine/src/lib/source-scan.ts
|
|
@@ -6020,11 +6116,11 @@ function locate(starts, offset) {
|
|
|
6020
6116
|
}
|
|
6021
6117
|
return { line: low + 1, column: offset - (starts[low] ?? 0) + 1 };
|
|
6022
6118
|
}
|
|
6023
|
-
function offsetOf(starts, sourceLength,
|
|
6024
|
-
const start = starts[
|
|
6119
|
+
function offsetOf(starts, sourceLength, line2, column) {
|
|
6120
|
+
const start = starts[line2 - 1];
|
|
6025
6121
|
if (start === void 0 || column < 1) return null;
|
|
6026
6122
|
const offset = start + column - 1;
|
|
6027
|
-
const next = starts[
|
|
6123
|
+
const next = starts[line2] ?? sourceLength + 1;
|
|
6028
6124
|
return offset < next ? offset : null;
|
|
6029
6125
|
}
|
|
6030
6126
|
|
|
@@ -6180,7 +6276,10 @@ function editableRegionAt(source, engine, at) {
|
|
|
6180
6276
|
const hasText = region.parts.some(
|
|
6181
6277
|
(p) => p.kind === "text" && decodeText2(source.slice(p.start, p.end)).text.trim() !== ""
|
|
6182
6278
|
);
|
|
6183
|
-
|
|
6279
|
+
const hasField = region.parts.some(
|
|
6280
|
+
(p) => p.kind === "chip" && p.chip === "expression"
|
|
6281
|
+
);
|
|
6282
|
+
return hasText || hasField ? region : { reason: "no-text" };
|
|
6184
6283
|
}
|
|
6185
6284
|
function findRegionAgain(source, engine, outer) {
|
|
6186
6285
|
const first = source.indexOf(outer);
|
|
@@ -6188,6 +6287,9 @@ function findRegionAgain(source, engine, outer) {
|
|
|
6188
6287
|
const found = editableRegionAt(source, engine, first);
|
|
6189
6288
|
return "reason" in found ? null : found;
|
|
6190
6289
|
}
|
|
6290
|
+
function regionPosition(source, region) {
|
|
6291
|
+
return locate(lineStarts(source), region.tagStart);
|
|
6292
|
+
}
|
|
6191
6293
|
function regionChips(source, region) {
|
|
6192
6294
|
const chips = [];
|
|
6193
6295
|
for (const part of region.parts)
|
|
@@ -6272,18 +6374,18 @@ function applyRegionEdit(source, engine, region, items) {
|
|
|
6272
6374
|
const rewritten = source.slice(0, region.start) + whole + source.slice(region.end);
|
|
6273
6375
|
return readsBack(rewritten, engine, region.tagStart, expected) ? { source: rewritten } : { error: "invalid" };
|
|
6274
6376
|
}
|
|
6275
|
-
function translationItems(
|
|
6377
|
+
function translationItems(text4) {
|
|
6276
6378
|
const items = [];
|
|
6277
6379
|
const names = [];
|
|
6278
6380
|
let last = 0;
|
|
6279
|
-
for (const match of
|
|
6381
|
+
for (const match of text4.matchAll(/\{(\w+)\}/g)) {
|
|
6280
6382
|
if (match.index > last)
|
|
6281
|
-
items.push({ kind: "text", text:
|
|
6383
|
+
items.push({ kind: "text", text: text4.slice(last, match.index) });
|
|
6282
6384
|
items.push({ kind: "chip", index: names.length });
|
|
6283
6385
|
names.push(match[1] ?? "");
|
|
6284
6386
|
last = match.index + match[0].length;
|
|
6285
6387
|
}
|
|
6286
|
-
if (last <
|
|
6388
|
+
if (last < text4.length) items.push({ kind: "text", text: text4.slice(last) });
|
|
6287
6389
|
return { items, names };
|
|
6288
6390
|
}
|
|
6289
6391
|
function translationText(items, names) {
|
|
@@ -6527,9 +6629,9 @@ function translationCall(engine, inner) {
|
|
|
6527
6629
|
);
|
|
6528
6630
|
return match ? { key: match[2] ?? "", params: parseParams(match[3] ?? "", "=", " ") } : null;
|
|
6529
6631
|
}
|
|
6530
|
-
function parseParams(
|
|
6632
|
+
function parseParams(text4, assign, separator) {
|
|
6531
6633
|
const params = {};
|
|
6532
|
-
for (const piece of splitTopLevel(
|
|
6634
|
+
for (const piece of splitTopLevel(text4, separator)) {
|
|
6533
6635
|
const at = piece.indexOf(assign);
|
|
6534
6636
|
if (at <= 0) continue;
|
|
6535
6637
|
const name = piece.slice(0, at).trim().replace(/^['"]|['"]$/g, "");
|
|
@@ -6537,12 +6639,12 @@ function parseParams(text2, assign, separator) {
|
|
|
6537
6639
|
}
|
|
6538
6640
|
return params;
|
|
6539
6641
|
}
|
|
6540
|
-
function splitTopLevel(
|
|
6642
|
+
function splitTopLevel(text4, separator) {
|
|
6541
6643
|
const pieces = [];
|
|
6542
6644
|
let depth = 0;
|
|
6543
6645
|
let quote2 = null;
|
|
6544
6646
|
let current = "";
|
|
6545
|
-
for (const ch of
|
|
6647
|
+
for (const ch of text4) {
|
|
6546
6648
|
if (quote2) {
|
|
6547
6649
|
if (ch === quote2) quote2 = null;
|
|
6548
6650
|
} else if (ch === '"' || ch === "'") quote2 = ch;
|
|
@@ -6567,7 +6669,7 @@ function entityChar(reference) {
|
|
|
6567
6669
|
return code === void 0 ? null : String.fromCharCode(code);
|
|
6568
6670
|
}
|
|
6569
6671
|
function decodeText2(raw) {
|
|
6570
|
-
let
|
|
6672
|
+
let text4 = "";
|
|
6571
6673
|
const map = [];
|
|
6572
6674
|
let i = 0;
|
|
6573
6675
|
while (i < raw.length) {
|
|
@@ -6577,23 +6679,23 @@ function decodeText2(raw) {
|
|
|
6577
6679
|
const decoded = match ? entityChar(match[1] ?? "") : null;
|
|
6578
6680
|
if (match && decoded !== null) {
|
|
6579
6681
|
for (let u = 0; u < decoded.length; u++) map.push(i);
|
|
6580
|
-
|
|
6682
|
+
text4 += decoded;
|
|
6581
6683
|
i += match[0].length;
|
|
6582
6684
|
continue;
|
|
6583
6685
|
}
|
|
6584
6686
|
}
|
|
6585
|
-
|
|
6687
|
+
text4 += raw[i];
|
|
6586
6688
|
map.push(i);
|
|
6587
6689
|
i++;
|
|
6588
6690
|
}
|
|
6589
6691
|
map.push(raw.length);
|
|
6590
|
-
return { text:
|
|
6692
|
+
return { text: text4, map };
|
|
6591
6693
|
}
|
|
6592
|
-
function encodeText(
|
|
6694
|
+
function encodeText(text4, keepNbsp, allBraces = false) {
|
|
6593
6695
|
let out = "";
|
|
6594
|
-
for (let k = 0; k <
|
|
6595
|
-
const ch =
|
|
6596
|
-
const next =
|
|
6696
|
+
for (let k = 0; k < text4.length; k++) {
|
|
6697
|
+
const ch = text4[k] ?? "";
|
|
6698
|
+
const next = text4[k + 1];
|
|
6597
6699
|
if (ch === "&") out += "&";
|
|
6598
6700
|
else if (ch === "<") out += "<";
|
|
6599
6701
|
else if (ch === ">") out += ">";
|
|
@@ -6605,8 +6707,8 @@ function encodeText(text2, keepNbsp, allBraces = false) {
|
|
|
6605
6707
|
}
|
|
6606
6708
|
return out;
|
|
6607
6709
|
}
|
|
6608
|
-
function encodeTemplateText(
|
|
6609
|
-
return encodeText(
|
|
6710
|
+
function encodeTemplateText(text4) {
|
|
6711
|
+
return encodeText(text4, true);
|
|
6610
6712
|
}
|
|
6611
6713
|
function spanOf(part) {
|
|
6612
6714
|
return part ? [part.start, part.end] : [0, 0];
|
|
@@ -6640,7 +6742,7 @@ function rewriteSegment(source, segStart, segEnd, parts, next, breakSpelling) {
|
|
|
6640
6742
|
const to = map[old.length - suffix] ?? segEnd;
|
|
6641
6743
|
const middle = next.slice(prefix, next.length - suffix);
|
|
6642
6744
|
const keepNbsp = old.slice(prefix, old.length - suffix).includes(NBSP);
|
|
6643
|
-
const written = middle.split(BREAK).map((
|
|
6745
|
+
const written = middle.split(BREAK).map((text4) => encodeText(text4, keepNbsp)).join(breakSpelling);
|
|
6644
6746
|
return source.slice(segStart, from) + written + source.slice(to, segEnd);
|
|
6645
6747
|
}
|
|
6646
6748
|
var isHighSurrogate = (code) => code >= 55296 && code <= 56319;
|
|
@@ -6669,10 +6771,10 @@ var editAttribute = "data-ff-edit";
|
|
|
6669
6771
|
function parseSourceAttribute(value) {
|
|
6670
6772
|
const match = /^(body|header|footer):(\d+):(\d+)$/.exec(value ?? "");
|
|
6671
6773
|
if (!match) return null;
|
|
6672
|
-
const
|
|
6774
|
+
const line2 = Number(match[2]);
|
|
6673
6775
|
const column = Number(match[3]);
|
|
6674
|
-
if (
|
|
6675
|
-
return { file: match[1], line, column };
|
|
6776
|
+
if (line2 < 1 || column < 1) return null;
|
|
6777
|
+
return { file: match[1], line: line2, column };
|
|
6676
6778
|
}
|
|
6677
6779
|
function annotateSourcePositions(source, engine, file, options = {}) {
|
|
6678
6780
|
const scanner = new Scanner(source, engine);
|
|
@@ -6719,12 +6821,12 @@ function annotateSourcePositions(source, engine, file, options = {}) {
|
|
|
6719
6821
|
const after = source[nameEnd];
|
|
6720
6822
|
const plainName = after === void 0 || after === ">" || after === "/" || /\s/.test(after);
|
|
6721
6823
|
if (plainName && !source.slice(nameEnd, end).toLowerCase().includes(sourceAttribute)) {
|
|
6722
|
-
const { line, column } = locate(lines, i);
|
|
6824
|
+
const { line: line2, column } = locate(lines, i);
|
|
6723
6825
|
const region = options.editable ? editableRegionAt(source, engine, i) : null;
|
|
6724
6826
|
const edit = region && !("reason" in region) ? ` ${editAttribute}="${region.kind}"` : "";
|
|
6725
6827
|
out.push(
|
|
6726
6828
|
source.slice(copied, nameEnd),
|
|
6727
|
-
` ${sourceAttribute}="${file}:${
|
|
6829
|
+
` ${sourceAttribute}="${file}:${line2}:${column}"${edit}`
|
|
6728
6830
|
);
|
|
6729
6831
|
copied = nameEnd;
|
|
6730
6832
|
}
|
|
@@ -6844,8 +6946,8 @@ function parseDesign(value) {
|
|
|
6844
6946
|
let guides;
|
|
6845
6947
|
const g = v["guides"];
|
|
6846
6948
|
if (g && typeof g === "object") {
|
|
6847
|
-
const
|
|
6848
|
-
guides = { x:
|
|
6949
|
+
const list3 = (x) => (Array.isArray(x) ? x : []).filter((n) => typeof n === "number" && Number.isFinite(n)).slice(0, 100);
|
|
6950
|
+
guides = { x: list3(g["x"]), y: list3(g["y"]) };
|
|
6849
6951
|
}
|
|
6850
6952
|
if (problems.length) return { design: null, problems };
|
|
6851
6953
|
return {
|
|
@@ -7395,11 +7497,11 @@ function googleFontsUrl(uses) {
|
|
|
7395
7497
|
|
|
7396
7498
|
// packages/engine/src/lib/design/hash.ts
|
|
7397
7499
|
function designOutputHash(html, css2) {
|
|
7398
|
-
const
|
|
7500
|
+
const text4 = `${html}\0${css2}`;
|
|
7399
7501
|
let a = 2166136261;
|
|
7400
7502
|
let b = 16777619 ^ 2654435769;
|
|
7401
|
-
for (let i = 0; i <
|
|
7402
|
-
const code =
|
|
7503
|
+
for (let i = 0; i < text4.length; i++) {
|
|
7504
|
+
const code = text4.charCodeAt(i);
|
|
7403
7505
|
if (code === 13) continue;
|
|
7404
7506
|
a = Math.imul(a ^ code, 16777619) >>> 0;
|
|
7405
7507
|
b = Math.imul(b ^ code, 16777619) >>> 0;
|
|
@@ -7509,7 +7611,7 @@ var tokenPattern2 = /^[a-z][a-z0-9-]{0,31}$/;
|
|
|
7509
7611
|
function emitDesign(design2, engine, size) {
|
|
7510
7612
|
const lines = ['<div class="ff-design">'];
|
|
7511
7613
|
const map = {};
|
|
7512
|
-
const
|
|
7614
|
+
const rules2 = [];
|
|
7513
7615
|
for (const layer of design2.layers) {
|
|
7514
7616
|
if (!layer.visible) continue;
|
|
7515
7617
|
const markup = layerHtml(layer, engine);
|
|
@@ -7517,7 +7619,7 @@ function emitDesign(design2, engine, size) {
|
|
|
7517
7619
|
` ${layer.showWhen?.path ? ifBlock(engine, layer.showWhen.path, markup) : markup}`
|
|
7518
7620
|
);
|
|
7519
7621
|
map[layer.id] = { start: lines.length, end: lines.length };
|
|
7520
|
-
|
|
7622
|
+
rules2.push(...layerCss(layer));
|
|
7521
7623
|
}
|
|
7522
7624
|
lines.push("</div>");
|
|
7523
7625
|
const html = `${lines.join("\n")}
|
|
@@ -7542,7 +7644,7 @@ function emitDesign(design2, engine, size) {
|
|
|
7542
7644
|
})} }`,
|
|
7543
7645
|
".ff-layer { position: absolute; box-sizing: border-box; margin: 0; }"
|
|
7544
7646
|
];
|
|
7545
|
-
const css2 = `${[...head, ...
|
|
7647
|
+
const css2 = `${[...head, ...rules2].join("\n")}
|
|
7546
7648
|
`;
|
|
7547
7649
|
return { html, css: css2, map, output: designOutputHash(html, css2) };
|
|
7548
7650
|
}
|
|
@@ -7626,32 +7728,32 @@ function imageSource(source, engine) {
|
|
|
7626
7728
|
return `{{ brand.logo.${source.brandLogo} }}`;
|
|
7627
7729
|
}
|
|
7628
7730
|
function layerCss(layer) {
|
|
7629
|
-
const
|
|
7731
|
+
const text4 = layer.type === "text" ? layer : null;
|
|
7630
7732
|
const box = {
|
|
7631
7733
|
left: px(layer.x),
|
|
7632
7734
|
top: px(layer.y),
|
|
7633
7735
|
width: px(layer.width),
|
|
7634
|
-
height:
|
|
7736
|
+
height: text4?.sizing === "grow" ? void 0 : px(layer.height),
|
|
7635
7737
|
opacity: layer.opacity < 1 ? num(layer.opacity) : void 0,
|
|
7636
7738
|
transform: layer.rotation ? `rotate(${num(layer.rotation)}deg)` : void 0,
|
|
7637
7739
|
"border-radius": layer.type === "shape" && layer.shape === "ellipse" ? "50%" : layer.radius ? px(layer.radius) : void 0,
|
|
7638
7740
|
border: layer.stroke && layer.stroke.width > 0 ? `${px(layer.stroke.width)} solid ${paint(layer.stroke.paint)}` : void 0,
|
|
7639
|
-
"box-shadow": layer.shadow && !
|
|
7741
|
+
"box-shadow": layer.shadow && !text4 ? shadow(layer.shadow) : void 0
|
|
7640
7742
|
};
|
|
7641
|
-
if (
|
|
7743
|
+
if (text4) {
|
|
7642
7744
|
Object.assign(box, {
|
|
7643
7745
|
display: "flex",
|
|
7644
7746
|
"flex-direction": "column",
|
|
7645
|
-
"justify-content":
|
|
7646
|
-
overflow:
|
|
7647
|
-
padding:
|
|
7648
|
-
background:
|
|
7747
|
+
"justify-content": text4.valign === "middle" ? "center" : text4.valign === "bottom" ? "flex-end" : "flex-start",
|
|
7748
|
+
overflow: text4.sizing === "grow" ? void 0 : "hidden",
|
|
7749
|
+
padding: text4.padding ? px(text4.padding) : void 0,
|
|
7750
|
+
background: text4.fill ? paint(text4.fill) : void 0
|
|
7649
7751
|
});
|
|
7650
|
-
const s =
|
|
7651
|
-
const clamp =
|
|
7752
|
+
const s = text4.style;
|
|
7753
|
+
const clamp = text4.maxLines ? {
|
|
7652
7754
|
display: "-webkit-box",
|
|
7653
7755
|
"-webkit-box-orient": "vertical",
|
|
7654
|
-
"-webkit-line-clamp": String(
|
|
7756
|
+
"-webkit-line-clamp": String(text4.maxLines),
|
|
7655
7757
|
overflow: "hidden"
|
|
7656
7758
|
} : {};
|
|
7657
7759
|
const inner = decl({
|
|
@@ -7667,7 +7769,7 @@ function layerCss(layer) {
|
|
|
7667
7769
|
"font-style": s.italic ? "italic" : void 0,
|
|
7668
7770
|
"text-transform": s.uppercase ? "uppercase" : void 0,
|
|
7669
7771
|
"text-decoration": [s.underline && "underline", s.strike && "line-through"].filter(Boolean).join(" ") || void 0,
|
|
7670
|
-
"text-shadow":
|
|
7772
|
+
"text-shadow": text4.shadow ? shadow(text4.shadow) : void 0,
|
|
7671
7773
|
"overflow-wrap": "break-word",
|
|
7672
7774
|
...clamp
|
|
7673
7775
|
});
|
|
@@ -8006,6 +8108,2445 @@ var designStarters = [
|
|
|
8006
8108
|
}
|
|
8007
8109
|
];
|
|
8008
8110
|
|
|
8111
|
+
// packages/engine/src/lib/einvoice/codes.generated.ts
|
|
8112
|
+
var list2 = (codes) => new Set(codes.split(" "));
|
|
8113
|
+
var CODE_LIST_RELEASE = "1.09.2";
|
|
8114
|
+
var documentTypeCodes = list2(
|
|
8115
|
+
"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"
|
|
8116
|
+
);
|
|
8117
|
+
var countryCodes = list2(
|
|
8118
|
+
"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"
|
|
8119
|
+
);
|
|
8120
|
+
var unitCodes = list2(
|
|
8121
|
+
"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"
|
|
8122
|
+
);
|
|
8123
|
+
var electronicAddressSchemes = list2(
|
|
8124
|
+
"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"
|
|
8125
|
+
);
|
|
8126
|
+
var currencyCodes = list2(
|
|
8127
|
+
"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"
|
|
8128
|
+
);
|
|
8129
|
+
var paymentMeansCodes = list2(
|
|
8130
|
+
"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"
|
|
8131
|
+
);
|
|
8132
|
+
|
|
8133
|
+
// packages/engine/src/lib/einvoice/decimal.ts
|
|
8134
|
+
function decimalText(value) {
|
|
8135
|
+
if (typeof value === "string") {
|
|
8136
|
+
const text5 = value.trim();
|
|
8137
|
+
return /^-?\d+(\.\d+)?$/.test(text5) ? trimZeros(text5) : null;
|
|
8138
|
+
}
|
|
8139
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return null;
|
|
8140
|
+
const text4 = value.toPrecision(15);
|
|
8141
|
+
return /^-?\d+(\.\d+)?$/.test(text4) ? trimZeros(text4) : null;
|
|
8142
|
+
}
|
|
8143
|
+
function trimZeros(text4) {
|
|
8144
|
+
const trimmed = text4.includes(".") ? text4.replace(/0+$/, "").replace(/\.$/, "") : text4;
|
|
8145
|
+
return trimmed === "-0" ? "0" : trimmed;
|
|
8146
|
+
}
|
|
8147
|
+
function decimalPlaces(text4) {
|
|
8148
|
+
const dot = text4.indexOf(".");
|
|
8149
|
+
return dot === -1 ? 0 : text4.length - dot - 1;
|
|
8150
|
+
}
|
|
8151
|
+
function toUnits(text4, scale) {
|
|
8152
|
+
const negative = text4.startsWith("-");
|
|
8153
|
+
const [whole = "0", fraction = ""] = (negative ? text4.slice(1) : text4).split(
|
|
8154
|
+
"."
|
|
8155
|
+
);
|
|
8156
|
+
const units = BigInt(whole + fraction.padEnd(scale, "0").slice(0, scale));
|
|
8157
|
+
return negative ? -units : units;
|
|
8158
|
+
}
|
|
8159
|
+
function fromUnits(units, scale, places = scale) {
|
|
8160
|
+
const negative = units < 0n;
|
|
8161
|
+
const digits = (negative ? -units : units).toString().padStart(scale + 1, "0");
|
|
8162
|
+
const whole = digits.slice(0, digits.length - scale);
|
|
8163
|
+
const fraction = digits.slice(digits.length - scale).padEnd(places, "0");
|
|
8164
|
+
const text4 = places > 0 ? `${whole}.${fraction.slice(0, places)}` : whole;
|
|
8165
|
+
return negative && /[1-9]/.test(text4) ? `-${text4}` : text4;
|
|
8166
|
+
}
|
|
8167
|
+
function withPlaces(text4, min) {
|
|
8168
|
+
const places = decimalPlaces(text4);
|
|
8169
|
+
if (places >= min) return text4;
|
|
8170
|
+
return places === 0 ? `${text4}.${"0".repeat(min)}` : text4 + "0".repeat(min - places);
|
|
8171
|
+
}
|
|
8172
|
+
function divideRounded(value, divisor) {
|
|
8173
|
+
const negative = value < 0n !== divisor < 0n;
|
|
8174
|
+
const a = value < 0n ? -value : value;
|
|
8175
|
+
const b = divisor < 0n ? -divisor : divisor;
|
|
8176
|
+
const quotient = (a * 2n + b) / (b * 2n);
|
|
8177
|
+
return negative ? -quotient : quotient;
|
|
8178
|
+
}
|
|
8179
|
+
var abs = (value) => value < 0n ? -value : value;
|
|
8180
|
+
|
|
8181
|
+
// packages/engine/src/lib/einvoice/schema.ts
|
|
8182
|
+
import { z } from "zod";
|
|
8183
|
+
var numeric = z.union([z.number(), z.string()]);
|
|
8184
|
+
var text2 = z.string().trim().min(1);
|
|
8185
|
+
var isoDate2 = z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "Expected a date as YYYY-MM-DD");
|
|
8186
|
+
var identifier2 = z.union([
|
|
8187
|
+
text2,
|
|
8188
|
+
z.object({ value: text2, scheme: text2.optional() })
|
|
8189
|
+
]);
|
|
8190
|
+
var address = z.object({
|
|
8191
|
+
street: text2.optional(),
|
|
8192
|
+
street2: text2.optional(),
|
|
8193
|
+
street3: text2.optional(),
|
|
8194
|
+
postcode: text2.optional(),
|
|
8195
|
+
city: text2.optional(),
|
|
8196
|
+
/** ISO 3166-1 alpha-2 (BT-40, BT-55, BT-80). */
|
|
8197
|
+
country: text2,
|
|
8198
|
+
/** Region or province (BT-39, BT-54, BT-79). */
|
|
8199
|
+
subdivision: text2.optional()
|
|
8200
|
+
});
|
|
8201
|
+
var contact = z.object({
|
|
8202
|
+
name: text2.optional(),
|
|
8203
|
+
phone: text2.optional(),
|
|
8204
|
+
email: text2.optional()
|
|
8205
|
+
});
|
|
8206
|
+
var party = z.object({
|
|
8207
|
+
name: text2,
|
|
8208
|
+
/** The name the business trades under, where it differs (BT-28, BT-45). */
|
|
8209
|
+
trading_name: text2.optional(),
|
|
8210
|
+
/** An identifier of the party (BT-29, BT-46). */
|
|
8211
|
+
id: identifier2.optional(),
|
|
8212
|
+
/** The register entry (BT-30, BT-47): a SIREN, a company number. */
|
|
8213
|
+
legal_registration: identifier2.optional(),
|
|
8214
|
+
vat_id: text2.optional(),
|
|
8215
|
+
address,
|
|
8216
|
+
contact: contact.optional(),
|
|
8217
|
+
/** Where the party receives electronic invoices (BT-34, BT-49); a bare e-mail address is scheme EM. */
|
|
8218
|
+
electronic_address: identifier2.optional()
|
|
8219
|
+
});
|
|
8220
|
+
var period = z.object({ start: isoDate2.optional(), end: isoDate2.optional() });
|
|
8221
|
+
var VAT_CATEGORIES = ["S", "Z", "E", "AE", "K", "G", "O"];
|
|
8222
|
+
var vatCategory = z.enum(VAT_CATEGORIES);
|
|
8223
|
+
var lineTax = z.object({
|
|
8224
|
+
category: vatCategory,
|
|
8225
|
+
/** Percent, `19` for 19 %. Left out for category O only. */
|
|
8226
|
+
rate: numeric.optional()
|
|
8227
|
+
});
|
|
8228
|
+
var allowanceOrCharge = z.object({
|
|
8229
|
+
amount: numeric,
|
|
8230
|
+
reason: text2.optional(),
|
|
8231
|
+
/** UNTDID 5189 for an allowance, UNTDID 7161 for a charge. */
|
|
8232
|
+
reason_code: text2.optional(),
|
|
8233
|
+
base_amount: numeric.optional(),
|
|
8234
|
+
percent: numeric.optional()
|
|
8235
|
+
});
|
|
8236
|
+
var line = z.object({
|
|
8237
|
+
id: z.union([text2, z.number()]),
|
|
8238
|
+
name: text2,
|
|
8239
|
+
description: text2.optional(),
|
|
8240
|
+
quantity: numeric,
|
|
8241
|
+
/** UN/ECE Recommendation 20: C62 a piece, HUR an hour, DAY a day, KGM a kilogram. */
|
|
8242
|
+
unit_code: text2.default("C62"),
|
|
8243
|
+
net_price: numeric,
|
|
8244
|
+
/** The quantity the price is for, where it is not one unit (BT-149). */
|
|
8245
|
+
price_base_quantity: numeric.optional(),
|
|
8246
|
+
net_amount: numeric,
|
|
8247
|
+
tax: lineTax,
|
|
8248
|
+
period: period.optional(),
|
|
8249
|
+
allowances: z.array(allowanceOrCharge).optional(),
|
|
8250
|
+
charges: z.array(allowanceOrCharge).optional(),
|
|
8251
|
+
buyer_accounting_reference: text2.optional(),
|
|
8252
|
+
note: text2.optional(),
|
|
8253
|
+
/** The seller's and the buyer's article numbers (BT-155, BT-156), a GTIN and the like (BT-157). */
|
|
8254
|
+
seller_item_id: text2.optional(),
|
|
8255
|
+
buyer_item_id: text2.optional(),
|
|
8256
|
+
standard_item_id: identifier2.optional(),
|
|
8257
|
+
/** The line of the buyer's order this one answers (BT-132). */
|
|
8258
|
+
order_line_reference: text2.optional()
|
|
8259
|
+
});
|
|
8260
|
+
var breakdown = z.object({
|
|
8261
|
+
category: vatCategory,
|
|
8262
|
+
rate: numeric.optional(),
|
|
8263
|
+
basis: numeric,
|
|
8264
|
+
amount: numeric,
|
|
8265
|
+
exemption_reason: text2.optional(),
|
|
8266
|
+
/** A VATEX code (BT-121), for example VATEX-EU-AE for reverse charge. */
|
|
8267
|
+
exemption_reason_code: text2.optional()
|
|
8268
|
+
});
|
|
8269
|
+
var totals = z.object({
|
|
8270
|
+
line_net: numeric,
|
|
8271
|
+
allowances: numeric.optional(),
|
|
8272
|
+
charges: numeric.optional(),
|
|
8273
|
+
tax_basis: numeric,
|
|
8274
|
+
tax_total: numeric,
|
|
8275
|
+
/** The VAT total in the accounting currency (BT-111). */
|
|
8276
|
+
tax_total_accounting: numeric.optional(),
|
|
8277
|
+
grand: numeric,
|
|
8278
|
+
prepaid: numeric.optional(),
|
|
8279
|
+
rounding: numeric.optional(),
|
|
8280
|
+
due: numeric
|
|
8281
|
+
});
|
|
8282
|
+
var payment = z.object({
|
|
8283
|
+
/** UNTDID 4461: 58 SEPA credit transfer, 59 SEPA direct debit, 30 credit transfer, 48 card. */
|
|
8284
|
+
means_code: z.union([text2, z.number()]).optional(),
|
|
8285
|
+
iban: text2.optional(),
|
|
8286
|
+
bic: text2.optional(),
|
|
8287
|
+
account_name: text2.optional(),
|
|
8288
|
+
/** What the payer quotes with the payment (BT-83). */
|
|
8289
|
+
reference: text2.optional(),
|
|
8290
|
+
terms: text2.optional(),
|
|
8291
|
+
due_date: isoDate2.optional(),
|
|
8292
|
+
/** Direct debit: the mandate (BT-89), the creditor's identifier (BT-90), the account debited (BT-91). */
|
|
8293
|
+
mandate_id: text2.optional(),
|
|
8294
|
+
creditor_id: text2.optional(),
|
|
8295
|
+
debited_iban: text2.optional()
|
|
8296
|
+
});
|
|
8297
|
+
var note = z.object({
|
|
8298
|
+
text: text2,
|
|
8299
|
+
/** UNTDID 4451, which French invoices use for their statutory mentions (PMT, PMD, AAB). */
|
|
8300
|
+
subject_code: text2.optional()
|
|
8301
|
+
});
|
|
8302
|
+
var invoiceSchema = z.object({
|
|
8303
|
+
number: text2,
|
|
8304
|
+
issue_date: isoDate2,
|
|
8305
|
+
/** UNTDID 1001: 380 invoice, 381 credit note, 384 corrected invoice, 389 self-billed. */
|
|
8306
|
+
type_code: z.union([text2, z.number()]).default("380"),
|
|
8307
|
+
currency: text2,
|
|
8308
|
+
/** The currency the VAT is accounted in, where the invoice is in another (BT-6); goes with `totals.tax_total_accounting`. */
|
|
8309
|
+
accounting_currency: text2.optional(),
|
|
8310
|
+
/** The buyer's routing reference (BT-10); a German authority's Leitweg-ID goes here. */
|
|
8311
|
+
buyer_reference: text2.optional(),
|
|
8312
|
+
order_reference: text2.optional(),
|
|
8313
|
+
contract_reference: text2.optional(),
|
|
8314
|
+
note: text2.optional(),
|
|
8315
|
+
notes: z.array(note).optional(),
|
|
8316
|
+
period: period.optional(),
|
|
8317
|
+
/** The invoices a credit note or a correction refers to (BG-3). */
|
|
8318
|
+
preceding_invoices: z.array(z.object({ number: text2, issue_date: isoDate2.optional() })).optional(),
|
|
8319
|
+
/** France (spec 17 §4.4): what was sold, and the billing framework's code where the plain case does not fit. */
|
|
8320
|
+
operation: z.enum(["goods", "services", "mixed"]).optional(),
|
|
8321
|
+
operation_code: text2.optional(),
|
|
8322
|
+
seller: party.extend({
|
|
8323
|
+
tax_number: text2.optional(),
|
|
8324
|
+
/** Further legal information the invoice must state (BT-33): register court, capital. */
|
|
8325
|
+
legal_info: text2.optional(),
|
|
8326
|
+
/** France: VAT is owed when the invoice is issued, not when it is paid. */
|
|
8327
|
+
vat_on_debits: z.boolean().optional()
|
|
8328
|
+
}),
|
|
8329
|
+
buyer: party.extend({
|
|
8330
|
+
/** France: the buyer's SIREN, nine digits. */
|
|
8331
|
+
siren: text2.optional()
|
|
8332
|
+
}),
|
|
8333
|
+
delivery: z.object({
|
|
8334
|
+
name: text2.optional(),
|
|
8335
|
+
date: isoDate2.optional(),
|
|
8336
|
+
address: address.optional()
|
|
8337
|
+
}).optional(),
|
|
8338
|
+
lines: z.array(line).min(1),
|
|
8339
|
+
/** Allowances and charges on the whole document (BG-20, BG-21), each with the VAT it falls under. */
|
|
8340
|
+
allowances: z.array(allowanceOrCharge.extend({ tax: lineTax })).optional(),
|
|
8341
|
+
charges: z.array(allowanceOrCharge.extend({ tax: lineTax })).optional(),
|
|
8342
|
+
tax: z.object({ breakdown: z.array(breakdown).min(1) }),
|
|
8343
|
+
totals,
|
|
8344
|
+
payment: payment.optional()
|
|
8345
|
+
});
|
|
8346
|
+
var EINVOICE_PROFILES = ["basic", "en16931"];
|
|
8347
|
+
var EINVOICE_FLAVOURS = ["factur-x", "zugferd"];
|
|
8348
|
+
var einvoiceOptionsSchema = z.object({
|
|
8349
|
+
profile: z.string().optional(),
|
|
8350
|
+
flavour: z.string().optional(),
|
|
8351
|
+
xml: z.enum(["embedded", "both"]).optional(),
|
|
8352
|
+
display_check: z.enum(["warn", "strict"]).optional()
|
|
8353
|
+
}).strict();
|
|
8354
|
+
var defaultEinvoiceOptions = {
|
|
8355
|
+
profile: "en16931",
|
|
8356
|
+
flavour: "factur-x",
|
|
8357
|
+
xml: "embedded",
|
|
8358
|
+
display_check: "warn"
|
|
8359
|
+
};
|
|
8360
|
+
var knownUnsupported = {
|
|
8361
|
+
minimum: "MINIMUM carries no invoice lines and is not an invoice on its own; use basic or en16931",
|
|
8362
|
+
"basic-wl": "BASIC WL carries no invoice lines and is not an invoice on its own; use basic or en16931",
|
|
8363
|
+
basicwl: "BASIC WL carries no invoice lines and is not an invoice on its own; use basic or en16931",
|
|
8364
|
+
extended: "EXTENDED is not offered; use en16931, which carries the full European standard",
|
|
8365
|
+
xrechnung: "XRechnung is not offered yet; use en16931"
|
|
8366
|
+
};
|
|
8367
|
+
function resolveEinvoiceOptions(...layers) {
|
|
8368
|
+
let merged = null;
|
|
8369
|
+
for (const layer of layers) {
|
|
8370
|
+
if (layer === false) merged = null;
|
|
8371
|
+
else if (layer) merged = { ...merged ?? {}, ...definedOnly(layer) };
|
|
8372
|
+
}
|
|
8373
|
+
if (!merged) return { ok: true, options: null };
|
|
8374
|
+
const profile = (merged.profile ?? defaultEinvoiceOptions.profile).trim().toLowerCase();
|
|
8375
|
+
const flavour = (merged.flavour ?? defaultEinvoiceOptions.flavour).trim().toLowerCase();
|
|
8376
|
+
if (!EINVOICE_PROFILES.includes(profile))
|
|
8377
|
+
return {
|
|
8378
|
+
ok: false,
|
|
8379
|
+
field: "profile",
|
|
8380
|
+
value: profile,
|
|
8381
|
+
reason: knownUnsupported[profile] ?? `Unknown profile; use ${EINVOICE_PROFILES.join(" or ")}`
|
|
8382
|
+
};
|
|
8383
|
+
if (!EINVOICE_FLAVOURS.includes(flavour))
|
|
8384
|
+
return {
|
|
8385
|
+
ok: false,
|
|
8386
|
+
field: "flavour",
|
|
8387
|
+
value: flavour,
|
|
8388
|
+
reason: `Unknown flavour; use ${EINVOICE_FLAVOURS.join(" or ")}`
|
|
8389
|
+
};
|
|
8390
|
+
return {
|
|
8391
|
+
ok: true,
|
|
8392
|
+
options: {
|
|
8393
|
+
profile,
|
|
8394
|
+
flavour,
|
|
8395
|
+
xml: merged.xml ?? defaultEinvoiceOptions.xml,
|
|
8396
|
+
display_check: merged.display_check ?? defaultEinvoiceOptions.display_check
|
|
8397
|
+
}
|
|
8398
|
+
};
|
|
8399
|
+
}
|
|
8400
|
+
function definedOnly(layer) {
|
|
8401
|
+
return Object.fromEntries(
|
|
8402
|
+
Object.entries(layer).filter(([, value]) => value !== void 0)
|
|
8403
|
+
);
|
|
8404
|
+
}
|
|
8405
|
+
|
|
8406
|
+
// packages/engine/src/lib/einvoice/check.ts
|
|
8407
|
+
var REQUIRED = {
|
|
8408
|
+
number: ["BR-02", "BT-1"],
|
|
8409
|
+
issue_date: ["BR-03", "BT-2"],
|
|
8410
|
+
currency: ["BR-05", "BT-5"],
|
|
8411
|
+
seller: ["BR-06", "BG-4"],
|
|
8412
|
+
"seller.name": ["BR-06", "BT-27"],
|
|
8413
|
+
"seller.address": ["BR-08", "BG-5"],
|
|
8414
|
+
"seller.address.country": ["BR-09", "BT-40"],
|
|
8415
|
+
buyer: ["BR-07", "BG-7"],
|
|
8416
|
+
"buyer.name": ["BR-07", "BT-44"],
|
|
8417
|
+
"buyer.address": ["BR-10", "BG-8"],
|
|
8418
|
+
"buyer.address.country": ["BR-11", "BT-55"],
|
|
8419
|
+
lines: ["BR-16", "BG-25"],
|
|
8420
|
+
"lines[].id": ["BR-21", "BT-126"],
|
|
8421
|
+
"lines[].quantity": ["BR-22", "BT-129"],
|
|
8422
|
+
"lines[].net_amount": ["BR-24", "BT-131"],
|
|
8423
|
+
"lines[].name": ["BR-25", "BT-153"],
|
|
8424
|
+
"lines[].net_price": ["BR-26", "BT-146"],
|
|
8425
|
+
"lines[].tax": ["BR-CO-04", "BT-151"],
|
|
8426
|
+
"lines[].tax.category": ["BR-CO-04", "BT-151"],
|
|
8427
|
+
tax: ["BR-CO-18", "BG-23"],
|
|
8428
|
+
"tax.breakdown": ["BR-CO-18", "BG-23"],
|
|
8429
|
+
"tax.breakdown[].basis": ["BR-45", "BT-116"],
|
|
8430
|
+
"tax.breakdown[].amount": ["BR-46", "BT-117"],
|
|
8431
|
+
"tax.breakdown[].category": ["BR-47", "BT-118"],
|
|
8432
|
+
totals: ["BR-12", "BG-22"],
|
|
8433
|
+
"totals.line_net": ["BR-12", "BT-106"],
|
|
8434
|
+
"totals.tax_basis": ["BR-13", "BT-109"],
|
|
8435
|
+
"totals.tax_total": ["BR-CO-14", "BT-110"],
|
|
8436
|
+
"totals.grand": ["BR-14", "BT-112"],
|
|
8437
|
+
"totals.due": ["BR-15", "BT-115"],
|
|
8438
|
+
"allowances[].amount": ["BR-31", "BT-92"],
|
|
8439
|
+
"allowances[].tax": ["BR-32", "BT-95"],
|
|
8440
|
+
"allowances[].tax.category": ["BR-32", "BT-95"],
|
|
8441
|
+
"charges[].amount": ["BR-36", "BT-99"],
|
|
8442
|
+
"charges[].tax": ["BR-37", "BT-102"],
|
|
8443
|
+
"charges[].tax.category": ["BR-37", "BT-102"],
|
|
8444
|
+
"lines[].allowances[].amount": ["BR-41", "BT-136"],
|
|
8445
|
+
"lines[].charges[].amount": ["BR-43", "BT-141"],
|
|
8446
|
+
"delivery.address.country": ["BR-57", "BT-80"],
|
|
8447
|
+
"preceding_invoices[].number": ["BR-55", "BT-25"]
|
|
8448
|
+
};
|
|
8449
|
+
var RULE_PREFIX = {
|
|
8450
|
+
S: "BR-S",
|
|
8451
|
+
Z: "BR-Z",
|
|
8452
|
+
E: "BR-E",
|
|
8453
|
+
AE: "BR-AE",
|
|
8454
|
+
K: "BR-IC",
|
|
8455
|
+
G: "BR-G",
|
|
8456
|
+
O: "BR-O"
|
|
8457
|
+
};
|
|
8458
|
+
var UNIT_SUGGESTIONS = {
|
|
8459
|
+
piece: "C62",
|
|
8460
|
+
pieces: "C62",
|
|
8461
|
+
pcs: "C62",
|
|
8462
|
+
pc: "C62",
|
|
8463
|
+
stk: "C62",
|
|
8464
|
+
st\u00FCck: "C62",
|
|
8465
|
+
unit: "C62",
|
|
8466
|
+
units: "C62",
|
|
8467
|
+
each: "C62",
|
|
8468
|
+
hour: "HUR",
|
|
8469
|
+
hours: "HUR",
|
|
8470
|
+
h: "HUR",
|
|
8471
|
+
std: "HUR",
|
|
8472
|
+
stunde: "HUR",
|
|
8473
|
+
stunden: "HUR",
|
|
8474
|
+
day: "DAY",
|
|
8475
|
+
days: "DAY",
|
|
8476
|
+
tag: "DAY",
|
|
8477
|
+
tage: "DAY",
|
|
8478
|
+
month: "MON",
|
|
8479
|
+
months: "MON",
|
|
8480
|
+
monat: "MON",
|
|
8481
|
+
year: "ANN",
|
|
8482
|
+
min: "MIN",
|
|
8483
|
+
minute: "MIN",
|
|
8484
|
+
minutes: "MIN",
|
|
8485
|
+
kg: "KGM",
|
|
8486
|
+
g: "GRM",
|
|
8487
|
+
t: "TNE",
|
|
8488
|
+
l: "LTR",
|
|
8489
|
+
litre: "LTR",
|
|
8490
|
+
liter: "LTR",
|
|
8491
|
+
m: "MTR",
|
|
8492
|
+
km: "KMT",
|
|
8493
|
+
m2: "MTK",
|
|
8494
|
+
qm: "MTK",
|
|
8495
|
+
m3: "MTQ",
|
|
8496
|
+
kwh: "KWH",
|
|
8497
|
+
flat: "LS",
|
|
8498
|
+
pauschal: "LS"
|
|
8499
|
+
};
|
|
8500
|
+
var FRENCH_FRAMEWORKS = /* @__PURE__ */ new Set([
|
|
8501
|
+
"B1",
|
|
8502
|
+
"S1",
|
|
8503
|
+
"M1",
|
|
8504
|
+
"B2",
|
|
8505
|
+
"S2",
|
|
8506
|
+
"M2",
|
|
8507
|
+
"B4",
|
|
8508
|
+
"S4",
|
|
8509
|
+
"M4",
|
|
8510
|
+
"S5",
|
|
8511
|
+
"S6",
|
|
8512
|
+
"B7",
|
|
8513
|
+
"S7"
|
|
8514
|
+
]);
|
|
8515
|
+
var FRENCH_OPERATION = { goods: "B1", services: "S1", mixed: "M1" };
|
|
8516
|
+
var CREDIT_TRANSFER = /* @__PURE__ */ new Set(["30", "58"]);
|
|
8517
|
+
function checkInvoice(data, options = {}) {
|
|
8518
|
+
const problems = [];
|
|
8519
|
+
const add2 = (code, path, message, extra = {}) => {
|
|
8520
|
+
problems.push({
|
|
8521
|
+
code,
|
|
8522
|
+
path,
|
|
8523
|
+
...extra.rule ? { rule: extra.rule } : {},
|
|
8524
|
+
message: extra.rule ? `${message} (${extra.rule})` : message,
|
|
8525
|
+
args: {
|
|
8526
|
+
path,
|
|
8527
|
+
...extra.rule ? { rule: extra.rule } : {},
|
|
8528
|
+
...extra.args
|
|
8529
|
+
}
|
|
8530
|
+
});
|
|
8531
|
+
};
|
|
8532
|
+
const parsed = invoiceSchema.safeParse(data);
|
|
8533
|
+
if (!parsed.success) {
|
|
8534
|
+
for (const issue of parsed.error.issues) {
|
|
8535
|
+
const path = pathText(issue.path);
|
|
8536
|
+
const required = REQUIRED[path.replace(/\[\d+\]/g, "[]")];
|
|
8537
|
+
const absent = valueAt(data, issue.path) === void 0;
|
|
8538
|
+
if (absent && required)
|
|
8539
|
+
add2("missing", path, `_invoice.${path} is missing (${required[1]})`, {
|
|
8540
|
+
rule: required[0],
|
|
8541
|
+
args: { term: required[1] }
|
|
8542
|
+
});
|
|
8543
|
+
else if (absent) add2("missing", path, `_invoice.${path} is missing`);
|
|
8544
|
+
else if (issue.code === "too_small" && path === "lines")
|
|
8545
|
+
add2(
|
|
8546
|
+
"missing",
|
|
8547
|
+
path,
|
|
8548
|
+
"_invoice.lines is empty: an invoice has at least one line (BG-25)",
|
|
8549
|
+
{
|
|
8550
|
+
rule: "BR-16",
|
|
8551
|
+
args: { term: "BG-25" }
|
|
8552
|
+
}
|
|
8553
|
+
);
|
|
8554
|
+
else if (issue.code === "too_small" && path === "tax.breakdown")
|
|
8555
|
+
add2(
|
|
8556
|
+
"missing",
|
|
8557
|
+
path,
|
|
8558
|
+
"_invoice.tax.breakdown is empty: an invoice has at least one VAT breakdown (BG-23)",
|
|
8559
|
+
{
|
|
8560
|
+
rule: "BR-CO-18",
|
|
8561
|
+
args: { term: "BG-23" }
|
|
8562
|
+
}
|
|
8563
|
+
);
|
|
8564
|
+
else
|
|
8565
|
+
add2("invalid", path, `_invoice.${path}: ${issue.message}`, {
|
|
8566
|
+
args: { detail: issue.message }
|
|
8567
|
+
});
|
|
8568
|
+
}
|
|
8569
|
+
return { ok: false, invoice: null, problems };
|
|
8570
|
+
}
|
|
8571
|
+
const invoice = normalise(parsed.data, add2, options);
|
|
8572
|
+
if (problems.length > 0) return { ok: false, invoice: null, problems };
|
|
8573
|
+
rules(invoice, add2);
|
|
8574
|
+
return problems.length > 0 ? { ok: false, invoice: null, problems } : { ok: true, invoice, problems: [] };
|
|
8575
|
+
}
|
|
8576
|
+
function pathText(path) {
|
|
8577
|
+
let out = "";
|
|
8578
|
+
for (const key of path)
|
|
8579
|
+
out += typeof key === "number" ? `[${key}]` : out ? `.${String(key)}` : String(key);
|
|
8580
|
+
return out;
|
|
8581
|
+
}
|
|
8582
|
+
function valueAt(data, path) {
|
|
8583
|
+
let value = data;
|
|
8584
|
+
for (const key of path) {
|
|
8585
|
+
if (value === null || typeof value !== "object") return void 0;
|
|
8586
|
+
value = value[key];
|
|
8587
|
+
}
|
|
8588
|
+
return value === null ? void 0 : value;
|
|
8589
|
+
}
|
|
8590
|
+
function normalise(input, add2, options) {
|
|
8591
|
+
const amount2 = (value, path) => {
|
|
8592
|
+
const text4 = decimalText(value);
|
|
8593
|
+
if (text4 === null) {
|
|
8594
|
+
add2("not_a_number", path, `_invoice.${path} is not a number`);
|
|
8595
|
+
return "0";
|
|
8596
|
+
}
|
|
8597
|
+
if (decimalPlaces(text4) > 2) {
|
|
8598
|
+
add2(
|
|
8599
|
+
"decimals",
|
|
8600
|
+
path,
|
|
8601
|
+
`_invoice.${path} has more than 2 decimals; an amount of the invoice is exact to the cent`,
|
|
8602
|
+
{
|
|
8603
|
+
args: { max: 2, value: text4 }
|
|
8604
|
+
}
|
|
8605
|
+
);
|
|
8606
|
+
return "0";
|
|
8607
|
+
}
|
|
8608
|
+
return text4;
|
|
8609
|
+
};
|
|
8610
|
+
const number = (value, path, max2) => {
|
|
8611
|
+
const text4 = decimalText(value);
|
|
8612
|
+
if (text4 === null) {
|
|
8613
|
+
add2("not_a_number", path, `_invoice.${path} is not a number`);
|
|
8614
|
+
return "0";
|
|
8615
|
+
}
|
|
8616
|
+
if (decimalPlaces(text4) > max2) {
|
|
8617
|
+
add2("decimals", path, `_invoice.${path} has more than ${max2} decimals`, {
|
|
8618
|
+
args: { max: max2, value: text4 }
|
|
8619
|
+
});
|
|
8620
|
+
return "0";
|
|
8621
|
+
}
|
|
8622
|
+
return text4;
|
|
8623
|
+
};
|
|
8624
|
+
const optionalAmount = (value, path) => value === void 0 ? void 0 : amount2(value, path);
|
|
8625
|
+
const date2 = (value, path) => {
|
|
8626
|
+
if (value === void 0) return void 0;
|
|
8627
|
+
const [year = 0, month = 0, day = 0] = value.split("-").map(Number);
|
|
8628
|
+
const real = new Date(Date.UTC(year, month - 1, day));
|
|
8629
|
+
if (real.getUTCFullYear() !== year || real.getUTCMonth() !== month - 1 || real.getUTCDate() !== day) {
|
|
8630
|
+
add2("date", path, `_invoice.${path} is not a date of the calendar`, {
|
|
8631
|
+
args: { value }
|
|
8632
|
+
});
|
|
8633
|
+
}
|
|
8634
|
+
return value;
|
|
8635
|
+
};
|
|
8636
|
+
const code = (value, path, list3, name, rule2) => {
|
|
8637
|
+
const upper = value.trim().toUpperCase();
|
|
8638
|
+
if (!list3.has(upper))
|
|
8639
|
+
add2(
|
|
8640
|
+
"code_list",
|
|
8641
|
+
path,
|
|
8642
|
+
`_invoice.${path}: "${value}" is not a code of ${name}`,
|
|
8643
|
+
{
|
|
8644
|
+
rule: rule2,
|
|
8645
|
+
args: { value, list: name }
|
|
8646
|
+
}
|
|
8647
|
+
);
|
|
8648
|
+
return upper;
|
|
8649
|
+
};
|
|
8650
|
+
const period3 = (value, path, rule2) => {
|
|
8651
|
+
if (!value || value.start === void 0 && value.end === void 0)
|
|
8652
|
+
return void 0;
|
|
8653
|
+
const start = date2(value.start, `${path}.start`);
|
|
8654
|
+
const end = date2(value.end, `${path}.end`);
|
|
8655
|
+
if (start && end && end < start)
|
|
8656
|
+
add2("date_order", path, `_invoice.${path} ends before it starts`, {
|
|
8657
|
+
rule: rule2
|
|
8658
|
+
});
|
|
8659
|
+
return { ...start ? { start } : {}, ...end ? { end } : {} };
|
|
8660
|
+
};
|
|
8661
|
+
const identifier4 = (value) => {
|
|
8662
|
+
if (value === void 0) return void 0;
|
|
8663
|
+
if (typeof value === "string") return { value };
|
|
8664
|
+
return {
|
|
8665
|
+
value: value.value,
|
|
8666
|
+
...value.scheme ? { scheme: value.scheme } : {}
|
|
8667
|
+
};
|
|
8668
|
+
};
|
|
8669
|
+
const address3 = (value, path) => ({
|
|
8670
|
+
...defined({
|
|
8671
|
+
street: value.street,
|
|
8672
|
+
street2: value.street2,
|
|
8673
|
+
street3: value.street3,
|
|
8674
|
+
postcode: value.postcode,
|
|
8675
|
+
city: value.city,
|
|
8676
|
+
subdivision: value.subdivision
|
|
8677
|
+
}),
|
|
8678
|
+
country: code(
|
|
8679
|
+
value.country,
|
|
8680
|
+
`${path}.country`,
|
|
8681
|
+
countryCodes,
|
|
8682
|
+
"ISO 3166-1 (two letters, as in DE)",
|
|
8683
|
+
"BR-CL-14"
|
|
8684
|
+
)
|
|
8685
|
+
});
|
|
8686
|
+
const vatId = (value, path) => {
|
|
8687
|
+
if (value === void 0) return void 0;
|
|
8688
|
+
const id = value.replace(/\s/g, "").toUpperCase();
|
|
8689
|
+
const prefix = id.slice(0, 2);
|
|
8690
|
+
if (!(countryCodes.has(prefix) || prefix === "EL") || !/^[A-Z]{2}/.test(id))
|
|
8691
|
+
add2(
|
|
8692
|
+
"vat_id_prefix",
|
|
8693
|
+
path,
|
|
8694
|
+
`_invoice.${path} must start with the country code of the VAT ID, as in DE123456789`,
|
|
8695
|
+
{
|
|
8696
|
+
rule: "BR-CO-09",
|
|
8697
|
+
args: { value }
|
|
8698
|
+
}
|
|
8699
|
+
);
|
|
8700
|
+
return id;
|
|
8701
|
+
};
|
|
8702
|
+
const electronicAddress = (value, path, rule2) => {
|
|
8703
|
+
const id = identifier4(value);
|
|
8704
|
+
if (!id) return void 0;
|
|
8705
|
+
const scheme = id.scheme?.trim().toUpperCase() ?? (/^[^@\s]+@[^@\s]+$/.test(id.value) ? "EM" : void 0);
|
|
8706
|
+
if (!scheme) {
|
|
8707
|
+
add2(
|
|
8708
|
+
"scheme_required",
|
|
8709
|
+
path,
|
|
8710
|
+
`_invoice.${path} needs its scheme: write { "value": \u2026, "scheme": \u2026 } with a code of the EAS list, or an e-mail address`,
|
|
8711
|
+
{ rule: rule2 }
|
|
8712
|
+
);
|
|
8713
|
+
return void 0;
|
|
8714
|
+
}
|
|
8715
|
+
if (!electronicAddressSchemes.has(scheme))
|
|
8716
|
+
add2(
|
|
8717
|
+
"code_list",
|
|
8718
|
+
`${path}.scheme`,
|
|
8719
|
+
`_invoice.${path}.scheme: "${scheme}" is not a code of the EAS list (EM is an e-mail address)`,
|
|
8720
|
+
{
|
|
8721
|
+
rule: "BR-CL-25",
|
|
8722
|
+
args: { value: scheme, list: "the EAS list" }
|
|
8723
|
+
}
|
|
8724
|
+
);
|
|
8725
|
+
return { value: id.value, scheme };
|
|
8726
|
+
};
|
|
8727
|
+
const party3 = (value, path, addressRule) => {
|
|
8728
|
+
const id = identifier4(value.id);
|
|
8729
|
+
const registration = identifier4(value.legal_registration);
|
|
8730
|
+
const electronic = electronicAddress(
|
|
8731
|
+
value.electronic_address,
|
|
8732
|
+
`${path}.electronic_address`,
|
|
8733
|
+
addressRule
|
|
8734
|
+
);
|
|
8735
|
+
const vat = vatId(value.vat_id, `${path}.vat_id`);
|
|
8736
|
+
return {
|
|
8737
|
+
name: value.name,
|
|
8738
|
+
...defined({ trading_name: value.trading_name, vat_id: vat }),
|
|
8739
|
+
...id ? { id } : {},
|
|
8740
|
+
...registration ? { legal_registration: registration } : {},
|
|
8741
|
+
address: address3(value.address, `${path}.address`),
|
|
8742
|
+
...value.contact && Object.values(value.contact).some((v) => v !== void 0) ? { contact: defined(value.contact) } : {},
|
|
8743
|
+
...electronic ? { electronic_address: electronic } : {}
|
|
8744
|
+
};
|
|
8745
|
+
};
|
|
8746
|
+
const tax = (value, path) => ({
|
|
8747
|
+
category: value.category,
|
|
8748
|
+
...value.rate === void 0 || value.rate === null ? {} : { rate: number(value.rate, `${path}.rate`, 4) }
|
|
8749
|
+
});
|
|
8750
|
+
const allowance = (value, path) => ({
|
|
8751
|
+
amount: amount2(value.amount, `${path}.amount`),
|
|
8752
|
+
...defined({
|
|
8753
|
+
reason: value.reason,
|
|
8754
|
+
reason_code: value.reason_code?.trim().toUpperCase(),
|
|
8755
|
+
base_amount: optionalAmount(value.base_amount, `${path}.base_amount`),
|
|
8756
|
+
percent: value.percent === void 0 ? void 0 : number(value.percent, `${path}.percent`, 4)
|
|
8757
|
+
})
|
|
8758
|
+
});
|
|
8759
|
+
const seller = party3(input.seller, "seller", "BR-62");
|
|
8760
|
+
const buyer = party3(input.buyer, "buyer", "BR-63");
|
|
8761
|
+
if (input.buyer.siren !== void 0) {
|
|
8762
|
+
const siren = input.buyer.siren.replace(/\s/g, "");
|
|
8763
|
+
if (buyer.legal_registration && buyer.legal_registration.value.replace(/\s/g, "") !== siren)
|
|
8764
|
+
add2(
|
|
8765
|
+
"siren_mismatch",
|
|
8766
|
+
"buyer.siren",
|
|
8767
|
+
"_invoice.buyer.siren and _invoice.buyer.legal_registration name different registrations; state one of them"
|
|
8768
|
+
);
|
|
8769
|
+
else
|
|
8770
|
+
buyer.legal_registration = {
|
|
8771
|
+
value: siren,
|
|
8772
|
+
scheme: buyer.legal_registration?.scheme ?? "0002"
|
|
8773
|
+
};
|
|
8774
|
+
}
|
|
8775
|
+
const notes = [
|
|
8776
|
+
...input.note ? [{ text: input.note }] : [],
|
|
8777
|
+
...(input.notes ?? []).map((note2) => ({
|
|
8778
|
+
text: note2.text,
|
|
8779
|
+
...note2.subject_code ? { subject_code: note2.subject_code.trim().toUpperCase() } : {}
|
|
8780
|
+
}))
|
|
8781
|
+
];
|
|
8782
|
+
const delivery = input.delivery ? defined({
|
|
8783
|
+
name: input.delivery.name,
|
|
8784
|
+
date: date2(input.delivery.date, "delivery.date"),
|
|
8785
|
+
address: input.delivery.address ? address3(input.delivery.address, "delivery.address") : void 0
|
|
8786
|
+
}) : void 0;
|
|
8787
|
+
let businessProcess;
|
|
8788
|
+
if (input.operation_code !== void 0)
|
|
8789
|
+
businessProcess = input.operation_code.trim().toUpperCase();
|
|
8790
|
+
else if (input.operation !== void 0)
|
|
8791
|
+
businessProcess = FRENCH_OPERATION[input.operation];
|
|
8792
|
+
const payment2 = input.payment ? defined({
|
|
8793
|
+
means_code: input.payment.means_code === void 0 ? void 0 : code(
|
|
8794
|
+
String(input.payment.means_code),
|
|
8795
|
+
"payment.means_code",
|
|
8796
|
+
paymentMeansCodes,
|
|
8797
|
+
"UNTDID 4461 (58 is a SEPA credit transfer)",
|
|
8798
|
+
"BR-CL-16"
|
|
8799
|
+
),
|
|
8800
|
+
iban: iban(input.payment.iban, "payment.iban", add2),
|
|
8801
|
+
bic: input.payment.bic?.replace(/\s/g, "").toUpperCase(),
|
|
8802
|
+
account_name: input.payment.account_name,
|
|
8803
|
+
reference: input.payment.reference,
|
|
8804
|
+
terms: input.payment.terms,
|
|
8805
|
+
due_date: date2(input.payment.due_date, "payment.due_date"),
|
|
8806
|
+
mandate_id: input.payment.mandate_id,
|
|
8807
|
+
creditor_id: input.payment.creditor_id,
|
|
8808
|
+
debited_iban: iban(
|
|
8809
|
+
input.payment.debited_iban,
|
|
8810
|
+
"payment.debited_iban",
|
|
8811
|
+
add2
|
|
8812
|
+
)
|
|
8813
|
+
}) : void 0;
|
|
8814
|
+
const rounding = optionalAmount(input.totals.rounding, "totals.rounding");
|
|
8815
|
+
if (options.profile === "basic" && rounding !== void 0 && toUnits(rounding, 2) !== 0n)
|
|
8816
|
+
add2(
|
|
8817
|
+
"profile",
|
|
8818
|
+
"totals.rounding",
|
|
8819
|
+
"_invoice.totals.rounding cannot be carried by the profile basic, which has no rounding amount (BT-114); use en16931",
|
|
8820
|
+
{
|
|
8821
|
+
args: { profile: "basic", term: "BT-114" }
|
|
8822
|
+
}
|
|
8823
|
+
);
|
|
8824
|
+
return {
|
|
8825
|
+
number: input.number,
|
|
8826
|
+
issue_date: date2(input.issue_date, "issue_date") ?? input.issue_date,
|
|
8827
|
+
type_code: code(
|
|
8828
|
+
String(input.type_code),
|
|
8829
|
+
"type_code",
|
|
8830
|
+
documentTypeCodes,
|
|
8831
|
+
"UNTDID 1001 (380 is an invoice, 381 a credit note)",
|
|
8832
|
+
"BR-CL-01"
|
|
8833
|
+
),
|
|
8834
|
+
currency: code(
|
|
8835
|
+
input.currency,
|
|
8836
|
+
"currency",
|
|
8837
|
+
currencyCodes,
|
|
8838
|
+
"ISO 4217 (three letters, as in EUR)",
|
|
8839
|
+
"BR-CL-04"
|
|
8840
|
+
),
|
|
8841
|
+
...defined({
|
|
8842
|
+
accounting_currency: input.accounting_currency === void 0 ? void 0 : code(
|
|
8843
|
+
input.accounting_currency,
|
|
8844
|
+
"accounting_currency",
|
|
8845
|
+
currencyCodes,
|
|
8846
|
+
"ISO 4217 (three letters, as in EUR)",
|
|
8847
|
+
"BR-CL-05"
|
|
8848
|
+
),
|
|
8849
|
+
buyer_reference: input.buyer_reference,
|
|
8850
|
+
order_reference: input.order_reference,
|
|
8851
|
+
contract_reference: input.contract_reference,
|
|
8852
|
+
period: period3(input.period, "period", "BR-29"),
|
|
8853
|
+
business_process: businessProcess
|
|
8854
|
+
}),
|
|
8855
|
+
notes,
|
|
8856
|
+
preceding_invoices: (input.preceding_invoices ?? []).map(
|
|
8857
|
+
(reference, i) => ({
|
|
8858
|
+
number: reference.number,
|
|
8859
|
+
...defined({
|
|
8860
|
+
issue_date: date2(
|
|
8861
|
+
reference.issue_date,
|
|
8862
|
+
`preceding_invoices[${i}].issue_date`
|
|
8863
|
+
)
|
|
8864
|
+
})
|
|
8865
|
+
})
|
|
8866
|
+
),
|
|
8867
|
+
seller: {
|
|
8868
|
+
...seller,
|
|
8869
|
+
...defined({
|
|
8870
|
+
tax_number: input.seller.tax_number,
|
|
8871
|
+
legal_info: input.seller.legal_info,
|
|
8872
|
+
vat_on_debits: input.seller.vat_on_debits
|
|
8873
|
+
})
|
|
8874
|
+
},
|
|
8875
|
+
buyer,
|
|
8876
|
+
...delivery && Object.keys(delivery).length > 0 ? { delivery } : {},
|
|
8877
|
+
lines: input.lines.map((line2, i) => {
|
|
8878
|
+
const path = `lines[${i}]`;
|
|
8879
|
+
const unit = line2.unit_code.trim();
|
|
8880
|
+
const known = unitCodes.has(unit.toUpperCase()) || unitCodes.has(unit);
|
|
8881
|
+
if (!known) {
|
|
8882
|
+
const suggestion = UNIT_SUGGESTIONS[unit.toLowerCase()];
|
|
8883
|
+
add2(
|
|
8884
|
+
"code_list",
|
|
8885
|
+
`${path}.unit_code`,
|
|
8886
|
+
`_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)"}`,
|
|
8887
|
+
{
|
|
8888
|
+
rule: "BR-CL-23",
|
|
8889
|
+
args: {
|
|
8890
|
+
value: unit,
|
|
8891
|
+
list: "UN/ECE Recommendation 20",
|
|
8892
|
+
...suggestion ? { suggestion } : {}
|
|
8893
|
+
}
|
|
8894
|
+
}
|
|
8895
|
+
);
|
|
8896
|
+
}
|
|
8897
|
+
const price = number(line2.net_price, `${path}.net_price`, 6);
|
|
8898
|
+
if (price.startsWith("-"))
|
|
8899
|
+
add2(
|
|
8900
|
+
"negative",
|
|
8901
|
+
`${path}.net_price`,
|
|
8902
|
+
`_invoice.${path}.net_price must not be negative; a credit is a negative quantity`,
|
|
8903
|
+
{ rule: "BR-27" }
|
|
8904
|
+
);
|
|
8905
|
+
const standard = identifier4(line2.standard_item_id);
|
|
8906
|
+
if (standard && !standard.scheme)
|
|
8907
|
+
add2(
|
|
8908
|
+
"scheme_required",
|
|
8909
|
+
`${path}.standard_item_id`,
|
|
8910
|
+
`_invoice.${path}.standard_item_id needs its scheme: write { "value": \u2026, "scheme": \u2026 }, 0160 for a GTIN`,
|
|
8911
|
+
{ rule: "BR-64" }
|
|
8912
|
+
);
|
|
8913
|
+
return {
|
|
8914
|
+
id: String(line2.id),
|
|
8915
|
+
name: line2.name,
|
|
8916
|
+
quantity: number(line2.quantity, `${path}.quantity`, 6),
|
|
8917
|
+
unit_code: unitCodes.has(unit) ? unit : unit.toUpperCase(),
|
|
8918
|
+
net_price: price,
|
|
8919
|
+
net_amount: amount2(line2.net_amount, `${path}.net_amount`),
|
|
8920
|
+
tax: tax(line2.tax, `${path}.tax`),
|
|
8921
|
+
allowances: (line2.allowances ?? []).map(
|
|
8922
|
+
(a, j) => allowance(a, `${path}.allowances[${j}]`)
|
|
8923
|
+
),
|
|
8924
|
+
charges: (line2.charges ?? []).map(
|
|
8925
|
+
(c, j) => allowance(c, `${path}.charges[${j}]`)
|
|
8926
|
+
),
|
|
8927
|
+
...defined({
|
|
8928
|
+
description: line2.description,
|
|
8929
|
+
price_base_quantity: line2.price_base_quantity === void 0 ? void 0 : number(
|
|
8930
|
+
line2.price_base_quantity,
|
|
8931
|
+
`${path}.price_base_quantity`,
|
|
8932
|
+
6
|
|
8933
|
+
),
|
|
8934
|
+
period: period3(line2.period, `${path}.period`, "BR-30"),
|
|
8935
|
+
buyer_accounting_reference: line2.buyer_accounting_reference,
|
|
8936
|
+
note: line2.note,
|
|
8937
|
+
seller_item_id: line2.seller_item_id,
|
|
8938
|
+
buyer_item_id: line2.buyer_item_id,
|
|
8939
|
+
standard_item_id: standard,
|
|
8940
|
+
order_line_reference: line2.order_line_reference
|
|
8941
|
+
})
|
|
8942
|
+
};
|
|
8943
|
+
}),
|
|
8944
|
+
allowances: (input.allowances ?? []).map((a, i) => ({
|
|
8945
|
+
...allowance(a, `allowances[${i}]`),
|
|
8946
|
+
tax: tax(a.tax, `allowances[${i}].tax`)
|
|
8947
|
+
})),
|
|
8948
|
+
charges: (input.charges ?? []).map((c, i) => ({
|
|
8949
|
+
...allowance(c, `charges[${i}]`),
|
|
8950
|
+
tax: tax(c.tax, `charges[${i}].tax`)
|
|
8951
|
+
})),
|
|
8952
|
+
breakdown: input.tax.breakdown.map((row2, i) => ({
|
|
8953
|
+
...tax(row2, `tax.breakdown[${i}]`),
|
|
8954
|
+
basis: amount2(row2.basis, `tax.breakdown[${i}].basis`),
|
|
8955
|
+
amount: amount2(row2.amount, `tax.breakdown[${i}].amount`),
|
|
8956
|
+
...defined({
|
|
8957
|
+
exemption_reason: row2.exemption_reason,
|
|
8958
|
+
exemption_reason_code: row2.exemption_reason_code?.trim()
|
|
8959
|
+
})
|
|
8960
|
+
})),
|
|
8961
|
+
totals: {
|
|
8962
|
+
line_net: amount2(input.totals.line_net, "totals.line_net"),
|
|
8963
|
+
tax_basis: amount2(input.totals.tax_basis, "totals.tax_basis"),
|
|
8964
|
+
tax_total: amount2(input.totals.tax_total, "totals.tax_total"),
|
|
8965
|
+
grand: amount2(input.totals.grand, "totals.grand"),
|
|
8966
|
+
due: amount2(input.totals.due, "totals.due"),
|
|
8967
|
+
...defined({
|
|
8968
|
+
allowances: optionalAmount(
|
|
8969
|
+
input.totals.allowances,
|
|
8970
|
+
"totals.allowances"
|
|
8971
|
+
),
|
|
8972
|
+
charges: optionalAmount(input.totals.charges, "totals.charges"),
|
|
8973
|
+
prepaid: optionalAmount(input.totals.prepaid, "totals.prepaid"),
|
|
8974
|
+
tax_total_accounting: optionalAmount(
|
|
8975
|
+
input.totals.tax_total_accounting,
|
|
8976
|
+
"totals.tax_total_accounting"
|
|
8977
|
+
),
|
|
8978
|
+
rounding
|
|
8979
|
+
})
|
|
8980
|
+
},
|
|
8981
|
+
...payment2 && Object.keys(payment2).length > 0 ? { payment: payment2 } : {}
|
|
8982
|
+
};
|
|
8983
|
+
}
|
|
8984
|
+
function iban(value, path, add2) {
|
|
8985
|
+
if (value === void 0) return void 0;
|
|
8986
|
+
const normalised = normaliseIban(value);
|
|
8987
|
+
if (!/^[A-Z]{2}[0-9]{2}[A-Z0-9]{11,30}$/.test(normalised) || !ibanChecksum(normalised))
|
|
8988
|
+
add2(
|
|
8989
|
+
"iban",
|
|
8990
|
+
path,
|
|
8991
|
+
`_invoice.${path} is not a valid IBAN: its check digits do not match`
|
|
8992
|
+
);
|
|
8993
|
+
return normalised;
|
|
8994
|
+
}
|
|
8995
|
+
function defined(value) {
|
|
8996
|
+
return Object.fromEntries(
|
|
8997
|
+
Object.entries(value).filter(([, v]) => v !== void 0)
|
|
8998
|
+
);
|
|
8999
|
+
}
|
|
9000
|
+
var cents = (text4) => text4 === void 0 ? 0n : toUnits(text4, 2);
|
|
9001
|
+
var money = (value) => fromUnits(value, 2);
|
|
9002
|
+
var rateKey = (tax) => `${tax.category}|${tax.rate ?? ""}`;
|
|
9003
|
+
function rules(invoice, add2) {
|
|
9004
|
+
const { totals: totals2 } = invoice;
|
|
9005
|
+
const sum = (path, stated, expected, rule2, formula) => {
|
|
9006
|
+
if (stated !== expected)
|
|
9007
|
+
add2(
|
|
9008
|
+
"sum",
|
|
9009
|
+
path,
|
|
9010
|
+
`_invoice.${path} is ${money(stated)}, but ${formula} ${money(expected)}`,
|
|
9011
|
+
{
|
|
9012
|
+
rule: rule2,
|
|
9013
|
+
args: { value: money(stated), expected: money(expected) }
|
|
9014
|
+
}
|
|
9015
|
+
);
|
|
9016
|
+
};
|
|
9017
|
+
const lineNet = invoice.lines.reduce(
|
|
9018
|
+
(total, line2) => total + cents(line2.net_amount),
|
|
9019
|
+
0n
|
|
9020
|
+
);
|
|
9021
|
+
const allowanceSum = invoice.allowances.reduce(
|
|
9022
|
+
(total, a) => total + cents(a.amount),
|
|
9023
|
+
0n
|
|
9024
|
+
);
|
|
9025
|
+
const chargeSum = invoice.charges.reduce(
|
|
9026
|
+
(total, c) => total + cents(c.amount),
|
|
9027
|
+
0n
|
|
9028
|
+
);
|
|
9029
|
+
const taxSum = invoice.breakdown.reduce(
|
|
9030
|
+
(total, row2) => total + cents(row2.amount),
|
|
9031
|
+
0n
|
|
9032
|
+
);
|
|
9033
|
+
sum(
|
|
9034
|
+
"totals.line_net",
|
|
9035
|
+
cents(totals2.line_net),
|
|
9036
|
+
lineNet,
|
|
9037
|
+
"BR-CO-10",
|
|
9038
|
+
"the net amounts of the lines add up to"
|
|
9039
|
+
);
|
|
9040
|
+
sum(
|
|
9041
|
+
"totals.allowances",
|
|
9042
|
+
cents(totals2.allowances),
|
|
9043
|
+
allowanceSum,
|
|
9044
|
+
"BR-CO-11",
|
|
9045
|
+
"the allowances of the document add up to"
|
|
9046
|
+
);
|
|
9047
|
+
sum(
|
|
9048
|
+
"totals.charges",
|
|
9049
|
+
cents(totals2.charges),
|
|
9050
|
+
chargeSum,
|
|
9051
|
+
"BR-CO-12",
|
|
9052
|
+
"the charges of the document add up to"
|
|
9053
|
+
);
|
|
9054
|
+
sum(
|
|
9055
|
+
"totals.tax_basis",
|
|
9056
|
+
cents(totals2.tax_basis),
|
|
9057
|
+
cents(totals2.line_net) - cents(totals2.allowances) + cents(totals2.charges),
|
|
9058
|
+
"BR-CO-13",
|
|
9059
|
+
"line_net less allowances plus charges is"
|
|
9060
|
+
);
|
|
9061
|
+
sum(
|
|
9062
|
+
"totals.tax_total",
|
|
9063
|
+
cents(totals2.tax_total),
|
|
9064
|
+
taxSum,
|
|
9065
|
+
"BR-CO-14",
|
|
9066
|
+
"the VAT amounts of the breakdown add up to"
|
|
9067
|
+
);
|
|
9068
|
+
sum(
|
|
9069
|
+
"totals.grand",
|
|
9070
|
+
cents(totals2.grand),
|
|
9071
|
+
cents(totals2.tax_basis) + cents(totals2.tax_total),
|
|
9072
|
+
"BR-CO-15",
|
|
9073
|
+
"tax_basis plus tax_total is"
|
|
9074
|
+
);
|
|
9075
|
+
sum(
|
|
9076
|
+
"totals.due",
|
|
9077
|
+
cents(totals2.due),
|
|
9078
|
+
cents(totals2.grand) - cents(totals2.prepaid) + cents(totals2.rounding),
|
|
9079
|
+
"BR-CO-16",
|
|
9080
|
+
"grand less prepaid plus rounding is"
|
|
9081
|
+
);
|
|
9082
|
+
if (invoice.accounting_currency !== void 0 && totals2.tax_total_accounting === void 0)
|
|
9083
|
+
add2(
|
|
9084
|
+
"missing",
|
|
9085
|
+
"totals.tax_total_accounting",
|
|
9086
|
+
`_invoice.totals.tax_total_accounting is missing: with accounting_currency ${invoice.accounting_currency} the invoice states its VAT total in that currency (BT-111)`,
|
|
9087
|
+
{
|
|
9088
|
+
rule: "BR-53",
|
|
9089
|
+
args: { term: "BT-111" }
|
|
9090
|
+
}
|
|
9091
|
+
);
|
|
9092
|
+
if (invoice.accounting_currency === void 0 && totals2.tax_total_accounting !== void 0)
|
|
9093
|
+
add2(
|
|
9094
|
+
"missing",
|
|
9095
|
+
"accounting_currency",
|
|
9096
|
+
"_invoice.accounting_currency is missing: totals.tax_total_accounting needs the currency it is stated in (BT-6)",
|
|
9097
|
+
{
|
|
9098
|
+
rule: "BR-53",
|
|
9099
|
+
args: { term: "BT-6" }
|
|
9100
|
+
}
|
|
9101
|
+
);
|
|
9102
|
+
const used = /* @__PURE__ */ new Map();
|
|
9103
|
+
const use = (tax, value, path) => {
|
|
9104
|
+
const entry = used.get(rateKey(tax)) ?? {
|
|
9105
|
+
tax,
|
|
9106
|
+
basis: 0n,
|
|
9107
|
+
items: 0,
|
|
9108
|
+
first: path
|
|
9109
|
+
};
|
|
9110
|
+
entry.basis += value;
|
|
9111
|
+
entry.items += 1;
|
|
9112
|
+
used.set(rateKey(tax), entry);
|
|
9113
|
+
};
|
|
9114
|
+
invoice.lines.forEach(
|
|
9115
|
+
(line2, i) => use(line2.tax, cents(line2.net_amount), `lines[${i}]`)
|
|
9116
|
+
);
|
|
9117
|
+
invoice.allowances.forEach(
|
|
9118
|
+
(a, i) => use(a.tax, -cents(a.amount), `allowances[${i}]`)
|
|
9119
|
+
);
|
|
9120
|
+
invoice.charges.forEach(
|
|
9121
|
+
(c, i) => use(c.tax, cents(c.amount), `charges[${i}]`)
|
|
9122
|
+
);
|
|
9123
|
+
const seen = /* @__PURE__ */ new Set();
|
|
9124
|
+
invoice.breakdown.forEach((row2, i) => {
|
|
9125
|
+
const path = `tax.breakdown[${i}]`;
|
|
9126
|
+
const prefix = RULE_PREFIX[row2.category];
|
|
9127
|
+
const shown = row2.rate === void 0 ? row2.category : `${row2.category} at ${row2.rate} %`;
|
|
9128
|
+
if (seen.has(rateKey(row2)))
|
|
9129
|
+
add2(
|
|
9130
|
+
"breakdown_duplicate",
|
|
9131
|
+
path,
|
|
9132
|
+
`_invoice.tax.breakdown lists category ${shown} twice; one entry per category and rate`,
|
|
9133
|
+
{
|
|
9134
|
+
args: { category: row2.category, rate: row2.rate ?? "" }
|
|
9135
|
+
}
|
|
9136
|
+
);
|
|
9137
|
+
seen.add(rateKey(row2));
|
|
9138
|
+
const entry = used.get(rateKey(row2));
|
|
9139
|
+
const expected = entry?.basis ?? 0n;
|
|
9140
|
+
if (cents(row2.basis) !== expected)
|
|
9141
|
+
add2(
|
|
9142
|
+
"sum",
|
|
9143
|
+
`${path}.basis`,
|
|
9144
|
+
`_invoice.${path}.basis is ${money(cents(row2.basis))}, but the lines, charges and allowances of category ${shown} come to ${money(expected)}`,
|
|
9145
|
+
{
|
|
9146
|
+
rule: `${prefix}-08`,
|
|
9147
|
+
args: {
|
|
9148
|
+
value: money(cents(row2.basis)),
|
|
9149
|
+
expected: money(expected),
|
|
9150
|
+
category: row2.category,
|
|
9151
|
+
rate: row2.rate ?? ""
|
|
9152
|
+
}
|
|
9153
|
+
}
|
|
9154
|
+
);
|
|
9155
|
+
if (row2.rate !== void 0) {
|
|
9156
|
+
const computed = divideRounded(
|
|
9157
|
+
cents(row2.basis) * toUnits(row2.rate, 4),
|
|
9158
|
+
1000000n
|
|
9159
|
+
);
|
|
9160
|
+
const items = BigInt(Math.max(1, entry?.items ?? 1));
|
|
9161
|
+
const tolerance = (items + 1n) / 2n > 100n ? 100n : (items + 1n) / 2n;
|
|
9162
|
+
if (abs(cents(row2.amount) - computed) > tolerance)
|
|
9163
|
+
add2(
|
|
9164
|
+
"sum",
|
|
9165
|
+
`${path}.amount`,
|
|
9166
|
+
`_invoice.${path}.amount is ${money(cents(row2.amount))}, but ${row2.rate} % of ${money(cents(row2.basis))} is ${money(computed)}`,
|
|
9167
|
+
{
|
|
9168
|
+
rule: "BR-CO-17",
|
|
9169
|
+
args: {
|
|
9170
|
+
value: money(cents(row2.amount)),
|
|
9171
|
+
expected: money(computed),
|
|
9172
|
+
rate: row2.rate,
|
|
9173
|
+
basis: money(cents(row2.basis))
|
|
9174
|
+
}
|
|
9175
|
+
}
|
|
9176
|
+
);
|
|
9177
|
+
}
|
|
9178
|
+
});
|
|
9179
|
+
for (const [key, entry] of used) {
|
|
9180
|
+
if (seen.has(key)) continue;
|
|
9181
|
+
const shown = entry.tax.rate === void 0 ? entry.tax.category : `${entry.tax.category} at ${entry.tax.rate} %`;
|
|
9182
|
+
add2(
|
|
9183
|
+
"breakdown_missing",
|
|
9184
|
+
"tax.breakdown",
|
|
9185
|
+
`_invoice.tax.breakdown has no entry for category ${shown}, which _invoice.${entry.first} falls under`,
|
|
9186
|
+
{
|
|
9187
|
+
rule: `${RULE_PREFIX[entry.tax.category]}-01`,
|
|
9188
|
+
args: {
|
|
9189
|
+
category: entry.tax.category,
|
|
9190
|
+
rate: entry.tax.rate ?? "",
|
|
9191
|
+
used: entry.first
|
|
9192
|
+
}
|
|
9193
|
+
}
|
|
9194
|
+
);
|
|
9195
|
+
}
|
|
9196
|
+
const rate = (tax, path, at) => {
|
|
9197
|
+
const prefix = RULE_PREFIX[tax.category];
|
|
9198
|
+
const number = at === "line" || at === "breakdown" ? "05" : at === "allowance" ? "06" : "07";
|
|
9199
|
+
if (tax.category === "O") {
|
|
9200
|
+
if (tax.rate !== void 0)
|
|
9201
|
+
add2(
|
|
9202
|
+
"rate_forbidden",
|
|
9203
|
+
`${path}.rate`,
|
|
9204
|
+
`_invoice.${path}.rate must be left out: category O is not subject to VAT and has no rate`,
|
|
9205
|
+
{ rule: `${prefix}-${number}` }
|
|
9206
|
+
);
|
|
9207
|
+
return;
|
|
9208
|
+
}
|
|
9209
|
+
if (tax.rate === void 0) {
|
|
9210
|
+
add2(
|
|
9211
|
+
"rate_required",
|
|
9212
|
+
`${path}.rate`,
|
|
9213
|
+
`_invoice.${path}.rate is missing: category ${tax.category} states its rate${tax.category === "S" ? "" : ", which is 0"}`,
|
|
9214
|
+
{
|
|
9215
|
+
rule: at === "breakdown" ? "BR-48" : `${prefix}-${number}`,
|
|
9216
|
+
args: { category: tax.category }
|
|
9217
|
+
}
|
|
9218
|
+
);
|
|
9219
|
+
return;
|
|
9220
|
+
}
|
|
9221
|
+
const value = toUnits(tax.rate, 4);
|
|
9222
|
+
if (tax.category === "S" && value <= 0n)
|
|
9223
|
+
add2(
|
|
9224
|
+
"rate_positive",
|
|
9225
|
+
`${path}.rate`,
|
|
9226
|
+
`_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`,
|
|
9227
|
+
{
|
|
9228
|
+
rule: `${prefix}-${number}`,
|
|
9229
|
+
args: { rate: tax.rate }
|
|
9230
|
+
}
|
|
9231
|
+
);
|
|
9232
|
+
if (tax.category !== "S" && value !== 0n)
|
|
9233
|
+
add2(
|
|
9234
|
+
"rate_zero",
|
|
9235
|
+
`${path}.rate`,
|
|
9236
|
+
`_invoice.${path}.rate is ${tax.rate}: category ${tax.category} carries a rate of 0`,
|
|
9237
|
+
{
|
|
9238
|
+
rule: `${prefix}-${number}`,
|
|
9239
|
+
args: { rate: tax.rate, category: tax.category }
|
|
9240
|
+
}
|
|
9241
|
+
);
|
|
9242
|
+
};
|
|
9243
|
+
invoice.lines.forEach((line2, i) => rate(line2.tax, `lines[${i}].tax`, "line"));
|
|
9244
|
+
invoice.allowances.forEach(
|
|
9245
|
+
(a, i) => rate(a.tax, `allowances[${i}].tax`, "allowance")
|
|
9246
|
+
);
|
|
9247
|
+
invoice.charges.forEach((c, i) => rate(c.tax, `charges[${i}].tax`, "charge"));
|
|
9248
|
+
const categories = new Set(
|
|
9249
|
+
[...used.values()].map((entry) => entry.tax.category)
|
|
9250
|
+
);
|
|
9251
|
+
invoice.breakdown.forEach((row2, i) => {
|
|
9252
|
+
const path = `tax.breakdown[${i}]`;
|
|
9253
|
+
const prefix = RULE_PREFIX[row2.category];
|
|
9254
|
+
rate(row2, path, "breakdown");
|
|
9255
|
+
categories.add(row2.category);
|
|
9256
|
+
const reason = row2.exemption_reason !== void 0 || row2.exemption_reason_code !== void 0;
|
|
9257
|
+
if (row2.category === "S" || row2.category === "Z") {
|
|
9258
|
+
if (reason)
|
|
9259
|
+
add2(
|
|
9260
|
+
"exemption_reason_forbidden",
|
|
9261
|
+
`${path}.exemption_reason`,
|
|
9262
|
+
`_invoice.${path} must not state an exemption reason: category ${row2.category} is not an exemption`,
|
|
9263
|
+
{
|
|
9264
|
+
rule: `${prefix}-10`,
|
|
9265
|
+
args: { category: row2.category }
|
|
9266
|
+
}
|
|
9267
|
+
);
|
|
9268
|
+
} else if (!reason) {
|
|
9269
|
+
add2(
|
|
9270
|
+
"exemption_reason_required",
|
|
9271
|
+
`${path}.exemption_reason`,
|
|
9272
|
+
`_invoice.${path}.exemption_reason is missing: category ${row2.category} says why no VAT is charged, as text or as exemption_reason_code`,
|
|
9273
|
+
{
|
|
9274
|
+
rule: `${prefix}-10`,
|
|
9275
|
+
args: { category: row2.category }
|
|
9276
|
+
}
|
|
9277
|
+
);
|
|
9278
|
+
}
|
|
9279
|
+
if (row2.category !== "S" && cents(row2.amount) !== 0n)
|
|
9280
|
+
add2(
|
|
9281
|
+
"amount_zero",
|
|
9282
|
+
`${path}.amount`,
|
|
9283
|
+
`_invoice.${path}.amount is ${money(cents(row2.amount))}: category ${row2.category} carries no VAT, so the amount is 0`,
|
|
9284
|
+
{
|
|
9285
|
+
rule: `${prefix}-09`,
|
|
9286
|
+
args: { value: money(cents(row2.amount)), category: row2.category }
|
|
9287
|
+
}
|
|
9288
|
+
);
|
|
9289
|
+
});
|
|
9290
|
+
const sellerTaxId = invoice.seller.vat_id !== void 0 || invoice.seller.tax_number !== void 0;
|
|
9291
|
+
for (const category of categories) {
|
|
9292
|
+
const prefix = RULE_PREFIX[category];
|
|
9293
|
+
if (category === "O") {
|
|
9294
|
+
if (invoice.seller.vat_id !== void 0)
|
|
9295
|
+
add2(
|
|
9296
|
+
"vat_id_forbidden",
|
|
9297
|
+
"seller.vat_id",
|
|
9298
|
+
"_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",
|
|
9299
|
+
{ rule: "BR-O-02" }
|
|
9300
|
+
);
|
|
9301
|
+
if (invoice.buyer.vat_id !== void 0)
|
|
9302
|
+
add2(
|
|
9303
|
+
"vat_id_forbidden",
|
|
9304
|
+
"buyer.vat_id",
|
|
9305
|
+
"_invoice.buyer.vat_id must be left out: an invoice of category O is not subject to VAT",
|
|
9306
|
+
{ rule: "BR-O-02" }
|
|
9307
|
+
);
|
|
9308
|
+
if (categories.size > 1)
|
|
9309
|
+
add2(
|
|
9310
|
+
"only_category",
|
|
9311
|
+
"tax.breakdown",
|
|
9312
|
+
"_invoice mixes category O with others: an invoice that is not subject to VAT has that one category only",
|
|
9313
|
+
{ rule: "BR-O-11" }
|
|
9314
|
+
);
|
|
9315
|
+
continue;
|
|
9316
|
+
}
|
|
9317
|
+
if (category === "K" || category === "G") {
|
|
9318
|
+
if (invoice.seller.vat_id === void 0)
|
|
9319
|
+
add2(
|
|
9320
|
+
"seller_tax_id_required",
|
|
9321
|
+
"seller.vat_id",
|
|
9322
|
+
`_invoice.seller.vat_id is missing: category ${category} names the seller's VAT ID`,
|
|
9323
|
+
{
|
|
9324
|
+
rule: `${prefix}-02`,
|
|
9325
|
+
args: { category }
|
|
9326
|
+
}
|
|
9327
|
+
);
|
|
9328
|
+
} else if (!sellerTaxId) {
|
|
9329
|
+
add2(
|
|
9330
|
+
"seller_tax_id_required",
|
|
9331
|
+
"seller.vat_id",
|
|
9332
|
+
`_invoice.seller.vat_id is missing: category ${category} names the seller's VAT ID, or tax_number where there is none`,
|
|
9333
|
+
{
|
|
9334
|
+
rule: `${prefix}-02`,
|
|
9335
|
+
args: { category }
|
|
9336
|
+
}
|
|
9337
|
+
);
|
|
9338
|
+
}
|
|
9339
|
+
if (category === "AE" && invoice.buyer.vat_id === void 0 && invoice.buyer.legal_registration === void 0)
|
|
9340
|
+
add2(
|
|
9341
|
+
"buyer_tax_id_required",
|
|
9342
|
+
"buyer.vat_id",
|
|
9343
|
+
"_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",
|
|
9344
|
+
{
|
|
9345
|
+
rule: "BR-AE-02",
|
|
9346
|
+
args: { category }
|
|
9347
|
+
}
|
|
9348
|
+
);
|
|
9349
|
+
if (category === "K") {
|
|
9350
|
+
if (invoice.buyer.vat_id === void 0)
|
|
9351
|
+
add2(
|
|
9352
|
+
"buyer_tax_id_required",
|
|
9353
|
+
"buyer.vat_id",
|
|
9354
|
+
"_invoice.buyer.vat_id is missing: an intra-community supply names the buyer's VAT ID",
|
|
9355
|
+
{
|
|
9356
|
+
rule: "BR-IC-02",
|
|
9357
|
+
args: { category }
|
|
9358
|
+
}
|
|
9359
|
+
);
|
|
9360
|
+
if (invoice.delivery?.date === void 0 && invoice.period === void 0)
|
|
9361
|
+
add2(
|
|
9362
|
+
"delivery_required",
|
|
9363
|
+
"delivery.date",
|
|
9364
|
+
"_invoice.delivery.date is missing: an intra-community supply states when it was delivered, or the invoicing period",
|
|
9365
|
+
{ rule: "BR-IC-11" }
|
|
9366
|
+
);
|
|
9367
|
+
if (invoice.delivery?.address === void 0)
|
|
9368
|
+
add2(
|
|
9369
|
+
"delivery_required",
|
|
9370
|
+
"delivery.address.country",
|
|
9371
|
+
"_invoice.delivery.address.country is missing: an intra-community supply states the country it was delivered to",
|
|
9372
|
+
{ rule: "BR-IC-12" }
|
|
9373
|
+
);
|
|
9374
|
+
}
|
|
9375
|
+
}
|
|
9376
|
+
if (invoice.seller.id === void 0 && invoice.seller.legal_registration === void 0 && invoice.seller.vat_id === void 0)
|
|
9377
|
+
add2(
|
|
9378
|
+
"seller_identifier_required",
|
|
9379
|
+
"seller.vat_id",
|
|
9380
|
+
"_invoice.seller needs an identifier the buyer can match: vat_id, legal_registration or id",
|
|
9381
|
+
{ rule: "BR-CO-26" }
|
|
9382
|
+
);
|
|
9383
|
+
const payment2 = invoice.payment;
|
|
9384
|
+
const account = payment2?.iban !== void 0 || payment2?.bic !== void 0 || payment2?.account_name !== void 0;
|
|
9385
|
+
if (payment2 && payment2.means_code === void 0 && (account || payment2.mandate_id !== void 0 || payment2.debited_iban !== void 0))
|
|
9386
|
+
add2(
|
|
9387
|
+
"means_code_required",
|
|
9388
|
+
"payment.means_code",
|
|
9389
|
+
"_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",
|
|
9390
|
+
{ rule: "BR-49" }
|
|
9391
|
+
);
|
|
9392
|
+
if (payment2?.means_code !== void 0 && CREDIT_TRANSFER.has(payment2.means_code) && payment2.iban === void 0)
|
|
9393
|
+
add2(
|
|
9394
|
+
"account_required",
|
|
9395
|
+
"payment.iban",
|
|
9396
|
+
`_invoice.payment.iban is missing: a payment by credit transfer (code ${payment2.means_code}) names the account`,
|
|
9397
|
+
{
|
|
9398
|
+
rule: "BR-61",
|
|
9399
|
+
args: { means: payment2.means_code }
|
|
9400
|
+
}
|
|
9401
|
+
);
|
|
9402
|
+
if (cents(totals2.due) > 0n && payment2?.due_date === void 0 && payment2?.terms === void 0)
|
|
9403
|
+
add2(
|
|
9404
|
+
"due_or_terms_required",
|
|
9405
|
+
"payment.due_date",
|
|
9406
|
+
"_invoice.payment.due_date is missing: an invoice with an amount due states when it is due, or its payment terms",
|
|
9407
|
+
{ rule: "BR-CO-25" }
|
|
9408
|
+
);
|
|
9409
|
+
if (invoice.seller.address.country === "FR" && invoice.buyer.address.country === "FR") {
|
|
9410
|
+
const digits = (id) => (id?.value ?? "").replace(/\s/g, "");
|
|
9411
|
+
if (!/^\d{9}$/.test(digits(invoice.seller.legal_registration)))
|
|
9412
|
+
add2(
|
|
9413
|
+
"fr_seller_siren",
|
|
9414
|
+
"seller.legal_registration",
|
|
9415
|
+
"_invoice.seller.legal_registration is missing or not nine digits: an invoice between French businesses names the seller's SIREN (BT-30)",
|
|
9416
|
+
{ rule: "BR-FR-10" }
|
|
9417
|
+
);
|
|
9418
|
+
if (!/^\d{9}$/.test(digits(invoice.buyer.legal_registration)))
|
|
9419
|
+
add2(
|
|
9420
|
+
"fr_buyer_siren",
|
|
9421
|
+
"buyer.siren",
|
|
9422
|
+
"_invoice.buyer.siren is missing or not nine digits: an invoice between French businesses names the buyer's SIREN (BT-47)",
|
|
9423
|
+
{ rule: "BR-FR-11" }
|
|
9424
|
+
);
|
|
9425
|
+
if (invoice.business_process === void 0)
|
|
9426
|
+
add2(
|
|
9427
|
+
"fr_operation",
|
|
9428
|
+
"operation",
|
|
9429
|
+
"_invoice.operation is missing: an invoice between French businesses says whether it is for goods, services or mixed (BT-23)",
|
|
9430
|
+
{ rule: "BR-FR-08" }
|
|
9431
|
+
);
|
|
9432
|
+
else if (!FRENCH_FRAMEWORKS.has(invoice.business_process))
|
|
9433
|
+
add2(
|
|
9434
|
+
"code_list",
|
|
9435
|
+
"operation_code",
|
|
9436
|
+
`_invoice.operation_code: "${invoice.business_process}" is not a billing framework of the French specifications (B1, S1, M1 and their variants)`,
|
|
9437
|
+
{
|
|
9438
|
+
rule: "BR-FR-08",
|
|
9439
|
+
args: {
|
|
9440
|
+
value: invoice.business_process,
|
|
9441
|
+
list: "the French billing frameworks"
|
|
9442
|
+
}
|
|
9443
|
+
}
|
|
9444
|
+
);
|
|
9445
|
+
if (invoice.seller.vat_on_debits === void 0)
|
|
9446
|
+
add2(
|
|
9447
|
+
"fr_vat_on_debits",
|
|
9448
|
+
"seller.vat_on_debits",
|
|
9449
|
+
"_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)"
|
|
9450
|
+
);
|
|
9451
|
+
}
|
|
9452
|
+
}
|
|
9453
|
+
|
|
9454
|
+
// packages/engine/src/lib/einvoice/cii.ts
|
|
9455
|
+
var CII_GUIDELINES = {
|
|
9456
|
+
basic: "urn:cen.eu:en16931:2017#compliant#urn:factur-x.eu:1p0:basic",
|
|
9457
|
+
en16931: "urn:cen.eu:en16931:2017"
|
|
9458
|
+
};
|
|
9459
|
+
var EINVOICE_XML_NAME = "factur-x.xml";
|
|
9460
|
+
function leaf(name, text4, attributes) {
|
|
9461
|
+
if (text4 === void 0 || text4 === "") return void 0;
|
|
9462
|
+
const kept = Object.entries(attributes ?? {}).filter(
|
|
9463
|
+
(entry) => entry[1] !== void 0
|
|
9464
|
+
);
|
|
9465
|
+
return {
|
|
9466
|
+
name,
|
|
9467
|
+
text: text4,
|
|
9468
|
+
...kept.length > 0 ? { attributes: Object.fromEntries(kept) } : {}
|
|
9469
|
+
};
|
|
9470
|
+
}
|
|
9471
|
+
function group2(name, children) {
|
|
9472
|
+
const kept = children.filter((child2) => !!child2);
|
|
9473
|
+
return kept.length > 0 ? { name, children: kept } : void 0;
|
|
9474
|
+
}
|
|
9475
|
+
var date = (name, value) => value === void 0 ? void 0 : group2(name, [
|
|
9476
|
+
leaf("udt:DateTimeString", value.replace(/-/g, ""), { format: "102" })
|
|
9477
|
+
]);
|
|
9478
|
+
var amount = (name, value, attributes) => value === void 0 ? void 0 : leaf(name, withPlaces(value, 2), attributes);
|
|
9479
|
+
var identifier3 = (plain, withScheme, id) => id === void 0 ? void 0 : id.scheme ? leaf(withScheme, id.value, { schemeID: id.scheme }) : leaf(plain, id.value);
|
|
9480
|
+
function address2(value) {
|
|
9481
|
+
if (!value) return void 0;
|
|
9482
|
+
return group2("ram:PostalTradeAddress", [
|
|
9483
|
+
leaf("ram:PostcodeCode", value.postcode),
|
|
9484
|
+
leaf("ram:LineOne", value.street),
|
|
9485
|
+
leaf("ram:LineTwo", value.street2),
|
|
9486
|
+
leaf("ram:LineThree", value.street3),
|
|
9487
|
+
leaf("ram:CityName", value.city),
|
|
9488
|
+
leaf("ram:CountryID", value.country),
|
|
9489
|
+
leaf("ram:CountrySubDivisionName", value.subdivision)
|
|
9490
|
+
]);
|
|
9491
|
+
}
|
|
9492
|
+
function party2(name, value, full) {
|
|
9493
|
+
return group2(name, [
|
|
9494
|
+
identifier3("ram:ID", "ram:GlobalID", value.id),
|
|
9495
|
+
leaf("ram:Name", value.name),
|
|
9496
|
+
full ? leaf("ram:Description", value.legal_info) : void 0,
|
|
9497
|
+
group2("ram:SpecifiedLegalOrganization", [
|
|
9498
|
+
value.legal_registration ? leaf("ram:ID", value.legal_registration.value, {
|
|
9499
|
+
schemeID: value.legal_registration.scheme
|
|
9500
|
+
}) : void 0,
|
|
9501
|
+
leaf("ram:TradingBusinessName", value.trading_name)
|
|
9502
|
+
]),
|
|
9503
|
+
full && value.contact ? group2("ram:DefinedTradeContact", [
|
|
9504
|
+
leaf("ram:PersonName", value.contact.name),
|
|
9505
|
+
group2("ram:TelephoneUniversalCommunication", [
|
|
9506
|
+
leaf("ram:CompleteNumber", value.contact.phone)
|
|
9507
|
+
]),
|
|
9508
|
+
group2("ram:EmailURIUniversalCommunication", [
|
|
9509
|
+
leaf("ram:URIID", value.contact.email)
|
|
9510
|
+
])
|
|
9511
|
+
]) : void 0,
|
|
9512
|
+
address2(value.address),
|
|
9513
|
+
value.electronic_address ? group2("ram:URIUniversalCommunication", [
|
|
9514
|
+
leaf("ram:URIID", value.electronic_address.value, {
|
|
9515
|
+
schemeID: value.electronic_address.scheme
|
|
9516
|
+
})
|
|
9517
|
+
]) : void 0,
|
|
9518
|
+
group2("ram:SpecifiedTaxRegistration", [
|
|
9519
|
+
leaf("ram:ID", value.vat_id, { schemeID: "VA" })
|
|
9520
|
+
]),
|
|
9521
|
+
group2("ram:SpecifiedTaxRegistration", [
|
|
9522
|
+
leaf("ram:ID", value.tax_number, { schemeID: "FC" })
|
|
9523
|
+
])
|
|
9524
|
+
]);
|
|
9525
|
+
}
|
|
9526
|
+
var taxOf = (tax) => [
|
|
9527
|
+
leaf("ram:TypeCode", "VAT"),
|
|
9528
|
+
leaf("ram:CategoryCode", tax.category),
|
|
9529
|
+
leaf("ram:RateApplicablePercent", tax.rate)
|
|
9530
|
+
];
|
|
9531
|
+
function allowanceOrCharge2(value, charge) {
|
|
9532
|
+
return group2("ram:SpecifiedTradeAllowanceCharge", [
|
|
9533
|
+
group2("ram:ChargeIndicator", [
|
|
9534
|
+
leaf("udt:Indicator", charge ? "true" : "false")
|
|
9535
|
+
]),
|
|
9536
|
+
leaf("ram:CalculationPercent", value.percent),
|
|
9537
|
+
amount("ram:BasisAmount", value.base_amount),
|
|
9538
|
+
amount("ram:ActualAmount", value.amount),
|
|
9539
|
+
leaf("ram:ReasonCode", value.reason_code),
|
|
9540
|
+
leaf("ram:Reason", value.reason),
|
|
9541
|
+
value.tax ? group2("ram:CategoryTradeTax", taxOf(value.tax)) : void 0
|
|
9542
|
+
]);
|
|
9543
|
+
}
|
|
9544
|
+
var period2 = (value) => value === void 0 ? void 0 : group2("ram:BillingSpecifiedPeriod", [
|
|
9545
|
+
date("ram:StartDateTime", value.start),
|
|
9546
|
+
date("ram:EndDateTime", value.end)
|
|
9547
|
+
]);
|
|
9548
|
+
function invoiceToCii(invoice, options) {
|
|
9549
|
+
const full = options.profile === "en16931";
|
|
9550
|
+
const { totals: totals2, payment: payment2 } = invoice;
|
|
9551
|
+
const lines = invoice.lines.map(
|
|
9552
|
+
(line2) => group2("ram:IncludedSupplyChainTradeLineItem", [
|
|
9553
|
+
group2("ram:AssociatedDocumentLineDocument", [
|
|
9554
|
+
leaf("ram:LineID", line2.id),
|
|
9555
|
+
group2("ram:IncludedNote", [leaf("ram:Content", line2.note)])
|
|
9556
|
+
]),
|
|
9557
|
+
group2("ram:SpecifiedTradeProduct", [
|
|
9558
|
+
line2.standard_item_id ? leaf("ram:GlobalID", line2.standard_item_id.value, {
|
|
9559
|
+
schemeID: line2.standard_item_id.scheme
|
|
9560
|
+
}) : void 0,
|
|
9561
|
+
full ? leaf("ram:SellerAssignedID", line2.seller_item_id) : void 0,
|
|
9562
|
+
full ? leaf("ram:BuyerAssignedID", line2.buyer_item_id) : void 0,
|
|
9563
|
+
leaf("ram:Name", line2.name),
|
|
9564
|
+
full ? leaf("ram:Description", line2.description) : void 0
|
|
9565
|
+
]),
|
|
9566
|
+
group2("ram:SpecifiedLineTradeAgreement", [
|
|
9567
|
+
full ? group2("ram:BuyerOrderReferencedDocument", [
|
|
9568
|
+
leaf("ram:LineID", line2.order_line_reference)
|
|
9569
|
+
]) : void 0,
|
|
9570
|
+
group2("ram:NetPriceProductTradePrice", [
|
|
9571
|
+
leaf("ram:ChargeAmount", withPlaces(line2.net_price, 2)),
|
|
9572
|
+
leaf("ram:BasisQuantity", line2.price_base_quantity, {
|
|
9573
|
+
unitCode: line2.unit_code
|
|
9574
|
+
})
|
|
9575
|
+
])
|
|
9576
|
+
]),
|
|
9577
|
+
group2("ram:SpecifiedLineTradeDelivery", [
|
|
9578
|
+
leaf("ram:BilledQuantity", line2.quantity, { unitCode: line2.unit_code })
|
|
9579
|
+
]),
|
|
9580
|
+
group2("ram:SpecifiedLineTradeSettlement", [
|
|
9581
|
+
group2("ram:ApplicableTradeTax", taxOf(line2.tax)),
|
|
9582
|
+
period2(line2.period),
|
|
9583
|
+
...line2.allowances.map((a) => allowanceOrCharge2(a, false)),
|
|
9584
|
+
...line2.charges.map((c) => allowanceOrCharge2(c, true)),
|
|
9585
|
+
group2("ram:SpecifiedTradeSettlementLineMonetarySummation", [
|
|
9586
|
+
amount("ram:LineTotalAmount", line2.net_amount)
|
|
9587
|
+
]),
|
|
9588
|
+
full ? group2("ram:ReceivableSpecifiedTradeAccountingAccount", [
|
|
9589
|
+
leaf("ram:ID", line2.buyer_accounting_reference)
|
|
9590
|
+
]) : void 0
|
|
9591
|
+
])
|
|
9592
|
+
])
|
|
9593
|
+
);
|
|
9594
|
+
const agreement = group2("ram:ApplicableHeaderTradeAgreement", [
|
|
9595
|
+
leaf("ram:BuyerReference", invoice.buyer_reference),
|
|
9596
|
+
party2("ram:SellerTradeParty", invoice.seller, full),
|
|
9597
|
+
party2("ram:BuyerTradeParty", invoice.buyer, full),
|
|
9598
|
+
group2("ram:BuyerOrderReferencedDocument", [
|
|
9599
|
+
leaf("ram:IssuerAssignedID", invoice.order_reference)
|
|
9600
|
+
]),
|
|
9601
|
+
group2("ram:ContractReferencedDocument", [
|
|
9602
|
+
leaf("ram:IssuerAssignedID", invoice.contract_reference)
|
|
9603
|
+
])
|
|
9604
|
+
]);
|
|
9605
|
+
const shipTo = invoice.delivery;
|
|
9606
|
+
const delivery = group2("ram:ApplicableHeaderTradeDelivery", [
|
|
9607
|
+
group2("ram:ShipToTradeParty", [
|
|
9608
|
+
leaf("ram:Name", shipTo?.name),
|
|
9609
|
+
address2(shipTo?.address)
|
|
9610
|
+
]),
|
|
9611
|
+
group2("ram:ActualDeliverySupplyChainEvent", [
|
|
9612
|
+
date("ram:OccurrenceDateTime", shipTo?.date)
|
|
9613
|
+
])
|
|
9614
|
+
]) ?? { name: "ram:ApplicableHeaderTradeDelivery" };
|
|
9615
|
+
const settlement = group2("ram:ApplicableHeaderTradeSettlement", [
|
|
9616
|
+
leaf("ram:CreditorReferenceID", payment2?.creditor_id),
|
|
9617
|
+
leaf("ram:PaymentReference", payment2?.reference),
|
|
9618
|
+
leaf("ram:TaxCurrencyCode", invoice.accounting_currency),
|
|
9619
|
+
leaf("ram:InvoiceCurrencyCode", invoice.currency),
|
|
9620
|
+
payment2?.means_code ? group2("ram:SpecifiedTradeSettlementPaymentMeans", [
|
|
9621
|
+
leaf("ram:TypeCode", payment2.means_code),
|
|
9622
|
+
group2("ram:PayerPartyDebtorFinancialAccount", [
|
|
9623
|
+
leaf("ram:IBANID", payment2.debited_iban)
|
|
9624
|
+
]),
|
|
9625
|
+
group2("ram:PayeePartyCreditorFinancialAccount", [
|
|
9626
|
+
leaf("ram:IBANID", payment2.iban),
|
|
9627
|
+
full ? leaf("ram:AccountName", payment2.account_name) : void 0
|
|
9628
|
+
]),
|
|
9629
|
+
full ? group2("ram:PayeeSpecifiedCreditorFinancialInstitution", [
|
|
9630
|
+
leaf("ram:BICID", payment2.bic)
|
|
9631
|
+
]) : void 0
|
|
9632
|
+
]) : void 0,
|
|
9633
|
+
...invoice.breakdown.map(
|
|
9634
|
+
(row2) => group2("ram:ApplicableTradeTax", [
|
|
9635
|
+
amount("ram:CalculatedAmount", row2.amount),
|
|
9636
|
+
leaf("ram:TypeCode", "VAT"),
|
|
9637
|
+
leaf("ram:ExemptionReason", row2.exemption_reason),
|
|
9638
|
+
amount("ram:BasisAmount", row2.basis),
|
|
9639
|
+
leaf("ram:CategoryCode", row2.category),
|
|
9640
|
+
leaf("ram:ExemptionReasonCode", row2.exemption_reason_code),
|
|
9641
|
+
// France: VAT owed on invoicing rather than on payment is the code for "date of the
|
|
9642
|
+
// invoice" (BT-8). Nothing is written for the default, which the specifications leave unsaid.
|
|
9643
|
+
invoice.seller.vat_on_debits ? leaf("ram:DueDateTypeCode", "5") : void 0,
|
|
9644
|
+
leaf("ram:RateApplicablePercent", row2.rate)
|
|
9645
|
+
])
|
|
9646
|
+
),
|
|
9647
|
+
period2(invoice.period),
|
|
9648
|
+
...invoice.allowances.map((a) => allowanceOrCharge2(a, false)),
|
|
9649
|
+
...invoice.charges.map((c) => allowanceOrCharge2(c, true)),
|
|
9650
|
+
group2("ram:SpecifiedTradePaymentTerms", [
|
|
9651
|
+
leaf("ram:Description", payment2?.terms),
|
|
9652
|
+
date("ram:DueDateDateTime", payment2?.due_date),
|
|
9653
|
+
leaf("ram:DirectDebitMandateID", payment2?.mandate_id)
|
|
9654
|
+
]),
|
|
9655
|
+
group2("ram:SpecifiedTradeSettlementHeaderMonetarySummation", [
|
|
9656
|
+
amount("ram:LineTotalAmount", totals2.line_net),
|
|
9657
|
+
amount("ram:ChargeTotalAmount", totals2.charges),
|
|
9658
|
+
amount("ram:AllowanceTotalAmount", totals2.allowances),
|
|
9659
|
+
amount("ram:TaxBasisTotalAmount", totals2.tax_basis),
|
|
9660
|
+
amount("ram:TaxTotalAmount", totals2.tax_total, {
|
|
9661
|
+
currencyID: invoice.currency
|
|
9662
|
+
}),
|
|
9663
|
+
invoice.accounting_currency ? amount("ram:TaxTotalAmount", totals2.tax_total_accounting, {
|
|
9664
|
+
currencyID: invoice.accounting_currency
|
|
9665
|
+
}) : void 0,
|
|
9666
|
+
full ? amount("ram:RoundingAmount", totals2.rounding) : void 0,
|
|
9667
|
+
amount("ram:GrandTotalAmount", totals2.grand),
|
|
9668
|
+
amount("ram:TotalPrepaidAmount", totals2.prepaid),
|
|
9669
|
+
amount("ram:DuePayableAmount", totals2.due)
|
|
9670
|
+
]),
|
|
9671
|
+
...invoice.preceding_invoices.map(
|
|
9672
|
+
(reference) => group2("ram:InvoiceReferencedDocument", [
|
|
9673
|
+
leaf("ram:IssuerAssignedID", reference.number),
|
|
9674
|
+
reference.issue_date ? group2("ram:FormattedIssueDateTime", [
|
|
9675
|
+
leaf(
|
|
9676
|
+
"qdt:DateTimeString",
|
|
9677
|
+
reference.issue_date.replace(/-/g, ""),
|
|
9678
|
+
{ format: "102" }
|
|
9679
|
+
)
|
|
9680
|
+
]) : void 0
|
|
9681
|
+
])
|
|
9682
|
+
)
|
|
9683
|
+
]);
|
|
9684
|
+
const root = {
|
|
9685
|
+
name: "rsm:CrossIndustryInvoice",
|
|
9686
|
+
attributes: {
|
|
9687
|
+
"xmlns:rsm": "urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100",
|
|
9688
|
+
"xmlns:qdt": "urn:un:unece:uncefact:data:standard:QualifiedDataType:100",
|
|
9689
|
+
"xmlns:ram": "urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100",
|
|
9690
|
+
"xmlns:udt": "urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100"
|
|
9691
|
+
},
|
|
9692
|
+
children: [
|
|
9693
|
+
group2("rsm:ExchangedDocumentContext", [
|
|
9694
|
+
group2("ram:BusinessProcessSpecifiedDocumentContextParameter", [
|
|
9695
|
+
leaf("ram:ID", invoice.business_process)
|
|
9696
|
+
]),
|
|
9697
|
+
group2("ram:GuidelineSpecifiedDocumentContextParameter", [
|
|
9698
|
+
leaf("ram:ID", CII_GUIDELINES[options.profile])
|
|
9699
|
+
])
|
|
9700
|
+
]),
|
|
9701
|
+
group2("rsm:ExchangedDocument", [
|
|
9702
|
+
leaf("ram:ID", invoice.number),
|
|
9703
|
+
leaf("ram:TypeCode", invoice.type_code),
|
|
9704
|
+
date("ram:IssueDateTime", invoice.issue_date),
|
|
9705
|
+
...invoice.notes.map(
|
|
9706
|
+
(note2) => group2("ram:IncludedNote", [
|
|
9707
|
+
leaf("ram:Content", note2.text),
|
|
9708
|
+
leaf("ram:SubjectCode", note2.subject_code)
|
|
9709
|
+
])
|
|
9710
|
+
)
|
|
9711
|
+
]),
|
|
9712
|
+
group2("rsm:SupplyChainTradeTransaction", [
|
|
9713
|
+
...lines,
|
|
9714
|
+
agreement,
|
|
9715
|
+
delivery,
|
|
9716
|
+
settlement
|
|
9717
|
+
])
|
|
9718
|
+
].filter((child2) => !!child2)
|
|
9719
|
+
};
|
|
9720
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
9721
|
+
${serialise(root, 0)}`;
|
|
9722
|
+
}
|
|
9723
|
+
var xmlCharacter = (code) => code === 9 || code === 10 || code === 13 || code >= 32 && !(code >= 55296 && code <= 57343) && code !== 65534 && code !== 65535;
|
|
9724
|
+
function carried(text4) {
|
|
9725
|
+
let out = "";
|
|
9726
|
+
for (const character of text4)
|
|
9727
|
+
if (xmlCharacter(character.codePointAt(0) ?? 0)) out += character;
|
|
9728
|
+
return out;
|
|
9729
|
+
}
|
|
9730
|
+
var escapeText2 = (text4) => carried(text4).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
9731
|
+
var escapeAttribute2 = (text4) => escapeText2(text4).replace(/"/g, """);
|
|
9732
|
+
function serialise(element, depth) {
|
|
9733
|
+
const indent = " ".repeat(depth);
|
|
9734
|
+
const attributes = Object.entries(element.attributes ?? {}).map(([name, value]) => ` ${name}="${escapeAttribute2(value)}"`).join("");
|
|
9735
|
+
if (element.children === void 0) {
|
|
9736
|
+
return element.text === void 0 ? `${indent}<${element.name}${attributes}/>
|
|
9737
|
+
` : `${indent}<${element.name}${attributes}>${escapeText2(element.text)}</${element.name}>
|
|
9738
|
+
`;
|
|
9739
|
+
}
|
|
9740
|
+
const children = element.children.map((child2) => serialise(child2, depth + 1)).join("");
|
|
9741
|
+
return `${indent}<${element.name}${attributes}>
|
|
9742
|
+
${children}${indent}</${element.name}>
|
|
9743
|
+
`;
|
|
9744
|
+
}
|
|
9745
|
+
|
|
9746
|
+
// packages/engine/src/lib/einvoice/display.ts
|
|
9747
|
+
var DISPLAY_TERMS = {
|
|
9748
|
+
"BT-1": "invoice number",
|
|
9749
|
+
"BT-109": "net total",
|
|
9750
|
+
"BT-110": "VAT total",
|
|
9751
|
+
"BT-112": "total",
|
|
9752
|
+
"BT-115": "amount due",
|
|
9753
|
+
"BT-117": "VAT amount"
|
|
9754
|
+
};
|
|
9755
|
+
var DIGIT_0 = 48;
|
|
9756
|
+
var DIGIT_9 = 57;
|
|
9757
|
+
var DOT = 46;
|
|
9758
|
+
var COMMA = 44;
|
|
9759
|
+
var SPACES = /* @__PURE__ */ new Set([32, 160, 8239, 8201]);
|
|
9760
|
+
var APOSTROPHES = /* @__PURE__ */ new Set([39, 8217]);
|
|
9761
|
+
var DASHES = /* @__PURE__ */ new Set([45, 8208, 8209, 8210, 8211, 8722]);
|
|
9762
|
+
var INVISIBLE = /* @__PURE__ */ new Set([173, 8203, 8204, 8205, 8288, 65279]);
|
|
9763
|
+
var isDigit = (code) => code >= DIGIT_0 && code <= DIGIT_9;
|
|
9764
|
+
var MAX_GROUPS = 6;
|
|
9765
|
+
function shownAmounts(text4) {
|
|
9766
|
+
const found = /* @__PURE__ */ new Set();
|
|
9767
|
+
let run2 = "";
|
|
9768
|
+
const flush = () => {
|
|
9769
|
+
const trimmed = run2.replace(/[^0-9]+$/, "");
|
|
9770
|
+
run2 = "";
|
|
9771
|
+
if (!trimmed) return;
|
|
9772
|
+
const parts = trimmed.split(" ").map((part) => part.replace(/[.,]+$/, "")).filter((part) => part !== "");
|
|
9773
|
+
for (let start = 0; start < parts.length; start += 1) {
|
|
9774
|
+
for (const cents2 of readings(parts[start] ?? "")) found.add(cents2);
|
|
9775
|
+
const first = parts[start] ?? "";
|
|
9776
|
+
if (!/^\d{1,3}$/.test(first)) continue;
|
|
9777
|
+
let whole = first;
|
|
9778
|
+
for (let end = start + 1; end < parts.length && end - start < MAX_GROUPS; end += 1) {
|
|
9779
|
+
const part = parts[end] ?? "";
|
|
9780
|
+
const last = /^(\d{3})(?:[.,](\d+))?$/.exec(part);
|
|
9781
|
+
if (!last) break;
|
|
9782
|
+
const cents2 = toCents(whole + last[1], last[2] ?? "");
|
|
9783
|
+
if (cents2 !== null) found.add(cents2);
|
|
9784
|
+
if (last[2] !== void 0) break;
|
|
9785
|
+
whole += last[1];
|
|
9786
|
+
}
|
|
9787
|
+
}
|
|
9788
|
+
};
|
|
9789
|
+
for (const character of text4) {
|
|
9790
|
+
const code = character.codePointAt(0) ?? 0;
|
|
9791
|
+
if (INVISIBLE.has(code)) continue;
|
|
9792
|
+
if (isDigit(code)) run2 += character;
|
|
9793
|
+
else if (run2 && (code === DOT || code === COMMA)) run2 += character;
|
|
9794
|
+
else if (run2 && SPACES.has(code)) run2 += " ";
|
|
9795
|
+
else if (run2 && APOSTROPHES.has(code)) continue;
|
|
9796
|
+
else flush();
|
|
9797
|
+
}
|
|
9798
|
+
flush();
|
|
9799
|
+
return found;
|
|
9800
|
+
}
|
|
9801
|
+
function readings(part) {
|
|
9802
|
+
if (/^\d+$/.test(part)) {
|
|
9803
|
+
const cents2 = toCents(part, "");
|
|
9804
|
+
return cents2 === null ? [] : [cents2];
|
|
9805
|
+
}
|
|
9806
|
+
const out = [];
|
|
9807
|
+
for (const [group3, decimal] of [
|
|
9808
|
+
[".", ","],
|
|
9809
|
+
[",", "."]
|
|
9810
|
+
]) {
|
|
9811
|
+
const pieces = part.split(decimal);
|
|
9812
|
+
if (pieces.length > 2) continue;
|
|
9813
|
+
const [whole = "", fraction] = pieces;
|
|
9814
|
+
if (fraction !== void 0 && !/^\d+$/.test(fraction)) continue;
|
|
9815
|
+
const groups = whole.split(group3);
|
|
9816
|
+
const grouped = groups.every(
|
|
9817
|
+
(digits, index) => /^\d+$/.test(digits) && (index === 0 ? groups.length === 1 || digits.length <= 3 : digits.length === 3)
|
|
9818
|
+
);
|
|
9819
|
+
if (!grouped) continue;
|
|
9820
|
+
const cents2 = toCents(groups.join(""), fraction ?? "");
|
|
9821
|
+
if (cents2 !== null) out.push(cents2);
|
|
9822
|
+
}
|
|
9823
|
+
return out;
|
|
9824
|
+
}
|
|
9825
|
+
function toCents(whole, fraction) {
|
|
9826
|
+
if (whole.length > 18 || /[1-9]/.test(fraction.slice(2))) return null;
|
|
9827
|
+
return BigInt(whole) * 100n + BigInt((fraction + "00").slice(0, 2));
|
|
9828
|
+
}
|
|
9829
|
+
function squeeze(text4) {
|
|
9830
|
+
let out = "";
|
|
9831
|
+
for (const character of text4) {
|
|
9832
|
+
const code = character.codePointAt(0) ?? 0;
|
|
9833
|
+
if (INVISIBLE.has(code) || /\s/.test(character) || SPACES.has(code))
|
|
9834
|
+
continue;
|
|
9835
|
+
out += DASHES.has(code) ? "-" : character.toLowerCase();
|
|
9836
|
+
}
|
|
9837
|
+
return out;
|
|
9838
|
+
}
|
|
9839
|
+
function displayCheck(text4, invoice) {
|
|
9840
|
+
const whole = typeof text4 === "string" ? text4 : text4.join("\n");
|
|
9841
|
+
const amounts = shownAmounts(whole);
|
|
9842
|
+
const squeezed = squeeze(whole);
|
|
9843
|
+
const values = [];
|
|
9844
|
+
values.push({
|
|
9845
|
+
term: "BT-1",
|
|
9846
|
+
path: "number",
|
|
9847
|
+
value: invoice.number,
|
|
9848
|
+
shown: squeezed.includes(squeeze(invoice.number))
|
|
9849
|
+
});
|
|
9850
|
+
const amount2 = (term, path, value) => {
|
|
9851
|
+
const cents2 = abs(toUnits(value, 2));
|
|
9852
|
+
if (cents2 === 0n) return;
|
|
9853
|
+
values.push({
|
|
9854
|
+
term,
|
|
9855
|
+
path,
|
|
9856
|
+
// as the XML writes it and a reader expects it: `3760.40`, not `3760.4`
|
|
9857
|
+
value: withPlaces(value, 2),
|
|
9858
|
+
shown: amounts.has(cents2)
|
|
9859
|
+
});
|
|
9860
|
+
};
|
|
9861
|
+
const { totals: totals2 } = invoice;
|
|
9862
|
+
amount2("BT-109", "totals.tax_basis", totals2.tax_basis);
|
|
9863
|
+
amount2("BT-110", "totals.tax_total", totals2.tax_total);
|
|
9864
|
+
amount2("BT-112", "totals.grand", totals2.grand);
|
|
9865
|
+
if (toUnits(totals2.due, 2) !== toUnits(totals2.grand, 2))
|
|
9866
|
+
amount2("BT-115", "totals.due", totals2.due);
|
|
9867
|
+
if (invoice.breakdown.length > 1)
|
|
9868
|
+
invoice.breakdown.forEach(
|
|
9869
|
+
(row2, index) => amount2("BT-117", `tax.breakdown[${index}].amount`, row2.amount)
|
|
9870
|
+
);
|
|
9871
|
+
const unique = (terms) => [...new Set(terms)];
|
|
9872
|
+
return {
|
|
9873
|
+
checked: unique(values.map((value) => value.term)),
|
|
9874
|
+
missing: unique(
|
|
9875
|
+
values.filter((value) => !value.shown).map((value) => value.term)
|
|
9876
|
+
),
|
|
9877
|
+
values
|
|
9878
|
+
};
|
|
9879
|
+
}
|
|
9880
|
+
function displayMissingText(check) {
|
|
9881
|
+
const missing = check.values.filter((value) => !value.shown);
|
|
9882
|
+
if (missing.length === 0) return null;
|
|
9883
|
+
const named = missing.map(
|
|
9884
|
+
(value) => `the ${DISPLAY_TERMS[value.term] ?? value.term} ${value.value} (${value.term})`
|
|
9885
|
+
);
|
|
9886
|
+
const list3 = named.length === 1 ? named[0] : `${named.slice(0, -1).join(", ")} and ${named[named.length - 1]}`;
|
|
9887
|
+
return `The PDF does not show ${list3} of the e-invoice`;
|
|
9888
|
+
}
|
|
9889
|
+
|
|
9890
|
+
// packages/engine/src/lib/einvoice/locate.ts
|
|
9891
|
+
function invoicePathSegments(path) {
|
|
9892
|
+
const segments = [];
|
|
9893
|
+
for (const part of path.split(".")) {
|
|
9894
|
+
if (!part) continue;
|
|
9895
|
+
const match = /^([^[\]]*)((?:\[\d+\])*)$/.exec(part);
|
|
9896
|
+
if (!match) {
|
|
9897
|
+
segments.push(part);
|
|
9898
|
+
continue;
|
|
9899
|
+
}
|
|
9900
|
+
if (match[1]) segments.push(match[1]);
|
|
9901
|
+
for (const index of match[2]?.matchAll(/\[(\d+)\]/g) ?? [])
|
|
9902
|
+
segments.push(Number(index[1]));
|
|
9903
|
+
}
|
|
9904
|
+
return segments;
|
|
9905
|
+
}
|
|
9906
|
+
function locateJsonPath(text4, path) {
|
|
9907
|
+
let offset = skipSpace(text4, 0);
|
|
9908
|
+
if (offset >= text4.length) return null;
|
|
9909
|
+
let best = { offset, depth: 0 };
|
|
9910
|
+
try {
|
|
9911
|
+
for (let depth = 0; depth < path.length; depth += 1) {
|
|
9912
|
+
const segment = path[depth];
|
|
9913
|
+
const found = typeof segment === "number" ? arrayItem(text4, offset, segment) : objectMember(text4, offset, String(segment));
|
|
9914
|
+
if (!found) break;
|
|
9915
|
+
best = { offset: found.at, depth: depth + 1 };
|
|
9916
|
+
offset = found.value;
|
|
9917
|
+
}
|
|
9918
|
+
} catch {
|
|
9919
|
+
}
|
|
9920
|
+
return { ...positionAt(text4, best.offset), depth: best.depth };
|
|
9921
|
+
}
|
|
9922
|
+
function positionAt(text4, offset) {
|
|
9923
|
+
let line2 = 1;
|
|
9924
|
+
let lineStart = 0;
|
|
9925
|
+
for (let i = 0; i < offset; i += 1)
|
|
9926
|
+
if (text4.charCodeAt(i) === 10) {
|
|
9927
|
+
line2 += 1;
|
|
9928
|
+
lineStart = i + 1;
|
|
9929
|
+
}
|
|
9930
|
+
return { line: line2, column: offset - lineStart + 1 };
|
|
9931
|
+
}
|
|
9932
|
+
function skipSpace(text4, from) {
|
|
9933
|
+
let i = from;
|
|
9934
|
+
while (i < text4.length && /\s/.test(text4[i] ?? "")) i += 1;
|
|
9935
|
+
return i;
|
|
9936
|
+
}
|
|
9937
|
+
function stringEnd(text4, from) {
|
|
9938
|
+
if (text4[from] !== '"') throw new Error("string");
|
|
9939
|
+
for (let i = from + 1; i < text4.length; i += 1) {
|
|
9940
|
+
if (text4[i] === "\\") i += 1;
|
|
9941
|
+
else if (text4[i] === '"') return i + 1;
|
|
9942
|
+
}
|
|
9943
|
+
throw new Error("string");
|
|
9944
|
+
}
|
|
9945
|
+
function valueEnd(text4, from) {
|
|
9946
|
+
const start = skipSpace(text4, from);
|
|
9947
|
+
const first = text4[start];
|
|
9948
|
+
if (first === '"') return stringEnd(text4, start);
|
|
9949
|
+
if (first === "{" || first === "[") {
|
|
9950
|
+
const close = first === "{" ? "}" : "]";
|
|
9951
|
+
let i2 = skipSpace(text4, start + 1);
|
|
9952
|
+
if (text4[i2] === close) return i2 + 1;
|
|
9953
|
+
for (; ; ) {
|
|
9954
|
+
if (first === "{") {
|
|
9955
|
+
i2 = skipSpace(text4, stringEnd(text4, skipSpace(text4, i2)));
|
|
9956
|
+
if (text4[i2] !== ":") throw new Error("colon");
|
|
9957
|
+
i2 += 1;
|
|
9958
|
+
}
|
|
9959
|
+
i2 = skipSpace(text4, valueEnd(text4, i2));
|
|
9960
|
+
if (text4[i2] === close) return i2 + 1;
|
|
9961
|
+
if (text4[i2] !== ",") throw new Error("comma");
|
|
9962
|
+
i2 += 1;
|
|
9963
|
+
}
|
|
9964
|
+
}
|
|
9965
|
+
let i = start;
|
|
9966
|
+
while (i < text4.length && !/[\s,\]}]/.test(text4[i] ?? "")) i += 1;
|
|
9967
|
+
if (i === start) throw new Error("value");
|
|
9968
|
+
return i;
|
|
9969
|
+
}
|
|
9970
|
+
function objectMember(text4, from, key) {
|
|
9971
|
+
const start = skipSpace(text4, from);
|
|
9972
|
+
if (text4[start] !== "{") return null;
|
|
9973
|
+
let i = skipSpace(text4, start + 1);
|
|
9974
|
+
while (text4[i] !== "}") {
|
|
9975
|
+
const at = skipSpace(text4, i);
|
|
9976
|
+
const end = stringEnd(text4, at);
|
|
9977
|
+
const colon = skipSpace(text4, end);
|
|
9978
|
+
if (text4[colon] !== ":") throw new Error("colon");
|
|
9979
|
+
const value = skipSpace(text4, colon + 1);
|
|
9980
|
+
if (JSON.parse(text4.slice(at, end)) === key) return { at, value };
|
|
9981
|
+
i = skipSpace(text4, valueEnd(text4, value));
|
|
9982
|
+
if (text4[i] === ",") i = skipSpace(text4, i + 1);
|
|
9983
|
+
else if (text4[i] !== "}") throw new Error("comma");
|
|
9984
|
+
}
|
|
9985
|
+
return null;
|
|
9986
|
+
}
|
|
9987
|
+
function arrayItem(text4, from, index) {
|
|
9988
|
+
const start = skipSpace(text4, from);
|
|
9989
|
+
if (text4[start] !== "[") return null;
|
|
9990
|
+
let i = skipSpace(text4, start + 1);
|
|
9991
|
+
for (let n = 0; text4[i] !== "]"; n += 1) {
|
|
9992
|
+
const at = skipSpace(text4, i);
|
|
9993
|
+
if (n === index) return { at, value: at };
|
|
9994
|
+
i = skipSpace(text4, valueEnd(text4, at));
|
|
9995
|
+
if (text4[i] === ",") i = skipSpace(text4, i + 1);
|
|
9996
|
+
else if (text4[i] !== "]") throw new Error("comma");
|
|
9997
|
+
}
|
|
9998
|
+
return null;
|
|
9999
|
+
}
|
|
10000
|
+
|
|
10001
|
+
// packages/engine/src/lib/einvoice/report.ts
|
|
10002
|
+
var EINVOICE_MAX_MESSAGES = 50;
|
|
10003
|
+
function capMessages(messages, max2 = EINVOICE_MAX_MESSAGES) {
|
|
10004
|
+
const sorted = [
|
|
10005
|
+
...messages.filter((message) => message.severity === "error"),
|
|
10006
|
+
...messages.filter((message) => message.severity !== "error")
|
|
10007
|
+
];
|
|
10008
|
+
return sorted.length > max2 ? { messages: sorted.slice(0, max2), truncated: true } : { messages: sorted };
|
|
10009
|
+
}
|
|
10010
|
+
function einvoiceResult(options, specVersion, validation, display) {
|
|
10011
|
+
return {
|
|
10012
|
+
profile: options.profile,
|
|
10013
|
+
flavour: options.flavour,
|
|
10014
|
+
spec_version: specVersion,
|
|
10015
|
+
validation: validation ? {
|
|
10016
|
+
valid: validation.valid,
|
|
10017
|
+
schematron: validation.schematron,
|
|
10018
|
+
pdfa: validation.pdfa,
|
|
10019
|
+
...capMessages(validation.messages)
|
|
10020
|
+
} : null,
|
|
10021
|
+
display: display ? { checked: display.checked, missing: display.missing } : null
|
|
10022
|
+
};
|
|
10023
|
+
}
|
|
10024
|
+
var EINVOICE_FLAVOUR_NAMES = {
|
|
10025
|
+
"factur-x": "Factur-X",
|
|
10026
|
+
zugferd: "ZUGFeRD"
|
|
10027
|
+
};
|
|
10028
|
+
var EINVOICE_PROFILE_NAMES = {
|
|
10029
|
+
basic: "Basic",
|
|
10030
|
+
en16931: "EN 16931"
|
|
10031
|
+
};
|
|
10032
|
+
function invoiceLineOf(location) {
|
|
10033
|
+
if (!location) return null;
|
|
10034
|
+
const match = /IncludedSupplyChainTradeLineItem\[(\d+)\]/.exec(location);
|
|
10035
|
+
return match ? Number(match[1]) : null;
|
|
10036
|
+
}
|
|
10037
|
+
|
|
10038
|
+
// packages/engine/src/lib/einvoice/html-text.ts
|
|
10039
|
+
var INLINE = /* @__PURE__ */ new Set([
|
|
10040
|
+
"a",
|
|
10041
|
+
"abbr",
|
|
10042
|
+
"b",
|
|
10043
|
+
"bdi",
|
|
10044
|
+
"bdo",
|
|
10045
|
+
"cite",
|
|
10046
|
+
"code",
|
|
10047
|
+
"data",
|
|
10048
|
+
"del",
|
|
10049
|
+
"dfn",
|
|
10050
|
+
"em",
|
|
10051
|
+
"font",
|
|
10052
|
+
"i",
|
|
10053
|
+
"ins",
|
|
10054
|
+
"kbd",
|
|
10055
|
+
"label",
|
|
10056
|
+
"mark",
|
|
10057
|
+
"nobr",
|
|
10058
|
+
"output",
|
|
10059
|
+
"q",
|
|
10060
|
+
"s",
|
|
10061
|
+
"samp",
|
|
10062
|
+
"small",
|
|
10063
|
+
"span",
|
|
10064
|
+
"strong",
|
|
10065
|
+
"sub",
|
|
10066
|
+
"sup",
|
|
10067
|
+
"time",
|
|
10068
|
+
"tt",
|
|
10069
|
+
"u",
|
|
10070
|
+
"var",
|
|
10071
|
+
"wbr"
|
|
10072
|
+
]);
|
|
10073
|
+
var SKIPPED = ["script", "style", "template", "noscript", "head", "title"];
|
|
10074
|
+
var ENTITIES = {
|
|
10075
|
+
amp: 38,
|
|
10076
|
+
lt: 60,
|
|
10077
|
+
gt: 62,
|
|
10078
|
+
quot: 34,
|
|
10079
|
+
apos: 39,
|
|
10080
|
+
nbsp: 160,
|
|
10081
|
+
ensp: 8194,
|
|
10082
|
+
emsp: 8195,
|
|
10083
|
+
thinsp: 8201,
|
|
10084
|
+
shy: 173,
|
|
10085
|
+
minus: 8722,
|
|
10086
|
+
ndash: 8211,
|
|
10087
|
+
mdash: 8212,
|
|
10088
|
+
hyphen: 8208,
|
|
10089
|
+
euro: 8364,
|
|
10090
|
+
pound: 163,
|
|
10091
|
+
yen: 165,
|
|
10092
|
+
cent: 162,
|
|
10093
|
+
sect: 167,
|
|
10094
|
+
middot: 183,
|
|
10095
|
+
bull: 8226,
|
|
10096
|
+
times: 215,
|
|
10097
|
+
auml: 228,
|
|
10098
|
+
ouml: 246,
|
|
10099
|
+
uuml: 252,
|
|
10100
|
+
Auml: 196,
|
|
10101
|
+
Ouml: 214,
|
|
10102
|
+
Uuml: 220,
|
|
10103
|
+
szlig: 223,
|
|
10104
|
+
eacute: 233,
|
|
10105
|
+
egrave: 232,
|
|
10106
|
+
agrave: 224,
|
|
10107
|
+
ccedil: 231
|
|
10108
|
+
};
|
|
10109
|
+
function decodeEntities(text4) {
|
|
10110
|
+
return text4.replace(
|
|
10111
|
+
/&(#x[0-9a-f]+|#\d+|[a-z][a-z0-9]*);/gi,
|
|
10112
|
+
(whole, reference) => {
|
|
10113
|
+
const code = reference.startsWith("#") ? reference[1] === "x" || reference[1] === "X" ? Number.parseInt(reference.slice(2), 16) : Number.parseInt(reference.slice(1), 10) : ENTITIES[reference];
|
|
10114
|
+
return code !== void 0 && Number.isFinite(code) && code > 0 && code <= 1114111 ? String.fromCodePoint(code) : whole;
|
|
10115
|
+
}
|
|
10116
|
+
);
|
|
10117
|
+
}
|
|
10118
|
+
function htmlText(html) {
|
|
10119
|
+
let source = html.replace(/<!--[\s\S]*?-->/g, "");
|
|
10120
|
+
for (const tag2 of SKIPPED)
|
|
10121
|
+
source = source.replace(
|
|
10122
|
+
new RegExp(`<${tag2}\\b[^>]*>[\\s\\S]*?</${tag2}\\s*>`, "gi"),
|
|
10123
|
+
"\n"
|
|
10124
|
+
);
|
|
10125
|
+
let out = "";
|
|
10126
|
+
let position = 0;
|
|
10127
|
+
const tag = /<\/?([a-zA-Z][a-zA-Z0-9-]*)(?:"[^"]*"|'[^']*'|[^'">])*>/g;
|
|
10128
|
+
for (let match = tag.exec(source); match; match = tag.exec(source)) {
|
|
10129
|
+
out += source.slice(position, match.index);
|
|
10130
|
+
position = match.index + match[0].length;
|
|
10131
|
+
const name = (match[1] ?? "").toLowerCase();
|
|
10132
|
+
if (name === "br" || !INLINE.has(name)) out += "\n";
|
|
10133
|
+
}
|
|
10134
|
+
out += source.slice(position);
|
|
10135
|
+
return decodeEntities(out).split("\n").map((line2) => line2.replace(/[ \t\r\f]+/g, " ").trim()).filter((line2) => line2 !== "").join("\n");
|
|
10136
|
+
}
|
|
10137
|
+
|
|
10138
|
+
// packages/engine/src/lib/einvoice/skeleton.ts
|
|
10139
|
+
function invoiceSkeleton(issueDate = "2026-01-15") {
|
|
10140
|
+
const due = /* @__PURE__ */ new Date(`${issueDate}T00:00:00Z`);
|
|
10141
|
+
due.setUTCDate(due.getUTCDate() + 14);
|
|
10142
|
+
const number = `RE-${issueDate.slice(0, 4)}-0001`;
|
|
10143
|
+
return {
|
|
10144
|
+
number,
|
|
10145
|
+
issue_date: issueDate,
|
|
10146
|
+
type_code: "380",
|
|
10147
|
+
currency: "EUR",
|
|
10148
|
+
seller: {
|
|
10149
|
+
name: "Fennlor Studio GmbH",
|
|
10150
|
+
vat_id: "DE000000000",
|
|
10151
|
+
address: {
|
|
10152
|
+
street: "Musterstra\xDFe 1",
|
|
10153
|
+
postcode: "12345",
|
|
10154
|
+
city: "Musterstadt",
|
|
10155
|
+
country: "DE"
|
|
10156
|
+
},
|
|
10157
|
+
contact: {
|
|
10158
|
+
name: "Erika Mustermann",
|
|
10159
|
+
email: "rechnung@fennlor.example",
|
|
10160
|
+
phone: "+49 30 0000000"
|
|
10161
|
+
}
|
|
10162
|
+
},
|
|
10163
|
+
buyer: {
|
|
10164
|
+
name: "Olvarest GmbH",
|
|
10165
|
+
address: {
|
|
10166
|
+
street: "Beispielweg 2",
|
|
10167
|
+
postcode: "54321",
|
|
10168
|
+
city: "Beispielstadt",
|
|
10169
|
+
country: "DE"
|
|
10170
|
+
}
|
|
10171
|
+
},
|
|
10172
|
+
delivery: { date: issueDate },
|
|
10173
|
+
lines: [
|
|
10174
|
+
{
|
|
10175
|
+
id: "1",
|
|
10176
|
+
name: "Consulting",
|
|
10177
|
+
quantity: 8,
|
|
10178
|
+
unit_code: "HUR",
|
|
10179
|
+
net_price: 120,
|
|
10180
|
+
net_amount: 960,
|
|
10181
|
+
tax: { category: "S", rate: 19 }
|
|
10182
|
+
}
|
|
10183
|
+
],
|
|
10184
|
+
tax: {
|
|
10185
|
+
breakdown: [{ category: "S", rate: 19, basis: 960, amount: 182.4 }]
|
|
10186
|
+
},
|
|
10187
|
+
totals: {
|
|
10188
|
+
line_net: 960,
|
|
10189
|
+
tax_basis: 960,
|
|
10190
|
+
tax_total: 182.4,
|
|
10191
|
+
grand: 1142.4,
|
|
10192
|
+
due: 1142.4
|
|
10193
|
+
},
|
|
10194
|
+
payment: {
|
|
10195
|
+
means_code: "58",
|
|
10196
|
+
iban: "DE36000000000000000000",
|
|
10197
|
+
reference: number,
|
|
10198
|
+
terms: "Zahlbar innerhalb von 14 Tagen ohne Abzug",
|
|
10199
|
+
due_date: due.toISOString().slice(0, 10)
|
|
10200
|
+
}
|
|
10201
|
+
};
|
|
10202
|
+
}
|
|
10203
|
+
|
|
10204
|
+
// packages/engine/src/lib/einvoice/index.ts
|
|
10205
|
+
var INVOICE_DATA_KEY = "_invoice";
|
|
10206
|
+
var EINVOICE_SPEC_VERSIONS = {
|
|
10207
|
+
"factur-x": "1.09",
|
|
10208
|
+
zugferd: "2.5"
|
|
10209
|
+
};
|
|
10210
|
+
function invoiceAmountText(amount2) {
|
|
10211
|
+
return withPlaces(amount2, 2);
|
|
10212
|
+
}
|
|
10213
|
+
function einvoiceXml(data, options) {
|
|
10214
|
+
const block = data !== null && typeof data === "object" ? data[INVOICE_DATA_KEY] : void 0;
|
|
10215
|
+
if (block === void 0 || block === null)
|
|
10216
|
+
return {
|
|
10217
|
+
ok: false,
|
|
10218
|
+
problems: [
|
|
10219
|
+
{
|
|
10220
|
+
code: "missing",
|
|
10221
|
+
path: "",
|
|
10222
|
+
message: "The data has no _invoice block: an e-invoice is built from it",
|
|
10223
|
+
args: { path: "" }
|
|
10224
|
+
}
|
|
10225
|
+
]
|
|
10226
|
+
};
|
|
10227
|
+
const check = checkInvoice(block, options);
|
|
10228
|
+
if (!check.ok) return { ok: false, problems: check.problems };
|
|
10229
|
+
return {
|
|
10230
|
+
ok: true,
|
|
10231
|
+
xml: invoiceToCii(check.invoice, options),
|
|
10232
|
+
invoice: check.invoice
|
|
10233
|
+
};
|
|
10234
|
+
}
|
|
10235
|
+
|
|
10236
|
+
// packages/engine/src/lib/accessibility/index.ts
|
|
10237
|
+
var PDFUA_STANDARD = "PDF/UA-1";
|
|
10238
|
+
var UA_CHECKS = ["strict", "report"];
|
|
10239
|
+
function resolveUa(setting) {
|
|
10240
|
+
if (setting === true) return { check: "strict" };
|
|
10241
|
+
if (!setting || typeof setting !== "object" || Array.isArray(setting))
|
|
10242
|
+
return null;
|
|
10243
|
+
const check = setting.check;
|
|
10244
|
+
return { check: check === "report" ? "report" : "strict" };
|
|
10245
|
+
}
|
|
10246
|
+
var UA_REFUSALS = {
|
|
10247
|
+
office: "pdf.ua is not available for Word and PowerPoint templates yet",
|
|
10248
|
+
merge: "pdf.ua cannot be combined with post.merge_after: the tags of merged documents do not survive the merge"
|
|
10249
|
+
};
|
|
10250
|
+
function isUaSetting(value) {
|
|
10251
|
+
if (value === null || typeof value === "boolean") return true;
|
|
10252
|
+
if (typeof value !== "object" || Array.isArray(value)) return false;
|
|
10253
|
+
const entries = Object.entries(value);
|
|
10254
|
+
return entries.every(
|
|
10255
|
+
([key, entry]) => key === "check" && UA_CHECKS.includes(entry)
|
|
10256
|
+
);
|
|
10257
|
+
}
|
|
10258
|
+
var AUDIT_CODES = [
|
|
10259
|
+
"document-title",
|
|
10260
|
+
"image-alt",
|
|
10261
|
+
"figure-name",
|
|
10262
|
+
"heading-order",
|
|
10263
|
+
"table-rows",
|
|
10264
|
+
"table-cell-empty",
|
|
10265
|
+
"masked-text",
|
|
10266
|
+
"filtered-text",
|
|
10267
|
+
"document-language",
|
|
10268
|
+
"table-headers",
|
|
10269
|
+
"link-name",
|
|
10270
|
+
"generated-text",
|
|
10271
|
+
"fixed-text",
|
|
10272
|
+
"running-text"
|
|
10273
|
+
];
|
|
10274
|
+
var AUDIT_SEVERITY = {
|
|
10275
|
+
"document-title": "error",
|
|
10276
|
+
"image-alt": "error",
|
|
10277
|
+
"figure-name": "error",
|
|
10278
|
+
"heading-order": "error",
|
|
10279
|
+
"table-rows": "error",
|
|
10280
|
+
"table-cell-empty": "error",
|
|
10281
|
+
"masked-text": "error",
|
|
10282
|
+
"filtered-text": "warning",
|
|
10283
|
+
"document-language": "warning",
|
|
10284
|
+
"table-headers": "warning",
|
|
10285
|
+
"link-name": "warning",
|
|
10286
|
+
"generated-text": "warning",
|
|
10287
|
+
"fixed-text": "warning",
|
|
10288
|
+
"running-text": "warning"
|
|
10289
|
+
};
|
|
10290
|
+
var AUDIT_RULES = {
|
|
10291
|
+
"document-title": ["7.1-9", "7.1-10"],
|
|
10292
|
+
"image-alt": ["7.3-1"],
|
|
10293
|
+
"figure-name": ["7.3-1"],
|
|
10294
|
+
"heading-order": ["7.4.2-1"],
|
|
10295
|
+
"table-rows": ["7.2-43"],
|
|
10296
|
+
"table-cell-empty": ["7.2-43"],
|
|
10297
|
+
"masked-text": ["7.20-2"],
|
|
10298
|
+
"filtered-text": [],
|
|
10299
|
+
"document-language": [],
|
|
10300
|
+
"table-headers": [],
|
|
10301
|
+
"link-name": [],
|
|
10302
|
+
"generated-text": [],
|
|
10303
|
+
"fixed-text": [],
|
|
10304
|
+
"running-text": []
|
|
10305
|
+
};
|
|
10306
|
+
var AUDIT_TITLES = {
|
|
10307
|
+
"document-title": "No document title",
|
|
10308
|
+
"image-alt": "Image without an alt attribute",
|
|
10309
|
+
"figure-name": "Figure without a name",
|
|
10310
|
+
"heading-order": "Heading level skipped",
|
|
10311
|
+
"table-rows": "Table rows of different lengths",
|
|
10312
|
+
"table-cell-empty": "Empty table cell",
|
|
10313
|
+
"masked-text": "Text under a CSS mask",
|
|
10314
|
+
"filtered-text": "Text under a CSS filter",
|
|
10315
|
+
"document-language": "No language stated",
|
|
10316
|
+
"table-headers": "Table without header cells",
|
|
10317
|
+
"link-name": "Link without a name",
|
|
10318
|
+
"generated-text": "Text generated by CSS",
|
|
10319
|
+
"fixed-text": "Fixed text on every page",
|
|
10320
|
+
"running-text": "Only in the header or footer"
|
|
10321
|
+
};
|
|
10322
|
+
var AUDIT_SNIPPET_LENGTH = 120;
|
|
10323
|
+
var text3 = (value) => String(value ?? "");
|
|
10324
|
+
function auditMessage(finding2) {
|
|
10325
|
+
const args = finding2.args;
|
|
10326
|
+
switch (finding2.code) {
|
|
10327
|
+
case "document-title":
|
|
10328
|
+
return "The document has no title. A PDF viewer shows the title in its title bar and a screen reader says it first: set pdf.metadata.title, or give the page a <title>.";
|
|
10329
|
+
case "image-alt":
|
|
10330
|
+
return 'The image has no alt attribute. Say what it shows, or write alt="" if it is decoration.';
|
|
10331
|
+
case "figure-name":
|
|
10332
|
+
return `The ${text3(args["tag"])} has no text alternative. Give it an aria-label that says what it shows; the chart helper takes alt.`;
|
|
10333
|
+
case "heading-order":
|
|
10334
|
+
return args["previous"] === 0 ? `The first heading is an h${text3(args["level"])}. Start with an h1 and size it with CSS.` : `This h${text3(args["level"])} follows an h${text3(args["previous"])}, so a heading level is skipped. Make it an h${Number(args["previous"]) + 1} and size it with CSS.`;
|
|
10335
|
+
case "table-rows":
|
|
10336
|
+
return `The rows of this table span different numbers of columns (${text3(args["first"])} and ${text3(args["other"])}). Even them out with colspan.`;
|
|
10337
|
+
case "table-cell-empty":
|
|
10338
|
+
return Number(args["count"]) > 1 ? `${text3(args["count"])} cells of this table are empty. Chromium writes no cell for an empty td, so their rows come out shorter than the others: put a non-breaking space ( ) or a dash into each.` : "This table cell is empty. Chromium writes no cell for an empty td, so its row comes out shorter than the others: put a non-breaking space ( ) or a dash into it.";
|
|
10339
|
+
case "masked-text":
|
|
10340
|
+
return "This element has a CSS mask and holds text. Chromium then writes the text in a way PDF/UA-1 does not allow, and no repair reaches it: mask an element without text instead.";
|
|
10341
|
+
case "filtered-text":
|
|
10342
|
+
return "This element has a CSS filter and holds text. The filter turns the text into a picture, which nobody can have read out or select.";
|
|
10343
|
+
case "document-language":
|
|
10344
|
+
return "The document names no language. Set lang on the html element, or the locale in the settings.";
|
|
10345
|
+
case "table-headers":
|
|
10346
|
+
return "The table has no header cells. Use th for the titles of its columns or rows, or a screen reader says the cells without them.";
|
|
10347
|
+
case "link-name":
|
|
10348
|
+
return "The link has no text. A screen reader says its address instead: give it text, an aria-label, or an image with alt.";
|
|
10349
|
+
case "generated-text":
|
|
10350
|
+
return `\u201C${text3(args["text"])}\u201D comes from CSS (::before or ::after). Generated text is not read out: write it into the template.`;
|
|
10351
|
+
case "fixed-text":
|
|
10352
|
+
return "This element is position: fixed, so it is printed on every page and read once per page, one after the other.";
|
|
10353
|
+
case "running-text":
|
|
10354
|
+
return `\u201C${text3(args["text"])}\u201D stands only in the ${text3(args["part"])}. A screen reader skips page headers and footers, so say it in the body too.`;
|
|
10355
|
+
}
|
|
10356
|
+
}
|
|
10357
|
+
var ACCESSIBILITY_MAX_FAILURES = 20;
|
|
10358
|
+
var ACCESSIBILITY_MAX_ELEMENTS = 5;
|
|
10359
|
+
var elementOf = (finding2) => finding2.code === "running-text" || finding2.code === "generated-text" ? text3(finding2.args["text"]) : finding2.snippet;
|
|
10360
|
+
function accessibilityResult(options, verdict, findings) {
|
|
10361
|
+
const failures = verdict.failures.map((failure) => {
|
|
10362
|
+
const about = findings.filter(
|
|
10363
|
+
(finding2) => AUDIT_RULES[finding2.code].includes(failure.rule)
|
|
10364
|
+
);
|
|
10365
|
+
const first = about[0];
|
|
10366
|
+
return {
|
|
10367
|
+
rule: failure.rule,
|
|
10368
|
+
...first ? { code: first.code } : {},
|
|
10369
|
+
count: failure.checks,
|
|
10370
|
+
message: first ? auditMessage(first) : failure.description.replace(/\s+/g, " ").trim(),
|
|
10371
|
+
elements: [...new Set(about.map(elementOf).filter(Boolean))].slice(
|
|
10372
|
+
0,
|
|
10373
|
+
ACCESSIBILITY_MAX_ELEMENTS
|
|
10374
|
+
)
|
|
10375
|
+
};
|
|
10376
|
+
});
|
|
10377
|
+
const warnings = [];
|
|
10378
|
+
for (const finding2 of findings) {
|
|
10379
|
+
if (finding2.severity !== "warning") continue;
|
|
10380
|
+
let warning = warnings.find((entry) => entry.code === finding2.code);
|
|
10381
|
+
if (!warning)
|
|
10382
|
+
warnings.push(warning = { code: finding2.code, count: 0, elements: [] });
|
|
10383
|
+
warning.count++;
|
|
10384
|
+
const element = elementOf(finding2);
|
|
10385
|
+
if (element && warning.elements.length < ACCESSIBILITY_MAX_ELEMENTS && !warning.elements.includes(element))
|
|
10386
|
+
warning.elements.push(element);
|
|
10387
|
+
}
|
|
10388
|
+
return {
|
|
10389
|
+
standard: PDFUA_STANDARD,
|
|
10390
|
+
check: options.check,
|
|
10391
|
+
conformant: verdict.compliant,
|
|
10392
|
+
validator: verdict.validator,
|
|
10393
|
+
rules: verdict.rules,
|
|
10394
|
+
failures: failures.slice(0, ACCESSIBILITY_MAX_FAILURES),
|
|
10395
|
+
warnings,
|
|
10396
|
+
...failures.length > ACCESSIBILITY_MAX_FAILURES ? { truncated: true } : {}
|
|
10397
|
+
};
|
|
10398
|
+
}
|
|
10399
|
+
function accessibilityHeader(result) {
|
|
10400
|
+
return result.conformant ? "conformant" : "not-conformant";
|
|
10401
|
+
}
|
|
10402
|
+
var ACCESSIBILITY_HEADER_LENGTH = 8e3;
|
|
10403
|
+
function accessibilityHeaderValue(result, limit = ACCESSIBILITY_HEADER_LENGTH) {
|
|
10404
|
+
const encode = (report2) => encodeURIComponent(JSON.stringify(report2));
|
|
10405
|
+
const keep = (report2, elements) => ({
|
|
10406
|
+
...report2,
|
|
10407
|
+
truncated: true,
|
|
10408
|
+
failures: report2.failures.map((failure) => ({
|
|
10409
|
+
...failure,
|
|
10410
|
+
elements: failure.elements.slice(0, elements)
|
|
10411
|
+
})),
|
|
10412
|
+
warnings: report2.warnings.map((warning) => ({
|
|
10413
|
+
...warning,
|
|
10414
|
+
elements: warning.elements.slice(0, elements)
|
|
10415
|
+
}))
|
|
10416
|
+
});
|
|
10417
|
+
let value = encode(result);
|
|
10418
|
+
if (value.length <= limit) return value;
|
|
10419
|
+
for (const elements of [1, 0]) {
|
|
10420
|
+
value = encode(keep(result, elements));
|
|
10421
|
+
if (value.length <= limit) return value;
|
|
10422
|
+
}
|
|
10423
|
+
let report = keep(result, 0);
|
|
10424
|
+
while (report.failures.length + report.warnings.length > 0) {
|
|
10425
|
+
report = report.warnings.length ? { ...report, warnings: report.warnings.slice(0, -1) } : { ...report, failures: report.failures.slice(0, -1) };
|
|
10426
|
+
value = encode(report);
|
|
10427
|
+
if (value.length <= limit) return value;
|
|
10428
|
+
}
|
|
10429
|
+
return value;
|
|
10430
|
+
}
|
|
10431
|
+
|
|
10432
|
+
// packages/engine/src/lib/accessibility/static.ts
|
|
10433
|
+
var finding = (code, src, snippet) => ({
|
|
10434
|
+
code,
|
|
10435
|
+
severity: AUDIT_SEVERITY[code],
|
|
10436
|
+
src,
|
|
10437
|
+
snippet,
|
|
10438
|
+
args: {}
|
|
10439
|
+
});
|
|
10440
|
+
var NAMING = /* @__PURE__ */ new Set(["alt", "aria-label", "aria-labelledby", "title"]);
|
|
10441
|
+
function imageIsNamed(attributes, scanner, base) {
|
|
10442
|
+
const n = attributes.length;
|
|
10443
|
+
let i = 0;
|
|
10444
|
+
let named = false;
|
|
10445
|
+
while (i < n) {
|
|
10446
|
+
const ch = attributes[i];
|
|
10447
|
+
if (/[\s/>]/.test(ch)) {
|
|
10448
|
+
i++;
|
|
10449
|
+
continue;
|
|
10450
|
+
}
|
|
10451
|
+
if (ch === "{" && scanner.skipTemplate(base + i) !== null) return null;
|
|
10452
|
+
const start = i;
|
|
10453
|
+
while (i < n && !/[\s=/>]/.test(attributes[i])) i++;
|
|
10454
|
+
const name = attributes.slice(start, i).toLowerCase();
|
|
10455
|
+
while (i < n && /\s/.test(attributes[i])) i++;
|
|
10456
|
+
let value = "";
|
|
10457
|
+
if (attributes[i] === "=") {
|
|
10458
|
+
i++;
|
|
10459
|
+
while (i < n && /\s/.test(attributes[i])) i++;
|
|
10460
|
+
const quote2 = attributes[i];
|
|
10461
|
+
if (quote2 === '"' || quote2 === "'") {
|
|
10462
|
+
const end = scanner.skipTo(base + i + 1, quote2) - base;
|
|
10463
|
+
value = attributes.slice(i + 1, Math.max(i + 1, end - 1));
|
|
10464
|
+
i = end;
|
|
10465
|
+
} else {
|
|
10466
|
+
const from = i;
|
|
10467
|
+
while (i < n && !/[\s>]/.test(attributes[i])) i++;
|
|
10468
|
+
value = attributes.slice(from, i);
|
|
10469
|
+
}
|
|
10470
|
+
}
|
|
10471
|
+
if (NAMING.has(name)) named = true;
|
|
10472
|
+
else if (name === "aria-hidden" && value.trim() !== "false") named = true;
|
|
10473
|
+
else if (name === "role" && /^(presentation|none)$/.test(value.trim()))
|
|
10474
|
+
named = true;
|
|
10475
|
+
}
|
|
10476
|
+
return named;
|
|
10477
|
+
}
|
|
10478
|
+
function staticAuditDiagnostics(input, ua) {
|
|
10479
|
+
return staticAudit(input).map((found) => {
|
|
10480
|
+
const at = /^body:(\d+):(\d+)$/.exec(found.src ?? "");
|
|
10481
|
+
return {
|
|
10482
|
+
severity: found.severity === "error" && ua.check === "strict" ? "error" : "warning",
|
|
10483
|
+
code: `accessibility-${found.code}`,
|
|
10484
|
+
message: auditMessage(found),
|
|
10485
|
+
...at ? { location: { line: Number(at[1]), column: Number(at[2]) } } : {}
|
|
10486
|
+
};
|
|
10487
|
+
});
|
|
10488
|
+
}
|
|
10489
|
+
function staticAudit(input) {
|
|
10490
|
+
const findings = [];
|
|
10491
|
+
if (!input.title?.trim() && !/<title[\s>]/i.test(input.head ?? ""))
|
|
10492
|
+
findings.push(finding("document-title", null, ""));
|
|
10493
|
+
const source = input.html;
|
|
10494
|
+
const scanner = new Scanner(source, input.engine);
|
|
10495
|
+
const lines = lineStarts(source);
|
|
10496
|
+
const n = source.length;
|
|
10497
|
+
let i = 0;
|
|
10498
|
+
while (i < n) {
|
|
10499
|
+
const ch = source[i];
|
|
10500
|
+
if (ch === "{") {
|
|
10501
|
+
i = scanner.skipTemplate(i) ?? i + 1;
|
|
10502
|
+
continue;
|
|
10503
|
+
}
|
|
10504
|
+
if (ch !== "<") {
|
|
10505
|
+
i++;
|
|
10506
|
+
continue;
|
|
10507
|
+
}
|
|
10508
|
+
if (source.startsWith("<!--", i)) {
|
|
10509
|
+
i = scanner.skipTo(i + 4, "-->");
|
|
10510
|
+
continue;
|
|
10511
|
+
}
|
|
10512
|
+
const next = source[i + 1];
|
|
10513
|
+
if (next === "!" || next === "?") {
|
|
10514
|
+
i = scanner.tagEnd(i + 2);
|
|
10515
|
+
continue;
|
|
10516
|
+
}
|
|
10517
|
+
if (next === "/") {
|
|
10518
|
+
i += 2;
|
|
10519
|
+
continue;
|
|
10520
|
+
}
|
|
10521
|
+
tagName.lastIndex = i + 1;
|
|
10522
|
+
const name = tagName.exec(source)?.[0];
|
|
10523
|
+
if (!name) {
|
|
10524
|
+
i++;
|
|
10525
|
+
continue;
|
|
10526
|
+
}
|
|
10527
|
+
const nameEnd = i + 1 + name.length;
|
|
10528
|
+
const end = scanner.tagEnd(nameEnd);
|
|
10529
|
+
if (name.toLowerCase() === "img") {
|
|
10530
|
+
const named = imageIsNamed(source.slice(nameEnd, end), scanner, nameEnd);
|
|
10531
|
+
if (named === false) {
|
|
10532
|
+
const { line: line2, column } = locate(lines, i);
|
|
10533
|
+
const tag = source.slice(i, end).replace(/\s+/g, " ");
|
|
10534
|
+
findings.push(
|
|
10535
|
+
finding(
|
|
10536
|
+
"image-alt",
|
|
10537
|
+
`body:${line2}:${column}`,
|
|
10538
|
+
tag.length > AUDIT_SNIPPET_LENGTH ? `${tag.slice(0, AUDIT_SNIPPET_LENGTH - 1)}\u2026` : tag
|
|
10539
|
+
)
|
|
10540
|
+
);
|
|
10541
|
+
}
|
|
10542
|
+
}
|
|
10543
|
+
i = end;
|
|
10544
|
+
if (rawTextElements.has(name.toLowerCase()) && source[end - 1] === ">")
|
|
10545
|
+
i = scanner.skipToClosingTag(end, name);
|
|
10546
|
+
}
|
|
10547
|
+
return findings;
|
|
10548
|
+
}
|
|
10549
|
+
|
|
8009
10550
|
// packages/engine/src/lib/office/errors.ts
|
|
8010
10551
|
var OfficeError = class extends Error {
|
|
8011
10552
|
constructor(code, message, details = {}) {
|
|
@@ -9325,12 +11866,12 @@ function assertWellFormed(tokens, part) {
|
|
|
9325
11866
|
}
|
|
9326
11867
|
var FORBIDDEN = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;
|
|
9327
11868
|
var ENTITY = /&(?:#x[0-9A-Fa-f]+|#\d+|amp|lt|gt|quot|apos);/y;
|
|
9328
|
-
function checkText(
|
|
9329
|
-
if (FORBIDDEN.test(
|
|
9330
|
-
if (
|
|
9331
|
-
for (let i =
|
|
11869
|
+
function checkText(text4, part) {
|
|
11870
|
+
if (FORBIDDEN.test(text4)) throw invalid2("a character XML does not allow", part);
|
|
11871
|
+
if (text4.includes("<")) throw invalid2("unescaped < in text", part);
|
|
11872
|
+
for (let i = text4.indexOf("&"); i !== -1; i = text4.indexOf("&", i + 1)) {
|
|
9332
11873
|
ENTITY.lastIndex = i;
|
|
9333
|
-
if (!ENTITY.test(
|
|
11874
|
+
if (!ENTITY.test(text4)) throw invalid2(`invalid entity reference near "${text4.slice(i, i + 12)}"`, part);
|
|
9334
11875
|
}
|
|
9335
11876
|
}
|
|
9336
11877
|
function checkAttributes(raw, part) {
|
|
@@ -9365,13 +11906,13 @@ function decodeText3(raw) {
|
|
|
9365
11906
|
}
|
|
9366
11907
|
});
|
|
9367
11908
|
}
|
|
9368
|
-
function
|
|
9369
|
-
return
|
|
11909
|
+
function escapeText3(text4) {
|
|
11910
|
+
return text4.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
9370
11911
|
}
|
|
9371
11912
|
var FORBIDDEN_GLOBAL = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g;
|
|
9372
|
-
function stripForbidden(
|
|
11913
|
+
function stripForbidden(text4) {
|
|
9373
11914
|
let removed = 0;
|
|
9374
|
-
const out =
|
|
11915
|
+
const out = text4.replace(FORBIDDEN_GLOBAL, () => {
|
|
9375
11916
|
removed++;
|
|
9376
11917
|
return "";
|
|
9377
11918
|
});
|
|
@@ -9584,7 +12125,7 @@ function textWidthEmu(xml2) {
|
|
|
9584
12125
|
function inlinePicture(picture, rId, id) {
|
|
9585
12126
|
const a = "http://schemas.openxmlformats.org/drawingml/2006/main";
|
|
9586
12127
|
const name = `Formfeed picture ${id}`;
|
|
9587
|
-
const alt =
|
|
12128
|
+
const alt = escapeText3(picture.alt).replace(/"/g, """);
|
|
9588
12129
|
const { widthEmu: cx, heightEmu: cy } = picture;
|
|
9589
12130
|
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>`;
|
|
9590
12131
|
}
|
|
@@ -9622,13 +12163,13 @@ function placeDrawings(xml2, pattern, markupFor) {
|
|
|
9622
12163
|
pattern.lastIndex = 0;
|
|
9623
12164
|
if (pattern.test(t.raw)) {
|
|
9624
12165
|
const segments = t.raw.split(pattern);
|
|
9625
|
-
let
|
|
12166
|
+
let text4 = segments[0];
|
|
9626
12167
|
for (let s = 1; s < segments.length; s += 2) {
|
|
9627
12168
|
const index = Number(segments[s]);
|
|
9628
|
-
|
|
12169
|
+
text4 += `</w:t></w:r><w:r>${runProps}${markupFor(index)}</w:r>${runOpen}${runProps}<w:t xml:space="preserve">` + segments[s + 1];
|
|
9629
12170
|
}
|
|
9630
12171
|
out[textOpen] = withPreserve(out[textOpen]);
|
|
9631
|
-
out.push(
|
|
12172
|
+
out.push(text4);
|
|
9632
12173
|
continue;
|
|
9633
12174
|
}
|
|
9634
12175
|
}
|
|
@@ -9641,7 +12182,7 @@ function withPreserve(openTag) {
|
|
|
9641
12182
|
}
|
|
9642
12183
|
function withRelationships(rels2, relationships) {
|
|
9643
12184
|
const type = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image";
|
|
9644
|
-
const added = relationships.map((r) => `<Relationship Id="${r.id}" Type="${type}" Target="${
|
|
12185
|
+
const added = relationships.map((r) => `<Relationship Id="${r.id}" Type="${type}" Target="${escapeText3(r.target)}"/>`).join("");
|
|
9645
12186
|
if (!rels2)
|
|
9646
12187
|
return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">${added}</Relationships>`;
|
|
9647
12188
|
const end = rels2.lastIndexOf("</Relationships>");
|
|
@@ -9883,11 +12424,11 @@ function fromTemplateOutput(output, template, part) {
|
|
|
9883
12424
|
let last = 0;
|
|
9884
12425
|
let inText = false;
|
|
9885
12426
|
const emit = (segment) => {
|
|
9886
|
-
const { text:
|
|
12427
|
+
const { text: text4, removed } = stripForbidden(segment);
|
|
9887
12428
|
removedCharacters += removed;
|
|
9888
|
-
if (!inText &&
|
|
9889
|
-
throw new OfficeError("office_document_invalid", `${part ?? "part"}: text outside a text element: "${
|
|
9890
|
-
xml2 +=
|
|
12429
|
+
if (!inText && text4.trim() !== "")
|
|
12430
|
+
throw new OfficeError("office_document_invalid", `${part ?? "part"}: text outside a text element: "${text4.trim().slice(0, 40)}"`);
|
|
12431
|
+
xml2 += escapeText3(text4);
|
|
9891
12432
|
};
|
|
9892
12433
|
for (const m of output.matchAll(placeholder)) {
|
|
9893
12434
|
emit(output.slice(last, m.index));
|
|
@@ -9929,15 +12470,15 @@ function layoutText(xml2, flavour, part) {
|
|
|
9929
12470
|
out.push(token2.raw);
|
|
9930
12471
|
continue;
|
|
9931
12472
|
}
|
|
9932
|
-
const
|
|
12473
|
+
const text4 = token2.raw.replace(/\r\n?/g, "\n");
|
|
9933
12474
|
if (flavour === "wordprocessing") {
|
|
9934
|
-
const pieces =
|
|
9935
|
-
if (pieces.length > 1 || /^\s|\s$/.test(
|
|
12475
|
+
const pieces = text4.split(/(\n|\t)/);
|
|
12476
|
+
if (pieces.length > 1 || /^\s|\s$/.test(text4)) out[textOpenIndex] = preserveSpace(out[textOpenIndex]);
|
|
9936
12477
|
out.push(
|
|
9937
12478
|
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("")
|
|
9938
12479
|
);
|
|
9939
12480
|
} else {
|
|
9940
|
-
out.push(
|
|
12481
|
+
out.push(text4.split("\n").join(`</a:t></a:r><a:br>${runProperties}</a:br><a:r>${runProperties}<a:t>`));
|
|
9941
12482
|
}
|
|
9942
12483
|
}
|
|
9943
12484
|
return out.join("");
|
|
@@ -9970,17 +12511,17 @@ var AUTOCORRECTED = [
|
|
|
9970
12511
|
[/\u200B|\u200C|\u200D|\uFEFF/g, ""]
|
|
9971
12512
|
];
|
|
9972
12513
|
function normaliseTags(template, part) {
|
|
9973
|
-
const { text:
|
|
12514
|
+
const { text: text4, origin, placeholders } = stripPlaceholders(template);
|
|
9974
12515
|
const sourceRange = (from, to) => [
|
|
9975
12516
|
origin[from] ?? template.source.length,
|
|
9976
12517
|
(origin[to - 1] ?? template.source.length - 1) + 1
|
|
9977
12518
|
];
|
|
9978
12519
|
const diagnostics = [];
|
|
9979
12520
|
const edits = [];
|
|
9980
|
-
for (const tag of findTags(
|
|
12521
|
+
for (const tag of findTags(text4)) {
|
|
9981
12522
|
const inside = placeholders.filter((p) => p.at > tag.start && p.at < tag.end);
|
|
9982
12523
|
const paragraph2 = paragraphOf(template, placeholders, tag.start);
|
|
9983
|
-
const raw =
|
|
12524
|
+
const raw = text4.slice(tag.start, tag.end);
|
|
9984
12525
|
const unsafe = inside.filter((p) => {
|
|
9985
12526
|
const piece = template.markup[p.index];
|
|
9986
12527
|
return !piece || piece.paragraphBoundary || piece.containerBoundary;
|
|
@@ -10016,7 +12557,7 @@ function normaliseTags(template, part) {
|
|
|
10016
12557
|
for (const p of placeholders) {
|
|
10017
12558
|
const raw = template.markup[p.index]?.raw ?? "";
|
|
10018
12559
|
for (const m of raw.matchAll(/<w:instrText\b[^>]*>([^<]*)<\/w:instrText>/g)) {
|
|
10019
|
-
const code =
|
|
12560
|
+
const code = decodeEntities2(m[1] ?? "");
|
|
10020
12561
|
if (!/\{\{|\{%|\{#/.test(code)) continue;
|
|
10021
12562
|
const paragraph2 = paragraphOf(template, placeholders, p.at);
|
|
10022
12563
|
if (reported.has(paragraph2)) continue;
|
|
@@ -10033,38 +12574,38 @@ function normaliseTags(template, part) {
|
|
|
10033
12574
|
}
|
|
10034
12575
|
return { template: { ...template, source: applyEdits(template.source, edits) }, diagnostics };
|
|
10035
12576
|
}
|
|
10036
|
-
var
|
|
10037
|
-
function
|
|
10038
|
-
return
|
|
10039
|
-
if (name[0] !== "#") return
|
|
12577
|
+
var ENTITIES2 = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'" };
|
|
12578
|
+
function decodeEntities2(text4) {
|
|
12579
|
+
return text4.replace(/&(#x[0-9a-f]+|#\d+|amp|lt|gt|quot|apos);/gi, (whole, name) => {
|
|
12580
|
+
if (name[0] !== "#") return ENTITIES2[name.toLowerCase()] ?? whole;
|
|
10040
12581
|
const code = name[1] === "x" || name[1] === "X" ? parseInt(name.slice(2), 16) : parseInt(name.slice(1), 10);
|
|
10041
12582
|
return Number.isFinite(code) ? String.fromCodePoint(code) : whole;
|
|
10042
12583
|
});
|
|
10043
12584
|
}
|
|
10044
12585
|
function stripPlaceholders(template) {
|
|
10045
12586
|
const pattern = placeholderPattern(template.nonce);
|
|
10046
|
-
let
|
|
12587
|
+
let text4 = "";
|
|
10047
12588
|
const origin = [];
|
|
10048
12589
|
const placeholders = [];
|
|
10049
12590
|
let last = 0;
|
|
10050
12591
|
for (const m of template.source.matchAll(pattern)) {
|
|
10051
12592
|
for (let i = last; i < (m.index ?? 0); i++) {
|
|
10052
|
-
|
|
12593
|
+
text4 += template.source[i];
|
|
10053
12594
|
origin.push(i);
|
|
10054
12595
|
}
|
|
10055
|
-
placeholders.push({ index: Number(m[1]), at:
|
|
12596
|
+
placeholders.push({ index: Number(m[1]), at: text4.length, from: m.index ?? 0, to: (m.index ?? 0) + m[0].length });
|
|
10056
12597
|
last = (m.index ?? 0) + m[0].length;
|
|
10057
12598
|
}
|
|
10058
12599
|
for (let i = last; i < template.source.length; i++) {
|
|
10059
|
-
|
|
12600
|
+
text4 += template.source[i];
|
|
10060
12601
|
origin.push(i);
|
|
10061
12602
|
}
|
|
10062
|
-
return { text:
|
|
12603
|
+
return { text: text4, origin, placeholders };
|
|
10063
12604
|
}
|
|
10064
12605
|
function listTags(template, part) {
|
|
10065
|
-
const { text:
|
|
10066
|
-
return findTags(
|
|
10067
|
-
const raw =
|
|
12606
|
+
const { text: text4, placeholders } = stripPlaceholders(template);
|
|
12607
|
+
return findTags(text4).map((tag) => {
|
|
12608
|
+
const raw = text4.slice(tag.start, tag.end);
|
|
10068
12609
|
const kind = raw.startsWith("{#") ? "comment" : raw.startsWith("{%") || /^\{\{~?\s*[#/^]/.test(raw) || /^\{\{~?\s*else\b/.test(raw) ? "block" : "output";
|
|
10069
12610
|
return { part, paragraph: paragraphOf(template, placeholders, tag.start), text: raw.replace(/\s+/g, " ").trim(), kind };
|
|
10070
12611
|
});
|
|
@@ -10085,15 +12626,15 @@ function undoAutocorrect(tag) {
|
|
|
10085
12626
|
for (const [pattern, replacement] of AUTOCORRECTED) out = out.replace(pattern, replacement);
|
|
10086
12627
|
return out;
|
|
10087
12628
|
}
|
|
10088
|
-
function findTags(
|
|
12629
|
+
function findTags(text4) {
|
|
10089
12630
|
const tags = [];
|
|
10090
|
-
for (let i = 0; i <
|
|
10091
|
-
const opener = OPENERS.find((o) =>
|
|
12631
|
+
for (let i = 0; i < text4.length - 1; i++) {
|
|
12632
|
+
const opener = OPENERS.find((o) => text4.startsWith(o, i));
|
|
10092
12633
|
if (!opener) continue;
|
|
10093
12634
|
const closer = CLOSERS[opener];
|
|
10094
|
-
const end =
|
|
12635
|
+
const end = text4.indexOf(closer, i + opener.length);
|
|
10095
12636
|
if (end === -1) continue;
|
|
10096
|
-
const stop = end + closer.length + (opener === "{{" &&
|
|
12637
|
+
const stop = end + closer.length + (opener === "{{" && text4[end + closer.length] === "}" ? 1 : 0);
|
|
10097
12638
|
tags.push({ start: i, end: stop });
|
|
10098
12639
|
i = stop - 1;
|
|
10099
12640
|
}
|
|
@@ -10123,8 +12664,8 @@ var CONTENT = /* @__PURE__ */ new Set(["w:drawing", "w:pict", "w:object", "w:fld
|
|
|
10123
12664
|
var JINJA_OPEN = /^(for|if|unless|case|capture|raw|with|macro|call|filter|block|tablerow|comment|autoescape)\b/;
|
|
10124
12665
|
var JINJA_CLOSE = /^end(for|if|unless|case|capture|raw|with|macro|call|filter|block|tablerow|comment|autoescape)\b/;
|
|
10125
12666
|
var JINJA_MIDDLE = /^(else|elif|elsif|when)\b/;
|
|
10126
|
-
function blockRole(
|
|
10127
|
-
const t =
|
|
12667
|
+
function blockRole(text4) {
|
|
12668
|
+
const t = text4.trim();
|
|
10128
12669
|
let m = /^\{%-?\s*([\s\S]*?)\s*-?%\}$/.exec(t);
|
|
10129
12670
|
if (m && !t.slice(2, -2).includes("%}")) {
|
|
10130
12671
|
const body = m[1] ?? "";
|
|
@@ -10156,14 +12697,14 @@ function dropTaggedFallbacks(xml2, part) {
|
|
|
10156
12697
|
if (t.kind === "open" && t.name === "mc:Fallback" && !t.selfClosing) {
|
|
10157
12698
|
let depth = 1;
|
|
10158
12699
|
let j = i + 1;
|
|
10159
|
-
let
|
|
12700
|
+
let text4 = "";
|
|
10160
12701
|
for (; j < tokens.length && depth > 0; j++) {
|
|
10161
12702
|
const u = tokens[j];
|
|
10162
12703
|
if (u.kind === "open" && u.name === "mc:Fallback" && !u.selfClosing) depth++;
|
|
10163
12704
|
else if (u.kind === "close" && u.name === "mc:Fallback") depth--;
|
|
10164
|
-
else if (u.kind === "text")
|
|
12705
|
+
else if (u.kind === "text") text4 += decodeText3(u.raw);
|
|
10165
12706
|
}
|
|
10166
|
-
if (/\{\{|\{%|\{#/.test(
|
|
12707
|
+
if (/\{\{|\{%|\{#/.test(text4)) {
|
|
10167
12708
|
i = j - 1;
|
|
10168
12709
|
continue;
|
|
10169
12710
|
}
|
|
@@ -10230,15 +12771,15 @@ function applyStructure(xml2, part) {
|
|
|
10230
12771
|
}
|
|
10231
12772
|
}
|
|
10232
12773
|
const replacements = [];
|
|
10233
|
-
const element = (tag) => `<${STRUCTURAL_ELEMENT}>${
|
|
12774
|
+
const element = (tag) => `<${STRUCTURAL_ELEMENT}>${escapeText3(tag)}</${STRUCTURAL_ELEMENT}>`;
|
|
10234
12775
|
for (const [row2, tag] of replacedRows) replacements.push({ start: row2.start, end: row2.end, text: element(tag) });
|
|
10235
12776
|
const cellsEmptied = /* @__PURE__ */ new Map();
|
|
10236
12777
|
for (const [span, s] of structural) {
|
|
10237
12778
|
if (rowOf.has(span)) continue;
|
|
10238
12779
|
const keep = s.info.sectionProperties;
|
|
10239
|
-
let
|
|
10240
|
-
if (keep)
|
|
10241
|
-
replacements.push({ start: span.start, end: span.end, text:
|
|
12780
|
+
let text4 = element(s.tag);
|
|
12781
|
+
if (keep) text4 = s.role === "open" ? `<w:p>${keep}</w:p>${text4}` : `${text4}<w:p>${keep}</w:p>`;
|
|
12782
|
+
replacements.push({ start: span.start, end: span.end, text: text4 });
|
|
10242
12783
|
const holder = span.parent && BODIES.has(span.parent.name) ? span.parent : null;
|
|
10243
12784
|
if (holder && !keep) cellsEmptied.set(holder, (cellsEmptied.get(holder) ?? 0) + 1);
|
|
10244
12785
|
}
|
|
@@ -10292,7 +12833,7 @@ function collectParagraphs(tokens, root) {
|
|
|
10292
12833
|
const out = [];
|
|
10293
12834
|
const walk3 = (span) => {
|
|
10294
12835
|
if (PARAGRAPH.has(span.name)) {
|
|
10295
|
-
let
|
|
12836
|
+
let text4 = "";
|
|
10296
12837
|
let hasContent = false;
|
|
10297
12838
|
let sectionProperties = null;
|
|
10298
12839
|
let inText = false;
|
|
@@ -10303,10 +12844,10 @@ function collectParagraphs(tokens, root) {
|
|
|
10303
12844
|
else if (CONTENT.has(t.name)) hasContent = true;
|
|
10304
12845
|
else if (t.name === "w:sectPr") sectionProperties = "";
|
|
10305
12846
|
} else if (t.kind === "close" && TEXT.has(t.name)) inText = false;
|
|
10306
|
-
else if (t.kind === "text" && inText)
|
|
12847
|
+
else if (t.kind === "text" && inText) text4 += decodeText3(t.raw);
|
|
10307
12848
|
}
|
|
10308
12849
|
if (sectionProperties !== null) sectionProperties = propertiesOf(tokens, span);
|
|
10309
|
-
out.push({ span, number: out.length + 1, text:
|
|
12850
|
+
out.push({ span, number: out.length + 1, text: text4, hasContent, sectionProperties });
|
|
10310
12851
|
}
|
|
10311
12852
|
for (const child2 of span.children) walk3(child2);
|
|
10312
12853
|
};
|
|
@@ -10328,9 +12869,9 @@ function isInside(span, container) {
|
|
|
10328
12869
|
function rewrite(tokens, replacements) {
|
|
10329
12870
|
const byStart = /* @__PURE__ */ new Map();
|
|
10330
12871
|
for (const r of replacements) {
|
|
10331
|
-
const
|
|
10332
|
-
|
|
10333
|
-
byStart.set(r.start,
|
|
12872
|
+
const list3 = byStart.get(r.start) ?? [];
|
|
12873
|
+
list3.push({ end: r.end, text: r.text });
|
|
12874
|
+
byStart.set(r.start, list3);
|
|
10334
12875
|
}
|
|
10335
12876
|
let out = "";
|
|
10336
12877
|
for (let i = 0; i < tokens.length; i++) {
|
|
@@ -10379,7 +12920,7 @@ function boxOf(container, tokens) {
|
|
|
10379
12920
|
return x === null || y === null || cx === null || cy === null ? null : { x, y, cx, cy };
|
|
10380
12921
|
}
|
|
10381
12922
|
function slidePicture(picture, rId, id, box) {
|
|
10382
|
-
const alt =
|
|
12923
|
+
const alt = escapeText3(picture.alt).replace(/"/g, """);
|
|
10383
12924
|
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>`;
|
|
10384
12925
|
}
|
|
10385
12926
|
function layoutPictures(pictures, box, growsWithText = false) {
|
|
@@ -10414,7 +12955,7 @@ function placeSlidePictures(xml2, pattern, drawingFor, pictureMarkup, slide) {
|
|
|
10414
12955
|
for (const container of containers) {
|
|
10415
12956
|
const indexes = [];
|
|
10416
12957
|
const edits = [];
|
|
10417
|
-
let
|
|
12958
|
+
let text4 = "";
|
|
10418
12959
|
let inText = false;
|
|
10419
12960
|
for (let i = container.start + 1; i < container.end; i++) {
|
|
10420
12961
|
const t = tokens[i];
|
|
@@ -10423,7 +12964,7 @@ function placeSlidePictures(xml2, pattern, drawingFor, pictureMarkup, slide) {
|
|
|
10423
12964
|
else if (t.kind === "text" && inText) {
|
|
10424
12965
|
pattern.lastIndex = 0;
|
|
10425
12966
|
if (!pattern.test(t.raw)) {
|
|
10426
|
-
|
|
12967
|
+
text4 += decodeText3(t.raw);
|
|
10427
12968
|
continue;
|
|
10428
12969
|
}
|
|
10429
12970
|
const segments = t.raw.split(pattern);
|
|
@@ -10432,7 +12973,7 @@ function placeSlidePictures(xml2, pattern, drawingFor, pictureMarkup, slide) {
|
|
|
10432
12973
|
if (s % 2 === 1) indexes.push(Number(segments[s]));
|
|
10433
12974
|
else kept += segments[s];
|
|
10434
12975
|
}
|
|
10435
|
-
|
|
12976
|
+
text4 += decodeText3(kept);
|
|
10436
12977
|
edits.push({ at: i, raw: kept });
|
|
10437
12978
|
}
|
|
10438
12979
|
}
|
|
@@ -10451,7 +12992,7 @@ function placeSlidePictures(xml2, pattern, drawingFor, pictureMarkup, slide) {
|
|
|
10451
12992
|
}
|
|
10452
12993
|
const autoFit = tokens.slice(container.start, container.end).some((t) => t.kind === "open" && t.name === "a:spAutoFit");
|
|
10453
12994
|
const placed = layoutPictures(pictures, box, autoFit).map((b, i) => pictureMarkup(pictures[i], b)).join("");
|
|
10454
|
-
const onlyPictures = container.name === "p:sp" &&
|
|
12995
|
+
const onlyPictures = container.name === "p:sp" && text4.trim() === "";
|
|
10455
12996
|
if (onlyPictures) replacements.push({ start: container.start, end: container.end, text: placed });
|
|
10456
12997
|
else {
|
|
10457
12998
|
for (const edit of edits) replacements.push({ start: edit.at, end: edit.at, text: edit.raw });
|
|
@@ -10724,8 +13265,8 @@ function starterTags(engine) {
|
|
|
10724
13265
|
codeFit: engine === "liquid" ? "{{ offer.url | qrcode }}" : "{{ qrcode(offer.url) }}"
|
|
10725
13266
|
};
|
|
10726
13267
|
}
|
|
10727
|
-
var paragraph = (
|
|
10728
|
-
var cell = (
|
|
13268
|
+
var paragraph = (text4, 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(text4)}</w:t></w:r></w:p>`;
|
|
13269
|
+
var cell = (text4, width, bold = false) => `<w:tc><w:tcPr><w:tcW w:w="${width}" w:type="dxa"/></w:tcPr>${paragraph(text4, void 0, bold)}</w:tc>`;
|
|
10729
13270
|
var row = (cells) => `<w:tr>${cells}</w:tr>`;
|
|
10730
13271
|
function starterDocument(engine) {
|
|
10731
13272
|
const t = starterTags(engine);
|
|
@@ -10768,7 +13309,7 @@ function starterDocument(engine) {
|
|
|
10768
13309
|
["word/document.xml", `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w:document xmlns:w="${W}"><w:body>${body}</w:body></w:document>`]
|
|
10769
13310
|
];
|
|
10770
13311
|
return {
|
|
10771
|
-
bytes: writeZip(files.map(([name,
|
|
13312
|
+
bytes: writeZip(files.map(([name, text4]) => ({ name, data: encoder2.encode(text4) }))),
|
|
10772
13313
|
sampleData: starterSampleData()
|
|
10773
13314
|
};
|
|
10774
13315
|
}
|
|
@@ -10796,15 +13337,15 @@ var CM = 36e4;
|
|
|
10796
13337
|
var FONT = "Carlito";
|
|
10797
13338
|
var ACCENT = "0F766E";
|
|
10798
13339
|
var emptyTree = '<p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr><p:grpSpPr/>';
|
|
10799
|
-
var run = (
|
|
10800
|
-
var para = (
|
|
13340
|
+
var run = (text4, 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(text4)}</a:t></a:r>`;
|
|
13341
|
+
var para = (text4, size, options = {}) => `<a:p>${run(text4, size, options)}</a:p>`;
|
|
10801
13342
|
function textBox(id, name, x, y, cx, cy, paragraphs) {
|
|
10802
13343
|
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>`;
|
|
10803
13344
|
}
|
|
10804
|
-
function cell2(
|
|
13345
|
+
function cell2(text4, header) {
|
|
10805
13346
|
const fill = header ? `<a:solidFill><a:srgbClr val="${ACCENT}"/></a:solidFill>` : "<a:noFill/>";
|
|
10806
|
-
const
|
|
10807
|
-
return `<a:tc><a:txBody><a:bodyPr/><a:lstStyle/>${para(
|
|
13347
|
+
const line2 = `<a:lnB w="6350"><a:solidFill><a:srgbClr val="BFBFBF"/></a:solidFill></a:lnB>`;
|
|
13348
|
+
return `<a:tc><a:txBody><a:bodyPr/><a:lstStyle/>${para(text4, 14, header ? { bold: true, color: "FFFFFF" } : {})}</a:txBody><a:tcPr marL="91440" marR="91440" marT="45720" marB="45720">${line2}${fill}</a:tcPr></a:tc>`;
|
|
10808
13349
|
}
|
|
10809
13350
|
var tableRow = (a, b, header = false) => `<a:tr h="${Math.round(0.9 * CM)}">${cell2(a, header)}${cell2(b, header)}</a:tr>`;
|
|
10810
13351
|
function table2(id, x, y, rows) {
|
|
@@ -10814,8 +13355,8 @@ function table2(id, x, y, rows) {
|
|
|
10814
13355
|
function theme() {
|
|
10815
13356
|
const scheme = (name, color) => `<a:${name}><a:srgbClr val="${color}"/></a:${name}>`;
|
|
10816
13357
|
const fill = `<a:solidFill><a:schemeClr val="phClr"/></a:solidFill>`;
|
|
10817
|
-
const
|
|
10818
|
-
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>${
|
|
13358
|
+
const line2 = `<a:ln w="6350"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:ln>`;
|
|
13359
|
+
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>`;
|
|
10819
13360
|
}
|
|
10820
13361
|
var xml = (body) => `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>${body}`;
|
|
10821
13362
|
var rels = (entries) => xml(
|
|
@@ -10894,21 +13435,47 @@ function starterPresentation(engine) {
|
|
|
10894
13435
|
];
|
|
10895
13436
|
const encoder2 = new TextEncoder();
|
|
10896
13437
|
return {
|
|
10897
|
-
bytes: writeZip(files.map(([name,
|
|
13438
|
+
bytes: writeZip(files.map(([name, text4]) => ({ name, data: encoder2.encode(text4) }))),
|
|
10898
13439
|
sampleData: starterSampleData()
|
|
10899
13440
|
};
|
|
10900
13441
|
}
|
|
10901
13442
|
export {
|
|
13443
|
+
ACCESSIBILITY_HEADER_LENGTH,
|
|
13444
|
+
ACCESSIBILITY_MAX_ELEMENTS,
|
|
13445
|
+
ACCESSIBILITY_MAX_FAILURES,
|
|
13446
|
+
AUDIT_CODES,
|
|
13447
|
+
AUDIT_RULES,
|
|
13448
|
+
AUDIT_SEVERITY,
|
|
13449
|
+
AUDIT_SNIPPET_LENGTH,
|
|
13450
|
+
AUDIT_TITLES,
|
|
13451
|
+
CII_GUIDELINES,
|
|
13452
|
+
CODE_LIST_RELEASE,
|
|
10902
13453
|
DEFAULT_CHROME_PADDING,
|
|
10903
13454
|
DESIGN_LIMITS,
|
|
10904
13455
|
DESIGN_VERSION,
|
|
13456
|
+
DISPLAY_TERMS,
|
|
10905
13457
|
DefaultHelperRegistry,
|
|
13458
|
+
EINVOICE_FLAVOURS,
|
|
13459
|
+
EINVOICE_FLAVOUR_NAMES,
|
|
13460
|
+
EINVOICE_MAX_MESSAGES,
|
|
13461
|
+
EINVOICE_PROFILES,
|
|
13462
|
+
EINVOICE_PROFILE_NAMES,
|
|
13463
|
+
EINVOICE_SPEC_VERSIONS,
|
|
13464
|
+
EINVOICE_XML_NAME,
|
|
10906
13465
|
EPC_MAX_BYTES,
|
|
10907
13466
|
EngineSyntaxError,
|
|
13467
|
+
INVOICE_DATA_KEY,
|
|
10908
13468
|
OFFICE_FILLED_MAX_BYTES,
|
|
10909
13469
|
OfficeTemplateError,
|
|
13470
|
+
PDFUA_STANDARD,
|
|
10910
13471
|
RenderError,
|
|
10911
13472
|
RenderLimitError,
|
|
13473
|
+
UA_CHECKS,
|
|
13474
|
+
UA_REFUSALS,
|
|
13475
|
+
VAT_CATEGORIES,
|
|
13476
|
+
accessibilityHeader,
|
|
13477
|
+
accessibilityHeaderValue,
|
|
13478
|
+
accessibilityResult,
|
|
10912
13479
|
analyzeHandlebars,
|
|
10913
13480
|
analyzeJinja2,
|
|
10914
13481
|
analyzeLiquid,
|
|
@@ -10917,16 +13484,21 @@ export {
|
|
|
10917
13484
|
apitemplateRegions,
|
|
10918
13485
|
applyRegionEdit,
|
|
10919
13486
|
assembleDocument,
|
|
13487
|
+
auditMessage,
|
|
13488
|
+
auditRuntime,
|
|
10920
13489
|
brandCss,
|
|
10921
13490
|
builtinHelpers,
|
|
10922
13491
|
canvasDocument,
|
|
13492
|
+
capMessages,
|
|
10923
13493
|
chartInitScript,
|
|
10924
13494
|
chartMarkup,
|
|
10925
13495
|
chartPayload,
|
|
13496
|
+
checkInvoice,
|
|
10926
13497
|
chipValues,
|
|
10927
13498
|
convertScss,
|
|
10928
13499
|
createHelperRegistry,
|
|
10929
13500
|
dataPathPattern,
|
|
13501
|
+
defaultEinvoiceOptions,
|
|
10930
13502
|
defaultHelpers,
|
|
10931
13503
|
defaultLayer,
|
|
10932
13504
|
defaultLimits,
|
|
@@ -10937,9 +13509,14 @@ export {
|
|
|
10937
13509
|
designOutputHash,
|
|
10938
13510
|
designStarters,
|
|
10939
13511
|
diffSchemas,
|
|
13512
|
+
displayCheck,
|
|
13513
|
+
displayMissingText,
|
|
10940
13514
|
editAttribute,
|
|
10941
13515
|
editableRegion,
|
|
10942
13516
|
editableRegionAt,
|
|
13517
|
+
einvoiceOptionsSchema,
|
|
13518
|
+
einvoiceResult,
|
|
13519
|
+
einvoiceXml,
|
|
10943
13520
|
emitDesign,
|
|
10944
13521
|
emptyBrand,
|
|
10945
13522
|
emptyDesign,
|
|
@@ -10959,6 +13536,7 @@ export {
|
|
|
10959
13536
|
googleFontsUrl,
|
|
10960
13537
|
handlebarsEngine,
|
|
10961
13538
|
helperDocs,
|
|
13539
|
+
htmlText,
|
|
10962
13540
|
ibanChecksum,
|
|
10963
13541
|
imageIsEmpty,
|
|
10964
13542
|
imageMarkup,
|
|
@@ -10969,11 +13547,18 @@ export {
|
|
|
10969
13547
|
importPdfmonkey,
|
|
10970
13548
|
inferSchema,
|
|
10971
13549
|
inferSchemaFromDataSets,
|
|
13550
|
+
invoiceAmountText,
|
|
13551
|
+
invoiceLineOf,
|
|
13552
|
+
invoicePathSegments,
|
|
13553
|
+
invoiceSchema,
|
|
13554
|
+
invoiceSkeleton,
|
|
13555
|
+
invoiceToCii,
|
|
10972
13556
|
isApitemplateHtmlTemplate,
|
|
10973
13557
|
isApitemplateRegion,
|
|
10974
13558
|
isOfficeKind,
|
|
10975
13559
|
isOutputFormat,
|
|
10976
13560
|
isScss,
|
|
13561
|
+
isUaSetting,
|
|
10977
13562
|
jinja2Engine,
|
|
10978
13563
|
jinjaTags,
|
|
10979
13564
|
jsreportTemplates,
|
|
@@ -10982,6 +13567,7 @@ export {
|
|
|
10982
13567
|
liquidBuiltinFilters,
|
|
10983
13568
|
liquidEngine,
|
|
10984
13569
|
liquidTags,
|
|
13570
|
+
locateJsonPath,
|
|
10985
13571
|
mergeSampleData,
|
|
10986
13572
|
mergeSettings,
|
|
10987
13573
|
mergeSnippetCss,
|
|
@@ -11008,12 +13594,16 @@ export {
|
|
|
11008
13594
|
readJsreportExport,
|
|
11009
13595
|
regionChips,
|
|
11010
13596
|
regionItems,
|
|
13597
|
+
regionPosition,
|
|
11011
13598
|
renderOffice,
|
|
11012
13599
|
renderVersion,
|
|
13600
|
+
resolveEinvoiceOptions,
|
|
11013
13601
|
resolvePath,
|
|
11014
13602
|
resolveTranslation,
|
|
13603
|
+
resolveUa,
|
|
11015
13604
|
scanBlocks,
|
|
11016
13605
|
schemaPaths,
|
|
13606
|
+
shownAmounts,
|
|
11017
13607
|
slugFromName,
|
|
11018
13608
|
snippetText,
|
|
11019
13609
|
snippets,
|
|
@@ -11022,6 +13612,8 @@ export {
|
|
|
11022
13612
|
splitApitemplateCss,
|
|
11023
13613
|
starterDocument,
|
|
11024
13614
|
starterPresentation,
|
|
13615
|
+
staticAudit,
|
|
13616
|
+
staticAuditDiagnostics,
|
|
11025
13617
|
strftimeToDateFns,
|
|
11026
13618
|
svgDataUri,
|
|
11027
13619
|
toDate,
|