@preferred-markdown-stream/core 0.1.9 → 0.2.1

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/README.md CHANGED
@@ -14,15 +14,21 @@ pnpm add @preferred-markdown-stream/core
14
14
  import { splitContent } from '@preferred-markdown-stream/core'
15
15
  ```
16
16
 
17
+ ```ts
18
+ import '@preferred-markdown-stream/core/styles.css'
19
+ ```
20
+
17
21
  ## Public API
18
22
 
19
23
  - `splitContent(message)`
20
- - `addFadeInClassToTreeNodes(children, loading, fadeInClass?)`
21
- - `streamingTextStyles`
24
+ - `addFadeInClassToTreeNodes(children, loading, options?)`
22
25
  - `StreamingTextNode`
26
+ - `FadeInClassOptions`
23
27
 
24
28
  ## Notes
25
29
 
26
30
  - The current implementation keeps the existing behavior from the app.
27
31
  - The core package no longer depends on Vue types.
28
32
  - Vue-specific node adaptation lives in `@preferred-markdown-stream/vue`.
33
+ - Default animation styles are published via `@preferred-markdown-stream/core/styles.css`.
34
+ - Animation duration and timing can be overridden with CSS variables.
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { addFadeInClassToTreeNodes, splitContent, streamingTextStyles, } from './streamingText.js';
2
- export type { StreamingTextNode } from './streamingText.js';
1
+ export { addFadeInClassToTreeNodes, splitContent, } from './streamingText.js';
2
+ export type { FadeInClassOptions, StreamingTextNode, } from './streamingText.js';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { addFadeInClassToTreeNodes, splitContent, streamingTextStyles, } from './streamingText.js';
1
+ export { addFadeInClassToTreeNodes, splitContent, } from './streamingText.js';
@@ -5,6 +5,9 @@ export interface StreamingTextNode {
5
5
  [key: string]: unknown;
6
6
  } | null;
7
7
  }
8
+ export interface FadeInClassOptions {
9
+ className?: string;
10
+ }
8
11
  /**
9
12
  * Smart content splitting to avoid displaying incomplete sentences
10
13
  * Supports both English and Chinese punctuation
@@ -13,9 +16,4 @@ export declare function splitContent(msg: string): string;
13
16
  /**
14
17
  * Add a fade-in class to string-backed nodes in a generic tree structure.
15
18
  */
16
- export declare function addFadeInClassToTreeNodes<T extends StreamingTextNode>(childrenRaw: T[], loading: boolean, fadeInClass?: string): T[];
17
- /**
18
- * CSS styles for streaming text animation
19
- * Can be used in your global styles or component styles
20
- */
21
- export declare const streamingTextStyles = "\n.fade-in {\n opacity: 0;\n animation: fadeIn 1s forwards;\n}\n\n@keyframes fadeIn {\n from {\n opacity: 0;\n }\n to {\n opacity: 1;\n }\n}\n\n.streaming-text-wrapper {\n position: relative;\n}\n\n.streaming-text-wrapper.streaming {\n /* Additional styling for streaming state */\n}\n";
19
+ export declare function addFadeInClassToTreeNodes<T extends StreamingTextNode>(childrenRaw: T[], loading: boolean, options?: string | FadeInClassOptions): T[];
@@ -6,6 +6,13 @@ const TABLE_SEPARATOR_REGEXP = /^\|[\s:|-]+\|$/;
6
6
  const FENCE_DELIMITER_REGEXP = /^(`{3,}|~{3,})/gm;
