@pixerate/editor 0.246.0 → 0.249.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 (105) hide show
  1. package/README.md +1 -0
  2. package/dist/animation-editor/index.cjs +64 -61
  3. package/dist/animation-editor/index.js +8 -5
  4. package/dist/{brushstrokeRender-ZDHMXJAE.cjs → brushstrokeRender-GCKK7V2I.cjs} +14 -11
  5. package/dist/{brushstrokeRender-AKUI3SEJ.js → brushstrokeRender-T3JZST44.js} +7 -4
  6. package/dist/canvas/index.cjs +8 -8
  7. package/dist/canvas/index.js +1 -1
  8. package/dist/{chunk-UVPD55UZ.cjs → chunk-2SMMZDMG.cjs} +35 -35
  9. package/dist/chunk-2VJAVXLI.js +192 -0
  10. package/dist/{chunk-OLNIPTB3.cjs → chunk-2VX55NFM.cjs} +1 -320
  11. package/dist/chunk-3K6HWEXZ.cjs +92 -0
  12. package/dist/{chunk-UOOK7HTX.js → chunk-3PPJRMIG.js} +1 -1
  13. package/dist/chunk-4D6KP5BV.js +92 -0
  14. package/dist/chunk-5RH3VXAK.js +269 -0
  15. package/dist/{chunk-LDPLEZ5T.js → chunk-6BIDVPED.js} +1 -1
  16. package/dist/{chunk-2ONK3ERD.cjs → chunk-75K3W4D6.cjs} +20 -20
  17. package/dist/chunk-BOHDJJ2O.cjs +192 -0
  18. package/dist/{chunk-2PBZBRP5.js → chunk-D5KGAO4Z.js} +10 -92
  19. package/dist/{chunk-DQWPMGH2.js → chunk-DOIU7VJG.js} +1 -1
  20. package/dist/{chunk-HB4ICNNA.cjs → chunk-DPYAO5U6.cjs} +42 -42
  21. package/dist/chunk-EJLRBS5Q.js +301 -0
  22. package/dist/{chunk-Q2UYUWAZ.cjs → chunk-H4AOUUBE.cjs} +679 -164
  23. package/dist/{chunk-PQ3H2AAN.cjs → chunk-I7NJPHWV.cjs} +122 -204
  24. package/dist/{chunk-FK5LTDOO.cjs → chunk-IOFVM3L3.cjs} +7 -7
  25. package/dist/{chunk-42TWUPNJ.js → chunk-IRSTHLQQ.js} +1 -320
  26. package/dist/{chunk-VDAWA546.js → chunk-J7T5QZ45.js} +614 -99
  27. package/dist/{chunk-VMROIWLL.cjs → chunk-KBYB7OWB.cjs} +3 -3
  28. package/dist/{chunk-5MFDD7SP.cjs → chunk-KYX7NZ5V.cjs} +1 -1
  29. package/dist/chunk-LJRCU3BJ.cjs +301 -0
  30. package/dist/{chunk-XTWXBQD4.cjs → chunk-LP2MCSBE.cjs} +593 -236
  31. package/dist/{chunk-A23PSOBB.js → chunk-O75V4ZS3.js} +1 -1
  32. package/dist/chunk-OTTT5N3K.js +322 -0
  33. package/dist/{chunk-N6WUB3Y5.js → chunk-PZP2SZIZ.js} +2 -2
  34. package/dist/{chunk-4PMCMWQS.js → chunk-UBRJOIR5.js} +367 -10
  35. package/dist/chunk-W5M3J7PV.cjs +322 -0
  36. package/dist/{chunk-4P6H35HU.js → chunk-WA44NKPF.js} +2 -2
  37. package/dist/{chunk-CEPKXLBS.cjs → chunk-WLJZZHUZ.cjs} +23 -23
  38. package/dist/{chunk-P3NIPIKS.js → chunk-WQCNC4DK.js} +1 -1
  39. package/dist/chunk-ZEYMKDYS.cjs +269 -0
  40. package/dist/image-editor/effect-tools.d.cts +37 -4
  41. package/dist/image-editor/effect-tools.d.ts +37 -4
  42. package/dist/image-editor/index.cjs +1340 -1828
  43. package/dist/image-editor/index.d.cts +1 -1
  44. package/dist/image-editor/index.d.ts +1 -1
  45. package/dist/image-editor/index.js +298 -786
  46. package/dist/paint/index.cjs +8 -5
  47. package/dist/paint/index.js +13 -10
  48. package/dist/paint-editor/controller.d.cts +71 -2
  49. package/dist/paint-editor/controller.d.ts +71 -2
  50. package/dist/paint-editor/index.cjs +901 -589
  51. package/dist/paint-editor/index.d.cts +3 -0
  52. package/dist/paint-editor/index.d.ts +3 -0
  53. package/dist/paint-editor/index.js +365 -53
  54. package/dist/paint-editor/procedural.d.cts +82 -5
  55. package/dist/paint-editor/procedural.d.ts +82 -5
  56. package/dist/paint-editor/sticker-art.d.cts +55 -0
  57. package/dist/paint-editor/sticker-art.d.ts +55 -0
  58. package/dist/paint-editor/stickers.d.cts +30 -17
  59. package/dist/paint-editor/stickers.d.ts +30 -17
  60. package/dist/paint-editor/stroke.d.cts +4 -0
  61. package/dist/paint-editor/stroke.d.ts +4 -0
  62. package/dist/paint-editor/tools.d.cts +1 -1
  63. package/dist/paint-editor/tools.d.ts +1 -1
  64. package/dist/paint-editor/ui.d.cts +25 -4
  65. package/dist/paint-editor/ui.d.ts +25 -4
  66. package/dist/{image-editor/layers/effects-ui.d.cts → raster/effects/ui.d.cts} +32 -5
  67. package/dist/{image-editor/layers/effects-ui.d.ts → raster/effects/ui.d.ts} +32 -5
  68. package/dist/raster/index.cjs +17 -3
  69. package/dist/raster/index.d.cts +1 -0
  70. package/dist/raster/index.d.ts +1 -0
  71. package/dist/raster/index.js +23 -9
  72. package/dist/stickers/browser.d.cts +48 -0
  73. package/dist/stickers/browser.d.ts +48 -0
  74. package/dist/stickers/combine.d.cts +10 -0
  75. package/dist/stickers/combine.d.ts +10 -0
  76. package/dist/stickers/conformance.d.cts +18 -0
  77. package/dist/stickers/conformance.d.ts +18 -0
  78. package/dist/stickers/editor.d.cts +14 -0
  79. package/dist/stickers/editor.d.ts +14 -0
  80. package/dist/stickers/errors.d.cts +6 -0
  81. package/dist/stickers/errors.d.ts +6 -0
  82. package/dist/stickers/fake.d.cts +16 -0
  83. package/dist/stickers/fake.d.ts +16 -0
  84. package/dist/stickers/helpers.d.cts +51 -0
  85. package/dist/stickers/helpers.d.ts +51 -0
  86. package/dist/stickers/index.cjs +331 -0
  87. package/dist/stickers/index.d.cts +16 -0
  88. package/dist/stickers/index.d.ts +16 -0
  89. package/dist/stickers/index.js +331 -0
  90. package/dist/stickers/stamps.d.cts +13 -0
  91. package/dist/stickers/stamps.d.ts +13 -0
  92. package/dist/stickers/tools.d.cts +25 -0
  93. package/dist/stickers/tools.d.ts +25 -0
  94. package/dist/stickers/types.d.cts +123 -0
  95. package/dist/stickers/types.d.ts +123 -0
  96. package/dist/vector/index.cjs +978 -975
  97. package/dist/vector/index.js +9 -6
  98. package/package.json +11 -1
  99. package/skills/README.md +1 -0
  100. package/skills/pixerate-paint-editor/SKILL.md +26 -32
  101. package/skills/pixerate-paint-editor/references/gradient-paint.md +23 -0
  102. package/skills/pixerate-paint-editor/references/layer-effects.md +28 -0
  103. package/skills/pixerate-paint-editor/references/light-paint.md +10 -2
  104. package/skills/pixerate-paint-editor/references/particle-brushes.md +66 -0
  105. package/skills/pixerate-stickers/SKILL.md +45 -0
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2;
2
2
 
