@7sage/vidstack
Version:
UI component library for building high-quality, accessible video and audio experiences on the web.
1,080 lines (1,041 loc) • 30.6 kB
JavaScript
const SCOPE = Symbol(0);
let scheduledEffects = false, runningEffects = false, currentScope = null, currentObserver = null, currentObservers = null, currentObserversIndex = 0, effects = [], defaultContext = {};
const NOOP = () => {
}, STATE_CLEAN = 0, STATE_CHECK = 1, STATE_DIRTY = 2, STATE_DISPOSED = 3;
function flushEffects() {
scheduledEffects = true;
queueMicrotask(runEffects);
}
function runEffects() {
if (!effects.length) {
scheduledEffects = false;
return;
}
runningEffects = true;
for (let i = 0; i < effects.length; i++) {
if (effects[i].$st !== STATE_CLEAN)
runTop(effects[i]);
}
effects = [];
scheduledEffects = false;
runningEffects = false;
}
function runTop(node) {
let ancestors = [node];
while (node = node[SCOPE]) {
if (node.$e && node.$st !== STATE_CLEAN)
ancestors.push(node);
}
for (let i = ancestors.length - 1; i >= 0; i--) {
updateCheck(ancestors[i]);
}
}
function peek(fn) {
return compute(currentScope, fn, null);
}
function untrack(fn) {
return compute(null, fn, null);
}
function tick() {
if (!runningEffects)
runEffects();
}
function getScope() {
return currentScope;
}
function scoped(run, scope) {
try {
return compute(scope, run, null);
} catch (error) {
handleError(scope, error);
return;
}
}
function getContext(key, scope = currentScope) {
return scope?.$cx[key];
}
function setContext(key, value, scope = currentScope) {
if (scope)
scope.$cx = { ...scope.$cx, [key]: value };
}
function onDispose(disposable) {
if (!disposable || !currentScope)
return disposable || NOOP;
const node = currentScope;
if (!node.$d) {
node.$d = disposable;
} else if (Array.isArray(node.$d)) {
node.$d.push(disposable);
} else {
node.$d = [node.$d, disposable];
}
return function removeDispose() {
if (node.$st === STATE_DISPOSED)
return;
disposable.call(null);
if (isFunction$1(node.$d)) {
node.$d = null;
} else if (Array.isArray(node.$d)) {
node.$d.splice(node.$d.indexOf(disposable), 1);
}
};
}
function dispose(self = true) {
if (this.$st === STATE_DISPOSED)
return;
if (this.$h) {
if (Array.isArray(this.$h)) {
for (let i = this.$h.length - 1; i >= 0; i--) {
dispose.call(this.$h[i]);
}
} else {
dispose.call(this.$h);
}
}
if (self) {
const parent = this[SCOPE];
if (parent) {
if (Array.isArray(parent.$h)) {
parent.$h.splice(parent.$h.indexOf(this), 1);
} else {
parent.$h = null;
}
}
disposeNode(this);
}
}
function disposeNode(node) {
node.$st = STATE_DISPOSED;
if (node.$d)
emptyDisposal(node);
if (node.$s)
removeSourceObservers(node, 0);
node[SCOPE] = null;
node.$s = null;
node.$o = null;
node.$h = null;
node.$cx = defaultContext;
node.$eh = null;
}
function emptyDisposal(scope) {
try {
if (Array.isArray(scope.$d)) {
for (let i = scope.$d.length - 1; i >= 0; i--) {
const callable = scope.$d[i];
callable.call(callable);
}
} else {
scope.$d.call(scope.$d);
}
scope.$d = null;
} catch (error) {
handleError(scope, error);
}
}
function compute(scope, compute2, observer) {
const prevScope = currentScope, prevObserver = currentObserver;
currentScope = scope;
currentObserver = observer;
try {
return compute2.call(scope);
} finally {
currentScope = prevScope;
currentObserver = prevObserver;
}
}
function handleError(scope, error) {
if (!scope || !scope.$eh)
throw error;
let i = 0, len = scope.$eh.length, currentError = error;
for (i = 0; i < len; i++) {
try {
scope.$eh[i](currentError);
break;
} catch (error2) {
currentError = error2;
}
}
if (i === len)
throw currentError;
}
function read() {
if (this.$st === STATE_DISPOSED)
return this.$v;
if (currentObserver && !this.$e) {
if (!currentObservers && currentObserver.$s && currentObserver.$s[currentObserversIndex] == this) {
currentObserversIndex++;
} else if (!currentObservers)
currentObservers = [this];
else
currentObservers.push(this);
}
if (this.$c)
updateCheck(this);
return this.$v;
}
function write(newValue) {
const value = isFunction$1(newValue) ? newValue(this.$v) : newValue;
if (this.$ch(this.$v, value)) {
this.$v = value;
if (this.$o) {
for (let i = 0; i < this.$o.length; i++) {
notify(this.$o[i], STATE_DIRTY);
}
}
}
return this.$v;
}
const ScopeNode = function Scope() {
this[SCOPE] = null;
this.$h = null;
if (currentScope)
currentScope.append(this);
};
const ScopeProto = ScopeNode.prototype;
ScopeProto.$cx = defaultContext;
ScopeProto.$eh = null;
ScopeProto.$c = null;
ScopeProto.$d = null;
ScopeProto.append = function(child) {
child[SCOPE] = this;
if (!this.$h) {
this.$h = child;
} else if (Array.isArray(this.$h)) {
this.$h.push(child);
} else {
this.$h = [this.$h, child];
}
child.$cx = child.$cx === defaultContext ? this.$cx : { ...this.$cx, ...child.$cx };
if (this.$eh) {
child.$eh = !child.$eh ? this.$eh : [...child.$eh, ...this.$eh];
}
};
ScopeProto.dispose = function() {
dispose.call(this);
};
function createScope() {
return new ScopeNode();
}
const ComputeNode = function Computation(initialValue, compute2, options) {
ScopeNode.call(this);
this.$st = compute2 ? STATE_DIRTY : STATE_CLEAN;
this.$i = false;
this.$e = false;
this.$s = null;
this.$o = null;
this.$v = initialValue;
if (compute2)
this.$c = compute2;
if (options && options.dirty)
this.$ch = options.dirty;
};
const ComputeProto = ComputeNode.prototype;
Object.setPrototypeOf(ComputeProto, ScopeProto);
ComputeProto.$ch = isNotEqual;
ComputeProto.call = read;
function createComputation(initialValue, compute2, options) {
return new ComputeNode(initialValue, compute2, options);
}
function isNotEqual(a, b) {
return a !== b;
}
function isFunction$1(value) {
return typeof value === "function";
}
function updateCheck(node) {
if (node.$st === STATE_CHECK) {
for (let i = 0; i < node.$s.length; i++) {
updateCheck(node.$s[i]);
if (node.$st === STATE_DIRTY) {
break;
}
}
}
if (node.$st === STATE_DIRTY)
update(node);
else
node.$st = STATE_CLEAN;
}
function cleanup(node) {
if (node.$h)
dispose.call(node, false);
if (node.$d)
emptyDisposal(node);
node.$eh = node[SCOPE] ? node[SCOPE].$eh : null;
}
function update(node) {
let prevObservers = currentObservers, prevObserversIndex = currentObserversIndex;
currentObservers = null;
currentObserversIndex = 0;
try {
cleanup(node);
const result = compute(node, node.$c, node);
updateObservers(node);
if (!node.$e && node.$i) {
write.call(node, result);
} else {
node.$v = result;
node.$i = true;
}
} catch (error) {
updateObservers(node);
handleError(node, error);
} finally {
currentObservers = prevObservers;
currentObserversIndex = prevObserversIndex;
node.$st = STATE_CLEAN;
}
}
function updateObservers(node) {
if (currentObservers) {
if (node.$s)
removeSourceObservers(node, currentObserversIndex);
if (node.$s && currentObserversIndex > 0) {
node.$s.length = currentObserversIndex + currentObservers.length;
for (let i = 0; i < currentObservers.length; i++) {
node.$s[currentObserversIndex + i] = currentObservers[i];
}
} else {
node.$s = currentObservers;
}
let source;
for (let i = currentObserversIndex; i < node.$s.length; i++) {
source = node.$s[i];
if (!source.$o)
source.$o = [node];
else
source.$o.push(node);
}
} else if (node.$s && currentObserversIndex < node.$s.length) {
removeSourceObservers(node, currentObserversIndex);
node.$s.length = currentObserversIndex;
}
}
function notify(node, state) {
if (node.$st >= state)
return;
if (node.$e && node.$st === STATE_CLEAN) {
effects.push(node);
if (!scheduledEffects)
flushEffects();
}
node.$st = state;
if (node.$o) {
for (let i = 0; i < node.$o.length; i++) {
notify(node.$o[i], STATE_CHECK);
}
}
}
function removeSourceObservers(node, index) {
let source, swap;
for (let i = index; i < node.$s.length; i++) {
source = node.$s[i];
if (source.$o) {
swap = source.$o.indexOf(node);
source.$o[swap] = source.$o[source.$o.length - 1];
source.$o.pop();
}
}
}
function noop(...args) {
}
function isNull(value) {
return value === null;
}
function isUndefined(value) {
return typeof value === "undefined";
}
function isObject(value) {
return value?.constructor === Object;
}
function isNumber(value) {
return typeof value === "number" && !Number.isNaN(value);
}
function isString(value) {
return typeof value === "string";
}
function isBoolean(value) {
return typeof value === "boolean";
}
function isFunction(value) {
return typeof value === "function";
}
function isArray(value) {
return Array.isArray(value);
}
const EVENT = class Event {
}, DOM_EVENT = Symbol("DOM_EVENT");
class DOMEvent extends EVENT {
[DOM_EVENT] = true;
/**
* The event detail.
*/
detail;
/**
* The event trigger chain.
*/
triggers = new EventTriggers();
/**
* The preceding event that was responsible for this event being fired.
*/
get trigger() {
return this.triggers.source;
}
/**
* The origin event that lead to this event being fired.
*/
get originEvent() {
return this.triggers.origin;
}
/**
* Whether the origin event was triggered by the user.
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted}
*/
get isOriginTrusted() {
return this.triggers.origin?.isTrusted ?? false;
}
constructor(type, ...init) {
super(type, init[0]);
this.detail = init[0]?.detail;
const trigger = init[0]?.trigger;
if (trigger) this.triggers.add(trigger);
}
}
class EventTriggers {
chain = [];
get source() {
return this.chain[0];
}
get origin() {
return this.chain[this.chain.length - 1];
}
/**
* Appends the event to the end of the chain.
*/
add(event) {
this.chain.push(event);
if (isDOMEvent(event)) {
this.chain.push(...event.triggers);
}
}
/**
* Removes the event from the chain and returns it (if found).
*/
remove(event) {
return this.chain.splice(this.chain.indexOf(event), 1)[0];
}
/**
* Returns whether the chain contains the given `event`.
*/
has(event) {
return this.chain.some((e) => e === event);
}
/**
* Returns whether the chain contains the given event type.
*/
hasType(type) {
return !!this.findType(type);
}
/**
* Returns the first event with the given `type` found in the chain.
*/
findType(type) {
return this.chain.find((e) => e.type === type);
}
/**
* Walks an event chain on a given `event`, and invokes the given `callback` for each trigger event.
*/
walk(callback) {
for (const event of this.chain) {
const returnValue = callback(event);
if (returnValue) return [event, returnValue];
}
}
[Symbol.iterator]() {
return this.chain.values();
}
}
function isDOMEvent(event) {
return !!event?.[DOM_EVENT];
}
function walkTriggerEventChain(event, callback) {
if (!isDOMEvent(event)) return;
return event.triggers.walk(callback);
}
function findTriggerEvent(event, type) {
return isDOMEvent(event) ? event.triggers.findType(type) : void 0;
}
function hasTriggerEvent(event, type) {
return !!findTriggerEvent(event, type);
}
function appendTriggerEvent(event, trigger) {
if (trigger) event.triggers.add(trigger);
}
class EventsTarget extends EventTarget {
/** @internal type only */
$ts__events;
addEventListener(type, callback, options) {
return super.addEventListener(type, callback, options);
}
removeEventListener(type, callback, options) {
return super.removeEventListener(type, callback, options);
}
}
function listenEvent(target, type, handler, options) {
return noop;
}
class EventsController {
#target;
#controller;
get signal() {
return this.#controller.signal;
}
constructor(target) {
this.#target = target;
this.#controller = new AbortController();
onDispose(this.abort.bind(this));
}
add(type, handler, options) {
if (this.signal.aborted) throw Error("aborted");
this.#target.addEventListener(type, handler, {
...options,
signal: options?.signal ? anySignal(this.signal, options.signal) : this.signal
});
return this;
}
remove(type, handler) {
this.#target.removeEventListener(type, handler);
return this;
}
abort(reason) {
this.#controller.abort(reason);
}
}
function anySignal(...signals) {
const controller = new AbortController(), options = { signal: controller.signal };
function onAbort(event) {
controller.abort(event.target.reason);
}
for (const signal of signals) {
if (signal.aborted) {
controller.abort(signal.reason);
break;
}
signal.addEventListener("abort", onAbort, options);
}
return controller.signal;
}
function isPointerEvent(event) {
return !!event?.type.startsWith("pointer");
}
function isTouchEvent(event) {
return !!event?.type.startsWith("touch");
}
function isMouseEvent(event) {
return /^(click|mouse)/.test(event?.type ?? "");
}
function isKeyboardEvent(event) {
return !!event?.type.startsWith("key");
}
function wasEnterKeyPressed(event) {
return isKeyboardEvent(event) && event.key === "Enter";
}
function isKeyboardClick(event) {
return isKeyboardEvent(event) && (event.key === "Enter" || event.key === " ");
}
function isDOMNode(node) {
return node instanceof Node;
}
function setAttribute(host, name, value) {
if (!host) return;
else if (!value && value !== "" && value !== 0) {
host.removeAttribute(name);
} else {
const attrValue = value === true ? "" : value + "";
if (host.getAttribute(name) !== attrValue) {
host.setAttribute(name, attrValue);
}
}
}
function setStyle(host, property, value) {
if (!host) return;
else if (!value && value !== 0) {
host.style.removeProperty(property);
} else {
host.style.setProperty(property, value + "");
}
}
function signal(initialValue, options) {
const node = createComputation(initialValue, null, options), signal2 = read.bind(node);
signal2[SCOPE] = true;
signal2.set = write.bind(node);
return signal2;
}
function isReadSignal(fn) {
return isFunction$1(fn) && SCOPE in fn;
}
function computed(compute, options) {
const node = createComputation(
options?.initial,
compute,
options
), signal2 = read.bind(node);
signal2[SCOPE] = true;
return signal2;
}
function effect$1(effect2, options) {
const signal2 = createComputation(
null,
function runEffect() {
let effectResult = effect2();
isFunction$1(effectResult) && onDispose(effectResult);
return null;
},
void 0
);
signal2.$e = true;
update(signal2);
return dispose.bind(signal2, true);
}
function isWriteSignal(fn) {
return isReadSignal(fn) && "set" in fn;
}
function createContext(provide) {
return { id: Symbol(), provide };
}
function provideContext(context, value, scope = getScope()) {
const hasProvidedValue = !isUndefined(value);
setContext(context.id, hasProvidedValue ? value : context.provide?.(), scope);
}
function useContext(context) {
const value = getContext(context.id);
return value;
}
function hasProvidedContext(context) {
return !isUndefined(getContext(context.id));
}
const PROPS = /* @__PURE__ */ Symbol(0);
const METHODS = /* @__PURE__ */ Symbol(0);
class ViewController extends EventTarget {
/** @internal */
$$;
get el() {
return this.$$.el;
}
get $el() {
return this.$$.$el();
}
get scope() {
return this.$$.scope;
}
get attachScope() {
return this.$$.attachScope;
}
get connectScope() {
return this.$$.connectScope;
}
/** @internal */
get $props() {
return this.$$.props;
}
/** @internal */
get $state() {
return this.$$.$state;
}
get state() {
return this.$$.state;
}
constructor() {
super();
}
attach({ $$ }) {
this.$$ = $$;
$$.addHooks(this);
return this;
}
addEventListener(type, callback, options) {
this.listen(type, callback, options);
}
removeEventListener(type, callback, options) {
this.el?.removeEventListener(type, callback, options);
}
/**
* The given callback is invoked when the component is ready to be set up.
*
* - This hook will run once.
* - This hook is called both client-side and server-side.
* - It's safe to use context inside this hook.
* - The host element has not attached yet - wait for `onAttach`.
*/
/**
* This method can be used to specify attributes that should be set on the host element. Any
* attributes that are assigned to a function will be considered a signal and updated accordingly.
*/
setAttributes(attributes) {
if (!this.$$.attrs) this.$$.attrs = {};
Object.assign(this.$$.attrs, attributes);
}
/**
* This method can be used to specify styles that should set be set on the host element. Any
* styles that are assigned to a function will be considered a signal and updated accordingly.
*/
setStyles(styles) {
if (!this.$$.styles) this.$$.styles = {};
Object.assign(this.$$.styles, styles);
}
/**
* This method is used to satisfy the CSS variables contract specified on the current
* component. Other CSS variables can be set via the `setStyles` method.
*/
setCSSVars(vars) {
this.setStyles(vars);
}
/**
* Type-safe utility for creating component DOM events.
*/
createEvent(type, ...init) {
return new DOMEvent(type, init[0]);
}
/**
* Creates a `DOMEvent` and dispatches it from the host element. This method is typed to
* match all component events.
*/
dispatch(type, ...init) {
return false;
}
dispatchEvent(event) {
return this.dispatch(event);
}
/**
* Adds an event listener for the given `type` and returns a function which can be invoked to
* remove the event listener.
*
* - The listener is removed if the current scope is disposed.
* - This method is safe to use on the server (noop).
*/
listen(type, handler, options) {
return noop;
}
}
const effect = serverEffect;
function serverEffect(effect2, options) {
if (typeof process !== "undefined" && process.env?.NODE_ENV === "test") {
return effect$1(effect2);
}
return noop;
}
class Component extends ViewController {
subscribe(callback) {
return scoped(() => effect(() => callback(this.state)), this.$$.scope);
}
destroy() {
this.$$.destroy();
}
}
function prop(target, propertyKey, descriptor) {
if (!target[PROPS]) target[PROPS] = /* @__PURE__ */ new Set();
target[PROPS].add(propertyKey);
}
function method(target, propertyKey, descriptor) {
if (!target[METHODS]) target[METHODS] = /* @__PURE__ */ new Set();
target[METHODS].add(propertyKey);
}
class State {
id = Symbol(0);
record;
#descriptors;
constructor(record) {
this.record = record;
this.#descriptors = Object.getOwnPropertyDescriptors(record);
}
create() {
const store = {}, state = new Proxy(store, { get: (_, prop2) => store[prop2]() });
for (const name of Object.keys(this.record)) {
const getter = this.#descriptors[name].get;
store[name] = getter ? computed(getter.bind(state)) : signal(this.record[name]);
}
return store;
}
reset(record, filter) {
for (const name of Object.keys(record)) {
if (!this.#descriptors[name].get && (!filter || filter(name))) {
record[name].set(this.record[name]);
}
}
}
}
function useState(state) {
return useContext(state);
}
function camelToKebabCase(str) {
return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
}
function kebabToCamelCase(str) {
return str.replace(/-./g, (x) => x[1].toUpperCase());
}
function uppercaseFirstChar(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
function ariaBool(value) {
return value ? "true" : "false";
}
function createDisposalBin() {
const disposal = /* @__PURE__ */ new Set();
return {
add(...callbacks) {
for (const callback of callbacks) disposal.add(callback);
},
empty() {
for (const callback of disposal) callback();
disposal.clear();
}
};
}
function deferredPromise() {
let resolve, reject;
const promise = new Promise((res, rej) => {
resolve = res;
reject = rej;
});
return { promise, resolve, reject };
}
function waitTimeout(delay) {
return new Promise((resolve) => setTimeout(resolve, delay));
}
function animationFrameThrottle(func) {
return noop;
}
var key = {
fullscreenEnabled: 0,
fullscreenElement: 1,
requestFullscreen: 2,
exitFullscreen: 3,
fullscreenchange: 4,
fullscreenerror: 5,
fullscreen: 6
};
var webkit = [
"webkitFullscreenEnabled",
"webkitFullscreenElement",
"webkitRequestFullscreen",
"webkitExitFullscreen",
"webkitfullscreenchange",
"webkitfullscreenerror",
"-webkit-full-screen"
];
var moz = [
"mozFullScreenEnabled",
"mozFullScreenElement",
"mozRequestFullScreen",
"mozCancelFullScreen",
"mozfullscreenchange",
"mozfullscreenerror",
"-moz-full-screen"
];
var ms = [
"msFullscreenEnabled",
"msFullscreenElement",
"msRequestFullscreen",
"msExitFullscreen",
"MSFullscreenChange",
"MSFullscreenError",
"-ms-fullscreen"
];
var document$1 = typeof window !== "undefined" && typeof window.document !== "undefined" ? window.document : {};
var vendor = "fullscreenEnabled" in document$1 && Object.keys(key) || webkit[0] in document$1 && webkit || moz[0] in document$1 && moz || ms[0] in document$1 && ms || [];
var fscreen = {
requestFullscreen: function(element) {
return element[vendor[key.requestFullscreen]]();
},
requestFullscreenFunction: function(element) {
return element[vendor[key.requestFullscreen]];
},
get exitFullscreen() {
return document$1[vendor[key.exitFullscreen]].bind(document$1);
},
get fullscreenPseudoClass() {
return ":" + vendor[key.fullscreen];
},
addEventListener: function(type, handler, options) {
return document$1.addEventListener(vendor[key[type]], handler, options);
},
removeEventListener: function(type, handler, options) {
return document$1.removeEventListener(vendor[key[type]], handler, options);
},
get fullscreenEnabled() {
return Boolean(document$1[vendor[key.fullscreenEnabled]]);
},
set fullscreenEnabled(val) {
},
get fullscreenElement() {
return document$1[vendor[key.fullscreenElement]];
},
set fullscreenElement(val) {
},
get onfullscreenchange() {
return document$1[("on" + vendor[key.fullscreenchange]).toLowerCase()];
},
set onfullscreenchange(handler) {
return document$1[("on" + vendor[key.fullscreenchange]).toLowerCase()] = handler;
},
get onfullscreenerror() {
return document$1[("on" + vendor[key.fullscreenerror]).toLowerCase()];
},
set onfullscreenerror(handler) {
return document$1[("on" + vendor[key.fullscreenerror]).toLowerCase()] = handler;
}
};
var functionThrottle = throttle;
function throttle(fn, interval, options) {
var timeoutId = null;
var throttledFn = null;
var leading = (options && options.leading);
var trailing = (options && options.trailing);
if (leading == null) {
leading = true; // default
}
if (trailing == null) {
trailing = !leading; //default
}
if (leading == true) {
trailing = false; // forced because there should be invocation per call
}
var cancel = function() {
if (timeoutId) {
clearTimeout(timeoutId);
timeoutId = null;
}
};
var flush = function() {
var call = throttledFn;
cancel();
if (call) {
call();
}
};
var throttleWrapper = function() {
var callNow = leading && !timeoutId;
var context = this;
var args = arguments;
throttledFn = function() {
return fn.apply(context, args);
};
if (!timeoutId) {
timeoutId = setTimeout(function() {
timeoutId = null;
if (trailing) {
return throttledFn();
}
}, interval);
}
if (callNow) {
callNow = false;
return throttledFn();
}
};
throttleWrapper.cancel = cancel;
throttleWrapper.flush = flush;
return throttleWrapper;
}
var functionDebounce = debounce;
function debounce(fn, wait, callFirst) {
var timeout = null;
var debouncedFn = null;
var clear = function() {
if (timeout) {
clearTimeout(timeout);
debouncedFn = null;
timeout = null;
}
};
var flush = function() {
var call = debouncedFn;
clear();
if (call) {
call();
}
};
var debounceWrapper = function() {
if (!wait) {
return fn.apply(this, arguments);
}
var context = this;
var args = arguments;
var callNow = callFirst && !timeout;
clear();
debouncedFn = function() {
fn.apply(context, args);
};
timeout = setTimeout(function() {
timeout = null;
if (!callNow) {
var call = debouncedFn;
debouncedFn = null;
return call();
}
}, wait);
if (callNow) {
return debouncedFn();
}
};
debounceWrapper.cancel = clear;
debounceWrapper.flush = flush;
return debounceWrapper;
}
const t = (t2) => "object" == typeof t2 && null != t2 && 1 === t2.nodeType, e = (t2, e2) => (!e2 || "hidden" !== t2) && ("visible" !== t2 && "clip" !== t2), n = (t2, n2) => {
if (t2.clientHeight < t2.scrollHeight || t2.clientWidth < t2.scrollWidth) {
const o2 = getComputedStyle(t2, null);
return e(o2.overflowY, n2) || e(o2.overflowX, n2) || ((t3) => {
const e2 = ((t4) => {
if (!t4.ownerDocument || !t4.ownerDocument.defaultView) return null;
try {
return t4.ownerDocument.defaultView.frameElement;
} catch (t5) {
return null;
}
})(t3);
return !!e2 && (e2.clientHeight < t3.scrollHeight || e2.clientWidth < t3.scrollWidth);
})(t2);
}
return false;
}, o = (t2, e2, n2, o2, l2, r2, i, s) => r2 < t2 && i > e2 || r2 > t2 && i < e2 ? 0 : r2 <= t2 && s <= n2 || i >= e2 && s >= n2 ? r2 - t2 - o2 : i > e2 && s < n2 || r2 < t2 && s > n2 ? i - e2 + l2 : 0, l = (t2) => {
const e2 = t2.parentElement;
return null == e2 ? t2.getRootNode().host || null : e2;
}, r = (e2, r2) => {
var i, s, d, h;
if ("undefined" == typeof document) return [];
const { scrollMode: c, block: f, inline: u, boundary: a, skipOverflowHiddenElements: g } = r2, p = "function" == typeof a ? a : (t2) => t2 !== a;
if (!t(e2)) throw new TypeError("Invalid target");
const m = document.scrollingElement || document.documentElement, w = [];
let W = e2;
for (; t(W) && p(W); ) {
if (W = l(W), W === m) {
w.push(W);
break;
}
null != W && W === document.body && n(W) && !n(document.documentElement) || null != W && n(W, g) && w.push(W);
}
const b = null != (s = null == (i = window.visualViewport) ? void 0 : i.width) ? s : innerWidth, H = null != (h = null == (d = window.visualViewport) ? void 0 : d.height) ? h : innerHeight, { scrollX: y, scrollY: M } = window, { height: v, width: E, top: x, right: C, bottom: I, left: R } = e2.getBoundingClientRect(), { top: T, right: B, bottom: F, left: V } = ((t2) => {
const e3 = window.getComputedStyle(t2);
return { top: parseFloat(e3.scrollMarginTop) || 0, right: parseFloat(e3.scrollMarginRight) || 0, bottom: parseFloat(e3.scrollMarginBottom) || 0, left: parseFloat(e3.scrollMarginLeft) || 0 };
})(e2);
let k = "start" === f || "nearest" === f ? x - T : "end" === f ? I + F : x + v / 2 - T + F, D = "center" === u ? R + E / 2 - V + B : "end" === u ? C + B : R - V;
const L = [];
for (let t2 = 0; t2 < w.length; t2++) {
const e3 = w[t2], { height: l2, width: r3, top: i2, right: s2, bottom: d2, left: h2 } = e3.getBoundingClientRect();
if ("if-needed" === c && x >= 0 && R >= 0 && I <= H && C <= b && (e3 === m && !n(e3) || x >= i2 && I <= d2 && R >= h2 && C <= s2)) return L;
const a2 = getComputedStyle(e3), g2 = parseInt(a2.borderLeftWidth, 10), p2 = parseInt(a2.borderTopWidth, 10), W2 = parseInt(a2.borderRightWidth, 10), T2 = parseInt(a2.borderBottomWidth, 10);
let B2 = 0, F2 = 0;
const V2 = "offsetWidth" in e3 ? e3.offsetWidth - e3.clientWidth - g2 - W2 : 0, S = "offsetHeight" in e3 ? e3.offsetHeight - e3.clientHeight - p2 - T2 : 0, X = "offsetWidth" in e3 ? 0 === e3.offsetWidth ? 0 : r3 / e3.offsetWidth : 0, Y = "offsetHeight" in e3 ? 0 === e3.offsetHeight ? 0 : l2 / e3.offsetHeight : 0;
if (m === e3) B2 = "start" === f ? k : "end" === f ? k - H : "nearest" === f ? o(M, M + H, H, p2, T2, M + k, M + k + v, v) : k - H / 2, F2 = "start" === u ? D : "center" === u ? D - b / 2 : "end" === u ? D - b : o(y, y + b, b, g2, W2, y + D, y + D + E, E), B2 = Math.max(0, B2 + M), F2 = Math.max(0, F2 + y);
else {
B2 = "start" === f ? k - i2 - p2 : "end" === f ? k - d2 + T2 + S : "nearest" === f ? o(i2, d2, l2, p2, T2 + S, k, k + v, v) : k - (i2 + l2 / 2) + S / 2, F2 = "start" === u ? D - h2 - g2 : "center" === u ? D - (h2 + r3 / 2) + V2 / 2 : "end" === u ? D - s2 + W2 + V2 : o(h2, s2, r3, g2, W2 + V2, D, D + E, E);
const { scrollLeft: t3, scrollTop: n2 } = e3;
B2 = 0 === Y ? 0 : Math.max(0, Math.min(n2 + B2 / Y, e3.scrollHeight - l2 / Y + S)), F2 = 0 === X ? 0 : Math.max(0, Math.min(t3 + F2 / X, e3.scrollWidth - r3 / X + V2)), k += n2 - B2, D += t3 - F2;
}
L.push({ el: e3, top: B2, left: F2 });
}
return L;
};
export { Component, DOMEvent, EventsController, EventsTarget, State, ViewController, animationFrameThrottle, appendTriggerEvent, ariaBool, camelToKebabCase, computed, createContext, createDisposalBin, createScope, deferredPromise, effect, findTriggerEvent, fscreen, functionDebounce, functionThrottle, getScope, hasProvidedContext, hasTriggerEvent, isArray, isBoolean, isDOMNode, isFunction, isKeyboardClick, isKeyboardEvent, isMouseEvent, isNull, isNumber, isObject, isPointerEvent, isString, isTouchEvent, isUndefined, isWriteSignal, kebabToCamelCase, listenEvent, method, noop, onDispose, peek, prop, provideContext, r, scoped, setAttribute, setStyle, signal, tick, untrack, uppercaseFirstChar, useContext, useState, waitTimeout, walkTriggerEventChain, wasEnterKeyPressed };