topographic-react 0.0.0-stage → 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Yahya Bedirhan Pak
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,32 @@
1
- # Temporary Holding Version
1
+ # topographic-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
+ [![npm](https://img.shields.io/npm/v/topographic-react)](https://www.npmjs.com/package/topographic-react)
4
+
5
+ Try it live in the [playground](https://yahyabedirhan.github.io/topographic/).
6
+
7
+ React bindings for [`topographic`](https://www.npmjs.com/package/topographic), the JavaScript library for topographic backgrounds. It works with React 18 and 19 and is safe for server rendering.
8
+
9
+ ```sh
10
+ npm install topographic topographic-react
11
+ ```
12
+
13
+ ```tsx
14
+ import { TopographicBackground } from 'topographic-react';
15
+
16
+ export function Hero() {
17
+ return (
18
+ <TopographicBackground styleName="granite" terrain={{ roughness: 0.3 }} style={{ height: '100vh' }}>
19
+ <h1>Hello</h1>
20
+ </TopographicBackground>
21
+ );
22
+ }
23
+ ```
24
+
25
+ For the 3D terrain, add `mode="3d"`, and optionally `elevation`, `extent`, `detail` and `camera`.
26
+
27
+ To put the background on your own element, use `useTopographicBackground(settings)`, which returns a ref.
28
+
29
+ - [Project README](https://github.com/yahyabedirhan/topographic#readme)
30
+ - [Guide](https://github.com/yahyabedirhan/topographic/blob/main/docs/guide.md)
31
+
32
+ MIT licence.
@@ -0,0 +1,33 @@
1
+ import { type HTMLAttributes, type MutableRefObject } from 'react';
2
+ import { type RendererOptions, type SettingsInput, type TopographicBackground as TopographicBackgroundInstance } from 'topographic';
3
+ export interface TopographicBackgroundSettingsProps {
4
+ /** Style id, e.g. 'dunes'. Named styleName because `style` is React's inline style prop. */
5
+ styleName?: string;
6
+ seed?: number;
7
+ lines?: SettingsInput['lines'];
8
+ terrain?: SettingsInput['terrain'];
9
+ motion?: SettingsInput['motion'];
10
+ layout?: SettingsInput['layout'];
11
+ theme?: SettingsInput['theme'];
12
+ /** '2d' is the map. '3d' is the same map as a terrain. */
13
+ mode?: SettingsInput['mode'];
14
+ elevation?: number;
15
+ extent?: SettingsInput['extent'];
16
+ detail?: number;
17
+ camera?: SettingsInput['camera'];
18
+ }
19
+ export interface TopographicBackgroundRef<T extends HTMLElement = HTMLDivElement> extends MutableRefObject<T | null> {
20
+ /** The live instance while mounted (for snapshot, or imperative updates). */
21
+ topographic: TopographicBackgroundInstance | null;
22
+ }
23
+ /** Attaches a topographic to the element you put the returned ref on. */
24
+ export declare function useTopographicBackground<T extends HTMLElement = HTMLDivElement>(settings?: TopographicBackgroundSettingsProps, options?: RendererOptions): TopographicBackgroundRef<T>;
25
+ export interface TopographicBackgroundProps extends TopographicBackgroundSettingsProps, Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
26
+ /** Renderer options (pixel budget, WebGL1). Changing them recreates the renderer. */
27
+ options?: RendererOptions;
28
+ /** Called with the instance after mount, and with null on unmount. */
29
+ onReady?: (topographic: TopographicBackgroundInstance | null) => void;
30
+ children?: React.ReactNode;
31
+ }
32
+ /** A <div> with a topographic background. Size it like any div; children render on top. */
33
+ export declare const TopographicBackground: import("react").ForwardRefExoticComponent<TopographicBackgroundProps & import("react").RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,98 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { forwardRef, useEffect, useRef, useState } from "react";
4
+ import { createTopographicBackground } from "topographic";
5
+ const key = (v) => v === void 0 ? "" : JSON.stringify(v);
6
+ function useByValue(value) {
7
+ const [kept, setKept] = useState(value);
8
+ if (key(kept) === key(value)) return kept;
9
+ setKept(value);
10
+ return value;
11
+ }
12
+ function useTopographicBackground(settings = {}, options) {
13
+ const [ref] = useState(() => ({ current: null, topographic: null }));
14
+ const latest = useRef(settings);
15
+ latest.current = settings;
16
+ const stableOptions = useByValue(options);
17
+ useEffect(() => {
18
+ if (!ref.current) return;
19
+ const { styleName: styleName2, ...rest } = latest.current;
20
+ const t = createTopographicBackground(ref.current, { ...rest, style: styleName2 }, stableOptions);
21
+ ref.topographic = t;
22
+ return () => {
23
+ t.destroy();
24
+ ref.topographic = null;
25
+ };
26
+ }, [ref, stableOptions]);
27
+ const { styleName, seed, mode, elevation, extent, detail } = settings;
28
+ const lines = useByValue(settings.lines);
29
+ const terrain = useByValue(settings.terrain);
30
+ const motion = useByValue(settings.motion);
31
+ const layout = useByValue(settings.layout);
32
+ const theme = useByValue(settings.theme);
33
+ const camera = useByValue(settings.camera);
34
+ useEffect(() => {
35
+ if (styleName !== void 0) ref.topographic?.update({ style: styleName });
36
+ }, [ref, styleName]);
37
+ useEffect(() => {
38
+ if (seed !== void 0) ref.topographic?.update({ seed });
39
+ }, [ref, seed]);
40
+ useEffect(() => {
41
+ if (lines) ref.topographic?.update({ lines });
42
+ }, [ref, lines]);
43
+ useEffect(() => {
44
+ if (terrain) ref.topographic?.update({ terrain });
45
+ }, [ref, terrain]);
46
+ useEffect(() => {
47
+ if (motion) ref.topographic?.update({ motion });
48
+ }, [ref, motion]);
49
+ useEffect(() => {
50
+ if (layout) ref.topographic?.update({ layout });
51
+ }, [ref, layout]);
52
+ useEffect(() => {
53
+ if (theme) ref.topographic?.update({ theme });
54
+ }, [ref, theme]);
55
+ useEffect(() => {
56
+ if (mode !== void 0) ref.topographic?.update({ mode });
57
+ }, [ref, mode]);
58
+ useEffect(() => {
59
+ if (elevation !== void 0) ref.topographic?.update({ elevation });
60
+ }, [ref, elevation]);
61
+ useEffect(() => {
62
+ if (extent !== void 0) ref.topographic?.update({ extent });
63
+ }, [ref, extent]);
64
+ useEffect(() => {
65
+ if (detail !== void 0) ref.topographic?.update({ detail });
66
+ }, [ref, detail]);
67
+ useEffect(() => {
68
+ if (camera) ref.topographic?.update({ camera });
69
+ }, [ref, camera]);
70
+ return ref;
71
+ }
72
+ const TopographicBackground = forwardRef(function TopographicBackground2({ styleName, seed, lines, terrain, motion, layout, theme, mode, elevation, extent, detail, camera, options, onReady, style, children, ...div }, forwarded) {
73
+ const ref = useTopographicBackground({ styleName, seed, lines, terrain, motion, layout, theme, mode, elevation, extent, detail, camera }, options);
74
+ const stableOptions = useByValue(options);
75
+ const ready = useRef(onReady);
76
+ ready.current = onReady;
77
+ useEffect(() => {
78
+ ready.current?.(ref.topographic);
79
+ return () => ready.current?.(null);
80
+ }, [ref, stableOptions]);
81
+ return /* @__PURE__ */ jsx(
82
+ "div",
83
+ {
84
+ ...div,
85
+ style: { position: "relative", ...style },
86
+ ref: (node) => {
87
+ ref.current = node;
88
+ if (typeof forwarded === "function") forwarded(node);
89
+ else if (forwarded) forwarded.current = node;
90
+ },
91
+ children: children !== void 0 && /* @__PURE__ */ jsx("div", { style: { position: "absolute", inset: 0 }, children })
92
+ }
93
+ );
94
+ });
95
+ export {
96
+ TopographicBackground,
97
+ useTopographicBackground
98
+ };
@@ -0,0 +1 @@
1
+ export { TopographicBackground, useTopographicBackground, type TopographicBackgroundProps, type TopographicBackgroundSettingsProps, type TopographicBackgroundRef } from './TopographicBackground.js';
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import { TopographicBackground, useTopographicBackground } from "./TopographicBackground.js";
2
+ export {
3
+ TopographicBackground,
4
+ useTopographicBackground
5
+ };
package/package.json CHANGED
@@ -1,6 +1,56 @@
1
1
  {
2
2
  "name": "topographic-react",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "React component and hook for topographic backgrounds.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/yahyabedirhan/topographic.git",
9
+ "directory": "packages/react"
10
+ },
11
+ "homepage": "https://yahyabedirhan.github.io/topographic/",
12
+ "bugs": {
13
+ "url": "https://github.com/yahyabedirhan/topographic/issues"
14
+ },
15
+ "keywords": [
16
+ "topography",
17
+ "topographic",
18
+ "contour",
19
+ "background",
20
+ "webgl",
21
+ "shader",
22
+ "animated-background",
23
+ "react"
24
+ ],
25
+ "type": "module",
26
+ "sideEffects": false,
27
+ "main": "./dist/index.js",
28
+ "module": "./dist/index.js",
29
+ "types": "./dist/index.d.ts",
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.js"
34
+ }
35
+ },
36
+ "files": [
37
+ "dist",
38
+ "README.md",
39
+ "LICENSE"
40
+ ],
41
+ "dependencies": {
42
+ "topographic": "^0.2.0"
43
+ },
44
+ "peerDependencies": {
45
+ "react": "^18 || ^19"
46
+ },
47
+ "devDependencies": {
48
+ "@types/react": "^18.3.0",
49
+ "@types/react-dom": "^18.3.7",
50
+ "react": "^18.3.1",
51
+ "react-dom": "^18.3.1"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public"
55
+ }
56
+ }