@lincyaw/addon-content 0.0.0-stage → 1.0.0-rc.2

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 ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,38 @@
1
- # Temporary Holding Version
1
+ # @lincyaw/addon-content
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Rich content: mind maps, PlantUML diagrams, video, audio, animations and YouTube.
4
+
5
+ Part of [Presmium](https://github.com/Lincyaw/presmium), which compiles canonical lecture.json teaching documents into web pages, slides, Jupyter notebooks and narrated playback.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ pnpm add -D @lincyaw/addon-content
11
+ ```
12
+
13
+ Add this package to `metadata.plugins` in the document's `lecture.json`.
14
+
15
+ It is a Presmium plugin: its components work on the web page and in the slides. It needs `@lincyaw/cli` and the renderers in the same project, and declares the Presmium packages it shares with them as peer dependencies (Presmium 1.x).
16
+
17
+ ## What it provides
18
+
19
+ - Mind maps, media with multilingual captions, and diagrams through component definitions.
20
+ - Structured component data and readable static fallbacks, with files localized into `.presmium/assets/` when required.
21
+
22
+ Native `PmMedia` video and audio keep the browser's controls and clock. Playback joins the runtime's
23
+ shared playback lease: starting another player pauses the previous one, and a pending start cannot
24
+ resume after navigation, cancellation or removal. Playback failures appear in the shared notice.
25
+
26
+ The document editor's initial positioning pauses media; if it cancels autoplay, use the native Play
27
+ control to start through the same authorization. Ordinary reading keeps native autoplay subject to
28
+ browser policy. Pausing media stays paused across step navigation. This coordination applies to
29
+ native video and audio; it does not control cross-origin YouTube players.
30
+
31
+ ## Documentation
32
+
33
+ - [Author guide](https://github.com/Lincyaw/presmium/blob/main/site/guide/locales/en/lecture.json) (Chinese: `site/guide/lecture.json`)
34
+ - [Document contract](https://github.com/Lincyaw/presmium/blob/main/.agents/skills/presmium-author/references/document.md): normalized entities, parameters, states and shared validation
35
+
36
+ ## License
37
+
38
+ Apache-2.0
@@ -0,0 +1 @@
1
+ export { default } from '../src/client/MarkmapView.tsx'
@@ -0,0 +1,24 @@
1
+ .pm-media {
2
+ margin: 0;
3
+ }
4
+ .pm-media :is(video, audio, img) {
5
+ display: block;
6
+ max-width: 100%;
7
+ }
8
+ .pm-media figcaption {
9
+ margin-top: 0.4em;
10
+ color: var(--pm-color-muted);
11
+ font-family: var(--pm-font-sans);
12
+ font-size: 0.85em;
13
+ }
14
+ .pm-media .pm-media-still {
15
+ display: none;
16
+ }
17
+ @media (prefers-reduced-motion: reduce) {
18
+ .pm-media .pm-media-motion {
19
+ display: none;
20
+ }
21
+ .pm-media .pm-media-still {
22
+ display: block;
23
+ }
24
+ }
@@ -0,0 +1,77 @@
1
+ import { PmNotice, useLocale, useMessages } from '@lincyaw/host'
2
+ import { createElement, useRef } from 'react'
3
+ import { useMediaPlayback } from '../src/client/media.ts'
4
+ import { captionTracks, mediaElements, MESSAGES } from '../src/domain/index.ts'
5
+ import type { MediaKind } from '../src/domain/index.ts'
6
+ import './PmMedia.css'
7
+ interface Props {
8
+ kind: MediaKind
9
+ src: string
10
+ still?: string
11
+ poster?: string
12
+ captions?: Record<string, string>
13
+ captionsDefault?: string
14
+ caption?: string
15
+ controls?: boolean
16
+ autoplay?: boolean
17
+ loop?: boolean
18
+ muted?: boolean
19
+ width?: number
20
+ height?: number
21
+ alt?: string
22
+ }
23
+ export default function PmMedia(props: Props) {
24
+ const locale = useLocale(),
25
+ t = useMessages(MESSAGES),
26
+ figure = useRef<HTMLElement>(null),
27
+ failed = useMediaPlayback(figure, `${props.kind}\0${props.src}`)
28
+ const elements = mediaElements(props.kind, props, props.still !== undefined),
29
+ tracks =
30
+ props.kind === 'video'
31
+ ? captionTracks(props.captions, props.captionsDefault, locale)
32
+ : []
33
+ return (
34
+ <figure
35
+ ref={figure}
36
+ className="pm-media"
37
+ data-kind={props.kind}
38
+ >
39
+ {elements.map(({ tag, file, attrs }, i) => {
40
+ const {
41
+ class: className,
42
+ autoplay: autoPlay,
43
+ playsinline: playsInline,
44
+ ...rest
45
+ } = attrs
46
+ return createElement(
47
+ tag,
48
+ {
49
+ ...rest,
50
+ className,
51
+ autoPlay,
52
+ playsInline,
53
+ src: file === 'still' ? props.still : props.src,
54
+ ...(tag === 'video' && props.poster
55
+ ? { poster: props.poster }
56
+ : {}),
57
+ key: i,
58
+ },
59
+ tag === 'video'
60
+ ? tracks.map((track) => (
61
+ <track
62
+ key={track.srclang}
63
+ kind="captions"
64
+ src={track.src}
65
+ srcLang={track.srclang}
66
+ label={track.label}
67
+ default={track.default}
68
+ />
69
+ ))
70
+ : undefined,
71
+ )
72
+ })}
73
+ {props.caption && <figcaption>{props.caption}</figcaption>}
74
+ {failed && <PmNotice tone="danger">{t.mediaPlaybackFailed}</PmNotice>}
75
+ </figure>
76
+ )
77
+ }
@@ -0,0 +1,5 @@
1
+ .pm-youtube iframe {
2
+ display: block;
3
+ max-width: 100%;
4
+ border: 0;
5
+ }
@@ -0,0 +1,31 @@
1
+ import './PmYoutube.css'
2
+ export default function PmYoutube({
3
+ id,
4
+ start,
5
+ width = 560,
6
+ height = 315,
7
+ caption,
8
+ }: {
9
+ id: string
10
+ start?: number
11
+ width?: number
12
+ height?: number
13
+ caption?: string
14
+ }) {
15
+ const src = `https://www.youtube-nocookie.com/embed/${encodeURIComponent(id)}${start ? `?start=${start}` : ''}`
16
+ return (
17
+ <figure className="pm-media pm-youtube" data-kind="youtube">
18
+ <iframe
19
+ src={src}
20
+ title={caption || 'YouTube'}
21
+ width={width}
22
+ height={height}
23
+ loading="lazy"
24
+ allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
25
+ referrerPolicy="strict-origin-when-cross-origin"
26
+ allowFullScreen
27
+ />
28
+ {caption && <figcaption>{caption}</figcaption>}
29
+ </figure>
30
+ )
31
+ }
Binary file
Binary file
Binary file
package/media/tone.ogg ADDED
Binary file
package/package.json CHANGED
@@ -1,6 +1,56 @@
1
1
  {
2
2
  "name": "@lincyaw/addon-content",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0-rc.2",
4
+ "description": "Presmium plugin: rich content: diagrams, mind maps, media, and web components",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/Lincyaw/presmium.git",
9
+ "directory": "packages/addon-content"
10
+ },
11
+ "homepage": "https://github.com/Lincyaw/presmium/tree/main/packages/addon-content#readme",
12
+ "bugs": "https://github.com/Lincyaw/presmium/issues",
13
+ "keywords": [
14
+ "presmium"
15
+ ],
16
+ "type": "module",
17
+ "engines": {
18
+ "node": ">=22.19"
19
+ },
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "exports": {
24
+ "./domain": "./src/domain/index.ts",
25
+ "./presmium": "./src/node/presmium.ts",
26
+ "./media/*": "./media/*",
27
+ "./package.json": "./package.json"
28
+ },
29
+ "files": [
30
+ "components",
31
+ "media",
32
+ "src"
33
+ ],
34
+ "presmium": {
35
+ "preview": {
36
+ "restartable": true
37
+ }
38
+ },
39
+ "dependencies": {
40
+ "markmap-lib": "^0.18.12",
41
+ "markmap-view": "^0.18.12",
42
+ "plantuml-encoder": "^1.4.0"
43
+ },
44
+ "peerDependencies": {
45
+ "react": "^18.3.1",
46
+ "@lincyaw/host": "^1.0.0-rc.2",
47
+ "@lincyaw/kernel": "^1.0.0-rc.2"
48
+ },
49
+ "devDependencies": {
50
+ "react": "18.3.1",
51
+ "@types/react": "18.3.28",
52
+ "@lincyaw/cli": "1.0.0-rc.2",
53
+ "@lincyaw/host": "1.0.0-rc.2",
54
+ "@lincyaw/kernel": "1.0.0-rc.2"
55
+ }
6
56
  }
