@incremark/svelte 0.2.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.
Files changed (79) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +91 -0
  3. package/dist/ThemeProvider.svelte +52 -0
  4. package/dist/ThemeProvider.svelte.d.ts +21 -0
  5. package/dist/ThemeProvider.svelte.d.ts.map +1 -0
  6. package/dist/components/AutoScrollContainer.svelte +163 -0
  7. package/dist/components/AutoScrollContainer.svelte.d.ts +17 -0
  8. package/dist/components/AutoScrollContainer.svelte.d.ts.map +1 -0
  9. package/dist/components/Incremark.svelte +183 -0
  10. package/dist/components/Incremark.svelte.d.ts +24 -0
  11. package/dist/components/Incremark.svelte.d.ts.map +1 -0
  12. package/dist/components/IncremarkBlockquote.svelte +30 -0
  13. package/dist/components/IncremarkBlockquote.svelte.d.ts +12 -0
  14. package/dist/components/IncremarkBlockquote.svelte.d.ts.map +1 -0
  15. package/dist/components/IncremarkCode.svelte +275 -0
  16. package/dist/components/IncremarkCode.svelte.d.ts +18 -0
  17. package/dist/components/IncremarkCode.svelte.d.ts.map +1 -0
  18. package/dist/components/IncremarkDefault.svelte +24 -0
  19. package/dist/components/IncremarkDefault.svelte.d.ts +12 -0
  20. package/dist/components/IncremarkDefault.svelte.d.ts.map +1 -0
  21. package/dist/components/IncremarkFootnotes.svelte +84 -0
  22. package/dist/components/IncremarkFootnotes.svelte.d.ts +4 -0
  23. package/dist/components/IncremarkFootnotes.svelte.d.ts.map +1 -0
  24. package/dist/components/IncremarkHeading.svelte +35 -0
  25. package/dist/components/IncremarkHeading.svelte.d.ts +12 -0
  26. package/dist/components/IncremarkHeading.svelte.d.ts.map +1 -0
  27. package/dist/components/IncremarkHtmlElement.svelte +138 -0
  28. package/dist/components/IncremarkHtmlElement.svelte.d.ts +27 -0
  29. package/dist/components/IncremarkHtmlElement.svelte.d.ts.map +1 -0
  30. package/dist/components/IncremarkInline.svelte +233 -0
  31. package/dist/components/IncremarkInline.svelte.d.ts +13 -0
  32. package/dist/components/IncremarkInline.svelte.d.ts.map +1 -0
  33. package/dist/components/IncremarkList.svelte +85 -0
  34. package/dist/components/IncremarkList.svelte.d.ts +12 -0
  35. package/dist/components/IncremarkList.svelte.d.ts.map +1 -0
  36. package/dist/components/IncremarkMath.svelte +137 -0
  37. package/dist/components/IncremarkMath.svelte.d.ts +24 -0
  38. package/dist/components/IncremarkMath.svelte.d.ts.map +1 -0
  39. package/dist/components/IncremarkParagraph.svelte +24 -0
  40. package/dist/components/IncremarkParagraph.svelte.d.ts +12 -0
  41. package/dist/components/IncremarkParagraph.svelte.d.ts.map +1 -0
  42. package/dist/components/IncremarkRenderer.svelte +70 -0
  43. package/dist/components/IncremarkRenderer.svelte.d.ts +12 -0
  44. package/dist/components/IncremarkRenderer.svelte.d.ts.map +1 -0
  45. package/dist/components/IncremarkTable.svelte +79 -0
  46. package/dist/components/IncremarkTable.svelte.d.ts +12 -0
  47. package/dist/components/IncremarkTable.svelte.d.ts.map +1 -0
  48. package/dist/components/IncremarkThematicBreak.svelte +11 -0
  49. package/dist/components/IncremarkThematicBreak.svelte.d.ts +19 -0
  50. package/dist/components/IncremarkThematicBreak.svelte.d.ts.map +1 -0
  51. package/dist/components/index.d.ts +21 -0
  52. package/dist/components/index.d.ts.map +1 -0
  53. package/dist/components/index.js +19 -0
  54. package/dist/components/types.d.ts +18 -0
  55. package/dist/components/types.d.ts.map +1 -0
  56. package/dist/components/types.js +5 -0
  57. package/dist/context/definitionsContext.d.ts +64 -0
  58. package/dist/context/definitionsContext.d.ts.map +1 -0
  59. package/dist/context/definitionsContext.js +117 -0
  60. package/dist/index.d.ts +15 -0
  61. package/dist/index.d.ts.map +1 -0
  62. package/dist/index.js +19 -0
  63. package/dist/stores/useBlockTransformer.d.ts +89 -0
  64. package/dist/stores/useBlockTransformer.d.ts.map +1 -0
  65. package/dist/stores/useBlockTransformer.js +110 -0
  66. package/dist/stores/useDevTools.d.ts +33 -0
  67. package/dist/stores/useDevTools.d.ts.map +1 -0
  68. package/dist/stores/useDevTools.js +53 -0
  69. package/dist/stores/useIncremark.d.ts +128 -0
  70. package/dist/stores/useIncremark.d.ts.map +1 -0
  71. package/dist/stores/useIncremark.js +177 -0
  72. package/dist/stores/useTypewriter.d.ts +42 -0
  73. package/dist/stores/useTypewriter.d.ts.map +1 -0
  74. package/dist/stores/useTypewriter.js +153 -0
  75. package/dist/svelte-runes.d.ts +32 -0
  76. package/dist/utils/cursor.d.ts +14 -0
  77. package/dist/utils/cursor.d.ts.map +1 -0
  78. package/dist/utils/cursor.js +36 -0
  79. package/package.json +70 -0
