immerslides 0.0.0-stage → 1.0.0-beta-3
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 +21 -0
- package/README.md +237 -2
- package/README.zh-TW.md +173 -0
- package/bin/immerslides.mjs +93 -0
- package/dist/code/CodeBlock.d.ts +16 -0
- package/dist/code/CodeBlock.js +16 -0
- package/dist/code/CodeWindow.d.ts +6 -0
- package/dist/code/CodeWindow.js +4 -0
- package/dist/code/HighlightedCode.d.ts +9 -0
- package/dist/code/HighlightedCode.js +36 -0
- package/dist/code/highlighting.d.ts +8 -0
- package/dist/code/highlighting.js +47 -0
- package/dist/flow/FlowConnector.d.ts +6 -0
- package/dist/flow/FlowConnector.js +4 -0
- package/dist/flow/FlowNode.d.ts +10 -0
- package/dist/flow/FlowNode.js +4 -0
- package/dist/flow/Timeline.d.ts +19 -0
- package/dist/flow/Timeline.js +30 -0
- package/dist/flow/types.d.ts +2 -0
- package/dist/flow/types.js +1 -0
- package/dist/i18n/context.d.ts +15 -0
- package/dist/i18n/context.js +20 -0
- package/dist/i18n/deck.d.ts +10 -0
- package/dist/i18n/deck.js +49 -0
- package/dist/i18n/messages.d.ts +78 -0
- package/dist/i18n/messages.js +147 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +20 -0
- package/dist/presentation/IconButton.d.ts +10 -0
- package/dist/presentation/IconButton.js +4 -0
- package/dist/presentation/Modal.d.ts +9 -0
- package/dist/presentation/Modal.js +21 -0
- package/dist/presentation/PageNumberInput.d.ts +10 -0
- package/dist/presentation/PageNumberInput.js +23 -0
- package/dist/presentation/Player.d.ts +9 -0
- package/dist/presentation/Player.js +144 -0
- package/dist/presentation/PlayerHelp.d.ts +7 -0
- package/dist/presentation/PlayerHelp.js +17 -0
- package/dist/presentation/PlayerToolbar.d.ts +18 -0
- package/dist/presentation/PlayerToolbar.js +10 -0
- package/dist/presentation/Presenter.d.ts +4 -0
- package/dist/presentation/Presenter.js +158 -0
- package/dist/presentation/SlideNavigator.d.ts +12 -0
- package/dist/presentation/SlideNavigator.js +60 -0
- package/dist/presentation/SlidePreview.d.ts +8 -0
- package/dist/presentation/SlidePreview.js +26 -0
- package/dist/presentation/Stage.d.ts +1 -0
- package/dist/presentation/Stage.js +129 -0
- package/dist/presentation/TransitionSnapshot.d.ts +24 -0
- package/dist/presentation/TransitionSnapshot.js +29 -0
- package/dist/presentation/context.d.ts +8 -0
- package/dist/presentation/context.js +70 -0
- package/dist/presentation/inertActions.d.ts +2 -0
- package/dist/presentation/inertActions.js +8 -0
- package/dist/presentation/keyboard.d.ts +2 -0
- package/dist/presentation/keyboard.js +15 -0
- package/dist/presentation/routing.d.ts +16 -0
- package/dist/presentation/routing.js +116 -0
- package/dist/presentation/state.d.ts +6 -0
- package/dist/presentation/state.js +83 -0
- package/dist/presentation/transitions.d.ts +3 -0
- package/dist/presentation/transitions.js +9 -0
- package/dist/presentation/types.d.ts +156 -0
- package/dist/presentation/types.js +57 -0
- package/dist/presentation/useReducedMotion.d.ts +1 -0
- package/dist/presentation/useReducedMotion.js +10 -0
- package/dist/site/Site.d.ts +10 -0
- package/dist/site/Site.js +367 -0
- package/dist/site/SiteStory.d.ts +10 -0
- package/dist/site/SiteStory.js +10 -0
- package/dist/site/context.d.ts +3 -0
- package/dist/site/context.js +3 -0
- package/dist/site/href.d.ts +9 -0
- package/dist/site/href.js +13 -0
- package/dist/site/index.d.ts +5 -0
- package/dist/site/index.js +3 -0
- package/dist/site/track.d.ts +33 -0
- package/dist/site/track.js +76 -0
- package/dist/slides/ChapterGuide.d.ts +2 -0
- package/dist/slides/ChapterGuide.js +10 -0
- package/dist/slides/ChapterRail.d.ts +7 -0
- package/dist/slides/ChapterRail.js +19 -0
- package/dist/slides/SlideFrame.d.ts +13 -0
- package/dist/slides/SlideFrame.js +15 -0
- package/dist/styles.css +1647 -0
- package/dist/walkthrough/StepDescription.d.ts +8 -0
- package/dist/walkthrough/StepDescription.js +10 -0
- package/dist/walkthrough/selectedStep.d.ts +1 -0
- package/dist/walkthrough/selectedStep.js +9 -0
- package/package.json +131 -4
- package/skills/immerslides/SKILL.md +56 -0
- package/skills/immerslides/references/authoring.md +143 -0
- package/skills/immerslides/references/composition.md +105 -0
- package/skills/immerslides/references/features.md +46 -0
- package/skills/immerslides/references/immersive.md +93 -0
- package/skills/immerslides/references/presenter.md +44 -0
- package/skills/immerslides/references/site.md +96 -0
- package/skills/immerslides/references/urls.md +63 -0
- package/skills/immerslides-en/SKILL.md +56 -0
- package/skills/immerslides-en/references/authoring.md +147 -0
- package/skills/immerslides-en/references/composition.md +105 -0
- package/skills/immerslides-en/references/features.md +46 -0
- package/skills/immerslides-en/references/immersive.md +118 -0
- package/skills/immerslides-en/references/presenter.md +44 -0
- package/skills/immerslides-en/references/site.md +96 -0
- package/skills/immerslides-en/references/urls.md +68 -0
- package/starter/.nvmrc +1 -0
- package/starter/index.html +5 -0
- package/starter/package.json +28 -0
- package/starter/public/avvvatars-LICENSE.txt +21 -0
- package/starter/public/favicon.svg +1 -0
- package/starter/public/handout.html +7 -0
- package/starter/site/index.html +5 -0
- package/starter/slides/index.html +5 -0
- package/starter/src/config.ts +7 -0
- package/starter/src/deck.tsx +760 -0
- package/starter/src/examples.ts +115 -0
- package/starter/src/main.tsx +13 -0
- package/starter/src/mount.tsx +8 -0
- package/starter/src/site.tsx +6 -0
- package/starter/src/slides.tsx +6 -0
- package/starter/src/styles.css +301 -0
- package/starter/src/vite-env.d.ts +1 -0
- package/starter/tsconfig.json +13 -0
- package/starter/vite.config.ts +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 dytsou
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,238 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="./starter/public/favicon.svg" alt="immerslides" width="128" height="128" />
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
# immerslides
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+
[](LICENSE)
|
|
12
|
+
|
|
13
|
+
React presentations with immersive code and flow walkthroughs. Build slides from composable React components, step through code and flows one focus at a time, and publish the same deck as a scrolling reading site.
|
|
14
|
+
|
|
15
|
+
**English** | [繁體中文](README.zh-TW.md)
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
|
|
19
|
+
- **Full-page clicks.** One click advances to the next complete slide. Extra steps are added only where a talk needs them.
|
|
20
|
+
- **Immersive code walkthroughs.** `CodeBlock` shows highlighted code, and `CodeWindow` provides the window frame. Syntax highlighting covers languages such as TypeScript, Python, Java, SQL, JSON, YAML, Bash, HTML, and CSS.
|
|
21
|
+
- **Flow timelines.** `Timeline`, `FlowNode`, and `FlowConnector` show processes and their steps.
|
|
22
|
+
- **Presenter mode.** Press `P` to open a window with the current slide, the next slide, speaker notes, and a timer.
|
|
23
|
+
- **Slide navigator.** Press `O` to browse chapters and slides as an outline or as thumbnails, and filter by marked slides.
|
|
24
|
+
- **Shareable URLs.** Every slide and step has a hash URL, such as `/#/code-walkthrough?step=2`. URLs survive reloads and work with browser history.
|
|
25
|
+
- **Scrolling site view.** `Site` and `SiteStory` render the same deck as a long-form reading page.
|
|
26
|
+
- **Reduced motion.** When the user prefers reduced motion, transitions are disabled and all content stays visible.
|
|
27
|
+
- **Agent skill.** A bundled skill helps AI coding agents write and revise decks.
|
|
28
|
+
|
|
29
|
+
## Requirements
|
|
30
|
+
|
|
31
|
+
- Node.js 26 or later (see [`.nvmrc`](.nvmrc))
|
|
32
|
+
- pnpm 12.20.0 (pinned by the `packageManager` field)
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
nvm install
|
|
36
|
+
nvm use
|
|
37
|
+
npm install --global pnpm@12.20.0
|
|
38
|
+
pnpm install
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Quick start: run the demo
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
pnpm dev
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Open the URL that Vite prints. By default this is `http://127.0.0.1:5173/`. The demo is a feature tour that covers layouts, flow diagrams, syntax highlighting, step-by-step focus, composition, presenter mode, and playback. Most slides advance with one click, and slides with extra steps are labeled.
|
|
48
|
+
|
|
49
|
+
The demo lives in [`starter/`](starter/):
|
|
50
|
+
|
|
51
|
+
- `/` shows the view set by `defaultView` in `starter/src/config.ts`.
|
|
52
|
+
- `/slides/` always shows the presentation.
|
|
53
|
+
- `/site/` always shows the scrolling site.
|
|
54
|
+
|
|
55
|
+
## Create a new presentation
|
|
56
|
+
|
|
57
|
+
The package is not yet published to npm. For now, pack this repository and create a project from the tarball:
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
pnpm pack --out immerslides.tgz
|
|
61
|
+
TARBALL="$PWD/immerslides.tgz"
|
|
62
|
+
node bin/immerslides.mjs create ../my-presentation
|
|
63
|
+
cd ../my-presentation
|
|
64
|
+
pnpm add "$TARBALL"
|
|
65
|
+
pnpm dev
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The `create` command copies the starter project and the agent skill into a new directory. It refuses to write into a non-empty directory and does not install dependencies.
|
|
69
|
+
|
|
70
|
+
After the package is published, you will be able to run:
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
pnpm dlx immerslides create my-presentation
|
|
74
|
+
cd my-presentation
|
|
75
|
+
pnpm install
|
|
76
|
+
pnpm dev
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Use with an AI agent
|
|
80
|
+
|
|
81
|
+
New projects include two skills under `.agents/skills/`: `immerslides` (Chinese) and `immerslides-en` (English). In an agent that supports project skills, invoke one of them with a prompt such as:
|
|
82
|
+
|
|
83
|
+
```text
|
|
84
|
+
$immerslides-en Turn this material into a CI talk.
|
|
85
|
+
One click should advance one full slide. Do not split a flow into one click per node.
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The sources are [`skills/immerslides/`](skills/immerslides/) (Chinese) and [`skills/immerslides-en/`](skills/immerslides-en/) (English). Each folder contains a `SKILL.md` and a `references/` directory. Keep the two versions in sync when you change one. To add a skill to an existing project, copy the matching folder to `.agents/skills/` in that project.
|
|
89
|
+
|
|
90
|
+
## Use in a React project
|
|
91
|
+
|
|
92
|
+
Import the player and the styles once, then pass a deck to `Player`:
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
import { Player } from 'immerslides/player';
|
|
96
|
+
import 'immerslides/styles.css';
|
|
97
|
+
import { deck } from './deck';
|
|
98
|
+
|
|
99
|
+
export function App() {
|
|
100
|
+
return <Player deck={deck} />;
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Define the deck with `defineDeck`. It sets the slide order, chapters, and a `RenderSlide` component:
|
|
105
|
+
|
|
106
|
+
```tsx
|
|
107
|
+
import { defineDeck, SlideFrame, type SlideRenderProps } from 'immerslides';
|
|
108
|
+
|
|
109
|
+
function RenderSlide(props: SlideRenderProps) {
|
|
110
|
+
return (
|
|
111
|
+
<SlideFrame {...props} deck={deck} footer="Team talk">
|
|
112
|
+
<h1>Every commit gets feedback</h1>
|
|
113
|
+
</SlideFrame>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export const deck = defineDeck({
|
|
118
|
+
id: 'ci-presentation',
|
|
119
|
+
title: 'CI presentation',
|
|
120
|
+
version: 1,
|
|
121
|
+
size: { width: 1600, height: 900 },
|
|
122
|
+
slides: [
|
|
123
|
+
{ id: 'opening', title: 'Every commit gets feedback', steps: 1 },
|
|
124
|
+
{ id: 'pipeline', title: 'Read the pipeline at a glance', steps: 1 },
|
|
125
|
+
],
|
|
126
|
+
previews: [{ slideId: 'opening' }],
|
|
127
|
+
RenderSlide,
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Use `steps: 1` for a normal slide, which advances with one click. Set a larger `steps` value only when a slide needs focus states. `steps` counts the initial state, so `steps: 2` gives the values `0` and `1`.
|
|
132
|
+
|
|
133
|
+
Each component has its own entry point, so you can import only what you need:
|
|
134
|
+
|
|
135
|
+
| Import | Provides |
|
|
136
|
+
| ----------------------------------------------------------------------------------- | ----------------------------------------------------------- |
|
|
137
|
+
| `immerslides` | Everything below, plus `usePlayback` and `useReducedMotion` |
|
|
138
|
+
| `immerslides/player` | `Player` |
|
|
139
|
+
| `immerslides/deck` | `defineDeck` and the deck types |
|
|
140
|
+
| `immerslides/site` | `Site`, `SiteStory`, `getSiteHref` |
|
|
141
|
+
| `immerslides/slide-frame`, `immerslides/chapter-guide` | `SlideFrame`, `ChapterGuide` |
|
|
142
|
+
| `immerslides/slide-navigator`, `immerslides/slide-preview` | `SlideNavigator`, `SlidePreview` |
|
|
143
|
+
| `immerslides/code-block`, `immerslides/code-window`, `immerslides/highlighted-code` | `CodeBlock`, `CodeWindow`, `HighlightedCode` |
|
|
144
|
+
| `immerslides/timeline`, `immerslides/flow-node`, `immerslides/flow-connector` | `Timeline`, `FlowNode`, `FlowConnector` |
|
|
145
|
+
| `immerslides/step-description` | `StepDescription` |
|
|
146
|
+
| `immerslides/styles.css` | Global styles. Import once. |
|
|
147
|
+
|
|
148
|
+
Standalone components such as `CodeWindow` and `FlowNode` work without the player. For full guides, see:
|
|
149
|
+
|
|
150
|
+
- [Authoring guide](skills/immerslides-en/references/authoring.md): deck definitions and the public API
|
|
151
|
+
- [Features](skills/immerslides-en/references/features.md): what each feature is for
|
|
152
|
+
- [Immersive walkthroughs](skills/immerslides-en/references/immersive.md): step-by-step code and flow focus
|
|
153
|
+
- [Composition](skills/immerslides-en/references/composition.md): custom layouts with the standalone components
|
|
154
|
+
- [Presenter mode](skills/immerslides-en/references/presenter.md): notes, next-slide preview, and timer
|
|
155
|
+
- [Slide URLs](skills/immerslides-en/references/urls.md): slugs, hash URLs, and `getSlideHref`
|
|
156
|
+
- [Site view](skills/immerslides-en/references/site.md): publishing the deck as a reading page
|
|
157
|
+
|
|
158
|
+
The Chinese versions of these guides are in [`skills/immerslides/references/`](skills/immerslides/references/).
|
|
159
|
+
|
|
160
|
+
## Localization
|
|
161
|
+
|
|
162
|
+
The player, presenter view, navigator, and site support `zh-Hant` (the default) and `en`. Pass `locale` to `Player` or `Site`:
|
|
163
|
+
|
|
164
|
+
```tsx
|
|
165
|
+
export function App() {
|
|
166
|
+
return <Player deck={deck} locale="en" />;
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Translate slide titles, notes, chapter titles, and the handout with `translations` in `defineDeck`, keyed by locale. Text without a translation falls back to the authored text. Links are built from the authored titles, so they are the same in every language. Slide renderers receive `locale`, and `useI18n()` gives your own components the current `locale` and a translator `t` for the built-in interface text.
|
|
171
|
+
|
|
172
|
+
## Playback controls
|
|
173
|
+
|
|
174
|
+
| Key | Action |
|
|
175
|
+
| ------------------- | -------------------------------------------------------- |
|
|
176
|
+
| → or Space | Next step. By default, this advances to the next slide. |
|
|
177
|
+
| ← | Previous slide, or the previous explicitly defined step. |
|
|
178
|
+
| Page Down / Page Up | Jump to the next or previous full slide. |
|
|
179
|
+
| Digits, then Enter | Jump to a slide number. Esc cancels. |
|
|
180
|
+
| `O` | Open the chapter and slide navigator. |
|
|
181
|
+
| `F` | Toggle fullscreen. |
|
|
182
|
+
| `P` | Open or focus the presenter window. |
|
|
183
|
+
| `?` | Open the help dialog. |
|
|
184
|
+
| Esc | Close menus. |
|
|
185
|
+
|
|
186
|
+
Reloading restores the slide and step from the URL. If the URL does not name a slide, the player restores the progress saved in the same tab. Pass `fresh` to `Player` (`<Player deck={deck} fresh />`) to start from the beginning instead.
|
|
187
|
+
|
|
188
|
+
## Deploy
|
|
189
|
+
|
|
190
|
+
The production build is a static site with a page for the player (`/`, `/slides/`) and the reading view (`/site/`). Deploy the entire build output directory to any static host, and keep the subfolders intact.
|
|
191
|
+
|
|
192
|
+
## Development
|
|
193
|
+
|
|
194
|
+
Run these commands from the repository root:
|
|
195
|
+
|
|
196
|
+
| Command | Purpose |
|
|
197
|
+
| ----------------------- | -------------------------------------------------------------------- |
|
|
198
|
+
| `pnpm dev` | Run the demo deck |
|
|
199
|
+
| `pnpm build` | Build the library into `dist/` |
|
|
200
|
+
| `pnpm typecheck` | Run the TypeScript compiler without emitting files |
|
|
201
|
+
| `pnpm lint` | Run Biome checks for code, React rules, formatting, and import order |
|
|
202
|
+
| `pnpm lint:fix` | Apply the Biome fixes that are safe to apply automatically |
|
|
203
|
+
| `pnpm test` | Run unit tests with Vitest |
|
|
204
|
+
| `pnpm test:browser` | Run end-to-end tests with Playwright |
|
|
205
|
+
| `pnpm test:package` | Build the package and verify the installed result |
|
|
206
|
+
| `pnpm generate:favicon` | Regenerate the favicon |
|
|
207
|
+
|
|
208
|
+
Browser tests need a Chromium build for Playwright. Install it once with `pnpm exec playwright install --with-deps chromium`.
|
|
209
|
+
|
|
210
|
+
Project layout:
|
|
211
|
+
|
|
212
|
+
- `src/`: the library source (components, player, presenter, and site view)
|
|
213
|
+
- `bin/`: the `immerslides` CLI, which provides `create`
|
|
214
|
+
- `starter/`: the project template that the CLI copies, and the demo app for `pnpm dev`
|
|
215
|
+
- `skills/immerslides/`: the agent skill and its reference documents
|
|
216
|
+
- `tests/`: Vitest unit tests and Playwright browser tests
|
|
217
|
+
- `scripts/`: build, package smoke test, and favicon generation
|
|
218
|
+
|
|
219
|
+
## Continuous integration
|
|
220
|
+
|
|
221
|
+
Pull requests and pushes to `main` run [`verify.yml`](.github/workflows/verify.yml). It runs lint, type checks, unit tests, package verification, and the Chromium browser tests. CodeQL analyzes JavaScript and TypeScript. For private repositories, GitHub Code Security must be enabled first. Dependabot checks the root project, the starter, and GitHub Actions every week.
|
|
222
|
+
|
|
223
|
+
## Releasing
|
|
224
|
+
|
|
225
|
+
The **Release** workflow is started manually from `main`. It runs the shared verification, publishes to npm and GitHub Packages, and creates a GitHub Release.
|
|
226
|
+
|
|
227
|
+
Before the first release:
|
|
228
|
+
|
|
229
|
+
1. Create an `npm` environment in the GitHub repository that allows deployments only from `main`. Add required reviewers if you want a manual approval step.
|
|
230
|
+
2. Add an `NPM_TOKEN` secret to that environment. The token must be allowed to publish `immerslides`.
|
|
231
|
+
3. Make sure the repository's `GITHUB_TOKEN` can write packages, and that the organization allows packages under the scope.
|
|
232
|
+
4. Commit the version you want to release in `package.json`. The release creates the tag `v<version>`.
|
|
233
|
+
|
|
234
|
+
On GitHub Packages, the package is published as `@<repository-owner>/immerslides`. The scope uses the lowercase name of the repository owner. Both registries receive the same build.
|
|
235
|
+
|
|
236
|
+
## License
|
|
237
|
+
|
|
238
|
+
This project is licensed under the MIT License. See [LICENSE](LICENSE).
|
package/README.zh-TW.md
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="./starter/public/favicon.svg" alt="immerslides" width="128" height="128" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
# immerslides
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+
[](LICENSE)
|
|
12
|
+
|
|
13
|
+
[English](README.md) | **繁體中文**
|
|
14
|
+
|
|
15
|
+
使用 React 製作沉浸式簡報,搭配可組合元件、簡報者模式與可重用的 agent skill。
|
|
16
|
+
|
|
17
|
+
## 預覽範例
|
|
18
|
+
|
|
19
|
+
需要 Node.js 26 以上與 pnpm 12。專案與 starter 都提供 `.nvmrc`,並以 `packageManager` 固定 pnpm 版本。
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
nvm install
|
|
23
|
+
nvm use
|
|
24
|
+
npm install --global pnpm@12.20.0
|
|
25
|
+
pnpm install
|
|
26
|
+
pnpm build
|
|
27
|
+
pnpm dev
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
開啟終端機顯示的 Vite 網址。範例是一份功能導覽,讓你查看版型、流程圖、語法上色、逐段聚焦、自由組合、簡報者模式與播放能力,再決定哪些適合自己的教材。大部分頁面一次點擊換頁,另有明確標示的分段示範。
|
|
31
|
+
|
|
32
|
+
同一份 deck 也能向下捲動閱讀。`/slides/` 固定開啟簡報,`/site/` 固定開啟直向網站,`/` 依 `starter/src/config.ts` 的 `defaultView` 決定。網站使用 `immerslides/site` 的 `Site` 元件,說明見 [site.md](skills/immerslides/references/site.md)。
|
|
33
|
+
|
|
34
|
+
## 從本機套件建立簡報
|
|
35
|
+
|
|
36
|
+
套件目前尚未發佈至 npm。先在這個 repository 打包。
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
pnpm pack --out immerslides.tgz
|
|
40
|
+
immerslides_package_tarball="$PWD/immerslides.tgz"
|
|
41
|
+
node bin/immerslides.mjs create /tmp/my-presentation
|
|
42
|
+
cd /tmp/my-presentation
|
|
43
|
+
pnpm add "$immerslides_package_tarball"
|
|
44
|
+
pnpm dev
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
將 tarball 路徑換成實際檔案位置。建立指令不會安裝依賴,也不會覆寫非空目錄。產生的專案使用公開的 `immerslides` 套件入口,不依賴這個 repository 的參考資料。
|
|
48
|
+
|
|
49
|
+
套件發佈後可使用以下指令。
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
pnpm dlx immerslides create my-presentation
|
|
53
|
+
cd my-presentation
|
|
54
|
+
pnpm install
|
|
55
|
+
pnpm dev
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## 使用對應的 skill
|
|
59
|
+
|
|
60
|
+
新專案會自動包含兩個 skill:中文版 `.agents/skills/immerslides/` 與英文版 `.agents/skills/immerslides-en/`。在該專案開啟支援 project skills 的 agent,選擇其中一個,例如使用以下提示。
|
|
61
|
+
|
|
62
|
+
```text
|
|
63
|
+
$immerslides 請把這份教材整理成一份 CI 技術簡報。
|
|
64
|
+
一次點擊切換一個完整頁面,流程不要逐節點拆開。
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
維護用的來源分別是 [skills/immerslides/](skills/immerslides/)(中文)與 [skills/immerslides-en/](skills/immerslides-en/)(英文),兩者都包含 `SKILL.md` 與 `references/`。修改其中一版時請同步另一版。CLI 會將兩者與各自的參考文件一起複製到新專案。既有專案也可將對應的資料夾複製至該專案的 `.agents/skills/`。
|
|
68
|
+
|
|
69
|
+
Skill 會先安排每頁的完整觀點,再使用套件元件撰寫 JSX。它保留整頁為主的點擊節奏,並要求檢查實際瀏覽器畫面、縮放與鍵盤播放。
|
|
70
|
+
|
|
71
|
+
## 在 React 專案使用
|
|
72
|
+
|
|
73
|
+
```tsx
|
|
74
|
+
import { Player } from 'immerslides/player';
|
|
75
|
+
import 'immerslides/styles.css';
|
|
76
|
+
import { deck } from './deck';
|
|
77
|
+
|
|
78
|
+
export function App() {
|
|
79
|
+
return <Player deck={deck} />;
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
使用 `defineDeck` 定義頁面順序、章節與 renderer。每頁設定 `steps: 1` 即為一次前進換頁。需要少量分段時再明確增加 `steps`。
|
|
84
|
+
|
|
85
|
+
每個元件都有獨立入口,可只匯入需要的部分。
|
|
86
|
+
|
|
87
|
+
```tsx
|
|
88
|
+
import { CodeWindow } from 'immerslides/code-window';
|
|
89
|
+
import { HighlightedCode } from 'immerslides/highlighted-code';
|
|
90
|
+
import { FlowNode } from 'immerslides/flow-node';
|
|
91
|
+
import type { CodeWindowProps } from 'immerslides/code-window';
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`CodeWindow`、`FlowNode` 等基礎元件可直接使用,不需要播放器。單獨匯入外框不會載入語法上色或播放核心。既有的 `import { CodeWindow } from 'immerslides'` 也可繼續使用。完整入口見 [元件組合指南](skills/immerslides/references/composition.md)。樣式統一由 `immerslides/styles.css` 匯入。
|
|
95
|
+
|
|
96
|
+
完整範例與公開介面見 [製作指南](skills/immerslides/references/authoring.md)。支援範圍與使用時機見 [功能表](skills/immerslides/references/features.md)。
|
|
97
|
+
|
|
98
|
+
程式碼與流程的分段聚焦範例見 [沉浸式講解](skills/immerslides/references/immersive.md)。CodeBlock 支援 `language` 指定語法,例如 TypeScript、Python、Java、SQL、JSON、YAML、Bash、HTML 與 CSS。
|
|
99
|
+
|
|
100
|
+
需要自己安排版面時,使用 [自由組合元件](skills/immerslides/references/composition.md)。`CodeWindow`、`HighlightedCode`、`StepDescription`、`FlowNode` 與 `FlowConnector` 可分開使用,並共用同一份講解步驟。
|
|
101
|
+
|
|
102
|
+
按 `P` 開啟 [簡報者模式](skills/immerslides/references/presenter.md),查看目前畫面、下一個畫面、講稿與計時。講稿使用每頁可選的 `notes` 欄位。
|
|
103
|
+
|
|
104
|
+
每頁都有 [可分享的 slug 網址](skills/immerslides/references/urls.md),例如 `/#/code-walkthrough?step=2`。網址會隨換頁與分段更新,支援重新整理與瀏覽器上一頁、下一頁。Slug 可明確指定,也會從標題與章節大綱產生。
|
|
105
|
+
|
|
106
|
+
也可使用 `/#/15` 直接前往第 15 頁。放映時直接鍵入頁數,或編輯下方目前頁數,再按 Enter 跳頁。Esc 或離開輸入框取消。純數字網址代表頁數,自訂 slug 使用 `chapter-1` 等名稱。
|
|
107
|
+
|
|
108
|
+
按 `O` 開啟「章節與投影片」。文字大綱以章節與投影片的樹狀結構呈現,可展開或收合;未分章頁面直接列出。切到「縮圖預覽」可依畫面挑選頁面。選擇的模式會保留,關閉選單或重新整理後仍可沿用。目前頁面符合篩選時,開啟選單或切換模式會捲到該頁並標示選取狀態;選取其他頁面後同步更新網址。
|
|
109
|
+
|
|
110
|
+
範例工具列的 ☆ 可標記目前頁面。點旁邊的數量會開啟同一個「章節與投影片」視窗,並套用「已標記」篩選。文字大綱與縮圖都可篩選,保留原始頁碼並隱藏空章節。滑鼠移到頁面時,右上角會顯示星星,可標記或取消;點頁面本身即可查看。鍵盤聚焦也會顯示星星,觸控裝置則直接顯示。標記保留於本次播放,重新整理或從頭開始會清除。
|
|
111
|
+
|
|
112
|
+
## 多語言
|
|
113
|
+
|
|
114
|
+
播放器、簡報者模式、導覽與網站的介面支援 `zh-Hant`(預設)與 `en`。在 `Player` 或 `Site` 傳入 `locale` 即可切換。
|
|
115
|
+
|
|
116
|
+
投影片標題、備註、章節與講義可在 `defineDeck` 的 `translations` 依語言翻譯,沒有翻譯的文字沿用原始內容。網址由原始標題產生,因此各語言的連結相同。詳見 [authoring.md](skills/immerslides/references/authoring.md)。
|
|
117
|
+
|
|
118
|
+
## 播放操作
|
|
119
|
+
|
|
120
|
+
| 按鍵 | 功能 |
|
|
121
|
+
| ------------------ | ---------------------------------- |
|
|
122
|
+
| →/Space | 前進。預設切換下一頁。 |
|
|
123
|
+
| ← | 返回上一頁或上一個明確設定的步驟。 |
|
|
124
|
+
| Page Down/Page Up | 直接切換整頁。 |
|
|
125
|
+
| 數字,再按 Enter | 輸入頁數跳頁。Esc 取消。 |
|
|
126
|
+
| O | 開啟章節與頁面選單。 |
|
|
127
|
+
| F | 切換全螢幕。 |
|
|
128
|
+
| P | 開啟或聚焦簡報者視窗。 |
|
|
129
|
+
| ? | 開啟說明與從頭開始。 |
|
|
130
|
+
| Esc | 關閉選單。 |
|
|
131
|
+
|
|
132
|
+
重新整理會優先恢復網址指定的投影片與步驟。未指定網址時沿用同一分頁保存的進度,`<Player deck={deck} fresh/>` 則從封面開始。使用者啟用減少動態效果時,播放器停用轉場並保留完整內容。
|
|
133
|
+
|
|
134
|
+
## 驗證
|
|
135
|
+
|
|
136
|
+
```sh
|
|
137
|
+
pnpm lint
|
|
138
|
+
pnpm test
|
|
139
|
+
pnpm typecheck
|
|
140
|
+
pnpm build
|
|
141
|
+
pnpm test:package
|
|
142
|
+
pnpm test:browser
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
`pnpm lint` 使用 Biome 檢查程式碼、React 規則、排版與匯入順序。`pnpm lint:fix` 套用可安全自動修正的項目。
|
|
146
|
+
|
|
147
|
+
規則保留明確的 effect 生命週期觸發、非空斷言、動畫索引與既有 CSS 優先序,仍會阻擋遺漏的 effect 依賴。原生 dialog 取消、子控制項冒泡的焦點、按鈕群組與 React 測試 fixture 採檔案範圍的規則例外。產生的 favicon 不納入檢查。
|
|
148
|
+
|
|
149
|
+
## GitHub 自動化
|
|
150
|
+
|
|
151
|
+
Pull request 與推送至 `main` 會執行 lint、型別、單元、套件安裝與 Chromium 播放檢查。CI 與發佈前檢查共用 `.github/workflows/verify.yml`。
|
|
152
|
+
|
|
153
|
+
Dependabot 每週檢查主專案、starter 與 GitHub Actions 的依賴。CodeQL 在 pull request 與 `main` 更新時分析 JavaScript 與 TypeScript。私人 repository 需先啟用 GitHub Code Security,才能使用 CodeQL。
|
|
154
|
+
|
|
155
|
+
## 發佈套件
|
|
156
|
+
|
|
157
|
+
發佈使用 [Release GitHub & NPM](https://github.com/marketplace/actions/release-github-npm)。流程僅能從 `main` 手動啟動,先執行共用檢查,再依序發佈 npm、GitHub Packages 與 GitHub Release。
|
|
158
|
+
|
|
159
|
+
npm 名稱維持 `immerslides`。GitHub Packages 名稱為 `@<repository-owner>/immerslides`,scope 自動使用 repository 擁有者的小寫名稱。兩個 registry 使用同一份建置內容。Workflow 在 runner 暫時切換套件名稱與 repository 資訊;GitHub Packages 步驟結束後,無論成功與否都還原原始 manifest。
|
|
160
|
+
|
|
161
|
+
1. 在 GitHub repository 建立 `npm` environment,限制僅允許 `main` 部署;需要人工核准時設定 required reviewers。
|
|
162
|
+
2. 在該 environment 新增 `NPM_TOKEN` secret,使用有權發佈 `immerslides` 的 npm token。
|
|
163
|
+
3. 確認 repository 的 `GITHUB_TOKEN` 可寫入 GitHub Packages。Workflow 已為發佈工作設定 `packages: write`;組織仍須允許建立該 scope 的套件。
|
|
164
|
+
4. 提交要發佈的 `package.json` 版本。首次發佈前先確認 npm 套件名稱與授權。
|
|
165
|
+
5. 開啟 Actions 的 **Release** workflow,選擇 `main` 並執行。
|
|
166
|
+
|
|
167
|
+
版本取自 `package.json`,對應標籤為 `v<version>`。同名標籤若已指向其他 commit,流程會停止。已存在的 registry 版本沿用 Action 的略過機制。GitHub Release 包含 commit notes,穩定版會將 `v<major>` 標籤移到本次發佈的 commit。
|
|
168
|
+
|
|
169
|
+
從 GitHub Packages 使用套件時,先設定該 scope 的 registry 與具備 `read:packages` 的登入權限。CLI 產生的專案會透過 npm alias 將 scoped 套件對應為 `immerslides`,原有元件匯入方式保持相同。產生專案後,該專案也需要相同的 scope registry 設定。
|
|
170
|
+
|
|
171
|
+
## 授權
|
|
172
|
+
|
|
173
|
+
本專案採用 MIT 授權條款。詳見 [LICENSE](LICENSE)。
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
cp,
|
|
4
|
+
lstat,
|
|
5
|
+
mkdir,
|
|
6
|
+
readdir,
|
|
7
|
+
readFile,
|
|
8
|
+
writeFile,
|
|
9
|
+
} from 'node:fs/promises';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { fileURLToPath } from 'node:url';
|
|
12
|
+
|
|
13
|
+
const root = fileURLToPath(new URL('../', import.meta.url));
|
|
14
|
+
const metadata = JSON.parse(
|
|
15
|
+
await readFile(path.join(root, 'package.json'), 'utf8'),
|
|
16
|
+
);
|
|
17
|
+
const args = process.argv.slice(2);
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
if (
|
|
21
|
+
args.length === 0 ||
|
|
22
|
+
(args.length === 1 && ['--help', '-h'].includes(args[0]))
|
|
23
|
+
) {
|
|
24
|
+
console.log(
|
|
25
|
+
'Usage: immerslides create <directory>\nCreates a React/Vite presentation and its project skill.',
|
|
26
|
+
);
|
|
27
|
+
} else if (args.length === 1 && args[0] === '--version') {
|
|
28
|
+
console.log(metadata.version);
|
|
29
|
+
} else {
|
|
30
|
+
if (
|
|
31
|
+
args.length !== 2 ||
|
|
32
|
+
args[0] !== 'create' ||
|
|
33
|
+
!args[1] ||
|
|
34
|
+
args[1].startsWith('-')
|
|
35
|
+
)
|
|
36
|
+
throw new Error('Usage: immerslides create <directory>');
|
|
37
|
+
const destination = path.resolve(args[1]);
|
|
38
|
+
const existing = await lstat(destination).catch((error) => {
|
|
39
|
+
if (error.code !== 'ENOENT') throw error;
|
|
40
|
+
});
|
|
41
|
+
if (
|
|
42
|
+
existing &&
|
|
43
|
+
(!existing.isDirectory() || (await readdir(destination)).length > 0)
|
|
44
|
+
)
|
|
45
|
+
throw new Error(
|
|
46
|
+
'The destination must be a new or empty directory. Existing files were not changed.',
|
|
47
|
+
);
|
|
48
|
+
const skills = ['immerslides', 'immerslides-en'];
|
|
49
|
+
for (const name of skills)
|
|
50
|
+
await readFile(path.join(root, 'skills', name, 'SKILL.md'));
|
|
51
|
+
await mkdir(destination, { recursive: true });
|
|
52
|
+
const starter = path.join(root, 'starter');
|
|
53
|
+
for (const entry of await readdir(starter)) {
|
|
54
|
+
await cp(path.join(starter, entry), path.join(destination, entry), {
|
|
55
|
+
recursive: true,
|
|
56
|
+
force: false,
|
|
57
|
+
errorOnExist: true,
|
|
58
|
+
filter: (source) =>
|
|
59
|
+
!['node_modules', 'dist'].includes(path.basename(source)),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
for (const name of skills)
|
|
63
|
+
await cp(
|
|
64
|
+
path.join(root, 'skills', name),
|
|
65
|
+
path.join(destination, '.agents/skills', name),
|
|
66
|
+
{ recursive: true, force: false, errorOnExist: true },
|
|
67
|
+
);
|
|
68
|
+
const projectPath = path.join(destination, 'package.json');
|
|
69
|
+
const project = JSON.parse(await readFile(projectPath, 'utf8'));
|
|
70
|
+
project.name =
|
|
71
|
+
path
|
|
72
|
+
.basename(destination)
|
|
73
|
+
.toLowerCase()
|
|
74
|
+
.replace(/[^a-z0-9-]/g, '-')
|
|
75
|
+
.replace(/^-+|-+$/g, '') || 'my-immerslides';
|
|
76
|
+
project.dependencies.immerslides =
|
|
77
|
+
metadata.name === 'immerslides'
|
|
78
|
+
? `^${metadata.version}`
|
|
79
|
+
: `npm:${metadata.name}@^${metadata.version}`;
|
|
80
|
+
await writeFile(projectPath, JSON.stringify(project, null, 2) + '\n');
|
|
81
|
+
await writeFile(
|
|
82
|
+
path.join(destination, '.gitignore'),
|
|
83
|
+
'node_modules/\ndist/\n.DS_Store\n',
|
|
84
|
+
);
|
|
85
|
+
const shellDirectory = "'" + destination.replaceAll("'", "'\\''") + "'";
|
|
86
|
+
console.log(
|
|
87
|
+
`Created ${destination}\n\nRun:\n cd ${shellDirectory}\n pnpm install\n pnpm dev\n\nUse $immerslides (Chinese) or $immerslides-en (English) to create or revise the presentation.`,
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
} catch (error) {
|
|
91
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
92
|
+
process.exitCode = 1;
|
|
93
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type CodeLineRange } from './highlighting.js';
|
|
2
|
+
export type { CodeLineRange } from './highlighting.js';
|
|
3
|
+
export type CodeStep = {
|
|
4
|
+
title: string;
|
|
5
|
+
detail?: string;
|
|
6
|
+
lines: readonly CodeLineRange[];
|
|
7
|
+
};
|
|
8
|
+
export type CodeBlockProps = {
|
|
9
|
+
children: string;
|
|
10
|
+
filename?: string;
|
|
11
|
+
language?: string;
|
|
12
|
+
steps?: readonly CodeStep[];
|
|
13
|
+
step?: number;
|
|
14
|
+
still?: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare function CodeBlock({ children, filename, language, steps, step, still, }: CodeBlockProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { StepDescription } from '../walkthrough/StepDescription.js';
|
|
3
|
+
import { selectedStep } from '../walkthrough/selectedStep.js';
|
|
4
|
+
import { CodeWindow } from './CodeWindow.js';
|
|
5
|
+
import { HighlightedCode } from './HighlightedCode.js';
|
|
6
|
+
import { validateCodeRanges } from './highlighting.js';
|
|
7
|
+
export function CodeBlock({ children, filename, language, steps, step = 0, still = false, }) {
|
|
8
|
+
const focus = selectedStep(steps, step);
|
|
9
|
+
if (steps) {
|
|
10
|
+
const lineCount = children.split('\n').length;
|
|
11
|
+
for (const entry of steps)
|
|
12
|
+
validateCodeRanges(entry.lines, lineCount);
|
|
13
|
+
}
|
|
14
|
+
const code = (_jsx(CodeWindow, { filename: filename, children: _jsx(HighlightedCode, { language: language, focus: focus?.lines, still: still, children: children }) }));
|
|
15
|
+
return focus ? (_jsxs("div", { className: "immerslides-walkthrough immerslides-code-walkthrough", "data-step": step, "data-still": still || undefined, children: [code, _jsx(StepDescription, { title: focus.title, step: step, count: steps.length, children: focus.detail })] })) : (code);
|
|
16
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type CodeLineRange } from './highlighting.js';
|
|
2
|
+
export type { CodeLineRange } from './highlighting.js';
|
|
3
|
+
export type HighlightedCodeProps = {
|
|
4
|
+
children: string;
|
|
5
|
+
language?: string;
|
|
6
|
+
focus?: readonly CodeLineRange[];
|
|
7
|
+
still?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare function HighlightedCode({ children, language, focus, still, }: HighlightedCodeProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment, useEffect, useMemo, useRef } from 'react';
|
|
3
|
+
import { useI18n } from '../i18n/context.js';
|
|
4
|
+
import { useReducedMotion } from '../presentation/useReducedMotion.js';
|
|
5
|
+
import { highlightLines, validateCodeRanges, } from './highlighting.js';
|
|
6
|
+
export function HighlightedCode({ children, language, focus, still = false, }) {
|
|
7
|
+
const lines = useMemo(() => highlightLines(children, language), [children, language]);
|
|
8
|
+
if (focus)
|
|
9
|
+
validateCodeRanges(focus, lines.length);
|
|
10
|
+
const pre = useRef(null);
|
|
11
|
+
const reducedMotion = useReducedMotion();
|
|
12
|
+
const { t } = useI18n();
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const element = pre.current;
|
|
15
|
+
const first = element?.querySelector('[data-focused="true"]');
|
|
16
|
+
if (!element || !first)
|
|
17
|
+
return;
|
|
18
|
+
const top = first.offsetTop + Number.parseFloat(getComputedStyle(element).paddingTop);
|
|
19
|
+
const end = Math.max(...focus.map(([, end]) => end));
|
|
20
|
+
const last = element.querySelector(`[data-line="${end}"]`);
|
|
21
|
+
const height = last.offsetTop + last.offsetHeight - first.offsetTop;
|
|
22
|
+
const scrollTop = Math.max(0, top - Math.max(0, (element.clientHeight - height) / 2));
|
|
23
|
+
element.scrollTo({
|
|
24
|
+
top: scrollTop,
|
|
25
|
+
behavior: still || reducedMotion ? 'instant' : 'smooth',
|
|
26
|
+
});
|
|
27
|
+
}, [focus, still, reducedMotion, children]);
|
|
28
|
+
return (_jsx("pre", { role: "region", className: "immerslides-code-content", "data-language": language, "data-still": still || undefined, ref: pre, tabIndex: 0, "aria-label": t('code.label'), children: _jsxs("code", { children: [focus?.map(([start, end], index) => (_jsx("span", { className: "immerslides-code-focus", "aria-hidden": true, style: {
|
|
29
|
+
transform: `translateY(${(start - 1) * 1.6}em)`,
|
|
30
|
+
height: `${(end - start + 1) * 1.6}em`,
|
|
31
|
+
} }, index))), lines.map((tokens, lineIndex) => {
|
|
32
|
+
const number = lineIndex + 1;
|
|
33
|
+
const focused = focus?.some(([start, end]) => number >= start && number <= end);
|
|
34
|
+
return (_jsxs(Fragment, { children: [_jsx("span", { className: "immerslides-code-line", "data-line": number, "data-focused": focused, children: tokens.map((token, tokenIndex) => (_jsx("span", { className: token.className, children: token.text }, tokenIndex))) }), lineIndex < lines.length - 1 ? '\n' : null] }, number));
|
|
35
|
+
})] }) }));
|
|
36
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type Token = {
|
|
2
|
+
text: string;
|
|
3
|
+
className?: string;
|
|
4
|
+
};
|
|
5
|
+
export type CodeLineRange = readonly [number, number];
|
|
6
|
+
export declare function validateCodeRanges(ranges: readonly CodeLineRange[], lineCount: number): void;
|
|
7
|
+
export declare function highlightLines(source: string, language?: string): Token[][];
|
|
8
|
+
export {};
|