@scalemule/news-publication 0.0.7

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.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +74 -0
  3. package/cookie-consent.css +419 -0
  4. package/dist/chunk-C7JTEHTH.js +158 -0
  5. package/dist/chunk-GB36YM56.js +72 -0
  6. package/dist/chunk-PYCU2T5O.js +93 -0
  7. package/dist/chunk-R33MJWND.js +261 -0
  8. package/dist/chunk-TJ7RL3PV.js +252 -0
  9. package/dist/chunk-YQXS2KQI.js +112 -0
  10. package/dist/cookie-consent-banner.cjs +210 -0
  11. package/dist/cookie-consent-banner.d.cts +19 -0
  12. package/dist/cookie-consent-banner.d.ts +19 -0
  13. package/dist/cookie-consent-banner.js +3 -0
  14. package/dist/cookie-settings-view.cjs +470 -0
  15. package/dist/cookie-settings-view.d.cts +15 -0
  16. package/dist/cookie-settings-view.d.ts +15 -0
  17. package/dist/cookie-settings-view.js +3 -0
  18. package/dist/index.cjs +1460 -0
  19. package/dist/index.d.cts +317 -0
  20. package/dist/index.d.ts +317 -0
  21. package/dist/index.js +441 -0
  22. package/dist/marketplace-Ch7mdJZv.d.cts +123 -0
  23. package/dist/marketplace-Ch7mdJZv.d.ts +123 -0
  24. package/dist/marketplace-forms.cjs +134 -0
  25. package/dist/marketplace-forms.d.cts +10 -0
  26. package/dist/marketplace-forms.d.ts +10 -0
  27. package/dist/marketplace-forms.js +115 -0
  28. package/dist/marketplace-view.cjs +110 -0
  29. package/dist/marketplace-view.d.cts +21 -0
  30. package/dist/marketplace-view.d.ts +21 -0
  31. package/dist/marketplace-view.js +85 -0
  32. package/dist/meet-5Ym5bxfh.d.cts +79 -0
  33. package/dist/meet-5Ym5bxfh.d.ts +79 -0
  34. package/dist/meet-forms.cjs +188 -0
  35. package/dist/meet-forms.d.cts +13 -0
  36. package/dist/meet-forms.d.ts +13 -0
  37. package/dist/meet-forms.js +166 -0
  38. package/dist/meet-view.cjs +82 -0
  39. package/dist/meet-view.d.cts +23 -0
  40. package/dist/meet-view.d.ts +23 -0
  41. package/dist/meet-view.js +59 -0
  42. package/dist/snapshot-BS4hn1dk.d.cts +234 -0
  43. package/dist/snapshot-BS4hn1dk.d.ts +234 -0
  44. package/dist/snapshot-file.cjs +192 -0
  45. package/dist/snapshot-file.d.cts +21 -0
  46. package/dist/snapshot-file.d.ts +21 -0
  47. package/dist/snapshot-file.js +38 -0
  48. package/marketplace.css +61 -0
  49. package/package.json +103 -0
  50. package/tokens/broadsheet.css +61 -0
