drab 4.1.7 → 5.0.0-beta.1
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.md +1 -1
- package/README.md +26 -103
- package/animate/define.d.ts +2 -0
- package/animate/define.iife.js +1 -0
- package/animate/define.js +1 -0
- package/animate/index.d.ts +54 -0
- package/animate/index.iife.js +1 -0
- package/animate/index.js +1 -0
- package/base/define.d.ts +2 -0
- package/base/define.iife.js +1 -0
- package/base/define.js +1 -0
- package/base/index.d.ts +69 -0
- package/base/index.iife.js +1 -0
- package/base/index.js +1 -0
- package/breakpoint/define.d.ts +2 -0
- package/breakpoint/define.iife.js +1 -0
- package/breakpoint/define.js +1 -0
- package/breakpoint/index.d.ts +24 -0
- package/breakpoint/index.iife.js +1 -0
- package/breakpoint/index.js +1 -0
- package/chunk-2ZZQECRY.js +1 -0
- package/chunk-57VEEUFG.js +1 -0
- package/chunk-5JV4T7GM.js +1 -0
- package/chunk-6HYPZWQ4.js +1 -0
- package/chunk-7F7CQUEG.js +1 -0
- package/chunk-7KU2PRW5.js +1 -0
- package/chunk-7S6DTKGH.js +1 -0
- package/chunk-FNJ7AESC.js +9 -0
- package/chunk-IQJQPZUL.js +1 -0
- package/chunk-JMJUWKN2.js +1 -0
- package/chunk-MXKU7AKV.js +1 -0
- package/chunk-T7RZI3ZL.js +1 -0
- package/chunk-TSTTUEAF.js +1 -0
- package/chunk-VEVFQB5N.js +1 -0
- package/contextmenu/define.d.ts +2 -0
- package/contextmenu/define.iife.js +1 -0
- package/contextmenu/define.js +1 -0
- package/contextmenu/index.d.ts +15 -0
- package/contextmenu/index.iife.js +1 -0
- package/contextmenu/index.js +1 -0
- package/copy/define.d.ts +2 -0
- package/copy/define.iife.js +1 -0
- package/copy/define.js +1 -0
- package/copy/index.d.ts +13 -0
- package/copy/index.iife.js +1 -0
- package/copy/index.js +1 -0
- package/define/index.d.ts +2 -0
- package/define/index.iife.js +9 -0
- package/define/index.js +1 -0
- package/details/define.d.ts +2 -0
- package/details/define.iife.js +1 -0
- package/details/define.js +1 -0
- package/details/index.d.ts +23 -0
- package/details/index.iife.js +1 -0
- package/details/index.js +1 -0
- package/dialog/define.d.ts +2 -0
- package/dialog/define.iife.js +1 -0
- package/dialog/define.js +1 -0
- package/dialog/index.d.ts +20 -0
- package/dialog/index.iife.js +1 -0
- package/dialog/index.js +1 -0
- package/editor/define.d.ts +2 -0
- package/editor/define.iife.js +9 -0
- package/editor/define.js +1 -0
- package/editor/index.d.ts +58 -0
- package/editor/index.iife.js +9 -0
- package/editor/index.js +1 -0
- package/fullscreen/define.d.ts +2 -0
- package/fullscreen/define.iife.js +1 -0
- package/fullscreen/define.js +1 -0
- package/fullscreen/index.d.ts +23 -0
- package/fullscreen/index.iife.js +1 -0
- package/fullscreen/index.js +1 -0
- package/index-SyRipepB.d.ts +17 -0
- package/index.d.ts +14 -0
- package/index.iife.js +9 -0
- package/index.js +1 -0
- package/package.json +130 -59
- package/popover/define.d.ts +2 -0
- package/popover/define.iife.js +1 -0
- package/popover/define.js +1 -0
- package/popover/index.d.ts +29 -0
- package/popover/index.iife.js +1 -0
- package/popover/index.js +1 -0
- package/share/define.d.ts +2 -0
- package/share/define.iife.js +1 -0
- package/share/define.js +1 -0
- package/share/index.d.ts +19 -0
- package/share/index.iife.js +1 -0
- package/share/index.js +1 -0
- package/tablesort/define.d.ts +2 -0
- package/tablesort/define.iife.js +1 -0
- package/tablesort/define.js +1 -0
- package/tablesort/index.d.ts +21 -0
- package/tablesort/index.iife.js +1 -0
- package/tablesort/index.js +1 -0
- package/youtube/define.d.ts +2 -0
- package/youtube/define.iife.js +1 -0
- package/youtube/define.js +1 -0
- package/youtube/index.d.ts +29 -0
- package/youtube/index.iife.js +1 -0
- package/youtube/index.js +1 -0
- package/dist/components/Breakpoint.svelte +0 -55
- package/dist/components/Breakpoint.svelte.d.ts +0 -46
- package/dist/components/ContextMenu.svelte +0 -150
- package/dist/components/ContextMenu.svelte.d.ts +0 -76
- package/dist/components/CopyButton.svelte +0 -97
- package/dist/components/CopyButton.svelte.d.ts +0 -60
- package/dist/components/DataTable.svelte +0 -208
- package/dist/components/DataTable.svelte.d.ts +0 -155
- package/dist/components/Details.svelte +0 -101
- package/dist/components/Details.svelte.d.ts +0 -67
- package/dist/components/Editor.svelte +0 -404
- package/dist/components/Editor.svelte.d.ts +0 -111
- package/dist/components/FrettedChord.svelte +0 -213
- package/dist/components/FrettedChord.svelte.d.ts +0 -79
- package/dist/components/FullscreenButton.svelte +0 -95
- package/dist/components/FullscreenButton.svelte.d.ts +0 -62
- package/dist/components/Popover.svelte +0 -153
- package/dist/components/Popover.svelte.d.ts +0 -80
- package/dist/components/ShareButton.svelte +0 -133
- package/dist/components/ShareButton.svelte.d.ts +0 -93
- package/dist/components/Sheet.svelte +0 -180
- package/dist/components/Sheet.svelte.d.ts +0 -99
- package/dist/components/Tablature.svelte +0 -173
- package/dist/components/Tablature.svelte.d.ts +0 -93
- package/dist/components/YouTube.svelte +0 -51
- package/dist/components/YouTube.svelte.d.ts +0 -49
- package/dist/index.d.ts +0 -14
- package/dist/index.js +0 -14
- package/dist/util/accessibility.d.ts +0 -6
- package/dist/util/accessibility.js +0 -11
- package/dist/util/delay.d.ts +0 -1
- package/dist/util/delay.js +0 -1
- package/dist/util/transition.d.ts +0 -2
- package/dist/util/transition.js +0 -2
package/LICENSE.md
CHANGED
package/README.md
CHANGED
@@ -1,131 +1,54 @@
|
|
1
|
-
#
|
1
|
+
# A Headless Custom Element Library
|
2
2
|
|
3
3
|
- [Docs](https://drab.robino.dev)
|
4
4
|
- [GitHub](https://github.com/rossrobino/drab)
|
5
5
|
- [npm](https://www.npmjs.com/package/drab)
|
6
6
|
- [MIT License](https://github.com/rossrobino/drab/blob/main/LICENSE.md)
|
7
7
|
|
8
|
-
##
|
8
|
+
## Features
|
9
9
|
|
10
|
-
**drab** focuses on providing JavaScript functionality where it's most useful. Many of the
|
10
|
+
**drab** focuses on providing JavaScript functionality where it's most useful. Many of the elements are helpful wrappers around browser APIs. Here are some of the features of the library.
|
11
11
|
|
12
|
-
|
13
|
-
- Whenever possible, components are [progressively enhanced](https://drab.robino.dev/docs/ShareButton) or provide a fallback [noscript](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/noscript) message
|
14
|
-
- Transitions are disabled for users who prefer reduced motion
|
15
|
-
- All components support server side rendering--they will not break your application depending on your rendering preferences
|
12
|
+
### Built on the web platform
|
16
13
|
|
17
|
-
|
14
|
+
- Each element is a [custom element](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements). So you can use them [with a framework](https://custom-elements-everywhere.com/), without one, or even directly in a markdown file. These components will work [regardless of your project's architecture](https://jakelazaroff.com/words/web-components-will-outlive-your-javascript-framework/).
|
15
|
+
- **drab** does _not_ use the [shadow DOM](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM), so you can style content within these elements as usual with CSS.
|
16
|
+
- Since you provide the HTML, these elements can take advantage of what JavaScript frameworks excel at---creating reusable markup that can be server side rendered.
|
17
|
+
- Each element can be imported, extended, named, and used however you see fit.
|
18
18
|
|
19
|
-
|
19
|
+
### Minimal bundle size
|
20
20
|
|
21
|
-
|
21
|
+
- **drab** has zero dependencies.
|
22
22
|
|
23
|
-
|
24
|
-
- [Astro](https://docs.astro.build/en/tutorial/1-setup/2/)
|
25
|
-
- [Vite](https://vitejs.dev/guide/)
|
23
|
+
### Write JavaScript, or don't
|
26
24
|
|
27
|
-
|
28
|
-
|
29
|
-
```
|
25
|
+
- Elements can be installed as a package (recommended), or utilized without writing any JavaScript by adding a script tag to your document.
|
26
|
+
- Each element can be configured through HTML attributes.
|
30
27
|
|
31
|
-
|
28
|
+
### Built in animations
|
32
29
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
**drab** is a collection of useful components, not a complete UI kit. If **drab** isn't what you are looking for, here are some other libraries to check out.
|
38
|
-
|
39
|
-
- [uico](https://uico.robino.dev) - a Tailwind plugin for CSS components designed to be complementary to **drab** (used to create this site)
|
40
|
-
- [daisyUI](https://daisyui.com/)
|
41
|
-
- [Skeleton](https://skeleton.dev)
|
42
|
-
- [Carbon Components](https://carbon-components-svelte.onrender.com/)
|
43
|
-
- [Melt UI](https://www.melt-ui.com/)
|
44
|
-
- [shadcn-svelte](https://www.shadcn-svelte.com/)
|
45
|
-
- [Svelte-HeadlessUI](https://captaincodeman.github.io/svelte-headlessui/)
|
46
|
-
|
47
|
-
## Styling
|
48
|
-
|
49
|
-
Components without styles can appear rather drab. You have the freedom to bring your own styles to these components. Using unstyled components allows you to selectively choose what you need and avoid being tied to any specific library.
|
50
|
-
|
51
|
-
To style the markup provided by the components, you can make use of [global styles](https://joyofcode.xyz/global-styles-in-sveltekit). Each component exports `class` and `id` props that can be leveraged for this purpose. This process can be expedited by utilizing CSS frameworks like [TailwindCSS](https://tailwindcss.com/). Tailwind generates a global stylesheet based on the utility classes used in your project. The examples in this documentation are styled with Tailwind with the [uico](https://uico.robino.dev) and [typography](https://tailwindcss.com/docs/typography-plugin) plugins. Tailwind does not have to be used with this library.
|
52
|
-
|
53
|
-
### Stylesheet
|
54
|
-
|
55
|
-
Here's a SvelteKit example using CSS imported in a layout. By using a layout, these styles can be accessed anywhere.
|
56
|
-
|
57
|
-
```css
|
58
|
-
/* src/app.css */
|
59
|
-
.button {
|
60
|
-
border-radius: 5px;
|
61
|
-
background-color: black;
|
62
|
-
padding: 5px;
|
63
|
-
color: white;
|
64
|
-
}
|
65
|
-
```
|
66
|
-
|
67
|
-
```svelte
|
68
|
-
<!-- src/routes/+layout.svelte -->
|
69
|
-
<script>
|
70
|
-
import "../app.css";
|
71
|
-
</script>
|
72
|
-
|
73
|
-
<slot />
|
74
|
-
```
|
75
|
-
|
76
|
-
```svelte
|
77
|
-
<!-- src/routes/+page.svelte -->
|
78
|
-
<script>
|
79
|
-
import { FullscreenButton } from "drab";
|
80
|
-
</script>
|
81
|
-
|
82
|
-
<FullscreenButton class="button" />
|
83
|
-
```
|
84
|
-
|
85
|
-
### Global modifier
|
86
|
-
|
87
|
-
Alternatively, the [`:global()` modifier](https://svelte.dev/docs/svelte-components#style) can be used instead of a separate stylesheet.
|
88
|
-
|
89
|
-
```svelte
|
90
|
-
<!-- src/routes/+page.svelte -->
|
91
|
-
<script>
|
92
|
-
import { FullscreenButton } from "drab";
|
93
|
-
</script>
|
94
|
-
|
95
|
-
<FullscreenButton class="button" />
|
96
|
-
|
97
|
-
<style>
|
98
|
-
:global(.button) {
|
99
|
-
border-radius: 5px;
|
100
|
-
background-color: black;
|
101
|
-
padding: 5px;
|
102
|
-
color: white;
|
103
|
-
}
|
104
|
-
</style>
|
105
|
-
```
|
30
|
+
- Uses the [web animations API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API) for transitions.
|
31
|
+
- Transitions are disabled for users who prefer reduced motion.
|
32
|
+
- Extend the `Animate` element to build your own elements.
|
106
33
|
|
107
34
|
## Contributing
|
108
35
|
|
109
|
-
Find an bug or have an idea? Feel free to create an issue on [GitHub](https://github.com/rossrobino/drab).
|
36
|
+
Find an bug or have an idea? Feel free to create an issue on [GitHub](https://github.com/rossrobino/drab).
|
110
37
|
|
111
|
-
|
112
|
-
|
113
|
-
Since this is an unstyled library, simple components like a badge that can be easily created with HTML and CSS are not included.
|
38
|
+
Since this is an headless library, simple components like a badge that can be easily created with HTML and CSS are not included.
|
114
39
|
|
115
40
|
### Local Development
|
116
41
|
|
117
|
-
|
118
|
-
|
119
|
-
#### Make changes
|
42
|
+
This library is built with [Vite](https://vitejs.dev), [domco](https://domco.robino.dev), and TypeScript. The package contents are located in `src/package`.
|
120
43
|
|
121
44
|
1. Clone the [repository](https://github.com/rossrobino/drab)
|
122
45
|
2. `bun i`
|
123
46
|
3. `bun dev`
|
124
47
|
|
125
|
-
|
48
|
+
### Making changes
|
126
49
|
|
127
|
-
1. Add or edit the
|
128
|
-
2. Add or edit the example in `src/
|
129
|
-
3.
|
130
|
-
4.
|
131
|
-
5.
|
50
|
+
1. Add or edit the element in `src/package`---each element should extend `Base` or `Animate`. Each element has a `index.ts` file with the source code, and then a `define.ts` file where it is imported and called for use with a CDN.
|
51
|
+
2. Add or edit the example in `src/docs`.
|
52
|
+
3. Export the element from `src/package/index.ts`.
|
53
|
+
4. Run `bun doc` to document your element with [TypeDoc](https://typedoc.org/).
|
54
|
+
5. Add the element as an entry point to `tsup.config.ts`, then run `bun package` to build with [tsup](https://tsup.egoist.dev/).
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";(()=>{var m=class extends HTMLElement{#e=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(s){this.setAttribute("event",s)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(s=HTMLElement){let n=this.querySelector(this.getAttribute("content")??"[data-content]");if(n instanceof s)return n;throw new Error("Content not found")}swapContent(s=!0,n=800){let e=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(e){let t=Array.from(this.getContent().childNodes);e instanceof HTMLTemplateElement?this.getContent().replaceChildren(e.content.cloneNode(!0)):this.getContent().replaceChildren(...e.childNodes),s&&setTimeout(()=>this.getContent().replaceChildren(...t),n)}}safeListener(s,n,e=document.body,t={}){t.signal=this.#e.signal,e.addEventListener(s,n,t)}triggerListener(s,n=this.event){for(let e of this.getTrigger())e.addEventListener(n,s)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}disconnectedCallback(){this.#e.abort()}};var f=class extends m{constructor(){super()}get animationOptions(){let s={};for(let n of this.getAttributeNames())if(n.startsWith("animation-option-")){let e=this.getAttribute(n),[,,t]=n.split("-");e&&(t==="duration"||t==="delay"?s[t]=Number(e):t==="easing"&&(s[t]=e))}return s}async animateElement(s={element:this.getContent(),options:{}}){let{element:n=this.getContent(),options:e={}}=s,t=this.keyframes;if(t.length&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches){e=Object.assign(this.animationOptions,e),e.duration||(e.duration=200),e.easing||(e.easing="ease-in-out");let r=t.at(0),i=t.at(-1);if(r&&i){let a=["composite","easing","offset"];for(let l of a)delete r[l],delete i[l]}e.direction?.includes("reverse")&&([r,i]=[i,r]),Object.assign(n.style,r),await n.animate(t,e).finished,Object.assign(n.style,i)}}get keyframes(){let s=[];for(let n of this.getAttributeNames()){let e=this.getAttribute(n),[,,t,...r]=n.split("-");if(n.startsWith("animation-keyframe-")){let i=r.map((o,a)=>a<1?o:o.at(0)?.toUpperCase()+o.slice(1)).join("");if(t&&i){t==="from"?t="0":t==="to"?t="1":t=String(parseInt(t)*.01);let o=Number(t),a=s.find(l=>l.offset===o);a?a[i]=e:s.push({[i]:e,offset:o})}}}return s.sort((n,e)=>Number(n.offset)-Number(e.offset)),s}};customElements.define("drab-animate",f);})();
|
@@ -0,0 +1 @@
|
|
1
|
+
import{a as e}from"../chunk-7KU2PRW5.js";import"../chunk-MXKU7AKV.js";customElements.define("drab-animate",e);
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import { Base } from '../base/index.js';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* The `Animate` base class provides a declarative way to use the
|
5
|
+
* [Web Animations API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API)
|
6
|
+
* through HTML attributes. The `animateElement` method uses these attributes and
|
7
|
+
* persists the final animation state. Other elements in **drab** extend this class
|
8
|
+
* to provide animations. You can also extend this class to create your own custom
|
9
|
+
* animated element.
|
10
|
+
*
|
11
|
+
* Keyframes can be set via HTML attributes on the element in the form of:
|
12
|
+
*
|
13
|
+
* ```html
|
14
|
+
* <drab-animate animation-keyframe-offset-property="value">
|
15
|
+
* ```
|
16
|
+
*
|
17
|
+
* `offset` can be `to`, `from`, or a `number`.
|
18
|
+
*
|
19
|
+
* `property` can be any animatable CSS property separated by dashes.
|
20
|
+
*
|
21
|
+
* Animations `options` can be set:
|
22
|
+
*
|
23
|
+
* ```html
|
24
|
+
* <drab-animate animation-option-property="value">
|
25
|
+
* ```
|
26
|
+
*
|
27
|
+
* `property` can be `duration`, `delay`, or `easing`.
|
28
|
+
*/
|
29
|
+
declare class Animate extends Base {
|
30
|
+
constructor();
|
31
|
+
/**
|
32
|
+
* @returns An object containing the values of each `animation-option` attribute
|
33
|
+
*/
|
34
|
+
get animationOptions(): KeyframeAnimationOptions;
|
35
|
+
/**
|
36
|
+
* @description
|
37
|
+
* Animates a particular element using the web animations API.
|
38
|
+
*
|
39
|
+
* - Disables animation if the user prefers reduced motion.
|
40
|
+
* - Sets default options
|
41
|
+
* - Uses the keyframes provided from `this.keyframes`
|
42
|
+
* - Waits for the animation to complete
|
43
|
+
* - Sets the start and end styles based on the first and last keyframe
|
44
|
+
*
|
45
|
+
* @param animateOptions - animates `this.content()` by default
|
46
|
+
*/
|
47
|
+
animateElement(animateOptions?: {
|
48
|
+
element?: HTMLElement;
|
49
|
+
options?: KeyframeAnimationOptions;
|
50
|
+
}): Promise<void>;
|
51
|
+
get keyframes(): Keyframe[];
|
52
|
+
}
|
53
|
+
|
54
|
+
export { Animate };
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";(()=>{var f=class extends HTMLElement{#e=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(s){this.setAttribute("event",s)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(s=HTMLElement){let n=this.querySelector(this.getAttribute("content")??"[data-content]");if(n instanceof s)return n;throw new Error("Content not found")}swapContent(s=!0,n=800){let e=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(e){let t=Array.from(this.getContent().childNodes);e instanceof HTMLTemplateElement?this.getContent().replaceChildren(e.content.cloneNode(!0)):this.getContent().replaceChildren(...e.childNodes),s&&setTimeout(()=>this.getContent().replaceChildren(...t),n)}}safeListener(s,n,e=document.body,t={}){t.signal=this.#e.signal,e.addEventListener(s,n,t)}triggerListener(s,n=this.event){for(let e of this.getTrigger())e.addEventListener(n,s)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}disconnectedCallback(){this.#e.abort()}};var m=class extends f{constructor(){super()}get animationOptions(){let s={};for(let n of this.getAttributeNames())if(n.startsWith("animation-option-")){let e=this.getAttribute(n),[,,t]=n.split("-");e&&(t==="duration"||t==="delay"?s[t]=Number(e):t==="easing"&&(s[t]=e))}return s}async animateElement(s={element:this.getContent(),options:{}}){let{element:n=this.getContent(),options:e={}}=s,t=this.keyframes;if(t.length&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches){e=Object.assign(this.animationOptions,e),e.duration||(e.duration=200),e.easing||(e.easing="ease-in-out");let r=t.at(0),i=t.at(-1);if(r&&i){let a=["composite","easing","offset"];for(let l of a)delete r[l],delete i[l]}e.direction?.includes("reverse")&&([r,i]=[i,r]),Object.assign(n.style,r),await n.animate(t,e).finished,Object.assign(n.style,i)}}get keyframes(){let s=[];for(let n of this.getAttributeNames()){let e=this.getAttribute(n),[,,t,...r]=n.split("-");if(n.startsWith("animation-keyframe-")){let i=r.map((o,a)=>a<1?o:o.at(0)?.toUpperCase()+o.slice(1)).join("");if(t&&i){t==="from"?t="0":t==="to"?t="1":t=String(parseInt(t)*.01);let o=Number(t),a=s.find(l=>l.offset===o);a?a[i]=e:s.push({[i]:e,offset:o})}}}return s.sort((n,e)=>Number(n.offset)-Number(e.offset)),s}};})();
|
package/animate/index.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
import{a}from"../chunk-7KU2PRW5.js";import"../chunk-MXKU7AKV.js";export{a as Animate};
|
package/base/define.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";(()=>{var s=class extends HTMLElement{#e=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(e){this.setAttribute("event",e)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(e=HTMLElement){let t=this.querySelector(this.getAttribute("content")??"[data-content]");if(t instanceof e)return t;throw new Error("Content not found")}swapContent(e=!0,t=800){let n=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(n){let r=Array.from(this.getContent().childNodes);n instanceof HTMLTemplateElement?this.getContent().replaceChildren(n.content.cloneNode(!0)):this.getContent().replaceChildren(...n.childNodes),e&&setTimeout(()=>this.getContent().replaceChildren(...r),t)}}safeListener(e,t,n=document.body,r={}){r.signal=this.#e.signal,n.addEventListener(e,t,r)}triggerListener(e,t=this.event){for(let n of this.getTrigger())n.addEventListener(t,e)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}disconnectedCallback(){this.#e.abort()}};customElements.define("drab-base",s);})();
|
package/base/define.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
import{b as e}from"../chunk-MXKU7AKV.js";customElements.define("drab-base",e);
|
package/base/index.d.ts
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
/**
|
2
|
+
* Each element in the library extends the `Base` class. It provides methods
|
3
|
+
* for selecting elements via HTML attributes along with other helpers.
|
4
|
+
*
|
5
|
+
* By default, `trigger`s and `content` will be selected via the `data-trigger` and
|
6
|
+
* `data-content` attributes. Alternatively, you can set the `trigger` or
|
7
|
+
* `content` attribute to a CSS selector to change the default selector from
|
8
|
+
* `[data-trigger]` or `[data-content]` to a selector of your choosing.
|
9
|
+
* This can be useful if you have multiple elements within one another.
|
10
|
+
*
|
11
|
+
* Each element can have multiple `trigger`s, but will only have one `content`.
|
12
|
+
*/
|
13
|
+
declare class Base extends HTMLElement {
|
14
|
+
#private;
|
15
|
+
constructor();
|
16
|
+
/**
|
17
|
+
* Event for the `trigger` to execute.
|
18
|
+
*
|
19
|
+
* For example, set to `"mouseover"` to execute the event when the user hovers the mouse over the `trigger`, instead of when they click it.
|
20
|
+
*
|
21
|
+
* @default "click"
|
22
|
+
*/
|
23
|
+
get event(): keyof HTMLElementEventMap;
|
24
|
+
set event(value: keyof HTMLElementEventMap);
|
25
|
+
/**
|
26
|
+
* @returns All of the elements that match the `trigger` selector.
|
27
|
+
* @default this.querySelectorAll("[data-trigger]")
|
28
|
+
*/
|
29
|
+
getTrigger(): NodeListOf<HTMLElement>;
|
30
|
+
/**
|
31
|
+
* @param instance The instance of the desired element, ex: `HTMLDialogElement`.
|
32
|
+
* Defaults to `HTMLElement`.
|
33
|
+
* @returns The element that matches the `content` selector.
|
34
|
+
* @default this.querySelector("[data-content]")
|
35
|
+
*/
|
36
|
+
getContent<T extends HTMLElement = HTMLElement>(instance?: {
|
37
|
+
new (): T;
|
38
|
+
}): T;
|
39
|
+
/**
|
40
|
+
* Finds the `HTMLElement | HTMLTemplateElement` via the `swap` selector and
|
41
|
+
* swaps `this.content()` with the content of the element found.
|
42
|
+
*
|
43
|
+
* @param revert Swap back to old content
|
44
|
+
* @param delay Wait time before swapping back
|
45
|
+
*/
|
46
|
+
swapContent(revert?: boolean, delay?: number): void;
|
47
|
+
/**
|
48
|
+
* Wrapper around `document.body.addEventListener` that ensures when the
|
49
|
+
* element is removed from the DOM, these event listeners are cleaned up.
|
50
|
+
* @param type
|
51
|
+
* @param listener
|
52
|
+
* @param options
|
53
|
+
*/
|
54
|
+
safeListener<K extends keyof HTMLElementEventMap, T extends HTMLElement | Window | Document = HTMLElement>(type: K, listener: (this: T, ev: HTMLElementEventMap[K]) => any, element?: T, options?: AddEventListenerOptions): void;
|
55
|
+
/**
|
56
|
+
* @param listener Listener to attach to all of the `trigger` elements.
|
57
|
+
*/
|
58
|
+
triggerListener<T extends HTMLElement, K extends keyof HTMLElementEventMap>(listener: (this: T, ev: HTMLElementEventMap[K]) => any, type?: K): void;
|
59
|
+
/**
|
60
|
+
* Placeholder function is passed into `queueMicrotask` in `connectedCallback`. It is overridden in each component that needs to run `connectedCallback`.
|
61
|
+
*
|
62
|
+
* The reason for this is to make these elements work better with frameworks like Svelte. For SSR this isn't necessary, but when client side rendering, the HTML within the custom element isn't available before `connectedCallback` is called. By waiting until the next microtask, the HTML content is available---then for example, listeners can be attached to elements inside.
|
63
|
+
*/
|
64
|
+
mount(): void;
|
65
|
+
connectedCallback(): void;
|
66
|
+
disconnectedCallback(): void;
|
67
|
+
}
|
68
|
+
|
69
|
+
export { Base };
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";(()=>{var s=class extends HTMLElement{#e=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(e){this.setAttribute("event",e)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(e=HTMLElement){let t=this.querySelector(this.getAttribute("content")??"[data-content]");if(t instanceof e)return t;throw new Error("Content not found")}swapContent(e=!0,t=800){let n=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(n){let r=Array.from(this.getContent().childNodes);n instanceof HTMLTemplateElement?this.getContent().replaceChildren(n.content.cloneNode(!0)):this.getContent().replaceChildren(...n.childNodes),e&&setTimeout(()=>this.getContent().replaceChildren(...r),t)}}safeListener(e,t,n=document.body,r={}){r.signal=this.#e.signal,n.addEventListener(e,t,r)}triggerListener(e,t=this.event){for(let n of this.getTrigger())n.addEventListener(t,e)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}disconnectedCallback(){this.#e.abort()}};})();
|
package/base/index.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
import{b as a}from"../chunk-MXKU7AKV.js";export{a as Base};
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";(()=>{var r=class extends HTMLElement{#t=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(t){this.setAttribute("event",t)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(t=HTMLElement){let e=this.querySelector(this.getAttribute("content")??"[data-content]");if(e instanceof t)return e;throw new Error("Content not found")}swapContent(t=!0,e=800){let n=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(n){let i=Array.from(this.getContent().childNodes);n instanceof HTMLTemplateElement?this.getContent().replaceChildren(n.content.cloneNode(!0)):this.getContent().replaceChildren(...n.childNodes),t&&setTimeout(()=>this.getContent().replaceChildren(...i),e)}}safeListener(t,e,n=document.body,i={}){i.signal=this.#t.signal,n.addEventListener(t,e,i)}triggerListener(t,e=this.event){for(let n of this.getTrigger())n.addEventListener(e,t)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}disconnectedCallback(){this.#t.abort()}};var s=class extends r{breakpoints=[{name:"sm",width:640},{name:"md",width:768},{name:"lg",width:1024},{name:"xl",width:1280},{name:"2xl",width:1536}];constructor(){super();let t=[];for(let e of this.getAttributeNames())if(e.startsWith("breakpoint-")){let[,...n]=e.split("-");n&&t.push({name:n.join("-"),width:Number(this.getAttribute(e))})}t.length&&(this.breakpoints=t),this.breakpoints.sort((e,n)=>n.width-e.width)}get breakpoint(){for(let t=0;t<this.breakpoints.length;t++){let e=this.breakpoints[t];if(e&&window.innerWidth>e.width)return e.name}return"none"}mount(){let t=()=>this.getContent().innerHTML=`${this.breakpoint}:${window.innerWidth}`;t(),this.safeListener("resize",t,window)}};customElements.define("drab-breakpoint",s);})();
|
@@ -0,0 +1 @@
|
|
1
|
+
import{a as e}from"../chunk-6HYPZWQ4.js";import"../chunk-MXKU7AKV.js";customElements.define("drab-breakpoint",e);
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import { Base } from '../base/index.js';
|
2
|
+
|
3
|
+
type Breakpoints = {
|
4
|
+
name: string;
|
5
|
+
width: number;
|
6
|
+
}[];
|
7
|
+
/**
|
8
|
+
* Displays the current breakpoint and `window.innerWidth`, based on the `breakpoints` provided. Defaults to [TailwindCSS breakpoint sizes](https://tailwindcss.com/docs/responsive-design).
|
9
|
+
*
|
10
|
+
* Provide alternate breakpoints by specifying `breakpoint` attributes:
|
11
|
+
*
|
12
|
+
* ```html
|
13
|
+
* <drab-breakpoint breakpoint-name="400">
|
14
|
+
* ```
|
15
|
+
*/
|
16
|
+
declare class Breakpoint extends Base {
|
17
|
+
breakpoints: Breakpoints;
|
18
|
+
constructor();
|
19
|
+
/** finds the current breakpoint */
|
20
|
+
get breakpoint(): string;
|
21
|
+
mount(): void;
|
22
|
+
}
|
23
|
+
|
24
|
+
export { Breakpoint, type Breakpoints };
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";(()=>{var r=class extends HTMLElement{#t=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(t){this.setAttribute("event",t)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(t=HTMLElement){let e=this.querySelector(this.getAttribute("content")??"[data-content]");if(e instanceof t)return e;throw new Error("Content not found")}swapContent(t=!0,e=800){let n=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(n){let i=Array.from(this.getContent().childNodes);n instanceof HTMLTemplateElement?this.getContent().replaceChildren(n.content.cloneNode(!0)):this.getContent().replaceChildren(...n.childNodes),t&&setTimeout(()=>this.getContent().replaceChildren(...i),e)}}safeListener(t,e,n=document.body,i={}){i.signal=this.#t.signal,n.addEventListener(t,e,i)}triggerListener(t,e=this.event){for(let n of this.getTrigger())n.addEventListener(e,t)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}disconnectedCallback(){this.#t.abort()}};var s=class extends r{breakpoints=[{name:"sm",width:640},{name:"md",width:768},{name:"lg",width:1024},{name:"xl",width:1280},{name:"2xl",width:1536}];constructor(){super();let t=[];for(let e of this.getAttributeNames())if(e.startsWith("breakpoint-")){let[,...n]=e.split("-");n&&t.push({name:n.join("-"),width:Number(this.getAttribute(e))})}t.length&&(this.breakpoints=t),this.breakpoints.sort((e,n)=>n.width-e.width)}get breakpoint(){for(let t=0;t<this.breakpoints.length;t++){let e=this.breakpoints[t];if(e&&window.innerWidth>e.width)return e.name}return"none"}mount(){let t=()=>this.getContent().innerHTML=`${this.breakpoint}:${window.innerWidth}`;t(),this.safeListener("resize",t,window)}};})();
|
@@ -0,0 +1 @@
|
|
1
|
+
import{a}from"../chunk-6HYPZWQ4.js";import"../chunk-MXKU7AKV.js";export{a as Breakpoint};
|
@@ -0,0 +1 @@
|
|
1
|
+
import{a as h}from"./chunk-VEVFQB5N.js";import{a as E}from"./chunk-FNJ7AESC.js";import{a as x}from"./chunk-5JV4T7GM.js";import{a as L}from"./chunk-T7RZI3ZL.js";import{a as M}from"./chunk-IQJQPZUL.js";import{a as g}from"./chunk-57VEEUFG.js";import{a as T}from"./chunk-TSTTUEAF.js";import{a as b}from"./chunk-JMJUWKN2.js";import{a as y}from"./chunk-7S6DTKGH.js";import{a as u}from"./chunk-7KU2PRW5.js";import{a as d}from"./chunk-6HYPZWQ4.js";import{a as H,b as s}from"./chunk-MXKU7AKV.js";var A={};H(A,{Animate:()=>u,Base:()=>s,Breakpoint:()=>d,ContextMenu:()=>g,Copy:()=>T,Details:()=>b,Dialog:()=>y,Editor:()=>E,Fullscreen:()=>x,Popover:()=>L,Share:()=>M,TableSort:()=>i,YouTube:()=>h});var i=class extends s{constructor(){super()}mount(){let r=this.getContent(HTMLTableSectionElement);for(let e of this.getTrigger())e.addEventListener(this.event,()=>{Array.from(r.querySelectorAll("tr")).sort(B(e,e.toggleAttribute("data-ascending"))).forEach(o=>r.appendChild(o))})}},B=(t,r)=>(o,a)=>{let c=Array.from(t.parentNode?.children??[]).indexOf(t);return((n,l)=>{let f=t.dataset.type??"string";if(f==="string")return new Intl.Collator().compare(n,l);if(f==="boolean"){let m=p=>["0","false","null","undefined"].includes(p)?!1:!!p;return m(n)===m(l)?0:m(n)?-1:1}else return Number(n)-Number(l)})(C(r?o:a,c),C(r?a:o,c))},C=(t,r)=>{let e=t.children[r];return e instanceof HTMLElement?e.dataset.value??e.textContent??"":""};export{i as a,A as b};
|
@@ -0,0 +1 @@
|
|
1
|
+
import{a as l}from"./chunk-7KU2PRW5.js";var a=class extends l{#t;constructor(){super()}set#e(t){this.getContent().style.left=`${t.x}px`,this.getContent().style.top=`${t.y}px`}async show(t){let e=window.scrollY,i=window.scrollX,d=t instanceof MouseEvent?t.clientX:t.touches[0]?.clientX??0,f=t instanceof MouseEvent?t.clientY:t.touches[0]?.clientY??0,s=d+i,n=f+e;this.getContent().style.position="absolute",this.getContent().style.display="block";let o=this.getContent().offsetWidth+24,h=this.getContent().offsetHeight+6,c=window.innerWidth,r=window.innerHeight;s+o>i+c&&(s=i+c-o),n+h>e+r&&(n=e+r-h),this.#e={x:s,y:n},await this.animateElement()}async hide(){this.getContent().style.display!=="none"&&(await this.animateElement({options:{direction:"reverse"}}),this.getContent().style.display="none")}mount(){this.triggerListener(e=>{e.preventDefault(),this.show(e)},"contextmenu"),this.safeListener("click",()=>this.hide()),this.triggerListener(e=>{this.#t=setTimeout(()=>{this.show(e)},800)},"touchstart");let t=()=>clearTimeout(this.#t);this.triggerListener(t,"touchend"),this.triggerListener(t,"touchcancel"),this.safeListener("keydown",e=>{e.key==="Escape"&&this.hide()})}};export{a};
|
@@ -0,0 +1 @@
|
|
1
|
+
import{b as t}from"./chunk-MXKU7AKV.js";var r=class extends t{constructor(){super()}isFullscreen(){return document.fullscreenElement!==null}fullscreenSupported(){return!!document.documentElement.requestFullscreen}toggle(){if(this.isFullscreen())document.exitFullscreen();else try{this.getContent(HTMLElement).requestFullscreen()}catch{document.documentElement.requestFullscreen()}}mount(){this.triggerListener(()=>this.toggle());for(let e of this.getTrigger())!this.fullscreenSupported()&&"disabled"in e&&(e.disabled=!0)}};export{r as a};
|
@@ -0,0 +1 @@
|
|
1
|
+
import{b as n}from"./chunk-MXKU7AKV.js";var s=class extends n{breakpoints=[{name:"sm",width:640},{name:"md",width:768},{name:"lg",width:1024},{name:"xl",width:1280},{name:"2xl",width:1536}];constructor(){super();let t=[];for(let e of this.getAttributeNames())if(e.startsWith("breakpoint-")){let[,...i]=e.split("-");i&&t.push({name:i.join("-"),width:Number(this.getAttribute(e))})}t.length&&(this.breakpoints=t),this.breakpoints.sort((e,i)=>i.width-e.width)}get breakpoint(){for(let t=0;t<this.breakpoints.length;t++){let e=this.breakpoints[t];if(e&&window.innerWidth>e.width)return e.name}return"none"}mount(){let t=()=>this.getContent().innerHTML=`${this.breakpoint}:${window.innerWidth}`;t(),this.safeListener("resize",t,window)}};export{s as a};
|
@@ -0,0 +1 @@
|
|
1
|
+
import{b as e}from"./chunk-MXKU7AKV.js";var r=class extends e{constructor(){super()}get value(){return this.getAttribute("value")??""}set value(t){this.setAttribute("value",t)}async copy(t=this.value){await navigator.clipboard.writeText(t),this.swapContent()}};export{r as a};
|
@@ -0,0 +1 @@
|
|
1
|
+
import{b as m}from"./chunk-MXKU7AKV.js";var l=class extends m{constructor(){super()}get animationOptions(){let i={};for(let s of this.getAttributeNames())if(s.startsWith("animation-option-")){let e=this.getAttribute(s),[,,t]=s.split("-");e&&(t==="duration"||t==="delay"?i[t]=Number(e):t==="easing"&&(i[t]=e))}return i}async animateElement(i={element:this.getContent(),options:{}}){let{element:s=this.getContent(),options:e={}}=i,t=this.keyframes;if(t.length&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches){e=Object.assign(this.animationOptions,e),e.duration||(e.duration=200),e.easing||(e.easing="ease-in-out");let o=t.at(0),n=t.at(-1);if(o&&n){let r=["composite","easing","offset"];for(let f of r)delete o[f],delete n[f]}e.direction?.includes("reverse")&&([o,n]=[n,o]),Object.assign(s.style,o),await s.animate(t,e).finished,Object.assign(s.style,n)}}get keyframes(){let i=[];for(let s of this.getAttributeNames()){let e=this.getAttribute(s),[,,t,...o]=s.split("-");if(s.startsWith("animation-keyframe-")){let n=o.map((a,r)=>r<1?a:a.at(0)?.toUpperCase()+a.slice(1)).join("");if(t&&n){t==="from"?t="0":t==="to"?t="1":t=String(parseInt(t)*.01);let a=Number(t),r=i.find(f=>f.offset===a);r?r[n]=e:i.push({[n]:e,offset:a})}}}return i.sort((s,e)=>Number(s.offset)-Number(e.offset)),i}};export{l as a};
|
@@ -0,0 +1 @@
|
|
1
|
+
import{a as t}from"./chunk-7KU2PRW5.js";var s=class extends t{constructor(){super()}get dialog(){return this.getContent(HTMLDialogElement)}async show(){this.dialog.showModal(),await this.animateElement()}async close(){await this.animateElement({options:{direction:"reverse"}}),this.dialog.close()}async toggle(){this.dialog.open?this.close():this.show()}mount(){this.triggerListener(()=>this.toggle()),this.safeListener("keydown",e=>{e.key==="Escape"&&this.dialog.open&&(e.preventDefault(),this.close())})}};export{s as a};
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import{b as y}from"./chunk-MXKU7AKV.js";var p=class extends y{#i=[];keyPairs={"(":")","{":"}","[":"]","<":">",'"':'"',"`":"`"};constructor(){super();for(let t of this.#h)t.type==="wrap"&&(this.keyPairs[t.value]=t.value)}get textArea(){return this.getContent(HTMLTextAreaElement)}get text(){return this.textArea.value}set text(t){this.textArea.value=t}get#h(){let t=[];for(let i of this.getTrigger())t.push(this.#l(i));return t}get#o(){let t=this.text.split("```"),i=0;for(let[s,e]of t.entries())if(i+=e.length+3,this.#e<i)return s;return 0}get#t(){return this.textArea.selectionEnd}get#e(){return this.textArea.selectionStart}#s(t,i){this.textArea.setSelectionRange(t,i)}#l(t){let i=t.dataset.type,s=t.dataset.value,e=t.dataset.key??void 0;return{type:i,value:s,key:e}}async#c(t,i,s){if(t.type==="inline")this.text=`${this.text.slice(0,s)}${t.value}${this.text.slice(s)}`;else if(t.type==="wrap")this.text=x(this.text,t.value,i),this.text=x(this.text,this.keyPairs[t.value],s+t.value.length),t.value.length<2&&this.#i.push(t.value);else if(t.type==="block"){let{lines:e,lineNumber:n}=this.#r(),r=t.value.at(0);r&&e[n]?.startsWith(r)?e[n]=t.value.trim()+e[n]:e[n]=t.value+e[n],this.text=e.join(`
|
2
|
+
`)}}async#u(t,i,s){let e=0,n=0;if(/[a-z]/i.test(t)){for(let r=s;r<this.text.length;r++)if(this.text[r]?.match(/[a-z]/i))e?n=r+1:e=r;else if(e)break}else e=i+t.length,n=s+t.length;this.#s(e,n),this.textArea.focus()}async#n(t){let i=this.#t,s=this.#e;await this.#c(t,s,i),this.#u(t.value,s,i)}#f(t){if(t){let i=[];this.#h.forEach(e=>{e.type==="block"&&i.push(e.value)});for(let e=0;e<i.length;e++){let n=i[e];if(n&&t.startsWith(n))return n}let s=g(t);if(s)return`${s}. `}return""}#r(){let t=this.text.split(`
|
3
|
+
`),i=0;for(let s=0;s<t.length;s++){let e=t.at(s)?.length??0;if(i++,i+=e,i>this.#t)return{lines:t,lineNumber:s,columnNumber:this.#t-(i-e-1)}}return{lines:t,lineNumber:0,columnNumber:0}}#a(t,i=!1){let{lines:s}=this.#r();for(let e=t+1;e<s.length;e++){let n=s[e];if(n){let r=g(n);if(r){let h;if(i)if(r>1)h=r-1;else break;else h=r+1;s[e]=n.slice(String(r).length),s[e]=String(h)+s[e]}else break}}this.text=s.join(`
|
4
|
+
`)}mount(){this.textArea.addEventListener("keydown",async t=>{let i=["ArrowUp","ArrowDown","Delete"],s=this.text[this.#t]??"";if(i.includes(t.key))this.#i=[];else if(t.key==="Backspace"){let e=this.text[this.#e-1];if(e&&e in this.keyPairs&&s===this.keyPairs[e]){t.preventDefault();let n=this.#e-1,r=this.#t-1;this.text=c(this.text,n),this.text=c(this.text,r),setTimeout(()=>{this.#s(n,r)},0),this.#i.pop()}if(e===`
|
5
|
+
`&&this.#e===this.#t){t.preventDefault();let n=this.#e-1,{lineNumber:r}=this.#r();this.#a(r,!0),this.text=c(this.text,n),setTimeout(async()=>{this.#s(n,n)},0)}}else if(t.key==="Tab")this.#o%2!==0&&(t.preventDefault(),await this.#n({type:"inline",value:" "}));else if(t.key==="Enter"){let{lines:e,lineNumber:n,columnNumber:r}=this.#r(),h=e.at(n),a=this.#f(h),o=a,u=g(a);if(u&&(a=`${u+1}. `),a&&o.length<r)t.preventDefault(),u&&this.#a(n),await this.#n({type:"inline",value:`
|
6
|
+
${a}`});else if(a&&o.length===r){t.preventDefault();let m=this.#t-o.length;for(let f=0;f<o.length;f++)this.text=c(this.text,this.#t-(f+1));setTimeout(async()=>{this.#s(m,m),this.textArea.focus(),await this.#n({type:"inline",value:`
|
7
|
+
`})},0)}}else{let e=Object.values(this.keyPairs).includes(s),n=this.#e!==this.#t;if((t.ctrlKey||t.metaKey)&&this.#e===this.#t&&(t.key==="c"||t.key==="x")){t.preventDefault();let{lines:r,lineNumber:h,columnNumber:a}=this.#r();if(await navigator.clipboard.writeText(`${h===0&&t.key==="x"?"":`
|
8
|
+
`}${r[h]}`),t.key==="x"){let o=this.#e-a;r.splice(h,1),this.text=r.join(`
|
9
|
+
`),setTimeout(()=>{this.#s(o,o)},0)}}if((t.ctrlKey||t.metaKey)&&t.key){let r=this.#h.find(h=>h.key===t.key);r&&this.#n(r)}else e&&(s===t.key||t.key==="ArrowRight")&&this.#i.length&&!n?(t.preventDefault(),this.#s(this.#e+1,this.#t+1),this.#i.pop()):t.key in this.keyPairs&&(t.preventDefault(),await this.#n({type:"wrap",value:t.key}),this.#i.push(t.key))}}),this.textArea.addEventListener("dblclick",()=>{this.#e!==this.#t&&(this.text[this.#e]===" "&&this.#s(this.#e+1,this.#t),this.text[this.#t-1]===" "&&this.#s(this.#e,this.#t-1))}),this.textArea.addEventListener("click",()=>this.#i=[]),this.triggerListener(t=>{t.target instanceof HTMLElement&&this.#n(this.#l(t.target))})}},g=l=>{let t=l.match(/^(\d+)\./);return t?Number(t[1]):null},x=(l,t,i)=>l.slice(0,i)+t+l.slice(i),c=(l,t)=>l.slice(0,t)+l.slice(t+1);export{p as a};
|
@@ -0,0 +1 @@
|
|
1
|
+
import{a as t}from"./chunk-7F7CQUEG.js";var e=class extends t{constructor(){super()}async share(r=this.value){if(navigator.canShare&&navigator.canShare({url:r}))try{await navigator.share({url:r})}catch(a){a?.name!=="AbortError"&&console.error(a)}else this.copy()}mount(){this.triggerListener(async()=>await this.share())}};export{e as a};
|
@@ -0,0 +1 @@
|
|
1
|
+
import{a as t}from"./chunk-7KU2PRW5.js";var n=class extends t{constructor(){super()}get details(){let e=this.getContent(HTMLElement).parentElement;if(!(e instanceof HTMLDetailsElement))throw new Error("Details: HTMLDetailsElement not found.");return e}async open(){this.details.open=!0,await this.animateElement()}async close(){await this.animateElement({options:{direction:"reverse"}}),this.details.open=!1}toggle(){this.details.open?this.close():this.open()}mount(){this.triggerListener(e=>{e.preventDefault(),this.toggle()})}};export{n as a};
|
@@ -0,0 +1 @@
|
|
1
|
+
var o=Object.defineProperty;var l=(s,e)=>{for(var t in e)o(s,t,{get:e[t],enumerable:!0})};var i=class extends HTMLElement{#e=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(e){this.setAttribute("event",e)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(e=HTMLElement){let t=this.querySelector(this.getAttribute("content")??"[data-content]");if(t instanceof e)return t;throw new Error("Content not found")}swapContent(e=!0,t=800){let n=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(n){let r=Array.from(this.getContent().childNodes);n instanceof HTMLTemplateElement?this.getContent().replaceChildren(n.content.cloneNode(!0)):this.getContent().replaceChildren(...n.childNodes),e&&setTimeout(()=>this.getContent().replaceChildren(...r),t)}}safeListener(e,t,n=document.body,r={}){r.signal=this.#e.signal,n.addEventListener(e,t,r)}triggerListener(e,t=this.event){for(let n of this.getTrigger())n.addEventListener(t,e)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}disconnectedCallback(){this.#e.abort()}};export{l as a,i as b};
|
@@ -0,0 +1 @@
|
|
1
|
+
import{a as t}from"./chunk-7KU2PRW5.js";var s=class extends t{constructor(){super()}get open(){return this.hasAttribute("open")}set open(e){e?this.setAttribute("open",""):this.removeAttribute("open")}async show(){this.getContent().showPopover(),await this.animateElement()}async hide(){await this.animateElement({options:{direction:"reverse"}}),this.getContent().hidePopover()}async toggle(){this.open?this.hide():this.show()}mount(){this.triggerListener(e=>{e.preventDefault(),this.toggle()}),this.getContent().addEventListener("toggle",e=>{e.newState==="open"?this.open=!0:this.open=!1}),this.safeListener("keydown",e=>{e.key==="Escape"&&this.open&&(e.preventDefault(),this.hide())})}};export{s as a};
|
@@ -0,0 +1 @@
|
|
1
|
+
import{a as t}from"./chunk-7F7CQUEG.js";var s=class extends t{constructor(){super()}mount(){this.triggerListener(async()=>await this.copy())}};export{s as a};
|
@@ -0,0 +1 @@
|
|
1
|
+
import{b as e}from"./chunk-MXKU7AKV.js";var r=class extends e{static observedAttributes=["autoplay","start","uid"];constructor(){super()}get iframe(){return this.getContent(HTMLIFrameElement)}get autoplay(){return this.hasAttribute("autoplay")}set autoplay(t){t?this.setAttribute("autoplay",""):this.removeAttribute("autoplay")}get start(){return this.getAttribute("start")??"0"}set start(t){this.setAttribute("start",t)}get uid(){let t=this.getAttribute("uid");if(!t)throw new Error("YouTube: missing `uid` attribute.");return t}set uid(t){this.setAttribute("uid",t)}mount(){this.iframe.allowFullscreen=!0,this.iframe.allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"}attributeChangedCallback(){queueMicrotask(()=>{this.iframe.src=`https://www.youtube-nocookie.com/embed/${this.uid}?start=${this.start}${this.autoplay?"&autoplay=1":""}`})}};export{r as a};
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";(()=>{var c=class extends HTMLElement{#t=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(t){this.setAttribute("event",t)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(t=HTMLElement){let e=this.querySelector(this.getAttribute("content")??"[data-content]");if(e instanceof t)return e;throw new Error("Content not found")}swapContent(t=!0,e=800){let n=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(n){let s=Array.from(this.getContent().childNodes);n instanceof HTMLTemplateElement?this.getContent().replaceChildren(n.content.cloneNode(!0)):this.getContent().replaceChildren(...n.childNodes),t&&setTimeout(()=>this.getContent().replaceChildren(...s),e)}}safeListener(t,e,n=document.body,s={}){s.signal=this.#t.signal,n.addEventListener(t,e,s)}triggerListener(t,e=this.event){for(let n of this.getTrigger())n.addEventListener(e,t)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}disconnectedCallback(){this.#t.abort()}};var f=class extends c{constructor(){super()}get animationOptions(){let t={};for(let e of this.getAttributeNames())if(e.startsWith("animation-option-")){let n=this.getAttribute(e),[,,s]=e.split("-");n&&(s==="duration"||s==="delay"?t[s]=Number(n):s==="easing"&&(t[s]=n))}return t}async animateElement(t={element:this.getContent(),options:{}}){let{element:e=this.getContent(),options:n={}}=t,s=this.keyframes;if(s.length&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches){n=Object.assign(this.animationOptions,n),n.duration||(n.duration=200),n.easing||(n.easing="ease-in-out");let r=s.at(0),i=s.at(-1);if(r&&i){let a=["composite","easing","offset"];for(let l of a)delete r[l],delete i[l]}n.direction?.includes("reverse")&&([r,i]=[i,r]),Object.assign(e.style,r),await e.animate(s,n).finished,Object.assign(e.style,i)}}get keyframes(){let t=[];for(let e of this.getAttributeNames()){let n=this.getAttribute(e),[,,s,...r]=e.split("-");if(e.startsWith("animation-keyframe-")){let i=r.map((o,a)=>a<1?o:o.at(0)?.toUpperCase()+o.slice(1)).join("");if(s&&i){s==="from"?s="0":s==="to"?s="1":s=String(parseInt(s)*.01);let o=Number(s),a=t.find(l=>l.offset===o);a?a[i]=n:t.push({[i]:n,offset:o})}}}return t.sort((e,n)=>Number(e.offset)-Number(n.offset)),t}};var m=class extends f{#t;constructor(){super()}set#e(t){this.getContent().style.left=`${t.x}px`,this.getContent().style.top=`${t.y}px`}async show(t){let e=window.scrollY,n=window.scrollX,s=t instanceof MouseEvent?t.clientX:t.touches[0]?.clientX??0,r=t instanceof MouseEvent?t.clientY:t.touches[0]?.clientY??0,i=s+n,o=r+e;this.getContent().style.position="absolute",this.getContent().style.display="block";let a=this.getContent().offsetWidth+24,l=this.getContent().offsetHeight+6,u=window.innerWidth,d=window.innerHeight;i+a>n+u&&(i=n+u-a),o+l>e+d&&(o=e+d-l),this.#e={x:i,y:o},await this.animateElement()}async hide(){this.getContent().style.display!=="none"&&(await this.animateElement({options:{direction:"reverse"}}),this.getContent().style.display="none")}mount(){this.triggerListener(e=>{e.preventDefault(),this.show(e)},"contextmenu"),this.safeListener("click",()=>this.hide()),this.triggerListener(e=>{this.#t=setTimeout(()=>{this.show(e)},800)},"touchstart");let t=()=>clearTimeout(this.#t);this.triggerListener(t,"touchend"),this.triggerListener(t,"touchcancel"),this.safeListener("keydown",e=>{e.key==="Escape"&&this.hide()})}};customElements.define("drab-contextmenu",m);})();
|
@@ -0,0 +1 @@
|
|
1
|
+
import{a as e}from"../chunk-57VEEUFG.js";import"../chunk-7KU2PRW5.js";import"../chunk-MXKU7AKV.js";customElements.define("drab-contextmenu",e);
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { Animate } from '../animate/index.js';
|
2
|
+
import '../base/index.js';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Displays content when the `trigger` element is right clicked, or long pressed on mobile.
|
6
|
+
*/
|
7
|
+
declare class ContextMenu extends Animate {
|
8
|
+
#private;
|
9
|
+
constructor();
|
10
|
+
show(e: MouseEvent | TouchEvent): Promise<void>;
|
11
|
+
hide(): Promise<void>;
|
12
|
+
mount(): void;
|
13
|
+
}
|
14
|
+
|
15
|
+
export { ContextMenu };
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";(()=>{var c=class extends HTMLElement{#t=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(t){this.setAttribute("event",t)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(t=HTMLElement){let e=this.querySelector(this.getAttribute("content")??"[data-content]");if(e instanceof t)return e;throw new Error("Content not found")}swapContent(t=!0,e=800){let n=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(n){let s=Array.from(this.getContent().childNodes);n instanceof HTMLTemplateElement?this.getContent().replaceChildren(n.content.cloneNode(!0)):this.getContent().replaceChildren(...n.childNodes),t&&setTimeout(()=>this.getContent().replaceChildren(...s),e)}}safeListener(t,e,n=document.body,s={}){s.signal=this.#t.signal,n.addEventListener(t,e,s)}triggerListener(t,e=this.event){for(let n of this.getTrigger())n.addEventListener(e,t)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}disconnectedCallback(){this.#t.abort()}};var f=class extends c{constructor(){super()}get animationOptions(){let t={};for(let e of this.getAttributeNames())if(e.startsWith("animation-option-")){let n=this.getAttribute(e),[,,s]=e.split("-");n&&(s==="duration"||s==="delay"?t[s]=Number(n):s==="easing"&&(t[s]=n))}return t}async animateElement(t={element:this.getContent(),options:{}}){let{element:e=this.getContent(),options:n={}}=t,s=this.keyframes;if(s.length&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches){n=Object.assign(this.animationOptions,n),n.duration||(n.duration=200),n.easing||(n.easing="ease-in-out");let r=s.at(0),i=s.at(-1);if(r&&i){let a=["composite","easing","offset"];for(let l of a)delete r[l],delete i[l]}n.direction?.includes("reverse")&&([r,i]=[i,r]),Object.assign(e.style,r),await e.animate(s,n).finished,Object.assign(e.style,i)}}get keyframes(){let t=[];for(let e of this.getAttributeNames()){let n=this.getAttribute(e),[,,s,...r]=e.split("-");if(e.startsWith("animation-keyframe-")){let i=r.map((o,a)=>a<1?o:o.at(0)?.toUpperCase()+o.slice(1)).join("");if(s&&i){s==="from"?s="0":s==="to"?s="1":s=String(parseInt(s)*.01);let o=Number(s),a=t.find(l=>l.offset===o);a?a[i]=n:t.push({[i]:n,offset:o})}}}return t.sort((e,n)=>Number(e.offset)-Number(n.offset)),t}};var d=class extends f{#t;constructor(){super()}set#e(t){this.getContent().style.left=`${t.x}px`,this.getContent().style.top=`${t.y}px`}async show(t){let e=window.scrollY,n=window.scrollX,s=t instanceof MouseEvent?t.clientX:t.touches[0]?.clientX??0,r=t instanceof MouseEvent?t.clientY:t.touches[0]?.clientY??0,i=s+n,o=r+e;this.getContent().style.position="absolute",this.getContent().style.display="block";let a=this.getContent().offsetWidth+24,l=this.getContent().offsetHeight+6,m=window.innerWidth,u=window.innerHeight;i+a>n+m&&(i=n+m-a),o+l>e+u&&(o=e+u-l),this.#e={x:i,y:o},await this.animateElement()}async hide(){this.getContent().style.display!=="none"&&(await this.animateElement({options:{direction:"reverse"}}),this.getContent().style.display="none")}mount(){this.triggerListener(e=>{e.preventDefault(),this.show(e)},"contextmenu"),this.safeListener("click",()=>this.hide()),this.triggerListener(e=>{this.#t=setTimeout(()=>{this.show(e)},800)},"touchstart");let t=()=>clearTimeout(this.#t);this.triggerListener(t,"touchend"),this.triggerListener(t,"touchcancel"),this.safeListener("keydown",e=>{e.key==="Escape"&&this.hide()})}};})();
|
@@ -0,0 +1 @@
|
|
1
|
+
import{a}from"../chunk-57VEEUFG.js";import"../chunk-7KU2PRW5.js";import"../chunk-MXKU7AKV.js";export{a as ContextMenu};
|
package/copy/define.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";(()=>{var s=class extends HTMLElement{#e=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(e){this.setAttribute("event",e)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(e=HTMLElement){let t=this.querySelector(this.getAttribute("content")??"[data-content]");if(t instanceof e)return t;throw new Error("Content not found")}swapContent(e=!0,t=800){let n=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(n){let r=Array.from(this.getContent().childNodes);n instanceof HTMLTemplateElement?this.getContent().replaceChildren(n.content.cloneNode(!0)):this.getContent().replaceChildren(...n.childNodes),e&&setTimeout(()=>this.getContent().replaceChildren(...r),t)}}safeListener(e,t,n=document.body,r={}){r.signal=this.#e.signal,n.addEventListener(e,t,r)}triggerListener(e,t=this.event){for(let n of this.getTrigger())n.addEventListener(t,e)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}disconnectedCallback(){this.#e.abort()}};var i=class extends s{constructor(){super()}get value(){return this.getAttribute("value")??""}set value(e){this.setAttribute("value",e)}async copy(e=this.value){await navigator.clipboard.writeText(e),this.swapContent()}};var o=class extends i{constructor(){super()}mount(){this.triggerListener(async()=>await this.copy())}};customElements.define("drab-copy",o);})();
|
package/copy/define.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
import{a as o}from"../chunk-TSTTUEAF.js";import"../chunk-7F7CQUEG.js";import"../chunk-MXKU7AKV.js";customElements.define("drab-copy",o);
|
package/copy/index.d.ts
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
import { B as BaseCopy } from '../index-SyRipepB.js';
|
2
|
+
import '../base/index.js';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Uses the [Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/writeText)
|
6
|
+
* to copy text.
|
7
|
+
*/
|
8
|
+
declare class Copy extends BaseCopy {
|
9
|
+
constructor();
|
10
|
+
mount(): void;
|
11
|
+
}
|
12
|
+
|
13
|
+
export { Copy };
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";(()=>{var s=class extends HTMLElement{#e=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(e){this.setAttribute("event",e)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(e=HTMLElement){let t=this.querySelector(this.getAttribute("content")??"[data-content]");if(t instanceof e)return t;throw new Error("Content not found")}swapContent(e=!0,t=800){let n=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(n){let r=Array.from(this.getContent().childNodes);n instanceof HTMLTemplateElement?this.getContent().replaceChildren(n.content.cloneNode(!0)):this.getContent().replaceChildren(...n.childNodes),e&&setTimeout(()=>this.getContent().replaceChildren(...r),t)}}safeListener(e,t,n=document.body,r={}){r.signal=this.#e.signal,n.addEventListener(e,t,r)}triggerListener(e,t=this.event){for(let n of this.getTrigger())n.addEventListener(t,e)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}disconnectedCallback(){this.#e.abort()}};var i=class extends s{constructor(){super()}get value(){return this.getAttribute("value")??""}set value(e){this.setAttribute("value",e)}async copy(e=this.value){await navigator.clipboard.writeText(e),this.swapContent()}};var a=class extends i{constructor(){super()}mount(){this.triggerListener(async()=>await this.copy())}};})();
|
package/copy/index.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
import{a}from"../chunk-TSTTUEAF.js";import"../chunk-7F7CQUEG.js";import"../chunk-MXKU7AKV.js";export{a as Copy};
|