@slidejs/runner-revealjs 0.1.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/src/runner.ts ADDED
@@ -0,0 +1,84 @@
1
+ /**
2
+ * @slidejs/runner-revealjs - SlideRunner 工厂函数
3
+ *
4
+ * 提供创建配置好的 SlideRunner 实例的便捷方法
5
+ */
6
+
7
+ import { parseSlideDSL, compile } from '@slidejs/dsl';
8
+ import { SlideRunner } from '@slidejs/runner';
9
+ import type { SlideContext } from '@slidejs/context';
10
+ import { RevealJsAdapter } from './adapter';
11
+ import type { RevealJsOptions } from './types';
12
+
13
+ /**
14
+ * SlideRunner 配置选项
15
+ */
16
+ export interface SlideRunnerConfig {
17
+ /**
18
+ * 容器选择器或 HTMLElement
19
+ */
20
+ container: string | HTMLElement;
21
+
22
+ /**
23
+ * reveal.js 配置选项
24
+ */
25
+ revealOptions?: RevealJsOptions['revealConfig'];
26
+ }
27
+
28
+ /**
29
+ * 从 DSL 源代码创建并运行 SlideRunner
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * import { createSlideRunner } from '@slidejs/runner-revealjs';
34
+ *
35
+ * const dslSource = `
36
+ * present quiz "demo" {
37
+ * rules {
38
+ * rule start "intro" {
39
+ * slide {
40
+ * content text { "Hello World!" }
41
+ * }
42
+ * }
43
+ * }
44
+ * }
45
+ * `;
46
+ *
47
+ * const context = { sourceType: 'quiz', sourceId: 'demo', items: [] };
48
+ * const runner = await createSlideRunner(dslSource, context, {
49
+ * container: '#app',
50
+ * revealOptions: {
51
+ * controls: true,
52
+ * progress: true,
53
+ * },
54
+ * });
55
+ * ```
56
+ */
57
+ export async function createSlideRunner<TContext extends SlideContext = SlideContext>(
58
+ dslSource: string,
59
+ context: TContext,
60
+ config: SlideRunnerConfig
61
+ ): Promise<SlideRunner<TContext>> {
62
+ // 1. 解析 DSL
63
+ const ast = await parseSlideDSL(dslSource);
64
+
65
+ // 2. 编译为 SlideDSL
66
+ const slideDSL = compile<TContext>(ast);
67
+
68
+ // 3. 创建适配器和 Runner
69
+ const adapter = new RevealJsAdapter();
70
+ const runner = new SlideRunner<TContext>({
71
+ container: config.container,
72
+ adapter,
73
+ adapterOptions: {
74
+ revealConfig: config.revealOptions,
75
+ },
76
+ });
77
+
78
+ // 4. 运行演示(这会初始化适配器并渲染幻灯片)
79
+ await runner.run(slideDSL, context);
80
+
81
+ // 注意:需要手动调用 runner.play() 来启动演示(导航到第一张幻灯片)
82
+ // 返回 runner 以便用户可以控制演示
83
+ return runner;
84
+ }
package/src/style.css ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @slidejs/runner-revealjs - reveal.js 核心样式
3
+ *
4
+ * 此文件导入 reveal.js 的核心 CSS,用户只需导入此包即可获得所有必需的样式。
5
+ * 主题样式需要单独导入(可选)。
6
+ *
7
+ * 使用示例:
8
+ * ```typescript
9
+ * import '@slidejs/runner-revealjs';
10
+ * // 或显式导入样式
11
+ * import '@slidejs/runner-revealjs/style.css';
12
+ * ```
13
+ */
14
+
15
+ /* 导入 reveal.js 核心 CSS */
16
+ @import 'reveal.js/dist/reveal.css';
17
+
package/src/types.ts ADDED
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @slidejs/runner-revealjs - 类型定义
3
+ *
4
+ * 定义 reveal.js 适配器的选项和配置
5
+ */
6
+
7
+ import type Reveal from 'reveal.js';
8
+ import type { AdapterOptions } from '@slidejs/runner';
9
+
10
+ /**
11
+ * RevealJsAdapter 选项
12
+ *
13
+ * 主题通过静态导入加载:
14
+ * ```typescript
15
+ * import 'reveal.js/dist/theme/black.css';
16
+ * ```
17
+ */
18
+ export interface RevealJsOptions extends AdapterOptions {
19
+ /**
20
+ * reveal.js 配置
21
+ * @see https://revealjs.com/config/
22
+ */
23
+ revealConfig?: Reveal.Options;
24
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src",
6
+ "composite": true,
7
+ "declarationMap": true
8
+ },
9
+ "include": ["src/**/*"],
10
+ "exclude": ["**/*.test.ts", "dist", "node_modules"],
11
+ "references": [{ "path": "../core" }, { "path": "../runner" }]
12
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,44 @@
1
+ import { defineConfig } from 'vite';
2
+ import dts from 'vite-plugin-dts';
3
+ import { resolve } from 'path';
4
+
5
+ export default defineConfig({
6
+ build: {
7
+ lib: {
8
+ entry: resolve(__dirname, 'src/index.ts'),
9
+ name: 'SlideJsRevealJs',
10
+ formats: ['es', 'cjs'],
11
+ fileName: (format) => `index.${format === 'es' ? 'js' : 'cjs'}`,
12
+ },
13
+ rollupOptions: {
14
+ external: [
15
+ '@slidejs/core',
16
+ '@slidejs/runner',
17
+ '@slidejs/dsl',
18
+ '@slidejs/context',
19
+ 'reveal.js',
20
+ // Only externalize JS modules from reveal.js, NOT CSS
21
+ /^reveal\.js\/.*\.js$/,
22
+ ],
23
+ output: {
24
+ // 确保 CSS 文件被正确提取
25
+ assetFileNames: (assetInfo) => {
26
+ if (assetInfo.name === 'style.css') {
27
+ return 'style.css';
28
+ }
29
+ return assetInfo.name || 'assets/[name].[ext]';
30
+ },
31
+ },
32
+ },
33
+ sourcemap: true,
34
+ // 确保 CSS 被提取到单独的文件
35
+ cssCodeSplit: false,
36
+ },
37
+ plugins: [
38
+ dts({
39
+ include: ['src/**/*'],
40
+ exclude: ['**/*.test.ts', 'src/themes/**/*'],
41
+ rollupTypes: true,
42
+ }),
43
+ ],
44
+ });