@overlastic/svelte 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,216 @@
1
+ // src/define/constructor.ts
2
+ import { createConstructor } from "@overlastic/core";
3
+
4
+ // src/internal/index.ts
5
+ var injectOverlayKey = Symbol("overlays:svelte");
6
+ var injectOptionsKey = Symbol("overlays:options");
7
+
8
+ // src/define/constructor.ts
9
+ var constructor = createConstructor((Inst, props, options) => {
10
+ const { container, deferred, context: _context = /* @__PURE__ */ new Map() } = options;
11
+ function vanish() {
12
+ childApp.$destroy();
13
+ container.remove();
14
+ }
15
+ const context = new Map([..._context.entries()]);
16
+ context.set(injectOverlayKey, {
17
+ resolve: deferred.resolve,
18
+ reject: deferred.reject,
19
+ deferred,
20
+ visible: false,
21
+ vanish
22
+ });
23
+ const childApp = new Inst({
24
+ target: container,
25
+ props,
26
+ context
27
+ });
28
+ });
29
+
30
+ // src/define/index.ts
31
+ var defineOverlay = constructor.define;
32
+ var renderOverlay = constructor.render;
33
+
34
+ // src/composable/usePrograms.ts
35
+ import { getContext, setContext } from "svelte";
36
+ function usePrograms(options = {}) {
37
+ setContext(injectOptionsKey, options);
38
+ return getContext(injectOverlayKey);
39
+ }
40
+
41
+ // src/components/index.ts
42
+ import { getContext as getContext2, onMount } from "svelte";
43
+ import { delay } from "@overlastic/core";
44
+ import {
45
+ SvelteComponentTyped,
46
+ check_outros,
47
+ create_slot,
48
+ detach,
49
+ empty,
50
+ get_all_dirty_from_scope,
51
+ get_slot_changes,
52
+ group_outros,
53
+ init,
54
+ insert,
55
+ noop,
56
+ safe_not_equal,
57
+ transition_in,
58
+ transition_out,
59
+ update_slot_base
60
+ } from "svelte/internal";
61
+ function create_if_block(ctx) {
62
+ let current;
63
+ const default_slot_template = (
64
+ /* #slots */
65
+ ctx[2].default
66
+ );
67
+ const default_slot = create_slot(
68
+ default_slot_template,
69
+ ctx,
70
+ /* $$scope */
71
+ ctx[1],
72
+ null
73
+ );
74
+ return {
75
+ c() {
76
+ if (default_slot)
77
+ default_slot.c();
78
+ },
79
+ m(target, anchor) {
80
+ if (default_slot)
81
+ default_slot.m(target, anchor);
82
+ current = true;
83
+ },
84
+ p(ctx2, dirty) {
85
+ if (default_slot) {
86
+ if (default_slot.p && (!current || dirty & 2)) {
87
+ update_slot_base(
88
+ default_slot,
89
+ default_slot_template,
90
+ ctx2,
91
+ /* $$scope */
92
+ ctx2[1],
93
+ !current ? get_all_dirty_from_scope(
94
+ /* $$scope */
95
+ ctx2[1]
96
+ ) : get_slot_changes(
97
+ default_slot_template,
98
+ /* $$scope */
99
+ ctx2[1],
100
+ dirty,
101
+ null
102
+ ),
103
+ null
104
+ );
105
+ }
106
+ }
107
+ },
108
+ i(local) {
109
+ if (current)
110
+ return;
111
+ transition_in(default_slot, local);
112
+ current = true;
113
+ },
114
+ o(local) {
115
+ transition_out(default_slot, local);
116
+ current = false;
117
+ },
118
+ d(detaching) {
119
+ if (default_slot)
120
+ default_slot.d(detaching);
121
+ }
122
+ };
123
+ }
124
+ function create_fragment(ctx) {
125
+ let if_block_anchor;
126
+ let current;
127
+ let if_block = (
128
+ /* visible */
129
+ ctx[0] && create_if_block(ctx)
130
+ );
131
+ return {
132
+ c() {
133
+ if (if_block)
134
+ if_block.c();
135
+ if_block_anchor = empty();
136
+ },
137
+ m(target, anchor) {
138
+ if (if_block)
139
+ if_block.m(target, anchor);
140
+ insert(target, if_block_anchor, anchor);
141
+ current = true;
142
+ },
143
+ p(ctx2, [dirty]) {
144
+ if (
145
+ /* visible */
146
+ ctx2[0]
147
+ ) {
148
+ if (if_block) {
149
+ if_block.p(ctx2, dirty);
150
+ if (dirty & 1)
151
+ transition_in(if_block, 1);
152
+ } else {
153
+ if_block = create_if_block(ctx2);
154
+ if_block.c();
155
+ transition_in(if_block, 1);
156
+ if_block.m(if_block_anchor.parentNode, if_block_anchor);
157
+ }
158
+ } else if (if_block) {
159
+ group_outros();
160
+ transition_out(if_block, 1, 1, () => {
161
+ if_block = null;
162
+ });
163
+ check_outros();
164
+ }
165
+ },
166
+ i() {
167
+ if (current)
168
+ return;
169
+ transition_in(if_block);
170
+ current = true;
171
+ },
172
+ o() {
173
+ transition_out(if_block);
174
+ current = false;
175
+ },
176
+ d(detaching) {
177
+ if (if_block)
178
+ if_block.d(detaching);
179
+ if (detaching)
180
+ detach(if_block_anchor);
181
+ }
182
+ };
183
+ }
184
+ function instance($$self, $$props, $$invalidate) {
185
+ let { $$slots: slots = {}, $$scope } = $$props;
186
+ let { visible = false } = $$props;
187
+ const { duration = 0, immediate = true } = getContext2(injectOptionsKey) || {};
188
+ const { deferred, vanish } = getContext2(injectOverlayKey);
189
+ async function destroy() {
190
+ $$invalidate(0, visible = false);
191
+ await delay(duration);
192
+ vanish == null ? void 0 : vanish();
193
+ return Promise.resolve();
194
+ }
195
+ onMount(() => immediate && $$invalidate(0, visible = true));
196
+ deferred == null ? void 0 : deferred.then(destroy).catch(destroy);
197
+ $$self.$$set = ($$props2) => {
198
+ if ("visible" in $$props2)
199
+ $$invalidate(0, visible = $$props2.visible);
200
+ if ("$$scope" in $$props2)
201
+ $$invalidate(1, $$scope = $$props2.$$scope);
202
+ };
203
+ return [visible, $$scope, slots];
204
+ }
205
+ var Overlay = class extends SvelteComponentTyped {
206
+ constructor(options) {
207
+ super(options);
208
+ init(this, options, instance, create_fragment, safe_not_equal, { visible: 0 }, noop);
209
+ }
210
+ };
211
+ export {
212
+ Overlay,
213
+ defineOverlay,
214
+ renderOverlay,
215
+ usePrograms
216
+ };
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@overlastic/svelte",
3
+ "type": "module",
4
+ "version": "0.4.3",
5
+ "license": "MIT",
6
+ "homepage": "https://github.com/hairyf/overlastic#readme",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/hairyf/overlastic.git"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/hairyf/overlastic/issues"
13
+ },
14
+ "keywords": [
15
+ "unified",
16
+ "overlay",
17
+ "svelte"
18
+ ],
19
+ "main": "./dist/index.cjs",
20
+ "publishConfig": {
21
+ "jsdelivr": "./dist/index.global.js",
22
+ "linkDirectory": false
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "dependencies": {
28
+ "svelte": "^3.57.0",
29
+ "@overlastic/core": "^0.4.3"
30
+ },
31
+ "scripts": {
32
+ "build": "tsup src/index.ts",
33
+ "lint": "eslint ."
34
+ },
35
+ "exports": {
36
+ ".": {
37
+ "import": "./dist/index.js",
38
+ "require": "./dist/index.cjs"
39
+ }
40
+ },
41
+ "types": "./dist/index.d.ts"
42
+ }