@notseeyou/icons-css 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +126 -2
- package/dist/categories/arrows.css +410 -0
- package/dist/categories/charts.css +350 -0
- package/dist/categories/commerce.css +386 -0
- package/dist/categories/communication.css +386 -0
- package/dist/categories/development.css +338 -0
- package/dist/categories/devices.css +374 -0
- package/dist/categories/editing.css +380 -0
- package/dist/categories/files.css +386 -0
- package/dist/categories/interface.css +428 -0
- package/dist/categories/maps.css +374 -0
- package/dist/categories/media.css +392 -0
- package/dist/categories/objects.css +362 -0
- package/dist/categories/security.css +380 -0
- package/dist/categories/status.css +368 -0
- package/dist/categories/time.css +350 -0
- package/dist/categories/users.css +347 -0
- package/dist/categories/weather.css +356 -0
- package/dist/data.js +2 -0
- package/dist/duotone.css +2113 -0
- package/dist/line.css +2113 -0
- package/dist/solid.css +2113 -0
- package/lib/core.js +62 -0
- package/lib/index.d.ts +20 -0
- package/lib/index.js +4 -0
- package/lib/tailwind.d.ts +5 -0
- package/lib/tailwind.js +26 -0
- package/package.json +67 -4
package/lib/core.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Icon → CSS. Shared by the Tailwind plugin, getIconsCSS() and the prebuilt CSS files.
|
|
2
|
+
// The icon is the element's background (currentColor) cut out by a mask: an SVG
|
|
3
|
+
// data URI whose alpha is the icon. Duotone's secondary layer is drawn at 35 %
|
|
4
|
+
// opacity inside that SVG, so it shows as 35 % of the color.
|
|
5
|
+
import data from '../dist/data.js';
|
|
6
|
+
|
|
7
|
+
export const STYLES = ['line', 'solid', 'duotone'];
|
|
8
|
+
export const DUO_OPACITY = data.duoOpacity;
|
|
9
|
+
|
|
10
|
+
/** `home`, `home-solid`, `home-duotone` for every icon. */
|
|
11
|
+
export const iconIds = Object.keys(data.icons).flatMap((n) => [n, `${n}-solid`, `${n}-duotone`]);
|
|
12
|
+
|
|
13
|
+
/** `home` → { name: 'home', style: 'line' }; undefined for anything that is not an icon. */
|
|
14
|
+
export function parseIconId(id) {
|
|
15
|
+
if (typeof id !== 'string') return;
|
|
16
|
+
const m = /^(.+?)(?:-(solid|duotone))?$/.exec(id);
|
|
17
|
+
if (m && Object.hasOwn(data.icons, m[1])) return { name: m[1], style: m[2] ?? 'line' };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function maskSVG(id) {
|
|
21
|
+
const icon = parseIconId(id);
|
|
22
|
+
if (!icon) throw new Error(`unknown icon "${id}"`);
|
|
23
|
+
const [line, solid, secondary, primary] = data.icons[icon.name];
|
|
24
|
+
const body =
|
|
25
|
+
icon.style === 'duotone'
|
|
26
|
+
? `<path opacity="${String(DUO_OPACITY).replace(/^0\./, '.')}" d="${secondary}"/><path d="${primary}"/>`
|
|
27
|
+
: `<path d="${icon.style === 'solid' ? solid : line}"/>`;
|
|
28
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">${body}</svg>`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** SVG → `url("data:image/svg+xml,…")`, escaped for CSS (no base64: smaller after gzip). */
|
|
32
|
+
export const svgURL = (svg) =>
|
|
33
|
+
`url("data:image/svg+xml,${svg.replace(/"/g, "'").replace(/%/g, '%25').replace(/#/g, '%23').replace(/</g, '%3C').replace(/>/g, '%3E').replace(/\s+/g, ' ')}")`;
|
|
34
|
+
|
|
35
|
+
/** Declarations every icon class shares. 1em square, currentColor. */
|
|
36
|
+
export const COMMON = {
|
|
37
|
+
display: 'inline-block',
|
|
38
|
+
width: '1em',
|
|
39
|
+
height: '1em',
|
|
40
|
+
'flex-shrink': '0',
|
|
41
|
+
'background-color': 'currentColor',
|
|
42
|
+
'-webkit-mask-image': 'var(--nsy-icon)',
|
|
43
|
+
'mask-image': 'var(--nsy-icon)',
|
|
44
|
+
'-webkit-mask-repeat': 'no-repeat',
|
|
45
|
+
'mask-repeat': 'no-repeat',
|
|
46
|
+
'-webkit-mask-size': '100% 100%',
|
|
47
|
+
'mask-size': '100% 100%',
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const iconVar = (id) => ({ '--nsy-icon': svgURL(maskSVG(id)) });
|
|
51
|
+
|
|
52
|
+
const block = (decls) => Object.entries(decls).map(([k, v]) => `${k}:${v}`).join(';');
|
|
53
|
+
|
|
54
|
+
/** Plain CSS for the given icons: one shared rule (zero specificity) + one rule per icon. */
|
|
55
|
+
export function getIconsCSS(ids, { prefix = 'nsy' } = {}) {
|
|
56
|
+
if (!/^[a-z][a-z0-9-]*$/i.test(prefix)) throw new Error(`invalid prefix "${prefix}"`);
|
|
57
|
+
const list = [...new Set(ids)];
|
|
58
|
+
for (const id of list) if (!parseIconId(id)) throw new Error(`unknown icon "${id}"`);
|
|
59
|
+
if (!list.length) return '';
|
|
60
|
+
const cls = (id) => `.${prefix}-${id}`;
|
|
61
|
+
return `:where(${list.map(cls).join(',')}){${block(COMMON)}}\n` + list.map((id) => `${cls(id)}{${block(iconVar(id))}}\n`).join('');
|
|
62
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type IconStyle = 'line' | 'solid' | 'duotone';
|
|
2
|
+
export declare const STYLES: readonly IconStyle[];
|
|
3
|
+
|
|
4
|
+
/** Every class suffix: `home`, `home-solid`, `home-duotone`, … */
|
|
5
|
+
export declare const iconIds: readonly string[];
|
|
6
|
+
|
|
7
|
+
/** `home-solid` → `{ name: 'home', style: 'solid' }`; `undefined` for unknown ids. */
|
|
8
|
+
export declare function parseIconId(id: string): { name: string; style: IconStyle } | undefined;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Plain CSS for exactly these icons: `.nsy-home`, `.nsy-lock-solid`, … (or your `prefix`).
|
|
12
|
+
* One shared `:where(…)` rule (zero specificity, easy to override) plus one rule per icon.
|
|
13
|
+
* Throws on unknown ids.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getIconsCSS(ids: Iterable<string>, options?: { prefix?: string }): string;
|
|
16
|
+
|
|
17
|
+
/** The icon as a standalone SVG (black on transparent) — the mask image. */
|
|
18
|
+
export declare function maskSVG(id: string): string;
|
|
19
|
+
/** SVG → `url("data:image/svg+xml,…")` for CSS. */
|
|
20
|
+
export declare function svgURL(svg: string): string;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// Node / build-time API: CSS for exactly the icons you list.
|
|
2
|
+
// import { getIconsCSS } from '@notseeyou/icons-css';
|
|
3
|
+
// await writeFile('icons.css', getIconsCSS(['home', 'lock-solid', 'ghost-duotone']));
|
|
4
|
+
export { getIconsCSS, iconIds, parseIconId, maskSVG, svgURL, STYLES } from './core.js';
|
package/lib/tailwind.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Tailwind CSS v4 plugin: @plugin "@notseeyou/icons-css/tailwind";
|
|
2
|
+
// Classes nsy-home, nsy-home-solid, nsy-home-duotone. Tailwind emits CSS only for
|
|
3
|
+
// classes it finds in your sources, so unused icons cost nothing.
|
|
4
|
+
// @plugin "@notseeyou/icons-css/tailwind" { prefix: icon; } → icon-home …
|
|
5
|
+
import plugin from 'tailwindcss/plugin';
|
|
6
|
+
import { COMMON, iconIds, iconVar, parseIconId } from './core.js';
|
|
7
|
+
|
|
8
|
+
const values = Object.fromEntries(iconIds.map((id) => [id, id]));
|
|
9
|
+
|
|
10
|
+
export default plugin.withOptions((options = {}) => {
|
|
11
|
+
const prefix = String(options.prefix ?? 'nsy');
|
|
12
|
+
if (!/^[a-z][a-z0-9-]*$/i.test(prefix)) throw new Error(`@notseeyou/icons-css: invalid prefix "${prefix}"`);
|
|
13
|
+
return ({ matchUtilities }) => {
|
|
14
|
+
matchUtilities(
|
|
15
|
+
{
|
|
16
|
+
[prefix]: (value) => {
|
|
17
|
+
// Only known icons: nsy-[anything] and typos produce no CSS.
|
|
18
|
+
if (!parseIconId(value)) return {};
|
|
19
|
+
return { ...COMMON, ...iconVar(value) };
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
// type 'url': arbitrary values (nsy-[home]) never match an icon name, so they emit nothing.
|
|
23
|
+
{ values, type: 'url', supportsNegativeValues: false },
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,69 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@notseeyou/icons-css",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "NSY Icons for CSS — Tailwind CSS v4 plugin and plain CSS classes, 2111 icons × line, solid, duotone",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": [
|
|
8
|
+
"*.css"
|
|
9
|
+
],
|
|
10
|
+
"main": "./lib/index.js",
|
|
11
|
+
"types": "./lib/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./lib/index.d.ts",
|
|
15
|
+
"default": "./lib/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./tailwind": {
|
|
18
|
+
"types": "./lib/tailwind.d.ts",
|
|
19
|
+
"default": "./lib/tailwind.js"
|
|
20
|
+
},
|
|
21
|
+
"./line.css": "./dist/line.css",
|
|
22
|
+
"./solid.css": "./dist/solid.css",
|
|
23
|
+
"./duotone.css": "./dist/duotone.css",
|
|
24
|
+
"./categories/*.css": "./dist/categories/*.css",
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"lib",
|
|
29
|
+
"dist",
|
|
30
|
+
"README.md"
|
|
31
|
+
],
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"tailwindcss": ">=4.0.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependenciesMeta": {
|
|
36
|
+
"tailwindcss": {
|
|
37
|
+
"optional": true
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@resvg/resvg-js": "^2.6.2",
|
|
42
|
+
"@tailwindcss/node": "4.3.3",
|
|
43
|
+
"@tailwindcss/oxide": "4.3.3",
|
|
44
|
+
"tailwindcss": "4.3.3"
|
|
45
|
+
},
|
|
46
|
+
"author": "Not See You",
|
|
47
|
+
"homepage": "https://github.com/NOT-SEE-YOU/icons/tree/main/packages/css#readme",
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/NOT-SEE-YOU/icons.git",
|
|
51
|
+
"directory": "packages/css"
|
|
52
|
+
},
|
|
53
|
+
"bugs": {
|
|
54
|
+
"url": "https://github.com/NOT-SEE-YOU/icons/issues"
|
|
55
|
+
},
|
|
56
|
+
"keywords": [
|
|
57
|
+
"icons",
|
|
58
|
+
"icon-set",
|
|
59
|
+
"svg",
|
|
60
|
+
"nsy",
|
|
61
|
+
"not-see-you",
|
|
62
|
+
"line",
|
|
63
|
+
"solid",
|
|
64
|
+
"duotone"
|
|
65
|
+
],
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"access": "public"
|
|
68
|
+
}
|
|
69
|
+
}
|