@agile-team/mach-report 2.14.0 → 2.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (256) hide show
  1. package/README.md +16 -11
  2. package/THIRD_PARTY_NOTICES.md +3 -1
  3. package/dist/{ExcelBindingWizard-CvsWR8Ga.js → ExcelBindingWizard-BKH1nGNS.js} +3 -3
  4. package/dist/{ExcelBindingWizard-CLT2p7P3.cjs → ExcelBindingWizard-Bs43BGNp.cjs} +1 -1
  5. package/dist/ParamEditor-Da4akw6V.cjs +1 -0
  6. package/dist/ParamEditor-DoAhzJsm.js +594 -0
  7. package/dist/{ReportBatchPanel-LqVgiqp7.js → ReportBatchPanel-BMf6boMA.js} +39 -39
  8. package/dist/{ReportBatchPanel-DkxTzBkD.cjs → ReportBatchPanel-wP9m9Pj1.cjs} +1 -1
  9. package/dist/ReportPreview-ChV19HBp.js +4619 -0
  10. package/dist/ReportPreview-DbLvvOUT.cjs +6 -0
  11. package/dist/{ReportTemplateLibrary-MjWEtc7X.js → ReportTemplateLibrary-C9wutIiT.js} +1 -1
  12. package/dist/{ReportTemplateLibrary-cQ1sqNYo.cjs → ReportTemplateLibrary-Sxr3eD0J.cjs} +1 -1
  13. package/dist/{RuleEditor-ChuXMlei.js → RuleEditor-C_Clasvd.js} +5 -5
  14. package/dist/{RuleEditor-BaR6xUiI.cjs → RuleEditor-XhGHK8DE.cjs} +1 -1
  15. package/dist/{TemplateOutlinePanel-Dci6aRn1.js → TemplateOutlinePanel-D6Bkny59.js} +2 -2
  16. package/dist/{TemplateOutlinePanel-BHKP89Xz.cjs → TemplateOutlinePanel-JTSR53vJ.cjs} +1 -1
  17. package/dist/{TemplateReusePanel-CY5eO2Sh.cjs → TemplateReusePanel-Kx35S0Ql.cjs} +1 -1
  18. package/dist/{TemplateReusePanel-B7Gmyc1z.js → TemplateReusePanel-rVuK1kTz.js} +2 -2
  19. package/dist/{TemplateReviewPanel-DjlX3xpt.js → TemplateReviewPanel-B0ar9_zf.js} +2 -2
  20. package/dist/{TemplateReviewPanel-JvZe9_4G.cjs → TemplateReviewPanel-Dn6X9UmY.cjs} +1 -1
  21. package/dist/analytics.cjs +1 -1
  22. package/dist/analytics.d.cts +3 -1
  23. package/dist/analytics.d.ts +3 -1
  24. package/dist/analytics.js +154 -60
  25. package/dist/artifact-integrity.json +135 -0
  26. package/dist/assets-B9ImAi6_.cjs +1 -0
  27. package/dist/assets-DEaz4qsp.js +124 -0
  28. package/dist/batch-BaP6pWDE.cjs +1 -0
  29. package/dist/batch-BfZHN1do.js +220 -0
  30. package/dist/batch-CGyt-b2W.js +273 -0
  31. package/dist/batch-CLpELXBl.cjs +1 -0
  32. package/dist/capabilities-CAh2Nrue.cjs +1 -0
  33. package/dist/capabilities-DskCHs3V.js +69 -0
  34. package/dist/codes.d.cts +2 -0
  35. package/dist/codes.d.ts +2 -0
  36. package/dist/{computed-Bvk0W15F.js → computed-C-4C2S5h.js} +3 -3
  37. package/dist/config-BVsJXSqS.js +842 -0
  38. package/dist/config-D10us76d.cjs +1 -0
  39. package/dist/data-explanation-B8MZRYVS.js +16 -0
  40. package/dist/data-explanation-DE55G30w.cjs +1 -0
  41. package/dist/designer-2bDlcNXQ.js +5136 -0
  42. package/dist/designer-BT7XCdbW.cjs +2 -0
  43. package/dist/designer.cjs +1 -1
  44. package/dist/designer.d.cts +144 -16
  45. package/dist/designer.d.ts +144 -16
  46. package/dist/designer.js +1 -1
  47. package/dist/drill-ByJviLXS.js +145 -0
  48. package/dist/drill-DYTxuL3A.cjs +1 -0
  49. package/dist/{font-loader-vhCT8znW.cjs → font-loader-B_UkxpzC.cjs} +1 -1
  50. package/dist/{font-loader-DHto6Lra.js → font-loader-Q3bQjmrI.js} +1 -1
  51. package/dist/index.cjs +8 -8
  52. package/dist/index.d.cts +82 -4
  53. package/dist/index.d.ts +82 -4
  54. package/dist/index.js +785 -820
  55. package/dist/json-snapshot-DFb2eWkf.js +1416 -0
  56. package/dist/json-snapshot-WWSGlaHG.cjs +2 -0
  57. package/dist/licenses/_bwip-js_generic-4.11.4.txt +24 -0
  58. package/dist/licenses/_fast-csv_format-4.3.5.txt +22 -0
  59. package/dist/licenses/_fast-csv_parse-4.3.6.txt +22 -0
  60. package/dist/licenses/_pdf-lib_fontkit-1.1.1.txt +326 -0
  61. package/dist/licenses/_pdf-lib_standard-fonts-1.0.0.txt +22 -0
  62. package/dist/licenses/_pdf-lib_upng-1.0.1.txt +22 -0
  63. package/dist/licenses/_types_node-14.18.63.txt +22 -0
  64. package/dist/licenses/_types_pako-2.0.3.txt +22 -0
  65. package/dist/licenses/_types_pegjs-0.10.6.txt +22 -0
  66. package/dist/licenses/archiver-5.3.2.txt +23 -0
  67. package/dist/licenses/archiver-utils-2.1.0.txt +23 -0
  68. package/dist/licenses/archiver-utils-3.0.4.txt +23 -0
  69. package/dist/licenses/async-3.2.6.txt +20 -0
  70. package/dist/licenses/balanced-match-1.0.2.txt +22 -0
  71. package/dist/licenses/base64-js-1.5.1.txt +22 -0
  72. package/dist/licenses/big-integer-1.6.52.txt +25 -0
  73. package/dist/licenses/binary-0.3.0.txt +178 -0
  74. package/dist/licenses/bl-4.1.0.txt +14 -0
  75. package/dist/licenses/bluebird-3.4.7.txt +22 -0
  76. package/dist/licenses/brace-expansion-1.1.21.txt +22 -0
  77. package/dist/licenses/brace-expansion-2.1.7.txt +22 -0
  78. package/dist/licenses/buffer-5.7.1.txt +22 -0
  79. package/dist/licenses/buffer-crc32-0.2.13.txt +20 -0
  80. package/dist/licenses/buffer-indexof-polyfill-1.0.2.txt +23 -0
  81. package/dist/licenses/buffers-0.1.1.txt +140 -0
  82. package/dist/licenses/chainsaw-0.1.0.txt +184 -0
  83. package/dist/licenses/compress-commons-4.1.2.txt +23 -0
  84. package/dist/licenses/concat-map-0.0.1.txt +19 -0
  85. package/dist/licenses/core-util-is-1.0.3.txt +20 -0
  86. package/dist/licenses/crc-32-1.2.2.txt +202 -0
  87. package/dist/licenses/crc32-stream-4.0.3.txt +23 -0
  88. package/dist/licenses/dayjs-1.11.23.txt +22 -0
  89. package/dist/licenses/duplexer2-0.1.4.txt +27 -0
  90. package/dist/licenses/end-of-stream-1.4.5.txt +22 -0
  91. package/dist/licenses/exceljs-4.4.0.txt +23 -0
  92. package/dist/licenses/fast-csv-4.3.6.txt +22 -0
  93. package/dist/licenses/fast-png-6.4.0.txt +22 -0
  94. package/dist/licenses/fs-constants-1.0.0.txt +22 -0
  95. package/dist/licenses/fs.realpath-1.0.0.txt +44 -0
  96. package/dist/licenses/fstream-1.0.12.txt +16 -0
  97. package/dist/licenses/glob-7.2.3.txt +22 -0
  98. package/dist/licenses/graceful-fs-4.2.11.txt +16 -0
  99. package/dist/licenses/ieee754-1.2.1.txt +12 -0
  100. package/dist/licenses/immediate-3.0.6.txt +21 -0
  101. package/dist/licenses/inflight-1.0.6.txt +16 -0
  102. package/dist/licenses/inherits-2.0.4.txt +17 -0
  103. package/dist/licenses/iobuffer-5.4.0.txt +23 -0
  104. package/dist/licenses/isarray-1.0.0.txt +61 -0
  105. package/dist/licenses/jszip-3.10.2.txt +652 -0
  106. package/dist/licenses/lazystream-1.0.1.txt +24 -0
  107. package/dist/licenses/lie-3.3.0.txt +8 -0
  108. package/dist/licenses/listenercount-1.0.1.txt +6 -0
  109. package/dist/licenses/lodash.defaults-4.2.0.txt +48 -0
  110. package/dist/licenses/lodash.difference-4.5.0.txt +48 -0
  111. package/dist/licenses/lodash.escaperegexp-4.1.2.txt +48 -0
  112. package/dist/licenses/lodash.flatten-4.4.0.txt +48 -0
  113. package/dist/licenses/lodash.groupby-4.6.0.txt +48 -0
  114. package/dist/licenses/lodash.isboolean-3.0.3.txt +23 -0
  115. package/dist/licenses/lodash.isequal-4.5.0.txt +48 -0
  116. package/dist/licenses/lodash.isfunction-3.0.9.txt +48 -0
  117. package/dist/licenses/lodash.isnil-4.0.0.txt +23 -0
  118. package/dist/licenses/lodash.isplainobject-4.0.6.txt +48 -0
  119. package/dist/licenses/lodash.isundefined-3.0.1.txt +23 -0
  120. package/dist/licenses/lodash.union-4.6.0.txt +48 -0
  121. package/dist/licenses/lodash.uniq-4.5.0.txt +48 -0
  122. package/dist/licenses/minimatch-3.1.5.txt +16 -0
  123. package/dist/licenses/minimatch-5.1.9.txt +16 -0
  124. package/dist/licenses/minimist-1.2.8.txt +19 -0
  125. package/dist/licenses/mkdirp-0.5.6.txt +22 -0
  126. package/dist/licenses/node-sql-parser-5.4.0.txt +202 -0
  127. package/dist/licenses/normalize-path-3.0.0.txt +22 -0
  128. package/dist/licenses/once-1.4.0.txt +16 -0
  129. package/dist/licenses/pako-1.0.11.txt +22 -0
  130. package/dist/licenses/pako-2.2.0.txt +22 -0
  131. package/dist/licenses/path-is-absolute-1.0.1.txt +22 -0
  132. package/dist/licenses/pdf-lib-1.17.1.txt +22 -0
  133. package/dist/licenses/process-nextick-args-2.0.1.txt +20 -0
  134. package/dist/licenses/readable-stream-2.3.8.txt +48 -0
  135. package/dist/licenses/readable-stream-3.6.2.txt +48 -0
  136. package/dist/licenses/readdir-glob-1.1.3.txt +202 -0
  137. package/dist/licenses/rimraf-2.7.1.txt +16 -0
  138. package/dist/licenses/safe-buffer-5.1.2.txt +22 -0
  139. package/dist/licenses/safe-buffer-5.2.1.txt +22 -0
  140. package/dist/licenses/saxes-5.0.1.txt +397 -0
  141. package/dist/licenses/setimmediate-1.0.5.txt +21 -0
  142. package/dist/licenses/string_decoder-1.1.1.txt +49 -0
  143. package/dist/licenses/string_decoder-1.3.0.txt +49 -0
  144. package/dist/licenses/tar-stream-2.2.0.txt +22 -0
  145. package/dist/licenses/tmp-0.2.7.txt +22 -0
  146. package/dist/licenses/traverse-0.3.9.txt +25 -0
  147. package/dist/licenses/tslib-1.14.1.txt +13 -0
  148. package/dist/licenses/unzipper-0.10.14.txt +26 -0
  149. package/dist/licenses/util-deprecate-1.0.2.txt +25 -0
  150. package/dist/licenses/uuid-11.1.1.txt +10 -0
  151. package/dist/licenses/wrappy-1.0.2.txt +16 -0
  152. package/dist/licenses/xmlchars-2.2.0.txt +19 -0
  153. package/dist/licenses/zip-stream-4.1.1.txt +23 -0
  154. package/dist/matrix-CGRGkn5s.js +112 -0
  155. package/dist/matrix-gEO7ZM_u.cjs +1 -0
  156. package/dist/media-B7vnpD8k.cjs +1 -0
  157. package/dist/media-Y90dHK9z.js +70 -0
  158. package/dist/param-validation-C3HlcLLO.cjs +1 -0
  159. package/dist/param-validation-Do7Eg8Zv.js +181 -0
  160. package/dist/{pdf-8UPQebOE.js → pdf-BwNyeGpt.js} +4385 -4321
  161. package/dist/{pdf-AyJGb22z.cjs → pdf-CvvrjPQg.cjs} +51 -49
  162. package/dist/pdf.cjs +1 -1
  163. package/dist/pdf.d.cts +18 -3
  164. package/dist/pdf.d.ts +18 -3
  165. package/dist/pdf.js +2 -2
  166. package/dist/{plugin-BGKf-Tqg.js → plugin-Ca_XZG3l.js} +2 -2
  167. package/dist/{plugin-CktLH_Iy.cjs → plugin-DHO7X8z2.cjs} +1 -1
  168. package/dist/prepared-CFy9B75C.cjs +1 -0
  169. package/dist/prepared-ajM-H-9B.js +69 -0
  170. package/dist/progress-B0ctFpKf.cjs +1 -0
  171. package/dist/progress-D-OTpEav.js +52 -0
  172. package/dist/record-bindings-By_UKZ2g.cjs +1 -0
  173. package/dist/record-bindings-Do_b3h4V.js +196 -0
  174. package/dist/{region-binding-workflow-DEJbhpCv.js → region-binding-workflow-BMhK_TjP.js} +1 -1
  175. package/dist/{region-binding-workflow-BzfbxRiR.cjs → region-binding-workflow-DIYJdCUr.cjs} +1 -1
  176. package/dist/{report-params-B44imUd4.js → report-params-B1RzkhJj.js} +1 -1
  177. package/dist/{report-params-SJfhKgaX.cjs → report-params-WDGrA4oP.cjs} +1 -1
  178. package/dist/sbom.cdx.json +3982 -0
  179. package/dist/server/node.d.cts +20 -1
  180. package/dist/server/node.d.ts +20 -1
  181. package/dist/server-node.cjs +1 -1
  182. package/dist/server-node.js +247 -237
  183. package/dist/server.cjs +1 -1
  184. package/dist/server.d.cts +772 -4
  185. package/dist/server.d.ts +772 -4
  186. package/dist/server.js +885 -645
  187. package/dist/sha256-ArEYjaTI.cjs +1 -0
  188. package/dist/sha256-DPEuJ3nh.js +155 -0
  189. package/dist/style.css +1 -1
  190. package/dist/template-bindings-C2SpvsMU.js +58 -0
  191. package/dist/template-bindings-CEtWyiLX.cjs +1 -0
  192. package/dist/template-catalog-FJE_c9Qe.cjs +1 -0
  193. package/dist/template-catalog-j2B1MJlL.js +414 -0
  194. package/dist/{template-fragments-CLkGo6To.js → template-fragments-BGbQLGlV.js} +21 -21
  195. package/dist/{template-fragments-DFUpq5QM.cjs → template-fragments-DcKeiylI.cjs} +1 -1
  196. package/dist/{template-outline-B3xVkzSv.cjs → template-outline-BwRV_eRo.cjs} +1 -1
  197. package/dist/{template-outline-CFenM1PV.js → template-outline-cnWfT_LK.js} +3 -3
  198. package/dist/{template-registry-COXDEJEM.js → template-registry-BtaKPELV.js} +364 -201
  199. package/dist/template-registry-Co1zPq5e.cjs +1 -0
  200. package/dist/textwrap-CWHyzkBH.cjs +4 -0
  201. package/dist/textwrap-DE1kgcJB.js +110 -0
  202. package/dist/{tree-CqcQ99NM.js → tree-CjVZLRw7.js} +1 -1
  203. package/dist/vue/async.d.cts +123 -14
  204. package/dist/vue/async.d.ts +123 -14
  205. package/dist/vue/index.d.cts +158 -22
  206. package/dist/vue/index.d.ts +158 -22
  207. package/dist/vue-async.cjs +1 -1
  208. package/dist/vue-async.js +3 -3
  209. package/dist/vue.cjs +1 -1
  210. package/dist/vue.js +80 -78
  211. package/dist/{workbook-session-DNa2RHNG.cjs → workbook-session-Bjv1YCRK.cjs} +18 -18
  212. package/dist/{workbook-session-BfK1yHOO.js → workbook-session-BvToI-Fd.js} +5440 -5288
  213. package/dist/worker.cjs +1 -1
  214. package/dist/worker.d.cts +20 -1
  215. package/dist/worker.d.ts +20 -1
  216. package/dist/worker.js +33 -32
  217. package/dist/xlsx-node.cjs +34 -34
  218. package/dist/xlsx-node.js +878 -870
  219. package/dist/xlsx.cjs +3 -4
  220. package/dist/xlsx.d.cts +22 -10
  221. package/dist/xlsx.d.ts +22 -10
  222. package/dist/xlsx.js +261 -253
  223. package/package.json +2 -2
  224. package/dist/ParamEditor-CflQV3eQ.js +0 -526
  225. package/dist/ParamEditor-vIDzvpPV.cjs +0 -1
  226. package/dist/ReportPreview-CvbqLUzM.cjs +0 -6
  227. package/dist/ReportPreview-D_ywJ_-H.js +0 -4533
  228. package/dist/assets-C2U-e-Sz.cjs +0 -4
  229. package/dist/assets-Q0wUwNrV.js +0 -217
  230. package/dist/batch-DzaTNLWI.js +0 -371
  231. package/dist/batch-xMkqYiTr.cjs +0 -1
  232. package/dist/capabilities-CK_7hizc.js +0 -63
  233. package/dist/capabilities-CsZ-pNHR.cjs +0 -1
  234. package/dist/config-0UIohTS7.cjs +0 -1
  235. package/dist/config-Dt9NtCPl.js +0 -566
  236. package/dist/data-explanation-BktvER5B.cjs +0 -1
  237. package/dist/data-explanation-C_J6jYNi.js +0 -16
  238. package/dist/designer-Ci1LizA9.js +0 -5020
  239. package/dist/designer-rtmVIIdN.cjs +0 -2
  240. package/dist/json-snapshot-BeFT3Tso.js +0 -1952
  241. package/dist/json-snapshot-D1NTP2oI.cjs +0 -2
  242. package/dist/matrix-DVyWiYsd.cjs +0 -1
  243. package/dist/matrix-yZsGnldA.js +0 -227
  244. package/dist/page-window-index-CIuT4BAv.js +0 -43
  245. package/dist/page-window-index-DEjnM6IB.cjs +0 -1
  246. package/dist/param-validation-BlHHXs6u.js +0 -153
  247. package/dist/param-validation-DCK039V1.cjs +0 -1
  248. package/dist/progress-7OSZbFok.js +0 -39
  249. package/dist/progress-BnLiS5eH.cjs +0 -1
  250. package/dist/task-events-DQ276fn2.cjs +0 -1
  251. package/dist/task-events-Dpsvf_t2.js +0 -47
  252. package/dist/template-bindings-BJR4k7qZ.cjs +0 -1
  253. package/dist/template-bindings-Daui7hLF.js +0 -252
  254. package/dist/template-registry-D3SjENi6.cjs +0 -1
  255. package/dist/validate-BJ5HIWY8.cjs +0 -1
  256. package/dist/validate-CkQBWCeg.js +0 -163
