UNPKG

@openanime/ass2esl

Version:

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

84 lines (82 loc) 2.24 kB
import { ALIGNMENT_MAP } from "./chunk-WA7VBIH5.js"; import { __name } from "./chunk-7QVYU63E.js"; // src/utils.ts function convertVBHexToCssColor(vbHexColor) { let hexStr = vbHexColor.trim(); if (hexStr.startsWith("&H00")) { hexStr = hexStr.replace("&H00", ""); } if (hexStr.endsWith("&")) { hexStr = hexStr.slice(0, -1); } return "#" + hexStr; } __name(convertVBHexToCssColor, "convertVBHexToCssColor"); function quoteString(s) { const escaped = s.replace(/\\/g, "\\\\").replace(/"/g, '\\\\"').replace(/\n/g, "\\n"); return `"${escaped}"`; } __name(quoteString, "quoteString"); function secondsToMilliseconds(seconds) { return seconds * 1e3; } __name(secondsToMilliseconds, "secondsToMilliseconds"); function formatHclValue(key, value) { if (key === "align" && typeof value === "number") { return quoteString(ALIGNMENT_MAP[value] || `unknown-alignment-${value}`); } if ((key === "in" || key === "out") && typeof value === "number") { return secondsToMilliseconds(value); } if (key === "color" || key === "border_color") { const colorData = convertVBHexToCssColor(value); if (colorData) { return quoteString(colorData); } } if (typeof value === "string") { return quoteString(value); } if (typeof value === "number" || typeof value === "boolean") { return value; } return quoteString(String(value)); } __name(formatHclValue, "formatHclValue"); function transformAssTextToEsl(assText) { return assText.replace(/\\N/g, "<br>"); } __name(transformAssTextToEsl, "transformAssTextToEsl"); function getDifferenceKeys(source, target) { const result = {}; for (const key in source) { if (source[key] !== target[key]) { result[key] = source[key]; } } return Object.keys(result); } __name(getDifferenceKeys, "getDifferenceKeys"); function diffObj(source, target) { const keys = getDifferenceKeys(source, target); const newObj = {}; for (const key of keys) { newObj[key] = target[key]; } return newObj; } __name(diffObj, "diffObj"); export { convertVBHexToCssColor, quoteString, secondsToMilliseconds, formatHclValue, transformAssTextToEsl, getDifferenceKeys, diffObj }; //# sourceMappingURL=chunk-ZLUXC5RC.js.map