@usemote/react 0.0.0-stage → 0.1.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 George Heavenson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,41 @@
1
- # Temporary Holding Version
1
+ # @usemote/react
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ React binding for [Mote](https://mote.hearvie.dev). **627 B** brotlied.
4
+
5
+ ```bash
6
+ pnpm add @usemote/core @usemote/react
7
+ ```
8
+
9
+ ```tsx
10
+ import { FloatingField } from '@usemote/react';
11
+
12
+ <section style={{ position: 'relative', overflow: 'hidden' }}>
13
+ <FloatingField mode="bob" set="geo" count={12} avoid="center" depth />
14
+ <h1 style={{ position: 'relative' }}>Your headline</h1>
15
+ </section>
16
+ ```
17
+
18
+ **The field is a layer.** It fills its nearest positioned ancestor, so that
19
+ parent needs `position: relative`, and content above it needs
20
+ `position: relative` too — otherwise the shapes cover it.
21
+
22
+ ## SSR
23
+
24
+ Works in Next.js app router and anywhere else. The server renders frame 0, the
25
+ client renders the identical markup, so there is no hydration mismatch and no
26
+ flash of an empty section.
27
+
28
+ If you pass an inline `packs`, `shapes` or `theme` literal, it is compared by
29
+ content rather than identity, so it will not rebuild the field each render. A
30
+ custom `mode` preset object should be memoised.
31
+
32
+ ## Inspiration
33
+
34
+ Architecturally modelled on **[Navii](https://github.com/uxderrick/navii)** by
35
+ **[Derrick Tsorme](https://github.com/uxderrick)** — a deterministic avatar
36
+ engine, and the reason this project exists. No code is shared; the debt is
37
+ architectural, and it is a large one. If you need avatars, use Navii.
38
+
39
+ ## License
40
+
41
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,74 @@
1
+ 'use strict';
2
+
3
+ var core = require('@usemote/core');
4
+ var react = require('react');
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+
7
+ // src/FloatingField.tsx
8
+ var BASE_STYLE = {
9
+ position: "absolute",
10
+ inset: 0,
11
+ overflow: "hidden",
12
+ pointerEvents: "none"
13
+ };
14
+ function FloatingField({
15
+ className,
16
+ style,
17
+ ssrWidth = 1200,
18
+ ssrHeight = 600,
19
+ ...options
20
+ }) {
21
+ const ref = react.useRef(null);
22
+ const handle = react.useRef(null);
23
+ const poolKey = react.useMemo(
24
+ () => JSON.stringify([
25
+ options.packs?.map((p) => `${p.id}@${p.version}`) ?? null,
26
+ options.shapes ?? null,
27
+ Array.isArray(options.theme) ? options.theme : options.theme ?? null
28
+ ]),
29
+ [options.packs, options.shapes, options.theme]
30
+ );
31
+ const modeIsObject = typeof options.mode === "object";
32
+ react.useEffect(() => {
33
+ const el = ref.current;
34
+ if (!el) return;
35
+ handle.current = core.createField(el, options);
36
+ return () => {
37
+ handle.current?.destroy();
38
+ handle.current = null;
39
+ };
40
+ }, [
41
+ poolKey,
42
+ options.seed,
43
+ options.count,
44
+ options.size,
45
+ options.set,
46
+ options.depth,
47
+ options.direction,
48
+ modeIsObject ? "custom" : options.mode
49
+ ]);
50
+ react.useEffect(() => {
51
+ const live = {};
52
+ if (options.speed !== void 0) live.speed = options.speed;
53
+ if (options.interactive !== void 0) live.interactive = options.interactive;
54
+ if (options.avoid !== void 0) live.avoid = options.avoid;
55
+ if (options.paused !== void 0) live.paused = options.paused;
56
+ handle.current?.update(live);
57
+ }, [options.speed, options.interactive, options.avoid, options.paused]);
58
+ const ssrHTML = react.useMemo(
59
+ () => core.renderFieldHTML({ ...options, width: ssrWidth, height: ssrHeight }),
60
+ [poolKey, options.seed, options.count, options.size, options.set, options.depth, ssrWidth, ssrHeight]
61
+ );
62
+ return /* @__PURE__ */ jsxRuntime.jsx(
63
+ "div",
64
+ {
65
+ ref,
66
+ className,
67
+ "aria-hidden": "true",
68
+ style: { ...BASE_STYLE, ...style },
69
+ dangerouslySetInnerHTML: { __html: ssrHTML }
70
+ }
71
+ );
72
+ }
73
+
74
+ exports.FloatingField = FloatingField;
@@ -0,0 +1,29 @@
1
+ import { FieldOptions } from '@usemote/core';
2
+ import { CSSProperties, ReactElement } from 'react';
3
+
4
+ /**
5
+ * <FloatingField /> — a thin React wrapper around `createField`.
6
+ *
7
+ * Deliberately thin: all logic lives in @usemote/core so there is one
8
+ * implementation to maintain and test across every framework wrapper.
9
+ *
10
+ * SSR works by rendering core's frame-0 markup via `dangerouslySetInnerHTML`.
11
+ * Because layout is a pure function of (seed, options), the server and client
12
+ * agree exactly, so there is no hydration mismatch and no first-paint flash of
13
+ * an empty section. On mount the field adopts that existing markup rather than
14
+ * throwing it away.
15
+ */
16
+
17
+ interface FloatingFieldProps extends FieldOptions {
18
+ className?: string;
19
+ style?: CSSProperties;
20
+ /**
21
+ * Size used for the server-rendered frame. Only affects the pre-hydration
22
+ * paint; the client re-measures its real box on mount.
23
+ */
24
+ ssrWidth?: number;
25
+ ssrHeight?: number;
26
+ }
27
+ declare function FloatingField({ className, style, ssrWidth, ssrHeight, ...options }: FloatingFieldProps): ReactElement;
28
+
29
+ export { FloatingField, type FloatingFieldProps };
@@ -0,0 +1,29 @@
1
+ import { FieldOptions } from '@usemote/core';
2
+ import { CSSProperties, ReactElement } from 'react';
3
+
4
+ /**
5
+ * <FloatingField /> — a thin React wrapper around `createField`.
6
+ *
7
+ * Deliberately thin: all logic lives in @usemote/core so there is one
8
+ * implementation to maintain and test across every framework wrapper.
9
+ *
10
+ * SSR works by rendering core's frame-0 markup via `dangerouslySetInnerHTML`.
11
+ * Because layout is a pure function of (seed, options), the server and client
12
+ * agree exactly, so there is no hydration mismatch and no first-paint flash of
13
+ * an empty section. On mount the field adopts that existing markup rather than
14
+ * throwing it away.
15
+ */
16
+
17
+ interface FloatingFieldProps extends FieldOptions {
18
+ className?: string;
19
+ style?: CSSProperties;
20
+ /**
21
+ * Size used for the server-rendered frame. Only affects the pre-hydration
22
+ * paint; the client re-measures its real box on mount.
23
+ */
24
+ ssrWidth?: number;
25
+ ssrHeight?: number;
26
+ }
27
+ declare function FloatingField({ className, style, ssrWidth, ssrHeight, ...options }: FloatingFieldProps): ReactElement;
28
+
29
+ export { FloatingField, type FloatingFieldProps };
package/dist/index.js ADDED
@@ -0,0 +1,72 @@
1
+ import { createField, renderFieldHTML } from '@usemote/core';
2
+ import { useRef, useMemo, useEffect } from 'react';
3
+ import { jsx } from 'react/jsx-runtime';
4
+
5
+ // src/FloatingField.tsx
6
+ var BASE_STYLE = {
7
+ position: "absolute",
8
+ inset: 0,
9
+ overflow: "hidden",
10
+ pointerEvents: "none"
11
+ };
12
+ function FloatingField({
13
+ className,
14
+ style,
15
+ ssrWidth = 1200,
16
+ ssrHeight = 600,
17
+ ...options
18
+ }) {
19
+ const ref = useRef(null);
20
+ const handle = useRef(null);
21
+ const poolKey = useMemo(
22
+ () => JSON.stringify([
23
+ options.packs?.map((p) => `${p.id}@${p.version}`) ?? null,
24
+ options.shapes ?? null,
25
+ Array.isArray(options.theme) ? options.theme : options.theme ?? null
26
+ ]),
27
+ [options.packs, options.shapes, options.theme]
28
+ );
29
+ const modeIsObject = typeof options.mode === "object";
30
+ useEffect(() => {
31
+ const el = ref.current;
32
+ if (!el) return;
33
+ handle.current = createField(el, options);
34
+ return () => {
35
+ handle.current?.destroy();
36
+ handle.current = null;
37
+ };
38
+ }, [
39
+ poolKey,
40
+ options.seed,
41
+ options.count,
42
+ options.size,
43
+ options.set,
44
+ options.depth,
45
+ options.direction,
46
+ modeIsObject ? "custom" : options.mode
47
+ ]);
48
+ useEffect(() => {
49
+ const live = {};
50
+ if (options.speed !== void 0) live.speed = options.speed;
51
+ if (options.interactive !== void 0) live.interactive = options.interactive;
52
+ if (options.avoid !== void 0) live.avoid = options.avoid;
53
+ if (options.paused !== void 0) live.paused = options.paused;
54
+ handle.current?.update(live);
55
+ }, [options.speed, options.interactive, options.avoid, options.paused]);
56
+ const ssrHTML = useMemo(
57
+ () => renderFieldHTML({ ...options, width: ssrWidth, height: ssrHeight }),
58
+ [poolKey, options.seed, options.count, options.size, options.set, options.depth, ssrWidth, ssrHeight]
59
+ );
60
+ return /* @__PURE__ */ jsx(
61
+ "div",
62
+ {
63
+ ref,
64
+ className,
65
+ "aria-hidden": "true",
66
+ style: { ...BASE_STYLE, ...style },
67
+ dangerouslySetInnerHTML: { __html: ssrHTML }
68
+ }
69
+ );
70
+ }
71
+
72
+ export { FloatingField };
package/package.json CHANGED
@@ -1,6 +1,62 @@
1
1
  {
2
2
  "name": "@usemote/react",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "React component for Mote — deterministic floating-shape background fields.",
5
+ "license": "MIT",
6
+ "author": {
7
+ "name": "George Heavenson",
8
+ "url": "https://hearvie.dev"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/oti-adjei/mote.git",
13
+ "directory": "packages/react"
14
+ },
15
+ "homepage": "https://mote.hearvie.dev",
16
+ "bugs": "https://github.com/oti-adjei/mote/issues",
17
+ "type": "module",
18
+ "main": "./dist/index.cjs",
19
+ "module": "./dist/index.js",
20
+ "types": "./dist/index.d.ts",
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "import": "./dist/index.js",
25
+ "require": "./dist/index.cjs"
26
+ }
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "README.md",
31
+ "LICENSE"
32
+ ],
33
+ "sideEffects": false,
34
+ "size-limit": [
35
+ {
36
+ "path": "dist/index.js",
37
+ "limit": "3 kB"
38
+ }
39
+ ],
40
+ "peerDependencies": {
41
+ "@usemote/core": "^0.1.1",
42
+ "react": ">=18"
43
+ },
44
+ "devDependencies": {
45
+ "@usemote/core": "0.1.1",
46
+ "@types/react": "^19.2.0",
47
+ "@types/react-dom": "^19.2.0",
48
+ "react": "^19.2.0",
49
+ "react-dom": "^19.2.0",
50
+ "@testing-library/react": "^16.3.0",
51
+ "happy-dom": "^20.0.0"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public"
55
+ },
56
+ "scripts": {
57
+ "build": "tsup",
58
+ "typecheck": "tsc -p tsconfig.json --noEmit",
59
+ "test": "vitest run",
60
+ "size": "size-limit"
61
+ }
6
62
  }