@mcp-b/wc-support 0.2.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/LICENSE +21 -0
- package/dist/base/sigvelo-element.d.ts +80 -0
- package/dist/base/sigvelo-element.d.ts.map +1 -0
- package/dist/base/sigvelo-element.js +147 -0
- package/dist/base/sigvelo-element.js.map +1 -0
- package/dist/cem-plugins/type-references.d.ts +64 -0
- package/dist/cem-plugins/type-references.d.ts.map +1 -0
- package/dist/cem-plugins/type-references.js +242 -0
- package/dist/cem-plugins/type-references.js.map +1 -0
- package/dist/events/activate.d.ts +25 -0
- package/dist/events/activate.d.ts.map +1 -0
- package/dist/events/activate.js +25 -0
- package/dist/events/activate.js.map +1 -0
- package/dist/events/animation.d.ts +10 -0
- package/dist/events/animation.d.ts.map +1 -0
- package/dist/events/animation.js +7 -0
- package/dist/events/animation.js.map +1 -0
- package/dist/events/content.d.ts +15 -0
- package/dist/events/content.d.ts.map +1 -0
- package/dist/events/content.js +8 -0
- package/dist/events/content.js.map +1 -0
- package/dist/events/copy.d.ts +25 -0
- package/dist/events/copy.d.ts.map +1 -0
- package/dist/events/copy.js +15 -0
- package/dist/events/copy.js.map +1 -0
- package/dist/events/expand-collapse.d.ts +38 -0
- package/dist/events/expand-collapse.d.ts.map +1 -0
- package/dist/events/expand-collapse.js +37 -0
- package/dist/events/expand-collapse.js.map +1 -0
- package/dist/events/filter.d.ts +13 -0
- package/dist/events/filter.d.ts.map +1 -0
- package/dist/events/filter.js +12 -0
- package/dist/events/filter.js.map +1 -0
- package/dist/events/flip.d.ts +15 -0
- package/dist/events/flip.d.ts.map +1 -0
- package/dist/events/flip.js +13 -0
- package/dist/events/flip.js.map +1 -0
- package/dist/events/form.d.ts +29 -0
- package/dist/events/form.d.ts.map +1 -0
- package/dist/events/form.js +31 -0
- package/dist/events/form.js.map +1 -0
- package/dist/events/include.d.ts +28 -0
- package/dist/events/include.d.ts.map +1 -0
- package/dist/events/include.js +15 -0
- package/dist/events/include.js.map +1 -0
- package/dist/events/index.d.ts +23 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +23 -0
- package/dist/events/index.js.map +1 -0
- package/dist/events/intersect.d.ts +15 -0
- package/dist/events/intersect.d.ts.map +1 -0
- package/dist/events/intersect.js +8 -0
- package/dist/events/intersect.js.map +1 -0
- package/dist/events/item.d.ts +18 -0
- package/dist/events/item.d.ts.map +1 -0
- package/dist/events/item.js +13 -0
- package/dist/events/item.js.map +1 -0
- package/dist/events/load.d.ts +25 -0
- package/dist/events/load.d.ts.map +1 -0
- package/dist/events/load.js +24 -0
- package/dist/events/load.js.map +1 -0
- package/dist/events/mutation.d.ts +15 -0
- package/dist/events/mutation.d.ts.map +1 -0
- package/dist/events/mutation.js +8 -0
- package/dist/events/mutation.js.map +1 -0
- package/dist/events/open-close.d.ts +38 -0
- package/dist/events/open-close.d.ts.map +1 -0
- package/dist/events/open-close.js +33 -0
- package/dist/events/open-close.js.map +1 -0
- package/dist/events/page.d.ts +24 -0
- package/dist/events/page.d.ts.map +1 -0
- package/dist/events/page.js +17 -0
- package/dist/events/page.js.map +1 -0
- package/dist/events/progress.d.ts +15 -0
- package/dist/events/progress.d.ts.map +1 -0
- package/dist/events/progress.js +8 -0
- package/dist/events/progress.js.map +1 -0
- package/dist/events/resize.d.ts +15 -0
- package/dist/events/resize.d.ts.map +1 -0
- package/dist/events/resize.js +8 -0
- package/dist/events/resize.js.map +1 -0
- package/dist/events/row.d.ts +19 -0
- package/dist/events/row.d.ts.map +1 -0
- package/dist/events/row.js +8 -0
- package/dist/events/row.js.map +1 -0
- package/dist/events/select.d.ts +16 -0
- package/dist/events/select.d.ts.map +1 -0
- package/dist/events/select.js +8 -0
- package/dist/events/select.js.map +1 -0
- package/dist/events/tabs.d.ts +32 -0
- package/dist/events/tabs.d.ts.map +1 -0
- package/dist/events/tabs.js +21 -0
- package/dist/events/tabs.js.map +1 -0
- package/dist/events/time.d.ts +15 -0
- package/dist/events/time.d.ts.map +1 -0
- package/dist/events/time.js +13 -0
- package/dist/events/time.js.map +1 -0
- package/dist/events/transition.d.ts +10 -0
- package/dist/events/transition.d.ts.map +1 -0
- package/dist/events/transition.js +7 -0
- package/dist/events/transition.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/prefix.d.ts +16 -0
- package/dist/prefix.d.ts.map +1 -0
- package/dist/prefix.js +22 -0
- package/dist/prefix.js.map +1 -0
- package/dist/styles/form-control.styles.d.ts +9 -0
- package/dist/styles/form-control.styles.d.ts.map +1 -0
- package/dist/styles/form-control.styles.js +337 -0
- package/dist/styles/form-control.styles.js.map +1 -0
- package/dist/styles/host.styles.d.ts +4 -0
- package/dist/styles/host.styles.d.ts.map +1 -0
- package/dist/styles/host.styles.js +33 -0
- package/dist/styles/host.styles.js.map +1 -0
- package/dist/utilities/active-element.d.ts +7 -0
- package/dist/utilities/active-element.d.ts.map +1 -0
- package/dist/utilities/active-element.js +16 -0
- package/dist/utilities/active-element.js.map +1 -0
- package/dist/utilities/animate.d.ts +25 -0
- package/dist/utilities/animate.d.ts.map +1 -0
- package/dist/utilities/animate.js +58 -0
- package/dist/utilities/animate.js.map +1 -0
- package/dist/utilities/defined.d.ts +37 -0
- package/dist/utilities/defined.d.ts.map +1 -0
- package/dist/utilities/defined.js +42 -0
- package/dist/utilities/defined.js.map +1 -0
- package/dist/utilities/drag.d.ts +45 -0
- package/dist/utilities/drag.d.ts.map +1 -0
- package/dist/utilities/drag.js +106 -0
- package/dist/utilities/drag.js.map +1 -0
- package/dist/utilities/html.d.ts +5 -0
- package/dist/utilities/html.d.ts.map +1 -0
- package/dist/utilities/html.js +41 -0
- package/dist/utilities/html.js.map +1 -0
- package/dist/utilities/icon-library.d.ts +28 -0
- package/dist/utilities/icon-library.d.ts.map +1 -0
- package/dist/utilities/icon-library.js +36 -0
- package/dist/utilities/icon-library.js.map +1 -0
- package/dist/utilities/index.d.ts +16 -0
- package/dist/utilities/index.d.ts.map +1 -0
- package/dist/utilities/index.js +16 -0
- package/dist/utilities/index.js.map +1 -0
- package/dist/utilities/library.d.ts +19 -0
- package/dist/utilities/library.d.ts.map +1 -0
- package/dist/utilities/library.js +45 -0
- package/dist/utilities/library.js.map +1 -0
- package/dist/utilities/loader.d.ts +36 -0
- package/dist/utilities/loader.d.ts.map +1 -0
- package/dist/utilities/loader.js +139 -0
- package/dist/utilities/loader.js.map +1 -0
- package/dist/utilities/localize.d.ts +62 -0
- package/dist/utilities/localize.d.ts.map +1 -0
- package/dist/utilities/localize.js +128 -0
- package/dist/utilities/localize.js.map +1 -0
- package/dist/utilities/long-press.d.ts +67 -0
- package/dist/utilities/long-press.d.ts.map +1 -0
- package/dist/utilities/long-press.js +125 -0
- package/dist/utilities/long-press.js.map +1 -0
- package/dist/utilities/math.d.ts +9 -0
- package/dist/utilities/math.d.ts.map +1 -0
- package/dist/utilities/math.js +25 -0
- package/dist/utilities/math.js.map +1 -0
- package/dist/utilities/parse.d.ts +5 -0
- package/dist/utilities/parse.d.ts.map +1 -0
- package/dist/utilities/parse.js +10 -0
- package/dist/utilities/parse.js.map +1 -0
- package/dist/utilities/platform.d.ts +10 -0
- package/dist/utilities/platform.d.ts.map +1 -0
- package/dist/utilities/platform.js +30 -0
- package/dist/utilities/platform.js.map +1 -0
- package/dist/utilities/scroll.d.ts +8 -0
- package/dist/utilities/scroll.d.ts.map +1 -0
- package/dist/utilities/scroll.js +33 -0
- package/dist/utilities/scroll.js.map +1 -0
- package/dist/utilities/search.d.ts +20 -0
- package/dist/utilities/search.d.ts.map +1 -0
- package/dist/utilities/search.js +110 -0
- package/dist/utilities/search.js.map +1 -0
- package/package.json +77 -0
- package/src/themes/sigvelo.css +28 -0
- package/src/themes/utilities.css +115 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { isServer } from "lit-html/is-server.js";
|
|
2
|
+
const connectedElements = new Set();
|
|
3
|
+
const translations = new Map();
|
|
4
|
+
let documentDirection = "ltr";
|
|
5
|
+
let documentLanguage = "en";
|
|
6
|
+
let fallback;
|
|
7
|
+
// Sync with `<html dir>` and `<html lang>` at startup and on mutation.
|
|
8
|
+
if (!isServer) {
|
|
9
|
+
documentDirection = document.documentElement.dir || "ltr";
|
|
10
|
+
documentLanguage = document.documentElement.lang || navigator.language;
|
|
11
|
+
new MutationObserver(update).observe(document.documentElement, {
|
|
12
|
+
attributes: true,
|
|
13
|
+
attributeFilter: ["dir", "lang"],
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/** Registers the fallback translation used when no better match is found. */
|
|
17
|
+
export function registerDefaultTranslation(translation) {
|
|
18
|
+
fallback = translation;
|
|
19
|
+
update();
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Registers one or more translations. If a translation with the same language
|
|
23
|
+
* code already exists, the new keys are merged into it.
|
|
24
|
+
*/
|
|
25
|
+
export function registerTranslation(...items) {
|
|
26
|
+
for (const t of items) {
|
|
27
|
+
const code = t.$code.toLowerCase();
|
|
28
|
+
translations.set(code, translations.has(code) ? { ...translations.get(code), ...t } : t);
|
|
29
|
+
}
|
|
30
|
+
update();
|
|
31
|
+
}
|
|
32
|
+
/** Re-reads `<html>` attributes and requests an update on every connected element. */
|
|
33
|
+
export function update() {
|
|
34
|
+
if (isServer)
|
|
35
|
+
return;
|
|
36
|
+
documentDirection = document.documentElement.dir || "ltr";
|
|
37
|
+
documentLanguage = document.documentElement.lang || navigator.language;
|
|
38
|
+
for (const el of connectedElements) {
|
|
39
|
+
if ("requestUpdate" in el && typeof el.requestUpdate === "function") {
|
|
40
|
+
el.requestUpdate();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Resolves the best-matching translations for a language string.
|
|
46
|
+
* Returns a regional match (e.g. `en-gb`) as `primary` and a base-language
|
|
47
|
+
* match (e.g. `en`) as `secondary`.
|
|
48
|
+
*/
|
|
49
|
+
function resolve(lang) {
|
|
50
|
+
const locale = new Intl.Locale(lang.replace(/_/g, "-"));
|
|
51
|
+
const language = locale.language.toLowerCase();
|
|
52
|
+
const region = locale.region?.toLowerCase() ?? "";
|
|
53
|
+
return {
|
|
54
|
+
primary: translations.get(`${language}-${region}`),
|
|
55
|
+
secondary: translations.get(language),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Reactive Controller that localizes terms, dates, numbers, and currency for
|
|
60
|
+
* Lit-based custom elements.
|
|
61
|
+
*
|
|
62
|
+
* Instantiate in a component constructor:
|
|
63
|
+
* ```ts
|
|
64
|
+
* private localize = new LocalizeController(this)
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* The controller automatically re-renders its host when `<html dir>` or
|
|
68
|
+
* `<html lang>` change. To also react to per-element overrides, declare
|
|
69
|
+
* `dir` / `lang` as reactive properties on the host.
|
|
70
|
+
*/
|
|
71
|
+
export class LocalizeController {
|
|
72
|
+
constructor(host) {
|
|
73
|
+
this.host = host;
|
|
74
|
+
this.host.addController(this);
|
|
75
|
+
}
|
|
76
|
+
hostConnected() {
|
|
77
|
+
connectedElements.add(this.host);
|
|
78
|
+
}
|
|
79
|
+
hostDisconnected() {
|
|
80
|
+
connectedElements.delete(this.host);
|
|
81
|
+
}
|
|
82
|
+
/** Returns the host's resolved text direction (`ltr` or `rtl`). */
|
|
83
|
+
dir() {
|
|
84
|
+
return (this.host.dir || documentDirection).toLowerCase();
|
|
85
|
+
}
|
|
86
|
+
/** Returns the host's resolved BCP 47 language tag. */
|
|
87
|
+
lang() {
|
|
88
|
+
return (this.host.lang || documentLanguage).toLowerCase();
|
|
89
|
+
}
|
|
90
|
+
/** Checks whether a translation key exists for the given (or current) language. */
|
|
91
|
+
exists(key, options = {}) {
|
|
92
|
+
const { primary, secondary } = resolve(options.lang ?? this.lang());
|
|
93
|
+
if ((primary && key in primary) || (secondary && key in secondary))
|
|
94
|
+
return true;
|
|
95
|
+
if (options.includeDefault && fallback && key in fallback)
|
|
96
|
+
return true;
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Returns a translated string for the given key. If the value is a function,
|
|
101
|
+
* it is called with the supplied arguments.
|
|
102
|
+
*/
|
|
103
|
+
term(key, ...args) {
|
|
104
|
+
const { primary, secondary } = resolve(this.lang());
|
|
105
|
+
const value = primary?.[key] ?? secondary?.[key] ?? fallback?.[key];
|
|
106
|
+
if (value == null) {
|
|
107
|
+
console.error(`No translation found for: ${String(key)}`);
|
|
108
|
+
return String(key);
|
|
109
|
+
}
|
|
110
|
+
if (typeof value === "function")
|
|
111
|
+
return value(...args);
|
|
112
|
+
return value;
|
|
113
|
+
}
|
|
114
|
+
/** Formats a date using `Intl.DateTimeFormat` in the host's locale. */
|
|
115
|
+
date(value, options) {
|
|
116
|
+
return new Intl.DateTimeFormat(this.lang(), options).format(new Date(value));
|
|
117
|
+
}
|
|
118
|
+
/** Formats a number using `Intl.NumberFormat` in the host's locale. */
|
|
119
|
+
number(value, options) {
|
|
120
|
+
const n = Number(value);
|
|
121
|
+
return Number.isNaN(n) ? "" : new Intl.NumberFormat(this.lang(), options).format(n);
|
|
122
|
+
}
|
|
123
|
+
/** Formats a relative time value (e.g. "3 days ago") in the host's locale. */
|
|
124
|
+
relativeTime(value, unit, options) {
|
|
125
|
+
return new Intl.RelativeTimeFormat(this.lang(), options).format(value, unit);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=localize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localize.js","sourceRoot":"","sources":["../../src/utilities/localize.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAejD,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAe,CAAC;AACjD,MAAM,YAAY,GAAG,IAAI,GAAG,EAA2B,CAAC;AAExD,IAAI,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,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC/E,CAAC;IAED,uEAAuE;IACvE,MAAM,CAAC,KAAsB,EAAE,OAAkC;QAC/D,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QACxB,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACtF,CAAC;IAED,8EAA8E;IAC9E,YAAY,CACV,KAAa,EACb,IAAiC,EACjC,OAAwC;QAExC,OAAO,IAAI,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC/E,CAAC;CACF"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds a configurable long press event to the target element.
|
|
3
|
+
*
|
|
4
|
+
* By default, a `long press` event will be dispatched 700ms after `touchstart` if the user hasn't moved the pointer far
|
|
5
|
+
* from the original position. You can listen for this event with `el.addEventListener('long-press')` like any other
|
|
6
|
+
* event. By design, this utility works with both touch and pointer events. To disable pointer events and only listen to
|
|
7
|
+
* touch, set `ignorePointerEvents` to `true`.
|
|
8
|
+
*
|
|
9
|
+
* The `long-press` event is cancelable and bubbles by default. To prevent browsers (e.g. iOS) from showing touch
|
|
10
|
+
* callouts and text selection, the `-webkit-touch-callout`, `-webkit-user-select`, and `user-select` properties are all
|
|
11
|
+
* set to `none !important` temporarily.
|
|
12
|
+
*
|
|
13
|
+
* The event will start functioning as soon as the constructor is called. A `start()` and `stop()` method can be used to
|
|
14
|
+
* start and stop the event listener programmatically, if needed.
|
|
15
|
+
*
|
|
16
|
+
* @usage
|
|
17
|
+
*
|
|
18
|
+
* const longPress = new LongPress(element);
|
|
19
|
+
*
|
|
20
|
+
* element.addEventListener('long-press', (event) => {
|
|
21
|
+
* // a long press has occurred at originalEvent.clientX, originalEvent.clientY
|
|
22
|
+
* const originalEvent = event.detail.originalEvent;
|
|
23
|
+
* });
|
|
24
|
+
*/
|
|
25
|
+
export declare class LongPress {
|
|
26
|
+
private options;
|
|
27
|
+
private target;
|
|
28
|
+
private timeout;
|
|
29
|
+
private startCoords;
|
|
30
|
+
private wasStarted;
|
|
31
|
+
constructor(el: Element, options?: Partial<LongPressOptions>);
|
|
32
|
+
private handlePress;
|
|
33
|
+
private handleMove;
|
|
34
|
+
private handleRelease;
|
|
35
|
+
/** Starts listening for the long press event. */
|
|
36
|
+
start(): void;
|
|
37
|
+
/** Stops listening for the long press event. */
|
|
38
|
+
stop(): void;
|
|
39
|
+
}
|
|
40
|
+
export declare class LongPressEvent extends Event {
|
|
41
|
+
readonly detail: LongPressEventDetail;
|
|
42
|
+
constructor(eventName: string, eventOptions: EventInit, detail: LongPressEventDetail);
|
|
43
|
+
}
|
|
44
|
+
export interface LongPressEventDetail {
|
|
45
|
+
/** The type of event. This will be `touch` for taps and `pointer` for clicks. */
|
|
46
|
+
type: "touch" | "pointer";
|
|
47
|
+
/** The event that initiated the long press. Useful for determining the target, coordinates, etc. */
|
|
48
|
+
originalEvent: TouchEvent | PointerEvent;
|
|
49
|
+
}
|
|
50
|
+
export interface LongPressOptions {
|
|
51
|
+
/**
|
|
52
|
+
* By default, both touch and pointers events will dispatch a long press event. Set this to `true` to disable pointer
|
|
53
|
+
* events and only listen to touch events.
|
|
54
|
+
*/
|
|
55
|
+
ignorePointerEvents: boolean;
|
|
56
|
+
/** The name of the event to emit. */
|
|
57
|
+
eventName: string;
|
|
58
|
+
/** Options to pass to the event. */
|
|
59
|
+
eventOptions: EventInit;
|
|
60
|
+
/** The amount of time to wait before considering it a long press. */
|
|
61
|
+
duration: number;
|
|
62
|
+
/** The maximum change in movement before the long press is canceled. */
|
|
63
|
+
maxDelta: number;
|
|
64
|
+
/** Whether to override certain styles that prevent touch callouts and user selection during the long press. */
|
|
65
|
+
overrideStyles: boolean;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=long-press.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"long-press.d.ts","sourceRoot":"","sources":["../../src/utilities/long-press.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,OAAO,CAAmB;IAClC,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,OAAO,CAAgC;IAC/C,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,UAAU,CAAS;gBAEf,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC;IAmB5D,OAAO,CAAC,WAAW,CA4BjB;IAEF,OAAO,CAAC,UAAU,CAchB;IAEF,OAAO,CAAC,aAAa,CAEnB;IAEF,iDAAiD;IAC1C,KAAK;IAmBZ,gDAAgD;IACzC,IAAI;CAqBZ;AAED,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAC;gBAE1B,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,EAAE,oBAAoB;CAIrF;AAED,MAAM,WAAW,oBAAoB;IACnC,iFAAiF;IACjF,IAAI,EAAE,OAAO,GAAG,SAAS,CAAC;IAC1B,oGAAoG;IACpG,aAAa,EAAE,UAAU,GAAG,YAAY,CAAC;CAC1C;AAED,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,mBAAmB,EAAE,OAAO,CAAC;IAC7B,qCAAqC;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,oCAAoC;IACpC,YAAY,EAAE,SAAS,CAAC;IACxB,qEAAqE;IACrE,QAAQ,EAAE,MAAM,CAAC;IACjB,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC;IACjB,+GAA+G;IAC/G,cAAc,EAAE,OAAO,CAAC;CACzB"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
const isTouchEnabled = "TouchEvent" in window;
|
|
2
|
+
/**
|
|
3
|
+
* Adds a configurable long press event to the target element.
|
|
4
|
+
*
|
|
5
|
+
* By default, a `long press` event will be dispatched 700ms after `touchstart` if the user hasn't moved the pointer far
|
|
6
|
+
* from the original position. You can listen for this event with `el.addEventListener('long-press')` like any other
|
|
7
|
+
* event. By design, this utility works with both touch and pointer events. To disable pointer events and only listen to
|
|
8
|
+
* touch, set `ignorePointerEvents` to `true`.
|
|
9
|
+
*
|
|
10
|
+
* The `long-press` event is cancelable and bubbles by default. To prevent browsers (e.g. iOS) from showing touch
|
|
11
|
+
* callouts and text selection, the `-webkit-touch-callout`, `-webkit-user-select`, and `user-select` properties are all
|
|
12
|
+
* set to `none !important` temporarily.
|
|
13
|
+
*
|
|
14
|
+
* The event will start functioning as soon as the constructor is called. A `start()` and `stop()` method can be used to
|
|
15
|
+
* start and stop the event listener programmatically, if needed.
|
|
16
|
+
*
|
|
17
|
+
* @usage
|
|
18
|
+
*
|
|
19
|
+
* const longPress = new LongPress(element);
|
|
20
|
+
*
|
|
21
|
+
* element.addEventListener('long-press', (event) => {
|
|
22
|
+
* // a long press has occurred at originalEvent.clientX, originalEvent.clientY
|
|
23
|
+
* const originalEvent = event.detail.originalEvent;
|
|
24
|
+
* });
|
|
25
|
+
*/
|
|
26
|
+
export class LongPress {
|
|
27
|
+
constructor(el, options) {
|
|
28
|
+
this.wasStarted = false;
|
|
29
|
+
this.handlePress = (event) => {
|
|
30
|
+
const x = event instanceof PointerEvent ? event.clientX : event.touches[0].clientX;
|
|
31
|
+
const y = event instanceof PointerEvent ? event.clientY : event.touches[0].clientY;
|
|
32
|
+
// Only listen for one finger touches
|
|
33
|
+
if (isTouchEnabled && event instanceof TouchEvent && event.touches.length > 1) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
this.startCoords = { x, y };
|
|
37
|
+
clearTimeout(this.timeout);
|
|
38
|
+
this.timeout = setTimeout(() => {
|
|
39
|
+
const longPressEvent = new LongPressEvent(this.options.eventName, this.options.eventOptions, {
|
|
40
|
+
type: event.type === "touchstart" ? "touch" : "pointer",
|
|
41
|
+
originalEvent: event,
|
|
42
|
+
});
|
|
43
|
+
this.target.dispatchEvent(longPressEvent);
|
|
44
|
+
}, this.options.duration);
|
|
45
|
+
// Listen for movement
|
|
46
|
+
this.target.addEventListener("touchmove", this.handleMove);
|
|
47
|
+
this.target.addEventListener("touchend", this.handleRelease);
|
|
48
|
+
if (!this.options.ignorePointerEvents) {
|
|
49
|
+
this.target.addEventListener("pointermove", this.handleMove);
|
|
50
|
+
this.target.addEventListener("pointerup", this.handleRelease);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
this.handleMove = (event) => {
|
|
54
|
+
const x = event instanceof PointerEvent ? event.clientX : event.touches[0].clientX;
|
|
55
|
+
const y = event instanceof PointerEvent ? event.clientY : event.touches[0].clientY;
|
|
56
|
+
const deltaX = Math.abs(this.startCoords.x - x);
|
|
57
|
+
const deltaY = Math.abs(this.startCoords.y - y);
|
|
58
|
+
const deltaRoot = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
|
59
|
+
// Cancel the long press if the delta is too big or 2+ finger touches
|
|
60
|
+
if (deltaRoot > this.options.maxDelta ||
|
|
61
|
+
(isTouchEnabled && event instanceof TouchEvent && event.touches.length > 1)) {
|
|
62
|
+
clearTimeout(this.timeout);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
this.handleRelease = () => {
|
|
66
|
+
clearTimeout(this.timeout);
|
|
67
|
+
};
|
|
68
|
+
this.target = el;
|
|
69
|
+
this.options = {
|
|
70
|
+
eventName: "long-press",
|
|
71
|
+
eventOptions: {
|
|
72
|
+
bubbles: true,
|
|
73
|
+
cancelable: true,
|
|
74
|
+
composed: true,
|
|
75
|
+
},
|
|
76
|
+
duration: 700,
|
|
77
|
+
ignorePointerEvents: false,
|
|
78
|
+
maxDelta: 10,
|
|
79
|
+
overrideStyles: true,
|
|
80
|
+
...options,
|
|
81
|
+
};
|
|
82
|
+
this.start();
|
|
83
|
+
}
|
|
84
|
+
/** Starts listening for the long press event. */
|
|
85
|
+
start() {
|
|
86
|
+
if (this.wasStarted)
|
|
87
|
+
return;
|
|
88
|
+
this.wasStarted = true;
|
|
89
|
+
if (this.options.overrideStyles && this.target instanceof HTMLElement) {
|
|
90
|
+
this.target.style.setProperty("-webkit-touch-callout", "none", "important");
|
|
91
|
+
this.target.style.setProperty("-webkit-user-select", "none", "important");
|
|
92
|
+
this.target.style.setProperty("user-select", "none", "important");
|
|
93
|
+
}
|
|
94
|
+
// Listen for touchstart / pointerdown
|
|
95
|
+
this.target.addEventListener("touchstart", this.handlePress);
|
|
96
|
+
if (!this.options.ignorePointerEvents) {
|
|
97
|
+
this.target.addEventListener("pointerdown", this.handlePress);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/** Stops listening for the long press event. */
|
|
101
|
+
stop() {
|
|
102
|
+
clearTimeout(this.timeout);
|
|
103
|
+
this.wasStarted = false;
|
|
104
|
+
if (this.options.overrideStyles && this.target instanceof HTMLElement) {
|
|
105
|
+
this.target.style.removeProperty("-webkit-touch-callout");
|
|
106
|
+
this.target.style.removeProperty("-webkit-user-select");
|
|
107
|
+
this.target.style.removeProperty("user-select");
|
|
108
|
+
}
|
|
109
|
+
this.target.removeEventListener("touchstart", this.handlePress);
|
|
110
|
+
this.target.removeEventListener("touchmove", this.handleMove);
|
|
111
|
+
this.target.removeEventListener("touchend", this.handleRelease);
|
|
112
|
+
if (!this.options.ignorePointerEvents) {
|
|
113
|
+
this.target.removeEventListener("pointerdown", this.handlePress);
|
|
114
|
+
this.target.removeEventListener("pointermove", this.handleMove);
|
|
115
|
+
this.target.removeEventListener("pointerup", this.handleRelease);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export class LongPressEvent extends Event {
|
|
120
|
+
constructor(eventName, eventOptions, detail) {
|
|
121
|
+
super(eventName, eventOptions);
|
|
122
|
+
this.detail = detail;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=long-press.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"long-press.js","sourceRoot":"","sources":["../../src/utilities/long-press.ts"],"names":[],"mappings":"AAAA,MAAM,cAAc,GAAG,YAAY,IAAI,MAAM,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,OAAO,SAAS;IAOpB,YAAY,EAAW,EAAE,OAAmC;QAFpD,eAAU,GAAG,KAAK,CAAC;QAqBnB,gBAAW,GAAG,CAAC,KAAgC,EAAE,EAAE;YACzD,MAAM,CAAC,GAAG,KAAK,YAAY,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;YACnF,MAAM,CAAC,GAAG,KAAK,YAAY,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;YAEnF,qCAAqC;YACrC,IAAI,cAAc,IAAI,KAAK,YAAY,UAAU,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC9E,OAAO;YACT,CAAC;YAED,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;YAE5B,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC3B,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;gBAC7B,MAAM,cAAc,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,I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IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,aAAa,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;YACjE,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,aAAa,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YAChE,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;CACF;AAED,MAAM,OAAO,cAAe,SAAQ,KAAK;IAGvC,YAAY,SAAiB,EAAE,YAAuB,EAAE,MAA4B;QAClF,KAAK,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Guarantees the returned value is between a minimum and maximum number. */
|
|
2
|
+
export declare function clamp(value: number, min: number, max: number): number;
|
|
3
|
+
/** Creates a unique ID with an optional prefix. */
|
|
4
|
+
export declare function createId(prefix?: string): string;
|
|
5
|
+
/** Generates a random integer from min to max. */
|
|
6
|
+
export declare function randomInteger(min: number, max: number): number;
|
|
7
|
+
/** Returns a function that generates a seeded, pseudo random number between 0-1 every time it's called. */
|
|
8
|
+
export declare function seededNumberGenerator(seed: number): () => number;
|
|
9
|
+
//# sourceMappingURL=math.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../../src/utilities/math.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,UAI5D;AAED,mDAAmD;AACnD,wBAAgB,QAAQ,CAAC,MAAM,SAAK,UAEnC;AAED,kDAAkD;AAClD,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,UAErD;AAED,2GAA2G;AAC3G,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,gBAMjD"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Guarantees the returned value is between a minimum and maximum number. */
|
|
2
|
+
export function clamp(value, min, max) {
|
|
3
|
+
if (value < min)
|
|
4
|
+
return min;
|
|
5
|
+
if (value > max)
|
|
6
|
+
return max;
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
/** Creates a unique ID with an optional prefix. */
|
|
10
|
+
export function createId(prefix = "") {
|
|
11
|
+
return prefix + crypto.randomUUID().split("-")[0];
|
|
12
|
+
}
|
|
13
|
+
/** Generates a random integer from min to max. */
|
|
14
|
+
export function randomInteger(min, max) {
|
|
15
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
16
|
+
}
|
|
17
|
+
/** Returns a function that generates a seeded, pseudo random number between 0-1 every time it's called. */
|
|
18
|
+
export function seededNumberGenerator(seed) {
|
|
19
|
+
return function () {
|
|
20
|
+
seed = Math.sin(seed) * 10000;
|
|
21
|
+
seed -= Math.floor(seed);
|
|
22
|
+
return seed;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=math.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math.js","sourceRoot":"","sources":["../../src/utilities/math.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,MAAM,UAAU,KAAK,CAAC,KAAa,EAAE,GAAW,EAAE,GAAW;IAC3D,IAAI,KAAK,GAAG,GAAG;QAAE,OAAO,GAAG,CAAC;IAC5B,IAAI,KAAK,GAAG,GAAG;QAAE,OAAO,GAAG,CAAC;IAC5B,OAAO,KAAK,CAAC;AACf,CAAC;AAED,mDAAmD;AACnD,MAAM,UAAU,QAAQ,CAAC,MAAM,GAAG,EAAE;IAClC,OAAO,MAAM,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC;AAED,kDAAkD;AAClD,MAAM,UAAU,aAAa,CAAC,GAAW,EAAE,GAAW;IACpD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;AAC3D,CAAC;AAED,2GAA2G;AAC3G,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,OAAO;QACL,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;QAC9B,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/utilities/parse.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,SAAS,GAAE,MAAY,GAAG,MAAM,EAAE,CAK9F"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses a delimited set of tokens and returns an array with all whitespace and empty items removed.
|
|
3
|
+
*/
|
|
4
|
+
export function parseDelimitedTokens(input, delimiter = " ") {
|
|
5
|
+
return (input + "")
|
|
6
|
+
.split(delimiter)
|
|
7
|
+
.map((token) => token.trim())
|
|
8
|
+
.filter((token) => token !== "");
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../src/utilities/parse.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAsB,EAAE,YAAoB,GAAG;IAClF,OAAO,CAAC,KAAK,GAAG,EAAE,CAAC;SAChB,KAAK,CAAC,SAAS,CAAC;SAChB,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;SAC5B,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type Platform = "mac" | "windows" | "linux" | "other";
|
|
2
|
+
/** Specific sniff for iOS devices */
|
|
3
|
+
export declare const IS_IOS: boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Detects the current platform using modern APIs with fallbacks. Yes, this is a browser sniff. No, in most cases it
|
|
6
|
+
* shouldn't be used. Currently, the use case is for displaying platform-specific keyboard shortcuts through the
|
|
7
|
+
* `<sigvelo-hotkey>` component which, to the best of my knowledge, can't be reliably feature-detected.
|
|
8
|
+
*/
|
|
9
|
+
export declare function detectPlatform(): Platform;
|
|
10
|
+
//# sourceMappingURL=platform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../../src/utilities/platform.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAE7D,qCAAqC;AACrC,eAAO,MAAM,MAAM,SAA+C,CAAC;AAEnE;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,QAAQ,CAmBzC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Specific sniff for iOS devices */
|
|
2
|
+
export const IS_IOS = /iPad|iPhone|iPod/.test(navigator.userAgent);
|
|
3
|
+
/**
|
|
4
|
+
* Detects the current platform using modern APIs with fallbacks. Yes, this is a browser sniff. No, in most cases it
|
|
5
|
+
* shouldn't be used. Currently, the use case is for displaying platform-specific keyboard shortcuts through the
|
|
6
|
+
* `<sigvelo-hotkey>` component which, to the best of my knowledge, can't be reliably feature-detected.
|
|
7
|
+
*/
|
|
8
|
+
export function detectPlatform() {
|
|
9
|
+
// Try using modern navigator.userAgentData first
|
|
10
|
+
if ("userAgentData" in navigator) {
|
|
11
|
+
const uaData = navigator.userAgentData;
|
|
12
|
+
const platform = uaData.platform.toLowerCase();
|
|
13
|
+
if (platform.includes("mac"))
|
|
14
|
+
return "mac";
|
|
15
|
+
if (platform.includes("win"))
|
|
16
|
+
return "windows";
|
|
17
|
+
if (platform.includes("linux"))
|
|
18
|
+
return "linux";
|
|
19
|
+
}
|
|
20
|
+
// Fallback to userAgent string if userAgentData is not available
|
|
21
|
+
const userAgent = navigator.userAgent.toLowerCase();
|
|
22
|
+
if (/macintosh|mac os x|mac|ipad|iphone|ipod/.test(userAgent))
|
|
23
|
+
return "mac";
|
|
24
|
+
if (/win/.test(userAgent))
|
|
25
|
+
return "windows";
|
|
26
|
+
if (/linux|android|unix|bsd/.test(userAgent))
|
|
27
|
+
return "linux";
|
|
28
|
+
return "other";
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=platform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../../src/utilities/platform.ts"],"names":[],"mappings":"AASA,qCAAqC;AACrC,MAAM,CAAC,MAAM,MAAM,GAAG,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;AAEnE;;;;GAIG;AACH,MAAM,UAAU,cAAc;IAC5B,iDAAiD;IACjD,IAAI,eAAe,IAAI,SAAS,EAAE,CAAC;QACjC,MAAM,MAAM,GAAG,SAAS,CAAC,aAAgC,CAAC;QAC1D,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC;QAE/C,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QAC3C,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC;YAAE,OAAO,SAAS,CAAC;QAC/C,IAAI,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC;YAAE,OAAO,OAAO,CAAC;IACjD,CAAC;IAED,iEAAiE;IACjE,MAAM,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC;IAEpD,IAAI,yCAAyC,CAAC,IAAI,CAAC,SAAS,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5E,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC;QAAE,OAAO,SAAS,CAAC;IAC5C,IAAI,wBAAwB,CAAC,IAAI,CAAC,SAAS,CAAC;QAAE,OAAO,OAAO,CAAC;IAE7D,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prevents scrolling on the document while a modal component is active. If more than one element locks scrolling, it
|
|
3
|
+
* will only be unlocked after all elements unlock it.
|
|
4
|
+
*/
|
|
5
|
+
export declare function lockScrolling(el: Element): void;
|
|
6
|
+
/** Removes a lock and enables scrolling on the document if there are no more locks in place. */
|
|
7
|
+
export declare function unlockScrolling(el: Element): void;
|
|
8
|
+
//# sourceMappingURL=scroll.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scroll.d.ts","sourceRoot":"","sources":["../../src/utilities/scroll.ts"],"names":[],"mappings":"AAUA;;;GAGG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,OAAO,QAQxC;AAED,gGAAgG;AAChG,wBAAgB,eAAe,CAAC,EAAE,EAAE,OAAO,QAc1C"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const locks = new Set();
|
|
2
|
+
const stylesheet = new CSSStyleSheet();
|
|
3
|
+
stylesheet.replaceSync(`
|
|
4
|
+
.sigvelo-scroll-lock {
|
|
5
|
+
scrollbar-gutter: stable !important;
|
|
6
|
+
overflow: hidden !important;
|
|
7
|
+
}
|
|
8
|
+
`);
|
|
9
|
+
/**
|
|
10
|
+
* Prevents scrolling on the document while a modal component is active. If more than one element locks scrolling, it
|
|
11
|
+
* will only be unlocked after all elements unlock it.
|
|
12
|
+
*/
|
|
13
|
+
export function lockScrolling(el) {
|
|
14
|
+
locks.add(el);
|
|
15
|
+
document.documentElement.classList.add("sigvelo-scroll-lock");
|
|
16
|
+
// Add the stylesheet to the document
|
|
17
|
+
if (!document.adoptedStyleSheets.includes(stylesheet)) {
|
|
18
|
+
document.adoptedStyleSheets = [...document.adoptedStyleSheets, stylesheet];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** Removes a lock and enables scrolling on the document if there are no more locks in place. */
|
|
22
|
+
export function unlockScrolling(el) {
|
|
23
|
+
locks.delete(el);
|
|
24
|
+
if (locks.size === 0) {
|
|
25
|
+
document.documentElement.classList.remove("sigvelo-scroll-lock");
|
|
26
|
+
// Remove the stylesheet from the document
|
|
27
|
+
const index = document.adoptedStyleSheets.indexOf(stylesheet);
|
|
28
|
+
if (index > -1) {
|
|
29
|
+
document.adoptedStyleSheets = [...document.adoptedStyleSheets].filter((_sheet, i) => i !== index);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=scroll.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scroll.js","sourceRoot":"","sources":["../../src/utilities/scroll.ts"],"names":[],"mappings":"AAAA,MAAM,KAAK,GAAG,IAAI,GAAG,EAAE,CAAC;AACxB,MAAM,UAAU,GAAG,IAAI,aAAa,EAAE,CAAC;AAEvC,UAAU,CAAC,WAAW,CAAC;;;;;CAKtB,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,EAAW;IACvC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACd,QAAQ,CAAC,eAAe,CAAC,SAAS,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;IAE9D,qCAAqC;IACrC,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QACtD,QAAQ,CAAC,kBAAkB,GAAG,CAAC,GAAG,QAAQ,CAAC,kBAAkB,EAAE,UAAU,CAAC,CAAC;IAC7E,CAAC;AACH,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,eAAe,CAAC,EAAW;IACzC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAEjB,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;QACrB,QAAQ,CAAC,eAAe,CAAC,SAAS,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC;QAEjE,0CAA0C;QAC1C,MAAM,KAAK,GAAG,QAAQ,CAAC,kBAAkB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC9D,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;YACf,QAAQ,CAAC,kBAAkB,GAAG,CAAC,GAAG,QAAQ,CAAC,kBAAkB,CAAC,CAAC,MAAM,CACnE,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,CAC3B,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple case-insensitive search that checks if a query string appears within content.
|
|
3
|
+
*
|
|
4
|
+
* @param query The search string to look for
|
|
5
|
+
* @param content The string to search within
|
|
6
|
+
* @returns a boolean indicating if the query exists within the content
|
|
7
|
+
*/
|
|
8
|
+
export declare function exactSearch(query: string, content: string): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Fuzzy string matching that handles typos, transpositions, and works with any language/script. The higher the
|
|
11
|
+
* threshold (0-1), the pickier it is about matches. 0.7 is a good default that catches most typos while avoiding false
|
|
12
|
+
* positives.
|
|
13
|
+
*
|
|
14
|
+
* @param query The search query to look for
|
|
15
|
+
* @param content The string to search within
|
|
16
|
+
* @param threshold Minimum similarity threshold (0-1), where 1 requires exact match
|
|
17
|
+
* @returns a boolean indicating if the fuzzy match meets the threshold
|
|
18
|
+
*/
|
|
19
|
+
export declare function fuzzySearch(query: string, content: string, threshold?: number): boolean;
|
|
20
|
+
//# sourceMappingURL=search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/utilities/search.ts"],"names":[],"mappings":"AAYA;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,WAEzD;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,SAAM,GAAG,OAAO,CAgFpF"}
|