Skip to content

Commit

Permalink
chore: internals cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte committed Dec 22, 2024
1 parent 6fd5ad6 commit 7ad4bbd
Show file tree
Hide file tree
Showing 80 changed files with 79 additions and 78 deletions.
2 changes: 1 addition & 1 deletion packages/runed/src/lib/internal/configurable-globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BROWSER } from "esm-env";

export type ConfigurableWindow = {
/** Provide a custom `window` object to use in place of the global `window` object. */
window?: typeof globalThis & Window;
window?: Window;
};

export type ConfigurableDocument = {
Expand Down
1 change: 1 addition & 0 deletions packages/runed/src/lib/internal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export type Expand<T> = T extends infer U ? { [K in keyof U]: U[K] } : never;
export type WritableProperties<T> = {
-readonly [P in keyof T]: T[P];
};
export type GlobalWindow = Window & typeof globalThis;
1 change: 0 additions & 1 deletion packages/runed/src/lib/utilities/AnimationFrames/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/runed/src/lib/utilities/Context/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { Context } from "./Context.js";
export * from "./context.js";
2 changes: 1 addition & 1 deletion packages/runed/src/lib/utilities/Debounced/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./Debounced.svelte.js";
export * from "./debounced.svelte.js";
1 change: 0 additions & 1 deletion packages/runed/src/lib/utilities/ElementRect/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/runed/src/lib/utilities/ElementSize/index.ts

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion packages/runed/src/lib/utilities/IsFocusWithin/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/runed/src/lib/utilities/IsIdle/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/runed/src/lib/utilities/IsInViewport/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/runed/src/lib/utilities/IsMounted/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/runed/src/lib/utilities/IsSupported/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/runed/src/lib/utilities/PersistedState/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/runed/src/lib/utilities/PressedKeys/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/runed/src/lib/utilities/Previous/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./Previous.svelte.js";
export * from "./previous.svelte.js";
1 change: 0 additions & 1 deletion packages/runed/src/lib/utilities/StateHistory/index.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/runed/src/lib/utilities/active-element/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./active-element.js";
1 change: 0 additions & 1 deletion packages/runed/src/lib/utilities/activeElement/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class AnimationFrames {
#frame: number | null = null;
#fps = $state(0);
#running = $state(false);
#window = defaultWindow;
#window: Window | undefined = defaultWindow;

constructor(callback: (params: RafCallbackParams) => void, options: AnimationFramesOptions = {}) {
if (options.window) this.#window = options.window;
Expand Down
1 change: 1 addition & 0 deletions packages/runed/src/lib/utilities/animation-frames/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./animation-frames.svelte.js";
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useDebounce } from "../useDebounce/useDebounce.svelte.js";
import { useDebounce } from "../use-debounce/use-debounce.svelte.js";
import { watch } from "../watch/watch.svelte.js";
import type { Getter, MaybeGetter } from "$lib/internal/types.js";
import { noop } from "$lib/internal/utils/function.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect } from "vitest";
import { Debounced } from "./Debounced.svelte.js";
import { Debounced } from "./debounced.svelte.js";
import { testWithEffect } from "$lib/test/util.svelte.js";

describe("Debounced", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { extract } from "../extract/extract.svelte.js";
import { useMutationObserver } from "../useMutationObserver/useMutationObserver.svelte.js";
import { useResizeObserver } from "../useResizeObserver/useResizeObserver.svelte.js";
import { useMutationObserver } from "../use-mutation-observer/use-mutation-observer.svelte.js";
import { useResizeObserver } from "../use-resize-observer/use-resize-observer.svelte.js";
import type { MaybeElementGetter, WritableProperties } from "$lib/internal/types.js";
import type { ConfigurableWindow } from "$lib/internal/configurable-globals.js";

Expand Down
1 change: 1 addition & 0 deletions packages/runed/src/lib/utilities/element-rect/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./element-rect.svelte.js";
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defaultWindow, type ConfigurableWindow } from "$lib/internal/configurable-globals.js";
import type { MaybeElementGetter } from "$lib/internal/types.js";
import type { GlobalWindow, MaybeElementGetter } from "$lib/internal/types.js";
import { get } from "$lib/internal/utils/get.js";

export type ElementSizeOptions = ConfigurableWindow & {
Expand Down Expand Up @@ -36,11 +36,11 @@ export class ElementSize {
};

$effect(() => {
if (!window) return;
if (!window || !("ResizeObserver" in window)) return;
const node$ = get(node);
if (!node$) return;

const observer = new window.ResizeObserver((entries) => {
const observer = new (window as unknown as GlobalWindow).ResizeObserver((entries) => {
for (const entry of entries) {
const boxSize =
options.box === "content-box" ? entry.contentBoxSize : entry.borderBoxSize;
Expand Down
1 change: 1 addition & 0 deletions packages/runed/src/lib/utilities/element-size/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./element-size.svelte.js";
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { type Action, FiniteStateMachine } from "./FiniteStateMachine.svelte.js";
import { type Action, FiniteStateMachine } from "./finite-state-machine.svelte.js";

describe("FiniteStateMachine", () => {
describe("simple toggle switch", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./finite-state-machine.svelte.js";
46 changes: 23 additions & 23 deletions packages/runed/src/lib/utilities/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
export * from "./activeElement/index.js";
export * from "./onClickOutside/index.js";
export * from "./useDebounce/index.js";
export * from "./ElementSize/index.js";
export * from "./useEventListener/index.js";
export * from "./IsIdle/index.js";
export * from "./IsMounted/index.js";
export * from "./IsSupported/index.js";
export * from "./StateHistory/index.js";
export * from "./Previous/index.js";
export * from "./active-element/index.js";
export * from "./on-click-outside/index.js";
export * from "./use-debounce/index.js";
export * from "./element-size/index.js";
export * from "./use-event-listener/index.js";
export * from "./is-idle/index.js";
export * from "./is-mounted/index.js";
export * from "./is-supported/index.js";
export * from "./state-history/index.js";
export * from "./previous/index.js";
export * from "./watch/index.js";
export * from "./Debounced/index.js";
export * from "./PressedKeys/index.js";
export * from "./ElementRect/index.js";
export * from "./useMutationObserver/index.js";
export * from "./useResizeObserver/index.js";
export * from "./AnimationFrames/index.js";
export * from "./useIntersectionObserver/index.js";
export * from "./IsFocusWithin/index.js";
export * from "./FiniteStateMachine/index.js";
export * from "./PersistedState/index.js";
export * from "./useGeolocation/index.js";
export * from "./Context/index.js";
export * from "./IsInViewport/index.js";
export * from "./debounced/index.js";
export * from "./pressed-keys/index.js";
export * from "./element-rect/index.js";
export * from "./use-mutation-observer/index.js";
export * from "./use-resize-observer/index.js";
export * from "./animation-frames/index.js";
export * from "./use-intersection-observer/index.js";
export * from "./is-focus-within/index.js";
export * from "./finite-state-machine/index.js";
export * from "./persisted-state/index.js";
export * from "./use-geolocation/index.js";
export * from "./context/index.js";
export * from "./is-in-viewport/index.js";
1 change: 1 addition & 0 deletions packages/runed/src/lib/utilities/is-focus-within/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./is-focus-within.svelte.js";
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { MaybeElementGetter } from "$lib/internal/types.js";
import { ActiveElement, type ActiveElementOptions } from "../activeElement/activeElement.svelte.js";
import { ActiveElement, type ActiveElementOptions } from "../active-element/active-element.js";
import { extract } from "../extract/extract.svelte.js";

export interface IsFocusWithinOptions extends ActiveElementOptions {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { effectRootScope } from "$lib/test/util.svelte.js";
import { describe, expect } from "vitest";
import { IsFocusWithin } from "./IsFocusWithin.svelte.js";
import { IsFocusWithin } from "./is-focus-within.svelte.js";

describe("IsFocusWithin", () => {
let shadowHost: HTMLElement;
Expand Down
1 change: 1 addition & 0 deletions packages/runed/src/lib/utilities/is-idle/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./is-idle.svelte.js";
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { extract } from "../extract/index.js";
import { useDebounce } from "../useDebounce/index.js";
import { useDebounce } from "../use-debounce/use-debounce.svelte.js";
import type { MaybeGetter } from "$lib/internal/types.js";
import { useEventListener } from "$lib/utilities/useEventListener/useEventListener.svelte.js";
import { useEventListener } from "$lib/utilities/use-event-listener/use-event-listener.svelte.js";
import {
defaultWindow,
type ConfigurableDocument,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { IsIdle } from "./IsIdle.svelte.js";
import { IsIdle } from "./is-idle.svelte.js";
import { testWithEffect, vitestSetTimeoutWrapper } from "$lib/test/util.svelte.js";

describe("IsIdle", () => {
Expand Down
1 change: 1 addition & 0 deletions packages/runed/src/lib/utilities/is-in-viewport/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./is-in-viewport.svelte.js";
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { MaybeElementGetter } from "$lib/internal/types.js";
import {
useIntersectionObserver,
type UseIntersectionObserverOptions,
} from "../useIntersectionObserver/useIntersectionObserver.svelte.js";
} from "../use-intersection-observer/use-intersection-observer.svelte.js";

export type IsInViewportOptions = ConfigurableWindow & UseIntersectionObserverOptions;

Expand Down
1 change: 1 addition & 0 deletions packages/runed/src/lib/utilities/is-mounted/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./is-mounted.svelte.js";
1 change: 1 addition & 0 deletions packages/runed/src/lib/utilities/is-supported/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./is-supported.svelte.js";
1 change: 1 addition & 0 deletions packages/runed/src/lib/utilities/on-click-outside/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./on-click-outside.svelte.js";
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { noop } from "$lib/internal/utils/function.js";
import { isElement } from "$lib/internal/utils/is.js";
import { sleep } from "$lib/internal/utils/sleep.js";
import { extract } from "../extract/extract.svelte.js";
import { useDebounce } from "../useDebounce/useDebounce.svelte.js";
import { useDebounce } from "../use-debounce/use-debounce.svelte.js";
import { watch } from "../watch/watch.svelte.js";

export type OnClickOutsideOptions = ConfigurableWindow &
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, vi, beforeEach, afterEach } from "vitest";
import { tick } from "svelte";
import { onClickOutside } from "./onClickOutside.svelte.js";
import { onClickOutside } from "./on-click-outside.svelte.js";
import { testWithEffect } from "$lib/test/util.svelte.js";

describe("onClickOutside", () => {
Expand Down
1 change: 0 additions & 1 deletion packages/runed/src/lib/utilities/onClickOutside/index.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/runed/src/lib/utilities/persisted-state/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./persisted-state.svelte.js";
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Serializer<T> = {

type StorageType = "local" | "session";

function getStorage(storageType: StorageType, window: Window & typeof globalThis): Storage {
function getStorage(storageType: StorageType, window: Window): Storage {
switch (storageType) {
case "local":
return window.localStorage;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect } from "vitest";

import { testWithEffect } from "$lib/test/util.svelte.js";
import { PersistedState } from "./PersistedState.svelte.js";
import { PersistedState } from "./persisted-state.svelte.js";

const key = "test-key";
const initialValue = "test-value";
Expand Down
1 change: 1 addition & 0 deletions packages/runed/src/lib/utilities/pressed-keys/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { PressedKeys } from "./pressed-keys.svelte.js";
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defaultWindow, type ConfigurableWindow } from "$lib/internal/configurable-globals.js";
import { useEventListener } from "../useEventListener/useEventListener.svelte.js";
import { useEventListener } from "../use-event-listener/use-event-listener.svelte.js";

export type PressedKeysOptions = ConfigurableWindow;
/**
Expand Down
1 change: 1 addition & 0 deletions packages/runed/src/lib/utilities/state-history/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./state-history.svelte.js";
1 change: 1 addition & 0 deletions packages/runed/src/lib/utilities/use-debounce/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./use-debounce.svelte.js";
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, vi } from "vitest";
import { useDebounce } from "./useDebounce.svelte.js";
import { useDebounce } from "./use-debounce.svelte.js";
import { testWithEffect } from "$lib/test/util.svelte.js";

describe("useDebounce", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./use-event-listener.svelte.js";
1 change: 1 addition & 0 deletions packages/runed/src/lib/utilities/use-geolocation/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./use-geolocation.svelte.js";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./use-intersection-observer.svelte.js";
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { extract } from "../extract/extract.svelte.js";
import type { MaybeElementGetter, MaybeGetter } from "$lib/internal/types.js";
import type { GlobalWindow, MaybeElementGetter, MaybeGetter } from "$lib/internal/types.js";
import { get } from "$lib/internal/utils/get.js";
import { defaultWindow, type ConfigurableWindow } from "$lib/internal/configurable-globals.js";

Expand Down Expand Up @@ -49,8 +49,8 @@ export function useIntersectionObserver(

const stop = $effect.root(() => {
$effect(() => {
if (!targets.size || !isActive || !window) return;
observer = new window.IntersectionObserver(callback, {
if (!targets.size || !isActive || !window || !("IntersectionObserver" in window)) return;
observer = new (window as unknown as GlobalWindow).IntersectionObserver(callback, {
rootMargin,
root: get(root),
threshold,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./use-mutation-observer.svelte.js";
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { extract } from "../extract/extract.svelte.js";
import type { MaybeGetter } from "$lib/internal/types.js";
import type { GlobalWindow, MaybeGetter } from "$lib/internal/types.js";
import { defaultWindow, type ConfigurableWindow } from "$lib/internal/configurable-globals.js";

export interface UseMutationObserverOptions extends MutationObserverInit, ConfigurableWindow {}
Expand All @@ -25,8 +25,8 @@ export function useMutationObserver(

const stop = $effect.root(() => {
$effect(() => {
if (!targets.size || !window) return;
observer = new window.MutationObserver(callback);
if (!targets.size || !window || !("MutationObserver" in window)) return;
observer = new (window as unknown as GlobalWindow).MutationObserver(callback);
for (const el of targets) observer.observe(el, options);

return () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { useResizeObserver } from "./use-resize-observer.svelte.js";
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { extract } from "../extract/extract.svelte.js";
import type { MaybeGetter } from "$lib/internal/types.js";
import type { GlobalWindow, MaybeGetter } from "$lib/internal/types.js";
import { defaultWindow, type ConfigurableWindow } from "$lib/internal/configurable-globals.js";

export interface ResizeObserverSize {
Expand Down Expand Up @@ -57,8 +57,8 @@ export function useResizeObserver(

const stop = $effect.root(() => {
$effect(() => {
if (!targets.size || !window) return;
observer = new window.ResizeObserver(callback);
if (!targets.size || !window || !("ResizeObserver" in window)) return;
observer = new (window as unknown as GlobalWindow).ResizeObserver(callback);
for (const el of targets) observer.observe(el, options);

return () => {
Expand Down
1 change: 0 additions & 1 deletion packages/runed/src/lib/utilities/useDebounce/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/runed/src/lib/utilities/useEventListener/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/runed/src/lib/utilities/useGeolocation/index.ts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion sites/docs/src/routes/api/search.json/search.json

Large diffs are not rendered by default.

0 comments on commit 7ad4bbd

Please sign in to comment.