@officedk/pptxdk 0.0.0-stage → 0.1.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.
Files changed (194) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +48 -2
  3. package/dist/build.d.ts +94 -0
  4. package/dist/build.js +148 -0
  5. package/dist/capabilities/dist/all.js +32 -0
  6. package/dist/capabilities/dist/box/box-codegen.js +51 -0
  7. package/dist/capabilities/dist/box/box-declaration.js +31 -0
  8. package/dist/capabilities/dist/box/box-elements.js +17 -0
  9. package/dist/capabilities/dist/box/box.js +138 -0
  10. package/dist/capabilities/dist/chart/chart-codegen.js +77 -0
  11. package/dist/capabilities/dist/chart/chart-declaration.js +7 -0
  12. package/dist/capabilities/dist/chart/chart-elements.js +12 -0
  13. package/dist/capabilities/dist/chart/chart-import.js +2272 -0
  14. package/dist/capabilities/dist/chart/chart-labels.js +86 -0
  15. package/dist/capabilities/dist/chart/chart-model.js +9 -0
  16. package/dist/capabilities/dist/chart/chart-schemas.js +1078 -0
  17. package/dist/capabilities/dist/chart/chart-xml.js +788 -0
  18. package/dist/capabilities/dist/chart/chart.js +1124 -0
  19. package/dist/capabilities/dist/chart/preview/axes-and-grid.js +298 -0
  20. package/dist/capabilities/dist/chart/preview/bar-column.js +143 -0
  21. package/dist/capabilities/dist/chart/preview/data-labels.js +334 -0
  22. package/dist/capabilities/dist/chart/preview/error-bars.js +213 -0
  23. package/dist/capabilities/dist/chart/preview/index.js +190 -0
  24. package/dist/capabilities/dist/chart/preview/layout.js +519 -0
  25. package/dist/capabilities/dist/chart/preview/legend.js +273 -0
  26. package/dist/capabilities/dist/chart/preview/line-area.js +404 -0
  27. package/dist/capabilities/dist/chart/preview/markers.js +100 -0
  28. package/dist/capabilities/dist/chart/preview/number-format.js +247 -0
  29. package/dist/capabilities/dist/chart/preview/pie-doughnut.js +159 -0
  30. package/dist/capabilities/dist/chart/preview/scales.js +365 -0
  31. package/dist/capabilities/dist/chart/preview/scatter.js +131 -0
  32. package/dist/capabilities/dist/chart/preview/style.js +48 -0
  33. package/dist/capabilities/dist/chart/preview/text-render.js +116 -0
  34. package/dist/capabilities/dist/chart/preview/trendlines.js +537 -0
  35. package/dist/capabilities/dist/chart/preview/types.js +5 -0
  36. package/dist/capabilities/dist/document.js +148 -0
  37. package/dist/capabilities/dist/font/font-embedding.js +289 -0
  38. package/dist/capabilities/dist/font/font-family.js +10 -0
  39. package/dist/capabilities/dist/font/font-import.js +302 -0
  40. package/dist/capabilities/dist/font/font-subset.js +55 -0
  41. package/dist/capabilities/dist/font/font.js +25 -0
  42. package/dist/capabilities/dist/group/group-codegen.js +51 -0
  43. package/dist/capabilities/dist/group/group-declaration.js +42 -0
  44. package/dist/capabilities/dist/group/group-elements.js +12 -0
  45. package/dist/capabilities/dist/group/group-import.js +319 -0
  46. package/dist/capabilities/dist/group/group-xml.js +7 -0
  47. package/dist/capabilities/dist/group/group.js +211 -0
  48. package/dist/capabilities/dist/image/gif-decoder.js +244 -0
  49. package/dist/capabilities/dist/image/image-codegen.js +94 -0
  50. package/dist/capabilities/dist/image/image-declaration.js +8 -0
  51. package/dist/capabilities/dist/image/image-decode.js +221 -0
  52. package/dist/capabilities/dist/image/image-elements.js +12 -0
  53. package/dist/capabilities/dist/image/image-import.js +778 -0
  54. package/dist/capabilities/dist/image/image-schemas.js +149 -0
  55. package/dist/capabilities/dist/image/image-xml.js +12 -0
  56. package/dist/capabilities/dist/image/image.js +472 -0
  57. package/dist/capabilities/dist/masters/footer-placeholder.js +685 -0
  58. package/dist/capabilities/dist/masters/masters-codegen.js +21 -0
  59. package/dist/capabilities/dist/masters/masters.js +250 -0
  60. package/dist/capabilities/dist/motion/motion-api.js +527 -0
  61. package/dist/capabilities/dist/motion/motion-codegen.js +340 -0
  62. package/dist/capabilities/dist/motion/motion-elements.js +43 -0
  63. package/dist/capabilities/dist/motion/motion-import.js +1033 -0
  64. package/dist/capabilities/dist/motion/motion-plan.js +2189 -0
  65. package/dist/capabilities/dist/motion/motion-query.js +420 -0
  66. package/dist/capabilities/dist/motion/motion-schemas.js +216 -0
  67. package/dist/capabilities/dist/motion/motion.js +1372 -0
  68. package/dist/capabilities/dist/notes/notes-codegen.js +20 -0
  69. package/dist/capabilities/dist/notes/notes-declaration.js +8 -0
  70. package/dist/capabilities/dist/notes/notes-elements.js +12 -0
  71. package/dist/capabilities/dist/notes/notes-import.js +292 -0
  72. package/dist/capabilities/dist/notes/notes-schemas.js +35 -0
  73. package/dist/capabilities/dist/notes/notes-xml.js +38 -0
  74. package/dist/capabilities/dist/notes/notes.js +191 -0
  75. package/dist/capabilities/dist/placeholder/placeholder-codegen.js +23 -0
  76. package/dist/capabilities/dist/placeholder/placeholder-elements.js +12 -0
  77. package/dist/capabilities/dist/placeholder/placeholder.js +292 -0
  78. package/dist/capabilities/dist/shape/shape-codegen.js +166 -0
  79. package/dist/capabilities/dist/shape/shape-declaration.js +57 -0
  80. package/dist/capabilities/dist/shape/shape-elements.js +12 -0
  81. package/dist/capabilities/dist/shape/shape-import.js +579 -0
  82. package/dist/capabilities/dist/shape/shape-xml.js +6 -0
  83. package/dist/capabilities/dist/shape/shape.js +337 -0
  84. package/dist/capabilities/dist/shared/geometry.js +1423 -0
  85. package/dist/capabilities/dist/shared/identity.js +205 -0
  86. package/dist/capabilities/dist/shared/morph-api.js +11 -0
  87. package/dist/capabilities/dist/shared/placeholder-import.js +113 -0
  88. package/dist/capabilities/dist/shared/preset-definitions.js +21390 -0
  89. package/dist/capabilities/dist/shared/style-inheritance.js +166 -0
  90. package/dist/capabilities/dist/shared/style-parse.js +11 -0
  91. package/dist/capabilities/dist/shared/text-schemas.js +216 -0
  92. package/dist/capabilities/dist/shared/text-service.js +1883 -0
  93. package/dist/capabilities/dist/shared/visual.js +918 -0
  94. package/dist/capabilities/dist/slide-background/slide-background-codegen.js +44 -0
  95. package/dist/capabilities/dist/slide-background/slide-background-import.js +161 -0
  96. package/dist/capabilities/dist/slide-background/slide-background-xml.js +21 -0
  97. package/dist/capabilities/dist/slide-background/slide-background.js +221 -0
  98. package/dist/capabilities/dist/table/table-codegen.js +81 -0
  99. package/dist/capabilities/dist/table/table-declaration.js +15 -0
  100. package/dist/capabilities/dist/table/table-elements.js +27 -0
  101. package/dist/capabilities/dist/table/table-import.js +539 -0
  102. package/dist/capabilities/dist/table/table-schemas.js +279 -0
  103. package/dist/capabilities/dist/table/table-xml.js +37 -0
  104. package/dist/capabilities/dist/table/table.js +662 -0
  105. package/dist/capabilities/dist/text/text-codegen.js +129 -0
  106. package/dist/capabilities/dist/text/text-declaration.js +19 -0
  107. package/dist/capabilities/dist/text/text-elements.js +38 -0
  108. package/dist/capabilities/dist/text/text-import.js +1077 -0
  109. package/dist/capabilities/dist/text/text-xml.js +9 -0
  110. package/dist/capabilities/dist/text/text.js +335 -0
  111. package/dist/capabilities/dist/transition/transition-api.js +139 -0
  112. package/dist/capabilities/dist/transition/transition-codegen.js +45 -0
  113. package/dist/capabilities/dist/transition/transition-import.js +477 -0
  114. package/dist/capabilities/dist/transition/transition.js +260 -0
  115. package/dist/capability-D_xeNVIw.d.ts +29496 -0
  116. package/dist/cli.js +20 -0
  117. package/dist/codegen/dist/assets.js +78 -0
  118. package/dist/codegen/dist/codegen.js +611 -0
  119. package/dist/codegen/dist/identifiers.js +193 -0
  120. package/dist/codegen/dist/index.js +3 -0
  121. package/dist/codegen/dist/printer.js +143 -0
  122. package/dist/codegen/dist/types.js +49 -0
  123. package/dist/core/dist/author-ids.js +48 -0
  124. package/dist/core/dist/author-schemas.js +313 -0
  125. package/dist/core/dist/block-flex-layout.js +749 -0
  126. package/dist/core/dist/build.js +4 -0
  127. package/dist/core/dist/capability.js +13 -0
  128. package/dist/core/dist/declaration.js +15 -0
  129. package/dist/core/dist/diagnostics.js +21 -0
  130. package/dist/core/dist/document-internals.js +13 -0
  131. package/dist/core/dist/document.js +408 -0
  132. package/dist/core/dist/geometry-schemas.js +249 -0
  133. package/dist/core/dist/grid-layout.js +445 -0
  134. package/dist/core/dist/host.js +40 -0
  135. package/dist/core/dist/index.js +15 -0
  136. package/dist/core/dist/input-values.js +45 -0
  137. package/dist/core/dist/layout-protocol.js +66 -0
  138. package/dist/core/dist/layout-schemas.js +208 -0
  139. package/dist/core/dist/layout.js +299 -0
  140. package/dist/core/dist/masters.js +169 -0
  141. package/dist/core/dist/morph.js +30 -0
  142. package/dist/core/dist/placeholders.js +213 -0
  143. package/dist/core/dist/query.js +155 -0
  144. package/dist/core/dist/resolution.js +11 -0
  145. package/dist/core/dist/resolve.js +1827 -0
  146. package/dist/core/dist/stage-options.js +67 -0
  147. package/dist/core/dist/theme.js +931 -0
  148. package/dist/document-BHPUODPP.d.ts +27759 -0
  149. package/dist/emit/dist/emit.js +936 -0
  150. package/dist/emit/dist/index.js +5 -0
  151. package/dist/emit/dist/ooxml.js +606 -0
  152. package/dist/emit/dist/shape-tree.js +12 -0
  153. package/dist/import/dist/alternate-content.js +54 -0
  154. package/dist/import/dist/diagnostics.js +153 -0
  155. package/dist/import/dist/fonts.js +250 -0
  156. package/dist/import/dist/import.js +504 -0
  157. package/dist/import/dist/index.js +16 -0
  158. package/dist/import/dist/masters.js +1153 -0
  159. package/dist/import/dist/mechanism.js +10 -0
  160. package/dist/import/dist/namespaces.js +60 -0
  161. package/dist/import/dist/notes-masters.js +300 -0
  162. package/dist/import/dist/opc.js +233 -0
  163. package/dist/import/dist/resources.js +166 -0
  164. package/dist/import/dist/sections.js +139 -0
  165. package/dist/import/dist/themes.js +671 -0
  166. package/dist/import/dist/visual.js +761 -0
  167. package/dist/import/dist/xml-fragments.js +36 -0
  168. package/dist/import/dist/xml-reader.js +267 -0
  169. package/dist/index-B5m3hqjC.d.ts +7 -0
  170. package/dist/index-CCy-Yo8G.d.ts +1208 -0
  171. package/dist/index-DpxcZ4Gs.d.ts +725 -0
  172. package/dist/index.d.ts +7 -0
  173. package/dist/index.js +70 -0
  174. package/dist/node.d.ts +53 -0
  175. package/dist/node.js +194 -0
  176. package/dist/pptxdk/src/cli-commands.js +913 -0
  177. package/dist/pptxdk/src/compose.js +44 -0
  178. package/dist/pptxdk/src/slide.js +9 -0
  179. package/dist/preview/dist/index.js +240 -0
  180. package/dist/preview/dist/options.js +53 -0
  181. package/dist/preview-Cfw0QdMM.d.ts +86 -0
  182. package/dist/preview.d.ts +3 -0
  183. package/dist/preview.js +27 -0
  184. package/dist/react/dist/append.js +66 -0
  185. package/dist/react/dist/document-adapter.js +65 -0
  186. package/dist/react/dist/elements.js +59 -0
  187. package/dist/react/dist/index.js +68 -0
  188. package/dist/react/dist/reconciler.js +290 -0
  189. package/dist/react.d.ts +145 -0
  190. package/dist/react.js +27 -0
  191. package/dist/transition-Cips9wma.d.ts +82 -0
  192. package/dist/vanilla.d.ts +4 -0
  193. package/dist/vanilla.js +14 -0
  194. package/package.json +78 -3
