Repository URL to install this package:
|
Version:
1.2.18 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.use = exports.set = exports.styleh = void 0;
/* eslint-disable */
/* eslint-disable max-lines */
/* eslint-disable max-statements */
/* eslint-disable complexity */
/* eslint-disable default-case */
// import IS_PIPELINE_SERVER from 'config/env/IS_PIPELINE_SERVER'
// const IS_PIPELINE_SERVER = process.env.NODE_ENV === 'production'
// may need to scope it, for when they call `new` for interop
/**
* @notes
*
* The ['<method name>'] pattern is used to support closure compiler
* the jsdoc signatures are also used to the same effect
*
* ----
*
* int + int + int === n4 [faster]
*
* vs
*
* int === n1 && int === n2 && int === n3
*
* ----
*
* switch (int) { case ints...} [faster]
*
* vs
*
* if (int == 1 && int === 2 ...)
*
* ----
*
* The (first*n1 + second*n2 + third*n3) format used in the property parser
* is a simple way to hash the sequence of characters
* taking into account the index they occur in
* since any number of 3 character sequences could produce duplicates.
*
* On the other hand sequences that are directly tied to the index of the character
* resolve a far more accurate measure, it's also faster
* to evaluate one condition in a switch statement
* than three in an if statement regardless of the added math.
*
* This allows the vendor prefixer to be both small and fast.
*/
const nullptn = /^\0+/g;
/* matches leading null characters */
const formatptn = /[\0\r\f]/g;
/* matches new line, null and formfeed characters */
const colonptn = /: */g;
/* splits animation rules */
const cursorptn = /zoo|gra/;
/* assert cursor varient */
const transformptn = /([,: ])(transform)/g;
/* vendor prefix transform, older webkit */
const animationptn = /,+\s*(?![^(]*[)])/g;
/* splits multiple shorthand notation animations */
const propertiesptn = / +\s*(?![^(]*[)])/g;
/* animation properties */
const elementptn = / *[\0] */g;
/* selector elements */
const selectorptn = /,\r+?/g;
/* splits selectors */
const andptn = /([\t\r\n ])*\f?&/g;
/* match & */
const escapeptn = /:global\(((?:[^\(\)\[\]]*|\[.*\]|\([^\(\)]*\))*)\)/g;
/* matches :global(.*) */
const invalidptn = /\W+/g;
/* removes invalid characters from keyframes */
const keyframeptn = /@(k\w+)\s*(\S*)\s*/;
/* matches @keyframes $1 */
const plcholdrptn = /::(place)/g;
/* match ::placeholder varient */
const readonlyptn = /:(read-only)/g;
/* match :read-only varient */
const beforeptn = /\s+(?=[{\];=:>])/g;
/* matches \s before ] ; = : */
const afterptn = /([[}=:>])\s+/g;
/* matches \s after characters [ } = : */
const tailptn = /(\{[^{]+?);(?=\})/g;
/* matches tail semi-colons ;} */
const whiteptn = /\s{2,}/g;
/* matches repeating whitespace */
const pseudoptn = /([^\(])(:+) */g;
/* pseudo element */
const writingptn = /[svh]\w+-[tblr]{2}/;
/* match writing mode property values */
const gradientptn = /([\w-]+t\()/g;
/* match *gradient property */
const supportsptn = /\(\s*(.*)\s*\)/g;
/* match supports (groups) */
const propertyptn = /([^]*?);/g;
/* match properties leading semicolon */
const selfptn = /-self|flex-/g;
/* match flex- and -self in align-self: flex-*; */
const pseudofmt = /[^]*?(:[rp][el]a[\w-]+)[^]*/;
/* extrats :readonly or :placholder from selector */
const trimptn = /[ \t]+$/;
/* match tail whitspace */
/* vendors */
const webkit = '-webkit-';
const moz = '-moz-';
const ms = '-ms-';
/* character codes */
const SEMICOLON = 59;
/* ; */
const CLOSEBRACES = 125;
/* } */
const OPENBRACES = 123;
/* { */
const OPENPARENTHESES = 40;
/* ( */
const CLOSEPARENTHESES = 41;
/* ) */
const OPENBRACKET = 91;
/* [ */
const CLOSEBRACKET = 93;
/* ] */
const NEWLINE = 10;
/* \n */
const CARRIAGE = 13;
/* \r */
const TAB = 9;
/* \t */
const AT = 64;
/* @ */
const SPACE = 32;
/* */
const AND = 38;
/* & */
const DASH = 45;
/* - */
const UNDERSCORE = 95;
/* _ */
const STAR = 42;
/* * */
const COMMA = 44;
/* , */
const COLON = 58;
/* : */
const SINGLEQUOTE = 39;
/* ' */
const DOUBLEQUOTE = 34;
/* " */
const FOWARDSLASH = 47;
/* / */
const GREATERTHAN = 62;
/* > */
const PLUS = 43;
/* + */
const TILDE = 126;
/* ~ */
const NULL = 0;
/* \0 */
const FORMFEED = 12;
/* \f */
const VERTICALTAB = 11;
/* \v */
/* special identifiers */
const KEYFRAME = 107;
/* k */
const MEDIA = 109;
/* m */
const SUPPORTS = 115;
/* s */
const PLACEHOLDER = 112;
/* p */
const READONLY = 111;
/* o */
const IMPORT = 169;
/* <at>i */
const CHARSET = 163;
/* <at>c */
const DOCUMENT = 100;
/* <at>d */
const PAGE = 112;
/* <at>p */
function factory(__scope) {
let column = 1;
/* current column */
let line = 1;
/* current line numebr */
let pattern = 0;
/* :pattern */
let cascade = 1;
/* #id h1 h2 vs h1#id h2#id */
let prefix = 1;
/* vendor prefix */
let escape = 1;
/* escape :global() pattern */
let compress = 0;
/* compress output */
let semicolon = 0;
/* no/semicolon option */
let preserve = 0;
/* preserve empty selectors */
/* empty reference @todo - use EMPTY_ARRAY */
let array = [];
/* plugins */
let plugins = [];
let plugged = 0;
let should = null;
/* plugin context */
const POSTS = -2;
const PREPS = -1;
const UNKWN = 0;
const PROPS = 1;
const BLCKS = 2;
const ATRUL = 3;
/* plugin newline context */
let unkwn = 0;
/* keyframe animation */
let keyed = 1;
let key = '';
/* selector namespace */
let nscopealt = '';
let nscope = '';
/**
* Compile
*
* @param {Array<string>} parent
* @param {Array<string>} current
* @param {string} body
* @param {number} id
* @param {number} depth
* @return {string}
*/
function compile(parent, current, body, id, depth) {
let bracket = 0;
/* brackets [] */
let comment = 0;
/* comments /* // or /* */
let parentheses = 0;
/* functions () */
let quote = 0;
/* quotes '', "" */
let first = 0;
/* first character code */
let second = 0;
/* second character code */
let code = 0;
/* current character code */
let tail = 0;
/* previous character code */
let trail = 0;
/* character before previous code */
let peak = 0;
/* previous non-whitespace code */
let counter = 0;
/* count sequence termination */
let context = 0;
/* track current context */
let atrule = 0;
/* track @at-rule context */
let pseudo = 0;
/* track pseudo token index */
let caret = 0;
/* current character index */
let format = 0;
/* control character formating context */
let insert = 0;
/* auto semicolon insertion */
let invert = 0;
/* inverted selector pattern */
let length = 0;
/* generic length address */
let eof = body.length;
/* end of file(length) */
let eol = eof - 1;
/* end of file(characters) */
let char = '';
/* current character */
let chars = '';
/* current buffer of characters */
let child = '';
/* next buffer of characters */
let out = '';
/* compiled body */
let children = '';
/* compiled children */
let flat = '';
/* compiled leafs */
let selector;
/* generic selector address */
let result;
/* generic address */
// ...build body
while (caret < eof) {
code = body.charCodeAt(caret); // eof varient
if (caret === eol) {
// last character + noop context, add synthetic padding for noop context to terminate
if (comment + quote + parentheses + bracket !== 0) {
if (comment !== 0) {
code = comment === FOWARDSLASH ? NEWLINE : FOWARDSLASH;
}
quote = parentheses = bracket = 0;
eof++;
eol++;
}
}
if (comment + quote + parentheses + bracket === 0) {
// eof varient
if (caret === eol) {
if (format > 0) {
chars = chars.replace(formatptn, '');
}
if (chars.trim().length > 0) {
switch (code) {
case SPACE:
case TAB:
case SEMICOLON:
case CARRIAGE:
case NEWLINE:
{
break;
}
default:
{
chars += body.charAt(caret);
}
}
code = SEMICOLON;
}
} // auto semicolon insertion
if (insert === 1) {
switch (code) {
// false flags
case OPENBRACES:
case CLOSEBRACES:
case SEMICOLON:
case DOUBLEQUOTE:
case SINGLEQUOTE:
case OPENPARENTHESES:
case CLOSEPARENTHESES:
case COMMA:
{
insert = 0;
}
// ignore
case TAB:
case CARRIAGE:
case NEWLINE:
case SPACE:
{
break;
}
// valid
default:
{
insert = 0;
length = caret;
first = code;
caret--;
code = SEMICOLON;
while (length < eof) {
switch (body.charCodeAt(++length)) {
case NEWLINE:
case CARRIAGE:
case SEMICOLON:
{
caret++;
code = first;
}
case COLON:
case OPENBRACES:
{
length = eof;
}
}
}
}
}
} // token varient
switch (code) {
case OPENBRACES:
{
chars = chars.trim();
first = chars.charCodeAt(0);
counter = 1;
length = ++caret;
while (caret < eof) {
code = body.charCodeAt(caret);
switch (code) {
case OPENBRACES:
{
counter++;
break;
}
case CLOSEBRACES:
{
counter--;
break;
}
}
if (counter === 0) {
break;
}
caret++;
}
child = body.substring(length, caret);
if (first === NULL) {
first = (chars = chars.replace(nullptn, '').trim()).charCodeAt(0);
}
switch (first) {
// @at-rule
case AT:
{
if (format > 0) {
chars = chars.replace(formatptn, '');
}
second = chars.charCodeAt(1);
switch (second) {
case DOCUMENT:
case MEDIA:
case SUPPORTS:
case DASH:
{
selector = current;
break;
}
default:
{
selector = array;
}
}
child = compile(current, selector, child, second, depth + 1);
length = child.length; // preserve empty @at-rule
if (preserve > 0 && length === 0) {
length = chars.length;
} // execute plugins, @at-rule context
if (plugged > 0) {
selector = select(array, chars, invert);
result = proxy(ATRUL, child, selector, current, line, column, length, second, depth);
chars = selector.join('');
if (result !== void 0) {
if ((length = (child = result.trim()).length) === 0) {
second = 0;
child = '';
}
}
}
if (length > 0) {
switch (second) {
case SUPPORTS:
{
chars = chars.replace(supportsptn, supports);
}
case DOCUMENT:
case MEDIA:
case DASH:
{
child = chars + '{' + child + '}';
break;
}
case KEYFRAME:
{
chars = chars.replace(keyframeptn, '$1 $2' + (keyed > 0 ? key : ''));
child = chars + '{' + child + '}';
if (prefix === 1 || prefix === 2 && vendor('@' + child, 3)) {
child = '@' + webkit + child + '@' + child;
} else {
child = '@' + child;
}
break;
}
default:
{
child = chars + child;
if (id === PAGE) {
child = (out += child, '');
}
}
}
} else {
child = '';
}
break;
}
// selector
default:
{
child = compile(current, select(current, chars, invert), child, id, depth + 1);
}
}
children += child; // reset
context = 0;
insert = 0;
pseudo = 0;
format = 0;
invert = 0;
atrule = 0;
chars = '';
child = '';
code = body.charCodeAt(++caret);
break;
}
case CLOSEBRACES:
case SEMICOLON:
{
chars = (format > 0 ? chars.replace(formatptn, '') : chars).trim();
if ((length = chars.length) > 1) {
// monkey-patch missing colon
if (pseudo === 0) {
first = chars.charCodeAt(0); // first character is a letter or dash, buffer has a space character
if (first === DASH || first > 96 && first < 123) {
length = (chars = chars.replace(' ', ':')).length;
}
} // execute plugins, property context
if (plugged > 0) {
if ((result = proxy(PROPS, chars, current, parent, line, column, out.length, id, depth)) !== void 0) {
if ((length = (chars = result.trim()).length) === 0) {
chars = '\0\0';
}
}
}
first = chars.charCodeAt(0);
second = chars.charCodeAt(1);
switch (first + second) {
case NULL:
{
break;
}
case IMPORT:
case CHARSET:
{
flat += chars + body.charAt(caret);
break;
}
default:
{
if (chars.charCodeAt(length - 1) === COLON) {
break;
}
out += property(chars, first, second, chars.charCodeAt(2));
}
}
} // reset
context = 0;
insert = 0;
pseudo = 0;
format = 0;
invert = 0;
chars = '';
code = body.charCodeAt(++caret);
break;
}
}
} // parse characters
switch (code) {
case CARRIAGE:
case NEWLINE:
{
// auto insert semicolon
if (comment + quote + parentheses + bracket + semicolon === 0) {
// valid non-whitespace characters that
// may precede a newline
switch (peak) {
case CLOSEPARENTHESES:
case SINGLEQUOTE:
case DOUBLEQUOTE:
case AT:
case TILDE:
case GREATERTHAN:
case STAR:
case PLUS:
case FOWARDSLASH:
case DASH:
case COLON:
case COMMA:
case SEMICOLON:
case OPENBRACES:
case CLOSEBRACES:
{
break;
}
default:
{
// current buffer has a colon
if (pseudo > 0) {
insert = 1;
}
}
}
} // terminate line comment
if (comment === FOWARDSLASH) {
comment = 0;
} else if (cascade + context === 0) {
format = 1;
chars += '\0';
} // execute plugins, newline context
if (plugged * unkwn > 0) {
proxy(UNKWN, chars, current, parent, line, column, out.length, id, depth);
} // next line, reset column position
column = 1;
line++;
break;
}
case SEMICOLON:
case CLOSEBRACES:
{
if (comment + quote + parentheses + bracket === 0) {
column++;
break;
}
}
default:
{
// increment column position
column++; // current character
char = body.charAt(caret); // remove comments, escape functions, strings, attributes and prepare selectors
switch (code) {
case TAB:
case SPACE:
{
if (quote + bracket + comment === 0) {
switch (tail) {
case COMMA:
case COLON:
case TAB:
case SPACE:
{
char = '';
break;
}
default:
{
if (code !== SPACE) {
char = ' ';
}
}
}
}
break;
}
// escape breaking control characters
case NULL:
{
char = '\\0';
break;
}
case FORMFEED:
{
char = '\\f';
break;
}
case VERTICALTAB:
{
char = '\\v';
break;
}
// &
case AND:
{
// inverted selector pattern i.e html &
if (quote + comment + bracket === 0 && cascade > 0) {
invert = 1;
format = 1;
char = '\f' + char;
}
break;
}
// ::p<l>aceholder, l
// :read-on<l>y, l
case 108:
{
if (quote + comment + bracket + pattern === 0 && pseudo > 0) {
switch (caret - pseudo) {
// ::placeholder
case 2:
{
if (tail === PLACEHOLDER && body.charCodeAt(caret - 3) === COLON) {
pattern = tail;
}
}
// :read-only
case 8:
{
if (trail === READONLY) {
pattern = trail;
}
}
}
}
break;
}
// :<pattern>
case COLON:
{
if (quote + comment + bracket === 0) {
pseudo = caret;
}
break;
}
// selectors
case COMMA:
{
if (comment + parentheses + quote + bracket === 0) {
format = 1;
char += '\r';
}
break;
}
// quotes
case DOUBLEQUOTE:
{
if (comment === 0) {
quote = quote === code ? 0 : quote === 0 ? code : quote;
}
break;
}
case SINGLEQUOTE:
{
if (comment === 0) {
quote = quote === code ? 0 : quote === 0 ? code : quote;
}
break;
}
// attributes
case OPENBRACKET:
{
if (quote + comment + parentheses === 0) {
bracket++;
}
break;
}
case CLOSEBRACKET:
{
if (quote + comment + parentheses === 0) {
bracket--;
}
break;
}
// functions
case CLOSEPARENTHESES:
{
if (quote + comment + bracket === 0) {
parentheses--;
}
break;
}
case OPENPARENTHESES:
{
if (quote + comment + bracket === 0) {
if (context === 0) {
switch (tail * 2 + trail * 3) {
// :matches
case 533:
{
break;
}
// :global, :not, :nth-child etc...
default:
{
counter = 0;
context = 1;
}
}
}
parentheses++;
}
break;
}
case AT:
{
if (comment + parentheses + quote + bracket + pseudo + atrule === 0) {
atrule = 1;
}
break;
}
// block/line comments
case STAR:
case FOWARDSLASH:
{
if (quote + bracket + parentheses > 0) {
break;
}
switch (comment) {
// initialize line/block comment context
case 0:
{
switch (code * 2 + body.charCodeAt(caret + 1) * 3) {
// //
case 235:
{
comment = FOWARDSLASH;
break;
}
// /*
case 220:
{
length = caret;
comment = STAR;
break;
}
}
break;
}
// end block comment context
case STAR:
{
if (code === FOWARDSLASH && tail === STAR) {
// /*<!> ... */, !
if (body.charCodeAt(length + 2) === 33) {
out += body.substring(length, caret + 1);
}
char = '';
comment = 0;
}
}
}
}
} // ignore comment blocks
if (comment === 0) {
// aggressive isolation mode, divide each individual selector
// including selectors in :not function but excluding selectors in :global function
if (cascade + quote + bracket + atrule === 0 && id !== KEYFRAME && code !== SEMICOLON) {
switch (code) {
case COMMA:
case TILDE:
case GREATERTHAN:
case PLUS:
case CLOSEPARENTHESES:
case OPENPARENTHESES:
{
if (context === 0) {
// outside of an isolated context i.e nth-child(<...>)
switch (tail) {
case TAB:
case SPACE:
case NEWLINE:
case CARRIAGE:
{
char = char + '\0';
break;
}
default:
{
char = '\0' + char + (code === COMMA ? '' : '\0');
}
}
format = 1;
} else {
// within an isolated context, sleep untill it's terminated
switch (code) {
case OPENPARENTHESES:
{
context = ++counter;
break;
}
case CLOSEPARENTHESES:
{
if ((context = --counter) === 0) {
format = 1;
char += '\0';
}
break;
}
}
}
break;
}
case TAB:
case SPACE:
{
switch (tail) {
case NULL:
case OPENBRACES:
case CLOSEBRACES:
case SEMICOLON:
case COMMA:
case FORMFEED:
case TAB:
case SPACE:
case NEWLINE:
case CARRIAGE:
{
break;
}
default:
{
// ignore in isolated contexts
if (context === 0) {
format = 1;
char += '\0';
}
}
}
}
}
} // concat buffer of characters
chars += char; // previous non-whitespace character code
if (code !== SPACE && code !== TAB) {
peak = code;
}
}
}
} // tail character codes
trail = tail;
tail = code; // visit every character
caret++;
}
length = out.length; // preserve empty selector
if (preserve > 0) {
if (length === 0 && children.length === 0 && current[0].length === 0 === false) {
if (id !== MEDIA || current.length === 1 && (cascade > 0 ? nscopealt : nscope) === current[0]) {
length = current.join(',').length + 2;
}
}
}
if (length > 0) {
// cascade isolation mode?
selector = cascade === 0 && id !== KEYFRAME ? isolate(current) : current; // execute plugins, block context
if (plugged > 0) {
result = proxy(BLCKS, out, selector, parent, line, column, length, id, depth);
if (result !== void 0 && (out = result).length === 0) {
return flat + out + children;
}
}
out = selector.join(',') + '{' + out + '}';
if (prefix * pattern !== 0) {
if (prefix === 2 && !vendor(out, 2)) {
pattern = 0;
}
switch (pattern) {
// ::read-only
case READONLY:
{
out = out.replace(readonlyptn, ':' + moz + '$1') + out;
break;
}
// ::placeholder
case PLACEHOLDER:
{
out = out.replace(plcholdrptn, '::' + webkit + 'input-$1') + out.replace(plcholdrptn, '::' + moz + '$1') + out.replace(plcholdrptn, ':' + ms + 'input-$1') + out;
break;
}
}
pattern = 0;
}
}
return flat + out + children;
}
/**
* Select
*
* @param {Array<string>} parent
* @param {string} current
* @param {number} invert
* @return {Array<string>}
*/
function select(parent, current, invert) {
let selectors = current.trim().split(selectorptn);
var out = selectors;
let length = selectors.length;
let l = parent.length;
switch (l) {
// 0-1 parent selectors
case 0:
case 1:
{
for (var i = 0, selector = l === 0 ? '' : parent[0] + ' '; i < length; ++i) {
out[i] = scope(selector, out[i], invert, l).trim();
}
break;
}
// >2 parent selectors, nested
default:
{
for (var i = 0, j = 0, out = []; i < length; ++i) {
for (let k = 0; k < l; ++k) {
out[j++] = scope(parent[k] + ' ', selectors[i], invert, l).trim();
}
}
}
}
return out;
}
/**
* Scope
*
* @param {string} parent
* @param {string} current
* @param {number} invert
* @param {number} level
* @return {string}
*/
function scope(parent, current, invert, level) {
let selector = current;
let code = selector.charCodeAt(0); // trim leading whitespace
if (code < 33) {
code = (selector = selector.trim()).charCodeAt(0);
}
switch (code) {
// &
case AND:
{
switch (cascade + level) {
case 0:
case 1:
{
if (parent.trim().length === 0) {
break;
}
}
default:
{
return selector.replace(andptn, '$1' + parent.trim());
}
}
break;
}
// :
case COLON:
{
switch (selector.charCodeAt(1)) {
// g in :global
case 103:
{
if (escape > 0 && cascade > 0) {
return selector.replace(escapeptn, '$1').replace(andptn, '$1' + nscope);
}
break;
}
default:
{
// :hover
return parent.trim() + selector;
}
}
}
default:
{
// html &
if (invert * cascade > 0 && selector.indexOf('\f') > 0) {
return selector.replace(andptn, (parent.charCodeAt(0) === COLON ? '' : '$1') + parent.trim());
}
}
}
return parent + selector;
}
/**
* Property
*
* @param {string} input
* @param {number} first
* @param {number} second
* @param {number} third
* @return {string}
*/
function property(input, first, second, third) {
let index = 0;
let out = input + ';';
let hash = first * 2 + second * 3 + third * 4;
let cache; // animation: a, n, i characters
if (hash === 944) {
return animation(out);
} else if (prefix === 0 || prefix === 2 && !vendor(out, 1)) {
return out;
} // vendor prefix
switch (hash) {
// text-decoration/text-size-adjust: t, e, x
case 1015:
{
// text-size-adjust, -
return out.charCodeAt(9) === DASH ? webkit + out + out : out;
}
// filter/fill f, i, l
case 951:
{
// filter, t
return out.charCodeAt(3) === 116 ? webkit + out + out : out;
}
// color/column, c, o, l
case 963:
{
// column, n
return out.charCodeAt(5) === 110 ? webkit + out + out : out;
}
// box-decoration-break, b, o, x
case 1009:
{
if (out.charCodeAt(4) !== 100) {
break;
}
}
// mask, m, a, s
// clip-path, c, l, i
case 969:
case 942:
{
return webkit + out + out;
}
// appearance: a, p, p
case 978:
{
return webkit + out + moz + out + out;
}
// hyphens: h, y, p
// user-select: u, s, e
case 1019:
case 983:
{
return webkit + out + moz + out + ms + out + out;
}
// background/backface-visibility, b, a, c
case 883:
{
// backface-visibility, -
return out.charCodeAt(8) === DASH ? webkit + out + out : out;
}
// flex: f, l, e
case 932:
{
if (out.charCodeAt(4) === DASH) {
switch (out.charCodeAt(5)) {
// flex-grow, g
case 103:
{
return webkit + 'box-' + out.replace('-grow', '') + webkit + out + ms + out.replace('grow', 'positive') + out;
}
// flex-shrink, s
case 115:
{
return webkit + out + ms + out.replace('shrink', 'negative') + out;
}
// flex-basis, b
case 98:
{
return webkit + out + ms + out.replace('basis', 'preferred-size') + out;
}
}
}
return webkit + out + ms + out + out;
}
// order: o, r, d
case 964:
{
return webkit + out + ms + 'flex' + '-' + out + out;
}
// justify-items/justify-content, j, u, s
case 1023:
{
// justify-content, c
if (out.charCodeAt(8) !== 99) {
break;
}
cache = out.substring(out.indexOf(':', 15)).replace('flex-', '').replace('space-between', 'justify');
return webkit + 'box-pack' + cache + webkit + out + ms + 'flex-pack' + cache + out;
}
// cursor, c, u, r
case 1005:
{
return cursorptn.test(out) ? out.replace(colonptn, ':' + webkit) + out.replace(colonptn, ':' + moz) + out : out;
}
// writing-mode, w, r, i
case 1000:
{
cache = out.substring(13).trim();
index = cache.indexOf('-') + 1;
switch (cache.charCodeAt(0) + cache.charCodeAt(index)) {
// vertical-lr
case 226:
{
cache = out.replace(writingptn, 'tb');
break;
}
// vertical-rl
case 232:
{
cache = out.replace(writingptn, 'tb-rl');
break;
}
// horizontal-tb
case 220:
{
cache = out.replace(writingptn, 'lr');
break;
}
default:
{
return out;
}
}
return webkit + out + ms + cache + out;
}
// position: sticky
case 1017:
{
if (out.indexOf('sticky', 9) === -1) {
return out;
}
}
// display(flex/inline-flex/inline-box): d, i, s
case 975:
{
index = (out = input).length - 10;
cache = (out.charCodeAt(index) === 33 ? out.substring(0, index) : out).substring(input.indexOf(':', 7) + 1).trim();
switch (hash = cache.charCodeAt(0) + (cache.charCodeAt(7) | 0)) {
// inline-
case 203:
{
// inline-box
if (cache.charCodeAt(8) < 111) {
break;
}
}
// inline-box/sticky
case 115:
{
out = out.replace(cache, webkit + cache) + ';' + out;
break;
}
// inline-flex
// flex
case 207:
case 102:
{
out = out.replace(cache, webkit + (hash > 102 ? 'inline-' : '') + 'box') + ';' + out.replace(cache, webkit + cache) + ';' + out.replace(cache, ms + cache + 'box') + ';' + out;
}
}
return out + ';';
}
// align-items, align-center, align-self: a, l, i, -
case 938:
{
if (out.charCodeAt(5) === DASH) {
switch (out.charCodeAt(6)) {
// align-items, i
case 105:
{
cache = out.replace('-items', '');
return webkit + out + webkit + 'box-' + cache + ms + 'flex-' + cache + out;
}
// align-self, s
case 115:
{
return webkit + out + ms + 'flex-item-' + out.replace(selfptn, '') + out;
}
// align-content
default:
{
return webkit + out + ms + 'flex-line-pack' + out.replace('align-content', '') + out;
}
}
}
break;
}
// width: min-content / width: max-content
case 953:
{
if ((index = out.indexOf('-content', 9)) > 0) {
// width: min-content / width: max-content
if (out.charCodeAt(index - 3) === 109 && out.charCodeAt(index - 4) !== 45) {
cache = out.substring(index - 3);
return 'width:' + webkit + cache + 'width:' + moz + cache + 'width:' + cache;
}
}
break;
}
// transform, transition: t, r, a
case 962:
{
out = webkit + out + (out.charCodeAt(5) === 102 ? ms + out : '') + out; // transitions
if (second + third === 211 && out.charCodeAt(13) === 105 && out.indexOf('transform', 10) > 0) {
return out.substring(0, out.indexOf(';', 27) + 1).replace(transformptn, '$1' + webkit + '$2') + out;
}
break;
}
}
return out;
}
let i = 0;
/**
* Vendor
*
* @param {string} content
* @param {number} context
* @return {boolean}
*/
function vendor(content, context) {
let index = content.indexOf(context === 1 ? ':' : '{');
let key = content.substring(0, context !== 3 ? index : 10);
let value = content.substring(index + 1, content.length - 1);
return should(context !== 2 ? key : key.replace(pseudofmt, '$1'), value, context);
}
/**
* Supports
*
* @param {string} match
* @param {string} group
* @return {string}
*/
function supports(match, group) {
let out = property(group, group.charCodeAt(0), group.charCodeAt(1), group.charCodeAt(2));
return out !== group + ';' ? out.replace(propertyptn, ' or ($1)').substring(4) : '(' + group + ')';
}
/**
* Animation
*
* @param {string} input
* @return {string}
*/
function animation(input) {
var length = input.length;
var index = input.indexOf(':', 9) + 1;
let declare = input.substring(0, index).trim();
let out = input.substring(index, length - 1).trim();
switch (input.charCodeAt(9) * keyed) {
case 0:
{
break;
}
// animation-*, -
case DASH:
{
// animation-name, n
if (input.charCodeAt(10) !== 110) {
break;
}
}
// animation/animation-name
default:
{
// split in case of multiple animations
let list = out.split((out = '', animationptn));
for (var i = 0, index = 0, length = list.length; i < length; index = 0, ++i) {
let value = list[i];
let items = value.split(propertiesptn);
while (value = items[index]) {
let peak = value.charCodeAt(0);
if (keyed === 1 && ( // letters
peak > AT && peak < 90 || peak > 96 && peak < 123 || peak === UNDERSCORE || // dash but not in sequence i.e --
peak === DASH && value.charCodeAt(1) !== DASH)) {
// not a number/function
switch (isNaN(parseFloat(value)) + (value.indexOf('(') !== -1)) {
case 1:
{
switch (value) {
// not a valid reserved keyword
case 'infinite':
case 'alternate':
case 'backwards':
case 'running':
case 'normal':
case 'forwards':
case 'both':
case 'none':
case 'linear':
case 'ease':
case 'ease-in':
case 'ease-out':
case 'ease-in-out':
case 'paused':
case 'reverse':
case 'alternate-reverse':
case 'inherit':
case 'initial':
case 'unset':
case 'step-start':
case 'step-end':
{
break;
}
default:
{
value += key;
}
}
}
}
}
items[index++] = value;
}
out += (i === 0 ? '' : ',') + items.join(' ');
}
}
}
out = declare + out + ';';
if (prefix === 1 || prefix === 2 && vendor(out, 1)) {
return webkit + out + out;
}
return out;
}
/**
* Isolate
*
* @param {Array<string>} current
*/
function isolate(current) {
for (var i = 0, length = current.length, selector = Array(length), padding, element; i < length; ++i) {
// split individual elements in a selector i.e h1 h2 === [h1, h2]
let elements = current[i].split(elementptn);
let out = '';
for (let j = 0, size = 0, tail = 0, code = 0, l = elements.length; j < l; ++j) {
// empty element
if ((size = (element = elements[j]).length) === 0 && l > 1) {
continue;
}
tail = out.charCodeAt(out.length - 1);
code = element.charCodeAt(0);
padding = '';
if (j !== 0) {
// determine if we need padding
switch (tail) {
case STAR:
case TILDE:
case GREATERTHAN:
case PLUS:
case SPACE:
case OPENPARENTHESES:
{
break;
}
default:
{
padding = ' ';
}
}
}
switch (code) {
case AND:
{
element = padding + nscopealt;
}
case TILDE:
case GREATERTHAN:
case PLUS:
case SPACE:
case CLOSEPARENTHESES:
case OPENPARENTHESES:
{
break;
}
case OPENBRACKET:
{
element = padding + element + nscopealt;
break;
}
case COLON:
{
switch (element.charCodeAt(1) * 2 + element.charCodeAt(2) * 3) {
// :global
case 530:
{
if (escape > 0) {
element = padding + element.substring(8, size - 1);
break;
}
}
// :hover, :nth-child(), ...
default:
{
if (j < 1 || elements[j - 1].length < 1) {
element = padding + nscopealt + element;
}
}
}
break;
}
case COMMA:
{
padding = '';
}
default:
{
if (size > 1 && element.indexOf(':') > 0) {
element = padding + element.replace(pseudoptn, '$1' + nscopealt + '$2');
} else {
element = padding + element + nscopealt;
}
}
}
out += element;
}
selector[i] = out.replace(formatptn, '').trim();
}
return selector;
}
/**
* Proxy
*
* @param {number} context
* @param {string} content
* @param {Array<string>} selectors
* @param {Array<string>} parents
* @param {number} line
* @param {number} column
* @param {number} length
* @param {number} id
* @param {number} depth
* @return {(string|void|*)}
*/
function proxy(context, content, selectors, parents, line, column, length, id, depth) {
for (var i = 0, out = content, next; i < plugged; ++i) {
switch (next = plugins[i].call(styleh, context, out, selectors, parents, line, column, length, id, depth)) {
case void 0:
case false:
case true:
case null:
{
break;
}
default:
{
out = next;
}
}
}
switch (out) {
case void 0:
case false:
case true:
case null:
case content:
{
break;
}
default:
{
return out;
}
}
}
/**
* Minify
*
* @param {(string|*)} output
* @return {string}
*/
function minify(output) {
return output.replace(formatptn, '').replace(beforeptn, '').replace(afterptn, '$1').replace(tailptn, '$1').replace(whiteptn, ' ');
}
/**
* Use
*
* @param {(Array<function(...?)>|function(...?)|number|void)?} plugin
*/
function use(plugin) {
switch (plugin) {
case void 0:
case null:
{
plugged = plugins.length = 0;
break;
}
default:
{
switch (plugin.constructor) {
case Array:
{
for (let i = 0, length = plugin.length; i < length; ++i) {
use(plugin[i]);
}
break;
}
case Function:
{
plugins[plugged++] = plugin;
break;
}
case Boolean:
{
unkwn = !!plugin | 0;
}
}
}
}
return use;
}
/**
* Set
*
* @param {*} options
*/
function set(options) {
for (let name in options) {
let value = options[name];
switch (name) {
case 'keyframe':
keyed = value | 0;
break;
case 'global':
escape = value | 0;
break;
case 'cascade':
cascade = value | 0;
break;
case 'compress':
compress = value | 0;
break;
case 'semicolon':
semicolon = value | 0;
break;
case 'preserve':
preserve = value | 0;
break;
case 'prefix':
should = null;
if (!value) {
prefix = 0;
} else if (typeof value !== 'function') {
prefix = 1;
} else {
prefix = 2;
should = value;
}
}
}
return set;
}
/**
* @module styleh
*
* @param {string} selector
* @param {string} input
* @return {*}
*/
function styleh(selector, input) {
if (this !== void 0 && this.constructor === styleh) {
// return factory(selector)
// return (selector)
// return this
// set(selector)
// return styleh
return factory(selector);
} // setup
let ns = selector;
let code = ns.charCodeAt(0); // trim leading whitespace
if (code < 33) {
code = (ns = ns.trim()).charCodeAt(0);
} // keyframe/animation namespace
if (keyed > 0) {
key = ns.replace(invalidptn, code === OPENBRACKET ? '' : '-');
} // reset, used to assert if a plugin is moneky-patching the return value
code = 1; // cascade/isolate
if (cascade === 1) {
nscope = ns;
} else {
nscopealt = ns;
}
let selectors = [nscope];
let result; // execute plugins, pre-process context
if (plugged > 0) {
result = proxy(PREPS, input, selectors, selectors, line, column, 0, 0, 0);
if (result !== void 0 && typeof result === 'string') {
input = result;
}
} // build
let output = compile(array, selectors, input, 0, 0); // execute plugins, post-process context
if (plugged > 0) {
result = proxy(POSTS, output, selectors, selectors, line, column, output.length, 0, 0); // bypass minification
if (result !== void 0 && typeof (output = result) !== 'string') {
code = 0;
}
} // reset
key = '';
nscope = '';
nscopealt = '';
pattern = 0;
line = 1;
column = 1;
return compress * code === 0 ? output : minify(output);
} // const OPTIMIZE = IS_PIPELINE_SERVER
// const OPTIMIZE = true
set({
compress: process.env.STYLEH_SHOULD_COMPRESS,
prefix: process.env.STYLEH_SHOULD_PREFIX
});
styleh.use = use;
styleh.set = set;
return styleh;
}
const styleh = factory();
exports.styleh = styleh;
const set = styleh.set,
use = styleh.use;
/**
* @todo - check for IE
* @todo - check for staging
*/
// const OPTIMIZE = process.env.NODE_ENV === 'production'
// const OPTIMIZE = IS_PIPELINE_SERVER
// const OPTIMIZE = true
exports.use = use;
exports.set = set;
set({
compress: process.env.STYLEH_SHOULD_COMPRESS,
prefix: process.env.STYLEH_SHOULD_PREFIX
});
var _default = styleh;
exports.default = _default;