wordinweb 0.1.18 → 0.1.20

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.
@@ -0,0 +1,38 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
+ }) : x)(function(x) {
10
+ if (typeof require !== "undefined") return require.apply(this, arguments);
11
+ throw Error('Dynamic require of "' + x + '" is not supported');
12
+ });
13
+ var __commonJS = (cb, mod) => function __require2() {
14
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
+ // If the importer is in node compatibility mode or this is not an ESM
26
+ // file that has been converted to a CommonJS file using a Babel-
27
+ // compatible transform (i.e. "__esModule" has not been set), then set
28
+ // "default" to the CommonJS "module.exports" for node compatibility.
29
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30
+ mod
31
+ ));
32
+
33
+ export {
34
+ __require,
35
+ __commonJS,
36
+ __toESM
37
+ };
38
+ //# sourceMappingURL=chunk-7D4SUZUM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/dist/index.js CHANGED
@@ -1,34 +1,8 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
- }) : x)(function(x) {
10
- if (typeof require !== "undefined") return require.apply(this, arguments);
11
- throw Error('Dynamic require of "' + x + '" is not supported');
12
- });
13
- var __commonJS = (cb, mod2) => function __require2() {
14
- return mod2 || (0, cb[__getOwnPropNames(cb)[0]])((mod2 = { exports: {} }).exports, mod2), mod2.exports;
15
- };
16
- var __copyProps = (to, from, except, desc) => {
17
- if (from && typeof from === "object" || typeof from === "function") {
18
- for (let key of __getOwnPropNames(from))
19
- if (!__hasOwnProp.call(to, key) && key !== except)
20
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
- }
22
- return to;
23
- };
24
- var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __copyProps(
25
- // If the importer is in node compatibility mode or this is not an ESM
26
- // file that has been converted to a CommonJS file using a Babel-
27
- // compatible transform (i.e. "__esModule" has not been set), then set
28
- // "default" to the CommonJS "module.exports" for node compatibility.
29
- isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
30
- mod2
31
- ));
1
+ import {
2
+ __commonJS,
3
+ __require,
4
+ __toESM
5
+ } from "./chunk-7D4SUZUM.js";
32
6
 
33
7
  // (disabled):fs
