@x-cmd/draw 0.1.0 → 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.
Files changed (64) hide show
  1. package/README.cn.md +235 -0
  2. package/README.md +138 -127
  3. package/dist/lib.d.ts +18 -0
  4. package/dist/lib.js +18 -0
  5. package/dist/node/cli.js +14 -11
  6. package/dist/render/area.d.ts +3 -0
  7. package/dist/render/area.js +3 -0
  8. package/dist/render/bar-grid.d.ts +3 -0
  9. package/dist/render/bar-grid.js +3 -0
  10. package/dist/render/bar-grouped.d.ts +3 -0
  11. package/dist/render/bar-grouped.js +3 -0
  12. package/dist/render/bar-stacked.d.ts +3 -0
  13. package/dist/render/bar-stacked.js +3 -0
  14. package/dist/render/bar.d.ts +3 -0
  15. package/dist/render/bar.js +3 -0
  16. package/dist/render/combo.d.ts +3 -0
  17. package/dist/render/combo.js +3 -0
  18. package/dist/render/dispatch.d.ts +3 -0
  19. package/dist/render/dispatch.js +3 -0
  20. package/dist/render/gauge.d.ts +3 -0
  21. package/dist/render/gauge.js +3 -0
  22. package/dist/render/hbar-spec.d.ts +3 -0
  23. package/dist/render/hbar-spec.js +3 -0
  24. package/dist/render/line-multi.d.ts +3 -0
  25. package/dist/render/line-multi.js +3 -0
  26. package/dist/render/line.d.ts +3 -0
  27. package/dist/render/line.js +3 -0
  28. package/dist/render/pie.d.ts +3 -0
  29. package/dist/render/pie.js +3 -0
  30. package/dist/render/qr.d.ts +9 -0
  31. package/dist/render/qr.js +9 -0
  32. package/dist/render/query.d.ts +12 -0
  33. package/dist/render/query.js +9 -0
  34. package/dist/render/radar.d.ts +3 -0
  35. package/dist/render/radar.js +3 -0
  36. package/dist/render/sankey.d.ts +3 -0
  37. package/dist/render/sankey.js +3 -0
  38. package/dist/render/scatter.d.ts +3 -0
  39. package/dist/render/scatter.js +3 -0
  40. package/dist/render/svg.d.ts +3 -0
  41. package/dist/specs/base.d.ts +36 -0
  42. package/dist/specs/base.js +30 -0
  43. package/dist/specs/combo.d.ts +15 -0
  44. package/dist/specs/combo.js +9 -0
  45. package/dist/specs/csv.d.ts +4 -0
  46. package/dist/specs/csv.js +4 -0
  47. package/dist/specs/gauge.d.ts +15 -0
  48. package/dist/specs/gauge.js +9 -0
  49. package/dist/specs/input.d.ts +12 -0
  50. package/dist/specs/input.js +9 -0
  51. package/dist/specs/multi.d.ts +18 -0
  52. package/dist/specs/multi.js +11 -0
  53. package/dist/specs/sankey.d.ts +15 -0
  54. package/dist/specs/sankey.js +9 -0
  55. package/dist/specs/scatter.d.ts +15 -0
  56. package/dist/specs/scatter.js +9 -0
  57. package/dist/store.d.ts +15 -0
  58. package/dist/store.js +9 -0
  59. package/dist/styles/index.d.ts +10 -0
  60. package/dist/styles/index.js +10 -0
  61. package/dist/styles/types.d.ts +3 -0
  62. package/dist/version.d.ts +11 -0
  63. package/dist/version.js +8 -0
  64. package/package.json +8 -2
@@ -1,8 +1,14 @@
1
+ /**
2
+ * One combo series: bars by default, or the line overlay with `type: 'line'`.
3
+ */
1
4
  export interface ComboSeries {
2
5
  name: string;
3
6
  values: number[];
4
7
  kind: 'bar' | 'line';
5
8
  }
