@measured/puck-plugin-heading-analyzer 0.14.2-canary.58b08a9 → 0.14.2-canary.717ccb9
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +60 -29
- package/package.json +2 -2
package/dist/index.js
CHANGED
@@ -45907,7 +45907,10 @@ var require_dist = __commonJS({
|
|
45907
45907
|
return collected;
|
45908
45908
|
};
|
45909
45909
|
var getStyleSheet = (el) => {
|
45910
|
-
return Array.from(document.styleSheets).find((ss) =>
|
45910
|
+
return Array.from(document.styleSheets).find((ss) => {
|
45911
|
+
const ownerNode = ss.ownerNode;
|
45912
|
+
return ownerNode.href === el.href;
|
45913
|
+
});
|
45911
45914
|
};
|
45912
45915
|
var getStyles2 = (styleSheet) => {
|
45913
45916
|
if (styleSheet) {
|
@@ -45929,25 +45932,16 @@ var require_dist = __commonJS({
|
|
45929
45932
|
onStylesLoaded = () => null
|
45930
45933
|
}) => {
|
45931
45934
|
const { document: doc, window: win } = (0, import_react_frame_component.useFrame)();
|
45932
|
-
(0, import_react22.
|
45935
|
+
(0, import_react22.useEffect)(() => {
|
45933
45936
|
if (!win || !doc) {
|
45934
45937
|
return () => {
|
45935
45938
|
};
|
45936
45939
|
}
|
45937
|
-
|
45940
|
+
let elements = [];
|
45941
|
+
const hashes = {};
|
45938
45942
|
const lookupEl = (el) => elements.findIndex((elementMap) => elementMap.original === el);
|
45939
|
-
const
|
45943
|
+
const mirrorEl = (el, onLoad = () => {
|
45940
45944
|
}) => __async2(void 0, null, function* () {
|
45941
|
-
const index = lookupEl(el);
|
45942
|
-
if (index > -1) {
|
45943
|
-
if (debug)
|
45944
|
-
console.log(
|
45945
|
-
`Tried to add an element that was already mirrored. Updating instead...`
|
45946
|
-
);
|
45947
|
-
elements[index].mirror.innerText = el.innerText;
|
45948
|
-
onLoad();
|
45949
|
-
return;
|
45950
|
-
}
|
45951
45945
|
let mirror;
|
45952
45946
|
if (el.nodeName === "LINK") {
|
45953
45947
|
mirror = document.createElement("style");
|
@@ -45964,7 +45958,6 @@ var require_dist = __commonJS({
|
|
45964
45958
|
`Tried to load styles for link element, but couldn't find them. Skipping...`
|
45965
45959
|
);
|
45966
45960
|
}
|
45967
|
-
onLoad();
|
45968
45961
|
return;
|
45969
45962
|
}
|
45970
45963
|
mirror.innerHTML = styles;
|
@@ -45972,11 +45965,28 @@ var require_dist = __commonJS({
|
|
45972
45965
|
} else {
|
45973
45966
|
mirror = el.cloneNode(true);
|
45974
45967
|
}
|
45968
|
+
mirror.onload = onLoad;
|
45969
|
+
return mirror;
|
45970
|
+
});
|
45971
|
+
const addEl = (el, onLoad = () => {
|
45972
|
+
}) => __async2(void 0, null, function* () {
|
45973
|
+
const index = lookupEl(el);
|
45974
|
+
if (index > -1) {
|
45975
|
+
if (debug)
|
45976
|
+
console.log(
|
45977
|
+
`Tried to add an element that was already mirrored. Updating instead...`
|
45978
|
+
);
|
45979
|
+
elements[index].mirror.innerText = el.innerText;
|
45980
|
+
onLoad();
|
45981
|
+
return;
|
45982
|
+
}
|
45983
|
+
const mirror = yield mirrorEl(el, onLoad);
|
45984
|
+
if (!mirror) {
|
45985
|
+
onLoad();
|
45986
|
+
return;
|
45987
|
+
}
|
45975
45988
|
const elHash = (0, import_object_hash.default)(mirror.outerHTML);
|
45976
|
-
|
45977
|
-
(existingStyle) => existingStyle !== mirror && (0, import_object_hash.default)(existingStyle.outerHTML)
|
45978
|
-
).filter(Boolean);
|
45979
|
-
if (existingHashes.indexOf(elHash) > -1) {
|
45989
|
+
if (hashes[elHash]) {
|
45980
45990
|
if (debug)
|
45981
45991
|
console.log(
|
45982
45992
|
`iframe already contains element that is being mirrored. Skipping...`
|
@@ -45984,6 +45994,7 @@ var require_dist = __commonJS({
|
|
45984
45994
|
onLoad();
|
45985
45995
|
return;
|
45986
45996
|
}
|
45997
|
+
hashes[elHash] = true;
|
45987
45998
|
mirror.onload = onLoad;
|
45988
45999
|
doc.head.append(mirror);
|
45989
46000
|
elements.push({ original: el, mirror });
|
@@ -45991,6 +46002,7 @@ var require_dist = __commonJS({
|
|
45991
46002
|
console.log(`Added style node ${el.outerHTML}`);
|
45992
46003
|
});
|
45993
46004
|
const removeEl = (el) => {
|
46005
|
+
var _a3, _b;
|
45994
46006
|
const index = lookupEl(el);
|
45995
46007
|
if (index === -1) {
|
45996
46008
|
if (debug)
|
@@ -45999,7 +46011,9 @@ var require_dist = __commonJS({
|
|
45999
46011
|
);
|
46000
46012
|
return;
|
46001
46013
|
}
|
46002
|
-
|
46014
|
+
const elHash = (0, import_object_hash.default)(el.outerHTML);
|
46015
|
+
(_b = (_a3 = elements[index]) == null ? void 0 : _a3.mirror) == null ? void 0 : _b.remove();
|
46016
|
+
delete hashes[elHash];
|
46003
46017
|
if (debug)
|
46004
46018
|
console.log(`Removed style node ${el.outerHTML}`);
|
46005
46019
|
};
|
@@ -46027,18 +46041,35 @@ var require_dist = __commonJS({
|
|
46027
46041
|
});
|
46028
46042
|
const parentDocument = win.parent.document;
|
46029
46043
|
const collectedStyles = collectStyles(parentDocument);
|
46030
|
-
|
46031
|
-
|
46032
|
-
|
46033
|
-
|
46034
|
-
|
46035
|
-
if (
|
46036
|
-
|
46044
|
+
const hrefs = [];
|
46045
|
+
Promise.all(
|
46046
|
+
collectedStyles.map((styleNode, i2) => __async2(void 0, null, function* () {
|
46047
|
+
if (styleNode.nodeName === "LINK") {
|
46048
|
+
const linkHref = styleNode.href;
|
46049
|
+
if (hrefs.indexOf(linkHref) > -1) {
|
46050
|
+
return;
|
46037
46051
|
}
|
46038
|
-
|
46052
|
+
hrefs.push(linkHref);
|
46053
|
+
}
|
46054
|
+
const mirror = yield mirrorEl(styleNode);
|
46055
|
+
if (!mirror)
|
46056
|
+
return;
|
46057
|
+
elements.push({ original: styleNode, mirror });
|
46058
|
+
return mirror;
|
46059
|
+
}))
|
46060
|
+
).then((mirrorStyles) => {
|
46061
|
+
const filtered = mirrorStyles.filter(
|
46062
|
+
(el) => typeof el !== "undefined"
|
46039
46063
|
);
|
46064
|
+
doc.head.innerHTML = "";
|
46065
|
+
doc.head.append(...filtered);
|
46066
|
+
observer.observe(parentDocument.head, { childList: true, subtree: true });
|
46067
|
+
filtered.forEach((el) => {
|
46068
|
+
const elHash = (0, import_object_hash.default)(el.outerHTML);
|
46069
|
+
hashes[elHash] = true;
|
46070
|
+
});
|
46071
|
+
onStylesLoaded();
|
46040
46072
|
});
|
46041
|
-
observer.observe(parentDocument.head, { childList: true, subtree: true });
|
46042
46073
|
return () => {
|
46043
46074
|
observer.disconnect();
|
46044
46075
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@measured/puck-plugin-heading-analyzer",
|
3
|
-
"version": "0.14.2-canary.
|
3
|
+
"version": "0.14.2-canary.717ccb9",
|
4
4
|
"author": "Measured Corporation Ltd <hello@measured.co>",
|
5
5
|
"repository": "measuredco/puck",
|
6
6
|
"bugs": "https://github.com/measuredco/puck/issues",
|
@@ -18,7 +18,7 @@
|
|
18
18
|
"dist"
|
19
19
|
],
|
20
20
|
"devDependencies": {
|
21
|
-
"@measured/puck": "^0.14.2-canary.
|
21
|
+
"@measured/puck": "^0.14.2-canary.717ccb9",
|
22
22
|
"@types/react": "^18.2.0",
|
23
23
|
"@types/react-dom": "^18.2.0",
|
24
24
|
"eslint": "^7.32.0",
|