@@ -0,0 +1,12 @@
1
+ .pm-markmap {
2
+ display: block;
3
+ width: 100%;
4
+ height: var(--pm-markmap-height, 18rem);
5
+ }
6
+ .pm-markmap.markmap {
7
+ --markmap-text-color: var(--pm-color-ink);
8
+ }
9
+ .pm-markmap g.markmap-node > circle:focus-visible {
10
+ outline: var(--pm-size-stroke) solid currentColor;
11
+ outline-offset: var(--pm-size-stroke);
12
+ }
@@ -0,0 +1,106 @@
1
+ import {
2
+ currentLocale,
3
+ usePrefersReducedMotion,
4
+ usePresentationMode,
5
+ } from '@lincyaw/host'
6
+ import { deriveOptions, Markmap } from 'markmap-view'
7
+ import { useEffect, useRef, useState } from 'react'
8
+ import { decodeMarkmap, MESSAGES } from '../domain/index.ts'
9
+ import './MarkmapView.css'
10
+ export default function MarkmapView({ data }: { data: string }) {
11
+ const interactive = usePresentationMode() === 'document',
12
+ reduced = usePrefersReducedMotion(),
13
+ svg = useRef<SVGSVGElement>(null),
14
+ [failure, setFailure] = useState<unknown>()
15
+ useEffect(() => {
16
+ const el = svg.current
17
+ if (!el) return
18
+ const { root, options } = decodeMarkmap(data)
19
+ let map: Markmap | undefined
20
+ let disposed = false
21
+ const fit = () => {
22
+ if (!map) return
23
+ const { x1, y1, x2, y2 } = map.state.rect,
24
+ width = el.clientWidth,
25
+ height = el.clientHeight
26
+ const scale =
27
+ map.options.fitRatio *
28
+ Math.min(
29
+ width / (x2 - x1 + 16),
30
+ height / (y2 - y1 + 16),
31
+ map.options.maxInitialScale,
32
+ )
33
+ map.zoom.extent([
34
+ [0, 0],
35
+ [width, height],
36
+ ])
37
+ map.zoom.scaleTo(map.svg, scale)
38
+ map.zoom.translateTo(map.svg, (x1 + x2) / 2, (y1 + y2) / 2)
39
+ }
40
+ const draw = async () => {
41
+ if (disposed || !el.clientWidth) return
42
+ if (map) return fit()
43
+ map = Markmap.create(el, {
44
+ ...deriveOptions(options),
45
+ autoFit: false,
46
+ zoom: interactive,
47
+ pan: interactive,
48
+ })
49
+ const duration = map.options.duration
50
+ await map.setData(root, { duration: 0 })
51
+ if (disposed) return
52
+ fit()
53
+ map.setOptions({ duration: reduced ? 0 : duration })
54
+ }
55
+ const observer = new ResizeObserver(() => void draw().catch(setFailure))
56
+ observer.observe(el)
57
+ const toggles = new MutationObserver(() => {
58
+ for (const circle of el.querySelectorAll('g.markmap-node > circle')) {
59
+ const node = circle.parentElement!
60
+ circle.setAttribute('tabindex', '0')
61
+ circle.setAttribute('role', 'button')
62
+ circle.setAttribute(
63
+ 'aria-expanded',
64
+ String(!node.classList.contains('markmap-fold')),
65
+ )
66
+ circle.setAttribute(
67
+ 'aria-label',
68
+ MESSAGES[currentLocale()].toggle(
69
+ node.querySelector('foreignObject')?.textContent?.trim() ?? '',
70
+ ),
71
+ )
72
+ }
73
+ })
74
+ toggles.observe(el, {
75
+ subtree: true,
76
+ childList: true,
77
+ attributes: true,
78
+ attributeFilter: ['class'],
79
+ })
80
+ void draw().catch(setFailure)
81
+ return () => {
82
+ disposed = true
83
+ observer.disconnect()
84
+ toggles.disconnect()
85
+ map?.destroy()
86
+ }
87
+ }, [data, interactive, reduced])
88
+ if (failure) throw failure
89
+ return (
90
+ <svg
91
+ ref={svg}
92
+ className="pm-markmap"
93
+ onKeyDown={(event) => {
94
+ const target = event.target as Element
95
+ if (
96
+ (event.key === 'Enter' || event.key === ' ') &&
97
+ target.matches('g.markmap-node > circle')
98
+ ) {
99
+ event.preventDefault()
100
+ event.stopPropagation()
101
+ target.dispatchEvent(new MouseEvent('click', { bubbles: true }))
102
+ }
103
+ }}
104
+ />
105
+ )
106
+ }
@@ -0,0 +1,107 @@
1
+ import { PLAYBACK_CONTROL, useService, useStep, useStepState, useViewRole } from '@lincyaw/host'
2
+ import { createContext, useContext, useLayoutEffect, useState } from 'react'
3
+ import type { RefObject } from 'react'
4
+ export const MEDIA_ACTIVE = createContext(true)
5
+ export function useMediaActive(): boolean { const active = useContext(MEDIA_ACTIVE), role = useViewRole(), state = useStepState({ from: 0 }); return active && (role === 'reader' || state.active) }
6
+
7
+ /** Native controls retain their clock; the runtime lease only authorizes starts. */
8
+ export function useMediaPlayback(figure: RefObject<HTMLElement>, source: string): boolean {
9
+ const control = useService(PLAYBACK_CONTROL), active = useMediaActive(), step = useStep()
10
+ const [failed, setFailed] = useState(false)
11
+ useLayoutEffect(() => {
12
+ const media = [...figure.current?.querySelectorAll<HTMLMediaElement>('video,audio') ?? []]
13
+ setFailed(false)
14
+ if (!media.length) return
15
+ let disposed = false, generation = 0
16
+ let current: { element: HTMLMediaElement, generation: number, phase: 'holding' | 'authorizing' | 'starting' | 'playing' } | undefined
17
+ const pauses = new Map<HTMLMediaElement, (() => void)[]>()
18
+ const pause = (element: HTMLMediaElement): Promise<void> => {
19
+ if (element.paused) return Promise.resolve()
20
+ return new Promise(resolve => {
21
+ const pending = pauses.get(element) ?? []
22
+ pending.push(resolve)
23
+ pauses.set(element, pending)
24
+ element.pause()
25
+ })
26
+ }
27
+ const stop = () => {
28
+ generation++
29
+ current = undefined
30
+ lease?.cancel()
31
+ for (const element of media) void pause(element)
32
+ }
33
+ const lease = control?.register(stop)
34
+ const valid = (request: NonNullable<typeof current>) => !disposed && active && current === request && generation === request.generation
35
+ const start = async (element: HTMLMediaElement) => {
36
+ lease?.cancel()
37
+ const request: NonNullable<typeof current> = { element, generation: ++generation, phase: 'holding' }
38
+ current = request
39
+ setFailed(false)
40
+ try {
41
+ // pause() queues a native event. Drain it before restoring playback so an
42
+ // old internal pause cannot cancel the permission just granted.
43
+ await pause(element)
44
+ if (!valid(request)) return
45
+ request.phase = 'authorizing'
46
+ const allowed = lease ? await lease.requestStart() : true
47
+ if (!valid(request) || !allowed) return
48
+ request.phase = 'starting'
49
+ await element.play()
50
+ } catch (error) {
51
+ if (!valid(request)) return
52
+ stop()
53
+ if (!(error instanceof Error && error.name === 'AbortError')) setFailed(true)
54
+ }
55
+ }
56
+ const onPlay = (event: Event) => {
57
+ const element = event.currentTarget as HTMLMediaElement
58
+ if (disposed || !active) { stop(); return }
59
+ if (current?.element === element && current.phase === 'starting') {
60
+ if (element.paused) stop()
61
+ else current.phase = 'playing'
62
+ return
63
+ }
64
+ if (element.paused) return // A play event queued before a newer pause.
65
+ void start(element)
66
+ }
67
+ const onPause = (event: Event) => {
68
+ const element = event.currentTarget as HTMLMediaElement, pending = pauses.get(element)
69
+ if (pending?.length) { pending.shift()!(); if (!pending.length) pauses.delete(element); return }
70
+ if (current?.element !== element || !element.paused) return
71
+ // During authorization the element is deliberately paused. A native
72
+ // control cannot pause it again; external cancellation calls stop().
73
+ if (current.phase === 'authorizing' || current.phase === 'holding' || current.phase === 'starting') return
74
+ stop()
75
+ }
76
+ const onStop = () => stop()
77
+ const onSeek = () => {
78
+ // Seeking during an authorization invalidates that start. Once playing,
79
+ // native scrubbing and loop seeks keep their existing lease and clock.
80
+ if (current && current.phase !== 'playing') stop()
81
+ }
82
+ const onError = () => { stop(); if (!disposed) setFailed(true) }
83
+ for (const element of media) {
84
+ element.addEventListener('play', onPlay)
85
+ element.addEventListener('pause', onPause)
86
+ element.addEventListener('ended', onStop)
87
+ element.addEventListener('seeking', onSeek)
88
+ element.addEventListener('error', onError)
89
+ }
90
+ if (!active) stop()
91
+ return () => {
92
+ disposed = true
93
+ stop()
94
+ lease?.dispose()
95
+ for (const element of media) {
96
+ element.removeEventListener('play', onPlay)
97
+ element.removeEventListener('pause', onPause)
98
+ element.removeEventListener('ended', onStop)
99
+ element.removeEventListener('seeking', onSeek)
100
+ element.removeEventListener('error', onError)
101
+ }
102
+ for (const pending of pauses.values()) for (const resolve of pending) resolve()
103
+ pauses.clear()
104
+ }
105
+ }, [figure, control, active, step, source])
106
+ return failed
107
+ }
@@ -0,0 +1,8 @@
1
+ export const CONTENT_ID = 'presmium.content'
2
+
3
+ const CUSTOM_ELEMENT_PREFIX = 'presmium-'
4
+
5
+ /** Tags the slides form leaves to the browser as custom elements (web components), not Vue components. */
6
+ export function isCustomElementTag(tag: string): boolean {
7
+ return tag.startsWith(CUSTOM_ELEMENT_PREFIX)
8
+ }
@@ -0,0 +1,7 @@
1
+ export { CONTENT_ID, isCustomElementTag } from './config.ts'
2
+ export { decodeMarkmap, encodeMarkmap, markmapOutline } from './markmap.ts'
3
+ export type { MarkmapData, MarkmapNode } from './markmap.ts'
4
+ export { captionTracks, isRemote, languageName, languageTag, MEDIA_KINDS, MEDIA_OPTIONS, mediaElements, mediaFallback, parseCaptions, videoHtml, youtubeId } from './media.ts'
5
+ export type { CaptionTrack, MediaElement, MediaKind, MediaOptions } from './media.ts'
6
+ export { MESSAGES } from './messages.ts'
7
+ export type { ContentMessages } from './messages.ts'
@@ -0,0 +1,42 @@
1
+ import type { MdastNode } from '@lincyaw/kernel'
2
+
3
+ export interface MarkmapNode {
4
+ content: string
5
+ children: MarkmapNode[]
6
+ payload?: Record<string, unknown>
7
+ }
8
+
9
+ export interface MarkmapData {
10
+ root: MarkmapNode
11
+ options?: Record<string, unknown>
12
+ }
13
+
14
+ export function encodeMarkmap(data: MarkmapData): string {
15
+ return encodeURIComponent(JSON.stringify(data))
16
+ }
17
+
18
+ export function decodeMarkmap(value: string): MarkmapData {
19
+ return JSON.parse(decodeURIComponent(value)) as MarkmapData
20
+ }
21
+
22
+ const ENTITIES: Record<string, string> = { amp: '&', lt: '<', gt: '>', quot: '"', apos: '\'', nbsp: ' ' }
23
+
24
+ function text(html: string): string {
25
+ return html.replace(/<[^>]*>/g, '').replace(/&(#x[\da-f]+|#\d+|[a-z]+);/gi, (entity, name: string) => {
26
+ if (name[0] !== '#') return ENTITIES[name] ?? entity
27
+ return String.fromCodePoint(name[1] === 'x' || name[1] === 'X' ? Number.parseInt(name.slice(2), 16) : Number(name.slice(1)))
28
+ }).trim()
29
+ }
30
+
31
+ export function markmapOutline(root: MarkmapNode): MdastNode {
32
+ const item = (node: MarkmapNode): MdastNode => ({
33
+ type: 'listItem',
34
+ spread: false,
35
+ children: [
36
+ { type: 'paragraph', children: [{ type: 'text', value: text(node.content) }] },
37
+ ...node.children.length > 0 ? [list(node.children)] : [],
38
+ ],
39
+ })
40
+ const list = (nodes: MarkmapNode[]): MdastNode => ({ type: 'list', ordered: false, spread: false, children: nodes.map(item) })
41
+ return { type: 'root', children: [list([root])] }
42
+ }
@@ -0,0 +1,128 @@
1
+ import { escapeHtml } from '@lincyaw/kernel'
2
+ import type { MdastNode } from '@lincyaw/kernel'
3
+
4
+ export type MediaKind = 'video' | 'audio' | 'animation'
5
+
6
+ export const MEDIA_KINDS: readonly MediaKind[] = ['video', 'audio', 'animation']
7
+
8
+ export interface MediaOptions {
9
+ controls?: boolean
10
+ autoplay?: boolean
11
+ loop?: boolean
12
+ muted?: boolean
13
+ width?: number
14
+ height?: number
15
+ alt?: string
16
+ }
17
+
18
+ export const MEDIA_OPTIONS = { controls: 'boolean', autoplay: 'boolean', loop: 'boolean', muted: 'boolean', width: 'number', height: 'number', alt: 'string' } as const
19
+
20
+ export interface MediaElement {
21
+ tag: 'video' | 'audio' | 'img'
22
+ file: 'media' | 'still'
23
+ attrs: Record<string, string | number | true>
24
+ }
25
+
26
+ export function mediaElements(kind: MediaKind, options: MediaOptions, still: boolean): MediaElement[] {
27
+ const size: Record<string, number> = {}
28
+ for (const key of ['width', 'height'] as const) {
29
+ const value = options[key]
30
+ if (typeof value === 'number' && value > 0) size[key] = value
31
+ }
32
+ const flags = (names: (keyof MediaOptions)[]) => Object.fromEntries(names.filter(name => options[name] === true).map(name => [name, true as const]))
33
+ if (kind === 'video') {
34
+ const autoplay: Record<string, true> = options.autoplay ? { muted: true, playsinline: true } : {}
35
+ return [{ tag: 'video', file: 'media', attrs: { ...flags(['controls', 'autoplay', 'loop', 'muted']), ...autoplay, preload: 'metadata', ...size } }]
36
+ }
37
+ if (kind === 'audio') return [{ tag: 'audio', file: 'media', attrs: { ...flags(['controls', 'autoplay', 'loop']), preload: 'metadata' } }]
38
+ const alt = { alt: options.alt ?? '' }
39
+ if (!still) return [{ tag: 'img', file: 'media', attrs: { ...alt, ...size } }]
40
+ return [
41
+ { tag: 'img', file: 'media', attrs: { class: 'pm-media-motion', ...alt, ...size } },
42
+ { tag: 'img', file: 'still', attrs: { class: 'pm-media-still', ...alt, ...size } },
43
+ ]
44
+ }
45
+
46
+ export interface CaptionTrack {
47
+ srclang: string
48
+ src: string
49
+ label: string
50
+ default: boolean
51
+ }
52
+
53
+ export function parseCaptions(value: string): { captions: Record<string, string>, invalid: string[] } {
54
+ const captions: Record<string, string> = {}
55
+ const invalid: string[] = []
56
+ for (const entry of value.split(',').map(part => part.trim()).filter(Boolean)) {
57
+ const [lang = '', ...file] = entry.split('=')
58
+ const tag = languageTag(lang.trim())
59
+ const path = file.join('=').trim()
60
+ if (tag && path) captions[tag] = path
61
+ else invalid.push(entry)
62
+ }
63
+ return { captions, invalid }
64
+ }
65
+
66
+ export function languageTag(value: string): string | undefined {
67
+ try {
68
+ return value ? Intl.getCanonicalLocales(value)[0] : undefined
69
+ } catch {
70
+ return undefined
71
+ }
72
+ }
73
+
74
+ export function languageName(lang: string, locale: string): string {
75
+ try {
76
+ return new Intl.DisplayNames([locale], { type: 'language' }).of(lang) ?? lang
77
+ } catch {
78
+ return lang
79
+ }
80
+ }
81
+
82
+ export function captionTracks(captions: Record<string, string> | undefined, chosen: string | undefined, locale: string): CaptionTrack[] {
83
+ return Object.entries(captions ?? {}).map(([srclang, src]) => ({ srclang, src, label: languageName(srclang, locale), default: srclang === chosen }))
84
+ }
85
+
86
+ function htmlAttributes(attrs: Record<string, string | number | true | undefined>): string {
87
+ return Object.entries(attrs)
88
+ .filter(([, value]) => value !== undefined)
89
+ .map(([name, value]) => (value === true ? ` ${name}` : ` ${name}="${escapeHtml(String(value))}"`))
90
+ .join('')
91
+ }
92
+
93
+ export function videoHtml(video: { src: string, poster?: string, tracks: CaptionTrack[], caption?: string, options: MediaOptions }): string {
94
+ const [element] = mediaElements('video', video.options, false)
95
+ const tracks = video.tracks.map(track => `<track${htmlAttributes({ kind: 'captions', src: track.src, srclang: track.srclang, label: track.label, default: track.default || undefined })}>`)
96
+ const lines = ['<figure>', `<video${htmlAttributes({ ...element!.attrs, src: video.src, poster: video.poster })}>`, ...tracks, '</video>']
97
+ if (video.caption) lines.push(`<figcaption>${escapeHtml(video.caption)}</figcaption>`)
98
+ return [...lines, '</figure>'].join('\n')
99
+ }
100
+
101
+ export function mediaFallback(url: string, caption?: string): MdastNode {
102
+ const name = caption || url.split(/[?#]/)[0]!.split('/').pop() || url
103
+ return { type: 'root', children: [{ type: 'paragraph', children: [{ type: 'link', url, children: [{ type: 'text', value: name }] }] }] }
104
+ }
105
+
106
+ export function isRemote(path: string): boolean {
107
+ return /^https?:\/\//i.test(path)
108
+ }
109
+
110
+ const YOUTUBE_ID = /^[\w-]{11}$/
111
+
112
+ export function youtubeId(value: string): string | undefined {
113
+ const text = value.trim()
114
+ if (YOUTUBE_ID.test(text)) return text
115
+ let url: URL
116
+ try {
117
+ url = new URL(text)
118
+ } catch {
119
+ return undefined
120
+ }
121
+ const host = url.hostname.replace(/^(www\.|m\.)/, '')
122
+ const id = host === 'youtu.be'
123
+ ? url.pathname.slice(1)
124
+ : /^youtube(-nocookie)?\.com$/.test(host)
125
+ ? url.searchParams.get('v') ?? /^\/(?:embed|shorts|live)\/([^/]+)/.exec(url.pathname)?.[1]
126
+ : undefined
127
+ return id && YOUTUBE_ID.test(id) ? id : undefined
128
+ }
@@ -0,0 +1,12 @@
1
+ import type { Locale } from '@lincyaw/kernel'
2
+
3
+ export interface ContentMessages {
4
+ plantUml: string
5
+ mediaPlaybackFailed: string
6
+ toggle: (node: string) => string
7
+ }
8
+
9
+ export const MESSAGES: Record<Locale, ContentMessages> = {
10
+ 'zh-CN': { plantUml: 'PlantUML 图', mediaPlaybackFailed: '无法播放媒体。请检查文件或播放权限,然后重试。', toggle: node => `折叠或展开:${node}` },
11
+ 'en': { plantUml: 'PlantUML diagram', mediaPlaybackFailed: 'Couldn’t play the media. Check the file or playback permission, then try again.', toggle: node => `Fold or unfold: ${node}` },
12
+ }
@@ -0,0 +1,24 @@
1
+ import { isRecord } from '@lincyaw/kernel'
2
+ import type { DirectiveSpec } from '@lincyaw/kernel'
3
+ import { Transformer } from 'markmap-lib'
4
+ import { CONTENT_ID, encodeMarkmap, markmapOutline } from '../domain/index.ts'
5
+
6
+ const transformer = new Transformer()
7
+
8
+ export const markmapDirective: DirectiveSpec = {
9
+ name: 'markmap',
10
+ body: true,
11
+ toIR(input) {
12
+ const { root, frontmatter } = transformer.transform(input.body)
13
+ const options = isRecord(input.options.markmap) ? input.options.markmap : frontmatter?.markmap
14
+ return {
15
+ node: {
16
+ type: 'component',
17
+ plugin: CONTENT_ID,
18
+ name: 'PmMarkmap',
19
+ props: { data: encodeMarkmap({ root, ...options ? { options } : {} }) },
20
+ fallback: markmapOutline(root),
21
+ },
22
+ }
23
+ },
24
+ }
@@ -0,0 +1,128 @@
1
+ import { existsSync } from 'node:fs'
2
+ import { createRequire } from 'node:module'
3
+ import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'
4
+ import { deckLocale, docBlocks, isRecord, NON_FILE_URL } from '@lincyaw/kernel'
5
+ import type { ComponentNode, DirectiveContext, DirectiveSpec, IRBlock, IRPass, RenderContext } from '@lincyaw/kernel'
6
+ import { captionTracks, CONTENT_ID, isRemote, languageTag, MEDIA_OPTIONS, mediaFallback, parseCaptions, videoHtml, youtubeId } from '../domain/index.ts'
7
+ import type { MediaKind, MediaOptions } from '../domain/index.ts'
8
+
9
+ function resolveMedia(path: string, ctx: DirectiveContext): string | undefined {
10
+ const file = resolve(dirname(ctx.file), path)
11
+ if (existsSync(file) || path.startsWith('.') || isAbsolute(path)) return existsSync(file) ? file : undefined
12
+ try {
13
+ return createRequire(join(ctx.deckDir, 'package.json')).resolve(path)
14
+ } catch {
15
+ return undefined
16
+ }
17
+ }
18
+
19
+ const posix = (path: string) => path.split(sep).join('/')
20
+
21
+ /** Resource paths belong to the actual media parameters, including step overrides. */
22
+ function mediaAssets(props: Record<string, unknown>): Record<string, string> {
23
+ const assets: Record<string, string> = {}
24
+ for (const key of ['src', 'poster', 'still']) if (typeof props[key] === 'string' && props[key]) assets[key] = props[key]
25
+ if (isRecord(props.captions)) for (const [lang, value] of Object.entries(props.captions)) if (typeof value === 'string' && value) assets[`captions.${lang}`] = value
26
+ return assets
27
+ }
28
+
29
+ export const mediaAssetsPass: IRPass = {
30
+ name: 'presmium.content.media-assets',
31
+ run(doc, ctx) {
32
+ for (const { block } of docBlocks(doc)) {
33
+ const { node } = block
34
+ if (node.type !== 'component' || node.plugin !== CONTENT_ID || node.name !== 'PmMedia') continue
35
+ node.assets = mediaAssets(node.props)
36
+ for (const state of block.stepStates ?? []) state.assets = mediaAssets(state.parameters ?? node.props)
37
+ const urls = new Set([node.assets, ...(block.stepStates ?? []).map(state => state.assets)].flatMap(assets => Object.values(assets ?? {})))
38
+ for (const url of urls) {
39
+ if (NON_FILE_URL.test(url)) continue
40
+ let file = url.replace(/[?#].*$/s, '')
41
+ try { file = decodeURIComponent(file) } catch {}
42
+ if (file) ctx.watch(file.startsWith('/') ? join(ctx.deckDir, 'public', file) : resolve(dirname(block.source.file), file))
43
+ }
44
+ }
45
+ },
46
+ }
47
+
48
+ const FILE_OPTIONS = {
49
+ video: { 'poster': 'string', 'captions': 'string', 'captions-default': 'string' },
50
+ audio: {},
51
+ animation: { still: 'string' },
52
+ } as const
53
+
54
+ export function mediaDirective(kind: MediaKind): DirectiveSpec {
55
+ return {
56
+ name: kind,
57
+ arg: true,
58
+ body: true,
59
+ options: { ...MEDIA_OPTIONS, ...FILE_OPTIONS[kind] },
60
+ toIR(input, ctx) {
61
+ const report = (severity: 'error' | 'warning', message: string) => ctx.report({ checkId: CONTENT_ID, severity, message: `{${kind}}: ${message}` })
62
+ const option = (name: string) => (typeof input.options[name] === 'string' ? (input.options[name] as string).trim() : undefined)
63
+ const media = input.arg?.trim()
64
+ if (!media) report('error', 'needs the path or URL of the media file')
65
+ const assets: Record<string, string> = {}
66
+ const url = (path: string, prop: string) => {
67
+ if (isRemote(path)) return path
68
+ const file = resolveMedia(path, ctx)
69
+ if (!file) report('error', `file not found: ${path}`)
70
+ return assets[prop] = file ? posix(relative(dirname(ctx.file), file)) : path
71
+ }
72
+ const props: Record<string, unknown> = { kind, src: media ? url(media, 'src') : '' }
73
+ const still = option('still')
74
+ if (still) props.still = url(still, 'still')
75
+ const poster = option('poster')
76
+ if (poster) props.poster = url(poster, 'poster')
77
+ const { captions, invalid } = parseCaptions(option('captions') ?? '')
78
+ for (const entry of invalid) report('error', `:captions: "${entry}" is not <language>=<file>, e.g. en=films/loop.en.vtt`)
79
+ if (Object.keys(captions).length) props.captions = Object.fromEntries(Object.entries(captions).map(([lang, path]) => [lang, url(path, `captions.${lang}`)]))
80
+ const chosen = option('captions-default')
81
+ const shown = chosen && Object.keys(captions).find(lang => lang === languageTag(chosen))
82
+ if (chosen && !shown) report('warning', `:captions-default: ${chosen} is not a language of :captions:; no captions show at first`)
83
+ if (shown) props.captionsDefault = shown
84
+ const { still: _still, 'poster': _poster, 'captions': _captions, 'captions-default': _default, ...options } = input.options
85
+ const caption = input.body.trim()
86
+ const node: ComponentNode = {
87
+ type: 'component',
88
+ plugin: CONTENT_ID,
89
+ name: 'PmMedia',
90
+ props: { ...props, ...options, ...caption ? { caption } : {} },
91
+ ...Object.keys(assets).length ? { assets } : {},
92
+ fallback: mediaFallback(String(props.src), caption),
93
+ }
94
+ return { node }
95
+ },
96
+ }
97
+ }
98
+
99
+ export function notebookMedia(node: ComponentNode, _block: IRBlock, ctx: RenderContext): unknown {
100
+ const { kind, src, poster, captions, captionsDefault, caption, ...options } = node.props
101
+ if (kind !== 'video' || (!poster && !captions)) return undefined
102
+ const tracks = captionTracks(captions as Record<string, string> | undefined, captionsDefault as string | undefined, deckLocale(ctx.lang))
103
+ const html = videoHtml({ src: String(src), poster: poster as string | undefined, tracks, caption: caption as string | undefined, options: options as MediaOptions })
104
+ return { cell_type: 'markdown', source: html }
105
+ }
106
+
107
+ export const youtubeDirective: DirectiveSpec = {
108
+ name: 'youtube',
109
+ arg: true,
110
+ body: true,
111
+ options: { start: 'number', width: 'number', height: 'number' },
112
+ toIR(input, ctx) {
113
+ const id = youtubeId(input.arg ?? '')
114
+ if (!id) ctx.report({ checkId: CONTENT_ID, severity: 'error', message: `{youtube}: "${input.arg ?? ''}" is no YouTube video id or link` })
115
+ const caption = input.body.trim()
116
+ const sizes = Object.fromEntries(['start', 'width', 'height'].flatMap(key => (typeof input.options[key] === 'number' && (input.options[key] as number) > 0 ? [[key, input.options[key]]] : [])))
117
+ const url = `https://www.youtube.com/watch?v=${id ?? ''}`
118
+ return {
119
+ node: {
120
+ type: 'component',
121
+ plugin: CONTENT_ID,
122
+ name: 'PmYoutube',
123
+ props: { id: id ?? '', ...sizes, ...caption ? { caption } : {} },
124
+ fallback: { type: 'root', children: [{ type: 'paragraph', children: [{ type: 'link', url, children: [{ type: 'text', value: caption || url }] }] }] },
125
+ },
126
+ }
127
+ },
128
+ }
@@ -0,0 +1,4 @@
1
+ declare module 'plantuml-encoder' {
2
+ const encoder: { encode(text: string): string }
3
+ export default encoder
4
+ }
@@ -0,0 +1,20 @@
1
+ import { deckLocale, docBlocks } from '@lincyaw/kernel'
2
+ import type { IRPass } from '@lincyaw/kernel'
3
+ import plantuml from 'plantuml-encoder'
4
+ import { MESSAGES } from '../domain/index.ts'
5
+
6
+ const DEFAULT_SERVER = 'https://www.plantuml.com/plantuml'
7
+
8
+ export const plantUmlPass: IRPass = {
9
+ name: 'presmium.content.plantuml',
10
+ run(doc, ctx) {
11
+ const server = (typeof ctx.config.plantUmlServer === 'string' ? ctx.config.plantUmlServer : DEFAULT_SERVER).replace(/\/+$/, '')
12
+ const alt = MESSAGES[deckLocale(ctx.lang)].plantUml
13
+ for (const { block } of docBlocks(doc)) {
14
+ const { node } = block
15
+ if (node.type !== 'code' || !/^(?:plantuml|puml)$/i.test(node.lang)) continue
16
+ const image = { type: 'image', url: `${server}/svg/${plantuml.encode(node.value)}`, alt: node.title ?? alt }
17
+ block.node = { type: 'markdown', mdast: { type: 'root', children: [{ type: 'paragraph', children: [image] }] } }
18
+ }
19
+ },
20
+ }
@@ -0,0 +1,19 @@
1
+ import { createRequire } from 'node:module'
2
+ import type { PresmiumNodePlugin } from '@lincyaw/kernel'
3
+ import { CONTENT_ID, MEDIA_KINDS } from '../domain/index.ts'
4
+ import { markmapDirective } from './markmap.ts'
5
+ import { mediaAssetsPass, mediaDirective, notebookMedia, youtubeDirective } from './media.ts'
6
+ import { plantUmlPass } from './plantuml.ts'
7
+
8
+ const { version } = createRequire(import.meta.url)('../../package.json') as { version: string }
9
+
10
+ const plugin: PresmiumNodePlugin = {
11
+ id: CONTENT_ID,
12
+ version,
13
+ kernel: '^1.0.0',
14
+ directives: [markmapDirective, ...MEDIA_KINDS.map(kind => mediaDirective(kind)), youtubeDirective],
15
+ passes: [plantUmlPass, mediaAssetsPass],
16
+ rendererExtensions: { notebook: { components: { PmMedia: notebookMedia } } },
17
+ }
18
+
19
+ export default plugin