@tricoteuses/tisseuse 0.12.10 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/README.md +46 -0
  2. package/dist/index.js +143 -1397
  3. package/dist/server.js +2739 -158
  4. package/dist/src/lib/extractors/action_directives.d.ts +84 -22
  5. package/dist/src/lib/extractors/article_portions.d.ts +15 -1
  6. package/dist/src/lib/extractors/references.d.ts +3 -1
  7. package/dist/src/lib/extractors/table_of_contents.d.ts +2 -0
  8. package/dist/src/lib/f_legi/extractors/links.d.ts +134 -0
  9. package/dist/src/lib/f_legi/linkers/html.d.ts +51 -0
  10. package/dist/src/lib/f_legi/resolver.d.ts +54 -0
  11. package/dist/src/lib/index.d.ts +4 -3
  12. package/dist/src/lib/legi/canutes_resolver.d.ts +33 -0
  13. package/dist/src/lib/legi/resolver.d.ts +48 -0
  14. package/dist/src/lib/server/databases/index.d.ts +1 -1
  15. package/dist/src/lib/server/f_legi/databases/index.d.ts +2 -0
  16. package/dist/src/lib/server/f_legi/linkers/html.d.ts +20 -0
  17. package/dist/src/lib/server/index.d.ts +3 -0
  18. package/dist/src/lib/server/legi/resolvers.d.ts +10 -0
  19. package/dist/src/lib/server/parsed_bills.d.ts +105 -0
  20. package/dist/src/lib/server/parsed_bills.test.d.ts +1 -0
  21. package/dist/src/lib/test/text_titles_infos.d.ts +1 -0
  22. package/dist/src/lib/text_parsers/action_directives.d.ts +3 -0
  23. package/dist/src/lib/text_parsers/action_directives.test.d.ts +1 -0
  24. package/dist/src/lib/text_parsers/ast.d.ts +53 -1
  25. package/dist/src/lib/text_parsers/parsers.d.ts +2 -0
  26. package/dist/src/lib/text_parsers/texts.d.ts +1 -0
  27. package/dist/src/lib/timings.d.ts +19 -0
  28. package/dist/src/scripts/f_legi/add_links_to_html_document.d.ts +0 -0
  29. package/dist/src/scripts/parse_akoma_ntoso_bill_raw.d.ts +1 -0
  30. package/dist/src/scripts/parse_assemblee_bill_raw.d.ts +1 -0
  31. package/dist/{html-DAKCS7I8.js → textes-8dVwaLo9.js} +5161 -3078
  32. package/package.json +1 -1
package/dist/server.js CHANGED
@@ -1,9 +1,11 @@
1
- import { $ as e, a as t, g as n, gn as r, o as i, t as a } from "./html-DAKCS7I8.js";
2
- import * as o from "node:crypto";
3
- import s from "fs-extra";
4
- import c from "node:path";
1
+ import { $t as e, A as t, En as n, Jn as r, Kn as i, L as a, Xn as o, Yn as s, a as c, an as l, c as u, dt as d, fn as f, ft as p, g as m, in as h, l as g, lt as _, nt as v, pt as y, qn as b, rt as x, st as ee, t as S, u as C, x as te } from "./textes-8dVwaLo9.js";
2
+ import * as ne from "node:crypto";
3
+ import w from "fs-extra";
4
+ import T from "node:path";
5
+ import { fileURLToPath as re } from "node:url";
6
+ import ie from "postgres";
5
7
  //#region src/lib/alineas/alineas_numbers.ts
