camox 0.76.1 → 0.77.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/dist/core/lib/artifactTheme.js +43 -6
- package/dist/features/studio/components/LocalePicker.js +518 -134
- package/dist/lib/locale-path.js +2 -2
- package/dist/lib/queries.js +5 -1
- package/dist/package.js +1 -1
- package/dist/studio.css +1 -1
- package/package.json +4 -4
- package/skills/camox/references/artifacts.md +7 -0
|
@@ -39,18 +39,55 @@ function readArtifactTheme(frame) {
|
|
|
39
39
|
function isThemeAttribute(name) {
|
|
40
40
|
return name === "class" || name === "style" || !!name?.startsWith("data-");
|
|
41
41
|
}
|
|
42
|
+
const isStylesheet = (node) => node?.nodeName === "STYLE" || node?.nodeName === "LINK" && /\bstylesheet\b/i.test(node.getAttribute("rel") ?? "");
|
|
43
|
+
/** Whether a change in the page's head may change its stylesheets. */
|
|
44
|
+
function isStylesheetChange(record) {
|
|
45
|
+
if (record.type === "childList") {
|
|
46
|
+
if (isStylesheet(record.target)) return true;
|
|
47
|
+
return [...record.addedNodes, ...record.removedNodes].some(isStylesheet);
|
|
48
|
+
}
|
|
49
|
+
const target = record.type === "characterData" ? record.target.parentNode : record.target;
|
|
50
|
+
return isStylesheet(target);
|
|
51
|
+
}
|
|
42
52
|
/**
|
|
43
|
-
* Calls `onChange` when the
|
|
44
|
-
*
|
|
53
|
+
* Calls `onChange` when the tokens at the frame's position may have changed: when the `class`,
|
|
54
|
+
* `style` or `data-*` attributes of the frame or one of its ancestors change, or when the page's
|
|
55
|
+
* stylesheets do, as the studio swaps them when it shows Live or a draft, or a draft's code
|
|
56
|
+
* changes them. A new stylesheet's tokens only resolve once it loaded, so its load counts too.
|
|
57
|
+
* Returns a disconnect.
|
|
45
58
|
*/
|
|
46
59
|
function observeArtifactTheme(frame, onChange) {
|
|
47
|
-
const
|
|
60
|
+
const doc = frame.ownerDocument;
|
|
61
|
+
const page = doc.defaultView;
|
|
48
62
|
if (!page) return () => {};
|
|
49
|
-
const
|
|
63
|
+
const ancestors = new page.MutationObserver((records) => {
|
|
50
64
|
if (records.some((record) => isThemeAttribute(record.attributeName))) onChange();
|
|
51
65
|
});
|
|
52
|
-
for (let element = frame; element; element = element.parentElement)
|
|
53
|
-
|
|
66
|
+
for (let element = frame; element; element = element.parentElement) ancestors.observe(element, { attributes: true });
|
|
67
|
+
const stylesheets = new page.MutationObserver((records) => {
|
|
68
|
+
if (records.some(isStylesheetChange)) onChange();
|
|
69
|
+
});
|
|
70
|
+
stylesheets.observe(doc.head, {
|
|
71
|
+
childList: true,
|
|
72
|
+
subtree: true,
|
|
73
|
+
characterData: true,
|
|
74
|
+
attributes: true,
|
|
75
|
+
attributeFilter: [
|
|
76
|
+
"href",
|
|
77
|
+
"rel",
|
|
78
|
+
"media",
|
|
79
|
+
"disabled"
|
|
80
|
+
]
|
|
81
|
+
});
|
|
82
|
+
const onLoad = (event) => {
|
|
83
|
+
if (isStylesheet(event.target)) onChange();
|
|
84
|
+
};
|
|
85
|
+
doc.addEventListener("load", onLoad, true);
|
|
86
|
+
return () => {
|
|
87
|
+
ancestors.disconnect();
|
|
88
|
+
stylesheets.disconnect();
|
|
89
|
+
doc.removeEventListener("load", onLoad, true);
|
|
90
|
+
};
|
|
54
91
|
}
|
|
55
92
|
|
|
56
93
|
//#endregion
|