epic-modals 0.0.4

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.
Files changed (46) hide show
  1. package/LICENSE +93 -0
  2. package/README.md +287 -0
  3. package/dist/core/config.svelte.d.ts +85 -0
  4. package/dist/core/index.d.ts +6 -0
  5. package/dist/core/stacking.svelte.d.ts +19 -0
  6. package/dist/core/state.svelte.d.ts +321 -0
  7. package/dist/core/types.d.ts +98 -0
  8. package/dist/core/viewport.d.ts +92 -0
  9. package/dist/core/viewport.test.d.ts +2 -0
  10. package/dist/epic-modals.css +9 -0
  11. package/dist/index.d.ts +2 -0
  12. package/dist/index.js +1 -0
  13. package/dist/react/Dock.d.ts +13 -0
  14. package/dist/react/Modal.d.ts +11 -0
  15. package/dist/react/ModalProvider.d.ts +11 -0
  16. package/dist/react/context.d.ts +4 -0
  17. package/dist/react/index.d.ts +15 -0
  18. package/dist/react/svelte-bridge.d.ts +18 -0
  19. package/dist/react/useModal.d.ts +27 -0
  20. package/dist/react/useModalZIndex.d.ts +35 -0
  21. package/dist/react.d.ts +11 -0
  22. package/dist/react.js +1 -0
  23. package/dist/styles/animations.css +1 -0
  24. package/dist/styles/dock.css +1 -0
  25. package/dist/styles/index.css +1 -0
  26. package/dist/styles/modal.css +1 -0
  27. package/dist/styles/themes/dark.css +1 -0
  28. package/dist/styles/themes/light.css +1 -0
  29. package/dist/styles/variables.css +1 -0
  30. package/dist/svelte/context.d.ts +8 -0
  31. package/dist/svelte/hooks/index.d.ts +13 -0
  32. package/dist/svelte/hooks/useFocusTrap.svelte.d.ts +20 -0
  33. package/dist/svelte/hooks/useModal.svelte.d.ts +41 -0
  34. package/dist/svelte/hooks/useModalAnimation.svelte.d.ts +16 -0
  35. package/dist/svelte/hooks/useModalDrag.svelte.d.ts +16 -0
  36. package/dist/svelte/hooks/useModalResize.svelte.d.ts +18 -0
  37. package/dist/svelte/hooks/useModalZIndex.svelte.d.ts +30 -0
  38. package/dist/svelte/hooks/usePortal.svelte.d.ts +13 -0
  39. package/dist/svelte/hooks/useWindowEvent.svelte.d.ts +12 -0
  40. package/dist/svelte/index.d.ts +14 -0
  41. package/dist/svelte.d.ts +10 -0
  42. package/dist/svelte.js +1 -0
  43. package/dist/vanilla/index.d.ts +51 -0
  44. package/dist/vanilla.d.ts +10 -0
  45. package/dist/vanilla.js +1 -0
  46. package/package.json +89 -0
