@cmssy/react 19.35.0 → 19.36.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
@@ -109,9 +109,19 @@ function blockPaint(block) {
109
109
  if (media.length === 0) return "painted";
110
110
  return media.some((state) => state.opacity > TRANSPARENT) ? "painted" : "transparent";
111
111
  }
112
+ function settles(animation) {
113
+ if (animation.playState !== "running") return false;
114
+ const end = animation.effect?.getComputedTiming().endTime;
115
+ return typeof end === "number" && Number.isFinite(end);
116
+ }
117
+ function isAnimatingIn(block) {
118
+ if (typeof block.getAnimations !== "function") return false;
119
+ return block.getAnimations({ subtree: true }).some(settles);
120
+ }
112
121
 
113
122
  // src/bridge/use-invisible-blocks.ts
114
123
  var DWELL_MS = 1500;
124
+ var CONFIRM_MS = 3e3;
115
125
  var VISIBLE_FRACTION = 0.35;
116
126
  var SWEEP_MS = 2e3;
117
127
  function useInvisibleBlocks(enabled, blocksKey, report) {
@@ -123,6 +133,7 @@ function useInvisibleBlocks(enabled, blocksKey, report) {
123
133
  if (typeof IntersectionObserver === "undefined") return;
124
134
  const timers = /* @__PURE__ */ new Map();
125
135
  const observed = /* @__PURE__ */ new WeakSet();
136
+ const suspects = /* @__PURE__ */ new WeakSet();
126
137
  const invisible = /* @__PURE__ */ new Map();
127
138
  let reported = "";
128
139
  const flush = () => {
@@ -132,13 +143,32 @@ function useInvisibleBlocks(enabled, blocksKey, report) {
132
143
  reported = key;
133
144
  reportRef.current(blocks);
134
145
  };
146
+ const schedule = (el, delay) => {
147
+ timers.set(
148
+ el,
149
+ setTimeout(() => {
150
+ timers.delete(el);
151
+ judge(el);
152
+ }, delay)
153
+ );
154
+ };
135
155
  const judge = (el) => {
136
156
  const blockId = el.getAttribute("data-block-id");
137
157
  const blockType = el.getAttribute("data-block-type");
138
158
  if (!blockId || !blockType) return;
139
159
  const paint2 = blockPaint(el);
140
- if (paint2 === "painted") invisible.delete(blockId);
141
- else invisible.set(blockId, { blockId, blockType, reason: paint2 });
160
+ if (paint2 === "painted") {
161
+ suspects.delete(el);
162
+ invisible.delete(blockId);
163
+ flush();
164
+ return;
165
+ }
166
+ if (!suspects.has(el) || isAnimatingIn(el)) {
167
+ suspects.add(el);
168
+ schedule(el, CONFIRM_MS);
169
+ return;
170
+ }
171
+ invisible.set(blockId, { blockId, blockType, reason: paint2 });
142
172
  flush();
143
173
  };
144
174
  const observer = new IntersectionObserver(
@@ -150,16 +180,11 @@ function useInvisibleBlocks(enabled, blocksKey, report) {
150
180
  clearTimeout(pending);
151
181
  timers.delete(entry.target);
152
182
  }
183
+ suspects.delete(entry.target);
153
184
  continue;
154
185
  }
155
186
  if (pending) continue;
156
- timers.set(
157
- entry.target,
158
- setTimeout(() => {
159
- timers.delete(entry.target);
160
- judge(entry.target);
161
- }, DWELL_MS)
162
- );
187
+ schedule(entry.target, DWELL_MS);
163
188
  }
164
189
  },
165
190
  { threshold: VISIBLE_FRACTION }
package/dist/client.js CHANGED
@@ -107,9 +107,19 @@ function blockPaint(block) {
107
107
  if (media.length === 0) return "painted";
108
108
  return media.some((state) => state.opacity > TRANSPARENT) ? "painted" : "transparent";
109
109
  }
110
+ function settles(animation) {
111
+ if (animation.playState !== "running") return false;
112
+ const end = animation.effect?.getComputedTiming().endTime;
113
+ return typeof end === "number" && Number.isFinite(end);
114
+ }
115
+ function isAnimatingIn(block) {
116
+ if (typeof block.getAnimations !== "function") return false;
117
+ return block.getAnimations({ subtree: true }).some(settles);
118
+ }
110
119
 
111
120
  // src/bridge/use-invisible-blocks.ts
112
121
  var DWELL_MS = 1500;
122
+ var CONFIRM_MS = 3e3;
113
123
  var VISIBLE_FRACTION = 0.35;
114
124
  var SWEEP_MS = 2e3;
115
125
  function useInvisibleBlocks(enabled, blocksKey, report) {
@@ -121,6 +131,7 @@ function useInvisibleBlocks(enabled, blocksKey, report) {
121
131
  if (typeof IntersectionObserver === "undefined") return;
122
132
  const timers = /* @__PURE__ */ new Map();
123
133
  const observed = /* @__PURE__ */ new WeakSet();
134
+ const suspects = /* @__PURE__ */ new WeakSet();
124
135
  const invisible = /* @__PURE__ */ new Map();
125
136
  let reported = "";
126
137
  const flush = () => {
@@ -130,13 +141,32 @@ function useInvisibleBlocks(enabled, blocksKey, report) {
130
141
  reported = key;
131
142
  reportRef.current(blocks);
132
143
  };
144
+ const schedule = (el, delay) => {
145
+ timers.set(
146
+ el,
147
+ setTimeout(() => {
148
+ timers.delete(el);
149
+ judge(el);
150
+ }, delay)
151
+ );
152
+ };
133
153
  const judge = (el) => {
134
154
  const blockId = el.getAttribute("data-block-id");
135
155
  const blockType = el.getAttribute("data-block-type");
136
156
  if (!blockId || !blockType) return;
137
157
  const paint2 = blockPaint(el);
138
- if (paint2 === "painted") invisible.delete(blockId);
139
- else invisible.set(blockId, { blockId, blockType, reason: paint2 });
158
+ if (paint2 === "painted") {
159
+ suspects.delete(el);
160
+ invisible.delete(blockId);
161
+ flush();
162
+ return;
163
+ }
164
+ if (!suspects.has(el) || isAnimatingIn(el)) {
165
+ suspects.add(el);
166
+ schedule(el, CONFIRM_MS);
167
+ return;
168
+ }
169
+ invisible.set(blockId, { blockId, blockType, reason: paint2 });
140
170
  flush();
141
171
  };
142
172
  const observer = new IntersectionObserver(
@@ -148,16 +178,11 @@ function useInvisibleBlocks(enabled, blocksKey, report) {
148
178
  clearTimeout(pending);
149
179
  timers.delete(entry.target);
150
180
  }
181
+ suspects.delete(entry.target);
151
182
  continue;
152
183
  }
153
184
  if (pending) continue;
154
- timers.set(
155
- entry.target,
156
- setTimeout(() => {
157
- timers.delete(entry.target);
158
- judge(entry.target);
159
- }, DWELL_MS)
160
- );
185
+ schedule(entry.target, DWELL_MS);
161
186
  }
162
187
  },
163
188
  { threshold: VISIBLE_FRACTION }
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.0",
3
+ "version": "19.36.0",
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.0"
113
+ "@cmssy/core": "19.36.0"
114
114
  },
115
115
  "scripts": {
116
116
  "build": "tsup",