@dxos/vite-plugin-icons 0.0.0-stage → 0.0.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.
Files changed (54) hide show
  1. package/LICENSE +105 -0
  2. package/dist/src/dev-sprite.test.d.ts +2 -0
  3. package/dist/src/dev-sprite.test.d.ts.map +1 -0
  4. package/dist/src/dev-sprite.test.js +99 -0
  5. package/dist/src/dev-sprite.test.js.map +1 -0
  6. package/dist/src/icon-assets.d.ts +22 -0
  7. package/dist/src/icon-assets.d.ts.map +1 -0
  8. package/dist/src/icon-assets.js +68 -0
  9. package/dist/src/icon-assets.js.map +1 -0
  10. package/dist/src/icon-assets.test.d.ts +2 -0
  11. package/dist/src/icon-assets.test.d.ts.map +1 -0
  12. package/dist/src/icon-assets.test.js +36 -0
  13. package/dist/src/icon-assets.test.js.map +1 -0
  14. package/dist/src/index.d.ts +26 -0
  15. package/dist/src/index.d.ts.map +1 -0
  16. package/dist/src/index.js +352 -0
  17. package/dist/src/index.js.map +1 -0
  18. package/dist/src/normalize-sprite.d.ts +22 -0
  19. package/dist/src/normalize-sprite.d.ts.map +1 -0
  20. package/dist/src/normalize-sprite.js +65 -0
  21. package/dist/src/normalize-sprite.js.map +1 -0
  22. package/dist/src/normalize-sprite.test.d.ts +2 -0
  23. package/dist/src/normalize-sprite.test.d.ts.map +1 -0
  24. package/dist/src/normalize-sprite.test.js +73 -0
  25. package/dist/src/normalize-sprite.test.js.map +1 -0
  26. package/dist/src/resolve-symbols.d.ts +42 -0
  27. package/dist/src/resolve-symbols.d.ts.map +1 -0
  28. package/dist/src/resolve-symbols.js +36 -0
  29. package/dist/src/resolve-symbols.js.map +1 -0
  30. package/dist/src/resolve-symbols.test.d.ts +2 -0
  31. package/dist/src/resolve-symbols.test.d.ts.map +1 -0
  32. package/dist/src/resolve-symbols.test.js +58 -0
  33. package/dist/src/resolve-symbols.test.js.map +1 -0
  34. package/dist/src/symbol-pattern.d.ts +20 -0
  35. package/dist/src/symbol-pattern.d.ts.map +1 -0
  36. package/dist/src/symbol-pattern.js +29 -0
  37. package/dist/src/symbol-pattern.js.map +1 -0
  38. package/dist/src/symbol-pattern.test.d.ts +2 -0
  39. package/dist/src/symbol-pattern.test.d.ts.map +1 -0
  40. package/dist/src/symbol-pattern.test.js +66 -0
  41. package/dist/src/symbol-pattern.test.js.map +1 -0
  42. package/dist/tsconfig.tsbuildinfo +1 -0
  43. package/package.json +35 -3
  44. package/src/dev-sprite.test.ts +112 -0
  45. package/src/icon-assets.test.ts +44 -0
  46. package/src/icon-assets.ts +82 -0
  47. package/src/index.ts +425 -0
  48. package/src/normalize-sprite.test.ts +101 -0
  49. package/src/normalize-sprite.ts +77 -0
  50. package/src/resolve-symbols.test.ts +74 -0
  51. package/src/resolve-symbols.ts +76 -0
  52. package/src/symbol-pattern.test.ts +77 -0
  53. package/src/symbol-pattern.ts +45 -0
  54. package/README.md +0 -3
