@agile-team/mach-report 2.23.0 → 2.23.1

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 (100) hide show
  1. package/README.md +3 -2
  2. package/dist/ExcelBindingWizard-BrTmdo7f.cjs +1 -0
  3. package/dist/ExcelBindingWizard-CcDMLO8Q.js +1486 -0
  4. package/dist/ParamEditor-BGjovFUe.js +737 -0
  5. package/dist/ParamEditor-CeNp4_zQ.cjs +1 -0
  6. package/dist/ReportBatchPanel-CHxBtG9R.cjs +1 -0
  7. package/dist/ReportBatchPanel-CJB67WNd.js +351 -0
  8. package/dist/ReportLabelStudio-Tplc1TLJ.js +784 -0
  9. package/dist/ReportLabelStudio-g8PkqJWn.cjs +1 -0
  10. package/dist/ReportParamPanel-C7fZTllk.cjs +1 -0
  11. package/dist/{ReportParamPanel-Dgmqro1Y.js → ReportParamPanel-GI43aGa0.js} +61 -56
  12. package/dist/{ReportPreview-FFIryrIr.cjs → ReportPreview-BoGBGyRr.cjs} +2 -2
  13. package/dist/{ReportPreview-DeWzG8jQ.js → ReportPreview-QLONCyci.js} +8 -8
  14. package/dist/ReportTemplateLibrary-BFQIX0sg.cjs +1 -0
  15. package/dist/ReportTemplateLibrary-KqX4E2sN.js +312 -0
  16. package/dist/RuleEditor-BZUP9yvL.cjs +1 -0
  17. package/dist/RuleEditor-OPX1awrH.js +2342 -0
  18. package/dist/TemplateOutlinePanel-CVYKVLv_.cjs +1 -0
  19. package/dist/TemplateOutlinePanel-DQS-eOs6.js +97 -0
  20. package/dist/TemplateReusePanel-CY6O93Zk.cjs +1 -0
  21. package/dist/TemplateReusePanel-DKXiFTyB.js +389 -0
  22. package/dist/TemplateReviewPanel-DbeNC8Ms.cjs +1 -0
  23. package/dist/TemplateReviewPanel-Dijwm9YE.js +593 -0
  24. package/dist/artifact-integrity.json +68 -68
  25. package/dist/{auto-CTIJ6PnR.js → auto-BB99S802.js} +4 -4
  26. package/dist/{auto-4pK9HePf.cjs → auto-BrPWo7Xm.cjs} +1 -1
  27. package/dist/designer-BZoVWTgl.js +7172 -0
  28. package/dist/designer-zS2uKJmY.cjs +2 -0
  29. package/dist/designer.cjs +1 -1
  30. package/dist/designer.d.cts +7 -0
  31. package/dist/designer.d.ts +7 -0
  32. package/dist/designer.js +2 -2
  33. package/dist/{encoding-BefcaHdp.cjs → encoding-7lquyj0w.cjs} +1 -1
  34. package/dist/{encoding-CL6rXEkR.js → encoding-CEd-dq9A.js} +2 -2
  35. package/dist/{font-loader-BT5baV-o.js → font-loader-CNWXomuV.js} +1 -1
  36. package/dist/{font-loader-Ga51c2VC.cjs → font-loader-D8pI87fL.cjs} +1 -1
  37. package/dist/index.cjs +1 -1
  38. package/dist/index.js +7 -7
  39. package/dist/{json-snapshot-OqkPyUk5.js → json-snapshot-BRnzKudk.js} +1 -1
  40. package/dist/{json-snapshot-1tvQNzQE.cjs → json-snapshot-DNiIbpOr.cjs} +1 -1
  41. package/dist/{pdf-aobetCsy.js → pdf-CJToa81Z.js} +2 -2
  42. package/dist/{pdf-HiEeXe9H.cjs → pdf-DpMkW72B.cjs} +1 -1
  43. package/dist/pdf.cjs +1 -1
  44. package/dist/pdf.js +2 -2
  45. package/dist/{plugin-BFANt-i8.cjs → plugin-BWTp-X7b.cjs} +1 -1
  46. package/dist/{plugin-DeYYAL6F.js → plugin-_BkUVc2z.js} +1 -1
  47. package/dist/{prefill-Dk4C6S5R.js → prefill-CWGdnqQd.js} +1 -1
  48. package/dist/{prefill-DsUD5OoK.cjs → prefill-PaAy6wLk.cjs} +1 -1
  49. package/dist/{prepared-DCIxhKFo.js → prepared-CJy_qk7d.js} +1 -1
  50. package/dist/{prepared-Dv-XM3i1.cjs → prepared-D0yCSxSO.cjs} +1 -1
  51. package/dist/{protocol-DxeUKGYG.js → protocol-BG16rz6D.js} +2 -2
  52. package/dist/{protocol-B9YgfQ_d.cjs → protocol-wzhl1Fim.cjs} +1 -1
  53. package/dist/report-encoding-worker.cjs +1 -1
  54. package/dist/report-encoding-worker.js +1 -1
  55. package/dist/{runtime-DKlGd_D4.cjs → runtime-DYMOS_gz.cjs} +1 -1
  56. package/dist/{runtime-75Y5Oq5B.js → runtime-PiCax9zQ.js} +2 -2
  57. package/dist/sbom.cdx.json +1 -1
  58. package/dist/server-node.cjs +4 -4
  59. package/dist/server-node.js +737 -736
  60. package/dist/server.cjs +1 -1
  61. package/dist/server.js +5 -5
  62. package/dist/style.css +1 -1
  63. package/dist/{template-catalog--cjxzgH7.js → template-catalog-CRuZL3pi.js} +1 -1
  64. package/dist/{template-catalog-CoT7jm_6.cjs → template-catalog-DtrtT1FY.cjs} +1 -1
  65. package/dist/textwrap-D4ZksyMK.js +111 -0
  66. package/dist/textwrap-DEHqAjKZ.cjs +4 -0
  67. package/dist/vue/async.d.cts +7 -0
  68. package/dist/vue/async.d.ts +7 -0
  69. package/dist/vue/index.d.cts +7 -0
  70. package/dist/vue/index.d.ts +7 -0
  71. package/dist/vue-async.cjs +1 -1
  72. package/dist/vue-async.js +3 -3
  73. package/dist/vue.cjs +1 -1
  74. package/dist/vue.js +6 -6
  75. package/dist/worker.cjs +1 -1
  76. package/dist/worker.js +4 -4
  77. package/package.json +1 -1
  78. package/dist/ExcelBindingWizard-D4FLind-.js +0 -1485
  79. package/dist/ExcelBindingWizard-D4RS5Bpg.cjs +0 -1
  80. package/dist/ParamEditor-C-6C9rd2.cjs +0 -1
  81. package/dist/ParamEditor-CASZt-Ma.js +0 -732
  82. package/dist/ReportBatchPanel-Bq7t8a5r.js +0 -350
  83. package/dist/ReportBatchPanel-YVj5IO5y.cjs +0 -1
  84. package/dist/ReportLabelStudio-Cqhita1b.cjs +0 -1
  85. package/dist/ReportLabelStudio-Dj7GXhuv.js +0 -783
  86. package/dist/ReportParamPanel-DZbFVmDL.cjs +0 -1
  87. package/dist/ReportTemplateLibrary-BaWodmpm.cjs +0 -1
  88. package/dist/ReportTemplateLibrary-DdAAAD2I.js +0 -311
  89. package/dist/RuleEditor-D2UwQGF6.js +0 -2341
  90. package/dist/RuleEditor-DcT9xI1v.cjs +0 -1
  91. package/dist/TemplateOutlinePanel-CUHFFiNM.cjs +0 -1
  92. package/dist/TemplateOutlinePanel-DrT7XN0m.js +0 -96
  93. package/dist/TemplateReusePanel-4eejkNqi.js +0 -388
  94. package/dist/TemplateReusePanel-DZMyiX5I.cjs +0 -1
  95. package/dist/TemplateReviewPanel-BIhNLeNw.js +0 -592
  96. package/dist/TemplateReviewPanel-DnYImiXu.cjs +0 -1
  97. package/dist/designer-DhrE7jzw.js +0 -7169
  98. package/dist/designer-IAZu6kBX.cjs +0 -2
  99. package/dist/textwrap-BIjtEWmq.js +0 -110
  100. package/dist/textwrap-Cy7o1hIR.cjs +0 -4
package/dist/designer.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("vue");const E=require("./designer-IAZu6kBX.cjs");exports.COLUMN_VISUAL_MESSAGES=E.COLUMN_VISUAL_MESSAGES;exports.ChartBindingInspector=E.ChartBindingInspector;exports.ColumnVisualEditor=E.ColumnVisualEditor;exports.DESIGNER_GUIDE_MESSAGES=E.DESIGNER_GUIDE_MESSAGES;exports.EXCEL_BINDING_MESSAGES=E.EXCEL_BINDING_MESSAGES;exports.ExcelBindingWizard=E.ExcelBindingWizard;exports.LABEL_STUDIO_MESSAGES=E.LABEL_STUDIO_MESSAGES;exports.PARAM_EDITOR_MESSAGES=E.PARAM_EDITOR_MESSAGES;exports.ParamEditor=E.ParamEditor;exports.REPORT_BATCH_MESSAGES=E.REPORT_BATCH_MESSAGES;exports.RULE_EDITOR_MESSAGES=E.DEFAULT_RULE_EDITOR_MESSAGES;exports.ReportBatchPanel=E.ReportBatchPanel;exports.ReportLabelStudio=E.ReportLabelStudio;exports.ReportTemplateEditor=E.ReportTemplateEditor;exports.ReportTemplateLibrary=E.ReportTemplateLibrary;exports.RuleEditor=E.RuleEditor;exports.TEMPLATE_EDITOR_MESSAGES=E.TEMPLATE_EDITOR_MESSAGES;exports.TEMPLATE_LIBRARY_MESSAGES=E.TEMPLATE_LIBRARY_MESSAGES;exports.TEMPLATE_PRODUCT_MESSAGES=E.TEMPLATE_PRODUCT_MESSAGES;exports.TEMPLATE_RECOVERY_MESSAGES=E.TEMPLATE_RECOVERY_MESSAGES;exports.TEMPLATE_REVIEW_MESSAGES=E.TEMPLATE_REVIEW_MESSAGES;exports.TemplateOutlinePanel=E.TemplateOutlinePanel;exports.TemplateReusePanel=E.TemplateReusePanel;exports.TemplateReviewPanel=E.TemplateReviewPanel;exports.createTemplateDraftStorage=E.createTemplateDraftStorage;exports.useTemplateWorkbench=E.useTemplateWorkbench;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("vue");const E=require("./designer-zS2uKJmY.cjs");exports.COLUMN_VISUAL_MESSAGES=E.COLUMN_VISUAL_MESSAGES;exports.ChartBindingInspector=E.ChartBindingInspector;exports.ColumnVisualEditor=E.ColumnVisualEditor;exports.DESIGNER_GUIDE_MESSAGES=E.DESIGNER_GUIDE_MESSAGES;exports.EXCEL_BINDING_MESSAGES=E.EXCEL_BINDING_MESSAGES;exports.ExcelBindingWizard=E.ExcelBindingWizard;exports.LABEL_STUDIO_MESSAGES=E.LABEL_STUDIO_MESSAGES;exports.PARAM_EDITOR_MESSAGES=E.PARAM_EDITOR_MESSAGES;exports.ParamEditor=E.ParamEditor;exports.REPORT_BATCH_MESSAGES=E.REPORT_BATCH_MESSAGES;exports.RULE_EDITOR_MESSAGES=E.DEFAULT_RULE_EDITOR_MESSAGES;exports.ReportBatchPanel=E.ReportBatchPanel;exports.ReportLabelStudio=E.ReportLabelStudio;exports.ReportTemplateEditor=E.ReportTemplateEditor;exports.ReportTemplateLibrary=E.ReportTemplateLibrary;exports.RuleEditor=E.RuleEditor;exports.TEMPLATE_EDITOR_MESSAGES=E.TEMPLATE_EDITOR_MESSAGES;exports.TEMPLATE_LIBRARY_MESSAGES=E.TEMPLATE_LIBRARY_MESSAGES;exports.TEMPLATE_PRODUCT_MESSAGES=E.TEMPLATE_PRODUCT_MESSAGES;exports.TEMPLATE_RECOVERY_MESSAGES=E.TEMPLATE_RECOVERY_MESSAGES;exports.TEMPLATE_REVIEW_MESSAGES=E.TEMPLATE_REVIEW_MESSAGES;exports.TemplateOutlinePanel=E.TemplateOutlinePanel;exports.TemplateReusePanel=E.TemplateReusePanel;exports.TemplateReviewPanel=E.TemplateReviewPanel;exports.createTemplateDraftStorage=E.createTemplateDraftStorage;exports.useTemplateWorkbench=E.useTemplateWorkbench;
@@ -1905,6 +1905,8 @@ declare interface MachReportPreviewOptions {
1905
1905
  }
1906
1906
  /** 主题变量(组件外壳注入的 --mrp-* CSS 自定义属性) */
