@fileverse-dev/dsheet 4.0.3-import-compaction.0 → 4.0.3-import-compaction.2

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,14 @@
1
+ import { DsheetWorkerApi } from './dsheet-worker';
2
+ import * as Comlink from 'comlink';
3
+ export type { DsheetWorkerApi };
4
+ export declare const isDsheetWorkerSupported: () => boolean;
5
+ export declare const terminateDsheetWorker: () => void;
6
+ /**
7
+ * Run a task on the shared dsheet worker. The worker is spawned lazily,
8
+ * reused across tasks, and terminated after 30s idle (a parse can hold
9
+ * hundreds of MB of transient allocations — terminating returns them to
10
+ * the OS immediately). Callers must handle rejection and fall back to the
11
+ * main-thread equivalent; a worker that failed is torn down so the next
12
+ * task starts from a fresh one.
13
+ */
14
+ export declare function runDsheetWorkerTask<T>(task: (api: Comlink.Remote<DsheetWorkerApi>) => Promise<T>): Promise<T>;
@@ -0,0 +1,14 @@
1
+ import { XlsxParseSettings, XlsxParsedWorkbook } from '../editor/utils/xlsx-import-pipeline';
2
+
3
+ /**
4
+ * The dsheet offload worker. One worker, many tasks: add new offloadable
5
+ * operations as methods on this object — the client (dsheet-worker-client)
6
+ * exposes them through the same Comlink proxy. Everything reachable from
7
+ * here must stay DOM/React/Yjs-free; the worker bundle is built standalone
8
+ * and inlined into the package, so main-bundle externals do not exist here.
9
+ */
10
+ declare const dsheetWorkerApi: {
11
+ parseXlsxWorkbook: (file: File, settings?: XlsxParseSettings) => Promise<XlsxParsedWorkbook>;
12
+ };
13
+ export type DsheetWorkerApi = typeof dsheetWorkerApi;
14
+ export {};
@@ -1,10 +1,9 @@
1
1
  import { utils as dt, write as Pt } from "xlsx-js-style";
2
2
  import { Workbook as Ut } from "exceljs";
3
3
  import { toast as Rt } from "@fileverse/ui";
4
- import { addFortuneImagesToWorksheet as Lt } from "./xlsx-image-utils-Cvg0qxRA.js";
5
- import { g as jt, c as xt, b as Wt } from "./executeStringFunction-C1C2F-4h.js";
6
- import { a as St, e as Mt } from "./index-Be1UXKhA.js";
7
- import { c as zt, g as Zt } from "./xlsx-hyperlink-inline-DzewAypN.js";
4
+ import { a as zt, g as Lt, b as jt } from "./xlsx-hyperlink-inline-D8ZL-y78.js";
5
+ import { g as Wt, c as xt, b as Mt } from "./executeStringFunction-C1C2F-4h.js";
6
+ import { a as St, e as Zt } from "./index-DdJcYIoi.js";
8
7
  const $t = {
9
8
  1: "thin",
10
9
  2: "hair",
@@ -2726,7 +2725,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE
2726
2725
  });
2727
2726
  })(Bt);
2728
2727
  var Xt = Bt.exports;
