story_player 0.1.1

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.
@@ -0,0 +1,168 @@
1
+ () => {
2
+ const hidden = "[hidden], [aria-hidden=true], [inert]"
3
+ const controls = new Set([
4
+ "button", "checkbox", "combobox", "link", "listbox", "menuitem", "menuitemcheckbox",
5
+ "menuitemradio", "radio", "searchbox", "slider", "spinbutton", "switch", "tab", "textbox"
6
+ ])
7
+ const landmarks = new Set([
8
+ "banner", "complementary", "contentinfo", "dialog", "form", "group", "main", "navigation",
9
+ "region", "search", "table"
10
+ ])
11
+ const namedByContents = new Set([
12
+ "button", "checkbox", "heading", "link", "menuitem", "menuitemcheckbox", "menuitemradio",
13
+ "option", "radio", "switch", "tab", "treeitem"
14
+ ])
15
+ const nativeRoles = {
16
+ aside: "complementary", button: "button", details: "group", dialog: "dialog", fieldset: "group",
17
+ h1: "heading", h2: "heading", h3: "heading", h4: "heading", h5: "heading", h6: "heading",
18
+ img: "img", main: "main", nav: "navigation", option: "option", p: "paragraph",
19
+ search: "search", summary: "button", table: "table", textarea: "textbox"
20
+ }
21
+ const inputRoles = {
22
+ button: "button", checkbox: "checkbox", image: "button", number: "spinbutton", radio: "radio",
23
+ range: "slider", reset: "button", search: "searchbox", submit: "button"
24
+ }
25
+ const possibleTargets = [...Object.keys(nativeRoles), "a[href]", "area[href]", "form", "section",
26
+ "header", "footer", "input", "select", "[role]"].join(", ")
27
+ const knownRoles = new Set([...controls, ...landmarks, ...Object.values(nativeRoles),
28
+ "alert", "alertdialog", "article", "cell", "columnheader", "grid", "gridcell", "list", "listitem",
29
+ "log", "menu", "menubar", "meter", "progressbar", "row", "rowgroup", "rowheader", "status",
30
+ "tabpanel", "toolbar", "tree", "treegrid", "treeitem"
31
+ ])
32
+ let roleIndex
33
+ const namesByRole = new Map()
34
+ const semanticText = value => (value || "").replace(/\s+/g, " ").trim().slice(0, 160)
35
+
36
+ function text(element, includeHidden = false) {
37
+ const walker = document.createTreeWalker(element, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT, {
38
+ acceptNode(node) {
39
+ if (node.nodeType === Node.TEXT_NODE) return NodeFilter.FILTER_ACCEPT
40
+ if (!includeHidden && node.matches(hidden)) return NodeFilter.FILTER_REJECT
41
+ if (node.matches("img, svg")) return NodeFilter.FILTER_ACCEPT
42
+ if (node.matches("input, select, textarea, script, style, template")) return NodeFilter.FILTER_REJECT
43
+ return NodeFilter.FILTER_SKIP
44
+ }
45
+ })
46
+ let value = ""
47
+ for (let node = walker.nextNode(); node && value.length < 320; node = walker.nextNode()) {
48
+ if (node.parentElement?.closest("svg") && node.localName !== "svg") continue
49
+ if (node.nodeType === Node.TEXT_NODE) value += node.nodeValue
50
+ else value += node.getAttribute("alt") || node.getAttribute("aria-label") || node.querySelector("title")?.textContent || ""
51
+ }
52
+ return semanticText(value)
53
+ }
54
+
55
+ function authoredName(element) {
56
+ const references = element.getAttribute("aria-labelledby")?.trim().split(/\s+/).slice(0, 8) || []
57
+ const referencedName = references.map(id => {
58
+ const reference = element.getRootNode().getElementById?.(id)
59
+ if (reference) return semanticText(reference.getAttribute("aria-label")) || text(reference, true)
60
+ return ""
61
+ }).join(" ")
62
+ return semanticText(referencedName) || semanticText(element.getAttribute("aria-label"))
63
+ }
64
+
65
+ function role(element) {
66
+ const explicit = element.getAttribute("role")?.trim().split(/\s+/)
67
+ .find(value => knownRoles.has(value) || ["none", "presentation", "generic"].includes(value))
68
+ if (["none", "presentation", "generic"].includes(explicit)) return "generic"
69
+ if (explicit) return explicit
70
+
71
+ switch (element.localName) {
72
+ case "a": case "area": return element.hasAttribute("href") ? "link" : "generic"
73
+ case "form": case "section": {
74
+ const named = authoredName(element) || element.getAttribute("title")
75
+ if (named) return element.localName === "form" ? "form" : "region"
76
+ return "generic"
77
+ }
78
+ case "header": case "footer": {
79
+ if (element.parentElement?.closest("article, aside, main, nav, section")) return "generic"
80
+ return element.localName === "header" ? "banner" : "contentinfo"
81
+ }
82
+ case "input":
83
+ if (["hidden", "password", "file", "color", "date", "time", "datetime-local", "month", "week"].includes(element.type)) return "generic"
84
+ if (element.list && ["email", "search", "tel", "text", "url"].includes(element.type)) return "combobox"
85
+ return inputRoles[element.type] || "textbox"
86
+ case "select": return element.multiple || element.size > 1 ? "listbox" : "combobox"
87
+ default: return nativeRoles[element.localName] || "generic"
88
+ }
89
+ }
90
+
91
+ function name(element, elementRole) {
92
+ if (["generic", "paragraph"].includes(elementRole)) return ""
93
+ const authored = authoredName(element)
94
+ if (authored) return authored
95
+ const labels = [...(element.labels || [])].map(label => text(label)).join(" ")
96
+ if (labels.trim()) return semanticText(labels)
97
+ if (element.localName === "img" || element.type === "image") {
98
+ return semanticText(element.getAttribute("alt") || element.getAttribute("title"))
99
+ }
100
+ if (element.localName === "input" && ["button", "submit", "reset"].includes(element.type)) {
101
+ return semanticText(element.getAttribute("value") || ({submit: "Submit", reset: "Reset"})[element.type])
102
+ }
103
+ if (["fieldset", "table"].includes(element.localName)) {
104
+ const caption = element.querySelector(":scope > legend, :scope > caption")
105
+ if (caption) return text(caption)
106
+ }
107
+ const contents = namedByContents.has(elementRole) ? text(element) : ""
108
+ return contents || semanticText(element.getAttribute("title"))
109
+ }
110
+
111
+ function path(element, elementRole = role(element), elementName = name(element, elementRole)) {
112
+ const trail = [{ role: elementRole, name: elementName }]
113
+ for (let node = element.parentElement; node && trail.length < 8; node = node.parentElement) {
114
+ const ancestorRole = role(node)
115
+ if (!landmarks.has(ancestorRole)) continue
116
+ const ancestorName = name(node, ancestorRole)
117
+ if (ancestorName || ["main", "navigation", "dialog"].includes(ancestorRole)) {
118
+ trail.unshift({ role: ancestorRole, name: ancestorName })
119
+ }
120
+ }
121
+ return trail
122
+ }
123
+
124
+ function candidates(elementRole, elementName) {
125
+ if (!roleIndex) {
126
+ roleIndex = new Map()
127
+ for (const element of document.querySelectorAll(possibleTargets)) {
128
+ const candidateRole = role(element)
129
+ if (!roleIndex.has(candidateRole)) roleIndex.set(candidateRole, [])
130
+ roleIndex.get(candidateRole).push(element)
131
+ }
132
+ }
133
+ if (!namesByRole.has(elementRole)) {
134
+ const names = new Map()
135
+ for (const element of roleIndex.get(elementRole) || []) {
136
+ if (element.closest(hidden)) continue
137
+ const label = name(element, elementRole)
138
+ if (!label) continue
139
+ if (!names.has(label)) names.set(label, [])
140
+ names.get(label).push(element)
141
+ }
142
+ namesByRole.set(elementRole, names)
143
+ }
144
+ return namesByRole.get(elementRole).get(elementName) || []
145
+ }
146
+
147
+ function matching(targetPath) {
148
+ const last = Array.isArray(targetPath) && targetPath.at(-1)
149
+ if (!last?.name || last.role === "generic") return []
150
+ const matches = []
151
+ for (const candidate of candidates(last.role, last.name)) {
152
+ const trail = path(candidate, last.role, last.name)
153
+ if (trail.length !== targetPath.length || !trail.every((segment, index) =>
154
+ segment.role === targetPath[index]?.role && segment.name === targetPath[index]?.name)) continue
155
+ if (!candidate.getClientRects().length || getComputedStyle(candidate).visibility !== "visible") continue
156
+ matches.push(candidate)
157
+ if (matches.length === 2) break
158
+ }
159
+ return matches
160
+ }
161
+
162
+ const invalidate = () => {
163
+ roleIndex = undefined
164
+ namesByRole.clear()
165
+ }
166
+
167
+ return { controls, matching, path, invalidate }
168
+ }
@@ -0,0 +1,229 @@
1
+ :host {
2
+ all: initial;
3
+ position: fixed;
4
+ inset: 0;
5
+ z-index: 2147483646;
6
+ pointer-events: none;
7
+ color-scheme: light dark;
8
+ --note-paper: light-dark(#fff3bd, #433619);
9
+ --note-ink: light-dark(#33290f, #fff2c7);
10
+ --note-muted: light-dark(#655629, #ded09d);
11
+ --note-edge: light-dark(#d4bf75, #8d783e);
12
+ --note-tint: light-dark(#59461112, #fff2c71a);
13
+ --note-focus: light-dark(#70551a, #f5d77f);
14
+ --demo-controls-height: 0px;
15
+ font: 13px / 1.35 system-ui, sans-serif;
16
+ }
17
+
18
+ [hidden] { display: none !important; }
19
+
20
+ .launcher, .picker, .highlight, .pin, dialog {
21
+ position: fixed;
22
+ z-index: 2147483647;
23
+ }
24
+
25
+ .launcher {
26
+ inset: auto auto calc(var(--demo-controls-height) + 24px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
27
+ }
28
+
29
+ .picker {
30
+ inset: auto auto calc(var(--demo-controls-height) + 56px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
31
+ }
32
+
33
+ .launcher, .picker, .pin, dialog {
34
+ pointer-events: auto;
35
+ background: var(--note-paper);
36
+ color: var(--note-ink);
37
+ border: 1px solid var(--note-edge);
38
+ box-shadow: 0 2px 10px rgb(0 0 0 / 18%);
39
+ box-sizing: border-box;
40
+ }
41
+
42
+ .launcher, .pin {
43
+ display: grid;
44
+ place-items: center;
45
+ border-radius: 50%;
46
+ padding: 0;
47
+ }
48
+
49
+ .launcher {
50
+ inline-size: 28px;
51
+ block-size: 28px;
52
+ }
53
+
54
+ .pin {
55
+ z-index: 2147483646;
56
+ inline-size: 24px;
57
+ block-size: 24px;
58
+ margin: 0;
59
+ font-size: 11px;
60
+ font-weight: 650;
61
+ line-height: 1;
62
+ transform: translate(-50%, -50%);
63
+ cursor: pointer;
64
+ }
65
+
66
+ .pin[data-active] {
67
+ background: var(--note-ink);
68
+ color: var(--note-paper);
69
+ border-color: var(--note-focus);
70
+ }
71
+
72
+ .picker {
73
+ display: flex;
74
+ flex-wrap: wrap;
75
+ align-items: center;
76
+ gap: 4px 8px;
77
+ max-inline-size: calc(100vw - 24px);
78
+ border-radius: 6px;
79
+ padding: 3px 8px;
80
+ font-size: 12px;
81
+ }
82
+
83
+ .highlight {
84
+ outline: 2px solid var(--note-focus);
85
+ box-shadow: inset 0 0 0 1px Canvas;
86
+ pointer-events: none;
87
+ }
88
+
89
+ dialog {
90
+ inset: auto auto calc(var(--demo-controls-height) + 60px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
91
+ inline-size: min(264px, calc(100vw - 24px));
92
+ max-block-size: min(360px, calc(100dvh - var(--demo-controls-height) - 76px));
93
+ margin: 0;
94
+ padding: 0;
95
+ overflow: auto;
96
+ border-radius: 8px;
97
+ }
98
+
99
+ dialog[data-anchored] {
100
+ inset: var(--note-y) auto auto var(--note-x);
101
+ }
102
+
103
+ header, .actions {
104
+ display: flex;
105
+ align-items: center;
106
+ justify-content: space-between;
107
+ gap: 4px;
108
+ }
109
+
110
+ header {
111
+ background: var(--note-tint);
112
+ border-block-end: 1px solid var(--note-edge);
113
+ padding-inline: 10px 4px;
114
+ }
115
+
116
+ h2 {
117
+ font-size: 13px;
118
+ font-weight: 650;
119
+ margin: 0;
120
+ }
121
+
122
+ form, .status, details { margin: 0 8px; }
123
+ form { padding-block-start: 4px; }
124
+
125
+ textarea, button, summary {
126
+ box-sizing: border-box;
127
+ color: inherit;
128
+ font: inherit;
129
+ }
130
+
131
+ textarea {
132
+ display: block;
133
+ inline-size: 100%;
134
+ min-block-size: 44px;
135
+ max-block-size: 140px;
136
+ resize: vertical;
137
+ background: transparent;
138
+ border: 1px solid var(--note-edge);
139
+ border-radius: 4px;
140
+ padding: 4px;
141
+ }
142
+
143
+ textarea:focus { outline: 1px solid var(--note-focus); }
144
+
145
+ button {
146
+ border: 1px solid transparent;
147
+ border-radius: 5px;
148
+ background: transparent;
149
+ cursor: pointer;
150
+ padding: 2px 5px;
151
+ }
152
+
153
+ header button, .actions button, [data-clear], .targeting-warning {
154
+ display: grid;
155
+ place-items: center;
156
+ inline-size: 24px;
157
+ block-size: 24px;
158
+ padding: 0;
159
+ }
160
+
161
+ button:hover, .launcher[aria-expanded="true"], .pin:hover { background: var(--note-tint); }
162
+ .launcher:hover, .launcher[aria-expanded="true"], .pin:hover, .pin[data-active] {
163
+ border-color: var(--note-focus);
164
+ }
165
+
166
+ .launcher:hover, .launcher[aria-expanded="true"] {
167
+ background: var(--note-paper);
168
+ }
169
+
170
+ button:disabled { opacity: 0.55; cursor: wait; }
171
+ button:focus-visible, summary:focus-visible { outline: 2px solid var(--note-focus); outline-offset: -2px; }
172
+
173
+ .actions { padding-block: 2px; }
174
+ .actions .primary {
175
+ margin-inline-start: auto;
176
+ background: var(--note-ink);
177
+ color: var(--note-paper);
178
+ border-radius: 50%;
179
+ }
180
+ .actions .primary:hover:not(:disabled) { background: var(--note-focus); color: var(--note-paper); }
181
+
182
+ .reference {
183
+ display: flex;
184
+ align-items: flex-start;
185
+ gap: 4px;
186
+ margin: 0 0 4px;
187
+ color: var(--note-muted);
188
+ font-size: 12px;
189
+ }
190
+
191
+ .reference-content { flex: 1; min-inline-size: 0; }
192
+ .reference-label { overflow-wrap: anywhere; }
193
+ [data-clear] { flex-shrink: 0; }
194
+ .comment-label { display: block; margin: 5px 0 2px; padding-inline: 4px; font-size: 12px; }
195
+
196
+ .status, summary, time { font-size: 12px; color: var(--note-muted); }
197
+ .status { padding: 0 4px 6px; }
198
+ .status:empty { display: none; }
199
+
200
+ summary {
201
+ cursor: pointer;
202
+ border-block-start: 1px solid var(--note-edge);
203
+ padding: 5px 4px;
204
+ }
205
+
206
+ ol { list-style: none; margin: 0; padding: 0 4px; }
207
+ li { border-block-start: 1px solid var(--note-edge); padding: 6px 0; }
208
+ li p { white-space: pre-wrap; overflow-wrap: anywhere; margin: 2px 0; }
209
+ li button { text-align: start; overflow-wrap: anywhere; max-inline-size: 100%; }
210
+
211
+ .targeting {
212
+ display: grid;
213
+ grid-template-columns: minmax(0, 1fr) auto;
214
+ align-items: start;
215
+ gap: 4px;
216
+ color: var(--note-muted);
217
+ font-size: 12px;
218
+ }
219
+ .targeting p { margin: 2px 0 0; overflow-wrap: anywhere; }
220
+ .targeting .breadcrumb { grid-column: 1; }
221
+ .targeting-warning {
222
+ grid-column: 2;
223
+ border-color: var(--note-edge);
224
+ color: var(--note-focus);
225
+ }
226
+ .targeting-warning:hover, .targeting-warning[aria-expanded="true"] { background: var(--note-tint); border-color: var(--note-focus); }
227
+ .targeting ul { grid-column: 1 / -1; margin: 2px 0 6px; padding-inline-start: 16px; }
228
+ .targeting li { padding: 0; border: 0; }
229
+ details .targeting { margin-inline: 4px; }