@silurus/ooxml 0.84.1 → 0.85.1

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 (68) hide show
  1. package/README.md +44 -18
  2. package/dist/assets/render-worker-BRKOyWVH.js +24 -0
  3. package/dist/assets/render-worker-CtLMFj9r.js +10 -0
  4. package/dist/assets/render-worker-NZPOUOTU.js +11 -0
  5. package/dist/{canvas-viewer-mechanics-CIfhCgYA.js → canvas-viewer-mechanics-CfRzOhz5.js} +308 -234
  6. package/dist/chart-ex.mjs +270 -270
  7. package/dist/{comment-ui-runtime-CdMMApEN.js → comment-ui-runtime-CAbpuWi_.js} +4 -4
  8. package/dist/{comment-ui-runtime-C5qimVMD.js → comment-ui-runtime-DAKBCpsM.js} +5 -5
  9. package/dist/comment-ui-runtime-DTaaZdXC.js +2 -0
  10. package/dist/{comments-BAlAyIhb.js → comments-Brfxa3hQ.js} +1 -1
  11. package/dist/{document-pull-client-BXw6AAhY.js → document-pull-client-BkHHIdR4.js} +4661 -4357
  12. package/dist/{docx-BA1vB0V-.js → docx-_uelcAui.js} +338 -304
  13. package/dist/docx.mjs +7 -6
  14. package/dist/docx_parser_bg.wasm +0 -0
  15. package/dist/{dom-interaction-boundary-DS6BVyHA.js → dom-interaction-boundary-CMDDgICk.js} +1 -1
  16. package/dist/index.mjs +3 -3
  17. package/dist/line-distribute-CiKeWjBF.js +1023 -0
  18. package/dist/{line-metrics-CXyjyYd5.js → line-metrics-u87yCAfV.js} +2182 -705
  19. package/dist/math.mjs +2 -2
  20. package/dist/node.mjs +404 -394
  21. package/dist/pixel-budget-Dgjw269h.js +37 -0
  22. package/dist/{plot-area-frame-DuXZzovH.js → plot-area-frame-D5hEOgkJ.js} +691 -1418
  23. package/dist/{pptx-C17oBD8Z.js → pptx-WpBbS0mq.js} +255 -222
  24. package/dist/pptx.mjs +7 -6
  25. package/dist/pptx_parser_bg.wasm +0 -0
  26. package/dist/raster-target-whZhvVMt.js +87 -0
  27. package/dist/region-map.mjs +5 -5
  28. package/dist/{render-CVeGktZG.js → render-DrAAZWwH.js} +9 -6
  29. package/dist/{render-worker-host-BbhwA24Y.js → render-worker-host-CBVe8aeD.js} +1 -1
  30. package/dist/{render-worker-host-BWdhjVH_.js → render-worker-host-CHlwYJdK.js} +1 -1
  31. package/dist/{render-worker-host-CbaQivE7.js → render-worker-host-XDMsyVsv.js} +1 -1
  32. package/dist/{renderer-Bmky2yBc.js → renderer-XFSCOT6m.js} +1937 -1936
  33. package/dist/resource-measurement-6uR3Huao.js +150 -0
  34. package/dist/{session-Cl0RVnMs.js → session-DoPwA4gv.js} +79 -79
  35. package/dist/{slide-pull-client-BS0EeZo2.js → slide-pull-client-8i8C4VyD.js} +1054 -824
  36. package/dist/{three-d-B7LsKeOS.js → three-d-YYghQndN.js} +109 -110
  37. package/dist/three-d.mjs +726 -726
  38. package/dist/tiff.mjs +664 -78
  39. package/dist/types/chart-ex.d.ts +2 -2
  40. package/dist/types/docx.d.ts +31 -13
  41. package/dist/types/index.d.ts +46 -21
  42. package/dist/types/math.d.ts +1 -1
  43. package/dist/types/node.d.ts +11 -7
  44. package/dist/types/pptx.d.ts +35 -15
  45. package/dist/types/region-map.d.ts +2 -2
  46. package/dist/types/three-d.d.ts +2 -2
  47. package/dist/types/tiff.d.ts +13 -3
  48. package/dist/types/xlsx.d.ts +30 -13
  49. package/dist/{worksheet-pull-client-B0zfEVau.js → worksheet-pull-client-Btydoxto.js} +47 -47
  50. package/dist/{xlsx-FyKAiNo-.js → xlsx-Bd16V4Xx.js} +1395 -1196
  51. package/dist/xlsx.mjs +7 -6
  52. package/package.json +2 -2
  53. package/dist/assets/render-worker-BWPpayBu.js +0 -10
  54. package/dist/assets/render-worker-CiEWCh_T.js +0 -11
  55. package/dist/assets/render-worker-Cpmy3GDF.js +0 -24
  56. package/dist/comment-ui-runtime-aPzHfV_A.js +0 -2
  57. package/dist/line-distribute-MqInuujx.js +0 -1003
  58. package/dist/resource-measurement-esyGbzAF.js +0 -120
  59. package/dist/tiff-contract-Xjn3qXqK.js +0 -69
  60. /package/dist/{comment-occurrence-C34fWs_F.js → comment-occurrence-tj54AXXB.js} +0 -0
  61. /package/dist/{highlight-rect-MaCt0om0.js → highlight-rect-DBcYVJDv.js} +0 -0
  62. /package/dist/{mathjax-DPEX346v.js → mathjax-DS69BmJd.js} +0 -0
  63. /package/dist/{read-only-comment-decoration-BYCXoSdC.js → read-only-comment-decoration-Mv_SAiHy.js} +0 -0
  64. /package/dist/{read-only-comment-margin-C7b3l0ro.js → read-only-comment-margin-Cqu-Ir0C.js} +0 -0
  65. /package/dist/{renderer-module-contract-C6sYZvTV.js → renderer-module-contract-Cu-GKuPd.js} +0 -0
  66. /package/dist/{source-key-DORuuFb-.js → source-key-BkBB3X82.js} +0 -0
  67. /package/dist/{transfer-vNOFQuvv.js → transfer-mIj7E7NB.js} +0 -0
  68. /package/dist/{visible-index-DwJzuGmJ.js → visible-index-DPoQYSDt.js} +0 -0
