ztd-charts-cli 0.4.1 → 0.5.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
@@ -1,6 +1,6 @@
1
1
  # ztd-charts-cli
2
2
 
3
- `ztd-charts`: the list of all 33 charts, JSON Schema, spec validation, SVG/PNG/HTML rendering, starter files, and chart suggestions from your data.
3
+ `ztd-charts`: the list of all 36 charts, JSON Schema, spec validation, SVG/PNG/HTML rendering, starter files, and chart suggestions from your data.
4
4
 
5
5
  [Website](https://charts.ztd.app) · [Gallery](https://charts.ztd.app/docs/) · [GitHub](https://github.com/Junhan2/ztd-charts)
6
6
 
@@ -21,7 +21,7 @@ Installed in a project (`npm i -D ztd-charts-cli`), the command is `ztd-charts`.
21
21
 
22
22
  Messages, chart text and number formats are English by default. Add `--locale ko` for Korean. `validate` exits with 1 when the spec has errors, so it works in CI.
23
23
 
24
- PNGs are drawn with resvg. Chart text asks for Pretendard first, then Apple SD Gothic Neo, Noto Sans KR or Malgun Gothic. Besides system fonts, the CLI loads the `pretendard` package when it is installed next to the CLI, every font in `ZTD_CHARTS_FONT_DIR`, and `--font path.otf`. For Korean text in PNGs, make one of those fonts available.
24
+ PNGs are drawn with resvg. Chart text asks for Pretendard first, then Apple SD Gothic Neo, Noto Sans KR or Malgun Gothic. The package ships Pretendard in the five weights charts use (SIL Open Font License 1.1, see `fonts/LICENSE.txt`), so PNG text, Korean included, renders even in a Linux container with no fonts installed. `--font path.otf` or `ZTD_CHARTS_FONT_DIR` loads your own fonts in place of the bundled ones.
25
25
 
26
26
  To use it from a program: `import { render, validate, suggest, listCharts } from "ztd-charts-cli"`.
27
27
 
package/dist/api.d.ts CHANGED
@@ -44,7 +44,7 @@ declare function getChartInfo(type: string, locale?: string): {
44
44
  schema: JSONSchema | null;
45
45
  example: ChartSpec;
46
46
  react: string;
47
- /** 이름 붙은 꼴: 예시 options 위에 덮어쓰는 옵션 (ztd-charts example <type> --variant <id>) */
47
+ /** 이름 붙은 꼴: 예시 options 위에 덮어쓰는 옵션, 범위 띠처럼 필드를 더하는 꼴은 encoding도 (ztd-charts example <type> --variant <id>) */
48
48
  variants: ztd_charts_spec.ChartVariant[];
49
49
  type: string;
50
50
  component: string;
@@ -100,7 +100,17 @@ interface RenderResult {
100
100
  html?: string;
101
101
  width?: number;
102
102
  height?: number;
103
+ /** 그리면서 바꾼 것 (PNG에서 뺀 이모지 등). 경고처럼 보여 줘요 */
104
+ notes?: string[];
103
105
  }
106
+ /**
107
+ * PNG로 바꾸기 전에 SVG 글자에서 이모지를 빼요. resvg는 컬러 이모지 글꼴을 못 그려서, 이모지가 든 글자 덩어리 전체가 네모로 나와요.
108
+ * 이모지를 뺀 자리의 겹친 공백은 하나로 줄이고 앞뒤 공백은 지워요. 뺀 개수를 돌려줘요
109
+ */
110
+ declare function stripEmoji(svg: string): {
111
+ svg: string;
112
+ removed: number;
113
+ };
104
114
  /** 데이터 주소를 가져올 때 기다리는 시간과 받는 크기의 한도 */
105
115
  declare const FETCH_TIMEOUT_MS = 15000;
106
116
  declare const MAX_FETCH_BYTES: number;
@@ -115,6 +125,18 @@ declare function fetchUrl(url: string, locale?: string, opts?: FetchOptions): Pr
115
125
  * 가져오기, 검사, 그리기가 같은 로캘(locale, 그다음 스펙 options.locale)을 써요
116
126
  */
117
127
  declare function render(input: ChartSpec, opts?: RenderOptions): Promise<RenderResult>;
128
+ /**
129
+ * SVG를 PNG로 (resvg). 이모지는 빼고, 뺀 수를 locale 언어로 notes에 알려요.
130
+ * MCP는 SVG가 너무 커서 글자로 못 보낼 때 이미 그린 SVG를 이걸로 바꿔 보내요
131
+ */
132
+ declare function svgToPng(svg: string, opts?: {
133
+ scale?: number;
134
+ fonts?: string[];
135
+ locale?: string;
136
+ }): Promise<{
137
+ png: Buffer;
138
+ notes?: string[];
139
+ }>;
118
140
  /** http(s) 주소인지. loadRows, CLI suggest, MCP suggest_chart가 같은 규칙(대소문자 무시)을 써요 */
119
141
  declare function isHttpUrl(source: string): boolean;
120
142
  /** 파일 경로나 URL, CSV/JSON 문자열을 행 배열로 */
@@ -128,5 +150,5 @@ declare function suggest(rows: Record<string, unknown>[], opts?: {
128
150
  suggestions: Suggestion[];
129
151
  };
130
152
 
131
- export { FETCH_TIMEOUT_MS, MAX_FETCH_BYTES, fetchUrl, findFonts, getChartInfo, getChartSchema, isHttpUrl, listCharts, loadRows, reactSnippet, render, resolveType, specSnippet, suggest, summarize, validate };
153
+ export { FETCH_TIMEOUT_MS, MAX_FETCH_BYTES, fetchUrl, findFonts, getChartInfo, getChartSchema, isHttpUrl, listCharts, loadRows, reactSnippet, render, resolveType, specSnippet, stripEmoji, suggest, summarize, svgToPng, validate };
132
154
  export type { ChartSummary, FetchOptions, RenderOptions, RenderResult };
package/dist/api.js CHANGED
@@ -13,10 +13,12 @@ import {
13
13
  render,
14
14
  resolveType,
15
15
  specSnippet,
16
+ stripEmoji,
16
17
  suggest,
17
18
  summarize,
19
+ svgToPng,
18
20
  validate
19
- } from "./chunk-3NU4OUQK.js";
21
+ } from "./chunk-QVXYPBAX.js";
20
22
  export {
21
23
  CHARTS,
22
24
  FETCH_TIMEOUT_MS,
@@ -32,7 +34,9 @@ export {
32
34
  render,
33
35
  resolveType,
34
36
  specSnippet,
37
+ stripEmoji,
35
38
  suggest,
36
39
  summarize,
40
+ svgToPng,
37
41
  validate
38
42
  };
@@ -9,10 +9,10 @@ import { langOf, renderSpecToHTML, renderSpecToSVG, resolveSpecData } from "ztd-
9
9
 
10
10
  // src/messages.ts
11
11
  import { plural } from "ztd-charts/server";
12
- var VERSION = "0.4.1";
12
+ var VERSION = "0.5.1";
13
13
  var SCHEMA_URL = "https://unpkg.com/ztd-charts/schema/chart-spec.schema.json";
14
14
  var en = {
15
- help: `ztd-charts ${VERSION} CLI for 33 React chart types
15
+ help: `ztd-charts ${VERSION} CLI for 36 React chart types
16
16
 
17
17
  Usage
18
18
  ztd-charts list [--group proportion] [--level basic] [--json]
@@ -65,6 +65,7 @@ ${n} charts. Details: ztd-charts info <type>`,
65
65
  variants: "Variants",
66
66
  noVariants: (type) => `${type} has no named variants`,
67
67
  saved: (p) => `Saved: ${p}`,
68
+ emojiRemoved: (n) => `Removed ${n} emoji from the PNG text because PNG has no emoji font. SVG and HTML keep them`,
68
69
  valid: (file, type, warnings) => `\u2713 ${file}: valid ${type} spec${warnings ? ` (${plural(warnings, "warning")})` : ""}`,
69
70
  skipped: (p) => `Skipped (already exists): ${p}`,
70
71
  created: (p) => `Created: ${p}`,
@@ -102,7 +103,7 @@ ${n} charts. Details: ztd-charts info <type>`,
102
103
  })
103
104
  };
104
105
  var ko = {
105
- help: `ztd-charts ${VERSION} React \uCC28\uD2B8 33\uC885\uC744 \uC704\uD55C CLI
106
+ help: `ztd-charts ${VERSION} React \uCC28\uD2B8 36\uC885\uC744 \uC704\uD55C CLI
106
107
 
107
108
  \uC0AC\uC6A9\uBC95
108
109
  ztd-charts list [--group \uBE44\uC728] [--level \uAE30\uBCF8] [--json]
@@ -153,6 +154,7 @@ ${n}\uC885. \uC790\uC138\uD788: ztd-charts info <type>`,
153
154
  variants: "\uBCC0\uD615",
154
155
  noVariants: (type) => `${type}\uC5D0\uB294 \uC774\uB984 \uBD99\uC740 \uBCC0\uD615\uC774 \uC5C6\uC5B4\uC694`,
155
156
  saved: (p) => `\uC800\uC7A5: ${p}`,
157
+ emojiRemoved: (n) => `PNG\uC5D0\uB294 \uC774\uBAA8\uC9C0 \uAE00\uAF34\uC774 \uC5C6\uC5B4\uC11C \uAE00\uC790\uC5D0\uC11C \uC774\uBAA8\uC9C0 ${n}\uAC1C\uB97C \uBE90\uC5B4\uC694. SVG\uC640 HTML\uC5D0\uB294 \uADF8\uB300\uB85C \uC788\uC5B4\uC694`,
156
158
  valid: (file, type, warnings) => `\u2713 ${file}: \uC62C\uBC14\uB978 ${type} \uC2A4\uD399${warnings ? `(\uACBD\uACE0 ${warnings}\uAC1C)` : ""}`,
157
159
  skipped: (p) => `\uAC74\uB108\uB700(\uC774\uBBF8 \uC788\uC74C): ${p}`,
158
160
  created: (p) => `\uB9CC\uB4E6: ${p}`,
@@ -260,7 +262,7 @@ function getChartInfo(type, locale) {
260
262
  schema: schemaForIn(def.type, lang),
261
263
  example: def.example,
262
264
  react: reactSnippet(def.example, { locale }),
263
- /** 이름 붙은 꼴: 예시 options 위에 덮어쓰는 옵션 (ztd-charts example <type> --variant <id>) */
265
+ /** 이름 붙은 꼴: 예시 options 위에 덮어쓰는 옵션, 범위 띠처럼 필드를 더하는 꼴은 encoding도 (ztd-charts example <type> --variant <id>) */
264
266
  variants: variantsIn(def.type, lang)
265
267
  };
266
268
  }
@@ -331,14 +333,25 @@ function findFonts(extra = []) {
331
333
  dirs.push(join(dirname(pkg), "dist/public/static"));
332
334
  } catch {
333
335
  }
334
- const here = dirname(fileURLToPath(import.meta.url));
335
- dirs.push(join(here, "../fonts"));
336
+ if (!extra.length && !process.env.ZTD_CHARTS_FONT_DIR) dirs.push(join(dirname(fileURLToPath(import.meta.url)), "../fonts"));
336
337
  for (const d of dirs) {
337
338
  if (!existsSync(d)) continue;
338
339
  for (const f of readdirSync(d)) if (/^Pretendard-(Regular|Medium|SemiBold|Bold|ExtraBold)\.(otf|ttf)$/i.test(f) || d === process.env.ZTD_CHARTS_FONT_DIR && /\.(otf|ttf|ttc)$/i.test(f)) out.push(join(d, f));
339
340
  }
340
341
  return out;
341
342
  }
343
+ var EMOJI = new RegExp("\\p{Regional_Indicator}{2}|[#*0-9]\\p{Variation_Selector}?\\p{Me}|(?:\\p{Emoji_Presentation}|\\p{Extended_Pictographic}\\p{Variation_Selector})\\p{Emoji_Modifier}?(?:\\p{Join_Control}(?:\\p{Emoji_Presentation}|\\p{Extended_Pictographic}\\p{Variation_Selector}?)\\p{Emoji_Modifier}?)*", "gu");
344
+ function stripEmoji(svg) {
345
+ let removed = 0;
346
+ const out = svg.replace(/(<(?:text|tspan)\b[^>]*>)([^<]+)</g, (whole, open, text) => {
347
+ const t = text.replace(EMOJI, () => {
348
+ removed++;
349
+ return "";
350
+ });
351
+ return t === text ? whole : `${open}${t.replace(/ {2,}/g, " ").trim()}<`;
352
+ });
353
+ return { svg: out, removed };
354
+ }
342
355
  function standaloneUrl() {
343
356
  try {
344
357
  const p = require2.resolve("ztd-charts/package.json");
@@ -417,11 +430,14 @@ async function render(input, opts = {}) {
417
430
  const width = m ? Number(m[1]) : void 0;
418
431
  const height = m ? Number(m[2]) : void 0;
419
432
  if (format === "svg") return { format, svg, width, height };
433
+ return { format, svg, width, height, ...await svgToPng(svg, { scale: opts.scale, fonts: opts.fonts, locale }) };
434
+ }
435
+ async function svgToPng(svg, opts = {}) {
420
436
  const { Resvg } = await import("@resvg/resvg-js");
421
437
  const fontFiles = findFonts(opts.fonts);
422
- const r = new Resvg(svg, { fitTo: { mode: "zoom", value: opts.scale ?? 2 }, font: { fontFiles, loadSystemFonts: true, defaultFontFamily: fontFiles.length ? "Pretendard" : "sans-serif" } });
423
- const png = r.render().asPng();
424
- return { format, svg, png: Buffer.from(png), width, height };
438
+ const plain = stripEmoji(svg);
439
+ const r = new Resvg(plain.svg, { fitTo: { mode: "zoom", value: opts.scale ?? 2 }, font: { fontFiles, loadSystemFonts: true, defaultFontFamily: fontFiles.length ? "Pretendard" : "sans-serif" } });
440
+ return { png: Buffer.from(r.render().asPng()), ...plain.removed ? { notes: [CLI_TEXT[langOf(opts.locale)].emojiRemoved(plain.removed)] } : {} };
425
441
  }
426
442
  function isHttpUrl(source) {
427
443
  return /^https?:\/\//i.test(source);
@@ -453,10 +469,12 @@ export {
453
469
  reactSnippet,
454
470
  specSnippet,
455
471
  findFonts,
472
+ stripEmoji,
456
473
  FETCH_TIMEOUT_MS,
457
474
  MAX_FETCH_BYTES,
458
475
  fetchUrl,
459
476
  render,
477
+ svgToPng,
460
478
  isHttpUrl,
461
479
  loadRows,
462
480
  suggest
package/dist/cli.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  resolveType,
14
14
  suggest,
15
15
  validate
16
- } from "./chunk-3NU4OUQK.js";
16
+ } from "./chunk-QVXYPBAX.js";
17
17
 
18
18
  // src/cli.ts
19
19
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
@@ -202,6 +202,7 @@ ${info.react}`);
202
202
  if (format === "png") writeFileSync(target, res.png);
203
203
  else writeFileSync(target, format === "html" ? res.html : res.svg);
204
204
  out(t.saved(`${target}${res.width ? ` (${res.width}\xD7${res.height}${format === "png" ? ` @${scale ?? 2}x` : ""})` : ""}`));
205
+ for (const n of res.notes ?? []) out(`! ${n}`);
205
206
  return;
206
207
  }
