@scalemule/news-publication 0.0.77 → 0.0.79

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.
@@ -4,6 +4,46 @@
4
4
  var react = require('react');
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
6
 
7
+ // src/reader-sso-scheduler.ts
8
+ function mountReaderSsoScheduler({ document: doc, timers, eligible, attempt, idleDelayMs }) {
9
+ let active = true;
10
+ let attempted = false;
11
+ let idle;
12
+ let delay;
13
+ const cancelPending = () => {
14
+ if (idle !== void 0) timers.cancelIdleCallback?.(idle);
15
+ if (delay !== void 0) timers.clearTimeout(delay);
16
+ idle = delay = void 0;
17
+ };
18
+ const run = () => {
19
+ delay = void 0;
20
+ if (!active || attempted || !eligible()) return;
21
+ attempted = true;
22
+ attempt();
23
+ };
24
+ const defer = () => {
25
+ idle = void 0;
26
+ if (active && !attempted) delay = timers.setTimeout(run, idleDelayMs);
27
+ };
28
+ const schedule = () => {
29
+ if (!active || attempted) return;
30
+ cancelPending();
31
+ if (doc.readyState === "loading" || !eligible()) return;
32
+ if (timers.requestIdleCallback) idle = timers.requestIdleCallback(defer, { timeout: 4e3 });
33
+ else defer();
34
+ };
35
+ doc.addEventListener("DOMContentLoaded", schedule);
36
+ doc.addEventListener("visibilitychange", schedule);
37
+ doc.addEventListener("prerenderingchange", schedule);
38
+ schedule();
39
+ return () => {
40
+ active = false;
41
+ cancelPending();
42
+ doc.removeEventListener("DOMContentLoaded", schedule);
43
+ doc.removeEventListener("visibilitychange", schedule);
44
+ doc.removeEventListener("prerenderingchange", schedule);
45
+ };
46
+ }
7
47
  var READER_SSO_BOT_PATTERN = /bot|crawl|spider|headless|lighthouse|pagespeed|preview|slurp|facebookexternalhit|embedly|python|curl|wget|phantom|puppeteer|playwright|selenium|prerender/i;
