UNPKG

@openanime/ass2esl

Version:

Utilities to convert Advanced SubStation Alpha (ASS) to Expressive Subtitle Language (ESL)

67 lines (65 loc) 1.98 kB
import { formatHclValue, quoteString } from "./chunk-ZLUXC5RC.js"; import { STYLE_PROPERTY_MAP, VALID_STYLE_PROPS } from "./chunk-WA7VBIH5.js"; import { __name } from "./chunk-7QVYU63E.js"; // src/style-processor.ts function processStyles(rawStyles) { const stylesHCLParts = []; const processedStylesMap = /* @__PURE__ */ new Map(); for (const [styleName, _styleData] of Object.entries(rawStyles)) { const styleData = _styleData?.style; if (styleData && typeof styleData === "object") { const currentStyle = { name: styleName, hclProperties: [], features: /* @__PURE__ */ new Set(), margins: {} }; for (const [assPropName, assPropValue] of Object.entries(styleData)) { if (assPropValue === null || assPropValue === void 0) continue; if ([ "Bold", "Italic", "Underline", "StrikeOut" ].includes(assPropName)) { if (assPropValue === -1) { currentStyle.features.add(assPropName); } } if ([ "MarginL", "MarginR", "MarginV" ].includes(assPropName) && typeof assPropValue === "number") { currentStyle.margins[assPropName] = assPropValue; } if (VALID_STYLE_PROPS.includes(assPropName)) { const eslPropName = STYLE_PROPERTY_MAP[assPropName]; const eslValue = formatHclValue(eslPropName, assPropValue); currentStyle.hclProperties.push(` ${eslPropName} = ${eslValue}`); } } processedStylesMap.set(styleName, currentStyle); stylesHCLParts.push(`style ${quoteString(styleName)} {`); stylesHCLParts.push(...currentStyle.hclProperties.sort()); stylesHCLParts.push(`}`); } } return { stylesHCL: stylesHCLParts.join("\n"), processedStylesMap }; } __name(processStyles, "processStyles"); export { processStyles }; //# sourceMappingURL=chunk-MV73J6ZW.js.map