@poe-platform/safe-bash 0.1.726 → 0.1.727

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 (207) hide show
  1. package/dist/safe-bash/chunks/{chunk-6VZX7ESE.js → chunk-26N7BLXE.js} +3 -3
  2. package/dist/safe-bash/chunks/{chunk-ZZ7JQBPX.js → chunk-4A2OLEML.js} +2 -2
  3. package/dist/safe-bash/chunks/{chunk-LTREB3HX.js → chunk-54MC6XF5.js} +4 -4
  4. package/dist/safe-bash/chunks/{chunk-Z3CCN6Y2.js → chunk-6J5FUESH.js} +2 -2
  5. package/dist/safe-bash/chunks/{chunk-YR5RZBWS.js → chunk-6TBFZ5JE.js} +2 -2
  6. package/dist/safe-bash/chunks/{chunk-6HJNJ625.js → chunk-7MMYQG3P.js} +2 -2
  7. package/dist/safe-bash/chunks/{chunk-WTZZX4LV.js → chunk-A4MB2KXV.js} +2 -2
  8. package/dist/safe-bash/chunks/{chunk-EM2JW7ZH.js → chunk-ATYJKRBZ.js} +2 -2
  9. package/dist/safe-bash/chunks/{chunk-VV24PRPB.js → chunk-AZQOEGP3.js} +1050 -101
  10. package/dist/safe-bash/chunks/chunk-AZQOEGP3.js.map +7 -0
  11. package/dist/safe-bash/chunks/{chunk-EFMXWUYE.js → chunk-B6JEJ6AT.js} +2 -2
  12. package/dist/safe-bash/chunks/{chunk-JFGGQUYP.js → chunk-BFXGHT3R.js} +2 -2
  13. package/dist/safe-bash/chunks/{chunk-RP5IZOOR.js → chunk-BJYV5J65.js} +1050 -101
  14. package/dist/safe-bash/chunks/chunk-BJYV5J65.js.map +7 -0
  15. package/dist/safe-bash/chunks/{chunk-HNHOPD3P.js → chunk-DIEFWGXO.js} +46 -26
  16. package/dist/safe-bash/chunks/{chunk-HNHOPD3P.js.map → chunk-DIEFWGXO.js.map} +2 -2
  17. package/dist/safe-bash/chunks/{chunk-SME47P4B.js → chunk-DV6EZOKM.js} +46 -26
  18. package/dist/safe-bash/chunks/{chunk-SME47P4B.js.map → chunk-DV6EZOKM.js.map} +2 -2
  19. package/dist/safe-bash/chunks/{chunk-646RTREQ.js → chunk-EEDOYIPC.js} +2 -2
  20. package/dist/safe-bash/chunks/{chunk-OFAAHWL5.js → chunk-GCQ5A2T2.js} +2 -2
  21. package/dist/safe-bash/chunks/{chunk-MJW4KSKV.js → chunk-GLPJEDLY.js} +2 -2
  22. package/dist/safe-bash/chunks/{chunk-FOOJWH7J.js → chunk-GO5OKPBO.js} +4 -4
  23. package/dist/safe-bash/chunks/{chunk-5JANWFJ3.js → chunk-GWYXCCGO.js} +4 -4
  24. package/dist/safe-bash/chunks/{chunk-DPHRNHPT.js → chunk-H6KJ4L22.js} +2 -2
  25. package/dist/safe-bash/chunks/{chunk-FLX2BZBF.js → chunk-HGBYIDAK.js} +4 -4
  26. package/dist/safe-bash/chunks/{chunk-VGJIDLZM.js → chunk-KS5VSJYM.js} +15 -8
  27. package/dist/safe-bash/chunks/chunk-KS5VSJYM.js.map +7 -0
  28. package/dist/safe-bash/chunks/{chunk-PO3Z7W3A.js → chunk-MUHYGUFD.js} +4 -4
  29. package/dist/safe-bash/chunks/{chunk-5DLGYPGJ.js → chunk-PDSTXORC.js} +126 -58
  30. package/dist/safe-bash/chunks/chunk-PDSTXORC.js.map +7 -0
  31. package/dist/safe-bash/chunks/{chunk-TIHMU25L.js → chunk-PQ37GDJF.js} +3 -3
  32. package/dist/safe-bash/chunks/{chunk-OTM5RCWZ.js → chunk-QNEDWYC2.js} +15 -8
  33. package/dist/safe-bash/chunks/chunk-QNEDWYC2.js.map +7 -0
  34. package/dist/safe-bash/chunks/{chunk-LZ7FUN6K.js → chunk-RHHDOA67.js} +5 -5
  35. package/dist/safe-bash/chunks/{chunk-DSCL3VA2.js → chunk-SJ3B26XV.js} +4 -4
  36. package/dist/safe-bash/chunks/{chunk-6JBTVWHH.js → chunk-SWACYEIT.js} +5 -5
  37. package/dist/safe-bash/chunks/{chunk-7UJW7TYR.js → chunk-TD6NWAUK.js} +126 -58
  38. package/dist/safe-bash/chunks/chunk-TD6NWAUK.js.map +7 -0
  39. package/dist/safe-bash/chunks/{chunk-Q4I754TV.js → chunk-THOBFD5C.js} +2 -2
  40. package/dist/safe-bash/chunks/{chunk-XELW5O3R.js → chunk-U2STHT7S.js} +2 -2
  41. package/dist/safe-bash/chunks/{chunk-5X4SOSTT.js → chunk-UJHE5PTK.js} +2 -2
  42. package/dist/safe-bash/chunks/{chunk-B6YFFKYG.js → chunk-X4I3RHTC.js} +5 -1
  43. package/dist/safe-bash/chunks/chunk-X4I3RHTC.js.map +7 -0
  44. package/dist/safe-bash/chunks/{chunk-YOK5UHA7.js → chunk-XKXFX3RH.js} +5 -1
  45. package/dist/safe-bash/chunks/chunk-XKXFX3RH.js.map +7 -0
  46. package/dist/safe-bash/chunks/{chunk-PLCYP2E5.js → chunk-XV4K3UUF.js} +2 -2
  47. package/dist/safe-bash/commands/csplit/index.browser.js +2 -2
  48. package/dist/safe-bash/commands/factor/index.browser.js +2 -2
  49. package/dist/safe-bash/commands/getopt/index.browser.js +2 -2
  50. package/dist/safe-bash/commands/hexdump/index.browser.js +2 -2
  51. package/dist/safe-bash/commands/iconv/index.browser.js +2 -2
  52. package/dist/safe-bash/commands/internal.d.ts.map +1 -1
  53. package/dist/safe-bash/commands/internal.js +4 -3
  54. package/dist/safe-bash/commands/internal.js.map +1 -1
  55. package/dist/safe-bash/commands/line-endings/index.browser.js +2 -2
  56. package/dist/safe-bash/commands/llm/index.browser.js +4 -4
  57. package/dist/safe-bash/commands/network/index.browser.js +4 -4
  58. package/dist/safe-bash/commands/node/index.browser.js +4 -4
  59. package/dist/safe-bash/commands/pandoc/index.js.map +1 -1
  60. package/dist/safe-bash/commands/pr/index.browser.js +3 -3
  61. package/dist/safe-bash/commands/python/index.browser.js +2 -2
  62. package/dist/safe-bash/commands/record-buffer.d.ts.map +1 -1
  63. package/dist/safe-bash/commands/record-buffer.js +12 -4
  64. package/dist/safe-bash/commands/record-buffer.js.map +1 -1
  65. package/dist/safe-bash/commands/regex-execution/bounded-provider.d.ts.map +1 -1
  66. package/dist/safe-bash/commands/regex-execution/bounded-provider.js +75 -8
  67. package/dist/safe-bash/commands/regex-execution/bounded-provider.js.map +1 -1
  68. package/dist/safe-bash/commands/regex-execution/ere/limits.d.ts +1 -1
  69. package/dist/safe-bash/commands/regex-execution/ere/limits.d.ts.map +1 -1
  70. package/dist/safe-bash/commands/regex-execution/ere/limits.js +6 -4
  71. package/dist/safe-bash/commands/regex-execution/ere/limits.js.map +1 -1
  72. package/dist/safe-bash/commands/regex-execution/portable.d.ts.map +1 -1
  73. package/dist/safe-bash/commands/regex-execution/portable.js +7 -2
  74. package/dist/safe-bash/commands/regex-execution/portable.js.map +1 -1
  75. package/dist/safe-bash/commands/regex-execution/protocol.d.ts +2 -0
  76. package/dist/safe-bash/commands/regex-execution/protocol.d.ts.map +1 -1
  77. package/dist/safe-bash/commands/regex-execution/protocol.js +26 -0
  78. package/dist/safe-bash/commands/regex-execution/protocol.js.map +1 -1
  79. package/dist/safe-bash/commands/regex-execution/utf8.d.ts +1 -1
  80. package/dist/safe-bash/commands/regex-execution/utf8.d.ts.map +1 -1
  81. package/dist/safe-bash/commands/regex-execution/utf8.js +26 -2
  82. package/dist/safe-bash/commands/regex-execution/utf8.js.map +1 -1
  83. package/dist/safe-bash/commands/search/grep.d.ts.map +1 -1
  84. package/dist/safe-bash/commands/search/grep.js +109 -15
  85. package/dist/safe-bash/commands/search/grep.js.map +1 -1
  86. package/dist/safe-bash/commands/search/matcher.d.ts +1 -1
  87. package/dist/safe-bash/commands/search/matcher.d.ts.map +1 -1
  88. package/dist/safe-bash/commands/search/matcher.js +2 -0
  89. package/dist/safe-bash/commands/search/matcher.js.map +1 -1
  90. package/dist/safe-bash/commands/search/shared.d.ts.map +1 -1
  91. package/dist/safe-bash/commands/search/shared.js +23 -12
  92. package/dist/safe-bash/commands/search/shared.js.map +1 -1
  93. package/dist/safe-bash/commands/standard.d.ts.map +1 -1
  94. package/dist/safe-bash/commands/standard.js +22 -0
  95. package/dist/safe-bash/commands/standard.js.map +1 -1
  96. package/dist/safe-bash/commands/streams.d.ts.map +1 -1
  97. package/dist/safe-bash/commands/streams.js +54 -10
  98. package/dist/safe-bash/commands/streams.js.map +1 -1
  99. package/dist/safe-bash/commands/structured/input.d.ts.map +1 -1
  100. package/dist/safe-bash/commands/structured/input.js +484 -55
  101. package/dist/safe-bash/commands/structured/input.js.map +1 -1
  102. package/dist/safe-bash/commands/structured/interpreter.d.ts +3 -0
  103. package/dist/safe-bash/commands/structured/interpreter.d.ts.map +1 -1
  104. package/dist/safe-bash/commands/structured/interpreter.js +157 -1
  105. package/dist/safe-bash/commands/structured/interpreter.js.map +1 -1
  106. package/dist/safe-bash/commands/structured/jq.d.ts.map +1 -1
  107. package/dist/safe-bash/commands/structured/jq.js +50 -24
  108. package/dist/safe-bash/commands/structured/jq.js.map +1 -1
  109. package/dist/safe-bash/commands/structured/limits.d.ts +5 -0
  110. package/dist/safe-bash/commands/structured/limits.d.ts.map +1 -1
  111. package/dist/safe-bash/commands/structured/limits.js +51 -36
  112. package/dist/safe-bash/commands/structured/limits.js.map +1 -1
  113. package/dist/safe-bash/commands/structured/numbers.d.ts +1 -0
  114. package/dist/safe-bash/commands/structured/numbers.d.ts.map +1 -1
  115. package/dist/safe-bash/commands/structured/numbers.js +32 -0
  116. package/dist/safe-bash/commands/structured/numbers.js.map +1 -1
  117. package/dist/safe-bash/commands/text-programs/awk-reader.d.ts +1 -0
  118. package/dist/safe-bash/commands/text-programs/awk-reader.d.ts.map +1 -1
  119. package/dist/safe-bash/commands/text-programs/awk-reader.js +41 -5
  120. package/dist/safe-bash/commands/text-programs/awk-reader.js.map +1 -1
  121. package/dist/safe-bash/commands/text-programs/awk-retention.d.ts +1 -0
  122. package/dist/safe-bash/commands/text-programs/awk-retention.d.ts.map +1 -1
  123. package/dist/safe-bash/commands/text-programs/awk-retention.js +9 -0
  124. package/dist/safe-bash/commands/text-programs/awk-retention.js.map +1 -1
  125. package/dist/safe-bash/commands/text-programs/awk-runtime.d.ts +13 -0
  126. package/dist/safe-bash/commands/text-programs/awk-runtime.d.ts.map +1 -1
  127. package/dist/safe-bash/commands/text-programs/awk-runtime.js +421 -83
  128. package/dist/safe-bash/commands/text-programs/awk-runtime.js.map +1 -1
  129. package/dist/safe-bash/commands/text-programs/awk-values.d.ts.map +1 -1
  130. package/dist/safe-bash/commands/text-programs/awk-values.js +21 -0
  131. package/dist/safe-bash/commands/text-programs/awk-values.js.map +1 -1
  132. package/dist/safe-bash/commands/text-programs/regex.d.ts +15 -2
  133. package/dist/safe-bash/commands/text-programs/regex.d.ts.map +1 -1
  134. package/dist/safe-bash/commands/text-programs/regex.js +501 -13
  135. package/dist/safe-bash/commands/text-programs/regex.js.map +1 -1
  136. package/dist/safe-bash/commands/text-programs/sed.d.ts.map +1 -1
  137. package/dist/safe-bash/commands/text-programs/sed.js +242 -102
  138. package/dist/safe-bash/commands/text-programs/sed.js.map +1 -1
  139. package/dist/safe-bash/commands/text-programs/shared.d.ts +2 -0
  140. package/dist/safe-bash/commands/text-programs/shared.d.ts.map +1 -1
  141. package/dist/safe-bash/commands/text-programs/shared.js +36 -0
  142. package/dist/safe-bash/commands/text-programs/shared.js.map +1 -1
  143. package/dist/safe-bash/commands/text.d.ts.map +1 -1
  144. package/dist/safe-bash/commands/text.js +136 -19
  145. package/dist/safe-bash/commands/text.js.map +1 -1
  146. package/dist/safe-bash/commands/tsort/index.browser.js +2 -2
  147. package/dist/safe-bash/commands/xml/index.browser.js +5 -5
  148. package/dist/safe-bash/commands/yq/index.browser.js +5 -5
  149. package/dist/safe-bash/contracts/yield.d.ts +1 -0
  150. package/dist/safe-bash/contracts/yield.d.ts.map +1 -1
  151. package/dist/safe-bash/contracts/yield.js +3 -0
  152. package/dist/safe-bash/contracts/yield.js.map +1 -1
  153. package/dist/safe-bash/core.browser.js +1052 -256
  154. package/dist/safe-bash/core.browser.js.map +3 -3
  155. package/dist/safe-bash/plugins/composition.d.ts +1 -0
  156. package/dist/safe-bash/plugins/composition.d.ts.map +1 -1
  157. package/dist/safe-bash/plugins/composition.js +80 -2
  158. package/dist/safe-bash/plugins/composition.js.map +1 -1
  159. package/dist/safe-bash/plugins/index.d.ts.map +1 -1
  160. package/dist/safe-bash/plugins/index.js +2 -2
  161. package/dist/safe-bash/plugins/index.js.map +1 -1
  162. package/dist/safe-bash-command-fold/arguments.d.ts +1 -1
  163. package/dist/safe-bash-command-fold/contracts.d.ts +2 -1
  164. package/dist/safe-bash-command-fold/engine.d.ts +1 -1
  165. package/dist/safe-bash-command-fold/index.js +10 -8
  166. package/dist/safe-bash-command-fold/index.js.map +2 -2
  167. package/dist/safe-bash-command-sips/index.js +231 -67
  168. package/dist/safe-bash-command-sips/index.js.map +2 -2
  169. package/dist/safe-bash-command-unrtf/contracts.d.ts +5 -2
  170. package/dist/safe-bash-command-unrtf/index.js +6 -5
  171. package/dist/safe-bash-command-unrtf/index.js.map +2 -2
  172. package/dist/safe-playwright-cloudflare/browser-run-code.js +22 -6
  173. package/package.json +2 -2
  174. package/dist/safe-bash/chunks/chunk-5DLGYPGJ.js.map +0 -7
  175. package/dist/safe-bash/chunks/chunk-7UJW7TYR.js.map +0 -7
  176. package/dist/safe-bash/chunks/chunk-B6YFFKYG.js.map +0 -7
  177. package/dist/safe-bash/chunks/chunk-OTM5RCWZ.js.map +0 -7
  178. package/dist/safe-bash/chunks/chunk-RP5IZOOR.js.map +0 -7
  179. package/dist/safe-bash/chunks/chunk-VGJIDLZM.js.map +0 -7
  180. package/dist/safe-bash/chunks/chunk-VV24PRPB.js.map +0 -7
  181. package/dist/safe-bash/chunks/chunk-YOK5UHA7.js.map +0 -7
  182. /package/dist/safe-bash/chunks/{chunk-6VZX7ESE.js.map → chunk-26N7BLXE.js.map} +0 -0
  183. /package/dist/safe-bash/chunks/{chunk-ZZ7JQBPX.js.map → chunk-4A2OLEML.js.map} +0 -0
  184. /package/dist/safe-bash/chunks/{chunk-LTREB3HX.js.map → chunk-54MC6XF5.js.map} +0 -0
  185. /package/dist/safe-bash/chunks/{chunk-Z3CCN6Y2.js.map → chunk-6J5FUESH.js.map} +0 -0
  186. /package/dist/safe-bash/chunks/{chunk-YR5RZBWS.js.map → chunk-6TBFZ5JE.js.map} +0 -0
  187. /package/dist/safe-bash/chunks/{chunk-6HJNJ625.js.map → chunk-7MMYQG3P.js.map} +0 -0
  188. /package/dist/safe-bash/chunks/{chunk-WTZZX4LV.js.map → chunk-A4MB2KXV.js.map} +0 -0
  189. /package/dist/safe-bash/chunks/{chunk-EM2JW7ZH.js.map → chunk-ATYJKRBZ.js.map} +0 -0
  190. /package/dist/safe-bash/chunks/{chunk-EFMXWUYE.js.map → chunk-B6JEJ6AT.js.map} +0 -0
  191. /package/dist/safe-bash/chunks/{chunk-JFGGQUYP.js.map → chunk-BFXGHT3R.js.map} +0 -0
  192. /package/dist/safe-bash/chunks/{chunk-646RTREQ.js.map → chunk-EEDOYIPC.js.map} +0 -0
  193. /package/dist/safe-bash/chunks/{chunk-OFAAHWL5.js.map → chunk-GCQ5A2T2.js.map} +0 -0
  194. /package/dist/safe-bash/chunks/{chunk-MJW4KSKV.js.map → chunk-GLPJEDLY.js.map} +0 -0
  195. /package/dist/safe-bash/chunks/{chunk-FOOJWH7J.js.map → chunk-GO5OKPBO.js.map} +0 -0
  196. /package/dist/safe-bash/chunks/{chunk-5JANWFJ3.js.map → chunk-GWYXCCGO.js.map} +0 -0
  197. /package/dist/safe-bash/chunks/{chunk-DPHRNHPT.js.map → chunk-H6KJ4L22.js.map} +0 -0
  198. /package/dist/safe-bash/chunks/{chunk-FLX2BZBF.js.map → chunk-HGBYIDAK.js.map} +0 -0
  199. /package/dist/safe-bash/chunks/{chunk-PO3Z7W3A.js.map → chunk-MUHYGUFD.js.map} +0 -0
  200. /package/dist/safe-bash/chunks/{chunk-TIHMU25L.js.map → chunk-PQ37GDJF.js.map} +0 -0
  201. /package/dist/safe-bash/chunks/{chunk-LZ7FUN6K.js.map → chunk-RHHDOA67.js.map} +0 -0
  202. /package/dist/safe-bash/chunks/{chunk-DSCL3VA2.js.map → chunk-SJ3B26XV.js.map} +0 -0
  203. /package/dist/safe-bash/chunks/{chunk-6JBTVWHH.js.map → chunk-SWACYEIT.js.map} +0 -0
  204. /package/dist/safe-bash/chunks/{chunk-Q4I754TV.js.map → chunk-THOBFD5C.js.map} +0 -0
  205. /package/dist/safe-bash/chunks/{chunk-XELW5O3R.js.map → chunk-U2STHT7S.js.map} +0 -0
  206. /package/dist/safe-bash/chunks/{chunk-5X4SOSTT.js.map → chunk-UJHE5PTK.js.map} +0 -0
  207. /package/dist/safe-bash/chunks/{chunk-PLCYP2E5.js.map → chunk-XV4K3UUF.js.map} +0 -0
