@cmssy/react 16.1.0 → 16.2.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/client.cjs CHANGED
@@ -44,19 +44,20 @@ var TRANSPARENT = 0.01;
44
44
  var VISIBLE_TEXT_FRACTION = 0.5;
45
45
  var MEDIA = "img,svg,video,canvas,picture,iframe";
46
46
  var UNPAINTED_TEXT = /* @__PURE__ */ new Set(["SCRIPT", "STYLE", "TEMPLATE", "NOSCRIPT"]);
47
- function effectiveOpacity(node) {
48
- let value = 1;
47
+ var NOT_LAID_OUT = { laidOut: false, opacity: 0 };
48
+ function paint(node) {
49
+ let opacity = 1;
49
50
  let current = node;
50
51
  while (current) {
51
52
  const style = getComputedStyle(current);
52
- if (style.display === "none" || style.visibility === "hidden") return 0;
53
+ if (style.display === "none") return NOT_LAID_OUT;
54
+ if (style.visibility === "hidden") opacity = 0;
53
55
  const own = Number.parseFloat(style.opacity);
54
- if (Number.isFinite(own)) value *= own;
55
- if (value <= TRANSPARENT) return 0;
56
+ if (Number.isFinite(own)) opacity *= own;
56
57
  if (current === document.documentElement) break;
57
58
  current = current.parentElement;
58
59
  }
59
- return value;
60
+ return { laidOut: true, opacity: opacity <= TRANSPARENT ? 0 : opacity };
60
61
  }
61
62
  function holdsText(el) {
62
63
  for (const node of el.childNodes) {
@@ -81,15 +82,18 @@ function collectMedia(block) {
81
82
  for (const el of block.querySelectorAll(MEDIA)) media.push(el);
82
83
  return media;
83
84
  }
85
+ function laidOut(elements) {
86
+ return elements.map(paint).filter((state) => state.laidOut);
87
+ }
84
88
  function isBlockPainted(block) {
85
- const copy = collectCopy(block);
89
+ const copy = laidOut(collectCopy(block));
86
90
  if (copy.length > 0) {
87
- const visible2 = copy.filter((el) => effectiveOpacity(el) > TRANSPARENT);
91
+ const visible2 = copy.filter((state) => state.opacity > TRANSPARENT);
88
92
  return visible2.length >= copy.length * VISIBLE_TEXT_FRACTION;
89
93
  }
90
- const media = collectMedia(block);
94
+ const media = laidOut(collectMedia(block));
91
95
  if (media.length === 0) return true;
92
- return media.some((el) => effectiveOpacity(el) > TRANSPARENT);
96
+ return media.some((state) => state.opacity > TRANSPARENT);
93
97
  }
94
98
 
95
99
  // src/bridge/use-invisible-blocks.ts
package/dist/client.js CHANGED
@@ -42,19 +42,20 @@ var TRANSPARENT = 0.01;
42
42
  var VISIBLE_TEXT_FRACTION = 0.5;
43
43
  var MEDIA = "img,svg,video,canvas,picture,iframe";
44
44
  var UNPAINTED_TEXT = /* @__PURE__ */ new Set(["SCRIPT", "STYLE", "TEMPLATE", "NOSCRIPT"]);
45
- function effectiveOpacity(node) {
46
- let value = 1;
45
+ var NOT_LAID_OUT = { laidOut: false, opacity: 0 };
46
+ function paint(node) {
47
+ let opacity = 1;
47
48
  let current = node;
48
49
  while (current) {
49
50
  const style = getComputedStyle(current);
50
- if (style.display === "none" || style.visibility === "hidden") return 0;
51
+ if (style.display === "none") return NOT_LAID_OUT;
52
+ if (style.visibility === "hidden") opacity = 0;
51
53
  const own = Number.parseFloat(style.opacity);
52
- if (Number.isFinite(own)) value *= own;
53
- if (value <= TRANSPARENT) return 0;
54
+ if (Number.isFinite(own)) opacity *= own;
54
55
  if (current === document.documentElement) break;
55
56
  current = current.parentElement;
56
57
  }
57
- return value;
58
+ return { laidOut: true, opacity: opacity <= TRANSPARENT ? 0 : opacity };
58
59
  }
59
60
  function holdsText(el) {
60
61
  for (const node of el.childNodes) {
@@ -79,15 +80,18 @@ function collectMedia(block) {
79
80
  for (const el of block.querySelectorAll(MEDIA)) media.push(el);
80
81
  return media;
81
82
  }
83
+ function laidOut(elements) {
84
+ return elements.map(paint).filter((state) => state.laidOut);
85
+ }
82
86
  function isBlockPainted(block) {
83
- const copy = collectCopy(block);
87
+ const copy = laidOut(collectCopy(block));
84
88
  if (copy.length > 0) {
85
- const visible2 = copy.filter((el) => effectiveOpacity(el) > TRANSPARENT);
89
+ const visible2 = copy.filter((state) => state.opacity > TRANSPARENT);
86
90
  return visible2.length >= copy.length * VISIBLE_TEXT_FRACTION;
87
91
  }
88
- const media = collectMedia(block);
92
+ const media = laidOut(collectMedia(block));
89
93
  if (media.length === 0) return true;
90
- return media.some((el) => effectiveOpacity(el) > TRANSPARENT);
94
+ return media.some((state) => state.opacity > TRANSPARENT);
91
95
  }
92
96
 
93
97
  // src/bridge/use-invisible-blocks.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/react",
3
- "version": "16.1.0",
3
+ "version": "16.2.0",
4
4
  "description": "React blocks, renderers, data client and editor bridge for cmssy headless sites",
5
5
  "keywords": [
6
6
  "cmssy",
@@ -96,8 +96,8 @@
96
96
  "vitest": "^2.1.0"
97
97
  },
98
98
  "dependencies": {
99
- "@cmssy/types": "0.41.0",
100
- "@cmssy/core": "16.1.0"
99
+ "@cmssy/types": "0.43.0",
100
+ "@cmssy/core": "16.2.0"
101
101
  },
102
102
  "scripts": {
103
103
  "build": "tsup",