6
- var l = {
8
+ var ae = {
7
9
  "0150a855548f15a2af52ea057be53f5d": 1,
8
10
  "039826cf379b94afefe90b25c6045ca0": 1,
9
11
  "03a7e564b84662f4d957c51018e26244": 1,
@@ -18977,7 +18979,7 @@ var l = {
18977
18979
  d16d29c923bd60c7b095b66c6058fe60: 1664,
18978
18980
  "1c14c2adf5cfda3220b2057160e10e91": 1665,
18979
18981
  e44c55ca1ac46ff46420686a466c9fc6: 1665
18980
- }, u = "\np:has(.alinea) {\n margin: 0.6em 0;\n}\n.alinea {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n min-width: 1.5em;\n height: 1.5em;\n padding: 0 0.3em;\n margin-right: 0.3em;\n font-size: 0.75em;\n font-weight: bold;\n color: #555;\n background-color: #f0f0f0;\n border: 1px solid #ccc;\n border-radius: 1em;\n vertical-align: middle;\n}\n", d = "\nh1 {\n font-size: 1.8em;\n margin: 1em 0 0.5em 0;\n}\nh2 {\n font-size: 1.5em;\n margin: 0.9em 0 0.4em 0;\n}\nh3 {\n font-size: 1.3em;\n margin: 0.8em 0 0.4em 0;\n}\nh4 {\n font-size: 1.15em;\n margin: 0.7em 0 0.3em 0;\n}\nh5 {\n font-size: 1.05em;\n margin: 0.6em 0 0.3em 0;\n}\nh6 {\n font-size: 1em;\n margin: 0.5em 0 0.3em 0;\n}\n", f = "\n.expose-motifs-titre {\n font-size: 1.1em;\n font-weight: bold;\n color: #0070b9;\n margin: 1em 0 0.5em 0;\n}\n.expose-motifs {\n border-left: 3px solid #0070b9;\n padding-left: 1em;\n margin: 0.5em 0 1em 0;\n color: #333;\n}\n.expose-motifs p {\n margin: 0.5em 0;\n}\n", p = "\nol {\n list-style: none;\n padding-left: 0;\n margin: 0.5em 0;\n counter-reset: list-counter;\n}\nol > li {\n counter-increment: list-counter;\n margin: 0.3em 0;\n padding-left: 2.3em;\n position: relative;\n}\nol > li::before {\n content: counter(list-counter);\n display: inline-flex;\n align-items: center;\n justify-content: center;\n min-width: 1.5em;\n height: 1.5em;\n padding: 0 0.3em;\n font-size: 0.75em;\n font-weight: bold;\n color: #555;\n background-color: #f0f0f0;\n border: 1px solid #ccc;\n border-radius: 1em;\n position: absolute;\n left: 0;\n top: 0.1em;\n}\n", m = "\n.cover-title {\n font-size: 1.8em;\n font-weight: bold;\n color: #0070b9;\n text-align: center;\n margin: 1em 0;\n}\n.cover-subtitle {\n font-size: 1.4em;\n font-weight: bold;\n color: #0070b9;\n text-align: center;\n margin: 0.8em 0;\n}\n.cover-info {\n text-align: center;\n margin: 0.3em 0;\n color: #333;\n}\n.cover-year {\n font-size: 2em;\n font-weight: bold;\n color: #0070b9;\n text-align: center;\n margin: 1em 0;\n}\n", h = {
18982
+ }, oe = "\np:has(.alinea) {\n margin: 0.6em 0;\n}\n.alinea {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n min-width: 1.5em;\n height: 1.5em;\n padding: 0 0.3em;\n margin-right: 0.3em;\n font-size: 0.75em;\n font-weight: bold;\n color: #555;\n background-color: #f0f0f0;\n border: 1px solid #ccc;\n border-radius: 1em;\n vertical-align: middle;\n}\n", se = "\nh1 {\n font-size: 1.8em;\n margin: 1em 0 0.5em 0;\n}\nh2 {\n font-size: 1.5em;\n margin: 0.9em 0 0.4em 0;\n}\nh3 {\n font-size: 1.3em;\n margin: 0.8em 0 0.4em 0;\n}\nh4 {\n font-size: 1.15em;\n margin: 0.7em 0 0.3em 0;\n}\nh5 {\n font-size: 1.05em;\n margin: 0.6em 0 0.3em 0;\n}\nh6 {\n font-size: 1em;\n margin: 0.5em 0 0.3em 0;\n}\n", ce = "\n.expose-motifs-titre {\n font-size: 1.1em;\n font-weight: bold;\n color: #0070b9;\n margin: 1em 0 0.5em 0;\n}\n.expose-motifs {\n border-left: 3px solid #0070b9;\n padding-left: 1em;\n margin: 0.5em 0 1em 0;\n color: #333;\n}\n.expose-motifs p {\n margin: 0.5em 0;\n}\n", le = "\nol {\n list-style: none;\n padding-left: 0;\n margin: 0.5em 0;\n counter-reset: list-counter;\n}\nol > li {\n counter-increment: list-counter;\n margin: 0.3em 0;\n padding-left: 2.3em;\n position: relative;\n}\nol > li::before {\n content: counter(list-counter);\n display: inline-flex;\n align-items: center;\n justify-content: center;\n min-width: 1.5em;\n height: 1.5em;\n padding: 0 0.3em;\n font-size: 0.75em;\n font-weight: bold;\n color: #555;\n background-color: #f0f0f0;\n border: 1px solid #ccc;\n border-radius: 1em;\n position: absolute;\n left: 0;\n top: 0.1em;\n}\n", ue = "\n.cover-title {\n font-size: 1.8em;\n font-weight: bold;\n color: #0070b9;\n text-align: center;\n margin: 1em 0;\n}\n.cover-subtitle {\n font-size: 1.4em;\n font-weight: bold;\n color: #0070b9;\n text-align: center;\n margin: 0.8em 0;\n}\n.cover-info {\n text-align: center;\n margin: 0.3em 0;\n color: #333;\n}\n.cover-year {\n font-size: 2em;\n font-weight: bold;\n color: #0070b9;\n text-align: center;\n margin: 1em 0;\n}\n", de = {
18981
18983
  assnatetatagr: { bold: !0 },
18982
18984
  assnatetatagrgr: { bold: !0 },
18983
18985
  assnatetatatr: { bold: !0 },
@@ -19078,29 +19080,29 @@ var l = {
19078
19080
  assnatxl67: { align: "center" },
19079
19081
  assnatenteteequilibre: { align: "center" }
19080
19082
  };
19081
- function g(e) {
19082
- let t = Object.keys(h).sort((e, t) => t.length - e.length);
19083
- for (let n of t) if (e.includes(n)) return h[n];
19083
+ function fe(e) {
19084
+ let t = Object.keys(de).sort((e, t) => t.length - e.length);
19085
+ for (let n of t) if (e.includes(n)) return de[n];
19084
19086
  return null;
19085
19087
  }
19086
- function _(e) {
19087
- return o.createHash("md5").update(e).digest("hex");
19088
+ function pe(e) {
19089
+ return ne.createHash("md5").update(e).digest("hex");
19088
19090
  }
19089
- function v(e) {
19091
+ function me(e) {
19090
19092
  return e ? /font-weight\s*:\s*(bold|[6-9]00|1000)/i.test(e) || /font-family\s*:\s*[^;]*\bBold\b/i.test(e) : !1;
19091
19093
  }
19092
- function y(e) {
19094
+ function he(e) {
19093
19095
  return e ? /font-style\s*:\s*italic/i.test(e) || /font-family\s*:\s*[^;]*\bItalic\b/i.test(e) : !1;
19094
19096
  }
19095
- function b(e) {
19097
+ function ge(e) {
19096
19098
  if (!e || !/vertical-align\s*:\s*super/i.test(e)) return !1;
19097
19099
  let t = e.match(/font-size\s*:\s*([\d.]+)pt/i);
19098
19100
  return !(t && parseFloat(t[1]) < 8);
19099
19101
  }
19100
- function x(e) {
19102
+ function _e(e) {
19101
19103
  return e ? /vertical-align\s*:\s*sub/i.test(e) : !1;
19102
19104
  }
19103
- function S(e) {
19105
+ function ve(e) {
19104
19106
  if (!e) return;
19105
19107
  let t = [
19106
19108
  "width",
@@ -19135,15 +19137,15 @@ function S(e) {
19135
19137
  }
19136
19138
  return n.length > 0 ? n.join("; ") : void 0;
19137
19139
  }
19138
- function C(e, t) {
19140
+ function ye(e, t) {
19139
19141
  return !!(e && /text-align\s*:\s*center/i.test(e) || t && /center/i.test(t));
19140
19142
  }
19141
- function w(e) {
19143
+ function be(e) {
19142
19144
  if (!e) return null;
19143
19145
  let t = e.match(/text-align\s*:\s*(left|center|right|justify)/i);
19144
19146
  return t ? t[1].toLowerCase() : null;
19145
19147
  }
19146
- function T(e) {
19148
+ function xe(e) {
19147
19149
  if (!e) return null;
19148
19150
  for (let [t, n] of [
19149
19151
  [/assnat1Tome|assnatAN1PARTIE/i, 1],
@@ -19155,73 +19157,73 @@ function T(e) {
19155
19157
  ]) if (t.test(e)) return n;
19156
19158
  return null;
19157
19159
  }
19158
- function E(t, n = {}) {
19159
- let { keepAlignment: r = !0, removeEmptyParagraphs: i = !0, strictAlineas: a = !1 } = n, o = e(t, { xml: { decodeEntities: !1 } });
19160
- o("style, script, meta, link").remove(), o(".assnatHeader, .assnatFooter, .assnatHeaderLeft, .assnatHeaderandFooter").remove(), o(".assnatFARSautApres, .assnatFARSautAvant, .assnatFARSautPageNiv0, .assnatFARSautPageNiv1, .assnatFARSautPageNiv1PG").remove(), o(".assnatFARTT08Bleu").each((e, t) => {
19161
- let n = o(t).closest("table");
19160
+ function Se(e, t = {}) {
19161
+ let { keepAlignment: n = !0, removeEmptyParagraphs: r = !0, strictAlineas: i = !1 } = t, a = y(e, { xml: { decodeEntities: !1 } });
19162
+ a("style, script, meta, link").remove(), a(".assnatHeader, .assnatFooter, .assnatHeaderLeft, .assnatHeaderandFooter").remove(), a(".assnatFARSautApres, .assnatFARSautAvant, .assnatFARSautPageNiv0, .assnatFARSautPageNiv1, .assnatFARSautPageNiv1PG").remove(), a(".assnatFARTT08Bleu").each((e, t) => {
19163
+ let n = a(t).closest("table");
19162
19164
  n.length > 0 && n.remove();
19163
- }), o("table").each((e, t) => {
19164
- let n = o(t), r = n.find("> tbody > tr, > tr");
19165
+ }), a("table").each((e, t) => {
19166
+ let n = a(t), r = n.find("> tbody > tr, > tr");
19165
19167
  if (r.length !== 1) return;
19166
19168
  let i = r.find("> td, > th");
19167
19169
  if (i.length !== 1) return;
19168
- let a = i.first();
19169
- if (a.find("h1, h2, h3, h4, h5, h6").length > 0) {
19170
- let e = a.attr("style") || "";
19171
- (e.includes("border-left:") || e.includes("border-bottom:")) && n.replaceWith(a.html() || "");
19170
+ let o = i.first();
19171
+ if (o.find("h1, h2, h3, h4, h5, h6").length > 0) {
19172
+ let e = o.attr("style") || "";
19173
+ (e.includes("border-left:") || e.includes("border-bottom:")) && n.replaceWith(o.html() || "");
19172
19174
  }
19173
- }), o("br[style*=\"page-break\"]").remove(), o("span[style*=\"position:absolute\"][style*=\"z-index:-65537\"]").each((e, t) => {
19174
- let n = o(t), r = n.find("img");
19175
+ }), a("br[style*=\"page-break\"]").remove(), a("span[style*=\"position:absolute\"][style*=\"z-index:-65537\"]").each((e, t) => {
19176
+ let n = a(t), r = n.find("img");
19175
19177
  if (r.length > 0) {
19176
19178
  let e = parseInt(r.attr("width") || "0", 10), t = parseInt(r.attr("height") || "0", 10);
19177
19179
  (e >= 50 || t >= 50) && n.remove();
19178
19180
  }
19179
- }), o("span[style*=\"position:absolute\"]").each((e, t) => {
19180
- let n = o(t), r = n.attr("style") || "", i = n.find("img");
19181
+ }), a("span[style*=\"position:absolute\"]").each((e, t) => {
19182
+ let n = a(t), r = n.attr("style") || "", i = n.find("img");
19181
19183
  if (i.length !== 0 && !(n.parents("del").length > 0 || n.find("del img").length > 0) && !(i.parent("del").length > 0)) {
19182
19184
  let e = i.attr();
19183
19185
  if (e && (e.width === "45" && (e.height === "31" || e.height === "30") || parseInt(e.width || "0", 10) < 50 && parseInt(e.height || "0", 10) < 50) && r.includes("position:absolute")) {
19184
- let t = (e.src || "").match(/^data:image\/png;base64,(.+)$/), r = t ? _(t[1]) : void 0, i = r ? ` data-image-hash="${r}"` : "";
19186
+ let t = (e.src || "").match(/^data:image\/png;base64,(.+)$/), r = t ? pe(t[1]) : void 0, i = r ? ` data-image-hash="${r}"` : "";
19185
19187
  n.replaceWith(`<span class="alinea"${i}></span>`);
19186
19188
  return;
19187
19189
  }
19188
19190
  }
19189
- }), o("span[style*=\"position:absolute\"]").each((e, t) => {
19190
- let n = o(t), r = n.attr("style") || "", i = n.find("img");
19191
+ }), a("span[style*=\"position:absolute\"]").each((e, t) => {
19192
+ let n = a(t), r = n.attr("style") || "", i = n.find("img");
19191
19193
  if (i.length > 0 && n.children().length === 1 && r.includes("height:0pt")) {
19192
19194
  let e = parseInt(i.attr("width") || "0", 10), t = parseInt(i.attr("height") || "0", 10);
19193
19195
  e < 100 || t < 100 ? n.remove() : n.replaceWith(i);
19194
19196
  }
19195
- }), o("img").each((e, t) => {
19196
- let n = o(t), r = parseInt(n.attr("width") || "0", 10), i = parseInt(n.attr("height") || "0", 10);
19197
+ }), a("img").each((e, t) => {
19198
+ let n = a(t), r = parseInt(n.attr("width") || "0", 10), i = parseInt(n.attr("height") || "0", 10);
19197
19199
  r < 100 || i < 100 ? n.remove() : n.removeAttr("style").removeAttr("class");
19198
- }), o("span[style*=\"height:0pt\"]:not(.alinea)").each((e, t) => {
19199
- let n = o(t), r = n.text().trim();
19200
+ }), a("span[style*=\"height:0pt\"]:not(.alinea)").each((e, t) => {
19201
+ let n = a(t), r = n.text().trim();
19200
19202
  (!r || r === "\xA0") && n.remove();
19201
- }), o("span[style*=\"display:block\"][style*=\"position:absolute\"]:not(.alinea)").remove(), o("del").remove();
19202
- function s(e) {
19203
- let t = o(e), n = t.attr("style"), r = e.tagName?.toLowerCase() || "", i = v(n) || r === "b" || r === "strong", a = y(n) || r === "i" || r === "em", s = b(n) || r === "sup", c = x(n) || r === "sub", l = t.attr("class") || "";
19204
- return /bold/i.test(l) && (i = !0), /strongemphasis/i.test(l) ? i = !0 : /italic|emphasis/i.test(l) && (a = !0), {
19203
+ }), a("span[style*=\"display:block\"][style*=\"position:absolute\"]:not(.alinea)").remove(), a("del").remove();
19204
+ function o(e) {
19205
+ let t = a(e), n = t.attr("style"), r = e.tagName?.toLowerCase() || "", i = me(n) || r === "b" || r === "strong", o = he(n) || r === "i" || r === "em", s = ge(n) || r === "sup", c = _e(n) || r === "sub", l = t.attr("class") || "";
19206
+ return /bold/i.test(l) && (i = !0), /strongemphasis/i.test(l) ? i = !0 : /italic|emphasis/i.test(l) && (o = !0), {
19205
19207
  bold: i,
19206
- italic: a,
19208
+ italic: o,
19207
19209
  sup: s,
19208
19210
  sub: c
19209
19211
  };
19210
19212
  }
19211
- function c(e, t) {
19213
+ function s(e, t) {
19212
19214
  let n = e;
19213
19215
  return t.sup ? n = `<sup>${n}</sup>` : t.sub && (n = `<sub>${n}</sub>`), t.italic && (n = `<em>${n}</em>`), t.bold && (n = `<strong>${n}</strong>`), n;
19214
19216
  }
19215
- let l = o("span").length;
19216
- for (; l > 0;) {
19217
- o("span").each((e, t) => {
19218
- let n = o(t), r = n.attr("style") || "", i = n.attr("class") || "", a = s(t), l = a.bold || a.italic || a.sup || a.sub, u = /vertical-align\s*:\s*super/i.test(r) && /font-size\s*:\s*([\d.]+)pt/i.test(r) && parseFloat((r.match(/font-size\s*:\s*([\d.]+)pt/i) || ["", "12"])[1]) < 8, d = i && !/^assnat/i.test(i), f = n.attr("id");
19217
+ let c = a("span").length;
19218
+ for (; c > 0;) {
19219
+ a("span").each((e, t) => {
19220
+ let n = a(t), r = n.attr("style") || "", i = n.attr("class") || "", c = o(t), l = c.bold || c.italic || c.sup || c.sub, u = /vertical-align\s*:\s*super/i.test(r) && /font-size\s*:\s*([\d.]+)pt/i.test(r) && parseFloat((r.match(/font-size\s*:\s*([\d.]+)pt/i) || ["", "12"])[1]) < 8, d = i && !/^assnat/i.test(i), f = n.attr("id");
19219
19221
  if (u) {
19220
19222
  let e = n.html() || "";
19221
19223
  n.replaceWith(e);
19222
19224
  } else if (l) {
19223
19225
  let e = n.html() || "";
19224
- n.replaceWith(c(e, a));
19226
+ n.replaceWith(s(e, c));
19225
19227
  } else if (d) n.removeAttr("style");
19226
19228
  else if (f) n.removeAttr("style").removeAttr("class");
19227
19229
  else {
@@ -19229,76 +19231,76 @@ function E(t, n = {}) {
19229
19231
  e.trim() === "" && e.length > 0 ? n.replaceWith(" ") : n.replaceWith(e);
19230
19232
  }
19231
19233
  });
19232
- let e = o("span").length;
19233
- if (e >= l) break;
19234
- l = e;
19234
+ let e = a("span").length;
19235
+ if (e >= c) break;
19236
+ c = e;
19235
19237
  }
19236
- for (o("p").each((e, t) => {
19237
- let n = o(t), i = n.attr("class") || "", a = n.attr("style"), s = T(i);
19238
+ for (a("p").each((e, t) => {
19239
+ let r = a(t), i = r.attr("class") || "", o = r.attr("style"), s = xe(i);
19238
19240
  if (i.includes("assnatFARCouvTitreD")) {
19239
- let e = n.html() || "";
19240
- n.replaceWith(`<p class="cover-subtitle">${e}</p>`);
19241
+ let e = r.html() || "";
19242
+ r.replaceWith(`<p class="cover-subtitle">${e}</p>`);
19241
19243
  return;
19242
19244
  }
19243
19245
  if (i.includes("assnatFARCouvTitre")) {
19244
- let e = n.html() || "";
19245
- n.replaceWith(`<p class="cover-title">${e}</p>`);
19246
+ let e = r.html() || "";
19247
+ r.replaceWith(`<p class="cover-title">${e}</p>`);
19246
19248
  return;
19247
19249
  }
19248
19250
  if (i.includes("assnatFPFprem")) {
19249
- let e = n.html() || "";
19250
- n.replaceWith(`<p class="cover-info">${e}</p>`);
19251
+ let e = r.html() || "";
19252
+ r.replaceWith(`<p class="cover-info">${e}</p>`);
19251
19253
  return;
19252
19254
  }
19253
19255
  if (i.includes("assnatFARCouvAnnee")) {
19254
- let e = n.html() || "";
19255
- n.replaceWith(`<p class="cover-year">${e}</p>`);
19256
+ let e = r.html() || "";
19257
+ r.replaceWith(`<p class="cover-year">${e}</p>`);
19256
19258
  return;
19257
19259
  }
19258
19260
  if (i.includes("assnatFPFexpogentitre1")) {
19259
- let e = n.html() || "";
19260
- n.replaceWith(`<p class="expose-motifs-titre">${e}</p>`);
19261
+ let e = r.html() || "";
19262
+ r.replaceWith(`<p class="expose-motifs-titre">${e}</p>`);
19261
19263
  return;
19262
19264
  }
19263
19265
  if (i.includes("assnatFPFexpogentexte")) {
19264
- n.removeAttr("style").attr("class", "expose-motifs-text");
19266
+ r.removeAttr("style").attr("class", "expose-motifs-text");
19265
19267
  return;
19266
19268
  }
19267
- let c = n.text().trim().startsWith("«");
19269
+ let c = r.text().trim().startsWith("«");
19268
19270
  if (s && !c) {
19269
- let e = o(`<h${s}>${n.html() || ""}</h${s}>`);
19270
- r && C(a, i) && e.attr("align", "center"), n.replaceWith(e);
19271
+ let e = a(`<h${s}>${r.html() || ""}</h${s}>`);
19272
+ n && ye(o, i) && e.attr("align", "center"), r.replaceWith(e);
19271
19273
  } else {
19272
- let e = g(i), t;
19273
- if (r) {
19274
- let n = w(a);
19274
+ let e = fe(i), t;
19275
+ if (n) {
19276
+ let n = be(o);
19275
19277
  n && n !== "justify" && n !== "left" ? t = n : e?.align && (t = e.align);
19276
19278
  }
19277
- if (n.removeAttr("style").removeAttr("class"), t && n.attr("align", t), e?.bold) {
19278
- let e = n.html() || "";
19279
- e.trim().startsWith("<strong>") || n.html(`<strong>${e}</strong>`);
19279
+ if (r.removeAttr("style").removeAttr("class"), t && r.attr("align", t), e?.bold) {
19280
+ let e = r.html() || "";
19281
+ e.trim().startsWith("<strong>") || r.html(`<strong>${e}</strong>`);
19280
19282
  }
19281
19283
  }
19282
- }), o("h1, h2, h3, h4, h5, h6").each((e, t) => {
19283
- let n = o(t), i = n.attr("style"), a = n.attr("class");
19284
- r && C(i, a) ? (n.removeAttr("style").removeAttr("class"), n.attr("align", "center")) : n.removeAttr("style").removeAttr("class");
19285
- }), o("a").each((e, t) => {
19286
- let n = o(t), r = n.attr("href"), i = n.attr("id"), a = { ...t.attribs || {} };
19287
- for (let e of Object.keys(a)) e !== "href" && e !== "id" && n.removeAttr(e);
19284
+ }), a("h1, h2, h3, h4, h5, h6").each((e, t) => {
19285
+ let r = a(t), i = r.attr("style"), o = r.attr("class");
19286
+ n && ye(i, o) ? (r.removeAttr("style").removeAttr("class"), r.attr("align", "center")) : r.removeAttr("style").removeAttr("class");
19287
+ }), a("a").each((e, t) => {
19288
+ let n = a(t), r = n.attr("href"), i = n.attr("id"), o = { ...t.attribs || {} };
19289
+ for (let e of Object.keys(o)) e !== "href" && e !== "id" && n.removeAttr(e);
19288
19290
  if (!r && !i) n.replaceWith(n.html() || "");
19289
19291
  else if (!r && i) {
19290
19292
  let e = n.html() || "";
19291
19293
  n.replaceWith(`<span id="${i}">${e}</span>`);
19292
19294
  }
19293
- }); o("div").length > 0;) o("div").each((e, t) => {
19294
- let n = o(t), r = n.html() || "";
19295
+ }); a("div").length > 0;) a("div").each((e, t) => {
19296
+ let n = a(t), r = n.html() || "";
19295
19297
  n.replaceWith(r);
19296
19298
  });
19297
- o(".expose-motifs-titre").each((e, t) => {
19298
- let n = o(t), r = [], i = n.next();
19299
+ a(".expose-motifs-titre").each((e, t) => {
19300
+ let n = a(t), r = [], i = n.next();
19299
19301
  for (; i.length > 0;) if (i.is("table") && i.find(".expose-motifs-text").length > 0) {
19300
19302
  i.find(".expose-motifs-text").each((e, t) => {
19301
- r.push(o(t).clone());
19303
+ r.push(a(t).clone());
19302
19304
  });
19303
19305
  let e = i;
19304
19306
  i = i.next(), e.remove();
@@ -19312,43 +19314,43 @@ function E(t, n = {}) {
19312
19314
  i = i.next(), e.remove();
19313
19315
  } else break;
19314
19316
  if (r.length > 0) {
19315
- let e = o("<div class=\"expose-motifs\"></div>");
19317
+ let e = a("<div class=\"expose-motifs\"></div>");
19316
19318
  r.forEach((t) => {
19317
19319
  t.removeClass("expose-motifs-text"), e.append(t);
19318
19320
  }), n.after(e);
19319
19321
  }
19320
- }), o("br").each((e, t) => {
19321
- o(t).removeAttr("style").removeAttr("class");
19322
- }), o("table, tr, td, th, thead, tbody, tfoot").each((e, t) => {
19323
- let n = o(t), r = S(n.attr("style"));
19322
+ }), a("br").each((e, t) => {
19323
+ a(t).removeAttr("style").removeAttr("class");
19324
+ }), a("table, tr, td, th, thead, tbody, tfoot").each((e, t) => {
19325
+ let n = a(t), r = ve(n.attr("style"));
19324
19326
  n.removeAttr("style").removeAttr("class"), r && n.attr("style", r);
19325
- }), o("td, th").each((e, t) => {
19326
- let n = o(t), r = n.children();
19327
+ }), a("td, th").each((e, t) => {
19328
+ let n = a(t), r = n.children();
19327
19329
  if (r.length === 1 && r.first().is("p")) {
19328
- let e = r.first(), t = n.html() || "", i = o.html(e);
19330
+ let e = r.first(), t = n.html() || "", i = a.html(e);
19329
19331
  if (t.trim() === i.trim()) {
19330
19332
  let t = e.attr("align"), r = e.attr("id");
19331
19333
  n.html(e.html() || ""), t && !n.attr("align") && n.attr("align", t), r && !n.attr("id") && n.attr("id", r);
19332
19334
  }
19333
19335
  }
19334
- }), o("ol, ul").each((e, t) => {
19335
- let n = o(t), r = n.attr("start");
19336
+ }), a("ol, ul").each((e, t) => {
19337
+ let n = a(t), r = n.attr("start");
19336
19338
  if (n.removeAttr("style").removeAttr("class"), r) {
19337
19339
  let e = parseInt(r, 10);
19338
19340
  !isNaN(e) && e > 1 && n.attr("style", `counter-reset: list-counter ${e - 1}`), n.attr("start", r);
19339
19341
  }
19340
- }), o("li").each((e, t) => {
19341
- let n = o(t), r = w(n.attr("style"));
19342
+ }), a("li").each((e, t) => {
19343
+ let n = a(t), r = be(n.attr("style"));
19342
19344
  n.removeAttr("style").removeAttr("class"), r === "center" && n.attr("style", "text-align: center");
19343
- let i = n.html() || "", a = i.replace(/^(\s|&#xa0;|&#160;|\u00a0)+/, "");
19344
- a !== i && n.html(a);
19345
- }), D(o), O(o, a);
19346
- let h = o("body").html() || o.html(), E = h.includes("class=\"alinea"), A = o("ol").length > 0, j = o("h1, h2, h3, h4, h5, h6").length > 0, M = h.includes("class=\"expose-motifs"), N = h.includes("class=\"cover-title\"") || h.includes("class=\"cover-subtitle\"") || h.includes("class=\"cover-info\"") || h.includes("class=\"cover-year\""), P = "";
19347
- N && (P += m), j && (P += d), M && (P += f), E && (P += u), A && (P += p);
19348
- let F = P ? `<style>${P}</style>\n${h}` : h;
19349
- return F = F.replace(/>\s+</g, "> <").replace(/\r\n/g, "\n").replace(/\r/g, "\n").replace(/\n{3,}/g, "\n\n").split("\n").map((e) => e.trim()).filter((e) => e.length > 0).join("\n"), F = F.replace(/&nbsp;/g, "\xA0"), i && (F = F.replace(/<p[^>]*>\s*(&nbsp;|&#xa0;|&#160;|\u00a0|\s)*\s*<\/p>/gi, "").replace(/<p[^>]*>\s*<(strong|em|b|i)>\s*(&nbsp;|&#xa0;|&#160;|\u00a0|\s)*\s*<\/\1>\s*<\/p>/gi, "")), F = F.replace(/<span[^>]*>\s*<\/span>/gi, ""), F = F.replace(/ class=""/g, ""), F = k(F), F = F.replace(/<(strong|em|b|i|sup|sub)>\s*(&nbsp;|&#xa0;|&#160;|\u00a0|\s)*\s*<\/\1>/gi, "").replace(/<(strong|em|b|i)>(&nbsp;|&#xa0;|&#160;|\u00a0)+<\/\1>/gi, " ").replace(/<br\s*\/?>/gi, "<br/>").replace(/ +/g, " ").trim(), F;
19345
+ let i = n.html() || "", o = i.replace(/^(\s|&#xa0;|&#160;|\u00a0)+/, "");
19346
+ o !== i && n.html(o);
19347
+ }), Ce(a), we(a, i);
19348
+ let l = a("body").html() || a.html(), u = l.includes("class=\"alinea"), d = a("ol").length > 0, f = a("h1, h2, h3, h4, h5, h6").length > 0, p = l.includes("class=\"expose-motifs"), m = l.includes("class=\"cover-title\"") || l.includes("class=\"cover-subtitle\"") || l.includes("class=\"cover-info\"") || l.includes("class=\"cover-year\""), h = "";
19349
+ m && (h += ue), f && (h += se), p && (h += ce), u && (h += oe), d && (h += le);
19350
+ let g = h ? `<style>${h}</style>\n${l}` : l;
19351
+ return g = g.replace(/>\s+</g, "> <").replace(/\r\n/g, "\n").replace(/\r/g, "\n").replace(/\n{3,}/g, "\n\n").split("\n").map((e) => e.trim()).filter((e) => e.length > 0).join("\n"), g = g.replace(/&nbsp;/g, "\xA0"), r && (g = g.replace(/<p[^>]*>\s*(&nbsp;|&#xa0;|&#160;|\u00a0|\s)*\s*<\/p>/gi, "").replace(/<p[^>]*>\s*<(strong|em|b|i)>\s*(&nbsp;|&#xa0;|&#160;|\u00a0|\s)*\s*<\/\1>\s*<\/p>/gi, "")), g = g.replace(/<span[^>]*>\s*<\/span>/gi, ""), g = g.replace(/ class=""/g, ""), g = Te(g), g = g.replace(/<(strong|em|b|i|sup|sub)>\s*(&nbsp;|&#xa0;|&#160;|\u00a0|\s)*\s*<\/\1>/gi, "").replace(/<(strong|em|b|i)>(&nbsp;|&#xa0;|&#160;|\u00a0)+<\/\1>/gi, " ").replace(/<br\s*\/?>/gi, "<br/>").replace(/ +/g, " ").trim(), g;
19350
19352
  }
19351
- function D(e) {
19353
+ function Ce(e) {
19352
19354
  e("span[id]").each((t, n) => {
19353
19355
  let r = e(n), i = r.attr("id"), a = n.attribs || {}, o = Object.keys(a);
19354
19356
  if (o.length !== 1 || o[0] !== "id") return;
@@ -19371,13 +19373,13 @@ function D(e) {
19371
19373
  l.trim() === u.trim() && (s.attr("id", i), r.replaceWith(r.html() || ""));
19372
19374
  });
19373
19375
  }
19374
- function O(e, t = !1) {
19376
+ function we(e, t = !1) {
19375
19377
  let n = e("body");
19376
19378
  if (n.length === 0) return;
19377
19379
  let r = n.find("span.alinea[data-image-hash]"), i = -1;
19378
19380
  r.each((n, r) => {
19379
19381
  let a = e(r), o = a.attr("data-image-hash"), s;
19380
- if (o && l[o] !== void 0 && (s = l[o]), s === void 0) {
19382
+ if (o && ae[o] !== void 0 && (s = ae[o]), s === void 0) {
19381
19383
  if (t) throw Error(`Missing alinea number mapping for image hash: "${o}". Please extract images, review them, and update the mapping in "src/lib/alineas/alineas_numbers.ts".`);
19382
19384
  a.remove();
19383
19385
  return;
@@ -19389,11 +19391,11 @@ function O(e, t = !1) {
19389
19391
  i = s, a.attr("data-alinea", String(s)), a.text(String(s)), a.removeAttr("data-image-hash");
19390
19392
  });
19391
19393
  }
19392
- function k(e) {
19394
+ function Te(e) {
19393
19395
  let t = e;
19394
19396
  return t = t.replace(/<\/strong>(\s*)<strong>/gi, "$1"), t = t.replace(/<\/em>(\s*)<em>/gi, "$1"), t = t.replace(/<\/sup>(\s*)<sup>/gi, "$1"), t = t.replace(/<\/sub>(\s*)<sub>/gi, "$1"), t;
19395
19397
  }
19396
- function A(e, t = {}) {
19398
+ function Ee(e, t = {}) {
19397
19399
  return `<!DOCTYPE html>
19398
19400
  <html lang="fr">
19399
19401
  <head>
@@ -19401,33 +19403,33 @@ function A(e, t = {}) {
19401
19403
  <title>Document simplifié</title>
19402
19404
  </head>
19403
19405
  <body>
19404
- ${E(e, t)}
19406
+ ${Se(e, t)}
19405
19407
  </body>
19406
19408
  </html>`;
19407
19409
  }
19408
19410
  //#endregion
19409
19411
  //#region src/lib/server/text_parsers/transformers.ts
19410
- function j(e, t) {
19412
+ function E(e, t) {
19411
19413
  let n = "transformation_", r = {};
19412
- for (let e of s.readdirSync(t).toSorted()) if (e.startsWith(n) && e.endsWith(".json")) {
19414
+ for (let e of w.readdirSync(t).toSorted()) if (e.startsWith(n) && e.endsWith(".json")) {
19413
19415
  let i = e.slice(15, -5), a = i.split(".").map((e) => parseInt(e) - 1), o = r;
19414
19416
  for (let e of a.slice(1)) {
19415
19417
  let t = o.transformations ??= [];
19416
19418
  for (; e >= t.length;) t.push({});
19417
19419
  o = t[e];
19418
19420
  }
19419
- o.output = s.readFileSync(c.join(t, `${n}${i}.html`), { encoding: "utf-8" });
19420
- let { sourceMap: l, title: u } = s.readJsonSync(c.join(t, e), { encoding: "utf-8" });
19421
- o.sourceMap = l ?? [], o.title = u;
19421
+ o.output = w.readFileSync(T.join(t, `${n}${i}.html`), { encoding: "utf-8" });
19422
+ let { sourceMap: s, title: c } = w.readJsonSync(T.join(t, e), { encoding: "utf-8" });
19423
+ o.sourceMap = s ?? [], o.title = c;
19422
19424
  }
19423
- return M(r, e), r;
19425
+ return De(r, e), r;
19424
19426
  }
19425
- function M(e, t) {
19426
- if (e.input = t, e.transformations !== void 0) for (let n of e.transformations) M(n, t), t = n.output;
19427
+ function De(e, t) {
19428
+ if (e.input = t, e.transformations !== void 0) for (let n of e.transformations) De(n, t), t = n.output;
19427
19429
  return t;
19428
19430
  }
19429
- function N(e, t, n = "1") {
19430
- if (s.ensureDirSync(t), e.transformations === void 0) s.writeJsonSync(c.join(t, `transformation_${n}.json`), {
19431
+ function D(e, t, n = "1") {
19432
+ if (w.ensureDirSync(t), e.transformations === void 0) w.writeJsonSync(T.join(t, `transformation_${n}.json`), {
19431
19433
  sourceMap: e.sourceMap,
19432
19434
  title: e.title
19433
19435
  }, {
@@ -19435,65 +19437,2644 @@ function N(e, t, n = "1") {
19435
19437
  spaces: 2
19436
19438
  });
19437
19439
  else {
19438
- s.writeJsonSync(c.join(t, `transformation_${n}.json`), { title: e.title }, {
19440
+ w.writeJsonSync(T.join(t, `transformation_${n}.json`), { title: e.title }, {
19439
19441
  encoding: "utf-8",
19440
19442
  spaces: 2
19441
19443
  });
19442
- for (let [r, i] of e.transformations.entries()) N(i, t, `${n}.${r + 1}`);
19444
+ for (let [r, i] of e.transformations.entries()) D(i, t, `${n}.${r + 1}`);
19443
19445
  }
19444
- e.output !== void 0 && s.writeFileSync(c.join(t, `transformation_${n}.html`), e.output, { encoding: "utf-8" });
19446
+ e.output !== void 0 && w.writeFileSync(T.join(t, `transformation_${n}.html`), e.output, { encoding: "utf-8" });
19445
19447
  }
19446
19448
  //#endregion
19447
19449
  //#region src/lib/server/linkers/html.ts
19448
- async function P({ canutesDb: e, date: t, defaultTextId: r, htmlFilePath: i, htmlTransformationsInputDir: o, htmlTransformationsOutputDir: c, htmlWithLinksFilePath: l, htmlWithLinksOrReferencesFilePath: u, htmlWithLinksTransformationsOutputDir: d, htmlWithReferencesFilePath: f, linkBaseUrl: p, linkType: m, logIgnoredReferencesTypes: h, logPartialReferences: g, logReferences: _, referredLegifranceTextsInfosFilePath: v }) {
19449
- let y = await s.readFile(i, { encoding: "utf-8" }), b;
19450
- o === void 0 ? (b = n({ removeAWithHref: !0 })(y), c !== void 0 && N(b, c)) : b = j(y, o);
19451
- let x = [];
19452
- l !== void 0 && x.push("links"), u !== void 0 && x.push("links_or_references"), f !== void 0 && x.push("references");
19453
- let { outputByType: S, referredLegifranceTextCountByCid: C } = await a({
19450
+ async function Oe({ canutesDb: e, date: t, defaultTextId: n, htmlFilePath: r, htmlTransformationsInputDir: i, htmlTransformationsOutputDir: a, htmlWithLinksFilePath: o, htmlWithLinksOrReferencesFilePath: s, htmlWithLinksTransformationsOutputDir: l, htmlWithReferencesFilePath: u, linkBaseUrl: d, linkType: f, logIgnoredReferencesTypes: p, logPartialReferences: m, logReferences: h, referredLegifranceTextsInfosFilePath: g }) {
19451
+ let _ = await w.readFile(r, { encoding: "utf-8" }), y;
19452
+ i === void 0 ? (y = v({ removeAWithHref: !0 })(_), a !== void 0 && D(y, a)) : y = E(_, i);
19453
+ let b = [];
19454
+ o !== void 0 && b.push("links"), s !== void 0 && b.push("links_or_references"), u !== void 0 && b.push("references");
19455
+ let { outputByType: x, referredLegifranceTextCountByCid: ee } = await c({
19454
19456
  canutesDb: e,
19455
19457
  date: t,
19456
- defaultTextId: r,
19457
- htmlTransformation: b,
19458
- inputHtml: y,
19459
- linkBaseUrl: p,
19460
- linkType: m,
19461
- logIgnoredReferencesTypes: h,
19462
- logPartialReferences: g,
19463
- logReferences: _,
19464
- outputTypes: x,
19465
- referredLegifranceTextsInfos: v !== void 0
19466
- }), w = {};
19467
- l !== void 0 && (w.links = l), u !== void 0 && (w.links_or_references = u), f !== void 0 && (w.references = f);
19468
- for (let [e, t] of Object.entries(S)) {
19469
- let n = w[e];
19470
- n !== void 0 && await s.writeFile(n, t.html, { encoding: "utf-8" });
19458
+ defaultTextId: n,
19459
+ htmlTransformation: y,
19460
+ inputHtml: _,
19461
+ linkBaseUrl: d,
19462
+ linkType: f,
19463
+ logIgnoredReferencesTypes: p,
19464
+ logPartialReferences: m,
19465
+ logReferences: h,
19466
+ outputTypes: b,
19467
+ referredLegifranceTextsInfos: g !== void 0
19468
+ }), S = {};
19469
+ o !== void 0 && (S.links = o), s !== void 0 && (S.links_or_references = s), u !== void 0 && (S.references = u);
19470
+ for (let [e, t] of Object.entries(x)) {
19471
+ let n = S[e];
19472
+ n !== void 0 && await w.writeFile(n, t.html, { encoding: "utf-8" });
19471
19473
  }
19472
- S.links !== void 0 && d !== void 0 && N(n()(S.links.html), d), v !== void 0 && await s.writeJson(v, C, {
19474
+ x.links !== void 0 && l !== void 0 && D(v()(x.links.html), l), g !== void 0 && await w.writeJson(g, ee, {
19473
19475
  encoding: "utf-8",
19474
19476
  spaces: 2
19475
19477
  });
19476
19478
  }
19477
19479
  //#endregion
19480
+ //#region src/lib/timings.ts
19481
+ var O = class {
19482
+ label;
19483
+ enabled;
19484
+ metrics = [];
19485
+ startedAt = performance.now();
19486
+ constructor(e, t = ke()) {
19487
+ this.label = e, this.enabled = t;
19488
+ }
19489
+ add(e) {
19490
+ this.enabled && this.metrics.push(e);
19491
+ }
19492
+ async time(e, t, n) {
19493
+ if (!this.enabled) return t();
19494
+ let r = performance.now();
19495
+ try {
19496
+ return await t();
19497
+ } finally {
19498
+ this.add({
19499
+ ...n,
19500
+ durationMs: Math.round((performance.now() - r) * 10) / 10,
19501
+ phase: e
19502
+ });
19503
+ }
19504
+ }
19505
+ timeSync(e, t, n) {
19506
+ if (!this.enabled) return t();
19507
+ let r = performance.now();
19508
+ try {
19509
+ return t();
19510
+ } finally {
19511
+ this.add({
19512
+ ...n,
19513
+ durationMs: Math.round((performance.now() - r) * 10) / 10,
19514
+ phase: e
19515
+ });
19516
+ }
19517
+ }
19518
+ log(e) {
19519
+ if (!this.enabled) return;
19520
+ let t = Math.round((performance.now() - this.startedAt) * 10) / 10;
19521
+ console.info(`[timings:${this.label}]`, JSON.stringify({
19522
+ ...e,
19523
+ totalMs: t,
19524
+ metricCount: this.metrics.length,
19525
+ metrics: this.metrics
19526
+ }, null, 2));
19527
+ }
19528
+ };
19529
+ function ke() {
19530
+ let e = globalThis.process?.env;
19531
+ return e?.PJL_BUILD_TIMINGS === "1" || e?.PJL_BUILD_TIMINGS === "true";
19532
+ }
19533
+ //#endregion
19534
+ //#region src/lib/f_legi/extractors/links.ts
19535
+ async function* Ae({ context: e, date: t, flegiResolver: n, logIgnoredReferencesTypes: r, logPartialReferences: i, logReferences: a, state: o, transformation: s }) {
19536
+ let c = new O("f_legi.extractTextLinks"), l = {}, u = s === void 0 ? void 0 : ee(s), d = o === void 0 ? {} : structuredClone(o), f = c.timeSync("extractReferences", () => {
19537
+ let t = [];
19538
+ for (let n of te(e, { overlapWindowForCandidate: je })) a && console.log(`In "${e.input.slice(n.position.start, n.position.stop)}": \nReference "${e.text(n.position)}": ${JSON.stringify(n, null, 2)}`), t.push(n);
19539
+ return t;
19540
+ }, { inputSize: e.input.length }), p = performance.now();
19541
+ for (let t of f) for (let n of N(e, t)) {
19542
+ let a = n.type === "parent-enfant" ? n.parent : n;
19543
+ switch (a.type) {
19544
+ case "alinéa":
19545
+ case "incomplete-header":
19546
+ case "item":
19547
+ case "phrase": break;
19548
+ case "article":
19549
+ a.definition && (d.textId === void 0 ? i && console.log(`In "${e.input.slice(t.position.start, t.position.stop)}": Missing state.textId for article definition`) : (l[d.textId] ??= {})[a.num] = Object.fromEntries(Object.entries({
19550
+ article: a,
19551
+ position: a.position,
19552
+ reference: t,
19553
+ textId: d.textId,
19554
+ type: "article_definition"
19555
+ }).filter(([, e]) => e !== void 0)));
19556
+ break;
19557
+ case "chapitre":
19558
+ case "livre":
19559
+ case "paragraphe":
19560
+ case "partie":
19561
+ case "section":
19562
+ case "sous-paragraphe":
19563
+ case "sous-section":
19564
+ case "sous-sous-paragraphe":
19565
+ case "sous-titre":
19566
+ case "titre":
19567
+ a.definition && d.textId === void 0 && i && console.log(`In "${e.input.slice(t.position.start, t.position.stop)}": Missing state.textId for division definition`);
19568
+ break;
19569
+ case "texte":
19570
+ k({
19571
+ context: e,
19572
+ logPartialReferences: i,
19573
+ reference: t,
19574
+ state: d,
19575
+ text: a
19576
+ });
19577
+ break;
19578
+ default: r && (console.log(`In "${e.input.slice(t.position.start, t.position.stop)}": Reference ${JSON.stringify(a, null, 2)} ignored`), console.log(JSON.stringify(t, null, 2)));
19579
+ }
19580
+ }
19581
+ c.add({
19582
+ durationMs: Math.round((performance.now() - p) * 10) / 10,
19583
+ phase: "collectDefinitionsAndTextState"
19584
+ });
19585
+ let m = /* @__PURE__ */ new Set();
19586
+ for (let e of f) for (let t of M(e, { citations: !0 })) m.add(t);
19587
+ let h = Me(e, f);
19588
+ Ie(n) && await c.time("preloadActiveArticlesByTextIds", () => n.preloadActiveArticlesByTextIds({
19589
+ date: t,
19590
+ nums: m,
19591
+ textIds: h
19592
+ }), { count: h.size });
19593
+ let g = await c.time("collectUniqueFallbackArticleNums", () => Ne({
19594
+ context: e,
19595
+ date: t,
19596
+ flegiResolver: n,
19597
+ logPartialReferences: i,
19598
+ references: f,
19599
+ state: o === void 0 ? {} : structuredClone(o)
19600
+ }), { count: f.length });
19601
+ await c.time("preloadUniqueActiveArticlesByNums", () => n.preloadUniqueActiveArticlesByNums({
19602
+ date: t,
19603
+ nums: g
19604
+ }), { count: g.size }), d = o === void 0 ? {} : o;
19605
+ let _ = 0, v = performance.now();
19606
+ for (let a of f) for await (let o of Re({
19607
+ articleDefinitionByNumByTextId: l,
19608
+ flegiResolver: n,
19609
+ context: e,
19610
+ date: t,
19611
+ logIgnoredReferencesTypes: r,
19612
+ logPartialReferences: i,
19613
+ originalPositionsFromTransformedIterator: u,
19614
+ reference: a,
19615
+ state: d
19616
+ })) _++, yield o;
19617
+ c.add({
19618
+ count: _,
19619
+ durationMs: Math.round((performance.now() - v) * 10) / 10,
19620
+ phase: "iterReferenceLinks"
19621
+ }), c.log({ referenceCount: f.length });
19622
+ }
19623
+ function je(e) {
19624
+ return /^[a-z]$/i.test(e) ? 0 : 80;
19625
+ }
19626
+ function k({ context: e, logPartialReferences: t, reference: n, state: r, text: a }) {
19627
+ switch (a.nature) {
19628
+ case "ARRETE":
19629
+ case "CIRCULAIRE":
19630
+ case "CONVENTION":
19631
+ case "DECRET_LOI":
19632
+ delete r.textId;
19633
+ break;
19634
+ case "ARRETEURO":
19635
+ case "AVISEURO":
19636
+ case "DECISION_EURO":
19637
+ case "DECLARATIONEURO":
19638
+ case "DELIBERATIONEURO":
19639
+ case "DIRECTIVE_EURO":
19640
+ case "INFORMATIONEURO":
19641
+ case "INSTRUCTIONEURO":
19642
+ case "LETTREEURO":
19643
+ case "REGLEMENTEUROPEEN":
19644
+ delete r.textId;
19645
+ break;
19646
+ case "CODE":
19647
+ if (a.relative === 0 && r.codeId !== void 0) {
19648
+ r.textId = r.codeId;
19649
+ break;
19650
+ }
19651
+ if (a.cid === void 0) {
19652
+ t && console.log(`In "${e.input.slice(n.position.start, n.position.stop)}": Missing CID of ${a.nature} reference ${JSON.stringify(a, null, 2)}`), delete r.textId;
19653
+ break;
19654
+ }
19655
+ r.textId = r.codeId = a.cid;
19656
+ break;
19657
+ case "CONSTITUTION":
19658
+ if (a.relative === 0 && r.constitutionId !== void 0) {
19659
+ r.textId = r.constitutionId;
19660
+ break;
19661
+ }
19662
+ if (a.cid === void 0) {
19663
+ t && console.log(`In "${e.input.slice(n.position.start, n.position.stop)}": Missing CID of ${a.nature} reference ${JSON.stringify(a, null, 2)}`), delete r.textId;
19664
+ break;
19665
+ }
19666
+ r.textId = r.constitutionId = a.cid;
19667
+ break;
19668
+ case "DECRET":
19669
+ if (a.relative === 0 && r.decreeId !== void 0) {
19670
+ r.textId = r.decreeId;
19671
+ break;
19672
+ }
19673
+ if (a.cid === void 0) {
19674
+ t && console.log(`In "${e.input.slice(n.position.start, n.position.stop)}": Missing CID of ${a.nature} reference ${JSON.stringify(a, null, 2)}`), delete r.textId;
19675
+ break;
19676
+ }
19677
+ r.textId = r.decreeId = a.cid;
19678
+ break;
19679
+ case "LOI":
19680
+ case "LOI_CONSTIT":
19681
+ case "LOI_ORGANIQUE":
19682
+ case "ORDONNANCE":
19683
+ if (a.relative === 0 && r.lawId !== void 0) {
19684
+ r.textId = r.lawId;
19685
+ break;
19686
+ }
19687
+ if (a.cid === void 0) {
19688
+ t && console.log(`In "${e.input.slice(n.position.start, n.position.stop)}": Missing CID of ${a.nature} reference ${JSON.stringify(a, null, 2)}`), delete r.textId;
19689
+ break;
19690
+ }
19691
+ r.textId = r.lawId = a.cid;
19692
+ break;
19693
+ default: a.nature === void 0 ? delete r.textId : i("nature", a.nature);
19694
+ }
19695
+ }
19696
+ function Me(e, t) {
19697
+ let n = /* @__PURE__ */ new Set();
19698
+ for (let r of t) for (let t of N(e, r, { citations: !0 })) {
19699
+ let e = t.type === "parent-enfant" ? t.parent : t;
19700
+ e.type === "texte" && e.cid !== void 0 ? n.add(e.cid) : e.type === "article" && e.implicitText?.cid !== void 0 && n.add(e.implicitText.cid);
19701
+ }
19702
+ return n;
19703
+ }
19704
+ async function Ne({ context: e, date: t, flegiResolver: n, logPartialReferences: r, references: i, state: a }) {
19705
+ let o = /* @__PURE__ */ new Set();
19706
+ for (let s of i) await A({
19707
+ articleNums: o,
19708
+ context: e,
19709
+ date: t,
19710
+ flegiResolver: n,
19711
+ logPartialReferences: r,
19712
+ reference: s,
19713
+ state: a
19714
+ });
19715
+ return o;
19716
+ }
19717
+ async function A({ articleNums: e, context: t, date: n, flegiResolver: r, logPartialReferences: i, reference: a, state: o }) {
19718
+ for (let s of N(t, a)) await Pe({
19719
+ articleNums: e,
19720
+ atomicOrParentChildReference: s,
19721
+ context: t,
19722
+ date: n,
19723
+ flegiResolver: r,
19724
+ logPartialReferences: i,
19725
+ reference: a,
19726
+ state: o
19727
+ });
19728
+ if (a.type === "reference_et_action") {
19729
+ let { originalCitations: s } = a.action;
19730
+ if (s !== void 0) {
19731
+ for (let a of s) if (a.references !== void 0) {
19732
+ let s = structuredClone(o);
19733
+ for (let o of a.references) await A({
19734
+ articleNums: e,
19735
+ context: t,
19736
+ date: n,
19737
+ flegiResolver: r,
19738
+ logPartialReferences: i,
19739
+ reference: o,
19740
+ state: s
19741
+ });
19742
+ }
19743
+ }
19744
+ }
19745
+ }
19746
+ async function Pe({ articleNums: e, atomicOrParentChildReference: t, context: n, date: r, flegiResolver: i, logPartialReferences: a, reference: o, state: s }) {
19747
+ let c = t.type === "parent-enfant" ? t.parent : t, l = t.type === "parent-enfant" ? t : void 0;
19748
+ switch (c.type) {
19749
+ case "alinéa":
19750
+ case "incomplete-header":
19751
+ case "item":
19752
+ case "phrase": break;
19753
+ case "article":
19754
+ if (c.definition && s.textId !== void 0) break;
19755
+ await Fe({
19756
+ article: c,
19757
+ date: r,
19758
+ flegiResolver: i,
19759
+ state: s
19760
+ }) && e.add(c.num);
19761
+ break;
19762
+ case "chapitre":
19763
+ case "livre":
19764
+ case "paragraphe":
19765
+ case "partie":
19766
+ case "section":
19767
+ case "sous-paragraphe":
19768
+ case "sous-section":
19769
+ case "sous-sous-paragraphe":
19770
+ case "sous-titre":
19771
+ case "titre":
19772
+ if (c.definition && s.textId !== void 0) break;
19773
+ l !== void 0 && await A({
19774
+ articleNums: e,
19775
+ context: n,
19776
+ date: r,
19777
+ flegiResolver: i,
19778
+ logPartialReferences: a,
19779
+ reference: l.child,
19780
+ state: s
19781
+ });
19782
+ break;
19783
+ case "texte":
19784
+ k({
19785
+ context: n,
19786
+ logPartialReferences: a,
19787
+ reference: o,
19788
+ state: s,
19789
+ text: c
19790
+ }), l !== void 0 && await A({
19791
+ articleNums: e,
19792
+ context: n,
19793
+ date: r,
19794
+ flegiResolver: i,
19795
+ logPartialReferences: a,
19796
+ reference: l.child,
19797
+ state: s
19798
+ });
19799
+ break;
19800
+ default: break;
19801
+ }
19802
+ }
19803
+ async function Fe({ article: e, date: t, flegiResolver: n, state: r }) {
19804
+ if (e.present || e.num === void 0) return !1;
19805
+ let i = e.implicitText?.cid ?? r.textId;
19806
+ return !(i !== void 0 && (await n.getActiveArticlesByTextAndNum({
19807
+ date: t,
19808
+ num: e.num,
19809
+ textId: i
19810
+ })).length > 0 || r.defaultTextId !== void 0 && r.defaultTextId !== i && (await n.getActiveArticlesByTextAndNum({
19811
+ date: t,
19812
+ num: e.num,
19813
+ textId: r.defaultTextId
19814
+ })).length > 0);
19815
+ }
19816
+ function Ie(e) {
19817
+ return "preloadActiveArticlesByTextIds" in e;
19818
+ }
19819
+ async function* j({ ancestors: e, article: t, flegiResolver: n, context: r, date: i, logPartialReferences: a, originalPositionsFromTransformedIterator: o, reference: s, state: c }) {
19820
+ if (t.present) return;
19821
+ let l = [], u = t.implicitText?.cid ?? c.textId;
19822
+ if (u !== void 0 && (l = await n.getActiveArticlesByTextAndNum({
19823
+ date: i,
19824
+ num: t.num,
19825
+ textId: u
19826
+ })), l.length === 0 && c.defaultTextId !== void 0 && c.defaultTextId !== u && (l = await n.getActiveArticlesByTextAndNum({
19827
+ date: i,
19828
+ num: t.num,
19829
+ textId: c.defaultTextId
19830
+ })), l.length === 0 && t.num !== void 0 && (l = await n.getUniqueActiveArticlesByNum({
19831
+ date: i,
19832
+ num: t.num
19833
+ }), l.length !== 0 && l.reduce((e, { textId: t }) => (t !== null && e.add(t), e), /* @__PURE__ */ new Set()).size > 1 && (l = [])), l.length === 0) a && console.warn(`In "${r.input.slice(t.position.start, t.position.stop)}": Unknown article ${t.num ?? null} of text ${u} for reference ${JSON.stringify(t, null, 2)}`), delete c.articleId;
19834
+ else if (l.length === 1) c.articleId = l[0].id;
19835
+ else {
19836
+ let e = l.filter(({ dateDebut: e, dateFin: t }) => e <= i && t > i);
19837
+ e.length === 1 ? c.articleId = e[0].id : (e.length !== 0 && (l = e), e = l.filter(({ id: e }) => !c.textId?.startsWith("JORF") || e.startsWith("JORF")), e.length === 1 ? c.articleId = e[0].id : (e.length !== 0 && (l = e), a && console.warn(`In "${r.input.slice(t.position.start, t.position.stop)}": Unable to filter article ${t.num ?? null} of text ${c.textId ?? null} among IDs ${JSON.stringify(l.map(({ id: e }) => e), null, 2)} for reference ${JSON.stringify(t, null, 2)}`), delete c.articleId));
19838
+ }
19839
+ let d = e === void 0 ? t.position : t.position.start < e[0].position.start ? {
19840
+ start: t.position.start,
19841
+ stop: e[0].position.stop
19842
+ } : {
19843
+ start: e[0].position.start,
19844
+ stop: t.position.stop
19845
+ };
19846
+ yield Object.fromEntries(Object.entries({
19847
+ article: t,
19848
+ articleId: c.articleId,
19849
+ originalTransformation: o === void 0 ? void 0 : _(o, d),
19850
+ position: d,
19851
+ reference: s,
19852
+ type: "external_article"
19853
+ }).filter(([, e]) => e !== void 0));
19854
+ }
19855
+ function* M(e, { citations: t = !1 } = {}) {
19856
+ switch (e.type) {
19857
+ case "article":
19858
+ e.num !== void 0 && (yield e.num);
19859
+ break;
19860
+ case "bounded-interval":
19861
+ yield* M(e.first, { citations: t }), yield* M(e.last, { citations: t });
19862
+ break;
19863
+ case "counted-interval":
19864
+ yield* M(e.first, { citations: t });
19865
+ break;
19866
+ case "enumeration":
19867
+ case "exclusion":
19868
+ yield* M(e.left, { citations: t }), yield* M(e.right, { citations: t });
19869
+ break;
19870
+ case "parent-enfant":
19871
+ yield* M(e.parent, { citations: t }), yield* M(e.child, { citations: t });
19872
+ break;
19873
+ case "reference_et_action":
19874
+ if (yield* M(e.reference, { citations: t }), t) {
19875
+ let { originalCitations: n } = e.action;
19876
+ if (n !== void 0) {
19877
+ for (let e of n) if (e.references !== void 0) for (let n of e.references) yield* M(n, { citations: t });
19878
+ }
19879
+ }
19880
+ break;
19881
+ }
19882
+ }
19883
+ function* N(e, t, { citations: n = !1 } = {}) {
19884
+ switch (t.type) {
19885
+ case "bounded-interval":
19886
+ yield* N(e, t.first, { citations: n }), yield* N(e, t.last, { citations: n });
19887
+ break;
19888
+ case "counted-interval":
19889
+ yield* N(e, t.first, { citations: n });
19890
+ break;
19891
+ case "enumeration":
19892
+ case "exclusion":
19893
+ yield* N(e, t.left, { citations: n }), yield* N(e, t.right, { citations: n });
19894
+ break;
19895
+ case "reference_et_action":
19896
+ if (yield* N(e, t.reference, { citations: n }), n) {
19897
+ let { originalCitations: r } = t.action;
19898
+ if (r !== void 0) {
19899
+ for (let t of r) if (t.references !== void 0) for (let r of t.references) yield* N(e, r, { citations: n });
19900
+ }
19901
+ }
19902
+ break;
19903
+ default: yield t;
19904
+ }
19905
+ }
19906
+ function* P(e, t) {
19907
+ if (t.type === "texte") console.error(`iterDeepestDivisionsOrArticles must not be called with a text:\n${JSON.stringify(t, null, 2)}`);
19908
+ else if (h(t) || t.type === "article") yield t;
19909
+ else if (!(l(t) || t.type === "incomplete-header")) switch (t.type) {
19910
+ case "bounded-interval":
19911
+ yield* P(e, t.first), yield* P(e, t.last);
19912
+ break;
19913
+ case "counted-interval":
19914
+ yield* P(e, t.first);
19915
+ break;
19916
+ case "enumeration":
19917
+ case "exclusion":
19918
+ yield* P(e, t.left), yield* P(e, t.right);
19919
+ break;
19920
+ case "parent-enfant": {
19921
+ let n = [...P(e, t.child)];
19922
+ n.length === 0 ? yield* P(e, t.parent) : yield* n;
19923
+ break;
19924
+ }
19925
+ case "reference_et_action": {
19926
+ yield* P(e, t.reference);
19927
+ let { originalCitations: n } = t.action;
19928
+ if (n !== void 0) {
19929
+ for (let t of n) if (t.references !== void 0) for (let n of t.references) yield* P(e, n);
19930
+ }
19931
+ break;
19932
+ }
19933
+ default: i("iterDeepestDivisionsOrArticles reference.type", t);
19934
+ }
19935
+ }
19936
+ function F(e) {
19937
+ return e?.split(":")[0].trim().toLowerCase().split(/\s+/).map((e) => e.trim()).filter((e) => e !== "").join(" ");
19938
+ }
19939
+ async function* I({ ancestors: t, flegiResolver: n, context: r, date: i, division: a, divisionChildReference: o, logIgnoredReferencesTypes: s, logPartialReferences: c, originalPositionsFromTransformedIterator: l, parentSectionChildren: u, reference: d, state: f }) {
19940
+ if (a.present) return;
19941
+ let p;
19942
+ if (u === void 0 && f.textId !== void 0 && (u = await n.getDirectSectionChildren({
19943
+ date: i,
19944
+ parentPath: f.textId
19945
+ })), u !== void 0) {
19946
+ for (let e of u) {
19947
+ let t = F(e.title);
19948
+ if (t !== void 0) {
19949
+ let n = !1;
19950
+ if (a.index !== void 0 && (n = Le(a.type, a.index).some((e) => e === t)), !n && a.num !== void 0 && (n = `${a.type} ${a.num.toLowerCase()}` === t), n) {
19951
+ p = e;
19952
+ break;
19953
+ }
19954
+ }
19955
+ }
19956
+ if (p === void 0 && (p = u.find((t) => {
19957
+ let n = F(t.title)?.split(/\s+/);
19958
+ return n !== void 0 && n.length === 2 && e.includes(n[0]) && n[1] === "législative";
19959
+ }), p !== void 0)) {
19960
+ let e = F(p.title).split(/\s+/), t = {
19961
+ start: a.position.stop,
19962
+ stop: a.position.stop
19963
+ }, n = l === void 0 ? void 0 : _(l, t), r = Object.fromEntries(Object.entries({
19964
+ num: e[1],
19965
+ originalTransformation: n,
19966
+ position: t,
19967
+ type: e[0]
19968
+ }).filter(([, e]) => e !== void 0));
19969
+ o = Object.fromEntries(Object.entries({
19970
+ child: o ?? a,
19971
+ parent: r,
19972
+ originalTransformation: n,
19973
+ position: t,
19974
+ type: "parent-enfant"
19975
+ }).filter(([, e]) => e !== void 0)), a = r;
19976
+ }
19977
+ }
19978
+ let m = o === void 0 ? [] : [...P(r, o.child)], h = 0;
19979
+ if (o !== void 0) for (let e of N(r, o.child)) {
19980
+ let u = e.type === "parent-enfant" ? e.parent : e, g = e.type === "parent-enfant" ? e : void 0;
19981
+ switch (u.type) {
19982
+ case "alinéa":
19983
+ case "incomplete-header":
19984
+ case "item":
19985
+ case "phrase": break;
19986
+ case "article":
19987
+ yield* j({
19988
+ ancestors: m.length === 1 ? [...t ?? [], a] : void 0,
19989
+ article: u,
19990
+ flegiResolver: n,
19991
+ context: r,
19992
+ date: i,
19993
+ logPartialReferences: c,
19994
+ originalPositionsFromTransformedIterator: l,
19995
+ reference: d,
19996
+ state: f
19997
+ }), h++;
19998
+ break;
19999
+ case "chapitre":
20000
+ case "livre":
20001
+ case "paragraphe":
20002
+ case "partie":
20003
+ case "section":
20004
+ case "sous-paragraphe":
20005
+ case "sous-section":
20006
+ case "sous-sous-paragraphe":
20007
+ case "sous-titre":
20008
+ case "titre": {
20009
+ let e;
20010
+ p !== void 0 && (e = await n.getDirectSectionChildren({
20011
+ date: i,
20012
+ parentPath: p.path
20013
+ })), yield* I({
20014
+ ancestors: m.length === 1 ? [...t ?? [], a] : void 0,
20015
+ flegiResolver: n,
20016
+ context: r,
20017
+ date: i,
20018
+ division: u,
20019
+ divisionChildReference: g,
20020
+ logIgnoredReferencesTypes: s,
20021
+ logPartialReferences: c,
20022
+ originalPositionsFromTransformedIterator: l,
20023
+ parentSectionChildren: e,
20024
+ reference: d,
20025
+ state: f
20026
+ }), h++;
20027
+ break;
20028
+ }
20029
+ default: s && (console.log(`In "${r.input.slice(o.position.start, o.position.stop)}": Reference of type ${u.type} ignored in division`), console.log(JSON.stringify(o, null, 2)));
20030
+ }
20031
+ }
20032
+ if (h === 0) {
20033
+ f.sectionTaId = p?.id;
20034
+ let e = t === void 0 ? a.position : a.position.start < t[0].position.start ? {
20035
+ start: a.position.start,
20036
+ stop: t[0].position.stop
20037
+ } : {
20038
+ start: t[0].position.start,
20039
+ stop: a.position.stop
20040
+ };
20041
+ yield Object.fromEntries(Object.entries({
20042
+ division: a,
20043
+ originalTransformation: l === void 0 ? void 0 : _(l, e),
20044
+ position: e,
20045
+ reference: d,
20046
+ sectionTaId: f.sectionTaId,
20047
+ type: "external_division"
20048
+ }).filter(([, e]) => e !== void 0));
20049
+ }
20050
+ }
20051
+ function* Le(e, t) {
20052
+ let n = Math.floor(t), i = Math.floor((t - n) * 1e3);
20053
+ if (i === 0) {
20054
+ for (let t of s(n)) yield `${t.toLowerCase()} ${e}`;
20055
+ for (let t of b(n)) yield `${e} ${t.toLowerCase()}`;
20056
+ } else for (let t of r(i)) {
20057
+ for (let r of s(n)) yield `${r.toLowerCase()} ${t} ${e}`;
20058
+ for (let r of b(n)) yield `${e} ${t} ${r.toLowerCase()}`;
20059
+ }
20060
+ }
20061
+ async function* Re({ articleDefinitionByNumByTextId: e, flegiResolver: t, context: n, date: r, logIgnoredReferencesTypes: i, logPartialReferences: a, originalPositionsFromTransformedIterator: o, reference: s, state: c }) {
20062
+ let l = e ?? {}, u = c === void 0 ? {} : c;
20063
+ for (let e of N(n, s)) {
20064
+ let c = e.type === "parent-enfant" ? e.parent : e, d = e.type === "parent-enfant" ? e : void 0;
20065
+ switch (c.type) {
20066
+ case "alinéa":
20067
+ case "incomplete-header":
20068
+ case "item":
20069
+ case "phrase": break;
20070
+ case "article":
20071
+ if (c.definition && u.textId !== void 0) {
20072
+ let e = l[u.textId]?.[c.num];
20073
+ e !== void 0 && (e.originalTransformation === void 0 && o !== void 0 && (e.originalTransformation = _(o, e.position)), yield e);
20074
+ } else yield* j({
20075
+ article: c,
20076
+ flegiResolver: t,
20077
+ context: n,
20078
+ date: r,
20079
+ logPartialReferences: a,
20080
+ originalPositionsFromTransformedIterator: o,
20081
+ reference: s,
20082
+ state: u
20083
+ });
20084
+ break;
20085
+ case "chapitre":
20086
+ case "livre":
20087
+ case "paragraphe":
20088
+ case "partie":
20089
+ case "section":
20090
+ case "sous-paragraphe":
20091
+ case "sous-section":
20092
+ case "sous-sous-paragraphe":
20093
+ case "sous-titre":
20094
+ case "titre":
20095
+ c.definition && u.textId !== void 0 || (yield* I({
20096
+ flegiResolver: t,
20097
+ context: n,
20098
+ date: r,
20099
+ division: c,
20100
+ divisionChildReference: d,
20101
+ logIgnoredReferencesTypes: i,
20102
+ logPartialReferences: a,
20103
+ originalPositionsFromTransformedIterator: o,
20104
+ reference: s,
20105
+ state: u
20106
+ }));
20107
+ break;
20108
+ case "texte": {
20109
+ k({
20110
+ context: n,
20111
+ logPartialReferences: a,
20112
+ reference: s,
20113
+ state: u,
20114
+ text: c
20115
+ });
20116
+ let e = d === void 0 ? [] : [...P(n, d.child)], l = 0;
20117
+ if (d !== void 0) for (let f of N(n, d.child)) {
20118
+ let p = f.type === "parent-enfant" ? f.parent : f, m = f.type === "parent-enfant" ? f : void 0;
20119
+ switch (p.type) {
20120
+ case "alinéa":
20121
+ case "incomplete-header":
20122
+ case "item":
20123
+ case "phrase": break;
20124
+ case "article":
20125
+ yield* j({
20126
+ ancestors: e.length === 1 ? [c] : void 0,
20127
+ article: p,
20128
+ flegiResolver: t,
20129
+ context: n,
20130
+ date: r,
20131
+ logPartialReferences: a,
20132
+ originalPositionsFromTransformedIterator: o,
20133
+ reference: s,
20134
+ state: u
20135
+ }), l++;
20136
+ break;
20137
+ case "chapitre":
20138
+ case "livre":
20139
+ case "paragraphe":
20140
+ case "partie":
20141
+ case "section":
20142
+ case "sous-paragraphe":
20143
+ case "sous-section":
20144
+ case "sous-sous-paragraphe":
20145
+ case "sous-titre":
20146
+ case "titre": {
20147
+ let d;
20148
+ u.textId !== void 0 && (d = await t.getDirectSectionChildren({
20149
+ date: r,
20150
+ parentPath: u.textId
20151
+ })), yield* I({
20152
+ ancestors: e.length === 1 ? [c] : void 0,
20153
+ flegiResolver: t,
20154
+ context: n,
20155
+ date: r,
20156
+ division: p,
20157
+ divisionChildReference: m,
20158
+ logIgnoredReferencesTypes: i,
20159
+ logPartialReferences: a,
20160
+ originalPositionsFromTransformedIterator: o,
20161
+ parentSectionChildren: d,
20162
+ reference: s,
20163
+ state: u
20164
+ }), l++;
20165
+ break;
20166
+ }
20167
+ default: i && (console.log(`In "${n.input.slice(s.position.start, d.position.stop)}": Reference of type ${p.type} ignored in text`), console.log(JSON.stringify(d, null, 2)));
20168
+ }
20169
+ }
20170
+ if (l === 0) {
20171
+ if (c.position === void 0) throw Error(`Position missing in atomic reference: ${c}`);
20172
+ yield Object.fromEntries(Object.entries({
20173
+ originalTransformation: o === void 0 ? void 0 : _(o, c.position),
20174
+ position: c.position,
20175
+ reference: s,
20176
+ text: c,
20177
+ type: "external_text"
20178
+ }).filter(([, e]) => e !== void 0));
20179
+ }
20180
+ break;
20181
+ }
20182
+ default: i && (console.log(`In "${n.input.slice(s.position.start, s.position.stop)}": Reference ${JSON.stringify(c, null, 2)} ignored`), console.log(JSON.stringify(s, null, 2)));
20183
+ }
20184
+ }
20185
+ if (s.type === "reference_et_action") {
20186
+ let { originalCitations: e } = s.action;
20187
+ if (e !== void 0) {
20188
+ for (let s of e) if (s.references !== void 0) {
20189
+ let e = structuredClone(u);
20190
+ for (let c of s.references) yield* Re({
20191
+ articleDefinitionByNumByTextId: l,
20192
+ flegiResolver: t,
20193
+ context: n,
20194
+ date: r,
20195
+ logIgnoredReferencesTypes: i,
20196
+ logPartialReferences: a,
20197
+ originalPositionsFromTransformedIterator: o,
20198
+ reference: c,
20199
+ state: e
20200
+ });
20201
+ }
20202
+ }
20203
+ }
20204
+ }
20205
+ //#endregion
20206
+ //#region src/lib/f_legi/linkers/html.ts
20207
+ async function ze({ legiResolver: e, date: t, html: r, linkBaseUrl: a, linkType: o, logIgnoredReferencesTypes: s, logPartialReferences: c, logReferences: l, onLink: d, previousContext: f, state: p }) {
20208
+ let m = new O("f_legi.addLinksToHtml");
20209
+ await m.time("preloadTextTitlesInfos", () => e.preloadTextTitlesInfos());
20210
+ let h = m.timeSync("simplifyHtml", () => v({ removeAWithHref: !0 })(r), {
20211
+ inputSize: r.length,
20212
+ outputSize: void 0
20213
+ }), g = new n(h.output);
20214
+ g.currentArticle = f?.currentArticle, g.currentText = f?.currentText;
20215
+ let _ = [], y = { value: 0 }, b = -1;
20216
+ await m.time("extractTextLinks", async () => {
20217
+ for await (let n of Ae({
20218
+ flegiResolver: e,
20219
+ context: g,
20220
+ date: t,
20221
+ logIgnoredReferencesTypes: s,
20222
+ logPartialReferences: c,
20223
+ logReferences: l,
20224
+ state: p,
20225
+ transformation: h
20226
+ })) if (b++, !(d !== void 0 && await d(n, b))) switch (n.type) {
20227
+ case "article_definition": {
20228
+ let { article: e, originalTransformation: t, textId: i } = n;
20229
+ if (t === void 0) throw Error(`Missing originalTransformation attribute in article definition: ${JSON.stringify(n, null, 2)}`);
20230
+ L({
20231
+ inputHtml: r,
20232
+ originalTransformation: t,
20233
+ output: { replacements: _ },
20234
+ replacementCounter: y,
20235
+ tagHtmlFromOriginal: (t) => `<span class="definition_article" id="definition_article_${i}_${e.num.replaceAll(" ", "_")}">${t}</span>`
20236
+ });
20237
+ break;
20238
+ }
20239
+ case "external_article": {
20240
+ let { articleId: e, originalTransformation: t } = n;
20241
+ if (e !== void 0) {
20242
+ if (t === void 0) throw Error(`Missing originalTransformation attribute in external article link: ${JSON.stringify(n, null, 2)}`);
20243
+ L({
20244
+ inputHtml: r,
20245
+ originalTransformation: t,
20246
+ output: { replacements: _ },
20247
+ replacementCounter: y,
20248
+ tagHtmlFromOriginal: (t) => `<a class="lien_article_externe" href="${u(o, a, e)}">${t}</a>`
20249
+ });
20250
+ }
20251
+ break;
20252
+ }
20253
+ case "external_division": {
20254
+ let { originalTransformation: e, sectionTaId: t } = n;
20255
+ if (t !== void 0) {
20256
+ if (e === void 0) throw Error(`Missing originalTransformation attribute in external division link: ${JSON.stringify(n, null, 2)}`);
20257
+ L({
20258
+ inputHtml: r,
20259
+ originalTransformation: e,
20260
+ output: { replacements: _ },
20261
+ replacementCounter: y,
20262
+ tagHtmlFromOriginal: (e) => `<a class="lien_division_externe" href="${u(o, a, t)}">${e}</a>`
20263
+ });
20264
+ }
20265
+ break;
20266
+ }
20267
+ case "external_text": {
20268
+ let { originalTransformation: e, text: t } = n;
20269
+ if (t.cid === void 0) {
20270
+ t.relative !== 0 && c && console.error(`Link to text "${g.text(t.position)}" without CID: ${JSON.stringify(t, null, 2)}`);
20271
+ continue;
20272
+ }
20273
+ if (e === void 0) throw Error(`Missing originalTransformation attribute in external text link: ${JSON.stringify(n, null, 2)}`);
20274
+ L({
20275
+ inputHtml: r,
20276
+ originalTransformation: e,
20277
+ output: { replacements: _ },
20278
+ replacementCounter: y,
20279
+ tagHtmlFromOriginal: (e) => `<a class="lien_texte_externe" href="${u(o, a, t.cid)}">${e}</a>`
20280
+ });
20281
+ break;
20282
+ }
20283
+ case "european_text": {
20284
+ let { url: e, originalTransformation: t } = n;
20285
+ if (e === void 0) continue;
20286
+ if (t === void 0) throw Error(`Missing originalTransformation attribute in european text link: ${JSON.stringify(n, null, 2)}`);
20287
+ L({
20288
+ inputHtml: r,
20289
+ originalTransformation: t,
20290
+ output: { replacements: _ },
20291
+ replacementCounter: y,
20292
+ tagHtmlFromOriginal: (t) => `<a class="lien_texte_european" href="${e}" target="_blank">${t}</a>`
20293
+ });
20294
+ break;
20295
+ }
20296
+ case "internal_article": {
20297
+ let { definition: e, originalTransformation: t } = n;
20298
+ if (t === void 0) throw Error(`Missing originalTransformation attribute in internal article link: ${JSON.stringify(n, null, 2)}`);
20299
+ L({
20300
+ inputHtml: r,
20301
+ originalTransformation: t,
20302
+ output: { replacements: _ },
20303
+ replacementCounter: y,
20304
+ tagHtmlFromOriginal: (t) => `<a class="lien_article_interne" href="#definition_article_${e.textId}_${e.article.num.replaceAll(" ", "_")}" style="background-color: #eae462">${t}</a>`
20305
+ });
20306
+ break;
20307
+ }
20308
+ default: i("Link", n);
20309
+ }
20310
+ }, { count: b + 1 });
20311
+ let x = m.timeSync("applyHtmlReplacements", () => Be(r, _), {
20312
+ count: _.length,
20313
+ inputSize: r.length
20314
+ });
20315
+ return m.log({
20316
+ linkCount: b + 1,
20317
+ replacementCount: _.length
20318
+ }), {
20319
+ context: g,
20320
+ output: _.length === 0 ? null : x
20321
+ };
20322
+ }
20323
+ function Be(e, t) {
20324
+ if (t.length === 0) return e;
20325
+ let n = [], r = 0;
20326
+ for (let i of t.toSorted((e, t) => e.start - t.start || e.stop - t.stop || e.order - t.order)) {
20327
+ if (i.start < r) {
20328
+ console.warn(`Skipping overlapping HTML replacement at ${i.start}-${i.stop}`);
20329
+ continue;
20330
+ }
20331
+ n.push(e.slice(r, i.start)), n.push(i.replacement), r = i.stop;
20332
+ }
20333
+ return n.push(e.slice(r)), n.join("");
20334
+ }
20335
+ function L({ inputHtml: e, originalTransformation: t, output: n, replacementCounter: r, tagHtmlFromOriginal: i }) {
20336
+ let a = p(t, i(d(e, t, 0) ?? ""));
20337
+ n.replacements.push({
20338
+ order: r.value++,
20339
+ replacement: a,
20340
+ start: t.position.start,
20341
+ stop: t.position.stop
20342
+ });
20343
+ }
20344
+ //#endregion
20345
+ //#region src/lib/legi/canutes_resolver.ts
20346
+ var Ve = T.dirname(re(import.meta.url)), He = [
20347
+ "src/lib/text_parsers/text_titles_infos.json",
20348
+ T.resolve(Ve, "../text_parsers/text_titles_infos.json"),
20349
+ T.resolve(Ve, "../src/lib/text_parsers/text_titles_infos.json")
20350
+ ];
20351
+ async function Ue(e) {
20352
+ if (e) return e;
20353
+ for (let e of He) if (await w.pathExists(e)) return e;
20354
+ return He[0];
20355
+ }
20356
+ function R(e) {
20357
+ return {
20358
+ dateDebut: e.dateDebut ?? "0001-01-01",
20359
+ dateFin: e.dateFin ?? "2999-01-01",
20360
+ id: e.id,
20361
+ num: e.num,
20362
+ textId: e.textId
20363
+ };
20364
+ }
20365
+ function We(e) {
20366
+ let t = e["@id"];
20367
+ return t === void 0 ? null : {
20368
+ dateDebut: e["@debut"] ?? null,
20369
+ dateFin: e["@fin"] ?? null,
20370
+ id: t,
20371
+ path: t,
20372
+ title: e["#text"] ?? null
20373
+ };
20374
+ }
20375
+ function Ge(e, t) {
20376
+ return (e.dateDebut === null || e.dateDebut <= t) && (e.dateFin === null || e.dateFin >= t);
20377
+ }
20378
+ var Ke = class {
20379
+ canutesDb;
20380
+ options;
20381
+ articleRowsByNumByTextAndDate = /* @__PURE__ */ new Map();
20382
+ directSectionChildrenByParentAndDate = /* @__PURE__ */ new Map();
20383
+ globalArticleRowsByNumAndDate = /* @__PURE__ */ new Map();
20384
+ textIdBySegmentId = /* @__PURE__ */ new Map();
20385
+ textTitlesInfosLoaded = !1;
20386
+ constructor(e, t = {}) {
20387
+ this.canutesDb = e, this.options = t;
20388
+ }
20389
+ async getActiveArticlesByTextAndNum({ date: e, num: t, textId: n }) {
20390
+ if (t === void 0) return [];
20391
+ let r = `${n}\0${t}\0${e}`, i = this.articleRowsByNumByTextAndDate.get(r);
20392
+ return i === void 0 && (i = (await this.canutesDb`
20393
+ SELECT
20394
+ id,
20395
+ num,
20396
+ data -> 'CONTEXTE' -> 'TEXTE' ->> '@cid' AS "textId",
20397
+ data -> 'META' -> 'META_SPEC' -> 'META_ARTICLE' ->> 'DATE_DEBUT' AS "dateDebut",
20398
+ data -> 'META' -> 'META_SPEC' -> 'META_ARTICLE' ->> 'DATE_FIN' AS "dateFin"
20399
+ FROM legifrance.article
20400
+ WHERE
20401
+ data -> 'CONTEXTE' -> 'TEXTE' ->> '@cid' = ${n}
20402
+ AND num = ${t}
20403
+ `).map(R), this.articleRowsByNumByTextAndDate.set(r, i)), i;
20404
+ }
20405
+ async getDirectSectionChildren({ date: e, parentPath: t }) {
20406
+ let n = `${t}\0${e}`, r = this.directSectionChildrenByParentAndDate.get(n);
20407
+ if (r === void 0) {
20408
+ let i = (await this.canutesDb`
20409
+ SELECT data
20410
+ FROM legifrance.section_ta
20411
+ WHERE id = ${t}
20412
+ `)[0]?.data.STRUCTURE_TA?.LIEN_SECTION_TA;
20413
+ r = i === void 0 ? (await this.canutesDb`
20414
+ SELECT data
20415
+ FROM legifrance.textelr
20416
+ WHERE id = ${t}
20417
+ `)[0]?.data.STRUCT?.LIEN_SECTION_TA?.map(We).filter((e) => e !== null).filter((t) => Ge(t, e)) ?? [] : i.map(We).filter((e) => e !== null).filter((t) => Ge(t, e)), this.directSectionChildrenByParentAndDate.set(n, r);
20418
+ }
20419
+ return r;
20420
+ }
20421
+ async getTextIdFromSegmentId(e) {
20422
+ let t = this.textIdBySegmentId.get(e);
20423
+ return t === void 0 && (t = e.startsWith("LEGIARTI") || e.startsWith("JORFARTI") ? (await this.canutesDb`
20424
+ SELECT data -> 'CONTEXTE' -> 'TEXTE' ->> '@cid' AS "textId"
20425
+ FROM legifrance.article
20426
+ WHERE id = ${e}
20427
+ `)[0]?.textId ?? null : (await this.canutesDb`
20428
+ SELECT data -> 'CONTEXTE' -> 'TEXTE' ->> '@cid' AS "textId"
20429
+ FROM legifrance.section_ta
20430
+ WHERE id = ${e}
20431
+ `)[0]?.textId ?? null, this.textIdBySegmentId.set(e, t)), t ?? void 0;
20432
+ }
20433
+ async getUniqueActiveArticlesByNum({ date: e, num: t }) {
20434
+ if (t === void 0) return [];
20435
+ let n = `${t}\0${e}`, r = this.globalArticleRowsByNumAndDate.get(n);
20436
+ return r === void 0 && (r = (await this.canutesDb`
20437
+ SELECT
20438
+ id,
20439
+ num,
20440
+ data -> 'CONTEXTE' -> 'TEXTE' ->> '@cid' AS "textId",
20441
+ data -> 'META' -> 'META_SPEC' -> 'META_ARTICLE' ->> 'DATE_DEBUT' AS "dateDebut",
20442
+ data -> 'META' -> 'META_SPEC' -> 'META_ARTICLE' ->> 'DATE_FIN' AS "dateFin"
20443
+ FROM legifrance.article
20444
+ WHERE num = ${t}
20445
+ LIMIT 100
20446
+ `).map(R), this.globalArticleRowsByNumAndDate.set(n, r)), r;
20447
+ }
20448
+ async preloadTextTitlesInfos(e = {}) {
20449
+ let t = (t, n = {}) => {
20450
+ e.onProgress?.({
20451
+ ...n,
20452
+ phase: t,
20453
+ resolver: "canutes"
20454
+ });
20455
+ };
20456
+ if (this.textTitlesInfosLoaded) {
20457
+ t("already-loaded");
20458
+ return;
20459
+ }
20460
+ t("resolveJsonPath:start");
20461
+ let n = await Ue(this.options.textTitlesInfosPath);
20462
+ t("resolveJsonPath:done", { detail: n }), t("readJson:start", { detail: n });
20463
+ let r = await w.stat(n), i = await w.readJson(n);
20464
+ t("readJson:done", {
20465
+ count: r.size,
20466
+ detail: n
20467
+ }), t("setTextTitlesInfos:start"), a(i), t("setTextTitlesInfos:done"), this.textTitlesInfosLoaded = !0;
20468
+ }
20469
+ async preloadUniqueActiveArticlesByNums({ date: e, nums: t }) {
20470
+ let n = [...new Set([...t].filter(Boolean))].filter((t) => !this.globalArticleRowsByNumAndDate.has(`${t}\0${e}`));
20471
+ if (n.length === 0) return;
20472
+ let r = (await this.canutesDb`
20473
+ SELECT
20474
+ id,
20475
+ num,
20476
+ data -> 'CONTEXTE' -> 'TEXTE' ->> '@cid' AS "textId",
20477
+ data -> 'META' -> 'META_SPEC' -> 'META_ARTICLE' ->> 'DATE_DEBUT' AS "dateDebut",
20478
+ data -> 'META' -> 'META_SPEC' -> 'META_ARTICLE' ->> 'DATE_FIN' AS "dateFin"
20479
+ FROM legifrance.article
20480
+ WHERE num IN ${this.canutesDb(n)}
20481
+ `).map(R), i = /* @__PURE__ */ new Map();
20482
+ for (let e of r) {
20483
+ if (e.num === null) continue;
20484
+ let t = i.get(e.num);
20485
+ t === void 0 ? i.set(e.num, [e]) : t.length < 100 && t.push(e);
20486
+ }
20487
+ for (let t of n) this.globalArticleRowsByNumAndDate.set(`${t}\0${e}`, i.get(t) ?? []);
20488
+ }
20489
+ }, qe = /\b(ins[èe]re|ins[ée]r[ée]|ajout|remplac|supprim|abrog|compl[èeé]t|r[ée]dig|r[ée]tabl|modifi(?:e|é|ée|és|ées|er|ant|ent))/iu, Je = /^article\s+(.+?)(?:\s*[::]\s*(.+))?$/iu, Ye = /^expos[ée]\s+des\s+motifs\b/iu;
20490
+ function z(e) {
20491
+ return (e ?? "").replace(/\u00a0/g, " ").replace(/\s+/g, " ").trim();
20492
+ }
20493
+ function B(e) {
20494
+ return z(e).toLowerCase().normalize("NFD").replace(/\p{Diacritic}/gu, "");
20495
+ }
20496
+ function V(e) {
20497
+ return B(e).replace(/[‐‑‒–—]/gu, "-").replace(/\s*\.\s*/gu, ".");
20498
+ }
20499
+ function Xe(e) {
20500
+ return V(e).replace(/[^a-z0-9]+/gu, "-").replace(/^-|-$/gu, "");
20501
+ }
20502
+ function Ze(e) {
20503
+ switch (e.kind) {
20504
+ case "insert_after":
20505
+ case "insert_before": return e.insertText;
20506
+ case "replace":
20507
+ case "replace_portion": return e.replacementText;
20508
+ case "compound": return e.operations.map((e) => {
20509
+ switch (e.kind) {
20510
+ case "insert_after":
20511
+ case "insert_before": return e.insertText;
20512
+ case "replace":
20513
+ case "replace_portion": return e.replacementText;
20514
+ default: return "";
20515
+ }
20516
+ }).filter(Boolean).join("\n");
20517
+ default: return;
20518
+ }
20519
+ }
20520
+ function Qe(e) {
20521
+ let t = z(e.sourceText), n = /\b(?:ins[ée]r[ée]s?|cr[ée][ée]s?|ajout[ée]s?|compl[ée]t[ée]s?\s+par)\b[\s\S]{0,160}?\barticle\s+(.+?)\s+ainsi\s+r[ée]dig[ée]s?\b/iu.exec(t);
20522
+ if (n?.[1] !== void 0) return z(n[1]);
20523
+ }
20524
+ function $e(e) {
20525
+ let t = Ze(e), n = [...(t ?? "").matchAll(/(?:^|\n)\s*(?:[«"]\s*)?(?:Art\.|Article)\s+(.+?)\s*[..]\s*[–—-]/giu)];
20526
+ if (n.length > 0 && t !== void 0) return n.map((e, r) => {
20527
+ let i = e.index ?? 0, a = n[r + 1]?.index ?? t.length, o = t.slice(i, a).trim();
20528
+ return {
20529
+ num: z(e[1]),
20530
+ text: o
20531
+ };
20532
+ });
20533
+ let r = Qe(e);
20534
+ return r === void 0 ? [] : [{
20535
+ num: r,
20536
+ text: t ?? e.sourceText
20537
+ }];
20538
+ }
20539
+ function H(e, t = /* @__PURE__ */ new Set()) {
20540
+ if (e == null) return t;
20541
+ if (Array.isArray(e)) {
20542
+ for (let n of e) H(n, t);
20543
+ return t;
20544
+ }
20545
+ if (typeof e != "object") return t;
20546
+ let n = e;
20547
+ n.type === "article" && typeof n.num == "string" && t.add(n.num);
20548
+ for (let e of Object.values(n)) H(e, t);
20549
+ return t;
20550
+ }
20551
+ function et(e) {
20552
+ let t = B(e.sourceText);
20553
+ return /\b(?:cree|cree[e]?s?|resultant|issu|prevu|mentionne)\b[\s\S]{0,80}\b(?:present|presente|pjl|projet\s+de\s+loi)\b/u.test(t);
20554
+ }
20555
+ function tt(e) {
20556
+ return z(e).replace(/[’']/gu, "'").replace(/[‐‑‒–—]/gu, "-");
20557
+ }
20558
+ function nt(e, t) {
20559
+ let r = new n(e, t), i = f(r);
20560
+ return typeof i != "string" || r.offset <= t ? null : {
20561
+ date: i,
20562
+ start: t,
20563
+ stop: r.offset
20564
+ };
20565
+ }
20566
+ function rt(e, t) {
20567
+ let n = /\d/u.exec(e.slice(t));
20568
+ if (!n) return null;
20569
+ let r = t + n.index;
20570
+ return e.slice(t, r).trim().length > 0 ? null : nt(e, r);
20571
+ }
20572
+ function it(e) {
20573
+ let t = /^la présente loi (?:s['’]appli(?:que|quent)|entr(?:e|ent) en vigueur) (?:[aà] compter (?:du|de|d['’])|au|le)\s*/u, n = /^la présente loi s['’]appli(?:que|quent)\s*:\s*/u, r = /\b[aà] compter (?:du|de|d['’])\s*/gu, i = [], a = "la présente loi", o = e.indexOf(a);
20574
+ for (; o !== -1;) {
20575
+ let s = e.indexOf(a, o + 15), c = e.slice(o, o + 1400), l = t.exec(c);
20576
+ if (l) {
20577
+ let e = rt(c, l[0].length);
20578
+ e && i.push(e.date);
20579
+ }
20580
+ let u = n.exec(c);
20581
+ if (u) {
20582
+ let e = /\barticle\s+\w/iu.exec(c), t = e === null ? c.slice(u[0].length) : c.slice(u[0].length, e.index);
20583
+ for (r.lastIndex = 0; r.exec(t) !== null;) {
20584
+ let e = rt(t, r.lastIndex);
20585
+ e && /^\s+pour\s+les\s+autres\s+dispositions\s+fiscales\b/iu.test(t.slice(e.stop)) && i.push(e.date);
20586
+ }
20587
+ }
20588
+ o = s;
20589
+ }
20590
+ return i;
20591
+ }
20592
+ function at(e) {
20593
+ let t = it(tt(e).toLowerCase()), n = Array.from(new Set(t));
20594
+ return n.length === 1 ? n[0] : void 0;
20595
+ }
20596
+ function ot(e) {
20597
+ return B(e).replace(/[’]/gu, "'").replace(/[‐‑‒–—]/gu, "-").replace(/^(?:(?:article\s+[^:]+|[a-z][.)]|[ivxlcdm]+\.|\d+°)\s*(?:-\s*)?)+/iu, "");
20598
+ }
20599
+ function U(e) {
20600
+ return e?.type === "tag";
20601
+ }
20602
+ function W(e, t) {
20603
+ return e.html(t) ?? "";
20604
+ }
20605
+ function st(e, t) {
20606
+ let n = [], r = /* @__PURE__ */ new Set();
20607
+ for (let i of e(t).find("a").get()) {
20608
+ let a = e(i).attr("href") ?? "", o = /\/legifrance\/(articles|sections|textes)\/([^?#"]+)/u.exec(a);
20609
+ if (!o) continue;
20610
+ let s = o[1] === "articles" ? "article" : o[1] === "sections" ? "division" : "text", c = o[2].replace(/\.md$/u, ""), l = `${s}\0${c}`;
20611
+ if (r.has(l)) continue;
20612
+ r.add(l);
20613
+ let u = z(e(i).text());
20614
+ n.push({
20615
+ id: c,
20616
+ ...ct(e, t, i) ? { insideFrenchQuotes: !0 } : {},
20617
+ ...u ? { text: u } : {},
20618
+ type: s
20619
+ });
20620
+ }
20621
+ return n;
20622
+ }
20623
+ function ct(e, t, n) {
20624
+ let r = lt(e, t, n);
20625
+ return (r.match(/«/gu) ?? []).length > (r.match(/»/gu) ?? []).length;
20626
+ }
20627
+ function lt(e, t, n) {
20628
+ if (t === n) return "";
20629
+ if (t.type === "text") return t.data ?? "";
20630
+ if (!U(t)) return "";
20631
+ let r = "";
20632
+ for (let i of e(t).contents().get()) {
20633
+ if (i === n) return r;
20634
+ if (U(i) && e.contains(i, n)) return r + lt(e, i, n);
20635
+ r += e(i).text();
20636
+ }
20637
+ return r;
20638
+ }
20639
+ function ut(e, t) {
20640
+ return t.map((t) => z(e(t).text())).filter(Boolean).join("\n");
20641
+ }
20642
+ function G(e) {
20643
+ let t = z(e).replace(/\s+:\s+/u, " : "), n = Je.exec(t), r = n?.[1]?.trim();
20644
+ if (!r) return null;
20645
+ let i = r.replace(/\s+/gu, ""), a = n?.[2]?.trim();
20646
+ return {
20647
+ label: `Article ${r}`,
20648
+ num: i,
20649
+ title: a
20650
+ };
20651
+ }
20652
+ function dt(e) {
20653
+ let t = B(e);
20654
+ return !t || Ye.test(t) ? "noise" : qe.test(e) ? "directive_candidate" : "context";
20655
+ }
20656
+ async function K(e, t, n) {
20657
+ if (n === void 0) throw Error("A document date is required to add links to legal references.");
20658
+ if (t.legiResolver === void 0 && t.canutesDb === void 0) throw Error("A Canutes database or an explicit legal resolver is required to add links to legal references.");
20659
+ let { output: r } = await ze({
20660
+ date: n,
20661
+ html: e,
20662
+ legiResolver: t.legiResolver ?? new Ke(t.canutesDb),
20663
+ linkBaseUrl: t.linkBaseUrl,
20664
+ linkType: t.linkType,
20665
+ logIgnoredReferencesTypes: t.logIgnoredReferencesTypes,
20666
+ logPartialReferences: t.logPartialReferences,
20667
+ logReferences: t.logReferences
20668
+ });
20669
+ return r ?? e;
20670
+ }
20671
+ function ft(e, t) {
20672
+ let n = e(t).closest("h1,h2,h3,h4,h5,h6,p,td,th").get(0), r = e(t).closest("table").get(0);
20673
+ return U(r) && U(n) && e(n).parents("table").get(0) === r ? r : U(n) ? n : t;
20674
+ }
20675
+ function pt(e) {
20676
+ let t = [], n = /* @__PURE__ */ new Set();
20677
+ return e("a[id]").each((r, i) => {
20678
+ let a = G(z(e(i).text()));
20679
+ if (!a) return;
20680
+ let o = e(i).attr("id");
20681
+ !o || n.has(o) || (n.add(o), t.push({
20682
+ id: o,
20683
+ ...a,
20684
+ element: i,
20685
+ container: ft(e, i)
20686
+ }));
20687
+ }), t;
20688
+ }
20689
+ function mt(e) {
20690
+ let t = e.next;
20691
+ for (; t !== null;) {
20692
+ if (U(t)) return t;
20693
+ t = t.next;
20694
+ }
20695
+ return null;
20696
+ }
20697
+ function ht(e, t, n) {
20698
+ let r = [t.container], i = n?.container;
20699
+ for (let e = mt(t.container); e !== null && e !== i; e = mt(e)) r.push(e);
20700
+ if (r.length > 1) return r;
20701
+ let a = e("body *").index(t.container), o = i ? e("body *").index(i) : -1;
20702
+ return e("body > *").get().filter((t) => {
20703
+ let n = e("body *").index(t);
20704
+ return n >= a && (o === -1 || n < o);
20705
+ });
20706
+ }
20707
+ function gt(e, t) {
20708
+ let n = [], r = /* @__PURE__ */ new Set();
20709
+ for (let i of t) {
20710
+ let t = "p,li,table", a = e(i).is(t) ? [i] : e(i).find(t).get();
20711
+ for (let t of a) e(t).is("table.akn-pastille-table,p.pastille") || r.has(t) || (r.add(t), n.push(t));
20712
+ }
20713
+ return n;
20714
+ }
20715
+ function _t(e, t, n) {
20716
+ let r = [], i = !1;
20717
+ for (let a of gt(e, n)) {
20718
+ let n = z(e(a).text());
20719
+ if (!n) continue;
20720
+ Ye.test(n) && (i = !0);
20721
+ let o = i ? "noise" : dt(n), s = `${t}-b${r.length + 1}`;
20722
+ e(a).attr("data-pjl-parsed-article-id", t), e(a).attr("data-pjl-parsed-block-id", s), r.push({
20723
+ id: s,
20724
+ articleId: t,
20725
+ kind: o,
20726
+ links: st(e, a),
20727
+ text: n,
20728
+ html: W(e, a)
20729
+ });
20730
+ }
20731
+ return r;
20732
+ }
20733
+ function vt(e, t) {
20734
+ if (t.length === 0) return e;
20735
+ let n = `<div style="display: none;">\n${t.map((e) => `<p class="assnatTOC6"><a href="#${`_TocArt${(e.num ?? e.label.replace(/^Article\s+/iu, "")).replace(/\s+/gu, "")}`}"><span class="assnatHyperlink" style="font-weight:bold; text-decoration:none; color:#000000">${e.label.toUpperCase()}</span></a></p>`).join("\n")}\n</div>`;
20736
+ return e.includes("class=\"assnatSection3\"") ? e.replace(/(<div class="assnatSection3">)/u, `${n}$1`) : e.includes("id=\"formCorrection:panel:1:table\"") ? e.replace(/(<div id="formCorrection:panel:1:table">)/u, `${n}$1`) : `${n}\n${e}`;
20737
+ }
20738
+ function yt(e) {
20739
+ let t = y(e);
20740
+ for (let e of pt(t)) {
20741
+ let n = `_TocArt${(e.num ?? e.label.replace(/^Article\s+/iu, "")).replace(/\s+/gu, "")}`, r = t(e.element), i = r.attr("id");
20742
+ i?.startsWith("_TocArt") || (i?.startsWith("_Toc") && !bt(t, i, e.element) && r.before(t("<span></span>").attr("id", i)), r.attr("id", n));
20743
+ }
20744
+ return t.html();
20745
+ }
20746
+ function bt(e, t, n) {
20747
+ for (let r of e("[id]").get()) if (r !== n && e(r).attr("id") === t) return !0;
20748
+ return !1;
20749
+ }
20750
+ function xt(e, t) {
20751
+ let n = ot("sourceText" in t ? t.sourceText : "");
20752
+ if (n) return e.filter((e) => e.kind === "directive_candidate").find((e) => {
20753
+ let t = ot(e.text);
20754
+ return t.length > 0 && (n.includes(t) || t.includes(n));
20755
+ });
20756
+ }
20757
+ function St(e, t) {
20758
+ if (t) return t.blockIds.map((t) => e.get(t)).find((e) => e?.kind === "directive_candidate");
20759
+ }
20760
+ function Ct(e) {
20761
+ return e?.links.filter((e) => !e.insideFrenchQuotes && (e.type === "article" || e.type === "division")).map((e) => e.id) ?? [];
20762
+ }
20763
+ var wt = [
20764
+ /^([IVXLCDM]+)\s*[.).]?\s*[–—-]/iu,
20765
+ /^(\d+°)\s+/u,
20766
+ /^([a-z])\)\s+/iu,
20767
+ /^([ivxlcdm]+)\)\s+/iu
20768
+ ];
20769
+ function Tt(e) {
20770
+ let t = z(e);
20771
+ if (!t) return;
20772
+ let n = wt.findIndex((e) => e.test(t));
20773
+ return n === -1 ? t.endsWith(":") ? 0 : void 0 : n + 1;
20774
+ }
20775
+ function Et(e) {
20776
+ let t = /* @__PURE__ */ new Map(), n = [];
20777
+ for (let r of e) {
20778
+ let e = Tt(r.text);
20779
+ if (e === void 0) {
20780
+ t.set(r.id, [...n, r]);
20781
+ continue;
20782
+ }
20783
+ n.length = Math.min(n.length, e), t.set(r.id, [...n, r]), n[e] = r, n.length = e + 1;
20784
+ }
20785
+ return t;
20786
+ }
20787
+ function Dt(e, t) {
20788
+ let n = [], r = /* @__PURE__ */ new Set();
20789
+ for (let i of [...e ?? [], ...t]) i !== void 0 && (r.has(i.id) || (r.add(i.id), n.push(i)));
20790
+ return n;
20791
+ }
20792
+ function Ot(e, t, n) {
20793
+ if (!t) return;
20794
+ let r = Dt(e, t.blockIds.map((e) => n.get(e)).filter((e) => e !== void 0));
20795
+ if (r.length === 0) return;
20796
+ let i = r.map((e) => e.id);
20797
+ if (i.length === t.blockIds.length && i.every((e, n) => e === t.blockIds[n])) return;
20798
+ let a = r.map((e) => e.text).join("\n"), o = r.map((e) => e.html).join("\n"), s = a.indexOf(t.text), c = s === -1 ? 0 : s;
20799
+ return {
20800
+ blockIds: i,
20801
+ text: a,
20802
+ html: o,
20803
+ position: {
20804
+ start: c + t.position.start,
20805
+ stop: c + t.position.stop
20806
+ }
20807
+ };
20808
+ }
20809
+ function kt(e) {
20810
+ let t = [], n = 0;
20811
+ for (let r of e.blocks) {
20812
+ let i = e.directiveText.indexOf(r.text, n);
20813
+ if (i === -1 && (i = e.directiveText.indexOf(r.text)), i === -1) continue;
20814
+ let a = i + r.text.length;
20815
+ t.push({
20816
+ block: r,
20817
+ start: i,
20818
+ stop: a
20819
+ }), n = a;
20820
+ }
20821
+ return t;
20822
+ }
20823
+ function At(e, t, n) {
20824
+ let { start: r, stop: i } = n.sourcePosition, a = t.filter((e) => e.stop >= r && e.start <= i);
20825
+ if (a.length === 0) return;
20826
+ let o = a[0], s = a[a.length - 1], c = o.start, l = s.stop;
20827
+ return {
20828
+ blockIds: a.map((e) => e.block.id),
20829
+ text: e.directiveText.slice(c, l),
20830
+ html: a.map((e) => e.block.html).join("\n"),
20831
+ position: {
20832
+ start: Math.max(0, r - c),
20833
+ stop: Math.min(l, i) - c
20834
+ }
20835
+ };
20836
+ }
20837
+ function jt(e, t, n) {
20838
+ if (!t) return;
20839
+ let r = e.directiveText.indexOf(t.text);
20840
+ if (r === -1) return;
20841
+ let i = n.sourcePosition.start - r, a = n.sourcePosition.stop - r;
20842
+ return i < 0 || a < i || a > t.text.length ? {
20843
+ start: 0,
20844
+ stop: t.text.length
20845
+ } : {
20846
+ start: i,
20847
+ stop: a
20848
+ };
20849
+ }
20850
+ function Mt(e) {
20851
+ let t = kt(e), n = new Map(e.blocks.map((e) => [e.id, e])), r = Et(e.blocks), i = /* @__PURE__ */ new Map(), a = [];
20852
+ for (let t of e.blocks) {
20853
+ let e = Ct(t);
20854
+ e.length > 0 && (a = e), i.set(t.id, a);
20855
+ }
20856
+ return m(e.directiveText).map((a) => {
20857
+ let o = At(e, t, a), s = St(n, o) ?? xt(e.blocks, a), c = Ct(s), l = c.length > 0 ? c : s?.id === void 0 ? [] : i.get(s.id) ?? [], u = jt(e, s, a), d = Ot(s?.id === void 0 ? void 0 : r.get(s.id), o, n);
20858
+ return {
20859
+ articleId: e.id,
20860
+ blockId: s?.id,
20861
+ ...u === void 0 ? {} : { sourceBlockPosition: u },
20862
+ ...o === void 0 ? {} : {
20863
+ sourceBlockIds: o.blockIds,
20864
+ sourceBlockText: o.text,
20865
+ sourceBlockHtml: o.html,
20866
+ sourceBlockPosition: o.position
20867
+ },
20868
+ ...d === void 0 ? {} : {
20869
+ sourceContextBlockIds: d.blockIds,
20870
+ sourceContextPosition: d.position
20871
+ },
20872
+ directive: a,
20873
+ ...l.length > 0 ? { targetIds: l } : {}
20874
+ };
20875
+ });
20876
+ }
20877
+ function Nt(e) {
20878
+ let t = /* @__PURE__ */ new Map(), n = [], r = /* @__PURE__ */ new Set();
20879
+ for (let i of e) {
20880
+ let e = $e(i.directive);
20881
+ if (e.length === 0) continue;
20882
+ let a = e.map(({ num: e }) => ({
20883
+ definitionId: `${i.articleId}:article:${Xe(e)}`,
20884
+ num: e
20885
+ }));
20886
+ t.set(i, a);
20887
+ for (let [t, o] of e.entries()) {
20888
+ let e = a[t];
20889
+ e === void 0 || r.has(e.definitionId) || (r.add(e.definitionId), n.push({
20890
+ ...e,
20891
+ articleId: i.articleId,
20892
+ blockId: i.blockId,
20893
+ html: o.text,
20894
+ ...i.targetIds === void 0 ? {} : { parentTargetIds: i.targetIds },
20895
+ sourceDirectiveId: i.directive.sourceText,
20896
+ ...i.sourceBlockHtml === void 0 ? {} : { sourceBlockHtml: i.sourceBlockHtml },
20897
+ ...i.sourceBlockText === void 0 ? {} : { sourceBlockText: i.sourceBlockText },
20898
+ text: o.text
20899
+ }));
20900
+ }
20901
+ }
20902
+ return {
20903
+ createdArticlesByDirective: t,
20904
+ definitions: n
20905
+ };
20906
+ }
20907
+ function Pt(e, t, n) {
20908
+ let r = new Map(t.map((e) => [V(e.num), e]));
20909
+ return e.map((e) => {
20910
+ let t = n.get(e), i = t?.[0], a = [...H(e.directive.reference)].map((e) => r.get(V(e))).filter((e) => e !== void 0 && e.definitionId !== i?.definitionId)[0], o = a === void 0 ? void 0 : {
20911
+ definitionId: a.definitionId,
20912
+ num: a.num
20913
+ }, s = et(e.directive), c = (e.targetIds?.length ?? 0) > 0;
20914
+ return {
20915
+ ...e,
20916
+ ...i === void 0 ? {} : { createdArticle: i },
20917
+ ...t !== void 0 && t.length > 0 ? { createdArticles: t } : {},
20918
+ ...o !== void 0 && (s || !c) ? { internalTarget: {
20919
+ ...o,
20920
+ resolution: s ? "explicit" : "fallback"
20921
+ } } : {},
20922
+ ...o !== void 0 && c && !s ? { internalTargetAmbiguity: o } : {}
20923
+ };
20924
+ });
20925
+ }
20926
+ function Ft(e, t, n, r, i, a) {
20927
+ let o = i.map((e) => e.directiveText).filter(Boolean).join("\n"), s = at(i.map((e) => e.text).join("\n")), c = i.flatMap(Mt), { createdArticlesByDirective: l, definitions: u } = Nt(c), d = Pt(c, u, l);
20928
+ return {
20929
+ sourceFormat: e,
20930
+ documentDate: r,
20931
+ html: t,
20932
+ htmlWithLinks: n,
20933
+ tableOfContents: a ?? C(o),
20934
+ articles: i,
20935
+ ...s ? { globalApplicabilityDate: s } : {},
20936
+ ...u.length > 0 ? { internalArticleDefinitions: u } : {},
20937
+ directives: d
20938
+ };
20939
+ }
20940
+ function It(e) {
20941
+ let t = C(e.map((e) => e.directiveText).filter(Boolean).join("\n")), n = new Map(e.map((e) => [B(e.label), e.id])), r = 0;
20942
+ function i(e) {
20943
+ for (let t of e.articles ?? []) r += 1, t.id ??= n.get(B(t.line));
20944
+ for (let t of e.divisions ?? []) i(t);
20945
+ }
20946
+ return i(t), r > 0 ? t : { articles: e.map((e) => ({
20947
+ id: e.id,
20948
+ line: e.title ? `${e.label} : ${e.title}` : e.label,
20949
+ type: "article"
20950
+ })) };
20951
+ }
20952
+ async function Lt(e, t) {
20953
+ let n = new O("parseAssembleeBillRaw"), r = t.linkedHtml === void 0 ? await n.time("linkAssembleeBillRaw", () => Rt(e, t)) : void 0, i = n.timeSync("applyArticleAnchorIds", () => yt(t.linkedHtml ?? r.linkedHtml), { inputSize: e.length }), a = n.timeSync("cheerioLoadLinkedHtml", () => y(i)), o = n.timeSync("extractArticleHeadings", () => pt(a)), s = n.timeSync("extractArticlesAndBlocks", () => o.map((e, t) => {
20954
+ let n = ht(a, e, o[t + 1]), r = _t(a, e.id, n), i = r.filter((e) => e.kind !== "noise").map((e) => e.text).join("\n");
20955
+ return {
20956
+ id: e.id,
20957
+ label: e.label,
20958
+ num: e.num,
20959
+ title: e.title,
20960
+ text: ut(a, n),
20961
+ html: n.map((e) => W(a, e)).join("\n"),
20962
+ directiveText: i,
20963
+ blocks: r
20964
+ };
20965
+ }), { count: o.length }), c = n.timeSync("injectHiddenArticleSummary", () => vt(a.html(), s)), l = n.timeSync("buildAssembleeTableOfContents", () => It(s), { count: s.length }), u = n.timeSync("buildParsedDocument", () => Ft("assemblee-html", e, c, t.date, s, l));
20966
+ return n.log({
20967
+ articleCount: u.articles.length,
20968
+ blockCount: u.articles.reduce((e, t) => e + t.blocks.length, 0),
20969
+ directiveCount: u.directives.length,
20970
+ targetDirectiveCount: u.directives.filter((e) => e.targetIds !== void 0).length
20971
+ }), u;
20972
+ }
20973
+ async function Rt(e, t) {
20974
+ return {
20975
+ sourceFormat: "assemblee-html",
20976
+ documentDate: t.date,
20977
+ html: e,
20978
+ linkedHtml: await K(e, t, t.date)
20979
+ };
20980
+ }
20981
+ function q(e) {
20982
+ return e.replace(/&/gu, "&amp;").replace(/</gu, "&lt;").replace(/>/gu, "&gt;").replace(/"/gu, "&quot;");
20983
+ }
20984
+ function zt(e) {
20985
+ let t = e;
20986
+ for (let e = 0; e < 3; e++) {
20987
+ let e = t;
20988
+ if (t = t.replace(/&amp;/gu, "&").replace(/&lt;/gu, "<").replace(/&gt;/gu, ">").replace(/&quot;/gu, "\"").replace(/&#39;/gu, "'").replace(/&apos;/gu, "'").replace(/&nbsp;/gu, "\xA0"), t === e) break;
20989
+ }
20990
+ return t;
20991
+ }
20992
+ function Bt(e) {
20993
+ return /(?:&lt;|&amp;lt;)\/?(?:p|br|span|b|i|u|sup|sub|table|thead|tbody|tr|th|td|ul|ol|li)\b/iu.test(e);
20994
+ }
20995
+ function J(e) {
20996
+ return e.name.replace(/^.*:/u, "");
20997
+ }
20998
+ function Vt(e, t) {
20999
+ return t.children.map((t) => Y(e, t)).filter(Boolean).join("");
21000
+ }
21001
+ function Ht(e, t) {
21002
+ return t.children.map((t) => t.type === "text" && Bt(t.data) ? zt(t.data) : Y(e, t)).filter(Boolean).join("");
21003
+ }
21004
+ function Y(e, t) {
21005
+ if (t.type === "text") {
21006
+ let e = t.data.replace(/\s+\./gu, ".");
21007
+ return Bt(e) ? zt(e) : q(e);
21008
+ }
21009
+ if (!U(t)) return "";
21010
+ let n = J(t), r = Vt(e, t);
21011
+ switch (n) {
21012
+ case "p": return `<p${X(e, t, [
21013
+ "id",
21014
+ "class",
21015
+ "align",
21016
+ "valign",
21017
+ "style"
21018
+ ])}>${r}</p>`;
21019
+ case "br": return "<br>";
21020
+ case "span":
21021
+ case "b":
21022
+ case "i":
21023
+ case "u":
21024
+ case "sup":
21025
+ case "sub":
21026
+ case "abbr": return `<${n}${X(e, t, [
21027
+ "id",
21028
+ "class",
21029
+ "title",
21030
+ "style"
21031
+ ])}>${r}</${n}>`;
21032
+ case "a": return `<a href="${q(e(t).attr("href") ?? e(t).attr("target") ?? "#")}"${X(e, t, [
21033
+ "id",
21034
+ "class",
21035
+ "title",
21036
+ "style"
21037
+ ])}>${r}</a>`;
21038
+ case "table":
21039
+ case "thead":
21040
+ case "tbody":
21041
+ case "tr":
21042
+ case "th":
21043
+ case "td": return Ut(e, t, n, r);
21044
+ case "caption": return `<caption${X(e, t, [
21045
+ "id",
21046
+ "class",
21047
+ "align",
21048
+ "style"
21049
+ ])}>${r}</caption>`;
21050
+ case "num": return `<span class="akn-num">${r}</span> `;
21051
+ case "heading": return `<p class="akn-heading">${r}</p>`;
21052
+ case "content": return Ht(e, t);
21053
+ case "alinea": return Q(e, t, "div", "akn-alinea");
21054
+ case "article": return Q(e, t, "article", "akn-article");
21055
+ case "blockList":
21056
+ case "list": return `<div class="akn-list">${r}</div>`;
21057
+ case "item": return Q(e, t, "div", "akn-item");
21058
+ case "listIntroduction":
21059
+ case "listWrapUp":
21060
+ case "intro":
21061
+ case "wrapUp": return `<div class="akn-${n}">${r}</div>`;
21062
+ case "part":
21063
+ case "title":
21064
+ case "chapter":
21065
+ case "section":
21066
+ case "paragraph":
21067
+ case "division":
21068
+ case "point":
21069
+ case "indent":
21070
+ case "book":
21071
+ case "tome":
21072
+ case "subchapter":
21073
+ case "subsection": return Q(e, t, "section", `akn-${n}`);
21074
+ case "crossHeading": return `<p class="akn-cross-heading">${r}</p>`;
21075
+ default: return r;
21076
+ }
21077
+ }
21078
+ function X(e, t, n, r = {}) {
21079
+ let i = [];
21080
+ for (let r of n) {
21081
+ if (r === "style") continue;
21082
+ let n = e(t).attr(r);
21083
+ n !== void 0 && i.push(`${r}="${q(n)}"`);
21084
+ }
21085
+ let a = r.style ?? e(t).attr("style");
21086
+ return a && i.push(`style="${q(a)}"`), i.length > 0 ? ` ${i.join(" ")}` : "";
21087
+ }
21088
+ function Ut(e, t, n, r) {
21089
+ return `<${n}${X(e, t, [
21090
+ "id",
21091
+ "class",
21092
+ "colspan",
21093
+ "rowspan",
21094
+ "align",
21095
+ "valign",
21096
+ "width",
21097
+ "height",
21098
+ "border",
21099
+ "cellspacing",
21100
+ "cellpadding",
21101
+ "style"
21102
+ ], { style: Wt(e, t, n) })}>${r}</${n}>`;
21103
+ }
21104
+ function Wt(e, t, n) {
21105
+ let r = e(t).attr("style") ?? "";
21106
+ return (n === "td" || n === "th") && /font-weight\s*:\s*bold/iu.test(r) && !/text-align\s*:/iu.test(r) && (r = Gt(r, "text-align", "center")), r || void 0;
21107
+ }
21108
+ function Gt(e, t, n) {
21109
+ let r = e.trim();
21110
+ return `${r}${r && !r.endsWith(";") ? ";" : ""} ${t}: ${n};`.trim();
21111
+ }
21112
+ function Kt(e, t) {
21113
+ let n = [z(e(t).children("num").first().text()), z(e(t).children("heading").first().text())].filter(Boolean);
21114
+ return n.length === 0 ? "" : `<p class="akn-heading">${q(n.join(" "))}</p>`;
21115
+ }
21116
+ function qt(e, t) {
21117
+ if (!t) return !1;
21118
+ let n = (e) => z(e).replace(/\s+/gu, " ").replace(/\s*[..]\s*(?=[–—-])/gu, " ").trim();
21119
+ return n(z(e.replace(/<[^>]*>/gu, " ").replace(/&nbsp;/gu, " ").replace(/&#xa0;/giu, " ").replace(/&#x2013;/giu, "–"))).startsWith(n(t));
21120
+ }
21121
+ function Jt(e) {
21122
+ let t = q(e);
21123
+ return `<p data-pastille="${t}" class="pastille"><span aria-label="pastille ${t}">${t}</span></p>`;
21124
+ }
21125
+ function Yt(e, t) {
21126
+ return Xt([Zt({
21127
+ content: e,
21128
+ pastille: t
21129
+ })]);
21130
+ }
21131
+ function Xt(e) {
21132
+ return `<table class="fixed-size large akn-pastille-table"><colgroup><col style="width: 5.0%;" class="texte-col-0 texte-col-pastille"><col style="width: 95.0%;" class="texte-col-1"></colgroup><tbody>${e.join("\n")}</tbody></table>`;
21133
+ }
21134
+ function Zt({ content: e, pastille: t, style: n, contextClass: r }) {
21135
+ let i = n ? ` style="${q(n)}"` : "", a = r ? ` ${q(r)}` : "";
21136
+ return `<tr${r ? ` class="${q(r)} hideable"` : ""}><td style="overflow: hidden; width: 5.0%;" class="texte-col-0 texte-col-pastille no-right-border"><div class="tableauComparatifCell${a}">${Jt(t)}</div></td><td style="overflow: hidden; width: 95.0%;" class="texte-col-1 no-right-border"><div class="tableauComparatifCell${a}"${i}>${e}</div></td></tr>`;
21137
+ }
21138
+ function Z({ content: e, style: t, contextClass: n }) {
21139
+ let r = t ? ` style="${q(t)}"` : "", i = n ? ` ${q(n)}` : "";
21140
+ return `<tr${n ? ` class="${q(n)} hideable"` : ""}><td style="overflow: hidden; width: 5.0%;" class="texte-col-0 no-right-border"><div class="tableauComparatifCell${i}"><p class="pastille"><br></p></div></td><td style="overflow: hidden; width: 95.0%;" class="texte-col-1 no-right-border"><div class="tableauComparatifCell${i}"${r}>${e}</div></td></tr>`;
21141
+ }
21142
+ function Qt(e, t) {
21143
+ return e(t).attr("data:pastille") ?? e(t).attr("pastille");
21144
+ }
21145
+ function $t(e, t) {
21146
+ return e(t).find("alinea[data\\:pastille],alinea[pastille]").length > 0;
21147
+ }
21148
+ function en(e, t) {
21149
+ return e(t).children().get().filter((e) => U(e) ? J(e) === "content" : !1).map((t) => Y(e, t)).filter(Boolean).join("\n");
21150
+ }
21151
+ function tn(e, t) {
21152
+ let n = [];
21153
+ return e(t).children().each((t, r) => {
21154
+ if (!U(r)) return;
21155
+ let i = J(r);
21156
+ i === "num" || i === "heading" || i === "content" || n.push(Y(e, r));
21157
+ }), n.filter(Boolean);
21158
+ }
21159
+ function nn(e, t) {
21160
+ let n = [], r = J(t), i = r === "alinea" ? Qt(e, t) : void 0, a = en(e, t), o = rn(e, t, r, i), s = un(e, t);
21161
+ if (i) {
21162
+ let r = [qt(a, z(e(t).children("num").first().text())) ? "" : Kt(e, t), a].filter(Boolean).join("\n");
21163
+ z(r) && n.push(Zt({
21164
+ content: r,
21165
+ pastille: i,
21166
+ style: o,
21167
+ contextClass: s
21168
+ }));
21169
+ } else a && n.push(Z({
21170
+ content: a,
21171
+ style: o,
21172
+ contextClass: s
21173
+ }));
21174
+ for (let r of e(t).children().get()) {
21175
+ if (!U(r)) continue;
21176
+ let t = J(r);
21177
+ t === "num" || t === "heading" || t === "content" || (t === "alinea" || $t(e, r)) && n.push(...nn(e, r));
21178
+ }
21179
+ return n;
21180
+ }
21181
+ function Q(e, t, n, r) {
21182
+ let i = J(t), a = e(t).attr("eId") ?? e(t).attr("GUID"), o = Qt(e, t), s = rn(e, t, i, o), c = [`<${n} ${[
21183
+ a ? `id="${q(a)}"` : void 0,
21184
+ `class="${r}"`,
21185
+ o ? `data-pastille="${q(o)}"` : void 0,
21186
+ s ? `style="${q(s)}"` : void 0
21187
+ ].filter((e) => e !== void 0).join(" ")}>`];
21188
+ if (i === "part" || i === "title") {
21189
+ let r = sn(e, t, i), a = ln(e, t), o = r ? [Z({
21190
+ content: r,
21191
+ contextClass: a
21192
+ })] : [], s = () => {
21193
+ o.length !== 0 && (c.push(on(o)), o = []);
21194
+ };
21195
+ return e(t).children().each((t, n) => {
21196
+ if (!U(n)) return;
21197
+ let r = J(n);
21198
+ if (!(r === "num" || r === "heading" || r === "content")) {
21199
+ if (r === "alinea") {
21200
+ o.push(...nn(e, n));
21201
+ return;
21202
+ }
21203
+ s(), c.push(Y(e, n));
21204
+ }
21205
+ }), s(), c.push(`</${n}>`), c.join("\n");
21206
+ }
21207
+ if (i === "article") {
21208
+ let r = z(e(t).children("num").first().text()), i = z(e(t).children("heading").first().text()), a = G(r) ?? {
21209
+ label: r,
21210
+ num: r
21211
+ }, o = `<p class="TCNumArticle as-text toc-article dispositif" id="${q(`_TocArt${(a.num ?? r).replace(/\s+/gu, "")}`)}">${q(a.label)}${i ? ` : ${q(i)}` : ""}</p>`;
21212
+ if ($t(e, t)) {
21213
+ let r = [Z({
21214
+ content: o,
21215
+ contextClass: fn(a.label)
21216
+ }), ...nn(e, t)];
21217
+ c.push(Xt(r));
21218
+ for (let n of tn(e, t)) n.includes("akn-pastille-table") || c.push(n);
21219
+ return c.push(`</${n}>`), c.join("\n");
21220
+ }
21221
+ c.push(o);
21222
+ }
21223
+ let l = [];
21224
+ for (let n of ["content", "children"]) e(t).children().each((t, r) => {
21225
+ if (!U(r)) return;
21226
+ let i = J(r);
21227
+ i === "num" || i === "heading" || n === "content" && i !== "content" || n === "children" && i === "content" || l.push(Y(e, r));
21228
+ });
21229
+ let u = l.join("\n");
21230
+ if (i !== "article") {
21231
+ let n = qt(u, z(e(t).children("num").first().text())) ? "" : Kt(e, t);
21232
+ n && c.push(n);
21233
+ }
21234
+ return c.push(o ? Yt(u, o) : u), c.push(`</${n}>`), c.join("\n");
21235
+ }
21236
+ function rn(e, t, n, r) {
21237
+ let i = an(e(t).attr("style") ?? "", "font-family");
21238
+ return !r && n !== "article" && /font-weight\s*:\s*bold/iu.test(i) && !/text-align\s*:/iu.test(i) && (i = Gt(i, "text-align", "center")), i || void 0;
21239
+ }
21240
+ function an(e, t) {
21241
+ return e.split(";").map((e) => e.trim()).filter(Boolean).filter((e) => !e.toLowerCase().startsWith(`${t.toLowerCase()}:`)).join(";");
21242
+ }
21243
+ function on(e) {
21244
+ return `<table class="fixed-size large akn-section-table"><colgroup><col style="width: 5.0%;" class="texte-col-0 texte-col-pastille"><col style="width: 95.0%;" class="texte-col-1"></colgroup><tbody>${e.join("\n")}</tbody></table>`;
21245
+ }
21246
+ function sn(e, t, n) {
21247
+ let r = z(e(t).children("num").first().text()), i = z(e(t).children("heading").first().text()), a = cn(n), o = [];
21248
+ return r && o.push(`<p class="${a.num} as-text dispositif"><span aria-label="">${q(r)}</span></p>`), i && o.push(`<p class="${a.heading} as-text dispositif"><span aria-label="">${q(i)}</span></p>`), o.join("\n");
21249
+ }
21250
+ function cn(e) {
21251
+ switch (e) {
21252
+ case "part": return {
21253
+ num: "TCNumPartie",
21254
+ heading: "TCIntPartie"
21255
+ };
21256
+ case "title": return {
21257
+ num: "TCNumTitre",
21258
+ heading: "TCIntTitre"
21259
+ };
21260
+ case "chapter": return {
21261
+ num: "TCNumChapitre",
21262
+ heading: "TCIntChapitre"
21263
+ };
21264
+ case "section": return {
21265
+ num: "TCNumSection",
21266
+ heading: "TCIntSection"
21267
+ };
21268
+ default: return {
21269
+ num: "TCNumDivision",
21270
+ heading: "TCIntDivision"
21271
+ };
21272
+ }
21273
+ }
21274
+ function ln(e, t) {
21275
+ let n = dn(z(e(t).children("num").first().text()));
21276
+ if (n) return n;
21277
+ for (let n of e(t).parents().get()) {
21278
+ if (!U(n)) continue;
21279
+ let t = J(n);
21280
+ if (t !== "title" && t !== "part") continue;
21281
+ let r = dn(z(e(n).children("num").first().text()));
21282
+ if (r) return r;
21283
+ }
21284
+ }
21285
+ function un(e, t) {
21286
+ return ln(e, t);
21287
+ }
21288
+ function dn(e) {
21289
+ let [t, ...n] = z(e).split(/\s+/u);
21290
+ if (!t || n.length === 0) return;
21291
+ let r = t.toLocaleLowerCase("fr-FR");
21292
+ if ([
21293
+ "partie",
21294
+ "titre",
21295
+ "chapitre",
21296
+ "section"
21297
+ ].includes(r)) return `${r}-${n.join("_")}`;
21298
+ }
21299
+ function fn(e) {
21300
+ return `article-${z(e).replace(/^Article\s+/iu, "").replace(/\s+/gu, "_")} article`;
21301
+ }
21302
+ function pn(e) {
21303
+ switch (e) {
21304
+ case "part": return "partie";
21305
+ case "book": return "livre";
21306
+ case "title": return "titre";
21307
+ case "chapter": return "chapitre";
21308
+ case "section": return "section";
21309
+ case "subsection": return "sous-section";
21310
+ case "paragraph": return "paragraphe";
21311
+ default: return;
21312
+ }
21313
+ }
21314
+ function mn(e, t) {
21315
+ return [z(e(t).children("num").first().text()), z(e(t).children("heading").first().text())].filter(Boolean).join(" ");
21316
+ }
21317
+ function hn(e, t) {
21318
+ let n = z(e(t).children("num").first().text()), r = z(e(t).children("heading").first().text()), i = G(n) ?? {
21319
+ label: n,
21320
+ num: n
21321
+ };
21322
+ return {
21323
+ id: `_TocArt${(i.num ?? n).replace(/\s+/gu, "")}`,
21324
+ line: [i.label, r].filter(Boolean).join(" : "),
21325
+ type: "article"
21326
+ };
21327
+ }
21328
+ function gn(e, t) {
21329
+ t.articles?.length && (e.articles ??= [], e.articles.push(...t.articles)), t.divisions?.length && (e.divisions ??= [], e.divisions.push(...t.divisions));
21330
+ }
21331
+ function _n(e, t) {
21332
+ let n = {};
21333
+ return e(t).children().each((t, r) => {
21334
+ if (!U(r)) return;
21335
+ let i = J(r);
21336
+ if (i === "article") {
21337
+ n.articles ??= [], n.articles.push(hn(e, r));
21338
+ return;
21339
+ }
21340
+ let a = pn(i);
21341
+ if (!a) {
21342
+ gn(n, _n(e, r));
21343
+ return;
21344
+ }
21345
+ let o = mn(e, r), s = _n(e, r);
21346
+ !o && !s.articles?.length && !s.divisions?.length || (n.divisions ??= [], n.divisions.push({
21347
+ ...s,
21348
+ id: e(r).attr("eId") ?? e(r).attr("GUID"),
21349
+ line: o,
21350
+ type: a
21351
+ }));
21352
+ }), n;
21353
+ }
21354
+ function vn(e) {
21355
+ let t = e("body").first().get(0);
21356
+ return t === void 0 ? {} : _n(e, t);
21357
+ }
21358
+ function yn(e) {
21359
+ return e("FRBRExpression FRBRdate[name=\"#depot\"]").attr("date") ?? e("FRBRWork FRBRdate[name=\"#presentation\"]").attr("date");
21360
+ }
21361
+ function bn(e) {
21362
+ let t = e("preamble").first(), n = e("body").first(), r = ["<div class=\"akn-bill\">"];
21363
+ return t.length > 0 && (r.push("<section class=\"akn-preamble\">"), r.push(Vt(e, t.get(0))), r.push("</section>")), r.push("<section class=\"akn-body\">"), n.children().each((t, n) => {
21364
+ U(n) && r.push(J(n) === "article" ? Q(e, n, "article", "akn-article") : Y(e, n));
21365
+ }), r.push("</section></div>"), r.join("\n");
21366
+ }
21367
+ function xn(e) {
21368
+ let t = y(e, { xml: {
21369
+ decodeEntities: !1,
21370
+ lowerCaseTags: !1,
21371
+ lowerCaseAttributeNames: !1,
21372
+ xmlMode: !0
21373
+ } }), n = yn(t), r = bn(t);
21374
+ return {
21375
+ sourceFormat: "akoma-ntoso",
21376
+ documentDate: n,
21377
+ html: r,
21378
+ linkedHtml: r
21379
+ };
21380
+ }
21381
+ function Sn(e) {
21382
+ return Cn(y(e));
21383
+ }
21384
+ function Cn(e) {
21385
+ let t = [];
21386
+ return e("article.akn-article").each((n, r) => {
21387
+ let i = e(r).children("p.TCNumArticle").first().get(0), a = z(i ? e(i).text() : ""), o = G(a) ?? { label: a || `Article ${n + 1}` }, s = e(r).attr("id") ?? `akn-article-${String(n + 1).padStart(3, "0")}`, c = [r], l = _t(e, s, c), u = l.filter((e) => e.kind !== "noise").map((e) => e.text).join("\n");
21388
+ t.push({
21389
+ id: s,
21390
+ label: o.label,
21391
+ num: o.num,
21392
+ title: o.title,
21393
+ text: ut(e, c),
21394
+ html: W(e, r),
21395
+ directiveText: u,
21396
+ blocks: l
21397
+ });
21398
+ }), t;
21399
+ }
21400
+ function wn(e) {
21401
+ let t = y(e);
21402
+ return {
21403
+ articles: Cn(t),
21404
+ htmlWithLinks: t.html()
21405
+ };
21406
+ }
21407
+ async function Tn(e, t) {
21408
+ let n = new O("parseAkomaNtosoBillRaw"), r = n.timeSync("cheerioLoadXml", () => y(e, { xml: {
21409
+ decodeEntities: !1,
21410
+ lowerCaseTags: !1,
21411
+ lowerCaseAttributeNames: !1,
21412
+ xmlMode: !0
21413
+ } })), i = t.date ?? yn(r), a = n.timeSync("renderAknHtml", () => bn(r), { inputSize: e.length }), o = t.linkedHtml ?? await n.time("addLinksToRenderedAknHtml", () => K(a, {
21414
+ ...t,
21415
+ date: i
21416
+ }, i)), s = n.timeSync("extractRenderedAknArticles", () => Sn(a)), c = n.timeSync("injectHiddenArticleSummary", () => vt(o, s)), { articles: l, htmlWithLinks: u } = n.timeSync("extractLinkedAknArticlesAndTaggedHtml", () => wn(c)), d = l.length > 0 ? l : s, f = n.timeSync("extractAknTableOfContents", () => vn(r)), p = n.timeSync("buildParsedDocument", () => Ft("akoma-ntoso", a, l.length > 0 ? u : c, i, d, f));
21417
+ return n.log({
21418
+ articleCount: p.articles.length,
21419
+ blockCount: p.articles.reduce((e, t) => e + t.blocks.length, 0),
21420
+ directiveCount: p.directives.length,
21421
+ targetDirectiveCount: p.directives.filter((e) => e.targetIds !== void 0).length
21422
+ }), p;
21423
+ }
21424
+ async function En(e, t) {
21425
+ let n = xn(e), r = t.date ?? n.documentDate;
21426
+ return {
21427
+ sourceFormat: "akoma-ntoso",
21428
+ documentDate: r,
21429
+ html: n.html,
21430
+ linkedHtml: await K(n.html, t, r)
21431
+ };
21432
+ }
21433
+ //#endregion
21434
+ //#region src/lib/legi/resolver.ts
21435
+ var Dn = ["canutes", "f_legi"], On = "canutes";
21436
+ function kn(e) {
21437
+ if (e === void 0 || e === "") return On;
21438
+ if (Dn.includes(e)) return e;
21439
+ throw Error(`Unknown legal resolver "${e}". Expected one of: ${Dn.join(", ")}`);
21440
+ }
21441
+ //#endregion
19478
21442
  //#region src/lib/server/tables_of_contents.ts
19479
- async function F(e, n, i, a) {
19480
- let o = j(await s.readFile(e, { encoding: "utf-8" }), n), c = o.output, l = new r(c), u = await s.readJson(i, { encoding: "utf-8" });
19481
- for await (let e of t({
19482
- context: l,
19483
- tableOfContents: u,
19484
- transformation: o
21443
+ async function An(e, t, r, i) {
21444
+ let a = E(await w.readFile(e, { encoding: "utf-8" }), t), o = a.output, s = new n(o), c = await w.readJson(r, { encoding: "utf-8" });
21445
+ for await (let e of g({
21446
+ context: s,
21447
+ tableOfContents: c,
21448
+ transformation: a
19485
21449
  }));
19486
- await s.writeJson(a, u, {
21450
+ await w.writeJson(i, c, {
19487
21451
  encoding: "utf-8",
19488
21452
  spaces: 2
19489
21453
  });
19490
21454
  }
19491
- async function I(e, t, n) {
19492
- let r = j(await s.readFile(e, { encoding: "utf-8" }), t).output, a = i(r);
19493
- await s.writeJson(n, a, {
21455
+ async function jn(e, t, n) {
21456
+ let r = E(await w.readFile(e, { encoding: "utf-8" }), t).output, i = C(r);
21457
+ await w.writeJson(n, i, {
19494
21458
  encoding: "utf-8",
19495
21459
  spaces: 2
19496
21460
  });
19497
21461
  }
19498
21462
  //#endregion
19499
- export { P as addLinksOrReferencesToHtmlFile, F as addPositionsToTableOfContentsFile, j as readTransformation, I as simplifiedHtmlBillFileToTableOfContentsFile, E as simplifyWordHtml, A as simplifyWordHtmlToDocument, N as writeTransformation };
21463
+ //#region src/lib/f_legi/resolver.ts
21464
+ var $, Mn = class {
21465
+ flegiDb;
21466
+ articleRowsByNumByTextAndDate = /* @__PURE__ */ new Map();
21467
+ articleNumsLoadedByTextAndDate = /* @__PURE__ */ new Map();
21468
+ articleRowsByContextTextId = /* @__PURE__ */ new Map();
21469
+ directSectionChildrenByParentAndDate = /* @__PURE__ */ new Map();
21470
+ globalArticleRowsByNumAndDate = /* @__PURE__ */ new Map();
21471
+ rootTextIdsByTextId = /* @__PURE__ */ new Map();
21472
+ contextTextIdsByTextId = /* @__PURE__ */ new Map();
21473
+ textIdBySegmentId = /* @__PURE__ */ new Map();
21474
+ textTitlesInfosLoaded = !1;
21475
+ constructor(e) {
21476
+ this.flegiDb = e;
21477
+ }
21478
+ async getActiveArticlesByTextAndNum({ date: e, num: t, textId: n }) {
21479
+ return t === void 0 ? [] : (await this.getActiveArticleRowsByNum(n, e)).get(t) ?? [];
21480
+ }
21481
+ async getDirectSectionChildren({ date: e, parentPath: t }) {
21482
+ let n = `${t}\0${e}`, r = this.directSectionChildrenByParentAndDate.get(n);
21483
+ if (r === void 0) {
21484
+ if (r = await this.getDirectSectionChildrenByExactParentPath({
21485
+ date: e,
21486
+ parentPath: t
21487
+ }), r.length === 0 && !t.includes(".")) {
21488
+ let n = await this.getRootTextIdsFromTextId(t);
21489
+ n.length > 1 && (r = await this.flegiDb`
21490
+ SELECT
21491
+ dernier_segment AS id,
21492
+ chemin::text AS path,
21493
+ titre AS title,
21494
+ date_debut::text AS "dateDebut",
21495
+ date_fin::text AS "dateFin"
21496
+ FROM scta
21497
+ WHERE
21498
+ subltree(chemin, 0, 1) = ANY(${this.flegiDb.array(n)}::ltree[])
21499
+ AND nlevel(chemin) = 2
21500
+ AND type_objet = 'scta'
21501
+ AND date_debut <= ${e}::date
21502
+ AND date_fin >= ${e}::date
21503
+ ORDER BY tri_hierarchique
21504
+ `);
21505
+ }
21506
+ this.directSectionChildrenByParentAndDate.set(n, r);
21507
+ }
21508
+ return r;
21509
+ }
21510
+ async getTextIdFromSegmentId(e) {
21511
+ let t = this.textIdBySegmentId.get(e);
21512
+ return t === void 0 && (t = await this.getTextIdFromSegmentIdUsingContextHeuristic(e) ?? await this.getTextIdFromSegmentIdUsingSctaHeuristic(e) ?? null, this.textIdBySegmentId.set(e, t)), t ?? void 0;
21513
+ }
21514
+ async preloadTextTitlesInfos(e = {}) {
21515
+ let t = (t, n = {}) => {
21516
+ e.onProgress?.({
21517
+ ...n,
21518
+ phase: t,
21519
+ resolver: "f_legi"
21520
+ });
21521
+ };
21522
+ if (this.textTitlesInfosLoaded) {
21523
+ t("already-loaded");
21524
+ return;
21525
+ }
21526
+ let n = new O("f_legi.preloadTextTitlesInfos");
21527
+ $ === void 0 ? (t("queryTextTitlesInfos:start"), $ = (async () => {
21528
+ let e = await n.time("queryTextTitlesInfos", () => this.flegiDb`
21529
+ SELECT
21530
+ cid,
21531
+ date_texte::text AS "dateTexte",
21532
+ nature,
21533
+ num,
21534
+ title
21535
+ FROM text_titles_infos
21536
+ ORDER BY legi_id
21537
+ `);
21538
+ t("queryTextTitlesInfos:done", { count: e.length }), t("buildTextTitlesInfos:start", { count: e.length });
21539
+ let r = performance.now(), i = await Fn(e, { onProgress: ({ count: e, phase: n }) => t(`buildTextTitlesInfos:${n}`, { count: e }) });
21540
+ return n.add({
21541
+ count: e.length,
21542
+ durationMs: Math.round((performance.now() - r) * 10) / 10,
21543
+ phase: "buildTextTitlesInfos"
21544
+ }), t("buildTextTitlesInfos:done"), i;
21545
+ })().catch((e) => {
21546
+ throw $ = void 0, e;
21547
+ })) : t("waiting-for-shared-preload");
21548
+ let r = await $;
21549
+ t("setTextTitlesInfos:start"), a(r), t("setTextTitlesInfos:done"), n.log(), this.textTitlesInfosLoaded = !0;
21550
+ }
21551
+ async getUniqueActiveArticlesByNum({ date: e, num: t }) {
21552
+ if (t === void 0) return [];
21553
+ let n = `${t}\0${e}`, r = this.globalArticleRowsByNumAndDate.get(n);
21554
+ return r === void 0 && (r = await this.queryUniqueActiveArticlesByNumsUsingContextHeuristic([t]), this.globalArticleRowsByNumAndDate.set(n, r)), r;
21555
+ }
21556
+ async preloadUniqueActiveArticlesByNums({ date: e, nums: t }) {
21557
+ let n = [];
21558
+ for (let r of t) {
21559
+ if (r === void 0) continue;
21560
+ let t = `${r}\0${e}`;
21561
+ this.globalArticleRowsByNumAndDate.has(t) || (this.globalArticleRowsByNumAndDate.set(t, []), n.push(r));
21562
+ }
21563
+ if (n.length === 0) return;
21564
+ let r = new O("f_legi.preloadUniqueActiveArticlesByNums"), i = await r.time("queryGloballyUniqueArticleRowsByNums", () => this.queryGloballyUniqueArticleRowsByNums(n), { count: n.length }), a = new Set(i.map(({ num: e }) => e).filter((e) => e !== null)), o = n.filter((e) => !a.has(e)), s = await r.time("queryUniqueActiveArticlesByNumsUsingContextHeuristic", () => this.queryUniqueActiveArticlesByNumsUsingContextHeuristic(o), { count: o.length }), c = [...i, ...s].toSorted((e, t) => e.id < t.id ? -1 : +(e.id > t.id)), l = /* @__PURE__ */ new Map();
21565
+ for (let t of c) {
21566
+ if (t.num === null) continue;
21567
+ let n = l.get(t.num) ?? 0;
21568
+ if (l.set(t.num, n + 1), n >= 100) continue;
21569
+ let r = `${t.num}\0${e}`;
21570
+ this.globalArticleRowsByNumAndDate.get(r)?.push(t);
21571
+ }
21572
+ r.log({
21573
+ articleRowCount: c.length,
21574
+ globallyUniqueArticleRowCount: i.length,
21575
+ heuristicArticleRowCount: s.length,
21576
+ heuristicNumCount: o.length,
21577
+ numCount: n.length
21578
+ });
21579
+ }
21580
+ async preloadActiveArticlesByTextIds({ date: e, nums: t, textIds: n }) {
21581
+ let r = t === void 0 ? void 0 : [...new Set(t)].filter(Boolean), i = [...new Set(n)].filter((t) => {
21582
+ if (t === void 0) return !1;
21583
+ let n = `${t}\0${e}`;
21584
+ if (this.articleRowsByNumByTextAndDate.get(n) === void 0) return !0;
21585
+ let i = this.articleNumsLoadedByTextAndDate.get(n);
21586
+ return i === "all" ? !1 : r === void 0 ? !0 : r.some((e) => !i?.has(e));
21587
+ });
21588
+ if (i.length === 0) return;
21589
+ let a = new O("f_legi.preloadActiveArticlesByTextIds"), o = await a.time("getContextTextIdsByTextIds", () => this.getContextTextIdsByTextIds(i)), s = [...new Set([...o.values()].flat())], c = await a.time("getActiveArticleRowsForContextTextIds", () => r === void 0 ? this.getActiveArticleRowsForContextTextIdsWithRoots(s) : this.queryActiveArticleRowsForContextTextIds(s, r), { count: s.length }), l = /* @__PURE__ */ new Map(), u = (e, t) => {
21590
+ if (e === null) return;
21591
+ let n = l.get(e);
21592
+ n === void 0 ? l.set(e, [t]) : n.push(t);
21593
+ };
21594
+ for (let e of c) u(e.rootTextId, e), u(e.textId, e);
21595
+ for (let t of i) {
21596
+ let n = `${t}\0${e}`, i = o.get(t) ?? [t], a = /* @__PURE__ */ new Map();
21597
+ for (let e of i) for (let t of l.get(e) ?? []) a.set(`${t.id}\0${t.textId}`, {
21598
+ id: t.id,
21599
+ textId: t.textId,
21600
+ num: t.num,
21601
+ dateDebut: t.dateDebut,
21602
+ dateFin: t.dateFin
21603
+ });
21604
+ let s = this.articleRowsByNumByTextAndDate.get(n) ?? /* @__PURE__ */ new Map();
21605
+ for (let e of a.values()) {
21606
+ if (e.num === null) continue;
21607
+ let t = s.get(e.num);
21608
+ t === void 0 ? s.set(e.num, [e]) : t.some((t) => t.id === e.id && t.textId === e.textId) || t.push(e);
21609
+ }
21610
+ if (this.articleRowsByNumByTextAndDate.set(n, s), r === void 0) this.articleNumsLoadedByTextAndDate.set(n, "all");
21611
+ else {
21612
+ let e = this.articleNumsLoadedByTextAndDate.get(n);
21613
+ if (e !== "all") {
21614
+ let t = e ?? /* @__PURE__ */ new Set();
21615
+ for (let e of r) t.add(e);
21616
+ this.articleNumsLoadedByTextAndDate.set(n, t);
21617
+ }
21618
+ }
21619
+ }
21620
+ a.log({
21621
+ articleRowCount: c.length,
21622
+ articleNumCount: r?.length,
21623
+ rootTextIdCount: s.length,
21624
+ textIdCount: i.length
21625
+ });
21626
+ }
21627
+ async queryUniqueActiveArticlesByNumsUsingContextHeuristic(e) {
21628
+ return e.length === 0 ? [] : await this.flegiDb`
21629
+ SELECT
21630
+ id,
21631
+ "textId",
21632
+ num,
21633
+ "dateDebut",
21634
+ "dateFin"
21635
+ FROM (
21636
+ SELECT
21637
+ id,
21638
+ text_id AS "textId",
21639
+ num,
21640
+ date_debut::text AS "dateDebut",
21641
+ date_fin::text AS "dateFin",
21642
+ row_number() OVER (
21643
+ PARTITION BY num
21644
+ ORDER BY id
21645
+ ) AS "rowNumber"
21646
+ FROM article_num_candidates
21647
+ WHERE num IN ${this.flegiDb(e)}
21648
+ ) AS ranked_articles
21649
+ WHERE "rowNumber" <= 100
21650
+ `;
21651
+ }
21652
+ async queryGloballyUniqueArticleRowsByNums(e) {
21653
+ return e.length === 0 ? [] : await this.flegiDb`
21654
+ WITH unique_stats AS (
21655
+ SELECT
21656
+ num,
21657
+ unique_article_id,
21658
+ unique_article_source,
21659
+ unique_text_cid
21660
+ FROM article_num_candidate_stats
21661
+ WHERE
21662
+ num IN ${this.flegiDb(e)}
21663
+ AND candidate_article_count = 1
21664
+ AND unique_article_id IS NOT NULL
21665
+ AND unique_article_source IS NOT NULL
21666
+ AND unique_text_cid IS NOT NULL
21667
+ )
21668
+ SELECT
21669
+ legiarti.legi_id AS id,
21670
+ unique_stats.unique_text_cid AS "textId",
21671
+ legiarti.num,
21672
+ legiarti.date_debut::text AS "dateDebut",
21673
+ legiarti.date_fin::text AS "dateFin"
21674
+ FROM unique_stats
21675
+ JOIN legiarti
21676
+ ON unique_stats.unique_article_source = 'LEGI'
21677
+ AND legiarti.legi_id = unique_stats.unique_article_id
21678
+
21679
+ UNION ALL
21680
+
21681
+ SELECT
21682
+ jorfarti.legi_id AS id,
21683
+ unique_stats.unique_text_cid AS "textId",
21684
+ jorfarti.num,
21685
+ jorfarti.date_debut::text AS "dateDebut",
21686
+ jorfarti.date_fin::text AS "dateFin"
21687
+ FROM unique_stats
21688
+ JOIN jorfarti
21689
+ ON unique_stats.unique_article_source = 'JORF'
21690
+ AND jorfarti.legi_id = unique_stats.unique_article_id
21691
+ `;
21692
+ }
21693
+ async getActiveArticleRowsByNum(e, t) {
21694
+ let n = `${e}\0${t}`, r = this.articleRowsByNumByTextAndDate.get(n);
21695
+ if (r === void 0) {
21696
+ let t = await this.getContextTextIdsFromTextId(e), i = await this.getActiveArticleRowsForContextTextIds(t);
21697
+ r = /* @__PURE__ */ new Map();
21698
+ for (let e of i) {
21699
+ if (e.num === null) continue;
21700
+ let t = r.get(e.num);
21701
+ t === void 0 ? r.set(e.num, [e]) : t.push(e);
21702
+ }
21703
+ this.articleRowsByNumByTextAndDate.set(n, r), this.articleNumsLoadedByTextAndDate.set(n, "all");
21704
+ }
21705
+ return r;
21706
+ }
21707
+ async getActiveArticleRowsForContextTextIds(e) {
21708
+ return (await this.getActiveArticleRowsForContextTextIdsWithRoots(e)).map((e) => ({
21709
+ id: e.id,
21710
+ textId: e.textId,
21711
+ num: e.num,
21712
+ dateDebut: e.dateDebut,
21713
+ dateFin: e.dateFin
21714
+ }));
21715
+ }
21716
+ async getActiveArticleRowsForContextTextIdsWithRoots(e) {
21717
+ let t = [...new Set(e)], n = t.filter((e) => !this.articleRowsByContextTextId.has(e));
21718
+ if (n.length > 0) {
21719
+ let e = await this.queryActiveArticleRowsForContextTextIds(n);
21720
+ for (let e of n) this.articleRowsByContextTextId.set(e, []);
21721
+ for (let t of e) this.articleRowsByContextTextId.get(t.rootTextId)?.push(t);
21722
+ }
21723
+ return t.flatMap((e) => this.articleRowsByContextTextId.get(e) ?? []).toSorted((e, t) => e.id.localeCompare(t.id));
21724
+ }
21725
+ async queryActiveArticleRowsForContextTextIds(e, t) {
21726
+ if (e.length === 0 || t?.length === 0) return [];
21727
+ let n = t === void 0 ? this.flegiDb`` : this.flegiDb`AND num IN ${this.flegiDb(t)}`, r = t === void 0 ? this.flegiDb`` : this.flegiDb`AND legiarti.num IN ${this.flegiDb(t)}`, i = t === void 0 ? this.flegiDb`` : this.flegiDb`AND jorfarti.num IN ${this.flegiDb(t)}`;
21728
+ return (await this.flegiDb`
21729
+ SELECT DISTINCT ON (article_rows.id, article_rows."textId")
21730
+ article_rows.id,
21731
+ article_rows."rootTextId",
21732
+ article_rows."textId",
21733
+ article_rows.num,
21734
+ article_rows."dateDebut",
21735
+ article_rows."dateFin"
21736
+ FROM (
21737
+ SELECT
21738
+ legi_id AS id,
21739
+ context_text_cid AS "rootTextId",
21740
+ context_text_cid AS "textId",
21741
+ num,
21742
+ date_debut::text AS "dateDebut",
21743
+ date_fin::text AS "dateFin",
21744
+ 0 AS priority,
21745
+ true AS "hasValidParentPeriod",
21746
+ NULL::varchar AS tri_hierarchique,
21747
+ legi_id AS order_id
21748
+ FROM legiarti
21749
+ WHERE
21750
+ context_text_cid IN ${this.flegiDb(e)}
21751
+ ${n}
21752
+
21753
+ UNION ALL
21754
+
21755
+ SELECT
21756
+ legi_id AS id,
21757
+ context_text_cid AS "rootTextId",
21758
+ context_text_cid AS "textId",
21759
+ num,
21760
+ date_debut::text AS "dateDebut",
21761
+ date_fin::text AS "dateFin",
21762
+ 0 AS priority,
21763
+ true AS "hasValidParentPeriod",
21764
+ NULL::varchar AS tri_hierarchique,
21765
+ legi_id AS order_id
21766
+ FROM jorfarti
21767
+ WHERE
21768
+ context_text_cid IN ${this.flegiDb(e)}
21769
+ ${n}
21770
+
21771
+ UNION ALL
21772
+
21773
+ -- Heuristique sur scta uniquement en fallback pour les
21774
+ -- rares articles sans CONTEXTE -> TEXTE dans f_legi.
21775
+ SELECT
21776
+ legiarti.legi_id AS id,
21777
+ COALESCE(
21778
+ legitext.cid,
21779
+ subltree(scta.chemin, 0, 1)::text
21780
+ ) AS "rootTextId",
21781
+ COALESCE(
21782
+ legitext.cid,
21783
+ subltree(scta.chemin, 0, 1)::text
21784
+ ) AS "textId",
21785
+ legiarti.num,
21786
+ legiarti.date_debut::text AS "dateDebut",
21787
+ legiarti.date_fin::text AS "dateFin",
21788
+ 1 AS priority,
21789
+ (scta.parents_valid_period IS NOT NULL AND NOT isempty(scta.parents_valid_period)) AS "hasValidParentPeriod",
21790
+ scta.tri_hierarchique,
21791
+ legiarti.legi_id AS order_id
21792
+ FROM article_location_diffs
21793
+ JOIN legiarti
21794
+ ON legiarti.legi_id = article_location_diffs.article_id
21795
+ JOIN scta
21796
+ ON scta.dernier_segment = legiarti.legi_id
21797
+ AND scta.type_objet = 'art'
21798
+ LEFT JOIN legitext
21799
+ ON legitext.legi_id = subltree(scta.chemin, 0, 1)::text
21800
+ WHERE
21801
+ article_location_diffs.diff_type = 'missing_from_contexte'
21802
+ AND COALESCE(
21803
+ legitext.cid,
21804
+ subltree(scta.chemin, 0, 1)::text
21805
+ ) IN ${this.flegiDb(e)}
21806
+ ${r}
21807
+
21808
+ UNION ALL
21809
+
21810
+ SELECT
21811
+ jorfarti.legi_id AS id,
21812
+ COALESCE(
21813
+ jorftext.cid,
21814
+ subltree(scta.chemin, 0, 1)::text
21815
+ ) AS "rootTextId",
21816
+ COALESCE(
21817
+ jorftext.cid,
21818
+ subltree(scta.chemin, 0, 1)::text
21819
+ ) AS "textId",
21820
+ jorfarti.num,
21821
+ jorfarti.date_debut::text AS "dateDebut",
21822
+ jorfarti.date_fin::text AS "dateFin",
21823
+ 1 AS priority,
21824
+ (scta.parents_valid_period IS NOT NULL AND NOT isempty(scta.parents_valid_period)) AS "hasValidParentPeriod",
21825
+ scta.tri_hierarchique,
21826
+ jorfarti.legi_id AS order_id
21827
+ FROM article_location_diffs
21828
+ JOIN jorfarti
21829
+ ON jorfarti.legi_id = article_location_diffs.article_id
21830
+ JOIN scta
21831
+ ON scta.dernier_segment = jorfarti.legi_id
21832
+ AND scta.type_objet = 'art'
21833
+ LEFT JOIN jorftext
21834
+ ON jorftext.legi_id = subltree(scta.chemin, 0, 1)::text
21835
+ WHERE
21836
+ article_location_diffs.diff_type = 'missing_from_contexte'
21837
+ AND COALESCE(
21838
+ jorftext.cid,
21839
+ subltree(scta.chemin, 0, 1)::text
21840
+ ) IN ${this.flegiDb(e)}
21841
+ ${i}
21842
+ ) AS article_rows
21843
+ ORDER BY
21844
+ article_rows.id,
21845
+ article_rows."textId",
21846
+ article_rows.priority,
21847
+ article_rows."hasValidParentPeriod" DESC,
21848
+ article_rows.tri_hierarchique,
21849
+ article_rows.order_id
21850
+ `).toSorted((e, t) => e.id.localeCompare(t.id));
21851
+ }
21852
+ async getDirectSectionChildrenByExactParentPath({ date: e, parentPath: t }) {
21853
+ return await this.flegiDb`
21854
+ SELECT
21855
+ dernier_segment AS id,
21856
+ chemin::text AS path,
21857
+ titre AS title,
21858
+ date_debut::text AS "dateDebut",
21859
+ date_fin::text AS "dateFin"
21860
+ FROM scta
21861
+ WHERE
21862
+ chemin <@ ${t}::ltree
21863
+ AND nlevel(chemin) = nlevel(${t}::ltree) + 1
21864
+ AND type_objet = 'scta'
21865
+ AND date_debut <= ${e}::date
21866
+ AND date_fin >= ${e}::date
21867
+ ORDER BY tri_hierarchique
21868
+ `;
21869
+ }
21870
+ async getTextIdFromSegmentIdUsingContextHeuristic(e) {
21871
+ if (e.startsWith("LEGIARTI")) return (await this.flegiDb`
21872
+ SELECT context_text_cid AS "textId"
21873
+ FROM legiarti
21874
+ WHERE legi_id = ${e}
21875
+ LIMIT 1
21876
+ `)[0]?.textId;
21877
+ if (e.startsWith("JORFARTI")) return (await this.flegiDb`
21878
+ SELECT context_text_cid AS "textId"
21879
+ FROM jorfarti
21880
+ WHERE legi_id = ${e}
21881
+ LIMIT 1
21882
+ `)[0]?.textId;
21883
+ }
21884
+ async getTextIdFromSegmentIdUsingSctaHeuristic(e) {
21885
+ return (await this.flegiDb`
21886
+ SELECT
21887
+ COALESCE(
21888
+ legitext.cid,
21889
+ jorftext.cid,
21890
+ subltree(scta.chemin, 0, 1)::text
21891
+ ) AS "textId"
21892
+ FROM scta
21893
+ LEFT JOIN legitext
21894
+ ON legitext.legi_id = subltree(scta.chemin, 0, 1)::text
21895
+ LEFT JOIN jorftext
21896
+ ON jorftext.legi_id = subltree(scta.chemin, 0, 1)::text
21897
+ WHERE scta.dernier_segment = ${e}
21898
+ ORDER BY
21899
+ (scta.parents_valid_period IS NOT NULL AND NOT isempty(scta.parents_valid_period)) DESC,
21900
+ scta.date_debut DESC
21901
+ LIMIT 1
21902
+ `)[0]?.textId;
21903
+ }
21904
+ async getContextTextIdsFromTextId(e) {
21905
+ let t = this.contextTextIdsByTextId.get(e);
21906
+ return t === void 0 && (t = (await this.getContextTextIdsByTextIds([e])).get(e) ?? [e], this.contextTextIdsByTextId.set(e, t)), t;
21907
+ }
21908
+ async getContextTextIdsByTextIds(e) {
21909
+ let t = /* @__PURE__ */ new Map(), n = e.filter((e) => !this.contextTextIdsByTextId.has(e));
21910
+ for (let n of e) {
21911
+ let e = this.contextTextIdsByTextId.get(n);
21912
+ e !== void 0 && t.set(n, e);
21913
+ }
21914
+ if (n.length === 0) return t;
21915
+ for (let e of n) t.set(e, [e]);
21916
+ let r = await this.flegiDb`
21917
+ SELECT legi_id AS "textId", cid AS "contextTextId"
21918
+ FROM legitext
21919
+ WHERE legi_id IN ${this.flegiDb(n)} OR cid IN ${this.flegiDb(n)}
21920
+
21921
+ UNION ALL
21922
+
21923
+ SELECT legi_id AS "textId", cid AS "contextTextId"
21924
+ FROM jorftext
21925
+ WHERE legi_id IN ${this.flegiDb(n)} OR cid IN ${this.flegiDb(n)}
21926
+
21927
+ ORDER BY "textId", "contextTextId"
21928
+ `;
21929
+ for (let { contextTextId: e, textId: i } of r) for (let r of [i, e]) {
21930
+ if (!n.includes(r)) continue;
21931
+ let i = t.get(r) ?? [r];
21932
+ i.includes(e) || i.push(e), t.set(r, i);
21933
+ }
21934
+ for (let e of n) this.contextTextIdsByTextId.set(e, t.get(e) ?? [e]);
21935
+ return t;
21936
+ }
21937
+ async getRootTextIdsFromTextId(e) {
21938
+ let t = this.rootTextIdsByTextId.get(e);
21939
+ return t === void 0 && (t = (await this.getRootTextIdsByTextIds([e])).get(e) ?? [e], this.rootTextIdsByTextId.set(e, t)), t;
21940
+ }
21941
+ async getRootTextIdsByTextIds(e) {
21942
+ let t = /* @__PURE__ */ new Map(), n = e.filter((e) => !this.rootTextIdsByTextId.has(e));
21943
+ for (let n of e) {
21944
+ let e = this.rootTextIdsByTextId.get(n);
21945
+ e !== void 0 && t.set(n, e);
21946
+ }
21947
+ if (n.length === 0) return t;
21948
+ for (let e of n) t.set(e, [e]);
21949
+ let r = await this.flegiDb`
21950
+ SELECT cid AS "textId", legi_id AS "rootTextId"
21951
+ FROM legitext
21952
+ WHERE cid IN ${this.flegiDb(n)}
21953
+
21954
+ UNION ALL
21955
+
21956
+ SELECT cid AS "textId", legi_id AS "rootTextId"
21957
+ FROM jorftext
21958
+ WHERE cid IN ${this.flegiDb(n)}
21959
+
21960
+ ORDER BY "textId", "rootTextId"
21961
+ `;
21962
+ for (let { textId: e, rootTextId: n } of r) {
21963
+ let r = t.get(e) ?? [e];
21964
+ r.includes(n) || r.push(n), t.set(e, r);
21965
+ }
21966
+ for (let e of n) this.rootTextIdsByTextId.set(e, t.get(e) ?? [e]);
21967
+ return t;
21968
+ }
21969
+ };
21970
+ function Nn(e, t, n, r) {
21971
+ n != null && ((e[t] ??= {})[n] ??= []).push(r);
21972
+ }
21973
+ function Pn(e, t, n) {
21974
+ let r = Rn(S(t).replace(/[,()]/g, " ")).split(" ").map((e) => /^[IVX]+$/gi.test(e) ? o(e).toString() : e.toLowerCase().replace(/^no$/, "n°")), i = e;
21975
+ for (let e of r) i = i[e] ??= {};
21976
+ i.cid === void 0 ? i.cid = n : Array.isArray(i.cid) ? i.cid.push(n) : i.cid = [i.cid, n];
21977
+ }
21978
+ async function Fn(e, { onProgress: r } = {}) {
21979
+ let i = {}, a = {}, o = {}, s = {}, c = {};
21980
+ r?.({
21981
+ count: e.length,
21982
+ phase: "parse:start"
21983
+ });
21984
+ for (let [l, { cid: u, dateTexte: d, nature: f, num: p, title: m }] of e.entries()) {
21985
+ l > 0 && l % 2e4 == 0 && (r?.({
21986
+ count: l,
21987
+ phase: "parse:progress"
21988
+ }), await new Promise((e) => setTimeout(e, 0)));
21989
+ let e = S(m);
21990
+ if ([
21991
+ "code",
21992
+ "décret",
21993
+ "loi",
21994
+ "ordonnance"
21995
+ ].includes(e.toLowerCase())) continue;
21996
+ o[u] = [f, e];
21997
+ let h = /* @__PURE__ */ new Set(), g = /* @__PURE__ */ new Set();
21998
+ switch (e) {
21999
+ case "Constitution du 4 octobre 1958":
22000
+ g.add(e), h.add("Constitution");
22001
+ break;
22002
+ case "Loi contenant organisation du notariat (loi 25 ventôse an XI)":
22003
+ g.add("Loi du 25 ventôse an XI (16 mars 1803) contenant organisation du notariat");
22004
+ break;
22005
+ case "Loi des 16-24 août 1790 sur l'organisation judiciaire":
22006
+ h.add(e), g.add("Loi du 16 août 1790 sur l'organisation judiciaire");
22007
+ break;
22008
+ case "Loi des 2-17 mars 1791 portant suspension de tous les droits d'aides, de toutes les maîtrises et jurandes et établissement des droits de patente (décret d'Allarde)":
22009
+ h.add(e), g.add("Loi du 17 mars 1791 portant suspension de tous les droits d'aides, de toutes les maîtrises et jurandes et établissement des droits de patente (décret d'Allarde)");
22010
+ break;
22011
+ case "Loi n° 77-1423 du 27 décembre 1977 77-1423 du 27 décembre 1977 autorisant l'approbation de la convention sur le commerce international des espèces de faune et de flore sauvages menacées d'extinction, ensemble quatre annexes, ouverte à la signature à Washington jusqu'au 30 avril 1973 et, après cette date, à Berne jusqu'au 31 décembre 1974":
22012
+ g.add("Loi n° 77-1423 du 27 décembre 1977 autorisant l'approbation de la convention sur le commerce international des espèces de faune et de flore sauvages menacées d'extinction, ensemble quatre annexes, ouverte à la signature à Washington jusqu'au 30 avril 1973 et, après cette date, à Berne jusqu'au 31 décembre 1974");
22013
+ break;
22014
+ default: g.add(e);
22015
+ }
22016
+ for (let e of g) {
22017
+ let r = t(new n(Rn(e)));
22018
+ if (r === void 0 && f === "DECRET" && (r = {
22019
+ date: d ?? void 0,
22020
+ nature: f,
22021
+ num: p ?? void 0,
22022
+ titleRest: e.replace(/^Décrets?\s*/i, "").trim() || void 0,
22023
+ type: "texte"
22024
+ }), r === void 0) throw Error(`Unparsable title of ${f} n° ${p ?? ""} du ${d ?? ""} (${u}): ${e}`);
22025
+ Nn(s, f, r.date, u), Nn(c, f, r.num, u), r.titleRest !== void 0 && Pn(a, r.titleRest, u);
22026
+ }
22027
+ for (let e of h) Pn(i, e, u);
22028
+ }
22029
+ r?.({
22030
+ count: e.length,
22031
+ phase: "parse:done"
22032
+ }), r?.({ phase: "compact:start" }), await new Promise((e) => setTimeout(e, 0));
22033
+ let l = {
22034
+ textCidByOtherTitleWordsTree: Ln(i),
22035
+ textCidByTitleRestWordsTree: Ln(a),
22036
+ textInfosByCid: o,
22037
+ textsCidsByNatureAndDate: In(s),
22038
+ textsCidsByNatureAndNum: In(c)
22039
+ };
22040
+ return r?.({ phase: "compact:done" }), l;
22041
+ }
22042
+ function In(e) {
22043
+ return Object.fromEntries(Object.entries(e).map(([e, t]) => [e, Object.fromEntries(Object.entries(t).map(([e, t]) => [e, t.length === 1 ? t[0] : t]))]));
22044
+ }
22045
+ function Ln(e) {
22046
+ let t = {};
22047
+ e.cid !== void 0 && (t.cid = e.cid);
22048
+ for (let [n, r] of Object.entries(e)) {
22049
+ if (n === "cid") continue;
22050
+ let e = n, i = Ln(r);
22051
+ for (; i.cid === void 0;) {
22052
+ let t = Object.entries(i).filter(([e]) => e !== "cid");
22053
+ if (t.length !== 1) break;
22054
+ let [[n, r]] = t;
22055
+ e = `${e} ${n}`, i = r;
22056
+ }
22057
+ t[e] = i;
22058
+ }
22059
+ return t;
22060
+ }
22061
+ function Rn(e) {
22062
+ return x(e).output;
22063
+ }
22064
+ var zn = ie(process.env.F_LEGI_DSN ?? "postgresql://f_legi:f_legi@127.0.0.1:5432/f_legi");
22065
+ //#endregion
22066
+ //#region src/lib/server/legi/resolvers.ts
22067
+ function Bn(e) {
22068
+ return e ?? process.env.TISSEUSE_TEXT_TITLES_INFOS_PATH;
22069
+ }
22070
+ function Vn(e) {
22071
+ return kn(e ?? process.env.TISSEUSE_LEGI_RESOLVER);
22072
+ }
22073
+ function Hn({ canutesDb: e, resolver: t, textTitlesInfosPath: n }) {
22074
+ switch (Vn(t)) {
22075
+ case "canutes": return new Ke(e, { textTitlesInfosPath: Bn(n) });
22076
+ case "f_legi": return new Mn(zn);
22077
+ }
22078
+ }
22079
+ //#endregion
22080
+ export { Oe as addLinksOrReferencesToHtmlFile, An as addPositionsToTableOfContentsFile, Hn as createLegiResolver, On as defaultLegiResolverKind, Dn as legiResolverKinds, En as linkAkomaNtosoBillRaw, Rt as linkAssembleeBillRaw, Tn as parseAkomaNtosoBillRaw, Lt as parseAssembleeBillRaw, kn as parseLegiResolverKind, E as readTransformation, xn as renderAkomaNtosoBillRaw, jn as simplifiedHtmlBillFileToTableOfContentsFile, Se as simplifyWordHtml, Ee as simplifyWordHtmlToDocument, D as writeTransformation };