8
48
  var READER_SSO_PRIVATE_PATHS = [
9
49
  /^\/account(\/|$)/,
@@ -38,9 +78,13 @@ function silentSignInUrl(startPath, pathname, search) {
38
78
  return `${startPath}?${new URLSearchParams({ mode: "silent", next: pathname + search })}`;
39
79
  }
40
80
  function isFormField(element) {
41
- if (!element) return false;
42
- const tag = element.tagName;
43
- return tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT" || element.isContentEditable === true;
81
+ let focused = element;
82
+ while (focused?.shadowRoot?.activeElement && focused.shadowRoot.activeElement !== focused) {
83
+ focused = focused.shadowRoot.activeElement;
84
+ }
85
+ if (!focused) return false;
86
+ const tag = focused.tagName;
87
+ return tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT" || focused.isContentEditable === true;
44
88
  }
45
89
  var ATTEMPT_KEY = "reader-sso-attempt-v1";
46
90
  function readAttempt() {
@@ -95,30 +139,18 @@ function ReaderSsoBoot({ enabled = true, hasSession: hasSessionCookie, suppresse
95
139
  }, [enabled, hasSessionCookie, staleCookie, sessionPath]);
96
140
  const hasSession = hasSessionCookie && !staleCookie;
97
141
  react.useEffect(() => {
98
- if (silentSignInDecision(browserEnvironment({ enabled, hasSession, suppressed, privatePaths })).attempt !== true) return;
99
- let cancelled = false;
100
- let idle;
101
- const go = () => {
102
- if (cancelled) return;
103
- const env = browserEnvironment({ enabled, hasSession, suppressed, privatePaths });
104
- if (silentSignInDecision(env).attempt !== true) return;
105
- writeAttempt(env.now);
106
- window.location.assign(silentSignInUrl(startPath, env.pathname, env.search));
107
- };
108
- const whenIdle = () => {
109
- const w = window;
110
- if (typeof w.requestIdleCallback === "function") idle = w.requestIdleCallback(() => {
111
- idle = window.setTimeout(go, idleDelayMs);
112
- }, { timeout: 4e3 });
113
- else idle = window.setTimeout(go, idleDelayMs);
114
- };
115
- if (document.readyState === "complete") whenIdle();
116
- else window.addEventListener("load", whenIdle, { once: true });
117
- return () => {
118
- cancelled = true;
119
- window.removeEventListener("load", whenIdle);
120
- if (idle !== void 0) window.clearTimeout(idle);
121
- };
142
+ const flags = { enabled, hasSession, suppressed, privatePaths };
143
+ return mountReaderSsoScheduler({
144
+ document,
145
+ timers: window,
146
+ idleDelayMs,
147
+ eligible: () => silentSignInDecision(browserEnvironment(flags)).attempt === true,
148
+ attempt: () => {
149
+ const env = browserEnvironment(flags);
150
+ writeAttempt(env.now);
151
+ window.location.assign(silentSignInUrl(startPath, env.pathname, env.search));
152
+ }
153
+ });
122
154
  }, [enabled, hasSession, suppressed, startPath, privatePaths, idleDelayMs]);
123
155
  return null;
124
156
  }
@@ -32,7 +32,7 @@ declare function silentSignInDecision(env: SilentSignInEnvironment): SilentSignI
32
32
  declare function silentSignInUrl(startPath: string, pathname: string, search: string): string;
33
33
  declare function isFormField(element: Element | null): boolean;
34
34
  /**
35
- * Renders nothing. Once per page load, after `load` and an idle period, performs a
35
+ * Renders nothing. Once per page load, after the DOM is usable and an idle period, performs a
36
36
  * top-level navigation to the silent sign-in start route when nothing argues
37
37
  * against it. The server sets the negative-cache cookie on every silent negative,
38
38
  * so this can never loop.
@@ -32,7 +32,7 @@ declare function silentSignInDecision(env: SilentSignInEnvironment): SilentSignI
32
32
  declare function silentSignInUrl(startPath: string, pathname: string, search: string): string;
33
33
  declare function isFormField(element: Element | null): boolean;
34
34
  /**
35
- * Renders nothing. Once per page load, after `load` and an idle period, performs a
35
+ * Renders nothing. Once per page load, after the DOM is usable and an idle period, performs a
36
36
  * top-level navigation to the silent sign-in start route when nothing argues
37
37
  * against it. The server sets the negative-cache cookie on every silent negative,
38
38
  * so this can never loop.
@@ -2,6 +2,46 @@
2
2
  import { useState, useEffect, useId } from 'react';
3
3
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
4
4
 
5
+ // src/reader-sso-scheduler.ts
6
+ function mountReaderSsoScheduler({ document: doc, timers, eligible, attempt, idleDelayMs }) {
7
+ let active = true;
8
+ let attempted = false;
9
+ let idle;
10
+ let delay;
11
+ const cancelPending = () => {
12
+ if (idle !== void 0) timers.cancelIdleCallback?.(idle);
13
+ if (delay !== void 0) timers.clearTimeout(delay);
14
+ idle = delay = void 0;
15
+ };
16
+ const run = () => {
17
+ delay = void 0;
18
+ if (!active || attempted || !eligible()) return;
19
+ attempted = true;
20
+ attempt();
21
+ };
22
+ const defer = () => {
23
+ idle = void 0;
24
+ if (active && !attempted) delay = timers.setTimeout(run, idleDelayMs);
25
+ };
26
+ const schedule = () => {
27
+ if (!active || attempted) return;
28
+ cancelPending();
29
+ if (doc.readyState === "loading" || !eligible()) return;
30
+ if (timers.requestIdleCallback) idle = timers.requestIdleCallback(defer, { timeout: 4e3 });
31
+ else defer();
32
+ };
33
+ doc.addEventListener("DOMContentLoaded", schedule);
34
+ doc.addEventListener("visibilitychange", schedule);
35
+ doc.addEventListener("prerenderingchange", schedule);
36
+ schedule();
37
+ return () => {
38
+ active = false;
39
+ cancelPending();
40
+ doc.removeEventListener("DOMContentLoaded", schedule);
41
+ doc.removeEventListener("visibilitychange", schedule);
42
+ doc.removeEventListener("prerenderingchange", schedule);
43
+ };
44
+ }
5
45
  var READER_SSO_BOT_PATTERN = /bot|crawl|spider|headless|lighthouse|pagespeed|preview|slurp|facebookexternalhit|embedly|python|curl|wget|phantom|puppeteer|playwright|selenium|prerender/i;
6
46
  var READER_SSO_PRIVATE_PATHS = [
7
47
  /^\/account(\/|$)/,
@@ -36,9 +76,13 @@ function silentSignInUrl(startPath, pathname, search) {
36
76
  return `${startPath}?${new URLSearchParams({ mode: "silent", next: pathname + search })}`;
37
77
  }
38
78
  function isFormField(element) {
39
- if (!element) return false;
40
- const tag = element.tagName;
41
- return tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT" || element.isContentEditable === true;
79
+ let focused = element;
80
+ while (focused?.shadowRoot?.activeElement && focused.shadowRoot.activeElement !== focused) {
81
+ focused = focused.shadowRoot.activeElement;
82
+ }
83
+ if (!focused) return false;
84
+ const tag = focused.tagName;
85
+ return tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT" || focused.isContentEditable === true;
42
86
  }
43
87
  var ATTEMPT_KEY = "reader-sso-attempt-v1";
44
88
  function readAttempt() {
@@ -93,30 +137,18 @@ function ReaderSsoBoot({ enabled = true, hasSession: hasSessionCookie, suppresse
93
137
  }, [enabled, hasSessionCookie, staleCookie, sessionPath]);
94
138
  const hasSession = hasSessionCookie && !staleCookie;
95
139
  useEffect(() => {
96
- if (silentSignInDecision(browserEnvironment({ enabled, hasSession, suppressed, privatePaths })).attempt !== true) return;
97
- let cancelled = false;
98
- let idle;
99
- const go = () => {
100
- if (cancelled) return;
101
- const env = browserEnvironment({ enabled, hasSession, suppressed, privatePaths });
102
- if (silentSignInDecision(env).attempt !== true) return;
103
- writeAttempt(env.now);
104
- window.location.assign(silentSignInUrl(startPath, env.pathname, env.search));
105
- };
106
- const whenIdle = () => {
107
- const w = window;
108
- if (typeof w.requestIdleCallback === "function") idle = w.requestIdleCallback(() => {
109
- idle = window.setTimeout(go, idleDelayMs);
110
- }, { timeout: 4e3 });
111
- else idle = window.setTimeout(go, idleDelayMs);
112
- };
113
- if (document.readyState === "complete") whenIdle();
114
- else window.addEventListener("load", whenIdle, { once: true });
115
- return () => {
116
- cancelled = true;
117
- window.removeEventListener("load", whenIdle);
118
- if (idle !== void 0) window.clearTimeout(idle);
119
- };
140
+ const flags = { enabled, hasSession, suppressed, privatePaths };
141
+ return mountReaderSsoScheduler({
142
+ document,
143
+ timers: window,
144
+ idleDelayMs,
145
+ eligible: () => silentSignInDecision(browserEnvironment(flags)).attempt === true,
146
+ attempt: () => {
147
+ const env = browserEnvironment(flags);
148
+ writeAttempt(env.now);
149
+ window.location.assign(silentSignInUrl(startPath, env.pathname, env.search));
150
+ }
151
+ });
120
152
  }, [enabled, hasSession, suppressed, startPath, privatePaths, idleDelayMs]);
121
153
  return null;
122
154
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalemule/news-publication",
3
- "version": "0.0.77",
3
+ "version": "0.0.79",
4
4
  "description": "Shared server framework for ScaleMule local news publications. Walnut Creek Times is the broadsheet default; each paper supplies its own identity and feature flags.",
5
5
  "type": "module",
6
6
  "bin": {