package/LICENSE ADDED
@@ -0,0 +1,105 @@
1
+ # Functional Source License, Version 1.1, ALv2 Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-Apache-2.0
6
+
7
+ ## Notice
8
+
9
+ Copyright 2026 DXOS
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=dev-sprite.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev-sprite.test.d.ts","sourceRoot":"","sources":["../../src/dev-sprite.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,99 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+ import fs from 'fs';
5
+ import { tmpdir } from 'os';
6
+ import { join } from 'path';
7
+ import { createServer } from 'vite';
8
+ import { afterEach, beforeEach, describe, expect, test } from 'vitest';
9
+ import { IconsPlugin } from './index.js';
10
+ import { iconSymbolPattern } from './symbol-pattern.js';
11
+ const SVG = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"><path d="M0 0h10v10H0z"/></svg>';
12
+ describe('dev sprite', () => {
13
+ let root;
14
+ const servers = [];
15
+ beforeEach(() => {
16
+ // Real path: Vite resolves module ids through symlinks (macOS `/var` → `/private/var`), and the
17
+ // content globs must match those ids.
18
+ root = fs.realpathSync(fs.mkdtempSync(join(tmpdir(), 'icons-test-')));
19
+ fs.mkdirSync(join(root, 'src'));
20
+ fs.mkdirSync(join(root, 'assets'));
21
+ fs.mkdirSync(join(root, 'public'));
22
+ for (const name of ['alpha', 'beta']) {
23
+ fs.writeFileSync(join(root, 'assets', `${name}.svg`), SVG);
24
+ fs.writeFileSync(join(root, 'src', `${name}.ts`), `export const icon = 'ph--${name}--regular';\n`);
25
+ }
26
+ });
27
+ afterEach(async () => {
28
+ await Promise.all(servers.splice(0).map((server) => server.close()));
29
+ fs.rmSync(root, { recursive: true, force: true });
30
+ });
31
+ const startServer = async () => {
32
+ const server = await createServer({
33
+ configFile: false,
34
+ root,
35
+ publicDir: join(root, 'public'),
36
+ logLevel: 'silent',
37
+ server: { port: 0, strictPort: false, ws: false, watch: null },
38
+ plugins: [
39
+ IconsPlugin({
40
+ symbolPattern: iconSymbolPattern({ sets: ['ph'] }),
41
+ assetPath: (_iconSet, name) => join(root, 'assets', `${name}.svg`),
42
+ contentPaths: [join(root, 'src/**/*.ts')],
43
+ spriteFile: 'icons.svg',
44
+ }),
45
+ ],
46
+ });
47
+ servers.push(server);
48
+ await server.listen();
49
+ const url = server.resolvedUrls?.local[0];
50
+ if (!url) {
51
+ throw new Error('Dev server has no local URL.');
52
+ }
53
+ return {
54
+ load: (module) => server.transformRequest(`/src/${module}.ts`),
55
+ sprite: async () => {
56
+ const response = await fetch(new URL('icons.svg', url));
57
+ expect(response.status).toBe(200);
58
+ return response.text();
59
+ },
60
+ };
61
+ };
62
+ test('serves the symbols found in the modules it transformed', async () => {
63
+ const server = await startServer();
64
+ await server.load('alpha');
65
+ expect(await server.sprite()).toContain('id="ph--alpha--regular"');
66
+ });
67
+ test('a request during an in-flight write receives the completed sprite', async () => {
68
+ const server = await startServer();
69
+ await server.load('alpha');
70
+ expect(await server.sprite()).toContain('id="ph--alpha--regular"');
71
+ await server.load('beta');
72
+ // Whichever request lands first flushes the pending write; the other finds it in flight with the
73
+ // `alpha`-only sprite still on disk, and must wait rather than serve that.
74
+ const sprites = await Promise.all([server.sprite(), server.sprite()]);
75
+ for (const sprite of sprites) {
76
+ expect(sprite).toContain('id="ph--beta--regular"');
77
+ expect(sprite.trim().endsWith('</svg>')).toBe(true);
78
+ }
79
+ });
80
+ test('a second server sharing the public dir cannot replace the sprite the first one serves', async () => {
81
+ // The shared storybook and every storybook vitest run load the same config, and so the same publicDir.
82
+ const shared = await startServer();
83
+ await shared.load('alpha');
84
+ expect(await shared.sprite()).toContain('id="ph--alpha--regular"');
85
+ const testRun = await startServer();
86
+ await testRun.load('beta');
87
+ const testRunSprite = await testRun.sprite();
88
+ expect(testRunSprite).toContain('id="ph--beta--regular"');
89
+ expect(testRunSprite).not.toContain('id="ph--alpha--regular"');
90
+ expect(await shared.sprite()).toContain('id="ph--alpha--regular"');
91
+ expect(fs.existsSync(join(root, 'public', 'icons.svg'))).toBe(false);
92
+ });
93
+ test('removes a sprite left in the public dir, which a static server would serve ahead of its own', async () => {
94
+ fs.writeFileSync(join(root, 'public', 'icons.svg'), '<svg xmlns="http://www.w3.org/2000/svg"/>');
95
+ await startServer();
96
+ expect(fs.existsSync(join(root, 'public', 'icons.svg'))).toBe(false);
97
+ });
98
+ });
99
+ //# sourceMappingURL=dev-sprite.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev-sprite.test.js","sourceRoot":"","sources":["../../src/dev-sprite.test.ts"],"names":[],"mappings":"AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;AAEF,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAsB,YAAY,EAAE,MAAM,MAAM,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEvE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,MAAM,GAAG,GAAG,6FAA6F,CAAC;AAE1G,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,IAAI,IAAY,CAAC;IACjB,MAAM,OAAO,GAAoB,EAAE,CAAC;IAEpC,UAAU,CAAC,GAAG,EAAE;QACd,gGAAgG;QAChG,sCAAsC;QACtC,IAAI,GAAG,EA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AW,EAAE,CAAC;QACpC,MAAM,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC3B,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC;QAC7C,MAAM,CAAC,aAAa,CAAC,CAAC,SAAS,CAAC,wBAAwB,CAAC,CAAC;QAC1D,MAAM,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,yBAAyB,CAAC,CAAC;QAE/D,MAAM,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,yBAAyB,CAAC,CAAC;QACnE,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,6FAA6F,EAAE,KAAK,IAAI,EAAE;QAC7G,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,WAAW,CAAC,EAAE,2CAA2C,CAAC,CAAC;QACjG,MAAM,WAAW,EAAE,CAAC;QACpB,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { Plugin } from 'vite';
2
+ export type IconAssets = {
3
+ /** Public route prefix the catalog is served under, e.g. `/phosphor`. */
4
+ route: string;
5
+ /** Directory containing the icon-set catalog, e.g. `node_modules/@phosphor-icons/core/assets`. */
6
+ dir: string;
7
+ /**
8
+ * Copy the catalog into the build output (default `true`). `false` serves it from the dev server
9
+ * only — for a host whose dev sprite can trail the modules it serves but whose builds must not
10
+ * carry thousands of files.
11
+ */
12
+ copy?: boolean;
13
+ };
14
+ /**
15
+ * Serves an icon-set catalog as individual SVGs under `{route}/...`, so runtime icon
16
+ * resolvers (e.g. @dxos/react-ui's IconRegistry) can fetch glyphs that weren't statically
17
+ * referenced — icons used only by runtime-loaded plugins.
18
+ *
19
+ * In dev: middleware streams from `dir`. In build: assets are copied into the output dir unless `copy` is false.
20
+ */
21
+ export declare const iconAssetsPlugin: ({ route, dir, copy }: IconAssets) => Plugin;
22
+ //# sourceMappingURL=icon-assets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"icon-assets.d.ts","sourceRoot":"","sources":["../../src/icon-assets.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,MAAM,MAAM,UAAU,GAAG;IACvB,yEAAyE;IACzE,KAAK,EAAE,MAAM,CAAC;IACd,kGAAkG;IAClG,GAAG,EAAE,MAAM,CAAC;IACZ;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,yBAAiC,UAAU,KAAG,MAoD1E,CAAC"}
@@ -0,0 +1,68 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+ import { existsSync, readFileSync } from 'fs';
5
+ import { cp, rm } from 'fs/promises';
6
+ import { isAbsolute, join, relative, resolve } from 'path';
7
+ /**
8
+ * Serves an icon-set catalog as individual SVGs under `{route}/...`, so runtime icon
9
+ * resolvers (e.g. @dxos/react-ui's IconRegistry) can fetch glyphs that weren't statically
10
+ * referenced — icons used only by runtime-loaded plugins.
11
+ *
12
+ * In dev: middleware streams from `dir`. In build: assets are copied into the output dir unless `copy` is false.
13
+ */
14
+ export const iconAssetsPlugin = ({ route, dir, copy = true }) => {
15
+ let outDir;
16
+ return {
17
+ name: `dxos:icon-assets${route}`,
18
+ configResolved: (config) => {
19
+ outDir = resolve(config.root, config.build.outDir);
20
+ },
21
+ configureServer: (server) => {
22
+ server.middlewares.use(route, (req, res, next) => {
23
+ if (req.method !== 'GET' && req.method !== 'HEAD') {
24
+ return next();
25
+ }
26
+ const rawPath = (req.url ?? '').split('?')[0];
27
+ if (rawPath.includes('..')) {
28
+ res.statusCode = 400;
29
+ res.end();
30
+ return;
31
+ }
32
+ const filePath = join(dir, rawPath);
33
+ if (!filePath.startsWith(dir) || !existsSync(filePath)) {
34
+ return next();
35
+ }
36
+ try {
37
+ const content = readFileSync(filePath);
38
+ res.setHeader('Content-Type', 'image/svg+xml');
39
+ res.setHeader('Cache-Control', 'public, max-age=31536000, immutable');
40
+ res.end(content);
41
+ }
42
+ catch {
43
+ next();
44
+ }
45
+ });
46
+ },
47
+ closeBundle: async () => {
48
+ if (!outDir) {
49
+ return;
50
+ }
51
+ const dest = join(outDir, route.replace(/^\//, ''));
52
+ if (!copy) {
53
+ // A kept outDir would otherwise still ship the catalog an earlier build copied. Only a directory strictly
54
+ // inside the output is removed: a root route (`/`) or an escaping one names the output itself or beyond it.
55
+ const within = relative(outDir, dest);
56
+ if (within !== '' && !within.startsWith('..') && !isAbsolute(within)) {
57
+ await rm(dest, { recursive: true, force: true });
58
+ }
59
+ return;
60
+ }
61
+ if (!existsSync(dir)) {
62
+ return;
63
+ }
64
+ await cp(dir, dest, { recursive: true });
65
+ },
66
+ };
67
+ };
68
+ //# sourceMappingURL=icon-assets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"icon-assets.js","sourceRoot":"","sources":["../../src/icon-assets.ts"],"names":[],"mappings":"AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;AAEF,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAgB3D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GA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C,GAAG,CAAC,SAAS,CAAC,eAAe,EAAE,qCAAqC,CAAC,CAAC;oBACtE,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;gBACnB,CAAC;gBAAC,MAAM,CAAC;oBACP,IAAI,EAAE,CAAC;gBACT,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;QACD,WAAW,EAAE,KAAK,IAAI,EAAE;YACtB,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,OAAO;YACT,CAAC;YACD,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;YACpD,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,0GAA0G;gBAC1G,4GAA4G;gBAC5G,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;gBACtC,IAAI,MAAM,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;oBACrE,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;gBACnD,CAAC;gBACD,OAAO;YACT,CAAC;YACD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;gBACrB,OAAO;YACT,CAAC;YACD,MAAM,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC3C,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=icon-assets.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"icon-assets.test.d.ts","sourceRoot":"","sources":["../../src/icon-assets.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,36 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+ import fs from 'fs';
5
+ import { tmpdir } from 'os';
6
+ import { join } from 'path';
7
+ import { build } from 'vite';
8
+ import { afterEach, beforeEach, describe, expect, test } from 'vitest';
9
+ import { iconAssetsPlugin } from './icon-assets.js';
10
+ describe('iconAssetsPlugin', () => {
11
+ let root;
12
+ beforeEach(() => {
13
+ root = fs.mkdtempSync(join(tmpdir(), 'icon-assets-test-'));
14
+ fs.mkdirSync(join(root, 'catalog'));
15
+ fs.writeFileSync(join(root, 'catalog', 'alpha.svg'), '<svg xmlns="http://www.w3.org/2000/svg"/>');
16
+ fs.writeFileSync(join(root, 'index.html'), '<!doctype html><html><body></body></html>');
17
+ });
18
+ afterEach(() => {
19
+ fs.rmSync(root, { recursive: true, force: true });
20
+ });
21
+ const runBuild = (assets) => build({
22
+ configFile: false,
23
+ root,
24
+ logLevel: 'silent',
25
+ plugins: [iconAssetsPlugin({ route: '/catalog', dir: join(root, 'catalog'), ...assets })],
26
+ });
27
+ test('copies the catalog into the build output', async () => {
28
+ await runBuild({});
29
+ expect(fs.existsSync(join(root, 'dist', 'catalog', 'alpha.svg'))).toBe(true);
30
+ });
31
+ test('leaves a dev-only catalog out of the build output', async () => {
32
+ await runBuild({ copy: false });
33
+ expect(fs.existsSync(join(root, 'dist', 'catalog'))).toBe(false);
34
+ });
35
+ });
36
+ //# sourceMappingURL=icon-assets.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"icon-assets.test.js","sourceRoot":"","sources":["../../src/icon-assets.test.ts"],"names":[],"mappings":"AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;AAEF,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,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MAAM,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/E,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,mDAAmD,EAAE,KAAK,IAAI,EAAE;QACnE,MAAM,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QAChC,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { type BundleParams } from '@ch-ui/icons';
2
+ import type { Plugin } from 'vite';
3
+ import { type IconAssets } from './icon-assets.ts';
4
+ import { type SymbolPatternParams, WEIGHTS, iconSymbolPattern } from './symbol-pattern.ts';
5
+ export { type SymbolPatternParams, WEIGHTS, iconSymbolPattern };
6
+ export type { IconAssets };
7
+ export type IconsPluginParams = Omit<BundleParams, 'spritePath'> & {
8
+ spriteFile: string;
9
+ /**
10
+ * Globs of files scanned eagerly at build start, in addition to the module
11
+ * graph. Needed for icon names that only occur in sources the build never
12
+ * imports — e.g. descriptors contributed by other packages at runtime (the
13
+ * composer-crx page actions).
14
+ */
15
+ scanPaths?: string[];
16
+ /**
17
+ * Icon-set catalogs to expose as individual SVGs (dev middleware + build-output copy)
18
+ * for runtime icon resolution — icons referenced only by runtime-loaded code that the
19
+ * scanner never sees. Opt-in: hosts that only need the static sprite omit this (e.g.
20
+ * composer-crx, where copying a full catalog would bloat the packaged extension).
21
+ */
22
+ assets?: IconAssets[];
23
+ verbose?: boolean;
24
+ };
25
+ export declare const IconsPlugin: ({ assetPath, symbolPattern, spriteFile, contentPaths, scanPaths, assets, config, verbose, }: IconsPluginParams) => Plugin[];
26
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,YAAY,EAA0B,MAAM,cAAc,CAAC;AAKzE,OAAO,KAAK,EAAW,MAAM,EAAiB,MAAM,MAAM,CAAC;AAE3D,OAAO,EAAE,KAAK,UAAU,EAAoB,MAAM,kBAAkB,CAAC;AAGrE,OAAO,EAAE,KAAK,mBAAmB,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE3F,OAAO,EAAE,KAAK,mBAAmB,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAEhE,YAAY,EAAE,UAAU,EAAE,CAAC;AAE3B,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC,GAAG;IACjE,UAAU,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,WAAW,gGASrB,iBAAiB,KAAG,MAAM,EAoX5B,CAAC"}