UNPKG

tpa-style-webpack-plugin

Version:

A Webpack plugin that handles wix tpa styles, it separates static css file that injects dynamic style at runtime.

53 lines (52 loc) 1.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.underlineFontHackSupport = exports.directionReplacer = void 0; const annotateDirection = match => `"direction(${match})"`; function replaceRtlStrings(str) { return str .replace(/STARTSIGN/g, annotateDirection) .replace(/ENDSIGN/g, annotateDirection) .replace(/START/g, annotateDirection) .replace(/END/g, annotateDirection) .replace(/DIR/g, annotateDirection); } function replaceValue(str) { str = str.trim(); if (str.match(/STARTSIGN\d/)) { str = str.replace('STARTSIGN', annotateDirection); } if (str.match(/ENDSIGN\d/)) { str = str.replace('ENDSIGN', annotateDirection); } if (str.match(/DEG-START/)) { str = str.replace('DEG-START', annotateDirection); } if (str.match(/DEG-END/)) { str = str.replace('DEG-END', annotateDirection); } if (str === 'DIR') { str = annotateDirection(str); } else if (str === 'END') { str = annotateDirection(str); } else if (str === 'START') { str = annotateDirection(str); } return str; } function directionReplacer(decl) { decl.prop = replaceRtlStrings(decl.prop); decl.value = replaceValue(decl.value); return decl; } exports.directionReplacer = directionReplacer; const underlineFontHackRegex = /font\((--[^)]+)\)/; function underlineFontHackSupport(decl) { let matches; if (decl.prop === 'font' && (matches = decl.value.match(underlineFontHackRegex))) { decl.after(`text-decoration: "underline(${matches[1]})"`); } return decl; } exports.underlineFontHackSupport = underlineFontHackSupport;