@@ -0,0 +1,79 @@
1
+ <!--
2
+ @file IncremarkTable.svelte - 表格组件
3
+ @description 渲染 Markdown 表格
4
+ -->
5
+
6
+ <script lang="ts">
7
+ import type { Table, TableCell, PhrasingContent } from 'mdast'
8
+ import IncremarkInline from './IncremarkInline.svelte'
9
+
10
+ /**
11
+ * 组件 Props
12
+ */
13
+ interface Props {
14
+ /** 表格节点 */
15
+ node: Table
16
+ }
17
+
18
+ let { node }: Props = $props()
19
+
20
+ /**
21
+ * 获取单元格内容
22
+ *
23
+ * @param cell - 单元格节点
24
+ * @returns 行内内容数组
25
+ */
26
+ function getCellContent(cell: TableCell): PhrasingContent[] {
27
+ return cell.children as PhrasingContent[]
28
+ }
29
+
30
+ /**
31
+ * 获取单元格对齐方式
32
+ *
33
+ * @param cellIndex - 单元格索引
34
+ * @returns 对齐方式样式对象
35
+ */
36
+ function getCellAlign(cellIndex: number): { textAlign: string } {
37
+ return {
38
+ textAlign: node.align?.[cellIndex] || 'left'
39
+ }
40
+ }
41
+
42
+ /**
43
+ * 获取表头行(第一行)
44
+ */
45
+ const headerRow = $derived(node.children[0])
46
+
47
+ /**
48
+ * 获取数据行(除第一行外的所有行)
49
+ */
50
+ const bodyRows = $derived(node.children.slice(1))
51
+ </script>
52
+
53
+ <div class="incremark-table-wrapper">
54
+ <table class="incremark-table">
55
+ <thead>
56
+ {#if headerRow}
57
+ <tr>
58
+ {#each headerRow.children as cell, cellIndex (cellIndex)}
59
+ <th style={getCellAlign(cellIndex)}>
60
+ <IncremarkInline nodes={getCellContent(cell)} />
61
+ </th>
62
+ {/each}
63
+ </tr>
64
+ {/if}
65
+ </thead>
66
+ <tbody>
67
+ {#each bodyRows as row, rowIndex (rowIndex)}
68
+ <tr>
69
+ {#each row.children as cell, cellIndex (cellIndex)}
70
+ <td style={getCellAlign(cellIndex)}>
71
+ <IncremarkInline nodes={getCellContent(cell)} />
72
+ </td>
73
+ {/each}
74
+ </tr>
75
+ {/each}
76
+ </tbody>
77
+ </table>
78
+ </div>
79
+
@@ -0,0 +1,12 @@
1
+ import type { Table } from 'mdast';
2
+ /**
3
+ * 组件 Props
4
+ */
5
+ interface Props {
6
+ /** 表格节点 */
7
+ node: Table;
8
+ }
9
+ declare const IncremarkTable: import("svelte").Component<Props, {}, "">;
10
+ type IncremarkTable = ReturnType<typeof IncremarkTable>;
11
+ export default IncremarkTable;
12
+ //# sourceMappingURL=IncremarkTable.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IncremarkTable.svelte.d.ts","sourceRoot":"","sources":["../../src/components/IncremarkTable.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAA8B,MAAM,OAAO,CAAA;AAI5D;;GAEG;AACH,UAAU,KAAK;IACb,WAAW;IACX,IAAI,EAAE,KAAK,CAAA;CACZ;AAyEH,QAAA,MAAM,cAAc,2CAAwC,CAAC;AAC7D,KAAK,cAAc,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AACxD,eAAe,cAAc,CAAC"}
@@ -0,0 +1,11 @@
1
+ <!--
2
+ @file IncremarkThematicBreak.svelte - 分隔线组件
3
+ @description 渲染 Markdown 分隔线
4
+ -->
5
+
6
+ <script lang="ts">
7
+ // ThematicBreak 不需要 props
8
+ </script>
9
+
10
+ <hr class="incremark-hr" />
11
+
@@ -0,0 +1,19 @@
1
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
2
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
3
+ $$bindings?: Bindings;
4
+ } & Exports;
5
+ (internal: unknown, props: {
6
+ $$events?: Events;
7
+ $$slots?: Slots;
8
+ }): Exports & {
9
+ $set?: any;
10
+ $on?: any;
11
+ };
12
+ z_$$bindings?: Bindings;
13
+ }
14
+ declare const IncremarkThematicBreak: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
15
+ [evt: string]: CustomEvent<any>;
16
+ }, {}, {}, string>;
17
+ type IncremarkThematicBreak = InstanceType<typeof IncremarkThematicBreak>;
18
+ export default IncremarkThematicBreak;
19
+ //# sourceMappingURL=IncremarkThematicBreak.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IncremarkThematicBreak.svelte.d.ts","sourceRoot":"","sources":["../../src/components/IncremarkThematicBreak.svelte.ts"],"names":[],"mappings":"AAcA,UAAU,kCAAkC,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,OAAO,GAAG,EAAE,EAAE,QAAQ,GAAG,MAAM;IACpM,KAAK,OAAO,EAAE,OAAO,QAAQ,EAAE,2BAA2B,CAAC,KAAK,CAAC,GAAG,OAAO,QAAQ,EAAE,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG;QAAE,UAAU,CAAC,EAAE,QAAQ,CAAA;KAAE,GAAG,OAAO,CAAC;IACjK,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,KAAK,CAAA;KAAC,GAAG,OAAO,GAAG;QAAE,IAAI,CAAC,EAAE,GAAG,CAAC;QAAC,GAAG,CAAC,EAAE,GAAG,CAAA;KAAE,CAAC;IACtG,YAAY,CAAC,EAAE,QAAQ,CAAC;CAC3B;AAKD,QAAA,MAAM,sBAAsB;;kBAA+E,CAAC;AAC1F,KAAK,sBAAsB,GAAG,YAAY,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAC5E,eAAe,sBAAsB,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @file Components Index - 组件导出
3
+ * @description 导出所有组件
4
+ */
5
+ export { default as Incremark } from './Incremark.svelte';
6
+ export { default as IncremarkParagraph } from './IncremarkParagraph.svelte';
7
+ export { default as IncremarkInline } from './IncremarkInline.svelte';
8
+ export { default as IncremarkHeading } from './IncremarkHeading.svelte';
9
+ export { default as IncremarkCode } from './IncremarkCode.svelte';
10
+ export { default as IncremarkList } from './IncremarkList.svelte';
11
+ export { default as IncremarkTable } from './IncremarkTable.svelte';
12
+ export { default as IncremarkBlockquote } from './IncremarkBlockquote.svelte';
13
+ export { default as IncremarkThematicBreak } from './IncremarkThematicBreak.svelte';
14
+ export { default as IncremarkMath } from './IncremarkMath.svelte';
15
+ export { default as IncremarkHtmlElement } from './IncremarkHtmlElement.svelte';
16
+ export { default as IncremarkFootnotes } from './IncremarkFootnotes.svelte';
17
+ export { default as IncremarkDefault } from './IncremarkDefault.svelte';
18
+ export { default as IncremarkRenderer } from './IncremarkRenderer.svelte';
19
+ export { default as AutoScrollContainer } from './AutoScrollContainer.svelte';
20
+ export type { ComponentMap, BlockWithStableId } from './types';
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAC3E,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,0BAA0B,CAAA;AACrE,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AACvE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACjE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACjE,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACnE,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,8BAA8B,CAAA;AAC7E,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,iCAAiC,CAAA;AACnF,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACjE,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,+BAA+B,CAAA;AAC/E,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAC3E,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AACvE,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AACzE,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,8BAA8B,CAAA;AAE7E,YAAY,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @file Components Index - 组件导出
3
+ * @description 导出所有组件
4
+ */
5
+ export { default as Incremark } from './Incremark.svelte';
6
+ export { default as IncremarkParagraph } from './IncremarkParagraph.svelte';
7
+ export { default as IncremarkInline } from './IncremarkInline.svelte';
8
+ export { default as IncremarkHeading } from './IncremarkHeading.svelte';
9
+ export { default as IncremarkCode } from './IncremarkCode.svelte';
10
+ export { default as IncremarkList } from './IncremarkList.svelte';
11
+ export { default as IncremarkTable } from './IncremarkTable.svelte';
12
+ export { default as IncremarkBlockquote } from './IncremarkBlockquote.svelte';
13
+ export { default as IncremarkThematicBreak } from './IncremarkThematicBreak.svelte';
14
+ export { default as IncremarkMath } from './IncremarkMath.svelte';
15
+ export { default as IncremarkHtmlElement } from './IncremarkHtmlElement.svelte';
16
+ export { default as IncremarkFootnotes } from './IncremarkFootnotes.svelte';
17
+ export { default as IncremarkDefault } from './IncremarkDefault.svelte';
18
+ export { default as IncremarkRenderer } from './IncremarkRenderer.svelte';
19
+ export { default as AutoScrollContainer } from './AutoScrollContainer.svelte';
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @file Component Types - 组件类型定义
3
+ * @description 定义组件相关的类型
4
+ */
5
+ import type { ParsedBlock } from '@incremark/core';
6
+ /**
7
+ * 组件映射类型
8
+ * 使用 any 以支持不同类型的组件
9
+ */
10
+ export type ComponentMap = Partial<Record<string, any>>;
11
+ /**
12
+ * 带稳定 ID 的块类型
13
+ */
14
+ export interface BlockWithStableId extends ParsedBlock {
15
+ stableId: string;
16
+ isLastPending?: boolean;
17
+ }
18
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/components/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAElD;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAA;AAEvD;;GAEG;AACH,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACpD,QAAQ,EAAE,MAAM,CAAA;IAChB,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @file Component Types - 组件类型定义
3
+ * @description 定义组件相关的类型
4
+ */
5
+ export {};
@@ -0,0 +1,64 @@
1
+ /**
2
+ * @file Definitions Context - Svelte Context 实现
3
+ * @description 管理 definitions 和 footnotes 的共享状态,对应 Vue 版本的 provide/inject
4
+ */
5
+ import { type Writable } from 'svelte/store';
6
+ import type { Definition, FootnoteDefinition } from 'mdast';
7
+ /**
8
+ * Definitions Context 值类型
9
+ */
10
+ export interface DefinitionsContextValue {
11
+ /** Definitions 映射 */
12
+ definations: Writable<Record<string, Definition>>;
13
+ /** Footnote definitions 映射 */
14
+ footnoteDefinitions: Writable<Record<string, FootnoteDefinition>>;
15
+ /** Footnote 引用顺序 */
16
+ footnoteReferenceOrder: Writable<string[]>;
17
+ }
18
+ /**
19
+ * 设置 Definitions Context
20
+ *
21
+ * @description
22
+ * 在父组件中调用,为子组件提供 definitions context
23
+ *
24
+ * @returns 返回设置函数,用于更新 context 值
25
+ *
26
+ * @example
27
+ * ```svelte
28
+ * <script>
29
+ * import { setDefinitionsContext } from '@incremark/svelte'
30
+ *
31
+ * const { setDefinations, setFootnoteDefinitions, setFootnoteReferenceOrder } = setDefinitionsContext()
32
+ * </script>
33
+ * ```
34
+ */
35
+ export declare function setDefinitionsContext(): {
36
+ setDefinations: (definitions: Record<string, Definition>) => void;
37
+ setFootnoteDefinitions: (definitions: Record<string, FootnoteDefinition>) => void;
38
+ setFootnoteReferenceOrder: (order: string[]) => void;
39
+ clearDefinations: () => void;
40
+ clearFootnoteDefinitions: () => void;
41
+ clearFootnoteReferenceOrder: () => void;
42
+ clearAllDefinations: () => void;
43
+ };
44
+ /**
45
+ * 获取 Definitions Context
46
+ *
47
+ * @description
48
+ * 在子组件中调用,获取父组件提供的 definitions context
49
+ *
50
+ * @returns Definitions context 值
51
+ *
52
+ * @throws 如果 context 不存在,抛出错误
53
+ *
54
+ * @example
55
+ * ```svelte
56
+ * <script>
57
+ * import { getDefinitionsContext } from '@incremark/svelte'
58
+ *
59
+ * const { definations, footnoteDefinitions, footnoteReferenceOrder } = getDefinitionsContext()
60
+ * </script>
61
+ * ```
62
+ */
63
+ export declare function getDefinitionsContext(): DefinitionsContextValue;
64
+ //# sourceMappingURL=definitionsContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definitionsContext.d.ts","sourceRoot":"","sources":["../../src/context/definitionsContext.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAA;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAA;AAE3D;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,qBAAqB;IACrB,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAA;IACjD,8BAA8B;IAC9B,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAA;IACjE,oBAAoB;IACpB,sBAAsB,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;CAC3C;AAOD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,qBAAqB;kCAgBE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;0CAOlB,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC;uCAOrC,MAAM,EAAE;;;;;EA2CnD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,qBAAqB,IAAI,uBAAuB,CAQ/D"}
@@ -0,0 +1,117 @@
1
+ /**
2
+ * @file Definitions Context - Svelte Context 实现
3
+ * @description 管理 definitions 和 footnotes 的共享状态,对应 Vue 版本的 provide/inject
4
+ */
5
+ import { setContext, getContext } from 'svelte';
6
+ import { writable } from 'svelte/store';
7
+ /**
8
+ * Context key
9
+ */
10
+ const DEFINITIONS_CONTEXT_KEY = Symbol('definitionsContext');
11
+ /**
12
+ * 设置 Definitions Context
13
+ *
14
+ * @description
15
+ * 在父组件中调用,为子组件提供 definitions context
16
+ *
17
+ * @returns 返回设置函数,用于更新 context 值
18
+ *
19
+ * @example
20
+ * ```svelte
21
+ * <script>
22
+ * import { setDefinitionsContext } from '@incremark/svelte'
23
+ *
24
+ * const { setDefinations, setFootnoteDefinitions, setFootnoteReferenceOrder } = setDefinitionsContext()
25
+ * </script>
26
+ * ```
27
+ */
28
+ export function setDefinitionsContext() {
29
+ const definations = writable({});
30
+ const footnoteDefinitions = writable({});
31
+ const footnoteReferenceOrder = writable([]);
32
+ const contextValue = {
33
+ definations,
34
+ footnoteDefinitions,
35
+ footnoteReferenceOrder
36
+ };
37
+ setContext(DEFINITIONS_CONTEXT_KEY, contextValue);
38
+ /**
39
+ * 设置 definitions
40
+ */
41
+ function setDefinations(definitions) {
42
+ definations.set(definitions);
43
+ }
44
+ /**
45
+ * 设置 footnote definitions
46
+ */
47
+ function setFootnoteDefinitions(definitions) {
48
+ footnoteDefinitions.set(definitions);
49
+ }
50
+ /**
51
+ * 设置 footnote 引用顺序
52
+ */
53
+ function setFootnoteReferenceOrder(order) {
54
+ footnoteReferenceOrder.set(order);
55
+ }
56
+ /**
57
+ * 清空 definitions
58
+ */
59
+ function clearDefinations() {
60
+ definations.set({});
61
+ }
62
+ /**
63
+ * 清空 footnote definitions
64
+ */
65
+ function clearFootnoteDefinitions() {
66
+ footnoteDefinitions.set({});
67
+ }
68
+ /**
69
+ * 清空 footnote 引用顺序
70
+ */
71
+ function clearFootnoteReferenceOrder() {
72
+ footnoteReferenceOrder.set([]);
73
+ }
74
+ /**
75
+ * 清空所有 definitions
76
+ */
77
+ function clearAllDefinations() {
78
+ clearDefinations();
79
+ clearFootnoteDefinitions();
80
+ clearFootnoteReferenceOrder();
81
+ }
82
+ return {
83
+ setDefinations,
84
+ setFootnoteDefinitions,
85
+ setFootnoteReferenceOrder,
86
+ clearDefinations,
87
+ clearFootnoteDefinitions,
88
+ clearFootnoteReferenceOrder,
89
+ clearAllDefinations
90
+ };
91
+ }
92
+ /**
93
+ * 获取 Definitions Context
94
+ *
95
+ * @description
96
+ * 在子组件中调用,获取父组件提供的 definitions context
97
+ *
98
+ * @returns Definitions context 值
99
+ *
100
+ * @throws 如果 context 不存在,抛出错误
101
+ *
102
+ * @example
103
+ * ```svelte
104
+ * <script>
105
+ * import { getDefinitionsContext } from '@incremark/svelte'
106
+ *
107
+ * const { definations, footnoteDefinitions, footnoteReferenceOrder } = getDefinitionsContext()
108
+ * </script>
109
+ * ```
110
+ */
111
+ export function getDefinitionsContext() {
112
+ const context = getContext(DEFINITIONS_CONTEXT_KEY);
113
+ if (!context) {
114
+ throw new Error('DefinitionsContext not found. Make sure to call setDefinitionsContext() in a parent component.');
115
+ }
116
+ return context;
117
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @file @incremark/svelte 主入口文件
3
+ * @description Svelte 5 集成库的导出入口
4
+ */
5
+ export { useIncremark, type UseIncremarkOptions, type UseIncremarkReturn, type TypewriterOptions, type TypewriterControls } from './stores/useIncremark';
6
+ export { useDevTools, type UseDevToolsOptions } from './stores/useDevTools';
7
+ export { useBlockTransformer, type UseBlockTransformerOptions, type UseBlockTransformerReturn } from './stores/useBlockTransformer';
8
+ export { setDefinitionsContext, getDefinitionsContext, type DefinitionsContextValue } from './context/definitionsContext';
9
+ export { Incremark, IncremarkParagraph, IncremarkInline, IncremarkHeading, IncremarkCode, IncremarkList, IncremarkTable, IncremarkBlockquote, IncremarkThematicBreak, IncremarkMath, IncremarkHtmlElement, IncremarkFootnotes, IncremarkDefault, IncremarkRenderer, type ComponentMap, type BlockWithStableId } from './components';
10
+ export { default as AutoScrollContainer } from './components/AutoScrollContainer.svelte';
11
+ export { default as ThemeProvider } from './ThemeProvider.svelte';
12
+ export type { ParsedBlock, IncrementalUpdate, ParserOptions, BlockStatus, Root, RootContent, SourceBlock, DisplayBlock, TransformerPlugin, TransformerOptions, TransformerState, AnimationEffect } from '@incremark/core';
13
+ export { BlockTransformer, createBlockTransformer, countChars, sliceAst, cloneNode, codeBlockPlugin, mermaidPlugin, imagePlugin, mathPlugin, thematicBreakPlugin, defaultPlugins, allPlugins, createPlugin } from '@incremark/core';
14
+ export { type DesignTokens, defaultTheme, darkTheme, generateCSSVars, mergeTheme, applyTheme } from '@incremark/theme';
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,KAAK,kBAAkB,EAAE,KAAK,iBAAiB,EAAE,KAAK,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AACxJ,OAAO,EAAE,WAAW,EAAE,KAAK,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAC3E,OAAO,EACL,mBAAmB,EACnB,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,EAC/B,MAAM,8BAA8B,CAAA;AAGrC,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,KAAK,uBAAuB,EAAE,MAAM,8BAA8B,CAAA;AAGzH,OAAO,EACL,SAAS,EACT,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,sBAAsB,EACtB,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACvB,MAAM,cAAc,CAAA;AAGrB,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,yCAAyC,CAAA;AACxF,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAGjE,YAAY,EACV,WAAW,EACX,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,IAAI,EACJ,WAAW,EAEX,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EAChB,MAAM,iBAAiB,CAAA;AAGxB,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACtB,UAAU,EACV,QAAQ,EACR,SAAS,EACT,eAAe,EACf,aAAa,EACb,WAAW,EACX,UAAU,EACV,mBAAmB,EACnB,cAAc,EACd,UAAU,EACV,YAAY,EACb,MAAM,iBAAiB,CAAA;AAGxB,OAAO,EACL,KAAK,YAAY,EACjB,YAAY,EACZ,SAAS,EACT,eAAe,EACf,UAAU,EACV,UAAU,EACX,MAAM,kBAAkB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @file @incremark/svelte 主入口文件
3
+ * @description Svelte 5 集成库的导出入口
4
+ */
5
+ // Stores/Utilities
6
+ export { useIncremark } from './stores/useIncremark';
7
+ export { useDevTools } from './stores/useDevTools';
8
+ export { useBlockTransformer } from './stores/useBlockTransformer';
9
+ // Context
10
+ export { setDefinitionsContext, getDefinitionsContext } from './context/definitionsContext';
11
+ // Components
12
+ export { Incremark, IncremarkParagraph, IncremarkInline, IncremarkHeading, IncremarkCode, IncremarkList, IncremarkTable, IncremarkBlockquote, IncremarkThematicBreak, IncremarkMath, IncremarkHtmlElement, IncremarkFootnotes, IncremarkDefault, IncremarkRenderer } from './components';
13
+ // Additional Components
14
+ export { default as AutoScrollContainer } from './components/AutoScrollContainer.svelte';
15
+ export { default as ThemeProvider } from './ThemeProvider.svelte';
16
+ // Re-export transformer utilities and plugins
17
+ export { BlockTransformer, createBlockTransformer, countChars, sliceAst, cloneNode, codeBlockPlugin, mermaidPlugin, imagePlugin, mathPlugin, thematicBreakPlugin, defaultPlugins, allPlugins, createPlugin } from '@incremark/core';
18
+ // Re-export theme utilities
19
+ export { defaultTheme, darkTheme, generateCSSVars, mergeTheme, applyTheme } from '@incremark/theme';
@@ -0,0 +1,89 @@
1
+ /**
2
+ * @file useBlockTransformer Store - 块转换器
3
+ * @description 用于控制 blocks 的逐步显示(打字机效果)
4
+ */
5
+ import { type Readable } from 'svelte/store';
6
+ import { BlockTransformer, type TransformerOptions, type DisplayBlock, type SourceBlock, type AnimationEffect } from '@incremark/core';
7
+ /**
8
+ * useBlockTransformer 选项
9
+ */
10
+ export interface UseBlockTransformerOptions extends Omit<TransformerOptions, 'onChange'> {
11
+ }
12
+ /**
13
+ * useBlockTransformer 返回值
14
+ */
15
+ export interface UseBlockTransformerReturn<T = unknown> {
16
+ /** 用于渲染的 display blocks */
17
+ displayBlocks: Readable<DisplayBlock<T>[]>;
18
+ /** 是否正在处理中 */
19
+ isProcessing: Readable<boolean>;
20
+ /** 是否已暂停 */
21
+ isPaused: Readable<boolean>;
22
+ /** 当前动画效果 */
23
+ effect: Readable<AnimationEffect>;
24
+ /** 跳过所有动画 */
25
+ skip: () => void;
26
+ /** 重置状态 */
27
+ reset: () => void;
28
+ /** 暂停动画 */
29
+ pause: () => void;
30
+ /** 恢复动画 */
31
+ resume: () => void;
32
+ /** 动态更新配置 */
33
+ setOptions: (options: Partial<Pick<TransformerOptions, 'charsPerTick' | 'tickInterval' | 'effect' | 'pauseOnHidden'>>) => void;
34
+ /** transformer 实例(用于高级用法) */
35
+ transformer: BlockTransformer<T>;
36
+ }
37
+ /**
38
+ * Svelte 5 Store: Block Transformer
39
+ *
40
+ * @description
41
+ * 用于控制 blocks 的逐步显示(打字机效果)
42
+ * 作为解析器和渲染器之间的中间层
43
+ *
44
+ * 特性:
45
+ * - 使用 requestAnimationFrame 实现流畅动画
46
+ * - 支持随机步长 `charsPerTick: [1, 3]`
47
+ * - 支持动画效果 `effect: 'typing'`
48
+ * - 页面不可见时自动暂停
49
+ *
50
+ * @param sourceBlocks - 源 blocks store
51
+ * @param options - 转换器选项
52
+ * @returns 转换器状态和控制对象
53
+ *
54
+ * @example
55
+ * ```svelte
56
+ * <script>
57
+ * import { useIncremark, useBlockTransformer, defaultPlugins } from '@incremark/svelte'
58
+ * import { derived } from 'svelte/store'
59
+ *
60
+ * const { completedBlocks, append, finalize } = useIncremark()
61
+ *
62
+ * // 使用 completedBlocks 作为输入(ID 稳定)
63
+ * const sourceBlocks = derived(completedBlocks, ($blocks) =>
64
+ * $blocks.map(b => ({
65
+ * id: b.id,
66
+ * node: b.node,
67
+ * status: b.status
68
+ * }))
69
+ * )
70
+ *
71
+ * // 添加打字机效果
72
+ * const { displayBlocks, isProcessing, skip, effect } = useBlockTransformer(sourceBlocks, {
73
+ * charsPerTick: [1, 3],
74
+ * tickInterval: 30,
75
+ * effect: 'typing',
76
+ * plugins: defaultPlugins
77
+ * })
78
+ * </script>
79
+ *
80
+ * <template>
81
+ * <Incremark blocks={$displayBlocks} class:typing={$effect === 'typing'} />
82
+ * {#if $isProcessing}
83
+ * <button on:click={skip}>跳过</button>
84
+ * {/if}
85
+ * </template>
86
+ * ```
87
+ */
88
+ export declare function useBlockTransformer<T = unknown>(sourceBlocks: Readable<SourceBlock<T>[]>, options?: UseBlockTransformerOptions): UseBlockTransformerReturn<T>;
89
+ //# sourceMappingURL=useBlockTransformer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBlockTransformer.d.ts","sourceRoot":"","sources":["../../src/stores/useBlockTransformer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAoC,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAA;AAC9E,OAAO,EACL,gBAAgB,EAEhB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,eAAe,EACrB,MAAM,iBAAiB,CAAA;AAExB;;GAEG;AACH,MAAM,WAAW,0BAA2B,SAAQ,IAAI,CAAC,kBAAkB,EAAE,UAAU,CAAC;CAAG;AAE3F;;GAEG;AACH,MAAM,WAAW,yBAAyB,CAAC,CAAC,GAAG,OAAO;IACpD,2BAA2B;IAC3B,aAAa,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;IAC1C,cAAc;IACd,YAAY,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC/B,YAAY;IACZ,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC3B,aAAa;IACb,MAAM,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAA;IACjC,aAAa;IACb,IAAI,EAAE,MAAM,IAAI,CAAA;IAChB,WAAW;IACX,KAAK,EAAE,MAAM,IAAI,CAAA;IACjB,WAAW;IACX,KAAK,EAAE,MAAM,IAAI,CAAA;IACjB,WAAW;IACX,MAAM,EAAE,MAAM,IAAI,CAAA;IAClB,aAAa;IACb,UAAU,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,kBAAkB,EAAE,cAAc,GAAG,cAAc,GAAG,QAAQ,GAAG,eAAe,CAAC,CAAC,KAAK,IAAI,CAAA;IAC9H,6BAA6B;IAC7B,WAAW,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAA;CACjC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,GAAG,OAAO,EAC7C,YAAY,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,EACxC,OAAO,GAAE,0BAA+B,GACvC,yBAAyB,CAAC,CAAC,CAAC,CAwD9B"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * @file useBlockTransformer Store - 块转换器
3
+ * @description 用于控制 blocks 的逐步显示(打字机效果)
4
+ */
5
+ import { writable, derived } from 'svelte/store';
6
+ import { createBlockTransformer } from '@incremark/core';
7
+ /**
8
+ * Svelte 5 Store: Block Transformer
9
+ *
10
+ * @description
11
+ * 用于控制 blocks 的逐步显示(打字机效果)
12
+ * 作为解析器和渲染器之间的中间层
13
+ *
14
+ * 特性:
15
+ * - 使用 requestAnimationFrame 实现流畅动画
16
+ * - 支持随机步长 `charsPerTick: [1, 3]`
17
+ * - 支持动画效果 `effect: 'typing'`
18
+ * - 页面不可见时自动暂停
19
+ *
20
+ * @param sourceBlocks - 源 blocks store
21
+ * @param options - 转换器选项
22
+ * @returns 转换器状态和控制对象
23
+ *
24
+ * @example
25
+ * ```svelte
26
+ * <script>
27
+ * import { useIncremark, useBlockTransformer, defaultPlugins } from '@incremark/svelte'
28
+ * import { derived } from 'svelte/store'
29
+ *
30
+ * const { completedBlocks, append, finalize } = useIncremark()
31
+ *
32
+ * // 使用 completedBlocks 作为输入(ID 稳定)
33
+ * const sourceBlocks = derived(completedBlocks, ($blocks) =>
34
+ * $blocks.map(b => ({
35
+ * id: b.id,
36
+ * node: b.node,
37
+ * status: b.status
38
+ * }))
39
+ * )
40
+ *
41
+ * // 添加打字机效果
42
+ * const { displayBlocks, isProcessing, skip, effect } = useBlockTransformer(sourceBlocks, {
43
+ * charsPerTick: [1, 3],
44
+ * tickInterval: 30,
45
+ * effect: 'typing',
46
+ * plugins: defaultPlugins
47
+ * })
48
+ * </script>
49
+ *
50
+ * <template>
51
+ * <Incremark blocks={$displayBlocks} class:typing={$effect === 'typing'} />
52
+ * {#if $isProcessing}
53
+ * <button on:click={skip}>跳过</button>
54
+ * {/if}
55
+ * </template>
56
+ * ```
57
+ */
58
+ export function useBlockTransformer(sourceBlocks, options = {}) {
59
+ const displayBlocks = writable([]);
60
+ const isProcessing = writable(false);
61
+ const isPaused = writable(false);
62
+ const effect = writable(options.effect ?? 'none');
63
+ const transformer = createBlockTransformer({
64
+ ...options,
65
+ onChange: (blocks) => {
66
+ displayBlocks.set(blocks);
67
+ isProcessing.set(transformer.isProcessing());
68
+ isPaused.set(transformer.isPausedState());
69
+ }
70
+ });
71
+ // 监听源 blocks 变化
72
+ sourceBlocks.subscribe((blocks) => {
73
+ // 推入新 blocks
74
+ transformer.push(blocks);
75
+ // 处理正在显示的 block 内容更新
76
+ displayBlocks.update((displayBlocksValue) => {
77
+ const currentDisplaying = displayBlocksValue.find((b) => !b.isDisplayComplete);
78
+ if (currentDisplaying) {
79
+ const updated = blocks.find((b) => b.id === currentDisplaying.id);
80
+ if (updated) {
81
+ transformer.update(updated);
82
+ }
83
+ }
84
+ return displayBlocksValue;
85
+ });
86
+ });
87
+ return {
88
+ displayBlocks: derived(displayBlocks, ($blocks) => $blocks),
89
+ isProcessing: derived(isProcessing, ($processing) => $processing),
90
+ isPaused: derived(isPaused, ($paused) => $paused),
91
+ effect: derived(effect, ($effect) => $effect),
92
+ skip: () => transformer.skip(),
93
+ reset: () => transformer.reset(),
94
+ pause: () => {
95
+ transformer.pause();
96
+ isPaused.set(true);
97
+ },
98
+ resume: () => {
99
+ transformer.resume();
100
+ isPaused.set(false);
101
+ },
102
+ setOptions: (opts) => {
103
+ transformer.setOptions(opts);
104
+ if (opts.effect !== undefined) {
105
+ effect.set(opts.effect);
106
+ }
107
+ },
108
+ transformer
109
+ };
110
+ }