@enigmax/primitives 0.22.0 → 0.24.0
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/{chunk-QQFNAKMY.js → chunk-45UHLZYT.js} +1 -1
- package/dist/chunk-4VUHQFAT.js +130 -0
- package/dist/{chunk-D5A2ZMAG.js → chunk-4ZPMP47J.js} +6 -1
- package/dist/chunk-DZMHY3SU.js +777 -0
- package/dist/{chunk-FWVWX67R.js → chunk-FGBIZDV2.js} +3 -3
- package/dist/chunk-N6PDHMAX.js +213 -0
- package/dist/chunk-NONGREXC.js +248 -0
- package/dist/{chunk-R4ZAEE7V.js → chunk-QJJ34E4G.js} +34 -10
- package/dist/chunk-S2FPN5ID.js +115 -0
- package/dist/chunk-S7EE57YB.js +9 -0
- package/dist/chunk-VKL3DEIQ.js +804 -0
- package/dist/chunk-WSQC3PCC.js +466 -0
- package/dist/chunk-Z3VDE7OA.js +532 -0
- package/dist/clipboard-menu-B_ouitfS.d.ts +264 -0
- package/dist/color-D_rZ83Oc.d.ts +152 -0
- package/dist/color-OPV3BJV6.js +452 -0
- package/dist/{index-BHpOZncw.d.ts → index-ZPvlf9vs.d.ts} +53 -5
- package/dist/index.d.ts +6 -2
- package/dist/index.js +9 -4
- package/dist/keys-D2zJs1uB.d.ts +100 -0
- package/dist/next/index.d.ts +10 -3
- package/dist/next/index.js +22 -13
- package/dist/react/context-menu.d.ts +219 -0
- package/dist/react/context-menu.js +6 -0
- package/dist/react/index.d.ts +12 -5
- package/dist/react/index.js +21 -12
- package/dist/react/input.d.ts +3 -3
- package/dist/react/input.js +2 -1
- package/dist/react/palette.d.ts +1 -1
- package/dist/react/palette.js +3 -3
- package/dist/react/search.d.ts +1 -1
- package/dist/react/search.js +2 -2
- package/dist/react/select.d.ts +217 -0
- package/dist/react/select.js +7 -0
- package/dist/react/selection.d.ts +104 -0
- package/dist/react/selection.js +4 -0
- package/dist/react-router/index.d.ts +10 -3
- package/dist/react-router/index.js +22 -13
- package/dist/search/index.d.ts +2 -2
- package/dist/search/index.js +1 -1
- package/dist/{search-BD9-5O5U.d.ts → search-DYgqRp37.d.ts} +13 -1
- package/dist/{search-UQEXAPQB.js → search-PBZORZ7P.js} +1 -1
- package/dist/select-ClSy-J1f.d.ts +100 -0
- package/dist/selection-B_pmzHpy.d.ts +150 -0
- package/package.json +23 -2
- package/recipes/color/styles.css +143 -0
- package/recipes/context-menu/styles.css +185 -0
- package/recipes/input/styles.css +9 -0
- package/recipes/palette/styles.css +3 -0
- package/recipes/search/tailwind.tsx +3 -2
- package/recipes/select/styles.css +230 -0
- package/recipes/toast/styles.css +1 -1
- package/registry.json +432 -5
- package/src/core/clipboard-menu.ts +270 -0
- package/src/core/color.ts +248 -0
- package/src/core/context-menu.ts +694 -0
- package/src/core/keys.ts +264 -0
- package/src/core/search.ts +19 -0
- package/src/core/select.ts +404 -0
- package/src/core/selection.ts +648 -0
- package/src/index.ts +92 -1
- package/src/react/context-menu/context.ts +64 -0
- package/src/react/context-menu/index.tsx +108 -0
- package/src/react/context-menu/root.tsx +970 -0
- package/src/react/context-menu/styles.ts +194 -0
- package/src/react/index.ts +100 -1
- package/src/react/input/color-styles.ts +156 -0
- package/src/react/input/color.tsx +466 -0
- package/src/react/input/index.tsx +54 -6
- package/src/react/input/types.ts +59 -3
- package/src/react/palette/root.tsx +2 -2
- package/src/react/select/context.ts +56 -0
- package/src/react/select/index.tsx +96 -0
- package/src/react/select/root.tsx +839 -0
- package/src/react/select/styles.ts +238 -0
- package/src/react/selection/index.tsx +115 -0
- package/src/react/selection/use-selection.ts +260 -0
- package/dist/password-C8lG4Zm9.d.ts +0 -71
- /package/dist/{chunk-U3V4EHOB.js → chunk-MSOCCQGH.js} +0 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// src/core/keys.ts
|
|
2
|
+
var MODIFIERS = /* @__PURE__ */ new Set(["mod", "ctrl", "control", "meta", "cmd", "command", "super", "win", "shift", "alt", "option", "opt"]);
|
|
3
|
+
var NAMED = {
|
|
4
|
+
esc: "escape",
|
|
5
|
+
escape: "escape",
|
|
6
|
+
del: "delete",
|
|
7
|
+
delete: "delete",
|
|
8
|
+
back: "backspace",
|
|
9
|
+
backspace: "backspace",
|
|
10
|
+
enter: "enter",
|
|
11
|
+
return: "enter",
|
|
12
|
+
space: " ",
|
|
13
|
+
spacebar: " ",
|
|
14
|
+
tab: "tab",
|
|
15
|
+
up: "arrowup",
|
|
16
|
+
down: "arrowdown",
|
|
17
|
+
left: "arrowleft",
|
|
18
|
+
right: "arrowright",
|
|
19
|
+
arrowup: "arrowup",
|
|
20
|
+
arrowdown: "arrowdown",
|
|
21
|
+
arrowleft: "arrowleft",
|
|
22
|
+
arrowright: "arrowright",
|
|
23
|
+
home: "home",
|
|
24
|
+
end: "end",
|
|
25
|
+
pageup: "pageup",
|
|
26
|
+
pagedown: "pagedown",
|
|
27
|
+
plus: "+"
|
|
28
|
+
};
|
|
29
|
+
function isApplePlatform() {
|
|
30
|
+
if (typeof navigator === "undefined") return false;
|
|
31
|
+
const source = navigator.platform || navigator.userAgent || "";
|
|
32
|
+
return /mac|iphone|ipad|ipod/i.test(source);
|
|
33
|
+
}
|
|
34
|
+
function parseShortcut(spec) {
|
|
35
|
+
if (typeof spec !== "string") return { ...spec, key: normalizeKey(spec.key) };
|
|
36
|
+
const shortcut = { key: "" };
|
|
37
|
+
const parts = spec.split(/[+-](?!$)/).map((part) => part.trim()).filter(Boolean);
|
|
38
|
+
if (parts.length === 0) return { key: normalizeKey(spec.trim()) };
|
|
39
|
+
parts.forEach((part, index) => {
|
|
40
|
+
const word = part.toLowerCase();
|
|
41
|
+
const last = index === parts.length - 1;
|
|
42
|
+
if (!last && MODIFIERS.has(word)) {
|
|
43
|
+
applyModifier(shortcut, word);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (last && MODIFIERS.has(word) && parts.length > 1) {
|
|
47
|
+
applyModifier(shortcut, word);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
shortcut.key = normalizeKey(part);
|
|
51
|
+
});
|
|
52
|
+
if (!shortcut.key) shortcut.key = normalizeKey(parts[parts.length - 1]);
|
|
53
|
+
return shortcut;
|
|
54
|
+
}
|
|
55
|
+
function applyModifier(shortcut, word) {
|
|
56
|
+
if (word === "mod") shortcut.mod = true;
|
|
57
|
+
else if (word === "ctrl" || word === "control") shortcut.ctrl = true;
|
|
58
|
+
else if (word === "meta" || word === "cmd" || word === "command" || word === "super" || word === "win") shortcut.meta = true;
|
|
59
|
+
else if (word === "shift") shortcut.shift = true;
|
|
60
|
+
else shortcut.alt = true;
|
|
61
|
+
}
|
|
62
|
+
function normalizeKey(key) {
|
|
63
|
+
const lower = key.toLowerCase();
|
|
64
|
+
return NAMED[lower] ?? lower;
|
|
65
|
+
}
|
|
66
|
+
function shortcutList(spec) {
|
|
67
|
+
if (spec === false || spec == null) return [];
|
|
68
|
+
const entries = Array.isArray(spec) ? spec : [spec];
|
|
69
|
+
return entries.map(parseShortcut);
|
|
70
|
+
}
|
|
71
|
+
function matchesShortcut(event, spec, apple = isApplePlatform()) {
|
|
72
|
+
return shortcutList(spec).some((shortcut) => matchesOne(event, shortcut, apple));
|
|
73
|
+
}
|
|
74
|
+
function matchesOne(event, shortcut, apple) {
|
|
75
|
+
const key = normalizeKey(event.key);
|
|
76
|
+
const wantCtrl = Boolean(shortcut.ctrl || shortcut.mod && !apple);
|
|
77
|
+
const wantMeta = Boolean(shortcut.meta || shortcut.mod && apple);
|
|
78
|
+
return key === shortcut.key && Boolean(event.ctrlKey) === wantCtrl && Boolean(event.metaKey) === wantMeta && Boolean(event.shiftKey) === Boolean(shortcut.shift) && Boolean(event.altKey) === Boolean(shortcut.alt);
|
|
79
|
+
}
|
|
80
|
+
function shortcutTokens(spec, apple = isApplePlatform()) {
|
|
81
|
+
const shortcut = parseShortcut(spec);
|
|
82
|
+
const tokens = [];
|
|
83
|
+
if (shortcut.ctrl || shortcut.mod && !apple) tokens.push(apple ? "\u2303" : "Ctrl");
|
|
84
|
+
if (shortcut.alt) tokens.push(apple ? "\u2325" : "Alt");
|
|
85
|
+
if (shortcut.shift) tokens.push(apple ? "\u21E7" : "Shift");
|
|
86
|
+
if (shortcut.meta || shortcut.mod && apple) tokens.push(apple ? "\u2318" : "Win");
|
|
87
|
+
tokens.push(keyLabel(shortcut.key, apple));
|
|
88
|
+
return tokens;
|
|
89
|
+
}
|
|
90
|
+
function shortcutText(spec, apple = isApplePlatform()) {
|
|
91
|
+
return shortcutTokens(spec, apple).join(apple ? "" : "+");
|
|
92
|
+
}
|
|
93
|
+
var KEY_LABELS = {
|
|
94
|
+
" ": "Space",
|
|
95
|
+
escape: "Esc",
|
|
96
|
+
enter: "Enter",
|
|
97
|
+
backspace: "Backspace",
|
|
98
|
+
delete: "Del",
|
|
99
|
+
arrowup: "\u2191",
|
|
100
|
+
arrowdown: "\u2193",
|
|
101
|
+
arrowleft: "\u2190",
|
|
102
|
+
arrowright: "\u2192",
|
|
103
|
+
pageup: "PgUp",
|
|
104
|
+
pagedown: "PgDn"
|
|
105
|
+
};
|
|
106
|
+
var APPLE_KEY_LABELS = {
|
|
107
|
+
delete: "\u2326",
|
|
108
|
+
backspace: "\u232B",
|
|
109
|
+
enter: "\u21A9",
|
|
110
|
+
escape: "esc"
|
|
111
|
+
};
|
|
112
|
+
function keyLabel(key, apple) {
|
|
113
|
+
if (apple && APPLE_KEY_LABELS[key]) return APPLE_KEY_LABELS[key];
|
|
114
|
+
const named = KEY_LABELS[key];
|
|
115
|
+
if (named) return named;
|
|
116
|
+
return key.length === 1 ? key.toUpperCase() : key.charAt(0).toUpperCase() + key.slice(1);
|
|
117
|
+
}
|
|
118
|
+
var TYPEAHEAD_MS = 600;
|
|
119
|
+
function typeaheadStep(state, character, now = Date.now(), windowMs = TYPEAHEAD_MS) {
|
|
120
|
+
const typed = now - state.at > windowMs ? character : state.typed + character;
|
|
121
|
+
const repeated = typed.length > 1 && [...typed].every((letter) => letter === typed[0]);
|
|
122
|
+
return {
|
|
123
|
+
typed,
|
|
124
|
+
at: now,
|
|
125
|
+
needle: repeated ? typed[0] : typed,
|
|
126
|
+
cycle: typed.length === 1 || repeated
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export { TYPEAHEAD_MS, isApplePlatform, matchesShortcut, parseShortcut, shortcutList, shortcutText, shortcutTokens, typeaheadStep };
|
|
@@ -61,6 +61,11 @@ function subsequenceScore(query, text) {
|
|
|
61
61
|
}
|
|
62
62
|
return score;
|
|
63
63
|
}
|
|
64
|
+
function shortenQuery(query, max = 32) {
|
|
65
|
+
const trimmed = query.trim();
|
|
66
|
+
if (trimmed.length <= max) return trimmed;
|
|
67
|
+
return `${trimmed.slice(0, max - 1).trimEnd()}\u2026`;
|
|
68
|
+
}
|
|
64
69
|
function createSearch(options = {}) {
|
|
65
70
|
let opts = { ...options };
|
|
66
71
|
let items = opts.items ?? [];
|
|
@@ -175,4 +180,4 @@ function createSearch(options = {}) {
|
|
|
175
180
|
};
|
|
176
181
|
}
|
|
177
182
|
|
|
178
|
-
export { createSearch, subsequenceMatcher };
|
|
183
|
+
export { createSearch, shortenQuery, subsequenceMatcher };
|