@betteroffice/docx 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README.md +20 -7
  2. package/dist/chunk-4V6MDZIK.mjs +1 -0
  3. package/dist/chunk-6KDV6AIL.mjs +1 -0
  4. package/dist/chunk-CTBUQRYQ.mjs +1 -0
  5. package/dist/{chunk-IFT6DUJX.mjs → chunk-LTVVQMHB.mjs} +1 -1
  6. package/dist/chunk-NBSLB77E.mjs +1 -0
  7. package/dist/chunk-NTSSE5QK.mjs +57 -0
  8. package/dist/chunk-YTILOUAA.mjs +16 -0
  9. package/dist/collaboration/index.d.mts +32 -8
  10. package/dist/collaboration/index.mjs +1 -1
  11. package/dist/{content-MOZ6hKP4.d.mts → content-C3sTRz-u.d.mts} +517 -650
  12. package/dist/core.d.mts +6 -6
  13. package/dist/core.mjs +1 -1
  14. package/dist/{displayListQueries-BJlo7Jkz.d.mts → displayListQueries-DLzpvJV6.d.mts} +14 -3
  15. package/dist/docx/index.d.mts +3 -3
  16. package/dist/docx/index.mjs +1 -1
  17. package/dist/editor/index.d.mts +7 -7
  18. package/dist/{fontLoader-aSewHMKF.d.mts → fontLoader-CMH3bZ2Z.d.mts} +127 -2
  19. package/dist/{formatting-D1EPSaJP.d.mts → formatting-BEkIBePP.d.mts} +77 -203
  20. package/dist/{frameDelta-D965X8yK.d.mts → frameDelta-B2kC6XiP.d.mts} +4 -2
  21. package/dist/generated/edit/docx_edit_bg.wasm +0 -0
  22. package/dist/generated/layout/docx_layout_bg.wasm +0 -0
  23. package/dist/generated/parse/docx_parse_bg.wasm +0 -0
  24. package/dist/{index-Dx4Z3lkz.d.mts → index-2piKi4gO.d.mts} +66 -3
  25. package/dist/layout/index.d.mts +8 -7
  26. package/dist/layout/index.mjs +1 -1
  27. package/dist/layout/pagination/index.d.mts +4 -4
  28. package/dist/layout/pagination/index.mjs +1 -1
  29. package/dist/layout/render/index.d.mts +10 -10
  30. package/dist/layout/render/index.mjs +1 -1
  31. package/dist/plugin-api/RenderedDomContext.d.mts +7 -7
  32. package/dist/plugin-api/index.d.mts +3 -3
  33. package/dist/plugin-api/resolveItemPositions.d.mts +3 -3
  34. package/dist/{rustDisplayList-BRuZBqdL.d.mts → rustDisplayList-B0M2eBkU.d.mts} +7 -2
  35. package/dist/styles/index.d.mts +2 -2
  36. package/dist/{styles-Dn_o3Vo5.d.mts → styles-BK3Jecxs.d.mts} +1 -1
  37. package/dist/types/content.d.mts +2 -2
  38. package/dist/types/document.d.mts +6 -6
  39. package/dist/{types-BfqUl2h_.d.mts → types-C1rv3KM-.d.mts} +2 -2
  40. package/dist/utils/comments.d.mts +2 -2
  41. package/dist/utils/index.d.mts +4 -4
  42. package/dist/utils/index.mjs +1 -1
  43. package/dist/utils/stylePreview.d.mts +2 -2
  44. package/dist/utils/units.d.mts +4 -34
  45. package/dist/utils/units.mjs +1 -1
  46. package/dist/wasm-F2ETFAYL.mjs +1 -0
  47. package/dist/wasm-JE7B3ROD.mjs +1 -0
  48. package/dist/wasm-edit.d.mts +24 -0
  49. package/dist/wasm-edit.mjs +1 -1
  50. package/dist/wasm-layout.d.mts +5 -1
  51. package/dist/wasm-layout.mjs +1 -1
  52. package/dist/yrs/index.d.mts +6 -6
  53. package/dist/yrs/index.mjs +1 -1
  54. package/dist/yrs/residentEngineWorker.mjs +1 -1
  55. package/package.json +1 -2
  56. package/dist/chunk-3UBMCDME.mjs +0 -1
  57. package/dist/chunk-AEQOEQJ7.mjs +0 -57
  58. package/dist/chunk-AZ52IWB6.mjs +0 -16
  59. package/dist/chunk-WON6K4FY.mjs +0 -1
  60. package/dist/chunk-Y7RUNRU2.mjs +0 -1
  61. package/dist/wasm-DO3BUV7C.mjs +0 -1
  62. package/dist/wasm-NWXX4H5G.mjs +0 -1
package/README.md CHANGED
@@ -6,7 +6,10 @@ WebAssembly, plus the display-list, canvas-render, geometry, and accessibility
6
6
  helpers the adapters build on. Layout never touches the DOM: the engine
7
7
  measures every line and pages are replayed onto canvas.
8
8
 
9
- > **Experimental (`0.0.x`).** The API is unstable and may change in any release.
9
+ > **Early (`0.0.x`).** The core surfaces — opening/saving documents, the editor
10
+ > components, collaboration — are settling and unlikely to change shape. Smaller
11
+ > APIs may still move between releases; breaking changes are always listed in
12
+ > the changelog.
10
13
 
11
14
  ```bash
12
15
  bun add @betteroffice/docx
@@ -17,16 +20,24 @@ Most apps want the turnkey React component in
17
20
  Reach for this package directly for headless parsing/serialization or when
18
21
  building a custom adapter.
19
22
 
20
- ## Usage
23
+ ## Parse and save
24
+
25
+ A full round trip: open a `.docx`, inspect the typed model, write bytes back.
21
26
 
22
27
  ```ts
23
- import { readFile } from 'node:fs/promises';
24
- import { parseDocx } from '@betteroffice/docx/docx';
28
+ import { readFile, writeFile } from 'node:fs/promises';
29
+ import { parseDocx, repackDocx } from '@betteroffice/docx/docx';
30
+
31
+ const document = await parseDocx(await readFile('contract.docx'));
32
+ // document.package: body, styles, numbering, theme, media, headers/footers
25
33
 
26
- const buffer = await readFile('contract.docx');
27
- const document = await parseDocx(buffer);
34
+ const bytes = await repackDocx(document);
35
+ await writeFile('contract-out.docx', Buffer.from(bytes));
28
36
  ```
29
37
 
38
+ `repackDocx` round-trips against the original buffer so untouched parts are
39
+ preserved; use `createDocx` for documents built from scratch.
40
+
30
41
  The engine ships as four wasm assets (container, parser, layout, editing core)
31
42
  in `dist/generated/`. Browsers fetch them lazily behind the async entry points
32
43
  (`parseDocx`, save, the layout engine, `createYrsSession`); Node and Bun read
@@ -39,7 +50,9 @@ Connect the editor's Yrs replica to any reliable binary transport:
39
50
  ```ts
40
51
  import { CollaborationProvider } from '@betteroffice/docx/collaboration';
41
52
 
42
- const provider = new CollaborationProvider(replica, createTransport());
53
+ const provider = new CollaborationProvider(replica, createTransport(), {
54
+ user: { name: "Ada" }, // identity for this peer's remote caret
55
+ });
43
56
  provider.connect();
