@kakadu/components 4.2.3 → 4.3.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/build/components/combobox.js +1 -1
- package/build/components/combobox.mjs +145 -273
- package/build/index.d.ts +2 -0
- package/build/index.js +1 -1
- package/build/index.mjs +2 -0
- package/build/utilities/search.d.ts +10 -0
- package/build/utilities/search.js +1 -0
- package/build/utilities/search.mjs +228 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("../jsx-runtime-BB_1_6y_.js"),e=require("react"),K=require("@kuma-ui/core"),te=require("../hooks/use-synchronized-value.js"),se=require("../icons/icon.js"),ne=require("../icons/chevron-up.js"),oe=require("../utilities/search.js"),re=require("./input.js"),B=require("./text.js"),U=require("./flex.js"),ae=require("./skeleton.js");function X(){const{value:o,setValue:p}=te.default("isKeyboardNavigating");return e.useMemo(()=>({isKeyboardNavigating:o,setIsKeyboardNavigating:p}),[o,p])}function _(o){return"text"in o?o.text:o.label}const D="kakadu-components-1144794361",F="kakadu-components-2911184744";function ue({isSelected:o,id:p,value:i,label:k,onSelect:v,onHover:E}){const{isKeyboardNavigating:f}=X(),j=e.useCallback(()=>{v(i)},[v,i]),n=e.useCallback(b=>{f||b.movementX===0&&b.movementY===0||E(i)},[f,E,i]),x=e.useRef(null);return e.useEffect(()=>{const b=x.current;o&&b&&f&&setTimeout(()=>{b.scrollIntoView({behavior:"smooth",block:"nearest"})},0)},[o,f]),c.jsxRuntimeExports.jsx("li",{ref:x,id:p,role:"option","aria-selected":o,tabIndex:-1,className:K.cx(D,"kakadu-components-4130497639",f?"kakadu-components-962373561":"kakadu-components-1109598791"),onClick:j,onMouseMove:n,children:c.jsxRuntimeExports.jsx(B.Span,{className:K.cx(F,typeof k=="string"&&"kakadu-components-154286052"),children:k})})}function ce({isLoading:o,id:p,activeOptionId:i,selectedValue:k,options:v,onSelect:E,onHover:f}){const j=e.useRef(null);return e.useEffect(()=>{const n=j.current;n&&n.scrollIntoView({behavior:"smooth",block:"nearest"})},[]),c.jsxRuntimeExports.jsxs("ul",{ref:j,id:p,role:"listbox","aria-label":"Options",tabIndex:-1,className:"kakadu-components-1951042708",children:[v.length===0?o?null:c.jsxRuntimeExports.jsxs(U.default,{"aria-atomic":!0,as:"li",role:"status","aria-live":"polite",direction:"row",preset:"start",gap:.5,className:D,children:[c.jsxRuntimeExports.jsx(se.default,{size:15,type:"exclamationTriangle"}),c.jsxRuntimeExports.jsx(B.Span,{className:F,children:"No results."})]}):v.map((n,x)=>c.jsxRuntimeExports.jsx(ue,{...n,id:n.value===k?i:void 0,isSelected:n.value===k,onSelect:E,onHover:f},_(n)+x)),o?c.jsxRuntimeExports.jsx(U.default,{as:"li",alignment:"center",className:D,children:c.jsxRuntimeExports.jsx(B.Span,{className:F,children:c.jsxRuntimeExports.jsx(ae.SkeletonInstance,{width:"100%",height:"1.3em"})})}):null]})}function ie({isLoading:o,label:p,options:i,error:k,warning:v,information:E,footnote:f,className:j,onChange:n,onSelect:x,...b}){const O=e.useRef(null),T=e.useId(),H=e.useId(),[g,M]=e.useState(!1),Y=e.useCallback(()=>{M(!0)},[]),$=e.useCallback(t=>{var s;(s=O.current)!=null&&s.contains(t.relatedTarget)||M(!1)},[]),[I,a]=e.useState(!1);e.useEffect(()=>{a(g)},[g]);const[P,V]=e.useState(""),{value:R}=b,[d,y]=e.useState(R),[S,G]=e.useState(R),A=e.useRef(S),u=e.useCallback(t=>{G(t),A.current=t},[]);e.useEffect(()=>{y(R),u(R)},[R,u]);const J=e.useCallback(()=>{d&&(V(""),u(void 0))},[d,u]),Q=e.useCallback((t,s)=>{V(t),n==null||n(t,s),a(!0),y(void 0)},[n]),W=e.useCallback(t=>{var s;(s=O.current)!=null&&s.contains(t.target)&&a(!0)},[]),h=e.useCallback(t=>{const s=t==null?void 0:t.value;u(s),t?V(_(t)):(V(""),n==null||n("")),x==null||x(s)},[u,n,x]),Z=e.useCallback(t=>{const s=i.find(m=>m.value===t);h(s),y(t),a(!1)},[i,h]),ee=e.useCallback(t=>{u(t)},[u]),q=e.useDeferredValue(P),l=e.useMemo(()=>d?i:oe.default(q,i,_),[d,i,q]);e.useEffect(()=>{!d&&q.length>0&&l.length>0&&!l.some(t=>S===t.value)&&u(l[0].value)},[d,q,l,S,u]);const{setIsKeyboardNavigating:N}=X();return e.useEffect(()=>{if(!g)return;const t=s=>{s.movementX===0&&s.movementY===0||N(!1)};return window.addEventListener("mousemove",t,{capture:!0}),()=>{window.removeEventListener("mousemove",t,{capture:!0})}},[g,N]),e.useEffect(()=>{if(!g)return;const t=s=>{var z;let m;const C=l.length,L=l.findIndex(r=>r.value===A.current),w=()=>{s.preventDefault(),s.stopPropagation(),s.stopImmediatePropagation()};switch(s.key){case"Enter":{const r=l[L];r&&(w(),N(!0),a(!1),h(r),y(r.value));break}case"Escape":{if(I)w(),d?u(void 0):h(void 0),a(!1);else if(d)w(),a(!0),h(void 0);else{w(),M(!1);const r=document.activeElement;r instanceof HTMLElement&&((z=O.current)!=null&&z.contains(r))&&r.blur()}return}case"ArrowDown":{m=L+1,a(!0);break}case"ArrowUp":{m=L-1,a(!0),m<0&&(m=C-1);break}case"Home":{a(!0),m=0;break}case"End":{a(!0),m=C-1;break}case"Backspace":{l.some(r=>r.value===d)&&(w(),h(void 0),a(!0));break}}if(m!==void 0&&(w(),N(!0),C>0)){const r=l[m%C];r&&u(r.value)}};return window.addEventListener("keydown",t,{capture:!0}),()=>{window.removeEventListener("keydown",t,{capture:!0})}},[g,l,N,a,h,y,I,d,u]),c.jsxRuntimeExports.jsx(re.default,{...b,ref:O,role:"combobox",autoComplete:"off","aria-controls":T,"aria-expanded":I,"aria-activedescendant":I?H:void 0,label:p,value:P,error:k,warning:v,information:E,footnote:f,attachments:I?c.jsxRuntimeExports.jsx(ce,{isLoading:o,id:T,activeOptionId:H,selectedValue:S,options:l,onSelect:Z,onHover:ee}):null,className:K.cx(j,"kakadu-components-879486679"),onMouseDown:W,onChange:Q,onBeforeInput:J,onFocus:Y,onBlur:$,children:c.jsxRuntimeExports.jsx(ne.default,{width:14,height:14,className:"kakadu-components-158931186"})})}exports.default=ie;exports.getComboboxOptionString=_;
|
|
@@ -1,343 +1,215 @@
|
|
|
1
|
-
import { j as
|
|
2
|
-
import { useRef as
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import { Span as
|
|
10
|
-
import
|
|
11
|
-
import { SkeletonInstance as
|
|
12
|
-
|
|
13
|
-
const z = new Uint32Array(65536), we = (t, a) => {
|
|
14
|
-
const r = t.length, m = a.length, i = 1 << r - 1;
|
|
15
|
-
let c = -1, u = 0, g = r, n = r;
|
|
16
|
-
for (; n--; )
|
|
17
|
-
z[t.charCodeAt(n)] |= 1 << n;
|
|
18
|
-
for (n = 0; n < m; n++) {
|
|
19
|
-
let d = z[a.charCodeAt(n)];
|
|
20
|
-
const h = d | u;
|
|
21
|
-
d |= (d & c) + c ^ c, u |= ~(d | c), c &= d, u & i && g++, c & i && g--, u = u << 1 | 1, c = c << 1 | ~(h | u), u &= h;
|
|
22
|
-
}
|
|
23
|
-
for (n = r; n--; )
|
|
24
|
-
z[t.charCodeAt(n)] = 0;
|
|
25
|
-
return g;
|
|
26
|
-
}, ke = (t, a) => {
|
|
27
|
-
const r = a.length, m = t.length, i = [], c = [], u = Math.ceil(r / 32), g = Math.ceil(m / 32);
|
|
28
|
-
for (let e = 0; e < u; e++)
|
|
29
|
-
c[e] = -1, i[e] = 0;
|
|
30
|
-
let n = 0;
|
|
31
|
-
for (; n < g - 1; n++) {
|
|
32
|
-
let e = 0, l = -1;
|
|
33
|
-
const x = n * 32, b = Math.min(32, m) + x;
|
|
34
|
-
for (let s = x; s < b; s++)
|
|
35
|
-
z[t.charCodeAt(s)] |= 1 << s;
|
|
36
|
-
for (let s = 0; s < r; s++) {
|
|
37
|
-
const v = z[a.charCodeAt(s)], A = c[s / 32 | 0] >>> s & 1, w = i[s / 32 | 0] >>> s & 1, F = v | e, y = ((v | w) & l) + l ^ l | v | w;
|
|
38
|
-
let E = e | ~(y | l), S = l & y;
|
|
39
|
-
E >>> 31 ^ A && (c[s / 32 | 0] ^= 1 << s), S >>> 31 ^ w && (i[s / 32 | 0] ^= 1 << s), E = E << 1 | A, S = S << 1 | w, l = S | ~(F | E), e = E & F;
|
|
40
|
-
}
|
|
41
|
-
for (let s = x; s < b; s++)
|
|
42
|
-
z[t.charCodeAt(s)] = 0;
|
|
43
|
-
}
|
|
44
|
-
let d = 0, h = -1;
|
|
45
|
-
const k = n * 32, V = Math.min(32, m - k) + k;
|
|
46
|
-
for (let e = k; e < V; e++)
|
|
47
|
-
z[t.charCodeAt(e)] |= 1 << e;
|
|
48
|
-
let M = m;
|
|
49
|
-
for (let e = 0; e < r; e++) {
|
|
50
|
-
const l = z[a.charCodeAt(e)], x = c[e / 32 | 0] >>> e & 1, b = i[e / 32 | 0] >>> e & 1, s = l | d, v = ((l | b) & h) + h ^ h | l | b;
|
|
51
|
-
let A = d | ~(v | h), w = h & v;
|
|
52
|
-
M += A >>> m - 1 & 1, M -= w >>> m - 1 & 1, A >>> 31 ^ x && (c[e / 32 | 0] ^= 1 << e), w >>> 31 ^ b && (i[e / 32 | 0] ^= 1 << e), A = A << 1 | x, w = w << 1 | b, h = w | ~(s | A), d = A & s;
|
|
53
|
-
}
|
|
54
|
-
for (let e = k; e < V; e++)
|
|
55
|
-
z[t.charCodeAt(e)] = 0;
|
|
56
|
-
return M;
|
|
57
|
-
}, re = (t, a) => {
|
|
58
|
-
if (t.length < a.length) {
|
|
59
|
-
const r = a;
|
|
60
|
-
a = t, t = r;
|
|
61
|
-
}
|
|
62
|
-
return a.length === 0 ? t.length : t.length <= 32 ? we(t, a) : ke(t, a);
|
|
63
|
-
}, ye = (t, a) => {
|
|
64
|
-
let r = 1 / 0, m = 0;
|
|
65
|
-
for (let i = 0; i < a.length; i++) {
|
|
66
|
-
const c = re(t, a[i]);
|
|
67
|
-
c < r && (r = c, m = i);
|
|
68
|
-
}
|
|
69
|
-
return a[m];
|
|
70
|
-
}, Ie = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
71
|
-
__proto__: null,
|
|
72
|
-
closest: ye,
|
|
73
|
-
distance: re
|
|
74
|
-
}, Symbol.toStringTag, { value: "Module" })), Ne = /* @__PURE__ */ me(Ie);
|
|
75
|
-
var ee;
|
|
76
|
-
function Ve() {
|
|
77
|
-
return ee || (ee = 1, (function(t, a) {
|
|
78
|
-
(function() {
|
|
79
|
-
var r;
|
|
80
|
-
try {
|
|
81
|
-
r = typeof Intl < "u" && typeof Intl.Collator < "u" ? Intl.Collator("generic", { sensitivity: "base" }) : null;
|
|
82
|
-
} catch {
|
|
83
|
-
console.log("Collator could not be initialized and wouldn't be used");
|
|
84
|
-
}
|
|
85
|
-
var m = Ne, i = [], c = [], u = {
|
|
86
|
-
/**
|
|
87
|
-
* Calculate levenshtein distance of the two strings.
|
|
88
|
-
*
|
|
89
|
-
* @param str1 String the first string.
|
|
90
|
-
* @param str2 String the second string.
|
|
91
|
-
* @param [options] Additional options.
|
|
92
|
-
* @param [options.useCollator] Use `Intl.Collator` for locale-sensitive string comparison.
|
|
93
|
-
* @return Integer the levenshtein distance (0 and above).
|
|
94
|
-
*/
|
|
95
|
-
get: function(g, n, d) {
|
|
96
|
-
var h = d && r && d.useCollator;
|
|
97
|
-
if (h) {
|
|
98
|
-
var k = g.length, V = n.length;
|
|
99
|
-
if (k === 0) return V;
|
|
100
|
-
if (V === 0) return k;
|
|
101
|
-
var M, e, l, x, b;
|
|
102
|
-
for (l = 0; l < V; ++l)
|
|
103
|
-
i[l] = l, c[l] = n.charCodeAt(l);
|
|
104
|
-
i[V] = V;
|
|
105
|
-
var s;
|
|
106
|
-
for (l = 0; l < k; ++l) {
|
|
107
|
-
for (e = l + 1, x = 0; x < V; ++x)
|
|
108
|
-
M = e, s = r.compare(g.charAt(l), String.fromCharCode(c[x])) === 0, e = i[x] + (s ? 0 : 1), b = M + 1, e > b && (e = b), b = i[x + 1] + 1, e > b && (e = b), i[x] = M;
|
|
109
|
-
i[x] = e;
|
|
110
|
-
}
|
|
111
|
-
return e;
|
|
112
|
-
}
|
|
113
|
-
return m.distance(g, n);
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
t !== null && t.exports === a ? t.exports = u : typeof self < "u" && typeof self.postMessage == "function" && typeof self.importScripts == "function" ? self.Levenshtein = u : typeof window < "u" && window !== null && (window.Levenshtein = u);
|
|
117
|
-
})();
|
|
118
|
-
})(T, T.exports)), T.exports;
|
|
119
|
-
}
|
|
120
|
-
var Ae = Ve();
|
|
121
|
-
const te = /* @__PURE__ */ he(Ae);
|
|
122
|
-
function se() {
|
|
1
|
+
import { j as c } from "../jsx-runtime-B4hRZ52C.mjs";
|
|
2
|
+
import { useRef as D, useId as J, useState as L, useCallback as u, useEffect as w, useDeferredValue as ae, useMemo as W } from "react";
|
|
3
|
+
import { cx as A } from "@kuma-ui/core";
|
|
4
|
+
import ce from "../hooks/use-synchronized-value.mjs";
|
|
5
|
+
import ie from "../icons/icon.mjs";
|
|
6
|
+
import le from "../icons/chevron-up.mjs";
|
|
7
|
+
import ue from "../utilities/search.mjs";
|
|
8
|
+
import me from "./input.mjs";
|
|
9
|
+
import { Span as P } from "./text.mjs";
|
|
10
|
+
import Q from "./flex.mjs";
|
|
11
|
+
import { SkeletonInstance as de } from "./skeleton.mjs";
|
|
12
|
+
function Z() {
|
|
123
13
|
const {
|
|
124
|
-
value:
|
|
125
|
-
setValue:
|
|
126
|
-
} =
|
|
127
|
-
return
|
|
128
|
-
isKeyboardNavigating:
|
|
129
|
-
setIsKeyboardNavigating:
|
|
130
|
-
}), [
|
|
14
|
+
value: s,
|
|
15
|
+
setValue: v
|
|
16
|
+
} = ce("isKeyboardNavigating");
|
|
17
|
+
return W(() => ({
|
|
18
|
+
isKeyboardNavigating: s,
|
|
19
|
+
setIsKeyboardNavigating: v
|
|
20
|
+
}), [s, v]);
|
|
131
21
|
}
|
|
132
|
-
function
|
|
133
|
-
return "text" in
|
|
22
|
+
function R(s) {
|
|
23
|
+
return "text" in s ? s.text : s.label;
|
|
134
24
|
}
|
|
135
|
-
const
|
|
136
|
-
function
|
|
137
|
-
isSelected:
|
|
138
|
-
id:
|
|
139
|
-
value:
|
|
140
|
-
label:
|
|
141
|
-
onSelect:
|
|
142
|
-
onHover:
|
|
25
|
+
const z = "kakadu-components-1144794361", U = "kakadu-components-2911184744";
|
|
26
|
+
function fe({
|
|
27
|
+
isSelected: s,
|
|
28
|
+
id: v,
|
|
29
|
+
value: i,
|
|
30
|
+
label: x,
|
|
31
|
+
onSelect: k,
|
|
32
|
+
onHover: I
|
|
143
33
|
}) {
|
|
144
34
|
const {
|
|
145
|
-
isKeyboardNavigating:
|
|
146
|
-
} =
|
|
147
|
-
i
|
|
148
|
-
}, [
|
|
149
|
-
|
|
150
|
-
}, [
|
|
151
|
-
return
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
35
|
+
isKeyboardNavigating: f
|
|
36
|
+
} = Z(), g = u(() => {
|
|
37
|
+
k(i);
|
|
38
|
+
}, [k, i]), n = u((b) => {
|
|
39
|
+
f || b.movementX === 0 && b.movementY === 0 || I(i);
|
|
40
|
+
}, [f, I, i]), p = D(null);
|
|
41
|
+
return w(() => {
|
|
42
|
+
const b = p.current;
|
|
43
|
+
s && b && f && setTimeout(() => {
|
|
44
|
+
b.scrollIntoView({
|
|
155
45
|
behavior: "smooth",
|
|
156
46
|
block: "nearest"
|
|
157
47
|
});
|
|
158
48
|
}, 0);
|
|
159
|
-
}, [
|
|
49
|
+
}, [s, f]), /* @__PURE__ */ c.jsx("li", { ref: p, id: v, role: "option", "aria-selected": s, tabIndex: -1, className: A(z, "kakadu-components-4130497639", f ? "kakadu-components-962373561" : "kakadu-components-1109598791"), onClick: g, onMouseMove: n, children: /* @__PURE__ */ c.jsx(P, { className: A(U, typeof x == "string" && "kakadu-components-154286052"), children: x }) });
|
|
160
50
|
}
|
|
161
|
-
function
|
|
162
|
-
isLoading:
|
|
163
|
-
id:
|
|
164
|
-
activeOptionId:
|
|
165
|
-
selectedValue:
|
|
166
|
-
options:
|
|
167
|
-
onSelect:
|
|
168
|
-
onHover:
|
|
51
|
+
function pe({
|
|
52
|
+
isLoading: s,
|
|
53
|
+
id: v,
|
|
54
|
+
activeOptionId: i,
|
|
55
|
+
selectedValue: x,
|
|
56
|
+
options: k,
|
|
57
|
+
onSelect: I,
|
|
58
|
+
onHover: f
|
|
169
59
|
}) {
|
|
170
|
-
const g =
|
|
171
|
-
return
|
|
60
|
+
const g = D(null);
|
|
61
|
+
return w(() => {
|
|
172
62
|
const n = g.current;
|
|
173
63
|
n && n.scrollIntoView({
|
|
174
64
|
behavior: "smooth",
|
|
175
65
|
block: "nearest"
|
|
176
66
|
});
|
|
177
|
-
}, []), /* @__PURE__ */
|
|
178
|
-
|
|
179
|
-
/* @__PURE__ */
|
|
180
|
-
/* @__PURE__ */
|
|
181
|
-
] }) :
|
|
182
|
-
|
|
67
|
+
}, []), /* @__PURE__ */ c.jsxs("ul", { ref: g, id: v, role: "listbox", "aria-label": "Options", tabIndex: -1, className: "kakadu-components-1951042708", children: [
|
|
68
|
+
k.length === 0 ? s ? null : /* @__PURE__ */ c.jsxs(Q, { "aria-atomic": !0, as: "li", role: "status", "aria-live": "polite", direction: "row", preset: "start", gap: 0.5, className: z, children: [
|
|
69
|
+
/* @__PURE__ */ c.jsx(ie, { size: 15, type: "exclamationTriangle" }),
|
|
70
|
+
/* @__PURE__ */ c.jsx(P, { className: U, children: "No results." })
|
|
71
|
+
] }) : k.map((n, p) => /* @__PURE__ */ c.jsx(
|
|
72
|
+
fe,
|
|
183
73
|
{
|
|
184
74
|
...n,
|
|
185
|
-
id: n.value ===
|
|
186
|
-
isSelected: n.value ===
|
|
187
|
-
onSelect:
|
|
188
|
-
onHover:
|
|
75
|
+
id: n.value === x ? i : void 0,
|
|
76
|
+
isSelected: n.value === x,
|
|
77
|
+
onSelect: I,
|
|
78
|
+
onHover: f
|
|
189
79
|
},
|
|
190
|
-
|
|
80
|
+
R(n) + p
|
|
191
81
|
)),
|
|
192
|
-
|
|
82
|
+
s ? /* @__PURE__ */ c.jsx(Q, { as: "li", alignment: "center", className: z, children: /* @__PURE__ */ c.jsx(P, { className: U, children: /* @__PURE__ */ c.jsx(de, { width: "100%", height: "1.3em" }) }) }) : null
|
|
193
83
|
] });
|
|
194
84
|
}
|
|
195
|
-
function
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
warning: i,
|
|
204
|
-
information: c,
|
|
205
|
-
footnote: u,
|
|
85
|
+
function ye({
|
|
86
|
+
isLoading: s,
|
|
87
|
+
label: v,
|
|
88
|
+
options: i,
|
|
89
|
+
error: x,
|
|
90
|
+
warning: k,
|
|
91
|
+
information: I,
|
|
92
|
+
footnote: f,
|
|
206
93
|
className: g,
|
|
207
94
|
onChange: n,
|
|
208
|
-
onSelect:
|
|
209
|
-
...
|
|
95
|
+
onSelect: p,
|
|
96
|
+
...b
|
|
210
97
|
}) {
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
}, []),
|
|
214
|
-
var
|
|
215
|
-
(
|
|
216
|
-
}, []), [
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}, [
|
|
220
|
-
const [
|
|
221
|
-
value:
|
|
222
|
-
} =
|
|
223
|
-
|
|
98
|
+
const F = D(null), X = J(), Y = J(), [N, H] = L(!1), _ = u(() => {
|
|
99
|
+
H(!0);
|
|
100
|
+
}, []), $ = u((e) => {
|
|
101
|
+
var t;
|
|
102
|
+
(t = F.current) != null && t.contains(e.relatedTarget) || H(!1);
|
|
103
|
+
}, []), [j, r] = L(!1);
|
|
104
|
+
w(() => {
|
|
105
|
+
r(N);
|
|
106
|
+
}, [N]);
|
|
107
|
+
const [q, K] = L(""), {
|
|
108
|
+
value: y
|
|
109
|
+
} = b, [m, O] = L(y), [M, ee] = L(y), C = D(M), a = u((e) => {
|
|
110
|
+
ee(e), C.current = e;
|
|
224
111
|
}, []);
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}, [
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
}, [
|
|
231
|
-
|
|
232
|
-
}, [n]),
|
|
233
|
-
var
|
|
234
|
-
(
|
|
235
|
-
}, []),
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
}, [
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
}, [
|
|
242
|
-
|
|
243
|
-
}, [
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
return f.length === 0 ? r : r.filter((O) => {
|
|
248
|
-
const _ = Y(O).toLowerCase();
|
|
249
|
-
if (_.includes(o) || o.includes(_) || te.get(_, o, {
|
|
250
|
-
useCollator: !0
|
|
251
|
-
}) <= 2)
|
|
252
|
-
return !0;
|
|
253
|
-
const q = ne(_);
|
|
254
|
-
return f.every((B) => q.some((p) => B.length >= 2 ? p.includes(B) || B.includes(p) || te.get(p, B, {
|
|
255
|
-
useCollator: !0
|
|
256
|
-
}) <= 2 : !1));
|
|
257
|
-
});
|
|
258
|
-
}, [y, r, K]);
|
|
259
|
-
D(() => {
|
|
260
|
-
!y && K.length > 0 && j.length > 0 && !j.some((o) => S === o.value) && I(j[0].value);
|
|
261
|
-
}, [y, K, j, S, I]);
|
|
112
|
+
w(() => {
|
|
113
|
+
O(y), a(y);
|
|
114
|
+
}, [y, a]);
|
|
115
|
+
const te = u(() => {
|
|
116
|
+
m && (K(""), a(void 0));
|
|
117
|
+
}, [m, a]), ne = u((e, t) => {
|
|
118
|
+
K(e), n == null || n(e, t), r(!0), O(void 0);
|
|
119
|
+
}, [n]), se = u((e) => {
|
|
120
|
+
var t;
|
|
121
|
+
(t = F.current) != null && t.contains(e.target) && r(!0);
|
|
122
|
+
}, []), h = u((e) => {
|
|
123
|
+
const t = e == null ? void 0 : e.value;
|
|
124
|
+
a(t), e ? K(R(e)) : (K(""), n == null || n("")), p == null || p(t);
|
|
125
|
+
}, [a, n, p]), oe = u((e) => {
|
|
126
|
+
const t = i.find((d) => d.value === e);
|
|
127
|
+
h(t), O(e), r(!1);
|
|
128
|
+
}, [i, h]), re = u((e) => {
|
|
129
|
+
a(e);
|
|
130
|
+
}, [a]), S = ae(q), l = W(() => m ? i : ue(S, i, R), [m, i, S]);
|
|
131
|
+
w(() => {
|
|
132
|
+
!m && S.length > 0 && l.length > 0 && !l.some((e) => M === e.value) && a(l[0].value);
|
|
133
|
+
}, [m, S, l, M, a]);
|
|
262
134
|
const {
|
|
263
|
-
setIsKeyboardNavigating:
|
|
264
|
-
} =
|
|
265
|
-
return
|
|
266
|
-
if (!
|
|
135
|
+
setIsKeyboardNavigating: E
|
|
136
|
+
} = Z();
|
|
137
|
+
return w(() => {
|
|
138
|
+
if (!N)
|
|
267
139
|
return;
|
|
268
|
-
const
|
|
269
|
-
|
|
140
|
+
const e = (t) => {
|
|
141
|
+
t.movementX === 0 && t.movementY === 0 || E(!1);
|
|
270
142
|
};
|
|
271
|
-
return window.addEventListener("mousemove",
|
|
143
|
+
return window.addEventListener("mousemove", e, {
|
|
272
144
|
capture: !0
|
|
273
145
|
}), () => {
|
|
274
|
-
window.removeEventListener("mousemove",
|
|
146
|
+
window.removeEventListener("mousemove", e, {
|
|
275
147
|
capture: !0
|
|
276
148
|
});
|
|
277
149
|
};
|
|
278
|
-
}, [
|
|
279
|
-
if (!
|
|
150
|
+
}, [N, E]), w(() => {
|
|
151
|
+
if (!N)
|
|
280
152
|
return;
|
|
281
|
-
const
|
|
282
|
-
var
|
|
283
|
-
let
|
|
284
|
-
const
|
|
285
|
-
|
|
153
|
+
const e = (t) => {
|
|
154
|
+
var G;
|
|
155
|
+
let d;
|
|
156
|
+
const B = l.length, T = l.findIndex((o) => o.value === C.current), V = () => {
|
|
157
|
+
t.preventDefault(), t.stopPropagation(), t.stopImmediatePropagation();
|
|
286
158
|
};
|
|
287
|
-
switch (
|
|
159
|
+
switch (t.key) {
|
|
288
160
|
case "Enter": {
|
|
289
|
-
const
|
|
290
|
-
|
|
161
|
+
const o = l[T];
|
|
162
|
+
o && (V(), E(!0), r(!1), h(o), O(o.value));
|
|
291
163
|
break;
|
|
292
164
|
}
|
|
293
165
|
case "Escape": {
|
|
294
|
-
if (
|
|
295
|
-
|
|
296
|
-
else if (
|
|
297
|
-
|
|
166
|
+
if (j)
|
|
167
|
+
V(), m ? a(void 0) : h(void 0), r(!1);
|
|
168
|
+
else if (m)
|
|
169
|
+
V(), r(!0), h(void 0);
|
|
298
170
|
else {
|
|
299
|
-
|
|
300
|
-
const
|
|
301
|
-
|
|
171
|
+
V(), H(!1);
|
|
172
|
+
const o = document.activeElement;
|
|
173
|
+
o instanceof HTMLElement && ((G = F.current) != null && G.contains(o)) && o.blur();
|
|
302
174
|
}
|
|
303
175
|
return;
|
|
304
176
|
}
|
|
305
177
|
case "ArrowDown": {
|
|
306
|
-
|
|
178
|
+
d = T + 1, r(!0);
|
|
307
179
|
break;
|
|
308
180
|
}
|
|
309
181
|
case "ArrowUp": {
|
|
310
|
-
|
|
182
|
+
d = T - 1, r(!0), d < 0 && (d = B - 1);
|
|
311
183
|
break;
|
|
312
184
|
}
|
|
313
185
|
case "Home": {
|
|
314
|
-
|
|
186
|
+
r(!0), d = 0;
|
|
315
187
|
break;
|
|
316
188
|
}
|
|
317
189
|
case "End": {
|
|
318
|
-
|
|
190
|
+
r(!0), d = B - 1;
|
|
319
191
|
break;
|
|
320
192
|
}
|
|
321
193
|
case "Backspace": {
|
|
322
|
-
|
|
194
|
+
l.some((o) => o.value === m) && (V(), h(void 0), r(!0));
|
|
323
195
|
break;
|
|
324
196
|
}
|
|
325
197
|
}
|
|
326
|
-
if (
|
|
327
|
-
const
|
|
328
|
-
|
|
198
|
+
if (d !== void 0 && (V(), E(!0), B > 0)) {
|
|
199
|
+
const o = l[d % B];
|
|
200
|
+
o && a(o.value);
|
|
329
201
|
}
|
|
330
202
|
};
|
|
331
|
-
return window.addEventListener("keydown",
|
|
203
|
+
return window.addEventListener("keydown", e, {
|
|
332
204
|
capture: !0
|
|
333
205
|
}), () => {
|
|
334
|
-
window.removeEventListener("keydown",
|
|
206
|
+
window.removeEventListener("keydown", e, {
|
|
335
207
|
capture: !0
|
|
336
208
|
});
|
|
337
209
|
};
|
|
338
|
-
}, [
|
|
210
|
+
}, [N, l, E, r, h, O, j, m, a]), /* @__PURE__ */ c.jsx(me, { ...b, ref: F, role: "combobox", autoComplete: "off", "aria-controls": X, "aria-expanded": j, "aria-activedescendant": j ? Y : void 0, label: v, value: q, error: x, warning: k, information: I, footnote: f, attachments: j ? /* @__PURE__ */ c.jsx(pe, { isLoading: s, id: X, activeOptionId: Y, selectedValue: M, options: l, onSelect: oe, onHover: re }) : null, className: A(g, "kakadu-components-879486679"), onMouseDown: se, onChange: ne, onBeforeInput: te, onFocus: _, onBlur: $, children: /* @__PURE__ */ c.jsx(le, { width: 14, height: 14, className: "kakadu-components-158931186" }) });
|
|
339
211
|
}
|
|
340
212
|
export {
|
|
341
|
-
|
|
342
|
-
|
|
213
|
+
ye as default,
|
|
214
|
+
R as getComboboxOptionString
|
|
343
215
|
};
|
package/build/index.d.ts
CHANGED
|
@@ -192,3 +192,5 @@ export * from './utilities/generate-random-id';
|
|
|
192
192
|
export { default as generateRandomId } from './utilities/generate-random-id';
|
|
193
193
|
export * from './utilities/scale';
|
|
194
194
|
export { default as scale } from './utilities/scale';
|
|
195
|
+
export * from './utilities/search';
|
|
196
|
+
export { default as search } from './utilities/search';
|
package/build/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./theme.js"),m=require("./components/aria-text.js"),q=require("./components/atom.js"),x=require("./components/bankid-logo.js"),P=require("./components/box.js"),t=require("./components/button.js"),_=require("./components/button-tooltip.js"),w=require("./components/card.js"),I=require("./components/click-ripples.js"),M=require("./components/collapsible.js"),v=require("./components/combobox.js"),B=require("./components/copy-icon-button.js"),D=require("./components/datum.js"),G=require("./components/decorators.js"),R=require("./components/dnb-logo.js"),A=require("./components/dot.js"),c=require("./components/flex.js"),h=require("./components/footer.js"),F=require("./components/gauge.js"),H=require("./components/gjensidige-logo.js"),V=require("./components/header.js"),y=require("./components/hover-gradient.js"),k=require("./components/icon-button.js"),a=require("./components/input.js"),E=require("./components/kakadu-guide-icon.js"),l=require("./components/kakadu-guide-logo.js"),U=require("./components/kakadu-index-logo.js"),K=require("./components/kakadu-academy-logo.js"),W=require("./components/kakadu-logo.js"),r=require("./components/modal.js"),N=require("./components/moving-gradients.js"),J=require("./components/moving-stars.js"),d=require("./components/notice.js"),p=require("./components/notification.js"),f=require("./components/popover-menu.js"),s=require("./components/popover.js"),L=require("./components/revealer.js"),j=require("./components/select.js"),u=require("./components/separator.js"),g=require("./components/skeleton.js"),O=require("./components/sparebank1-logo.js"),b=require("./components/spinner.js"),z=require("./components/sto-logo.js"),Q=require("./components/storebrand-logo.js"),e=require("./components/text.js"),T=require("./components/text-button.js"),n=require("./components/theme-setter.js"),X=require("./components/veil.js"),C=require("./components/wrapper.js"),S=require("./icons/icon.js"),Y=require("./icons/anchor-down.js"),Z=require("./icons/anchor-up.js"),$=require("./icons/arrow-down.js"),ee=require("./icons/arrow-left.js"),oe=require("./icons/arrow-right.js"),te=require("./icons/arrow-up.js"),ne=require("./icons/caret-down.js"),re=require("./icons/caret-left.js"),ae=require("./icons/caret-right.js"),se=require("./icons/caret-up.js"),ue=require("./icons/check.js"),ie=require("./icons/chevron-down.js"),ce=require("./icons/chevron-left.js"),le=require("./icons/chevron-right.js"),de=require("./icons/chevron-up.js"),pe=require("./icons/cog.js"),fe=require("./icons/copy.js"),ge=require("./icons/document.js"),Se=require("./icons/dots.js"),me=require("./icons/drag.js"),qe=require("./icons/edit.js"),_e=require("./icons/external.js"),ve=require("./icons/exclamation-triangle.js"),he=require("./icons/eye.js"),ye=require("./icons/information.js"),ke=require("./icons/kakadu-guide-glyph.js"),Le=require("./icons/kakadu-guide-icon.js"),be=require("./icons/menu.js"),Te=require("./icons/package.js"),Ce=require("./icons/plus.js"),xe=require("./icons/select.js"),Pe=require("./icons/share.js"),we=require("./icons/sparkle.js"),Ie=require("./icons/test.js"),Me=require("./icons/times.js"),Be=require("./icons/trash.js"),De=require("./icons/trend-up.js"),Ge=require("./icons/chrome-browser-logo.js"),Re=require("./icons/edge-browser-logo.js"),i=require("./hooks/use-fetch.js"),Ae=require("./hooks/use-media-query.js"),Fe=require("./hooks/use-synchronized-value.js"),He=require("./hooks/use-throttled.js"),Ve=require("./utilities/clamp.js"),Ee=require("./utilities/copy-to-clipboard.js"),Ue=require("./utilities/generate-random-id.js"),Ke=require("./utilities/scale.js");exports.FontFamilyHead=o.FontFamilyHead;exports.buttonResetStyles=o.buttonResetStyles;exports.darkBackgroundColor=o.darkBackgroundColor;exports.effectStyles=o.effectStyles;exports.font=o.font;exports.lightBackgroundColor=o.lightBackgroundColor;exports.nonInteractiveEffectStyles=o.nonInteractiveEffectStyles;exports.overflowProtectionStyles=o.overflowProtectionStyles;exports.theme=o.default;exports.AriaText=m.default;exports.ariaTextStyles=m.ariaTextStyles;exports.Atom=q.default;exports.defaultAtomElementType=q.defaultAtomElementType;exports.BankidLogo=x.default;exports.Box=P.default;exports.Button=t.default;exports.ButtonLoader=t.ButtonLoader;exports.buttonDangerStyles=t.buttonDangerStyles;exports.buttonSecondaryStyles=t.buttonSecondaryStyles;exports.buttonSuccessStyles=t.buttonSuccessStyles;exports.buttonVariants=t.buttonVariants;exports.buttonWarningStyles=t.buttonWarningStyles;exports.ButtonTooltip=_.default;exports.buttonTooltipPositions=_.buttonTooltipPositions;exports.Card=w.default;exports.ClickRipples=I.default;exports.Collapsible=M.default;exports.Combobox=v.default;exports.getComboboxOptionString=v.getComboboxOptionString;exports.CopyIconButton=B.default;exports.Datum=D.default;exports.Decorators=G.default;exports.DnbLogo=R.default;exports.Dot=A.default;exports.Flex=c.default;exports.flexDirections=c.flexDirections;exports.flexPresets=c.flexPresets;exports.Footer=h.default;exports.footerLinkItems=h.footerLinkItems;exports.Gauge=F.default;exports.GjensidigeLogo=H.default;exports.Header=V.default;exports.HoverGradient=y.default;exports.normalBlendStyles=y.normalBlendStyles;exports.IconButton=k.default;exports.iconButtonVariants=k.iconButtonVariants;exports.Input=a.default;exports.InputLabel=a.InputLabel;exports.errorParagraph=a.errorParagraph;exports.inputStyles=a.inputStyles;exports.KakaduGuideIcon=E.default;exports.KakaduGuideLogo=l.default;exports.KakaduGuideLogoSvg=l.KakaduGuideLogoSvg;exports.kakaduGuideLogoVariants=l.kakaduGuideLogoVariants;exports.KakaduIndexLogo=U.default;exports.KakaduAcademyLogo=K.default;exports.KakaduLogo=W.default;exports.Modal=r.default;exports.ModalActions=r.ModalActions;exports.ModalContent=r.ModalContent;exports.ModalHeading=r.ModalHeading;exports.useModal=r.useModal;exports.useModalContext=r.useModalContext;exports.MovingGradients=N.default;exports.MovingStars=J.default;exports.Notice=d.default;exports.noticeTypes=d.noticeTypes;exports.notificationTypes=d.noticeTypes;exports.Notification=p.default;exports.NotificationProvider=p.NotificationProvider;exports.useCreateNotification=p.useCreateNotification;exports.PopoverMenu=f.default;exports.dangerPopoverMenuItemStyles=f.dangerPopoverMenuItemStyles;exports.usePopoverMenu=f.usePopoverMenu;exports.Popover=s.default;exports.PopoverContainer=s.PopoverContainer;exports.usePopover=s.usePopover;exports.usePopoverContext=s.usePopoverContext;exports.Revealer=L.default;exports.useRevealer=L.useRevealer;exports.Select=j.default;exports.Separator=u.default;exports.SeparatorLabel=u.SeparatorLabel;exports.SmallSeparator=u.SmallSeparator;exports.VerticalSeparator=u.VerticalSeparator;exports.Skeleton=g.default;exports.SkeletonInstance=g.SkeletonInstance;exports.getDeterministicSkeletonWidth=g.getDeterministicSkeletonWidth;exports.Sparebank1Logo=O.default;exports.RevealSpinner=b.RevealSpinner;exports.Spinner=b.default;exports.StoLogo=z.default;exports.StorebrandLogo=Q.default;exports.AnchorHeading=e.AnchorHeading;exports.Footnote=e.Footnote;exports.Heading=e.Heading;exports.Hero=e.Hero;exports.Label=e.Label;exports.Paragraph=e.Paragraph;exports.Span=e.Span;exports.Text=e.default;exports.defaultHeadingElementType=e.defaultHeadingElementType;exports.spanStyles=e.spanStyles;exports.textShadowStyles=e.textShadowStyles;exports.TextButton=T.default;exports.textButtonVariants=T.textButtonVariants;exports.ThemeSetter=n.default;exports.getThemePreference=n.getThemePreference;exports.setThemePreference=n.setThemePreference;exports.themePreferences=n.themePreferences;exports.useIsDarkMode=n.useIsDarkMode;exports.useIsLightMode=n.useIsLightMode;exports.useTheme=n.useTheme;exports.Veil=X.default;exports.Wrapper=C.default;exports.wrapperWidths=C.wrapperWidths;exports.Icon=S.default;exports.iconShadowStyles=S.iconShadowStyles;exports.iconTypes=S.iconTypes;exports.AnchorDownSvg=Y.default;exports.AnchorUpSvg=Z.default;exports.ArrowDownSvg=$.default;exports.ArrowLeftSvg=ee.default;exports.ArrowRightSvg=oe.default;exports.ArrowUpSvg=te.default;exports.CaretDownSvg=ne.default;exports.CaretLeftSvg=re.default;exports.CaretRightSvg=ae.default;exports.CaretUpSvg=se.default;exports.CheckSvg=ue.default;exports.ChevronDownSvg=ie.default;exports.ChevronLeftSvg=ce.default;exports.ChevronRightSvg=le.default;exports.ChevronUpSvg=de.default;exports.CogSvg=pe.default;exports.CopySvg=fe.default;exports.DocumentSvg=ge.default;exports.DotsSvg=Se.default;exports.DragSvg=me.default;exports.EditSvg=qe.default;exports.ExternalSvg=_e.default;exports.ExclamationTriangleSvg=ve.default;exports.EyeSvg=he.default;exports.InformationSvg=ye.default;exports.KakaduGuideGlyphSvg=ke.default;exports.KakaduGuideIconSvg=Le.default;exports.MenuSvg=be.default;exports.PackageSvg=Te.default;exports.PlusSvg=Ce.default;exports.SelectSvg=xe.default;exports.ShareSvg=Pe.default;exports.SparkleSvg=we.default;exports.TestSvg=Ie.default;exports.TimesSvg=Me.default;exports.TrashSvg=Be.default;exports.TrendUpSvg=De.default;exports.ChromeBrowserLogoSvg=Ge.default;exports.EdgeBrowserLogoSvg=Re.default;exports.useFetch=i.default;exports.useFetcher=i.useFetcher;exports.useJsonFetch=i.useJsonFetch;exports.useJsonFetcher=i.useJsonFetcher;exports.useMediaQuery=Ae.default;exports.useSynchronizedValue=Fe.default;exports.useThrottled=He.default;exports.clamp=Ve.default;exports.copyToClipboard=Ee.default;exports.generateRandomId=Ue.default;exports.scale=Ke.default;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./theme.js"),m=require("./components/aria-text.js"),q=require("./components/atom.js"),x=require("./components/bankid-logo.js"),P=require("./components/box.js"),t=require("./components/button.js"),_=require("./components/button-tooltip.js"),w=require("./components/card.js"),I=require("./components/click-ripples.js"),M=require("./components/collapsible.js"),v=require("./components/combobox.js"),B=require("./components/copy-icon-button.js"),D=require("./components/datum.js"),G=require("./components/decorators.js"),R=require("./components/dnb-logo.js"),A=require("./components/dot.js"),c=require("./components/flex.js"),h=require("./components/footer.js"),F=require("./components/gauge.js"),H=require("./components/gjensidige-logo.js"),V=require("./components/header.js"),y=require("./components/hover-gradient.js"),k=require("./components/icon-button.js"),a=require("./components/input.js"),E=require("./components/kakadu-guide-icon.js"),l=require("./components/kakadu-guide-logo.js"),U=require("./components/kakadu-index-logo.js"),K=require("./components/kakadu-academy-logo.js"),W=require("./components/kakadu-logo.js"),r=require("./components/modal.js"),N=require("./components/moving-gradients.js"),J=require("./components/moving-stars.js"),d=require("./components/notice.js"),p=require("./components/notification.js"),f=require("./components/popover-menu.js"),s=require("./components/popover.js"),L=require("./components/revealer.js"),j=require("./components/select.js"),u=require("./components/separator.js"),g=require("./components/skeleton.js"),O=require("./components/sparebank1-logo.js"),b=require("./components/spinner.js"),z=require("./components/sto-logo.js"),Q=require("./components/storebrand-logo.js"),e=require("./components/text.js"),T=require("./components/text-button.js"),n=require("./components/theme-setter.js"),X=require("./components/veil.js"),C=require("./components/wrapper.js"),S=require("./icons/icon.js"),Y=require("./icons/anchor-down.js"),Z=require("./icons/anchor-up.js"),$=require("./icons/arrow-down.js"),ee=require("./icons/arrow-left.js"),oe=require("./icons/arrow-right.js"),te=require("./icons/arrow-up.js"),ne=require("./icons/caret-down.js"),re=require("./icons/caret-left.js"),ae=require("./icons/caret-right.js"),se=require("./icons/caret-up.js"),ue=require("./icons/check.js"),ie=require("./icons/chevron-down.js"),ce=require("./icons/chevron-left.js"),le=require("./icons/chevron-right.js"),de=require("./icons/chevron-up.js"),pe=require("./icons/cog.js"),fe=require("./icons/copy.js"),ge=require("./icons/document.js"),Se=require("./icons/dots.js"),me=require("./icons/drag.js"),qe=require("./icons/edit.js"),_e=require("./icons/external.js"),ve=require("./icons/exclamation-triangle.js"),he=require("./icons/eye.js"),ye=require("./icons/information.js"),ke=require("./icons/kakadu-guide-glyph.js"),Le=require("./icons/kakadu-guide-icon.js"),be=require("./icons/menu.js"),Te=require("./icons/package.js"),Ce=require("./icons/plus.js"),xe=require("./icons/select.js"),Pe=require("./icons/share.js"),we=require("./icons/sparkle.js"),Ie=require("./icons/test.js"),Me=require("./icons/times.js"),Be=require("./icons/trash.js"),De=require("./icons/trend-up.js"),Ge=require("./icons/chrome-browser-logo.js"),Re=require("./icons/edge-browser-logo.js"),i=require("./hooks/use-fetch.js"),Ae=require("./hooks/use-media-query.js"),Fe=require("./hooks/use-synchronized-value.js"),He=require("./hooks/use-throttled.js"),Ve=require("./utilities/clamp.js"),Ee=require("./utilities/copy-to-clipboard.js"),Ue=require("./utilities/generate-random-id.js"),Ke=require("./utilities/scale.js"),We=require("./utilities/search.js");exports.FontFamilyHead=o.FontFamilyHead;exports.buttonResetStyles=o.buttonResetStyles;exports.darkBackgroundColor=o.darkBackgroundColor;exports.effectStyles=o.effectStyles;exports.font=o.font;exports.lightBackgroundColor=o.lightBackgroundColor;exports.nonInteractiveEffectStyles=o.nonInteractiveEffectStyles;exports.overflowProtectionStyles=o.overflowProtectionStyles;exports.theme=o.default;exports.AriaText=m.default;exports.ariaTextStyles=m.ariaTextStyles;exports.Atom=q.default;exports.defaultAtomElementType=q.defaultAtomElementType;exports.BankidLogo=x.default;exports.Box=P.default;exports.Button=t.default;exports.ButtonLoader=t.ButtonLoader;exports.buttonDangerStyles=t.buttonDangerStyles;exports.buttonSecondaryStyles=t.buttonSecondaryStyles;exports.buttonSuccessStyles=t.buttonSuccessStyles;exports.buttonVariants=t.buttonVariants;exports.buttonWarningStyles=t.buttonWarningStyles;exports.ButtonTooltip=_.default;exports.buttonTooltipPositions=_.buttonTooltipPositions;exports.Card=w.default;exports.ClickRipples=I.default;exports.Collapsible=M.default;exports.Combobox=v.default;exports.getComboboxOptionString=v.getComboboxOptionString;exports.CopyIconButton=B.default;exports.Datum=D.default;exports.Decorators=G.default;exports.DnbLogo=R.default;exports.Dot=A.default;exports.Flex=c.default;exports.flexDirections=c.flexDirections;exports.flexPresets=c.flexPresets;exports.Footer=h.default;exports.footerLinkItems=h.footerLinkItems;exports.Gauge=F.default;exports.GjensidigeLogo=H.default;exports.Header=V.default;exports.HoverGradient=y.default;exports.normalBlendStyles=y.normalBlendStyles;exports.IconButton=k.default;exports.iconButtonVariants=k.iconButtonVariants;exports.Input=a.default;exports.InputLabel=a.InputLabel;exports.errorParagraph=a.errorParagraph;exports.inputStyles=a.inputStyles;exports.KakaduGuideIcon=E.default;exports.KakaduGuideLogo=l.default;exports.KakaduGuideLogoSvg=l.KakaduGuideLogoSvg;exports.kakaduGuideLogoVariants=l.kakaduGuideLogoVariants;exports.KakaduIndexLogo=U.default;exports.KakaduAcademyLogo=K.default;exports.KakaduLogo=W.default;exports.Modal=r.default;exports.ModalActions=r.ModalActions;exports.ModalContent=r.ModalContent;exports.ModalHeading=r.ModalHeading;exports.useModal=r.useModal;exports.useModalContext=r.useModalContext;exports.MovingGradients=N.default;exports.MovingStars=J.default;exports.Notice=d.default;exports.noticeTypes=d.noticeTypes;exports.notificationTypes=d.noticeTypes;exports.Notification=p.default;exports.NotificationProvider=p.NotificationProvider;exports.useCreateNotification=p.useCreateNotification;exports.PopoverMenu=f.default;exports.dangerPopoverMenuItemStyles=f.dangerPopoverMenuItemStyles;exports.usePopoverMenu=f.usePopoverMenu;exports.Popover=s.default;exports.PopoverContainer=s.PopoverContainer;exports.usePopover=s.usePopover;exports.usePopoverContext=s.usePopoverContext;exports.Revealer=L.default;exports.useRevealer=L.useRevealer;exports.Select=j.default;exports.Separator=u.default;exports.SeparatorLabel=u.SeparatorLabel;exports.SmallSeparator=u.SmallSeparator;exports.VerticalSeparator=u.VerticalSeparator;exports.Skeleton=g.default;exports.SkeletonInstance=g.SkeletonInstance;exports.getDeterministicSkeletonWidth=g.getDeterministicSkeletonWidth;exports.Sparebank1Logo=O.default;exports.RevealSpinner=b.RevealSpinner;exports.Spinner=b.default;exports.StoLogo=z.default;exports.StorebrandLogo=Q.default;exports.AnchorHeading=e.AnchorHeading;exports.Footnote=e.Footnote;exports.Heading=e.Heading;exports.Hero=e.Hero;exports.Label=e.Label;exports.Paragraph=e.Paragraph;exports.Span=e.Span;exports.Text=e.default;exports.defaultHeadingElementType=e.defaultHeadingElementType;exports.spanStyles=e.spanStyles;exports.textShadowStyles=e.textShadowStyles;exports.TextButton=T.default;exports.textButtonVariants=T.textButtonVariants;exports.ThemeSetter=n.default;exports.getThemePreference=n.getThemePreference;exports.setThemePreference=n.setThemePreference;exports.themePreferences=n.themePreferences;exports.useIsDarkMode=n.useIsDarkMode;exports.useIsLightMode=n.useIsLightMode;exports.useTheme=n.useTheme;exports.Veil=X.default;exports.Wrapper=C.default;exports.wrapperWidths=C.wrapperWidths;exports.Icon=S.default;exports.iconShadowStyles=S.iconShadowStyles;exports.iconTypes=S.iconTypes;exports.AnchorDownSvg=Y.default;exports.AnchorUpSvg=Z.default;exports.ArrowDownSvg=$.default;exports.ArrowLeftSvg=ee.default;exports.ArrowRightSvg=oe.default;exports.ArrowUpSvg=te.default;exports.CaretDownSvg=ne.default;exports.CaretLeftSvg=re.default;exports.CaretRightSvg=ae.default;exports.CaretUpSvg=se.default;exports.CheckSvg=ue.default;exports.ChevronDownSvg=ie.default;exports.ChevronLeftSvg=ce.default;exports.ChevronRightSvg=le.default;exports.ChevronUpSvg=de.default;exports.CogSvg=pe.default;exports.CopySvg=fe.default;exports.DocumentSvg=ge.default;exports.DotsSvg=Se.default;exports.DragSvg=me.default;exports.EditSvg=qe.default;exports.ExternalSvg=_e.default;exports.ExclamationTriangleSvg=ve.default;exports.EyeSvg=he.default;exports.InformationSvg=ye.default;exports.KakaduGuideGlyphSvg=ke.default;exports.KakaduGuideIconSvg=Le.default;exports.MenuSvg=be.default;exports.PackageSvg=Te.default;exports.PlusSvg=Ce.default;exports.SelectSvg=xe.default;exports.ShareSvg=Pe.default;exports.SparkleSvg=we.default;exports.TestSvg=Ie.default;exports.TimesSvg=Me.default;exports.TrashSvg=Be.default;exports.TrendUpSvg=De.default;exports.ChromeBrowserLogoSvg=Ge.default;exports.EdgeBrowserLogoSvg=Re.default;exports.useFetch=i.default;exports.useFetcher=i.useFetcher;exports.useJsonFetch=i.useJsonFetch;exports.useJsonFetcher=i.useJsonFetcher;exports.useMediaQuery=Ae.default;exports.useSynchronizedValue=Fe.default;exports.useThrottled=He.default;exports.clamp=Ve.default;exports.copyToClipboard=Ee.default;exports.generateRandomId=Ue.default;exports.scale=Ke.default;exports.search=We.default;
|
package/build/index.mjs
CHANGED
|
@@ -95,6 +95,7 @@ import { default as za } from "./utilities/clamp.mjs";
|
|
|
95
95
|
import { default as Qa } from "./utilities/copy-to-clipboard.mjs";
|
|
96
96
|
import { default as Xa } from "./utilities/generate-random-id.mjs";
|
|
97
97
|
import { default as Za } from "./utilities/scale.mjs";
|
|
98
|
+
import { default as $a } from "./utilities/search.mjs";
|
|
98
99
|
export {
|
|
99
100
|
pt as AnchorDownSvg,
|
|
100
101
|
Ao as AnchorHeading,
|
|
@@ -241,6 +242,7 @@ export {
|
|
|
241
242
|
Qe as notificationTypes,
|
|
242
243
|
d as overflowProtectionStyles,
|
|
243
244
|
Za as scale,
|
|
245
|
+
$a as search,
|
|
244
246
|
Xo as setThemePreference,
|
|
245
247
|
No as spanStyles,
|
|
246
248
|
zo as textButtonVariants,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type SearchOptions = {
|
|
2
|
+
/** Maximum Levenshtein distance for fuzzy matches (default: 2). */
|
|
3
|
+
fuzzyMatchThreshold?: number;
|
|
4
|
+
/** Minimum length for query tokens to be considered (default: 2). */
|
|
5
|
+
minimumTokenLength?: number;
|
|
6
|
+
/** Items with a score below this are excluded (default: 1). */
|
|
7
|
+
minimumScore?: number;
|
|
8
|
+
};
|
|
9
|
+
/** Search a dataset for matches based on an input query. Returns matches sorted by relevance. */
|
|
10
|
+
export default function search<Type>(query: string, dataset: Type[], getValues: (value: Type) => string | string[], options?: SearchOptions): Type[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const P=require("../_commonjsHelpers-DGT2Y9Xa.js");var S={exports:{}};const w=new Uint32Array(65536),F=(t,e)=>{const s=t.length,i=e.length,r=1<<s-1;let o=-1,d=0,a=s,f=s;for(;f--;)w[t.charCodeAt(f)]|=1<<f;for(f=0;f<i;f++){let g=w[e.charCodeAt(f)];const l=g|d;g|=(g&o)+o^o,d|=~(g|o),o&=g,d&r&&a++,o&r&&a--,d=d<<1|1,o=o<<1|~(l|d),d&=l}for(f=s;f--;)w[t.charCodeAt(f)]=0;return a},L=(t,e)=>{const s=e.length,i=t.length,r=[],o=[],d=Math.ceil(s/32),a=Math.ceil(i/32);for(let n=0;n<d;n++)o[n]=-1,r[n]=0;let f=0;for(;f<a-1;f++){let n=0,u=-1;const m=f*32,M=Math.min(32,i)+m;for(let c=m;c<M;c++)w[t.charCodeAt(c)]|=1<<c;for(let c=0;c<s;c++){const C=w[e.charCodeAt(c)],A=o[c/32|0]>>>c&1,v=r[c/32|0]>>>c&1,q=C|n,O=((C|v)&u)+u^u|C|v;let y=n|~(O|u),_=u&O;y>>>31^A&&(o[c/32|0]^=1<<c),_>>>31^v&&(r[c/32|0]^=1<<c),y=y<<1|A,_=_<<1|v,u=_|~(q|y),n=y&q}for(let c=m;c<M;c++)w[t.charCodeAt(c)]=0}let g=0,l=-1;const h=f*32,p=Math.min(32,i-h)+h;for(let n=h;n<p;n++)w[t.charCodeAt(n)]|=1<<n;let x=i;for(let n=0;n<s;n++){const u=w[e.charCodeAt(n)],m=o[n/32|0]>>>n&1,M=r[n/32|0]>>>n&1,c=u|g,C=((u|M)&l)+l^l|u|M;let A=g|~(C|l),v=l&C;x+=A>>>i-1&1,x-=v>>>i-1&1,A>>>31^m&&(o[n/32|0]^=1<<n),v>>>31^M&&(r[n/32|0]^=1<<n),A=A<<1|m,v=v<<1|M,l=v|~(c|A),g=A&c}for(let n=h;n<p;n++)w[t.charCodeAt(n)]=0;return x},W=(t,e)=>{if(t.length<e.length){const s=e;e=t,t=s}return e.length===0?t.length:t.length<=32?F(t,e):L(t,e)},N=(t,e)=>{let s=1/0,i=0;for(let r=0;r<e.length;r++){const o=W(t,e[r]);o<s&&(s=o,i=r)}return e[i]},R=Object.freeze(Object.defineProperty({__proto__:null,closest:N,distance:W},Symbol.toStringTag,{value:"Module"})),j=P.getAugmentedNamespace(R);var b;function z(){return b||(b=1,(function(t,e){(function(){var s;try{s=typeof Intl<"u"&&typeof Intl.Collator<"u"?Intl.Collator("generic",{sensitivity:"base"}):null}catch{console.log("Collator could not be initialized and wouldn't be used")}var i=j,r=[],o=[],d={get:function(a,f,g){var l=g&&s&&g.useCollator;if(l){var h=a.length,p=f.length;if(h===0)return p;if(p===0)return h;var x,n,u,m,M;for(u=0;u<p;++u)r[u]=u,o[u]=f.charCodeAt(u);r[p]=p;var c;for(u=0;u<h;++u){for(n=u+1,m=0;m<p;++m)x=n,c=s.compare(a.charAt(u),String.fromCharCode(o[m]))===0,n=r[m]+(c?0:1),M=x+1,n>M&&(n=M),M=r[m+1]+1,n>M&&(n=M),r[m]=x;r[m]=n}return n}return i.distance(a,f)}};t!==null&&t.exports===e?t.exports=d:typeof self<"u"&&typeof self.postMessage=="function"&&typeof self.importScripts=="function"?self.Levenshtein=d:typeof window<"u"&&window!==null&&(window.Levenshtein=d)})()})(S,S.exports)),S.exports}var B=z();const $=P.getDefaultExportFromCjs(B);function E(t){return t.normalize("NFC").split(/[\s-]+/).filter(Boolean)}function D(t){return Array.isArray(t)?t.map(e=>e.toLowerCase()):[t.toLowerCase()]}function I(t,e,s,i){if(t===e)return 100;if(t.startsWith(e))return 80;if(t.includes(e)){const o=t.indexOf(e);return 65-Math.min(o,15)}if(e.includes(t)&&t.length>=i)return 45;const r=$.get(t,e,{useCollator:!0});return r<=s?35-r*10:0}function H(t,e,s){if(!t.includes(e))return 0;const i=t.indexOf(e);return s.length>1?72-Math.min(i,10):55-Math.min(i,15)}function U(t,e,s,i){if(e===t)return 25;if(e.startsWith(t))return 20;if(t.startsWith(e)&&e.length>=i)return 15;if(e.includes(t)){const o=e.indexOf(t);return 15-Math.min(o,5)}if(t.includes(e)&&e.length>=i)return 10;const r=$.get(e,t,{useCollator:!0});return r<=s?12-r*4:0}function G(t,e,s,i){const{fuzzyMatchThreshold:r,minimumTokenLength:o}=i,d=s.join(" ");let a=Math.max(I(d,t,r,o),H(d,t,e));if(a===100)return a;if(s.length>1){for(const h of s)if(a=Math.max(a,I(h,t,r,o)),a===100)return a}const f=s.flatMap(h=>E(h)),g=[];return e.every(h=>{if(h.length<o)return!1;let p=0;for(const x of f)p=Math.max(p,U(h,x,r,o));return p===0?!1:(g.push(p),!0)})&&g.length>0&&(a=Math.max(a,30+g.reduce((h,p)=>h+p,0))),a}function J(t,e,s,i={}){if(e.length===0||t.length===0)return e;const r=t.toLowerCase(),o=E(r);if(o.length===0)return e;const{fuzzyMatchThreshold:d=2,minimumTokenLength:a=2,minimumScore:f=1}=i,g={fuzzyMatchThreshold:d,minimumTokenLength:a};return e.map((l,h)=>{const p=G(r,o,D(s(l)),g);return{item:l,score:p,index:h}}).filter(l=>l.score>=f).sort((l,h)=>h.score!==l.score?h.score-l.score:l.index-h.index).map(({item:l})=>l)}exports.default=J;
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { g as F, a as L } from "../_commonjsHelpers-MdHo5S7N.mjs";
|
|
2
|
+
var _ = { exports: {} };
|
|
3
|
+
const w = new Uint32Array(65536), N = (t, e) => {
|
|
4
|
+
const s = t.length, i = e.length, r = 1 << s - 1;
|
|
5
|
+
let o = -1, d = 0, a = s, f = s;
|
|
6
|
+
for (; f--; )
|
|
7
|
+
w[t.charCodeAt(f)] |= 1 << f;
|
|
8
|
+
for (f = 0; f < i; f++) {
|
|
9
|
+
let g = w[e.charCodeAt(f)];
|
|
10
|
+
const l = g | d;
|
|
11
|
+
g |= (g & o) + o ^ o, d |= ~(g | o), o &= g, d & r && a++, o & r && a--, d = d << 1 | 1, o = o << 1 | ~(l | d), d &= l;
|
|
12
|
+
}
|
|
13
|
+
for (f = s; f--; )
|
|
14
|
+
w[t.charCodeAt(f)] = 0;
|
|
15
|
+
return a;
|
|
16
|
+
}, P = (t, e) => {
|
|
17
|
+
const s = e.length, i = t.length, r = [], o = [], d = Math.ceil(s / 32), a = Math.ceil(i / 32);
|
|
18
|
+
for (let n = 0; n < d; n++)
|
|
19
|
+
o[n] = -1, r[n] = 0;
|
|
20
|
+
let f = 0;
|
|
21
|
+
for (; f < a - 1; f++) {
|
|
22
|
+
let n = 0, u = -1;
|
|
23
|
+
const m = f * 32, M = Math.min(32, i) + m;
|
|
24
|
+
for (let c = m; c < M; c++)
|
|
25
|
+
w[t.charCodeAt(c)] |= 1 << c;
|
|
26
|
+
for (let c = 0; c < s; c++) {
|
|
27
|
+
const C = w[e.charCodeAt(c)], A = o[c / 32 | 0] >>> c & 1, v = r[c / 32 | 0] >>> c & 1, q = C | n, O = ((C | v) & u) + u ^ u | C | v;
|
|
28
|
+
let y = n | ~(O | u), S = u & O;
|
|
29
|
+
y >>> 31 ^ A && (o[c / 32 | 0] ^= 1 << c), S >>> 31 ^ v && (r[c / 32 | 0] ^= 1 << c), y = y << 1 | A, S = S << 1 | v, u = S | ~(q | y), n = y & q;
|
|
30
|
+
}
|
|
31
|
+
for (let c = m; c < M; c++)
|
|
32
|
+
w[t.charCodeAt(c)] = 0;
|
|
33
|
+
}
|
|
34
|
+
let g = 0, l = -1;
|
|
35
|
+
const h = f * 32, p = Math.min(32, i - h) + h;
|
|
36
|
+
for (let n = h; n < p; n++)
|
|
37
|
+
w[t.charCodeAt(n)] |= 1 << n;
|
|
38
|
+
let x = i;
|
|
39
|
+
for (let n = 0; n < s; n++) {
|
|
40
|
+
const u = w[e.charCodeAt(n)], m = o[n / 32 | 0] >>> n & 1, M = r[n / 32 | 0] >>> n & 1, c = u | g, C = ((u | M) & l) + l ^ l | u | M;
|
|
41
|
+
let A = g | ~(C | l), v = l & C;
|
|
42
|
+
x += A >>> i - 1 & 1, x -= v >>> i - 1 & 1, A >>> 31 ^ m && (o[n / 32 | 0] ^= 1 << n), v >>> 31 ^ M && (r[n / 32 | 0] ^= 1 << n), A = A << 1 | m, v = v << 1 | M, l = v | ~(c | A), g = A & c;
|
|
43
|
+
}
|
|
44
|
+
for (let n = h; n < p; n++)
|
|
45
|
+
w[t.charCodeAt(n)] = 0;
|
|
46
|
+
return x;
|
|
47
|
+
}, W = (t, e) => {
|
|
48
|
+
if (t.length < e.length) {
|
|
49
|
+
const s = e;
|
|
50
|
+
e = t, t = s;
|
|
51
|
+
}
|
|
52
|
+
return e.length === 0 ? t.length : t.length <= 32 ? N(t, e) : P(t, e);
|
|
53
|
+
}, R = (t, e) => {
|
|
54
|
+
let s = 1 / 0, i = 0;
|
|
55
|
+
for (let r = 0; r < e.length; r++) {
|
|
56
|
+
const o = W(t, e[r]);
|
|
57
|
+
o < s && (s = o, i = r);
|
|
58
|
+
}
|
|
59
|
+
return e[i];
|
|
60
|
+
}, z = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
61
|
+
__proto__: null,
|
|
62
|
+
closest: R,
|
|
63
|
+
distance: W
|
|
64
|
+
}, Symbol.toStringTag, { value: "Module" })), B = /* @__PURE__ */ F(z);
|
|
65
|
+
var I;
|
|
66
|
+
function D() {
|
|
67
|
+
return I || (I = 1, (function(t, e) {
|
|
68
|
+
(function() {
|
|
69
|
+
var s;
|
|
70
|
+
try {
|
|
71
|
+
s = typeof Intl < "u" && typeof Intl.Collator < "u" ? Intl.Collator("generic", { sensitivity: "base" }) : null;
|
|
72
|
+
} catch {
|
|
73
|
+
console.log("Collator could not be initialized and wouldn't be used");
|
|
74
|
+
}
|
|
75
|
+
var i = B, r = [], o = [], d = {
|
|
76
|
+
/**
|
|
77
|
+
* Calculate levenshtein distance of the two strings.
|
|
78
|
+
*
|
|
79
|
+
* @param str1 String the first string.
|
|
80
|
+
* @param str2 String the second string.
|
|
81
|
+
* @param [options] Additional options.
|
|
82
|
+
* @param [options.useCollator] Use `Intl.Collator` for locale-sensitive string comparison.
|
|
83
|
+
* @return Integer the levenshtein distance (0 and above).
|
|
84
|
+
*/
|
|
85
|
+
get: function(a, f, g) {
|
|
86
|
+
var l = g && s && g.useCollator;
|
|
87
|
+
if (l) {
|
|
88
|
+
var h = a.length, p = f.length;
|
|
89
|
+
if (h === 0) return p;
|
|
90
|
+
if (p === 0) return h;
|
|
91
|
+
var x, n, u, m, M;
|
|
92
|
+
for (u = 0; u < p; ++u)
|
|
93
|
+
r[u] = u, o[u] = f.charCodeAt(u);
|
|
94
|
+
r[p] = p;
|
|
95
|
+
var c;
|
|
96
|
+
for (u = 0; u < h; ++u) {
|
|
97
|
+
for (n = u + 1, m = 0; m < p; ++m)
|
|
98
|
+
x = n, c = s.compare(a.charAt(u), String.fromCharCode(o[m])) === 0, n = r[m] + (c ? 0 : 1), M = x + 1, n > M && (n = M), M = r[m + 1] + 1, n > M && (n = M), r[m] = x;
|
|
99
|
+
r[m] = n;
|
|
100
|
+
}
|
|
101
|
+
return n;
|
|
102
|
+
}
|
|
103
|
+
return i.distance(a, f);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
t !== null && t.exports === e ? t.exports = d : typeof self < "u" && typeof self.postMessage == "function" && typeof self.importScripts == "function" ? self.Levenshtein = d : typeof window < "u" && window !== null && (window.Levenshtein = d);
|
|
107
|
+
})();
|
|
108
|
+
})(_, _.exports)), _.exports;
|
|
109
|
+
}
|
|
110
|
+
var U = D();
|
|
111
|
+
const $ = /* @__PURE__ */ L(U);
|
|
112
|
+
function E(t) {
|
|
113
|
+
return t.normalize("NFC").split(/[\s-]+/).filter(Boolean);
|
|
114
|
+
}
|
|
115
|
+
function G(t) {
|
|
116
|
+
return Array.isArray(t) ? t.map((e) => e.toLowerCase()) : [t.toLowerCase()];
|
|
117
|
+
}
|
|
118
|
+
function b(t, e, s, i) {
|
|
119
|
+
if (t === e)
|
|
120
|
+
return 100;
|
|
121
|
+
if (t.startsWith(e))
|
|
122
|
+
return 80;
|
|
123
|
+
if (t.includes(e)) {
|
|
124
|
+
const o = t.indexOf(e);
|
|
125
|
+
return 65 - Math.min(o, 15);
|
|
126
|
+
}
|
|
127
|
+
if (e.includes(t) && t.length >= i)
|
|
128
|
+
return 45;
|
|
129
|
+
const r = $.get(t, e, {
|
|
130
|
+
useCollator: !0
|
|
131
|
+
});
|
|
132
|
+
return r <= s ? 35 - r * 10 : 0;
|
|
133
|
+
}
|
|
134
|
+
function H(t, e, s) {
|
|
135
|
+
if (!t.includes(e))
|
|
136
|
+
return 0;
|
|
137
|
+
const i = t.indexOf(e);
|
|
138
|
+
return s.length > 1 ? 72 - Math.min(i, 10) : 55 - Math.min(i, 15);
|
|
139
|
+
}
|
|
140
|
+
function J(t, e, s, i) {
|
|
141
|
+
if (e === t)
|
|
142
|
+
return 25;
|
|
143
|
+
if (e.startsWith(t))
|
|
144
|
+
return 20;
|
|
145
|
+
if (t.startsWith(e) && e.length >= i)
|
|
146
|
+
return 15;
|
|
147
|
+
if (e.includes(t)) {
|
|
148
|
+
const o = e.indexOf(t);
|
|
149
|
+
return 15 - Math.min(o, 5);
|
|
150
|
+
}
|
|
151
|
+
if (t.includes(e) && e.length >= i)
|
|
152
|
+
return 10;
|
|
153
|
+
const r = $.get(e, t, {
|
|
154
|
+
useCollator: !0
|
|
155
|
+
});
|
|
156
|
+
return r <= s ? 12 - r * 4 : 0;
|
|
157
|
+
}
|
|
158
|
+
function K(t, e, s, i) {
|
|
159
|
+
const { fuzzyMatchThreshold: r, minimumTokenLength: o } = i, d = s.join(" ");
|
|
160
|
+
let a = Math.max(
|
|
161
|
+
b(
|
|
162
|
+
d,
|
|
163
|
+
t,
|
|
164
|
+
r,
|
|
165
|
+
o
|
|
166
|
+
),
|
|
167
|
+
H(d, t, e)
|
|
168
|
+
);
|
|
169
|
+
if (a === 100)
|
|
170
|
+
return a;
|
|
171
|
+
if (s.length > 1) {
|
|
172
|
+
for (const h of s)
|
|
173
|
+
if (a = Math.max(
|
|
174
|
+
a,
|
|
175
|
+
b(
|
|
176
|
+
h,
|
|
177
|
+
t,
|
|
178
|
+
r,
|
|
179
|
+
o
|
|
180
|
+
)
|
|
181
|
+
), a === 100)
|
|
182
|
+
return a;
|
|
183
|
+
}
|
|
184
|
+
const f = s.flatMap((h) => E(h)), g = [];
|
|
185
|
+
return e.every((h) => {
|
|
186
|
+
if (h.length < o)
|
|
187
|
+
return !1;
|
|
188
|
+
let p = 0;
|
|
189
|
+
for (const x of f)
|
|
190
|
+
p = Math.max(
|
|
191
|
+
p,
|
|
192
|
+
J(
|
|
193
|
+
h,
|
|
194
|
+
x,
|
|
195
|
+
r,
|
|
196
|
+
o
|
|
197
|
+
)
|
|
198
|
+
);
|
|
199
|
+
return p === 0 ? !1 : (g.push(p), !0);
|
|
200
|
+
}) && g.length > 0 && (a = Math.max(
|
|
201
|
+
a,
|
|
202
|
+
30 + g.reduce((h, p) => h + p, 0)
|
|
203
|
+
)), a;
|
|
204
|
+
}
|
|
205
|
+
function X(t, e, s, i = {}) {
|
|
206
|
+
if (e.length === 0 || t.length === 0)
|
|
207
|
+
return e;
|
|
208
|
+
const r = t.toLowerCase(), o = E(r);
|
|
209
|
+
if (o.length === 0)
|
|
210
|
+
return e;
|
|
211
|
+
const {
|
|
212
|
+
fuzzyMatchThreshold: d = 2,
|
|
213
|
+
minimumTokenLength: a = 2,
|
|
214
|
+
minimumScore: f = 1
|
|
215
|
+
} = i, g = { fuzzyMatchThreshold: d, minimumTokenLength: a };
|
|
216
|
+
return e.map((l, h) => {
|
|
217
|
+
const p = K(
|
|
218
|
+
r,
|
|
219
|
+
o,
|
|
220
|
+
G(s(l)),
|
|
221
|
+
g
|
|
222
|
+
);
|
|
223
|
+
return { item: l, score: p, index: h };
|
|
224
|
+
}).filter((l) => l.score >= f).sort((l, h) => h.score !== l.score ? h.score - l.score : l.index - h.index).map(({ item: l }) => l);
|
|
225
|
+
}
|
|
226
|
+
export {
|
|
227
|
+
X as default
|
|
228
|
+
};
|