@usemote/react 0.0.0-stage → 0.1.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/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,58 @@
1
1
  {
2
2
  "name": "@usemote/react",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "React component for Mote — deterministic floating-shape background fields.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/oti-adjei/mote.git",
9
+ "directory": "packages/react"
10
+ },
11
+ "homepage": "https://mote.hearvie.dev",
12
+ "bugs": "https://github.com/oti-adjei/mote/issues",
13
+ "type": "module",
14
+ "main": "./dist/index.cjs",
15
+ "module": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js",
21
+ "require": "./dist/index.cjs"
22
+ }
23
+ },
24
+ "files": [
25
+ "dist",
26
+ "README.md",
27
+ "LICENSE"
28
+ ],
29
+ "sideEffects": false,
30
+ "scripts": {
31
+ "build": "tsup",
32
+ "typecheck": "tsc -p tsconfig.json --noEmit",
33
+ "test": "vitest run",
34
+ "size": "size-limit"
35
+ },
36
+ "size-limit": [
37
+ {
38
+ "path": "dist/index.js",
39
+ "limit": "3 kB"
40
+ }
41
+ ],
42
+ "peerDependencies": {
43
+ "@usemote/core": "workspace:^0.1.0",
44
+ "react": ">=18"
45
+ },
46
+ "devDependencies": {
47
+ "@usemote/core": "workspace:*",
48
+ "@types/react": "^19.2.0",
49
+ "@types/react-dom": "^19.2.0",
50
+ "react": "^19.2.0",
51
+ "react-dom": "^19.2.0",
52
+ "@testing-library/react": "^16.3.0",
53
+ "happy-dom": "^20.0.0"
54
+ },
55
+ "publishConfig": {
56
+ "access": "public"
57
+ }
58
+ }