@minjun0219/mdwire 0.1.10 → 0.1.11

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/js/react.d.ts CHANGED
@@ -2,32 +2,32 @@ import type { ElementType, ReactElement, ReactNode } from "react";
2
2
  import type { MdTag } from "./events.js";
3
3
  import type { RenderOptions } from "@minjun0219/mdwire";
4
4
 
5
- /** 태그별로 갈아 끼울 컴포넌트 — 예: `{ a: MyLink, code: CodeBlock }`. 받는 props 는 그 태그의 것이다. */
5
+ /** Components that replace individual tags, e.g. `{ a: MyLink, code: CodeBlock }`. Each receives that tag's props. */
6
6
  export type MdComponents = Partial<Record<MdTag, ElementType>>;
7
7
 
8
8
  export interface MarkdownProps {
9
- /** 에이전트가 쓴 마크다운(완성된 글). 스트리밍은 `Streamer` + `toElements` 로 — 누적본을 매번 넘기면 처음부터 다시 변환한다. */
9
+ /** Markdown written by the agent (complete text). For streaming, use `Streamer` + `toElements`; passing the accumulated output each time reconverts it from scratch. */
10
10
  text: string;
11
11
  components?: MdComponents;
12
- /** 코어에 넘길 옵션 — `html` 정책(줄바꿈·이미지·스킴)이 여기 든다. */
12
+ /** Options passed to the core. The `html` policy (line breaks, images, schemes) goes here. */
13
13
  options?: RenderOptions;
14
14
  }
15
15
 
16
- /** 마크다운을 React 요소로 그린다. innerHTML 을 쓰지 않는다. */
16
+ /** Renders markdown as React elements. Does not use innerHTML. */
17
17
  export function Markdown(props: MarkdownProps): ReactElement;
18
18
 
19
19
  export interface MarkdownStreamOptions {
20
20
  components?: MdComponents;
21
21
  options?: RenderOptions;
22
- /** 붙든 것(열린 강조·표 행·코드 스팬)도 먼저 그린다. 기본 `true`. `false` 면 확정된 것만. */
22
+ /** Also draw what is held back (open emphasis, table rows, code spans) ahead of time. Default `true`. With `false`, only final output is shown. */
23
23
  eager?: boolean;
24
- /** 끝났을 때. `revised` 는 완성본이 마지막 화면과 다른가 — 거짓이면 훅은 다시 그리지 않는다. */
24
+ /** Called when done. `revised` tells whether the final output differs from the last screen; if false, the hook does not redraw. */
25
25
  onSettled?: (html: string, revised: boolean) => void;
26
26
  }
27
27
 
28
28
  /**
29
- * 스트리밍용 훅 — 토큰마다 `push`, 끝나면 `finish`. 기본은 붙든 것도 먼저 그린다(`eager`).
30
- * `onSettled` 말고는 처음 한 번만 읽는다.
29
+ * Hook for streaming: call `push` for each token and `finish` at the end. By default it also draws what is held back (`eager`).
30
+ * Options other than `onSettled` are read only once, on first render.
31
31
  */
