mirror of
https://github.com/LukeHagar/ui-development-kit.git
synced 2025-12-09 12:57:44 +00:00
588 lines
15 KiB
JavaScript
588 lines
15 KiB
JavaScript
var __defProp = Object.defineProperty;
|
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
var __publicField = (obj, key, value) => {
|
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
return value;
|
|
};
|
|
import { o as noop, a0 as get_root_for_style, g as detach, a1 as append_empty_stylesheet, y as run_all, X as is_function, v as add_render_callback, a2 as custom_event, a3 as identity, a4 as blank_object, b as children, H as flush, a5 as is_empty, a6 as flush_render_callbacks, a7 as current_component, G as set_current_component, a8 as run, a9 as dirty_components, aa as schedule_update, ab as start_hydrating, ac as end_hydrating } from "./scheduler.fBTsnP2i.js";
|
|
const is_client = typeof window !== "undefined";
|
|
let now = is_client ? () => window.performance.now() : () => Date.now();
|
|
let raf = is_client ? (cb) => requestAnimationFrame(cb) : noop;
|
|
const tasks = /* @__PURE__ */ new Set();
|
|
function run_tasks(now2) {
|
|
tasks.forEach((task) => {
|
|
if (!task.c(now2)) {
|
|
tasks.delete(task);
|
|
task.f();
|
|
}
|
|
});
|
|
if (tasks.size !== 0)
|
|
raf(run_tasks);
|
|
}
|
|
function loop(callback) {
|
|
let task;
|
|
if (tasks.size === 0)
|
|
raf(run_tasks);
|
|
return {
|
|
promise: new Promise((fulfill) => {
|
|
tasks.add(task = { c: callback, f: fulfill });
|
|
}),
|
|
abort() {
|
|
tasks.delete(task);
|
|
}
|
|
};
|
|
}
|
|
const managed_styles = /* @__PURE__ */ new Map();
|
|
let active = 0;
|
|
function hash(str) {
|
|
let hash2 = 5381;
|
|
let i = str.length;
|
|
while (i--)
|
|
hash2 = (hash2 << 5) - hash2 ^ str.charCodeAt(i);
|
|
return hash2 >>> 0;
|
|
}
|
|
function create_style_information(doc, node) {
|
|
const info = { stylesheet: append_empty_stylesheet(node), rules: {} };
|
|
managed_styles.set(doc, info);
|
|
return info;
|
|
}
|
|
function create_rule(node, a, b, duration, delay, ease, fn, uid = 0) {
|
|
const step = 16.666 / duration;
|
|
let keyframes = "{\n";
|
|
for (let p = 0; p <= 1; p += step) {
|
|
const t = a + (b - a) * ease(p);
|
|
keyframes += p * 100 + `%{${fn(t, 1 - t)}}
|
|
`;
|
|
}
|
|
const rule = keyframes + `100% {${fn(b, 1 - b)}}
|
|
}`;
|
|
const name = `__svelte_${hash(rule)}_${uid}`;
|
|
const doc = get_root_for_style(node);
|
|
const { stylesheet, rules } = managed_styles.get(doc) || create_style_information(doc, node);
|
|
if (!rules[name]) {
|
|
rules[name] = true;
|
|
stylesheet.insertRule(`@keyframes ${name} ${rule}`, stylesheet.cssRules.length);
|
|
}
|
|
const animation = node.style.animation || "";
|
|
node.style.animation = `${animation ? `${animation}, ` : ""}${name} ${duration}ms linear ${delay}ms 1 both`;
|
|
active += 1;
|
|
return name;
|
|
}
|
|
function delete_rule(node, name) {
|
|
const previous = (node.style.animation || "").split(", ");
|
|
const next = previous.filter(
|
|
name ? (anim) => anim.indexOf(name) < 0 : (anim) => anim.indexOf("__svelte") === -1
|
|
// remove all Svelte animations
|
|
);
|
|
const deleted = previous.length - next.length;
|
|
if (deleted) {
|
|
node.style.animation = next.join(", ");
|
|
active -= deleted;
|
|
if (!active)
|
|
clear_rules();
|
|
}
|
|
}
|
|
function clear_rules() {
|
|
raf(() => {
|
|
if (active)
|
|
return;
|
|
managed_styles.forEach((info) => {
|
|
const { ownerNode } = info.stylesheet;
|
|
if (ownerNode)
|
|
detach(ownerNode);
|
|
});
|
|
managed_styles.clear();
|
|
});
|
|
}
|
|
let promise;
|
|
function wait() {
|
|
if (!promise) {
|
|
promise = Promise.resolve();
|
|
promise.then(() => {
|
|
promise = null;
|
|
});
|
|
}
|
|
return promise;
|
|
}
|
|
function dispatch(node, direction, kind) {
|
|
node.dispatchEvent(custom_event(`${direction ? "intro" : "outro"}${kind}`));
|
|
}
|
|
const outroing = /* @__PURE__ */ new Set();
|
|
let outros;
|
|
function group_outros() {
|
|
outros = {
|
|
r: 0,
|
|
c: [],
|
|
p: outros
|
|
// parent group
|
|
};
|
|
}
|
|
function check_outros() {
|
|
if (!outros.r) {
|
|
run_all(outros.c);
|
|
}
|
|
outros = outros.p;
|
|
}
|
|
function transition_in(block, local) {
|
|
if (block && block.i) {
|
|
outroing.delete(block);
|
|
block.i(local);
|
|
}
|
|
}
|
|
function transition_out(block, local, detach2, callback) {
|
|
if (block && block.o) {
|
|
if (outroing.has(block))
|
|
return;
|
|
outroing.add(block);
|
|
outros.c.push(() => {
|
|
outroing.delete(block);
|
|
if (callback) {
|
|
if (detach2)
|
|
block.d(1);
|
|
callback();
|
|
}
|
|
});
|
|
block.o(local);
|
|
} else if (callback) {
|
|
callback();
|
|
}
|
|
}
|
|
const null_transition = { duration: 0 };
|
|
function create_in_transition(node, fn, params) {
|
|
const options = { direction: "in" };
|
|
let config = fn(node, params, options);
|
|
let running = false;
|
|
let animation_name;
|
|
let task;
|
|
let uid = 0;
|
|
function cleanup() {
|
|
if (animation_name)
|
|
delete_rule(node, animation_name);
|
|
}
|
|
function go() {
|
|
const {
|
|
delay = 0,
|
|
duration = 300,
|
|
easing = identity,
|
|
tick = noop,
|
|
css
|
|
} = config || null_transition;
|
|
if (css)
|
|
animation_name = create_rule(node, 0, 1, duration, delay, easing, css, uid++);
|
|
tick(0, 1);
|
|
const start_time = now() + delay;
|
|
const end_time = start_time + duration;
|
|
if (task)
|
|
task.abort();
|
|
running = true;
|
|
add_render_callback(() => dispatch(node, true, "start"));
|
|
task = loop((now2) => {
|
|
if (running) {
|
|
if (now2 >= end_time) {
|
|
tick(1, 0);
|
|
dispatch(node, true, "end");
|
|
cleanup();
|
|
return running = false;
|
|
}
|
|
if (now2 >= start_time) {
|
|
const t = easing((now2 - start_time) / duration);
|
|
tick(t, 1 - t);
|
|
}
|
|
}
|
|
return running;
|
|
});
|
|
}
|
|
let started = false;
|
|
return {
|
|
start() {
|
|
if (started)
|
|
return;
|
|
started = true;
|
|
delete_rule(node);
|
|
if (is_function(config)) {
|
|
config = config(options);
|
|
wait().then(go);
|
|
} else {
|
|
go();
|
|
}
|
|
},
|
|
invalidate() {
|
|
started = false;
|
|
},
|
|
end() {
|
|
if (running) {
|
|
cleanup();
|
|
running = false;
|
|
}
|
|
}
|
|
};
|
|
}
|
|
function create_out_transition(node, fn, params) {
|
|
const options = { direction: "out" };
|
|
let config = fn(node, params, options);
|
|
let running = true;
|
|
let animation_name;
|
|
const group = outros;
|
|
group.r += 1;
|
|
let original_inert_value;
|
|
function go() {
|
|
const {
|
|
delay = 0,
|
|
duration = 300,
|
|
easing = identity,
|
|
tick = noop,
|
|
css
|
|
} = config || null_transition;
|
|
if (css)
|
|
animation_name = create_rule(node, 1, 0, duration, delay, easing, css);
|
|
const start_time = now() + delay;
|
|
const end_time = start_time + duration;
|
|
add_render_callback(() => dispatch(node, false, "start"));
|
|
if ("inert" in node) {
|
|
original_inert_value = /** @type {HTMLElement} */
|
|
node.inert;
|
|
node.inert = true;
|
|
}
|
|
loop((now2) => {
|
|
if (running) {
|
|
if (now2 >= end_time) {
|
|
tick(0, 1);
|
|
dispatch(node, false, "end");
|
|
if (!--group.r) {
|
|
run_all(group.c);
|
|
}
|
|
return false;
|
|
}
|
|
if (now2 >= start_time) {
|
|
const t = easing((now2 - start_time) / duration);
|
|
tick(1 - t, t);
|
|
}
|
|
}
|
|
return running;
|
|
});
|
|
}
|
|
if (is_function(config)) {
|
|
wait().then(() => {
|
|
config = config(options);
|
|
go();
|
|
});
|
|
} else {
|
|
go();
|
|
}
|
|
return {
|
|
end(reset) {
|
|
if (reset && "inert" in node) {
|
|
node.inert = original_inert_value;
|
|
}
|
|
if (reset && config.tick) {
|
|
config.tick(1, 0);
|
|
}
|
|
if (running) {
|
|
if (animation_name)
|
|
delete_rule(node, animation_name);
|
|
running = false;
|
|
}
|
|
}
|
|
};
|
|
}
|
|
function create_bidirectional_transition(node, fn, params, intro) {
|
|
const options = { direction: "both" };
|
|
let config = fn(node, params, options);
|
|
let t = intro ? 0 : 1;
|
|
let running_program = null;
|
|
let pending_program = null;
|
|
let animation_name = null;
|
|
let original_inert_value;
|
|
function clear_animation() {
|
|
if (animation_name)
|
|
delete_rule(node, animation_name);
|
|
}
|
|
function init2(program, duration) {
|
|
const d = (
|
|
/** @type {Program['d']} */
|
|
program.b - t
|
|
);
|
|
duration *= Math.abs(d);
|
|
return {
|
|
a: t,
|
|
b: program.b,
|
|
d,
|
|
duration,
|
|
start: program.start,
|
|
end: program.start + duration,
|
|
group: program.group
|
|
};
|
|
}
|
|
function go(b) {
|
|
const {
|
|
delay = 0,
|
|
duration = 300,
|
|
easing = identity,
|
|
tick = noop,
|
|
css
|
|
} = config || null_transition;
|
|
const program = {
|
|
start: now() + delay,
|
|
b
|
|
};
|
|
if (!b) {
|
|
program.group = outros;
|
|
outros.r += 1;
|
|
}
|
|
if ("inert" in node) {
|
|
if (b) {
|
|
if (original_inert_value !== void 0) {
|
|
node.inert = original_inert_value;
|
|
}
|
|
} else {
|
|
original_inert_value = /** @type {HTMLElement} */
|
|
node.inert;
|
|
node.inert = true;
|
|
}
|
|
}
|
|
if (running_program || pending_program) {
|
|
pending_program = program;
|
|
} else {
|
|
if (css) {
|
|
clear_animation();
|
|
animation_name = create_rule(node, t, b, duration, delay, easing, css);
|
|
}
|
|
if (b)
|
|
tick(0, 1);
|
|
running_program = init2(program, duration);
|
|
add_render_callback(() => dispatch(node, b, "start"));
|
|
loop((now2) => {
|
|
if (pending_program && now2 > pending_program.start) {
|
|
running_program = init2(pending_program, duration);
|
|
pending_program = null;
|
|
dispatch(node, running_program.b, "start");
|
|
if (css) {
|
|
clear_animation();
|
|
animation_name = create_rule(
|
|
node,
|
|
t,
|
|
running_program.b,
|
|
running_program.duration,
|
|
0,
|
|
easing,
|
|
config.css
|
|
);
|
|
}
|
|
}
|
|
if (running_program) {
|
|
if (now2 >= running_program.end) {
|
|
tick(t = running_program.b, 1 - t);
|
|
dispatch(node, running_program.b, "end");
|
|
if (!pending_program) {
|
|
if (running_program.b) {
|
|
clear_animation();
|
|
} else {
|
|
if (!--running_program.group.r)
|
|
run_all(running_program.group.c);
|
|
}
|
|
}
|
|
running_program = null;
|
|
} else if (now2 >= running_program.start) {
|
|
const p = now2 - running_program.start;
|
|
t = running_program.a + running_program.d * easing(p / running_program.duration);
|
|
tick(t, 1 - t);
|
|
}
|
|
}
|
|
return !!(running_program || pending_program);
|
|
});
|
|
}
|
|
}
|
|
return {
|
|
run(b) {
|
|
if (is_function(config)) {
|
|
wait().then(() => {
|
|
const opts = { direction: b ? "in" : "out" };
|
|
config = config(opts);
|
|
go(b);
|
|
});
|
|
} else {
|
|
go(b);
|
|
}
|
|
},
|
|
end() {
|
|
clear_animation();
|
|
running_program = pending_program = null;
|
|
}
|
|
};
|
|
}
|
|
function bind(component, name, callback) {
|
|
const index = component.$$.props[name];
|
|
if (index !== void 0) {
|
|
component.$$.bound[index] = callback;
|
|
callback(component.$$.ctx[index]);
|
|
}
|
|
}
|
|
function create_component(block) {
|
|
block && block.c();
|
|
}
|
|
function claim_component(block, parent_nodes) {
|
|
block && block.l(parent_nodes);
|
|
}
|
|
function mount_component(component, target, anchor) {
|
|
const { fragment, after_update } = component.$$;
|
|
fragment && fragment.m(target, anchor);
|
|
add_render_callback(() => {
|
|
const new_on_destroy = component.$$.on_mount.map(run).filter(is_function);
|
|
if (component.$$.on_destroy) {
|
|
component.$$.on_destroy.push(...new_on_destroy);
|
|
} else {
|
|
run_all(new_on_destroy);
|
|
}
|
|
component.$$.on_mount = [];
|
|
});
|
|
after_update.forEach(add_render_callback);
|
|
}
|
|
function destroy_component(component, detaching) {
|
|
const $$ = component.$$;
|
|
if ($$.fragment !== null) {
|
|
flush_render_callbacks($$.after_update);
|
|
run_all($$.on_destroy);
|
|
$$.fragment && $$.fragment.d(detaching);
|
|
$$.on_destroy = $$.fragment = null;
|
|
$$.ctx = [];
|
|
}
|
|
}
|
|
function make_dirty(component, i) {
|
|
if (component.$$.dirty[0] === -1) {
|
|
dirty_components.push(component);
|
|
schedule_update();
|
|
component.$$.dirty.fill(0);
|
|
}
|
|
component.$$.dirty[i / 31 | 0] |= 1 << i % 31;
|
|
}
|
|
function init(component, options, instance, create_fragment, not_equal, props, append_styles = null, dirty = [-1]) {
|
|
const parent_component = current_component;
|
|
set_current_component(component);
|
|
const $$ = component.$$ = {
|
|
fragment: null,
|
|
ctx: [],
|
|
// state
|
|
props,
|
|
update: noop,
|
|
not_equal,
|
|
bound: blank_object(),
|
|
// lifecycle
|
|
on_mount: [],
|
|
on_destroy: [],
|
|
on_disconnect: [],
|
|
before_update: [],
|
|
after_update: [],
|
|
context: new Map(options.context || (parent_component ? parent_component.$$.context : [])),
|
|
// everything else
|
|
callbacks: blank_object(),
|
|
dirty,
|
|
skip_bound: false,
|
|
root: options.target || parent_component.$$.root
|
|
};
|
|
append_styles && append_styles($$.root);
|
|
let ready = false;
|
|
$$.ctx = instance ? instance(component, options.props || {}, (i, ret, ...rest) => {
|
|
const value = rest.length ? rest[0] : ret;
|
|
if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) {
|
|
if (!$$.skip_bound && $$.bound[i])
|
|
$$.bound[i](value);
|
|
if (ready)
|
|
make_dirty(component, i);
|
|
}
|
|
return ret;
|
|
}) : [];
|
|
$$.update();
|
|
ready = true;
|
|
run_all($$.before_update);
|
|
$$.fragment = create_fragment ? create_fragment($$.ctx) : false;
|
|
if (options.target) {
|
|
if (options.hydrate) {
|
|
start_hydrating();
|
|
const nodes = children(options.target);
|
|
$$.fragment && $$.fragment.l(nodes);
|
|
nodes.forEach(detach);
|
|
} else {
|
|
$$.fragment && $$.fragment.c();
|
|
}
|
|
if (options.intro)
|
|
transition_in(component.$$.fragment);
|
|
mount_component(component, options.target, options.anchor);
|
|
end_hydrating();
|
|
flush();
|
|
}
|
|
set_current_component(parent_component);
|
|
}
|
|
class SvelteComponent {
|
|
constructor() {
|
|
/**
|
|
* ### PRIVATE API
|
|
*
|
|
* Do not use, may change at any time
|
|
*
|
|
* @type {any}
|
|
*/
|
|
__publicField(this, "$$");
|
|
/**
|
|
* ### PRIVATE API
|
|
*
|
|
* Do not use, may change at any time
|
|
*
|
|
* @type {any}
|
|
*/
|
|
__publicField(this, "$$set");
|
|
}
|
|
/** @returns {void} */
|
|
$destroy() {
|
|
destroy_component(this, 1);
|
|
this.$destroy = noop;
|
|
}
|
|
/**
|
|
* @template {Extract<keyof Events, string>} K
|
|
* @param {K} type
|
|
* @param {((e: Events[K]) => void) | null | undefined} callback
|
|
* @returns {() => void}
|
|
*/
|
|
$on(type, callback) {
|
|
if (!is_function(callback)) {
|
|
return noop;
|
|
}
|
|
const callbacks = this.$$.callbacks[type] || (this.$$.callbacks[type] = []);
|
|
callbacks.push(callback);
|
|
return () => {
|
|
const index = callbacks.indexOf(callback);
|
|
if (index !== -1)
|
|
callbacks.splice(index, 1);
|
|
};
|
|
}
|
|
/**
|
|
* @param {Partial<Props>} props
|
|
* @returns {void}
|
|
*/
|
|
$set(props) {
|
|
if (this.$$set && !is_empty(props)) {
|
|
this.$$.skip_bound = true;
|
|
this.$$set(props);
|
|
this.$$.skip_bound = false;
|
|
}
|
|
}
|
|
}
|
|
const PUBLIC_VERSION = "4";
|
|
if (typeof window !== "undefined")
|
|
(window.__svelte || (window.__svelte = { v: /* @__PURE__ */ new Set() })).v.add(PUBLIC_VERSION);
|
|
export {
|
|
SvelteComponent as S,
|
|
transition_out as a,
|
|
create_component as b,
|
|
check_outros as c,
|
|
claim_component as d,
|
|
destroy_component as e,
|
|
bind as f,
|
|
group_outros as g,
|
|
create_in_transition as h,
|
|
init as i,
|
|
create_bidirectional_transition as j,
|
|
create_out_transition as k,
|
|
mount_component as m,
|
|
transition_in as t
|
|
};
|