@funnest/charts-ui 0.11.64 → 0.11.65

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.
@@ -1,23 +1,41 @@
1
1
  /** @jsxImportSource preact */
2
- import type { ComponentChildren } from 'preact';
2
+ import { type ComponentChildren } from 'preact';
3
3
  import type { Strings } from '../i18n.js';
4
4
  /** Rows of the board: grays, three lighter rows, the hues, two darker rows. */
5
5
  export declare const PALETTE: readonly (readonly string[])[];
6
6
  export declare function recentColors(): string[];
7
7
  /** A color picked with the browser's picker: first among the recent ones (shared by every field). */
8
8
  export declare function rememberColor(color: string): string[];
9
+ type PaletteStrings = Pick<Strings, 'paletteCustom' | 'paletteRecent'>;
9
10
  /**
10
- * A button (`children`: what it shows) that opens the board under it — or above when there's no room
11
- * — placed in the viewport, so a scrolling list or a menu it sits in can't clip it.
11
+ * The board itself: the ready colors, the ones picked lately, and 직접 고르기 (the browser's picker).
12
+ * In ColorPicker's pop, or right in a menu (🖌 on the drawing bar).
12
13
  */
13
- export declare function ColorPicker({ value, label, t, onPick, class: cls, style, tip, children, }: {
14
+ export declare function PaletteBoard({ value, label, t, onPick, onCustom }: {
15
+ value: string;
16
+ label: string;
17
+ t: PaletteStrings;
18
+ onPick(color: string): void;
19
+ onCustom?(color: string): void;
20
+ }): import("preact").JSX.Element;
21
+ /**
22
+ * A button (`children`: what it shows) that opens the board under it — or above when there's no room.
23
+ * The board is on a layer over the page: a scrolling list, a menu or a moved (transformed) bar it
24
+ * sits in can't cut it off.
25
+ */
26
+ export declare function ColorPicker({ value, label, t, onPick, class: cls, style, tip, boardClass, onOpen, children, }: {
14
27
  /** #rrggbb (anything else: nothing marked). */
15
28
  value: string;
16
29
  label: string;
17
- t: Pick<Strings, 'paletteCustom' | 'paletteRecent'>;
30
+ t: PaletteStrings;
18
31
  onPick(color: string): void;
19
32
  class?: string;
20
33
  style?: Record<string, string>;
21
34
  tip?: string;
35
+ /** A class for the board (fnc-palette-big: bigger cells for a finger). */
36
+ boardClass?: string;
37
+ /** The board opened (e.g. to close the menus beside the button). */
38
+ onOpen?(): void;
22
39
  children?: ComponentChildren;
23
40
  }): import("preact").JSX.Element;
41
+ export {};
@@ -6,4 +6,4 @@ import type { ChartSettings } from '@funnest/charts';
6
6
  */
7
7
  export declare function usePageLayer(anchor: {
8
8
  current: HTMLElement | null;
9
- }, settings: ChartSettings): HTMLElement | null;
9
+ }, settings?: ChartSettings): HTMLElement | null;
package/dist/index.js CHANGED
@@ -1337,258 +1337,6 @@ function IntervalVisibilityEditor({ t: t3, value, onChange }) {
1337
1337
  }) });
1338
1338
  }
1339
1339
 