32
32
  export function useMarkdownStream(opts?: MarkdownStreamOptions): {
33
33
  elements: ReactElement;
@@ -35,6 +35,6 @@ export function useMarkdownStream(opts?: MarkdownStreamOptions): {
35
35
  finish(): void;
36
36
  };
37
37
 
38
- /** html 채널 출력(스트리밍이면 누적본 + `preview()` 또는 `closeOpen()`)을 React 노드로 바꾼다. */
39
- /** `schemes` 는 코어에 준 `options.html.schemes` 와 같게 준다. 기본 `["http", "https", "mailto"]`. */
38
+ /** Converts html channel output (when streaming, the accumulated output + `preview()` or `closeOpen()`) into React nodes. */
39
+ /** Pass the same `schemes` you gave the core as `options.html.schemes`. Default `["http", "https", "mailto"]`. */
40
40
  export function toElements(html: string, components?: MdComponents, schemes?: string[]): ReactNode[];
package/js/react.js CHANGED
@@ -40,11 +40,11 @@ function propsOf(tag, attrs, key, schemes) {
40
40
  }
41
41
 
42
42
  /**
43
- * html 채널 출력을 React 노드 배열로 바꾼다. 스트리밍 누적본을 직접 다루는 쪽이 쓴다 —
44
- * `toElements(acc + streamer.closeOpen())`.
43
+ * Converts html channel output into an array of React nodes. Use it when you handle the
44
+ * accumulated stream output yourself: `toElements(acc + streamer.closeOpen())`.
45
45
  * @param {string} html
46
- * @param {Partial<Record<string, import("react").ElementType>>} [components] 태그별로 갈아 끼울 컴포넌트.
47
- * @param {string[]} [schemes] 링크·이미지로 받는 스킴. 코어에 준 `options.html.schemes` 와 같게.
46
+ * @param {Partial<Record<string, import("react").ElementType>>} [components] Components that replace individual tags.
47
+ * @param {string[]} [schemes] Schemes allowed for links and images. Same as the `options.html.schemes` given to the core.
48
48
  */
49
49
  export function toElements(html, components = {}, schemes = DEFAULT_SCHEMES) {
50
50
  const root = { tag: null, children: [] };
@@ -84,9 +84,9 @@ export function toElements(html, components = {}, schemes = DEFAULT_SCHEMES) {
84
84
  }
85
85
 
86
86
  /**
87
- * 에이전트 마크다운을 그린다 — 완성된 글용. 스트리밍 중인 누적본을 토큰마다 넘기면 매번
88
- * 처음부터 다시 변환해 전체 비용이 제곱으로 늘고, 반쪽 마커(`**굵`, 여는 백틱, `##`)가 잠깐 글자로
89
- * 보였다가 사라진다. 스트리밍은 [`useMarkdownStream`].
87
+ * Renders agent markdown, for complete text. If you pass the accumulated stream on every token,
88
+ * it reconverts from scratch each time, so total cost grows quadratically, and half-written markers
89
+ * (`**bo`, an opening backtick, `##`) briefly show up as text and then vanish. For streaming, use [`useMarkdownStream`].
90
90
  * @param {import("./react.d.ts").MarkdownProps} props
91
91
  */
92
92
  export function Markdown({ text, components, options }) {
@@ -95,15 +95,16 @@ export function Markdown({ text, components, options }) {
95
95
  }
96
96
 
97
97
  /**
98
- * 스트리밍용 훅. 토큰이 오는 대로 `push(chunk)`, 끝나면 `finish()`.
98
+ * Hook for streaming. Call `push(chunk)` as tokens arrive and `finish()` at the end.
99
99
  *
100
- * 기본(`eager: true`)은 **붙든 것도 먼저 그린다** — 열린 강조는 닫아서, 표는 지금까지 온 행으로,
101
- * 코드 스팬은 닫아서(`Streamer.preview()`). 추측이라 뒤 토큰이 모양을 바꿀 수 있지만 완성본은
102
- * 일괄 변환과 같다. `eager: false` 면 확정된 것만 보인다(append-only, SPEC 8.2) — 짝이 안 맞은
103
- * 강조·판정 전 접두사는 확정될 때 나온다.
100
+ * By default (`eager: true`) it **also draws what is held back**: open emphasis closed, tables with
101
+ * the rows received so far, code spans closed (`Streamer.preview()`). This is a guess, so later tokens
102
+ * may change the shape, but the final output matches a one-shot conversion. With `eager: false`, only
103
+ * final output is shown (append-only, SPEC 8.2): unmatched emphasis and prefixes not yet decided
104
+ * appear once they become final.
104
105
  *
105
- * 끝나면 `onSettled(html, revised)` — `revised` 는 완성본이 마지막으로 **화면에 그려진** 것과
106
- * 다른가다. 같으면 훅은 다시 그리지 않는다.
106
+ * At the end it calls `onSettled(html, revised)`. `revised` tells whether the final output differs
107
+ * from what was last **drawn on screen**. If they match, the hook does not redraw.
107
108
  * @param {import("./react.d.ts").MarkdownStreamOptions} [opts]
108
109
  */
109
110
  export function useMarkdownStream({ components, options, eager = true, onSettled } = {}) {
package/node/mdwire.d.ts CHANGED
@@ -1,17 +1,17 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
 
4
- /** 변환 옵션. 생략하면 채널의 기본값이다. */
4
+ /** Conversion options. Anything omitted uses the channel's default. */
5
5
  export interface RenderOptions {
6
- /** 조각 한도(글자 수). 생략하면 채널의 한도다 — plain 을 텔레그램에 보내면 4096. 스트리밍은 나누지 않는다. */
6
+ /** Part size limit (in characters). Defaults to the channel's limit; for example, 4096 when sending plain to Telegram. Streaming does not split. */
7
7
  limit?: number;
8
- /** 브라우저 채널("html")의 정책. 기본값이 가장 보수적이다. */
8
+ /** Policy for the browser channel ("html"). The defaults are the most conservative. */
9
9
  html?: {
10
- /** 블록 안 줄바꿈. "br"(기본) 은 `<br>`, "space" 는 브라우저가 공백으로 접게 둔다. */
10
+ /** Line breaks inside a block. "br" (default) emits `<br>`; "space" lets the browser collapse them into spaces. */
11
11
  lineBreaks?: "br" | "space";
12
- /** 이미지. "link"(기본) 는 누르기 전에 아무것도 안 불러온다, "load" 는 `<img>`. */
12
+ /** Images. "link" (default) loads nothing until clicked; "load" emits `<img>`. */
13
13
  images?: "link" | "load";
14
- /** 링크·이미지 주소로 받는 스킴(콜론 없이). 주면 그것만 받는다. 기본 ["http","https","mailto"]. */
14
+ /** Schemes allowed in link and image URLs (without the colon). If given, only these are allowed. Default ["http","https","mailto"]. */
15
15
  schemes?: string[];
16
16
  };
17
17
  }
@@ -19,133 +19,136 @@ export interface RenderOptions {
19
19
 
20
20
 
21
21
  /**
22
- * `renderWithReport` 의 결과.
22
+ * The result of `renderWithReport`.
23
23
  */
24
24
  export class Rendered {
25
25
  private constructor();
26
26
  free(): void;
27
27
  [Symbol.dispose](): void;
28
28
  /**
29
- * 조각들. 한도를 넘지 않았으면 하나다.
29
+ * The parts. Just one if the text fit within the limit.
30
30
  */
31
31
  readonly parts: string[];
32
32
  /**
33
- * 정규화가 고친 것.
33
+ * What normalization repaired.
34
34
  */
35
35
  readonly repairs: Repairs;
36
36
  }
37
37
 
38
38
  /**
39
- * 정규화가 고친 것과 채널에 맞춰 바꾼 것의 개수.
39
+ * Counts of what normalization repaired and what was changed to fit the channel.
40
40
  */
41
41
  export class Repairs {
42
42
  private constructor();
43
43
  free(): void;
44
44
  [Symbol.dispose](): void;
45
45
  /**
46
- * 블록이 끝나도록 안 닫혀서 닫아 준 강조.
46
+ * Emphasis left open at the end of a block, closed for you.
47
47
  */
48
48
  closedEmphasis: number;
49
49
  /**
50
- * 문서 끝까지 안 닫혀서 닫아 준 코드펜스.
50
+ * Code fences left open at the end of the document, closed for you.
51
51
  */
52
52
  closedFence: number;
53
53
  /**
54
- * 다른 표기로 바꿔 쓴 강조 마커와 `<url|텍스트>` 링크.
54
+ * Emphasis markers and `<url|text>` links rewritten in a different notation.
55
55
  */
56
56
  convertedMarker: number;
57
57
  /**
58
- * 짝 잃은 채 버린 `**`.
58
+ * Unmatched `**` markers that were dropped.
59
59
  */
60
60
  droppedMarker: number;
61
61
  /**
62
- * 채널이 구문으로 읽을 글자를 이스케이프한 수(GitHub 의 `\~`·`\<`·`\*`).
62
+ * Characters escaped because the channel would read them as syntax (GitHub's `\~`, `\<`, `\*`).
63
63
  */
64
64
  escapedChar: number;
65
65
  /**
66
- * 짝이 없어 글자로 되돌린 백틱 런.
66
+ * Unmatched backtick runs, turned back into literal text.
67
67
  */
68
68
  revertedCodeSpan: number;
69
69
  /**
70
- * 다른 기호로 바꿔 쓴 목록 불릿.
70
+ * List bullets rewritten with a different symbol.
71
71
  */
72
72
  rewrittenBullet: number;
73
73
  /**
74
- * 원문과 다른 모양으로 다시 쓴 표.
74
+ * Tables rewritten in a different shape from the source.
75
75
  */
76
76
  rewrittenTable: number;
77
77
  /**
78
- * 벗긴 원문 HTML(태그·주석·줄바꿈으로 바꾼 `<br>`).
78
+ * Raw HTML stripped from the source (tags, comments, and `<br>` turned into line breaks).
79
79
  */
80
80
  strippedHtml: number;
81
81
  /**
82
- * 채널이 마커로 못 읽는 자리라 다르게 낸 강조(GitHub 의 `<strong>`, 슬랙의 U+2060).
82
+ * Emphasis emitted differently because the channel would not read the marker in that position (GitHub's `<strong>`, Slack's U+2060).
83
83
  */
84
84
  tagEmphasis: number;
85
85
  }
86
86
 
87
87
  /**
88
- * 스트리밍 변환기.
88
+ * Streaming converter.
89
89
  *
90
- * 조각을 넣으면 지금 안전하게 내보낼 수 있는 만큼만 돌려준다. 경계에 걸린 마크업은
91
- * 안에 남는다 — 토큰이 흘러들어오는 대로 화면에 붙이는 쪽이 이것 때문에 쓴다.
90
+ * Push a chunk and it returns only what is safe to emit now. Markup cut off at the
91
+ * chunk boundary stays inside. This is what you want when appending tokens to the
92
+ * screen as they arrive.
92
93
  */
93
94
  export class Streamer {
94
95
  free(): void;
95
96
  [Symbol.dispose](): void;
96
97
  /**
97
- * **지금까지 받은 것을 그대로 보내려면 이걸 뒤에 붙인다.**
98
+ * **To send what you have received so far as is, append this after it.**
98
99
  *
99
- * 상태는 건드리지 않으므로 붙인 뒤에도 스트리밍은 이어진다. 누적본 자체에는
100
- * 넣지 말고, 보내기 직전에만 붙인다. 토큰이 오는 대로 메시지를 편집하는 쪽이 쓴다.
100
+ * It does not touch the state, so streaming continues afterwards. Do not add it
101
+ * to the accumulated output itself; append it only right before sending. Use it
102
+ * when editing a message as tokens arrive.
101
103
  *
102
104
  * ```js
103
105
  * acc += s.push(chunk);
104
- * await edit(acc + s.closeOpen()); // 누적본은 그대로 둔다
106
+ * await edit(acc + s.closeOpen()); // leave acc unchanged
105
107
  * ```
106
108
  */
107
109
  closeOpen(): string;
108
110
  /**
109
- * 입력이 끝났다. 남은 것을 내보내고 열린 마크업을 닫는다.
111
+ * Input has ended. Emits what is left and closes open markup.
110
112
  */
111
113
  finish(): string;
112
114
  constructor(channel: string, options?: RenderOptions | null);
113
115
  /**
114
- * **지금 입력이 끝났다면 확정분 뒤에 붙을 꼬리.** `closeOpen` 과 같은 자리에 들어가지만
115
- * 붙들고 있던 것(열린 강조, 표 행, 코드 스팬)까지 그린다. 누적본을 통째로 다시 그리는 쪽의
116
- * 기본값이다. 추측이라 뒤 조각이 모양을 바꿀 수 있다 — 끝난 뒤 `revised()` 로 본다.
116
+ * **The tail that would follow the final output if input ended now.** It goes in the
117
+ * same place as `closeOpen`, but also draws what is being held back (open emphasis,
118
+ * table rows, code spans). This is the default when you redraw the whole message.
119
+ * It is a guess, so later chunks may change the shape. Check `revised()` after the end.
117
120
  *
118
121
  * ```js
119
122
  * acc += s.push(chunk);
120
- * await edit(acc + s.preview()); // 화면을 그릴 때만 부른다(열린 블록만큼 든다)
123
+ * await edit(acc + s.preview()); // call only when drawing (costs as much as the open block)
121
124
  * acc += s.finish();
122
- * if (s.revised()) await edit(acc); // 마지막 화면이 곧 완성본이면 건너뛴다
125
+ * if (s.revised()) await edit(acc); // skip if the last screen already is the final output
123
126
  * ```
124
127
  */
125
128
  preview(): string;
126
129
  push(chunk: string): string;
127
130
  /**
128
- * 지금까지 정규화가 고친 것. `finish` 뒤에 보면 문서 전체의 값이다.
131
+ * What normalization has repaired so far. After `finish`, this covers the whole document.
129
132
  */
130
133
  repairs(): Repairs;
131
134
  /**
132
- * 완성본이 마지막 `preview()` 와 다른가 — `finish` 뒤에 본다.
135
+ * Whether the final output differs from the last `preview()`. Check it after `finish`.
133
136
  */
134
137
  revised(): boolean;
135
138
  }
136
139
 
137
140
  /**
138
- * 채널의 길이 한도(문자 수). 조각을 직접 다루려는 호출자를 위해 열어 둔다.
141
+ * The channel's length limit (in characters). Exposed for callers that handle parts themselves.
139
142
  */
140
143
  export function limit(channel: string): number;
141
144
 
142
145
  /**
143
- * 완성된 문서를 변환한다. 한도를 넘으면 조각 배열로 돌아온다.
146
+ * Converts a complete document. Returns an array of parts; it has more than one when the text exceeds the limit.
144
147
  */
145
148
  export function render(input: string, channel: string, options?: RenderOptions | null): string[];
146
149
 
147
150
  /**
148
- * [`render`] 에 **정규화가 고친 것**을 같이 돌려준다. 모델이 얼마나 자주 서식을 깨는지
149
- * 로그로 남기려는 쪽이 쓴다.
151
+ * Like [`render`], but also returns **what normalization repaired**. Use it to log
152
+ * how often the model breaks formatting.
150
153
  */
151
154
  export function renderWithReport(input: string, channel: string, options?: RenderOptions | null): Rendered;