@silurus/ooxml 0.82.1 → 0.83.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 +72 -3
- package/dist/assets/{render-worker-Cy-QsDge.js → render-worker-Bu31cf1J.js} +4 -4
- package/dist/assets/render-worker-DuztdEcX.js +11 -0
- package/dist/{canvas-viewer-mechanics-CS_qbr6T.js → canvas-viewer-mechanics-h07vpVOQ.js} +42 -2
- package/dist/{comment-ui-runtime-C1RV_3iu.js → comment-ui-runtime-BelHJt73.js} +2 -2
- package/dist/{comment-ui-runtime-DgCZpPR0.js → comment-ui-runtime-DD5a3x3k.js} +2 -2
- package/dist/{comments-Cf9W7r3M.js → comments-AAaNnQTi.js} +7 -2
- package/dist/{document-pull-client-B1WOjA0z.js → document-pull-client-BAhqoTmm.js} +4508 -3952
- package/dist/docx-Dg73PGgC.js +2707 -0
- package/dist/docx.mjs +6 -6
- package/dist/docx_parser_bg.wasm +0 -0
- package/dist/dom-interaction-boundary-CepOlXt6.js +217 -0
- package/dist/index.mjs +4 -4
- package/dist/line-distribute-D7A_wnJg.js +1003 -0
- package/dist/{line-metrics-B3syvDn2.js → line-metrics-Bpn7OeZD.js} +616 -616
- package/dist/node.mjs +308 -308
- package/dist/pptx-BcUCETmQ.js +2990 -0
- package/dist/pptx.mjs +5 -5
- package/dist/pptx_parser_bg.wasm +0 -0
- package/dist/{render-BC8p7vZQ.js → render-CL-7V3E8.js} +1 -1
- package/dist/{render-worker-host-DhnkTyjj.js → render-worker-host-DDZo0feh.js} +1 -1
- package/dist/{render-worker-host-BNnXCtAu.js → render-worker-host-FJ19-fUI.js} +1 -1
- package/dist/{resource-measurement-CsW4_eYt.js → resource-measurement-DuiFWzam.js} +3 -3
- package/dist/{session-Da7LEQUB.js → session-BjydZEDF.js} +107 -94
- package/dist/{slide-pull-client-Bg9DusLX.js → slide-pull-client-CwvvncPA.js} +1158 -935
- package/dist/types/docx.d.ts +98 -8
- package/dist/types/index.d.ts +184 -13
- package/dist/types/node.d.ts +2 -2
- package/dist/types/pptx.d.ts +94 -5
- package/dist/types/xlsx.d.ts +2 -2
- package/dist/{worksheet-pull-client-CYtwXP5D.js → worksheet-pull-client-DyFsDF4A.js} +32 -32
- package/dist/{xlsx-DMWeXT-c.js → xlsx-BibrHQ52.js} +476 -476
- package/dist/xlsx.mjs +5 -5
- package/dist/xlsx_parser_bg.wasm +0 -0
- package/package.json +3 -1
- package/dist/assets/render-worker-aHayzR7v.js +0 -11
- package/dist/docx-HoZXZUPA.js +0 -2162
- package/dist/dom-interaction-boundary-C8F6HO5x.js +0 -119
- package/dist/line-distribute-iXsUCIH-.js +0 -1003
- package/dist/pptx-DEUP4Yq5.js +0 -2432
- /package/dist/{comment-occurrence-C34fWs_F.js → comment-occurrence-X54si2ob.js} +0 -0
- /package/dist/{highlight-rect-MaCt0om0.js → highlight-rect-Hes0z_Mj.js} +0 -0
|
@@ -0,0 +1,2707 @@
|
|
|
1
|
+
import { t as e } from "./chunk-DmhlhrBa.js";
|
|
2
|
+
import { B as t, Qt as n, R as r, Vt as i, W as a, Zt as o, a as s, et as c, ft as l, lt as u, z as d } from "./line-metrics-Bpn7OeZD.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 S, s as ce, t as le, u as ue, v as C, w as de, x as fe, y as w } from "./canvas-viewer-mechanics-h07vpVOQ.js";
|
|
4
|
+
import { a as pe, i as me, t as he } from "./bounded-raw-part-cache-C6ro6Ezf.js";
|
|
5
|
+
import { c as ge, i as _e, l as ve, n as ye, o as T, r as be, s as xe, t as Se } from "./dom-interaction-boundary-CepOlXt6.js";
|
|
6
|
+
import { A as Ce, C as E, D, E as we, O, S as Te, T as Ee, _ as De, a as Oe, b as ke, c as Ae, d as je, f as Me, g as Ne, h as Pe, j as Fe, k as Ie, l as Le, m as Re, n as k, o as ze, p as Be, s as Ve, t as A, v as He, w as Ue, x as j, y as We } from "./document-pull-client-BAhqoTmm.js";
|
|
7
|
+
import { cn as Ge, ln as Ke } from "./plot-area-frame-DHV02PJU.js";
|
|
8
|
+
import { a as M } from "./units-BzZ0gAxs.js";
|
|
9
|
+
import { n as qe } from "./renderer-module-contract-DLbb7zY0.js";
|
|
10
|
+
import { n as Je, t as N } from "./highlight-rect-Hes0z_Mj.js";
|
|
11
|
+
import { o as P } from "./source-key-BklvnEyQ.js";
|
|
12
|
+
import { i as Ye, n as F, r as Xe, t as Ze } from "./comments-AAaNnQTi.js";
|
|
13
|
+
//#region packages/docx/src/worker.ts?worker&inline
|
|
14
|
+
var Qe = "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)})}};", $e = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", Qe], { type: "text/javascript;charset=utf-8" });
|
|
15
|
+
function et(e) {
|
|
16
|
+
let t;
|
|
17
|
+
try {
|
|
18
|
+
if (t = $e && (self.URL || self.webkitURL).createObjectURL($e), !t) throw "";
|
|
19
|
+
let n = new Worker(t, {
|
|
20
|
+
type: "module",
|
|
21
|
+
name: e?.name
|
|
22
|
+
});
|
|
23
|
+
return n.addEventListener("error", () => {
|
|
24
|
+
(self.URL || self.webkitURL).revokeObjectURL(t);
|
|
25
|
+
}), n;
|
|
26
|
+
} catch {
|
|
27
|
+
return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(Qe), {
|
|
28
|
+
type: "module",
|
|
29
|
+
name: e?.name
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region packages/docx/src/wasm/docx_parser_bg.wasm?url
|
|
35
|
+
var tt = new URL("docx_parser_bg.wasm", import.meta.url).href;
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region packages/docx/src/bookmark-nav.ts
|
|
38
|
+
function nt(e) {
|
|
39
|
+
let t = /* @__PURE__ */ new Map();
|
|
40
|
+
for (let n of e.pages) for (let e of n.bookmarkStarts) e.name !== "" && !t.has(e.name) && t.set(e.name, n.pageIndex);
|
|
41
|
+
return t;
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region packages/docx/src/embedded-fonts.ts
|
|
45
|
+
async function rt(e, t) {
|
|
46
|
+
let n = e.embeddedFonts;
|
|
47
|
+
if (!n || n.length === 0) return [];
|
|
48
|
+
let r = (await Promise.all(n.map(async (e) => {
|
|
49
|
+
try {
|
|
50
|
+
let n = await t(e.partPath);
|
|
51
|
+
return {
|
|
52
|
+
family: e.fontName,
|
|
53
|
+
bytes: n,
|
|
54
|
+
odttf: e.partPath.toLowerCase().endsWith(".odttf"),
|
|
55
|
+
fontKey: e.fontKey,
|
|
56
|
+
weight: it(e.style),
|
|
57
|
+
style: at(e.style)
|
|
58
|
+
};
|
|
59
|
+
} catch {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}))).filter((e) => e !== null);
|
|
63
|
+
return r.length === 0 ? [] : ge(r);
|
|
64
|
+
}
|
|
65
|
+
function it(e) {
|
|
66
|
+
return e === "bold" || e === "boldItalic" ? "bold" : "normal";
|
|
67
|
+
}
|
|
68
|
+
function at(e) {
|
|
69
|
+
return e === "italic" || e === "boldItalic" ? "italic" : "normal";
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region packages/docx/src/element-context.ts
|
|
73
|
+
var I = ue, ot = 16384;
|
|
74
|
+
function st(e, t) {
|
|
75
|
+
let n = Math.min(e.length, t);
|
|
76
|
+
if (n > 0 && n < e.length) {
|
|
77
|
+
let t = e.charCodeAt(n - 1), r = e.charCodeAt(n);
|
|
78
|
+
t >= 55296 && t <= 56319 && r >= 56320 && r <= 57343 && n--;
|
|
79
|
+
}
|
|
80
|
+
return e.slice(0, n);
|
|
81
|
+
}
|
|
82
|
+
function ct(e, t) {
|
|
83
|
+
let n = [], r = 0, i = !1;
|
|
84
|
+
for (let a of e) {
|
|
85
|
+
if (a.length === 0) continue;
|
|
86
|
+
if (r > 0) {
|
|
87
|
+
if (r >= t) {
|
|
88
|
+
i = !0;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
n.push("\n"), r++;
|
|
92
|
+
}
|
|
93
|
+
let e = st(a, Math.max(0, t - r));
|
|
94
|
+
if (n.push(e), r += e.length, e.length < a.length) {
|
|
95
|
+
i = !0;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
let a = n.join("");
|
|
100
|
+
return {
|
|
101
|
+
...a.length === 0 ? {} : { text: a },
|
|
102
|
+
truncated: i
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function* L(e) {
|
|
106
|
+
if (e.kind === "paragraph") {
|
|
107
|
+
for (let t of e.lines) {
|
|
108
|
+
let e = t.placements.flatMap((e) => e.kind === "text" ? [e.text] : []).join("");
|
|
109
|
+
e && (yield e);
|
|
110
|
+
}
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (e.kind === "table") {
|
|
114
|
+
for (let t of e.rows) for (let e of t.cells) for (let t of e.blocks) yield* L(t.layout);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (e.kind === "note" || e.kind === "textbox") for (let t of e.story.blocks) yield* L(t);
|
|
118
|
+
}
|
|
119
|
+
function* lt(e) {
|
|
120
|
+
for (let t of e.drawing.commands) (t.kind === "text" || t.kind === "watermark-text") && (yield t.text);
|
|
121
|
+
for (let t of e.textBoxes) yield* L(t);
|
|
122
|
+
}
|
|
123
|
+
function R(e) {
|
|
124
|
+
let t = e ?? ot;
|
|
125
|
+
if (!Number.isFinite(t) || t < 0) throw RangeError("maxTextCharacters must be a finite non-negative number.");
|
|
126
|
+
return Math.min(I, Math.floor(t));
|
|
127
|
+
}
|
|
128
|
+
function ut(e) {
|
|
129
|
+
return {
|
|
130
|
+
story: e.story,
|
|
131
|
+
storyInstance: e.storyInstance,
|
|
132
|
+
path: [...e.path]
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function dt(e) {
|
|
136
|
+
return "drawing" in e ? e.drawing.inkBounds : e.placement.bounds;
|
|
137
|
+
}
|
|
138
|
+
function ft(e) {
|
|
139
|
+
let t = dt(e), n = [
|
|
140
|
+
E(e.pointToPage, t),
|
|
141
|
+
E(e.pointToPage, {
|
|
142
|
+
xPt: t.xPt + t.widthPt,
|
|
143
|
+
yPt: t.yPt
|
|
144
|
+
}),
|
|
145
|
+
E(e.pointToPage, {
|
|
146
|
+
xPt: t.xPt,
|
|
147
|
+
yPt: t.yPt + t.heightPt
|
|
148
|
+
}),
|
|
149
|
+
E(e.pointToPage, {
|
|
150
|
+
xPt: t.xPt + t.widthPt,
|
|
151
|
+
yPt: t.yPt + t.heightPt
|
|
152
|
+
})
|
|
153
|
+
], r = Math.min(...n.map((e) => e.xPt)), i = Math.min(...n.map((e) => e.yPt)), a = Math.max(...n.map((e) => e.xPt)), o = Math.max(...n.map((e) => e.yPt));
|
|
154
|
+
return {
|
|
155
|
+
xPt: r,
|
|
156
|
+
yPt: i,
|
|
157
|
+
widthPt: a - r,
|
|
158
|
+
heightPt: o - i
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function z(e, t) {
|
|
162
|
+
return t.xPt >= e.xPt && t.xPt <= e.xPt + e.widthPt && t.yPt >= e.yPt && t.yPt <= e.yPt + e.heightPt;
|
|
163
|
+
}
|
|
164
|
+
function pt(e, t) {
|
|
165
|
+
let n = !1;
|
|
166
|
+
for (let r = 0, i = t.length - 1; r < t.length; i = r++) {
|
|
167
|
+
let a = t[r], o = t[i];
|
|
168
|
+
a.yPt > e.yPt != o.yPt > e.yPt && e.xPt < (o.xPt - a.xPt) * (e.yPt - a.yPt) / (o.yPt - a.yPt) + a.xPt && (n = !n);
|
|
169
|
+
}
|
|
170
|
+
return n;
|
|
171
|
+
}
|
|
172
|
+
function mt(e, t) {
|
|
173
|
+
return z(e.inkBounds, t) ? e.clip ? e.clip.kind === "rect" ? z(e.clip.rect, t) : pt(t, e.clip.points) : !0 : !1;
|
|
174
|
+
}
|
|
175
|
+
function ht(e, t, n) {
|
|
176
|
+
for (let n of e.clips) {
|
|
177
|
+
let e = Te(n.pointToPage, t);
|
|
178
|
+
if (!e || !z(n.bounds, e)) return !1;
|
|
179
|
+
}
|
|
180
|
+
return "drawing" in e ? mt(e.drawing, n) : z(e.placement.bounds, n);
|
|
181
|
+
}
|
|
182
|
+
function B(e, t) {
|
|
183
|
+
return e.commands.find((e) => e.kind === "resource" && e.resourceKind === t);
|
|
184
|
+
}
|
|
185
|
+
function gt(e) {
|
|
186
|
+
return B(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" : B(e, "image") ? "image" : null;
|
|
187
|
+
}
|
|
188
|
+
function _t(e, t, n, r, i, a) {
|
|
189
|
+
let o = "drawing" in e ? gt(e.drawing) : e.placement.resourceKind;
|
|
190
|
+
if (!o) return null;
|
|
191
|
+
let s, c = !1, l, u;
|
|
192
|
+
if (o === "chart") {
|
|
193
|
+
let t = "drawing" in e ? B(e.drawing, "chart").resourceKey : e.placement.resourceKey, n = i.resolve(t, "chart"), r = y(n.model, a);
|
|
194
|
+
s = r.text, c = r.truncated, u = n.model.series.length;
|
|
195
|
+
} else if (o === "image") {
|
|
196
|
+
let t = "drawing" in e ? B(e.drawing, "image").resourceKey : e.placement.resourceKey, n = i.descriptors.find((e) => e.resourceKey === t && e.kind === "image" && "mimeType" in e);
|
|
197
|
+
if (!n) throw Error(`Unknown image paint resource: ${t}`);
|
|
198
|
+
l = n.mimeType;
|
|
199
|
+
} else {
|
|
200
|
+
let t = ct(lt(e), a);
|
|
201
|
+
s = t.text, c = t.truncated;
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
format: "docx",
|
|
205
|
+
kind: "element",
|
|
206
|
+
pageIndex: t,
|
|
207
|
+
elementIndex: n,
|
|
208
|
+
elementType: o,
|
|
209
|
+
point: { ...r },
|
|
210
|
+
bounds: ft(e),
|
|
211
|
+
source: ut("drawing" in e ? e.drawing.source : e.source),
|
|
212
|
+
...s === void 0 ? {} : { text: s },
|
|
213
|
+
...l === void 0 ? {} : { mimeType: l },
|
|
214
|
+
...u === void 0 ? {} : { seriesCount: u },
|
|
215
|
+
truncated: c,
|
|
216
|
+
truncationReasons: c ? ["text"] : [],
|
|
217
|
+
textCharacters: s?.length ?? 0,
|
|
218
|
+
maxTextCharacters: a
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
function vt(e, t, n, r, i = {}) {
|
|
222
|
+
if (!Number.isFinite(n.xPt) || !Number.isFinite(n.yPt)) throw RangeError("DOCX hit-test point must contain finite page coordinates.");
|
|
223
|
+
let a = R(i.maxTextCharacters), o = ke(e, t);
|
|
224
|
+
for (let e = o.length - 1; e >= 0; e--) {
|
|
225
|
+
let i = o[e], s = Te(i.pointToPage, n);
|
|
226
|
+
if (!s || !ht(i, n, s)) continue;
|
|
227
|
+
let c = _t(i, t, e, n, r, a);
|
|
228
|
+
if (c) return c;
|
|
229
|
+
}
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
function yt(e, t, n, r) {
|
|
233
|
+
return vt(Ue(e, {
|
|
234
|
+
currentDate: r.currentDate,
|
|
235
|
+
defaultCurrentDateMs: r.defaultCurrentDateMs,
|
|
236
|
+
showTrackedChanges: r.showTrackedChanges
|
|
237
|
+
}, t).layout, t, n, Ie(e), r);
|
|
238
|
+
}
|
|
239
|
+
function bt(e, t) {
|
|
240
|
+
let n = R(t), r = e.text === void 0 ? void 0 : st(e.text, n), i = e.truncated || e.text !== void 0 && r.length < e.text.length;
|
|
241
|
+
return {
|
|
242
|
+
...structuredClone(e),
|
|
243
|
+
...r === void 0 ? {} : { text: r },
|
|
244
|
+
truncated: i,
|
|
245
|
+
truncationReasons: i ? ["text"] : [],
|
|
246
|
+
textCharacters: r?.length ?? 0,
|
|
247
|
+
maxTextCharacters: n
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
//#endregion
|
|
251
|
+
//#region packages/docx/src/revisions.ts
|
|
252
|
+
function V(e) {
|
|
253
|
+
let t = Ye(e.id);
|
|
254
|
+
return t === void 0 ? void 0 : `${e.kind}\u0000${t}`;
|
|
255
|
+
}
|
|
256
|
+
function H(e) {
|
|
257
|
+
return Object.freeze({
|
|
258
|
+
...e,
|
|
259
|
+
path: Object.freeze([...e.path])
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
function xt(e, t) {
|
|
263
|
+
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]);
|
|
264
|
+
}
|
|
265
|
+
function U(e, t) {
|
|
266
|
+
let n = 0, r = e.length;
|
|
267
|
+
for (; n < r;) {
|
|
268
|
+
let i = n + Math.floor((r - n) / 2);
|
|
269
|
+
e[i] < t ? n = i + 1 : r = i;
|
|
270
|
+
}
|
|
271
|
+
return n;
|
|
272
|
+
}
|
|
273
|
+
function St(e, t) {
|
|
274
|
+
let n = Array(e.length), r;
|
|
275
|
+
for (let i = e.length - 1; i >= 0; --i) {
|
|
276
|
+
n[i] = r;
|
|
277
|
+
let a = e[i], o = t.get(P(a.source))?.[0];
|
|
278
|
+
o !== void 0 && (r = Object.freeze({
|
|
279
|
+
source: H(a.source),
|
|
280
|
+
sourceRunIndex: o
|
|
281
|
+
}));
|
|
282
|
+
}
|
|
283
|
+
let i = Array(e.length), a;
|
|
284
|
+
for (let n = 0; n < e.length; n += 1) {
|
|
285
|
+
i[n] = a;
|
|
286
|
+
let r = e[n], o = t.get(P(r.source))?.at(-1);
|
|
287
|
+
o !== void 0 && (a = Object.freeze({
|
|
288
|
+
source: H(r.source),
|
|
289
|
+
sourceRunIndex: o
|
|
290
|
+
}));
|
|
291
|
+
}
|
|
292
|
+
return {
|
|
293
|
+
following: n,
|
|
294
|
+
preceding: i
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
function Ct(e, t, n, r, i, a) {
|
|
298
|
+
let o = r[e], s = i.get(P(o.source)) ?? [], c = s[U(s, n)], l = s[U(s, t) - 1], u = c ?? l;
|
|
299
|
+
return u === void 0 ? a.following[e] ?? a.preceding[e] : Object.freeze({
|
|
300
|
+
source: H(o.source),
|
|
301
|
+
sourceRunIndex: u
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
function wt(e, t, n = /* @__PURE__ */ new Map()) {
|
|
305
|
+
let r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set();
|
|
306
|
+
e.forEach((e, t) => {
|
|
307
|
+
let n = V(e);
|
|
308
|
+
n === void 0 || i.has(n) || (r.has(n) ? (r.delete(n), i.add(n)) : r.set(n, t));
|
|
309
|
+
});
|
|
310
|
+
let a = t.blocks.sources.flatMap((e) => {
|
|
311
|
+
if (e.story !== "body") return [];
|
|
312
|
+
let n = t.blocks.resolve(e);
|
|
313
|
+
return n.type === "paragraph" ? [{
|
|
314
|
+
source: e,
|
|
315
|
+
runs: n.runs
|
|
316
|
+
}] : [];
|
|
317
|
+
}), o = new Map([...n].map(([e, t]) => [e, Object.freeze([...t].sort((e, t) => e - t))])), s = St(a, o), c = [];
|
|
318
|
+
for (let [e, t] of a.entries()) {
|
|
319
|
+
let n = 0;
|
|
320
|
+
for (; n < t.runs.length;) {
|
|
321
|
+
let i = t.runs[n], l = i.revision?.kind ? V({
|
|
322
|
+
kind: i.revision.kind,
|
|
323
|
+
id: i.revision.id
|
|
324
|
+
}) : void 0, u = l === void 0 ? void 0 : r.get(l);
|
|
325
|
+
if (u === void 0) {
|
|
326
|
+
n += 1;
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
let d = n;
|
|
330
|
+
for (n += 1; n < t.runs.length;) {
|
|
331
|
+
let e = t.runs[n].revision;
|
|
332
|
+
if (!e?.kind || V({
|
|
333
|
+
kind: e.kind,
|
|
334
|
+
id: e.id
|
|
335
|
+
}) !== l) break;
|
|
336
|
+
n += 1;
|
|
337
|
+
}
|
|
338
|
+
let f = n, p = o.get(P(t.source)) ?? [], m = (p[U(p, d)] ?? f) < f ? void 0 : Ct(e, d, f, a, o, s);
|
|
339
|
+
c.push(Object.freeze({
|
|
340
|
+
revisionIndex: u,
|
|
341
|
+
source: H(t.source),
|
|
342
|
+
startRunIndex: d,
|
|
343
|
+
endRunIndex: f,
|
|
344
|
+
...m === void 0 ? {} : { geometryFallback: m }
|
|
345
|
+
}));
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return c;
|
|
349
|
+
}
|
|
350
|
+
function Tt(e, t, n = /* @__PURE__ */ new Map(), r = {}) {
|
|
351
|
+
if ((e?.length ?? 0) === 0) return [];
|
|
352
|
+
let i = wt(e ?? [], t, n), a = r.completedSourceKeys;
|
|
353
|
+
return a === void 0 ? i : i.filter((e) => {
|
|
354
|
+
let t = n.get(P(e.source));
|
|
355
|
+
return t !== void 0 && [...t].some((t) => t >= e.startRunIndex && t < e.endRunIndex) || a.has(P(e.source));
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
function Et(e, t) {
|
|
359
|
+
let n = t.filter((t) => t.sourceRunIndex !== void 0 && xt(t.source, e.source) && t.sourceRunIndex >= e.startRunIndex && t.sourceRunIndex < e.endRunIndex);
|
|
360
|
+
if (n.length > 0) return n;
|
|
361
|
+
let r = e.geometryFallback;
|
|
362
|
+
return r === void 0 ? [] : t.filter((e) => e.sourceRunIndex === r.sourceRunIndex && xt(e.source, r.source));
|
|
363
|
+
}
|
|
364
|
+
//#endregion
|
|
365
|
+
//#region packages/docx/src/layout/progressive.ts
|
|
366
|
+
var Dt = 12;
|
|
367
|
+
async function Ot(e, t, n, r = {}) {
|
|
368
|
+
let { onPreview: i, scheduler: a } = r;
|
|
369
|
+
return Ne(De(e, t, n, i && e.sequence.length > Dt ? { onPages: (e, t) => {
|
|
370
|
+
i(Object.freeze({
|
|
371
|
+
layout: e,
|
|
372
|
+
exact: !1,
|
|
373
|
+
coveredEntries: t
|
|
374
|
+
}));
|
|
375
|
+
} } : void 0), a);
|
|
376
|
+
}
|
|
377
|
+
//#endregion
|
|
378
|
+
//#region packages/docx/src/document-layout-events.ts
|
|
379
|
+
var W = /* @__PURE__ */ new WeakMap();
|
|
380
|
+
function G(e, t) {
|
|
381
|
+
let n = Object.freeze({ ...t });
|
|
382
|
+
for (let t of [...W.get(e) ?? []]) try {
|
|
383
|
+
t.notify(n);
|
|
384
|
+
} catch (e) {
|
|
385
|
+
try {
|
|
386
|
+
t.report(e);
|
|
387
|
+
} catch {}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
function kt(e, t, n, r) {
|
|
391
|
+
let i = W.get(e);
|
|
392
|
+
i || (i = /* @__PURE__ */ new Set(), W.set(e, i));
|
|
393
|
+
let a = Object.freeze({
|
|
394
|
+
notify: n,
|
|
395
|
+
report: r
|
|
396
|
+
});
|
|
397
|
+
i.add(a);
|
|
398
|
+
try {
|
|
399
|
+
n(Object.freeze({ ...t() }));
|
|
400
|
+
} catch (e) {
|
|
401
|
+
try {
|
|
402
|
+
r(e);
|
|
403
|
+
} catch {}
|
|
404
|
+
}
|
|
405
|
+
return () => {
|
|
406
|
+
i?.delete(a), i?.size === 0 && W.delete(e);
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
//#endregion
|
|
410
|
+
//#region packages/docx/src/document.ts
|
|
411
|
+
function At(e, t) {
|
|
412
|
+
return e !== null && e.currentDateMs === t.currentDateMs && e.showTrackedChanges === !0 == (t.showTrackedChanges === !0);
|
|
413
|
+
}
|
|
414
|
+
function jt() {
|
|
415
|
+
let e, t;
|
|
416
|
+
return {
|
|
417
|
+
promise: new Promise((n, r) => {
|
|
418
|
+
e = n, t = r;
|
|
419
|
+
}),
|
|
420
|
+
resolve: e,
|
|
421
|
+
reject: t
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
var Mt = Object.freeze([]), Nt = Object.freeze([]), Pt = Object.freeze({
|
|
425
|
+
comments: Object.freeze([]),
|
|
426
|
+
revisions: Object.freeze([])
|
|
427
|
+
});
|
|
428
|
+
function K(e, t) {
|
|
429
|
+
return Ce({
|
|
430
|
+
comments: e,
|
|
431
|
+
revisions: t
|
|
432
|
+
}, "DOCX review metadata");
|
|
433
|
+
}
|
|
434
|
+
var q = class e {
|
|
435
|
+
_metrics = null;
|
|
436
|
+
_document = null;
|
|
437
|
+
_source = null;
|
|
438
|
+
_meta = null;
|
|
439
|
+
_review = Pt;
|
|
440
|
+
_layoutLifecycle = new _e();
|
|
441
|
+
_layoutObservers = new be();
|
|
442
|
+
_layoutCompletion = null;
|
|
443
|
+
_layoutAbort = null;
|
|
444
|
+
_bookmarkPages = null;
|
|
445
|
+
_commentAnchorRanges = null;
|
|
446
|
+
_revisionAnchorRanges = null;
|
|
447
|
+
_reviewProjectionIndex = null;
|
|
448
|
+
_parseRequestId = null;
|
|
449
|
+
_progressive = null;
|
|
450
|
+
_parseWatchdog;
|
|
451
|
+
_parseWatchdogMs;
|
|
452
|
+
_layoutViewGeneration = 0;
|
|
453
|
+
_mode = "main";
|
|
454
|
+
_threeD;
|
|
455
|
+
_regionMap;
|
|
456
|
+
_chartEx;
|
|
457
|
+
_worker;
|
|
458
|
+
_bridge;
|
|
459
|
+
_rawParts = new he({
|
|
460
|
+
maxEntries: 64,
|
|
461
|
+
maxBytes: i
|
|
462
|
+
});
|
|
463
|
+
_embeddedFontFaces = [];
|
|
464
|
+
_googleFontFaces = [];
|
|
465
|
+
_localMetricFontFaces = [];
|
|
466
|
+
_fetchImage = (e, t) => this.getImage(e, t);
|
|
467
|
+
constructor(e, t, n, r) {
|
|
468
|
+
this._worker = e, this._mode = t, we(this, n), this._bridge = new f(this._worker, {
|
|
469
|
+
correlate: (e) => "protocol" in e && e.protocol === "ooxml-pull-v1" ? e.requestId : "id" in e ? e.id : void 0,
|
|
470
|
+
onUnsolicited: (e) => this._onWorkerLayoutPush(e),
|
|
471
|
+
toError: (e) => {
|
|
472
|
+
if (!("protocol" in e || e.type !== "error")) return Object.assign(a(e), {
|
|
473
|
+
...e.reason === void 0 ? {} : { reason: e.reason },
|
|
474
|
+
...e.outgoingColumnIndex === void 0 ? {} : { outgoingColumnIndex: e.outgoingColumnIndex },
|
|
475
|
+
...e.outgoingColumnCount === void 0 ? {} : { outgoingColumnCount: e.outgoingColumnCount },
|
|
476
|
+
...e.incomingColumnCount === void 0 ? {} : { incomingColumnCount: e.incomingColumnCount }
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
let i = new URL(r ?? tt, location.href).href;
|
|
481
|
+
this._bridge.post({
|
|
482
|
+
type: "init",
|
|
483
|
+
wasmUrl: i
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
static async load(n, i = {}) {
|
|
487
|
+
let a = t(i), o = Date.now(), s = i.mode ?? "main", c = new r({
|
|
488
|
+
enabled: !0,
|
|
489
|
+
format: "docx",
|
|
490
|
+
mode: s,
|
|
491
|
+
policy: a.policy,
|
|
492
|
+
onMetrics: a.onResourceMetrics,
|
|
493
|
+
emitToConsole: a.debug
|
|
494
|
+
});
|
|
495
|
+
try {
|
|
496
|
+
if (s === "worker" && (typeof Worker > "u" || typeof OffscreenCanvas > "u")) throw Error("mode: 'worker' requires Worker and OffscreenCanvas support");
|
|
497
|
+
let t;
|
|
498
|
+
if (typeof n == "string") {
|
|
499
|
+
let e = await fetch(n);
|
|
500
|
+
if (!e.ok) throw Error(`Failed to fetch: ${e.status} ${e.statusText}`);
|
|
501
|
+
t = await e.arrayBuffer();
|
|
502
|
+
} else t = n;
|
|
503
|
+
t = p(await h(t, i.password)), c.setSourceBytes(t.byteLength), c.checkpoint("container ready");
|
|
504
|
+
let r = s === "worker" ? (await import("./render-worker-host-DDZo0feh.js")).createRenderWorker() : new et(), l = s === "worker" ? qe(i) : void 0, u = s === "worker" && !!i.progressiveLayout, d;
|
|
505
|
+
try {
|
|
506
|
+
d = new e(r, s, o, i.wasmUrl), d._metrics = c;
|
|
507
|
+
let n = D(d), f = Ee(i.currentDate, n.defaultCurrentDateMs, i.showTrackedChanges === !0);
|
|
508
|
+
if (n.activeLayoutOptions = f, await d._parse(t, a.policy, s === "worker" ? !!i.useGoogleFonts : !1, i.workerTimeoutMs, (e) => c.observeUsage(e), l, u ? {
|
|
509
|
+
onPartial: i.onLayoutPartial,
|
|
510
|
+
onComplete: i.onLayoutComplete,
|
|
511
|
+
onProgress: i.onLayoutProgress,
|
|
512
|
+
layoutOptions: f,
|
|
513
|
+
abort: new AbortController(),
|
|
514
|
+
firstPublication: jt(),
|
|
515
|
+
published: !1,
|
|
516
|
+
settled: !1
|
|
517
|
+
} : void 0), s === "worker" && d._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.")), i.math && d._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."), i.threeD && d._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."), d._threeD = d._mode === "worker" ? void 0 : i.threeD, i.regionMap && d._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."), d._regionMap = d._mode === "worker" ? void 0 : i.regionMap, i.chartEx && d._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."), d._chartEx = d._mode === "worker" ? void 0 : i.chartEx, d._mode === "main" && i.useGoogleFonts && d._document && (d._googleFontFaces = await me(Be(d._document), Me)), d._mode === "main" && d._document?.embeddedFonts?.length) {
|
|
518
|
+
let e = d;
|
|
519
|
+
d._embeddedFontFaces = await rt(d._document, (t) => e.getFontBytes(t));
|
|
520
|
+
}
|
|
521
|
+
let p;
|
|
522
|
+
d._mode === "main" && d._document && (p = await je(d._document), d._localMetricFontFaces = p.faces);
|
|
523
|
+
let m;
|
|
524
|
+
if (d._mode === "main" && i.math && d._document && ze(d._document) && (m = await Ve(d._document, i.math)), d._mode === "main" && d._document && d._source) {
|
|
525
|
+
let e = d, t = D(d);
|
|
526
|
+
t.services = Le(d._source, {
|
|
527
|
+
localMetrics: p?.metrics,
|
|
528
|
+
useGoogleFonts: !!i.useGoogleFonts,
|
|
529
|
+
embeddedFaces: d._embeddedFontFaces,
|
|
530
|
+
googleFaces: d._googleFontFaces,
|
|
531
|
+
mathResources: m?.records,
|
|
532
|
+
mathDrawables: m?.drawables
|
|
533
|
+
});
|
|
534
|
+
let n = t.services, r = Oe(d._source, n, t.defaultCurrentDateMs), a = d._source.fatalParse === null, o = t.activeLayoutOptions;
|
|
535
|
+
if (!o) throw Error("Active layout view was not recorded at load");
|
|
536
|
+
let s = { onProgress: i.onLayoutProgress ? (t) => e._layoutObservers.notify("onLayoutProgress", i.onLayoutProgress, { committedUnits: t }) : void 0 };
|
|
537
|
+
if (a && i.progressiveLayout) {
|
|
538
|
+
let e = r.layoutVariants, t = d, a = new AbortController();
|
|
539
|
+
t._layoutAbort = a;
|
|
540
|
+
let c = jt(), l = null, u = !0;
|
|
541
|
+
t._layoutCompletion = Ot(d._source.bodyLayoutInput, n, o, {
|
|
542
|
+
scheduler: {
|
|
543
|
+
...s,
|
|
544
|
+
signal: a.signal
|
|
545
|
+
},
|
|
546
|
+
onPreview: (n) => {
|
|
547
|
+
if (!u) return;
|
|
548
|
+
let r = l === null, a = t._replaceMainLayoutPublication(e, o, l, n.layout);
|
|
549
|
+
if (a === null) {
|
|
550
|
+
u = !1;
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
if (l = a, r) t._layoutLifecycle.begin(), G(t, {
|
|
554
|
+
pageCount: n.layout.pages.length,
|
|
555
|
+
exact: n.exact,
|
|
556
|
+
complete: !1
|
|
557
|
+
}), c.resolve();
|
|
558
|
+
else {
|
|
559
|
+
if (!t._isLayoutViewActive(o)) return;
|
|
560
|
+
G(t, {
|
|
561
|
+
pageCount: n.layout.pages.length,
|
|
562
|
+
exact: n.exact,
|
|
563
|
+
complete: !1
|
|
564
|
+
}), t._layoutObservers.notify("onLayoutPartial", i.onLayoutPartial, {
|
|
565
|
+
availableUnits: n.layout.pages.length,
|
|
566
|
+
exact: n.exact
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}).then((n) => {
|
|
571
|
+
u && t._replaceMainLayoutPublication(e, o, l, n) === null && (u = !1), t._layoutLifecycle.succeed(), G(t, {
|
|
572
|
+
pageCount: t.pageCount,
|
|
573
|
+
exact: !0,
|
|
574
|
+
complete: !0
|
|
575
|
+
}), l !== null && t._layoutObservers.notify("onLayoutComplete", i.onLayoutComplete), c.resolve();
|
|
576
|
+
}).catch((e) => {
|
|
577
|
+
if (l === null) {
|
|
578
|
+
c.reject(e);
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
if (e instanceof Pe) {
|
|
582
|
+
t._layoutLifecycle.succeed();
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
let n = t._layoutLifecycle.fail(e);
|
|
586
|
+
G(t, {
|
|
587
|
+
pageCount: t.pageCount,
|
|
588
|
+
exact: !1,
|
|
589
|
+
complete: !1,
|
|
590
|
+
error: n
|
|
591
|
+
}), t._layoutObservers.notify("onLayoutComplete", i.onLayoutComplete, n);
|
|
592
|
+
}), await c.promise;
|
|
593
|
+
} else if (a && (i.sliceLayout || i.onLayoutProgress)) {
|
|
594
|
+
let e = await Re(d._source.bodyLayoutInput, n, o, s);
|
|
595
|
+
r.layoutVariants.prime(o, e);
|
|
596
|
+
} else r.layoutVariants.layoutFor(o);
|
|
597
|
+
}
|
|
598
|
+
return await d._resourceUsage(i.workerTimeoutMs ?? 1e3).then((e) => c.observeUsage(e), () => void 0), c.checkpoint("model and layout ready"), c.succeed({ pages: d.pageCount }), d;
|
|
599
|
+
} catch (e) {
|
|
600
|
+
let t = d;
|
|
601
|
+
throw m(r, t ? () => t.destroy() : void 0), e;
|
|
602
|
+
}
|
|
603
|
+
} catch (e) {
|
|
604
|
+
throw c.fail(e), e;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
async _parse(e, t, n = !1, r, i, a, o) {
|
|
608
|
+
if (o) {
|
|
609
|
+
await this._parseProgressively(e, t, n, r, i, a, o);
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
let s = await this._bridge.request((r) => this._mode === "worker" ? {
|
|
613
|
+
type: "parse",
|
|
614
|
+
id: r,
|
|
615
|
+
data: e,
|
|
616
|
+
resourcePolicy: t,
|
|
617
|
+
useGoogleFonts: n,
|
|
618
|
+
defaultCurrentDateMs: D(this).defaultCurrentDateMs,
|
|
619
|
+
...this._parseViewFields(),
|
|
620
|
+
renderers: a
|
|
621
|
+
} : {
|
|
622
|
+
type: "parse",
|
|
623
|
+
id: r,
|
|
624
|
+
data: e,
|
|
625
|
+
resourcePolicy: t
|
|
626
|
+
}, [e], { timeoutMs: r });
|
|
627
|
+
if ("protocol" in s) throw Error("DOCX parse open returned a pull-protocol response");
|
|
628
|
+
if (this._mode === "worker") if ("usage" in s && s.usage && i?.(s.usage), s.type === "mainThreadVerticalFallback") {
|
|
629
|
+
let e = await k(this._bridge.transport(A), s, {
|
|
630
|
+
timeoutMs: r,
|
|
631
|
+
onUsage: i
|
|
632
|
+
});
|
|
633
|
+
this._source = e.source, this._document = e.document, this._meta = null, this._mode = "main";
|
|
634
|
+
} else this._meta = s.meta;
|
|
635
|
+
else {
|
|
636
|
+
let e = s, t = await k(this._bridge.transport(A), e, {
|
|
637
|
+
timeoutMs: r,
|
|
638
|
+
onUsage: i
|
|
639
|
+
});
|
|
640
|
+
this._source = t.source, this._document = t.document;
|
|
641
|
+
}
|
|
642
|
+
this._review = K(this._meta?.comments ?? this._document?.comments ?? [], this._meta?.revisions ?? this._document?.revisions ?? []);
|
|
643
|
+
}
|
|
644
|
+
_onWorkerLayoutPush(e) {
|
|
645
|
+
if (!("forId" in e) || e.forId !== this._parseRequestId) return;
|
|
646
|
+
this._rearmParseWatchdog();
|
|
647
|
+
let t = this._progressive;
|
|
648
|
+
if (t?.settled) return;
|
|
649
|
+
if (e.type === "layoutProgress") {
|
|
650
|
+
this._layoutObservers.notify("onLayoutProgress", t?.onProgress, { committedUnits: e.committedPages });
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
if (e.type !== "layoutPartial" || !t) return;
|
|
654
|
+
let n = !t.published || this._isLayoutViewActive(t.layoutOptions);
|
|
655
|
+
if (n && this._applyLayoutPartial(e.partial), t.published) {
|
|
656
|
+
if (!n) return;
|
|
657
|
+
G(this, {
|
|
658
|
+
pageCount: e.partial.pageCount,
|
|
659
|
+
exact: e.partial.exact,
|
|
660
|
+
complete: !1
|
|
661
|
+
}), this._layoutObservers.notify("onLayoutPartial", t.onPartial, {
|
|
662
|
+
availableUnits: e.partial.pageCount,
|
|
663
|
+
exact: e.partial.exact
|
|
664
|
+
});
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
t.published = !0, this._layoutLifecycle.begin(), G(this, {
|
|
668
|
+
pageCount: e.partial.pageCount,
|
|
669
|
+
exact: e.partial.exact,
|
|
670
|
+
complete: !1
|
|
671
|
+
}), t.firstPublication.resolve();
|
|
672
|
+
}
|
|
673
|
+
_applyLayoutPartial(e) {
|
|
674
|
+
let t = e.review ?? this._meta;
|
|
675
|
+
this._meta = {
|
|
676
|
+
pageCount: e.pageCount,
|
|
677
|
+
pageSizes: e.pageSizes,
|
|
678
|
+
bookmarkPages: e.bookmarkPages,
|
|
679
|
+
revisions: t?.revisions ?? [],
|
|
680
|
+
comments: t?.comments ?? [],
|
|
681
|
+
footnotes: t?.footnotes ?? [],
|
|
682
|
+
endnotes: t?.endnotes ?? [],
|
|
683
|
+
commentAnchorRanges: e.commentAnchorRanges,
|
|
684
|
+
revisionAnchorRanges: e.revisionAnchorRanges
|
|
685
|
+
}, e.review && (this._review = K(e.review.comments, e.review.revisions)), this._invalidateLayoutDerivedCaches();
|
|
686
|
+
}
|
|
687
|
+
_onAuthoritativeMeta(e) {
|
|
688
|
+
this._clearParseWatchdog();
|
|
689
|
+
let t = this._progressive;
|
|
690
|
+
if (!t?.settled) {
|
|
691
|
+
if (!t || this._isLayoutViewActive(t.layoutOptions) || !this._meta) this._meta = e;
|
|
692
|
+
else {
|
|
693
|
+
let t = this._meta;
|
|
694
|
+
this._meta = {
|
|
695
|
+
...e,
|
|
696
|
+
pageCount: t.pageCount,
|
|
697
|
+
pageSizes: t.pageSizes,
|
|
698
|
+
bookmarkPages: t.bookmarkPages,
|
|
699
|
+
commentAnchorRanges: t.commentAnchorRanges,
|
|
700
|
+
revisionAnchorRanges: t.revisionAnchorRanges
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
this._invalidateLayoutDerivedCaches(), this._review = K(e.comments, e.revisions), t && (t.settled = !0, this._layoutLifecycle.succeed(), G(this, {
|
|
704
|
+
pageCount: this.pageCount,
|
|
705
|
+
exact: !0,
|
|
706
|
+
complete: !0
|
|
707
|
+
}), t.firstPublication.resolve(), t.published && this._layoutObservers.notify("onLayoutComplete", t.onComplete));
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
_invalidateLayoutDerivedCaches() {
|
|
711
|
+
this._bookmarkPages = null, this._commentAnchorRanges = null, this._revisionAnchorRanges = null, this._reviewProjectionIndex = null;
|
|
712
|
+
}
|
|
713
|
+
_replaceMainLayoutPublication(e, t, n, r) {
|
|
714
|
+
let i = e.replaceIfCurrent(t, n, r);
|
|
715
|
+
return i !== null && this._isLayoutViewActive(t) && this._invalidateLayoutDerivedCaches(), i;
|
|
716
|
+
}
|
|
717
|
+
_isLayoutViewActive(e) {
|
|
718
|
+
return At(D(this).activeLayoutOptions, e);
|
|
719
|
+
}
|
|
720
|
+
_rearmParseWatchdog() {
|
|
721
|
+
this._parseWatchdogMs !== void 0 && (clearTimeout(this._parseWatchdog), this._parseWatchdog = setTimeout(() => this._onParseWentSilent(), this._parseWatchdogMs));
|
|
722
|
+
}
|
|
723
|
+
_clearParseWatchdog() {
|
|
724
|
+
clearTimeout(this._parseWatchdog), this._parseWatchdog = void 0, this._parseWatchdogMs = void 0;
|
|
725
|
+
}
|
|
726
|
+
_onParseWentSilent() {
|
|
727
|
+
let e = this._progressive, t = this._parseWatchdogMs;
|
|
728
|
+
this._clearParseWatchdog();
|
|
729
|
+
let n = /* @__PURE__ */ Error(`worker layout produced no progress for ${t}ms`);
|
|
730
|
+
e && this._failWorkerProgressive(e, n), this._bridge.terminate();
|
|
731
|
+
}
|
|
732
|
+
_failWorkerProgressive(e, t) {
|
|
733
|
+
if (e.settled) return;
|
|
734
|
+
if (e.settled = !0, this._clearParseWatchdog(), !e.published) {
|
|
735
|
+
e.firstPublication.reject(t);
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
let n = this._layoutLifecycle.fail(t);
|
|
739
|
+
G(this, {
|
|
740
|
+
pageCount: this.pageCount,
|
|
741
|
+
exact: !1,
|
|
742
|
+
complete: !1,
|
|
743
|
+
error: n
|
|
744
|
+
}), this._layoutObservers.notify("onLayoutComplete", e.onComplete, n);
|
|
745
|
+
}
|
|
746
|
+
_parseViewFields() {
|
|
747
|
+
let e = D(this), t = e.activeLayoutOptions;
|
|
748
|
+
return t ? {
|
|
749
|
+
...t.currentDateMs === e.defaultCurrentDateMs ? {} : { currentDateMs: t.currentDateMs },
|
|
750
|
+
...t.showTrackedChanges === !0 ? { showTrackedChanges: !0 } : {}
|
|
751
|
+
} : {};
|
|
752
|
+
}
|
|
753
|
+
async _parseProgressively(e, t, n, r, i, a, o) {
|
|
754
|
+
this._progressive = o, this._layoutAbort = o.abort, this._parseWatchdogMs = r, this._layoutCompletion = this._bridge.request((r) => (this._parseRequestId = r, {
|
|
755
|
+
type: "parse",
|
|
756
|
+
id: r,
|
|
757
|
+
data: e,
|
|
758
|
+
resourcePolicy: t,
|
|
759
|
+
useGoogleFonts: n,
|
|
760
|
+
defaultCurrentDateMs: D(this).defaultCurrentDateMs,
|
|
761
|
+
...this._parseViewFields(),
|
|
762
|
+
renderers: a,
|
|
763
|
+
progressiveLayout: !0
|
|
764
|
+
}), [e], { timeoutMs: !1 }).then(async (e) => {
|
|
765
|
+
if (this._parseRequestId = null, "protocol" in e) throw Error("DOCX parse open returned a pull-protocol response");
|
|
766
|
+
if ("usage" in e && e.usage && i?.(e.usage), e.type === "mainThreadVerticalFallback") {
|
|
767
|
+
this._clearParseWatchdog(), o.settled = !0, this._progressive = null, this._layoutAbort = null;
|
|
768
|
+
let t = await k(this._bridge.transport(A), e, {
|
|
769
|
+
timeoutMs: r,
|
|
770
|
+
onUsage: i
|
|
771
|
+
});
|
|
772
|
+
this._source = t.source, this._document = t.document, this._meta = null, this._mode = "main", this._review = K(t.document.comments ?? [], t.document.revisions ?? []), o.firstPublication.resolve();
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
this._onAuthoritativeMeta(e.meta);
|
|
776
|
+
}, (e) => {
|
|
777
|
+
if (this._parseRequestId = null, this._clearParseWatchdog(), !o.settled) {
|
|
778
|
+
if (o.abort.signal.aborted) {
|
|
779
|
+
o.settled = !0, this._layoutLifecycle.succeed(), o.firstPublication.resolve();
|
|
780
|
+
return;
|
|
781
|
+
}
|
|
782
|
+
this._failWorkerProgressive(o, e);
|
|
783
|
+
}
|
|
784
|
+
}), this._rearmParseWatchdog(), await o.firstPublication.promise;
|
|
785
|
+
}
|
|
786
|
+
destroy() {
|
|
787
|
+
this._layoutAbort?.abort(), this._layoutAbort = null, this._clearParseWatchdog(), this._parseRequestId = null, this._progressive = null, this._layoutViewGeneration++, this._bridge.terminate(), this._document = null, this._source = null, this._meta = null, this._review = Pt, D(this).services = null, this._bookmarkPages = null, this._commentAnchorRanges = null, this._revisionAnchorRanges = null, this._reviewProjectionIndex = null, this._rawParts.clear(), this._embeddedFontFaces.length > 0 && (ve(this._embeddedFontFaces), this._embeddedFontFaces = []), this._googleFontFaces.length > 0 && (pe(this._googleFontFaces), this._googleFontFaces = []), this._localMetricFontFaces.length > 0 && (Fe(this._localMetricFontFaces), this._localMetricFontFaces = []), l(this._fetchImage), u(this._fetchImage);
|
|
788
|
+
}
|
|
789
|
+
async getImage(e, t) {
|
|
790
|
+
return this._rawParts.get(e, t, () => this._bridge.request((t) => ({
|
|
791
|
+
type: "extractImage",
|
|
792
|
+
id: t,
|
|
793
|
+
path: e
|
|
794
|
+
})).then((e) => {
|
|
795
|
+
let n = e.bytes;
|
|
796
|
+
return new Blob([n], { type: t });
|
|
797
|
+
}));
|
|
798
|
+
}
|
|
799
|
+
async getFontBytes(e) {
|
|
800
|
+
let t = (await this._bridge.request((t) => ({
|
|
801
|
+
type: "extractImage",
|
|
802
|
+
id: t,
|
|
803
|
+
path: e
|
|
804
|
+
}))).bytes;
|
|
805
|
+
return new Uint8Array(t);
|
|
806
|
+
}
|
|
807
|
+
async _resourceUsage(e) {
|
|
808
|
+
return (await this._bridge.request((e) => ({
|
|
809
|
+
type: "resourceUsage",
|
|
810
|
+
id: e
|
|
811
|
+
}), void 0, { timeoutMs: e })).usage;
|
|
812
|
+
}
|
|
813
|
+
async getResourceMetrics() {
|
|
814
|
+
let e = this._metrics;
|
|
815
|
+
if (!e) throw Error("Document not loaded");
|
|
816
|
+
return d(e, (e) => this._resourceUsage(e));
|
|
817
|
+
}
|
|
818
|
+
async toMarkdown() {
|
|
819
|
+
return (await this._bridge.request((e) => ({
|
|
820
|
+
type: "toMarkdown",
|
|
821
|
+
id: e
|
|
822
|
+
}))).markdown;
|
|
823
|
+
}
|
|
824
|
+
get pageCount() {
|
|
825
|
+
return this._meta ? this._meta.pageCount : this._document ? this._getLayout()?.pages.length ?? 0 : 0;
|
|
826
|
+
}
|
|
827
|
+
get layoutComplete() {
|
|
828
|
+
return this._layoutLifecycle.complete;
|
|
829
|
+
}
|
|
830
|
+
async waitUntilLayoutComplete() {
|
|
831
|
+
this._layoutCompletion && await this._layoutCompletion, this._layoutLifecycle.throwIfFailed();
|
|
832
|
+
}
|
|
833
|
+
get mode() {
|
|
834
|
+
return this._mode;
|
|
835
|
+
}
|
|
836
|
+
get document() {
|
|
837
|
+
if (this._meta && !this._document) throw Error("the raw document model stays in the worker in mode: 'worker'; use mode: 'main' if you need direct model access");
|
|
838
|
+
if (!this._document) throw Error("Document not loaded");
|
|
839
|
+
return this._document;
|
|
840
|
+
}
|
|
841
|
+
get comments() {
|
|
842
|
+
return this._reviewSnapshot().comments;
|
|
843
|
+
}
|
|
844
|
+
get revisions() {
|
|
845
|
+
return this._reviewSnapshot().revisions;
|
|
846
|
+
}
|
|
847
|
+
commentAnchorRanges() {
|
|
848
|
+
if (this._meta) return this._meta.commentAnchorRanges ?? Mt;
|
|
849
|
+
if (!this._document || !this._source) return [];
|
|
850
|
+
let e = this._reviewSnapshot().comments;
|
|
851
|
+
if (e.length === 0) return Mt;
|
|
852
|
+
let t = D(this), n = t.services;
|
|
853
|
+
if (!n) throw Error("Document layout services are not initialized");
|
|
854
|
+
let r = O(n);
|
|
855
|
+
if (!r) throw Error("Document layout variant store is not initialized");
|
|
856
|
+
let i = t.activeLayoutOptions, a = i ? r.layoutFor(i) : r.defaultLayout;
|
|
857
|
+
this._reviewProjectionIndex ??= j(a);
|
|
858
|
+
let o = this._layoutLifecycle?.complete ?? !0 ? void 0 : { completedSourceKeys: this._reviewProjectionIndex.completedSourceKeys };
|
|
859
|
+
return this._commentAnchorRanges ??= Ze(e, this._source, this._reviewProjectionIndex.renderedRunIndex, o), this._commentAnchorRanges;
|
|
860
|
+
}
|
|
861
|
+
revisionAnchorRanges() {
|
|
862
|
+
if (this._meta) return this._meta.revisionAnchorRanges ?? Nt;
|
|
863
|
+
if (!this._document || !this._source) return [];
|
|
864
|
+
let e = this._reviewSnapshot().revisions;
|
|
865
|
+
if (e.length === 0) return Nt;
|
|
866
|
+
let t = D(this), n = t.services;
|
|
867
|
+
if (!n) throw Error("Document layout services are not initialized");
|
|
868
|
+
let r = O(n);
|
|
869
|
+
if (!r) throw Error("Document layout variant store is not initialized");
|
|
870
|
+
let i = t.activeLayoutOptions, a = i ? r.layoutFor(i) : r.defaultLayout;
|
|
871
|
+
this._reviewProjectionIndex ??= j(a);
|
|
872
|
+
let o = this._layoutLifecycle?.complete ?? !0 ? void 0 : { completedSourceKeys: this._reviewProjectionIndex.completedSourceKeys };
|
|
873
|
+
return this._revisionAnchorRanges ??= Tt(e, this._source, this._reviewProjectionIndex.renderedRunIndex, o), this._revisionAnchorRanges;
|
|
874
|
+
}
|
|
875
|
+
_reviewSnapshot() {
|
|
876
|
+
return this._review ||= K(this._meta?.comments ?? this._document?.comments ?? [], this._meta?.revisions ?? this._document?.revisions ?? []), this._review;
|
|
877
|
+
}
|
|
878
|
+
get footnotes() {
|
|
879
|
+
return this._meta?.footnotes ?? this._document?.footnotes ?? [];
|
|
880
|
+
}
|
|
881
|
+
get endnotes() {
|
|
882
|
+
return this._meta?.endnotes ?? this._document?.endnotes ?? [];
|
|
883
|
+
}
|
|
884
|
+
_getLayout() {
|
|
885
|
+
if (!this._document) return null;
|
|
886
|
+
let e = D(this), t = e.services;
|
|
887
|
+
if (!t) throw Error("Document layout services are not initialized");
|
|
888
|
+
let n = O(t);
|
|
889
|
+
if (!n) throw Error("Document layout variant store is not initialized");
|
|
890
|
+
let r = e.activeLayoutOptions;
|
|
891
|
+
return r ? n.layoutFor(r) : n.defaultLayout;
|
|
892
|
+
}
|
|
893
|
+
async setLayoutView(e = {}) {
|
|
894
|
+
let t = D(this), n = Ee(e.currentDate, t.defaultCurrentDateMs, e.showTrackedChanges === !0), r = ++this._layoutViewGeneration, i = t.activeLayoutOptions;
|
|
895
|
+
if (!At(i, n)) {
|
|
896
|
+
if (this._mode === "worker" && this._meta) {
|
|
897
|
+
let e = await this._bridge.request((e) => ({
|
|
898
|
+
type: "selectLayoutView",
|
|
899
|
+
id: e,
|
|
900
|
+
currentDateMs: n.currentDateMs,
|
|
901
|
+
showTrackedChanges: n.showTrackedChanges === !0
|
|
902
|
+
}));
|
|
903
|
+
if (r !== this._layoutViewGeneration) return;
|
|
904
|
+
let i = e;
|
|
905
|
+
t.activeLayoutOptions = n, this._meta = {
|
|
906
|
+
...this._meta,
|
|
907
|
+
...i.meta
|
|
908
|
+
}, this._invalidateLayoutDerivedCaches();
|
|
909
|
+
return;
|
|
910
|
+
}
|
|
911
|
+
t.activeLayoutOptions = n, this._invalidateLayoutDerivedCaches();
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
_getBookmarkPages() {
|
|
915
|
+
if (this._bookmarkPages) return this._bookmarkPages;
|
|
916
|
+
if (this._meta) return this._bookmarkPages = new Map(this._meta.bookmarkPages), this._bookmarkPages;
|
|
917
|
+
let e = this._getLayout();
|
|
918
|
+
return e ? (this._bookmarkPages = nt(e), this._bookmarkPages) : null;
|
|
919
|
+
}
|
|
920
|
+
getBookmarkPage(e) {
|
|
921
|
+
return this._getBookmarkPages()?.get(e);
|
|
922
|
+
}
|
|
923
|
+
pageSize(e) {
|
|
924
|
+
if (this._meta) {
|
|
925
|
+
let t = this._meta.pageSizes, n = t[Math.max(0, Math.min(e, t.length - 1))];
|
|
926
|
+
return n ? {
|
|
927
|
+
widthPt: n.widthPt,
|
|
928
|
+
heightPt: n.heightPt
|
|
929
|
+
} : {
|
|
930
|
+
widthPt: 0,
|
|
931
|
+
heightPt: 0
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
if (!this._document) return {
|
|
935
|
+
widthPt: 0,
|
|
936
|
+
heightPt: 0
|
|
937
|
+
};
|
|
938
|
+
let t = this._getLayout();
|
|
939
|
+
if (!t || t.pages.length === 0) return {
|
|
940
|
+
widthPt: 0,
|
|
941
|
+
heightPt: 0
|
|
942
|
+
};
|
|
943
|
+
let n = Math.max(0, Math.min(e, t.pages.length - 1)), r = t.pages[n].geometry;
|
|
944
|
+
return {
|
|
945
|
+
widthPt: r.widthPt,
|
|
946
|
+
heightPt: r.heightPt
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
_withActiveView(e) {
|
|
950
|
+
let t = D(this).activeLayoutOptions;
|
|
951
|
+
if (!t) return e;
|
|
952
|
+
let n = { ...e };
|
|
953
|
+
return e.currentDate === void 0 && (n.currentDate = t.currentDateMs), e.showTrackedChanges === void 0 && t.showTrackedChanges === !0 && (n.showTrackedChanges = !0), n;
|
|
954
|
+
}
|
|
955
|
+
renderPage(e, t, n = {}) {
|
|
956
|
+
if (this._mode === "worker") throw Error("renderPage(canvas) is unavailable in mode: 'worker'; use renderPageToBitmap() and paint it via an ImageBitmapRenderingContext");
|
|
957
|
+
if (!this._source) throw Error("Document not loaded");
|
|
958
|
+
return Ae(this._source, e, t, {
|
|
959
|
+
...this._withActiveView(n),
|
|
960
|
+
fetchImage: this._fetchImage,
|
|
961
|
+
layoutServices: D(this).services ?? void 0,
|
|
962
|
+
defaultCurrentDateMs: D(this).defaultCurrentDateMs,
|
|
963
|
+
threeD: this._threeD,
|
|
964
|
+
regionMap: this._regionMap,
|
|
965
|
+
chartEx: this._chartEx
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
async renderPageToBitmap(e, t = {}) {
|
|
969
|
+
let { onTextRun: n, ...r } = t, i = {
|
|
970
|
+
...this._withActiveView(r),
|
|
971
|
+
dpr: r.dpr ?? c()
|
|
972
|
+
};
|
|
973
|
+
if (this._mode === "worker") {
|
|
974
|
+
let t = await this._bridge.request((t) => ({
|
|
975
|
+
type: "renderPage",
|
|
976
|
+
id: t,
|
|
977
|
+
pageIndex: e,
|
|
978
|
+
opts: i
|
|
979
|
+
}));
|
|
980
|
+
if (n) for (let e of t.runs) n(e);
|
|
981
|
+
return t.bitmap;
|
|
982
|
+
}
|
|
983
|
+
let a = new OffscreenCanvas(1, 1);
|
|
984
|
+
return await this.renderPage(a, e, {
|
|
985
|
+
...i,
|
|
986
|
+
onTextRun: n
|
|
987
|
+
}), a.transferToImageBitmap();
|
|
988
|
+
}
|
|
989
|
+
async collectPageRuns(e, t = {}) {
|
|
990
|
+
let n = { ...this._withActiveView(t) };
|
|
991
|
+
if (this._mode === "worker") return (await this._bridge.request((t) => ({
|
|
992
|
+
type: "collectRuns",
|
|
993
|
+
id: t,
|
|
994
|
+
pageIndex: e,
|
|
995
|
+
opts: n
|
|
996
|
+
}))).runs;
|
|
997
|
+
let r = D(this), i = r.services;
|
|
998
|
+
if (!i) throw Error("Document layout services are not initialized");
|
|
999
|
+
return We(i, e, {
|
|
1000
|
+
currentDate: n.currentDate,
|
|
1001
|
+
defaultCurrentDateMs: r.defaultCurrentDateMs,
|
|
1002
|
+
width: n.width,
|
|
1003
|
+
showTrackedChanges: n.showTrackedChanges
|
|
1004
|
+
});
|
|
1005
|
+
}
|
|
1006
|
+
async getCommentThreads(e, t = {}) {
|
|
1007
|
+
let { includeResolved: n, ...r } = t, i = await this.collectPageRuns(e, r);
|
|
1008
|
+
return Xe(this.comments, this.commentAnchorRanges(), i, { includeResolved: n });
|
|
1009
|
+
}
|
|
1010
|
+
async getElementContextAt(e, t, n = {}) {
|
|
1011
|
+
let r = this._withActiveView(n);
|
|
1012
|
+
if (this._mode === "worker") return (await this._bridge.request((n) => ({
|
|
1013
|
+
type: "hitTestElement",
|
|
1014
|
+
id: n,
|
|
1015
|
+
pageIndex: e,
|
|
1016
|
+
point: t,
|
|
1017
|
+
opts: r
|
|
1018
|
+
}))).context;
|
|
1019
|
+
let i = D(this), a = i.services;
|
|
1020
|
+
if (!a) throw Error("Document layout services are not initialized");
|
|
1021
|
+
return yt(a, e, t, {
|
|
1022
|
+
...r,
|
|
1023
|
+
defaultCurrentDateMs: i.defaultCurrentDateMs
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
};
|
|
1027
|
+
//#endregion
|
|
1028
|
+
//#region packages/docx/src/tate-chu-yoko-overlay.ts
|
|
1029
|
+
function Ft(e, t) {
|
|
1030
|
+
if (!e.eastAsianVert) return 1;
|
|
1031
|
+
let n = t(e.text);
|
|
1032
|
+
return !(n > 0) || e.w >= n ? 1 : e.w / n;
|
|
1033
|
+
}
|
|
1034
|
+
//#endregion
|
|
1035
|
+
//#region packages/docx/src/text-layer.ts
|
|
1036
|
+
function J(e, t, n) {
|
|
1037
|
+
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);
|
|
1038
|
+
}
|
|
1039
|
+
function Y(e, t, n, r, i, a, o) {
|
|
1040
|
+
e.innerHTML = "", J(e, "ooxmlSelectionSurface", "docx"), J(e, "pageIndex", o === void 0 ? void 0 : String(o));
|
|
1041
|
+
let s = e.ownerDocument ?? document;
|
|
1042
|
+
for (let [o, c] of t.entries()) {
|
|
1043
|
+
let t = s.createElement("span");
|
|
1044
|
+
J(t, "ooxmlSelectionRun", "docx"), J(t, "runIndex", String(o)), c.paragraphId !== void 0 && J(t, "paragraphId", c.paragraphId), c.source !== void 0 && (J(t, "sourceStory", c.source.story), J(t, "sourceStoryInstance", c.source.storyInstance), J(t, "sourcePath", JSON.stringify(c.source.path))), t.textContent = c.text;
|
|
1045
|
+
let l = c.transform ?? "";
|
|
1046
|
+
if (a && c.eastAsianVert) {
|
|
1047
|
+
let e = Ft(c, a(c.font));
|
|
1048
|
+
e !== 1 && (l = `${l ? `${l} ` : ""}scaleX(${e})`);
|
|
1049
|
+
}
|
|
1050
|
+
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`;
|
|
1051
|
+
t.style.cssText = `position:absolute;left:${N(c.x, n)};top:${N(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) => {
|
|
1052
|
+
e.preventDefault(), i(d);
|
|
1053
|
+
})), e.appendChild(t);
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
function X(e, t, n, r, i, a, o = {}) {
|
|
1057
|
+
e.innerHTML = "";
|
|
1058
|
+
let s = o.match ?? "rgba(255, 214, 0, 0.42)", c = o.active ?? "rgba(255, 140, 0, 0.55)";
|
|
1059
|
+
for (let o of n) {
|
|
1060
|
+
let n = o.active ? c : s;
|
|
1061
|
+
for (let s of o.slices) {
|
|
1062
|
+
let o = t[s.runIndex];
|
|
1063
|
+
if (!o) continue;
|
|
1064
|
+
let c = a(o.font), l = Je(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, _ = Ft(o, c), ee = h * _, v = g * _;
|
|
1065
|
+
if (v <= 0) continue;
|
|
1066
|
+
let y = document.createElement("div"), te = o.transform ? `transform:${o.transform};transform-origin:top left;` : "";
|
|
1067
|
+
y.style.cssText = `position:absolute;left:${N(o.x + ee, r)};top:${N(o.y, i)};width:${N(v, r)};height:${N(o.h, i)};` + te + `background:${n};pointer-events:none;`, e.appendChild(y);
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
//#endregion
|
|
1072
|
+
//#region packages/docx/src/find.ts
|
|
1073
|
+
var Z = class {
|
|
1074
|
+
_pageRuns = /* @__PURE__ */ new Map();
|
|
1075
|
+
_matches = [];
|
|
1076
|
+
_active = -1;
|
|
1077
|
+
_generation = 0;
|
|
1078
|
+
_runsRevision = 0;
|
|
1079
|
+
constructor(e, t) {
|
|
1080
|
+
this._pageCount = e, this._collectPageRuns = t;
|
|
1081
|
+
}
|
|
1082
|
+
invalidate() {
|
|
1083
|
+
this._generation++, this._runsRevision++, this._pageRuns.clear(), this._matches = [], this._active = -1;
|
|
1084
|
+
}
|
|
1085
|
+
pageRuns(e) {
|
|
1086
|
+
return this._pageRuns.get(e);
|
|
1087
|
+
}
|
|
1088
|
+
setPageRuns(e, t) {
|
|
1089
|
+
this._runsRevision++, this._pageRuns.set(e, t);
|
|
1090
|
+
}
|
|
1091
|
+
_matchAt(e) {
|
|
1092
|
+
return this._matches[e];
|
|
1093
|
+
}
|
|
1094
|
+
pageHighlights(e) {
|
|
1095
|
+
let t = [];
|
|
1096
|
+
for (let n = 0; n < this._matches.length; n++) {
|
|
1097
|
+
let r = this._matches[n];
|
|
1098
|
+
r.page === e && t.push({
|
|
1099
|
+
slices: r.slices,
|
|
1100
|
+
active: n === this._active
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1103
|
+
return t;
|
|
1104
|
+
}
|
|
1105
|
+
activePage() {
|
|
1106
|
+
let e = this._matchAt(this._active);
|
|
1107
|
+
return e ? e.page : null;
|
|
1108
|
+
}
|
|
1109
|
+
matches() {
|
|
1110
|
+
return this._matches.map((e, t) => ({
|
|
1111
|
+
matchIndex: t,
|
|
1112
|
+
text: e.text,
|
|
1113
|
+
location: { page: e.page }
|
|
1114
|
+
}));
|
|
1115
|
+
}
|
|
1116
|
+
async find(e, t = {}) {
|
|
1117
|
+
let n = ++this._generation;
|
|
1118
|
+
if (e.length === 0) return this._runsRevision++, this._pageRuns.clear(), this._matches = [], this._active = -1, [];
|
|
1119
|
+
let r = this._runsRevision, i = new Map(this._pageRuns), a = this._pageCount();
|
|
1120
|
+
for (let e = 0; e < a; e++) {
|
|
1121
|
+
let t = i.get(e);
|
|
1122
|
+
if (!t) {
|
|
1123
|
+
try {
|
|
1124
|
+
t = await this._collectPageRuns(e);
|
|
1125
|
+
} catch (e) {
|
|
1126
|
+
if (n !== this._generation) return [];
|
|
1127
|
+
throw e;
|
|
1128
|
+
}
|
|
1129
|
+
if (n !== this._generation) return [];
|
|
1130
|
+
i.set(e, t);
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
if (n !== this._generation) return [];
|
|
1134
|
+
let o = r === this._runsRevision ? i : new Map([...i, ...this._pageRuns]), s = [];
|
|
1135
|
+
for (let n = 0; n < a; n++) {
|
|
1136
|
+
let r = o.get(n) ?? [], i = ie(r);
|
|
1137
|
+
for (let a of re(i, e, t)) {
|
|
1138
|
+
let e = a.slices.map((e) => r[e.runIndex].text.slice(e.start, e.end)).join("");
|
|
1139
|
+
s.push({
|
|
1140
|
+
page: n,
|
|
1141
|
+
text: e,
|
|
1142
|
+
slices: a.slices
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
return this._runsRevision++, this._pageRuns = o, this._matches = s, this._active = -1, this.matches();
|
|
1147
|
+
}
|
|
1148
|
+
next() {
|
|
1149
|
+
return this._active = te(this._active, this._matches.length), this._activePublic();
|
|
1150
|
+
}
|
|
1151
|
+
prev() {
|
|
1152
|
+
return this._active = se(this._active, this._matches.length), this._activePublic();
|
|
1153
|
+
}
|
|
1154
|
+
_activePublic() {
|
|
1155
|
+
let e = this._matchAt(this._active);
|
|
1156
|
+
return e ? {
|
|
1157
|
+
matchIndex: this._active,
|
|
1158
|
+
text: e.text,
|
|
1159
|
+
location: { page: e.page }
|
|
1160
|
+
} : null;
|
|
1161
|
+
}
|
|
1162
|
+
};
|
|
1163
|
+
//#endregion
|
|
1164
|
+
//#region packages/docx/src/selection-context.ts
|
|
1165
|
+
function It(e, t, n, r, i = {}) {
|
|
1166
|
+
let a = e.find((e) => e.id === n && e.parentId === void 0);
|
|
1167
|
+
if (!a) return null;
|
|
1168
|
+
let o = new Map(e.map((e) => [e.id, e])), s = e.filter((e) => {
|
|
1169
|
+
if (e.parentId === void 0) return !1;
|
|
1170
|
+
let t = e, n = /* @__PURE__ */ new Set();
|
|
1171
|
+
for (; t.parentId !== void 0 && !n.has(t.id);) {
|
|
1172
|
+
n.add(t.id);
|
|
1173
|
+
let e = o.get(t.parentId);
|
|
1174
|
+
if (!e) return !1;
|
|
1175
|
+
if (e.id === a.id) return !0;
|
|
1176
|
+
t = e;
|
|
1177
|
+
}
|
|
1178
|
+
return !1;
|
|
1179
|
+
}), c = ye({
|
|
1180
|
+
id: a.id,
|
|
1181
|
+
author: a.author,
|
|
1182
|
+
date: a.date,
|
|
1183
|
+
text: a.paragraphs?.join("\n") ?? a.text,
|
|
1184
|
+
status: a.resolved ? "resolved" : "active"
|
|
1185
|
+
}, s.map((e) => ({
|
|
1186
|
+
id: e.id,
|
|
1187
|
+
author: e.author,
|
|
1188
|
+
date: e.date,
|
|
1189
|
+
text: e.paragraphs?.join("\n") ?? e.text,
|
|
1190
|
+
status: e.resolved ? "resolved" : "active"
|
|
1191
|
+
})), i.maxTextCharacters), l = t.find((e) => e.commentId === n)?.source;
|
|
1192
|
+
return Object.freeze({
|
|
1193
|
+
format: "docx",
|
|
1194
|
+
kind: "comment",
|
|
1195
|
+
pageIndex: r,
|
|
1196
|
+
commentId: n,
|
|
1197
|
+
...l ? { source: Object.freeze({
|
|
1198
|
+
...l,
|
|
1199
|
+
path: Object.freeze([...l.path])
|
|
1200
|
+
}) } : {},
|
|
1201
|
+
thread: c.thread,
|
|
1202
|
+
truncated: c.truncated,
|
|
1203
|
+
truncationReasons: c.truncated ? ["text"] : [],
|
|
1204
|
+
textCharacters: c.textCharacters,
|
|
1205
|
+
maxTextCharacters: c.maxTextCharacters
|
|
1206
|
+
});
|
|
1207
|
+
}
|
|
1208
|
+
function Lt(e) {
|
|
1209
|
+
if (e === void 0 || !/^\d+$/.test(e)) return null;
|
|
1210
|
+
let t = Number(e);
|
|
1211
|
+
return Number.isSafeInteger(t) ? t : null;
|
|
1212
|
+
}
|
|
1213
|
+
function Rt(e) {
|
|
1214
|
+
for (let t = e; t; t = t.parentElement) {
|
|
1215
|
+
let e = Lt(t.dataset.pageIndex);
|
|
1216
|
+
if (e !== null) return e;
|
|
1217
|
+
}
|
|
1218
|
+
return null;
|
|
1219
|
+
}
|
|
1220
|
+
var zt = new Set([
|
|
1221
|
+
"body",
|
|
1222
|
+
"header",
|
|
1223
|
+
"footer",
|
|
1224
|
+
"footnote",
|
|
1225
|
+
"endnote",
|
|
1226
|
+
"textbox"
|
|
1227
|
+
]);
|
|
1228
|
+
function Bt(e) {
|
|
1229
|
+
let t = e.dataset.sourceStory, n = e.dataset.sourceStoryInstance, r = e.dataset.sourcePath;
|
|
1230
|
+
if (!t || !zt.has(t) || !n || !r) return null;
|
|
1231
|
+
try {
|
|
1232
|
+
let e = JSON.parse(r);
|
|
1233
|
+
return !Array.isArray(e) || e.length === 0 || e.length > 32 || !e.every((e) => Number.isSafeInteger(e) && e >= 0) ? null : {
|
|
1234
|
+
story: t,
|
|
1235
|
+
storyInstance: n,
|
|
1236
|
+
path: [...e]
|
|
1237
|
+
};
|
|
1238
|
+
} catch {
|
|
1239
|
+
return null;
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
function Q(e, t, n = {}) {
|
|
1243
|
+
let r = ce(e, t, (e) => {
|
|
1244
|
+
let t = Rt(e), n = Lt(e.dataset.runIndex);
|
|
1245
|
+
return t === null || n === null ? null : {
|
|
1246
|
+
pageIndex: t,
|
|
1247
|
+
runIndex: n,
|
|
1248
|
+
...e.dataset.paragraphId === void 0 ? {} : { paragraphId: e.dataset.paragraphId },
|
|
1249
|
+
...Bt(e) === null ? {} : { source: Bt(e) }
|
|
1250
|
+
};
|
|
1251
|
+
}, {
|
|
1252
|
+
maxChars: n.maxTextCharacters,
|
|
1253
|
+
maxLocators: n.maxRunLocators
|
|
1254
|
+
});
|
|
1255
|
+
if (!r) return null;
|
|
1256
|
+
let i = [...r.locators].sort((e, t) => e.pageIndex - t.pageIndex || e.runIndex - t.runIndex);
|
|
1257
|
+
return {
|
|
1258
|
+
format: "docx",
|
|
1259
|
+
kind: "text",
|
|
1260
|
+
text: r.text,
|
|
1261
|
+
pageIndexes: [...new Set(i.map((e) => e.pageIndex))],
|
|
1262
|
+
paragraphIds: [...new Set(i.flatMap((e) => e.paragraphId ? [e.paragraphId] : []))],
|
|
1263
|
+
runs: i,
|
|
1264
|
+
truncated: r.truncated,
|
|
1265
|
+
truncationReasons: r.truncationReasons,
|
|
1266
|
+
textCharacters: r.textCharacters,
|
|
1267
|
+
maxTextCharacters: r.maxTextCharacters,
|
|
1268
|
+
maxRunLocators: r.maxLocators
|
|
1269
|
+
};
|
|
1270
|
+
}
|
|
1271
|
+
//#endregion
|
|
1272
|
+
//#region packages/docx/src/focused-view-runtime.ts
|
|
1273
|
+
function $(e, t, n, r, i) {
|
|
1274
|
+
return r === "worker" ? e.renderPageToBitmap(n, i) : e.renderPage(t, n, i);
|
|
1275
|
+
}
|
|
1276
|
+
//#endregion
|
|
1277
|
+
//#region packages/docx/src/viewer.ts
|
|
1278
|
+
var Vt = Symbol("DocxViewer.borrowedDocument"), Ht = class e {
|
|
1279
|
+
_documentOwner;
|
|
1280
|
+
get _doc() {
|
|
1281
|
+
return this._documentOwner.current;
|
|
1282
|
+
}
|
|
1283
|
+
_borrowed;
|
|
1284
|
+
_hostWindow;
|
|
1285
|
+
_currentPage = 0;
|
|
1286
|
+
_scale = null;
|
|
1287
|
+
_canvas;
|
|
1288
|
+
_wrapper;
|
|
1289
|
+
_canvasMount;
|
|
1290
|
+
_textLayer = null;
|
|
1291
|
+
_highlightLayer = null;
|
|
1292
|
+
_elementLayer = null;
|
|
1293
|
+
_find;
|
|
1294
|
+
_findRequestGeneration = 0;
|
|
1295
|
+
_measureCtx = null;
|
|
1296
|
+
_opts;
|
|
1297
|
+
_mode;
|
|
1298
|
+
_renderDispatcher;
|
|
1299
|
+
_errorRouter;
|
|
1300
|
+
_destroyed = !1;
|
|
1301
|
+
_selectionChangeListener = null;
|
|
1302
|
+
_selectionContextKey = "null";
|
|
1303
|
+
_elementContext = null;
|
|
1304
|
+
_elementHitGeneration = 0;
|
|
1305
|
+
_layoutViewGeneration = 0;
|
|
1306
|
+
_navigationGeneration = 0;
|
|
1307
|
+
_layoutUnsubscribe = null;
|
|
1308
|
+
_internalHyperlinkGeneration = 0;
|
|
1309
|
+
_layoutWaiters = /* @__PURE__ */ new Set();
|
|
1310
|
+
_layoutFailed = !1;
|
|
1311
|
+
_loadingLayer;
|
|
1312
|
+
_elementClickListener = null;
|
|
1313
|
+
_contextMenuListener = null;
|
|
1314
|
+
static fromDocument(t, n, r = {}) {
|
|
1315
|
+
return new e(t, {
|
|
1316
|
+
...r,
|
|
1317
|
+
[Vt]: n
|
|
1318
|
+
});
|
|
1319
|
+
}
|
|
1320
|
+
constructor(e, t = {}) {
|
|
1321
|
+
this._canvas = e, this._opts = t;
|
|
1322
|
+
let n = t[Vt];
|
|
1323
|
+
this._borrowed = n !== void 0, this._mode = x("DocxViewer", t.mode, n), this._documentOwner = new _("DocxViewer", n ?? null, !1);
|
|
1324
|
+
let r = e.ownerDocument?.defaultView ?? (typeof window < "u" ? window : null);
|
|
1325
|
+
if (!r) throw Error("DocxViewer requires a canvas with an active Window");
|
|
1326
|
+
this._hostWindow = r, this._canvasMount = new le(e, {
|
|
1327
|
+
wrapperCssText: "position:relative;display:inline-block;vertical-align:top;",
|
|
1328
|
+
forceDisplayBlock: !0
|
|
1329
|
+
}), this._wrapper = this._canvasMount.wrapper, this._renderDispatcher = new b(e, this._mode === "worker"), this._errorRouter = new S("DocxViewer", t.onError);
|
|
1330
|
+
let i = new ae(this._wrapper, t.enableTextSelection === !0, t.enableElementSelection === !0);
|
|
1331
|
+
this._textLayer = i.textLayer, this._highlightLayer = i.highlightLayer, this._elementLayer = i.elementLayer, this._loadingLayer = this._wrapper.ownerDocument.createElement("div"), this._loadingLayer.style.cssText = [
|
|
1332
|
+
"position:absolute",
|
|
1333
|
+
"inset:0",
|
|
1334
|
+
"display:none",
|
|
1335
|
+
"align-items:center",
|
|
1336
|
+
"justify-content:center",
|
|
1337
|
+
"background:rgba(255,255,255,0.72)",
|
|
1338
|
+
"pointer-events:none",
|
|
1339
|
+
"z-index:4"
|
|
1340
|
+
].join(";"), this._loadingLayer.setAttribute("role", "status"), this._loadingLayer.setAttribute("aria-live", "polite"), this._loadingLayer.setAttribute("aria-label", "Loading page");
|
|
1341
|
+
let a = this._wrapper.ownerDocument.createElement("progress");
|
|
1342
|
+
a.setAttribute("aria-hidden", "true"), this._loadingLayer.appendChild(a), this._wrapper.insertBefore(this._loadingLayer, this._elementLayer), this._textLayer && (t.onSelectionContextChange || t.enableElementSelection) && (this._selectionChangeListener = () => this._emitSelectionContextChange(), this._wrapper.ownerDocument.addEventListener("selectionchange", this._selectionChangeListener)), t.enableElementSelection && (this._elementClickListener = (e) => {
|
|
1343
|
+
this._onElementClick(e).catch((e) => this._reportRenderError(e));
|
|
1344
|
+
}, this._wrapper.addEventListener("click", this._elementClickListener)), t.onContextMenu && (this._contextMenuListener = (e) => this._onContextMenu(e), this._wrapper.addEventListener("contextmenu", this._contextMenuListener)), this._find = new Z(() => this.pageCount, (e) => this._collectPageRuns(e)), n && this._bindLayoutDocument(n);
|
|
1345
|
+
}
|
|
1346
|
+
async load(e) {
|
|
1347
|
+
if (this._destroyed) throw Error("DocxViewer is destroyed");
|
|
1348
|
+
if (this._borrowed) throw Error("DocxViewer.load() is unsupported on a Viewer created by fromDocument(); the borrowed document is already loaded.");
|
|
1349
|
+
let t = !1;
|
|
1350
|
+
try {
|
|
1351
|
+
let n = await this._documentOwner.replace(() => q.load(e, {
|
|
1352
|
+
password: this._opts.password,
|
|
1353
|
+
useGoogleFonts: this._opts.useGoogleFonts,
|
|
1354
|
+
maxZipEntryBytes: this._opts.maxZipEntryBytes,
|
|
1355
|
+
resourceLimits: this._opts.resourceLimits,
|
|
1356
|
+
debug: this._opts.debug,
|
|
1357
|
+
onResourceMetrics: this._opts.onResourceMetrics,
|
|
1358
|
+
workerTimeoutMs: this._opts.workerTimeoutMs,
|
|
1359
|
+
wasmUrl: this._opts.wasmUrl,
|
|
1360
|
+
math: this._opts.math,
|
|
1361
|
+
threeD: this._opts.threeD,
|
|
1362
|
+
regionMap: this._opts.regionMap,
|
|
1363
|
+
chartEx: this._opts.chartEx,
|
|
1364
|
+
mode: this._mode,
|
|
1365
|
+
...this._opts.progressiveLayout ? { progressiveLayout: !0 } : {},
|
|
1366
|
+
...this._opts.sliceLayout ? { sliceLayout: !0 } : {},
|
|
1367
|
+
onLayoutProgress: this._opts.onLayoutProgress,
|
|
1368
|
+
onLayoutPartial: this._opts.onLayoutPartial,
|
|
1369
|
+
onLayoutComplete: this._opts.onLayoutComplete,
|
|
1370
|
+
...this._opts.showTrackedChanges === !0 ? { showTrackedChanges: !0 } : {},
|
|
1371
|
+
...this._opts.currentDate === void 0 ? {} : { currentDate: this._opts.currentDate }
|
|
1372
|
+
}), () => {
|
|
1373
|
+
this._invalidateElementContext(!1), t = !0, this._renderDispatcher.begin(), this._findRequestGeneration++, this._find.invalidate(), this._unbindLayoutDocument();
|
|
1374
|
+
});
|
|
1375
|
+
if (!n) return;
|
|
1376
|
+
if (this._destroyed) throw Error("DocxViewer is destroyed");
|
|
1377
|
+
this._currentPage = 0, this._bindLayoutDocument(n), this._find.invalidate(), await this._render();
|
|
1378
|
+
} catch (e) {
|
|
1379
|
+
throw this._destroyed ? Error("DocxViewer is destroyed") : e instanceof Error ? e : Error(String(e));
|
|
1380
|
+
}
|
|
1381
|
+
t && !this._destroyed && this._emitSelectionContextChange();
|
|
1382
|
+
}
|
|
1383
|
+
get pageCount() {
|
|
1384
|
+
return this._doc?.pageCount ?? 0;
|
|
1385
|
+
}
|
|
1386
|
+
get currentPage() {
|
|
1387
|
+
return this._currentPage;
|
|
1388
|
+
}
|
|
1389
|
+
get layoutComplete() {
|
|
1390
|
+
return this._doc?.layoutComplete ?? !0;
|
|
1391
|
+
}
|
|
1392
|
+
async waitUntilLayoutComplete() {
|
|
1393
|
+
await this._errorRouter.ownBackgroundLifecycle(async () => {
|
|
1394
|
+
await this._doc?.waitUntilLayoutComplete?.();
|
|
1395
|
+
});
|
|
1396
|
+
}
|
|
1397
|
+
get canvasElement() {
|
|
1398
|
+
return this._canvas;
|
|
1399
|
+
}
|
|
1400
|
+
async goToPage(e) {
|
|
1401
|
+
let t = this._doc;
|
|
1402
|
+
if (!t) return;
|
|
1403
|
+
let n = this._cancelPendingNavigation(), r = Math.max(0, Number.isNaN(e) ? 0 : Math.trunc(e));
|
|
1404
|
+
if (r >= this.pageCount && !this.layoutComplete) {
|
|
1405
|
+
this._setLoading(!0);
|
|
1406
|
+
try {
|
|
1407
|
+
await this._waitForPage(t, r, n);
|
|
1408
|
+
} finally {
|
|
1409
|
+
n === this._navigationGeneration && this._setLoading(!1);
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
if (this._destroyed || n !== this._navigationGeneration || t !== this._doc) return;
|
|
1413
|
+
let i = Math.max(0, Math.min(r, this.pageCount - 1)), a = i !== this._currentPage;
|
|
1414
|
+
a && this._invalidateElementContext(!1), this._currentPage = i, await this._render(), a && !this._destroyed && this._emitSelectionContextChange();
|
|
1415
|
+
}
|
|
1416
|
+
async nextPage() {
|
|
1417
|
+
await this.goToPage(this._currentPage + 1);
|
|
1418
|
+
}
|
|
1419
|
+
async prevPage() {
|
|
1420
|
+
await this.goToPage(this._currentPage - 1);
|
|
1421
|
+
}
|
|
1422
|
+
_naturalWidthPx() {
|
|
1423
|
+
return !this._doc || this._doc.pageCount === 0 ? 0 : this._doc.pageSize(this._currentPage).widthPt * M;
|
|
1424
|
+
}
|
|
1425
|
+
_renderWidth() {
|
|
1426
|
+
if (this._scale === null) return this._opts.width;
|
|
1427
|
+
let e = this._naturalWidthPx();
|
|
1428
|
+
return e <= 0 ? this._opts.width : Math.round(e * this._scale);
|
|
1429
|
+
}
|
|
1430
|
+
getScale() {
|
|
1431
|
+
if (this._scale !== null) return this._scale;
|
|
1432
|
+
let e = this._naturalWidthPx();
|
|
1433
|
+
return e <= 0 ? 1 : this._opts.width && this._opts.width > 0 ? this._opts.width / e : 1;
|
|
1434
|
+
}
|
|
1435
|
+
_zoomMin() {
|
|
1436
|
+
return this._opts.zoomMin ?? .1;
|
|
1437
|
+
}
|
|
1438
|
+
_zoomMax() {
|
|
1439
|
+
return this._opts.zoomMax ?? 4;
|
|
1440
|
+
}
|
|
1441
|
+
async setScale(e) {
|
|
1442
|
+
let t = ne(e, this._zoomMin(), this._zoomMax()), n = t !== this.getScale();
|
|
1443
|
+
this._scale = t, await this._render(), n && this._opts.onScaleChange?.(t);
|
|
1444
|
+
}
|
|
1445
|
+
async zoomIn() {
|
|
1446
|
+
await this.setScale(C(this.getScale()));
|
|
1447
|
+
}
|
|
1448
|
+
async zoomOut() {
|
|
1449
|
+
await this.setScale(w(this.getScale()));
|
|
1450
|
+
}
|
|
1451
|
+
async fitWidth() {
|
|
1452
|
+
await this._fit("width");
|
|
1453
|
+
}
|
|
1454
|
+
async fitPage() {
|
|
1455
|
+
await this._fit("page");
|
|
1456
|
+
}
|
|
1457
|
+
async _fit(e) {
|
|
1458
|
+
if (!this._doc || this._doc.pageCount === 0) return;
|
|
1459
|
+
let t = this._doc.pageSize(this._currentPage), n = this._fitContainer();
|
|
1460
|
+
if (!n) return;
|
|
1461
|
+
let r = g({
|
|
1462
|
+
contentWidth: t.widthPt * M,
|
|
1463
|
+
contentHeight: t.heightPt * M,
|
|
1464
|
+
containerWidth: n.clientWidth,
|
|
1465
|
+
containerHeight: n.clientHeight
|
|
1466
|
+
}, e);
|
|
1467
|
+
r <= 0 || await this.setScale(r);
|
|
1468
|
+
}
|
|
1469
|
+
_fitContainer() {
|
|
1470
|
+
return this._opts.container ?? this._wrapper.parentElement ?? null;
|
|
1471
|
+
}
|
|
1472
|
+
async findText(e, t = {}) {
|
|
1473
|
+
let n = this._doc;
|
|
1474
|
+
if (!n) return [];
|
|
1475
|
+
let r = ++this._findRequestGeneration;
|
|
1476
|
+
if (e.length > 0 && !n.layoutComplete && (await this._errorRouter.ownBackgroundLifecycle(() => n.waitUntilLayoutComplete()), this._destroyed || this._doc !== n || r !== this._findRequestGeneration)) return [];
|
|
1477
|
+
let i = await this._errorRouter.ownAwaitable(() => this._find.find(e, t));
|
|
1478
|
+
return this._redrawHighlights(), i;
|
|
1479
|
+
}
|
|
1480
|
+
async findNext() {
|
|
1481
|
+
return this._activateMatch(this._find.next());
|
|
1482
|
+
}
|
|
1483
|
+
async findPrev() {
|
|
1484
|
+
return this._activateMatch(this._find.prev());
|
|
1485
|
+
}
|
|
1486
|
+
clearFind() {
|
|
1487
|
+
this._findRequestGeneration++, this._find.invalidate(), this._redrawHighlights();
|
|
1488
|
+
}
|
|
1489
|
+
async _activateMatch(e) {
|
|
1490
|
+
return e ? (e.location.page === this._currentPage ? this._redrawHighlights() : await this.goToPage(e.location.page), e) : (this._redrawHighlights(), null);
|
|
1491
|
+
}
|
|
1492
|
+
_redrawHighlights() {
|
|
1493
|
+
let e = this._find.pageRuns(this._currentPage) ?? [];
|
|
1494
|
+
this._buildHighlightLayer(e);
|
|
1495
|
+
}
|
|
1496
|
+
async getResourceMetrics() {
|
|
1497
|
+
if (!this._doc) throw Error("Document not loaded");
|
|
1498
|
+
return await this._doc.getResourceMetrics();
|
|
1499
|
+
}
|
|
1500
|
+
getSelectionContext(e = {}) {
|
|
1501
|
+
if (this._destroyed) throw Error("DocxViewer is destroyed");
|
|
1502
|
+
return (this._textLayer ? Q(this._wrapper, this._wrapper.ownerDocument?.getSelection?.() ?? null, e) : null) ?? (this._elementContext ? bt(this._elementContext, e.maxTextCharacters) : null);
|
|
1503
|
+
}
|
|
1504
|
+
_emitSelectionContextChange() {
|
|
1505
|
+
let e = this.getSelectionContext();
|
|
1506
|
+
e?.kind === "text" && (this._elementHitGeneration++, this._elementContext = null, this._redrawElementOutline());
|
|
1507
|
+
let t = JSON.stringify(e);
|
|
1508
|
+
t !== this._selectionContextKey && (this._selectionContextKey = t, this._opts.onSelectionContextChange?.(e ? structuredClone(e) : null));
|
|
1509
|
+
}
|
|
1510
|
+
_setElementContext(e) {
|
|
1511
|
+
this._elementContext = e ? structuredClone(e) : null, this._redrawElementOutline(), this._emitSelectionContextChange();
|
|
1512
|
+
}
|
|
1513
|
+
_invalidateElementContext(e = !0) {
|
|
1514
|
+
this._elementHitGeneration++, this._elementContext = null, this._redrawElementOutline(), e && this._emitSelectionContextChange();
|
|
1515
|
+
}
|
|
1516
|
+
_redrawElementOutline() {
|
|
1517
|
+
let e = this._elementContext, t = this._doc;
|
|
1518
|
+
if (!e || !t || e.pageIndex !== this._currentPage) {
|
|
1519
|
+
v(this._elementLayer, null);
|
|
1520
|
+
return;
|
|
1521
|
+
}
|
|
1522
|
+
let n = t.pageSize(e.pageIndex);
|
|
1523
|
+
v(this._elementLayer, {
|
|
1524
|
+
x: e.bounds.xPt / n.widthPt,
|
|
1525
|
+
y: e.bounds.yPt / n.heightPt,
|
|
1526
|
+
width: e.bounds.widthPt / n.widthPt,
|
|
1527
|
+
height: e.bounds.heightPt / n.heightPt
|
|
1528
|
+
});
|
|
1529
|
+
}
|
|
1530
|
+
async _onElementClick(e) {
|
|
1531
|
+
this._destroyed || e.defaultPrevented || e.button !== 0 || await this._resolveContextAt(e);
|
|
1532
|
+
}
|
|
1533
|
+
_onContextMenu(e) {
|
|
1534
|
+
let t;
|
|
1535
|
+
this._opts.onContextMenu?.({
|
|
1536
|
+
originalEvent: e,
|
|
1537
|
+
getContext: () => t ??= this._resolveContextAt(e)
|
|
1538
|
+
});
|
|
1539
|
+
}
|
|
1540
|
+
async _resolveContextAt(e) {
|
|
1541
|
+
let t = this._doc;
|
|
1542
|
+
if (this._destroyed || !t) return null;
|
|
1543
|
+
if (this._textLayer && Q(this._wrapper, this._wrapper.ownerDocument?.getSelection?.() ?? null)) return this._emitSelectionContextChange(), this._destroyed ? null : this.getSelectionContext();
|
|
1544
|
+
if (!this._opts.enableElementSelection) return this.getSelectionContext();
|
|
1545
|
+
let n = this._canvas.getBoundingClientRect();
|
|
1546
|
+
if (n.width <= 0 || n.height <= 0) return this._invalidateElementContext(), null;
|
|
1547
|
+
let r = e.clientX - n.left, i = e.clientY - n.top;
|
|
1548
|
+
if (r < 0 || i < 0 || r > n.width || i > n.height) return this._invalidateElementContext(), null;
|
|
1549
|
+
let a = ++this._elementHitGeneration, o = this._currentPage, s = t.pageSize(o), c;
|
|
1550
|
+
try {
|
|
1551
|
+
c = await t.getElementContextAt(o, {
|
|
1552
|
+
xPt: r / n.width * s.widthPt,
|
|
1553
|
+
yPt: i / n.height * s.heightPt
|
|
1554
|
+
}, {
|
|
1555
|
+
currentDate: this._opts.currentDate,
|
|
1556
|
+
showTrackedChanges: this._opts.showTrackedChanges,
|
|
1557
|
+
maxTextCharacters: I
|
|
1558
|
+
});
|
|
1559
|
+
} catch (e) {
|
|
1560
|
+
if (this._destroyed || a !== this._elementHitGeneration || o !== this._currentPage || t !== this._doc) return null;
|
|
1561
|
+
throw e;
|
|
1562
|
+
}
|
|
1563
|
+
return this._destroyed || a !== this._elementHitGeneration || o !== this._currentPage || t !== this._doc ? null : (this._setElementContext(c), this._destroyed ? null : this.getSelectionContext());
|
|
1564
|
+
}
|
|
1565
|
+
destroy() {
|
|
1566
|
+
this._destroyed || (this._destroyed = !0, this._findRequestGeneration++, this._layoutViewGeneration++, this._unbindLayoutDocument(), this._errorRouter.close(), this._renderDispatcher.destroy(), He(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());
|
|
1567
|
+
}
|
|
1568
|
+
async _render() {
|
|
1569
|
+
let e = this._renderDispatcher.begin();
|
|
1570
|
+
try {
|
|
1571
|
+
await this._renderPage(e);
|
|
1572
|
+
} catch (t) {
|
|
1573
|
+
if (!this._renderDispatcher.isCurrent(e)) return;
|
|
1574
|
+
throw t;
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
_reportRenderError(e) {
|
|
1578
|
+
this._errorRouter.report(e);
|
|
1579
|
+
}
|
|
1580
|
+
async _renderPage(e) {
|
|
1581
|
+
if (!this._doc) return;
|
|
1582
|
+
let t = this._mode === "worker", n = this._renderWidth(), r = this._doc.pageSize(this._currentPage), i = n ?? r.widthPt * 1.3333333333333333, a = r.widthPt > 0 ? i * r.heightPt / r.widthPt : 0, o = [], s = (e) => o.push(e), c = this._opts.dpr ?? (typeof window < "u" && window.devicePixelRatio || 1), l = {
|
|
1583
|
+
width: n,
|
|
1584
|
+
dpr: this._opts.dpr,
|
|
1585
|
+
defaultTextColor: this._opts.defaultTextColor,
|
|
1586
|
+
currentDate: this._opts.currentDate,
|
|
1587
|
+
showTrackedChanges: this._opts.showTrackedChanges,
|
|
1588
|
+
onTextRun: s
|
|
1589
|
+
};
|
|
1590
|
+
if (t) {
|
|
1591
|
+
let t = await $(this._doc, this._canvas, this._currentPage, "worker", l);
|
|
1592
|
+
if (!this._renderDispatcher.commitBitmap(e, t, {
|
|
1593
|
+
cssWidth: i > 0 ? i : Math.round(t.width / c),
|
|
1594
|
+
cssHeight: a > 0 ? a : Math.round(t.height / c)
|
|
1595
|
+
})) return;
|
|
1596
|
+
} else if (await $(this._doc, this._canvas, this._currentPage, "main", l), !this._renderDispatcher.isCurrent(e)) return;
|
|
1597
|
+
this._textLayer && this._buildTextLayer(this._textLayer, o), this._find.setPageRuns(this._currentPage, o), this._buildHighlightLayer(o), this._opts.onPageChange?.(this._currentPage, this.pageCount, this.layoutComplete);
|
|
1598
|
+
}
|
|
1599
|
+
_bindLayoutDocument(e) {
|
|
1600
|
+
this._unbindLayoutDocument(), this._layoutFailed = !1;
|
|
1601
|
+
let t = !0;
|
|
1602
|
+
this._layoutUnsubscribe = kt(e, () => ({
|
|
1603
|
+
pageCount: e.pageCount,
|
|
1604
|
+
exact: e.layoutComplete,
|
|
1605
|
+
complete: e.layoutComplete
|
|
1606
|
+
}), (n) => {
|
|
1607
|
+
if (t) {
|
|
1608
|
+
t = !1;
|
|
1609
|
+
return;
|
|
1610
|
+
}
|
|
1611
|
+
this._onLayoutPublication(e, n);
|
|
1612
|
+
}, (e) => this._reportRenderError(e));
|
|
1613
|
+
}
|
|
1614
|
+
_unbindLayoutDocument() {
|
|
1615
|
+
this._layoutUnsubscribe?.(), this._layoutUnsubscribe = null, this._layoutFailed = !1, this._cancelPendingNavigation();
|
|
1616
|
+
}
|
|
1617
|
+
_onLayoutPublication(e, t) {
|
|
1618
|
+
if (!(this._destroyed || e !== this._doc)) {
|
|
1619
|
+
if (this._wakeLayoutWaiters(), t.error !== void 0) {
|
|
1620
|
+
this._layoutFailed = !0, this._errorRouter.reportBackground(t.error, this._opts.onLayoutComplete !== void 0);
|
|
1621
|
+
return;
|
|
1622
|
+
}
|
|
1623
|
+
this._find.invalidate(), this._currentPage = Math.max(0, Math.min(this._currentPage, t.pageCount - 1)), this._render().catch((e) => this._reportRenderError(e));
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
async _waitForPage(e, t, n) {
|
|
1627
|
+
await this._errorRouter.ownBackgroundLifecycle(async () => {
|
|
1628
|
+
for (; !this._destroyed && n === this._navigationGeneration && e === this._doc && t >= e.pageCount && !e.layoutComplete && !this._layoutFailed;) await new Promise((e) => {
|
|
1629
|
+
this._layoutWaiters.add(e);
|
|
1630
|
+
});
|
|
1631
|
+
e === this._doc && (e.layoutComplete || this._layoutFailed) && await e.waitUntilLayoutComplete();
|
|
1632
|
+
});
|
|
1633
|
+
}
|
|
1634
|
+
_wakeLayoutWaiters() {
|
|
1635
|
+
for (let e of this._layoutWaiters) e();
|
|
1636
|
+
this._layoutWaiters.clear();
|
|
1637
|
+
}
|
|
1638
|
+
_cancelPendingNavigation() {
|
|
1639
|
+
let e = ++this._navigationGeneration;
|
|
1640
|
+
return this._wakeLayoutWaiters(), this._setLoading(!1), e;
|
|
1641
|
+
}
|
|
1642
|
+
_setLoading(e) {
|
|
1643
|
+
this._loadingLayer.style.display = e ? "flex" : "none";
|
|
1644
|
+
}
|
|
1645
|
+
async setShowTrackedChanges(e) {
|
|
1646
|
+
let t = ++this._layoutViewGeneration, n = this._doc;
|
|
1647
|
+
if (this._opts.showTrackedChanges === !0 === e) {
|
|
1648
|
+
await n?.setLayoutView?.({
|
|
1649
|
+
showTrackedChanges: e,
|
|
1650
|
+
currentDate: this._opts.currentDate
|
|
1651
|
+
});
|
|
1652
|
+
return;
|
|
1653
|
+
}
|
|
1654
|
+
let r = {
|
|
1655
|
+
...this._opts,
|
|
1656
|
+
showTrackedChanges: e
|
|
1657
|
+
};
|
|
1658
|
+
await n?.setLayoutView?.({
|
|
1659
|
+
showTrackedChanges: e,
|
|
1660
|
+
currentDate: r.currentDate
|
|
1661
|
+
}), !(this._destroyed || t !== this._layoutViewGeneration || n !== this._doc) && (this._opts = r, this._find.invalidate(), this._currentPage = Math.max(0, Math.min(this._currentPage, this.pageCount - 1)), await this._render());
|
|
1662
|
+
}
|
|
1663
|
+
_buildHighlightLayer(e) {
|
|
1664
|
+
let t = this._highlightLayer;
|
|
1665
|
+
if (!t) return;
|
|
1666
|
+
let { width: n, height: r } = this._canvasCssPx();
|
|
1667
|
+
X(t, e, this._find.pageHighlights(this._currentPage), n, r, (e) => this._measureForFont(e), this._opts.findHighlightColors);
|
|
1668
|
+
}
|
|
1669
|
+
_canvasCssPx() {
|
|
1670
|
+
return {
|
|
1671
|
+
width: parseFloat(this._canvas.style.width) || this._canvas.width,
|
|
1672
|
+
height: parseFloat(this._canvas.style.height) || this._canvas.height
|
|
1673
|
+
};
|
|
1674
|
+
}
|
|
1675
|
+
_measureForFont(e) {
|
|
1676
|
+
this._measureCtx ||= document.createElement("canvas").getContext("2d");
|
|
1677
|
+
let t = this._measureCtx;
|
|
1678
|
+
return t ? (t.font = e, (e) => t.measureText(e).width) : (e) => e.length;
|
|
1679
|
+
}
|
|
1680
|
+
async _collectPageRuns(e) {
|
|
1681
|
+
return this._doc ? this._doc.collectPageRuns(e, {
|
|
1682
|
+
width: this._renderWidth(),
|
|
1683
|
+
currentDate: this._opts.currentDate,
|
|
1684
|
+
showTrackedChanges: this._opts.showTrackedChanges
|
|
1685
|
+
}) : [];
|
|
1686
|
+
}
|
|
1687
|
+
_buildTextLayer(e, t) {
|
|
1688
|
+
let { width: n, height: r } = this._canvasCssPx();
|
|
1689
|
+
Y(e, t, n, r, this._hyperlinkHandler(), (e) => this._measureForFont(e), this._currentPage);
|
|
1690
|
+
}
|
|
1691
|
+
_hyperlinkHandler() {
|
|
1692
|
+
return this._opts.enableHyperlinks === !1 ? void 0 : this._opts.onHyperlinkClick || ((e) => {
|
|
1693
|
+
if (e.kind === "external") {
|
|
1694
|
+
s(e.url, void 0, this._hostWindow);
|
|
1695
|
+
return;
|
|
1696
|
+
}
|
|
1697
|
+
let t = this._doc;
|
|
1698
|
+
if (!t) return;
|
|
1699
|
+
let n = ++this._internalHyperlinkGeneration;
|
|
1700
|
+
this._navigateInternalHyperlink(t, e.ref, n).catch((e) => this._reportRenderError(e));
|
|
1701
|
+
});
|
|
1702
|
+
}
|
|
1703
|
+
async _navigateInternalHyperlink(e, t, n) {
|
|
1704
|
+
if (e.layoutComplete || await e.waitUntilLayoutComplete(), this._destroyed || this._doc !== e || n !== this._internalHyperlinkGeneration) return;
|
|
1705
|
+
let r = e.getBookmarkPage(t);
|
|
1706
|
+
r !== void 0 && await this.goToPage(r);
|
|
1707
|
+
}
|
|
1708
|
+
}, Ut = 150, Wt = "0 1px 3px rgba(0,0,0,0.2)", Gt = 12, Kt = 13, qt = Symbol("DocxScrollViewer.borrowedDocument"), Jt;
|
|
1709
|
+
function Yt() {
|
|
1710
|
+
return Jt ??= import("./comment-ui-runtime-DD5a3x3k.js");
|
|
1711
|
+
}
|
|
1712
|
+
var Xt = class e {
|
|
1713
|
+
_documentOwner;
|
|
1714
|
+
get _doc() {
|
|
1715
|
+
return this._documentOwner.current;
|
|
1716
|
+
}
|
|
1717
|
+
_borrowed;
|
|
1718
|
+
_opts;
|
|
1719
|
+
_errorRouter;
|
|
1720
|
+
_container;
|
|
1721
|
+
_wrapper;
|
|
1722
|
+
_scrollHost;
|
|
1723
|
+
_spacer;
|
|
1724
|
+
_mode;
|
|
1725
|
+
_scale = 1;
|
|
1726
|
+
_scaleEstablished = !1;
|
|
1727
|
+
_pendingScale = null;
|
|
1728
|
+
_slots = /* @__PURE__ */ new Map();
|
|
1729
|
+
_free = [];
|
|
1730
|
+
_heights = [];
|
|
1731
|
+
_scrollGeometry = {
|
|
1732
|
+
offsets: [],
|
|
1733
|
+
totalHeight: 0
|
|
1734
|
+
};
|
|
1735
|
+
_lastRange = null;
|
|
1736
|
+
_lastTopIndex = -1;
|
|
1737
|
+
_lastReportedTotal = -1;
|
|
1738
|
+
_lastReportedLayoutComplete = null;
|
|
1739
|
+
_layoutUnsubscribe = null;
|
|
1740
|
+
_presentedPageCount = 0;
|
|
1741
|
+
_pendingLayoutPublication = null;
|
|
1742
|
+
_scrollListener = null;
|
|
1743
|
+
_selectionChangeListener = null;
|
|
1744
|
+
_selectionContextKey = "null";
|
|
1745
|
+
_elementClickListener = null;
|
|
1746
|
+
_contextMenuListener = null;
|
|
1747
|
+
_commentOutsidePointerListener = null;
|
|
1748
|
+
_elementContext = null;
|
|
1749
|
+
_activeCommentId = null;
|
|
1750
|
+
_activeCommentPage = null;
|
|
1751
|
+
_commentUi = null;
|
|
1752
|
+
_commentPageById = /* @__PURE__ */ new Map();
|
|
1753
|
+
_commentRunsByPage = /* @__PURE__ */ new Map();
|
|
1754
|
+
_commentIndexedPages = /* @__PURE__ */ new Set();
|
|
1755
|
+
_commentScanFrontier = 0;
|
|
1756
|
+
_commentNavigationGeneration = 0;
|
|
1757
|
+
_internalHyperlinkGeneration = 0;
|
|
1758
|
+
_commentAnchorRangesForMargin = null;
|
|
1759
|
+
_commentAnchorIds = /* @__PURE__ */ new Set();
|
|
1760
|
+
_reviewOriginPx = 0;
|
|
1761
|
+
_commentGeometryScheduled = !1;
|
|
1762
|
+
_commentGeometryFrame = null;
|
|
1763
|
+
_pendingCommentGeometry = /* @__PURE__ */ new Map();
|
|
1764
|
+
_elementHitGeneration = 0;
|
|
1765
|
+
_destroyed = !1;
|
|
1766
|
+
_measureCtx;
|
|
1767
|
+
_bitmapInFlight = /* @__PURE__ */ new Set();
|
|
1768
|
+
_renderEpoch = 0;
|
|
1769
|
+
_settleTimer = null;
|
|
1770
|
+
_wheelListener = null;
|
|
1771
|
+
_pendingZoomAnchor = null;
|
|
1772
|
+
_resizeObserver = null;
|
|
1773
|
+
_prevBase = 0;
|
|
1774
|
+
_lastFitWidth = 0;
|
|
1775
|
+
_pageShadow;
|
|
1776
|
+
_find = new Z(() => this.pageCount, (e) => this._collectPageRuns(e));
|
|
1777
|
+
_findActive = !1;
|
|
1778
|
+
_findRequestGeneration = 0;
|
|
1779
|
+
_showTrackedChanges;
|
|
1780
|
+
_layoutViewGeneration = 0;
|
|
1781
|
+
static fromDocument(t, n, r = {}) {
|
|
1782
|
+
return new e(t, {
|
|
1783
|
+
...r,
|
|
1784
|
+
[qt]: n
|
|
1785
|
+
});
|
|
1786
|
+
}
|
|
1787
|
+
constructor(e, t = {}) {
|
|
1788
|
+
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.");
|
|
1789
|
+
this._container = e, this._opts = t, this._errorRouter = new S("DocxScrollViewer", t.onError), this._showTrackedChanges = t.showTrackedChanges === !0, this._pageShadow = t.pageShadow ?? Wt;
|
|
1790
|
+
let n = t[qt];
|
|
1791
|
+
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() && Yt().then((e) => {
|
|
1792
|
+
if (!this._destroyed) {
|
|
1793
|
+
this._commentUi = e;
|
|
1794
|
+
for (let [e, t] of this._slots) this._redrawSlotComments(e, t);
|
|
1795
|
+
}
|
|
1796
|
+
}).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) => {
|
|
1797
|
+
this._onElementClick(e).catch((e) => this._reportRenderError(e));
|
|
1798
|
+
}, 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) => {
|
|
1799
|
+
if (!Se(e, this._wrapper, "ooxmlCommentId") && this._activeCommentId !== null) {
|
|
1800
|
+
this._activeCommentId = null, this._activeCommentPage = null;
|
|
1801
|
+
for (let [e, t] of this._slots) this._redrawSlotComments(e, t);
|
|
1802
|
+
this._emitSelectionContextChange();
|
|
1803
|
+
}
|
|
1804
|
+
}, this._wrapper.ownerDocument.addEventListener("pointerdown", this._commentOutsidePointerListener)), this._opts.enableZoom !== !1 && (this._wheelListener = (e) => {
|
|
1805
|
+
if (!(e.ctrlKey || e.metaKey) || (e.preventDefault(), e.deltaY === 0)) return;
|
|
1806
|
+
let t = this._scrollHost.getBoundingClientRect(), n = e.clientX - t.left, r = e.clientY - t.top;
|
|
1807
|
+
this._pendingZoomAnchor = Number.isFinite(n) && Number.isFinite(r) ? {
|
|
1808
|
+
x: n,
|
|
1809
|
+
y: r
|
|
1810
|
+
} : null, this.setScale(fe(this._scale, e.deltaY));
|
|
1811
|
+
}, 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._bindLayoutDocument(n), this.relayout());
|
|
1812
|
+
}
|
|
1813
|
+
async load(e) {
|
|
1814
|
+
if (this._destroyed) throw Error("DocxScrollViewer is destroyed");
|
|
1815
|
+
if (this._borrowed) throw Error("DocxScrollViewer.load() is unsupported on a Viewer created by fromDocument(); the borrowed document is already loaded.");
|
|
1816
|
+
let t = !1;
|
|
1817
|
+
try {
|
|
1818
|
+
let n = await this._documentOwner.replace(() => q.load(e, {
|
|
1819
|
+
password: this._opts.password,
|
|
1820
|
+
useGoogleFonts: this._opts.useGoogleFonts,
|
|
1821
|
+
maxZipEntryBytes: this._opts.maxZipEntryBytes,
|
|
1822
|
+
resourceLimits: this._opts.resourceLimits,
|
|
1823
|
+
debug: this._opts.debug,
|
|
1824
|
+
onResourceMetrics: this._opts.onResourceMetrics,
|
|
1825
|
+
workerTimeoutMs: this._opts.workerTimeoutMs,
|
|
1826
|
+
wasmUrl: this._opts.wasmUrl,
|
|
1827
|
+
math: this._opts.math,
|
|
1828
|
+
threeD: this._opts.threeD,
|
|
1829
|
+
regionMap: this._opts.regionMap,
|
|
1830
|
+
chartEx: this._opts.chartEx,
|
|
1831
|
+
mode: this._mode,
|
|
1832
|
+
...this._showTrackedChanges ? { showTrackedChanges: !0 } : {},
|
|
1833
|
+
...this._opts.currentDate === void 0 ? {} : { currentDate: this._opts.currentDate },
|
|
1834
|
+
...this._opts.progressiveLayout ? { progressiveLayout: !0 } : {},
|
|
1835
|
+
...this._opts.sliceLayout ? { sliceLayout: !0 } : {},
|
|
1836
|
+
onLayoutProgress: this._opts.onLayoutProgress,
|
|
1837
|
+
onLayoutPartial: this._opts.onLayoutPartial,
|
|
1838
|
+
onLayoutComplete: this._opts.onLayoutComplete
|
|
1839
|
+
}), (e) => {
|
|
1840
|
+
if (this._invalidateElementContext(!1), t = !0, this._findRequestGeneration++, this._find.invalidate(), this._findActive = !1, this._activeCommentId = null, this._activeCommentPage = null, this._resetCommentNavigation(), this._unbindLayoutDocument(), e) {
|
|
1841
|
+
for (let [e, t] of [...this._slots]) this._recycleSlot(e, t);
|
|
1842
|
+
this._lastTopIndex = -1, this._lastReportedTotal = -1, this._lastReportedLayoutComplete = null;
|
|
1843
|
+
}
|
|
1844
|
+
});
|
|
1845
|
+
if (!n) return;
|
|
1846
|
+
if (this._destroyed) throw Error("DocxScrollViewer is destroyed");
|
|
1847
|
+
this._bindLayoutDocument(n), this._find.invalidate(), this._findActive = !1, this._activeCommentId = null, this._activeCommentPage = null, this._resetCommentNavigation();
|
|
1848
|
+
let r = [];
|
|
1849
|
+
this._relayout(r), await Promise.all(r);
|
|
1850
|
+
} catch (e) {
|
|
1851
|
+
throw this._destroyed ? Error("DocxScrollViewer is destroyed") : e instanceof Error ? e : Error(String(e));
|
|
1852
|
+
}
|
|
1853
|
+
t && !this._destroyed && this._emitSelectionContextChange();
|
|
1854
|
+
}
|
|
1855
|
+
get pageCount() {
|
|
1856
|
+
return this._doc?.pageCount ?? 0;
|
|
1857
|
+
}
|
|
1858
|
+
get layoutComplete() {
|
|
1859
|
+
return this._doc?.layoutComplete ?? !0;
|
|
1860
|
+
}
|
|
1861
|
+
async waitUntilLayoutComplete() {
|
|
1862
|
+
await this._errorRouter.ownBackgroundLifecycle(async () => {
|
|
1863
|
+
await this._doc?.waitUntilLayoutComplete?.();
|
|
1864
|
+
});
|
|
1865
|
+
}
|
|
1866
|
+
_bindLayoutDocument(e) {
|
|
1867
|
+
this._unbindLayoutDocument(), this._presentedPageCount = e.pageCount, this._pendingLayoutPublication = null;
|
|
1868
|
+
let t = !0;
|
|
1869
|
+
this._layoutUnsubscribe = kt(e, () => ({
|
|
1870
|
+
pageCount: e.pageCount,
|
|
1871
|
+
exact: e.layoutComplete,
|
|
1872
|
+
complete: e.layoutComplete
|
|
1873
|
+
}), (n) => {
|
|
1874
|
+
if (t) {
|
|
1875
|
+
t = !1;
|
|
1876
|
+
return;
|
|
1877
|
+
}
|
|
1878
|
+
this._onLayoutPublication(e, n);
|
|
1879
|
+
}, (e) => this._reportRenderError(e));
|
|
1880
|
+
}
|
|
1881
|
+
_unbindLayoutDocument() {
|
|
1882
|
+
this._layoutUnsubscribe?.(), this._layoutUnsubscribe = null, this._presentedPageCount = 0, this._pendingLayoutPublication = null;
|
|
1883
|
+
}
|
|
1884
|
+
_onLayoutPublication(e, t) {
|
|
1885
|
+
if (!(this._destroyed || e !== this._doc)) {
|
|
1886
|
+
if (t.error !== void 0) {
|
|
1887
|
+
this._errorRouter.reportBackground(t.error, this._opts.onLayoutComplete !== void 0);
|
|
1888
|
+
return;
|
|
1889
|
+
}
|
|
1890
|
+
if (this._find.invalidate(), this._refreshCommentSurface(), !t.complete) {
|
|
1891
|
+
if (this._pendingLayoutPublication = t, this._lastRange && this._emitVisiblePageChange(this._lastRange), this._presentedPageCount === 0 || t.pageCount < this._presentedPageCount) {
|
|
1892
|
+
this._pendingLayoutPublication = null, this._applyLayoutPublication(t);
|
|
1893
|
+
return;
|
|
1894
|
+
}
|
|
1895
|
+
this._revealPendingLayoutAtPresentedTail();
|
|
1896
|
+
return;
|
|
1897
|
+
}
|
|
1898
|
+
this._pendingLayoutPublication = null, this._applyLayoutPublication(t);
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
_refreshCommentSurface() {
|
|
1902
|
+
if (!(!this._commentsEnabled() || this._slots.size === 0)) {
|
|
1903
|
+
this._syncSpacerWidth();
|
|
1904
|
+
for (let [e, t] of this._slots) this._redrawSlotComments(e, t);
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
_applyLayoutPublication(e) {
|
|
1908
|
+
let t = [...this._slots];
|
|
1909
|
+
this._presentedPageCount = e.pageCount, this._renderEpoch++, this.relayout();
|
|
1910
|
+
for (let [e, n] of t) e >= this._presentedPageCount || this._slots.get(e) !== n || this._refreshSlotAtomically(e, n);
|
|
1911
|
+
}
|
|
1912
|
+
_revealPendingLayoutAtPresentedTail() {
|
|
1913
|
+
let e = this._pendingLayoutPublication;
|
|
1914
|
+
!e || this._presentedPageCount === 0 || T(this._scrollGeometry, this._scrollHost.scrollTop, this._scrollHost.clientHeight, 0).end < this._presentedPageCount - 1 || (this._pendingLayoutPublication = null, this._applyLayoutPublication(e));
|
|
1915
|
+
}
|
|
1916
|
+
_revealPendingLayoutThroughPage(e) {
|
|
1917
|
+
let t = this._pendingLayoutPublication;
|
|
1918
|
+
!t || e < this._presentedPageCount || (this._pendingLayoutPublication = null, this._applyLayoutPublication(t));
|
|
1919
|
+
}
|
|
1920
|
+
_pageWidthPx(e) {
|
|
1921
|
+
return this._doc.pageSize(e).widthPt * M * this._scale;
|
|
1922
|
+
}
|
|
1923
|
+
_pageHeightPx(e) {
|
|
1924
|
+
return this._doc.pageSize(e).heightPt * M * this._scale;
|
|
1925
|
+
}
|
|
1926
|
+
_fitWidthPx() {
|
|
1927
|
+
if (this._opts.width && this._opts.width > 0) return this._opts.width;
|
|
1928
|
+
let e = this._scrollHost.clientWidth || this._container.clientWidth;
|
|
1929
|
+
if (e <= 0) return 0;
|
|
1930
|
+
let { left: t, right: n } = this._padH(), r = e - t - n;
|
|
1931
|
+
return r <= 0 ? 0 : r;
|
|
1932
|
+
}
|
|
1933
|
+
_hasCommentMargin() {
|
|
1934
|
+
return this._hasDisplayableComments() && this._commentsOptions()?.cards !== !1;
|
|
1935
|
+
}
|
|
1936
|
+
_hasDisplayableComments() {
|
|
1937
|
+
if (!this._commentsEnabled()) return !1;
|
|
1938
|
+
let e = this._doc;
|
|
1939
|
+
if (!e) return !1;
|
|
1940
|
+
let t = e.commentAnchorRanges();
|
|
1941
|
+
if (this._commentAnchorRangesForMargin !== t && (this._commentAnchorRangesForMargin = t, this._commentAnchorIds = new Set(t.map((e) => e.commentId))), this._commentAnchorIds.size === 0) return !1;
|
|
1942
|
+
let n = this._commentsOptions()?.includeResolved === !0;
|
|
1943
|
+
return e.comments.some((e) => this._commentAnchorIds.has(e.id) && e.parentId === void 0 && (n || e.resolved !== !0));
|
|
1944
|
+
}
|
|
1945
|
+
_commentMarginExtent() {
|
|
1946
|
+
return this._hasCommentMargin() ? (Gt + 280) * this._commentZoom() : 0;
|
|
1947
|
+
}
|
|
1948
|
+
_commentZoom() {
|
|
1949
|
+
return this._scaleEstablished ? this._scale : 1;
|
|
1950
|
+
}
|
|
1951
|
+
_commentsEnabled() {
|
|
1952
|
+
return this._opts.comments === !0 || typeof this._opts.comments == "object";
|
|
1953
|
+
}
|
|
1954
|
+
_commentsOptions() {
|
|
1955
|
+
return typeof this._opts.comments == "object" ? this._opts.comments : void 0;
|
|
1956
|
+
}
|
|
1957
|
+
_commentSide() {
|
|
1958
|
+
let e = this._commentsOptions()?.side;
|
|
1959
|
+
return e === "left" || e === "right" ? e : (this._container.ownerDocument.defaultView?.getComputedStyle?.(this._container).direction || this._container.dir || this._container.style.direction) === "rtl" ? "left" : "right";
|
|
1960
|
+
}
|
|
1961
|
+
_syncCommentMarginGeometry(e) {
|
|
1962
|
+
if (!e) return;
|
|
1963
|
+
let t = this._commentZoom(), n = `calc(100% + ${Gt * t}px)`;
|
|
1964
|
+
e.style.left = this._commentSide() === "right" ? n : "", e.style.right = this._commentSide() === "left" ? n : "", e.style.width = `${280 * t}px`, e.style.fontSize = `${Kt}px`, e.dataset.ooxmlCommentZoom = String(t);
|
|
1965
|
+
}
|
|
1966
|
+
_baseScale() {
|
|
1967
|
+
if (!this._doc || this._doc.pageCount === 0) return 0;
|
|
1968
|
+
let e = this._fitWidthPx();
|
|
1969
|
+
if (e <= 0) return 0;
|
|
1970
|
+
let t = this._doc.pageSize(0).widthPt;
|
|
1971
|
+
return t <= 0 ? 0 : e / (t * M);
|
|
1972
|
+
}
|
|
1973
|
+
relayout() {
|
|
1974
|
+
this._relayout();
|
|
1975
|
+
}
|
|
1976
|
+
_relayout(e) {
|
|
1977
|
+
if (this._doc) {
|
|
1978
|
+
if (this._doc.layoutComplete !== !1 && this._pendingLayoutPublication === null && (this._presentedPageCount = this._doc.pageCount), !this._scaleEstablished) {
|
|
1979
|
+
let e = this._baseScale();
|
|
1980
|
+
if (e > 0) {
|
|
1981
|
+
if (this._scale = e, this._prevBase = e, this._lastFitWidth = this._fitWidthPx(), this._scaleEstablished = !0, this._pendingScale !== null) {
|
|
1982
|
+
let e = this._pendingScale;
|
|
1983
|
+
this._pendingScale = null, e !== this._scale && (this._scale = e, this._opts.onScaleChange?.(e));
|
|
1984
|
+
}
|
|
1985
|
+
} else return;
|
|
1986
|
+
}
|
|
1987
|
+
this._recomputeHeights(), this._syncSpacer(), this._mountVisible(e);
|
|
1988
|
+
for (let [e, t] of this._slots) t.renderedPage === e && t.renderedScale >= 0 && this._redrawSlotComments(e, t);
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
_recomputeHeights() {
|
|
1992
|
+
let e = Math.min(this._presentedPageCount, this._doc.pageCount), t = Array(e);
|
|
1993
|
+
for (let n = 0; n < e; n++) t[n] = this._pageHeightPx(n);
|
|
1994
|
+
this._heights = t, this._scrollGeometry = xe(t, this._gap(), this._pad());
|
|
1995
|
+
}
|
|
1996
|
+
_gap() {
|
|
1997
|
+
return this._opts.gap ?? 16;
|
|
1998
|
+
}
|
|
1999
|
+
_overscan() {
|
|
2000
|
+
return this._opts.overscan ?? 1;
|
|
2001
|
+
}
|
|
2002
|
+
_pad() {
|
|
2003
|
+
let e = this._gap();
|
|
2004
|
+
return {
|
|
2005
|
+
leading: this._opts.paddingTop ?? e,
|
|
2006
|
+
trailing: this._opts.paddingBottom ?? e
|
|
2007
|
+
};
|
|
2008
|
+
}
|
|
2009
|
+
_padH() {
|
|
2010
|
+
let e = this._gap();
|
|
2011
|
+
return {
|
|
2012
|
+
left: this._opts.paddingLeft ?? e,
|
|
2013
|
+
right: this._opts.paddingRight ?? e
|
|
2014
|
+
};
|
|
2015
|
+
}
|
|
2016
|
+
_pageIndexAtOffset(e, t) {
|
|
2017
|
+
let { offsets: n } = e, r = 0, i = n.length - 1, a = 0;
|
|
2018
|
+
for (; r <= i;) {
|
|
2019
|
+
let e = r + i >> 1;
|
|
2020
|
+
n[e] <= t ? (a = e, r = e + 1) : i = e - 1;
|
|
2021
|
+
}
|
|
2022
|
+
return a;
|
|
2023
|
+
}
|
|
2024
|
+
_range() {
|
|
2025
|
+
return T(this._scrollGeometry, this._scrollHost.scrollTop, this._scrollHost.clientHeight, this._overscan());
|
|
2026
|
+
}
|
|
2027
|
+
_syncSpacer() {
|
|
2028
|
+
let e = this._range();
|
|
2029
|
+
this._lastRange = e, this._spacer.style.height = `${e.totalHeight}px`, this._syncSpacerWidth();
|
|
2030
|
+
}
|
|
2031
|
+
_syncSpacerWidth() {
|
|
2032
|
+
let { left: e, right: t } = this._padH(), n = 0;
|
|
2033
|
+
for (let e = 0; e < this._heights.length; e++) {
|
|
2034
|
+
let t = this._pageWidthPx(e);
|
|
2035
|
+
t > n && (n = t);
|
|
2036
|
+
}
|
|
2037
|
+
let r = this._commentMarginExtent(), i = this._commentSide() === "left" ? r : 0, a = i - this._reviewOriginPx, o = Math.max(0, this._scrollHost.scrollLeft + a);
|
|
2038
|
+
this._spacer.style.width = `${n + r + e + t}px`, a !== 0 && (this._reviewOriginPx = i, this._scrollHost.style["--ooxml-review-origin-x"] = `${i}px`, this._scrollHost.scrollLeft = o);
|
|
2039
|
+
}
|
|
2040
|
+
_onScroll() {
|
|
2041
|
+
!this._doc || !this._scaleEstablished || (this._revealPendingLayoutAtPresentedTail(), this._mountVisible(void 0, !1));
|
|
2042
|
+
}
|
|
2043
|
+
_mountVisible(e, t = !0) {
|
|
2044
|
+
if (!this._doc || this._doc.pageCount === 0) return;
|
|
2045
|
+
let n = this._range();
|
|
2046
|
+
this._lastRange = n;
|
|
2047
|
+
for (let [e, t] of [...this._slots]) (e < n.start || e > n.end) && this._recycleSlot(e, t);
|
|
2048
|
+
for (let r = n.start; r <= n.end; r++) if (!this._slots.has(r)) {
|
|
2049
|
+
let t = this._acquireSlot();
|
|
2050
|
+
this._positionSlot(t, r, n), this._slots.set(r, t);
|
|
2051
|
+
let i = this._renderSlot(r, t, e === void 0);
|
|
2052
|
+
e && i && e.push(i);
|
|
2053
|
+
} else if (t) {
|
|
2054
|
+
let t = this._slots.get(r);
|
|
2055
|
+
this._positionSlot(t, r, n);
|
|
2056
|
+
let i = this._renderSlot(r, t, e === void 0);
|
|
2057
|
+
e && i && e.push(i);
|
|
2058
|
+
}
|
|
2059
|
+
this._emitVisiblePageChange(n);
|
|
2060
|
+
}
|
|
2061
|
+
_emitVisiblePageChange(e) {
|
|
2062
|
+
if (!this._doc) return;
|
|
2063
|
+
let t = this._doc.pageCount, n = this.layoutComplete;
|
|
2064
|
+
e.topIndex === this._lastTopIndex && t === this._lastReportedTotal && n === this._lastReportedLayoutComplete || (this._lastTopIndex = e.topIndex, this._lastReportedTotal = t, this._lastReportedLayoutComplete = n, this._opts.onVisiblePageChange?.(e.topIndex, t, n));
|
|
2065
|
+
}
|
|
2066
|
+
_applyPageShadow(e) {
|
|
2067
|
+
this._pageShadow !== !1 && (e.style.boxShadow = this._pageShadow);
|
|
2068
|
+
}
|
|
2069
|
+
_acquireSlot() {
|
|
2070
|
+
let e = this._free.pop();
|
|
2071
|
+
if (e) return this._scrollHost.appendChild(e.wrapper), e;
|
|
2072
|
+
let t = document.createElement("div");
|
|
2073
|
+
t.style.cssText = "position:absolute;";
|
|
2074
|
+
let n = document.createElement("canvas");
|
|
2075
|
+
n.style.cssText = "display:block;background:#fff;", this._applyPageShadow(n), t.appendChild(n);
|
|
2076
|
+
let r = null;
|
|
2077
|
+
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));
|
|
2078
|
+
let i = document.createElement("div");
|
|
2079
|
+
i.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;overflow:hidden;pointer-events:none;", t.appendChild(i);
|
|
2080
|
+
let a = null, o = null, s = null;
|
|
2081
|
+
this._commentsEnabled() && (a = document.createElement("div"), a.style.cssText = "position:absolute;inset:0;overflow:hidden;pointer-events:none;", t.appendChild(a), this._commentsOptions()?.cards !== !1 && (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)));
|
|
2082
|
+
let c = oe(t, this._opts.enableElementSelection === !0);
|
|
2083
|
+
return this._scrollHost.appendChild(t), {
|
|
2084
|
+
wrapper: t,
|
|
2085
|
+
canvas: n,
|
|
2086
|
+
textLayer: r,
|
|
2087
|
+
highlightLayer: i,
|
|
2088
|
+
elementLayer: c,
|
|
2089
|
+
commentTintLayer: a,
|
|
2090
|
+
commentMargin: o,
|
|
2091
|
+
commentDecorationLayer: s,
|
|
2092
|
+
commentRuns: Object.freeze([]),
|
|
2093
|
+
commentGeometry: null,
|
|
2094
|
+
renderedPage: -1,
|
|
2095
|
+
renderedScale: -1,
|
|
2096
|
+
dispatcher: new b(n, this._mode === "worker")
|
|
2097
|
+
};
|
|
2098
|
+
}
|
|
2099
|
+
_recycleSlot(e, t) {
|
|
2100
|
+
this._slots.delete(e), t.dispatcher.destroy(), this._destroyed || (t.dispatcher = new b(t.canvas, this._mode === "worker")), t.textLayer && (t.textLayer.innerHTML = "", this._clearTextLayerPreview(t.textLayer)), 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);
|
|
2101
|
+
}
|
|
2102
|
+
_positionSlot(e, t, n) {
|
|
2103
|
+
e.wrapper.style.top = `${n.offsets[t]}px`;
|
|
2104
|
+
let r = this._pageWidthPx(t), i = this._pageHeightPx(t);
|
|
2105
|
+
if (e.wrapper.style.width = `${r}px`, e.wrapper.style.height = `${i}px`, this._syncCommentMarginGeometry(e.commentMargin), e.commentDecorationLayer) {
|
|
2106
|
+
let t = this._commentMarginExtent();
|
|
2107
|
+
e.commentDecorationLayer.style.left = this._commentSide() === "left" ? `${-t}px` : "0px", e.commentDecorationLayer.style.width = `${r + t}px`, e.commentDecorationLayer.style.height = `${i}px`;
|
|
2108
|
+
}
|
|
2109
|
+
this._redrawElementOutlineForSlot(t, e);
|
|
2110
|
+
let { left: a } = this._padH(), o = Math.max(a, (this._scrollHost.clientWidth - r) / 2);
|
|
2111
|
+
e.wrapper.style.left = this._commentSide() === "left" && this._commentsEnabled() ? `calc(${o}px + var(--ooxml-review-origin-x, 0px))` : `${o}px`;
|
|
2112
|
+
}
|
|
2113
|
+
_dpr() {
|
|
2114
|
+
return this._opts.dpr ?? (typeof window < "u" && window.devicePixelRatio || 1);
|
|
2115
|
+
}
|
|
2116
|
+
_renderSlot(e, t, n = !0) {
|
|
2117
|
+
if (!this._doc || t.renderedPage === e) return null;
|
|
2118
|
+
t.renderedPage = e;
|
|
2119
|
+
let r = this._dpr(), i = this._pageWidthPx(e), a = this._renderEpoch, o = this._scale, s = t.dispatcher, c = s.begin();
|
|
2120
|
+
if (this._mode === "worker") return this._renderSlotBitmap(e, t, i, r, o, s, c, n);
|
|
2121
|
+
let l = [], u = !!this._opts.enableTextSelection && !!t.textLayer, d = u || this._findActive || !!t.commentTintLayer, f = d ? (e) => l.push(e) : void 0, p;
|
|
2122
|
+
try {
|
|
2123
|
+
p = $(this._doc, t.canvas, e, "main", {
|
|
2124
|
+
width: i,
|
|
2125
|
+
dpr: r,
|
|
2126
|
+
defaultTextColor: this._opts.defaultTextColor,
|
|
2127
|
+
currentDate: this._opts.currentDate,
|
|
2128
|
+
...this._showTrackedChanges ? { showTrackedChanges: !0 } : {},
|
|
2129
|
+
onTextRun: f
|
|
2130
|
+
});
|
|
2131
|
+
} catch (e) {
|
|
2132
|
+
return n ? (this._reportRenderError(e), Promise.resolve()) : Promise.reject(e);
|
|
2133
|
+
}
|
|
2134
|
+
return p.then(() => {
|
|
2135
|
+
if (!(!s.isCurrent(c) || a !== this._renderEpoch || this._slots.get(e) !== t || t.renderedPage !== e)) {
|
|
2136
|
+
if (t.renderedScale = o, u && t.textLayer) {
|
|
2137
|
+
let { width: n, height: r } = this._canvasCssPx(t.canvas);
|
|
2138
|
+
Y(t.textLayer, l, n, r, this._hyperlinkHandler(), (e) => this._measureForFont(e), e);
|
|
2139
|
+
}
|
|
2140
|
+
d && this._refreshFindRuns(e, l), this._commitCommentRuns(e, t, l), this._redrawSlotHighlights(e, t);
|
|
2141
|
+
}
|
|
2142
|
+
}).catch((r) => {
|
|
2143
|
+
if (s.isCurrent(c) && a === this._renderEpoch && this._slots.get(e) === t && t.renderedPage === e) if (n) this._reportRenderError(r);
|
|
2144
|
+
else throw r;
|
|
2145
|
+
});
|
|
2146
|
+
}
|
|
2147
|
+
_hyperlinkHandler() {
|
|
2148
|
+
return this._opts.enableHyperlinks === !1 ? void 0 : this._opts.onHyperlinkClick || ((e) => {
|
|
2149
|
+
if (e.kind === "external") {
|
|
2150
|
+
s(e.url);
|
|
2151
|
+
return;
|
|
2152
|
+
}
|
|
2153
|
+
let t = this._doc;
|
|
2154
|
+
if (!t) return;
|
|
2155
|
+
let n = ++this._internalHyperlinkGeneration;
|
|
2156
|
+
this._navigateInternalHyperlink(t, e.ref, n).catch((e) => this._reportRenderError(e));
|
|
2157
|
+
});
|
|
2158
|
+
}
|
|
2159
|
+
async _navigateInternalHyperlink(e, t, n) {
|
|
2160
|
+
if (e.layoutComplete || await e.waitUntilLayoutComplete(), this._destroyed || this._doc !== e || n !== this._internalHyperlinkGeneration) return;
|
|
2161
|
+
let r = e.getBookmarkPage(t);
|
|
2162
|
+
r !== void 0 && this.scrollToPage(r);
|
|
2163
|
+
}
|
|
2164
|
+
_measureForFont(e) {
|
|
2165
|
+
this._measureCtx === void 0 && (this._measureCtx = document.createElement("canvas").getContext("2d"));
|
|
2166
|
+
let t = this._measureCtx;
|
|
2167
|
+
return !t || typeof t.measureText != "function" ? (e) => e.length : (t.font = e, (e) => t.measureText(e).width);
|
|
2168
|
+
}
|
|
2169
|
+
_canvasCssPx(e) {
|
|
2170
|
+
return {
|
|
2171
|
+
width: parseFloat(e.style.width) || e.width,
|
|
2172
|
+
height: parseFloat(e.style.height) || e.height
|
|
2173
|
+
};
|
|
2174
|
+
}
|
|
2175
|
+
_reportRenderError(e) {
|
|
2176
|
+
this._errorRouter.report(e);
|
|
2177
|
+
}
|
|
2178
|
+
async _renderSlotBitmap(e, t, n, r, i, a = t.dispatcher, o = a.begin(), s = !0) {
|
|
2179
|
+
if (this._bitmapInFlight.has(e) || this._slots.get(e) !== t) return;
|
|
2180
|
+
let c = this._renderEpoch, l = this._pageHeightPx(e);
|
|
2181
|
+
this._bitmapInFlight.add(e);
|
|
2182
|
+
let u = !1, d = !!this._opts.enableTextSelection && !!t.textLayer, f = d || this._findActive || !!t.commentTintLayer, p = [];
|
|
2183
|
+
try {
|
|
2184
|
+
let s = await $(this._doc, t.canvas, e, "worker", {
|
|
2185
|
+
width: n,
|
|
2186
|
+
dpr: r,
|
|
2187
|
+
defaultTextColor: this._opts.defaultTextColor,
|
|
2188
|
+
currentDate: this._opts.currentDate,
|
|
2189
|
+
...this._showTrackedChanges ? { showTrackedChanges: !0 } : {},
|
|
2190
|
+
onTextRun: f ? (e) => p.push(e) : void 0
|
|
2191
|
+
});
|
|
2192
|
+
if (!a.isCurrent(o) || c !== this._renderEpoch || this._slots.get(e) !== t || t.renderedPage !== e) {
|
|
2193
|
+
s.close();
|
|
2194
|
+
return;
|
|
2195
|
+
}
|
|
2196
|
+
if (!a.commitBitmap(o, s, {
|
|
2197
|
+
cssWidth: n,
|
|
2198
|
+
cssHeight: l
|
|
2199
|
+
})) return;
|
|
2200
|
+
if (t.renderedScale = i, t.textLayer && (this._clearTextLayerPreview(t.textLayer), d)) {
|
|
2201
|
+
let { width: n, height: r } = this._canvasCssPx(t.canvas);
|
|
2202
|
+
Y(t.textLayer, p, n, r, this._hyperlinkHandler(), (e) => this._measureForFont(e), e);
|
|
2203
|
+
}
|
|
2204
|
+
f && this._refreshFindRuns(e, p), this._commitCommentRuns(e, t, p), this._redrawSlotHighlights(e, t), u = !0;
|
|
2205
|
+
} catch (n) {
|
|
2206
|
+
if (a.isCurrent(o) && c === this._renderEpoch && this._slots.get(e) === t && t.renderedPage === e) if (s) this._reportRenderError(n);
|
|
2207
|
+
else throw n;
|
|
2208
|
+
} finally {
|
|
2209
|
+
this._bitmapInFlight.delete(e);
|
|
2210
|
+
let n = this._slots.get(e);
|
|
2211
|
+
!u && n && (n !== t || c !== this._renderEpoch || !a.isCurrent(o)) && !this._bitmapInFlight.has(e) && !this._destroyed && this._renderSlotBitmap(e, n, this._pageWidthPx(e), this._dpr(), this._scale);
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
setScale(e) {
|
|
2215
|
+
let t = this._opts.zoomMin ?? .1, n = this._opts.zoomMax ?? 4, r = Math.min(n, Math.max(t, e)), i = this._pendingZoomAnchor;
|
|
2216
|
+
if (this._pendingZoomAnchor = null, !this._doc || this._doc.pageCount === 0 || !this._scaleEstablished) {
|
|
2217
|
+
this._pendingScale = r;
|
|
2218
|
+
return;
|
|
2219
|
+
}
|
|
2220
|
+
if (r === this._scale) return;
|
|
2221
|
+
let a = this._scale, o = i ? i.y : 0, s = this._range(), c = this._scrollHost.scrollTop, l = c + o, u = this._pageIndexAtOffset(s, l), d = this._heights[u] || 0, f = d > 0 ? (l - s.offsets[u]) / d : 0;
|
|
2222
|
+
f = Math.min(1, Math.max(0, f));
|
|
2223
|
+
let p = this._padH().left, m = this._scrollHost.scrollLeft || 0;
|
|
2224
|
+
this._renderEpoch++, this._scale = r, this._recomputeHeights();
|
|
2225
|
+
let h = T(this._scrollGeometry, 0, this._scrollHost.clientHeight, this._overscan());
|
|
2226
|
+
this._spacer.style.height = `${h.totalHeight}px`, this._syncSpacerWidth();
|
|
2227
|
+
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;
|
|
2228
|
+
if (this._scrollHost.scrollTop = Math.min(g, Math.max(0, v)), i) {
|
|
2229
|
+
let e = Math.max(0, (this._spacer.offsetWidth || 0) - this._scrollHost.clientWidth);
|
|
2230
|
+
this._scrollHost.scrollLeft = ee(m, i.x - p, a, r, { maxScroll: e });
|
|
2231
|
+
}
|
|
2232
|
+
this._previewVisible(), this._scheduleSettle(), this._opts.onScaleChange?.(r);
|
|
2233
|
+
}
|
|
2234
|
+
getScale() {
|
|
2235
|
+
return this._scaleEstablished ? this._scale : this._pendingScale ?? 1;
|
|
2236
|
+
}
|
|
2237
|
+
zoomIn() {
|
|
2238
|
+
this.setScale(C(this.getScale()));
|
|
2239
|
+
}
|
|
2240
|
+
zoomOut() {
|
|
2241
|
+
this.setScale(w(this.getScale()));
|
|
2242
|
+
}
|
|
2243
|
+
fitWidth() {
|
|
2244
|
+
this._fit("width");
|
|
2245
|
+
}
|
|
2246
|
+
fitPage() {
|
|
2247
|
+
this._fit("page");
|
|
2248
|
+
}
|
|
2249
|
+
_fit(e) {
|
|
2250
|
+
if (!this._doc || this._doc.pageCount === 0) return;
|
|
2251
|
+
let t = this._doc.pageSize(0), n = g({
|
|
2252
|
+
contentWidth: t.widthPt * M,
|
|
2253
|
+
contentHeight: t.heightPt * M,
|
|
2254
|
+
containerWidth: this._fitWidthPx(),
|
|
2255
|
+
containerHeight: this._scrollHost.clientHeight
|
|
2256
|
+
}, e);
|
|
2257
|
+
n <= 0 || this.setScale(n);
|
|
2258
|
+
}
|
|
2259
|
+
_previewVisible() {
|
|
2260
|
+
if (!this._doc || this._doc.pageCount === 0) return;
|
|
2261
|
+
let e = this._range();
|
|
2262
|
+
this._lastRange = e;
|
|
2263
|
+
for (let [t, n] of [...this._slots]) (t < e.start || t > e.end) && this._recycleSlot(t, n);
|
|
2264
|
+
for (let t = e.start; t <= e.end; t++) {
|
|
2265
|
+
let n = this._slots.get(t);
|
|
2266
|
+
if (n) this._previewSlot(n, t, e);
|
|
2267
|
+
else {
|
|
2268
|
+
let n = this._acquireSlot();
|
|
2269
|
+
this._positionSlot(n, t, e), this._slots.set(t, n), this._renderSlot(t, n);
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
this._emitVisiblePageChange(e);
|
|
2273
|
+
}
|
|
2274
|
+
_previewSlot(e, t, n) {
|
|
2275
|
+
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) {
|
|
2276
|
+
let n = this._scale / e.renderedScale;
|
|
2277
|
+
e.textLayer && (e.textLayer.style.transformOrigin = "0 0", e.textLayer.style.width = `${this._pageWidthPx(t) / n}px`, e.textLayer.style.height = `${this._pageHeightPx(t) / n}px`, e.textLayer.style.transform = `scale(${n})`), e.commentMargin && this._commentUi?.previewReadOnlyCommentMargin(e.commentMargin, n);
|
|
2278
|
+
for (let t of e.commentTintLayer?.children ?? []) t.dataset.ooxmlCommentMarker !== void 0 && (t.style.transform = `translate(-50%,-50%) scale(${n})`);
|
|
2279
|
+
e.commentTintLayer && (e.commentTintLayer.style.visibility = ""), e.commentMargin && (e.commentMargin.style.visibility = ""), e.commentDecorationLayer && (e.commentDecorationLayer.style.visibility = "");
|
|
2280
|
+
return;
|
|
2281
|
+
}
|
|
2282
|
+
e.commentTintLayer && (e.commentTintLayer.style.visibility = "hidden"), e.commentMargin && (e.commentMargin.style.visibility = "hidden"), e.commentDecorationLayer && (e.commentDecorationLayer.style.visibility = "hidden");
|
|
2283
|
+
}
|
|
2284
|
+
_clearTextLayerPreview(e) {
|
|
2285
|
+
e.style.transform = "", e.style.transformOrigin = "", e.style.width = "100%", e.style.height = "100%";
|
|
2286
|
+
}
|
|
2287
|
+
_scheduleSettle() {
|
|
2288
|
+
this._settleTimer !== null && clearTimeout(this._settleTimer), this._settleTimer = setTimeout(() => {
|
|
2289
|
+
this._settleTimer = null, this._settleRender();
|
|
2290
|
+
}, Ut);
|
|
2291
|
+
}
|
|
2292
|
+
_settleRender() {
|
|
2293
|
+
if (!(this._destroyed || !this._doc || this._doc.pageCount === 0)) for (let [e, t] of [...this._slots]) t.renderedScale !== this._scale && this._refreshSlotAtomically(e, t);
|
|
2294
|
+
}
|
|
2295
|
+
_refreshSlotAtomically(e, t) {
|
|
2296
|
+
if (!this._doc) return;
|
|
2297
|
+
let n = this._dpr(), r = this._pageWidthPx(e), i = this._scale, a = this._renderEpoch;
|
|
2298
|
+
if (this._mode === "worker") {
|
|
2299
|
+
this._renderSlotBitmap(e, t, r, n, i);
|
|
2300
|
+
return;
|
|
2301
|
+
}
|
|
2302
|
+
let o = document.createElement("canvas");
|
|
2303
|
+
o.style.cssText = "display:block;background:#fff;", this._applyPageShadow(o);
|
|
2304
|
+
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;
|
|
2305
|
+
$(this._doc, o, e, "main", {
|
|
2306
|
+
width: r,
|
|
2307
|
+
dpr: n,
|
|
2308
|
+
defaultTextColor: this._opts.defaultTextColor,
|
|
2309
|
+
currentDate: this._opts.currentDate,
|
|
2310
|
+
...this._showTrackedChanges ? { showTrackedChanges: !0 } : {},
|
|
2311
|
+
onTextRun: f
|
|
2312
|
+
}).then(() => {
|
|
2313
|
+
if (!s.isCurrent(c) || a !== this._renderEpoch || this._slots.get(e) !== t || t.renderedPage !== e) {
|
|
2314
|
+
s.destroy();
|
|
2315
|
+
return;
|
|
2316
|
+
}
|
|
2317
|
+
let n = t.canvas;
|
|
2318
|
+
if (t.dispatcher.destroy(), t.wrapper.insertBefore(o, n), n.remove(), t.canvas = o, t.dispatcher = s, t.renderedScale = i, t.textLayer && (this._clearTextLayerPreview(t.textLayer), u)) {
|
|
2319
|
+
let { width: n, height: r } = this._canvasCssPx(o);
|
|
2320
|
+
Y(t.textLayer, l, n, r, this._hyperlinkHandler(), (e) => this._measureForFont(e), e);
|
|
2321
|
+
}
|
|
2322
|
+
d && this._refreshFindRuns(e, l), this._commitCommentRuns(e, t, l), this._redrawSlotHighlights(e, t);
|
|
2323
|
+
}).catch((n) => {
|
|
2324
|
+
s.isCurrent(c) && a === this._renderEpoch && this._slots.get(e) === t && t.renderedPage === e && this._reportRenderError(n), s.destroy();
|
|
2325
|
+
});
|
|
2326
|
+
}
|
|
2327
|
+
async setShowTrackedChanges(e) {
|
|
2328
|
+
let t = ++this._layoutViewGeneration, n = this._doc;
|
|
2329
|
+
if (this._showTrackedChanges === e) {
|
|
2330
|
+
await n?.setLayoutView?.({
|
|
2331
|
+
showTrackedChanges: e,
|
|
2332
|
+
currentDate: this._opts.currentDate
|
|
2333
|
+
});
|
|
2334
|
+
return;
|
|
2335
|
+
}
|
|
2336
|
+
await n?.setLayoutView?.({
|
|
2337
|
+
showTrackedChanges: e,
|
|
2338
|
+
currentDate: this._opts.currentDate
|
|
2339
|
+
}), !(this._destroyed || t !== this._layoutViewGeneration || n !== this._doc) && (this._showTrackedChanges = e, this._find.invalidate(), this._pendingLayoutPublication = null, this._applyLayoutPublication({
|
|
2340
|
+
pageCount: n?.pageCount ?? 0,
|
|
2341
|
+
exact: !0,
|
|
2342
|
+
complete: n?.layoutComplete !== !1
|
|
2343
|
+
}));
|
|
2344
|
+
}
|
|
2345
|
+
scrollToPage(e, t) {
|
|
2346
|
+
if (!this._doc || this._doc.pageCount === 0 || !this._scaleEstablished) return;
|
|
2347
|
+
let n = Math.max(0, Math.min(e, this._doc.pageCount - 1));
|
|
2348
|
+
this._revealPendingLayoutThroughPage(n);
|
|
2349
|
+
let r = T(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;
|
|
2350
|
+
typeof s.scrollTo == "function" ? s.scrollTo({
|
|
2351
|
+
top: o,
|
|
2352
|
+
behavior: t?.behavior ?? "auto"
|
|
2353
|
+
}) : this._scrollHost.scrollTop = o, this._mountVisible();
|
|
2354
|
+
}
|
|
2355
|
+
_scrollToPageTarget(e, t, n) {
|
|
2356
|
+
this._revealPendingLayoutThroughPage(e);
|
|
2357
|
+
let r = T(this._scrollGeometry, 0, this._scrollHost.clientHeight, this._overscan()), i = this._pageWidthPx(e), { left: a } = this._padH(), o = Math.max(a, (this._scrollHost.clientWidth - i) / 2) + this._reviewOriginPx, s = Math.max(0, r.totalHeight - this._scrollHost.clientHeight), c = this._spacer.offsetWidth || Number.parseFloat(this._spacer.style.width) || 0, l = Math.max(0, c - this._scrollHost.clientWidth), u = Math.min(s, Math.max(0, (r.offsets[e] ?? 0) + t.y + t.h / 2 - this._scrollHost.clientHeight / 2)), d = Math.min(l, Math.max(0, o + t.x + t.w / 2 - this._scrollHost.clientWidth / 2)), f = this._scrollHost;
|
|
2358
|
+
typeof f.scrollTo == "function" ? f.scrollTo({
|
|
2359
|
+
top: u,
|
|
2360
|
+
left: d,
|
|
2361
|
+
behavior: n?.behavior ?? "auto"
|
|
2362
|
+
}) : (this._scrollHost.scrollTop = u, this._scrollHost.scrollLeft = d), this._mountVisible();
|
|
2363
|
+
}
|
|
2364
|
+
_resetCommentNavigation() {
|
|
2365
|
+
this._commentNavigationGeneration++, this._commentPageById.clear(), this._commentRunsByPage.clear(), this._commentIndexedPages.clear(), this._commentScanFrontier = 0;
|
|
2366
|
+
}
|
|
2367
|
+
_advanceCommentScanFrontier() {
|
|
2368
|
+
for (; this._commentIndexedPages.has(this._commentScanFrontier);) this._commentScanFrontier++;
|
|
2369
|
+
}
|
|
2370
|
+
_indexCommentPages(e, t, n) {
|
|
2371
|
+
if (!this._commentIndexedPages.has(e)) {
|
|
2372
|
+
for (let r of n) this._commentPageById.has(r.commentId) || F(r, t).length > 0 && this._commentPageById.set(r.commentId, e);
|
|
2373
|
+
this._commentIndexedPages.add(e), this._advanceCommentScanFrontier();
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
async _commentRunsForPage(e, t) {
|
|
2377
|
+
for (; !this._destroyed && this._doc === t;) {
|
|
2378
|
+
let n = this._scale, r = this._commentRunsByPage.get(e);
|
|
2379
|
+
(!r || r.scale !== n) && (r = {
|
|
2380
|
+
scale: n,
|
|
2381
|
+
runs: t.collectPageRuns(e, {
|
|
2382
|
+
width: this._pageWidthPx(e),
|
|
2383
|
+
currentDate: this._opts.currentDate,
|
|
2384
|
+
...this._showTrackedChanges ? { showTrackedChanges: !0 } : {}
|
|
2385
|
+
})
|
|
2386
|
+
}, this._commentRunsByPage.set(e, r));
|
|
2387
|
+
try {
|
|
2388
|
+
let e = await r.runs;
|
|
2389
|
+
if (this._destroyed || this._doc !== t) return null;
|
|
2390
|
+
if (this._scale !== n) continue;
|
|
2391
|
+
return e;
|
|
2392
|
+
} catch (t) {
|
|
2393
|
+
throw this._commentRunsByPage.get(e) === r && this._commentRunsByPage.delete(e), t;
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
return null;
|
|
2397
|
+
}
|
|
2398
|
+
async goToComment(e, t) {
|
|
2399
|
+
if (this._destroyed) throw Error("DocxScrollViewer is destroyed");
|
|
2400
|
+
let n = this._doc;
|
|
2401
|
+
if (!n || !n.comments.some((t) => t.id === e && t.parentId === void 0)) return !1;
|
|
2402
|
+
let r = ++this._commentNavigationGeneration, i = !n.layoutComplete, a = n.commentAnchorRanges().filter((t) => t.commentId === e), o = t?.pageIndex;
|
|
2403
|
+
if (o !== void 0 && (!Number.isInteger(o) || o < 0)) return !1;
|
|
2404
|
+
let s = o ?? this._commentPageById.get(e), c, l = async () => {
|
|
2405
|
+
let t = n.commentAnchorRanges();
|
|
2406
|
+
for (; s === void 0 && this._commentScanFrontier < n.pageCount;) {
|
|
2407
|
+
let i = this._commentScanFrontier, a = await this._commentRunsForPage(i, n);
|
|
2408
|
+
if (this._destroyed) throw Error("DocxScrollViewer is destroyed");
|
|
2409
|
+
if (this._doc !== n || r !== this._commentNavigationGeneration || !a) return;
|
|
2410
|
+
this._indexCommentPages(i, a, t), s = this._commentPageById.get(e);
|
|
2411
|
+
}
|
|
2412
|
+
return s;
|
|
2413
|
+
};
|
|
2414
|
+
if (o === void 0 && s === void 0 && a.length > 0 && await l(), i && (o !== void 0 && o >= n.pageCount || o === void 0 && s === void 0)) {
|
|
2415
|
+
if (await this._errorRouter.ownBackgroundLifecycle(() => n.waitUntilLayoutComplete()), this._destroyed) throw Error("DocxScrollViewer is destroyed");
|
|
2416
|
+
if (this._doc !== n || r !== this._commentNavigationGeneration) return !1;
|
|
2417
|
+
a = n.commentAnchorRanges().filter((t) => t.commentId === e), this._commentPageById.clear(), this._commentRunsByPage.clear(), this._commentIndexedPages.clear(), this._commentScanFrontier = 0, s = o, o === void 0 && a.length > 0 && await l();
|
|
2418
|
+
}
|
|
2419
|
+
if (a.length === 0 || o !== void 0 && o >= n.pageCount || s === void 0) return !1;
|
|
2420
|
+
let u = await this._commentRunsForPage(s, n);
|
|
2421
|
+
if (this._destroyed) throw Error("DocxScrollViewer is destroyed");
|
|
2422
|
+
if (this._doc !== n || r !== this._commentNavigationGeneration || !u || (c = a.flatMap((e) => F(e, u))[0], !c)) return !1;
|
|
2423
|
+
this._activeCommentId = e, this._activeCommentPage = s, this._elementContext = null, this._scrollToPageTarget(s, c, t);
|
|
2424
|
+
for (let [e, t] of this._slots) this._redrawSlotComments(e, t);
|
|
2425
|
+
return this._emitSelectionContextChange(), !0;
|
|
2426
|
+
}
|
|
2427
|
+
async findText(e, t = {}) {
|
|
2428
|
+
if (!this._doc) return [];
|
|
2429
|
+
let n = ++this._findRequestGeneration;
|
|
2430
|
+
if (this._doc.layoutComplete === !1) {
|
|
2431
|
+
let e = this._doc;
|
|
2432
|
+
if (await this._errorRouter.ownBackgroundLifecycle(() => e.waitUntilLayoutComplete()), this._destroyed || this._doc !== e || n !== this._findRequestGeneration) return [];
|
|
2433
|
+
}
|
|
2434
|
+
this._findActive = e.length > 0;
|
|
2435
|
+
let r = await this._errorRouter.ownAwaitable(() => this._find.find(e, t));
|
|
2436
|
+
return this._redrawHighlights(), r;
|
|
2437
|
+
}
|
|
2438
|
+
async findNext() {
|
|
2439
|
+
return this._activateMatch(this._find.next());
|
|
2440
|
+
}
|
|
2441
|
+
async findPrev() {
|
|
2442
|
+
return this._activateMatch(this._find.prev());
|
|
2443
|
+
}
|
|
2444
|
+
clearFind() {
|
|
2445
|
+
this._findRequestGeneration++, this._findActive = !1, this._find.invalidate(), this._redrawHighlights();
|
|
2446
|
+
}
|
|
2447
|
+
async _activateMatch(e) {
|
|
2448
|
+
return e && this.scrollToPage(e.location.page), this._redrawHighlights(), e;
|
|
2449
|
+
}
|
|
2450
|
+
async _collectPageRuns(e) {
|
|
2451
|
+
return this._doc ? this._doc.collectPageRuns(e, {
|
|
2452
|
+
width: this._pageWidthPx(e),
|
|
2453
|
+
currentDate: this._opts.currentDate,
|
|
2454
|
+
...this._showTrackedChanges ? { showTrackedChanges: !0 } : {}
|
|
2455
|
+
}) : [];
|
|
2456
|
+
}
|
|
2457
|
+
_redrawHighlights() {
|
|
2458
|
+
for (let [e, t] of this._slots) this._redrawSlotHighlights(e, t);
|
|
2459
|
+
}
|
|
2460
|
+
_refreshFindRuns(e, t) {
|
|
2461
|
+
this._findActive && this._find.setPageRuns(e, t);
|
|
2462
|
+
}
|
|
2463
|
+
_commitCommentRuns(e, t, n) {
|
|
2464
|
+
t.commentTintLayer && (t.commentRuns = Object.freeze([...n]), this._commentRunsByPage.set(e, {
|
|
2465
|
+
scale: this._scale,
|
|
2466
|
+
runs: Promise.resolve(t.commentRuns)
|
|
2467
|
+
}), 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 = ""));
|
|
2468
|
+
}
|
|
2469
|
+
_redrawSlotComments(e, t) {
|
|
2470
|
+
if (!this._doc || !t.commentTintLayer) return;
|
|
2471
|
+
let n = this._commentUi;
|
|
2472
|
+
if (!n) {
|
|
2473
|
+
t.commentTintLayer.replaceChildren(), t.commentMargin?.replaceChildren(), t.commentDecorationLayer?.replaceChildren(), t.commentGeometry = null;
|
|
2474
|
+
return;
|
|
2475
|
+
}
|
|
2476
|
+
t.commentGeometry = n.buildDocxCommentMargin(t.commentTintLayer, t.commentMargin, t.commentRuns, {
|
|
2477
|
+
comments: this._doc.comments,
|
|
2478
|
+
anchors: this._doc.commentAnchorRanges()
|
|
2479
|
+
}, this._pageWidthPx(e), this._pageHeightPx(e), this._activeCommentId, (t, n) => {
|
|
2480
|
+
let r = n ? t : this._activeCommentId === t ? null : this._activeCommentId;
|
|
2481
|
+
if (r !== this._activeCommentId) {
|
|
2482
|
+
this._activeCommentId = r, this._activeCommentPage = r ? e : null, this._elementContext = null;
|
|
2483
|
+
for (let [e, t] of this._slots) this._redrawSlotComments(e, t);
|
|
2484
|
+
this._emitSelectionContextChange();
|
|
2485
|
+
}
|
|
2486
|
+
}, 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);
|
|
2487
|
+
}
|
|
2488
|
+
_redrawSlotCommentConnectors(e, t) {
|
|
2489
|
+
let n = t.commentDecorationLayer, r = t.commentMargin, i = t.commentGeometry, a = this._commentsOptions()?.connectors;
|
|
2490
|
+
if (!n || !r || !i || !a) return;
|
|
2491
|
+
let o = this._pageWidthPx(e), s = this._pageHeightPx(e), c = this._commentSide(), l = this._commentMarginExtent(), u = this._commentUi;
|
|
2492
|
+
u && u.buildReadOnlyCommentDecoration(n, Object.freeze({
|
|
2493
|
+
surfaceBounds: Object.freeze({
|
|
2494
|
+
x: c === "left" ? -l : 0,
|
|
2495
|
+
y: 0,
|
|
2496
|
+
width: o + l,
|
|
2497
|
+
height: s
|
|
2498
|
+
}),
|
|
2499
|
+
contentBounds: Object.freeze({
|
|
2500
|
+
x: 0,
|
|
2501
|
+
y: 0,
|
|
2502
|
+
width: o,
|
|
2503
|
+
height: s
|
|
2504
|
+
}),
|
|
2505
|
+
side: c,
|
|
2506
|
+
threads: u.projectReadOnlyCommentMarginScroll(i, r.scrollTop)
|
|
2507
|
+
}), {
|
|
2508
|
+
route: a.route ?? "bezier",
|
|
2509
|
+
stroke: a.stroke ?? "solid",
|
|
2510
|
+
color: a.color,
|
|
2511
|
+
activeColor: a.activeColor
|
|
2512
|
+
});
|
|
2513
|
+
}
|
|
2514
|
+
_scheduleCommentGeometry(e, t, n = !1) {
|
|
2515
|
+
let r = this._pendingCommentGeometry.get(e);
|
|
2516
|
+
if (this._pendingCommentGeometry.set(e, {
|
|
2517
|
+
slot: t,
|
|
2518
|
+
connectorsOnly: r?.slot === t ? r.connectorsOnly && n : n
|
|
2519
|
+
}), this._commentGeometryScheduled) return;
|
|
2520
|
+
this._commentGeometryScheduled = !0;
|
|
2521
|
+
let i = () => {
|
|
2522
|
+
this._commentGeometryScheduled = !1, this._commentGeometryFrame = null;
|
|
2523
|
+
let e = [...this._pendingCommentGeometry];
|
|
2524
|
+
if (this._pendingCommentGeometry.clear(), !this._destroyed) for (let [t, n] of e) {
|
|
2525
|
+
let { slot: e, connectorsOnly: r } = n;
|
|
2526
|
+
this._slots.get(t) === e && e.renderedScale === this._scale && (r ? this._redrawSlotCommentConnectors(t, e) : this._redrawSlotComments(t, e));
|
|
2527
|
+
}
|
|
2528
|
+
}, a = this._wrapper.ownerDocument.defaultView;
|
|
2529
|
+
a?.requestAnimationFrame ? this._commentGeometryFrame = a.requestAnimationFrame(i) : queueMicrotask(i);
|
|
2530
|
+
}
|
|
2531
|
+
_redrawSlotHighlights(e, t) {
|
|
2532
|
+
if (!this._findActive) {
|
|
2533
|
+
t.highlightLayer.innerHTML = "";
|
|
2534
|
+
return;
|
|
2535
|
+
}
|
|
2536
|
+
let n = this._find.pageRuns(e);
|
|
2537
|
+
if (!n) {
|
|
2538
|
+
t.highlightLayer.innerHTML = "";
|
|
2539
|
+
return;
|
|
2540
|
+
}
|
|
2541
|
+
X(t.highlightLayer, n, this._find.pageHighlights(e), this._pageWidthPx(e), this._pageHeightPx(e), (e) => this._measureForFont(e), this._opts.findHighlightColors);
|
|
2542
|
+
}
|
|
2543
|
+
_onResize() {
|
|
2544
|
+
if (!this._doc || this._doc.pageCount === 0) return;
|
|
2545
|
+
if (!this._scaleEstablished) {
|
|
2546
|
+
this.relayout();
|
|
2547
|
+
return;
|
|
2548
|
+
}
|
|
2549
|
+
if (this._opts.refitOnResize === !1) {
|
|
2550
|
+
this._lastFitWidth = this._fitWidthPx(), this._mountVisible();
|
|
2551
|
+
return;
|
|
2552
|
+
}
|
|
2553
|
+
let e = this._baseScale();
|
|
2554
|
+
if (e <= 0) return;
|
|
2555
|
+
let t = this._fitWidthPx();
|
|
2556
|
+
if (t === this._lastFitWidth) {
|
|
2557
|
+
this._mountVisible();
|
|
2558
|
+
return;
|
|
2559
|
+
}
|
|
2560
|
+
this._lastFitWidth = t;
|
|
2561
|
+
let n = this._prevBase > 0 ? this._scale / this._prevBase : 1;
|
|
2562
|
+
this._prevBase = e, this.setScale(e * n), this._mountVisible();
|
|
2563
|
+
}
|
|
2564
|
+
get topVisiblePage() {
|
|
2565
|
+
return this._lastRange?.topIndex ?? 0;
|
|
2566
|
+
}
|
|
2567
|
+
mountedPageIndicesForTest() {
|
|
2568
|
+
return [...this._slots.keys()];
|
|
2569
|
+
}
|
|
2570
|
+
scaleForTest() {
|
|
2571
|
+
return this._scale;
|
|
2572
|
+
}
|
|
2573
|
+
baseScaleForTest() {
|
|
2574
|
+
return this._baseScale();
|
|
2575
|
+
}
|
|
2576
|
+
renderEpochForTest() {
|
|
2577
|
+
return this._renderEpoch;
|
|
2578
|
+
}
|
|
2579
|
+
resizeForTest() {
|
|
2580
|
+
this._onResize();
|
|
2581
|
+
}
|
|
2582
|
+
contentAtViewportYForTest(e) {
|
|
2583
|
+
let t = this._range(), n = this._scrollHost.scrollTop + e, r = this._pageIndexAtOffset(t, n), i = this._heights[r] || 0;
|
|
2584
|
+
return {
|
|
2585
|
+
page: r,
|
|
2586
|
+
frac: i > 0 ? Math.min(1, Math.max(0, (n - t.offsets[r]) / i)) : 0
|
|
2587
|
+
};
|
|
2588
|
+
}
|
|
2589
|
+
viewportYOfForTest(e, t) {
|
|
2590
|
+
return (this._range().offsets[e] ?? 0) + t * (this._heights[e] || 0) - this._scrollHost.scrollTop;
|
|
2591
|
+
}
|
|
2592
|
+
async getResourceMetrics() {
|
|
2593
|
+
if (!this._doc) throw Error("Document not loaded");
|
|
2594
|
+
return await this._doc.getResourceMetrics();
|
|
2595
|
+
}
|
|
2596
|
+
getSelectionContext(e = {}) {
|
|
2597
|
+
if (this._destroyed) throw Error("DocxScrollViewer is destroyed");
|
|
2598
|
+
return (this._doc && this._activeCommentId !== null && this._activeCommentPage !== null ? It(this._doc.comments, this._doc.commentAnchorRanges(), this._activeCommentId, this._activeCommentPage, e) : null) || ((this._opts.enableTextSelection ? Q(this._wrapper, this._wrapper.ownerDocument?.getSelection?.() ?? null, e) : null) ?? (this._elementContext ? bt(this._elementContext, e.maxTextCharacters) : null));
|
|
2599
|
+
}
|
|
2600
|
+
_emitSelectionContextChange() {
|
|
2601
|
+
let e = this.getSelectionContext();
|
|
2602
|
+
e?.kind === "text" && (this._elementHitGeneration++, this._elementContext = null, this._redrawElementOutlines());
|
|
2603
|
+
let t = JSON.stringify(e);
|
|
2604
|
+
t !== this._selectionContextKey && (this._selectionContextKey = t, this._opts.onSelectionContextChange?.(e ? structuredClone(e) : null));
|
|
2605
|
+
}
|
|
2606
|
+
_setElementContext(e) {
|
|
2607
|
+
this._elementContext = e ? structuredClone(e) : null, this._redrawElementOutlines(), this._emitSelectionContextChange();
|
|
2608
|
+
}
|
|
2609
|
+
_invalidateElementContext(e = !0) {
|
|
2610
|
+
this._elementHitGeneration++, this._elementContext = null, this._redrawElementOutlines(), e && this._emitSelectionContextChange();
|
|
2611
|
+
}
|
|
2612
|
+
_redrawElementOutlines() {
|
|
2613
|
+
for (let [e, t] of this._slots) this._redrawElementOutlineForSlot(e, t);
|
|
2614
|
+
}
|
|
2615
|
+
_redrawElementOutlineForSlot(e, t) {
|
|
2616
|
+
let n = this._elementContext, r = this._doc;
|
|
2617
|
+
if (!n || !r || n.pageIndex !== e) {
|
|
2618
|
+
v(t.elementLayer, null);
|
|
2619
|
+
return;
|
|
2620
|
+
}
|
|
2621
|
+
let i = r.pageSize(e);
|
|
2622
|
+
v(t.elementLayer, {
|
|
2623
|
+
x: n.bounds.xPt / i.widthPt,
|
|
2624
|
+
y: n.bounds.yPt / i.heightPt,
|
|
2625
|
+
width: n.bounds.widthPt / i.widthPt,
|
|
2626
|
+
height: n.bounds.heightPt / i.heightPt
|
|
2627
|
+
});
|
|
2628
|
+
}
|
|
2629
|
+
async _onElementClick(e) {
|
|
2630
|
+
this._destroyed || e.defaultPrevented || e.button !== 0 || await this._resolveContextAt(e);
|
|
2631
|
+
}
|
|
2632
|
+
_onContextMenu(e) {
|
|
2633
|
+
let t;
|
|
2634
|
+
this._opts.onContextMenu?.({
|
|
2635
|
+
originalEvent: e,
|
|
2636
|
+
getContext: () => t ??= this._resolveContextAt(e)
|
|
2637
|
+
});
|
|
2638
|
+
}
|
|
2639
|
+
async _resolveContextAt(e) {
|
|
2640
|
+
let t = this._doc;
|
|
2641
|
+
if (this._destroyed || !t) return null;
|
|
2642
|
+
if (this._opts.enableTextSelection && Q(this._wrapper, this._wrapper.ownerDocument?.getSelection?.() ?? null)) return this._emitSelectionContextChange(), this._destroyed ? null : this.getSelectionContext();
|
|
2643
|
+
if (!this._opts.enableElementSelection) return this.getSelectionContext();
|
|
2644
|
+
let n = e.target, r = [...this._slots].find(([, e]) => n !== null && e.wrapper.contains(n));
|
|
2645
|
+
if (!r) return this._invalidateElementContext(), null;
|
|
2646
|
+
let [i, a] = r, o = a.canvas.getBoundingClientRect();
|
|
2647
|
+
if (o.width <= 0 || o.height <= 0) return this._invalidateElementContext(), null;
|
|
2648
|
+
let s = e.clientX - o.left, c = e.clientY - o.top;
|
|
2649
|
+
if (s < 0 || c < 0 || s > o.width || c > o.height) return this._invalidateElementContext(), null;
|
|
2650
|
+
let l = ++this._elementHitGeneration, u = t.pageSize(i), d;
|
|
2651
|
+
try {
|
|
2652
|
+
d = await t.getElementContextAt(i, {
|
|
2653
|
+
xPt: s / o.width * u.widthPt,
|
|
2654
|
+
yPt: c / o.height * u.heightPt
|
|
2655
|
+
}, {
|
|
2656
|
+
currentDate: this._opts.currentDate,
|
|
2657
|
+
...this._showTrackedChanges ? { showTrackedChanges: !0 } : {},
|
|
2658
|
+
maxTextCharacters: I
|
|
2659
|
+
});
|
|
2660
|
+
} catch (e) {
|
|
2661
|
+
if (this._destroyed || l !== this._elementHitGeneration || t !== this._doc) return null;
|
|
2662
|
+
throw e;
|
|
2663
|
+
}
|
|
2664
|
+
return this._destroyed || l !== this._elementHitGeneration || t !== this._doc ? null : (this._setElementContext(d), this._destroyed ? null : this.getSelectionContext());
|
|
2665
|
+
}
|
|
2666
|
+
destroy() {
|
|
2667
|
+
if (!this._destroyed) {
|
|
2668
|
+
this._destroyed = !0, this._findRequestGeneration++, this._errorRouter.close(), this._unbindLayoutDocument(), this._layoutViewGeneration++, 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);
|
|
2669
|
+
for (let [e, t] of [...this._slots]) this._recycleSlot(e, t);
|
|
2670
|
+
this._free.length = 0, this._documentOwner.close(), this._wrapper.remove();
|
|
2671
|
+
}
|
|
2672
|
+
}
|
|
2673
|
+
};
|
|
2674
|
+
//#endregion
|
|
2675
|
+
//#region packages/docx/src/types.ts
|
|
2676
|
+
function Zt(e) {
|
|
2677
|
+
let t = [];
|
|
2678
|
+
for (let n of e.content) {
|
|
2679
|
+
if (n.type !== "paragraph") continue;
|
|
2680
|
+
let e = "";
|
|
2681
|
+
for (let t of n.runs) t.type === "text" && !t.noteRef && (e += t.text);
|
|
2682
|
+
e = e.trim(), e && t.push(e);
|
|
2683
|
+
}
|
|
2684
|
+
return t.join(" ");
|
|
2685
|
+
}
|
|
2686
|
+
//#endregion
|
|
2687
|
+
//#region src/docx.ts
|
|
2688
|
+
var Qt = /* @__PURE__ */ e({
|
|
2689
|
+
DocxDocument: () => q,
|
|
2690
|
+
DocxScrollViewer: () => Xt,
|
|
2691
|
+
DocxViewer: () => Ht,
|
|
2692
|
+
OoxmlDecodedImageLimitError: () => Ge,
|
|
2693
|
+
OoxmlError: () => o,
|
|
2694
|
+
OoxmlResourceLimitError: () => n,
|
|
2695
|
+
autoResize: () => de,
|
|
2696
|
+
buildDocxHighlightLayer: () => X,
|
|
2697
|
+
buildDocxTextLayer: () => Y,
|
|
2698
|
+
isOoxmlDecodedImageLimitError: () => Ke,
|
|
2699
|
+
noteText: () => Zt,
|
|
2700
|
+
openExternalHyperlink: () => s,
|
|
2701
|
+
readDocxTextSelectionContext: () => Q,
|
|
2702
|
+
resolveCommentAnchorRuns: () => F,
|
|
2703
|
+
resolveDocxCommentThreads: () => Xe,
|
|
2704
|
+
resolveRevisionAnchorRuns: () => Et
|
|
2705
|
+
});
|
|
2706
|
+
//#endregion
|
|
2707
|
+
export { Q as a, q as c, Ht as i, Et as l, Zt as n, X as o, Xt as r, Y as s, Qt as t };
|