@oxvo/ai-live-assist 7.5.20 → 7.5.22

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 (101) hide show
  1. package/cjs/AiLiveAssist.d.ts +8 -1
  2. package/cjs/AiLiveAssist.js +113 -8
  3. package/cjs/client.d.ts +5 -3
  4. package/cjs/client.js +44 -5
  5. package/cjs/commerce/cartContracts.d.ts +158 -0
  6. package/cjs/commerce/cartContracts.js +228 -0
  7. package/cjs/commerce/cartSession.d.ts +86 -0
  8. package/cjs/commerce/cartSession.js +475 -0
  9. package/cjs/commerce/contracts.d.ts +152 -0
  10. package/cjs/commerce/contracts.js +322 -0
  11. package/cjs/commerce/pageContext.d.ts +50 -0
  12. package/cjs/commerce/pageContext.js +173 -0
  13. package/cjs/commerce/productPanel.d.ts +65 -0
  14. package/cjs/commerce/productPanel.js +662 -0
  15. package/cjs/commerce/realtimeCommerce.d.ts +73 -0
  16. package/cjs/commerce/realtimeCommerce.js +345 -0
  17. package/cjs/commerce/shopifyCart.d.ts +130 -0
  18. package/cjs/commerce/shopifyCart.js +1135 -0
  19. package/cjs/commerce/shopifyCartPresentation.d.ts +12 -0
  20. package/cjs/commerce/shopifyCartPresentation.js +379 -0
  21. package/cjs/commerce/shoppingNotes.d.ts +61 -0
  22. package/cjs/commerce/shoppingNotes.js +313 -0
  23. package/cjs/commerce/shoppingNotesView.d.ts +46 -0
  24. package/cjs/commerce/shoppingNotesView.js +269 -0
  25. package/cjs/context.js +17 -5
  26. package/cjs/control.d.ts +9 -1
  27. package/cjs/control.js +51 -1
  28. package/cjs/guideAdmission.d.ts +6 -2
  29. package/cjs/guideAdmission.js +39 -2
  30. package/cjs/guideInstaller.js +1 -1
  31. package/cjs/guideMeasurement.d.ts +7 -0
  32. package/cjs/guideMeasurement.js +59 -0
  33. package/cjs/guideSubjectStore.js +2 -0
  34. package/cjs/guideTypes.d.ts +19 -0
  35. package/cjs/liveControlChannel.d.ts +43 -1
  36. package/cjs/liveControlChannel.js +166 -14
  37. package/cjs/liveGuideAdmission.d.ts +3 -2
  38. package/cjs/liveGuideAdmission.js +14 -2
  39. package/cjs/liveGuideWidget.d.ts +18 -0
  40. package/cjs/liveGuideWidget.js +228 -23
  41. package/cjs/locales/resources.js +2240 -0
  42. package/cjs/messages.js +56 -0
  43. package/cjs/tabLock.d.ts +2 -0
  44. package/cjs/tabLock.js +11 -1
  45. package/cjs/types.d.ts +6 -2
  46. package/cjs/types.js +56 -0
  47. package/cjs/ui.d.ts +37 -0
  48. package/cjs/ui.js +259 -9
  49. package/cjs/version.d.ts +1 -1
  50. package/cjs/version.js +1 -1
  51. package/lib/AiLiveAssist.d.ts +8 -1
  52. package/lib/AiLiveAssist.js +113 -8
  53. package/lib/client.d.ts +5 -3
  54. package/lib/client.js +44 -5
  55. package/lib/commerce/cartContracts.d.ts +158 -0
  56. package/lib/commerce/cartContracts.js +221 -0
  57. package/lib/commerce/cartSession.d.ts +86 -0
  58. package/lib/commerce/cartSession.js +471 -0
  59. package/lib/commerce/contracts.d.ts +152 -0
  60. package/lib/commerce/contracts.js +300 -0
  61. package/lib/commerce/pageContext.d.ts +50 -0
  62. package/lib/commerce/pageContext.js +168 -0
  63. package/lib/commerce/productPanel.d.ts +65 -0
  64. package/lib/commerce/productPanel.js +657 -0
  65. package/lib/commerce/realtimeCommerce.d.ts +73 -0
  66. package/lib/commerce/realtimeCommerce.js +340 -0
  67. package/lib/commerce/shopifyCart.d.ts +130 -0
  68. package/lib/commerce/shopifyCart.js +1130 -0
  69. package/lib/commerce/shopifyCartPresentation.d.ts +12 -0
  70. package/lib/commerce/shopifyCartPresentation.js +376 -0
  71. package/lib/commerce/shoppingNotes.d.ts +61 -0
  72. package/lib/commerce/shoppingNotes.js +307 -0
  73. package/lib/commerce/shoppingNotesView.d.ts +46 -0
  74. package/lib/commerce/shoppingNotesView.js +265 -0
  75. package/lib/context.js +17 -5
  76. package/lib/control.d.ts +9 -1
  77. package/lib/control.js +51 -1
  78. package/lib/guideAdmission.d.ts +6 -2
  79. package/lib/guideAdmission.js +39 -2
  80. package/lib/guideInstaller.js +1 -1
  81. package/lib/guideMeasurement.d.ts +7 -0
  82. package/lib/guideMeasurement.js +53 -0
  83. package/lib/guideSubjectStore.js +2 -0
  84. package/lib/guideTypes.d.ts +19 -0
  85. package/lib/liveControlChannel.d.ts +43 -1
  86. package/lib/liveControlChannel.js +166 -14
  87. package/lib/liveGuideAdmission.d.ts +3 -2
  88. package/lib/liveGuideAdmission.js +14 -2
  89. package/lib/liveGuideWidget.d.ts +18 -0
  90. package/lib/liveGuideWidget.js +228 -23
  91. package/lib/locales/resources.js +2240 -0
  92. package/lib/messages.js +56 -0
  93. package/lib/tabLock.d.ts +2 -0
  94. package/lib/tabLock.js +11 -1
  95. package/lib/types.d.ts +6 -2
  96. package/lib/types.js +56 -0
  97. package/lib/ui.d.ts +37 -0
  98. package/lib/ui.js +259 -9
  99. package/lib/version.d.ts +1 -1
  100. package/lib/version.js +1 -1
  101. package/package.json +1 -1