1340
- // src/components/color-picker.tsx
1341
- var GRAYS = ["#FFFFFF", "#F2F4F6", "#D1D6DB", "#B0B8C1", "#8B95A1", "#6B7684", "#4E5968", "#333D4B", "#191F28", "#000000"];
1342
- var HUES = ["#F04452", "#FF9F0A", "#FFD43B", "#94D82D", "#12B886", "#15AABF", "#3182F6", "#4C6EF5", "#7048E8", "#E64980"];
1343
- var hex = (n2) => Math.round(Math.max(0, Math.min(255, n2))).toString(16).padStart(2, "0");
1344
- function mix(color, t3) {
1345
- const v3 = [1, 3, 5].map((i3) => parseInt(color.slice(i3, i3 + 2), 16));
1346
- const to = t3 > 0 ? 255 : 0;
1347
- const k2 = Math.abs(t3);
1348
- return `#${v3.map((c3) => hex(c3 + (to - c3) * k2)).join("")}`.toUpperCase();
1349
- }
1350
- var PALETTE = [GRAYS, ...[0.75, 0.5, 0.25].map((t3) => HUES.map((c3) => mix(c3, t3))), HUES, ...[-0.25, -0.5].map((t3) => HUES.map((c3) => mix(c3, t3)))];
1351
- var RECENT_KEY = "fnc-drawing-colors";
1352
- var RECENT_MAX = 10;
1353
- function recentColors() {
1354
- try {
1355
- const list = JSON.parse(localStorage.getItem(RECENT_KEY) ?? "[]");
1356
- return Array.isArray(list) ? list.filter((c3) => typeof c3 === "string" && /^#[0-9a-f]{6}$/i.test(c3)).slice(0, RECENT_MAX) : [];
1357
- } catch {
1358
- return [];
1359
- }
1360
- }
1361
- function rememberColor(color) {
1362
- const next = [color, ...recentColors().filter((c3) => c3.toLowerCase() !== color.toLowerCase())].slice(0, RECENT_MAX);
1363
- try {
1364
- localStorage.setItem(RECENT_KEY, JSON.stringify(next));
1365
- } catch {
1366
- }
1367
- return next;
1368
- }
1369
- var MARGIN = 8;
1370
- var same = (a4, b) => a4.slice(0, 7).toLowerCase() === b.slice(0, 7).toLowerCase();
1371
- function ColorPicker({
1372
- value,
1373
- label,
1374
- t: t3,
1375
- onPick,
1376
- class: cls,
1377
- style,
1378
- tip,
1379
- children
1380
- }) {
1381
- const [open, setOpen] = d2(false);
1382
- const [recent, setRecent] = d2([]);
1383
- const wrap = T2(null);
1384
- const button = T2(null);
1385
- const pop = T2(null);
1386
- A2(() => {
1387
- if (!open) return;
1388
- setRecent(recentColors());
1389
- const close = (e3) => !wrap.current?.contains(e3.target) && setOpen(false);
1390
- const esc = (e3) => {
1391
- if (e3.key !== "Escape") return;
1392
- e3.stopPropagation();
1393
- setOpen(false);
1394
- button.current?.focus();
1395
- };
1396
- document.addEventListener("pointerdown", close, true);
1397
- document.addEventListener("keydown", esc, true);
1398
- return () => {
1399
- document.removeEventListener("pointerdown", close, true);
1400
- document.removeEventListener("keydown", esc, true);
1401
- };
1402
- }, [open]);
1403
- F2(() => {
1404
- const el = pop.current;
1405
- const a4 = button.current;
1406
- if (!open || !el || !a4) return;
1407
- const place = () => {
1408
- const r3 = a4.getBoundingClientRect();
1409
- el.style.left = "0px";
1410
- el.style.top = "0px";
1411
- const origin = el.getBoundingClientRect();
1412
- const vw = document.documentElement.clientWidth;
1413
- const vh = document.documentElement.clientHeight;
1414
- const below = r3.bottom + 6;
1415
- const top = below + el.offsetHeight + MARGIN <= vh ? below : Math.max(MARGIN, r3.top - 6 - el.offsetHeight);
1416
- const left = Math.max(MARGIN, Math.min(vw - MARGIN - el.offsetWidth, r3.left));
1417
- el.style.left = `${Math.round(left - origin.left)}px`;
1418
- el.style.top = `${Math.round(top - origin.top)}px`;
1419
- };
1420
- place();
1421
- window.addEventListener("resize", place);
1422
- window.addEventListener("scroll", place, true);
1423
- return () => {
1424
- window.removeEventListener("resize", place);
1425
- window.removeEventListener("scroll", place, true);
1426
- };
1427
- }, [open]);
1428
- const pick = (color) => {
1429
- onPick(color);
1430
- setOpen(false);
1431
- };
1432
- const swatch = (color) => /* @__PURE__ */ a3(
1433
- "button",
1434
- {
1435
- type: "button",
1436
- class: "fnc-palette-cell",
1437
- role: "option",
1438
- style: { background: color },
1439
- "aria-label": color,
1440
- "aria-selected": same(color, value),
1441
- onClick: () => pick(color)
1442
- },
1443
- color
1444
- );
1445
- return /* @__PURE__ */ a3("span", { class: "fnc-palette-wrap", ref: wrap, children: [
1446
- /* @__PURE__ */ a3(
1447
- "button",
1448
- {
1449
- type: "button",
1450
- ref: button,
1451
- class: cls,
1452
- style,
1453
- "data-tip": tip,
1454
- "aria-label": label,
1455
- "aria-haspopup": "listbox",
1456
- "aria-expanded": open,
1457
- onClick: () => setOpen(!open),
1458
- children
1459
- }
1460
- ),
1461
- open && /* @__PURE__ */ a3("div", { class: "fnc-palette", ref: pop, role: "dialog", "aria-label": label, onKeyDown: (e3) => e3.key !== "Escape" && e3.stopPropagation(), children: [
1462
- /* @__PURE__ */ a3("div", { class: "fnc-palette-grid", role: "listbox", "aria-label": label, children: PALETTE.map((row2) => row2.map(swatch)) }),
1463
- recent.length > 0 && /* @__PURE__ */ a3($, { children: [
1464
- /* @__PURE__ */ a3("div", { class: "fnc-palette-title", children: t3.paletteRecent }),
1465
- /* @__PURE__ */ a3("div", { class: "fnc-palette-grid", role: "listbox", "aria-label": t3.paletteRecent, children: recent.map(swatch) })
1466
- ] }),
1467
- /* @__PURE__ */ a3("label", { class: "fnc-palette-custom", children: [
1468
- /* @__PURE__ */ a3("span", { class: "fnc-palette-custom-chip", style: { background: /^#[0-9a-f]{6}/i.test(value) ? value.slice(0, 7) : "#3182F6" } }),
1469
- /* @__PURE__ */ a3("span", { children: t3.paletteCustom }),
1470
- /* @__PURE__ */ a3(
1471
- "input",
1472
- {
1473
- type: "color",
1474
- value: /^#[0-9a-f]{6}/i.test(value) ? value.slice(0, 7) : "#3182f6",
1475
- onInput: (e3) => onPick(e3.target.value),
1476
- onChange: (e3) => setRecent(rememberColor(e3.target.value))
1477
- }
1478
- )
1479
- ] })
1480
- ] })
1481
- ] });
1482
- }
1483
-
1484
- // src/components/hover-open.ts
1485
- var HIDE_TIP = "fnc-hide-tip";
1486
- var OPEN_MS = 140;
1487
- var CLOSE_MS = 260;
1488
- function useHoverOpen(open, onOpen, group) {
1489
- const timer = T2(null);
1490
- const byHover = T2(false);
1491
- const clear = () => {
1492
- if (timer.current) clearTimeout(timer.current);
1493
- timer.current = null;
1494
- };
1495
- A2(() => {
1496
- if (open) {
1497
- group?.current?.dispatchEvent(new CustomEvent(HIDE_TIP, { bubbles: true }));
1498
- return;
1499
- }
1500
- byHover.current = false;
1501
- clear();
1502
- }, [open]);
1503
- A2(() => clear, []);
1504
- return {
1505
- onPointerEnter: (e3) => {
1506
- if (e3.pointerType !== "mouse") return;
1507
- clear();
1508
- if (open) return;
1509
- timer.current = setTimeout(() => {
1510
- byHover.current = true;
1511
- onOpen(true);
1512
- }, OPEN_MS);
1513
- },
1514
- onPointerLeave: (e3) => {
1515
- if (e3.pointerType !== "mouse") return;
1516
- clear();
1517
- if (!open || !byHover.current) return;
1518
- timer.current = setTimeout(() => onOpen(false), CLOSE_MS);
1519
- },
1520
- /** The corner button: opens or closes the list — or, when hovering opened it, keeps it open until a click outside. */
1521
- toggle: () => {
1522
- clear();
1523
- if (open && byHover.current) {
1524
- byHover.current = false;
1525
- return;
1526
- }
1527
- onOpen(!open);
1528
- }
1529
- };
1530
- }
1531
-
1532
- // src/components/keep-in-view.ts
1533
- var MARGIN2 = 8;
1534
- function useKeepInView(open) {
1535
- const ref = T2(null);
1536
- F2(() => {
1537
- const el = ref.current;
1538
- if (!open || !el) return;
1539
- el.style.translate = "";
1540
- const fit2 = () => {
1541
- el.style.translate = "";
1542
- el.style.maxHeight = "";
1543
- const r3 = el.getBoundingClientRect();
1544
- const root = el.closest(".fnc-root")?.getBoundingClientRect();
1545
- const maxY = Math.min(document.documentElement.clientHeight, root?.bottom ?? Infinity) - MARGIN2;
1546
- if (r3.bottom > maxY) {
1547
- el.style.maxHeight = `${Math.max(120, Math.floor(maxY - r3.top))}px`;
1548
- el.style.overflowY = "auto";
1549
- }
1550
- const minX = Math.max(0, root?.left ?? 0) + MARGIN2;
1551
- const maxX = Math.min(document.documentElement.clientWidth, root?.right ?? Infinity) - MARGIN2;
1552
- let dx = 0;
1553
- if (r3.right > maxX) dx = maxX - r3.right;
1554
- if (r3.left + dx < minX) dx = minX - r3.left;
1555
- if (dx) el.style.translate = `${Math.round(dx)}px 0`;
1556
- };
1557
- fit2();
1558
- window.addEventListener("resize", fit2);
1559
- return () => window.removeEventListener("resize", fit2);
1560
- }, [open]);
1561
- return ref;
1562
- }
1563
- function useBesideAnchor(open, anchor) {
1564
- const ref = T2(null);
1565
- F2(() => {
1566
- const el = ref.current;
1567
- const a4 = anchor.current;
1568
- if (!open || !el || !a4) return;
1569
- const place = () => {
1570
- const r3 = a4.getBoundingClientRect();
1571
- el.style.position = "fixed";
1572
- el.style.left = "0px";
1573
- el.style.top = "0px";
1574
- const origin = el.getBoundingClientRect();
1575
- const vh = document.documentElement.clientHeight;
1576
- const top = Math.max(MARGIN2, Math.min(r3.top, vh - MARGIN2 - el.offsetHeight));
1577
- el.style.left = `${Math.round(r3.right + 8 - origin.left)}px`;
1578
- el.style.top = `${Math.round(top - origin.top)}px`;
1579
- };
1580
- place();
1581
- const bar = a4.closest(".fnc-drawbar");
1582
- window.addEventListener("resize", place);
1583
- bar?.addEventListener("scroll", place);
1584
- return () => {
1585
- window.removeEventListener("resize", place);
1586
- bar?.removeEventListener("scroll", place);
1587
- };
1588
- }, [open]);
1589
- return ref;
1590
- }
1591
-
1592
1340
  // src/shell.ts
1593
1341
  import { darkTheme, directionColors, lightTheme } from "@funnest/charts";
1594
1342
 
@@ -2991,9 +2739,9 @@ var CSS = (
2991
2739
  .fnc-ss-text { box-sizing: border-box; width: 100%; height: 42px; font-size: 15px; }
2992
2740
  .fnc-ss-body .fnc-menu-item { min-height: 44px; font-size: 15px; }
2993
2741
  .fnc-ss-body .fnc-levels-list { max-height: none; }
2994
- /* \u{1F58C}'s colors: one row of swatches over the bar. */
2995
- .fnc-menu.fnc-brush-pop { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 10px; }
2996
- .fnc-brush-pop .fnc-swatch { width: 24px; height: 24px; }
2742
+ /* A list over the bar that's taller than the room scrolls, but shows no scroll bar. */
2743
+ .fnc-selbar-pop { scrollbar-width: none; }
2744
+ .fnc-selbar-pop::-webkit-scrollbar { display: none; }
2997
2745
  .fnc-selbar-pop.fnc-note-menu { width: auto; }
2998
2746
  .fnc-line-pop { padding: 6px 14px; }
2999
2747
  .fnc-line-pop .fnc-ss-seg button { width: 42px; }
@@ -3232,6 +2980,9 @@ var CSS = (
3232
2980
  z-index: 30;
3233
2981
  }
3234
2982
  .fnc-levels-list { max-height: none; }
2983
+ /* T's note on a phone on its side: a shorter field, so it fits over the chart without scrolling. */
2984
+ .fnc-note-menu { gap: 6px; padding: 8px 12px; }
2985
+ .fnc-note-menu textarea { min-height: 36px; }
3235
2986
  /* Thin indicator panes: their legend stays on one line (not over the pane below). */
3236
2987
  .fnc-pane-legend .fnc-ind { flex-wrap: nowrap; white-space: nowrap; }
3237
2988
  .fnc-backdrop { padding: 0; align-items: stretch; }
@@ -3328,6 +3079,15 @@ var CSS = (
3328
3079
  box-shadow: 0 8px 28px rgb(0 0 0 / 0.16), 0 0 0 1px var(--fnc-border);
3329
3080
  cursor: default;
3330
3081
  }
3082
+ @media (pointer: coarse) {
3083
+ /* \u{1F58C}'s board for a finger: cells up to 30px, as many as the screen's width and height leave room for. */
3084
+ .fnc-palette-big .fnc-palette-grid { --cell: min(30px, calc((100vw - 81px) / 10), calc((100dvh - 142px) / 8)); grid-template-columns: repeat(10, var(--cell)); gap: 5px; }
3085
+ .fnc-palette-big .fnc-palette-cell { width: var(--cell); height: var(--cell); }
3086
+ }
3087
+ .fnc-palette-board { display: flex; flex-direction: column; gap: 6px; }
3088
+ /* The board's page layer: only the board takes taps, the page under it stays live. */
3089
+ .fnc-root.fnc-layer.fnc-layer-pass { pointer-events: none; }
3090
+ .fnc-layer-pass > * { pointer-events: auto; }
3331
3091
  .fnc-palette-grid { display: grid; grid-template-columns: repeat(10, 20px); gap: 4px; }
3332
3092
  .fnc-palette-cell { width: 20px; height: 20px; padding: 0; border: 0; border-radius: 5px; cursor: pointer; box-shadow: inset 0 0 0 1px rgb(127 127 127 / 0.22); }
3333
3093
  .fnc-palette-cell:hover { transform: scale(1.12); }
@@ -3757,6 +3517,280 @@ function usePageLayer(anchor, settings) {
3757
3517
  return layer;
3758
3518
  }
3759
3519
 
3520
+ // src/components/color-picker.tsx
3521
+ var GRAYS = ["#FFFFFF", "#F2F4F6", "#D1D6DB", "#B0B8C1", "#8B95A1", "#6B7684", "#4E5968", "#333D4B", "#191F28", "#000000"];
3522
+ var HUES = ["#F04452", "#FF9F0A", "#FFD43B", "#94D82D", "#12B886", "#15AABF", "#3182F6", "#4C6EF5", "#7048E8", "#E64980"];
3523
+ var hex = (n2) => Math.round(Math.max(0, Math.min(255, n2))).toString(16).padStart(2, "0");
3524
+ function mix(color, t3) {
3525
+ const v3 = [1, 3, 5].map((i3) => parseInt(color.slice(i3, i3 + 2), 16));
3526
+ const to = t3 > 0 ? 255 : 0;
3527
+ const k2 = Math.abs(t3);
3528
+ return `#${v3.map((c3) => hex(c3 + (to - c3) * k2)).join("")}`.toUpperCase();
3529
+ }
3530
+ var PALETTE = [GRAYS, ...[0.75, 0.5, 0.25].map((t3) => HUES.map((c3) => mix(c3, t3))), HUES, ...[-0.25, -0.5].map((t3) => HUES.map((c3) => mix(c3, t3)))];
3531
+ var RECENT_KEY = "fnc-drawing-colors";
3532
+ var RECENT_MAX = 10;
3533
+ function recentColors() {
3534
+ try {
3535
+ const list = JSON.parse(localStorage.getItem(RECENT_KEY) ?? "[]");
3536
+ return Array.isArray(list) ? list.filter((c3) => typeof c3 === "string" && /^#[0-9a-f]{6}$/i.test(c3)).slice(0, RECENT_MAX) : [];
3537
+ } catch {
3538
+ return [];
3539
+ }
3540
+ }
3541
+ function rememberColor(color) {
3542
+ const next = [color, ...recentColors().filter((c3) => c3.toLowerCase() !== color.toLowerCase())].slice(0, RECENT_MAX);
3543
+ try {
3544
+ localStorage.setItem(RECENT_KEY, JSON.stringify(next));
3545
+ } catch {
3546
+ }
3547
+ return next;
3548
+ }
3549
+ var MARGIN = 8;
3550
+ var same = (a4, b) => a4.slice(0, 7).toLowerCase() === b.slice(0, 7).toLowerCase();
3551
+ function PaletteBoard({ value, label, t: t3, onPick, onCustom }) {
3552
+ const [recent, setRecent] = d2(recentColors);
3553
+ const swatch = (color) => /* @__PURE__ */ a3(
3554
+ "button",
3555
+ {
3556
+ type: "button",
3557
+ class: "fnc-palette-cell",
3558
+ role: "option",
3559
+ style: { background: color },
3560
+ "aria-label": color,
3561
+ "aria-selected": same(color, value),
3562
+ onClick: () => onPick(color)
3563
+ },
3564
+ color
3565
+ );
3566
+ const hex63 = /^#[0-9a-f]{6}/i.test(value) ? value.slice(0, 7) : "";
3567
+ return /* @__PURE__ */ a3("div", { class: "fnc-palette-board", children: [
3568
+ /* @__PURE__ */ a3("div", { class: "fnc-palette-grid", role: "listbox", "aria-label": label, children: PALETTE.map((row2) => row2.map(swatch)) }),
3569
+ recent.length > 0 && /* @__PURE__ */ a3($, { children: [
3570
+ /* @__PURE__ */ a3("div", { class: "fnc-palette-title", children: t3.paletteRecent }),
3571
+ /* @__PURE__ */ a3("div", { class: "fnc-palette-grid", role: "listbox", "aria-label": t3.paletteRecent, children: recent.map(swatch) })
3572
+ ] }),
3573
+ /* @__PURE__ */ a3("label", { class: "fnc-palette-custom", children: [
3574
+ /* @__PURE__ */ a3("span", { class: "fnc-palette-custom-chip", style: { background: hex63 || "#3182F6" } }),
3575
+ /* @__PURE__ */ a3("span", { children: t3.paletteCustom }),
3576
+ /* @__PURE__ */ a3(
3577
+ "input",
3578
+ {
3579
+ type: "color",
3580
+ value: hex63.toLowerCase() || "#3182f6",
3581
+ onInput: (e3) => (onCustom ?? onPick)(e3.target.value),
3582
+ onChange: (e3) => setRecent(rememberColor(e3.target.value))
3583
+ }
3584
+ )
3585
+ ] })
3586
+ ] });
3587
+ }
3588
+ function ColorPicker({
3589
+ value,
3590
+ label,
3591
+ t: t3,
3592
+ onPick,
3593
+ class: cls,
3594
+ style,
3595
+ tip,
3596
+ boardClass,
3597
+ onOpen,
3598
+ children
3599
+ }) {
3600
+ const [open, setOpen] = d2(false);
3601
+ const wrap = T2(null);
3602
+ const button = T2(null);
3603
+ const pop = T2(null);
3604
+ A2(() => {
3605
+ if (!open) return;
3606
+ const close = (e3) => !wrap.current?.contains(e3.target) && !pop.current?.contains(e3.target) && setOpen(false);
3607
+ const esc = (e3) => {
3608
+ if (e3.key !== "Escape") return;
3609
+ e3.stopPropagation();
3610
+ setOpen(false);
3611
+ button.current?.focus();
3612
+ };
3613
+ document.addEventListener("pointerdown", close, true);
3614
+ document.addEventListener("keydown", esc, true);
3615
+ return () => {
3616
+ document.removeEventListener("pointerdown", close, true);
3617
+ document.removeEventListener("keydown", esc, true);
3618
+ };
3619
+ }, [open]);
3620
+ return /* @__PURE__ */ a3("span", { class: "fnc-palette-wrap", ref: wrap, children: [
3621
+ /* @__PURE__ */ a3(
3622
+ "button",
3623
+ {
3624
+ type: "button",
3625
+ ref: button,
3626
+ class: cls,
3627
+ style,
3628
+ "data-tip": tip,
3629
+ "aria-label": label,
3630
+ "aria-haspopup": "listbox",
3631
+ "aria-expanded": open,
3632
+ onClick: () => {
3633
+ if (!open) onOpen?.();
3634
+ setOpen(!open);
3635
+ },
3636
+ children
3637
+ }
3638
+ ),
3639
+ open && /* @__PURE__ */ a3(FloatingBoard, { anchor: button, pop, label, class: boardClass, children: /* @__PURE__ */ a3(
3640
+ PaletteBoard,
3641
+ {
3642
+ value,
3643
+ label,
3644
+ t: t3,
3645
+ onPick: (color) => {
3646
+ onPick(color);
3647
+ setOpen(false);
3648
+ },
3649
+ onCustom: onPick
3650
+ }
3651
+ ) })
3652
+ ] });
3653
+ }
3654
+ function FloatingBoard({ anchor, pop, label, class: cls, children }) {
3655
+ const layer = usePageLayer(anchor);
3656
+ F2(() => {
3657
+ const el = pop.current;
3658
+ const a4 = anchor.current;
3659
+ if (!layer || !el || !a4) return;
3660
+ layer.classList.add("fnc-layer-pass");
3661
+ const place = () => {
3662
+ const r3 = a4.getBoundingClientRect();
3663
+ const vw = document.documentElement.clientWidth;
3664
+ const vh = document.documentElement.clientHeight;
3665
+ const below = r3.bottom + 6;
3666
+ const top = below + el.offsetHeight + MARGIN <= vh ? below : Math.max(MARGIN, r3.top - 6 - el.offsetHeight);
3667
+ const left = Math.max(MARGIN, Math.min(vw - MARGIN - el.offsetWidth, r3.left));
3668
+ el.style.left = `${Math.round(left)}px`;
3669
+ el.style.top = `${Math.round(top)}px`;
3670
+ };
3671
+ place();
3672
+ window.addEventListener("resize", place);
3673
+ window.addEventListener("scroll", place, true);
3674
+ return () => {
3675
+ window.removeEventListener("resize", place);
3676
+ window.removeEventListener("scroll", place, true);
3677
+ };
3678
+ }, [layer]);
3679
+ if (!layer) return null;
3680
+ return X(
3681
+ /* @__PURE__ */ a3("div", { class: cls ? `fnc-palette ${cls}` : "fnc-palette", ref: pop, role: "dialog", "aria-label": label, onKeyDown: (e3) => e3.key !== "Escape" && e3.stopPropagation(), children }),
3682
+ layer
3683
+ );
3684
+ }
3685
+
3686
+ // src/components/hover-open.ts
3687
+ var HIDE_TIP = "fnc-hide-tip";
3688
+ var OPEN_MS = 140;
3689
+ var CLOSE_MS = 260;
3690
+ function useHoverOpen(open, onOpen, group) {
3691
+ const timer = T2(null);
3692
+ const byHover = T2(false);
3693
+ const clear = () => {
3694
+ if (timer.current) clearTimeout(timer.current);
3695
+ timer.current = null;
3696
+ };
3697
+ A2(() => {
3698
+ if (open) {
3699
+ group?.current?.dispatchEvent(new CustomEvent(HIDE_TIP, { bubbles: true }));
3700
+ return;
3701
+ }
3702
+ byHover.current = false;
3703
+ clear();
3704
+ }, [open]);
3705
+ A2(() => clear, []);
3706
+ return {
3707
+ onPointerEnter: (e3) => {
3708
+ if (e3.pointerType !== "mouse") return;
3709
+ clear();
3710
+ if (open) return;
3711
+ timer.current = setTimeout(() => {
3712
+ byHover.current = true;
3713
+ onOpen(true);
3714
+ }, OPEN_MS);
3715
+ },
3716
+ onPointerLeave: (e3) => {
3717
+ if (e3.pointerType !== "mouse") return;
3718
+ clear();
3719
+ if (!open || !byHover.current) return;
3720
+ timer.current = setTimeout(() => onOpen(false), CLOSE_MS);
3721
+ },
3722
+ /** The corner button: opens or closes the list — or, when hovering opened it, keeps it open until a click outside. */
3723
+ toggle: () => {
3724
+ clear();
3725
+ if (open && byHover.current) {
3726
+ byHover.current = false;
3727
+ return;
3728
+ }
3729
+ onOpen(!open);
3730
+ }
3731
+ };
3732
+ }
3733
+
3734
+ // src/components/keep-in-view.ts
3735
+ var MARGIN2 = 8;
3736
+ function useKeepInView(open) {
3737
+ const ref = T2(null);
3738
+ F2(() => {
3739
+ const el = ref.current;
3740
+ if (!open || !el) return;
3741
+ el.style.translate = "";
3742
+ const fit2 = () => {
3743
+ el.style.translate = "";
3744
+ el.style.maxHeight = "";
3745
+ const r3 = el.getBoundingClientRect();
3746
+ const root = el.closest(".fnc-root")?.getBoundingClientRect();
3747
+ const maxY = Math.min(document.documentElement.clientHeight, root?.bottom ?? Infinity) - MARGIN2;
3748
+ if (r3.bottom > maxY) {
3749
+ el.style.maxHeight = `${Math.max(120, Math.floor(maxY - r3.top))}px`;
3750
+ el.style.overflowY = "auto";
3751
+ }
3752
+ const minX = Math.max(0, root?.left ?? 0) + MARGIN2;
3753
+ const maxX = Math.min(document.documentElement.clientWidth, root?.right ?? Infinity) - MARGIN2;
3754
+ let dx = 0;
3755
+ if (r3.right > maxX) dx = maxX - r3.right;
3756
+ if (r3.left + dx < minX) dx = minX - r3.left;
3757
+ if (dx) el.style.translate = `${Math.round(dx)}px 0`;
3758
+ };
3759
+ fit2();
3760
+ window.addEventListener("resize", fit2);
3761
+ return () => window.removeEventListener("resize", fit2);
3762
+ }, [open]);
3763
+ return ref;
3764
+ }
3765
+ function useBesideAnchor(open, anchor) {
3766
+ const ref = T2(null);
3767
+ F2(() => {
3768
+ const el = ref.current;
3769
+ const a4 = anchor.current;
3770
+ if (!open || !el || !a4) return;
3771
+ const place = () => {
3772
+ const r3 = a4.getBoundingClientRect();
3773
+ el.style.position = "fixed";
3774
+ el.style.left = "0px";
3775
+ el.style.top = "0px";
3776
+ const origin = el.getBoundingClientRect();
3777
+ const vh = document.documentElement.clientHeight;
3778
+ const top = Math.max(MARGIN2, Math.min(r3.top, vh - MARGIN2 - el.offsetHeight));
3779
+ el.style.left = `${Math.round(r3.right + 8 - origin.left)}px`;
3780
+ el.style.top = `${Math.round(top - origin.top)}px`;
3781
+ };
3782
+ place();
3783
+ const bar = a4.closest(".fnc-drawbar");
3784
+ window.addEventListener("resize", place);
3785
+ bar?.addEventListener("scroll", place);
3786
+ return () => {
3787
+ window.removeEventListener("resize", place);
3788
+ bar?.removeEventListener("scroll", place);
3789
+ };
3790
+ }, [open]);
3791
+ return ref;
3792
+ }
3793
+
3760
3794
  // src/icons.tsx
3761
3795
  function Icon({ children, size = 20 }) {
3762
3796
  return /* @__PURE__ */ a3(
@@ -4566,7 +4600,6 @@ function SelectionBar({ ctx }) {
4566
4600
  const d3 = s3.selection;
4567
4601
  const [offset, setOffset] = d2(() => readJson(POS_KEY, [0, 0]));
4568
4602
  const [lift, setLift] = d2(() => readJson(LIFT_KEY, 0));
4569
- const [recent, setRecent] = d2(() => recentColors().slice(0, 3));
4570
4603
  const [menu, setMenu] = d2(null);
4571
4604
  const [sheet, setSheet] = d2(false);
4572
4605
  const [templates, setTemplates] = d2(() => readJson(TEMPLATES_KEY, {}));
@@ -4983,26 +5016,7 @@ function SelectionBar({ ctx }) {
4983
5016
  children: /* @__PURE__ */ a3(GripIcon, {})
4984
5017
  }
4985
5018
  ),
4986
- phone && !def?.levels && !def?.plain && /* @__PURE__ */ a3("div", { class: "fnc-selbar-menu", children: [
4987
- /* @__PURE__ */ a3("button", { class: "fnc-btn fnc-selbar-brush", "aria-label": t3.color, "aria-expanded": menu === "brush", onClick: () => setMenu(menu === "brush" ? null : "brush"), children: /* @__PURE__ */ a3(BrushIcon, { color: current }) }),
4988
- menu === "brush" && /* @__PURE__ */ a3("div", { class: "fnc-menu fnc-selbar-pop fnc-brush-pop", role: "menu", children: [
4989
- [...SWATCHES, ...recent.filter((c3) => !SWATCHES.includes(c3))].map((color) => /* @__PURE__ */ a3("button", { class: "fnc-swatch", style: { background: color }, "aria-label": `${t3.color} ${color}`, "aria-pressed": current === color, onClick: () => pickColor(color) })),
4990
- /* @__PURE__ */ a3(
4991
- ColorPicker,
4992
- {
4993
- class: "fnc-swatch fnc-swatch-add",
4994
- value: current,
4995
- label: t3.palette,
4996
- t: t3,
4997
- onPick: (color) => {
4998
- pickColor(color);
4999
- setRecent(recentColors().slice(0, 3));
5000
- },
5001
- children: /* @__PURE__ */ a3("svg", { width: "10", height: "10", viewBox: "0 0 10 10", "aria-hidden": "true", children: /* @__PURE__ */ a3("path", { d: "M5 1.5v7M1.5 5h7", stroke: "currentColor", "stroke-width": "1.5", "stroke-linecap": "round" }) })
5002
- }
5003
- )
5004
- ] })
5005
- ] }),
5019
+ !def?.levels && !def?.plain && /* @__PURE__ */ a3(ColorPicker, { class: "fnc-btn fnc-selbar-brush", boardClass: "fnc-palette-big", value: current, label: t3.color, tip: t3.color, t: t3, onPick: pickColor, onOpen: () => setMenu(null), children: /* @__PURE__ */ a3(BrushIcon, { color: current }) }),
5006
5020
  phone && def && (def.text || !def.plain) && /* @__PURE__ */ a3("div", { class: "fnc-selbar-menu", children: [
5007
5021
  /* @__PURE__ */ a3(
5008
5022
  "button",
@@ -5063,22 +5077,6 @@ function SelectionBar({ ctx }) {
5063
5077
  }
5064
5078
  ),
5065
5079
  !phone && /* @__PURE__ */ a3($, { children: [
5066
- !def?.levels && !def?.plain && [...SWATCHES, ...recent.filter((c3) => !SWATCHES.includes(c3))].map((color) => /* @__PURE__ */ a3("button", { class: "fnc-swatch", style: { background: color }, "data-tip": t3.color, "aria-label": `${t3.color} ${color}`, "aria-pressed": current === color, onClick: () => pickColor(color) })),
5067
- !def?.levels && !def?.plain && /* @__PURE__ */ a3(
5068
- ColorPicker,
5069
- {
5070
- class: "fnc-swatch fnc-swatch-add",
5071
- value: current,
5072
- label: t3.palette,
5073
- tip: t3.palette,
5074
- t: t3,
5075
- onPick: (color) => {
5076
- pickColor(color);
5077
- setRecent(recentColors().slice(0, 3));
5078
- },
5079
- children: /* @__PURE__ */ a3("svg", { width: "10", height: "10", viewBox: "0 0 10 10", "aria-hidden": "true", children: /* @__PURE__ */ a3("path", { d: "M5 1.5v7M1.5 5h7", stroke: "currentColor", "stroke-width": "1.5", "stroke-linecap": "round" }) })
5080
- }
5081
- ),
5082
5080
  slots.length > 0 && /* @__PURE__ */ a3("div", { class: "fnc-selbar-menu", children: [
5083
5081
  /* @__PURE__ */ a3("button", { class: "fnc-btn", "data-tip": t3.partColors, "aria-label": t3.partColors, "aria-expanded": menu === "colors", onClick: () => setMenu(menu === "colors" ? null : "colors"), children: /* @__PURE__ */ a3(PaletteIcon, {}) }),
5084
5082
  menu === "colors" && /* @__PURE__ */ a3("div", { class: "fnc-menu fnc-selbar-pop fnc-part-menu", role: "menu", children: colorsBody() })
@@ -5260,10 +5258,7 @@ function SelectionBar({ ctx }) {
5260
5258
  value: current,
5261
5259
  label: t3.color,
5262
5260
  t: t3,
5263
- onPick: (color) => {
5264
- pickColor(color);
5265
- setRecent(recentColors().slice(0, 3));
5266
- }
5261
+ onPick: pickColor
5267
5262
  }
5268
5263
  )
5269
5264
  ] }),
@@ -5312,10 +5307,12 @@ function SelectionBar({ ctx }) {
5312
5307
  ] });
5313
5308
  }
5314
5309
  function BrushIcon({ color }) {
5315
- return /* @__PURE__ */ a3("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", "stroke-width": "1.5", "stroke-linecap": "round", "stroke-linejoin": "round", "aria-hidden": "true", children: [
5316
- /* @__PURE__ */ a3("path", { d: "M13.5 3.5 16.5 6.5 9 14 6 11Z" }),
5317
- /* @__PURE__ */ a3("path", { d: "M6 11 4.5 12.5c-.8.8-.9 2-1 3 1 0 2.2-.2 3-1L8 13" }),
5318
- /* @__PURE__ */ a3("rect", { x: "3", y: "17", width: "14", height: "2.2", rx: "1.1", fill: color, stroke: "none" })
5310
+ return /* @__PURE__ */ a3("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", "stroke-width": "1.6", "stroke-linecap": "round", "stroke-linejoin": "round", "aria-hidden": "true", children: [
5311
+ /* @__PURE__ */ a3("path", { d: "M11.4 6.8 15 3.2a1.2 1.2 0 0 1 1.7 1.7L13.1 8.5" }),
5312
+ /* @__PURE__ */ a3("path", { d: "M10.4 7.5 12.4 9.5" }),
5313
+ /* @__PURE__ */ a3("path", { d: "M10.4 7.5C7.8 7.3 5.6 8.6 4.9 11c-.4 1.3-.5 2.4-1.1 3.4 1.2.1 2.6 0 4-.5 3.1-1 4.6-3 4.6-4.4Z" }),
5314
+ /* @__PURE__ */ a3("path", { d: "M8.3 9.9 6.4 12.6" }),
5315
+ /* @__PURE__ */ a3("rect", { x: "4.2", y: "15.4", width: "11.6", height: "2", rx: "1", fill: color, stroke: "none" })
5319
5316
  ] });
5320
5317
  }
5321
5318
  function StyleSheet({ ctx, title, resetLabel, onReset, onClose, children }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnest/charts-ui",
3
- "version": "0.11.64",
3
+ "version": "0.11.65",
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.11.64"
45
+ "@funnest/charts": "0.11.65"
46
46
  },
47
47
  "devDependencies": {
48
48
  "preact": "^11.2.0"