7
7
  const INLINE_CODE_BACKTICK_REGEXP = /(?<!`)`(?!`)/g;
8
8
  const COMPLETE_INLINE_MARKUP_REGEXP = /^!?\[[^\]]*\]\([^)]*\)/;
9
+ const DEFAULT_FADE_IN_CLASS_NAME = 'preferred-markdown-stream-fade-in';
10
+ function resolveFadeInClassName(options) {
11
+ if (typeof options === 'string') {
12
+ return options;
13
+ }
14
+ return options?.className ?? DEFAULT_FADE_IN_CLASS_NAME;
15
+ }
9
16
  /**
10
17
  * Strip trailing unclosed display-math blocks ($$…) that would render
11
18
  * as plain text because the closing $$ has not arrived yet.
@@ -189,7 +196,7 @@ export function splitContent(msg) {
189
196
  /**
190
197
  * Add a fade-in class to string-backed nodes in a generic tree structure.
191
198
  */
192
- export function addFadeInClassToTreeNodes(childrenRaw, loading, fadeInClass = 'fade-in') {
199
+ function addFadeInClassToTreeNodesWithClassName(childrenRaw, loading, className) {
193
200
  // eslint-disable-next-line unicorn/no-magic-array-flat-depth
194
201
  const children = childrenRaw.flat(20);
195
202
  for (const child of children) {
@@ -207,41 +214,21 @@ export function addFadeInClassToTreeNodes(childrenRaw, loading, fadeInClass = 'f
207
214
  const existingClass = typeof child.props.class === 'string'
208
215
  ? child.props.class
209
216
  : '';
210
- child.props.class = `${existingClass} ${fadeInClass}`.trim();
217
+ child.props.class = `${existingClass} ${className}`.trim();
211
218
  }
212
219
  }
213
220
  if (child.children
214
221
  && Array.isArray(child.children)
215
222
  && child.children.length > 0) {
216
- addFadeInClassToTreeNodes(child.children, loading, fadeInClass);
223
+ addFadeInClassToTreeNodesWithClassName(child.children, loading, className);
217
224
  }
218
225
  }
219
226
  return children;
220
227
  }
221
228
  /**
222
- * CSS styles for streaming text animation
223
- * Can be used in your global styles or component styles
229
+ * Add a fade-in class to string-backed nodes in a generic tree structure.
224
230
  */
225
- export const streamingTextStyles = `
226
- .fade-in {
227
- opacity: 0;
228
- animation: fadeIn 1s forwards;
229
- }
230
-
231
- @keyframes fadeIn {
232
- from {
233
- opacity: 0;
234
- }
235
- to {
236
- opacity: 1;
237
- }
238
- }
239
-
240
- .streaming-text-wrapper {
241
- position: relative;
242
- }
243
-
244
- .streaming-text-wrapper.streaming {
245
- /* Additional styling for streaming state */
231
+ export function addFadeInClassToTreeNodes(childrenRaw, loading, options) {
232
+ const className = resolveFadeInClassName(options);
233
+ return addFadeInClassToTreeNodesWithClassName(childrenRaw, loading, className);
246
234
  }
247
- `;
@@ -0,0 +1,29 @@
1
+ .preferred-markdown-stream-fade-in {
2
+ opacity: 0;
3
+ animation-name: var(
4
+ --preferred-markdown-stream-animation-name,
5
+ preferred-markdown-stream-fade-in
6
+ );
7
+ animation-duration: var(
8
+ --preferred-markdown-stream-animation-duration,
9
+ 1s
10
+ );
11
+ animation-timing-function: var(
12
+ --preferred-markdown-stream-animation-timing-function,
13
+ ease
14
+ );
15
+ animation-fill-mode: var(
16
+ --preferred-markdown-stream-animation-fill-mode,
17
+ forwards
18
+ );
19
+ }
20
+
21
+ @keyframes preferred-markdown-stream-fade-in {
22
+ from {
23
+ opacity: 0;
24
+ }
25
+
26
+ to {
27
+ opacity: 1;
28
+ }
29
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@preferred-markdown-stream/core",
3
3
  "type": "module",
4
- "version": "0.1.9",
4
+ "version": "0.2.1",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Jannchie/preferred-markdown-stream/tree/main/packages/core#readme",
7
7
  "repository": {
@@ -18,6 +18,7 @@
18
18
  "types": "./dist/index.d.ts",
19
19
  "import": "./dist/index.js"
20
20
  },
21
+ "./styles.css": "./dist/styles.css",
21
22
  "./streaming-text": {
22
23
  "types": "./dist/streamingText.d.ts",
23
24
  "import": "./dist/streamingText.js"
@@ -39,7 +40,7 @@
39
40
  "vitest": "^4.1.1"
40
41
  },
41
42
  "scripts": {
42
- "build": "tsc -p ./tsconfig.build.json",
43
+ "build": "tsc -p ./tsconfig.build.json && node ./scripts/copy-assets.mjs",
43
44
  "test": "vitest run --config ./vitest.config.ts",
44
45
  "typecheck": "tsc -p ./tsconfig.json"
45
46
  }