3
- var _chunkQ2UYUWAZcjs = require('./chunk-Q2UYUWAZ.cjs');
3
+ var _chunkH4AOUUBEcjs = require('./chunk-H4AOUUBE.cjs');
4
4
 
5
5
 
6
6
  var _chunkCVFAAZXEcjs = require('./chunk-CVFAAZXE.cjs');
@@ -47,7 +47,7 @@ var _chunkNM3G4VQTcjs = require('./chunk-NM3G4VQT.cjs');
47
47
 
48
48
 
49
49
 
50
- var _chunkPQ3H2AANcjs = require('./chunk-PQ3H2AAN.cjs');
50
+ var _chunkI7NJPHWVcjs = require('./chunk-I7NJPHWV.cjs');
51
51
 
52
52
 
53
53
 
@@ -2527,7 +2527,7 @@ function vectorExtrudeFaces(path, params) {
2527
2527
  // src/vector/brushstroke.ts
2528
2528
  var VECTOR_BRUSHSTROKE_SCALE = 2;
2529
2529
  function vectorBrushstrokeBrushes() {
2530
- return _chunkQ2UYUWAZcjs.BUILTIN_BRUSHES.filter((b) => _chunkPQ3H2AANcjs.isBrushstrokeBrush.call(void 0, b));
2530
+ return _chunkH4AOUUBEcjs.BUILTIN_BRUSHES.filter((b) => _chunkI7NJPHWVcjs.isBrushstrokeBrush.call(void 0, b));
2531
2531
  }
2532
2532
  function vectorBrushstrokeBrush(id) {
2533
2533
  return _nullishCoalesce(vectorBrushstrokeBrushes().find((b) => b.id === id), () => ( null));
@@ -2558,7 +2558,7 @@ function sanitizeVectorBrushstrokePaper(value) {
2558
2558
  if (!value || typeof value !== "object") return null;
2559
2559
  const r = value;
2560
2560
  const out = {};
2561
- if (typeof r.pattern === "string" && _chunkPQ3H2AANcjs.GRAIN_PATTERNS.includes(r.pattern)) out.pattern = r.pattern;
2561
+ if (typeof r.pattern === "string" && _chunkI7NJPHWVcjs.GRAIN_PATTERNS.includes(r.pattern)) out.pattern = r.pattern;
2562
2562
  const seed = sanitizeSeed(r.seed);
2563
2563
  if (seed !== void 0) out.seed = seed;
2564
2564
  if (finite2(r.scale) && r.scale > 0) out.scale = Math.min(8, Math.max(0.25, r.scale));
@@ -2573,7 +2573,7 @@ function vectorBrushstrokeCharacterError(brush) {
2573
2573
  const r = paper;
2574
2574
  const extra = Object.keys(r).filter((k) => !["pattern", "seed", "scale", "depth"].includes(k));
2575
2575
  if (extra.length) return `paper has unknown field ${extra.map((k) => `"${k}"`).join(", ")}: use pattern, seed, scale, depth.`;
2576
- if (r.pattern !== void 0 && !_chunkPQ3H2AANcjs.GRAIN_PATTERNS.includes(r.pattern)) return `Unknown paper pattern "${String(r.pattern)}": use one of ${_chunkPQ3H2AANcjs.GRAIN_PATTERNS.join(", ")}.`;
2576
+ if (r.pattern !== void 0 && !_chunkI7NJPHWVcjs.GRAIN_PATTERNS.includes(r.pattern)) return `Unknown paper pattern "${String(r.pattern)}": use one of ${_chunkI7NJPHWVcjs.GRAIN_PATTERNS.join(", ")}.`;
2577
2577
  if (r.seed !== void 0 && !(Number.isInteger(r.seed) && r.seed >= 0 && r.seed <= VECTOR_BRUSHSTROKE_MAX_SEED)) return `paper.seed must be an integer from 0 to ${VECTOR_BRUSHSTROKE_MAX_SEED}.`;
2578
2578
  if (r.scale !== void 0 && !(finite2(r.scale) && r.scale >= 0.25 && r.scale <= 8)) return "paper.scale must be from 0.25 to 8 (1 is the pattern's natural size).";
2579
2579
  if (r.depth !== void 0 && !(finite2(r.depth) && r.depth >= 0 && r.depth <= 1)) return "paper.depth must be from 0 to 1.";
@@ -2589,7 +2589,7 @@ function vectorBrushstrokeReach(layer) {
2589
2589
  if (!isVectorBrushstrokeLayer(layer)) return 0;
2590
2590
  return (_nullishCoalesce(layer.brush.size, () => ( vectorBrushstrokeBrush(layer.brush.brushId).tip.size))) / 2;
2591
2591
  }
2592
- var cache = new (0, _chunkPQ3H2AANcjs.BrushstrokeCache)(256);
2592
+ var cache = new (0, _chunkI7NJPHWVcjs.BrushstrokeCache)(256);
2593
2593
  var urls = /* @__PURE__ */ new WeakMap();
2594
2594
  var layerCache = /* @__PURE__ */ new WeakMap();
2595
2595
  function vectorBrushstrokeImages(node, layer) {
@@ -2614,7 +2614,7 @@ function vectorBrushstrokeImages(node, layer) {
2614
2614
  const stroke = cache.render({ points: ring.map(([x, y]) => ({ x, y })), ...layer.brush.pressure ? { pressure: layer.brush.pressure } : {} }, brush, { scale: VECTOR_BRUSHSTROKE_SCALE, color: color2, maxPixels: 2048 * 2048, ...character });
2615
2615
  if (!stroke.bounds) continue;
2616
2616
  let href = urls.get(stroke);
2617
- if (!href) urls.set(stroke, href = _chunkPQ3H2AANcjs.brushstrokeDataUrl.call(void 0, stroke));
2617
+ if (!href) urls.set(stroke, href = _chunkI7NJPHWVcjs.brushstrokeDataUrl.call(void 0, stroke));
2618
2618
  out.push({ href, ...stroke.bounds });
2619
2619
  }
2620
2620
  }
@@ -6,10 +6,6 @@ import {
6
6
  tileKey,
7
7
  tilesInRect
8
8
  } from "./chunk-HVVR5PZW.js";
9
- import {
10
- deflate,
11
- inflate
12
- } from "./chunk-QGHEDC7B.js";
13
9
 
14
10
  // src/raster/pigment.ts
15
11
  var PIGMENT_BANDS = 36;
@@ -990,314 +986,6 @@ function keepDeepSamples(before, after) {
990
986
  return tiles ? new TiledSurface(ch, tiles, after.defaultValue) : after;
991
987
  }
992
988
 
993
- // src/raster/png.ts
994
- var SIGNATURE = [137, 80, 78, 71, 13, 10, 26, 10];
995
- var crcTable = null;
996
- function crc32(bytes, start, end) {
997
- if (!crcTable) {
998
- crcTable = new Uint32Array(256);
999
- for (let n = 0; n < 256; n++) {
1000
- let c2 = n;
1001
- for (let k = 0; k < 8; k++) c2 = c2 & 1 ? 3988292384 ^ c2 >>> 1 : c2 >>> 1;
1002
- crcTable[n] = c2 >>> 0;
1003
- }
1004
- }
1005
- let c = 4294967295;
1006
- for (let i = start; i < end; i++) c = crcTable[(c ^ bytes[i]) & 255] ^ c >>> 8;
1007
- return (c ^ 4294967295) >>> 0;
1008
- }
1009
- function paeth(a, b, c) {
1010
- const p = a + b - c;
1011
- const pa = Math.abs(p - a);
1012
- const pb = Math.abs(p - b);
1013
- const pc = Math.abs(p - c);
1014
- return pa <= pb && pa <= pc ? a : pb <= pc ? b : c;
1015
- }
1016
- function encodePng(width, height, data, channels = 4) {
1017
- const stride = width * channels;
1018
- const raw = new Uint8Array((stride + 1) * height);
1019
- const bpp = channels;
1020
- const cand = [new Uint8Array(stride), new Uint8Array(stride), new Uint8Array(stride), new Uint8Array(stride), new Uint8Array(stride)];
1021
- for (let y = 0; y < height; y++) {
1022
- const row = y * stride;
1023
- const prevRow = (y - 1) * stride;
1024
- let best = 0;
1025
- let bestScore = Infinity;
1026
- for (let f = 0; f < 5; f++) {
1027
- const out2 = cand[f];
1028
- let score = 0;
1029
- for (let x = 0; x < stride; x++) {
1030
- const v = data[row + x];
1031
- const a = x >= bpp ? data[row + x - bpp] : 0;
1032
- const b = y > 0 ? data[prevRow + x] : 0;
1033
- const c = x >= bpp && y > 0 ? data[prevRow + x - bpp] : 0;
1034
- let r;
1035
- switch (f) {
1036
- case 0:
1037
- r = v;
1038
- break;
1039
- case 1:
1040
- r = v - a;
1041
- break;
1042
- case 2:
1043
- r = v - b;
1044
- break;
1045
- case 3:
1046
- r = v - (a + b >> 1);
1047
- break;
1048
- default:
1049
- r = v - paeth(a, b, c);
1050
- }
1051
- r &= 255;
1052
- out2[x] = r;
1053
- score += r < 128 ? r : 256 - r;
1054
- if (score >= bestScore) break;
1055
- }
1056
- if (score < bestScore) {
1057
- bestScore = score;
1058
- best = f;
1059
- }
1060
- }
1061
- const o = y * (stride + 1);
1062
- raw[o] = best;
1063
- raw.set(cand[best], o + 1);
1064
- }
1065
- const idat = deflate(raw);
1066
- const chunks = [];
1067
- const ihdr = new Uint8Array(13);
1068
- writeU32(ihdr, 0, width);
1069
- writeU32(ihdr, 4, height);
1070
- ihdr[8] = 8;
1071
- ihdr[9] = channels === 1 ? 0 : 6;
1072
- chunks.push(["IHDR", ihdr], ["IDAT", idat], ["IEND", new Uint8Array(0)]);
1073
- let size = 8;
1074
- for (const [, d] of chunks) size += 12 + d.length;
1075
- const out = new Uint8Array(size);
1076
- out.set(SIGNATURE, 0);
1077
- let p = 8;
1078
- for (const [type, d] of chunks) {
1079
- writeU32(out, p, d.length);
1080
- for (let i = 0; i < 4; i++) out[p + 4 + i] = type.charCodeAt(i);
1081
- out.set(d, p + 8);
1082
- writeU32(out, p + 8 + d.length, crc32(out, p + 4, p + 8 + d.length));
1083
- p += 12 + d.length;
1084
- }
1085
- return out;
1086
- }
1087
- function writeU32(b, o, v) {
1088
- b[o] = v >>> 24;
1089
- b[o + 1] = v >>> 16 & 255;
1090
- b[o + 2] = v >>> 8 & 255;
1091
- b[o + 3] = v & 255;
1092
- }
1093
- function readU32(b, o) {
1094
- return (b[o] << 24 | b[o + 1] << 16 | b[o + 2] << 8 | b[o + 3]) >>> 0;
1095
- }
1096
- function isPng(bytes) {
1097
- return bytes.length > 8 && SIGNATURE.every((v, i) => bytes[i] === v);
1098
- }
1099
- function decodePng(bytes, options = {}) {
1100
- if (!isPng(bytes)) throw new Error("Not a PNG image.");
1101
- let p = 8;
1102
- let width = 0;
1103
- let height = 0;
1104
- let depth = 0;
1105
- let type = 0;
1106
- let interlace = 0;
1107
- let palette = null;
1108
- let trns = null;
1109
- const idat = [];
1110
- while (p + 8 <= bytes.length) {
1111
- const len = readU32(bytes, p);
1112
- const t = String.fromCharCode(bytes[p + 4], bytes[p + 5], bytes[p + 6], bytes[p + 7]);
1113
- const body = bytes.subarray(p + 8, p + 8 + len);
1114
- if (p + 12 + len > bytes.length) throw new Error("Truncated PNG.");
1115
- if (t === "IHDR") {
1116
- width = readU32(body, 0);
1117
- height = readU32(body, 4);
1118
- depth = body[8];
1119
- type = body[9];
1120
- interlace = body[12];
1121
- } else if (t === "PLTE") palette = body;
1122
- else if (t === "tRNS") trns = body;
1123
- else if (t === "IDAT") idat.push(body);
1124
- else if (t === "IEND") break;
1125
- p += 12 + len;
1126
- }
1127
- if (!width || !height) throw new Error("PNG has no image header.");
1128
- if (interlace) throw new Error("Interlaced PNGs are not supported here; decode them with a canvas.");
1129
- const maxPixels = options.maxPixels ?? 1 << 28;
1130
- if (width * height > maxPixels) throw new Error(`PNG is too large (${width}\xD7${height}).`);
1131
- const samples = type === 0 ? 1 : type === 2 ? 3 : type === 3 ? 1 : type === 4 ? 2 : type === 6 ? 4 : 0;
1132
- if (!samples || ![1, 2, 4, 8, 16].includes(depth)) throw new Error(`Unsupported PNG format (type ${type}, depth ${depth}).`);
1133
- let total = 0;
1134
- for (const c of idat) total += c.length;
1135
- const z = new Uint8Array(total);
1136
- let o = 0;
1137
- for (const c of idat) {
1138
- z.set(c, o);
1139
- o += c.length;
1140
- }
1141
- const bitsPerPixel = samples * depth;
1142
- const stride = Math.ceil(width * bitsPerPixel / 8);
1143
- const raw = inflate(z, { maxOutput: (stride + 1) * height, sizeHint: (stride + 1) * height });
1144
- if (raw.length < (stride + 1) * height) throw new Error("PNG image data is truncated.");
1145
- const bpp = Math.max(1, bitsPerPixel >> 3);
1146
- const lines = new Uint8Array(stride * height);
1147
- for (let y = 0; y < height; y++) {
1148
- const f = raw[y * (stride + 1)];
1149
- const src = y * (stride + 1) + 1;
1150
- const dst = y * stride;
1151
- const up = dst - stride;
1152
- for (let x = 0; x < stride; x++) {
1153
- const v = raw[src + x];
1154
- const a = x >= bpp ? lines[dst + x - bpp] : 0;
1155
- const b = y > 0 ? lines[up + x] : 0;
1156
- const c = x >= bpp && y > 0 ? lines[up + x - bpp] : 0;
1157
- let r;
1158
- switch (f) {
1159
- case 0:
1160
- r = v;
1161
- break;
1162
- case 1:
1163
- r = v + a;
1164
- break;
1165
- case 2:
1166
- r = v + b;
1167
- break;
1168
- case 3:
1169
- r = v + (a + b >> 1);
1170
- break;
1171
- case 4:
1172
- r = v + paeth(a, b, c);
1173
- break;
1174
- default:
1175
- throw new Error(`Invalid PNG filter ${f}.`);
1176
- }
1177
- lines[dst + x] = r & 255;
1178
- }
1179
- }
1180
- const sample = (y, i) => {
1181
- const row = y * stride;
1182
- if (depth === 8) return lines[row + i];
1183
- if (depth === 16) return lines[row + i * 2];
1184
- const perByte = 8 / depth;
1185
- const byte = lines[row + Math.floor(i / perByte)];
1186
- const shift = 8 - depth * (i % perByte + 1);
1187
- const v = byte >> shift & (1 << depth) - 1;
1188
- return type === 3 ? v : Math.round(v * 255 / ((1 << depth) - 1));
1189
- };
1190
- const gray = options.keepGray && type === 0 && !trns;
1191
- const channels = gray ? 1 : 4;
1192
- const out = new Uint8ClampedArray(width * height * channels);
1193
- const trnsGray = trns && type === 0 ? depth === 16 ? trns[0] : sample16(trns, 0, depth) : -1;
1194
- const trnsRgb = trns && type === 2 ? [0, 1, 2].map((k) => depth === 16 ? trns[k * 2] : sample16(trns, k, depth)) : null;
1195
- for (let y = 0; y < height; y++) {
1196
- for (let x = 0; x < width; x++) {
1197
- const d = (y * width + x) * channels;
1198
- if (type === 0) {
1199
- const v = sample(y, x);
1200
- if (gray) out[d] = v;
1201
- else {
1202
- out[d] = out[d + 1] = out[d + 2] = v;
1203
- out[d + 3] = v === trnsGray && trns ? 0 : 255;
1204
- }
1205
- } else if (type === 2) {
1206
- const r = sample(y, x * 3);
1207
- const g = sample(y, x * 3 + 1);
1208
- const b = sample(y, x * 3 + 2);
1209
- out[d] = r;
1210
- out[d + 1] = g;
1211
- out[d + 2] = b;
1212
- out[d + 3] = trnsRgb && r === trnsRgb[0] && g === trnsRgb[1] && b === trnsRgb[2] ? 0 : 255;
1213
- } else if (type === 3) {
1214
- const i = sample(y, x);
1215
- if (!palette || i * 3 + 2 >= palette.length) throw new Error("PNG palette index out of range.");
1216
- out[d] = palette[i * 3];
1217
- out[d + 1] = palette[i * 3 + 1];
1218
- out[d + 2] = palette[i * 3 + 2];
1219
- out[d + 3] = trns && i < trns.length ? trns[i] : 255;
1220
- } else if (type === 4) {
1221
- const v = sample(y, x * 2);
1222
- out[d] = out[d + 1] = out[d + 2] = v;
1223
- out[d + 3] = sample(y, x * 2 + 1);
1224
- } else {
1225
- out[d] = sample(y, x * 4);
1226
- out[d + 1] = sample(y, x * 4 + 1);
1227
- out[d + 2] = sample(y, x * 4 + 2);
1228
- out[d + 3] = sample(y, x * 4 + 3);
1229
- }
1230
- }
1231
- }
1232
- return { width, height, channels, data: out };
1233
- }
1234
- function sample16(trns, k, depth) {
1235
- const v = trns[k * 2] << 8 | trns[k * 2 + 1];
1236
- if (depth === 8) return v & 255;
1237
- return Math.round((v & (1 << depth) - 1) * 255 / ((1 << depth) - 1));
1238
- }
1239
- var B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1240
- var B64_INV = null;
1241
- function bytesToBase64(bytes) {
1242
- const parts = [];
1243
- const CHUNK = 3 * 4096;
1244
- for (let start = 0; start < bytes.length; start += CHUNK) {
1245
- const end = Math.min(bytes.length, start + CHUNK);
1246
- let s = "";
1247
- let i = start;
1248
- for (; i + 2 < end; i += 3) {
1249
- const n = bytes[i] << 16 | bytes[i + 1] << 8 | bytes[i + 2];
1250
- s += B64[n >> 18] + B64[n >> 12 & 63] + B64[n >> 6 & 63] + B64[n & 63];
1251
- }
1252
- if (i < end) {
1253
- const n = bytes[i] << 16 | (i + 1 < end ? bytes[i + 1] << 8 : 0);
1254
- s += B64[n >> 18] + B64[n >> 12 & 63] + (i + 1 < end ? B64[n >> 6 & 63] : "=") + "=";
1255
- }
1256
- parts.push(s);
1257
- }
1258
- return parts.join("");
1259
- }
1260
- function base64ToBytes(text) {
1261
- if (!B64_INV) {
1262
- B64_INV = new Int16Array(128).fill(-1);
1263
- for (let i = 0; i < 64; i++) B64_INV[B64.charCodeAt(i)] = i;
1264
- B64_INV["-".charCodeAt(0)] = 62;
1265
- B64_INV["_".charCodeAt(0)] = 63;
1266
- }
1267
- const inv = B64_INV;
1268
- const clean = text.replace(/[\s=]/g, "");
1269
- const out = new Uint8Array(Math.floor(clean.length * 3 / 4));
1270
- let bits = 0;
1271
- let acc = 0;
1272
- let o = 0;
1273
- for (let i = 0; i < clean.length; i++) {
1274
- const c = clean.charCodeAt(i);
1275
- const v = c < 128 ? inv[c] : -1;
1276
- if (v < 0) throw new Error("Invalid base64 data.");
1277
- acc = acc << 6 | v;
1278
- bits += 6;
1279
- if (bits >= 8) {
1280
- bits -= 8;
1281
- out[o++] = acc >> bits & 255;
1282
- }
1283
- }
1284
- return out.subarray(0, o);
1285
- }
1286
- function parseDataUrl(url) {
1287
- const m = /^data:([^;,]*)((?:;[^;,]*)*?),/i.exec(url);
1288
- if (!m) return null;
1289
- const body = url.slice(m[0].length);
1290
- const isBase64 = /;base64/i.test(m[2]);
1291
- if (isBase64) return { mime: m[1] || "text/plain", bytes: base64ToBytes(body) };
1292
- const text = decodeURIComponent(body);
1293
- const bytes = new Uint8Array(text.length);
1294
- for (let i = 0; i < text.length; i++) bytes[i] = text.charCodeAt(i) & 255;
1295
- return { mime: m[1] || "text/plain", bytes };
1296
- }
1297
- function pngDataUrl(width, height, data, channels = 4) {
1298
- return `data:image/png;base64,${bytesToBase64(encodePng(width, height, data, channels))}`;
1299
- }
1300
-
1301
989
  export {
1302
990
  PIGMENT_BANDS,
1303
991
  PIGMENT_LAMBDA_MIN,
@@ -1350,12 +1038,5 @@ export {
1350
1038
  surfaceFromDeepPixels,
1351
1039
  convertSurfaceDepth,
1352
1040
  deepBytes,
1353
- keepDeepSamples,
1354
- encodePng,
1355
- isPng,
1356
- decodePng,
1357
- bytesToBase64,
1358
- base64ToBytes,
1359
- parseDataUrl,
1360
- pngDataUrl
1041
+ keepDeepSamples
1361
1042
  };