@@ -0,0 +1,244 @@
1
+ import { CapabilityError } from "../../../core/dist/diagnostics.js";
2
+ import "../../../core/dist/capability.js";
3
+ // ../capabilities/dist/image/gif-decoder.js
4
+ function corruptGif(message) {
5
+ throw new CapabilityError("preview-corrupt-image", message);
6
+ }
7
+ function u16LE(bytes, offset) {
8
+ return (bytes[offset] ?? 0) + ((bytes[offset + 1] ?? 0) << 8);
9
+ }
10
+ function skipSubBlocks(bytes, startOffset) {
11
+ let offset = startOffset;
12
+ while (offset < bytes.length) {
13
+ const size = bytes[offset] ?? 0;
14
+ offset += 1;
15
+ if (size === 0) return offset;
16
+ offset += size;
17
+ if (offset > bytes.length) corruptGif("Failed to decode GIF image: truncated extension sub-block");
18
+ }
19
+ corruptGif("Failed to decode GIF image: unterminated extension sub-block");
20
+ }
21
+ function collectSubBlocks(bytes, startOffset) {
22
+ const chunks = [];
23
+ let totalLength = 0;
24
+ let offset = startOffset;
25
+ while (offset < bytes.length) {
26
+ const size = bytes[offset] ?? 0;
27
+ offset += 1;
28
+ if (size === 0) {
29
+ const merged = new Uint8Array(totalLength);
30
+ let cursor = 0;
31
+ for (const chunk of chunks) {
32
+ merged.set(chunk, cursor);
33
+ cursor += chunk.length;
34
+ }
35
+ return {
36
+ data: merged,
37
+ nextOffset: offset
38
+ };
39
+ }
40
+ if (offset + size > bytes.length) corruptGif("Failed to decode GIF image: truncated image data sub-block");
41
+ chunks.push(bytes.subarray(offset, offset + size));
42
+ totalLength += size;
43
+ offset += size;
44
+ }
45
+ corruptGif("Failed to decode GIF image: unterminated image data sub-block");
46
+ }
47
+ function decompressLzw(compressed, lzwMinCodeSize, expectedPixels) {
48
+ if (lzwMinCodeSize < 2 || lzwMinCodeSize > 11) corruptGif(`Failed to decode GIF image: invalid LZW minimum code size ${lzwMinCodeSize}`);
49
+ if (compressed.length === 0) corruptGif("Failed to decode GIF image: empty LZW compressed stream");
50
+ const clearCode = 1 << lzwMinCodeSize;
51
+ const eoiCode = clearCode + 1;
52
+ const indices = new Uint8Array(expectedPixels);
53
+ const prefix = /* @__PURE__ */ new Int32Array(4096);
54
+ const suffix = /* @__PURE__ */ new Uint8Array(4096);
55
+ const pixelStack = /* @__PURE__ */ new Uint8Array(4096);
56
+ for (let i = 0; i < clearCode; i += 1) {
57
+ prefix[i] = -1;
58
+ suffix[i] = i;
59
+ }
60
+ let codeSize = lzwMinCodeSize + 1;
61
+ let nextCode = eoiCode + 1;
62
+ let oldCode = -1;
63
+ let firstChar = 0;
64
+ let pixelOut = 0;
65
+ let bytePos = 0;
66
+ let bitBuffer = 0;
67
+ let bitCount = 0;
68
+ const readCode = () => {
69
+ while (bitCount < codeSize) {
70
+ if (bytePos >= compressed.length) corruptGif("Failed to decode GIF image: truncated LZW bit stream");
71
+ bitBuffer |= (compressed[bytePos] ?? 0) << bitCount;
72
+ bytePos += 1;
73
+ bitCount += 8;
74
+ }
75
+ const mask = (1 << codeSize) - 1;
76
+ const code = bitBuffer & mask;
77
+ bitBuffer >>>= codeSize;
78
+ bitCount -= codeSize;
79
+ return code;
80
+ };
81
+ while (pixelOut < expectedPixels) {
82
+ const rawCode = readCode();
83
+ if (rawCode === clearCode) {
84
+ codeSize = lzwMinCodeSize + 1;
85
+ nextCode = eoiCode + 1;
86
+ oldCode = -1;
87
+ continue;
88
+ }
89
+ if (rawCode === eoiCode) break;
90
+ if (rawCode > nextCode || rawCode === nextCode && oldCode === -1) corruptGif(`Failed to decode GIF image: out-of-range LZW code ${rawCode} (nextCode=${nextCode})`);
91
+ let code = rawCode;
92
+ let stackTop = 0;
93
+ if (code === nextCode) {
94
+ pixelStack[stackTop] = firstChar;
95
+ stackTop += 1;
96
+ code = oldCode;
97
+ }
98
+ while (code >= clearCode) {
99
+ if (stackTop >= 4096) corruptGif("Failed to decode GIF image: corrupt LZW dictionary cycle");
100
+ pixelStack[stackTop] = suffix[code] ?? 0;
101
+ stackTop += 1;
102
+ code = prefix[code] ?? -1;
103
+ if (code < 0) corruptGif("Failed to decode GIF image: invalid LZW prefix reference");
104
+ }
105
+ firstChar = suffix[code] ?? 0;
106
+ pixelStack[stackTop] = firstChar;
107
+ stackTop += 1;
108
+ for (let i = stackTop - 1; i >= 0 && pixelOut < expectedPixels; i -= 1) {
109
+ indices[pixelOut] = pixelStack[i] ?? 0;
110
+ pixelOut += 1;
111
+ }
112
+ if (oldCode !== -1 && nextCode < 4096) {
113
+ prefix[nextCode] = oldCode;
114
+ suffix[nextCode] = firstChar;
115
+ nextCode += 1;
116
+ if (nextCode === 1 << codeSize && codeSize < 12) codeSize += 1;
117
+ }
118
+ oldCode = rawCode;
119
+ }
120
+ if (pixelOut < expectedPixels) corruptGif(`Failed to decode GIF image: truncated pixel stream (${pixelOut}/${expectedPixels} pixels)`);
121
+ return indices;
122
+ }
123
+ const interlacePasses = [
124
+ {
125
+ start: 0,
126
+ step: 8
127
+ },
128
+ {
129
+ start: 4,
130
+ step: 8
131
+ },
132
+ {
133
+ start: 2,
134
+ step: 4
135
+ },
136
+ {
137
+ start: 1,
138
+ step: 2
139
+ }
140
+ ];
141
+ /**
142
+ * Decodes the static first frame of a GIF87a or GIF89a byte stream into RGBA pixels.
143
+ * Supports GCT/LCT palettes, Graphic Control Extension transparency, and 4-pass interlacing.
144
+ */
145
+ function decodeGifFirstFrame(bytes) {
146
+ if (bytes.length < 14) corruptGif("Failed to decode GIF image: truncated header");
147
+ const signature = String.fromCharCode(...bytes.subarray(0, 6));
148
+ if (signature !== "GIF87a" && signature !== "GIF89a") corruptGif("Failed to decode GIF image: invalid GIF signature");
149
+ const screenW = u16LE(bytes, 6);
150
+ const screenH = u16LE(bytes, 8);
151
+ if (screenW < 1 || screenH < 1) corruptGif("Failed to decode GIF image: invalid logical screen dimensions");
152
+ const packed = bytes[10] ?? 0;
153
+ const hasGct = (packed & 128) !== 0;
154
+ const gctSize = 1 << (packed & 7) + 1;
155
+ let offset = 13;
156
+ let gct;
157
+ if (hasGct) {
158
+ const gctEnd = offset + gctSize * 3;
159
+ if (gctEnd > bytes.length) corruptGif("Failed to decode GIF image: truncated global color table");
160
+ gct = bytes.subarray(offset, gctEnd);
161
+ offset = gctEnd;
162
+ }
163
+ let transparentIndex;
164
+ let foundImage = false;
165
+ while (offset < bytes.length) {
166
+ const block = bytes[offset];
167
+ offset += 1;
168
+ if (block === 44) {
169
+ foundImage = true;
170
+ break;
171
+ }
172
+ if (block === 59) corruptGif("Failed to decode GIF image: no image frame before trailer");
173
+ if (block === 33) {
174
+ if (offset >= bytes.length) corruptGif("Failed to decode GIF image: truncated extension header");
175
+ const label = bytes[offset] ?? 0;
176
+ offset += 1;
177
+ if (label === 249) {
178
+ if ((bytes[offset] ?? 0) !== 4 || offset + 5 >= bytes.length) corruptGif("Failed to decode GIF image: invalid graphic control extension");
179
+ const transparentFlag = ((bytes[offset + 1] ?? 0) & 1) !== 0;
180
+ const transIdx = bytes[offset + 4] ?? 0;
181
+ transparentIndex = transparentFlag ? transIdx : void 0;
182
+ offset = skipSubBlocks(bytes, offset);
183
+ } else offset = skipSubBlocks(bytes, offset);
184
+ continue;
185
+ }
186
+ corruptGif(`Failed to decode GIF image: unexpected block introducer 0x${(block ?? 0).toString(16)}`);
187
+ }
188
+ if (!foundImage || offset + 9 > bytes.length) corruptGif("Failed to decode GIF image: missing image descriptor");
189
+ const left = u16LE(bytes, offset);
190
+ const top = u16LE(bytes, offset + 2);
191
+ const frameW = u16LE(bytes, offset + 4);
192
+ const frameH = u16LE(bytes, offset + 6);
193
+ const imgPacked = bytes[offset + 8] ?? 0;
194
+ offset += 9;
195
+ if (frameW < 1 || frameH < 1) corruptGif("Failed to decode GIF image: invalid frame dimensions");
196
+ const hasLct = (imgPacked & 128) !== 0;
197
+ const interlaced = (imgPacked & 64) !== 0;
198
+ const lctSize = 1 << (imgPacked & 7) + 1;
199
+ let palette = gct;
200
+ if (hasLct) {
201
+ const lctEnd = offset + lctSize * 3;
202
+ if (lctEnd > bytes.length) corruptGif("Failed to decode GIF image: truncated local color table");
203
+ palette = bytes.subarray(offset, lctEnd);
204
+ offset = lctEnd;
205
+ }
206
+ if (palette === void 0 || palette.length < 3) corruptGif("Failed to decode GIF image: missing color table");
207
+ if (offset >= bytes.length) corruptGif("Failed to decode GIF image: missing LZW minimum code size");
208
+ const lzwMinCodeSize = bytes[offset] ?? 0;
209
+ offset += 1;
210
+ const { data: compressed } = collectSubBlocks(bytes, offset);
211
+ const indices = decompressLzw(compressed, lzwMinCodeSize, frameW * frameH);
212
+ const rgba = new Uint8Array(screenW * screenH * 4);
213
+ const rowMap = new Int32Array(frameH);
214
+ if (interlaced) {
215
+ let srcY = 0;
216
+ for (const pass of interlacePasses) for (let destY = pass.start; destY < frameH; destY += pass.step) {
217
+ rowMap[srcY] = destY;
218
+ srcY += 1;
219
+ }
220
+ } else for (let y = 0; y < frameH; y += 1) rowMap[y] = y;
221
+ for (let srcY = 0; srcY < frameH; srcY += 1) {
222
+ const destY = top + (rowMap[srcY] ?? 0);
223
+ for (let x = 0; x < frameW; x += 1) {
224
+ const colorIdx = indices[srcY * frameW + x] ?? 0;
225
+ if (colorIdx === transparentIndex) continue;
226
+ const palOffset = colorIdx * 3;
227
+ if (palOffset + 2 >= palette.length) corruptGif(`Failed to decode GIF image: palette index ${colorIdx} out of bounds`);
228
+ const destX = left + x;
229
+ if (destX >= 0 && destX < screenW && destY >= 0 && destY < screenH) {
230
+ const outOffset = (destY * screenW + destX) * 4;
231
+ rgba[outOffset] = palette[palOffset] ?? 0;
232
+ rgba[outOffset + 1] = palette[palOffset + 1] ?? 0;
233
+ rgba[outOffset + 2] = palette[palOffset + 2] ?? 0;
234
+ rgba[outOffset + 3] = 255;
235
+ }
236
+ }
237
+ }
238
+ return {
239
+ width: screenW,
240
+ height: screenH,
241
+ data: rgba
242
+ };
243
+ }
244
+ export { decodeGifFirstFrame };
@@ -0,0 +1,94 @@
1
+ import "../../../codegen/dist/index.js";
2
+ import { CommonNode } from "../../../core/dist/document.js";
3
+ import { defineObjectCodegen, expr } from "../../../codegen/dist/types.js";
4
+ import { readImage } from "./image-decode.js";
5
+ import { externalImageSourceSchema } from "./image-schemas.js";
6
+ // ../capabilities/dist/image/image-codegen.js
7
+ const objectMotionPropKeys = /* @__PURE__ */ new Set([
8
+ "enter",
9
+ "emphasis",
10
+ "motion"
11
+ ]);
12
+ function isPlainObject(value) {
13
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
14
+ const proto = Object.getPrototypeOf(value);
15
+ return proto === Object.prototype || proto === null;
16
+ }
17
+ function assertNoImageChildren(node, ctx) {
18
+ for (const child of node.children) {
19
+ if (child instanceof CommonNode) ctx.fail("invalid-document", "Image does not accept child declarations");
20
+ const leaf = child;
21
+ if (leaf.type === "#text" && leaf.text.trim() !== "") ctx.fail("invalid-document", "Image does not accept text children");
22
+ }
23
+ }
24
+ function serializeImageSrcProp(value, ctx) {
25
+ if (isPlainObject(value) && Object.hasOwn(value, "externalUrl")) {
26
+ const parsedExternal = externalImageSourceSchema.safeParse(value);
27
+ if (!parsedExternal.success) ctx.fail("unexpressible-value", "Image.src externalUrl must be a non-empty string", "@src");
28
+ return { externalUrl: parsedExternal.data.externalUrl };
29
+ }
30
+ try {
31
+ const loaded = readImage(value);
32
+ const assetVar = ctx.registerImageAsset(loaded.bytes, loaded.extension);
33
+ return expr(assetVar);
34
+ } catch (error) {
35
+ ctx.fail("unexpressible-value", error instanceof Error ? error.message : "Image.src could not be read or decoded", "@src");
36
+ }
37
+ }
38
+ /**
39
+ * Serializes an `{ image: string | URL | Uint8Array }` descriptor (used in `VisualStyle.backgroundImage`
40
+ * and `SlideBackground`) by reading/validating the embedded image and registering a relative asset URL.
41
+ */
42
+ function serializeImageDescriptorValue(value, ctx) {
43
+ if (!isPlainObject(value)) return void 0;
44
+ const definedKeys = Object.keys(value).filter((key) => value[key] !== void 0);
45
+ if (definedKeys.length !== 1 || definedKeys[0] !== "image") return;
46
+ const rawSource = value["image"];
47
+ const subPath = ctx.path.includes("@") ? void 0 : "@style.backgroundImage";
48
+ try {
49
+ const loaded = readImage(rawSource);
50
+ const assetVar = ctx.registerImageAsset(loaded.bytes, loaded.extension);
51
+ return expr(ctx.formatProps([["image", expr(assetVar)]]));
52
+ } catch (error) {
53
+ ctx.fail("unexpressible-value", error instanceof Error ? error.message : "Background image source could not be read or decoded", subPath);
54
+ }
55
+ }
56
+ function collectImageProps(node, ctx) {
57
+ assertNoImageChildren(node, ctx);
58
+ const extra = ctx.emitObjectExtraProps(node.props);
59
+ const entries = [];
60
+ let sawSrc = false;
61
+ for (const [key, value] of Object.entries(node.props)) {
62
+ if (value === void 0) continue;
63
+ if (key === "src") {
64
+ sawSrc = true;
65
+ entries.push(["src", serializeImageSrcProp(value, ctx)]);
66
+ continue;
67
+ }
68
+ if (objectMotionPropKeys.has(key)) {
69
+ if (Object.hasOwn(extra, key)) entries.push([key, extra[key]]);
70
+ else ctx.fail("unexpressible-value", `Object property ${JSON.stringify(key)} requires motion codegen support`, `@${key}`);
71
+ continue;
72
+ }
73
+ entries.push([key, value]);
74
+ }
75
+ if (!sawSrc) ctx.fail("unexpressible-value", "Image declaration is missing src", "@src");
76
+ return entries;
77
+ }
78
+ /** Source codegen contribution for `image` declarations and `{ image: ... }` fill descriptors. */
79
+ const imageCodegen = defineObjectCodegen({
80
+ declarations: { image: {
81
+ emitVanilla: (node, ctx) => {
82
+ const callee = ctx.useImport("image");
83
+ const props = collectImageProps(node, ctx);
84
+ return ctx.formatVanillaCall(callee, [ctx.formatProps(props)]);
85
+ },
86
+ emitReact: (node, ctx) => {
87
+ const tag = ctx.useImport("Image");
88
+ const props = collectImageProps(node, ctx);
89
+ return ctx.formatJsxElement(tag, props);
90
+ }
91
+ } },
92
+ valueSerializers: [serializeImageDescriptorValue]
93
+ });
94
+ export { imageCodegen, serializeImageDescriptorValue };
@@ -0,0 +1,8 @@
1
+ import { CommonNode } from "../../../core/dist/document.js";
2
+ import { imageVisualStyleKeys } from "./image-schemas.js";
3
+ // ../capabilities/dist/image/image-declaration.js
4
+ /** Creates the editable native image shared by the command factory and the Image JSX element. */
5
+ function createImageNode(props) {
6
+ return new CommonNode("image", "image", props);
7
+ }
8
+ export { createImageNode, imageVisualStyleKeys };
@@ -0,0 +1,221 @@
1
+ import { CapabilityError } from "../../../core/dist/diagnostics.js";
2
+ import "../../../core/dist/capability.js";
3
+ import { decodeGifFirstFrame } from "./gif-decoder.js";
4
+ import { createRequire } from "node:module";
5
+ import { readFileSync } from "node:fs";
6
+ import { fileURLToPath } from "node:url";
7
+ // ../capabilities/dist/image/image-decode.js
8
+ function uint32(data, offset) {
9
+ return ((data[offset] ?? 0) << 24 >>> 0) + ((data[offset + 1] ?? 0) << 16) + ((data[offset + 2] ?? 0) << 8) + (data[offset + 3] ?? 0);
10
+ }
11
+ function uint16(data, offset) {
12
+ return ((data[offset] ?? 0) << 8) + (data[offset + 1] ?? 0);
13
+ }
14
+ function pngMetadata(data) {
15
+ if (data.length < 45 || data[0] !== 137 || data[1] !== 80 || data[2] !== 78 || data[3] !== 71 || data[4] !== 13 || data[5] !== 10 || data[6] !== 26 || data[7] !== 10 || uint32(data, 8) !== 13 || data[12] !== 73 || data[13] !== 72 || data[14] !== 68 || data[15] !== 82) return;
16
+ let offset = 8;
17
+ let hasHeader = false;
18
+ let hasImageData = false;
19
+ let hasEnd = false;
20
+ while (offset + 12 <= data.length) {
21
+ const size = uint32(data, offset);
22
+ const end = offset + size + 12;
23
+ if (end > data.length) return void 0;
24
+ const isHeader = data[offset + 4] === 73 && data[offset + 5] === 72 && data[offset + 6] === 68 && data[offset + 7] === 82;
25
+ const isEnd = data[offset + 4] === 73 && data[offset + 5] === 69 && data[offset + 6] === 78 && data[offset + 7] === 68;
26
+ const isImageData = data[offset + 4] === 73 && data[offset + 5] === 68 && data[offset + 6] === 65 && data[offset + 7] === 84;
27
+ if (offset === 8 && !isHeader) return void 0;
28
+ if (isHeader) hasHeader = true;
29
+ if (isImageData && size > 0) hasImageData = true;
30
+ if (isEnd) {
31
+ hasEnd = size === 0;
32
+ break;
33
+ }
34
+ offset = end;
35
+ }
36
+ const width = uint32(data, 16);
37
+ const height = uint32(data, 20);
38
+ if (!hasHeader || !hasImageData || !hasEnd || width < 1 || height < 1) return;
39
+ return {
40
+ extension: "png",
41
+ contentType: "image/png",
42
+ width,
43
+ height
44
+ };
45
+ }
46
+ function jpegMetadata(data) {
47
+ if (data.length < 12 || data[0] !== 255 || data[1] !== 216) return;
48
+ let offset = 2;
49
+ let frame;
50
+ while (offset + 4 <= data.length) {
51
+ if (data[offset] !== 255) return void 0;
52
+ while (data[offset] === 255) offset += 1;
53
+ const marker = data[offset];
54
+ if (marker === void 0 || marker === 217) return void 0;
55
+ if (marker === 218) {
56
+ const length = uint16(data, offset + 1);
57
+ if (frame === void 0 || length < 2 || offset + length + 1 > data.length) return;
58
+ let hasScanData = false;
59
+ for (let index = offset + length + 1; index + 1 < data.length; index++) {
60
+ if (data[index] !== 255) {
61
+ hasScanData = true;
62
+ continue;
63
+ }
64
+ let markerIndex = index + 1;
65
+ while (data[markerIndex] === 255) markerIndex += 1;
66
+ const scanMarker = data[markerIndex];
67
+ if (scanMarker === 217) return hasScanData ? frame : void 0;
68
+ if (scanMarker === 0 || scanMarker !== void 0 && scanMarker >= 208 && scanMarker <= 215) hasScanData = true;
69
+ index = markerIndex;
70
+ }
71
+ return;
72
+ }
73
+ if (marker === 216 || marker === 1 || marker >= 208 && marker <= 215) {
74
+ offset += 1;
75
+ continue;
76
+ }
77
+ const length = uint16(data, offset + 1);
78
+ if (length < 2 || offset + length + 1 > data.length) return void 0;
79
+ if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) {
80
+ const height = uint16(data, offset + 4);
81
+ const width = uint16(data, offset + 6);
82
+ if (width < 1 || height < 1) return void 0;
83
+ frame = {
84
+ extension: "jpeg",
85
+ contentType: "image/jpeg",
86
+ width,
87
+ height
88
+ };
89
+ }
90
+ offset += length + 1;
91
+ }
92
+ }
93
+ function gifMetadata(data) {
94
+ const signature = String.fromCharCode(...data.subarray(0, 6));
95
+ if (data.length < 14 || signature !== "GIF87a" && signature !== "GIF89a" || data[data.length - 1] !== 59) return;
96
+ const width = (data[6] ?? 0) + ((data[7] ?? 0) << 8);
97
+ const height = (data[8] ?? 0) + ((data[9] ?? 0) << 8);
98
+ if (width < 1 || height < 1) return void 0;
99
+ let offset = 13;
100
+ const globalTable = data[10] ?? 0;
101
+ if ((globalTable & 128) !== 0) {
102
+ offset += 3 * (1 << (globalTable & 7) + 1);
103
+ if (offset > data.length) return void 0;
104
+ }
105
+ let hasImageData = false;
106
+ while (offset < data.length) {
107
+ const block = data[offset];
108
+ if (block === 59) {
109
+ if (offset !== data.length - 1 || !hasImageData) return void 0;
110
+ return {
111
+ extension: "gif",
112
+ contentType: "image/gif",
113
+ width,
114
+ height
115
+ };
116
+ }
117
+ if (block === 33) {
118
+ if (offset + 1 >= data.length) return void 0;
119
+ offset += 2;
120
+ let terminated = false;
121
+ while (offset < data.length) {
122
+ const size = data[offset] ?? 0;
123
+ offset += 1;
124
+ if (size === 0) {
125
+ terminated = true;
126
+ break;
127
+ }
128
+ offset += size;
129
+ if (offset > data.length) return void 0;
130
+ }
131
+ if (!terminated) return void 0;
132
+ continue;
133
+ }
134
+ if (block !== 44 || offset + 10 > data.length) return void 0;
135
+ const imageWidth = (data[offset + 5] ?? 0) + ((data[offset + 6] ?? 0) << 8);
136
+ const imageHeight = (data[offset + 7] ?? 0) + ((data[offset + 8] ?? 0) << 8);
137
+ const localTable = data[offset + 9] ?? 0;
138
+ if (imageWidth < 1 || imageHeight < 1) return void 0;
139
+ offset += 10;
140
+ if ((localTable & 128) !== 0) {
141
+ offset += 3 * (1 << (localTable & 7) + 1);
142
+ if (offset > data.length) return void 0;
143
+ }
144
+ if (offset >= data.length) return void 0;
145
+ offset += 1;
146
+ let hasImageBlockData = false;
147
+ let terminated = false;
148
+ while (offset < data.length) {
149
+ const size = data[offset] ?? 0;
150
+ offset += 1;
151
+ if (size === 0) {
152
+ terminated = true;
153
+ break;
154
+ }
155
+ offset += size;
156
+ if (offset > data.length) return void 0;
157
+ hasImageBlockData = true;
158
+ }
159
+ if (!terminated || !hasImageBlockData) return void 0;
160
+ hasImageData = true;
161
+ }
162
+ }
163
+ /** Reads and validates PNG, JPEG, or GIF header metadata from a file path, URL, or byte buffer. */
164
+ function readImage(source) {
165
+ if (typeof source !== "string" && !(source instanceof URL) && !(source instanceof Uint8Array)) throw new CapabilityError("invalid-image-source", "Image.src must be a file path, file URL, or image bytes");
166
+ let bytes;
167
+ try {
168
+ bytes = source instanceof Uint8Array ? new Uint8Array(source) : new Uint8Array(readFileSync(source instanceof URL ? fileURLToPath(source) : source));
169
+ } catch {
170
+ throw new CapabilityError("image-read-failed", "Failed to read image resource");
171
+ }
172
+ const metadata = pngMetadata(bytes) ?? jpegMetadata(bytes) ?? gifMetadata(bytes);
173
+ if (metadata === void 0) throw new CapabilityError("unsupported-image-format", "Invalid image resource content or unsupported format; only PNG, JPEG, and GIF are supported");
174
+ return {
175
+ ...metadata,
176
+ bytes
177
+ };
178
+ }
179
+ let cachedDecoders;
180
+ function imageDecoders() {
181
+ if (cachedDecoders === void 0) {
182
+ const require = createRequire(import.meta.url);
183
+ cachedDecoders = {
184
+ png: require("pngjs"),
185
+ jpeg: require("jpeg-js")
186
+ };
187
+ }
188
+ return cachedDecoders;
189
+ }
190
+ /**
191
+ * Decodes PNG, JPEG, or static first-frame GIF bytes into normalized PNG bytes for SVG embedding.
192
+ * Throws `preview-corrupt-image` if compressed pixel data is invalid.
193
+ */
194
+ function decodeImageToPngBytes(image) {
195
+ const { png: pngModule, jpeg: jpegModule } = imageDecoders();
196
+ let decoded;
197
+ try {
198
+ switch (image.extension) {
199
+ case "png":
200
+ decoded = pngModule.PNG.sync.read(Buffer.from(image.bytes));
201
+ break;
202
+ case "jpeg":
203
+ decoded = jpegModule.decode(image.bytes, { tolerantDecoding: false });
204
+ break;
205
+ case "gif":
206
+ decoded = decodeGifFirstFrame(image.bytes);
207
+ break;
208
+ default: return image.extension;
209
+ }
210
+ } catch (error) {
211
+ if (error instanceof CapabilityError) throw error;
212
+ throw new CapabilityError("preview-corrupt-image", error instanceof Error ? `Failed to decode ${image.extension.toUpperCase()} image for preview: ${error.message}` : `Failed to decode ${image.extension.toUpperCase()} image for preview`);
213
+ }
214
+ const normalized = new pngModule.PNG({
215
+ width: decoded.width,
216
+ height: decoded.height
217
+ });
218
+ normalized.data = Buffer.from(decoded.data);
219
+ return new Uint8Array(pngModule.PNG.sync.write(normalized));
220
+ }
221
+ export { decodeImageToPngBytes, readImage };
@@ -0,0 +1,12 @@
1
+ import { hostNodeCreator } from "../../../core/dist/host.js";
2
+ import { motionElement } from "../motion/motion-elements.js";
3
+ import { createImageNode } from "./image-declaration.js";
4
+ // ../capabilities/dist/image/image-elements.js
5
+ /** Declares a native image handled by the image module within the React tree. */
6
+ function Image(props) {
7
+ return motionElement("image", {
8
+ ...props,
9
+ [hostNodeCreator]: createImageNode
10
+ });
11
+ }
12
+ export { Image };