dh-remixer-sdk 0.0.28-23f57ed → 0.0.28-6c514b2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dh-remixer-sdk",
3
- "version": "0.0.28-23f57ed",
3
+ "version": "0.0.28-6c514b2",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "templates",
@@ -1,31 +1,13 @@
1
1
  import { spawn } from "child_process";
2
2
  import { TARGET_ENVIRONMENT } from "./vars.mjs";
3
3
 
4
- const TAG_BY_ENV = {
5
- production: "latest",
6
- staging: "staging",
7
- develop: "develop",
8
- };
9
-
10
4
  export async function getSdkVersion() {
11
- const tag = TAG_BY_ENV[TARGET_ENVIRONMENT];
12
-
13
- if (!tag) {
14
- throw new Error(
15
- `[sdk-update] Unknown NEXT_PUBLIC_ENVIRONMENT "${TARGET_ENVIRONMENT}". ` +
16
- `Expected one of: ${Object.keys(TAG_BY_ENV).join(", ")}`,
17
- );
18
- }
19
-
20
5
  const res = await fetch("https://registry.npmjs.org/dh-remixer-sdk");
21
6
  const data = await res.json();
22
- const sdkVersion = data["dist-tags"]?.[tag];
23
-
24
- if (!sdkVersion) {
25
- throw new Error(
26
- `[sdk-update] No "${tag}" dist-tag published for dh-remixer-sdk on npm`,
27
- );
28
- }
7
+ const sdkVersion =
8
+ TARGET_ENVIRONMENT === "production"
9
+ ? data["dist-tags"].latest
10
+ : data["dist-tags"].dev;
29
11
 
30
12
  return sdkVersion;
31
13
  }
@@ -5,19 +5,7 @@ import { SDK_ROOT } from "./vars.mjs";
5
5
  import { jsonMerge } from "./type-utils.mjs";
6
6
 
7
7
 
