@ucdjs-internal/shared-ui 0.1.4 → 0.1.6
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/index.d.mts +3 -0
- package/dist/components/index.mjs +4 -0
- package/dist/components/shiki-code.d.mts +1 -1
- package/dist/components/shiki-code.mjs +3 -1
- package/dist/components/theme-toggle.d.mts +2 -1
- package/dist/components/theme-toggle.mjs +23 -2
- package/dist/hooks/index.d.mts +2 -1
- package/dist/hooks/index.mjs +2 -1
- package/dist/hooks/use-clipboard.d.mts +28 -0
- package/dist/hooks/use-clipboard.mjs +62 -0
- package/dist/hooks/use-theme.mjs +5 -5
- package/dist/ui/alert-dialog.mjs +0 -1
- package/dist/ui/avatar.mjs +0 -1
- package/dist/ui/badge.d.mts +1 -1
- package/dist/ui/breadcrumb.mjs +0 -1
- package/dist/ui/button.d.mts +1 -1
- package/dist/ui/card.mjs +0 -1
- package/dist/ui/command.d.mts +8 -8
- package/dist/ui/command.mjs +8 -9
- package/dist/ui/context-menu.mjs +0 -1
- package/dist/ui/dialog.mjs +0 -1
- package/dist/ui/dropdown-menu.mjs +0 -1
- package/dist/ui/field.d.mts +1 -1
- package/dist/ui/input-group.mjs +0 -1
- package/dist/ui/input.mjs +0 -1
- package/dist/ui/label.mjs +0 -1
- package/dist/ui/scroll-area.mjs +0 -1
- package/dist/ui/select.mjs +0 -1
- package/dist/ui/sheet.mjs +0 -1
- package/dist/ui/table.mjs +0 -1
- package/dist/ui/textarea.mjs +0 -1
- package/dist/vendor/cmdk/command-score.mjs +62 -0
- package/dist/vendor/cmdk/index.d.mts +181 -0
- package/dist/vendor/cmdk/index.mjs +713 -0
- package/dist/vscode/syntaxes/ucd.tmLanguage.mjs +43 -0
- package/package.json +16 -16
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import ucd_tmLanguage_default from "../vscode/syntaxes/ucd.tmLanguage.mjs";
|
|
1
2
|
import { use, useMemo } from "react";
|
|
2
3
|
import { createJavaScriptRegexEngine } from "shiki";
|
|
3
4
|
import { createCssVariablesTheme, createHighlighterCore } from "shiki/core";
|
|
@@ -12,7 +13,8 @@ const highlighterPromise = createHighlighterCore({
|
|
|
12
13
|
langs: [
|
|
13
14
|
import("shiki/langs/javascript.mjs"),
|
|
14
15
|
import("shiki/langs/typescript.mjs"),
|
|
15
|
-
import("shiki/langs/json.mjs")
|
|
16
|
+
import("shiki/langs/json.mjs"),
|
|
17
|
+
ucd_tmLanguage_default
|
|
16
18
|
],
|
|
17
19
|
engine: createJavaScriptRegexEngine()
|
|
18
20
|
});
|
|
@@ -2,5 +2,6 @@ import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
|
2
2
|
|
|
3
3
|
//#region src/components/theme-toggle.d.ts
|
|
4
4
|
declare function ThemeToggle(): react_jsx_runtime0.JSX.Element;
|
|
5
|
+
declare function ThemeToggleFallback(): react_jsx_runtime0.JSX.Element;
|
|
5
6
|
//#endregion
|
|
6
|
-
export { ThemeToggle };
|
|
7
|
+
export { ThemeToggle, ThemeToggleFallback };
|
|
@@ -22,7 +22,10 @@ function ThemeToggle() {
|
|
|
22
22
|
size: "icon",
|
|
23
23
|
className: "h-7 w-7",
|
|
24
24
|
...props,
|
|
25
|
-
children: [/* @__PURE__ */ jsx(Icon, {
|
|
25
|
+
children: [/* @__PURE__ */ jsx(Icon, {
|
|
26
|
+
className: "h-4 w-4",
|
|
27
|
+
suppressHydrationWarning: true
|
|
28
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
26
29
|
className: "sr-only",
|
|
27
30
|
children: "Toggle theme"
|
|
28
31
|
})]
|
|
@@ -70,6 +73,24 @@ function ThemeToggle() {
|
|
|
70
73
|
} else t3 = $[8];
|
|
71
74
|
return t3;
|
|
72
75
|
}
|
|
76
|
+
function ThemeToggleFallback() {
|
|
77
|
+
const $ = c(1);
|
|
78
|
+
let t0;
|
|
79
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
80
|
+
t0 = /* @__PURE__ */ jsx(Button, {
|
|
81
|
+
variant: "ghost",
|
|
82
|
+
size: "icon",
|
|
83
|
+
className: "h-7 w-7",
|
|
84
|
+
disabled: true,
|
|
85
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
86
|
+
className: "sr-only",
|
|
87
|
+
children: "Toggle theme"
|
|
88
|
+
})
|
|
89
|
+
});
|
|
90
|
+
$[0] = t0;
|
|
91
|
+
} else t0 = $[0];
|
|
92
|
+
return t0;
|
|
93
|
+
}
|
|
73
94
|
|
|
74
95
|
//#endregion
|
|
75
|
-
export { ThemeToggle };
|
|
96
|
+
export { ThemeToggle, ThemeToggleFallback };
|
package/dist/hooks/index.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useClipboard } from "./use-clipboard.mjs";
|
|
1
2
|
import { useIsMobile } from "./use-mobile.mjs";
|
|
2
3
|
import { ThemeMode, UseThemeReturn, useTheme } from "./use-theme.mjs";
|
|
3
|
-
export { type ThemeMode, type UseThemeReturn, useIsMobile, useTheme };
|
|
4
|
+
export { type ThemeMode, type UseThemeReturn, useClipboard, useIsMobile, useTheme };
|
package/dist/hooks/index.mjs
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/hooks/use-clipboard.d.ts
|
|
2
|
+
interface UseClipboardOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Time in ms after which the copied state will reset, `2000` by default
|
|
5
|
+
*/
|
|
6
|
+
timeout?: number;
|
|
7
|
+
}
|
|
8
|
+
interface UseClipboardReturnValue {
|
|
9
|
+
/**
|
|
10
|
+
* Function to copy value to clipboard
|
|
11
|
+
*/
|
|
12
|
+
copy: (value: unknown) => void;
|
|
13
|
+
/**
|
|
14
|
+
* Function to reset copied state and error
|
|
15
|
+
*/
|
|
16
|
+
reset: () => void;
|
|
17
|
+
/**
|
|
18
|
+
* Error if copying failed
|
|
19
|
+
*/
|
|
20
|
+
error: Error | null;
|
|
21
|
+
/**
|
|
22
|
+
* Boolean indicating if the value was copied successfully
|
|
23
|
+
*/
|
|
24
|
+
copied: boolean;
|
|
25
|
+
}
|
|
26
|
+
declare function useClipboard(options?: UseClipboardOptions): UseClipboardReturnValue;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { useClipboard };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { c } from "react/compiler-runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/hooks/use-clipboard.ts
|
|
5
|
+
function useClipboard(t0) {
|
|
6
|
+
const $ = c(12);
|
|
7
|
+
let t1;
|
|
8
|
+
if ($[0] !== t0) {
|
|
9
|
+
t1 = t0 === void 0 ? { timeout: 2e3 } : t0;
|
|
10
|
+
$[0] = t0;
|
|
11
|
+
$[1] = t1;
|
|
12
|
+
} else t1 = $[1];
|
|
13
|
+
const options = t1;
|
|
14
|
+
const [error, setError] = useState(null);
|
|
15
|
+
const [copied, setCopied] = useState(false);
|
|
16
|
+
const [copyTimeout, setCopyTimeout] = useState(null);
|
|
17
|
+
let t2;
|
|
18
|
+
if ($[2] !== copyTimeout || $[3] !== options) {
|
|
19
|
+
const handleCopyResult = (value) => {
|
|
20
|
+
window.clearTimeout(copyTimeout);
|
|
21
|
+
setCopyTimeout(window.setTimeout(() => setCopied(false), options.timeout));
|
|
22
|
+
setCopied(value);
|
|
23
|
+
};
|
|
24
|
+
t2 = (value_0) => {
|
|
25
|
+
if ("clipboard" in navigator) navigator.clipboard.writeText(value_0).then(() => handleCopyResult(true)).catch((err) => setError(err));
|
|
26
|
+
else setError(/* @__PURE__ */ new Error("useClipboard: navigator.clipboard is not supported"));
|
|
27
|
+
};
|
|
28
|
+
$[2] = copyTimeout;
|
|
29
|
+
$[3] = options;
|
|
30
|
+
$[4] = t2;
|
|
31
|
+
} else t2 = $[4];
|
|
32
|
+
const copy = t2;
|
|
33
|
+
let t3;
|
|
34
|
+
if ($[5] !== copyTimeout) {
|
|
35
|
+
t3 = () => {
|
|
36
|
+
setCopied(false);
|
|
37
|
+
setError(null);
|
|
38
|
+
window.clearTimeout(copyTimeout);
|
|
39
|
+
};
|
|
40
|
+
$[5] = copyTimeout;
|
|
41
|
+
$[6] = t3;
|
|
42
|
+
} else t3 = $[6];
|
|
43
|
+
const reset = t3;
|
|
44
|
+
let t4;
|
|
45
|
+
if ($[7] !== copied || $[8] !== copy || $[9] !== error || $[10] !== reset) {
|
|
46
|
+
t4 = {
|
|
47
|
+
copy,
|
|
48
|
+
reset,
|
|
49
|
+
error,
|
|
50
|
+
copied
|
|
51
|
+
};
|
|
52
|
+
$[7] = copied;
|
|
53
|
+
$[8] = copy;
|
|
54
|
+
$[9] = error;
|
|
55
|
+
$[10] = reset;
|
|
56
|
+
$[11] = t4;
|
|
57
|
+
} else t4 = $[11];
|
|
58
|
+
return t4;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
export { useClipboard };
|
package/dist/hooks/use-theme.mjs
CHANGED
|
@@ -21,7 +21,7 @@ function syncTheme(resolved) {
|
|
|
21
21
|
}
|
|
22
22
|
function useTheme() {
|
|
23
23
|
const $ = c(11);
|
|
24
|
-
const [theme,
|
|
24
|
+
const [theme, setTheme] = useState(_temp);
|
|
25
25
|
const [systemTheme, setSystemTheme] = useState(_temp2);
|
|
26
26
|
const resolvedTheme = theme === "system" ? systemTheme : theme;
|
|
27
27
|
let t0;
|
|
@@ -62,15 +62,15 @@ function useTheme() {
|
|
|
62
62
|
let t4;
|
|
63
63
|
if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
|
|
64
64
|
t4 = (nextTheme) => {
|
|
65
|
-
|
|
65
|
+
setTheme(nextTheme);
|
|
66
66
|
};
|
|
67
67
|
$[6] = t4;
|
|
68
68
|
} else t4 = $[6];
|
|
69
|
-
const
|
|
69
|
+
const setThemeCb = t4;
|
|
70
70
|
let t5;
|
|
71
71
|
if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
|
|
72
72
|
t5 = () => {
|
|
73
|
-
|
|
73
|
+
setTheme(_temp3);
|
|
74
74
|
};
|
|
75
75
|
$[7] = t5;
|
|
76
76
|
} else t5 = $[7];
|
|
@@ -80,7 +80,7 @@ function useTheme() {
|
|
|
80
80
|
t6 = {
|
|
81
81
|
theme,
|
|
82
82
|
resolvedTheme,
|
|
83
|
-
setTheme,
|
|
83
|
+
setTheme: setThemeCb,
|
|
84
84
|
toggleTheme
|
|
85
85
|
};
|
|
86
86
|
$[8] = resolvedTheme;
|
package/dist/ui/alert-dialog.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { cn } from "../lib/utils.mjs";
|
|
2
2
|
import { Button } from "./button.mjs";
|
|
3
|
-
import "react";
|
|
4
3
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
4
|
import { c } from "react/compiler-runtime";
|
|
6
5
|
import { AlertDialog as AlertDialog$1 } from "@base-ui/react/alert-dialog";
|
package/dist/ui/avatar.mjs
CHANGED
package/dist/ui/badge.d.mts
CHANGED
|
@@ -5,7 +5,7 @@ import * as class_variance_authority_types0 from "class-variance-authority/types
|
|
|
5
5
|
|
|
6
6
|
//#region src/ui/badge.d.ts
|
|
7
7
|
declare const badgeVariants: (props?: ({
|
|
8
|
-
variant?: "
|
|
8
|
+
variant?: "default" | "secondary" | "destructive" | "outline" | "ghost" | "link" | null | undefined;
|
|
9
9
|
} & class_variance_authority_types0.ClassProp) | undefined) => string;
|
|
10
10
|
declare function Badge({
|
|
11
11
|
className,
|
package/dist/ui/breadcrumb.mjs
CHANGED
package/dist/ui/button.d.mts
CHANGED
|
@@ -5,7 +5,7 @@ import * as class_variance_authority_types0 from "class-variance-authority/types
|
|
|
5
5
|
|
|
6
6
|
//#region src/ui/button.d.ts
|
|
7
7
|
declare const buttonVariants: (props?: ({
|
|
8
|
-
variant?: "
|
|
8
|
+
variant?: "default" | "secondary" | "destructive" | "outline" | "ghost" | "link" | null | undefined;
|
|
9
9
|
size?: "xs" | "sm" | "icon-xs" | "icon-sm" | "default" | "lg" | "icon" | "icon-lg" | null | undefined;
|
|
10
10
|
} & class_variance_authority_types0.ClassProp) | undefined) => string;
|
|
11
11
|
declare function Button({
|
package/dist/ui/card.mjs
CHANGED
package/dist/ui/command.d.mts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Dialog } from "./dialog.mjs";
|
|
2
|
+
import { pkg } from "../vendor/cmdk/index.mjs";
|
|
2
3
|
import * as React from "react";
|
|
3
4
|
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
4
|
-
import { Command as Command$1 } from "cmdk";
|
|
5
5
|
|
|
6
6
|
//#region src/ui/command.d.ts
|
|
7
7
|
declare function Command({
|
|
8
8
|
className,
|
|
9
9
|
...props
|
|
10
|
-
}: React.ComponentProps<typeof
|
|
10
|
+
}: React.ComponentProps<typeof pkg>): react_jsx_runtime0.JSX.Element;
|
|
11
11
|
declare function CommandDialog({
|
|
12
12
|
title,
|
|
13
13
|
description,
|
|
@@ -25,28 +25,28 @@ declare function CommandDialog({
|
|
|
25
25
|
declare function CommandInput({
|
|
26
26
|
className,
|
|
27
27
|
...props
|
|
28
|
-
}: React.ComponentProps<typeof
|
|
28
|
+
}: React.ComponentProps<typeof pkg.Input>): react_jsx_runtime0.JSX.Element;
|
|
29
29
|
declare function CommandList({
|
|
30
30
|
className,
|
|
31
31
|
...props
|
|
32
|
-
}: React.ComponentProps<typeof
|
|
32
|
+
}: React.ComponentProps<typeof pkg.List>): react_jsx_runtime0.JSX.Element;
|
|
33
33
|
declare function CommandEmpty({
|
|
34
34
|
className,
|
|
35
35
|
...props
|
|
36
|
-
}: React.ComponentProps<typeof
|
|
36
|
+
}: React.ComponentProps<typeof pkg.Empty>): react_jsx_runtime0.JSX.Element;
|
|
37
37
|
declare function CommandGroup({
|
|
38
38
|
className,
|
|
39
39
|
...props
|
|
40
|
-
}: React.ComponentProps<typeof
|
|
40
|
+
}: React.ComponentProps<typeof pkg.Group>): react_jsx_runtime0.JSX.Element;
|
|
41
41
|
declare function CommandSeparator({
|
|
42
42
|
className,
|
|
43
43
|
...props
|
|
44
|
-
}: React.ComponentProps<typeof
|
|
44
|
+
}: React.ComponentProps<typeof pkg.Separator>): react_jsx_runtime0.JSX.Element;
|
|
45
45
|
declare function CommandItem({
|
|
46
46
|
className,
|
|
47
47
|
children,
|
|
48
48
|
...props
|
|
49
|
-
}: React.ComponentProps<typeof
|
|
49
|
+
}: React.ComponentProps<typeof pkg.Item>): react_jsx_runtime0.JSX.Element;
|
|
50
50
|
declare function CommandShortcut({
|
|
51
51
|
className,
|
|
52
52
|
...props
|
package/dist/ui/command.mjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { cn } from "../lib/utils.mjs";
|
|
2
2
|
import { InputGroup, InputGroupAddon } from "./input-group.mjs";
|
|
3
3
|
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "./dialog.mjs";
|
|
4
|
-
import "
|
|
4
|
+
import { pkg } from "../vendor/cmdk/index.mjs";
|
|
5
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
6
|
import { c } from "react/compiler-runtime";
|
|
7
7
|
import { CheckIcon, SearchIcon } from "lucide-react";
|
|
8
|
-
import { Command as Command$1 } from "cmdk";
|
|
9
8
|
|
|
10
9
|
//#region src/ui/command.tsx
|
|
11
10
|
function Command(t0) {
|
|
@@ -29,7 +28,7 @@ function Command(t0) {
|
|
|
29
28
|
} else t1 = $[4];
|
|
30
29
|
let t2;
|
|
31
30
|
if ($[5] !== props || $[6] !== t1) {
|
|
32
|
-
t2 = /* @__PURE__ */ jsx(
|
|
31
|
+
t2 = /* @__PURE__ */ jsx(pkg, {
|
|
33
32
|
"data-slot": "command",
|
|
34
33
|
className: t1,
|
|
35
34
|
...props
|
|
@@ -142,7 +141,7 @@ function CommandInput(t0) {
|
|
|
142
141
|
} else t1 = $[4];
|
|
143
142
|
let t2;
|
|
144
143
|
if ($[5] !== props || $[6] !== t1) {
|
|
145
|
-
t2 = /* @__PURE__ */ jsx(
|
|
144
|
+
t2 = /* @__PURE__ */ jsx(pkg.Input, {
|
|
146
145
|
"data-slot": "command-input",
|
|
147
146
|
className: t1,
|
|
148
147
|
...props
|
|
@@ -192,7 +191,7 @@ function CommandList(t0) {
|
|
|
192
191
|
} else t1 = $[4];
|
|
193
192
|
let t2;
|
|
194
193
|
if ($[5] !== props || $[6] !== t1) {
|
|
195
|
-
t2 = /* @__PURE__ */ jsx(
|
|
194
|
+
t2 = /* @__PURE__ */ jsx(pkg.List, {
|
|
196
195
|
"data-slot": "command-list",
|
|
197
196
|
className: t1,
|
|
198
197
|
...props
|
|
@@ -224,7 +223,7 @@ function CommandEmpty(t0) {
|
|
|
224
223
|
} else t1 = $[4];
|
|
225
224
|
let t2;
|
|
226
225
|
if ($[5] !== props || $[6] !== t1) {
|
|
227
|
-
t2 = /* @__PURE__ */ jsx(
|
|
226
|
+
t2 = /* @__PURE__ */ jsx(pkg.Empty, {
|
|
228
227
|
"data-slot": "command-empty",
|
|
229
228
|
className: t1,
|
|
230
229
|
...props
|
|
@@ -256,7 +255,7 @@ function CommandGroup(t0) {
|
|
|
256
255
|
} else t1 = $[4];
|
|
257
256
|
let t2;
|
|
258
257
|
if ($[5] !== props || $[6] !== t1) {
|
|
259
|
-
t2 = /* @__PURE__ */ jsx(
|
|
258
|
+
t2 = /* @__PURE__ */ jsx(pkg.Group, {
|
|
260
259
|
"data-slot": "command-group",
|
|
261
260
|
className: t1,
|
|
262
261
|
...props
|
|
@@ -288,7 +287,7 @@ function CommandSeparator(t0) {
|
|
|
288
287
|
} else t1 = $[4];
|
|
289
288
|
let t2;
|
|
290
289
|
if ($[5] !== props || $[6] !== t1) {
|
|
291
|
-
t2 = /* @__PURE__ */ jsx(
|
|
290
|
+
t2 = /* @__PURE__ */ jsx(pkg.Separator, {
|
|
292
291
|
"data-slot": "command-separator",
|
|
293
292
|
className: t1,
|
|
294
293
|
...props
|
|
@@ -328,7 +327,7 @@ function CommandItem(t0) {
|
|
|
328
327
|
} else t2 = $[6];
|
|
329
328
|
let t3;
|
|
330
329
|
if ($[7] !== children || $[8] !== props || $[9] !== t1) {
|
|
331
|
-
t3 = /* @__PURE__ */ jsxs(
|
|
330
|
+
t3 = /* @__PURE__ */ jsxs(pkg.Item, {
|
|
332
331
|
"data-slot": "command-item",
|
|
333
332
|
className: t1,
|
|
334
333
|
...props,
|
package/dist/ui/context-menu.mjs
CHANGED
package/dist/ui/dialog.mjs
CHANGED
package/dist/ui/field.d.mts
CHANGED
|
@@ -20,7 +20,7 @@ declare function FieldGroup({
|
|
|
20
20
|
...props
|
|
21
21
|
}: React.ComponentProps<"div">): react_jsx_runtime0.JSX.Element;
|
|
22
22
|
declare const fieldVariants: (props?: ({
|
|
23
|
-
orientation?: "
|
|
23
|
+
orientation?: "horizontal" | "vertical" | "responsive" | null | undefined;
|
|
24
24
|
} & class_variance_authority_types0.ClassProp) | undefined) => string;
|
|
25
25
|
declare function Field({
|
|
26
26
|
className,
|
package/dist/ui/input-group.mjs
CHANGED
|
@@ -2,7 +2,6 @@ import { cn } from "../lib/utils.mjs";
|
|
|
2
2
|
import { Button } from "./button.mjs";
|
|
3
3
|
import { Input } from "./input.mjs";
|
|
4
4
|
import { Textarea } from "./textarea.mjs";
|
|
5
|
-
import "react";
|
|
6
5
|
import { jsx } from "react/jsx-runtime";
|
|
7
6
|
import { c } from "react/compiler-runtime";
|
|
8
7
|
import { cva } from "class-variance-authority";
|
package/dist/ui/input.mjs
CHANGED
package/dist/ui/label.mjs
CHANGED
package/dist/ui/scroll-area.mjs
CHANGED
package/dist/ui/select.mjs
CHANGED
package/dist/ui/sheet.mjs
CHANGED
package/dist/ui/table.mjs
CHANGED
package/dist/ui/textarea.mjs
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
//#region src/vendor/cmdk/command-score.ts
|
|
2
|
+
const SCORE_CONTINUE_MATCH = 1;
|
|
3
|
+
const SCORE_SPACE_WORD_JUMP = .9;
|
|
4
|
+
const SCORE_NON_SPACE_WORD_JUMP = .8;
|
|
5
|
+
const SCORE_CHARACTER_JUMP = .17;
|
|
6
|
+
const SCORE_TRANSPOSITION = .1;
|
|
7
|
+
const PENALTY_SKIPPED = .999;
|
|
8
|
+
const PENALTY_CASE_MISMATCH = .9999;
|
|
9
|
+
const PENALTY_NOT_COMPLETE = .99;
|
|
10
|
+
const IS_GAP_REGEXP = /[\\/_+.#"@[({&]/;
|
|
11
|
+
const COUNT_GAPS_REGEXP = /[\\/_+.#"@[({&]/g;
|
|
12
|
+
const IS_SPACE_REGEXP = /[\s-]/;
|
|
13
|
+
const COUNT_SPACE_REGEXP = /[\s-]/g;
|
|
14
|
+
function commandScoreInner(value, abbreviation, lowerString, lowerAbbreviation, stringIndex, abbreviationIndex, memoizedResults) {
|
|
15
|
+
if (abbreviationIndex === abbreviation.length) {
|
|
16
|
+
if (stringIndex === value.length) return SCORE_CONTINUE_MATCH;
|
|
17
|
+
return PENALTY_NOT_COMPLETE;
|
|
18
|
+
}
|
|
19
|
+
const memoizeKey = `${stringIndex},${abbreviationIndex}`;
|
|
20
|
+
if (memoizedResults[memoizeKey] !== void 0) return memoizedResults[memoizeKey];
|
|
21
|
+
const abbreviationChar = lowerAbbreviation.charAt(abbreviationIndex);
|
|
22
|
+
let index = lowerString.indexOf(abbreviationChar, stringIndex);
|
|
23
|
+
let highScore = 0;
|
|
24
|
+
let score, transposedScore, wordBreaks, spaceBreaks;
|
|
25
|
+
while (index >= 0) {
|
|
26
|
+
score = commandScoreInner(value, abbreviation, lowerString, lowerAbbreviation, index + 1, abbreviationIndex + 1, memoizedResults);
|
|
27
|
+
if (score > highScore) {
|
|
28
|
+
if (index === stringIndex) score *= SCORE_CONTINUE_MATCH;
|
|
29
|
+
else if (IS_GAP_REGEXP.test(value.charAt(index - 1))) {
|
|
30
|
+
score *= SCORE_NON_SPACE_WORD_JUMP;
|
|
31
|
+
wordBreaks = value.slice(stringIndex, index - 1).match(COUNT_GAPS_REGEXP);
|
|
32
|
+
if (wordBreaks && stringIndex > 0) score *= PENALTY_SKIPPED ** wordBreaks.length;
|
|
33
|
+
} else if (IS_SPACE_REGEXP.test(value.charAt(index - 1))) {
|
|
34
|
+
score *= SCORE_SPACE_WORD_JUMP;
|
|
35
|
+
spaceBreaks = value.slice(stringIndex, index - 1).match(COUNT_SPACE_REGEXP);
|
|
36
|
+
if (spaceBreaks && stringIndex > 0) score *= PENALTY_SKIPPED ** spaceBreaks.length;
|
|
37
|
+
} else {
|
|
38
|
+
score *= SCORE_CHARACTER_JUMP;
|
|
39
|
+
if (stringIndex > 0) score *= PENALTY_SKIPPED ** (index - stringIndex);
|
|
40
|
+
}
|
|
41
|
+
if (value.charAt(index) !== abbreviation.charAt(abbreviationIndex)) score *= PENALTY_CASE_MISMATCH;
|
|
42
|
+
}
|
|
43
|
+
if (score < SCORE_TRANSPOSITION && lowerString.charAt(index - 1) === lowerAbbreviation.charAt(abbreviationIndex + 1) || lowerAbbreviation.charAt(abbreviationIndex + 1) === lowerAbbreviation.charAt(abbreviationIndex) && lowerString.charAt(index - 1) !== lowerAbbreviation.charAt(abbreviationIndex)) {
|
|
44
|
+
transposedScore = commandScoreInner(value, abbreviation, lowerString, lowerAbbreviation, index + 1, abbreviationIndex + 2, memoizedResults);
|
|
45
|
+
if (transposedScore * SCORE_TRANSPOSITION > score) score = transposedScore * SCORE_TRANSPOSITION;
|
|
46
|
+
}
|
|
47
|
+
if (score > highScore) highScore = score;
|
|
48
|
+
index = lowerString.indexOf(abbreviationChar, index + 1);
|
|
49
|
+
}
|
|
50
|
+
memoizedResults[memoizeKey] = highScore;
|
|
51
|
+
return highScore;
|
|
52
|
+
}
|
|
53
|
+
function formatInput(value) {
|
|
54
|
+
return value.toLowerCase().replace(COUNT_SPACE_REGEXP, " ");
|
|
55
|
+
}
|
|
56
|
+
function commandScore(string, abbreviation, aliases) {
|
|
57
|
+
string = aliases && aliases.length > 0 ? `${`${string} ${aliases.join(" ")}`}` : string;
|
|
58
|
+
return commandScoreInner(string, abbreviation, formatInput(string), formatInput(abbreviation), 0, 0, {});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
export { commandScore };
|