@opengeni/artifact-tool 0.2.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.
Files changed (203) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +104 -0
  3. package/dist/bounded-zip.d.ts +28 -0
  4. package/dist/chunk-4BSENMAE.js +39 -0
  5. package/dist/chunk-4BSENMAE.js.map +1 -0
  6. package/dist/chunk-4FRFNNBM.js +276 -0
  7. package/dist/chunk-4FRFNNBM.js.map +1 -0
  8. package/dist/chunk-5XIA6KHZ.js +49 -0
  9. package/dist/chunk-5XIA6KHZ.js.map +1 -0
  10. package/dist/chunk-66CT2ZRP.js +2229 -0
  11. package/dist/chunk-66CT2ZRP.js.map +1 -0
  12. package/dist/chunk-72SYDU4O.js +319 -0
  13. package/dist/chunk-72SYDU4O.js.map +1 -0
  14. package/dist/chunk-B2ZJRZDA.js +279 -0
  15. package/dist/chunk-B2ZJRZDA.js.map +1 -0
  16. package/dist/chunk-DCTLTNPW.js +2458 -0
  17. package/dist/chunk-DCTLTNPW.js.map +1 -0
  18. package/dist/chunk-FGZM4FQ6.js +473 -0
  19. package/dist/chunk-FGZM4FQ6.js.map +1 -0
  20. package/dist/chunk-HTJBLBDE.js +591 -0
  21. package/dist/chunk-HTJBLBDE.js.map +1 -0
  22. package/dist/chunk-IYFXZQ34.js +5306 -0
  23. package/dist/chunk-IYFXZQ34.js.map +1 -0
  24. package/dist/chunk-J6N7IR44.js +172 -0
  25. package/dist/chunk-J6N7IR44.js.map +1 -0
  26. package/dist/chunk-N2IHNWBS.js +1002 -0
  27. package/dist/chunk-N2IHNWBS.js.map +1 -0
  28. package/dist/chunk-NAG44K67.js +549 -0
  29. package/dist/chunk-NAG44K67.js.map +1 -0
  30. package/dist/chunk-O24KTEGP.js +33 -0
  31. package/dist/chunk-O24KTEGP.js.map +1 -0
  32. package/dist/chunk-PI2AZVGK.js +2074 -0
  33. package/dist/chunk-PI2AZVGK.js.map +1 -0
  34. package/dist/chunk-Q2FFHEY7.js +40 -0
  35. package/dist/chunk-Q2FFHEY7.js.map +1 -0
  36. package/dist/chunk-RBGQADXA.js +57 -0
  37. package/dist/chunk-RBGQADXA.js.map +1 -0
  38. package/dist/chunk-U5G2BKM2.js +613 -0
  39. package/dist/chunk-U5G2BKM2.js.map +1 -0
  40. package/dist/chunk-VOJHMSM3.js +39 -0
  41. package/dist/chunk-VOJHMSM3.js.map +1 -0
  42. package/dist/chunk-VUNV25KB.js +16 -0
  43. package/dist/chunk-VUNV25KB.js.map +1 -0
  44. package/dist/chunk-XIFUNVBO.js +101 -0
  45. package/dist/chunk-XIFUNVBO.js.map +1 -0
  46. package/dist/chunk-ZCJYRJGB.js +489 -0
  47. package/dist/chunk-ZCJYRJGB.js.map +1 -0
  48. package/dist/chunk-ZZXPEE4S.js +2260 -0
  49. package/dist/chunk-ZZXPEE4S.js.map +1 -0
  50. package/dist/document-docx-api.d.ts +49 -0
  51. package/dist/document-docx-codec.d.ts +9 -0
  52. package/dist/document-docx-codec.js +4765 -0
  53. package/dist/document-docx-codec.js.map +1 -0
  54. package/dist/document-docx-import.d.ts +261 -0
  55. package/dist/document-docx-packer.d.ts +18 -0
  56. package/dist/document-docx-state.d.ts +12 -0
  57. package/dist/document-render.d.ts +3 -0
  58. package/dist/document-render.js +492 -0
  59. package/dist/document-render.js.map +1 -0
  60. package/dist/document.d.ts +432 -0
  61. package/dist/document.js +37 -0
  62. package/dist/document.js.map +1 -0
  63. package/dist/errors.d.ts +23 -0
  64. package/dist/file-blob.d.ts +11 -0
  65. package/dist/index.d.ts +4 -0
  66. package/dist/index.js +186 -0
  67. package/dist/index.js.map +1 -0
  68. package/dist/inspection.d.ts +12 -0
  69. package/dist/kernel.d.ts +101 -0
  70. package/dist/lib-GQLPACFK.js +9746 -0
  71. package/dist/lib-GQLPACFK.js.map +1 -0
  72. package/dist/materializer-cli-entry.d.ts +2 -0
  73. package/dist/materializer-cli-entry.js +29 -0
  74. package/dist/materializer-cli-entry.js.map +1 -0
  75. package/dist/materializer-cli.d.ts +24 -0
  76. package/dist/materializer-cli.js +24 -0
  77. package/dist/materializer-cli.js.map +1 -0
  78. package/dist/native-raster.d.ts +10 -0
  79. package/dist/native.d.ts +129 -0
  80. package/dist/native.js +31 -0
  81. package/dist/native.js.map +1 -0
  82. package/dist/office-import.d.ts +48 -0
  83. package/dist/office-import.js +154 -0
  84. package/dist/office-import.js.map +1 -0
  85. package/dist/presentation-pptx-api.d.ts +60 -0
  86. package/dist/presentation-pptx-import.d.ts +5 -0
  87. package/dist/presentation-pptx-state-digest-765CZZED.js +10 -0
  88. package/dist/presentation-pptx-state-digest-765CZZED.js.map +1 -0
  89. package/dist/presentation-pptx-state-digest.d.ts +3 -0
  90. package/dist/presentation-pptx-state.d.ts +4 -0
  91. package/dist/presentation-pptx-xml.d.ts +29 -0
  92. package/dist/presentation-pptx.d.ts +5 -0
  93. package/dist/presentation-pptx.js +2365 -0
  94. package/dist/presentation-pptx.js.map +1 -0
  95. package/dist/presentation-render.d.ts +29 -0
  96. package/dist/presentation-render.js +375 -0
  97. package/dist/presentation-render.js.map +1 -0
  98. package/dist/presentation.d.ts +565 -0
  99. package/dist/presentation.js +71 -0
  100. package/dist/presentation.js.map +1 -0
  101. package/dist/production-composite.d.ts +68 -0
  102. package/dist/production-document.d.ts +2 -0
  103. package/dist/production-document.js +176 -0
  104. package/dist/production-document.js.map +1 -0
  105. package/dist/production-native-codecs.d.ts +94 -0
  106. package/dist/production-presentation.d.ts +2 -0
  107. package/dist/production-presentation.js +176 -0
  108. package/dist/production-presentation.js.map +1 -0
  109. package/dist/production-sha256.d.ts +2 -0
  110. package/dist/production-spreadsheet-native.d.ts +12 -0
  111. package/dist/production-spreadsheet.d.ts +2 -0
  112. package/dist/production-spreadsheet.js +176 -0
  113. package/dist/production-spreadsheet.js.map +1 -0
  114. package/dist/production.d.ts +96 -0
  115. package/dist/raster-image.d.ts +34 -0
  116. package/dist/reference.d.ts +17 -0
  117. package/dist/reference.js +574 -0
  118. package/dist/reference.js.map +1 -0
  119. package/dist/runtime-cli-entry.d.ts +2 -0
  120. package/dist/runtime-cli-entry.js +21 -0
  121. package/dist/runtime-cli-entry.js.map +1 -0
  122. package/dist/runtime-cli.d.ts +76 -0
  123. package/dist/runtime-cli.js +26 -0
  124. package/dist/runtime-cli.js.map +1 -0
  125. package/dist/runtime-development.d.ts +73 -0
  126. package/dist/runtime-development.js +30 -0
  127. package/dist/runtime-development.js.map +1 -0
  128. package/dist/runtime-receipt.d.ts +19 -0
  129. package/dist/runtime.d.ts +355 -0
  130. package/dist/runtime.js +42 -0
  131. package/dist/runtime.js.map +1 -0
  132. package/dist/snapshot.d.ts +26 -0
  133. package/dist/snapshot.js +61 -0
  134. package/dist/snapshot.js.map +1 -0
  135. package/dist/spreadsheet-address.d.ts +18 -0
  136. package/dist/spreadsheet-file.d.ts +17 -0
  137. package/dist/spreadsheet-formula.d.ts +67 -0
  138. package/dist/spreadsheet-image.d.ts +17 -0
  139. package/dist/spreadsheet-render.d.ts +5 -0
  140. package/dist/spreadsheet-render.js +752 -0
  141. package/dist/spreadsheet-render.js.map +1 -0
  142. package/dist/spreadsheet-types.d.ts +155 -0
  143. package/dist/spreadsheet-xlsx-api.d.ts +88 -0
  144. package/dist/spreadsheet-xlsx-codec.d.ts +16 -0
  145. package/dist/spreadsheet-xlsx-codec.js +16 -0
  146. package/dist/spreadsheet-xlsx-codec.js.map +1 -0
  147. package/dist/spreadsheet-xlsx-state.d.ts +16 -0
  148. package/dist/spreadsheet.d.ts +724 -0
  149. package/dist/spreadsheet.js +67 -0
  150. package/dist/spreadsheet.js.map +1 -0
  151. package/package.json +129 -0
  152. package/src/bounded-zip.ts +450 -0
  153. package/src/document-docx-api.ts +64 -0
  154. package/src/document-docx-codec.ts +2253 -0
  155. package/src/document-docx-import.ts +3814 -0
  156. package/src/document-docx-packer.ts +72 -0
  157. package/src/document-docx-state.ts +59 -0
  158. package/src/document-render.ts +615 -0
  159. package/src/document.ts +2800 -0
  160. package/src/errors.ts +45 -0
  161. package/src/file-blob.ts +43 -0
  162. package/src/index.ts +4 -0
  163. package/src/inspection.ts +50 -0
  164. package/src/kernel.ts +525 -0
  165. package/src/materializer-cli-entry.ts +11 -0
  166. package/src/materializer-cli.ts +743 -0
  167. package/src/native-raster.ts +141 -0
  168. package/src/native.ts +390 -0
  169. package/src/office-import.ts +243 -0
  170. package/src/presentation-pptx-api.ts +107 -0
  171. package/src/presentation-pptx-import.ts +2065 -0
  172. package/src/presentation-pptx-state-digest.ts +46 -0
  173. package/src/presentation-pptx-state.ts +18 -0
  174. package/src/presentation-pptx-xml.ts +473 -0
  175. package/src/presentation-pptx.ts +447 -0
  176. package/src/presentation-render.ts +532 -0
  177. package/src/presentation.ts +2599 -0
  178. package/src/production-composite.ts +805 -0
  179. package/src/production-document.ts +2 -0
  180. package/src/production-native-codecs.ts +1141 -0
  181. package/src/production-presentation.ts +2 -0
  182. package/src/production-sha256.ts +150 -0
  183. package/src/production-spreadsheet-native.ts +686 -0
  184. package/src/production-spreadsheet.ts +2 -0
  185. package/src/production.ts +1022 -0
  186. package/src/raster-image.ts +586 -0
  187. package/src/reference.ts +17 -0
  188. package/src/runtime-cli-entry.ts +13 -0
  189. package/src/runtime-cli.ts +670 -0
  190. package/src/runtime-development.ts +689 -0
  191. package/src/runtime-receipt.ts +169 -0
  192. package/src/runtime.ts +1463 -0
  193. package/src/snapshot.ts +88 -0
  194. package/src/spreadsheet-address.ts +90 -0
  195. package/src/spreadsheet-file.ts +71 -0
  196. package/src/spreadsheet-formula.ts +1212 -0
  197. package/src/spreadsheet-image.ts +242 -0
  198. package/src/spreadsheet-render.ts +985 -0
  199. package/src/spreadsheet-types.ts +171 -0
  200. package/src/spreadsheet-xlsx-api.ts +123 -0
  201. package/src/spreadsheet-xlsx-codec.ts +3063 -0
  202. package/src/spreadsheet-xlsx-state.ts +191 -0
  203. package/src/spreadsheet.ts +5195 -0
