@cmssy/react 19.35.1 → 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 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 copy = laidOut(collectCopy(block));
104
- if (copy.length > 0) {
105
- const visible2 = copy.filter((state) => state.opacity > TRANSPARENT);
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 copy = laidOut(collectCopy(block));
102
- if (copy.length > 0) {
103
- const visible2 = copy.filter((state) => state.opacity > TRANSPARENT);
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/dist/index.cjs CHANGED
@@ -848,11 +848,12 @@ function defineCmssyRouteConfig(config) {
848
848
  if (typeof window !== "undefined") {
849
849
  const carried = [
850
850
  ...config.draftSecret === void 0 ? [] : ["draftSecret"],
851
- ...config.devToken === void 0 ? [] : ["devToken"]
851
+ ...config.devToken === void 0 ? [] : ["devToken"],
852
+ ...config.apiToken === void 0 ? [] : ["apiToken"]
852
853
  ];
853
854
  if (carried.length > 0) {
854
855
  throw new Error(
855
- `cmssy: ${carried.join(" and ")} reached the browser. Anyone loading the page can read a value in the bundle: a draft secret opens every unpublished draft in the workspace, and a devToken is an API credential that writes to it. Keep both on a server build (@cmssy/next, @cmssy/astro or Vite SSR) and leave them out of a client-side config.`
856
+ `cmssy: ${carried.join(", ").replace(/, (?=[^,]*$)/, " and ")} reached the browser. Anyone loading the page can read a value in the bundle: a draft secret opens every unpublished draft in the workspace, and a devToken or apiToken is an API credential for it. Keep them on a server build (@cmssy/next, @cmssy/astro or Vite SSR) and leave them out of a client-side config.`
856
857
  );
857
858
  }
858
859
  }
package/dist/index.js CHANGED
@@ -848,11 +848,12 @@ function defineCmssyRouteConfig(config) {
848
848
  if (typeof window !== "undefined") {
849
849
  const carried = [
850
850
  ...config.draftSecret === void 0 ? [] : ["draftSecret"],
851
- ...config.devToken === void 0 ? [] : ["devToken"]
851
+ ...config.devToken === void 0 ? [] : ["devToken"],
852
+ ...config.apiToken === void 0 ? [] : ["apiToken"]
852
853
  ];
853
854
  if (carried.length > 0) {
854
855
  throw new Error(
855
- `cmssy: ${carried.join(" and ")} reached the browser. Anyone loading the page can read a value in the bundle: a draft secret opens every unpublished draft in the workspace, and a devToken is an API credential that writes to it. Keep both on a server build (@cmssy/next, @cmssy/astro or Vite SSR) and leave them out of a client-side config.`
856
+ `cmssy: ${carried.join(", ").replace(/, (?=[^,]*$)/, " and ")} reached the browser. Anyone loading the page can read a value in the bundle: a draft secret opens every unpublished draft in the workspace, and a devToken or apiToken is an API credential for it. Keep them on a server build (@cmssy/next, @cmssy/astro or Vite SSR) and leave them out of a client-side config.`
856
857
  );
857
858
  }
858
859
  }
package/dist/spa.cjs CHANGED
@@ -310,11 +310,12 @@ function defineCmssyRouteConfig(config) {
310
310
  if (typeof window !== "undefined") {
311
311
  const carried = [
312
312
  ...config.draftSecret === void 0 ? [] : ["draftSecret"],
313
- ...config.devToken === void 0 ? [] : ["devToken"]
313
+ ...config.devToken === void 0 ? [] : ["devToken"],
314
+ ...config.apiToken === void 0 ? [] : ["apiToken"]
314
315
  ];
315
316
  if (carried.length > 0) {
316
317
  throw new Error(
317
- `cmssy: ${carried.join(" and ")} reached the browser. Anyone loading the page can read a value in the bundle: a draft secret opens every unpublished draft in the workspace, and a devToken is an API credential that writes to it. Keep both on a server build (@cmssy/next, @cmssy/astro or Vite SSR) and leave them out of a client-side config.`
318
+ `cmssy: ${carried.join(", ").replace(/, (?=[^,]*$)/, " and ")} reached the browser. Anyone loading the page can read a value in the bundle: a draft secret opens every unpublished draft in the workspace, and a devToken or apiToken is an API credential for it. Keep them on a server build (@cmssy/next, @cmssy/astro or Vite SSR) and leave them out of a client-side config.`
318
319
  );
319
320
  }
320
321
  }
package/dist/spa.js CHANGED
@@ -308,11 +308,12 @@ function defineCmssyRouteConfig(config) {
308
308
  if (typeof window !== "undefined") {
309
309
  const carried = [
310
310
  ...config.draftSecret === void 0 ? [] : ["draftSecret"],
311
- ...config.devToken === void 0 ? [] : ["devToken"]
311
+ ...config.devToken === void 0 ? [] : ["devToken"],
312
+ ...config.apiToken === void 0 ? [] : ["apiToken"]
312
313
  ];
313
314
  if (carried.length > 0) {
314
315
  throw new Error(
315
- `cmssy: ${carried.join(" and ")} reached the browser. Anyone loading the page can read a value in the bundle: a draft secret opens every unpublished draft in the workspace, and a devToken is an API credential that writes to it. Keep both on a server build (@cmssy/next, @cmssy/astro or Vite SSR) and leave them out of a client-side config.`
316
+ `cmssy: ${carried.join(", ").replace(/, (?=[^,]*$)/, " and ")} reached the browser. Anyone loading the page can read a value in the bundle: a draft secret opens every unpublished draft in the workspace, and a devToken or apiToken is an API credential for it. Keep them on a server build (@cmssy/next, @cmssy/astro or Vite SSR) and leave them out of a client-side config.`
316
317
  );
317
318
  }
318
319
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/react",
3
- "version": "19.35.1",
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.35.1"
113
+ "@cmssy/core": "19.36.1"
114
114
  },
115
115
  "scripts": {
116
116
  "build": "tsup",