@@ -0,0 +1,72 @@
1
+ // src/meet.ts
2
+ var MEET_ACTIVITIES = [
3
+ { value: "coffee", label: "Coffee" },
4
+ { value: "walk", label: "Walk" },
5
+ { value: "hike", label: "Hike" },
6
+ { value: "pickleball", label: "Pickleball" },
7
+ { value: "tennis", label: "Tennis" },
8
+ { value: "soccer", label: "Soccer" },
9
+ { value: "bike", label: "Bike ride" },
10
+ { value: "dogs", label: "Dog walk" },
11
+ { value: "books", label: "Book club" },
12
+ { value: "games", label: "Board games" },
13
+ { value: "kids", label: "Kids outing" },
14
+ { value: "volunteer", label: "Volunteer" },
15
+ { value: "other", label: "Something else" }
16
+ ];
17
+ var HOST_WAIT_MS = 48 * 60 * 60 * 1e3;
18
+ function isAdult(bornOn, now = /* @__PURE__ */ new Date()) {
19
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(bornOn)) return false;
20
+ const born = /* @__PURE__ */ new Date(`${bornOn}T00:00:00.000Z`);
21
+ if (Number.isNaN(born.getTime())) return false;
22
+ const adult = new Date(born);
23
+ adult.setUTCFullYear(adult.getUTCFullYear() + 18);
24
+ return adult.getTime() <= now.getTime();
25
+ }
26
+ function canHostMeetup(accountCreatedAt, now = /* @__PURE__ */ new Date()) {
27
+ const created = Date.parse(accountCreatedAt);
28
+ return Number.isFinite(created) && now.getTime() - created >= HOST_WAIT_MS;
29
+ }
30
+ function screenMessage(value) {
31
+ const text = Array.from(value.trim()).slice(0, 1e3).join("");
32
+ if (Array.from(text).length < 1) return { ok: false, reason: "Write a short message." };
33
+ if (/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}/i.test(text)) return { ok: false, reason: "Share an email in person, not in the chat." };
34
+ if (/(https?:\/\/|www\.)\S+/i.test(text)) return { ok: false, reason: "Links are not allowed in the chat." };
35
+ const digits = text.replace(/\D/g, "");
36
+ if (digits.length >= 10) return { ok: false, reason: "Share a phone number in person, not in the chat." };
37
+ return { ok: true, text };
38
+ }
39
+ function activityLabel(value, otherLabel = "") {
40
+ if (value === "other") return Array.from(otherLabel.trim()).slice(0, 40).join("") || "Something else";
41
+ return MEET_ACTIVITIES.find((item) => item.value === value)?.label ?? "";
42
+ }
43
+ function prepareMeetup(input, places, now = /* @__PURE__ */ new Date()) {
44
+ const activity = typeof input.activity === "string" ? input.activity : "";
45
+ if (!MEET_ACTIVITIES.some((item) => item.value === activity)) throw new Error("Choose an activity.");
46
+ const label = activityLabel(activity, typeof input.otherLabel === "string" ? input.otherLabel : "");
47
+ if (activity === "other" && label === "Something else" && !String(input.otherLabel ?? "").trim()) {
48
+ throw new Error("Name the activity.");
49
+ }
50
+ const place = places.find((item) => item.id === input.placeId);
51
+ if (!place) throw new Error("Choose a public place.");
52
+ const starts = typeof input.startsAt === "string" ? Date.parse(input.startsAt) : NaN;
53
+ if (!Number.isFinite(starts) || starts < now.getTime() + 60 * 60 * 1e3) {
54
+ throw new Error("Choose a time at least an hour from now.");
55
+ }
56
+ const notes = screenMessage(typeof input.notes === "string" && input.notes.trim() ? input.notes : "Meet at the public place.");
57
+ if (!notes.ok) throw new Error(notes.reason);
58
+ const capacity = Number(input.capacity ?? 6);
59
+ if (!Number.isInteger(capacity) || capacity < 2 || capacity > 12) throw new Error("Choose a group size from 2 to 12.");
60
+ return {
61
+ activity,
62
+ activityLabel: label,
63
+ placeId: place.id,
64
+ placeName: place.name,
65
+ placeDetail: place.detail,
66
+ startsAt: new Date(starts).toISOString(),
67
+ notes: notes.text,
68
+ capacity
69
+ };
70
+ }
71
+
72
+ export { MEET_ACTIVITIES, activityLabel, canHostMeetup, isAdult, prepareMeetup, screenMessage };
@@ -0,0 +1,93 @@
1
+ import { hasConsented, COOKIE_CONSENT_EVENT, acceptAllCookies, recordConsentToCompliance, rejectOptionalCookies } from './chunk-TJ7RL3PV.js';
2
+ import { useState, useEffect } from 'react';
3
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
4
+
5
+ function CookieConsentBanner({
6
+ title = "Help Us Improve Our Website with Cookies",
7
+ text,
8
+ settingsUrl = "/cookies",
9
+ className = "",
10
+ publicationSlug,
11
+ complianceEndpoint = "/api/compliance/consent"
12
+ }) {
13
+ const [mounted, setMounted] = useState(false);
14
+ const [visible, setVisible] = useState(false);
15
+ useEffect(() => {
16
+ setMounted(true);
17
+ if (!hasConsented()) {
18
+ const timer = window.setTimeout(() => setVisible(true), 300);
19
+ return () => window.clearTimeout(timer);
20
+ }
21
+ const onConsentChange = () => {
22
+ if (hasConsented()) {
23
+ setVisible(false);
24
+ }
25
+ };
26
+ window.addEventListener(COOKIE_CONSENT_EVENT, onConsentChange);
27
+ return () => window.removeEventListener(COOKIE_CONSENT_EVENT, onConsentChange);
28
+ }, []);
29
+ if (!mounted || !visible) return null;
30
+ const handleAccept = () => {
31
+ const record = acceptAllCookies();
32
+ setVisible(false);
33
+ void recordConsentToCompliance(record, {
34
+ endpoint: complianceEndpoint,
35
+ publicationSlug
36
+ });
37
+ };
38
+ const handleReject = () => {
39
+ const record = rejectOptionalCookies();
40
+ setVisible(false);
41
+ void recordConsentToCompliance(record, {
42
+ endpoint: complianceEndpoint,
43
+ publicationSlug
44
+ });
45
+ };
46
+ const defaultText = /* @__PURE__ */ jsxs(Fragment, { children: [
47
+ "We use cookies and process data from your device to analyze website performance, personalize ad content, and improve your experience. Your consent includes data transfers outside of the country you\u2019re located. View",
48
+ " ",
49
+ /* @__PURE__ */ jsx("a", { href: settingsUrl, className: "sm-cookie-banner-link", children: "Cookie Settings" }),
50
+ " ",
51
+ "for more information."
52
+ ] });
53
+ return /* @__PURE__ */ jsx(
54
+ "aside",
55
+ {
56
+ className: `sm-cookie-banner-wrapper ${className}`,
57
+ role: "region",
58
+ "aria-label": "Cookie consent",
59
+ children: /* @__PURE__ */ jsxs("div", { className: "sm-cookie-banner-card", children: [
60
+ /* @__PURE__ */ jsxs("div", { className: "sm-cookie-banner-content", children: [
61
+ /* @__PURE__ */ jsx("h2", { className: "sm-cookie-banner-title", children: title }),
62
+ /* @__PURE__ */ jsx("p", { className: "sm-cookie-banner-text", children: text ? /* @__PURE__ */ jsxs(Fragment, { children: [
63
+ text,
64
+ " ",
65
+ /* @__PURE__ */ jsx("a", { href: settingsUrl, className: "sm-cookie-banner-link", children: "Cookie Settings" })
66
+ ] }) : defaultText })
67
+ ] }),
68
+ /* @__PURE__ */ jsxs("div", { className: "sm-cookie-banner-actions", children: [
69
+ /* @__PURE__ */ jsx(
70
+ "button",
71
+ {
72
+ type: "button",
73
+ className: "sm-cookie-btn sm-cookie-btn-primary",
74
+ onClick: handleAccept,
75
+ children: "Accept"
76
+ }
77
+ ),
78
+ /* @__PURE__ */ jsx(
79
+ "button",
80
+ {
81
+ type: "button",
82
+ className: "sm-cookie-btn sm-cookie-btn-secondary",
83
+ onClick: handleReject,
84
+ children: "Reject"
85
+ }
86
+ )
87
+ ] })
88
+ ] })
89
+ }
90
+ );
91
+ }
92
+
93
+ export { CookieConsentBanner };
@@ -0,0 +1,261 @@
1
+ import { getCookieConsent, DEFAULT_PREFERENCES_ACCEPTED, COOKIE_CATEGORIES, setCookieConsent, recordConsentToCompliance, DEFAULT_PREFERENCES_REJECTED } from './chunk-TJ7RL3PV.js';
2
+ import { useState, useEffect } from 'react';
3
+ import { jsxs, jsx } from 'react/jsx-runtime';
4
+
5
+ function CookieSettingsView({
6
+ publicationName = "This Publication",
7
+ region,
8
+ complianceEndpoint = "/api/compliance/consent",
9
+ publicationSlug
10
+ }) {
11
+ const [preferences, setPreferences] = useState(() => {
12
+ const existing = getCookieConsent();
13
+ return existing ? existing.preferences : { ...DEFAULT_PREFERENCES_ACCEPTED };
14
+ });
15
+ const [expandedCategories, setExpandedCategories] = useState({
16
+ essential: false,
17
+ performance: false,
18
+ functional: false,
19
+ advertising: false
20
+ });
21
+ const [saveSuccess, setSaveSuccess] = useState(false);
22
+ const [lastSavedTime, setLastSavedTime] = useState(null);
23
+ useEffect(() => {
24
+ const existing = getCookieConsent();
25
+ if (existing) {
26
+ setPreferences(existing.preferences);
27
+ setLastSavedTime(new Date(existing.timestamp).toLocaleTimeString([], { hour: "numeric", minute: "2-digit" }));
28
+ }
29
+ }, []);
30
+ const handleToggle = (category) => {
31
+ if (category === "essential") return;
32
+ setPreferences((prev) => ({
33
+ ...prev,
34
+ [category]: !prev[category]
35
+ }));
36
+ setSaveSuccess(false);
37
+ };
38
+ const toggleExpand = (category) => {
39
+ setExpandedCategories((prev) => ({
40
+ ...prev,
41
+ [category]: !prev[category]
42
+ }));
43
+ };
44
+ const handleSave = () => {
45
+ const record = setCookieConsent(preferences, "settings_save");
46
+ setSaveSuccess(true);
47
+ setLastSavedTime(new Date(record.timestamp).toLocaleTimeString([], { hour: "numeric", minute: "2-digit" }));
48
+ void recordConsentToCompliance(record, {
49
+ endpoint: complianceEndpoint,
50
+ publicationSlug
51
+ });
52
+ window.scrollTo({ top: 0, behavior: "smooth" });
53
+ };
54
+ const handleAcceptAll = () => {
55
+ setPreferences({ ...DEFAULT_PREFERENCES_ACCEPTED });
56
+ const record = setCookieConsent(DEFAULT_PREFERENCES_ACCEPTED, "settings_save");
57
+ setSaveSuccess(true);
58
+ setLastSavedTime(new Date(record.timestamp).toLocaleTimeString([], { hour: "numeric", minute: "2-digit" }));
59
+ void recordConsentToCompliance(record, {
60
+ endpoint: complianceEndpoint,
61
+ publicationSlug
62
+ });
63
+ window.scrollTo({ top: 0, behavior: "smooth" });
64
+ };
65
+ const handleRejectAll = () => {
66
+ setPreferences({ ...DEFAULT_PREFERENCES_REJECTED });
67
+ const record = setCookieConsent(DEFAULT_PREFERENCES_REJECTED, "settings_save");
68
+ setSaveSuccess(true);
69
+ setLastSavedTime(new Date(record.timestamp).toLocaleTimeString([], { hour: "numeric", minute: "2-digit" }));
70
+ void recordConsentToCompliance(record, {
71
+ endpoint: complianceEndpoint,
72
+ publicationSlug
73
+ });
74
+ window.scrollTo({ top: 0, behavior: "smooth" });
75
+ };
76
+ return /* @__PURE__ */ jsxs("div", { className: "sm-cookie-settings-container", children: [
77
+ /* @__PURE__ */ jsxs("header", { className: "sm-cookie-settings-header", children: [
78
+ /* @__PURE__ */ jsxs("div", { className: "sm-cookie-settings-eyebrow", children: [
79
+ publicationName,
80
+ " \xB7 Legal & Privacy"
81
+ ] }),
82
+ /* @__PURE__ */ jsx("h1", { className: "sm-cookie-settings-title", children: "Cookie Settings & Privacy Controls" }),
83
+ /* @__PURE__ */ jsxs("p", { className: "sm-cookie-settings-intro", children: [
84
+ "We believe in transparent, neighborly community journalism. When you visit ",
85
+ publicationName,
86
+ region ? ` across ${region}` : "",
87
+ ", we use cookies and process device data to ensure the website is secure, reliable, and easy to read. Review our cookie categories below, view detailed technical disclosures, and choose your preferences at any time."
88
+ ] })
89
+ ] }),
90
+ saveSuccess && /* @__PURE__ */ jsxs("div", { className: "sm-cookie-alert-success", role: "status", "aria-live": "polite", children: [
91
+ /* @__PURE__ */ jsx("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsx(
92
+ "path",
93
+ {
94
+ d: "M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.707l-4.5 4.5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L8.5 10.586l3.793-3.793a1 1 0 011.414 1.414z",
95
+ fill: "currentColor"
96
+ }
97
+ ) }),
98
+ /* @__PURE__ */ jsxs("div", { children: [
99
+ /* @__PURE__ */ jsx("strong", { children: "Preferences Saved." }),
100
+ " Your cookie choices have been updated",
101
+ lastSavedTime ? ` (at ${lastSavedTime})` : "",
102
+ " and will be remembered across all community editions."
103
+ ] })
104
+ ] }),
105
+ /* @__PURE__ */ jsxs("div", { className: "sm-cookie-global-actions", children: [
106
+ /* @__PURE__ */ jsx(
107
+ "button",
108
+ {
109
+ type: "button",
110
+ className: "sm-cookie-btn sm-cookie-btn-secondary",
111
+ onClick: handleRejectAll,
112
+ children: "Reject Optional Cookies"
113
+ }
114
+ ),
115
+ /* @__PURE__ */ jsx(
116
+ "button",
117
+ {
118
+ type: "button",
119
+ className: "sm-cookie-btn sm-cookie-btn-secondary",
120
+ onClick: handleAcceptAll,
121
+ children: "Accept All Cookies"
122
+ }
123
+ ),
124
+ /* @__PURE__ */ jsx(
125
+ "button",
126
+ {
127
+ type: "button",
128
+ className: "sm-cookie-btn sm-cookie-btn-primary",
129
+ onClick: handleSave,
130
+ children: "Save Preferences"
131
+ }
132
+ )
133
+ ] }),
134
+ /* @__PURE__ */ jsx("div", { className: "sm-cookie-category-list", children: COOKIE_CATEGORIES.map((category) => {
135
+ const isEssential = category.id === "essential";
136
+ const isChecked = isEssential || preferences[category.id];
137
+ const isExpanded = expandedCategories[category.id];
138
+ return /* @__PURE__ */ jsxs(
139
+ "section",
140
+ {
141
+ className: "sm-cookie-category-card",
142
+ "aria-labelledby": `cookie-cat-${category.id}`,
143
+ children: [
144
+ /* @__PURE__ */ jsxs("div", { className: "sm-cookie-category-top", children: [
145
+ /* @__PURE__ */ jsx("h2", { id: `cookie-cat-${category.id}`, className: "sm-cookie-category-heading", children: category.title }),
146
+ isEssential ? /* @__PURE__ */ jsx("span", { className: "sm-cookie-badge-required", children: "Always Active" }) : /* @__PURE__ */ jsxs(
147
+ "label",
148
+ {
149
+ className: "sm-cookie-switch-label",
150
+ htmlFor: `toggle-${category.id}`,
151
+ "aria-label": `Toggle ${category.title}`,
152
+ children: [
153
+ /* @__PURE__ */ jsx(
154
+ "input",
155
+ {
156
+ id: `toggle-${category.id}`,
157
+ type: "checkbox",
158
+ className: "sm-cookie-switch-input",
159
+ checked: isChecked,
160
+ onChange: () => handleToggle(category.id)
161
+ }
162
+ ),
163
+ /* @__PURE__ */ jsx("span", { className: "sm-cookie-switch-slider" })
164
+ ]
165
+ }
166
+ )
167
+ ] }),
168
+ /* @__PURE__ */ jsx("p", { className: "sm-cookie-category-desc", children: category.fullDescription }),
169
+ /* @__PURE__ */ jsxs("div", { children: [
170
+ /* @__PURE__ */ jsxs(
171
+ "button",
172
+ {
173
+ type: "button",
174
+ className: "sm-cookie-details-toggle",
175
+ onClick: () => toggleExpand(category.id),
176
+ "aria-expanded": isExpanded,
177
+ children: [
178
+ /* @__PURE__ */ jsx(
179
+ "svg",
180
+ {
181
+ width: "14",
182
+ height: "14",
183
+ viewBox: "0 0 20 20",
184
+ fill: "currentColor",
185
+ style: {
186
+ transform: isExpanded ? "rotate(90deg)" : "rotate(0deg)",
187
+ transition: "transform 0.2s ease"
188
+ },
189
+ "aria-hidden": "true",
190
+ children: /* @__PURE__ */ jsx(
191
+ "path",
192
+ {
193
+ fillRule: "evenodd",
194
+ d: "M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z",
195
+ clipRule: "evenodd"
196
+ }
197
+ )
198
+ }
199
+ ),
200
+ isExpanded ? "Hide cookie disclosures" : `View ${category.cookies.length} cookie disclosures`
201
+ ]
202
+ }
203
+ ),
204
+ isExpanded && /* @__PURE__ */ jsx("div", { className: "sm-cookie-table-wrapper", children: /* @__PURE__ */ jsxs("table", { className: "sm-cookie-table", children: [
205
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
206
+ /* @__PURE__ */ jsx("th", { children: "Cookie Name" }),
207
+ /* @__PURE__ */ jsx("th", { children: "Provider" }),
208
+ /* @__PURE__ */ jsx("th", { children: "Duration" }),
209
+ /* @__PURE__ */ jsx("th", { children: "Storage Type" }),
210
+ /* @__PURE__ */ jsx("th", { children: "Purpose" })
211
+ ] }) }),
212
+ /* @__PURE__ */ jsx("tbody", { children: category.cookies.map((cookie) => /* @__PURE__ */ jsxs("tr", { children: [
213
+ /* @__PURE__ */ jsx("td", { children: /* @__PURE__ */ jsx("code", { className: "sm-cookie-code", children: cookie.name }) }),
214
+ /* @__PURE__ */ jsx("td", { children: cookie.provider }),
215
+ /* @__PURE__ */ jsx("td", { children: cookie.duration }),
216
+ /* @__PURE__ */ jsx("td", { children: cookie.type }),
217
+ /* @__PURE__ */ jsx("td", { children: cookie.purpose })
218
+ ] }, cookie.name)) })
219
+ ] }) })
220
+ ] })
221
+ ]
222
+ },
223
+ category.id
224
+ );
225
+ }) }),
226
+ /* @__PURE__ */ jsxs("div", { className: "sm-cookie-save-bar", children: [
227
+ /* @__PURE__ */ jsx("div", { className: "sm-cookie-save-status", children: lastSavedTime ? `Last saved: today at ${lastSavedTime}` : "No custom preferences saved yet." }),
228
+ /* @__PURE__ */ jsxs("div", { className: "sm-cookie-save-buttons", children: [
229
+ /* @__PURE__ */ jsx(
230
+ "button",
231
+ {
232
+ type: "button",
233
+ className: "sm-cookie-btn sm-cookie-btn-secondary",
234
+ onClick: handleRejectAll,
235
+ children: "Reject Optional"
236
+ }
237
+ ),
238
+ /* @__PURE__ */ jsx(
239
+ "button",
240
+ {
241
+ type: "button",
242
+ className: "sm-cookie-btn sm-cookie-btn-secondary",
243
+ onClick: handleAcceptAll,
244
+ children: "Accept All"
245
+ }
246
+ ),
247
+ /* @__PURE__ */ jsx(
248
+ "button",
249
+ {
250
+ type: "button",
251
+ className: "sm-cookie-btn sm-cookie-btn-primary",
252
+ onClick: handleSave,
253
+ children: "Save Preferences"
254
+ }
255
+ )
256
+ ] })
257
+ ] })
258
+ ] });
259
+ }
260
+
261
+ export { CookieSettingsView };
@@ -0,0 +1,252 @@
1
+ // src/cookies.ts
2
+ var COOKIE_CONSENT_KEY = "sm_cookie_consent_v1";
3
+ var COOKIE_CONSENT_BACKUP_KEY = "napsite_cookie_consent_v1";
4
+ var COOKIE_CONSENT_EVENT = "scalemule-cookie-consent-change";
5
+ var COOKIE_CONSENT_MAX_AGE_SECONDS = 365 * 24 * 60 * 60;
6
+ var DEFAULT_PREFERENCES_REJECTED = {
7
+ essential: true,
8
+ performance: false,
9
+ functional: false,
10
+ advertising: false
11
+ };
12
+ var DEFAULT_PREFERENCES_ACCEPTED = {
13
+ essential: true,
14
+ performance: true,
15
+ functional: true,
16
+ advertising: true
17
+ };
18
+ var COOKIE_CATEGORIES = [
19
+ {
20
+ id: "essential",
21
+ title: "Strictly Necessary Cookies",
22
+ shortDescription: "Essential for site security, navigation, and privacy preference management.",
23
+ fullDescription: "These cookies are necessary for the website to function properly and securely. They enable core features such as load balancing, CSRF protection, secure session tokens, and remembering your cookie consent choice. Because the site cannot function without them, they cannot be turned off.",
24
+ required: true,
25
+ cookies: [
26
+ {
27
+ name: "sm_cookie_consent_v1",
28
+ provider: "First-Party (ScaleMule)",
29
+ purpose: "Stores your verified cookie privacy and category consent choices.",
30
+ duration: "1 year",
31
+ type: "HTTP Cookie"
32
+ },
33
+ {
34
+ name: "napsite_session_v1",
35
+ provider: "First-Party",
36
+ purpose: "Maintains session continuity, security tokens, and server routing.",
37
+ duration: "30 minutes (idle)",
38
+ type: "Session Storage"
39
+ },
40
+ {
41
+ name: "napsite_preview",
42
+ provider: "First-Party",
43
+ purpose: "Verifies preview access permissions when viewing unpublished newsroom editions.",
44
+ duration: "14 days",
45
+ type: "HTTP Cookie"
46
+ }
47
+ ]
48
+ },
49
+ {
50
+ id: "performance",
51
+ title: "Performance & Analytics Cookies",
52
+ shortDescription: "Help us measure reader engagement, story completion, and site reliability.",
53
+ fullDescription: "These cookies collect anonymous information about how visitors navigate our news publication. They allow us to count article reads, understand scroll depth and reading completion, and identify broken links or slow-loading assets so we can keep our community reporting responsive and fast. All metrics are aggregated and never contain personal information.",
54
+ required: false,
55
+ cookies: [
56
+ {
57
+ name: "napsite_visitor_v1",
58
+ provider: "First-Party",
59
+ purpose: "A randomized anonymous UUIDv7 to count distinct readers without tracking personal identity.",
60
+ duration: "1 year",
61
+ type: "Local Storage"
62
+ },
63
+ {
64
+ name: "napsite_analytics_v1",
65
+ provider: "First-Party",
66
+ purpose: "Connects reading completion and web vitals to the anonymous session.",
67
+ duration: "30 minutes",
68
+ type: "HTTP Cookie"
69
+ }
70
+ ]
71
+ },
72
+ {
73
+ id: "functional",
74
+ title: "Functional & Personalization Cookies",
75
+ shortDescription: "Remember your reading preferences, text size, and narration audio settings.",
76
+ fullDescription: "These cookies enable enhanced convenience features designed for readers. They remember your custom text sizing, keep your preferred audio narration playback speed (e.g., 1.0x vs 1.25x), and preserve your local town filters across the front page so you always see news closest to your neighborhood.",
77
+ required: false,
78
+ cookies: [
79
+ {
80
+ name: "reader_text_size",
81
+ provider: "First-Party",
82
+ purpose: "Remembers your preferred reading font size across articles.",
83
+ duration: "1 year",
84
+ type: "Local Storage"
85
+ },
86
+ {
87
+ name: "audio_narration_speed",
88
+ provider: "First-Party",
89
+ purpose: "Stores your preferred audio player playback rate (e.g. 1.0x, 1.25x).",
90
+ duration: "1 year",
91
+ type: "Local Storage"
92
+ }
93
+ ]
94
+ },
95
+ {
96
+ id: "advertising",
97
+ title: "Advertising & Local Sponsorship Cookies",
98
+ shortDescription: "Support local business sponsors by capping repetition and measuring notices.",
99
+ fullDescription: "Our journalism is supported by local business sponsors and community partners. These cookies ensure you do not see the same sponsor banner repeatedly (frequency capping) and help local merchants measure whether their announcement reached their community. They never track your activity across unrelated third-party websites or build external advertising profiles.",
100
+ required: false,
101
+ cookies: [
102
+ {
103
+ name: "napsite_sponsor_cap",
104
+ provider: "First-Party",
105
+ purpose: "Prevents repetitive display of identical local business announcements.",
106
+ duration: "7 days",
107
+ type: "Local Storage"
108
+ },
109
+ {
110
+ name: "local_sponsor_ref",
111
+ provider: "First-Party",
112
+ purpose: "Attributes community inquiries directly to the sponsoring local merchant.",
113
+ duration: "30 days",
114
+ type: "Local Storage"
115
+ }
116
+ ]
117
+ }
118
+ ];
119
+ var memoryConsent = null;
120
+ function readCookie(name) {
121
+ if (typeof document === "undefined") return null;
122
+ const match = document.cookie.match(new RegExp("(?:^|; )" + name.replace(/([.$?*|{}()[\]\\/+^])/g, "\\$1") + "=([^;]*)"));
123
+ return match ? decodeURIComponent(match[1]) : null;
124
+ }
125
+ function writeCookie(name, value, maxAgeSeconds) {
126
+ if (typeof document === "undefined") return;
127
+ const secure = typeof location !== "undefined" && location.protocol === "https:" ? "; Secure" : "";
128
+ document.cookie = `${name}=${encodeURIComponent(value)}; Path=/; Max-Age=${maxAgeSeconds}; SameSite=Lax${secure}`;
129
+ }
130
+ function getCookieConsent() {
131
+ if (typeof window === "undefined") return memoryConsent;
132
+ try {
133
+ const raw = readCookie(COOKIE_CONSENT_KEY) || readCookie(COOKIE_CONSENT_BACKUP_KEY);
134
+ if (raw) {
135
+ const parsed = JSON.parse(raw);
136
+ if (parsed && parsed.version === 1 && parsed.preferences) {
137
+ memoryConsent = parsed;
138
+ return parsed;
139
+ }
140
+ }
141
+ const stored = window.localStorage?.getItem(COOKIE_CONSENT_KEY);
142
+ if (stored) {
143
+ const parsed = JSON.parse(stored);
144
+ if (parsed && parsed.version === 1 && parsed.preferences) {
145
+ memoryConsent = parsed;
146
+ return parsed;
147
+ }
148
+ }
149
+ } catch {
150
+ }
151
+ return memoryConsent;
152
+ }
153
+ function hasConsented() {
154
+ return getCookieConsent() !== null;
155
+ }
156
+ function isCategoryAllowed(category) {
157
+ if (category === "essential") return true;
158
+ const consent = getCookieConsent();
159
+ if (!consent) {
160
+ if (typeof navigator !== "undefined") {
161
+ const nav = navigator;
162
+ if (nav.globalPrivacyControl || nav.doNotTrack === "1") {
163
+ return false;
164
+ }
165
+ }
166
+ return false;
167
+ }
168
+ return Boolean(consent.preferences[category]);
169
+ }
170
+ function setCookieConsent(preferences, source = "settings_save") {
171
+ const mergedPreferences = {
172
+ essential: true,
173
+ performance: Boolean(preferences.performance),
174
+ functional: Boolean(preferences.functional),
175
+ advertising: Boolean(preferences.advertising)
176
+ };
177
+ let anonymous_id;
178
+ if (typeof window !== "undefined") {
179
+ try {
180
+ anonymous_id = window.localStorage?.getItem("napsite_visitor_v1") || void 0;
181
+ } catch {
182
+ }
183
+ }
184
+ const record = {
185
+ version: 1,
186
+ preferences: mergedPreferences,
187
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
188
+ anonymous_id,
189
+ source
190
+ };
191
+ memoryConsent = record;
192
+ const serialized = JSON.stringify(record);
193
+ writeCookie(COOKIE_CONSENT_KEY, serialized, COOKIE_CONSENT_MAX_AGE_SECONDS);
194
+ writeCookie(COOKIE_CONSENT_BACKUP_KEY, serialized, COOKIE_CONSENT_MAX_AGE_SECONDS);
195
+ if (typeof window !== "undefined") {
196
+ try {
197
+ window.localStorage?.setItem(COOKIE_CONSENT_KEY, serialized);
198
+ } catch {
199
+ }
200
+ window.dispatchEvent(new CustomEvent(COOKIE_CONSENT_EVENT, { detail: record }));
201
+ }
202
+ return record;
203
+ }
204
+ function acceptAllCookies() {
205
+ return setCookieConsent(DEFAULT_PREFERENCES_ACCEPTED, "banner_accept");
206
+ }
207
+ function rejectOptionalCookies() {
208
+ return setCookieConsent(DEFAULT_PREFERENCES_REJECTED, "banner_reject");
209
+ }
210
+ function clearCookieConsent() {
211
+ memoryConsent = null;
212
+ if (typeof document !== "undefined") {
213
+ document.cookie = `${COOKIE_CONSENT_KEY}=; Path=/; Max-Age=0; SameSite=Lax`;
214
+ document.cookie = `${COOKIE_CONSENT_BACKUP_KEY}=; Path=/; Max-Age=0; SameSite=Lax`;
215
+ }
216
+ if (typeof window !== "undefined") {
217
+ try {
218
+ window.localStorage?.removeItem(COOKIE_CONSENT_KEY);
219
+ } catch {
220
+ }
221
+ window.dispatchEvent(new CustomEvent(COOKIE_CONSENT_EVENT, { detail: null }));
222
+ }
223
+ }
224
+ async function recordConsentToCompliance(record, options) {
225
+ if (typeof window === "undefined") return;
226
+ const endpoint = options?.endpoint || "/api/compliance/consent";
227
+ try {
228
+ const payload = {
229
+ consent_type: "cookie_policy",
230
+ granted: record.preferences.performance || record.preferences.advertising,
231
+ preferences: record.preferences,
232
+ source: record.source,
233
+ anonymous_id: record.anonymous_id,
234
+ timestamp: record.timestamp,
235
+ url: window.location.href,
236
+ user_agent: window.navigator.userAgent
237
+ };
238
+ if (typeof navigator.sendBeacon === "function") {
239
+ navigator.sendBeacon(endpoint, new Blob([JSON.stringify(payload)], { type: "application/json" }));
240
+ } else {
241
+ await fetch(endpoint, {
242
+ method: "POST",
243
+ headers: { "content-type": "application/json" },
244
+ body: JSON.stringify(payload),
245
+ keepalive: true
246
+ });
247
+ }
248
+ } catch {
249
+ }
250
+ }
251
+
252
+ export { COOKIE_CATEGORIES, COOKIE_CONSENT_BACKUP_KEY, COOKIE_CONSENT_EVENT, COOKIE_CONSENT_KEY, COOKIE_CONSENT_MAX_AGE_SECONDS, DEFAULT_PREFERENCES_ACCEPTED, DEFAULT_PREFERENCES_REJECTED, acceptAllCookies, clearCookieConsent, getCookieConsent, hasConsented, isCategoryAllowed, recordConsentToCompliance, rejectOptionalCookies, setCookieConsent };