UNPKG

@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,736 lines (1,409 loc) 419 kB
'use strict'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const blurFrosted = '--p-blur-frosted'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const radius2Xl = '--p-radius-2xl'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const radius3Xl = '--p-radius-3xl'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const radiusFull = '--p-radius-full'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const radiusLg = '--p-radius-lg'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const radiusMd = '--p-radius-md'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const radiusSm = '--p-radius-sm'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const radiusXl = '--p-radius-xl'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorFocus = '--p-color-focus'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorBackdrop = '--p-color-backdrop'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorCanvas = '--p-color-canvas'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorFrosted = '--p-color-frosted'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorFrostedSoft = '--p-color-frosted-soft'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorFrostedStrong = '--p-color-frosted-strong'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorSurface = '--p-color-surface'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorContrastHigh = '--p-color-contrast-high'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorContrastHigher = '--p-color-contrast-higher'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorContrastLow = '--p-color-contrast-low'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorContrastLower = '--p-color-contrast-lower'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorContrastMedium = '--p-color-contrast-medium'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorPrimary = '--p-color-primary'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorError = '--p-color-error'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorErrorFrosted = '--p-color-error-frosted'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorErrorFrostedSoft = '--p-color-error-frosted-soft'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorErrorMedium = '--p-color-error-medium'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorInfo = '--p-color-info'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorInfoFrosted = '--p-color-info-frosted'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorInfoFrostedSoft = '--p-color-info-frosted-soft'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorInfoMedium = '--p-color-info-medium'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorSuccess = '--p-color-success'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorSuccessFrosted = '--p-color-success-frosted'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorSuccessFrostedSoft = '--p-color-success-frosted-soft'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorSuccessLow = '--p-color-success-low'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorSuccessMedium = '--p-color-success-medium'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorWarning = '--p-color-warning'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorWarningFrosted = '--p-color-warning-frosted'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorWarningFrostedSoft = '--p-color-warning-frosted-soft'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const colorWarningMedium = '--p-color-warning-medium'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const fontPorscheNext$1 = '--p-font-porsche-next'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const leadingNormal$1 = '--p-leading-normal'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const typescale2Xl = '--p-typescale-2xl'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const typescale2Xs = '--p-typescale-2xs'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const typescale3Xl = '--p-typescale-3xl'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const typescale4Xl = '--p-typescale-4xl'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const typescale5Xl = '--p-typescale-5xl'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const typescaleLg = '--p-typescale-lg'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const typescaleMd = '--p-typescale-md'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const typescaleSm$1 = '--p-typescale-sm'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const typescaleXl = '--p-typescale-xl'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const typescaleXs$1 = '--p-typescale-xs'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const fontWeightBold = '--p-font-weight-bold'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const fontWeightNormal$1 = '--p-font-weight-normal'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const fontWeightSemibold = '--p-font-weight-semibold'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const durationLg = '--p-duration-lg'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const durationMd$1 = '--p-duration-md'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const durationSm = '--p-duration-sm'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const durationXl = '--p-duration-xl'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const easeIn$1 = '--p-ease-in'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const easeInOut = '--p-ease-in-out'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const easeOut$1 = '--p-ease-out'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const shadowLg = '--p-shadow-lg'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const spacingFluidLg = '--p-spacing-fluid-lg'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const spacingFluidMd$1 = '--p-spacing-fluid-md'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const spacingFluidSm = '--p-spacing-fluid-sm'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const spacingFluidXs = '--p-spacing-fluid-xs'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const spacingStatic2Xs = '--p-spacing-static-2xs'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const spacingStaticMd = '--p-spacing-static-md'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const spacingStaticSm$1 = '--p-spacing-static-sm'; // AUTO-GENERATED by scripts/buildCssVariableConstants.ts — do not edit by hand. const spacingStaticXs$1 = '--p-spacing-static-xs'; // Wraps a bare CSS custom property name // (e.g. `--p-color-canvas`, exported as a plain literal const) into a CSS // `var(...)` reference, optionally with a fallback. Kept as a standalone module // with no side effects so bundlers (Stencil/Rollup) can tree-shake it together // with the individual variable consts. /** * Wraps a CSS custom property name into a `var(...)` reference. * * @example * import { colorCanvas, ref } from '@porsche-design-system/stylesheets'; * const styles = { background: ref(colorCanvas) }; // -> 'var(--p-color-canvas)' * const styles = { color: ref(colorPrimary, '#000') }; // -> 'var(--p-color-primary,#000)' * * @param name The bare CSS custom property name, e.g. `--p-color-canvas`. * @param fallback Optional fallback value used when the variable is not defined. */ const ref = (name, fallback) => `var(${name}${fallback === undefined ? '' : `,${fallback}`})`; const alphaDisabled = 0.4; const forcedColorsMediaQuery = (style) => { return { '@media(forced-colors:active)': style }; }; const motionDurationMap = { short: ref(durationSm), moderate: ref(durationMd$1), long: ref(durationLg), veryLong: ref(durationXl), }; const motionEasingMap = { base: ref(easeInOut), in: ref(easeIn$1), out: ref(easeOut$1), linear: 'linear', }; const cssVariableTransitionDuration = '--p-transition-duration'; const cssVariableAnimationDuration = '--p-animation-duration'; const getAnimation = (name, duration = 'short', easing = 'base') => { return `${name} ${ref(cssVariableAnimationDuration, motionDurationMap[duration])} ${motionEasingMap[easing]}`; }; const getTransition = (cssProperty, duration = 'short', easing = 'base', delay) => { return `${cssProperty} ${ref(cssVariableTransitionDuration, motionDurationMap[duration])} ${motionEasingMap[easing]}${''}`; }; const addImportantToRule = (value) => `${value} !important`; const addImportantToEachRule = (input) => { return Object.entries(input).reduce((result, [key, value]) => value === null ? result : // @ts-expect-error: Type string can't be used to index type JssStyle ((result[key] = // biome-ignore lint/complexity/noCommaOperator: to be refactored typeof value === 'object' ? addImportantToEachRule(value) : addImportantToRule(value)), result), {}); }; const getFocusBaseStyles = (offset = 2) => { return { outline: `2px solid ${ref(colorFocus)}`, outlineOffset: `${offset}px`, ...forcedColorsMediaQuery({ outlineColor: 'Highlight', }), }; }; const getDisabledBaseStyles = (addForcedColorsDisabledStyles) => { return { opacity: alphaDisabled, ...forcedColorsMediaQuery({ opacity: 1, color: 'GrayText', ...addForcedColorsDisabledStyles, }), }; }; /** * Returns a JSS style object that can be used to visually hide text in the browser, while still allowing it to be accessed by screen readers. * @param {boolean} isHidden - A boolean value indicating whether the text should be hidden or not. Defaults to true. * @param {JssStyle} isShownJssStyle - Additional styles applied when isHidden = false * @returns {JssStyle} - A JSS style object containing styles depending on the value of isHidden and isShownJssStyle. */ const getHiddenTextJssStyle = (isHidden = true, isShownJssStyle) => { return isHidden ? { position: 'absolute', width: '1px', height: '1px', padding: 0, margin: '-1px', overflow: 'hidden', clip: 'rect(0,0,0,0)', whiteSpace: 'nowrap', } : { position: 'static', width: 'auto', height: 'auto', padding: 0, margin: 0, overflow: 'visible', clip: 'auto', whiteSpace: 'normal', ...isShownJssStyle, }; }; const hostHiddenStyles = { '&([hidden])': { display: 'none', }, }; const preventFoucOfNestedElementsStyles = { ':not(:defined,[data-ssr])': { visibility: 'hidden', }, }; /** * utility to wrap jss styles parameter in `@media (hover: hover)` * which is used to not have hover styles on touch devices */ const hoverMediaQuery = (style) => { return { '@media(hover:hover)': style }; }; /** * Utility to wrap JSS styles in `@media (pointer: coarse)`, * which targets touch devices with an imprecise pointer. */ const pointerCoarseMediaQuery = (style) => { return { '@media(pointer:coarse)': style }; }; function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, 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(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", { writable: false }), e; } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } function _inheritsLoose(t, o) { t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o); } function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; } 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)