UNPKG

@svelte-put/inline-svg

Version:
163 lines (154 loc) 5.66 kB
declare module '@svelte-put/inline-svg' { import type { ActionReturn } from 'svelte/action'; /** * *Svelte action for dynamically inlining remote-fetched SVG into DOM * @example * * ```html * <script> * import { inlineSvg } from '@svelte-put/inline-svg; * </script> * * <svg use:inlineSvg={"http://example.com/icon.svg"}></svg> * ``` * @param node - SVGElement to inline SVG into * @param param - config for the action. * */ export function inlineSvg(node: SVGElement, param: InlineSvgActionParameter): InlineSvgActionReturn; /** * resolve the input parameters of `inlineSvg` action to an internally usable config * */ export function resolveConfig(param?: InlineSvgActionParameter | undefined): Required<InlineSvgActionConfig>; export const DEFAULT_INLINE_SVG_ACTION_CONFIG: Required<InlineSvgActionConfig>; /** * Deprecated, use `InlineSvgActionParameter` and `InlineSvgActionConfig` instead */ export type InlineSvgActionParameters = InlineSvgActionParameter; /** verbose config for `inlineSvg` action */ interface InlineSvgActionConfig { /** svg remote URI */ src: string; /** cache policy for use in fetch from svg `src` */ cache?: Request['cache']; /** * automatically calculate dimensions from the available attributes * of both the local SVG element (on which action is used) and the remote SVG * * For example, if you specify only `width` to the local SVG element, the * height will automatically be calculated from the remote SVG * * For this to work, width & height must be "extractable" from the remote element, * that is, the remote SVG must either have the `viewBox` or both `width` and `height` attributes that * is in the same unit. */ autoDimensions?: boolean; /** * optionally transform the SVG string fetched from remote source before inlining */ transform?: (svg: string) => string; } /** input parameters for `inlineSvg` action */ type InlineSvgActionParameter = string | InlineSvgActionConfig; type InlineSvgActionReturn = ActionReturn<InlineSvgActionParameter>; export {}; } declare module '@svelte-put/inline-svg/preprocessor' { /** * create a preprocessor that inlines SVG from disk to source code at compile time * @param uSources - sources to search for svg * @param uConfig - global options to configure preprocessor input & output * @returns - Svelte preprocessor interface */ export default function inlineSvg_1(uSources?: PreprocessorSourceDefinition | PreprocessorSourceDefinition[], uConfig?: PreprocessorConfig): import("svelte/compiler").PreprocessorGroup & { __params: ResolvedUserParameters; }; export type ResolvedUserParameters = { /** * - resolved sources parameter */ sources: ResolvedSources; /** * - resolved config parameter */ config: ResolvedPreprocessorConfig; }; /** sources for the inline svg */ type PreprocessorSourceDefinition = { /** * 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 PreprocessorConfig = { /** attribute to get the svg source from, default to `inline-src` */ inlineSrcAttributeName?: string; /** whether to keep the inline src attribute after compilation, default to `false` */ keepInlineSrcAttribute?: boolean; }; type ResolvedSourceDefinition = { /** * - directories to search for SVG files */ directories: string[]; /** * - HTML attributes to apply to SVG element */ attributes: Record<string, string>; }; type ResolvedSources = { /** * - fallback definition */ local: ResolvedSourceDefinition; /** * - specific directories-based definitions */ dirs: ResolvedSourceDefinition[]; }; type ResolvedPreprocessorConfig = Required<PreprocessorConfig>; export {}; } declare module '@svelte-put/inline-svg/vite' { /** * create a Vite plugin that wraps a Svelte preprocessor to * inline SVG from disk to source code at compile time * */ export default function inlineSvg_1(uSources?: PreprocessorSourceDefinition | PreprocessorSourceDefinition[], uConfig?: VitePluginConfig): import("vite").Plugin; /** sources for the inline svg */ type PreprocessorSourceDefinition = { /** * 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 PreprocessorConfig = { /** attribute to get the svg source from, default to `inline-src` */ inlineSrcAttributeName?: string; /** whether to keep the inline src attribute after compilation, default to `false` */ keepInlineSrcAttribute?: boolean; }; /** configuration for the vite plugin that wraps inline-svg preprocessor */ type VitePluginConfig = PreprocessorConfig & { /** * output path for generated type definition for inline-src attribute. * Defaults to `null` (no generation). * Set to `true` to use the default `src/preprocess-inline-svg.d.ts` path. */ typedef?: string | null | true; }; export {}; } //# sourceMappingURL=index.d.ts.map