@silurus/ooxml 0.11.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -100,7 +100,8 @@ async function m(e, t, n, r = {}) {
100
100
  docGrid: {
101
101
  type: i.docGridType ?? null,
102
102
  linePitchPt: i.docGridLinePitch ?? null
103
- }
103
+ },
104
+ onTextRun: r.onTextRun
104
105
  }, v = y(e.headers, n, f, e.section.titlePage, e.section.evenAndOddHeaders);
105
106
  v && b(v, i.headerDistance * s, _);
106
107
  let S = y(e.footers, n, f, e.section.titlePage, e.section.evenAndOddHeaders);
@@ -294,23 +295,30 @@ function T(e, t, n = !1) {
294
295
  }
295
296
  let u = n;
296
297
  if (!l) {
297
- let e = K(u, i), t = u.vertAlign === "super" ? -u.fontSize * i * .35 : u.vertAlign === "sub" ? u.fontSize * i * .15 : 0;
298
- r.font = q(u.bold, u.italic, e, u.fontFamily), u.highlight && (r.fillStyle = c[u.highlight] ?? "#FFFF00", r.fillRect(b, p + t - e * .85, u.measuredWidth, e * 1.1)), r.fillStyle = u.color ? `#${u.color}` : s, r.fillText(u.text, b, p + t);
299
- let n = u.color ? `#${u.color}` : s, a = Math.max(.5, e * .05), o = r.measureText(u.text).width;
298
+ let e = K(u, i), n = u.vertAlign === "super" ? -u.fontSize * i * .35 : u.vertAlign === "sub" ? u.fontSize * i * .15 : 0;
299
+ r.font = q(u.bold, u.italic, e, u.fontFamily), u.highlight && (r.fillStyle = c[u.highlight] ?? "#FFFF00", r.fillRect(b, p + n - e * .85, u.measuredWidth, e * 1.1)), r.fillStyle = u.color ? `#${u.color}` : s, r.fillText(u.text, b, p + n), t.onTextRun && u.text && t.onTextRun({
300
+ text: u.text,
301
+ x: b,
302
+ y: t.y,
303
+ w: u.measuredWidth,
304
+ h: d,
305
+ fontSize: e
306
+ });
307
+ let a = u.color ? `#${u.color}` : s, o = Math.max(.5, e * .05), l = r.measureText(u.text).width;
300
308
  if (u.underline) {
301
- r.strokeStyle = n, r.lineWidth = a;
302
- let i = p + t + e * .12;
303
- r.beginPath(), r.moveTo(b, i), r.lineTo(b + o, i), r.stroke();
309
+ r.strokeStyle = a, r.lineWidth = o;
310
+ let t = p + n + e * .12;
311
+ r.beginPath(), r.moveTo(b, t), r.lineTo(b + l, t), r.stroke();
304
312
  }
305
313
  if (u.strikethrough) {
306
- r.strokeStyle = n, r.lineWidth = a;
307
- let i = p + t - e * .3;
308
- r.beginPath(), r.moveTo(b, i), r.lineTo(b + o, i), r.stroke();
314
+ r.strokeStyle = a, r.lineWidth = o;
315
+ let t = p + n - e * .3;
316
+ r.beginPath(), r.moveTo(b, t), r.lineTo(b + l, t), r.stroke();
309
317
  }
310
318
  if (u.doubleStrikethrough) {
311
- r.strokeStyle = n, r.lineWidth = a;
312
- let i = p + t - e * .35, s = p + t - e * .22;
313
- r.beginPath(), r.moveTo(b, i), r.lineTo(b + o, i), r.stroke(), r.beginPath(), r.moveTo(b, s), r.lineTo(b + o, s), r.stroke();
319
+ r.strokeStyle = a, r.lineWidth = o;
320
+ let t = p + n - e * .35, i = p + n - e * .22;
321
+ r.beginPath(), r.moveTo(b, t), r.lineTo(b + l, t), r.stroke(), r.beginPath(), r.moveTo(b, i), r.lineTo(b + l, i), r.stroke();
314
322
  }
315
323
  }
