@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.
- package/README.md +1 -0
- package/dist/animation-editor/index.cjs +64 -61
- package/dist/animation-editor/index.js +8 -5
- package/dist/{brushstrokeRender-ZDHMXJAE.cjs → brushstrokeRender-GCKK7V2I.cjs} +14 -11
- package/dist/{brushstrokeRender-AKUI3SEJ.js → brushstrokeRender-T3JZST44.js} +7 -4
- package/dist/canvas/index.cjs +8 -8
- package/dist/canvas/index.js +1 -1
- package/dist/{chunk-UVPD55UZ.cjs → chunk-2SMMZDMG.cjs} +35 -35
- package/dist/chunk-2VJAVXLI.js +192 -0
- package/dist/{chunk-OLNIPTB3.cjs → chunk-2VX55NFM.cjs} +1 -320
- package/dist/chunk-3K6HWEXZ.cjs +92 -0
- package/dist/{chunk-UOOK7HTX.js → chunk-3PPJRMIG.js} +1 -1
- package/dist/chunk-4D6KP5BV.js +92 -0
- package/dist/chunk-5RH3VXAK.js +269 -0
- package/dist/{chunk-LDPLEZ5T.js → chunk-6BIDVPED.js} +1 -1
- package/dist/{chunk-2ONK3ERD.cjs → chunk-75K3W4D6.cjs} +20 -20
- package/dist/chunk-BOHDJJ2O.cjs +192 -0
- package/dist/{chunk-2PBZBRP5.js → chunk-D5KGAO4Z.js} +10 -92
- package/dist/{chunk-DQWPMGH2.js → chunk-DOIU7VJG.js} +1 -1
- package/dist/{chunk-HB4ICNNA.cjs → chunk-DPYAO5U6.cjs} +42 -42
- package/dist/chunk-EJLRBS5Q.js +301 -0
- package/dist/{chunk-Q2UYUWAZ.cjs → chunk-H4AOUUBE.cjs} +679 -164
- package/dist/{chunk-PQ3H2AAN.cjs → chunk-I7NJPHWV.cjs} +122 -204
- package/dist/{chunk-FK5LTDOO.cjs → chunk-IOFVM3L3.cjs} +7 -7
- package/dist/{chunk-42TWUPNJ.js → chunk-IRSTHLQQ.js} +1 -320
- package/dist/{chunk-VDAWA546.js → chunk-J7T5QZ45.js} +614 -99
- package/dist/{chunk-VMROIWLL.cjs → chunk-KBYB7OWB.cjs} +3 -3
- package/dist/{chunk-5MFDD7SP.cjs → chunk-KYX7NZ5V.cjs} +1 -1
- package/dist/chunk-LJRCU3BJ.cjs +301 -0
- package/dist/{chunk-XTWXBQD4.cjs → chunk-LP2MCSBE.cjs} +593 -236
- package/dist/{chunk-A23PSOBB.js → chunk-O75V4ZS3.js} +1 -1
- package/dist/chunk-OTTT5N3K.js +322 -0
- package/dist/{chunk-N6WUB3Y5.js → chunk-PZP2SZIZ.js} +2 -2
- package/dist/{chunk-4PMCMWQS.js → chunk-UBRJOIR5.js} +367 -10
- package/dist/chunk-W5M3J7PV.cjs +322 -0
- package/dist/{chunk-4P6H35HU.js → chunk-WA44NKPF.js} +2 -2
- package/dist/{chunk-CEPKXLBS.cjs → chunk-WLJZZHUZ.cjs} +23 -23
- package/dist/{chunk-P3NIPIKS.js → chunk-WQCNC4DK.js} +1 -1
- package/dist/chunk-ZEYMKDYS.cjs +269 -0
- package/dist/image-editor/effect-tools.d.cts +37 -4
- package/dist/image-editor/effect-tools.d.ts +37 -4
- package/dist/image-editor/index.cjs +1340 -1828
- package/dist/image-editor/index.d.cts +1 -1
- package/dist/image-editor/index.d.ts +1 -1
- package/dist/image-editor/index.js +298 -786
- package/dist/paint/index.cjs +8 -5
- package/dist/paint/index.js +13 -10
- package/dist/paint-editor/controller.d.cts +71 -2
- package/dist/paint-editor/controller.d.ts +71 -2
- package/dist/paint-editor/index.cjs +901 -589
- package/dist/paint-editor/index.d.cts +3 -0
- package/dist/paint-editor/index.d.ts +3 -0
- package/dist/paint-editor/index.js +365 -53
- package/dist/paint-editor/procedural.d.cts +82 -5
- package/dist/paint-editor/procedural.d.ts +82 -5
- package/dist/paint-editor/sticker-art.d.cts +55 -0
- package/dist/paint-editor/sticker-art.d.ts +55 -0
- package/dist/paint-editor/stickers.d.cts +30 -17
- package/dist/paint-editor/stickers.d.ts +30 -17
- package/dist/paint-editor/stroke.d.cts +4 -0
- package/dist/paint-editor/stroke.d.ts +4 -0
- package/dist/paint-editor/tools.d.cts +1 -1
- package/dist/paint-editor/tools.d.ts +1 -1
- package/dist/paint-editor/ui.d.cts +25 -4
- package/dist/paint-editor/ui.d.ts +25 -4
- package/dist/{image-editor/layers/effects-ui.d.cts → raster/effects/ui.d.cts} +32 -5
- package/dist/{image-editor/layers/effects-ui.d.ts → raster/effects/ui.d.ts} +32 -5
- package/dist/raster/index.cjs +17 -3
- package/dist/raster/index.d.cts +1 -0
- package/dist/raster/index.d.ts +1 -0
- package/dist/raster/index.js +23 -9
- package/dist/stickers/browser.d.cts +48 -0
- package/dist/stickers/browser.d.ts +48 -0
- package/dist/stickers/combine.d.cts +10 -0
- package/dist/stickers/combine.d.ts +10 -0
- package/dist/stickers/conformance.d.cts +18 -0
- package/dist/stickers/conformance.d.ts +18 -0
- package/dist/stickers/editor.d.cts +14 -0
- package/dist/stickers/editor.d.ts +14 -0
- package/dist/stickers/errors.d.cts +6 -0
- package/dist/stickers/errors.d.ts +6 -0
- package/dist/stickers/fake.d.cts +16 -0
- package/dist/stickers/fake.d.ts +16 -0
- package/dist/stickers/helpers.d.cts +51 -0
- package/dist/stickers/helpers.d.ts +51 -0
- package/dist/stickers/index.cjs +331 -0
- package/dist/stickers/index.d.cts +16 -0
- package/dist/stickers/index.d.ts +16 -0
- package/dist/stickers/index.js +331 -0
- package/dist/stickers/stamps.d.cts +13 -0
- package/dist/stickers/stamps.d.ts +13 -0
- package/dist/stickers/tools.d.cts +25 -0
- package/dist/stickers/tools.d.ts +25 -0
- package/dist/stickers/types.d.cts +123 -0
- package/dist/stickers/types.d.ts +123 -0
- package/dist/vector/index.cjs +978 -975
- package/dist/vector/index.js +9 -6
- package/package.json +11 -1
- package/skills/README.md +1 -0
- package/skills/pixerate-paint-editor/SKILL.md +26 -32
- package/skills/pixerate-paint-editor/references/gradient-paint.md +23 -0
- package/skills/pixerate-paint-editor/references/layer-effects.md +28 -0
- package/skills/pixerate-paint-editor/references/light-paint.md +10 -2
- package/skills/pixerate-paint-editor/references/particle-brushes.md +66 -0
- package/skills/pixerate-stickers/SKILL.md +45 -0
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EDITOR_STICKERS_ID,
|
|
3
|
+
STAMP_KINDS,
|
|
4
|
+
StickerError,
|
|
5
|
+
stampCoverage,
|
|
6
|
+
stickerPage,
|
|
7
|
+
stickerRefOf
|
|
8
|
+
} from "./chunk-5RH3VXAK.js";
|
|
9
|
+
import {
|
|
10
|
+
pngDataUrl
|
|
11
|
+
} from "./chunk-OTTT5N3K.js";
|
|
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] = stampCoverage(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 += stampCoverage(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) => 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, pngDataUrl(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 (!STAMP_KINDS.includes(id)) throw new StickerError("unknown_sticker", `The editor has no sticker "${id}"; its stickers are ${STAMP_KINDS.join(", ")}.`);
|
|
193
|
+
return id;
|
|
194
|
+
};
|
|
195
|
+
return {
|
|
196
|
+
id: EDITOR_STICKERS_ID,
|
|
197
|
+
name: "Editor stickers",
|
|
198
|
+
version: "1",
|
|
199
|
+
capabilities: { supportsSearch: true, supportsSvg: true, supportsRaster: true, maxSize: 1024 },
|
|
200
|
+
list: (options) => stickerPage(STAMP_KINDS.map(summary), options),
|
|
201
|
+
search: (query, options) => stickerPage(STAMP_KINDS.map(summary), options, query),
|
|
202
|
+
describe(id) {
|
|
203
|
+
if (!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(STAMP_KINDS.map((k) => META[k].category))].map((c) => ({ id: c, name: c[0].toUpperCase() + c.slice(1), count: STAMP_KINDS.filter((k) => META[k].category === c).length })),
|
|
208
|
+
load(id, options = {}) {
|
|
209
|
+
const k = kind(id);
|
|
210
|
+
const colour = options.colour ?? META[k].colour;
|
|
211
|
+
if (!HEX.test(colour)) throw new StickerError("invalid_argument", `colour ${JSON.stringify(colour)} must be #rrggbb.`);
|
|
212
|
+
if (options.format === "png") {
|
|
213
|
+
const size = options.size ?? 256;
|
|
214
|
+
if (!(Number.isInteger(size) && size >= 8 && size <= 1024)) throw new StickerError("invalid_argument", `size must be a whole number of px from 8 to 1024, got ${size}.`);
|
|
215
|
+
return { kind: "image", url: pngDataUrl(size, size, stampPixels(k, size, colour.toLowerCase())), width: size, height: size };
|
|
216
|
+
}
|
|
217
|
+
if (options.format !== void 0 && options.format !== "svg") throw new 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 {
|
|
227
|
+
constructor(provider, pageSize = 24) {
|
|
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
|
+
provider;
|
|
233
|
+
pageSize;
|
|
234
|
+
s;
|
|
235
|
+
next;
|
|
236
|
+
run = 0;
|
|
237
|
+
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 p.categories?.() ?? [];
|
|
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: stickerRefOf(p, s.id) }));
|
|
292
|
+
this.set({ items: first ? items : [...this.s.items, ...items], total: res.total, hasMore: Boolean(res.next), loading: false });
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
export {
|
|
297
|
+
stampOutline,
|
|
298
|
+
stampPixels,
|
|
299
|
+
editorStickers,
|
|
300
|
+
StickerBrowser
|
|
301
|
+
};
|