ztd-charts-cli 0.5.0 → 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/dist/api.d.ts CHANGED
@@ -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-LVCEIXBR.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,7 +9,7 @@ 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.5.0";
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
15
  help: `ztd-charts ${VERSION} CLI for 36 React chart types
@@ -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}`,
@@ -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}`,
@@ -338,6 +340,18 @@ function findFonts(extra = []) {
338
340
  }
339
341
  return out;
340
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
+ }
341
355
  function standaloneUrl() {
342
356
  try {
343
357
  const p = require2.resolve("ztd-charts/package.json");
@@ -416,11 +430,14 @@ async function render(input, opts = {}) {
416
430
  const width = m ? Number(m[1]) : void 0;
417
431
  const height = m ? Number(m[2]) : void 0;
418
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 = {}) {
419
436
  const { Resvg } = await import("@resvg/resvg-js");
420
437
  const fontFiles = findFonts(opts.fonts);
421
- const r = new Resvg(svg, { fitTo: { mode: "zoom", value: opts.scale ?? 2 }, font: { fontFiles, loadSystemFonts: true, defaultFontFamily: fontFiles.length ? "Pretendard" : "sans-serif" } });
422
- const png = r.render().asPng();
423
- 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)] } : {} };
424
441
  }
425
442
  function isHttpUrl(source) {
426
443
  return /^https?:\/\//i.test(source);
@@ -452,10 +469,12 @@ export {
452
469
  reactSnippet,
453
470
  specSnippet,
454
471
  findFonts,
472
+ stripEmoji,
455
473
  FETCH_TIMEOUT_MS,
456
474
  MAX_FETCH_BYTES,
457
475
  fetchUrl,
458
476
  render,
477
+ svgToPng,
459
478
  isHttpUrl,
460
479
  loadRows,
461
480
  suggest
package/dist/cli.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  resolveType,
14
14
  suggest,
15
15
  validate
16
- } from "./chunk-LVCEIXBR.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": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztd-charts-cli",
3
- "version": "0.5.0",
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",
@@ -35,7 +35,7 @@
35
35
  "@resvg/resvg-js": "^2.6.2",
36
36
  "react": "^19.3.1",
37
37
  "react-dom": "^19.3.1",
38
- "ztd-charts": "0.5.0"
38
+ "ztd-charts": "0.5.1"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/react": "^19.2.0",