import MagicString from 'magic-string'; import * as svelte from 'svelte/compiler'; /** @typedef {ReturnType['children']} StyleSheetChildren */ /** @typedef {{ property: string; value: string; start: number; end: number; type: 'Declaration' }} Declaration */ const parse = svelte.parseCss ? svelte.parseCss : /** @param {string} css */ (css) => { return /** @type {{ css: { children: StyleSheetChildren } }} */ ( svelte.parse(``) ).css; }; const SKIP_PARSING_REGEX = /url\(/i; /** Capture a single url(...) so we can process them one at a time */ const URL_FUNCTION_REGEX = /url\(\s*.*?\)/gi; /** Captures the value inside a CSS url(...) */ const URL_PARAMETER_REGEX = /url\(\s*(['"]?)(.*?)\1\s*\)/i; /** Splits the URL if there's a query string or hash fragment */ const HASH_OR_QUERY_REGEX = /[#?]/; /** * Assets handled by Vite that are referenced in the stylesheet always start * with this prefix because Vite emits them into the same directory as the CSS file */ const VITE_ASSET_PREFIX = './'; const AST_OFFSET = '