@@ -0,0 +1,242 @@
1
+ import {
2
+ boundedUtf8ByteLength,
3
+ canonicalizeRasterDataUrl,
4
+ encodeRasterBase64,
5
+ normalizeRasterContentType,
6
+ RasterImageValidationError,
7
+ validateRasterImageBytes,
8
+ } from "./raster-image";
9
+ import type { SpreadsheetImageConfig } from "./spreadsheet-types";
10
+
11
+ export type SpreadsheetRasterImageContentType =
12
+ | "image/png"
13
+ | "image/jpeg"
14
+ | "image/gif"
15
+ | "image/webp";
16
+
17
+ /** Untrusted spreadsheet image input was rejected before render or file export. */
18
+ export class InvalidSpreadsheetImageError extends Error {
19
+ readonly code = "INVALID_SPREADSHEET_IMAGE";
20
+
21
+ constructor(
22
+ readonly field: string,
23
+ detail: string,
24
+ ) {
25
+ super(`Invalid spreadsheet ${field}: ${detail}`);
26
+ this.name = "InvalidSpreadsheetImageError";
27
+ }
28
+ }
29
+
30
+ // Keep these model-boundary caps aligned with SPREADSHEET_SNAPSHOT_LIMITS.
31
+ const MAX_IMAGE_BYTES = 32 * 1024 * 1024;
32
+ const MAX_ALT_LENGTH = 1024 * 1024;
33
+ const MAX_PIXEL_VALUE = 1_000_000;
34
+ const normalizedImages = new WeakSet<object>();
35
+
36
+ /**
37
+ * Copies, validates, and freezes a spreadsheet image at the model boundary.
38
+ *
39
+ * Both byte and data-URL inputs become a canonical immutable data URL. This
40
+ * prevents later caller mutation and lets render/export reuse validation in O(1).
41
+ */
42
+ export function normalizeSpreadsheetImageConfig(
43
+ input: SpreadsheetImageConfig,
44
+ ): SpreadsheetImageConfig {
45
+ if (typeof input !== "object" || input === null) {
46
+ throw new InvalidSpreadsheetImageError("image", "must be an object");
47
+ }
48
+ if (normalizedImages.has(input)) return input;
49
+
50
+ const hasDataUrl = input.dataUrl !== undefined;
51
+ const hasBlob = input.blob !== undefined;
52
+ if (Number(hasDataUrl) + Number(hasBlob) !== 1) {
53
+ throw new InvalidSpreadsheetImageError(
54
+ "image source",
55
+ "requires exactly one source: dataUrl or blob",
56
+ );
57
+ }
58
+
59
+ let canonical: string;
60
+ let contentType: SpreadsheetRasterImageContentType;
61
+ if (hasDataUrl) {
62
+ const parsed = parseRasterDataUrl(input.dataUrl);
63
+ contentType = parsed.contentType;
64
+ canonical = parsed.canonical;
65
+ } else {
66
+ const bytes = copyImageBytes(input.blob);
67
+ contentType = validateRasterBytes(bytes, input.contentType, "image blob");
68
+ canonical = `data:${contentType};base64,${encodeRasterBase64(bytes)}`;
69
+ }
70
+
71
+ if (input.contentType !== undefined && normalizeRasterMime(input.contentType) !== contentType) {
72
+ throw new InvalidSpreadsheetImageError("image contentType", "does not match the image bytes");
73
+ }
74
+
75
+ const anchor = normalizeAnchor(input.anchor);
76
+ const alt = normalizeAlt(input.alt);
77
+ const normalized = Object.freeze({
78
+ dataUrl: canonical,
79
+ contentType,
80
+ ...(alt === undefined ? {} : { alt }),
81
+ anchor,
82
+ }) satisfies SpreadsheetImageConfig;
83
+ normalizedImages.add(normalized);
84
+ return normalized;
85
+ }
86
+
87
+ /** Returns a validated inline source and never fetches or reads external data. */
88
+ export function spreadsheetImageSource(input: SpreadsheetImageConfig): string {
89
+ const normalized = normalizeSpreadsheetImageConfig(input);
90
+ return normalized.dataUrl!;
91
+ }
92
+
93
+ function normalizeAnchor(
94
+ anchor: SpreadsheetImageConfig["anchor"],
95
+ ): SpreadsheetImageConfig["anchor"] {
96
+ if (typeof anchor !== "object" || anchor === null) {
97
+ throw new InvalidSpreadsheetImageError("image anchor", "must be an object");
98
+ }
99
+ const from = anchor.from;
100
+ const extent = anchor.extent;
101
+ if (typeof from !== "object" || from === null) {
102
+ throw new InvalidSpreadsheetImageError("image anchor.from", "must be an object");
103
+ }
104
+ if (typeof extent !== "object" || extent === null) {
105
+ throw new InvalidSpreadsheetImageError("image anchor.extent", "must be an object");
106
+ }
107
+ assertInteger(from.row, "image anchor.from.row", 0, 1_048_575);
108
+ assertInteger(from.col, "image anchor.from.col", 0, 16_383);
109
+ if (from.rowOffsetPx !== undefined) {
110
+ assertFiniteInRange(from.rowOffsetPx, "image anchor.from.rowOffsetPx", 0, MAX_PIXEL_VALUE);
111
+ }
112
+ if (from.colOffsetPx !== undefined) {
113
+ assertFiniteInRange(from.colOffsetPx, "image anchor.from.colOffsetPx", 0, MAX_PIXEL_VALUE);
114
+ }
115
+ assertFiniteInRange(
116
+ extent.widthPx,
117
+ "image anchor.extent.widthPx",
118
+ Number.MIN_VALUE,
119
+ MAX_PIXEL_VALUE,
120
+ );
121
+ assertFiniteInRange(
122
+ extent.heightPx,
123
+ "image anchor.extent.heightPx",
124
+ Number.MIN_VALUE,
125
+ MAX_PIXEL_VALUE,
126
+ );
127
+ return Object.freeze({
128
+ from: Object.freeze({
129
+ row: from.row,
130
+ col: from.col,
131
+ ...(from.rowOffsetPx === undefined ? {} : { rowOffsetPx: from.rowOffsetPx }),
132
+ ...(from.colOffsetPx === undefined ? {} : { colOffsetPx: from.colOffsetPx }),
133
+ }),
134
+ extent: Object.freeze({ widthPx: extent.widthPx, heightPx: extent.heightPx }),
135
+ });
136
+ }
137
+
138
+ function normalizeAlt(value: string | undefined): string | undefined {
139
+ if (value === undefined) return undefined;
140
+ if (
141
+ typeof value !== "string" ||
142
+ value.length > MAX_ALT_LENGTH ||
143
+ boundedUtf8ByteLength(value, MAX_ALT_LENGTH) > MAX_ALT_LENGTH
144
+ ) {
145
+ throw new InvalidSpreadsheetImageError("image alt", "must be a bounded string");
146
+ }
147
+ for (const character of value) {
148
+ const codePoint = character.codePointAt(0)!;
149
+ if (
150
+ (codePoint < 0x20 && codePoint !== 0x09 && codePoint !== 0x0a && codePoint !== 0x0d) ||
151
+ (codePoint >= 0xd800 && codePoint <= 0xdfff) ||
152
+ codePoint === 0xfffe ||
153
+ codePoint === 0xffff
154
+ ) {
155
+ throw new InvalidSpreadsheetImageError(
156
+ "image alt",
157
+ "contains characters forbidden by XML 1.0",
158
+ );
159
+ }
160
+ }
161
+ return value;
162
+ }
163
+
164
+ function parseRasterDataUrl(value: unknown): {
165
+ contentType: SpreadsheetRasterImageContentType;
166
+ canonical: string;
167
+ } {
168
+ try {
169
+ const result = canonicalizeRasterDataUrl(value, MAX_IMAGE_BYTES);
170
+ return {
171
+ contentType: result.contentType,
172
+ canonical: result.canonical,
173
+ };
174
+ } catch (error) {
175
+ if (error instanceof RasterImageValidationError) {
176
+ throw new InvalidSpreadsheetImageError("image dataUrl", error.detail);
177
+ }
178
+ throw error;
179
+ }
180
+ }
181
+
182
+ function copyImageBytes(value: unknown): Uint8Array {
183
+ if (!(value instanceof ArrayBuffer)) {
184
+ throw new InvalidSpreadsheetImageError("image blob", "must be an ArrayBuffer");
185
+ }
186
+ const bytes = new Uint8Array(value.slice(0));
187
+ if (bytes.byteLength === 0 || bytes.byteLength > MAX_IMAGE_BYTES) {
188
+ throw new InvalidSpreadsheetImageError(
189
+ "image blob",
190
+ `must contain between 1 and ${MAX_IMAGE_BYTES} bytes`,
191
+ );
192
+ }
193
+ return bytes;
194
+ }
195
+
196
+ function normalizeRasterMime(value: unknown): SpreadsheetRasterImageContentType {
197
+ try {
198
+ return normalizeRasterContentType(value);
199
+ } catch (error) {
200
+ if (error instanceof RasterImageValidationError) {
201
+ throw new InvalidSpreadsheetImageError("image contentType", error.detail);
202
+ }
203
+ throw error;
204
+ }
205
+ }
206
+
207
+ function validateRasterBytes(
208
+ bytes: Uint8Array,
209
+ declaredType: unknown,
210
+ field: string,
211
+ ): SpreadsheetRasterImageContentType {
212
+ try {
213
+ return validateRasterImageBytes(bytes, declaredType);
214
+ } catch (error) {
215
+ if (error instanceof RasterImageValidationError) {
216
+ throw new InvalidSpreadsheetImageError(field, error.detail);
217
+ }
218
+ throw error;
219
+ }
220
+ }
221
+
222
+ function assertInteger(
223
+ value: unknown,
224
+ field: string,
225
+ min: number,
226
+ max: number,
227
+ ): asserts value is number {
228
+ if (!Number.isInteger(value) || (value as number) < min || (value as number) > max) {
229
+ throw new InvalidSpreadsheetImageError(field, `must be an integer from ${min} through ${max}`);
230
+ }
231
+ }
232
+
233
+ function assertFiniteInRange(
234
+ value: unknown,
235
+ field: string,
236
+ min: number,
237
+ max: number,
238
+ ): asserts value is number {
239
+ if (typeof value !== "number" || !Number.isFinite(value) || value < min || value > max) {
240
+ throw new InvalidSpreadsheetImageError(field, `must be a finite number from ${min} to ${max}`);
241
+ }
242
+ }