@samva/markup 0.9.0 → 0.10.0
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/AGENTS.md +48 -40
- package/CHANGELOG.md +345 -0
- package/README.md +6 -6
- package/dist/{brand-B-0bN_Ir.d.ts → assets-BIsyMQ92.d.ts} +41 -11
- package/dist/{email/brand.js → brand-C0MKTwmX.js} +64 -4
- package/dist/{theme-css.d.ts → brand.d.ts} +12 -3
- package/dist/brand.js +4 -0
- package/dist/compiler.d.ts +231 -11
- package/dist/compiler.js +1312 -13
- package/dist/components-BZCqegS8.js +1864 -0
- package/dist/diagnostic-model-DJtqbETd.js +38 -0
- package/dist/diagnostic-model-DxthUZBT.d.ts +31 -0
- package/dist/{email/diagnostics.js → diagnostics-CnKFefKz.js} +2 -2
- package/dist/diagnostics.d.ts +406 -27
- package/dist/diagnostics.js +402 -34
- package/dist/edit.d.ts +234 -0
- package/dist/{channel-edit.js → edit.js} +341 -3
- package/dist/email/jsx-dev-runtime.d.ts +1 -1
- package/dist/email/jsx-dev-runtime.js +1 -2
- package/dist/email/jsx-runtime.d.ts +1 -1
- package/dist/email/jsx-runtime.js +1 -85
- package/dist/{email/components.d.ts → email.d.ts} +2 -2
- package/dist/email.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{cascade-t6kxlgEI.js → ir-CLhlklKV.js} +8 -4
- package/dist/jsx-runtime-CBlexoeR.js +98 -0
- package/dist/{elements-cqldpaJt.d.ts → jsx-runtime-ylIOnaSf.d.ts} +74 -74
- package/dist/{profile-BH-OtdDA.js → profile-pWGtWZXF.js} +153 -20
- package/dist/render-BPonDpCl.d.ts +539 -0
- package/dist/{email/render.js → render-BQmfh94k.js} +102 -8
- package/dist/render.d.ts +35 -0
- package/dist/render.js +49 -0
- package/dist/sms.d.ts +1 -1
- package/dist/sms.js +1 -1
- package/dist/{template-_QE_rQND.d.ts → template-DMPwxMSq.d.ts} +2 -2
- package/dist/{template.js → template-zLUjcwfF.js} +2 -2
- package/dist/{theme-css-hFqcPSar.js → theme-css-JtRCm1fb.js} +2 -2
- package/dist/whatsapp.d.ts +1 -1
- package/dist/whatsapp.js +1 -1
- package/generated/contract.json +16 -10
- package/generated/reference.md +17 -10
- package/package.json +36 -119
- package/samva-brand.d.ts +4 -4
- package/skills/sml/SKILL.md +2 -2
- package/dist/assets-C5duwTya.d.ts +0 -40
- package/dist/channel-edit.d.ts +0 -121
- package/dist/channel-specs-B6M_HlaV.js +0 -29
- package/dist/compatibility-DbISoFIq.js +0 -589
- package/dist/css-BVQKICKC.d.ts +0 -109
- package/dist/diagnostic-codes.d.ts +0 -403
- package/dist/diagnostic-codes.js +0 -399
- package/dist/email/assets.d.ts +0 -2
- package/dist/email/assets.js +0 -63
- package/dist/email/brand-footer.d.ts +0 -34
- package/dist/email/brand-footer.js +0 -63
- package/dist/email/brand.d.ts +0 -2
- package/dist/email/components.js +0 -275
- package/dist/email/diagnostics.d.ts +0 -2
- package/dist/email/elements.d.ts +0 -2
- package/dist/email/elements.js +0 -299
- package/dist/email/html.d.ts +0 -2
- package/dist/email/html.js +0 -321
- package/dist/email/render.d.ts +0 -40
- package/dist/email/text.d.ts +0 -7
- package/dist/email/text.js +0 -100
- package/dist/html-BJepOwZ4.d.ts +0 -56
- package/dist/ir-aaqNE987.d.ts +0 -252
- package/dist/ir.d.ts +0 -2
- package/dist/ir.js +0 -7
- package/dist/preview-Ekdg1dXG.d.ts +0 -100
- package/dist/preview.d.ts +0 -2
- package/dist/preview.js +0 -160
- package/dist/render-ir.d.ts +0 -19
- package/dist/render-ir.js +0 -826
- package/dist/sms-segments.d.ts +0 -13
- package/dist/sms-segments.js +0 -46
- package/dist/source-edit.d.ts +0 -116
- package/dist/source-edit.js +0 -343
- package/dist/source-locations.d.ts +0 -2
- package/dist/source-locations.js +0 -16
- package/dist/static.d.ts +0 -57
- package/dist/static.js +0 -69
- package/dist/tailwind-CMYpZf1v.js +0 -614
- package/dist/template.d.ts +0 -2
- package/dist/theme-css.js +0 -2
- package/dist/theme-imports-lvBw3AD1.js +0 -109
- package/dist/transform-Ct2OMkFN.d.ts +0 -153
package/dist/compiler.js
CHANGED
|
@@ -1,13 +1,1312 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { a as
|
|
6
|
-
import {
|
|
7
|
-
import { a as
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
1
|
+
import { n as isObject } from "./guards-eV1qLbf2.js";
|
|
2
|
+
import { n as TEMPLATE_NAME_PATTERN } from "./template-zLUjcwfF.js";
|
|
3
|
+
import { k as renderIr } from "./components-BZCqegS8.js";
|
|
4
|
+
import { c as parseBrandCss, d as formatColor, f as parseColor, i as brandTailwindCss, u as downlevelColors } from "./theme-css-JtRCm1fb.js";
|
|
5
|
+
import { a as downlevelMediaQuery, c as renderHeadCss, i as matchesSelector, l as resolveVariables, n as applyStylesheet, o as finalizeValue, r as classListOf, s as foldCalc, u as unquote } from "./ir-CLhlklKV.js";
|
|
6
|
+
import { i as lineColumn, t as buildLineMap } from "./diagnostic-model-DJtqbETd.js";
|
|
7
|
+
import { a as lowerProject, d as parseBrandSpecifier, f as projectDirectory, i as completed, l as Findings, m as resolveThemeImports, n as introducedProfileErrors, p as resolveFromDirectory, r as loadProject, t as checkStaticProfile, u as BRAND_SPECIFIER } from "./profile-pWGtWZXF.js";
|
|
8
|
+
import { c as assetEntry, d as isAssetPath, i as brandComponents, l as assetUrl, o as withoutUnsubscribeRow, t as BRAND_COMPONENT_CLASSES, u as checkAssetBase } from "./brand-C0MKTwmX.js";
|
|
9
|
+
import { t as EmailCompileError } from "./diagnostics-CnKFefKz.js";
|
|
10
|
+
import { n as compileEmail, r as renderEmailContent } from "./render-BQmfh94k.js";
|
|
11
|
+
import { caniemail, parseHtml, rawData } from "caniemail";
|
|
12
|
+
import { generate, ident, parse, walk } from "css-tree";
|
|
13
|
+
import { parse as parse$1 } from "@babel/parser";
|
|
14
|
+
import { compile } from "tailwindcss";
|
|
15
|
+
//#region src/email/compatibility-assessment.ts
|
|
16
|
+
const VERIFIED_VALUES = /^(?:left|right|center|justify)$/i;
|
|
17
|
+
const SIMPLE_COLOR = /^(?:#[\da-f]{3,8}|rgba?\([^()]+\)|transparent|white|black)$/i;
|
|
18
|
+
/**
|
|
19
|
+
* A feature matrix establishes support, not the effect on a particular message.
|
|
20
|
+
* These rules interpret the pinned caniemail@2.0.2 limitations using emitted
|
|
21
|
+
* values. Unresolved layout, fallback and client-account behavior stays unverified.
|
|
22
|
+
*/
|
|
23
|
+
const assessCompatibility = (title, client, support, context, blocking) => {
|
|
24
|
+
const result = (assessment, heading, explanation) => ({
|
|
25
|
+
assessment,
|
|
26
|
+
title: heading,
|
|
27
|
+
explanation
|
|
28
|
+
});
|
|
29
|
+
if (client === "outlook.windows" && support === "partial" && (title === "display" || title === "display:none") && context.hiddenContentOffsets.length > 0) return result("risk", "Hidden content becomes visible in classic Outlook", "Classic Outlook ignores display:none on images and does not inherit it onto nested tables. The emitted inline styles contain hidden content without a resolved hiding fallback. Add a supported hiding fallback before publishing.");
|
|
30
|
+
if (blocking) return result("risk", `${title} is unavailable in a target client`, "This construct is required for message content, structure or navigation. Replace it with a supported construct before publishing.");
|
|
31
|
+
const explained = context.explanation(title, client, support);
|
|
32
|
+
if (explained !== void 0) return result(title.startsWith("system-ui,") ? "degradation" : "not-applicable", title.startsWith("system-ui,") ? "A fallback font will be used" : `${title}: limitation avoided`, explained);
|
|
33
|
+
const declarations = (property) => context.declarations(property);
|
|
34
|
+
const every = (property, predicate) => {
|
|
35
|
+
const values = declarations(property);
|
|
36
|
+
return context.complete && values.length > 0 && values.every(({ value }) => predicate(value));
|
|
37
|
+
};
|
|
38
|
+
const attributesAvoid = (attribute, unsupportedElement) => {
|
|
39
|
+
const values = context.attributes(attribute);
|
|
40
|
+
return values.length > 0 && values.every(({ element }) => element !== unsupportedElement);
|
|
41
|
+
};
|
|
42
|
+
if (title === "font-size" && support === "partial" && ["outlook.windows", "yahoo.desktop-webmail"].includes(client) && declarations("font-size").some(({ value }) => /\d(?:\.\d+)?rem\b/i.test(value))) return result("risk", "Text sizes use unsupported rem units", "These clients cannot apply the emitted rem font sizes. Use pixel sizes to preserve the intended text size.");
|
|
43
|
+
if (title === "target attribute" && context.attributes("target").some(({ value }) => value !== "_blank")) return result("risk", "Links cannot keep the requested window target", "These clients open links in a new window regardless of the requested target. Use a new-window target or remove the dependency on another browsing context.");
|
|
44
|
+
if (title.startsWith("system-ui,") && declarations("font-family").some(({ value }) => !/(?:^|,)\s*(?:sans-serif|serif|monospace)\s*$/i.test(value))) return result("risk", "An unsupported font stack has no generic fallback", "Declare a generic fallback so the client has an explicit font choice when the requested system font is unavailable.");
|
|
45
|
+
if (title === "border-radius" && support !== "partial") return result("degradation", "Corners may appear square", "CSS corner rounding is unavailable in this client. Uncovered elements appear square; a separate VML shape can retain rounding. This finding does not establish a content or navigation failure.");
|
|
46
|
+
if (title === "border-radius" && client === "yahoo.desktop-webmail" && support === "partial") return result("degradation", "Corner shapes may differ", "This client does not support elliptical slash syntax. Review the recorded values if that corner shape is part of the intended design.");
|
|
47
|
+
if (title === "background") {
|
|
48
|
+
const values = [...declarations("background"), ...declarations("background-color")];
|
|
49
|
+
if (context.complete && values.length > 0 && values.every(({ value }) => SIMPLE_COLOR.test(value)) && declarations("background-image").every(({ value }) => value.toLowerCase() === "none")) return result("not-applicable", "Backgrounds use supported color values", "The emitted backgrounds use simple colors. The cited multiple-background and background-size shorthand limitations do not apply.");
|
|
50
|
+
}
|
|
51
|
+
if (title === "dir attribute" && client === "outlook.windows" && attributesAvoid("dir", "a")) return result("not-applicable", "Direction is set outside links", "The cited direction bug affects anchor elements. No emitted anchor carries a dir attribute.");
|
|
52
|
+
if (title === "lang attribute" && client === "yahoo.desktop-webmail" && attributesAvoid("lang", "td")) return result("not-applicable", "Language is set outside table cells", "The cited language-attribute limitation affects table cells. No emitted td carries a lang attribute.");
|
|
53
|
+
if (title === "role attribute" && client === "yahoo.desktop-webmail" && context.attributes("role").length > 0 && context.attributes("role").every(({ element }) => element === "table")) return result("not-applicable", "Roles are applied to supported tables", "Every emitted role attribute is on a table, matching this client's supported element scope.");
|
|
54
|
+
if (title === "text-align" && support === "partial" && every("text-align", (value) => VERIFIED_VALUES.test(value))) return result("not-applicable", "Text uses supported alignment values", "The emitted alignment values do not use match-parent or flow-relative start/end values.");
|
|
55
|
+
if (title === "font-weight" && support === "partial") {
|
|
56
|
+
const pattern = client === "outlook.windows" ? /^(?:normal|bold|400|700)$/i : /^(?:normal|bold|[1-9]00)$/i;
|
|
57
|
+
if (every("font-weight", (value) => pattern.test(value))) return result("not-applicable", "Font weights avoid the numeric limitation", "The emitted weights use values preserved by this client's pinned numeric-weight rule.");
|
|
58
|
+
return result("degradation", "Font weight may be approximated", "This client may substitute a supported weight. Text remains present, but its emphasis can look different.");
|
|
59
|
+
}
|
|
60
|
+
if (title === "outline" && every("outline", (value) => value === "none" || value === "0")) return result("unverified", "Image outlines need a client check", "The emitted styles remove outlines. The matrix cannot establish whether this client adds its own link or image outline.");
|
|
61
|
+
if (title === "width attribute" && client === "outlook.windows" && context.attributes(title.split(" ")[0]).some(({ value, element }) => element === "img" && value.includes("%"))) return result("risk", "Percentage image dimensions use the wrong reference size", "Classic Outlook sizes percentage image attributes against the image file rather than its parent. Use fixed image dimensions with an appropriate responsive fallback.");
|
|
62
|
+
if (title === "overflow" && declarations("overflow").some(({ value }) => /^(?:auto|scroll)$/i.test(value))) return result("risk", "Scrollable content may be inaccessible", "These clients cannot reliably expose content hidden behind a scrolling container. Keep required email content visible without scrolling inside an element.");
|
|
63
|
+
return result("unverified", {
|
|
64
|
+
"<body> element": "Body styling needs a client check",
|
|
65
|
+
border: "Borders need an Outlook check",
|
|
66
|
+
"color-scheme meta tag": "Dark appearance needs a client check",
|
|
67
|
+
display: "Display behavior needs a client check",
|
|
68
|
+
"display:none": "Hidden content needs an Outlook check",
|
|
69
|
+
"height attribute": "Image sizing needs a high-DPI Outlook check",
|
|
70
|
+
"height property": "Element heights need a client check",
|
|
71
|
+
"line-height": "Line spacing needs an Outlook check",
|
|
72
|
+
margin: "Outer spacing needs a client check",
|
|
73
|
+
"max-height property": "Height limits need an Outlook check",
|
|
74
|
+
"max-width": "Width limits need a client check",
|
|
75
|
+
"@media": "Conditional styles need a client check",
|
|
76
|
+
opacity: "Transparent content needs an Outlook check",
|
|
77
|
+
overflow: "Clipped content needs a client check",
|
|
78
|
+
"overflow-wrap": "Long text wrapping needs a client check",
|
|
79
|
+
padding: "Cell spacing needs an Outlook check",
|
|
80
|
+
"<style> element": "Retained styles need a client check",
|
|
81
|
+
"text-decoration": "Link decoration needs a client check",
|
|
82
|
+
"width attribute": "Image sizing needs a high-DPI Outlook check",
|
|
83
|
+
"width property": "Element widths need an Outlook check",
|
|
84
|
+
"word-break": "Word breaking needs a client check"
|
|
85
|
+
}[title] ?? `${title} needs a client check`, "The feature matrix identifies a support difference but does not establish its effect on this message. Check the affected fixtures in the listed clients before relying on this behavior; no automatic source change is justified by this observation alone.");
|
|
86
|
+
};
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/email/compatibility-context.ts
|
|
89
|
+
const NON_HIDING_VALUES = {
|
|
90
|
+
"mso-hide": /^none$/,
|
|
91
|
+
visibility: /^visible$/,
|
|
92
|
+
opacity: /^(?:1(?:\.0+)?|100(?:\.0+)?%)$/,
|
|
93
|
+
overflow: /^visible$/,
|
|
94
|
+
"overflow-y": /^visible$/,
|
|
95
|
+
"overflow-x": /^visible$/,
|
|
96
|
+
clip: /^auto$/,
|
|
97
|
+
"clip-path": /^none$/
|
|
98
|
+
};
|
|
99
|
+
const POSITIVE_FIXED_HEIGHT = /^(?:\d+(?:\.\d+)?|\.\d+)(?:px|pt|pc|in|cm|mm)$/;
|
|
100
|
+
/** Evidence from actual declarations and elements, never a text match in email content. */
|
|
101
|
+
const compatibilityContext = (html, css) => {
|
|
102
|
+
const declarations = /* @__PURE__ */ new Map();
|
|
103
|
+
const attributes = /* @__PURE__ */ new Map();
|
|
104
|
+
const elements = /* @__PURE__ */ new Map();
|
|
105
|
+
let complete = true;
|
|
106
|
+
let unresolvedStyles = false;
|
|
107
|
+
const hiddenContentOffsets = [];
|
|
108
|
+
const addCss = (source, context, offset, element) => {
|
|
109
|
+
const inline = /* @__PURE__ */ new Map();
|
|
110
|
+
if (context === "stylesheet" && source.trim() !== "") unresolvedStyles = true;
|
|
111
|
+
try {
|
|
112
|
+
const ast = parse(source, { context });
|
|
113
|
+
walk(ast, (node) => {
|
|
114
|
+
if (node.type === "Raw") complete = false;
|
|
115
|
+
if (node.type !== "Declaration") return;
|
|
116
|
+
const property = node.property.toLowerCase();
|
|
117
|
+
const entries = declarations.get(property) ?? [];
|
|
118
|
+
const value = generate(node.value);
|
|
119
|
+
entries.push({
|
|
120
|
+
value,
|
|
121
|
+
offset,
|
|
122
|
+
element
|
|
123
|
+
});
|
|
124
|
+
if (!inline.get(property)?.important || node.important) inline.set(property, {
|
|
125
|
+
value: value.toLowerCase(),
|
|
126
|
+
important: Boolean(node.important)
|
|
127
|
+
});
|
|
128
|
+
declarations.set(property, entries);
|
|
129
|
+
});
|
|
130
|
+
} catch {
|
|
131
|
+
complete = false;
|
|
132
|
+
}
|
|
133
|
+
return inline;
|
|
134
|
+
};
|
|
135
|
+
const { document } = parseHtml(html);
|
|
136
|
+
const visit = (node, ancestors = []) => {
|
|
137
|
+
let descendants = ancestors;
|
|
138
|
+
if (node.type === "comment" && /\[if\b/i.test(node.data)) unresolvedStyles = true;
|
|
139
|
+
if ("attribs" in node) {
|
|
140
|
+
const offset = node.startIndex ?? void 0;
|
|
141
|
+
if (offset !== void 0) {
|
|
142
|
+
const entries = elements.get(node.name) ?? [];
|
|
143
|
+
entries.push(offset);
|
|
144
|
+
elements.set(node.name, entries);
|
|
145
|
+
}
|
|
146
|
+
for (const [name, value] of Object.entries(node.attribs)) {
|
|
147
|
+
const entries = attributes.get(name) ?? [];
|
|
148
|
+
entries.push({
|
|
149
|
+
value,
|
|
150
|
+
offset,
|
|
151
|
+
element: node.name
|
|
152
|
+
});
|
|
153
|
+
attributes.set(name, entries);
|
|
154
|
+
}
|
|
155
|
+
const styles = node.attribs.style === void 0 ? /* @__PURE__ */ new Map() : addCss(node.attribs.style, "declarationList", offset, node.name);
|
|
156
|
+
descendants = [...ancestors, {
|
|
157
|
+
offset,
|
|
158
|
+
styles
|
|
159
|
+
}];
|
|
160
|
+
const fallback = descendants.some(({ styles: candidate }) => {
|
|
161
|
+
const candidateDisplay = candidate.get("display")?.value;
|
|
162
|
+
return candidateDisplay !== void 0 && !/^(?:none|block|inline|inline-block|table|table-row|table-cell|table-row-group)$/i.test(candidateDisplay) || candidate.has("all") || Object.entries(NON_HIDING_VALUES).some(([property, neutral]) => {
|
|
163
|
+
const value = candidate.get(property)?.value;
|
|
164
|
+
return value !== void 0 && !neutral.test(value);
|
|
165
|
+
}) || ["height", "max-height"].some((property) => {
|
|
166
|
+
const value = candidate.get(property)?.value;
|
|
167
|
+
return value !== void 0 && value !== (property === "height" ? "auto" : "none") && !(POSITIVE_FIXED_HEIGHT.test(value) && Number.parseFloat(value) > 0);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
const hiddenAncestor = ancestors.find(({ styles: candidate }) => candidate.get("display")?.value === "none");
|
|
171
|
+
const display = styles.get("display")?.value;
|
|
172
|
+
if (!fallback && node.name === "img" && display === "none" && hiddenAncestor === void 0 && offset !== void 0) hiddenContentOffsets.push(offset);
|
|
173
|
+
if (!fallback && node.name === "table" && hiddenAncestor !== void 0 && display === void 0 && hiddenAncestor.offset !== void 0) hiddenContentOffsets.push(hiddenAncestor.offset);
|
|
174
|
+
if (node.name === "style") {
|
|
175
|
+
for (const child of node.children) if (child.type === "text") addCss(child.data, "stylesheet");
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if ("children" in node) for (const child of node.children) visit(child, descendants);
|
|
179
|
+
};
|
|
180
|
+
for (const child of document.children) visit(child);
|
|
181
|
+
if (css !== void 0) addCss(css, "stylesheet");
|
|
182
|
+
const everyValue = (property, predicate) => {
|
|
183
|
+
const entries = declarations.get(property);
|
|
184
|
+
return complete && entries !== void 0 && entries.length > 0 && entries.every(({ value }) => predicate(value));
|
|
185
|
+
};
|
|
186
|
+
return {
|
|
187
|
+
/** Known hidden-content failures; unresolved cascade or fallback evidence cannot block. */
|
|
188
|
+
get hiddenContentOffsets() {
|
|
189
|
+
return complete && !unresolvedStyles ? [...new Set(hiddenContentOffsets)] : [];
|
|
190
|
+
},
|
|
191
|
+
/** Incomplete CSS cannot prove that every occurrence avoids a limitation. */
|
|
192
|
+
get complete() {
|
|
193
|
+
return complete;
|
|
194
|
+
},
|
|
195
|
+
declarations(property) {
|
|
196
|
+
return declarations.get(property) ?? [];
|
|
197
|
+
},
|
|
198
|
+
attributes(name) {
|
|
199
|
+
return attributes.get(name) ?? [];
|
|
200
|
+
},
|
|
201
|
+
/** Bounded exceptions to caniemail@2.0.2's feature-wide matrix, tied to its client rules. */
|
|
202
|
+
explanation(title, client, support) {
|
|
203
|
+
if (title === "font-size" && support === "partial" && ["outlook.windows", "yahoo.desktop-webmail"].includes(client) && everyValue("font-size", (value) => /^(?:0|(?:\d+(?:\.\d+)?|\.\d+)px)$/i.test(value))) return "All font sizes use pixels; this client's rem-unit limitation does not apply.";
|
|
204
|
+
if (title === "border-radius" && support === "partial" && client === "yahoo.desktop-webmail" && everyValue("border-radius", (value) => /^(?:0|(?:\d+(?:\.\d+)?|\.\d+)(?:px|%))(?:\s+(?:0|(?:\d+(?:\.\d+)?|\.\d+)(?:px|%))){0,3}$/i.test(value))) return "These corner radii do not use the unsupported elliptical slash syntax.";
|
|
205
|
+
if (title === "target attribute" && [
|
|
206
|
+
"gmail.desktop-webmail",
|
|
207
|
+
"gmail.ios",
|
|
208
|
+
"gmail.android",
|
|
209
|
+
"outlook.outlook-com",
|
|
210
|
+
"yahoo.desktop-webmail",
|
|
211
|
+
"outlook.windows",
|
|
212
|
+
"apple-mail.macos",
|
|
213
|
+
"apple-mail.ios"
|
|
214
|
+
].includes(client) && attributes.has("target") && attributes.get("target").every(({ value }) => value === "_blank")) return "Links already request a new window, matching the client's enforced behavior.";
|
|
215
|
+
if (title === "system-ui, ui-serif, ui-sans-serif, ui-rounded, ui-monospace" && everyValue("font-family", (value) => /(?:^|,)\s*(?:sans-serif|serif|monospace)\s*$/i.test(value))) return "Every font stack ends with a generic fallback. Font appearance can differ in this client.";
|
|
216
|
+
},
|
|
217
|
+
offsets(title) {
|
|
218
|
+
const element = /^<([a-z0-9]+)> element$/i.exec(title);
|
|
219
|
+
if (element !== null) return elements.get(element[1]) ?? [];
|
|
220
|
+
const attribute = /^([a-z-]+) attribute$/i.exec(title);
|
|
221
|
+
const entries = attribute !== null ? attributes.get(attribute[1]) : declarations.get(title.startsWith("system-ui,") ? "font-family" : title.replace(/ property$/, ""));
|
|
222
|
+
return [...new Set(entries?.flatMap(({ offset }) => offset === void 0 ? [] : [offset]) ?? [])];
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
//#endregion
|
|
227
|
+
//#region src/email/compatibility.ts
|
|
228
|
+
/**
|
|
229
|
+
* The pinned matrix. Every finding is reported per client, and a client absent
|
|
230
|
+
* from this list is a client Samva makes no claim about.
|
|
231
|
+
*/
|
|
232
|
+
const EMAIL_CLIENT_MATRIX = [
|
|
233
|
+
{
|
|
234
|
+
id: "gmail.desktop-webmail",
|
|
235
|
+
label: "Gmail web"
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
id: "gmail.ios",
|
|
239
|
+
label: "Gmail iOS"
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
id: "gmail.android",
|
|
243
|
+
label: "Gmail Android"
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
id: "apple-mail.macos",
|
|
247
|
+
label: "Apple Mail macOS"
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
id: "apple-mail.ios",
|
|
251
|
+
label: "Apple Mail iOS"
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
id: "yahoo.desktop-webmail",
|
|
255
|
+
label: "Yahoo web"
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
id: "outlook.outlook-com",
|
|
259
|
+
label: "Outlook web and new Windows"
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
id: "outlook.windows",
|
|
263
|
+
label: "Outlook classic Windows"
|
|
264
|
+
}
|
|
265
|
+
];
|
|
266
|
+
const LABELS = new Map(EMAIL_CLIENT_MATRIX.map((target) => [target.id, target.label]));
|
|
267
|
+
const COMPATIBILITY_PROVENANCE = {
|
|
268
|
+
rules: "caniemail@2.0.2",
|
|
269
|
+
apiVersion: rawData.api_version,
|
|
270
|
+
lastUpdate: rawData.last_update_date
|
|
271
|
+
};
|
|
272
|
+
/**
|
|
273
|
+
* The constructs whose loss actually breaks a message: the recipient reads
|
|
274
|
+
* something different, in a different order, follows a link that does not work,
|
|
275
|
+
* or sees a layout that has collapsed. A target client dropping one of these
|
|
276
|
+
* blocks publication.
|
|
277
|
+
*
|
|
278
|
+
* The list is deliberately short and enumerated, because the contract is to
|
|
279
|
+
* block *known* failures. Nonessential differences require an assessment of
|
|
280
|
+
* emitted values: a concrete risk warns, expected differences and unverified
|
|
281
|
+
* behavior remain compatibility observations.
|
|
282
|
+
*/
|
|
283
|
+
const ESSENTIAL_CONSTRUCTS = /* @__PURE__ */ new Set([
|
|
284
|
+
"<table> element",
|
|
285
|
+
"<div> element",
|
|
286
|
+
"<p> element",
|
|
287
|
+
"<span> element",
|
|
288
|
+
"<ul>, <ol> and <dl>",
|
|
289
|
+
"<h1> to <h6> elements",
|
|
290
|
+
"HTML5 doctype",
|
|
291
|
+
"width attribute",
|
|
292
|
+
"height attribute",
|
|
293
|
+
"align attribute",
|
|
294
|
+
"valign attribute",
|
|
295
|
+
"<img> element",
|
|
296
|
+
"display",
|
|
297
|
+
"mailto: links",
|
|
298
|
+
"Local anchors"
|
|
299
|
+
]);
|
|
300
|
+
const KNOWN_TITLES = new Set(rawData.data.map((feature) => feature.title));
|
|
301
|
+
/** The innermost recorded node containing an offset, so a finding names its element. */
|
|
302
|
+
const originsAt = (positions, offset) => {
|
|
303
|
+
let best;
|
|
304
|
+
for (const position of positions) {
|
|
305
|
+
if (offset < position.start || offset >= position.end) continue;
|
|
306
|
+
if (best === void 0 || position.end - position.start < best.end - best.start) best = position;
|
|
307
|
+
}
|
|
308
|
+
return best?.origins ?? [];
|
|
309
|
+
};
|
|
310
|
+
const slug = (title) => title.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
311
|
+
/**
|
|
312
|
+
* Check the emitted document against the pinned matrix.
|
|
313
|
+
*
|
|
314
|
+
* Findings are grouped by construct rather than repeated per client, so one
|
|
315
|
+
* unsupported property is one diagnostic naming every client that drops it.
|
|
316
|
+
*/
|
|
317
|
+
const checkEmailCompatibility = (input) => {
|
|
318
|
+
const targets = input.clients ?? EMAIL_CLIENT_MATRIX;
|
|
319
|
+
const context = compatibilityContext(input.html, input.css);
|
|
320
|
+
const targetClients = targets.map((target) => target.id);
|
|
321
|
+
const reports = [caniemail({
|
|
322
|
+
clients: targetClients,
|
|
323
|
+
html: input.html
|
|
324
|
+
}), ...input.css === void 0 ? [] : [caniemail({
|
|
325
|
+
clients: targetClients,
|
|
326
|
+
css: input.css
|
|
327
|
+
})]];
|
|
328
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
329
|
+
for (const bucket of reports.flatMap((report) => [report.issues.errors, report.issues.warnings])) for (const [client, issues] of bucket) {
|
|
330
|
+
const label = LABELS.get(client) ?? client;
|
|
331
|
+
for (const raw of issues) {
|
|
332
|
+
const hiddenContentFailure = client === "outlook.windows" && raw.support === "partial" && (raw.title === "display" || raw.title === "display:none") && context.hiddenContentOffsets.length > 0;
|
|
333
|
+
const blocking = hiddenContentFailure || raw.support !== "partial" && ESSENTIAL_CONSTRUCTS.has(raw.title);
|
|
334
|
+
const { explanation, ...compatibility } = assessCompatibility(raw.title, client, raw.support, context, blocking);
|
|
335
|
+
const key = JSON.stringify([
|
|
336
|
+
raw.title,
|
|
337
|
+
raw.support,
|
|
338
|
+
compatibility,
|
|
339
|
+
explanation
|
|
340
|
+
]);
|
|
341
|
+
const offsets = hiddenContentFailure ? context.hiddenContentOffsets : context.offsets(raw.title);
|
|
342
|
+
const entry = grouped.get(key);
|
|
343
|
+
if (entry === void 0) grouped.set(key, {
|
|
344
|
+
title: raw.title,
|
|
345
|
+
support: raw.support,
|
|
346
|
+
clients: /* @__PURE__ */ new Set([label]),
|
|
347
|
+
notes: new Set(raw.notes),
|
|
348
|
+
explanation,
|
|
349
|
+
compatibility,
|
|
350
|
+
blocking,
|
|
351
|
+
offsets
|
|
352
|
+
});
|
|
353
|
+
else {
|
|
354
|
+
entry.clients.add(label);
|
|
355
|
+
for (const note of raw.notes) entry.notes.add(note);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
const findings = [];
|
|
360
|
+
for (const entry of grouped.values()) {
|
|
361
|
+
const severity = entry.blocking ? "error" : entry.compatibility.assessment === "risk" ? "warning" : "info";
|
|
362
|
+
const occurrences = entry.offsets.map((offset) => originsAt(input.positions ?? [], offset)).filter((origins) => origins.length > 0);
|
|
363
|
+
const clients = [...entry.clients].sort();
|
|
364
|
+
const dropped = entry.support === "partial" ? clients.length === 1 ? "partially supports" : "partially support" : clients.length === 1 ? "does not support" : "do not support";
|
|
365
|
+
findings.push({
|
|
366
|
+
code: `caniemail/${slug(entry.title)}`,
|
|
367
|
+
severity,
|
|
368
|
+
message: `${clients.join(", ")} ${dropped} ${entry.title}. ${entry.explanation}`,
|
|
369
|
+
compatibility: entry.compatibility,
|
|
370
|
+
origins: occurrences[0] ?? [],
|
|
371
|
+
...occurrences.length === 0 ? {} : { occurrences },
|
|
372
|
+
...input.fixture === void 0 ? {} : { fixtures: [input.fixture] },
|
|
373
|
+
clients,
|
|
374
|
+
...entry.notes.size === 0 ? {} : { notes: [...entry.notes].join(" ") },
|
|
375
|
+
provenance: `${COMPATIBILITY_PROVENANCE.rules} (caniemail data ${COMPATIBILITY_PROVENANCE.apiVersion}, updated ${COMPATIBILITY_PROVENANCE.lastUpdate})`
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
return findings.sort((left, right) => left.code.localeCompare(right.code));
|
|
379
|
+
};
|
|
380
|
+
/**
|
|
381
|
+
* Constructs the pinned data says nothing about for a target client. These are
|
|
382
|
+
* reported so "we did not check that" is never mistaken for "that works".
|
|
383
|
+
*/
|
|
384
|
+
const unknownCoverage = (titles) => [...titles].filter((title) => !KNOWN_TITLES.has(title)).sort().map((title) => ({
|
|
385
|
+
code: "caniemail/unknown-coverage",
|
|
386
|
+
severity: "info",
|
|
387
|
+
message: `The pinned rules say nothing about ${title}, so no client claim is made about it. Verify it in a real client before relying on it.`,
|
|
388
|
+
origins: [],
|
|
389
|
+
provenance: `${COMPATIBILITY_PROVENANCE.rules} (caniemail data ${COMPATIBILITY_PROVENANCE.apiVersion}, updated ${COMPATIBILITY_PROVENANCE.lastUpdate})`
|
|
390
|
+
}));
|
|
391
|
+
/** A publication carrying one of these is refused; the message would arrive broken. */
|
|
392
|
+
const hasBlockingCompatibility = (findings) => findings.some((finding) => finding.severity === "error");
|
|
393
|
+
//#endregion
|
|
394
|
+
//#region src/email/fonts.ts
|
|
395
|
+
const FONT_FILE = /\.woff2$/i;
|
|
396
|
+
const WOFF2_FORMAT = /^woff2(?:-variations)?$/i;
|
|
397
|
+
const SCHEME = /^[a-z][a-z0-9+.-]*:/i;
|
|
398
|
+
const declarationValue = (declaration) => declaration.type === "Declaration" ? generate(declaration.value).trim() : "";
|
|
399
|
+
/**
|
|
400
|
+
* Validate one `@font-face` and rewrite its project-relative `src` URLs.
|
|
401
|
+
* Accepts only WOFF2: a relative URL must name a `.woff2` file the project has,
|
|
402
|
+
* and an `https:` URL stays an external reference. `local()` entries pass.
|
|
403
|
+
*/
|
|
404
|
+
const compileFontFace = (node, origin, resolve) => {
|
|
405
|
+
const diagnostics = [];
|
|
406
|
+
const fail = (code, message) => diagnostics.push({
|
|
407
|
+
code,
|
|
408
|
+
severity: "error",
|
|
409
|
+
message: `${origin}: ${message}`,
|
|
410
|
+
origins: []
|
|
411
|
+
});
|
|
412
|
+
if (node.type !== "Atrule" || node.block === null || node.block.children === null) return {
|
|
413
|
+
rule: void 0,
|
|
414
|
+
diagnostics
|
|
415
|
+
};
|
|
416
|
+
let family;
|
|
417
|
+
let sources = 0;
|
|
418
|
+
for (const declaration of node.block.children) {
|
|
419
|
+
if (declaration.type !== "Declaration") continue;
|
|
420
|
+
const property = declaration.property.toLowerCase();
|
|
421
|
+
if (property === "font-family") family = unquote(declarationValue(declaration));
|
|
422
|
+
if (property !== "src") continue;
|
|
423
|
+
const authored = declarationValue(declaration);
|
|
424
|
+
let value;
|
|
425
|
+
try {
|
|
426
|
+
value = parse(authored, { context: "value" });
|
|
427
|
+
} catch {
|
|
428
|
+
fail("email-font-src", "@font-face src could not be parsed.");
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
walk(value, { enter: (part) => {
|
|
432
|
+
if (part.type === "Function" && part.name.toLowerCase() === "format") {
|
|
433
|
+
const format = unquote(generate(part).slice(7, -1));
|
|
434
|
+
if (!WOFF2_FORMAT.test(format)) fail("email-font-format", `@font-face format(${format}) is not supported. Email fonts are WOFF2 only; convert the file to .woff2.`);
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
if (part.type !== "Url") return;
|
|
438
|
+
sources++;
|
|
439
|
+
const reference = part.value;
|
|
440
|
+
const path = reference.replace(/[?#].*$/, "");
|
|
441
|
+
if (/^https:\/\//i.test(reference)) {
|
|
442
|
+
if (!FONT_FILE.test(path) && !/format\(\s*['"]?woff2/i.test(generate(value))) fail("email-font-format", `@font-face src ${JSON.stringify(reference)} is not a WOFF2 file. Email fonts are WOFF2 only.`);
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
if (SCHEME.test(reference) || reference.startsWith("//")) {
|
|
446
|
+
fail("email-font-src", `@font-face src ${JSON.stringify(reference)} must be a project .woff2 file or an https URL.`);
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
if (!FONT_FILE.test(path)) {
|
|
450
|
+
fail("email-font-format", `@font-face src ${JSON.stringify(reference)} is not a .woff2 file. Email fonts are WOFF2 only; convert the file to .woff2.`);
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
const url = resolve?.(reference);
|
|
454
|
+
if (url === void 0) {
|
|
455
|
+
fail("email-font-missing", `@font-face src ${JSON.stringify(reference)} names no file in the project. Paths resolve from the stylesheet's own directory.`);
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
part.value = url;
|
|
459
|
+
} });
|
|
460
|
+
declaration.value = {
|
|
461
|
+
type: "Raw",
|
|
462
|
+
value: generate(value).replace(/\)(?=(?:format|tech)\()/gi, ") ")
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
if (family === void 0 || family === "") fail("email-font-family", "@font-face declares no font-family.");
|
|
466
|
+
if (sources === 0) fail("email-font-src", "@font-face declares no url() src.");
|
|
467
|
+
if (diagnostics.length > 0 || family === void 0) return {
|
|
468
|
+
rule: void 0,
|
|
469
|
+
diagnostics
|
|
470
|
+
};
|
|
471
|
+
return {
|
|
472
|
+
rule: {
|
|
473
|
+
family,
|
|
474
|
+
css: generate(node)
|
|
475
|
+
},
|
|
476
|
+
diagnostics
|
|
477
|
+
};
|
|
478
|
+
};
|
|
479
|
+
//#endregion
|
|
480
|
+
//#region src/email/css.ts
|
|
481
|
+
const UNLAYERED = Number.MAX_SAFE_INTEGER;
|
|
482
|
+
const CONDITIONAL_AT_RULES = /* @__PURE__ */ new Set([
|
|
483
|
+
"media",
|
|
484
|
+
"supports",
|
|
485
|
+
"container"
|
|
486
|
+
]);
|
|
487
|
+
const HEAD_AT_RULES = /* @__PURE__ */ new Set([
|
|
488
|
+
"page",
|
|
489
|
+
"counter-style",
|
|
490
|
+
"keyframes"
|
|
491
|
+
]);
|
|
492
|
+
const ROOT_SELECTORS = /* @__PURE__ */ new Set([
|
|
493
|
+
":root",
|
|
494
|
+
":host",
|
|
495
|
+
"html",
|
|
496
|
+
"*",
|
|
497
|
+
":where(:root)"
|
|
498
|
+
]);
|
|
499
|
+
const text = (node) => node === null || node === void 0 ? "" : generate(node);
|
|
500
|
+
/** The CSS specificity triple for one selector, ignoring the parts email clients drop. */
|
|
501
|
+
const specificityOf = (selector) => {
|
|
502
|
+
let id = 0;
|
|
503
|
+
let cls = 0;
|
|
504
|
+
let type = 0;
|
|
505
|
+
const visit = (node) => {
|
|
506
|
+
switch (node.type) {
|
|
507
|
+
case "IdSelector":
|
|
508
|
+
id += 1;
|
|
509
|
+
break;
|
|
510
|
+
case "ClassSelector":
|
|
511
|
+
case "AttributeSelector":
|
|
512
|
+
cls += 1;
|
|
513
|
+
break;
|
|
514
|
+
case "PseudoClassSelector":
|
|
515
|
+
if (node.name !== "where") cls += 1;
|
|
516
|
+
break;
|
|
517
|
+
case "TypeSelector":
|
|
518
|
+
if (node.name !== "*") type += 1;
|
|
519
|
+
break;
|
|
520
|
+
case "PseudoElementSelector": type += 1;
|
|
521
|
+
}
|
|
522
|
+
if ("children" in node && node.children !== null && node.children !== void 0) for (const child of node.children) visit(child);
|
|
523
|
+
};
|
|
524
|
+
visit(selector);
|
|
525
|
+
return [
|
|
526
|
+
id,
|
|
527
|
+
cls,
|
|
528
|
+
type
|
|
529
|
+
];
|
|
530
|
+
};
|
|
531
|
+
const hasPseudo = (selector) => {
|
|
532
|
+
let found = false;
|
|
533
|
+
const visit = (node) => {
|
|
534
|
+
if (node.type === "PseudoClassSelector" || node.type === "PseudoElementSelector") found = true;
|
|
535
|
+
if ("children" in node && node.children !== null && node.children !== void 0) for (const child of node.children) visit(child);
|
|
536
|
+
};
|
|
537
|
+
visit(selector);
|
|
538
|
+
return found;
|
|
539
|
+
};
|
|
540
|
+
const COMBINATORS = {
|
|
541
|
+
" ": "descendant",
|
|
542
|
+
">": "child",
|
|
543
|
+
"+": "adjacent",
|
|
544
|
+
"~": "sibling"
|
|
545
|
+
};
|
|
546
|
+
/** Compile a selector into the plain-data matcher the render lane uses. */
|
|
547
|
+
const compileSelector = (selector) => {
|
|
548
|
+
let ast;
|
|
549
|
+
try {
|
|
550
|
+
ast = parse(selector, {
|
|
551
|
+
context: "selector",
|
|
552
|
+
positions: false
|
|
553
|
+
});
|
|
554
|
+
} catch {
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
if (ast.type !== "Selector" || ast.children === null) return void 0;
|
|
558
|
+
const parts = [];
|
|
559
|
+
let tag;
|
|
560
|
+
let id;
|
|
561
|
+
let classes = [];
|
|
562
|
+
let attributes = [];
|
|
563
|
+
let opaque = false;
|
|
564
|
+
const flush = (after) => {
|
|
565
|
+
parts.push({
|
|
566
|
+
compound: {
|
|
567
|
+
tag,
|
|
568
|
+
id,
|
|
569
|
+
classes,
|
|
570
|
+
attributes,
|
|
571
|
+
opaque
|
|
572
|
+
},
|
|
573
|
+
...after === void 0 ? {} : { after }
|
|
574
|
+
});
|
|
575
|
+
tag = void 0;
|
|
576
|
+
id = void 0;
|
|
577
|
+
classes = [];
|
|
578
|
+
attributes = [];
|
|
579
|
+
opaque = false;
|
|
580
|
+
};
|
|
581
|
+
for (const node of ast.children) switch (node.type) {
|
|
582
|
+
case "TypeSelector":
|
|
583
|
+
if (node.name !== "*") tag = node.name.toLowerCase();
|
|
584
|
+
break;
|
|
585
|
+
case "IdSelector":
|
|
586
|
+
id = node.name;
|
|
587
|
+
break;
|
|
588
|
+
case "ClassSelector":
|
|
589
|
+
classes.push(ident.decode(node.name));
|
|
590
|
+
break;
|
|
591
|
+
case "AttributeSelector":
|
|
592
|
+
attributes.push({
|
|
593
|
+
name: node.name.name,
|
|
594
|
+
operator: node.matcher ?? void 0,
|
|
595
|
+
value: node.value === null || node.value === void 0 ? void 0 : node.value.type === "String" ? node.value.value : node.value.name
|
|
596
|
+
});
|
|
597
|
+
break;
|
|
598
|
+
case "Combinator":
|
|
599
|
+
flush(COMBINATORS[node.name.trim() === "" ? " " : node.name] ?? "descendant");
|
|
600
|
+
break;
|
|
601
|
+
default: opaque = true;
|
|
602
|
+
}
|
|
603
|
+
flush();
|
|
604
|
+
return { parts };
|
|
605
|
+
};
|
|
606
|
+
/** Substitute a nested rule's `&` against its parent selector. */
|
|
607
|
+
const nestSelector = (parent, child) => child.includes("&") ? child.replaceAll("&", parent) : `${parent} ${child}`;
|
|
608
|
+
/** Parse one stylesheet into rules, keeping layer, order and conditions. */
|
|
609
|
+
const parseStylesheet = (source, options = {}) => {
|
|
610
|
+
const rules = [];
|
|
611
|
+
const headAtRules = [];
|
|
612
|
+
const fontFaces = [];
|
|
613
|
+
const variables = {};
|
|
614
|
+
const conditionalVariables = /* @__PURE__ */ new Set();
|
|
615
|
+
const diagnostics = [];
|
|
616
|
+
const layers = /* @__PURE__ */ new Map();
|
|
617
|
+
const selectorFacts = /* @__PURE__ */ new Map();
|
|
618
|
+
let order = options.startOrder ?? 0;
|
|
619
|
+
/** Everything a rule needs from its selector, computed once per distinct string. */
|
|
620
|
+
const factsFor = (selector) => {
|
|
621
|
+
const cached = selectorFacts.get(selector);
|
|
622
|
+
if (cached !== void 0) return cached;
|
|
623
|
+
let facts;
|
|
624
|
+
try {
|
|
625
|
+
const node = parse(selector, {
|
|
626
|
+
context: "selector",
|
|
627
|
+
positions: false
|
|
628
|
+
});
|
|
629
|
+
const classes = /* @__PURE__ */ new Set();
|
|
630
|
+
walk(node, {
|
|
631
|
+
visit: "ClassSelector",
|
|
632
|
+
enter: (part) => {
|
|
633
|
+
classes.add(ident.decode(part.name));
|
|
634
|
+
}
|
|
635
|
+
});
|
|
636
|
+
facts = {
|
|
637
|
+
classes: [...classes],
|
|
638
|
+
specificity: specificityOf(node),
|
|
639
|
+
pseudo: hasPseudo(node),
|
|
640
|
+
matcher: compileSelector(selector)
|
|
641
|
+
};
|
|
642
|
+
} catch {
|
|
643
|
+
facts = {
|
|
644
|
+
classes: [],
|
|
645
|
+
specificity: [
|
|
646
|
+
0,
|
|
647
|
+
0,
|
|
648
|
+
0
|
|
649
|
+
],
|
|
650
|
+
pseudo: true,
|
|
651
|
+
matcher: void 0
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
selectorFacts.set(selector, facts);
|
|
655
|
+
return facts;
|
|
656
|
+
};
|
|
657
|
+
let ast;
|
|
658
|
+
try {
|
|
659
|
+
ast = parse(source, {
|
|
660
|
+
parseValue: false,
|
|
661
|
+
parseCustomProperty: false,
|
|
662
|
+
positions: false
|
|
663
|
+
});
|
|
664
|
+
} catch (cause) {
|
|
665
|
+
return {
|
|
666
|
+
rules: [],
|
|
667
|
+
headAtRules: [],
|
|
668
|
+
fontFaces: [],
|
|
669
|
+
variables: {},
|
|
670
|
+
diagnostics: [{
|
|
671
|
+
code: "css-parse-error",
|
|
672
|
+
severity: "error",
|
|
673
|
+
message: `${options.origin ?? "stylesheet"} could not be parsed: ${String(cause)}`,
|
|
674
|
+
origins: []
|
|
675
|
+
}]
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
const declarationsOf = (block) => {
|
|
679
|
+
const output = [];
|
|
680
|
+
if (block === null || block.type !== "Block" || block.children === null) return output;
|
|
681
|
+
for (const child of block.children) {
|
|
682
|
+
if (child.type !== "Declaration") continue;
|
|
683
|
+
output.push({
|
|
684
|
+
property: child.property,
|
|
685
|
+
value: downlevelColors(text(child.value).trim().replace(/[\t\n\r\f]/g, " ")),
|
|
686
|
+
important: child.important === true
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
return output;
|
|
690
|
+
};
|
|
691
|
+
const emit = (selector, context, declarations) => {
|
|
692
|
+
if (declarations.length === 0) return;
|
|
693
|
+
const facts = factsFor(selector);
|
|
694
|
+
if (ROOT_SELECTORS.has(selector.trim())) for (const declaration of declarations) {
|
|
695
|
+
if (!declaration.property.startsWith("--")) continue;
|
|
696
|
+
if (context.conditions.length === 0) variables[declaration.property] = declaration.value;
|
|
697
|
+
else conditionalVariables.add(declaration.property);
|
|
698
|
+
}
|
|
699
|
+
rules.push({
|
|
700
|
+
selector,
|
|
701
|
+
classes: facts.classes,
|
|
702
|
+
specificity: facts.specificity,
|
|
703
|
+
declarations,
|
|
704
|
+
order: order++,
|
|
705
|
+
layer: context.layer,
|
|
706
|
+
conditions: context.conditions,
|
|
707
|
+
inlinable: context.conditions.length === 0 && !facts.pseudo,
|
|
708
|
+
matcher: facts.matcher
|
|
709
|
+
});
|
|
710
|
+
};
|
|
711
|
+
/**
|
|
712
|
+
* Declarations directly in a block belong to the enclosing selector, whether
|
|
713
|
+
* that block is the rule's own or a `@media` nested inside it — which is
|
|
714
|
+
* exactly the shape Tailwind v4 emits for a responsive utility.
|
|
715
|
+
*/
|
|
716
|
+
const walkBlock = (block, context) => {
|
|
717
|
+
if (block === null || block.type !== "Block" || block.children === null) return;
|
|
718
|
+
const declarations = declarationsOf(block);
|
|
719
|
+
if (declarations.length > 0 && context.selector !== void 0) emit(context.selector, context, declarations);
|
|
720
|
+
for (const child of block.children) if (child.type !== "Declaration") visitNode(child, context);
|
|
721
|
+
};
|
|
722
|
+
const visitNode = (node, context) => {
|
|
723
|
+
if (node.type === "Rule") {
|
|
724
|
+
const prelude = node.prelude;
|
|
725
|
+
const selectors = prelude.type === "SelectorList" && prelude.children !== null ? [...prelude.children] : [prelude];
|
|
726
|
+
for (const selector of selectors) {
|
|
727
|
+
const own = text(selector).trim();
|
|
728
|
+
if (own === "") continue;
|
|
729
|
+
walkBlock(node.block, {
|
|
730
|
+
...context,
|
|
731
|
+
selector: context.selector === void 0 ? own : nestSelector(context.selector, own)
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
736
|
+
if (node.type !== "Atrule") return;
|
|
737
|
+
const name = node.name.toLowerCase();
|
|
738
|
+
if (name === "layer") {
|
|
739
|
+
const prelude = text(node.prelude).trim();
|
|
740
|
+
if (node.block === null) {
|
|
741
|
+
for (const declared of prelude.split(",").map((part) => part.trim())) if (declared !== "" && !layers.has(declared)) layers.set(declared, layers.size);
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
const named = prelude.split(",")[0]?.trim() ?? "";
|
|
745
|
+
if (named !== "" && !layers.has(named)) layers.set(named, layers.size);
|
|
746
|
+
walkBlock(node.block, {
|
|
747
|
+
...context,
|
|
748
|
+
layer: layers.get(named) ?? context.layer
|
|
749
|
+
});
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
752
|
+
if (name === "theme" || name === "scope") {
|
|
753
|
+
for (const declaration of declarationsOf(node.block)) if (declaration.property.startsWith("--")) variables[declaration.property] = declaration.value;
|
|
754
|
+
for (const child of node.block?.children ?? []) if (child.type !== "Declaration") visitNode(child, context);
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
if (name === "property") {
|
|
758
|
+
const initial = declarationsOf(node.block).find((declaration) => declaration.property === "initial-value");
|
|
759
|
+
const property = text(node.prelude).trim();
|
|
760
|
+
if (initial !== void 0 && property.startsWith("--") && !(property in variables)) variables[property] = initial.value;
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
if (CONDITIONAL_AT_RULES.has(name)) {
|
|
764
|
+
walkBlock(node.block, {
|
|
765
|
+
...context,
|
|
766
|
+
conditions: [...context.conditions, `@${name} ${text(node.prelude).trim()}`]
|
|
767
|
+
});
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
if (name === "font-face") {
|
|
771
|
+
const face = compileFontFace(node, options.origin ?? "stylesheet", options.resolveFontFile);
|
|
772
|
+
if (face.rule !== void 0) fontFaces.push(face.rule);
|
|
773
|
+
diagnostics.push(...face.diagnostics);
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
if (HEAD_AT_RULES.has(name)) {
|
|
777
|
+
headAtRules.push(generate(node));
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
if (name === "import") {
|
|
781
|
+
if (options.themeImports === true) return;
|
|
782
|
+
diagnostics.push({
|
|
783
|
+
code: "css-import-unresolved",
|
|
784
|
+
severity: "error",
|
|
785
|
+
message: `${options.origin ?? "stylesheet"} uses @import ${text(node.prelude).trim()}; import the stylesheet from the template module instead so the compiler can resolve it.`,
|
|
786
|
+
origins: []
|
|
787
|
+
});
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
790
|
+
if (name === "charset" || name === "namespace") return;
|
|
791
|
+
diagnostics.push({
|
|
792
|
+
code: "css-unsupported-at-rule",
|
|
793
|
+
severity: "warning",
|
|
794
|
+
message: `@${name} is not applied to email output; remove it or move the declarations into a class rule.`,
|
|
795
|
+
origins: []
|
|
796
|
+
});
|
|
797
|
+
};
|
|
798
|
+
if (ast.type === "StyleSheet" && ast.children !== null) for (const child of ast.children) visitNode(child, {
|
|
799
|
+
conditions: [],
|
|
800
|
+
layer: UNLAYERED
|
|
801
|
+
});
|
|
802
|
+
for (const property of conditionalVariables) if (property in variables) diagnostics.push({
|
|
803
|
+
code: "css-conditional-variable",
|
|
804
|
+
severity: "warning",
|
|
805
|
+
message: `${property} is redefined inside a conditional at-rule. Inlined declarations take the unconditional value; keep the override on a class rule so the retained head rule can apply it.`,
|
|
806
|
+
origins: []
|
|
807
|
+
});
|
|
808
|
+
return {
|
|
809
|
+
rules,
|
|
810
|
+
headAtRules,
|
|
811
|
+
fontFaces,
|
|
812
|
+
variables,
|
|
813
|
+
diagnostics
|
|
814
|
+
};
|
|
815
|
+
};
|
|
816
|
+
//#endregion
|
|
817
|
+
//#region src/email/tailwind-stylesheets.gen.ts
|
|
818
|
+
/** The exact Tailwind release the compiler runs, recorded in every build manifest. */
|
|
819
|
+
const TAILWIND_VERSION = "4.3.3";
|
|
820
|
+
//#endregion
|
|
821
|
+
//#region src/email/tailwind.ts
|
|
822
|
+
const STYLESHEETS = {
|
|
823
|
+
tailwindcss: `@layer theme, base, components, utilities;\n@import "tailwindcss/theme.css" layer(theme);\n@import "tailwindcss/utilities.css" layer(utilities);`,
|
|
824
|
+
"tailwindcss/theme.css": "@theme default {\n --font-sans:\n -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', 'Noto Sans', Arial,\n sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';\n --font-serif: ui-serif, Georgia, Cambria, 'Times New Roman', Times, serif;\n --font-mono:\n ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New',\n monospace;\n\n --color-red-50: oklch(97.1% 0.013 17.38);\n --color-red-100: oklch(93.6% 0.032 17.717);\n --color-red-200: oklch(88.5% 0.062 18.334);\n --color-red-300: oklch(80.8% 0.114 19.571);\n --color-red-400: oklch(70.4% 0.191 22.216);\n --color-red-500: oklch(63.7% 0.237 25.331);\n --color-red-600: oklch(57.7% 0.245 27.325);\n --color-red-700: oklch(50.5% 0.213 27.518);\n --color-red-800: oklch(44.4% 0.177 26.899);\n --color-red-900: oklch(39.6% 0.141 25.723);\n --color-red-950: oklch(25.8% 0.092 26.042);\n\n --color-orange-50: oklch(98% 0.016 73.684);\n --color-orange-100: oklch(95.4% 0.038 75.164);\n --color-orange-200: oklch(90.1% 0.076 70.697);\n --color-orange-300: oklch(83.7% 0.128 66.29);\n --color-orange-400: oklch(75% 0.183 55.934);\n --color-orange-500: oklch(70.5% 0.213 47.604);\n --color-orange-600: oklch(64.6% 0.222 41.116);\n --color-orange-700: oklch(55.3% 0.195 38.402);\n --color-orange-800: oklch(47% 0.157 37.304);\n --color-orange-900: oklch(40.8% 0.123 38.172);\n --color-orange-950: oklch(26.6% 0.079 36.259);\n\n --color-amber-50: oklch(98.7% 0.022 95.277);\n --color-amber-100: oklch(96.2% 0.059 95.617);\n --color-amber-200: oklch(92.4% 0.12 95.746);\n --color-amber-300: oklch(87.9% 0.169 91.605);\n --color-amber-400: oklch(82.8% 0.189 84.429);\n --color-amber-500: oklch(76.9% 0.188 70.08);\n --color-amber-600: oklch(66.6% 0.179 58.318);\n --color-amber-700: oklch(55.5% 0.163 48.998);\n --color-amber-800: oklch(47.3% 0.137 46.201);\n --color-amber-900: oklch(41.4% 0.112 45.904);\n --color-amber-950: oklch(27.9% 0.077 45.635);\n\n --color-yellow-50: oklch(98.7% 0.026 102.212);\n --color-yellow-100: oklch(97.3% 0.071 103.193);\n --color-yellow-200: oklch(94.5% 0.129 101.54);\n --color-yellow-300: oklch(90.5% 0.182 98.111);\n --color-yellow-400: oklch(85.2% 0.199 91.936);\n --color-yellow-500: oklch(79.5% 0.184 86.047);\n --color-yellow-600: oklch(68.1% 0.162 75.834);\n --color-yellow-700: oklch(55.4% 0.135 66.442);\n --color-yellow-800: oklch(47.6% 0.114 61.907);\n --color-yellow-900: oklch(42.1% 0.095 57.708);\n --color-yellow-950: oklch(28.6% 0.066 53.813);\n\n --color-lime-50: oklch(98.6% 0.031 120.757);\n --color-lime-100: oklch(96.7% 0.067 122.328);\n --color-lime-200: oklch(93.8% 0.127 124.321);\n --color-lime-300: oklch(89.7% 0.196 126.665);\n --color-lime-400: oklch(84.1% 0.238 128.85);\n --color-lime-500: oklch(76.8% 0.233 130.85);\n --color-lime-600: oklch(64.8% 0.2 131.684);\n --color-lime-700: oklch(53.2% 0.157 131.589);\n --color-lime-800: oklch(45.3% 0.124 130.933);\n --color-lime-900: oklch(40.5% 0.101 131.063);\n --color-lime-950: oklch(27.4% 0.072 132.109);\n\n --color-green-50: oklch(98.2% 0.018 155.826);\n --color-green-100: oklch(96.2% 0.044 156.743);\n --color-green-200: oklch(92.5% 0.084 155.995);\n --color-green-300: oklch(87.1% 0.15 154.449);\n --color-green-400: oklch(79.2% 0.209 151.711);\n --color-green-500: oklch(72.3% 0.219 149.579);\n --color-green-600: oklch(62.7% 0.194 149.214);\n --color-green-700: oklch(52.7% 0.154 150.069);\n --color-green-800: oklch(44.8% 0.119 151.328);\n --color-green-900: oklch(39.3% 0.095 152.535);\n --color-green-950: oklch(26.6% 0.065 152.934);\n\n --color-emerald-50: oklch(97.9% 0.021 166.113);\n --color-emerald-100: oklch(95% 0.052 163.051);\n --color-emerald-200: oklch(90.5% 0.093 164.15);\n --color-emerald-300: oklch(84.5% 0.143 164.978);\n --color-emerald-400: oklch(76.5% 0.177 163.223);\n --color-emerald-500: oklch(69.6% 0.17 162.48);\n --color-emerald-600: oklch(59.6% 0.145 163.225);\n --color-emerald-700: oklch(50.8% 0.118 165.612);\n --color-emerald-800: oklch(43.2% 0.095 166.913);\n --color-emerald-900: oklch(37.8% 0.077 168.94);\n --color-emerald-950: oklch(26.2% 0.051 172.552);\n\n --color-teal-50: oklch(98.4% 0.014 180.72);\n --color-teal-100: oklch(95.3% 0.051 180.801);\n --color-teal-200: oklch(91% 0.096 180.426);\n --color-teal-300: oklch(85.5% 0.138 181.071);\n --color-teal-400: oklch(77.7% 0.152 181.912);\n --color-teal-500: oklch(70.4% 0.14 182.503);\n --color-teal-600: oklch(60% 0.118 184.704);\n --color-teal-700: oklch(51.1% 0.096 186.391);\n --color-teal-800: oklch(43.7% 0.078 188.216);\n --color-teal-900: oklch(38.6% 0.063 188.416);\n --color-teal-950: oklch(27.7% 0.046 192.524);\n\n --color-cyan-50: oklch(98.4% 0.019 200.873);\n --color-cyan-100: oklch(95.6% 0.045 203.388);\n --color-cyan-200: oklch(91.7% 0.08 205.041);\n --color-cyan-300: oklch(86.5% 0.127 207.078);\n --color-cyan-400: oklch(78.9% 0.154 211.53);\n --color-cyan-500: oklch(71.5% 0.143 215.221);\n --color-cyan-600: oklch(60.9% 0.126 221.723);\n --color-cyan-700: oklch(52% 0.105 223.128);\n --color-cyan-800: oklch(45% 0.085 224.283);\n --color-cyan-900: oklch(39.8% 0.07 227.392);\n --color-cyan-950: oklch(30.2% 0.056 229.695);\n\n --color-sky-50: oklch(97.7% 0.013 236.62);\n --color-sky-100: oklch(95.1% 0.026 236.824);\n --color-sky-200: oklch(90.1% 0.058 230.902);\n --color-sky-300: oklch(82.8% 0.111 230.318);\n --color-sky-400: oklch(74.6% 0.16 232.661);\n --color-sky-500: oklch(68.5% 0.169 237.323);\n --color-sky-600: oklch(58.8% 0.158 241.966);\n --color-sky-700: oklch(50% 0.134 242.749);\n --color-sky-800: oklch(44.3% 0.11 240.79);\n --color-sky-900: oklch(39.1% 0.09 240.876);\n --color-sky-950: oklch(29.3% 0.066 243.157);\n\n --color-blue-50: oklch(97% 0.014 254.604);\n --color-blue-100: oklch(93.2% 0.032 255.585);\n --color-blue-200: oklch(88.2% 0.059 254.128);\n --color-blue-300: oklch(80.9% 0.105 251.813);\n --color-blue-400: oklch(70.7% 0.165 254.624);\n --color-blue-500: oklch(62.3% 0.214 259.815);\n --color-blue-600: oklch(54.6% 0.245 262.881);\n --color-blue-700: oklch(48.8% 0.243 264.376);\n --color-blue-800: oklch(42.4% 0.199 265.638);\n --color-blue-900: oklch(37.9% 0.146 265.522);\n --color-blue-950: oklch(28.2% 0.091 267.935);\n\n --color-indigo-50: oklch(96.2% 0.018 272.314);\n --color-indigo-100: oklch(93% 0.034 272.788);\n --color-indigo-200: oklch(87% 0.065 274.039);\n --color-indigo-300: oklch(78.5% 0.115 274.713);\n --color-indigo-400: oklch(67.3% 0.182 276.935);\n --color-indigo-500: oklch(58.5% 0.233 277.117);\n --color-indigo-600: oklch(51.1% 0.262 276.966);\n --color-indigo-700: oklch(45.7% 0.24 277.023);\n --color-indigo-800: oklch(39.8% 0.195 277.366);\n --color-indigo-900: oklch(35.9% 0.144 278.697);\n --color-indigo-950: oklch(25.7% 0.09 281.288);\n\n --color-violet-50: oklch(96.9% 0.016 293.756);\n --color-violet-100: oklch(94.3% 0.029 294.588);\n --color-violet-200: oklch(89.4% 0.057 293.283);\n --color-violet-300: oklch(81.1% 0.111 293.571);\n --color-violet-400: oklch(70.2% 0.183 293.541);\n --color-violet-500: oklch(60.6% 0.25 292.717);\n --color-violet-600: oklch(54.1% 0.281 293.009);\n --color-violet-700: oklch(49.1% 0.27 292.581);\n --color-violet-800: oklch(43.2% 0.232 292.759);\n --color-violet-900: oklch(38% 0.189 293.745);\n --color-violet-950: oklch(28.3% 0.141 291.089);\n\n --color-purple-50: oklch(97.7% 0.014 308.299);\n --color-purple-100: oklch(94.6% 0.033 307.174);\n --color-purple-200: oklch(90.2% 0.063 306.703);\n --color-purple-300: oklch(82.7% 0.119 306.383);\n --color-purple-400: oklch(71.4% 0.203 305.504);\n --color-purple-500: oklch(62.7% 0.265 303.9);\n --color-purple-600: oklch(55.8% 0.288 302.321);\n --color-purple-700: oklch(49.6% 0.265 301.924);\n --color-purple-800: oklch(43.8% 0.218 303.724);\n --color-purple-900: oklch(38.1% 0.176 304.987);\n --color-purple-950: oklch(29.1% 0.149 302.717);\n\n --color-fuchsia-50: oklch(97.7% 0.017 320.058);\n --color-fuchsia-100: oklch(95.2% 0.037 318.852);\n --color-fuchsia-200: oklch(90.3% 0.076 319.62);\n --color-fuchsia-300: oklch(83.3% 0.145 321.434);\n --color-fuchsia-400: oklch(74% 0.238 322.16);\n --color-fuchsia-500: oklch(66.7% 0.295 322.15);\n --color-fuchsia-600: oklch(59.1% 0.293 322.896);\n --color-fuchsia-700: oklch(51.8% 0.253 323.949);\n --color-fuchsia-800: oklch(45.2% 0.211 324.591);\n --color-fuchsia-900: oklch(40.1% 0.17 325.612);\n --color-fuchsia-950: oklch(29.3% 0.136 325.661);\n\n --color-pink-50: oklch(97.1% 0.014 343.198);\n --color-pink-100: oklch(94.8% 0.028 342.258);\n --color-pink-200: oklch(89.9% 0.061 343.231);\n --color-pink-300: oklch(82.3% 0.12 346.018);\n --color-pink-400: oklch(71.8% 0.202 349.761);\n --color-pink-500: oklch(65.6% 0.241 354.308);\n --color-pink-600: oklch(59.2% 0.249 0.584);\n --color-pink-700: oklch(52.5% 0.223 3.958);\n --color-pink-800: oklch(45.9% 0.187 3.815);\n --color-pink-900: oklch(40.8% 0.153 2.432);\n --color-pink-950: oklch(28.4% 0.109 3.907);\n\n --color-rose-50: oklch(96.9% 0.015 12.422);\n --color-rose-100: oklch(94.1% 0.03 12.58);\n --color-rose-200: oklch(89.2% 0.058 10.001);\n --color-rose-300: oklch(81% 0.117 11.638);\n --color-rose-400: oklch(71.2% 0.194 13.428);\n --color-rose-500: oklch(64.5% 0.246 16.439);\n --color-rose-600: oklch(58.6% 0.253 17.585);\n --color-rose-700: oklch(51.4% 0.222 16.935);\n --color-rose-800: oklch(45.5% 0.188 13.697);\n --color-rose-900: oklch(41% 0.159 10.272);\n --color-rose-950: oklch(27.1% 0.105 12.094);\n\n --color-slate-50: oklch(98.4% 0.003 247.858);\n --color-slate-100: oklch(96.8% 0.007 247.896);\n --color-slate-200: oklch(92.9% 0.013 255.508);\n --color-slate-300: oklch(86.9% 0.022 252.894);\n --color-slate-400: oklch(70.4% 0.04 256.788);\n --color-slate-500: oklch(55.4% 0.046 257.417);\n --color-slate-600: oklch(44.6% 0.043 257.281);\n --color-slate-700: oklch(37.2% 0.044 257.287);\n --color-slate-800: oklch(27.9% 0.041 260.031);\n --color-slate-900: oklch(20.8% 0.042 265.755);\n --color-slate-950: oklch(12.9% 0.042 264.695);\n\n --color-gray-50: oklch(98.5% 0.002 247.839);\n --color-gray-100: oklch(96.7% 0.003 264.542);\n --color-gray-200: oklch(92.8% 0.006 264.531);\n --color-gray-300: oklch(87.2% 0.01 258.338);\n --color-gray-400: oklch(70.7% 0.022 261.325);\n --color-gray-500: oklch(55.1% 0.027 264.364);\n --color-gray-600: oklch(44.6% 0.03 256.802);\n --color-gray-700: oklch(37.3% 0.034 259.733);\n --color-gray-800: oklch(27.8% 0.033 256.848);\n --color-gray-900: oklch(21% 0.034 264.665);\n --color-gray-950: oklch(13% 0.028 261.692);\n\n --color-zinc-50: oklch(98.5% 0 none);\n --color-zinc-100: oklch(96.7% 0.001 286.375);\n --color-zinc-200: oklch(92% 0.004 286.32);\n --color-zinc-300: oklch(87.1% 0.006 286.286);\n --color-zinc-400: oklch(70.5% 0.015 286.067);\n --color-zinc-500: oklch(55.2% 0.016 285.938);\n --color-zinc-600: oklch(44.2% 0.017 285.786);\n --color-zinc-700: oklch(37% 0.013 285.805);\n --color-zinc-800: oklch(27.4% 0.006 286.033);\n --color-zinc-900: oklch(21% 0.006 285.885);\n --color-zinc-950: oklch(14.1% 0.005 285.823);\n\n --color-neutral-50: oklch(98.5% 0 none);\n --color-neutral-100: oklch(97% 0 none);\n --color-neutral-200: oklch(92.2% 0 none);\n --color-neutral-300: oklch(87% 0 none);\n --color-neutral-400: oklch(70.8% 0 none);\n --color-neutral-500: oklch(55.6% 0 none);\n --color-neutral-600: oklch(43.9% 0 none);\n --color-neutral-700: oklch(37.1% 0 none);\n --color-neutral-800: oklch(26.9% 0 none);\n --color-neutral-900: oklch(20.5% 0 none);\n --color-neutral-950: oklch(14.5% 0 none);\n\n --color-stone-50: oklch(98.5% 0.001 106.423);\n --color-stone-100: oklch(97% 0.001 106.424);\n --color-stone-200: oklch(92.3% 0.003 48.717);\n --color-stone-300: oklch(86.9% 0.005 56.366);\n --color-stone-400: oklch(70.9% 0.01 56.259);\n --color-stone-500: oklch(55.3% 0.013 58.071);\n --color-stone-600: oklch(44.4% 0.011 73.639);\n --color-stone-700: oklch(37.4% 0.01 67.558);\n --color-stone-800: oklch(26.8% 0.007 34.298);\n --color-stone-900: oklch(21.6% 0.006 56.043);\n --color-stone-950: oklch(14.7% 0.004 49.25);\n\n --color-mauve-50: oklch(98.5% 0 none);\n --color-mauve-100: oklch(96% 0.003 325.6);\n --color-mauve-200: oklch(92.2% 0.005 325.62);\n --color-mauve-300: oklch(86.5% 0.012 325.68);\n --color-mauve-400: oklch(71.1% 0.019 323.02);\n --color-mauve-500: oklch(54.2% 0.034 322.5);\n --color-mauve-600: oklch(43.5% 0.029 321.78);\n --color-mauve-700: oklch(36.4% 0.029 323.89);\n --color-mauve-800: oklch(26.3% 0.024 320.12);\n --color-mauve-900: oklch(21.2% 0.019 322.12);\n --color-mauve-950: oklch(14.5% 0.008 326);\n\n --color-olive-50: oklch(98.8% 0.003 106.5);\n --color-olive-100: oklch(96.6% 0.005 106.5);\n --color-olive-200: oklch(93% 0.007 106.5);\n --color-olive-300: oklch(88% 0.011 106.6);\n --color-olive-400: oklch(73.7% 0.021 106.9);\n --color-olive-500: oklch(58% 0.031 107.3);\n --color-olive-600: oklch(46.6% 0.025 107.3);\n --color-olive-700: oklch(39.4% 0.023 107.4);\n --color-olive-800: oklch(28.6% 0.016 107.4);\n --color-olive-900: oklch(22.8% 0.013 107.4);\n --color-olive-950: oklch(15.3% 0.006 107.1);\n\n --color-mist-50: oklch(98.7% 0.002 197.1);\n --color-mist-100: oklch(96.3% 0.002 197.1);\n --color-mist-200: oklch(92.5% 0.005 214.3);\n --color-mist-300: oklch(87.2% 0.007 219.6);\n --color-mist-400: oklch(72.3% 0.014 214.4);\n --color-mist-500: oklch(56% 0.021 213.5);\n --color-mist-600: oklch(45% 0.017 213.2);\n --color-mist-700: oklch(37.8% 0.015 216);\n --color-mist-800: oklch(27.5% 0.011 216.9);\n --color-mist-900: oklch(21.8% 0.008 223.9);\n --color-mist-950: oklch(14.8% 0.004 228.8);\n\n --color-taupe-50: oklch(98.6% 0.002 67.8);\n --color-taupe-100: oklch(96% 0.002 17.2);\n --color-taupe-200: oklch(92.2% 0.005 34.3);\n --color-taupe-300: oklch(86.8% 0.007 39.5);\n --color-taupe-400: oklch(71.4% 0.014 41.2);\n --color-taupe-500: oklch(54.7% 0.021 43.1);\n --color-taupe-600: oklch(43.8% 0.017 39.3);\n --color-taupe-700: oklch(36.7% 0.016 35.7);\n --color-taupe-800: oklch(26.8% 0.011 36.5);\n --color-taupe-900: oklch(21.4% 0.009 43.1);\n --color-taupe-950: oklch(14.7% 0.004 49.3);\n\n --color-black: #000;\n --color-white: #fff;\n\n --spacing: 0.25rem;\n\n --breakpoint-sm: 40rem;\n --breakpoint-md: 48rem;\n --breakpoint-lg: 64rem;\n --breakpoint-xl: 80rem;\n --breakpoint-2xl: 96rem;\n\n --container-3xs: 16rem;\n --container-2xs: 18rem;\n --container-xs: 20rem;\n --container-sm: 24rem;\n --container-md: 28rem;\n --container-lg: 32rem;\n --container-xl: 36rem;\n --container-2xl: 42rem;\n --container-3xl: 48rem;\n --container-4xl: 56rem;\n --container-5xl: 64rem;\n --container-6xl: 72rem;\n --container-7xl: 80rem;\n\n --text-xs: 0.75rem;\n --text-xs--line-height: calc(1 / 0.75);\n --text-sm: 0.875rem;\n --text-sm--line-height: calc(1.25 / 0.875);\n --text-base: 1rem;\n --text-base--line-height: calc(1.5 / 1);\n --text-lg: 1.125rem;\n --text-lg--line-height: calc(1.75 / 1.125);\n --text-xl: 1.25rem;\n --text-xl--line-height: calc(1.75 / 1.25);\n --text-2xl: 1.5rem;\n --text-2xl--line-height: calc(2 / 1.5);\n --text-3xl: 1.875rem;\n --text-3xl--line-height: calc(2.25 / 1.875);\n --text-4xl: 2.25rem;\n --text-4xl--line-height: calc(2.5 / 2.25);\n --text-5xl: 3rem;\n --text-5xl--line-height: 1;\n --text-6xl: 3.75rem;\n --text-6xl--line-height: 1;\n --text-7xl: 4.5rem;\n --text-7xl--line-height: 1;\n --text-8xl: 6rem;\n --text-8xl--line-height: 1;\n --text-9xl: 8rem;\n --text-9xl--line-height: 1;\n\n --font-weight-thin: 100;\n --font-weight-extralight: 200;\n --font-weight-light: 300;\n --font-weight-normal: 400;\n --font-weight-medium: 500;\n --font-weight-semibold: 600;\n --font-weight-bold: 700;\n --font-weight-extrabold: 800;\n --font-weight-black: 900;\n\n --tracking-tighter: -0.05em;\n --tracking-tight: -0.025em;\n --tracking-normal: 0em;\n --tracking-wide: 0.025em;\n --tracking-wider: 0.05em;\n --tracking-widest: 0.1em;\n\n --leading-tight: 1.25;\n --leading-snug: 1.375;\n --leading-normal: 1.5;\n --leading-relaxed: 1.625;\n --leading-loose: 2;\n\n --radius-xs: 0.125rem;\n --radius-sm: 0.25rem;\n --radius-md: 0.375rem;\n --radius-lg: 0.5rem;\n --radius-xl: 0.75rem;\n --radius-2xl: 1rem;\n --radius-3xl: 1.5rem;\n --radius-4xl: 2rem;\n\n --shadow-2xs: 0 1px rgb(0 0 0 / 0.05);\n --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.05);\n --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);\n --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);\n --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);\n --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);\n --shadow-2xl: 0 25px 50px -12px rgb(0 0 0 / 0.25);\n\n --inset-shadow-2xs: inset 0 1px rgb(0 0 0 / 0.05);\n --inset-shadow-xs: inset 0 1px 1px rgb(0 0 0 / 0.05);\n --inset-shadow-sm: inset 0 2px 4px rgb(0 0 0 / 0.05);\n\n --drop-shadow-xs: 0 1px 1px rgb(0 0 0 / 0.05);\n --drop-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.15);\n --drop-shadow-md: 0 3px 3px rgb(0 0 0 / 0.12);\n --drop-shadow-lg: 0 4px 4px rgb(0 0 0 / 0.15);\n --drop-shadow-xl: 0 9px 7px rgb(0 0 0 / 0.1);\n --drop-shadow-2xl: 0 25px 25px rgb(0 0 0 / 0.15);\n\n --text-shadow-2xs: 0px 1px 0px rgb(0 0 0 / 0.15);\n --text-shadow-xs: 0px 1px 1px rgb(0 0 0 / 0.2);\n --text-shadow-sm:\n 0px 1px 0px rgb(0 0 0 / 0.075), 0px 1px 1px rgb(0 0 0 / 0.075), 0px 2px 2px rgb(0 0 0 / 0.075);\n --text-shadow-md:\n 0px 1px 1px rgb(0 0 0 / 0.1), 0px 1px 2px rgb(0 0 0 / 0.1), 0px 2px 4px rgb(0 0 0 / 0.1);\n --text-shadow-lg:\n 0px 1px 2px rgb(0 0 0 / 0.1), 0px 3px 2px rgb(0 0 0 / 0.1), 0px 4px 8px rgb(0 0 0 / 0.1);\n\n --ease-in: cubic-bezier(0.4, 0, 1, 1);\n --ease-out: cubic-bezier(0, 0, 0.2, 1);\n --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);\n\n --animate-spin: spin 1s linear infinite;\n --animate-ping: ping 1s cubic-bezier(0, 0, 0.2, 1) infinite;\n --animate-pulse: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;\n --animate-bounce: bounce 1s infinite;\n\n @keyframes spin {\n to {\n transform: rotate(360deg);\n }\n }\n\n @keyframes ping {\n 75%,\n 100% {\n transform: scale(2);\n opacity: 0;\n }\n }\n\n @keyframes pulse {\n 50% {\n opacity: 0.5;\n }\n }\n\n @keyframes bounce {\n 0%,\n 100% {\n transform: translateY(-25%);\n animation-timing-function: cubic-bezier(0.8, 0, 1, 1);\n }\n\n 50% {\n transform: none;\n animation-timing-function: cubic-bezier(0, 0, 0.2, 1);\n }\n }\n\n --blur-xs: 4px;\n --blur-sm: 8px;\n --blur-md: 12px;\n --blur-lg: 16px;\n --blur-xl: 24px;\n --blur-2xl: 40px;\n --blur-3xl: 64px;\n\n --perspective-dramatic: 100px;\n --perspective-near: 300px;\n --perspective-normal: 500px;\n --perspective-midrange: 800px;\n --perspective-distant: 1200px;\n\n --aspect-video: 16 / 9;\n\n --default-transition-duration: 150ms;\n --default-transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);\n --default-font-family: --theme(--font-sans, initial);\n --default-font-feature-settings: --theme(--font-sans--font-feature-settings, initial);\n --default-font-variation-settings: --theme(--font-sans--font-variation-settings, initial);\n --default-mono-font-family: --theme(--font-mono, initial);\n --default-mono-font-feature-settings: --theme(--font-mono--font-feature-settings, initial);\n --default-mono-font-variation-settings: --theme(--font-mono--font-variation-settings, initial);\n}\n\n/* Deprecated */\n@theme default inline reference {\n --blur: 8px;\n --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);\n --shadow-inner: inset 0 2px 4px 0 rgb(0 0 0 / 0.05);\n --drop-shadow: 0 1px 2px rgb(0 0 0 / 0.1), 0 1px 1px rgb(0 0 0 / 0.06);\n --radius: 0.25rem;\n --max-width-prose: 65ch;\n}\n",
|
|
825
|
+
"tailwindcss/utilities.css": "@tailwind utilities;\n",
|
|
826
|
+
"tailwindcss/preflight.css": "/*\n 1. Prevent padding and border from affecting element width. (https://github.com/mozdevs/cssremedy/issues/4)\n 2. Remove default margins and padding\n 3. Reset all borders.\n*/\n\n*,\n::after,\n::before,\n::backdrop,\n::file-selector-button {\n box-sizing: border-box; /* 1 */\n margin: 0; /* 2 */\n padding: 0; /* 2 */\n border: 0 solid; /* 3 */\n}\n\n/*\n 1. Use a consistent sensible line-height in all browsers.\n 2. Prevent adjustments of font size after orientation changes in iOS.\n 3. Use a more readable tab size.\n 4. Use the user's configured `sans` font-family by default.\n 5. Use the user's configured `sans` font-feature-settings by default.\n 6. Use the user's configured `sans` font-variation-settings by default.\n 7. Disable tap highlights on iOS.\n*/\n\nhtml,\n:host {\n line-height: 1.5; /* 1 */\n -webkit-text-size-adjust: 100%; /* 2 */\n tab-size: 4; /* 3 */\n font-family: --theme(\n --default-font-family,\n -apple-system,\n BlinkMacSystemFont,\n 'Segoe UI',\n Roboto,\n 'Helvetica Neue',\n 'Noto Sans',\n Arial,\n sans-serif,\n 'Apple Color Emoji',\n 'Segoe UI Emoji',\n 'Segoe UI Symbol',\n 'Noto Color Emoji'\n ); /* 4 */\n font-feature-settings: --theme(--default-font-feature-settings, normal); /* 5 */\n font-variation-settings: --theme(--default-font-variation-settings, normal); /* 6 */\n -webkit-tap-highlight-color: transparent; /* 7 */\n}\n\n/*\n 1. Add the correct height in Firefox.\n 2. Correct the inheritance of border color in Firefox. (https://bugzilla.mozilla.org/show_bug.cgi?id=190655)\n 3. Reset the default border style to a 1px solid border.\n*/\n\nhr {\n height: 0; /* 1 */\n color: inherit; /* 2 */\n border-top-width: 1px; /* 3 */\n}\n\n/*\n Add the correct text decoration in Chrome, Edge, and Safari.\n*/\n\nabbr:where([title]) {\n -webkit-text-decoration: underline dotted;\n text-decoration: underline dotted;\n}\n\n/*\n Remove the default font size and weight for headings.\n*/\n\nh1,\nh2,\nh3,\nh4,\nh5,\nh6 {\n font-size: inherit;\n font-weight: inherit;\n}\n\n/*\n Reset links to optimize for opt-in styling instead of opt-out.\n*/\n\na {\n color: inherit;\n -webkit-text-decoration: inherit;\n text-decoration: inherit;\n}\n\n/*\n Add the correct font weight in Edge and Safari.\n*/\n\nb,\nstrong {\n font-weight: bolder;\n}\n\n/*\n 1. Use the user's configured `mono` font-family by default.\n 2. Use the user's configured `mono` font-feature-settings by default.\n 3. Use the user's configured `mono` font-variation-settings by default.\n 4. Correct the odd `em` font sizing in all browsers.\n*/\n\ncode,\nkbd,\nsamp,\npre {\n font-family: --theme(\n --default-mono-font-family,\n ui-monospace,\n SFMono-Regular,\n Menlo,\n Monaco,\n Consolas,\n 'Liberation Mono',\n 'Courier New',\n monospace\n ); /* 1 */\n font-feature-settings: --theme(--default-mono-font-feature-settings, normal); /* 2 */\n font-variation-settings: --theme(--default-mono-font-variation-settings, normal); /* 3 */\n font-size: 1em; /* 4 */\n}\n\n/*\n Add the correct font size in all browsers.\n*/\n\nsmall {\n font-size: 80%;\n}\n\n/*\n Prevent `sub` and `sup` elements from affecting the line height in all browsers.\n*/\n\nsub,\nsup {\n font-size: 75%;\n line-height: 0;\n position: relative;\n vertical-align: baseline;\n}\n\nsub {\n bottom: -0.25em;\n}\n\nsup {\n top: -0.5em;\n}\n\n/*\n 1. Remove text indentation from table contents in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=999088, https://bugs.webkit.org/show_bug.cgi?id=201297)\n 2. Correct table border color inheritance in all Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=935729, https://bugs.webkit.org/show_bug.cgi?id=195016)\n 3. Remove gaps between table borders by default.\n*/\n\ntable {\n text-indent: 0; /* 1 */\n border-color: inherit; /* 2 */\n border-collapse: collapse; /* 3 */\n}\n\n/*\n Use the modern Firefox focus style for all focusable elements.\n*/\n\n:-moz-focusring:where(:not(iframe)) {\n outline: auto;\n}\n\n/*\n Add the correct vertical alignment in Chrome and Firefox.\n*/\n\nprogress {\n vertical-align: baseline;\n}\n\n/*\n Add the correct display in Chrome and Safari.\n*/\n\nsummary {\n display: list-item;\n}\n\n/*\n Make lists unstyled by default.\n*/\n\nol,\nul,\nmenu {\n list-style: none;\n}\n\n/*\n 1. Make replaced elements `display: block` by default. (https://github.com/mozdevs/cssremedy/issues/14)\n 2. Add `vertical-align: middle` to align replaced elements more sensibly by default. (https://github.com/jensimmons/cssremedy/issues/14#issuecomment-634934210)\n This can trigger a poorly considered lint error in some tools but is included by design.\n*/\n\nimg,\nsvg,\nvideo,\ncanvas,\naudio,\niframe,\nembed,\nobject {\n display: block; /* 1 */\n vertical-align: middle; /* 2 */\n}\n\n/*\n Constrain images and videos to the parent width and preserve their intrinsic aspect ratio. (https://github.com/mozdevs/cssremedy/issues/14)\n*/\n\nimg,\nvideo {\n max-width: 100%;\n height: auto;\n}\n\n/*\n 1. Inherit font styles in all browsers.\n 2. Remove border radius in all browsers.\n 3. Remove background color in all browsers.\n 4. Ensure consistent opacity for disabled states in all browsers.\n*/\n\nbutton,\ninput,\nselect,\noptgroup,\ntextarea,\n::file-selector-button {\n font: inherit; /* 1 */\n font-feature-settings: inherit; /* 1 */\n font-variation-settings: inherit; /* 1 */\n letter-spacing: inherit; /* 1 */\n color: inherit; /* 1 */\n border-radius: 0; /* 2 */\n background-color: transparent; /* 3 */\n opacity: 1; /* 4 */\n}\n\n/*\n Restore default font weight.\n*/\n\n:where(select:is([multiple], [size])) optgroup {\n font-weight: bolder;\n}\n\n/*\n Restore indentation.\n*/\n\n:where(select:is([multiple], [size])) optgroup option {\n padding-inline-start: 20px;\n}\n\n/*\n Restore space after button.\n*/\n\n::file-selector-button {\n margin-inline-end: 4px;\n}\n\n/*\n Reset the default placeholder opacity in Firefox. (https://github.com/tailwindlabs/tailwindcss/issues/3300)\n*/\n\n::placeholder {\n opacity: 1;\n}\n\n/*\n Set the default placeholder color to a semi-transparent version of the current text color in browsers that do not\n crash when using `color-mix(…)` with `currentcolor`. (https://github.com/tailwindlabs/tailwindcss/issues/17194)\n*/\n\n@supports (not (-webkit-appearance: -apple-pay-button)) /* Not Safari */ or\n (contain-intrinsic-size: 1px) /* Safari 17+ */ {\n ::placeholder {\n color: color-mix(in oklab, currentcolor 50%, transparent);\n }\n}\n\n/*\n Prevent resizing textareas horizontally by default.\n*/\n\ntextarea {\n resize: vertical;\n}\n\n/*\n Remove the inner padding in Chrome and Safari on macOS.\n*/\n\n::-webkit-search-decoration {\n -webkit-appearance: none;\n}\n\n/*\n 1. Ensure date/time inputs have the same height when empty in iOS Safari.\n 2. Ensure text alignment can be changed on date/time inputs in iOS Safari.\n*/\n\n::-webkit-date-and-time-value {\n min-height: 1lh; /* 1 */\n text-align: inherit; /* 2 */\n}\n\n/*\n Prevent height from changing on date/time inputs in macOS Safari when the input is set to `display: block`.\n*/\n\n::-webkit-datetime-edit {\n display: inline-flex;\n}\n\n/*\n Remove excess padding from pseudo-elements in date/time inputs to ensure consistent height across browsers.\n*/\n\n::-webkit-datetime-edit-fields-wrapper {\n padding: 0;\n}\n\n::-webkit-datetime-edit,\n::-webkit-datetime-edit-year-field,\n::-webkit-datetime-edit-month-field,\n::-webkit-datetime-edit-day-field,\n::-webkit-datetime-edit-hour-field,\n::-webkit-datetime-edit-minute-field,\n::-webkit-datetime-edit-second-field,\n::-webkit-datetime-edit-millisecond-field,\n::-webkit-datetime-edit-meridiem-field {\n padding-block: 0;\n}\n\n/*\n Center dropdown marker shown on inputs with paired `<datalist>`s in Chrome. (https://github.com/tailwindlabs/tailwindcss/issues/18499)\n*/\n\n::-webkit-calendar-picker-indicator {\n line-height: 1;\n}\n\n/*\n Remove the additional `:invalid` styles in Firefox. (https://github.com/mozilla/gecko-dev/blob/2f9eacd9d3d995c937b4251a5557d95d494c9be1/layout/style/res/forms.css#L728-L737)\n*/\n\n:-moz-ui-invalid {\n box-shadow: none;\n}\n\n/*\n Correct the inability to style the border radius in iOS Safari.\n*/\n\nbutton,\ninput:where([type='button'], [type='reset'], [type='submit']),\n::file-selector-button {\n appearance: button;\n}\n\n/*\n Correct the cursor style of increment and decrement buttons in Safari.\n*/\n\n::-webkit-inner-spin-button,\n::-webkit-outer-spin-button {\n height: auto;\n}\n\n/*\n Make elements with the HTML hidden attribute stay hidden by default.\n*/\n\n[hidden]:where(:not([hidden='until-found'])) {\n display: none !important;\n}\n"
|
|
827
|
+
};
|
|
828
|
+
/**
|
|
829
|
+
* Mark every `@theme` in project and brand CSS `static`. Tailwind emits a
|
|
830
|
+
* theme variable only when a utility it generated reads it, but a project's
|
|
831
|
+
* own stylesheets read theme variables too (`color: var(--color-brand)`), and
|
|
832
|
+
* Tailwind never sees those rules. A later layer that redefines a variable
|
|
833
|
+
* replaces its options, so every layer has to carry `static` for the value
|
|
834
|
+
* the cascade settles on to reach the inliner.
|
|
835
|
+
*/
|
|
836
|
+
const staticTheme = (css) => {
|
|
837
|
+
const ast = parse(css, {
|
|
838
|
+
positions: true,
|
|
839
|
+
parseValue: false,
|
|
840
|
+
parseRulePrelude: false,
|
|
841
|
+
parseCustomProperty: false
|
|
842
|
+
});
|
|
843
|
+
const insertions = [];
|
|
844
|
+
walk(ast, (node) => {
|
|
845
|
+
if (node.type !== "Atrule" || node.name.toLowerCase() !== "theme" || node.loc == null) return;
|
|
846
|
+
const prelude = node.prelude === null ? "" : css.slice(node.prelude.loc?.start.offset ?? 0, node.prelude.loc?.end.offset ?? 0);
|
|
847
|
+
if (/(?:^|\s)static(?:\s|$)/i.test(prelude)) return;
|
|
848
|
+
insertions.push(node.loc.start.offset + 6);
|
|
849
|
+
});
|
|
850
|
+
let output = css;
|
|
851
|
+
for (const offset of insertions.reverse()) output = `${output.slice(0, offset)} static${output.slice(offset)}`;
|
|
852
|
+
return output;
|
|
853
|
+
};
|
|
854
|
+
/** Compile the discovered class set into CSS with the pinned Tailwind release. */
|
|
855
|
+
const compileTailwind = async (candidates, options = {}, imports = { stylesheets: /* @__PURE__ */ new Map() }) => {
|
|
856
|
+
const entry = [
|
|
857
|
+
"@layer theme, base, components, utilities;",
|
|
858
|
+
"@import \"tailwindcss/theme.css\" layer(theme);",
|
|
859
|
+
...options.preflight === true ? ["@import \"tailwindcss/preflight.css\" layer(base);"] : [],
|
|
860
|
+
"@import \"tailwindcss/utilities.css\" layer(utilities);",
|
|
861
|
+
staticTheme(options.css ?? "")
|
|
862
|
+
].join("\n");
|
|
863
|
+
const compiler = await compile(entry, {
|
|
864
|
+
base: projectDirectory(options.cssPath ?? "theme.css"),
|
|
865
|
+
loadStylesheet: (id, base) => {
|
|
866
|
+
const builtIn = STYLESHEETS[id];
|
|
867
|
+
if (builtIn !== void 0) return Promise.resolve({
|
|
868
|
+
path: id,
|
|
869
|
+
base,
|
|
870
|
+
content: builtIn
|
|
871
|
+
});
|
|
872
|
+
if (/^samva:brand(?:\/|$)/.test(id)) {
|
|
873
|
+
if (imports.brandCss === void 0) throw new TypeError(`${id} has no brand in this build`);
|
|
874
|
+
return Promise.resolve({
|
|
875
|
+
path: id,
|
|
876
|
+
base,
|
|
877
|
+
content: staticTheme(imports.brandCss)
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
const path = resolveFromDirectory(base, id.replace(/[?#].*$/, ""));
|
|
881
|
+
const content = path === void 0 ? void 0 : imports.stylesheets.get(path);
|
|
882
|
+
if (path === void 0 || content === void 0) throw new TypeError(`@import ${JSON.stringify(id)} names no project stylesheet`);
|
|
883
|
+
return Promise.resolve({
|
|
884
|
+
path,
|
|
885
|
+
base: projectDirectory(path),
|
|
886
|
+
content: staticTheme(content)
|
|
887
|
+
});
|
|
888
|
+
}
|
|
889
|
+
});
|
|
890
|
+
const all = [.../* @__PURE__ */ new Set([...candidates, ...options.safelist ?? []])].sort();
|
|
891
|
+
const limits = options.limits;
|
|
892
|
+
if (limits !== void 0 && all.length > limits.candidates) throw new TypeError(`Tailwind candidate limit exceeded: ${all.length} classes, limit ${limits.candidates}. Reduce the utility classes this project uses, or its declared safelist.`);
|
|
893
|
+
const css = compiler.build(all);
|
|
894
|
+
const bytes = new TextEncoder().encode(css).length;
|
|
895
|
+
if (limits !== void 0 && bytes > limits.cssBytes) throw new TypeError(`Generated CSS limit exceeded: ${bytes} bytes, limit ${limits.cssBytes}. Reduce the utility classes this project uses, or its declared safelist.`);
|
|
896
|
+
return {
|
|
897
|
+
css,
|
|
898
|
+
version: TAILWIND_VERSION,
|
|
899
|
+
candidates: all
|
|
900
|
+
};
|
|
901
|
+
};
|
|
902
|
+
const isRecord = (value) => isObject(value) && !Array.isArray(value);
|
|
903
|
+
const isAstNode = (value) => isRecord(value) && typeof value.type === "string" && typeof value.start === "number" && typeof value.end === "number";
|
|
904
|
+
const walk$1 = (value, visit) => {
|
|
905
|
+
if (Array.isArray(value)) {
|
|
906
|
+
for (const item of value) walk$1(item, visit);
|
|
907
|
+
return;
|
|
908
|
+
}
|
|
909
|
+
if (!isRecord(value)) return;
|
|
910
|
+
if (isAstNode(value)) visit(value);
|
|
911
|
+
for (const [key, child] of Object.entries(value)) {
|
|
912
|
+
if (key === "loc" || key === "extra" || key === "comments" || key === "tokens") continue;
|
|
913
|
+
walk$1(child, visit);
|
|
914
|
+
}
|
|
915
|
+
};
|
|
916
|
+
const CLASS_KEYS = /* @__PURE__ */ new Set(["class", "className"]);
|
|
917
|
+
const nameOf = (node) => {
|
|
918
|
+
if (!isAstNode(node)) return void 0;
|
|
919
|
+
if (node.type === "JSXIdentifier" || node.type === "Identifier") return typeof node.name === "string" ? node.name : void 0;
|
|
920
|
+
if (node.type === "StringLiteral") return typeof node.value === "string" ? node.value : void 0;
|
|
921
|
+
};
|
|
922
|
+
/**
|
|
923
|
+
* Collect the class names one module states literally, and report the positions
|
|
924
|
+
* where a class is assembled from values the compiler cannot see.
|
|
925
|
+
*/
|
|
926
|
+
const discoverClassCandidates = (source, fileName) => {
|
|
927
|
+
let parsed;
|
|
928
|
+
try {
|
|
929
|
+
parsed = parse$1(source, {
|
|
930
|
+
plugins: ["typescript", "jsx"],
|
|
931
|
+
sourceType: "module"
|
|
932
|
+
});
|
|
933
|
+
} catch {
|
|
934
|
+
return {
|
|
935
|
+
candidates: [],
|
|
936
|
+
diagnostics: []
|
|
937
|
+
};
|
|
938
|
+
}
|
|
939
|
+
const lineMap = buildLineMap(source);
|
|
940
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
941
|
+
const diagnostics = [];
|
|
942
|
+
const at = (offset) => {
|
|
943
|
+
const position = lineColumn(lineMap, offset);
|
|
944
|
+
return {
|
|
945
|
+
fileName,
|
|
946
|
+
lineNumber: position.line,
|
|
947
|
+
columnNumber: position.column
|
|
948
|
+
};
|
|
949
|
+
};
|
|
950
|
+
/** Returns true when every class in the expression is statically known. */
|
|
951
|
+
const readValue = (node) => {
|
|
952
|
+
if (!isAstNode(node)) return false;
|
|
953
|
+
switch (node.type) {
|
|
954
|
+
case "StringLiteral":
|
|
955
|
+
if (typeof node.value !== "string") return false;
|
|
956
|
+
for (const name of node.value.split(/\s+/)) if (name !== "") candidates.add(name);
|
|
957
|
+
return true;
|
|
958
|
+
case "TemplateLiteral": {
|
|
959
|
+
const quasis = Array.isArray(node.quasis) ? node.quasis : [];
|
|
960
|
+
for (const quasi of quasis) {
|
|
961
|
+
const cooked = isAstNode(quasi) && isRecord(quasi.value) ? quasi.value.cooked : void 0;
|
|
962
|
+
if (typeof cooked !== "string") continue;
|
|
963
|
+
for (const name of cooked.split(/\s+/)) if (name !== "") candidates.add(name);
|
|
964
|
+
}
|
|
965
|
+
return Array.isArray(node.expressions) && node.expressions.length === 0;
|
|
966
|
+
}
|
|
967
|
+
case "JSXExpressionContainer": return readValue(node.expression);
|
|
968
|
+
case "ConditionalExpression": return [node.consequent, node.alternate].every((branch) => readValue(branch));
|
|
969
|
+
case "LogicalExpression": return readValue(node.right);
|
|
970
|
+
case "BinaryExpression": return node.operator === "+" && [node.left, node.right].every((side) => readValue(side));
|
|
971
|
+
case "ArrayExpression": return Array.isArray(node.elements) && node.elements.every((element) => readValue(element));
|
|
972
|
+
default: return false;
|
|
973
|
+
}
|
|
974
|
+
};
|
|
975
|
+
walk$1(parsed.program, (node) => {
|
|
976
|
+
const isJsxAttribute = node.type === "JSXAttribute";
|
|
977
|
+
const isObjectProperty = node.type === "ObjectProperty";
|
|
978
|
+
if (!isJsxAttribute && !isObjectProperty) return;
|
|
979
|
+
const key = nameOf(isJsxAttribute ? node.name : node.key);
|
|
980
|
+
if (key === void 0 || !CLASS_KEYS.has(key)) return;
|
|
981
|
+
const value = isJsxAttribute ? node.value : node.value;
|
|
982
|
+
if (value === null || value === void 0) return;
|
|
983
|
+
if (readValue(value)) return;
|
|
984
|
+
diagnostics.push({
|
|
985
|
+
code: "tailwind-dynamic-class",
|
|
986
|
+
severity: "warning",
|
|
987
|
+
message: `This ${key} is assembled at run time, so the compiler cannot discover the classes it produces and they will have no styles. Write the classes literally, or declare them in the project's Tailwind safelist.`,
|
|
988
|
+
origins: [at(node.start)]
|
|
989
|
+
});
|
|
990
|
+
});
|
|
991
|
+
return {
|
|
992
|
+
candidates: [...candidates].sort(),
|
|
993
|
+
diagnostics
|
|
994
|
+
};
|
|
995
|
+
};
|
|
996
|
+
//#endregion
|
|
997
|
+
//#region src/email/transform.ts
|
|
998
|
+
const SCRIPT = /\.[cm]?[jt]sx?$/;
|
|
999
|
+
/**
|
|
1000
|
+
* The project path a stylesheet URL names, resolved from the stylesheet's own
|
|
1001
|
+
* directory (a leading `/` means the project root), or `undefined` when it
|
|
1002
|
+
* climbs out of the project.
|
|
1003
|
+
*/
|
|
1004
|
+
const resolveProjectPath = (from, reference) => resolveFromDirectory(projectDirectory(from), reference.replace(/[?#].*$/, ""));
|
|
1005
|
+
const readStylesheet = (id, source, options, assets = /* @__PURE__ */ new Map(), themeImports = false) => {
|
|
1006
|
+
const sheet = parseStylesheet(source, {
|
|
1007
|
+
origin: id,
|
|
1008
|
+
themeImports,
|
|
1009
|
+
resolveFontFile: (reference) => {
|
|
1010
|
+
const path = resolveProjectPath(id, reference);
|
|
1011
|
+
const entry = path === void 0 ? void 0 : assets.get(path);
|
|
1012
|
+
return entry === void 0 ? void 0 : assetUrl(entry, options.assetBase);
|
|
1013
|
+
}
|
|
1014
|
+
});
|
|
1015
|
+
return {
|
|
1016
|
+
sheet: {
|
|
1017
|
+
rules: sheet.rules,
|
|
1018
|
+
headAtRules: sheet.headAtRules,
|
|
1019
|
+
fontFaces: sheet.fontFaces,
|
|
1020
|
+
variables: sheet.variables,
|
|
1021
|
+
diagnostics: []
|
|
1022
|
+
},
|
|
1023
|
+
diagnostics: sheet.diagnostics
|
|
1024
|
+
};
|
|
1025
|
+
};
|
|
1026
|
+
/**
|
|
1027
|
+
* Read one project file. A stylesheet is parsed, with its `@font-face` sources resolved against
|
|
1028
|
+
* `assets`, the project's addressed files by path. An imported binary is content-addressed. A
|
|
1029
|
+
* script contributes the utility classes it states literally.
|
|
1030
|
+
*/
|
|
1031
|
+
const readFile = async (id, source, options, assets) => {
|
|
1032
|
+
if (isAssetPath(id)) {
|
|
1033
|
+
const bytes = typeof source === "string" ? new TextEncoder().encode(source) : source;
|
|
1034
|
+
return {
|
|
1035
|
+
asset: await assetEntry(id, bytes),
|
|
1036
|
+
diagnostics: checkAssetBase(options.assetBase)
|
|
1037
|
+
};
|
|
1038
|
+
}
|
|
1039
|
+
const text = typeof source === "string" ? source : new TextDecoder().decode(source);
|
|
1040
|
+
if (id.endsWith(".css")) return readStylesheet(id, text, options, assets);
|
|
1041
|
+
if (!SCRIPT.test(id)) return { diagnostics: [] };
|
|
1042
|
+
const discovered = options.tailwind === false ? void 0 : discoverClassCandidates(text, id);
|
|
1043
|
+
return {
|
|
1044
|
+
classes: discovered?.candidates,
|
|
1045
|
+
diagnostics: discovered?.diagnostics ?? []
|
|
1046
|
+
};
|
|
1047
|
+
};
|
|
1048
|
+
/** The Tailwind sheet's stylesheet origin. */
|
|
1049
|
+
const TAILWIND_ORIGIN = ".samva-tailwind.css";
|
|
1050
|
+
/** `samva:brand` / `samva:brand/<slug>` as a module specifier in an import or export. */
|
|
1051
|
+
const BRAND_MODULE_SPECIFIER = /(\b(?:from|import)\s*\(?\s*)(["'])(samva:brand(?:\/[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?)?)\2/g;
|
|
1052
|
+
/** The `samva:brand` specifiers a script imports, with where it asks for each. */
|
|
1053
|
+
const scriptBrandImports = (path, source) => {
|
|
1054
|
+
const lines = buildLineMap(source);
|
|
1055
|
+
return [...source.matchAll(BRAND_MODULE_SPECIFIER)].map((match) => {
|
|
1056
|
+
const at = lineColumn(lines, match.index + match[1].length);
|
|
1057
|
+
return {
|
|
1058
|
+
specifier: match[3],
|
|
1059
|
+
origin: {
|
|
1060
|
+
fileName: path,
|
|
1061
|
+
lineNumber: at.line,
|
|
1062
|
+
columnNumber: at.column
|
|
1063
|
+
}
|
|
1064
|
+
};
|
|
1065
|
+
});
|
|
1066
|
+
};
|
|
1067
|
+
/**
|
|
1068
|
+
* The `samva:brand` specifier a project imports — from its theme's `@import`s
|
|
1069
|
+
* or its TSX — so a host can fetch that brand before it compiles. `undefined`
|
|
1070
|
+
* when the project imports no brand. A project that names two brands gets the
|
|
1071
|
+
* first here and a refusal from the compile.
|
|
1072
|
+
*/
|
|
1073
|
+
const projectBrandSpecifier = (files, themePath = "theme.css") => {
|
|
1074
|
+
const theme = files[themePath];
|
|
1075
|
+
const fromTheme = typeof theme === "string" ? resolveThemeImports(themePath, theme, files).brandSpecifiers : [];
|
|
1076
|
+
const fromScripts = Object.keys(files).sort().filter((path) => SCRIPT.test(path) && typeof files[path] === "string").flatMap((path) => scriptBrandImports(path, files[path])).map((request) => request.specifier);
|
|
1077
|
+
return [...fromTheme, ...fromScripts][0];
|
|
1078
|
+
};
|
|
1079
|
+
/**
|
|
1080
|
+
* The theme stylesheet's `@import` graph and the brand the project reaches,
|
|
1081
|
+
* resolved before anything compiles. An import the compiler cannot resolve, a
|
|
1082
|
+
* brand the build was not given, two different brands, or a brand theme
|
|
1083
|
+
* outside its grammar refuses the whole compile: a theme that silently lost a
|
|
1084
|
+
* layer would ship the wrong look.
|
|
1085
|
+
*/
|
|
1086
|
+
const resolveTheme = (files, tailwind, brand) => {
|
|
1087
|
+
const refusals = [];
|
|
1088
|
+
const css = tailwind?.css;
|
|
1089
|
+
const themePath = tailwind?.cssPath ?? "theme.css";
|
|
1090
|
+
const imports = css === void 0 ? void 0 : resolveThemeImports(themePath, css, files);
|
|
1091
|
+
refusals.push(...imports?.diagnostics ?? []);
|
|
1092
|
+
const themeOrigin = {
|
|
1093
|
+
fileName: themePath,
|
|
1094
|
+
lineNumber: 1,
|
|
1095
|
+
columnNumber: 1
|
|
1096
|
+
};
|
|
1097
|
+
const cssRequests = (imports?.brandSpecifiers ?? []).map((specifier) => ({
|
|
1098
|
+
specifier,
|
|
1099
|
+
origin: themeOrigin
|
|
1100
|
+
}));
|
|
1101
|
+
const scriptRequests = Object.keys(files).sort().filter((path) => SCRIPT.test(path) && typeof files[path] === "string").flatMap((path) => scriptBrandImports(path, files[path]));
|
|
1102
|
+
const requests = [...cssRequests, ...scriptRequests];
|
|
1103
|
+
const specifiers = [...new Set(requests.map((request) => request.specifier))];
|
|
1104
|
+
if (specifiers.length > 1) refusals.push({
|
|
1105
|
+
code: "brand-import-conflict",
|
|
1106
|
+
severity: "error",
|
|
1107
|
+
message: `The project imports ${specifiers.join(" and ")}; a project compiles against one brand.`,
|
|
1108
|
+
origins: requests.map((request) => request.origin)
|
|
1109
|
+
});
|
|
1110
|
+
else if (specifiers.length === 1) {
|
|
1111
|
+
const specifier = specifiers[0];
|
|
1112
|
+
const named = parseBrandSpecifier(specifier)?.slug;
|
|
1113
|
+
const origins = [requests[0].origin];
|
|
1114
|
+
if (brand === void 0) refusals.push({
|
|
1115
|
+
code: "brand-unavailable",
|
|
1116
|
+
severity: "error",
|
|
1117
|
+
message: `${origins[0].fileName} imports ${specifier}, but this build has no brand to resolve it.`,
|
|
1118
|
+
origins
|
|
1119
|
+
});
|
|
1120
|
+
else if (named !== void 0 && named !== brand.slug) refusals.push({
|
|
1121
|
+
code: "brand-unavailable",
|
|
1122
|
+
severity: "error",
|
|
1123
|
+
message: `${origins[0].fileName} imports ${specifier}, but this build resolved brand ${brand.slug}.`,
|
|
1124
|
+
origins
|
|
1125
|
+
});
|
|
1126
|
+
}
|
|
1127
|
+
let brandCss;
|
|
1128
|
+
if (refusals.length === 0 && brand !== void 0 && cssRequests.length > 0) {
|
|
1129
|
+
const parsed = parseBrandCss(brand.css);
|
|
1130
|
+
if (parsed.isOk()) brandCss = brandTailwindCss(parsed.value);
|
|
1131
|
+
else {
|
|
1132
|
+
const lines = buildLineMap(brand.css);
|
|
1133
|
+
const specifier = cssRequests[0].specifier;
|
|
1134
|
+
for (const finding of parsed.error) {
|
|
1135
|
+
const at = lineColumn(lines, finding.span.start);
|
|
1136
|
+
refusals.push({
|
|
1137
|
+
code: finding.code,
|
|
1138
|
+
severity: "error",
|
|
1139
|
+
message: `${specifier}: ${finding.message}`,
|
|
1140
|
+
origins: [{
|
|
1141
|
+
fileName: specifier,
|
|
1142
|
+
lineNumber: at.line,
|
|
1143
|
+
columnNumber: at.column
|
|
1144
|
+
}]
|
|
1145
|
+
});
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
if (refusals.length > 0) throw new EmailCompileError({ diagnostics: refusals });
|
|
1150
|
+
return {
|
|
1151
|
+
stylesheets: imports?.stylesheets ?? /* @__PURE__ */ new Map(),
|
|
1152
|
+
brandCss,
|
|
1153
|
+
brandModule: scriptRequests.length > 0 ? brand : void 0
|
|
1154
|
+
};
|
|
1155
|
+
};
|
|
1156
|
+
/** Read a whole project, then compile the classes its scripts used. */
|
|
1157
|
+
const transformProject = async (files, options) => {
|
|
1158
|
+
const assets = [];
|
|
1159
|
+
const diagnostics = [];
|
|
1160
|
+
const stylesheets = /* @__PURE__ */ new Map();
|
|
1161
|
+
const classes = /* @__PURE__ */ new Set();
|
|
1162
|
+
const wanted = options.tailwind === false ? void 0 : options.tailwind ?? {};
|
|
1163
|
+
const theme = resolveTheme(files, wanted, options.brand);
|
|
1164
|
+
if (theme.brandModule !== void 0) for (const name of BRAND_COMPONENT_CLASSES) classes.add(name);
|
|
1165
|
+
const paths = Object.keys(files).sort();
|
|
1166
|
+
const binaries = new Map(await Promise.all(paths.filter(isAssetPath).map(async (path) => [path, await readFile(path, files[path], options)])));
|
|
1167
|
+
const addressed = new Map([...binaries].flatMap(([path, reading]) => reading.asset === void 0 ? [] : [[path, reading.asset]]));
|
|
1168
|
+
const readings = await Promise.all(paths.map((path) => binaries.get(path) ?? (theme.stylesheets.has(path) ? readStylesheet(path, theme.stylesheets.get(path), options, addressed, true) : readFile(path, files[path], options, addressed))));
|
|
1169
|
+
for (const [index, path] of paths.entries()) {
|
|
1170
|
+
const reading = readings[index];
|
|
1171
|
+
if (reading.asset !== void 0) assets.push(reading.asset);
|
|
1172
|
+
if (reading.sheet !== void 0) stylesheets.set(path, reading.sheet);
|
|
1173
|
+
for (const name of reading.classes ?? []) classes.add(name);
|
|
1174
|
+
diagnostics.push(...reading.diagnostics);
|
|
1175
|
+
}
|
|
1176
|
+
if (wanted === void 0 || classes.size === 0 && (wanted.safelist?.length ?? 0) === 0 && wanted.css === void 0) return {
|
|
1177
|
+
assets,
|
|
1178
|
+
tailwindSheet: void 0,
|
|
1179
|
+
stylesheets,
|
|
1180
|
+
diagnostics
|
|
1181
|
+
};
|
|
1182
|
+
const compiled = await compileTailwind(classes, wanted, theme);
|
|
1183
|
+
const generated = readStylesheet(TAILWIND_ORIGIN, compiled.css, options, addressed);
|
|
1184
|
+
const findingKey = (diagnostic) => `${diagnostic.code}\0${diagnostic.message.slice(diagnostic.message.indexOf(": ") + 2)}`;
|
|
1185
|
+
const reported = new Set(diagnostics.map(findingKey));
|
|
1186
|
+
for (const diagnostic of generated.diagnostics) if (diagnostic.code.startsWith("email-font-") && !reported.has(findingKey(diagnostic))) diagnostics.push(diagnostic);
|
|
1187
|
+
return {
|
|
1188
|
+
assets,
|
|
1189
|
+
tailwindSheet: generated.sheet,
|
|
1190
|
+
stylesheets,
|
|
1191
|
+
diagnostics
|
|
1192
|
+
};
|
|
1193
|
+
};
|
|
1194
|
+
//#endregion
|
|
1195
|
+
//#region src/email/brand-footer.ts
|
|
1196
|
+
/** The brand theme as Tailwind compiles it; a theme outside the grammar is a compile refusal. */
|
|
1197
|
+
const brandTheme = (brand) => {
|
|
1198
|
+
const parsed = parseBrandCss(brand.css);
|
|
1199
|
+
if (parsed.isErr()) throw new EmailCompileError({ diagnostics: parsed.error.map((finding) => ({
|
|
1200
|
+
code: finding.code,
|
|
1201
|
+
severity: "error",
|
|
1202
|
+
message: `samva:brand: ${finding.message}`,
|
|
1203
|
+
origins: []
|
|
1204
|
+
})) });
|
|
1205
|
+
return brandTailwindCss(parsed.value);
|
|
1206
|
+
};
|
|
1207
|
+
/**
|
|
1208
|
+
* Render `BrandFooter` against a brand on its own, for the send path to
|
|
1209
|
+
* append to a message whose template renders no footer of its own. It
|
|
1210
|
+
* compiles the same component, styled by the same brand theme, a template
|
|
1211
|
+
* would get from `samva:brand`. Without `unsubscribe` the unsubscribe row is
|
|
1212
|
+
* left out.
|
|
1213
|
+
*/
|
|
1214
|
+
const renderBrandFooter = async (brand, options) => {
|
|
1215
|
+
const tailwind = await compileTailwind(BRAND_COMPONENT_CLASSES, { css: brandTheme(brand) });
|
|
1216
|
+
const node = brandComponents(brand).BrandFooter({});
|
|
1217
|
+
if (node === null) return {
|
|
1218
|
+
html: "",
|
|
1219
|
+
text: ""
|
|
1220
|
+
};
|
|
1221
|
+
const styled = applyStylesheet(node, parseStylesheet(tailwind.css, { origin: "samva:brand" }));
|
|
1222
|
+
const compiled = compileEmail(styled.tree);
|
|
1223
|
+
const rendered = options.unsubscribe ? compiled : withoutUnsubscribeRow({
|
|
1224
|
+
html: compiled.html,
|
|
1225
|
+
text: compiled.text
|
|
1226
|
+
});
|
|
1227
|
+
const text = (rendered.text ?? "").trim();
|
|
1228
|
+
return {
|
|
1229
|
+
html: rendered.html ?? "",
|
|
1230
|
+
text: text === "" ? "" : `\n\n---\n${text}`
|
|
1231
|
+
};
|
|
1232
|
+
};
|
|
1233
|
+
/**
|
|
1234
|
+
* Render content against a brand as a project whose `theme.css` is
|
|
1235
|
+
* `@import "samva:brand";` renders it: Tailwind compiles the brand theme for
|
|
1236
|
+
* the classes the content names, `BrandLogo` and `BrandFooter` are bound to the
|
|
1237
|
+
* brand, and the render inlines the result. A brand preview renders through
|
|
1238
|
+
* this, so it shows what a template importing the brand compiles to.
|
|
1239
|
+
*/
|
|
1240
|
+
const renderBrandSample = async (brand, sample) => {
|
|
1241
|
+
const tailwind = await compileTailwind([...BRAND_COMPONENT_CLASSES, ...sample.classes], { css: "@import \"samva:brand\";" }, {
|
|
1242
|
+
stylesheets: /* @__PURE__ */ new Map(),
|
|
1243
|
+
brandCss: brandTheme(brand)
|
|
1244
|
+
});
|
|
1245
|
+
const components = brandComponents(brand);
|
|
1246
|
+
return renderEmailContent(parseStylesheet(tailwind.css, { origin: "samva:brand" }), () => sample.render(components));
|
|
1247
|
+
};
|
|
1248
|
+
//#endregion
|
|
1249
|
+
//#region src/sml/compile.ts
|
|
1250
|
+
/** Compile a project's entry template to IR without evaluating any of it. */
|
|
1251
|
+
const compileTemplate = async (options) => {
|
|
1252
|
+
const findings = new Findings();
|
|
1253
|
+
const project = loadProject(options.files, options.entry, findings);
|
|
1254
|
+
if (project === void 0) return completed(findings, void 0);
|
|
1255
|
+
let transformed;
|
|
1256
|
+
try {
|
|
1257
|
+
transformed = await transformProject(options.files, options);
|
|
1258
|
+
} catch (error) {
|
|
1259
|
+
if (!(error instanceof EmailCompileError)) throw error;
|
|
1260
|
+
findings.items.push(...error.diagnostics);
|
|
1261
|
+
return completed(findings, void 0);
|
|
1262
|
+
}
|
|
1263
|
+
findings.items.push(...transformed.diagnostics.filter((item) => item.code !== "tailwind-dynamic-class"));
|
|
1264
|
+
const assetsByPath = new Map(transformed.assets.map((asset) => [asset.path, asset]));
|
|
1265
|
+
return lowerProject(options, project, findings, {
|
|
1266
|
+
assets: transformed.assets,
|
|
1267
|
+
stylesheets: transformed.stylesheets,
|
|
1268
|
+
tailwindSheet: transformed.tailwindSheet,
|
|
1269
|
+
urlFor: (path) => {
|
|
1270
|
+
const entry = assetsByPath.get(path);
|
|
1271
|
+
return entry === void 0 ? void 0 : assetUrl(entry, options.assetBase);
|
|
1272
|
+
}
|
|
1273
|
+
});
|
|
1274
|
+
};
|
|
1275
|
+
//#endregion
|
|
1276
|
+
//#region src/sml/compatibility.ts
|
|
1277
|
+
/**
|
|
1278
|
+
* Check what each declared fixture delivers against the pinned client matrix. The rules run on the
|
|
1279
|
+
* rendered document, because what a client drops is what the compiler produced, and every finding
|
|
1280
|
+
* is located at the source of the element that produced it.
|
|
1281
|
+
*/
|
|
1282
|
+
const checkTemplateCompatibility = (ir, fixtures, options = {}) => {
|
|
1283
|
+
if (ir.email === void 0) return [];
|
|
1284
|
+
const sources = ir.sources ?? [];
|
|
1285
|
+
const findings = [];
|
|
1286
|
+
for (const [fixture, input] of Object.entries(fixtures)) {
|
|
1287
|
+
const rendered = renderIr(ir, input, { positions: true });
|
|
1288
|
+
const positions = (rendered.positions ?? []).map((position, index) => ({
|
|
1289
|
+
start: position.start,
|
|
1290
|
+
end: position.end,
|
|
1291
|
+
tag: position.tag,
|
|
1292
|
+
instancePath: String(index),
|
|
1293
|
+
authored: true,
|
|
1294
|
+
origins: position.src === void 0 ? [] : [{
|
|
1295
|
+
fileName: sources[position.src[2] ?? 0] ?? "",
|
|
1296
|
+
lineNumber: position.src[0],
|
|
1297
|
+
columnNumber: position.src[1]
|
|
1298
|
+
}]
|
|
1299
|
+
}));
|
|
1300
|
+
findings.push(...checkEmailCompatibility({
|
|
1301
|
+
html: rendered.html,
|
|
1302
|
+
fixture,
|
|
1303
|
+
positions,
|
|
1304
|
+
...options.clients === void 0 ? {} : { clients: options.clients }
|
|
1305
|
+
}));
|
|
1306
|
+
}
|
|
1307
|
+
return findings;
|
|
1308
|
+
};
|
|
1309
|
+
//#endregion
|
|
1310
|
+
export { BRAND_SPECIFIER, COMPATIBILITY_PROVENANCE, EMAIL_CLIENT_MATRIX, ESSENTIAL_CONSTRUCTS, TAILWIND_VERSION, TEMPLATE_NAME_PATTERN, applyStylesheet, checkEmailCompatibility, checkStaticProfile, checkTemplateCompatibility, classListOf, compileSelector, compileTailwind, compileTemplate, discoverClassCandidates, downlevelColors, downlevelMediaQuery, finalizeValue, foldCalc, formatColor, hasBlockingCompatibility, introducedProfileErrors, matchesSelector, parseBrandSpecifier, parseColor, parseStylesheet, projectBrandSpecifier, renderBrandFooter, renderBrandSample, renderHeadCss, resolveVariables, transformProject, unknownCoverage };
|
|
1311
|
+
|
|
1312
|
+
//# sourceMappingURL=compiler.js.map
|