UNPKG

wj-elements

Version:

WebJET Elements is a modern set of user interface tools harnessing the power of web components designed to simplify web application development.

61 lines (60 loc) 1.57 kB
let animations = []; function parseCSS(css) { const keyframesRegex = /@keyframes\s+([\w-]+)\s*{([\s\S]+?})\s*}/g; let match; let localAnimations = []; while ((match = keyframesRegex.exec(css)) !== null) { let name = match[1]; let frames = match[2].trim(); let keyframes = parseKeyframes(frames); localAnimations.push({ name, keyframes }); } return localAnimations; } function parseKeyframes(frames) { const frameRegex = /([\d%]+)\s*{([\s\S]+?)}/g; let match; let keyframes = []; while ((match = frameRegex.exec(frames)) !== null) { let offset = parseFloat(match[1]) / 100; let properties = parseProperties(match[2]); let keyframeObject = { offset, ...properties }; keyframes.push(keyframeObject); } keyframes.sort((a, b) => a.offset - b.offset); return keyframes; } function parseProperties(propertiesString) { const properties = {}; propertiesString.split(";").forEach((property) => { const [key, value] = property.split(":").map((part) => part.trim()); if (key && value) { if (key === "animation-timing-function") { properties["easing"] = value; } else { properties[key] = value; } } }); return properties; } async function fetchAndParseCSS(css) { try { if (animations.length > 0) { return animations; } animations = parseCSS(css); return await animations; } catch (error) { console.error("Error:", error); return null; } } export { animations, fetchAndParseCSS }; //# sourceMappingURL=animations.js.map