@effectiveailabs/design-system 1.0.0 → 1.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/CHANGELOG.md +6 -0
- package/README.md +18 -13
- package/dist/components/Icon/Icon.d.ts +6 -3
- package/dist/components/Icon/Icon.js +21 -12
- package/dist/components/Icon/lucideIcons.d.ts +9 -0
- package/dist/components/Icon/lucideIcons.js +14 -0
- package/dist/components/Icon/lucideIconsOnDemand.d.ts +11 -0
- package/dist/components/Icon/lucideIconsOnDemand.js +48 -0
- package/dist/vite/index.d.ts +21 -0
- package/dist/vite/index.js +104 -0
- package/dist/vite/lucideIcons.d.ts +11 -0
- package/dist/vite/lucideIcons.js +53 -0
- package/package.json +19 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @effectiveai/design-system
|
|
2
2
|
|
|
3
|
+
## 1.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 9107640: Add `designSystem()` from `@effectiveailabs/design-system/vite`, the Vite plugins an app needs in place of a hand-written StyleX configuration. The development server pre-bundles the design system with its styles compiled, so a page loads it in a few dozen requests instead of thousands, and a production build bundles only the Lucide icons the app names in string literals and loads the rest of the set on first use. `@stylexjs/unplugin` and Vite 6 or 7 are optional peer dependencies.
|
|
8
|
+
|
|
3
9
|
## 1.0.0
|
|
4
10
|
|
|
5
11
|
### Major Changes
|
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@ this repository, import `@effectiveai/design-system` from the workspace instead.
|
|
|
22
22
|
| `@effectiveailabs/design-system/constants.stylex` | `layers`, the stacking order, and `viewportMedia`, the phone breakpoint |
|
|
23
23
|
| `@effectiveailabs/design-system/color` | `Color` values without React or StyleX, for workers and data code |
|
|
24
24
|
| `@effectiveailabs/design-system/files` | Contracts for file renderer and file source authors |
|
|
25
|
+
| `@effectiveailabs/design-system/vite` | The Vite plugins an app needs |
|
|
25
26
|
| `@effectiveailabs/design-system/experimental` | Work in progress, outside [versioning](#versioning) |
|
|
26
27
|
| `@effectiveailabs/design-system/stat-card.stylex` | Experimental StatCard's variables, outside versioning |
|
|
27
28
|
| `@effectiveailabs/design-system/tile-button.stylex` | Experimental TileButton's variables, outside versioning |
|
|
@@ -35,27 +36,31 @@ pnpm add @effectiveailabs/design-system @stylexjs/stylex react react-dom
|
|
|
35
36
|
pnpm add -D @stylexjs/unplugin
|
|
36
37
|
```
|
|
37
38
|
|
|
38
|
-
Build the app with Vite. Other bundlers are not supported yet: the
|
|
39
|
-
read Vite's `import.meta.env.DEV` to tell a development build from
|
|
40
|
-
production one. A Vite app
|
|
39
|
+
Build the app with Vite 6 or 7. Other bundlers are not supported yet: the
|
|
40
|
+
components read Vite's `import.meta.env.DEV` to tell a development build from
|
|
41
|
+
a production one. A Vite app adds the design system's plugins:
|
|
41
42
|
|
|
42
43
|
```ts
|
|
43
|
-
import
|
|
44
|
+
import { designSystem } from '@effectiveailabs/design-system/vite';
|
|
44
45
|
import react from '@vitejs/plugin-react';
|
|
45
46
|
import { defineConfig } from 'vite';
|
|
46
47
|
|
|
47
48
|
export default defineConfig({
|
|
48
|
-
plugins: [
|
|
49
|
-
optimizeDeps: {
|
|
50
|
-
// The StyleX plugin keeps the design system out of dependency
|
|
51
|
-
// pre-bundling, so Vite also skips this CommonJS module React Aria imports.
|
|
52
|
-
include: [
|
|
53
|
-
'@effectiveailabs/design-system > react-aria-components > use-sync-external-store/shim/index.js',
|
|
54
|
-
],
|
|
55
|
-
},
|
|
49
|
+
plugins: [designSystem(), react()],
|
|
56
50
|
});
|
|
57
51
|
```
|
|
58
52
|
|
|
53
|
+
`designSystem()` returns the StyleX plugin, with `useCSSLayers: false`, and a
|
|
54
|
+
plugin for the design system. Pass other StyleX options as
|
|
55
|
+
`designSystem({ stylex: { … } })`.
|
|
56
|
+
|
|
57
|
+
- The development server pre-bundles the design system with its styles
|
|
58
|
+
compiled. A page then loads it in a few requests, instead of one for each
|
|
59
|
+
module of it and of its dependencies: about 3,800 for a page with one card.
|
|
60
|
+
- A production build bundles only the Lucide icons that the app's source names
|
|
61
|
+
in string literals, such as `<Icon name="Calendar" />`. An `Icon` with any
|
|
62
|
+
other Lucide name, such as one from data, draws an empty glyph and loads the
|
|
63
|
+
rest of the set, once, from a separate file.
|
|
59
64
|
- Run Vite from the app's folder. The StyleX plugin compiles the packages that
|
|
60
65
|
the nearest `package.json` lists and that depend on `@stylexjs/stylex`.
|
|
61
66
|
- Import at least one stylesheet from the app's entry, such as
|
|
@@ -94,7 +99,7 @@ At the root, a `ThemeScope` follows the system's light or dark setting.
|
|
|
94
99
|
|
|
95
100
|
Releases follow [semantic versioning](https://semver.org) from 1.0.0. The
|
|
96
101
|
versioned API is everything the main entry, `./theming.stylex`,
|
|
97
|
-
`./constants.stylex`, `./color` and `./
|
|
102
|
+
`./constants.stylex`, `./color`, `./files` and `./vite` export: names, types, props, prop values and defaults, token names, and the
|
|
98
103
|
behavior the component guides describe, including roles, accessible names and
|
|
99
104
|
keyboard interaction.
|
|
100
105
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Color } from '../../foundations/Color.ts';
|
|
2
|
-
import type { LucideIcon } from 'lucide-react';
|
|
3
|
-
import { icons } from 'lucide-react';
|
|
2
|
+
import type { icons, LucideIcon } from 'lucide-react';
|
|
4
3
|
import type { CommonIconName, CustomIconName, SemanticIconName } from './Icon.registry.ts';
|
|
5
4
|
export type LucideIconName = Extract<keyof typeof icons, string>;
|
|
6
5
|
export type { CommonIconName, CustomIconName, SemanticIconName };
|
|
@@ -43,5 +42,9 @@ export declare function IconGlyph({ fill, glyph, isDisabled, label, size, tone,
|
|
|
43
42
|
* icons. `Icon` draws a placeholder for any other name.
|
|
44
43
|
*/
|
|
45
44
|
export declare function isIconName(name: string): name is IconName;
|
|
46
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* The glyph a registered name draws, falling back to a question mark. Package-internal, for the
|
|
47
|
+
* file and folder marks, which pass format and site names. A Lucide name outside the registries
|
|
48
|
+
* draws through `Icon`, which loads it on demand in an app's build.
|
|
49
|
+
*/
|
|
47
50
|
export declare function resolveIcon(name: IconName | undefined): LucideIcon;
|
|
@@ -3,10 +3,11 @@ import { Color } from "../../foundations/Color.js";
|
|
|
3
3
|
import { colorStyles } from "../../foundations/Color.styles.stylex.js";
|
|
4
4
|
import * as stylex from '@stylexjs/stylex';
|
|
5
5
|
import { useSkeleton } from "../Skeleton/useSkeleton.js";
|
|
6
|
-
import { CircleHelp
|
|
6
|
+
import { CircleHelp } from 'lucide-react';
|
|
7
7
|
import { commonIcons, customIcons, semanticIcons } from "./Icon.registry.js";
|
|
8
8
|
import { styles } from "./Icon.stylex.js";
|
|
9
9
|
import { FilledIcon } from "./FilledIcon.js";
|
|
10
|
+
import { isLucideIconName, useLucideIcon } from "./lucideIcons.js";
|
|
10
11
|
export { commonIconNames, customIconNames, semanticIconNames } from "./Icon.registry.js";
|
|
11
12
|
export const iconSizes = ['xSmall', 'small', 'medium', 'large', 'font'];
|
|
12
13
|
export const iconTones = [
|
|
@@ -55,7 +56,9 @@ const fillableIcons = new Set([
|
|
|
55
56
|
'Square',
|
|
56
57
|
]);
|
|
57
58
|
export function Icon({ isFilled = false, isDisabled = false, label, name, size = 'medium', tone = 'inherit', weight = 'regular', }) {
|
|
58
|
-
|
|
59
|
+
const registeredIcon = resolveRegisteredIcon(name);
|
|
60
|
+
const lucideIcon = useLucideIcon(registeredIcon === undefined ? name : undefined);
|
|
61
|
+
return (_jsx(IconGlyph, { fill: !isFilled ? 'none' : supportsIconFill(name) ? 'native' : 'square', glyph: registeredIcon ?? lucideIcon ?? CircleHelp, isDisabled: isDisabled, label: label, size: size, tone: tone, weight: weight }));
|
|
59
62
|
}
|
|
60
63
|
/** Renders a glyph with the Icon contract's size, tone, label and skeleton. Package-internal. */
|
|
61
64
|
export function IconGlyph({ fill, glyph, isDisabled, label, size, tone, weight }) {
|
|
@@ -86,16 +89,22 @@ function supportsIconFill(name) {
|
|
|
86
89
|
* icons. `Icon` draws a placeholder for any other name.
|
|
87
90
|
*/
|
|
88
91
|
export function isIconName(name) {
|
|
89
|
-
return [semanticIcons, customIcons, commonIcons
|
|
92
|
+
return ([semanticIcons, customIcons, commonIcons].some((set) => Object.hasOwn(set, name)) ||
|
|
93
|
+
isLucideIconName(name));
|
|
90
94
|
}
|
|
91
|
-
/**
|
|
95
|
+
/**
|
|
96
|
+
* The glyph a registered name draws, falling back to a question mark. Package-internal, for the
|
|
97
|
+
* file and folder marks, which pass format and site names. A Lucide name outside the registries
|
|
98
|
+
* draws through `Icon`, which loads it on demand in an app's build.
|
|
99
|
+
*/
|
|
92
100
|
export function resolveIcon(name) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
+
return resolveRegisteredIcon(name) ?? CircleHelp;
|
|
102
|
+
}
|
|
103
|
+
/** The registries' icon for a name, or undefined for a Lucide name outside them. */
|
|
104
|
+
function resolveRegisteredIcon(name) {
|
|
105
|
+
if (name === undefined)
|
|
106
|
+
return CircleHelp;
|
|
107
|
+
return (semanticIcons[name] ??
|
|
108
|
+
customIcons[name] ??
|
|
109
|
+
commonIcons[name]);
|
|
101
110
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { LucideIcon } from 'lucide-react';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves a name the icon registries do not hold against the whole Lucide set, which this module
|
|
4
|
+
* bundles. In a production build, the design system's Vite preset puts `createOnDemandLucideIcons`
|
|
5
|
+
* in this module's place, so the app bundles only the Lucide icons its source names.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useLucideIcon(name: string | undefined): LucideIcon | undefined;
|
|
8
|
+
/** Whether a name is one of Lucide's icons. */
|
|
9
|
+
export declare function isLucideIconName(name: string): boolean;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { icons } from 'lucide-react';
|
|
2
|
+
const lucideIcons = icons;
|
|
3
|
+
/**
|
|
4
|
+
* Resolves a name the icon registries do not hold against the whole Lucide set, which this module
|
|
5
|
+
* bundles. In a production build, the design system's Vite preset puts `createOnDemandLucideIcons`
|
|
6
|
+
* in this module's place, so the app bundles only the Lucide icons its source names.
|
|
7
|
+
*/
|
|
8
|
+
export function useLucideIcon(name) {
|
|
9
|
+
return name === undefined ? undefined : lucideIcons[name];
|
|
10
|
+
}
|
|
11
|
+
/** Whether a name is one of Lucide's icons. */
|
|
12
|
+
export function isLucideIconName(name) {
|
|
13
|
+
return Object.hasOwn(lucideIcons, name);
|
|
14
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { LucideIcon } from 'lucide-react';
|
|
2
|
+
type LucideIconSet = Readonly<Record<string, LucideIcon | undefined>>;
|
|
3
|
+
/** An empty glyph, drawn at the icon's size while the rest of the Lucide set loads. */
|
|
4
|
+
export declare const PendingLucideIcon: import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
|
|
5
|
+
/**
|
|
6
|
+
* Builds the Lucide lookup the design system's Vite preset puts in an app's production build in
|
|
7
|
+
* place of `lucideIcons.ts`. `bundled` holds the icons the app's source names. Any other name
|
|
8
|
+
* draws an empty glyph and loads the rest of the set, once, then redraws.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createOnDemandLucideIcons(bundled: LucideIconSet, loadAll: () => Promise<LucideIconSet>): (name: string | undefined) => LucideIcon | undefined;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createLucideIcon } from 'lucide-react';
|
|
2
|
+
import { useEffect, useSyncExternalStore } from 'react';
|
|
3
|
+
/** An empty glyph, drawn at the icon's size while the rest of the Lucide set loads. */
|
|
4
|
+
export const PendingLucideIcon = createLucideIcon('pending', []);
|
|
5
|
+
/**
|
|
6
|
+
* Builds the Lucide lookup the design system's Vite preset puts in an app's production build in
|
|
7
|
+
* place of `lucideIcons.ts`. `bundled` holds the icons the app's source names. Any other name
|
|
8
|
+
* draws an empty glyph and loads the rest of the set, once, then redraws.
|
|
9
|
+
*/
|
|
10
|
+
export function createOnDemandLucideIcons(bundled, loadAll) {
|
|
11
|
+
let all;
|
|
12
|
+
let loading;
|
|
13
|
+
const listeners = new Set();
|
|
14
|
+
const subscribe = (listener) => {
|
|
15
|
+
listeners.add(listener);
|
|
16
|
+
return () => {
|
|
17
|
+
listeners.delete(listener);
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
const load = () => {
|
|
21
|
+
loading ??= loadAll().then((icons) => {
|
|
22
|
+
all = icons;
|
|
23
|
+
for (const listener of listeners)
|
|
24
|
+
listener();
|
|
25
|
+
}, () => {
|
|
26
|
+
// The next icon that needs the set tries again.
|
|
27
|
+
loading = undefined;
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
const resolve = (name) => {
|
|
31
|
+
if (name === undefined)
|
|
32
|
+
return undefined;
|
|
33
|
+
if (all === undefined)
|
|
34
|
+
return bundled[name] ?? PendingLucideIcon;
|
|
35
|
+
return bundled[name] ?? all[name];
|
|
36
|
+
};
|
|
37
|
+
// The server never loads the set, and hydration must draw what the server drew.
|
|
38
|
+
const resolveOnServer = (name) => name === undefined ? undefined : (bundled[name] ?? PendingLucideIcon);
|
|
39
|
+
return function useLucideIcon(name) {
|
|
40
|
+
const icon = useSyncExternalStore(subscribe, () => resolve(name), () => resolveOnServer(name));
|
|
41
|
+
const isPending = icon === PendingLucideIcon;
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (isPending)
|
|
44
|
+
load();
|
|
45
|
+
}, [isPending]);
|
|
46
|
+
return icon;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type UserOptions as StyleXOptions } from '@stylexjs/unplugin';
|
|
2
|
+
import type { PluginOption } from 'vite';
|
|
3
|
+
/** @public */
|
|
4
|
+
export type DesignSystemOptions = {
|
|
5
|
+
/** Options for the StyleX plugin, which compiles the app's styles and the design system's. */
|
|
6
|
+
readonly stylex?: Partial<StyleXOptions>;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The Vite plugins an app needs to use the design system: StyleX, a fast development server
|
|
10
|
+
* and small builds.
|
|
11
|
+
*
|
|
12
|
+
* - The StyleX plugin compiles the app's `stylex.create` calls and the design system's styles.
|
|
13
|
+
* - The development server pre-bundles the design system with its styles compiled, so a page
|
|
14
|
+
* loads it in a few requests instead of one for each module of it and its dependencies.
|
|
15
|
+
* - A production build bundles only the Lucide icons that the app's source names in string
|
|
16
|
+
* literals. An `Icon` with any other name, such as one from data, loads the rest of the set
|
|
17
|
+
* the first time it renders.
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export declare function designSystem(options?: DesignSystemOptions): PluginOption[];
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { unplugin as stylex, unpluginFactory, } from '@stylexjs/unplugin';
|
|
6
|
+
import { findLucideIconNames, onDemandLucideIconsModule } from "./lucideIcons.js";
|
|
7
|
+
// This module runs from dist/vite in the published package and from src/vite in the repository.
|
|
8
|
+
const moduleFile = fileURLToPath(import.meta.url);
|
|
9
|
+
const moduleExtension = path.extname(moduleFile);
|
|
10
|
+
const codeDirectory = path.resolve(path.dirname(moduleFile), '..');
|
|
11
|
+
const packageDirectory = fs.realpathSync(path.resolve(codeDirectory, '..'));
|
|
12
|
+
const packageName = JSON.parse(fs.readFileSync(path.join(packageDirectory, 'package.json'), 'utf8')).name;
|
|
13
|
+
const lucideIconsModule = fs.realpathSync(path.join(codeDirectory, `components/Icon/lucideIcons${moduleExtension}`));
|
|
14
|
+
/**
|
|
15
|
+
* The Vite plugins an app needs to use the design system: StyleX, a fast development server
|
|
16
|
+
* and small builds.
|
|
17
|
+
*
|
|
18
|
+
* - The StyleX plugin compiles the app's `stylex.create` calls and the design system's styles.
|
|
19
|
+
* - The development server pre-bundles the design system with its styles compiled, so a page
|
|
20
|
+
* loads it in a few requests instead of one for each module of it and its dependencies.
|
|
21
|
+
* - A production build bundles only the Lucide icons that the app's source names in string
|
|
22
|
+
* literals. An `Icon` with any other name, such as one from data, loads the rest of the set
|
|
23
|
+
* the first time it renders.
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
export function designSystem(options = {}) {
|
|
28
|
+
const stylexOptions = { useCSSLayers: false, ...options.stylex };
|
|
29
|
+
return [stylex.vite(stylexOptions), designSystemPlugin(stylexOptions)];
|
|
30
|
+
}
|
|
31
|
+
function designSystemPlugin(stylexOptions) {
|
|
32
|
+
let isBuild = false;
|
|
33
|
+
let root = process.cwd();
|
|
34
|
+
let outDir = path.join(root, 'dist');
|
|
35
|
+
let iconNames;
|
|
36
|
+
let allIconNames = [];
|
|
37
|
+
return {
|
|
38
|
+
name: 'effective-design-system',
|
|
39
|
+
config(config, { command }) {
|
|
40
|
+
if (command !== 'serve')
|
|
41
|
+
return undefined;
|
|
42
|
+
// The StyleX plugin keeps each package that uses StyleX out of dependency pre-bundling,
|
|
43
|
+
// so that it compiles their styles, and the browser then requests every module of the
|
|
44
|
+
// design system and of its dependencies one by one. Pre-bundle the design system anyway
|
|
45
|
+
// and compile its styles while bundling.
|
|
46
|
+
const exclude = config.optimizeDeps?.exclude;
|
|
47
|
+
if (config.optimizeDeps && exclude) {
|
|
48
|
+
config.optimizeDeps.exclude = exclude.filter((name) => name !== packageName);
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
optimizeDeps: {
|
|
52
|
+
esbuildOptions: {
|
|
53
|
+
plugins: [compileStylesWhilePreBundling(stylexOptions)],
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
configResolved(config) {
|
|
59
|
+
isBuild = config.command === 'build';
|
|
60
|
+
root = config.root;
|
|
61
|
+
outDir = path.resolve(config.root, config.build.outDir);
|
|
62
|
+
},
|
|
63
|
+
buildStart() {
|
|
64
|
+
if (!isBuild)
|
|
65
|
+
return;
|
|
66
|
+
const lucide = createRequire(import.meta.url)('lucide-react');
|
|
67
|
+
allIconNames = Object.keys(lucide.icons);
|
|
68
|
+
iconNames = findLucideIconNames(allIconNames, [root, codeDirectory], [outDir]);
|
|
69
|
+
},
|
|
70
|
+
async load(id) {
|
|
71
|
+
if (iconNames === undefined || id.split('?')[0] !== lucideIconsModule)
|
|
72
|
+
return undefined;
|
|
73
|
+
return onDemandLucideIconsModule(await iconNames, allIconNames, moduleExtension);
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Compiles the design system's styles while Vite pre-bundles it. The compiled modules inject
|
|
79
|
+
* their rules as they load: pre-bundled code skips the StyleX plugin, which collects the
|
|
80
|
+
* rules of the app's own files into the development stylesheet.
|
|
81
|
+
*/
|
|
82
|
+
function compileStylesWhilePreBundling(stylexOptions) {
|
|
83
|
+
const compiler = unpluginFactory({ ...stylexOptions, runtimeInjection: true },
|
|
84
|
+
// StyleX reads only the framework; unplugin 3 also requires the versions map.
|
|
85
|
+
{ framework: 'esbuild', versions: {} });
|
|
86
|
+
const filter = new RegExp(`^${escapeRegExp(packageDirectory)}/.*\\.[jt]sx?$`);
|
|
87
|
+
return {
|
|
88
|
+
name: 'effective-design-system:stylex',
|
|
89
|
+
setup(build) {
|
|
90
|
+
build.onLoad({ filter }, async ({ path: file }) => {
|
|
91
|
+
const code = await fs.promises.readFile(file, 'utf8');
|
|
92
|
+
const compiled = await compiler.transform.call({}, code, file);
|
|
93
|
+
const extension = path.extname(file).slice(1);
|
|
94
|
+
return {
|
|
95
|
+
contents: compiled?.code ?? code,
|
|
96
|
+
loader: extension === 'ts' || extension === 'tsx' || extension === 'jsx' ? extension : 'js',
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function escapeRegExp(value) {
|
|
103
|
+
return value.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&');
|
|
104
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Lucide icon names that appear as string literals in the JavaScript and TypeScript files
|
|
3
|
+
* under `directories`, other than in `node_modules`, hidden folders and `skip`.
|
|
4
|
+
*/
|
|
5
|
+
export declare function findLucideIconNames(iconNames: Iterable<string>, directories: readonly string[], skip?: readonly string[]): Promise<readonly string[]>;
|
|
6
|
+
/**
|
|
7
|
+
* The module a production build loads in place of the design system's `lucideIcons` module:
|
|
8
|
+
* it bundles the named icons and loads the rest of the set on first use. It keeps every Lucide
|
|
9
|
+
* name, `allNames`, so `isIconName` answers without loading the set.
|
|
10
|
+
*/
|
|
11
|
+
export declare function onDemandLucideIconsModule(names: readonly string[], allNames: readonly string[], extension: string): string;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
const SOURCE_FILE = /\.[cm]?[jt]sx?$/;
|
|
4
|
+
const STRING_LITERAL = /(['"`])([A-Z][A-Za-z0-9]*)\1/g;
|
|
5
|
+
/**
|
|
6
|
+
* The Lucide icon names that appear as string literals in the JavaScript and TypeScript files
|
|
7
|
+
* under `directories`, other than in `node_modules`, hidden folders and `skip`.
|
|
8
|
+
*/
|
|
9
|
+
export async function findLucideIconNames(iconNames, directories, skip = []) {
|
|
10
|
+
const known = new Set(iconNames);
|
|
11
|
+
const found = new Set();
|
|
12
|
+
const visit = async (directory) => {
|
|
13
|
+
const entries = await fs.promises.readdir(directory, {
|
|
14
|
+
withFileTypes: true,
|
|
15
|
+
});
|
|
16
|
+
await Promise.all(entries.map(async (entry) => {
|
|
17
|
+
const file = path.join(directory, entry.name);
|
|
18
|
+
if (entry.isDirectory()) {
|
|
19
|
+
const skipped = entry.name === 'node_modules' || entry.name.startsWith('.') || skip.includes(file);
|
|
20
|
+
if (!skipped)
|
|
21
|
+
await visit(file);
|
|
22
|
+
}
|
|
23
|
+
else if (entry.isFile() && SOURCE_FILE.test(entry.name)) {
|
|
24
|
+
const source = await fs.promises.readFile(file, 'utf8');
|
|
25
|
+
for (const [, , name] of source.matchAll(STRING_LITERAL)) {
|
|
26
|
+
if (name !== undefined && known.has(name))
|
|
27
|
+
found.add(name);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}));
|
|
31
|
+
};
|
|
32
|
+
await Promise.all(directories.map(visit));
|
|
33
|
+
return [...found].sort();
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The module a production build loads in place of the design system's `lucideIcons` module:
|
|
37
|
+
* it bundles the named icons and loads the rest of the set on first use. It keeps every Lucide
|
|
38
|
+
* name, `allNames`, so `isIconName` answers without loading the set.
|
|
39
|
+
*/
|
|
40
|
+
export function onDemandLucideIconsModule(names, allNames, extension) {
|
|
41
|
+
const imports = names.map((name, index) => `${name} as i${index}`).join(', ');
|
|
42
|
+
const entries = names.map((name, index) => `${name}: i${index}`).join(', ');
|
|
43
|
+
return [
|
|
44
|
+
`import { createOnDemandLucideIcons } from './lucideIconsOnDemand${extension}';`,
|
|
45
|
+
...(names.length > 0 ? [`import { ${imports} } from 'lucide-react';`] : []),
|
|
46
|
+
`export const useLucideIcon = createOnDemandLucideIcons({ ${entries} }, () =>`,
|
|
47
|
+
` import('lucide-react/dist/esm/icons/index.js')`,
|
|
48
|
+
');',
|
|
49
|
+
`const lucideIconNames = new Set(${JSON.stringify(allNames.join(','))}.split(','));`,
|
|
50
|
+
'export const isLucideIconName = (name) => lucideIconNames.has(name);',
|
|
51
|
+
'',
|
|
52
|
+
].join('\n');
|
|
53
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effectiveailabs/design-system",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"description": "Semantic React components, StyleX design tokens and interface guidelines for Effective apps.",
|
|
@@ -39,6 +39,10 @@
|
|
|
39
39
|
"types": "./dist/foundations/Color.core.d.ts",
|
|
40
40
|
"import": "./dist/foundations/Color.core.js"
|
|
41
41
|
},
|
|
42
|
+
"./vite": {
|
|
43
|
+
"types": "./dist/vite/index.d.ts",
|
|
44
|
+
"import": "./dist/vite/index.js"
|
|
45
|
+
},
|
|
42
46
|
"./package.json": "./package.json"
|
|
43
47
|
},
|
|
44
48
|
"files": [
|
|
@@ -80,7 +84,8 @@
|
|
|
80
84
|
"./color",
|
|
81
85
|
"./constants.stylex",
|
|
82
86
|
"./files",
|
|
83
|
-
"./theming.stylex"
|
|
87
|
+
"./theming.stylex",
|
|
88
|
+
"./vite"
|
|
84
89
|
]
|
|
85
90
|
}
|
|
86
91
|
},
|
|
@@ -116,8 +121,18 @@
|
|
|
116
121
|
},
|
|
117
122
|
"peerDependencies": {
|
|
118
123
|
"@stylexjs/stylex": "^0.19.0",
|
|
124
|
+
"@stylexjs/unplugin": "^0.19.0",
|
|
119
125
|
"react": "^19.2.0",
|
|
120
|
-
"react-dom": "^19.2.0"
|
|
126
|
+
"react-dom": "^19.2.0",
|
|
127
|
+
"vite": "^6.0.0 || ^7.0.0"
|
|
128
|
+
},
|
|
129
|
+
"peerDependenciesMeta": {
|
|
130
|
+
"@stylexjs/unplugin": {
|
|
131
|
+
"optional": true
|
|
132
|
+
},
|
|
133
|
+
"vite": {
|
|
134
|
+
"optional": true
|
|
135
|
+
}
|
|
121
136
|
},
|
|
122
137
|
"devDependencies": {
|
|
123
138
|
"@effectiveai/tsconfig": "file:../../../toolchain/packages/tsconfig",
|
|
@@ -142,6 +157,6 @@
|
|
|
142
157
|
"@effectiveai/util-code-highlight": "0.0.0"
|
|
143
158
|
},
|
|
144
159
|
"scripts": {
|
|
145
|
-
"build": "rm -rf dist && tsc -p tsconfig.build.json"
|
|
160
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json && tsc -p src/vite"
|
|
146
161
|
}
|
|
147
162
|
}
|