import { AutoLoggerInput, Logger } from "@neodx/log"; import { AutoVfsInput, VfsLogMethod } from "@neodx/vfs"; import { AnyFn } from "@neodx/std/shared"; import { Config } from "svgo"; import { z } from "zod"; import { AnyColor, Colord } from "colord"; //#region src/core/shared.d.ts declare const defineSymbolMeta: (name: string, path: string, source: string, node: ParsedSvgNode) => { name: string; path: string; node: ParsedSvgNode; /** The original SVG source */ source: string; inlined: boolean; /** @internal */ __: { allNodes: ParsedSvgNode[]; nodeById: { [x: string]: ParsedSvgNode; }; references: Record; id: string; sync: () => void; }; }; declare const defineSpriteMeta: (name: string, symbols: SymbolMeta[]) => { /** * Name of the sprite. * @example "common" */ name: string; assets: SpriteAsset[]; }; type SymbolMeta = ReturnType; type SpriteMeta = ReturnType; type SvgLogger = Logger; interface BaseSpriteAsset { /** * Optional name of the asset. * If omitted, the name will be generated from the sprite name. */ assetName?: string; /** * Symbols in the asset. * The single sprite can hold multiple assets, so we need to track and distinguish them. */ symbols: SymbolMeta[]; additionalChildren?: ParsedSvgNode[]; } /** * The asset will be saved as a file and used as a regular external SVG sprite (``). */ interface ExternalFileSpriteChunk extends BaseSpriteAsset { type: 'external'; /** * Name of the SVG file that will be referenced. * Will be actualized before writing to the disk. * @example "common.2eb4b56f.svg" */ fileName: string; } /** * The asset content will be injected into the document for global usage (``). */ interface InlinedSpriteAsset extends BaseSpriteAsset { type: 'inject'; /** * Inlined SVG content. */ content: string; } /** * Same as `inject`, but the sprite content will be saved as a file and then fetched from the server and injected into the document. */ interface ExtractedSpriteAsset extends BaseSpriteAsset { type: 'fetch-and-inject'; /** * Name of the SVG file that will be loaded and inlined. * Will be actualized before writing to the disk. * @example "inlined-common.2eb4b56f.svg" */ fileName: string; } type SpriteAsset = ExternalFileSpriteChunk | InlinedSpriteAsset | ExtractedSpriteAsset; //#endregion //#region src/core/parser.d.ts interface ParsedSvgNode { name: string; props: Record; parent?: ParsedSvgNode; children: Array; } //#endregion //#region ../internal/src/params.d.ts type CallableParam = Fn | boolean | null; //#endregion //#region ../internal/src/svgo.d.ts interface CreateSvgoConfigParams { /** * Additional attributes to remove. Provide them if you want to extend the default behavior, but do not override it. */ removeAttrs?: string[]; /** * If `true`, disables specific optimizations which are not compatible with sprites: * - "removeHiddenElems" removes invisible elements * - "removeUselessDefs" removes unused symbols * - "cleanupIds" removes symbol ids * * @see https://github.com/svg/svgo/issues/1962 * @default false */ spriteMode?: boolean; /** * SVGO configuration * @see https://github.com/svg/svgo#configuration */ config?: Config; } //#endregion //#region src/core/metadata.d.ts type SpritesMetadataInput = z.input; /** Any possible value for `metadata` option */ declare const MetadataInputSchema: z.ZodUnion<[z.ZodObject<{ /** * Path to generated sprites metadata - types and runtime information * @example "src/sprites/meta.ts" */ path: z.ZodString; /** * Name for the variable generated for sprites metadata * @default "sprites" * @example Generated metadata * export const sprites = defineSpriteMap({ * common: defineSprite('common', 'common.svg', [ * defineSpriteSymbol('close', 16, 16), * defineSpriteSymbol('add', 16, 16), * ]), * }); * // ... * console.log(sprites.common.symbols.close); // { name: 'close', axis: 'xy', width: 16, height: 16, viewBox: '0 0 16 16' } */ name: z.ZodDefault; /** * Name of the type generated for sprites metadata * @default "SpritesMeta" * @example Generated metadata * export type SpritesMeta = typeof sprites; */ typeName: z.ZodDefault; /** * @deprecated Not used anymore, remove it from your code */ runtime: z.ZodOptional; }, "strip", z.ZodTypeAny, { path: string; name: string; typeName: string; runtime?: any; }, { path: string; name?: string | undefined; typeName?: string | undefined; runtime?: any; }>, z.ZodEffects, z.ZodEffects, null, false>]>; //#endregion //#region src/core/cleanup.d.ts type SpritesCleanupType = 'force' | 'auto'; //#endregion //#region src/core/inlining.d.ts type FilterInlineMode = 'auto' | 'none' | 'all' | ((symbol: SymbolMeta) => boolean); interface SvgSpriteInliningParams { /** * Generates a unique ID for the symbol. * The ID will be used as a global ID for the symbol in the document. * * @default ({ spriteName, symbolName, contentHash }) => `${spriteName}-${symbolName}-${contentHash.slice(0, 8)}` * @example Single hash * { getId: it => it.hash(`${it.spriteName}-${it.symbolName}-${it.contentHash}`) } */ getId?: (params: SymbolIdParams) => string; /** * Name of the generated asset for "extract: true" mode. * You can use "{name}" placeholder to include sprite name or a custom function. * * @default "inlined-{name}" */ assetName?: string | ((sprite: SpriteMeta) => string); /** * Name of the merged sprite for "merge: true" mode. * @default "all" */ mergeName?: string; /** * Extract inlined symbols from sprites. * - if `true`, inlined symbols will be extracted as separate assets and marked as "fetch-and-inject". * - if `false`, inlined symbols will be injected into the document as "inject" assets. * * @default false */ extract?: boolean; /** * Inline recognition strategy. * - "auto" - (default) detects all symbols that reference other symbols * - "none" - disables inlining * - "all" - inlines all symbols * - (fn: (symbol: SymbolMeta) => boolean) - custom filter function * * @default 'auto' * @example Custom filter function * symbol => symbol.name.includes('illustration') */ filter?: FilterInlineMode; /** * Merge all inlined symbols into a single sprite. * @default false */ merge?: boolean; /** * Logger instance * @see `@neodx/log` */ log: SvgLogger; } interface SymbolIdParams { /** * Name of the symbol * @example "close" */ symbolName: string; /** * Name of the sprite * @example "common" */ spriteName: string; /** Hash of the symbol's content */ contentHash: string; /** Hash function */ hash: (value: unknown) => string; } //#endregion //#region src/core/reset-colors.d.ts type SvgResetColorsParams = ColorPropertyReplacementInput | ColorPropertyReplacementInput[]; interface ColorPropertyReplacementInput { /** * Properties to replace colors in * @default ['fill', 'stroke'] */ properties?: string | string[]; /** * Colors to keep untouched * @default [] * @example ['#fff', '#000'] */ keep?: ColorsKeepInput; /** * Define it if you want to include only certain files * @example /.*\.icon\.svg$/ // include only icons */ include?: FileFilterInput; /** * Define it if you want to exclude certain files * @example /.*\.illustration\.svg$/ // exclude illustrations */ exclude?: FileFilterInput; /** * Replace colors policy. You can define it in multiple ways: * - { from: , [...], to: } will replace all colors from the `from` array with the `to` value * - `to` property is optional and will be replaced with the "replaceUnknown" option value if not defined * - raw color string ot array (e.g. '#fff' or ['#fff', '#000']) is alias for `{ from: , [...] }` * * @example Replace "#fff" with "currentColor" * { replace: '#fff' } * @example Replace "#fff" and "#000" with "currentColor" * { replace: ['#fff', '#000'] } * @example Replace "#fff" with "#000" * { replace: { from: '#fff', to: '#000' } } * @example Replace "#fff" and "#000" with "currentColor" * { replace: { from: ['#fff', '#000'], to: 'currentColor' } } * @example Replace "#fff" and "#000" with "currentColor" and "#eee" with "#e5e5e5" * { replace: ['#fff', '#000', { from: '#eee', to: '#e5e5e5' }], replaceUnknown: 'currentColor' } */ replace?: ColorReplacementInput | ColorReplacementInput[]; /** * Color to replace unknown (not defined implicitly in "replace.to" option) colors * @default 'currentColor' */ replaceUnknown?: string | false; } type ColorsKeepInput = AnyColorInput | AnyColorInput[]; type FileFilterInput = FileFilterInputValue | FileFilterInputValue[]; type FileFilterInputValue = string | RegExp; type ColorReplacementInput = string | ColorReplacementInputConfig; interface ColorReplacementInputConfig { from: AnyColorInput | AnyColorInput[]; to?: string; } type AnyColorInput = AnyColor | Colord; //#endregion //#region src/core/builder.d.ts interface CreateSvgSpriteBuilderParams { /** * Logger instance * @see `@neodx/log` * @default built-in logger */ log?: AutoLoggerInput; /** * VFS instance, a path or params for creating a VFS instance * @see `@neodx/vfs` * @default process.cwd() */ vfs?: AutoVfsInput; /** * Sprite grouping mode * * - `true` - use `dirname` as sprite name (default), * - `false` - don't group sprites, `defaultSpriteName` will be used for all sprites, * - otherwise a function that accepts relative path and returns sprite name * * @default true * @example Grouping by path's dirname and specific attribute * { group: ({ node, path }) => `${dirname(path)}/${node.props['data-category']}` } */ group?: CallableParam<(file: SymbolMeta) => string>; /** * Root path for the input files. * All paths will be relative to this path. * @default '.' */ inputRoot?: string; /** * Sprite inlining mode, disabled by default * * - `'auto'` - we'll automatically detect all problematic svgs and extract them into separate sprite for future inlining * - `'all'` - all sprites will be inlined. Perfect for solving CDN compatibility * - `false` - no inlining. If we find any potential issues, we'll display corresponding errors in the console * * @default false */ inline?: Partial | FilterInlineMode | false; /** * Path to generated sprite/sprites folder * @default 'public/sprites' */ output?: string; /** * Sprite cleanup mode. * * - `'auto'` - smart cleanup, removes only outdated sprites and requires `metadata` option to identify current sprites * - `'force'` - delete the entire output directory before building sprites * - `false` - no cleanup * * @default 'auto' if `metadata` option is provided, otherwise `false` */ cleanup?: false | SpritesCleanupType; /** * Template of sprite file name * @example {name}.svg * @example sprite-{name}.svg * @example {name}-{hash}.svg * @example {name}-{hash:8}.svg * @default {name}.svg */ fileName?: string; /** * Resolves symbol name for the given file path. * By default, it's a kebab-cased file name without an extension. * * @default path => cases.kebab(basename(path, '.svg')) * @example path => basename(path, '.svg') // don't force any case */ getSymbolName?: (path: string) => string; /** * Should we optimize icons? * - `true` - minify SVG files, * - `false` - don't minify, * - otherwise, a custom configuration (with an SVGO configuration as a part) * * @default true * @example With additional plugins * { * optimize: { * config: { * plugins: [ * { name: 'sortDefsChildren' }, * ] * } * } * } */ optimize?: boolean | CreateSvgoConfigParams; /** * Metadata generation rules. * * - `false` - don't generate metadata, * - `` - path to generated metadata file, alias for `{ path: 'path/to/metadata.ts' }`, * - otherwise, a configuration object (`SpritesMetadataParams`) * * @see `SpritesMetadataParams` * @example * { * metadata: { * path: 'src/sprites/meta.ts', * name: 'mySpritesVariableName', // default: 'sprites' * typeName: 'MySpritesTypeName' // default: 'SpritesMeta' * } * } */ metadata?: SpritesMetadataInput; /** * Reset colors config. * * - `true` - converts all colors to `currentColor`, * - `false` - keeps original colors, * - otherwise custom config * * @default true * @example Complex config * { * resetColors: { * // 1. Don't touch our special static colors * keep: Object.values(colors.static), * // 2. Replace all brand colors with CSS variables * replace: [ * { from: colors.brand.main, to: 'var(--color-brand-main)' }, * { from: colors.brand.secondary, to: 'var(--color-brand-secondary)' } * ], * // 3. Replace all other ("unknown" means "not defined implicitly in `replace.to` option") colors with `currentColor` * replaceUnknown: 'currentColor', * // 4. Preserve specific SVG files untouched * exclude: /.*\.standalone\.svg$/ * } * } */ resetColors?: SvgResetColorsParams | boolean; /** * Default sprite name. Will be used if `group` is `false` or for all root-level svg files. * @default 'sprite' */ defaultSpriteName?: string; } //#endregion //#region src/unplugin.d.ts interface SvgPluginParams extends Omit { /** * Root path for the input files. * All paths will be relative to this path. * @default '.' * @deprecated use `inputRoot` instead */ root?: string; /** * Globs to icons files */ input?: string | string[]; } //#endregion export { SvgPluginParams as t }; //# sourceMappingURL=unplugin-BJsJSQY-.d.cts.map