207
208
  case "init": {
@@ -0,0 +1,94 @@
1
+ Copyright (c) 2021, Kil Hyung-jin (https://github.com/orioncactus/pretendard),
2
+ with Reserved Font Name Pretendard.
3
+
4
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
5
+ This license is copied below, and is also available with a FAQ at:
6
+ https://scripts.sil.org/OFL
7
+
8
+
9
+ -----------------------------------------------------------
10
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
11
+ -----------------------------------------------------------
12
+
13
+ PREAMBLE
14
+ The goals of the Open Font License (OFL) are to stimulate worldwide
15
+ development of collaborative font projects, to support the font creation
16
+ efforts of academic and linguistic communities, and to provide a free and
17
+ open framework in which fonts may be shared and improved in partnership
18
+ with others.
19
+
20
+ The OFL allows the licensed fonts to be used, studied, modified and
21
+ redistributed freely as long as they are not sold by themselves. The
22
+ fonts, including any derivative works, can be bundled, embedded,
23
+ redistributed and/or sold with any software provided that any reserved
24
+ names are not used by derivative works. The fonts and derivatives,
25
+ however, cannot be released under any other type of license. The
26
+ requirement for fonts to remain under this license does not apply
27
+ to any document created using the fonts or their derivatives.
28
+
29
+ DEFINITIONS
30
+ "Font Software" refers to the set of files released by the Copyright
31
+ Holder(s) under this license and clearly marked as such. This may
32
+ include source files, build scripts and documentation.
33
+
34
+ "Reserved Font Name" refers to any names specified as such after the
35
+ copyright statement(s).
36
+
37
+ "Original Version" refers to the collection of Font Software components as
38
+ distributed by the Copyright Holder(s).
39
+
40
+ "Modified Version" refers to any derivative made by adding to, deleting,
41
+ or substituting -- in part or in whole -- any of the components of the
42
+ Original Version, by changing formats or by porting the Font Software to a
43
+ new environment.
44
+
45
+ "Author" refers to any designer, engineer, programmer, technical
46
+ writer or other person who contributed to the Font Software.
47
+
48
+ PERMISSION & CONDITIONS
49
+ Permission is hereby granted, free of charge, to any person obtaining
50
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
51
+ redistribute, and sell modified and unmodified copies of the Font
52
+ Software, subject to the following conditions:
53
+
54
+ 1) Neither the Font Software nor any of its individual components,
55
+ in Original or Modified Versions, may be sold by itself.
56
+
57
+ 2) Original or Modified Versions of the Font Software may be bundled,
58
+ redistributed and/or sold with any software, provided that each copy
59
+ contains the above copyright notice and this license. These can be
60
+ included either as stand-alone text files, human-readable headers or
61
+ in the appropriate machine-readable metadata fields within text or
62
+ binary files as long as those fields can be easily viewed by the user.
63
+
64
+ 3) No Modified Version of the Font Software may use the Reserved Font
65
+ Name(s) unless explicit written permission is granted by the corresponding
66
+ Copyright Holder. This restriction only applies to the primary font name as
67
+ presented to the users.
68
+
69
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
70
+ Software shall not be used to promote, endorse or advertise any
71
+ Modified Version, except to acknowledge the contribution(s) of the
72
+ Copyright Holder(s) and the Author(s) or with their explicit written
73
+ permission.
74
+
75
+ 5) The Font Software, modified or unmodified, in part or in whole,
76
+ must be distributed entirely under this license, and must not be
77
+ distributed under any other license. The requirement for fonts to
78
+ remain under this license does not apply to any document created
79
+ using the Font Software.
80
+
81
+ TERMINATION
82
+ This license becomes null and void if any of the above conditions are
83
+ not met.
84
+
85
+ DISCLAIMER
86
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
87
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
88
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
89
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
90
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
91
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
92
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
93
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
94
+ OTHER DEALINGS IN THE FONT SOFTWARE.
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztd-charts-cli",
3
- "version": "0.4.1",
3
+ "version": "0.5.1",
4
4
  "description": "ztd-charts CLI: list charts, get JSON Schemas, validate specs, render SVG/PNG/HTML, start a project, and get chart suggestions from data",
5
5
  "license": "MIT",
6
6
  "author": "Junhan2",
@@ -25,6 +25,7 @@
25
25
  },
26
26
  "files": [
27
27
  "dist",
28
+ "fonts",
28
29
  "README.md"
29
30
  ],
30
31
  "engines": {
@@ -34,7 +35,7 @@
34
35
  "@resvg/resvg-js": "^2.6.2",
35
36
  "react": "^19.3.1",
36
37
  "react-dom": "^19.3.1",
37
- "ztd-charts": "0.4.1"
38
+ "ztd-charts": "0.5.1"
38
39
  },
39
40
  "devDependencies": {
40
41
  "@types/react": "^19.2.0",
@@ -44,7 +45,7 @@
44
45
  "typescript": "5.9.3"
45
46
  },
46
47
  "scripts": {
47
- "build": "rm -rf dist && tsup",
48
+ "build": "rm -rf dist && tsup && node scripts/copy-fonts.mjs",
48
49
  "typecheck": "tsc --noEmit -p tsconfig.json"
49
50
  }
50
51
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Junhan2
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.