@elyndra/svelte-core 1.2.0

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/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@elyndra/svelte-core",
3
+ "version": "1.2.0",
4
+ "sideEffects": false,
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "description": "Elyndra core bridge components for Svelte",
9
+ "keywords": [
10
+ "elyndra",
11
+ "ui",
12
+ "front-end",
13
+ "framework",
14
+ "scifi",
15
+ "sci-fi",
16
+ "science-fiction",
17
+ "svelte"
18
+ ],
19
+ "homepage": "https://elyndra.dev",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/Gabox301/elyndra.git"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/Gabox301/elyndra/issues"
26
+ },
27
+ "funding": "https://github.com/sponsors/romelperez",
28
+ "license": "MIT",
29
+ "files": [
30
+ "src"
31
+ ],
32
+ "exports": {
33
+ ".": "./src/index.ts"
34
+ },
35
+ "types": "./src/index.ts",
36
+ "module": "./src/index.ts",
37
+ "main": "./src/index.ts",
38
+ "peerDependencies": {
39
+ "svelte": "5.57.0"
40
+ },
41
+ "dependencies": {
42
+ "@elyndra/animated": "^1.2.0",
43
+ "@elyndra/animator": "^1.2.0",
44
+ "@elyndra/bleeps": "^1.2.0",
45
+ "@elyndra/svelte-animator": "^1.2.0",
46
+ "@elyndra/svelte-bleeps": "^1.2.0",
47
+ "@elyndra/svelte-tools": "^1.2.0",
48
+ "tslib": "2.8.1"
49
+ },
50
+ "scripts": {
51
+ "build": "tsc --noEmit -p tsconfig.json && svelte-check --tsconfig tsconfig.json --output machine"
52
+ }
53
+ }
@@ -0,0 +1,51 @@
1
+ <script lang="ts">
2
+ import type { Bleep } from '@elyndra/bleeps';
3
+ import { useAnimator } from '@elyndra/svelte-animator';
4
+ import { useBleeps } from '@elyndra/svelte-bleeps';
5
+ import type { BleepsOnAnimatorProps } from './types.js';
6
+
7
+ // No destructured rest: only direct `props.*` reads stay reactive.
8
+ const props: BleepsOnAnimatorProps<string> = $props();
9
+
10
+ // Stable per-instance id, same role as Solid's `createUniqueId` / React's
11
+ // `useId`. Svelte props are a live proxy, so no transitions ref is needed,
12
+ // unlike React/Preact.
13
+ const internalId = `elyndra-bleeps-${Math.random().toString(36).slice(2)}`;
14
+ const getAnimator = useAnimator();
15
+ const bleeps = useBleeps<string>();
16
+
17
+ $effect(() => {
18
+ // Tracked so the subscription follows prop updates.
19
+ const id = props.id ?? internalId;
20
+ const animator = getAnimator?.();
21
+
22
+ if (!animator) {
23
+ return;
24
+ }
25
+
26
+ let currentBleep: Bleep | null = null;
27
+
28
+ const cancelSubscription = animator.node.subscribe((node) => {
29
+ const bleepName = (props.transitions as Record<string, string | undefined>)[node.state];
30
+
31
+ if (!props.continuous) {
32
+ currentBleep?.stop(id);
33
+ }
34
+
35
+ if (bleepName) {
36
+ const newBleep = (bleeps as Record<string, Bleep | undefined>)[bleepName];
37
+
38
+ if (newBleep) {
39
+ currentBleep?.stop(id);
40
+ currentBleep = newBleep;
41
+ currentBleep.play(id);
42
+ }
43
+ }
44
+ });
45
+
46
+ return () => {
47
+ cancelSubscription();
48
+ currentBleep?.stop(id);
49
+ };
50
+ });
51
+ </script>
@@ -0,0 +1,13 @@
1
+ import { render } from '@testing-library/svelte';
2
+ import type { Component } from 'svelte';
3
+ import { expect, test } from 'vitest';
4
+ import BleepsOnAnimator from './BleepsOnAnimator.svelte';
5
+
6
+ // `.svelte` components are `unknown` in-repo (ambient decl, tests only).
7
+ const bleepsOnAnimator = BleepsOnAnimator as Component;
8
+
9
+ test('Should render nothing without animator and bleeps providers', () => {
10
+ const { container } = render(bleepsOnAnimator, { transitions: {} });
11
+ // Script-only bridge renders no markup at all, same as the Solid adapter.
12
+ expect(container.innerHTML).toBe('');
13
+ });
@@ -0,0 +1,2 @@
1
+ export { default as BleepsOnAnimator } from './BleepsOnAnimator.svelte';
2
+ export type * from './types.js';
@@ -0,0 +1,13 @@
1
+ import type { AnimatorState } from '@elyndra/animator';
2
+
3
+ type Transitions<BleepsNames extends string> = {
4
+ [p in AnimatorState]?: BleepsNames;
5
+ };
6
+
7
+ interface BleepsOnAnimatorProps<BleepsNames extends string = string> {
8
+ id?: string;
9
+ transitions: Transitions<BleepsNames>;
10
+ continuous?: boolean;
11
+ }
12
+
13
+ export type { BleepsOnAnimatorProps, Transitions };
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './BleepsOnAnimator/index.js';
@@ -0,0 +1,7 @@
1
+ // In-repo ambient types for `.svelte` imports (tests only). The published
2
+ // package ships the `.svelte` sources and consumers get full prop inference
3
+ // from the `$props()` interfaces via their own Svelte setup.
4
+ declare module '*.svelte' {
5
+ const Component: unknown;
6
+ export default Component;
7
+ }