@axceera/playstep 0.9.0 → 0.10.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/README.md +13 -2
- package/dist/capture-cKutY_OF.js +13 -0
- package/dist/cdn/capture.js +1 -1
- package/dist/cdn/events.js +1 -1
- package/dist/cdn/insights.js +1 -0
- package/dist/cdn/launcher.js +1 -1
- package/dist/cdn/loader.js +1 -1
- package/dist/cdn/ui.js +1 -1
- package/dist/{done-CVMSfARV.js → done-kxa44syt.js} +1 -1
- package/dist/index.d.ts +2 -329
- package/dist/index.js +1 -1
- package/dist/launcher-button-B62YRJZF.js +1 -0
- package/dist/{list-CJUADwzY.js → list-DJOai7g8.js} +1 -1
- package/dist/plugin-DtuC_pEx.d.ts +426 -0
- package/dist/plugin.d.ts +2 -0
- package/dist/plugin.js +1 -0
- package/dist/queue-CTbppTdt.js +1 -0
- package/dist/sdk-DpzIfiet.js +1 -0
- package/dist/transport-dyLfVpw6.js +1 -0
- package/dist/ui-BVaIwTOj.js +1 -0
- package/package.json +8 -4
- package/dist/capture-NeIia2Wg.js +0 -13
- package/dist/launcher-button-BFeH6G4k.js +0 -1
- package/dist/sdk-ujPSGL2k.js +0 -1
- package/dist/transport-DZeLw3bE.js +0 -1
- package/dist/ui-Wx3i3XXx.js +0 -1
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
//#region ../spec/src/strings.d.ts
|
|
2
|
+
/** Every word the SDK UI shows. `{n}`, `{total}`, `{guide}` and `{title}` are filled in by the SDK. */
|
|
3
|
+
declare const UI_STRING_KEYS: readonly ["next", "back", "done", "close_guide", "step_of", "waiting", "level_cleared", "finished", "next_up", "replay", "next_guide", "guides", "open_guides", "close_guides", "need_a_hand", "pick_a_guide", "completed", "n_steps", "new", "start_over", "video", "play_video", "clip", "play_clip", "loop", "mute_clip", "unmute_clip", "expand_clip", "shrink_clip"];
|
|
4
|
+
type UiStringKey = (typeof UI_STRING_KEYS)[number];
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region ../spec/src/types.d.ts
|
|
7
|
+
type Platform = 'web' | 'flutter' | 'react-native';
|
|
8
|
+
interface ClipBase {
|
|
9
|
+
poster?: string;
|
|
10
|
+
duration_ms?: number;
|
|
11
|
+
}
|
|
12
|
+
type Clip = (ClipBase & {
|
|
13
|
+
source: 'hosted';
|
|
14
|
+
clip_id?: string;
|
|
15
|
+
url: string;
|
|
16
|
+
bytes?: number;
|
|
17
|
+
}) | (ClipBase & {
|
|
18
|
+
source: 'external';
|
|
19
|
+
url: string;
|
|
20
|
+
}) | (ClipBase & {
|
|
21
|
+
source: 'embed';
|
|
22
|
+
provider: 'youtube' | 'vimeo';
|
|
23
|
+
url: string;
|
|
24
|
+
});
|
|
25
|
+
type ClipSource = Clip['source'];
|
|
26
|
+
type CompleteOn = {
|
|
27
|
+
type: 'tap_anchor';
|
|
28
|
+
} | {
|
|
29
|
+
type: 'event';
|
|
30
|
+
name: string;
|
|
31
|
+
} | {
|
|
32
|
+
type: 'manual';
|
|
33
|
+
} | {
|
|
34
|
+
type: 'next_button';
|
|
35
|
+
} | {
|
|
36
|
+
type: 'page';
|
|
37
|
+
path: string;
|
|
38
|
+
};
|
|
39
|
+
/** Where an anchor is when the app has no data-guide / GuideAnchor for it (see findSchema). */
|
|
40
|
+
interface Find {
|
|
41
|
+
web?: {
|
|
42
|
+
css: string;
|
|
43
|
+
text?: string;
|
|
44
|
+
};
|
|
45
|
+
flutter?: {
|
|
46
|
+
by: 'key' | 'text' | 'semantics' | 'tooltip';
|
|
47
|
+
value: string;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
type Trigger = {
|
|
51
|
+
type: 'first_visit';
|
|
52
|
+
once: boolean;
|
|
53
|
+
} | {
|
|
54
|
+
type: 'page_view';
|
|
55
|
+
path: string;
|
|
56
|
+
once: boolean;
|
|
57
|
+
} | {
|
|
58
|
+
type: 'event';
|
|
59
|
+
name: string;
|
|
60
|
+
once: boolean;
|
|
61
|
+
} | {
|
|
62
|
+
type: 'guide_completed';
|
|
63
|
+
guide: string;
|
|
64
|
+
once: boolean;
|
|
65
|
+
} | {
|
|
66
|
+
type: 'manual';
|
|
67
|
+
};
|
|
68
|
+
interface SegmentRule {
|
|
69
|
+
trait: string;
|
|
70
|
+
op: 'eq' | 'neq' | 'in' | 'exists';
|
|
71
|
+
value?: string | number | boolean | (string | number)[];
|
|
72
|
+
}
|
|
73
|
+
type ColorMode = 'auto' | 'light' | 'dark';
|
|
74
|
+
/** Guide UI token values from a brand kit, applied as `--ps-<name>` (see themeTokensSchema). */
|
|
75
|
+
interface ThemeTokens {
|
|
76
|
+
accent?: string;
|
|
77
|
+
'accent-hover'?: string;
|
|
78
|
+
'on-accent'?: string;
|
|
79
|
+
'primary-soft'?: string;
|
|
80
|
+
'primary-ink'?: string;
|
|
81
|
+
'surface-raised'?: string;
|
|
82
|
+
surface?: string;
|
|
83
|
+
'surface-sunken'?: string;
|
|
84
|
+
line?: string;
|
|
85
|
+
ink?: string;
|
|
86
|
+
'ink-secondary'?: string;
|
|
87
|
+
'ink-muted'?: string;
|
|
88
|
+
scrim?: string;
|
|
89
|
+
'shadow-lg'?: string;
|
|
90
|
+
'ring-focus'?: string;
|
|
91
|
+
'radius-lg'?: string;
|
|
92
|
+
'radius-md'?: string;
|
|
93
|
+
'radius-btn'?: string;
|
|
94
|
+
'font-sans'?: string;
|
|
95
|
+
'font-display'?: string;
|
|
96
|
+
}
|
|
97
|
+
/** The app's brand kit as the SDKs get it (see resolvedThemeSchema). */
|
|
98
|
+
interface ResolvedTheme {
|
|
99
|
+
mode: ColorMode;
|
|
100
|
+
light: ThemeTokens;
|
|
101
|
+
dark: ThemeTokens;
|
|
102
|
+
radius?: 'sharp' | 'small' | 'medium' | 'round';
|
|
103
|
+
shadow?: 'none' | 'soft' | 'strong';
|
|
104
|
+
scrim?: number;
|
|
105
|
+
font?: {
|
|
106
|
+
body?: string;
|
|
107
|
+
display?: string;
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
interface ConfigFlags {
|
|
111
|
+
disabled: boolean;
|
|
112
|
+
paused_for_new_users: boolean;
|
|
113
|
+
show_badge: boolean;
|
|
114
|
+
}
|
|
115
|
+
/** Capture links (Generate with AI): where the capture panel sends screens. */
|
|
116
|
+
interface CaptureConfig {
|
|
117
|
+
endpoint: string;
|
|
118
|
+
expires_at: string;
|
|
119
|
+
max_screens: number;
|
|
120
|
+
}
|
|
121
|
+
/** Insights' settings, present when the app turned analytics on (see analyticsConfigSchema). */
|
|
122
|
+
interface AnalyticsConfig {
|
|
123
|
+
url: string;
|
|
124
|
+
hash_key: string;
|
|
125
|
+
anonymous: boolean;
|
|
126
|
+
consent: 'granted' | 'pending' | 'denied';
|
|
127
|
+
autocapture: {
|
|
128
|
+
pages: boolean;
|
|
129
|
+
clicks: boolean;
|
|
130
|
+
forms: boolean;
|
|
131
|
+
rage: boolean;
|
|
132
|
+
dead: boolean;
|
|
133
|
+
};
|
|
134
|
+
identities: boolean;
|
|
135
|
+
mask: string[];
|
|
136
|
+
}
|
|
137
|
+
type EventType = 'guide_shown' | 'step_shown' | 'step_completed' | 'clip_loaded' | 'clip_played' | 'clip_unmuted' | 'guide_completed' | 'guide_dismissed' | 'anchor_missing' | 'sdk_error' | 'progress_reset';
|
|
138
|
+
interface AnalyticsEvent {
|
|
139
|
+
/** Random per event, so a batch delivered twice counts once. */
|
|
140
|
+
id?: string;
|
|
141
|
+
type: EventType;
|
|
142
|
+
ts: number;
|
|
143
|
+
guide_id?: string;
|
|
144
|
+
guide_version?: number;
|
|
145
|
+
step_id?: string;
|
|
146
|
+
step_index?: number;
|
|
147
|
+
anchor?: string;
|
|
148
|
+
clip_id?: string;
|
|
149
|
+
clip_source?: ClipSource;
|
|
150
|
+
/** guide_shown: what started the guide. */
|
|
151
|
+
source?: GuideSource;
|
|
152
|
+
message?: string;
|
|
153
|
+
}
|
|
154
|
+
/** What started a guide (see GUIDE_SOURCES). */
|
|
155
|
+
type GuideSource = 'trigger' | 'launcher' | 'api';
|
|
156
|
+
interface EventBatch {
|
|
157
|
+
key: string;
|
|
158
|
+
sdk: {
|
|
159
|
+
name: 'web' | 'react' | 'flutter';
|
|
160
|
+
version: string;
|
|
161
|
+
};
|
|
162
|
+
platform: Platform;
|
|
163
|
+
session_id: string;
|
|
164
|
+
user_key: string;
|
|
165
|
+
preview: boolean;
|
|
166
|
+
locale?: string;
|
|
167
|
+
events: AnalyticsEvent[];
|
|
168
|
+
}
|
|
169
|
+
/** A step's clip or image, ready to draw. */
|
|
170
|
+
interface RenderedMedia {
|
|
171
|
+
/** `video`: a muted looping <video>; `embed`: a click-to-load player (`url` is the player); `image`. */
|
|
172
|
+
kind: 'video' | 'embed' | 'image';
|
|
173
|
+
url: string;
|
|
174
|
+
poster?: string;
|
|
175
|
+
duration_ms?: number;
|
|
176
|
+
/** For clip events. */
|
|
177
|
+
source?: ClipSource;
|
|
178
|
+
clip_id?: string;
|
|
179
|
+
/** `embed`: the site it plays from; `image`: its description for screen readers. */
|
|
180
|
+
label?: string;
|
|
181
|
+
width?: number;
|
|
182
|
+
height?: number;
|
|
183
|
+
}
|
|
184
|
+
interface RenderedStep {
|
|
185
|
+
id: string;
|
|
186
|
+
anchor?: string;
|
|
187
|
+
find?: Find;
|
|
188
|
+
title: string;
|
|
189
|
+
body: string;
|
|
190
|
+
media?: RenderedMedia;
|
|
191
|
+
complete_on: CompleteOn;
|
|
192
|
+
skip_if_on?: string;
|
|
193
|
+
/**
|
|
194
|
+
* The page (path or route pattern) this step belongs on: the page trigger's or a page step's, kept through Next
|
|
195
|
+
* steps only; none: any page. Elsewhere a running guide waits, its progress kept, so it neither follows the user
|
|
196
|
+
* around nor blocks that page's own guide.
|
|
197
|
+
*/
|
|
198
|
+
page?: string;
|
|
199
|
+
placement: 'auto' | 'top' | 'bottom' | 'left' | 'right';
|
|
200
|
+
/** Show Back on this step. */
|
|
201
|
+
back?: true;
|
|
202
|
+
}
|
|
203
|
+
interface RenderedGuide {
|
|
204
|
+
id: string;
|
|
205
|
+
version: number;
|
|
206
|
+
name: string;
|
|
207
|
+
/** The language it shows in: a key of the config's `words`. */
|
|
208
|
+
lang: string;
|
|
209
|
+
rtl?: true;
|
|
210
|
+
trigger: Trigger;
|
|
211
|
+
segments?: SegmentRule[];
|
|
212
|
+
launcher: boolean;
|
|
213
|
+
/**
|
|
214
|
+
* The page it begins on, `*` parts to fill in from the current path. Started from the guide list, the finish screen
|
|
215
|
+
* or start(id) elsewhere, an SDK with the app's router takes the user there first.
|
|
216
|
+
*/
|
|
217
|
+
start_path?: string;
|
|
218
|
+
/** Where the card sits for steps without an anchor. */
|
|
219
|
+
position: 'bottom' | 'center';
|
|
220
|
+
/** Always this mode, whatever the app does. */
|
|
221
|
+
mode?: 'light' | 'dark';
|
|
222
|
+
/** Its own accent's tokens, over the brand kit's. */
|
|
223
|
+
tokens?: {
|
|
224
|
+
light: ThemeTokens;
|
|
225
|
+
dark: ThemeTokens;
|
|
226
|
+
};
|
|
227
|
+
steps: RenderedStep[];
|
|
228
|
+
}
|
|
229
|
+
/** The guide UI's own words in one language, every one filled. */
|
|
230
|
+
type Words = Record<UiStringKey, string>;
|
|
231
|
+
interface RenderedConfig {
|
|
232
|
+
/** The render protocol it was made for (RENDER_PROTOCOL). */
|
|
233
|
+
render: number;
|
|
234
|
+
app_id: string;
|
|
235
|
+
env: 'dev' | 'prod';
|
|
236
|
+
generated_at: string;
|
|
237
|
+
ingest_url?: string;
|
|
238
|
+
flags: ConfigFlags;
|
|
239
|
+
/** The guide list's language. */
|
|
240
|
+
lang: string;
|
|
241
|
+
rtl?: true;
|
|
242
|
+
/** Per language used: the list's and each guide's. */
|
|
243
|
+
words: Record<string, Words>;
|
|
244
|
+
launcher: {
|
|
245
|
+
enabled: boolean;
|
|
246
|
+
position: 'bottom-right' | 'bottom-left';
|
|
247
|
+
title: string;
|
|
248
|
+
description: string;
|
|
249
|
+
};
|
|
250
|
+
theme?: ResolvedTheme;
|
|
251
|
+
guides: RenderedGuide[];
|
|
252
|
+
capture?: CaptureConfig;
|
|
253
|
+
/** Insights: present when the app turned analytics on. */
|
|
254
|
+
analytics?: AnalyticsConfig;
|
|
255
|
+
/**
|
|
256
|
+
* A signed-in user's guide progress from all their devices, when the SDK asked with the SHA-256 hex of
|
|
257
|
+
* `<publishable key>:<user id>` (`u=`; PLAY-56). Per guide it wins over the device's own; the guides in `reset`
|
|
258
|
+
* (a support reset) are cleared on the device.
|
|
259
|
+
*/
|
|
260
|
+
progress?: {
|
|
261
|
+
seen: boolean;
|
|
262
|
+
guides: Record<string, {
|
|
263
|
+
version: number;
|
|
264
|
+
step: number;
|
|
265
|
+
status: 'running' | 'done' | 'dismissed';
|
|
266
|
+
source?: string;
|
|
267
|
+
}>;
|
|
268
|
+
reset: string[];
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
//#endregion
|
|
272
|
+
//#region src/core/queue.d.ts
|
|
273
|
+
interface SendResult {
|
|
274
|
+
/** The HTTP status; 0 when the request never got an answer. */
|
|
275
|
+
status: number;
|
|
276
|
+
/** Retry-After, in seconds. */
|
|
277
|
+
retryAfter?: number;
|
|
278
|
+
}
|
|
279
|
+
/** `E` is an event and `B` the batch around it: guide events by default; Insights' add-on queues its own batches. */
|
|
280
|
+
interface QueueOptions<B = Omit<EventBatch, 'events' | 'platform'>> {
|
|
281
|
+
url: string;
|
|
282
|
+
/** The batch envelope (who and where), or null to keep the events for now. */
|
|
283
|
+
envelope: () => B | null;
|
|
284
|
+
/** Where unsent batches are kept between page loads (one entry per page load, so tabs never overwrite each other). */
|
|
285
|
+
storageKey: string;
|
|
286
|
+
/** Tests and the e2e harness: replaces fetch and sendBeacon. Returning nothing counts as delivered. */
|
|
287
|
+
send?: (url: string, body: string) => Promise<SendResult> | SendResult | undefined;
|
|
288
|
+
delayMs?: number;
|
|
289
|
+
}
|
|
290
|
+
declare function createQueue<E = AnalyticsEvent, B = Omit<EventBatch, 'events' | 'platform'>>(o: QueueOptions<B>): {
|
|
291
|
+
push(e: E): void;
|
|
292
|
+
flush: () => undefined;
|
|
293
|
+
/** Events not yet in a batch. */
|
|
294
|
+
readonly size: number;
|
|
295
|
+
/** Batches waiting to be sent (or retried). */
|
|
296
|
+
readonly pending: number;
|
|
297
|
+
};
|
|
298
|
+
//#endregion
|
|
299
|
+
//#region src/core/util.d.ts
|
|
300
|
+
/** localStorage that never throws (private mode, blocked storage, quota). */
|
|
301
|
+
declare const store: {
|
|
302
|
+
get<T>(key: string): T | null | undefined;
|
|
303
|
+
set(key: string, value: unknown): void;
|
|
304
|
+
};
|
|
305
|
+
//#endregion
|
|
306
|
+
//#region src/core/engine.d.ts
|
|
307
|
+
type Traits = Record<string, unknown>;
|
|
308
|
+
//#endregion
|
|
309
|
+
//#region src/core/sdk.d.ts
|
|
310
|
+
interface InitOptions {
|
|
311
|
+
/** Your publishable key, `ps_pub_…`. */
|
|
312
|
+
appKey: string;
|
|
313
|
+
/** Where configs and events live. Defaults to https://cdn.playstep.app. */
|
|
314
|
+
apiBase?: string;
|
|
315
|
+
/**
|
|
316
|
+
* The language to show guides in, like `fr` or `pt-BR`. Defaults to the browser language. A guide without that
|
|
317
|
+
* language shows in its default one. Change it later with setLocale().
|
|
318
|
+
*/
|
|
319
|
+
locale?: string;
|
|
320
|
+
/** Send page views for client-side navigation automatically. Default true. */
|
|
321
|
+
autoPageViews?: boolean;
|
|
322
|
+
/** Use this config instead of fetching one (dashboard previews and tests). Nothing is metered. */
|
|
323
|
+
config?: RenderedConfig;
|
|
324
|
+
/** Preview mode: nothing is metered. Set automatically by `?playstep_preview=` links. */
|
|
325
|
+
preview?: boolean;
|
|
326
|
+
/** Called for every analytics event, so you can pipe guide events into your own analytics. */
|
|
327
|
+
onEvent?: (event: AnalyticsEvent) => void;
|
|
328
|
+
/**
|
|
329
|
+
* Light or dark guides. `auto` (the default) follows your page: a `dark` or `light` class, `data-theme`,
|
|
330
|
+
* `data-bs-theme` or `color-scheme` on `<html>` or `<body>` (re-checked whenever they change), else the device
|
|
331
|
+
* setting. A guide or brand kit set to always light or dark wins over this.
|
|
332
|
+
*/
|
|
333
|
+
colorMode?: ColorMode;
|
|
334
|
+
/**
|
|
335
|
+
* Your router, so a guide can begin where it starts (its start page, set in the dashboard): `(path) =>
|
|
336
|
+
* router.push(path)`. When someone starts a guide from the guide list, replays it from the finish screen, or your code
|
|
337
|
+
* calls start(id) on another page, PlayStep calls this with that page and shows step 1 once the page view is reported.
|
|
338
|
+
* Triggers never navigate. Without it, guides start wherever the user is.
|
|
339
|
+
*/
|
|
340
|
+
navigate?: (path: string) => void;
|
|
341
|
+
/**
|
|
342
|
+
* Where a guide's start page is for this user right now, for `navigate`. `startPath` is the page as set in the
|
|
343
|
+
* dashboard, with `*` for the parts that vary, like `/app/*\/projects`. Without this, each `*` takes the same part of
|
|
344
|
+
* the current URL: `/app/acme/projects` from `/app/acme/settings`. Give it when that part is not always in the URL
|
|
345
|
+
* (pages outside a workspace, like `/app/home`), so nobody is sent to a page that does not exist. Return nothing to
|
|
346
|
+
* start the guide where the user is.
|
|
347
|
+
*/
|
|
348
|
+
startPage?: (startPath: string, guideId: string) => string | null | undefined;
|
|
349
|
+
/** @internal Set by @axceera/playstep-react. */
|
|
350
|
+
sdkName?: 'web' | 'react';
|
|
351
|
+
/** @internal Tests: replaces fetch and navigator.sendBeacon. Returning nothing counts as delivered. */
|
|
352
|
+
transport?: (url: string, body: string) => Promise<SendResult> | SendResult | undefined;
|
|
353
|
+
}
|
|
354
|
+
interface OpenLauncherOptions {
|
|
355
|
+
/** The element that opened the list (your help button): the list opens next to it instead of in a corner. */
|
|
356
|
+
anchor?: Element;
|
|
357
|
+
}
|
|
358
|
+
/** Event properties for track(): what add-ons such as Insights record with the event. Guides use only the name. */
|
|
359
|
+
type EventProps = Record<string, unknown>;
|
|
360
|
+
/**
|
|
361
|
+
* What an add-on hears: the config (with the init options: the app key, the SDK's name) once it has loaded, then the
|
|
362
|
+
* app's calls. `identify` carries every trait so far; `page` comes for the first page and each client-side navigation
|
|
363
|
+
* (unless autoPageViews is false) and for page().
|
|
364
|
+
*/
|
|
365
|
+
type PluginCall = [call: 'config', config: RenderedConfig, options: InitOptions] | [call: 'identify', userId: string, traits: Traits] | [call: 'track', event: string, props?: EventProps] | [call: 'page', path: string] | [call: 'reset'];
|
|
366
|
+
/**
|
|
367
|
+
* An add-on, attached with use(): Insights' analytics add-on (@axceera/playstep-analytics, or the insights.js chunk
|
|
368
|
+
* the loader fetches for an app with analytics on, which attaches itself). One function that hears every call; one
|
|
369
|
+
* that throws is reported and never breaks the app. A disabled app tells add-ons nothing. Once the config is here, the
|
|
370
|
+
* first add-on of an app with analytics on also hears up to 50 calls made before it; without analytics they're dropped.
|
|
371
|
+
*/
|
|
372
|
+
type PlayStepPlugin = (...call: PluginCall) => void;
|
|
373
|
+
interface PlayStep {
|
|
374
|
+
readonly version: string;
|
|
375
|
+
/** Starts the SDK. Safe to call once; later calls are ignored. */
|
|
376
|
+
init: (options: InitOptions) => void;
|
|
377
|
+
/** Tells PlayStep who the user is. The id is hashed before it leaves the browser; traits drive segments. */
|
|
378
|
+
identify: (userId: string, traits?: Traits) => void;
|
|
379
|
+
/**
|
|
380
|
+
* Reports one of your events: it can start a guide or complete an `event` step. `props` go to add-ons such as
|
|
381
|
+
* Insights; guides use only the name.
|
|
382
|
+
*/
|
|
383
|
+
track: (event: string, props?: EventProps) => void;
|
|
384
|
+
/** Starts a guide now, even if it has been completed before (a replay). */
|
|
385
|
+
start: (guideId: string) => void;
|
|
386
|
+
/** Completes the current step if its id matches (for `manual` steps). */
|
|
387
|
+
complete: (stepId: string) => void;
|
|
388
|
+
/** Reports a page or screen view (automatic for client-side navigation unless autoPageViews is false). */
|
|
389
|
+
page: (path?: string) => void;
|
|
390
|
+
/**
|
|
391
|
+
* Opens the list of guides this user can replay, whether or not the floating launcher button is on: call it from
|
|
392
|
+
* your own help menu, passing that button as the `anchor` option so the list opens next to it (else next to the
|
|
393
|
+
* focused element, or in the launcher's corner). A guide that is showing pauses until the list closes. Does nothing when there are no
|
|
394
|
+
* guides to list; before the SDK has loaded, it opens once loaded.
|
|
395
|
+
*/
|
|
396
|
+
openLauncher: (options?: OpenLauncherOptions) => void;
|
|
397
|
+
/**
|
|
398
|
+
* Clears guide progress on this device so guides can start again: every guide, or only `guideId`. The user, their
|
|
399
|
+
* traits and the device id stay. A guide it clears closes, and first-visit and page triggers are checked again for
|
|
400
|
+
* the current page straight away. Emits `progress_reset`.
|
|
401
|
+
*/
|
|
402
|
+
resetProgress: (guideId?: string) => void;
|
|
403
|
+
/**
|
|
404
|
+
* Forgets the user and their guide progress on this device (call on sign-out). It does not end a pause().
|
|
405
|
+
*/
|
|
406
|
+
reset: () => void;
|
|
407
|
+
/**
|
|
408
|
+
* Stops guides for now, for a user who should not see them at the moment (a guest in this workspace, say): nothing
|
|
409
|
+
* starts, a guide that is showing leaves the screen with nothing stored, and the guide list cannot open. Stored
|
|
410
|
+
* progress is untouched. Lasts until resume() or the next page load. Use reset() on sign-out instead.
|
|
411
|
+
*/
|
|
412
|
+
pause: () => void;
|
|
413
|
+
/** Ends a pause(): the guide that was showing comes back on its step, else triggers are checked for this page. */
|
|
414
|
+
resume: () => void;
|
|
415
|
+
/** Whether guides are paused. */
|
|
416
|
+
isPaused: () => boolean;
|
|
417
|
+
/**
|
|
418
|
+
* Shows guides in another language from now on, for an app that switches language without reloading. A guide that
|
|
419
|
+
* is showing switches straight away.
|
|
420
|
+
*/
|
|
421
|
+
setLocale: (locale: string) => void;
|
|
422
|
+
/** Attaches an add-on (once per name), such as Insights' analytics add-on. */
|
|
423
|
+
use: (plugin: PlayStepPlugin) => void;
|
|
424
|
+
}
|
|
425
|
+
//#endregion
|
|
426
|
+
export { PlayStepPlugin as a, QueueOptions as c, AnalyticsEvent as d, ColorMode as f, PlayStep as i, SendResult as l, RenderedGuide as m, InitOptions as n, PluginCall as o, RenderedConfig as p, OpenLauncherOptions as r, store as s, EventProps as t, createQueue as u };
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as PlayStepPlugin, c as QueueOptions, i as PlayStep, l as SendResult, n as InitOptions, o as PluginCall, s as store, t as EventProps, u as createQueue } from "./plugin-DtuC_pEx.js";
|
|
2
|
+
export { type EventProps, type InitOptions, type PlayStep, type PlayStepPlugin, type PluginCall, type QueueOptions, type SendResult, createQueue, store };
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./util-X5IoDowG.js";import{t}from"./queue-CTbppTdt.js";export{t as createQueue,e as store};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=`playstep:q`,t=(e,t)=>fetch(e,{method:`POST`,body:t,keepalive:!0,headers:{"content-type":`text/plain`}}).then(e=>({status:e.status,retryAfter:Number(e.headers.get(`retry-after`))||void 0}),()=>({status:0})),n={read(e){try{return JSON.parse(localStorage.getItem(e))??[]}catch{return[]}},write(t,n){try{n.length?localStorage.setItem(t,JSON.stringify(n)):localStorage.removeItem(t);let r=!1;for(let e=0;e<localStorage.length;e++)r||(r=!!localStorage.key(e)?.startsWith(`playstep:q:`));r?localStorage.setItem(e,`1`):localStorage.removeItem(e)}catch{}}};function r(e){let r=[],i=[],a=[],o,s,c=0,l=!1,u=`${e.storageKey}:${Math.random().toString(36).slice(2,10)}`,d=()=>n.write(u,[...a,...i]),f=async n=>await e.send?.(e.url,n)??(e.send?{status:204}:t(e.url,n));try{for(let t=localStorage.length-1;t>=0;t--){let r=localStorage.key(t);r?.startsWith(`${e.storageKey}:`)&&(i.push(...n.read(r).filter(e=>Date.now()-e.t<6048e5)),localStorage.removeItem(r))}}catch{}i=i.sort((e,t)=>e.t-t.t).slice(-25),d();async function p(){if(!(l||s)){l=!0;try{for(;i.length;){let e=await f(i[0].b);if(e.status===0||e.status===408||e.status===429||e.status>=500){c=Math.min(6e4,c*2||2e3),s=setTimeout(()=>{s=void 0,p()},Math.max(c,(e.retryAfter??0)*1e3));break}c=0,i.shift(),d()}}finally{l=!1}}}function m(n=!1){clearTimeout(o),o=void 0;let s=r.length?e.envelope():null;if(s){for(;r.length;)i.push({b:JSON.stringify({...s,events:r.splice(0,20)}),t:Date.now()});i=i.slice(-25),d()}if(!n)return void p();for(let n of i.splice(0))e.send?f(n.b):navigator.sendBeacon?.(e.url,n.b)||t(e.url,n.b),a.push(n);a=a.slice(-25),d()}return addEventListener(`visibilitychange`,()=>document.visibilityState===`hidden`&&m(!0)),addEventListener(`pagehide`,()=>m(!0)),i.length&&p(),{push(t){r.push(t),r.length>=20?m():o??(o=setTimeout(m,e.delayMs??2e3))},flush:()=>m(),get size(){return r.length},get pending(){return i.length}}}export{r as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./util-X5IoDowG.js";const t=e=>RegExp(`^${e.replace(/[.+?^${}()|[\]\\]/g,`\\$&`).replace(/\*/g,`.*`)}$`),n=e=>e.length>1?e.replace(/\/+$/,``):e;function r(e,r){return!!e&&r!==void 0&&t(n(e)).test(n(r))}function i(e,t){return(e??[]).every(e=>{let n=t[e.trait];return e.op===`exists`?n!=null:e.op===`in`?Array.isArray(e.value)&&e.value.includes(n):e.op==`eq`?n===e.value:e.op==`neq`&&n!==e.value})}function a(e){let t=e.progress??{seen:!1,guides:{}},n=e.traits??{},a=null,o,s=/* @__PURE__ */ new Set,c=/* @__PURE__ */ new Set,l=!1,u=e.config.flags,d=e.config.guides,f=e=>d.find(t=>t.id===e),p=(e,t,n)=>({type:e,guide_id:t.id,guide_version:t.version,...n>=0&&{step_id:t.steps[n].id,step_index:n}}),m=e=>!l&&!u.disabled&&(!u.paused_for_new_users||t.seen)&&i(e.segments,n),h=e=>{let n=t.guides[e.id];return!a&&!s.has(e.id)&&m(e)&&(!n||n.status!==`done`&&(n.status===`running`||!e.trigger.once))},g=(e,n,r)=>{t.guides[e.id]={...t.guides[e.id],version:e.version,step:r,status:n}},_,v=e=>r(e.path,_),y=e=>r(e.skip_if_on,_)||v(e.complete_on),b=e=>!_||r(e.page??`*`,_),x=(e,t,n)=>{for(;t<e.steps.length;){if(a={guide:e,index:t,status:`running`},o=void 0,g(e,`running`,t),n.push(p(`step_shown`,e,t)),!y(e.steps[t]))return n;n.push(p(`step_completed`,e,t++))}return a={guide:e,index:--t,status:`completed`},g(e,`done`,t),n.push(p(`guide_completed`,e)),n},S=(e,n,r=`trigger`)=>(t.seen=!0,c.add(e.id),t.guides[e.id]={source:r},x(e,n,[{...p(`guide_shown`,e),source:r}])),C=()=>{let e=a;return x(e.guide,e.index+1,[p(`step_completed`,e.guide,e.index)])},w=e=>{let t=d.find(t=>h(t)&&e(t));return t?S(t,0):[]},T=e=>e.trigger.type===`first_visit`||v(e.trigger),E=()=>(s.clear(),w(T)),D=(e=T)=>{let n=0,r=d.find(e=>{let r=t.guides[e.id];return n=r?.version===e.version?r.step:0,!a&&r?.status===`running`&&!s.has(e.id)&&m(e)&&b(e.steps[n])});return r?c.has(r.id)?x(r,n,[]):S(r,n,t.guides[r.id].source):w(e)};function O(e){let i=a?.status===`running`?a.guide.steps[a.index]:null,u=l?null:i;switch(e.type){case`init`:return _=e.path,s.clear(),c.clear(),D();case`pause`:return l=!0,[];case`resume`:return l?(l=!1,D()):[];case`page_view`:return _=e.path,!l&&a?.status===`waiting`?S(a.guide,0,a.source):u&&y(u)?C():(i&&!b(i)&&(a=null),D(e=>v(e.trigger)));case`reset_progress`:{let n=typeof e.guide==`string`&&f(e.guide);return n===void 0?[]:((!n||a?.guide===n)&&(a=null),n?delete t.guides[n.id]:t.guides={},[{type:`progress_reset`,...n&&{guide_id:n.id}},...E()])}case`event`:return u?.complete_on.type===`event`&&u.complete_on.name===e.name?C():w(t=>t.trigger.type===`event`&&t.trigger.name===e.name);case`tap`:return u?.complete_on.type===`tap_anchor`&&u.anchor===e.anchor?C():[];case`complete`:return u?.id===e.step?C():[];case`next`:return u?.complete_on.type===`next_button`?C():[];case`back`:return!u||a.index===0?[]:(a={...a,index:a.index-1},g(a.guide,`running`,a.index),[p(`step_shown`,a.guide,a.index)]);case`hide`:return u&&(s.add(a.guide.id),a=null),[];case`close`:if(a?.status!==`completed`)return[];case`dismiss`:{let e=a;return a=null,i?(g(e.guide,`dismissed`,e.index),[p(`guide_dismissed`,e.guide,e.index)]):e?.status==`completed`?D(t=>v(t.trigger)||t.trigger.guide==e.guide.id):[]}case`start`:{let t=f(e.guide);if(!t||!m(t)||u&&a.guide===t&&t.steps.slice(0,a.index).every(y))return[];let n=e.source??`api`;return e.to&&!r(t.start_path,_)?(a={guide:t,index:0,status:`waiting`,source:n},[]):S(t,0,n)}case`anchor_missing`:return!u||u.anchor!==e.anchor||o===e.anchor?[]:(o=e.anchor,[{...p(`anchor_missing`,a.guide,a.index),anchor:e.anchor}]);case`identify`:return n={...n,...e.traits},[]}}return{get active(){return l?null:a},progress:t,dispatch:O,launcherGuides:()=>d.filter(e=>e.launcher&&m(e)),use(e){d=e.guides,a&&(a={...a,guide:f(a.guide.id)??a.guide})}}}const o=`0.10.0`,s=`playstep_preview`;function c(t,n,r,i){let c,l,u,d,f,p,m,h,g={},_=!1,v,y=[],b=[],x=[],S=[],C=()=>`p:${c.appKey}`,w=()=>c.preview||e.set(C(),l.progress),T=e=>{let t={...e,ts:Date.now()};c?.preview||(f?f.send(t):b.push(t)),c?.onEvent?.(t)},E=e=>{try{T({type:`sdk_error`,message:String(e)})}catch{}},D=e=>(...t)=>{try{e(...t)}catch(e){E(e)}},O=(...e)=>S?S.length<50&&S.push(e):x.forEach(t=>D(t)(...e)),k=()=>{let e=S;S=void 0,e.forEach(e=>O(...e))},A=(e,t)=>D(n=>j({type:e,[t]:n}));function j(t){if(!l)return void y.push(t);if(t.type==`start`&&t.to===void 0&&c.navigate)return void N().then(e=>e?.start(t));let n=l.dispatch(t);w(),n.forEach(D(T)),(l.active||e.get(`q`))&&N(),f?.update()}function M(){return m??(m=document.body.appendChild(document.createElement(`playstep-root`)).attachShadow({mode:`open`}))}function N(){return p??(p=t().then(e=>{let t=M();return t.innerHTML=``,f=e.mount({engine:l,get config(){return u},options:c,root:t,outbox:b,userId:()=>h,dispatch:D(j),emit:D(T)})}).catch(E))}let P,F=D((e={})=>{l?l.launcherGuides().length&&N().then(t=>t?.openLauncher(e.anchor)):P=e});function I(e){e.launcher?.enabled&&l.launcherGuides().length&&!p&&n&&n().then(t=>{p||t.drawLauncher(M(),l,e,F,c)}).catch(E)}let L=e=>D(()=>{_!==e&&(_=e,l&&(j({type:e?`pause`:`resume`}),!p&&(e?m&&(m.innerHTML=``):I(u))))});async function R(){let t=c,n=(t.apiBase??`https://cdn.playstep.app`).replace(/\/$/,``),o=null;try{o=new URLSearchParams(location.search).get(s)||(t.config?null:sessionStorage.getItem(s))}catch{}t.preview||(t.preview=!!(t.config||o)),d=async e=>{let r=``;try{h&&!o&&(r=`&u=`+btoa(String.fromCharCode(...new Uint8Array(await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(`${t.appKey}:${h}`))))))}catch{}return(await fetch(`${n}/v2/${o?`preview/${o}?key=${t.appKey}&`:`config/${t.appKey}?`}l=${e}${r}`)).json()};let f=t.config;try{f??(f=await d(t.locale??navigator.language??``))}catch{return}try{o&&sessionStorage[f.guides?`setItem`:`removeItem`](s,o)}catch{}if(f?.capture)return void r?.().then(e=>e.start(f.capture,t.appKey)).catch(E);if(!f?.guides||f.flags?.disabled)return;u=f,t.eventsUrl=f.ingest_url??`${n}/v1/events`,f.analytics||(S=void 0),x.splice(0).forEach(z.use),S&&i?.().catch(E);let p=t.preview?void 0:e.get(C()),m=f.progress;if(m){p={seen:m.seen||!!p?.seen,guides:{...p?.guides,...m.guides}};for(let e of m.reset)delete p.guides[e]}if(l=a({config:f,progress:p,traits:g}),_&&l.dispatch({type:`pause`}),j({type:`init`,path:location.pathname}),y.splice(0).forEach(j),P&&F(P),I(f),t.autoPageViews!==!1){let e=location.pathname;O(`page`,e);let t=D(()=>location.pathname!==e&&z.page(e=location.pathname));for(let e of[`pushState`,`replaceState`]){let n=history[e];history[e]=function(...e){n.apply(this,e),t()}}addEventListener(`popstate`,t)}}let z={version:o,init:D(e=>{if(c||!e?.appKey)return;c={...e},v&&(c.locale=v);let t=()=>setTimeout(()=>R().catch(E));document.readyState===`complete`?t():addEventListener(`load`,t)}),identify:D((e,t)=>{h=e,g={...g,...t},j({type:`identify`,traits:g}),O(`identify`,e,g)}),track:D((e,t)=>{j({type:`event`,name:e}),O(`track`,e,t)}),start:A(`start`,`guide`),complete:A(`complete`,`step`),page:D((e=location.pathname)=>{j({type:`page_view`,path:e}),O(`page`,e)}),openLauncher:F,resetProgress:A(`reset_progress`,`guide`),reset:D(()=>{j({type:`dismiss`}),h=void 0,g={},l&&(Object.assign(l.progress,{seen:!1,guides:{}}),w(),f?.update()),c?.preview||e.set(`d`,null),O(`reset`)}),pause:L(!0),resume:L(!1),isPaused:()=>_,setLocale:D(e=>{v=e,c&&(c.locale=e),d?.(e).then(t=>{t.guides&&c?.locale==e&&(l.use(u=t),f?.update())}).catch(E)}),use:D(e=>{x.push(e),u&&(D(e)(`config`,u,c),S&&k())})};return z}export{c as n,o as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./util-X5IoDowG.js";import{t}from"./queue-CTbppTdt.js";const n=[];for(let e=2;n.length<64;e++){let t=!0;for(let n=2;n*n<=e;n++)e%n===0&&(t=!1);t&&n.push(Math.cbrt(e)%1*2**32|0)}const r=(e,t)=>e>>>t|e<<32-t;function i(e){let t=new TextEncoder().encode(e),i=t.length,a=new Uint32Array((i+8>>6)*16+16);for(let e=0;e<i;e++)a[e>>2]|=t[e]<<24-e%4*8;a[i>>2]|=128<<24-i%4*8,a[a.length-1]=i*8,a[a.length-2]=Math.floor(i/536870912);let o=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],s=/* @__PURE__ */ new Uint32Array(64);for(let e=0;e<a.length;e+=16){for(let t=0;t<64;t++)if(t<16)s[t]=a[e+t];else{let e=s[t-15],n=s[t-2];s[t]=s[t-16]+(r(e,7)^r(e,18)^e>>>3)+s[t-7]+(r(n,17)^r(n,19)^n>>>10)}let[t,i,c,l,u,d,f,p]=o;for(let e=0;e<64;e++){let a=p+(r(u,6)^r(u,11)^r(u,25))+(u&d^~u&f)+n[e]+s[e]|0,o=(r(t,2)^r(t,13)^r(t,22))+(t&i^t&c^i&c)|0;p=f,f=d,d=u,u=l+a|0,l=c,c=i,i=t,t=a+o|0}[t,i,c,l,u,d,f,p].forEach((e,t)=>o[t]=o[t]+e|0)}return o.map(e=>(e>>>0).toString(16).padStart(8,`0`)).join(``)}const a=e=>e+(crypto.randomUUID?crypto.randomUUID().replace(/-/g,``):Math.random().toString(36).slice(2)+Date.now().toString(36));function o(){try{let e=sessionStorage.getItem(`playstep:s`);return e||sessionStorage.setItem(`playstep:s`,e=a(`s_`)),e}catch{return a(`s_`)}}function s(n){let r=o(),s=()=>{let t=e.get(`d`);return t||e.set(`d`,t=a(`d_`)),t},c,l=``,u=t({url:n.url,send:n.send,storageKey:`playstep:q:${n.appKey}`,envelope:()=>{let e=n.userId()||void 0;return e?e!==c&&(l=`u_${i(`${n.appKey}:${e}`).slice(0,40)}`):l=s(),c=e,{key:n.appKey,sdk:{name:n.sdk,version:n.version},session_id:r,user_key:l,preview:n.preview,locale:n.locale()}}});return{session:r,push:e=>u.push({...e,id:e.id??a(`e`).slice(0,25),...e.message?{message:e.message.slice(0,300)}:{}}),flush:u.flush}}export{s as createTransport,a as randomId,o as sessionId};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./sdk-DpzIfiet.js";import{t}from"./util-X5IoDowG.js";import{t as n}from"./mode-CPlpg1Yl.js";var r=Object.defineProperty,i=(e,t)=>{let n={};for(var i in e)r(n,i,{get:e[i],enumerable:!0});return t||r(n,Symbol.toStringTag,{value:`Module`}),n};const a={x:`<path d="M18 6 6 18"/><path d="m6 6 12 12"/>`,play:`<path d="M5 5a2 2 0 0 1 3-1.7l12 7a2 2 0 0 1 0 3.5l-12 7A2 2 0 0 1 5 19z"/>`,"volume-2":`<path d="M11 4.7a.7.7 0 0 0-1.2-.5L6.4 7.6A1.4 1.4 0 0 1 5.4 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.4a1.4 1.4 0 0 1 1 .4l3.4 3.4A.7.7 0 0 0 11 19.3z"/><path d="M16 9a5 5 0 0 1 0 6"/><path d="M19.4 18.4a9 9 0 0 0 0-12.7"/>`,"volume-x":`<path d="M11 4.7a.7.7 0 0 0-1.2-.5L6.4 7.6A1.4 1.4 0 0 1 5.4 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.4a1.4 1.4 0 0 1 1 .4l3.4 3.4A.7.7 0 0 0 11 19.3z"/><path d="m16.5 14.5 5-5"/><path d="m16.5 9.5 5 5"/>`,check:`<path d="M20 6 9 17l-5-5"/>`,"maximize-2":`<path d="M15 3h6v6"/><path d="m21 3-7 7"/><path d="m3 21 7-7"/><path d="M9 21H3v-6"/>`,"arrow-right":`<path d="M5 12h14"/><path d="m12 5 7 7-7 7"/>`,"rotate-ccw":`<path d="M3 12a9 9 0 1 0 9-9 9.8 9.8 0 0 0-6.7 2.7L3 8"/><path d="M3 3v5h5"/>`,"external-link":`<path d="M15 3h6v6"/><path d="M10 14 21 3"/><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/>`,"ps-launcher":`<path d="M12 21a9 9 0 1 0-8-5L3 21l5-.9A9 9 0 0 0 12 21z"/><path d="M10 9v6l5-3z"/>`,"ps-level-up":`<path d="M3 21h5v-4h5v-4h5V9"/><path d="M18 9V3l4 2.5L18 8"/>`,"ps-guide":`<rect x="4" y="3" width="4" height="18" rx="2"/><path d="M12 5.5v10l7.5-5z"/>`};function o(e,t,...n){let r=document.createElement(e);for(let e in t){let n=t[e];if(n!=null&&n!==!1){if(e[0]==`o`&&e[1]==`n`)r.addEventListener(e.slice(2).toLowerCase(),n);else if(e==`ref`)n(r);else if(e==`style`)for(let e in n)r.style.setProperty(e,n[e]);else r.setAttribute(e,n===!0?``:String(n))}}return s(r,n),r}function s(e,t){for(let n of t)Array.isArray(n)?s(e,n):n!=null&&n!==!1&&e.appendChild(typeof n==`object`?n:document.createTextNode(String(n)))}const c=document.createElement(`template`);function l(e){return c.innerHTML=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${a[e]}</svg>`,c.content.firstChild}const u=(e,...t)=>{e.textContent=``,s(e,t)},d=(e,t={})=>e.replace(/\{(\w+)\}/g,(e,n)=>n in t?String(t[n]):e),f=e=>{let t=Math.round(e/1e3);return`${Math.floor(t/60)}:${String(t%60).padStart(2,`0`)}`},p=e=>e.options.locale??navigator.language??`en`,m=(e,t=e.config.lang)=>(n,r)=>d(e.config.words[t]?.[n]??n,r);function h(e,t){let n=e=>!!e?.getClientRects().length,r=[...document.querySelectorAll(`[data-guide="${CSS.escape(e)}"]`)].find(n)??null;try{r||(r=t?[...document.querySelectorAll(t.css)].find(e=>n(e)&&(!t.text||e.innerText.includes(t.text)))??null:null)}catch{}return n(r)?r:null}function g(e){try{let t=JSON.parse(sessionStorage.getItem(`playstep:clips`)??`[]`);if(t.includes(e))return!1;sessionStorage.setItem(`playstep:clips`,JSON.stringify([...t,e].slice(-200)))}catch{}return!0}function _(e,t,n,r,i,a){(!a||g(`${i}|${r.url}`))&&e.emit({type:i,guide_id:t.id,guide_version:t.version,step_id:t.steps[n].id,step_index:n,clip_id:r.clip_id,clip_source:r.source})}function v(e,t,n,r,i,a,s){let c=m(e,t.lang),d=t.steps[n].title,p=o(`div`,{class:`clip`}),h=!0,g=r.duration_ms??0;if(r.kind==`embed`)return p.className=`clip embed`,u(p,r.poster&&o(`img`,{src:r.poster,alt:``}),o(`button`,{class:`play`,"aria-label":c(`play_video`),onClick:()=>{u(p,o(`iframe`,{src:r.url,title:c(`video`,{title:d}),allow:`autoplay; encrypted-media; picture-in-picture; fullscreen`,allowfullscreen:!0})),_(e,t,n,r,`clip_played`)}},l(`play`)),o(`div`,{class:`bar`},o(`span`,{class:`pill`},l(`external-link`),r.label,g?` · ${f(g)}`:``))),s(0),p;let v=()=>{let i=o(`video`,{src:r.url,poster:r.poster,loop:!0,autoplay:!0,playsinline:!0,preload:`auto`,"aria-label":c(`clip`,{title:d}),onLoadeddata:()=>_(e,t,n,r,`clip_loaded`,!0),onPlaying:()=>_(e,t,n,r,`clip_played`,!0),onLoadedmetadata:()=>{Number.isFinite(i.duration)&&(g=i.duration*1e3,m.textContent=`${f(g)} `,s(g))}});i.muted=!0;let m=o(`span`,null,g?`${f(g)} `:``),v=o(`button`,{class:`round`,"aria-label":c(`unmute_clip`),onClick:()=>{h=!h,i.muted=h,v.setAttribute(`aria-label`,c(h?`unmute_clip`:`mute_clip`)),u(v,l(h?`volume-x`:`volume-2`)),h||_(e,t,n,r,`clip_unmuted`)}},l(`volume-x`)),y=o(`button`,{class:`round`,"aria-label":c(`expand_clip`),"aria-pressed":`false`,onClick:()=>{let e=a.classList.toggle(`big`);y.setAttribute(`aria-label`,c(e?`shrink_clip`:`expand_clip`)),y.setAttribute(`aria-pressed`,String(e))}},l(`maximize-2`));u(p,i,o(`div`,{class:`bar`},o(`span`,{class:`pill`},l(`play`),m,c(`loop`)),v,y)),i.play()?.catch(()=>{}),s(g)};return i?u(p,r.poster&&o(`img`,{src:r.poster,alt:``}),o(`button`,{class:`play`,"aria-label":c(`play_clip`),onClick:v},l(`play`))):v(),p}function y(e,t,n,r,i){let a=t.steps[n],s=t.steps.length,c=m(e,t.lang),d=a.complete_on.type==`next_button`,f=a.media,p=c(`step_of`,{n:n+1,total:s}),h=t.steps.map((e,t)=>o(`span`,{class:`seg${t<n?` done`:t==n?` cur`:``}`})),g=e=>{let t=h[n];t.className=`seg cur${e&&!r?` anim`:``}`,e?t.style.setProperty(`--d`,`${e}ms`):t.style.removeProperty(`--d`)};i.classList.remove(`big`),i.dataset.step=a.id,i.lang=t.lang,t.rtl?i.dir=`rtl`:i.removeAttribute(`dir`),u(i,f?.kind==`image`?o(`div`,{class:`clip img`},o(`img`,{src:f.url,alt:f.label??``,width:f.width,height:f.height})):f&&v(e,t,n,f,r,i,g),o(`div`,{class:`body`},o(`div`,{class:`meta`},o(`span`,null,`${p} · ${t.name}`),o(`button`,{class:`x`,"aria-label":c(`close_guide`),onClick:()=>e.dispatch({type:`dismiss`})},l(`x`))),o(`div`,{class:`steps`,role:`img`,"aria-label":p},h),o(`h2`,{class:`title`,id:`ps-title`},a.title),o(`p`,{class:`text`,id:`ps-text`},a.body)),o(`div`,{class:`foot`},d?o(`span`,{class:`sp`}):o(`span`,{class:`wait`},o(`span`,{class:`pulse`,"aria-hidden":`true`}),c(`waiting`)),a.back&&o(`button`,{class:`btn gho`,onClick:()=>e.dispatch({type:`back`})},c(`back`)),d&&o(`button`,{class:`btn pri`,onClick:()=>e.dispatch({type:`next`})},c(n+1==s?`done`:`next`),l(`arrow-right`))));let y=t.steps[n+1]?.media;if(y&&y.kind!=`embed`&&!r&&!navigator.connection?.saveData){if(y.kind==`image`)new Image().src=y.url;else{let r=document.createElement(`video`);r.preload=`auto`,r.muted=!0,r.src=y.url,y.source==`hosted`&&_(e,t,n+1,y,`clip_loaded`,!0)}}}function b(e,t,n,r,i,a=!1,o=12){let s={bottom:e.bottom+i+n<=innerHeight-o,top:e.top-i-n>=o,left:e.left-i-t>=o,right:e.right+i+t<=innerWidth-o},c=r.find(e=>s[e])??r[0],l=(e,t)=>Math.max(o,Math.min(e,t-o));return c==`top`||c==`bottom`?{x:l(a?e.left:e.left+(e.width-t)/2,innerWidth-t),y:c==`top`?e.top-i-n:e.bottom+i}:{x:c==`left`?e.left-i-t:e.right+i,y:l(e.top+(e.height-n)/2,innerHeight-n)}}var x=/* @__PURE__ */ i({fillEl:()=>u,h:()=>o,icon:()=>l,mount:()=>j,words:()=>m});const S=document.currentScript?.src,C=(e,t,n)=>t?new Promise((n,r)=>document.head.append(Object.assign(document.createElement(`script`),{src:new URL(`${e}.js`,S||location.href).href,integrity:t,crossOrigin:`anonymous`,onload:()=>n(window[`__playstep_${e}`]),onerror:()=>r(Error(e))}))):n(),w=()=>C(`events`,``,()=>import(`./transport-dyLfVpw6.js`)),T=()=>C(`list`,typeof __PLAYSTEP_LIST_INTEGRITY__==`string`?__PLAYSTEP_LIST_INTEGRITY__:``,()=>import(`./list-DJOai7g8.js`)),E=()=>C(`done`,typeof __PLAYSTEP_DONE_INTEGRITY__==`string`?__PLAYSTEP_DONE_INTEGRITY__:``,()=>import(`./done-kxa44syt.js`));function D(e,t,n){let r=m(e),i=e.engine.launcherGuides().filter(t=>!e.engine.progress.guides[t.id]).length;t.className=`lb${e.config.launcher.position==`bottom-left`?` left`:``}`,t.setAttribute(`aria-label`,r(n?`close_guides`:`open_guides`)),t.setAttribute(`aria-expanded`,String(n)),u(t,l(`ps-launcher`),i>0&&!n&&o(`span`,{class:`cnt`},i))}function O(e){let t=location.pathname.split(`/`),n=!0,r=e.split(`/`).map((e,r)=>e==`*`?t[r]||(n=!1,``):e).join(`/`);return n?r:``}const k=(e,t,n,r)=>(e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r));function A(e,t,n){let r=o(`div`,{class:`card`,role:`dialog`,"aria-modal":`false`,"aria-labelledby":`ps-title`,"aria-describedby":`ps-text`,tabindex:`-1`,style:{visibility:`hidden`}}),i=o(`div`,{class:`spot`,"aria-hidden":`true`}),a=o(`div`,{class:`scrim`,"aria-hidden":`true`}),s=!1,c=!1,l,u=-1,d=null,f=[],p=[],m=[],g=!1,_=``,v=``,x,S=e=>e.splice(0).forEach(e=>e()),C=()=>l.steps[u];function w(e,t,a){r.style.transform=`translate(${Math.round(e)}px,${Math.round(t)}px)`,r.style.visibility=``,g||(r.style.transition=`none`,requestAnimationFrame(()=>(g=!0,r.style.transition=``))),s!=!!(d&&a)&&(s=!s,n()),d&&a&&Object.assign(i.style,{width:`${a.w}px`,height:`${a.h}px`,transform:`translate(${a.x}px,${a.y}px)`,borderRadius:`${a.r}px`}),_!=C().id&&(_=C().id,document.hasFocus()&&!document.activeElement?.matches(`input,textarea,select,[contenteditable]:not([contenteditable=false])`)&&r.focus({preventScroll:!0}))}function T(){S(m);let e=r;if(c!=(!d&&l.position==`center`)&&(c=!c,n()),!d){let t=()=>w((innerWidth-e.offsetWidth)/2,l.position==`center`?(innerHeight-e.offsetHeight)/2:innerHeight-e.offsetHeight-24);t();let n=new ResizeObserver(t);n.observe(e),m.push(()=>n.disconnect(),k(window,`resize`,t));return}let i=d,a=i.getBoundingClientRect();(a.bottom<0||a.top>innerHeight)&&i.scrollIntoView({block:`center`,behavior:t?`auto`:`smooth`});let o=()=>{let t=i.getBoundingClientRect(),n=Number.parseFloat(getComputedStyle(i).borderTopLeftRadius)||8,r=C().placement,{x:a,y:o}=b(t,e.offsetWidth,e.offsetHeight,[r==`auto`?`bottom`:r,`top`,`left`,`right`],18);w(a,o,{x:t.left-6,y:t.top-6,w:t.width+12,h:t.height+12,r:Math.min(n+6,(t.height+12)/2)})};o();let s=new ResizeObserver(o);s.observe(i),s.observe(e);let u=setInterval(o,400);m.push(()=>s.disconnect(),()=>clearInterval(u),k(window,`scroll`,o,{capture:!0,passive:!0}),k(window,`resize`,o))}function E(t){d=t,S(p),clearTimeout(x);let n=C();if(t)p.push(k(document,`click`,(r=>{r.composedPath().includes(t)&&(v=``,e.dispatch({type:`tap`,anchor:n.anchor}))}),!0)),t==h(n.anchor,n.find?.web)&&(v=n.id);else if(v==n.id){let t=u;x=setTimeout(()=>{for(let n=t;n--;){let r=l.steps[n];if(!r.anchor||r.complete_on.type==`page`)return;if(h(r.anchor,r.find?.web)){for(let r=t;r-->n;)e.dispatch({type:`back`});return}}},400)}p.push(k(document,`keydown`,(n=>{if(n.key!=`Tab`)return;let i=[...r.querySelectorAll(`button,a,iframe,[tabindex="0"]`)],a=n.composedPath().includes(r),o=i[0],s=i.at(-1),c=e.root.activeElement;a&&!n.shiftKey&&c==s?(n.preventDefault(),(t??o)?.focus()):a&&n.shiftKey&&c==o?(n.preventDefault(),(t??s)?.focus()):t&&document.activeElement==t&&(n.preventDefault(),(n.shiftKey?s:o)?.focus())}),!0)),T()}function D(){S(f);let t=C(),n=t.anchor?h(t.anchor,t.find?.web):null;if(E(n),!t.anchor)return;let r=0,i=()=>{r=0;let e=h(t.anchor,t.find?.web);e!=n&&E(n=e)},a=new MutationObserver(()=>r||(r=requestAnimationFrame(i)));a.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`data-guide`,`hidden`,`style`,`class`]});let o=setTimeout(()=>!n&&e.dispatch({type:`anchor_missing`,anchor:t.anchor}),3e3);f.push(()=>a.disconnect(),()=>clearTimeout(o),()=>cancelAnimationFrame(r))}return{nodes:()=>[s&&i,c&&a,r],get guide(){return l},update(n,i){if(n==l&&i==u)return;let a=!l||i!=u||n.steps[i]?.id!=C().id;l=n,u=i,y(e,n,i,t,r),a?D():T()},stop(){S(f),S(p),S(m),clearTimeout(x)}}}function j(r){let i=r.options,a=e=>void r.outbox.push(e);w().then(({createTransport:t})=>{let n=t({appKey:i.appKey,url:i.eventsUrl,sdk:i.sdkName??`web`,version:e,preview:i.preview,userId:r.userId,locale:()=>p(r),send:i.transport});r.outbox.splice(0).forEach(n.push),a=n.push}).catch(e=>r.emit({type:`sdk_error`,message:String(e)}));let s=r.root;s.appendChild(o(`style`,null,`:host{--ps-radius-md:14px;--ps-radius-lg:20px;--ps-font-display:"Bricolage Grotesque","Figtree",system-ui,sans-serif;--ps-font-sans:"Figtree",system-ui,-apple-system,"Segoe UI",sans-serif;--ps-clip-overlay:rgba(12,14,19,.72);--ps-ease:cubic-bezier(.2,.8,.2,1);--ps-accent:var(--ps-primary);--ps-accent-hover:var(--ps-primary-hover);--ps-on-accent:var(--ps-on-primary);--ps-surface:#fff;--ps-surface-sunken:#f5f6f9;--ps-surface-raised:#fff;--ps-line:#e3e6ec;--ps-ink:#151823;--ps-ink-secondary:#454b5c;--ps-ink-muted:#646b7d;--ps-primary:#2e5bff;--ps-primary-hover:#2149e6;--ps-primary-soft:#e8edff;--ps-primary-ink:#2149e6;--ps-on-primary:#fff;--ps-spark:#ffc933;--ps-spark-soft:#fff4cc;--ps-spark-ink:#7a5a00;--ps-on-spark:#151823;--ps-scrim:rgba(12,14,19,.64);--ps-tag-mint:#ddf5ea;--ps-chart-4:#14b37d;--ps-chart-5:#ff7a59;--ps-shadow-lg:0 20px 48px -12px rgba(21,24,35,.28),0 4px 10px rgba(21,24,35,.06);--ps-ring-focus:0 0 0 2px #fff,0 0 0 4px #2e5bff}:host([data-mode=dark]){--ps-surface:#161922;--ps-surface-sunken:#1d212b;--ps-surface-raised:#222633;--ps-line:#2a2f3c;--ps-ink:#f2f4f8;--ps-ink-secondary:#c5cad5;--ps-ink-muted:#959cad;--ps-primary:#7091ff;--ps-primary-hover:#8da7ff;--ps-primary-soft:#1c2550;--ps-primary-ink:#93abff;--ps-on-primary:#0c0e13;--ps-spark:#ffd452;--ps-spark-soft:#3a2f0a;--ps-spark-ink:#ffd86b;--ps-on-spark:#151823;--ps-scrim:rgba(0,0,0,.72);--ps-tag-mint:#0f2c22;--ps-chart-4:#3dd9a0;--ps-chart-5:#ff9478;--ps-shadow-lg:0 20px 48px -12px rgba(0,0,0,.8),0 4px 10px rgba(0,0,0,.5);--ps-ring-focus:0 0 0 2px #161922,0 0 0 4px #7091ff}:host{all:initial}*{box-sizing:border-box;margin:0}.l{position:fixed;inset:0;pointer-events:none;z-index:2147483000;font:400 14px/20px var(--ps-font-sans);color:var(--ps-ink);-webkit-font-smoothing:antialiased}button{font:inherit;color:inherit;border:0;padding:0;background:none;cursor:pointer}button:focus-visible,a:focus-visible,[tabindex]:focus-visible{outline:none;box-shadow:var(--ps-ring-focus)}svg{width:16px;height:16px;flex:none}.scrim{position:fixed;inset:0;background:var(--ps-scrim);pointer-events:auto}.spot,.card{position:fixed;left:0;top:0;transition:transform .36s var(--ps-ease),width .36s var(--ps-ease),height .36s var(--ps-ease)}.spot{box-shadow:0 0 0 9999px var(--ps-scrim)}.spot:after{content:"";position:absolute;inset:-4px;border-radius:18px;border:2px solid var(--ps-spark);animation:ring 1.8s ease-out infinite}.card,.cel,.panel{background:var(--ps-surface-raised);border-radius:var(--ps-radius-lg);box-shadow:var(--ps-shadow-lg);pointer-events:auto;outline:none}.card{width:336px;max-width:calc(100vw - 24px);padding:10px}.big{width:min(720px,calc(100vw - 24px))}.clip{position:relative;aspect-ratio:16/10;border-radius:var(--ps-radius-md);overflow:hidden;background:var(--ps-surface-sunken)}.clip>video,.clip>img,.clip>iframe{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;border:0}.bar{position:absolute;left:8px;right:8px;bottom:8px;display:flex;align-items:center;gap:6px;color:#fff}.pill,.round{background:var(--ps-clip-overlay);border-radius:99px;display:inline-flex;align-items:center;justify-content:center}.pill{height:24px;padding:0 8px;gap:4px;font:700 11px/1 var(--ps-font-sans)}.pill svg{width:13px;height:13px}.round{width:28px;height:28px}.round svg{width:14px;height:14px}.bar .round:first-of-type{margin-inline-start:auto}[dir=rtl] .btn svg{transform:scaleX(-1)}.img>img{object-fit:contain}.play{position:absolute;inset:0;margin:auto;width:60px;height:60px;border-radius:50%;background:var(--ps-accent);color:var(--ps-on-accent);display:grid;place-items:center}.play svg{width:26px;height:26px}.body{padding:14px 8px 6px}.meta{display:flex;align-items:center;justify-content:space-between;gap:8px;font-size:12px;line-height:16px;font-weight:600;color:var(--ps-ink-muted);margin-bottom:10px}.meta span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.x{width:28px;height:28px;border-radius:50%;display:grid;place-items:center;margin:-6px -6px -6px 0}.x:hover,.gho:hover,.row:hover,.sec:hover{background:var(--ps-surface-sunken);color:var(--ps-ink)}.steps{display:flex;gap:4px;margin-bottom:12px}.seg{flex:1;height:6px;border-radius:99px;background:var(--ps-surface-sunken);overflow:hidden;position:relative}.done{background:var(--ps-accent)}.cur:after{content:"";position:absolute;left:0;top:0;bottom:0;width:55%;border-radius:99px;background:var(--ps-spark)}.anim:after{animation:fill var(--d,4s) linear infinite}.title,.cel h2,.panel h2{font:700 20px/26px var(--ps-font-display);letter-spacing:-.01em;margin-bottom:4px}.text,.cel p{color:var(--ps-ink-secondary)}.foot{display:flex;align-items:center;gap:8px;padding:14px 8px 4px}.wait,.sp{flex:1}.wait{display:flex;align-items:center;gap:8px;font-size:12px;line-height:16px;font-weight:600;color:var(--ps-ink-muted)}.pulse{width:8px;height:8px;border-radius:50%;background:var(--ps-spark);animation:pulse 1.6s ease-out infinite}.btn{height:32px;padding:0 14px;border-radius:var(--ps-radius-btn,99px);border:1px solid transparent;font-size:13px;line-height:18px;font-weight:600;display:inline-flex;align-items:center;gap:6px;white-space:nowrap}.pri{background:var(--ps-accent);color:var(--ps-on-accent)}.pri:hover{background:var(--ps-accent-hover)}.x{color:var(--ps-ink-muted)}.gho{color:var(--ps-ink-secondary)}.embed{background:#151823}.sec{background:var(--ps-surface);border-color:var(--ps-line)}.acts{display:flex;justify-content:center;gap:12px}.lb{position:fixed;bottom:24px;right:24px;width:56px;height:56px;border-radius:50%;background:var(--ps-accent);color:var(--ps-on-accent);box-shadow:var(--ps-shadow-lg);display:grid;place-items:center;pointer-events:auto}.lb svg{width:26px;height:26px}.cnt{position:absolute;top:-2px;right:-2px;min-width:20px;height:20px;padding:0 5px;border-radius:99px;background:var(--ps-spark);color:var(--ps-on-spark);font:800 11px/20px var(--ps-font-sans)}.left{right:auto;left:24px}.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0)}@keyframes ring{to{opacity:0;transform:scale(1.12)}}@keyframes pulse{0%{box-shadow:0 0 0 0 var(--ps-spark)}70%,to{box-shadow:0 0 0 8px transparent}}@keyframes fill{0%{width:0}to{width:100%}}@media (max-width:480px){.card{width:300px}.title{font-size:17px;line-height:22px}.lb{right:18px;bottom:18px}.left{right:auto;left:18px}}@media (prefers-reduced-motion:reduce){.spot,.card{transition:none}.spot:after,.pulse,.cur:after,.tile{animation:none}}`));let c=s.appendChild(o(`div`,{class:`l`})),l=o(`div`,{class:`sr`,"aria-live":`polite`}),u=!1,d,f,g=null,_=o(`button`,{onClick:()=>L(!u)}),v,y,x,S,C=e=>r.emit({type:`sdk_error`,message:String(e)}),j=()=>x??(x=T().then(e=>(v=e,s.appendChild(o(`style`,null,e.css)),z())).catch(C)),M=()=>S??(S=E().then(e=>(y=e,s.appendChild(o(`style`,null,e.css)),z())).catch(C)),N,P=[],F=()=>[l],I,L=e=>{u=e,z()};function R(e){let t=e.filter(Boolean);for(t.forEach((e,t)=>c.childNodes[t]!=e&&c.insertBefore(e,c.childNodes[t]??null));c.childNodes.length>t.length;)c.lastChild.remove()}function z(){let e=r.engine.active,a=e?.guide,p=n(r.config,i.colorMode,a?.mode)?`dark`:`light`;s.host.setAttribute(`data-mode`,p),c.removeAttribute(`style`);for(let[e,t]of Object.entries({...r.config.theme?.[p],...a?.tokens?.[p]}))c.style.setProperty(`--ps-${e}`,t);let h=r.engine.launcherGuides().length>0,x=!!f;u&&h&&v?(f??(f=o(`div`,{tabindex:`-1`,role:`dialog`})),v.drawList(r,f,()=>L(!1))):(f=void 0,u&&h&&j()),h&&D(r,_,u),!u&&e?.status==`running`?N?.guide?.id!=a.id&&(N?.stop(),N=A(r,t(),()=>R(F()))):(N?.stop(),N=void 0),e?.status==`running`&&e.index==a.steps.length-1&&M();let S=!u&&e?.status==`completed`&&!!y;!u&&e?.status==`completed`&&!y&&M();let C=S&&(I!=a||!P.length);if(S?C&&(P=y.drawDone(r,a)):P=[],I=S?a:void 0,l.textContent=e?.status==`running`?`${m(r,a.lang)(`step_of`,{n:e.index+1,total:a.steps.length})}: ${a.steps[e.index].title}`:e?.status==`completed`?m(r,a.lang)(`level_cleared`):``,F=()=>[f,h&&r.config.launcher.enabled&&_,...N?.nodes()??[],...P,l],R(F()),N?.update(a,e.index),f&&!x){if(g=s.activeElement??document.activeElement,d){let{x:e,y:t}=b(d.getBoundingClientRect(),f.offsetWidth,f.offsetHeight,[`top`,`bottom`],8,!0);f.style.cssText=`left:${e}px;top:${t}px;right:auto;bottom:auto`}f.focus()}else!f&&x&&g?.focus();C&&P[1]?.focus()}k(window,`keydown`,(e=>{if(e.key!=`Escape`||e.defaultPrevented||!e.composedPath().includes(s.host))return;let t=r.engine.active;if(u)L(!1);else if(t?.status==`completed`)r.dispatch({type:`close`});else if(t?.status==`running`){let e=t.guide.steps[t.index],n=e.anchor?h(e.anchor,e.find?.web):null;r.dispatch({type:`hide`}),n?.focus({preventScroll:!0})}else return;e.preventDefault(),e.stopPropagation()}),!0);let B=new MutationObserver(()=>z());for(let e of[document.documentElement,document.body])B.observe(e,{attributes:!0});return k(matchMedia(`(prefers-color-scheme: dark)`),`change`,()=>z()),z(),{update:()=>{r.engine.launcherGuides().length||(u=!1),z()},openLauncher:e=>{let t=document.activeElement;d=e??(t!=document.body&&t!=s.host?t??void 0:void 0),L(!0)},send:e=>a(e),start:e=>{let t=r.config.guides.find(t=>t.id==e.guide)?.start_path;try{let n=t&&(i.startPage??O)(t,e.guide)||``;r.dispatch({...e,to:n});let a=r.engine.active;a?.status==`waiting`&&a.guide.id==e.guide&&i.navigate(n)}catch(t){C(t),r.dispatch({...e,to:``})}}}}export{u as fillEl,o as h,l as icon,j as mount,x as t,m as words};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axceera/playstep",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "PlayStep web SDK: playable, video-first guides for any web app. A 3.
|
|
3
|
+
"version": "0.10.0",
|
|
4
|
+
"description": "PlayStep web SDK: playable, video-first guides for any web app. A 3.7 KB loader; the guide UI loads only when a guide shows.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"homepage": "https://playstep.app/docs/sdk/web",
|
|
@@ -20,6 +20,10 @@
|
|
|
20
20
|
"types": "./dist/index.d.ts",
|
|
21
21
|
"import": "./dist/index.js"
|
|
22
22
|
},
|
|
23
|
+
"./plugin": {
|
|
24
|
+
"types": "./dist/plugin.d.ts",
|
|
25
|
+
"import": "./dist/plugin.js"
|
|
26
|
+
},
|
|
23
27
|
"./package.json": "./package.json"
|
|
24
28
|
},
|
|
25
29
|
"files": [
|
|
@@ -39,8 +43,8 @@
|
|
|
39
43
|
"typescript": "~6.0.3",
|
|
40
44
|
"vite": "^8.3.4",
|
|
41
45
|
"vitest": "^4.1.11",
|
|
42
|
-
"@playstep/
|
|
43
|
-
"@playstep/
|
|
46
|
+
"@playstep/spec": "0.1.0",
|
|
47
|
+
"@playstep/design-system": "0.1.0"
|
|
44
48
|
},
|
|
45
49
|
"scripts": {
|
|
46
50
|
"build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsdown && node scripts/cdn.ts",
|
package/dist/capture-NeIia2Wg.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const e=/[\w.+-]+@[\w-]+(?:\.[\w-]+)+/g,t=/\+?\(?\d[\d\s().-]{5,}\d/g,n=/\d{6,}/g,r=/\b(?=[\w-]*\d)[\w-]{24,}\b/g;function i(i){return[e,r,n].some(e=>new RegExp(e.source).test(i))||[...i.matchAll(t)].some(e=>e[0].replace(/\D/g,``).length>=7)}function a(i){if(!i)return``;let a=i.replace(/\s+/g,` `).trim().replace(e,`[email]`).replace(r,`[id]`).replace(t,e=>e.replace(/\D/g,``).length>=7?`[number]`:e).replace(n,`[number]`);return a.length>80?`${a.slice(0,79)}…`:a}function o(e=80){let t=/^(:|radix-|headlessui-|react-|ember\d|mui-|v-|css-|sc-|jsx-)|\d{3,}|[a-f0-9]{8,}|__/i,n=/active|selected|current|open|hover|focus|disabled|hidden|show|visible|checked|loading/i,r=e=>(e??``).replace(/\s+/g,` `).trim().slice(0,80),i=e=>`"${e.replace(/["\\]/g,`\\$&`)}"`,a=e=>CSS.escape(e),o=e=>{try{return document.querySelectorAll(e).length===1}catch{return!1}},s=e=>{let t=e.getBoundingClientRect();if(t.width<1||t.height<1)return!1;let n=getComputedStyle(e);return n.visibility!==`hidden`&&n.display!==`none`&&Number(n.opacity||1)>.05},c=e=>{let t=e.getAttribute(`role`),n=e.tagName,r=(e.getAttribute(`type`)??``).toLowerCase();return t===`tab`||t===`menuitem`||t===`link`||t===`button`?t:t===`checkbox`||t===`switch`||n===`INPUT`&&(r===`checkbox`||r===`radio`)?`checkbox`:n===`A`?`link`:n===`BUTTON`||n===`SUMMARY`||n===`INPUT`&&/^(submit|button|reset|image)$/.test(r)?`button`:n===`SELECT`?`select`:n===`INPUT`||n===`TEXTAREA`?`input`:`other`},l=e=>{let r=e.tagName.toLowerCase(),s=[];e.id&&!t.test(e.id)&&s.push(`#${a(e.id)}`);for(let t of[`data-testid`,`data-test`,`data-cy`,`data-qa`]){let n=e.getAttribute(t);n&&s.push(`[${t}=${i(n)}]`)}for(let t of[`aria-label`,`name`,`title`,`placeholder`]){let n=e.getAttribute(t);n&&n.length<=80&&s.push(`${r}[${t}=${i(n)}]`)}let c=e.getAttribute(`href`);r===`a`&&c&&!/^javascript:/i.test(c)&&c.length<=200&&s.push(`a[href=${i(c)}]`);let l=[...e.classList].filter(e=>/^[a-z][\w-]{1,40}$/i.test(e)&&!t.test(e)&&!n.test(e));l.length&&s.push(`${r}.${l.slice(0,3).map(a).join(`.`)}`);for(let e of s)if(o(e))return e;let u=[],d=e;for(;d&&u.length<7;){if(d===document.body){u.unshift(`body`);break}if(d!==e&&d.id&&!t.test(d.id)){u.unshift(`#${a(d.id)}`);break}let n=d.tagName.toLowerCase(),r=d.parentElement?[...d.parentElement.children].filter(e=>e.tagName===d.tagName):[];u.unshift(r.length>1?`${n}:nth-of-type(${r.indexOf(d)+1})`:n),d=d.parentElement}let f=u.join(`>`);return o(f)?f:void 0},u=e=>{let t=e.getAttribute(`aria-label`)||e.getAttribute(`title`);if(t)return t;let n=e.getAttribute(`aria-labelledby`);if(n)return n.split(/\s+/).map(e=>document.getElementById(e)?.textContent??``).join(` `);let r=e.labels;return r?.length?r[0].innerText:``},d=[...document.querySelectorAll(`a[href],button,input:not([type=hidden]),select,textarea,summary,[role=button],[role=link],[role=tab],[role=menuitem],[role=checkbox],[role=switch],[data-guide]`)].filter(e=>!e.closest(`[data-private],[aria-hidden=true],[inert]`)&&s(e)&&!e.parentElement?.closest(`a[href],button,[role=button],[role=link]`)).map((e,t)=>{let n=e.getBoundingClientRect(),r=n.bottom>0&&n.top<innerHeight;return{e,i:t,score:(e.hasAttribute(`data-guide`)?0:2)+ +!r}}).sort((e,t)=>e.score-t.score||e.i-t.i).slice(0,e).sort((e,t)=>e.i-t.i),f=[];for(let{e}of d){let t=c(e),n=e.getAttribute(`data-guide`),i=t===`input`||t===`select`?``:r(e.innerText||e.textContent),a=r(u(e))||(e.tagName===`INPUT`&&t===`button`?r(e.value):``),o=r(e.getAttribute(`placeholder`)),s=e.getAttribute(`href`),d;if(e.tagName===`A`&&s)try{let e=new URL(s,location.href);e.origin===location.origin&&(d=e.pathname)}catch{}let p=n?void 0:l(e);if(!n&&!p)continue;let m=e.getBoundingClientRect();f.push({ref:`e${f.length+1}`,role:t,...i?{text:i}:{},...a&&a!==i?{label:a}:{},...o?{placeholder:o}:{},...d?{href:d}:{},...n?{anchor:n.slice(0,64)}:{css:p.slice(0,300)},clickable:t!==`input`&&t!==`select`&&t!==`other`,rect:[m.left+scrollX,m.top+scrollY,m.width,m.height].map(Math.round)})}let p=[...document.querySelectorAll(`h1,h2,h3,[role=heading]`)].filter(e=>!e.closest(`[data-private]`)&&s(e)).map(e=>r(e.innerText)).filter(Boolean).slice(0,10);return{platform:`web`,path:location.pathname||`/`,...document.title?{title:r(document.title)}:{},headings:p,viewport:[innerWidth,innerHeight],elements:f}}function s(){let e=document.createElement(`canvas`);e.width=e.height=1;let t=e.getContext(`2d`,{willReadFrequently:!0}),n=e=>{if(!t||!e||e===`transparent`||e===`none`||(t.fillStyle=`#010203`,t.fillStyle=e,t.fillStyle===`#010203`&&!/^#010203$/i.test(e)))return null;t.clearRect(0,0,1,1),t.fillRect(0,0,1,1);let n=t.getImageData(0,0,1,1).data;return[n[0],n[1],n[2],n[3]/255]},r=e=>`#${e.slice(0,3).map(e=>e.toString(16).padStart(2,`0`)).join(``)}`,i=e=>(Math.max(e[0],e[1],e[2])-Math.min(e[0],e[1],e[2]))/255,a=e=>{let[t,n,r]=e.slice(0,3).map(e=>{let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4});return .2126*t+.7152*n+.0722*r},o=(e,t)=>{let r=n(e),i=n(t);return Math.hypot(r[0]-i[0],r[1]-i[1],r[2]-i[2])<30},s=e=>{let t=e.getBoundingClientRect();if(t.width<4||t.height<4||t.bottom<0||t.top>innerHeight*3)return null;let n=getComputedStyle(e);return n.visibility===`hidden`||n.display===`none`||Number(n.opacity||1)<.3?null:{r:t,s:n}},c=e=>{let t=n(e);return t&&t[3]>=.9?t:null},l=e=>e.length?e.sort((e,t)=>e-t)[Math.floor(e.length/2)]:void 0,u=null;for(let e of[document.querySelector(`#root,#app,#__next,[data-reactroot],main`),document.body,document.documentElement])if(u=e?c(getComputedStyle(e).backgroundColor):null,u)break;for(let e=document.elementFromPoint(innerWidth/2,innerHeight/2);!u&&e;e=e.parentElement)u=c(getComputedStyle(e).backgroundColor);u??(u=getComputedStyle(document.documentElement).colorScheme.trim()===`dark`?[18,18,18,1]:[255,255,255,1]);let d=a(u)<.2,f=n(getComputedStyle(document.querySelector(`main`)??document.body).color),p=[],m=(e,t,n)=>{let r=p.find(t=>t.from===n&&o(t.color,e));r?r.weight+=t:p.push({color:e,weight:t,from:n})},h=[],g=document.querySelectorAll(`button,[role=button],input[type=submit],input[type=button],a,[class*=btn],[class*=Btn],[class*=button],[class*=Button]`);for(let e of[...g].slice(0,400)){let t=s(e);if(!t)continue;let o=c(t.s.backgroundColor);if(o&&i(o)>.18&&a(o)>.02&&a(o)<.9){m(r(o),Math.min(t.r.width*t.r.height,3e4),`button`);let e=Number.parseFloat(t.s.borderTopLeftRadius)||0;h.push(e>=t.r.height/2-1?999:e)}else if(e.tagName===`A`){let e=n(t.s.color);e&&i(e)>.25&&m(r(e),400,`link`)}}let _=getComputedStyle(document.documentElement),v=/* @__PURE__ */ new Set,y=0;for(let e of[...document.styleSheets]){let t;try{t=e.cssRules}catch{continue}for(let e of[...t]){if(++y>3e3)break;let t=e.style;if(t&&/:root|html|body|\.light|\[data-theme/.test(e.selectorText??``))for(let e of[...t]){if(!e.startsWith(`--`)||v.has(e)||!/primary|accent|brand/i.test(e)||/foreground|fg|text|contrast|muted|soft|subtle|hover|active|border|ring|shadow|sidebar|chart|50\b|100\b|900\b/i.test(e))continue;v.add(e);let t=_.getPropertyValue(e).trim(),a=n(t)??n(`hsl(${t})`)??n(`rgb(${t})`)??n(`oklch(${t})`);a&&a[3]>=.9&&i(a)>.18&&m(r(a),/^--(color-)?(primary|brand)$/i.test(e)?8e4:4e4,`variable`)}}}let b=n(document.querySelector(`meta[name=theme-color]`)?.getAttribute(`content`));b&&i(b)>.18&&m(r(b),2e4,`theme-color`);let x=[],S=[],C=document.querySelectorAll(`section,article,aside,dialog,[role=dialog],[class*=card],[class*=Card],[class*=panel],[class*=Panel],div`);for(let e of[...C].slice(0,800)){let t=s(e);if(!t||t.r.width*t.r.height<2e4||t.r.width>innerWidth*.95)continue;let n=c(t.s.backgroundColor);if(!n||i(n)>.2||o(r(n),r(u))||a(n)<.2!==d)continue;let l=t.s.boxShadow!==`none`||Number.parseFloat(t.s.borderTopWidth)>0,f=r(n),p=x.find(e=>o(e.color,f)),m=Math.min(t.r.width*t.r.height,2e5)*(l?2:1);p?p.weight+=m:x.push({color:f,weight:m}),l&&S.push(Number.parseFloat(t.s.borderTopLeftRadius)||0)}let w=getComputedStyle(document.body).fontFamily,T=document.querySelector(`h1,h2`),E=T?getComputedStyle(T).fontFamily:void 0;return{scheme:d?`dark`:`light`,background:r(u),...f?{text:r(f)}:{},accents:p.sort((e,t)=>t.weight-e.weight).slice(0,8),surfaces:x.sort((e,t)=>t.weight-e.weight).slice(0,4).map(e=>e.color),...w?{font:w.slice(0,300)}:{},...E&&E!==w?{displayFont:E.slice(0,300)}:{},...h.length?{radius:l(h)}:{},...S.length?{cardRadius:l(S)}:{}}}function c(){try{return s()}catch{return}}const l=`playstep_preview`,u=`playstep_capture_on`,d={get:e=>{try{return sessionStorage.getItem(e)}catch{return null}},set:(e,t)=>{try{t===null?sessionStorage.removeItem(e):sessionStorage.setItem(e,t)}catch{}}};function f(e){let t=e=>e&&a(e)||void 0;return{...e,title:t(e.title),headings:(e.headings??[]).map(e=>a(e)).filter(Boolean),elements:e.elements.map(e=>({...e,text:t(e.text),label:t(e.label),placeholder:t(e.placeholder),href:e.href&&!i(e.href)?e.href:void 0,css:e.css&&!i(e.css)?e.css:void 0})).filter(e=>e.anchor||e.css)}}function p(e,t){let n=document.createElement(`playstep-capture`),r=n.attachShadow({mode:`open`});document.body.appendChild(n);let i=document.createElement(`div`);i.className=`p`,i.setAttribute(`role`,`region`),i.setAttribute(`aria-label`,`PlayStep capture`),r.innerHTML=`<style>:host{all:initial}
|
|
2
|
-
.p{position:fixed;left:24px;bottom:24px;z-index:2147483001;width:320px;max-width:calc(100vw - 48px);box-sizing:border-box;padding:16px;border-radius:16px;background:#fff;color:#151823;font:14px/20px system-ui,-apple-system,"Segoe UI",sans-serif;box-shadow:0 12px 32px #15182333,0 0 0 1px #15182314}
|
|
3
|
-
h2{margin:0 0 4px;font-size:15px;line-height:22px;font-weight:700;display:flex;align-items:center;gap:8px}
|
|
4
|
-
p{margin:0 0 12px;color:#4a5163}
|
|
5
|
-
.dot{width:8px;height:8px;border-radius:50%;background:#e5484d;animation:b 1.6s ease-in-out infinite}
|
|
6
|
-
@keyframes b{50%{opacity:.35}}
|
|
7
|
-
.row{display:flex;gap:8px;flex-wrap:wrap}
|
|
8
|
-
button{font:600 14px/20px inherit;font-family:inherit;border:0;border-radius:999px;padding:8px 14px;cursor:pointer;background:#eef0f5;color:#151823}
|
|
9
|
-
button.go{background:#2e5bff;color:#fff}
|
|
10
|
-
button:focus-visible{outline:2px solid #2e5bff;outline-offset:2px}
|
|
11
|
-
.last{margin:-6px 0 12px;font-size:12px;color:#4a5163;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
12
|
-
@media (prefers-color-scheme:dark){.p{background:#151821;color:#e7e9ee;box-shadow:0 12px 32px #0008,0 0 0 1px #ffffff1a}p,.last{color:#b4bccb}button{background:#262a35;color:#e7e9ee}button.go{background:#4f78ff}}
|
|
13
|
-
@media (prefers-reduced-motion:reduce){.dot{animation:none}}</style>`,r.appendChild(i);let a=0,s=``,p,m=!1,h=(n=``)=>`${e.endpoint}${n}?key=${encodeURIComponent(t)}`,g=(e,t,n=!1)=>{let r=document.createElement(`button`);return r.textContent=e,n&&(r.className=`go`),r.onclick=t,r},_=(e,t,n,r={})=>{i.innerHTML=``;let a=document.createElement(`h2`);r.live&&(a.innerHTML=`<span class="dot" aria-hidden="true"></span>`),a.append(e);let o=document.createElement(`p`);if(o.textContent=t,o.setAttribute(`aria-live`,`polite`),i.append(a,o),r.note){let e=document.createElement(`div`);e.className=`last`,e.textContent=r.note,i.append(e)}let s=document.createElement(`div`);s.className=`row`,s.append(...n),i.append(s)},v=()=>{m=!0,clearTimeout(p),d.set(l,null),d.set(u,null),n.remove()},y=()=>{m=!0,d.set(l,null),d.set(u,null),_(`Capture link expired`,`Get a new link from Generate with AI in PlayStep.`,[g(`Close`,v,!0)])},b=e=>_(`Capturing · ${a} ${a===1?`page`:`pages`}`,`Open the pages your users need help with. Each one is added as you go.`,[g(`Capture this page`,()=>void x()),g(`Finish`,()=>void S(),!0)],{live:!0,note:e});async function x(){if(m)return;clearTimeout(p);let e={...f(o()),style:c()};try{let t=await fetch(h(`/screens`),{method:`POST`,headers:{"content-type":`text/plain`},body:JSON.stringify(e)});if(t.status===404||t.status===410)return y();let n=await t.json().catch(()=>({}));if(!t.ok)return b(n.message??`That page could not be added.`);a=n.screens??a+1,s=location.pathname,b(`Added ${e.title||s}`)}catch{b(`PlayStep could not be reached. It will try again on the next page.`)}}async function S(){m=!0,await fetch(h(`/finish`),{method:`POST`}).catch(()=>void 0),d.set(l,null),d.set(u,null),_(`Capture finished`,`${a} ${a===1?`page`:`pages`} captured. Go back to PlayStep to generate tours.`,[g(`Close`,()=>n.remove(),!0)])}let C=()=>{m||d.get(u)!==`1`||location.pathname===s||(clearTimeout(p),p=setTimeout(()=>void x(),1200))};for(let e of[`pushState`,`replaceState`]){let t=history[e];history[e]=function(...e){t.apply(this,e),C()}}addEventListener(`popstate`,C);let w=()=>{d.set(u,`1`),b(),C()};return d.get(u)===`1`?fetch(h()).then(e=>e.ok?e.json():Promise.reject(e.status)).then(e=>{a=e.screens,w()}).catch(e=>e===404?y():w()):_(`Show PlayStep your app`,`Visit the pages your users need help with. PlayStep notes the buttons, links and headings on each page. Never what you type, and no screenshots.`,[g(`Start capturing`,w,!0),g(`Not now`,v)]),{captureNow:x,stop:v}}export{f as redactScreen,o as snapshotPage,p as start};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./mode-CPlpg1Yl.js";const t=``;function n(t,n,r,i,a){let o=n.launcherGuides();if(!o.length)return;let s=e(r,a.colorMode),c=r.theme?.[s?`dark`:`light`]??{},l=o.filter(e=>!n.progress.guides[e.id]).length;t.innerHTML=`<button aria-label="${r.words[r.lang].open_guides}" style="position:fixed;${r.launcher.position.slice(7)}:24px;bottom:24px;z-index:2147483000;padding:15px;border:0;border-radius:50%;cursor:pointer;background:${c.accent??(s?`#7091ff`:`#2e5bff`)};color:${c[`on-accent`]??(s?`#0c0e13`:`#fff`)};box-shadow:0 8px 24px #0004"><svg width=26 height=26 viewBox="0 0 24 24" fill=none stroke=currentColor stroke-width=2 stroke-linecap=round stroke-linejoin=round><path d="M12 21a9 9 0 1 0-8.05-4.98L3 21l4.98-.95A8.96 8.96 0 0 0 12 21zM10 9v6l5-3z"/></svg>${l?`<b style="position:absolute;top:-2px;right:-2px;padding:0 6px;border-radius:9px;background:#ffc933;color:#151823;font:800 11px/20px sans-serif">${l}</b>`:``}</button>`,t.firstChild.onclick=i}export{t as captureIntegrity,n as drawLauncher};
|
package/dist/sdk-ujPSGL2k.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e}from"./util-X5IoDowG.js";const t=e=>RegExp(`^${e.replace(/[.+?^${}()|[\]\\]/g,`\\$&`).replace(/\*/g,`.*`)}$`),n=e=>e.length>1?e.replace(/\/+$/,``):e;function r(e,r){return!!e&&r!==void 0&&t(n(e)).test(n(r))}function i(e,t){return(e??[]).every(e=>{let n=t[e.trait];return e.op===`exists`?n!=null:e.op===`in`?Array.isArray(e.value)&&e.value.includes(n):n===e.value==(e.op===`eq`)})}function a(e){let t=e.progress??{seen:!1,guides:{}},n=e.traits??{},a=null,o,s=/* @__PURE__ */ new Set,c=/* @__PURE__ */ new Set,l=!1,u=e.config.flags,d=e.config.guides,f=e=>d.find(t=>t.id===e),p=(e,t,n)=>({type:e,guide_id:t.id,guide_version:t.version,...n>=0&&{step_id:t.steps[n].id,step_index:n}}),m=e=>!l&&!u.disabled&&(!u.paused_for_new_users||t.seen)&&i(e.segments,n),h=e=>{let n=t.guides[e.id];return!a&&!s.has(e.id)&&m(e)&&(!n||n.status!==`done`&&(n.status===`running`||!e.trigger.once))},g=(e,n,r)=>{t.guides[e.id]={...t.guides[e.id],version:e.version,step:r,status:n}},_,v=e=>r(e.path,_),y=e=>r(e.skip_if_on,_)||v(e.complete_on),b=e=>!_||r(e.page??`*`,_),x=(e,t,n)=>{for(;t<e.steps.length;){if(a={guide:e,index:t,status:`running`},o=void 0,g(e,`running`,t),n.push(p(`step_shown`,e,t)),!y(e.steps[t]))return n;n.push(p(`step_completed`,e,t++))}return a={guide:e,index:--t,status:`completed`},g(e,`done`,t),n.push(p(`guide_completed`,e)),n},S=(e,n,r=`trigger`)=>(t.seen=!0,c.add(e.id),t.guides[e.id]={source:r},x(e,n,[{...p(`guide_shown`,e),source:r}])),C=()=>{let e=a;return x(e.guide,e.index+1,[p(`step_completed`,e.guide,e.index)])},w=e=>{let t=d.find(t=>h(t)&&e(t));return t?S(t,0):[]},T=e=>e.trigger.type===`first_visit`||v(e.trigger),E=()=>(s.clear(),w(T)),D=(e=T)=>{let n=0,r=d.find(e=>{let r=t.guides[e.id];return n=r?.version===e.version?r.step:0,!a&&r?.status===`running`&&!s.has(e.id)&&m(e)&&b(e.steps[n])});return r?c.has(r.id)?x(r,n,[]):S(r,n,t.guides[r.id].source):w(e)};function O(e){let i=a?.status===`running`?a.guide.steps[a.index]:null,u=l?null:i;switch(e.type){case`init`:return _=e.path,s.clear(),c.clear(),D();case`pause`:return l=!0,[];case`resume`:return l?(l=!1,D()):[];case`page_view`:return _=e.path,!l&&a?.status===`waiting`?S(a.guide,0,a.source):u&&y(u)?C():(i&&!b(i)&&(a=null),D(e=>v(e.trigger)));case`reset_progress`:{let n=typeof e.guide==`string`&&f(e.guide);return n===void 0?[]:((!n||a?.guide===n)&&(a=null),n?delete t.guides[n.id]:t.guides={},[{type:`progress_reset`,...n&&{guide_id:n.id}},...E()])}case`event`:return u?.complete_on.type===`event`&&u.complete_on.name===e.name?C():w(t=>t.trigger.type===`event`&&t.trigger.name===e.name);case`tap`:return u?.complete_on.type===`tap_anchor`&&u.anchor===e.anchor?C():[];case`complete`:return u?.id===e.step?C():[];case`next`:return u?.complete_on.type===`next_button`?C():[];case`back`:return!u||a.index===0?[]:(a={...a,index:a.index-1},g(a.guide,`running`,a.index),[p(`step_shown`,a.guide,a.index)]);case`hide`:return u&&(s.add(a.guide.id),a=null),[];case`close`:if(a?.status!==`completed`)return[];case`dismiss`:{let e=a;return a=null,i?(g(e.guide,`dismissed`,e.index),[p(`guide_dismissed`,e.guide,e.index)]):[]}case`start`:{let t=f(e.guide);if(!t||!m(t)||u&&a.guide===t&&t.steps.slice(0,a.index).every(y))return[];let n=e.source??`api`;return e.to&&!r(t.start_path,_)?(a={guide:t,index:0,status:`waiting`,source:n},[]):S(t,0,n)}case`anchor_missing`:return!u||u.anchor!==e.anchor||o===e.anchor?[]:(o=e.anchor,[{...p(`anchor_missing`,a.guide,a.index),anchor:e.anchor}]);case`identify`:return n={...n,...e.traits},[]}}return{get active(){return l?null:a},progress:t,dispatch:O,launcherGuides:()=>d.filter(e=>e.launcher&&m(e)),use(e){d=e.guides,a&&(a={...a,guide:f(a.guide.id)??a.guide})}}}const o=`0.9.0`,s=`playstep_preview`;function c(t,n,r){let i,c,l,u,d,f,p,m,h={},g=!1,_,v=[],y=[],b=()=>`p:${i.appKey}`,x=()=>i.preview||e.set(b(),c.progress),S=e=>{let t={...e,ts:Date.now()};i?.preview||(d?d.send(t):y.push(t)),i?.onEvent?.(t)},C=e=>{try{S({type:`sdk_error`,message:String(e)})}catch{}},w=e=>(...t)=>{try{e(...t)}catch(e){C(e)}},T=(e,t)=>w(n=>E({type:e,[t]:n}));function E(t){if(!c)return void v.push(t);if(t.type==`start`&&t.to===void 0&&i.navigate)return void O().then(e=>e?.start(t));let n=c.dispatch(t);x(),n.forEach(w(S)),(c.active||e.get(`q`))&&O(),d?.update()}function D(){return p??(p=document.body.appendChild(document.createElement(`playstep-root`)).attachShadow({mode:`open`}))}function O(){return f??(f=t().then(e=>{let t=D();return t.innerHTML=``,d=e.mount({engine:c,get config(){return l},options:i,root:t,outbox:y,userId:()=>m,dispatch:w(E),emit:w(S)})}).catch(C))}let k,A=w((e={})=>{c?c.launcherGuides().length&&O().then(t=>t?.openLauncher(e.anchor)):k=e});function j(e){e.launcher?.enabled&&c.launcherGuides().length&&!f&&n&&n().then(t=>{f||t.drawLauncher(D(),c,e,A,i)}).catch(C)}let M=e=>w(()=>{g!==e&&(g=e,c&&(E({type:e?`pause`:`resume`}),!f&&(e?p&&(p.innerHTML=``):j(l))))});async function N(){let t=i,n=(t.apiBase??`https://cdn.playstep.app`).replace(/\/$/,``),o=null;try{o=new URLSearchParams(location.search).get(s)||(t.config?null:sessionStorage.getItem(s))}catch{}t.preview||(t.preview=!!(t.config||o)),u=e=>fetch(`${n}/v2/${o?`preview/${o}?key=${t.appKey}&`:`config/${t.appKey}?`}l=${e}`).then(e=>e.json());let d=t.config;try{d??(d=await u(t.locale??navigator.language??``))}catch{return}try{o&&sessionStorage[d.guides?`setItem`:`removeItem`](s,o)}catch{}if(d?.capture)return void r?.().then(e=>e.start(d.capture,t.appKey)).catch(C);if(d?.guides&&!d.flags?.disabled&&(l=d,t.eventsUrl=d.ingest_url??`${n}/v1/events`,c=a({config:d,progress:t.preview?void 0:e.get(b()),traits:h}),g&&c.dispatch({type:`pause`}),E({type:`init`,path:location.pathname}),v.splice(0).forEach(E),k&&A(k),j(d),t.autoPageViews!==!1)){let e=location.pathname,t=w(()=>location.pathname!==e&&E({type:`page_view`,path:e=location.pathname}));for(let e of[`pushState`,`replaceState`]){let n=history[e];history[e]=function(...e){n.apply(this,e),t()}}addEventListener(`popstate`,t)}}return{version:o,init:w(e=>{if(i||!e?.appKey)return;i={...e},_&&(i.locale=_);let t=()=>setTimeout(()=>N().catch(C));document.readyState===`complete`?t():addEventListener(`load`,t)}),identify:w((e,t)=>{m=e,h={...h,...t},E({type:`identify`,traits:h})}),track:T(`event`,`name`),start:T(`start`,`guide`),complete:T(`complete`,`step`),page:w(e=>E({type:`page_view`,path:e??location.pathname})),openLauncher:A,resetProgress:T(`reset_progress`,`guide`),reset:w(()=>{E({type:`dismiss`}),m=void 0,h={},c&&(Object.assign(c.progress,{seen:!1,guides:{}}),x(),d?.update()),i?.preview||e.set(`d`,null)}),pause:M(!0),resume:M(!1),isPaused:()=>g,setLocale:w(e=>{_=e,i&&(i.locale=e),u?.(e).then(t=>{t.guides&&i?.locale==e&&(c.use(l=t),d?.update())}).catch(C)})}}export{c as n,o as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e}from"./util-X5IoDowG.js";const t=`playstep:q`,n=(e,t)=>fetch(e,{method:`POST`,body:t,keepalive:!0,headers:{"content-type":`text/plain`}}).then(e=>({status:e.status,retryAfter:Number(e.headers.get(`retry-after`))||void 0}),()=>({status:0})),r={read(e){try{return JSON.parse(localStorage.getItem(e))??[]}catch{return[]}},write(e,n){try{n.length?localStorage.setItem(e,JSON.stringify(n)):localStorage.removeItem(e);let r=!1;for(let e=0;e<localStorage.length;e++)r||(r=!!localStorage.key(e)?.startsWith(`playstep:q:`));r?localStorage.setItem(t,`1`):localStorage.removeItem(t)}catch{}}};function i(e){let t=[],i=[],a=[],o,s,c=0,l=!1,u=`${e.storageKey}:${Math.random().toString(36).slice(2,10)}`,d=()=>r.write(u,[...a,...i]),f=async t=>await e.send?.(e.url,t)??(e.send?{status:204}:n(e.url,t));try{for(let t=localStorage.length-1;t>=0;t--){let n=localStorage.key(t);n?.startsWith(`${e.storageKey}:`)&&(i.push(...r.read(n).filter(e=>Date.now()-e.t<6048e5)),localStorage.removeItem(n))}}catch{}i=i.sort((e,t)=>e.t-t.t).slice(-25),d();async function p(){if(!(l||s)){l=!0;try{for(;i.length;){let e=await f(i[0].b);if(e.status===0||e.status===408||e.status===429||e.status>=500){c=Math.min(6e4,c*2||2e3),s=setTimeout(()=>{s=void 0,p()},Math.max(c,(e.retryAfter??0)*1e3));break}c=0,i.shift(),d()}}finally{l=!1}}}function m(r=!1){clearTimeout(o),o=void 0;let s=t.length?e.envelope():null;if(s){for(;t.length;)i.push({b:JSON.stringify({...s,events:t.splice(0,20)}),t:Date.now()});i=i.slice(-25),d()}if(!r)return void p();for(let t of i.splice(0))e.send?f(t.b):navigator.sendBeacon?.(e.url,t.b)||n(e.url,t.b),a.push(t);a=a.slice(-25),d()}return addEventListener(`visibilitychange`,()=>document.visibilityState===`hidden`&&m(!0)),addEventListener(`pagehide`,()=>m(!0)),i.length&&p(),{push(n){t.push(n),t.length>=20?m():o??(o=setTimeout(m,e.delayMs??2e3))},flush:()=>m(),get size(){return t.length},get pending(){return i.length}}}const a=[];for(let e=2;a.length<64;e++){let t=!0;for(let n=2;n*n<=e;n++)e%n===0&&(t=!1);t&&a.push(Math.cbrt(e)%1*2**32|0)}const o=(e,t)=>e>>>t|e<<32-t;function s(e){let t=new TextEncoder().encode(e),n=t.length,r=new Uint32Array((n+8>>6)*16+16);for(let e=0;e<n;e++)r[e>>2]|=t[e]<<24-e%4*8;r[n>>2]|=128<<24-n%4*8,r[r.length-1]=n*8,r[r.length-2]=Math.floor(n/536870912);let i=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],s=/* @__PURE__ */ new Uint32Array(64);for(let e=0;e<r.length;e+=16){for(let t=0;t<64;t++)if(t<16)s[t]=r[e+t];else{let e=s[t-15],n=s[t-2];s[t]=s[t-16]+(o(e,7)^o(e,18)^e>>>3)+s[t-7]+(o(n,17)^o(n,19)^n>>>10)}let[t,n,c,l,u,d,f,p]=i;for(let e=0;e<64;e++){let r=p+(o(u,6)^o(u,11)^o(u,25))+(u&d^~u&f)+a[e]+s[e]|0,i=(o(t,2)^o(t,13)^o(t,22))+(t&n^t&c^n&c)|0;p=f,f=d,d=u,u=l+r|0,l=c,c=n,n=t,t=r+i|0}[t,n,c,l,u,d,f,p].forEach((e,t)=>i[t]=i[t]+e|0)}return i.map(e=>(e>>>0).toString(16).padStart(8,`0`)).join(``)}const c=e=>e+(crypto.randomUUID?crypto.randomUUID().replace(/-/g,``):Math.random().toString(36).slice(2)+Date.now().toString(36));function l(){try{let e=sessionStorage.getItem(`playstep:s`);return e||sessionStorage.setItem(`playstep:s`,e=c(`s_`)),e}catch{return c(`s_`)}}function u(t){let n=l(),r=e.get(`d`);r||e.set(`d`,r=c(`d_`));let a,o=r,u=i({url:t.url,send:t.send,storageKey:`playstep:q:${t.appKey}`,envelope:()=>{let e=t.userId()||void 0;return e!==a&&(a=e,o=e?`u_${s(`${t.appKey}:${e}`).slice(0,40)}`:r),{key:t.appKey,sdk:{name:t.sdk,version:t.version},session_id:n,user_key:o,preview:t.preview,locale:t.locale()}}});return{session:n,push:e=>u.push({...e,id:e.id??c(`e`).slice(0,25),...e.message?{message:e.message.slice(0,300)}:{}}),flush:u.flush}}export{u as createTransport,c as randomId,l as sessionId};
|