@@ -0,0 +1,313 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ShoppingNotesStore = exports.SHOPPING_NOTES_QUESTION_MAX_LENGTH = exports.SHOPPING_NOTES_TTL_MS = exports.SHOPPING_NOTES_MAX_BYTES = exports.SHOPPING_NOTES_STORAGE_KEY = void 0;
4
+ exports.createShoppingNotesScope = createShoppingNotesScope;
5
+ exports.buildShoppingNotesQuestion = buildShoppingNotesQuestion;
6
+ const guideTypes_js_1 = require("../guideTypes.js");
7
+ const contracts_js_1 = require("./contracts.js");
8
+ exports.SHOPPING_NOTES_STORAGE_KEY = "__oxvo_guide_shopping_notes_v1";
9
+ exports.SHOPPING_NOTES_MAX_BYTES = 4096;
10
+ exports.SHOPPING_NOTES_TTL_MS = 30 * 60 * 1000;
11
+ exports.SHOPPING_NOTES_QUESTION_MAX_LENGTH = 4000;
12
+ const scopeKeys = [
13
+ "origin",
14
+ "installKey",
15
+ "projectId",
16
+ "guideId",
17
+ "store",
18
+ ];
19
+ const storeKeys = ["provider", "storeRef", "origin", "policyRevision"];
20
+ const recordKeys = [
21
+ "schemaVersion",
22
+ "scope",
23
+ "savedAt",
24
+ "expiresAt",
25
+ "draft",
26
+ ];
27
+ const owns = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
28
+ /** Do not invoke accessors/toJSON on inputs from a page or UI callback. */
29
+ function fields(value, required, optional = []) {
30
+ if (!value ||
31
+ typeof value !== "object" ||
32
+ Array.isArray(value) ||
33
+ (Object.getPrototypeOf(value) !== Object.prototype &&
34
+ Object.getPrototypeOf(value) !== null))
35
+ return false;
36
+ const keys = Reflect.ownKeys(value);
37
+ return (required.every((key) => owns(value, key)) &&
38
+ keys.every((key) => {
39
+ if (typeof key !== "string" ||
40
+ (!required.includes(key) && !optional.includes(key)))
41
+ return false;
42
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
43
+ return !!descriptor?.enumerable && "value" in descriptor;
44
+ }));
45
+ }
46
+ function plainArray(value, maximum) {
47
+ if (!Array.isArray(value) ||
48
+ value.length > maximum ||
49
+ Reflect.ownKeys(value).length !== value.length + 1)
50
+ return false;
51
+ return Array.from({ length: value.length }, (_, index) => Object.getOwnPropertyDescriptor(value, String(index))).every((descriptor) => !!descriptor?.enumerable && "value" in descriptor);
52
+ }
53
+ function validScope(value) {
54
+ return (fields(value, scopeKeys) &&
55
+ typeof value.origin === "string" &&
56
+ typeof value.installKey === "string" &&
57
+ guideTypes_js_1.GUIDE_INSTALL_KEY_PATTERN.test(value.installKey) &&
58
+ Number.isSafeInteger(value.projectId) &&
59
+ Number(value.projectId) > 0 &&
60
+ (0, contracts_js_1.commerceUuid)(value.guideId) &&
61
+ fields(value.store, storeKeys) &&
62
+ (0, contracts_js_1.isCommerceStore)(value.store) &&
63
+ value.store.origin === value.origin);
64
+ }
65
+ const sameScope = (left, right) => left.origin === right.origin &&
66
+ left.installKey === right.installKey &&
67
+ left.projectId === right.projectId &&
68
+ left.guideId === right.guideId &&
69
+ (0, contracts_js_1.sameCommerceStore)(left.store, right.store);
70
+ const copyScope = (scope) => ({
71
+ origin: scope.origin,
72
+ installKey: scope.installKey,
73
+ projectId: scope.projectId,
74
+ guideId: scope.guideId,
75
+ store: {
76
+ provider: scope.store.provider,
77
+ storeRef: scope.store.storeRef,
78
+ origin: scope.store.origin,
79
+ policyRevision: scope.store.policyRevision,
80
+ },
81
+ });
82
+ function ownData(value, key) {
83
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
84
+ return descriptor && "value" in descriptor ? descriptor.value : undefined;
85
+ }
86
+ /** Only validated current bootstrap identity supplies the scope; notes never supply it. */
87
+ function createShoppingNotesScope(config, origin = location.origin) {
88
+ try {
89
+ if (!config ||
90
+ typeof config !== "object" ||
91
+ ownData(config, "schemaVersion") !== 3)
92
+ return null;
93
+ const commerce = ownData(config, "commerce");
94
+ if (!fields(commerce, [
95
+ "schemaVersion",
96
+ "enabled",
97
+ "guideId",
98
+ "store",
99
+ "cartEnabled",
100
+ ]) ||
101
+ !fields(commerce.store, storeKeys))
102
+ return null;
103
+ const scope = {
104
+ origin,
105
+ installKey: ownData(config, "installKey"),
106
+ projectId: ownData(config, "projectId"),
107
+ guideId: ownData(config, "guideId"),
108
+ store: commerce.store,
109
+ };
110
+ if (!validScope(scope) ||
111
+ !(0, contracts_js_1.parseCommerceBootstrap)(commerce, scope.guideId, origin))
112
+ return null;
113
+ return copyScope(scope);
114
+ }
115
+ catch {
116
+ return null;
117
+ }
118
+ }
119
+ const controls = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/u;
120
+ function reference(value, kind) {
121
+ if (typeof value !== "string")
122
+ return false;
123
+ const match = new RegExp(`^gid://shopify/${kind}/([1-9]\\d{0,19})$`, "u").exec(value);
124
+ return !!match?.[1] && BigInt(match[1]) <= 18446744073709551615n;
125
+ }
126
+ function validDraft(value) {
127
+ return (fields(value, ["needs", "products"]) &&
128
+ typeof value.needs === "string" &&
129
+ value.needs.length <= exports.SHOPPING_NOTES_QUESTION_MAX_LENGTH &&
130
+ !controls.test(value.needs) &&
131
+ plainArray(value.products, 3) &&
132
+ value.products.every((product) => fields(product, ["productRef", "variantRef", "selectedOptions"], ["label"]) &&
133
+ reference(product.productRef, "Product") &&
134
+ (product.variantRef === null ||
135
+ reference(product.variantRef, "ProductVariant")) &&
136
+ plainArray(product.selectedOptions, 3) &&
137
+ product.selectedOptions.every((option) => fields(option, ["name", "value"])) &&
138
+ (0, contracts_js_1.isCommerceOptions)(product.selectedOptions) &&
139
+ (!owns(product, "label") ||
140
+ (typeof product.label === "string" &&
141
+ product.label.length > 0 &&
142
+ product.label.length <= 120 &&
143
+ product.label === product.label.trim() &&
144
+ !/[\u0000-\u001f\u007f]/u.test(product.label)))) &&
145
+ new Set(value.products.map((product) => `${product.productRef}\n${product.variantRef ?? ""}`)).size === value.products.length);
146
+ }
147
+ const empty = (draft) => !draft.needs.trim() && draft.products.length === 0;
148
+ function copyDraft(draft) {
149
+ return {
150
+ needs: draft.needs,
151
+ products: draft.products.map((product) => ({
152
+ productRef: product.productRef,
153
+ variantRef: product.variantRef,
154
+ selectedOptions: product.selectedOptions.map(({ name, value }) => ({
155
+ name,
156
+ value,
157
+ })),
158
+ ...(product.label === undefined ? {} : { label: product.label }),
159
+ })),
160
+ };
161
+ }
162
+ /** Builds the entire text for shopper review. No truncation, launch, text send or permission restoration. */
163
+ function buildShoppingNotesQuestion(reviewedDraft) {
164
+ try {
165
+ if (fields(reviewedDraft, ["needs", "products"]) &&
166
+ typeof reviewedDraft.needs === "string" &&
167
+ reviewedDraft.needs.length > exports.SHOPPING_NOTES_QUESTION_MAX_LENGTH)
168
+ return { ok: false, reason: "too_long" };
169
+ if (!validDraft(reviewedDraft))
170
+ return { ok: false, reason: "invalid" };
171
+ if (empty(reviewedDraft))
172
+ return { ok: false, reason: "empty" };
173
+ const products = reviewedDraft.products.map((product) => [
174
+ ...(product.label ? [product.label] : []),
175
+ product.productRef,
176
+ ...(product.variantRef ? [product.variantRef] : []),
177
+ ...product.selectedOptions.map((option) => `${option.name}: ${option.value}`),
178
+ ].join("\n"));
179
+ const initialQuestion = [
180
+ ...(reviewedDraft.needs ? [reviewedDraft.needs] : []),
181
+ ...products,
182
+ ].join("\n\n");
183
+ return initialQuestion.length <= exports.SHOPPING_NOTES_QUESTION_MAX_LENGTH
184
+ ? { ok: true, initialQuestion }
185
+ : { ok: false, reason: "too_long" };
186
+ }
187
+ catch {
188
+ return { ok: false, reason: "invalid" };
189
+ }
190
+ }
191
+ const bytes = (value) => new TextEncoder().encode(value).byteLength;
192
+ function validRecord(value, now) {
193
+ return (fields(value, recordKeys) &&
194
+ value.schemaVersion === 1 &&
195
+ validScope(value.scope) &&
196
+ validDraft(value.draft) &&
197
+ !empty(value.draft) &&
198
+ Number.isSafeInteger(value.savedAt) &&
199
+ Number(value.savedAt) >= 0 &&
200
+ Number(value.savedAt) <= now &&
201
+ Number.isSafeInteger(value.expiresAt) &&
202
+ value.expiresAt === Number(value.savedAt) + exports.SHOPPING_NOTES_TTL_MS &&
203
+ Number(value.expiresAt) > now);
204
+ }
205
+ /** Optional per-tab convenience. Constructing or reading this cannot start any Guide or restore authority. */
206
+ class ShoppingNotesStore {
207
+ constructor(scope) {
208
+ try {
209
+ this.scope = validScope(scope) ? copyScope(scope) : null;
210
+ }
211
+ catch {
212
+ this.scope = null;
213
+ }
214
+ }
215
+ currentScope() {
216
+ return this.scope?.origin === location.origin ? this.scope : null;
217
+ }
218
+ read() {
219
+ try {
220
+ const scope = this.currentScope();
221
+ if (!scope)
222
+ return null;
223
+ const raw = sessionStorage.getItem(exports.SHOPPING_NOTES_STORAGE_KEY);
224
+ if (raw === null || raw.length > exports.SHOPPING_NOTES_MAX_BYTES)
225
+ return null;
226
+ let value;
227
+ try {
228
+ value = JSON.parse(raw);
229
+ }
230
+ catch {
231
+ return null;
232
+ }
233
+ // Another Guide's valid notes are not ours to remove. Unscopable records are ignored.
234
+ if (!value ||
235
+ typeof value !== "object" ||
236
+ !validScope(value.scope) ||
237
+ !sameScope(value.scope, scope))
238
+ return null;
239
+ if (bytes(raw) > exports.SHOPPING_NOTES_MAX_BYTES ||
240
+ !validRecord(value, Date.now())) {
241
+ sessionStorage.removeItem(exports.SHOPPING_NOTES_STORAGE_KEY);
242
+ return null;
243
+ }
244
+ return {
245
+ schemaVersion: 1,
246
+ scope: copyScope(value.scope),
247
+ savedAt: value.savedAt,
248
+ expiresAt: value.expiresAt,
249
+ draft: copyDraft(value.draft),
250
+ };
251
+ }
252
+ catch {
253
+ return null;
254
+ }
255
+ }
256
+ /** Called only by the explicit shopper Save control. Saving starts one new fixed expiry interval. */
257
+ save(draft) {
258
+ try {
259
+ const scope = this.currentScope();
260
+ if (!scope || !validDraft(draft))
261
+ return { ok: false, reason: "invalid" };
262
+ if (empty(draft))
263
+ return { ok: false, reason: "empty" };
264
+ const savedAt = Date.now();
265
+ const record = {
266
+ schemaVersion: 1,
267
+ scope: copyScope(scope),
268
+ savedAt,
269
+ expiresAt: savedAt + exports.SHOPPING_NOTES_TTL_MS,
270
+ draft: copyDraft(draft),
271
+ };
272
+ const raw = JSON.stringify(record);
273
+ if (bytes(raw) > exports.SHOPPING_NOTES_MAX_BYTES)
274
+ return { ok: false, reason: "too_large" };
275
+ sessionStorage.setItem(exports.SHOPPING_NOTES_STORAGE_KEY, raw);
276
+ if (sessionStorage.getItem(exports.SHOPPING_NOTES_STORAGE_KEY) !== raw)
277
+ return { ok: false, reason: "storage_unavailable" };
278
+ return { ok: true, record };
279
+ }
280
+ catch {
281
+ return { ok: false, reason: "storage_unavailable" };
282
+ }
283
+ }
284
+ /** Only our own scoped notes are removed; launch and unresolved-cart stores are never accessed. */
285
+ clear() {
286
+ try {
287
+ const scope = this.currentScope();
288
+ if (!scope)
289
+ return false;
290
+ const raw = sessionStorage.getItem(exports.SHOPPING_NOTES_STORAGE_KEY);
291
+ if (raw === null || raw.length > exports.SHOPPING_NOTES_MAX_BYTES)
292
+ return true;
293
+ let value;
294
+ try {
295
+ value = JSON.parse(raw);
296
+ }
297
+ catch {
298
+ return true;
299
+ }
300
+ if (!value ||
301
+ typeof value !== "object" ||
302
+ !validScope(value.scope) ||
303
+ !sameScope(value.scope, scope))
304
+ return true;
305
+ sessionStorage.removeItem(exports.SHOPPING_NOTES_STORAGE_KEY);
306
+ return sessionStorage.getItem(exports.SHOPPING_NOTES_STORAGE_KEY) === null;
307
+ }
308
+ catch {
309
+ return false;
310
+ }
311
+ }
312
+ }
313
+ exports.ShoppingNotesStore = ShoppingNotesStore;
@@ -0,0 +1,46 @@
1
+ import type { WidgetMessageKey } from "../types.js";
2
+ import type { DialogFocusScope } from "../dialogFocusScope.js";
3
+ import { type ShoppingNotesProduct, type ShoppingNotesScope } from "./shoppingNotes.js";
4
+ export declare const SHOPPING_NOTES_STYLES = "\n .shopping-notes-entry, .shopping-notes-dialog button { min-height: 44px; padding: 8px 12px; border: 1px solid var(--assist-border, var(--voice-border)); border-radius: 10px; color: var(--assist-text, var(--voice-text)); background: var(--assist-surface, var(--voice-surface)); font: inherit; cursor: pointer; pointer-events: auto; }\n .shopping-notes-entry { align-self: flex-end; margin-block-end: 8px; max-width: 100%; font: 400 13px/1.4 system-ui, sans-serif; }\n .shopping-notes-dialog { position: fixed; inset: auto max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) auto; z-index: 20; box-sizing: border-box; width: min(420px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto; overscroll-behavior: contain; padding: 16px; border: 1px solid var(--assist-border, var(--voice-border)); border-radius: 16px; color: var(--assist-text, var(--voice-text)); background: var(--assist-surface, var(--voice-surface)); box-shadow: 0 8px 32px #0003; pointer-events: auto; font: 400 14px/1.45 system-ui, sans-serif; }\n .shopping-notes-dialog *, .shopping-notes-dialog *::before, .shopping-notes-dialog *::after { box-sizing: border-box; }\n .shopping-notes-dialog[hidden], .shopping-notes-dialog [hidden], .shopping-notes-entry[hidden] { display: none !important; }\n .shopping-notes-dialog h2 { margin: 0; font-size: 18px; }\n .shopping-notes-dialog p { margin-block: 10px; }\n .shopping-notes-dialog label { display: grid; gap: 6px; }\n .shopping-notes-dialog textarea { min-height: 100px; width: 100%; min-width: 0; padding: 10px; resize: vertical; border: 1px solid var(--assist-border, var(--voice-border)); border-radius: 8px; color: inherit; background: var(--assist-surface-muted, var(--voice-surface)); font: inherit; }\n .shopping-notes-products { display: grid; gap: 8px; padding: 0; list-style: none; }\n .shopping-notes-products li { display: grid; gap: 4px; padding: 8px; border: 1px solid var(--assist-border, var(--voice-border)); border-radius: 8px; overflow-wrap: anywhere; }\n .shopping-notes-products small { color: var(--assist-muted, var(--voice-muted)); }\n .shopping-notes-actions { display: flex; flex-wrap: wrap; gap: 8px; }\n .shopping-notes-actions button { flex: 1 1 120px; }\n .shopping-notes-dialog button { white-space: normal; overflow-wrap: anywhere; }\n .shopping-notes-dialog button:disabled { opacity: .55; cursor: default; }\n .shopping-notes-dialog :is(button, textarea):focus-visible, .shopping-notes-entry:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }\n";
5
+ /** Explicit local editor. It never receives transcript, prices, or cart state. */
6
+ export declare class ShoppingNotesView {
7
+ readonly scope: ShoppingNotesScope;
8
+ private readonly message;
9
+ private readonly focus;
10
+ private readonly callbacks;
11
+ readonly element: HTMLElement;
12
+ private readonly needs;
13
+ private readonly products;
14
+ private readonly status;
15
+ private readonly startButton;
16
+ private readonly store;
17
+ private draft;
18
+ private expiresAt;
19
+ private destroyed;
20
+ private submitted;
21
+ private submittedQuestion;
22
+ private submittedCaption;
23
+ private failedLaunchDraft;
24
+ constructor(scope: ShoppingNotesScope, message: (key: WidgetMessageKey) => string, focus: DialogFocusScope, callbacks: {
25
+ active: () => boolean;
26
+ start: (question: string) => boolean;
27
+ changed: () => void;
28
+ fallbackFocus: () => HTMLElement | null;
29
+ });
30
+ hasSaved(): boolean;
31
+ markLaunchFailed(): void;
32
+ prepareLaunch(question?: string): void;
33
+ /** Internal retrieval references remain in the submitted text, not its UI echo. */
34
+ captionText(question: string): string;
35
+ open(product?: ShoppingNotesProduct): void;
36
+ /** Recover only our exact admitted draft after a failed asynchronous launch. */
37
+ retry(question: string, message: string): boolean;
38
+ private present;
39
+ close(restore?: boolean): void;
40
+ destroy(): void;
41
+ private save;
42
+ private clear;
43
+ private start;
44
+ private renderProducts;
45
+ private button;
46
+ }
@@ -0,0 +1,269 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ShoppingNotesView = exports.SHOPPING_NOTES_STYLES = void 0;
4
+ const shoppingNotes_js_1 = require("./shoppingNotes.js");
5
+ exports.SHOPPING_NOTES_STYLES = `
6
+ .shopping-notes-entry, .shopping-notes-dialog button { min-height: 44px; padding: 8px 12px; border: 1px solid var(--assist-border, var(--voice-border)); border-radius: 10px; color: var(--assist-text, var(--voice-text)); background: var(--assist-surface, var(--voice-surface)); font: inherit; cursor: pointer; pointer-events: auto; }
7
+ .shopping-notes-entry { align-self: flex-end; margin-block-end: 8px; max-width: 100%; font: 400 13px/1.4 system-ui, sans-serif; }
8
+ .shopping-notes-dialog { position: fixed; inset: auto max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) auto; z-index: 20; box-sizing: border-box; width: min(420px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto; overscroll-behavior: contain; padding: 16px; border: 1px solid var(--assist-border, var(--voice-border)); border-radius: 16px; color: var(--assist-text, var(--voice-text)); background: var(--assist-surface, var(--voice-surface)); box-shadow: 0 8px 32px #0003; pointer-events: auto; font: 400 14px/1.45 system-ui, sans-serif; }
9
+ .shopping-notes-dialog *, .shopping-notes-dialog *::before, .shopping-notes-dialog *::after { box-sizing: border-box; }
10
+ .shopping-notes-dialog[hidden], .shopping-notes-dialog [hidden], .shopping-notes-entry[hidden] { display: none !important; }
11
+ .shopping-notes-dialog h2 { margin: 0; font-size: 18px; }
12
+ .shopping-notes-dialog p { margin-block: 10px; }
13
+ .shopping-notes-dialog label { display: grid; gap: 6px; }
14
+ .shopping-notes-dialog textarea { min-height: 100px; width: 100%; min-width: 0; padding: 10px; resize: vertical; border: 1px solid var(--assist-border, var(--voice-border)); border-radius: 8px; color: inherit; background: var(--assist-surface-muted, var(--voice-surface)); font: inherit; }
15
+ .shopping-notes-products { display: grid; gap: 8px; padding: 0; list-style: none; }
16
+ .shopping-notes-products li { display: grid; gap: 4px; padding: 8px; border: 1px solid var(--assist-border, var(--voice-border)); border-radius: 8px; overflow-wrap: anywhere; }
17
+ .shopping-notes-products small { color: var(--assist-muted, var(--voice-muted)); }
18
+ .shopping-notes-actions { display: flex; flex-wrap: wrap; gap: 8px; }
19
+ .shopping-notes-actions button { flex: 1 1 120px; }
20
+ .shopping-notes-dialog button { white-space: normal; overflow-wrap: anywhere; }
21
+ .shopping-notes-dialog button:disabled { opacity: .55; cursor: default; }
22
+ .shopping-notes-dialog :is(button, textarea):focus-visible, .shopping-notes-entry:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
23
+ `;
24
+ /** Explicit local editor. It never receives transcript, prices, or cart state. */
25
+ class ShoppingNotesView {
26
+ constructor(scope, message, focus, callbacks) {
27
+ this.scope = scope;
28
+ this.message = message;
29
+ this.focus = focus;
30
+ this.callbacks = callbacks;
31
+ this.element = document.createElement("section");
32
+ this.needs = document.createElement("textarea");
33
+ this.products = document.createElement("ul");
34
+ this.status = document.createElement("p");
35
+ this.draft = { needs: "", products: [] };
36
+ this.expiresAt = null;
37
+ this.destroyed = false;
38
+ this.submitted = false;
39
+ this.submittedQuestion = null;
40
+ this.submittedCaption = null;
41
+ this.failedLaunchDraft = false;
42
+ this.store = new shoppingNotes_js_1.ShoppingNotesStore(scope);
43
+ this.element.className = "shopping-notes-dialog";
44
+ this.element.hidden = true;
45
+ this.element.setAttribute("role", "dialog");
46
+ this.element.setAttribute("aria-modal", "true");
47
+ this.element.setAttribute("aria-label", message("shoppingNotesTitle"));
48
+ const title = document.createElement("h2");
49
+ title.textContent = message("shoppingNotesTitle");
50
+ const description = document.createElement("p");
51
+ description.textContent = message("shoppingNotesDescription");
52
+ const label = document.createElement("label");
53
+ label.textContent = message("shoppingNotesNeeds");
54
+ this.needs.dataset.role = "shopping-notes-needs";
55
+ this.needs.addEventListener("input", () => {
56
+ this.draft.needs = this.needs.value;
57
+ this.status.textContent = "";
58
+ });
59
+ label.append(this.needs);
60
+ this.products.className = "shopping-notes-products";
61
+ this.status.setAttribute("role", "status");
62
+ this.status.setAttribute("aria-live", "polite");
63
+ this.status.dataset.role = "shopping-notes-status";
64
+ const actions = document.createElement("div");
65
+ actions.className = "shopping-notes-actions";
66
+ this.startButton = this.button("shoppingNotesStart", () => this.start());
67
+ actions.append(this.button("shoppingNotesSave", () => this.save()), this.button("shoppingNotesClear", () => this.clear()), this.startButton, this.button("close", () => this.close()));
68
+ this.element.append(title, description, label, this.products, this.status, actions);
69
+ }
70
+ hasSaved() {
71
+ return this.failedLaunchDraft || this.store.read() !== null;
72
+ }
73
+ markLaunchFailed() {
74
+ if (this.submittedQuestion !== null)
75
+ this.failedLaunchDraft = true;
76
+ }
77
+ prepareLaunch(question) {
78
+ if (question !== this.submittedQuestion) {
79
+ this.submittedQuestion = null;
80
+ this.submittedCaption = null;
81
+ }
82
+ }
83
+ /** Internal retrieval references remain in the submitted text, not its UI echo. */
84
+ captionText(question) {
85
+ return this.submittedCaption?.question === question ? this.submittedCaption.text : question;
86
+ }
87
+ open(product) {
88
+ if (this.destroyed)
89
+ return;
90
+ if (!this.failedLaunchDraft) {
91
+ const saved = this.store.read();
92
+ this.draft = saved?.draft ?? { needs: "", products: [] };
93
+ this.expiresAt = saved?.expiresAt ?? null;
94
+ }
95
+ this.submitted = false;
96
+ this.submittedQuestion = null;
97
+ this.status.textContent = this.failedLaunchDraft
98
+ ? this.message("shoppingNotesStartFailed")
99
+ : "";
100
+ if (product) {
101
+ const index = this.draft.products.findIndex((value) => value.productRef === product.productRef &&
102
+ value.variantRef === product.variantRef);
103
+ if (index >= 0)
104
+ this.draft.products[index] = product;
105
+ else if (this.draft.products.length < 3)
106
+ this.draft.products.push(product);
107
+ else
108
+ this.status.textContent = this.message("shoppingNotesTooMany");
109
+ }
110
+ this.needs.value = this.draft.needs;
111
+ this.renderProducts();
112
+ this.present();
113
+ }
114
+ /** Recover only our exact admitted draft after a failed asynchronous launch. */
115
+ retry(question, message) {
116
+ if (this.destroyed || question !== this.submittedQuestion)
117
+ return false;
118
+ this.failedLaunchDraft = true;
119
+ this.submitted = false;
120
+ this.needs.value = this.draft.needs;
121
+ this.renderProducts();
122
+ this.status.textContent = message;
123
+ this.present();
124
+ return true;
125
+ }
126
+ present() {
127
+ this.startButton.hidden = this.callbacks.active();
128
+ this.startButton.disabled = false;
129
+ this.element.hidden = false;
130
+ this.focus.present({
131
+ surface: this.element,
132
+ initialFocus: () => this.needs,
133
+ fallbackFocus: this.callbacks.fallbackFocus,
134
+ onEscape: () => this.close(),
135
+ });
136
+ }
137
+ close(restore = true) {
138
+ if (this.element.hidden)
139
+ return;
140
+ this.element.hidden = true;
141
+ this.focus.dismiss(this.element, { restore });
142
+ }
143
+ destroy() {
144
+ this.close(false);
145
+ this.destroyed = true;
146
+ this.element.remove();
147
+ }
148
+ save() {
149
+ if (this.destroyed || this.element.hidden)
150
+ return;
151
+ this.draft.needs = this.needs.value;
152
+ if (this.draft.needs.length > shoppingNotes_js_1.SHOPPING_NOTES_QUESTION_MAX_LENGTH) {
153
+ this.status.textContent = this.message("shoppingNotesTooLarge");
154
+ return;
155
+ }
156
+ const result = this.store.save(this.draft);
157
+ if (!result.ok) {
158
+ this.status.textContent = this.message(result.reason === "storage_unavailable"
159
+ ? "shoppingNotesStorageError"
160
+ : result.reason === "too_large"
161
+ ? "shoppingNotesTooLarge"
162
+ : result.reason === "empty"
163
+ ? "shoppingNotesEmpty"
164
+ : "shoppingNotesInvalid");
165
+ return;
166
+ }
167
+ this.draft = result.record.draft;
168
+ this.expiresAt = result.record.expiresAt;
169
+ this.failedLaunchDraft = false;
170
+ this.status.textContent = this.message("shoppingNotesSaved");
171
+ this.callbacks.changed();
172
+ }
173
+ clear() {
174
+ if (this.destroyed || this.element.hidden)
175
+ return;
176
+ if (!this.store.clear()) {
177
+ this.status.textContent = this.message("shoppingNotesStorageError");
178
+ return;
179
+ }
180
+ this.draft = { needs: "", products: [] };
181
+ this.expiresAt = null;
182
+ this.failedLaunchDraft = false;
183
+ this.submittedQuestion = null;
184
+ this.needs.value = "";
185
+ this.renderProducts();
186
+ this.status.textContent = this.message("shoppingNotesCleared");
187
+ this.callbacks.changed();
188
+ this.needs.focus();
189
+ }
190
+ start() {
191
+ if (this.destroyed ||
192
+ this.element.hidden ||
193
+ this.submitted ||
194
+ this.callbacks.active())
195
+ return;
196
+ if (this.expiresAt !== null && Date.now() >= this.expiresAt) {
197
+ this.status.textContent = this.message("shoppingNotesExpired");
198
+ return;
199
+ }
200
+ this.draft.needs = this.needs.value;
201
+ if (this.draft.needs.length > shoppingNotes_js_1.SHOPPING_NOTES_QUESTION_MAX_LENGTH) {
202
+ this.status.textContent = this.message("shoppingNotesTooLarge");
203
+ return;
204
+ }
205
+ const result = (0, shoppingNotes_js_1.buildShoppingNotesQuestion)(this.draft);
206
+ if (!result.ok) {
207
+ this.status.textContent = this.message(result.reason === "too_long"
208
+ ? "shoppingNotesTooLarge"
209
+ : result.reason === "empty"
210
+ ? "shoppingNotesEmpty"
211
+ : "shoppingNotesInvalid");
212
+ return;
213
+ }
214
+ this.submitted = true;
215
+ this.submittedQuestion = result.initialQuestion;
216
+ this.submittedCaption = {
217
+ question: result.initialQuestion,
218
+ text: [this.draft.needs, ...this.draft.products.map(product => [
219
+ product.label || this.message("shoppingNotesItem"),
220
+ ...product.selectedOptions.map(option => `${option.name}: ${option.value}`),
221
+ ].join("\n"))].filter(Boolean).join("\n\n"),
222
+ };
223
+ this.startButton.disabled = true;
224
+ if (!this.callbacks.start(result.initialQuestion)) {
225
+ this.failedLaunchDraft = true;
226
+ this.submitted = false;
227
+ this.startButton.disabled = false;
228
+ this.status.textContent = this.message("shoppingNotesStartFailed");
229
+ return;
230
+ }
231
+ this.failedLaunchDraft = false;
232
+ this.close(false);
233
+ }
234
+ renderProducts() {
235
+ this.products.replaceChildren();
236
+ for (const product of this.draft.products) {
237
+ const item = document.createElement("li");
238
+ const label = product.label || this.message("shoppingNotesItem");
239
+ const title = document.createElement("strong");
240
+ title.textContent = label;
241
+ const options = document.createElement("span");
242
+ options.textContent = product.selectedOptions
243
+ .map((value) => `${value.name}: ${value.value}`)
244
+ .join(" · ");
245
+ const remove = document.createElement("button");
246
+ remove.type = "button";
247
+ remove.textContent = this.message("shoppingNotesRemove")
248
+ .split("{product}")
249
+ .join(label);
250
+ remove.addEventListener("click", () => {
251
+ this.draft.products = this.draft.products.filter((value) => value !== product);
252
+ this.renderProducts();
253
+ this.status.textContent = "";
254
+ this.needs.focus();
255
+ });
256
+ item.append(title, options, remove);
257
+ this.products.append(item);
258
+ }
259
+ }
260
+ button(key, action) {
261
+ const button = document.createElement("button");
262
+ button.type = "button";
263
+ button.textContent = this.message(key);
264
+ button.dataset.role = key;
265
+ button.addEventListener("click", action);
266
+ return button;
267
+ }
268
+ }
269
+ exports.ShoppingNotesView = ShoppingNotesView;
package/cjs/context.js CHANGED
@@ -668,14 +668,26 @@ const safeOptionLabel = (option) => {
668
668
  return sensitivityFor(option, label) === 'none' ? label : '';
669
669
  };
