@pathmx/player 0.5.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/LICENSE +43 -0
- package/LICENSE.md +172 -0
- package/README.md +161 -0
- package/actions.ts +69 -0
- package/client.ts +1047 -0
- package/controls.tsx +716 -0
- package/fragments.ts +6 -0
- package/gestures.ts +143 -0
- package/grid.ts +199 -0
- package/guide.ts +86 -0
- package/index.ts +59 -0
- package/keyboard.ts +172 -0
- package/media.ts +47 -0
- package/navigation.ts +97 -0
- package/notes.css +65 -0
- package/notes.ts +10 -0
- package/package.json +32 -0
- package/play.css +1052 -0
- package/preferences.ts +71 -0
- package/progress.tsx +70 -0
- package/ref/deckset-exports/Letters from Sweden.dstheme +1 -0
- package/ref/deckset-exports/Merriweather.dstheme +1 -0
- package/ref/deckset-exports/Next.dstheme +1 -0
- package/route.ts +231 -0
- package/scroll.ts +276 -0
- package/themes.ts +39 -0
- package/variants.ts +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Lucide Icons and Contributors
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
The following Lucide icons are derived from the Feather project:
|
|
20
|
+
|
|
21
|
+
chevron-down, chevron-up, external-link, play, x
|
|
22
|
+
|
|
23
|
+
The MIT License (MIT) (for the icons listed above)
|
|
24
|
+
|
|
25
|
+
Copyright (c) 2013-present Cole Bemis
|
|
26
|
+
|
|
27
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
28
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
29
|
+
in the Software without restriction, including without limitation the rights
|
|
30
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
31
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
32
|
+
furnished to do so, subject to the following conditions:
|
|
33
|
+
|
|
34
|
+
The above copyright notice and this permission notice shall be included in all
|
|
35
|
+
copies or substantial portions of the Software.
|
|
36
|
+
|
|
37
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
38
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
39
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
40
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
41
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
42
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
43
|
+
SOFTWARE.
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# PathMX Proprietary Beta License
|
|
2
|
+
|
|
3
|
+
Version 0.1 — July 21, 2026
|
|
4
|
+
|
|
5
|
+
Copyright © 2026 DUO Interactive, LLC.
|
|
6
|
+
All rights reserved.
|
|
7
|
+
|
|
8
|
+
This license governs the first-party PathMX software distributed in the npm
|
|
9
|
+
package `@pathmx/core`, including its command-line interface, bundled
|
|
10
|
+
library surfaces, runtime and Player components, and accompanying
|
|
11
|
+
documentation (the “Software”). DUO Interactive, LLC is the “Licensor.” This
|
|
12
|
+
license does not cover the private PathMX source-code repository or separately
|
|
13
|
+
identified third-party materials.
|
|
14
|
+
|
|
15
|
+
“Project” means Paths, Sources, responses, data, and other content authored or
|
|
16
|
+
processed with the Software.
|
|
17
|
+
|
|
18
|
+
“Application” means software or a service created by you in which the Software
|
|
19
|
+
supports product-specific functionality but is not itself offered as a
|
|
20
|
+
general-purpose PathMX product.
|
|
21
|
+
|
|
22
|
+
“Redistributable Components” means runtime, Player, or library portions of the
|
|
23
|
+
Software incorporated into a Project, Application, or generated output through
|
|
24
|
+
ordinary use of the Software or ordinary compilation and bundling tools.
|
|
25
|
+
|
|
26
|
+
“Authorized Users” means your employees and individual contractors who use the
|
|
27
|
+
Software on your behalf, and your hosting, continuous-integration, and other
|
|
28
|
+
service providers that possess or run necessary copies solely to provide
|
|
29
|
+
services to you.
|
|
30
|
+
|
|
31
|
+
## 1. Agreement
|
|
32
|
+
|
|
33
|
+
By installing, accessing, or using the Software, you agree to this license. If
|
|
34
|
+
you use the Software on behalf of an organization, you represent that you have
|
|
35
|
+
authority to accept this license for that organization. If you do not agree,
|
|
36
|
+
do not install or use the Software.
|
|
37
|
+
|
|
38
|
+
## 2. License grant
|
|
39
|
+
|
|
40
|
+
Subject to this license, the Licensor grants you a non-exclusive, worldwide,
|
|
41
|
+
royalty-free, non-transferable, and non-sublicensable license, perpetual for
|
|
42
|
+
the version of the Software to which it applies unless terminated under
|
|
43
|
+
Section 10, to:
|
|
44
|
+
|
|
45
|
+
- install, execute, and use the Software for personal, educational,
|
|
46
|
+
internal-business, or commercial purposes;
|
|
47
|
+
- use the Software to author, integrate, build, test, serve, play, host, and
|
|
48
|
+
operate Projects and Applications;
|
|
49
|
+
- import, compile, bundle, configure, and integrate the Software through its
|
|
50
|
+
documented library and command-line interfaces;
|
|
51
|
+
- create and distribute independent Projects, Applications, plugins, and
|
|
52
|
+
integrations that use those interfaces without modifying the Software
|
|
53
|
+
itself; and
|
|
54
|
+
- make copies reasonably necessary for local development, testing, continuous
|
|
55
|
+
integration, backup, and hosted production environments.
|
|
56
|
+
|
|
57
|
+
Your Authorized Users may exercise those rights solely on your behalf. You are
|
|
58
|
+
responsible for their compliance with this license.
|
|
59
|
+
|
|
60
|
+
You may reproduce and distribute Redistributable Components only as
|
|
61
|
+
incorporated into your Project, Application, or generated output, and only when
|
|
62
|
+
you preserve applicable license and proprietary notices. You may host and
|
|
63
|
+
commercially provide access to that Project, Application, or output. You may
|
|
64
|
+
not distribute Redistributable Components as a standalone package or as a
|
|
65
|
+
general-purpose substitute for the Software.
|
|
66
|
+
|
|
67
|
+
Each lawful recipient of a Redistributable Component may execute and use that
|
|
68
|
+
component, display its output, and make technically necessary transitory copies
|
|
69
|
+
solely as incorporated into the Project, Application, or output in which they
|
|
70
|
+
received it. This limited recipient permission does not include a right to
|
|
71
|
+
extract, modify, or redistribute the component separately.
|
|
72
|
+
|
|
73
|
+
## 3. Restrictions
|
|
74
|
+
|
|
75
|
+
Except where applicable law does not allow the restriction, you may not:
|
|
76
|
+
|
|
77
|
+
- modify, adapt, translate, or create derivative works of the Software, except
|
|
78
|
+
for the compilation, bundling, configuration, and integration expressly
|
|
79
|
+
permitted in Section 2;
|
|
80
|
+
- redistribute, sublicense, sell, lease, or otherwise provide the Software to
|
|
81
|
+
another person as a standalone package, product, or service except to an
|
|
82
|
+
Authorized User or as a Redistributable Component under Section 2;
|
|
83
|
+
- resell, rebrand, or provide the Software as a hosted or managed service that
|
|
84
|
+
gives third parties general-purpose access to substantial PathMX authoring,
|
|
85
|
+
building, serving, Player-administration, or library functionality for their
|
|
86
|
+
own unrelated projects;
|
|
87
|
+
- reverse engineer, decompile, disassemble, or otherwise attempt to derive the
|
|
88
|
+
source code of the Software; or
|
|
89
|
+
- remove or alter copyright, license, trademark, or other proprietary notices.
|
|
90
|
+
|
|
91
|
+
For clarity, the managed-service restriction does not prohibit a hosted
|
|
92
|
+
Project or Application in which PathMX supports the licensee's own
|
|
93
|
+
product-specific experience and is not itself the general-purpose product
|
|
94
|
+
offered to customers.
|
|
95
|
+
|
|
96
|
+
## 4. Your content
|
|
97
|
+
|
|
98
|
+
As between you and the Licensor, you retain ownership of the Paths, Sources,
|
|
99
|
+
responses, data, independent application code, and other content that you
|
|
100
|
+
author or provide while using the Software. You are responsible for that
|
|
101
|
+
content and for having the rights needed to use it.
|
|
102
|
+
|
|
103
|
+
Generated output may contain Redistributable Components or third-party
|
|
104
|
+
materials. Your ownership of your content does not change the ownership or
|
|
105
|
+
license terms of those components and materials.
|
|
106
|
+
|
|
107
|
+
## 5. Ownership and trademarks
|
|
108
|
+
|
|
109
|
+
The Software is licensed, not sold. The Licensor and its suppliers retain all
|
|
110
|
+
rights in the Software not expressly granted by this license. This license
|
|
111
|
+
does not grant permission to use the PathMX name, logos, or other marks except
|
|
112
|
+
as reasonably necessary to identify the Software accurately.
|
|
113
|
+
|
|
114
|
+
## 6. Beta status and changes
|
|
115
|
+
|
|
116
|
+
The Software is a proprietary beta release. Its APIs, behavior, file formats,
|
|
117
|
+
and features may change or be removed without notice. The Licensor has no
|
|
118
|
+
obligation to provide support, maintenance, updates, continued availability,
|
|
119
|
+
or backward compatibility. A later version may be offered under different
|
|
120
|
+
license terms, including an open-source license. Different terms for a later
|
|
121
|
+
version do not change the license previously granted for an earlier version.
|
|
122
|
+
|
|
123
|
+
## 7. Third-party materials
|
|
124
|
+
|
|
125
|
+
The Software and Redistributable Components may include or depend on
|
|
126
|
+
third-party materials governed by their own license terms. Those terms control
|
|
127
|
+
for the applicable third-party materials. You must preserve third-party notices
|
|
128
|
+
when the applicable third-party terms require it.
|
|
129
|
+
|
|
130
|
+
## 8. Disclaimer of warranties
|
|
131
|
+
|
|
132
|
+
TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED “AS IS” AND
|
|
133
|
+
“AS AVAILABLE,” WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS,
|
|
134
|
+
IMPLIED, OR STATUTORY, INCLUDING WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
135
|
+
PARTICULAR PURPOSE, TITLE, NON-INFRINGEMENT, OR THAT THE SOFTWARE WILL BE
|
|
136
|
+
SECURE, ERROR-FREE, OR UNINTERRUPTED.
|
|
137
|
+
|
|
138
|
+
## 9. Limitation of liability
|
|
139
|
+
|
|
140
|
+
TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE LICENSOR AND ITS CONTRIBUTORS,
|
|
141
|
+
SUPPLIERS, AND AFFILIATES WILL NOT BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
|
|
142
|
+
SPECIAL, CONSEQUENTIAL, EXEMPLARY, OR PUNITIVE DAMAGES, OR FOR LOSS OF DATA,
|
|
143
|
+
PROFITS, REVENUE, GOODWILL, OR BUSINESS OPPORTUNITY, ARISING FROM OR RELATED TO
|
|
144
|
+
THE SOFTWARE OR THIS LICENSE, EVEN IF ADVISED OF THE POSSIBILITY OF THOSE
|
|
145
|
+
DAMAGES.
|
|
146
|
+
|
|
147
|
+
TO THE MAXIMUM EXTENT PERMITTED BY LAW, THEIR TOTAL LIABILITY FOR ALL CLAIMS
|
|
148
|
+
ARISING FROM OR RELATED TO THE SOFTWARE OR THIS LICENSE WILL NOT EXCEED THE
|
|
149
|
+
GREATER OF THE AMOUNT YOU PAID FOR THE SOFTWARE DURING THE TWELVE MONTHS BEFORE
|
|
150
|
+
THE EVENT GIVING RISE TO THE CLAIM OR US$100.
|
|
151
|
+
|
|
152
|
+
## 10. Termination
|
|
153
|
+
|
|
154
|
+
This license terminates if you materially breach it and do not cure the breach
|
|
155
|
+
within thirty days after receiving written notice from the Licensor. On
|
|
156
|
+
termination, you and your Authorized Users must stop using and delete your
|
|
157
|
+
copies of the Software. Sections 4, 5, 8, 9, 10, and 11 survive termination.
|
|
158
|
+
Termination does not withdraw the limited permission already granted by
|
|
159
|
+
Section 2 to lawful recipients of Redistributable Components distributed
|
|
160
|
+
before termination.
|
|
161
|
+
|
|
162
|
+
## 11. General
|
|
163
|
+
|
|
164
|
+
If a provision of this license is unenforceable, it will be modified only to
|
|
165
|
+
the minimum extent necessary to make it enforceable, and the remaining
|
|
166
|
+
provisions will continue in effect. Failure to enforce a provision is not a
|
|
167
|
+
waiver. You may not assign or transfer this license without the Licensor's
|
|
168
|
+
written consent. The Licensor may assign this license together with ownership
|
|
169
|
+
of the Software to a successor owner. This license binds and benefits the
|
|
170
|
+
permitted successors and assigns of you and the Licensor. This license is the
|
|
171
|
+
entire agreement concerning the Software unless you and the Licensor have
|
|
172
|
+
signed a separate agreement that expressly replaces it.
|
package/README.md
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# `@pathmx/player`
|
|
2
|
+
|
|
3
|
+
`@pathmx/player` turns a rendered PathMX document into focused reading or a slide
|
|
4
|
+
presentation. It derives its route from semantic HTML in the browser, so Sources
|
|
5
|
+
stay ordinary Markdown. Core image directives compile into portable metadata,
|
|
6
|
+
which Player projects into presentation frames before deriving that route.
|
|
7
|
+
|
|
8
|
+
Install the plugin and author its app component where the Player should exist:
|
|
9
|
+
|
|
10
|
+
```md
|
|
11
|
+
<x-player-app />
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
The package default-exports `PlayerPlugin` for application/plugin composition.
|
|
15
|
+
Most applications install it transitively through the `@pathmx/paths` preset.
|
|
16
|
+
|
|
17
|
+
## Test Play
|
|
18
|
+
|
|
19
|
+
Use `?play=focus` for reading or `?play=presentation` for slides. The current
|
|
20
|
+
settings model also supports `intensity=low|medium|high`,
|
|
21
|
+
`play-theme=native|editorial|signal|code`, `play-guide=off`, and
|
|
22
|
+
`play-notes=off`. The last-used controls are remembered locally; an active
|
|
23
|
+
Play URL records the resolved shareable state.
|
|
24
|
+
|
|
25
|
+
High intensity hides upcoming Beats completely while keeping previously viewed
|
|
26
|
+
Beats visible at a reduced opacity.
|
|
27
|
+
A Play URL opens at its public Beat fragment or the first Beat. Beats with
|
|
28
|
+
public fragments keep the URL current for copying, history traversal, and
|
|
29
|
+
reloads at the same point. Fragment-free URLs always start from the beginning;
|
|
30
|
+
private session state never changes where a shared URL opens.
|
|
31
|
+
|
|
32
|
+
In presentation mode Player owns browser scroll restoration. It re-anchors the
|
|
33
|
+
active Beat after initial load and persisted-page restoration so the viewport
|
|
34
|
+
cannot drift away from the progress state when an iOS browser view restores an
|
|
35
|
+
older document offset.
|
|
36
|
+
|
|
37
|
+
The maintained acceptance fixtures are:
|
|
38
|
+
|
|
39
|
+
- `/demos/block-layouts.demo`
|
|
40
|
+
- `/demos/play-reading-gauntlet.demo?play=focus`
|
|
41
|
+
- `/demos/play-deck-gauntlet.demo?play=presentation`
|
|
42
|
+
- `/demos/play-media-hints.demo?play=presentation`
|
|
43
|
+
- `/demos/play-theme-gallery.demo`
|
|
44
|
+
|
|
45
|
+
Keyboard controls:
|
|
46
|
+
|
|
47
|
+
| Shortcut | Result |
|
|
48
|
+
| ------------------------- | ------------------------------- |
|
|
49
|
+
| `Command/Control + Enter` | Start Play with saved settings |
|
|
50
|
+
| `↑` / `↓`, `Space` | Previous / next Beat |
|
|
51
|
+
| `←` / `→` | Previous / next Block |
|
|
52
|
+
| `G` | Toggle the Block grid |
|
|
53
|
+
| `M` | Change between Focus and Slides |
|
|
54
|
+
| `+` / `-` | Raise / lower intensity |
|
|
55
|
+
| `Escape` | Close the grid, then exit Play |
|
|
56
|
+
|
|
57
|
+
Inside the Block grid, arrow keys move between the actual rendered Blocks and
|
|
58
|
+
Enter/Space selects a Block's first Beat. The grid is temporary; selecting a
|
|
59
|
+
Block updates the current shareable Beat without adding browser-history noise.
|
|
60
|
+
|
|
61
|
+
## Source authoring
|
|
62
|
+
|
|
63
|
+
Give an explicit Beat a stable fragment when it should be directly linkable:
|
|
64
|
+
|
|
65
|
+
```md
|
|
66
|
+
<p data-pmx-beat="course-goals">Name the three course goals.</p>
|
|
67
|
+
|
|
68
|
+
[Return to the course goals](#course-goals)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Player compiles `id="course-goals"` into the server-rendered HTML when the
|
|
72
|
+
element does not already have an ID. Authored IDs are always preserved, and
|
|
73
|
+
Markdown headings already work as native fragments. Add the Play query to a
|
|
74
|
+
link that should enter directly into Play, for example
|
|
75
|
+
`?play=presentation#course-goals`.
|
|
76
|
+
|
|
77
|
+
Choose a built-in slide theme in Source frontmatter:
|
|
78
|
+
|
|
79
|
+
```md
|
|
80
|
+
---
|
|
81
|
+
play:
|
|
82
|
+
theme: editorial
|
|
83
|
+
---
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Choose reusable composition directly in Block topmatter:
|
|
87
|
+
|
|
88
|
+
```md
|
|
89
|
+
<!--
|
|
90
|
+
layout: media-end
|
|
91
|
+
-->
|
|
92
|
+
|
|
93
|
+
# A slide title
|
|
94
|
+
|
|
95
|
+

|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
The core Block layouts are `center`, `media-start`, and `media-end`; they also
|
|
99
|
+
apply outside Player. Player-only rhetorical treatments stay under
|
|
100
|
+
`play.variant`:
|
|
101
|
+
|
|
102
|
+
```md
|
|
103
|
+
<!--
|
|
104
|
+
play:
|
|
105
|
+
variant: quote
|
|
106
|
+
-->
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
The Player variants are `cover`, `section`, `quote`, `fact`, `full`, and
|
|
110
|
+
`end`. Tables step through body rows automatically. Code fences opt into
|
|
111
|
+
line-group Beats with a compact range expression:
|
|
112
|
+
|
|
113
|
+
````md
|
|
114
|
+
```ts [1-2|3|5-7]
|
|
115
|
+
// code
|
|
116
|
+
```
|
|
117
|
+
````
|
|
118
|
+
|
|
119
|
+
Standalone Markdown images keep their natural size by default. Put one native
|
|
120
|
+
image directive at the start of the alt text when a Block needs a different
|
|
121
|
+
media treatment:
|
|
122
|
+
|
|
123
|
+
```md
|
|
124
|
+

|
|
125
|
+

|
|
126
|
+

|
|
127
|
+

|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
`fit` contains the whole image; `fill` covers the available content area and
|
|
131
|
+
becomes full-bleed in Slides mode when it is the Block's only content.
|
|
132
|
+
`background` covers the Block behind its content, while `background.fit` shows
|
|
133
|
+
the entire background. The core Image Plugin removes the leading directive
|
|
134
|
+
from the rendered `alt` attribute, so the remaining text stays meaningful to
|
|
135
|
+
readers and assistive technology.
|
|
136
|
+
|
|
137
|
+
Add presenter annotations with the Deckset-style caret paragraph syntax. Each
|
|
138
|
+
additional note paragraph starts with another caret:
|
|
139
|
+
|
|
140
|
+
```md
|
|
141
|
+
# Explain the model
|
|
142
|
+
|
|
143
|
+
^ Ask for a concrete example before advancing.
|
|
144
|
+
|
|
145
|
+
^ Relate the answer to the next Block.
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Notes stay out of normal document flow and the Beat route. Slides mode shows
|
|
149
|
+
the active Block's notes in an optional bottom-right annotation card.
|
|
150
|
+
|
|
151
|
+
## Shared Plugin controls
|
|
152
|
+
|
|
153
|
+
React-owned Plugin surfaces can import the source-owned shadcn/Base UI layer
|
|
154
|
+
from `@pathmx/react/ui`. `ActionButton` is the standard accessible icon-action
|
|
155
|
+
boundary; Player composition remains private to this Plugin.
|
|
156
|
+
|
|
157
|
+
```tsx
|
|
158
|
+
import { ActionButton } from "@pathmx/react/ui"
|
|
159
|
+
|
|
160
|
+
;<ActionButton label="Open tools" icon={<ToolsIcon aria-hidden="true" />} />
|
|
161
|
+
```
|
package/actions.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Beat } from "./route.ts"
|
|
2
|
+
import { invokePathMXAction } from "@pathmx/react"
|
|
3
|
+
import type { ActionAffordance } from "@pathmx/core"
|
|
4
|
+
|
|
5
|
+
export type PlayAction = {
|
|
6
|
+
type: "action"
|
|
7
|
+
label: string
|
|
8
|
+
external: boolean
|
|
9
|
+
activate(): void
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type PlayerLeaf = Beat | PlayAction
|
|
13
|
+
|
|
14
|
+
function actionLabel(link: HTMLAnchorElement) {
|
|
15
|
+
return (
|
|
16
|
+
link.getAttribute("aria-label") ??
|
|
17
|
+
link.textContent?.replace(/\s+/g, " ").trim() ??
|
|
18
|
+
""
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function playerReady(action: ActionAffordance) {
|
|
23
|
+
const required = action.input?.required
|
|
24
|
+
return (
|
|
25
|
+
!Array.isArray(required) ||
|
|
26
|
+
required.every(
|
|
27
|
+
(name) => typeof name === "string" && name in (action.boundInput ?? {}),
|
|
28
|
+
)
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Project ordinary links in the active Beat into touch-friendly Play actions. */
|
|
33
|
+
export function actionsForBeat(
|
|
34
|
+
beat: Beat,
|
|
35
|
+
contextual: readonly ActionAffordance[] = [],
|
|
36
|
+
): PlayAction[] {
|
|
37
|
+
const links = [
|
|
38
|
+
...(beat.element.matches("a[href]")
|
|
39
|
+
? [beat.element as HTMLAnchorElement]
|
|
40
|
+
: []),
|
|
41
|
+
...beat.element.querySelectorAll<HTMLAnchorElement>("a[href]"),
|
|
42
|
+
]
|
|
43
|
+
const hrefs = new Set<string>()
|
|
44
|
+
|
|
45
|
+
return links
|
|
46
|
+
.flatMap((link) => {
|
|
47
|
+
const label = actionLabel(link)
|
|
48
|
+
const href = link.href
|
|
49
|
+
if (!label || !href || hrefs.has(href)) return []
|
|
50
|
+
hrefs.add(href)
|
|
51
|
+
const url = new URL(href, location.href)
|
|
52
|
+
return [
|
|
53
|
+
{
|
|
54
|
+
type: "action" as const,
|
|
55
|
+
label,
|
|
56
|
+
external: url.origin !== location.origin || link.target === "_blank",
|
|
57
|
+
activate: () => link.click(),
|
|
58
|
+
},
|
|
59
|
+
]
|
|
60
|
+
})
|
|
61
|
+
.concat(
|
|
62
|
+
contextual.filter(playerReady).map((action) => ({
|
|
63
|
+
type: "action" as const,
|
|
64
|
+
label: action.title,
|
|
65
|
+
external: false,
|
|
66
|
+
activate: () => void invokePathMXAction(action),
|
|
67
|
+
})),
|
|
68
|
+
)
|
|
69
|
+
}
|