iconplease 0.3.0 → 0.4.1

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.
@@ -0,0 +1,53 @@
1
+ # iconplease Icon License
2
+
3
+ Version 1.0 — 2026
4
+
5
+ This licence covers the icons in the public iconplease catalogue (served from
6
+ `cdn.iconplease.com` and shown on iconplease.com/icons). It does not cover
7
+ private icons; see "Private icons" below.
8
+
9
+ ## You may
10
+
11
+ - Use the icons for free in personal and commercial work: websites, apps,
12
+ software, products you sell, marketing, print, video, slides and documents.
13
+ - Change them: recolour, resize, re-stroke, edit and combine them.
14
+ - Ship them inside your own product, website or app, including in source code
15
+ and builds that other people can download.
16
+
17
+ No attribution is required. A link back to iconplease.com is appreciated.
18
+
19
+ ## You may not
20
+
21
+ - Redistribute the icons as an icon set, icon font, icon pack or library — on
22
+ their own or as the main part of another product — whether free or paid.
23
+ - Use them to build a product that competes with iconplease (an icon library,
24
+ icon marketplace or icon design service).
25
+ - Sell or license the icons themselves, as they are or modified, for example as
26
+ stock assets, templates or NFTs.
27
+ - Use them in a logo or trademark, or in a way that suggests iconplease
28
+ endorses you.
29
+
30
+ ## Private icons
31
+
32
+ Private icons are not covered by this licence, by the MIT licence of the
33
+ iconplease code, or by any other open licence. Private icons are:
34
+
35
+ - icons drawn in the iconplease designer and saved to an account ("My icons");
36
+ - icons in a private set, including catalogue icons that a set owner changed;
37
+ - icons in a file written by `npx iconplease pull` from a private set.
38
+
39
+ A private icon belongs to the person who made it (or their employer or client,
40
+ as they agree between themselves). iconplease does not own it and only stores
41
+ and serves it to do the job the owner asked for. Seeing, downloading or
42
+ receiving a private icon, through a website, an API key, a token, a build file
43
+ or a Figma file, gives you no right to use it. Only its owner can grant one.
44
+
45
+ A catalogue icon that someone has only recoloured or resized stays a catalogue
46
+ icon, and this licence still applies to it.
47
+
48
+ ## No warranty
49
+
50
+ The icons are provided "as is", without warranty of any kind. iconplease is
51
+ not liable for any claim or damage arising from their use.
52
+
53
+ Questions: hello@iconplease.com
package/LICENSE ADDED
@@ -0,0 +1,30 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 TECHNOLOGYPLEASE Co., Ltd.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ This licence covers the code in this package only. It does not cover any icon
24
+ the code loads, renders or writes, including:
25
+
26
+ - the public catalogue icons from cdn.iconplease.com, which are covered by the
27
+ iconplease Icon License (ICONS-LICENSE.md);
28
+ - private icons: icons in a private set, icons people draw in the iconplease
29
+ designer, and icons in a file written by `npx iconplease pull`. These belong
30
+ to their owners. Nothing in this licence grants anyone any right to them.
package/README.md CHANGED
@@ -144,3 +144,11 @@ await load(["heart", "star"]);
144
144
  import { init } from "iconplease";
145
145
  init({ revalidate: 600 });