34
8
  var require_fs = __commonJS({
@@ -17440,9 +17414,6 @@ function firstText(el16) {
17440
17414
  return void 0;
17441
17415
  }
17442
17416
 
17443
- // ../core/src/render/dom.ts
17444
- import { convertEmfToDataUrl } from "emf-converter";
17445
-
17446
17417
  // ../core/src/render/tiff.ts
17447
17418
  var TYPE_SIZE = { 1: 1, 2: 1, 3: 2, 4: 4, 5: 8, 6: 1, 7: 1, 8: 2, 9: 4, 10: 8 };
17448
17419
  function decodeTiff(bytes) {
@@ -17650,194 +17621,6 @@ function packBits(input, expected) {
17650
17621
  return out;
17651
17622
  }
17652
17623
 
17653
- // ../core/src/render/wmf.ts
17654
- import * as WmfModule from "wmf";
17655
- var WMF = WmfModule.default ?? WmfModule;
17656
- var META_EOF = 0;
17657
- var META_SETBKCOLOR = 513;
17658
- var META_SETTEXTALIGN = 302;
17659
- var META_MOVETO = 532;
17660
- var META_LINETO = 531;
17661
- var META_POLYLINE = 805;
17662
- var META_ESCAPE = 1574;
17663
- var META_EXTTEXTOUT = 2610;
17664
- var PLACEABLE_KEY = 2596720087;
17665
- var SYMBOL_TEXT = {
17666
- p: "\u03C0",
17667
- "\xA5": "\u221E",
17668
- "\xB6": "\u2202",
17669
- \u00E5: "\u2211",
17670
- D: "\u0394"
17671
- };
17672
- function decodeWmfText(text, family) {
17673
- if (family === "Symbol") {
17674
- return { text: [...text].map((char) => SYMBOL_TEXT[char] ?? char).join(""), family };
17675
- }
17676
- if (family === "\xCB\xCE\xCC\xE5") {
17677
- return { text: text.replace(/£¨/g, "\uFF08").replace(/£©/g, "\uFF09"), family: "SimSun" };
17678
- }
17679
- return { text, family };
17680
- }
17681
- function record(fn, params) {
17682
- const length = 6 + params.length + (params.length & 1);
17683
- const out = new Uint8Array(length);
17684
- const view = new DataView(out.buffer);
17685
- view.setUint32(0, length / 2, true);
17686
- view.setUint16(4, fn, true);
17687
- out.set(params, 6);
17688
- return out;
17689
- }
17690
- function polyline(from, to) {
17691
- const params = new Uint8Array(10);
17692
- const view = new DataView(params.buffer);
17693
- view.setUint16(0, 2, true);
17694
- view.setInt16(2, from[0], true);
17695
- view.setInt16(4, from[1], true);
17696
- view.setInt16(6, to[0], true);
17697
- view.setInt16(8, to[1], true);
17698
- return record(META_POLYLINE, params);
17699
- }
17700
- function textRecord(char, x, y, advance) {
17701
- const params = new Uint8Array(12);
17702
- const view = new DataView(params.buffer);
17703
- view.setInt16(0, y, true);
17704
- view.setInt16(2, x, true);
17705
- view.setUint16(4, 1, true);
17706
- params[8] = char;
17707
- view.setInt16(10, advance, true);
17708
- return record(META_EXTTEXTOUT, params);
17709
- }
17710
- function isMathTypeEscape(bytes, offset, length) {
17711
- if (length < 18) return false;
17712
- const name = [77, 97, 116, 104, 84, 121, 112, 101];
17713
- return name.every((value, i) => bytes[offset + 10 + i] === value);
17714
- }
17715
- function hasMathTypeEscapes(bytes) {
17716
- const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
17717
- let offset = 18;
17718
- while (offset + 6 <= bytes.length) {
17719
- const length = view.getUint32(offset, true) * 2;
17720
- if (length < 6 || offset + length > bytes.length) return false;
17721
- const fn = view.getUint16(offset + 4, true);
17722
- if (fn === META_ESCAPE && isMathTypeEscape(bytes, offset, length)) return true;
17723
- offset += length;
17724
- if (fn === META_EOF) break;
17725
- }
17726
- return false;
17727
- }
17728
- function prepareWmf(input) {
17729
- let bytes = input;
17730
- if (bytes.length >= 22 && new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getUint32(0, true) === PLACEABLE_KEY) {
17731
- bytes = bytes.subarray(22);
17732
- }
17733
- if (bytes.length < 18) return null;
17734
- const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
17735
- const mathType = hasMathTypeEscapes(bytes);
17736
- const parts = [bytes.slice(0, 18)];
17737
- let offset = 18;
17738
- let textAlign = 0;
17739
- let current = [0, 0];
17740
- let maxRecordWords = 0;
17741
- const append = (part) => {
17742
- parts.push(part);
17743
- maxRecordWords = Math.max(maxRecordWords, part.length / 2);
17744
- };
17745
- while (offset + 6 <= bytes.length) {
17746
- const length = view.getUint32(offset, true) * 2;
17747
- if (length < 6 || offset + length > bytes.length) return null;
17748
- const fn = view.getUint16(offset + 4, true);
17749
- const params = offset + 6;
17750
- if (fn === META_SETTEXTALIGN) {
17751
- textAlign = view.getUint16(params, true);
17752
- append(bytes.slice(offset, offset + length));
17753
- } else if (fn === META_MOVETO) {
17754
- current = [view.getInt16(params + 2, true), view.getInt16(params, true)];
17755
- } else if (fn === META_LINETO) {
17756
- const next = [view.getInt16(params + 2, true), view.getInt16(params, true)];
17757
- append(polyline(current, next));
17758
- current = next;
17759
- } else if (fn === META_EXTTEXTOUT) {
17760
- const y = view.getInt16(params, true);
17761
- const x = view.getInt16(params + 2, true);
17762
- const count = view.getUint16(params + 4, true);
17763
- const options = view.getUint16(params + 6, true);
17764
- let charsAt = params + 8 + (options & 6 ? 8 : 0);
17765
- const advancesAt = charsAt + count + (count & 1);
17766
- const hasAdvances = options === 0 && advancesAt + count * 2 <= offset + length;
17767
- if (hasAdvances) {
17768
- let position = textAlign & 1 ? current : [x, y];
17769
- for (let i = 0; i < count; i++) {
17770
- const advance = view.getInt16(advancesAt + i * 2, true);
17771
- append(textRecord(bytes[charsAt + i], position[0], position[1], advance));
17772
- position = [position[0] + advance, position[1]];
17773
- }
17774
- if (textAlign & 1) current = position;
17775
- } else {
17776
- const copy = bytes.slice(offset, offset + length);
17777
- if (textAlign & 1) {
17778
- const copyView = new DataView(copy.buffer, copy.byteOffset, copy.byteLength);
17779
- copyView.setInt16(6, current[1], true);
17780
- copyView.setInt16(8, current[0], true);
17781
- }
17782
- append(copy);
17783
- }
17784
- } else if (fn === META_ESCAPE && mathType) {
17785
- } else if (fn !== META_SETBKCOLOR) {
17786
- append(bytes.slice(offset, offset + length));
17787
- }
17788
- offset += length;
17789
- if (fn === META_EOF) break;
17790
- }
17791
- const total = parts.reduce((sum2, part) => sum2 + part.length, 0);
17792
- const out = new Uint8Array(total);
17793
- let at = 0;
17794
- for (const part of parts) {
17795
- out.set(part, at);
17796
- at += part.length;
17797
- }
17798
- const outView = new DataView(out.buffer);
17799
- outView.setUint32(6, total / 2, true);
17800
- outView.setUint32(12, maxRecordWords, true);
17801
- return out;
17802
- }
17803
- function renderWmf(bytes, width, height) {
17804
- var _a, _b;
17805
- try {
17806
- const prepared = prepareWmf(bytes);
17807
- if (!prepared) return null;
17808
- const [rawWidth, rawHeight] = WMF.image_size(prepared).map(Math.abs);
17809
- if (!rawWidth || !rawHeight) return null;
17810
- const scale = Math.max(1, window.devicePixelRatio || 1);
17811
- const canvas = document.createElement("canvas");
17812
- canvas.width = Math.max(1, Math.round(width * scale));
17813
- canvas.height = Math.max(1, Math.round(height * scale));
17814
- const ctx = canvas.getContext("2d");
17815
- if (!ctx) return null;
17816
- ctx.fillStyle = "#fff";
17817
- ctx.fillRect(0, 0, canvas.width, canvas.height);
17818
- ctx.fillStyle = "#000";
17819
- ctx.scale(canvas.width / rawWidth, canvas.height / rawHeight);
17820
- const actions = WMF.get_actions(prepared);
17821
- for (const action of actions) {
17822
- if (!action.s) continue;
17823
- delete action.s.Extent;
17824
- if (action.t === "text" && action.v !== void 0 && action.s.Font) {
17825
- const decoded = decodeWmfText(action.v, action.s.Font.Name);
17826
- action.v = decoded.text;
17827
- action.s.Font.Name = decoded.family;
17828
- }
17829
- if (action.t === "poly") {
17830
- (_a = action.s).Pen ?? (_a.Pen = { Style: 0, Width: 1, Color: 0 });
17831
- (_b = action.s).Brush ?? (_b.Brush = { Style: 1, Color: 0 });
17832
- }
17833
- }
17834
- WMF.render_canvas(actions, canvas);
17835
- return canvas.toDataURL("image/png");
17836
- } catch {
17837
- return null;
17838
- }
17839
- }
17840
-
17841
17624
  // ../core/src/render/dom.ts
17842
17625
  function isXmlish(v) {
17843
17626
  return typeof v === "object" && v !== null && "attrs" in v && "children" in v && "name" in v;
@@ -18029,30 +17812,30 @@ function renderEmptyPageRecord(page, zoom, options) {
18029
17812
  mounted: false
18030
17813
  };
18031
17814
  }
18032
- function mountPageRecord(doc, record2, zoom, options) {
18033
- if (record2.mounted) return;
18034
- const rendered = renderPageRecord(doc, record2.page, zoom, options);
17815
+ function mountPageRecord(doc, record, zoom, options) {
17816
+ if (record.mounted) return;
17817
+ const rendered = renderPageRecord(doc, record.page, zoom, options);
18035
17818
  const surface = rendered.el.firstElementChild;
18036
- if (surface) record2.el.appendChild(surface);
18037
- record2.bindings = rendered.bindings;
18038
- record2.grips = rendered.grips;
18039
- record2.images = rendered.images;
18040
- record2.drawings = rendered.drawings;
18041
- record2.wordarts = rendered.wordarts;
18042
- record2.urls = rendered.urls;
18043
- record2.mounted = true;
18044
- }
18045
- function unmountPageRecord(record2) {
18046
- if (!record2.mounted) return;
18047
- for (const url of record2.urls) URL.revokeObjectURL(url);
18048
- record2.el.replaceChildren();
18049
- record2.bindings = [];
18050
- record2.grips = [];
18051
- record2.images = [];
18052
- record2.drawings = [];
18053
- record2.wordarts = [];
18054
- record2.urls = [];
18055
- record2.mounted = false;
17819
+ if (surface) record.el.appendChild(surface);
17820
+ record.bindings = rendered.bindings;
17821
+ record.grips = rendered.grips;
17822
+ record.images = rendered.images;
17823
+ record.drawings = rendered.drawings;
17824
+ record.wordarts = rendered.wordarts;
17825
+ record.urls = rendered.urls;
17826
+ record.mounted = true;
17827
+ }
17828
+ function unmountPageRecord(record) {
17829
+ if (!record.mounted) return;
17830
+ for (const url of record.urls) URL.revokeObjectURL(url);
17831
+ record.el.replaceChildren();
17832
+ record.bindings = [];
17833
+ record.grips = [];
17834
+ record.images = [];
17835
+ record.drawings = [];
17836
+ record.wordarts = [];
17837
+ record.urls = [];
17838
+ record.mounted = false;
18056
17839
  }
18057
17840
  function renderToDom(doc, layout, container, options = {}, prev) {
18058
17841
  const zoom = options.zoom ?? 1;
@@ -19018,8 +18801,18 @@ function renderItem(doc, item, urls, interactive) {
19018
18801
  }
19019
18802
  } else if (ext === "wmf") {
19020
18803
  const wmfKey = `wmf:${item.part}:${Math.round(item.width)}x${Math.round(item.height)}`;
19021
- decoded = docDerivedSrc(doc, wmfKey) ?? renderWmf(bytes, item.width, item.height);
19022
- if (decoded) setDocDerivedSrc(doc, wmfKey, decoded);
18804
+ const cachedWmf = docDerivedSrc(doc, wmfKey);
18805
+ if (cachedWmf) {
18806
+ decoded = cachedWmf;
18807
+ } else {
18808
+ void import("./wmf-53LMIKNI.js").then(({ renderWmf }) => {
18809
+ const url = renderWmf(bytes, item.width, item.height);
18810
+ if (url) {
18811
+ setDocDerivedSrc(doc, wmfKey, url);
18812
+ img.src = url;
18813
+ }
18814
+ });
18815
+ }
19023
18816
  } else if (ext === "emf") {
19024
18817
  const emfKey = `emf:${item.part}`;
19025
18818
  const cachedEmf = docDerivedSrc(doc, emfKey);
@@ -19027,7 +18820,7 @@ function renderItem(doc, item, urls, interactive) {
19027
18820
  decoded = cachedEmf;
19028
18821
  } else {
19029
18822
  const buf = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
19030
- void convertEmfToDataUrl(buf).then((url) => {
18823
+ void import("emf-converter").then(({ convertEmfToDataUrl }) => convertEmfToDataUrl(buf)).then((url) => {
19031
18824
  if (url) {
19032
18825
  setDocDerivedSrc(doc, emfKey, url);
19033
18826
  img.src = url;
@@ -21741,6 +21534,26 @@ function setMathLinear(doc, oMathEl, text) {
21741
21534
  doc.refresh();
21742
21535
  return true;
21743
21536
  }
21537
+ function deleteMath(doc, oMathEl) {
21538
+ const parent = doc.findParentOf(oMathEl);
21539
+ if (!parent) return false;
21540
+ let container = parent;
21541
+ let target = oMathEl;
21542
+ if (localName(parent.name) === "oMathPara") {
21543
+ const equations = parent.children.filter((child4) => localName(child4.name) === "oMath");
21544
+ if (equations.length === 1) {
21545
+ const grandparent = doc.findParentOf(parent);
21546
+ if (!grandparent) return false;
21547
+ container = grandparent;
21548
+ target = parent;
21549
+ }
21550
+ }
21551
+ const index = container.children.indexOf(target);
21552
+ if (index < 0) return false;
21553
+ container.children.splice(index, 1);
21554
+ doc.refresh();
21555
+ return true;
21556
+ }
21744
21557
  function insertMathAt(doc, t, offset, text) {
21745
21558
  const nodes = parseMathLinear(text.trim());
21746
21559
  if (nodes.length === 0) return null;
@@ -27590,11 +27403,23 @@ var _DocxEditor = class _DocxEditor {
27590
27403
  box.appendChild(caption);
27591
27404
  document.body.appendChild(box);
27592
27405
  this.mathEditorEl = box;
27406
+ const deleteEquation = () => {
27407
+ this.host.history?.checkpoint();
27408
+ if (deleteMath(this.host.doc, oMathEl)) this.host.rerender();
27409
+ this.closeMathEditor();
27410
+ this.focusText();
27411
+ };
27412
+ const remove = document.createElement("button");
27413
+ remove.textContent = "Delete";
27414
+ remove.setAttribute("aria-label", "Delete equation");
27415
+ remove.style.cssText = "border:1px solid #f1a7a2;border-radius:14px;padding:3px 12px;cursor:pointer;background:#fff;color:#b3261e;";
27416
+ remove.addEventListener("click", deleteEquation);
27593
27417
  if (!editable) {
27594
27418
  input.readOnly = true;
27595
27419
  input.style.background = "#f1f3f4";
27596
27420
  input.style.color = "#5f6368";
27597
27421
  caption.textContent = "Structured equation \u2014 text editing is disabled to protect its formatting.";
27422
+ row.appendChild(remove);
27598
27423
  setTimeout(() => input.select(), 0);
27599
27424
  input.addEventListener("keydown", (ke) => {
27600
27425
  ke.stopPropagation();
@@ -27609,6 +27434,7 @@ var _DocxEditor = class _DocxEditor {
27609
27434
  apply.textContent = "Apply";
27610
27435
  apply.style.cssText = "border:1px solid #dadce0;border-radius:14px;padding:3px 12px;cursor:pointer;background:#1a73e8;color:#fff;";
27611
27436
  row.appendChild(apply);
27437
+ row.appendChild(remove);
27612
27438
  const reject = () => {
27613
27439
  input.style.borderColor = "#d93025";
27614
27440
  input.style.background = "#fce8e6";
@@ -27620,6 +27446,10 @@ var _DocxEditor = class _DocxEditor {
27620
27446
  };
27621
27447
  const commitMath = () => {
27622
27448
  const val = input.value.trim();
27449
+ if (!val) {
27450
+ deleteEquation();
27451
+ return;
27452
+ }
27623
27453
  if (val === original.trim()) {
27624
27454
  this.closeMathEditor();
27625
27455
  this.focusText();
@@ -34712,11 +34542,6 @@ function DocxView({
34712
34542
  const applyZoomRef = useRef3(null);
34713
34543
  const onPageCountChangeRef = useRef3(onPageCountChange);
34714
34544
  onPageCountChangeRef.current = onPageCountChange;
34715
- useEffect3(() => {
34716
- if (editable && typeof window !== "undefined" && !customElements.get("model-viewer")) {
34717
- void import("@google/model-viewer");
34718
- }
34719
- }, [editable]);
34720
34545
  const recomputeFit = useCallback2(() => {
34721
34546
  const c = containerRef.current;
34722
34547
  if (!c) return;
@@ -34810,6 +34635,9 @@ function DocxView({
34810
34635
  paintedModelVersion = doc.modelVersion;
34811
34636
  const container = containerRef.current;
34812
34637
  if (!container) return 0;
34638
+ if (editable && !customElements.get("model-viewer") && layout.pages.some((page) => page.items.some((item) => item.kind === "image" && item.model3D))) {
34639
+ void import("@google/model-viewer");
34640
+ }
34813
34641
  const { scrollTop, scrollLeft } = container;
34814
34642
  const prev = handle;
34815
34643
  const t2 = perf ? performance.now() : 0;