@pithyjs/vite-plugin 0.1.0-beta.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 +237 -0
- package/dist/aotCodegen/generateBindings.d.ts +184 -0
- package/dist/aotCodegen/generateBindings.d.ts.map +1 -0
- package/dist/aotCodegen/generateBindings.js +326 -0
- package/dist/aotCodegen/generateBindings.js.map +1 -0
- package/dist/aotCodegen/generateDomFactory.d.ts +59 -0
- package/dist/aotCodegen/generateDomFactory.d.ts.map +1 -0
- package/dist/aotCodegen/generateDomFactory.js +302 -0
- package/dist/aotCodegen/generateDomFactory.js.map +1 -0
- package/dist/aotCodegen/index.d.ts +18 -0
- package/dist/aotCodegen/index.d.ts.map +1 -0
- package/dist/aotCodegen/index.js +17 -0
- package/dist/aotCodegen/index.js.map +1 -0
- package/dist/aotCodegen/serializeNode.d.ts +74 -0
- package/dist/aotCodegen/serializeNode.d.ts.map +1 -0
- package/dist/aotCodegen/serializeNode.js +169 -0
- package/dist/aotCodegen/serializeNode.js.map +1 -0
- package/dist/aotCodegen/structuralCodegen.d.ts +38 -0
- package/dist/aotCodegen/structuralCodegen.d.ts.map +1 -0
- package/dist/aotCodegen/structuralCodegen.js +56 -0
- package/dist/aotCodegen/structuralCodegen.js.map +1 -0
- package/dist/aotCodegen/utils.d.ts +38 -0
- package/dist/aotCodegen/utils.d.ts.map +1 -0
- package/dist/aotCodegen/utils.js +48 -0
- package/dist/aotCodegen/utils.js.map +1 -0
- package/dist/babelPlugin/babelPlugin.d.ts +44 -0
- package/dist/babelPlugin/babelPlugin.d.ts.map +1 -0
- package/dist/babelPlugin/babelPlugin.js +392 -0
- package/dist/babelPlugin/babelPlugin.js.map +1 -0
- package/dist/babelPlugin/extractOriginalTagNames.d.ts +20 -0
- package/dist/babelPlugin/extractOriginalTagNames.d.ts.map +1 -0
- package/dist/babelPlugin/extractOriginalTagNames.js +44 -0
- package/dist/babelPlugin/extractOriginalTagNames.js.map +1 -0
- package/dist/babelPlugin/extractUsedIdentifiers.d.ts +26 -0
- package/dist/babelPlugin/extractUsedIdentifiers.d.ts.map +1 -0
- package/dist/babelPlugin/extractUsedIdentifiers.js +206 -0
- package/dist/babelPlugin/extractUsedIdentifiers.js.map +1 -0
- package/dist/buildPlugin/plugin.d.ts +79 -0
- package/dist/buildPlugin/plugin.d.ts.map +1 -0
- package/dist/buildPlugin/plugin.js +142 -0
- package/dist/buildPlugin/plugin.js.map +1 -0
- package/dist/designSystemPlugin/collector.d.ts +63 -0
- package/dist/designSystemPlugin/collector.d.ts.map +1 -0
- package/dist/designSystemPlugin/collector.js +175 -0
- package/dist/designSystemPlugin/collector.js.map +1 -0
- package/dist/designSystemPlugin/cssTokens.d.ts +34 -0
- package/dist/designSystemPlugin/cssTokens.d.ts.map +1 -0
- package/dist/designSystemPlugin/cssTokens.js +56 -0
- package/dist/designSystemPlugin/cssTokens.js.map +1 -0
- package/dist/designSystemPlugin/enumerate.d.ts +24 -0
- package/dist/designSystemPlugin/enumerate.d.ts.map +1 -0
- package/dist/designSystemPlugin/enumerate.js +430 -0
- package/dist/designSystemPlugin/enumerate.js.map +1 -0
- package/dist/designSystemPlugin/extractor.d.ts +95 -0
- package/dist/designSystemPlugin/extractor.d.ts.map +1 -0
- package/dist/designSystemPlugin/extractor.js +150 -0
- package/dist/designSystemPlugin/extractor.js.map +1 -0
- package/dist/designSystemPlugin/generator.d.ts +33 -0
- package/dist/designSystemPlugin/generator.d.ts.map +1 -0
- package/dist/designSystemPlugin/generator.js +256 -0
- package/dist/designSystemPlugin/generator.js.map +1 -0
- package/dist/designSystemPlugin/index.d.ts +18 -0
- package/dist/designSystemPlugin/index.d.ts.map +1 -0
- package/dist/designSystemPlugin/index.js +19 -0
- package/dist/designSystemPlugin/index.js.map +1 -0
- package/dist/designSystemPlugin/patterns/a11y.d.ts +19 -0
- package/dist/designSystemPlugin/patterns/a11y.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/a11y.js +230 -0
- package/dist/designSystemPlugin/patterns/a11y.js.map +1 -0
- package/dist/designSystemPlugin/patterns/borders.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/borders.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/borders.js +474 -0
- package/dist/designSystemPlugin/patterns/borders.js.map +1 -0
- package/dist/designSystemPlugin/patterns/colors.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/colors.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/colors.js +134 -0
- package/dist/designSystemPlugin/patterns/colors.js.map +1 -0
- package/dist/designSystemPlugin/patterns/iconography.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/iconography.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/iconography.js +61 -0
- package/dist/designSystemPlugin/patterns/iconography.js.map +1 -0
- package/dist/designSystemPlugin/patterns/index.d.ts +22 -0
- package/dist/designSystemPlugin/patterns/index.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/index.js +44 -0
- package/dist/designSystemPlugin/patterns/index.js.map +1 -0
- package/dist/designSystemPlugin/patterns/layout.d.ts +34 -0
- package/dist/designSystemPlugin/patterns/layout.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/layout.js +917 -0
- package/dist/designSystemPlugin/patterns/layout.js.map +1 -0
- package/dist/designSystemPlugin/patterns/motion.d.ts +19 -0
- package/dist/designSystemPlugin/patterns/motion.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/motion.js +162 -0
- package/dist/designSystemPlugin/patterns/motion.js.map +1 -0
- package/dist/designSystemPlugin/patterns/radius.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/radius.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/radius.js +107 -0
- package/dist/designSystemPlugin/patterns/radius.js.map +1 -0
- package/dist/designSystemPlugin/patterns/shadows.d.ts +19 -0
- package/dist/designSystemPlugin/patterns/shadows.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/shadows.js +161 -0
- package/dist/designSystemPlugin/patterns/shadows.js.map +1 -0
- package/dist/designSystemPlugin/patterns/smartContainer.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/smartContainer.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/smartContainer.js +96 -0
- package/dist/designSystemPlugin/patterns/smartContainer.js.map +1 -0
- package/dist/designSystemPlugin/patterns/spacing.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/spacing.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/spacing.js +333 -0
- package/dist/designSystemPlugin/patterns/spacing.js.map +1 -0
- package/dist/designSystemPlugin/patterns/typography.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/typography.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/typography.js +416 -0
- package/dist/designSystemPlugin/patterns/typography.js.map +1 -0
- package/dist/designSystemPlugin/plugin.d.ts +39 -0
- package/dist/designSystemPlugin/plugin.d.ts.map +1 -0
- package/dist/designSystemPlugin/plugin.js +351 -0
- package/dist/designSystemPlugin/plugin.js.map +1 -0
- package/dist/designSystemPlugin/types.d.ts +156 -0
- package/dist/designSystemPlugin/types.d.ts.map +1 -0
- package/dist/designSystemPlugin/types.js +49 -0
- package/dist/designSystemPlugin/types.js.map +1 -0
- package/dist/htmlTransform/htmlTransform.d.ts +47 -0
- package/dist/htmlTransform/htmlTransform.d.ts.map +1 -0
- package/dist/htmlTransform/htmlTransform.js +86 -0
- package/dist/htmlTransform/htmlTransform.js.map +1 -0
- package/dist/iconsPlugin/index.d.ts +18 -0
- package/dist/iconsPlugin/index.d.ts.map +1 -0
- package/dist/iconsPlugin/index.js +17 -0
- package/dist/iconsPlugin/index.js.map +1 -0
- package/dist/iconsPlugin/optimize.d.ts +54 -0
- package/dist/iconsPlugin/optimize.d.ts.map +1 -0
- package/dist/iconsPlugin/optimize.js +253 -0
- package/dist/iconsPlugin/optimize.js.map +1 -0
- package/dist/iconsPlugin/plugin.d.ts +49 -0
- package/dist/iconsPlugin/plugin.d.ts.map +1 -0
- package/dist/iconsPlugin/plugin.js +242 -0
- package/dist/iconsPlugin/plugin.js.map +1 -0
- package/dist/iconsPlugin/types.d.ts +49 -0
- package/dist/iconsPlugin/types.d.ts.map +1 -0
- package/dist/iconsPlugin/types.js +30 -0
- package/dist/iconsPlugin/types.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/pithyPlugin/plugin.d.ts +38 -0
- package/dist/pithyPlugin/plugin.d.ts.map +1 -0
- package/dist/pithyPlugin/plugin.js +119 -0
- package/dist/pithyPlugin/plugin.js.map +1 -0
- package/dist/routerPlugin/manifest.d.ts +33 -0
- package/dist/routerPlugin/manifest.d.ts.map +1 -0
- package/dist/routerPlugin/manifest.js +223 -0
- package/dist/routerPlugin/manifest.js.map +1 -0
- package/dist/routerPlugin/plugin.d.ts +51 -0
- package/dist/routerPlugin/plugin.d.ts.map +1 -0
- package/dist/routerPlugin/plugin.js +164 -0
- package/dist/routerPlugin/plugin.js.map +1 -0
- package/dist/routerPlugin/scanner.d.ts +69 -0
- package/dist/routerPlugin/scanner.d.ts.map +1 -0
- package/dist/routerPlugin/scanner.js +290 -0
- package/dist/routerPlugin/scanner.js.map +1 -0
- package/dist/ssrPlugin/plugin.d.ts +76 -0
- package/dist/ssrPlugin/plugin.d.ts.map +1 -0
- package/dist/ssrPlugin/plugin.js +439 -0
- package/dist/ssrPlugin/plugin.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.vite.html-transform-plugin",
|
|
4
|
+
"title": "HTML Transform Vite Plugin",
|
|
5
|
+
"category": "plugin",
|
|
6
|
+
"description": "Babel-based Vite plugin that transforms html`…` tagged template literals, with optional AOT compilation to eliminate runtime HTML parsing.",
|
|
7
|
+
"since": "0.0.1",
|
|
8
|
+
"stability": "stable",
|
|
9
|
+
"testing": {
|
|
10
|
+
"unit": { "required": true, "covered": true, "file": "htmlTransformAot.test.ts" },
|
|
11
|
+
"integration": { "required": true, "covered": false },
|
|
12
|
+
"e2e": { "required": false, "covered": false }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
*/
|
|
16
|
+
import pithyBabelPlugin from '../babelPlugin/babelPlugin';
|
|
17
|
+
import * as babel from '@babel/core';
|
|
18
|
+
/**
|
|
19
|
+
* Vite plugin that transforms `html\`\`` tagged templates using Babel.
|
|
20
|
+
*
|
|
21
|
+
* In build mode, templates are AOT-compiled to eliminate runtime HTML parsing.
|
|
22
|
+
* In dev mode, templates are left as-is for faster HMR unless `aot` is explicitly enabled.
|
|
23
|
+
*
|
|
24
|
+
* @param options - Plugin configuration for AOT mode, strict AOT, and component scopes
|
|
25
|
+
* @returns A Vite plugin that transforms html tagged templates
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { htmlTransformPlugin } from '@pithyjs/vite-plugin';
|
|
30
|
+
*
|
|
31
|
+
* export default defineConfig({
|
|
32
|
+
* plugins: [htmlTransformPlugin({ aot: true })],
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
/** @codexApi {"parent":"pithy.vite.html-transform-plugin","name":"htmlTransformPlugin","stability":"stable","signature":"(options?: HtmlTransformPluginOptions) => PluginOption"} */
|
|
37
|
+
export function htmlTransformPlugin(options) {
|
|
38
|
+
let resolvedAot = false;
|
|
39
|
+
return {
|
|
40
|
+
name: 'pithy:html-transform',
|
|
41
|
+
enforce: 'pre',
|
|
42
|
+
configResolved(config) {
|
|
43
|
+
// Default: AOT enabled in build, disabled in dev (for faster HMR)
|
|
44
|
+
resolvedAot = options?.aot ?? config.command === 'build';
|
|
45
|
+
},
|
|
46
|
+
transform(code, id) {
|
|
47
|
+
// Strip Vite query/hash suffixes (e.g. component.ts?import → component.ts)
|
|
48
|
+
const normalizedId = id.split(/[?#]/, 1)[0];
|
|
49
|
+
// Fast-path: skip files with no pithy tagged templates.
|
|
50
|
+
// Check for html` (common case) or aliased html import from @pithyjs/core.
|
|
51
|
+
if (!normalizedId.endsWith('.ts'))
|
|
52
|
+
return;
|
|
53
|
+
if (!code.includes('html`') &&
|
|
54
|
+
!/import\s*\{[^}]*\bhtml\b[^}]*\}\s*from\s+['"]@pithyjs\/core['"]/.test(code))
|
|
55
|
+
return;
|
|
56
|
+
const babelPluginOptions = {
|
|
57
|
+
componentScopes: options?.componentScopes,
|
|
58
|
+
aot: resolvedAot,
|
|
59
|
+
strictAot: options?.strictAot,
|
|
60
|
+
filename: normalizedId,
|
|
61
|
+
};
|
|
62
|
+
const result = babel.transformSync(code, {
|
|
63
|
+
filename: normalizedId,
|
|
64
|
+
plugins: [() => pithyBabelPlugin(babelPluginOptions)],
|
|
65
|
+
presets: [
|
|
66
|
+
[
|
|
67
|
+
'@babel/preset-typescript',
|
|
68
|
+
{
|
|
69
|
+
onlyRemoveTypeImports: true,
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
],
|
|
73
|
+
parserOpts: {
|
|
74
|
+
sourceType: 'module',
|
|
75
|
+
plugins: ['typescript'],
|
|
76
|
+
},
|
|
77
|
+
configFile: false,
|
|
78
|
+
});
|
|
79
|
+
return {
|
|
80
|
+
code: result?.code ?? code,
|
|
81
|
+
map: null,
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=htmlTransform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"htmlTransform.js","sourceRoot":"","sources":["../../src/htmlTransform/htmlTransform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAGF,OAAO,gBAEN,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,KAAK,MAAM,aAAa,CAAC;AAYrC;;;;;;;;;;;;;;;;;GAiBG;AACH,qLAAqL;AACr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AI,IAAI,IAAI;gBAC1B,GAAG,EAAE,IAAI;aACV,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.vite-plugin-icons.exports",
|
|
4
|
+
"title": "Vite Icons Plugin Entry",
|
|
5
|
+
"category": "plugin",
|
|
6
|
+
"description": "Public entry point re-exporting the icon sprite Vite plugin and its types.",
|
|
7
|
+
"since": "0.0.1",
|
|
8
|
+
"stability": "stable",
|
|
9
|
+
"testing": {
|
|
10
|
+
"unit": { "required": false, "covered": false },
|
|
11
|
+
"integration": { "required": true, "covered": false },
|
|
12
|
+
"e2e": { "required": false, "covered": false }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
*/
|
|
16
|
+
export { pithyIcons } from './plugin';
|
|
17
|
+
export type { PithyIconsOptions } from './types';
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/iconsPlugin/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAEF,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,YAAY,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.vite-plugin-icons.exports",
|
|
4
|
+
"title": "Vite Icons Plugin Entry",
|
|
5
|
+
"category": "plugin",
|
|
6
|
+
"description": "Public entry point re-exporting the icon sprite Vite plugin and its types.",
|
|
7
|
+
"since": "0.0.1",
|
|
8
|
+
"stability": "stable",
|
|
9
|
+
"testing": {
|
|
10
|
+
"unit": { "required": false, "covered": false },
|
|
11
|
+
"integration": { "required": true, "covered": false },
|
|
12
|
+
"e2e": { "required": false, "covered": false }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
*/
|
|
16
|
+
export { pithyIcons } from './plugin';
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/iconsPlugin/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAEF,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.vite-plugin-icons.optimize",
|
|
4
|
+
"title": "SVG Optimization for Icon Sprites",
|
|
5
|
+
"category": "plugin",
|
|
6
|
+
"description": "Optimizes SVG icons by stripping metadata, enforcing currentColor, and generating sprite sheets.",
|
|
7
|
+
"since": "0.0.1",
|
|
8
|
+
"stability": "stable",
|
|
9
|
+
"testing": {
|
|
10
|
+
"unit": { "required": true, "covered": true, "file": "iconsPlugin.test.ts" },
|
|
11
|
+
"integration": { "required": false, "covered": false },
|
|
12
|
+
"e2e": { "required": false, "covered": false }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
*/
|
|
16
|
+
/** Extract viewBox from an SVG string. Falls back to "0 0 24 24". */
|
|
17
|
+
/** @codexApi {"parent":"pithy.vite-plugin-icons.optimize","name":"extractViewBox","stability":"stable","signature":"(svg: string) => string"} */
|
|
18
|
+
export declare function extractViewBox(svg: string): string;
|
|
19
|
+
/** Extract the inner content of an SVG (everything between <svg> and </svg>) */
|
|
20
|
+
/** @codexApi {"parent":"pithy.vite-plugin-icons.optimize","name":"extractSvgInner","stability":"stable","signature":"(svg: string) => string"} */
|
|
21
|
+
export declare function extractSvgInner(svg: string): string;
|
|
22
|
+
/** Extract presentational attributes from the root <svg> tag. */
|
|
23
|
+
/** @codexApi {"parent":"pithy.vite-plugin-icons.optimize","name":"extractRootAttrs","stability":"stable","signature":"(svg: string) => string"} */
|
|
24
|
+
export declare function extractRootAttrs(svg: string): string;
|
|
25
|
+
export interface OptimizedIcon {
|
|
26
|
+
/** Symbol ID for the sprite */
|
|
27
|
+
id: string;
|
|
28
|
+
/** viewBox attribute value */
|
|
29
|
+
viewBox: string;
|
|
30
|
+
/** Cleaned SVG inner content (for <symbol> body) */
|
|
31
|
+
inner: string;
|
|
32
|
+
/** Presentational attributes from root <svg> (e.g. fill="none" stroke="currentColor") */
|
|
33
|
+
rootAttrs: string;
|
|
34
|
+
/** Search tags derived from filename */
|
|
35
|
+
tags: string[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Optimize an SVG icon for sprite inclusion.
|
|
39
|
+
*
|
|
40
|
+
* @param raw - Raw SVG file content
|
|
41
|
+
* @param name - Icon name (used as symbol ID)
|
|
42
|
+
* @param options - Optimization options
|
|
43
|
+
*/
|
|
44
|
+
/** @codexApi {"parent":"pithy.vite-plugin-icons.optimize","name":"optimizeIcon","stability":"stable","signature":"(raw: string, name: string, options: { prefix?: string; enforceCurrentColor?: boolean }) => OptimizedIcon"} */
|
|
45
|
+
export declare function optimizeIcon(raw: string, name: string, options?: {
|
|
46
|
+
prefix?: string;
|
|
47
|
+
enforceCurrentColor?: boolean;
|
|
48
|
+
}): OptimizedIcon;
|
|
49
|
+
/**
|
|
50
|
+
* Generate an SVG sprite sheet from optimized icons.
|
|
51
|
+
*/
|
|
52
|
+
/** @codexApi {"parent":"pithy.vite-plugin-icons.optimize","name":"generateSprite","stability":"stable","signature":"(icons: OptimizedIcon[]) => string"} */
|
|
53
|
+
export declare function generateSprite(icons: OptimizedIcon[]): string;
|
|
54
|
+
//# sourceMappingURL=optimize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optimize.d.ts","sourceRoot":"","sources":["../../src/iconsPlugin/optimize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAyHF,qEAAqE;AACrE,iJAAiJ;AACjJ,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAWlD;AASD,gFAAgF;AAChF,kJAAkJ;AAClJ,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAKnD;AAyBD,iEAAiE;AACjE,mJAAmJ;AACnJ,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAqBpD;AAsBD,MAAM,WAAW,aAAa;IAC5B,+BAA+B;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,oDAAoD;IACpD,KAAK,EAAE,MAAM,CAAC;IACd,yFAAyF;IACzF,SAAS,EAAE,MAAM,CAAC;IAClB,wCAAwC;IACxC,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED;;;;;;GAMG;AACH,iOAAiO;AACjO,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,mBAAmB,CAAC,EAAE,OAAO,CAAA;CAAO,GAC/D,aAAa,CA6Cf;AAMD;;GAEG;AACH,4JAA4J;AAC5J,wBAAgB,cAAc,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,MAAM,CAU7D"}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.vite-plugin-icons.optimize",
|
|
4
|
+
"title": "SVG Optimization for Icon Sprites",
|
|
5
|
+
"category": "plugin",
|
|
6
|
+
"description": "Optimizes SVG icons by stripping metadata, enforcing currentColor, and generating sprite sheets.",
|
|
7
|
+
"since": "0.0.1",
|
|
8
|
+
"stability": "stable",
|
|
9
|
+
"testing": {
|
|
10
|
+
"unit": { "required": true, "covered": true, "file": "iconsPlugin.test.ts" },
|
|
11
|
+
"integration": { "required": false, "covered": false },
|
|
12
|
+
"e2e": { "required": false, "covered": false }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Lightweight SVG optimization for icon sprites.
|
|
18
|
+
*
|
|
19
|
+
* Strips unnecessary metadata, enforces `currentColor` for theme integration,
|
|
20
|
+
* and extracts the viewBox for sprite symbol generation.
|
|
21
|
+
*
|
|
22
|
+
* Intentionally avoids a full SVGO dependency — covers the 80% case
|
|
23
|
+
* (icon SVGs from standard icon sets) with simple regex transforms.
|
|
24
|
+
*
|
|
25
|
+
* Known limitations of the regex approach:
|
|
26
|
+
* - CDATA sections are not handled (rare in icon SVGs)
|
|
27
|
+
* - Multi-line attributes may not be matched correctly
|
|
28
|
+
* - Nested `<svg>` elements are not supported
|
|
29
|
+
* For complex SVGs, pre-process with SVGO before adding to the icons directory.
|
|
30
|
+
*/
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
// Metadata stripping
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
/**
|
|
35
|
+
* Elements to remove entirely (open tag → close tag, or self-closing).
|
|
36
|
+
*
|
|
37
|
+
* Note: `<defs>` and `<style>` are intentionally preserved — they can contain
|
|
38
|
+
* gradients, clip paths, masks, or class-based styling referenced by the icon's
|
|
39
|
+
* child elements. Stripping them would silently break those icons.
|
|
40
|
+
* `<script>` is stripped for security reasons.
|
|
41
|
+
*
|
|
42
|
+
* Limitation: the `[\s\S]*?` non-greedy match can over-match if the same tag
|
|
43
|
+
* name appears nested. This is acceptable for `metadata`, `title`, `desc`, and
|
|
44
|
+
* `script` which are never nested in valid icon SVGs. For complex SVGs,
|
|
45
|
+
* pre-process with SVGO before adding to the icons directory.
|
|
46
|
+
*/
|
|
47
|
+
const STRIP_ELEMENTS = /<(?:metadata|title|desc|script)\b[^>]*>[\s\S]*?<\/(?:metadata|title|desc|script)>|<(?:metadata|title|desc|script)\b[^>]*\/>/gi;
|
|
48
|
+
/**
|
|
49
|
+
* Attributes to remove from all elements.
|
|
50
|
+
*
|
|
51
|
+
* Note: `id` is intentionally preserved — internal IDs are needed for
|
|
52
|
+
* `url(#id)` references (gradients, clip paths, masks). The sprite `<symbol>`
|
|
53
|
+
* gets its own ID from the filename, not from SVG-internal IDs.
|
|
54
|
+
*/
|
|
55
|
+
const STRIP_ATTRS = /\s(?:xmlns:(?:xlink|svg|dc|cc|rdf|sodipodi|inkscape)|data-name|inkscape:[a-z-]+|sodipodi:[a-z-]+)=(?:"[^"]*"|'[^']*')/gi;
|
|
56
|
+
/**
|
|
57
|
+
* Inline event handler attributes (e.g. `onload`, `onclick`, `onerror`).
|
|
58
|
+
* Stripped as defense-in-depth against XSS when adding third-party SVGs.
|
|
59
|
+
* While `<use>` references don't execute scripts in modern browsers,
|
|
60
|
+
* removing these attributes avoids any risk if the SVG is used differently.
|
|
61
|
+
*/
|
|
62
|
+
const STRIP_EVENT_HANDLERS = /\s+on[a-z]+=(?:"[^"]*"|'[^']*')/gi;
|
|
63
|
+
/**
|
|
64
|
+
* `href` and `xlink:href` attributes with `javascript:` protocol.
|
|
65
|
+
* Stripped to prevent script execution via link navigation.
|
|
66
|
+
*/
|
|
67
|
+
const STRIP_JS_HREF = /\s+(?:xlink:)?href=(?:"javascript:[^"]*"|'javascript:[^']*')/gi;
|
|
68
|
+
/** XML comments */
|
|
69
|
+
const STRIP_COMMENTS = /<!--[\s\S]*?-->/g;
|
|
70
|
+
/** XML processing instructions */
|
|
71
|
+
const STRIP_PI = /<\?xml[^?]*\?>/gi;
|
|
72
|
+
/** DOCTYPE declarations */
|
|
73
|
+
const STRIP_DOCTYPE = /<!DOCTYPE[^>]*>/gi;
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
// currentColor enforcement
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
/**
|
|
78
|
+
* Replace hardcoded fill/stroke colors with `currentColor`.
|
|
79
|
+
*
|
|
80
|
+
* Preserves `fill="none"` and `stroke="none"` since those are structural
|
|
81
|
+
* (e.g. a circle with fill="none" is an outlined circle, not a filled one).
|
|
82
|
+
*
|
|
83
|
+
* Skips content inside `<defs>` blocks to preserve gradients, patterns,
|
|
84
|
+
* clip paths, and masks that use explicit colors.
|
|
85
|
+
*/
|
|
86
|
+
const FILL_REPLACE = /\bfill=(?:"(?!none")(?!url\()[^"]*"|'(?!none')(?!url\()[^']*')/gi;
|
|
87
|
+
const STROKE_REPLACE = /\bstroke=(?:"(?!none")(?!url\()[^"]*"|'(?!none')(?!url\()[^']*')/gi;
|
|
88
|
+
const DEFS_BLOCK_RE = /<defs\b[^>]*>[\s\S]*?<\/defs>/gi;
|
|
89
|
+
function enforceCurrentColor(svg) {
|
|
90
|
+
// Extract <defs> blocks and replace with placeholders to protect them
|
|
91
|
+
const defsBlocks = [];
|
|
92
|
+
const withoutDefs = svg.replace(DEFS_BLOCK_RE, match => {
|
|
93
|
+
defsBlocks.push(match);
|
|
94
|
+
return `__PITHY_DEFS_${defsBlocks.length - 1}__`;
|
|
95
|
+
});
|
|
96
|
+
// Apply currentColor replacement on non-defs content
|
|
97
|
+
let result = withoutDefs
|
|
98
|
+
.replace(FILL_REPLACE, 'fill="currentColor"')
|
|
99
|
+
.replace(STROKE_REPLACE, 'stroke="currentColor"');
|
|
100
|
+
// Restore <defs> blocks unchanged
|
|
101
|
+
for (let i = 0; i < defsBlocks.length; i++) {
|
|
102
|
+
result = result.replace(`__PITHY_DEFS_${i}__`, defsBlocks[i]);
|
|
103
|
+
}
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
// ---------------------------------------------------------------------------
|
|
107
|
+
// viewBox extraction
|
|
108
|
+
// ---------------------------------------------------------------------------
|
|
109
|
+
const VIEWBOX_RE = /viewBox=(?:"([^"]*)"|'([^']*)')/i;
|
|
110
|
+
/** Validates that a viewBox value contains only safe numeric characters. */
|
|
111
|
+
const SAFE_VIEWBOX_RE = /^[\d.\s,-]+$/;
|
|
112
|
+
/** Extract viewBox from an SVG string. Falls back to "0 0 24 24". */
|
|
113
|
+
/** @codexApi {"parent":"pithy.vite-plugin-icons.optimize","name":"extractViewBox","stability":"stable","signature":"(svg: string) => string"} */
|
|
114
|
+
export function extractViewBox(svg) {
|
|
115
|
+
const match = VIEWBOX_RE.exec(svg);
|
|
116
|
+
const raw = match?.[1] ?? match?.[2] ?? '0 0 24 24';
|
|
117
|
+
// Validate viewBox contains only numeric/space/dot/comma/dash — prevent attribute breakout
|
|
118
|
+
if (!SAFE_VIEWBOX_RE.test(raw)) {
|
|
119
|
+
console.warn(`[pithy:icons] Invalid viewBox value "${raw}" — using fallback "0 0 24 24"`);
|
|
120
|
+
return '0 0 24 24';
|
|
121
|
+
}
|
|
122
|
+
return raw;
|
|
123
|
+
}
|
|
124
|
+
// ---------------------------------------------------------------------------
|
|
125
|
+
// SVG inner content extraction + root attribute extraction
|
|
126
|
+
// ---------------------------------------------------------------------------
|
|
127
|
+
const SVG_OPEN_RE = /<svg\b([^>]*)>/i;
|
|
128
|
+
const SVG_CLOSE_RE = /<\/svg>\s*$/i;
|
|
129
|
+
/** Extract the inner content of an SVG (everything between <svg> and </svg>) */
|
|
130
|
+
/** @codexApi {"parent":"pithy.vite-plugin-icons.optimize","name":"extractSvgInner","stability":"stable","signature":"(svg: string) => string"} */
|
|
131
|
+
export function extractSvgInner(svg) {
|
|
132
|
+
return svg
|
|
133
|
+
.replace(/<svg\b[^>]*>/i, '')
|
|
134
|
+
.replace(SVG_CLOSE_RE, '')
|
|
135
|
+
.trim();
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Presentational attributes that should be carried from the root `<svg>`
|
|
139
|
+
* onto the `<symbol>` element so child elements inherit them correctly.
|
|
140
|
+
*
|
|
141
|
+
* Without this, stroke-based icons (Feather, Heroicons) lose their
|
|
142
|
+
* `fill="none" stroke="currentColor"` from the root and render as filled.
|
|
143
|
+
*/
|
|
144
|
+
const PRESENTATIONAL_ATTRS = [
|
|
145
|
+
'fill',
|
|
146
|
+
'stroke',
|
|
147
|
+
'stroke-width',
|
|
148
|
+
'stroke-linecap',
|
|
149
|
+
'stroke-linejoin',
|
|
150
|
+
];
|
|
151
|
+
/** Pre-built regex map for presentational attribute extraction */
|
|
152
|
+
const ATTR_RE_MAP = new Map(PRESENTATIONAL_ATTRS.map(name => [
|
|
153
|
+
name,
|
|
154
|
+
new RegExp(`\\b${name}=(?:"([^"]*)"|'([^']*)')`, 'i'),
|
|
155
|
+
]));
|
|
156
|
+
/** Extract presentational attributes from the root <svg> tag. */
|
|
157
|
+
/** @codexApi {"parent":"pithy.vite-plugin-icons.optimize","name":"extractRootAttrs","stability":"stable","signature":"(svg: string) => string"} */
|
|
158
|
+
export function extractRootAttrs(svg) {
|
|
159
|
+
const match = SVG_OPEN_RE.exec(svg);
|
|
160
|
+
if (!match)
|
|
161
|
+
return '';
|
|
162
|
+
const openTag = match[1];
|
|
163
|
+
const attrs = [];
|
|
164
|
+
for (const name of PRESENTATIONAL_ATTRS) {
|
|
165
|
+
const attrMatch = ATTR_RE_MAP.get(name).exec(openTag);
|
|
166
|
+
if (attrMatch) {
|
|
167
|
+
const val = (attrMatch[1] ?? attrMatch[2]);
|
|
168
|
+
// Validate attribute value — skip if it contains suspicious content
|
|
169
|
+
if (SAFE_ATTR_VALUE_RE.test(val)) {
|
|
170
|
+
attrs.push(`${name}="${val}"`);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
attrs.push(`${name}="${escapeXmlAttr(val)}"`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return attrs.join(' ');
|
|
178
|
+
}
|
|
179
|
+
// ---------------------------------------------------------------------------
|
|
180
|
+
// XML escaping
|
|
181
|
+
// ---------------------------------------------------------------------------
|
|
182
|
+
/** Escape a string for safe use inside an XML attribute value (double-quoted). */
|
|
183
|
+
function escapeXmlAttr(value) {
|
|
184
|
+
return value
|
|
185
|
+
.replace(/&/g, '&')
|
|
186
|
+
.replace(/"/g, '"')
|
|
187
|
+
.replace(/</g, '<')
|
|
188
|
+
.replace(/>/g, '>');
|
|
189
|
+
}
|
|
190
|
+
/** Validate that a value is safe for use as an XML/SVG attribute (no injection). */
|
|
191
|
+
const SAFE_ATTR_VALUE_RE = /^[a-zA-Z0-9.:\-_#(),\s/]+$/;
|
|
192
|
+
/**
|
|
193
|
+
* Optimize an SVG icon for sprite inclusion.
|
|
194
|
+
*
|
|
195
|
+
* @param raw - Raw SVG file content
|
|
196
|
+
* @param name - Icon name (used as symbol ID)
|
|
197
|
+
* @param options - Optimization options
|
|
198
|
+
*/
|
|
199
|
+
/** @codexApi {"parent":"pithy.vite-plugin-icons.optimize","name":"optimizeIcon","stability":"stable","signature":"(raw: string, name: string, options: { prefix?: string; enforceCurrentColor?: boolean }) => OptimizedIcon"} */
|
|
200
|
+
export function optimizeIcon(raw, name, options = {}) {
|
|
201
|
+
const { prefix = '', enforceCurrentColor: shouldEnforce = true } = options;
|
|
202
|
+
// Sanitize name for use as XML id and URL fragment identifier
|
|
203
|
+
const safeName = name.replace(/[^a-z0-9-_]/gi, '-');
|
|
204
|
+
let svg = raw;
|
|
205
|
+
// Strip non-content elements
|
|
206
|
+
svg = svg.replace(STRIP_PI, '');
|
|
207
|
+
svg = svg.replace(STRIP_DOCTYPE, '');
|
|
208
|
+
svg = svg.replace(STRIP_COMMENTS, '');
|
|
209
|
+
svg = svg.replace(STRIP_ELEMENTS, '');
|
|
210
|
+
svg = svg.replace(STRIP_ATTRS, '');
|
|
211
|
+
svg = svg.replace(STRIP_EVENT_HANDLERS, '');
|
|
212
|
+
svg = svg.replace(STRIP_JS_HREF, '');
|
|
213
|
+
// Safety net: ensure no <script tags survived regex stripping (defense-in-depth)
|
|
214
|
+
if (/<script\b/i.test(svg)) {
|
|
215
|
+
// Aggressively strip any remaining script-like content
|
|
216
|
+
svg = svg.replace(/<script\b[^>]*>?[\s\S]*?(?:<\/script>|$)/gi, '');
|
|
217
|
+
console.warn(`[pithy:icons] Residual <script> tag detected and stripped in icon "${name}"`);
|
|
218
|
+
}
|
|
219
|
+
// Enforce currentColor for design system integration
|
|
220
|
+
if (shouldEnforce) {
|
|
221
|
+
svg = enforceCurrentColor(svg);
|
|
222
|
+
}
|
|
223
|
+
const viewBox = extractViewBox(svg);
|
|
224
|
+
const rootAttrs = extractRootAttrs(svg);
|
|
225
|
+
const inner = extractSvgInner(svg);
|
|
226
|
+
// Derive search tags from filename (e.g. "arrow-left" → ["arrow", "left"])
|
|
227
|
+
const tags = safeName.split(/[-_]/).filter(Boolean);
|
|
228
|
+
return {
|
|
229
|
+
id: prefix ? `${prefix}${safeName}` : safeName,
|
|
230
|
+
viewBox,
|
|
231
|
+
inner,
|
|
232
|
+
rootAttrs,
|
|
233
|
+
tags,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
// ---------------------------------------------------------------------------
|
|
237
|
+
// Sprite generation
|
|
238
|
+
// ---------------------------------------------------------------------------
|
|
239
|
+
/**
|
|
240
|
+
* Generate an SVG sprite sheet from optimized icons.
|
|
241
|
+
*/
|
|
242
|
+
/** @codexApi {"parent":"pithy.vite-plugin-icons.optimize","name":"generateSprite","stability":"stable","signature":"(icons: OptimizedIcon[]) => string"} */
|
|
243
|
+
export function generateSprite(icons) {
|
|
244
|
+
const symbols = icons
|
|
245
|
+
.map(icon => {
|
|
246
|
+
const attrs = icon.rootAttrs ? ` ${icon.rootAttrs}` : '';
|
|
247
|
+
// id is already sanitized to [a-zA-Z0-9-_], viewBox validated to numeric — escape as defense-in-depth
|
|
248
|
+
return `<symbol id="${escapeXmlAttr(icon.id)}" viewBox="${escapeXmlAttr(icon.viewBox)}"${attrs}>${icon.inner}</symbol>`;
|
|
249
|
+
})
|
|
250
|
+
.join('\n');
|
|
251
|
+
return `<svg xmlns="http://www.w3.org/2000/svg">\n${symbols}\n</svg>`;
|
|
252
|
+
}
|
|
253
|
+
//# sourceMappingURL=optimize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optimize.js","sourceRoot":"","sources":["../../src/iconsPlugin/optimize.ts"],"names":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+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.vite-plugin-icons",
|
|
4
|
+
"title": "Vite Plugin for Icon Sprite Generation",
|
|
5
|
+
"category": "plugin",
|
|
6
|
+
"description": "SVG icon sprite generation plugin with optimization, HMR, and virtual module output.",
|
|
7
|
+
"since": "0.0.1",
|
|
8
|
+
"stability": "stable",
|
|
9
|
+
"testing": {
|
|
10
|
+
"unit": { "required": true, "covered": true, "file": "iconsPlugin.test.ts" },
|
|
11
|
+
"integration": { "required": false, "covered": false },
|
|
12
|
+
"e2e": { "required": false, "covered": false }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
*/
|
|
16
|
+
import type { Plugin } from 'vite';
|
|
17
|
+
import { type PithyIconsOptions } from './types';
|
|
18
|
+
/**
|
|
19
|
+
* Vite plugin for SVG icon sprite generation.
|
|
20
|
+
*
|
|
21
|
+
* Scans an icons directory, optimizes SVGs (strip metadata, enforce
|
|
22
|
+
* `currentColor`), and generates:
|
|
23
|
+
* - An SVG sprite asset (emitted as a Rollup asset in build, served in dev)
|
|
24
|
+
* - A `virtual:pithy-icons` module exporting `SPRITE_URL`, `ICON_NAMES`,
|
|
25
|
+
* and `ICON_META` for runtime registration
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* // vite.config.ts
|
|
30
|
+
* import { pithyIcons } from '@pithyjs/vite-plugin';
|
|
31
|
+
*
|
|
32
|
+
* export default defineConfig({
|
|
33
|
+
* plugins: [
|
|
34
|
+
* pithyIcons({ dir: 'src/icons' })
|
|
35
|
+
* ]
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* // main.ts — register icons at app startup
|
|
42
|
+
* import { SPRITE_URL, ICON_NAMES, ICON_META } from "virtual:pithy-icons";
|
|
43
|
+
* import { registerIconSprite } from "@pithyjs/ui-kit/icons";
|
|
44
|
+
* registerIconSprite(SPRITE_URL, ICON_NAMES, ICON_META);
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
/** @codexApi {"parent":"pithy.vite-plugin-icons","name":"pithyIcons","stability":"stable","signature":"(options?: PithyIconsOptions) => Plugin"} */
|
|
48
|
+
export declare function pithyIcons(options?: PithyIconsOptions): Plugin;
|
|
49
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/iconsPlugin/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAEF,OAAO,KAAK,EAAE,MAAM,EAAkB,MAAM,MAAM,CAAC;AAInD,OAAO,EAIL,KAAK,iBAAiB,EAEvB,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,oJAAoJ;AACpJ,wBAAgB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,MAAM,CAsNlE"}
|