@funnest/charts-ui 0.11.35 → 0.11.37
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/components/color-picker.d.ts +23 -0
- package/dist/components/hover-open.d.ts +16 -0
- package/dist/context.d.ts +7 -1
- package/dist/i18n.d.ts +18 -0
- package/dist/icons.d.ts +1 -0
- package/dist/index.js +452 -130
- package/dist/shell.d.ts +12 -5
- package/package.json +2 -2
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** @jsxImportSource preact */
|
|
2
|
+
import type { ComponentChildren } from 'preact';
|
|
3
|
+
import type { Strings } from '../i18n.js';
|
|
4
|
+
/** Rows of the board: grays, three lighter rows, the hues, two darker rows. */
|
|
5
|
+
export declare const PALETTE: readonly (readonly string[])[];
|
|
6
|
+
export declare function recentColors(): string[];
|
|
7
|
+
/** A color picked with the browser's picker: first among the recent ones (shared by every field). */
|
|
8
|
+
export declare function rememberColor(color: string): string[];
|
|
9
|
+
/**
|
|
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.
|
|
12
|
+
*/
|
|
13
|
+
export declare function ColorPicker({ value, label, t, onPick, class: cls, style, tip, children, }: {
|
|
14
|
+
/** #rrggbb (anything else: nothing marked). */
|
|
15
|
+
value: string;
|
|
16
|
+
label: string;
|
|
17
|
+
t: Pick<Strings, 'paletteCustom' | 'paletteRecent'>;
|
|
18
|
+
onPick(color: string): void;
|
|
19
|
+
class?: string;
|
|
20
|
+
style?: Record<string, string>;
|
|
21
|
+
tip?: string;
|
|
22
|
+
children?: ComponentChildren;
|
|
23
|
+
}): import("preact").JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Asks the widget's tooltip to hide (shell.ts bindTooltips listens for it). */
|
|
2
|
+
export declare const HIDE_TIP = "fnc-hide-tip";
|
|
3
|
+
/**
|
|
4
|
+
* The drawing bar's tool lists open when a mouse rests on the group (the corner button still opens
|
|
5
|
+
* them with a click, and touch only by tapping). One opened this way closes when the pointer has
|
|
6
|
+
* left the group and its list for a moment; one opened with a click stays until a click outside.
|
|
7
|
+
* Spread the returned handlers on the group's element (its list is inside it).
|
|
8
|
+
*/
|
|
9
|
+
export declare function useHoverOpen(open: boolean, onOpen: (open: boolean) => void, group?: {
|
|
10
|
+
current: HTMLElement | null;
|
|
11
|
+
}): {
|
|
12
|
+
onPointerEnter: (e: PointerEvent) => void;
|
|
13
|
+
onPointerLeave: (e: PointerEvent) => void;
|
|
14
|
+
/** The corner button: opens or closes the list — or, when hovering opened it, keeps it open until a click outside. */
|
|
15
|
+
toggle: () => void;
|
|
16
|
+
};
|
package/dist/context.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Chart, ChartContextMenu, ChartLayout, ChartSettings, ChartType, CompareInfo, CursorMode, Datafeed, Drawing, DrawingType, IndicatorConfig, LegendItem, Locale, ReplayStatus, Resolution, SymbolInfo } from '@funnest/charts';
|
|
1
|
+
import type { Chart, ChartContextMenu, ChartLayout, ChartSettings, ChartType, CompareInfo, CursorMode, Datafeed, Drawing, DrawingType, IndicatorConfig, MagnetMode, LegendItem, Locale, ReplayStatus, Resolution, SymbolInfo } from '@funnest/charts';
|
|
2
2
|
import type { LayoutId } from './layouts.js';
|
|
3
3
|
import type { WidgetStorage } from './storage.js';
|
|
4
4
|
import type { Strings } from './i18n.js';
|
|
@@ -24,7 +24,11 @@ export interface UiState {
|
|
|
24
24
|
drawingsLocked: boolean;
|
|
25
25
|
/** Narrow screens: the drawing bar is hidden until toggled from the toolbar. */
|
|
26
26
|
drawbarOpen: boolean;
|
|
27
|
+
/** 자석 on (weak or strong). */
|
|
27
28
|
magnet: boolean;
|
|
29
|
+
magnetMode: MagnetMode;
|
|
30
|
+
/** The strength the magnet button turns on with. */
|
|
31
|
+
magnetStrength: 'weak' | 'strong';
|
|
28
32
|
indicators: IndicatorConfig[];
|
|
29
33
|
/** Open dialog: indicator picker, or settings for one indicator id. */
|
|
30
34
|
dialog: {
|
|
@@ -216,6 +220,8 @@ export interface WidgetContext {
|
|
|
216
220
|
toggleFavoriteTool(tool: DrawingType): void;
|
|
217
221
|
setKeepDrawing(on: boolean): void;
|
|
218
222
|
setCursorMode(mode: CursorMode): void;
|
|
223
|
+
/** 자석 (every pane; kept). */
|
|
224
|
+
setMagnetMode(mode: MagnetMode): void;
|
|
219
225
|
/** Hides or shows the drawings of every pane. */
|
|
220
226
|
setDrawingsHidden(hidden: boolean): void;
|
|
221
227
|
setSearchOpen(open: boolean, target?: 'symbol' | 'compare'): void;
|
package/dist/i18n.d.ts
CHANGED
|
@@ -168,6 +168,15 @@ export declare const STRINGS: {
|
|
|
168
168
|
done: string;
|
|
169
169
|
expandDrawbar: string;
|
|
170
170
|
magnet: string;
|
|
171
|
+
magnetModes: string;
|
|
172
|
+
magnetWeak: string;
|
|
173
|
+
magnetWeakSub: string;
|
|
174
|
+
magnetStrong: string;
|
|
175
|
+
magnetStrongSub: string;
|
|
176
|
+
palette: string;
|
|
177
|
+
paletteCustom: string;
|
|
178
|
+
paletteRecent: string;
|
|
179
|
+
resetDrawingLook: string;
|
|
171
180
|
remove: string;
|
|
172
181
|
color: string;
|
|
173
182
|
customColor: string;
|
|
@@ -530,6 +539,15 @@ export declare const STRINGS: {
|
|
|
530
539
|
done: string;
|
|
531
540
|
expandDrawbar: string;
|
|
532
541
|
magnet: string;
|
|
542
|
+
magnetModes: string;
|
|
543
|
+
magnetWeak: string;
|
|
544
|
+
magnetWeakSub: string;
|
|
545
|
+
magnetStrong: string;
|
|
546
|
+
magnetStrongSub: string;
|
|
547
|
+
palette: string;
|
|
548
|
+
paletteCustom: string;
|
|
549
|
+
paletteRecent: string;
|
|
550
|
+
resetDrawingLook: string;
|
|
533
551
|
remove: string;
|
|
534
552
|
color: string;
|
|
535
553
|
customColor: string;
|
package/dist/icons.d.ts
CHANGED
|
@@ -45,6 +45,7 @@ export declare const SmallCloseIcon: () => import("preact").JSX.Element;
|
|
|
45
45
|
export declare const EyeIcon: () => import("preact").JSX.Element;
|
|
46
46
|
export declare const EyeOffIcon: () => import("preact").JSX.Element;
|
|
47
47
|
export declare const ChevronUpIcon: () => import("preact").JSX.Element;
|
|
48
|
+
/** A sturdy horseshoe: wide arms, the poles filled in (a thin U read as faint next to the other tools). */
|
|
48
49
|
export declare const MagnetIcon: () => import("preact").JSX.Element;
|
|
49
50
|
export declare const StarIcon: ({ filled }: {
|
|
50
51
|
filled?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -603,6 +603,15 @@ var STRINGS = {
|
|
|
603
603
|
done: "\uC644\uB8CC",
|
|
604
604
|
expandDrawbar: "\uADF8\uB9AC\uAE30 \uB3C4\uAD6C \uD3BC\uCE58\uAE30",
|
|
605
605
|
magnet: "\uC790\uC11D \uBAA8\uB4DC (\uC2DC\xB7\uACE0\xB7\uC800\xB7\uC885\uAC00\uC5D0 \uBD99\uC774\uAE30)",
|
|
606
|
+
magnetModes: "\uC790\uC11D \uC138\uAE30",
|
|
607
|
+
magnetWeak: "\uC57D\uD55C \uC790\uC11D",
|
|
608
|
+
magnetWeakSub: "\uC2DC\xB7\uACE0\xB7\uC800\xB7\uC885\uAC00 \uAC00\uAE4C\uC774 \uAC14\uC744 \uB54C\uB9CC \uBD99\uC5B4\uC694",
|
|
609
|
+
magnetStrong: "\uAC15\uD55C \uC790\uC11D",
|
|
610
|
+
magnetStrongSub: "\uD56D\uC0C1 \uAC00\uC7A5 \uAC00\uAE4C\uC6B4 \uC2DC\xB7\uACE0\xB7\uC800\xB7\uC885\uAC00\uC5D0 \uBD99\uC5B4\uC694",
|
|
611
|
+
palette: "\uC0C9 \uACE0\uB974\uAE30",
|
|
612
|
+
paletteCustom: "\uC9C1\uC811 \uACE0\uB974\uAE30",
|
|
613
|
+
paletteRecent: "\uCD5C\uADFC\uC5D0 \uC4F4 \uC0C9",
|
|
614
|
+
resetDrawingLook: "\uAE30\uBCF8 \uBAA8\uC591\uC73C\uB85C \uB418\uB3CC\uB9AC\uAE30",
|
|
606
615
|
remove: "\uC0AD\uC81C",
|
|
607
616
|
color: "\uC0C9\uC0C1",
|
|
608
617
|
customColor: "\uB2E4\uB978 \uC0C9",
|
|
@@ -967,6 +976,15 @@ var STRINGS = {
|
|
|
967
976
|
done: "Done",
|
|
968
977
|
expandDrawbar: "Show drawing tools",
|
|
969
978
|
magnet: "Magnet (snap to OHLC)",
|
|
979
|
+
magnetModes: "Magnet strength",
|
|
980
|
+
magnetWeak: "Weak magnet",
|
|
981
|
+
magnetWeakSub: "Snaps only near an open, high, low or close",
|
|
982
|
+
magnetStrong: "Strong magnet",
|
|
983
|
+
magnetStrongSub: "Always snaps to the nearest open, high, low or close",
|
|
984
|
+
palette: "Pick a color",
|
|
985
|
+
paletteCustom: "Custom\u2026",
|
|
986
|
+
paletteRecent: "Recent",
|
|
987
|
+
resetDrawingLook: "Back to the default look",
|
|
970
988
|
remove: "Remove",
|
|
971
989
|
color: "Color",
|
|
972
990
|
customColor: "Other color",
|
|
@@ -1249,8 +1267,200 @@ function IntervalVisibilityEditor({ t: t3, value, onChange }) {
|
|
|
1249
1267
|
}) });
|
|
1250
1268
|
}
|
|
1251
1269
|
|
|
1252
|
-
// src/components/
|
|
1270
|
+
// src/components/color-picker.tsx
|
|
1271
|
+
var GRAYS = ["#FFFFFF", "#F2F4F6", "#D1D6DB", "#B0B8C1", "#8B95A1", "#6B7684", "#4E5968", "#333D4B", "#191F28", "#000000"];
|
|
1272
|
+
var HUES = ["#F04452", "#FF9F0A", "#FFD43B", "#94D82D", "#12B886", "#15AABF", "#3182F6", "#4C6EF5", "#7048E8", "#E64980"];
|
|
1273
|
+
var hex = (n2) => Math.round(Math.max(0, Math.min(255, n2))).toString(16).padStart(2, "0");
|
|
1274
|
+
function mix(color, t3) {
|
|
1275
|
+
const v3 = [1, 3, 5].map((i3) => parseInt(color.slice(i3, i3 + 2), 16));
|
|
1276
|
+
const to = t3 > 0 ? 255 : 0;
|
|
1277
|
+
const k2 = Math.abs(t3);
|
|
1278
|
+
return `#${v3.map((c3) => hex(c3 + (to - c3) * k2)).join("")}`.toUpperCase();
|
|
1279
|
+
}
|
|
1280
|
+
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)))];
|
|
1281
|
+
var RECENT_KEY = "fnc-drawing-colors";
|
|
1282
|
+
var RECENT_MAX = 10;
|
|
1283
|
+
function recentColors() {
|
|
1284
|
+
try {
|
|
1285
|
+
const list = JSON.parse(localStorage.getItem(RECENT_KEY) ?? "[]");
|
|
1286
|
+
return Array.isArray(list) ? list.filter((c3) => typeof c3 === "string" && /^#[0-9a-f]{6}$/i.test(c3)).slice(0, RECENT_MAX) : [];
|
|
1287
|
+
} catch {
|
|
1288
|
+
return [];
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
function rememberColor(color) {
|
|
1292
|
+
const next = [color, ...recentColors().filter((c3) => c3.toLowerCase() !== color.toLowerCase())].slice(0, RECENT_MAX);
|
|
1293
|
+
try {
|
|
1294
|
+
localStorage.setItem(RECENT_KEY, JSON.stringify(next));
|
|
1295
|
+
} catch {
|
|
1296
|
+
}
|
|
1297
|
+
return next;
|
|
1298
|
+
}
|
|
1253
1299
|
var MARGIN = 8;
|
|
1300
|
+
var same = (a4, b) => a4.slice(0, 7).toLowerCase() === b.slice(0, 7).toLowerCase();
|
|
1301
|
+
function ColorPicker({
|
|
1302
|
+
value,
|
|
1303
|
+
label,
|
|
1304
|
+
t: t3,
|
|
1305
|
+
onPick,
|
|
1306
|
+
class: cls,
|
|
1307
|
+
style,
|
|
1308
|
+
tip,
|
|
1309
|
+
children
|
|
1310
|
+
}) {
|
|
1311
|
+
const [open, setOpen] = d2(false);
|
|
1312
|
+
const [recent, setRecent] = d2([]);
|
|
1313
|
+
const wrap = T2(null);
|
|
1314
|
+
const button = T2(null);
|
|
1315
|
+
const pop = T2(null);
|
|
1316
|
+
A2(() => {
|
|
1317
|
+
if (!open) return;
|
|
1318
|
+
setRecent(recentColors());
|
|
1319
|
+
const close = (e3) => !wrap.current?.contains(e3.target) && setOpen(false);
|
|
1320
|
+
const esc = (e3) => {
|
|
1321
|
+
if (e3.key !== "Escape") return;
|
|
1322
|
+
e3.stopPropagation();
|
|
1323
|
+
setOpen(false);
|
|
1324
|
+
button.current?.focus();
|
|
1325
|
+
};
|
|
1326
|
+
document.addEventListener("pointerdown", close, true);
|
|
1327
|
+
document.addEventListener("keydown", esc, true);
|
|
1328
|
+
return () => {
|
|
1329
|
+
document.removeEventListener("pointerdown", close, true);
|
|
1330
|
+
document.removeEventListener("keydown", esc, true);
|
|
1331
|
+
};
|
|
1332
|
+
}, [open]);
|
|
1333
|
+
F2(() => {
|
|
1334
|
+
const el = pop.current;
|
|
1335
|
+
const a4 = button.current;
|
|
1336
|
+
if (!open || !el || !a4) return;
|
|
1337
|
+
const place = () => {
|
|
1338
|
+
const r3 = a4.getBoundingClientRect();
|
|
1339
|
+
el.style.left = "0px";
|
|
1340
|
+
el.style.top = "0px";
|
|
1341
|
+
const origin = el.getBoundingClientRect();
|
|
1342
|
+
const vw = document.documentElement.clientWidth;
|
|
1343
|
+
const vh = document.documentElement.clientHeight;
|
|
1344
|
+
const below = r3.bottom + 6;
|
|
1345
|
+
const top = below + el.offsetHeight + MARGIN <= vh ? below : Math.max(MARGIN, r3.top - 6 - el.offsetHeight);
|
|
1346
|
+
const left = Math.max(MARGIN, Math.min(vw - MARGIN - el.offsetWidth, r3.left));
|
|
1347
|
+
el.style.left = `${Math.round(left - origin.left)}px`;
|
|
1348
|
+
el.style.top = `${Math.round(top - origin.top)}px`;
|
|
1349
|
+
};
|
|
1350
|
+
place();
|
|
1351
|
+
window.addEventListener("resize", place);
|
|
1352
|
+
window.addEventListener("scroll", place, true);
|
|
1353
|
+
return () => {
|
|
1354
|
+
window.removeEventListener("resize", place);
|
|
1355
|
+
window.removeEventListener("scroll", place, true);
|
|
1356
|
+
};
|
|
1357
|
+
}, [open]);
|
|
1358
|
+
const pick = (color) => {
|
|
1359
|
+
onPick(color);
|
|
1360
|
+
setOpen(false);
|
|
1361
|
+
};
|
|
1362
|
+
const swatch = (color) => /* @__PURE__ */ a3(
|
|
1363
|
+
"button",
|
|
1364
|
+
{
|
|
1365
|
+
type: "button",
|
|
1366
|
+
class: "fnc-palette-cell",
|
|
1367
|
+
role: "option",
|
|
1368
|
+
style: { background: color },
|
|
1369
|
+
"aria-label": color,
|
|
1370
|
+
"aria-selected": same(color, value),
|
|
1371
|
+
onClick: () => pick(color)
|
|
1372
|
+
},
|
|
1373
|
+
color
|
|
1374
|
+
);
|
|
1375
|
+
return /* @__PURE__ */ a3("span", { class: "fnc-palette-wrap", ref: wrap, children: [
|
|
1376
|
+
/* @__PURE__ */ a3(
|
|
1377
|
+
"button",
|
|
1378
|
+
{
|
|
1379
|
+
type: "button",
|
|
1380
|
+
ref: button,
|
|
1381
|
+
class: cls,
|
|
1382
|
+
style,
|
|
1383
|
+
"data-tip": tip,
|
|
1384
|
+
"aria-label": label,
|
|
1385
|
+
"aria-haspopup": "listbox",
|
|
1386
|
+
"aria-expanded": open,
|
|
1387
|
+
onClick: () => setOpen(!open),
|
|
1388
|
+
children
|
|
1389
|
+
}
|
|
1390
|
+
),
|
|
1391
|
+
open && /* @__PURE__ */ a3("div", { class: "fnc-palette", ref: pop, role: "dialog", "aria-label": label, onKeyDown: (e3) => e3.key !== "Escape" && e3.stopPropagation(), children: [
|
|
1392
|
+
/* @__PURE__ */ a3("div", { class: "fnc-palette-grid", role: "listbox", "aria-label": label, children: PALETTE.map((row2) => row2.map(swatch)) }),
|
|
1393
|
+
recent.length > 0 && /* @__PURE__ */ a3($, { children: [
|
|
1394
|
+
/* @__PURE__ */ a3("div", { class: "fnc-palette-title", children: t3.paletteRecent }),
|
|
1395
|
+
/* @__PURE__ */ a3("div", { class: "fnc-palette-grid", role: "listbox", "aria-label": t3.paletteRecent, children: recent.map(swatch) })
|
|
1396
|
+
] }),
|
|
1397
|
+
/* @__PURE__ */ a3("label", { class: "fnc-palette-custom", children: [
|
|
1398
|
+
/* @__PURE__ */ a3("span", { class: "fnc-palette-custom-chip", style: { background: /^#[0-9a-f]{6}/i.test(value) ? value.slice(0, 7) : "#3182F6" } }),
|
|
1399
|
+
/* @__PURE__ */ a3("span", { children: t3.paletteCustom }),
|
|
1400
|
+
/* @__PURE__ */ a3(
|
|
1401
|
+
"input",
|
|
1402
|
+
{
|
|
1403
|
+
type: "color",
|
|
1404
|
+
value: /^#[0-9a-f]{6}/i.test(value) ? value.slice(0, 7) : "#3182f6",
|
|
1405
|
+
onInput: (e3) => onPick(e3.target.value),
|
|
1406
|
+
onChange: (e3) => setRecent(rememberColor(e3.target.value))
|
|
1407
|
+
}
|
|
1408
|
+
)
|
|
1409
|
+
] })
|
|
1410
|
+
] })
|
|
1411
|
+
] });
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
// src/components/hover-open.ts
|
|
1415
|
+
var HIDE_TIP = "fnc-hide-tip";
|
|
1416
|
+
var OPEN_MS = 140;
|
|
1417
|
+
var CLOSE_MS = 260;
|
|
1418
|
+
function useHoverOpen(open, onOpen, group) {
|
|
1419
|
+
const timer = T2(null);
|
|
1420
|
+
const byHover = T2(false);
|
|
1421
|
+
const clear = () => {
|
|
1422
|
+
if (timer.current) clearTimeout(timer.current);
|
|
1423
|
+
timer.current = null;
|
|
1424
|
+
};
|
|
1425
|
+
A2(() => {
|
|
1426
|
+
if (open) {
|
|
1427
|
+
group?.current?.dispatchEvent(new CustomEvent(HIDE_TIP, { bubbles: true }));
|
|
1428
|
+
return;
|
|
1429
|
+
}
|
|
1430
|
+
byHover.current = false;
|
|
1431
|
+
clear();
|
|
1432
|
+
}, [open]);
|
|
1433
|
+
A2(() => clear, []);
|
|
1434
|
+
return {
|
|
1435
|
+
onPointerEnter: (e3) => {
|
|
1436
|
+
if (e3.pointerType !== "mouse") return;
|
|
1437
|
+
clear();
|
|
1438
|
+
if (open) return;
|
|
1439
|
+
timer.current = setTimeout(() => {
|
|
1440
|
+
byHover.current = true;
|
|
1441
|
+
onOpen(true);
|
|
1442
|
+
}, OPEN_MS);
|
|
1443
|
+
},
|
|
1444
|
+
onPointerLeave: (e3) => {
|
|
1445
|
+
if (e3.pointerType !== "mouse") return;
|
|
1446
|
+
clear();
|
|
1447
|
+
if (!open || !byHover.current) return;
|
|
1448
|
+
timer.current = setTimeout(() => onOpen(false), CLOSE_MS);
|
|
1449
|
+
},
|
|
1450
|
+
/** The corner button: opens or closes the list — or, when hovering opened it, keeps it open until a click outside. */
|
|
1451
|
+
toggle: () => {
|
|
1452
|
+
clear();
|
|
1453
|
+
if (open && byHover.current) {
|
|
1454
|
+
byHover.current = false;
|
|
1455
|
+
return;
|
|
1456
|
+
}
|
|
1457
|
+
onOpen(!open);
|
|
1458
|
+
}
|
|
1459
|
+
};
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
// src/components/keep-in-view.ts
|
|
1463
|
+
var MARGIN2 = 8;
|
|
1254
1464
|
function useKeepInView(open) {
|
|
1255
1465
|
const ref = T2(null);
|
|
1256
1466
|
F2(() => {
|
|
@@ -1262,13 +1472,13 @@ function useKeepInView(open) {
|
|
|
1262
1472
|
el.style.maxHeight = "";
|
|
1263
1473
|
const r3 = el.getBoundingClientRect();
|
|
1264
1474
|
const root = el.closest(".fnc-root")?.getBoundingClientRect();
|
|
1265
|
-
const maxY = Math.min(document.documentElement.clientHeight, root?.bottom ?? Infinity) -
|
|
1475
|
+
const maxY = Math.min(document.documentElement.clientHeight, root?.bottom ?? Infinity) - MARGIN2;
|
|
1266
1476
|
if (r3.bottom > maxY) {
|
|
1267
1477
|
el.style.maxHeight = `${Math.max(120, Math.floor(maxY - r3.top))}px`;
|
|
1268
1478
|
el.style.overflowY = "auto";
|
|
1269
1479
|
}
|
|
1270
|
-
const minX = Math.max(0, root?.left ?? 0) +
|
|
1271
|
-
const maxX = Math.min(document.documentElement.clientWidth, root?.right ?? Infinity) -
|
|
1480
|
+
const minX = Math.max(0, root?.left ?? 0) + MARGIN2;
|
|
1481
|
+
const maxX = Math.min(document.documentElement.clientWidth, root?.right ?? Infinity) - MARGIN2;
|
|
1272
1482
|
let dx = 0;
|
|
1273
1483
|
if (r3.right > maxX) dx = maxX - r3.right;
|
|
1274
1484
|
if (r3.left + dx < minX) dx = minX - r3.left;
|
|
@@ -1293,7 +1503,7 @@ function useBesideAnchor(open, anchor) {
|
|
|
1293
1503
|
el.style.top = "0px";
|
|
1294
1504
|
const origin = el.getBoundingClientRect();
|
|
1295
1505
|
const vh = document.documentElement.clientHeight;
|
|
1296
|
-
const top = Math.max(
|
|
1506
|
+
const top = Math.max(MARGIN2, Math.min(r3.top, vh - MARGIN2 - el.offsetHeight));
|
|
1297
1507
|
el.style.left = `${Math.round(r3.right + 8 - origin.left)}px`;
|
|
1298
1508
|
el.style.top = `${Math.round(top - origin.top)}px`;
|
|
1299
1509
|
};
|
|
@@ -1454,8 +1664,8 @@ var EyeIcon = () => /* @__PURE__ */ a3(Icon, { size: 14, children: [
|
|
|
1454
1664
|
var EyeOffIcon = () => /* @__PURE__ */ a3(Icon, { size: 14, children: /* @__PURE__ */ a3("path", { d: "M3 3l14 14M8.2 5a8 8 0 0 1 1.8-.5c5 0 8 5.5 8 5.5a14 14 0 0 1-2.2 2.9M5.4 6.4A14 14 0 0 0 2 10s3 5.5 8 5.5a7.7 7.7 0 0 0 3.6-.9" }) });
|
|
1455
1665
|
var ChevronUpIcon = () => /* @__PURE__ */ a3(Icon, { size: 14, children: /* @__PURE__ */ a3("path", { d: "M5 12l5-5 5 5" }) });
|
|
1456
1666
|
var MagnetIcon = () => /* @__PURE__ */ a3(Icon, { children: [
|
|
1457
|
-
/* @__PURE__ */ a3("path", { d: "
|
|
1458
|
-
/* @__PURE__ */ a3("path", { d: "
|
|
1667
|
+
/* @__PURE__ */ a3("path", { d: "M3 3h4.5v7a2.5 2.5 0 0 0 5 0V3H17v7a7 7 0 0 1-14 0z" }),
|
|
1668
|
+
/* @__PURE__ */ a3("path", { d: "M3 3h4.5v3.2H3zM12.5 3H17v3.2h-4.5z", fill: "currentColor" })
|
|
1459
1669
|
] });
|
|
1460
1670
|
var StarIcon = ({ filled = false }) => /* @__PURE__ */ a3(Icon, { size: 16, children: /* @__PURE__ */ a3(
|
|
1461
1671
|
"path",
|
|
@@ -1623,6 +1833,7 @@ function ToolGroup({
|
|
|
1623
1833
|
const name = current.name[s3.locale];
|
|
1624
1834
|
const ref = T2(null);
|
|
1625
1835
|
const menu = useBesideAnchor(open, ref);
|
|
1836
|
+
const hover = useHoverOpen(open, onOpen, ref);
|
|
1626
1837
|
A2(() => {
|
|
1627
1838
|
if (!open) return;
|
|
1628
1839
|
const close = (e3) => !ref.current?.contains(e3.target) && onOpen(false);
|
|
@@ -1639,9 +1850,9 @@ function ToolGroup({
|
|
|
1639
1850
|
onOpen(false);
|
|
1640
1851
|
onPick(def.type);
|
|
1641
1852
|
};
|
|
1642
|
-
return /* @__PURE__ */ a3("div", { class: "fnc-tool-group", ref, "data-open": open, children: [
|
|
1853
|
+
return /* @__PURE__ */ a3("div", { class: "fnc-tool-group", ref, "data-open": open, ...tools.length > 1 ? { onPointerEnter: hover.onPointerEnter, onPointerLeave: hover.onPointerLeave } : {}, children: [
|
|
1643
1854
|
/* @__PURE__ */ a3("button", { class: "fnc-btn", "data-tip": name, "aria-label": name, "aria-pressed": !!armed, onClick: () => pick(current), children: /* @__PURE__ */ a3(ToolIcon, { def: current, locale: s3.locale }) }),
|
|
1644
|
-
tools.length > 1 && /* @__PURE__ */ a3("button", { class: "fnc-tool-more", "aria-label": `${t3.moreTools}: ${name}`, "aria-haspopup": "menu", "aria-expanded": open, onClick:
|
|
1855
|
+
tools.length > 1 && /* @__PURE__ */ a3("button", { class: "fnc-tool-more", "aria-label": `${t3.moreTools}: ${name}`, "aria-haspopup": "menu", "aria-expanded": open, onClick: hover.toggle, children: [
|
|
1645
1856
|
/* @__PURE__ */ a3("span", { class: "fnc-tool-corner", children: /* @__PURE__ */ a3(CornerIcon, {}) }),
|
|
1646
1857
|
/* @__PURE__ */ a3("span", { class: "fnc-tool-chevron", children: /* @__PURE__ */ a3(ChevronRightIcon, {}) })
|
|
1647
1858
|
] }),
|
|
@@ -1689,6 +1900,7 @@ function CursorGroup({ ctx, open, onOpen, onPick }) {
|
|
|
1689
1900
|
const t3 = stringsOf(s3);
|
|
1690
1901
|
const ref = T2(null);
|
|
1691
1902
|
const menu = useBesideAnchor(open, ref);
|
|
1903
|
+
const hover = useHoverOpen(open, onOpen, ref);
|
|
1692
1904
|
const current = CURSORS.find((c3) => c3.mode === s3.cursorMode) ?? CURSORS[0];
|
|
1693
1905
|
A2(() => {
|
|
1694
1906
|
if (!open) return;
|
|
@@ -1702,9 +1914,9 @@ function CursorGroup({ ctx, open, onOpen, onPick }) {
|
|
|
1702
1914
|
};
|
|
1703
1915
|
}, [open]);
|
|
1704
1916
|
const name = `${t3.cursor}: ${t3[current.label]}`;
|
|
1705
|
-
return /* @__PURE__ */ a3("div", { class: "fnc-tool-group", ref, "data-open": open, children: [
|
|
1917
|
+
return /* @__PURE__ */ a3("div", { class: "fnc-tool-group", ref, "data-open": open, onPointerEnter: hover.onPointerEnter, onPointerLeave: hover.onPointerLeave, children: [
|
|
1706
1918
|
/* @__PURE__ */ a3("button", { class: "fnc-btn", "data-tip": name, "aria-label": name, "aria-pressed": s3.drawingTool === null, onClick: onPick, children: /* @__PURE__ */ a3(current.Icon, {}) }),
|
|
1707
|
-
/* @__PURE__ */ a3("button", { class: "fnc-tool-more", "aria-label": `${t3.cursorModes}: ${t3[current.label]}`, "aria-haspopup": "menu", "aria-expanded": open, onClick:
|
|
1919
|
+
/* @__PURE__ */ a3("button", { class: "fnc-tool-more", "aria-label": `${t3.cursorModes}: ${t3[current.label]}`, "aria-haspopup": "menu", "aria-expanded": open, onClick: hover.toggle, children: [
|
|
1708
1920
|
/* @__PURE__ */ a3("span", { class: "fnc-tool-corner", children: /* @__PURE__ */ a3(CornerIcon, {}) }),
|
|
1709
1921
|
/* @__PURE__ */ a3("span", { class: "fnc-tool-chevron", children: /* @__PURE__ */ a3(ChevronRightIcon, {}) })
|
|
1710
1922
|
] }),
|
|
@@ -1731,6 +1943,60 @@ function CursorGroup({ ctx, open, onOpen, onPick }) {
|
|
|
1731
1943
|
] })
|
|
1732
1944
|
] });
|
|
1733
1945
|
}
|
|
1946
|
+
function MagnetGroup({ ctx, open, onOpen }) {
|
|
1947
|
+
const s3 = useStore(ctx.store);
|
|
1948
|
+
const t3 = stringsOf(s3);
|
|
1949
|
+
const ref = T2(null);
|
|
1950
|
+
const menu = useBesideAnchor(open, ref);
|
|
1951
|
+
const hover = useHoverOpen(open, onOpen, ref);
|
|
1952
|
+
A2(() => {
|
|
1953
|
+
if (!open) return;
|
|
1954
|
+
const close = (e3) => !ref.current?.contains(e3.target) && onOpen(false);
|
|
1955
|
+
const esc = (e3) => e3.key === "Escape" && onOpen(false);
|
|
1956
|
+
document.addEventListener("pointerdown", close, true);
|
|
1957
|
+
document.addEventListener("keydown", esc);
|
|
1958
|
+
return () => {
|
|
1959
|
+
document.removeEventListener("pointerdown", close, true);
|
|
1960
|
+
document.removeEventListener("keydown", esc);
|
|
1961
|
+
};
|
|
1962
|
+
}, [open]);
|
|
1963
|
+
const strengths = [
|
|
1964
|
+
{ mode: "weak", label: t3.magnetWeak, sub: t3.magnetWeakSub },
|
|
1965
|
+
{ mode: "strong", label: t3.magnetStrong, sub: t3.magnetStrongSub }
|
|
1966
|
+
];
|
|
1967
|
+
const now = strengths.find((x2) => x2.mode === (s3.magnet ? s3.magnetMode : s3.magnetStrength));
|
|
1968
|
+
const name = s3.magnet ? `${t3.magnet}: ${now.label}` : t3.magnet;
|
|
1969
|
+
return /* @__PURE__ */ a3("div", { class: "fnc-tool-group", ref, "data-open": open, onPointerEnter: hover.onPointerEnter, onPointerLeave: hover.onPointerLeave, children: [
|
|
1970
|
+
/* @__PURE__ */ a3("button", { class: "fnc-btn", "data-tip": name, "aria-label": name, "aria-pressed": s3.magnet, "data-magnet": s3.magnet ? s3.magnetMode : "off", onClick: () => ctx.setMagnetMode(s3.magnet ? "off" : s3.magnetStrength), children: /* @__PURE__ */ a3(MagnetIcon, {}) }),
|
|
1971
|
+
/* @__PURE__ */ a3("button", { class: "fnc-tool-more", "aria-label": `${t3.magnetModes}: ${now.label}`, "aria-haspopup": "menu", "aria-expanded": open, onClick: hover.toggle, children: [
|
|
1972
|
+
/* @__PURE__ */ a3("span", { class: "fnc-tool-corner", children: /* @__PURE__ */ a3(CornerIcon, {}) }),
|
|
1973
|
+
/* @__PURE__ */ a3("span", { class: "fnc-tool-chevron", children: /* @__PURE__ */ a3(ChevronRightIcon, {}) })
|
|
1974
|
+
] }),
|
|
1975
|
+
open && /* @__PURE__ */ a3("div", { class: "fnc-menu fnc-tool-menu fnc-magnet-menu", role: "menu", ref: menu, children: [
|
|
1976
|
+
/* @__PURE__ */ a3("div", { class: "fnc-tool-section", role: "presentation", children: t3.magnetModes }),
|
|
1977
|
+
strengths.map((x2) => /* @__PURE__ */ a3(
|
|
1978
|
+
"button",
|
|
1979
|
+
{
|
|
1980
|
+
class: "fnc-menu-item fnc-magnet-item",
|
|
1981
|
+
role: "menuitemradio",
|
|
1982
|
+
"aria-checked": s3.magnet && s3.magnetMode === x2.mode,
|
|
1983
|
+
onClick: () => {
|
|
1984
|
+
ctx.setMagnetMode(x2.mode);
|
|
1985
|
+
onOpen(false);
|
|
1986
|
+
},
|
|
1987
|
+
children: [
|
|
1988
|
+
/* @__PURE__ */ a3(MagnetIcon, {}),
|
|
1989
|
+
/* @__PURE__ */ a3("span", { children: [
|
|
1990
|
+
/* @__PURE__ */ a3("b", { children: x2.label }),
|
|
1991
|
+
/* @__PURE__ */ a3("small", { children: x2.sub })
|
|
1992
|
+
] })
|
|
1993
|
+
]
|
|
1994
|
+
},
|
|
1995
|
+
x2.mode
|
|
1996
|
+
))
|
|
1997
|
+
] })
|
|
1998
|
+
] });
|
|
1999
|
+
}
|
|
1734
2000
|
function DrawingToolbar({ ctx }) {
|
|
1735
2001
|
const s3 = useStore(ctx.store);
|
|
1736
2002
|
const t3 = stringsOf(s3);
|
|
@@ -1785,7 +2051,7 @@ function DrawingToolbar({ ctx }) {
|
|
|
1785
2051
|
onScroll: checkMore,
|
|
1786
2052
|
children: [
|
|
1787
2053
|
more.up && /* @__PURE__ */ a3("button", { class: "fnc-drawbar-more is-up", "aria-label": t3.moreToolsUp, onClick: () => scrollBar(-160), children: /* @__PURE__ */ a3(ChevronUpIcon, {}) }),
|
|
1788
|
-
/* @__PURE__ */ a3(CursorGroup, { ctx, open: openGroup === "__cursor", onOpen: (open) => setOpenGroup(open ? "__cursor" : null), onPick: () => pick(null) }),
|
|
2054
|
+
/* @__PURE__ */ a3(CursorGroup, { ctx, open: openGroup === "__cursor", onOpen: (open) => setOpenGroup((cur) => open ? "__cursor" : cur === "__cursor" ? null : cur), onPick: () => pick(null) }),
|
|
1789
2055
|
favorites.length > 0 && /* @__PURE__ */ a3($, { children: [
|
|
1790
2056
|
favorites.map((def) => /* @__PURE__ */ a3(
|
|
1791
2057
|
"button",
|
|
@@ -1807,23 +2073,13 @@ function DrawingToolbar({ ctx }) {
|
|
|
1807
2073
|
ctx,
|
|
1808
2074
|
tools,
|
|
1809
2075
|
open: openGroup === key,
|
|
1810
|
-
onOpen: (open) => setOpenGroup(open ? key : null),
|
|
2076
|
+
onOpen: (open) => setOpenGroup((cur) => open ? key : cur === key ? null : cur),
|
|
1811
2077
|
onPick: pick
|
|
1812
2078
|
},
|
|
1813
2079
|
key
|
|
1814
2080
|
)),
|
|
1815
2081
|
/* @__PURE__ */ a3("div", { class: "fnc-hsep" }),
|
|
1816
|
-
/* @__PURE__ */ a3(
|
|
1817
|
-
"button",
|
|
1818
|
-
{
|
|
1819
|
-
class: "fnc-btn",
|
|
1820
|
-
"data-tip": t3.magnet,
|
|
1821
|
-
"aria-label": t3.magnet,
|
|
1822
|
-
"aria-pressed": s3.magnet,
|
|
1823
|
-
onClick: () => ctx.chart.setMagnet(!s3.magnet),
|
|
1824
|
-
children: /* @__PURE__ */ a3(MagnetIcon, {})
|
|
1825
|
-
}
|
|
1826
|
-
),
|
|
2082
|
+
/* @__PURE__ */ a3(MagnetGroup, { ctx, open: openGroup === "__magnet", onOpen: (open) => setOpenGroup((cur) => open ? "__magnet" : cur === "__magnet" ? null : cur) }),
|
|
1827
2083
|
/* @__PURE__ */ a3("button", { class: "fnc-btn", "data-tip": t3.keepDrawing, "aria-label": t3.keepDrawing, "aria-pressed": s3.keepDrawing, onClick: () => ctx.setKeepDrawing(!s3.keepDrawing), children: /* @__PURE__ */ a3(KeepDrawingIcon, {}) }),
|
|
1828
2084
|
/* @__PURE__ */ a3(
|
|
1829
2085
|
"button",
|
|
@@ -1881,7 +2137,6 @@ var SWATCHES = ["#3182F6", "#F04452", "#12B886", "#FF9F0A", "#7048E8"];
|
|
|
1881
2137
|
var WIDTHS = [1, 2, 3, 4];
|
|
1882
2138
|
var FONT_SIZES = [10, 12, 14, 16, 20, 24, 32];
|
|
1883
2139
|
var DASH_ORDER = ["solid", "dashed", "dotted"];
|
|
1884
|
-
var RECENT_KEY = "fnc-drawing-colors";
|
|
1885
2140
|
var POS_KEY = "fnc-selbar-pos";
|
|
1886
2141
|
var TEMPLATES_KEY = "fnc-drawing-templates";
|
|
1887
2142
|
var TEMPLATES_MAX = 20;
|
|
@@ -1960,11 +2215,10 @@ function SelectionBar({ ctx }) {
|
|
|
1960
2215
|
const t3 = stringsOf(s3);
|
|
1961
2216
|
const d3 = s3.selection;
|
|
1962
2217
|
const [offset, setOffset] = d2(() => readJson(POS_KEY, [0, 0]));
|
|
1963
|
-
const [recent, setRecent] = d2(() =>
|
|
2218
|
+
const [recent, setRecent] = d2(() => recentColors().slice(0, 3));
|
|
1964
2219
|
const [menu, setMenu] = d2(null);
|
|
1965
2220
|
const [templates, setTemplates] = d2(() => readJson(TEMPLATES_KEY, {}));
|
|
1966
2221
|
const [naming, setNaming] = d2(null);
|
|
1967
|
-
const colorInput = T2(null);
|
|
1968
2222
|
if (!d3 || s3.layout.plotWidth <= 0) return null;
|
|
1969
2223
|
const def = ctx.chart.drawingDefinitions().find((x2) => x2.type === d3.type);
|
|
1970
2224
|
const style = d3.style ?? {};
|
|
@@ -1989,11 +2243,6 @@ function SelectionBar({ ctx }) {
|
|
|
1989
2243
|
setStyleRaw(rest);
|
|
1990
2244
|
};
|
|
1991
2245
|
const slotColor = (key, fallback) => style.colors?.[key] ?? d3.color ?? fallback;
|
|
1992
|
-
const addRecent = (color) => {
|
|
1993
|
-
const next = [color, ...recent.filter((c3) => c3 !== color)].slice(0, 3);
|
|
1994
|
-
setRecent(next);
|
|
1995
|
-
writeJson(RECENT_KEY, next);
|
|
1996
|
-
};
|
|
1997
2246
|
const locked = !!style.locked;
|
|
1998
2247
|
const dash = style.dash ?? "solid";
|
|
1999
2248
|
const mine = templates[d3.type] ?? [];
|
|
@@ -2010,6 +2259,14 @@ function SelectionBar({ ctx }) {
|
|
|
2010
2259
|
setNaming(null);
|
|
2011
2260
|
setMenu(null);
|
|
2012
2261
|
};
|
|
2262
|
+
const resetLook = () => {
|
|
2263
|
+
const { text, locked: lock, hidden, intervals } = style;
|
|
2264
|
+
ctx.chart.updateDrawing(d3.id, {
|
|
2265
|
+
color: null,
|
|
2266
|
+
style: { ...text !== void 0 ? { text } : {}, ...lock ? { locked: lock } : {}, ...hidden ? { hidden } : {}, ...intervals ? { intervals } : {} }
|
|
2267
|
+
});
|
|
2268
|
+
setMenu(null);
|
|
2269
|
+
};
|
|
2013
2270
|
const applyTemplate = (tpl) => {
|
|
2014
2271
|
const { text, locked: lock, hidden } = style;
|
|
2015
2272
|
ctx.chart.updateDrawing(d3.id, {
|
|
@@ -2050,36 +2307,29 @@ function SelectionBar({ ctx }) {
|
|
|
2050
2307
|
}
|
|
2051
2308
|
),
|
|
2052
2309
|
!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) })),
|
|
2053
|
-
!def?.levels && !def?.plain && /* @__PURE__ */ a3(
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
"
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2310
|
+
!def?.levels && !def?.plain && /* @__PURE__ */ a3(
|
|
2311
|
+
ColorPicker,
|
|
2312
|
+
{
|
|
2313
|
+
class: "fnc-swatch fnc-swatch-add",
|
|
2314
|
+
value: current,
|
|
2315
|
+
label: t3.palette,
|
|
2316
|
+
tip: t3.palette,
|
|
2317
|
+
t: t3,
|
|
2318
|
+
onPick: (color) => {
|
|
2319
|
+
pickColor(color);
|
|
2320
|
+
setRecent(recentColors().slice(0, 3));
|
|
2321
|
+
},
|
|
2322
|
+
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" }) })
|
|
2323
|
+
}
|
|
2324
|
+
),
|
|
2066
2325
|
slots.length > 0 && /* @__PURE__ */ a3("div", { class: "fnc-selbar-menu", children: [
|
|
2067
2326
|
/* @__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, {}) }),
|
|
2068
2327
|
menu === "colors" && /* @__PURE__ */ a3("div", { class: "fnc-menu fnc-selbar-pop fnc-part-menu", role: "menu", children: [
|
|
2069
2328
|
slots.map((slot) => {
|
|
2070
2329
|
const c3 = slotColor(slot.key, slot.color);
|
|
2071
|
-
return /* @__PURE__ */ a3("
|
|
2072
|
-
/* @__PURE__ */ a3(
|
|
2073
|
-
/* @__PURE__ */ a3("span", { children: slot.name[s3.locale] })
|
|
2074
|
-
/* @__PURE__ */ a3(
|
|
2075
|
-
"input",
|
|
2076
|
-
{
|
|
2077
|
-
type: "color",
|
|
2078
|
-
"aria-label": `${slot.name[s3.locale]} ${t3.color}`,
|
|
2079
|
-
value: /^#[0-9a-f]{6}$/i.test(c3) ? c3 : "#3182f6",
|
|
2080
|
-
onInput: (e3) => setStyle({ colors: { ...style.colors, [slot.key]: e3.target.value } })
|
|
2081
|
-
}
|
|
2082
|
-
)
|
|
2330
|
+
return /* @__PURE__ */ a3("div", { class: "fnc-menu-item fnc-part", children: [
|
|
2331
|
+
/* @__PURE__ */ a3(ColorPicker, { class: "fnc-swatch", style: { background: c3 }, value: c3, label: `${slot.name[s3.locale]} ${t3.color}`, t: t3, onPick: (color) => setStyle({ colors: { ...style.colors, [slot.key]: color } }) }),
|
|
2332
|
+
/* @__PURE__ */ a3("span", { children: slot.name[s3.locale] })
|
|
2083
2333
|
] });
|
|
2084
2334
|
}),
|
|
2085
2335
|
/* @__PURE__ */ a3(
|
|
@@ -2175,15 +2425,18 @@ function SelectionBar({ ctx }) {
|
|
|
2175
2425
|
}
|
|
2176
2426
|
}
|
|
2177
2427
|
),
|
|
2178
|
-
/* @__PURE__ */ a3(
|
|
2179
|
-
|
|
2428
|
+
/* @__PURE__ */ a3(
|
|
2429
|
+
ColorPicker,
|
|
2180
2430
|
{
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2431
|
+
class: "fnc-swatch fnc-level-color",
|
|
2432
|
+
style: { background: l3.color ?? "#3182F6" },
|
|
2433
|
+
tip: t3.levelColor,
|
|
2434
|
+
value: l3.color ?? "",
|
|
2435
|
+
label: `${t3.levelColor} ${l3.value}`,
|
|
2436
|
+
t: t3,
|
|
2437
|
+
onPick: (color) => setLevels(levelRows.map((x2, j2) => j2 === i3 ? { ...x2, color } : x2))
|
|
2185
2438
|
}
|
|
2186
|
-
)
|
|
2439
|
+
),
|
|
2187
2440
|
/* @__PURE__ */ a3(
|
|
2188
2441
|
"input",
|
|
2189
2442
|
{
|
|
@@ -2329,7 +2582,10 @@ function SelectionBar({ ctx }) {
|
|
|
2329
2582
|
)
|
|
2330
2583
|
] })),
|
|
2331
2584
|
/* @__PURE__ */ a3("div", { class: "fnc-menu-sep" }),
|
|
2332
|
-
naming === null ? /* @__PURE__ */ a3(
|
|
2585
|
+
naming === null ? /* @__PURE__ */ a3($, { children: [
|
|
2586
|
+
/* @__PURE__ */ a3("button", { class: "fnc-menu-item", role: "menuitem", onClick: () => setNaming(""), children: t3.saveTemplate }),
|
|
2587
|
+
/* @__PURE__ */ a3("button", { class: "fnc-menu-item", role: "menuitem", onClick: resetLook, children: t3.resetDrawingLook })
|
|
2588
|
+
] }) : /* @__PURE__ */ a3(
|
|
2333
2589
|
"input",
|
|
2334
2590
|
{
|
|
2335
2591
|
class: "fnc-selbar-text fnc-template-name",
|
|
@@ -2402,13 +2658,14 @@ function SelectionBar({ ctx }) {
|
|
|
2402
2658
|
),
|
|
2403
2659
|
/* @__PURE__ */ a3("div", { class: "fnc-note-row", children: [
|
|
2404
2660
|
/* @__PURE__ */ a3(
|
|
2405
|
-
|
|
2661
|
+
ColorPicker,
|
|
2406
2662
|
{
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2663
|
+
class: "fnc-color fnc-color-btn",
|
|
2664
|
+
style: { background: style.textColor ?? d3.color ?? "#3182F6" },
|
|
2665
|
+
value: style.textColor ?? d3.color ?? "",
|
|
2666
|
+
label: t3.textColor,
|
|
2667
|
+
t: t3,
|
|
2668
|
+
onPick: (textColor) => setStyle({ textColor })
|
|
2412
2669
|
}
|
|
2413
2670
|
),
|
|
2414
2671
|
/* @__PURE__ */ a3("select", { class: "fnc-select", "aria-label": t3.fontSize, value: String(style.fontSize ?? 14), onChange: (e3) => setStyle({ fontSize: Number(e3.target.value) }), children: [10, 11, 12, 14, 16, 20, 24, 28, 32, 40].map((n2) => /* @__PURE__ */ a3("option", { value: String(n2), children: [
|
|
@@ -2739,14 +2996,14 @@ var PRECISIONS = [0, 1, 2, 3, 4, 5, 6, 7, 8];
|
|
|
2739
2996
|
var TIMEFRAMES = ["3", "5", "15", "30", "60", "120", "240", "1D", "1W", "1M"];
|
|
2740
2997
|
var hex6 = (c3) => /^#[0-9a-f]{6}/i.test(c3) ? c3.slice(0, 7) : "#3182f6";
|
|
2741
2998
|
var alphaOf = (c3) => /^#[0-9a-f]{8}$/i.test(c3) ? Math.round(parseInt(c3.slice(7, 9), 16) / 255 * 100) : 100;
|
|
2742
|
-
var withAlpha = (
|
|
2743
|
-
const base = hex6(
|
|
2999
|
+
var withAlpha = (hex2, pct) => {
|
|
3000
|
+
const base = hex6(hex2);
|
|
2744
3001
|
return pct >= 100 ? base : `${base}${Math.round(Math.max(0, pct) / 100 * 255).toString(16).padStart(2, "0")}`;
|
|
2745
3002
|
};
|
|
2746
|
-
function ColorField({ value, label, onChange }) {
|
|
3003
|
+
function ColorField({ value, label, t: t3, onChange }) {
|
|
2747
3004
|
const pct = alphaOf(value);
|
|
2748
3005
|
return /* @__PURE__ */ a3("span", { class: "fnc-color-field", children: [
|
|
2749
|
-
/* @__PURE__ */ a3(
|
|
3006
|
+
/* @__PURE__ */ a3(ColorPicker, { class: "fnc-color fnc-color-btn", style: { background: hex6(value) }, value: hex6(value), label, t: t3, onPick: (c3) => onChange(withAlpha(c3, pct)) }),
|
|
2750
3007
|
/* @__PURE__ */ a3(
|
|
2751
3008
|
"input",
|
|
2752
3009
|
{
|
|
@@ -2980,7 +3237,7 @@ function IndicatorSettings({ ctx, id, Dialog: Dialog2 }) {
|
|
|
2980
3237
|
/* @__PURE__ */ a3("div", { class: "fnc-rows", children: rows.map((r3, i3) => /* @__PURE__ */ a3("div", { class: "fnc-row fnc-style-row", children: [
|
|
2981
3238
|
/* @__PURE__ */ a3("input", { type: "checkbox", class: "fnc-check", checked: r3.visible, "aria-label": r3.visible ? t3.hide : t3.show, onChange: (e3) => patchRow(i3, { visible: e3.currentTarget.checked }) }),
|
|
2982
3239
|
/* @__PURE__ */ a3("span", { class: "fnc-row-label fnc-row-label-wide", title: r3.label, children: r3.label }),
|
|
2983
|
-
/* @__PURE__ */ a3(ColorField, { value: /^#[0-9a-f]{6}/i.test(r3.color) ? r3.color : hex6(r3.color), label: t3.color, onChange: (color) => patchRow(i3, { color }) }),
|
|
3240
|
+
/* @__PURE__ */ a3(ColorField, { t: t3, value: /^#[0-9a-f]{6}/i.test(r3.color) ? r3.color : hex6(r3.color), label: t3.color, onChange: (color) => patchRow(i3, { color }) }),
|
|
2984
3241
|
/* @__PURE__ */ a3("select", { class: "fnc-select fnc-select-width", value: r3.width, "aria-label": t3.lineWidth, onChange: (e3) => patchRow(i3, { width: Number(e3.currentTarget.value) }), children: WIDTHS2.map((w3) => /* @__PURE__ */ a3("option", { value: w3, children: [
|
|
2985
3242
|
w3,
|
|
2986
3243
|
"px"
|
|
@@ -2992,7 +3249,7 @@ function IndicatorSettings({ ctx, id, Dialog: Dialog2 }) {
|
|
|
2992
3249
|
hasLevels && /* @__PURE__ */ a3("div", { class: "fnc-row", children: [
|
|
2993
3250
|
/* @__PURE__ */ a3("input", { type: "checkbox", class: "fnc-check", checked: display.levels !== false, "aria-label": t3.indLevels, onChange: (e3) => setD({ levels: e3.currentTarget.checked ? void 0 : false }) }),
|
|
2994
3251
|
/* @__PURE__ */ a3("span", { class: "fnc-row-label fnc-row-label-wide", children: t3.indLevels }),
|
|
2995
|
-
/* @__PURE__ */ a3(ColorField, { value: display.levelColor ?? "#8b95a1", label: t3.color, onChange: (levelColor) => setD({ levelColor }) })
|
|
3252
|
+
/* @__PURE__ */ a3(ColorField, { t: t3, value: display.levelColor ?? "#8b95a1", label: t3.color, onChange: (levelColor) => setD({ levelColor }) })
|
|
2996
3253
|
] }),
|
|
2997
3254
|
hasLevels && display.levels !== false && /* @__PURE__ */ a3("div", { class: "fnc-row fnc-level-values", children: [
|
|
2998
3255
|
/* @__PURE__ */ a3("span", { class: "fnc-row-label fnc-row-label-wide", children: t3.levelValuesLabel }),
|
|
@@ -3010,8 +3267,8 @@ function IndicatorSettings({ ctx, id, Dialog: Dialog2 }) {
|
|
|
3010
3267
|
const n2 = Number(e3.currentTarget.value);
|
|
3011
3268
|
const next = probe.levels.map((x2, j2) => display.levelValues?.[j2] ?? (typeof x2 === "number" ? x2 : x2.value));
|
|
3012
3269
|
next[i3] = Number.isFinite(n2) ? n2 : own;
|
|
3013
|
-
const
|
|
3014
|
-
setD({ levelValues:
|
|
3270
|
+
const same2 = next.every((x2, j2) => x2 === (typeof probe.levels[j2] === "number" ? probe.levels[j2] : probe.levels[j2].value));
|
|
3271
|
+
setD({ levelValues: same2 ? void 0 : next });
|
|
3015
3272
|
}
|
|
3016
3273
|
},
|
|
3017
3274
|
`${i3}:${v3 ?? own}`
|
|
@@ -3021,7 +3278,7 @@ function IndicatorSettings({ ctx, id, Dialog: Dialog2 }) {
|
|
|
3021
3278
|
hasFill && /* @__PURE__ */ a3("div", { class: "fnc-row", children: [
|
|
3022
3279
|
/* @__PURE__ */ a3("input", { type: "checkbox", class: "fnc-check", checked: display.fill !== false, "aria-label": t3.fillBand, onChange: (e3) => setD({ fill: e3.currentTarget.checked ? void 0 : false }) }),
|
|
3023
3280
|
/* @__PURE__ */ a3("span", { class: "fnc-row-label fnc-row-label-wide", children: t3.fillBand }),
|
|
3024
|
-
/* @__PURE__ */ a3(ColorField, { value: display.fillColor ?? (/^#[0-9a-f]{6}$/i.test(probe.fill?.color ?? "") ? `${probe.fill.color}26` : "#3182f626"), label: t3.color, onChange: (fillColor) => setD({ fillColor }) })
|
|
3281
|
+
/* @__PURE__ */ a3(ColorField, { t: t3, value: display.fillColor ?? (/^#[0-9a-f]{6}$/i.test(probe.fill?.color ?? "") ? `${probe.fill.color}26` : "#3182f626"), label: t3.color, onChange: (fillColor) => setD({ fillColor }) })
|
|
3025
3282
|
] })
|
|
3026
3283
|
] }),
|
|
3027
3284
|
/* @__PURE__ */ a3("div", { class: "fnc-section", children: t3.outputValues }),
|
|
@@ -3788,7 +4045,6 @@ var CSS = (
|
|
|
3788
4045
|
}
|
|
3789
4046
|
.fnc-tip[data-side='bottom'] { transform: translateY(-4px); }
|
|
3790
4047
|
.fnc-tip[data-side='top'] { transform: translateY(4px); }
|
|
3791
|
-
.fnc-tip[data-side='right'] { transform: translateX(-4px); }
|
|
3792
4048
|
.fnc-tip.is-on {
|
|
3793
4049
|
opacity: 1;
|
|
3794
4050
|
visibility: visible;
|
|
@@ -4186,7 +4442,16 @@ var CSS = (
|
|
|
4186
4442
|
.fnc-btn-label span { display: none; }
|
|
4187
4443
|
.fnc-toolbar .fnc-btn-label { padding: 0 6px; }
|
|
4188
4444
|
}
|
|
4445
|
+
/* A narrower widget (beside a book and an order panel): the pinned intervals stay, as a strip that
|
|
4446
|
+
scrolls sideways and gives up room before the buttons do; phones (\u2264 480px) keep only the menu. */
|
|
4189
4447
|
@container fnc (max-width: 940px) {
|
|
4448
|
+
.fnc-interval-picker { flex: 0 1 auto; min-width: 88px; }
|
|
4449
|
+
.fnc-intervals { flex: 0 1 auto; }
|
|
4450
|
+
.fnc-chip { padding: 0 8px; }
|
|
4451
|
+
/* The host's toolbar content (market stats) gives up its room first. */
|
|
4452
|
+
.fnc-toolbar > .fnc-slot-host:not(.fnc-slot-host-fixed) { flex-shrink: 100; }
|
|
4453
|
+
}
|
|
4454
|
+
@container fnc (max-width: 480px) {
|
|
4190
4455
|
.fnc-intervals { display: none; }
|
|
4191
4456
|
.fnc-interval-current { display: inline; }
|
|
4192
4457
|
}
|
|
@@ -4380,10 +4645,9 @@ var CSS = (
|
|
|
4380
4645
|
/* \u2500\u2500 Drawing tool groups \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
4381
4646
|
.fnc-tool-group { position: relative; display: flex; }
|
|
4382
4647
|
.fnc-tool-group[data-open='true'] { z-index: 30; }
|
|
4383
|
-
/* The list opener: a corner mark
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
way. Touch screens always show the chevron (no hover). */
|
|
4648
|
+
/* The list opener: a corner mark on the group's button (a click on it opens the list; a mouse
|
|
4649
|
+
resting on the group opens it too). Every tool in the bar lights up on hover the same way.
|
|
4650
|
+
Touch screens show a chevron instead (no hover to open with). */
|
|
4387
4651
|
.fnc-drawbar .fnc-btn:hover { background: var(--fnc-surface); }
|
|
4388
4652
|
.fnc-tool-more {
|
|
4389
4653
|
position: absolute;
|
|
@@ -4400,33 +4664,14 @@ var CSS = (
|
|
|
4400
4664
|
.fnc-tool-corner { display: flex; opacity: 0.7; }
|
|
4401
4665
|
.fnc-tool-chevron { display: none; }
|
|
4402
4666
|
.fnc-tool-chevron svg { width: 12px; height: 12px; }
|
|
4667
|
+
/* A mouse opens a group's list by resting on it (hover-open.ts): no tab or chevron grows out on
|
|
4668
|
+
hover \u2014 the corner mark stays (a group; a click on it keeps the list open), the button stays lit
|
|
4669
|
+
while its list is open. */
|
|
4403
4670
|
@media (hover: hover) {
|
|
4404
|
-
.fnc-tool-group
|
|
4405
|
-
.fnc-tool-group[data-open='true'] > .fnc-btn {
|
|
4406
|
-
background: var(--fnc-surface);
|
|
4407
|
-
border-top-right-radius: 0;
|
|
4408
|
-
border-bottom-right-radius: 0;
|
|
4409
|
-
}
|
|
4671
|
+
.fnc-tool-group[data-open='true'] > .fnc-btn { background: var(--fnc-surface); }
|
|
4410
4672
|
.fnc-tool-group:hover .fnc-tool-more,
|
|
4411
|
-
.fnc-tool-more[aria-expanded='true'],
|
|
4412
|
-
.fnc-tool-more:focus-visible {
|
|
4413
|
-
right: -14px;
|
|
4414
|
-
width: 14px;
|
|
4415
|
-
align-items: center;
|
|
4416
|
-
justify-content: center;
|
|
4417
|
-
padding: 0;
|
|
4418
|
-
border-radius: 0 var(--fnc-radius) var(--fnc-radius) 0;
|
|
4419
|
-
background: var(--fnc-surface);
|
|
4420
|
-
color: var(--fnc-text-2);
|
|
4421
|
-
}
|
|
4422
|
-
.fnc-tool-more:hover,
|
|
4423
4673
|
.fnc-tool-more[aria-expanded='true'] { color: var(--fnc-text); }
|
|
4424
|
-
.fnc-tool-
|
|
4425
|
-
.fnc-tool-more[aria-expanded='true'] .fnc-tool-corner,
|
|
4426
|
-
.fnc-tool-more:focus-visible .fnc-tool-corner { display: none; }
|
|
4427
|
-
.fnc-tool-group:hover .fnc-tool-chevron,
|
|
4428
|
-
.fnc-tool-more[aria-expanded='true'] .fnc-tool-chevron,
|
|
4429
|
-
.fnc-tool-more:focus-visible .fnc-tool-chevron { display: flex; }
|
|
4674
|
+
.fnc-tool-more:focus-visible { outline: 2px solid var(--fnc-accent); outline-offset: 1px; border-radius: 3px; }
|
|
4430
4675
|
}
|
|
4431
4676
|
@media (hover: none) {
|
|
4432
4677
|
.fnc-tool-more { right: -8px; width: 10px; align-items: center; justify-content: center; padding: 0; }
|
|
@@ -4750,6 +4995,46 @@ var CSS = (
|
|
|
4750
4995
|
.fnc-rows .fnc-input-period { order: 11; }
|
|
4751
4996
|
.fnc-rows .fnc-ind-btn { margin-left: auto; }
|
|
4752
4997
|
}
|
|
4998
|
+
|
|
4999
|
+
/* \u2500\u2500 \uC0C9 \uACE0\uB974\uAE30 (color-picker.tsx): a board of ready colors, the recent ones, and the browser's picker \u2500\u2500 */
|
|
5000
|
+
.fnc-palette-wrap { display: inline-flex; flex: none; }
|
|
5001
|
+
.fnc-palette-wrap > button { padding: 0; border: 0; font: inherit; }
|
|
5002
|
+
.fnc-palette-wrap > .fnc-swatch { border-radius: 50%; cursor: pointer; }
|
|
5003
|
+
.fnc-palette {
|
|
5004
|
+
position: fixed;
|
|
5005
|
+
z-index: 60;
|
|
5006
|
+
display: flex;
|
|
5007
|
+
flex-direction: column;
|
|
5008
|
+
gap: 6px;
|
|
5009
|
+
width: max-content;
|
|
5010
|
+
padding: 10px;
|
|
5011
|
+
border-radius: 12px;
|
|
5012
|
+
background: var(--fnc-bg);
|
|
5013
|
+
color: var(--fnc-text);
|
|
5014
|
+
box-shadow: 0 8px 28px rgb(0 0 0 / 0.16), 0 0 0 1px var(--fnc-border);
|
|
5015
|
+
cursor: default;
|
|
5016
|
+
}
|
|
5017
|
+
.fnc-palette-grid { display: grid; grid-template-columns: repeat(10, 20px); gap: 4px; }
|
|
5018
|
+
.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); }
|
|
5019
|
+
.fnc-palette-cell:hover { transform: scale(1.12); }
|
|
5020
|
+
.fnc-palette-cell[aria-selected='true'] { box-shadow: 0 0 0 2px var(--fnc-bg), 0 0 0 4px var(--fnc-text); }
|
|
5021
|
+
.fnc-palette-cell:focus-visible { outline: 2px solid var(--fnc-accent); outline-offset: 1px; }
|
|
5022
|
+
.fnc-palette-title { padding-top: 4px; font-size: 11px; font-weight: 600; color: var(--fnc-text-2); }
|
|
5023
|
+
.fnc-palette-custom { position: relative; display: flex; align-items: center; gap: 8px; height: 32px; margin-top: 2px; padding: 0 8px; border-top: 1px solid var(--fnc-border); font-size: 13px; color: var(--fnc-text); cursor: pointer; }
|
|
5024
|
+
.fnc-palette-custom:hover { background: var(--fnc-surface); border-radius: 8px; }
|
|
5025
|
+
.fnc-palette-custom-chip { width: 16px; height: 16px; border-radius: 4px; box-shadow: inset 0 0 0 1px rgb(127 127 127 / 0.3); }
|
|
5026
|
+
.fnc-palette-custom input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
|
|
5027
|
+
.fnc-color-btn { box-shadow: inset 0 0 0 3px var(--fnc-bg); }
|
|
5028
|
+
.fnc-part { gap: 10px; }
|
|
5029
|
+
|
|
5030
|
+
/* \uC790\uC11D \uC138\uAE30: two lines each (name, what it does) \u2014 the row grows to hold them. */
|
|
5031
|
+
.fnc-magnet-menu { width: 272px; }
|
|
5032
|
+
.fnc-tool-menu .fnc-magnet-item { height: auto; padding: 9px 10px; align-items: flex-start; gap: 10px; white-space: normal; }
|
|
5033
|
+
.fnc-magnet-item > svg { flex: none; margin-top: 1px; }
|
|
5034
|
+
.fnc-magnet-item > span { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
|
|
5035
|
+
.fnc-magnet-item b { font-size: 14px; font-weight: 600; line-height: 20px; color: var(--fnc-text); }
|
|
5036
|
+
.fnc-magnet-item small { font-size: 12px; line-height: 17px; color: var(--fnc-text-2); }
|
|
5037
|
+
.fnc-magnet-item + .fnc-magnet-item { margin-top: 2px; }
|
|
4753
5038
|
`
|
|
4754
5039
|
);
|
|
4755
5040
|
var STYLE_ID = "fnc-styles";
|
|
@@ -4798,10 +5083,10 @@ function bindTooltips(root) {
|
|
|
4798
5083
|
const h3 = tip.offsetHeight;
|
|
4799
5084
|
const vw = window.innerWidth;
|
|
4800
5085
|
const vh = window.innerHeight;
|
|
4801
|
-
let side = el.closest(".fnc-
|
|
5086
|
+
let side = el.closest(".fnc-nav") ? "top" : "bottom";
|
|
4802
5087
|
if (side === "bottom" && r3.bottom + h3 + 10 > vh) side = "top";
|
|
4803
|
-
let left =
|
|
4804
|
-
const top = side === "
|
|
5088
|
+
let left = el.closest(".fnc-drawbar") ? r3.left : r3.left + r3.width / 2 - w3 / 2;
|
|
5089
|
+
const top = side === "top" ? r3.top - h3 - 6 : r3.bottom + 6;
|
|
4805
5090
|
left = Math.max(4, Math.min(vw - w3 - 4, left));
|
|
4806
5091
|
tip.style.left = `${Math.round(left)}px`;
|
|
4807
5092
|
tip.style.top = `${Math.round(top)}px`;
|
|
@@ -4809,7 +5094,7 @@ function bindTooltips(root) {
|
|
|
4809
5094
|
};
|
|
4810
5095
|
const show = (el) => {
|
|
4811
5096
|
const text = el.dataset.tip;
|
|
4812
|
-
if (!text || !el.isConnected) return;
|
|
5097
|
+
if (!text || !el.isConnected || el.closest('.fnc-tool-group[data-open="true"]')) return;
|
|
4813
5098
|
tip.textContent = text;
|
|
4814
5099
|
el.setAttribute("aria-describedby", tip.id);
|
|
4815
5100
|
place(el);
|
|
@@ -4845,6 +5130,7 @@ function bindTooltips(root) {
|
|
|
4845
5130
|
root.addEventListener("wheel", hide, { passive: true });
|
|
4846
5131
|
root.addEventListener("focusin", onFocus);
|
|
4847
5132
|
root.addEventListener("focusout", hide);
|
|
5133
|
+
root.addEventListener("fnc-hide-tip", hide);
|
|
4848
5134
|
return () => {
|
|
4849
5135
|
hide();
|
|
4850
5136
|
root.removeEventListener("pointerover", onOver);
|
|
@@ -4853,6 +5139,7 @@ function bindTooltips(root) {
|
|
|
4853
5139
|
root.removeEventListener("wheel", hide);
|
|
4854
5140
|
root.removeEventListener("focusin", onFocus);
|
|
4855
5141
|
root.removeEventListener("focusout", hide);
|
|
5142
|
+
root.removeEventListener("fnc-hide-tip", hide);
|
|
4856
5143
|
tip.remove();
|
|
4857
5144
|
};
|
|
4858
5145
|
}
|
|
@@ -4903,11 +5190,19 @@ function createShell(container, options) {
|
|
|
4903
5190
|
let keepDrawing = storage.get("keep-drawing", false);
|
|
4904
5191
|
let drawingDefaults = storage.get("drawing-defaults", {});
|
|
4905
5192
|
let cursorMode = storage.get("cursor-mode", "cross");
|
|
5193
|
+
const isMagnet = (m3) => m3 === "off" || m3 === "weak" || m3 === "strong";
|
|
5194
|
+
let magnetMode = isMagnet(storage.get("magnet", "off")) ? storage.get("magnet", "off") : "off";
|
|
5195
|
+
let magnetStrength = storage.get("magnet-strength", "strong") === "weak" ? "weak" : "strong";
|
|
5196
|
+
const magnetState = () => ({ magnet: magnetMode !== "off", magnetMode, magnetStrength });
|
|
5197
|
+
const applyMagnet = () => {
|
|
5198
|
+
for (const p3 of panes()) p3.chart.setMagnetMode(magnetMode);
|
|
5199
|
+
broadcast(magnetState());
|
|
5200
|
+
};
|
|
4906
5201
|
const broadcast = (patch) => {
|
|
4907
5202
|
for (const p3 of panes()) p3.store.set(patch);
|
|
4908
5203
|
};
|
|
4909
5204
|
const prefListeners = /* @__PURE__ */ new Set();
|
|
4910
|
-
const prefs = () => ({ favoriteIntervals: [...favoriteIntervals], customIntervals: [...customIntervals], favoriteTools: [...favoriteTools], keepDrawing, drawingDefaults: { ...drawingDefaults }, cursorMode });
|
|
5205
|
+
const prefs = () => ({ favoriteIntervals: [...favoriteIntervals], customIntervals: [...customIntervals], favoriteTools: [...favoriteTools], keepDrawing, drawingDefaults: { ...drawingDefaults }, cursorMode, magnet: magnetMode, magnetStrength });
|
|
4911
5206
|
const changed = () => {
|
|
4912
5207
|
const now = prefs();
|
|
4913
5208
|
for (const l3 of prefListeners) l3(now);
|
|
@@ -4930,7 +5225,15 @@ function createShell(container, options) {
|
|
|
4930
5225
|
slots,
|
|
4931
5226
|
storage,
|
|
4932
5227
|
theme: () => theme,
|
|
4933
|
-
sharedState: () => ({ fullscreen: isFullscreen(), favoriteIntervals, customIntervals, drawbarCollapsed, favoriteTools, keepDrawing, cursorMode }),
|
|
5228
|
+
sharedState: () => ({ fullscreen: isFullscreen(), favoriteIntervals, customIntervals, drawbarCollapsed, favoriteTools, keepDrawing, cursorMode, ...magnetState() }),
|
|
5229
|
+
setMagnetMode: (mode) => {
|
|
5230
|
+
if (!isMagnet(mode)) return;
|
|
5231
|
+
magnetMode = mode;
|
|
5232
|
+
storage.set("magnet", mode);
|
|
5233
|
+
if (mode !== "off") storage.set("magnet-strength", magnetStrength = mode);
|
|
5234
|
+
applyMagnet();
|
|
5235
|
+
changed();
|
|
5236
|
+
},
|
|
4934
5237
|
setCursorMode: (mode) => {
|
|
4935
5238
|
cursorMode = mode;
|
|
4936
5239
|
storage.set("cursor-mode", mode);
|
|
@@ -5030,7 +5333,12 @@ function createShell(container, options) {
|
|
|
5030
5333
|
storage.set("cursor-mode", cursorMode = patch.cursorMode);
|
|
5031
5334
|
for (const p3 of panes()) p3.chart.setCursorMode(cursorMode);
|
|
5032
5335
|
}
|
|
5033
|
-
|
|
5336
|
+
if (patch.magnetStrength === "weak" || patch.magnetStrength === "strong") storage.set("magnet-strength", magnetStrength = patch.magnetStrength);
|
|
5337
|
+
if (isMagnet(patch.magnet)) {
|
|
5338
|
+
storage.set("magnet", magnetMode = patch.magnet);
|
|
5339
|
+
applyMagnet();
|
|
5340
|
+
}
|
|
5341
|
+
broadcast({ favoriteIntervals, customIntervals, favoriteTools, keepDrawing, cursorMode, ...magnetState() });
|
|
5034
5342
|
},
|
|
5035
5343
|
onPreferences: (listener) => {
|
|
5036
5344
|
prefListeners.add(listener);
|
|
@@ -5188,7 +5496,7 @@ function SettingsDialog({ ctx }) {
|
|
|
5188
5496
|
const colorRow = ({ key, label, shown: shown2, seeThrough }) => /* @__PURE__ */ a3("div", { class: "fnc-row fnc-color-row", children: [
|
|
5189
5497
|
/* @__PURE__ */ a3("span", { class: "fnc-toggle-label", children: t3[label] }),
|
|
5190
5498
|
settings[key] && /* @__PURE__ */ a3("button", { type: "button", class: "fnc-color-reset", title: t3.followTheme, "aria-label": `${t3[label]} ${t3.followTheme}`, onClick: () => set({ [key]: null }), children: /* @__PURE__ */ a3(ResetIcon, {}) }),
|
|
5191
|
-
/* @__PURE__ */ a3(Swatch, { label: t3[label], color: toHex(shown2(palette)), seeThrough, onPick: (c3) => set({ [key]: c3 }) })
|
|
5499
|
+
/* @__PURE__ */ a3(Swatch, { t: t3, label: t3[label], color: toHex(shown2(palette)), seeThrough, onPick: (c3) => set({ [key]: c3 }) })
|
|
5192
5500
|
] });
|
|
5193
5501
|
const tabs = [
|
|
5194
5502
|
["look", t3.settingsTabLook],
|
|
@@ -5302,8 +5610,8 @@ function SettingsDialog({ ctx }) {
|
|
|
5302
5610
|
]
|
|
5303
5611
|
}
|
|
5304
5612
|
),
|
|
5305
|
-
/* @__PURE__ */ a3(Swatch, { label: t3.settingBackground, color: toHex(palette.background), onPick: (c3) => set({ background: c3 }) }),
|
|
5306
|
-
settings.backgroundStyle === "gradient" && /* @__PURE__ */ a3(Swatch, { label: t3.bgGradientBottom, color: toHex(palette.backgroundBottom ?? palette.background), onPick: (c3) => set({ backgroundBottom: c3 }) })
|
|
5613
|
+
/* @__PURE__ */ a3(Swatch, { t: t3, label: t3.settingBackground, color: toHex(palette.background), onPick: (c3) => set({ background: c3 }) }),
|
|
5614
|
+
settings.backgroundStyle === "gradient" && /* @__PURE__ */ a3(Swatch, { t: t3, label: t3.bgGradientBottom, color: toHex(palette.backgroundBottom ?? palette.background), onPick: (c3) => set({ backgroundBottom: c3 }) })
|
|
5307
5615
|
] }),
|
|
5308
5616
|
CHART_COLORS.map(colorRow),
|
|
5309
5617
|
/* @__PURE__ */ a3("div", { class: "fnc-section", children: t3.settingsCandles }),
|
|
@@ -5408,11 +5716,8 @@ function usePageLayer(anchor, settings) {
|
|
|
5408
5716
|
}, [layer, settings]);
|
|
5409
5717
|
return layer;
|
|
5410
5718
|
}
|
|
5411
|
-
function Swatch({ label, color, seeThrough, onPick }) {
|
|
5412
|
-
return /* @__PURE__ */ a3(
|
|
5413
|
-
/* @__PURE__ */ a3("span", { style: { background: color } }),
|
|
5414
|
-
/* @__PURE__ */ a3("input", { type: "color", "aria-label": label, value: color, onInput: (e3) => onPick(e3.currentTarget.value) })
|
|
5415
|
-
] });
|
|
5719
|
+
function Swatch({ label, color, seeThrough, t: t3, onPick }) {
|
|
5720
|
+
return /* @__PURE__ */ a3(ColorPicker, { class: seeThrough ? "fnc-swatch-pick is-see-through" : "fnc-swatch-pick", tip: label, value: color, label, t: t3, onPick, children: /* @__PURE__ */ a3("span", { style: { background: color } }) });
|
|
5416
5721
|
}
|
|
5417
5722
|
function Info({ text }) {
|
|
5418
5723
|
return /* @__PURE__ */ a3("span", { class: "fnc-info", tabIndex: 0, role: "img", "aria-label": text, onClick: (e3) => e3.preventDefault(), children: [
|
|
@@ -5754,8 +6059,24 @@ function IntervalPicker({ ctx }) {
|
|
|
5754
6059
|
setOpen(false);
|
|
5755
6060
|
ctx.selectResolution(r3);
|
|
5756
6061
|
};
|
|
6062
|
+
const strip = T2(null);
|
|
6063
|
+
F2(() => {
|
|
6064
|
+
const el = strip.current;
|
|
6065
|
+
if (!el) return;
|
|
6066
|
+
const reveal = () => {
|
|
6067
|
+
const on = el.querySelector('[aria-pressed="true"]');
|
|
6068
|
+
if (!on || el.scrollWidth <= el.clientWidth) return;
|
|
6069
|
+
const left = on.offsetLeft - el.offsetLeft;
|
|
6070
|
+
if (left < el.scrollLeft) el.scrollLeft = left;
|
|
6071
|
+
else if (left + on.offsetWidth > el.scrollLeft + el.clientWidth) el.scrollLeft = left + on.offsetWidth - el.clientWidth;
|
|
6072
|
+
};
|
|
6073
|
+
reveal();
|
|
6074
|
+
const ro = new ResizeObserver(reveal);
|
|
6075
|
+
ro.observe(el);
|
|
6076
|
+
return () => ro.disconnect();
|
|
6077
|
+
}, [s3.resolution, chips.join(",")]);
|
|
5757
6078
|
return /* @__PURE__ */ a3("div", { class: "fnc-interval-picker", ref, children: [
|
|
5758
|
-
/* @__PURE__ */ a3("div", { class: "fnc-intervals", children: chips.map((r3) => /* @__PURE__ */ a3(
|
|
6079
|
+
/* @__PURE__ */ a3("div", { class: "fnc-intervals", ref: strip, children: chips.map((r3) => /* @__PURE__ */ a3(
|
|
5759
6080
|
"button",
|
|
5760
6081
|
{
|
|
5761
6082
|
class: favorites.includes(r3) ? "fnc-chip" : "fnc-chip fnc-chip-extra",
|
|
@@ -6558,7 +6879,7 @@ function MenuIcon({ name }) {
|
|
|
6558
6879
|
}
|
|
6559
6880
|
|
|
6560
6881
|
// src/components/context-menu.tsx
|
|
6561
|
-
var
|
|
6882
|
+
var MARGIN3 = 8;
|
|
6562
6883
|
function ContextMenu({ ctx }) {
|
|
6563
6884
|
const s3 = useStore(ctx.store);
|
|
6564
6885
|
const t3 = stringsOf(s3);
|
|
@@ -6588,8 +6909,8 @@ function ContextMenu({ ctx }) {
|
|
|
6588
6909
|
const w3 = el.offsetWidth;
|
|
6589
6910
|
const h3 = el.offsetHeight;
|
|
6590
6911
|
const { width, height } = stage.getBoundingClientRect();
|
|
6591
|
-
const x2 = target.x + w3 +
|
|
6592
|
-
const y3 = target.y + h3 +
|
|
6912
|
+
const x2 = target.x + w3 + MARGIN3 > width ? Math.max(MARGIN3, target.x - w3) : target.x;
|
|
6913
|
+
const y3 = target.y + h3 + MARGIN3 > height ? Math.max(MARGIN3, target.y - h3) : target.y;
|
|
6593
6914
|
el.style.transform = `translate(${Math.round(x2)}px, ${Math.round(y3)}px)`;
|
|
6594
6915
|
}, [target]);
|
|
6595
6916
|
if (!target) return null;
|
|
@@ -7231,6 +7552,7 @@ function createPane(shell, config) {
|
|
|
7231
7552
|
chart.setChartType(config.chartType);
|
|
7232
7553
|
chart.setKeepDrawingTool(shell.sharedState().keepDrawing);
|
|
7233
7554
|
chart.setCursorMode(shell.sharedState().cursorMode);
|
|
7555
|
+
chart.setMagnetMode(shell.sharedState().magnetMode);
|
|
7234
7556
|
chart.setDrawingDefaults(shell.drawingDefaults());
|
|
7235
7557
|
const canvasVars = (s3) => {
|
|
7236
7558
|
const muted = s3.textColor && /^#[0-9a-f]{6}$/i.test(s3.textColor) ? `${s3.textColor}99` : null;
|
|
@@ -7273,7 +7595,6 @@ function createPane(shell, config) {
|
|
|
7273
7595
|
drawingCount: 0,
|
|
7274
7596
|
drawingsLocked: false,
|
|
7275
7597
|
drawbarOpen: false,
|
|
7276
|
-
magnet: chart.magnetEnabled,
|
|
7277
7598
|
drawingsHidden: chart.drawingsHidden,
|
|
7278
7599
|
indicators: chart.getIndicators(),
|
|
7279
7600
|
dialog: null,
|
|
@@ -7290,7 +7611,7 @@ function createPane(shell, config) {
|
|
|
7290
7611
|
chart.on("selectionChange", (selection) => store.set({ selection })),
|
|
7291
7612
|
chart.on("drawingsChange", (drawings) => store.set({ drawingCount: drawings.length, drawingsLocked: drawings.length > 0 && drawings.every((d3) => d3.style?.locked) })),
|
|
7292
7613
|
chart.on("indicatorsChange", (indicators) => store.set({ indicators })),
|
|
7293
|
-
chart.on("
|
|
7614
|
+
chart.on("magnetModeChange", (magnetMode) => store.set({ magnet: magnetMode !== "off", magnetMode })),
|
|
7294
7615
|
chart.on("drawingsHiddenChange", (drawingsHidden) => store.set({ drawingsHidden })),
|
|
7295
7616
|
chart.on("cursorModeChange", (cursorMode) => store.set({ cursorMode })),
|
|
7296
7617
|
// A color or style picked for a drawing: remembered for the tool, in every pane.
|
|
@@ -7345,6 +7666,7 @@ function createPane(shell, config) {
|
|
|
7345
7666
|
toggleFavoriteTool: shell.toggleFavoriteTool,
|
|
7346
7667
|
setKeepDrawing: shell.setKeepDrawing,
|
|
7347
7668
|
setCursorMode: shell.setCursorMode,
|
|
7669
|
+
setMagnetMode: shell.setMagnetMode,
|
|
7348
7670
|
setDrawingsHidden: shell.setDrawingsHidden,
|
|
7349
7671
|
setSearchOpen: (open, target = "symbol") => store.set(open ? { searchOpen: true, searchTarget: target } : { searchOpen: false }),
|
|
7350
7672
|
screenshot: () => {
|
package/dist/shell.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { type CursorMode, type DirectionPreset, type DrawingDefaults, type DrawingType, type Resolution, type ThemeTokens } from '@funnest/charts';
|
|
1
|
+
import { type CursorMode, type DirectionPreset, type DrawingDefaults, type DrawingType, type MagnetMode, type Resolution, type ThemeTokens } from '@funnest/charts';
|
|
2
2
|
import type { UiState } from './context.js';
|
|
3
3
|
import { type WidgetStorage } from './storage.js';
|
|
4
4
|
import type { Store } from './store.js';
|
|
5
5
|
export type ColorScheme = 'light' | 'dark' | 'system';
|
|
6
6
|
/**
|
|
7
7
|
* A person's widget preferences (what follows them, not the device): pinned and added intervals,
|
|
8
|
-
* favorite drawing tools, keep-drawing, each tool's last style, the cursor. `preferences()` reads
|
|
8
|
+
* favorite drawing tools, keep-drawing, each tool's last style and settings, the cursor, the magnet. `preferences()` reads
|
|
9
9
|
* them, `setPreferences()` puts them (another device's), and `preferencesChange` tells when they
|
|
10
10
|
* change here — so an app can keep them on its users' accounts.
|
|
11
11
|
*/
|
|
@@ -16,6 +16,10 @@ export interface WidgetPreferences {
|
|
|
16
16
|
keepDrawing: boolean;
|
|
17
17
|
drawingDefaults: DrawingDefaults;
|
|
18
18
|
cursorMode: CursorMode;
|
|
19
|
+
/** 자석: off, weak or strong (kept, so it's on again after a reload). */
|
|
20
|
+
magnet: MagnetMode;
|
|
21
|
+
/** The strength the magnet button turns on with (the last one picked). */
|
|
22
|
+
magnetStrength: 'weak' | 'strong';
|
|
19
23
|
}
|
|
20
24
|
/**
|
|
21
25
|
* Empty elements inside the widget layout where the host app mounts its own UI (any framework):
|
|
@@ -48,6 +52,7 @@ export interface ShellPane {
|
|
|
48
52
|
setDrawingsHidden(hidden: boolean): void;
|
|
49
53
|
setDrawingDefaults(defaults: DrawingDefaults): void;
|
|
50
54
|
setCursorMode(mode: CursorMode): void;
|
|
55
|
+
setMagnetMode(mode: MagnetMode): void;
|
|
51
56
|
};
|
|
52
57
|
}
|
|
53
58
|
export interface ShellOptions {
|
|
@@ -78,8 +83,10 @@ export interface Shell {
|
|
|
78
83
|
readonly storage: WidgetStorage;
|
|
79
84
|
theme(): ThemeTokens;
|
|
80
85
|
/** Initial UI-state fields owned by the shell (same for every pane). */
|
|
81
|
-
sharedState(): Pick<UiState, 'fullscreen' | 'favoriteIntervals' | 'customIntervals' | 'drawbarCollapsed' | 'favoriteTools' | 'keepDrawing' | 'cursorMode'>;
|
|
86
|
+
sharedState(): Pick<UiState, 'fullscreen' | 'favoriteIntervals' | 'customIntervals' | 'drawbarCollapsed' | 'favoriteTools' | 'keepDrawing' | 'cursorMode' | 'magnet' | 'magnetMode' | 'magnetStrength'>;
|
|
82
87
|
setCursorMode(mode: CursorMode): void;
|
|
88
|
+
/** 자석 for every pane (kept). */
|
|
89
|
+
setMagnetMode(mode: MagnetMode): void;
|
|
83
90
|
/** Each tool's last color / style (saved; every pane starts with it). */
|
|
84
91
|
drawingDefaults(): DrawingDefaults;
|
|
85
92
|
saveDrawingDefaults(defaults: DrawingDefaults): void;
|
|
@@ -105,8 +112,8 @@ export interface Shell {
|
|
|
105
112
|
/**
|
|
106
113
|
* One tooltip per widget for every element with `data-tip` (instead of native `title`, whose look
|
|
107
114
|
* and delay can't be styled). Shows after 350ms of hover or on keyboard focus; moving between
|
|
108
|
-
* tipped elements shows the next one at once.
|
|
109
|
-
* navigation buttons,
|
|
115
|
+
* tipped elements shows the next one at once. Below the element (the drawing bar's too: its tool
|
|
116
|
+
* lists open to the right), above the navigation buttons, flipped up near the bottom edge.
|
|
110
117
|
*/
|
|
111
118
|
/** Hover / focus tips for every [data-tip] inside `root` (the widget, or a dialog's page layer). */
|
|
112
119
|
export declare function bindTooltips(root: HTMLElement): () => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@funnest/charts-ui",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.37",
|
|
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.
|
|
45
|
+
"@funnest/charts": "0.11.37"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"preact": "^11.2.0"
|