iconplease 0.0.1 → 0.1.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 CHANGED
@@ -1,83 +1,79 @@
1
1
  # iconplease
2
2
 
3
- Icons you can draw yourself.
3
+ Icons you can draw yourself. The catalogue loads once from the iconplease CDN, is cached in the
4
+ browser, and new icons show up without updating this package.
4
5
 
5
- The free catalogue ships inside this package, so it renders with no network
6
- request, no account and no key. A key unlocks the private sets you draw in the
7
- [iconplease designer](https://iconplease.com/designer).
8
-
9
- > **0.0.1 is an early placeholder.** The component, the bundled catalogue and
10
- > the SVG renderer work today. Resolving private sets over the network is not
11
- > built yet — `init()` validates and stores your key, nothing more.
12
-
13
- ## Install
6
+ ## React
14
7
 
15
8
  ```bash
16
- npm install iconplease
9
+ npm i iconplease
17
10
  ```
18
11
 
19
- ## React
20
-
21
12
  ```tsx
22
13
  import { Iconplease } from "iconplease/react";
23
- import "iconplease/styles.css"; // only if you use motion
14
+ import "iconplease/styles.css"; // only needed for motion
24
15
 
25
- <Iconplease icon="rocket" />
26
- <Iconplease icon="heart" size={32} color="#f59ab5" motion="pop" />
16
+ <Iconplease icon="heart" />
17
+ <Iconplease icon="rocket" size={32} color="#e11d48" strokeScale={1.5} motion="pop" />
18
+ <Iconplease icon="bell" label="Notifications" />
27
19
  ```
28
20
 
29
- ## Anywhere else
30
-
31
- ```ts
32
- import { renderSVG, getIcon } from "iconplease";
33
-
34
- const heart = getIcon("heart");
35
- if (heart) element.innerHTML = renderSVG(heart, { size: 32, motion: "pop" });
21
+ | Prop | Default | |
22
+ | --- | --- | --- |
23
+ | `icon` | — | Icon name, e.g. `"heart"`, `"arrow-right"` |
24
+ | `size` | `24` | Width and height in px |
25
+ | `color` | inherits | Replaces only the parts drawn in `currentColor`; parts the icon paints itself keep their colour |
26
+ | `strokeScale` | `1` | Multiplies every stroke width, so icons drawn with different weights keep their proportions |
27
+ | `motion` | `"none"` | `wiggle`, `pop`, `bounce` or `draw` (needs `styles.css`; switched off for visitors who prefer reduced motion) |
28
+ | `label` | — | Makes the icon announced by screen readers. Without it the icon is decorative (`aria-hidden`) |
29
+ | `className` | — | Passed to the `<svg>` |
30
+
31
+ Until the catalogue has loaded, the component renders an empty `<svg>` of the right size, so nothing
32
+ shifts when the icon appears. An unknown name renders that same empty box and logs one warning — it
33
+ never throws.
34
+
35
+ ## Plain HTML
36
+
37
+ ```html
38
+ <script src="https://cdn.jsdelivr.net/npm/iconplease@0.1/dist/iconplease.min.js" defer></script>
39
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/iconplease@0.1/dist/styles.css">
40
+
41
+ <i data-icon="heart"></i>
42
+ <i data-icon="rocket" data-size="32" data-color="#e11d48" data-stroke="1.5" data-motion="pop"></i>
43
+ <i data-icon="bell" data-label="Notifications"></i>
36
44
  ```
37
45
 
38
- ## Props
46
+ Elements added later are picked up automatically. `<i class="ip ip-heart">` works too.
39
47
 
40
- | Prop | Type | Default |
41
- | --- | --- | --- |
42
- | `icon` | icon name | required |
43
- | `size` | number, px | `24` |
44
- | `color` | any CSS colour | inherits `currentColor` |
45
- | `strokeScale` | number | `1` |
46
- | `motion` | `none` `wiggle` `pop` `bounce` `draw` | none |
47
- | `label` | string | none — the icon is hidden from screen readers |
48
+ ## Functions
48
49
 
49
- An icon carries the stroke widths, caps and colours it was drawn with, so
50
- props **override** rather than supply defaults:
50
+ ```ts
51
+ import { load, renderSVG, iconNames } from "iconplease";
51
52
 
52
- - `color` replaces only the parts drawn to inherit (`currentColor`). A shape
53
- painted a specific colour keeps it, so multi-colour icons survive.
54
- - `strokeScale` multiplies every stroke width, keeping the ratios between
55
- shapes. There is no absolute stroke override — one value across shapes drawn
56
- at different widths would destroy the drawing.
53
+ await load(["heart"]); // fetch (or read from cache) the icons you need
54
+ const svg = renderSVG("heart", { size: 32 }); // string, or undefined if unknown / not loaded
55
+ const names = iconNames();
56
+ ```
57
57
 
58
- ## Accessibility
58
+ ## How loading works
59
59
 
60
- Icons are hidden from screen readers by default. Pass `label` when the icon
61
- carries meaning on its own, such as an icon-only button.
60
+ - The SDK downloads a small **index** of icon names (about 1.5 KB for the whole catalogue), then
61
+ fetches **only the icons your page uses**, one small SVG each, in parallel.
62
+ - Every icon file is permanent at its URL, so browsers and the CDN cache it indefinitely. Icons are
63
+ also kept in `localStorage`, so later visits render immediately with no requests.
64
+ - The index is re-checked at most once an hour (`init({ revalidate: seconds })`). When an icon gets a
65
+ new version, only that icon is downloaded again.
66
+ - If the network fails, cached icons keep working. With no cache and no network, icons render as
67
+ empty boxes of the right size; nothing throws.
62
68
 
63
- Motion presets are wrapped in `prefers-reduced-motion: no-preference`, so they
64
- switch off for visitors who ask for less.
69
+ To fetch icons before they are rendered:
65
70
 
66
- ## Keys
71
+ ```ts
72
+ import { load } from "iconplease";
73
+ await load(["heart", "star"]);
74
+ ```
67
75
 
68
76
  ```ts
69
77
  import { init } from "iconplease";
70
-
71
- init({ apiKey: "ip_pk_…" });
78
+ init({ revalidate: 600 });
72
79
  ```
73
-
74
- Use the **publishable** key (`ip_pk_…`). It ships in your bundle where anyone
75
- can read it, so it is read-only and locked to your domains. Secret keys
76
- (`ip_sk_…`) are for servers and CI, and `init()` refuses them.
77
-
78
- ## Known limits in 0.0.1
79
-
80
- - Private sets do not resolve yet — bundled catalogue only.
81
- - The catalogue is resolved by name at runtime, so all 32 icons are included
82
- whether or not you use them.
83
- - Licensing is not settled; this release is published `UNLICENSED`.
package/dist/config.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  import type { Config } from "./types.js";
2
2
  export declare const init: (next?: Config) => Config;
3
3
  export declare const getConfig: () => Config;
4
+ export declare const cdnBase: () => string;
5
+ export declare const revalidateMs: () => number;
package/dist/config.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const DEFAULTS = {
2
- baseUrl: "https://api.iconplease.com",
2
+ cdnUrl: "https://cdn.iconplease.com",
3
3
  revalidate: 3600,
4
4
  };
5
5
  let config = { ...DEFAULTS };
@@ -11,3 +11,5 @@ export const init = (next = {}) => {
11
11
  return config;
12
12
  };
13
13
  export const getConfig = () => config;
14
+ export const cdnBase = () => (config.cdnUrl ?? DEFAULTS.cdnUrl).replace(/\/+$/, "");
15
+ export const revalidateMs = () => Math.max(0, config.revalidate ?? DEFAULTS.revalidate) * 1000;
@@ -0,0 +1 @@
1
+ "use strict";(()=>{var h={cdnUrl:"https://cdn.iconplease.com",revalidate:3600},m={...h},S=(t={})=>{if(t.apiKey&&t.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).");return m={...h,...t},m};var k=()=>{var t;return((t=m.cdnUrl)!=null?t:h.cdnUrl).replace(/\/+$/,"")},L=()=>{var t;return Math.max(0,(t=m.revalidate)!=null?t:h.revalidate)*1e3};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=t=>t.replace(ot,"").replace(rt,"").replace(st,""),E=t=>{var o;if(!t||typeof t!="object")return;let e=t;if(typeof e.body!="string"||typeof e.viewBox!="string"||!/^[0-9.\s-]+$/.test(e.viewBox))return;let n={};for(let[r,s]of Object.entries((o=e.attrs)!=null?o:{}))it.test(r)&&!r.startsWith("on")&&typeof s=="string"&&at.test(s)&&(n[r]=s);return{viewBox:e.viewBox,attrs:n,body:ct(e.body)}};var J="iconplease:index:v2",q="iconplease:icons:v2",dt=1e3,H=/^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/,i={status:"idle",revision:0},w=0,b,_=!1,B=!1,O,u=new Map,A=new Map,$=new Set,C=()=>{try{return typeof localStorage=="undefined"?void 0:localStorage}catch{return}},y=(t={})=>{i={...i,...t,revision:i.revision+1};for(let e of $)e()},x=(t,e)=>`${t}@${e}`,K=t=>{if(!t||typeof t!="object")return;let e=t;if(e.format!==2||typeof e.hash!="string"||!e.icons||typeof e.icons!="object")return;let n=Object.entries(e.icons).filter(([o,r])=>H.test(o)&&Number.isInteger(r)&&r>0);return{format:2,hash:e.hash,icons:Object.fromEntries(n)}},g=()=>{var e,n;if(_)return;_=!0;let t=C();if(t){try{let o=JSON.parse((e=t.getItem(J))!=null?e:"null"),r=K(o==null?void 0:o.index);r&&(i={status:"ready",index:r,revision:i.revision},w=typeof(o==null?void 0:o.checkedAt)=="number"?o.checkedAt:0)}catch{return}try{let o=JSON.parse((n=t.getItem(q))!=null?n:"{}");for(let[r,s]of Object.entries(o)){let c=E(s);c&&u.set(r,c)}}catch{return}}},F=()=>{var t;try{(t=C())==null||t.setItem(J,JSON.stringify({index:i.index,checkedAt:w}))}catch{return}},V=()=>{O||(O=setTimeout(()=>{var n,o,r;O=void 0;let t=(o=(n=i.index)==null?void 0:n.icons)!=null?o:{},e=[...u.entries()].filter(([s])=>{let c=s.lastIndexOf("@");return t[s.slice(0,c)]===Number(s.slice(c+1))});try{(r=C())==null||r.setItem(q,JSON.stringify(Object.fromEntries(e.slice(-dt))))}catch{return}},0))},U=async t=>{let e=await fetch(t);if(!e.ok)throw new Error(`${e.status} for ${t}`);return e.json()},G=t=>{B||(B=!0,console.warn("iconplease: could not reach the icon CDN.",t))},ft=async()=>{var r;let t=k(),e=await U(`${t}/catalogue/latest.json`);if((e==null?void 0:e.format)!==2||typeof e.hash!="string"||typeof e.index!="string")throw new Error("iconplease: the catalogue pointer is malformed");if(w=Date.now(),((r=i.index)==null?void 0:r.hash)===e.hash){F();return}let n=e.index.replace(/^\/+/,"");if(!/^catalogue\/index-[a-z0-9]+\.json$/.test(n))throw new Error("iconplease: unexpected index location");let o=K(await U(`${t}/${n}`));if(!o)throw new Error("iconplease: the icon index is malformed");y({status:"ready",index:o}),F(),V()},N=(t={})=>{if(g(),i.index&&Date.now()-w<L()&&!t.force)return Promise.resolve();if(b)return b;let n=ft().catch(o=>{i.index||y({status:"error"}),G(o)}).finally(()=>{b=void 0});return b=n,!i.index&&i.status!=="loading"&&y({status:"loading"}),n},ut=t=>{let e=/<svg\b([^>]*)>([\s\S]*)<\/svg>\s*$/.exec(t.trim());if(!e)return;let n={},o="0 0 24 24";for(let[,r,s]of e[1].matchAll(/([a-zA-Z:-]+)="([^"]*)"/g))r==="viewBox"?o=s:["xmlns","width","height","aria-hidden","role","class","style"].includes(r)||(n[r]=s);return E({viewBox:o,attrs:n,body:e[2]})},lt=(t,e)=>{let n=x(t,e),o=A.get(n);if(o)return o;let r=fetch(`${k()}/v${e}/${t}.svg`).then(async s=>{if(!s.ok)throw new Error(`${s.status} for ${t}`);let c=ut(await s.text());if(!c)throw new Error(`iconplease: "${t}" is not a valid SVG`);u.set(n,c),V(),y()}).catch(G).finally(()=>{A.delete(n)});return A.set(n,r),r},j=async t=>{var o,r;if(!H.test(t))return;g();let e=(o=i.index)==null?void 0:o.icons[t];if(e&&u.has(x(t,e))){N();return}await N();let n=(r=i.index)==null?void 0:r.icons[t];n&&!u.has(x(t,n))&&await lt(t,n)},P=async(t={})=>{let{icons:e=[],force:n=!1}=Array.isArray(t)?{icons:t}:t;await N({force:n}),await Promise.all(e.map(j))},W=t=>(g(),$.add(t),()=>$.delete(t));var v=t=>{var n;g();let e=(n=i.index)==null?void 0:n.icons[t];return e?u.get(x(t,e)):void 0},X=t=>(g(),i.status==="ready"&&!!i.index&&!(t in i.index.icons));var pt=/^[#a-zA-Z0-9(),.%\s-]{1,64}$/,gt=/[<>"&]/g,mt={"<":"&lt;",">":"&gt;",'"':"&quot;","&":"&amp;"},ht=t=>t.replace(gt,e=>mt[e]),Y=t=>String(Number(t.toFixed(3))),bt=(t,e)=>t.replace(/\b(fill|stroke)="currentColor"/g,`$1="${e}"`),yt=(t,e)=>t.replace(/\bstroke-width="([0-9]*\.?[0-9]+)"/g,(n,o)=>`stroke-width="${Y(Number(o)*e)}"`),D=(t,e={})=>{var T;let{size:n=24,color:o,strokeScale:r,motion:s,label:c,className:l}=e,d=o&&pt.test(o)?o:void 0,f=typeof r=="number"&&Number.isFinite(r)&&r>0&&r!==1?r:void 0,a={...(T=t.attrs)!=null?T:{}};if(d)for(let z of["fill","stroke"])a[z]==="currentColor"&&(a[z]=d);f&&a["stroke-width"]&&(a["stroke-width"]=Y(Number(a["stroke-width"])*f));let p=t.body;return d&&(p=bt(p,d)),f&&(p=yt(p,f)),a.width=String(n),a.height=String(n),a.viewBox=t.viewBox,s&&s!=="none"&&(a["data-motion"]=s),c?(a.role="img",a["aria-label"]=c):a["aria-hidden"]="true",l&&(a.class=l),{attrs:a,body:p}},M=({attrs:t,body:e})=>`<svg xmlns="http://www.w3.org/2000/svg" ${Object.entries(t).map(([o,r])=>`${o}="${ht(r)}"`).join(" ")}>${e}</svg>`,Z=(t,e={})=>{let n=typeof t=="string"?v(t):t;return n?M(D(n,e)):void 0};var Q="[data-icon], i.ip[class*='ip-']",xt=new Set(["none","wiggle","pop","bounce","draw"]),tt=new Set,wt=t=>{let e=t.getAttribute("data-icon");if(e)return e;for(let n of Array.from(t.classList))if(n.startsWith("ip-")&&n.length>3)return n.slice(3)},et=t=>{if(t===null)return;let e=Number(t);return Number.isFinite(e)&&e>0?e:void 0},R=t=>{var l,d,f,a;let e=wt(t);if(!e)return;let n=v(e),o=t.getAttribute("data-motion"),r=o&&xt.has(o)?o:void 0,s={size:(l=et(t.getAttribute("data-size")))!=null?l:24,color:(d=t.getAttribute("data-color"))!=null?d:void 0,strokeScale:et(t.getAttribute("data-stroke")),motion:r,label:(f=t.getAttribute("data-label"))!=null?f:void 0},c=JSON.stringify([e,s,n?"1":"0"]);if(t.getAttribute("data-ip-rendered")!==c){if(!n){X(e)?tt.has(e)||(tt.add(e),console.warn(`iconplease: no icon named "${e}".`)):j(e);return}t.innerHTML=M(D(n,s)),t.setAttribute("data-ip-rendered",c),t.tagName==="I"&&((a=t.style).display||(a.display="inline-flex"))}},I=(t=document)=>{t instanceof Element&&t.matches(Q)&&R(t),t.querySelectorAll(Q).forEach(R)},nt=()=>{let t=window.iconpleaseConfig;t&&S(t),W(()=>I()),I(),P(),new MutationObserver(e=>{for(let n of e)n.type==="attributes"&&n.target instanceof Element&&R(n.target),n.addedNodes.forEach(o=>{o instanceof Element&&I(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:S,load:P,renderSVG:Z,refresh:()=>I()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",nt,{once:!0}):nt();})();
package/dist/index.d.ts CHANGED
@@ -1,8 +1,6 @@
1
- import { icons, iconNames } from "./icons.js";
2
- import type { IconDefinition } from "./types.js";
3
- export { icons, iconNames };
4
1
  export { init, getConfig } from "./config.js";
5
- export { renderSVG, resolveShape } from "./render.js";
6
- export type { Config, IconDefinition, IconMotion, IconShape, StrokeLinecap, StrokeLinejoin, } from "./types.js";
7
- export type { RenderOptions, ResolvedShape } from "./render.js";
8
- export declare const getIcon: (name: string) => IconDefinition | undefined;
2
+ export { load, requestIcon, subscribe, getIcon, getStatus, iconNames, isUnknown } from "./store.js";
3
+ export { renderSVG, prepare } from "./render.js";
4
+ export type { RenderOptions, Prepared } from "./render.js";
5
+ export type { LoadOptions } from "./store.js";
6
+ export type { Config, IconData, IconIndex, IconMotion, Status } from "./types.js";
package/dist/index.js CHANGED
@@ -1,14 +1,3 @@
1
- import { icons, iconNames } from "./icons.js";
2
- export { icons, iconNames };
3
1
  export { init, getConfig } from "./config.js";
4
- export { renderSVG, resolveShape } from "./render.js";
5
- const account = {};
6
- const warned = new Set();
7
- export const getIcon = (name) => {
8
- const found = account[name] ?? icons[name];
9
- if (!found && !warned.has(name)) {
10
- warned.add(name);
11
- console.warn(`iconplease: no icon named "${name}".`);
12
- }
13
- return found;
14
- };
2
+ export { load, requestIcon, subscribe, getIcon, getStatus, iconNames, isUnknown } from "./store.js";
3
+ export { renderSVG, prepare } from "./render.js";
package/dist/react.d.ts CHANGED
@@ -1,12 +1,6 @@
1
- import type { IconMotion } from "./types.js";
2
- export type IconpleaseProps = {
1
+ import { type RenderOptions } from "./render.js";
2
+ export type IconpleaseProps = RenderOptions & {
3
3
  icon: string;
4
- size?: number;
5
- color?: string;
6
- strokeScale?: number;
7
- motion?: IconMotion;
8
- label?: string;
9
- className?: string;
10
4
  };
11
- export declare const Iconplease: ({ icon, size, color, strokeScale, motion, label, className, }: IconpleaseProps) => import("react").JSX.Element | null;
5
+ export declare const Iconplease: ({ icon, size, className, label, ...options }: IconpleaseProps) => import("react").JSX.Element;
12
6
  export default Iconplease;
package/dist/react.js CHANGED
@@ -1,13 +1,37 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { getIcon } from "./index.js";
3
- import { resolveShape } from "./render.js";
4
- export const Iconplease = ({ icon, size = 24, color, strokeScale, motion, label, className, }) => {
5
- const found = getIcon(icon);
6
- if (!found)
7
- return null;
8
- return (_jsx("svg", { width: size, height: size, viewBox: `0 0 ${found.viewBox} ${found.viewBox}`, "data-motion": motion === "none" ? undefined : motion, role: label ? "img" : undefined, "aria-label": label, "aria-hidden": label ? undefined : true, className: className, children: found.shapes.map((shape, index) => {
9
- const s = resolveShape(shape, { color, strokeScale });
10
- return (_jsx("path", { d: s.d, pathLength: "100", fill: s.fill, stroke: s.stroke, strokeWidth: s.strokeWidth, strokeLinecap: s.strokeLinecap, strokeLinejoin: s.strokeLinejoin, opacity: s.opacity }, index));
11
- }) }));
2
+ import { useEffect, useSyncExternalStore } from "react";
3
+ import { prepare } from "./render.js";
4
+ import { getIcon, getSnapshot, isUnknown, requestIcon, subscribe } from "./store.js";
5
+ const serverSnapshot = { status: "idle", revision: 0 };
6
+ const getServerSnapshot = () => serverSnapshot;
7
+ const REACT_NAMES = {
8
+ class: "className",
9
+ "stroke-width": "strokeWidth",
10
+ "stroke-linecap": "strokeLinecap",
11
+ "stroke-linejoin": "strokeLinejoin",
12
+ "stroke-miterlimit": "strokeMiterlimit",
13
+ "stroke-dasharray": "strokeDasharray",
14
+ "stroke-opacity": "strokeOpacity",
15
+ "fill-opacity": "fillOpacity",
16
+ "fill-rule": "fillRule",
17
+ "clip-rule": "clipRule",
18
+ };
19
+ const toProps = (attrs) => Object.fromEntries(Object.entries(attrs).map(([name, value]) => [REACT_NAMES[name] ?? name, value]));
20
+ const warned = new Set();
21
+ export const Iconplease = ({ icon, size = 24, className, label, ...options }) => {
22
+ const state = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
23
+ useEffect(() => {
24
+ void requestIcon(icon);
25
+ }, [icon]);
26
+ const data = state === serverSnapshot ? undefined : getIcon(icon);
27
+ if (!data) {
28
+ if (state !== serverSnapshot && isUnknown(icon) && !warned.has(icon)) {
29
+ warned.add(icon);
30
+ console.warn(`iconplease: no icon named "${icon}".`);
31
+ }
32
+ 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
+ }
34
+ 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 } });
12
36
  };
13
37
  export default Iconplease;
package/dist/render.d.ts CHANGED
@@ -1,19 +1,16 @@
1
- import type { IconDefinition, IconShape } from "./types.js";
1
+ import type { IconData, IconMotion } from "./types.js";
2
2
  export type RenderOptions = {
3
3
  size?: number;
4
4
  color?: string;
5
5
  strokeScale?: number;
6
- motion?: string;
6
+ motion?: IconMotion;
7
7
  label?: string;
8
+ className?: string;
8
9
  };
9
- export type ResolvedShape = {
10
- d: string;
11
- fill: string;
12
- stroke: string;
13
- strokeWidth: number;
14
- strokeLinecap: string;
15
- strokeLinejoin: string;
16
- opacity: number;
10
+ export type Prepared = {
11
+ attrs: Record<string, string>;
12
+ body: string;
17
13
  };
18
- export declare const resolveShape: (shape: IconShape, { color, strokeScale }?: RenderOptions) => ResolvedShape;
19
- export declare const renderSVG: (icon: IconDefinition, options?: RenderOptions) => string;
14
+ export declare const prepare: (icon: IconData, options?: RenderOptions) => Prepared;
15
+ export declare const toMarkup: ({ attrs, body }: Prepared) => string;
16
+ export declare const renderSVG: (icon: string | IconData, options?: RenderOptions) => string | undefined;
package/dist/render.js CHANGED
@@ -1,46 +1,53 @@
1
- // A prop overrides only what the icon left inheriting. A shape the author
2
- // painted keeps its own colour, or every multi-colour icon flattens.
3
- const paint = (value, color) => value === "currentColor" && color ? color : value;
4
- export const resolveShape = (shape, { color, strokeScale = 1 } = {}) => ({
5
- d: shape.d,
6
- fill: paint(shape.fill ?? "none", color),
7
- stroke: paint(shape.stroke ?? "currentColor", color),
8
- strokeWidth: shape.strokeWidth * strokeScale,
9
- strokeLinecap: shape.strokeLinecap ?? "round",
10
- strokeLinejoin: shape.strokeLinejoin ?? "round",
11
- opacity: shape.opacity ?? 1,
12
- });
1
+ import { getIcon } from "./store.js";
2
+ const SAFE_COLOR = /^[#a-zA-Z0-9(),.%\s-]{1,64}$/;
3
+ const SAFE_TEXT = /[<>"&]/g;
4
+ const ESCAPES = { "<": "&lt;", ">": "&gt;", '"': "&quot;", "&": "&amp;" };
5
+ const escape = (value) => value.replace(SAFE_TEXT, (c) => ESCAPES[c]);
13
6
  const num = (value) => String(Number(value.toFixed(3)));
14
- export const renderSVG = (icon, options = {}) => {
15
- const { size = 24, motion, label } = options;
16
- const box = icon.viewBox;
17
- const shapes = icon.shapes
18
- .map((shape) => {
19
- const s = resolveShape(shape, options);
20
- return [
21
- `<path d="${s.d}"`,
22
- `pathLength="100"`,
23
- `fill="${s.fill}"`,
24
- `stroke="${s.stroke}"`,
25
- `stroke-width="${num(s.strokeWidth)}"`,
26
- `stroke-linecap="${s.strokeLinecap}"`,
27
- `stroke-linejoin="${s.strokeLinejoin}"`,
28
- s.opacity === 1 ? "" : `opacity="${num(s.opacity)}"`,
29
- "/>",
30
- ]
31
- .filter(Boolean)
32
- .join(" ");
33
- })
34
- .join("");
35
- const attributes = [
36
- `xmlns="http://www.w3.org/2000/svg"`,
37
- `width="${size}"`,
38
- `height="${size}"`,
39
- `viewBox="0 0 ${box} ${box}"`,
40
- motion && motion !== "none" ? `data-motion="${motion}"` : "",
41
- label ? `role="img" aria-label="${label}"` : `aria-hidden="true"`,
42
- ]
43
- .filter(Boolean)
7
+ const recolor = (markup, color) => markup.replace(/\b(fill|stroke)="currentColor"/g, `$1="${color}"`);
8
+ const rescale = (markup, scale) => markup.replace(/\bstroke-width="([0-9]*\.?[0-9]+)"/g, (_m, w) => `stroke-width="${num(Number(w) * scale)}"`);
9
+ export const prepare = (icon, options = {}) => {
10
+ const { size = 24, color, strokeScale, motion, label, className } = options;
11
+ const useColor = color && SAFE_COLOR.test(color) ? color : undefined;
12
+ const useScale = typeof strokeScale === "number" && Number.isFinite(strokeScale) && strokeScale > 0 && strokeScale !== 1
13
+ ? strokeScale
14
+ : undefined;
15
+ const attrs = { ...(icon.attrs ?? {}) };
16
+ if (useColor) {
17
+ for (const key of ["fill", "stroke"])
18
+ if (attrs[key] === "currentColor")
19
+ attrs[key] = useColor;
20
+ }
21
+ if (useScale && attrs["stroke-width"])
22
+ attrs["stroke-width"] = num(Number(attrs["stroke-width"]) * useScale);
23
+ let body = icon.body;
24
+ if (useColor)
25
+ body = recolor(body, useColor);
26
+ if (useScale)
27
+ body = rescale(body, useScale);
28
+ attrs.width = String(size);
29
+ attrs.height = String(size);
30
+ attrs.viewBox = icon.viewBox;
31
+ if (motion && motion !== "none")
32
+ attrs["data-motion"] = motion;
33
+ if (label) {
34
+ attrs.role = "img";
35
+ attrs["aria-label"] = label;
36
+ }
37
+ else {
38
+ attrs["aria-hidden"] = "true";
39
+ }
40
+ if (className)
41
+ attrs.class = className;
42
+ return { attrs, body };
43
+ };
44
+ export const toMarkup = ({ attrs, body }) => {
45
+ const list = Object.entries(attrs)
46
+ .map(([name, value]) => `${name}="${escape(value)}"`)
44
47
  .join(" ");
45
- return `<svg ${attributes}>${shapes}</svg>`;
48
+ return `<svg xmlns="http://www.w3.org/2000/svg" ${list}>${body}</svg>`;
49
+ };
50
+ export const renderSVG = (icon, options = {}) => {
51
+ const data = typeof icon === "string" ? getIcon(icon) : icon;
52
+ return data ? toMarkup(prepare(data, options)) : undefined;
46
53
  };
@@ -0,0 +1,3 @@
1
+ import type { IconData } from "./types.js";
2
+ export declare const cleanBody: (body: string) => string;
3
+ export declare const cleanIcon: (raw: unknown) => IconData | undefined;
@@ -0,0 +1,22 @@
1
+ const BLOCKED = /<\s*(script|foreignObject|iframe|object|embed|style)\b[\s\S]*?(<\s*\/\s*\1\s*>|\/>)/gi;
2
+ const HANDLER = /\s+on[a-z]+\s*=\s*("[^"]*"|'[^']*'|[^\s>]+)/gi;
3
+ const JS_HREF = /\s+(?:xlink:)?href\s*=\s*("\s*javascript:[^"]*"|'\s*javascript:[^']*')/gi;
4
+ const ATTR_NAME = /^[a-z][a-z0-9-]*$/;
5
+ const ATTR_VALUE = /^[^"<>]*$/;
6
+ export const cleanBody = (body) => body.replace(BLOCKED, "").replace(HANDLER, "").replace(JS_HREF, "");
7
+ export const cleanIcon = (raw) => {
8
+ if (!raw || typeof raw !== "object")
9
+ return undefined;
10
+ const icon = raw;
11
+ if (typeof icon.body !== "string" || typeof icon.viewBox !== "string")
12
+ return undefined;
13
+ if (!/^[0-9.\s-]+$/.test(icon.viewBox))
14
+ return undefined;
15
+ const attrs = {};
16
+ for (const [name, value] of Object.entries(icon.attrs ?? {})) {
17
+ if (ATTR_NAME.test(name) && !name.startsWith("on") && typeof value === "string" && ATTR_VALUE.test(value)) {
18
+ attrs[name] = value;
19
+ }
20
+ }
21
+ return { viewBox: icon.viewBox, attrs, body: cleanBody(icon.body) };
22
+ };
@@ -0,0 +1 @@
1
+ export {};
package/dist/script.js ADDED
@@ -0,0 +1,89 @@
1
+ import { init } from "./config.js";
2
+ import { load, requestIcon, subscribe, getIcon, isUnknown } from "./store.js";
3
+ import { prepare, renderSVG, toMarkup } from "./render.js";
4
+ const SELECTOR = "[data-icon], i.ip[class*='ip-']";
5
+ const MOTIONS = new Set(["none", "wiggle", "pop", "bounce", "draw"]);
6
+ const warned = new Set();
7
+ const nameOf = (element) => {
8
+ const explicit = element.getAttribute("data-icon");
9
+ if (explicit)
10
+ return explicit;
11
+ for (const name of Array.from(element.classList)) {
12
+ if (name.startsWith("ip-") && name.length > 3)
13
+ return name.slice(3);
14
+ }
15
+ return undefined;
16
+ };
17
+ const numberOf = (value) => {
18
+ if (value === null)
19
+ return undefined;
20
+ const n = Number(value);
21
+ return Number.isFinite(n) && n > 0 ? n : undefined;
22
+ };
23
+ const paint = (element) => {
24
+ var _a;
25
+ const name = nameOf(element);
26
+ if (!name)
27
+ return;
28
+ const icon = getIcon(name);
29
+ const motionAttr = element.getAttribute("data-motion");
30
+ const motion = motionAttr && MOTIONS.has(motionAttr) ? motionAttr : undefined;
31
+ const options = {
32
+ size: numberOf(element.getAttribute("data-size")) ?? 24,
33
+ color: element.getAttribute("data-color") ?? undefined,
34
+ strokeScale: numberOf(element.getAttribute("data-stroke")),
35
+ motion,
36
+ label: element.getAttribute("data-label") ?? undefined,
37
+ };
38
+ const key = JSON.stringify([name, options, icon ? "1" : "0"]);
39
+ if (element.getAttribute("data-ip-rendered") === key)
40
+ return;
41
+ if (!icon) {
42
+ if (isUnknown(name)) {
43
+ if (!warned.has(name)) {
44
+ warned.add(name);
45
+ console.warn(`iconplease: no icon named "${name}".`);
46
+ }
47
+ }
48
+ else
49
+ void requestIcon(name);
50
+ return;
51
+ }
52
+ element.innerHTML = toMarkup(prepare(icon, options));
53
+ element.setAttribute("data-ip-rendered", key);
54
+ if (element.tagName === "I")
55
+ (_a = element.style).display || (_a.display = "inline-flex");
56
+ };
57
+ const paintAll = (root = document) => {
58
+ if (root instanceof Element && root.matches(SELECTOR))
59
+ paint(root);
60
+ root.querySelectorAll(SELECTOR).forEach(paint);
61
+ };
62
+ const start = () => {
63
+ const preset = window.iconpleaseConfig;
64
+ if (preset)
65
+ init(preset);
66
+ subscribe(() => paintAll());
67
+ paintAll();
68
+ void load();
69
+ new MutationObserver((records) => {
70
+ for (const record of records) {
71
+ if (record.type === "attributes" && record.target instanceof Element)
72
+ paint(record.target);
73
+ record.addedNodes.forEach((node) => {
74
+ if (node instanceof Element)
75
+ paintAll(node);
76
+ });
77
+ }
78
+ }).observe(document.documentElement, {
79
+ childList: true,
80
+ subtree: true,
81
+ attributes: true,
82
+ attributeFilter: ["data-icon", "data-size", "data-color", "data-stroke", "data-motion", "data-label", "class"],
83
+ });
84
+ };
85
+ window.iconplease = { init, load, renderSVG, refresh: () => paintAll() };
86
+ if (document.readyState === "loading")
87
+ document.addEventListener("DOMContentLoaded", start, { once: true });
88
+ else
89
+ start();
@@ -0,0 +1,23 @@
1
+ import type { IconData, IconIndex, Status } from "./types.js";
2
+ export type State = {
3
+ status: Status;
4
+ index?: IconIndex;
5
+ revision: number;
6
+ };
7
+ export declare const loadIndex: (options?: {
8
+ force?: boolean;
9
+ }) => Promise<void>;
10
+ export declare const parseSVG: (text: string) => IconData | undefined;
11
+ export declare const requestIcon: (name: string) => Promise<void>;
12
+ export type LoadOptions = {
13
+ icons?: string[];
14
+ force?: boolean;
15
+ };
16
+ export declare const load: (options?: LoadOptions | string[]) => Promise<void>;
17
+ export declare const subscribe: (listener: () => void) => (() => void);
18
+ export declare const getSnapshot: () => State;
19
+ export declare const getStatus: () => Status;
20
+ export declare const getIcon: (name: string) => IconData | undefined;
21
+ export declare const isUnknown: (name: string) => boolean;
22
+ export declare const iconNames: () => string[];
23
+ export declare const resetForTests: () => void;
package/dist/store.js ADDED
@@ -0,0 +1,237 @@
1
+ import { cdnBase, revalidateMs } from "./config.js";
2
+ import { cleanIcon } from "./sanitize.js";
3
+ const INDEX_KEY = "iconplease:index:v2";
4
+ const ICONS_KEY = "iconplease:icons:v2";
5
+ const MAX_CACHED_ICONS = 1000;
6
+ const NAME = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
7
+ let state = { status: "idle", revision: 0 };
8
+ let checkedAt = 0;
9
+ let indexInflight;
10
+ let hydrated = false;
11
+ let warnedOffline = false;
12
+ let persistTimer;
13
+ const icons = new Map();
14
+ const iconInflight = new Map();
15
+ const listeners = new Set();
16
+ const storage = () => {
17
+ try {
18
+ return typeof localStorage === "undefined" ? undefined : localStorage;
19
+ }
20
+ catch {
21
+ return undefined;
22
+ }
23
+ };
24
+ const notify = (patch = {}) => {
25
+ state = { ...state, ...patch, revision: state.revision + 1 };
26
+ for (const listener of listeners)
27
+ listener();
28
+ };
29
+ const keyOf = (name, version) => `${name}@${version}`;
30
+ const cleanIndex = (raw) => {
31
+ if (!raw || typeof raw !== "object")
32
+ return undefined;
33
+ const data = raw;
34
+ if (data.format !== 2 || typeof data.hash !== "string" || !data.icons || typeof data.icons !== "object") {
35
+ return undefined;
36
+ }
37
+ const entries = Object.entries(data.icons).filter(([name, version]) => NAME.test(name) && Number.isInteger(version) && version > 0);
38
+ return { format: 2, hash: data.hash, icons: Object.fromEntries(entries) };
39
+ };
40
+ const hydrate = () => {
41
+ if (hydrated)
42
+ return;
43
+ hydrated = true;
44
+ const store = storage();
45
+ if (!store)
46
+ return;
47
+ try {
48
+ const cached = JSON.parse(store.getItem(INDEX_KEY) ?? "null");
49
+ const index = cleanIndex(cached?.index);
50
+ if (index) {
51
+ state = { status: "ready", index, revision: state.revision };
52
+ checkedAt = typeof cached?.checkedAt === "number" ? cached.checkedAt : 0;
53
+ }
54
+ }
55
+ catch {
56
+ return;
57
+ }
58
+ try {
59
+ const saved = JSON.parse(store.getItem(ICONS_KEY) ?? "{}");
60
+ for (const [key, raw] of Object.entries(saved)) {
61
+ const icon = cleanIcon(raw);
62
+ if (icon)
63
+ icons.set(key, icon);
64
+ }
65
+ }
66
+ catch {
67
+ return;
68
+ }
69
+ };
70
+ const persistIndex = () => {
71
+ try {
72
+ storage()?.setItem(INDEX_KEY, JSON.stringify({ index: state.index, checkedAt }));
73
+ }
74
+ catch {
75
+ return;
76
+ }
77
+ };
78
+ const persistIcons = () => {
79
+ if (persistTimer)
80
+ return;
81
+ persistTimer = setTimeout(() => {
82
+ persistTimer = undefined;
83
+ const current = state.index?.icons ?? {};
84
+ const keep = [...icons.entries()].filter(([key]) => {
85
+ const at = key.lastIndexOf("@");
86
+ return current[key.slice(0, at)] === Number(key.slice(at + 1));
87
+ });
88
+ try {
89
+ storage()?.setItem(ICONS_KEY, JSON.stringify(Object.fromEntries(keep.slice(-MAX_CACHED_ICONS))));
90
+ }
91
+ catch {
92
+ return;
93
+ }
94
+ }, 0);
95
+ };
96
+ const getJSON = async (url) => {
97
+ const response = await fetch(url);
98
+ if (!response.ok)
99
+ throw new Error(`${response.status} for ${url}`);
100
+ return response.json();
101
+ };
102
+ const warnOnce = (error) => {
103
+ if (warnedOffline)
104
+ return;
105
+ warnedOffline = true;
106
+ console.warn("iconplease: could not reach the icon CDN.", error);
107
+ };
108
+ const refreshIndex = async () => {
109
+ const base = cdnBase();
110
+ const pointer = (await getJSON(`${base}/catalogue/latest.json`));
111
+ if (pointer?.format !== 2 || typeof pointer.hash !== "string" || typeof pointer.index !== "string") {
112
+ throw new Error("iconplease: the catalogue pointer is malformed");
113
+ }
114
+ checkedAt = Date.now();
115
+ if (state.index?.hash === pointer.hash) {
116
+ persistIndex();
117
+ return;
118
+ }
119
+ const path = pointer.index.replace(/^\/+/, "");
120
+ if (!/^catalogue\/index-[a-z0-9]+\.json$/.test(path))
121
+ throw new Error("iconplease: unexpected index location");
122
+ const index = cleanIndex(await getJSON(`${base}/${path}`));
123
+ if (!index)
124
+ throw new Error("iconplease: the icon index is malformed");
125
+ notify({ status: "ready", index });
126
+ persistIndex();
127
+ persistIcons();
128
+ };
129
+ export const loadIndex = (options = {}) => {
130
+ hydrate();
131
+ const fresh = state.index && Date.now() - checkedAt < revalidateMs();
132
+ if (fresh && !options.force)
133
+ return Promise.resolve();
134
+ if (indexInflight)
135
+ return indexInflight;
136
+ const pending = refreshIndex()
137
+ .catch((error) => {
138
+ if (!state.index)
139
+ notify({ status: "error" });
140
+ warnOnce(error);
141
+ })
142
+ .finally(() => {
143
+ indexInflight = undefined;
144
+ });
145
+ indexInflight = pending;
146
+ if (!state.index && state.status !== "loading")
147
+ notify({ status: "loading" });
148
+ return pending;
149
+ };
150
+ export const parseSVG = (text) => {
151
+ const root = /<svg\b([^>]*)>([\s\S]*)<\/svg>\s*$/.exec(text.trim());
152
+ if (!root)
153
+ return undefined;
154
+ const attrs = {};
155
+ let viewBox = "0 0 24 24";
156
+ for (const [, name, value] of root[1].matchAll(/([a-zA-Z:-]+)="([^"]*)"/g)) {
157
+ if (name === "viewBox")
158
+ viewBox = value;
159
+ else if (!["xmlns", "width", "height", "aria-hidden", "role", "class", "style"].includes(name))
160
+ attrs[name] = value;
161
+ }
162
+ return cleanIcon({ viewBox, attrs, body: root[2] });
163
+ };
164
+ const fetchIcon = (name, version) => {
165
+ const key = keyOf(name, version);
166
+ const pending = iconInflight.get(key);
167
+ if (pending)
168
+ return pending;
169
+ const request = fetch(`${cdnBase()}/v${version}/${name}.svg`)
170
+ .then(async (response) => {
171
+ if (!response.ok)
172
+ throw new Error(`${response.status} for ${name}`);
173
+ const icon = parseSVG(await response.text());
174
+ if (!icon)
175
+ throw new Error(`iconplease: "${name}" is not a valid SVG`);
176
+ icons.set(key, icon);
177
+ persistIcons();
178
+ notify();
179
+ })
180
+ .catch(warnOnce)
181
+ .finally(() => {
182
+ iconInflight.delete(key);
183
+ });
184
+ iconInflight.set(key, request);
185
+ return request;
186
+ };
187
+ export const requestIcon = async (name) => {
188
+ if (!NAME.test(name))
189
+ return;
190
+ hydrate();
191
+ const known = state.index?.icons[name];
192
+ if (known && icons.has(keyOf(name, known))) {
193
+ void loadIndex();
194
+ return;
195
+ }
196
+ await loadIndex();
197
+ const version = state.index?.icons[name];
198
+ if (version && !icons.has(keyOf(name, version)))
199
+ await fetchIcon(name, version);
200
+ };
201
+ export const load = async (options = {}) => {
202
+ const { icons: names = [], force = false } = Array.isArray(options) ? { icons: options } : options;
203
+ await loadIndex({ force });
204
+ await Promise.all(names.map(requestIcon));
205
+ };
206
+ export const subscribe = (listener) => {
207
+ hydrate();
208
+ listeners.add(listener);
209
+ return () => listeners.delete(listener);
210
+ };
211
+ export const getSnapshot = () => {
212
+ hydrate();
213
+ return state;
214
+ };
215
+ export const getStatus = () => getSnapshot().status;
216
+ export const getIcon = (name) => {
217
+ hydrate();
218
+ const version = state.index?.icons[name];
219
+ return version ? icons.get(keyOf(name, version)) : undefined;
220
+ };
221
+ export const isUnknown = (name) => {
222
+ hydrate();
223
+ return state.status === "ready" && !!state.index && !(name in state.index.icons);
224
+ };
225
+ export const iconNames = () => Object.keys(getSnapshot().index?.icons ?? {});
226
+ export const resetForTests = () => {
227
+ state = { status: "idle", revision: 0 };
228
+ checkedAt = 0;
229
+ indexInflight = undefined;
230
+ hydrated = false;
231
+ warnedOffline = false;
232
+ icons.clear();
233
+ iconInflight.clear();
234
+ if (persistTimer)
235
+ clearTimeout(persistTimer);
236
+ persistTimer = undefined;
237
+ };
package/dist/types.d.ts CHANGED
@@ -1,22 +1,23 @@
1
- export type StrokeLinecap = "butt" | "round" | "square";
2
- export type StrokeLinejoin = "miter" | "round" | "bevel";
3
1
  export type IconMotion = "none" | "wiggle" | "pop" | "bounce" | "draw";
4
- export type IconShape = {
5
- d: string;
6
- strokeWidth: number;
7
- fill?: string;
8
- stroke?: string;
9
- strokeLinecap?: StrokeLinecap;
10
- strokeLinejoin?: StrokeLinejoin;
11
- opacity?: number;
2
+ export type IconData = {
3
+ viewBox: string;
4
+ attrs?: Record<string, string>;
5
+ body: string;
12
6
  };
13
- export type IconDefinition = {
14
- name: string;
15
- viewBox: number;
16
- shapes: IconShape[];
7
+ export type IconIndex = {
8
+ format: 2;
9
+ hash: string;
10
+ icons: Record<string, number>;
11
+ };
12
+ export type IndexPointer = {
13
+ format: 2;
14
+ hash: string;
15
+ index: string;
16
+ count: number;
17
17
  };
18
18
  export type Config = {
19
- apiKey?: string;
20
- baseUrl?: string;
19
+ cdnUrl?: string;
21
20
  revalidate?: number;
21
+ apiKey?: string;
22
22
  };
23
+ export type Status = "idle" | "loading" | "ready" | "error";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "iconplease",
3
- "version": "0.0.1",
4
- "description": "Icons you can draw yourself. The free catalogue ships in the package; private sets resolve live.",
3
+ "version": "0.1.0",
4
+ "description": "Icons you can draw yourself. The catalogue loads once from the iconplease CDN and is cached in the browser.",
5
5
  "keywords": [
6
6
  "icons",
7
7
  "icon",
@@ -17,6 +17,8 @@
17
17
  ],
18
18
  "main": "./dist/index.js",
19
19
  "types": "./dist/index.d.ts",
20
+ "unpkg": "./dist/iconplease.min.js",
21
+ "jsdelivr": "./dist/iconplease.min.js",
20
22
  "exports": {
21
23
  ".": {
22
24
  "types": "./dist/index.d.ts",
@@ -27,6 +29,7 @@
27
29
  "import": "./dist/react.js"
28
30
  },
29
31
  "./styles.css": "./dist/styles.css",
32
+ "./script": "./dist/iconplease.min.js",
30
33
  "./package.json": "./package.json"
31
34
  },
32
35
  "files": [
@@ -37,7 +40,7 @@
37
40
  "node": ">=18"
38
41
  },
39
42
  "scripts": {
40
- "build": "tsc && cp src/styles.css dist/styles.css",
43
+ "build": "rm -rf dist && tsc && cp src/styles.css dist/styles.css && esbuild src/script.ts --bundle --minify --format=iife --target=es2019 --outfile=dist/iconplease.min.js",
41
44
  "dev": "tsc --watch",
42
45
  "typecheck": "tsc --noEmit",
43
46
  "prepublishOnly": "npm run build",
@@ -54,6 +57,7 @@
54
57
  "devDependencies": {
55
58
  "@types/react": "^19.2.14",
56
59
  "@types/react-dom": "^19.3.0",
60
+ "esbuild": "0.25.10",
57
61
  "react": "^19.3.0",
58
62
  "react-dom": "^19.3.0",
59
63
  "typescript": "^5.8.3"
package/dist/icons.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import type { IconDefinition } from "./types.js";
2
- export declare const icons: Record<string, IconDefinition>;
3
- export declare const iconNames: string[];
package/dist/icons.js DELETED
@@ -1,163 +0,0 @@
1
- export const icons = {
2
- "home": {
3
- name: "Home",
4
- viewBox: 24,
5
- shapes: [{ d: "M3 11 12 3l9 8M5 9.5V21h5v-6h4v6h5V9.5", strokeWidth: 1.75 }],
6
- },
7
- "search": {
8
- name: "Search",
9
- viewBox: 24,
10
- shapes: [{ d: "M11 4a7 7 0 1 0 0 14a7 7 0 1 0 0-14M21 21l-5-5", strokeWidth: 1.75 }],
11
- },
12
- "bell": {
13
- name: "Bell",
14
- viewBox: 24,
15
- shapes: [{ d: "M6 16v-5a6 6 0 0 1 12 0v5l2 2H4zM10 21h4", strokeWidth: 1.75 }],
16
- },
17
- "user": {
18
- name: "User",
19
- viewBox: 24,
20
- shapes: [{ d: "M12 4a4 4 0 1 0 0 8a4 4 0 1 0 0-8M4 21a8 8 0 0 1 16 0", strokeWidth: 1.75 }],
21
- },
22
- "settings": {
23
- name: "Settings",
24
- viewBox: 24,
25
- shapes: [{ d: "M12 9a3 3 0 1 0 0 6a3 3 0 1 0 0-6M12 2v3M12 19v3M2 12h3M19 12h3M4.9 4.9 7 7M17 17l2.1 2.1M4.9 19.1 7 17M17 7l2.1-2.1", strokeWidth: 1.75 }],
26
- },
27
- "lock": {
28
- name: "Lock",
29
- viewBox: 24,
30
- shapes: [{ d: "M6 11h12v10H6zM8 11V7a4 4 0 0 1 8 0v4", strokeWidth: 1.75 }],
31
- },
32
- "trash": {
33
- name: "Trash",
34
- viewBox: 24,
35
- shapes: [{ d: "M4 7h16M9 7V4h6v3M6 7l1 13h10l1-13M10 11v6M14 11v6", strokeWidth: 1.75 }],
36
- },
37
- "pencil": {
38
- name: "Pencil",
39
- viewBox: 24,
40
- shapes: [{ d: "M4 20l1-4L16 5l3 3L8 19zM14 7l3 3", strokeWidth: 1.75 }],
41
- },
42
- "download": {
43
- name: "Download",
44
- viewBox: 24,
45
- shapes: [{ d: "M12 4v11M7 10l5 5 5-5M4 20h16", strokeWidth: 1.75 }],
46
- },
47
- "upload": {
48
- name: "Upload",
49
- viewBox: 24,
50
- shapes: [{ d: "M12 20V9M7 14l5-5 5 5M4 4h16", strokeWidth: 1.75 }],
51
- },
52
- "bookmark": {
53
- name: "Bookmark",
54
- viewBox: 24,
55
- shapes: [{ d: "M6 3h12v18l-6-4-6 4z", strokeWidth: 1.75 }],
56
- },
57
- "calendar": {
58
- name: "Calendar",
59
- viewBox: 24,
60
- shapes: [{ d: "M4 6h16v14H4zM4 10h16M8 3v5M16 3v5", strokeWidth: 1.75 }],
61
- },
62
- "code": {
63
- name: "Code",
64
- viewBox: 24,
65
- shapes: [{ d: "M8 7l-5 5 5 5M16 7l5 5-5 5M14 4l-4 16", strokeWidth: 1.75 }],
66
- },
67
- "pin": {
68
- name: "Map pin",
69
- viewBox: 24,
70
- shapes: [{ d: "M12 21s-7-6.5-7-12a7 7 0 0 1 14 0c0 5.5-7 12-7 12zM12 6.5a2.5 2.5 0 1 0 0 5a2.5 2.5 0 1 0 0-5", strokeWidth: 1.75 }],
71
- },
72
- "camera": {
73
- name: "Camera",
74
- viewBox: 24,
75
- shapes: [{ d: "M4 8h3l2-3h6l2 3h3v11H4zM12 10a3.5 3.5 0 1 0 0 7a3.5 3.5 0 1 0 0-7", strokeWidth: 1.75 }],
76
- },
77
- "play": {
78
- name: "Play",
79
- viewBox: 24,
80
- shapes: [{ d: "M7 4l13 8-13 8z", strokeWidth: 1.75 }],
81
- },
82
- "music": {
83
- name: "Music",
84
- viewBox: 24,
85
- shapes: [{ d: "M9 18V5l11-2v13M9 18a3 3 0 1 1-6 0a3 3 0 1 1 6 0M20 16a3 3 0 1 1-6 0a3 3 0 1 1 6 0", strokeWidth: 1.75 }],
86
- },
87
- "chat": {
88
- name: "Chat",
89
- viewBox: 24,
90
- shapes: [{ d: "M4 5h16v11H9l-5 4z", strokeWidth: 1.75 }],
91
- },
92
- "mail": {
93
- name: "Mail",
94
- viewBox: 24,
95
- shapes: [{ d: "M3 6h18v12H3zM3 7l9 6 9-6", strokeWidth: 1.75 }],
96
- },
97
- "cart": {
98
- name: "Cart",
99
- viewBox: 24,
100
- shapes: [{ d: "M3 4h2l2.5 11h11L21 8H6.5M9 19.5a1 1 0 1 0 0 .1M18 19.5a1 1 0 1 0 0 .1", strokeWidth: 1.75 }],
101
- },
102
- "gift": {
103
- name: "Gift",
104
- viewBox: 24,
105
- shapes: [{ d: "M3 9h18v4H3zM5 13h14v8H5zM12 9v12M12 9c-2-4-6-4-6-1s6 1 6 1s6 2 6-1s-4-3-6 1", strokeWidth: 1.75 }],
106
- },
107
- "flag": {
108
- name: "Flag",
109
- viewBox: 24,
110
- shapes: [{ d: "M5 21V4M5 4h12l-2 4 2 4H5", strokeWidth: 1.75 }],
111
- },
112
- "sun": {
113
- name: "Sun",
114
- viewBox: 24,
115
- shapes: [{ d: "M12 8a4 4 0 1 0 0 8a4 4 0 1 0 0-8M12 2v2M12 20v2M2 12h2M20 12h2M5 5l1.5 1.5M17.5 17.5 19 19M5 19l1.5-1.5M17.5 6.5 19 5", strokeWidth: 1.75 }],
116
- },
117
- "moon": {
118
- name: "Moon",
119
- viewBox: 24,
120
- shapes: [{ d: "M20 14.5A8 8 0 1 1 9.5 4a6.5 6.5 0 0 0 10.5 10.5z", strokeWidth: 1.75 }],
121
- },
122
- "cloud": {
123
- name: "Cloud",
124
- viewBox: 24,
125
- shapes: [{ d: "M7 18a4 4 0 0 1-.5-8A6 6 0 0 1 18 9a4.5 4.5 0 0 1-.5 9z", strokeWidth: 1.75 }],
126
- },
127
- "leaf": {
128
- name: "Leaf",
129
- viewBox: 24,
130
- shapes: [{ d: "M5 19C5 10 11 5 20 4c-1 9-6 15-15 15zM5 19l8-8", strokeWidth: 1.75 }],
131
- },
132
- "bolt": {
133
- name: "Bolt",
134
- viewBox: 24,
135
- shapes: [{ d: "M13 2 4 14h7l-1 8 9-12h-7z", strokeWidth: 1.75 }],
136
- },
137
- "heart": {
138
- name: "Heart",
139
- viewBox: 24,
140
- shapes: [{ d: "M12 20s-7-4.35-9-9a4.5 4.5 0 0 1 9-3a4.5 4.5 0 0 1 9 3c-2 4.65-9 9-9 9z", strokeWidth: 1.75 }],
141
- },
142
- "star": {
143
- name: "Star",
144
- viewBox: 24,
145
- shapes: [{ d: "M12 3l2.7 5.6 6.1.9-4.4 4.3 1 6.1L12 17l-5.4 2.9 1-6.1L3.2 9.5l6.1-.9z", strokeWidth: 1.75 }],
146
- },
147
- "smile": {
148
- name: "Smile",
149
- viewBox: 24,
150
- shapes: [{ d: "M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18M8.5 14a4 4 0 0 0 7 0M9 9.5v.5M15 9.5v.5", strokeWidth: 1.75 }],
151
- },
152
- "rocket": {
153
- name: "Rocket",
154
- viewBox: 24,
155
- shapes: [{ d: "M12 15l-3-3c1.5-4.5 4.5-8 10-9-1 5.5-4.5 8.5-9 10zM9 12H5l3-4h4M12 15v4l4-3v-4M6 16c-2 1-2 4-2 4s3 0 4-2", strokeWidth: 1.75 }],
156
- },
157
- "coffee": {
158
- name: "Coffee",
159
- viewBox: 24,
160
- shapes: [{ d: "M4 8h13v6a5 5 0 0 1-5 5H9a5 5 0 0 1-5-5zM17 10h1.5a2.5 2.5 0 0 1 0 5H17M8 2v3M12 2v3", strokeWidth: 1.75 }],
161
- },
162
- };
163
- export const iconNames = Object.keys(icons);