8
- function assertTemplateExists(templateType) {
9
- if (templateType === "base") return;
10
- const templateRoot = path.join(SDK_ROOT, "templates", templateType);
11
- if (!fssync.existsSync(templateRoot)) {
12
- throw new Error(
13
- `[sdk-update] Template "${templateType}" not found in installed dh-remixer-sdk (${templateRoot}). ` +
14
- `Run: npm install dh-remixer-sdk@latest`,
15
- );
16
- }
17
- }
18
-
19
8
  export async function getDeletionList(templateType) {
20
- assertTemplateExists(templateType);
21
9
  const baseRoot = path.join(SDK_ROOT, "templates", "base");
22
10
  const templateRoot = path.join(SDK_ROOT, "templates", templateType);
23
11
  const templateCleanupPath = path.join(templateRoot, "cleanup.json");
@@ -35,7 +23,6 @@ export async function getDeletionList(templateType) {
35
23
  }
36
24
 
37
25
  export async function getExtractionList(templateType) {
38
- assertTemplateExists(templateType);
39
26
  const baseRoot = path.join(SDK_ROOT, "templates", "base");
40
27
  const templateRoot = path.join(SDK_ROOT, "templates", templateType);
41
28
  const templateFilemapPath = path.join(templateRoot, "filemap.json");
@@ -6,6 +6,12 @@ const CHANGEFREQ_HOME = "daily";
6
6
  const CHANGEFREQ_NORMAL = "weekly";
7
7
  const CHANGEFREQ_TEMPLATED = "weekly";
8
8
 
9
+ const ensureTrailingSlash = (p) => {
10
+ const [base, suffix] = p.split(/([?#].*)/); // keep query/hash intact
11
+ const normalized = base.endsWith("/") ? base : base + "/";
12
+ return suffix ? normalized + suffix : normalized;
13
+ };
14
+
9
15
  export function buildSitemapXml(origin, routes) {
10
16
  if (!/^https?:\/\//i.test(origin)) origin = "https://" + origin;
11
17
  const cleanOrigin = origin.replace(/\/+$/, "");
@@ -60,7 +66,7 @@ export function buildSitemapXml(origin, routes) {
60
66
  : CHANGEFREQ_NORMAL;
61
67
 
62
68
  return ` <url>
63
- <loc>${esc(abs(path))}</loc>
69
+ <loc>${esc(abs(ensureTrailingSlash(path)))}</loc>
64
70
  <lastmod>${today}</lastmod>
65
71
  <changefreq>${changefreq}</changefreq>
66
72
  <priority>${priority.toFixed(1)}</priority>
@@ -202,15 +202,6 @@ export class Prerenderer {
202
202
  this.#client = await CDP({ port: this.#cdpPort, target: pageTarget });
203
203
  await this.#client.Page.enable();
204
204
  await this.#client.Runtime.enable();
205
-
206
- // Signal to the app that we are in SSG prerender mode, BEFORE any page
207
- // scripts run. Components (e.g. ScrollScene, useScrollProgress) can read
208
- // window.__PRERENDER__ to skip WebGL/Lenis and render a static fallback,
209
- // which keeps headless Chrome from hanging on canvas rendering and
210
- // guarantees meaningful HTML for SEO.
211
- await this.#client.Page.addScriptToEvaluateOnNewDocument({
212
- source: "window.__PRERENDER__ = true;",
213
- });
214
205
  }
215
206
 
216
207
  async #launchDirect() {
@@ -1,6 +1,5 @@
1
1
  import React from "react";
2
2
  import ReactDOM from "react-dom/client";
3
- import { HelmetProvider } from "react-helmet-async";
4
3
  import tailwindConfig from "@/tailwind.config";
5
4
  import App from "@/App";
6
5
  import { GOOGLE_FONTS_URL } from "@/fonts";
@@ -28,10 +27,8 @@ if (!rootElement) {
28
27
  const root = ReactDOM.createRoot(rootElement);
29
28
  root.render(
30
29
  <React.StrictMode>
31
- <HelmetProvider>
32
- <LanguageProvider>
33
- <App />
34
- </LanguageProvider>
35
- </HelmetProvider>
30
+ <LanguageProvider>
31
+ <App />
32
+ </LanguageProvider>
36
33
  </React.StrictMode>
37
- );
34
+ );
@@ -8,7 +8,7 @@
8
8
  "start": "vite preview --host 0.0.0.0 --mode production --port ${PORT:-4173}",
9
9
  "dev": "vite --host 0.0.0.0 --port ${PORT:-4173} --mode development",
10
10
  "lint": "echo 'Linting not implemented!'",
11
- "remixer-sdk:update": "bun install dh-remixer-sdk@${REMIXER_SDK_TAG:-latest} && sdk-update"
11
+ "remixer-sdk:update": "npm cache clean --force && npm install dh-remixer-sdk@latest && sdk-update"
12
12
  },
13
13
  "dependencies": {
14
14
  "@openobserve/browser-logs": "0.3.1",
@@ -21,7 +21,7 @@
21
21
  "react": "19.2.0",
22
22
  "react-aria-components": "1.11.0",
23
23
  "react-dom": "19.2.0",
24
- "react-helmet-async": "3.0.0",
24
+ "react-helmet": "6.1.0",
25
25
  "react-router-dom": "7.9.6"
26
26
  },
27
27
  "devDependencies": {
@@ -1,10 +1,113 @@
1
- import { defineConfig, loadEnv, Plugin } from "vite";
1
+ import { defineConfig, Plugin } from "vite";
2
2
  import react from "@vitejs/plugin-react";
3
3
  import tailwindcss from "tailwindcss";
4
4
  import autoprefixer from "autoprefixer";
5
5
  import tailwindConfig from "./tailwind.config.ts";
6
6
  import path from "path";
7
7
 
8
+ const REMIXER_LOGO_SVG = `
9
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
10
+ <path d="M18.0005 12.0025C14.6877 12.0025 12.0012 14.6889 12.0012 18.0016V24.0006H24.0024V12H18.0031L18.0005 12.0025Z" fill="url(#paint0_linear_14487_36369)"/>
11
+ <path d="M12.0012 5.99904V0H0V12.0006H5.99932C9.31215 12.0006 11.9986 9.31423 11.9986 6.00155L12.0012 5.99904Z" fill="url(#paint1_linear_14487_36369)"/>
12
+ <path d="M5.99902 11.999C9.31222 11.999 11.9988 14.6851 11.999 17.998C11.999 21.3112 9.31236 23.9971 5.99902 23.9971C2.68583 23.9969 0 21.3111 0 17.998C0.00021569 14.6852 2.68596 11.9992 5.99902 11.999ZM18 0C21.3133 0 24 2.68585 24 5.99902C24 9.3122 21.3133 11.998 18 11.998C14.6869 11.9978 12.001 9.31205 12.001 5.99902C12.001 2.68601 14.6869 0.00024737 18 0Z" fill="url(#paint2_linear_14487_36369)"/>
13
+ <path d="M12.0012 6H18.0005V11.999C14.6877 11.999 12.0012 9.31016 12.0012 6Z" fill="white"/>
14
+ <path d="M5.99927 12V6.00096H11.9986C11.9986 9.31364 9.30958 12 5.99927 12Z" fill="white"/>
15
+ <path d="M12.0012 18H6.0019L6.0019 12.001C9.31473 12.001 12.0012 14.6898 12.0012 18Z" fill="white"/>
16
+ <path d="M18.0005 12V17.999H12.0012C12.0012 14.6864 14.6902 12 18.0005 12Z" fill="white"/>
17
+ <defs>
18
+ <linearGradient id="paint0_linear_14487_36369" x1="12.0024" y1="12" x2="24.0018" y2="24" gradientUnits="userSpaceOnUse">
19
+ <stop stop-color="#3F3F46"/>
20
+ <stop offset="1" stop-color="#71717A"/>
21
+ </linearGradient>
22
+ <linearGradient id="paint1_linear_14487_36369" x1="0.001139" y1="3.18903e-07" x2="12.0005" y2="12" gradientUnits="userSpaceOnUse">
23
+ <stop stop-color="#71717A"/>
24
+ <stop offset="1" stop-color="#3F3F46"/>
25
+ </linearGradient>
26
+ <linearGradient id="paint2_linear_14487_36369" x1="-8.53364" y1="33.7017" x2="-6.30119" y2="-14.057" gradientUnits="userSpaceOnUse">
27
+ <stop stop-color="#BE59FF"/>
28
+ <stop offset="0.19" stop-color="#9D60FF"/>
29
+ <stop offset="0.74" stop-color="#4274FF"/>
30
+ <stop offset="1" stop-color="#1F7CFF"/>
31
+ </linearGradient>
32
+ </defs>
33
+ </svg>`
34
+
35
+ const ARROW_SVG = `
36
+ <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" fill="none">
37
+ <path d="M11.1635 10.0004L7.60246 6.43958C7.48718 6.32417 7.42816 6.19646 7.42538 6.05646C7.42274 5.9166 7.48177 5.78625 7.60246 5.66542C7.72329 5.54472 7.85232 5.48438 7.98954 5.48438C8.12677 5.48438 8.25579 5.54472 8.37663 5.66542L12.2468 9.53563C12.3109 9.59979 12.3589 9.67167 12.391 9.75125C12.4231 9.83083 12.4391 9.91389 12.4391 10.0004C12.4391 10.0869 12.4231 10.17 12.391 10.2496C12.3589 10.3292 12.3109 10.401 12.2468 10.4652L8.37663 14.3354C8.26121 14.4507 8.13697 14.5063 8.00392 14.5021C7.871 14.4978 7.74413 14.4353 7.62329 14.3146C7.5026 14.1938 7.44225 14.0647 7.44225 13.9275C7.44225 13.7903 7.5026 13.6613 7.62329 13.5404L11.1635 10.0004Z" fill="#A18AFB" fill-opacity="0.7"/>
38
+ </svg>`
39
+
40
+ const BUILT_WITH_REMIXER_TEXT = (classes?: string) => `
41
+ <div class="flex gap-[12px] items-center">
42
+ ${REMIXER_LOGO_SVG}
43
+ <p class="${classes} text-[#FFF] text-[14px] font-[400]">Built with <span class="font-[600]">Remixer</span></p>
44
+ </div>`
45
+
46
+ const CTA_LINK = (title: string, href: string, isShowArrow: boolean = false) => `
47
+ <a href="${href}" target="_blank" class="group text-[14px] text-[#B6A3FE] font-[600] flex gap-[6px] items-center cursor-pointer relative">
48
+ ${title}
49
+ ${isShowArrow ? ARROW_SVG : ''}
50
+ <div class="bg-[#B6A3FE] absolute left-0 bottom-0 h-[1px] right-[100%] transition-all duration-150 ${isShowArrow ? 'group-hover:right-[4px]' : 'group-hover:right-[0px]'}"></div>
51
+ </a>`
52
+
53
+ const BADGE_CONTAINER = (cta_links?: string) => `
54
+ <div class="fixed bottom-[0px] right-[0px] z-[2147483647] flex p-[8px] gap-[16px] mx-[16px] mb-[16px] bg-[#09090B] border-[#3F3F46] border-[1px] border-solid rounded-[12px] items-center shadow-[0_2px_32px_0_rgba(0,0,0,0.25)]">
55
+ <div class="flex gap-[12px] items-center">
56
+ ${cta_links ?
57
+ [
58
+ BUILT_WITH_REMIXER_TEXT('hidden md:block'),
59
+ '<div class="h-[20px] w-[1px] bg-[#3F3F46]"></div>',
60
+ cta_links
61
+ ].join('\n') :
62
+ BUILT_WITH_REMIXER_TEXT()
63
+ }
64
+ </div>
65
+ </div>`
66
+
67
+ const PREVIEW_DOMAINS = [
68
+ '.remixer.ai',
69
+ '.dreamhosters.ai',
70
+ ];
71
+
72
+ function injectRemixerBadgePlugin(): Plugin {
73
+ return {
74
+ name: "vite-plugin-inject-remixer-badge",
75
+ apply: "build",
76
+
77
+ transformIndexHtml(html) {
78
+ try {
79
+ const IS_SHOW_REMIXER_BADGE: boolean = process.env.IS_SHOW_REMIXER_BADGE as boolean | undefined || false;
80
+ const REMIXER_BADGE_TYPE: string = process.env.REMIXER_BADGE_TYPE || 'DEFAULT';
81
+
82
+ const domain = process.env.NEXT_PUBLIC_DOMAIN || '';
83
+ const isPreviewService = PREVIEW_DOMAINS.some(pd => domain.endsWith(pd));
84
+
85
+ if (!IS_SHOW_REMIXER_BADGE && !isPreviewService) return html
86
+
87
+ const DICTIONARY: Record<string, string> = {
88
+ DEFAULT: BADGE_CONTAINER(),
89
+ UPGRADE_PLAN: BADGE_CONTAINER([
90
+ CTA_LINK(`Upgrade Plan`, 'https://www.dreamhost.com/remixer-website-builder/', true)
91
+
92
+ ].join('\n')),
93
+ NAVBAR: BADGE_CONTAINER([
94
+ CTA_LINK(`Upgrade plan`, 'https://www.dreamhost.com/remixer-website-builder/'),
95
+ CTA_LINK(`Get Access`, 'https://www.dreamhost.com/remixer-website-builder/'),
96
+ CTA_LINK(`Signup`, 'https://www.dreamhost.com/remixer-website-builder/')
97
+ ].join('\n')),
98
+ }
99
+
100
+ const BADGE_CONTENT = DICTIONARY[REMIXER_BADGE_TYPE]
101
+
102
+ return html.replace(/<\/body>/, `${BADGE_CONTENT}\n</body>`);
103
+ } catch (e) {
104
+ console.warn('Remixer badge failed to inject', e);
105
+ return html;
106
+ }
107
+ },
108
+ };
109
+ }
110
+
8
111
  // Switches from Tailwind CDN to regular Tailwind CSS with PostCSS for production builds
9
112
  function tailwindProdPlugin(): Plugin {
10
113
  return {
@@ -34,7 +137,7 @@ function tailwindProdPlugin(): Plugin {
34
137
 
35
138
  transformIndexHtml(html) {
36
139
  return html.replace(
37
- /\s*<script\s+src=["']https:\/\/cdn\.tailwindcss\.com["']\s*><\/script>\s*/g,
140
+ /\s*<script\s+src=["']https:\/\/cdn\.tailwindcss\.com[^"']*["']\s*><\/script>\s*/g,
38
141
  "\n"
39
142
  );
40
143
  },
@@ -56,16 +159,10 @@ const VIRTUAL_OO_ID = "virtual:openobserve";
56
159
  const RESOLVED_OO_ID = "\0" + VIRTUAL_OO_ID;
57
160
 
58
161
  function openobservePlugin(): Plugin {
59
- let env: Record<string, string> = {};
60
-
61
162
  return {
62
163
  name: "vite-plugin-openobserve",
63
164
  apply: "build",
64
165
 
65
- config(_, { mode }) {
66
- env = loadEnv(mode, process.cwd(), "VITE_OO_");
67
- },
68
-
69
166
  resolveId(id) {
70
167
  if (id === VIRTUAL_OO_ID) return RESOLVED_OO_ID;
71
168
  },
@@ -73,47 +170,55 @@ function openobservePlugin(): Plugin {
73
170
  load(id) {
74
171
  if (id !== RESOLVED_OO_ID) return;
75
172
 
76
- const token = env.VITE_OO_CLIENT_TOKEN;
173
+ const token = process.env.VITE_OO_CLIENT_TOKEN;
77
174
  if (!token) return "export default false;";
78
175
 
79
- const site = env.VITE_OO_SITE || "api.openobserve.ai";
80
- const org = env.VITE_OO_ORG || "";
81
- const appId = env.VITE_OO_APP_ID || "";
82
- const service = env.VITE_OO_SERVICE || "";
83
- const version = env.VITE_OO_VERSION || "0.0.1";
176
+ const domain = process.env.NEXT_PUBLIC_DOMAIN || "";
177
+ if (PREVIEW_DOMAINS.some(pd => domain.endsWith(pd))) return "export default false;";
178
+
179
+ const site = process.env.VITE_OO_SITE || "api.openobserve.ai";
180
+ const org = process.env.VITE_OO_ORG || "";
181
+ const appId = process.env.VITE_OO_APP_ID || "";
182
+ const service = domain;
183
+ const version = process.env.VITE_OO_VERSION || "0.0.0";
184
+ const env = process.env.NEXT_PUBLIC_ENVIRONMENT || "production";
84
185
 
85
186
  return `
86
187
  import { openobserveRum } from "@openobserve/browser-rum-slim";
87
188
  import { openobserveLogs } from "@openobserve/browser-logs";
88
189
 
89
- openobserveRum.init({
90
- applicationId: ${JSON.stringify(appId)},
91
- clientToken: ${JSON.stringify(token)},
92
- site: ${JSON.stringify(site)},
93
- organizationIdentifier: ${JSON.stringify(org)},
94
- service: ${JSON.stringify(service)},
95
- env: "production",
96
- version: ${JSON.stringify(version)},
97
- trackResources: true,
98
- trackLongTasks: true,
99
- trackUserInteractions: true,
100
- insecureHTTP: false,
101
- apiVersion: "v1",
102
- defaultPrivacyLevel: "allow",
103
- sessionSampleRate: 100,
104
- });
105
-
106
- openobserveLogs.init({
107
- clientToken: ${JSON.stringify(token)},
108
- site: ${JSON.stringify(site)},
109
- organizationIdentifier: ${JSON.stringify(org)},
110
- service: ${JSON.stringify(service)},
111
- env: "production",
112
- version: ${JSON.stringify(version)},
113
- forwardErrorsToLogs: true,
114
- insecureHTTP: false,
115
- apiVersion: "v1",
116
- });
190
+ try {
191
+ openobserveRum.init({
192
+ applicationId: ${JSON.stringify(appId)},
193
+ clientToken: ${JSON.stringify(token)},
194
+ site: ${JSON.stringify(site)},
195
+ organizationIdentifier: ${JSON.stringify(org)},
196
+ service: ${JSON.stringify(service)},
197
+ env: ${JSON.stringify(env)},
198
+ version: ${JSON.stringify(version)},
199
+ trackResources: true,
200
+ trackLongTasks: true,
201
+ trackUserInteractions: true,
202
+ insecureHTTP: false,
203
+ apiVersion: "v1",
204
+ defaultPrivacyLevel: "allow",
205
+ sessionSampleRate: 100,
206
+ });
207
+
208
+ openobserveLogs.init({
209
+ clientToken: ${JSON.stringify(token)},
210
+ site: ${JSON.stringify(site)},
211
+ organizationIdentifier: ${JSON.stringify(org)},
212
+ service: ${JSON.stringify(service)},
213
+ env: ${JSON.stringify(env)},
214
+ version: ${JSON.stringify(version)},
215
+ forwardErrorsToLogs: true,
216
+ insecureHTTP: false,
217
+ apiVersion: "v1",
218
+ });
219
+ } catch (e) {
220
+ console.warn('RemixerObserve failed to initialize', e);
221
+ }
117
222
 
118
223
  export default true;
119
224
  `;
@@ -129,6 +234,7 @@ export default true;
129
234
 
130
235
  export default defineConfig({
131
236
  plugins: [
237
+ injectRemixerBadgePlugin(),
132
238
  openobservePlugin(),
133
239
  tailwindProdPlugin(),
134
240
  react(),
@@ -3,4 +3,4 @@
3
3
  "remixerMetadata": {
4
4
  "template": "landing-page"
5
5
  }
6
- }
6
+ }
@@ -1,43 +0,0 @@
1
- import { Helmet } from "react-helmet-async";
2
- import { useLanguage } from "@/context/LanguageContext";
3
- import images from "@/assets/images.json";
4
-
5
- interface SEOHeadProps {
6
- titleKey?: string;
7
- descriptionKey?: string;
8
- ogImage?: string;
9
- ogImageKey?: string;
10
- }
11
-
12
- // Canonical <head> for every page. Render exactly one <SEOHead /> per page
13
- // inside pages/*.tsx; no raw <Helmet> anywhere else. Pulls og:image from
14
- // assets/images.json by default so social sharing works without extra wiring.
15
- export function SEOHead({
16
- titleKey = "home.title",
17
- descriptionKey = "home.description",
18
- ogImage,
19
- ogImageKey = "og_image",
20
- }: SEOHeadProps) {
21
- const { t } = useLanguage();
22
- const siteTitle = import.meta.env.VITE_METADATA_TITLE as string | undefined;
23
- const translated = t(titleKey);
24
- const title = siteTitle ? `${translated} | ${siteTitle}` : translated;
25
- const description = t(descriptionKey);
26
- const resolvedOg =
27
- ogImage ?? (images as Record<string, string>)[ogImageKey];
28
-
29
- return (
30
- <Helmet>
31
- <title>{title}</title>
32
- <meta name="description" content={description} />
33
- <meta property="og:title" content={title} />
34
- <meta property="og:description" content={description} />
35
- <meta property="og:type" content="website" />
36
- {resolvedOg ? <meta property="og:image" content={resolvedOg} /> : null}
37
- <meta name="twitter:card" content="summary_large_image" />
38
- {resolvedOg ? <meta name="twitter:image" content={resolvedOg} /> : null}
39
- </Helmet>
40
- );
41
- }
42
-
43
- export default SEOHead;
@@ -1,62 +0,0 @@
1
- import {
2
- useContext,
3
- useEffect,
4
- useId,
5
- useRef,
6
- type CSSProperties,
7
- type ReactNode,
8
- } from 'react';
9
- import { StageContext, type AnchorRegistration } from './StageContext';
10
-
11
- interface Anchor3DProps {
12
- // Scene factory — invoked inside <Stage3D>'s Canvas. Read the live scroll
13
- // signal via useAnchor().
14
- render: () => ReactNode;
15
- // When to keep the scene subtree mounted. Default: w > 0.02.
16
- keepMountedWhen?: (w: number) => boolean;
17
- // DOM wrapped by the anchor. The scroll signal is derived from this
18
- // wrapper's bounding rect.
19
- children?: ReactNode;
20
- className?: string;
21
- style?: CSSProperties;
22
- }
23
-
24
- // Binds a scroll-driven scene to a DOM region and registers it with the
25
- // parent <Stage3D>, which hoists the scene into its Canvas.
26
- export function Anchor3D({
27
- render,
28
- keepMountedWhen,
29
- children,
30
- className,
31
- style,
32
- }: Anchor3DProps) {
33
- const id = useId();
34
- const elementRef = useRef<HTMLDivElement | null>(null);
35
- const stage = useContext(StageContext);
36
-
37
- // Stash render/keepMountedWhen in refs so re-registration only fires on
38
- // structural changes (id), not every parent re-render.
39
- const renderRef = useRef(render);
40
- renderRef.current = render;
41
- const keepRef = useRef(keepMountedWhen);
42
- keepRef.current = keepMountedWhen;
43
-
44
- useEffect(() => {
45
- if (!stage) return;
46
- const reg: AnchorRegistration = {
47
- id,
48
- getElement: () => elementRef.current,
49
- render: () => renderRef.current(),
50
- keepMountedWhen: keepRef.current
51
- ? (w: number) => (keepRef.current as (w: number) => boolean)(w)
52
- : undefined,
53
- };
54
- return stage.registerAnchor(reg);
55
- }, [id, stage]);
56
-
57
- return (
58
- <div ref={elementRef} className={className} style={style}>
59
- {children}
60
- </div>
61
- );
62
- }
@@ -1,134 +0,0 @@
1
- import { useMemo, useRef } from 'react';
2
- import { useFrame } from '@react-three/fiber';
3
- import * as THREE from 'three';
4
- import type { StagePalette } from './StageContext';
5
-
6
- function triLerp(
7
- out: THREE.Color,
8
- a: THREE.Color,
9
- b: THREE.Color,
10
- c: THREE.Color,
11
- p: number,
12
- ): void {
13
- if (p < 0.5) out.copy(a).lerp(b, p * 2);
14
- else out.copy(b).lerp(c, (p - 0.5) * 2);
15
- }
16
-
17
- function getPageProgress(): number {
18
- if (typeof window === 'undefined') return 0;
19
- const max = document.documentElement.scrollHeight - window.innerHeight || 1;
20
- return Math.max(0, Math.min(1, window.scrollY / max));
21
- }
22
-
23
- // Back-faced gradient sphere whose two stop colors lerp across page progress.
24
- // Gives every immersive page a mood that evolves with scroll — for free, no
25
- // per-site shader authoring.
26
- export function Atmosphere({ palette }: { palette: StagePalette }) {
27
- const inner = useMemo(
28
- () => palette.sky.map((c) => new THREE.Color(c)),
29
- [palette.sky],
30
- );
31
- const outer = useMemo(
32
- () => palette.ground.map((c) => new THREE.Color(c)),
33
- [palette.ground],
34
- );
35
-
36
- const uniforms = useRef({
37
- uInner: { value: inner[0].clone() },
38
- uOuter: { value: outer[0].clone() },
39
- });
40
- const innerNow = useRef(inner[0].clone());
41
- const outerNow = useRef(outer[0].clone());
42
- const ti = useMemo(() => new THREE.Color(), []);
43
- const to = useMemo(() => new THREE.Color(), []);
44
-
45
- useFrame((_, dt) => {
46
- const p = getPageProgress();
47
- const k = Math.min(dt * 2, 1);
48
- triLerp(ti, inner[0], inner[1], inner[2], p);
49
- triLerp(to, outer[0], outer[1], outer[2], p);
50
- innerNow.current.lerp(ti, k);
51
- outerNow.current.lerp(to, k);
52
- uniforms.current.uInner.value.copy(innerNow.current);
53
- uniforms.current.uOuter.value.copy(outerNow.current);
54
- });
55
-
56
- return (
57
- <mesh scale={[50, 50, 50]}>
58
- <sphereGeometry args={[1, 32, 32]} />
59
- <shaderMaterial
60
- side={THREE.BackSide}
61
- uniforms={uniforms.current}
62
- vertexShader={`
63
- varying vec3 vPos;
64
- void main() {
65
- vPos = position;
66
- gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
67
- }
68
- `}
69
- fragmentShader={`
70
- varying vec3 vPos;
71
- uniform vec3 uInner;
72
- uniform vec3 uOuter;
73
- void main() {
74
- float t = smoothstep(-0.9, 0.7, normalize(vPos).y);
75
- vec3 c = mix(uOuter, uInner, t);
76
- gl_FragColor = vec4(c, 1.0);
77
- }
78
- `}
79
- />
80
- </mesh>
81
- );
82
- }
83
-
84
- // Three-point rig whose key + rim colors lerp with page progress. Fill light
85
- // stays neutral. Shadow-casting key light is on; Stage3D decides whether the
86
- // Canvas has `shadows` enabled via a prop.
87
- export function SceneLighting({ palette }: { palette: StagePalette }) {
88
- const keyLight = useRef<THREE.DirectionalLight>(null);
89
- const rimLight = useRef<THREE.PointLight>(null);
90
-
91
- const keyColors = useMemo(
92
- () => palette.key.map((c) => new THREE.Color(c)),
93
- [palette.key],
94
- );
95
- const rimColors = useMemo(
96
- () => palette.rim.map((c) => new THREE.Color(c)),
97
- [palette.rim],
98
- );
99
-
100
- const keyNow = useRef(keyColors[0].clone());
101
- const rimNow = useRef(rimColors[0].clone());
102
- const tK = useMemo(() => new THREE.Color(), []);
103
- const tR = useMemo(() => new THREE.Color(), []);
104
-
105
- useFrame((_, dt) => {
106
- const p = getPageProgress();
107
- const k = Math.min(dt * 2.2, 1);
108
- triLerp(tK, keyColors[0], keyColors[1], keyColors[2], p);
109
- triLerp(tR, rimColors[0], rimColors[1], rimColors[2], p);
110
- keyNow.current.lerp(tK, k);
111
- rimNow.current.lerp(tR, k);
112
- if (keyLight.current) keyLight.current.color.copy(keyNow.current);
113
- if (rimLight.current) rimLight.current.color.copy(rimNow.current);
114
- });
115
-
116
- return (
117
- <>
118
- <ambientLight intensity={0.35} />
119
- <directionalLight
120
- ref={keyLight}
121
- position={[3.5, 5, 3]}
122
- intensity={1.2}
123
- castShadow
124
- />
125
- <pointLight
126
- ref={rimLight}
127
- position={[-3, 1.5, -2.5]}
128
- intensity={1.8}
129
- distance={12}
130
- />
131
- <pointLight position={[2, -1.5, 2.5]} intensity={0.6} distance={10} />
132
- </>
133
- );
134
- }