670
670
  const isActionTarget = (element) => element.matches('a[href],button,input,select,textarea,summary,form,[contenteditable="true"],[role="button"],[role="link"],[role="checkbox"],[role="radio"],[role="combobox"],[role="textbox"],[tabindex]');
671
- const belongsToInteractiveControl = (element) => {
671
+ const belongsToInteractiveControl = (element, text) => {
672
+ const linkedText = element.closest('a[href],[role="link"]') !== null;
672
673
  for (let current = element; current; current = current.parentElement) {
673
- // Form copy can carry useful public instructions. Only controls and links
674
- // already represented in targets are omitted from visible page text.
674
+ // Public link text belongs in reading order beside surrounding page copy.
675
+ // Inspect the link's descriptors before sanitized names can erase them;
676
+ // neither those attributes nor the destination become semantic text.
677
+ if (current.matches('a[href],[role="link"]')) {
678
+ if (sensitivityFor(current, text) !== 'none' ||
679
+ sensitivityFor(current, normalize(`${current.getAttribute('aria-label') ?? ''} ${current.getAttribute('title') ?? ''}`, 500)) !== 'none' ||
680
+ accessibleNameSourceSensitivity(current) !== 'none')
681
+ return true;
682
+ }
683
+ if (linkedText && current.matches('[role="switch"],[role="option"],[role="slider"],[role="spinbutton"],[role="searchbox"],[role="listbox"],[role="treeitem"],[role="tab"],[role="menuitem"],[role="menuitemcheckbox"],[role="menuitemradio"]'))
684
+ return true;
685
+ // Form copy can carry useful public instructions. Actual control text
686
+ // stays in targets, including links nested inside controls.
675
687
  if (current.matches('form'))
676
688
  continue;
677
689
  // A bare tabindex is often a focusable Framer content card, not an action.
678
- if (current.matches('a[href],button,input,select,textarea,summary,[contenteditable="true"],[role="button"],[role="link"],[role="checkbox"],[role="radio"],[role="combobox"],[role="textbox"]'))
690
+ if (current.matches('button,input,select,textarea,summary,[contenteditable="true"],[role="button"],[role="checkbox"],[role="radio"],[role="combobox"],[role="textbox"]'))
679
691
  return true;
680
692
  }
681
693
  return false;
@@ -1254,7 +1266,7 @@ class PageContextCollector {
1254
1266
  !parent.closest('script,style,noscript,template,svg') &&
1255
1267
  !parent.closest('input,select,textarea,option') &&
1256
1268
  (!semanticTextElement || !capturedSemanticText.has(semanticTextElement)) &&
1257
- !belongsToInteractiveControl(textElement) &&
1269
+ !belongsToInteractiveControl(textElement, text) &&
1258
1270
  isRendered(textElement) &&
1259
1271
  sensitivityFor(textElement, nameFor(textElement)) === 'none') {
1260
1272
  const textId = this.textIds.get(node) ?? id('text');