2729
- const Jt = /* @__PURE__ */ jt(Xt);
2728
+ const Jt = /* @__PURE__ */ Wt(Xt);
2730
2729
  function Qt(U) {
2731
2730
  let K = "";
2732
2731
  const s = [];
@@ -2876,7 +2875,7 @@ const Ct = (U) => {
2876
2875
  return ((1 << 24) + (c << 16) + (o << 8) + a).toString(16).slice(1).toUpperCase();
2877
2876
  }
2878
2877
  return null;
2879
- }, _e = async (U, K, s, S) => {
2878
+ }, me = async (U, K, s, S) => {
2880
2879
  var c, o, a, r;
2881
2880
  if (!(!U.current || !K.current))
2882
2881
  try {
@@ -2888,11 +2887,11 @@ const Ct = (U) => {
2888
2887
  duration: 30 * 1e3
2889
2888
  }), K.current.getArray(s);
2890
2889
  const b = U.current.getAllSheets();
2891
- b.forEach((z) => Mt(z));
2890
+ b.forEach((z) => Zt(z));
2892
2891
  const y = dt.book_new(), n = b.map(() => /* @__PURE__ */ new Map()), p = /* @__PURE__ */ new Set();
2893
2892
  b.forEach((z, V) => {
2894
2893
  var F, J, W, et, M;
2895
- const X = Wt(z), g = dt.aoa_to_sheet(X);
2894
+ const X = Mt(z), g = dt.aoa_to_sheet(X);
2896
2895
  Object.keys(g).forEach((H) => {
2897
2896
  if (H.startsWith("!")) return;
2898
2897
  const E = g[H];
@@ -3037,7 +3036,7 @@ const Ct = (U) => {
3037
3036
  const g = z.data;
3038
3037
  Object.entries(z.hyperlink || {}).forEach(([et, M]) => {
3039
3038
  var tt, rt, st, ot;
3040
- const H = Zt(M);
3039
+ const H = Lt(M);
3041
3040
  if (!(H != null && H.linkAddress)) return;
3042
3041
  const [E, w] = et.split("_").map(Number);
3043
3042
  if (Number.isNaN(E) || Number.isNaN(w)) return;
@@ -3112,7 +3111,7 @@ const Ct = (U) => {
3112
3111
  const X = u.worksheets[V];
3113
3112
  if (!X) return;
3114
3113
  const g = Number(z.defaultColWidth) || 99, O = Number(z.defaultRowHeight) || 21;
3115
- Lt(
3114
+ jt(
3116
3115
  X,
3117
3116
  u,
3118
3117
  z.images,
@@ -3136,5 +3135,5 @@ const Ct = (U) => {
3136
3135
  }
3137
3136
  };
3138
3137
  export {
3139
- _e as handleExportToXLSX
3138
+ me as handleExportToXLSX
3140
3139
  };
@@ -0,0 +1,195 @@
1
+ function O(e, r) {
2
+ const s = e.getImages();
3
+ if (!s.length) return [];
4
+ const n = [];
5
+ for (const t of s)
6
+ try {
7
+ const a = r.getImage(Number(t.imageId));
8
+ if (!a) continue;
9
+ let o;
10
+ if (a.buffer) {
11
+ const u = new Uint8Array(a.buffer);
12
+ let d = "";
13
+ for (let v = 0; v < u.length; v += 8192)
14
+ d += String.fromCharCode(...u.subarray(v, v + 8192));
15
+ o = btoa(d);
16
+ } else if (a.base64)
17
+ o = a.base64;
18
+ else
19
+ continue;
20
+ const l = a.extension ?? "png", g = `data:${l === "jpeg" ? "image/jpeg" : `image/${l}`};base64,${o}`, { tl: f, br: i } = t.range, h = t.range.ext;
21
+ n.push({
22
+ src: g,
23
+ nativeCol: f.nativeCol,
24
+ nativeColOff: f.nativeColOff,
25
+ nativeRow: f.nativeRow,
26
+ nativeRowOff: f.nativeRowOff,
27
+ width: h ? Math.max(Math.round(h.width), 20) : 0,
28
+ height: h ? Math.max(Math.round(h.height), 20) : 0,
29
+ brNativeCol: i == null ? void 0 : i.nativeCol,
30
+ brNativeColOff: i == null ? void 0 : i.nativeColOff,
31
+ brNativeRow: i == null ? void 0 : i.nativeRow,
32
+ brNativeRowOff: i == null ? void 0 : i.nativeRowOff
33
+ });
34
+ } catch {
35
+ }
36
+ return n;
37
+ }
38
+ const m = 9525, p = 1, y = 2;
39
+ function C(e, r, s) {
40
+ var a, o;
41
+ let n = 0, t = 0;
42
+ for (; t < 1e4; ) {
43
+ const l = (((o = (a = r.config) == null ? void 0 : a.columnlen) == null ? void 0 : o[t]) ?? s) + p;
44
+ if (n + l > e)
45
+ return {
46
+ nativeCol: t,
47
+ nativeColOff: Math.round((e - n) * m)
48
+ };
49
+ n += l, t++;
50
+ }
51
+ return { nativeCol: t, nativeColOff: 0 };
52
+ }
53
+ function x(e, r, s) {
54
+ var a, o;
55
+ let n = 0, t = 0;
56
+ for (; t < 1e5; ) {
57
+ const l = (((o = (a = r.config) == null ? void 0 : a.rowlen) == null ? void 0 : o[t]) ?? s) + y;
58
+ if (n + l > e)
59
+ return {
60
+ nativeRow: t,
61
+ nativeRowOff: Math.round((e - n) * m)
62
+ };
63
+ n += l, t++;
64
+ }
65
+ return { nativeRow: t, nativeRowOff: 0 };
66
+ }
67
+ function I(e, r, s, n, t, a) {
68
+ for (const o of s)
69
+ try {
70
+ const l = o.src.match(/^data:image\/([a-zA-Z]+);base64,(.+)$/);
71
+ if (!l) continue;
72
+ const c = l[1].toLowerCase(), g = c === "jpeg" || c === "jpg" ? "jpeg" : c === "gif" ? "gif" : "png", f = l[2], i = r.addImage({ base64: f, extension: g }), { nativeCol: h, nativeColOff: u } = C(
73
+ o.left,
74
+ n,
75
+ t
76
+ ), { nativeRow: d, nativeRowOff: v } = x(
77
+ o.top,
78
+ n,
79
+ a
80
+ );
81
+ e.addImage(i, {
82
+ tl: { nativeCol: h, nativeColOff: u, nativeRow: d, nativeRowOff: v },
83
+ ext: { width: o.width, height: o.height },
84
+ editAs: "oneCell"
85
+ });
86
+ } catch {
87
+ }
88
+ }
89
+ function A(e, r, s, n) {
90
+ const t = (o, l) => {
91
+ var g, f;
92
+ let c = 0;
93
+ for (let i = 0; i < o; i++)
94
+ c += (((f = (g = r.config) == null ? void 0 : g.columnlen) == null ? void 0 : f[i]) ?? s) + p;
95
+ return Math.round(c + l / m);
96
+ }, a = (o, l) => {
97
+ var g, f;
98
+ let c = 0;
99
+ for (let i = 0; i < o; i++)
100
+ c += (((f = (g = r.config) == null ? void 0 : g.rowlen) == null ? void 0 : f[i]) ?? n) + y;
101
+ return Math.round(c + l / m);
102
+ };
103
+ return e.map((o) => {
104
+ const l = t(o.nativeCol, o.nativeColOff), c = a(o.nativeRow, o.nativeRowOff);
105
+ let { width: g, height: f } = o;
106
+ return !g && o.brNativeCol != null && (g = Math.max(
107
+ t(o.brNativeCol, o.brNativeColOff ?? 0) - l,
108
+ 20
109
+ )), !f && o.brNativeRow != null && (f = Math.max(
110
+ a(o.brNativeRow, o.brNativeRowOff ?? 0) - c,
111
+ 20
112
+ )), {
113
+ id: `img_imported_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
114
+ src: o.src,
115
+ left: l,
116
+ top: c,
117
+ width: Math.max(g, 20),
118
+ height: Math.max(f, 20)
119
+ };
120
+ });
121
+ }
122
+ function k(e) {
123
+ if (Array.isArray(e)) {
124
+ const r = e[0];
125
+ return r && typeof r == "object" && typeof r.linkType == "string" && typeof r.linkAddress == "string" ? r : void 0;
126
+ }
127
+ if (e && typeof e == "object" && typeof e.linkType == "string" && typeof e.linkAddress == "string")
128
+ return e;
129
+ }
130
+ function N(e) {
131
+ var s, n;
132
+ if (!Array.isArray(e) || e.length === 0) return "";
133
+ if (e.length === 1) return String(((s = e[0]) == null ? void 0 : s.v) ?? "");
134
+ let r = "";
135
+ for (let t = 0; t < e.length; t += 1)
136
+ r += String(((n = e[t]) == null ? void 0 : n.v) ?? "");
137
+ return r;
138
+ }
139
+ function w(e) {
140
+ if (!e || typeof e != "object" || Array.isArray(e)) return {};
141
+ const r = e, s = {};
142
+ for (const n in r)
143
+ Object.prototype.hasOwnProperty.call(r, n) && (n === "fc" || n === "un" || n === "s" || n === "t" || (s[n] = r[n]));
144
+ return s;
145
+ }
146
+ function M(e, r) {
147
+ const s = String(e.m ?? e.v ?? "").replace(
148
+ /\r\n/g,
149
+ `
150
+ `
151
+ );
152
+ let n = "", t = null;
153
+ const a = e.ct;
154
+ if ((a == null ? void 0 : a.t) === "inlineStr" && Array.isArray(a.s) && a.s.length > 0) {
155
+ const g = a.s;
156
+ if (g.length === 1) {
157
+ const f = g[0];
158
+ n = String((f == null ? void 0 : f.v) ?? ""), n.length > 0 && (t = f);
159
+ } else
160
+ for (let f = 0; f < g.length; f += 1) {
161
+ const i = g[f], h = String((i == null ? void 0 : i.v) ?? "");
162
+ h.length > 0 && t == null && (t = i), n += h;
163
+ }
164
+ }
165
+ n.length === 0 && (n = s);
166
+ const o = {
167
+ v: n,
168
+ fs: (t == null ? void 0 : t.fs) ?? e.fs ?? 10,
169
+ ff: (t == null ? void 0 : t.ff) ?? e.ff ?? 0,
170
+ bl: (t == null ? void 0 : t.bl) ?? e.bl ?? 0,
171
+ it: (t == null ? void 0 : t.it) ?? e.it ?? 0,
172
+ cl: (t == null ? void 0 : t.cl) ?? e.cl ?? 0,
173
+ fc: (t == null ? void 0 : t.fc) != null && String(t.fc).length > 0 ? t.fc : "rgb(0, 0, 255)",
174
+ un: (t == null ? void 0 : t.un) != null && t.un !== 0 ? t.un : 1,
175
+ link: {
176
+ linkType: r.linkType,
177
+ linkAddress: r.linkAddress
178
+ }
179
+ }, l = w(e.ct);
180
+ e.ct = {
181
+ ...l,
182
+ t: "inlineStr",
183
+ s: [o]
184
+ }, e.m = n, e.v = n, delete e.fc, delete e.un;
185
+ const c = e.ct;
186
+ c && typeof c == "object" && !Array.isArray(c) && (delete c.fc, delete c.un);
187
+ }
188
+ export {
189
+ N as a,
190
+ I as b,
191
+ A as c,
192
+ O as e,
193
+ k as g,
194
+ M as n
195
+ };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@fileverse-dev/dsheet",
3
3
  "private": false,
4
4
  "description": "DSheet",
5
- "version": "4.0.3-import-compaction.0",
5
+ "version": "4.0.3-import-compaction.2",
6
6
  "main": "dist/index.es.js",
7
7
  "module": "dist/index.es.js",
8
8
  "exports": {
@@ -69,6 +69,7 @@
69
69
  "@tippyjs/react": "^4.2.6",
70
70
  "@ucans/ucans": "^0.12.0",
71
71
  "classnames": "^2.5.1",
72
+ "comlink": "^4.4.2",
72
73
  "dayjs": "^1.11.0",
73
74
  "exceljs": "^4.4.0",
74
75
  "immer": "^9.0.12",