@porsche-design-system/components-react
Version:
Porsche Design System is a component library designed to help developers create the best experience for software or services distributed by Dr. Ing. h.c. F. Porsche AG.
1,893 lines (1,515 loc) • 506 kB
JavaScript
'use strict';
const borderRadiusSmall = '4px';
const borderRadiusMedium = '8px';
const borderRadiusLarge = '12px';
const borderWidthBase = '2px';
const _dropShadowBackgroundColor = 'rgba(0, 0, 0, 0.16)';
const dropShadowLowStyle = {
boxShadow: `0px 3px 8px ${_dropShadowBackgroundColor}`, // filter: drop-shadow() causes visual glitches in Firefox in combination with frostedGlassStyle
};
const dropShadowHighStyle = {
boxShadow: `0px 8px 40px ${_dropShadowBackgroundColor}`, // filter: drop-shadow() causes visual glitches in Firefox in combination with frostedGlassStyle
};
const fontFamily = "'Porsche Next','Arial Narrow',Arial,'Heiti SC',SimHei,sans-serif";
const fontHyphenationStyle = {
overflowWrap: 'break-word',
// @ts-ignore
hyphens: 'var(--p-hyphens, auto)',
};
const fontLineHeight = 'calc(6px + 2.125ex)';
const fontSizeTextXXSmall = '.75rem';
const fontSizeTextXSmall = 'clamp(0.81rem, 0.23vw + 0.77rem, 0.88rem)';
const fontSizeTextSmall = '1rem';
const fontSizeTextMedium = 'clamp(1.13rem, 0.21vw + 1.08rem, 1.33rem)';
const fontSizeTextLarge = 'clamp(1.27rem, 0.51vw + 1.16rem, 1.78rem)';
const fontSizeTextXLarge = 'clamp(1.42rem, 0.94vw + 1.23rem, 2.37rem)';
const fontSizeText = {
xxSmall: fontSizeTextXXSmall,
xSmall: fontSizeTextXSmall,
small: fontSizeTextSmall,
medium: fontSizeTextMedium,
large: fontSizeTextLarge,
xLarge: fontSizeTextXLarge,
};
const fontSizeHeadingSmall = fontSizeTextSmall;
const fontSizeHeadingMedium = fontSizeTextMedium;
const fontSizeHeadingLarge = fontSizeTextLarge;
const fontSizeHeadingXLarge = fontSizeTextXLarge;
const fontSizeHeadingXXLarge = 'clamp(1.6rem, 1.56vw + 1.29rem, 3.16rem)';
const fontSizeDisplaySmall = 'clamp(1.8rem, 2.41vw + 1.32rem, 4.21rem)';
const fontSizeDisplayMedium = 'clamp(2.03rem, 3.58vw + 1.31rem, 5.61rem)';
const fontSizeDisplayLarge = 'clamp(2.28rem, 5.2vw + 1.24rem, 7.48rem)';
const fontWeightRegular = 400;
const fontWeightSemiBold = 600;
const fontWeightBold = 700;
const fontStyleNormal = 'normal';
const fontVariant = 'normal';
const backdropFilter = 'blur(32px)';
const frostedGlassStyle = {
WebkitBackdropFilter: backdropFilter,
backdropFilter,
};
const _gradient = 'hsla(0, 0%, 0%, 0.80) 0%,' +
'hsla(0, 0%, 0%, 0.80) 8.1%,' +
'hsla(0, 0%, 0%, 0.80) 15.5%,' +
'hsla(0, 0%, 0%, 0.80) 22.5%,' +
'hsla(0, 0%, 0%, 0.78) 29%,' +
'hsla(0, 0%, 0%, 0.73) 35.3%,' +
'hsla(0, 0%, 0%, 0.67) 41.2%,' +
'hsla(0, 0%, 0%, 0.60) 47.1%,' +
'hsla(0, 0%, 0%, 0.52) 52.9%,' +
'hsla(0, 0%, 0%, 0.44) 58.8%,' +
'hsla(0, 0%, 0%, 0.33) 64.7%,' +
'hsla(0, 0%, 0%, 0.22) 71%,' +
'hsla(0, 0%, 0%, 0.12) 77.5%,' +
'hsla(0, 0%, 0%, 0.05) 84.5%,' +
'hsla(0, 0%, 0%, 0.011) 91.9%,' +
'hsla(0, 0%, 0%, 0)';
const gradientToBottomStyle = {
background: `linear-gradient(to bottom, ${_gradient} 100%);`,
};
const gradientToTopStyle = {
background: `linear-gradient(to top, ${_gradient} 100%);`,
};
const breakpointBase = 0;
const breakpointXS = 480;
const breakpointS = 760;
const breakpointM = 1000;
const breakpointL = 1300;
const breakpointXL = 1760;
const breakpointXXL = 1920;
const breakpoint = {
base: breakpointBase,
xs: breakpointXS,
s: breakpointS,
m: breakpointM,
l: breakpointL,
xl: breakpointXL,
xxl: breakpointXXL,
};
function getMediaQueryMin(min) {
return `@media(min-width:${breakpoint[min]}px)`;
}
const spacingFluidMedium = 'clamp(16px, 1.25vw + 12px, 36px)';
const gridGap = spacingFluidMedium;
const _gridWidthMax = '2560px';
// fluid sizing calculated by https://fluidtypography.com/#app-get-started
const _gridSafeZoneBase = 'max(22px, 10.625vw - 12px)'; // viewport-width range = 320 - 760px / size range = 22 - 68.75px
const _gridSafeZoneS = 'calc(5vw - 16px)'; // viewport-width range = 760 - 1920px / size range = 22(22.75) - 80(79.71)px
const _gridSafeZoneXXL = 'min(50vw - 880px, 400px)'; // viewport-width range = 1920 - 2560px / size range = 80(79.71)px - 400(399.71)px
const columnMap = {
narrow: 4,
basic: 2,
extended: 1,
};
const gridColumnWidthS = `calc((100vw - ${_gridSafeZoneS} * 2 - ${gridGap} * 15) / 16)`;
const gridColumnWidthXXL = `calc((min(100vw, ${_gridWidthMax}) - ${_gridSafeZoneXXL} * 2 - ${gridGap} * 15) / 16)`;
const _gridPadding = `max(0px, 50vw - ${_gridWidthMax} / 2)`;
const _getGridOffsetS = (width) => `calc(${_gridSafeZoneS} + (${gridGap} + ${gridColumnWidthS}) * ${columnMap[width]})`;
const _getGridOffsetXXL = (width) => `calc(${_gridPadding} + ${_gridSafeZoneXXL} + (${gridGap} + ${gridColumnWidthXXL}) * ${columnMap[width]})`;
const gridFullOffset = _gridPadding;
const gridWideOffsetBase = _gridSafeZoneBase;
const gridWideOffsetS = _gridSafeZoneS;
const gridWideOffsetXXL = `calc(${_gridPadding} + ${_gridSafeZoneXXL})`;
const gridWideOffset = {
base: gridWideOffsetBase,
s: gridWideOffsetS,
xxl: gridWideOffsetXXL,
};
const gridExtendedOffsetBase = _gridSafeZoneBase;
const gridExtendedOffsetS = _getGridOffsetS('extended');
const gridExtendedOffsetXXL = _getGridOffsetXXL('extended');
const gridExtendedOffset = {
base: gridExtendedOffsetBase,
s: gridExtendedOffsetS,
xxl: gridExtendedOffsetXXL,
};
const gridBasicOffsetBase = _gridSafeZoneBase;
const gridBasicOffsetS = _getGridOffsetS('basic');
const gridBasicOffsetXXL = _getGridOffsetXXL('basic');
const gridBasicOffset = {
base: gridBasicOffsetBase,
s: gridBasicOffsetS,
xxl: gridBasicOffsetXXL,
};
const gridNarrowOffsetBase = _gridSafeZoneBase;
const gridNarrowOffsetS = _getGridOffsetS('narrow');
const gridNarrowOffsetXXL = _getGridOffsetXXL('narrow');
const gridNarrowOffset = {
base: gridNarrowOffsetBase,
s: gridNarrowOffsetS,
xxl: gridNarrowOffsetXXL,
};
const motionDurationShort = '0.25s';
const motionEasingBase = 'cubic-bezier(0.25,0.1,0.25,1)';
const breakpoints = ['base', 'xs', 's', 'm', 'l', 'xl', 'xxl'];
function getMediaQueryMax(max) {
return `@media(max-width:${breakpoint[max] - 1}px)`;
}
const motionDurationLong = '0.6s';
const motionDurationModerate = '0.4s';
const motionDurationVeryLong = '1.2s';
const motionEasingIn = 'cubic-bezier(0,0,0.2,1)';
const motionEasingOut = 'cubic-bezier(0.4,0,0.5,1)';
const spacingStaticXSmall = '4px';
const spacingStaticSmall = '8px';
const spacingStaticMedium = '16px';
const spacingStaticLarge = '32px';
const spacingFluidXSmall = 'clamp(4px, 0.25vw + 3px, 8px)';
const spacingFluidSmall = 'clamp(8px, 0.5vw + 6px, 16px)';
const spacingFluidLarge = 'clamp(32px, 2.75vw + 23px, 76px)';
const _displayFontPartA = `${fontStyleNormal} ${fontVariant} ${fontWeightRegular} `;
const _displayFontPartB = `/${fontLineHeight} ${fontFamily}`;
const displayMediumStyle = {
font: `${_displayFontPartA}${fontSizeDisplayMedium}${_displayFontPartB}`,
};
const displayLargeStyle = {
font: `${_displayFontPartA}${fontSizeDisplayLarge}${_displayFontPartB}`,
};
const _headingFontPartA = `${fontStyleNormal} ${fontVariant} ${fontWeightSemiBold} `;
const _headingFontPartB = `/${fontLineHeight} ${fontFamily}`;
const headingSmallStyle = {
font: `${_headingFontPartA}${fontSizeHeadingSmall}${_headingFontPartB}`,
};
const headingMediumStyle = {
font: `${_headingFontPartA}${fontSizeHeadingMedium}${_headingFontPartB}`,
};
const headingLargeStyle = {
font: `${_headingFontPartA}${fontSizeHeadingLarge}${_headingFontPartB}`,
};
const headingXLargeStyle = {
font: `${_headingFontPartA}${fontSizeHeadingXLarge}${_headingFontPartB}`,
};
const headingXXLargeStyle = {
font: `${_headingFontPartA}${fontSizeHeadingXXLarge}${_headingFontPartB}`,
};
const _textFontPartA = `${fontStyleNormal} ${fontVariant} ${fontWeightRegular} `;
const _textFontPartB = `/${fontLineHeight} ${fontFamily}`;
const textXXSmallStyle = {
font: `${_textFontPartA}${fontSizeTextXXSmall}${_textFontPartB}`,
...fontHyphenationStyle,
};
const textXSmallStyle = {
font: `${_textFontPartA}${fontSizeTextXSmall}${_textFontPartB}`,
...fontHyphenationStyle,
};
const textSmallStyle = {
font: `${_textFontPartA}${fontSizeTextSmall}${_textFontPartB}`,
...fontHyphenationStyle,
};
const textMediumStyle = {
font: `${_textFontPartA}${fontSizeTextMedium}${_textFontPartB}`,
...fontHyphenationStyle,
};
const textLargeStyle = {
font: `${_textFontPartA}${fontSizeTextLarge}${_textFontPartB}`,
...fontHyphenationStyle,
};
function _extends() {
_extends = Object.assign ? Object.assign.bind() : function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
var _typeof$1 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var isBrowser = (typeof window === "undefined" ? "undefined" : _typeof$1(window)) === "object" && (typeof document === "undefined" ? "undefined" : _typeof$1(document)) === 'object' && document.nodeType === 9;
function _typeof(o) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, _typeof(o);
}
function toPrimitive(t, r) {
if ("object" != _typeof(t) || !t) return t;
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r);
if ("object" != _typeof(i)) return i;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (String )(t);
}
function toPropertyKey(t) {
var i = toPrimitive(t, "string");
return "symbol" == _typeof(i) ? i : i + "";
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
_setPrototypeOf(subClass, superClass);
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
}
var plainObjectConstrurctor = {}.constructor;
function cloneStyle(style) {
if (style == null || typeof style !== 'object') return style;
if (Array.isArray(style)) return style.map(cloneStyle);
if (style.constructor !== plainObjectConstrurctor) return style;
var newStyle = {};
for (var name in style) {
newStyle[name] = cloneStyle(style[name]);
}
return newStyle;
}
/**
* Create a rule instance.
*/
function createRule(name, decl, options) {
if (name === void 0) {
name = 'unnamed';
}
var jss = options.jss;
var declCopy = cloneStyle(decl);
var rule = jss.plugins.onCreateRule(name, declCopy, options);
if (rule) return rule; // It is an at-rule and it has no instance.
if (name[0] === '@') ;
return null;
}
var join = function join(value, by) {
var result = '';
for (var i = 0; i < value.length; i++) {
// Remove !important from the value, it will be readded later.
if (value[i] === '!important') break;
if (result) result += by;
result += value[i];
}
return result;
};
/**
* Converts JSS array value to a CSS string.
*
* `margin: [['5px', '10px']]` > `margin: 5px 10px;`
* `border: ['1px', '2px']` > `border: 1px, 2px;`
* `margin: [['5px', '10px'], '!important']` > `margin: 5px 10px !important;`
* `color: ['red', !important]` > `color: red !important;`
*/
var toCssValue = function toCssValue(value) {
if (!Array.isArray(value)) return value;
var cssValue = ''; // Support space separated values via `[['5px', '10px']]`.
if (Array.isArray(value[0])) {
for (var i = 0; i < value.length; i++) {
if (value[i] === '!important') break;
if (cssValue) cssValue += ', ';
cssValue += join(value[i], ' ');
}
} else cssValue = join(value, ', '); // Add !important, because it was ignored.
if (value[value.length - 1] === '!important') {
cssValue += ' !important';
}
return cssValue;
};
function getWhitespaceSymbols(options) {
if (options && options.format === false) {
return {
linebreak: '',
space: ''
};
}
return {
linebreak: '\n',
space: ' '
};
}
/**
* Indent a string.
* http://jsperf.com/array-join-vs-for
*/
function indentStr(str, indent) {
var result = '';
for (var index = 0; index < indent; index++) {
result += ' ';
}
return result + str;
}
/**
* Converts a Rule to CSS string.
*/
function toCss(selector, style, options) {
if (options === void 0) {
options = {};
}
var result = '';
if (!style) return result;
var _options = options,
_options$indent = _options.indent,
indent = _options$indent === void 0 ? 0 : _options$indent;
var fallbacks = style.fallbacks;
if (options.format === false) {
indent = -Infinity;
}
var _getWhitespaceSymbols = getWhitespaceSymbols(options),
linebreak = _getWhitespaceSymbols.linebreak,
space = _getWhitespaceSymbols.space;
if (selector) indent++; // Apply fallbacks first.
if (fallbacks) {
// Array syntax {fallbacks: [{prop: value}]}
if (Array.isArray(fallbacks)) {
for (var index = 0; index < fallbacks.length; index++) {
var fallback = fallbacks[index];
for (var prop in fallback) {
var value = fallback[prop];
if (value != null) {
if (result) result += linebreak;
result += indentStr(prop + ":" + space + toCssValue(value) + ";", indent);
}
}
}
} else {
// Object syntax {fallbacks: {prop: value}}
for (var _prop in fallbacks) {
var _value = fallbacks[_prop];
if (_value != null) {
if (result) result += linebreak;
result += indentStr(_prop + ":" + space + toCssValue(_value) + ";", indent);
}
}
}
}
for (var _prop2 in style) {
var _value2 = style[_prop2];
if (_value2 != null && _prop2 !== 'fallbacks') {
if (result) result += linebreak;
result += indentStr(_prop2 + ":" + space + toCssValue(_value2) + ";", indent);
}
} // Allow empty style in this case, because properties will be added dynamically.
if (!result && !options.allowEmpty) return result; // When rule is being stringified before selector was defined.
if (!selector) return result;
indent--;
if (result) result = "" + linebreak + result + linebreak;
return indentStr("" + selector + space + "{" + result, indent) + indentStr('}', indent);
}
var escapeRegex = /([[\].#*$><+~=|^:(),"'`\s])/g;
var nativeEscape = typeof CSS !== 'undefined' && CSS.escape;
var escape = (function (str) {
return nativeEscape ? nativeEscape(str) : str.replace(escapeRegex, '\\$1');
});
var BaseStyleRule =
/*#__PURE__*/
function () {
function BaseStyleRule(key, style, options) {
this.type = 'style';
this.isProcessed = false;
var sheet = options.sheet,
Renderer = options.Renderer;
this.key = key;
this.options = options;
this.style = style;
if (sheet) this.renderer = sheet.renderer;else if (Renderer) this.renderer = new Renderer();
}
/**
* Get or set a style property.
*/
var _proto = BaseStyleRule.prototype;
_proto.prop = function prop(name, value, options) {
// It's a getter.
if (value === undefined) return this.style[name]; // Don't do anything if the value has not changed.
var force = options ? options.force : false;
if (!force && this.style[name] === value) return this;
var newValue = value;
if (!options || options.process !== false) {
newValue = this.options.jss.plugins.onChangeValue(value, name, this);
}
var isEmpty = newValue == null || newValue === false;
var isDefined = name in this.style; // Value is empty and wasn't defined before.
if (isEmpty && !isDefined && !force) return this; // We are going to remove this value.
var remove = isEmpty && isDefined;
if (remove) delete this.style[name];else this.style[name] = newValue; // Renderable is defined if StyleSheet option `link` is true.
if (this.renderable && this.renderer) {
if (remove) this.renderer.removeProperty(this.renderable, name);else this.renderer.setProperty(this.renderable, name, newValue);
return this;
}
var sheet = this.options.sheet;
if (sheet && sheet.attached) ;
return this;
};
return BaseStyleRule;
}();
var StyleRule =
/*#__PURE__*/
function (_BaseStyleRule) {
_inheritsLoose(StyleRule, _BaseStyleRule);
function StyleRule(key, style, options) {
var _this;
_this = _BaseStyleRule.call(this, key, style, options) || this;
var selector = options.selector,
scoped = options.scoped,
sheet = options.sheet,
generateId = options.generateId;
if (selector) {
_this.selectorText = selector;
} else if (scoped !== false) {
_this.id = generateId(_assertThisInitialized(_assertThisInitialized(_this)), sheet);
_this.selectorText = "." + escape(_this.id);
}
return _this;
}
/**
* Set selector string.
* Attention: use this with caution. Most browsers didn't implement
* selectorText setter, so this may result in rerendering of entire Style Sheet.
*/
var _proto2 = StyleRule.prototype;
/**
* Apply rule to an element inline.
*/
_proto2.applyTo = function applyTo(renderable) {
var renderer = this.renderer;
if (renderer) {
var json = this.toJSON();
for (var prop in json) {
renderer.setProperty(renderable, prop, json[prop]);
}
}
return this;
}
/**
* Returns JSON representation of the rule.
* Fallbacks are not supported.
* Useful for inline styles.
*/
;
_proto2.toJSON = function toJSON() {
var json = {};
for (var prop in this.style) {
var value = this.style[prop];
if (typeof value !== 'object') json[prop] = value;else if (Array.isArray(value)) json[prop] = toCssValue(value);
}
return json;
}
/**
* Generates a CSS string.
*/
;
_proto2.toString = function toString(options) {
var sheet = this.options.sheet;
var link = sheet ? sheet.options.link : false;
var opts = link ? _extends({}, options, {
allowEmpty: true
}) : options;
return toCss(this.selectorText, this.style, opts);
};
_createClass(StyleRule, [{
key: "selector",
set: function set(selector) {
if (selector === this.selectorText) return;
this.selectorText = selector;
var renderer = this.renderer,
renderable = this.renderable;
if (!renderable || !renderer) return;
var hasChanged = renderer.setSelector(renderable, selector); // If selector setter is not implemented, rerender the rule.
if (!hasChanged) {
renderer.replaceRule(renderable, this);
}
}
/**
* Get selector string.
*/
,
get: function get() {
return this.selectorText;
}
}]);
return StyleRule;
}(BaseStyleRule);
var pluginStyleRule = {
onCreateRule: function onCreateRule(key, style, options) {
if (key[0] === '@' || options.parent && options.parent.type === 'keyframes') {
return null;
}
return new StyleRule(key, style, options);
}
};
var defaultToStringOptions = {
indent: 1,
children: true
};
var atRegExp = /@([\w-]+)/;
/**
* Conditional rule for @media, @supports
*/
var ConditionalRule =
/*#__PURE__*/
function () {
function ConditionalRule(key, styles, options) {
this.type = 'conditional';
this.isProcessed = false;
this.key = key;
var atMatch = key.match(atRegExp);
this.at = atMatch ? atMatch[1] : 'unknown'; // Key might contain a unique suffix in case the `name` passed by user was duplicate.
this.query = options.name || "@" + this.at;
this.options = options;
this.rules = new RuleList(_extends({}, options, {
parent: this
}));
for (var name in styles) {
this.rules.add(name, styles[name]);
}
this.rules.process();
}
/**
* Get a rule.
*/
var _proto = ConditionalRule.prototype;
_proto.getRule = function getRule(name) {
return this.rules.get(name);
}
/**
* Get index of a rule.
*/
;
_proto.indexOf = function indexOf(rule) {
return this.rules.indexOf(rule);
}
/**
* Create and register rule, run plugins.
*/
;
_proto.addRule = function addRule(name, style, options) {
var rule = this.rules.add(name, style, options);
if (!rule) return null;
this.options.jss.plugins.onProcessRule(rule);
return rule;
}
/**
* Replace rule, run plugins.
*/
;
_proto.replaceRule = function replaceRule(name, style, options) {
var newRule = this.rules.replace(name, style, options);
if (newRule) this.options.jss.plugins.onProcessRule(newRule);
return newRule;
}
/**
* Generates a CSS string.
*/
;
_proto.toString = function toString(options) {
if (options === void 0) {
options = defaultToStringOptions;
}
var _getWhitespaceSymbols = getWhitespaceSymbols(options),
linebreak = _getWhitespaceSymbols.linebreak;
if (options.indent == null) options.indent = defaultToStringOptions.indent;
if (options.children == null) options.children = defaultToStringOptions.children;
if (options.children === false) {
return this.query + " {}";
}
var children = this.rules.toString(options);
return children ? this.query + " {" + linebreak + children + linebreak + "}" : '';
};
return ConditionalRule;
}();
var keyRegExp = /@container|@media|@supports\s+/;
var pluginConditionalRule = {
onCreateRule: function onCreateRule(key, styles, options) {
return keyRegExp.test(key) ? new ConditionalRule(key, styles, options) : null;
}
};
var defaultToStringOptions$1 = {
indent: 1,
children: true
};
var nameRegExp = /@keyframes\s+([\w-]+)/;
/**
* Rule for @keyframes
*/
var KeyframesRule =
/*#__PURE__*/
function () {
function KeyframesRule(key, frames, options) {
this.type = 'keyframes';
this.at = '@keyframes';
this.isProcessed = false;
var nameMatch = key.match(nameRegExp);
if (nameMatch && nameMatch[1]) {
this.name = nameMatch[1];
} else {
this.name = 'noname';
}
this.key = this.type + "-" + this.name;
this.options = options;
var scoped = options.scoped,
sheet = options.sheet,
generateId = options.generateId;
this.id = scoped === false ? this.name : escape(generateId(this, sheet));
this.rules = new RuleList(_extends({}, options, {
parent: this
}));
for (var name in frames) {
this.rules.add(name, frames[name], _extends({}, options, {
parent: this
}));
}
this.rules.process();
}
/**
* Generates a CSS string.
*/
var _proto = KeyframesRule.prototype;
_proto.toString = function toString(options) {
if (options === void 0) {
options = defaultToStringOptions$1;
}
var _getWhitespaceSymbols = getWhitespaceSymbols(options),
linebreak = _getWhitespaceSymbols.linebreak;
if (options.indent == null) options.indent = defaultToStringOptions$1.indent;
if (options.children == null) options.children = defaultToStringOptions$1.children;
if (options.children === false) {
return this.at + " " + this.id + " {}";
}
var children = this.rules.toString(options);
if (children) children = "" + linebreak + children + linebreak;
return this.at + " " + this.id + " {" + children + "}";
};
return KeyframesRule;
}();
var keyRegExp$1 = /@keyframes\s+/;
var refRegExp$1 = /\$([\w-]+)/g;
var findReferencedKeyframe = function findReferencedKeyframe(val, keyframes) {
if (typeof val === 'string') {
return val.replace(refRegExp$1, function (match, name) {
if (name in keyframes) {
return keyframes[name];
}
return match;
});
}
return val;
};
/**
* Replace the reference for a animation name.
*/
var replaceRef = function replaceRef(style, prop, keyframes) {
var value = style[prop];
var refKeyframe = findReferencedKeyframe(value, keyframes);
if (refKeyframe !== value) {
style[prop] = refKeyframe;
}
};
var pluginKeyframesRule = {
onCreateRule: function onCreateRule(key, frames, options) {
return typeof key === 'string' && keyRegExp$1.test(key) ? new KeyframesRule(key, frames, options) : null;
},
// Animation name ref replacer.
onProcessStyle: function onProcessStyle(style, rule, sheet) {
if (rule.type !== 'style' || !sheet) return style;
if ('animation-name' in style) replaceRef(style, 'animation-name', sheet.keyframes);
if ('animation' in style) replaceRef(style, 'animation', sheet.keyframes);
return style;
},
onChangeValue: function onChangeValue(val, prop, rule) {
var sheet = rule.options.sheet;
if (!sheet) {
return val;
}
switch (prop) {
case 'animation':
return findReferencedKeyframe(val, sheet.keyframes);
case 'animation-name':
return findReferencedKeyframe(val, sheet.keyframes);
default:
return val;
}
}
};
var KeyframeRule =
/*#__PURE__*/
function (_BaseStyleRule) {
_inheritsLoose(KeyframeRule, _BaseStyleRule);
function KeyframeRule() {
return _BaseStyleRule.apply(this, arguments) || this;
}
var _proto = KeyframeRule.prototype;
/**
* Generates a CSS string.
*/
_proto.toString = function toString(options) {
var sheet = this.options.sheet;
var link = sheet ? sheet.options.link : false;
var opts = link ? _extends({}, options, {
allowEmpty: true
}) : options;
return toCss(this.key, this.style, opts);
};
return KeyframeRule;
}(BaseStyleRule);
var pluginKeyframeRule = {
onCreateRule: function onCreateRule(key, style, options) {
if (options.parent && options.parent.type === 'keyframes') {
return new KeyframeRule(key, style, options);
}
return null;
}
};
var FontFaceRule =
/*#__PURE__*/
function () {
function FontFaceRule(key, style, options) {
this.type = 'font-face';
this.at = '@font-face';
this.isProcessed = false;
this.key = key;
this.style = style;
this.options = options;
}
/**
* Generates a CSS string.
*/
var _proto = FontFaceRule.prototype;
_proto.toString = function toString(options) {
var _getWhitespaceSymbols = getWhitespaceSymbols(options),
linebreak = _getWhitespaceSymbols.linebreak;
if (Array.isArray(this.style)) {
var str = '';
for (var index = 0; index < this.style.length; index++) {
str += toCss(this.at, this.style[index]);
if (this.style[index + 1]) str += linebreak;
}
return str;
}
return toCss(this.at, this.style, options);
};
return FontFaceRule;
}();
var keyRegExp$2 = /@font-face/;
var pluginFontFaceRule = {
onCreateRule: function onCreateRule(key, style, options) {
return keyRegExp$2.test(key) ? new FontFaceRule(key, style, options) : null;
}
};
var ViewportRule =
/*#__PURE__*/
function () {
function ViewportRule(key, style, options) {
this.type = 'viewport';
this.at = '@viewport';
this.isProcessed = false;
this.key = key;
this.style = style;
this.options = options;
}
/**
* Generates a CSS string.
*/
var _proto = ViewportRule.prototype;
_proto.toString = function toString(options) {
return toCss(this.key, this.style, options);
};
return ViewportRule;
}();
var pluginViewportRule = {
onCreateRule: function onCreateRule(key, style, options) {
return key === '@viewport' || key === '@-ms-viewport' ? new ViewportRule(key, style, options) : null;
}
};
var SimpleRule =
/*#__PURE__*/
function () {
function SimpleRule(key, value, options) {
this.type = 'simple';
this.isProcessed = false;
this.key = key;
this.value = value;
this.options = options;
}
/**
* Generates a CSS string.
*/
// eslint-disable-next-line no-unused-vars
var _proto = SimpleRule.prototype;
_proto.toString = function toString(options) {
if (Array.isArray(this.value)) {
var str = '';
for (var index = 0; index < this.value.length; index++) {
str += this.key + " " + this.value[index] + ";";
if (this.value[index + 1]) str += '\n';
}
return str;
}
return this.key + " " + this.value + ";";
};
return SimpleRule;
}();
var keysMap = {
'@charset': true,
'@import': true,
'@namespace': true
};
var pluginSimpleRule = {
onCreateRule: function onCreateRule(key, value, options) {
return key in keysMap ? new SimpleRule(key, value, options) : null;
}
};
var plugins = [pluginStyleRule, pluginConditionalRule, pluginKeyframesRule, pluginKeyframeRule, pluginFontFaceRule, pluginViewportRule, pluginSimpleRule];
var defaultUpdateOptions = {
process: true
};
var forceUpdateOptions = {
force: true,
process: true
/**
* Contains rules objects and allows adding/removing etc.
* Is used for e.g. by `StyleSheet` or `ConditionalRule`.
*/
};
var RuleList =
/*#__PURE__*/
function () {
// Rules registry for access by .get() method.
// It contains the same rule registered by name and by selector.
// Original styles object.
// Used to ensure correct rules order.
function RuleList(options) {
this.map = {};
this.raw = {};
this.index = [];
this.counter = 0;
this.options = options;
this.classes = options.classes;
this.keyframes = options.keyframes;
}
/**
* Create and register rule.
*
* Will not render after Style Sheet was rendered the first time.
*/
var _proto = RuleList.prototype;
_proto.add = function add(name, decl, ruleOptions) {
var _this$options = this.options,
parent = _this$options.parent,
sheet = _this$options.sheet,
jss = _this$options.jss,
Renderer = _this$options.Renderer,
generateId = _this$options.generateId,
scoped = _this$options.scoped;
var options = _extends({
classes: this.classes,
parent: parent,
sheet: sheet,
jss: jss,
Renderer: Renderer,
generateId: generateId,
scoped: scoped,
name: name,
keyframes: this.keyframes,
selector: undefined
}, ruleOptions); // When user uses .createStyleSheet(), duplicate names are not possible, but
// `sheet.addRule()` opens the door for any duplicate rule name. When this happens
// we need to make the key unique within this RuleList instance scope.
var key = name;
if (name in this.raw) {
key = name + "-d" + this.counter++;
} // We need to save the original decl before creating the rule
// because cache plugin needs to use it as a key to return a cached rule.
this.raw[key] = decl;
if (key in this.classes) {
// E.g. rules inside of @media container
options.selector = "." + escape(this.classes[key]);
}
var rule = createRule(key, decl, options);
if (!rule) return null;
this.register(rule);
var index = options.index === undefined ? this.index.length : options.index;
this.index.splice(index, 0, rule);
return rule;
}
/**
* Replace rule.
* Create a new rule and remove old one instead of overwriting
* because we want to invoke onCreateRule hook to make plugins work.
*/
;
_proto.replace = function replace(name, decl, ruleOptions) {
var oldRule = this.get(name);
var oldIndex = this.index.indexOf(oldRule);
if (oldRule) {
this.remove(oldRule);
}
var options = ruleOptions;
if (oldIndex !== -1) options = _extends({}, ruleOptions, {
index: oldIndex
});
return this.add(name, decl, options);
}
/**
* Get a rule by name or selector.
*/
;
_proto.get = function get(nameOrSelector) {
return this.map[nameOrSelector];
}
/**
* Delete a rule.
*/
;
_proto.remove = function remove(rule) {
this.unregister(rule);
delete this.raw[rule.key];
this.index.splice(this.index.indexOf(rule), 1);
}
/**
* Get index of a rule.
*/
;
_proto.indexOf = function indexOf(rule) {
return this.index.indexOf(rule);
}
/**
* Run `onProcessRule()` plugins on every rule.
*/
;
_proto.process = function process() {
var plugins = this.options.jss.plugins; // We need to clone array because if we modify the index somewhere else during a loop
// we end up with very hard-to-track-down side effects.
this.index.slice(0).forEach(plugins.onProcessRule, plugins);
}
/**
* Register a rule in `.map`, `.classes` and `.keyframes` maps.
*/
;
_proto.register = function register(rule) {
this.map[rule.key] = rule;
if (rule instanceof StyleRule) {
this.map[rule.selector] = rule;
if (rule.id) this.classes[rule.key] = rule.id;
} else if (rule instanceof KeyframesRule && this.keyframes) {
this.keyframes[rule.name] = rule.id;
}
}
/**
* Unregister a rule.
*/
;
_proto.unregister = function unregister(rule) {
delete this.map[rule.key];
if (rule instanceof StyleRule) {
delete this.map[rule.selector];
delete this.classes[rule.key];
} else if (rule instanceof KeyframesRule) {
delete this.keyframes[rule.name];
}
}
/**
* Update the function values with a new data.
*/
;
_proto.update = function update() {
var name;
var data;
var options;
if (typeof (arguments.length <= 0 ? undefined : arguments[0]) === 'string') {
name = arguments.length <= 0 ? undefined : arguments[0];
data = arguments.length <= 1 ? undefined : arguments[1];
options = arguments.length <= 2 ? undefined : arguments[2];
} else {
data = arguments.length <= 0 ? undefined : arguments[0];
options = arguments.length <= 1 ? undefined : arguments[1];
name = null;
}
if (name) {
this.updateOne(this.get(name), data, options);
} else {
for (var index = 0; index < this.index.length; index++) {
this.updateOne(this.index[index], data, options);
}
}
}
/**
* Execute plugins, update rule props.
*/
;
_proto.updateOne = function updateOne(rule, data, options) {
if (options === void 0) {
options = defaultUpdateOptions;
}
var _this$options2 = this.options,
plugins = _this$options2.jss.plugins,
sheet = _this$options2.sheet; // It is a rules container like for e.g. ConditionalRule.
if (rule.rules instanceof RuleList) {
rule.rules.update(data, options);
return;
}
var style = rule.style;
plugins.onUpdate(data, rule, sheet, options); // We rely on a new `style` ref in case it was mutated during onUpdate hook.
if (options.process && style && style !== rule.style) {
// We need to run the plugins in case new `style` relies on syntax plugins.
plugins.onProcessStyle(rule.style, rule, sheet); // Update and add props.
for (var prop in rule.style) {
var nextValue = rule.style[prop];
var prevValue = style[prop]; // We need to use `force: true` because `rule.style` has been updated during onUpdate hook, so `rule.prop()` will not update the CSSOM rule.
// We do this comparison to avoid unneeded `rule.prop()` calls, since we have the old `style` object here.
if (nextValue !== prevValue) {
rule.prop(prop, nextValue, forceUpdateOptions);
}
} // Remove props.
for (var _prop in style) {
var _nextValue = rule.style[_prop];
var _prevValue = style[_prop]; // We need to use `force: true` because `rule.style` has been updated during onUpdate hook, so `rule.prop()` will not update the CSSOM rule.
// We do this comparison to avoid unneeded `rule.prop()` calls, since we have the old `style` object here.
if (_nextValue == null && _nextValue !== _prevValue) {
rule.prop(_prop, null, forceUpdateOptions);
}
}
}
}
/**
* Convert rules to a CSS string.
*/
;
_proto.toString = function toString(options) {
var str = '';
var sheet = this.options.sheet;
var link = sheet ? sheet.options.link : false;
var _getWhitespaceSymbols = getWhitespaceSymbols(options),
linebreak = _getWhitespaceSymbols.linebreak;
for (var index = 0; index < this.index.length; index++) {
var rule = this.index[index];
var css = rule.toString(options); // No need to render an empty rule.
if (!css && !link) continue;
if (str) str += linebreak;
str += css;
}
return str;
};
return RuleList;
}();
var StyleSheet =
/*#__PURE__*/
function () {
function StyleSheet(styles, options) {
this.attached = false;
this.deployed = false;
this.classes = {};
this.keyframes = {};
this.options = _extends({}, options, {
sheet: this,
parent: this,
classes: this.classes,
keyframes: this.keyframes
});
if (options.Renderer) {
this.renderer = new options.Renderer(this);
}
this.rules = new RuleList(this.options);
for (var name in styles) {
this.rules.add(name, styles[name]);
}
this.rules.process();
}
/**
* Attach renderable to the render tree.
*/
var _proto = StyleSheet.prototype;
_proto.attach = function attach() {
if (this.attached) return this;
if (this.renderer) this.renderer.attach();
this.attached = true; // Order is important, because we can't use insertRule API if style element is not attached.
if (!this.deployed) this.deploy();
return this;
}
/**
* Remove renderable from render tree.
*/
;
_proto.detach = function detach() {
if (!this.attached) return this;
if (this.renderer) this.renderer.detach();
this.attached = false;
return this;
}
/**
* Add a rule to the current stylesheet.
* Will insert a rule also after the stylesheet has been rendered first time.
*/
;
_proto.addRule = function addRule(name, decl, options) {
var queue = this.queue; // Plugins can create rules.
// In order to preserve the right order, we need to queue all `.addRule` calls,
// which happen after the first `rules.add()` call.
if (this.attached && !queue) this.queue = [];
var rule = this.rules.add(name, decl, options);
if (!rule) return null;
this.options.jss.plugins.onProcessRule(rule);
if (this.attached) {
if (!this.deployed) return rule; // Don't insert rule directly if there is no stringified version yet.
// It will be inserted all together when .attach is called.
if (queue) queue.push(rule);else {
this.insertRule(rule);
if (this.queue) {
this.queue.forEach(this.insertRule, this);
this.queue = undefined;
}
}
return rule;
} // We can't add rules to a detached style node.
// We will redeploy the sheet once user will attach it.
this.deployed = false;
return rule;
}
/**
* Replace a rule in the current stylesheet.
*/
;
_proto.replaceRule = function replaceRule(nameOrSelector, decl, options) {
var oldRule = this.rules.get(nameOrSelector);
if (!oldRule) return this.addRule(nameOrSelector, decl, options);
var newRule = this.rules.replace(nameOrSelector, decl, options);
if (newRule) {
this.options.jss.plugins.onProcessRule(newRule);
}
if (this.attached) {
if (!this.deployed) return newRule; // Don't replace / delete rule directly if there is no stringified version yet.
// It will be inserted all together when .attach is called.
if (this.renderer) {
if (!newRule) {
this.renderer.deleteRule(oldRule);
} else if (oldRule.renderable) {
this.renderer.replaceRule(oldRule.renderable, newRule);
}
}
return newRule;
} // We can't replace rules to a detached style node.
// We will redeploy the sheet once user will attach it.
this.deployed = false;
return newRule;
}
/**
* Insert rule into the StyleSheet
*/
;
_proto.insertRule = function insertRule(rule) {
if (this.renderer) {
this.renderer.insertRule(rule);
}
}
/**
* Create and add rules.
* Will render also after Style Sheet was rendered the first time.
*/
;
_proto.addRules = function addRules(styles, options) {
var added = [];
for (var name in styles) {
var rule = this.addRule(name, styles[name], options);
if (rule) added.push(rule);
}
return added;
}
/**
* Get a rule by name or selector.
*/
;
_proto.getRule = function getRule(nameOrSelector) {
return this.rules.get(nameOrSelector);
}
/**
* Delete a rule by name.
* Returns `true`: if rule has been deleted from the DOM.
*/
;
_proto.deleteRule = function deleteRule(name) {
var rule = typeof name === 'object' ? name : this.rules.get(name);
if (!rule || // Style sheet was created without link: true and attached, in this case we
// won't be able to remove the CSS rule from the DOM.
this.attached && !rule.renderable) {
return false;
}
this.rules.remove(rule);
if (this.attached && rule.renderable && this.renderer) {
return this.renderer.deleteRule(rule.renderable);
}
return true;
}
/**
* Get index of a rule.
*/
;
_proto.indexOf = function indexOf(rule) {
return this.rules.indexOf(rule);
}
/**
* Deploy pure CSS string to a renderable.
*/
;
_proto.deploy = function deploy() {
if (this.renderer) this.renderer.deploy();
this.deployed = true;
return this;
}
/**
* Update the function values with a new data.
*/
;
_proto.update = function update() {
var _this$rules;
(_this$rules = this.rules).update.apply(_this$rules, arguments);
return this;
}
/**
* Updates a single rule.
*/
;
_proto.updateOne = function updateOne(rule, data, options) {
this.rules.updateOne(rule, data, options);
return this;
}
/**
* Convert rules to a CSS string.
*/
;
_proto.toString = function toString(options) {
return this.rules.toString(options);
};
return StyleSheet;
}();
var PluginsRegistry =
/*#__PURE__*/
function () {
function PluginsRegistry() {
this.plugins = {
internal: [],
external: []
};
this.registry = {};
}
var _proto = PluginsRegistry.prototype;
/**
* Call `onCreateRule` hooks and return an object if returned by a hook.
*/
_proto.onCreateRule = function onCreateRule(name, decl, options) {
for (var i = 0; i < this.registry.onCreateRule.length; i++) {
var rule = this.registry.onCreateRule[i](name, decl, options);
if (rule) return rule;
}
return null;
}
/**
* Call `onProcessRule` hooks.
*/
;
_proto.onProcessRule = function onProcessRule(rule) {
if (rule.isProcessed) return;
var sheet = rule.options.sheet;
for (var i = 0; i < this.registry.onProcessRule.length; i++) {
this.registry.onProcessRule[i](rule, sheet);
}
if (rule.style) this.onProcessStyle(rule.style, rule, sheet);
rule.isProcessed = true;
}
/**
* Call `onProcessStyle` hooks.
*/
;
_proto.onProcessStyle = function onProcessStyle(style, rule, sheet) {
for (var i = 0; i < this.registry.onProcessStyle.length; i++) {
rule.style = this.registry.onProcessStyle[i](rule.style, rule, sheet);
}
}
/**
* Call `onProcessSheet` hooks.
*/
;
_proto.onProcessSheet = function onProcessSheet(sheet) {
for (var i = 0; i < this.registry.onProcessSheet.length; i++) {
this.registry.onProcessSheet[i](sheet);
}
}
/**
* Call `onUpdate` hooks.
*/
;
_proto.onUpdate = function onUpdate(data, rule, sheet, options) {
for (var i = 0; i < this.registry.onUpdate.length; i++) {
this.registry.onUpdate[i](data, rule, sheet, options);
}
}
/**
* Call `onChangeValue` hooks.
*/
;
_proto.onChangeValue = function onChangeValue(value, prop, rule) {
var processedValue = value;
for (var i = 0; i < this.registry.onChangeValue.length; i++) {
processedValue = this.registry.onChangeValue[i](processedValue, prop, rule);
}
return processedValue;
}
/**
* Register a plugin.
*/
;
_proto.use = function use(newPlugin, options) {
if (options === void 0) {
options = {
queue: 'external'
};
}
var plugins = this.plugins[options.queue]; // Avoids applying same plugin twice, at least based on ref.
if (plugins.indexOf(newPlugin) !== -1) {
return;
}
plugins.push(newPlugin);
this.registry = [].concat(this.plugins.external, this.plugins.internal).reduce(function (registry, plugin) {
for (var name in plugin) {
if (name in registry) {
registry[name].push(plugin[name]);
}
}
return registry;
}, {
onCreateRule: [],
onProcessRule: [],
onProcessStyle: [],
onProcessSheet: [],
onChangeValue: [],
onUpdate: []
});
};
return PluginsRegistry;
}();
/**
* Sheets registry to access all instances in one place.
*/
var SheetsRegistry =
/*#__PURE__*/
function () {
function SheetsRegistry() {
this.registry = [];
}
var _proto = SheetsRegistry.prototype;
/**
* Register a Style Sheet.
*/
_proto.add = function add(sheet) {
var registry = this.registry;
var index = sheet.options.index;
if (registry.indexOf(sheet) !== -1) return;
if (registry.length === 0 || index >= this.index) {
registry.push(sheet);
return;
} // Find a position.
for (var i = 0; i < registry.length; i++) {
if (registry[i].options.index > index) {
registry.splice(i, 0, sheet);
return;
}
}
}
/**
* Reset the registry.
*/
;
_proto.reset = function reset() {
this.registry = [];
}
/**
* Remove a Style Sheet.
*/
;
_proto.remove = function remove(sheet) {
var index = this.registry.indexOf(sheet);
this.registry.splice(index, 1);
}
/**
* Convert all attached sheets to a CSS string.
*/
;
_proto.toString = function toString(_temp) {
var _ref = _temp === void 0 ? {} : _temp,
attached = _ref.attached,
options = _objectWithoutPropertiesLoose(_ref, ["attached"]);
var _getWhitespaceSymbols = getWhitespaceSymbols(options),
linebreak = _getWhitespaceSymbols.linebreak;
var css = '';
for (var i = 0; i < this.registry.length; i++) {
var sheet = this.registry[i];
if (attached != null && sheet.attached !== attached) {
continue;
}
if (css) css += linebreak;
css += sheet.toString(options);
}
return css;
};
_createClass(SheetsRegistry, [{
key: "index",
/**
* Current highest index number.
*/
get: function get() {
return this.registry.length === 0 ? 0 : this.registry[this.registry.length - 1].options.index;
}
}]);
return SheetsRegistry;
}();
/**
* This is a global sheets registry. Only DomRenderer will add sheets to it.
* On the server one should use an own SheetsRegistry instance and add the
* sheets to it, because you need to make sure to create a new registry for
* each request in order to not leak sheets across requests.
*/
var sheets = new SheetsRegistry();
/* eslint-disable */
/**
* Now that `globalThis` is available on most platforms
* (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis#browser_compatibility)
* we check for `globalThis` first. `globalThis` is necessary for jss
* to run in Agoric's secure version of JavaScript (SES). Under SES,
* `globalThis` exists, but `window`, `self`, and `Function('return
* this')()` are all undefined for security reasons.
*
* https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
*/
var globalThis$1 = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' && window.Math === Math ? window : typeof self !== 'undefined' && self.Math === Math ? self : Function('return this')();
var ns = '2f1acc6c3a606b082e5eef5e54414ffb';
if (globalThis$1[ns] == null) globalThis$1[ns] = 0; // Bundle may contain multiple JSS versions at the same time. In order to identify
// the current version with just one short number and use it for classes