@funnest/charts-ui 0.9.0 → 0.9.2

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/i18n.d.ts CHANGED
@@ -105,6 +105,18 @@ export declare const STRINGS: {
105
105
  customColor: string;
106
106
  partColors: string;
107
107
  resetColors: string;
108
+ templates: string;
109
+ levels: string;
110
+ levelShown: string;
111
+ levelValue: string;
112
+ levelColor: string;
113
+ removeLevel: string;
114
+ addLevel: string;
115
+ resetLevels: string;
116
+ saveTemplate: string;
117
+ templateName: string;
118
+ noTemplates: string;
119
+ deleteTemplate: string;
108
120
  lineWidth: string;
109
121
  lineStyle: string;
110
122
  lineSolid: string;
@@ -312,6 +324,18 @@ export declare const STRINGS: {
312
324
  customColor: string;
313
325
  partColors: string;
314
326
  resetColors: string;
327
+ templates: string;
328
+ levels: string;
329
+ levelShown: string;
330
+ levelValue: string;
331
+ levelColor: string;
332
+ removeLevel: string;
333
+ addLevel: string;
334
+ resetLevels: string;
335
+ saveTemplate: string;
336
+ templateName: string;
337
+ noTemplates: string;
338
+ deleteTemplate: string;
315
339
  lineWidth: string;
316
340
  lineStyle: string;
317
341
  lineSolid: string;
package/dist/icons.d.ts CHANGED
@@ -34,6 +34,10 @@ export declare const LineBreakIcon: () => import("preact").JSX.Element;
34
34
  export declare const PointFigureIcon: () => import("preact").JSX.Element;
35
35
  export declare const IndicatorIcon: () => import("preact").JSX.Element;
36
36
  export declare const GearIcon: () => import("preact").JSX.Element;
37
+ /** 레벨 설정: lines at different heights with a value tick. */
38
+ export declare const LevelsIcon: () => import("preact").JSX.Element;
39
+ /** 그리기 템플릿: stacked cards. */
40
+ export declare const TemplateIcon: () => import("preact").JSX.Element;
37
41
  export declare const SmallPlusIcon: () => import("preact").JSX.Element;
38
42
  export declare const SmallCloseIcon: () => import("preact").JSX.Element;
39
43
  export declare const EyeIcon: () => import("preact").JSX.Element;
package/dist/index.js CHANGED
@@ -269,6 +269,9 @@ n = { __e: function(n2, t3, r3, u3) {
269
269
  return n2.__v.__b - t3.__v.__b;
270
270
  }, e = /* @__PURE__ */ Symbol(), l = /(PointerCapture)$|Capture$/i, c = 0, a = {}, s = 0;
271
271
 
272
+ // src/components/drawing-toolbar.tsx
273
+ import { drawingLevels } from "@funnest/charts";
274
+
272
275
  // ../../node_modules/.pnpm/preact@11.2.0/node_modules/preact/hooks/dist/hooks.mjs
273
276
  var t2;
274
277
  var r2;
@@ -531,6 +534,18 @@ var STRINGS = {
531
534
  customColor: "\uB2E4\uB978 \uC0C9",
532
535
  partColors: "\uBD80\uBD84 \uC0C9\uC0C1",
533
536
  resetColors: "\uAE30\uBCF8 \uC0C9\uC73C\uB85C",
537
+ templates: "\uD15C\uD50C\uB9BF",
538
+ levels: "\uB808\uBCA8 \uC124\uC815",
539
+ levelShown: "\uB808\uBCA8 \uBCF4\uC774\uAE30",
540
+ levelValue: "\uB808\uBCA8 \uAC12",
541
+ levelColor: "\uB808\uBCA8 \uC0C9",
542
+ removeLevel: "\uB808\uBCA8 \uBE7C\uAE30",
543
+ addLevel: "\uB808\uBCA8 \uCD94\uAC00",
544
+ resetLevels: "\uAE30\uBCF8 \uB808\uBCA8\uB85C",
545
+ saveTemplate: "\uC9C0\uAE08 \uBAA8\uC591\uC744 \uD15C\uD50C\uB9BF\uC73C\uB85C \uC800\uC7A5",
546
+ templateName: "\uD15C\uD50C\uB9BF \uC774\uB984",
547
+ noTemplates: "\uC774 \uB3C4\uAD6C\uB85C \uC800\uC7A5\uD55C \uD15C\uD50C\uB9BF\uC774 \uC5C6\uC5B4\uC694",
548
+ deleteTemplate: "\uD15C\uD50C\uB9BF \uC9C0\uC6B0\uAE30",
534
549
  lineWidth: "\uC120 \uAD75\uAE30",
535
550
  lineStyle: "\uC120 \uBAA8\uC591",
536
551
  lineSolid: "\uC2E4\uC120",
@@ -740,6 +755,18 @@ var STRINGS = {
740
755
  customColor: "Other color",
741
756
  partColors: "Part colors",
742
757
  resetColors: "Reset colors",
758
+ templates: "Templates",
759
+ levels: "Levels",
760
+ levelShown: "Show level",
761
+ levelValue: "Level value",
762
+ levelColor: "Level color",
763
+ removeLevel: "Remove level",
764
+ addLevel: "Add level",
765
+ resetLevels: "Default levels",
766
+ saveTemplate: "Save this look as a template",
767
+ templateName: "Template name",
768
+ noTemplates: "No templates for this tool yet",
769
+ deleteTemplate: "Delete template",
743
770
  lineWidth: "Line width",
744
771
  lineStyle: "Line style",
745
772
  lineSolid: "Solid",
@@ -985,6 +1012,15 @@ var GearIcon = () => /* @__PURE__ */ a3(Icon, { size: 14, children: [
985
1012
  /* @__PURE__ */ a3("circle", { cx: "10", cy: "10", r: "2.4" }),
986
1013
  /* @__PURE__ */ a3("path", { d: "M10 3v2M10 15v2M3 10h2M15 10h2M5 5l1.4 1.4M13.6 13.6L15 15M5 15l1.4-1.4M13.6 6.4L15 5" })
987
1014
  ] });
1015
+ var LevelsIcon = () => /* @__PURE__ */ a3(Icon, { children: [
1016
+ /* @__PURE__ */ a3("path", { d: "M3 5h9M3 10h14M3 15h11" }),
1017
+ /* @__PURE__ */ a3("circle", { cx: "15", cy: "5", r: "1.4" }),
1018
+ /* @__PURE__ */ a3("circle", { cx: "17", cy: "15", r: "1.4" })
1019
+ ] });
1020
+ var TemplateIcon = () => /* @__PURE__ */ a3(Icon, { children: [
1021
+ /* @__PURE__ */ a3("rect", { x: "3", y: "7", width: "10", height: "10", rx: "2" }),
1022
+ /* @__PURE__ */ a3("path", { d: "M7 4h8a2 2 0 0 1 2 2v8" })
1023
+ ] });
988
1024
  var SmallPlusIcon = () => /* @__PURE__ */ a3(Icon, { size: 14, children: /* @__PURE__ */ a3("path", { d: "M5 10h10M10 5v10" }) });
989
1025
  var SmallCloseIcon = () => /* @__PURE__ */ a3(Icon, { size: 14, children: /* @__PURE__ */ a3("path", { d: "M6 6l8 8M14 6l-8 8" }) });
990
1026
  var EyeIcon = () => /* @__PURE__ */ a3(Icon, { size: 14, children: [
@@ -1396,6 +1432,18 @@ var FONT_SIZES = [10, 12, 14, 16, 20, 24, 32];
1396
1432
  var DASH_ORDER = ["solid", "dashed", "dotted"];
1397
1433
  var RECENT_KEY = "fnc-drawing-colors";
1398
1434
  var POS_KEY = "fnc-selbar-pos";
1435
+ var TEMPLATES_KEY = "fnc-drawing-templates";
1436
+ var TEMPLATES_MAX = 20;
1437
+ var lookOf = (style) => {
1438
+ const { width, dash, fontSize, colors, levels } = style;
1439
+ return {
1440
+ ...width ? { width } : {},
1441
+ ...dash ? { dash } : {},
1442
+ ...fontSize ? { fontSize } : {},
1443
+ ...colors ? { colors: { ...colors } } : {},
1444
+ ...levels ? { levels: levels.map((l3) => ({ ...l3 })) } : {}
1445
+ };
1446
+ };
1399
1447
  var readJson = (key, fallback) => {
1400
1448
  try {
1401
1449
  const raw = localStorage.getItem(key);
@@ -1421,19 +1469,32 @@ function SelectionBar({ ctx }) {
1421
1469
  const [offset, setOffset] = d2(() => readJson(POS_KEY, [0, 0]));
1422
1470
  const [recent, setRecent] = d2(() => readJson(RECENT_KEY, []));
1423
1471
  const [menu, setMenu] = d2(null);
1472
+ const [templates, setTemplates] = d2(() => readJson(TEMPLATES_KEY, {}));
1473
+ const [naming, setNaming] = d2(null);
1424
1474
  const colorInput = T2(null);
1425
1475
  if (!d3 || s3.layout.plotWidth <= 0) return null;
1426
1476
  const def = ctx.chart.drawingDefinitions().find((x2) => x2.type === d3.type);
1427
1477
  const style = d3.style ?? {};
1428
1478
  const setStyle = (patch) => ctx.chart.updateDrawing(d3.id, { style: { ...style, ...patch } });
1479
+ const setStyleRaw = (next) => ctx.chart.updateDrawing(d3.id, { style: next });
1429
1480
  const current = d3.color ?? SWATCHES[0];
1430
1481
  const pickColor = (color) => {
1431
- if (style.colors) {
1482
+ if (style.colors || style.levels?.some((l3) => l3.color)) {
1432
1483
  const { colors: _drop, ...rest } = style;
1433
- ctx.chart.updateDrawing(d3.id, { color, style: rest });
1484
+ const levels = rest.levels?.map(({ color: _c, ...l3 }) => l3);
1485
+ ctx.chart.updateDrawing(d3.id, { color, style: { ...rest, ...levels ? { levels } : {} } });
1434
1486
  } else ctx.chart.updateDrawing(d3.id, { color });
1435
1487
  };
1436
- const slots = def?.colors ?? [];
1488
+ const slots = def?.levels ? [] : def?.colors ?? [];
1489
+ const levelRows = def?.levels ? drawingLevels(def, d3) : [];
1490
+ const setLevels = (next) => {
1491
+ const { colors: _drop, ...rest } = style;
1492
+ setStyleRaw({ ...rest, levels: next });
1493
+ };
1494
+ const resetLevels = () => {
1495
+ const { colors: _c, levels: _l, ...rest } = style;
1496
+ setStyleRaw(rest);
1497
+ };
1437
1498
  const slotColor = (key, fallback) => style.colors?.[key] ?? d3.color ?? fallback;
1438
1499
  const addRecent = (color) => {
1439
1500
  const next = [color, ...recent.filter((c3) => c3 !== color)].slice(0, 3);
@@ -1442,6 +1503,28 @@ function SelectionBar({ ctx }) {
1442
1503
  };
1443
1504
  const locked = !!style.locked;
1444
1505
  const dash = style.dash ?? "solid";
1506
+ const mine = templates[d3.type] ?? [];
1507
+ const keepTemplates = (next) => {
1508
+ const all = { ...templates, [d3.type]: next };
1509
+ if (!next.length) delete all[d3.type];
1510
+ setTemplates(all);
1511
+ writeJson(TEMPLATES_KEY, all);
1512
+ };
1513
+ const saveTemplate = () => {
1514
+ const name = (naming ?? "").trim().slice(0, 30);
1515
+ if (!name) return setNaming(null);
1516
+ keepTemplates([{ name, ...d3.color ? { color: d3.color } : {}, style: lookOf(style) }, ...mine.filter((x2) => x2.name !== name)].slice(0, TEMPLATES_MAX));
1517
+ setNaming(null);
1518
+ setMenu(null);
1519
+ };
1520
+ const applyTemplate = (tpl) => {
1521
+ const { text, locked: lock, hidden } = style;
1522
+ ctx.chart.updateDrawing(d3.id, {
1523
+ ...tpl.color ? { color: tpl.color } : {},
1524
+ style: { ...tpl.style, ...text !== void 0 ? { text } : {}, ...lock ? { locked: lock } : {}, ...hidden ? { hidden } : {} }
1525
+ });
1526
+ setMenu(null);
1527
+ };
1445
1528
  const actions = ctx.drawingActions?.(d3, ctx.chart) ?? [];
1446
1529
  const startMove = (e3) => {
1447
1530
  e3.preventDefault();
@@ -1521,6 +1604,65 @@ function SelectionBar({ ctx }) {
1521
1604
  )
1522
1605
  ] })
1523
1606
  ] }),
1607
+ def?.levels && /* @__PURE__ */ a3("div", { class: "fnc-selbar-menu", children: [
1608
+ /* @__PURE__ */ a3("button", { class: "fnc-btn", "data-tip": t3.levels, "aria-label": t3.levels, "aria-expanded": menu === "levels", onClick: () => setMenu(menu === "levels" ? null : "levels"), children: /* @__PURE__ */ a3(LevelsIcon, {}) }),
1609
+ menu === "levels" && /* @__PURE__ */ a3("div", { class: "fnc-menu fnc-selbar-pop fnc-levels-menu", role: "menu", onKeyDown: (e3) => e3.key !== "Escape" && e3.stopPropagation(), children: [
1610
+ /* @__PURE__ */ a3("div", { class: "fnc-levels-list fnc-scroll", children: levelRows.map((l3, i3) => /* @__PURE__ */ a3("div", { class: "fnc-level-row", children: [
1611
+ /* @__PURE__ */ a3(
1612
+ "input",
1613
+ {
1614
+ type: "checkbox",
1615
+ checked: l3.on !== false,
1616
+ "aria-label": `${t3.levelShown} ${l3.value}`,
1617
+ onChange: (e3) => setLevels(levelRows.map((x2, j2) => j2 === i3 ? { ...x2, on: e3.target.checked } : x2))
1618
+ }
1619
+ ),
1620
+ /* @__PURE__ */ a3(
1621
+ "input",
1622
+ {
1623
+ class: "fnc-input fnc-level-value",
1624
+ type: "number",
1625
+ step: "any",
1626
+ defaultValue: String(l3.value),
1627
+ "aria-label": t3.levelValue,
1628
+ onChange: (e3) => {
1629
+ const v3 = Number(e3.target.value);
1630
+ if (Number.isFinite(v3) && Math.abs(v3) <= 1e3) setLevels(levelRows.map((x2, j2) => j2 === i3 ? { ...x2, value: v3 } : x2));
1631
+ }
1632
+ }
1633
+ ),
1634
+ /* @__PURE__ */ a3("label", { class: "fnc-swatch fnc-level-color", style: { background: l3.color }, "data-tip": t3.levelColor, children: /* @__PURE__ */ a3(
1635
+ "input",
1636
+ {
1637
+ type: "color",
1638
+ "aria-label": `${t3.levelColor} ${l3.value}`,
1639
+ value: /^#[0-9a-f]{6}$/i.test(l3.color ?? "") ? l3.color : "#3182f6",
1640
+ onInput: (e3) => setLevels(levelRows.map((x2, j2) => j2 === i3 ? { ...x2, color: e3.target.value } : x2))
1641
+ }
1642
+ ) }),
1643
+ /* @__PURE__ */ a3("button", { class: "fnc-ind-btn", "data-tip": t3.removeLevel, "aria-label": `${l3.value} ${t3.removeLevel}`, onClick: () => setLevels(levelRows.filter((_3, j2) => j2 !== i3)), children: /* @__PURE__ */ a3(SmallCloseIcon, {}) })
1644
+ ] }, `${i3}:${l3.value}`)) }),
1645
+ /* @__PURE__ */ a3("div", { class: "fnc-menu-sep" }),
1646
+ /* @__PURE__ */ a3(
1647
+ "button",
1648
+ {
1649
+ class: "fnc-menu-item",
1650
+ role: "menuitem",
1651
+ onClick: () => {
1652
+ const values = levelRows.map((x2) => x2.value);
1653
+ const top = values.length ? Math.max(...values) : 0;
1654
+ const gap = values.length > 1 ? Math.abs(values[values.length - 1] - values[values.length - 2]) || 1 : 1;
1655
+ setLevels([...levelRows, { value: Number((top + gap).toFixed(4)), on: true, color: current }]);
1656
+ },
1657
+ children: [
1658
+ "+ ",
1659
+ t3.addLevel
1660
+ ]
1661
+ }
1662
+ ),
1663
+ /* @__PURE__ */ a3("button", { class: "fnc-menu-item", role: "menuitem", onClick: resetLevels, children: t3.resetLevels })
1664
+ ] })
1665
+ ] }),
1524
1666
  /* @__PURE__ */ a3("div", { class: "fnc-sep" }),
1525
1667
  /* @__PURE__ */ a3("div", { class: "fnc-selbar-menu", children: [
1526
1668
  /* @__PURE__ */ a3("button", { class: "fnc-btn fnc-selbar-width", "data-tip": t3.lineWidth, "aria-label": t3.lineWidth, "aria-expanded": menu === "width", onClick: () => setMenu(menu === "width" ? null : "width"), children: /* @__PURE__ */ a3("svg", { width: "20", height: "20", viewBox: "0 0 20 20", "aria-hidden": "true", children: /* @__PURE__ */ a3("path", { d: "M3 10h14", stroke: "currentColor", "stroke-width": style.width ?? 2, "stroke-linecap": "round" }) }) }),
@@ -1585,6 +1727,69 @@ function SelectionBar({ ctx }) {
1585
1727
  }
1586
1728
  )) })
1587
1729
  ] }),
1730
+ /* @__PURE__ */ a3("div", { class: "fnc-selbar-menu", children: [
1731
+ /* @__PURE__ */ a3(
1732
+ "button",
1733
+ {
1734
+ class: "fnc-btn",
1735
+ "data-tip": t3.templates,
1736
+ "aria-label": t3.templates,
1737
+ "aria-expanded": menu === "template",
1738
+ onClick: () => {
1739
+ setNaming(null);
1740
+ setMenu(menu === "template" ? null : "template");
1741
+ },
1742
+ children: /* @__PURE__ */ a3(TemplateIcon, {})
1743
+ }
1744
+ ),
1745
+ menu === "template" && /* @__PURE__ */ a3("div", { class: "fnc-menu fnc-selbar-pop fnc-template-menu", role: "menu", children: [
1746
+ mine.length === 0 && /* @__PURE__ */ a3("div", { class: "fnc-menu-note", children: t3.noTemplates }),
1747
+ mine.map((tpl) => /* @__PURE__ */ a3("div", { class: "fnc-template-row", children: [
1748
+ /* @__PURE__ */ a3("button", { class: "fnc-menu-item", role: "menuitem", onClick: () => applyTemplate(tpl), children: [
1749
+ /* @__PURE__ */ a3("span", { class: "fnc-swatch", style: { background: tpl.color ?? current } }),
1750
+ /* @__PURE__ */ a3("svg", { width: "28", height: "12", viewBox: "0 0 28 12", "aria-hidden": "true", children: /* @__PURE__ */ a3(
1751
+ "path",
1752
+ {
1753
+ d: "M2 6h24",
1754
+ stroke: tpl.color ?? current,
1755
+ "stroke-width": tpl.style.width ?? 2,
1756
+ "stroke-linecap": "round",
1757
+ "stroke-dasharray": tpl.style.dash === "dashed" ? "4 3" : tpl.style.dash === "dotted" ? "1 3" : void 0
1758
+ }
1759
+ ) }),
1760
+ /* @__PURE__ */ a3("span", { children: tpl.name })
1761
+ ] }),
1762
+ /* @__PURE__ */ a3(
1763
+ "button",
1764
+ {
1765
+ class: "fnc-ind-btn",
1766
+ "data-tip": t3.deleteTemplate,
1767
+ "aria-label": `${tpl.name} ${t3.deleteTemplate}`,
1768
+ onClick: () => keepTemplates(mine.filter((x2) => x2 !== tpl)),
1769
+ children: /* @__PURE__ */ a3(SmallCloseIcon, {})
1770
+ }
1771
+ )
1772
+ ] })),
1773
+ /* @__PURE__ */ a3("div", { class: "fnc-menu-sep" }),
1774
+ naming === null ? /* @__PURE__ */ a3("button", { class: "fnc-menu-item", role: "menuitem", onClick: () => setNaming(""), children: t3.saveTemplate }) : /* @__PURE__ */ a3(
1775
+ "input",
1776
+ {
1777
+ class: "fnc-selbar-text fnc-template-name",
1778
+ value: naming,
1779
+ placeholder: t3.templateName,
1780
+ "aria-label": t3.templateName,
1781
+ maxLength: 30,
1782
+ autoFocus: true,
1783
+ onInput: (e3) => setNaming(e3.target.value),
1784
+ onKeyDown: (e3) => {
1785
+ e3.stopPropagation();
1786
+ if (e3.key === "Enter") saveTemplate();
1787
+ if (e3.key === "Escape") setNaming(null);
1788
+ }
1789
+ }
1790
+ )
1791
+ ] })
1792
+ ] }),
1588
1793
  actions.length > 0 && /* @__PURE__ */ a3("div", { class: "fnc-sep" }),
1589
1794
  actions.map((a4) => /* @__PURE__ */ a3(
1590
1795
  "button",
@@ -4879,6 +5084,20 @@ var CSS = (
4879
5084
  .fnc-tools-seg[data-count="5"] button, .fnc-tools-seg[data-count="8"] button, .fnc-tools-seg[data-count="13"] button { flex-direction: column; gap: 2px; height: auto; min-height: 40px; padding: 5px 4px; font-size: 12px; white-space: normal; word-break: keep-all; text-align: center; line-height: 1.25; }
4880
5085
  .fnc-tools-seg button { display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-width: 0; padding: 0 6px; }
4881
5086
  .fnc-tools-seg svg { width: 16px; height: 16px; flex: none; }
5087
+ .fnc-template-menu { min-width: 220px; }
5088
+ .fnc-levels-menu { min-width: 230px; }
5089
+ .fnc-levels-list { max-height: 300px; overflow-y: auto; padding: 2px 0; }
5090
+ .fnc-level-row { display: flex; align-items: center; gap: 8px; padding: 3px 8px; }
5091
+ .fnc-level-row input[type='checkbox'] { width: 15px; height: 15px; margin: 0; accent-color: var(--fnc-accent, #3182f6); }
5092
+ .fnc-level-value { flex: none; width: 84px; height: 28px; padding: 0 8px; font-size: 13px; }
5093
+ .fnc-level-color { position: relative; flex: none; overflow: hidden; }
5094
+ .fnc-level-color input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
5095
+ .fnc-template-row { display: flex; align-items: center; }
5096
+ .fnc-template-row .fnc-menu-item { flex: 1; min-width: 0; gap: 8px; }
5097
+ .fnc-template-row .fnc-menu-item span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
5098
+ .fnc-template-name { width: calc(100% - 8px); margin: 4px; }
5099
+ .fnc-menu-note { padding: 8px 10px; color: var(--fnc-text-2); font-size: 12px; }
5100
+ .fnc-menu-sep { height: 1px; margin: 4px 6px; background: var(--fnc-border); }
4882
5101
  .fnc-tools-layouts { display: flex; flex-direction: column; gap: 2px; padding: 0 2px 4px; }
4883
5102
  .fnc-tools-sep { height: 1px; margin: 6px 4px; background: var(--fnc-border); }
4884
5103
  .fnc-tools-icon { display: inline-flex; width: 20px; height: 20px; flex: none; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnest/charts-ui",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "Pro trading UI (toolbar, drawing tools, sheets) for Funnest Charts. Framework-agnostic.",
5
5
  "keywords": [
6
6
  "chart",
@@ -42,7 +42,7 @@
42
42
  "NOTICE"
43
43
  ],
44
44
  "dependencies": {
45
- "@funnest/charts": "0.9.0"
45
+ "@funnest/charts": "0.9.2"
46
46
  },
47
47
  "devDependencies": {
48
48
  "preact": "^11.2.0"