44
57
  ```
45
58
 
@@ -0,0 +1 @@
1
+ import {a}from'./chunk-T4EZMUXM.mjs';var M=class{__destroy_into_raw(){let _=this.__wbg_ptr;return this.__wbg_ptr=0,B.unregister(this),_}free(){let _=this.__destroy_into_raw();e.__wbg_editsession_free(_,0);}accept_change(_){let t,o;try{let i=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),l=c,s=e.editsession_accept_change(this.__wbg_ptr,i,l);var n=s[0],r=s[1];if(s[3])throw n=0,r=0,w(s[2]);return t=n,o=r,p(n,r)}finally{e.__wbindgen_free(t,o,1);}}add_comment(_,t,o,n){let r,i;try{let a=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),f=c,g=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),u=c,m=d(o,e.__wbindgen_malloc,e.__wbindgen_realloc),y=c,h=d(n,e.__wbindgen_malloc,e.__wbindgen_realloc),x=c,v=e.editsession_add_comment(this.__wbg_ptr,a,f,g,u,m,y,h,x);var l=v[0],s=v[1];if(v[3])throw l=0,s=0,w(v[2]);return r=l,i=s,p(l,s)}finally{e.__wbindgen_free(r,i,1);}}apply_delete(_,t){let o=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),n=c,r=e.editsession_apply_delete(this.__wbg_ptr,o,n,t);if(r[3])throw w(r[2]);var i=R(r[0],r[1]).slice();return e.__wbindgen_free(r[0],r[1]*1,1),i}apply_delete_profiled(_,t){let o=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),n=c,r=e.editsession_apply_delete_profiled(this.__wbg_ptr,o,n,t);if(r[3])throw w(r[2]);var i=R(r[0],r[1]).slice();return e.__wbindgen_free(r[0],r[1]*1,1),i}apply_input(_,t){let o=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),n=c,r=e.editsession_apply_input(this.__wbg_ptr,o,n,t);if(r[3])throw w(r[2]);var i=R(r[0],r[1]).slice();return e.__wbindgen_free(r[0],r[1]*1,1),i}apply_input_profile_json(){let _,t;try{let o=e.editsession_apply_input_profile_json(this.__wbg_ptr);return _=o[0],t=o[1],p(o[0],o[1])}finally{e.__wbindgen_free(_,t,1);}}apply_input_profiled(_,t){let o=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),n=c,r=e.editsession_apply_input_profiled(this.__wbg_ptr,o,n,t);if(r[3])throw w(r[2]);var i=R(r[0],r[1]).slice();return e.__wbindgen_free(r[0],r[1]*1,1),i}apply_local_update(_){let t=S(_,e.__wbindgen_malloc),o=c,n=e.editsession_apply_local_update(this.__wbg_ptr,t,o);if(n[1])throw w(n[0])}apply_paragraph_style(_,t,o,n,r,i,l,s){let a=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),f=c,g=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),u=c,m=d(n,e.__wbindgen_malloc,e.__wbindgen_realloc),y=c,h=d(i,e.__wbindgen_malloc,e.__wbindgen_realloc),x=c;var v=j(l)?0:d(l,e.__wbindgen_malloc,e.__wbindgen_realloc),A=c,W=j(s)?0:d(s,e.__wbindgen_malloc,e.__wbindgen_realloc),E=c;let k=e.editsession_apply_paragraph_style(this.__wbg_ptr,a,f,g,u,o,m,y,r,h,x,v,A,W,E);if(k[1])throw w(k[0])}apply_raw_ops(_,t){let o=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),n=c,r=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),i=c,l=e.editsession_apply_raw_ops(this.__wbg_ptr,o,n,r,i);if(l[1])throw w(l[0])}apply_update(_){let t=S(_,e.__wbindgen_malloc),o=c,n=e.editsession_apply_update(this.__wbg_ptr,t,o);if(n[1])throw w(n[0])}apply_update_with_inference(_){let t,o;try{let i=S(_,e.__wbindgen_malloc),l=c,s=e.editsession_apply_update_with_inference(this.__wbg_ptr,i,l);var n=s[0],r=s[1];if(s[3])throw n=0,r=0,w(s[2]);return t=n,o=r,p(n,r)}finally{e.__wbindgen_free(t,o,1);}}build_display_list_frame(_,t){let o=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),n=c,r=e.editsession_build_display_list_frame(this.__wbg_ptr,o,n,t);if(r[3])throw w(r[2]);var i=R(r[0],r[1]).slice();return e.__wbindgen_free(r[0],r[1]*1,1),i}build_display_list_json(_){let t,o;try{let i=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),l=c,s=e.editsession_build_display_list_json(this.__wbg_ptr,i,l);var n=s[0],r=s[1];if(s[3])throw n=0,r=0,w(s[2]);return t=n,o=r,p(n,r)}finally{e.__wbindgen_free(t,o,1);}}can_redo(){return e.editsession_can_redo(this.__wbg_ptr)!==0}can_undo(){return e.editsession_can_undo(this.__wbg_ptr)!==0}cell_selection(){let _,t;try{let r=e.editsession_cell_selection(this.__wbg_ptr);var o=r[0],n=r[1];if(r[3])throw o=0,n=0,w(r[2]);return _=o,t=n,p(o,n)}finally{e.__wbindgen_free(_,t,1);}}clear_content_control_value(_){let t=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),o=c,n=e.editsession_clear_content_control_value(this.__wbg_ptr,t,o);if(n[1])throw w(n[0])}clear_formatting(_,t,o,n,r){let i=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),l=c,s=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),a=c,f=d(n,e.__wbindgen_malloc,e.__wbindgen_realloc),g=c,u=e.editsession_clear_formatting(this.__wbg_ptr,i,l,s,a,o,f,g,r);if(u[1])throw w(u[0])}clear_measure_fonts(){e.editsession_clear_measure_fonts(this.__wbg_ptr);}clear_update_event_observation(){e.editsession_clear_update_event_observation(this.__wbg_ptr);}clear_update_observer(){e.editsession_clear_update_observer(this.__wbg_ptr);}client_id(){return e.editsession_client_id(this.__wbg_ptr)}create_story(_,t,o,n){let r,i;try{let a=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),f=c,g=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),u=c,m=d(o,e.__wbindgen_malloc,e.__wbindgen_realloc),y=c,h=d(n,e.__wbindgen_malloc,e.__wbindgen_realloc),x=c,v=e.editsession_create_story(this.__wbg_ptr,a,f,g,u,m,y,h,x);var l=v[0],s=v[1];if(v[3])throw l=0,s=0,w(v[2]);return r=l,i=s,p(l,s)}finally{e.__wbindgen_free(r,i,1);}}delete_column(_){let t,o;try{let i=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),l=c,s=e.editsession_delete_column(this.__wbg_ptr,i,l);var n=s[0],r=s[1];if(s[3])throw n=0,r=0,w(s[2]);return t=n,o=r,p(n,r)}finally{e.__wbindgen_free(t,o,1);}}delete_range(_,t,o,n,r,i,l){let s,a;try{let x=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),v=c,A=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),W=c,E=d(n,e.__wbindgen_malloc,e.__wbindgen_realloc),k=c;var f=j(i)?0:d(i,e.__wbindgen_malloc,e.__wbindgen_realloc),g=c,u=j(l)?0:d(l,e.__wbindgen_malloc,e.__wbindgen_realloc),m=c;let T=e.editsession_delete_range(this.__wbg_ptr,x,v,A,W,o,E,k,r,f,g,u,m);var y=T[0],h=T[1];if(T[3])throw y=0,h=0,w(T[2]);return s=y,a=h,p(y,h)}finally{e.__wbindgen_free(s,a,1);}}delete_row(_,t,o){let n,r;try{let u=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),m=c;var i=j(t)?0:d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),l=c,s=j(o)?0:d(o,e.__wbindgen_malloc,e.__wbindgen_realloc),a=c;let y=e.editsession_delete_row(this.__wbg_ptr,u,m,i,l,s,a);var f=y[0],g=y[1];if(y[3])throw f=0,g=0,w(y[2]);return n=f,r=g,p(f,g)}finally{e.__wbindgen_free(n,r,1);}}delete_story(_){let t=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),o=c,n=e.editsession_delete_story(this.__wbg_ptr,t,o);if(n[1])throw w(n[0])}delete_table(_){let t,o;try{let i=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),l=c,s=e.editsession_delete_table(this.__wbg_ptr,i,l);var n=s[0],r=s[1];if(s[3])throw n=0,r=0,w(s[2]);return t=n,o=r,p(n,r)}finally{e.__wbindgen_free(t,o,1);}}display_hit_test_regions_json(_,t,o){let n,r;try{let s=e.editsession_display_hit_test_regions_json(this.__wbg_ptr,_,t,o);var i=s[0],l=s[1];if(s[3])throw i=0,l=0,w(s[2]);return n=i,r=l,p(i,l)}finally{e.__wbindgen_free(n,r,1);}}display_range_rects_json(_,t){let o,n;try{let l=e.editsession_display_range_rects_json(this.__wbg_ptr,_,t);var r=l[0],i=l[1];if(l[3])throw r=0,i=0,w(l[2]);return o=r,n=i,p(r,i)}finally{e.__wbindgen_free(o,n,1);}}display_range_rects_region_json(_,t,o,n){let r,i;try{let a=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),f=c,g=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),u=c,m=e.editsession_display_range_rects_region_json(this.__wbg_ptr,a,f,g,u,o,n);var l=m[0],s=m[1];if(m[3])throw l=0,s=0,w(m[2]);return r=l,i=s,p(l,s)}finally{e.__wbindgen_free(r,i,1);}}display_vertical_move_json(_,t,o){let n,r;try{let s=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),a=c,f=e.editsession_display_vertical_move_json(this.__wbg_ptr,_,s,a,o);var i=f[0],l=f[1];if(f[3])throw i=0,l=0,w(f[2]);return n=i,r=l,p(i,l)}finally{e.__wbindgen_free(n,r,1);}}drain_update_event(){let _=e.editsession_drain_update_event(this.__wbg_ptr);var t=R(_[0],_[1]).slice();return e.__wbindgen_free(_[0],_[1]*1,1),t}encode_diff(_){let t=S(_,e.__wbindgen_malloc),o=c,n=e.editsession_encode_diff(this.__wbg_ptr,t,o);if(n[3])throw w(n[2]);var r=R(n[0],n[1]).slice();return e.__wbindgen_free(n[0],n[1]*1,1),r}encode_state(){let _=e.editsession_encode_state(this.__wbg_ptr);var t=R(_[0],_[1]).slice();return e.__wbindgen_free(_[0],_[1]*1,1),t}encode_state_vector(){let _=e.editsession_encode_state_vector(this.__wbg_ptr);var t=R(_[0],_[1]).slice();return e.__wbindgen_free(_[0],_[1]*1,1),t}encode_sticky_position(_,t,o){let n=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),r=c,i=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),l=c,s=e.editsession_encode_sticky_position(this.__wbg_ptr,n,r,i,l,o);if(s[3])throw w(s[2]);var a=R(s[0],s[1]).slice();return e.__wbindgen_free(s[0],s[1]*1,1),a}encoded_selection(){let _,t;try{let r=e.editsession_encoded_selection(this.__wbg_ptr);var o=r[0],n=r[1];if(r[3])throw o=0,n=0,w(r[2]);return _=o,t=n,p(o,n)}finally{e.__wbindgen_free(_,t,1);}}format_range(_,t,o,n,r,i){let l=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),s=c,a=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),f=c,g=d(n,e.__wbindgen_malloc,e.__wbindgen_realloc),u=c,m=d(i,e.__wbindgen_malloc,e.__wbindgen_realloc),y=c,h=e.editsession_format_range(this.__wbg_ptr,l,s,a,f,o,g,u,r,m,y);if(h[1])throw w(h[0])}insert_column(_,t){let o,n;try{let l=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),s=c,a=e.editsession_insert_column(this.__wbg_ptr,l,s,t);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,w(a[2]);return o=r,n=i,p(r,i)}finally{e.__wbindgen_free(o,n,1);}}insert_image(_,t,o,n,r,i){let l,s;try{let h=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),x=c,v=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),A=c,W=d(n,e.__wbindgen_malloc,e.__wbindgen_realloc),E=c;var a=j(r)?0:d(r,e.__wbindgen_malloc,e.__wbindgen_realloc),f=c,g=j(i)?0:d(i,e.__wbindgen_malloc,e.__wbindgen_realloc),u=c;let k=e.editsession_insert_image(this.__wbg_ptr,h,x,v,A,o,W,E,a,f,g,u);var m=k[0],y=k[1];if(k[3])throw m=0,y=0,w(k[2]);return l=m,s=y,p(m,y)}finally{e.__wbindgen_free(l,s,1);}}insert_page_break(_,t,o){let n=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),r=c,i=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),l=c,s=e.editsession_insert_page_break(this.__wbg_ptr,n,r,i,l,o);if(s[1])throw w(s[0])}insert_row(_,t,o,n){let r,i;try{let m=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),y=c;var l=j(o)?0:d(o,e.__wbindgen_malloc,e.__wbindgen_realloc),s=c,a=j(n)?0:d(n,e.__wbindgen_malloc,e.__wbindgen_realloc),f=c;let h=e.editsession_insert_row(this.__wbg_ptr,m,y,t,l,s,a,f);var g=h[0],u=h[1];if(h[3])throw g=0,u=0,w(h[2]);return r=g,i=u,p(g,u)}finally{e.__wbindgen_free(r,i,1);}}insert_section_break(_,t,o,n){let r=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),i=c,l=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),s=c,a=d(n,e.__wbindgen_malloc,e.__wbindgen_realloc),f=c,g=e.editsession_insert_section_break(this.__wbg_ptr,r,i,l,s,o,a,f);if(g[1])throw w(g[0])}insert_table(_,t,o,n,r,i,l){let s,a;try{let x=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),v=c,A=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),W=c;var f=j(i)?0:d(i,e.__wbindgen_malloc,e.__wbindgen_realloc),g=c,u=j(l)?0:d(l,e.__wbindgen_malloc,e.__wbindgen_realloc),m=c;let E=e.editsession_insert_table(this.__wbg_ptr,x,v,A,W,o,n,r,f,g,u,m);var y=E[0],h=E[1];if(E[3])throw y=0,h=0,w(E[2]);return s=y,a=h,p(y,h)}finally{e.__wbindgen_free(s,a,1);}}insert_text(_,t,o,n,r,i){let l,s;try{let h=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),x=c,v=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),A=c,W=d(n,e.__wbindgen_malloc,e.__wbindgen_realloc),E=c;var a=j(r)?0:d(r,e.__wbindgen_malloc,e.__wbindgen_realloc),f=c,g=j(i)?0:d(i,e.__wbindgen_malloc,e.__wbindgen_realloc),u=c;let k=e.editsession_insert_text(this.__wbg_ptr,h,x,v,A,o,W,E,a,f,g,u);var m=k[0],y=k[1];if(k[3])throw m=0,y=0,w(k[2]);return l=m,s=y,p(m,y)}finally{e.__wbindgen_free(l,s,1);}}insert_watermark(_,t,o,n){let r=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),i=c,l=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),s=c,a=d(n,e.__wbindgen_malloc,e.__wbindgen_realloc),f=c,g=e.editsession_insert_watermark(this.__wbg_ptr,r,i,l,s,o,a,f);if(g[1])throw w(g[0])}layout_document_json(_){let t,o;try{let i=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),l=c,s=e.editsession_layout_document_json(this.__wbg_ptr,i,l);var n=s[0],r=s[1];if(s[3])throw n=0,r=0,w(s[2]);return t=n,o=r,p(n,r)}finally{e.__wbindgen_free(t,o,1);}}layout_document_with_regions_json(_){let t,o;try{let i=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),l=c,s=e.editsession_layout_document_with_regions_json(this.__wbg_ptr,i,l);var n=s[0],r=s[1];if(s[3])throw n=0,r=0,w(s[2]);return t=n,o=r,p(n,r)}finally{e.__wbindgen_free(t,o,1);}}layout_font_requirements_json(_){let t,o;try{let i=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),l=c,s=e.editsession_layout_font_requirements_json(this.__wbg_ptr,i,l);var n=s[0],r=s[1];if(s[3])throw n=0,r=0,w(s[2]);return t=n,o=r,p(n,r)}finally{e.__wbindgen_free(t,o,1);}}list_revisions(){let _,t;try{let r=e.editsession_list_revisions(this.__wbg_ptr);var o=r[0],n=r[1];if(r[3])throw o=0,n=0,w(r[2]);return _=o,t=n,p(o,n)}finally{e.__wbindgen_free(_,t,1);}}load(_){let t=S(_,e.__wbindgen_malloc),o=c,n=e.editsession_load(this.__wbg_ptr,t,o);if(n[1])throw w(n[0])}load_json(_){let t,o;try{let i=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),l=c,s=e.editsession_load_json(this.__wbg_ptr,i,l);var n=s[0],r=s[1];if(s[3])throw n=0,r=0,w(s[2]);return t=n,o=r,p(n,r)}finally{e.__wbindgen_free(t,o,1);}}locate_paragraph(_,t){let o,n;try{let l=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),s=c,a=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),f=c,g=e.editsession_locate_paragraph(this.__wbg_ptr,l,s,a,f);var r=g[0],i=g[1];if(g[3])throw r=0,i=0,w(g[2]);return o=r,n=i,p(r,i)}finally{e.__wbindgen_free(o,n,1);}}materialize_docx(){let _=e.editsession_materialize_docx(this.__wbg_ptr);if(_[3])throw w(_[2]);let t;return _[0]!==0&&(t=p(_[0],_[1]).slice(),e.__wbindgen_free(_[0],_[1]*1,1)),t}measure_paragraph_json(_){let t,o;try{let i=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),l=c,s=e.editsession_measure_paragraph_json(this.__wbg_ptr,i,l);var n=s[0],r=s[1];if(s[3])throw n=0,r=0,w(s[2]);return t=n,o=r,p(n,r)}finally{e.__wbindgen_free(t,o,1);}}merge_cells(_){let t,o;try{let i=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),l=c,s=e.editsession_merge_cells(this.__wbg_ptr,i,l);var n=s[0],r=s[1];if(s[3])throw n=0,r=0,w(s[2]);return t=n,o=r,p(n,r)}finally{e.__wbindgen_free(t,o,1);}}merge_paragraphs(_,t,o,n){let r,i;try{let m=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),y=c,h=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),x=c;var l=j(o)?0:d(o,e.__wbindgen_malloc,e.__wbindgen_realloc),s=c,a=j(n)?0:d(n,e.__wbindgen_malloc,e.__wbindgen_realloc),f=c;let v=e.editsession_merge_paragraphs(this.__wbg_ptr,m,y,h,x,l,s,a,f);var g=v[0],u=v[1];if(v[3])throw g=0,u=0,w(v[2]);return r=g,i=u,p(g,u)}finally{e.__wbindgen_free(r,i,1);}}constructor(_){let t=e.editsession_new(_);if(t[2])throw w(t[1]);return this.__wbg_ptr=t[0],B.register(this,this.__wbg_ptr,this),this}open_docx(_,t){let o,n;try{let l=S(_,e.__wbindgen_malloc),s=c,a=e.editsession_open_docx(this.__wbg_ptr,l,s,t);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,w(a[2]);return o=r,n=i,p(r,i)}finally{e.__wbindgen_free(o,n,1);}}outline_glyph_json(_,t){let o,n;try{let l=e.editsession_outline_glyph_json(this.__wbg_ptr,_,t);var r=l[0],i=l[1];if(l[3])throw r=0,i=0,w(l[2]);return o=r,n=i,p(r,i)}finally{e.__wbindgen_free(o,n,1);}}paragraph_spans(_){let t,o;try{let i=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),l=c,s=e.editsession_paragraph_spans(this.__wbg_ptr,i,l);var n=s[0],r=s[1];if(s[3])throw n=0,r=0,w(s[2]);return t=n,o=r,p(n,r)}finally{e.__wbindgen_free(t,o,1);}}paragraphs(_){let t,o;try{let i=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),l=c,s=e.editsession_paragraphs(this.__wbg_ptr,i,l);var n=s[0],r=s[1];if(s[3])throw n=0,r=0,w(s[2]);return t=n,o=r,p(n,r)}finally{e.__wbindgen_free(t,o,1);}}redo(){return e.editsession_redo(this.__wbg_ptr)!==0}redo_depth(){return e.editsession_redo_depth(this.__wbg_ptr)>>>0}register_measure_font(_){let t=S(_,e.__wbindgen_malloc),o=c,n=e.editsession_register_measure_font(this.__wbg_ptr,t,o);if(n[2])throw w(n[1]);return n[0]>>>0}reject_change(_){let t,o;try{let i=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),l=c,s=e.editsession_reject_change(this.__wbg_ptr,i,l);var n=s[0],r=s[1];if(s[3])throw n=0,r=0,w(s[2]);return t=n,o=r,p(n,r)}finally{e.__wbindgen_free(t,o,1);}}replace_range(_,t,o,n,r,i,l,s){let a,f;try{let v=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),A=c,W=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),E=c,k=d(n,e.__wbindgen_malloc,e.__wbindgen_realloc),T=c,Y=d(i,e.__wbindgen_malloc,e.__wbindgen_realloc),H=c;var g=j(l)?0:d(l,e.__wbindgen_malloc,e.__wbindgen_realloc),u=c,m=j(s)?0:d(s,e.__wbindgen_malloc,e.__wbindgen_realloc),y=c;let F=e.editsession_replace_range(this.__wbg_ptr,v,A,W,E,o,k,T,r,Y,H,g,u,m,y);var h=F[0],x=F[1];if(F[3])throw h=0,x=0,w(F[2]);return a=h,f=x,p(h,x)}finally{e.__wbindgen_free(a,f,1);}}resident_caret_snapshot_json(){let _,t;try{let r=e.editsession_resident_caret_snapshot_json(this.__wbg_ptr);var o=r[0],n=r[1];if(r[3])throw o=0,n=0,w(r[2]);return _=o,t=n,p(o,n)}finally{e.__wbindgen_free(_,t,1);}}resolve_comment(_){let t,o;try{let i=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),l=c,s=e.editsession_resolve_comment(this.__wbg_ptr,i,l);var n=s[0],r=s[1];if(s[3])throw n=0,r=0,w(s[2]);return t=n,o=r,p(n,r)}finally{e.__wbindgen_free(t,o,1);}}resolve_encoded_selection(_,t,o){let n,r;try{let s=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),a=c,f=S(t,e.__wbindgen_malloc),g=c,u=S(o,e.__wbindgen_malloc),m=c,y=e.editsession_resolve_encoded_selection(this.__wbg_ptr,s,a,f,g,u,m);var i=y[0],l=y[1];if(y[3])throw i=0,l=0,w(y[2]);return n=i,r=l,p(i,l)}finally{e.__wbindgen_free(n,r,1);}}resolve_sticky_position(_,t){let o,n;try{let l=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),s=c,a=S(t,e.__wbindgen_malloc),f=c,g=e.editsession_resolve_sticky_position(this.__wbg_ptr,l,s,a,f);var r=g[0],i=g[1];if(g[3])throw r=0,i=0,w(g[2]);return o=r,n=i,p(r,i)}finally{e.__wbindgen_free(o,n,1);}}seed_from_docx(_){let t,o;try{let i=S(_,e.__wbindgen_malloc),l=c,s=e.editsession_seed_from_docx(this.__wbg_ptr,i,l);var n=s[0],r=s[1];if(s[3])throw n=0,r=0,w(s[2]);return t=n,o=r,p(n,r)}finally{e.__wbindgen_free(t,o,1);}}selection(){let _,t;try{let r=e.editsession_selection(this.__wbg_ptr);var o=r[0],n=r[1];if(r[3])throw o=0,n=0,w(r[2]);return _=o,t=n,p(o,n)}finally{e.__wbindgen_free(_,t,1);}}selection_context(_,t,o,n,r){let i,l;try{let f=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),g=c,u=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),m=c,y=d(n,e.__wbindgen_malloc,e.__wbindgen_realloc),h=c,x=e.editsession_selection_context(this.__wbg_ptr,f,g,u,m,o,y,h,r);var s=x[0],a=x[1];if(x[3])throw s=0,a=0,w(x[2]);return i=s,l=a,p(s,a)}finally{e.__wbindgen_free(i,l,1);}}set_cell_borders(_,t){let o,n;try{let l=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),s=c,a=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),f=c,g=e.editsession_set_cell_borders(this.__wbg_ptr,l,s,a,f);var r=g[0],i=g[1];if(g[3])throw r=0,i=0,w(g[2]);return o=r,n=i,p(r,i)}finally{e.__wbindgen_free(o,n,1);}}set_cell_selection(_){let t=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),o=c,n=e.editsession_set_cell_selection(this.__wbg_ptr,t,o);if(n[1])throw w(n[0])}set_cell_shading(_,t){let o,n;try{let a=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),f=c;var r=j(t)?0:d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),i=c;let g=e.editsession_set_cell_shading(this.__wbg_ptr,a,f,r,i);var l=g[0],s=g[1];if(g[3])throw l=0,s=0,w(g[2]);return o=l,n=s,p(l,s)}finally{e.__wbindgen_free(o,n,1);}}set_cell_text_format(_,t){let o,n;try{let l=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),s=c,a=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),f=c,g=e.editsession_set_cell_text_format(this.__wbg_ptr,l,s,a,f);var r=g[0],i=g[1];if(g[3])throw r=0,i=0,w(g[2]);return o=r,n=i,p(r,i)}finally{e.__wbindgen_free(o,n,1);}}set_column_width(_,t){let o,n;try{let l=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),s=c,a=e.editsession_set_column_width(this.__wbg_ptr,l,s,t);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,w(a[2]);return o=r,n=i,p(r,i)}finally{e.__wbindgen_free(o,n,1);}}set_content_control_value(_,t){let o=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),n=c,r=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),i=c,l=e.editsession_set_content_control_value(this.__wbg_ptr,o,n,r,i);if(l[1])throw w(l[0])}set_content_control_value_at(_,t,o,n){let r=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),i=c,l=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),s=c,a=d(n,e.__wbindgen_malloc,e.__wbindgen_realloc),f=c,g=e.editsession_set_content_control_value_at(this.__wbg_ptr,r,i,l,s,o,a,f);if(g[1])throw w(g[0])}set_hyperlink(_,t,o,n,r,i){let l=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),s=c,a=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),f=c,g=d(n,e.__wbindgen_malloc,e.__wbindgen_realloc),u=c,m=d(i,e.__wbindgen_malloc,e.__wbindgen_realloc),y=c,h=e.editsession_set_hyperlink(this.__wbg_ptr,l,s,a,f,o,g,u,r,m,y);if(h[1])throw w(h[0])}set_image_geometry(_,t){let o=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),n=c,r=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),i=c,l=e.editsession_set_image_geometry(this.__wbg_ptr,o,n,r,i);if(l[1])throw w(l[0])}set_paragraph_attr(_,t,o){let n=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),r=c,i=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),l=c,s=d(o,e.__wbindgen_malloc,e.__wbindgen_realloc),a=c,f=e.editsession_set_paragraph_attr(this.__wbg_ptr,n,r,i,l,s,a);if(f[1])throw w(f[0])}set_paragraph_attrs(_,t,o,n,r,i,l,s){let a=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),f=c,g=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),u=c,m=d(n,e.__wbindgen_malloc,e.__wbindgen_realloc),y=c,h=d(i,e.__wbindgen_malloc,e.__wbindgen_realloc),x=c;var v=j(l)?0:d(l,e.__wbindgen_malloc,e.__wbindgen_realloc),A=c,W=j(s)?0:d(s,e.__wbindgen_malloc,e.__wbindgen_realloc),E=c;let k=e.editsession_set_paragraph_attrs(this.__wbg_ptr,a,f,g,u,o,m,y,r,h,x,v,A,W,E);if(k[1])throw w(k[0])}set_selection(_,t,o,n,r){let i=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),l=c,s=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),a=c,f=d(n,e.__wbindgen_malloc,e.__wbindgen_realloc),g=c,u=e.editsession_set_selection(this.__wbg_ptr,i,l,s,a,o,f,g,r);if(u[1])throw w(u[0])}set_table_width(_,t){let o,n;try{let l=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),s=c,a=e.editsession_set_table_width(this.__wbg_ptr,l,s,t);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,w(a[2]);return o=r,n=i,p(r,i)}finally{e.__wbindgen_free(o,n,1);}}set_update_observer(_){let t=e.editsession_set_update_observer(this.__wbg_ptr,_);if(t[1])throw w(t[0])}split_cell(_,t,o){let n,r;try{let s=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),a=c,f=e.editsession_split_cell(this.__wbg_ptr,s,a,j(t)?Number.MAX_SAFE_INTEGER:t>>>0,j(o)?Number.MAX_SAFE_INTEGER:o>>>0);var i=f[0],l=f[1];if(f[3])throw i=0,l=0,w(f[2]);return n=i,r=l,p(i,l)}finally{e.__wbindgen_free(n,r,1);}}split_paragraph(_,t,o,n,r){let i,l;try{let y=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),h=c,x=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),v=c;var s=j(n)?0:d(n,e.__wbindgen_malloc,e.__wbindgen_realloc),a=c,f=j(r)?0:d(r,e.__wbindgen_malloc,e.__wbindgen_realloc),g=c;let A=e.editsession_split_paragraph(this.__wbg_ptr,y,h,x,v,o,s,a,f,g);var u=A[0],m=A[1];if(A[3])throw u=0,m=0,w(A[2]);return i=u,l=m,p(u,m)}finally{e.__wbindgen_free(i,l,1);}}start_update_event_observation(){let _=e.editsession_start_update_event_observation(this.__wbg_ptr);if(_[1])throw w(_[0])}story_checksum(_){let t,o;try{let i=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),l=c,s=e.editsession_story_checksum(this.__wbg_ptr,i,l);var n=s[0],r=s[1];if(s[3])throw n=0,r=0,w(s[2]);return t=n,o=r,p(n,r)}finally{e.__wbindgen_free(t,o,1);}}story_ids(){let _=e.editsession_story_ids(this.__wbg_ptr);var t=$(_[0],_[1]).slice();return e.__wbindgen_free(_[0],_[1]*4,4),t}story_len(_){let t=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),o=c,n=e.editsession_story_len(this.__wbg_ptr,t,o);if(n[2])throw w(n[1]);return n[0]>>>0}story_segments(_){let t,o;try{let i=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),l=c,s=e.editsession_story_segments(this.__wbg_ptr,i,l);var n=s[0],r=s[1];if(s[3])throw n=0,r=0,w(s[2]);return t=n,o=r,p(n,r)}finally{e.__wbindgen_free(t,o,1);}}toggle_mark(_,t,o,n,r,i){let l=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),s=c,a=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),f=c,g=d(n,e.__wbindgen_malloc,e.__wbindgen_realloc),u=c,m=d(i,e.__wbindgen_malloc,e.__wbindgen_realloc),y=c,h=e.editsession_toggle_mark(this.__wbg_ptr,l,s,a,f,o,g,u,r,m,y);if(h[1])throw w(h[0])}track_table_undo(_){let t=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),o=c,n=e.editsession_track_table_undo(this.__wbg_ptr,t,o);if(n[1])throw w(n[0])}track_undo(_){let t=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),o=c,n=e.editsession_track_undo(this.__wbg_ptr,t,o);if(n[1])throw w(n[0])}undo(){return e.editsession_undo(this.__wbg_ptr)!==0}undo_depth(){return e.editsession_undo_depth(this.__wbg_ptr)>>>0}yrs_blocks_for_story(_,t){let o,n;try{let l=d(_,e.__wbindgen_malloc,e.__wbindgen_realloc),s=c,a=d(t,e.__wbindgen_malloc,e.__wbindgen_realloc),f=c,g=e.editsession_yrs_blocks_for_story(this.__wbg_ptr,l,s,a,f);var r=g[0],i=g[1];if(g[3])throw r=0,i=0,w(g[2]);return o=r,n=i,p(r,i)}finally{e.__wbindgen_free(o,n,1);}}};Symbol.dispose&&(M.prototype[Symbol.dispose]=M.prototype.free);function C(){return {__proto__:null,"./docx_edit_bg.js":{__proto__:null,__wbg___wbindgen_string_get_b0ca35b86a603356:function(_,t){let o=t,n=typeof o=="string"?o:void 0;var r=j(n)?0:d(n,e.__wbindgen_malloc,e.__wbindgen_realloc),i=c;V().setInt32(_+4,i,true),V().setInt32(_+0,r,true);},__wbg___wbindgen_throw_344f42d3211c4765:function(_,t){throw new Error(p(_,t))},__wbg_call_e3b662382210db98:function(){return D(function(_,t,o,n){return _.call(t,o,n)},arguments)},__wbg_error_25e7706a73a81f28:function(_,t){console.error(p(_,t));},__wbg_getRandomValues_3f44b700395062e5:function(){return D(function(_,t){globalThis.crypto.getRandomValues(R(_,t));},arguments)},__wbg_get_78f252d074a84d0b:function(){return D(function(_,t){return Reflect.get(_,t)},arguments)},__wbg_get_unchecked_6e0ad6d2a41b06f6:function(_,t){return _[t>>>0]},__wbg_instanceof_Object_33f20e6f12439f3e:function(_){let t;try{t=_ instanceof Object;}catch{t=false;}return t},__wbg_keys_58421f8f96795607:function(_){return Object.keys(_)},__wbg_length_1f0964f4a5e2c6d8:function(_){return _.length},__wbg_length_370319915dc99107:function(_){return _.length},__wbg_new_cd45aabdf6073e84:function(_){return new Uint8Array(_)},__wbg_new_da52cf8fe3429cb2:function(){return new Object},__wbg_new_from_slice_77cdfb7977362f3c:function(_,t){return new Uint8Array(R(_,t))},__wbg_now_d0bb76462549e961:function(){return performance.now()},__wbg_prototypesetcall_4770620bbe4688a0:function(_,t,o){Uint8Array.prototype.set.call(R(_,t),o);},__wbg_set_8535240470bf2500:function(){return D(function(_,t,o){return Reflect.set(_,t,o)},arguments)},__wbindgen_cast_0000000000000001:function(_){return _},__wbindgen_cast_0000000000000002:function(_,t){return p(_,t)},__wbindgen_init_externref_table:function(){let _=e.__wbindgen_externrefs,t=_.grow(4);_.set(0,void 0),_.set(t+0,void 0),_.set(t+1,null),_.set(t+2,true),_.set(t+3,false);}}}}var B=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(b=>e.__wbg_editsession_free(b,1));function Z(b){let _=e.__externref_table_alloc();return e.__wbindgen_externrefs.set(_,b),_}function $(b,_){b=b>>>0;let t=V(),o=[];for(let n=b;n<b+4*_;n+=4)o.push(e.__wbindgen_externrefs.get(t.getUint32(n,true)));return e.__externref_drop_slice(b,_),o}function R(b,_){return b=b>>>0,O().subarray(b/1,b/1+_)}var z=null;function V(){return (z===null||z.buffer.detached===true||z.buffer.detached===void 0&&z.buffer!==e.memory.buffer)&&(z=new DataView(e.memory.buffer)),z}function p(b,_){return _e(b>>>0,_)}var I=null;function O(){return (I===null||I.byteLength===0)&&(I=new Uint8Array(e.memory.buffer)),I}function D(b,_){try{return b.apply(this,_)}catch(t){let o=Z(t);e.__wbindgen_exn_store(o);}}function j(b){return b==null}function S(b,_){let t=_(b.length*1,1)>>>0;return O().set(b,t/1),c=b.length,t}function d(b,_,t){if(t===void 0){let l=U.encode(b),s=_(l.length,1)>>>0;return O().subarray(s,s+l.length).set(l),c=l.length,s}let o=b.length,n=_(o,1)>>>0,r=O(),i=0;for(;i<o;i++){let l=b.charCodeAt(i);if(l>127)break;r[n+i]=l;}if(i!==o){i!==0&&(b=b.slice(i)),n=t(n,o,o=i+b.length*3,1)>>>0;let l=O().subarray(n+i,n+o),s=U.encodeInto(b,l);i+=s.written,n=t(n,o,i,1)>>>0;}return c=i,n}function w(b){let _=e.__wbindgen_externrefs.get(b);return e.__externref_table_dealloc(b),_}var L=new TextDecoder("utf-8",{ignoreBOM:true,fatal:true});L.decode();var ee=2146435072,N=0;function _e(b,_){return N+=_,N>=ee&&(L=new TextDecoder("utf-8",{ignoreBOM:true,fatal:true}),L.decode(),N=_),L.decode(O().subarray(b,b+_))}var U=new TextEncoder;"encodeInto"in U||(U.encodeInto=function(b,_){let t=U.encode(b);return _.set(t),{read:b.length,written:t.length}});var c=0,e;function P(b,_){return e=b.exports,z=null,I=null,e.__wbindgen_start(),e}async function re(b,_){if(typeof Response=="function"&&b instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(b,_)}catch(n){if(b.ok&&t(b.type)&&b.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",n);else throw n}let o=await b.arrayBuffer();return await WebAssembly.instantiate(o,_)}else {let o=await WebAssembly.instantiate(b,_);return o instanceof WebAssembly.Instance?{instance:o,module:b}:o}function t(o){switch(o){case "basic":case "cors":case "default":return true}return false}}function X(b){if(e!==void 0)return e;b!==void 0&&(Object.getPrototypeOf(b)===Object.prototype?{module:b}=b:console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));let _=C();b instanceof WebAssembly.Module||(b=new WebAssembly.Module(b));let t=new WebAssembly.Instance(b,_);return P(t)}async function G(b){if(e!==void 0)return e;if(b!==void 0&&(Object.getPrototypeOf(b)===Object.prototype?{module_or_path:b}=b:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),b===void 0)throw new Error("docx-edit wasm requires an explicit module or URL");let _=C();(typeof b=="string"||typeof Request=="function"&&b instanceof Request||typeof URL=="function"&&b instanceof URL)&&(b=fetch(b));let{instance:t,module:o}=await re(await b,_);return P(t)}var J=a({label:"docx-edit",preloadName:"preloadEditWasm",assetUrl:()=>new URL("./generated/edit/docx_edit_bg.wasm",import.meta.url),initAsync:G,initSync:X});function ce(b){return J.preload(b)}function de(b){return J.ensure(),new M(b)}export{ce as a,de as b};
@@ -0,0 +1 @@
1
+ import {b,c as c$1}from'./chunk-B4IR6YP4.mjs';var P=new Set(["__proto__","constructor","prototype"]);function J(t,e){return B(b(new Uint8Array(t),JSON.stringify(e)),t)}function B(t,e){return R(JSON.parse(t),e)}function R(t,e){h(t,"wire");let n=c(t,"wire");if(p(n,["wireVersion","document","embeddedFontParts","fontTableRelationshipsXml","canonicalBase64","canonicalSha256"],"wire",["fontTableRelationshipsXml","canonicalBase64","canonicalSha256"]),n.wireVersion!==1)throw new TypeError("wire.wireVersion must be 1");let r=D(n.document,e),o=N(n.embeddedFontParts);if((n.canonicalBase64!==void 0||n.canonicalSha256!==void 0)&&(n.canonicalBase64===void 0||n.canonicalSha256===void 0))throw new TypeError("wire canonical fields must be present together");let a=n.canonicalSha256===void 0?void 0:d(n.canonicalSha256,"wire.canonicalSha256");if(a!==void 0&&!/^[0-9a-f]{64}$/.test(a))throw new TypeError("wire.canonicalSha256 is invalid");return {wireVersion:1,document:r,embeddedFonts:o,...n.fontTableRelationshipsXml===void 0?{}:{fontTableRelationshipsXml:d(n.fontTableRelationshipsXml,"wire.fontTableRelationshipsXml")},...n.canonicalBase64===void 0?{}:{rustCanonicalBytes:g(d(n.canonicalBase64,"wire.canonicalBase64")),rustCanonicalSha256:a}}}function D(t,e){let n=c(t,"wire.document");p(n,["package","templateVariables","warnings"],"wire.document",["templateVariables","warnings"]);let o={package:M(n.package),originalBuffer:e};return n.warnings!==void 0&&(o.warnings=O(n.warnings,"wire.document.warnings")),o}function M(t){let e=c(t,"wire.document.package");p(e,["document","styles","theme","numbering","settings","fontTable","headerEntries","footerEntries","footnotes","endnotes","footnoteSeparators","endnoteSeparators","relationshipEntries","mediaEntries","chartEntries"],"wire.document.package",["styles","headerEntries","footerEntries","footnotes","endnotes","footnoteSeparators","endnoteSeparators"]);let o={document:x(e.document),theme:c(e.theme,"wire.document.package.theme"),numbering:c(e.numbering,"wire.document.package.numbering"),settings:c(e.settings,"wire.document.package.settings"),fontTable:c(e.fontTable,"wire.document.package.fontTable"),relationships:E(e.relationshipEntries,"wire.document.package.relationshipEntries"),media:F(e.mediaEntries),charts:y(e.chartEntries,"wire.document.package.chartEntries",(i,a)=>c(i,a))};e.styles!==void 0&&(o.styles=c(e.styles,"wire.document.package.styles"));for(let[i,a]of [["headerEntries","headers"],["footerEntries","footers"]]){let s=e[i];s!==void 0&&(o[a]=y(s,`wire.document.package.${i}`,(f,u)=>c(f,u)));}return e.footnotes!==void 0&&(o.footnotes=l(e.footnotes,"wire.document.package.footnotes")),e.endnotes!==void 0&&(o.endnotes=l(e.endnotes,"wire.document.package.endnotes")),e.footnoteSeparators!==void 0&&(o.footnoteSeparators=l(e.footnoteSeparators,"wire.document.package.footnoteSeparators")),e.endnoteSeparators!==void 0&&(o.endnoteSeparators=l(e.endnoteSeparators,"wire.document.package.endnoteSeparators")),o}function x(t){let e="wire.document.package.document",n=c(t,e);if(p(n,["content","sections","finalSectionProperties","comments"],e,["sections","finalSectionProperties","comments"]),!Array.isArray(n.content))throw new TypeError(`${e}.content must be an array`);n.content.forEach((o,i)=>c(o,`${e}.content[${i}]`));let r={content:n.content};if(n.sections!==void 0){if(!Array.isArray(n.sections))throw new TypeError(`${e}.sections must be an array`);r.sections=n.sections.map((o,i)=>{let a=`${e}.sections[${i}]`,s=c(o,a);p(s,["id","properties","contentStart","contentEnd"],a,["id"]);let f=S(s.contentStart,`${a}.contentStart`),u=S(s.contentEnd,`${a}.contentEnd`);if(f>u||u>r.content.length)throw new TypeError(`${a} has an invalid content range`);return {...s.id===void 0?{}:{id:d(s.id,`${a}.id`)},properties:c(s.properties,`${a}.properties`),content:r.content.slice(f,u)}});}return n.finalSectionProperties!==void 0&&(r.finalSectionProperties=c(n.finalSectionProperties,`${e}.finalSectionProperties`)),n.comments!==void 0&&(r.comments=l(n.comments,`${e}.comments`)),r}function E(t,e){return y(t,e,(n,r,o)=>C(n,r,o))}function F(t){let e="wire.document.package.mediaEntries";if(!Array.isArray(t))throw new TypeError(`${e} must be an array`);let n=new Map,r=new Map;for(let o=0;o<t.length;o+=1){let i=`${e}[${o}]`,a=t[o];if(!Array.isArray(a)||a.length!==2)throw new TypeError(`${i} must be a key/value pair`);let s=d(a[0],`${i}[0]`);if(n.has(s))throw new TypeError(`${e} contains duplicate key ${JSON.stringify(s)}`);let f=`${i}[1]`,u=c(a[1],f);p(u,["path","filename","mimeType","base64","dataUrl"],f,["filename"]);let m=d(u.path,`${f}.path`),w=r.get(m);if(!w){let A=g(d(u.base64,`${f}.base64`)),b={path:m,...u.filename===void 0?{}:{filename:d(u.filename,`${f}.filename`)},mimeType:d(u.mimeType,`${f}.mimeType`),data:T(A),dataUrl:d(u.dataUrl,`${f}.dataUrl`)};w=b,r.set(m,b);}n.set(s,w);}return n}function N(t){let e="wire.embeddedFontParts";if(!Array.isArray(t))throw new TypeError(`${e} must be an array`);let n=new Map;return t.forEach((r,o)=>{let i=`${e}[${o}]`,a=c(r,i);p(a,["path","base64"],i);let s=d(a.path,`${i}.path`);if(n.has(s))throw new TypeError(`${e} contains duplicate key ${JSON.stringify(s)}`);n.set(s,T(g(d(a.base64,`${i}.base64`))));}),n}function y(t,e,n){if(!Array.isArray(t))throw new TypeError(`${e} must be an array`);let r=new Map;return t.forEach((o,i)=>{let a=`${e}[${i}]`;if(!Array.isArray(o)||o.length!==2)throw new TypeError(`${a} must be a key/value pair`);let s=d(o[0],`${a}[0]`);if(r.has(s))throw new TypeError(`${e} contains duplicate key ${JSON.stringify(s)}`);r.set(s,n(o[1],`${a}[1]`,s));}),r}function O(t,e){if(!Array.isArray(t))throw new TypeError(`${e} must be an array`);return t.map((n,r)=>d(n,`${e}[${r}]`))}function l(t,e){if(!Array.isArray(t))throw new TypeError(`${e} must be an array`);return t.forEach((n,r)=>c(n,`${e}[${r}]`)),t}function T(t){return Uint8Array.from(t).buffer}function S(t,e){let n=U(t,e);if(!Number.isSafeInteger(n)||n<0)throw new TypeError(`${e} must be a non-negative safe integer`);return n}function _(t,e="word/_rels/document.xml.rels"){let n=JSON.parse(c$1(new TextEncoder().encode(t),e));h(n,"relationshipPart");let r=c(n,"relationshipPart");return p(r,["path","relationships","canonicalBase64","canonicalSha256"],"relationshipPart"),d(r.path,"relationshipPart.path"),E(r.relationships,"relationshipPart.relationships")}function C(t,e,n){let r=c(t,e);p(r,["id","type","target","targetMode"],e,["targetMode"]);let o=d(r.id,`${e}.id`);if(o!==n)throw new TypeError(`${e}.id does not match its map key`);let i={id:o,type:d(r.type,`${e}.type`),target:d(r.target,`${e}.target`)};if(r.targetMode!==void 0){if(r.targetMode!=="External"&&r.targetMode!=="Internal")throw new TypeError(`${e}.targetMode is invalid`);i.targetMode=r.targetMode;}return i}function h(t,e,n=new WeakSet){if(!(t===null||typeof t!="object")){if(n.has(t))throw new TypeError(`${e} contains a cycle`);n.add(t);try{for(let r of Object.keys(t)){if(P.has(r))throw new TypeError(`${e} contains forbidden key ${r}`);h(t[r],`${e}.${r}`,n);}}finally{n.delete(t);}}}function c(t,e){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(`${e} must be an object`);return t}function p(t,e,n,r=[]){let o=new Set(e);for(let a of Object.keys(t))if(!o.has(a))throw new TypeError(`${n} contains unknown key ${a}`);let i=new Set(r);for(let a of e)if(!i.has(a)&&!Object.prototype.hasOwnProperty.call(t,a))throw new TypeError(`${n} is missing ${a}`)}function d(t,e){if(typeof t!="string")throw new TypeError(`${e} must be a string`);return t}function U(t,e){if(typeof t!="number"||!Number.isFinite(t))throw new TypeError(`${e} must be a finite number`);return t}function g(t){let e;try{e=atob(t);}catch{throw new TypeError("wire canonicalBase64 is invalid")}let n=new Uint8Array(e.length);for(let r=0;r<e.length;r+=1)n[r]=e.charCodeAt(r);return n}export{J as a,B as b,R as c,_ as d};
@@ -0,0 +1 @@
1
+ var m=96;function E(n){return n==null||isNaN(n)?0:Math.round(n*96/914400)}function I(n){return Math.round(n/96*914400)}function b(n){return n/72*96}var t=1440,u=144,o=576,s=14;function p(n){return n/t*96}function x(n){return n/96*t}function c(n){return Math.round(n/914400*t)}function N(n){return Math.round(n/t*914400)}function H(n){return n/u*96}function f(n){return n/2}function R(n){return n*2}function C(n){return n/o*96}function P(n,e=2){let r=Math.pow(10,e);return Math.round(n*r)/r}function S(n,e,r){return Math.min(Math.max(n,e),r)}function T(n){return `${P(n)}px`}export{m as a,E as b,I as c,b as d,t as e,s as f,p as g,x as h,c as i,N as j,H as k,f as l,R as m,C as n,P as o,S as p,T as q};
@@ -1 +1 @@
1
- var s={dk1:"000000",lt1:"FFFFFF",dk2:"44546A",lt2:"E7E6E6",accent1:"4472C4",accent2:"ED7D31",accent3:"A5A5A5",accent4:"FFC000",accent5:"5B9BD5",accent6:"70AD47",hlink:"0563C1",folHlink:"954F72"},m={dk1:"dk1",lt1:"lt1",dk2:"dk2",lt2:"lt2",accent1:"accent1",accent2:"accent2",accent3:"accent3",accent4:"accent4",accent5:"accent5",accent6:"accent6",hlink:"hlink",folHlink:"folHlink",dark1:"dk1",light1:"lt1",dark2:"dk2",light2:"lt2",hyperlink:"hlink",followedHyperlink:"folHlink",background1:"lt1",text1:"dk1",background2:"lt2",text2:"dk2",tx1:"dk1",tx2:"dk2",bg1:"lt1",bg2:"lt2"};function x(e){if(!e)return 1;let n=parseInt(e,16);return isNaN(n)?1:n/255}function u(e){let n=e.padStart(6,"0").slice(0,6),t=parseInt(n.slice(0,2),16),r=parseInt(n.slice(2,4),16),l=parseInt(n.slice(4,6),16);return {r:isNaN(t)?0:t,g:isNaN(r)?0:r,b:isNaN(l)?0:l}}function g(e,n,t){let r=l=>Math.max(0,Math.min(255,Math.round(l))).toString(16).padStart(2,"0");return `${r(e)}${r(n)}${r(t)}`.toUpperCase()}function c(e,n){if(n>=1)return e;if(n<=0)return "FFFFFF";let t=u(e);return g(Math.min(255,Math.max(0,Math.round(t.r*n+255*(1-n)))),Math.min(255,Math.max(0,Math.round(t.g*n+255*(1-n)))),Math.min(255,Math.max(0,Math.round(t.b*n+255*(1-n)))))}function d(e,n){if(n>=1)return e;if(n<=0)return "000000";let t=u(e);return g(Math.min(255,Math.max(0,Math.round(t.r*n))),Math.min(255,Math.max(0,Math.round(t.g*n))),Math.min(255,Math.max(0,Math.round(t.b*n))))}function T(e,n){let t=m[n]??n,r=["dk1","lt1","dk2","lt2","accent1","accent2","accent3","accent4","accent5","accent6","hlink","folHlink"],l=o=>r.includes(o);return e?.colorScheme?l(t)?e.colorScheme[t]??s[t]??"000000":"000000":l(t)?s[t]??"000000":"000000"}function p(e){if(!e)return null;let n=e.toLowerCase();return m[e]??m[n]??null}function a(e,n,t="000000"){if(!e)return `#${t}`;if(e.auto)return `#${t}`;let r;if(e.themeColor){let l=p(e.themeColor);if(l?r=T(n,l):r=e.rgb??t,e.themeTint){let o=x(e.themeTint);r=c(r,o);}else if(e.themeShade){let o=x(e.themeShade);r=d(r,o);}}else e.rgb?r=e.rgb==="auto"?t:e.rgb:r=t;return `#${r.toUpperCase().replace(/^#/,"")}`}function S(e,n){if(!(!e||e.auto)){if(e.themeColor&&n)return a(e,n).slice(1);if(e.rgb&&e.rgb!=="auto")return e.rgb.toUpperCase().replace(/^#/,"")}}function k(e,n){if(!e)return "#000000";let r=a(e,n).replace(/^#/,""),l=u(r);return (.299*l.r+.587*l.g+.114*l.b)/255>.5?"#000000":"#FFFFFF"}function F(e,n,t){let l=a(e,n).replace(/^#/,""),o=1-t/100;return `#${d(l,o)}`}function M(e,n,t){let l=a(e,n).replace(/^#/,""),o=1-t/100;return `#${c(l,o)}`}function y(e,n,t,r){let l=a(e,r).replace(/^#/,""),o=a(n,r).replace(/^#/,""),i=u(l),h=u(o),f={r:Math.round(i.r*(1-t)+h.r*t),g:Math.round(i.g*(1-t)+h.g*t),b:Math.round(i.b*(1-t)+h.b*t)};return `#${g(f.r,f.g,f.b)}`}var v=[{slot:"lt1",name:"Background 1"},{slot:"dk1",name:"Text 1"},{slot:"lt2",name:"Background 2"},{slot:"dk2",name:"Text 2"},{slot:"accent1",name:"Accent 1"},{slot:"accent2",name:"Accent 2"},{slot:"accent3",name:"Accent 3"},{slot:"accent4",name:"Accent 4"},{slot:"accent5",name:"Accent 5"},{slot:"accent6",name:"Accent 6"}],V=[{type:"base",value:0,hexValue:"",labelSuffix:""},{type:"tint",value:.8,hexValue:"CC",labelSuffix:", Lighter 80%"},{type:"tint",value:.6,hexValue:"99",labelSuffix:", Lighter 60%"},{type:"tint",value:.4,hexValue:"66",labelSuffix:", Lighter 40%"},{type:"shade",value:.75,hexValue:"BF",labelSuffix:", Darker 25%"},{type:"shade",value:.5,hexValue:"80",labelSuffix:", Darker 50%"}];function H(e,n,t){return n==="tint"?c(e,1-t):d(e,t)}function A(e){let n=e??s;return V.map(t=>v.map(r=>{let l=n[r.slot]??s[r.slot]??"000000",o;t.type==="base"?o=l.toUpperCase():t.type==="tint"?o=c(l,1-t.value):o=d(l,t.value);let i={hex:o,themeSlot:r.slot,label:`${r.name}${t.labelSuffix}`};return t.type==="tint"&&t.hexValue?i.tint=t.hexValue:t.type==="shade"&&t.hexValue&&(i.shade=t.hexValue),i}))}var E={black:"000000",blue:"0000FF",cyan:"00FFFF",darkBlue:"00008B",darkCyan:"008B8B",darkGray:"A9A9A9",darkGreen:"006400",darkMagenta:"8B008B",darkRed:"8B0000",darkYellow:"808000",green:"00FF00",lightGray:"D3D3D3",magenta:"FF00FF",red:"FF0000",white:"FFFFFF",yellow:"FFFF00",none:""};function R(e){if(!e||e==="none")return "";let n=E[e];return n?`#${n}`:""}function D(e,n){return e?e.auto?"transparent":a(e,n):""}function I(e,n){if(!e)return false;if(e.auto)return true;let r=a(e,n).replace(/^#/,"").toLowerCase(),l=u(r);return (l.r+l.g+l.b)/3<20}function _(e,n){if(!e)return false;let r=a(e,n).replace(/^#/,"").toLowerCase(),l=u(r);return (l.r+l.g+l.b)/3>235}function O(e){if(!e)return;let n=e.trim();if(n.toLowerCase()==="auto")return {auto:true};let t=p(n);if(t)return {themeColor:t};let r=n.replace(/^#/,"").toUpperCase();return /^[0-9A-F]{6}$/i.test(r)?{rgb:r}:/^[0-9A-F]{3}$/i.test(r)?{rgb:r.split("").map(o=>o+o).join("")}:{rgb:r.padStart(6,"0").slice(0,6)}}function K(e,n,t){let r={themeColor:e};return n!==void 0&&n>0&&n<1&&(r.themeTint=Math.round(n*255).toString(16).toUpperCase().padStart(2,"0")),t!==void 0&&t>0&&t<1&&(r.themeShade=Math.round(t*255).toString(16).toUpperCase().padStart(2,"0")),r}function N(e){return {rgb:e.replace(/^#/,"").toUpperCase()}}function $(e){return e.startsWith("#")?e:`#${e}`}function G(e){return R(e)||$(e)}function z(e,n,t){if(!e&&!n)return true;if(!e||!n)return false;let r=a(e,t).toUpperCase(),l=a(n,t).toUpperCase();return r===l}export{a,S as b,k as c,F as d,M as e,y as f,H as g,A as h,R as i,D as j,I as k,_ as l,O as m,K as n,N as o,$ as p,G as q,z as r};
1
+ var s={dk1:"000000",lt1:"FFFFFF",dk2:"44546A",lt2:"E7E6E6",accent1:"4472C4",accent2:"ED7D31",accent3:"A5A5A5",accent4:"FFC000",accent5:"5B9BD5",accent6:"70AD47",hlink:"0563C1",folHlink:"954F72"},m={dk1:"dk1",lt1:"lt1",dk2:"dk2",lt2:"lt2",accent1:"accent1",accent2:"accent2",accent3:"accent3",accent4:"accent4",accent5:"accent5",accent6:"accent6",hlink:"hlink",folHlink:"folHlink",dark1:"dk1",light1:"lt1",dark2:"dk2",light2:"lt2",hyperlink:"hlink",followedHyperlink:"folHlink",background1:"lt1",text1:"dk1",background2:"lt2",text2:"dk2",tx1:"dk1",tx2:"dk2",bg1:"lt1",bg2:"lt2"};function C(e){if(!e)return 1;let n=parseInt(e,16);return isNaN(n)?1:n/255}function u(e){let n=e.padStart(6,"0").slice(0,6),t=parseInt(n.slice(0,2),16),r=parseInt(n.slice(2,4),16),l=parseInt(n.slice(4,6),16);return {r:isNaN(t)?0:t,g:isNaN(r)?0:r,b:isNaN(l)?0:l}}function g(e,n,t){let r=l=>Math.max(0,Math.min(255,Math.round(l))).toString(16).padStart(2,"0");return `${r(e)}${r(n)}${r(t)}`.toUpperCase()}function c(e,n){if(n>=1)return e;if(n<=0)return "FFFFFF";let t=u(e);return g(Math.min(255,Math.max(0,Math.round(t.r*n+255*(1-n)))),Math.min(255,Math.max(0,Math.round(t.g*n+255*(1-n)))),Math.min(255,Math.max(0,Math.round(t.b*n+255*(1-n)))))}function d(e,n){if(n>=1)return e;if(n<=0)return "000000";let t=u(e);return g(Math.min(255,Math.max(0,Math.round(t.r*n))),Math.min(255,Math.max(0,Math.round(t.g*n))),Math.min(255,Math.max(0,Math.round(t.b*n))))}function T(e,n){let t=m[n]??n,r=["dk1","lt1","dk2","lt2","accent1","accent2","accent3","accent4","accent5","accent6","hlink","folHlink"],l=o=>r.includes(o);return e?.colorScheme?l(t)?e.colorScheme[t]??s[t]??"000000":"000000":l(t)?s[t]??"000000":"000000"}function p(e){if(!e)return null;let n=e.toLowerCase();return m[e]??m[n]??null}function a(e,n,t="000000"){if(!e)return `#${t}`;if(e.auto)return `#${t}`;let r;if(e.themeColor){let l=p(e.themeColor);if(l?r=T(n,l):r=e.rgb??t,e.themeTint){let o=C(e.themeTint);r=c(r,o);}else if(e.themeShade){let o=C(e.themeShade);r=d(r,o);}}else e.rgb?r=e.rgb==="auto"?t:e.rgb:r=t;return `#${r.toUpperCase().replace(/^#/,"")}`}function S(e,n){if(!(!e||e.auto)){if(e.themeColor&&n)return a(e,n).slice(1);if(e.rgb&&e.rgb!=="auto")return e.rgb.toUpperCase().replace(/^#/,"")}}function k(e,n){if(!e)return "#000000";let r=a(e,n).replace(/^#/,""),l=u(r);return (.299*l.r+.587*l.g+.114*l.b)/255>.5?"#000000":"#FFFFFF"}function F(e,n,t){let l=a(e,n).replace(/^#/,""),o=1-t/100;return `#${d(l,o)}`}function M(e,n,t){let l=a(e,n).replace(/^#/,""),o=1-t/100;return `#${c(l,o)}`}function y(e,n,t,r){let l=a(e,r).replace(/^#/,""),o=a(n,r).replace(/^#/,""),i=u(l),h=u(o),f={r:Math.round(i.r*(1-t)+h.r*t),g:Math.round(i.g*(1-t)+h.g*t),b:Math.round(i.b*(1-t)+h.b*t)};return `#${g(f.r,f.g,f.b)}`}var v=[{slot:"lt1",name:"Background 1"},{slot:"dk1",name:"Text 1"},{slot:"lt2",name:"Background 2"},{slot:"dk2",name:"Text 2"},{slot:"accent1",name:"Accent 1"},{slot:"accent2",name:"Accent 2"},{slot:"accent3",name:"Accent 3"},{slot:"accent4",name:"Accent 4"},{slot:"accent5",name:"Accent 5"},{slot:"accent6",name:"Accent 6"}],V=[{type:"base",value:0,hexValue:"",labelSuffix:""},{type:"tint",value:.8,hexValue:"CC",labelSuffix:", Lighter 80%"},{type:"tint",value:.6,hexValue:"99",labelSuffix:", Lighter 60%"},{type:"tint",value:.4,hexValue:"66",labelSuffix:", Lighter 40%"},{type:"shade",value:.75,hexValue:"BF",labelSuffix:", Darker 25%"},{type:"shade",value:.5,hexValue:"80",labelSuffix:", Darker 50%"}];function A(e,n,t){return n==="tint"?c(e,1-t):d(e,t)}function H(e){let n=e??s;return V.map(t=>v.map(r=>{let l=n[r.slot]??s[r.slot]??"000000",o;t.type==="base"?o=l.toUpperCase():t.type==="tint"?o=c(l,1-t.value):o=d(l,t.value);let i={hex:o,themeSlot:r.slot,label:`${r.name}${t.labelSuffix}`};return t.type==="tint"&&t.hexValue?i.tint=t.hexValue:t.type==="shade"&&t.hexValue&&(i.shade=t.hexValue),i}))}var E={black:"000000",blue:"0000FF",cyan:"00FFFF",darkBlue:"00008B",darkCyan:"008B8B",darkGray:"A9A9A9",darkGreen:"006400",darkMagenta:"8B008B",darkRed:"8B0000",darkYellow:"808000",green:"00FF00",lightGray:"D3D3D3",magenta:"FF00FF",red:"FF0000",white:"FFFFFF",yellow:"FFFF00",none:""};function R(e){if(!e||e==="none")return "";let n=E[e];return n?`#${n}`:""}function D(e,n){return e?e.auto?"transparent":a(e,n):""}function I(e,n){if(!e)return false;if(e.auto)return true;let r=a(e,n).replace(/^#/,"").toLowerCase(),l=u(r);return (l.r+l.g+l.b)/3<20}function _(e,n){if(!e)return false;let r=a(e,n).replace(/^#/,"").toLowerCase(),l=u(r);return (l.r+l.g+l.b)/3>235}function O(e){if(!e)return;let n=e.trim();if(n.toLowerCase()==="auto")return {auto:true};let t=p(n);if(t)return {themeColor:t};let r=n.replace(/^#/,"").toUpperCase();return /^[0-9A-F]{6}$/i.test(r)?{rgb:r}:/^[0-9A-F]{3}$/i.test(r)?{rgb:r.split("").map(o=>o+o).join("")}:{rgb:r.padStart(6,"0").slice(0,6)}}function K(e,n,t){let r={themeColor:e};return n!==void 0&&n>0&&n<1&&(r.themeTint=Math.round(n*255).toString(16).toUpperCase().padStart(2,"0")),t!==void 0&&t>0&&t<1&&(r.themeShade=Math.round(t*255).toString(16).toUpperCase().padStart(2,"0")),r}function N(e){return {rgb:e.replace(/^#/,"").toUpperCase()}}function $(e){return e.startsWith("#")?e:`#${e}`}function G(e){return R(e)||$(e)}function z(e,n,t){if(!e&&!n)return true;if(!e||!n)return false;let r=a(e,t).toUpperCase(),l=a(n,t).toUpperCase();return r===l}export{a,S as b,k as c,F as d,M as e,y as f,A as g,H as h,R as i,D as j,I as k,_ as l,O as m,K as n,N as o,$ as p,G as q,z as r};
@@ -0,0 +1 @@
1
+ import {a as a$1}from'./chunk-T4EZMUXM.mjs';import {a}from'./chunk-TTRUPDAB.mjs';var S={};a(S,{build_display_list_json:()=>A,clear_measure_fonts:()=>D,close_display_list:()=>P,default:()=>J,hit_test_json:()=>X,hit_test_regions_by_handle:()=>z,hit_test_regions_json:()=>M,initSync:()=>H,install_panic_hook:()=>N,layout_document_json:()=>T,measure_paragraph_json:()=>W,open_display_list:()=>Y,outline_glyph_json:()=>O,range_rects_by_handle:()=>K,range_rects_json:()=>B,range_rects_region_by_handle:()=>Q,range_rects_region_json:()=>Z,register_measure_font:()=>I,update_display_list:()=>$,vertical_move_by_handle:()=>ee,vertical_move_json:()=>ne});function A(e){let n,t;try{let _=g(e,o.__wbindgen_malloc,o.__wbindgen_realloc),a=d,s=o.build_display_list_json(_,a);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,y(s[2]);return n=r,t=i,p(r,i)}finally{o.__wbindgen_free(n,t,1);}}function D(){o.clear_measure_fonts();}function P(e){o.close_display_list(e);}function X(e,n,t,r){let i,_;try{let l=g(e,o.__wbindgen_malloc,o.__wbindgen_realloc),f=d,u=o.hit_test_json(l,f,n,t,r);var a=u[0],s=u[1];if(u[3])throw a=0,s=0,y(u[2]);return i=a,_=s,p(a,s)}finally{o.__wbindgen_free(i,_,1);}}function z(e,n,t,r){let i,_;try{let l=o.hit_test_regions_by_handle(e,n,t,r);var a=l[0],s=l[1];if(l[3])throw a=0,s=0,y(l[2]);return i=a,_=s,p(a,s)}finally{o.__wbindgen_free(i,_,1);}}function M(e,n,t,r){let i,_;try{let l=g(e,o.__wbindgen_malloc,o.__wbindgen_realloc),f=d,u=o.hit_test_regions_json(l,f,n,t,r);var a=u[0],s=u[1];if(u[3])throw a=0,s=0,y(u[2]);return i=a,_=s,p(a,s)}finally{o.__wbindgen_free(i,_,1);}}function N(){o.install_panic_hook();}function T(e){let n,t;try{let _=g(e,o.__wbindgen_malloc,o.__wbindgen_realloc),a=d,s=o.layout_document_json(_,a);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,y(s[2]);return n=r,t=i,p(r,i)}finally{o.__wbindgen_free(n,t,1);}}function W(e){let n,t;try{let _=g(e,o.__wbindgen_malloc,o.__wbindgen_realloc),a=d,s=o.measure_paragraph_json(_,a);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,y(s[2]);return n=r,t=i,p(r,i)}finally{o.__wbindgen_free(n,t,1);}}function Y(e){let n=g(e,o.__wbindgen_malloc,o.__wbindgen_realloc),t=d,r=o.open_display_list(n,t);if(r[2])throw y(r[1]);return r[0]>>>0}function O(e,n){let t,r;try{let a=o.outline_glyph_json(e,n);var i=a[0],_=a[1];if(a[3])throw i=0,_=0,y(a[2]);return t=i,r=_,p(i,_)}finally{o.__wbindgen_free(t,r,1);}}function K(e,n,t){let r,i;try{let s=o.range_rects_by_handle(e,n,t);var _=s[0],a=s[1];if(s[3])throw _=0,a=0,y(s[2]);return r=_,i=a,p(_,a)}finally{o.__wbindgen_free(r,i,1);}}function B(e,n,t){let r,i;try{let s=g(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=d,f=o.range_rects_json(s,l,n,t);var _=f[0],a=f[1];if(f[3])throw _=0,a=0,y(f[2]);return r=_,i=a,p(_,a)}finally{o.__wbindgen_free(r,i,1);}}function Q(e,n,t,r,i){let _,a;try{let f=g(n,o.__wbindgen_malloc,o.__wbindgen_realloc),u=d,h=g(t,o.__wbindgen_malloc,o.__wbindgen_realloc),m=d,w=o.range_rects_region_by_handle(e,f,u,h,m,r,i);var s=w[0],l=w[1];if(w[3])throw s=0,l=0,y(w[2]);return _=s,a=l,p(s,l)}finally{o.__wbindgen_free(_,a,1);}}function Z(e,n,t,r,i){let _,a;try{let f=g(e,o.__wbindgen_malloc,o.__wbindgen_realloc),u=d,h=g(n,o.__wbindgen_malloc,o.__wbindgen_realloc),m=d,w=g(t,o.__wbindgen_malloc,o.__wbindgen_realloc),F=d,E=o.range_rects_region_json(f,u,h,m,w,F,r,i);var s=E[0],l=E[1];if(E[3])throw s=0,l=0,y(E[2]);return _=s,a=l,p(s,l)}finally{o.__wbindgen_free(_,a,1);}}function I(e){let n=te(e,o.__wbindgen_malloc),t=d,r=o.register_measure_font(n,t);if(r[2])throw y(r[1]);return r[0]>>>0}function $(e,n){let t=g(n,o.__wbindgen_malloc,o.__wbindgen_realloc),r=d,i=o.update_display_list(e,t,r);if(i[1])throw y(i[0])}function ee(e,n,t,r){let i,_;try{let l=g(t,o.__wbindgen_malloc,o.__wbindgen_realloc),f=d,u=o.vertical_move_by_handle(e,n,l,f,r);var a=u[0],s=u[1];if(u[3])throw a=0,s=0,y(u[2]);return i=a,_=s,p(a,s)}finally{o.__wbindgen_free(i,_,1);}}function ne(e,n,t,r){let i,_;try{let l=g(e,o.__wbindgen_malloc,o.__wbindgen_realloc),f=d,u=g(t,o.__wbindgen_malloc,o.__wbindgen_realloc),h=d,m=o.vertical_move_json(l,f,n,u,h,r);var a=m[0],s=m[1];if(m[3])throw a=0,s=0,y(m[2]);return i=a,_=s,p(a,s)}finally{o.__wbindgen_free(i,_,1);}}function k(){return {__proto__:null,"./docx_layout_bg.js":{__proto__:null,__wbg_error_25e7706a73a81f28:function(n,t){console.error(p(n,t));},__wbindgen_cast_0000000000000001:function(n,t){return p(n,t)},__wbindgen_init_externref_table:function(){let n=o.__wbindgen_externrefs,t=n.grow(4);n.set(0,void 0),n.set(t+0,void 0),n.set(t+1,null),n.set(t+2,true),n.set(t+3,false);}}}}function p(e,n){return oe(e>>>0,n)}var x=null;function v(){return (x===null||x.byteLength===0)&&(x=new Uint8Array(o.memory.buffer)),x}function te(e,n){let t=n(e.length*1,1)>>>0;return v().set(e,t/1),d=e.length,t}function g(e,n,t){if(t===void 0){let s=R.encode(e),l=n(s.length,1)>>>0;return v().subarray(l,l+s.length).set(s),d=s.length,l}let r=e.length,i=n(r,1)>>>0,_=v(),a=0;for(;a<r;a++){let s=e.charCodeAt(a);if(s>127)break;_[i+a]=s;}if(a!==r){a!==0&&(e=e.slice(a)),i=t(i,r,r=a+e.length*3,1)>>>0;let s=v().subarray(i+a,i+r),l=R.encodeInto(e,s);a+=l.written,i=t(i,r,a,1)>>>0;}return d=a,i}function y(e){let n=o.__wbindgen_externrefs.get(e);return o.__externref_table_dealloc(e),n}var j=new TextDecoder("utf-8",{ignoreBOM:true,fatal:true});j.decode();var re=2146435072,L=0;function oe(e,n){return L+=n,L>=re&&(j=new TextDecoder("utf-8",{ignoreBOM:true,fatal:true}),j.decode(),L=n),j.decode(v().subarray(e,e+n))}var R=new TextEncoder;"encodeInto"in R||(R.encodeInto=function(e,n){let t=R.encode(e);return n.set(t),{read:e.length,written:t.length}});var d=0,o;function q(e,n){return o=e.exports,x=null,o.__wbindgen_start(),o}async function ae(e,n){if(typeof Response=="function"&&e instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(e,n)}catch(i){if(e.ok&&t(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",i);else throw i}let r=await e.arrayBuffer();return await WebAssembly.instantiate(r,n)}else {let r=await WebAssembly.instantiate(e,n);return r instanceof WebAssembly.Instance?{instance:r,module:e}:r}function t(r){switch(r){case "basic":case "cors":case "default":return true}return false}}function H(e){if(o!==void 0)return o;e!==void 0&&(Object.getPrototypeOf(e)===Object.prototype?{module:e}=e:console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));let n=k();e instanceof WebAssembly.Module||(e=new WebAssembly.Module(e));let t=new WebAssembly.Instance(e,n);return q(t)}async function J(e){if(o!==void 0)return o;if(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")),e===void 0)throw new Error("docx-layout wasm requires an explicit module or URL");let n=k();(typeof e=="string"||typeof Request=="function"&&e instanceof Request||typeof URL=="function"&&e instanceof URL)&&(e=fetch(e));let{instance:t,module:r}=await ae(await e,n);return q(t)}var c=a$1({label:"docx-layout",preloadName:"preloadLayoutWasm",assetUrl:()=>new URL("./generated/layout/docx_layout_bg.wasm",import.meta.url),initAsync:J,initSync:H});function de(e){return c.preload(e)}function fe(e,n,t,r){return c.ensure(),M(e,n,t,r)}function ge(e,n,t){return c.ensure(),B(e,n,t)}function b(e){let n=S[e];return typeof n=="function"?n:void 0}function ye(){return c.ensure(),b("open_display_list")!==void 0}function pe(){return c.ensure(),b("range_rects_region_json")!==void 0}function be(e){c.ensure();let n=b("open_display_list");if(!n)throw new Error("open_display_list is not available in the embedded layout wasm yet");return n(e)}function me(e){c.ensure(),b("close_display_list")?.(e);}function we(e,n){c.ensure();let t=b("update_display_list");if(!t)throw new Error("update_display_list is not available in the embedded layout wasm yet");t(e,n);}function he(){return c.ensure(),b("update_display_list")!==void 0}function xe(e,n,t,r){c.ensure();let i=b("hit_test_regions_by_handle");if(!i)throw new Error("hit_test_regions_by_handle is not available in the embedded layout wasm yet");return i(e,n,t,r)}function ve(e,n,t,r){c.ensure();let i=b("vertical_move_json");if(!i)throw new Error("vertical_move_json is not available in the embedded layout wasm");return i(e,n,t,r)}function Re(e,n,t,r){c.ensure();let i=b("vertical_move_by_handle");if(!i)throw new Error("vertical_move_by_handle is not available in the embedded layout wasm");return i(e,n,t,r)}function Ee(e,n,t){c.ensure();let r=b("range_rects_by_handle");if(!r)throw new Error("range_rects_by_handle is not available in the embedded layout wasm yet");return r(e,n,t)}function je(e,n,t,r,i){c.ensure();let _=b("range_rects_region_json");if(!_)throw new Error("range_rects_region_json is not available in the embedded layout wasm yet");return _(e,n,t,r,i)}function Le(e,n,t,r,i){c.ensure();let _=b("range_rects_region_by_handle");if(!_)throw new Error("range_rects_region_by_handle is not available in the embedded layout wasm yet");return _(e,n,t,r,i)}function Ae(e){return c.ensure(),A(e)}function De(e){return c.ensure(),T(e)}function Me(e){return c.ensure(),I(e)}function Te(){c.ensure(),D();}function We(e){return c.ensure(),W(e)}function _e(){let e=O;return typeof e=="function"?e:void 0}function Oe(e,n){c.ensure();let t=_e();if(!t)throw new Error("outline_glyph_json is not available in the embedded layout wasm yet");return t(e,n)}export{de as a,fe as b,ge as c,ye as d,pe as e,be as f,me as g,we as h,he as i,xe as j,ve as k,Re as l,Ee as m,je as n,Le as o,Ae as p,De as q,Me as r,Te as s,We as t,Oe as u};
@@ -0,0 +1,57 @@
1
+ import {a as a$2,B as B$1,u}from'./chunk-YTILOUAA.mjs';import {a as a$3}from'./chunk-6KDV6AIL.mjs';import {a,b as b$1,c}from'./chunk-NJHOPXZW.mjs';import {a as a$1,d,e,f as f$1,g}from'./chunk-B4IR6YP4.mjs';async function we(e,t={}){await a(),await a$1();let r=e instanceof ArrayBuffer?e:await a$2(e),o=t.onProgress??(()=>{});try{o("Extracting DOCX...",0);let n=a$3(r,Z(t));return q(t,o),await K(n,t.preloadFonts??!0,o),o("Assembling document...",95),o("Complete",100),n.document}catch(n){let s=n instanceof Error?n.message:String(n);if(s.startsWith("Failed to parse DOCX: "))throw n;let a=Q(s),c=a.code==="Container"?s.replace(/^container error: /,""):s,m=new Error(`Failed to parse DOCX: ${c}`,{cause:n});throw Object.assign(m,a),m}}function Z(e){return {parseHeadersFooters:e.parseHeadersFooters??true,parseNotes:e.parseNotes??true,detectVariables:false,includeCanonical:false}}function q(e,t){t("Extracted DOCX",10),t("Parsing relationships...",10),t("Parsed relationships",15),t("Parsing theme...",15),t("Parsed theme",20),t("Parsing styles...",20),t("Parsed styles",30),t("Parsing numbering...",30),t("Parsed numbering",35),t("Processing media files...",35),t("Processed media",40),t("Parsing document body...",40),t("Parsed document body",55),e.parseHeadersFooters??true?(t("Parsing headers/footers...",55),t("Parsed headers/footers",65)):t("Skipping headers/footers",65),e.parseNotes??true?(t("Parsing footnotes/endnotes...",65),t("Parsed footnotes/endnotes",75)):t("Skipping footnotes/endnotes",75),t("Parsing comments...",75),t("Parsed comments",80);}async function K(e,t,r){if(!t){r("Skipping font loading",95);return}r("Loading fonts...",80),await G(e.document.package.theme??null,e.document.package.styles,e.document.package.document),await B$1(e.document.package.fontTable,e.embeddedFonts,e.fontTableRelationshipsXml),r("Loaded fonts",95);}async function G(e,t,r){let o=new Set;e?.fontScheme?.majorFont?.latin&&o.add(e.fontScheme.majorFont.latin),e?.fontScheme?.minorFont?.latin&&o.add(e.fontScheme.minorFont.latin),t?.docDefaults?.rPr?.fontFamily?.ascii&&o.add(t.docDefaults.rPr.fontFamily.ascii);for(let n of t?.styles??[])n.rPr?.fontFamily?.ascii&&o.add(n.rPr.fontFamily.ascii),n.rPr?.fontFamily?.hAnsi&&o.add(n.rPr.fontFamily.hAnsi);for(let n of r.content)if(n.type==="paragraph")for(let s of n.content)s.type==="run"&&(s.formatting?.fontFamily?.ascii&&o.add(s.formatting.fontFamily.ascii),s.formatting?.fontFamily?.hAnsi&&o.add(s.formatting.fontFamily.hAnsi));if(o.size!==0)try{await u([...o]);}catch(n){console.warn("Failed to load some fonts:",n);}}function Q(e){let t=/(?:unsafe XML|resource limit .* exceeded|malformed XML|invalid relationship) in ([^:]+)(?::| at)/.exec(e)?.[1],r=/ at byte (\d+):/.exec(e)?.[1];return {code:e.startsWith("unsafe XML")?"UnsafeXml":e.startsWith("resource limit")?"ResourceLimit":e.startsWith("malformed XML")?"MalformedXml":e.startsWith("invalid relationship")?"Relationship":e.startsWith("container error")?"Container":e.startsWith("wire.")?"Wire":"Parse",...t?{part:t}:{},...r?{offset:Number(r)}:{}}}var ee={seed:"0".repeat(64),now:"2000-01-01T00:00:00.000Z"};function B(e$1,t){let r=JSON.stringify({...t,determinism:ee}),o=e$1==="S10"?d(r):e$1==="S11"?e(r):f$1(r),n=JSON.parse(o);if(!n||typeof n!="object")throw new TypeError(`${e$1} Rust serializer returned a non-object response`);let s=n;if(s.wireVersion!==1||s.family!==t.family||typeof s.xml!="string")throw new TypeError(`invalid ${e$1} Rust serializer response for ${String(t.family)}`);return s.xml}function Se(e){return B("S12",{family:"document",body:e.package.document})}function Te(e){let t=B("S12",{family:"document",body:e}),r="<w:body>",o="</w:body>",n=t.indexOf(r),s=t.lastIndexOf(o);if(n<0||s<n)throw new Error("Rust document serializer omitted w:body");return t.slice(n+r.length,s)}function ke(e){return B("S10",{family:"section",properties:e})}var M={image:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",hyperlink:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink",header:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/header",footer:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer",footnotes:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes",endnotes:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes",styles:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles",numbering:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering",fontTable:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable",theme:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme",settings:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings",webSettings:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings",oleObject:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject",chart:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart",diagramData:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/diagramData",officeDocument:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",coreProperties:"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties",extendedProperties:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties",customProperties:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties",customXml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml",comments:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",commentsExtended:"http://schemas.microsoft.com/office/2011/relationships/commentsExtended",commentsIds:"http://schemas.microsoft.com/office/2016/09/relationships/commentsIds",commentsExtensible:"http://schemas.microsoft.com/office/2018/08/relationships/commentsExtensible"};var te=new TextEncoder,re=new TextDecoder("utf-8",{ignoreBOM:true});function l(e){return typeof e=="string"?te.encode(e):e instanceof Uint8Array?e:new Uint8Array(e)}function b(e){return e?re.decode(e):void 0}function I(e){let t=c(Object.fromEntries(e)),r=new ArrayBuffer(t.byteLength);return new Uint8Array(r).set(t),r}function E(e){return e.startsWith("/")?e.slice(1):`word/${e}`}function L(e){let t=[{relsPath:"word/_rels/document.xml.rels",blocks:e.package.document.content}],r=c=>(c??[]).flatMap(m=>m.content),o=[...r(e.package.footnoteSeparators),...r(e.package.footnotes)];o.length>0&&t.push({relsPath:"word/_rels/footnotes.xml.rels",blocks:o});let n=[...r(e.package.endnoteSeparators),...r(e.package.endnotes)];n.length>0&&t.push({relsPath:"word/_rels/endnotes.xml.rels",blocks:n});let s=e.package.relationships;if(!s)return t;let a=(c,m)=>{if(c)for(let[p,y]of c.entries()){let d=s.get(p);if(!d||d.type!==m||!d.target)continue;let w=E(d.target).replace(/^word\//,"");t.push({relsPath:`word/_rels/${w}.rels`,blocks:y.content});}};return a(e.package.headers,M.header),a(e.package.footers,M.footer),t}async function oe(e){let t=await crypto.subtle.digest("SHA-256",Uint8Array.from(e).buffer);return Array.from(new Uint8Array(t),r=>r.toString(16).padStart(2,"0")).join("")}async function A(e,t,r={},o,n){await a(),await a$1();let s=n??{seed:await oe(new Uint8Array(t)),now:new Date().toISOString()};ie(s);let a$2=e.package,c={determinism:s,document:a$2.document,headerEntries:[...a$2.headers?.entries()??[]],footerEntries:[...a$2.footers?.entries()??[]],footnotes:a$2.footnotes??[],endnotes:a$2.endnotes??[],footnoteSeparators:a$2.footnoteSeparators??[],endnoteSeparators:a$2.endnoteSeparators??[],relationshipEntries:[...a$2.relationships?.entries()??[]],...a$2.numbering===void 0?{}:{numbering:a$2.numbering},options:{updateModifiedDate:r.updateModifiedDate??true,...r.modifiedBy===void 0?{}:{modifiedBy:r.modifiedBy}},...o===void 0?{}:{selective:{changedParaIds:[...o.changedParaIds]}}};F(c,"save");let m=g(JSON.stringify(c),new Uint8Array(t)),p=ce(m);return o||ne(e,t,p),{buffer:p,determinism:s}}function ne(e,t,r){let o=b$1(new Uint8Array(t)),n=b$1(new Uint8Array(r));for(let c of L(e)){let m=b(o[c.relsPath])??"",p=b(n[c.relsPath])??"",y=new Set(S(m).map(i=>f(i,"Id"))),d=S(p).filter(i=>f(i,"Type")?.endsWith("/image")).map(i=>f(i,"Id")).filter(i=>!!i&&!y.has(i)),x=Y(c.blocks);if(x.length>d.length)throw new Error(`Rust save image mutation mismatch in ${c.relsPath}: ${x.length} model images, ${d.length} relationships`);x.forEach((i,u)=>{i.rId=d[u];});let w=S(p).filter(i=>f(i,"Type")?.endsWith("/hyperlink")&&f(i,"TargetMode")==="External");for(let i of C(c.blocks)){if(!i.href){j(p,i.rId)||(i.rId=void 0);continue}let u=w.find(T=>se(f(T,"Target")??"")===i.href),D=u&&f(u,"Id");D&&(i.rId=D);}}let s=e.package.headers,a=e.package.relationships;if(!(!s||!a))for(let[c,m]of s){let p=m.watermark;if(!p||p.kind!=="picture")continue;let y=a.get(c);if(!y?.target)continue;let x=`word/_rels/${E(y.target).replace(/^word\//,"")}.rels`,w=b(n[x])??"";if(j(w,p.relId))continue;let i=p.mediaPath?.split("/").pop(),u=S(w).find(T=>{if(!f(T,"Type")?.endsWith("/image"))return false;let J=f(T,"Target")?.split("/").pop();return i?J===i:true}),D=u&&f(u,"Id");D&&(p.relId=D);}}function Y(e){let t=[],r=o=>{for(let n of o.content)n.type==="drawing"&&n.image.src?.startsWith("data:")&&!n.image.rId&&t.push(n.image);};for(let o of e)if(o.type==="paragraph"){for(let n of o.content)if(n.type==="run")r(n);else if(n.type==="insertion"||n.type==="deletion"||n.type==="moveFrom"||n.type==="moveTo")for(let s of n.content)s.type==="run"&&r(s);}else if(o.type==="table")for(let n of o.rows)for(let s of n.cells)t.push(...Y(s.content));return t}function C(e){let t=[];for(let r of e)if(r.type==="paragraph")for(let o of r.content)o.type==="hyperlink"&&(o.href||o.rId)&&!o.anchor&&t.push(o);else if(r.type==="table")for(let o of r.rows)for(let n of o.cells)t.push(...C(n.content));else r.type==="blockSdt"&&t.push(...C(r.content));return t}function S(e){return [...e.matchAll(/<Relationship\b[^>]*\/?>/g)].map(t=>t[0])}function f(e,t){return e.match(new RegExp(`\\b${t}="([^"]*)"`))?.[1]}function j(e,t){if(t)return S(e).find(r=>f(r,"Id")===t)}function se(e){return e.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&apos;/g,"'").replace(/&#(\d+);/g,(t,r)=>String.fromCodePoint(Number(r))).replace(/&#x([0-9A-Fa-f]+);/g,(t,r)=>String.fromCodePoint(parseInt(r,16))).replace(/&amp;/g,"&")}function ie(e){if(!/^[0-9a-f]{64}$/i.test(e.seed))throw new TypeError("Rust save determinism seed must be a SHA-256 hex digest");if(!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(e.now))throw new TypeError("Rust save clock must be a UTC ISO-8601 millisecond timestamp")}var ae=new Set(["__proto__","constructor","prototype"]);function F(e,t,r=new WeakSet){if(!(e===null||typeof e!="object")){if(r.has(e))throw new TypeError(`${t} contains a cycle`);if(r.add(e),Array.isArray(e))e.forEach((o,n)=>F(o,`${t}[${n}]`,r));else for(let o of Object.keys(e)){if(ae.has(o))throw new TypeError(`${t} contains forbidden key ${o}`);F(e[o],`${t}.${o}`,r);}r.delete(e);}}function ce(e){let t=new ArrayBuffer(e.byteLength);return new Uint8Array(t).set(e),t}async function V(){let e=new Map;e.set("[Content_Types].xml",l(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
+ <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
3
+ <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
4
+ <Default Extension="xml" ContentType="application/xml"/>
5
+ <Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>
6
+ <Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"/>
7
+ <Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>
8
+ <Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>
9
+ </Types>`)),e.set("_rels/.rels",l(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
10
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
11
+ <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>
12
+ <Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>
13
+ <Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>
14
+ </Relationships>`)),e.set("word/_rels/document.xml.rels",l(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
15
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
16
+ <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>
17
+ </Relationships>`)),e.set("word/document.xml",l(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
18
+ <w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
19
+ <w:body>
20
+ <w:p>
21
+ <w:r>
22
+ <w:t></w:t>
23
+ </w:r>
24
+ </w:p>
25
+ <w:sectPr>
26
+ <w:pgSz w:w="12240" w:h="15840"/>
27
+ <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="720" w:footer="720" w:gutter="0"/>
28
+ </w:sectPr>
29
+ </w:body>
30
+ </w:document>`)),e.set("word/styles.xml",l(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
31
+ <w:styles xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
32
+ <w:docDefaults>
33
+ <w:rPrDefault>
34
+ <w:rPr>
35
+ <w:rFonts w:ascii="Calibri" w:hAnsi="Calibri"/>
36
+ <w:sz w:val="22"/>
37
+ </w:rPr>
38
+ </w:rPrDefault>
39
+ <w:pPrDefault>
40
+ <w:pPr>
41
+ <w:spacing w:after="200" w:line="276" w:lineRule="auto"/>
42
+ </w:pPr>
43
+ </w:pPrDefault>
44
+ </w:docDefaults>
45
+ <w:style w:type="paragraph" w:default="1" w:styleId="Normal">
46
+ <w:name w:val="Normal"/>
47
+ </w:style>
48
+ </w:styles>`));let t=new Date().toISOString();return e.set("docProps/core.xml",l(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
49
+ <cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
50
+ <dc:creator>OpenOOXML DOCX Editor</dc:creator>
51
+ <dcterms:created xsi:type="dcterms:W3CDTF">${t}</dcterms:created>
52
+ <dcterms:modified xsi:type="dcterms:W3CDTF">${t}</dcterms:modified>
53
+ </cp:coreProperties>`)),e.set("docProps/app.xml",l(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
54
+ <Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties">
55
+ <Application>OpenOOXML DOCX Editor</Application>
56
+ <AppVersion>1.0.0</AppVersion>
57
+ </Properties>`)),I(e)}async function pe(e,t={}){if(!e.originalBuffer)throw new Error("Cannot repack document: no original buffer for round-trip. Use createDocx() for new documents.");return (await A(e,e.originalBuffer,t)).buffer}function me(e){return new Map(Object.entries(b$1(new Uint8Array(e))))}async function Ve(e,t,r={}){return fe(me(e),t,r)}async function fe(e,t,r={}){for(let[o,n]of t)e.set(o,l(n));return I(e)}async function Je(e){let t=await V();return pe({...e,originalBuffer:t})}async function Ge(e,t,r){if(!le(e,t,r))return null;try{return (await A(e,t,{updateModifiedDate:!0},{changedParaIds:r.changedParaIds})).buffer}catch{return null}}function le(e,t,r){return r.structuralChange||r.hasUntrackedChanges||!t?false:!O(e.package.document.content)}function O(e){let t=r=>r.content.some(o=>o.type==="drawing"&&o.image?.src?.startsWith("data:")&&!o.image.rId);for(let r of e)if(r.type==="paragraph")for(let o of r.content){if(o.type==="run"&&t(o)||o.type==="hyperlink"&&o.href&&!o.rId&&!o.anchor)return true;if(o.type==="insertion"||o.type==="deletion"||o.type==="moveFrom"||o.type==="moveTo"){for(let n of o.content)if(n.type==="run"&&t(n))return true}}else if(r.type==="table"){for(let o of r.rows)for(let n of o.cells)if(O(n.content))return true}else if(r.type==="blockSdt"&&O(r.content))return true;return false}export{we as a,Se as b,Te as c,ke as d,M as e,pe as f,Ve as g,Je as h,Ge as i};
@@ -0,0 +1,16 @@
1
+ import {d as d$1}from'./chunk-6KDV6AIL.mjs';import {a,b as b$1}from'./chunk-NJHOPXZW.mjs';import {a as a$1}from'./chunk-B4IR6YP4.mjs';async function pe(n){if(n instanceof ArrayBuffer)return n;if(n instanceof Uint8Array){let e=new ArrayBuffer(n.byteLength);return new Uint8Array(e).set(n),e}if(n instanceof Blob)return n.arrayBuffer();throw new TypeError(`Unsupported DocxInput type: ${typeof n}`)}function P(n){let e=n.replace(/[^0-9a-fA-F]/g,"");if(e.length!==32)return null;let t=new Uint8Array(16);for(let r=0;r<16;r++){let i=Number.parseInt(e.slice(r*2,r*2+2),16);if(Number.isNaN(i))return null;t[r]=i;}let o=new Uint8Array(16);for(let r=0;r<16;r++)o[r]=t[15-r];return o}function B(n){return n?P(n)!==null:false}function v(n,e){let t=P(e);if(!t)throw new Error(`Invalid embedded-font key: "${e}"`);let o=new Uint8Array(n.slice(0)),r=Math.min(32,o.length);for(let i=0;i<r;i++)o[i]^=t[i%16];return o.buffer}var W={calibri:{googleFont:"Carlito",category:"sans-serif",fallbackStack:["Calibri","Carlito","Arial","Helvetica","sans-serif"],singleLineRatio:1.2207},cambria:{googleFont:"Caladea",category:"serif",fallbackStack:["Cambria","Caladea","Georgia","serif"],singleLineRatio:1.2676},arial:{googleFont:"Arimo",category:"sans-serif",fallbackStack:["Arial","Arimo","Helvetica","sans-serif"],singleLineRatio:1.1172},"times new roman":{googleFont:"Tinos",category:"serif",fallbackStack:["Times New Roman","Tinos","Times","serif"],singleLineRatio:1.1074},"courier new":{googleFont:"Cousine",category:"monospace",fallbackStack:["Courier New","Cousine","Courier","monospace"],singleLineRatio:1.1328},georgia:{googleFont:"Tinos",category:"serif",fallbackStack:["Georgia","Tinos","Times New Roman","serif"],singleLineRatio:1.1362},verdana:{googleFont:"Open Sans",category:"sans-serif",fallbackStack:["Verdana","Open Sans","Arial","sans-serif"],singleLineRatio:1.2153},tahoma:{googleFont:"Open Sans",category:"sans-serif",fallbackStack:["Tahoma","Open Sans","Arial","sans-serif"],singleLineRatio:1.2075},"trebuchet ms":{googleFont:"Fira Sans",category:"sans-serif",fallbackStack:["Trebuchet MS","Fira Sans","Arial","sans-serif"],singleLineRatio:1.1431},"comic sans ms":{googleFont:"Comic Neue",category:"cursive",fallbackStack:["Comic Sans MS","Comic Neue","cursive"],singleLineRatio:1.3936},impact:{googleFont:"Anton",category:"sans-serif",fallbackStack:["Impact","Anton","Arial Black","sans-serif"],singleLineRatio:1.2197},"palatino linotype":{googleFont:"EB Garamond",category:"serif",fallbackStack:["Palatino Linotype","EB Garamond","Palatino","Georgia","serif"],singleLineRatio:1.0259},"book antiqua":{googleFont:"EB Garamond",category:"serif",fallbackStack:["Book Antiqua","EB Garamond","Palatino","Georgia","serif"],singleLineRatio:1.0259},garamond:{googleFont:"EB Garamond",category:"serif",fallbackStack:["Garamond","EB Garamond","Georgia","serif"],singleLineRatio:1.068},"century gothic":{googleFont:"Questrial",category:"sans-serif",fallbackStack:["Century Gothic","Questrial","Arial","sans-serif"],singleLineRatio:1.1611},"lucida sans":{googleFont:"Open Sans",category:"sans-serif",fallbackStack:["Lucida Sans","Open Sans","Arial","sans-serif"],singleLineRatio:1.1655},"lucida console":{googleFont:"Cousine",category:"monospace",fallbackStack:["Lucida Console","Cousine","Courier New","monospace"],singleLineRatio:1.1387},consolas:{googleFont:"Inconsolata",category:"monospace",fallbackStack:["Consolas","Inconsolata","Cousine","Courier New","monospace"],singleLineRatio:1.1626},"ms mincho":{googleFont:"Noto Serif JP",category:"serif",fallbackStack:["MS Mincho","Noto Serif JP","serif"],singleLineRatio:1.15},"\uFF4D\uFF53 \u660E\u671D":{googleFont:"Noto Serif JP",category:"serif",fallbackStack:["MS Mincho","\uFF2D\uFF33 \u660E\u671D","Noto Serif JP","serif"],singleLineRatio:1.15},"\uFF4D\uFF53 \uFF50\u660E\u671D":{googleFont:"Noto Serif JP",category:"serif",fallbackStack:["MS PMincho","\uFF2D\uFF33 \uFF30\u660E\u671D","Noto Serif JP","serif"],singleLineRatio:1.15},"ms gothic":{googleFont:"Noto Sans JP",category:"sans-serif",fallbackStack:["MS Gothic","Noto Sans JP","sans-serif"],singleLineRatio:1.15},"\uFF4D\uFF53 \u30B4\u30B7\u30C3\u30AF":{googleFont:"Noto Sans JP",category:"sans-serif",fallbackStack:["MS Gothic","\uFF2D\uFF33 \u30B4\u30B7\u30C3\u30AF","Noto Sans JP","sans-serif"],singleLineRatio:1.15},"\uFF4D\uFF53 \uFF50\u30B4\u30B7\u30C3\u30AF":{googleFont:"Noto Sans JP",category:"sans-serif",fallbackStack:["MS PGothic","\uFF2D\uFF33 \uFF30\u30B4\u30B7\u30C3\u30AF","Noto Sans JP","sans-serif"],singleLineRatio:1.15},simhei:{googleFont:"Noto Sans SC",category:"sans-serif",fallbackStack:["SimHei","Noto Sans SC","sans-serif"],singleLineRatio:1.15},simsun:{googleFont:"Noto Serif SC",category:"serif",fallbackStack:["SimSun","Noto Serif SC","serif"],singleLineRatio:1.15},"malgun gothic":{googleFont:"Noto Sans KR",category:"sans-serif",fallbackStack:["Malgun Gothic","Noto Sans KR","sans-serif"],singleLineRatio:1.15},\u5B8B\u4F53:{googleFont:"Noto Serif SC",category:"serif",fallbackStack:["SimSun","\u5B8B\u4F53","Noto Serif SC","serif"],singleLineRatio:1.15},\u9ED1\u4F53:{googleFont:"Noto Sans SC",category:"sans-serif",fallbackStack:["SimHei","\u9ED1\u4F53","Noto Sans SC","sans-serif"],singleLineRatio:1.15},\u5FAE\u8F6F\u96C5\u9ED1:{googleFont:"Noto Sans SC",category:"sans-serif",fallbackStack:["Microsoft YaHei","\u5FAE\u8F6F\u96C5\u9ED1","Noto Sans SC","sans-serif"],singleLineRatio:1.15},\u7B49\u7EBF:{googleFont:"Noto Sans SC",category:"sans-serif",fallbackStack:["DengXian","\u7B49\u7EBF","Noto Sans SC","sans-serif"],singleLineRatio:1.15},\u4EFF\u5B8B:{googleFont:"Noto Serif SC",category:"serif",fallbackStack:["FangSong","\u4EFF\u5B8B","Noto Serif SC","serif"],singleLineRatio:1.15},\u6977\u4F53:{googleFont:"Noto Serif SC",category:"serif",fallbackStack:["KaiTi","\u6977\u4F53","Noto Serif SC","serif"],singleLineRatio:1.15},\u65B0\u7D30\u660E\u9AD4:{googleFont:"Noto Serif TC",category:"serif",fallbackStack:["PMingLiU","\u65B0\u7D30\u660E\u9AD4","Noto Serif TC","serif"],singleLineRatio:1.15},\u7D30\u660E\u9AD4:{googleFont:"Noto Serif TC",category:"serif",fallbackStack:["MingLiU","\u7D30\u660E\u9AD4","Noto Serif TC","serif"],singleLineRatio:1.15},\u5FAE\u8EDF\u6B63\u9ED1\u9AD4:{googleFont:"Noto Sans TC",category:"sans-serif",fallbackStack:["Microsoft JhengHei","\u5FAE\u8EDF\u6B63\u9ED1\u9AD4","Noto Sans TC","sans-serif"],singleLineRatio:1.15},\u6A19\u6977\u9AD4:{googleFont:"Noto Serif TC",category:"serif",fallbackStack:["DFKai-SB","\u6A19\u6977\u9AD4","Noto Serif TC","serif"],singleLineRatio:1.15},"\uB9D1\uC740 \uACE0\uB515":{googleFont:"Noto Sans KR",category:"sans-serif",fallbackStack:["Malgun Gothic","\uB9D1\uC740 \uACE0\uB515","Noto Sans KR","sans-serif"],singleLineRatio:1.15},\uAD74\uB9BC:{googleFont:"Noto Sans KR",category:"sans-serif",fallbackStack:["Gulim","\uAD74\uB9BC","Noto Sans KR","sans-serif"],singleLineRatio:1.15},\uB3CB\uC6C0:{googleFont:"Noto Sans KR",category:"sans-serif",fallbackStack:["Dotum","\uB3CB\uC6C0","Noto Sans KR","sans-serif"],singleLineRatio:1.15},\uBC14\uD0D5:{googleFont:"Noto Serif KR",category:"serif",fallbackStack:["Batang","\uBC14\uD0D5","Noto Serif KR","serif"],singleLineRatio:1.15},\uAD81\uC11C:{googleFont:"Noto Serif KR",category:"serif",fallbackStack:["Gungsuh","\uAD81\uC11C","Noto Serif KR","serif"],singleLineRatio:1.15}},q={"sans-serif":"Arial, Helvetica, sans-serif",serif:"Times New Roman, Times, serif",monospace:"Courier New, Courier, monospace",cursive:"cursive",fantasy:"fantasy","system-ui":"system-ui, sans-serif"};function J(n){let e=n.toLowerCase();return e.includes("mono")||e.includes("courier")||e.includes("consolas")||e.includes("console")||e.includes("code")||e.includes("terminal")?"monospace":e.includes("times")||e.includes("georgia")||e.includes("garamond")||e.includes("palatino")||e.includes("baskerville")||e.includes("bodoni")||e.includes("cambria")||e.includes("mincho")||e.includes("\u660E\u671D")||e.includes("\u660E\u9AD4")||e.includes("\u5B8B")||e.includes("ming")||e.includes("song")||e.includes("serif")?"serif":e.includes("script")||e.includes("cursive")||e.includes("comic")||e.includes("brush")||e.includes("hand")?"cursive":"sans-serif"}var Y={"microsoft yahei":"\u5FAE\u8F6F\u96C5\u9ED1",dengxian:"\u7B49\u7EBF",fangsong:"\u4EFF\u5B8B",kaiti:"\u6977\u4F53",pmingliu:"\u65B0\u7D30\u660E\u9AD4",mingliu:"\u7D30\u660E\u9AD4","microsoft jhenghei":"\u5FAE\u8EDF\u6B63\u9ED1\u9AD4","dfkai-sb":"\u6A19\u6977\u9AD4",gulim:"\uAD74\uB9BC",dotum:"\uB3CB\uC6C0",batang:"\uBC14\uD0D5",gungsuh:"\uAD81\uC11C",meiryo:"ms gothic",\u30E1\u30A4\u30EA\u30AA:"ms gothic","yu gothic":"ms gothic",\u6E38\u30B4\u30B7\u30C3\u30AF:"ms gothic","yu mincho":"ms mincho",\u6E38\u660E\u671D:"ms mincho"};function O(n){let e=n.trim().toLowerCase(),t=W[Y[e]??e];if(t)return {googleFont:t.googleFont,cssFallback:t.fallbackStack.map(D).join(", "),originalFont:n,hasGoogleEquivalent:true,singleLineRatio:t.singleLineRatio};let o=J(n),r=q[o];return {googleFont:null,cssFallback:`${D(n)}, ${r}`,originalFont:n,hasGoogleEquivalent:false,singleLineRatio:1.15}}var V={"\n":"\\a ","\r":"\\d ","\f":"\\c "};function X(n){return n.replace(/["\\]/g,"\\$&").replace(/[\n\r\f]/g,e=>V[e])}function D(n){return ["serif","sans-serif","monospace","cursive","fantasy","system-ui"].includes(n.toLowerCase())?n:/[\s,'"()]/.test(n)?`"${X(n)}"`:n}var g=new Set,m=new Map,C=new Set,f=new Map,w=new Set,b=new Set,d=false,L=true,h=new Set,E=new Set;function p(n,e){let t=n instanceof Error?n.message:String(n),o=new Error(`[font] ${e}: ${t}`,{cause:n});if(b.size>0)for(let r of b)try{r(o);}catch(i){console.error("Font error subscriber threw:",i);}else console.warn(o.message);}function M(n,e="normal",t="normal"){return `${n.trim()}|${e}|${t}`}function R(n){return h.has(n)?false:E.has(n)?true:re(n)?(E.add(n),queueMicrotask(()=>T([n])),true):false}function Q(n){let e=`${n}|`,t=[];for(let[o,r]of f)o.startsWith(e)&&t.push(r);return t}function $(n,e){C.add(n),g.add(e),T([e]);}function Z(n,e=[400,700],t=["normal","italic"]){let o=encodeURIComponent(n),r=[];for(let a of t){let s=a==="italic"?1:0;for(let c of e)r.push(`${s},${c}`);}r.sort();let i=r.join(";");return `https://fonts.googleapis.com/css2?family=${o}:ital,wght@${i}&display=swap`}async function A(n,e){if(typeof document>"u")return false;let t=n.trim();if(g.has(t))return true;let o=m.get(t);if(o)return o;if(!e&&R(t))return true;let r=Q(t);if(!L&&r.length===0)return false;let i=(async()=>{d=true;try{if(r.length>0&&(await Promise.all(r),g.has(t)||!e&&R(t)))return !0;if(!L)return !1;let a=Z(t,e?.weights,e?.styles),s=document.createElement("link");return s.rel="stylesheet",s.href=a,await new Promise(l=>{let u=setTimeout(()=>l(!1),5e3);s.onload=()=>{clearTimeout(u),l(!0);},s.onerror=()=>{clearTimeout(u),l(!1);},document.head.appendChild(s);})?(await I(t,3e3),g.add(t),T([t]),!0):!1}catch(a){return p(a,`failed to load "${t}"`),false}finally{m.delete(t),m.size===0&&f.size===0&&(d=false);}})();return m.set(t,i),i}async function ee(n,e){let t=n.filter(o=>!g.has(o.trim()));t.length!==0&&await Promise.all(t.map(o=>A(o,e)));}function ne(n){let e=n.trim();return g.has(e)||E.has(e)}function Re(n){L=n;}function Ae(){return L}function Ce(){return d}function Te(){return Array.from(new Set([...g,...E]))}function Ie(n){return w.add(n),()=>{w.delete(n);}}function T(n){for(let e of w)try{e(n);}catch(t){p(t,"load callback threw");}}function _e(n){return b.add(n),()=>{b.delete(n);}}async function I(n,e){if("fonts"in document)try{let t=`400 16px "${n}"`;return await Promise.race([document.fonts.load(t),new Promise(o=>setTimeout(o,e))]),document.fonts.check(t)}catch{}return await new Promise(t=>setTimeout(t,100)),true}var F,U=new Map,te="abcdefghijklmnopqrstuvwxyz0123456789";function oe(){return F===void 0&&(F=document.createElement("canvas").getContext("2d"),F&&(F.textBaseline="top")),F}function re(n,e="sans-serif"){if(typeof document>"u")return false;let t=oe();if(!t)return false;let o=i=>(t.font=i,t.measureText(te).width),r=i=>{let a=U.get(i);return a===void 0&&(a=o(`72px ${i}`),U.set(i,a)),o(`72px "${n}", ${i}`)!==a};return r(e)||r(e==="sans-serif"?"serif":"sans-serif")}var ie={"<":"\\3c ",">":"\\3e ","\n":"\\a ","\r":"\\d ","\f":"\\c "},K=n=>n.replace(/["\\]/g,"\\$&").replace(/[<>\n\r\f]/g,e=>ie[e]);async function H(n,e,t){if(typeof document>"u")return false;let o=n.trim(),r=t?.style??"normal",i=M(o,t?.weight,r);if(h.add(o),C.has(i))return true;let a=f.get(i);if(a)return a;let s=(async()=>{d=true;try{let c=new Blob([e],{type:"font/ttf"}),l=URL.createObjectURL(c),u=document.createElement("style");return u.textContent=`
2
+ @font-face {
3
+ font-family: "${K(o)}";
4
+ src: url(${l}) format('truetype');
5
+ font-weight: ${t?.weight??"normal"};
6
+ font-style: ${r};
7
+ font-display: swap;
8
+ }
9
+ `,document.head.appendChild(u),await I(o,3e3),$(i,o),!0}catch(c){return p(c,`failed to load "${o}" from buffer`),false}finally{f.delete(i),m.size===0&&f.size===0&&(d=false);}})();return f.set(i,s),s}function ae(n){let e=n.split("?")[0].split("#")[0].toLowerCase();return e.endsWith(".woff2")?"woff2":e.endsWith(".woff")?"woff":e.endsWith(".otf")?"opentype":"truetype"}async function se(n,e,t){if(typeof document>"u")return false;if(/[<>]/.test(e))return p(new Error(`invalid src URL for "${n}": contains '<' or '>'`),"rejected src"),false;let o=n.trim(),r=M(o,t?.weight);if(h.add(o),C.has(r))return true;let i=f.get(r);if(i)return i;let a=(async()=>{d=true;try{let s=document.createElement("style");return s.textContent=`
10
+ @font-face {
11
+ font-family: "${K(o)}";
12
+ src: url(${JSON.stringify(e)}) format('${ae(e)}');
13
+ font-weight: ${t?.weight??"normal"};
14
+ font-display: swap;
15
+ }
16
+ `,document.head.appendChild(s),await I(o,3e3),$(r,o),!0}catch(s){return p(s,`failed to load "${o}" from ${e}`),false}finally{f.delete(r),m.size===0&&f.size===0&&(d=false);}})();return f.set(r,a),a}async function Ge(n){!n||n.length===0||await Promise.all(n.map(e=>se(e.family,e.src,{weight:e.weight})));}var le={Calibri:"Carlito",Cambria:"Caladea",Arial:"Arimo","Times New Roman":"Tinos","Courier New":"Cousine",Garamond:"EB Garamond","Book Antiqua":"EB Garamond",Georgia:"Tinos",Verdana:"Open Sans",Tahoma:"Open Sans","Trebuchet MS":"Source Sans Pro","Century Gothic":"Poppins","Franklin Gothic":"Libre Franklin",Palatino:"EB Garamond","Palatino Linotype":"EB Garamond","Lucida Sans":"Open Sans","Segoe UI":"Open Sans",Impact:"Anton","Comic Sans MS":"Comic Neue",Consolas:"Inconsolata","Lucida Console":"Inconsolata",Monaco:"Fira Code"};function ce(n){let e=n.trim();return le[e]||O(e).googleFont||e}async function fe(n){let e=n.trim(),t=ce(e);if(t!==e){if(!h.has(e)&&ne(e)||R(e))return true;let o=await A(t);return o&&g.add(e),o}return A(t)}async function ge(n){let e=[...new Set(n.map(t=>t.trim()))];await Promise.all(e.map(t=>fe(t)));}async function xe(){await ee(["Carlito","Caladea","Arimo","Tinos","Cousine","EB Garamond"]);}function ue(n){let e=new Set;if(typeof n!="object"||n===null)return e;let t=[n],o=new WeakSet,r=0,i=1e5;for(;t.length>0&&r++<i;){let a=t.pop();if(typeof a!="object"||a===null||o.has(a))continue;if(o.add(a),Array.isArray(a)){for(let l of a)t.push(l);continue}let s=a,c=s.fontFamily;if(typeof c=="object"&&c!==null){let l=c;for(let u of ["ascii","hAnsi","eastAsia","cs"]){let N=l[u];typeof N=="string"&&N.trim()&&e.add(N.trim());}}typeof s.name=="string"&&("altName"in s||"panose1"in s||"embedRegular"in s)&&(s.name.trim()&&e.add(s.name.trim()),typeof s.altName=="string"&&s.altName.trim()&&e.add(s.altName.trim()));for(let l of Object.values(s))t.push(l);}return e}async function Pe(n){let e=ue(n);e.size!==0&&await ge(Array.from(e));}function de(n){let e=new TextDecoder("utf-8",{ignoreBOM:true});return {paths:()=>[...n.keys()],file:t=>n.get(t)??null,text:t=>{let o=n.get(t);return o?e.decode(o):null}}}function z(n){let e=b$1(new Uint8Array(n));return de(new Map(Object.entries(e)))}function me(n){let e=new Set;if(!n)return e;for(let t of n.fonts)(t.embedRegular||t.embedBold||t.embedItalic||t.embedBoldItalic)&&e.add(t.name);return e}var ye=[{key:"embedRegular",weight:"normal",style:"normal"},{key:"embedBold",weight:"bold",style:"normal"},{key:"embedItalic",weight:"normal",style:"italic"},{key:"embedBoldItalic",weight:"bold",style:"italic"}];function Se(n,e){let t=n.replace(/^\/+/,""),r=(t.toLowerCase().startsWith("word/")?t:`word/${t}`).toLowerCase();for(let[i,a]of e)if(i.toLowerCase()===r)return a}function Fe(n,e,t,o,r){let i=r.get(e.relId);if(!i)return null;let a=Se(i,o);if(!a)return null;let s;if(e.fontKey&&B(e.fontKey))try{s=v(a,e.fontKey);}catch{return null}else s=a.slice(0);return {family:n,weight:t.weight,style:t.style,data:s,subsetted:e.subsetted??false}}function j(n,e,t){if(!n||n.fonts.length===0)return [];if(!t||e.size===0)return [];let o=d$1(t,"word/_rels/fontTable.xml.rels"),r=new Map;for(let[a,s]of o)r.set(a,s.target);let i=[];for(let a of n.fonts)for(let s of ye){let c=a[s.key];if(!c)continue;let l=Fe(a.name,c,s,e,r);l&&i.push(l);}return i}async function We(n){let e=n.package.fontTable;if(!e||me(e).size===0)return [];let t=n.originalBuffer;if(!t)return [];await Promise.all([a(),a$1()]);let o=z(t),r=new Map,i=null;for(let a of o.paths()){if(a.toLowerCase().startsWith("word/fonts/")){let s=o.file(a);s&&r.set(a,s.slice().buffer);}a.toLowerCase()==="word/_rels/fonttable.xml.rels"&&(i=o.text(a));}return j(e,r,i)}async function qe(n,e,t){if(!n||!t||e.size===0)return new Set;await a$1();let o=j(n,e,t),r=new Set;return o.length===0||await Promise.all(o.map(async i=>{await H(i.family,i.data,{weight:i.weight,style:i.style})?r.add(i.family):typeof document<"u"&&console.warn(`[embeddedFonts] embedded face "${i.family}" (${i.weight} ${i.style}) failed to load; text using it falls back to the CSS stack`);})),r}export{We as A,qe as B,pe as a,B as b,v as c,O as d,A as e,ee as f,ne as g,Re as h,Ae as i,Ce as j,Te as k,Ie as l,_e as m,re as n,H as o,se as p,Ge as q,le as r,ce as s,fe as t,ge as u,xe as v,ue as w,Pe as x,me as y,j as z};
@@ -1,11 +1,11 @@
1
- import { C as CollaborationReplica, b as CollaborationTransport, c as CollaborationProviderOptions, d as CollaborationStatus, e as CollaborationStatusListener, f as CollaborationErrorListener, g as YrsSelection, Y as YrsSession } from '../index-Dx4Z3lkz.mjs';
2
- export { h as CollaborationError, i as CollaborationErrorCode, j as CollaborationStatusChange, k as CollaborationTransportEvent, l as CollaborationUpdateOrigin } from '../index-Dx4Z3lkz.mjs';
3
- import '../frameDelta-D965X8yK.mjs';
4
- import '../content-MOZ6hKP4.mjs';
5
- import '../formatting-D1EPSaJP.mjs';
6
- import '../docx/wrapTypes.mjs';
1
+ import { C as CollaborationReplica, b as CollaborationTransport, c as CollaborationProviderOptions, d as CollaborationStatus, e as CollaborationPeer, f as CollaborationCursor, g as CollaborationPeerListener, h as CollaborationStatusListener, i as CollaborationErrorListener, j as YrsSelection, Y as YrsSession } from '../index-2piKi4gO.mjs';
2
+ export { k as CollaborationAwarenessState, l as CollaborationError, m as CollaborationErrorCode, n as CollaborationPresence, o as CollaborationResolvedUser, p as CollaborationStatusChange, q as CollaborationTextInsertion, r as CollaborationTransportEvent, s as CollaborationUpdateOrigin, t as CollaborationUser } from '../index-2piKi4gO.mjs';
7
3
  import '../types/document.mjs';
8
- import '../styles-Dn_o3Vo5.mjs';
4
+ import '../content-C3sTRz-u.mjs';
5
+ import '../formatting-BEkIBePP.mjs';
6
+ import '../docx/wrapTypes.mjs';
7
+ import '../styles-BK3Jecxs.mjs';
8
+ import '../frameDelta-B2kC6XiP.mjs';
9
9
 
10
10
  declare class CollaborationProvider {
11
11
  private readonly replica;
@@ -13,9 +13,12 @@ declare class CollaborationProvider {
13
13
  private readonly maxFrameBytes;
14
14
  private readonly maxMessagesPerFrame;
15
15
  private readonly maxPendingBytes;
16
+ private readonly localUser;
16
17
  private readonly statusListeners;
17
18
  private readonly errorListeners;
19
+ private readonly peerListeners;
18
20
  private readonly pendingFrames;
21
+ private awarenessRecords;
19
22
  private unsubscribeReplica;
20
23
  private unsubscribeTransport;
21
24
  private hasTransportSubscription;
@@ -29,10 +32,20 @@ declare class CollaborationProvider {
29
32
  private nextListenerId;
30
33
  private queuedBytes;
31
34
  private isFlushing;
35
+ private localClock;
36
+ private reportedClockExhaustion;
37
+ private localCursor;
38
+ private lastAwarenessSentAt;
39
+ private cursorBroadcastTimer;
40
+ private heartbeatTimer;
41
+ private expiryTimer;
32
42
  constructor(replica: CollaborationReplica, transport: CollaborationTransport, options?: CollaborationProviderOptions);
33
43
  get status(): CollaborationStatus;
34
44
  get synced(): boolean;
35
45
  get pendingBytes(): number;
46
+ get peers(): readonly CollaborationPeer[];
47
+ setCursor(cursor: CollaborationCursor | null, broadcast?: boolean): void;
48
+ onPeers(listener: CollaborationPeerListener): () => void;
36
49
  connect(): void;
37
50
  disconnect(): void;
38
51
  destroy(): void;
@@ -48,6 +61,15 @@ declare class CollaborationProvider {
48
61
  private respondToSyncStep1;
49
62
  private applyRemoteUpdate;
50
63
  private forwardLocalUpdate;
64
+ private nextAwarenessClock;
65
+ private encodeLocalAwareness;
66
+ private broadcastLocalAwareness;
67
+ private scheduleCursorBroadcast;
68
+ private clearCursorBroadcastTimer;
69
+ private startPresence;
70
+ private stopPresence;
71
+ private sendLeaveBestEffort;
72
+ private emitPeers;
51
73
  private sendFrame;
52
74
  private queueFrame;
53
75
  private flushPending;
@@ -56,10 +78,12 @@ declare class CollaborationProvider {
56
78
  private report;
57
79
  }
58
80
 
81
+ declare function resolvePresenceColor(clientId: number, color: unknown): string;
82
+
59
83
  interface WorkerCollaborationTarget {
60
84
  invalidate(update: Uint8Array, selection: YrsSelection | null): void;
61
85
  }
62
86
  declare function createDirectCollaborationReplica(session: YrsSession): CollaborationReplica;
63
87
  declare function createWorkerCollaborationReplica(session: YrsSession, worker: WorkerCollaborationTarget): CollaborationReplica;
64
88
 
65
- export { CollaborationErrorListener, CollaborationProvider, CollaborationProviderOptions, CollaborationReplica, CollaborationStatus, CollaborationStatusListener, CollaborationTransport, type WorkerCollaborationTarget, createDirectCollaborationReplica, createWorkerCollaborationReplica };
89
+ export { CollaborationCursor, CollaborationErrorListener, CollaborationPeer, CollaborationPeerListener, CollaborationProvider, CollaborationProviderOptions, CollaborationReplica, CollaborationStatus, CollaborationStatusListener, CollaborationTransport, type WorkerCollaborationTarget, createDirectCollaborationReplica, createWorkerCollaborationReplica, resolvePresenceColor };
@@ -1 +1 @@
1
- import {b as b$1}from'../chunk-TTRUPDAB.mjs';var w=Number.MAX_SAFE_INTEGER,c=class extends Error{constructor(t){super(t),this.name="ProtocolError";}},b=class{constructor(t){b$1(this,"bytes",t);b$1(this,"offset",0);}get done(){return this.offset===this.bytes.byteLength}readVarUint(){let t=0,e=1,r=0;for(;;){if(this.offset>=this.bytes.byteLength)throw new c("Truncated varUint");let n=this.bytes[this.offset++],i=n&127;if(i>Math.floor((w-t)/e))throw new c("varUint exceeds Number.MAX_SAFE_INTEGER");if(t+=i*e,r+=1,(n&128)===0){if(r>1&&i===0)throw new c("Non-canonical varUint");return t}if(r>=8)throw new c("varUint exceeds Number.MAX_SAFE_INTEGER");e*=128;}}readVarUint8Array(){let t=this.readVarUint(),e=this.bytes.byteLength-this.offset;if(t>e)throw new c("Truncated varUint8Array");let r=this.bytes.slice(this.offset,this.offset+t);return this.offset+=t,r}readVarString(){let t=this.readVarUint8Array();try{return new TextDecoder("utf-8",{fatal:!0}).decode(t)}catch(e){throw new c(`Invalid UTF-8 string${e instanceof Error?`: ${e.message}`:""}`)}}};function u(o){if(!Number.isSafeInteger(o)||o<0)throw new c("varUint value must be a non-negative safe integer");let t=[],e=o;for(;e>=128;)t.push(e%128|128),e=Math.floor(e/128);return t.push(e),Uint8Array.from(t)}function C(o,t){let e=0;for(let i of o)if(e+=i.byteLength,e>t)throw new c(`Frame exceeds ${t} bytes`);let r=new Uint8Array(e),n=0;for(let i of o)r.set(i,n),n+=i.byteLength;return r}function f(o,t,e){return C([u(0),u(o),u(t.byteLength),t],e)}function A(o,t=16777216){return f(0,o,t)}function g(o,t=16777216){return f(1,o,t)}function U(o,t=16777216){return f(2,o,t)}function v(o=16777216){let t=Uint8Array.of(0);return C([u(1),u(t.byteLength),t],o)}function T(o,t=16777216,e=4096){if(!(o instanceof Uint8Array))throw new c("Frame must be a Uint8Array");if(o.byteLength===0)throw new c("Frame is empty");if(o.byteLength>t)throw new c(`Frame exceeds ${t} bytes`);if(!Number.isSafeInteger(e)||e<1)throw new c("Message limit must be a positive integer");let r=new b(o),n=[];for(;!r.done;){if(n.length>=e)throw new c(`Frame exceeds ${e} messages`);let i=r.readVarUint();switch(i){case 0:{let l=r.readVarUint(),y=r.readVarUint8Array();if(l===0)n.push({type:"sync-step-1",stateVector:y});else if(l===1)n.push({type:"sync-step-2",update:y});else if(l===2)n.push({type:"update",update:y});else throw new c(`Unknown sync message type ${l}`);break}case 1:n.push({type:"awareness",update:r.readVarUint8Array()});break;case 2:{let l=r.readVarUint();if(l!==0)throw new c(`Unknown auth message type ${l}`);n.push({type:"auth",reason:r.readVarString()});break}case 3:n.push({type:"query-awareness"});break;default:throw new c(`Unknown top-level message type ${i}`)}}return n}var p=class extends Error{constructor(e,r,n){super(r);b$1(this,"code");b$1(this,"cause");this.name="CollaborationError",this.code=e,this.cause=n;}};var L=16*1024*1024;function m(o,t,e){if(!Number.isSafeInteger(t)||t<(e?0:1))throw new RangeError(`${o} must be ${e?"a non-negative":"a positive"} integer`);return t}function x(o){return o instanceof Error&&o.message?o.message:typeof o=="string"&&o?o:"Unknown error"}function a(o,t,e){return e instanceof p?e:new p(o,`${t}: ${x(e)}`,e)}function E(o,t){if(!(o instanceof Uint8Array))throw new TypeError(`${t} must return a Uint8Array`);return o.slice()}var S=class{constructor(t,e,r={}){b$1(this,"replica");b$1(this,"transport");b$1(this,"maxFrameBytes");b$1(this,"maxMessagesPerFrame");b$1(this,"maxPendingBytes");b$1(this,"statusListeners",new Map);b$1(this,"errorListeners",new Map);b$1(this,"pendingFrames",[]);b$1(this,"unsubscribeReplica");b$1(this,"unsubscribeTransport",()=>{});b$1(this,"hasTransportSubscription",false);b$1(this,"connectionStatus","disconnected");b$1(this,"isSynced",false);b$1(this,"wantsConnection",false);b$1(this,"isOpen",false);b$1(this,"isDestroyed",false);b$1(this,"epoch",0);b$1(this,"connectAttempt",0);b$1(this,"nextListenerId",0);b$1(this,"queuedBytes",0);b$1(this,"isFlushing",false);this.replica=t,this.transport=e,this.maxFrameBytes=m("maxFrameBytes",r.maxFrameBytes??16777216,false),this.maxMessagesPerFrame=m("maxMessagesPerFrame",r.maxMessagesPerFrame??4096,false),this.maxPendingBytes=m("maxPendingBytes",r.maxPendingBytes??L,true);try{this.unsubscribeReplica=t.onUpdate((n,i)=>{i==="local"&&this.forwardLocalUpdate(n);});}catch(n){throw a("replica","Failed to observe replica updates",n)}}get status(){return this.connectionStatus}get synced(){return this.isSynced}get pendingBytes(){return this.queuedBytes}connect(){if(this.isDestroyed||this.isOpen||this.connectionStatus==="connecting")return;this.wantsConnection=true;let t=this.hasTransportSubscription?this.epoch:++this.epoch,e=++this.connectAttempt;if(this.setStatus("connecting",false),!!this.isCurrent(t)){if(!this.hasTransportSubscription){let r;try{if(r=this.transport.onEvent(n=>this.handleTransportEvent(t,n)),typeof r!="function")throw new TypeError("Transport event subscription must return a function")}catch(n){this.failConnection(t,a("transport","Failed to subscribe to transport events",n));return}if(!this.isCurrent(t)){try{r();}catch(n){this.isDestroyed||this.report(a("transport","Failed to unsubscribe from stale transport events",n));}return}this.unsubscribeTransport=r,this.hasTransportSubscription=true;}try{let r=this.transport.connect();r&&r.catch(n=>{this.isCurrent(t)&&this.connectAttempt===e&&this.failConnection(t,a("transport","Transport connect failed",n));});}catch(r){this.failConnection(t,a("transport","Transport connect failed",r));}}}disconnect(){if(this.isDestroyed||!(this.wantsConnection||this.isOpen||this.hasTransportSubscription||this.connectionStatus!=="disconnected"))return;this.wantsConnection=false,this.isOpen=false,this.epoch+=1,this.connectAttempt+=1;let e=this.takeTransportSubscription();this.clearPending();let r=this.cleanupTransport(e,true);this.setStatus("disconnected",false);for(let n of r)this.report(n);}destroy(){if(this.isDestroyed)return;let t=this.wantsConnection||this.isOpen||this.hasTransportSubscription||this.connectionStatus==="connecting"||this.connectionStatus==="connected";this.isDestroyed=true,this.wantsConnection=false,this.isOpen=false,this.epoch+=1,this.connectAttempt+=1;let e=this.takeTransportSubscription();this.clearPending();let r=this.cleanupTransport(e,t);this.setStatus("destroyed",false);for(let n of r)this.report(n);try{this.unsubscribeReplica();}catch(n){this.report(a("replica","Failed to unsubscribe from replica updates",n));}this.unsubscribeReplica=()=>{},this.statusListeners.clear(),this.errorListeners.clear();}onStatus(t){if(this.isDestroyed)return ()=>{};if(typeof t!="function")throw new TypeError("status listener must be a function");let e=this.nextListenerId++;return this.statusListeners.set(e,t),()=>this.statusListeners.delete(e)}onError(t){if(this.isDestroyed)return ()=>{};if(typeof t!="function")throw new TypeError("error listener must be a function");let e=this.nextListenerId++;return this.errorListeners.set(e,t),()=>this.errorListeners.delete(e)}isCurrent(t){return !this.isDestroyed&&this.wantsConnection&&t===this.epoch}failConnection(t,e){if(!this.isCurrent(t))return;this.wantsConnection=false,this.isOpen=false,this.epoch+=1,this.connectAttempt+=1;let r=this.takeTransportSubscription();this.clearPending();let n=this.cleanupTransport(r,true);this.setStatus("disconnected",false),this.report(e);for(let i of n)this.report(i);}takeTransportSubscription(){let t=this.unsubscribeTransport;return this.unsubscribeTransport=()=>{},this.hasTransportSubscription=false,t}cleanupTransport(t,e){let r=[];try{t();}catch(n){r.push(a("transport","Failed to unsubscribe from transport events",n));}if(!e)return r;try{let n=this.transport.disconnect();n&&n.catch(i=>{this.isDestroyed||this.report(a("transport","Transport disconnect failed",i));});}catch(n){r.push(a("transport","Transport disconnect failed",n));}return r}handleTransportEvent(t,e){if(this.isCurrent(t))switch(e.type){case "open":this.handleOpen(t);break;case "message":this.isOpen&&this.handleMessage(t,e.data);break;case "close":this.isOpen=false,this.connectAttempt+=1,this.clearPending(),this.setStatus("disconnected",false);break;case "error":this.failConnection(t,a("transport","Transport error",e.error));break;case "drain":this.isOpen&&this.flushPending();break;default:this.failConnection(t,new p("transport","Unknown transport event"));}}handleOpen(t){if(this.isOpen||(this.isOpen=true,this.clearPending(),this.setStatus("connected",false),!this.isCurrent(t)||!this.isOpen))return;let e;try{e=E(this.replica.encodeStateVector(),"encodeStateVector");}catch(r){this.failConnection(t,a("replica","Failed to encode replica state vector",r));return}try{this.sendFrame(A(e,this.maxFrameBytes));}catch(r){this.failConnection(t,a("protocol","Failed to encode SyncStep1",r));}}handleMessage(t,e){let r;try{r=T(e.slice(),this.maxFrameBytes,this.maxMessagesPerFrame);}catch(n){this.failConnection(t,a("protocol","Invalid collaboration frame",n));return}for(let n of r){if(!this.isCurrent(t)||!this.isOpen)return;switch(n.type){case "sync-step-1":this.respondToSyncStep1(t,n.stateVector);break;case "sync-step-2":this.applyRemoteUpdate(t,n.update)&&this.isCurrent(t)&&this.setStatus("connected",true);break;case "update":this.applyRemoteUpdate(t,n.update);break;case "awareness":break;case "auth":this.failConnection(t,new p("protocol",n.reason?`Authentication denied: ${n.reason}`:"Authentication denied"));return;case "query-awareness":try{this.sendFrame(v(this.maxFrameBytes));}catch(i){this.failConnection(t,a("protocol","Failed to encode awareness response",i));return}break}}}respondToSyncStep1(t,e){let r;try{r=E(this.replica.encodeStateAsUpdate(e.slice()),"encodeStateAsUpdate");}catch(n){this.failConnection(t,a("replica","Failed to encode replica update",n));return}try{this.sendFrame(g(r,this.maxFrameBytes));}catch(n){this.failConnection(t,a("protocol","Failed to encode SyncStep2",n));}}applyRemoteUpdate(t,e){try{return this.replica.applyUpdate(e.slice()),!0}catch(r){return this.failConnection(t,a("replica","Failed to apply remote update",r)),false}}forwardLocalUpdate(t){if(this.isDestroyed||!this.isOpen||!this.wantsConnection)return;let e=this.epoch,r;try{r=E(t,"Replica update");}catch(n){this.failConnection(e,a("replica","Invalid replica update",n));return}try{this.sendFrame(U(r,this.maxFrameBytes));}catch(n){this.failConnection(e,a("protocol","Failed to encode update",n));}}sendFrame(t){if(!this.isOpen||this.isDestroyed||!this.wantsConnection)return;let e=this.epoch;if(this.pendingFrames.length>0){this.queueFrame(e,t);return}let r;try{r=this.transport.send(t.slice());}catch(n){this.failConnection(e,a("transport","Transport send failed",n));return}if(typeof r!="boolean"){this.failConnection(e,new p("transport","Transport send must return a boolean"));return}!r&&this.isCurrent(e)&&this.isOpen&&this.queueFrame(e,t);}queueFrame(t,e){if(e.byteLength>this.maxPendingBytes-this.queuedBytes){this.failConnection(t,new p("backpressure",`Pending collaboration data exceeds ${this.maxPendingBytes} bytes`));return}let r=e.slice();this.pendingFrames.push(r),this.queuedBytes+=r.byteLength;}flushPending(){if(!this.isFlushing){this.isFlushing=true;try{for(;this.isOpen&&!this.isDestroyed&&this.pendingFrames.length>0;){let t=this.epoch,e=this.pendingFrames[0],r;try{r=this.transport.send(e.slice());}catch(n){this.failConnection(t,a("transport","Transport send failed",n));return}if(typeof r!="boolean"){this.failConnection(t,new p("transport","Transport send must return a boolean"));return}if(!r||!this.isOpen||this.pendingFrames[0]!==e)return;this.pendingFrames.shift(),this.queuedBytes-=e.byteLength;}}finally{this.isFlushing=false;}}}clearPending(){this.pendingFrames.length=0,this.queuedBytes=0;}setStatus(t,e){if(this.connectionStatus===t&&this.isSynced===e)return;this.connectionStatus=t,this.isSynced=e;let r={status:t,synced:e};for(let[n,i]of [...this.statusListeners])if(this.statusListeners.get(n)===i)try{i(r);}catch{}}report(t){for(let[e,r]of [...this.errorListeners])if(this.errorListeners.get(e)===r)try{r(t);}catch{}}};function P(o){return o}function M(o,t){return {clientId:o.clientId,encodeStateVector:()=>o.encodeStateVector(),encodeStateAsUpdate:e=>o.encodeStateAsUpdate(e?.slice()),applyUpdate:e=>{let r=e.slice();o.applyUpdate(r),t.invalidate(r,o.selection());},onUpdate:e=>o.onUpdate(e)}}export{p as CollaborationError,S as CollaborationProvider,P as createDirectCollaborationReplica,M as createWorkerCollaborationReplica};
1
+ import {b as b$1}from'../chunk-TTRUPDAB.mjs';var B=["#0B57D0","#B3261E","#137333","#7B1FA2","#A142F4","#A04B00","#006A6A","#455A64"],oe=/^#[0-9a-fA-F]{3}(?:[0-9a-fA-F]{3})?$/;function S(r,e){if(typeof e=="string"&&oe.test(e))return e;let t=Number.isSafeInteger(r)&&r>=0?r%B.length:0;return B[t]}function D(r,e){return r.byteLength===e.byteLength&&r.every((t,n)=>t===e[n])}function ae(r,e){return r===e||!!(r&&e&&r.story===e.story&&D(r.anchor,e.anchor)&&D(r.head,e.head))}function ie(r,e){return r?.clientId===e.clientId&&r.story===e.story&&r.paraId===e.paraId&&r.endOffset===e.endOffset}function V(r){return r?{story:r.story,anchor:r.anchor.slice(),head:r.head.slice()}:null}function ce(r){return r?{user:{...r.user},cursor:V(r.cursor)}:null}function X(r,e,t,n){let s=r,o=false;for(let a of e){if(a.clientId===t)continue;let u=s.get(a.clientId);if(!u&&s.size>=1024)continue;if(u&&a.clock<=u.clock){a.clock===u.clock&&n>u.lastSeenAt&&(s===r&&(s=new Map(r)),s.set(a.clientId,{...u,lastSeenAt:n}));continue}s===r&&(s=new Map(r));let h=a.state?.cursor!=null&&(u?.inferredCursor!=null||u?.state==null||!ae(u.state.cursor,a.state.cursor));s.set(a.clientId,{clientId:a.clientId,clock:a.clock,state:ce(a.state),lastSeenAt:n,cursorMovedAt:h?n:u?.cursorMovedAt??0,inferredCursor:null}),o=true;}return {records:s,peersChanged:o}}function $(r,e,t,n){if(e.clientId===t)return {records:r,peersChanged:false};let s=r.get(e.clientId);if(!s&&r.size>=1024)return {records:r,peersChanged:false};let o=new Map(r);return o.set(e.clientId,{clientId:e.clientId,clock:s?.clock??-1,state:s?.state??null,lastSeenAt:s?.lastSeenAt??n,cursorMovedAt:ie(s?.inferredCursor??null,e)?s?.cursorMovedAt??n:n,inferredCursor:{...e}}),{records:o,peersChanged:s?.state!=null}}function Y(r,e,t){let n=r,s=false;for(let[o,a]of r)e-a.lastSeenAt<t||(n===r&&(n=new Map(r)),n.delete(o),a.state&&(s=true));return {records:n,peersChanged:s}}function I(r){let e=[];for(let t of r.values()){if(!t.state)continue;let n={clientId:t.clientId,clock:t.clock,user:{...t.state.user},cursor:V(t.state.cursor)};e.push({...n,lastSeenAt:t.lastSeenAt,cursorMovedAt:t.cursorMovedAt,inferredCursor:t.inferredCursor?{...t.inferredCursor}:null});}return e.sort((t,n)=>t.clientId-n.clientId),e}var b=16777216,_=4096,q=0,j=1,ue=2,H=3,z=0,K=1,J=2,de=0,pe=Number.MAX_SAFE_INTEGER,c=class extends Error{constructor(e){super(e),this.name="ProtocolError";}},f=class extends c{},U=class{constructor(e){b$1(this,"bytes",e);b$1(this,"offset",0);}get done(){return this.offset===this.bytes.byteLength}readVarUint(){let e=0,t=1,n=0;for(;;){if(this.offset>=this.bytes.byteLength)throw new c("Truncated varUint");let s=this.bytes[this.offset++],o=s&127;if(o>Math.floor((pe-e)/t))throw new c("varUint exceeds Number.MAX_SAFE_INTEGER");if(e+=o*t,n+=1,(s&128)===0){if(n>1&&o===0)throw new c("Non-canonical varUint");return e}if(n>=8)throw new c("varUint exceeds Number.MAX_SAFE_INTEGER");t*=128;}}readVarUint8Array(){let e=this.readVarUint(),t=this.bytes.byteLength-this.offset;if(e>t)throw new c("Truncated varUint8Array");let n=this.bytes.slice(this.offset,this.offset+e);return this.offset+=e,n}skipVarUint8Array(){let e=this.readVarUint(),t=this.bytes.byteLength-this.offset;if(e>t)throw new c("Truncated varUint8Array");this.offset+=e;}readVarString(){let e=this.readVarUint8Array();try{return new TextDecoder("utf-8",{fatal:!0}).decode(e)}catch(t){throw new c(`Invalid UTF-8 string${t instanceof Error?`: ${t.message}`:""}`)}}};function p(r){if(!Number.isSafeInteger(r)||r<0)throw new c("varUint value must be a non-negative safe integer");let e=[],t=r;for(;t>=128;)e.push(t%128|128),t=Math.floor(t/128);return e.push(t),Uint8Array.from(e)}function g(r,e){let t=0;for(let o of r)if(t+=o.byteLength,t>e)throw new c(`Frame exceeds ${e} bytes`);let n=new Uint8Array(t),s=0;for(let o of r)n.set(o,s),s+=o.byteLength;return n}function he(r){let e=new TextEncoder().encode(r);return g([p(e.byteLength),e],Number.MAX_SAFE_INTEGER)}function P(r,e,t){return g([p(q),p(r),p(e.byteLength),e],t)}function Q(r,e=b){return P(z,r,e)}function Z(r,e=b){return P(K,r,e)}function ee(r,e=b){return P(J,r,e)}function ye(r){return r.state===null?"null":JSON.stringify({user:r.state.user,cursor:r.state.cursor?{story:r.state.cursor.story,anchor:[...r.state.cursor.anchor],head:[...r.state.cursor.head]}:null})}function fe(r){let e=[p(r.length)];for(let t of r)e.push(p(t.clientId),p(t.clock),he(ye(t)));return g(e,Number.MAX_SAFE_INTEGER)}function R(r,e=b){let t=fe(r);return g([p(j),p(t.byteLength),t],e)}function L(r=b){return g([p(H)],r)}function G(r,e){if(!Array.isArray(r))throw new c(`${e} must be a byte array`);if(r.length>1024)throw new f(`${e} exceeds ${1024} bytes`);if(r.some(t=>!Number.isInteger(t)||t<0||t>255))throw new c(`${e} must be a byte array`);return Uint8Array.from(r)}function be(r,e){let t;try{t=JSON.parse(r);}catch{throw new c("Invalid awareness JSON")}if(t===null)return null;if(typeof t!="object"||Array.isArray(t))throw new c("Awareness state must be an object or null");let n=t,s=n.user;if(typeof s!="object"||s===null||Array.isArray(s))throw new c("Awareness user must be an object");let o=s;if(typeof o.name!="string")throw new c("Awareness user requires a string name");if(o.name.length>1024)throw new f(`Awareness user name exceeds ${1024} characters`);let a={name:o.name,color:S(e,o.color)},u=n.cursor;if(u==null)return {user:a,cursor:null};if(typeof u!="object"||Array.isArray(u))throw new c("Awareness cursor must be an object or null");let h=u;if(typeof h.story!="string")throw new c("Awareness cursor requires a string story");if(h.story.length>1024)throw new f(`Awareness cursor story exceeds ${1024} characters`);return {user:a,cursor:{story:h.story,anchor:G(h.anchor,"Awareness cursor anchor"),head:G(h.head,"Awareness cursor head")}}}function te(r,e={}){let t=new U(r),n=t.readVarUint();if(n>r.byteLength)throw new c("Invalid awareness entry count");let s=new Set(e.trackedClientIds);e.localClientId!==void 0&&s.delete(e.localClientId);let o=new Set,a=m=>{o.has(m.message)||(o.add(m.message),e.onDiscard?.(m));};n>1024&&a(new f(`Awareness update exceeds ${1024} entries`));let u=[],h=Math.min(n,1024);for(let m=0;m<h;m+=1){let A=t.readVarUint(),ne=t.readVarUint();if(!(A===e.localClientId||s.has(A))&&s.size>=1024){t.skipVarUint8Array(),a(new f(`Awareness peer limit of ${1024} reached`));continue}let se=t.readVarString(),O;try{O=be(se,A);}catch(x){if(!(x instanceof f))throw x;a(x);continue}u.push({clientId:A,clock:ne,state:O}),A!==e.localClientId&&s.add(A);}if(n<=1024&&!t.done)throw new c("Trailing awareness data");return u}function re(r,e=b,t=_){if(!(r instanceof Uint8Array))throw new c("Frame must be a Uint8Array");if(r.byteLength===0)throw new c("Frame is empty");if(r.byteLength>e)throw new c(`Frame exceeds ${e} bytes`);if(!Number.isSafeInteger(t)||t<1)throw new c("Message limit must be a positive integer");let n=new U(r),s=[];for(;!n.done;){if(s.length>=t)throw new c(`Frame exceeds ${t} messages`);let o=n.readVarUint();switch(o){case q:{let a=n.readVarUint(),u=n.readVarUint8Array();if(a===z)s.push({type:"sync-step-1",stateVector:u});else if(a===K)s.push({type:"sync-step-2",update:u});else if(a===J)s.push({type:"update",update:u});else throw new c(`Unknown sync message type ${a}`);break}case j:s.push({type:"awareness",update:n.readVarUint8Array()});break;case ue:{let a=n.readVarUint();if(a!==de)throw new c(`Unknown auth message type ${a}`);s.push({type:"auth",reason:n.readVarString()});break}case H:s.push({type:"query-awareness"});break;default:throw new c(`Unknown top-level message type ${o}`)}}return s}var d=class extends Error{constructor(t,n,s){super(n);b$1(this,"code");b$1(this,"cause");this.name="CollaborationError",this.code=t,this.cause=s;}};var me=16*1024*1024,Ae=80,Ce=2e4,we=45e3,Ee=5e3;function F(r,e,t){if(!Number.isSafeInteger(e)||e<(t?0:1))throw new RangeError(`${r} must be ${t?"a non-negative":"a positive"} integer`);return e}function Se(r){return r instanceof Error&&r.message?r.message:typeof r=="string"&&r?r:"Unknown error"}function l(r,e,t){return t instanceof d?t:new d(r,`${e}: ${Se(t)}`,t)}function M(r,e){if(!(r instanceof Uint8Array))throw new TypeError(`${e} must return a Uint8Array`);return r.slice()}function v(){return globalThis.performance?.now?.()??Date.now()}function k(r){r.unref?.();}function ge(r,e){if(!r)return null;if(!Number.isSafeInteger(e)||e<0)throw new RangeError("clientId must be a non-negative safe integer for awareness");if(typeof r.name!="string"||r.name.trim().length===0)throw new TypeError("user.name must be a non-empty string");return {name:r.name.trim().slice(0,1024),color:S(e,r.color)}}function ve(r){if(r===null)return null;if(typeof r.story!="string"||!r.story||!(r.anchor instanceof Uint8Array)||!(r.head instanceof Uint8Array))throw new TypeError("cursor requires a story and Uint8Array anchor/head");return {story:r.story,anchor:r.anchor.slice(),head:r.head.slice()}}function Te(r){return r.story.length<=1024&&r.anchor.byteLength<=1024&&r.head.byteLength<=1024}function Ue(r){if(typeof r!="object"||r===null)return null;let e=r;return !Number.isSafeInteger(e.clientId)||(e.clientId??-1)<0||typeof e.story!="string"||typeof e.paraId!="string"||!Number.isSafeInteger(e.endOffset)||(e.endOffset??-1)<0?null:{clientId:e.clientId,story:e.story,paraId:e.paraId,endOffset:e.endOffset}}var N=class{constructor(e,t,n={}){b$1(this,"replica");b$1(this,"transport");b$1(this,"maxFrameBytes");b$1(this,"maxMessagesPerFrame");b$1(this,"maxPendingBytes");b$1(this,"localUser");b$1(this,"statusListeners",new Map);b$1(this,"errorListeners",new Map);b$1(this,"peerListeners",new Map);b$1(this,"pendingFrames",[]);b$1(this,"awarenessRecords",new Map);b$1(this,"unsubscribeReplica");b$1(this,"unsubscribeTransport",()=>{});b$1(this,"hasTransportSubscription",false);b$1(this,"connectionStatus","disconnected");b$1(this,"isSynced",false);b$1(this,"wantsConnection",false);b$1(this,"isOpen",false);b$1(this,"isDestroyed",false);b$1(this,"epoch",0);b$1(this,"connectAttempt",0);b$1(this,"nextListenerId",0);b$1(this,"queuedBytes",0);b$1(this,"isFlushing",false);b$1(this,"localClock",0);b$1(this,"reportedClockExhaustion",false);b$1(this,"localCursor",null);b$1(this,"lastAwarenessSentAt",Number.NEGATIVE_INFINITY);b$1(this,"cursorBroadcastTimer",null);b$1(this,"heartbeatTimer",null);b$1(this,"expiryTimer",null);this.replica=e,this.transport=t,this.maxFrameBytes=F("maxFrameBytes",n.maxFrameBytes??b,false),this.maxMessagesPerFrame=F("maxMessagesPerFrame",n.maxMessagesPerFrame??_,false),this.maxPendingBytes=F("maxPendingBytes",n.maxPendingBytes??me,true),this.localUser=ge(n.user,e.clientId);try{this.unsubscribeReplica=e.onUpdate((s,o)=>{o==="local"&&this.forwardLocalUpdate(s);});}catch(s){throw l("replica","Failed to observe replica updates",s)}}get status(){return this.connectionStatus}get synced(){return this.isSynced}get pendingBytes(){return this.queuedBytes}get peers(){return I(this.awarenessRecords)}setCursor(e,t=true){if(this.isDestroyed||!this.localUser)return;let n=ve(e);if(this.localCursor=!n||Te(n)?n:null,n&&!this.localCursor&&this.report(new d("protocol",`Presence cursor exceeds ${1024} story characters or ${1024} position bytes; cursor dropped`)),!t){this.clearCursorBroadcastTimer();return}this.scheduleCursorBroadcast();}onPeers(e){if(this.isDestroyed)return ()=>{};if(typeof e!="function")throw new TypeError("peer listener must be a function");let t=this.nextListenerId++;return this.peerListeners.set(t,e),e(this.peers),()=>this.peerListeners.delete(t)}connect(){if(this.isDestroyed||this.isOpen||this.connectionStatus==="connecting")return;this.wantsConnection=true;let e=this.hasTransportSubscription?this.epoch:++this.epoch,t=++this.connectAttempt;if(this.setStatus("connecting",false),!!this.isCurrent(e)){if(!this.hasTransportSubscription){let n;try{if(n=this.transport.onEvent(s=>this.handleTransportEvent(e,s)),typeof n!="function")throw new TypeError("Transport event subscription must return a function")}catch(s){this.failConnection(e,l("transport","Failed to subscribe to transport events",s));return}if(!this.isCurrent(e)){try{n();}catch(s){this.isDestroyed||this.report(l("transport","Failed to unsubscribe from stale transport events",s));}return}this.unsubscribeTransport=n,this.hasTransportSubscription=true;}try{let n=this.transport.connect();n&&n.catch(s=>{this.isCurrent(e)&&this.connectAttempt===t&&this.failConnection(e,l("transport","Transport connect failed",s));});}catch(n){this.failConnection(e,l("transport","Transport connect failed",n));}}}disconnect(){if(this.isDestroyed||!(this.wantsConnection||this.isOpen||this.hasTransportSubscription||this.connectionStatus!=="disconnected"))return;this.sendLeaveBestEffort(),this.stopPresence(),this.wantsConnection=false,this.isOpen=false,this.epoch+=1,this.connectAttempt+=1;let t=this.takeTransportSubscription();this.clearPending();let n=this.cleanupTransport(t,true);this.setStatus("disconnected",false);for(let s of n)this.report(s);}destroy(){if(this.isDestroyed)return;let e=this.wantsConnection||this.isOpen||this.hasTransportSubscription||this.connectionStatus==="connecting"||this.connectionStatus==="connected";this.sendLeaveBestEffort(),this.stopPresence(),this.isDestroyed=true,this.wantsConnection=false,this.isOpen=false,this.epoch+=1,this.connectAttempt+=1;let t=this.takeTransportSubscription();this.clearPending();let n=this.cleanupTransport(t,e);this.setStatus("destroyed",false);for(let s of n)this.report(s);try{this.unsubscribeReplica();}catch(s){this.report(l("replica","Failed to unsubscribe from replica updates",s));}this.unsubscribeReplica=()=>{},this.statusListeners.clear(),this.errorListeners.clear(),this.peerListeners.clear();}onStatus(e){if(this.isDestroyed)return ()=>{};if(typeof e!="function")throw new TypeError("status listener must be a function");let t=this.nextListenerId++;return this.statusListeners.set(t,e),()=>this.statusListeners.delete(t)}onError(e){if(this.isDestroyed)return ()=>{};if(typeof e!="function")throw new TypeError("error listener must be a function");let t=this.nextListenerId++;return this.errorListeners.set(t,e),()=>this.errorListeners.delete(t)}isCurrent(e){return !this.isDestroyed&&this.wantsConnection&&e===this.epoch}failConnection(e,t){if(!this.isCurrent(e))return;this.stopPresence(),this.wantsConnection=false,this.isOpen=false,this.epoch+=1,this.connectAttempt+=1;let n=this.takeTransportSubscription();this.clearPending();let s=this.cleanupTransport(n,true);this.setStatus("disconnected",false),this.report(t);for(let o of s)this.report(o);}takeTransportSubscription(){let e=this.unsubscribeTransport;return this.unsubscribeTransport=()=>{},this.hasTransportSubscription=false,e}cleanupTransport(e,t){let n=[];try{e();}catch(s){n.push(l("transport","Failed to unsubscribe from transport events",s));}if(!t)return n;try{let s=this.transport.disconnect();s&&s.catch(o=>{this.isDestroyed||this.report(l("transport","Transport disconnect failed",o));});}catch(s){n.push(l("transport","Transport disconnect failed",s));}return n}handleTransportEvent(e,t){if(this.isCurrent(e))switch(t.type){case "open":this.handleOpen(e);break;case "message":this.isOpen&&this.handleMessage(e,t.data);break;case "close":this.isOpen=false,this.connectAttempt+=1,this.stopPresence(),this.clearPending(),this.setStatus("disconnected",false);break;case "error":this.failConnection(e,l("transport","Transport error",t.error));break;case "drain":this.isOpen&&this.flushPending();break;default:this.failConnection(e,new d("transport","Unknown transport event"));}}handleOpen(e){if(this.isOpen||(this.isOpen=true,this.clearPending(),this.setStatus("connected",false),!this.isCurrent(e)||!this.isOpen))return;let t;try{t=M(this.replica.encodeStateVector(),"encodeStateVector");}catch(n){this.failConnection(e,l("replica","Failed to encode replica state vector",n));return}try{this.sendFrame(Q(t,this.maxFrameBytes));}catch(n){this.failConnection(e,l("protocol","Failed to encode collaboration handshake",n));return}if(!(!this.localUser||!this.isCurrent(e)||!this.isOpen)){try{this.sendFrame(L(this.maxFrameBytes));}catch(n){this.report(l("protocol","Failed to encode awareness query",n));}!this.isCurrent(e)||!this.isOpen||(this.broadcastLocalAwareness(),!(!this.isCurrent(e)||!this.isOpen)&&this.startPresence());}}handleMessage(e,t){let n;try{n=re(t.slice(),this.maxFrameBytes,this.maxMessagesPerFrame);}catch(s){this.failConnection(e,l("protocol","Invalid collaboration frame",s));return}for(let s of n){if(!this.isCurrent(e)||!this.isOpen)return;switch(s.type){case "sync-step-1":this.respondToSyncStep1(e,s.stateVector);break;case "sync-step-2":if(this.applyRemoteUpdate(e,s.update,false)&&this.isCurrent(e)&&(this.setStatus("connected",true),this.localUser))try{this.sendFrame(L(this.maxFrameBytes));}catch(o){this.report(l("protocol","Failed to query awareness after sync",o));}break;case "update":this.applyRemoteUpdate(e,s.update,true);break;case "awareness":{let o=[];try{let a=X(this.awarenessRecords,te(s.update,{trackedClientIds:this.awarenessRecords.keys(),localClientId:this.replica.clientId,onDiscard:u=>o.push(u)}),this.replica.clientId,v());this.awarenessRecords=a.records,a.peersChanged&&this.emitPeers();}catch(a){this.report(l("protocol","Failed to apply awareness update",a));}for(let a of o)this.report(l("protocol","Discarded over-limit awareness data",a));break}case "auth":this.failConnection(e,new d("protocol",s.reason?`Authentication denied: ${s.reason}`:"Authentication denied"));return;case "query-awareness":try{this.localUser?this.broadcastLocalAwareness():this.sendFrame(R([],this.maxFrameBytes));}catch(o){this.report(l("protocol","Failed to encode awareness response",o));}break}}}respondToSyncStep1(e,t){let n;try{n=M(this.replica.encodeStateAsUpdate(t.slice()),"encodeStateAsUpdate");}catch(s){this.failConnection(e,l("replica","Failed to encode replica update",s));return}try{this.sendFrame(Z(n,this.maxFrameBytes));}catch(s){this.failConnection(e,l("protocol","Failed to encode SyncStep2",s));}}applyRemoteUpdate(e,t,n){try{let s=this.replica.applyUpdate(t.slice()),o=n?Ue(s):null;if(o){let a=$(this.awarenessRecords,o,this.replica.clientId,v());this.awarenessRecords=a.records,a.peersChanged&&this.emitPeers();}return !0}catch(s){return this.failConnection(e,l("replica","Failed to apply remote update",s)),false}}forwardLocalUpdate(e){if(this.isDestroyed||!this.isOpen||!this.wantsConnection)return;let t=this.epoch,n;try{n=M(e,"Replica update");}catch(s){this.failConnection(t,l("replica","Invalid replica update",s));return}try{this.sendFrame(ee(n,this.maxFrameBytes));}catch(s){this.failConnection(t,l("protocol","Failed to encode update",s));}}nextAwarenessClock(){if(this.localClock>=Number.MAX_SAFE_INTEGER)throw new RangeError("Awareness clock exceeds Number.MAX_SAFE_INTEGER");return this.localClock+=1,this.localClock}encodeLocalAwareness(e,t,n){return R([{clientId:this.replica.clientId,clock:t,state:{user:e,cursor:n}}],this.maxFrameBytes)}broadcastLocalAwareness(){if(!this.localUser||!this.isOpen||this.isDestroyed||!this.wantsConnection)return;if(this.clearCursorBroadcastTimer(),this.localClock>=Number.MAX_SAFE_INTEGER){this.reportedClockExhaustion||(this.reportedClockExhaustion=true,this.report(new d("protocol","Awareness clock exceeds Number.MAX_SAFE_INTEGER")));return}let e=this.localUser,t=this.nextAwarenessClock(),n;try{n=this.encodeLocalAwareness(e,t,this.localCursor);}catch(s){let o=this.localCursor;if(this.localCursor=null,!o){this.report(l("protocol","Failed to encode local awareness",s));return}try{n=this.encodeLocalAwareness(e,t,null);}catch(a){this.report(l("protocol","Failed to encode local awareness",a));return}this.report(l("protocol","Dropped an unencodable presence cursor",s));}this.sendFrame(n),this.lastAwarenessSentAt=v();}scheduleCursorBroadcast(){if(!this.localUser||!this.isOpen||this.isDestroyed||!this.wantsConnection)return;let e=Ae-(v()-this.lastAwarenessSentAt);if(e<=0){this.broadcastLocalAwareness();return}this.cursorBroadcastTimer||(this.cursorBroadcastTimer=setTimeout(()=>{this.cursorBroadcastTimer=null,!(!this.isOpen||this.isDestroyed||!this.wantsConnection)&&this.broadcastLocalAwareness();},e),k(this.cursorBroadcastTimer));}clearCursorBroadcastTimer(){this.cursorBroadcastTimer&&clearTimeout(this.cursorBroadcastTimer),this.cursorBroadcastTimer=null;}startPresence(){!this.localUser||!this.isOpen||this.isDestroyed||!this.wantsConnection||this.heartbeatTimer||this.expiryTimer||(this.heartbeatTimer=setInterval(()=>{this.broadcastLocalAwareness();},Ce),this.expiryTimer=setInterval(()=>{let e=Y(this.awarenessRecords,v(),we);this.awarenessRecords=e.records,e.peersChanged&&this.emitPeers();},Ee),k(this.heartbeatTimer),k(this.expiryTimer));}stopPresence(){this.clearCursorBroadcastTimer(),this.heartbeatTimer&&clearInterval(this.heartbeatTimer),this.expiryTimer&&clearInterval(this.expiryTimer),this.heartbeatTimer=null,this.expiryTimer=null;let e=I(this.awarenessRecords).length>0;this.awarenessRecords=new Map,e&&this.emitPeers();}sendLeaveBestEffort(){if(!(!this.localUser||!this.isOpen||this.isDestroyed||!this.wantsConnection)){this.clearCursorBroadcastTimer();try{let e=R([{clientId:this.replica.clientId,clock:this.nextAwarenessClock(),state:null}],this.maxFrameBytes);this.transport.send(e.slice());}catch(e){this.report(l("transport","Failed to send awareness leave",e));}}}emitPeers(){let e=this.peers;for(let[t,n]of [...this.peerListeners])if(this.peerListeners.get(t)===n)try{n(e);}catch{}}sendFrame(e){if(!this.isOpen||this.isDestroyed||!this.wantsConnection)return;let t=this.epoch;if(this.pendingFrames.length>0){this.queueFrame(t,e);return}let n;try{n=this.transport.send(e.slice());}catch(s){this.failConnection(t,l("transport","Transport send failed",s));return}if(typeof n!="boolean"){this.failConnection(t,new d("transport","Transport send must return a boolean"));return}!n&&this.isCurrent(t)&&this.isOpen&&this.queueFrame(t,e);}queueFrame(e,t){if(t.byteLength>this.maxPendingBytes-this.queuedBytes){this.failConnection(e,new d("backpressure",`Pending collaboration data exceeds ${this.maxPendingBytes} bytes`));return}let n=t.slice();this.pendingFrames.push(n),this.queuedBytes+=n.byteLength;}flushPending(){if(!this.isFlushing){this.isFlushing=true;try{for(;this.isOpen&&!this.isDestroyed&&this.pendingFrames.length>0;){let e=this.epoch,t=this.pendingFrames[0],n;try{n=this.transport.send(t.slice());}catch(s){this.failConnection(e,l("transport","Transport send failed",s));return}if(typeof n!="boolean"){this.failConnection(e,new d("transport","Transport send must return a boolean"));return}if(!n||!this.isOpen||this.pendingFrames[0]!==t)return;this.pendingFrames.shift(),this.queuedBytes-=t.byteLength;}}finally{this.isFlushing=false;}}}clearPending(){this.pendingFrames.length=0,this.queuedBytes=0;}setStatus(e,t){if(this.connectionStatus===e&&this.isSynced===t)return;this.connectionStatus=e,this.isSynced=t;let n={status:e,synced:t};for(let[s,o]of [...this.statusListeners])if(this.statusListeners.get(s)===o)try{o(n);}catch{}}report(e){for(let[t,n]of [...this.errorListeners])if(this.errorListeners.get(t)===n)try{n(e);}catch{}}};function Re(r){return r}function xe(r,e){return {clientId:r.clientId,encodeStateVector:()=>r.encodeStateVector(),encodeStateAsUpdate:t=>r.encodeStateAsUpdate(t?.slice()),applyUpdate:t=>{let n=t.slice();r.applyUpdate(n),e.invalidate(n,r.selection());},onUpdate:t=>r.onUpdate(t)}}export{d as CollaborationError,N as CollaborationProvider,Re as createDirectCollaborationReplica,xe as createWorkerCollaborationReplica,S as resolvePresenceColor};