1907
1907
  declare interface MachReportTheme {
1908
+ /** Native controls follow the host's declared light/dark palette. */
1909
+ colorScheme?: "light" | "dark";
1908
1910
  /** 空态插图强调色,不随正文颜色变灰。 */
1909
1911
  emptyAccent?: string;
1910
1912
  shellBg: string;
@@ -1917,6 +1919,11 @@ declare interface MachReportTheme {
1917
1919
  btnHoverBg: string;
1918
1920
  btnHoverFg: string;
1919
1921
  btnActiveBg: string;
1922
+ /** Foreground on solid primary actions. Optional for existing complete themes. */
1923
+ btnActiveFg?: string;
1924
+ errorFg?: string;
1925
+ warningFg?: string;
1926
+ successFg?: string;
1920
1927
  }
1921
1928
  declare interface MachReportToolbarOptions {
1922
1929
  /** Reasons explain host restrictions without granting capabilities. */
@@ -1905,6 +1905,8 @@ declare interface MachReportPreviewOptions {
1905
1905
  }
1906
1906
  /** 主题变量(组件外壳注入的 --mrp-* CSS 自定义属性) */
1907
1907
  declare interface MachReportTheme {
1908
+ /** Native controls follow the host's declared light/dark palette. */
1909
+ colorScheme?: "light" | "dark";
1908
1910
  /** 空态插图强调色,不随正文颜色变灰。 */
1909
1911
  emptyAccent?: string;
1910
1912
  shellBg: string;
@@ -1917,6 +1919,11 @@ declare interface MachReportTheme {
1917
1919
  btnHoverBg: string;
1918
1920
  btnHoverFg: string;
1919
1921
  btnActiveBg: string;
1922
+ /** Foreground on solid primary actions. Optional for existing complete themes. */
1923
+ btnActiveFg?: string;
1924
+ errorFg?: string;
1925
+ warningFg?: string;
1926
+ successFg?: string;
1920
1927
  }
1921
1928
  declare interface MachReportToolbarOptions {
1922
1929
  /** Reasons explain host restrictions without granting capabilities. */
package/dist/designer.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "vue";
2
- import { C as e, e as s, f as t, g as T, E as _, h as A, L as r, P as R, i as M, R as l, D as o, j as i, k as p, l as G, m as L, n as P, o as n, a as m, b as I, p as D, T as O, q as d, r as C, s as u, t as B, v as U } from "./designer-DhrE7jzw.js";
2
+ import { C as e, f as s, g as t, h as T, E as _, i as A, L as r, P as R, j as M, R as l, D as o, k as i, l as p, m as G, n as L, o as P, p as n, b as m, c as I, q as D, T as O, r as d, s as C, t as u, v as B, w as c } from "./designer-BZoVWTgl.js";
3
3
  export {
4
4
  e as COLUMN_VISUAL_MESSAGES,
5
5
  s as ChartBindingInspector,
@@ -26,5 +26,5 @@ export {
26
26
  C as TemplateReusePanel,
27
27
  u as TemplateReviewPanel,
28
28
  B as createTemplateDraftStorage,
29
- U as useTemplateWorkbench
29
+ c as useTemplateWorkbench
30
30
  };
@@ -1 +1 @@
1
- "use strict";const s=require("./runtime-DKlGd_D4.cjs"),e=require("./protocol-B9YgfQ_d.cjs");async function a(r,t){try{if(r.operation!=="exportPrepared")throw new TypeError("内置编码 Worker 仅接受 exportPrepared");return await e.runReportWorkerRequest(s.createReportRuntime({reports:{},budget:r.budget}),r,t)}catch(o){return{protocol:e.REPORT_WORKER_PROTOCOL,id:r.id,error:e.serializeError(o)}}}function R(r=globalThis){const t=o=>{if(!e.isReportWorkerRequest(o.data))return;const i=o.data;a(i,n=>r.postMessage({protocol:e.REPORT_WORKER_PROTOCOL,id:i.id,type:"event",event:n})).then(n=>r.postMessage(n,e.reportWorkerTransferList(n)))};return r.addEventListener("message",t),()=>r.removeEventListener("message",t)}exports.serveReportEncodingWorker=R;
1
+ "use strict";const s=require("./runtime-DYMOS_gz.cjs"),e=require("./protocol-wzhl1Fim.cjs");async function a(r,t){try{if(r.operation!=="exportPrepared")throw new TypeError("内置编码 Worker 仅接受 exportPrepared");return await e.runReportWorkerRequest(s.createReportRuntime({reports:{},budget:r.budget}),r,t)}catch(o){return{protocol:e.REPORT_WORKER_PROTOCOL,id:r.id,error:e.serializeError(o)}}}function R(r=globalThis){const t=o=>{if(!e.isReportWorkerRequest(o.data))return;const i=o.data;a(i,n=>r.postMessage({protocol:e.REPORT_WORKER_PROTOCOL,id:i.id,type:"event",event:n})).then(n=>r.postMessage(n,e.reportWorkerTransferList(n)))};return r.addEventListener("message",t),()=>r.removeEventListener("message",t)}exports.serveReportEncodingWorker=R;
@@ -1,5 +1,5 @@
1
- import { c as n } from "./runtime-75Y5Oq5B.js";
2
- import { i, a as p, r as d, R as a, s as R } from "./protocol-DxeUKGYG.js";
1
+ import { c as n } from "./runtime-PiCax9zQ.js";
2
+ import { i, a as p, r as d, R as a, s as R } from "./protocol-BG16rz6D.js";
3
3
  async function u(r, e) {
4
4
  try {
5
5
  if (r.operation !== "exportPrepared") throw new TypeError("内置编码 Worker 仅接受 exportPrepared");
@@ -139,7 +139,7 @@ function I(t) {
139
139
  const a = String.fromCharCode(...t.subarray(0, 4));
140
140
  if (!["\0\0\0", "true", "OTTO", "wOFF", "wOF2", "ttcf"].includes(a))
141
141
  throw new Error("文件内容不是支持的 TTF/OTF/WOFF 字体(可能返回了 JSON 或文本)");
142
- const { default: r } = await import("./pdf-aobetCsy.js").then((i) => i.f), o = r.create(t);
142
+ const { default: r } = await import("./pdf-CJToa81Z.js").then((i) => i.f), o = r.create(t);
143
143
  if (!Number.isFinite(o.unitsPerEm) || o.unitsPerEm <= 0 || !o.characterSet?.length || !o.numGlyphs)
144
144
  throw new Error("字体结构无效或不含可嵌入的单字体;请提供有效的 TTF/OTF/WOFF 文件");
145
145
  })();
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=new Map;let b=0,d={maxFonts:8,maxBytes:64*1024*1024,maxFontBytes:24*1024*1024};function O(){for(;f.size>d.maxFonts||b>d.maxBytes;){const t=f.keys().next().value;b-=f.get(t).byteLength,f.delete(t)}}function W(t){const e={...d,...t};if(!Object.values(e).every(n=>Number.isSafeInteger(n)&&n>0))throw new Error("字体缓存预算应为正整数字节/数量");d=e;for(const[n,a]of f)a.byteLength>d.maxFontBytes&&B(n);O()}function p(){return{fonts:f.size,bytes:b,...d}}function j(t){const e=f.get(t);return e&&(f.delete(t),f.set(t,e)),e}function B(t){const e=f.get(t);e&&(b-=e.byteLength),f.delete(t)}function q(){f.clear(),b=0}function H(t,e){B(t),!(e.byteLength>d.maxBytes||e.byteLength>d.maxFontBytes)&&(f.set(t,e),b+=e.byteLength,O())}const V="mach-report-fonts",u="fonts";function $(){return new Promise((t,e)=>{const n=indexedDB.open(V,1);n.onupgradeneeded=()=>{n.result.objectStoreNames.contains(u)||n.result.createObjectStore(u)},n.onsuccess=()=>t(n.result),n.onerror=()=>e(n.error)})}function M(t){if(t instanceof Uint8Array)return{bytes:t,accessedAt:0};const e=t;return e?.bytes instanceof Uint8Array&&Number.isFinite(e.accessedAt)?e:void 0}async function C(t,e){if(typeof indexedDB>"u")return t;let n;try{return n=await $(),await e(n)}catch{return t}finally{n?.close()}}function G(t){return C(null,e=>new Promise((n,a)=>{const r=e.transaction(u,"readwrite"),o=r.objectStore(u),i=o.get(t);let c=null;i.onsuccess=()=>{const s=M(i.result);s&&s.bytes.byteLength<=p().maxFontBytes?(c=s.bytes,o.put({bytes:s.bytes,accessedAt:Date.now()},t)):i.result!==void 0&&o.delete(t)},r.oncomplete=()=>n(c),r.onerror=()=>a(r.error),r.onabort=()=>a(r.error)}))}function J(t,e,n,a){const r=p(),o=e.filter(s=>s.key!==n);t.delete(n),a.byteLength<=Math.min(r.maxFontBytes,r.maxBytes)&&o.unshift({key:n,bytes:a.byteLength,accessedAt:Date.now()}),o.sort((s,h)=>h.accessedAt-s.accessedAt);let i=0,c=0;for(const s of o){if(c>=r.maxFonts||i+s.bytes>r.maxBytes||s.bytes>r.maxFontBytes){t.delete(s.key);continue}i+=s.bytes,c++,s.key===n&&t.put({bytes:a,accessedAt:s.accessedAt},n)}}function _(t,e){return C(void 0,n=>new Promise((a,r)=>{const o=n.transaction(u,"readwrite"),i=o.objectStore(u),c=i.openCursor(),s=[];c.onsuccess=()=>{const h=c.result;if(!h){J(i,s,t,e);return}const x=M(h.value);x?s.push({key:h.key,bytes:x.bytes.byteLength,accessedAt:x.accessedAt}):h.delete(),h.continue()},o.oncomplete=()=>a(),o.onerror=()=>r(o.error),o.onabort=()=>r(o.error)}))}function D(t){return C(void 0,e=>new Promise((n,a)=>{const r=e.transaction(u,"readwrite"),o=r.objectStore(u);t===void 0?o.clear():o.delete(t),r.oncomplete=()=>n(),r.onerror=()=>a(r.error),r.onabort=()=>a(r.error)}))}let L=0,S=0,v=Promise.resolve();const g=new Map;async function N(t){l.set(t,(l.get(t)??0)+1),B(t),w.delete(t);const e=g.get(t),n=(async()=>{await v,await e,await y.get(t),await D(t)})();g.set(t,n);try{await n}finally{g.get(t)===n&&g.delete(t)}}async function I(){L++,q(),w.clear(),l.clear();const t=v,e=(async()=>{await t,await Promise.all(y.values()),await D()})();v=e.catch(()=>{}),await e}const l=new Map,y=new Map,w=new Map,E=new Set;function k(){!S&&!E.size&&l.clear()}const T=new WeakMap;function K(t){const e=new TextDecoder().decode(t.subarray(0,256));return/^\s*(?:\uFEFF)?\s*<(?:!doctype\s+html|html|head|body)(?:\s|>)/i.test(e)}function R(t){if(t.byteLength===0)throw new Error("字体文件为空");if(K(t))throw new Error("字体 URL 返回 HTML 页面(可能是 SPA 路由回退),不是字体文件")}function Q(t){const e=T.get(t);if(e)return e;const n=(async()=>{const a=String.fromCharCode(...t.subarray(0,4));if(!["\0\0\0","true","OTTO","wOFF","wOF2","ttcf"].includes(a))throw new Error("文件内容不是支持的 TTF/OTF/WOFF 字体(可能返回了 JSON 或文本)");const{default:r}=await Promise.resolve().then(()=>require("./pdf-HiEeXe9H.cjs")).then(i=>i.fontkit_es),o=r.create(t);if(!Number.isFinite(o.unitsPerEm)||o.unitsPerEm<=0||!o.characterSet?.length||!o.numGlyphs)throw new Error("字体结构无效或不含可嵌入的单字体;请提供有效的 TTF/OTF/WOFF 文件")})();return T.set(t,n),n}function A(t,e,n=!1){const a=n?"字体加载超时,请检查网络或字体服务":e instanceof Error?e.message:String(e);return Object.assign(new Error(`PDF 字体 ${JSON.stringify(t)} 加载失败:${a}`),{cause:e})}function P(t,e){if(t>e)throw new Error(`字体文件超过单字体下载预算(${e}字节)`)}async function X(t,e,n){const a=Number(t.headers?.get("content-length"));try{Number.isFinite(a)&&P(a,e)}catch(r){throw t.body?.cancel(r).catch(()=>{}),r}if(!t.body){const r=new Uint8Array(await F(t.arrayBuffer(),n));return P(r.byteLength,e),r}return U(t.body,e,n)}async function U(t,e,n){const a=t.getReader(),r=[];let o=0;try{for(;;){const s=await F(a.read(),n);if(s.done)break;o+=s.value.byteLength,P(o,e),r.push(s.value)}const i=new Uint8Array(o);let c=0;for(const s of r)i.set(s,c),c+=s.byteLength;return i}catch(i){throw a.cancel(i).catch(()=>{}),i}finally{a.releaseLock()}}async function Y(t,e,n){if(t[0]!==31||t[1]!==139)return t;if(typeof DecompressionStream>"u")throw new Error("当前环境不支持 gzip 字体解压,请使用未压缩的字体 URL 或支持 DecompressionStream 的浏览器 / Node 环境");const r=new ReadableStream({start(o){o.enqueue(t),o.close()}}).pipeThrough(new DecompressionStream("gzip"));return U(r,e,n)}async function Z(t){const e=new AbortController;let n=!1;const a=setTimeout(()=>{n=!0,e.abort()},15e3);try{const r=await fetch(t,{signal:e.signal});if(!r.ok)throw new Error(`字体请求返回 HTTP ${r.status}`);if(/text\/html|application\/xhtml\+xml/i.test(r.headers?.get("content-type")??""))throw new Error("字体 URL 返回 HTML 页面(可能是 SPA 路由回退),不是字体文件");const o=p().maxFontBytes,i=await X(r,o,e.signal),c=await Y(i,o,e.signal);return R(c),{bytes:c,fromCache:!1}}catch(r){throw e.abort(),A(t,r,n)}finally{clearTimeout(a)}}async function tt(t){await v,await g.get(t);const e=await G(t);if(e)try{return R(e),{bytes:e,fromCache:!0}}catch{}return Z(t)}function et(t){const e=w.get(t);if(e)return e;const n=tt(t);w.set(t,n),E.add(n);const a=()=>{w.get(t)===n&&w.delete(t),E.delete(n),k()};return n.then(a,a),n}async function nt(t,e,n,a){if((l.get(t)??0)!==n||L!==a)return;H(t,e);const r=y.get(t);if(r){await r;return}const o=_(t,e);y.set(t,o),await o,y.get(t)===o&&y.delete(t)}function m(t){return t.reason??new DOMException("字体加载已取消","AbortError")}function F(t,e){return e?e.aborted?Promise.reject(m(e)):new Promise((n,a)=>{const r=()=>{e.removeEventListener("abort",r),a(m(e))};e.addEventListener("abort",r,{once:!0}),t.then(o=>{e.removeEventListener("abort",r),n(o)},o=>{e.removeEventListener("abort",r),a(o)})}):t}async function rt(t,e,n,a,r){try{return await F(Q(e.bytes),n.signal),e.bytes}catch(o){if(n.signal?.aborted)throw m(n.signal);if((l.get(t)??0)!==a||L!==r)throw A(t,o);if(await N(t),e.fromCache)return await z(t,n);throw A(t,o)}}async function z(t,e={}){if(e.signal?.aborted)throw m(e.signal);const n=l.get(t)??0,a=L,r=j(t);if(r&&!e.strict)return r;const o=r?void 0:et(t);S++;try{const i=r?{bytes:r,fromCache:!0}:await F(o,e.signal),c=e.strict?await rt(t,i,e,n,a):i.bytes;if(e.signal?.aborted)throw m(e.signal);return r||await F(nt(t,c,n,a),e.signal),c}catch(i){if(e.signal?.aborted)throw m(e.signal);if(e.strict)throw i;return null}finally{S--,k()}}exports.clearFontCache=I;exports.configureFontCache=W;exports.getFontCacheStats=p;exports.invalidateFontCache=N;exports.loadFontWithCache=z;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=new Map;let b=0,d={maxFonts:8,maxBytes:64*1024*1024,maxFontBytes:24*1024*1024};function O(){for(;f.size>d.maxFonts||b>d.maxBytes;){const t=f.keys().next().value;b-=f.get(t).byteLength,f.delete(t)}}function W(t){const e={...d,...t};if(!Object.values(e).every(n=>Number.isSafeInteger(n)&&n>0))throw new Error("字体缓存预算应为正整数字节/数量");d=e;for(const[n,a]of f)a.byteLength>d.maxFontBytes&&B(n);O()}function p(){return{fonts:f.size,bytes:b,...d}}function j(t){const e=f.get(t);return e&&(f.delete(t),f.set(t,e)),e}function B(t){const e=f.get(t);e&&(b-=e.byteLength),f.delete(t)}function q(){f.clear(),b=0}function H(t,e){B(t),!(e.byteLength>d.maxBytes||e.byteLength>d.maxFontBytes)&&(f.set(t,e),b+=e.byteLength,O())}const V="mach-report-fonts",u="fonts";function $(){return new Promise((t,e)=>{const n=indexedDB.open(V,1);n.onupgradeneeded=()=>{n.result.objectStoreNames.contains(u)||n.result.createObjectStore(u)},n.onsuccess=()=>t(n.result),n.onerror=()=>e(n.error)})}function M(t){if(t instanceof Uint8Array)return{bytes:t,accessedAt:0};const e=t;return e?.bytes instanceof Uint8Array&&Number.isFinite(e.accessedAt)?e:void 0}async function C(t,e){if(typeof indexedDB>"u")return t;let n;try{return n=await $(),await e(n)}catch{return t}finally{n?.close()}}function G(t){return C(null,e=>new Promise((n,a)=>{const r=e.transaction(u,"readwrite"),o=r.objectStore(u),i=o.get(t);let c=null;i.onsuccess=()=>{const s=M(i.result);s&&s.bytes.byteLength<=p().maxFontBytes?(c=s.bytes,o.put({bytes:s.bytes,accessedAt:Date.now()},t)):i.result!==void 0&&o.delete(t)},r.oncomplete=()=>n(c),r.onerror=()=>a(r.error),r.onabort=()=>a(r.error)}))}function J(t,e,n,a){const r=p(),o=e.filter(s=>s.key!==n);t.delete(n),a.byteLength<=Math.min(r.maxFontBytes,r.maxBytes)&&o.unshift({key:n,bytes:a.byteLength,accessedAt:Date.now()}),o.sort((s,h)=>h.accessedAt-s.accessedAt);let i=0,c=0;for(const s of o){if(c>=r.maxFonts||i+s.bytes>r.maxBytes||s.bytes>r.maxFontBytes){t.delete(s.key);continue}i+=s.bytes,c++,s.key===n&&t.put({bytes:a,accessedAt:s.accessedAt},n)}}function _(t,e){return C(void 0,n=>new Promise((a,r)=>{const o=n.transaction(u,"readwrite"),i=o.objectStore(u),c=i.openCursor(),s=[];c.onsuccess=()=>{const h=c.result;if(!h){J(i,s,t,e);return}const x=M(h.value);x?s.push({key:h.key,bytes:x.bytes.byteLength,accessedAt:x.accessedAt}):h.delete(),h.continue()},o.oncomplete=()=>a(),o.onerror=()=>r(o.error),o.onabort=()=>r(o.error)}))}function D(t){return C(void 0,e=>new Promise((n,a)=>{const r=e.transaction(u,"readwrite"),o=r.objectStore(u);t===void 0?o.clear():o.delete(t),r.oncomplete=()=>n(),r.onerror=()=>a(r.error),r.onabort=()=>a(r.error)}))}let L=0,S=0,v=Promise.resolve();const g=new Map;async function N(t){l.set(t,(l.get(t)??0)+1),B(t),w.delete(t);const e=g.get(t),n=(async()=>{await v,await e,await y.get(t),await D(t)})();g.set(t,n);try{await n}finally{g.get(t)===n&&g.delete(t)}}async function I(){L++,q(),w.clear(),l.clear();const t=v,e=(async()=>{await t,await Promise.all(y.values()),await D()})();v=e.catch(()=>{}),await e}const l=new Map,y=new Map,w=new Map,E=new Set;function k(){!S&&!E.size&&l.clear()}const T=new WeakMap;function K(t){const e=new TextDecoder().decode(t.subarray(0,256));return/^\s*(?:\uFEFF)?\s*<(?:!doctype\s+html|html|head|body)(?:\s|>)/i.test(e)}function R(t){if(t.byteLength===0)throw new Error("字体文件为空");if(K(t))throw new Error("字体 URL 返回 HTML 页面(可能是 SPA 路由回退),不是字体文件")}function Q(t){const e=T.get(t);if(e)return e;const n=(async()=>{const a=String.fromCharCode(...t.subarray(0,4));if(!["\0\0\0","true","OTTO","wOFF","wOF2","ttcf"].includes(a))throw new Error("文件内容不是支持的 TTF/OTF/WOFF 字体(可能返回了 JSON 或文本)");const{default:r}=await Promise.resolve().then(()=>require("./pdf-DpMkW72B.cjs")).then(i=>i.fontkit_es),o=r.create(t);if(!Number.isFinite(o.unitsPerEm)||o.unitsPerEm<=0||!o.characterSet?.length||!o.numGlyphs)throw new Error("字体结构无效或不含可嵌入的单字体;请提供有效的 TTF/OTF/WOFF 文件")})();return T.set(t,n),n}function A(t,e,n=!1){const a=n?"字体加载超时,请检查网络或字体服务":e instanceof Error?e.message:String(e);return Object.assign(new Error(`PDF 字体 ${JSON.stringify(t)} 加载失败:${a}`),{cause:e})}function P(t,e){if(t>e)throw new Error(`字体文件超过单字体下载预算(${e}字节)`)}async function X(t,e,n){const a=Number(t.headers?.get("content-length"));try{Number.isFinite(a)&&P(a,e)}catch(r){throw t.body?.cancel(r).catch(()=>{}),r}if(!t.body){const r=new Uint8Array(await F(t.arrayBuffer(),n));return P(r.byteLength,e),r}return U(t.body,e,n)}async function U(t,e,n){const a=t.getReader(),r=[];let o=0;try{for(;;){const s=await F(a.read(),n);if(s.done)break;o+=s.value.byteLength,P(o,e),r.push(s.value)}const i=new Uint8Array(o);let c=0;for(const s of r)i.set(s,c),c+=s.byteLength;return i}catch(i){throw a.cancel(i).catch(()=>{}),i}finally{a.releaseLock()}}async function Y(t,e,n){if(t[0]!==31||t[1]!==139)return t;if(typeof DecompressionStream>"u")throw new Error("当前环境不支持 gzip 字体解压,请使用未压缩的字体 URL 或支持 DecompressionStream 的浏览器 / Node 环境");const r=new ReadableStream({start(o){o.enqueue(t),o.close()}}).pipeThrough(new DecompressionStream("gzip"));return U(r,e,n)}async function Z(t){const e=new AbortController;let n=!1;const a=setTimeout(()=>{n=!0,e.abort()},15e3);try{const r=await fetch(t,{signal:e.signal});if(!r.ok)throw new Error(`字体请求返回 HTTP ${r.status}`);if(/text\/html|application\/xhtml\+xml/i.test(r.headers?.get("content-type")??""))throw new Error("字体 URL 返回 HTML 页面(可能是 SPA 路由回退),不是字体文件");const o=p().maxFontBytes,i=await X(r,o,e.signal),c=await Y(i,o,e.signal);return R(c),{bytes:c,fromCache:!1}}catch(r){throw e.abort(),A(t,r,n)}finally{clearTimeout(a)}}async function tt(t){await v,await g.get(t);const e=await G(t);if(e)try{return R(e),{bytes:e,fromCache:!0}}catch{}return Z(t)}function et(t){const e=w.get(t);if(e)return e;const n=tt(t);w.set(t,n),E.add(n);const a=()=>{w.get(t)===n&&w.delete(t),E.delete(n),k()};return n.then(a,a),n}async function nt(t,e,n,a){if((l.get(t)??0)!==n||L!==a)return;H(t,e);const r=y.get(t);if(r){await r;return}const o=_(t,e);y.set(t,o),await o,y.get(t)===o&&y.delete(t)}function m(t){return t.reason??new DOMException("字体加载已取消","AbortError")}function F(t,e){return e?e.aborted?Promise.reject(m(e)):new Promise((n,a)=>{const r=()=>{e.removeEventListener("abort",r),a(m(e))};e.addEventListener("abort",r,{once:!0}),t.then(o=>{e.removeEventListener("abort",r),n(o)},o=>{e.removeEventListener("abort",r),a(o)})}):t}async function rt(t,e,n,a,r){try{return await F(Q(e.bytes),n.signal),e.bytes}catch(o){if(n.signal?.aborted)throw m(n.signal);if((l.get(t)??0)!==a||L!==r)throw A(t,o);if(await N(t),e.fromCache)return await z(t,n);throw A(t,o)}}async function z(t,e={}){if(e.signal?.aborted)throw m(e.signal);const n=l.get(t)??0,a=L,r=j(t);if(r&&!e.strict)return r;const o=r?void 0:et(t);S++;try{const i=r?{bytes:r,fromCache:!0}:await F(o,e.signal),c=e.strict?await rt(t,i,e,n,a):i.bytes;if(e.signal?.aborted)throw m(e.signal);return r||await F(nt(t,c,n,a),e.signal),c}catch(i){if(e.signal?.aborted)throw m(e.signal);if(e.strict)throw i;return null}finally{S--,k()}}exports.clearFontCache=I;exports.configureFontCache=W;exports.getFontCacheStats=p;exports.invalidateFontCache=N;exports.loadFontWithCache=z;
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("./progress-WomPRP3B.cjs"),U=require("./record-bindings-MBxbeBsi.cjs"),v=require("./template-registry-DI59PXVK.cjs"),ye=require("./dataset-IrlXbUvh.cjs"),_=require("./textwrap-Cy7o1hIR.cjs"),w=require("./json-snapshot-1tvQNzQE.cjs"),J=require("./dom-ChE5D-L-.cjs"),ot=require("./data-bar-CeZuFmYl.cjs"),it=require("./rich-text-layout-DK7A_a5r.cjs"),H=require("./capabilities-DiBj4Qgl.cjs"),ee=require("./assets-D2gHc4Mz.cjs"),at=require("./grid-strokes-Be24LGuV.cjs"),j=require("./prefill-DsUD5OoK.cjs"),A=require("./param-validation-C-8sRJLq.cjs"),te=require("./computed-DK6BruFz.cjs"),ne=require("./template-catalog-CoT7jm_6.cjs"),me=require("./template-fragments-GVjpew_q.cjs"),be=require("./template-serialization-CqQY4zDg.cjs");function ve(e,t,n,r,o,i,c,s="top"){e.font=`${t.italic?"italic ":""}${t.bold?"bold ":""}${t.fontSizePx}px ${c}`,"letterSpacing"in e&&(e.letterSpacing="0px"),e.fillStyle=t.color,e.textBaseline="alphabetic";const a=t.fontSizePx*t.lineHeight,l=t.text===""?[""]:t.text.split(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("./progress-WomPRP3B.cjs"),U=require("./record-bindings-MBxbeBsi.cjs"),v=require("./template-registry-DI59PXVK.cjs"),ye=require("./dataset-IrlXbUvh.cjs"),_=require("./textwrap-DEHqAjKZ.cjs"),w=require("./json-snapshot-DNiIbpOr.cjs"),J=require("./dom-ChE5D-L-.cjs"),ot=require("./data-bar-CeZuFmYl.cjs"),it=require("./rich-text-layout-DK7A_a5r.cjs"),H=require("./capabilities-DiBj4Qgl.cjs"),ee=require("./assets-D2gHc4Mz.cjs"),at=require("./grid-strokes-Be24LGuV.cjs"),j=require("./prefill-PaAy6wLk.cjs"),A=require("./param-validation-C-8sRJLq.cjs"),te=require("./computed-DK6BruFz.cjs"),ne=require("./template-catalog-DtrtT1FY.cjs"),me=require("./template-fragments-GVjpew_q.cjs"),be=require("./template-serialization-CqQY4zDg.cjs");function ve(e,t,n,r,o,i,c,s="top"){e.font=`${t.italic?"italic ":""}${t.bold?"bold ":""}${t.fontSizePx}px ${c}`,"letterSpacing"in e&&(e.letterSpacing="0px"),e.fillStyle=t.color,e.textBaseline="alphabetic";const a=t.fontSizePx*t.lineHeight,l=t.text===""?[""]:t.text.split(`
2
2
  `),m=l.length*a;let p=r;s==="middle"?p=r+(i-m)/2:s==="bottom"&&(p=r+i-m),l.forEach((d,u)=>{const f=p+u*a+t.fontSizePx*.8;st(e,d,t,n,f,o),t.underline&&d&&lt(e,d,t,n,f,o)}),e.textAlign="left"}function st(e,t,n,r,o,i){const c=Array.from(t),s=n.letterSpacingPx??0;if(!s){e.textAlign=n.align==="center"?"center":n.align==="right"?"right":"left";const p=n.align==="center"?r+i/2:n.align==="right"?r+i:r;e.fillText(t,p,o);return}const a=e.measureText(t).width+Math.max(0,c.length-1)*s,l=n.align==="center"?r+(i-a)/2:n.align==="right"?r+i-a:r;e.textAlign="left";let m="";c.forEach((p,d)=>{e.fillText(p,l+e.measureText(m).width+d*s,o),m+=p})}function lt(e,t,n,r,o,i){const c=e.measureText(t).width+Math.max(0,Array.from(t).length-1)*(n.letterSpacingPx??0),s=n.align==="center"?r+(i-c)/2:n.align==="right"?r+i-c:r;e.strokeStyle=n.color,e.lineWidth=Math.max(.5,n.fontSizePx/20),e.beginPath(),e.moveTo(s,o+1),e.lineTo(s+c,o+1),e.stroke()}function _e(e,t,n,r,o){const i=r/72,c=s=>{e.font=`${s.italic?"italic ":""}${s.bold?"bold ":""}${g.resolveFontSize(s,r).fontSizePx}px ${s.fontFamily??o}`,"letterSpacing"in e&&(e.letterSpacing="0px")};it.drawRichText(t,{x:n.x/i,yTop:-n.y/i,width:n.width/i,height:n.height/i},{measure(s,a){return c(a),e.measureText(s).width/i+(a.letterSpacing??0)},draw(s,a,l,m,p){const d=g.resolveFontSize(a,r).fontSizePx,u=-m*i-d*.8;a.backgroundColor&&(e.fillStyle=a.backgroundColor,e.fillRect(l*i,u,p*i,d*g.resolveLineHeight(a))),ve(e,{text:s,fontSizePx:d,bold:!!a.bold,italic:a.italic,underline:a.underline,color:g.resolveTextColor(a),align:"left",lineHeight:g.resolveLineHeight(a),letterSpacingPx:(a.letterSpacing??0)*i},l*i,u,p*i,d,a.fontFamily??o)}})}function L(e){if(e?.aborted)throw e.reason??new DOMException("The operation was aborted.","AbortError")}const ct=(e,t)=>(L(t),/^data:image\/(?:png|jpe?g|webp|gif|svg\+xml)[;,]/i.test(e)?new Promise((n,r)=>{const o=new Image,i=()=>{o.onload=null,o.onerror=null,t?.removeEventListener("abort",c)},c=()=>{i(),o.src="",r(t?.reason??new DOMException("The operation was aborted.","AbortError"))};o.onload=()=>{i(),n(o)},o.onerror=()=>{i(),r(new Error("Image could not be decoded for Canvas output."))},t?.addEventListener("abort",c,{once:!0}),o.src=e}):Promise.reject(new TypeError("Canvas imageData must be an image data URL; provide imageLoader for other sources.")));function mt(e,t,n){return L(n),n?new Promise((r,o)=>{const i=()=>o(n.reason??new DOMException("The operation was aborted.","AbortError"));n.addEventListener("abort",i,{once:!0}),Promise.resolve().then(()=>e(t,n)).then(r,o).finally(()=>n.removeEventListener("abort",i))}):e(t)}function*Me(e){function*t(n,r,o,i){if(i.has(n))throw new TypeError("Cyclic grid children cannot be rendered.");g.isImageBackedComponent(n)&&(yield{component:n,componentIndex:r,componentPath:o});const c=new Set(i).add(n);for(const[s,a]of(n.grid?.cells??[]).entries())for(const[l,m]of a.entries())for(const[p,d]of(m?.children??[]).entries())yield*t(d,r,[...o,s,l,p],c)}for(const[n,r]of e.components.entries())yield*t(r,n,[],new Set)}async function dt(e,t,n){const r=new Map;for(const{component:o}of Me(e))!g.isImageBackedComponent(o)||r.has(o.imageData)||r.set(o.imageData,await mt(t,o.imageData,n));return L(n),r}function pt(e,t,n,r,o,i){const c=t,s=c.naturalWidth??c.width??o,a=c.naturalHeight??c.height??i;if(s<=0||a<=0)throw new RangeError("Decoded Canvas image dimensions must be positive.");const l=Math.min(o/s,i/a),m=s*l,p=a*l;e.drawImage(t,n+(o-m)/2,r+(i-p)/2,m,p)}function je(e){return j.createPageWindowIndex(e.pageHeightsPx,e.gapPx).window(e.viewportHeightPx,e.scrollTopPx,e.overscan)}const Re=96/25.4;function de(e,t=96){const n=t/96*Re;return{widthPx:Math.max(1,Math.round(e.pageWidthMm*n)),heightPx:Math.max(1,Math.round(e.pageHeightMm*n))}}function Be(e,t,n,r=64e6){if(!Number.isFinite(t)||t<=0||!Number.isFinite(n)||n<=0)throw new RangeError("Canvas dpr and dpi must be positive finite numbers.");if(!Number.isFinite(r)||r<=0)throw new RangeError("maxCanvasPixels must be positive and finite.");const o=de(e,n),i=Math.round(o.widthPx*t),c=Math.round(o.heightPx*t);if(!Number.isSafeInteger(i)||!Number.isSafeInteger(c)||i*c>r)throw new RangeError("Canvas page exceeds maxCanvasPixels; reduce resolution or split the report.");return{width:i,height:c}}function ze(e,t,n,r){const o=document.createElement("canvas"),{widthPx:i,heightPx:c}=de(e,n),s=Be(e,t,n,r);o.width=s.width,o.height=s.height,o.style.width=`${i}px`,o.style.height=`${c}px`;const a=o.getContext("2d");if(!a)throw new Error("当前环境不支持 Canvas 2D(测试需真浏览器,见 e2e/canvas.spec.ts)");return a.scale(t,t),a.fillStyle="#ffffff",a.fillRect(0,0,i,c),{canvas:o,ctx:a}}function gt(e,t=96){return g.resolveFontSize(e,t).fontSizePx}function ut(e,t,n,r,o,i,c){for(const s of at.resolveGridStrokes(t,n))e.strokeStyle=s.color,e.lineWidth=g.ptToPx(s.widthPt,c),e.beginPath(),s.kind==="v"?(e.moveTo(r+s.pos*i,o+s.from*i),e.lineTo(r+s.pos*i,o+s.to*i)):(e.moveTo(r+s.from*i,o+s.pos*i),e.lineTo(r+s.to*i,o+s.pos*i)),e.stroke()}function ft(e,t,n,r,o,i){e.beginPath(),t.top&&(e.moveTo(n,r),e.lineTo(n+o,r)),t.right&&(e.moveTo(n+o,r),e.lineTo(n+o,r+i)),t.bottom&&(e.moveTo(n+o,r+i),e.lineTo(n,r+i)),t.left&&(e.moveTo(n,r+i),e.lineTo(n,r)),e.stroke()}function ht(e,t,n,r,o,i,c,s,a,l,m,p){const d=g.resolveGridLayout(t,i/s,c/s);for(const u of d.cells){const f=u.cell.style?.backgroundColor??n.style?.backgroundColor;f&&(e.fillStyle=f,e.fillRect(r+u.xMm*s,o+u.yMm*s,u.widthMm*s,u.heightMm*s))}ut(e,d,n,r,o,s,a);for(const u of d.cells)wt(e,u,n,r,o,s,a,l,m,p)}function wt(e,t,n,r,o,i,c,s,a,l){const m=n.grid?.paddingMm??.5,p=t.cell.text??"",d=g.mergeComponentStyles(n.style,t.cell.style),u=g.resolveFontSize(d,c),f=t.cell.indentMm??0,x=Math.max(0,t.widthMm-2*m-f),C=_.wrapText(p,x,{fontSizePt:u.fontSizePt,bold:d.bold,italic:d.italic,fontFamily:d.fontFamily??s,letterSpacingPt:d.letterSpacing},a).join(`
3
3
  `),M={x:r+(t.xMm+m+f)*i,y:o+(t.yMm+m)*i,width:x*i,height:Math.max(0,t.heightMm-2*m)*i};e.save(),e.beginPath(),e.rect(M.x,M.y,M.width,M.height),e.clip(),t.cell.richParagraphs?.length?_e(e,{...n,richParagraphs:t.cell.richParagraphs,style:{verticalAlign:"middle",...d}},M,c,s):ve(e,{text:C,fontSizePx:u.fontSizePx,bold:d.bold??!1,italic:d.italic,underline:d.underline,color:g.resolveTextColor(d,g.DEFAULT_TEXT_COLOR),align:d.align??"left",lineHeight:g.resolveLineHeight(d),letterSpacingPx:g.ptToPx(d.letterSpacing??0,c)},r+(t.xMm+m+f)*i,o+(t.yMm+m)*i,x*i,Math.max(0,t.heightMm-2*m)*i,d.fontFamily??s,d.verticalAlign??"middle");for(const P of t.cell.children??[])pe(e,{...P,leftMm:P.leftMm+M.x/i,topMm:P.topMm+M.y/i},i,c,s,a,l);e.restore();const E=ot.dataBarBox(t.cell.dataBar,t.widthMm,t.heightMm,m);E&&(e.save(),e.globalAlpha*=.35,e.fillStyle=E.color,e.fillRect(r+(t.xMm+E.x)*i,o+(t.yMm+E.y)*i,E.width*i,E.height*i),e.restore())}function yt(e,t,n,r,o,i,c,s,a){const l=t.style??{},m=g.resolveFontSize(l,c);if(g.isRichText(t)){_e(e,t,{x:n,y:r,width:o,height:i},c,s);return}const p=t.lines?.length?t.lines.join(`
4
4
  `):_.wrapText(t.text??"",t.widthMm,{fontSizePt:m.fontSizePt,bold:l.bold,italic:l.italic,fontFamily:l.fontFamily??s,letterSpacingPt:l.letterSpacing},a).join(`
package/dist/index.js CHANGED
@@ -5,10 +5,10 @@ import { v as Fe, R as je, a as me, p as X, b as ct } from "./template-registry-
5
5
  import { c as Dr, d as Lr, e as Nr, i as kr, s as Fr, f as jr, g as zr, h as Hr } from "./template-registry-O0hNIOfB.js";
6
6
  import { v as lt } from "./dataset-DL83majE.js";
7
7
  import { d as _r } from "./dataset-DL83majE.js";
8
- import { h as ue, w as ze } from "./textwrap-BIjtEWmq.js";
9
- import { c as Ur, a as qr, b as Vr, m as Jr } from "./textwrap-BIjtEWmq.js";
10
- import { R as pe, d as mt, s as He, a as dt, p as ft } from "./json-snapshot-OqkPyUk5.js";
11
- import { D as Kr, b as Yr, c as Xr, e as Zr, f as Qr, g as ei, h as ti, i as ni, j as ri, k as ii, l as oi, m as ai, n as si, o as ci, q as li, r as mi, t as di, u as fi, v as hi, w as gi, x as ui, y as pi, z as wi, A as bi, B as yi, C as Mi, E as vi, F as xi, G as Ei } from "./json-snapshot-OqkPyUk5.js";
8
+ import { h as ue, w as ze } from "./textwrap-D4ZksyMK.js";
9
+ import { c as Ur, a as qr, b as Vr, m as Jr } from "./textwrap-D4ZksyMK.js";
10
+ import { R as pe, d as mt, s as He, a as dt, p as ft } from "./json-snapshot-BRnzKudk.js";
11
+ import { D as Kr, b as Yr, c as Xr, e as Zr, f as Qr, g as ei, h as ti, i as ni, j as ri, k as ii, l as oi, m as ai, n as si, o as ci, q as li, r as mi, t as di, u as fi, v as hi, w as gi, x as ui, y as pi, z as wi, A as bi, B as yi, C as Mi, E as vi, F as xi, G as Ei } from "./json-snapshot-BRnzKudk.js";
12
12
  import { c as Ri, a as Ci, b as Ti, i as Pi, r as $i, d as Oi, e as Ai, t as Ii } from "./dom-JWrchIre.js";
13
13
  import { d as ht } from "./data-bar-IkI6VvMQ.js";
14
14
  import { d as gt } from "./rich-text-layout-Ciwa6D2o.js";
@@ -17,11 +17,11 @@ import { i as Li } from "./capabilities-pg7j7VLT.js";
17
17
  import { r as we } from "./assets-T_gDeFaz.js";
18
18
  import { O as ki } from "./assets-T_gDeFaz.js";
19
19
  import { r as pt } from "./grid-strokes-EoY66L2f.js";
20
- import { c as wt } from "./prefill-Dk4C6S5R.js";
21
- import { R as ji, a as zi, b as Hi, d as Bi, e as _i, m as Wi, r as Ui, f as qi, g as Vi, v as Ji } from "./prefill-Dk4C6S5R.js";
20
+ import { c as wt } from "./prefill-CWGdnqQd.js";
21
+ import { R as ji, a as zi, b as Hi, d as Bi, e as _i, m as Wi, r as Ui, f as qi, g as Vi, v as Ji } from "./prefill-CWGdnqQd.js";
22
22
  import { R as Ki, a as Yi, f as Xi, b as Zi, c as Qi, d as eo, i as to, e as no, g as ro, p as io, h as oo, j as ao, k as so, r as co, v as lo, l as mo } from "./param-validation-CnDEd2l-.js";
23
23
  import { n as ho, f as go, o as uo, r as po, l as wo } from "./computed-f3pOqWLX.js";
24
- import { c as yo, a as Mo, d as vo, r as xo, b as Eo } from "./template-catalog--cjxzgH7.js";
24
+ import { c as yo, a as Mo, d as vo, r as xo, b as Eo } from "./template-catalog-CRuZL3pi.js";
25
25
  import { a as Ro, c as Co, i as To, b as Po } from "./template-fragments-CPpGpQoz.js";
26
26
  import { T as Oo, c as Ao, a as Io } from "./template-serialization-CWmHq7lX.js";
27
27
  function be(e, t, n, r, i, o, l, s = "top") {
@@ -1,5 +1,5 @@
1
1
  import { r as te, a as re, L as ye, b as Wt, R as be, j as Vt, m as j, D as We } from "./progress-ByiOxUD3.js";
2
- import { w as _, h as Ve } from "./textwrap-BIjtEWmq.js";
2
+ import { w as _, h as Ve } from "./textwrap-D4ZksyMK.js";
3
3
  import { e as ve, n as H, b as Me, q as N, s as zt, t as Jt } from "./computed-f3pOqWLX.js";
4
4
  import { d as ze, R as $, f as W, k as Je, b as _t, i as qt, v as Se, c as Ut, P as Y, l as xe, t as _e, m as qe, h as Ue, n as Xt, o as Yt, D as Qt, e as fe } from "./record-bindings-DatJZv_e.js";
5
5
  import { c as Zt, e as er } from "./matrix-C6e_r_vp.js";
@@ -1,2 +1,2 @@
1
- "use strict";const R=require("./progress-WomPRP3B.cjs"),D=require("./textwrap-Cy7o1hIR.cjs"),I=require("./computed-DK6BruFz.cjs"),S=require("./record-bindings-MBxbeBsi.cjs"),Ge=require("./matrix-B8QWbsGM.cjs"),G=require("./template-serialization-CqQY4zDg.cjs"),j=require("./template-registry-DI59PXVK.cjs"),At=require("./report-params-VTg8MoCp.cjs"),Oe=require("./param-validation-C-8sRJLq.cjs"),Ve=require("./number-format-CZ2T_5kF.cjs"),we=require("./dataset-IrlXbUvh.cjs"),Nt=4096,Ae=128*1024;function Lt(e){const t=new Map;let r=0;return{measureMm(o,n){const a=JSON.stringify([o,n.fontSizePt,n.fontFamily,n.bold,n.italic,n.letterSpacingPt]),s=t.get(a);if(s!==void 0)return t.delete(a),t.set(a,s),s;const i=e.measureMm(o,n);if(Number.isFinite(i)&&a.length<=Ae){for(;t.size>=Nt||r+a.length>Ae;){const c=t.keys().next().value;r-=c.length,t.delete(c)}t.set(a,i),r+=a.length}return i}}}function Kt(e,t){return{member:"body",subtotal:"subtotal",total:"grand-total"}[e?.rows.get(t)?.kind??"member"]}function jt(e){const t=e.matrix;if(!t.hierarchy)return t;const r=new Map(e.columns.map(n=>[n.field,n.header])),o={sum:"求和",count:"计数",avg:"平均",min:"最小",max:"最大",weightedAvg:"加权平均"};return{...t,hierarchy:{...t.hierarchy,row:{...t.hierarchy.row,labels:t.hierarchy.row?.labels??t.rowFields.map(n=>r.get(n)??n)},column:{...t.hierarchy.column,labels:t.hierarchy.column?.labels??t.columnFields.map(n=>r.get(n)??n)}},measures:t.measures.map(n=>{const a=r.get(n.field)??r.get(n.valueField??n.field);return n.label===void 0&&a?{...n,label:`${a}(${o[n.op]})`}:n})}}function Dt(e,t){if(!e.matrix)return{list:e,rows:t};if(e.detail||e.groupBy||e.groups?.length||e.grandTotal)throw new Error("矩阵不能同时配置普通分组、总计或主从明细");const r=Ge.createMatrixTable(t,jt(e)),o=r.columns.map(i=>({...i,widthMm:i.semanticRole==="dimension"?e.matrix.rowWidthMm??40:e.matrix.columnWidthMm??28,editable:!1,align:i.semanticRole==="dimension"?"center":"right"})),n={...e,columns:o,headerGrid:r.headerGrid,rowKey:void 0,revisionField:void 0,sourceTokenField:void 0};e.layout==="wide"&&(n.widthMm=o.reduce((i,c)=>i+c.widthMm,0));const a=r.metadata,s=a?{rows:new WeakMap(r.rows.map((i,c)=>[i,a.rows[c]])),header:{columns:a.columns,rowFields:a.rowFields,rowLabels:a.rowLabels,columnFields:a.columnFields,columnLabels:a.columnLabels}}:void 0;return{list:n,rows:r.rows,...s?{matrix:s}:{}}}function Bt(e,t){if(!e.matrix?.hierarchy||!e.headerGrid)return e.headerGrid;const r=e.paddingMm??1,o=e.headerGrid.cells.map(()=>e.rowHeightMm??0),n=e.columns.map(c=>c.widthMm),a=R.resolveGridLayout({...e.headerGrid,colWidthsMm:n},n.reduce((c,l)=>c+l,0),o.length),s=new WeakMap;for(const{cell:c,ci:l,ri:u,widthMm:f}of a.cells){const d={...S.resolveListHeaderStyle(e,e.columns[l]),...c.style},g=R.resolveFontSize(d).fontSizePt,v=(D.wrapText(c.text??"",Math.max(1,f-r*2),{fontSizePt:g,fontFamily:d.fontFamily,bold:d.bold,italic:d.italic,letterSpacingPt:d.letterSpacing},t).length*g*(d.lineHeight??R.LINE_HEIGHT)*25.4/72+r*2)/(c.rowSpan??1);for(let p=u;p<u+(c.rowSpan??1);p++)o[p]=Math.max(o[p]??0,v);s.set(c,d)}const i=e.headerGrid.cells.map(c=>c.map(l=>l?{...l,style:s.get(l)}:null));return{...e.headerGrid,cells:i,rowHeightsMm:o}}function Ht(e,t,r){const o=new Set,n=e.cells.map((a,s)=>{const i=[];let c=0;for(const l of a){for(;o.has(`${s}:${c}`);)c++;const u=l?.colSpan??1,f=l?.rowSpan??1;let d=0;for(let g=c;g<c+u;g++){t.has(g)&&d++;for(let m=s+1;m<s+f;m++)o.add(`${m}:${g}`)}d&&i.push(l?{...l,colSpan:d}:null),c+=u}return i});return{...e,cells:n,colWidthsMm:r}}function _e(e){if(!e.columns.some(o=>o.hidden))return e;const t=new Set,r=e.columns.filter((o,n)=>o.hidden?!1:(t.add(n),!0));if(!r.length)throw new Error("列表至少需要一列可见列");return{...e,columns:r,...e.headerGrid?{headerGrid:Ht(e.headerGrid,t,r.map(o=>o.widthMm))}:{}}}function*Gt(e){const{page:t}=e;j.validateReportPageFlow(t.components,t.flow);let r=0,o=0;for(const n of j.reportFlowGroups(t.components,t.flow)){e.active();const a=n.band,s=n.components.some(u=>u.kind==="list"&&u.cardinality!=="record"),i=s?0:n.components.reduce((u,f)=>Math.max(u,f.topMm-a.topMm+(f.kind==="list"?e.height(f):f.heightMm)),a.heightMm);let c=Math.max(e.top(),o+a.topMm-r);if(!s&&i>e.bottom()-e.top()+.001)throw new Error(`静态区域 ${a.componentIds.join(",")} 高度超出单页可用范围`);!s&&c+i>e.bottom()+.001&&(e.nextPage(),yield*e.takePages(),e.active(),c=e.top());let l=c+i;for(const u of n.components){const f=c+u.topMm-a.topMm;u.kind==="list"?(yield*e.list(u,f,d=>{l=s?d:Math.max(l,d)}),e.active()):e.append({...u,topMm:f})}o=l,r=a.topMm+a.heightMm}}function Vt(e){return!!(e.computed?.length||e.groups?.length||e.groupBy||e.grandTotal||e.rowVisibleWhen||e.matrix||e.tree||e.detail||e.columns.some(t=>t.rules?.length||t.visibleWhen||t.visual))}function ye(e){return e.pages.some(t=>t.components.some(r=>r.kind==="list"?Vt(r):!!r.chartBinding))}const _t=512,Ne=256*1024;function Wt(){const e=new Map;let t=0,r;return(o,n,a,s)=>{s!==r&&(e.clear(),t=0,r=s);const i=JSON.stringify([o,n,a.fontSizePt,a.fontFamily,a.bold,a.italic,a.letterSpacingPt]),c=e.get(i);if(c)return e.delete(i),e.set(i,c),c.lines.slice();const l=D.wrapText(o,n,a,s),u=i.length+l.reduce((f,d)=>f+d.length,0);if(u<=Ne){for(;e.size>=_t||t+u>Ne;){const f=e.keys().next().value;t-=e.get(f).units,e.delete(f)}e.set(i,{lines:l.slice(),units:u}),t+=u}return l}}const We=1e4,Le=25e4;function be(e){if(e?.aborted)throw e.reason??new DOMException("标签生成已取消","AbortError")}function ze(e,t,r){const o=typeof e.copies=="object"?S.readRecordScalar(t,e.copies.field,r):e.copies??1;if(typeof o!="number"||!Number.isSafeInteger(o)||o<1||o>1e3)throw new S.ReportBindingError(`$.datasets.${r.dataset}[${r.rowIndex}]`,"每条记录复制数必须是 1..1000 的数值型整数",r.rowIndex,typeof e.copies=="object"?e.copies.field:void 0);return o}function Je(e,t,r){if(e.rowKey===void 0)return;const o=S.readRecordScalar(t,e.rowKey,r);if(typeof o=="string"&&o.trim()||typeof o=="number"&&Number.isFinite(o))return o;throw new S.ReportBindingError(`$.datasets.${r.dataset}[${r.rowIndex}].${e.rowKey}`,"业务主键必须是非空字符串或有限数字",r.rowIndex,e.rowKey)}function zt(e){const t=r=>1+(r.grid?.cells.reduce((o,n)=>o+1+n.length+n.reduce((a,s)=>a+(s?.children?.reduce((i,c)=>i+t(c),0)??0),0),0)??0);return e.pages.reduce((r,o)=>r+o.components.reduce((n,a)=>n+t(a),0),0)}function Jt(e,t,r){const o=e.repeat,n=Object.prototype.hasOwnProperty.call(t,o.dataset)?t[o.dataset]:void 0;if(!Array.isArray(n))throw new S.ReportBindingError(`$.datasets.${o.dataset}`,"逐记录标签数据集缺失,应提供对象数组(允许空数组)");const a=new Set,s=r.maxPages??We,i=zt(e);let c=0,l=0;for(const[u,f]of n.entries()){if(be(r.signal),!f||typeof f!="object"||Array.isArray(f))throw new S.ReportBindingError(`$.datasets.${o.dataset}[${u}]`,"标签记录应为对象",u);const d={rowIndex:u,dataset:o.dataset},g=Je(o,f,d);if(g!==void 0){const v=JSON.stringify([typeof g,g]);if(a.has(v))throw new S.ReportBindingError(`$.datasets.${o.dataset}[${u}].${o.rowKey}`,"业务主键重复;请先确认记录来源,避免重复打印标签",u,o.rowKey);a.add(v)}const m=ze(o,f,d);if(c+=m*e.pages.length,l+=m*i,c>s)throw new S.PaginatePageLimitError(s,c);if(l>Le)throw new S.ReportBindingError("$.repeat",`标签组件总量(含网格行、槽位及嵌套组件)超过安全预算 ${Le},请分批生成`,u)}return n}function qt(e,t,r){if(!e.binding)return e;const{binding:o,...n}=e,a=S.resolveComponentBinding(o,t.row,t);if(e.kind==="image"){if(!a)return;if(!S.isLabelImageData(a))throw new S.ReportBindingError(`${r}.binding`,"图片字段只接受 PNG/JPEG base64 data URL;业务 URL 应由宿主安全加载后转换",t.rowIndex,o.field);return{...n,imageData:a}}return e.kind==="barcode"||e.kind==="qrcode"?(delete n.imageData,{...n,code:{...n.code,value:a},fallbackText:a}):(delete n.lines,delete n.richParagraphs,{...n,text:a})}function Ut(e,t,r){if(e.kind!=="text"||e.grid||e.richParagraphs?.length)return e;const o=e.style??{},n=R.resolveFontSize(o).fontSizePt,a=e.text??e.lines?.join(`
1
+ "use strict";const R=require("./progress-WomPRP3B.cjs"),D=require("./textwrap-DEHqAjKZ.cjs"),I=require("./computed-DK6BruFz.cjs"),S=require("./record-bindings-MBxbeBsi.cjs"),Ge=require("./matrix-B8QWbsGM.cjs"),G=require("./template-serialization-CqQY4zDg.cjs"),j=require("./template-registry-DI59PXVK.cjs"),At=require("./report-params-VTg8MoCp.cjs"),Oe=require("./param-validation-C-8sRJLq.cjs"),Ve=require("./number-format-CZ2T_5kF.cjs"),we=require("./dataset-IrlXbUvh.cjs"),Nt=4096,Ae=128*1024;function Lt(e){const t=new Map;let r=0;return{measureMm(o,n){const a=JSON.stringify([o,n.fontSizePt,n.fontFamily,n.bold,n.italic,n.letterSpacingPt]),s=t.get(a);if(s!==void 0)return t.delete(a),t.set(a,s),s;const i=e.measureMm(o,n);if(Number.isFinite(i)&&a.length<=Ae){for(;t.size>=Nt||r+a.length>Ae;){const c=t.keys().next().value;r-=c.length,t.delete(c)}t.set(a,i),r+=a.length}return i}}}function Kt(e,t){return{member:"body",subtotal:"subtotal",total:"grand-total"}[e?.rows.get(t)?.kind??"member"]}function jt(e){const t=e.matrix;if(!t.hierarchy)return t;const r=new Map(e.columns.map(n=>[n.field,n.header])),o={sum:"求和",count:"计数",avg:"平均",min:"最小",max:"最大",weightedAvg:"加权平均"};return{...t,hierarchy:{...t.hierarchy,row:{...t.hierarchy.row,labels:t.hierarchy.row?.labels??t.rowFields.map(n=>r.get(n)??n)},column:{...t.hierarchy.column,labels:t.hierarchy.column?.labels??t.columnFields.map(n=>r.get(n)??n)}},measures:t.measures.map(n=>{const a=r.get(n.field)??r.get(n.valueField??n.field);return n.label===void 0&&a?{...n,label:`${a}(${o[n.op]})`}:n})}}function Dt(e,t){if(!e.matrix)return{list:e,rows:t};if(e.detail||e.groupBy||e.groups?.length||e.grandTotal)throw new Error("矩阵不能同时配置普通分组、总计或主从明细");const r=Ge.createMatrixTable(t,jt(e)),o=r.columns.map(i=>({...i,widthMm:i.semanticRole==="dimension"?e.matrix.rowWidthMm??40:e.matrix.columnWidthMm??28,editable:!1,align:i.semanticRole==="dimension"?"center":"right"})),n={...e,columns:o,headerGrid:r.headerGrid,rowKey:void 0,revisionField:void 0,sourceTokenField:void 0};e.layout==="wide"&&(n.widthMm=o.reduce((i,c)=>i+c.widthMm,0));const a=r.metadata,s=a?{rows:new WeakMap(r.rows.map((i,c)=>[i,a.rows[c]])),header:{columns:a.columns,rowFields:a.rowFields,rowLabels:a.rowLabels,columnFields:a.columnFields,columnLabels:a.columnLabels}}:void 0;return{list:n,rows:r.rows,...s?{matrix:s}:{}}}function Bt(e,t){if(!e.matrix?.hierarchy||!e.headerGrid)return e.headerGrid;const r=e.paddingMm??1,o=e.headerGrid.cells.map(()=>e.rowHeightMm??0),n=e.columns.map(c=>c.widthMm),a=R.resolveGridLayout({...e.headerGrid,colWidthsMm:n},n.reduce((c,l)=>c+l,0),o.length),s=new WeakMap;for(const{cell:c,ci:l,ri:u,widthMm:f}of a.cells){const d={...S.resolveListHeaderStyle(e,e.columns[l]),...c.style},g=R.resolveFontSize(d).fontSizePt,v=(D.wrapText(c.text??"",Math.max(1,f-r*2),{fontSizePt:g,fontFamily:d.fontFamily,bold:d.bold,italic:d.italic,letterSpacingPt:d.letterSpacing},t).length*g*(d.lineHeight??R.LINE_HEIGHT)*25.4/72+r*2)/(c.rowSpan??1);for(let p=u;p<u+(c.rowSpan??1);p++)o[p]=Math.max(o[p]??0,v);s.set(c,d)}const i=e.headerGrid.cells.map(c=>c.map(l=>l?{...l,style:s.get(l)}:null));return{...e.headerGrid,cells:i,rowHeightsMm:o}}function Ht(e,t,r){const o=new Set,n=e.cells.map((a,s)=>{const i=[];let c=0;for(const l of a){for(;o.has(`${s}:${c}`);)c++;const u=l?.colSpan??1,f=l?.rowSpan??1;let d=0;for(let g=c;g<c+u;g++){t.has(g)&&d++;for(let m=s+1;m<s+f;m++)o.add(`${m}:${g}`)}d&&i.push(l?{...l,colSpan:d}:null),c+=u}return i});return{...e,cells:n,colWidthsMm:r}}function _e(e){if(!e.columns.some(o=>o.hidden))return e;const t=new Set,r=e.columns.filter((o,n)=>o.hidden?!1:(t.add(n),!0));if(!r.length)throw new Error("列表至少需要一列可见列");return{...e,columns:r,...e.headerGrid?{headerGrid:Ht(e.headerGrid,t,r.map(o=>o.widthMm))}:{}}}function*Gt(e){const{page:t}=e;j.validateReportPageFlow(t.components,t.flow);let r=0,o=0;for(const n of j.reportFlowGroups(t.components,t.flow)){e.active();const a=n.band,s=n.components.some(u=>u.kind==="list"&&u.cardinality!=="record"),i=s?0:n.components.reduce((u,f)=>Math.max(u,f.topMm-a.topMm+(f.kind==="list"?e.height(f):f.heightMm)),a.heightMm);let c=Math.max(e.top(),o+a.topMm-r);if(!s&&i>e.bottom()-e.top()+.001)throw new Error(`静态区域 ${a.componentIds.join(",")} 高度超出单页可用范围`);!s&&c+i>e.bottom()+.001&&(e.nextPage(),yield*e.takePages(),e.active(),c=e.top());let l=c+i;for(const u of n.components){const f=c+u.topMm-a.topMm;u.kind==="list"?(yield*e.list(u,f,d=>{l=s?d:Math.max(l,d)}),e.active()):e.append({...u,topMm:f})}o=l,r=a.topMm+a.heightMm}}function Vt(e){return!!(e.computed?.length||e.groups?.length||e.groupBy||e.grandTotal||e.rowVisibleWhen||e.matrix||e.tree||e.detail||e.columns.some(t=>t.rules?.length||t.visibleWhen||t.visual))}function ye(e){return e.pages.some(t=>t.components.some(r=>r.kind==="list"?Vt(r):!!r.chartBinding))}const _t=512,Ne=256*1024;function Wt(){const e=new Map;let t=0,r;return(o,n,a,s)=>{s!==r&&(e.clear(),t=0,r=s);const i=JSON.stringify([o,n,a.fontSizePt,a.fontFamily,a.bold,a.italic,a.letterSpacingPt]),c=e.get(i);if(c)return e.delete(i),e.set(i,c),c.lines.slice();const l=D.wrapText(o,n,a,s),u=i.length+l.reduce((f,d)=>f+d.length,0);if(u<=Ne){for(;e.size>=_t||t+u>Ne;){const f=e.keys().next().value;t-=e.get(f).units,e.delete(f)}e.set(i,{lines:l.slice(),units:u}),t+=u}return l}}const We=1e4,Le=25e4;function be(e){if(e?.aborted)throw e.reason??new DOMException("标签生成已取消","AbortError")}function ze(e,t,r){const o=typeof e.copies=="object"?S.readRecordScalar(t,e.copies.field,r):e.copies??1;if(typeof o!="number"||!Number.isSafeInteger(o)||o<1||o>1e3)throw new S.ReportBindingError(`$.datasets.${r.dataset}[${r.rowIndex}]`,"每条记录复制数必须是 1..1000 的数值型整数",r.rowIndex,typeof e.copies=="object"?e.copies.field:void 0);return o}function Je(e,t,r){if(e.rowKey===void 0)return;const o=S.readRecordScalar(t,e.rowKey,r);if(typeof o=="string"&&o.trim()||typeof o=="number"&&Number.isFinite(o))return o;throw new S.ReportBindingError(`$.datasets.${r.dataset}[${r.rowIndex}].${e.rowKey}`,"业务主键必须是非空字符串或有限数字",r.rowIndex,e.rowKey)}function zt(e){const t=r=>1+(r.grid?.cells.reduce((o,n)=>o+1+n.length+n.reduce((a,s)=>a+(s?.children?.reduce((i,c)=>i+t(c),0)??0),0),0)??0);return e.pages.reduce((r,o)=>r+o.components.reduce((n,a)=>n+t(a),0),0)}function Jt(e,t,r){const o=e.repeat,n=Object.prototype.hasOwnProperty.call(t,o.dataset)?t[o.dataset]:void 0;if(!Array.isArray(n))throw new S.ReportBindingError(`$.datasets.${o.dataset}`,"逐记录标签数据集缺失,应提供对象数组(允许空数组)");const a=new Set,s=r.maxPages??We,i=zt(e);let c=0,l=0;for(const[u,f]of n.entries()){if(be(r.signal),!f||typeof f!="object"||Array.isArray(f))throw new S.ReportBindingError(`$.datasets.${o.dataset}[${u}]`,"标签记录应为对象",u);const d={rowIndex:u,dataset:o.dataset},g=Je(o,f,d);if(g!==void 0){const v=JSON.stringify([typeof g,g]);if(a.has(v))throw new S.ReportBindingError(`$.datasets.${o.dataset}[${u}].${o.rowKey}`,"业务主键重复;请先确认记录来源,避免重复打印标签",u,o.rowKey);a.add(v)}const m=ze(o,f,d);if(c+=m*e.pages.length,l+=m*i,c>s)throw new S.PaginatePageLimitError(s,c);if(l>Le)throw new S.ReportBindingError("$.repeat",`标签组件总量(含网格行、槽位及嵌套组件)超过安全预算 ${Le},请分批生成`,u)}return n}function qt(e,t,r){if(!e.binding)return e;const{binding:o,...n}=e,a=S.resolveComponentBinding(o,t.row,t);if(e.kind==="image"){if(!a)return;if(!S.isLabelImageData(a))throw new S.ReportBindingError(`${r}.binding`,"图片字段只接受 PNG/JPEG base64 data URL;业务 URL 应由宿主安全加载后转换",t.rowIndex,o.field);return{...n,imageData:a}}return e.kind==="barcode"||e.kind==="qrcode"?(delete n.imageData,{...n,code:{...n.code,value:a},fallbackText:a}):(delete n.lines,delete n.richParagraphs,{...n,text:a})}function Ut(e,t,r){if(e.kind!=="text"||e.grid||e.richParagraphs?.length)return e;const o=e.style??{},n=R.resolveFontSize(o).fontSizePt,a=e.text??e.lines?.join(`
2
2
  `)??"";if(a.length>16384)throw new S.ReportBindingError(r,"标签文本超过 16384 字符预算,请缩小字段内容",t.rowIndex);const s=t.wrapText(a,e.widthMm,{fontSizePt:n,bold:o.bold,italic:o.italic,fontFamily:o.fontFamily,letterSpacingPt:o.letterSpacing},t.options.measurer??D.heuristicMeasurer),i=s.length*n*R.resolveLineHeight(o)*25.4/72;if(i>e.heightMm+.05)throw new S.ReportBindingError(r,`标签文字需要约 ${i.toFixed(2)}mm 高,超出 ${e.heightMm}mm;请增大文本区域、减少内容或调整字号`,t.rowIndex,e.binding?.field);return{...e,lines:s}}function qe(e,t,r){be(t.options.signal);const o=qt(e,t,r);if(!o)return;let n=o.grid;return n&&(n={...n,cells:n.cells.map((a,s)=>a.map((i,c)=>i?.children?.length?{...i,children:i.children.flatMap((l,u)=>{const f=qe(l,t,`${r}.grid.cells.${s}.${c}.children.${u}`);return f?[f]:[]})}:i))}),Ut(n===o.grid?o:{...o,grid:n},t,r)}function Xt(e,t,r,o,n,a){return{...e,components:e.components.flatMap((s,i)=>{const c=qe(s,r,`$.pages.${t}.components.${i}`);return c?[{...c,meta:{...c.meta,labelSource:{pageIndex:t,componentIndex:i}}}]:[]}),meta:{...e.meta,record:{dataset:r.dataset,rowIndex:r.rowIndex,...a===void 0?{}:{rowKey:a},copyIndex:o,copyCount:n,templatePageIndex:t}}}}function*Yt(e,t,r){const o=[];if(j.validateTemplateRepeat(e,o),o.length)throw new S.ReportBindingError(o[0].path,o[0].message);if(!e.repeat){for(const[i,c]of e.pages.entries())yield{page:c,pageIndex:i};return}const n=e.repeat,a=Jt(e,t,r),s=Wt();for(const[i,c]of a.entries()){const l={row:c,rowIndex:i,dataset:n.dataset,options:r,wrapText:s},u=ze(n,c,l),f=Je(n,c,l);for(let d=0;d<u;d++)for(const[g,m]of e.pages.entries())be(r.signal),yield{page:Xt(m,g,l,d,u,f),pageIndex:g}}}function Qt(e){return{widthMm:e.widthMm,heightMm:e.heightMm,marginTopMm:e.marginTopMm??0,marginBottomMm:e.marginBottomMm??0,marginLeftMm:e.marginLeftMm??0,marginRightMm:e.marginRightMm??0,components:[]}}function Y(e,t){const r=t.heightMm-(e.layout==="wide"?t.marginBottomMm:e.marginBottomMm??t.marginBottomMm);return e.components.reduce((o,n)=>n.kind!=="list"&&n.pageAnchor==="footer"?Math.min(o,n.topMm):o,r)}function J(e){return e.components.reduce((t,r)=>r.kind!=="list"&&r.pageAnchor==="header"?Math.max(t,r.topMm+r.heightMm):t,0)}function Ue(e,t){let r=e.textMetrics.get(t);if(!r){const o=R.resolveFontSize(t).fontSizePt;r={measureOptions:{fontSizePt:o,fontFamily:t.fontFamily??R.DEFAULT_FONT_FAMILY,italic:t.italic,bold:t.bold,letterSpacingPt:t.letterSpacing},lineMm:o*(t.lineHeight??R.LINE_HEIGHT)*25.4/72},e.textMetrics.set(t,r)}return r}function Zt(e){if(e===null||typeof e=="string"||typeof e=="boolean"||typeof e=="number"&&Number.isFinite(e))return e}function ve(e,t,r=[],o){const n=e.fontSizePt??R.DEFAULT_FONT_PT,a=e.paddingMm??1,s=e.columns.map(w=>w.align??w.style?.align??e.align??"left"),i=e.columns.map((w,y)=>({...R.mergeComponentStyles({fontSize:n,verticalAlign:"middle"},w.style),align:s[y]==="auto"?"left":s[y]})),c=i.map((w,y)=>s[y]==="auto"?{left:w,center:{...w,align:"center"},right:{...w,align:"right"}}:void 0),l=e.columns.map((w,y)=>w.rules?.map(C=>{const P=c[y];if(P)return{left:R.mergeComponentStyles(P.left,C.style),center:R.mergeComponentStyles(P.center,C.style),right:R.mergeComponentStyles(P.right,C.style)};const T=R.mergeComponentStyles(i[y],C.style);return{left:T,center:T,right:T}})),u=e.columns.map(w=>S.resolveListHeaderStyle(e,w)),f=e.columns.map(w=>w.header);let d=e.rowHeightMm??0;for(let w=0;w<f.length;w++){const y=u[w],C=R.resolveFontSize(y).fontSizePt,P=D.wrapText(f[w],e.columns[w].widthMm-a*2,{fontSizePt:C,fontFamily:y.fontFamily??R.DEFAULT_FONT_FAMILY,italic:y.italic,bold:y.bold,letterSpacingPt:y.letterSpacing},t),T=C*(y.lineHeight??R.LINE_HEIGHT)*25.4/72;d=Math.max(d,Math.max(P.length,1)*T+a*2)}const g=f.map((w,y)=>({text:w,style:u[y]})),m=e.border===!1?{borderTop:!1,borderRight:!1,borderBottom:!1,borderLeft:!1}:{borderBottom:!0,borderLeft:!0,borderRight:!0,borderTop:!0},v=e.columns.map(w=>w.widthMm),p=er(Bt(e,t),v,{cells:[g],colWidthsMm:v,rowHeightsMm:[d],paddingMm:a});return{fontSizePt:n,paddingMm:a,visuals:G.createColumnVisualResolvers(e.columns,r,o),visibility:e.columns.map(w=>w.visibleWhen?I.compileReportPredicate(w.visibleWhen):void 0),ruleReaders:e.columns.map(w=>w.rules?.map(y=>I.compileReportPredicate(y.when))),cellStyles:i,autoStyles:c,ruleStyles:l,textMetrics:new WeakMap,numberFormats:e.columns.map(w=>S.toExcelNumberFormat(w.format)),derivedFields:new Set(e.computed?.map(w=>w.field)),borderStyle:m,headerHeightMm:p.rowHeightsMm.reduce((w,y)=>w+y,0),headerGrid:p,colWidthsMm:v,columns:e.columns}}function er(e,t,r){if(!e)return r;if(!e.cells.length)throw new Error("自定义列表表头至少需要一行");const o=e.rowHeightsMm??e.cells.map(()=>r.rowHeightsMm[0]);if(o.length!==e.cells.length||o.some(n=>!Number.isFinite(n)||n<=0))throw new Error("自定义列表表头行高无效");return{...e,colWidthsMm:t,rowHeightsMm:o}}function tr(e,t,r){const o=t.format?.kind==="number"||t.format?.kind==="percent";t.valueType!==void 0?e.valueType=t.valueType:o&&(e.valueType="number"),t.editable!==void 0&&(e.editable=t.editable),(typeof e.value=="number"||e.value==null)&&r!==void 0&&(e.numberFormat=r)}function q(e,t,r){const o=e.columns,n=e.tree?.rows.get(t);let a=e.rowHeightFloorMm;const s=new Array(o.length);for(let i=0;i<o.length;i++){const c=o[i],l=e.visibility[i]?.(t)!==!1,u=l?t[c.field]:null,f=e.autoStyles[i]?S.resolveListAutoAlignment(u,c.format,c.semanticRole):"left";let d=e.autoStyles[i]?.[f]??e.cellStyles[i];if(c.rules){for(let C=0;C<c.rules.length;C++)if(e.ruleReaders[i][C](t)){d=e.ruleStyles[i][C][f];break}}const g=c.format?S.formatValue(u,c.format):S.listCellText(u),m=rr(e,c,n);d=or(e,c,d,n);const v=Ue(e,d),p=D.wrapText(g,Math.max(1,c.widthMm-e.paddingMm*2-m),v.measureOptions,r);a=Math.max(a,p.length*v.lineMm+e.paddingMm*2);const w=Zt(u),y={text:g,style:d};u!=null&&e.visuals[i]?.apply(y,t),w!==void 0&&(y.value=w),tr(y,c,e.numberFormats[i]),nr(y,c,e,n,m),e.derivedFields.has(c.field)&&(y.derived=!0,y.editable=!1),l||(y.editable=!1),s[i]=y}return{grid:{cells:[s],colWidthsMm:e.colWidthsMm,rowHeightsMm:[a],paddingMm:e.paddingMm},heightMm:a,...e.matrix?{meta:{matrix:{row:e.matrix.rows.get(t)}}}:{}}}function rr(e,t,r){return!r||t.field!==e.tree.list.tree.labelField?0:S.listTreeIndent(e.tree.list,t,r,e.paddingMm)}function or(e,t,r,o){return!o||t.field!==e.tree.list.tree.labelField||r.align==="left"?r:{...r,align:"left"}}function nr(e,t,r,o,n=0){o&&(n&&(e.indentMm=n),S.applyListTreeMetadata(e,t,o,r.tree.list))}function Xe(e){if(e!=null&&typeof e!="string"&&typeof e!="boolean"&&!(typeof e=="number"&&Number.isFinite(e)))throw new Error("分组字段应为有限 JSON 标量");return JSON.stringify([typeof e,e??null])}function*Ye(e,t,r=0){const o=t[r];if(!o){for(const a of e)yield{kind:"row",row:a};return}const n=new Map;for(const a of e){const s=Xe(a[o.field]),i=n.get(s);i?i.push(a):n.set(s,[a])}for(const a of n.values())yield{kind:"groupHeader",label:(o.headerTemplate??"{value}").replace(/\{value\}/g,S.listCellText(a[0][o.field])),firstRow:a[0],group:o,depth:r,rows:a},yield*Ye(a,t,r+1),(o.subtotal?.length||o.aggregates?.length)&&(yield{kind:"subtotal",label:o.subtotalLabel??"小计",rows:a,group:o,depth:r}),yield{kind:"groupEnd",depth:r}}function Qe(e,t,r,o=[]){const n=[...r.filter(a=>!o.some(s=>s.field===a)).map(a=>({field:a,op:"sum"})),...o];return new Map(n.map(a=>{const s=e.find(c=>c.field===a.field)?.format??{kind:"number",thousands:!0},i=I.aggregateRows(t,{...a,field:a.valueField??a.field});return[a.field,{text:S.formatValue(i,s),...i===null?{}:{value:i},...typeof i=="number"?{numberFormat:S.toExcelNumberFormat(s)}:{}}]}))}function Ze(e,t){const r=e.findIndex(o=>t.includes(o.field));return r<0?1:r}function z(e,t,r,o,n,a){const s=[],i=Math.max(0,Math.min(a,e.columns.length)),c=R.mergeComponentStyles({fontSize:e.fontSizePt},n);i&&s.push({text:r,colSpan:i,style:{bold:!0,...c}});for(let d=i;d<e.columns.length;d++){const g=e.columns[d],m=o.get(g.field),v=e.autoStyles[d]?.[S.resolveListAutoAlignment(m?.value,g.format)]??e.cellStyles[d];s.push({...m,text:m?.text??"",style:R.mergeComponentStyles(v,n)})}const l={text:r,colSpan:e.columns.length,style:{bold:!0,...c}},u=i?[s]:[[l],s],f=u.map(d=>ar(e,d,t));return{grid:{cells:u,colWidthsMm:e.colWidthsMm,rowHeightsMm:f,paddingMm:e.paddingMm},heightMm:f.reduce((d,g)=>d+g,0)}}function ar(e,t,r){let o=e.rowHeightFloorMm,n=0;for(const a of t){let s=0;const i=n+(a.colSpan??1);for(;n<i;n++)s+=e.colWidthsMm[n]??0;const c=Ue(e,a.style),l=D.wrapText(a.text??"",s-e.paddingMm*2,c.measureOptions,r);o=Math.max(o,l.length*c.lineMm+e.paddingMm*2)}return o}function sr(e,t,r){const{templatePage:o,current:n,warnings:a,nextId:s,pushCurrent:i}=r,c=()=>Y(o,n),l=Math.max(n.marginTopMm,J(o)),u=o.layout==="wide"?J(o):l,f={id:r.tableId,columnKeys:e.columns.map(h=>h.field),...e.layout===void 0?{}:{layout:e.layout},...e.title===void 0?{}:{title:e.title}},d=new Map,g=new Map,m={kind:"rect",leftMm:e.leftMm,topMm:0,widthMm:e.widthMm,heightMm:t.headerHeightMm,grid:t.headerGrid,nid:s("listh"),table:{...f,role:"header",rowIndex:-1},style:t.borderStyle,...e.meta||t.matrix?{meta:{...e.meta,...t.matrix?{matrix:t.matrix.header}:{}}}:{}},v=h=>n.components.push({...m,topMm:h});if(r.flow&&e.header!==!1&&t.headerHeightMm>c()-l+.001)throw new Error(`流式列表 ${e.id??e.dataset} 的表头高度超出单页可用范围`);let p=Math.max(r.startTop??e.topMm,l);e.header!==!1&&(v(p),p+=t.headerHeightMm+r.mmPerRow);function w(){const h=Math.max(r.flow||o.layout==="wide"?0:e.topMm,u);return(e.header!==!1&&e.headerEveryPage!==!1?h+t.headerHeightMm:u)+[...g.values()].reduce((x,$)=>x+$.heightMm,0)}function y(){const h=o.layout==="wide"?0:n.marginBottomMm;return Math.min(o.heightMm-h,Y(o,n))-w()}function C(h){if(p+h<=c())return;i(),n.components=[],n.heightMm=o.heightMm,o.layout==="wide"&&(n.marginTopMm=0,n.marginBottomMm=0);const b=Math.max(r.flow||o.layout==="wide"?0:e.topMm,u);e.header!==!1&&e.headerEveryPage!==!1?(v(b),p=b+t.headerHeightMm):p=u;for(const x of g.values())T(x,"listgr","group-header")}function P(h,b,x,$){const k=y();if(r.flow&&h.heightMm>k+.001)throw new Error(`流式列表 ${e.id??e.dataset} 的单行高度超出单页可用范围`);h.heightMm>k&&a.push(`列表 ${e.id??e.dataset} 行高 ${h.heightMm.toFixed(2)}mm 超出单页可用高度 ${k.toFixed(2)}mm,预览与打印可能截断内容`),C(h.heightMm),T(h,b,x,$)}function T(h,b,x,$){const k=h.table?.id??f.id,F=x==="header"?-1:d.get(k)??0;x!=="header"&&d.set(k,F+h.grid.cells.length),n.components.push({kind:"rect",leftMm:e.leftMm,topMm:p,widthMm:e.widthMm,heightMm:h.heightMm,grid:h.grid,nid:s(b),table:{...f,...h.table,role:x,rowIndex:F,...$?{source:$}:{}},style:t.borderStyle,...e.meta||h.meta?{meta:{...e.meta,...h.meta}}:{}}),p+=h.heightMm}function N(h){h<=y()&&C(h)}return{keepTogether:N,placeGridRow:P,setGroupHeader:(h,b)=>{b?g.set(h,b):g.delete(h)},bottom:()=>p}}function ir(e,t){if(!e.rowKey)return;const r=t[e.rowKey];if((typeof r!="string"||!r.trim())&&!(typeof r=="number"&&Number.isFinite(r)))throw new Error(`数据集 ${e.dataset} 的 ${e.rowKey} 应为稳定的字符串或有限数字主键`);const o=e.revisionField?t[e.revisionField]:void 0,n=e.sourceTokenField?t[e.sourceTokenField]:void 0;if(o!==void 0&&typeof o!="string"&&!(typeof o=="number"&&Number.isFinite(o)))throw new Error("业务修订号应为字符串或有限数字");if(n!==void 0&&typeof n!="string")throw new Error("来源令牌应为字符串");return{datasetId:e.dataset,rowKey:r,...o===void 0?{}:{revision:o},...n===void 0?{}:{sourceToken:n}}}function ee(e,t){const r=new Map;if(!e.rowKey)return r;const o=new Set;for(const n of t){const a=ir(e,n),s=JSON.stringify(a.rowKey);if(o.has(s))throw new Error(`数据集 ${e.dataset} 的业务主键重复:${String(a.rowKey)}`);o.add(s),r.set(n,a)}return r}function cr(e,t,r,o,n){if(!e.grandTotal)return;const a=typeof e.grandTotal=="object"?e.grandTotal:void 0,s=te(e)[0],i=a?.fields??s?.subtotal??[],c=a?.aggregates??s?.aggregates??[];if(i.length===0&&c.length===0){o.warnings.push(`列表 ${e.id??""} 配置了 grandTotal 但未提供合计字段(groupBy.subtotal 或 grandTotal.fields)`);return}const l=z(r,o.measurer,a?.label??"合计",Qe(e.columns,t,i,c),a?.style??{},Ze(e.columns,[...i,...c.map(u=>u.field)]));n.placeGridRow(l,"listgt","grand-total")}function K(e){if(e?.aborted){const t=new Error("报表排版已取消");throw t.name="AbortError",t}}function te(e){const t=e.groups??(e.groupBy?[e.groupBy]:[]);if(t.length>16)throw new Error("列表最多支持 16 级分组");return t}function Me(e){const t=_e(e),r=t.columns.reduce((n,a)=>n+a.widthMm,0),o=r>t.widthMm?t.widthMm/r:1;return o===1?t:{...t,columns:t.columns.map(n=>({...n,widthMm:n.widthMm*o}))}}function lr(e,t,r){const o=e.detail;if(!o)return;const n=new Set;for(const l of t){const u=ue(l[o.parentKey]);if(n.has(u))throw new Error("主从明细的主表关联键重复");n.add(u)}const a=r.datasets[o.dataset]??[],s=new Map,i=[];for(const l of a){const u=l[o.foreignKey];if(!et(u)&&o.unmatched==="ignore")continue;const f=ue(u);if(!n.has(f)){if(o.unmatched!=="ignore")throw new Error(`明细数据集 ${o.dataset} 存在未关联的业务键`);continue}const d=s.get(f);d?d.push(l):s.set(f,[l]),i.push(l)}const c=Me({...e,id:`${e.id??e.dataset}:detail`,dataset:o.dataset,rowKey:o.rowKey,revisionField:o.revisionField,sourceTokenField:o.sourceTokenField,computed:void 0,columns:o.columns,headerGrid:void 0,rowHeightMm:o.rowHeightMm??e.rowHeightMm,detail:void 0});return{list:c,inter:{...ve(c,r.measurer,i,r.signal),rowHeightFloorMm:c.rowHeightMm??0},rows:s,sources:ee(c,i)}}function et(e){return typeof e=="string"&&!!e.trim()||typeof e=="number"&&Number.isFinite(e)}function ue(e){if(!et(e))throw new Error("主从关联键必须是非空字符串或有限数字");return Xe(e)}function*dr(e,t,r,o,n){if(!r)return;const a=r.rows.get(ue(t[e.detail.parentKey]))??[];if(!a.length)return;const s={id:`${o.tableId}:detail`,columnKeys:r.list.columns.map(i=>i.field),title:e.detail.label};e.detail.label&&n.placeGridRow({...z(r.inter,o.measurer,e.detail.label,new Map,{},r.list.columns.length),table:s},"listdl","group-header"),e.detail.header!==!1&&n.placeGridRow({grid:r.inter.headerGrid,heightMm:r.inter.headerHeightMm,table:s},"listdh","header"),yield*o.takePages();for(const i of a)K(o.signal),n.placeGridRow({...q(r.inter,i,o.measurer),table:s},"listdr","body",r.sources.get(i)),yield*o.takePages()}function tt(e){if(e.matrix||e.detail||e.groups?.length||e.groupBy||e.rowVisibleWhen)throw new Error("树形布局不能同时配置普通分组、矩阵、主从或行可见条件");if(e.rowKey&&e.rowKey!==e.tree.idField)throw new Error("树形布局的 rowKey 应与 idField 一致");if(!e.columns.some(t=>t.field===e.tree.labelField&&!t.hidden))throw new Error("树形布局需要可见的标签列");G.validateTreeComputed(e.tree,e.computed)}function ur(e,t,r){tt(e);const o=G.createTreeTable(t,e.tree,{signal:r.signal,computed:e.computed?.length?{fields:e.computed,formula:r.formula}:void 0}),n={...e,rowKey:e.tree.idField},a=ee(n,o.entries.map(c=>c.original)),s=new Map,i=new WeakMap;for(const c of o.entries)s.set(c.row,a.get(c.original)),i.set(c.row,c);return{list:n,rows:o.rows,sources:s,treeRows:i,totalRows:o.leaves}}function fr(e,t){if(e.cardinality==="record"){if(t.length>1)throw new Error(`单记录区域 ${e.id??e.dataset} 仅允许 0 或 1 行数据`);if(e.tree||e.matrix||e.detail||e.groups?.length||e.groupBy||e.grandTotal||e.rowVisibleWhen)throw new Error("单记录区域不能配置树、矩阵、主从、分组、总计或行过滤");if(!t.length)return{list:{...e,columns:e.columns.map(r=>({...r,editable:!1}))},rows:[{}],sources:new Map}}}function rt(e,t,r){const o=r.prepared.get(e);if(o)return o;const n=fr(e,t);if(n)return r.prepared.set(e,n),n;if(e.tree){const c=ur(e,t,r);return r.prepared.set(e,c),c}let a=e.computed?.length?I.computeDataset(t,{fields:e.computed,signal:r.signal,formula:r.formula}).rows:t;const s=a===t?void 0:new Map(a.map((c,l)=>[c,t[l]]));e.rowVisibleWhen&&(a=a.filter(I.compileReportPredicate(e.rowVisibleWhen)));const i=Dt(e,a);if(!e.matrix){const c=ee(e,s?a.map(l=>s.get(l)):a);i.sources=s?new Map(a.map(l=>[l,c.get(s.get(l))])):c}return r.prepared.set(e,i),i}function mr(e,t,r,o){if(!o.flow)return;const{current:n,templatePage:a}=o,s=Math.max(n.marginTopMm,J(a)),i=Math.max(o.startTop??e.topMm,s),c=(e.header===!1?0:t.headerHeightMm)+(r[0]?q(t,r[0],o.measurer).heightMm:0);i+c<=Y(a,n)+.001||i<=s+.001||(o.pushCurrent(),n.components=[],n.heightMm=a.heightMm,a.layout==="wide"&&(n.marginTopMm=0,n.marginBottomMm=0),o.startTop=Math.max(n.marginTopMm,J(a)))}function*gr(e,t,r){const o=rt(e,t,r),n=o.rows;e=o.list,e.layout==="wide"&&(r.current.widthMm=Math.max(r.current.widthMm,e.leftMm+e.widthMm+r.current.marginRightMm));const a=o.sources??ee(e,n),s=Me(e),i=te(s),c={...ve(s,r.measurer,n,r.signal),rowHeightFloorMm:s.rowHeightMm??0,matrix:o.matrix,...o.treeRows?{tree:{list:s,rows:o.treeRows}}:{}};mr(s,c,n,r);const l=sr(s,c,r),u=lr(s,n,r);let f;for(const d of Ye(n,i)){if(K(r.signal),d.kind==="row")l.placeGridRow(f??q(c,d.row,r.measurer),"listr",Kt(o.matrix,d.row),a.get(d.row)),f=void 0,yield*r.takePages(),yield*dr(s,d.row,u,r,l);else if(d.kind==="groupHeader"){const g=z(c,r.measurer,d.label,new Map,d.group.headerStyle??{},s.columns.length);f??=q(c,d.firstRow,r.measurer);const m=i.slice(d.depth+1).reduce((v,p)=>v+z(c,r.measurer,(p.headerTemplate??"{value}").replace(/\{value\}/g,S.listCellText(d.firstRow[p.field])),new Map,p.headerStyle??{},s.columns.length).heightMm,0);d.group.keepWithNext!==!1&&l.keepTogether(g.heightMm+m+f.heightMm),l.placeGridRow(g,"listg","group-header"),d.group.repeatHeader&&l.setGroupHeader(d.depth,g)}else if(d.kind==="subtotal"){const g=d.group.subtotal??[],m=d.group.aggregates??[],v=z(c,r.measurer,d.label,Qe(s.columns,d.rows,g,m),d.group.subtotalStyle??{},Ze(s.columns,[...g,...m.map(p=>p.field)]));l.placeGridRow(v,"listst","subtotal")}else l.setGroupHeader(d.depth);yield*r.takePages()}cr(s,o.totalRows??n,c,r,l),r.finished?.(l.bottom()),yield*r.takePages()}function re(e){return e.kind!=="list"&&(e.pageAnchor!==void 0||e.kind==="text"&&typeof e.text=="string"&&(e.text.includes("{page}")||e.text.includes("{totalPages}")))}function oe(e,t){return{...e,...e.text===void 0?{}:{text:t(e.text)},...e.lines?{lines:e.lines.map(t)}:{},...e.richParagraphs?{richParagraphs:e.richParagraphs.map(r=>({...r,segments:r.segments.map(o=>({...o,...o.text===void 0?{}:{text:t(o.text)}}))}))}:{},...e.grid?{grid:{...e.grid,cells:e.grid.cells.map(r=>r.map(o=>o?{...o,...o.text===void 0?{}:{text:t(o.text)},...o.children?{children:o.children.map(n=>oe(n,t))}:{}}:null))}}:{}}}function hr(e){let t=!1;for(const r of e.pages)for(const o of r.components)re(o)&&oe(o,n=>(n.includes("{totalPages}")&&(t=!0),n));return t}function pr(e,t,r,o,n,a){const s={pageWidthMm:t.widthMm,pageHeightMm:t.heightMm,...e.layout===void 0?{}:{layout:e.layout},marginTopMm:t.marginTopMm,marginBottomMm:t.marginBottomMm,marginLeftMm:t.marginLeftMm,marginRightMm:t.marginRightMm,components:t.components,...e.meta?{meta:e.meta}:{}},i=c=>{const l=c.replace(/\{page\}/g,String(o));return a===void 0?l:l.replace(/\{totalPages\}/g,String(a))};for(const c of r)s.components.push(oe(c,i));if(e.layout==="wide"){const c=s.components.reduce((l,u)=>Math.max(l,u.topMm+u.heightMm),0);s.marginBottomMm=n?e.marginBottomMm??0:0,s.pageHeightMm=Math.max(1,c+s.marginBottomMm)}return s}function Se(e){return e.cells.reduce((t,r)=>t+r.reduce((o,n)=>o+(n?1+(n.children?.reduce((a,s)=>a+ot(s),0)??0):0),0),0)}function ot(e){return e.grid?Se(e.grid):0}function ne(e){for(const t of["maxPages","maxCells","knownTotalPages"])if(e[t]!==void 0&&(!Number.isSafeInteger(e[t])||e[t]<1))throw new RangeError(`${t} 应为正安全整数`);S.validateChartComponentLimit(e.maxChartComponents)}function wr(e,t){const r=rt(e,t.datasets[e.dataset]??[],t),o=Me(r.list),n={...ve(o,t.measurer,r.rows,t.signal),rowHeightFloorMm:o.rowHeightMm??0};return(o.header===!1?0:n.headerHeightMm)+r.rows.reduce((a,s)=>a+q(n,s,t.measurer).heightMm,0)}function*yr(e){const{templatePage:t,current:r}=e,o=new Map(t.components.map((a,s)=>[a,s])),n=(a,s,i)=>{const c=e.datasets[a.dataset];return Array.isArray(c)||e.warnings.push(`数据集 ${a.dataset} 未提供数据,列表 ${a.id??""} 输出为空`),gr(a,Array.isArray(c)?c:[],{...e,tableId:`${e.tableId}:${o.get(a)}`,startTop:s,finished:i,flow:!!t.flow})};if(t.flow){yield*Gt({page:t,active:()=>K(e.signal),top:()=>Math.max(r.marginTopMm,J(t)),bottom:()=>Y(t,r),append:a=>{r.components.push(...e.resolveChart(a))},nextPage:()=>{e.pushCurrent(),r.components=[],r.heightMm=t.heightMm,t.layout==="wide"&&(r.marginTopMm=0,r.marginBottomMm=0)},takePages:e.takePages,height:a=>wr(a,e),list:n});return}for(const a of t.components)re(a)||(a.kind==="list"?yield*n(a):r.components.push(...e.resolveChart(a)))}function*U(e,t,r,o,n,a=new WeakMap,s){let i=0,c=0,l=0;const u=Lt(r.measurer??D.heuristicMeasurer),f=S.createChartResolver(t,r.signal,r.maxChartComponents),d=g=>`${g}_${(++i).toString(36)}`;for(const{pageIndex:g,page:m}of Yt(e,t,r)){K(r.signal);const v=Qt(m),p=m.components.filter(re);let w=[];const y=(P=!1)=>{if(K(r.signal),r.maxPages!==void 0&&c>=r.maxPages)throw new S.PaginatePageLimitError(r.maxPages,c+1);if(r.maxCells!==void 0&&(l+=[...v.components,...p].reduce((T,N)=>T+ot(N),0),l>r.maxCells))throw new S.PaginateCellLimitError(r.maxCells,l);w.push(pr(m,v,p,++c,P,n))},C=()=>{const P=w;return w=[],P};yield*yr({templatePage:m,current:v,warnings:o,nextId:d,pushCurrent:y,takePages:C,datasets:t,resolveChart:f,signal:r.signal,formula:r.formula,prepared:a,measurer:u,mmPerRow:r.mmPerRow??0,tableId:`table:${g}`}),y(!0),yield*C()}s&&(s.chartComponents=f.used())}function br(e,t,r={}){ne(r);let o=0;for(const n of U(e,t,{...r,onWarning:void 0},[]))o++;return o}function*vr(e,t,r={}){yield*Mr(e,t,r)}function*Mr(e,t,r,o){ne(r);const n=hr(e),a=new WeakMap;let s=r.knownTotalPages;if(n&&s===void 0){s=0;for(const l of U(e,t,r,[],void 0,a))s++}const i=[];let c=0;for(const l of U(e,t,r,i,s,a,o)){for(;c<i.length;c++)r.onWarning?.(i[c]);yield l}}function xe(e,t,r={}){const o=typeof r=="number"?{mmPerRow:r}:r;ne(o);const n=[],a={chartComponents:0},s=[...U(e,t,o,n,o.knownTotalPages,void 0,a)];return at(e,o,s,n,a)}async function nt(e,t,r={}){ne(r),K(r.signal);const o=[],n=[],a={chartComponents:0};let s=performance.now(),i=0;for(const c of U(e,t,r,o,r.knownTotalPages,void 0,a))n.push(c),(++i>=8||performance.now()-s>=8)&&(await new Promise(l=>setTimeout(l,0)),K(r.signal),s=performance.now(),i=0);return K(r.signal),at(e,r,n,o,a)}function at(e,t,r,o,n){for(const a of r)a.components=a.components.map(s=>re(s)?oe(s,i=>i.replace(/\{totalPages\}/g,String(r.length))):s);return o.forEach(a=>t.onWarning?.(a)),{plan:{schemaVersion:R.RENDER_PLAN_SCHEMA_VERSION,...ye(e)?{requiresRecalculation:!0}:{},pages:r},warnings:o,...n}}function Sr(e){const t=e.columns.find(a=>!a.hidden)?.field;if(!t)return{groups:0,total:0};const r=te(e),o=(a=[],s=[])=>a.includes(t)||s.some(i=>i.field===t),n=typeof e.grandTotal=="object"?e.grandTotal:void 0;return{groups:r.filter(a=>o(a.subtotal,a.aggregates)).length,total:Number(o(n?.fields??r[0]?.subtotal,n?.aggregates??r[0]?.aggregates))}}function xr(e,t,r){tt(e);const o=G.flattenTreeInput(t[e.dataset]??[],e.tree,r),n=e.columns.filter(s=>!s.hidden).length,a=e.header===!1?0:e.headerGrid?Se(e.headerGrid):n;return o.length*n+a+ +!!e.grandTotal*2*n}function Cr(e,t,r={}){if(e.tree)return xr(e,t,r.signal);if(e.matrix){let c=t[e.dataset]??[];e.computed?.length&&(c=I.computeDataset(c,{fields:e.computed,...r}).rows),e.rowVisibleWhen&&(c=c.filter(I.compileReportPredicate(e.rowVisibleWhen)));const l=Ge.estimateMatrixTable(c,e.matrix);return l.cells+(e.header===!1?0:l.columnCount*(e.matrix.hierarchy?e.matrix.columnFields.length+1:1))}const o=t[e.dataset]?.length??0,n=e.columns.filter(c=>!c.hidden).length,a=te(e).length,s=Sr(e);let i=(o*(1+2*a+s.groups)+ +!!e.grandTotal*(1+s.total))*n;if(i+=e.header===!1?0:e.headerGrid?Se(e.headerGrid):n,e.cardinality==="record"&&o===0&&(i+=n),e.detail){const c=t[e.detail.dataset]?.length??0,l=e.detail.columns.filter(u=>!u.hidden).length;i+=(c+o*(+(e.detail.header!==!1)+ +!!e.detail.label))*l}if(!Number.isSafeInteger(i))throw new RangeError("报表单元格估算超出安全整数预算");return i}class st extends Error{constructor(t){super(t.map(r=>r.message).join(";")),this.issues=t,this.name="ReportValidationError"}}function Ke(e,t,r){if(!Number.isSafeInteger(e)||e<1||e>r)throw new Error(`校验 ${t} 超出预算`);return e}function Er(e){if(e.aggregates&&e.scope!=="dataset")throw new Error("仅数据集规则允许汇总");if(e.aggregates&&(!Array.isArray(e.aggregates)||e.aggregates.length>64))throw new Error("校验汇总最多 64 项");const t=new Set;for(const r of e.aggregates??[]){if(I.computationFieldName(r.field),t.has(r.field))throw new Error("校验汇总字段重复");t.add(r.field),r.valueField!==void 0&&I.computationFieldName(r.valueField),r.weightField!==void 0&&I.computationFieldName(r.weightField),I.aggregateRows([],{...r,field:r.valueField??r.field})}}function it(e){if(!Array.isArray(e)||e.length>256||Object.keys(e).length!==e.length)throw new Error("校验规则最多 256 条且不允许空位");const t=new Set;return e.map(r=>{if(!r||typeof r!="object")throw new Error("校验规则应为声明式对象");if(I.computationFieldName(r.id),t.has(r.id))throw new Error("校验规则 id 重复");if(t.add(r.id),r.field!==void 0&&I.computationFieldName(r.field),r.dataset!==void 0&&I.computationFieldName(r.dataset),typeof r.message!="string"||!r.message.trim()||r.message.length>2048)throw new Error("校验规则需要有界提示文案");if(r.severity!==void 0&&!["error","warning"].includes(r.severity))throw new Error("未知校验严重程度");if(r.scope!==void 0&&!["row","dataset"].includes(r.scope))throw new Error("未知校验范围");Er(r);const o={nodes:0},n=I.compileReportPredicate(r.assert,o),a=r.when?I.compileReportPredicate(r.when,o):void 0;return{rule:r,assert:n,when:a,checks:o.nodes}})}function je(e){if(e?.aborted){const t=new Error("报表校验已取消");throw t.name="AbortError",t}}function Rr(e,t,r,o){const n=o&&Object.prototype.hasOwnProperty.call(t,o)?t[o]:void 0;if(n!==void 0&&typeof n!="string"&&!(typeof n=="number"&&Number.isFinite(n)))throw new Error("校验定位需要稳定的文本或数值业务键");return{ruleId:e.id,rowIndex:r,...n===void 0?{}:{rowKey:n},field:e.field,severity:e.severity??"error",message:e.message}}function Pr(e,t){const r=t.computed?.length?{fields:t.computed,formula:t.formula,signal:t.signal}:void 0;if(t.tree){const n=G.createTreeTable(e,t.tree,{signal:t.signal,computed:r});if(n.rows.length>1e5)throw new Error("校验展开后数据最多 100000 行");return{rows:n.rows,summaryRows:n.leaves,rowKey:t.tree.idField}}const o=r?I.computeDataset(e,r).rows:e;return{rows:o,summaryRows:o,rowKey:t.rowKey}}function Tr(e,t){const r=new Set;e.forEach(o=>{if(!o||typeof o!="object"||Array.isArray(o))throw new Error("校验数据行应为对象");if(!t)return;const n=Object.prototype.hasOwnProperty.call(o,t)?o[t]:void 0;if(!(typeof n=="string"&&n.trim())&&!(typeof n=="number"&&Number.isFinite(n)))throw new Error("校验定位需要稳定业务键");if(r.has(n))throw new Error("校验业务键重复");r.add(n)})}function kr(e,t){return ct(e,t,{checks:0})}function ct(e,t,r){if(!Array.isArray(e)||e.length>1e5)throw new Error("校验数据最多 100000 行");je(t.signal);const o=Ke(t.maxChecks??2e6,"maxChecks",1e7),n=Ke(t.maxIssues??1e3,"maxIssues",1e4);t.rowKey!==void 0&&I.computationFieldName(t.rowKey);const a=Pr(e,t),{rows:s,summaryRows:i,rowKey:c}=a;Tr(s,c);const l=it(t.rules),u=l.reduce((d,g)=>d+(g.rule.scope==="dataset"?g.checks+i.length*(g.rule.aggregates?.length??0):s.length*g.checks),0);if(r.checks+=u,r.checks>o)throw new Error("整批校验超出 maxChecks 预算");const f=[];for(const d of l)(d.rule.scope==="dataset"?[Object.fromEntries((d.rule.aggregates??[]).map(m=>[m.field,I.aggregateRows(i,{...m,field:m.valueField??m.field})]))]:s).forEach((m,v)=>{if(je(t.signal),!m||typeof m!="object"||Array.isArray(m))throw new Error("校验数据行应为对象");if(!(d.when&&!d.when(m)||d.assert(m))){if(f.length>=n)throw new Error("校验问题超出 maxIssues 预算,请缩小范围");f.push(Rr(d.rule,m,d.rule.scope==="dataset"?void 0:v,d.rule.scope==="dataset"?void 0:c))}});return f}function lt(e,t="allow"){if(!["allow","block"].includes(t))throw new Error("未知校验警告策略");if(!Array.isArray(e)||e.length>1e4||e.some(r=>!r||!["error","warning"].includes(r.severity)||typeof r.ruleId!="string"||!r.ruleId.trim()||typeof r.message!="string"||!r.message.trim()))throw new Error("校验问题结构无效");if(e.some(r=>r.severity==="error"||t==="block"))throw new st(e)}function De(e,t,r){const o=e.get(t);if(o&&JSON.stringify(o)!==JSON.stringify(r))throw new Error("同一数据集的校验计算/业务键存在歧义,请统一绑定");e.set(t,r)}function Ir(e,t,r,o=[]){it(t.rules);const n=[],a={checks:0};for(const[i,c]of e.entries()){const l=new Map;for(const u of c.template.pages)for(const f of u.components)f.kind==="list"&&(De(l,f.dataset,{rowKey:f.tree?.idField??f.rowKey,computed:f.computed,tree:f.tree}),f.detail&&De(l,f.detail.dataset,{rowKey:f.detail.rowKey}));for(const[u,f]of l){const d=t.rules.filter(g=>!g.dataset||g.dataset===u);if(d.length&&(n.push(...ct(c.datasets[u]??[],{...t,rules:d,...f,formula:o[i],signal:r},a).map(g=>({...g,dataset:u,sourceScope:c.sourceScope}))),n.length>(t.maxIssues??1e3)))throw new Error("整批候选校验问题超出 maxIssues 预算")}}const s=new Set(e.flatMap(i=>i.template.pages.flatMap(c=>c.components.flatMap(l=>l.kind==="list"?[l.dataset,...l.detail?[l.detail.dataset]:[]]:[]))));if(t.rules.some(i=>i.dataset&&!s.has(i.dataset)))throw new Error("校验目标数据集不存在");return n}function dt(e){return!e||typeof e!="object"?!1:[e.pageIndex,e.componentIndex,e.rowIndex,e.columnIndex].every(t=>Number.isInteger(t)&&t>=0)}function ut(e,t,r){const o=e.grid;if(!o)return null;const n=o.cells[t];if(!n)return null;const s=R.resolveGridLayout(o,e.widthMm,e.heightMm).cells.filter(c=>c.ri===t).findIndex(c=>c.ci===r),i=n[s];return i?{cell:i,sourceColumnIndex:s}:null}function $r(e){return e.value!==void 0?e.value:e.rawText??e.text??null}function Fr(e,t){return e.valueType?e.valueType:typeof t=="number"?"number":typeof t=="boolean"?"boolean":t===null&&e.numberFormat&&/[0#?]/.test(e.numberFormat)?"number":"text"}function Or(e,t){if(e.derived)return"derived";if(e.editable===!1)return"cell";if(e.formula!==void 0)return"formula";if(e.children?.length||e.richParagraphs?.length)return"complex";if(t.table&&t.table.role!=="body"&&e.editable!==!0)return"structure"}function Ar(e,t){const r=e.table;if(r)return{id:r.id,rowIndex:r.rowIndex+t.rowIndex,role:r.role,columnKey:r.columnKeys[t.columnIndex]}}function Nr(e,t,r){if(e.derived)return;if(e.source)return{...e.source};const o=t.table?.source,n=t.table?.columnKeys[r.columnIndex];if(!(!o||o.rowKey===void 0||n===void 0))return{...o,rowKey:o.rowKey,field:n}}function ft(e,t,r){const o=$r(r),n=Or(r,e);return{address:{...t},cell:r,component:e,value:o,valueType:Fr(r,o),table:Ar(e,t),source:Nr(r,e,t),editable:n===void 0,readOnlyReason:n}}function ae(e,t){if(!dt(t))return null;const r=e.pages[t.pageIndex]?.components[t.componentIndex];if(!r)return null;const o=ut(r,t.rowIndex,t.columnIndex);return o?ft(r,t,o.cell):null}function B(e){const t=new Map;return r=>{if(!dt(r))return null;const o=e.pages[r.pageIndex]?.components[r.componentIndex];if(!o?.grid)return null;let n=t.get(o);if(!n){const s=new Map;n=new Map;for(const i of R.resolveGridLayout(o.grid,o.widthMm,o.heightMm).cells){const c=s.get(i.ri)??0;s.set(i.ri,c+1);const l=o.grid.cells[i.ri]?.[c];l&&n.set(`${i.ri}:${i.ci}`,l)}t.set(o,n)}const a=n.get(`${r.rowIndex}:${r.columnIndex}`);return a?ft(o,r,a):null}}class M extends Error{constructor(t){super(`Invalid report cell edit: ${t}`),this.code=t,this.name="ReportCellEditError"}}function Lr(e,t){let r=e.trim();const o=t&&r.endsWith("%");if(o&&(r=r.slice(0,-1).trim()),/^[+-]?\d{1,3}(?:,\d{3})+(?:\.\d*)?(?:[eE][+-]?\d+)?$/.test(r)&&(r=r.replace(/,/g,"")),!/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(r))throw new M("number");return Number(r)/(o?100:1)}function Kr(e,t){if(e===null||typeof e=="string"&&e.trim()==="")return null;if(typeof e!="string"&&typeof e!="number")throw new M("number");const r=typeof e=="number"?e:Lr(e,Ve.isExcelPercentageFormat(t.cell.numberFormat));if(!Number.isFinite(r)||Number.isInteger(r)&&!Number.isSafeInteger(r))throw new M("number");return r}function jr(e){if(e===null||typeof e=="string"&&e.trim()==="")return null;if(typeof e=="boolean")return e;const t=String(e).trim().toLowerCase();if(["true","yes","是","1"].includes(t))return!0;if(["false","no","否","0"].includes(t))return!1;throw new M("boolean")}function Ce(e,t){return e.valueType==="number"?Kr(t,e):e.valueType==="boolean"?jr(t):t===null?null:String(t)}function Dr(e,t){const r=t.cell.text,n=[["是","否"],["TRUE","FALSE"],["True","False"],["true","false"],["1","0"]].find(a=>a.includes(r??""));return n?n[e?0:1]:String(e)}function V(e,t){return t===null?"":typeof t=="boolean"?Dr(t,e):typeof t=="number"?Ve.formatExcelNumber(t,e.cell.numberFormat):String(t)}function Br(e,t,r){const o=ae(e,t);if(!o)throw new M("missing");return _(o,r)}function _(e,t){if(!e.editable)throw new M("readonly");const r=Ce(e,t);return{address:{...e.address},table:e.table,source:e.source,previousValue:e.value,previousText:e.cell.text??"",value:r,text:V(e,r)}}function Hr(e,t){const r=e.table,o=t.table;return!r||!o||r.columnKey===void 0?!1:r.id===o.id&&r.rowIndex===o.rowIndex&&r.role===o.role&&r.columnKey===o.columnKey}function mt(e,t,r){const o=e.grid,{rowIndex:n,columnIndex:a}=t.address,s=ut(e,n,a),i=[...o.cells],c=[...i[n]],l=V(t,r.value),u={...s.cell,value:r.value,text:l,rawText:l};return c[s.sourceColumnIndex]=u,i[n]=c,{...e,grid:{...o,cells:i}}}function Gr(e,t){const r=e.table?.columnKeys,o=t.table?.columnKey;return r&&o!==void 0?r.flatMap((n,a)=>n===o?[a]:[]):[]}function Vr(e,t,r,o,n,a){const s=t.table,i=n.table;if(!s||!i||s.id!==i.id||s.role!==i.role||!t.grid)return t;const c=i.rowIndex-s.rowIndex;if(c<0||c>=t.grid.cells.length)return t;let l=t;for(const u of Gr(t,n)){const f=ae(e,{pageIndex:r,componentIndex:o,rowIndex:c,columnIndex:u});f?.editable&&Hr(n,f)&&(l=mt(l,f,a))}return l}function _r(e,t,r,o,n,a){const s=n.address;return n.table?.columnKey!==void 0?Vr(e,t,r,o,n,a):s.pageIndex===r&&s.componentIndex===o?mt(t,n,a):t}function se(e,t){const r=t.source;if(!r)return!1;const o=e.source;return!o||["sourceScope","datasetId","rowKey","field","revision","sourceToken"].some(n=>!Object.is(o[n],r[n]))}function Wr(e,t){const r=ae(e,t.address);if(!r)throw new M("missing");if(!r.editable)throw new M("readonly");if(se(r,t))throw new M("conflict");if(!Object.is(r.value,t.previousValue)||(r.cell.text??"")!==t.previousText)throw new M("conflict");const o=Ce(r,t.value),n={...t,value:o,text:V(r,o)};if(Object.is(o,r.value)&&n.text===r.cell.text)return e;const a=e.pages.map((s,i)=>{const c=s.components.map((l,u)=>_r(e,l,i,u,r,n));return c.every((l,u)=>l===s.components[u])?s:{...s,components:c}});return{...e,pages:a}}function gt(e){const t=[];for(const r of e.template.pages)for(const o of r.components)o.kind==="list"&&(t.push(o.tree?{...o,rowKey:o.tree.idField}:o),o.detail&&t.push({...o.detail,relation:{detail:o.detail,parentRows:e.datasets[o.dataset]??[]}}));return t}function W(e){return JSON.stringify([e.sourceScope,e.datasetId])}function Be(e){return JSON.stringify([e.sourceScope,e.datasetId,e.rowKey])}function ht(e){const t=new Map,r=new Set;return e.forEach((o,n)=>{for(const a of gt(o)){if(!a.rowKey)continue;const s=a.relation,i=s?new Set(s.parentRows.map(c=>JSON.stringify(c[s.detail.parentKey]))):void 0;(o.datasets[a.dataset]??[]).forEach((c,l)=>{if(s&&!i.has(JSON.stringify(c[s.detail.foreignKey])))return;const u=c[a.rowKey];if(typeof u!="string"&&typeof u!="number")return;const f=`${n}:${a.dataset}:${l}:${a.rowKey}`;if(r.has(f))return;r.add(f);const d=Be({sourceScope:o.sourceScope,datasetId:a.dataset,rowKey:u}),g=t.get(d)??[];g.push({partIndex:n,dataset:a.dataset,rowIndex:l,row:c,binding:a}),t.set(d,g)})}}),o=>{const n=t.get(Be(o));if(!n?.length)throw new M("missing");if(new Set(n.map(a=>`${a.partIndex}:${a.dataset}`)).size!==n.length)throw new M("conflict");return n}}function pt(e,t){const r=e.map(n=>({...n,datasets:{...n.datasets}})),o=new Set;for(const{row:n,field:a,value:s}of t){const i=r[n.partIndex],c=JSON.stringify([n.partIndex,n.dataset]);o.has(c)||(i.datasets[n.dataset]=[...i.datasets[n.dataset]],o.add(c)),i.datasets[n.dataset][n.rowIndex]={...i.datasets[n.dataset][n.rowIndex],[a]:s}}for(const n of o){const[a,s]=JSON.parse(n);I.forkComputedDataset(e[a].datasets[s],r[a].datasets[s])}return r}function zr(e,t,r){const o=[],n=new Set;return e.forEach((a,s)=>{for(const i of gt(a))t.has(W({sourceScope:a.sourceScope,datasetId:i.dataset}))&&(a.datasets[i.dataset]??[]).forEach((c,l)=>{const u={partIndex:s,dataset:i.dataset,rowIndex:l,row:c,binding:i};for(const[f,d]of[[i.revisionField,r.revision],[i.sourceTokenField,r.sourceToken]]){if(!f||d===void 0)continue;const g=`${s}:${i.dataset}:${l}:${f}`;n.has(g)||(n.add(g),o.push({row:u,field:f,value:d}))}})}),o}function wt(e,t,r){if(!r||r.revision===void 0&&r.sourceToken===void 0)return e;const o=new Set(t.edits.flatMap(n=>n.source?[W(n.source)]:[]));return Ee(e,new Map([...o].map(n=>[n,r])))}function Ee(e,t){if(!t.size)return e;function r(a){const s=a.datasetId&&t.get(W({...a,datasetId:a.datasetId}));return!s||(s.revision===void 0||Object.is(s.revision,a.revision))&&(s.sourceToken===void 0||s.sourceToken===a.sourceToken)?a:{...a,...s.revision!==void 0?{revision:s.revision}:{},...s.sourceToken!==void 0?{sourceToken:s.sourceToken}:{}}}function o(a){const s=a.map(i=>{const c=i.table?.source?r(i.table.source):void 0,l=i.table&&c!==i.table.source?{...i.table,source:c}:i.table,u=i.grid?.cells.map(d=>{const g=d.map(m=>{if(!m)return m;const v=m.source?r(m.source):void 0,p=m.children?o(m.children):void 0;return v===m.source&&p===m.children?m:{...m,source:v,children:p}});return g.some((m,v)=>m!==d[v])?g:d}),f=i.grid&&u?.some((d,g)=>d!==i.grid.cells[g])?{...i.grid,cells:u}:i.grid;return l!==i.table||f!==i.grid?{...i,table:l,grid:f}:i});return s.some((i,c)=>i!==a[c])?s:a}const n=e.pages.map(a=>{const s=o(a.components);return s!==a.components?{...a,components:s}:a});return n.some((a,s)=>a!==e.pages[s])?{...e,pages:n}:e}function Jr(e){return JSON.stringify([e.pageIndex,e.componentIndex,e.rowIndex,e.columnIndex])}function He(e){const t=e.table;return t?.columnKey!==void 0?JSON.stringify([t.id,t.role,t.rowIndex,t.columnKey]):Jr(e.address)}function qr(e,t){if(!t.length)return e;const r=new Map(t.map(c=>[He(c),c])),o=new Set(t.flatMap(c=>c.table?[c.table.id]:[])),n=new Set(t.map(c=>`${c.address.pageIndex}:${c.address.componentIndex}`)),a=B(e);function s(c,l,u){const f=c.grid;if(!f||!n.has(`${l}:${u}`)&&!o.has(c.table?.id??""))return c;const d=new Map,g=new Map;for(const m of R.resolveGridLayout(f,c.widthMm,c.heightMm).cells){const v=g.get(m.ri)??0;g.set(m.ri,v+1);const p=a({pageIndex:l,componentIndex:u,rowIndex:m.ri,columnIndex:m.ci}),w=p&&r.get(He(p));if(!w||!p.editable)continue;const y=d.get(m.ri)??[...f.cells[m.ri]],C=V(p,w.value);Object.is(p.value,w.value)&&C===p.cell.text||(y[v]={...m.cell,value:w.value,text:C,rawText:C},d.set(m.ri,y))}return d.size?{...c,grid:{...f,cells:f.cells.map((m,v)=>d.get(v)??m)}}:c}const i=e.pages.map((c,l)=>{const u=c.components.map((f,d)=>s(f,l,d));return u.every((f,d)=>f===c.components[d])?c:{...c,components:u}});return i.every((c,l)=>c===e.pages[l])?e:{...e,pages:i}}function A(e){const t=e.source;if(t)return JSON.stringify([t.sourceScope,t.datasetId,t.rowKey,t.field]);const r=e.table;if(r?.columnKey!==void 0)return JSON.stringify([r.id,r.role,r.rowIndex,r.columnKey]);const o=e.address;return JSON.stringify([o.pageIndex,o.componentIndex,o.rowIndex,o.columnIndex])}function Ur(e,t,r){if(typeof r!="string"||!r.trim()||!Array.isArray(t))throw new M("missing");if(t.length>1e4)throw new M("limit");const o=new Set,n=B(e),a=t.map(({address:s,value:i})=>{const c=n(s);if(!c)throw new M("missing");const l=_(c,i),u=A(l);if(o.has(u))throw new M("duplicate");return o.add(u),l});return{requestId:r,edits:a}}function Xr(e,t){if(t.edits.length>1e4)throw new M("limit");const r=B(e),o=new Set,n=t.edits.map(a=>{const s=r(a.address);if(!s)throw new M("missing");const i=A(a);if(o.has(i))throw new M("duplicate");if(o.add(i),se(s,a)||!Object.is(s.value,a.previousValue)||(s.cell.text??"")!==a.previousText)throw new M("conflict");return _(s,a.value)});return qr(e,n)}function Yr(e){const t=new Map;for(const r of e){const o=A(r),n=t.get(o),a=n?{...r,previousValue:n.previousValue,previousText:n.previousText}:{...r};Object.is(a.previousValue,a.value)?t.delete(o):t.set(o,a)}return[...t.values()]}function yt(e){const t=new Map,r=B(e);return e.pages.forEach((o,n)=>o.components.forEach((a,s)=>{if(!(!a.grid||a.table?.role!=="body"))for(let i=0;i<a.grid.cells.length;i++)for(let c=0;c<a.table.columnKeys.length;c++){const l=r({pageIndex:n,componentIndex:s,rowIndex:i,columnIndex:c});l?.source&&l.editable&&t.set(A(l),l)}})),t}function Qr(e,t,r){const o=yt(e),n=B(e);return t.map(a=>{const s=a.source?o.get(A(a)):n(a.address);if(!s||A(s)!==A(a))throw new M("missing");return{address:{...s.address},value:a[r]}})}function bt(e,t){if(++e.nodes>1e6||t>128)throw new M("limit")}function Q(e,t){const r=Object.getOwnPropertyDescriptor(e,t);if(!r||r.get||r.set)throw new M("conflict");return r.value}function Re(e){if(Object.getOwnPropertyDescriptor(e,"toJSON"))throw new M("conflict");const t=Object.getPrototypeOf(e);if(Array.isArray(e)&&(t!==Array.prototype||Object.keys(e).length!==e.length))throw new M("conflict");if(!(e instanceof Date)&&!Array.isArray(e)&&t!==Object.prototype&&t!==null)throw new M("conflict");for(const r of Reflect.ownKeys(e))if(!(Array.isArray(e)&&r==="length")){if(typeof r=="symbol"||!Object.getOwnPropertyDescriptor(e,r)?.enumerable)throw new M("conflict");if(e instanceof Date||Array.isArray(e)&&!/^(0|[1-9]\d*)$/.test(r))throw new M("conflict")}}function vt(e,t,r,o,n){if(bt(o,n),typeof e=="function"||typeof e=="symbol")throw new M("conflict");if(e===null||typeof e!="object")return;if(Re(e),r.has(e))throw new M("conflict");r.add(e);const a=Object.keys(e),s=a.map(i=>Q(e,i));t.push({object:e,prototype:Object.getPrototypeOf(e),keys:a,values:s,...e instanceof Date?{date:Date.prototype.getTime.call(e)}:{},...Array.isArray(e)?{length:e.length}:{}});for(const i of s)vt(i,t,r,o,n+1);r.delete(e)}function Zr(e){const{object:t,keys:r,values:o}=e;if(Re(t),Object.getPrototypeOf(t)!==e.prototype||Object.getOwnPropertyDescriptor(t,"toJSON")||e.date!==void 0&&!Object.is(Date.prototype.getTime.call(t),e.date)||e.length!==void 0&&t.length!==e.length)return!1;const n=Object.keys(t);return n.length===r.length&&r.every((a,s)=>n[s]===a&&Object.is(Q(t,a),o[s]))}function eo(e){const t=[];return vt(e,t,new Set,{nodes:0},0),()=>{try{return t.every(Zr)}catch{return!1}}}function Z(e,t,r,o=!1){if(bt(t,r),o){if(typeof e=="function"||typeof e=="symbol")throw new M("conflict");e!==null&&typeof e=="object"&&Re(e)}if(e===null||typeof e!="object")return e;if(e instanceof Date)return new Date(Date.prototype.getTime.call(e));if(Array.isArray(e)){const n=[];for(let a=0;a<e.length;a++)n[a]=Z(Q(e,String(a)),t,r+1,o);return n}return Object.fromEntries(Object.keys(e).map(n=>[n,Z(Q(e,n),t,r+1,o)]))}function to(e){return Z(e,{nodes:0},0,!0)}function ro(e){const t=Z(e,{nodes:0},0);for(const r of t)for(const o of Object.values(r.datasets))I.registerComputedDataset(o);return t}async function oo(e,t,r={}){return(await Mt(e,t,r)).plan}async function Mt(e,t,r={}){return nt(e,t,{...r,knownTotalPages:void 0})}const fe=new WeakMap;function no(e){return fe.get(e)}function X(e){if(e?.aborted){const t=new Error("报表重算已取消");throw t.name="AbortError",t}}function St(e,t){return e[t]===void 0?"":e[t]}function ao(e,t){if(t.edits.length>1e4)throw new M("limit");const r=B(e),o=new Set,n=[],a=t.edits.map(s=>{const i=r(s.address);if(!i?.source)throw new M("missing");const c=A(s);if(o.has(c))throw new M("duplicate");if(o.add(c),se(i,s)||!Object.is(i.value,s.previousValue)||(i.cell.text??"")!==s.previousText)throw new M("conflict");return n.push(i),_(i,s.value)});return{batch:{requestId:t.requestId,edits:a},contexts:n}}function so(e,t){const r=ht(e);return t.flatMap(o=>{if(!o.source)throw new M("missing");return r(o.source).map(n=>{if(!Object.is(St(n.row,o.source.field),o.previousValue))throw new M("conflict");if(n.binding.rowKey===o.source.field)throw new M("readonly");return{row:n,field:o.source.field,value:o.value}})})}function le(e,t,r){const o={...e,value:t,source:{...e.source,...r?.revision===void 0?{}:{revision:r.revision},...r?.sourceToken===void 0?{}:{sourceToken:r.sourceToken}}};return o.cell={...e.cell,value:o.value,text:V(o,o.value)},o}function io(e,t,r){if(!r||r.revision===void 0&&r.sourceToken===void 0)return[...e];const o=new Set(t.edits.flatMap(n=>n.source?[W(n.source)]:[]));return pt(e,zr(e,o,r))}function co(e,t,r){const o=new Set(t.edits.map(n=>W(n.source)));for(const n of o)e.set(n,{...e.get(n),...r.revision!==void 0?{revision:r.revision}:{},...r.sourceToken!==void 0?{sourceToken:r.sourceToken}:{}});return o}function Pe(e,t){let r=t.parts;const o=t.rebuild,n=[...t.validationFormulas??[]];let a=eo(r),s=e,i;const c=new Map,l=new Map;function u(g){if(g!==s)throw new M("conflict");if(i)return i;if(!a?.())throw new M("conflict");return ro(r)}async function f(g,m,v,p={}){X(p.signal),m={requestId:m.requestId,edits:m.edits.map(b=>({...b,address:{...b.address},source:b.source?{...b.source}:void 0,table:b.table?{...b.table}:void 0}))},v=v.map(b=>({...b,address:{...b.address},source:b.source?{...b.source}:void 0,table:b.table?{...b.table}:void 0,cell:{...b.cell}})),await new Promise(b=>setTimeout(b,0)),X(p.signal);const w=u(g),y=pt(w,so(w,m.edits)),C=Ee(await o(y,p.signal),l);X(p.signal);let P=!1,T=[],N="allow",L=!1;function h(b){return L=!0,T=Object.freeze(Ir(y,b,p.signal,n).map(x=>Object.freeze({...x}))),L=!1,N=b.warningPolicy??"allow",T}return p.validation&&h(p.validation),{plan:C,get validationIssues(){return T},validate:h,commit(b){if(X(p.signal),P||s!==g)throw new M("conflict");if(b?.conflicts?.length)throw new M("conflict");if(L)throw new Error("候选规则校验未完成,不能提交");lt(T,N);const x=io(y,m,b),$=wt(C,m,b);if(b){const k=co(l,m,b);for(const[F,H]of c)k.has(W(H.source))&&c.set(F,le(H,H.value,b))}return v.forEach((k,F)=>c.set(A(k),le(k,m.edits[F].value,b))),P=!0,i=x,r=void 0,a=void 0,s=$,fe.set(s,d),s}}}const d={get plan(){return s},async prepare(g,m,v){const p=ao(g,m);return f(g,p.batch,p.contexts,v)},async prepareHistory(g,m,v,p,w){if(!p.trim()||m.length>1e4)throw new M("limit");const y=u(g),C=ht(y),P=yt(g),T=new Set,L=m.map(x=>{if(!x.source)throw new M("missing");const $=A(x);if(T.has($))throw new M("duplicate");T.add($);const k=P.get($)??c.get($);if(!k?.source)throw new M("missing");const F=C(k.source)[0];return le(k,St(F.row,k.source.field))}).map((x,$)=>({context:x,edit:_(x,m[$][v])})).filter(({edit:x})=>!Object.is(x.previousValue,x.value)),h={requestId:p,edits:L.map(({edit:x})=>x)},b=L.map(({context:x})=>x);return{batch:h,contexts:b,prepared:await f(g,h,b,w)}}};return fe.set(e,d),d}function lo(e){const t=xe(e.template,e.datasets,e.pagination).plan;return Pe(t,{validationFormulas:[e.pagination?.formula],parts:[{template:e.template,datasets:e.datasets}],rebuild:(r,o)=>oo(r[0].template,r[0].datasets,{...e.pagination,signal:o})})}let uo=0;function xt(){return`report-${Date.now()}-${++uo}`}function me(e,t,r){if(!r?.aborted)try{const o=e?.({...t});o&&typeof o.then=="function"&&Promise.resolve(o).catch(()=>{})}catch{}}function Ct(e){const t=e.taskId??xt(),r=(o,n,a)=>{me(e.onEvent,{taskId:t,...e.correlationId===void 0?{}:{correlationId:e.correlationId},stage:o,status:n,...a===void 0?{}:{reportId:a}},e.signal)};return{taskId:t,progress(o,n,a){me(e.onEvent,{taskId:t,...e.correlationId===void 0?{}:{correlationId:e.correlationId},stage:o,status:"started",completed:n,total:a},e.signal)},async run(o,n,a){r(o,"started",a);try{const s=await n();return r(o,"completed",a),s}catch(s){throw r(o,"failed",a),s}},runSync(o,n,a){r(o,"started",a);try{const s=n();return r(o,"completed",a),s}catch(s){throw r(o,"failed",a),s}}}}function Te(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;const t=e,r=o=>typeof o=="string"&&o.trim().length>0&&o.length<=256;return!r(t.datasetId)||!r(t.field)||t.tableId!==void 0&&!r(t.tableId)||t.reportScope!==void 0&&(typeof t.reportScope!="string"||!t.reportScope.trim()||t.reportScope.length>4096)?!1:t.rowKey===void 0?!0:typeof t.rowKey=="string"?t.rowKey.trim().length>0&&t.rowKey.length<=1024:typeof t.rowKey=="number"&&Number.isFinite(t.rowKey)}function Et(e){return e==="missing-source"||e==="not-applicable"||e==="not-calculable"}function Rt(e){return e.target!==void 0&&!Te(e.target)?!1:e.valueState===void 0||Et(e.valueState)&&e.target!==void 0}function fo(e,t){if(we.validateDatasetRows([],e),!Te(t))throw new Error("数据说明目标无效");const r=e.fields.find(n=>n.field===t.field);if(!r)throw new Error("数据说明字段未在契约中声明");const o=[];return r.description&&o.push({code:"field-definition",severity:"info",message:r.description,target:{...t}}),r.calculation&&o.push({code:"field-calculation",severity:"info",message:r.calculation.description,target:{...t}}),o}function ke(e,t,r={}){const o=new Map;for(const a of e.pages)for(const s of a.components){if(s.kind!=="list"||s.tree?.input!=="nested")continue;const i=o.get(s.dataset);if(i&&(i.childrenField??"children")!==(s.tree.childrenField??"children"))throw new Error("同一数据集的嵌套树应使用相同 childrenField");o.set(s.dataset,s.tree)}if(!o.size)return t;const n={...t};for(const[a,s]of o){const i=Math.min(s.maxRows??1e5,r.maxRows??1/0);n[a]=G.flattenTreeInput(t[a]??[],{...s,maxRows:i},r.signal)}return n}function mo(e,t,r={}){return Object.values(ke(e,t,r)).reduce((o,n)=>o+n.length,0)}function go(e,t,r){const o=we.datasetJsonSchema(r),n=e?.pages.flatMap(i=>i.components).find(i=>i.kind==="list"&&i.dataset===t&&i.tree?.input==="nested");if(!n||n.kind!=="list"||!n.tree)return o;const a=o.items,s=n.tree.childrenField??"children";return{...o,items:{$ref:"#/$defs/treeNode"},$defs:{treeNode:{...a,properties:{...a.properties,[s]:{anyOf:[{type:"null"},{type:"array",items:{$ref:"#/$defs/treeNode"}}]}}}}}}function Ie(e,t){return JSON.stringify([e,t])}function $e(e,t,r){return r===void 0?Ie(e,t):JSON.stringify(["shared",r])}function Pt(e,t,r){return e.map(o=>{const n=o.table?{...o.table,id:r(o.table.id),...o.table.source?{source:{...o.table.source,sourceScope:t}}:{}}:void 0,a=o.grid?.cells.map(s=>s.map(i=>!i||!i.source&&!i.children?i:{...i,...i.source?{source:{...i.source,sourceScope:t}}:{},...i.children?{children:Pt(i.children,t,r)}:{}}));return n||a?{...o,...n?{table:n}:{},...a?{grid:{...o.grid,cells:a}}:{}}:o})}function ge(e){return S.validateChartComponentLimit(e.maxChartComponents),{maxPages:e.maxPages,maxCells:e.maxCells,maxChartComponents:e.maxChartComponents??S.DEFAULT_CHART_COMPONENT_LIMIT,usedPages:0,usedCells:0,usedChartComponents:0}}function ho(e,t){if(!e.repeat)return!1;const r=Object.prototype.hasOwnProperty.call(t,e.repeat.dataset)?t[e.repeat.dataset]:void 0;return Array.isArray(r)&&r.length===0}function po(e){const t=r=>r.grid?.cells.reduce((o,n)=>o+n.reduce((a,s)=>a+(s?1+(s.children?.reduce((i,c)=>i+t(c),0)??0):0),0),0)??0;return e.pages.reduce((r,o)=>r+o.components.reduce((n,a)=>n+t(a),0),0)}function he(e,t){return e===void 0?void 0:e-t}function de(e,t){return e===void 0?t:Math.max(1,Math.min(e,t??e))}function Tt(e,t,r,o,n){S.validateChartComponentLimit(e?.maxChartComponents);const a=he(t.maxPages,t.usedPages),s=t.maxChartComponents-t.usedChartComponents;if(a!==void 0&&a<1&&r.pages.length&&!ho(r,o))throw new S.PaginatePageLimitError(0,1);if(s<1&&r.pages.some(i=>i.components.some(c=>c.kind!=="list"&&c.chartBinding)))throw new S.PaginateChartComponentLimitError(s,1);return{...e,signal:n??e?.signal,maxPages:de(a,e?.maxPages),maxCells:de(he(t.maxCells,t.usedCells),e?.maxCells),maxChartComponents:de(s,e?.maxChartComponents)}}function kt(e,t){const r=po(t.plan),o=he(e.maxCells,e.usedCells);if(o!==void 0&&r>o)throw new S.PaginateCellLimitError(o,r);e.usedPages+=t.plan.pages.length,e.usedCells+=r,e.usedChartComponents+=t.chartComponents}function It(e,t){return e instanceof S.PaginatePageLimitError&&t.maxPages!==void 0&&(e.limit===t.maxPages-t.usedPages||e.limit===0)?new S.PaginatePageLimitError(t.maxPages,t.usedPages+e.actual):e instanceof S.PaginateCellLimitError&&t.maxCells!==void 0?new S.PaginateCellLimitError(t.maxCells,t.usedCells+e.actual):e instanceof S.PaginateChartComponentLimitError&&e.limit===t.maxChartComponents-t.usedChartComponents?new S.PaginateChartComponentLimitError(t.maxChartComponents,t.usedChartComponents+e.estimated):e}function wo(e){if(!("mapData"in e))return e;const{load:t,mapData:r,...o}=e;return{...o,load:async n=>{const a=await t(n);O(n.signal);try{return r(a,n)}catch(s){throw new E("validate",`报表 ${n.reportId} 数据映射失败`,s)}}}}class E extends Error{constructor(t,r,o){super(r),this.name="ReportSourceError",this.code=t,this.cause=o}}function ie(e){const t=new Error("报表加载已取消");return t.name="AbortError",Object.defineProperty(t,"cause",{value:e.reason}),t}function O(e){if(e?.aborted)throw ie(e)}function pe(e,t){return t?new Promise((r,o)=>{const n=()=>t.removeEventListener("abort",a),a=()=>{n(),o(ie(t))};t.addEventListener("abort",a,{once:!0}),t.aborted&&a(),Promise.resolve(e).then(s=>{n(),r(s)},s=>{n(),o(s)})}):Promise.resolve(e)}function yo(e,t){if(!e||typeof e!="object"||Array.isArray(e))throw new E("validate",`报表 ${t} 的数据集应为对象`);for(const[r,o]of Object.entries(e))if(!Array.isArray(o)||o.some(n=>!n||typeof n!="object"||Array.isArray(n)))throw new E("validate",`报表 ${t} 的数据集 ${r} 应为对象数组`)}async function bo(e,t,r){const{reportId:o,signal:n}=t;try{const a=await pe(e(t),n);O(n);const s=j.validateReportTemplate(a);if(!s.ok)throw new E("validate",`报表 ${o} 模板校验失败:${s.errors.slice(0,3).map(i=>`${i.path}: ${i.message}`).join("; ")}`);return r.push(...s.warnings.map(i=>`${o}: ${i.path}: ${i.message}`)),a}catch(a){throw n?.aborted?ie(n):a instanceof E?a:a instanceof j.ReportTemplateError?new E("validate",`报表 ${o} 模板校验失败:${a.message}`,a):new E("fetch",`报表 ${o} 模板加载失败:${a instanceof Error?a.message:String(a)}`,a)}}async function vo(e,t,r,o){const n=t.signal;let a;try{if(e.load)a=await pe(e.load(t),n);else if(e.provider){const s=await pe(e.provider.query(t),n);O(n),Mo(s,r),a=s.datasets,o?.(r,s)}else a=e.datasets??{}}catch(s){throw n?.aborted?ie(n):s instanceof E?s:new E("fetch",`报表 ${r} 取数失败:${s instanceof Error?s.message:String(s)}`,s)}return O(n),a}function Mo(e,t){if(!e||typeof e!="object"||Array.isArray(e))throw new E("validate",`报表 ${t} Provider 应返回 datasets 结果对象`);for(const r of["revision","sourceToken"])if(e[r]!==void 0&&typeof e[r]!="string")throw new E("validate",`报表 ${t} Provider ${r} 应为字符串`);if(e.diagnostics!==void 0&&(!Array.isArray(e.diagnostics)||e.diagnostics.some(r=>!r||typeof r.code!="string"||typeof r.message!="string"||!["info","warning","error"].includes(r.severity))))throw new E("validate",`报表 ${t} Provider diagnostics 不符合结构化诊断契约`);if(e.diagnostics?.some(r=>!Rt(r)))throw new E("validate",`报表 ${t} Provider 数据说明缺少有效的字段身份或值状态`)}function So(e,t,r,o,n){try{t=ke(o,t,{maxRows:e.dataValidation?.maxRows,signal:n})}catch(a){throw new E("validate",`报表 ${r} 树形数据无效:${a instanceof Error?a.message:String(a)}`,a)}for(const[a,s]of Object.entries(e.dataSchema??{})){let i;try{i=we.validateDatasetRows(Object.prototype.hasOwnProperty.call(t,a)?t[a]:void 0,s,{...e.dataValidation,path:`$.datasets.${a}`})}catch(c){throw new E("config",`报表 ${r} 数据集 ${a} 字段契约配置无效`,c)}if(!i.ok)throw new E("validate",`报表 ${r} 数据集 ${a} 不符合字段契约:${i.issues[0]?.message}`,{issues:i.issues})}}async function xo(e,t,r,o,n){try{let a;try{a=to(e)}catch{}const s=a??e,i=Tt(t.pagination,o,s.template,s.datasets,n),c=a?await nt(s.template,s.datasets,i):xe(s.template,s.datasets,i);return kt(o,c),{result:c,part:s}}catch(a){O(n);const s=It(a,o);throw new E("validate",`报表 ${r} 排版失败:${s instanceof Error?s.message:String(s)}`,s)}}function $t(e,t,r,o,n){const a=new Map,s=i=>{let c=a.get(i);return c===void 0&&(c=JSON.stringify([r,o,i]),a.set(i,c)),c};for(const i of t.pages)e.push({...i,meta:{...i.meta,reportScope:Ie(r,o)},components:Pt(i.components,n??$e(r,o),s)})}async function Co(e,t,r,o,n){const a=[],s=ge(o);for(const[l,u]of e.entries()){O(n);try{const f=await Mt(u.template,u.datasets,Tt(t[l]?.pagination,s,u.template,u.datasets,n));kt(s,f),$t(a,f.plan,l,r[l],u.sourceScope)}catch(f){throw It(f,s)}}const i={schemaVersion:R.RENDER_PLAN_SCHEMA_VERSION,...e.some(l=>ye(l.template))?{requiresRecalculation:!0}:{},pages:a},c=j.validateRenderPlan(i);if(!c.ok)throw new E("validate",`重算渲染计划校验失败:${c.errors[0]?.message}`);return i}function Eo(e,t={}){if(t.maxPages!==void 0&&(!Number.isSafeInteger(t.maxPages)||t.maxPages<1))throw new E("config","maxPages 应为正安全整数");if(t.maxCells!==void 0&&(!Number.isSafeInteger(t.maxCells)||t.maxCells<1))throw new E("config","maxCells 应为正安全整数");try{ge(t)}catch(n){throw new E("config","maxChartComponents 应为 1..1000000 的安全整数",n)}function r(n){const a=Object.prototype.hasOwnProperty.call(e,n)?e[n]:void 0;if(!a)throw new E("config",`未注册报表 ${n}`);if(a.sourceScope!==void 0&&(typeof a.sourceScope!="string"||!a.sourceScope.trim()||a.sourceScope.length>512))throw new E("config","sourceScope 应为不超过 512 字符的非空字符串");return a}return Object.assign(async({reportIds:n,params:a,signal:s,onWarning:i,onQueryResult:c,...l})=>{O(s);const u=Ct({...l,signal:s}),f=[...n],d={...a};if(f.length===0)throw new E("config","缺少报表 ID");const g=f.map(r),m=u.runSync("validate",()=>g.map(h=>Oe.assertReportParams(h.params??(typeof h.template=="function"?[]:h.template.params)??[],d))),v=[],p=[],w=ge(t),y=[];for(const[h,b]of g.entries()){O(s);const x=f[h],$={reportId:x,params:m[h],signal:s},k=typeof b.template=="function"?await u.run("query",()=>bo(b.template,$,y),x):b.template;$.params=u.runSync("validate",()=>Oe.assertReportParams(b.params??k.params??[],$.params),x);const F=await u.run("query",()=>vo(b,$,x,(ce,Ot)=>c?.(ce,Ot,h)),x);u.runSync("validate",()=>{yo(F,x),t.onDatasets?.(x,F,k),So(b,F,x,k,s)},x),O(s);const H=$e(h,x,b.sourceScope),{result:Fe,part:Ft}=await u.run("layout",()=>xo({template:k,datasets:F,sourceScope:H},b,x,w,s),x);p.push(Ft),$t(v,Fe.plan,h,x,H),y.push(...Fe.warnings.map(ce=>`${x}: ${ce}`))}O(s);const C={schemaVersion:R.RENDER_PLAN_SCHEMA_VERSION,...p.some(h=>ye(h.template))?{requiresRecalculation:!0}:{},pages:v},P=u.runSync("validate",()=>{const h=j.validateRenderPlan(C);if(!h.ok)throw new E("validate",`渲染计划校验失败:${h.errors.slice(0,3).map(b=>`${b.path}: ${b.message}`).join("; ")}`);return h});y.push(...P.warnings.map(h=>`${h.path}: ${h.message}`));const T=g.map(h=>({...h,pagination:{...h.pagination}})),N={maxPages:t.maxPages,maxCells:t.maxCells,maxChartComponents:t.maxChartComponents};try{Pe(C,{parts:p,validationFormulas:T.map(h=>h.pagination?.formula),rebuild:(h,b)=>Co(h,T,f,N,b)})}catch{y.push("来源数据无法建立本地重算口径;当前预览仅支持计划内编辑,请使用可序列化模板数据启用规则重算")}const L=i??t.onWarning??(h=>console.warn("[mach-report]",h));for(const h of y)O(s),L(h);return O(s),C},{getParamDefs:n=>At.getReportParamDefs(e,n)})}const Ro=new Set([8,9,10,12,13]);function Po(e,t){const r=Array.isArray(e),o=Object.getPrototypeOf(e);if(o!==(r?Array.prototype:Object.prototype)&&!(o===null&&!r)||Object.getOwnPropertySymbols(e).length)throw t("input","快照应为普通 JSON 对象");const n=Object.getOwnPropertyNames(e).filter(a=>!(r&&a==="length"));if(r&&(n.length!==e.length||n.some((a,s)=>a!==String(s))))throw t("input","快照数组应为连续数组");return{array:r,keys:n}}function To(e){if(/^[\u0020-\u007e]*$/.test(e)&&!/["\\]/.test(e))return e.length+2;let t=2;for(let r=0;r<e.length;r++){const o=e.charCodeAt(r);if(o<32)t+=Ro.has(o)?2:6;else if(o===34||o===92)t+=2;else if(o<128)t++;else if(o<2048)t+=2;else if(o>=55296&&o<=57343){const n=e.charCodeAt(r+1);o<=56319&&n>=56320&&n<=57343?(t+=4,r++):t+=6}else t+=3}return t}function ko(e,t){const r=t.maxNodes??1e6;if(![t.maxBytes,r].every(d=>Number.isSafeInteger(d)&&d>0))throw t.error("budget","快照预算应为正安全整数");let o=0,n=0;const a=new Set,s=new Map;function i(d){if(d.length+2>t.maxBytes-n)throw t.error("budget","快照超过字节预算");const g=s.get(d);if(g!==void 0)return g;const m=To(d);return d.length<=256&&s.size<4096&&s.set(d,m),m}function c(d){if(n+=d,n>t.maxBytes)throw t.error("budget","快照超过字节预算")}function l(d,g){if(++o>r||g>64)throw t.error("budget","快照节点或深度超过预算");if(o%1024===0&&t.check?.(),typeof d=="string")return c(i(d)),d;if(d===null||typeof d=="boolean"||typeof d=="number"&&Number.isFinite(d))return c(String(d).length),typeof d=="number"&&Object.is(d,-0)?0:d;if(!d||typeof d!="object"||a.has(d))throw t.error("input","快照应为无循环的有限 JSON 值");return u(d,g)}function u(d,g){const{array:m,keys:v}=Po(d,t.error);a.add(d),c(2);const p=m?[]:{};let w=0;for(const y of v){const C=Object.getOwnPropertyDescriptor(d,y);if(C.get||C.set||!C.enumerable||["__proto__","constructor","prototype"].includes(y))throw t.error("input","快照不允许访问器或危险键");if(C.value===void 0&&!m)continue;c((w++?1:0)+(m?0:i(y)+1));const P=l(C.value===void 0?null:C.value,g+1);y in p?Object.defineProperty(p,y,{value:P,enumerable:!0,configurable:!0,writable:!0}):p[y]=P}return a.delete(d),p}t.check?.();const f=l(e,0);return t.check?.(),f}exports.DEFAULT_LABEL_PAGE_LIMIT=We;exports.ReportCellEditError=M;exports.ReportSourceError=E;exports.ReportValidationError=st;exports.applyReportCellEdit=Wr;exports.applyReportCellEditBatch=Xr;exports.applyReportEditResult=wt;exports.applyReportSourceMetadata=Ee;exports.assertReportValidation=lt;exports.countTemplatePages=br;exports.createReportCellEdit=Br;exports.createReportCellEditBatch=Ur;exports.createReportCellResolver=B;exports.createReportEditSession=lo;exports.createReportSource=Eo;exports.createReportTaskReporter=Ct;exports.defineReport=wo;exports.editFromContext=_;exports.estimateListLayoutCells=Cr;exports.explainDatasetField=fo;exports.formatReportCellEdit=V;exports.getReportCellContext=ae;exports.getReportEditSession=no;exports.hasValidDataExplanation=Rt;exports.isReportDataTarget=Te;exports.isReportValueState=Et;exports.notifyReportTaskEvent=me;exports.paginateTemplate=xe;exports.paginateTemplatePages=vr;exports.parseReportCellInput=Ce;exports.projectListColumns=_e;exports.registerReportEditSession=Pe;exports.relocateReportCellEdits=Qr;exports.reportCellEditKey=A;exports.reportOccurrenceScope=Ie;exports.reportSourceScope=$e;exports.reportTaskId=xt;exports.snapshotReportJson=ko;exports.sourceChanged=se;exports.summarizeReportCellEdits=Yr;exports.templateDatasetJsonSchema=go;exports.templateDatasetRowCount=mo;exports.templateValidationDatasets=ke;exports.validateReportDataset=kr;
@@ -1,6 +1,6 @@
1
- import "./font-loader-BT5baV-o.js";
1
+ import "./font-loader-CNWXomuV.js";
2
2
  import { g as Z1 } from "./_commonjsHelpers-DaMA6jEr.js";
3
- import { h as Rd, w as Y1 } from "./textwrap-BIjtEWmq.js";
3
+ import { h as Rd, w as Y1 } from "./textwrap-D4ZksyMK.js";
4
4
  import { d as J1 } from "./data-bar-IkI6VvMQ.js";
5
5
  import { o as Q1, t as _1, i as $1, r as eg, f as tg, a as pi, b as ss, d as Md, m as rg, e as ng } from "./progress-ByiOxUD3.js";
6
6
  import { r as ig, n as ag, O as og } from "./capabilities-pg7j7VLT.js";