New source found from dndbeyond.com
This commit is contained in:
+6
-151
@@ -1,5 +1,5 @@
|
||||
import { StyleSheet } from '@emotion/sheet';
|
||||
import { dealloc, alloc, next, token, from, peek, delimit, slice, position, RULESET, combine, match, serialize, copy, replace, WEBKIT, MOZ, MS, KEYFRAMES, DECLARATION, hash, charat, strlen, indexof, stringify, COMMENT, rulesheet, middleware, compile } from 'stylis';
|
||||
import { dealloc, alloc, next, token, from, peek, delimit, slice, position, RULESET, combine, match, serialize, copy, replace, WEBKIT, MOZ, MS, KEYFRAMES, DECLARATION, hash, charat, strlen, indexof, stringify, rulesheet, middleware, compile } from 'stylis';
|
||||
import '@emotion/weak-memoize';
|
||||
import '@emotion/memoize';
|
||||
|
||||
@@ -81,8 +81,8 @@ var compat = function compat(element) {
|
||||
return;
|
||||
}
|
||||
|
||||
var value = element.value,
|
||||
parent = element.parent;
|
||||
var value = element.value;
|
||||
var parent = element.parent;
|
||||
var isImplicitRule = element.column === parent.column && element.line === parent.line;
|
||||
|
||||
while (parent.type !== 'rule') {
|
||||
@@ -127,114 +127,6 @@ var removeLabel = function removeLabel(element) {
|
||||
}
|
||||
}
|
||||
};
|
||||
var ignoreFlag = 'emotion-disable-server-rendering-unsafe-selector-warning-please-do-not-use-this-the-warning-exists-for-a-reason';
|
||||
|
||||
var isIgnoringComment = function isIgnoringComment(element) {
|
||||
return element.type === 'comm' && element.children.indexOf(ignoreFlag) > -1;
|
||||
};
|
||||
|
||||
var createUnsafeSelectorsAlarm = function createUnsafeSelectorsAlarm(cache) {
|
||||
return function (element, index, children) {
|
||||
if (element.type !== 'rule' || cache.compat) return;
|
||||
var unsafePseudoClasses = element.value.match(/(:first|:nth|:nth-last)-child/g);
|
||||
|
||||
if (unsafePseudoClasses) {
|
||||
var isNested = !!element.parent; // in nested rules comments become children of the "auto-inserted" rule and that's always the `element.parent`
|
||||
//
|
||||
// considering this input:
|
||||
// .a {
|
||||
// .b /* comm */ {}
|
||||
// color: hotpink;
|
||||
// }
|
||||
// we get output corresponding to this:
|
||||
// .a {
|
||||
// & {
|
||||
// /* comm */
|
||||
// color: hotpink;
|
||||
// }
|
||||
// .b {}
|
||||
// }
|
||||
|
||||
var commentContainer = isNested ? element.parent.children : // global rule at the root level
|
||||
children;
|
||||
|
||||
for (var i = commentContainer.length - 1; i >= 0; i--) {
|
||||
var node = commentContainer[i];
|
||||
|
||||
if (node.line < element.line) {
|
||||
break;
|
||||
} // it is quite weird but comments are *usually* put at `column: element.column - 1`
|
||||
// so we seek *from the end* for the node that is earlier than the rule's `element` and check that
|
||||
// this will also match inputs like this:
|
||||
// .a {
|
||||
// /* comm */
|
||||
// .b {}
|
||||
// }
|
||||
//
|
||||
// but that is fine
|
||||
//
|
||||
// it would be the easiest to change the placement of the comment to be the first child of the rule:
|
||||
// .a {
|
||||
// .b { /* comm */ }
|
||||
// }
|
||||
// with such inputs we wouldn't have to search for the comment at all
|
||||
// TODO: consider changing this comment placement in the next major version
|
||||
|
||||
|
||||
if (node.column < element.column) {
|
||||
if (isIgnoringComment(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
unsafePseudoClasses.forEach(function (unsafePseudoClass) {
|
||||
console.error("The pseudo class \"" + unsafePseudoClass + "\" is potentially unsafe when doing server-side rendering. Try changing it to \"" + unsafePseudoClass.split('-child')[0] + "-of-type\".");
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var isImportRule = function isImportRule(element) {
|
||||
return element.type.charCodeAt(1) === 105 && element.type.charCodeAt(0) === 64;
|
||||
};
|
||||
|
||||
var isPrependedWithRegularRules = function isPrependedWithRegularRules(index, children) {
|
||||
for (var i = index - 1; i >= 0; i--) {
|
||||
if (!isImportRule(children[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}; // use this to remove incorrect elements from further processing
|
||||
// so they don't get handed to the `sheet` (or anything else)
|
||||
// as that could potentially lead to additional logs which in turn could be overhelming to the user
|
||||
|
||||
|
||||
var nullifyElement = function nullifyElement(element) {
|
||||
element.type = '';
|
||||
element.value = '';
|
||||
element["return"] = '';
|
||||
element.children = '';
|
||||
element.props = '';
|
||||
};
|
||||
|
||||
var incorrectImportAlarm = function incorrectImportAlarm(element, index, children) {
|
||||
if (!isImportRule(element)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (element.parent) {
|
||||
console.error("`@import` rules can't be nested inside other rules. Please move it to the top level and put it before regular rules. Keep in mind that they can only be used within global styles.");
|
||||
nullifyElement(element);
|
||||
} else if (isPrependedWithRegularRules(index, children)) {
|
||||
console.error("`@import` rules can't be after other rules. Please put your `@import` rules before your other rules.");
|
||||
nullifyElement(element);
|
||||
}
|
||||
};
|
||||
|
||||
/* eslint-disable no-fallthrough */
|
||||
|
||||
@@ -453,10 +345,6 @@ var defaultStylisPlugins = [prefixer];
|
||||
var createCache = function createCache(options) {
|
||||
var key = options.key;
|
||||
|
||||
if (process.env.NODE_ENV !== 'production' && !key) {
|
||||
throw new Error("You have to configure `key` for your cache. Please make sure it's unique (and not equal to 'css') as it's used for linking styles to your cache.\n" + "If multiple caches share the same key they might \"fight\" for each other's style elements.");
|
||||
}
|
||||
|
||||
if (key === 'css') {
|
||||
var ssrStyles = document.querySelectorAll("style[data-emotion]:not([data-s])"); // get SSRed styles out of the way of React's hydration
|
||||
// document.head is a safe place to move them to(though note document.head is not necessarily the last place they will be)
|
||||
@@ -475,6 +363,7 @@ var createCache = function createCache(options) {
|
||||
if (dataEmotionAttribute.indexOf(' ') === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
document.head.appendChild(node);
|
||||
node.setAttribute('data-s', '');
|
||||
});
|
||||
@@ -482,13 +371,6 @@ var createCache = function createCache(options) {
|
||||
|
||||
var stylisPlugins = options.stylisPlugins || defaultStylisPlugins;
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
// $FlowFixMe
|
||||
if (/[^a-z-]/.test(key)) {
|
||||
throw new Error("Emotion key must only contain lower case alphabetical characters and - but \"" + key + "\" was passed");
|
||||
}
|
||||
}
|
||||
|
||||
var inserted = {};
|
||||
var container;
|
||||
var nodesToHydrate = [];
|
||||
@@ -498,7 +380,7 @@ var createCache = function createCache(options) {
|
||||
Array.prototype.forEach.call( // this means we will ignore elements which don't have a space in them which
|
||||
// means that the style elements we're looking at are only Emotion 11 server-rendered style elements
|
||||
document.querySelectorAll("style[data-emotion^=\"" + key + " \"]"), function (node) {
|
||||
var attrib = node.getAttribute("data-emotion").split(' '); // $FlowFixMe
|
||||
var attrib = node.getAttribute("data-emotion").split(' ');
|
||||
|
||||
for (var i = 1; i < attrib.length; i++) {
|
||||
inserted[attrib[i]] = true;
|
||||
@@ -512,28 +394,9 @@ var createCache = function createCache(options) {
|
||||
|
||||
var omnipresentPlugins = [compat, removeLabel];
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
omnipresentPlugins.push(createUnsafeSelectorsAlarm({
|
||||
get compat() {
|
||||
return cache.compat;
|
||||
}
|
||||
|
||||
}), incorrectImportAlarm);
|
||||
}
|
||||
|
||||
{
|
||||
var currentSheet;
|
||||
var finalizingPlugins = [stringify, process.env.NODE_ENV !== 'production' ? function (element) {
|
||||
if (!element.root) {
|
||||
if (element["return"]) {
|
||||
currentSheet.insert(element["return"]);
|
||||
} else if (element.value && element.type !== COMMENT) {
|
||||
// insert empty rule in non-production environments
|
||||
// so @emotion/jest can grab `key` from the (JS)DOM for caches without any rules inserted yet
|
||||
currentSheet.insert(element.value + "{}");
|
||||
}
|
||||
}
|
||||
} : rulesheet(function (rule) {
|
||||
var finalizingPlugins = [stringify, rulesheet(function (rule) {
|
||||
currentSheet.insert(rule);
|
||||
})];
|
||||
var serializer = middleware(omnipresentPlugins.concat(stylisPlugins, finalizingPlugins));
|
||||
@@ -545,14 +408,6 @@ var createCache = function createCache(options) {
|
||||
_insert = function insert(selector, serialized, sheet, shouldCache) {
|
||||
currentSheet = sheet;
|
||||
|
||||
if (process.env.NODE_ENV !== 'production' && serialized.map !== undefined) {
|
||||
currentSheet = {
|
||||
insert: function insert(rule) {
|
||||
sheet.insert(rule + serialized.map);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
stylis(selector ? selector + "{" + serialized.styles + "}" : serialized.styles);
|
||||
|
||||
if (shouldCache) {
|
||||
|
||||
Reference in New Issue
Block a user