9
+ /**
10
+ * Combo data: bar series + line series on shared labels.
11
+ */
6
12
  export interface ComboSpec {
7
13
  title?: string;
8
14
  unit?: string;
@@ -11,5 +17,14 @@ export interface ComboSpec {
11
17
  /** 柱系列堆叠(而非并排),折线仍叠加在上 */
12
18
  stack?: boolean;
13
19
  }
20
+ /**
21
+ * Parse and validate combo JSON.
22
+ *
23
+ * @throws ApiError(400) with a corrective example on bad input
24
+ */
14
25
  export declare function parseComboSpec(raw: string | null): ComboSpec;
26
+ /**
27
+ * Build combo spec JSON from `?series=` (bars) and `?line=` (lines).
28
+ * Returns null when neither is present.
29
+ */
15
30
  export declare function comboSpecFromParams(params: URLSearchParams): string | null;
@@ -28,6 +28,11 @@ function parseSeriesEntries(rawEntries, labels, kind) {
28
28
  return { name: clip(s.name, LIMITS.seriesName), values, kind: entryKind };
29
29
  });
30
30
  }
31
+ /**
32
+ * Parse and validate combo JSON.
33
+ *
34
+ * @throws ApiError(400) with a corrective example on bad input
35
+ */
31
36
  export function parseComboSpec(raw) {
32
37
  if (raw === null || raw === '') {
33
38
  throw new ApiError(400, `Missing data. Use ?type=combo&${COMBO_EXAMPLE}`);
@@ -78,6 +83,10 @@ export function parseComboSpec(raw) {
78
83
  const stack = o.stack === true;
79
84
  return { title, unit, labels, series, ...(stack ? { stack: true } : {}) };
80
85
  }
86
+ /**
87
+ * Build combo spec JSON from `?series=` (bars) and `?line=` (lines).
88
+ * Returns null when neither is present.
89
+ */
81
90
  export function comboSpecFromParams(params) {
82
91
  const d = params.get('d');
83
92
  if (d !== null && d !== '')
@@ -1 +1,5 @@
1
+ /**
2
+ * Convert CSV (first row = header) into spec JSON: one numeric column
3
+ * → single-series spec; several → multi-series.
4
+ */
1
5
  export declare function csvToSpecJson(csv: string): string;
package/dist/specs/csv.js CHANGED
@@ -1,6 +1,10 @@
1
1
  // CSV → spec JSON:首行表头,两列=单系列,多列=多系列。
2
2
  import { ApiError } from './base.js';
3
3
  // CSV → spec JSON:首行为表头。两列(label,value)=单系列;多列(label,系列A,系列B)=多系列
4
+ /**
5
+ * Convert CSV (first row = header) into spec JSON: one numeric column
6
+ * → single-series spec; several → multi-series.
7
+ */
4
8
  export function csvToSpecJson(csv) {
5
9
  const rows = csv.replace(/\r/g, '').split('\n').filter((l) => l.trim() !== '');
6
10
  if (rows.length < 2)
@@ -1,7 +1,13 @@
1
+ /**
2
+ * One ring of a multi-ring gauge; `value` is a percentage.
3
+ */
1
4
  export interface GaugeDatum {
2
5
  label: string;
3
6
  value: number;
4
7
  }
8
+ /**
9
+ * Gauge data: single value (`{value,max}`) or multi-ring (`{max,data}`).
10
+ */
5
11
  export interface GaugeSpec {
6
12
  title?: string;
7
13
  unit?: string;
@@ -11,5 +17,14 @@ export interface GaugeSpec {
11
17
  value?: number;
12
18
  max: number;
13
19
  }
20
+ /**
21
+ * Build gauge spec JSON from `?value=&max=` (single) or `?labels=&values=` (multi-ring).
22
+ * Returns null when neither form is present.
23
+ */
14
24
  export declare function gaugeSpecFromParams(params: URLSearchParams): string | null;
25
+ /**
26
+ * Parse and validate gauge JSON.
27
+ *
28
+ * @throws ApiError(400) with a corrective example on bad input
29
+ */
15
30
  export declare function parseGaugeSpec(raw: string | null): GaugeSpec;
@@ -1,6 +1,10 @@
1
1
  // 仪表盘(gauge):多环(labels+values,每行一环,值为百分比)或单值(value/max)。
2
2
  import { ApiError, LIMITS, clip, flatList } from './base.js';
3
3
  const GAUGE_EXAMPLE = 'value=87&max=100';
4
+ /**
5
+ * Build gauge spec JSON from `?value=&max=` (single) or `?labels=&values=` (multi-ring).
6
+ * Returns null when neither form is present.
7
+ */
4
8
  export function gaugeSpecFromParams(params) {
5
9
  const d = params.get('d');
6
10
  if (d !== null && d !== '')
@@ -42,6 +46,11 @@ export function gaugeSpecFromParams(params) {
42
46
  obj.unit = unit;
43
47
  return JSON.stringify(obj);
44
48
  }
49
+ /**
50
+ * Parse and validate gauge JSON.
51
+ *
52
+ * @throws ApiError(400) with a corrective example on bad input
53
+ */
45
54
  export function parseGaugeSpec(raw) {
46
55
  if (raw === null || raw === '') {
47
56
  throw new ApiError(400, `Missing data. Use ?type=gauge&${GAUGE_EXAMPLE} — or ?d= with {"value":87,"max":100}`);
@@ -1,5 +1,8 @@
1
1
  import { type ChartSpec } from './base.js';
2
2
  import { type MultiSpec } from './multi.js';
3
+ /**
4
+ * A parsed chart input, tagged single- (`multi: false`) or multi-series.
5
+ */
3
6
  export type ChartInput = {
4
7
  multi: false;
5
8
  spec: ChartSpec;
@@ -7,5 +10,14 @@ export type ChartInput = {
7
10
  multi: true;
8
11
  spec: MultiSpec;
9
12
  };
13
+ /**
14
+ * Structural check: does this JSON payload carry a `series` array?
15
+ */
10
16
  export declare function looksMultiSeries(json: string): boolean;
17
+ /**
18
+ * Unified parser for the six basic kinds: flat params or `?d=` JSON
19
+ * → a tagged ChartInput.
20
+ *
21
+ * @throws ApiError(400) with a corrective example on bad input
22
+ */
11
23
  export declare function parseInput(params: URLSearchParams, kind: 'pie' | 'bar' | 'hbar' | 'line' | 'area' | 'radar'): ChartInput;
@@ -3,6 +3,9 @@ import { ApiError, parseChartSpec, specFromParams } from './base.js';
3
3
  import { parseSeriesSpec, seriesSpecFromParams } from './multi.js';
4
4
  // 结构判断(而非字符串嗅探):按解析后的对象是否含 "series" 键决定单/多系列,
5
5
  // 避免标题里恰好含 "series" 字样时误路由
6
+ /**
7
+ * Structural check: does this JSON payload carry a `series` array?
8
+ */
6
9
  export function looksMultiSeries(json) {
7
10
  try {
8
11
  const obj = JSON.parse(json);
@@ -12,6 +15,12 @@ export function looksMultiSeries(json) {
12
15
  return false; // 交给后续解析器给出具体报错
13
16
  }
14
17
  }
18
+ /**
19
+ * Unified parser for the six basic kinds: flat params or `?d=` JSON
20
+ * → a tagged ChartInput.
21
+ *
22
+ * @throws ApiError(400) with a corrective example on bad input
23
+ */
15
24
  export function parseInput(params, kind) {
16
25
  if (kind === 'pie') {
17
26
  if (params.has('series')) {
@@ -1,12 +1,30 @@
1
+ /**
2
+ * One named series of a multi-series chart.
3
+ */
1
4
  export interface SeriesEntry {
2
5
  name: string;
3
6
  values: number[];
4
7
  }
8
+ /**
9
+ * Multi-series chart data: shared labels + named series
10
+ * (grouped/stacked bars, multi-line, multi-area, multi-radar).
11
+ */
5
12
  export interface MultiSpec {
6
13
  title?: string;
7
14
  unit?: string;
8
15
  labels: string[];
9
16
  series: SeriesEntry[];
10
17
  }
18
+ /**
19
+ * Parse and validate a multi-series spec from a JSON string.
20
+ *
21
+ * @param kind `'bar'` or `'line'` — selects the applicable limits
22
+ * @throws ApiError(400) with a corrective example on bad input
23
+ */
11
24
  export declare function parseSeriesSpec(raw: string | null, kind: 'bar' | 'line'): MultiSpec;
25
+ /**
26
+ * Build multi-series spec JSON from flat params
27
+ * (`labels=Mon,Tue&series=a:1,2&series=b:3,4`).
28
+ * Returns null when no series params are present.
29
+ */
12
30
  export declare function seriesSpecFromParams(params: URLSearchParams): string | null;
@@ -1,6 +1,12 @@
1
1
  // 多系列(bar 分组/堆叠、line 多曲线):labels + series[{name, values}]。
2
2
  import { ApiError, LIMITS, MAX_BY_KIND, clip, flatList } from './base.js';
3
3
  const SERIES_EXAMPLE_FLAT = 'labels=Mon,Tue&series=draw:120,180&series=qc:80,90';
4
+ /**
5
+ * Parse and validate a multi-series spec from a JSON string.
6
+ *
7
+ * @param kind `'bar'` or `'line'` — selects the applicable limits
8
+ * @throws ApiError(400) with a corrective example on bad input
9
+ */
4
10
  export function parseSeriesSpec(raw, kind) {
5
11
  if (raw === null || raw === '') {
6
12
  throw new ApiError(400, `Missing data. Use ?${SERIES_EXAMPLE_FLAT} — or ?d= with {"labels":["A","B"],"series":[{"name":"s1","values":[1,2]}]}`);
@@ -76,6 +82,11 @@ export function parseSeriesSpec(raw, kind) {
76
82
  return { title, unit, labels, series };
77
83
  }
78
84
  // 扁平参数 → 多系列 JSON:series=名字:1,2,3 重复参数
85
+ /**
86
+ * Build multi-series spec JSON from flat params
87
+ * (`labels=Mon,Tue&series=a:1,2&series=b:3,4`).
88
+ * Returns null when no series params are present.
89
+ */
79
90
  export function seriesSpecFromParams(params) {
80
91
  const entries = params.getAll('series');
81
92
  if (entries.length === 0)
@@ -1,13 +1,28 @@
1
+ /**
2
+ * One flow: node `from` → node `to` with positive weight `value`.
3
+ */
1
4
  export interface SankeyLink {
2
5
  from: string;
3
6
  to: string;
4
7
  value: number;
5
8
  }
9
+ /**
10
+ * Sankey data: node labels + weighted links (must form a DAG).
11
+ */
6
12
  export interface SankeySpec {
7
13
  title?: string;
8
14
  unit?: string;
9
15
  labels: string[];
10
16
  links: SankeyLink[];
11
17
  }
18
+ /**
19
+ * Build sankey spec JSON from `?labels=` + `?links=A>B:3;C>B:2`.
20
+ * Returns null when absent.
21
+ */
12
22
  export declare function sankeySpecFromParams(params: URLSearchParams): string | null;
23
+ /**
24
+ * Parse and validate sankey JSON (includes the cycle check).
25
+ *
26
+ * @throws ApiError(400) with a corrective example on bad input
27
+ */
13
28
  export declare function parseSankeySpec(raw: string | null): SankeySpec;
@@ -3,6 +3,10 @@ import { ApiError, LIMITS, clip, flatList } from './base.js';
3
3
  const SANKEY_EXAMPLE = 'labels=Ads,Web,Signup,Buy&links=Ads>Signup:30,Web>Signup:20,Signup>Buy:40';
4
4
  const MAX_NODES = 24;
5
5
  const MAX_LINKS = 60;
6
+ /**
7
+ * Build sankey spec JSON from `?labels=` + `?links=A>B:3;C>B:2`.
8
+ * Returns null when absent.
9
+ */
6
10
  export function sankeySpecFromParams(params) {
7
11
  const d = params.get('d');
8
12
  if (d !== null && d !== '')
@@ -28,6 +32,11 @@ export function sankeySpecFromParams(params) {
28
32
  ...(params.get('unit') ? { unit: params.get('unit') } : {}),
29
33
  });
30
34
  }
35
+ /**
36
+ * Parse and validate sankey JSON (includes the cycle check).
37
+ *
38
+ * @throws ApiError(400) with a corrective example on bad input
39
+ */
31
40
  export function parseSankeySpec(raw) {
32
41
  if (raw === null || raw === '') {
33
42
  throw new ApiError(400, `Missing data. Use ?type=sankey&${SANKEY_EXAMPLE} — or ?d= with {"labels":["A","B"],"links":[{"from":"A","to":"B","value":30}]}`);
@@ -1,3 +1,6 @@
1
+ /**
2
+ * One scatter series: a name plus `[x,y]` points.
3
+ */
1
4
  export interface ScatterSeries {
2
5
  name: string;
3
6
  points: {
@@ -5,6 +8,9 @@ export interface ScatterSeries {
5
8
  y: number;
6
9
  }[];
7
10
  }
11
+ /**
12
+ * Scatter data — one or more series; negative coordinates allowed.
13
+ */
8
14
  export interface ScatterSpec {
9
15
  title?: string;
10
16
  unit?: string;
@@ -16,5 +22,14 @@ export interface ScatterSpec {
16
22
  /** 多系列形态(规范 scatter-1 双系列对比) */
17
23
  series?: ScatterSeries[];
18
24
  }
25
+ /**
26
+ * Build scatter spec JSON from `?x=&y=` (repeated pairs form multiple series).
27
+ * Returns null when absent.
28
+ */
19
29
  export declare function scatterSpecFromParams(params: URLSearchParams): string | null;
30
+ /**
31
+ * Parse and validate scatter JSON (`{"points":[[1,4]]}` or `{"series":[...]}`).
32
+ *
33
+ * @throws ApiError(400) with a corrective example on bad input
34
+ */
20
35
  export declare function parseScatterSpec(raw: string | null): ScatterSpec;
@@ -1,6 +1,10 @@
1
1
  // 散点图(scatter):x,y 点对;单系列扁平 x=/y=(或 JSON points),多系列重复 x=/y= 参数(或 JSON series)。
2
2
  import { ApiError, LIMITS, clip } from './base.js';
3
3
  const SCATTER_EXAMPLE = 'x=1,2,3&y=4,5,6';
4
+ /**
5
+ * Build scatter spec JSON from `?x=&y=` (repeated pairs form multiple series).
6
+ * Returns null when absent.
7
+ */
4
8
  export function scatterSpecFromParams(params) {
5
9
  const d = params.get('d');
6
10
  if (d !== null && d !== '')
@@ -69,6 +73,11 @@ function parsePoints(rawPoints, at) {
69
73
  return { x, y };
70
74
  });
71
75
  }
76
+ /**
77
+ * Parse and validate scatter JSON (`{"points":[[1,4]]}` or `{"series":[...]}`).
78
+ *
79
+ * @throws ApiError(400) with a corrective example on bad input
80
+ */
72
81
  export function parseScatterSpec(raw) {
73
82
  if (raw === null || raw === '') {
74
83
  throw new ApiError(400, `Missing data. Use ?type=scatter&${SCATTER_EXAMPLE} — or ?d= with {"points":[[1,4],[2,5]]}`);
package/dist/store.d.ts CHANGED
@@ -1,6 +1,15 @@
1
1
  import type { DrawEnv } from './types.js';
2
+ /**
3
+ * All supported chart template ids — the valid `?type=` values.
4
+ */
2
5
  export declare const CHART_TEMPLATES: readonly ["pie", "bar", "hbar", "line", "area", "radar", "gauge", "scatter", "combo", "sankey", "qr"];
6
+ /**
7
+ * A chart template id; one of {@link CHART_TEMPLATES}.
8
+ */
3
9
  export type ChartTemplate = (typeof CHART_TEMPLATES)[number];
10
+ /**
11
+ * A stored (short-linked) chart: template + style family + normalized spec.
12
+ */
4
13
  export interface StoredChart {
5
14
  template: ChartTemplate;
6
15
  theme: string;
@@ -8,7 +17,13 @@ export interface StoredChart {
8
17
  spec: unknown;
9
18
  }
10
19
  export declare function assertHash(hash: string): void;
20
+ /**
21
+ * Canonical JSON with keys recursively sorted — equal data, equal text.
22
+ */
11
23
  export declare function canonicalJson(v: unknown): string;
24
+ /**
25
+ * Content hash (SHA-256, first 16 hex chars) of a stored chart — the short-link id.
26
+ */
12
27
  export declare function fingerprint(doc: StoredChart): Promise<string>;
13
28
  export declare function putChart(env: DrawEnv, hash: string, doc: StoredChart): Promise<void>;
14
29
  export declare function getChart(env: DrawEnv, hash: string): Promise<StoredChart>;
package/dist/store.js CHANGED
@@ -2,6 +2,9 @@
2
2
  // 读取走 raw(免 token);写入需 GITHUB_TOKEN(secret,fine-grained PAT 仅授本仓 Contents 写)。
3
3
  // 可见性:公开仓任何人都可浏览目录,请勿存放敏感数据(私有方案规划中,将收费提供)。
4
4
  import { ApiError } from './specs/index.js';
5
+ /**
6
+ * All supported chart template ids — the valid `?type=` values.
7
+ */
5
8
  export const CHART_TEMPLATES = ['pie', 'bar', 'hbar', 'line', 'area', 'radar', 'gauge', 'scatter', 'combo', 'sankey', 'qr'];
6
9
  const HASH_RE = /^[0-9a-f]{16}$/;
7
10
  const MAX_BODY = 64 * 1024;
@@ -11,6 +14,9 @@ export function assertHash(hash) {
11
14
  }
12
15
  }
13
16
  // 规范化 JSON(递归排序 key),让"相同数据"得到相同指纹
17
+ /**
18
+ * Canonical JSON with keys recursively sorted — equal data, equal text.
19
+ */
14
20
  export function canonicalJson(v) {
15
21
  const walk = (x) => {
16
22
  if (Array.isArray(x))
@@ -26,6 +32,9 @@ export function canonicalJson(v) {
26
32
  };
27
33
  return JSON.stringify(walk(v));
28
34
  }
35
+ /**
36
+ * Content hash (SHA-256, first 16 hex chars) of a stored chart — the short-link id.
37
+ */
29
38
  export async function fingerprint(doc) {
30
39
  const data = new TextEncoder().encode(canonicalJson(doc));
31
40
  const digest = await crypto.subtle.digest('SHA-256', data);
@@ -1,7 +1,17 @@
1
1
  import type { ChartTemplate } from '../store.js';
2
2
  import { type Scheme, type Skin, type Variant } from './types.js';
3
+ /**
4
+ * Style registry: available variants per chart type (index 0 = default family).
5
+ */
3
6
  export declare const VARIANTS: Record<ChartTemplate, Variant[]>;
4
7
  /** 全部有效风格家族(错误提示/演示页用) */
5
8
  export declare const FAMILIES: string[];
9
+ /**
10
+ * Resolve the render-ready skin for a chart.
11
+ *
12
+ * @param family the `?t=` style family; null uses the type default.
13
+ * An unknown family throws; a family not built for this type falls back to the default.
14
+ * @param scheme `auto` emits both palettes plus a `prefers-color-scheme` media query.
15
+ */
6
16
  export declare function resolveSkin(type: ChartTemplate, family: string | null, scheme: Scheme): Skin;
7
17
  export { type Skin, type Scheme, type Variant } from './types.js';
@@ -13,6 +13,9 @@ import { GAUGE_VARIANTS } from './gauge.js';
13
13
  import { SCATTER_VARIANTS } from './scatter.js';
14
14
  import { COMBO_VARIANTS } from './combo.js';
15
15
  import { QR_VARIANTS } from './qr.js';
16
+ /**
17
+ * Style registry: available variants per chart type (index 0 = default family).
18
+ */
16
19
  export const VARIANTS = {
17
20
  pie: PIE_VARIANTS,
18
21
  bar: BAR_VARIANTS,
@@ -58,6 +61,13 @@ function padSeries(series) {
58
61
  }
59
62
  return out;
60
63
  }
64
+ /**
65
+ * Resolve the render-ready skin for a chart.
66
+ *
67
+ * @param family the `?t=` style family; null uses the type default.
68
+ * An unknown family throws; a family not built for this type falls back to the default.
69
+ * @param scheme `auto` emits both palettes plus a `prefers-color-scheme` media query.
70
+ */
61
71
  export function resolveSkin(type, family, scheme) {
62
72
  const variants = VARIANTS[type];
63
73
  let variant = variants[0]; // 默认 = 第一个变体
@@ -94,6 +94,9 @@ export interface Variant {
94
94
  export declare function makeVariant(v: VariantInput): Variant;
95
95
  /** 渲染期皮肤:变体 + 明暗模式 → 渲染器直接消费 */
96
96
  export type Scheme = 'auto' | 'dark' | 'light';
97
+ /**
98
+ * A resolved, render-ready skin: palette, rules, and optional design canvas size.
99
+ */
97
100
  export interface Skin {
98
101
  scheme: Scheme;
99
102
  series: Duo[];
package/dist/version.d.ts CHANGED
@@ -1,6 +1,17 @@
1
+ /**
2
+ * The current render version. Bump when a deploy changes rendered output.
3
+ */
1
4
  export declare const CURRENT_VERSION = 1;
5
+ /**
6
+ * A resolved version plus the Cache-Control policy it implies.
7
+ */
2
8
  export interface VersionInfo {
3
9
  version: number;
4
10
  cacheControl: string;
5
11
  }
12
+ /**
13
+ * Resolve `?v=`: omitted → latest (300s cache); `v=N` → pinned (1-day cache).
14
+ *
15
+ * @throws ApiError(400) for values outside 1..CURRENT_VERSION
16
+ */
6
17
  export declare function resolveVersion(vParam: string | null): VersionInfo;
package/dist/version.js CHANGED
@@ -2,7 +2,15 @@
2
2
  // 缺省 = 最新版(短 TTL 300s)。?v=N = 钉住版本,长缓存 1 天;
3
3
  // immutable 仅用于内容寻址短链 /c/<hash>(渲染代码随部署变化,/draw 的输出做不到真正冻结)。
4
4
  import { ApiError } from './specs/index.js';
5
+ /**
6
+ * The current render version. Bump when a deploy changes rendered output.
7
+ */
5
8
  export const CURRENT_VERSION = 1;
9
+ /**
10
+ * Resolve `?v=`: omitted → latest (300s cache); `v=N` → pinned (1-day cache).
11
+ *
12
+ * @throws ApiError(400) for values outside 1..CURRENT_VERSION
13
+ */
6
14
  export function resolveVersion(vParam) {
7
15
  if (vParam === null) {
8
16
  return { version: CURRENT_VERSION, cacheControl: 'public, max-age=300' };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@x-cmd/draw",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "SVG chart rendering as a service, a library, and a CLI — pie/bar/hbar/line/area/radar/gauge/scatter/combo/sankey/qr, same params everywhere",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -11,8 +11,14 @@
11
11
  }
12
12
  },
13
13
  "bin": {
14
- "x-draw": "./dist/node/cli.js"
14
+ "draw": "./dist/node/cli.js"
15
15
  },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/x-cmd/draw.git"
19
+ },
20
+ "homepage": "https://x-cmd.com/draw",
21
+ "bugs": "https://github.com/x-cmd/draw/issues",
16
22
  "files": [
17
23
  "dist"
18
24
  ],