@@ -0,0 +1,2 @@
1
+ "use strict";const z=require("./render-plan-7xpGrCEl.cjs"),K=require("./defaults-xhmcLLrf.cjs"),j=require("./textwrap-CWHyzkBH.cjs"),E=require("./record-bindings-By_UKZ2g.cjs"),de=require("./computed-CGV2a809.cjs"),Ce=require("./matrix-gEO7ZM_u.cjs"),U=require("./tree-BX380Rr7.cjs"),N=require("./template-registry-Co1zPq5e.cjs"),$=require("./style-UgIJSA1F.cjs"),lt=require("./report-params-WDGrA4oP.cjs"),Se=require("./param-validation-C3HlcLLO.cjs"),M=require("./batch-BaP6pWDE.cjs"),dt=require("./data-explanation-DE55G30w.cjs"),ke=require("./dataset-BkRmwgeJ.cjs");function ut(e,t,r){const o=new Set,a=e.cells.map((n,s)=>{const i=[];let c=0;for(const l of n){for(;o.has(`${s}:${c}`);)c++;const d=l?.colSpan??1,f=l?.rowSpan??1;let u=0;for(let g=c;g<c+d;g++){t.has(g)&&u++;for(let h=s+1;h<s+f;h++)o.add(`${h}:${g}`)}u&&i.push(l?{...l,colSpan:u}:null),c+=d}return i});return{...e,cells:a,colWidthsMm:r}}function $e(e){if(!e.columns.some(o=>o.hidden))return e;const t=new Set,r=e.columns.filter((o,a)=>o.hidden?!1:(t.add(a),!0));if(!r.length)throw new Error("列表至少需要一列可见列");return{...e,columns:r,...e.headerGrid?{headerGrid:ut(e.headerGrid,t,r.map(o=>o.widthMm))}:{}}}function*ft(e){const{page:t}=e;N.validateReportPageFlow(t.components,t.flow);let r=0,o=0;for(const a of N.reportFlowGroups(t.components,t.flow)){e.active();const n=a.band,s=a.components.some(d=>d.kind==="list"&&d.cardinality!=="record"),i=s?0:a.components.reduce((d,f)=>Math.max(d,f.topMm-n.topMm+(f.kind==="list"?e.height(f):f.heightMm)),n.heightMm);let c=Math.max(e.top(),o+n.topMm-r);if(!s&&i>e.bottom()-e.top()+.001)throw new Error(`静态区域 ${n.componentIds.join(",")} 高度超出单页可用范围`);!s&&c+i>e.bottom()+.001&&(e.nextPage(),yield*e.takePages(),e.active(),c=e.top());let l=c+i;for(const d of a.components){const f=c+d.topMm-n.topMm;d.kind==="list"?(yield*e.list(d,f,u=>{l=s?u:Math.max(l,u)}),e.active()):e.append({...d,topMm:f})}o=l,r=n.topMm+n.heightMm}}function mt(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))}function X(e){return e.pages.some(t=>t.components.some(r=>r.kind==="list"&&mt(r)))}const gt=512,Re=256*1024;function ht(){const e=new Map;let t=0,r;return(o,a,n,s)=>{s!==r&&(e.clear(),t=0,r=s);const i=JSON.stringify([o,a,n.fontSizePt,n.fontFamily,n.bold,n.italic,n.letterSpacingPt]),c=e.get(i);if(c)return e.delete(i),e.set(i,c),c.lines.slice();const l=j.wrapText(o,a,n,s),d=i.length+l.reduce((f,u)=>f+u.length,0);if(d<=Re){for(;e.size>=gt||t+d>Re;){const f=e.keys().next().value;t-=e.get(f).units,e.delete(f)}e.set(i,{lines:l.slice(),units:d}),t+=d}return l}}class L extends Error{constructor(t,r){super(`报表页数超出上限 ${t}(至少 ${r} 页)`),this.limit=t,this.actual=r,this.code="page-limit",this.name="PaginatePageLimitError"}}class H extends Error{constructor(t,r){super(`报表单元格数量超出上限 ${t}(至少 ${r} 格)`),this.limit=t,this.actual=r,this.code="cell-limit",this.name="PaginateCellLimitError"}}const xe=1e4,Pe=25e4;function ue(e){if(e?.aborted)throw e.reason??new DOMException("标签生成已取消","AbortError")}function Oe(e,t,r){const o=typeof e.copies=="object"?E.readRecordScalar(t,e.copies.field,r):e.copies??1;if(typeof o!="number"||!Number.isSafeInteger(o)||o<1||o>1e3)throw new E.ReportBindingError(`$.datasets.${r.dataset}[${r.rowIndex}]`,"每条记录复制数必须是 1..1000 的数值型整数",r.rowIndex,typeof e.copies=="object"?e.copies.field:void 0);return o}function Fe(e,t,r){if(e.rowKey===void 0)return;const o=E.readRecordScalar(t,e.rowKey,r);if(typeof o=="string"&&o.trim()||typeof o=="number"&&Number.isFinite(o))return o;throw new E.ReportBindingError(`$.datasets.${r.dataset}[${r.rowIndex}].${e.rowKey}`,"业务主键必须是非空字符串或有限数字",r.rowIndex,e.rowKey)}function pt(e){const t=r=>1+(r.grid?.cells.reduce((o,a)=>o+1+a.length+a.reduce((n,s)=>n+(s?.children?.reduce((i,c)=>i+t(c),0)??0),0),0)??0);return e.pages.reduce((r,o)=>r+o.components.reduce((a,n)=>a+t(n),0),0)}function wt(e,t,r){const o=e.repeat,a=Object.prototype.hasOwnProperty.call(t,o.dataset)?t[o.dataset]:void 0;if(!Array.isArray(a))throw new E.ReportBindingError(`$.datasets.${o.dataset}`,"逐记录标签数据集缺失,应提供对象数组(允许空数组)");const n=new Set,s=r.maxPages??xe,i=pt(e);let c=0,l=0;for(const[d,f]of a.entries()){if(ue(r.signal),!f||typeof f!="object"||Array.isArray(f))throw new E.ReportBindingError(`$.datasets.${o.dataset}[${d}]`,"标签记录应为对象",d);const u={rowIndex:d,dataset:o.dataset},g=Fe(o,f,u);if(g!==void 0){const m=JSON.stringify([typeof g,g]);if(n.has(m))throw new E.ReportBindingError(`$.datasets.${o.dataset}[${d}].${o.rowKey}`,"业务主键重复;请先确认记录来源,避免重复打印标签",d,o.rowKey);n.add(m)}const h=Oe(o,f,u);if(c+=h*e.pages.length,l+=h*i,c>s)throw new L(s,c);if(l>Pe)throw new E.ReportBindingError("$.repeat",`标签组件总量(含网格行、槽位及嵌套组件)超过安全预算 ${Pe},请分批生成`,d)}return a}function yt(e,t,r){if(!e.binding)return e;const{binding:o,...a}=e,n=E.resolveComponentBinding(o,t.row,t);if(e.kind==="image"){if(!n)return;if(!E.isLabelImageData(n))throw new E.ReportBindingError(`${r}.binding`,"图片字段只接受 PNG/JPEG base64 data URL;业务 URL 应由宿主安全加载后转换",t.rowIndex,o.field);return{...a,imageData:n}}return e.kind==="barcode"||e.kind==="qrcode"?(delete a.imageData,{...a,code:{...a.code,value:n},fallbackText:n}):(delete a.lines,delete a.richParagraphs,{...a,text:n})}function Mt(e,t,r){if(e.kind!=="text"||e.grid||e.richParagraphs?.length)return e;const o=e.style??{},a=$.resolveFontSize(o).fontSizePt,n=e.text??e.lines?.join(`
2
+ `)??"";if(n.length>16384)throw new E.ReportBindingError(r,"标签文本超过 16384 字符预算,请缩小字段内容",t.rowIndex);const s=t.wrapText(n,e.widthMm,{fontSizePt:a,bold:o.bold,italic:o.italic,fontFamily:o.fontFamily,letterSpacingPt:o.letterSpacing},t.options.measurer??j.heuristicMeasurer),i=s.length*a*$.resolveLineHeight(o)*25.4/72;if(i>e.heightMm+.05)throw new E.ReportBindingError(r,`标签文字需要约 ${i.toFixed(2)}mm 高,超出 ${e.heightMm}mm;请增大文本区域、减少内容或调整字号`,t.rowIndex,e.binding?.field);return{...e,lines:s}}function Ae(e,t,r){ue(t.options.signal);const o=yt(e,t,r);if(!o)return;let a=o.grid;return a&&(a={...a,cells:a.cells.map((n,s)=>n.map((i,c)=>i?.children?.length?{...i,children:i.children.flatMap((l,d)=>{const f=Ae(l,t,`${r}.grid.cells.${s}.${c}.children.${d}`);return f?[f]:[]})}:i))}),Mt(a===o.grid?o:{...o,grid:a},t,r)}function bt(e,t,r,o,a,n){return{...e,components:e.components.flatMap((s,i)=>{const c=Ae(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,...n===void 0?{}:{rowKey:n},copyIndex:o,copyCount:a,templatePageIndex:t}}}}function*vt(e,t,r){const o=[];if(N.validateTemplateRepeat(e,o),o.length)throw new E.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 a=e.repeat,n=wt(e,t,r),s=ht();for(const[i,c]of n.entries()){const l={row:c,rowIndex:i,dataset:a.dataset,options:r,wrapText:s},d=Oe(a,c,l),f=Fe(a,c,l);for(let u=0;u<d;u++)for(const[g,h]of e.pages.entries())ue(r.signal),yield{page:bt(h,g,l,u,d,f),pageIndex:g}}}function Et(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 V(e,t){const r=t.heightMm-(e.layout==="wide"?t.marginBottomMm:e.marginBottomMm??t.marginBottomMm);return e.components.reduce((o,a)=>a.kind!=="list"&&a.pageAnchor==="footer"?Math.min(o,a.topMm):o,r)}function _(e){return e.components.reduce((t,r)=>r.kind!=="list"&&r.pageAnchor==="header"?Math.max(t,r.topMm+r.heightMm):t,0)}function Ie(e,t){let r=e.textMetrics.get(t);if(!r){const o=$.resolveFontSize(t).fontSizePt;r={measureOptions:{fontSizePt:o,fontFamily:t.fontFamily??K.DEFAULT_FONT_FAMILY,italic:t.italic,bold:t.bold,letterSpacingPt:t.letterSpacing},lineMm:o*(t.lineHeight??K.LINE_HEIGHT)*25.4/72},e.textMetrics.set(t,r)}return r}function St(e){if(e===null||typeof e=="string"||typeof e=="boolean"||typeof e=="number"&&Number.isFinite(e))return e}function fe(e,t){const r=e.fontSizePt??K.DEFAULT_FONT_PT,o=e.paddingMm??1,a=e.columns.map(m=>m.align??m.style?.align??e.align??"left"),n=e.columns.map((m,w)=>({...$.mergeComponentStyles({fontSize:r,verticalAlign:"middle"},m.style),align:a[w]==="auto"?"left":a[w]})),s=n.map((m,w)=>a[w]==="auto"?{left:m,center:{...m,align:"center"},right:{...m,align:"right"}}:void 0),i=e.columns.map((m,w)=>m.rules?.map(S=>{const R=s[w];if(R)return{left:$.mergeComponentStyles(R.left,S.style),center:$.mergeComponentStyles(R.center,S.style),right:$.mergeComponentStyles(R.right,S.style)};const T=$.mergeComponentStyles(n[w],S.style);return{left:T,center:T,right:T}})),c=e.columns.map(m=>E.resolveListHeaderStyle(e,m)),l=e.columns.map(m=>m.header);let d=e.rowHeightMm??0;for(let m=0;m<l.length;m++){const w=c[m],S=$.resolveFontSize(w).fontSizePt,R=j.wrapText(l[m],e.columns[m].widthMm-o*2,{fontSizePt:S,fontFamily:w.fontFamily??K.DEFAULT_FONT_FAMILY,italic:w.italic,bold:w.bold,letterSpacingPt:w.letterSpacing},t),T=S*(w.lineHeight??K.LINE_HEIGHT)*25.4/72;d=Math.max(d,Math.max(R.length,1)*T+o*2)}const f=l.map((m,w)=>({text:m,style:c[w]})),u=e.border===!1?{borderTop:!1,borderRight:!1,borderBottom:!1,borderLeft:!1}:{borderBottom:!0,borderLeft:!0,borderRight:!0,borderTop:!0},g=e.columns.map(m=>m.widthMm),h=Rt(e.headerGrid,g,{cells:[f],colWidthsMm:g,rowHeightsMm:[d],paddingMm:o});return{fontSizePt:r,paddingMm:o,cellStyles:n,autoStyles:s,ruleStyles:i,textMetrics:new WeakMap,numberFormats:e.columns.map(m=>E.toExcelNumberFormat(m.format)),derivedFields:new Set(e.computed?.map(m=>m.field)),borderStyle:u,headerHeightMm:h.rowHeightsMm.reduce((m,w)=>m+w,0),headerGrid:h,colWidthsMm:g,columns:e.columns}}function Rt(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(a=>!Number.isFinite(a)||a<=0))throw new Error("自定义列表表头行高无效");return{...e,colWidthsMm:t,rowHeightsMm:o}}function Pt(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 G(e,t,r){const o=e.columns,a=e.tree?.rows.get(t);let n=e.rowHeightFloorMm;const s=new Array(o.length);for(let i=0;i<o.length;i++){const c=o[i],l=c.visibleWhen&&!E.evalStyleRule(t,c.visibleWhen)?null:t[c.field],d=e.autoStyles[i]?E.resolveListAutoAlignment(l,c.format,c.semanticRole):"left";let f=e.autoStyles[i]?.[d]??e.cellStyles[i];if(c.rules)for(let R=0;R<c.rules.length;R++){const T=c.rules[R];if(E.evalStyleRule(t,T.when)){f=e.ruleStyles[i][R][d];break}}const u=c.format?E.formatValue(l,c.format):E.listCellText(l),g=Tt(e,c,a);f=Ct(e,c,f,a);const h=Ie(e,f),m=j.wrapText(u,Math.max(1,c.widthMm-e.paddingMm*2-g),h.measureOptions,r);n=Math.max(n,m.length*h.lineMm+e.paddingMm*2);const w=St(l),S={text:u,style:f};w!==void 0&&(S.value=w),Pt(S,c,e.numberFormats[i]),kt(S,c,e,a,g),e.derivedFields.has(c.field)&&(S.derived=!0,S.editable=!1),c.visibleWhen&&l===null&&!E.evalStyleRule(t,c.visibleWhen)&&(S.editable=!1),s[i]=S}return{grid:{cells:[s],colWidthsMm:e.colWidthsMm,rowHeightsMm:[n],paddingMm:e.paddingMm},heightMm:n}}function Tt(e,t,r){return!r||t.field!==e.tree.list.tree.labelField?0:E.listTreeIndent(e.tree.list,t,r,e.paddingMm)}function Ct(e,t,r,o){return!o||t.field!==e.tree.list.tree.labelField||r.align==="left"?r:{...r,align:"left"}}function kt(e,t,r,o,a=0){o&&(a&&(e.indentMm=a),E.applyListTreeMetadata(e,t,o,r.tree.list))}function Le(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*Ne(e,t,r=0){const o=t[r];if(!o){for(const n of e)yield{kind:"row",row:n};return}const a=new Map;for(const n of e){const s=Le(n[o.field]),i=a.get(s);i?i.push(n):a.set(s,[n])}for(const n of a.values())yield{kind:"groupHeader",label:(o.headerTemplate??"{value}").replace(/\{value\}/g,E.listCellText(n[0][o.field])),firstRow:n[0],group:o,depth:r,rows:n},yield*Ne(n,t,r+1),(o.subtotal?.length||o.aggregates?.length)&&(yield{kind:"subtotal",label:o.subtotalLabel??"小计",rows:n,group:o,depth:r}),yield{kind:"groupEnd",depth:r}}function He(e,t,r,o=[]){const a=[...r.filter(n=>!o.some(s=>s.field===n)).map(n=>({field:n,op:"sum"})),...o];return new Map(a.map(n=>{const s=e.find(c=>c.field===n.field)?.format??{kind:"number",thousands:!0},i=de.aggregateRows(t,{...n,field:n.valueField??n.field});return[n.field,{text:E.formatValue(i,s),...i===null?{}:{value:i},...typeof i=="number"?{numberFormat:E.toExcelNumberFormat(s)}:{}}]}))}function je(e,t){const r=e.findIndex(o=>t.includes(o.field));return r<0?1:r}function B(e,t,r,o,a,n){const s=[],i=Math.max(0,Math.min(n,e.columns.length)),c=$.mergeComponentStyles({fontSize:e.fontSizePt},a);i&&s.push({text:r,colSpan:i,style:{bold:!0,...c}});for(let u=i;u<e.columns.length;u++){const g=e.columns[u],h=o.get(g.field),m=e.autoStyles[u]?.[E.resolveListAutoAlignment(h?.value,g.format)]??e.cellStyles[u];s.push({...h,text:h?.text??"",style:$.mergeComponentStyles(m,a)})}const l={text:r,colSpan:e.columns.length,style:{bold:!0,...c}},d=i?[s]:[[l],s],f=d.map(u=>$t(e,u,t));return{grid:{cells:d,colWidthsMm:e.colWidthsMm,rowHeightsMm:f,paddingMm:e.paddingMm},heightMm:f.reduce((u,g)=>u+g,0)}}function $t(e,t,r){let o=e.rowHeightFloorMm,a=0;for(const n of t){let s=0;const i=a+(n.colSpan??1);for(;a<i;a++)s+=e.colWidthsMm[a]??0;const c=Ie(e,n.style),l=j.wrapText(n.text??"",s-e.paddingMm*2,c.measureOptions,r);o=Math.max(o,l.length*c.lineMm+e.paddingMm*2)}return o}function xt(e,t,r){const{templatePage:o,current:a,warnings:n,nextId:s,pushCurrent:i}=r,c=()=>V(o,a),l=Math.max(a.marginTopMm,_(o)),d=o.layout==="wide"?_(o):l,f={id:r.tableId,columnKeys:e.columns.map(p=>p.field),...e.layout===void 0?{}:{layout:e.layout},...e.title===void 0?{}:{title:e.title}},u=new Map,g=new Map,h={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?{meta:e.meta}:{}},m=p=>a.components.push({...h,topMm:p});if(r.flow&&e.header!==!1&&t.headerHeightMm>c()-l+.001)throw new Error(`流式列表 ${e.id??e.dataset} 的表头高度超出单页可用范围`);let w=Math.max(r.startTop??e.topMm,l);e.header!==!1&&(m(w),w+=t.headerHeightMm+r.mmPerRow);function S(){const p=Math.max(r.flow||o.layout==="wide"?0:e.topMm,d);return(e.header!==!1&&e.headerEveryPage!==!1?p+t.headerHeightMm:d)+[...g.values()].reduce((v,C)=>v+C.heightMm,0)}function R(){const p=o.layout==="wide"?0:a.marginBottomMm;return Math.min(o.heightMm-p,V(o,a))-S()}function T(p){if(w+p<=c())return;i(),a.components=[],a.heightMm=o.heightMm,o.layout==="wide"&&(a.marginTopMm=0,a.marginBottomMm=0);const y=Math.max(r.flow||o.layout==="wide"?0:e.topMm,d);e.header!==!1&&e.headerEveryPage!==!1?(m(y),w=y+t.headerHeightMm):w=d;for(const v of g.values())I(v,"listgr","group-header")}function b(p,y,v,C){const k=R();if(r.flow&&p.heightMm>k+.001)throw new Error(`流式列表 ${e.id??e.dataset} 的单行高度超出单页可用范围`);p.heightMm>k&&n.push(`列表 ${e.id??e.dataset} 行高 ${p.heightMm.toFixed(2)}mm 超出单页可用高度 ${k.toFixed(2)}mm,预览与打印可能截断内容`),T(p.heightMm),I(p,y,v,C)}function I(p,y,v,C){const k=p.table?.id??f.id,A=v==="header"?-1:u.get(k)??0;v!=="header"&&u.set(k,A+p.grid.cells.length),a.components.push({kind:"rect",leftMm:e.leftMm,topMm:w,widthMm:e.widthMm,heightMm:p.heightMm,grid:p.grid,nid:s(y),table:{...f,...p.table,role:v,rowIndex:A,...C?{source:C}:{}},style:t.borderStyle,...e.meta?{meta:e.meta}:{}}),w+=p.heightMm}function F(p){p<=R()&&T(p)}return{keepTogether:F,placeGridRow:b,setGroupHeader:(p,y)=>{y?g.set(p,y):g.delete(p)},bottom:()=>w}}function Ot(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,a=e.sourceTokenField?t[e.sourceTokenField]:void 0;if(o!==void 0&&typeof o!="string"&&!(typeof o=="number"&&Number.isFinite(o)))throw new Error("业务修订号应为字符串或有限数字");if(a!==void 0&&typeof a!="string")throw new Error("来源令牌应为字符串");return{datasetId:e.dataset,rowKey:r,...o===void 0?{}:{revision:o},...a===void 0?{}:{sourceToken:a}}}function Y(e,t){const r=new Map;if(!e.rowKey)return r;const o=new Set;for(const a of t){const n=Ot(e,a),s=JSON.stringify(n.rowKey);if(o.has(s))throw new Error(`数据集 ${e.dataset} 的业务主键重复:${String(n.rowKey)}`);o.add(s),r.set(a,n)}return r}function Ft(e,t,r,o,a){if(!e.grandTotal)return;const n=typeof e.grandTotal=="object"?e.grandTotal:void 0,s=Q(e)[0],i=n?.fields??s?.subtotal??[],c=n?.aggregates??s?.aggregates??[];if(i.length===0&&c.length===0){o.warnings.push(`列表 ${e.id??""} 配置了 grandTotal 但未提供合计字段(groupBy.subtotal 或 grandTotal.fields)`);return}const l=B(r,o.measurer,n?.label??"合计",He(e.columns,t,i,c),n?.style??{},je(e.columns,[...i,...c.map(d=>d.field)]));a.placeGridRow(l,"listgt","grand-total")}function W(e){if(e?.aborted){const t=new Error("报表排版已取消");throw t.name="AbortError",t}}function Q(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((a,n)=>a+n.widthMm,0),o=r>t.widthMm?t.widthMm/r:1;return o===1?t:{...t,columns:t.columns.map(a=>({...a,widthMm:a.widthMm*o}))}}function At(e,t,r){const o=e.detail;if(!o)return;const a=new Set;for(const l of t){const d=ae(l[o.parentKey]);if(a.has(d))throw new Error("主从明细的主表关联键重复");a.add(d)}const n=r.datasets[o.dataset]??[],s=new Map,i=[];for(const l of n){const d=l[o.foreignKey];if(!De(d)&&o.unmatched==="ignore")continue;const f=ae(d);if(!a.has(f)){if(o.unmatched!=="ignore")throw new Error(`明细数据集 ${o.dataset} 存在未关联的业务键`);continue}const u=s.get(f);u?u.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:{...fe(c,r.measurer),rowHeightFloorMm:c.rowHeightMm??0},rows:s,sources:Y(c,i)}}function De(e){return typeof e=="string"&&!!e.trim()||typeof e=="number"&&Number.isFinite(e)}function ae(e){if(!De(e))throw new Error("主从关联键必须是非空字符串或有限数字");return Le(e)}function*It(e,t,r,o,a){if(!r)return;const n=r.rows.get(ae(t[e.detail.parentKey]))??[];if(!n.length)return;const s={id:`${o.tableId}:detail`,columnKeys:r.list.columns.map(i=>i.field),title:e.detail.label};e.detail.label&&a.placeGridRow({...B(r.inter,o.measurer,e.detail.label,new Map,{},r.list.columns.length),table:s},"listdl","group-header"),e.detail.header!==!1&&a.placeGridRow({grid:r.inter.headerGrid,heightMm:r.inter.headerHeightMm,table:s},"listdh","header"),yield*o.takePages();for(const i of n)W(o.signal),a.placeGridRow({...G(r.inter,i,o.measurer),table:s},"listdr","body",r.sources.get(i)),yield*o.takePages()}function Lt(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=Ce.createMatrixTable(t,e.matrix),o=r.columns.map((n,s)=>({...n,widthMm:s===0?e.matrix.rowWidthMm??40:e.matrix.columnWidthMm??28,editable:!1,align:s===0?"center":"right"})),a={...e,columns:o,headerGrid:void 0,rowKey:void 0,revisionField:void 0,sourceTokenField:void 0};return e.layout==="wide"&&(a.widthMm=o.reduce((n,s)=>n+s.widthMm,0)),{list:a,rows:r.rows}}function Ke(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("树形布局需要可见的标签列");U.validateTreeComputed(e.tree,e.computed)}function Nt(e,t,r){Ke(e);const o=U.createTreeTable(t,e.tree,{signal:r.signal,computed:e.computed?.length?{fields:e.computed,formula:r.formula}:void 0}),a={...e,rowKey:e.tree.idField},n=Y(a,o.entries.map(c=>c.original)),s=new Map,i=new WeakMap;for(const c of o.entries)s.set(c.row,n.get(c.original)),i.set(c.row,c);return{list:a,rows:o.rows,sources:s,treeRows:i,totalRows:o.leaves}}function Ht(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 Be(e,t,r){const o=r.prepared.get(e);if(o)return o;const a=Ht(e,t);if(a)return r.prepared.set(e,a),a;if(e.tree){const c=Nt(e,t,r);return r.prepared.set(e,c),c}let n=e.computed?.length?de.computeDataset(t,{fields:e.computed,signal:r.signal,formula:r.formula}).rows:t;const s=n===t?void 0:new Map(n.map((c,l)=>[c,t[l]]));e.rowVisibleWhen&&(n=n.filter(c=>E.evalStyleRule(c,e.rowVisibleWhen)));const i=Lt(e,n);if(!e.matrix){const c=Y(e,s?n.map(l=>s.get(l)):n);i.sources=s?new Map(n.map(l=>[l,c.get(s.get(l))])):c}return r.prepared.set(e,i),i}function jt(e,t,r,o){if(!o.flow)return;const{current:a,templatePage:n}=o,s=Math.max(a.marginTopMm,_(n)),i=Math.max(o.startTop??e.topMm,s),c=(e.header===!1?0:t.headerHeightMm)+(r[0]?G(t,r[0],o.measurer).heightMm:0);i+c<=V(n,a)+.001||i<=s+.001||(o.pushCurrent(),a.components=[],a.heightMm=n.heightMm,n.layout==="wide"&&(a.marginTopMm=0,a.marginBottomMm=0),o.startTop=Math.max(a.marginTopMm,_(n)))}function*Dt(e,t,r){const o=Be(e,t,r),a=o.rows;e=o.list,e.layout==="wide"&&(r.current.widthMm=Math.max(r.current.widthMm,e.leftMm+e.widthMm+r.current.marginRightMm));const n=o.sources??Y(e,a),s=me(e),i=Q(s),c={...fe(s,r.measurer),rowHeightFloorMm:s.rowHeightMm??0,...o.treeRows?{tree:{list:s,rows:o.treeRows}}:{}};jt(s,c,a,r);const l=xt(s,c,r),d=At(s,a,r);let f;for(const u of Ne(a,i)){if(W(r.signal),u.kind==="row")l.placeGridRow(f??G(c,u.row,r.measurer),"listr","body",n.get(u.row)),f=void 0,yield*r.takePages(),yield*It(s,u.row,d,r,l);else if(u.kind==="groupHeader"){const g=B(c,r.measurer,u.label,new Map,u.group.headerStyle??{},s.columns.length);f??=G(c,u.firstRow,r.measurer);const h=i.slice(u.depth+1).reduce((m,w)=>m+B(c,r.measurer,(w.headerTemplate??"{value}").replace(/\{value\}/g,E.listCellText(u.firstRow[w.field])),new Map,w.headerStyle??{},s.columns.length).heightMm,0);u.group.keepWithNext!==!1&&l.keepTogether(g.heightMm+h+f.heightMm),l.placeGridRow(g,"listg","group-header"),u.group.repeatHeader&&l.setGroupHeader(u.depth,g)}else if(u.kind==="subtotal"){const g=u.group.subtotal??[],h=u.group.aggregates??[],m=B(c,r.measurer,u.label,He(s.columns,u.rows,g,h),u.group.subtotalStyle??{},je(s.columns,[...g,...h.map(w=>w.field)]));l.placeGridRow(m,"listst","subtotal")}else l.setGroupHeader(u.depth);yield*r.takePages()}Ft(s,o.totalRows??a,c,r,l),r.finished?.(l.bottom()),yield*r.takePages()}function Z(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 ee(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(a=>ee(a,t))}:{}}:null))}}:{}}}function Kt(e){let t=!1;for(const r of e.pages)for(const o of r.components)Z(o)&&ee(o,a=>(a.includes("{totalPages}")&&(t=!0),a));return t}function Bt(e,t,r,o,a,n){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 n===void 0?l:l.replace(/\{totalPages\}/g,String(n))};for(const c of r)s.components.push(ee(c,i));if(e.layout==="wide"){const c=s.components.reduce((l,d)=>Math.max(l,d.topMm+d.heightMm),0);s.marginBottomMm=a?e.marginBottomMm??0:0,s.pageHeightMm=Math.max(1,c+s.marginBottomMm)}return s}function ge(e){return e.cells.reduce((t,r)=>t+r.reduce((o,a)=>o+(a?1+(a.children?.reduce((n,s)=>n+_e(s),0)??0):0),0),0)}function _e(e){return e.grid?ge(e.grid):0}function he(e){for(const t of["maxPages","maxCells","knownTotalPages"])if(e[t]!==void 0&&(!Number.isSafeInteger(e[t])||e[t]<1))throw new RangeError(`${t} 应为正安全整数`)}function _t(e,t){const r=Be(e,t.datasets[e.dataset]??[],t),o=me(r.list),a={...fe(o,t.measurer),rowHeightFloorMm:o.rowHeightMm??0};return(o.header===!1?0:a.headerHeightMm)+r.rows.reduce((n,s)=>n+G(a,s,t.measurer).heightMm,0)}function*Gt(e){const{templatePage:t,current:r}=e,o=new Map(t.components.map((n,s)=>[n,s])),a=(n,s,i)=>{const c=e.datasets[n.dataset];return Array.isArray(c)||e.warnings.push(`数据集 ${n.dataset} 未提供数据,列表 ${n.id??""} 输出为空`),Dt(n,Array.isArray(c)?c:[],{...e,tableId:`${e.tableId}:${o.get(n)}`,startTop:s,finished:i,flow:!!t.flow})};if(t.flow){yield*ft({page:t,active:()=>W(e.signal),top:()=>Math.max(r.marginTopMm,_(t)),bottom:()=>V(t,r),append:n=>{r.components.push(n)},nextPage:()=>{e.pushCurrent(),r.components=[],r.heightMm=t.heightMm,t.layout==="wide"&&(r.marginTopMm=0,r.marginBottomMm=0)},takePages:e.takePages,height:n=>_t(n,e),list:a});return}for(const n of t.components)Z(n)||(n.kind==="list"?yield*a(n):r.components.push(n))}function*J(e,t,r,o,a,n=new WeakMap){let s=0,i=0,c=0;const l=d=>`${d}_${(++s).toString(36)}`;for(const{pageIndex:d,page:f}of vt(e,t,r)){W(r.signal);const u=Et(f),g=f.components.filter(Z);let h=[];const m=(S=!1)=>{if(W(r.signal),r.maxPages!==void 0&&i>=r.maxPages)throw new L(r.maxPages,i+1);if(r.maxCells!==void 0&&(c+=[...u.components,...g].reduce((R,T)=>R+_e(T),0),c>r.maxCells))throw new H(r.maxCells,c);h.push(Bt(f,u,g,++i,S,a))},w=()=>{const S=h;return h=[],S};yield*Gt({templatePage:f,current:u,warnings:o,nextId:l,pushCurrent:m,takePages:w,datasets:t,signal:r.signal,formula:r.formula,prepared:n,measurer:r.measurer??j.heuristicMeasurer,mmPerRow:r.mmPerRow??0,tableId:`table:${d}`}),m(!0),yield*w()}}function Wt(e,t,r={}){he(r);let o=0;for(const a of J(e,t,{...r,onWarning:void 0},[]))o++;return o}function*Ge(e,t,r={}){he(r);const o=Kt(e),a=new WeakMap;let n=r.knownTotalPages;if(o&&n===void 0){n=0;for(const c of J(e,t,r,[],void 0,a))n++}const s=[];let i=0;for(const c of J(e,t,r,s,n,a)){for(;i<s.length;i++)r.onWarning?.(s[i]);yield c}}function pe(e,t,r={}){const o=typeof r=="number"?{mmPerRow:r}:r;he(o);const a=[],n=[...J(e,t,o,a,o.knownTotalPages)];for(const s of n)s.components=s.components.map(i=>Z(i)?ee(i,c=>c.replace(/\{totalPages\}/g,String(n.length))):i);return a.forEach(s=>o.onWarning?.(s)),{plan:{schemaVersion:z.RENDER_PLAN_SCHEMA_VERSION,...X(e)?{requiresRecalculation:!0}:{},pages:n},warnings:a}}function qt(e){const t=e.columns.find(n=>!n.hidden)?.field;if(!t)return{groups:0,total:0};const r=Q(e),o=(n=[],s=[])=>n.includes(t)||s.some(i=>i.field===t),a=typeof e.grandTotal=="object"?e.grandTotal:void 0;return{groups:r.filter(n=>o(n.subtotal,n.aggregates)).length,total:Number(o(a?.fields??r[0]?.subtotal,a?.aggregates??r[0]?.aggregates))}}function Vt(e,t,r){Ke(e);const o=U.flattenTreeInput(t[e.dataset]??[],e.tree,r),a=e.columns.filter(s=>!s.hidden).length,n=e.header===!1?0:e.headerGrid?ge(e.headerGrid):a;return o.length*a+n+ +!!e.grandTotal*2*a}function Jt(e,t,r={}){if(e.tree)return Vt(e,t,r.signal);if(e.matrix){let c=t[e.dataset]??[];e.computed?.length&&(c=de.computeDataset(c,{fields:e.computed,...r}).rows),e.rowVisibleWhen&&(c=c.filter(d=>E.evalStyleRule(d,e.rowVisibleWhen)));const l=Ce.estimateMatrixTable(c,e.matrix);return l.cells+l.columnCount}const o=t[e.dataset]?.length??0,a=e.columns.filter(c=>!c.hidden).length,n=Q(e).length,s=qt(e);let i=(o*(1+2*n+s.groups)+ +!!e.grandTotal*(1+s.total))*a;if(i+=e.header===!1?0:e.headerGrid?ge(e.headerGrid):a,e.cardinality==="record"&&o===0&&(i+=a),e.detail){const c=t[e.detail.dataset]?.length??0,l=e.detail.columns.filter(d=>!d.hidden).length;i+=(c+o*(+(e.detail.header!==!1)+ +!!e.detail.label))*l}if(!Number.isSafeInteger(i))throw new RangeError("报表单元格估算超出安全整数预算");return i}function We(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 D(e){return JSON.stringify([e.sourceScope,e.datasetId])}function Te(e){return JSON.stringify([e.sourceScope,e.datasetId,e.rowKey])}function qe(e){const t=new Map,r=new Set;return e.forEach((o,a)=>{for(const n of We(o)){if(!n.rowKey)continue;const s=n.relation,i=s?new Set(s.parentRows.map(c=>JSON.stringify(c[s.detail.parentKey]))):void 0;(o.datasets[n.dataset]??[]).forEach((c,l)=>{if(s&&!i.has(JSON.stringify(c[s.detail.foreignKey])))return;const d=c[n.rowKey];if(typeof d!="string"&&typeof d!="number")return;const f=`${a}:${n.dataset}:${l}:${n.rowKey}`;if(r.has(f))return;r.add(f);const u=Te({sourceScope:o.sourceScope,datasetId:n.dataset,rowKey:d}),g=t.get(u)??[];g.push({partIndex:a,dataset:n.dataset,rowIndex:l,row:c,binding:n}),t.set(u,g)})}}),o=>{const a=t.get(Te(o));if(!a?.length)throw new M.ReportCellEditError("missing");if(new Set(a.map(n=>`${n.partIndex}:${n.dataset}`)).size!==a.length)throw new M.ReportCellEditError("conflict");return a}}function Ve(e,t){const r=e.map(a=>({...a,datasets:{...a.datasets}})),o=new Set;for(const{row:a,field:n,value:s}of t){const i=r[a.partIndex],c=`${a.partIndex}:${a.dataset}`;o.has(c)||(i.datasets[a.dataset]=[...i.datasets[a.dataset]],o.add(c)),i.datasets[a.dataset][a.rowIndex]={...i.datasets[a.dataset][a.rowIndex],[n]:s}}return r}function zt(e,t,r){const o=[],a=new Set;return e.forEach((n,s)=>{for(const i of We(n))t.has(D({sourceScope:n.sourceScope,datasetId:i.dataset}))&&(n.datasets[i.dataset]??[]).forEach((c,l)=>{const d={partIndex:s,dataset:i.dataset,rowIndex:l,row:c,binding:i};for(const[f,u]of[[i.revisionField,r.revision],[i.sourceTokenField,r.sourceToken]]){if(!f||u===void 0)continue;const g=`${s}:${i.dataset}:${l}:${f}`;a.has(g)||(a.add(g),o.push({row:d,field:f,value:u}))}})}),o}function Je(e,t,r){if(!r||r.revision===void 0&&r.sourceToken===void 0)return e;const o=new Set(t.edits.flatMap(a=>a.source?[D(a.source)]:[]));return we(e,new Map([...o].map(a=>[a,r])))}function we(e,t){if(!t.size)return e;function r(n){const s=n.datasetId&&t.get(D({...n,datasetId:n.datasetId}));return!s||(s.revision===void 0||Object.is(s.revision,n.revision))&&(s.sourceToken===void 0||s.sourceToken===n.sourceToken)?n:{...n,...s.revision!==void 0?{revision:s.revision}:{},...s.sourceToken!==void 0?{sourceToken:s.sourceToken}:{}}}function o(n){const s=n.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,d=i.grid?.cells.map(u=>{const g=u.map(h=>{if(!h)return h;const m=h.source?r(h.source):void 0,w=h.children?o(h.children):void 0;return m===h.source&&w===h.children?h:{...h,source:m,children:w}});return g.some((h,m)=>h!==u[m])?g:u}),f=i.grid&&d?.some((u,g)=>u!==i.grid.cells[g])?{...i.grid,cells:d}:i.grid;return l!==i.table||f!==i.grid?{...i,table:l,grid:f}:i});return s.some((i,c)=>i!==n[c])?s:n}const a=e.pages.map(n=>{const s=o(n.components);return s!==n.components?{...n,components:s}:n});return a.some((n,s)=>n!==e.pages[s])?{...e,pages:a}:e}function ze(e){const t=new Map,r=M.createReportCellResolver(e);return e.pages.forEach((o,a)=>o.components.forEach((n,s)=>{if(!(!n.grid||n.table?.role!=="body"))for(let i=0;i<n.grid.cells.length;i++)for(let c=0;c<n.table.columnKeys.length;c++){const l=r({pageIndex:a,componentIndex:s,rowIndex:i,columnIndex:c});l?.source&&l.editable&&t.set(M.reportCellEditKey(l),l)}})),t}function Ut(e,t,r){const o=ze(e),a=M.createReportCellResolver(e);return t.map(n=>{const s=n.source?o.get(M.reportCellEditKey(n)):a(n.address);if(!s||M.reportCellEditKey(s)!==M.reportCellEditKey(n))throw new M.ReportCellEditError("missing");return{address:{...s.address},value:n[r]}})}function Ue(e,t){if(++e.nodes>1e6||t>128)throw new M.ReportCellEditError("limit")}function ye(e,t){const r=Object.getOwnPropertyDescriptor(e,t);if(!r||r.get||r.set)throw new M.ReportCellEditError("conflict");return r.value}function Xe(e){if(Object.getOwnPropertyDescriptor(e,"toJSON"))throw new M.ReportCellEditError("conflict");const t=Object.getPrototypeOf(e);if(!(e instanceof Date)&&!Array.isArray(e)&&t!==Object.prototype&&t!==null)throw new M.ReportCellEditError("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.ReportCellEditError("conflict");if(e instanceof Date||Array.isArray(e)&&!/^(0|[1-9]\d*)$/.test(r))throw new M.ReportCellEditError("conflict")}}function Ye(e,t,r,o,a){if(Ue(o,a),typeof e=="function"||typeof e=="symbol")throw new M.ReportCellEditError("conflict");if(e===null||typeof e!="object")return;if(Xe(e),r.has(e))throw new M.ReportCellEditError("conflict");r.add(e);const n=Object.keys(e),s=n.map(i=>ye(e,i));t.push({object:e,prototype:Object.getPrototypeOf(e),keys:n,values:s,...e instanceof Date?{date:Date.prototype.getTime.call(e)}:{},...Array.isArray(e)?{length:e.length}:{}});for(const i of s)Ye(i,t,r,o,a+1);r.delete(e)}function Xt(e){const{object:t,keys:r,values:o}=e;if(Xe(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 a=Object.keys(t);return a.length===r.length&&r.every((n,s)=>a[s]===n&&Object.is(ye(t,n),o[s]))}function Yt(e){const t=[];return Ye(e,t,new Set,{nodes:0},0),()=>{try{return t.every(Xt)}catch{return!1}}}function se(e,t,r){return Ue(t,r),e===null||typeof e!="object"?e:e instanceof Date?new Date(Date.prototype.getTime.call(e)):Array.isArray(e)?e.map(o=>se(o,t,r+1)):Object.fromEntries(Object.keys(e).map(o=>[o,se(ye(e,o),t,r+1)]))}function Qt(e){return se(e,{nodes:0},0)}async function Qe(e,t,r={}){const o=[],a={...r,knownTotalPages:void 0};for(const n of Ge(e,t,a))o.push(n),o.length%8===0&&await new Promise(s=>setTimeout(s,0));if(r.signal?.aborted){const n=new Error("报表重算已取消");throw n.name="AbortError",n}return{schemaVersion:z.RENDER_PLAN_SCHEMA_VERSION,...X(e)?{requiresRecalculation:!0}:{},pages:o}}const ie=new WeakMap;function Zt(e){return ie.get(e)}function q(e){if(e?.aborted){const t=new Error("报表重算已取消");throw t.name="AbortError",t}}function Ze(e,t){return e[t]===void 0?"":e[t]}function er(e,t){if(t.edits.length>1e4)throw new M.ReportCellEditError("limit");const r=M.createReportCellResolver(e),o=new Set,a=[],n=t.edits.map(s=>{const i=r(s.address);if(!i?.source)throw new M.ReportCellEditError("missing");const c=M.reportCellEditKey(s);if(o.has(c))throw new M.ReportCellEditError("duplicate");if(o.add(c),M.sourceChanged(i,s)||!Object.is(i.value,s.previousValue)||(i.cell.text??"")!==s.previousText)throw new M.ReportCellEditError("conflict");return a.push(i),M.editFromContext(i,s.value)});return{batch:{requestId:t.requestId,edits:n},contexts:a}}function tr(e,t){const r=qe(e);return t.flatMap(o=>{if(!o.source)throw new M.ReportCellEditError("missing");return r(o.source).map(a=>{if(!Object.is(Ze(a.row,o.source.field),o.previousValue))throw new M.ReportCellEditError("conflict");if(a.binding.rowKey===o.source.field)throw new M.ReportCellEditError("readonly");return{row:a,field:o.source.field,value:o.value}})})}function ne(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:M.formatReportCellEdit(o,o.value)},o}function rr(e,t,r){if(!r||r.revision===void 0&&r.sourceToken===void 0)return[...e];const o=new Set(t.edits.flatMap(a=>a.source?[D(a.source)]:[]));return Ve(e,zt(e,o,r))}function or(e,t,r){const o=new Set(t.edits.map(a=>D(a.source)));for(const a of o)e.set(a,{...e.get(a),...r.revision!==void 0?{revision:r.revision}:{},...r.sourceToken!==void 0?{sourceToken:r.sourceToken}:{}});return o}function Me(e,t){let r=t.parts;const o=t.rebuild;let a=Yt(r),n=e,s;const i=new Map,c=new Map;function l(u){if(u!==n)throw new M.ReportCellEditError("conflict");if(s)return s;if(!a?.())throw new M.ReportCellEditError("conflict");return Qt(r)}async function d(u,g,h,m={}){q(m.signal),g={requestId:g.requestId,edits:g.edits.map(b=>({...b,address:{...b.address},source:b.source?{...b.source}:void 0,table:b.table?{...b.table}:void 0}))},h=h.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)),q(m.signal);const w=l(u),S=Ve(w,tr(w,g.edits)),R=we(await o(S,m.signal),c);q(m.signal);let T=!1;return{plan:R,commit(b){if(q(m.signal),T||n!==u)throw new M.ReportCellEditError("conflict");if(b?.conflicts?.length)throw new M.ReportCellEditError("conflict");const I=rr(S,g,b),F=Je(R,g,b);if(b){const O=or(c,g,b);for(const[p,y]of i)O.has(D(y.source))&&i.set(p,ne(y,y.value,b))}return h.forEach((O,p)=>i.set(M.reportCellEditKey(O),ne(O,g.edits[p].value,b))),T=!0,s=I,r=void 0,a=void 0,n=F,ie.set(n,f),n}}}const f={get plan(){return n},async prepare(u,g,h){const m=er(u,g);return d(u,m.batch,m.contexts,h)},async prepareHistory(u,g,h,m,w){if(!m.trim()||g.length>1e4)throw new M.ReportCellEditError("limit");const S=l(u),R=qe(S),T=ze(u),b=new Set,F=g.map(y=>{if(!y.source)throw new M.ReportCellEditError("missing");const v=M.reportCellEditKey(y);if(b.has(v))throw new M.ReportCellEditError("duplicate");b.add(v);const C=T.get(v)??i.get(v);if(!C?.source)throw new M.ReportCellEditError("missing");const k=R(C.source)[0];return ne(C,Ze(k.row,C.source.field))}).map((y,v)=>({context:y,edit:M.editFromContext(y,g[v][h])})).filter(({edit:y})=>!Object.is(y.previousValue,y.value)),O={requestId:m,edits:F.map(({edit:y})=>y)},p=F.map(({context:y})=>y);return{batch:O,contexts:p,prepared:await d(u,O,p,w)}}};return ie.set(e,f),f}function nr(e){const t=pe(e.template,e.datasets,e.pagination).plan;return Me(t,{parts:[{template:e.template,datasets:e.datasets}],rebuild:(r,o)=>Qe(r[0].template,r[0].datasets,{...e.pagination,signal:o})})}let ar=0;function et(){return`report-${Date.now()}-${++ar}`}function ce(e,t,r){if(!r?.aborted)try{const o=e?.({...t});o&&typeof o.then=="function"&&Promise.resolve(o).catch(()=>{})}catch{}}function tt(e){const t=e.taskId??et(),r=(o,a,n)=>{ce(e.onEvent,{taskId:t,...e.correlationId===void 0?{}:{correlationId:e.correlationId},stage:o,status:a,...n===void 0?{}:{reportId:n}},e.signal)};return{taskId:t,progress(o,a,n){ce(e.onEvent,{taskId:t,...e.correlationId===void 0?{}:{correlationId:e.correlationId},stage:o,status:"started",completed:a,total:n},e.signal)},async run(o,a,n){r(o,"started",n);try{const s=await a();return r(o,"completed",n),s}catch(s){throw r(o,"failed",n),s}},runSync(o,a,n){r(o,"started",n);try{const s=a();return r(o,"completed",n),s}catch(s){throw r(o,"failed",n),s}}}}function be(e,t,r={}){const o=new Map;for(const n of e.pages)for(const s of n.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 a={...t};for(const[n,s]of o){const i=Math.min(s.maxRows??1e5,r.maxRows??1/0);a[n]=U.flattenTreeInput(t[n]??[],{...s,maxRows:i},r.signal)}return a}function sr(e,t,r={}){return Object.values(be(e,t,r)).reduce((o,a)=>o+a.length,0)}function ir(e,t,r){const o=ke.datasetJsonSchema(r),a=e?.pages.flatMap(i=>i.components).find(i=>i.kind==="list"&&i.dataset===t&&i.tree?.input==="nested");if(!a||a.kind!=="list"||!a.tree)return o;const n=o.items,s=a.tree.childrenField??"children";return{...o,items:{$ref:"#/$defs/treeNode"},$defs:{treeNode:{...n,properties:{...n.properties,[s]:{anyOf:[{type:"null"},{type:"array",items:{$ref:"#/$defs/treeNode"}}]}}}}}}function ve(e,t){return JSON.stringify([e,t])}function rt(e,t,r){return r===void 0?ve(e,t):JSON.stringify(["shared",r])}function ot(e,t,r){return e.map(o=>{const a=o.table?{...o.table,id:r(o.table.id),...o.table.source?{source:{...o.table.source,sourceScope:t}}:{}}:void 0,n=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:ot(i.children,t,r)}:{}}));return a||n?{...o,...a?{table:a}:{},...n?{grid:{...o.grid,cells:n}}:{}}:o})}function cr(e){if(!("mapData"in e))return e;const{load:t,mapData:r,...o}=e;return{...o,load:async a=>{const n=await t(a);x(a.signal);try{return r(n,a)}catch(s){throw new P("validate",`报表 ${a.reportId} 数据映射失败`,s)}}}}class P extends Error{constructor(t,r,o){super(r),this.name="ReportSourceError",this.code=t,this.cause=o}}function te(e){const t=new Error("报表加载已取消");return t.name="AbortError",Object.defineProperty(t,"cause",{value:e.reason}),t}function x(e){if(e?.aborted)throw te(e)}function le(e,t){return t?new Promise((r,o)=>{const a=()=>t.removeEventListener("abort",n),n=()=>{a(),o(te(t))};t.addEventListener("abort",n,{once:!0}),t.aborted&&n(),Promise.resolve(e).then(s=>{a(),r(s)},s=>{a(),o(s)})}):Promise.resolve(e)}function lr(e,t){if(!e||typeof e!="object"||Array.isArray(e))throw new P("validate",`报表 ${t} 的数据集应为对象`);for(const[r,o]of Object.entries(e))if(!Array.isArray(o)||o.some(a=>!a||typeof a!="object"||Array.isArray(a)))throw new P("validate",`报表 ${t} 的数据集 ${r} 应为对象数组`)}async function dr(e,t,r){const{reportId:o,signal:a}=t;try{const n=await le(e(t),a);x(a);const s=N.validateReportTemplate(n);if(!s.ok)throw new P("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}`)),n}catch(n){throw a?.aborted?te(a):n instanceof P?n:n instanceof N.ReportTemplateError?new P("validate",`报表 ${o} 模板校验失败:${n.message}`,n):new P("fetch",`报表 ${o} 模板加载失败:${n instanceof Error?n.message:String(n)}`,n)}}async function ur(e,t,r,o){const a=t.signal;let n;try{if(e.load)n=await le(e.load(t),a);else if(e.provider){const s=await le(e.provider.query(t),a);x(a),fr(s,r),n=s.datasets,o?.(r,s)}else n=e.datasets??{}}catch(s){throw a?.aborted?te(a):s instanceof P?s:new P("fetch",`报表 ${r} 取数失败:${s instanceof Error?s.message:String(s)}`,s)}return x(a),n}function fr(e,t){if(!e||typeof e!="object"||Array.isArray(e))throw new P("validate",`报表 ${t} Provider 应返回 datasets 结果对象`);for(const r of["revision","sourceToken"])if(e[r]!==void 0&&typeof e[r]!="string")throw new P("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 P("validate",`报表 ${t} Provider diagnostics 不符合结构化诊断契约`);if(e.diagnostics?.some(r=>!dt.hasValidDataExplanation(r)))throw new P("validate",`报表 ${t} Provider 数据说明缺少有效的字段身份或值状态`)}function mr(e,t,r,o,a){try{t=be(o,t,{maxRows:e.dataValidation?.maxRows,signal:a})}catch(n){throw new P("validate",`报表 ${r} 树形数据无效:${n instanceof Error?n.message:String(n)}`,n)}for(const[n,s]of Object.entries(e.dataSchema??{})){let i;try{i=ke.validateDatasetRows(Object.prototype.hasOwnProperty.call(t,n)?t[n]:void 0,s,{...e.dataValidation,path:`$.datasets.${n}`})}catch(c){throw new P("config",`报表 ${r} 数据集 ${n} 字段契约配置无效`,c)}if(!i.ok)throw new P("validate",`报表 ${r} 数据集 ${n} 不符合字段契约:${i.issues[0]?.message}`,{issues:i.issues})}}function nt(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 at(e){const t=r=>r.grid?.cells.reduce((o,a)=>o+a.reduce((n,s)=>n+(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((a,n)=>a+t(n),0),0)}function st(e,t,r,o){return{...e,signal:o??e?.signal,...t===void 0?{}:{maxPages:Math.max(1,Math.min(t,e?.maxPages??t))},...r===void 0?{}:{maxCells:Math.max(1,Math.min(r,e?.maxCells??r))}}}function gr(e,t,r,o,a,n){const s=a.maxPages===void 0?void 0:a.maxPages-a.usedPages,i=a.maxCells===void 0?void 0:a.maxCells-a.usedCells;try{if(s!==void 0&&s<1&&e.pages.length&&!nt(e,t))throw new L(0,1);const c=st(r.pagination,s,i,n),l=pe(e,t,c),d=at(l.plan);if(i!==void 0&&d>i)throw new H(i,d);return{...l,cells:d}}catch(c){let l=c;throw c instanceof L&&a.maxPages!==void 0&&c.limit===s&&(l=new L(a.maxPages,a.usedPages+c.actual)),c instanceof H&&a.maxCells!==void 0&&(l=new H(a.maxCells,a.usedCells+c.actual)),new P("validate",`报表 ${o} 排版失败:${l instanceof Error?l.message:String(l)}`,l)}}function it(e,t,r,o,a){const n=new Map,s=i=>{let c=n.get(i);return c===void 0&&(c=JSON.stringify([r,o,i]),n.set(i,c)),c};for(const i of t.pages)e.push({...i,meta:{...i.meta,reportScope:ve(r,o)},components:ot(i.components,a??rt(r,o),s)})}async function hr(e,t,r,o,a){const n=[];let s=0;for(const[l,d]of e.entries()){x(a);const f=o.maxPages===void 0?void 0:o.maxPages-n.length,u=o.maxCells===void 0?void 0:o.maxCells-s;if(f!==void 0&&f<1&&d.template.pages.length&&!nt(d.template,d.datasets))throw new L(o.maxPages,n.length+1);const g=await Qe(d.template,d.datasets,st(t[l]?.pagination,f,u,a));if(s+=at(g),o.maxCells!==void 0&&s>o.maxCells)throw new H(o.maxCells,s);it(n,g,l,r[l],d.sourceScope)}const i={schemaVersion:z.RENDER_PLAN_SCHEMA_VERSION,...e.some(l=>X(l.template))?{requiresRecalculation:!0}:{},pages:n},c=N.validateRenderPlan(i);if(!c.ok)throw new P("validate",`重算渲染计划校验失败:${c.errors[0]?.message}`);return i}function pr(e,t={}){if(t.maxPages!==void 0&&(!Number.isSafeInteger(t.maxPages)||t.maxPages<1))throw new P("config","maxPages 应为正安全整数");if(t.maxCells!==void 0&&(!Number.isSafeInteger(t.maxCells)||t.maxCells<1))throw new P("config","maxCells 应为正安全整数");function r(a){const n=Object.prototype.hasOwnProperty.call(e,a)?e[a]:void 0;if(!n)throw new P("config",`未注册报表 ${a}`);if(n.sourceScope!==void 0&&(typeof n.sourceScope!="string"||!n.sourceScope.trim()||n.sourceScope.length>512))throw new P("config","sourceScope 应为不超过 512 字符的非空字符串");return n}return Object.assign(async({reportIds:a,params:n,signal:s,onWarning:i,onQueryResult:c,...l})=>{x(s);const d=tt({...l,signal:s}),f=[...a],u={...n};if(f.length===0)throw new P("config","缺少报表 ID");const g=f.map(r),h=d.runSync("validate",()=>g.map(p=>Se.assertReportParams(p.params??(typeof p.template=="function"?[]:p.template.params)??[],u))),m=[],w=[];let S=0;const R=[];for(const[p,y]of g.entries()){x(s);const v=f[p],C={reportId:v,params:h[p],signal:s},k=typeof y.template=="function"?await d.run("query",()=>dr(y.template,C,R),v):y.template;C.params=d.runSync("validate",()=>Se.assertReportParams(y.params??k.params??[],C.params),v);const A=await d.run("query",()=>ur(y,C,v,(oe,ct)=>c?.(oe,ct,p)),v);d.runSync("validate",()=>{lr(A,v),t.onDatasets?.(v,A,k),mr(y,A,v,k,s)},v),x(s);const re=d.runSync("layout",()=>gr(k,A,y,v,{maxPages:t.maxPages,usedPages:m.length,maxCells:t.maxCells,usedCells:S},s),v);S+=re.cells;const Ee=rt(p,v,y.sourceScope);w.push({template:k,datasets:A,sourceScope:Ee}),it(m,re.plan,p,v,Ee),R.push(...re.warnings.map(oe=>`${v}: ${oe}`))}x(s);const T={schemaVersion:z.RENDER_PLAN_SCHEMA_VERSION,...w.some(p=>X(p.template))?{requiresRecalculation:!0}:{},pages:m},b=d.runSync("validate",()=>{const p=N.validateRenderPlan(T);if(!p.ok)throw new P("validate",`渲染计划校验失败:${p.errors.slice(0,3).map(y=>`${y.path}: ${y.message}`).join("; ")}`);return p});R.push(...b.warnings.map(p=>`${p.path}: ${p.message}`));const I=g.map(p=>({...p,pagination:{...p.pagination}})),F={maxPages:t.maxPages,maxCells:t.maxCells};try{Me(T,{parts:w,rebuild:(p,y)=>hr(p,I,f,F,y)})}catch{R.push("来源数据无法建立本地重算口径;当前预览仅支持计划内编辑,请使用可序列化模板数据启用规则重算")}const O=i??t.onWarning??(p=>console.warn("[mach-report]",p));for(const p of R)x(s),O(p);return x(s),T},{getParamDefs:a=>lt.getReportParamDefs(e,a)})}function wr(e,t){let r=0,o=0;const a=new Set;function n(c,l){if(++r>1e6||l>64)throw t.error("budget","快照节点或深度超过预算");if(r%1024===0&&t.check?.(),typeof c=="string"&&(o+=c.length,o>t.maxBytes))throw t.error("budget","快照文本超过预算");if(c===null||["string","boolean"].includes(typeof c)||typeof c=="number"&&Number.isFinite(c))return c;if(!c||typeof c!="object"||a.has(c))throw t.error("input","快照应为无循环的有限 JSON 值");return s(c,l)}function s(c,l){const d=Array.isArray(c),f=Object.getPrototypeOf(c);if(f!==(d?Array.prototype:Object.prototype)&&!(f===null&&!d)||Object.getOwnPropertySymbols(c).length)throw t.error("input","快照应为普通 JSON 对象");const u=Object.getOwnPropertyNames(c).filter(h=>!(d&&h==="length"));if(d&&(u.length!==c.length||u.some((h,m)=>h!==String(m))))throw t.error("input","快照数组应为连续数组");a.add(c);const g=Object.create(null);for(const h of u){if(o+=h.length,o>t.maxBytes)throw t.error("budget","快照文本超过预算");const m=Object.getOwnPropertyDescriptor(c,h);if(m.get||m.set||!m.enumerable||["__proto__","constructor","prototype"].includes(h))throw t.error("input","快照不允许访问器或危险键");m.value!==void 0&&(g[h]=n(m.value,l+1))}return a.delete(c),d?u.map(h=>g[h]):g}t.check?.();const i=JSON.stringify(n(e,0));if(new TextEncoder().encode(i).byteLength>t.maxBytes)throw t.error("budget","快照超过字节预算");return JSON.parse(i)}exports.DEFAULT_LABEL_PAGE_LIMIT=xe;exports.PaginateCellLimitError=H;exports.PaginatePageLimitError=L;exports.ReportSourceError=P;exports.applyReportEditResult=Je;exports.applyReportSourceMetadata=we;exports.countTemplatePages=Wt;exports.createReportEditSession=nr;exports.createReportSource=pr;exports.createReportTaskReporter=tt;exports.defineReport=cr;exports.estimateListLayoutCells=Jt;exports.getReportEditSession=Zt;exports.notifyReportTaskEvent=ce;exports.paginateTemplate=pe;exports.paginateTemplatePages=Ge;exports.projectListColumns=$e;exports.registerReportEditSession=Me;exports.relocateReportCellEdits=Ut;exports.reportOccurrenceScope=ve;exports.reportTaskId=et;exports.snapshotReportJson=wr;exports.templateDatasetJsonSchema=ir;exports.templateDatasetRowCount=sr;exports.templateValidationDatasets=be;
@@ -0,0 +1,24 @@
1
+ --- LICENSE ---
2
+ bwip-js : Barcode Writer in Pure JavaScript
3
+
4
+ Copyright (c) 2011-2026 Mark Warren
5
+
6
+ The MIT License
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in
16
+ all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ THE SOFTWARE.
@@ -0,0 +1,22 @@
1
+ --- LICENSE ---
2
+ The MIT License
3
+
4
+ Copyright (c) 2011-2019 C2FO
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
@@ -0,0 +1,22 @@
1
+ --- LICENSE ---
2
+ The MIT License
3
+
4
+ Copyright (c) 2011-2019 C2FO
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
@@ -0,0 +1,326 @@
1
+ --- README.md ---
2
+ # Purpose of this Fork
3
+ This project is a fork of https://github.com/foliojs/fontkit created for use in https://github.com/Hopding/pdf-lib.
4
+
5
+ Listed below are changes that have been made in this fork:
6
+
7
+ * Store binary data as compressed base64 JSON so the `fs` module isn't needed to read it back:
8
+ * [968e35c](https://github.com/Hopding/fontkit/commit/968e35c158589294e9543818f56d0b229b95a475)
9
+ * [99a35c7](/Hopding/fontkit/commit/99a35c7b0f0f6549d7727bcbc1ddabb7f9ca19bf)
10
+ * [2f1445d](/Hopding/fontkit/commit/2f1445d9a3f8426bc259690819eea8306a98545a)
11
+ * [f674bf2-R24](https://github.com/Hopding/fontkit/commit/f674bf2e3c8a8e0a34083e19f0abe65df20520e3#diff-b61f8676a8a37c519e9c3c86c4676208R24), [f674bf2-R13](https://github.com/Hopding/fontkit/commit/f674bf2e3c8a8e0a34083e19f0abe65df20520e3#diff-a73febb5d14ad8d9d7ab6ac378a698aaR13)
12
+ * Rewrote `Makefile` to `Makefile.js` using `shelljs`:
13
+ * [a246e7f](https://github.com/Hopding/fontkit/commit/a246e7fda8c0bb5df4be355a993e0ba59f07300e)
14
+ * Update to Babel 7:
15
+ * [70049f8](https://github.com/Hopding/fontkit/commit/70049f8f038145cc0caca83c75e0b76f49d11f52)
16
+ * [8d5b29b](https://github.com/Hopding/fontkit/commit/8d5b29bd00b752a6ab9348e6be1997e201055d31)
17
+ * Build UMD modules:
18
+ * [cce995c](https://github.com/Hopding/fontkit/commit/cce995c3378c35b247ed2965e15eb92ffad9ea09)
19
+ * [08cacef](https://github.com/Hopding/fontkit/commit/08cacefa3e745f83a2c95051e38985b02aa2f16d)
20
+ * Build ES modules:
21
+ * [dbe8e9d](https://github.com/Hopding/fontkit/commit/dbe8e9da4e8f2e23f507ba5a767a8109e81fb7ab)
22
+ * [9363d1f](https://github.com/Hopding/fontkit/commit/9363d1f8e97985d8a94ee6dac1fac39631ee3c77)
23
+ * Bundle Node dependencies (`stream`, `util`, `Buffer`) into UMD and ES modules so consumers of this lib don't have to deal with them:
24
+ * [9363d1f](https://github.com/Hopding/fontkit/commit/9363d1f8e97985d8a94ee6dac1fac39631ee3c77)
25
+ * Accept `Uint8Array` objects for font data instead of `Buffer` objects, so consumers can stick to plain JS regardless of their environment:
26
+ * [9363d1f-R12](https://github.com/Hopding/fontkit/commit/9363d1f8e97985d8a94ee6dac1fac39631ee3c77#diff-d7e697eff3913f1acaacac8002c3b05eR12)
27
+ * Add TypeScript declaration file:
28
+ * [387ebc4](https://github.com/Hopding/fontkit/commit/387ebc418cc04be51d82d39e05f4db01b1bf063f)
29
+ * [3bafdbc](https://github.com/Hopding/fontkit/commit/3bafdbc3656ebba5251f8d4dc77dcc4b6c11afa6)
30
+ * [b0241e7](https://github.com/Hopding/fontkit/commit/b0241e7c30cdb83bda6867aa8c9229c1ab1cb8e3)
31
+ * Remove calls to `new Function()` to allow usage on CSP sites:
32
+ * [e3dcc8a](https://github.com/Hopding/fontkit/commit/e3dcc8aad014081b8106c47d89049ba9e6f3dd48)
33
+ * Released to NPM as `@pdf-lib/fontkit`
34
+ * [873b05d](https://github.com/Hopding/fontkit/commit/873b05d23aecb9f0142fc3ebda593fd2a7d81c17)
35
+
36
+ Also see
37
+ * https://github.com/Hopding/unicode-properties
38
+ * https://github.com/Hopding/brotli.js
39
+ * https://github.com/Hopding/restructure
40
+ * https://github.com/Hopding/png-ts
41
+
42
+ # fontkit
43
+
44
+ Fontkit is an advanced font engine for Node and the browser, used by [PDFKit](https://github.com/devongovett/pdfkit) and [`pdf-lib`](https://github.com/Hopding/pdf-lib). It supports many font formats, advanced glyph substitution and layout features, glyph path extraction, color emoji glyphs, font subsetting, and more.
45
+
46
+ ## Features
47
+
48
+ * Suports TrueType (.ttf), OpenType (.otf), WOFF, WOFF2, TrueType Collection (.ttc), and Datafork TrueType (.dfont) font files
49
+ * Supports mapping characters to glyphs, including support for ligatures and other advanced substitutions (see below)
50
+ * Supports reading glyph metrics and laying out glyphs, including support for kerning and other advanced layout features (see below)
51
+ * Advanced OpenType features including glyph substitution (GSUB) and positioning (GPOS)
52
+ * Apple Advanced Typography (AAT) glyph substitution features (morx table)
53
+ * Support for getting glyph vector paths and converting them to SVG paths, or rendering them to a graphics context
54
+ * Supports TrueType (glyf) and PostScript (CFF) outlines
55
+ * Support for color glyphs (e.g. emoji), including Apple’s SBIX table, and Microsoft’s COLR table
56
+ * Support for AAT variation glyphs, allowing for nearly infinite design control over weight, width, and other axes.
57
+ * Font subsetting support - create a new font including only the specified glyphs
58
+
59
+ ## Example
60
+
61
+ ```js
62
+ import fontkit from '@pdf-lib/fontkit';
63
+ import fs from 'fs';
64
+
65
+ // open a font synchronously
66
+ const fontData = fs.readFileSync('font.ttf');
67
+ const font = fontkit.create(fontData);
68
+
69
+ // layout a string, using default shaping features.
70
+ // returns a GlyphRun, describing glyphs and positions.
71
+ const run = font.layout('hello world!');
72
+
73
+ // get an SVG path for a glyph
74
+ const svg = run.glyphs[0].path.toSVG();
75
+
76
+ // create a font subset
77
+ const subset = font.createSubset();
78
+ run.glyphs.forEach(function(glyph) {
79
+ subset.includeGlyph(glyph);
80
+ });
81
+
82
+ subset.encodeStream()
83
+ .pipe(fs.createWriteStream('subset.ttf'));
84
+ ```
85
+
86
+ ## Installation
87
+ ### NPM Module
88
+ To install the latest stable version:
89
+ ```bash
90
+ # With npm
91
+ npm install --save @pdf-lib/fontkit
92
+
93
+ # With yarn
94
+ yarn add @pdf-lib/fontkit
95
+ ```
96
+ This assumes you're using [npm](https://www.npmjs.com/) or [yarn](https://yarnpkg.com/lang/en/) as your package manager.
97
+
98
+ ### UMD Module
99
+ You can also download `@pdf-lib/fontkit` as a UMD module from [unpkg](https://unpkg.com/#/). The UMD builds have been compiled to ES5, so they should work [in any modern browser](https://caniuse.com/#feat=es5). UMD builds are useful if you aren't using a package manager or module bundler. For example, you can use them directly in the `<script>` tag of an HTML page.
100
+
101
+ The following builds are available:
102
+
103
+ * https://unpkg.com/@pdf-lib/fontkit/dist/fontkit.umd.js
104
+ * https://unpkg.com/@pdf-lib/fontkit/dist/fontkit.umd.min.js
105
+
106
+ When using a UMD build, you will have access to a global `window.fontkit` variable. This variable contains the object exported by `@pdf-lib/fontkit`. For example:
107
+
108
+ ```javascript
109
+ // NPM module
110
+ import fontkit from '@pdf-lib/fontkit';
111
+
112
+ // UMD module
113
+ var fontkit = window.fontkit;
114
+ ```
115
+
116
+ ## API
117
+
118
+ ### `fontkit.create(buffer, postscriptName = null)`
119
+
120
+ Returns a font object for the given buffer. For collection fonts (such as TrueType collection files), you can pass a `postscriptName` to get that font out of the collection instead of a collection object.
121
+
122
+ ## Font objects
123
+
124
+ There are several different types of font objects that are returned by fontkit depending on the font format. They all inherit from the `TTFFont` class and have the same public API, described below.
125
+
126
+ ### Metadata properties
127
+
128
+ The following properties are strings (or null if the font does not contain strings for them) describing the font, as specified by the font creator.
129
+
130
+ * `postscriptName`
131
+ * `fullName`
132
+ * `familyName`
133
+ * `subfamilyName`
134
+ * `copyright`
135
+ * `version`
136
+
137
+ ### Metrics
138
+
139
+ The following properties describe the general metrics of the font. See [here](http://www.freetype.org/freetype2/docs/glyphs/glyphs-3.html) for a good overview of how all of these properties relate to one another.
140
+
141
+ * `unitsPerEm` - the size of the font’s internal coordinate grid
142
+ * `ascent` - the font’s [ascender](http://en.wikipedia.org/wiki/Ascender_(typography))
143
+ * `descent` - the font’s [descender](http://en.wikipedia.org/wiki/Descender)
144
+ * `lineGap` - the amount of space that should be included between lines
145
+ * `underlinePosition` - the offset from the normal underline position that should be used
146
+ * `underlineThickness` - the weight of the underline that should be used
147
+ * `italicAngle` - if this is an italic font, the angle the cursor should be drawn at to match the font design
148
+ * `capHeight` - the height of capital letters above the baseline. See [here](http://en.wikipedia.org/wiki/Cap_height) for more details.
149
+ * `xHeight`- the height of lower case letters. See [here](http://en.wikipedia.org/wiki/X-height) for more details.
150
+ * `bbox` - the font’s bounding box, i.e. the box that encloses all glyphs in the font
151
+
152
+ ### Other properties
153
+
154
+ * `numGlyphs` - the number of glyphs in the font
155
+ * `characterSet` - an array of all of the unicode code points supported by the font
156
+ * `availableFeatures` - an array of all [OpenType feature tags](https://www.microsoft.com/typography/otspec/featuretags.htm) (or mapped AAT tags) supported by the font (see below for a description of this)
157
+
158
+ ### Character to glyph mapping
159
+
160
+ Fontkit includes several methods for character to glyph mapping, including support for advanced OpenType and AAT substitutions.
161
+
162
+ #### `font.glyphForCodePoint(codePoint)`
163
+
164
+ Maps a single unicode code point (number) to a Glyph object. Does not perform any advanced substitutions (there is no context to do so).
165
+
166
+ #### `font.hasGlyphForCodePoint(codePoint)`
167
+
168
+ Returns whether there is glyph in the font for the given unicode code point.
169
+
170
+ #### `font.glyphsForString(string)`
171
+
172
+ This method returns an array of Glyph objects for the given string. This is only a one-to-one mapping from characters
173
+ to glyphs. For most uses, you should use `font.layout` (described below), which provides a much more advanced mapping
174
+ supporting AAT and OpenType shaping.
175
+
176
+ ### Glyph metrics and layout
177
+
178
+ Fontkit includes several methods for accessing glyph metrics and performing layout, including support for kerning and other advanced OpenType positioning adjustments.
179
+
180
+ #### `font.widthOfGlyph(glyph_id)`
181
+
182
+ Returns the advance width (described above) for a single glyph id.
183
+
184
+ #### `font.layout(string, features = [])`
185
+
186
+ This method returns a `GlyphRun` object, which includes an array of `Glyph`s and `GlyphPosition`s for the given string.
187
+ `Glyph` objects are described below. `GlyphPosition` objects include 4 properties: `xAdvance`, `yAdvance`, `xOffset`,
188
+ and `yOffset`.
189
+
190
+ The `features` parameter is an array of [OpenType feature tags](https://www.microsoft.com/typography/otspec/featuretags.htm) to be applied
191
+ in addition to the default set. If this is an AAT font, the OpenType feature tags are mapped to AAT features.
192
+
193
+ ### Variation fonts
194
+
195
+ Fontkit has support for AAT variation fonts, where glyphs can adjust their shape according to user defined settings along
196
+ various axes including weight, width, and slant. Font designers specify the minimum, default, and maximum values for each
197
+ axis they support, and allow the user fine grained control over the rendered text.
198
+
199
+ #### `font.variationAxes`
200
+
201
+ Returns an object describing the available variation axes. Keys are 4 letter axis tags, and values include `name`,
202
+ `min`, `default`, and `max` properties for the axis.
203
+
204
+ #### `font.namedVariations`
205
+
206
+ The font designer may have picked out some variations that they think look particularly good, for example a light, regular,
207
+ and bold weight which would traditionally be separate fonts. This property returns an object describing these named variation
208
+ instances that the designer has specified. Keys are variation names, and values are objects with axis settings.
209
+
210
+ #### `font.getVariation(variation)`
211
+
212
+ Returns a new font object representing this variation, from which you can get glyphs and perform layout as normal.
213
+ The `variation` parameter can either be a variation settings object or a string variation name. Variation settings objects
214
+ have axis names as keys, and numbers as values (should be in the range specified by `font.variationAxes`).
215
+
216
+ ### Other methods
217
+
218
+ #### `font.getGlyph(glyph_id, codePoints = [])`
219
+
220
+ Returns a glyph object for the given glyph id. You can pass the array of code points this glyph represents for your use later, and it will be stored in the glyph object.
221
+
222
+ #### `font.createSubset()`
223
+
224
+ Returns a Subset object for this font, described below.
225
+
226
+ ## Font Collection objects
227
+
228
+ For font collection files that contain multiple fonts in a single file, such as TrueType Collection (.ttc) and Datafork TrueType (.dfont) files, a font collection object can be returned by Fontkit.
229
+
230
+ ### `collection.getFont(postscriptName)`
231
+
232
+ Gets a font from the collection by its postscript name. Returns a Font object, described above.
233
+
234
+ ### `collection.fonts`
235
+
236
+ This property is a lazily-loaded array of all of the fonts in the collection.
237
+
238
+ ## Glyph objects
239
+
240
+ Glyph objects represent a glyph in the font. They have various properties for accessing metrics and the actual vector path the glyph represents, and methods for rendering the glyph to a graphics context.
241
+
242
+ You do not create glyph objects directly. They are created by various methods on the font object, described above. There are several subclasses of the base `Glyph` class internally that may be returned depending on the font format, but they all include the following API.
243
+
244
+ ### Properties
245
+
246
+ * `id` - the glyph id in the font
247
+ * `codePoints` - an array of unicode code points that are represented by this glyph. There can be multiple code points in the case of ligatures and other glyphs that represent multiple visual characters.
248
+ * `path` - a vector Path object representing the glyph
249
+ * `bbox` - the glyph’s bounding box, i.e. the rectangle that encloses the glyph outline as tightly as possible.
250
+ * `cbox` - the glyph’s control box. This is often the same as the bounding box, but is faster to compute. Because of the way bezier curves are defined, some of the control points can be outside of the bounding box. Where `bbox` takes this into account, `cbox` does not. Thus, `cbox` is less accurate, but faster to compute. See [here](http://www.freetype.org/freetype2/docs/glyphs/glyphs-6.html#section-2) for a more detailed description.
251
+ * `advanceWidth` - the glyph’s advance width.
252
+
253
+ ### `glyph.render(ctx, size)`
254
+
255
+ Renders the glyph to the given graphics context, at the specified font size.
256
+
257
+ ### Color glyphs (e.g. emoji)
258
+
259
+ Fontkit has support for several different color emoji font formats. Currently, these include Apple’s SBIX table (as used by the “Apple Color Emoji” font), and Microsoft’s COLR table (supported by Windows 8.1). [Here](http://blog.symbolset.com/multicolor-fonts) is an overview of the various color font formats out there.
260
+
261
+ #### `glyph.getImageForSize(size)`
262
+
263
+ For SBIX glyphs, which are bitmap based, this returns an object containing some properties about the image, along with the image data itself (usually PNG).
264
+
265
+ #### `glyph.layers`
266
+
267
+ For COLR glyphs, which are vector based, this returns an array of objects representing the glyphs and colors for each layer in render order.
268
+
269
+ ## Path objects
270
+
271
+ Path objects are returned by glyphs and represent the actual vector outlines for each glyph in the font. Paths can be converted to SVG path data strings, or to functions that can be applied to render the path to a graphics context.
272
+
273
+ ### `path.moveTo(x, y)`
274
+
275
+ Moves the virtual pen to the given x, y coordinates.
276
+
277
+ ### `path.lineTo(x, y)`
278
+
279
+ Adds a line to the path from the current point to the given x, y coordinates.
280
+
281
+ ### `path.quadraticCurveTo(cpx, cpy, x, y)`
282
+
283
+ Adds a quadratic curve to the path from the current point to the given x, y coordinates using cpx, cpy as a control point.
284
+
285
+ ### `path.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y)`
286
+
287
+ Adds a bezier curve to the path from the current point to the given x, y coordinates using cp1x, cp1y and cp2x, cp2y as control points.
288
+
289
+ ### `path.closePath()`
290
+
291
+ Closes the current sub-path by drawing a straight line back to the starting point.
292
+
293
+ ### `path.toFunction()`
294
+
295
+ Compiles the path to a JavaScript function that can be applied with a graphics context in order to render the path.
296
+
297
+ ### `path.toSVG()`
298
+
299
+ Converts the path to an SVG path data string.
300
+
301
+ ### `path.bbox`
302
+
303
+ This property represents the path’s bounding box, i.e. the smallest rectangle that contains the entire path shape. This is the exact bounding box, taking into account control points that may be outside the visible shape.
304
+
305
+ ### `path.cbox`
306
+
307
+ This property represents the path’s control box. It is like the bounding box, but it includes all points of the path, including control points of bezier segments. It is much faster to compute than the real bounding box, but less accurate if there are control points outside of the visible shape.
308
+
309
+ ## Subsets
310
+
311
+ Fontkit can perform font subsetting, i.e. the process of creating a new font from an existing font where only the specified glyphs are included. This is useful to reduce the size of large fonts, such as in PDF generation or for web use.
312
+
313
+ Currently, subsets produce minimal fonts designed for PDF embedding that may not work as standalone files. They have no cmap tables and other essential tables for standalone use. This limitation will be removed in the future.
314
+
315
+ You create a Subset object by calling `font.createSubset()`, described above. The API on Subset objects is as follows.
316
+
317
+ ### `subset.includeGlyph(glyph)`
318
+
319
+ Includes the given glyph object or glyph ID in the subset.
320
+
321
+ ### `subset.encodeStream()`
322
+
323
+ Returns a [stream](https://nodejs.org/api/stream.html) containing the encoded font file that can be piped to a destination, such as a file.
324
+
325
+ ## License
326
+ [MIT](https://choosealicense.com/licenses/mit/)
@@ -0,0 +1,22 @@
1
+ --- LICENSE.md ---
2
+ MIT License
3
+
4
+ Copyright (c) 2018 Andrew Dillon
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
@@ -0,0 +1,22 @@
1
+ --- LICENSE ---
2
+ MIT License
3
+
4
+ Copyright (c) 2017 Photopea
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
@@ -0,0 +1,22 @@
1
+ --- LICENSE ---
2
+ MIT License
3
+
4
+ Copyright (c) Microsoft Corporation.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE
@@ -0,0 +1,22 @@
1
+ --- LICENSE ---
2
+ MIT License
3
+
4
+ Copyright (c) Microsoft Corporation.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE
@@ -0,0 +1,22 @@
1
+ --- LICENSE ---
2
+ MIT License
3
+
4
+ Copyright (c) Microsoft Corporation.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE