formacao
This commit is contained in:
+59
-9
@@ -1,4 +1,3 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
@@ -58,6 +57,24 @@ const toHash = (str) => {
|
||||
}
|
||||
return "css-" + out;
|
||||
};
|
||||
const normalizeLabel = (label) => {
|
||||
return label.trim().replace(/\s+/g, "-");
|
||||
};
|
||||
const isValidClassName = (name) => /^-?[_a-zA-Z][_a-zA-Z0-9-]*$/.test(name);
|
||||
const hasUnsafeSelectorChar = (name) => /[<{}]/.test(name);
|
||||
const RESERVED_KEYFRAME_NAMES = /* @__PURE__ */ new Set([
|
||||
"default",
|
||||
"inherit",
|
||||
"initial",
|
||||
"none",
|
||||
"revert",
|
||||
"revert-layer",
|
||||
"unset"
|
||||
]);
|
||||
const isValidKeyframeName = (name) => isValidClassName(name) && !RESERVED_KEYFRAME_NAMES.has(name.toLowerCase());
|
||||
const defaultOnInvalidSlug = (slug) => {
|
||||
console.warn(`Invalid slug: ${slug}`);
|
||||
};
|
||||
const cssStringReStr = [
|
||||
'"(?:(?:\\\\[\\s\\S]|[^"\\\\])*)"',
|
||||
// double quoted string
|
||||
@@ -144,13 +161,26 @@ const buildStyleString = (strings, values) => {
|
||||
}
|
||||
return [label, minify(styleString), selectors, externalClassNames];
|
||||
};
|
||||
const cssCommon = (strings, values) => {
|
||||
const cssCommon = (strings, values, classNameSlug, onInvalidSlug) => {
|
||||
let [label, thisStyleString, selectors, externalClassNames] = buildStyleString(strings, values);
|
||||
const isPseudoGlobal = isPseudoGlobalSelectorRe.exec(thisStyleString);
|
||||
if (isPseudoGlobal) {
|
||||
thisStyleString = isPseudoGlobal[1];
|
||||
}
|
||||
const selector = (isPseudoGlobal ? PSEUDO_GLOBAL_SELECTOR : "") + toHash(label + thisStyleString);
|
||||
const hash = toHash(label + thisStyleString);
|
||||
let customSlug;
|
||||
if (classNameSlug) {
|
||||
const slug = classNameSlug(hash, normalizeLabel(label), thisStyleString);
|
||||
if (slug) {
|
||||
if (isValidClassName(slug)) {
|
||||
customSlug = slug;
|
||||
} else {
|
||||
;
|
||||
(onInvalidSlug || defaultOnInvalidSlug)(slug);
|
||||
}
|
||||
}
|
||||
}
|
||||
const selector = (isPseudoGlobal ? PSEUDO_GLOBAL_SELECTOR : "") + (customSlug || hash);
|
||||
const className = (isPseudoGlobal ? selectors.map((s) => s[CLASS_NAME]) : [selector, ...externalClassNames]).join(" ");
|
||||
return {
|
||||
[SELECTOR]: selector,
|
||||
@@ -169,30 +199,50 @@ const cxCommon = (args) => {
|
||||
[CLASS_NAME]: "",
|
||||
[STYLE_STRING]: "",
|
||||
[SELECTORS]: [],
|
||||
[EXTERNAL_CLASS_NAMES]: [arg]
|
||||
// drop names that are unsafe to emit as a selector
|
||||
[EXTERNAL_CLASS_NAMES]: hasUnsafeSelectorChar(arg) ? [] : [arg]
|
||||
};
|
||||
}
|
||||
}
|
||||
return args;
|
||||
};
|
||||
const keyframesCommon = (strings, ...values) => {
|
||||
const keyframesCommon = (strings, values, classNameSlug, onInvalidSlug) => {
|
||||
const [label, styleString] = buildStyleString(strings, values);
|
||||
const hash = toHash(label + styleString);
|
||||
let customSlug;
|
||||
if (classNameSlug) {
|
||||
const slug = classNameSlug(hash, normalizeLabel(label), styleString);
|
||||
if (slug) {
|
||||
if (isValidKeyframeName(slug)) {
|
||||
customSlug = slug;
|
||||
} else {
|
||||
;
|
||||
(onInvalidSlug || defaultOnInvalidSlug)(slug);
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
[SELECTOR]: "",
|
||||
[CLASS_NAME]: `@keyframes ${toHash(label + styleString)}`,
|
||||
[CLASS_NAME]: `@keyframes ${customSlug || hash}`,
|
||||
[STYLE_STRING]: styleString,
|
||||
[SELECTORS]: [],
|
||||
[EXTERNAL_CLASS_NAMES]: []
|
||||
};
|
||||
};
|
||||
let viewTransitionNameIndex = 0;
|
||||
const viewTransitionCommon = ((strings, values) => {
|
||||
const viewTransitionCommon = ((strings, values, classNameSlug, onInvalidSlug) => {
|
||||
if (!strings) {
|
||||
strings = [`/* h-v-t ${viewTransitionNameIndex++} */`];
|
||||
}
|
||||
const content = Array.isArray(strings) ? cssCommon(strings, values) : strings;
|
||||
const content = Array.isArray(strings) ? cssCommon(strings, values, classNameSlug, onInvalidSlug) : strings;
|
||||
const transitionName = content[CLASS_NAME];
|
||||
const res = cssCommon(["view-transition-name:", ""], [transitionName]);
|
||||
const res = cssCommon(
|
||||
["view-transition-name:", ""],
|
||||
// eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
[transitionName],
|
||||
classNameSlug,
|
||||
onInvalidSlug
|
||||
);
|
||||
content[CLASS_NAME] = PSEUDO_GLOBAL_SELECTOR + content[CLASS_NAME];
|
||||
content[STYLE_STRING] = content[STYLE_STRING].replace(
|
||||
/(?<=::view-transition(?:[a-z-]*)\()(?=\))/g,
|
||||
|
||||
+20
-6
@@ -1,4 +1,3 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
@@ -30,9 +29,14 @@ module.exports = __toCommonJS(css_exports);
|
||||
var import_html = require("../../helper/html");
|
||||
var import_constants = require("../../jsx/constants");
|
||||
var import_css = require("../../jsx/dom/css");
|
||||
var import_html2 = require("../../utils/html");
|
||||
var import_common = require("./common");
|
||||
var import_common2 = require("./common");
|
||||
const createCssContext = ({ id }) => {
|
||||
const createCssContext = ({
|
||||
id,
|
||||
classNameSlug,
|
||||
onInvalidSlug
|
||||
}) => {
|
||||
const [cssJsxDomObject, StyleRenderToDom] = (0, import_css.createCssJsxDomObjects)({ id });
|
||||
const contextMap = /* @__PURE__ */ new WeakMap();
|
||||
const nonceMap = /* @__PURE__ */ new WeakMap();
|
||||
@@ -85,7 +89,14 @@ const createCssContext = ({ id }) => {
|
||||
}
|
||||
return Promise.resolve((0, import_html.raw)("", [appendStyle]));
|
||||
};
|
||||
const className = new String(cssClassName[import_common.CLASS_NAME]);
|
||||
const rawClassName = cssClassName[import_common.CLASS_NAME];
|
||||
let escapedClassName = rawClassName;
|
||||
if (/[&<>'"]/.test(rawClassName)) {
|
||||
const escapedBuffer = [""];
|
||||
(0, import_html2.escapeToBuffer)(rawClassName, escapedBuffer);
|
||||
escapedClassName = escapedBuffer[0];
|
||||
}
|
||||
const className = new String(escapedClassName);
|
||||
Object.assign(className, cssClassName);
|
||||
className.isEscaped = true;
|
||||
className.callbacks = [addClassNameToContext];
|
||||
@@ -95,15 +106,18 @@ const createCssContext = ({ id }) => {
|
||||
return promise;
|
||||
};
|
||||
const css2 = (strings, ...values) => {
|
||||
return newCssClassNameObject((0, import_common.cssCommon)(strings, values));
|
||||
return newCssClassNameObject((0, import_common.cssCommon)(strings, values, classNameSlug, onInvalidSlug));
|
||||
};
|
||||
const cx2 = (...args) => {
|
||||
args = (0, import_common.cxCommon)(args);
|
||||
return css2(Array(args.length).fill(""), ...args);
|
||||
};
|
||||
const keyframes2 = import_common.keyframesCommon;
|
||||
const keyframes2 = (strings, ...values) => (0, import_common.keyframesCommon)(strings, values, classNameSlug, onInvalidSlug);
|
||||
const viewTransition2 = ((strings, ...values) => {
|
||||
return newCssClassNameObject((0, import_common.viewTransitionCommon)(strings, values));
|
||||
return newCssClassNameObject(
|
||||
(0, import_common.viewTransitionCommon)(strings, values, classNameSlug, onInvalidSlug)
|
||||
// eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
);
|
||||
});
|
||||
const Style2 = ({ children, nonce } = {}) => (0, import_html.raw)(
|
||||
`<style id="${id}"${nonce ? ` nonce="${nonce}"` : ""}>${children ? children[import_common.STYLE_STRING] : ""}</style>`,
|
||||
|
||||
Reference in New Issue
Block a user