146
146
  ```
147
+
148
+ ## Licence
149
+
150
+ The code is MIT (see `LICENSE`). The catalogue icons are free for personal and
151
+ commercial use, with no attribution, under the iconplease Icon License (see
152
+ `ICONS-LICENSE.md`). Just don't redistribute them as an icon set of your own.
153
+ Private icons (your own drawings, private sets, files from `npx iconplease pull`)
154
+ are not covered by either licence. They belong to their owners.
@@ -0,0 +1,71 @@
1
+ export type AnimationPreset = "draw" | "fade" | "pop" | "spin" | "slide-up" | "slide-down" | "slide-left" | "slide-right" | "bounce" | "pulse" | "shake" | "spin-back" | "fade-out" | "pop-out" | "slide-out-up" | "slide-out-down" | "follow";
2
+ export type AnimationEasing = "linear" | "ease-in" | "ease-out" | "ease-in-out" | "spring";
3
+ export type AnimationTrigger = "load" | "hover" | "click" | "toggle" | "visible";
4
+ export type AnimationClip = {
5
+ id: string;
6
+ target: string;
7
+ preset: AnimationPreset;
8
+ start: number;
9
+ duration: number;
10
+ easing: AnimationEasing;
11
+ path?: string;
12
+ orient?: boolean;
13
+ };
14
+ export type IconAnimation = {
15
+ version: 1;
16
+ trigger: AnimationTrigger;
17
+ loop: boolean;
18
+ loopGap: number;
19
+ reverse?: boolean;
20
+ clips: AnimationClip[];
21
+ };
22
+ type Frame = {
23
+ offset: number;
24
+ transform?: string;
25
+ opacity?: number;
26
+ };
27
+ type PresetSpec = {
28
+ label: string;
29
+ hint: string;
30
+ duration: number;
31
+ easing: AnimationEasing;
32
+ frames?: Frame[];
33
+ draw?: boolean;
34
+ route?: boolean;
35
+ };
36
+ export declare const PRESETS: Record<AnimationPreset, PresetSpec>;
37
+ export declare const PRESET_ORDER: AnimationPreset[];
38
+ export declare const ROUTE_PATH: RegExp;
39
+ export declare const EASINGS: Record<AnimationEasing, {
40
+ label: string;
41
+ css: string;
42
+ }>;
43
+ export declare const TRIGGERS: Record<AnimationTrigger, string>;
44
+ export declare const MAX_CLIPS = 64;
45
+ export declare const MAX_TIME = 10000;
46
+ export declare const MIN_DURATION = 50;
47
+ export declare const cleanAnimation: (value: unknown) => IconAnimation | undefined;
48
+ export declare const ANIMATION_ATTRIBUTE = "data-ip-animation";
49
+ export declare const MARKER_ATTRIBUTE = "data-ip";
50
+ export declare const encodeAnimation: (animation: IconAnimation) => string;
51
+ export declare const decodeAnimation: (value: string | undefined | null) => IconAnimation | undefined;
52
+ export declare const totalDuration: (animation: Pick<IconAnimation, "clips">) => number;
53
+ export type Playback = {
54
+ play: () => void;
55
+ pause: () => void;
56
+ seek: (time: number) => void;
57
+ cancel: () => void;
58
+ readonly period: number;
59
+ readonly animations: Animation[];
60
+ /** Plays backwards from wherever it is, then calls done once it is back at the start. */
61
+ reverse: (done?: () => void) => void;
62
+ /** Plays forwards again after a reverse, from wherever it is. */
63
+ forward: () => void;
64
+ /** Maps an animation's raw currentTime to a moment on the designer's ruler (0..total). */
65
+ readonly clock: (raw: number) => number;
66
+ };
67
+ export declare const animate: (animation: IconAnimation, targetsOf: (target: string) => Element[], options?: {
68
+ paused?: boolean;
69
+ loop?: boolean;
70
+ }) => Playback;
71
+ export {};
@@ -0,0 +1,294 @@
1
+ export const PRESETS = {
2
+ draw: { label: "Draw on", hint: "Strokes draw themselves", duration: 700, easing: "ease-in-out", draw: true },
3
+ fade: { label: "Fade in", hint: "From invisible to visible", duration: 400, easing: "ease-out", frames: [{ offset: 0, opacity: 0 }, { offset: 1, opacity: 1 }] },
4
+ pop: { label: "Pop in", hint: "Grows from nothing with a little overshoot", duration: 450, easing: "spring", frames: [{ offset: 0, transform: "scale(0)" }, { offset: 1, transform: "scale(1)" }] },
5
+ spin: { label: "Spin", hint: "One full turn", duration: 800, easing: "ease-in-out", frames: [{ offset: 0, transform: "rotate(0deg)" }, { offset: 1, transform: "rotate(360deg)" }] },
6
+ "slide-up": { label: "Slide up", hint: "Rises into place", duration: 450, easing: "ease-out", frames: [{ offset: 0, transform: "translateY(4px)", opacity: 0 }, { offset: 1, transform: "translateY(0px)", opacity: 1 }] },
7
+ "slide-down": { label: "Slide down", hint: "Drops into place", duration: 450, easing: "ease-out", frames: [{ offset: 0, transform: "translateY(-4px)", opacity: 0 }, { offset: 1, transform: "translateY(0px)", opacity: 1 }] },
8
+ "slide-left": { label: "Slide left", hint: "Comes in from the right", duration: 450, easing: "ease-out", frames: [{ offset: 0, transform: "translateX(4px)", opacity: 0 }, { offset: 1, transform: "translateX(0px)", opacity: 1 }] },
9
+ "slide-right": { label: "Slide right", hint: "Comes in from the left", duration: 450, easing: "ease-out", frames: [{ offset: 0, transform: "translateX(-4px)", opacity: 0 }, { offset: 1, transform: "translateX(0px)", opacity: 1 }] },
10
+ bounce: {
11
+ label: "Bounce",
12
+ hint: "Hops up and lands",
13
+ duration: 700,
14
+ easing: "ease-out",
15
+ frames: [
16
+ { offset: 0, transform: "translateY(0px)" },
17
+ { offset: 0.35, transform: "translateY(-4px)" },
18
+ { offset: 0.65, transform: "translateY(0px)" },
19
+ { offset: 0.82, transform: "translateY(-1.5px)" },
20
+ { offset: 1, transform: "translateY(0px)" },
21
+ ],
22
+ },
23
+ pulse: {
24
+ label: "Pulse",
25
+ hint: "Swells and settles",
26
+ duration: 600,
27
+ easing: "ease-in-out",
28
+ frames: [
29
+ { offset: 0, transform: "scale(1)" },
30
+ { offset: 0.5, transform: "scale(1.18)" },
31
+ { offset: 1, transform: "scale(1)" },
32
+ ],
33
+ },
34
+ "spin-back": { label: "Spin back", hint: "One full turn, anticlockwise", duration: 800, easing: "ease-in-out", frames: [{ offset: 0, transform: "rotate(0deg)" }, { offset: 1, transform: "rotate(-360deg)" }] },
35
+ "fade-out": { label: "Fade out", hint: "From visible to invisible", duration: 400, easing: "ease-in", frames: [{ offset: 0, opacity: 1 }, { offset: 1, opacity: 0 }] },
36
+ "pop-out": { label: "Pop out", hint: "Shrinks away to nothing", duration: 350, easing: "ease-in", frames: [{ offset: 0, transform: "scale(1)" }, { offset: 1, transform: "scale(0)" }] },
37
+ "slide-out-up": { label: "Slide out up", hint: "Rises and fades away", duration: 400, easing: "ease-in", frames: [{ offset: 0, transform: "translateY(0px)", opacity: 1 }, { offset: 1, transform: "translateY(-4px)", opacity: 0 }] },
38
+ "slide-out-down": { label: "Slide out down", hint: "Drops and fades away", duration: 400, easing: "ease-in", frames: [{ offset: 0, transform: "translateY(0px)", opacity: 1 }, { offset: 1, transform: "translateY(4px)", opacity: 0 }] },
39
+ follow: { label: "Move along path", hint: "The shape's centre travels along a route you drew", duration: 1200, easing: "ease-in-out", route: true },
40
+ shake: {
41
+ label: "Shake",
42
+ hint: "A quick wobble",
43
+ duration: 600,
44
+ easing: "ease-in-out",
45
+ frames: [
46
+ { offset: 0, transform: "rotate(0deg)" },
47
+ { offset: 0.2, transform: "rotate(-14deg)" },
48
+ { offset: 0.4, transform: "rotate(12deg)" },
49
+ { offset: 0.6, transform: "rotate(-8deg)" },
50
+ { offset: 0.8, transform: "rotate(4deg)" },
51
+ { offset: 1, transform: "rotate(0deg)" },
52
+ ],
53
+ },
54
+ };
55
+ export const PRESET_ORDER = Object.keys(PRESETS).filter((preset) => !PRESETS[preset].route);
56
+ export const ROUTE_PATH = /^[MmLlHhVvCcSsQqTtAaZz0-9eE.,\s+-]{1,8000}$/;
57
+ export const EASINGS = {
58
+ linear: { label: "Linear", css: "linear" },
59
+ "ease-in": { label: "Ease in", css: "cubic-bezier(0.4, 0, 1, 1)" },
60
+ "ease-out": { label: "Ease out", css: "cubic-bezier(0, 0, 0.2, 1)" },
61
+ "ease-in-out": { label: "Ease in-out", css: "cubic-bezier(0.4, 0, 0.2, 1)" },
62
+ spring: { label: "Spring", css: "cubic-bezier(0.34, 1.56, 0.64, 1)" },
63
+ };
64
+ export const TRIGGERS = {
65
+ load: "When it appears",
66
+ hover: "On hover",
67
+ click: "On click",
68
+ toggle: "Click to toggle",
69
+ visible: "When scrolled into view",
70
+ };
71
+ export const MAX_CLIPS = 64;
72
+ export const MAX_TIME = 10000;
73
+ export const MIN_DURATION = 50;
74
+ const PRESET_SET = new Set(Object.keys(PRESETS));
75
+ const ID = /^[A-Za-z0-9_-]{1,64}$/;
76
+ const ms = (value, low, high) => typeof value === "number" && Number.isFinite(value) ? Math.round(Math.min(Math.max(value, low), high)) : undefined;
77
+ export const cleanAnimation = (value) => {
78
+ if (!value || typeof value !== "object")
79
+ return undefined;
80
+ const raw = value;
81
+ const clips = [];
82
+ for (const clip of Array.isArray(raw.clips) ? raw.clips.slice(0, MAX_CLIPS) : []) {
83
+ if (!clip || typeof clip !== "object")
84
+ continue;
85
+ const start = ms(clip.start, 0, MAX_TIME);
86
+ const duration = ms(clip.duration, MIN_DURATION, MAX_TIME);
87
+ if (typeof clip.id !== "string" || !ID.test(clip.id))
88
+ continue;
89
+ if (typeof clip.target !== "string" || !ID.test(clip.target))
90
+ continue;
91
+ if (!PRESET_SET.has(clip.preset) || start === undefined || duration === undefined)
92
+ continue;
93
+ const route = PRESETS[clip.preset].route;
94
+ if (route && (typeof clip.path !== "string" || !ROUTE_PATH.test(clip.path) || !/^\s*[Mm]/.test(clip.path)))
95
+ continue;
96
+ clips.push({
97
+ id: clip.id,
98
+ target: clip.target,
99
+ preset: clip.preset,
100
+ start,
101
+ duration,
102
+ easing: clip.easing && clip.easing in EASINGS ? clip.easing : PRESETS[clip.preset].easing,
103
+ ...(route ? { path: clip.path, orient: clip.orient === true } : {}),
104
+ });
105
+ }
106
+ if (!clips.length)
107
+ return undefined;
108
+ return {
109
+ version: 1,
110
+ trigger: raw.trigger && raw.trigger in TRIGGERS ? raw.trigger : "load",
111
+ loop: raw.loop === true,
112
+ loopGap: ms(raw.loopGap, 0, MAX_TIME) ?? 0,
113
+ ...(raw.reverse === true ? { reverse: true } : {}),
114
+ clips,
115
+ };
116
+ };
117
+ export const ANIMATION_ATTRIBUTE = "data-ip-animation";
118
+ export const MARKER_ATTRIBUTE = "data-ip";
119
+ const toBase64Url = (text) => btoa(text).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
120
+ const fromBase64Url = (value) => atob(value.replace(/-/g, "+").replace(/_/g, "/"));
121
+ export const encodeAnimation = (animation) => toBase64Url(JSON.stringify(animation));
122
+ export const decodeAnimation = (value) => {
123
+ if (!value || value.length > 60000 || !/^[A-Za-z0-9_-]+$/.test(value))
124
+ return undefined;
125
+ try {
126
+ return cleanAnimation(JSON.parse(fromBase64Url(value)));
127
+ }
128
+ catch {
129
+ return undefined;
130
+ }
131
+ };
132
+ export const totalDuration = (animation) => animation.clips.reduce((end, clip) => Math.max(end, clip.start + clip.duration), 0);
133
+ const GEOMETRY = "path, line, rect, ellipse, circle, polyline, polygon";
134
+ const strokesOf = (root) => [...root.querySelectorAll(GEOMETRY)].filter((node) => {
135
+ if (node.closest("defs, clipPath, mask"))
136
+ return false;
137
+ const stroke = node.getAttribute("stroke") ?? getComputedStyle(node).stroke;
138
+ return Boolean(stroke) && stroke !== "none" && stroke !== "transparent" && typeof node.getTotalLength === "function";
139
+ });
140
+ const SVG_NS = "http://www.w3.org/2000/svg";
141
+ const ROUTE_SAMPLES = 48;
142
+ const routeFrames = (root, d, orient) => {
143
+ const host = root.ownerSVGElement ?? root.closest("svg");
144
+ if (!host || typeof root.getBBox !== "function")
145
+ return [];
146
+ const guide = document.createElementNS(SVG_NS, "path");
147
+ guide.setAttribute("d", d);
148
+ guide.setAttribute("visibility", "hidden");
149
+ host.appendChild(guide);
150
+ try {
151
+ const length = guide.getTotalLength();
152
+ const box = root.getBBox();
153
+ const cx = box.x + box.width / 2;
154
+ const cy = box.y + box.height / 2;
155
+ const at = (distance) => guide.getPointAtLength(Math.min(Math.max(distance, 0), length));
156
+ const angle = (distance) => {
157
+ const step = Math.max(length / 400, 0.01);
158
+ const a = at(distance - step);
159
+ const b = at(distance + step);
160
+ return (Math.atan2(b.y - a.y, b.x - a.x) * 180) / Math.PI;
161
+ };
162
+ const first = angle(0);
163
+ let previous = 0;
164
+ return Array.from({ length: ROUTE_SAMPLES + 1 }, (_, index) => {
165
+ const distance = (index / ROUTE_SAMPLES) * length;
166
+ const point = at(distance);
167
+ let turn = angle(distance) - first;
168
+ while (turn - previous > 180)
169
+ turn -= 360;
170
+ while (turn - previous < -180)
171
+ turn += 360;
172
+ previous = turn;
173
+ const move = `translate(${(point.x - cx).toFixed(3)}px, ${(point.y - cy).toFixed(3)}px)`;
174
+ return { offset: index / ROUTE_SAMPLES, transform: orient ? `${move} rotate(${turn.toFixed(2)}deg)` : move };
175
+ });
176
+ }
177
+ finally {
178
+ guide.remove();
179
+ }
180
+ };
181
+ const onTimeline = (frames, clip, period, neutral, lead = 0) => {
182
+ const begin = (clip.start + lead) / period;
183
+ const end = (clip.start + lead + clip.duration) / period;
184
+ const easing = EASINGS[clip.easing].css;
185
+ const placed = frames.map((frame, index) => ({
186
+ ...frame,
187
+ offset: begin + frame.offset * (end - begin),
188
+ easing: index < frames.length - 1 ? easing : "linear",
189
+ }));
190
+ const first = { ...(neutral ?? frames[0]), offset: 0, easing: "linear" };
191
+ const last = { ...frames[frames.length - 1], offset: 1, easing: "linear" };
192
+ const out = [];
193
+ if (placed[0].offset > 0) {
194
+ out.push(first);
195
+ if (neutral)
196
+ out.push({ ...neutral, offset: placed[0].offset, easing: "linear" });
197
+ }
198
+ out.push(...placed);
199
+ if (placed[placed.length - 1].offset < 1)
200
+ out.push(last);
201
+ return out;
202
+ };
203
+ export const animate = (animation, targetsOf, options = {}) => {
204
+ const total = Math.max(totalDuration(animation), MIN_DURATION);
205
+ const loop = options.loop ?? animation.loop;
206
+ const period = loop ? total + animation.loopGap : total;
207
+ const backAndForth = loop && animation.reverse === true;
208
+ const lead = backAndForth ? animation.loopGap / 2 : 0;
209
+ const animations = [];
210
+ const timing = {
211
+ duration: period,
212
+ iterations: loop ? Infinity : 1,
213
+ fill: "both",
214
+ direction: backAndForth ? "alternate" : "normal",
215
+ };
216
+ for (const clip of animation.clips) {
217
+ const spec = PRESETS[clip.preset];
218
+ const follows = animation.clips.some((other) => other.target === clip.target && other.start < clip.start);
219
+ for (const root of targetsOf(clip.target)) {
220
+ if (spec.draw) {
221
+ for (const stroke of strokesOf(root)) {
222
+ const length = Math.max(stroke.getTotalLength(), 0.01);
223
+ const frames = [
224
+ { offset: 0, strokeDasharray: `${length} ${length}`, strokeDashoffset: length },
225
+ { offset: 1, strokeDasharray: `${length} ${length}`, strokeDashoffset: 0 },
226
+ ];
227
+ const shown = follows ? { offset: 0, strokeDasharray: `${length} ${length}`, strokeDashoffset: 0 } : undefined;
228
+ animations.push(stroke.animate(onTimeline(frames, clip, period, shown, lead), timing));
229
+ }
230
+ continue;
231
+ }
232
+ const element = root;
233
+ element.style.transformBox = "fill-box";
234
+ element.style.transformOrigin = "center";
235
+ const frames = spec.route ? routeFrames(root, clip.path ?? "", clip.orient === true) : (spec.frames ?? []).map((frame) => ({ ...frame }));
236
+ if (!frames.length)
237
+ continue;
238
+ const moves = frames.some((frame) => frame.transform !== undefined);
239
+ const fades = frames.some((frame) => frame.opacity !== undefined);
240
+ const shown = follows
241
+ ? { offset: 0, ...(moves ? { transform: "translate(0px, 0px)" } : {}), ...(fades ? { opacity: 1 } : {}) }
242
+ : undefined;
243
+ animations.push(element.animate(onTimeline(frames, clip, period, shown, lead), { ...timing, composite: moves ? "add" : "replace" }));
244
+ }
245
+ }
246
+ const each = (fn) => animations.forEach(fn);
247
+ const clock = (raw) => {
248
+ if (!loop)
249
+ return Math.min(raw, total);
250
+ const cycle = Math.floor(raw / period);
251
+ const within = raw - cycle * period;
252
+ const forward = backAndForth && cycle % 2 === 1 ? period - within : within;
253
+ return Math.min(total, Math.max(0, forward - lead));
254
+ };
255
+ if (options.paused)
256
+ each((item) => item.pause());
257
+ return {
258
+ play: () => each((item) => item.play()),
259
+ pause: () => each((item) => item.pause()),
260
+ reverse: (done) => {
261
+ const first = animations[0];
262
+ if (!first)
263
+ return done?.();
264
+ const at = clock(Number(first.currentTime ?? 0)) + lead;
265
+ if (at <= 1)
266
+ return done?.();
267
+ try {
268
+ each((item) => {
269
+ item.currentTime = at;
270
+ item.playbackRate = -1;
271
+ item.play();
272
+ });
273
+ }
274
+ catch {
275
+ return done?.();
276
+ }
277
+ first.onfinish = () => {
278
+ first.onfinish = null;
279
+ done?.();
280
+ };
281
+ },
282
+ forward: () => {
283
+ if (animations[0])
284
+ animations[0].onfinish = null;
285
+ each((item) => (item.playbackRate = 1));
286
+ each((item) => item.play());
287
+ },
288
+ seek: (time) => each((item) => (item.currentTime = Math.max(0, time + lead))),
289
+ cancel: () => each((item) => item.cancel()),
290
+ period,
291
+ animations,
292
+ clock,
293
+ };
294
+ };
@@ -1 +1 @@
1
- "use strict";(()=>{var v={cdnUrl:"https://cdn.iconplease.com",apiUrl:"https://api.iconplease.com",revalidate:3600},l={...v},z=(e={})=>{if(e.apiKey&&e.apiKey.startsWith("ip_sk_"))throw new Error("iconplease: that is a secret key. init() runs in the browser, where the key is readable by anyone \u2014 use the publishable key (ip_pk_\u2026).");if(e.apiKey&&!/^ip_pk_[A-Za-z0-9]{32}$/.test(e.apiKey)&&console.warn("iconplease: that does not look like a publishable key (ip_pk_ followed by 32 characters). Set icons will not load."),e.token!==void 0&&typeof e.token!="function")throw new Error('iconplease: token must be a function that asks your server for a fresh token, e.g. () => fetch("/api/iconplease-token").then((r) => r.json()).');return l={...v,...e},l};var L=()=>{var e;return((e=l.cdnUrl)!=null?e:v.cdnUrl).replace(/\/+$/,"")},K=()=>{var e;return Math.max(0,(e=l.revalidate)!=null?e:v.revalidate)*1e3},U=()=>{var e;return((e=l.apiUrl)!=null?e:v.apiUrl).replace(/\/+$/,"")},F=()=>l.apiKey||void 0,x=()=>l.token,ce=()=>l.set;var Oe=/<\s*(script|foreignObject|iframe|object|embed|style)\b[\s\S]*?(<\s*\/\s*\1\s*>|\/>)/gi,Ne=/\s+on[a-z]+\s*=\s*("[^"]*"|'[^']*'|[^\s>]+)/gi,$e=/\s+(?:xlink:)?href\s*=\s*("\s*javascript:[^"]*"|'\s*javascript:[^']*')/gi,Pe=/^[a-z][a-z0-9-]*$/,De=/^[^"<>]*$/,je=e=>e.replace(Oe,"").replace(Ne,"").replace($e,""),J=e=>{var o;if(!e||typeof e!="object")return;let t=e;if(typeof t.body!="string"||typeof t.viewBox!="string"||!/^[0-9.\s-]+$/.test(t.viewBox))return;let n={};for(let[r,s]of Object.entries((o=t.attrs)!=null?o:{}))Pe.test(r)&&!r.startsWith("on")&&typeof s=="string"&&De.test(s)&&(n[r]=s);return{viewBox:t.viewBox,attrs:n,body:je(t.body)}};var pe="iconplease:index:v2",ge="iconplease:icons:v2",me="iconplease:set:v1",Ce=1e3,O=/^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/,c={status:"idle",revision:0},T=0,P,ae=!1,de=!1,q,y=new Map,h=new Map,H,E=0,b=!1,I,G=!1,V=new Map,w=null,W=0,_e=6e4,A,j=null,Y=new Map,C=new Map,Te=()=>{let e=ce();if(e!==A&&(A=e,Y.clear(),C.clear(),j=null,!(!e||e.format!==1||typeof e.icons!="object"))){j=typeof e.version=="number"?e.version:null;for(let[t,n]of Object.entries(e.icons)){if(!O.test(t)||typeof(n==null?void 0:n.svg)!="string")continue;let o=M(n.svg);o&&(n.source==="public"?C:Y).set(t,o)}}},Me=()=>w!==null&&(j===null||w>j),m=e=>{var t,n;return A?Me()?(t=h.get(e))!=null?t:C.get(e):(n=Y.get(e))!=null?n:C.get(e):h.get(e)};var X=new Set,N=()=>{try{return typeof localStorage=="undefined"?void 0:localStorage}catch{return}},p=(e={})=>{c={...c,...e,revision:c.revision+1};for(let t of X)t()},_=(e,t)=>`${e}@${t}`,ye=e=>{if(!e||typeof e!="object")return;let t=e;if(t.format!==2||typeof t.hash!="string"||!t.icons||typeof t.icons!="object")return;let n=Object.entries(t.icons).filter(([o,r])=>O.test(o)&&Number.isInteger(r)&&r>0);return{format:2,hash:t.hash,icons:Object.fromEntries(n)}},Re=e=>e.slice(0,14),$=()=>{if(x())return"token";let e=F();return e?Re(e):void 0},Be=6e4,ze=9*6e4,D,S,Le=(e=!1)=>{let t=x();return t?!e&&D&&D.expiresAt-Be>Date.now()?Promise.resolve(D.token):S||(S=t().then(n=>{let o=typeof n=="string"?n:n==null?void 0:n.token;if(typeof o!="string"||!o.startsWith("ipt_"))throw new Error("your token function did not return an iconplease token (ipt_\u2026).");let r=typeof n=="string"?void 0:n.expiresAt,s=typeof r=="number"?r:r?Date.parse(r):NaN;return D={token:o,expiresAt:Number.isFinite(s)?s:Date.now()+ze},o}).finally(()=>{S=void 0}),S):Promise.reject(new Error("no token source"))},Ke=()=>{var t,n,o;let e=$();if(e!==H&&(H=e,h.clear(),E=0,b=!1,I=void 0,G=!1,w=null,W=0,!!e))try{if(e==="token")return;let r=JSON.parse((n=(t=N())==null?void 0:t.getItem(me))!=null?n:"null");if(!r||r.tag!==e)return;for(let[s,i]of Object.entries((o=r.icons)!=null?o:{})){let u=O.test(s)&&typeof(i==null?void 0:i.svg)=="string"?M(i.svg):void 0;u&&h.set(s,u)}E=typeof r.checkedAt=="number"?r.checkedAt:0,w=typeof r.version=="number"?r.version:null,b=!0}catch{return}},g=()=>{var t,n;if(Te(),Ke(),ae)return;ae=!0;let e=N();if(e){try{let o=JSON.parse((t=e.getItem(pe))!=null?t:"null"),r=ye(o==null?void 0:o.index);r&&(c={status:"ready",index:r,revision:c.revision},T=typeof(o==null?void 0:o.checkedAt)=="number"?o.checkedAt:0)}catch{return}try{let o=JSON.parse((n=e.getItem(ge))!=null?n:"{}");for(let[r,s]of Object.entries(o)){let i=J(s);i&&y.set(r,i)}}catch{return}}},ue=()=>{var e;try{(e=N())==null||e.setItem(pe,JSON.stringify({index:c.index,checkedAt:T}))}catch{return}},he=()=>{q||(q=setTimeout(()=>{var n,o,r;q=void 0;let e=(o=(n=c.index)==null?void 0:n.icons)!=null?o:{},t=[...y.entries()].filter(([s])=>{let i=s.lastIndexOf("@");return e[s.slice(0,i)]===Number(s.slice(i+1))});try{(r=N())==null||r.setItem(ge,JSON.stringify(Object.fromEntries(t.slice(-Ce))))}catch{return}},0))},fe=async e=>{let t=await fetch(e);if(!t.ok)throw new Error(`${t.status} for ${e}`);return t.json()},be=e=>{de||(de=!0,console.warn("iconplease: could not reach the icon CDN.",e))},Ue=async()=>{var r;let e=L(),t=await fe(`${e}/catalogue/latest.json`);if((t==null?void 0:t.format)!==2||typeof t.hash!="string"||typeof t.index!="string")throw new Error("iconplease: the catalogue pointer is malformed");if(T=Date.now(),((r=c.index)==null?void 0:r.hash)===t.hash){ue();return}let n=t.index.replace(/^\/+/,"");if(!/^catalogue\/index-[a-z0-9]+\.json$/.test(n))throw new Error("iconplease: unexpected index location");let o=ye(await fe(`${e}/${n}`));if(!o)throw new Error("iconplease: the icon index is malformed");p({status:"ready",index:o}),ue(),he()},Z=(e={})=>{if(g(),c.index&&Date.now()-T<K()&&!e.force)return Promise.resolve();if(P)return P;let n=Ue().catch(o=>{c.index||p({status:"error"}),be(o)}).finally(()=>{P=void 0});return P=n,!c.index&&c.status!=="loading"&&p({status:"loading"}),n},M=e=>{let t=/<svg\b([^>]*)>([\s\S]*)<\/svg>\s*$/.exec(e.trim());if(!t)return;let n={},o="0 0 24 24";for(let[,r,s]of t[1].matchAll(/([a-zA-Z:-]+)="([^"]*)"/g))r==="viewBox"?o=s:["xmlns","width","height","aria-hidden","role","class","style"].includes(r)||(n[r]=s);return J({viewBox:o,attrs:n,body:t[2]})},Fe=(e,t)=>{let n=_(e,t),o=V.get(n);if(o)return o;let r=fetch(`${L()}/v${t}/${e}.svg`).then(async s=>{if(!s.ok)throw new Error(`${s.status} for ${e}`);let i=M(await s.text());if(!i)throw new Error(`iconplease: "${e}" is not a valid SVG`);y.set(n,i),he(),p()}).catch(be).finally(()=>{V.delete(n)});return V.set(n,r),r},le=async(e=!1)=>{var n;if(!x()){let o=(n=F())!=null?n:"";return fetch(`${U()}/sdk/set?key=${encodeURIComponent(o)}`)}let t=await Le(e);return fetch(`${U()}/sdk/set`,{headers:{Authorization:`Bearer ${t}`}})},Je=async e=>{var s,i;let t=await le();t.status===401&&x()&&(t=await le(!0));let n=await t.json().catch(()=>({}));if(!t.ok)throw new Error(n.error||`HTTP ${t.status}`);let o=new Map,r={};for(let[u,d]of Object.entries((s=n.icons)!=null?s:{})){if(!O.test(u)||typeof(d==null?void 0:d.svg)!="string")continue;let f=M(d.svg);f&&(o.set(u,f),r[u]={version:Number(d.version)||1,svg:d.svg})}if(e===H){h.clear();for(let[u,d]of o)h.set(u,d);E=Date.now(),b=!0,w=typeof n.version=="number"?n.version:null;try{e!=="token"&&((i=N())==null||i.setItem(me,JSON.stringify({tag:e,checkedAt:E,version:w,icons:r})))}catch{p();return}p()}},Q=(e={})=>{g();let t=$();if(!t||b&&Date.now()-E<K()&&!e.force||!e.force&&Date.now()<W)return Promise.resolve();if(I)return I;let o=Je(t).catch(r=>{b=!0,W=Date.now()+_e,G||(G=!0,console.warn(`iconplease: could not load your icon set \u2014 ${r instanceof Error?r.message:String(r)} Falling back to public icons.`)),p()}).finally(()=>{I=void 0});return I=o,o},ee=async e=>{var o,r;if(!O.test(e))return;if(g(),$()){if(m(e)){Q();return}if(await Q(),m(e))return}else if(m(e))return;let t=(o=c.index)==null?void 0:o.icons[e];if(t&&y.has(_(e,t))){Z();return}await Z();let n=(r=c.index)==null?void 0:r.icons[e];n&&!y.has(_(e,n))&&await Fe(e,n)},te=async(e={})=>{let{icons:t=[],force:n=!1}=Array.isArray(e)?{icons:e}:e;g(),!(A&&!$()&&t.every(r=>m(r)))&&(await Promise.all([A?Promise.resolve():Z({force:n}),Q({force:n})]),await Promise.all(t.map(ee)))},we=e=>(g(),X.add(e),()=>X.delete(e));var R=e=>{var o;g();let t=m(e);if(t)return t;let n=(o=c.index)==null?void 0:o.icons[e];return n?y.get(_(e,n)):void 0},ke=e=>(g(),m(e)||$()&&!b?!1:c.status==="ready"&&!!c.index&&!(e in c.index.icons));var qe=/^[#a-zA-Z0-9(),.%\s-]{1,64}$/,Ve=/[<>"&]/g,He={"<":"&lt;",">":"&gt;",'"':"&quot;","&":"&amp;"},Ge=e=>e.replace(Ve,t=>He[t]),ve=e=>String(Number(e.toFixed(3))),We=(e,t)=>e.replace(/\b(fill|stroke)="currentColor"/g,`$1="${t}"`),Ye=(e,t)=>e.replace(/\bstroke-width="([0-9]*\.?[0-9]+)"/g,(n,o)=>`stroke-width="${ve(Number(o)*t)}"`),ne=(e,t={})=>{var se;let{size:n=24,color:o,strokeScale:r,motion:s,label:i,className:u}=t,d=o&&qe.test(o)?o:void 0,f=typeof r=="number"&&Number.isFinite(r)&&r>0&&r!==1?r:void 0,a={...(se=e.attrs)!=null?se:{}};if(d)for(let ie of["fill","stroke"])a[ie]==="currentColor"&&(a[ie]=d);f&&a["stroke-width"]&&(a["stroke-width"]=ve(Number(a["stroke-width"])*f));let k=e.body;return d&&(k=We(k,d)),f&&(k=Ye(k,f)),a.width=String(n),a.height=String(n),a.viewBox=e.viewBox,s&&s!=="none"&&(a["data-motion"]=s),i?(a.role="img",a["aria-label"]=i):a["aria-hidden"]="true",u&&(a.class=u),{attrs:a,body:k}},oe=({attrs:e,body:t})=>`<svg xmlns="http://www.w3.org/2000/svg" ${Object.entries(e).map(([o,r])=>`${o}="${Ge(r)}"`).join(" ")}>${t}</svg>`,xe=(e,t={})=>{let n=typeof e=="string"?R(e):e;return n?oe(ne(n,t)):void 0};var Se="[data-icon], i.ip[class*='ip-']",Xe=new Set(["none","wiggle","pop","bounce","draw"]),Ie=new Set,Ze=e=>{let t=e.getAttribute("data-icon");if(t)return t;for(let n of Array.from(e.classList))if(n.startsWith("ip-")&&n.length>3)return n.slice(3)},Ee=e=>{if(e===null)return;let t=Number(e);return Number.isFinite(t)&&t>0?t:void 0},re=e=>{var u,d,f,a;let t=Ze(e);if(!t)return;let n=R(t),o=e.getAttribute("data-motion"),r=o&&Xe.has(o)?o:void 0,s={size:(u=Ee(e.getAttribute("data-size")))!=null?u:24,color:(d=e.getAttribute("data-color"))!=null?d:void 0,strokeScale:Ee(e.getAttribute("data-stroke")),motion:r,label:(f=e.getAttribute("data-label"))!=null?f:void 0},i=JSON.stringify([t,s,n?"1":"0"]);if(e.getAttribute("data-ip-rendered")!==i){if(!n){ke(t)?Ie.has(t)||(Ie.add(t),console.warn(`iconplease: no icon named "${t}".`)):ee(t);return}e.innerHTML=oe(ne(n,s)),e.setAttribute("data-ip-rendered",i),e.tagName==="I"&&((a=e.style).display||(a.display="inline-flex"))}},B=(e=document)=>{e instanceof Element&&e.matches(Se)&&re(e),e.querySelectorAll(Se).forEach(re)},Ae=()=>{let e=window.iconpleaseConfig;e&&z(e),we(()=>B()),B(),te(),new MutationObserver(t=>{for(let n of t)n.type==="attributes"&&n.target instanceof Element&&re(n.target),n.addedNodes.forEach(o=>{o instanceof Element&&B(o)})}).observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-icon","data-size","data-color","data-stroke","data-motion","data-label","class"]})};window.iconplease={init:z,load:te,renderSVG:xe,refresh:()=>B()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Ae,{once:!0}):Ae();})();
1
+ "use strict";(()=>{var $={cdnUrl:"https://cdn.iconplease.com",apiUrl:"https://api.iconplease.com",revalidate:3600},v={...$},Q=(e={})=>{if(e.apiKey&&e.apiKey.startsWith("ip_sk_"))throw new Error("iconplease: that is a secret key. init() runs in the browser, where the key is readable by anyone \u2014 use the publishable key (ip_pk_\u2026).");if(e.apiKey&&!/^ip_pk_[A-Za-z0-9]{32}$/.test(e.apiKey)&&console.warn("iconplease: that does not look like a publishable key (ip_pk_ followed by 32 characters). Set icons will not load."),e.token!==void 0&&typeof e.token!="function")throw new Error('iconplease: token must be a function that asks your server for a fresh token, e.g. () => fetch("/api/iconplease-token").then((r) => r.json()).');return v={...$,...e},v};var ee=()=>{var e;return((e=v.cdnUrl)!=null?e:$.cdnUrl).replace(/\/+$/,"")},te=()=>{var e;return Math.max(0,(e=v.revalidate)!=null?e:$.revalidate)*1e3},ne=()=>{var e;return((e=v.apiUrl)!=null?e:$.apiUrl).replace(/\/+$/,"")},oe=()=>v.apiKey||void 0,N=()=>v.token,Ee=()=>v.set;var ot=/<\s*(script|foreignObject|iframe|object|embed|style)\b[\s\S]*?(<\s*\/\s*\1\s*>|\/>)/gi,rt=/\s+on[a-z]+\s*=\s*("[^"]*"|'[^']*'|[^\s>]+)/gi,st=/\s+(?:xlink:)?href\s*=\s*("\s*javascript:[^"]*"|'\s*javascript:[^']*')/gi,it=/^[a-z][a-z0-9-]*$/,at=/^[^"<>]*$/,ct=e=>e.replace(ot,"").replace(rt,"").replace(st,""),re=e=>{var r;if(!e||typeof e!="object")return;let t=e;if(typeof t.body!="string"||typeof t.viewBox!="string"||!/^[0-9.\s-]+$/.test(t.viewBox))return;let n={};for(let[o,s]of Object.entries((r=t.attrs)!=null?r:{}))it.test(o)&&!o.startsWith("on")&&typeof s=="string"&&at.test(s)&&(n[o]=s);return{viewBox:t.viewBox,attrs:n,body:ct(t.body)}};var Re="iconplease:index:v2",$e="iconplease:icons:v2",Ne="iconplease:set:v1",lt=1e3,j=/^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/,h={status:"idle",revision:0},q=0,z,Ie=!1,Te=!1,se,T=new Map,O=new Map,ae,C=0,P=!1,D,ce=!1,ie=new Map,M=null,le=0,ft=6e4,L,U=null,fe=new Map,Y=new Map,ut=()=>{let e=Ee();if(e!==L&&(L=e,fe.clear(),Y.clear(),U=null,!(!e||e.format!==1||typeof e.icons!="object"))){U=typeof e.version=="number"?e.version:null;for(let[t,n]of Object.entries(e.icons)){if(!j.test(t)||typeof(n==null?void 0:n.svg)!="string")continue;let r=J(n.svg);r&&(n.source==="public"?Y:fe).set(t,r)}}},dt=()=>M!==null&&(U===null||M>U),I=e=>{var t,n;return L?dt()?(t=O.get(e))!=null?t:Y.get(e):(n=fe.get(e))!=null?n:Y.get(e):O.get(e)};var ue=new Set,B=()=>{try{return typeof localStorage=="undefined"?void 0:localStorage}catch{return}},S=(e={})=>{h={...h,...e,revision:h.revision+1};for(let t of ue)t()},V=(e,t)=>`${e}@${t}`,_e=e=>{if(!e||typeof e!="object")return;let t=e;if(t.format!==2||typeof t.hash!="string"||!t.icons||typeof t.icons!="object")return;let n=Object.entries(t.icons).filter(([r,o])=>j.test(r)&&Number.isInteger(o)&&o>0);return{format:2,hash:t.hash,icons:Object.fromEntries(n)}},pt=e=>e.slice(0,14),G=()=>{if(N())return"token";let e=oe();return e?pt(e):void 0},gt=6e4,mt=9*6e4,K,_,ht=(e=!1)=>{let t=N();return t?!e&&K&&K.expiresAt-gt>Date.now()?Promise.resolve(K.token):_||(_=t().then(n=>{let r=typeof n=="string"?n:n==null?void 0:n.token;if(typeof r!="string"||!r.startsWith("ipt_"))throw new Error("your token function did not return an iconplease token (ipt_\u2026).");let o=typeof n=="string"?void 0:n.expiresAt,s=typeof o=="number"?o:o?Date.parse(o):NaN;return K={token:r,expiresAt:Number.isFinite(s)?s:Date.now()+mt},r}).finally(()=>{_=void 0}),_):Promise.reject(new Error("no token source"))},bt=()=>{var t,n,r;let e=G();if(e!==ae&&(ae=e,O.clear(),C=0,P=!1,D=void 0,ce=!1,M=null,le=0,!!e))try{if(e==="token")return;let o=JSON.parse((n=(t=B())==null?void 0:t.getItem(Ne))!=null?n:"null");if(!o||o.tag!==e)return;for(let[s,c]of Object.entries((r=o.icons)!=null?r:{})){let u=j.test(s)&&typeof(c==null?void 0:c.svg)=="string"?J(c.svg):void 0;u&&O.set(s,u)}C=typeof o.checkedAt=="number"?o.checkedAt:0,M=typeof o.version=="number"?o.version:null,P=!0}catch{return}},E=()=>{var t,n;if(ut(),bt(),Ie)return;Ie=!0;let e=B();if(e){try{let r=JSON.parse((t=e.getItem(Re))!=null?t:"null"),o=_e(r==null?void 0:r.index);o&&(h={status:"ready",index:o,revision:h.revision},q=typeof(r==null?void 0:r.checkedAt)=="number"?r.checkedAt:0)}catch{return}try{let r=JSON.parse((n=e.getItem($e))!=null?n:"{}");for(let[o,s]of Object.entries(r)){let c=re(s);c&&T.set(o,c)}}catch{return}}},Oe=()=>{var e;try{(e=B())==null||e.setItem(Re,JSON.stringify({index:h.index,checkedAt:q}))}catch{return}},De=()=>{se||(se=setTimeout(()=>{var n,r,o;se=void 0;let e=(r=(n=h.index)==null?void 0:n.icons)!=null?r:{},t=[...T.entries()].filter(([s])=>{let c=s.lastIndexOf("@");return e[s.slice(0,c)]===Number(s.slice(c+1))});try{(o=B())==null||o.setItem($e,JSON.stringify(Object.fromEntries(t.slice(-lt))))}catch{return}},0))},Pe=async e=>{let t=await fetch(e);if(!t.ok)throw new Error(`${t.status} for ${e}`);return t.json()},Ce=e=>{Te||(Te=!0,console.warn("iconplease: could not reach the icon CDN.",e))},yt=async()=>{var o;let e=ee(),t=await Pe(`${e}/catalogue/latest.json`);if((t==null?void 0:t.format)!==2||typeof t.hash!="string"||typeof t.index!="string")throw new Error("iconplease: the catalogue pointer is malformed");if(q=Date.now(),((o=h.index)==null?void 0:o.hash)===t.hash){Oe();return}let n=t.index.replace(/^\/+/,"");if(!/^catalogue\/index-[a-z0-9]+\.json$/.test(n))throw new Error("iconplease: unexpected index location");let r=_e(await Pe(`${e}/${n}`));if(!r)throw new Error("iconplease: the icon index is malformed");S({status:"ready",index:r}),Oe(),De()},de=(e={})=>{if(E(),h.index&&Date.now()-q<te()&&!e.force)return Promise.resolve();if(z)return z;let n=yt().catch(r=>{h.index||S({status:"error"}),Ce(r)}).finally(()=>{z=void 0});return z=n,!h.index&&h.status!=="loading"&&S({status:"loading"}),n},J=e=>{let t=/<svg\b([^>]*)>([\s\S]*)<\/svg>\s*$/.exec(e.trim());if(!t)return;let n={},r="0 0 24 24";for(let[,o,s]of t[1].matchAll(/([a-zA-Z:-]+)="([^"]*)"/g))o==="viewBox"?r=s:["xmlns","width","height","aria-hidden","role","class","style"].includes(o)||(n[o]=s);return re({viewBox:r,attrs:n,body:t[2]})},xt=(e,t)=>{let n=V(e,t),r=ie.get(n);if(r)return r;let o=fetch(`${ee()}/v${t}/${e}.svg`).then(async s=>{if(!s.ok)throw new Error(`${s.status} for ${e}`);let c=J(await s.text());if(!c)throw new Error(`iconplease: "${e}" is not a valid SVG`);T.set(n,c),De(),S()}).catch(Ce).finally(()=>{ie.delete(n)});return ie.set(n,o),o},Me=async(e=!1)=>{var n;if(!N()){let r=(n=oe())!=null?n:"";return fetch(`${ne()}/sdk/set?key=${encodeURIComponent(r)}`)}let t=await ht(e);return fetch(`${ne()}/sdk/set`,{headers:{Authorization:`Bearer ${t}`}})},wt=async e=>{var s,c;let t=await Me();t.status===401&&N()&&(t=await Me(!0));let n=await t.json().catch(()=>({}));if(!t.ok)throw new Error(n.error||`HTTP ${t.status}`);let r=new Map,o={};for(let[u,l]of Object.entries((s=n.icons)!=null?s:{})){if(!j.test(u)||typeof(l==null?void 0:l.svg)!="string")continue;let p=J(l.svg);p&&(r.set(u,p),o[u]={version:Number(l.version)||1,svg:l.svg})}if(e===ae){O.clear();for(let[u,l]of r)O.set(u,l);C=Date.now(),P=!0,M=typeof n.version=="number"?n.version:null;try{e!=="token"&&((c=B())==null||c.setItem(Ne,JSON.stringify({tag:e,checkedAt:C,version:M,icons:o})))}catch{S();return}S()}},pe=(e={})=>{E();let t=G();if(!t||P&&Date.now()-C<te()&&!e.force||!e.force&&Date.now()<le)return Promise.resolve();if(D)return D;let r=wt(t).catch(o=>{P=!0,le=Date.now()+ft,ce||(ce=!0,console.warn(`iconplease: could not load your icon set \u2014 ${o instanceof Error?o.message:String(o)} Falling back to public icons.`)),S()}).finally(()=>{D=void 0});return D=r,r},ge=async e=>{var r,o;if(!j.test(e))return;if(E(),G()){if(I(e)){pe();return}if(await pe(),I(e))return}else if(I(e))return;let t=(r=h.index)==null?void 0:r.icons[e];if(t&&T.has(V(e,t))){de();return}await de();let n=(o=h.index)==null?void 0:o.icons[e];n&&!T.has(V(e,n))&&await xt(e,n)},me=async(e={})=>{let{icons:t=[],force:n=!1}=Array.isArray(e)?{icons:e}:e;E(),!(L&&!G()&&t.every(o=>I(o)))&&(await Promise.all([L?Promise.resolve():de({force:n}),pe({force:n})]),await Promise.all(t.map(ge)))},Le=e=>(E(),ue.add(e),()=>ue.delete(e));var H=e=>{var r;E();let t=I(e);if(t)return t;let n=(r=h.index)==null?void 0:r.icons[e];return n?T.get(V(e,n)):void 0},je=e=>(E(),I(e)||G()&&!P?!1:h.status==="ready"&&!!h.index&&!(e in h.index.icons));var kt=/^[#a-zA-Z0-9(),.%\s-]{1,64}$/,vt=/[<>"&]/g,At={"<":"&lt;",">":"&gt;",'"':"&quot;","&":"&amp;"},St=e=>e.replace(vt,t=>At[t]),Be=e=>String(Number(e.toFixed(3))),Et=(e,t)=>e.replace(/\b(fill|stroke)="currentColor"/g,`$1="${t}"`),It=(e,t)=>e.replace(/\bstroke-width="([0-9]*\.?[0-9]+)"/g,(n,r)=>`stroke-width="${Be(Number(r)*t)}"`),he=(e,t={})=>{var y;let{size:n=24,color:r,strokeScale:o,motion:s,label:c,className:u}=t,l=r&&kt.test(r)?r:void 0,p=typeof o=="number"&&Number.isFinite(o)&&o>0&&o!==1?o:void 0,f={...(y=e.attrs)!=null?y:{}};if(l)for(let b of["fill","stroke"])f[b]==="currentColor"&&(f[b]=l);p&&f["stroke-width"]&&(f["stroke-width"]=Be(Number(f["stroke-width"])*p));let d=e.body;return l&&(d=Et(d,l)),p&&(d=It(d,p)),f.width=String(n),f.height=String(n),f.viewBox=e.viewBox,s&&s!=="none"&&(f["data-motion"]=s),c?(f.role="img",f["aria-label"]=c):f["aria-hidden"]="true",u&&(f.class=u),{attrs:f,body:d}},be=({attrs:e,body:t})=>`<svg xmlns="http://www.w3.org/2000/svg" ${Object.entries(e).map(([r,o])=>`${r}="${St(o)}"`).join(" ")}>${t}</svg>`,Ge=(e,t={})=>{let n=typeof e=="string"?H(e):e;return n?be(he(n,t)):void 0};var R={draw:{label:"Draw on",hint:"Strokes draw themselves",duration:700,easing:"ease-in-out",draw:!0},fade:{label:"Fade in",hint:"From invisible to visible",duration:400,easing:"ease-out",frames:[{offset:0,opacity:0},{offset:1,opacity:1}]},pop:{label:"Pop in",hint:"Grows from nothing with a little overshoot",duration:450,easing:"spring",frames:[{offset:0,transform:"scale(0)"},{offset:1,transform:"scale(1)"}]},spin:{label:"Spin",hint:"One full turn",duration:800,easing:"ease-in-out",frames:[{offset:0,transform:"rotate(0deg)"},{offset:1,transform:"rotate(360deg)"}]},"slide-up":{label:"Slide up",hint:"Rises into place",duration:450,easing:"ease-out",frames:[{offset:0,transform:"translateY(4px)",opacity:0},{offset:1,transform:"translateY(0px)",opacity:1}]},"slide-down":{label:"Slide down",hint:"Drops into place",duration:450,easing:"ease-out",frames:[{offset:0,transform:"translateY(-4px)",opacity:0},{offset:1,transform:"translateY(0px)",opacity:1}]},"slide-left":{label:"Slide left",hint:"Comes in from the right",duration:450,easing:"ease-out",frames:[{offset:0,transform:"translateX(4px)",opacity:0},{offset:1,transform:"translateX(0px)",opacity:1}]},"slide-right":{label:"Slide right",hint:"Comes in from the left",duration:450,easing:"ease-out",frames:[{offset:0,transform:"translateX(-4px)",opacity:0},{offset:1,transform:"translateX(0px)",opacity:1}]},bounce:{label:"Bounce",hint:"Hops up and lands",duration:700,easing:"ease-out",frames:[{offset:0,transform:"translateY(0px)"},{offset:.35,transform:"translateY(-4px)"},{offset:.65,transform:"translateY(0px)"},{offset:.82,transform:"translateY(-1.5px)"},{offset:1,transform:"translateY(0px)"}]},pulse:{label:"Pulse",hint:"Swells and settles",duration:600,easing:"ease-in-out",frames:[{offset:0,transform:"scale(1)"},{offset:.5,transform:"scale(1.18)"},{offset:1,transform:"scale(1)"}]},"spin-back":{label:"Spin back",hint:"One full turn, anticlockwise",duration:800,easing:"ease-in-out",frames:[{offset:0,transform:"rotate(0deg)"},{offset:1,transform:"rotate(-360deg)"}]},"fade-out":{label:"Fade out",hint:"From visible to invisible",duration:400,easing:"ease-in",frames:[{offset:0,opacity:1},{offset:1,opacity:0}]},"pop-out":{label:"Pop out",hint:"Shrinks away to nothing",duration:350,easing:"ease-in",frames:[{offset:0,transform:"scale(1)"},{offset:1,transform:"scale(0)"}]},"slide-out-up":{label:"Slide out up",hint:"Rises and fades away",duration:400,easing:"ease-in",frames:[{offset:0,transform:"translateY(0px)",opacity:1},{offset:1,transform:"translateY(-4px)",opacity:0}]},"slide-out-down":{label:"Slide out down",hint:"Drops and fades away",duration:400,easing:"ease-in",frames:[{offset:0,transform:"translateY(0px)",opacity:1},{offset:1,transform:"translateY(4px)",opacity:0}]},follow:{label:"Move along path",hint:"The shape's centre travels along a route you drew",duration:1200,easing:"ease-in-out",route:!0},shake:{label:"Shake",hint:"A quick wobble",duration:600,easing:"ease-in-out",frames:[{offset:0,transform:"rotate(0deg)"},{offset:.2,transform:"rotate(-14deg)"},{offset:.4,transform:"rotate(12deg)"},{offset:.6,transform:"rotate(-8deg)"},{offset:.8,transform:"rotate(4deg)"},{offset:1,transform:"rotate(0deg)"}]}},Jt=Object.keys(R).filter(e=>!R[e].route),Tt=/^[MmLlHhVvCcSsQqTtAaZz0-9eE.,\s+-]{1,8000}$/,Ke={linear:{label:"Linear",css:"linear"},"ease-in":{label:"Ease in",css:"cubic-bezier(0.4, 0, 1, 1)"},"ease-out":{label:"Ease out",css:"cubic-bezier(0, 0, 0.2, 1)"},"ease-in-out":{label:"Ease in-out",css:"cubic-bezier(0.4, 0, 0.2, 1)"},spring:{label:"Spring",css:"cubic-bezier(0.34, 1.56, 0.64, 1)"}},Ot={load:"When it appears",hover:"On hover",click:"On click",toggle:"Click to toggle",visible:"When scrolled into view"},Pt=64,ye=1e4,Ue=50,Mt=new Set(Object.keys(R)),Fe=/^[A-Za-z0-9_-]{1,64}$/,xe=(e,t,n)=>typeof e=="number"&&Number.isFinite(e)?Math.round(Math.min(Math.max(e,t),n)):void 0,Rt=e=>{var r;if(!e||typeof e!="object")return;let t=e,n=[];for(let o of Array.isArray(t.clips)?t.clips.slice(0,Pt):[]){if(!o||typeof o!="object")continue;let s=xe(o.start,0,ye),c=xe(o.duration,Ue,ye);if(typeof o.id!="string"||!Fe.test(o.id)||typeof o.target!="string"||!Fe.test(o.target)||!Mt.has(o.preset)||s===void 0||c===void 0)continue;let u=R[o.preset].route;u&&(typeof o.path!="string"||!Tt.test(o.path)||!/^\s*[Mm]/.test(o.path))||n.push({id:o.id,target:o.target,preset:o.preset,start:s,duration:c,easing:o.easing&&o.easing in Ke?o.easing:R[o.preset].easing,...u?{path:o.path,orient:o.orient===!0}:{}})}if(n.length)return{version:1,trigger:t.trigger&&t.trigger in Ot?t.trigger:"load",loop:t.loop===!0,loopGap:(r=xe(t.loopGap,0,ye))!=null?r:0,...t.reverse===!0?{reverse:!0}:{},clips:n}},ke="data-ip-animation",Ye="data-ip";var $t=e=>atob(e.replace(/-/g,"+").replace(/_/g,"/"));var Ve=e=>{if(!(!e||e.length>6e4||!/^[A-Za-z0-9_-]+$/.test(e)))try{return Rt(JSON.parse($t(e)))}catch{return}},Nt=e=>e.clips.reduce((t,n)=>Math.max(t,n.start+n.duration),0),_t="path, line, rect, ellipse, circle, polyline, polygon",Dt=e=>[...e.querySelectorAll(_t)].filter(t=>{var r;if(t.closest("defs, clipPath, mask"))return!1;let n=(r=t.getAttribute("stroke"))!=null?r:getComputedStyle(t).stroke;return!!n&&n!=="none"&&n!=="transparent"&&typeof t.getTotalLength=="function"}),Ct="http://www.w3.org/2000/svg",we=48,Lt=(e,t,n)=>{var s;let r=(s=e.ownerSVGElement)!=null?s:e.closest("svg");if(!r||typeof e.getBBox!="function")return[];let o=document.createElementNS(Ct,"path");o.setAttribute("d",t),o.setAttribute("visibility","hidden"),r.appendChild(o);try{let c=o.getTotalLength(),u=e.getBBox(),l=u.x+u.width/2,p=u.y+u.height/2,f=x=>o.getPointAtLength(Math.min(Math.max(x,0),c)),d=x=>{let i=Math.max(c/400,.01),a=f(x-i),m=f(x+i);return Math.atan2(m.y-a.y,m.x-a.x)*180/Math.PI},y=d(0),b=0;return Array.from({length:we+1},(x,i)=>{let a=i/we*c,m=f(a),g=d(a)-y;for(;g-b>180;)g-=360;for(;g-b<-180;)g+=360;b=g;let w=`translate(${(m.x-l).toFixed(3)}px, ${(m.y-p).toFixed(3)}px)`;return{offset:i/we,transform:n?`${w} rotate(${g.toFixed(2)}deg)`:w}})}finally{o.remove()}},ze=(e,t,n,r,o=0)=>{let s=(t.start+o)/n,c=(t.start+o+t.duration)/n,u=Ke[t.easing].css,l=e.map((y,b)=>({...y,offset:s+y.offset*(c-s),easing:b<e.length-1?u:"linear"})),p={...r!=null?r:e[0],offset:0,easing:"linear"},f={...e[e.length-1],offset:1,easing:"linear"},d=[];return l[0].offset>0&&(d.push(p),r&&d.push({...r,offset:l[0].offset,easing:"linear"})),d.push(...l),l[l.length-1].offset<1&&d.push(f),d},qe=(e,t,n={})=>{var y,b,x;let r=Math.max(Nt(e),Ue),o=(y=n.loop)!=null?y:e.loop,s=o?r+e.loopGap:r,c=o&&e.reverse===!0,u=c?e.loopGap/2:0,l=[],p={duration:s,iterations:o?1/0:1,fill:"both",direction:c?"alternate":"normal"};for(let i of e.clips){let a=R[i.preset],m=e.clips.some(g=>g.target===i.target&&g.start<i.start);for(let g of t(i.target)){if(a.draw){for(let k of Dt(g)){let A=Math.max(k.getTotalLength(),.01),tt=[{offset:0,strokeDasharray:`${A} ${A}`,strokeDashoffset:A},{offset:1,strokeDasharray:`${A} ${A}`,strokeDashoffset:0}],nt=m?{offset:0,strokeDasharray:`${A} ${A}`,strokeDashoffset:0}:void 0;l.push(k.animate(ze(tt,i,s,nt,u),p))}continue}let w=g;w.style.transformBox="fill-box",w.style.transformOrigin="center";let F=a.route?Lt(g,(b=i.path)!=null?b:"",i.orient===!0):((x=a.frames)!=null?x:[]).map(k=>({...k}));if(!F.length)continue;let Se=F.some(k=>k.transform!==void 0),Qe=F.some(k=>k.opacity!==void 0),et=m?{offset:0,...Se?{transform:"translate(0px, 0px)"}:{},...Qe?{opacity:1}:{}}:void 0;l.push(w.animate(ze(F,i,s,et,u),{...p,composite:Se?"add":"replace"}))}}let f=i=>l.forEach(i),d=i=>{if(!o)return Math.min(i,r);let a=Math.floor(i/s),m=i-a*s,g=c&&a%2===1?s-m:m;return Math.min(r,Math.max(0,g-u))};return n.paused&&f(i=>i.pause()),{play:()=>f(i=>i.play()),pause:()=>f(i=>i.pause()),reverse:i=>{var g;let a=l[0];if(!a)return i==null?void 0:i();let m=d(Number((g=a.currentTime)!=null?g:0))+u;if(m<=1)return i==null?void 0:i();try{f(w=>{w.currentTime=m,w.playbackRate=-1,w.play()})}catch{return i==null?void 0:i()}a.onfinish=()=>{a.onfinish=null,i==null||i()}},forward:()=>{l[0]&&(l[0].onfinish=null),f(i=>i.playbackRate=1),f(i=>i.play())},seek:i=>f(a=>a.currentTime=Math.max(0,i+u)),cancel:()=>f(i=>i.cancel()),period:s,animations:l,clock:d}};var X=new WeakMap,jt=()=>typeof matchMedia=="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches,ve=e=>{var t,n;return(n=(t=e.closest("a, button, [role=button], label, summary"))!=null?t:e.parentElement)!=null?n:e},W=(e,t={})=>{var b,x,i;(b=X.get(e))==null||b();let n=Ve(e.getAttribute(ke));if(!n||typeof e.animate!="function")return()=>{};if((x=t.reducedMotion)!=null?x:jt())return()=>{};let r=(i=t.trigger)!=null?i:n.trigger,o=a=>[...e.querySelectorAll(`[${Ye}="${a}"]`)],s,c=[],u=()=>{s==null||s.cancel(),s=void 0},l=()=>{u(),s=qe(n,o)};r==="load"&&l();let p=!1,f=()=>{if(s&&p){p=!1,s.forward();return}s||l()},d=()=>{s&&(p=!0,s.reverse(()=>{p&&(p=!1,u())}))};if(r==="hover"){let a=ve(e);a.addEventListener("pointerenter",f),a.addEventListener("pointerleave",d),a.addEventListener("focusin",f),a.addEventListener("focusout",d),c.push(()=>{a.removeEventListener("pointerenter",f),a.removeEventListener("pointerleave",d),a.removeEventListener("focusin",f),a.removeEventListener("focusout",d)})}if(r==="toggle"){let a=ve(e),m=!1,g=()=>{m=!m,m?f():d()};a.addEventListener("click",g),c.push(()=>a.removeEventListener("click",g))}if(r==="click"){let a=ve(e);a.addEventListener("click",l),c.push(()=>a.removeEventListener("click",l))}if(r==="visible")if(typeof IntersectionObserver=="function"){let a=new IntersectionObserver(m=>{m.some(g=>g.isIntersecting)&&(a.disconnect(),l())},{threshold:.5});a.observe(e),c.push(()=>a.disconnect())}else l();let y=()=>{u(),c.forEach(a=>a()),X.delete(e)};return X.set(e,y),y},Je=(e=document)=>{e.querySelectorAll(`svg[${ke}]`).forEach(t=>{X.has(t)||W(t)})};var He="[data-icon], i.ip[class*='ip-']",Bt=new Set(["none","wiggle","pop","bounce","draw"]),Xe=new Set,Gt=e=>{let t=e.getAttribute("data-icon");if(t)return t;for(let n of Array.from(e.classList))if(n.startsWith("ip-")&&n.length>3)return n.slice(3)},We=e=>{if(e===null)return;let t=Number(e);return Number.isFinite(t)&&t>0?t:void 0},Ae=e=>{var l,p,f,d;let t=Gt(e);if(!t)return;let n=H(t),r=e.getAttribute("data-motion"),o=r&&Bt.has(r)?r:void 0,s={size:(l=We(e.getAttribute("data-size")))!=null?l:24,color:(p=e.getAttribute("data-color"))!=null?p:void 0,strokeScale:We(e.getAttribute("data-stroke")),motion:o,label:(f=e.getAttribute("data-label"))!=null?f:void 0},c=JSON.stringify([t,s,n?"1":"0"]);if(e.getAttribute("data-ip-rendered")===c)return;if(!n){je(t)?Xe.has(t)||(Xe.add(t),console.warn(`iconplease: no icon named "${t}".`)):ge(t);return}e.innerHTML=be(he(n,s)),e.setAttribute("data-ip-rendered",c);let u=e.querySelector("svg");u&&W(u),e.tagName==="I"&&((d=e.style).display||(d.display="inline-flex"))},Z=(e=document)=>{e instanceof Element&&e.matches(He)&&Ae(e),e.querySelectorAll(He).forEach(Ae)},Ze=()=>{let e=window.iconpleaseConfig;e&&Q(e),Le(()=>Z()),Z(),me(),new MutationObserver(t=>{for(let n of t)n.type==="attributes"&&n.target instanceof Element&&Ae(n.target),n.addedNodes.forEach(r=>{r instanceof Element&&Z(r)})}).observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-icon","data-size","data-color","data-stroke","data-motion","data-label","class"]})};window.iconplease={init:Q,load:me,renderSVG:Ge,attachAnimation:W,attachAll:Je,refresh:()=>Z()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Ze,{once:!0}):Ze();})();
package/dist/index.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  export { init, getConfig } from "./config.js";
2
2
  export { load, loadSet, requestIcon, subscribe, getIcon, getStatus, iconNames, setIconNames, isUnknown, bundledIcon } from "./store.js";
3
3
  export { renderSVG, prepare } from "./render.js";
4
+ export { attachAnimation, attachAll } from "./player.js";
5
+ export { decodeAnimation, encodeAnimation, cleanAnimation, PRESETS } from "./animation.js";
6
+ export type { IconAnimation, AnimationClip, AnimationPreset, AnimationTrigger } from "./animation.js";
4
7
  export type { RenderOptions, Prepared } from "./render.js";
5
8
  export type { LoadOptions } from "./store.js";
6
9
  export type { Config, IconData, IconIndex, IconMotion, Status, BundledSet, BundledIcon, TokenSource } from "./types.js";
package/dist/index.js CHANGED
@@ -1,3 +1,5 @@
1
1
  export { init, getConfig } from "./config.js";
2
2
  export { load, loadSet, requestIcon, subscribe, getIcon, getStatus, iconNames, setIconNames, isUnknown, bundledIcon } from "./store.js";
3
3
  export { renderSVG, prepare } from "./render.js";
4
+ export { attachAnimation, attachAll } from "./player.js";
5
+ export { decodeAnimation, encodeAnimation, cleanAnimation, PRESETS } from "./animation.js";
@@ -0,0 +1,7 @@
1
+ import { type IconAnimation } from "./animation.js";
2
+ export type AttachOptions = {
3
+ trigger?: IconAnimation["trigger"];
4
+ reducedMotion?: boolean;
5
+ };
6
+ export declare const attachAnimation: (svg: Element, options?: AttachOptions) => (() => void);
7
+ export declare const attachAll: (root?: ParentNode) => void;
package/dist/player.js ADDED
@@ -0,0 +1,106 @@
1
+ import { ANIMATION_ATTRIBUTE, MARKER_ATTRIBUTE, animate, decodeAnimation } from "./animation.js";
2
+ const attached = new WeakMap();
3
+ const prefersReduced = () => typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
4
+ const hoverHost = (svg) => svg.closest("a, button, [role=button], label, summary") ?? svg.parentElement ?? svg;
5
+ export const attachAnimation = (svg, options = {}) => {
6
+ attached.get(svg)?.();
7
+ const animation = decodeAnimation(svg.getAttribute(ANIMATION_ATTRIBUTE));
8
+ if (!animation || typeof svg.animate !== "function")
9
+ return () => { };
10
+ if (options.reducedMotion ?? prefersReduced())
11
+ return () => { };
12
+ const trigger = options.trigger ?? animation.trigger;
13
+ const targets = (marker) => [...svg.querySelectorAll(`[${MARKER_ATTRIBUTE}="${marker}"]`)];
14
+ let playback;
15
+ const cleanups = [];
16
+ const stop = () => {
17
+ playback?.cancel();
18
+ playback = undefined;
19
+ };
20
+ const start = () => {
21
+ stop();
22
+ playback = animate(animation, targets);
23
+ };
24
+ if (trigger === "load")
25
+ start();
26
+ let backwards = false;
27
+ const enter = () => {
28
+ if (playback && backwards) {
29
+ backwards = false;
30
+ playback.forward();
31
+ return;
32
+ }
33
+ if (!playback)
34
+ start();
35
+ };
36
+ const leave = () => {
37
+ if (!playback)
38
+ return;
39
+ backwards = true;
40
+ playback.reverse(() => {
41
+ if (!backwards)
42
+ return;
43
+ backwards = false;
44
+ stop();
45
+ });
46
+ };
47
+ if (trigger === "hover") {
48
+ const host = hoverHost(svg);
49
+ host.addEventListener("pointerenter", enter);
50
+ host.addEventListener("pointerleave", leave);
51
+ host.addEventListener("focusin", enter);
52
+ host.addEventListener("focusout", leave);
53
+ cleanups.push(() => {
54
+ host.removeEventListener("pointerenter", enter);
55
+ host.removeEventListener("pointerleave", leave);
56
+ host.removeEventListener("focusin", enter);
57
+ host.removeEventListener("focusout", leave);
58
+ });
59
+ }
60
+ if (trigger === "toggle") {
61
+ const host = hoverHost(svg);
62
+ let on = false;
63
+ const flip = () => {
64
+ on = !on;
65
+ if (on)
66
+ enter();
67
+ else
68
+ leave();
69
+ };
70
+ host.addEventListener("click", flip);
71
+ cleanups.push(() => host.removeEventListener("click", flip));
72
+ }
73
+ if (trigger === "click") {
74
+ const host = hoverHost(svg);
75
+ host.addEventListener("click", start);
76
+ cleanups.push(() => host.removeEventListener("click", start));
77
+ }
78
+ if (trigger === "visible") {
79
+ if (typeof IntersectionObserver === "function") {
80
+ const observer = new IntersectionObserver((entries) => {
81
+ if (!entries.some((entry) => entry.isIntersecting))
82
+ return;
83
+ observer.disconnect();
84
+ start();
85
+ }, { threshold: 0.5 });
86
+ observer.observe(svg);
87
+ cleanups.push(() => observer.disconnect());
88
+ }
89
+ else {
90
+ start();
91
+ }
92
+ }
93
+ const detach = () => {
94
+ stop();
95
+ cleanups.forEach((cleanup) => cleanup());
96
+ attached.delete(svg);
97
+ };
98
+ attached.set(svg, detach);
99
+ return detach;
100
+ };
101
+ export const attachAll = (root = document) => {
102
+ root.querySelectorAll(`svg[${ANIMATION_ATTRIBUTE}]`).forEach((svg) => {
103
+ if (!attached.has(svg))
104
+ attachAnimation(svg);
105
+ });
106
+ };
package/dist/react.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useEffect, useSyncExternalStore } from "react";
2
+ import { useEffect, useRef, useSyncExternalStore } from "react";
3
+ import { attachAnimation } from "./player.js";
3
4
  import { prepare } from "./render.js";
4
5
  import { bundledIcon, getIcon, getSnapshot, isUnknown, requestIcon, subscribe } from "./store.js";
5
6
  const serverSnapshot = { status: "idle", revision: 0 };
@@ -20,6 +21,7 @@ const toProps = (attrs) => Object.fromEntries(Object.entries(attrs).map(([name,
20
21
  const warned = new Set();
21
22
  export const Iconplease = ({ icon, size = 24, className, label, ...options }) => {
22
23
  const state = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
24
+ const ref = useRef(null);
23
25
  useEffect(() => {
24
26
  void requestIcon(icon);
25
27
  }, [icon]);
@@ -32,6 +34,13 @@ export const Iconplease = ({ icon, size = 24, className, label, ...options }) =>
32
34
  return (_jsx("svg", { width: size, height: size, viewBox: "0 0 24 24", "aria-hidden": label ? undefined : true, role: label ? "img" : undefined, "aria-label": label, className: className, "data-iconplease-pending": "" }));
33
35
  }
34
36
  const { attrs, body } = prepare(data, { size, className, label, ...options });
35
- return _jsx("svg", { xmlns: "http://www.w3.org/2000/svg", ...toProps(attrs), dangerouslySetInnerHTML: { __html: body } });
37
+ return _jsx(Animated, { attrs: attrs, body: body, svgRef: ref });
38
+ };
39
+ const Animated = ({ attrs, body, svgRef }) => {
40
+ useEffect(() => {
41
+ const svg = svgRef.current;
42
+ return svg ? attachAnimation(svg) : undefined;
43
+ }, [body, attrs["data-ip-animation"], svgRef]);
44
+ return _jsx("svg", { ref: svgRef, xmlns: "http://www.w3.org/2000/svg", ...toProps(attrs), dangerouslySetInnerHTML: { __html: body } });
36
45
  };
37
46
  export default Iconplease;
package/dist/script.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { init } from "./config.js";
2
2
  import { load, requestIcon, subscribe, getIcon, isUnknown } from "./store.js";
3
3
  import { prepare, renderSVG, toMarkup } from "./render.js";
4
+ import { attachAll, attachAnimation } from "./player.js";
4
5
  const SELECTOR = "[data-icon], i.ip[class*='ip-']";
5
6
  const MOTIONS = new Set(["none", "wiggle", "pop", "bounce", "draw"]);
6
7
  const warned = new Set();
@@ -51,6 +52,9 @@ const paint = (element) => {
51
52
  }
52
53
  element.innerHTML = toMarkup(prepare(icon, options));
53
54
  element.setAttribute("data-ip-rendered", key);
55
+ const svg = element.querySelector("svg");
56
+ if (svg)
57
+ attachAnimation(svg);
54
58
  if (element.tagName === "I")
55
59
  (_a = element.style).display || (_a.display = "inline-flex");
56
60
  };
@@ -82,7 +86,7 @@ const start = () => {
82
86
  attributeFilter: ["data-icon", "data-size", "data-color", "data-stroke", "data-motion", "data-label", "class"],
83
87
  });
84
88
  };
85
- window.iconplease = { init, load, renderSVG, refresh: () => paintAll() };
89
+ window.iconplease = { init, load, renderSVG, attachAnimation, attachAll, refresh: () => paintAll() };
86
90
  if (document.readyState === "loading")
87
91
  document.addEventListener("DOMContentLoaded", start, { once: true });
88
92
  else
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iconplease",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "Icons you can draw yourself. Pages load only the icons they show from the iconplease CDN; private sets via a key, a token or a build-time file.",
5
5
  "keywords": [
6
6
  "icons",
@@ -10,7 +10,8 @@
10
10
  "icon-library"
11
11
  ],
12
12
  "homepage": "https://iconplease.com",
13
- "license": "UNLICENSED",
13
+ "author": "TECHNOLOGYPLEASE Co., Ltd.",
14
+ "license": "MIT",
14
15
  "type": "module",
15
16
  "sideEffects": [
16
17
  "*.css"
@@ -35,7 +36,9 @@
35
36
  "files": [
36
37
  "dist",
37
38
  "bin",
38
- "README.md"
39
+ "README.md",
40
+ "LICENSE",
41
+ "ICONS-LICENSE.md"
39
42
  ],
40
43
  "engines": {
41
44
  "node": ">=18"
@@ -64,6 +67,6 @@
64
67
  "typescript": "^5.8.3"
65
68
  },
66
69
  "bin": {
67
- "iconplease": "./bin/iconplease.mjs"
70
+ "iconplease": "bin/iconplease.mjs"
68
71
  }
69
72
  }