@svelte-put/preprocess-inline-svg
Version:
minimal svg inliner from local resources at build time
85 lines (81 loc) • 2.51 kB
TypeScript
import * as magic_string from 'magic-string';
/**
*
* sources for the inline svg
*/
type SourceConfig = {
/**
* directories relative to which the svg source path will be resolved
*/
directories?: string[] | string;
/**
* default attributes to add to the svg element, will override the attributes from the svg source,
* but be overridden by the attributes from the element itself (in svelte source)
*/
attributes?: Record<string, string>;
};
/**
*
* global options for configuring behaviors of the inline-svg preprocessor
*/
type InlineSvgConfig = {
/** attribute to get the svg source from, default to `data-inline-src` */
inlineSrcAttributeName?: string;
/** whether to keep the inline src attribute after build, default to `false` */
keepInlineSrcAttribute?: boolean;
};
/**
* @package
* default config of the inline-svg preprocessor
*/
declare const DEFAULT_SOURCES_CONFIG: {
directories: string[];
attributes: Record<string, string>;
};
/**
* @package
*/
declare function resolveSourceOptions(options?: SourceConfig): {
directories: string[];
attributes: Record<string, string>;
};
/**
* resolve config input and search for a default
* If none is found, use DEFAULT_SOURCES_CONFIG.
* If multiple of such input are found, throw an error.
* @package
*/
declare function resolveSources(sources?: SourceConfig | SourceConfig[]): {
local: {
directories: any[];
attributes: Record<string, string>;
};
dirs: {
directories: string[];
attributes: Record<string, string>;
}[];
};
/**
* @package
*/
declare const DEFAULT_INLINE_SVG_CONFIG: {
inlineSrcAttributeName: string;
keepInlineSrcAttribute: false;
};
/**
* @package
*/
declare function resolveInlineSvgConfig(config?: InlineSvgConfig): {
inlineSrcAttributeName: string;
keepInlineSrcAttribute: boolean;
};
/** @package */
declare function findSvgSrc(filename: string, directories: string[], inlineSrc?: string): string | undefined;
/**
* @package
*/
declare function transform(code: string, filename: string, sources: ReturnType<typeof resolveSources>, config: ReturnType<typeof resolveInlineSvgConfig>): {
code: string;
map: magic_string.SourceMap;
};
export { DEFAULT_SOURCES_CONFIG as D, type InlineSvgConfig as I, type SourceConfig as S, resolveSources as a, DEFAULT_INLINE_SVG_CONFIG as b, resolveInlineSvgConfig as c, findSvgSrc as f, resolveSourceOptions as r, transform as t };