316
324
  if (b += u.measuredWidth, D > 0 && !o) {
@@ -793,12 +801,16 @@ var Q = class e {
793
801
  _doc = null;
794
802
  _currentPage = 0;
795
803
  _canvas;
804
+ _wrapper;
805
+ _textLayer = null;
796
806
  _opts;
797
807
  constructor(e, t = {}) {
798
808
  this._canvas = e, this._opts = t;
809
+ let n = e.parentElement;
810
+ this._wrapper = document.createElement("div"), this._wrapper.style.cssText = "position:relative;display:inline-block;", n && n.insertBefore(this._wrapper, e), this._wrapper.appendChild(e), t.enableTextSelection && (this._textLayer = document.createElement("div"), this._textLayer.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;overflow:hidden;pointer-events:none;user-select:text;-webkit-user-select:text;", this._wrapper.appendChild(this._textLayer));
799
811
  }
800
812
  async load(e) {
801
- this._doc = await Q.load(e), this._currentPage = 0, this._render();
813
+ this._doc = await Q.load(e), this._currentPage = 0, await this._render();
802
814
  }
803
815
  get pageCount() {
804
816
  return this._doc?.pageCount ?? 0;
@@ -806,17 +818,30 @@ var Q = class e {
806
818
  get currentPage() {
807
819
  return this._currentPage;
808
820
  }
809
- goToPage(e) {
810
- this._doc && (this._currentPage = Math.max(0, Math.min(e, this.pageCount - 1)), this._render());
811
- }
812
- nextPage() {
813
- this.goToPage(this._currentPage + 1);
814
- }
815
- prevPage() {
816
- this.goToPage(this._currentPage - 1);
817
- }
818
- _render() {
819
- this._doc && this._doc.renderPage(this._canvas, this._currentPage, this._opts);
821
+ async goToPage(e) {
822
+ this._doc && (this._currentPage = Math.max(0, Math.min(e, this.pageCount - 1)), await this._render());
823
+ }
824
+ async nextPage() {
825
+ await this.goToPage(this._currentPage + 1);
826
+ }
827
+ async prevPage() {
828
+ await this.goToPage(this._currentPage - 1);
829
+ }
830
+ async _render() {
831
+ if (!this._doc) return;
832
+ let e = [], t = this._textLayer ? (t) => e.push(t) : void 0;
833
+ await this._doc.renderPage(this._canvas, this._currentPage, {
834
+ ...this._opts,
835
+ onTextRun: t
836
+ }), this._textLayer && this._buildTextLayer(e);
837
+ }
838
+ _buildTextLayer(e) {
839
+ let t = this._textLayer;
840
+ t.innerHTML = "", t.style.width = `${this._canvas.style.width || this._canvas.width + "px"}`, t.style.height = `${this._canvas.style.height || this._canvas.height + "px"}`;
841
+ for (let n of e) {
842
+ let e = document.createElement("span");
843
+ e.textContent = n.text, e.style.cssText = `position:absolute;left:${n.x}px;top:${n.y}px;font-size:${n.fontSize}px;line-height:${n.h}px;white-space:pre;color:transparent;cursor:text;pointer-events:all;`, t.appendChild(e);
844
+ }
820
845
  }
821
846
  }, re = /* @__PURE__ */ e({
822
847
  DocxDocument: () => Q,
package/dist/docx.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./autoResize-ggn4hzd8.cjs`),t=require(`./docx-5SgqrF74.cjs`);exports.DocxDocument=t.r,exports.DocxViewer=t.n,exports.autoResize=e.t;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./autoResize-ggn4hzd8.cjs`),t=require(`./docx-BWxysGzi.cjs`);exports.DocxDocument=t.r,exports.DocxViewer=t.n,exports.autoResize=e.t;
package/dist/docx.mjs CHANGED
@@ -1,3 +1,3 @@
1
1
  import { t as e } from "./autoResize-U2-IRmNE.js";
2
- import { n as t, r as n } from "./docx-BdQTKYcj.js";
2
+ import { n as t, r as n } from "./docx-I_31kSX9.js";
3
3
  export { n as DocxDocument, t as DocxViewer, e as autoResize };
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./pptx-BGtPXrb6.cjs`),t=require(`./xlsx-DYZg9gH8.cjs`),n=require(`./docx-5SgqrF74.cjs`);Object.defineProperty(exports,`docx`,{enumerable:!0,get:function(){return n.t}}),Object.defineProperty(exports,`pptx`,{enumerable:!0,get:function(){return e.t}}),Object.defineProperty(exports,`xlsx`,{enumerable:!0,get:function(){return t.t}});
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./pptx-D0uqcB_p.cjs`),t=require(`./xlsx-B4rNAWcg.cjs`),n=require(`./docx-BWxysGzi.cjs`);Object.defineProperty(exports,`docx`,{enumerable:!0,get:function(){return n.t}}),Object.defineProperty(exports,`pptx`,{enumerable:!0,get:function(){return e.t}}),Object.defineProperty(exports,`xlsx`,{enumerable:!0,get:function(){return t.t}});
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as e } from "./pptx-CsVDY5Ej.js";
2
- import { t } from "./xlsx-35w32FNQ.js";
3
- import { t as n } from "./docx-BdQTKYcj.js";
1
+ import { t as e } from "./pptx-8AYrKKlD.js";
2
+ import { t } from "./xlsx-B-twWw7w.js";
3
+ import { t as n } from "./docx-I_31kSX9.js";
4
4
  export { n as docx, e as pptx, t as xlsx };