@@ -4159,6 +4159,10 @@ function decodeTiffImage(bytes) {
4159
4159
  let photometric = 2;
4160
4160
  let stripOffsets = [8];
4161
4161
  let stripByteCounts = [];
4162
+ let tileWidth = 0;
4163
+ let tileLength = 0;
4164
+ let tileOffsets = [];
4165
+ let tileByteCounts = [];
4162
4166
  let samplesPerPixel = 4;
4163
4167
  let rowsPerStrip = 0;
4164
4168
  let predictor = 1;
@@ -4183,42 +4187,77 @@ function decodeTiffImage(bytes) {
4183
4187
  else if (tag === 282 && first > 0) xRes = first;
4184
4188
  else if (tag === 296 && (first === 2 || first === 3)) resUnit = first;
4185
4189
  else if (tag === 317 && first > 0) predictor = first;
4190
+ else if (tag === 322 && first > 0) tileWidth = first;
4191
+ else if (tag === 323 && first > 0) tileLength = first;
4192
+ else if (tag === 324 && vals.length > 0) tileOffsets = vals;
4193
+ else if (tag === 325 && vals.length > 0) tileByteCounts = vals;
4186
4194
  }
4187
4195
  const bytesPerSample = Math.max(1, bitsPerSample >>> 3);
4196
+ const bytesPerPixel = samplesPerPixel * bytesPerSample;
4188
4197
  const rowByteWidth = width * samplesPerPixel * bytesPerSample;
4189
4198
  const totalExpectedBytes = height * rowByteWidth;
4190
4199
  const combined = new Uint8Array(totalExpectedBytes);
4191
- const effectiveRowsPerStrip = rowsPerStrip > 0 ? rowsPerStrip : height;
4192
- let dstOff = 0;
4193
- for (let s = 0; s < stripOffsets.length && dstOff < totalExpectedBytes; s++) {
4194
- const off = stripOffsets[s];
4195
- const remainingBytes = totalExpectedBytes - dstOff;
4196
- const expectedStripBytes = Math.min(remainingBytes, effectiveRowsPerStrip * rowByteWidth);
4197
- const rawLen = stripByteCounts[s] ?? Math.max(0, bytes.length - off);
4200
+ const decompressChunk = (off, rawLen, expectedBytes) => {
4198
4201
  const rawSlice = bytes.subarray(off, Math.min(bytes.length, off + rawLen));
4199
- let decodedStrip;
4200
4202
  if (compression === 8 || compression === 32946) {
4201
4203
  try {
4202
- decodedStrip = inflate3(rawSlice);
4204
+ return inflate3(rawSlice);
4203
4205
  } catch {
4204
- decodedStrip = rawSlice;
4206
+ return rawSlice;
4205
4207
  }
4206
- } else if (compression === 5) {
4207
- decodedStrip = decodeTiffLzw(rawSlice, expectedStripBytes);
4208
- } else if (compression === 32773) {
4209
- decodedStrip = decodePackBits(rawSlice, expectedStripBytes);
4210
- } else {
4211
- decodedStrip = rawSlice;
4212
4208
  }
4213
- const copyLen = Math.min(decodedStrip.length, remainingBytes);
4214
- combined.set(decodedStrip.subarray(0, copyLen), dstOff);
4215
- dstOff += copyLen;
4216
- }
4217
- if (predictor === 2 && bytesPerSample === 1) {
4218
- for (let y = 0; y < height; y++) {
4219
- const rowStart = y * rowByteWidth;
4220
- for (let x = samplesPerPixel; x < rowByteWidth; x++) {
4221
- combined[rowStart + x] = (combined[rowStart + x] ?? 0) + (combined[rowStart + x - samplesPerPixel] ?? 0) & 255;
4209
+ if (compression === 5) return decodeTiffLzw(rawSlice, expectedBytes);
4210
+ if (compression === 32773) return decodePackBits(rawSlice, expectedBytes);
4211
+ return rawSlice;
4212
+ };
4213
+ if (tileWidth > 0 && tileLength > 0 && tileOffsets.length > 0) {
4214
+ const tilesAcross = Math.max(1, Math.ceil(width / tileWidth));
4215
+ const tileRowByteWidth = tileWidth * bytesPerPixel;
4216
+ const expectedTileBytes = tileLength * tileRowByteWidth;
4217
+ for (let t = 0; t < tileOffsets.length; t++) {
4218
+ const off = tileOffsets[t];
4219
+ const rawLen = tileByteCounts[t] ?? Math.max(0, bytes.length - off);
4220
+ const decodedTile = new Uint8Array(decompressChunk(off, rawLen, expectedTileBytes));
4221
+ if (predictor === 2 && bytesPerSample === 1) {
4222
+ for (let ry = 0; ry < tileLength; ry++) {
4223
+ const rStart = ry * tileRowByteWidth;
4224
+ for (let rx = samplesPerPixel; rx < tileRowByteWidth && rStart + rx < decodedTile.length; rx++) {
4225
+ decodedTile[rStart + rx] = (decodedTile[rStart + rx] ?? 0) + (decodedTile[rStart + rx - samplesPerPixel] ?? 0) & 255;
4226
+ }
4227
+ }
4228
+ }
4229
+ const tx = t % tilesAcross * tileWidth;
4230
+ const ty = Math.floor(t / tilesAcross) * tileLength;
4231
+ const validW = Math.max(0, Math.min(tileWidth, width - tx));
4232
+ const validH = Math.max(0, Math.min(tileLength, height - ty));
4233
+ const validRowBytes = validW * bytesPerPixel;
4234
+ for (let ry = 0; ry < validH; ry++) {
4235
+ const srcStart = ry * tileRowByteWidth;
4236
+ const dstStart = (ty + ry) * rowByteWidth + tx * bytesPerPixel;
4237
+ if (srcStart + validRowBytes <= decodedTile.length && dstStart + validRowBytes <= combined.length) {
4238
+ combined.set(decodedTile.subarray(srcStart, srcStart + validRowBytes), dstStart);
4239
+ }
4240
+ }
4241
+ }
4242
+ } else {
4243
+ const effectiveRowsPerStrip = rowsPerStrip > 0 ? rowsPerStrip : height;
4244
+ let dstOff = 0;
4245
+ for (let s = 0; s < stripOffsets.length && dstOff < totalExpectedBytes; s++) {
4246
+ const off = stripOffsets[s];
4247
+ const remainingBytes = totalExpectedBytes - dstOff;
4248
+ const expectedStripBytes = Math.min(remainingBytes, effectiveRowsPerStrip * rowByteWidth);
4249
+ const rawLen = stripByteCounts[s] ?? Math.max(0, bytes.length - off);
4250
+ const decodedStrip = decompressChunk(off, rawLen, expectedStripBytes);
4251
+ const copyLen = Math.min(decodedStrip.length, remainingBytes);
4252
+ combined.set(decodedStrip.subarray(0, copyLen), dstOff);
4253
+ dstOff += copyLen;
4254
+ }
4255
+ if (predictor === 2 && bytesPerSample === 1) {
4256
+ for (let y = 0; y < height; y++) {
4257
+ const rowStart = y * rowByteWidth;
4258
+ for (let x = samplesPerPixel; x < rowByteWidth; x++) {
4259
+ combined[rowStart + x] = (combined[rowStart + x] ?? 0) + (combined[rowStart + x - samplesPerPixel] ?? 0) & 255;
4260
+ }
4222
4261
  }
4223
4262
  }
4224
4263
  }
@@ -4617,6 +4656,7 @@ function decodeSvgImage(bytes, options) {
4617
4656
 
4618
4657
  // packages/image-ast/src/codecs/index.ts
4619
4658
  var DEFAULT_PIXEL_LIMIT = 268402689;
4659
+ var DECODE_CACHE = /* @__PURE__ */ new WeakMap();
4620
4660
  function detectImageFormat(bytes) {
4621
4661
  if (isPngBytes(bytes)) return "png";
4622
4662
  if (isJpegBytes(bytes)) return "jpeg";
@@ -4752,14 +4792,25 @@ function decodeImage(bytes, options) {
4752
4792
  };
4753
4793
  }
4754
4794
  if (options?.raw && bytes) {
4755
- const { width, height, channels } = options.raw;
4795
+ const { width, height, channels, premultiplied } = options.raw;
4756
4796
  const data = new Uint8Array(width * height * 4);
4757
4797
  for (let i = 0; i < width * height; i++) {
4758
4798
  if (channels === 4) {
4759
- data[i * 4] = bytes[i * 4] ?? 0;
4760
- data[i * 4 + 1] = bytes[i * 4 + 1] ?? 0;
4761
- data[i * 4 + 2] = bytes[i * 4 + 2] ?? 0;
4762
- data[i * 4 + 3] = bytes[i * 4 + 3] ?? 255;
4799
+ const r = bytes[i * 4] ?? 0;
4800
+ const g = bytes[i * 4 + 1] ?? 0;
4801
+ const b = bytes[i * 4 + 2] ?? 0;
4802
+ const a = bytes[i * 4 + 3] ?? 255;
4803
+ if (premultiplied && a > 0 && a < 255) {
4804
+ const scale = 255 / a;
4805
+ data[i * 4] = Math.min(255, Math.round(r * scale));
4806
+ data[i * 4 + 1] = Math.min(255, Math.round(g * scale));
4807
+ data[i * 4 + 2] = Math.min(255, Math.round(b * scale));
4808
+ } else {
4809
+ data[i * 4] = r;
4810
+ data[i * 4 + 1] = g;
4811
+ data[i * 4 + 2] = b;
4812
+ }
4813
+ data[i * 4 + 3] = a;
4763
4814
  } else if (channels === 3) {
4764
4815
  data[i * 4] = bytes[i * 3] ?? 0;
4765
4816
  data[i * 4 + 1] = bytes[i * 3 + 1] ?? 0;
@@ -4794,35 +4845,55 @@ function decodeImage(bytes, options) {
4794
4845
  if (!bytes || bytes.length === 0) {
4795
4846
  throw new Error("Empty image input");
4796
4847
  }
4848
+ const canCache = options?.density === void 0 && options?.page === void 0 && options?.pages === void 0 && options?.raw === void 0 && options?.create === void 0;
4849
+ if (canCache) {
4850
+ const cached = DECODE_CACHE.get(bytes);
4851
+ if (cached) return cached;
4852
+ }
4797
4853
  const meta = readImageMetadata(bytes, options);
4854
+ let decoded;
4798
4855
  switch (meta.format) {
4799
4856
  case "png":
4800
- return decodePngImage(bytes);
4857
+ decoded = decodePngImage(bytes);
4858
+ break;
4801
4859
  case "jpeg":
4802
- return decodeJpegImage(bytes);
4860
+ decoded = decodeJpegImage(bytes);
4861
+ break;
4803
4862
  case "webp":
4804
- return decodeWebpImage(bytes);
4863
+ decoded = decodeWebpImage(bytes);
4864
+ break;
4805
4865
  case "heic":
4806
4866
  case "heif":
4807
4867
  case "avif":
4808
- return decodeHeifImage(bytes);
4868
+ decoded = decodeHeifImage(bytes);
4869
+ break;
4809
4870
  case "gif":
4810
- return decodeGifImage(bytes, options);
4871
+ decoded = decodeGifImage(bytes, options);
4872
+ break;
4811
4873
  case "ppm":
4812
4874
  case "pgm":
4813
4875
  case "pbm":
4814
- return decodeNetpbmImage(bytes);
4876
+ decoded = decodeNetpbmImage(bytes);
4877
+ break;
4815
4878
  case "bmp":
4816
- return decodeBmpImage(bytes);
4879
+ decoded = decodeBmpImage(bytes);
4880
+ break;
4817
4881
  case "tiff":
4818
- return decodeTiffImage(bytes);
4882
+ decoded = decodeTiffImage(bytes);
4883
+ break;
4819
4884
  case "pdf":
4820
- return decodePdfImage(bytes, options);
4885
+ decoded = decodePdfImage(bytes, options);
4886
+ break;
4821
4887
  case "svg":
4822
- return decodeSvgImage(bytes, options);
4888
+ decoded = decodeSvgImage(bytes, options);
4889
+ break;
4823
4890
  default:
4824
4891
  throw new Error(`Unsupported format: ${meta.format}`);
4825
4892
  }
4893
+ if (canCache) {
4894
+ DECODE_CACHE.set(bytes, decoded);
4895
+ }
4896
+ return decoded;
4826
4897
  }
4827
4898
  function encodeImage(img, options) {
4828
4899
  const fmt = options.format === "pdf" || options.format === "svg" ? "png" : options.format ?? (img.format === "pdf" || img.format === "svg" ? "png" : img.format);
@@ -5381,20 +5452,38 @@ function rotateImage(img, angle, background = { r: 0, g: 0, b: 0, a: 255 }) {
5381
5452
  const i10 = (y0 * img.width + (x0 + 1)) * 4;
5382
5453
  const i01 = ((y0 + 1) * img.width + x0) * 4;
5383
5454
  const i11 = ((y0 + 1) * img.width + (x0 + 1)) * 4;
5384
- for (let c = 0; c < 4; c++) {
5385
- const top = img.data[i00 + c] * (1 - fx) + img.data[i10 + c] * fx;
5386
- const bot = img.data[i01 + c] * (1 - fx) + img.data[i11 + c] * fx;
5387
- out[dIdx + c] = Math.round(top * (1 - fy) + bot * fy);
5455
+ const w00 = (1 - fx) * (1 - fy);
5456
+ const w10 = fx * (1 - fy);
5457
+ const w01 = (1 - fx) * fy;
5458
+ const w11 = fx * fy;
5459
+ const a00 = img.data[i00 + 3] / 255;
5460
+ const a10 = img.data[i10 + 3] / 255;
5461
+ const a01 = img.data[i01 + 3] / 255;
5462
+ const a11 = img.data[i11 + 3] / 255;
5463
+ const outA = a00 * w00 + a10 * w10 + a01 * w01 + a11 * w11;
5464
+ if (outA > 1e-6) {
5465
+ for (let c = 0; c < 3; c++) {
5466
+ const pm = img.data[i00 + c] * a00 * w00 + img.data[i10 + c] * a10 * w10 + img.data[i01 + c] * a01 * w01 + img.data[i11 + c] * a11 * w11;
5467
+ out[dIdx + c] = Math.max(0, Math.min(255, Math.round(pm / outA)));
5468
+ }
5469
+ out[dIdx + 3] = Math.max(0, Math.min(255, Math.round(outA * 255)));
5470
+ } else {
5471
+ out[dIdx] = 0;
5472
+ out[dIdx + 1] = 0;
5473
+ out[dIdx + 2] = 0;
5474
+ out[dIdx + 3] = 0;
5388
5475
  }
5389
5476
  }
5390
5477
  }
5391
5478
  }
5479
+ const nextHasAlpha = img.hasAlpha || background.a < 255;
5392
5480
  return {
5393
5481
  ...img,
5394
5482
  width: dstW,
5395
5483
  height: dstH,
5396
5484
  data: out,
5397
- hasAlpha: img.hasAlpha || background.a < 255
5485
+ hasAlpha: nextHasAlpha,
5486
+ channels: nextHasAlpha ? img.channels < 3 ? 2 : 4 : img.channels
5398
5487
  };
5399
5488
  }
5400
5489
  function extractImage(img, region) {
@@ -5535,7 +5624,8 @@ function extendImage(img, spec) {
5535
5624
  width: dstW,
5536
5625
  height: dstH,
5537
5626
  data: out,
5538
- hasAlpha: img.hasAlpha || spec.background.a < 255
5627
+ hasAlpha: img.hasAlpha || spec.background.a < 255,
5628
+ channels: img.hasAlpha || spec.background.a < 255 ? img.channels < 3 ? 2 : 4 : img.channels
5539
5629
  };
5540
5630
  }
5541
5631
  function blendChannel(s, d, mode) {
@@ -5584,8 +5674,31 @@ function compositeImage(base, layers) {
5584
5674
  } else if (layer.input instanceof Uint8Array) {
5585
5675
  overlay = decodeImage(layer.input, {
5586
5676
  ...layer.density !== void 0 ? { density: layer.density } : {},
5587
- ...layer.raw !== void 0 ? { raw: layer.raw } : {}
5677
+ ...layer.raw !== void 0 ? {
5678
+ raw: {
5679
+ ...layer.raw,
5680
+ ...layer.premultiplied !== void 0 ? { premultiplied: layer.premultiplied } : {}
5681
+ }
5682
+ } : {}
5588
5683
  });
5684
+ if (layer.premultiplied && !layer.raw) {
5685
+ const unpremul = new Uint8Array(overlay.data.length);
5686
+ for (let i = 0; i < overlay.width * overlay.height; i++) {
5687
+ const a = overlay.data[i * 4 + 3];
5688
+ if (a > 0 && a < 255) {
5689
+ const scale = 255 / a;
5690
+ unpremul[i * 4] = Math.min(255, Math.round(overlay.data[i * 4] * scale));
5691
+ unpremul[i * 4 + 1] = Math.min(255, Math.round(overlay.data[i * 4 + 1] * scale));
5692
+ unpremul[i * 4 + 2] = Math.min(255, Math.round(overlay.data[i * 4 + 2] * scale));
5693
+ } else {
5694
+ unpremul[i * 4] = overlay.data[i * 4];
5695
+ unpremul[i * 4 + 1] = overlay.data[i * 4 + 1];
5696
+ unpremul[i * 4 + 2] = overlay.data[i * 4 + 2];
5697
+ }
5698
+ unpremul[i * 4 + 3] = a;
5699
+ }
5700
+ overlay = { ...overlay, data: unpremul };
5701
+ }
5589
5702
  } else {
5590
5703
  overlay = decodeImage(void 0, {
5591
5704
  create: layer.input.create,
@@ -5598,10 +5711,27 @@ function compositeImage(base, layers) {
5598
5711
  baseH,
5599
5712
  overlay.width,
5600
5713
  overlay.height,
5601
- layer.gravity ?? "northwest"
5714
+ layer.gravity ?? "center"
5602
5715
  );
5603
- const startX = layer.left !== void 0 ? Math.round(layer.left) : grav.x;
5604
- const startY = layer.top !== void 0 ? Math.round(layer.top) : grav.y;
5716
+ const startX = layer.left !== void 0 ? Math.round(layer.left) : layer.top !== void 0 ? 0 : grav.x;
5717
+ const startY = layer.top !== void 0 ? Math.round(layer.top) : layer.left !== void 0 ? 0 : grav.y;
5718
+ if (!layer.tile && !overlay.hasAlpha && (blend === "over" || blend === "source")) {
5719
+ const copyStartX = Math.max(0, startX);
5720
+ const copyEndX = Math.min(baseW, startX + overlay.width);
5721
+ const copyW = copyEndX - copyStartX;
5722
+ if (copyW > 0) {
5723
+ const srcOffX = copyStartX - startX;
5724
+ const copyStartY = Math.max(0, startY);
5725
+ const copyEndY = Math.min(baseH, startY + overlay.height);
5726
+ for (let dy = copyStartY; dy < copyEndY; dy++) {
5727
+ const sy = dy - startY;
5728
+ const sRowOff = (sy * overlay.width + srcOffX) * 4;
5729
+ const dRowOff = (dy * baseW + copyStartX) * 4;
5730
+ out.set(overlay.data.subarray(sRowOff, sRowOff + copyW * 4), dRowOff);
5731
+ }
5732
+ }
5733
+ continue;
5734
+ }
5605
5735
  const iterW = layer.tile ? baseW : overlay.width;
5606
5736
  const iterH = layer.tile ? baseH : overlay.height;
5607
5737
  for (let ty = 0; ty < 1; ty++) {
@@ -5609,11 +5739,11 @@ function compositeImage(base, layers) {
5609
5739
  for (let y = 0; y < iterH; y++) {
5610
5740
  const dy = layer.tile ? y : startY + y;
5611
5741
  if (dy < 0 || dy >= baseH) continue;
5612
- const sy = layer.tile ? dy % overlay.height : y;
5742
+ const sy = layer.tile ? ((dy - startY) % overlay.height + overlay.height) % overlay.height : y;
5613
5743
  for (let x = 0; x < iterW; x++) {
5614
5744
  const dx = layer.tile ? x : startX + x;
5615
5745
  if (dx < 0 || dx >= baseW) continue;
5616
- const sx = layer.tile ? dx % overlay.width : x;
5746
+ const sx = layer.tile ? ((dx - startX) % overlay.width + overlay.width) % overlay.width : x;
5617
5747
  const sIdx = (sy * overlay.width + sx) * 4;
5618
5748
  const dIdx = (dy * baseW + dx) * 4;
5619
5749
  const sr = overlay.data[sIdx] / 255;
@@ -5639,6 +5769,21 @@ function compositeImage(base, layers) {
5639
5769
  continue;
5640
5770
  }
5641
5771
  if (blend === "dest") continue;
5772
+ if (blend === "over") {
5773
+ const outA2 = sa + da * (1 - sa);
5774
+ if (outA2 > 0) {
5775
+ out[dIdx] = Math.max(0, Math.min(255, Math.round((sr * sa + dr * da * (1 - sa)) / outA2 * 255)));
5776
+ out[dIdx + 1] = Math.max(0, Math.min(255, Math.round((sg * sa + dg * da * (1 - sa)) / outA2 * 255)));
5777
+ out[dIdx + 2] = Math.max(0, Math.min(255, Math.round((sb * sa + db * da * (1 - sa)) / outA2 * 255)));
5778
+ out[dIdx + 3] = Math.max(0, Math.min(255, Math.round(outA2 * 255)));
5779
+ } else {
5780
+ out[dIdx] = 0;
5781
+ out[dIdx + 1] = 0;
5782
+ out[dIdx + 2] = 0;
5783
+ out[dIdx + 3] = 0;
5784
+ }
5785
+ continue;
5786
+ }
5642
5787
  if (blend === "dest-over") {
5643
5788
  const outA2 = da + sa * (1 - da);
5644
5789
  if (outA2 > 0) {
@@ -5737,12 +5882,18 @@ function compositeImage(base, layers) {
5737
5882
  out[dIdx + 2] = 0;
5738
5883
  out[dIdx + 3] = 0;
5739
5884
  } else {
5740
- const br = blendChannel(sr, dr, blend);
5741
- const bg = blendChannel(sg, dg, blend);
5742
- const bb = blendChannel(sb, db, blend);
5743
- const cr = (sa * (1 - da) * sr + sa * da * br + (1 - sa) * da * dr) / outA;
5744
- const cg = (sa * (1 - da) * sg + sa * da * bg + (1 - sa) * da * dg) / outA;
5745
- const cb = (sa * (1 - da) * sb + sa * da * bb + (1 - sa) * da * db) / outA;
5885
+ const srP = sr * sa;
5886
+ const sgP = sg * sa;
5887
+ const sbP = sb * sa;
5888
+ const drP = dr * da;
5889
+ const dgP = dg * da;
5890
+ const dbP = db * da;
5891
+ const br = blendChannel(srP, drP, blend);
5892
+ const bg = blendChannel(sgP, dgP, blend);
5893
+ const bb = blendChannel(sbP, dbP, blend);
5894
+ const cr = ((1 - da) * srP + (1 - sa) * drP + sa * da * br) / outA;
5895
+ const cg = ((1 - da) * sgP + (1 - sa) * dgP + sa * da * bg) / outA;
5896
+ const cb = ((1 - da) * sbP + (1 - sa) * dbP + sa * da * bb) / outA;
5746
5897
  out[dIdx] = Math.max(0, Math.min(255, Math.round(cr * 255)));
5747
5898
  out[dIdx + 1] = Math.max(0, Math.min(255, Math.round(cg * 255)));
5748
5899
  out[dIdx + 2] = Math.max(0, Math.min(255, Math.round(cb * 255)));
@@ -5753,7 +5904,12 @@ function compositeImage(base, layers) {
5753
5904
  }
5754
5905
  }
5755
5906
  }
5756
- return { ...base, data: out };
5907
+ return {
5908
+ ...base,
5909
+ data: out,
5910
+ hasAlpha: true,
5911
+ channels: base.channels < 3 ? 2 : 4
5912
+ };
5757
5913
  }
5758
5914
  function grayscaleImage(img) {
5759
5915
  const out = new Uint8Array(img.data.length);
@@ -6018,10 +6174,11 @@ function blurImage(img, sigma = 1.5) {
6018
6174
  const sx = Math.max(0, Math.min(width - 1, x + k));
6019
6175
  const sIdx = (y * width + sx) * 4;
6020
6176
  const w = kernel[k + radius];
6021
- r += data[sIdx] * w;
6022
- g += data[sIdx + 1] * w;
6023
- b += data[sIdx + 2] * w;
6024
- a += data[sIdx + 3] * w;
6177
+ const sa = data[sIdx + 3] / 255;
6178
+ r += data[sIdx] * sa * w;
6179
+ g += data[sIdx + 1] * sa * w;
6180
+ b += data[sIdx + 2] * sa * w;
6181
+ a += sa * w;
6025
6182
  }
6026
6183
  const dIdx = (y * width + x) * 4;
6027
6184
  temp[dIdx] = r;
@@ -6046,10 +6203,17 @@ function blurImage(img, sigma = 1.5) {
6046
6203
  a += temp[sIdx + 3] * w;
6047
6204
  }
6048
6205
  const dIdx = (y * width + x) * 4;
6049
- out[dIdx] = Math.max(0, Math.min(255, Math.round(r)));
6050
- out[dIdx + 1] = Math.max(0, Math.min(255, Math.round(g)));
6051
- out[dIdx + 2] = Math.max(0, Math.min(255, Math.round(b)));
6052
- out[dIdx + 3] = Math.max(0, Math.min(255, Math.round(a)));
6206
+ if (a > 1e-6) {
6207
+ out[dIdx] = Math.max(0, Math.min(255, Math.round(r / a)));
6208
+ out[dIdx + 1] = Math.max(0, Math.min(255, Math.round(g / a)));
6209
+ out[dIdx + 2] = Math.max(0, Math.min(255, Math.round(b / a)));
6210
+ out[dIdx + 3] = Math.max(0, Math.min(255, Math.round(a * 255)));
6211
+ } else {
6212
+ out[dIdx] = 0;
6213
+ out[dIdx + 1] = 0;
6214
+ out[dIdx + 2] = 0;
6215
+ out[dIdx + 3] = 0;
6216
+ }
6053
6217
  }
6054
6218
  }
6055
6219
  return { ...img, data: out };