package/LICENSE ADDED
@@ -0,0 +1,93 @@
1
+ Elastic License 2.0
2
+
3
+ URL: https://www.elastic.co/licensing/elastic-license
4
+
5
+ ## Acceptance
6
+
7
+ By using the software, you agree to all of the terms and conditions below.
8
+
9
+ ## Copyright License
10
+
11
+ The licensor grants you a non-exclusive, royalty-free, worldwide,
12
+ non-sublicensable, non-transferable license to use, copy, distribute, make
13
+ available, and prepare derivative works of the software, in each case subject
14
+ to the limitations and conditions below.
15
+
16
+ ## Limitations
17
+
18
+ You may not provide the software to third parties as a hosted or managed
19
+ service, where the service provides users with access to any substantial set of
20
+ the features or functionality of the software.
21
+
22
+ You may not move, change, disable, or circumvent the license key functionality
23
+ in the software, and you may not remove or obscure any functionality in the
24
+ software that is protected by the license key.
25
+
26
+ You may not alter, remove, or obscure any licensing, copyright, or other notices
27
+ of the licensor in the software. Any use of the licensor's trademarks is subject
28
+ to applicable law.
29
+
30
+ ## Patents
31
+
32
+ The licensor grants you a license, under any patent claims the licensor can
33
+ license, or becomes able to license, to make, have made, use, sell, offer for
34
+ sale, import and have imported the software, in each case subject to the
35
+ limitations and conditions in this license. This license does not cover any
36
+ patent claims that you cause to be infringed by modifications or additions to
37
+ the software. If you or your company make any written claim that the software
38
+ infringes or contributes to infringement of any patent, your patent license for
39
+ the software granted under these terms ends immediately. If your company makes
40
+ such a claim, your patent license ends immediately for work on behalf of your
41
+ company.
42
+
43
+ ## Notices
44
+
45
+ You must ensure that anyone who gets a copy of any part of the software from you
46
+ also gets a copy of these terms.
47
+
48
+ If you modify the software, you must include in any modified copies of the
49
+ software prominent notices stating that you have modified the software.
50
+
51
+ ## No Other Rights
52
+
53
+ These terms do not imply any licenses other than those expressly granted in
54
+ these terms.
55
+
56
+ ## Termination
57
+
58
+ If you use the software in violation of these terms, such use is not licensed,
59
+ and your licenses will automatically terminate. If the licensor provides you
60
+ with a notice of your violation, and you cease all violation of this license no
61
+ later than 30 days after you receive that notice, your licenses will be
62
+ reinstated retroactively. However, if you violate these terms after such
63
+ reinstatement, any additional violation of these terms will cause your licenses
64
+ to terminate automatically and permanently.
65
+
66
+ ## No Liability
67
+
68
+ *As far as the law allows, the software comes as is, without any warranty or
69
+ condition, and the licensor will not be liable to you for any damages arising
70
+ out of these terms or the use or nature of the software, under any kind of
71
+ legal claim.*
72
+
73
+ ## Definitions
74
+
75
+ The **licensor** is the entity offering these terms, and the **software** is the
76
+ software the licensor makes available under these terms, including any portion
77
+ of it.
78
+
79
+ **you** refers to the individual or entity agreeing to these terms.
80
+
81
+ **your company** is any legal entity, sole proprietorship, or other kind of
82
+ organization that you work for, plus all organizations that have control over,
83
+ are under the control of, or are under common control with that organization.
84
+ **control** means ownership of substantially all the assets of an entity, or the
85
+ power to direct its management and policies by vote, contract, or otherwise.
86
+ Control can be direct or indirect.
87
+
88
+ **your licenses** are all the licenses granted to you for the software under
89
+ these terms.
90
+
91
+ **use** means anything you do with the software requiring one of your licenses.
92
+
93
+ **trademark** means trademarks, service marks, and similar rights.
package/README.md ADDED
@@ -0,0 +1,287 @@
1
+ # epic-modals
2
+
3
+ A stunning modal library with macOS-style animations, drag, resize, and dock. Supports Svelte 5, React, and vanilla JavaScript.
4
+
5
+ **[Live Demo](https://epicmodals.eu)**
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install epic-modals
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ### React
16
+
17
+ ```tsx
18
+ import { ModalProvider, Modal, Dock, useModal } from 'epic-modals/react';
19
+ import 'epic-modals/styles';
20
+
21
+ // Modal IDs can be symbols (recommended) or strings
22
+ const MODAL_ID = Symbol('my-modal');
23
+
24
+ function App() {
25
+ return (
26
+ <ModalProvider>
27
+ <MyComponent />
28
+ <Dock />
29
+ </ModalProvider>
30
+ );
31
+ }
32
+
33
+ function MyComponent() {
34
+ const { open, close } = useModal(MODAL_ID);
35
+
36
+ return (
37
+ <>
38
+ <button onClick={(e) => open(e.currentTarget)}>Open</button>
39
+
40
+ <Modal id={MODAL_ID} title="Hello World" maxWidth="480px"
41
+ footer={<button onClick={close}>Close</button>}
42
+ >
43
+ <p>Your content here!</p>
44
+ </Modal>
45
+ </>
46
+ );
47
+ }
48
+ ```
49
+
50
+ ### Svelte 5
51
+
52
+ ```svelte
53
+ <script lang="ts">
54
+ import { ModalProvider, Modal, Dock, openModal, closeModal } from 'epic-modals/svelte';
55
+ import 'epic-modals/styles';
56
+
57
+ // Modal IDs can be symbols (recommended) or strings
58
+ const MODAL_ID = Symbol('my-modal');
59
+ </script>
60
+
61
+ <ModalProvider>
62
+ <button onclick={(e) => openModal(MODAL_ID, e.currentTarget)}>Open</button>
63
+
64
+ <Modal id={MODAL_ID} title="Hello World" maxWidth="480px">
65
+ <p>Your content here!</p>
66
+
67
+ {#snippet footer()}
68
+ <button onclick={() => closeModal(MODAL_ID)}>Close</button>
69
+ {/snippet}
70
+ </Modal>
71
+
72
+ <Dock />
73
+ </ModalProvider>
74
+ ```
75
+
76
+ ### Vanilla JavaScript
77
+
78
+ ```js
79
+ import { init, createModal, openModal, closeModal } from 'epic-modals/vanilla';
80
+ import 'epic-modals/styles';
81
+
82
+ // Modal IDs can be symbols (recommended) or strings
83
+ const MODAL_ID = Symbol('my-modal');
84
+
85
+ // Initialize library (creates backdrop + dock automatically)
86
+ init();
87
+
88
+ createModal({
89
+ id: MODAL_ID,
90
+ title: 'Hello World',
91
+ content: '<p>Your content here!</p>',
92
+ footer: '<button id="close-btn">Close</button>',
93
+ maxWidth: '480px',
94
+ });
95
+
96
+ document.querySelector('#close-btn').onclick = () => closeModal(MODAL_ID);
97
+ document.querySelector('#open-btn').onclick = (e) => {
98
+ openModal(MODAL_ID, e.currentTarget);
99
+ };
100
+ ```
101
+
102
+ ## Features
103
+
104
+ - **Dock** - Minimized modals appear in a customizable dock
105
+ - **Minimize/Restore** - Smooth genie animation to/from dock
106
+ - **Resize** - 8-direction resize handles
107
+ - **Drag** - Drag modals by header
108
+ - **Parent-Child** - Modals can spawn child modals
109
+ - **Attention Effect** - Shake animation to grab user attention
110
+ - **Focus Trap** - Tab key stays within modal
111
+ - **macOS Style** - Traffic light buttons (close, minimize, maximize)
112
+ - **Theming** - Light/dark themes + full CSS variable customization
113
+
114
+ ## Hooks & Functions
115
+
116
+ ### React
117
+
118
+ ```tsx
119
+ import { useModal, useModals } from 'epic-modals/react';
120
+
121
+ const MODAL_ID = Symbol('my-modal');
122
+
123
+ function MyComponent() {
124
+ const {
125
+ open, // (element) => void - Open modal
126
+ close, // () => void - Close modal
127
+ minimize, // () => void - Minimize to dock
128
+ restore, // () => void - Restore from dock
129
+ shake, // () => void - Trigger attention effect
130
+ bringToFront, // () => void - Focus modal (z-index)
131
+ isOpen, // boolean
132
+ isMinimized, // boolean
133
+ isRegistered, // boolean
134
+ } = useModal(MODAL_ID);
135
+
136
+ return (
137
+ <button onClick={(e) => open(e.currentTarget)}>Open</button>
138
+ );
139
+ }
140
+ ```
141
+
142
+ ### Svelte
143
+
144
+ ```svelte
145
+ <script lang="ts">
146
+ import { useModal } from 'epic-modals/svelte';
147
+
148
+ const MODAL_ID = Symbol('my-modal');
149
+ const modal = useModal(MODAL_ID);
150
+
151
+ // modal.open(element) - Open modal
152
+ // modal.close() - Close modal
153
+ // modal.minimize() - Minimize to dock
154
+ // modal.restore() - Restore from dock
155
+ // modal.shake() - Trigger attention effect
156
+ // modal.bringToFront() - Focus modal (z-index)
157
+ // modal.isOpen() - Check if open
158
+ // modal.isRegistered() - Check if registered
159
+ </script>
160
+
161
+ <button onclick={(e) => modal.open(e.currentTarget)}>Open</button>
162
+ ```
163
+
164
+ ### Vanilla
165
+
166
+ ```js
167
+ import {
168
+ openModal, closeModal, minimizeModal, restoreModal,
169
+ triggerAttention, bringToFront, isModalOpen
170
+ } from 'epic-modals/vanilla';
171
+
172
+ const MODAL_ID = Symbol('my-modal');
173
+
174
+ openModal(MODAL_ID, buttonElement);
175
+ closeModal(MODAL_ID);
176
+ minimizeModal(MODAL_ID);
177
+ restoreModal(MODAL_ID);
178
+ triggerAttention(MODAL_ID); // Shake effect
179
+ bringToFront(MODAL_ID);
180
+ isModalOpen(MODAL_ID); // Returns boolean
181
+ ```
182
+
183
+ ## Parent-Child Modals
184
+
185
+ ```tsx
186
+ // React
187
+ import { useModal } from 'epic-modals/react';
188
+
189
+ const PARENT_ID = Symbol('parent');
190
+ const CHILD_ID = Symbol('child');
191
+
192
+ function Parent() {
193
+ const parent = useModal(PARENT_ID);
194
+ const child = useModal(CHILD_ID);
195
+
196
+ return (
197
+ <Modal id={PARENT_ID} title="Parent">
198
+ <button onClick={(e) => child.openAsChild(PARENT_ID, e.currentTarget)}>
199
+ Open Child
200
+ </button>
201
+ </Modal>
202
+ );
203
+ }
204
+ ```
205
+
206
+ ```svelte
207
+ <!-- Svelte -->
208
+ <script>
209
+ import { openChildModal } from 'epic-modals/svelte';
210
+
211
+ const PARENT_ID = Symbol('parent');
212
+ const CHILD_ID = Symbol('child');
213
+ </script>
214
+
215
+ <Modal id={PARENT_ID} title="Parent">
216
+ <button onclick={(e) => openChildModal(CHILD_ID, PARENT_ID, e.currentTarget)}>
217
+ Open Child
218
+ </button>
219
+ </Modal>
220
+
221
+ <Modal id={CHILD_ID} title="Child">
222
+ <p>I'm a child modal!</p>
223
+ </Modal>
224
+ ```
225
+
226
+ ## Configuration
227
+
228
+ ```tsx
229
+ <ModalProvider config={{
230
+ features: {
231
+ dock: true, // Enable dock for minimized modals
232
+ minimize: true, // Enable minimize button
233
+ resize: true, // Enable resize handles
234
+ drag: true, // Enable drag to move
235
+ focusTrap: true, // Enable focus trapping
236
+ animations: true, // Enable animations
237
+ backdrop: true, // Enable backdrop overlay
238
+ },
239
+ dock: {
240
+ position: 'bottom', // 'left' | 'right' | 'bottom'
241
+ labelMode: 'hidden', // 'hidden' | 'beside' | 'below'
242
+ },
243
+ animations: {
244
+ open: 400,
245
+ close: 250,
246
+ minimize: 500,
247
+ restore: 400,
248
+ },
249
+ appearance: {
250
+ headerLayout: 'macos', // 'macos' | 'windows' | 'none'
251
+ },
252
+ }}>
253
+ ```
254
+
255
+ ## Theming
256
+
257
+ ```css
258
+ /* Import base styles */
259
+ @import 'epic-modals/styles';
260
+
261
+ /* Optional: Import a theme */
262
+ @import 'epic-modals/styles/themes/light';
263
+ @import 'epic-modals/styles/themes/dark';
264
+ ```
265
+
266
+ Override CSS variables for custom theming:
267
+
268
+ ```css
269
+ :root {
270
+ --modal-bg: #ffffff;
271
+ --modal-border-radius: 12px;
272
+ --modal-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
273
+ --modal-title-color: #1a1a1a;
274
+
275
+ /* Traffic lights */
276
+ --modal-btn-close: #ff5f57;
277
+ --modal-btn-minimize: #febc2e;
278
+ --modal-btn-maximize: #28c840;
279
+
280
+ /* Dock */
281
+ --modal-dock-bg: linear-gradient(to bottom, #f8f9fa, #f0f1f3);
282
+ }
283
+ ```
284
+
285
+ ## License
286
+
287
+ [Elastic License 2.0](https://www.elastic.co/licensing/elastic-license) - Free for commercial use, but you cannot offer it as a hosted service or redistribute it as your own product.
@@ -0,0 +1,85 @@
1
+ import { DockPosition, DockLabelMode, ModalFeatures, AppearanceConfig } from './types';
2
+ export type { ModalFeatures, AppearanceConfig } from './types';
3
+ export interface DockConfig {
4
+ /** Dock position: left, right, bottom, or free-floating */
5
+ position: DockPosition;
6
+ /** Label display mode */
7
+ labelMode: DockLabelMode;
8
+ /** Enable reordering items in dock */
9
+ enableReorder: boolean;
10
+ /** Allow dock to be dragged freely (when position is 'free') */
11
+ enableFreeDrag: boolean;
12
+ }
13
+ export interface AnimationDurations {
14
+ /** Open animation duration */
15
+ open: number;
16
+ /** Close animation duration */
17
+ close: number;
18
+ /** Minimize animation duration */
19
+ minimize: number;
20
+ /** Restore animation duration */
21
+ restore: number;
22
+ }
23
+ export interface ZIndexConfig {
24
+ /** Base z-index for modals */
25
+ base: number;
26
+ /** Z-index for dock */
27
+ dock: number;
28
+ /** Z-index for toasts */
29
+ toast: number;
30
+ }
31
+ export interface ParentChildConfig {
32
+ /** Movement mode: 'realtime' (parent moves instantly) or 'animated' (parent animates after drag) */
33
+ movementMode: 'realtime' | 'animated';
34
+ /** Animation duration in milliseconds for animated movement mode */
35
+ animationDuration: number;
36
+ }
37
+ export interface PositioningConfig {
38
+ /**
39
+ * Strategy for placing new modals:
40
+ * - 'centered': Always center new modals (default, current behavior)
41
+ * - 'smart': Find position with least overlap with existing modals
42
+ */
43
+ strategy: 'centered' | 'smart';
44
+ /** Minimum gap between modals when using smart positioning (default: 16) */
45
+ modalGap: number;
46
+ /** CSS selectors for elements that modals should avoid overlapping (e.g., navigation bars, toolbars) */
47
+ avoidElements: string[];
48
+ }
49
+ export interface ModalLibraryConfig {
50
+ features: ModalFeatures;
51
+ dock: DockConfig;
52
+ animations: AnimationDurations;
53
+ appearance: AppearanceConfig;
54
+ zIndex: ZIndexConfig;
55
+ parentChild: ParentChildConfig;
56
+ positioning: PositioningConfig;
57
+ /** Portal target selector or element */
58
+ portalTarget: string | HTMLElement;
59
+ }
60
+ export declare const defaultConfig: ModalLibraryConfig;
61
+ /**
62
+ * Get the config version for tracking changes in $derived
63
+ */
64
+ export declare function getConfigVersion(): number;
65
+ /**
66
+ * Get the current library configuration
67
+ */
68
+ export declare function getConfig(): ModalLibraryConfig;
69
+ /**
70
+ * Set the library configuration (called by ModalProvider)
71
+ */
72
+ export declare function setConfig(config: Partial<ModalLibraryConfig>): void;
73
+ /**
74
+ * Reset to default configuration
75
+ */
76
+ export declare function resetConfig(): void;
77
+ /**
78
+ * Deep merge configuration objects
79
+ */
80
+ export declare function mergeConfig(base: ModalLibraryConfig, override: Partial<ModalLibraryConfig>): ModalLibraryConfig;
81
+ /**
82
+ * Check if a feature is enabled
83
+ */
84
+ export declare function isFeatureEnabled(feature: keyof ModalFeatures): boolean;
85
+ //# sourceMappingURL=config.svelte.d.ts.map
@@ -0,0 +1,6 @@
1
+ export * from './types';
2
+ export * from './config.svelte';
3
+ export * from './state.svelte';
4
+ export * from './stacking.svelte';
5
+ export * from './viewport';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,19 @@
1
+ import { StackingLayerName } from './types';
2
+ /**
3
+ * Initialize the z-index counter from config
4
+ */
5
+ export declare function initializeStacking(): void;
6
+ /**
7
+ * Get the next available z-index for a new modal
8
+ * Increments by 2 to leave room for floating elements (dropdowns, tooltips) at +1
9
+ */
10
+ export declare function acquireModalZIndex(): number;
11
+ /**
12
+ * Get a specific z-index for a layer
13
+ */
14
+ export declare function getLayerZIndex(layer: StackingLayerName): number;
15
+ /**
16
+ * Reset the z-index counter (useful for testing)
17
+ */
18
+ export declare function resetStacking(): void;
19
+ //# sourceMappingURL=stacking.svelte.d.ts.map