@cmssy/react 19.36.0 → 19.36.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.
- package/dist/client.cjs +24 -4
- package/dist/client.js +24 -4
- package/package.json +2 -2
package/dist/client.cjs
CHANGED
|
@@ -92,6 +92,27 @@ function collectMedia(block) {
|
|
|
92
92
|
function laidOut(elements) {
|
|
93
93
|
return elements.map(paint).filter((state) => state.laidOut);
|
|
94
94
|
}
|
|
95
|
+
function textArea(el) {
|
|
96
|
+
let total = 0;
|
|
97
|
+
for (const node of el.childNodes) {
|
|
98
|
+
if (node.nodeType !== 3 || !node.textContent?.trim()) continue;
|
|
99
|
+
const range = document.createRange();
|
|
100
|
+
range.selectNodeContents(node);
|
|
101
|
+
if (typeof range.getClientRects !== "function") continue;
|
|
102
|
+
for (const rect of range.getClientRects()) {
|
|
103
|
+
total += Math.max(0, rect.width) * Math.max(0, rect.height);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return total;
|
|
107
|
+
}
|
|
108
|
+
function visibleCopyShare(copy) {
|
|
109
|
+
const states = copy.map((el) => ({ paint: paint(el), area: textArea(el) })).filter((state) => state.paint.laidOut);
|
|
110
|
+
if (states.length === 0) return null;
|
|
111
|
+
const total = states.reduce((sum, state) => sum + state.area, 0);
|
|
112
|
+
const weight = (state) => total > 0 ? state.area : 1;
|
|
113
|
+
const visible2 = states.filter((state) => state.paint.opacity > TRANSPARENT).reduce((sum, state) => sum + weight(state), 0);
|
|
114
|
+
return visible2 / (total > 0 ? total : states.length);
|
|
115
|
+
}
|
|
95
116
|
function hasArea(block) {
|
|
96
117
|
const rect = block.getBoundingClientRect();
|
|
97
118
|
return rect.width > 0 && rect.height > 0;
|
|
@@ -100,10 +121,9 @@ function blockPaint(block) {
|
|
|
100
121
|
if (block.childElementCount === 0 && !holdsText(block) && !hasArea(block)) {
|
|
101
122
|
return "empty";
|
|
102
123
|
}
|
|
103
|
-
const
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
-
return visible2.length >= copy.length * VISIBLE_TEXT_FRACTION ? "painted" : "transparent";
|
|
124
|
+
const share = visibleCopyShare(collectCopy(block));
|
|
125
|
+
if (share !== null) {
|
|
126
|
+
return share >= VISIBLE_TEXT_FRACTION ? "painted" : "transparent";
|
|
107
127
|
}
|
|
108
128
|
const media = laidOut(collectMedia(block));
|
|
109
129
|
if (media.length === 0) return "painted";
|
package/dist/client.js
CHANGED
|
@@ -90,6 +90,27 @@ function collectMedia(block) {
|
|
|
90
90
|
function laidOut(elements) {
|
|
91
91
|
return elements.map(paint).filter((state) => state.laidOut);
|
|
92
92
|
}
|
|
93
|
+
function textArea(el) {
|
|
94
|
+
let total = 0;
|
|
95
|
+
for (const node of el.childNodes) {
|
|
96
|
+
if (node.nodeType !== 3 || !node.textContent?.trim()) continue;
|
|
97
|
+
const range = document.createRange();
|
|
98
|
+
range.selectNodeContents(node);
|
|
99
|
+
if (typeof range.getClientRects !== "function") continue;
|
|
100
|
+
for (const rect of range.getClientRects()) {
|
|
101
|
+
total += Math.max(0, rect.width) * Math.max(0, rect.height);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return total;
|
|
105
|
+
}
|
|
106
|
+
function visibleCopyShare(copy) {
|
|
107
|
+
const states = copy.map((el) => ({ paint: paint(el), area: textArea(el) })).filter((state) => state.paint.laidOut);
|
|
108
|
+
if (states.length === 0) return null;
|
|
109
|
+
const total = states.reduce((sum, state) => sum + state.area, 0);
|
|
110
|
+
const weight = (state) => total > 0 ? state.area : 1;
|
|
111
|
+
const visible2 = states.filter((state) => state.paint.opacity > TRANSPARENT).reduce((sum, state) => sum + weight(state), 0);
|
|
112
|
+
return visible2 / (total > 0 ? total : states.length);
|
|
113
|
+
}
|
|
93
114
|
function hasArea(block) {
|
|
94
115
|
const rect = block.getBoundingClientRect();
|
|
95
116
|
return rect.width > 0 && rect.height > 0;
|
|
@@ -98,10 +119,9 @@ function blockPaint(block) {
|
|
|
98
119
|
if (block.childElementCount === 0 && !holdsText(block) && !hasArea(block)) {
|
|
99
120
|
return "empty";
|
|
100
121
|
}
|
|
101
|
-
const
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
return visible2.length >= copy.length * VISIBLE_TEXT_FRACTION ? "painted" : "transparent";
|
|
122
|
+
const share = visibleCopyShare(collectCopy(block));
|
|
123
|
+
if (share !== null) {
|
|
124
|
+
return share >= VISIBLE_TEXT_FRACTION ? "painted" : "transparent";
|
|
105
125
|
}
|
|
106
126
|
const media = laidOut(collectMedia(block));
|
|
107
127
|
if (media.length === 0) return "painted";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cmssy/react",
|
|
3
|
-
"version": "19.36.
|
|
3
|
+
"version": "19.36.1",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=20"
|
|
6
6
|
},
|
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
},
|
|
111
111
|
"dependencies": {
|
|
112
112
|
"@cmssy/types": "0.77.0",
|
|
113
|
-
"@cmssy/core": "19.36.
|
|
113
|
+
"@cmssy/core": "19.36.1"
|
|
114
114
|
},
|
|
115
115
|
"scripts": {
|
|
116
116
|
"build": "tsup",
|