@react-email/tailwind 2.0.0-tailwindv4.2 → 2.0.0-tailwindv4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +80 -66
- package/dist/index.mjs +70 -66
- package/dist/index.mjs.map +1 -1
- package/package.json +50 -8
package/dist/index.js
CHANGED
|
@@ -34,6 +34,26 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
34
34
|
//#endregion
|
|
35
35
|
let react = require("react");
|
|
36
36
|
react = __toESM(react);
|
|
37
|
+
let __react_email_body = require("@react-email/body");
|
|
38
|
+
__react_email_body = __toESM(__react_email_body);
|
|
39
|
+
let __react_email_button = require("@react-email/button");
|
|
40
|
+
__react_email_button = __toESM(__react_email_button);
|
|
41
|
+
let __react_email_code_block = require("@react-email/code-block");
|
|
42
|
+
__react_email_code_block = __toESM(__react_email_code_block);
|
|
43
|
+
let __react_email_code_inline = require("@react-email/code-inline");
|
|
44
|
+
__react_email_code_inline = __toESM(__react_email_code_inline);
|
|
45
|
+
let __react_email_container = require("@react-email/container");
|
|
46
|
+
__react_email_container = __toESM(__react_email_container);
|
|
47
|
+
let __react_email_heading = require("@react-email/heading");
|
|
48
|
+
__react_email_heading = __toESM(__react_email_heading);
|
|
49
|
+
let __react_email_hr = require("@react-email/hr");
|
|
50
|
+
__react_email_hr = __toESM(__react_email_hr);
|
|
51
|
+
let __react_email_img = require("@react-email/img");
|
|
52
|
+
__react_email_img = __toESM(__react_email_img);
|
|
53
|
+
let __react_email_link = require("@react-email/link");
|
|
54
|
+
__react_email_link = __toESM(__react_email_link);
|
|
55
|
+
let __react_email_preview = require("@react-email/preview");
|
|
56
|
+
__react_email_preview = __toESM(__react_email_preview);
|
|
37
57
|
let tailwindcss = require("tailwindcss");
|
|
38
58
|
tailwindcss = __toESM(tailwindcss);
|
|
39
59
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -1079,9 +1099,7 @@ function sourceFragment({ source, line, column, baseLine, baseColumn }, extraLin
|
|
|
1079
1099
|
function processLines(start, end) {
|
|
1080
1100
|
return lines.slice(start, end).map((line$1, idx) => String(start + idx + 1).padStart(maxNumLength) + " |" + line$1).join("\n");
|
|
1081
1101
|
}
|
|
1082
|
-
const
|
|
1083
|
-
const precolumns = " ".repeat(Math.max(baseColumn - 1, 0));
|
|
1084
|
-
const lines = (prelines + precolumns + source).split(/\r\n?|\n|\f/);
|
|
1102
|
+
const lines = ("\n".repeat(Math.max(baseLine - 1, 0)) + " ".repeat(Math.max(baseColumn - 1, 0)) + source).split(/\r\n?|\n|\f/);
|
|
1085
1103
|
const startLine = Math.max(1, line - extraLines) - 1;
|
|
1086
1104
|
const endLine = Math.min(line + extraLines, lines.length + 1);
|
|
1087
1105
|
const maxNumLength = Math.max(4, String(endLine).length) + 1;
|
|
@@ -1364,8 +1382,7 @@ function createParser(config) {
|
|
|
1364
1382
|
if (typeof onComment === "function") parser.forEachToken((type, start, end) => {
|
|
1365
1383
|
if (type === Comment) {
|
|
1366
1384
|
const loc = parser.getLocation(start, end);
|
|
1367
|
-
|
|
1368
|
-
onComment(value, loc);
|
|
1385
|
+
onComment(cmpStr(source, end - 2, end, "*/") ? source.slice(start + 2, end - 2) : source.slice(start + 2, end), loc);
|
|
1369
1386
|
}
|
|
1370
1387
|
});
|
|
1371
1388
|
const ast = parser.context[context].call(parser, options);
|
|
@@ -4800,8 +4817,7 @@ function processStructure(name$49, nodeType) {
|
|
|
4800
4817
|
const docs = { type: "\"" + name$49 + "\"" };
|
|
4801
4818
|
for (const key in structure$49) {
|
|
4802
4819
|
if (hasOwnProperty$1.call(structure$49, key) === false) continue;
|
|
4803
|
-
|
|
4804
|
-
docs[key] = genTypesList(fieldTypes, name$49 + "." + key);
|
|
4820
|
+
docs[key] = genTypesList(fields[key] = Array.isArray(structure$49[key]) ? structure$49[key].slice() : [structure$49[key]], name$49 + "." + key);
|
|
4805
4821
|
}
|
|
4806
4822
|
return {
|
|
4807
4823
|
docs,
|
|
@@ -19090,9 +19106,7 @@ function populateParentsForNodeTree(node) {
|
|
|
19090
19106
|
//#endregion
|
|
19091
19107
|
//#region src/utils/css/resolve-all-css-variables.ts
|
|
19092
19108
|
function doSelectorsIntersect(first, second) {
|
|
19093
|
-
|
|
19094
|
-
const secondStringified = generate(second);
|
|
19095
|
-
if (firstStringified === secondStringified) return true;
|
|
19109
|
+
if (generate(first) === generate(second)) return true;
|
|
19096
19110
|
let hasSomeUniversal = false;
|
|
19097
19111
|
const walker = (node) => {
|
|
19098
19112
|
if (hasSomeUniversal) return;
|
|
@@ -19104,12 +19118,6 @@ function doSelectorsIntersect(first, second) {
|
|
|
19104
19118
|
if (hasSomeUniversal) return true;
|
|
19105
19119
|
return false;
|
|
19106
19120
|
}
|
|
19107
|
-
function removeAndRepeatIfEmptyRecursively(node) {
|
|
19108
|
-
if (node.parent) if (node.containedIn && node.containingItem) {
|
|
19109
|
-
node.containedIn.remove(node.containingItem);
|
|
19110
|
-
if (node.containedIn.isEmpty) removeAndRepeatIfEmptyRecursively(node.parent);
|
|
19111
|
-
} else removeAndRepeatIfEmptyRecursively(node.parent);
|
|
19112
|
-
}
|
|
19113
19121
|
function someParent(node, predicate) {
|
|
19114
19122
|
if (node.parent) {
|
|
19115
19123
|
if (predicate(node.parent)) return true;
|
|
@@ -19127,11 +19135,8 @@ function resolveAllCssVariables(node) {
|
|
|
19127
19135
|
if (someParent(declaration, (ancestor) => ancestor.type === "Atrule" && ancestor.name === "layer" && ancestor.prelude !== null && generate(ancestor.prelude).includes("properties"))) return;
|
|
19128
19136
|
if (/--[\S]+/.test(declaration.property)) variableDefinitions.add({
|
|
19129
19137
|
declaration,
|
|
19130
|
-
variableName:
|
|
19131
|
-
definition: generate(declaration.value)
|
|
19132
|
-
remove() {
|
|
19133
|
-
removeAndRepeatIfEmptyRecursively(declaration);
|
|
19134
|
-
}
|
|
19138
|
+
variableName: declaration.property,
|
|
19139
|
+
definition: generate(declaration.value)
|
|
19135
19140
|
});
|
|
19136
19141
|
else {
|
|
19137
19142
|
function parseVariableUsesFrom(node$1) {
|
|
@@ -19148,10 +19153,7 @@ function resolveAllCssVariables(node) {
|
|
|
19148
19153
|
variableName: name$49,
|
|
19149
19154
|
raw: generate(funcNode)
|
|
19150
19155
|
});
|
|
19151
|
-
if (fallback?.includes("var(")) {
|
|
19152
|
-
const parsedFallback = parse(fallback, { context: "value" });
|
|
19153
|
-
parseVariableUsesFrom(parsedFallback);
|
|
19154
|
-
}
|
|
19156
|
+
if (fallback?.includes("var(")) parseVariableUsesFrom(parse(fallback, { context: "value" }));
|
|
19155
19157
|
}
|
|
19156
19158
|
}
|
|
19157
19159
|
});
|
|
@@ -19177,7 +19179,6 @@ function resolveAllCssVariables(node) {
|
|
|
19177
19179
|
}
|
|
19178
19180
|
if (!hasReplaced && use.fallback) use.declaration.value = parse(generate(use.declaration.value).replaceAll(use.raw, use.fallback), { context: "value" });
|
|
19179
19181
|
}
|
|
19180
|
-
for (const definition of variableDefinitions) definition.remove();
|
|
19181
19182
|
}
|
|
19182
19183
|
|
|
19183
19184
|
//#endregion
|
|
@@ -19466,48 +19467,26 @@ function sanitizeDeclarations(nodeContainingDeclarations) {
|
|
|
19466
19467
|
enter(hash, hashParentListItem) {
|
|
19467
19468
|
const hex = hash.value.trim();
|
|
19468
19469
|
if (hex.length === 3) {
|
|
19469
|
-
|
|
19470
|
-
const g$1 = Number.parseInt(hex.charAt(1) + hex.charAt(1), 16);
|
|
19471
|
-
const b$1 = Number.parseInt(hex.charAt(2) + hex.charAt(2), 16);
|
|
19472
|
-
hashParentListItem.data = parse(`rgb(${r$1},${g$1},${b$1})`, { context: "value" });
|
|
19470
|
+
hashParentListItem.data = parse(`rgb(${Number.parseInt(hex.charAt(0) + hex.charAt(0), 16)},${Number.parseInt(hex.charAt(1) + hex.charAt(1), 16)},${Number.parseInt(hex.charAt(2) + hex.charAt(2), 16)})`, { context: "value" });
|
|
19473
19471
|
return;
|
|
19474
19472
|
}
|
|
19475
19473
|
if (hex.length === 4) {
|
|
19476
|
-
|
|
19477
|
-
const g$1 = Number.parseInt(hex.charAt(1) + hex.charAt(1), 16);
|
|
19478
|
-
const b$1 = Number.parseInt(hex.charAt(2) + hex.charAt(2), 16);
|
|
19479
|
-
const a$1 = Number.parseInt(hex.charAt(3) + hex.charAt(3), 16) / 255;
|
|
19480
|
-
hashParentListItem.data = parse(`rgb(${r$1},${g$1},${b$1},${a$1.toFixed(1)})`, { context: "value" });
|
|
19474
|
+
hashParentListItem.data = parse(`rgb(${Number.parseInt(hex.charAt(0) + hex.charAt(0), 16)},${Number.parseInt(hex.charAt(1) + hex.charAt(1), 16)},${Number.parseInt(hex.charAt(2) + hex.charAt(2), 16)},${(Number.parseInt(hex.charAt(3) + hex.charAt(3), 16) / 255).toFixed(1)})`, { context: "value" });
|
|
19481
19475
|
return;
|
|
19482
19476
|
}
|
|
19483
19477
|
if (hex.length === 5) {
|
|
19484
|
-
|
|
19485
|
-
const g$1 = Number.parseInt(hex.charAt(2) + hex.charAt(2), 16);
|
|
19486
|
-
const b$1 = Number.parseInt(hex.charAt(3) + hex.charAt(3), 16);
|
|
19487
|
-
const a$1 = Number.parseInt(hex.charAt(4) + hex.charAt(4), 16) / 255;
|
|
19488
|
-
hashParentListItem.data = parse(`rgb(${r$1},${g$1},${b$1},${a$1.toFixed(1)})`, { context: "value" });
|
|
19478
|
+
hashParentListItem.data = parse(`rgb(${Number.parseInt(hex.slice(0, 2), 16)},${Number.parseInt(hex.charAt(2) + hex.charAt(2), 16)},${Number.parseInt(hex.charAt(3) + hex.charAt(3), 16)},${(Number.parseInt(hex.charAt(4) + hex.charAt(4), 16) / 255).toFixed(1)})`, { context: "value" });
|
|
19489
19479
|
return;
|
|
19490
19480
|
}
|
|
19491
19481
|
if (hex.length === 6) {
|
|
19492
|
-
|
|
19493
|
-
const g$1 = Number.parseInt(hex.slice(2, 4), 16);
|
|
19494
|
-
const b$1 = Number.parseInt(hex.slice(4, 6), 16);
|
|
19495
|
-
hashParentListItem.data = parse(`rgb(${r$1},${g$1},${b$1})`, { context: "value" });
|
|
19482
|
+
hashParentListItem.data = parse(`rgb(${Number.parseInt(hex.slice(0, 2), 16)},${Number.parseInt(hex.slice(2, 4), 16)},${Number.parseInt(hex.slice(4, 6), 16)})`, { context: "value" });
|
|
19496
19483
|
return;
|
|
19497
19484
|
}
|
|
19498
19485
|
if (hex.length === 7) {
|
|
19499
|
-
|
|
19500
|
-
const g$1 = Number.parseInt(hex.slice(2, 4), 16);
|
|
19501
|
-
const b$1 = Number.parseInt(hex.slice(4, 6), 16);
|
|
19502
|
-
const a$1 = Number.parseInt(hex.charAt(6) + hex.charAt(6), 16) / 255;
|
|
19503
|
-
hashParentListItem.data = parse(`rgb(${r$1},${g$1},${b$1},${a$1.toFixed(1)})`, { context: "value" });
|
|
19486
|
+
hashParentListItem.data = parse(`rgb(${Number.parseInt(hex.slice(0, 2), 16)},${Number.parseInt(hex.slice(2, 4), 16)},${Number.parseInt(hex.slice(4, 6), 16)},${(Number.parseInt(hex.charAt(6) + hex.charAt(6), 16) / 255).toFixed(1)})`, { context: "value" });
|
|
19504
19487
|
return;
|
|
19505
19488
|
}
|
|
19506
|
-
|
|
19507
|
-
const g = Number.parseInt(hex.slice(2, 4), 16);
|
|
19508
|
-
const b = Number.parseInt(hex.slice(4, 6), 16);
|
|
19509
|
-
const a = Number.parseInt(hex.slice(6, 8), 16) / 255;
|
|
19510
|
-
hashParentListItem.data = parse(`rgb(${r},${g},${b},${a.toFixed(1)})`, { context: "value" });
|
|
19489
|
+
hashParentListItem.data = parse(`rgb(${Number.parseInt(hex.slice(0, 2), 16)},${Number.parseInt(hex.slice(2, 4), 16)},${Number.parseInt(hex.slice(4, 6), 16)},${(Number.parseInt(hex.slice(6, 8), 16) / 255).toFixed(1)})`, { context: "value" });
|
|
19511
19490
|
}
|
|
19512
19491
|
});
|
|
19513
19492
|
walk(declaration, {
|
|
@@ -19594,10 +19573,7 @@ function sanitizeNonInlinableRules(node) {
|
|
|
19594
19573
|
enter(rule) {
|
|
19595
19574
|
if (!isRuleInlinable(rule)) {
|
|
19596
19575
|
walk(rule.prelude, (node$1) => {
|
|
19597
|
-
if (node$1.type === "ClassSelector")
|
|
19598
|
-
const unescapedClassName = decode$1(node$1.name);
|
|
19599
|
-
node$1.name = sanitizeClassName(unescapedClassName);
|
|
19600
|
-
}
|
|
19576
|
+
if (node$1.type === "ClassSelector") node$1.name = sanitizeClassName(decode$1(node$1.name));
|
|
19601
19577
|
});
|
|
19602
19578
|
walk(rule, {
|
|
19603
19579
|
visit: "Declaration",
|
|
@@ -19612,8 +19588,20 @@ function sanitizeNonInlinableRules(node) {
|
|
|
19612
19588
|
|
|
19613
19589
|
//#endregion
|
|
19614
19590
|
//#region src/utils/react/is-component.ts
|
|
19591
|
+
const componentsToTreatAsElements = [
|
|
19592
|
+
__react_email_body.Body,
|
|
19593
|
+
__react_email_button.Button,
|
|
19594
|
+
__react_email_code_block.CodeBlock,
|
|
19595
|
+
__react_email_code_inline.CodeInline,
|
|
19596
|
+
__react_email_container.Container,
|
|
19597
|
+
__react_email_heading.Heading,
|
|
19598
|
+
__react_email_hr.Hr,
|
|
19599
|
+
__react_email_img.Img,
|
|
19600
|
+
__react_email_link.Link,
|
|
19601
|
+
__react_email_preview.Preview
|
|
19602
|
+
];
|
|
19615
19603
|
const isComponent = (element) => {
|
|
19616
|
-
return (typeof element.type === "function" || element.type.render !== void 0) && element.type
|
|
19604
|
+
return (typeof element.type === "function" || element.type.render !== void 0) && !componentsToTreatAsElements.includes(element.type);
|
|
19617
19605
|
};
|
|
19618
19606
|
|
|
19619
19607
|
//#endregion
|
|
@@ -19636,10 +19624,7 @@ function mapReactTree(value, process) {
|
|
|
19636
19624
|
const newProps = { ...node.props };
|
|
19637
19625
|
if (node.props.children && !isComponent(node)) newProps.children = mapReactTree(node.props.children, process);
|
|
19638
19626
|
const processed = process(react.default.cloneElement(node, newProps, newProps.children));
|
|
19639
|
-
if (react.default.isValidElement(processed) && isComponent(processed))
|
|
19640
|
-
const rendered = (typeof processed.type === "object" ? processed.type.render : processed.type)(processed.props);
|
|
19641
|
-
return mapReactTree(rendered, process);
|
|
19642
|
-
}
|
|
19627
|
+
if (react.default.isValidElement(processed) && isComponent(processed)) return mapReactTree((typeof processed.type === "object" ? processed.type.render : processed.type)(processed.props), process);
|
|
19643
19628
|
return processed;
|
|
19644
19629
|
}
|
|
19645
19630
|
return process(node);
|
|
@@ -19654,8 +19639,8 @@ const fromDashCaseToCamelCase = (text) => {
|
|
|
19654
19639
|
};
|
|
19655
19640
|
|
|
19656
19641
|
//#endregion
|
|
19657
|
-
//#region src/utils/compatibility/
|
|
19658
|
-
function
|
|
19642
|
+
//#region src/utils/compatibility/get-react-property.ts
|
|
19643
|
+
function getReactProperty(prop) {
|
|
19659
19644
|
const modifiedProp = prop.toLowerCase();
|
|
19660
19645
|
if (modifiedProp.startsWith("--")) return modifiedProp;
|
|
19661
19646
|
if (modifiedProp.startsWith("-ms-")) return fromDashCaseToCamelCase(modifiedProp.slice(1));
|
|
@@ -19666,12 +19651,41 @@ function convertCssPropertyToReactProperty(prop) {
|
|
|
19666
19651
|
//#region src/utils/css/make-inline-styles-for.ts
|
|
19667
19652
|
function makeInlineStylesFor(inlinableRules) {
|
|
19668
19653
|
const styles = {};
|
|
19654
|
+
const localVariableDeclarations = /* @__PURE__ */ new Set();
|
|
19669
19655
|
for (const rule of inlinableRules) walk(rule, {
|
|
19670
19656
|
visit: "Declaration",
|
|
19671
19657
|
enter(declaration) {
|
|
19672
|
-
|
|
19658
|
+
if (declaration.property.startsWith("--")) localVariableDeclarations.add(declaration);
|
|
19673
19659
|
}
|
|
19674
19660
|
});
|
|
19661
|
+
for (const rule of inlinableRules) {
|
|
19662
|
+
walk(rule, {
|
|
19663
|
+
visit: "Function",
|
|
19664
|
+
enter(func, funcParentListItem) {
|
|
19665
|
+
if (func.name === "var") {
|
|
19666
|
+
let variableName;
|
|
19667
|
+
walk(func, {
|
|
19668
|
+
visit: "Identifier",
|
|
19669
|
+
enter(identifier) {
|
|
19670
|
+
variableName = identifier.name;
|
|
19671
|
+
return this.break;
|
|
19672
|
+
}
|
|
19673
|
+
});
|
|
19674
|
+
if (variableName) {
|
|
19675
|
+
const definition = Array.from(localVariableDeclarations).find((declaration) => variableName === declaration.property);
|
|
19676
|
+
if (definition) funcParentListItem.data = definition.value;
|
|
19677
|
+
}
|
|
19678
|
+
}
|
|
19679
|
+
}
|
|
19680
|
+
});
|
|
19681
|
+
walk(rule, {
|
|
19682
|
+
visit: "Declaration",
|
|
19683
|
+
enter(declaration) {
|
|
19684
|
+
if (declaration.property.startsWith("--")) return;
|
|
19685
|
+
styles[getReactProperty(declaration.property)] = generate(declaration.value) + (declaration.important ? "!important" : "");
|
|
19686
|
+
}
|
|
19687
|
+
});
|
|
19688
|
+
}
|
|
19675
19689
|
return styles;
|
|
19676
19690
|
}
|
|
19677
19691
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import * as React$1 from "react";
|
|
2
2
|
import React from "react";
|
|
3
|
+
import { Body } from "@react-email/body";
|
|
4
|
+
import { Button } from "@react-email/button";
|
|
5
|
+
import { CodeBlock } from "@react-email/code-block";
|
|
6
|
+
import { CodeInline } from "@react-email/code-inline";
|
|
7
|
+
import { Container } from "@react-email/container";
|
|
8
|
+
import { Heading } from "@react-email/heading";
|
|
9
|
+
import { Hr } from "@react-email/hr";
|
|
10
|
+
import { Img } from "@react-email/img";
|
|
11
|
+
import { Link } from "@react-email/link";
|
|
12
|
+
import { Preview } from "@react-email/preview";
|
|
3
13
|
import { compile } from "tailwindcss";
|
|
4
14
|
import { jsx } from "react/jsx-runtime";
|
|
5
15
|
|
|
@@ -1077,9 +1087,7 @@ function sourceFragment({ source, line, column, baseLine, baseColumn }, extraLin
|
|
|
1077
1087
|
function processLines(start, end) {
|
|
1078
1088
|
return lines.slice(start, end).map((line$1, idx) => String(start + idx + 1).padStart(maxNumLength) + " |" + line$1).join("\n");
|
|
1079
1089
|
}
|
|
1080
|
-
const
|
|
1081
|
-
const precolumns = " ".repeat(Math.max(baseColumn - 1, 0));
|
|
1082
|
-
const lines = (prelines + precolumns + source).split(/\r\n?|\n|\f/);
|
|
1090
|
+
const lines = ("\n".repeat(Math.max(baseLine - 1, 0)) + " ".repeat(Math.max(baseColumn - 1, 0)) + source).split(/\r\n?|\n|\f/);
|
|
1083
1091
|
const startLine = Math.max(1, line - extraLines) - 1;
|
|
1084
1092
|
const endLine = Math.min(line + extraLines, lines.length + 1);
|
|
1085
1093
|
const maxNumLength = Math.max(4, String(endLine).length) + 1;
|
|
@@ -1362,8 +1370,7 @@ function createParser(config) {
|
|
|
1362
1370
|
if (typeof onComment === "function") parser.forEachToken((type, start, end) => {
|
|
1363
1371
|
if (type === Comment) {
|
|
1364
1372
|
const loc = parser.getLocation(start, end);
|
|
1365
|
-
|
|
1366
|
-
onComment(value, loc);
|
|
1373
|
+
onComment(cmpStr(source, end - 2, end, "*/") ? source.slice(start + 2, end - 2) : source.slice(start + 2, end), loc);
|
|
1367
1374
|
}
|
|
1368
1375
|
});
|
|
1369
1376
|
const ast = parser.context[context].call(parser, options);
|
|
@@ -4798,8 +4805,7 @@ function processStructure(name$49, nodeType) {
|
|
|
4798
4805
|
const docs = { type: "\"" + name$49 + "\"" };
|
|
4799
4806
|
for (const key in structure$49) {
|
|
4800
4807
|
if (hasOwnProperty$1.call(structure$49, key) === false) continue;
|
|
4801
|
-
|
|
4802
|
-
docs[key] = genTypesList(fieldTypes, name$49 + "." + key);
|
|
4808
|
+
docs[key] = genTypesList(fields[key] = Array.isArray(structure$49[key]) ? structure$49[key].slice() : [structure$49[key]], name$49 + "." + key);
|
|
4803
4809
|
}
|
|
4804
4810
|
return {
|
|
4805
4811
|
docs,
|
|
@@ -19088,9 +19094,7 @@ function populateParentsForNodeTree(node) {
|
|
|
19088
19094
|
//#endregion
|
|
19089
19095
|
//#region src/utils/css/resolve-all-css-variables.ts
|
|
19090
19096
|
function doSelectorsIntersect(first, second) {
|
|
19091
|
-
|
|
19092
|
-
const secondStringified = generate(second);
|
|
19093
|
-
if (firstStringified === secondStringified) return true;
|
|
19097
|
+
if (generate(first) === generate(second)) return true;
|
|
19094
19098
|
let hasSomeUniversal = false;
|
|
19095
19099
|
const walker = (node) => {
|
|
19096
19100
|
if (hasSomeUniversal) return;
|
|
@@ -19102,12 +19106,6 @@ function doSelectorsIntersect(first, second) {
|
|
|
19102
19106
|
if (hasSomeUniversal) return true;
|
|
19103
19107
|
return false;
|
|
19104
19108
|
}
|
|
19105
|
-
function removeAndRepeatIfEmptyRecursively(node) {
|
|
19106
|
-
if (node.parent) if (node.containedIn && node.containingItem) {
|
|
19107
|
-
node.containedIn.remove(node.containingItem);
|
|
19108
|
-
if (node.containedIn.isEmpty) removeAndRepeatIfEmptyRecursively(node.parent);
|
|
19109
|
-
} else removeAndRepeatIfEmptyRecursively(node.parent);
|
|
19110
|
-
}
|
|
19111
19109
|
function someParent(node, predicate) {
|
|
19112
19110
|
if (node.parent) {
|
|
19113
19111
|
if (predicate(node.parent)) return true;
|
|
@@ -19125,11 +19123,8 @@ function resolveAllCssVariables(node) {
|
|
|
19125
19123
|
if (someParent(declaration, (ancestor) => ancestor.type === "Atrule" && ancestor.name === "layer" && ancestor.prelude !== null && generate(ancestor.prelude).includes("properties"))) return;
|
|
19126
19124
|
if (/--[\S]+/.test(declaration.property)) variableDefinitions.add({
|
|
19127
19125
|
declaration,
|
|
19128
|
-
variableName:
|
|
19129
|
-
definition: generate(declaration.value)
|
|
19130
|
-
remove() {
|
|
19131
|
-
removeAndRepeatIfEmptyRecursively(declaration);
|
|
19132
|
-
}
|
|
19126
|
+
variableName: declaration.property,
|
|
19127
|
+
definition: generate(declaration.value)
|
|
19133
19128
|
});
|
|
19134
19129
|
else {
|
|
19135
19130
|
function parseVariableUsesFrom(node$1) {
|
|
@@ -19146,10 +19141,7 @@ function resolveAllCssVariables(node) {
|
|
|
19146
19141
|
variableName: name$49,
|
|
19147
19142
|
raw: generate(funcNode)
|
|
19148
19143
|
});
|
|
19149
|
-
if (fallback?.includes("var(")) {
|
|
19150
|
-
const parsedFallback = parse(fallback, { context: "value" });
|
|
19151
|
-
parseVariableUsesFrom(parsedFallback);
|
|
19152
|
-
}
|
|
19144
|
+
if (fallback?.includes("var(")) parseVariableUsesFrom(parse(fallback, { context: "value" }));
|
|
19153
19145
|
}
|
|
19154
19146
|
}
|
|
19155
19147
|
});
|
|
@@ -19175,7 +19167,6 @@ function resolveAllCssVariables(node) {
|
|
|
19175
19167
|
}
|
|
19176
19168
|
if (!hasReplaced && use.fallback) use.declaration.value = parse(generate(use.declaration.value).replaceAll(use.raw, use.fallback), { context: "value" });
|
|
19177
19169
|
}
|
|
19178
|
-
for (const definition of variableDefinitions) definition.remove();
|
|
19179
19170
|
}
|
|
19180
19171
|
|
|
19181
19172
|
//#endregion
|
|
@@ -19464,48 +19455,26 @@ function sanitizeDeclarations(nodeContainingDeclarations) {
|
|
|
19464
19455
|
enter(hash, hashParentListItem) {
|
|
19465
19456
|
const hex = hash.value.trim();
|
|
19466
19457
|
if (hex.length === 3) {
|
|
19467
|
-
|
|
19468
|
-
const g$1 = Number.parseInt(hex.charAt(1) + hex.charAt(1), 16);
|
|
19469
|
-
const b$1 = Number.parseInt(hex.charAt(2) + hex.charAt(2), 16);
|
|
19470
|
-
hashParentListItem.data = parse(`rgb(${r$1},${g$1},${b$1})`, { context: "value" });
|
|
19458
|
+
hashParentListItem.data = parse(`rgb(${Number.parseInt(hex.charAt(0) + hex.charAt(0), 16)},${Number.parseInt(hex.charAt(1) + hex.charAt(1), 16)},${Number.parseInt(hex.charAt(2) + hex.charAt(2), 16)})`, { context: "value" });
|
|
19471
19459
|
return;
|
|
19472
19460
|
}
|
|
19473
19461
|
if (hex.length === 4) {
|
|
19474
|
-
|
|
19475
|
-
const g$1 = Number.parseInt(hex.charAt(1) + hex.charAt(1), 16);
|
|
19476
|
-
const b$1 = Number.parseInt(hex.charAt(2) + hex.charAt(2), 16);
|
|
19477
|
-
const a$1 = Number.parseInt(hex.charAt(3) + hex.charAt(3), 16) / 255;
|
|
19478
|
-
hashParentListItem.data = parse(`rgb(${r$1},${g$1},${b$1},${a$1.toFixed(1)})`, { context: "value" });
|
|
19462
|
+
hashParentListItem.data = parse(`rgb(${Number.parseInt(hex.charAt(0) + hex.charAt(0), 16)},${Number.parseInt(hex.charAt(1) + hex.charAt(1), 16)},${Number.parseInt(hex.charAt(2) + hex.charAt(2), 16)},${(Number.parseInt(hex.charAt(3) + hex.charAt(3), 16) / 255).toFixed(1)})`, { context: "value" });
|
|
19479
19463
|
return;
|
|
19480
19464
|
}
|
|
19481
19465
|
if (hex.length === 5) {
|
|
19482
|
-
|
|
19483
|
-
const g$1 = Number.parseInt(hex.charAt(2) + hex.charAt(2), 16);
|
|
19484
|
-
const b$1 = Number.parseInt(hex.charAt(3) + hex.charAt(3), 16);
|
|
19485
|
-
const a$1 = Number.parseInt(hex.charAt(4) + hex.charAt(4), 16) / 255;
|
|
19486
|
-
hashParentListItem.data = parse(`rgb(${r$1},${g$1},${b$1},${a$1.toFixed(1)})`, { context: "value" });
|
|
19466
|
+
hashParentListItem.data = parse(`rgb(${Number.parseInt(hex.slice(0, 2), 16)},${Number.parseInt(hex.charAt(2) + hex.charAt(2), 16)},${Number.parseInt(hex.charAt(3) + hex.charAt(3), 16)},${(Number.parseInt(hex.charAt(4) + hex.charAt(4), 16) / 255).toFixed(1)})`, { context: "value" });
|
|
19487
19467
|
return;
|
|
19488
19468
|
}
|
|
19489
19469
|
if (hex.length === 6) {
|
|
19490
|
-
|
|
19491
|
-
const g$1 = Number.parseInt(hex.slice(2, 4), 16);
|
|
19492
|
-
const b$1 = Number.parseInt(hex.slice(4, 6), 16);
|
|
19493
|
-
hashParentListItem.data = parse(`rgb(${r$1},${g$1},${b$1})`, { context: "value" });
|
|
19470
|
+
hashParentListItem.data = parse(`rgb(${Number.parseInt(hex.slice(0, 2), 16)},${Number.parseInt(hex.slice(2, 4), 16)},${Number.parseInt(hex.slice(4, 6), 16)})`, { context: "value" });
|
|
19494
19471
|
return;
|
|
19495
19472
|
}
|
|
19496
19473
|
if (hex.length === 7) {
|
|
19497
|
-
|
|
19498
|
-
const g$1 = Number.parseInt(hex.slice(2, 4), 16);
|
|
19499
|
-
const b$1 = Number.parseInt(hex.slice(4, 6), 16);
|
|
19500
|
-
const a$1 = Number.parseInt(hex.charAt(6) + hex.charAt(6), 16) / 255;
|
|
19501
|
-
hashParentListItem.data = parse(`rgb(${r$1},${g$1},${b$1},${a$1.toFixed(1)})`, { context: "value" });
|
|
19474
|
+
hashParentListItem.data = parse(`rgb(${Number.parseInt(hex.slice(0, 2), 16)},${Number.parseInt(hex.slice(2, 4), 16)},${Number.parseInt(hex.slice(4, 6), 16)},${(Number.parseInt(hex.charAt(6) + hex.charAt(6), 16) / 255).toFixed(1)})`, { context: "value" });
|
|
19502
19475
|
return;
|
|
19503
19476
|
}
|
|
19504
|
-
|
|
19505
|
-
const g = Number.parseInt(hex.slice(2, 4), 16);
|
|
19506
|
-
const b = Number.parseInt(hex.slice(4, 6), 16);
|
|
19507
|
-
const a = Number.parseInt(hex.slice(6, 8), 16) / 255;
|
|
19508
|
-
hashParentListItem.data = parse(`rgb(${r},${g},${b},${a.toFixed(1)})`, { context: "value" });
|
|
19477
|
+
hashParentListItem.data = parse(`rgb(${Number.parseInt(hex.slice(0, 2), 16)},${Number.parseInt(hex.slice(2, 4), 16)},${Number.parseInt(hex.slice(4, 6), 16)},${(Number.parseInt(hex.slice(6, 8), 16) / 255).toFixed(1)})`, { context: "value" });
|
|
19509
19478
|
}
|
|
19510
19479
|
});
|
|
19511
19480
|
walk(declaration, {
|
|
@@ -19592,10 +19561,7 @@ function sanitizeNonInlinableRules(node) {
|
|
|
19592
19561
|
enter(rule) {
|
|
19593
19562
|
if (!isRuleInlinable(rule)) {
|
|
19594
19563
|
walk(rule.prelude, (node$1) => {
|
|
19595
|
-
if (node$1.type === "ClassSelector")
|
|
19596
|
-
const unescapedClassName = decode$1(node$1.name);
|
|
19597
|
-
node$1.name = sanitizeClassName(unescapedClassName);
|
|
19598
|
-
}
|
|
19564
|
+
if (node$1.type === "ClassSelector") node$1.name = sanitizeClassName(decode$1(node$1.name));
|
|
19599
19565
|
});
|
|
19600
19566
|
walk(rule, {
|
|
19601
19567
|
visit: "Declaration",
|
|
@@ -19610,8 +19576,20 @@ function sanitizeNonInlinableRules(node) {
|
|
|
19610
19576
|
|
|
19611
19577
|
//#endregion
|
|
19612
19578
|
//#region src/utils/react/is-component.ts
|
|
19579
|
+
const componentsToTreatAsElements = [
|
|
19580
|
+
Body,
|
|
19581
|
+
Button,
|
|
19582
|
+
CodeBlock,
|
|
19583
|
+
CodeInline,
|
|
19584
|
+
Container,
|
|
19585
|
+
Heading,
|
|
19586
|
+
Hr,
|
|
19587
|
+
Img,
|
|
19588
|
+
Link,
|
|
19589
|
+
Preview
|
|
19590
|
+
];
|
|
19613
19591
|
const isComponent = (element) => {
|
|
19614
|
-
return (typeof element.type === "function" || element.type.render !== void 0) && element.type
|
|
19592
|
+
return (typeof element.type === "function" || element.type.render !== void 0) && !componentsToTreatAsElements.includes(element.type);
|
|
19615
19593
|
};
|
|
19616
19594
|
|
|
19617
19595
|
//#endregion
|
|
@@ -19634,10 +19612,7 @@ function mapReactTree(value, process) {
|
|
|
19634
19612
|
const newProps = { ...node.props };
|
|
19635
19613
|
if (node.props.children && !isComponent(node)) newProps.children = mapReactTree(node.props.children, process);
|
|
19636
19614
|
const processed = process(React.cloneElement(node, newProps, newProps.children));
|
|
19637
|
-
if (React.isValidElement(processed) && isComponent(processed))
|
|
19638
|
-
const rendered = (typeof processed.type === "object" ? processed.type.render : processed.type)(processed.props);
|
|
19639
|
-
return mapReactTree(rendered, process);
|
|
19640
|
-
}
|
|
19615
|
+
if (React.isValidElement(processed) && isComponent(processed)) return mapReactTree((typeof processed.type === "object" ? processed.type.render : processed.type)(processed.props), process);
|
|
19641
19616
|
return processed;
|
|
19642
19617
|
}
|
|
19643
19618
|
return process(node);
|
|
@@ -19652,8 +19627,8 @@ const fromDashCaseToCamelCase = (text) => {
|
|
|
19652
19627
|
};
|
|
19653
19628
|
|
|
19654
19629
|
//#endregion
|
|
19655
|
-
//#region src/utils/compatibility/
|
|
19656
|
-
function
|
|
19630
|
+
//#region src/utils/compatibility/get-react-property.ts
|
|
19631
|
+
function getReactProperty(prop) {
|
|
19657
19632
|
const modifiedProp = prop.toLowerCase();
|
|
19658
19633
|
if (modifiedProp.startsWith("--")) return modifiedProp;
|
|
19659
19634
|
if (modifiedProp.startsWith("-ms-")) return fromDashCaseToCamelCase(modifiedProp.slice(1));
|
|
@@ -19664,12 +19639,41 @@ function convertCssPropertyToReactProperty(prop) {
|
|
|
19664
19639
|
//#region src/utils/css/make-inline-styles-for.ts
|
|
19665
19640
|
function makeInlineStylesFor(inlinableRules) {
|
|
19666
19641
|
const styles = {};
|
|
19642
|
+
const localVariableDeclarations = /* @__PURE__ */ new Set();
|
|
19667
19643
|
for (const rule of inlinableRules) walk(rule, {
|
|
19668
19644
|
visit: "Declaration",
|
|
19669
19645
|
enter(declaration) {
|
|
19670
|
-
|
|
19646
|
+
if (declaration.property.startsWith("--")) localVariableDeclarations.add(declaration);
|
|
19671
19647
|
}
|
|
19672
19648
|
});
|
|
19649
|
+
for (const rule of inlinableRules) {
|
|
19650
|
+
walk(rule, {
|
|
19651
|
+
visit: "Function",
|
|
19652
|
+
enter(func, funcParentListItem) {
|
|
19653
|
+
if (func.name === "var") {
|
|
19654
|
+
let variableName;
|
|
19655
|
+
walk(func, {
|
|
19656
|
+
visit: "Identifier",
|
|
19657
|
+
enter(identifier) {
|
|
19658
|
+
variableName = identifier.name;
|
|
19659
|
+
return this.break;
|
|
19660
|
+
}
|
|
19661
|
+
});
|
|
19662
|
+
if (variableName) {
|
|
19663
|
+
const definition = Array.from(localVariableDeclarations).find((declaration) => variableName === declaration.property);
|
|
19664
|
+
if (definition) funcParentListItem.data = definition.value;
|
|
19665
|
+
}
|
|
19666
|
+
}
|
|
19667
|
+
}
|
|
19668
|
+
});
|
|
19669
|
+
walk(rule, {
|
|
19670
|
+
visit: "Declaration",
|
|
19671
|
+
enter(declaration) {
|
|
19672
|
+
if (declaration.property.startsWith("--")) return;
|
|
19673
|
+
styles[getReactProperty(declaration.property)] = generate(declaration.value) + (declaration.important ? "!important" : "");
|
|
19674
|
+
}
|
|
19675
|
+
});
|
|
19676
|
+
}
|
|
19673
19677
|
return styles;
|
|
19674
19678
|
}
|
|
19675
19679
|
|