@yahoo/uds-create-config 5.82.0 → 5.82.1
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.
|
@@ -202,6 +202,8 @@ var Converter = class {
|
|
|
202
202
|
breakpoints;
|
|
203
203
|
/** Each modifier's class prefix (`md`) → the prop key its bag is written under (`_md`). */
|
|
204
204
|
modifierKeys;
|
|
205
|
+
/** The classes a modifier's selector names on another element (`.peer`, `.group`). */
|
|
206
|
+
markerClasses;
|
|
205
207
|
constructor(options, grammar) {
|
|
206
208
|
this.options = options;
|
|
207
209
|
this.grammar = grammar;
|
|
@@ -227,6 +229,13 @@ var Converter = class {
|
|
|
227
229
|
});
|
|
228
230
|
}
|
|
229
231
|
this.breakpoints = breakpoints;
|
|
232
|
+
const markers = /* @__PURE__ */ new Set();
|
|
233
|
+
for (const modifier of options.config.list("modifier")) {
|
|
234
|
+
const { type, value } = modifier.toJSON();
|
|
235
|
+
if (type !== "selector" || typeof value !== "string") continue;
|
|
236
|
+
for (const [, name] of value.matchAll(/\.(-?[A-Za-z_][\w-]*)/g)) markers.add(name);
|
|
237
|
+
}
|
|
238
|
+
this.markerClasses = markers;
|
|
230
239
|
this.modifierKeys = new Map(options.config.list("modifier").map((modifier) => [modifierClassPrefix(modifier), `_${modifier.leaf}`]));
|
|
231
240
|
}
|
|
232
241
|
convertTop(el) {
|
|
@@ -307,15 +316,22 @@ var Converter = class {
|
|
|
307
316
|
plain(el, convertKids = () => this.plainChildren(el)) {
|
|
308
317
|
const tag = el.tagName.toLowerCase();
|
|
309
318
|
if (FORBIDDEN_TAGS.has(tag)) return [];
|
|
310
|
-
|
|
311
|
-
if (
|
|
319
|
+
let kidsOf = convertKids;
|
|
320
|
+
if (el.hasAttribute(FOLD) && !this.placesItself(el)) {
|
|
321
|
+
const kids = convertKids();
|
|
322
|
+
if (kids.length <= 1) return this.pinFolded(el, kids);
|
|
323
|
+
kidsOf = () => kids;
|
|
324
|
+
}
|
|
325
|
+
if ([...inlineDeclarations(el), ...declarationsOf(el.getAttribute("data-uds-computed") ?? "")].find(([property]) => property === "display")?.[1].trim() === "contents") return kidsOf();
|
|
312
326
|
const { className, style, paints } = this.plainStyle(el);
|
|
313
327
|
const attrs = plainAttributes(el);
|
|
314
328
|
if (tag === "img" && !attrs.src) return [];
|
|
315
|
-
const children = VOID_TAGS.has(tag) ? [] :
|
|
329
|
+
const children = VOID_TAGS.has(tag) ? [] : kidsOf();
|
|
316
330
|
const text = children.length === 0 ? plainText(el) : "";
|
|
317
|
-
if (children.length === 0 && !text && !VOID_TAGS.has(tag) && !paints && !sizesItself(el) && !el.hasAttribute(EMBED_SPACE_ATTR)) return [];
|
|
318
|
-
|
|
331
|
+
if (children.length === 0 && !text && !VOID_TAGS.has(tag) && !paints && !sizesItself(el) && !el.hasAttribute(EMBED_SPACE_ATTR) && !holdsGridCell(el)) return [];
|
|
332
|
+
const carries = className !== "" || Object.keys(style).length > 0 || Object.keys(attrs).length > 0;
|
|
333
|
+
const holdsCell = children.length === 0 && !text && holdsGridCell(el);
|
|
334
|
+
if (!carries && GROUPING_TAGS.has(tag) && children.length <= 1 && !holdsCell) {
|
|
319
335
|
if (text) return this.plainTextRun(text);
|
|
320
336
|
return children;
|
|
321
337
|
}
|
|
@@ -503,6 +519,7 @@ var Converter = class {
|
|
|
503
519
|
classes.push(...owned.length < each.atoms.size ? this.narrowed(each, new Set(owned)) : [each.bare]);
|
|
504
520
|
}
|
|
505
521
|
fromDeclarations(declarationsOf(el.getAttribute("data-uds-computed") ?? ""));
|
|
522
|
+
for (const cls of classesOf(el)) if (this.markerClasses.has(cls)) classes.push(cls);
|
|
506
523
|
return {
|
|
507
524
|
className: [...new Set(classes)].join(" "),
|
|
508
525
|
style,
|
|
@@ -539,6 +556,20 @@ var Converter = class {
|
|
|
539
556
|
}
|
|
540
557
|
}
|
|
541
558
|
/**
|
|
559
|
+
* Whether an element's classes or computed styles place it in its parent's grid or flex row (a
|
|
560
|
+
* column span, its own alignment, a flex share). Folding it would leave its child unplaced, so a
|
|
561
|
+
* card spanning two columns would take one.
|
|
562
|
+
*/
|
|
563
|
+
placesItself(el) {
|
|
564
|
+
if (declarationsOf(el.getAttribute("data-uds-computed") ?? "").some(([property]) => PLACEMENT_PROPERTY.test(property))) return true;
|
|
565
|
+
return classesOf(el).some((cls) => {
|
|
566
|
+
const read = this.readModifiedClass(cls);
|
|
567
|
+
if (!read || read.modifiers.length > 0) return false;
|
|
568
|
+
const { properties = [] } = this.options.config.resolve("style-property", read.style.path)?.toJSON() ?? {};
|
|
569
|
+
return properties.some((property) => PLACEMENT_PROPERTY.test(property));
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
542
573
|
* The content of an unmarked wrapper the capture folded, with the wrapper's measured box written
|
|
543
574
|
* onto it when it is one element: the wrapper's sizing (a flex share, a fixed size) no longer reaches
|
|
544
575
|
* the child, so the child keeps the box it had.
|
|
@@ -673,7 +704,7 @@ var Converter = class {
|
|
|
673
704
|
const important = /^!|!$/.test(leaf);
|
|
674
705
|
if (important) leaf = leaf.replace(/^!|!$/, "");
|
|
675
706
|
if (important) rank += IMPORTANT_RANK;
|
|
676
|
-
const style = this.grammar.styleProp(leaf);
|
|
707
|
+
const style = this.grammar.styleProp(leaf) ?? this.grammar.styleProp(FADED_CLASS.exec(leaf)?.[1] ?? "");
|
|
677
708
|
return style ? {
|
|
678
709
|
modifiers,
|
|
679
710
|
style,
|
|
@@ -1456,6 +1487,10 @@ const ROOT_ATTRIBUTE_PROPS = [
|
|
|
1456
1487
|
];
|
|
1457
1488
|
/** The CSS properties that draw something of an element's own. */
|
|
1458
1489
|
const PAINT_PROPERTY = /^(background|border-(top-|right-|bottom-|left-)?(width|color)|box-shadow|outline)/;
|
|
1490
|
+
/** A class under an opacity modifier, `bg-brand/50`, with the class it fades. */
|
|
1491
|
+
const FADED_CLASS = /^(.+)\/(?:100|\d{1,2}(?:\.\d+)?)$/;
|
|
1492
|
+
/** The CSS properties that place an element in its parent's grid or flex layout. */
|
|
1493
|
+
const PLACEMENT_PROPERTY = /^(grid-(column|row|area)(-start|-end)?|(align|justify|place)-self|order|flex(-grow)?)$/;
|
|
1459
1494
|
/** Tags that only group what they hold, and fold away when they carry nothing of their own. */
|
|
1460
1495
|
const GROUPING_TAGS = new Set(["div", "span"]);
|
|
1461
1496
|
/** Tags with no content. */
|
|
@@ -1486,6 +1521,8 @@ const PLAIN_ATTRIBUTES = {
|
|
|
1486
1521
|
rowspan: "rowSpan",
|
|
1487
1522
|
for: "htmlFor"
|
|
1488
1523
|
};
|
|
1524
|
+
/** The state attributes a plain element keeps, which `open:` and `peer-disabled:` styles read. */
|
|
1525
|
+
const BOOLEAN_ATTRIBUTES = ["open", "disabled"];
|
|
1489
1526
|
function plainAttributes(el) {
|
|
1490
1527
|
const out = {};
|
|
1491
1528
|
const tag = el.tagName.toLowerCase();
|
|
@@ -1500,6 +1537,17 @@ function plainAttributes(el) {
|
|
|
1500
1537
|
const value = tag === "textarea" ? el.textContent ?? "" : el.getAttribute("value");
|
|
1501
1538
|
if (value) out.defaultValue = value;
|
|
1502
1539
|
}
|
|
1540
|
+
if (tag === "input" && el.hasAttribute("checked")) out.defaultChecked = true;
|
|
1541
|
+
for (const attr of BOOLEAN_ATTRIBUTES) if (el.hasAttribute(attr)) out[attr] = true;
|
|
1542
|
+
if (tag === "option") {
|
|
1543
|
+
const value = el.getAttribute("value");
|
|
1544
|
+
if (value !== null && value !== void 0) out.value = value;
|
|
1545
|
+
}
|
|
1546
|
+
if (tag === "select") {
|
|
1547
|
+
const chosen = el.querySelector("option[selected]");
|
|
1548
|
+
const value = chosen?.getAttribute("value") ?? chosen?.textContent;
|
|
1549
|
+
if (value) out.defaultValue = value;
|
|
1550
|
+
}
|
|
1503
1551
|
return out;
|
|
1504
1552
|
}
|
|
1505
1553
|
/** The text an element holds directly, its whitespace collapsed; empty for a field. */
|
|
@@ -1521,6 +1569,10 @@ function camelCase(property) {
|
|
|
1521
1569
|
function isImage(el) {
|
|
1522
1570
|
return el.tagName.toLowerCase() === "img" && !el.hasAttribute("data-uds-component");
|
|
1523
1571
|
}
|
|
1572
|
+
/** A form control whose state a page's styles can read. */
|
|
1573
|
+
function isFieldControl(el) {
|
|
1574
|
+
return isField(el) || el.tagName.toLowerCase() === "select";
|
|
1575
|
+
}
|
|
1524
1576
|
function isField(el) {
|
|
1525
1577
|
const tag = el.tagName.toLowerCase();
|
|
1526
1578
|
return tag === "input" || tag === "textarea";
|
|
@@ -1588,6 +1640,12 @@ const SIZING_PROPERTY = new Set([
|
|
|
1588
1640
|
"flex-basis"
|
|
1589
1641
|
]);
|
|
1590
1642
|
/** Whether an element's inline style gives it a size of its own, so it holds space while empty. */
|
|
1643
|
+
/** Whether an element is an item of a grid, by the display the capture recorded on its parent. */
|
|
1644
|
+
function holdsGridCell(el) {
|
|
1645
|
+
const parent = el.parentElement;
|
|
1646
|
+
if (!parent) return false;
|
|
1647
|
+
return declarationsOf(parent.getAttribute("data-uds-computed") ?? "").some(([property, value]) => property === "display" && /^(inline-)?grid$/.test(value.trim()));
|
|
1648
|
+
}
|
|
1591
1649
|
function sizesItself(el) {
|
|
1592
1650
|
return inlineDeclarations(el).some(([property, value]) => {
|
|
1593
1651
|
const size = value.trim().toLowerCase();
|
|
@@ -1705,7 +1763,7 @@ function nearestRoot(el) {
|
|
|
1705
1763
|
function visible(el) {
|
|
1706
1764
|
const style = el.getAttribute("style") ?? "";
|
|
1707
1765
|
if (/display:\s*none/.test(style)) return false;
|
|
1708
|
-
if (hiddenInline(el) && /position:\s*(absolute|fixed)/.test(style)) return false;
|
|
1766
|
+
if (hiddenInline(el) && /position:\s*(absolute|fixed)/.test(style) && !(isFieldControl(el) && !/visibility:\s*hidden/.test(style))) return false;
|
|
1709
1767
|
if (el.hasAttribute("hidden")) return false;
|
|
1710
1768
|
if (el.getAttribute("role") === "tooltip") return false;
|
|
1711
1769
|
if (el.getAttribute("data-uds-props")?.includes("\"hidden\":true")) return false;
|
|
@@ -102,17 +102,23 @@ function capturedFromDom(el) {
|
|
|
102
102
|
const attrs = {};
|
|
103
103
|
for (const attribute of Array.from(el.attributes ?? [])) attrs[attribute.name] = attribute.value;
|
|
104
104
|
const children = [];
|
|
105
|
+
let text = "";
|
|
106
|
+
const flush = () => {
|
|
107
|
+
if (text.trim()) children.push(text);
|
|
108
|
+
text = "";
|
|
109
|
+
};
|
|
105
110
|
for (const child of Array.from(el.childNodes ?? [])) {
|
|
106
111
|
if (child.nodeType === TEXT_NODE) {
|
|
107
|
-
|
|
108
|
-
if (text.trim()) children.push(text);
|
|
112
|
+
text += child.textContent ?? "";
|
|
109
113
|
continue;
|
|
110
114
|
}
|
|
111
115
|
if (child.nodeType !== ELEMENT_NODE) continue;
|
|
112
116
|
const tag = (child.tagName ?? "").toLowerCase();
|
|
113
117
|
if (SKIPPED_TAGS.has(tag)) continue;
|
|
118
|
+
flush();
|
|
114
119
|
children.push(capturedFromDom(child));
|
|
115
120
|
}
|
|
121
|
+
flush();
|
|
116
122
|
return {
|
|
117
123
|
tag: (el.tagName ?? "div").toLowerCase(),
|
|
118
124
|
...Object.keys(attrs).length > 0 ? { attrs } : {},
|