@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,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } 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; var _class3;
2
2
 
3
3
 
4
- var _chunkOLNIPTB3cjs = require('./chunk-OLNIPTB3.cjs');
4
+ var _chunk2VX55NFMcjs = require('./chunk-2VX55NFM.cjs');
5
5
 
6
6
 
7
7
 
@@ -64,8 +64,8 @@ function createPigmentTools() {
64
64
  const rgbs = items.map((item, i) => parseHex(item.color, i));
65
65
  const total = items.reduce((sum, item) => sum + item.weight, 0);
66
66
  if (!(total > 0)) throw new Error("Every weight is 0; give at least one colour a weight above 0.");
67
- const pigments = rgbs.map((rgb2, i) => _chunkOLNIPTB3cjs.createPigment.call(void 0, rgb2, { strength: items[i].strength }));
68
- const mixed = _chunkOLNIPTB3cjs.mixPigments.call(void 0, pigments, items.map((item) => item.weight));
67
+ const pigments = rgbs.map((rgb2, i) => _chunk2VX55NFMcjs.createPigment.call(void 0, rgb2, { strength: items[i].strength }));
68
+ const mixed = _chunk2VX55NFMcjs.mixPigments.call(void 0, pigments, items.map((item) => item.weight));
69
69
  const lerp = [0, 1, 2].map((c) => rgbs.reduce((sum, rgb2, i) => sum + rgb2[c] * items[i].weight, 0) / total);
70
70
  const rgb = args.model === "rgb";
71
71
  return {
@@ -74,7 +74,7 @@ function profileAlongPolyline(points, values, count = 32) {
74
74
  var round3 = (v) => Math.round(v * 1e3) / 1e3;
75
75
  var loading = null;
76
76
  function loadCanvasBrushstrokeRenderer() {
77
- loading ??= Promise.resolve().then(() => _interopRequireWildcard(require("./brushstrokeRender-ZDHMXJAE.cjs"))).catch((error) => {
77
+ loading ??= Promise.resolve().then(() => _interopRequireWildcard(require("./brushstrokeRender-GCKK7V2I.cjs"))).catch((error) => {
78
78
  loading = null;
79
79
  throw error;
80
80
  });
@@ -0,0 +1,301 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await 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;
2
+
3
+
4
+
5
+
6
+
7
+
8
+ var _chunkZEYMKDYScjs = require('./chunk-ZEYMKDYS.cjs');
9
+
10
+
11
+ var _chunkW5M3J7PVcjs = require('./chunk-W5M3J7PV.cjs');
12
+
13
+ // src/stickers/editor.ts
14
+ var BOX = 100;
15
+ var GRID = 128;
16
+ var SHAPE_SEED = 7;
17
+ var LICENCE = { spdx: "MIT", name: "MIT", commercial: true };
18
+ var META = {
19
+ dot: { name: "Dot", category: "shapes", tags: ["circle", "round", "spot"], colour: "#2563eb", description: "A round dot." },
20
+ star: { name: "Star", category: "shapes", tags: ["five-pointed", "favourite", "rating"], colour: "#f59e0b", description: "A five-pointed star, one point up." },
21
+ heart: { name: "Heart", category: "shapes", tags: ["love", "like"], colour: "#e11d48", description: "A heart." },
22
+ leaf: { name: "Leaf", category: "nature", tags: ["plant", "green"], colour: "#16a34a", description: "A pointed leaf with a midrib." },
23
+ flower: { name: "Flower", category: "nature", tags: ["petals", "blossom"], colour: "#db2777", description: "A five-petal flower." },
24
+ confetti: { name: "Confetti", category: "party", tags: ["celebration", "rectangle"], colour: "#7c3aed", description: "A small strip of confetti." },
25
+ splat: { name: "Splat", category: "party", tags: ["paint", "splash", "blob"], colour: "#0891b2", description: "A paint splat with drops." },
26
+ sparkle: { name: "Sparkle", category: "party", tags: ["twinkle", "shine", "glint"], colour: "#eab308", description: "A four-pointed twinkle." },
27
+ ring: { name: "Ring", category: "shapes", tags: ["circle", "outline", "hoop"], colour: "#0f766e", description: "A ring." }
28
+ };
29
+ var HEX = /^#[0-9a-fA-F]{6}$/;
30
+ function stampOutline(kind) {
31
+ const n = GRID;
32
+ const f = new Float32Array((n + 1) * (n + 1));
33
+ for (let j = 0; j <= n; j++) for (let i = 0; i <= n; i++) f[j * (n + 1) + i] = _chunkZEYMKDYScjs.stampCoverage.call(void 0, kind, i / n * 2 - 1, j / n * 2 - 1, SHAPE_SEED) - 0.5;
34
+ const at = (i, j) => f[j * (n + 1) + i];
35
+ const points = /* @__PURE__ */ new Map();
36
+ const point = (key, i0, j0, i1, j1) => {
37
+ if (!points.has(key)) {
38
+ const a = at(i0, j0);
39
+ const b = at(i1, j1);
40
+ const t = a / (a - b);
41
+ points.set(key, [(i0 + (i1 - i0) * t) / n * BOX, (j0 + (j1 - j0) * t) / n * BOX]);
42
+ }
43
+ return key;
44
+ };
45
+ const next = /* @__PURE__ */ new Map();
46
+ for (let j = 0; j < n; j++) {
47
+ for (let i = 0; i < n; i++) {
48
+ const tl = at(i, j) > 0 ? 1 : 0;
49
+ const tr = at(i + 1, j) > 0 ? 1 : 0;
50
+ const br = at(i + 1, j + 1) > 0 ? 1 : 0;
51
+ const bl = at(i, j + 1) > 0 ? 1 : 0;
52
+ const code = tl << 3 | tr << 2 | br << 1 | bl;
53
+ if (code === 0 || code === 15) continue;
54
+ const top = () => point(`h${i},${j}`, i, j, i + 1, j);
55
+ const right = () => point(`v${i + 1},${j}`, i + 1, j, i + 1, j + 1);
56
+ const bottom = () => point(`h${i},${j + 1}`, i, j + 1, i + 1, j + 1);
57
+ const left = () => point(`v${i},${j}`, i, j, i, j + 1);
58
+ const seg = (a, b) => next.set(a, b);
59
+ const centre = at(i, j) + at(i + 1, j) + at(i + 1, j + 1) + at(i, j + 1) > 0;
60
+ switch (code) {
61
+ case 1:
62
+ seg(left(), bottom());
63
+ break;
64
+ case 2:
65
+ seg(bottom(), right());
66
+ break;
67
+ case 3:
68
+ seg(left(), right());
69
+ break;
70
+ case 4:
71
+ seg(right(), top());
72
+ break;
73
+ case 5:
74
+ if (centre) {
75
+ seg(left(), top());
76
+ seg(right(), bottom());
77
+ } else {
78
+ seg(left(), bottom());
79
+ seg(right(), top());
80
+ }
81
+ break;
82
+ case 6:
83
+ seg(bottom(), top());
84
+ break;
85
+ case 7:
86
+ seg(left(), top());
87
+ break;
88
+ case 8:
89
+ seg(top(), left());
90
+ break;
91
+ case 9:
92
+ seg(top(), bottom());
93
+ break;
94
+ case 10:
95
+ if (centre) {
96
+ seg(top(), right());
97
+ seg(bottom(), left());
98
+ } else {
99
+ seg(top(), left());
100
+ seg(bottom(), right());
101
+ }
102
+ break;
103
+ case 11:
104
+ seg(top(), right());
105
+ break;
106
+ case 12:
107
+ seg(right(), left());
108
+ break;
109
+ case 13:
110
+ seg(right(), bottom());
111
+ break;
112
+ case 14:
113
+ seg(bottom(), left());
114
+ break;
115
+ }
116
+ }
117
+ }
118
+ const loops = [];
119
+ const seen = /* @__PURE__ */ new Set();
120
+ for (const start of next.keys()) {
121
+ if (seen.has(start)) continue;
122
+ const loop = [];
123
+ let k = start;
124
+ while (k !== void 0 && !seen.has(k)) {
125
+ seen.add(k);
126
+ loop.push(points.get(k));
127
+ k = next.get(k);
128
+ }
129
+ if (loop.length >= 3) loops.push(simplify(loop, 0.12));
130
+ }
131
+ const fmt = (v) => String(Math.round(v * 100) / 100);
132
+ return loops.map((l) => "M" + l.map(([x, y]) => `${fmt(x)} ${fmt(y)}`).join("L") + "Z").join("");
133
+ }
134
+ function simplify(loop, eps) {
135
+ if (loop.length < 8) return loop;
136
+ const keep = new Uint8Array(loop.length);
137
+ const rdp = (a, b) => {
138
+ const [ax, ay] = loop[a];
139
+ const [bx, by] = loop[b];
140
+ const len = Math.hypot(bx - ax, by - ay) || 1e-9;
141
+ let worst = -1;
142
+ let far = 0;
143
+ for (let i = a + 1; i < b; i++) {
144
+ const d = Math.abs((bx - ax) * (ay - loop[i][1]) - (ax - loop[i][0]) * (by - ay)) / len;
145
+ if (d > far) {
146
+ far = d;
147
+ worst = i;
148
+ }
149
+ }
150
+ if (worst !== -1 && far > eps) {
151
+ keep[worst] = 1;
152
+ rdp(a, worst);
153
+ rdp(worst, b);
154
+ }
155
+ };
156
+ const mid = Math.floor(loop.length / 2);
157
+ keep[0] = keep[mid] = 1;
158
+ rdp(0, mid);
159
+ rdp(mid, loop.length - 1);
160
+ keep[loop.length - 1] = 1;
161
+ return loop.filter((_, i) => keep[i]);
162
+ }
163
+ function stampPixels(kind, size, colour) {
164
+ const out = new Uint8ClampedArray(size * size * 4);
165
+ const n = parseInt(colour.slice(1), 16);
166
+ const ss = size <= 128 ? 3 : 2;
167
+ for (let y = 0; y < size; y++) {
168
+ for (let x = 0; x < size; x++) {
169
+ let c = 0;
170
+ for (let sy = 0; sy < ss; sy++) for (let sx = 0; sx < ss; sx++) c += _chunkZEYMKDYScjs.stampCoverage.call(void 0, kind, (x + (sx + 0.5) / ss) / size * 2 - 1, (y + (sy + 0.5) / ss) / size * 2 - 1, SHAPE_SEED);
171
+ const a = Math.round(c / (ss * ss) * 255);
172
+ if (!a) continue;
173
+ const i = (y * size + x) * 4;
174
+ out[i] = n >> 16 & 255;
175
+ out[i + 1] = n >> 8 & 255;
176
+ out[i + 2] = n & 255;
177
+ out[i + 3] = a;
178
+ }
179
+ }
180
+ return out;
181
+ }
182
+ function editorStickers() {
183
+ const outlines = /* @__PURE__ */ new Map();
184
+ const thumbs = /* @__PURE__ */ new Map();
185
+ const outline = (k) => _nullishCoalesce(outlines.get(k), () => ( (outlines.set(k, stampOutline(k)), outlines.get(k))));
186
+ const summary = (k) => {
187
+ const m = META[k];
188
+ if (!thumbs.has(k)) thumbs.set(k, _chunkW5M3J7PVcjs.pngDataUrl.call(void 0, 48, 48, stampPixels(k, 48, m.colour)));
189
+ return { id: k, name: m.name, category: m.category, tags: m.tags, description: m.description, width: BOX, height: BOX, thumbnail: thumbs.get(k), formats: ["svg", "png"], licence: { ...LICENCE }, tintable: true };
190
+ };
191
+ const kind = (id) => {
192
+ if (!_chunkZEYMKDYScjs.STAMP_KINDS.includes(id)) throw new (0, _chunkZEYMKDYScjs.StickerError)("unknown_sticker", `The editor has no sticker "${id}"; its stickers are ${_chunkZEYMKDYScjs.STAMP_KINDS.join(", ")}.`);
193
+ return id;
194
+ };
195
+ return {
196
+ id: _chunkZEYMKDYScjs.EDITOR_STICKERS_ID,
197
+ name: "Editor stickers",
198
+ version: "1",
199
+ capabilities: { supportsSearch: true, supportsSvg: true, supportsRaster: true, maxSize: 1024 },
200
+ list: (options) => _chunkZEYMKDYScjs.stickerPage.call(void 0, _chunkZEYMKDYScjs.STAMP_KINDS.map(summary), options),
201
+ search: (query, options) => _chunkZEYMKDYScjs.stickerPage.call(void 0, _chunkZEYMKDYScjs.STAMP_KINDS.map(summary), options, query),
202
+ describe(id) {
203
+ if (!_chunkZEYMKDYScjs.STAMP_KINDS.includes(id)) return void 0;
204
+ const k = id;
205
+ return { ...summary(k), silhouette: outline(k), colours: [META[k].colour] };
206
+ },
207
+ categories: () => [...new Set(_chunkZEYMKDYScjs.STAMP_KINDS.map((k) => META[k].category))].map((c) => ({ id: c, name: c[0].toUpperCase() + c.slice(1), count: _chunkZEYMKDYScjs.STAMP_KINDS.filter((k) => META[k].category === c).length })),
208
+ load(id, options = {}) {
209
+ const k = kind(id);
210
+ const colour = _nullishCoalesce(options.colour, () => ( META[k].colour));
211
+ if (!HEX.test(colour)) throw new (0, _chunkZEYMKDYScjs.StickerError)("invalid_argument", `colour ${JSON.stringify(colour)} must be #rrggbb.`);
212
+ if (options.format === "png") {
213
+ const size = _nullishCoalesce(options.size, () => ( 256));
214
+ if (!(Number.isInteger(size) && size >= 8 && size <= 1024)) throw new (0, _chunkZEYMKDYScjs.StickerError)("invalid_argument", `size must be a whole number of px from 8 to 1024, got ${size}.`);
215
+ return { kind: "image", url: _chunkW5M3J7PVcjs.pngDataUrl.call(void 0, size, size, stampPixels(k, size, colour.toLowerCase())), width: size, height: size };
216
+ }
217
+ if (options.format !== void 0 && options.format !== "svg") throw new (0, _chunkZEYMKDYScjs.StickerError)("unsupported_format", `format must be svg or png, got ${JSON.stringify(options.format)}.`);
218
+ const d = outline(k);
219
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${BOX} ${BOX}" width="${BOX}" height="${BOX}"><path fill="${colour.toLowerCase()}" fill-rule="evenodd" d="${d}"/></svg>`;
220
+ return { kind: "svg", svg, silhouette: d };
221
+ }
222
+ };
223
+ }
224
+
225
+ // src/stickers/browser.ts
226
+ var StickerBrowser = (_class = class {
227
+ constructor(provider, pageSize = 24) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);
228
+ this.provider = provider;
229
+ this.pageSize = pageSize;
230
+ this.s = { query: "", category: "", items: [], total: 0, hasMore: false, loading: false, error: null, categories: [], provider: provider().name };
231
+ }
232
+
233
+
234
+
235
+
236
+ __init() {this.run = 0}
237
+ __init2() {this.listeners = /* @__PURE__ */ new Set()}
238
+ get state() {
239
+ return this.s;
240
+ }
241
+ subscribe(listener) {
242
+ this.listeners.add(listener);
243
+ return () => this.listeners.delete(listener);
244
+ }
245
+ set(patch) {
246
+ this.s = { ...this.s, ...patch };
247
+ for (const l of [...this.listeners]) l();
248
+ }
249
+ /** Loads the first page (and the categories) again, for the current provider. */
250
+ async refresh() {
251
+ const run = ++this.run;
252
+ const p = this.provider();
253
+ this.next = void 0;
254
+ this.set({ loading: true, error: null, items: [], total: 0, hasMore: false, provider: p.name });
255
+ try {
256
+ const categories = await _asyncNullishCoalesce(await _optionalChain([p, 'access', _2 => _2.categories, 'optionalCall', _3 => _3()]), async () => ( []));
257
+ if (run !== this.run) return;
258
+ this.set({ categories });
259
+ await this.page(run, p, true);
260
+ } catch (e) {
261
+ if (run === this.run) this.set({ loading: false, error: e instanceof Error ? e.message : String(e) });
262
+ }
263
+ }
264
+ /** Searches for `query` (words; `''` lists everything) from the first page. */
265
+ setQuery(query) {
266
+ this.s = { ...this.s, query };
267
+ return this.refresh();
268
+ }
269
+ /** Shows one category (`''` for all) from the first page. */
270
+ setCategory(category) {
271
+ this.s = { ...this.s, category };
272
+ return this.refresh();
273
+ }
274
+ /** Loads the next page onto the list. */
275
+ async more() {
276
+ if (!this.next || this.s.loading) return;
277
+ const run = this.run;
278
+ this.set({ loading: true });
279
+ try {
280
+ await this.page(run, this.provider(), false);
281
+ } catch (e) {
282
+ if (run === this.run) this.set({ loading: false, error: e instanceof Error ? e.message : String(e) });
283
+ }
284
+ }
285
+ async page(run, p, first) {
286
+ const options = { limit: this.pageSize, ...this.s.category ? { category: this.s.category } : {}, ...!first && this.next ? { after: this.next } : {} };
287
+ const q = this.s.query.trim();
288
+ const res = q && p.capabilities.supportsSearch ? await p.search(q, options) : await p.list(options);
289
+ if (run !== this.run) return;
290
+ this.next = res.next;
291
+ const items = res.items.map((s) => ({ ...s, ref: _chunkZEYMKDYScjs.stickerRefOf.call(void 0, p, s.id) }));
292
+ this.set({ items: first ? items : [...this.s.items, ...items], total: res.total, hasMore: Boolean(res.next), loading: false });
293
+ }
294
+ }, _class);
295
+
296
+
297
+
298
+
299
+
300
+
301
+ exports.stampOutline = stampOutline; exports.stampPixels = stampPixels; exports.editorStickers = editorStickers; exports.StickerBrowser = StickerBrowser;