package/dist/tiff.mjs CHANGED
@@ -1,21 +1,39 @@
1
- import { a as e, c as t, o as n, t as r } from "./tiff-contract-Xjn3qXqK.js";
2
- import { t as i } from "./renderer-module-contract-C6sYZvTV.js";
1
+ import { a as e, i as t, o as n, r, s as i } from "./pixel-budget-Dgjw269h.js";
2
+ import { i as a, o, s, t as c } from "./raster-target-whZhvVMt.js";
3
+ import { t as l } from "./renderer-module-contract-Cu-GKuPd.js";
3
4
  //#region packages/core/src/image/tiff.ts
4
- var a = 1, o = 3, s = 4, c = {
5
+ var u = 1, d = 3, f = 4, p = {
5
6
  width: 256,
6
7
  height: 257,
7
8
  bitsPerSample: 258,
8
9
  compression: 259,
9
10
  photometric: 262,
11
+ fillOrder: 266,
10
12
  stripOffsets: 273,
11
13
  orientation: 274,
12
14
  samplesPerPixel: 277,
13
15
  rowsPerStrip: 278,
14
16
  stripByteCounts: 279,
15
17
  planarConfiguration: 284,
18
+ t6Options: 293,
19
+ predictor: 317,
20
+ tileWidth: 322,
21
+ tileLength: 323,
22
+ tileOffsets: 324,
23
+ tileByteCounts: 325,
16
24
  inkSet: 332,
17
- extraSamples: 338
18
- }, l = class {
25
+ extraSamples: 338,
26
+ sampleFormat: 339
27
+ }, m = [
28
+ p.tileWidth,
29
+ p.tileLength,
30
+ p.tileOffsets,
31
+ p.tileByteCounts
32
+ ];
33
+ function h(e, t) {
34
+ throw new a(e, t === void 0 ? void 0 : { cause: t });
35
+ }
36
+ var g = class {
19
37
  view;
20
38
  constructor(e, t) {
21
39
  this.bytes = e, this.littleEndian = t, this.view = new DataView(e.buffer, e.byteOffset, e.byteLength);
@@ -23,24 +41,33 @@ var a = 1, o = 3, s = 4, c = {
23
41
  contains(e, t) {
24
42
  return Number.isSafeInteger(e) && Number.isSafeInteger(t) && e >= 0 && t >= 0 && e <= this.view.byteLength - t;
25
43
  }
26
- u16(e) {
27
- return this.contains(e, 2) ? this.view.getUint16(e, this.littleEndian) : null;
44
+ u8(e, t) {
45
+ return this.contains(e, 1) || h(`Malformed TIFF ${t} range`), this.view.getUint8(e);
46
+ }
47
+ u16(e, t) {
48
+ return this.contains(e, 2) || h(`Malformed TIFF ${t} range`), this.view.getUint16(e, this.littleEndian);
28
49
  }
29
- u32(e) {
30
- return this.contains(e, 4) ? this.view.getUint32(e, this.littleEndian) : null;
50
+ u32(e, t) {
51
+ return this.contains(e, 4) || h(`Malformed TIFF ${t} range`), this.view.getUint32(e, this.littleEndian);
31
52
  }
32
53
  };
33
- function u(e) {
34
- if (!r(e)) return null;
35
- let t = new l(e, e[0] === 73), n = t.u32(4);
36
- if (n == null) return null;
37
- let i = t.u16(n);
38
- if (i == null || !t.contains(n + 2, i * 12 + 4)) return null;
54
+ function _(e) {
55
+ return e.length >= 2 && (e[0] === 73 && e[1] === 73 || e[0] === 77 && e[1] === 77);
56
+ }
57
+ function v(e) {
58
+ if (!o(e)) {
59
+ if (!_(e)) return null;
60
+ e.length < 4 && h("Malformed TIFF header: missing version");
61
+ let t = e[0] === 73;
62
+ h(`Unsupported TIFF version: ${new DataView(e.buffer, e.byteOffset, e.byteLength).getUint16(2, t)}`);
63
+ }
64
+ e.length < 8 && h("Malformed TIFF header: missing first-IFD offset");
65
+ let t = new g(e, e[0] === 73), n = t.u32(4, "first-IFD offset"), r = t.u16(n, "first IFD"), i = r * 12 + 4;
66
+ t.contains(n + 2, i) || h("Malformed TIFF first-IFD entry range");
39
67
  let a = /* @__PURE__ */ new Map();
40
- for (let e = 0; e < i; e++) {
41
- let r = n + 2 + e * 12, i = t.u16(r), o = t.u16(r + 2), s = t.u32(r + 4);
42
- if (i == null || o == null || s == null || a.has(i)) return null;
43
- a.set(i, {
68
+ for (let e = 0; e < r; e++) {
69
+ let r = n + 2 + e * 12, i = t.u16(r, `IFD entry ${e}`), o = t.u16(r + 2, `IFD entry ${e} type`), s = t.u32(r + 4, `IFD entry ${e} count`);
70
+ a.has(i) && h(`Malformed TIFF: duplicate tag ${i}`), a.set(i, {
44
71
  type: o,
45
72
  count: s,
46
73
  entryOffset: r
@@ -51,74 +78,633 @@ function u(e) {
51
78
  fields: a
52
79
  };
53
80
  }
54
- function d(e, t, n) {
55
- let r = e.fields.get(t);
56
- if (!r || r.count < 1 || r.count > n) return null;
57
- let i = r.type === a ? 1 : r.type === o ? 2 : r.type === s ? 4 : 0;
58
- if (i === 0) return null;
59
- let c = r.count * i, l = c <= 4 ? r.entryOffset + 8 : e.reader.u32(r.entryOffset + 8);
60
- if (l == null || !e.reader.contains(l, c)) return null;
61
- let u = Array(r.count);
62
- for (let t = 0; t < r.count; t++) {
63
- let n = l + t * i, s = r.type === a ? e.reader.bytes[n] : r.type === o ? e.reader.u16(n) : e.reader.u32(n);
64
- if (s == null) return null;
65
- u[t] = s;
66
- }
67
- return u;
68
- }
69
- function f(e, t, n) {
70
- return e.fields.has(t) ? e.fields.get(t).count === 1 ? d(e, t, 1)?.[0] ?? null : null : n ?? null;
71
- }
72
- function p(e, t) {
73
- return Math.round((255 - e) * (255 - t) / 255);
81
+ function y(e) {
82
+ return e === u ? 1 : e === d ? 2 : e === f ? 4 : 0;
74
83
  }
75
- function m(t) {
76
- let r = u(t);
77
- if (!r) return null;
78
- let i = f(r, c.width), a = f(r, c.height);
79
- if (i == null || a == null) return null;
80
- let o = i * a;
81
- if (i <= 0 || a <= 0 || i > 32767 || a > 32767 || o > 33554432) throw new n("image-pixels", e, o);
82
- let s = f(r, c.compression, 1), l = f(r, c.photometric), m = f(r, c.samplesPerPixel, 1), h = f(r, c.rowsPerStrip, 4294967295);
83
- if (s !== 1 || l == null || m == null || h == null || h < 1 || f(r, c.planarConfiguration, 1) !== 1 || f(r, c.orientation, 1) !== 1 || r.fields.has(c.extraSamples) || l !== 5 || m !== 4 || f(r, c.inkSet, 1) !== 1) return null;
84
- let g = r.fields.has(c.bitsPerSample) ? d(r, c.bitsPerSample, m) : [1];
85
- if (!g || g.length !== m || g.some((e) => e !== 8)) return null;
86
- let _ = Math.ceil(a / h), v = d(r, c.stripOffsets, _), y = d(r, c.stripByteCounts, _);
87
- if (!v || !y || v.length !== _ || y.length !== _) return null;
88
- let b = i * m;
89
- for (let e = 0; e < _; e++) {
90
- let t = e * h, n = Math.min(h, a - t) * b;
91
- if (y[e] < n || !r.reader.contains(v[e], n)) return null;
92
- }
93
- let x = new Uint8ClampedArray(o * 4);
94
- for (let e = 0; e < _; e++) {
95
- let n = e * h, r = Math.min(h, a - n);
96
- for (let a = 0; a < r; a++) {
97
- let r = v[e] + a * b, o = (n + a) * i * 4;
98
- for (let e = 0; e < i; e++, o += 4) {
99
- let e = t[r++], n = t[r++], i = t[r++], a = t[r++];
100
- x[o] = p(e, a), x[o + 1] = p(n, a), x[o + 2] = p(i, a), x[o + 3] = 255;
84
+ function b(e, t, n, r) {
85
+ let i = e.fields.get(t);
86
+ if (!i) return;
87
+ r.includes(i.type) || h(`Unsupported TIFF ${n} field type: ${i.type}`), i.count < 1 && h(`Malformed TIFF ${n}: empty value list`);
88
+ let a = y(i.type), o = i.count * a;
89
+ Number.isSafeInteger(o) || h(`Malformed TIFF ${n} value count`);
90
+ let s = o <= 4 ? i.entryOffset + 8 : e.reader.u32(i.entryOffset + 8, `${n} value offset`);
91
+ return e.reader.contains(s, o) || h(`Malformed TIFF ${n} value range`), {
92
+ count: i.count,
93
+ at(t) {
94
+ (!Number.isSafeInteger(t) || t < 0 || t >= i.count) && h(`Malformed TIFF ${n} value index`);
95
+ let r = s + t * a;
96
+ return i.type === u ? e.reader.u8(r, n) : i.type === d ? e.reader.u16(r, n) : e.reader.u32(r, n);
97
+ }
98
+ };
99
+ }
100
+ function x(e, t, n, r, i) {
101
+ let a = b(e, t, n, r);
102
+ if (!a) {
103
+ if (i !== void 0) return i;
104
+ h(`Malformed TIFF: missing ${n}`);
105
+ }
106
+ return a.count !== 1 && h(`Malformed TIFF ${n}: expected one value`), a.at(0);
107
+ }
108
+ function S(e, t, n, r, i) {
109
+ let a = b(e, t, n, r);
110
+ return a || h(`Malformed TIFF: missing ${n}`), a.count !== i && h(`Malformed TIFF ${n}: expected ${i} value${i === 1 ? "" : "s"}`), a;
111
+ }
112
+ function C(t, r) {
113
+ (t < 1 || r < 1) && h("Malformed TIFF: image dimensions must be positive");
114
+ let a = Math.max(t, r);
115
+ if (a > 134217728) throw new i("image-dimension", e, a);
116
+ let o = t * r;
117
+ if (o > 134217728) throw new i("image-pixels", n, Number.isSafeInteger(o) ? o : 2 ** 53 - 1);
118
+ }
119
+ function w(e, t) {
120
+ if (!e.fields.has(p.bitsPerSample)) return [1];
121
+ let n = S(e, p.bitsPerSample, "BitsPerSample", [d], t), r = Array(t);
122
+ for (let e = 0; e < t; e++) r[e] = n.at(e);
123
+ return r;
124
+ }
125
+ function T(e, t) {
126
+ if (!e.fields.has(p.sampleFormat)) return;
127
+ let n = S(e, p.sampleFormat, "SampleFormat", [d], t);
128
+ for (let e = 0; e < n.count; e++) n.at(e) !== 1 && h("Unsupported TIFF SampleFormat: only unsigned integers are supported");
129
+ }
130
+ function E(e, t) {
131
+ let n = x(e, p.compression, "Compression", [d], 1);
132
+ n !== 1 && n !== 4 && h(`Unsupported TIFF compression: ${n}`);
133
+ let r = x(e, p.photometric, "PhotometricInterpretation", [d]), i = x(e, p.samplesPerPixel, "SamplesPerPixel", [d], 1);
134
+ i !== 1 && i !== 3 && i !== 4 && h(`Unsupported TIFF SamplesPerPixel: ${i}`);
135
+ let a = w(e, i);
136
+ if (T(e, i), n === 4) {
137
+ (i !== 1 || a.length !== 1 || a[0] !== 1 || r !== 0 && r !== 1) && h("Unsupported CCITT Group 4 TIFF sample layout"), e.fields.has(p.extraSamples) && h("Unsupported CCITT Group 4 TIFF ExtraSamples");
138
+ let t = x(e, p.t6Options, "T6Options", [f], 0);
139
+ return t !== 0 && h(`Unsupported TIFF T6Options: ${t}`), {
140
+ compression: n,
141
+ layout: {
142
+ kind: "group4",
143
+ photometric: r
144
+ }
145
+ };
146
+ }
147
+ if (r === 0 || r === 1) {
148
+ if ((i !== 1 || e.fields.has(p.extraSamples)) && h("Unsupported TIFF grayscale sample layout"), a[0] === 1) return {
149
+ compression: n,
150
+ layout: {
151
+ kind: "gray-1",
152
+ photometric: r,
153
+ bytesPerRow: Math.ceil(t / 8)
154
+ }
155
+ };
156
+ if (a[0] === 8) return {
157
+ compression: n,
158
+ layout: {
159
+ kind: "gray-8",
160
+ photometric: r,
161
+ bytesPerRow: t
162
+ }
163
+ };
164
+ h(`Unsupported TIFF grayscale BitsPerSample: ${a[0]}`);
165
+ }
166
+ if (r === 2) {
167
+ if (a.some((e) => e !== 8) && h("Unsupported TIFF RGB BitsPerSample: only 8-bit samples are supported"), i === 3) return e.fields.has(p.extraSamples) && h("Unsupported TIFF RGB ExtraSamples"), {
168
+ compression: n,
169
+ layout: {
170
+ kind: "rgb",
171
+ bytesPerRow: t * 3
101
172
  }
173
+ };
174
+ if (i === 4) {
175
+ let r = S(e, p.extraSamples, "ExtraSamples", [d], 1).at(0);
176
+ if (r === 1) return {
177
+ compression: n,
178
+ layout: {
179
+ kind: "rgba-associated",
180
+ bytesPerRow: t * 4
181
+ }
182
+ };
183
+ if (r === 2) return {
184
+ compression: n,
185
+ layout: {
186
+ kind: "rgba-unassociated",
187
+ bytesPerRow: t * 4
188
+ }
189
+ };
190
+ h(`Unsupported TIFF ExtraSamples value: ${r}`);
191
+ }
192
+ h(`Unsupported TIFF RGB SamplesPerPixel: ${i}`);
193
+ }
194
+ if (r === 5) {
195
+ (i !== 4 || a.length !== 4 || a.some((e) => e !== 8)) && h("Unsupported TIFF separated sample layout: expected 8-bit process CMYK"), e.fields.has(p.extraSamples) && h("Unsupported TIFF CMYK ExtraSamples");
196
+ let r = x(e, p.inkSet, "InkSet", [d], 1);
197
+ return r !== 1 && h(`Unsupported TIFF InkSet: ${r}`), {
198
+ compression: n,
199
+ layout: {
200
+ kind: "cmyk",
201
+ bytesPerRow: t * 4
202
+ }
203
+ };
204
+ }
205
+ h(`Unsupported TIFF PhotometricInterpretation: ${r}`);
206
+ }
207
+ function D(e) {
208
+ let t = v(e);
209
+ if (!t) return null;
210
+ let n = x(t, p.width, "ImageWidth", [d, f]), r = x(t, p.height, "ImageLength", [d, f]);
211
+ C(n, r), m.some((e) => t.fields.has(e)) && h("Unsupported tiled TIFF: only stripped images are supported");
212
+ let i = x(t, p.orientation, "Orientation", [d], 1);
213
+ i !== 1 && h(`Unsupported TIFF orientation: ${i}`);
214
+ let a = x(t, p.planarConfiguration, "PlanarConfiguration", [d], 1);
215
+ a !== 1 && h(`Unsupported TIFF PlanarConfiguration: ${a}`);
216
+ let o = x(t, p.fillOrder, "FillOrder", [d], 1);
217
+ o !== 1 && h(`Unsupported TIFF FillOrder: ${o}`);
218
+ let s = x(t, p.predictor, "Predictor", [d], 1);
219
+ s !== 1 && h(`Unsupported TIFF Predictor: ${s}`);
220
+ let c = x(t, p.rowsPerStrip, "RowsPerStrip", [d, f], 4294967295);
221
+ c < 1 && h("Malformed TIFF RowsPerStrip: expected a positive value");
222
+ let l = Math.ceil(r / c), u = S(t, p.stripOffsets, "StripOffsets", [d, f], l), g = S(t, p.stripByteCounts, "StripByteCounts", [d, f], l), { compression: _, layout: y } = E(t, n);
223
+ for (let e = 0; e < l; e++) {
224
+ let n = u.at(e), i = g.at(e);
225
+ if (t.reader.contains(n, i) || h(`Malformed TIFF strip ${e} byte range`), _ === 1) {
226
+ let t = e * c, n = Math.min(c, r - t) * y.bytesPerRow;
227
+ i < n && h(`Malformed TIFF strip ${e}: ${i} bytes cannot hold ${n} bytes`);
102
228
  }
103
229
  }
104
230
  return {
105
- width: i,
106
- height: a,
107
- data: x
231
+ directory: t,
232
+ width: n,
233
+ height: r,
234
+ rowsPerStrip: c,
235
+ stripCount: l,
236
+ stripOffsets: u,
237
+ stripByteCounts: g,
238
+ layout: y
108
239
  };
109
240
  }
110
- async function h(e) {
111
- let n = m(e);
112
- if (!n) return null;
113
- let r = t(n.width, n.height);
241
+ function O(e, t) {
242
+ if (e !== void 0) return (!Number.isFinite(e) || e <= 0) && h(`Invalid TIFF ${t}: expected a positive finite number`), e;
243
+ }
244
+ function k(e, n, a) {
245
+ let o = O(a.targetWidthPx, "targetWidthPx"), s = O(a.targetHeightPx, "targetHeightPx"), l = c({
246
+ width: e,
247
+ height: n
248
+ }, o, s, !0), u = l?.width ?? e, d = l?.height ?? n, f = Math.max(u, d);
249
+ if (f > 32767) throw new i("image-dimension", r, f);
250
+ let p = a.maxRetainedPixels ?? 33554432;
251
+ (!Number.isFinite(p) || p < 0) && h("Invalid TIFF maxRetainedPixels: expected a non-negative finite number");
252
+ let m = Math.min(t, Math.floor(p)), g = u * d;
253
+ if (g > m) throw new i("image-pixels", m, g);
254
+ return {
255
+ width: u,
256
+ height: d,
257
+ pixels: g
258
+ };
259
+ }
260
+ function A(e, t) {
261
+ return Math.round((255 - e) * (255 - t) / 255);
262
+ }
263
+ function j(e, t) {
264
+ return t === 0 ? 0 : Math.min(255, Math.round(e * 255 / t));
265
+ }
266
+ function M(e, t) {
267
+ let n = e.layout, r = e.directory.reader.bytes;
268
+ for (let i = 0; i < e.height; i++) {
269
+ let a = Math.floor(i / e.rowsPerStrip), o = i - a * e.rowsPerStrip, s = e.stripOffsets.at(a) + o * n.bytesPerRow;
270
+ for (let a = 0; a < e.width; a++) {
271
+ let o = (i * e.width + a) * 4;
272
+ if (n.kind === "gray-1") {
273
+ let e = r[s + (a >> 3)] >> 7 - (a & 7) & 1, i = n.photometric === 0 ? e === 0 ? 255 : 0 : e === 0 ? 0 : 255;
274
+ t[o] = i, t[o + 1] = i, t[o + 2] = i, t[o + 3] = 255;
275
+ continue;
276
+ }
277
+ if (n.kind === "gray-8") {
278
+ let e = r[s + a], i = n.photometric === 0 ? 255 - e : e;
279
+ t[o] = i, t[o + 1] = i, t[o + 2] = i, t[o + 3] = 255;
280
+ continue;
281
+ }
282
+ if (n.kind === "rgb") {
283
+ let e = s + a * 3;
284
+ t[o] = r[e], t[o + 1] = r[e + 1], t[o + 2] = r[e + 2], t[o + 3] = 255;
285
+ continue;
286
+ }
287
+ if (n.kind === "rgba-associated" || n.kind === "rgba-unassociated") {
288
+ let e = s + a * 4, i = r[e + 3];
289
+ t[o] = n.kind === "rgba-associated" ? j(r[e], i) : r[e], t[o + 1] = n.kind === "rgba-associated" ? j(r[e + 1], i) : r[e + 1], t[o + 2] = n.kind === "rgba-associated" ? j(r[e + 2], i) : r[e + 2], t[o + 3] = i;
290
+ continue;
291
+ }
292
+ let c = s + a * 4, l = r[c + 3];
293
+ t[o] = A(r[c], l), t[o + 1] = A(r[c + 1], l), t[o + 2] = A(r[c + 2], l), t[o + 3] = 255;
294
+ }
295
+ }
296
+ }
297
+ function N(e) {
298
+ return Math.max(0, Math.min(255, Math.round(e)));
299
+ }
300
+ function P(e, t, n, r, i) {
301
+ let a = e.layout, o = e.directory.reader.bytes;
302
+ for (let s = 0; s < t.width; s++) {
303
+ let c = s * e.width, l = (s + 1) * e.width, u = Math.floor(c / t.width), d = Math.floor((l - 1) / t.width), f = 0, p = 0, m = 0, h = 0;
304
+ for (let e = u; e <= d; e++) {
305
+ let i = e * t.width, s = (e + 1) * t.width, u = (Math.min(l, s) - Math.max(c, i)) * r, d, g, _, v = 255;
306
+ if (a.kind === "gray-1") {
307
+ let t = o[n + (e >> 3)] >> 7 - (e & 7) & 1;
308
+ d = a.photometric === 0 ? t === 0 ? 255 : 0 : t === 0 ? 0 : 255, g = d, _ = d;
309
+ } else if (a.kind === "gray-8") {
310
+ let t = o[n + e];
311
+ d = a.photometric === 0 ? 255 - t : t, g = d, _ = d;
312
+ } else if (a.kind === "rgb") {
313
+ let t = n + e * 3;
314
+ d = o[t], g = o[t + 1], _ = o[t + 2];
315
+ } else if (a.kind === "rgba-associated") {
316
+ let t = n + e * 4;
317
+ v = o[t + 3], d = v === 0 ? 0 : o[t] * 255, g = v === 0 ? 0 : o[t + 1] * 255, _ = v === 0 ? 0 : o[t + 2] * 255;
318
+ } else if (a.kind === "rgba-unassociated") {
319
+ let t = n + e * 4;
320
+ v = o[t + 3], d = o[t] * v, g = o[t + 1] * v, _ = o[t + 2] * v;
321
+ } else {
322
+ let t = n + e * 4, r = o[t + 3];
323
+ d = A(o[t], r), g = A(o[t + 1], r), _ = A(o[t + 2], r);
324
+ }
325
+ a.kind !== "rgba-associated" && a.kind !== "rgba-unassociated" && (d *= 255, g *= 255, _ *= 255), f += d * u, p += g * u, m += _ * u, h += v * u;
326
+ }
327
+ let g = s * 4;
328
+ i[g] += f, i[g + 1] += p, i[g + 2] += m, i[g + 3] += h;
329
+ }
330
+ }
331
+ function F(e, t, n, r, i) {
332
+ for (let a = 0; a < n; a++) {
333
+ let o = a * 4, s = (r * n + a) * 4, c = e[o + 3];
334
+ t[s] = c === 0 ? 0 : N(e[o] / c), t[s + 1] = c === 0 ? 0 : N(e[o + 1] / c), t[s + 2] = c === 0 ? 0 : N(e[o + 2] / c), t[s + 3] = N(c / i);
335
+ }
336
+ }
337
+ function I(e, t, n) {
338
+ let r = e.layout, i = new Float64Array(t.width * 4), a = e.width * e.height, o = -1;
339
+ for (let s = 0; s < e.height; s++) {
340
+ let c = Math.floor(s / e.rowsPerStrip), l = s - c * e.rowsPerStrip, u = e.stripOffsets.at(c) + l * r.bytesPerRow, d = s * t.height, f = (s + 1) * t.height, p = Math.floor(d / e.height), m = Math.floor((f - 1) / e.height);
341
+ for (let r = p; r <= m; r++) {
342
+ r !== o && (o >= 0 && (F(i, n, t.width, o, a), i.fill(0)), r !== o + 1 && h("Internal TIFF area-row sequence failure"), o = r);
343
+ let s = r * e.height, c = (r + 1) * e.height;
344
+ P(e, t, u, Math.min(f, c) - Math.max(d, s), i);
345
+ }
346
+ }
347
+ o !== t.height - 1 && h("Internal TIFF area-row coverage failure"), F(i, n, t.width, o, a);
348
+ }
349
+ function L(e, t, n) {
350
+ t.width === e.width && t.height === e.height ? M(e, n) : I(e, t, n);
351
+ }
352
+ var R = class {
353
+ bitOffset = 0;
354
+ constructor(e, t, n) {
355
+ this.bytes = e, this.byteOffset = t, this.byteLength = n;
356
+ }
357
+ readBit() {
358
+ this.bitOffset >= this.byteLength * 8 && h("CCITT Group 4 data is truncated");
359
+ let e = this.bytes[this.byteOffset + (this.bitOffset >> 3)] >> 7 - (this.bitOffset & 7) & 1;
360
+ return this.bitOffset++, e;
361
+ }
362
+ }, z = [
363
+ ["00000001000", 1792],
364
+ ["00000001100", 1856],
365
+ ["00000001101", 1920],
366
+ ["000000010010", 1984],
367
+ ["000000010011", 2048],
368
+ ["000000010100", 2112],
369
+ ["000000010101", 2176],
370
+ ["000000010110", 2240],
371
+ ["000000010111", 2304],
372
+ ["000000011100", 2368],
373
+ ["000000011101", 2432],
374
+ ["000000011110", 2496],
375
+ ["000000011111", 2560]
376
+ ], B = [
377
+ ["00110101", 0],
378
+ ["000111", 1],
379
+ ["0111", 2],
380
+ ["1000", 3],
381
+ ["1011", 4],
382
+ ["1100", 5],
383
+ ["1110", 6],
384
+ ["1111", 7],
385
+ ["10011", 8],
386
+ ["10100", 9],
387
+ ["00111", 10],
388
+ ["01000", 11],
389
+ ["001000", 12],
390
+ ["000011", 13],
391
+ ["110100", 14],
392
+ ["110101", 15],
393
+ ["101010", 16],
394
+ ["101011", 17],
395
+ ["0100111", 18],
396
+ ["0001100", 19],
397
+ ["0001000", 20],
398
+ ["0010111", 21],
399
+ ["0000011", 22],
400
+ ["0000100", 23],
401
+ ["0101000", 24],
402
+ ["0101011", 25],
403
+ ["0010011", 26],
404
+ ["0100100", 27],
405
+ ["0011000", 28],
406
+ ["00000010", 29],
407
+ ["00000011", 30],
408
+ ["00011010", 31],
409
+ ["00011011", 32],
410
+ ["00010010", 33],
411
+ ["00010011", 34],
412
+ ["00010100", 35],
413
+ ["00010101", 36],
414
+ ["00010110", 37],
415
+ ["00010111", 38],
416
+ ["00101000", 39],
417
+ ["00101001", 40],
418
+ ["00101010", 41],
419
+ ["00101011", 42],
420
+ ["00101100", 43],
421
+ ["00101101", 44],
422
+ ["00000100", 45],
423
+ ["00000101", 46],
424
+ ["00001010", 47],
425
+ ["00001011", 48],
426
+ ["01010010", 49],
427
+ ["01010011", 50],
428
+ ["01010100", 51],
429
+ ["01010101", 52],
430
+ ["00100100", 53],
431
+ ["00100101", 54],
432
+ ["01011000", 55],
433
+ ["01011001", 56],
434
+ ["01011010", 57],
435
+ ["01011011", 58],
436
+ ["01001010", 59],
437
+ ["01001011", 60],
438
+ ["00110010", 61],
439
+ ["00110011", 62],
440
+ ["00110100", 63],
441
+ ["11011", 64],
442
+ ["10010", 128],
443
+ ["010111", 192],
444
+ ["0110111", 256],
445
+ ["00110110", 320],
446
+ ["00110111", 384],
447
+ ["01100100", 448],
448
+ ["01100101", 512],
449
+ ["01101000", 576],
450
+ ["01100111", 640],
451
+ ["011001100", 704],
452
+ ["011001101", 768],
453
+ ["011010010", 832],
454
+ ["011010011", 896],
455
+ ["011010100", 960],
456
+ ["011010101", 1024],
457
+ ["011010110", 1088],
458
+ ["011010111", 1152],
459
+ ["011011000", 1216],
460
+ ["011011001", 1280],
461
+ ["011011010", 1344],
462
+ ["011011011", 1408],
463
+ ["010011000", 1472],
464
+ ["010011001", 1536],
465
+ ["010011010", 1600],
466
+ ["011000", 1664],
467
+ ["010011011", 1728],
468
+ ...z
469
+ ], V = [
470
+ ["0000110111", 0],
471
+ ["010", 1],
472
+ ["11", 2],
473
+ ["10", 3],
474
+ ["011", 4],
475
+ ["0011", 5],
476
+ ["0010", 6],
477
+ ["00011", 7],
478
+ ["000101", 8],
479
+ ["000100", 9],
480
+ ["0000100", 10],
481
+ ["0000101", 11],
482
+ ["0000111", 12],
483
+ ["00000100", 13],
484
+ ["00000111", 14],
485
+ ["000011000", 15],
486
+ ["0000010111", 16],
487
+ ["0000011000", 17],
488
+ ["0000001000", 18],
489
+ ["00001100111", 19],
490
+ ["00001101000", 20],
491
+ ["00001101100", 21],
492
+ ["00000110111", 22],
493
+ ["00000101000", 23],
494
+ ["00000010111", 24],
495
+ ["00000011000", 25],
496
+ ["000011001010", 26],
497
+ ["000011001011", 27],
498
+ ["000011001100", 28],
499
+ ["000011001101", 29],
500
+ ["000001101000", 30],
501
+ ["000001101001", 31],
502
+ ["000001101010", 32],
503
+ ["000001101011", 33],
504
+ ["000011010010", 34],
505
+ ["000011010011", 35],
506
+ ["000011010100", 36],
507
+ ["000011010101", 37],
508
+ ["000011010110", 38],
509
+ ["000011010111", 39],
510
+ ["000001101100", 40],
511
+ ["000001101101", 41],
512
+ ["000011011010", 42],
513
+ ["000011011011", 43],
514
+ ["000001010100", 44],
515
+ ["000001010101", 45],
516
+ ["000001010110", 46],
517
+ ["000001010111", 47],
518
+ ["000001100100", 48],
519
+ ["000001100101", 49],
520
+ ["000001010010", 50],
521
+ ["000001010011", 51],
522
+ ["000000100100", 52],
523
+ ["000000110111", 53],
524
+ ["000000111000", 54],
525
+ ["000000100111", 55],
526
+ ["000000101000", 56],
527
+ ["000001011000", 57],
528
+ ["000001011001", 58],
529
+ ["000000101011", 59],
530
+ ["000000101100", 60],
531
+ ["000001011010", 61],
532
+ ["000001100110", 62],
533
+ ["000001100111", 63],
534
+ ["0000001111", 64],
535
+ ["000011001000", 128],
536
+ ["000011001001", 192],
537
+ ["000001011011", 256],
538
+ ["000000110011", 320],
539
+ ["000000110100", 384],
540
+ ["000000110101", 448],
541
+ ["0000001101100", 512],
542
+ ["0000001101101", 576],
543
+ ["0000001001010", 640],
544
+ ["0000001001011", 704],
545
+ ["0000001001100", 768],
546
+ ["0000001001101", 832],
547
+ ["0000001110010", 896],
548
+ ["0000001110011", 960],
549
+ ["0000001110100", 1024],
550
+ ["0000001110101", 1088],
551
+ ["0000001110110", 1152],
552
+ ["0000001110111", 1216],
553
+ ["0000001010010", 1280],
554
+ ["0000001010011", 1344],
555
+ ["0000001010100", 1408],
556
+ ["0000001010101", 1472],
557
+ ["0000001011010", 1536],
558
+ ["0000001011011", 1600],
559
+ ["0000001100100", 1664],
560
+ ["0000001100101", 1728],
561
+ ...z
562
+ ];
563
+ function H(e) {
564
+ let t = /* @__PURE__ */ new Map();
565
+ for (let [n, r] of e) t.set(1 << n.length | Number.parseInt(n, 2), r);
566
+ return t;
567
+ }
568
+ var U = H(B), W = H(V), G = new Map([
569
+ [3, 0],
570
+ [9, "horizontal"],
571
+ [10, -1],
572
+ [11, 1],
573
+ [17, "pass"],
574
+ [66, -2],
575
+ [67, 2],
576
+ [130, -3],
577
+ [131, 3]
578
+ ]);
579
+ function K(e) {
580
+ let t = 0;
581
+ for (let n = 1; n <= 7; n++) {
582
+ t = t << 1 | e.readBit();
583
+ let r = G.get(1 << n | t);
584
+ if (r !== void 0) return r;
585
+ }
586
+ h("Invalid or unsupported CCITT Group 4 two-dimensional mode");
587
+ }
588
+ function q(e, t, n) {
589
+ let r = t ? W : U, i = 0, a = Math.ceil(n / 64) + 64;
590
+ for (let t = 0; t < a; t++) {
591
+ let t = 0, a;
592
+ for (let n = 1; n <= 13 && (t = t << 1 | e.readBit(), a = r.get(1 << n | t), a === void 0); n++);
593
+ if (a === void 0 && h("Invalid CCITT Group 4 run-length code"), i += a, i > n && h("CCITT Group 4 run exceeds the scanline width"), a < 64) return i;
594
+ }
595
+ h("CCITT Group 4 run-length code limit exceeded");
596
+ }
597
+ var J = r + 1;
598
+ function Y(e, t) {
599
+ let n = e[e.length - 1];
600
+ n !== void 0 && n > t && h("Internal TIFF Group 4 changing-element order failure"), n === t ? e.pop() : (e.length >= J && h("CCITT Group 4 changing-element limit exceeded"), e.push(t));
601
+ }
602
+ function X(e, t, n, r, i, a, o) {
603
+ let s = i ? n : n + 1;
604
+ for (; a.index < e.length && (o && o.referenceProbeCount++, !(e[a.index] >= s));) a.index++;
605
+ let c = a.index;
606
+ return c < e.length && (c + 1 & 1) != (r ^ 1) && c++, [e[c] ?? t, e[c + 1] ?? t];
607
+ }
608
+ function Z(e, t, n, r, i) {
609
+ n.length = 0;
610
+ let a = 0, o = 0, s = !0, c = { index: 0 }, l = r * 4 + 32;
611
+ for (let u = 0; a < r; u++) {
612
+ u >= l && h("CCITT Group 4 scanline operation limit exceeded"), i && i.modeCount++;
613
+ let d = K(e);
614
+ if (d === "horizontal") {
615
+ let t = q(e, o === 1, r - a), i = a + t, c = i + q(e, o === 0, r - i);
616
+ c <= a && h("Invalid CCITT Group 4 horizontal mode with no progress"), Y(n, i), Y(n, c), a = c, s = !1;
617
+ continue;
618
+ }
619
+ let [f, p] = X(t, r, a, o, s, c, i);
620
+ if (d === "pass") {
621
+ p <= a && h("Invalid CCITT Group 4 pass mode with no progress"), a = p, s = !1;
622
+ continue;
623
+ }
624
+ let m = f + d;
625
+ (m < a || m > r) && h("Invalid CCITT Group 4 vertical mode position"), Y(n, m), a = m, o ^= 1, s = !1;
626
+ }
627
+ n[n.length - 1] !== r && (n.length >= J && h("CCITT Group 4 changing-element limit exceeded"), n.push(r));
628
+ }
629
+ function Q(e, t, n, r, i) {
630
+ let a = 0;
631
+ for (let o = 0; o < e.length; o++) {
632
+ let s = e[o], c = o & 1, l = i === 0 ? c === 0 ? 255 : 0 : c === 0 ? 0 : 255;
633
+ for (let e = a; e < s; e++) {
634
+ let i = (r * n + e) * 4;
635
+ t[i] = l, t[i + 1] = l, t[i + 2] = l, t[i + 3] = 255;
636
+ }
637
+ a = s;
638
+ }
639
+ }
640
+ function $(e, t, n, r, i, a, o) {
641
+ let s = 0, c = n[0] * t.width;
642
+ for (let l = 0; l < t.width; l++) {
643
+ let u = l * e.width, d = (l + 1) * e.width, f = u;
644
+ for (; f < d;) {
645
+ for (o && o.areaSegmentCount++; c <= f && s + 1 < n.length;) s++, c = n[s] * t.width;
646
+ let e = Math.min(d, c);
647
+ e <= f && h("Internal TIFF Group 4 area-run coverage failure");
648
+ let u = s & 1, p = r === 0 ? u === 0 ? 255 : 0 : u === 0 ? 0 : 255, m = (e - f) * i, g = l * 4, _ = p * 255 * m;
649
+ a[g] += _, a[g + 1] += _, a[g + 2] += _, a[g + 3] += 255 * m, f = e;
650
+ }
651
+ }
652
+ }
653
+ function ee(e, t, n, r) {
654
+ let i = e.layout, a = [e.width], o = [], s = t.width !== e.width || t.height !== e.height ? new Float64Array(t.width * 4) : null, c = e.width * e.height, l = -1;
655
+ for (let u = 0; u < e.stripCount; u++) {
656
+ a.length = 1, a[0] = e.width;
657
+ let d = u * e.rowsPerStrip, f = Math.min(e.rowsPerStrip, e.height - d), p = new R(e.directory.reader.bytes, e.stripOffsets.at(u), e.stripByteCounts.at(u));
658
+ for (let u = 0; u < f; u++) {
659
+ let f = d + u;
660
+ if (Z(p, a, o, e.width, r), !s) Q(o, n, e.width, f, i.photometric);
661
+ else {
662
+ let a = f * t.height, u = (f + 1) * t.height, d = Math.floor(a / e.height), p = Math.floor((u - 1) / e.height);
663
+ for (let f = d; f <= p; f++) {
664
+ f !== l && (l >= 0 && (F(s, n, t.width, l, c), s.fill(0)), f !== l + 1 && h("Internal TIFF Group 4 area-row sequence failure"), l = f);
665
+ let d = f * e.height, p = (f + 1) * e.height, m = Math.min(u, p) - Math.max(a, d);
666
+ $(e, t, o, i.photometric, m, s, r);
667
+ }
668
+ }
669
+ [a, o] = [o, a];
670
+ }
671
+ }
672
+ s && (l !== t.height - 1 && h("Internal TIFF Group 4 area-row coverage failure"), F(s, n, t.width, l, c));
673
+ }
674
+ function te(e, t, n) {
675
+ let r = D(e);
114
676
  if (!r) return null;
115
- let i = r.getContext("2d");
116
- if (!i) return null;
117
- let a = i.createImageData(n.width, n.height);
118
- return a.data.set(n.data), i.putImageData(a, 0, 0), createImageBitmap(r);
677
+ let i = k(r.width, r.height, t), a = new Uint8ClampedArray(i.pixels * 4);
678
+ return r.layout.kind === "group4" ? ee(r, i, a, n) : L(r, i, a), {
679
+ width: i.width,
680
+ height: i.height,
681
+ data: a
682
+ };
683
+ }
684
+ function ne(e, t = {}) {
685
+ return te(e, t);
686
+ }
687
+ async function re(e, t = {}) {
688
+ let n = ne(e, t);
689
+ if (!n) return null;
690
+ typeof ImageData != "function" && h("TIFF ImageData construction is unavailable");
691
+ let r;
692
+ try {
693
+ r = new ImageData(n.data, n.width, n.height);
694
+ } catch (e) {
695
+ h("TIFF ImageData construction failed", e);
696
+ }
697
+ typeof createImageBitmap != "function" && h("TIFF ImageBitmap creation is unavailable");
698
+ let i;
699
+ try {
700
+ i = await createImageBitmap(r);
701
+ } catch (e) {
702
+ h("TIFF ImageBitmap creation failed", e);
703
+ }
704
+ return i || h("TIFF ImageBitmap creation returned no bitmap"), i;
119
705
  }
120
706
  //#endregion
121
707
  //#region src/tiff.ts
122
- var g = i({ render: h }, "tiff");
708
+ var ie = l({ render: re }, "tiff");
123
709
  //#endregion
124
- export { g as tiff };
710
+ export { a as TiffDecodeError, s as isTiffDecodeError, ie as tiff };