@silurus/ooxml 0.81.0 → 0.82.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.
- package/README.md +4 -8
- package/dist/assets/render-worker-7-Zr7fSw.js +10 -0
- package/dist/assets/{render-worker-C2ACcLes.js → render-worker-B5gsW6b5.js} +4 -4
- package/dist/assets/{render-worker-DtU8oQZ7.js → render-worker-Dw_wQRIh.js} +1 -1
- package/dist/{canvas-viewer-mechanics-CqxKRGCp.js → canvas-viewer-mechanics-CS_qbr6T.js} +1 -1
- package/dist/chart-ex.mjs +4 -4
- package/dist/comment-occurrence-C34fWs_F.js +6 -0
- package/dist/comment-ui-runtime-BAe30Ct9.js +112 -0
- package/dist/comment-ui-runtime-BUCj4hWn.js +171 -0
- package/dist/comment-ui-runtime-F4a3te6p.js +2 -0
- package/dist/comments-Cf9W7r3M.js +241 -0
- package/dist/{document-pull-client-Ux4a_ax8.js → document-pull-client-BCgmytqI.js} +2205 -2192
- package/dist/{docx-SEyQ4gS-.js → docx-wokGKYfi.js} +674 -249
- package/dist/docx.mjs +6 -5
- package/dist/docx_parser_bg.wasm +0 -0
- package/dist/dom-interaction-boundary-C8F6HO5x.js +119 -0
- package/dist/highlight-rect-MaCt0om0.js +13 -0
- package/dist/index.mjs +3 -3
- package/dist/{line-distribute-BBGvvwLt.js → line-distribute-iXsUCIH-.js} +2 -2
- package/dist/{line-metrics-Baz31mML.js → line-metrics-B3syvDn2.js} +52 -52
- package/dist/math.mjs +2 -2
- package/dist/node.mjs +10 -10
- package/dist/{plot-area-frame-Dg1VIpUU.js → plot-area-frame-DHV02PJU.js} +591 -590
- package/dist/{pptx-5lQrMvMR.js → pptx-DU8L8I2T.js} +537 -243
- package/dist/pptx.mjs +6 -6
- package/dist/pptx_parser_bg.wasm +0 -0
- package/dist/read-only-comment-decoration-DcFevX_Q.js +96 -0
- package/dist/read-only-comment-margin-Dn2y55W6.js +189 -0
- package/dist/region-map.mjs +2 -2
- package/dist/{render-DEHjijQD.js → render-CenWM4g1.js} +1 -1
- package/dist/{render-worker-host-Dg_74V64.js → render-worker-host-BNENN3qP.js} +1 -1
- package/dist/{render-worker-host-B1nbV_k7.js → render-worker-host-BmH3kGSj.js} +1 -1
- package/dist/{render-worker-host-Bze5M6k5.js → render-worker-host-CmPBviYJ.js} +1 -1
- package/dist/{renderer-DuopJE1K.js → renderer-CYr9YTXM.js} +436 -435
- package/dist/{resource-measurement-DRLp4nFt.js → resource-measurement-CsW4_eYt.js} +2 -2
- package/dist/{session-CNVc3VJ4.js → session-Cky_swUj.js} +3 -3
- package/dist/{slide-pull-client-CzutXnGc.js → slide-pull-client-CqTVFb3W.js} +490 -383
- package/dist/source-key-BklvnEyQ.js +42 -0
- package/dist/{three-d-BYiWCNlz.js → three-d-7MaVzQuZ.js} +48 -47
- package/dist/three-d.mjs +324 -323
- package/dist/types/chart-ex.d.ts +2 -2
- package/dist/types/docx.d.ts +181 -19
- package/dist/types/index.d.ts +337 -26
- package/dist/types/math.d.ts +1 -1
- package/dist/types/node.d.ts +84 -10
- package/dist/types/pptx.d.ts +130 -11
- package/dist/types/region-map.d.ts +2 -2
- package/dist/types/three-d.d.ts +2 -2
- package/dist/types/xlsx.d.ts +76 -10
- package/dist/units-BzZ0gAxs.js +4 -0
- package/dist/{worksheet-pull-client-Cxj3Ej0s.js → worksheet-pull-client-CYtwXP5D.js} +3 -3
- package/dist/{xlsx-Bl3TIEVu.js → xlsx-DlV37-0j.js} +429 -218
- package/dist/xlsx.mjs +6 -6
- package/dist/xlsx_parser_bg.wasm +0 -0
- package/package.json +1 -1
- package/dist/assets/render-worker-Cx5uR77k.js +0 -10
- package/dist/highlight-rect-BqcZMHUE.js +0 -48
- /package/dist/{mathjax-DJa-Q93p.js → mathjax-DwIrafQ6.js} +0 -0
- /package/dist/{renderer-module-contract-0bO_5SC0.js → renderer-module-contract-DLbb7zY0.js} +0 -0
- /package/dist/{transfer-D0U6Uhn4.js → transfer-R6NjgBKD.js} +0 -0
- /package/dist/{visible-index-DbDuGMCE.js → visible-index-BFE3PWiY.js} +0 -0
|
@@ -1,31 +1,35 @@
|
|
|
1
1
|
import { t as e } from "./chunk-DmhlhrBa.js";
|
|
2
|
-
import { B as t, Ct as n, Et as r, Jt as i, R as a, Yt as o, a as s, it as c, mt as l, q as u, z as d } from "./line-metrics-
|
|
3
|
-
import { C as f, E as p, S as m, T as h, _ as g, a as _, b as
|
|
4
|
-
import { a as
|
|
5
|
-
import { C as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { n as
|
|
2
|
+
import { B as t, Ct as n, Et as r, Jt as i, R as a, Yt as o, a as s, it as c, mt as l, q as u, z as d } from "./line-metrics-B3syvDn2.js";
|
|
3
|
+
import { C as f, E as p, S as m, T as h, _ as g, a as _, b as ee, c as v, d as y, f as te, g as ne, h as re, i as b, l as x, m as ie, n as ae, o as oe, p as se, r as ce, s as le, t as ue, u as de, v as fe, w as pe, x as me, y as S } from "./canvas-viewer-mechanics-CS_qbr6T.js";
|
|
4
|
+
import { a as he, c as ge, i as _e, o as ve, r as ye, s as be, t as xe } from "./bounded-raw-part-cache-C6ro6Ezf.js";
|
|
5
|
+
import { C, E as Se, S as w, T as Ce, _ as T, a as we, b as Te, c as Ee, d as De, f as Oe, g as ke, h as Ae, l as je, m as Me, n as Ne, o as Pe, p as Fe, s as Ie, t as Le, v as Re, w as ze, x as Be, y as E } from "./document-pull-client-BCgmytqI.js";
|
|
6
|
+
import { cn as Ve, ln as He } from "./plot-area-frame-DHV02PJU.js";
|
|
7
|
+
import { a as D } from "./units-BzZ0gAxs.js";
|
|
8
|
+
import { n as Ue } from "./renderer-module-contract-DLbb7zY0.js";
|
|
9
|
+
import { a as We, i as O, n as Ge, t as Ke } from "./dom-interaction-boundary-C8F6HO5x.js";
|
|
10
|
+
import { n as qe, t as k } from "./highlight-rect-MaCt0om0.js";
|
|
11
|
+
import { o as A } from "./source-key-BklvnEyQ.js";
|
|
12
|
+
import { i as Je, n as j, r as M, t as Ye } from "./comments-Cf9W7r3M.js";
|
|
9
13
|
//#region packages/core/src/fonts/embedded.ts
|
|
10
|
-
function
|
|
11
|
-
let n =
|
|
14
|
+
function Xe(e, t) {
|
|
15
|
+
let n = Ze(t), r = e.slice(), i = Math.min(32, r.length);
|
|
12
16
|
for (let e = 0; e < i; e++) r[e] ^= n[e % 16];
|
|
13
17
|
return r;
|
|
14
18
|
}
|
|
15
|
-
function
|
|
19
|
+
function Ze(e) {
|
|
16
20
|
let t = e.replace(/[{}\-\s]/g, "");
|
|
17
21
|
if (t.length !== 32 || /[^0-9a-fA-F]/.test(t)) throw Error(`invalid fontKey GUID: ${e}`);
|
|
18
22
|
let n = new Uint8Array(16);
|
|
19
23
|
for (let e = 0; e < 16; e++) n[e] = parseInt(t.slice(e * 2, e * 2 + 2), 16);
|
|
20
24
|
return n.reverse();
|
|
21
25
|
}
|
|
22
|
-
function
|
|
26
|
+
function Qe(e, t, n, r) {
|
|
23
27
|
let i = 2166136261;
|
|
24
28
|
for (let e = 0; e < r.length; e++) i ^= r[e], i = Math.imul(i, 16777619);
|
|
25
29
|
return `${e}|${t}|${n}|${r.length}|${(i >>> 0).toString(16)}`;
|
|
26
30
|
}
|
|
27
|
-
async function
|
|
28
|
-
let n =
|
|
31
|
+
async function $e(e, t = 30 * 1024 * 1024) {
|
|
32
|
+
let n = ye();
|
|
29
33
|
if (!n || typeof FontFace > "u") return [];
|
|
30
34
|
let r = [], i = [], a = [];
|
|
31
35
|
for (let o of e) try {
|
|
@@ -33,7 +37,7 @@ async function He(e, t = 30 * 1024 * 1024) {
|
|
|
33
37
|
a.push(o.family);
|
|
34
38
|
continue;
|
|
35
39
|
}
|
|
36
|
-
let e = o.odttf ?
|
|
40
|
+
let e = o.odttf ? Xe(o.bytes, o.fontKey ?? "") : o.bytes, { face: s, isNew: c } = ge(`embedded:${Qe(o.family, o.weight, o.style, e)}`, n, () => {
|
|
37
41
|
let t = e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength), r = new FontFace(o.family, t, {
|
|
38
42
|
weight: o.weight,
|
|
39
43
|
style: o.style
|
|
@@ -44,20 +48,20 @@ async function He(e, t = 30 * 1024 * 1024) {
|
|
|
44
48
|
} catch {
|
|
45
49
|
a.push(o.family);
|
|
46
50
|
}
|
|
47
|
-
return i.length > 0 && await
|
|
51
|
+
return i.length > 0 && await ve(Promise.allSettled(i.map((e) => e.load())).then((e) => (e.forEach((e, t) => {
|
|
48
52
|
e.status === "rejected" && a.push(i[t].family);
|
|
49
53
|
}), n.ready))), a.length > 0 && console.warn(`[ooxml] failed to register embedded font(s): ${[...new Set(a)].join(", ")}; falling back to substitute fonts (text may shift or differ).`), r;
|
|
50
54
|
}
|
|
51
|
-
function
|
|
52
|
-
|
|
55
|
+
function et(e) {
|
|
56
|
+
be(e);
|
|
53
57
|
}
|
|
54
58
|
//#endregion
|
|
55
59
|
//#region packages/docx/src/worker.ts?worker&inline
|
|
56
|
-
var P = "var e=(e,t)=>()=>(e&&(t=e(e=0)),t),t=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,r.unregister(this),e}free(){let e=this.__destroy_into_raw();_.__wbg_docxarchive_free(e,0)}acknowledge_document_chunk(e,t,n){let r=_.docxarchive_acknowledge_document_chunk(this.__wbg_ptr,e,t,n);if(r[1])throw f(r[0])}assert_healthy(){let e=_.docxarchive_assert_healthy(this.__wbg_ptr);if(e[1])throw f(e[0])}cancel_document_cursor(){_.docxarchive_cancel_document_cursor(this.__wbg_ptr)}close_document_session(){_.docxarchive_close_document_session(this.__wbg_ptr)}document_chunk_done(){let e=_.docxarchive_document_chunk_done(this.__wbg_ptr);if(e[2])throw f(e[1]);return e[0]!==0}document_cursor_resource_usage(){let e=_.docxarchive_document_cursor_resource_usage(this.__wbg_ptr);if(e[3])throw f(e[2]);var t=i(e[0],e[1]).slice();return _.__wbindgen_free(e[0],e[1]*1,1),t}extract_image(e){let t=d(e,_.__wbindgen_malloc,_.__wbindgen_realloc),n=g,r=_.docxarchive_extract_image(this.__wbg_ptr,t,n);if(r[3])throw f(r[2]);var a=i(r[0],r[1]).slice();return _.__wbindgen_free(r[0],r[1]*1,1),a}constructor(e,t,n,i){let a=ee(e,_.__wbindgen_malloc),o=g,s=_.docxarchive_new(a,o,!u(t),u(t)?BigInt(0):t,!u(n),u(n)?BigInt(0):n,!u(i),u(i)?BigInt(0):i);if(s[2])throw f(s[1]);return this.__wbg_ptr=s[0]>>>0,r.register(this,this.__wbg_ptr,this),this}open_document_cursor(e,t){let n=_.docxarchive_open_document_cursor(this.__wbg_ptr,e,t);if(n[1])throw f(n[0])}parse(){let e=_.docxarchive_parse(this.__wbg_ptr);if(e[3])throw f(e[2]);var t=i(e[0],e[1]).slice();return _.__wbindgen_free(e[0],e[1]*1,1),t}pull_document_chunk(e,t,n,r){let a=_.docxarchive_pull_document_chunk(this.__wbg_ptr,e,t,n,r);if(a[3])throw f(a[2]);var o=i(a[0],a[1]).slice();return _.__wbindgen_free(a[0],a[1]*1,1),o}resource_usage(){let e=_.docxarchive_resource_usage(this.__wbg_ptr);if(e[3])throw f(e[2]);var t=i(e[0],e[1]).slice();return _.__wbindgen_free(e[0],e[1]*1,1),t}to_markdown(){let e,t;try{let i=_.docxarchive_to_markdown(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,f(i[2]);return e=n,t=r,s(n,r)}finally{_.__wbindgen_free(e,t,1)}}};Symbol.dispose&&(t.prototype[Symbol.dispose]=t.prototype.free);function n(){return{__proto__:null,\"./docx_parser_bg.js\":{__proto__:null,__wbg___wbindgen_throw_6b64449b9b9ed33c:function(e,t){throw Error(s(e,t))},__wbg_error_a6fa202b58aa1cd3:function(e,t){let n,r;try{n=e,r=t,console.error(s(e,t))}finally{_.__wbindgen_free(n,r,1)}},__wbg_new_227d7c05414eb861:function(){return Error()},__wbg_stack_3b0d974bbf31e44f:function(e,t){let n=t.stack,r=d(n,_.__wbindgen_malloc,_.__wbindgen_realloc),i=g;o().setInt32(e+4,i,!0),o().setInt32(e+0,r,!0)},__wbindgen_cast_0000000000000001:function(e,t){return s(e,t)},__wbindgen_init_externref_table:function(){let e=_.__wbindgen_externrefs,t=e.grow(4);e.set(0,void 0),e.set(t+0,void 0),e.set(t+1,null),e.set(t+2,!0),e.set(t+3,!1)}}}}const r=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>_.__wbg_docxarchive_free(e>>>0,1));function i(e,t){return e>>>=0,l().subarray(e/1,e/1+t)}let a=null;function o(){return(a===null||a.buffer.detached===!0||a.buffer.detached===void 0&&a.buffer!==_.memory.buffer)&&(a=new DataView(_.memory.buffer)),a}function s(e,t){return e>>>=0,te(e,t)}let c=null;function l(){return(c===null||c.byteLength===0)&&(c=new Uint8Array(_.memory.buffer)),c}function u(e){return e==null}function ee(e,t){let n=t(e.length*1,1)>>>0;return l().set(e,n/1),g=e.length,n}function d(e,t,n){if(n===void 0){let n=h.encode(e),r=t(n.length,1)>>>0;return l().subarray(r,r+n.length).set(n),g=n.length,r}let r=e.length,i=t(r,1)>>>0,a=l(),o=0;for(;o<r;o++){let t=e.charCodeAt(o);if(t>127)break;a[i+o]=t}if(o!==r){o!==0&&(e=e.slice(o)),i=n(i,r,r=o+e.length*3,1)>>>0;let t=l().subarray(i+o,i+r),a=h.encodeInto(e,t);o+=a.written,i=n(i,r,o,1)>>>0}return g=o,i}function f(e){let t=_.__wbindgen_externrefs.get(e);return _.__externref_table_dealloc(e),t}let p=new TextDecoder(`utf-8`,{ignoreBOM:!0,fatal:!0});p.decode();let m=0;function te(e,t){return m+=t,m>=2146435072&&(p=new TextDecoder(`utf-8`,{ignoreBOM:!0,fatal:!0}),p.decode(),m=t),p.decode(l().subarray(e,e+t))}const h=new TextEncoder;`encodeInto`in h||(h.encodeInto=function(e,t){let n=h.encode(e);return t.set(n),{read:e.length,written:n.length}});let g=0,_;function v(e,t){return _=e.exports,a=null,c=null,_.__wbindgen_start(),_}async function y(e,t){if(typeof Response==`function`&&e instanceof Response){if(typeof WebAssembly.instantiateStreaming==`function`)try{return await WebAssembly.instantiateStreaming(e,t)}catch(t){if(e.ok&&n(e.type)&&e.headers.get(`Content-Type`)!==`application/wasm`)console.warn(\"`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\\n\",t);else throw t}let r=await e.arrayBuffer();return await WebAssembly.instantiate(r,t)}else{let n=await WebAssembly.instantiate(e,t);return n instanceof WebAssembly.Instance?{instance:n,module:e}:n}function n(e){switch(e){case`basic`:case`cors`:case`default`:return!0}return!1}}async function b(e){if(_!==void 0)return _;e!==void 0&&(Object.getPrototypeOf(e)===Object.prototype?{module_or_path:e}=e:console.warn(`using deprecated parameters for the initialization function; pass a single object instead`));let t=n();(typeof e==`string`||typeof Request==`function`&&e instanceof Request||typeof URL==`function`&&e instanceof URL)&&(e=fetch(e));let{instance:r,module:i}=await y(await e,t);return v(r,i)}async function ne(e){return _=void 0,a=null,c=null,b(e)}var x=class e extends Error{code;constructor(t,n){super(n),this.name=`OoxmlError`,this.code=t,Object.setPrototypeOf(this,e.prototype)}},S=class e extends Error{code=`ooxml-resource-limit`;details;constructor(t,n){super(t),this.name=`OoxmlResourceLimitError`;let r=n.violation,i=Object.freeze({format:r.format,operation:r.operation,resource:r.resource,metric:r.metric,...r.part===void 0?{}:{part:r.part},limit:r.limit,observed:r.observed,configurable:r.configurable,usage:Object.freeze({archiveEntryCount:r.usage.archiveEntryCount,declaredInflatedBytes:r.usage.declaredInflatedBytes,...r.usage.largestInflatedEntryBytes===void 0?{}:{largestInflatedEntryBytes:r.usage.largestInflatedEntryBytes},distinctInflatedBytes:r.usage.distinctInflatedBytes,operationInflatedBytes:r.usage.operationInflatedBytes})});this.details=Object.freeze({stage:n.stage,violation:i}),Object.setPrototypeOf(this,e.prototype)}},C,w,re=e((()=>{C=1<<25,C*4,w=class e extends RangeError{code=`ooxml-decoded-image-limit`;constructor(t,n,r){super(`OOXML decoded image limit exceeded: ${t} ${r} > ${n}`),this.metric=t,this.limit=n,this.observed=r,this.name=`OoxmlDecodedImageLimitError`,Object.setPrototypeOf(this,e.prototype)}}}));function ie(e){if(!e.startsWith(`data:`))return null;let t=e.indexOf(`,`);if(t===-1)return null;let n=atob(e.slice(t+1)),r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return r.buffer}var ae=class{state=`uninitialized`;generationValue=0;readiness;poisonListeners=new Set;constructor(e,t,n){this.initialize=e,this.reinitialize=t,this.normalizeFailure=n}get generation(){return this.generationValue}get poisoned(){return this.state===`poisoned`}onPoison(e){return this.poisonListeners.add(e),()=>this.poisonListeners.delete(e)}async ensureReady(){if(this.state!==`ready`){if(!this.readiness){let e=this.state===`uninitialized`?this.initialize:this.reinitialize;this.readiness=Promise.resolve().then(e).then(()=>{this.generationValue+=1,this.state=`ready`,this.readiness=void 0},e=>{throw this.readiness=void 0,e})}await this.readiness}}run(e){try{return e()}catch(e){let t=this.normalizeFailure(e);throw t?(this.poison(t),t):e}}tryRunReady(e){if(this.state!==`ready`)return{current:!1};let t=this.generationValue,n=this.run(e);return this.state!==`ready`||t!==this.generationValue?{current:!1}:{current:!0,generation:t,value:n}}poison(e){this.state=`poisoned`,this.readiness=void 0;for(let t of this.poisonListeners)t(e)}assertCurrent(e){if(this.state!==`ready`||e!==this.generationValue)throw Error(`WASM archive session belongs to a discarded runtime generation`)}},T=class e extends Error{code=`parser-crashed`;constructor(t){super(t),this.name=`WasmTrapError`,Object.setPrototypeOf(this,e.prototype)}};function E(e){let t=globalThis.WebAssembly?.RuntimeError;return t&&e instanceof t||e instanceof RangeError?!0:e instanceof Error?e.name===`RuntimeError`||e.name===`CompileError`||e.name===`LinkError`||e.name===`InternalError`||e.name===`OOMError`:!1}function oe(e){try{if((typeof e!=`object`||!e)&&typeof e!=`function`)return;let t=Reflect.get(e,`__destroy_into_raw`);typeof t==`function`&&Reflect.apply(t,e,[])}catch{}}function se(e,t){return e({module_or_path:t})}var ce=class{runtime;wasmInput=null;currentArchive=null;constructor(e,t={}){this.init=e,this.options=t,this.runtime=new ae(()=>this.invokeConfigured(this.init),()=>this.invokeConfigured(this.options.reinit??this.init),le),this.runtime.onPoison(()=>this.dropPoisonedArchive())}setWasmInput(e){this.wasmInput=e,this.runtime.ensureReady().catch(()=>void 0)}setWasmUrl(e){this.setWasmInput(e)}get archive(){return this.currentArchive}setArchive(e){this.freeArchive(),this.currentArchive=e}disposeArchive(){this.freeArchive()}get poisoned(){return this.runtime.poisoned}async ensureReady(){await this.runtime.ensureReady()}run(e){return this.runtime.run(e)}poison(){this.runtime.poison(new T(`WASM parser was recycled`))}invokeConfigured(e){return this.wasmInput===null?Promise.reject(Error(`WasmParserHost: setWasmInput was never called`)):se(e,this.wasmInput)}freeArchive(){this.currentArchive!==null&&this.options.freeArchive&&this.options.freeArchive(this.currentArchive),this.currentArchive=null}dropPoisonedArchive(){let e=this.currentArchive;this.currentArchive=null,oe(e)}};function le(e){return E(e)?new T(`WASM parser trapped and was recycled: ${e instanceof Error?e.message:String(e)}`):null}function D(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>0}function O(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return D(t.requiredBytes)&&D(t.offeredBytes)&&t.requiredBytes>t.offeredBytes}var k=class e extends RangeError{code=`ooxml-insufficient-credit`;requiredBytes;offeredBytes;constructor(t){super(`Pull unit requires ${t.requiredBytes} bytes but credit is ${t.offeredBytes}`),this.name=`PullSessionInsufficientCreditError`,this.requiredBytes=t.requiredBytes,this.offeredBytes=t.offeredBytes,Object.setPrototypeOf(this,e.prototype)}};function A(e){if(e instanceof k)return e;let t=e instanceof Error?e.message:String(e);if(!t.startsWith(`OOXML_INSUFFICIENT_CREDIT:`))return;let n;try{n=JSON.parse(t.slice(26))}catch{return}if(!n||typeof n!=`object`||Array.isArray(n))return;let r=n;if(!(r.code!==`ooxml-insufficient-credit`||!O(r)))return new k(r)}function ue(e,t,n){let r=A(e);if(!(!r||r.offeredBytes!==t||r.requiredBytes>n))return r}re();const j=`OOXML_RESOURCE_LIMIT:`;function M(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}function N(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return M(t.archiveEntryCount)&&M(t.declaredInflatedBytes)&&(t.largestInflatedEntryBytes===void 0||M(t.largestInflatedEntryBytes))&&M(t.distinctInflatedBytes)&&M(t.operationInflatedBytes)}function P(e){let t;try{t=JSON.parse(new TextDecoder().decode(e))}catch{throw TypeError(`OOXML resource usage checkpoint is not valid JSON`)}if(!N(t))throw TypeError(`OOXML resource usage checkpoint is invalid`);return t}function F(e){return e===`docx`||e===`xlsx`||e===`pptx`}function I(e){return e===`container`||e===`decompression`||e===`parsing`||e===`serialization`||e===`layout`||e===`rendering`||e===`worker`}function L(e,t){return typeof e==`string`&&e.length>0&&e.length<=t&&!/[\\u0000-\\u001f\\u007f]/u.test(e)}function R(e){return L(e,128)&&/^[a-z0-9][a-z0-9-]*$/u.test(e)}function z(e){return!L(e,4096)||e.startsWith(`/`)||e.startsWith(`\\\\`)||e.includes(`\\\\`)||e.includes(`?`)||e.includes(`#`)||e.includes(`://`)||/^[a-z]:/iu.test(e)?!1:e.split(`/`).every(e=>e!==``&&e!==`.`&&e!==`..`)}const B=new Map([[`archive-entry:declared-inflated-bytes`,{stage:`container`,part:`required`}],[`archive-entry:actual-inflated-bytes`,{stage:`decompression`,part:`required`}],[`archive:entry-count`,{stage:`container`,part:`forbidden`}],[`archive:central-directory-bytes`,{stage:`container`,part:`forbidden`,configurable:!1}],[`archive:distinct-inflated-bytes`,{stage:`decompression`,part:`required`}],[`xml-event:bytes`,{stage:`parsing`,part:`optional`,configurable:!1}],[`xml-context:bytes`,{stage:`parsing`,part:`optional`,configurable:!1}],[`xml-tree:depth`,{stage:`parsing`,part:`optional`,configurable:!1}],[`worksheet-row:projected-bytes`,{stage:`parsing`,part:`optional`,configurable:!1}],[`worksheet-shell:projected-bytes`,{stage:`parsing`,part:`optional`,configurable:!1}]]),V=new Set([...B.keys()].map(e=>e.slice(0,e.indexOf(`:`)))),H=new Set([...B.keys()].map(e=>e.slice(e.indexOf(`:`)+1)));function de(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return!F(t.format)||!L(t.operation,256)||!R(t.resource)||!R(t.metric)||!M(t.limit)||!M(t.observed)||typeof t.configurable!=`boolean`||!N(t.usage)?!1:!(`part`in t)||z(t.part)}function U(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;if(!I(t.stage)||!de(t.violation))return!1;let n=t.violation,r=B.get(`${n.resource}:${n.metric}`);return r?t.stage!==r.stage||r.configurable===!1&&n.configurable!==!1?!1:r.part===`required`?n.part!==void 0:r.part===`forbidden`?n.part===void 0:!0:!(V.has(n.resource)&&H.has(n.metric))}function fe(e){return{archiveEntryCount:e.archiveEntryCount,declaredInflatedBytes:e.declaredInflatedBytes,...e.largestInflatedEntryBytes===void 0?{}:{largestInflatedEntryBytes:e.largestInflatedEntryBytes},distinctInflatedBytes:e.distinctInflatedBytes,operationInflatedBytes:e.operationInflatedBytes}}function pe(e){if(!U(e))return;let t=e.violation,n={stage:e.stage,violation:{format:t.format,operation:t.operation,resource:t.resource,metric:t.metric,...t.part===void 0?{}:{part:t.part},limit:t.limit,observed:t.observed,configurable:t.configurable,usage:fe(t.usage)}};return U(n)?n:void 0}function W(e){let t=e.violation;return`OOXML resource limit exceeded${t.part?` for ${t.part}`:``}: ${t.metric} ${t.observed} > ${t.limit}`}function me(e){let t=e instanceof Error?e.message:String(e);if(!t.startsWith(j))return;let n;try{n=JSON.parse(t.slice(21))}catch{return}if(!n||typeof n!=`object`)return;let r=n;if(!(r.code!==`ooxml-resource-limit`||!U(r.details)))return new S(W(r.details),r.details)}function he(e){if(e instanceof w)return{message:e.message,errorName:e.name,code:e.code,decodedImage:{metric:e.metric,limit:e.limit,observed:e.observed}};let t=A(e);if(t)return{message:t.message,errorName:t.name,code:t.code,insufficientCredit:{requiredBytes:t.requiredBytes,offeredBytes:t.offeredBytes}};let n=e instanceof x||e instanceof S?e:me(e);if(n instanceof S){let e=pe(n.details);return e?{message:typeof n.message==`string`?n.message:W(e),errorName:`OoxmlResourceLimitError`,code:`ooxml-resource-limit`,resourceLimit:e}:{message:`Invalid OOXML resource-limit error payload`,errorName:`Error`}}if(n instanceof x)return{message:typeof n.message==`string`?n.message:String(n.message),errorName:L(n.name,128)?n.name:`OoxmlError`,...R(n.code)?{code:n.code}:{}};let r=e instanceof Error?e.message:String(e);if(typeof r==`string`&&r.startsWith(j))return{message:`Invalid OOXML resource-limit payload`,errorName:`Error`};let i=e instanceof Error?e:Error(r),a=i;return{message:typeof i.message==`string`?i.message:String(i.message),errorName:L(i.name,128)?i.name:`Error`,...typeof a.code==`string`?{code:a.code}:{}}}function G(e){try{return he(e)}catch{return{message:`Worker operation failed with an unreadable error`,errorName:`Error`}}}function ge(e){return e.byteOffset===0&&e.byteLength===e.buffer.byteLength&&e.buffer instanceof ArrayBuffer?e.buffer:e.slice().buffer}Object.freeze({maxArchiveEntryBytes:134217728,maxTotalInflatedBytes:268435456,maxArchiveEntries:4096});function _e(e){return[e.maxArchiveEntryBytes===null?0n:BigInt(e.maxArchiveEntryBytes),e.maxTotalInflatedBytes===null?0n:BigInt(e.maxTotalInflatedBytes),e.maxArchiveEntries===null?0n:BigInt(e.maxArchiveEntries)]}const K=`ooxml-pull-v1`;function q(e,t){if(!Number.isSafeInteger(e)||e<=0)throw RangeError(`${t} must be a positive safe integer`)}function ve(e){if(!(typeof e==`string`&&e.length>0||typeof e==`number`&&Number.isSafeInteger(e)&&e>0))throw RangeError(`session id must be a non-empty string or positive safe integer`)}var J=class{owner;queue=Promise.resolve();leases=new Map;retainedBytes=0;retainedCount=0;maxRetainedBytes;maxRetainedCount;cleanups=new Set;pendingFatalCleanups=[];poisonRunning=!1;fatal;constructor(e){this.maxRetainedBytes=e?.maxRetainedBytes??64*1024*1024,this.maxRetainedCount=e?.maxRetainedCount??256,q(this.maxRetainedBytes,`max retained lease bytes`),q(this.maxRetainedCount,`max retained lease count`)}enqueue(e){let t=this.queue.then(e,e);return this.queue=t.then(()=>void 0,()=>void 0),t}acquire(e){return this.owner===void 0?(this.owner=e,!0):this.owner===e}release(e){this.owner===e&&(this.owner=void 0)}retainLease(e,t,n){if(!Number.isSafeInteger(n)||n<0)throw RangeError(`retained lease bytes are invalid`);let r=this.leases.get(e)??new Map;if(r.has(t))throw Error(`driver returned a duplicate lease id`);if(this.retainedCount+1>this.maxRetainedCount)throw RangeError(`retained lease count exceeds limit`);if(this.retainedBytes+n>this.maxRetainedBytes)throw RangeError(`retained lease bytes exceed limit`);r.set(t,n),this.leases.set(e,r),this.retainedCount++,this.retainedBytes+=n}releaseLease(e,t){let n=this.leases.get(e),r=n?.get(t);r!==void 0&&(n?.delete(t),n?.size===0&&this.leases.delete(e),this.retainedCount--,this.retainedBytes-=r)}registerCleanup(e){return this.fatal?(this.poisonRunning?this.pendingFatalCleanups.push(e):this.enqueue(e).catch(()=>void 0),()=>void 0):(this.cleanups.add(e),()=>this.cleanups.delete(e))}get fatalError(){return this.fatal}get registeredHostCount(){return this.cleanups.size}async poison(e){if(this.fatal??=e,this.poisonRunning)return this.fatal;this.poisonRunning=!0,this.pendingFatalCleanups.push(...this.cleanups);try{let e;for(;(e=this.pendingFatalCleanups.shift())!==void 0;)await e().catch(()=>void 0)}finally{this.poisonRunning=!1}return this.fatal}},ye=class{options;coordinator;coordinatorOwner=Symbol(`pull-session-host`);unregisterCleanup;sequence=0;unacked;leases=new Map;activeDriverLeases=new Set;nextWireLeaseId;cancelRequested=!1;cancelComplete=!1;closeRequested=!1;closeComplete=!1;driverCancelComplete=!1;driverCloseComplete=!1;completed=!1;constructor(e){ve(e.sessionId),q(e.operationId,`operation id`),q(e.generation,`generation`),q(e.maxByteCredit,`max byte credit`),e.wireLeaseIdStart!==void 0&&q(e.wireLeaseIdStart,`wire lease id start`),this.options=e,this.coordinator=e.coordinator,this.nextWireLeaseId=e.wireLeaseIdStart??1,this.unregisterCleanup=this.coordinator.registerCleanup(()=>this.forceFatalCleanup())}dispatch(e,t){return this.coordinator.enqueue(async()=>{let n=await this.execute(e);try{t(n.response,n.transfer)}catch(e){throw await this.rollbackFailedPost(n),e}})}async rollbackFailedPost(e){let t=e.response;if(t.kind===`chunk`){let n=t.leaseId===void 0?void 0:this.leases.get(t.leaseId);try{await this.options.driver.disposeInvalidChunk?.({payload:t.payload,byteLength:t.byteLength,done:t.done,leaseId:n?.driverLeaseId,retainedBytes:n?.retainedBytes,transfer:e.transfer})}catch{}}this.unacked=void 0,this.coordinator.release(this.coordinatorOwner);for(let[e,t]of[...this.leases])try{await this.options.driver.releaseLease?.(t.driverLeaseId)}catch{}finally{this.leases.delete(e),this.activeDriverLeases.delete(t.driverLeaseId),this.coordinator.releaseLease(this.coordinatorOwner,e)}if(this.cancelRequested=!0,!this.driverCancelComplete)try{await this.options.driver.cancel?.(),this.driverCancelComplete=!0}catch{}this.unregisterCleanup()}async execute(e){try{if(this.isStaleLifecycle(e)){let t=e.kind===`cancel`?`cancel`:`close`;return this.sameOperationIdentity(e)?{response:this.accepted(e,t,!0)}:{response:this.errorResponse(e,{message:`stale lifecycle targets another session or operation`,errorName:`PullSessionProtocolError`,code:`ooxml-stale-lifecycle`})}}this.validateCommandIdentity(e);let t=this.coordinator.fatalError;if(t)return e.kind===`pull`?{response:this.errorResponse(e,t)}:(e.kind===`cancel`?await this.cancel():e.kind===`close`?await this.close():e.kind===`release`&&await this.release(e.leaseId),{response:this.accepted(e,e.kind)});switch(e.kind){case`pull`:return await this.pull(e);case`ack`:return await this.ack(e.sequence),{response:this.accepted(e,`ack`)};case`release`:return await this.release(e.leaseId),{response:this.accepted(e,`release`)};case`cancel`:return await this.cancel(),{response:this.accepted(e,`cancel`)};case`close`:return await this.close(),{response:this.accepted(e,`close`)}}}catch(t){let n=G(t);return n.code===`ooxml-resource-limit`&&(n=await this.coordinator.poison(n)),{response:this.errorResponse(e,n)}}}async pull(e){if(this.closeRequested||this.cancelRequested||this.completed)throw Error(`pull session is closed`);if(this.unacked)throw Error(`previous chunk is not acknowledged`);if(!Number.isSafeInteger(e.sequence)||e.sequence<0||e.sequence!==this.sequence)throw Error(`pull command sequence mismatch`);if(this.validateHostCredit(e.byteCredit),!this.coordinator.acquire(this.coordinatorOwner))throw Error(`another operation has an unacknowledged package chunk`);let t;try{t=await this.options.driver.pull(e.byteCredit)}catch(e){throw this.coordinator.release(this.coordinatorOwner),e}let n=!1,r=!1,i,a;try{let o=this.options.driver.measureChunk(t),s=this.arrayBufferTransferBytes(t.transfer);if(o<s)throw RangeError(`measured chunk bytes are below ArrayBuffer transfer bytes`);if(a=Math.max(o,s),t.leaseId!==void 0){if(q(t.leaseId,`lease id`),t.retainedBytes===void 0)throw Error(`retained lease bytes are required`);if(this.activeDriverLeases.has(t.leaseId))throw r=!0,Error(`driver returned an active duplicate lease id`);i=this.allocateWireLeaseId(),this.coordinator.retainLease(this.coordinatorOwner,i,t.retainedBytes),this.leases.set(i,{driverLeaseId:t.leaseId,retainedBytes:t.retainedBytes}),this.activeDriverLeases.add(t.leaseId),n=!0}else if(t.retainedBytes!==void 0)throw Error(`retained lease bytes require a lease id`);if(!Number.isSafeInteger(a)||a<0)throw RangeError(`host chunk byte length must be a non-negative safe integer`);if(a>e.byteCredit)throw RangeError(`host chunk exceeds byte credit`)}catch(e){let a;try{await this.options.driver.disposeInvalidChunk?.(t)}catch(e){a=e}if(n&&i!==void 0)try{await this.release(i)}catch(e){a??=e}else if(t.leaseId!==void 0&&!r)try{await this.options.driver.releaseLease?.(t.leaseId)}catch(e){a??=e}if(r)try{await this.cancel()}catch(e){a??=e}throw this.coordinator.release(this.coordinatorOwner),a||e}return this.unacked={sequence:this.sequence,done:t.done},{response:{kind:`chunk`,protocol:K,...this.identity(),requestId:e.requestId,sequence:this.sequence,byteLength:a,done:t.done,payload:t.payload,leaseId:i,usage:this.resourceUsage()},transfer:t.transfer}}async ack(e){if(!Number.isSafeInteger(e)||e<0)throw RangeError(`invalid ack sequence`);if(e<this.sequence)return;if(!this.unacked||e!==this.sequence)throw Error(`ack sequence mismatch`);let t=this.unacked.done;await this.options.driver.acknowledge?.(e),this.unacked=void 0,this.coordinator.release(this.coordinatorOwner),this.sequence++,t&&(this.completed=!0,this.maybeUnregisterCompleted())}async release(e){q(e,`wire lease id`);let t=this.leases.get(e);t&&(await this.options.driver.releaseLease?.(t.driverLeaseId),this.leases.delete(e),this.activeDriverLeases.delete(t.driverLeaseId),this.coordinator.releaseLease(this.coordinatorOwner,e),this.maybeUnregisterCompleted())}async cancel(){if(this.cancelComplete)return;this.cancelRequested=!0,this.unacked=void 0,this.coordinator.release(this.coordinatorOwner);let e;try{await this.releaseAllLeases()}catch(t){e=t}if(!this.driverCancelComplete)try{await this.options.driver.cancel?.(),this.driverCancelComplete=!0}catch(t){e??=t}if(e)throw e;this.cancelComplete=!0,this.unregisterCleanup()}async close(){if(this.closeComplete)return;this.closeRequested=!0,this.unacked=void 0,this.coordinator.release(this.coordinatorOwner);let e;try{await this.releaseAllLeases()}catch(t){e=t}if(!this.driverCloseComplete)try{await this.options.driver.close?.(),this.driverCloseComplete=!0}catch(t){e??=t}if(e)throw e;this.closeComplete=!0,this.unregisterCleanup()}async releaseAllLeases(){let e;for(let t of[...this.leases.keys()])try{await this.release(t)}catch(t){e??=t}if(e)throw e}validateCommandIdentity(e){if(e.protocol!==`ooxml-pull-v1`||e.sessionId!==this.options.sessionId||e.operationId!==this.options.operationId||e.generation!==this.options.generation||!Number.isSafeInteger(e.requestId)||e.requestId<=0)throw Error(`stale or mismatched pull session command`)}validateHostCredit(e){if(q(e,`byte credit`),e>this.options.maxByteCredit)throw RangeError(`byte credit exceeds host maximum`)}accepted(e,t,n=!1){return{kind:`accepted`,protocol:K,...n?{sessionId:e.sessionId,operationId:e.operationId,generation:e.generation}:this.identity(),requestId:e.requestId,command:t,usage:this.resourceUsage()}}identity(){return{sessionId:this.options.sessionId,operationId:this.options.operationId,generation:this.options.generation}}isStaleLifecycle(e){return(e.kind===`cancel`||e.kind===`close`)&&e.protocol===`ooxml-pull-v1`&&Number.isSafeInteger(e.requestId)&&e.requestId>0&&Number.isSafeInteger(e.generation)&&e.generation>0&&e.generation<this.options.generation}sameOperationIdentity(e){return e.sessionId===this.options.sessionId&&e.operationId===this.options.operationId}errorResponse(e,t){return{kind:`error`,protocol:K,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,error:t,usage:this.errorResourceUsage()}}async forceFatalCleanup(){this.cancelRequested=!0,this.unacked=void 0,this.coordinator.release(this.coordinatorOwner);let e;for(let t of[...this.leases.keys()])try{await this.release(t)}catch(t){e??=t}if(!this.driverCancelComplete)try{await this.options.driver.cancel?.(),this.driverCancelComplete=!0}catch(t){e??=t}if(e)throw e;this.unregisterCleanup()}allocateWireLeaseId(){if(!Number.isSafeInteger(this.nextWireLeaseId)||this.nextWireLeaseId<=0)throw RangeError(`wire lease id space exhausted`);return this.nextWireLeaseId++}arrayBufferTransferBytes(e){let t=0;for(let n of e??[])if(n instanceof ArrayBuffer&&(t+=n.byteLength,!Number.isSafeInteger(t)))throw RangeError(`ArrayBuffer transfer bytes overflow`);return t}maybeUnregisterCompleted(){this.completed&&this.leases.size===0&&this.unregisterCleanup()}resourceUsage(){return this.options.driver.resourceUsage?.()}errorResourceUsage(){try{return this.resourceUsage()}catch{return}}};const Y=67108864;var be=class{coordinator=new J;host=null;identity=null;constructor(e,t=e=>e(this.requireArchive())){this.archive=e,this.executeArchive=t}open(e){if(this.host)throw Error(`a DOCX document pull session is already active`);this.executeArchive(t=>{t.open_document_cursor(e.operationId,e.generation)});let t=0;this.identity=e,this.host=new ye({...e,maxByteCredit:Y,coordinator:this.coordinator,driver:{pull:n=>{let r;try{r=this.executeArchive(r=>r.pull_document_chunk(t,e.operationId,e.generation,n))}catch(e){throw ue(e,n,Y)||e}let i=ge(r);return{payload:i,byteLength:i.byteLength,done:this.executeArchive(e=>e.document_chunk_done()),transfer:[i]}},measureChunk:({payload:e})=>e.byteLength,acknowledge:n=>{if(n!==t)throw Error(`DOCX document acknowledgement sequence mismatch`);this.executeArchive(n=>n.acknowledge_document_chunk(t,e.operationId,e.generation)),t+=1},cancel:()=>this.executeArchive(e=>e.cancel_document_cursor()),close:()=>this.executeArchive(e=>e.close_document_session()),resourceUsage:()=>{let e=this.executeArchive(e=>e.document_cursor_resource_usage?.());return e?P(e):void 0}}})}dispatch(e,t){return!this.host||!this.identity?(t({protocol:K,kind:`error`,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,error:G(Error(`DOCX document pull session is not open`))}),Promise.resolve()):this.host.dispatch(e,t)}async reset(){if(this.host)try{this.archive()&&this.executeArchive(e=>e.close_document_session())}finally{this.host=null,this.identity=null,this.coordinator=new J}}requireArchive(){let e=this.archive();if(!e)throw Error(`No docx loaded`);return e}};function xe(e){return!!e&&typeof e==`object`&&e.protocol===`ooxml-pull-v1`}const X=new ce(b,{freeArchive:e=>e.free(),reinit:ne}),Z=new be(()=>X.archive,e=>X.run(()=>{let t=X.archive;if(!t)throw Error(`No docx loaded`);return e(t)}));let Q=0;const $=(e,t)=>self.postMessage(e,t);self.onmessage=async e=>{let n=e.data;if(xe(n)){try{await Z.dispatch(n,$)}catch(e){$({protocol:K,kind:`error`,sessionId:n.sessionId,operationId:n.operationId,generation:n.generation,requestId:n.requestId,error:G(e)})}return}if(n.type===`init`){X.setWasmInput(ie(n.wasmUrl)??n.wasmUrl);return}let r=n.id;try{if(await X.ensureReady(),n.type!==`parse`&&X.archive){let e=X.archive;X.run(()=>e.assert_healthy())}if(n.type===`parse`){await Z.reset();let[e,i,a]=_e(n.resourcePolicy),o=new Uint8Array(n.data);X.run(()=>{let n=new t(o,e,i,a);X.setArchive(n)}),Q+=1;let s={sessionId:Q,operationId:Q,generation:Q};Z.open(s),$({type:`documentSessionOpened`,id:r,...s});return}let e=X.archive;if(n.type===`extractImage`){if(!e)throw Error(`No docx loaded`);let t=X.run(()=>e.extract_image(n.path).buffer),i={type:`imageExtracted`,id:r,bytes:t};self.postMessage(i,[t]);return}if(n.type===`resourceUsage`){if(!e)throw Error(`No docx loaded`);$({type:`resourceUsage`,id:r,usage:P(X.run(()=>e.resource_usage()))});return}if(n.type===`toMarkdown`){if(!e)throw Error(`No docx loaded`);$({type:`markdownRendered`,id:r,markdown:X.run(()=>e.to_markdown())});return}}catch(e){$({type:`error`,id:r,...G(e)})}};", F = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", P], { type: "text/javascript;charset=utf-8" });
|
|
57
|
-
function
|
|
60
|
+
var N = "var e=(e,t)=>()=>(e&&(t=e(e=0)),t),t=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,r.unregister(this),e}free(){let e=this.__destroy_into_raw();_.__wbg_docxarchive_free(e,0)}acknowledge_document_chunk(e,t,n){let r=_.docxarchive_acknowledge_document_chunk(this.__wbg_ptr,e,t,n);if(r[1])throw f(r[0])}assert_healthy(){let e=_.docxarchive_assert_healthy(this.__wbg_ptr);if(e[1])throw f(e[0])}cancel_document_cursor(){_.docxarchive_cancel_document_cursor(this.__wbg_ptr)}close_document_session(){_.docxarchive_close_document_session(this.__wbg_ptr)}document_chunk_done(){let e=_.docxarchive_document_chunk_done(this.__wbg_ptr);if(e[2])throw f(e[1]);return e[0]!==0}document_cursor_resource_usage(){let e=_.docxarchive_document_cursor_resource_usage(this.__wbg_ptr);if(e[3])throw f(e[2]);var t=i(e[0],e[1]).slice();return _.__wbindgen_free(e[0],e[1]*1,1),t}extract_image(e){let t=d(e,_.__wbindgen_malloc,_.__wbindgen_realloc),n=g,r=_.docxarchive_extract_image(this.__wbg_ptr,t,n);if(r[3])throw f(r[2]);var a=i(r[0],r[1]).slice();return _.__wbindgen_free(r[0],r[1]*1,1),a}constructor(e,t,n,i){let a=ee(e,_.__wbindgen_malloc),o=g,s=_.docxarchive_new(a,o,!u(t),u(t)?BigInt(0):t,!u(n),u(n)?BigInt(0):n,!u(i),u(i)?BigInt(0):i);if(s[2])throw f(s[1]);return this.__wbg_ptr=s[0]>>>0,r.register(this,this.__wbg_ptr,this),this}open_document_cursor(e,t){let n=_.docxarchive_open_document_cursor(this.__wbg_ptr,e,t);if(n[1])throw f(n[0])}parse(){let e=_.docxarchive_parse(this.__wbg_ptr);if(e[3])throw f(e[2]);var t=i(e[0],e[1]).slice();return _.__wbindgen_free(e[0],e[1]*1,1),t}pull_document_chunk(e,t,n,r){let a=_.docxarchive_pull_document_chunk(this.__wbg_ptr,e,t,n,r);if(a[3])throw f(a[2]);var o=i(a[0],a[1]).slice();return _.__wbindgen_free(a[0],a[1]*1,1),o}resource_usage(){let e=_.docxarchive_resource_usage(this.__wbg_ptr);if(e[3])throw f(e[2]);var t=i(e[0],e[1]).slice();return _.__wbindgen_free(e[0],e[1]*1,1),t}to_markdown(){let e,t;try{let i=_.docxarchive_to_markdown(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,f(i[2]);return e=n,t=r,s(n,r)}finally{_.__wbindgen_free(e,t,1)}}};Symbol.dispose&&(t.prototype[Symbol.dispose]=t.prototype.free);function n(){return{__proto__:null,\"./docx_parser_bg.js\":{__proto__:null,__wbg___wbindgen_throw_6b64449b9b9ed33c:function(e,t){throw Error(s(e,t))},__wbg_error_a6fa202b58aa1cd3:function(e,t){let n,r;try{n=e,r=t,console.error(s(e,t))}finally{_.__wbindgen_free(n,r,1)}},__wbg_new_227d7c05414eb861:function(){return Error()},__wbg_stack_3b0d974bbf31e44f:function(e,t){let n=t.stack,r=d(n,_.__wbindgen_malloc,_.__wbindgen_realloc),i=g;o().setInt32(e+4,i,!0),o().setInt32(e+0,r,!0)},__wbindgen_cast_0000000000000001:function(e,t){return s(e,t)},__wbindgen_init_externref_table:function(){let e=_.__wbindgen_externrefs,t=e.grow(4);e.set(0,void 0),e.set(t+0,void 0),e.set(t+1,null),e.set(t+2,!0),e.set(t+3,!1)}}}}const r=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>_.__wbg_docxarchive_free(e>>>0,1));function i(e,t){return e>>>=0,l().subarray(e/1,e/1+t)}let a=null;function o(){return(a===null||a.buffer.detached===!0||a.buffer.detached===void 0&&a.buffer!==_.memory.buffer)&&(a=new DataView(_.memory.buffer)),a}function s(e,t){return e>>>=0,te(e,t)}let c=null;function l(){return(c===null||c.byteLength===0)&&(c=new Uint8Array(_.memory.buffer)),c}function u(e){return e==null}function ee(e,t){let n=t(e.length*1,1)>>>0;return l().set(e,n/1),g=e.length,n}function d(e,t,n){if(n===void 0){let n=h.encode(e),r=t(n.length,1)>>>0;return l().subarray(r,r+n.length).set(n),g=n.length,r}let r=e.length,i=t(r,1)>>>0,a=l(),o=0;for(;o<r;o++){let t=e.charCodeAt(o);if(t>127)break;a[i+o]=t}if(o!==r){o!==0&&(e=e.slice(o)),i=n(i,r,r=o+e.length*3,1)>>>0;let t=l().subarray(i+o,i+r),a=h.encodeInto(e,t);o+=a.written,i=n(i,r,o,1)>>>0}return g=o,i}function f(e){let t=_.__wbindgen_externrefs.get(e);return _.__externref_table_dealloc(e),t}let p=new TextDecoder(`utf-8`,{ignoreBOM:!0,fatal:!0});p.decode();let m=0;function te(e,t){return m+=t,m>=2146435072&&(p=new TextDecoder(`utf-8`,{ignoreBOM:!0,fatal:!0}),p.decode(),m=t),p.decode(l().subarray(e,e+t))}const h=new TextEncoder;`encodeInto`in h||(h.encodeInto=function(e,t){let n=h.encode(e);return t.set(n),{read:e.length,written:n.length}});let g=0,_;function v(e,t){return _=e.exports,a=null,c=null,_.__wbindgen_start(),_}async function y(e,t){if(typeof Response==`function`&&e instanceof Response){if(typeof WebAssembly.instantiateStreaming==`function`)try{return await WebAssembly.instantiateStreaming(e,t)}catch(t){if(e.ok&&n(e.type)&&e.headers.get(`Content-Type`)!==`application/wasm`)console.warn(\"`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\\n\",t);else throw t}let r=await e.arrayBuffer();return await WebAssembly.instantiate(r,t)}else{let n=await WebAssembly.instantiate(e,t);return n instanceof WebAssembly.Instance?{instance:n,module:e}:n}function n(e){switch(e){case`basic`:case`cors`:case`default`:return!0}return!1}}async function b(e){if(_!==void 0)return _;e!==void 0&&(Object.getPrototypeOf(e)===Object.prototype?{module_or_path:e}=e:console.warn(`using deprecated parameters for the initialization function; pass a single object instead`));let t=n();(typeof e==`string`||typeof Request==`function`&&e instanceof Request||typeof URL==`function`&&e instanceof URL)&&(e=fetch(e));let{instance:r,module:i}=await y(await e,t);return v(r,i)}async function ne(e){return _=void 0,a=null,c=null,b(e)}var x=class e extends Error{code;constructor(t,n){super(n),this.name=`OoxmlError`,this.code=t,Object.setPrototypeOf(this,e.prototype)}},S=class e extends Error{code=`ooxml-resource-limit`;details;constructor(t,n){super(t),this.name=`OoxmlResourceLimitError`;let r=n.violation,i=Object.freeze({format:r.format,operation:r.operation,resource:r.resource,metric:r.metric,...r.part===void 0?{}:{part:r.part},limit:r.limit,observed:r.observed,configurable:r.configurable,usage:Object.freeze({archiveEntryCount:r.usage.archiveEntryCount,declaredInflatedBytes:r.usage.declaredInflatedBytes,...r.usage.largestInflatedEntryBytes===void 0?{}:{largestInflatedEntryBytes:r.usage.largestInflatedEntryBytes},distinctInflatedBytes:r.usage.distinctInflatedBytes,operationInflatedBytes:r.usage.operationInflatedBytes})});this.details=Object.freeze({stage:n.stage,violation:i}),Object.setPrototypeOf(this,e.prototype)}},C,w,re=e((()=>{C=1<<25,C*4,w=class e extends RangeError{code=`ooxml-decoded-image-limit`;constructor(t,n,r){super(`OOXML decoded image limit exceeded: ${t} ${r} > ${n}`),this.metric=t,this.limit=n,this.observed=r,this.name=`OoxmlDecodedImageLimitError`,Object.setPrototypeOf(this,e.prototype)}}}));function ie(e){if(!e.startsWith(`data:`))return null;let t=e.indexOf(`,`);if(t===-1)return null;let n=atob(e.slice(t+1)),r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return r.buffer}var ae=class{state=`uninitialized`;generationValue=0;readiness;poisonListeners=new Set;constructor(e,t,n){this.initialize=e,this.reinitialize=t,this.normalizeFailure=n}get generation(){return this.generationValue}get poisoned(){return this.state===`poisoned`}onPoison(e){return this.poisonListeners.add(e),()=>this.poisonListeners.delete(e)}async ensureReady(){if(this.state!==`ready`){if(!this.readiness){let e=this.state===`uninitialized`?this.initialize:this.reinitialize;this.readiness=Promise.resolve().then(e).then(()=>{this.generationValue+=1,this.state=`ready`,this.readiness=void 0},e=>{throw this.readiness=void 0,e})}await this.readiness}}run(e){try{return e()}catch(e){let t=this.normalizeFailure(e);throw t?(this.poison(t),t):e}}tryRunReady(e){if(this.state!==`ready`)return{current:!1};let t=this.generationValue,n=this.run(e);return this.state!==`ready`||t!==this.generationValue?{current:!1}:{current:!0,generation:t,value:n}}poison(e){this.state=`poisoned`,this.readiness=void 0;for(let t of this.poisonListeners)t(e)}assertCurrent(e){if(this.state!==`ready`||e!==this.generationValue)throw Error(`WASM archive session belongs to a discarded runtime generation`)}},T=class e extends Error{code=`parser-crashed`;constructor(t){super(t),this.name=`WasmTrapError`,Object.setPrototypeOf(this,e.prototype)}};function E(e){let t=globalThis.WebAssembly?.RuntimeError;return t&&e instanceof t||e instanceof RangeError?!0:e instanceof Error?e.name===`RuntimeError`||e.name===`CompileError`||e.name===`LinkError`||e.name===`InternalError`||e.name===`OOMError`:!1}function oe(e){try{if((typeof e!=`object`||!e)&&typeof e!=`function`)return;let t=Reflect.get(e,`__destroy_into_raw`);typeof t==`function`&&Reflect.apply(t,e,[])}catch{}}function se(e,t){return e({module_or_path:t})}var ce=class{runtime;wasmInput=null;currentArchive=null;constructor(e,t={}){this.init=e,this.options=t,this.runtime=new ae(()=>this.invokeConfigured(this.init),()=>this.invokeConfigured(this.options.reinit??this.init),le),this.runtime.onPoison(()=>this.dropPoisonedArchive())}setWasmInput(e){this.wasmInput=e,this.runtime.ensureReady().catch(()=>void 0)}setWasmUrl(e){this.setWasmInput(e)}get archive(){return this.currentArchive}setArchive(e){this.freeArchive(),this.currentArchive=e}disposeArchive(){this.freeArchive()}get poisoned(){return this.runtime.poisoned}async ensureReady(){await this.runtime.ensureReady()}run(e){return this.runtime.run(e)}poison(){this.runtime.poison(new T(`WASM parser was recycled`))}invokeConfigured(e){return this.wasmInput===null?Promise.reject(Error(`WasmParserHost: setWasmInput was never called`)):se(e,this.wasmInput)}freeArchive(){this.currentArchive!==null&&this.options.freeArchive&&this.options.freeArchive(this.currentArchive),this.currentArchive=null}dropPoisonedArchive(){let e=this.currentArchive;this.currentArchive=null,oe(e)}};function le(e){return E(e)?new T(`WASM parser trapped and was recycled: ${e instanceof Error?e.message:String(e)}`):null}function D(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>0}function O(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return D(t.requiredBytes)&&D(t.offeredBytes)&&t.requiredBytes>t.offeredBytes}var k=class e extends RangeError{code=`ooxml-insufficient-credit`;requiredBytes;offeredBytes;constructor(t){super(`Pull unit requires ${t.requiredBytes} bytes but credit is ${t.offeredBytes}`),this.name=`PullSessionInsufficientCreditError`,this.requiredBytes=t.requiredBytes,this.offeredBytes=t.offeredBytes,Object.setPrototypeOf(this,e.prototype)}};function A(e){if(e instanceof k)return e;let t=e instanceof Error?e.message:String(e);if(!t.startsWith(`OOXML_INSUFFICIENT_CREDIT:`))return;let n;try{n=JSON.parse(t.slice(26))}catch{return}if(!n||typeof n!=`object`||Array.isArray(n))return;let r=n;if(!(r.code!==`ooxml-insufficient-credit`||!O(r)))return new k(r)}function ue(e,t,n){let r=A(e);if(!(!r||r.offeredBytes!==t||r.requiredBytes>n))return r}re();const j=`OOXML_RESOURCE_LIMIT:`;function M(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}function N(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return M(t.archiveEntryCount)&&M(t.declaredInflatedBytes)&&(t.largestInflatedEntryBytes===void 0||M(t.largestInflatedEntryBytes))&&M(t.distinctInflatedBytes)&&M(t.operationInflatedBytes)}function P(e){let t;try{t=JSON.parse(new TextDecoder().decode(e))}catch{throw TypeError(`OOXML resource usage checkpoint is not valid JSON`)}if(!N(t))throw TypeError(`OOXML resource usage checkpoint is invalid`);return t}function F(e){return e===`docx`||e===`xlsx`||e===`pptx`}function I(e){return e===`container`||e===`decompression`||e===`parsing`||e===`serialization`||e===`layout`||e===`rendering`||e===`worker`}function L(e,t){return typeof e==`string`&&e.length>0&&e.length<=t&&!/[\\u0000-\\u001f\\u007f]/u.test(e)}function R(e){return L(e,128)&&/^[a-z0-9][a-z0-9-]*$/u.test(e)}function z(e){return!L(e,4096)||e.startsWith(`/`)||e.startsWith(`\\\\`)||e.includes(`\\\\`)||e.includes(`?`)||e.includes(`#`)||e.includes(`://`)||/^[a-z]:/iu.test(e)?!1:e.split(`/`).every(e=>e!==``&&e!==`.`&&e!==`..`)}const B=new Map([[`archive-entry:declared-inflated-bytes`,{stage:`container`,part:`required`}],[`archive-entry:actual-inflated-bytes`,{stage:`decompression`,part:`required`}],[`archive:entry-count`,{stage:`container`,part:`forbidden`}],[`archive:central-directory-bytes`,{stage:`container`,part:`forbidden`,configurable:!1}],[`archive:distinct-inflated-bytes`,{stage:`decompression`,part:`required`}],[`xml-event:bytes`,{stage:`parsing`,part:`optional`,configurable:!1}],[`xml-context:bytes`,{stage:`parsing`,part:`optional`,configurable:!1}],[`xml-tree:depth`,{stage:`parsing`,part:`optional`,configurable:!1}],[`worksheet-row:projected-bytes`,{stage:`parsing`,part:`optional`,configurable:!1}],[`worksheet-shell:projected-bytes`,{stage:`parsing`,part:`optional`,configurable:!1}]]),V=new Set([...B.keys()].map(e=>e.slice(0,e.indexOf(`:`)))),H=new Set([...B.keys()].map(e=>e.slice(e.indexOf(`:`)+1)));function de(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return!F(t.format)||!L(t.operation,256)||!R(t.resource)||!R(t.metric)||!M(t.limit)||!M(t.observed)||typeof t.configurable!=`boolean`||!N(t.usage)?!1:!(`part`in t)||z(t.part)}function U(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;if(!I(t.stage)||!de(t.violation))return!1;let n=t.violation,r=B.get(`${n.resource}:${n.metric}`);return r?t.stage!==r.stage||r.configurable===!1&&n.configurable!==!1?!1:r.part===`required`?n.part!==void 0:r.part===`forbidden`?n.part===void 0:!0:!(V.has(n.resource)&&H.has(n.metric))}function fe(e){return{archiveEntryCount:e.archiveEntryCount,declaredInflatedBytes:e.declaredInflatedBytes,...e.largestInflatedEntryBytes===void 0?{}:{largestInflatedEntryBytes:e.largestInflatedEntryBytes},distinctInflatedBytes:e.distinctInflatedBytes,operationInflatedBytes:e.operationInflatedBytes}}function pe(e){if(!U(e))return;let t=e.violation,n={stage:e.stage,violation:{format:t.format,operation:t.operation,resource:t.resource,metric:t.metric,...t.part===void 0?{}:{part:t.part},limit:t.limit,observed:t.observed,configurable:t.configurable,usage:fe(t.usage)}};return U(n)?n:void 0}function W(e){let t=e.violation;return`OOXML resource limit exceeded${t.part?` for ${t.part}`:``}: ${t.metric} ${t.observed} > ${t.limit}`}function me(e){let t=e instanceof Error?e.message:String(e);if(!t.startsWith(j))return;let n;try{n=JSON.parse(t.slice(21))}catch{return}if(!n||typeof n!=`object`)return;let r=n;if(!(r.code!==`ooxml-resource-limit`||!U(r.details)))return new S(W(r.details),r.details)}function he(e){if(e instanceof w)return{message:e.message,errorName:e.name,code:e.code,decodedImage:{metric:e.metric,limit:e.limit,observed:e.observed}};let t=A(e);if(t)return{message:t.message,errorName:t.name,code:t.code,insufficientCredit:{requiredBytes:t.requiredBytes,offeredBytes:t.offeredBytes}};let n=e instanceof x||e instanceof S?e:me(e);if(n instanceof S){let e=pe(n.details);return e?{message:typeof n.message==`string`?n.message:W(e),errorName:`OoxmlResourceLimitError`,code:`ooxml-resource-limit`,resourceLimit:e}:{message:`Invalid OOXML resource-limit error payload`,errorName:`Error`}}if(n instanceof x)return{message:typeof n.message==`string`?n.message:String(n.message),errorName:L(n.name,128)?n.name:`OoxmlError`,...R(n.code)?{code:n.code}:{}};let r=e instanceof Error?e.message:String(e);if(typeof r==`string`&&r.startsWith(j))return{message:`Invalid OOXML resource-limit payload`,errorName:`Error`};let i=e instanceof Error?e:Error(r),a=i;return{message:typeof i.message==`string`?i.message:String(i.message),errorName:L(i.name,128)?i.name:`Error`,...typeof a.code==`string`?{code:a.code}:{}}}function G(e){try{return he(e)}catch{return{message:`Worker operation failed with an unreadable error`,errorName:`Error`}}}function ge(e){return e.byteOffset===0&&e.byteLength===e.buffer.byteLength&&e.buffer instanceof ArrayBuffer?e.buffer:e.slice().buffer}Object.freeze({maxArchiveEntryBytes:134217728,maxTotalInflatedBytes:268435456,maxArchiveEntries:4096});function _e(e){return[e.maxArchiveEntryBytes===null?0n:BigInt(e.maxArchiveEntryBytes),e.maxTotalInflatedBytes===null?0n:BigInt(e.maxTotalInflatedBytes),e.maxArchiveEntries===null?0n:BigInt(e.maxArchiveEntries)]}const K=`ooxml-pull-v1`;function q(e,t){if(!Number.isSafeInteger(e)||e<=0)throw RangeError(`${t} must be a positive safe integer`)}function ve(e){if(!(typeof e==`string`&&e.length>0||typeof e==`number`&&Number.isSafeInteger(e)&&e>0))throw RangeError(`session id must be a non-empty string or positive safe integer`)}var J=class{owner;queue=Promise.resolve();leases=new Map;retainedBytes=0;retainedCount=0;maxRetainedBytes;maxRetainedCount;cleanups=new Set;pendingFatalCleanups=[];poisonRunning=!1;fatal;constructor(e){this.maxRetainedBytes=e?.maxRetainedBytes??64*1024*1024,this.maxRetainedCount=e?.maxRetainedCount??256,q(this.maxRetainedBytes,`max retained lease bytes`),q(this.maxRetainedCount,`max retained lease count`)}enqueue(e){let t=this.queue.then(e,e);return this.queue=t.then(()=>void 0,()=>void 0),t}acquire(e){return this.owner===void 0?(this.owner=e,!0):this.owner===e}release(e){this.owner===e&&(this.owner=void 0)}retainLease(e,t,n){if(!Number.isSafeInteger(n)||n<0)throw RangeError(`retained lease bytes are invalid`);let r=this.leases.get(e)??new Map;if(r.has(t))throw Error(`driver returned a duplicate lease id`);if(this.retainedCount+1>this.maxRetainedCount)throw RangeError(`retained lease count exceeds limit`);if(this.retainedBytes+n>this.maxRetainedBytes)throw RangeError(`retained lease bytes exceed limit`);r.set(t,n),this.leases.set(e,r),this.retainedCount++,this.retainedBytes+=n}releaseLease(e,t){let n=this.leases.get(e),r=n?.get(t);r!==void 0&&(n?.delete(t),n?.size===0&&this.leases.delete(e),this.retainedCount--,this.retainedBytes-=r)}registerCleanup(e){return this.fatal?(this.poisonRunning?this.pendingFatalCleanups.push(e):this.enqueue(e).catch(()=>void 0),()=>void 0):(this.cleanups.add(e),()=>this.cleanups.delete(e))}get fatalError(){return this.fatal}get registeredHostCount(){return this.cleanups.size}async poison(e){if(this.fatal??=e,this.poisonRunning)return this.fatal;this.poisonRunning=!0,this.pendingFatalCleanups.push(...this.cleanups);try{let e;for(;(e=this.pendingFatalCleanups.shift())!==void 0;)await e().catch(()=>void 0)}finally{this.poisonRunning=!1}return this.fatal}},ye=class{options;coordinator;coordinatorOwner=Symbol(`pull-session-host`);unregisterCleanup;sequence=0;unacked;leases=new Map;activeDriverLeases=new Set;nextWireLeaseId;cancelRequested=!1;cancelComplete=!1;closeRequested=!1;closeComplete=!1;driverCancelComplete=!1;driverCloseComplete=!1;completed=!1;constructor(e){ve(e.sessionId),q(e.operationId,`operation id`),q(e.generation,`generation`),q(e.maxByteCredit,`max byte credit`),e.wireLeaseIdStart!==void 0&&q(e.wireLeaseIdStart,`wire lease id start`),this.options=e,this.coordinator=e.coordinator,this.nextWireLeaseId=e.wireLeaseIdStart??1,this.unregisterCleanup=this.coordinator.registerCleanup(()=>this.forceFatalCleanup())}dispatch(e,t){return this.coordinator.enqueue(async()=>{let n=await this.execute(e);try{t(n.response,n.transfer)}catch(e){throw await this.rollbackFailedPost(n),e}})}async rollbackFailedPost(e){let t=e.response;if(t.kind===`chunk`){let n=t.leaseId===void 0?void 0:this.leases.get(t.leaseId);try{await this.options.driver.disposeInvalidChunk?.({payload:t.payload,byteLength:t.byteLength,done:t.done,leaseId:n?.driverLeaseId,retainedBytes:n?.retainedBytes,transfer:e.transfer})}catch{}}this.unacked=void 0,this.coordinator.release(this.coordinatorOwner);for(let[e,t]of[...this.leases])try{await this.options.driver.releaseLease?.(t.driverLeaseId)}catch{}finally{this.leases.delete(e),this.activeDriverLeases.delete(t.driverLeaseId),this.coordinator.releaseLease(this.coordinatorOwner,e)}if(this.cancelRequested=!0,!this.driverCancelComplete)try{await this.options.driver.cancel?.(),this.driverCancelComplete=!0}catch{}this.unregisterCleanup()}async execute(e){try{if(this.isStaleLifecycle(e)){let t=e.kind===`cancel`?`cancel`:`close`;return this.sameOperationIdentity(e)?{response:this.accepted(e,t,!0)}:{response:this.errorResponse(e,{message:`stale lifecycle targets another session or operation`,errorName:`PullSessionProtocolError`,code:`ooxml-stale-lifecycle`})}}this.validateCommandIdentity(e);let t=this.coordinator.fatalError;if(t)return e.kind===`pull`?{response:this.errorResponse(e,t)}:(e.kind===`cancel`?await this.cancel():e.kind===`close`?await this.close():e.kind===`release`&&await this.release(e.leaseId),{response:this.accepted(e,e.kind)});switch(e.kind){case`pull`:return await this.pull(e);case`ack`:return await this.ack(e.sequence),{response:this.accepted(e,`ack`)};case`release`:return await this.release(e.leaseId),{response:this.accepted(e,`release`)};case`cancel`:return await this.cancel(),{response:this.accepted(e,`cancel`)};case`close`:return await this.close(),{response:this.accepted(e,`close`)}}}catch(t){let n=G(t);return n.code===`ooxml-resource-limit`&&(n=await this.coordinator.poison(n)),{response:this.errorResponse(e,n)}}}async pull(e){if(this.closeRequested||this.cancelRequested||this.completed)throw Error(`pull session is closed`);if(this.unacked)throw Error(`previous chunk is not acknowledged`);if(!Number.isSafeInteger(e.sequence)||e.sequence<0||e.sequence!==this.sequence)throw Error(`pull command sequence mismatch`);if(this.validateHostCredit(e.byteCredit),!this.coordinator.acquire(this.coordinatorOwner))throw Error(`another operation has an unacknowledged package chunk`);let t;try{t=await this.options.driver.pull(e.byteCredit)}catch(e){throw this.coordinator.release(this.coordinatorOwner),e}let n=!1,r=!1,i,a;try{let o=this.options.driver.measureChunk(t),s=this.arrayBufferTransferBytes(t.transfer);if(o<s)throw RangeError(`measured chunk bytes are below ArrayBuffer transfer bytes`);if(a=Math.max(o,s),t.leaseId!==void 0){if(q(t.leaseId,`lease id`),t.retainedBytes===void 0)throw Error(`retained lease bytes are required`);if(this.activeDriverLeases.has(t.leaseId))throw r=!0,Error(`driver returned an active duplicate lease id`);i=this.allocateWireLeaseId(),this.coordinator.retainLease(this.coordinatorOwner,i,t.retainedBytes),this.leases.set(i,{driverLeaseId:t.leaseId,retainedBytes:t.retainedBytes}),this.activeDriverLeases.add(t.leaseId),n=!0}else if(t.retainedBytes!==void 0)throw Error(`retained lease bytes require a lease id`);if(!Number.isSafeInteger(a)||a<0)throw RangeError(`host chunk byte length must be a non-negative safe integer`);if(a>e.byteCredit)throw RangeError(`host chunk exceeds byte credit`)}catch(e){let a;try{await this.options.driver.disposeInvalidChunk?.(t)}catch(e){a=e}if(n&&i!==void 0)try{await this.release(i)}catch(e){a??=e}else if(t.leaseId!==void 0&&!r)try{await this.options.driver.releaseLease?.(t.leaseId)}catch(e){a??=e}if(r)try{await this.cancel()}catch(e){a??=e}throw this.coordinator.release(this.coordinatorOwner),a||e}return this.unacked={sequence:this.sequence,done:t.done},{response:{kind:`chunk`,protocol:K,...this.identity(),requestId:e.requestId,sequence:this.sequence,byteLength:a,done:t.done,payload:t.payload,leaseId:i,usage:this.resourceUsage()},transfer:t.transfer}}async ack(e){if(!Number.isSafeInteger(e)||e<0)throw RangeError(`invalid ack sequence`);if(e<this.sequence)return;if(!this.unacked||e!==this.sequence)throw Error(`ack sequence mismatch`);let t=this.unacked.done;await this.options.driver.acknowledge?.(e),this.unacked=void 0,this.coordinator.release(this.coordinatorOwner),this.sequence++,t&&(this.completed=!0,this.maybeUnregisterCompleted())}async release(e){q(e,`wire lease id`);let t=this.leases.get(e);t&&(await this.options.driver.releaseLease?.(t.driverLeaseId),this.leases.delete(e),this.activeDriverLeases.delete(t.driverLeaseId),this.coordinator.releaseLease(this.coordinatorOwner,e),this.maybeUnregisterCompleted())}async cancel(){if(this.cancelComplete)return;this.cancelRequested=!0,this.unacked=void 0,this.coordinator.release(this.coordinatorOwner);let e;try{await this.releaseAllLeases()}catch(t){e=t}if(!this.driverCancelComplete)try{await this.options.driver.cancel?.(),this.driverCancelComplete=!0}catch(t){e??=t}if(e)throw e;this.cancelComplete=!0,this.unregisterCleanup()}async close(){if(this.closeComplete)return;this.closeRequested=!0,this.unacked=void 0,this.coordinator.release(this.coordinatorOwner);let e;try{await this.releaseAllLeases()}catch(t){e=t}if(!this.driverCloseComplete)try{await this.options.driver.close?.(),this.driverCloseComplete=!0}catch(t){e??=t}if(e)throw e;this.closeComplete=!0,this.unregisterCleanup()}async releaseAllLeases(){let e;for(let t of[...this.leases.keys()])try{await this.release(t)}catch(t){e??=t}if(e)throw e}validateCommandIdentity(e){if(e.protocol!==`ooxml-pull-v1`||e.sessionId!==this.options.sessionId||e.operationId!==this.options.operationId||e.generation!==this.options.generation||!Number.isSafeInteger(e.requestId)||e.requestId<=0)throw Error(`stale or mismatched pull session command`)}validateHostCredit(e){if(q(e,`byte credit`),e>this.options.maxByteCredit)throw RangeError(`byte credit exceeds host maximum`)}accepted(e,t,n=!1){return{kind:`accepted`,protocol:K,...n?{sessionId:e.sessionId,operationId:e.operationId,generation:e.generation}:this.identity(),requestId:e.requestId,command:t,usage:this.resourceUsage()}}identity(){return{sessionId:this.options.sessionId,operationId:this.options.operationId,generation:this.options.generation}}isStaleLifecycle(e){return(e.kind===`cancel`||e.kind===`close`)&&e.protocol===`ooxml-pull-v1`&&Number.isSafeInteger(e.requestId)&&e.requestId>0&&Number.isSafeInteger(e.generation)&&e.generation>0&&e.generation<this.options.generation}sameOperationIdentity(e){return e.sessionId===this.options.sessionId&&e.operationId===this.options.operationId}errorResponse(e,t){return{kind:`error`,protocol:K,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,error:t,usage:this.errorResourceUsage()}}async forceFatalCleanup(){this.cancelRequested=!0,this.unacked=void 0,this.coordinator.release(this.coordinatorOwner);let e;for(let t of[...this.leases.keys()])try{await this.release(t)}catch(t){e??=t}if(!this.driverCancelComplete)try{await this.options.driver.cancel?.(),this.driverCancelComplete=!0}catch(t){e??=t}if(e)throw e;this.unregisterCleanup()}allocateWireLeaseId(){if(!Number.isSafeInteger(this.nextWireLeaseId)||this.nextWireLeaseId<=0)throw RangeError(`wire lease id space exhausted`);return this.nextWireLeaseId++}arrayBufferTransferBytes(e){let t=0;for(let n of e??[])if(n instanceof ArrayBuffer&&(t+=n.byteLength,!Number.isSafeInteger(t)))throw RangeError(`ArrayBuffer transfer bytes overflow`);return t}maybeUnregisterCompleted(){this.completed&&this.leases.size===0&&this.unregisterCleanup()}resourceUsage(){return this.options.driver.resourceUsage?.()}errorResourceUsage(){try{return this.resourceUsage()}catch{return}}};const Y=67108864;var be=class{coordinator=new J;host=null;identity=null;constructor(e,t=e=>e(this.requireArchive())){this.archive=e,this.executeArchive=t}open(e){if(this.host)throw Error(`a DOCX document pull session is already active`);this.executeArchive(t=>{t.open_document_cursor(e.operationId,e.generation)});let t=0;this.identity=e,this.host=new ye({...e,maxByteCredit:Y,coordinator:this.coordinator,driver:{pull:n=>{let r;try{r=this.executeArchive(r=>r.pull_document_chunk(t,e.operationId,e.generation,n))}catch(e){throw ue(e,n,Y)||e}let i=ge(r);return{payload:i,byteLength:i.byteLength,done:this.executeArchive(e=>e.document_chunk_done()),transfer:[i]}},measureChunk:({payload:e})=>e.byteLength,acknowledge:n=>{if(n!==t)throw Error(`DOCX document acknowledgement sequence mismatch`);this.executeArchive(n=>n.acknowledge_document_chunk(t,e.operationId,e.generation)),t+=1},cancel:()=>this.executeArchive(e=>e.cancel_document_cursor()),close:()=>this.executeArchive(e=>e.close_document_session()),resourceUsage:()=>{let e=this.executeArchive(e=>e.document_cursor_resource_usage?.());return e?P(e):void 0}}})}dispatch(e,t){return!this.host||!this.identity?(t({protocol:K,kind:`error`,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,error:G(Error(`DOCX document pull session is not open`))}),Promise.resolve()):this.host.dispatch(e,t)}async reset(){if(this.host)try{this.archive()&&this.executeArchive(e=>e.close_document_session())}finally{this.host=null,this.identity=null,this.coordinator=new J}}requireArchive(){let e=this.archive();if(!e)throw Error(`No docx loaded`);return e}};function xe(e){return!!e&&typeof e==`object`&&e.protocol===`ooxml-pull-v1`}const X=new ce(b,{freeArchive:e=>e.free(),reinit:ne}),Z=new be(()=>X.archive,e=>X.run(()=>{let t=X.archive;if(!t)throw Error(`No docx loaded`);return e(t)}));let Q=0;const $=(e,t)=>self.postMessage(e,t);self.onmessage=async e=>{let n=e.data;if(xe(n)){try{await Z.dispatch(n,$)}catch(e){$({protocol:K,kind:`error`,sessionId:n.sessionId,operationId:n.operationId,generation:n.generation,requestId:n.requestId,error:G(e)})}return}if(n.type===`init`){X.setWasmInput(ie(n.wasmUrl)??n.wasmUrl);return}let r=n.id;try{if(await X.ensureReady(),n.type!==`parse`&&X.archive){let e=X.archive;X.run(()=>e.assert_healthy())}if(n.type===`parse`){await Z.reset();let[e,i,a]=_e(n.resourcePolicy),o=new Uint8Array(n.data);X.run(()=>{let n=new t(o,e,i,a);X.setArchive(n)}),Q+=1;let s={sessionId:Q,operationId:Q,generation:Q};Z.open(s),$({type:`documentSessionOpened`,id:r,...s});return}let e=X.archive;if(n.type===`extractImage`){if(!e)throw Error(`No docx loaded`);let t=X.run(()=>e.extract_image(n.path).buffer),i={type:`imageExtracted`,id:r,bytes:t};self.postMessage(i,[t]);return}if(n.type===`resourceUsage`){if(!e)throw Error(`No docx loaded`);$({type:`resourceUsage`,id:r,usage:P(X.run(()=>e.resource_usage()))});return}if(n.type===`toMarkdown`){if(!e)throw Error(`No docx loaded`);$({type:`markdownRendered`,id:r,markdown:X.run(()=>e.to_markdown())});return}}catch(e){$({type:`error`,id:r,...G(e)})}};", tt = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", N], { type: "text/javascript;charset=utf-8" });
|
|
61
|
+
function nt(e) {
|
|
58
62
|
let t;
|
|
59
63
|
try {
|
|
60
|
-
if (t =
|
|
64
|
+
if (t = tt && (self.URL || self.webkitURL).createObjectURL(tt), !t) throw "";
|
|
61
65
|
let n = new Worker(t, {
|
|
62
66
|
type: "module",
|
|
63
67
|
name: e?.name
|
|
@@ -66,7 +70,7 @@ function We(e) {
|
|
|
66
70
|
(self.URL || self.webkitURL).revokeObjectURL(t);
|
|
67
71
|
}), n;
|
|
68
72
|
} catch {
|
|
69
|
-
return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(
|
|
73
|
+
return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(N), {
|
|
70
74
|
type: "module",
|
|
71
75
|
name: e?.name
|
|
72
76
|
});
|
|
@@ -74,17 +78,17 @@ function We(e) {
|
|
|
74
78
|
}
|
|
75
79
|
//#endregion
|
|
76
80
|
//#region packages/docx/src/wasm/docx_parser_bg.wasm?url
|
|
77
|
-
var
|
|
81
|
+
var rt = new URL("docx_parser_bg.wasm", import.meta.url).href;
|
|
78
82
|
//#endregion
|
|
79
83
|
//#region packages/docx/src/bookmark-nav.ts
|
|
80
|
-
function
|
|
84
|
+
function it(e) {
|
|
81
85
|
let t = /* @__PURE__ */ new Map();
|
|
82
86
|
for (let n of e.pages) for (let e of n.bookmarkStarts) e.name !== "" && !t.has(e.name) && t.set(e.name, n.pageIndex);
|
|
83
87
|
return t;
|
|
84
88
|
}
|
|
85
89
|
//#endregion
|
|
86
90
|
//#region packages/docx/src/embedded-fonts.ts
|
|
87
|
-
async function
|
|
91
|
+
async function at(e, t) {
|
|
88
92
|
let n = e.embeddedFonts;
|
|
89
93
|
if (!n || n.length === 0) return [];
|
|
90
94
|
let r = (await Promise.all(n.map(async (e) => {
|
|
@@ -95,25 +99,25 @@ async function qe(e, t) {
|
|
|
95
99
|
bytes: n,
|
|
96
100
|
odttf: e.partPath.toLowerCase().endsWith(".odttf"),
|
|
97
101
|
fontKey: e.fontKey,
|
|
98
|
-
weight:
|
|
99
|
-
style:
|
|
102
|
+
weight: ot(e.style),
|
|
103
|
+
style: st(e.style)
|
|
100
104
|
};
|
|
101
105
|
} catch {
|
|
102
106
|
return null;
|
|
103
107
|
}
|
|
104
108
|
}))).filter((e) => e !== null);
|
|
105
|
-
return r.length === 0 ? [] :
|
|
109
|
+
return r.length === 0 ? [] : $e(r);
|
|
106
110
|
}
|
|
107
|
-
function
|
|
111
|
+
function ot(e) {
|
|
108
112
|
return e === "bold" || e === "boldItalic" ? "bold" : "normal";
|
|
109
113
|
}
|
|
110
|
-
function
|
|
114
|
+
function st(e) {
|
|
111
115
|
return e === "italic" || e === "boldItalic" ? "italic" : "normal";
|
|
112
116
|
}
|
|
113
117
|
//#endregion
|
|
114
118
|
//#region packages/docx/src/element-context.ts
|
|
115
|
-
var
|
|
116
|
-
function
|
|
119
|
+
var P = de, ct = 16384;
|
|
120
|
+
function lt(e, t) {
|
|
117
121
|
let n = Math.min(e.length, t);
|
|
118
122
|
if (n > 0 && n < e.length) {
|
|
119
123
|
let t = e.charCodeAt(n - 1), r = e.charCodeAt(n);
|
|
@@ -121,7 +125,7 @@ function L(e, t) {
|
|
|
121
125
|
}
|
|
122
126
|
return e.slice(0, n);
|
|
123
127
|
}
|
|
124
|
-
function
|
|
128
|
+
function ut(e, t) {
|
|
125
129
|
let n = [], r = 0, i = !1;
|
|
126
130
|
for (let a of e) {
|
|
127
131
|
if (a.length === 0) continue;
|
|
@@ -132,7 +136,7 @@ function Ze(e, t) {
|
|
|
132
136
|
}
|
|
133
137
|
n.push("\n"), r++;
|
|
134
138
|
}
|
|
135
|
-
let e =
|
|
139
|
+
let e = lt(a, Math.max(0, t - r));
|
|
136
140
|
if (n.push(e), r += e.length, e.length < a.length) {
|
|
137
141
|
i = !0;
|
|
138
142
|
break;
|
|
@@ -144,7 +148,7 @@ function Ze(e, t) {
|
|
|
144
148
|
truncated: i
|
|
145
149
|
};
|
|
146
150
|
}
|
|
147
|
-
function*
|
|
151
|
+
function* F(e) {
|
|
148
152
|
if (e.kind === "paragraph") {
|
|
149
153
|
for (let t of e.lines) {
|
|
150
154
|
let e = t.placements.flatMap((e) => e.kind === "text" ? [e.text] : []).join("");
|
|
@@ -153,42 +157,42 @@ function* R(e) {
|
|
|
153
157
|
return;
|
|
154
158
|
}
|
|
155
159
|
if (e.kind === "table") {
|
|
156
|
-
for (let t of e.rows) for (let e of t.cells) for (let t of e.blocks) yield*
|
|
160
|
+
for (let t of e.rows) for (let e of t.cells) for (let t of e.blocks) yield* F(t.layout);
|
|
157
161
|
return;
|
|
158
162
|
}
|
|
159
|
-
if (e.kind === "note" || e.kind === "textbox") for (let t of e.story.blocks) yield*
|
|
163
|
+
if (e.kind === "note" || e.kind === "textbox") for (let t of e.story.blocks) yield* F(t);
|
|
160
164
|
}
|
|
161
|
-
function*
|
|
165
|
+
function* dt(e) {
|
|
162
166
|
for (let t of e.drawing.commands) (t.kind === "text" || t.kind === "watermark-text") && (yield t.text);
|
|
163
|
-
for (let t of e.textBoxes) yield*
|
|
167
|
+
for (let t of e.textBoxes) yield* F(t);
|
|
164
168
|
}
|
|
165
|
-
function
|
|
166
|
-
let t = e ??
|
|
169
|
+
function ft(e) {
|
|
170
|
+
let t = e ?? ct;
|
|
167
171
|
if (!Number.isFinite(t) || t < 0) throw RangeError("maxTextCharacters must be a finite non-negative number.");
|
|
168
|
-
return Math.min(
|
|
172
|
+
return Math.min(P, Math.floor(t));
|
|
169
173
|
}
|
|
170
|
-
function
|
|
174
|
+
function pt(e) {
|
|
171
175
|
return {
|
|
172
176
|
story: e.story,
|
|
173
177
|
storyInstance: e.storyInstance,
|
|
174
178
|
path: [...e.path]
|
|
175
179
|
};
|
|
176
180
|
}
|
|
177
|
-
function
|
|
181
|
+
function mt(e) {
|
|
178
182
|
return "drawing" in e ? e.drawing.inkBounds : e.placement.bounds;
|
|
179
183
|
}
|
|
180
|
-
function
|
|
181
|
-
let t =
|
|
182
|
-
|
|
183
|
-
|
|
184
|
+
function ht(e) {
|
|
185
|
+
let t = mt(e), n = [
|
|
186
|
+
E(e.pointToPage, t),
|
|
187
|
+
E(e.pointToPage, {
|
|
184
188
|
xPt: t.xPt + t.widthPt,
|
|
185
189
|
yPt: t.yPt
|
|
186
190
|
}),
|
|
187
|
-
|
|
191
|
+
E(e.pointToPage, {
|
|
188
192
|
xPt: t.xPt,
|
|
189
193
|
yPt: t.yPt + t.heightPt
|
|
190
194
|
}),
|
|
191
|
-
|
|
195
|
+
E(e.pointToPage, {
|
|
192
196
|
xPt: t.xPt + t.widthPt,
|
|
193
197
|
yPt: t.yPt + t.heightPt
|
|
194
198
|
})
|
|
@@ -200,10 +204,10 @@ function tt(e) {
|
|
|
200
204
|
heightPt: o - i
|
|
201
205
|
};
|
|
202
206
|
}
|
|
203
|
-
function
|
|
207
|
+
function I(e, t) {
|
|
204
208
|
return t.xPt >= e.xPt && t.xPt <= e.xPt + e.widthPt && t.yPt >= e.yPt && t.yPt <= e.yPt + e.heightPt;
|
|
205
209
|
}
|
|
206
|
-
function
|
|
210
|
+
function gt(e, t) {
|
|
207
211
|
let n = !1;
|
|
208
212
|
for (let r = 0, i = t.length - 1; r < t.length; i = r++) {
|
|
209
213
|
let a = t[r], o = t[i];
|
|
@@ -211,35 +215,35 @@ function nt(e, t) {
|
|
|
211
215
|
}
|
|
212
216
|
return n;
|
|
213
217
|
}
|
|
214
|
-
function
|
|
215
|
-
return
|
|
218
|
+
function _t(e, t) {
|
|
219
|
+
return I(e.inkBounds, t) ? e.clip ? e.clip.kind === "rect" ? I(e.clip.rect, t) : gt(t, e.clip.points) : !0 : !1;
|
|
216
220
|
}
|
|
217
|
-
function
|
|
221
|
+
function vt(e, t, n) {
|
|
218
222
|
for (let n of e.clips) {
|
|
219
|
-
let e =
|
|
220
|
-
if (!e || !
|
|
223
|
+
let e = Re(n.pointToPage, t);
|
|
224
|
+
if (!e || !I(n.bounds, e)) return !1;
|
|
221
225
|
}
|
|
222
|
-
return "drawing" in e ?
|
|
226
|
+
return "drawing" in e ? _t(e.drawing, n) : I(e.placement.bounds, n);
|
|
223
227
|
}
|
|
224
|
-
function
|
|
228
|
+
function L(e, t) {
|
|
225
229
|
return e.commands.find((e) => e.kind === "resource" && e.resourceKind === t);
|
|
226
230
|
}
|
|
227
|
-
function
|
|
228
|
-
return
|
|
231
|
+
function yt(e) {
|
|
232
|
+
return L(e, "chart") ? "chart" : e.commands.some((e) => e.kind === "drawingml-shape" || e.kind === "drawingml-image-fill" || e.kind === "fill-rect" || e.kind === "stroke-rect" || e.kind === "text" || e.kind === "watermark-text") ? "shape" : L(e, "image") ? "image" : null;
|
|
229
233
|
}
|
|
230
|
-
function
|
|
231
|
-
let o = "drawing" in e ?
|
|
234
|
+
function bt(e, t, n, r, i, a) {
|
|
235
|
+
let o = "drawing" in e ? yt(e.drawing) : e.placement.resourceKind;
|
|
232
236
|
if (!o) return null;
|
|
233
237
|
let s, c = !1, l, u;
|
|
234
238
|
if (o === "chart") {
|
|
235
|
-
let t = "drawing" in e ?
|
|
239
|
+
let t = "drawing" in e ? L(e.drawing, "chart").resourceKey : e.placement.resourceKey, n = i.resolve(t, "chart"), r = y(n.model, a);
|
|
236
240
|
s = r.text, c = r.truncated, u = n.model.series.length;
|
|
237
241
|
} else if (o === "image") {
|
|
238
|
-
let t = "drawing" in e ?
|
|
242
|
+
let t = "drawing" in e ? L(e.drawing, "image").resourceKey : e.placement.resourceKey, n = i.descriptors.find((e) => e.resourceKey === t && e.kind === "image" && "mimeType" in e);
|
|
239
243
|
if (!n) throw Error(`Unknown image paint resource: ${t}`);
|
|
240
244
|
l = n.mimeType;
|
|
241
245
|
} else {
|
|
242
|
-
let t =
|
|
246
|
+
let t = ut(dt(e), a);
|
|
243
247
|
s = t.text, c = t.truncated;
|
|
244
248
|
}
|
|
245
249
|
return {
|
|
@@ -249,8 +253,8 @@ function ot(e, t, n, r, i, a) {
|
|
|
249
253
|
elementIndex: n,
|
|
250
254
|
elementType: o,
|
|
251
255
|
point: { ...r },
|
|
252
|
-
bounds:
|
|
253
|
-
source:
|
|
256
|
+
bounds: ht(e),
|
|
257
|
+
source: pt("drawing" in e ? e.drawing.source : e.source),
|
|
254
258
|
...s === void 0 ? {} : { text: s },
|
|
255
259
|
...l === void 0 ? {} : { mimeType: l },
|
|
256
260
|
...u === void 0 ? {} : { seriesCount: u },
|
|
@@ -260,25 +264,25 @@ function ot(e, t, n, r, i, a) {
|
|
|
260
264
|
maxTextCharacters: a
|
|
261
265
|
};
|
|
262
266
|
}
|
|
263
|
-
function
|
|
267
|
+
function xt(e, t, n, r, i = {}) {
|
|
264
268
|
if (!Number.isFinite(n.xPt) || !Number.isFinite(n.yPt)) throw RangeError("DOCX hit-test point must contain finite page coordinates.");
|
|
265
|
-
let a =
|
|
269
|
+
let a = ft(i.maxTextCharacters), o = ke(e, t);
|
|
266
270
|
for (let e = o.length - 1; e >= 0; e--) {
|
|
267
|
-
let i = o[e], s =
|
|
268
|
-
if (!s || !
|
|
269
|
-
let c =
|
|
271
|
+
let i = o[e], s = Re(i.pointToPage, n);
|
|
272
|
+
if (!s || !vt(i, n, s)) continue;
|
|
273
|
+
let c = bt(i, t, e, n, r, a);
|
|
270
274
|
if (c) return c;
|
|
271
275
|
}
|
|
272
276
|
return null;
|
|
273
277
|
}
|
|
274
|
-
function
|
|
275
|
-
return
|
|
278
|
+
function St(e, t, n, r) {
|
|
279
|
+
return xt(Te(e, {
|
|
276
280
|
currentDate: r.currentDate,
|
|
277
281
|
defaultCurrentDateMs: r.defaultCurrentDateMs
|
|
278
|
-
}, t).layout, t, n,
|
|
282
|
+
}, t).layout, t, n, ze(e), r);
|
|
279
283
|
}
|
|
280
|
-
function
|
|
281
|
-
let n =
|
|
284
|
+
function R(e, t) {
|
|
285
|
+
let n = ft(t), r = e.text === void 0 ? void 0 : lt(e.text, n), i = e.truncated || e.text !== void 0 && r.length < e.text.length;
|
|
282
286
|
return {
|
|
283
287
|
...structuredClone(e),
|
|
284
288
|
...r === void 0 ? {} : { text: r },
|
|
@@ -289,20 +293,143 @@ function H(e, t) {
|
|
|
289
293
|
};
|
|
290
294
|
}
|
|
291
295
|
//#endregion
|
|
296
|
+
//#region packages/docx/src/revisions.ts
|
|
297
|
+
function z(e) {
|
|
298
|
+
let t = Je(e.id);
|
|
299
|
+
return t === void 0 ? void 0 : `${e.kind}\u0000${t}`;
|
|
300
|
+
}
|
|
301
|
+
function B(e) {
|
|
302
|
+
return Object.freeze({
|
|
303
|
+
...e,
|
|
304
|
+
path: Object.freeze([...e.path])
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
function V(e, t) {
|
|
308
|
+
return e !== void 0 && e.story === t.story && e.storyInstance === t.storyInstance && e.path.length === t.path.length && e.path.every((e, n) => e === t.path[n]);
|
|
309
|
+
}
|
|
310
|
+
function H(e, t) {
|
|
311
|
+
let n = 0, r = e.length;
|
|
312
|
+
for (; n < r;) {
|
|
313
|
+
let i = n + Math.floor((r - n) / 2);
|
|
314
|
+
e[i] < t ? n = i + 1 : r = i;
|
|
315
|
+
}
|
|
316
|
+
return n;
|
|
317
|
+
}
|
|
318
|
+
function Ct(e, t) {
|
|
319
|
+
let n = Array(e.length), r;
|
|
320
|
+
for (let i = e.length - 1; i >= 0; --i) {
|
|
321
|
+
n[i] = r;
|
|
322
|
+
let a = e[i], o = t.get(A(a.source))?.[0];
|
|
323
|
+
o !== void 0 && (r = Object.freeze({
|
|
324
|
+
source: B(a.source),
|
|
325
|
+
sourceRunIndex: o
|
|
326
|
+
}));
|
|
327
|
+
}
|
|
328
|
+
let i = Array(e.length), a;
|
|
329
|
+
for (let n = 0; n < e.length; n += 1) {
|
|
330
|
+
i[n] = a;
|
|
331
|
+
let r = e[n], o = t.get(A(r.source))?.at(-1);
|
|
332
|
+
o !== void 0 && (a = Object.freeze({
|
|
333
|
+
source: B(r.source),
|
|
334
|
+
sourceRunIndex: o
|
|
335
|
+
}));
|
|
336
|
+
}
|
|
337
|
+
return {
|
|
338
|
+
following: n,
|
|
339
|
+
preceding: i
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
function wt(e, t, n, r, i, a) {
|
|
343
|
+
let o = r[e], s = i.get(A(o.source)) ?? [], c = s[H(s, n)], l = s[H(s, t) - 1], u = c ?? l;
|
|
344
|
+
return u === void 0 ? a.following[e] ?? a.preceding[e] : Object.freeze({
|
|
345
|
+
source: B(o.source),
|
|
346
|
+
sourceRunIndex: u
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
function Tt(e, t, n = /* @__PURE__ */ new Map()) {
|
|
350
|
+
let r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set();
|
|
351
|
+
e.forEach((e, t) => {
|
|
352
|
+
let n = z(e);
|
|
353
|
+
n === void 0 || i.has(n) || (r.has(n) ? (r.delete(n), i.add(n)) : r.set(n, t));
|
|
354
|
+
});
|
|
355
|
+
let a = t.blocks.sources.flatMap((e) => {
|
|
356
|
+
if (e.story !== "body") return [];
|
|
357
|
+
let n = t.blocks.resolve(e);
|
|
358
|
+
return n.type === "paragraph" ? [{
|
|
359
|
+
source: e,
|
|
360
|
+
runs: n.runs
|
|
361
|
+
}] : [];
|
|
362
|
+
}), o = new Map([...n].map(([e, t]) => [e, Object.freeze([...t].sort((e, t) => e - t))])), s = Ct(a, o), c = [];
|
|
363
|
+
for (let [e, t] of a.entries()) {
|
|
364
|
+
let n = 0;
|
|
365
|
+
for (; n < t.runs.length;) {
|
|
366
|
+
let i = t.runs[n], l = i.revision?.kind ? z({
|
|
367
|
+
kind: i.revision.kind,
|
|
368
|
+
id: i.revision.id
|
|
369
|
+
}) : void 0, u = l === void 0 ? void 0 : r.get(l);
|
|
370
|
+
if (u === void 0) {
|
|
371
|
+
n += 1;
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
let d = n;
|
|
375
|
+
for (n += 1; n < t.runs.length;) {
|
|
376
|
+
let e = t.runs[n].revision;
|
|
377
|
+
if (!e?.kind || z({
|
|
378
|
+
kind: e.kind,
|
|
379
|
+
id: e.id
|
|
380
|
+
}) !== l) break;
|
|
381
|
+
n += 1;
|
|
382
|
+
}
|
|
383
|
+
let f = n, p = o.get(A(t.source)) ?? [], m = (p[H(p, d)] ?? f) < f ? void 0 : wt(e, d, f, a, o, s);
|
|
384
|
+
c.push(Object.freeze({
|
|
385
|
+
revisionIndex: u,
|
|
386
|
+
source: B(t.source),
|
|
387
|
+
startRunIndex: d,
|
|
388
|
+
endRunIndex: f,
|
|
389
|
+
...m === void 0 ? {} : { geometryFallback: m }
|
|
390
|
+
}));
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return c;
|
|
394
|
+
}
|
|
395
|
+
function Et(e, t, n = /* @__PURE__ */ new Map()) {
|
|
396
|
+
return (e?.length ?? 0) === 0 ? [] : Tt(e ?? [], t, n);
|
|
397
|
+
}
|
|
398
|
+
function U(e, t) {
|
|
399
|
+
let n = t.filter((t) => t.sourceRunIndex !== void 0 && V(t.source, e.source) && t.sourceRunIndex >= e.startRunIndex && t.sourceRunIndex < e.endRunIndex);
|
|
400
|
+
if (n.length > 0) return n;
|
|
401
|
+
let r = e.geometryFallback;
|
|
402
|
+
return r === void 0 ? [] : t.filter((e) => e.sourceRunIndex === r.sourceRunIndex && V(e.source, r.source));
|
|
403
|
+
}
|
|
404
|
+
//#endregion
|
|
292
405
|
//#region packages/docx/src/document.ts
|
|
293
|
-
var
|
|
406
|
+
var W = Object.freeze({
|
|
407
|
+
comments: Object.freeze([]),
|
|
408
|
+
revisions: Object.freeze([])
|
|
409
|
+
});
|
|
410
|
+
function G(e, t) {
|
|
411
|
+
return Ce({
|
|
412
|
+
comments: e,
|
|
413
|
+
revisions: t
|
|
414
|
+
}, "DOCX review metadata");
|
|
415
|
+
}
|
|
416
|
+
var K = class e {
|
|
294
417
|
_metrics = null;
|
|
295
418
|
_document = null;
|
|
296
419
|
_source = null;
|
|
297
420
|
_meta = null;
|
|
421
|
+
_review = W;
|
|
298
422
|
_bookmarkPages = null;
|
|
423
|
+
_commentAnchorRanges = null;
|
|
424
|
+
_revisionAnchorRanges = null;
|
|
425
|
+
_reviewTextRunSourceIndex = null;
|
|
299
426
|
_mode = "main";
|
|
300
427
|
_threeD;
|
|
301
428
|
_regionMap;
|
|
302
429
|
_chartEx;
|
|
303
430
|
_worker;
|
|
304
431
|
_bridge;
|
|
305
|
-
_rawParts = new
|
|
432
|
+
_rawParts = new xe({
|
|
306
433
|
maxEntries: 64,
|
|
307
434
|
maxBytes: u
|
|
308
435
|
});
|
|
@@ -311,7 +438,7 @@ var U = class e {
|
|
|
311
438
|
_localMetricFontFaces = [];
|
|
312
439
|
_fetchImage = (e, t) => this.getImage(e, t);
|
|
313
440
|
constructor(e, t, n, r) {
|
|
314
|
-
this._worker = e, this._mode = t,
|
|
441
|
+
this._worker = e, this._mode = t, Be(this, n), this._bridge = new f(this._worker, {
|
|
315
442
|
correlate: (e) => "protocol" in e && e.protocol === "ooxml-pull-v1" ? e.requestId : "id" in e ? e.id : void 0,
|
|
316
443
|
toError: (e) => {
|
|
317
444
|
if (!("protocol" in e || e.type !== "error")) return Object.assign(c(e), {
|
|
@@ -322,7 +449,7 @@ var U = class e {
|
|
|
322
449
|
});
|
|
323
450
|
}
|
|
324
451
|
});
|
|
325
|
-
let i = new URL(r ??
|
|
452
|
+
let i = new URL(r ?? rt, location.href).href;
|
|
326
453
|
this._bridge.post({
|
|
327
454
|
type: "init",
|
|
328
455
|
wasmUrl: i
|
|
@@ -346,18 +473,18 @@ var U = class e {
|
|
|
346
473
|
t = await e.arrayBuffer();
|
|
347
474
|
} else t = n;
|
|
348
475
|
t = p(await h(t, r.password)), c.setSourceBytes(t.byteLength), c.checkpoint("container ready");
|
|
349
|
-
let a = s === "worker" ? (await import("./render-worker-host-
|
|
476
|
+
let a = s === "worker" ? (await import("./render-worker-host-BNENN3qP.js")).createRenderWorker() : new nt(), l = s === "worker" ? Ue(r) : void 0, u;
|
|
350
477
|
try {
|
|
351
|
-
if (u = new e(a, s, o, r.wasmUrl), u._metrics = c, await u._parse(t, i.policy, s === "worker" ? !!r.useGoogleFonts : !1, r.workerTimeoutMs, (e) => c.observeUsage(e), l), s === "worker" && u._mode === "main" && (c.setMode("main"), console.warn("[ooxml] mode: 'worker' fell back to main-thread rendering because this document requires DOM OpenType vertical glyph selection.")), r.math && u._mode === "worker" && !l?.math && console.warn("[ooxml] a custom math renderer cannot cross the worker boundary; equations will be skipped in mode: 'worker'. Use the math renderer from @silurus/ooxml/math."), r.threeD && u._mode === "worker" && !l?.threeD && console.warn("[ooxml] a custom 3-D chart renderer cannot cross the worker boundary; charts use their 2-D family fallback in mode: 'worker'. Use the renderer from @silurus/ooxml/three-d."), u._threeD = u._mode === "worker" ? void 0 : r.threeD, r.regionMap && u._mode === "worker" && !l?.regionMap && console.warn("[ooxml] a custom Region Map renderer cannot cross the worker boundary; geospatial charts use the unsupported-chart placeholder in mode: 'worker'. Use the renderer from @silurus/ooxml/region-map."), u._regionMap = u._mode === "worker" ? void 0 : r.regionMap, r.chartEx && u._mode === "worker" && !l?.chartEx && console.warn("[ooxml] a custom ChartEx renderer cannot cross the worker boundary; ChartEx charts use the unsupported-chart placeholder in mode: 'worker'. Use the renderer from @silurus/ooxml/chart-ex."), u._chartEx = u._mode === "worker" ? void 0 : r.chartEx, u._mode === "main" && r.useGoogleFonts && u._document && (u._googleFontFaces = await
|
|
478
|
+
if (u = new e(a, s, o, r.wasmUrl), u._metrics = c, await u._parse(t, i.policy, s === "worker" ? !!r.useGoogleFonts : !1, r.workerTimeoutMs, (e) => c.observeUsage(e), l), s === "worker" && u._mode === "main" && (c.setMode("main"), console.warn("[ooxml] mode: 'worker' fell back to main-thread rendering because this document requires DOM OpenType vertical glyph selection.")), r.math && u._mode === "worker" && !l?.math && console.warn("[ooxml] a custom math renderer cannot cross the worker boundary; equations will be skipped in mode: 'worker'. Use the math renderer from @silurus/ooxml/math."), r.threeD && u._mode === "worker" && !l?.threeD && console.warn("[ooxml] a custom 3-D chart renderer cannot cross the worker boundary; charts use their 2-D family fallback in mode: 'worker'. Use the renderer from @silurus/ooxml/three-d."), u._threeD = u._mode === "worker" ? void 0 : r.threeD, r.regionMap && u._mode === "worker" && !l?.regionMap && console.warn("[ooxml] a custom Region Map renderer cannot cross the worker boundary; geospatial charts use the unsupported-chart placeholder in mode: 'worker'. Use the renderer from @silurus/ooxml/region-map."), u._regionMap = u._mode === "worker" ? void 0 : r.regionMap, r.chartEx && u._mode === "worker" && !l?.chartEx && console.warn("[ooxml] a custom ChartEx renderer cannot cross the worker boundary; ChartEx charts use the unsupported-chart placeholder in mode: 'worker'. Use the renderer from @silurus/ooxml/chart-ex."), u._chartEx = u._mode === "worker" ? void 0 : r.chartEx, u._mode === "main" && r.useGoogleFonts && u._document && (u._googleFontFaces = await _e(Fe(u._document), Oe)), u._mode === "main" && u._document?.embeddedFonts?.length) {
|
|
352
479
|
let e = u;
|
|
353
|
-
u._embeddedFontFaces = await
|
|
480
|
+
u._embeddedFontFaces = await at(u._document, (t) => e.getFontBytes(t));
|
|
354
481
|
}
|
|
355
482
|
let n;
|
|
356
|
-
u._mode === "main" && u._document && (n = await
|
|
483
|
+
u._mode === "main" && u._document && (n = await De(u._document), u._localMetricFontFaces = n.faces);
|
|
357
484
|
let d;
|
|
358
|
-
if (u._mode === "main" && r.math && u._document &&
|
|
359
|
-
let e =
|
|
360
|
-
e.services =
|
|
485
|
+
if (u._mode === "main" && r.math && u._document && Pe(u._document) && (d = await Ie(u._document, r.math)), u._mode === "main" && u._document && u._source) {
|
|
486
|
+
let e = w(u);
|
|
487
|
+
e.services = je(u._source, {
|
|
361
488
|
localMetrics: n?.metrics,
|
|
362
489
|
useGoogleFonts: !!r.useGoogleFonts,
|
|
363
490
|
embeddedFaces: u._embeddedFontFaces,
|
|
@@ -366,7 +493,7 @@ var U = class e {
|
|
|
366
493
|
mathDrawables: d?.drawables
|
|
367
494
|
});
|
|
368
495
|
let t = e.services;
|
|
369
|
-
|
|
496
|
+
we(u._source, t, e.defaultCurrentDateMs).layoutVariants.defaultLayout;
|
|
370
497
|
}
|
|
371
498
|
return await u._resourceUsage(r.workerTimeoutMs ?? 1e3).then((e) => c.observeUsage(e), () => void 0), c.checkpoint("model and layout ready"), c.succeed({ pages: u.pageCount }), u;
|
|
372
499
|
} catch (e) {
|
|
@@ -384,7 +511,7 @@ var U = class e {
|
|
|
384
511
|
data: e,
|
|
385
512
|
resourcePolicy: t,
|
|
386
513
|
useGoogleFonts: n,
|
|
387
|
-
defaultCurrentDateMs:
|
|
514
|
+
defaultCurrentDateMs: w(this).defaultCurrentDateMs,
|
|
388
515
|
renderers: a
|
|
389
516
|
} : {
|
|
390
517
|
type: "parse",
|
|
@@ -394,22 +521,23 @@ var U = class e {
|
|
|
394
521
|
}, [e], { timeoutMs: r });
|
|
395
522
|
if ("protocol" in o) throw Error("DOCX parse open returned a pull-protocol response");
|
|
396
523
|
if (this._mode === "worker") if ("usage" in o && o.usage && i?.(o.usage), o.type === "mainThreadVerticalFallback") {
|
|
397
|
-
let e = await
|
|
524
|
+
let e = await Ne(this._bridge.transport(Le), o, {
|
|
398
525
|
timeoutMs: r,
|
|
399
526
|
onUsage: i
|
|
400
527
|
});
|
|
401
528
|
this._source = e.source, this._document = e.document, this._meta = null, this._mode = "main";
|
|
402
529
|
} else this._meta = o.meta;
|
|
403
530
|
else {
|
|
404
|
-
let e = o, t = await
|
|
531
|
+
let e = o, t = await Ne(this._bridge.transport(Le), e, {
|
|
405
532
|
timeoutMs: r,
|
|
406
533
|
onUsage: i
|
|
407
534
|
});
|
|
408
535
|
this._source = t.source, this._document = t.document;
|
|
409
536
|
}
|
|
537
|
+
this._review = G(this._meta?.comments ?? this._document?.comments ?? [], this._meta?.revisions ?? this._document?.revisions ?? []);
|
|
410
538
|
}
|
|
411
539
|
destroy() {
|
|
412
|
-
this._bridge.terminate(), this._document = null, this._source = null, this._meta = null,
|
|
540
|
+
this._bridge.terminate(), this._document = null, this._source = null, this._meta = null, this._review = W, w(this).services = null, this._bookmarkPages = null, this._commentAnchorRanges = null, this._revisionAnchorRanges = null, this._reviewTextRunSourceIndex = null, this._rawParts.clear(), this._embeddedFontFaces.length > 0 && (et(this._embeddedFontFaces), this._embeddedFontFaces = []), this._googleFontFaces.length > 0 && (he(this._googleFontFaces), this._googleFontFaces = []), this._localMetricFontFaces.length > 0 && (Se(this._localMetricFontFaces), this._localMetricFontFaces = []), r(this._fetchImage), n(this._fetchImage);
|
|
413
541
|
}
|
|
414
542
|
async getImage(e, t) {
|
|
415
543
|
return this._rawParts.get(e, t, () => this._bridge.request((t) => ({
|
|
@@ -458,7 +586,31 @@ var U = class e {
|
|
|
458
586
|
return this._document;
|
|
459
587
|
}
|
|
460
588
|
get comments() {
|
|
461
|
-
return this.
|
|
589
|
+
return this._reviewSnapshot().comments;
|
|
590
|
+
}
|
|
591
|
+
get revisions() {
|
|
592
|
+
return this._reviewSnapshot().revisions;
|
|
593
|
+
}
|
|
594
|
+
commentAnchorRanges() {
|
|
595
|
+
if (this._meta) return this._meta.commentAnchorRanges ?? [];
|
|
596
|
+
if (!this._document || !this._source) return [];
|
|
597
|
+
let e = w(this).services;
|
|
598
|
+
if (!e) throw Error("Document layout services are not initialized");
|
|
599
|
+
let t = C(e)?.defaultLayout;
|
|
600
|
+
if (!t) throw Error("Document layout variant store is not initialized");
|
|
601
|
+
return this._reviewTextRunSourceIndex ??= T(t), this._commentAnchorRanges ??= Ye(this._reviewSnapshot().comments, this._source, this._reviewTextRunSourceIndex), this._commentAnchorRanges;
|
|
602
|
+
}
|
|
603
|
+
revisionAnchorRanges() {
|
|
604
|
+
if (this._meta) return this._meta.revisionAnchorRanges ?? [];
|
|
605
|
+
if (!this._document || !this._source) return [];
|
|
606
|
+
let e = w(this).services;
|
|
607
|
+
if (!e) throw Error("Document layout services are not initialized");
|
|
608
|
+
let t = C(e)?.defaultLayout;
|
|
609
|
+
if (!t) throw Error("Document layout variant store is not initialized");
|
|
610
|
+
return this._reviewTextRunSourceIndex ??= T(t), this._revisionAnchorRanges ??= Et(this._reviewSnapshot().revisions, this._source, this._reviewTextRunSourceIndex), this._revisionAnchorRanges;
|
|
611
|
+
}
|
|
612
|
+
_reviewSnapshot() {
|
|
613
|
+
return this._review ||= G(this._meta?.comments ?? this._document?.comments ?? [], this._meta?.revisions ?? this._document?.revisions ?? []), this._review;
|
|
462
614
|
}
|
|
463
615
|
get footnotes() {
|
|
464
616
|
return this._meta?.footnotes ?? this._document?.footnotes ?? [];
|
|
@@ -468,9 +620,9 @@ var U = class e {
|
|
|
468
620
|
}
|
|
469
621
|
_getLayout() {
|
|
470
622
|
if (!this._document) return null;
|
|
471
|
-
let e =
|
|
623
|
+
let e = w(this).services;
|
|
472
624
|
if (!e) throw Error("Document layout services are not initialized");
|
|
473
|
-
let t =
|
|
625
|
+
let t = C(e);
|
|
474
626
|
if (!t) throw Error("Document layout variant store is not initialized");
|
|
475
627
|
return t.defaultLayout;
|
|
476
628
|
}
|
|
@@ -478,7 +630,7 @@ var U = class e {
|
|
|
478
630
|
if (this._bookmarkPages) return this._bookmarkPages;
|
|
479
631
|
if (this._meta) return this._bookmarkPages = new Map(this._meta.bookmarkPages), this._bookmarkPages;
|
|
480
632
|
let e = this._getLayout();
|
|
481
|
-
return e ? (this._bookmarkPages =
|
|
633
|
+
return e ? (this._bookmarkPages = it(e), this._bookmarkPages) : null;
|
|
482
634
|
}
|
|
483
635
|
getBookmarkPage(e) {
|
|
484
636
|
return this._getBookmarkPages()?.get(e);
|
|
@@ -512,11 +664,11 @@ var U = class e {
|
|
|
512
664
|
renderPage(e, t, n = {}) {
|
|
513
665
|
if (this._mode === "worker") throw Error("renderPage(canvas) is unavailable in mode: 'worker'; use renderPageToBitmap() and paint it via an ImageBitmapRenderingContext");
|
|
514
666
|
if (!this._source) throw Error("Document not loaded");
|
|
515
|
-
return
|
|
667
|
+
return Ee(this._source, e, t, {
|
|
516
668
|
...n,
|
|
517
669
|
fetchImage: this._fetchImage,
|
|
518
|
-
layoutServices:
|
|
519
|
-
defaultCurrentDateMs:
|
|
670
|
+
layoutServices: w(this).services ?? void 0,
|
|
671
|
+
defaultCurrentDateMs: w(this).defaultCurrentDateMs,
|
|
520
672
|
threeD: this._threeD,
|
|
521
673
|
regionMap: this._regionMap,
|
|
522
674
|
chartEx: this._chartEx
|
|
@@ -551,14 +703,21 @@ var U = class e {
|
|
|
551
703
|
pageIndex: e,
|
|
552
704
|
opts: n
|
|
553
705
|
}))).runs;
|
|
554
|
-
let r =
|
|
706
|
+
let r = w(this), i = r.services;
|
|
555
707
|
if (!i) throw Error("Document layout services are not initialized");
|
|
556
|
-
return
|
|
708
|
+
return Ae(i, e, {
|
|
557
709
|
currentDate: n.currentDate,
|
|
558
710
|
defaultCurrentDateMs: r.defaultCurrentDateMs,
|
|
559
711
|
width: n.width
|
|
560
712
|
});
|
|
561
713
|
}
|
|
714
|
+
async getCommentThreads(e, t = {}) {
|
|
715
|
+
let { includeResolved: n, width: r, currentDate: i } = t, a = await this.collectPageRuns(e, {
|
|
716
|
+
width: r,
|
|
717
|
+
currentDate: i
|
|
718
|
+
});
|
|
719
|
+
return M(this.comments, this.commentAnchorRanges(), a, { includeResolved: n });
|
|
720
|
+
}
|
|
562
721
|
async getElementContextAt(e, t, n = {}) {
|
|
563
722
|
if (this._mode === "worker") return (await this._bridge.request((r) => ({
|
|
564
723
|
type: "hitTestElement",
|
|
@@ -567,9 +726,9 @@ var U = class e {
|
|
|
567
726
|
point: t,
|
|
568
727
|
opts: n
|
|
569
728
|
}))).context;
|
|
570
|
-
let r =
|
|
729
|
+
let r = w(this), i = r.services;
|
|
571
730
|
if (!i) throw Error("Document layout services are not initialized");
|
|
572
|
-
return
|
|
731
|
+
return St(i, e, t, {
|
|
573
732
|
...n,
|
|
574
733
|
defaultCurrentDateMs: r.defaultCurrentDateMs
|
|
575
734
|
});
|
|
@@ -577,34 +736,34 @@ var U = class e {
|
|
|
577
736
|
};
|
|
578
737
|
//#endregion
|
|
579
738
|
//#region packages/docx/src/tate-chu-yoko-overlay.ts
|
|
580
|
-
function
|
|
739
|
+
function Dt(e, t) {
|
|
581
740
|
if (!e.eastAsianVert) return 1;
|
|
582
741
|
let n = t(e.text);
|
|
583
742
|
return !(n > 0) || e.w >= n ? 1 : e.w / n;
|
|
584
743
|
}
|
|
585
744
|
//#endregion
|
|
586
745
|
//#region packages/docx/src/text-layer.ts
|
|
587
|
-
function
|
|
746
|
+
function q(e, t, n) {
|
|
588
747
|
e.dataset ? n === void 0 ? delete e.dataset[t] : e.dataset[t] = n : n !== void 0 && e.setAttribute?.(`data-${t.replace(/[A-Z]/g, (e) => `-${e.toLowerCase()}`)}`, n);
|
|
589
748
|
}
|
|
590
|
-
function
|
|
591
|
-
e.innerHTML = "",
|
|
749
|
+
function J(e, t, n, r, i, a, o) {
|
|
750
|
+
e.innerHTML = "", q(e, "ooxmlSelectionSurface", "docx"), q(e, "pageIndex", o === void 0 ? void 0 : String(o));
|
|
592
751
|
let s = e.ownerDocument ?? document;
|
|
593
752
|
for (let [o, c] of t.entries()) {
|
|
594
753
|
let t = s.createElement("span");
|
|
595
|
-
|
|
754
|
+
q(t, "ooxmlSelectionRun", "docx"), q(t, "runIndex", String(o)), c.paragraphId !== void 0 && q(t, "paragraphId", c.paragraphId), c.source !== void 0 && (q(t, "sourceStory", c.source.story), q(t, "sourceStoryInstance", c.source.storyInstance), q(t, "sourcePath", JSON.stringify(c.source.path))), t.textContent = c.text;
|
|
596
755
|
let l = c.transform ?? "";
|
|
597
756
|
if (a && c.eastAsianVert) {
|
|
598
|
-
let e =
|
|
757
|
+
let e = Dt(c, a(c.font));
|
|
599
758
|
e !== 1 && (l = `${l ? `${l} ` : ""}scaleX(${e})`);
|
|
600
759
|
}
|
|
601
760
|
let u = l ? `transform:${l};transform-origin:top left;` : "", d = i ? c.hyperlink : void 0, f = d ? "pointer" : "text", p = c.letterSpacingPx === void 0 ? "0" : `${c.letterSpacingPx}px`;
|
|
602
|
-
t.style.cssText = `position:absolute;left:${
|
|
761
|
+
t.style.cssText = `position:absolute;left:${k(c.x, n)};top:${k(c.y, r)};font:${c.font};line-height:${c.h}px;letter-spacing:${p};` + u + `white-space:pre;color:transparent;cursor:${f};pointer-events:all;`, d && i && (t.title = d.kind === "external" ? d.url : d.ref, t.addEventListener("click", (e) => {
|
|
603
762
|
e.preventDefault(), i(d);
|
|
604
763
|
})), e.appendChild(t);
|
|
605
764
|
}
|
|
606
765
|
}
|
|
607
|
-
function
|
|
766
|
+
function Y(e, t, n, r, i, a, o = {}) {
|
|
608
767
|
e.innerHTML = "";
|
|
609
768
|
let s = o.match ?? "rgba(255, 214, 0, 0.42)", c = o.active ?? "rgba(255, 140, 0, 0.55)";
|
|
610
769
|
for (let o of n) {
|
|
@@ -612,16 +771,16 @@ function q(e, t, n, r, i, a, o = {}) {
|
|
|
612
771
|
for (let s of o.slices) {
|
|
613
772
|
let o = t[s.runIndex];
|
|
614
773
|
if (!o) continue;
|
|
615
|
-
let c = a(o.font), l =
|
|
616
|
-
if (
|
|
617
|
-
let
|
|
618
|
-
|
|
774
|
+
let c = a(o.font), l = qe(o.text, s.start, s.end, c), u = o.letterSpacingPx ?? 0, d = Math.max(0, Math.min(s.start, o.text.length)), f = Math.max(d, Math.min(s.end, o.text.length)), p = [...o.text.slice(0, d)].length, m = [...o.text.slice(d, f)].length, h = l.x + p * u, g = l.width + Math.max(0, m - 1) * u, _ = Dt(o, c), ee = h * _, v = g * _;
|
|
775
|
+
if (v <= 0) continue;
|
|
776
|
+
let y = document.createElement("div"), te = o.transform ? `transform:${o.transform};transform-origin:top left;` : "";
|
|
777
|
+
y.style.cssText = `position:absolute;left:${k(o.x + ee, r)};top:${k(o.y, i)};width:${k(v, r)};height:${k(o.h, i)};` + te + `background:${n};pointer-events:none;`, e.appendChild(y);
|
|
619
778
|
}
|
|
620
779
|
}
|
|
621
780
|
}
|
|
622
781
|
//#endregion
|
|
623
782
|
//#region packages/docx/src/find.ts
|
|
624
|
-
var
|
|
783
|
+
var Ot = class {
|
|
625
784
|
_pageRuns = /* @__PURE__ */ new Map();
|
|
626
785
|
_matches = [];
|
|
627
786
|
_active = -1;
|
|
@@ -684,8 +843,8 @@ var J = class {
|
|
|
684
843
|
if (n !== this._generation) return [];
|
|
685
844
|
let o = r === this._runsRevision ? i : new Map([...i, ...this._pageRuns]), s = [];
|
|
686
845
|
for (let n = 0; n < a; n++) {
|
|
687
|
-
let r = o.get(n) ?? [], i =
|
|
688
|
-
for (let a of
|
|
846
|
+
let r = o.get(n) ?? [], i = ie(r);
|
|
847
|
+
for (let a of re(i, e, t)) {
|
|
689
848
|
let e = a.slices.map((e) => r[e.runIndex].text.slice(e.start, e.end)).join("");
|
|
690
849
|
s.push({
|
|
691
850
|
page: n,
|
|
@@ -697,10 +856,10 @@ var J = class {
|
|
|
697
856
|
return this._runsRevision++, this._pageRuns = o, this._matches = s, this._active = -1, this.matches();
|
|
698
857
|
}
|
|
699
858
|
next() {
|
|
700
|
-
return this._active =
|
|
859
|
+
return this._active = te(this._active, this._matches.length), this._activePublic();
|
|
701
860
|
}
|
|
702
861
|
prev() {
|
|
703
|
-
return this._active =
|
|
862
|
+
return this._active = se(this._active, this._matches.length), this._activePublic();
|
|
704
863
|
}
|
|
705
864
|
_activePublic() {
|
|
706
865
|
let e = this._matchAt(this._active);
|
|
@@ -713,19 +872,62 @@ var J = class {
|
|
|
713
872
|
};
|
|
714
873
|
//#endregion
|
|
715
874
|
//#region packages/docx/src/selection-context.ts
|
|
716
|
-
function
|
|
875
|
+
function kt(e, t, n, r, i = {}) {
|
|
876
|
+
let a = e.find((e) => e.id === n && e.parentId === void 0);
|
|
877
|
+
if (!a) return null;
|
|
878
|
+
let o = new Map(e.map((e) => [e.id, e])), s = e.filter((e) => {
|
|
879
|
+
if (e.parentId === void 0) return !1;
|
|
880
|
+
let t = e, n = /* @__PURE__ */ new Set();
|
|
881
|
+
for (; t.parentId !== void 0 && !n.has(t.id);) {
|
|
882
|
+
n.add(t.id);
|
|
883
|
+
let e = o.get(t.parentId);
|
|
884
|
+
if (!e) return !1;
|
|
885
|
+
if (e.id === a.id) return !0;
|
|
886
|
+
t = e;
|
|
887
|
+
}
|
|
888
|
+
return !1;
|
|
889
|
+
}), c = Ge({
|
|
890
|
+
id: a.id,
|
|
891
|
+
author: a.author,
|
|
892
|
+
date: a.date,
|
|
893
|
+
text: a.paragraphs?.join("\n") ?? a.text,
|
|
894
|
+
status: a.resolved ? "resolved" : "active"
|
|
895
|
+
}, s.map((e) => ({
|
|
896
|
+
id: e.id,
|
|
897
|
+
author: e.author,
|
|
898
|
+
date: e.date,
|
|
899
|
+
text: e.paragraphs?.join("\n") ?? e.text,
|
|
900
|
+
status: e.resolved ? "resolved" : "active"
|
|
901
|
+
})), i.maxTextCharacters), l = t.find((e) => e.commentId === n)?.source;
|
|
902
|
+
return Object.freeze({
|
|
903
|
+
format: "docx",
|
|
904
|
+
kind: "comment",
|
|
905
|
+
pageIndex: r,
|
|
906
|
+
commentId: n,
|
|
907
|
+
...l ? { source: Object.freeze({
|
|
908
|
+
...l,
|
|
909
|
+
path: Object.freeze([...l.path])
|
|
910
|
+
}) } : {},
|
|
911
|
+
thread: c.thread,
|
|
912
|
+
truncated: c.truncated,
|
|
913
|
+
truncationReasons: c.truncated ? ["text"] : [],
|
|
914
|
+
textCharacters: c.textCharacters,
|
|
915
|
+
maxTextCharacters: c.maxTextCharacters
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
function At(e) {
|
|
717
919
|
if (e === void 0 || !/^\d+$/.test(e)) return null;
|
|
718
920
|
let t = Number(e);
|
|
719
921
|
return Number.isSafeInteger(t) ? t : null;
|
|
720
922
|
}
|
|
721
|
-
function
|
|
923
|
+
function jt(e) {
|
|
722
924
|
for (let t = e; t; t = t.parentElement) {
|
|
723
|
-
let e =
|
|
925
|
+
let e = At(t.dataset.pageIndex);
|
|
724
926
|
if (e !== null) return e;
|
|
725
927
|
}
|
|
726
928
|
return null;
|
|
727
929
|
}
|
|
728
|
-
var
|
|
930
|
+
var Mt = new Set([
|
|
729
931
|
"body",
|
|
730
932
|
"header",
|
|
731
933
|
"footer",
|
|
@@ -733,9 +935,9 @@ var ut = new Set([
|
|
|
733
935
|
"endnote",
|
|
734
936
|
"textbox"
|
|
735
937
|
]);
|
|
736
|
-
function
|
|
938
|
+
function Nt(e) {
|
|
737
939
|
let t = e.dataset.sourceStory, n = e.dataset.sourceStoryInstance, r = e.dataset.sourcePath;
|
|
738
|
-
if (!t || !
|
|
940
|
+
if (!t || !Mt.has(t) || !n || !r) return null;
|
|
739
941
|
try {
|
|
740
942
|
let e = JSON.parse(r);
|
|
741
943
|
return !Array.isArray(e) || e.length === 0 || e.length > 32 || !e.every((e) => Number.isSafeInteger(e) && e >= 0) ? null : {
|
|
@@ -747,14 +949,14 @@ function X(e) {
|
|
|
747
949
|
return null;
|
|
748
950
|
}
|
|
749
951
|
}
|
|
750
|
-
function
|
|
751
|
-
let r =
|
|
752
|
-
let t =
|
|
952
|
+
function X(e, t, n = {}) {
|
|
953
|
+
let r = le(e, t, (e) => {
|
|
954
|
+
let t = jt(e), n = At(e.dataset.runIndex);
|
|
753
955
|
return t === null || n === null ? null : {
|
|
754
956
|
pageIndex: t,
|
|
755
957
|
runIndex: n,
|
|
756
958
|
...e.dataset.paragraphId === void 0 ? {} : { paragraphId: e.dataset.paragraphId },
|
|
757
|
-
...
|
|
959
|
+
...Nt(e) === null ? {} : { source: Nt(e) }
|
|
758
960
|
};
|
|
759
961
|
}, {
|
|
760
962
|
maxChars: n.maxTextCharacters,
|
|
@@ -777,8 +979,13 @@ function Z(e, t, n = {}) {
|
|
|
777
979
|
};
|
|
778
980
|
}
|
|
779
981
|
//#endregion
|
|
982
|
+
//#region packages/docx/src/focused-view-runtime.ts
|
|
983
|
+
function Z(e, t, n, r, i) {
|
|
984
|
+
return r === "worker" ? e.renderPageToBitmap(n, i) : e.renderPage(t, n, i);
|
|
985
|
+
}
|
|
986
|
+
//#endregion
|
|
780
987
|
//#region packages/docx/src/viewer.ts
|
|
781
|
-
var
|
|
988
|
+
var Pt = Symbol("DocxViewer.borrowedDocument"), Q = class e {
|
|
782
989
|
_documentOwner;
|
|
783
990
|
get _doc() {
|
|
784
991
|
return this._documentOwner.current;
|
|
@@ -809,30 +1016,30 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
809
1016
|
static fromDocument(t, n, r = {}) {
|
|
810
1017
|
return new e(t, {
|
|
811
1018
|
...r,
|
|
812
|
-
[
|
|
1019
|
+
[Pt]: n
|
|
813
1020
|
});
|
|
814
1021
|
}
|
|
815
1022
|
constructor(e, t = {}) {
|
|
816
1023
|
this._canvas = e, this._opts = t;
|
|
817
|
-
let n = t[
|
|
818
|
-
this._borrowed = n !== void 0, this._mode =
|
|
1024
|
+
let n = t[Pt];
|
|
1025
|
+
this._borrowed = n !== void 0, this._mode = x("DocxViewer", t.mode, n), this._documentOwner = new _("DocxViewer", n ?? null, !1);
|
|
819
1026
|
let r = e.ownerDocument?.defaultView ?? (typeof window < "u" ? window : null);
|
|
820
1027
|
if (!r) throw Error("DocxViewer requires a canvas with an active Window");
|
|
821
|
-
this._hostWindow = r, this._canvasMount = new
|
|
1028
|
+
this._hostWindow = r, this._canvasMount = new ue(e, {
|
|
822
1029
|
wrapperCssText: "position:relative;display:inline-block;vertical-align:top;",
|
|
823
1030
|
forceDisplayBlock: !0
|
|
824
|
-
}), this._wrapper = this._canvasMount.wrapper, this._renderDispatcher = new
|
|
825
|
-
let i = new
|
|
1031
|
+
}), this._wrapper = this._canvasMount.wrapper, this._renderDispatcher = new b(e, this._mode === "worker"), this._errorRouter = new ce("DocxViewer", t.onError);
|
|
1032
|
+
let i = new ae(this._wrapper, t.enableTextSelection === !0, t.enableElementSelection === !0);
|
|
826
1033
|
this._textLayer = i.textLayer, this._highlightLayer = i.highlightLayer, this._elementLayer = i.elementLayer, this._textLayer && (t.onSelectionContextChange || t.enableElementSelection) && (this._selectionChangeListener = () => this._emitSelectionContextChange(), this._wrapper.ownerDocument.addEventListener("selectionchange", this._selectionChangeListener)), t.enableElementSelection && (this._elementClickListener = (e) => {
|
|
827
1034
|
this._onElementClick(e).catch((e) => this._reportRenderError(e));
|
|
828
|
-
}, this._wrapper.addEventListener("click", this._elementClickListener)), t.onContextMenu && (this._contextMenuListener = (e) => this._onContextMenu(e), this._wrapper.addEventListener("contextmenu", this._contextMenuListener)), this._find = new
|
|
1035
|
+
}, this._wrapper.addEventListener("click", this._elementClickListener)), t.onContextMenu && (this._contextMenuListener = (e) => this._onContextMenu(e), this._wrapper.addEventListener("contextmenu", this._contextMenuListener)), this._find = new Ot(() => this.pageCount, (e) => this._collectPageRuns(e));
|
|
829
1036
|
}
|
|
830
1037
|
async load(e) {
|
|
831
1038
|
if (this._destroyed) throw Error("DocxViewer is destroyed");
|
|
832
1039
|
if (this._borrowed) throw Error("DocxViewer.load() is unsupported on a Viewer created by fromDocument(); the borrowed document is already loaded.");
|
|
833
1040
|
let t = !1;
|
|
834
1041
|
try {
|
|
835
|
-
if (!await this._documentOwner.replace(() =>
|
|
1042
|
+
if (!await this._documentOwner.replace(() => K.load(e, {
|
|
836
1043
|
password: this._opts.password,
|
|
837
1044
|
useGoogleFonts: this._opts.useGoogleFonts,
|
|
838
1045
|
maxZipEntryBytes: this._opts.maxZipEntryBytes,
|
|
@@ -877,7 +1084,7 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
877
1084
|
await this.goToPage(this._currentPage - 1);
|
|
878
1085
|
}
|
|
879
1086
|
_naturalWidthPx() {
|
|
880
|
-
return !this._doc || this._doc.pageCount === 0 ? 0 : this._doc.pageSize(this._currentPage).widthPt *
|
|
1087
|
+
return !this._doc || this._doc.pageCount === 0 ? 0 : this._doc.pageSize(this._currentPage).widthPt * D;
|
|
881
1088
|
}
|
|
882
1089
|
_renderWidth() {
|
|
883
1090
|
if (this._scale === null) return this._opts.width;
|
|
@@ -896,14 +1103,14 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
896
1103
|
return this._opts.zoomMax ?? 4;
|
|
897
1104
|
}
|
|
898
1105
|
async setScale(e) {
|
|
899
|
-
let t =
|
|
1106
|
+
let t = ne(e, this._zoomMin(), this._zoomMax()), n = t !== this.getScale();
|
|
900
1107
|
this._scale = t, await this._render(), n && this._opts.onScaleChange?.(t);
|
|
901
1108
|
}
|
|
902
1109
|
async zoomIn() {
|
|
903
|
-
await this.setScale(
|
|
1110
|
+
await this.setScale(fe(this.getScale()));
|
|
904
1111
|
}
|
|
905
1112
|
async zoomOut() {
|
|
906
|
-
await this.setScale(
|
|
1113
|
+
await this.setScale(S(this.getScale()));
|
|
907
1114
|
}
|
|
908
1115
|
async fitWidth() {
|
|
909
1116
|
await this._fit("width");
|
|
@@ -916,8 +1123,8 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
916
1123
|
let t = this._doc.pageSize(this._currentPage), n = this._fitContainer();
|
|
917
1124
|
if (!n) return;
|
|
918
1125
|
let r = g({
|
|
919
|
-
contentWidth: t.widthPt *
|
|
920
|
-
contentHeight: t.heightPt *
|
|
1126
|
+
contentWidth: t.widthPt * D,
|
|
1127
|
+
contentHeight: t.heightPt * D,
|
|
921
1128
|
containerWidth: n.clientWidth,
|
|
922
1129
|
containerHeight: n.clientHeight
|
|
923
1130
|
}, e);
|
|
@@ -953,7 +1160,7 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
953
1160
|
}
|
|
954
1161
|
getSelectionContext(e = {}) {
|
|
955
1162
|
if (this._destroyed) throw Error("DocxViewer is destroyed");
|
|
956
|
-
return (this._textLayer ?
|
|
1163
|
+
return (this._textLayer ? X(this._wrapper, this._wrapper.ownerDocument?.getSelection?.() ?? null, e) : null) ?? (this._elementContext ? R(this._elementContext, e.maxTextCharacters) : null);
|
|
957
1164
|
}
|
|
958
1165
|
_emitSelectionContextChange() {
|
|
959
1166
|
let e = this.getSelectionContext();
|
|
@@ -970,11 +1177,11 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
970
1177
|
_redrawElementOutline() {
|
|
971
1178
|
let e = this._elementContext, t = this._doc;
|
|
972
1179
|
if (!e || !t || e.pageIndex !== this._currentPage) {
|
|
973
|
-
|
|
1180
|
+
v(this._elementLayer, null);
|
|
974
1181
|
return;
|
|
975
1182
|
}
|
|
976
1183
|
let n = t.pageSize(e.pageIndex);
|
|
977
|
-
|
|
1184
|
+
v(this._elementLayer, {
|
|
978
1185
|
x: e.bounds.xPt / n.widthPt,
|
|
979
1186
|
y: e.bounds.yPt / n.heightPt,
|
|
980
1187
|
width: e.bounds.widthPt / n.widthPt,
|
|
@@ -994,7 +1201,7 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
994
1201
|
async _resolveContextAt(e) {
|
|
995
1202
|
let t = this._doc;
|
|
996
1203
|
if (this._destroyed || !t) return null;
|
|
997
|
-
if (this._textLayer &&
|
|
1204
|
+
if (this._textLayer && X(this._wrapper, this._wrapper.ownerDocument?.getSelection?.() ?? null)) return this._emitSelectionContextChange(), this._destroyed ? null : this.getSelectionContext();
|
|
998
1205
|
if (!this._opts.enableElementSelection) return this.getSelectionContext();
|
|
999
1206
|
let n = this._canvas.getBoundingClientRect();
|
|
1000
1207
|
if (n.width <= 0 || n.height <= 0) return this._invalidateElementContext(), null;
|
|
@@ -1007,7 +1214,7 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1007
1214
|
yPt: i / n.height * s.heightPt
|
|
1008
1215
|
}, {
|
|
1009
1216
|
currentDate: this._opts.currentDate,
|
|
1010
|
-
maxTextCharacters:
|
|
1217
|
+
maxTextCharacters: P
|
|
1011
1218
|
});
|
|
1012
1219
|
} catch (e) {
|
|
1013
1220
|
if (this._destroyed || a !== this._elementHitGeneration || o !== this._currentPage || t !== this._doc) return null;
|
|
@@ -1016,7 +1223,7 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1016
1223
|
return this._destroyed || a !== this._elementHitGeneration || o !== this._currentPage || t !== this._doc ? null : (this._setElementContext(c), this._destroyed ? null : this.getSelectionContext());
|
|
1017
1224
|
}
|
|
1018
1225
|
destroy() {
|
|
1019
|
-
this._destroyed || (this._destroyed = !0, this._errorRouter.close(), this._renderDispatcher.destroy(),
|
|
1226
|
+
this._destroyed || (this._destroyed = !0, this._errorRouter.close(), this._renderDispatcher.destroy(), Me(this._canvas), this._documentOwner.close(), this._find.invalidate(), this._selectionChangeListener &&= (this._wrapper.ownerDocument.removeEventListener("selectionchange", this._selectionChangeListener), null), this._elementHitGeneration++, this._elementClickListener &&= (this._wrapper.removeEventListener("click", this._elementClickListener), null), this._contextMenuListener &&= (this._wrapper.removeEventListener("contextmenu", this._contextMenuListener), null), this._elementContext = null, this._canvasMount.restore());
|
|
1020
1227
|
}
|
|
1021
1228
|
async _render() {
|
|
1022
1229
|
let e = this._renderDispatcher.begin();
|
|
@@ -1032,31 +1239,27 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1032
1239
|
}
|
|
1033
1240
|
async _renderPage(e) {
|
|
1034
1241
|
if (!this._doc) return;
|
|
1035
|
-
let t = this._mode === "worker", n = this._renderWidth(), r = [], i = (e) => r.push(e)
|
|
1036
|
-
if (t) {
|
|
1037
|
-
let t = this._opts.dpr ?? (typeof window < "u" && window.devicePixelRatio || 1), r = await this._doc.renderPageToBitmap(this._currentPage, {
|
|
1038
|
-
width: n,
|
|
1039
|
-
dpr: this._opts.dpr,
|
|
1040
|
-
defaultTextColor: this._opts.defaultTextColor,
|
|
1041
|
-
currentDate: this._opts.currentDate,
|
|
1042
|
-
onTextRun: i
|
|
1043
|
-
});
|
|
1044
|
-
if (!this._renderDispatcher.commitBitmap(e, r, {
|
|
1045
|
-
cssWidth: Math.round(r.width / t),
|
|
1046
|
-
cssHeight: Math.round(r.height / t)
|
|
1047
|
-
})) return;
|
|
1048
|
-
} else if (await this._doc.renderPage(this._canvas, this._currentPage, {
|
|
1049
|
-
...this._opts,
|
|
1242
|
+
let t = this._mode === "worker", n = this._renderWidth(), r = [], i = (e) => r.push(e), a = this._opts.dpr ?? (typeof window < "u" && window.devicePixelRatio || 1), o = {
|
|
1050
1243
|
width: n,
|
|
1244
|
+
dpr: this._opts.dpr,
|
|
1245
|
+
defaultTextColor: this._opts.defaultTextColor,
|
|
1246
|
+
currentDate: this._opts.currentDate,
|
|
1051
1247
|
onTextRun: i
|
|
1052
|
-
}
|
|
1248
|
+
};
|
|
1249
|
+
if (t) {
|
|
1250
|
+
let t = await Z(this._doc, this._canvas, this._currentPage, "worker", o);
|
|
1251
|
+
if (!this._renderDispatcher.commitBitmap(e, t, {
|
|
1252
|
+
cssWidth: Math.round(t.width / a),
|
|
1253
|
+
cssHeight: Math.round(t.height / a)
|
|
1254
|
+
})) return;
|
|
1255
|
+
} else if (await Z(this._doc, this._canvas, this._currentPage, "main", o), !this._renderDispatcher.isCurrent(e)) return;
|
|
1053
1256
|
this._textLayer && this._buildTextLayer(this._textLayer, r), this._find.setPageRuns(this._currentPage, r), this._buildHighlightLayer(r), this._opts.onPageChange?.(this._currentPage, this.pageCount);
|
|
1054
1257
|
}
|
|
1055
1258
|
_buildHighlightLayer(e) {
|
|
1056
1259
|
let t = this._highlightLayer;
|
|
1057
1260
|
if (!t) return;
|
|
1058
1261
|
let { width: n, height: r } = this._canvasCssPx();
|
|
1059
|
-
|
|
1262
|
+
Y(t, e, this._find.pageHighlights(this._currentPage), n, r, (e) => this._measureForFont(e), this._opts.findHighlightColors);
|
|
1060
1263
|
}
|
|
1061
1264
|
_canvasCssPx() {
|
|
1062
1265
|
return {
|
|
@@ -1077,7 +1280,7 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1077
1280
|
}
|
|
1078
1281
|
_buildTextLayer(e, t) {
|
|
1079
1282
|
let { width: n, height: r } = this._canvasCssPx();
|
|
1080
|
-
|
|
1283
|
+
J(e, t, n, r, this._hyperlinkHandler(), (e) => this._measureForFont(e), this._currentPage);
|
|
1081
1284
|
}
|
|
1082
1285
|
_hyperlinkHandler() {
|
|
1083
1286
|
return this._opts.enableHyperlinks === !1 ? void 0 : this._opts.onHyperlinkClick || ((e) => {
|
|
@@ -1089,7 +1292,11 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1089
1292
|
t !== void 0 && this.goToPage(t).catch((e) => this._reportRenderError(e));
|
|
1090
1293
|
});
|
|
1091
1294
|
}
|
|
1092
|
-
},
|
|
1295
|
+
}, Ft = 150, It = "0 1px 3px rgba(0,0,0,0.2)", $ = 12, Lt = 13, Rt = Symbol("DocxScrollViewer.borrowedDocument"), zt;
|
|
1296
|
+
function Bt() {
|
|
1297
|
+
return zt ??= import("./comment-ui-runtime-BUCj4hWn.js");
|
|
1298
|
+
}
|
|
1299
|
+
var Vt = class e {
|
|
1093
1300
|
_documentOwner;
|
|
1094
1301
|
get _doc() {
|
|
1095
1302
|
return this._documentOwner.current;
|
|
@@ -1107,6 +1314,10 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1107
1314
|
_slots = /* @__PURE__ */ new Map();
|
|
1108
1315
|
_free = [];
|
|
1109
1316
|
_heights = [];
|
|
1317
|
+
_scrollGeometry = {
|
|
1318
|
+
offsets: [],
|
|
1319
|
+
totalHeight: 0
|
|
1320
|
+
};
|
|
1110
1321
|
_lastRange = null;
|
|
1111
1322
|
_lastTopIndex = -1;
|
|
1112
1323
|
_scrollListener = null;
|
|
@@ -1114,7 +1325,21 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1114
1325
|
_selectionContextKey = "null";
|
|
1115
1326
|
_elementClickListener = null;
|
|
1116
1327
|
_contextMenuListener = null;
|
|
1328
|
+
_commentOutsidePointerListener = null;
|
|
1117
1329
|
_elementContext = null;
|
|
1330
|
+
_activeCommentId = null;
|
|
1331
|
+
_activeCommentPage = null;
|
|
1332
|
+
_commentUi = null;
|
|
1333
|
+
_commentPageById = /* @__PURE__ */ new Map();
|
|
1334
|
+
_commentRunsByPage = /* @__PURE__ */ new Map();
|
|
1335
|
+
_commentIndexedPages = /* @__PURE__ */ new Set();
|
|
1336
|
+
_commentScanFrontier = 0;
|
|
1337
|
+
_commentNavigationGeneration = 0;
|
|
1338
|
+
_commentAnchorRangesForMargin = null;
|
|
1339
|
+
_commentAnchorIds = /* @__PURE__ */ new Set();
|
|
1340
|
+
_commentGeometryScheduled = !1;
|
|
1341
|
+
_commentGeometryFrame = null;
|
|
1342
|
+
_pendingCommentGeometry = /* @__PURE__ */ new Map();
|
|
1118
1343
|
_elementHitGeneration = 0;
|
|
1119
1344
|
_destroyed = !1;
|
|
1120
1345
|
_measureCtx;
|
|
@@ -1127,27 +1352,38 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1127
1352
|
_prevBase = 0;
|
|
1128
1353
|
_lastFitWidth = 0;
|
|
1129
1354
|
_pageShadow;
|
|
1130
|
-
_find = new
|
|
1355
|
+
_find = new Ot(() => this.pageCount, (e) => this._collectPageRuns(e));
|
|
1131
1356
|
_findActive = !1;
|
|
1132
1357
|
static fromDocument(t, n, r = {}) {
|
|
1133
1358
|
return new e(t, {
|
|
1134
1359
|
...r,
|
|
1135
|
-
[
|
|
1360
|
+
[Rt]: n
|
|
1136
1361
|
});
|
|
1137
1362
|
}
|
|
1138
1363
|
constructor(e, t = {}) {
|
|
1139
1364
|
if (e.tagName === "CANVAS") throw Error("DocxScrollViewer takes a container element (e.g. a <div>), not a <canvas> — the viewer creates and manages its own canvases. Pass a block container; for the single-page canvas API use DocxViewer.");
|
|
1140
|
-
this._container = e, this._opts = t, this._pageShadow = t.pageShadow ??
|
|
1141
|
-
let n = t[
|
|
1142
|
-
this._borrowed = n !== void 0, n ? (this._documentOwner = new _("DocxScrollViewer", n, !1), this._mode =
|
|
1365
|
+
this._container = e, this._opts = t, this._pageShadow = t.pageShadow ?? It;
|
|
1366
|
+
let n = t[Rt];
|
|
1367
|
+
this._borrowed = n !== void 0, n ? (this._documentOwner = new _("DocxScrollViewer", n, !1), this._mode = x("DocxScrollViewer", t.mode, n)) : (this._documentOwner = new _("DocxScrollViewer"), this._mode = x("DocxScrollViewer", t.mode, void 0)), this._wrapper = document.createElement("div"), this._wrapper.style.cssText = "position:relative;width:100%;height:100%;overflow:hidden;", this._scrollHost = document.createElement("div"), this._scrollHost.style.cssText = "position:absolute;inset:0;overflow:auto;", this._scrollHost.style.scrollbarGutter = "stable", t.background && (this._scrollHost.style.background = t.background), this._spacer = document.createElement("div"), this._spacer.style.cssText = "position:absolute;top:0;left:0;width:1px;height:0;pointer-events:none;", this._scrollHost.appendChild(this._spacer), this._wrapper.appendChild(this._scrollHost), this._container.appendChild(this._wrapper), this._commentsEnabled() && Bt().then((e) => {
|
|
1368
|
+
if (!this._destroyed) {
|
|
1369
|
+
this._commentUi = e;
|
|
1370
|
+
for (let [e, t] of this._slots) this._redrawSlotComments(e, t);
|
|
1371
|
+
}
|
|
1372
|
+
}).catch((e) => this._reportRenderError(e)), t.enableTextSelection && (t.onSelectionContextChange || t.enableElementSelection) && (this._selectionChangeListener = () => this._emitSelectionContextChange(), this._wrapper.ownerDocument.addEventListener("selectionchange", this._selectionChangeListener)), t.enableElementSelection && (this._elementClickListener = (e) => {
|
|
1143
1373
|
this._onElementClick(e).catch((e) => this._reportRenderError(e));
|
|
1144
|
-
}, this._scrollHost.addEventListener("click", this._elementClickListener)), t.onContextMenu && (this._contextMenuListener = (e) => this._onContextMenu(e), this._scrollHost.addEventListener("contextmenu", this._contextMenuListener)), this._scrollListener = () => this._onScroll(), this._scrollHost.addEventListener("scroll", this._scrollListener),
|
|
1374
|
+
}, this._scrollHost.addEventListener("click", this._elementClickListener)), t.onContextMenu && (this._contextMenuListener = (e) => this._onContextMenu(e), this._scrollHost.addEventListener("contextmenu", this._contextMenuListener)), this._scrollListener = () => this._onScroll(), this._scrollHost.addEventListener("scroll", this._scrollListener), t.comments && (this._commentOutsidePointerListener = (e) => {
|
|
1375
|
+
if (!Ke(e, this._wrapper, "ooxmlCommentId") && this._activeCommentId !== null) {
|
|
1376
|
+
this._activeCommentId = null, this._activeCommentPage = null;
|
|
1377
|
+
for (let [e, t] of this._slots) this._redrawSlotComments(e, t);
|
|
1378
|
+
this._emitSelectionContextChange();
|
|
1379
|
+
}
|
|
1380
|
+
}, this._wrapper.ownerDocument.addEventListener("pointerdown", this._commentOutsidePointerListener)), this._opts.enableZoom !== !1 && (this._wheelListener = (e) => {
|
|
1145
1381
|
if (!(e.ctrlKey || e.metaKey) || (e.preventDefault(), e.deltaY === 0)) return;
|
|
1146
1382
|
let t = this._scrollHost.getBoundingClientRect(), n = e.clientX - t.left, r = e.clientY - t.top;
|
|
1147
1383
|
this._pendingZoomAnchor = Number.isFinite(n) && Number.isFinite(r) ? {
|
|
1148
1384
|
x: n,
|
|
1149
1385
|
y: r
|
|
1150
|
-
} : null, this.setScale(
|
|
1386
|
+
} : null, this.setScale(me(this._scale, e.deltaY));
|
|
1151
1387
|
}, this._scrollHost.addEventListener("wheel", this._wheelListener, { passive: !1 })), typeof ResizeObserver < "u" && (this._resizeObserver = new ResizeObserver(() => this._onResize()), this._resizeObserver.observe(this._container)), this._borrowed && this.relayout();
|
|
1152
1388
|
}
|
|
1153
1389
|
async load(e) {
|
|
@@ -1155,7 +1391,7 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1155
1391
|
if (this._borrowed) throw Error("DocxScrollViewer.load() is unsupported on a Viewer created by fromDocument(); the borrowed document is already loaded.");
|
|
1156
1392
|
let t = !1;
|
|
1157
1393
|
try {
|
|
1158
|
-
if (!await this._documentOwner.replace(() =>
|
|
1394
|
+
if (!await this._documentOwner.replace(() => K.load(e, {
|
|
1159
1395
|
password: this._opts.password,
|
|
1160
1396
|
useGoogleFonts: this._opts.useGoogleFonts,
|
|
1161
1397
|
maxZipEntryBytes: this._opts.maxZipEntryBytes,
|
|
@@ -1170,13 +1406,13 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1170
1406
|
chartEx: this._opts.chartEx,
|
|
1171
1407
|
mode: this._mode
|
|
1172
1408
|
}), (e) => {
|
|
1173
|
-
if (this._invalidateElementContext(!1), t = !0, this._find.invalidate(), this._findActive = !1, e) {
|
|
1409
|
+
if (this._invalidateElementContext(!1), t = !0, this._find.invalidate(), this._findActive = !1, this._activeCommentId = null, this._activeCommentPage = null, this._resetCommentNavigation(), e) {
|
|
1174
1410
|
for (let [e, t] of [...this._slots]) this._recycleSlot(e, t);
|
|
1175
1411
|
this._lastTopIndex = -1;
|
|
1176
1412
|
}
|
|
1177
1413
|
})) return;
|
|
1178
1414
|
if (this._destroyed) throw Error("DocxScrollViewer is destroyed");
|
|
1179
|
-
this._find.invalidate(), this._findActive = !1;
|
|
1415
|
+
this._find.invalidate(), this._findActive = !1, this._activeCommentId = null, this._activeCommentPage = null, this._resetCommentNavigation();
|
|
1180
1416
|
let n = [];
|
|
1181
1417
|
this._relayout(n), await Promise.all(n);
|
|
1182
1418
|
} catch (e) {
|
|
@@ -1188,24 +1424,59 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1188
1424
|
return this._doc?.pageCount ?? 0;
|
|
1189
1425
|
}
|
|
1190
1426
|
_pageWidthPx(e) {
|
|
1191
|
-
return this._doc.pageSize(e).widthPt *
|
|
1427
|
+
return this._doc.pageSize(e).widthPt * D * this._scale;
|
|
1192
1428
|
}
|
|
1193
1429
|
_pageHeightPx(e) {
|
|
1194
|
-
return this._doc.pageSize(e).heightPt *
|
|
1430
|
+
return this._doc.pageSize(e).heightPt * D * this._scale;
|
|
1195
1431
|
}
|
|
1196
1432
|
_fitWidthPx() {
|
|
1197
1433
|
if (this._opts.width && this._opts.width > 0) return this._opts.width;
|
|
1198
1434
|
let e = this._scrollHost.clientWidth || this._container.clientWidth;
|
|
1199
1435
|
if (e <= 0) return 0;
|
|
1200
1436
|
let { left: t, right: n } = this._padH(), r = e - t - n;
|
|
1201
|
-
|
|
1437
|
+
if (r <= 0) return 0;
|
|
1438
|
+
let i = this._doc?.pageSize(0).widthPt ? this._doc.pageSize(0).widthPt * D : 0, a = this._hasCommentMargin() && i > 0 ? r * i / (i + $ + 280) : r;
|
|
1439
|
+
return a > 0 ? a : 0;
|
|
1440
|
+
}
|
|
1441
|
+
_hasCommentMargin() {
|
|
1442
|
+
return this._hasDisplayableComments() && this._commentsOptions()?.cards !== !1;
|
|
1443
|
+
}
|
|
1444
|
+
_hasDisplayableComments() {
|
|
1445
|
+
if (!this._commentsEnabled()) return !1;
|
|
1446
|
+
let e = this._doc;
|
|
1447
|
+
if (!e) return !1;
|
|
1448
|
+
let t = e.commentAnchorRanges();
|
|
1449
|
+
if (this._commentAnchorRangesForMargin !== t && (this._commentAnchorRangesForMargin = t, this._commentAnchorIds = new Set(t.map((e) => e.commentId))), this._commentAnchorIds.size === 0) return !1;
|
|
1450
|
+
let n = this._commentsOptions()?.includeResolved === !0;
|
|
1451
|
+
return e.comments.some((e) => this._commentAnchorIds.has(e.id) && e.parentId === void 0 && (n || e.resolved !== !0));
|
|
1452
|
+
}
|
|
1453
|
+
_commentMarginExtent() {
|
|
1454
|
+
return this._hasCommentMargin() ? ($ + 280) * this._commentZoom() : 0;
|
|
1455
|
+
}
|
|
1456
|
+
_commentZoom() {
|
|
1457
|
+
return this._scaleEstablished ? this._scale : 1;
|
|
1458
|
+
}
|
|
1459
|
+
_commentsEnabled() {
|
|
1460
|
+
return this._opts.comments === !0 || typeof this._opts.comments == "object";
|
|
1461
|
+
}
|
|
1462
|
+
_commentsOptions() {
|
|
1463
|
+
return typeof this._opts.comments == "object" ? this._opts.comments : void 0;
|
|
1464
|
+
}
|
|
1465
|
+
_commentSide() {
|
|
1466
|
+
let e = this._commentsOptions()?.side;
|
|
1467
|
+
return e === "left" || e === "right" ? e : (this._container.ownerDocument.defaultView?.getComputedStyle?.(this._container).direction || this._container.dir || this._container.style.direction) === "rtl" ? "left" : "right";
|
|
1468
|
+
}
|
|
1469
|
+
_syncCommentMarginGeometry(e) {
|
|
1470
|
+
if (!e) return;
|
|
1471
|
+
let t = this._commentZoom(), n = `calc(100% + ${$ * t}px)`;
|
|
1472
|
+
e.style.left = this._commentSide() === "right" ? n : "", e.style.right = this._commentSide() === "left" ? n : "", e.style.width = `${280 * t}px`, e.style.fontSize = `${Lt}px`, e.dataset.ooxmlCommentZoom = String(t);
|
|
1202
1473
|
}
|
|
1203
1474
|
_baseScale() {
|
|
1204
1475
|
if (!this._doc || this._doc.pageCount === 0) return 0;
|
|
1205
1476
|
let e = this._fitWidthPx();
|
|
1206
1477
|
if (e <= 0) return 0;
|
|
1207
1478
|
let t = this._doc.pageSize(0).widthPt;
|
|
1208
|
-
return t <= 0 ? 0 : e / (t *
|
|
1479
|
+
return t <= 0 ? 0 : e / (t * D);
|
|
1209
1480
|
}
|
|
1210
1481
|
relayout() {
|
|
1211
1482
|
this._relayout();
|
|
@@ -1222,12 +1493,13 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1222
1493
|
} else return;
|
|
1223
1494
|
}
|
|
1224
1495
|
this._recomputeHeights(), this._syncSpacer(), this._mountVisible(e);
|
|
1496
|
+
for (let [e, t] of this._slots) t.renderedPage === e && t.renderedScale >= 0 && this._redrawSlotComments(e, t);
|
|
1225
1497
|
}
|
|
1226
1498
|
}
|
|
1227
1499
|
_recomputeHeights() {
|
|
1228
1500
|
let e = this._doc.pageCount, t = Array(e);
|
|
1229
1501
|
for (let n = 0; n < e; n++) t[n] = this._pageHeightPx(n);
|
|
1230
|
-
this._heights = t;
|
|
1502
|
+
this._heights = t, this._scrollGeometry = We(t, this._gap(), this._pad());
|
|
1231
1503
|
}
|
|
1232
1504
|
_gap() {
|
|
1233
1505
|
return this._opts.gap ?? 16;
|
|
@@ -1258,7 +1530,7 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1258
1530
|
return a;
|
|
1259
1531
|
}
|
|
1260
1532
|
_range() {
|
|
1261
|
-
return
|
|
1533
|
+
return O(this._scrollGeometry, this._scrollHost.scrollTop, this._scrollHost.clientHeight, this._overscan());
|
|
1262
1534
|
}
|
|
1263
1535
|
_syncSpacer() {
|
|
1264
1536
|
let e = this._range();
|
|
@@ -1270,24 +1542,24 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1270
1542
|
let t = this._pageWidthPx(e);
|
|
1271
1543
|
t > n && (n = t);
|
|
1272
1544
|
}
|
|
1273
|
-
this._spacer.style.width = `${n + e + t}px`;
|
|
1545
|
+
this._spacer.style.width = `${n + this._commentMarginExtent() + e + t}px`;
|
|
1274
1546
|
}
|
|
1275
1547
|
_onScroll() {
|
|
1276
|
-
!this._doc || !this._scaleEstablished || this._mountVisible();
|
|
1548
|
+
!this._doc || !this._scaleEstablished || this._mountVisible(void 0, !1);
|
|
1277
1549
|
}
|
|
1278
|
-
_mountVisible(e) {
|
|
1550
|
+
_mountVisible(e, t = !0) {
|
|
1279
1551
|
if (!this._doc || this._doc.pageCount === 0) return;
|
|
1280
|
-
let
|
|
1281
|
-
this._lastRange =
|
|
1282
|
-
for (let [e,
|
|
1283
|
-
for (let
|
|
1552
|
+
let n = this._range();
|
|
1553
|
+
this._lastRange = n;
|
|
1554
|
+
for (let [e, t] of [...this._slots]) (e < n.start || e > n.end) && this._recycleSlot(e, t);
|
|
1555
|
+
for (let r = n.start; r <= n.end; r++) if (this._slots.has(r)) t && this._positionSlot(this._slots.get(r), r, n);
|
|
1284
1556
|
else {
|
|
1285
|
-
let
|
|
1286
|
-
this._positionSlot(r, n
|
|
1287
|
-
let i = this._renderSlot(
|
|
1557
|
+
let t = this._acquireSlot();
|
|
1558
|
+
this._positionSlot(t, r, n), this._slots.set(r, t);
|
|
1559
|
+
let i = this._renderSlot(r, t, e === void 0);
|
|
1288
1560
|
e && i && e.push(i);
|
|
1289
1561
|
}
|
|
1290
|
-
|
|
1562
|
+
n.topIndex !== this._lastTopIndex && (this._lastTopIndex = n.topIndex, this._opts.onVisiblePageChange?.(n.topIndex, this._doc.pageCount));
|
|
1291
1563
|
}
|
|
1292
1564
|
_applyPageShadow(e) {
|
|
1293
1565
|
this._pageShadow !== !1 && (e.style.boxShadow = this._pageShadow);
|
|
@@ -1303,27 +1575,38 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1303
1575
|
this._opts.enableTextSelection && (r = document.createElement("div"), r.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;overflow:hidden;pointer-events:none;user-select:text;-webkit-user-select:text;", t.appendChild(r));
|
|
1304
1576
|
let i = document.createElement("div");
|
|
1305
1577
|
i.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;overflow:hidden;pointer-events:none;", t.appendChild(i);
|
|
1306
|
-
let a =
|
|
1578
|
+
let a = null, o = null, s = null;
|
|
1579
|
+
this._hasDisplayableComments() && (a = document.createElement("div"), a.style.cssText = "position:absolute;inset:0;overflow:hidden;pointer-events:none;", t.appendChild(a), this._hasCommentMargin() && (o = document.createElement("div"), o.style.cssText = "position:absolute;top:0;height:100%;box-sizing:border-box;overflow-x:hidden;overflow-y:auto;pointer-events:auto;", this._syncCommentMarginGeometry(o), this._commentsOptions()?.connectors !== void 0 && (s = document.createElement("div"), s.style.cssText = "position:absolute;top:0;left:0;overflow:visible;pointer-events:none;", t.appendChild(s)), t.appendChild(o)));
|
|
1580
|
+
let c = oe(t, this._opts.enableElementSelection === !0);
|
|
1307
1581
|
return this._scrollHost.appendChild(t), {
|
|
1308
1582
|
wrapper: t,
|
|
1309
1583
|
canvas: n,
|
|
1310
1584
|
textLayer: r,
|
|
1311
1585
|
highlightLayer: i,
|
|
1312
|
-
elementLayer:
|
|
1586
|
+
elementLayer: c,
|
|
1587
|
+
commentTintLayer: a,
|
|
1588
|
+
commentMargin: o,
|
|
1589
|
+
commentDecorationLayer: s,
|
|
1590
|
+
commentRuns: Object.freeze([]),
|
|
1591
|
+
commentGeometry: null,
|
|
1313
1592
|
renderedPage: -1,
|
|
1314
1593
|
renderedScale: -1,
|
|
1315
|
-
dispatcher: new
|
|
1594
|
+
dispatcher: new b(n, this._mode === "worker")
|
|
1316
1595
|
};
|
|
1317
1596
|
}
|
|
1318
1597
|
_recycleSlot(e, t) {
|
|
1319
|
-
this._slots.delete(e), t.dispatcher.destroy(), this._destroyed || (t.dispatcher = new
|
|
1598
|
+
this._slots.delete(e), t.dispatcher.destroy(), this._destroyed || (t.dispatcher = new b(t.canvas, this._mode === "worker")), t.textLayer && (t.textLayer.innerHTML = "", t.textLayer.style.transform = "", t.textLayer.style.transformOrigin = ""), t.highlightLayer.innerHTML = "", t.highlightLayer.style.transform = "", t.highlightLayer.style.transformOrigin = "", t.commentTintLayer && (t.commentTintLayer.replaceChildren(), t.commentTintLayer.style.transform = "", t.commentTintLayer.style.transformOrigin = "", t.commentTintLayer.style.visibility = ""), t.commentMargin && (this._commentUi?.disposeReadOnlyCommentMargin(t.commentMargin), this._commentUi || t.commentMargin.replaceChildren(), t.commentMargin.style.visibility = ""), t.commentDecorationLayer && (this._commentUi?.disposeReadOnlyCommentDecoration(t.commentDecorationLayer), this._commentUi || t.commentDecorationLayer.replaceChildren()), t.commentRuns = Object.freeze([]), t.commentGeometry = null, v(t.elementLayer, null), t.renderedPage = -1, t.renderedScale = -1, t.wrapper.remove(), this._free.push(t);
|
|
1320
1599
|
}
|
|
1321
1600
|
_positionSlot(e, t, n) {
|
|
1322
1601
|
e.wrapper.style.top = `${n.offsets[t]}px`;
|
|
1323
1602
|
let r = this._pageWidthPx(t), i = this._pageHeightPx(t);
|
|
1324
|
-
e.wrapper.style.width = `${r}px`, e.wrapper.style.height = `${i}px`, this.
|
|
1325
|
-
|
|
1326
|
-
|
|
1603
|
+
if (e.wrapper.style.width = `${r}px`, e.wrapper.style.height = `${i}px`, this._syncCommentMarginGeometry(e.commentMargin), e.commentDecorationLayer) {
|
|
1604
|
+
let t = this._commentMarginExtent();
|
|
1605
|
+
e.commentDecorationLayer.style.left = this._commentSide() === "left" ? `${-t}px` : "0px", e.commentDecorationLayer.style.width = `${r + t}px`, e.commentDecorationLayer.style.height = `${i}px`;
|
|
1606
|
+
}
|
|
1607
|
+
this._redrawElementOutlineForSlot(t, e);
|
|
1608
|
+
let { left: a } = this._padH(), o = this._scrollHost.clientWidth, s = this._commentMarginExtent(), c = r + s, l = Math.max(a, (o - c) / 2);
|
|
1609
|
+
e.wrapper.style.left = `${l + (this._commentSide() === "left" ? s : 0)}px`;
|
|
1327
1610
|
}
|
|
1328
1611
|
_dpr() {
|
|
1329
1612
|
return this._opts.dpr ?? (typeof window < "u" && window.devicePixelRatio || 1);
|
|
@@ -1333,9 +1616,9 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1333
1616
|
t.renderedPage = e;
|
|
1334
1617
|
let r = this._dpr(), i = this._pageWidthPx(e), a = this._renderEpoch, o = this._scale, s = t.dispatcher, c = s.begin();
|
|
1335
1618
|
if (this._mode === "worker") return this._renderSlotBitmap(e, t, i, r, o, s, c, n);
|
|
1336
|
-
let l = [], u = !!this._opts.enableTextSelection && !!t.textLayer, d = u || this._findActive, f = d ? (e) => l.push(e) : void 0, p;
|
|
1619
|
+
let l = [], u = !!this._opts.enableTextSelection && !!t.textLayer, d = u || this._findActive || !!t.commentTintLayer, f = d ? (e) => l.push(e) : void 0, p;
|
|
1337
1620
|
try {
|
|
1338
|
-
p = this._doc
|
|
1621
|
+
p = Z(this._doc, t.canvas, e, "main", {
|
|
1339
1622
|
width: i,
|
|
1340
1623
|
dpr: r,
|
|
1341
1624
|
defaultTextColor: this._opts.defaultTextColor,
|
|
@@ -1349,9 +1632,9 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1349
1632
|
if (!(!s.isCurrent(c) || a !== this._renderEpoch || this._slots.get(e) !== t || t.renderedPage !== e)) {
|
|
1350
1633
|
if (t.renderedScale = o, u && t.textLayer) {
|
|
1351
1634
|
let { width: n, height: r } = this._canvasCssPx(t.canvas);
|
|
1352
|
-
|
|
1635
|
+
J(t.textLayer, l, n, r, this._hyperlinkHandler(), (e) => this._measureForFont(e), e);
|
|
1353
1636
|
}
|
|
1354
|
-
d && this._refreshFindRuns(e, l), this._redrawSlotHighlights(e, t);
|
|
1637
|
+
d && this._refreshFindRuns(e, l), this._commitCommentRuns(e, t, l), this._redrawSlotHighlights(e, t);
|
|
1355
1638
|
}
|
|
1356
1639
|
}).catch((r) => {
|
|
1357
1640
|
if (s.isCurrent(c) && a === this._renderEpoch && this._slots.get(e) === t && t.renderedPage === e) if (n) this._reportRenderError(r);
|
|
@@ -1388,9 +1671,9 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1388
1671
|
if (this._bitmapInFlight.has(e) || this._slots.get(e) !== t) return;
|
|
1389
1672
|
let c = this._renderEpoch;
|
|
1390
1673
|
this._bitmapInFlight.add(e);
|
|
1391
|
-
let l = !1, u = !!this._opts.enableTextSelection && !!t.textLayer, d = u || this._findActive, f = [];
|
|
1674
|
+
let l = !1, u = !!this._opts.enableTextSelection && !!t.textLayer, d = u || this._findActive || !!t.commentTintLayer, f = [];
|
|
1392
1675
|
try {
|
|
1393
|
-
let s = await this._doc.
|
|
1676
|
+
let s = await Z(this._doc, t.canvas, e, "worker", {
|
|
1394
1677
|
width: n,
|
|
1395
1678
|
dpr: r,
|
|
1396
1679
|
defaultTextColor: this._opts.defaultTextColor,
|
|
@@ -1407,9 +1690,9 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1407
1690
|
})) return;
|
|
1408
1691
|
if (t.renderedScale = i, t.textLayer && (t.textLayer.style.transform = "", t.textLayer.style.transformOrigin = "", u)) {
|
|
1409
1692
|
let { width: n, height: r } = this._canvasCssPx(t.canvas);
|
|
1410
|
-
|
|
1693
|
+
J(t.textLayer, f, n, r, this._hyperlinkHandler(), (e) => this._measureForFont(e), e);
|
|
1411
1694
|
}
|
|
1412
|
-
d && this._refreshFindRuns(e, f), this._redrawSlotHighlights(e, t), l = !0;
|
|
1695
|
+
d && this._refreshFindRuns(e, f), this._commitCommentRuns(e, t, f), this._redrawSlotHighlights(e, t), l = !0;
|
|
1413
1696
|
} catch (n) {
|
|
1414
1697
|
if (a.isCurrent(o) && c === this._renderEpoch && this._slots.get(e) === t && t.renderedPage === e) if (s) this._reportRenderError(n);
|
|
1415
1698
|
else throw n;
|
|
@@ -1430,12 +1713,12 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1430
1713
|
f = Math.min(1, Math.max(0, f));
|
|
1431
1714
|
let p = this._padH().left, m = this._scrollHost.scrollLeft || 0;
|
|
1432
1715
|
this._renderEpoch++, this._scale = r, this._recomputeHeights();
|
|
1433
|
-
let h =
|
|
1716
|
+
let h = O(this._scrollGeometry, 0, this._scrollHost.clientHeight, this._overscan());
|
|
1434
1717
|
this._spacer.style.height = `${h.totalHeight}px`, this._syncSpacerWidth();
|
|
1435
|
-
let g = Math.max(0, h.totalHeight - this._scrollHost.clientHeight), _ = (h.offsets[u] ?? 0) + f * (this._heights[u] || 0),
|
|
1436
|
-
if (this._scrollHost.scrollTop = Math.min(g, Math.max(0,
|
|
1718
|
+
let g = Math.max(0, h.totalHeight - this._scrollHost.clientHeight), _ = (h.offsets[u] ?? 0) + f * (this._heights[u] || 0), v = l < (s.offsets[0] ?? 0) ? c : _ - o;
|
|
1719
|
+
if (this._scrollHost.scrollTop = Math.min(g, Math.max(0, v)), i) {
|
|
1437
1720
|
let e = Math.max(0, (this._spacer.offsetWidth || 0) - this._scrollHost.clientWidth);
|
|
1438
|
-
this._scrollHost.scrollLeft =
|
|
1721
|
+
this._scrollHost.scrollLeft = ee(m, i.x - p, a, r, { maxScroll: e });
|
|
1439
1722
|
}
|
|
1440
1723
|
this._previewVisible(), this._scheduleSettle(), this._opts.onScaleChange?.(r);
|
|
1441
1724
|
}
|
|
@@ -1443,10 +1726,10 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1443
1726
|
return this._scaleEstablished ? this._scale : this._pendingScale ?? 1;
|
|
1444
1727
|
}
|
|
1445
1728
|
zoomIn() {
|
|
1446
|
-
this.setScale(
|
|
1729
|
+
this.setScale(fe(this.getScale()));
|
|
1447
1730
|
}
|
|
1448
1731
|
zoomOut() {
|
|
1449
|
-
this.setScale(
|
|
1732
|
+
this.setScale(S(this.getScale()));
|
|
1450
1733
|
}
|
|
1451
1734
|
fitWidth() {
|
|
1452
1735
|
this._fit("width");
|
|
@@ -1457,8 +1740,8 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1457
1740
|
_fit(e) {
|
|
1458
1741
|
if (!this._doc || this._doc.pageCount === 0) return;
|
|
1459
1742
|
let t = this._doc.pageSize(0), n = g({
|
|
1460
|
-
contentWidth: t.widthPt *
|
|
1461
|
-
contentHeight: t.heightPt *
|
|
1743
|
+
contentWidth: t.widthPt * D,
|
|
1744
|
+
contentHeight: t.heightPt * D,
|
|
1462
1745
|
containerWidth: this._fitWidthPx(),
|
|
1463
1746
|
containerHeight: this._scrollHost.clientHeight
|
|
1464
1747
|
}, e);
|
|
@@ -1480,15 +1763,19 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1480
1763
|
e.topIndex !== this._lastTopIndex && (this._lastTopIndex = e.topIndex, this._opts.onVisiblePageChange?.(e.topIndex, this._doc.pageCount));
|
|
1481
1764
|
}
|
|
1482
1765
|
_previewSlot(e, t, n) {
|
|
1483
|
-
if (this._positionSlot(e, t, n), e.canvas.style.width = `${this._pageWidthPx(t)}px`, e.canvas.style.height = `${this._pageHeightPx(t)}px`, e.
|
|
1766
|
+
if (this._positionSlot(e, t, n), e.canvas.style.width = `${this._pageWidthPx(t)}px`, e.canvas.style.height = `${this._pageHeightPx(t)}px`, e.renderedScale > 0) {
|
|
1484
1767
|
let t = this._scale / e.renderedScale;
|
|
1485
|
-
e.textLayer.style.transformOrigin = "0 0", e.textLayer.style.transform = `scale(${t})
|
|
1768
|
+
e.textLayer && (e.textLayer.style.transformOrigin = "0 0", e.textLayer.style.transform = `scale(${t})`), e.commentMargin && this._commentUi?.previewReadOnlyCommentMargin(e.commentMargin, t);
|
|
1769
|
+
for (let n of e.commentTintLayer?.children ?? []) n.dataset.ooxmlCommentMarker !== void 0 && (n.style.transform = `translate(-50%,-50%) scale(${t})`);
|
|
1770
|
+
e.commentTintLayer && (e.commentTintLayer.style.visibility = ""), e.commentMargin && (e.commentMargin.style.visibility = ""), e.commentDecorationLayer && (e.commentDecorationLayer.style.visibility = "");
|
|
1771
|
+
return;
|
|
1486
1772
|
}
|
|
1773
|
+
e.commentTintLayer && (e.commentTintLayer.style.visibility = "hidden"), e.commentMargin && (e.commentMargin.style.visibility = "hidden"), e.commentDecorationLayer && (e.commentDecorationLayer.style.visibility = "hidden");
|
|
1487
1774
|
}
|
|
1488
1775
|
_scheduleSettle() {
|
|
1489
1776
|
this._settleTimer !== null && clearTimeout(this._settleTimer), this._settleTimer = setTimeout(() => {
|
|
1490
1777
|
this._settleTimer = null, this._settleRender();
|
|
1491
|
-
},
|
|
1778
|
+
}, Ft);
|
|
1492
1779
|
}
|
|
1493
1780
|
_settleRender() {
|
|
1494
1781
|
if (!(this._destroyed || !this._doc || this._doc.pageCount === 0)) for (let [e, t] of [...this._slots]) t.renderedScale !== this._scale && this._settleSlot(e, t);
|
|
@@ -1502,8 +1789,8 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1502
1789
|
}
|
|
1503
1790
|
let o = document.createElement("canvas");
|
|
1504
1791
|
o.style.cssText = "display:block;background:#fff;", this._applyPageShadow(o);
|
|
1505
|
-
let s = new
|
|
1506
|
-
this._doc
|
|
1792
|
+
let s = new b(o, !1), c = s.begin(), l = [], u = !!this._opts.enableTextSelection && !!t.textLayer, d = u || this._findActive || !!t.commentTintLayer, f = d ? (e) => l.push(e) : void 0;
|
|
1793
|
+
Z(this._doc, o, e, "main", {
|
|
1507
1794
|
width: r,
|
|
1508
1795
|
dpr: n,
|
|
1509
1796
|
defaultTextColor: this._opts.defaultTextColor,
|
|
@@ -1517,21 +1804,88 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1517
1804
|
let n = t.canvas;
|
|
1518
1805
|
if (t.dispatcher.destroy(), t.wrapper.insertBefore(o, n), n.remove(), t.canvas = o, t.dispatcher = s, t.renderedScale = i, t.textLayer && (t.textLayer.style.transform = "", t.textLayer.style.transformOrigin = "", u)) {
|
|
1519
1806
|
let { width: n, height: r } = this._canvasCssPx(o);
|
|
1520
|
-
|
|
1807
|
+
J(t.textLayer, l, n, r, this._hyperlinkHandler(), (e) => this._measureForFont(e), e);
|
|
1521
1808
|
}
|
|
1522
|
-
d && this._refreshFindRuns(e, l), this._redrawSlotHighlights(e, t);
|
|
1809
|
+
d && this._refreshFindRuns(e, l), this._commitCommentRuns(e, t, l), this._redrawSlotHighlights(e, t);
|
|
1523
1810
|
}).catch((n) => {
|
|
1524
1811
|
s.isCurrent(c) && a === this._renderEpoch && this._slots.get(e) === t && t.renderedPage === e && this._reportRenderError(n), s.destroy();
|
|
1525
1812
|
});
|
|
1526
1813
|
}
|
|
1527
1814
|
scrollToPage(e, t) {
|
|
1528
1815
|
if (!this._doc || this._doc.pageCount === 0 || !this._scaleEstablished) return;
|
|
1529
|
-
let n = Math.max(0, Math.min(e, this._doc.pageCount - 1)), r =
|
|
1816
|
+
let n = Math.max(0, Math.min(e, this._doc.pageCount - 1)), r = O(this._scrollGeometry, 0, this._scrollHost.clientHeight, this._overscan()), i = r.offsets[n] ?? 0, a = Math.max(0, r.totalHeight - this._scrollHost.clientHeight), o = Math.min(a, Math.max(0, i)), s = this._scrollHost;
|
|
1530
1817
|
typeof s.scrollTo == "function" ? s.scrollTo({
|
|
1531
1818
|
top: o,
|
|
1532
1819
|
behavior: t?.behavior ?? "auto"
|
|
1533
1820
|
}) : this._scrollHost.scrollTop = o, this._mountVisible();
|
|
1534
1821
|
}
|
|
1822
|
+
_scrollToPageTarget(e, t, n) {
|
|
1823
|
+
let r = O(this._scrollGeometry, 0, this._scrollHost.clientHeight, this._overscan()), i = this._pageWidthPx(e), a = this._commentMarginExtent(), { left: o } = this._padH(), s = Math.max(o, (this._scrollHost.clientWidth - i - a) / 2) + (this._commentSide() === "left" ? a : 0), c = Math.max(0, r.totalHeight - this._scrollHost.clientHeight), l = this._spacer.offsetWidth || Number.parseFloat(this._spacer.style.width) || 0, u = Math.max(0, l - this._scrollHost.clientWidth), d = Math.min(c, Math.max(0, (r.offsets[e] ?? 0) + t.y + t.h / 2 - this._scrollHost.clientHeight / 2)), f = Math.min(u, Math.max(0, s + t.x + t.w / 2 - this._scrollHost.clientWidth / 2)), p = this._scrollHost;
|
|
1824
|
+
typeof p.scrollTo == "function" ? p.scrollTo({
|
|
1825
|
+
top: d,
|
|
1826
|
+
left: f,
|
|
1827
|
+
behavior: n?.behavior ?? "auto"
|
|
1828
|
+
}) : (this._scrollHost.scrollTop = d, this._scrollHost.scrollLeft = f), this._mountVisible();
|
|
1829
|
+
}
|
|
1830
|
+
_resetCommentNavigation() {
|
|
1831
|
+
this._commentNavigationGeneration++, this._commentPageById.clear(), this._commentRunsByPage.clear(), this._commentIndexedPages.clear(), this._commentScanFrontier = 0;
|
|
1832
|
+
}
|
|
1833
|
+
_advanceCommentScanFrontier() {
|
|
1834
|
+
for (; this._commentIndexedPages.has(this._commentScanFrontier);) this._commentScanFrontier++;
|
|
1835
|
+
}
|
|
1836
|
+
_indexCommentPages(e, t, n) {
|
|
1837
|
+
if (!this._commentIndexedPages.has(e)) {
|
|
1838
|
+
for (let r of n) this._commentPageById.has(r.commentId) || j(r, t).length > 0 && this._commentPageById.set(r.commentId, e);
|
|
1839
|
+
this._commentIndexedPages.add(e), this._advanceCommentScanFrontier();
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
async _commentRunsForPage(e, t) {
|
|
1843
|
+
for (; !this._destroyed && this._doc === t;) {
|
|
1844
|
+
let n = this._scale, r = this._commentRunsByPage.get(e);
|
|
1845
|
+
(!r || r.scale !== n) && (r = {
|
|
1846
|
+
scale: n,
|
|
1847
|
+
runs: t.collectPageRuns(e, {
|
|
1848
|
+
width: this._pageWidthPx(e),
|
|
1849
|
+
currentDate: this._opts.currentDate
|
|
1850
|
+
})
|
|
1851
|
+
}, this._commentRunsByPage.set(e, r));
|
|
1852
|
+
try {
|
|
1853
|
+
let e = await r.runs;
|
|
1854
|
+
if (this._destroyed || this._doc !== t) return null;
|
|
1855
|
+
if (this._scale !== n) continue;
|
|
1856
|
+
return e;
|
|
1857
|
+
} catch (t) {
|
|
1858
|
+
throw this._commentRunsByPage.get(e) === r && this._commentRunsByPage.delete(e), t;
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
return null;
|
|
1862
|
+
}
|
|
1863
|
+
async goToComment(e, t) {
|
|
1864
|
+
if (this._destroyed) throw Error("DocxScrollViewer is destroyed");
|
|
1865
|
+
let n = this._doc;
|
|
1866
|
+
if (!n || !n.comments.some((t) => t.id === e && t.parentId === void 0)) return !1;
|
|
1867
|
+
let r = ++this._commentNavigationGeneration, i = n.commentAnchorRanges().filter((t) => t.commentId === e);
|
|
1868
|
+
if (i.length === 0) return !1;
|
|
1869
|
+
let a = t?.pageIndex;
|
|
1870
|
+
if (a !== void 0 && (!Number.isInteger(a) || a < 0 || a >= n.pageCount)) return !1;
|
|
1871
|
+
let o = a ?? this._commentPageById.get(e), s;
|
|
1872
|
+
if (a === void 0 && o === void 0) {
|
|
1873
|
+
let t = n.commentAnchorRanges();
|
|
1874
|
+
for (; o === void 0 && this._commentScanFrontier < n.pageCount;) {
|
|
1875
|
+
let i = this._commentScanFrontier, a = await this._commentRunsForPage(i, n);
|
|
1876
|
+
if (this._destroyed) throw Error("DocxScrollViewer is destroyed");
|
|
1877
|
+
if (this._doc !== n || r !== this._commentNavigationGeneration || !a) return !1;
|
|
1878
|
+
this._indexCommentPages(i, a, t), o = this._commentPageById.get(e);
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
if (o === void 0) return !1;
|
|
1882
|
+
let c = await this._commentRunsForPage(o, n);
|
|
1883
|
+
if (this._destroyed) throw Error("DocxScrollViewer is destroyed");
|
|
1884
|
+
if (this._doc !== n || r !== this._commentNavigationGeneration || !c || (s = i.flatMap((e) => j(e, c))[0], !s)) return !1;
|
|
1885
|
+
this._activeCommentId = e, this._activeCommentPage = o, this._elementContext = null, this._scrollToPageTarget(o, s, t);
|
|
1886
|
+
for (let [e, t] of this._slots) this._redrawSlotComments(e, t);
|
|
1887
|
+
return this._emitSelectionContextChange(), !0;
|
|
1888
|
+
}
|
|
1535
1889
|
async findText(e, t = {}) {
|
|
1536
1890
|
if (!this._doc) return [];
|
|
1537
1891
|
this._findActive = e.length > 0;
|
|
@@ -1562,6 +1916,74 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1562
1916
|
_refreshFindRuns(e, t) {
|
|
1563
1917
|
this._findActive && this._find.setPageRuns(e, t);
|
|
1564
1918
|
}
|
|
1919
|
+
_commitCommentRuns(e, t, n) {
|
|
1920
|
+
t.commentTintLayer && (t.commentRuns = Object.freeze([...n]), this._commentRunsByPage.set(e, {
|
|
1921
|
+
scale: this._scale,
|
|
1922
|
+
runs: Promise.resolve(t.commentRuns)
|
|
1923
|
+
}), this._doc && e === this._commentScanFrontier && this._indexCommentPages(e, t.commentRuns, this._doc.commentAnchorRanges()), t.commentTintLayer.style.transform = "", t.commentTintLayer.style.transformOrigin = "", this._redrawSlotComments(e, t), t.commentTintLayer.style.visibility = "", t.commentMargin && (t.commentMargin.style.visibility = ""), t.commentDecorationLayer && (t.commentDecorationLayer.style.visibility = ""));
|
|
1924
|
+
}
|
|
1925
|
+
_redrawSlotComments(e, t) {
|
|
1926
|
+
if (!this._doc || !t.commentTintLayer) return;
|
|
1927
|
+
let n = this._commentUi;
|
|
1928
|
+
if (!n) {
|
|
1929
|
+
t.commentTintLayer.replaceChildren(), t.commentMargin?.replaceChildren(), t.commentDecorationLayer?.replaceChildren(), t.commentGeometry = null;
|
|
1930
|
+
return;
|
|
1931
|
+
}
|
|
1932
|
+
t.commentGeometry = n.buildDocxCommentMargin(t.commentTintLayer, t.commentMargin, t.commentRuns, {
|
|
1933
|
+
comments: this._doc.comments,
|
|
1934
|
+
anchors: this._doc.commentAnchorRanges()
|
|
1935
|
+
}, this._pageWidthPx(e), this._pageHeightPx(e), this._activeCommentId, (t, n) => {
|
|
1936
|
+
let r = n ? t : this._activeCommentId === t ? null : this._activeCommentId;
|
|
1937
|
+
if (r !== this._activeCommentId) {
|
|
1938
|
+
this._activeCommentId = r, this._activeCommentPage = r ? e : null, this._elementContext = null;
|
|
1939
|
+
for (let [e, t] of this._slots) this._redrawSlotComments(e, t);
|
|
1940
|
+
this._emitSelectionContextChange();
|
|
1941
|
+
}
|
|
1942
|
+
}, this._commentZoom(), 280, this._commentsOptions()?.markers !== !1, this._commentsOptions()?.includeResolved === !0, t.commentDecorationLayer ? () => this._scheduleCommentGeometry(e, t, !1) : void 0, t.commentDecorationLayer ? () => this._scheduleCommentGeometry(e, t, !0) : void 0), this._redrawSlotCommentConnectors(e, t);
|
|
1943
|
+
}
|
|
1944
|
+
_redrawSlotCommentConnectors(e, t) {
|
|
1945
|
+
let n = t.commentDecorationLayer, r = t.commentMargin, i = t.commentGeometry, a = this._commentsOptions()?.connectors;
|
|
1946
|
+
if (!n || !r || !i || !a) return;
|
|
1947
|
+
let o = this._pageWidthPx(e), s = this._pageHeightPx(e), c = this._commentSide(), l = this._commentMarginExtent(), u = this._commentUi;
|
|
1948
|
+
u && u.buildReadOnlyCommentDecoration(n, Object.freeze({
|
|
1949
|
+
surfaceBounds: Object.freeze({
|
|
1950
|
+
x: c === "left" ? -l : 0,
|
|
1951
|
+
y: 0,
|
|
1952
|
+
width: o + l,
|
|
1953
|
+
height: s
|
|
1954
|
+
}),
|
|
1955
|
+
contentBounds: Object.freeze({
|
|
1956
|
+
x: 0,
|
|
1957
|
+
y: 0,
|
|
1958
|
+
width: o,
|
|
1959
|
+
height: s
|
|
1960
|
+
}),
|
|
1961
|
+
side: c,
|
|
1962
|
+
threads: u.projectReadOnlyCommentMarginScroll(i, r.scrollTop)
|
|
1963
|
+
}), {
|
|
1964
|
+
route: a.route ?? "bezier",
|
|
1965
|
+
stroke: a.stroke ?? "solid",
|
|
1966
|
+
color: a.color,
|
|
1967
|
+
activeColor: a.activeColor
|
|
1968
|
+
});
|
|
1969
|
+
}
|
|
1970
|
+
_scheduleCommentGeometry(e, t, n = !1) {
|
|
1971
|
+
let r = this._pendingCommentGeometry.get(e);
|
|
1972
|
+
if (this._pendingCommentGeometry.set(e, {
|
|
1973
|
+
slot: t,
|
|
1974
|
+
connectorsOnly: r?.slot === t ? r.connectorsOnly && n : n
|
|
1975
|
+
}), this._commentGeometryScheduled) return;
|
|
1976
|
+
this._commentGeometryScheduled = !0;
|
|
1977
|
+
let i = () => {
|
|
1978
|
+
this._commentGeometryScheduled = !1, this._commentGeometryFrame = null;
|
|
1979
|
+
let e = [...this._pendingCommentGeometry];
|
|
1980
|
+
if (this._pendingCommentGeometry.clear(), !this._destroyed) for (let [t, n] of e) {
|
|
1981
|
+
let { slot: e, connectorsOnly: r } = n;
|
|
1982
|
+
this._slots.get(t) === e && e.renderedScale === this._scale && (r ? this._redrawSlotCommentConnectors(t, e) : this._redrawSlotComments(t, e));
|
|
1983
|
+
}
|
|
1984
|
+
}, a = this._wrapper.ownerDocument.defaultView;
|
|
1985
|
+
a?.requestAnimationFrame ? this._commentGeometryFrame = a.requestAnimationFrame(i) : queueMicrotask(i);
|
|
1986
|
+
}
|
|
1565
1987
|
_redrawSlotHighlights(e, t) {
|
|
1566
1988
|
if (!this._findActive) {
|
|
1567
1989
|
t.highlightLayer.innerHTML = "";
|
|
@@ -1572,7 +1994,7 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1572
1994
|
t.highlightLayer.innerHTML = "";
|
|
1573
1995
|
return;
|
|
1574
1996
|
}
|
|
1575
|
-
|
|
1997
|
+
Y(t.highlightLayer, n, this._find.pageHighlights(e), this._pageWidthPx(e), this._pageHeightPx(e), (e) => this._measureForFont(e), this._opts.findHighlightColors);
|
|
1576
1998
|
}
|
|
1577
1999
|
_onResize() {
|
|
1578
2000
|
if (!this._doc || this._doc.pageCount === 0) return;
|
|
@@ -1629,7 +2051,7 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1629
2051
|
}
|
|
1630
2052
|
getSelectionContext(e = {}) {
|
|
1631
2053
|
if (this._destroyed) throw Error("DocxScrollViewer is destroyed");
|
|
1632
|
-
return (this._opts.enableTextSelection ?
|
|
2054
|
+
return (this._doc && this._activeCommentId !== null && this._activeCommentPage !== null ? kt(this._doc.comments, this._doc.commentAnchorRanges(), this._activeCommentId, this._activeCommentPage, e) : null) || ((this._opts.enableTextSelection ? X(this._wrapper, this._wrapper.ownerDocument?.getSelection?.() ?? null, e) : null) ?? (this._elementContext ? R(this._elementContext, e.maxTextCharacters) : null));
|
|
1633
2055
|
}
|
|
1634
2056
|
_emitSelectionContextChange() {
|
|
1635
2057
|
let e = this.getSelectionContext();
|
|
@@ -1649,11 +2071,11 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1649
2071
|
_redrawElementOutlineForSlot(e, t) {
|
|
1650
2072
|
let n = this._elementContext, r = this._doc;
|
|
1651
2073
|
if (!n || !r || n.pageIndex !== e) {
|
|
1652
|
-
|
|
2074
|
+
v(t.elementLayer, null);
|
|
1653
2075
|
return;
|
|
1654
2076
|
}
|
|
1655
2077
|
let i = r.pageSize(e);
|
|
1656
|
-
|
|
2078
|
+
v(t.elementLayer, {
|
|
1657
2079
|
x: n.bounds.xPt / i.widthPt,
|
|
1658
2080
|
y: n.bounds.yPt / i.heightPt,
|
|
1659
2081
|
width: n.bounds.widthPt / i.widthPt,
|
|
@@ -1673,7 +2095,7 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1673
2095
|
async _resolveContextAt(e) {
|
|
1674
2096
|
let t = this._doc;
|
|
1675
2097
|
if (this._destroyed || !t) return null;
|
|
1676
|
-
if (this._opts.enableTextSelection &&
|
|
2098
|
+
if (this._opts.enableTextSelection && X(this._wrapper, this._wrapper.ownerDocument?.getSelection?.() ?? null)) return this._emitSelectionContextChange(), this._destroyed ? null : this.getSelectionContext();
|
|
1677
2099
|
if (!this._opts.enableElementSelection) return this.getSelectionContext();
|
|
1678
2100
|
let n = e.target, r = [...this._slots].find(([, e]) => n !== null && e.wrapper.contains(n));
|
|
1679
2101
|
if (!r) return this._invalidateElementContext(), null;
|
|
@@ -1688,7 +2110,7 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1688
2110
|
yPt: c / o.height * u.heightPt
|
|
1689
2111
|
}, {
|
|
1690
2112
|
currentDate: this._opts.currentDate,
|
|
1691
|
-
maxTextCharacters:
|
|
2113
|
+
maxTextCharacters: P
|
|
1692
2114
|
});
|
|
1693
2115
|
} catch (e) {
|
|
1694
2116
|
if (this._destroyed || l !== this._elementHitGeneration || t !== this._doc) return null;
|
|
@@ -1698,7 +2120,7 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1698
2120
|
}
|
|
1699
2121
|
destroy() {
|
|
1700
2122
|
if (!this._destroyed) {
|
|
1701
|
-
this._destroyed = !0, this._find.invalidate(), this._findActive = !1, this._selectionChangeListener &&= (this._wrapper.ownerDocument.removeEventListener("selectionchange", this._selectionChangeListener), null), this._elementHitGeneration++, this._elementClickListener &&= (this._scrollHost.removeEventListener("click", this._elementClickListener), null), this._contextMenuListener &&= (this._scrollHost.removeEventListener("contextmenu", this._contextMenuListener), null), this._elementContext = null, this._scrollListener &&= (this._scrollHost.removeEventListener("scroll", this._scrollListener), null), this._wheelListener &&= (this._scrollHost.removeEventListener("wheel", this._wheelListener), null), this._resizeObserver?.disconnect(), this._resizeObserver = null, this._settleTimer !== null && (clearTimeout(this._settleTimer), this._settleTimer = null);
|
|
2123
|
+
this._destroyed = !0, this._resetCommentNavigation(), this._find.invalidate(), this._findActive = !1, this._selectionChangeListener &&= (this._wrapper.ownerDocument.removeEventListener("selectionchange", this._selectionChangeListener), null), this._elementHitGeneration++, this._elementClickListener &&= (this._scrollHost.removeEventListener("click", this._elementClickListener), null), this._contextMenuListener &&= (this._scrollHost.removeEventListener("contextmenu", this._contextMenuListener), null), this._commentOutsidePointerListener &&= (this._wrapper.ownerDocument.removeEventListener("pointerdown", this._commentOutsidePointerListener), null), this._commentGeometryFrame !== null && (this._wrapper.ownerDocument.defaultView?.cancelAnimationFrame?.(this._commentGeometryFrame), this._commentGeometryFrame = null), this._commentGeometryScheduled = !1, this._pendingCommentGeometry.clear(), this._elementContext = null, this._scrollListener &&= (this._scrollHost.removeEventListener("scroll", this._scrollListener), null), this._wheelListener &&= (this._scrollHost.removeEventListener("wheel", this._wheelListener), null), this._resizeObserver?.disconnect(), this._resizeObserver = null, this._settleTimer !== null && (clearTimeout(this._settleTimer), this._settleTimer = null);
|
|
1702
2124
|
for (let [e, t] of [...this._slots]) this._recycleSlot(e, t);
|
|
1703
2125
|
this._free.length = 0, this._documentOwner.close(), this._wrapper.remove();
|
|
1704
2126
|
}
|
|
@@ -1706,7 +2128,7 @@ var Q = Symbol("DocxViewer.borrowedDocument"), dt = class e {
|
|
|
1706
2128
|
};
|
|
1707
2129
|
//#endregion
|
|
1708
2130
|
//#region packages/docx/src/types.ts
|
|
1709
|
-
function
|
|
2131
|
+
function Ht(e) {
|
|
1710
2132
|
let t = [];
|
|
1711
2133
|
for (let n of e.content) {
|
|
1712
2134
|
if (n.type !== "paragraph") continue;
|
|
@@ -1718,20 +2140,23 @@ function $(e) {
|
|
|
1718
2140
|
}
|
|
1719
2141
|
//#endregion
|
|
1720
2142
|
//#region src/docx.ts
|
|
1721
|
-
var
|
|
1722
|
-
DocxDocument: () =>
|
|
1723
|
-
DocxScrollViewer: () =>
|
|
1724
|
-
DocxViewer: () =>
|
|
1725
|
-
OoxmlDecodedImageLimitError: () =>
|
|
2143
|
+
var Ut = /* @__PURE__ */ e({
|
|
2144
|
+
DocxDocument: () => K,
|
|
2145
|
+
DocxScrollViewer: () => Vt,
|
|
2146
|
+
DocxViewer: () => Q,
|
|
2147
|
+
OoxmlDecodedImageLimitError: () => Ve,
|
|
1726
2148
|
OoxmlError: () => i,
|
|
1727
2149
|
OoxmlResourceLimitError: () => o,
|
|
1728
|
-
autoResize: () =>
|
|
1729
|
-
buildDocxHighlightLayer: () =>
|
|
1730
|
-
buildDocxTextLayer: () =>
|
|
1731
|
-
isOoxmlDecodedImageLimitError: () =>
|
|
1732
|
-
noteText: () =>
|
|
2150
|
+
autoResize: () => pe,
|
|
2151
|
+
buildDocxHighlightLayer: () => Y,
|
|
2152
|
+
buildDocxTextLayer: () => J,
|
|
2153
|
+
isOoxmlDecodedImageLimitError: () => He,
|
|
2154
|
+
noteText: () => Ht,
|
|
1733
2155
|
openExternalHyperlink: () => s,
|
|
1734
|
-
readDocxTextSelectionContext: () =>
|
|
2156
|
+
readDocxTextSelectionContext: () => X,
|
|
2157
|
+
resolveCommentAnchorRuns: () => j,
|
|
2158
|
+
resolveDocxCommentThreads: () => M,
|
|
2159
|
+
resolveRevisionAnchorRuns: () => U
|
|
1735
2160
|
});
|
|
1736
2161
|
//#endregion
|
|
1737
|
-
export {
|
|
2162
|
+
export { X as a, K as c, Q as i, U as l, Ht as n, Y as o, Vt as r, J as s, Ut as t };
|