@revyme/runtime 0.0.7 → 0.0.9

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/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { default as withResponsiveProps } from './withResponsiveProps';
2
2
  export { withCursor, CursorPortal, type CursorMode, type CursorSide, type CursorAlign, type CursorTransition, type CursorOpts, } from './cursor-runtime';
3
3
  export { useStaticCanvas } from './useStaticCanvas';
4
+ export { RevymeSplitText, type SplitTextSpec, type SplitTextScope, type RevymeSplitTextProps, } from './split-text';
4
5
  export { playSketchDraw, type SketchAnimOpts, type SketchAnimMode, type SketchAnimTrigger, type SketchAnimTransition, } from './sketch-draw';
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use client";
2
+ import * as React from "react";
2
3
  import { forwardRef, useEffect, useRef, useState, useSyncExternalStore } from "react";
3
- import { AnimatePresence, isMotionValue, motion, useMotionValue, useSpring } from "framer-motion";
4
+ import { AnimatePresence, isMotionValue, motion, useInView, useMotionValue, useScroll, useSpring, useTransform } from "framer-motion";
4
5
  import { jsx } from "react/jsx-runtime";
5
6
  import { getStroke } from "perfect-freehand";
6
7
  //#region src/withResponsiveProps.tsx
@@ -136,6 +137,7 @@ function withResponsiveProps(Component) {
136
137
  else innerStyle[k] = v;
137
138
  if ("width" in wrapperStyle) innerStyle.width = "100%";
138
139
  if ("height" in wrapperStyle) innerStyle.height = "100%";
140
+ innerStyle.position = "relative";
139
141
  const { style: _split, ...rest } = mergedProps;
140
142
  delete rest.ref;
141
143
  return /* @__PURE__ */ jsx(motion.div, {
@@ -349,6 +351,346 @@ function useStaticCanvas() {
349
351
  return false;
350
352
  }
351
353
  //#endregion
354
+ //#region src/split-text.tsx
355
+ var WRAP_PLAIN = { whiteSpace: "nowrap" };
356
+ /** paddingBottom/marginBottom cancel out — zero layout cost. The padding keeps descenders
357
+ * (g, y, p) from being shaved by the clip AND leaves the sliver IntersectionObserver needs
358
+ * when a unit is offset a full 100% (otherwise it sits entirely outside the clip). */
359
+ var WRAP_MASK = {
360
+ whiteSpace: "nowrap",
361
+ display: "inline-block",
362
+ overflow: "hidden",
363
+ paddingBottom: "0.14em",
364
+ marginBottom: "-0.14em"
365
+ };
366
+ /** The editor persists a custom cubic-bezier as the STRING "[0.22, 1, 0.36, 1]" (that's what
367
+ * the TransitionPanel curve editor writes). framer accepts a named easing or a real array —
368
+ * handed the string it throws `Invalid easing type` and unmounts the tree. Codegen normalises
369
+ * this too; the runtime keeps it so hand-written source still works. */
370
+ function normalizeEase(e) {
371
+ if (e === void 0 || Array.isArray(e)) return e;
372
+ const s = String(e).trim();
373
+ if (!s.startsWith("[")) return s;
374
+ const n = s.replace(/[[\]]/g, "").split(",").map((v) => parseFloat(v.trim()));
375
+ return n.length === 4 && n.every(Number.isFinite) ? n : void 0;
376
+ }
377
+ /** Collapse React children to a plain string, or null when they can't be split.
378
+ *
379
+ * `null` (a real element child — a styled `<span>` mark, an icon) means "render verbatim,
380
+ * unsplit" rather than mangling rich content. Everything the generator used to normalise at
381
+ * build time — `{item.title}`, `{t('key')}`, `{"a\nb"}`, `a<br/>b` — arrives here already
382
+ * resolved to a string or a `<br />`, so one function covers all of it. */
383
+ function flattenToText(node) {
384
+ if (node === null || node === void 0 || node === false || node === true) return "";
385
+ if (typeof node === "string") return node;
386
+ if (typeof node === "number") return String(node);
387
+ if (Array.isArray(node)) {
388
+ let out = "";
389
+ for (const child of node) {
390
+ const part = flattenToText(child);
391
+ if (part === null) return null;
392
+ out += part;
393
+ }
394
+ return out;
395
+ }
396
+ if (React.isValidElement(node)) {
397
+ const type = node.type;
398
+ if (type === "br") return "\n";
399
+ if (type === React.Fragment) return flattenToText(node.props?.children);
400
+ return null;
401
+ }
402
+ return null;
403
+ }
404
+ /** Active `responsive` entry index, or -1 for the base spec.
405
+ *
406
+ * The `matchMedia` read is a LAZY useState initialiser, not a post-mount effect: framer
407
+ * captures `initial` once at mount, so starting at `false` and correcting later makes the
408
+ * responsive branch permanently lose to the base. Same shape as the builder's generated
409
+ * `useMediaQuery` (canvas-poc/src/code/generation/scoped-expr.ts). */
410
+ function useActiveScopeIndex(spec, variant) {
411
+ const entries = spec.responsive;
412
+ const compute = React.useCallback(() => {
413
+ if (!entries || entries.length === 0) return -1;
414
+ for (let i = 0; i < entries.length; i++) {
415
+ const scope = entries[i].scope;
416
+ if ("variant" in scope) {
417
+ if (variant !== void 0 && scope.variant === variant) return i;
418
+ } else if (typeof window !== "undefined" && typeof window.matchMedia === "function") {
419
+ if (window.matchMedia(scope.query).matches) return i;
420
+ }
421
+ }
422
+ return -1;
423
+ }, [entries, variant]);
424
+ const [idx, setIdx] = React.useState(compute);
425
+ React.useEffect(() => {
426
+ setIdx(compute());
427
+ if (!entries || typeof window === "undefined" || typeof window.matchMedia !== "function") return;
428
+ const lists = entries.map((e) => "query" in e.scope ? window.matchMedia(e.scope.query) : null).filter(Boolean);
429
+ if (lists.length === 0) return;
430
+ const onChange = () => setIdx(compute());
431
+ for (const l of lists) l.addEventListener("change", onChange);
432
+ return () => {
433
+ for (const l of lists) l.removeEventListener("change", onChange);
434
+ };
435
+ }, [entries, compute]);
436
+ return idx;
437
+ }
438
+ var RESTING = {
439
+ opacity: 1,
440
+ scale: 1,
441
+ rotateX: 0,
442
+ rotateY: 0,
443
+ rotateZ: 0,
444
+ skewX: 0,
445
+ skewY: 0,
446
+ x: 0,
447
+ y: 0
448
+ };
449
+ var CHANNELS = [
450
+ "opacity",
451
+ "scale",
452
+ "rotateX",
453
+ "rotateY",
454
+ "rotateZ",
455
+ "skewX",
456
+ "skewY",
457
+ "x",
458
+ "y"
459
+ ];
460
+ /** The animated-from state. Mirrors the builder's `buildHiddenState`: a channel is animated
461
+ * only when the spec sets it to something other than its resting value. */
462
+ function hiddenState(s) {
463
+ const out = {};
464
+ for (const k of CHANNELS) {
465
+ const v = s[k];
466
+ if (v !== void 0 && v !== RESTING[k]) out[k] = v;
467
+ }
468
+ if (s.blur !== void 0 && s.blur !== 0) out.filter = `blur(${s.blur}px)`;
469
+ return out;
470
+ }
471
+ function visibleState(s) {
472
+ const out = {};
473
+ for (const k of CHANNELS) {
474
+ const v = s[k];
475
+ if (v !== void 0 && v !== RESTING[k]) out[k] = RESTING[k];
476
+ }
477
+ if (s.blur !== void 0 && s.blur !== 0) out.filter = "blur(0px)";
478
+ return out;
479
+ }
480
+ /** `'100%'` → `'0%'`, `24` → `0`. Keeps the unit so a percentage offset scrubs correctly. */
481
+ function restingOf(from, key) {
482
+ if (typeof from === "number") return RESTING[key] ?? 0;
483
+ const m = String(from).match(/^(-?[\d.]+)(.*)$/);
484
+ return m ? `${RESTING[key] ?? 0}${m[2]}` : RESTING[key] ?? 0;
485
+ }
486
+ /** Split `text` into render nodes. Structure mirrors the old codegen splitter exactly, so the
487
+ * emitted DOM is unchanged from the build-time era. Keys are pure functions of index → SSR
488
+ * and CSR agree. */
489
+ function buildNodes(text, animationType, mask) {
490
+ const nodes = [];
491
+ let i = 0;
492
+ const lines = text.split("\n");
493
+ if (animationType === "line") {
494
+ for (let li = 0; li < lines.length; li++) {
495
+ if (li > 0) nodes.push({
496
+ t: "br",
497
+ k: `br${li}`
498
+ });
499
+ nodes.push({
500
+ t: "unit",
501
+ u: {
502
+ key: `u${i}`,
503
+ inner: lines[li],
504
+ display: "block",
505
+ index: i
506
+ }
507
+ });
508
+ i++;
509
+ }
510
+ return {
511
+ nodes,
512
+ count: i
513
+ };
514
+ }
515
+ if (animationType === "full") {
516
+ nodes.push({
517
+ t: "unit",
518
+ u: {
519
+ key: "u0",
520
+ inner: text,
521
+ display: "inline-block",
522
+ index: 0
523
+ }
524
+ });
525
+ return {
526
+ nodes,
527
+ count: 1
528
+ };
529
+ }
530
+ for (let li = 0; li < lines.length; li++) {
531
+ if (li > 0) nodes.push({
532
+ t: "br",
533
+ k: `br${li}`
534
+ });
535
+ const words = lines[li].split(" ");
536
+ for (let wi = 0; wi < words.length; wi++) {
537
+ if (wi > 0) nodes.push({
538
+ t: "text",
539
+ k: `sp${li}-${wi}`,
540
+ v: " "
541
+ });
542
+ const word = words[wi];
543
+ if (!word) continue;
544
+ if (animationType === "word") {
545
+ const u = {
546
+ t: "unit",
547
+ u: {
548
+ key: `u${i}`,
549
+ inner: word,
550
+ display: "inline-block",
551
+ index: i
552
+ }
553
+ };
554
+ i++;
555
+ nodes.push(mask ? {
556
+ t: "wrap",
557
+ k: `w${li}-${wi}`,
558
+ kids: [u]
559
+ } : u);
560
+ } else {
561
+ const kids = [];
562
+ for (const ch of word) {
563
+ kids.push({
564
+ t: "unit",
565
+ u: {
566
+ key: `u${i}`,
567
+ inner: ch,
568
+ display: "inline-block",
569
+ index: i
570
+ }
571
+ });
572
+ i++;
573
+ }
574
+ nodes.push({
575
+ t: "wrap",
576
+ k: `w${li}-${wi}`,
577
+ kids
578
+ });
579
+ }
580
+ }
581
+ }
582
+ return {
583
+ nodes,
584
+ count: i
585
+ };
586
+ }
587
+ /** One scroll-scrubbed unit. Split into its own component because `useTransform` must be
588
+ * called once per animated channel and that count is data-driven — calling them in a loop
589
+ * inside the parent would violate the rules of hooks. The parent keys each instance by a
590
+ * channel fingerprint, so a spec change REMOUNTS rather than reordering hooks. */
591
+ function ScrollUnit({ progress, range, channels, display, children }) {
592
+ const style = { display };
593
+ for (const c of channels) style[c.key] = useTransform(progress, range, [c.from, c.to]);
594
+ return /* @__PURE__ */ jsx(motion.span, {
595
+ style,
596
+ children
597
+ });
598
+ }
599
+ function RevymeSplitText({ spec, variant, children }) {
600
+ const base = spec ?? {};
601
+ const hostRef = React.useRef(null);
602
+ const scopeIdx = useActiveScopeIndex(base, variant);
603
+ const resolved = React.useMemo(() => {
604
+ return {
605
+ ...scopeIdx >= 0 && base.responsive ? {
606
+ ...base,
607
+ ...base.responsive[scopeIdx].config
608
+ } : base,
609
+ animationType: base.animationType,
610
+ mask: base.mask,
611
+ responsive: base.responsive
612
+ };
613
+ }, [base, scopeIdx]);
614
+ const animationType = base.animationType ?? "character";
615
+ const mask = !!base.mask;
616
+ const text = flattenToText(children);
617
+ const inView = useInView(hostRef, {
618
+ once: true,
619
+ amount: 0
620
+ });
621
+ const startFrac = Math.min(1, Math.max(0, (resolved.scrollStart ?? 90) / 100));
622
+ const endFrac = Math.min(1, Math.max(0, (resolved.scrollEnd ?? 35) / 100));
623
+ const { scrollYProgress } = useScroll({
624
+ target: hostRef,
625
+ offset: [`start ${startFrac}`, `start ${endFrac}`]
626
+ });
627
+ const { nodes, count } = React.useMemo(() => buildNodes(text ?? "", animationType, mask), [
628
+ text,
629
+ animationType,
630
+ mask
631
+ ]);
632
+ if (text === null) return /* @__PURE__ */ jsx("span", {
633
+ ref: hostRef,
634
+ children
635
+ });
636
+ const isScroll = resolved.trigger === "scroll";
637
+ const hidden = hiddenState(resolved);
638
+ const visible = visibleState(resolved);
639
+ const stagger = resolved.delay ?? .05;
640
+ const initialDelay = resolved.transition?.delay ?? 0;
641
+ const tr = resolved.transition ? {
642
+ ...resolved.transition,
643
+ ease: normalizeEase(resolved.transition.ease),
644
+ delay: void 0
645
+ } : {
646
+ type: "spring",
647
+ stiffness: 300,
648
+ damping: 30
649
+ };
650
+ const channels = isScroll ? Object.entries(hidden).map(([key, from]) => ({
651
+ key,
652
+ from,
653
+ to: key === "filter" ? "blur(0px)" : restingOf(from, key)
654
+ })) : [];
655
+ const fingerprint = channels.map((c) => c.key).join("|");
656
+ const renderUnit = (u) => {
657
+ if (isScroll) {
658
+ const start = count > 1 ? Math.round(u.index / (count - 1) * .6 * 1e3) / 1e3 : 0;
659
+ return /* @__PURE__ */ jsx(ScrollUnit, {
660
+ progress: scrollYProgress,
661
+ range: [start, Math.min(1, Math.round((start + .4) * 1e3) / 1e3)],
662
+ channels,
663
+ display: u.display,
664
+ children: u.inner
665
+ }, `${fingerprint}#${u.key}`);
666
+ }
667
+ return /* @__PURE__ */ jsx(motion.span, {
668
+ style: { display: u.display },
669
+ initial: hidden,
670
+ animate: inView ? visible : hidden,
671
+ transition: {
672
+ ...tr,
673
+ delay: Math.round((initialDelay + u.index * stagger) * 1e3) / 1e3
674
+ },
675
+ children: u.inner
676
+ }, u.key);
677
+ };
678
+ const render = (n) => {
679
+ if (n.t === "br") return /* @__PURE__ */ jsx("br", {}, n.k);
680
+ if (n.t === "text") return n.v;
681
+ if (n.t === "wrap") return /* @__PURE__ */ jsx("span", {
682
+ style: mask ? WRAP_MASK : WRAP_PLAIN,
683
+ children: n.kids.map(render)
684
+ }, n.k);
685
+ return renderUnit(n.u);
686
+ };
687
+ return /* @__PURE__ */ jsx("span", {
688
+ ref: hostRef,
689
+ style: { display: animationType === "line" ? "block" : "inline" },
690
+ children: nodes.map(render)
691
+ });
692
+ }
693
+ //#endregion
352
694
  //#region src/sketch-draw.ts
353
695
  var DEFAULT_OPTS = {
354
696
  trigger: "inView",
@@ -509,6 +851,6 @@ function playSketchDraw(wrapperEl, userOpts = {}) {
509
851
  };
510
852
  }
511
853
  //#endregion
512
- export { CursorPortal, playSketchDraw, useStaticCanvas, withCursor, withResponsiveProps };
854
+ export { CursorPortal, RevymeSplitText, playSketchDraw, useStaticCanvas, withCursor, withResponsiveProps };
513
855
 
514
856
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/withResponsiveProps.tsx","../src/cursor-runtime.tsx","../src/useStaticCanvas.ts","../src/sketch-draw.ts"],"sourcesContent":["'use client';\n\nimport { useState, useEffect, forwardRef, type ComponentType } from 'react';\nimport { motion, isMotionValue } from 'framer-motion';\n\n/**\n * HOC that reads a `data-responsive` JSON prop and merges per-viewport overrides.\n * Usage: `export default withResponsiveProps(MyComponent)`\n *\n * On the canvas, CodeComponentHost injects `__canvasViewportWidth` to simulate viewport size.\n * In production, uses `window.innerWidth`.\n *\n * data-responsive='{\"768\":{\"fontSize\":32},\"375\":{\"fontSize\":24}}'\n * Breakpoints are max-width: if viewport <= 768, the 768 overrides apply.\n *\n * ANIMATED-STYLE SOCKET (Framer parity): the editor expresses instance\n * animation effects (Appear, scroll scrubs, …) as framer MotionValues bound\n * into the instance's `style` prop — `style={{ opacity: <mv>, y: <mv> }}`.\n * Design components consume them natively (their roots are motion.* and\n * spread `...style`), but a CODE component's root is a plain element: a\n * MotionValue arrives as an un-serialisable object (the style is dropped)\n * and motion-only keys like `y` aren't CSS at all — the effect silently\n * dies at the component boundary (live find 2026-07-14: Appear on a\n * Marquee). When animated values or motion-only keys are present, the HOC\n * renders a motion.div WRAPPER that carries them (plus the placement props\n * that describe the instance's slot in its parent), and hands the wrapped\n * component a clean static style. Framer does exactly this — the platform\n * owns an animatable container around every code component, so component\n * authors never deal with animation plumbing. No animated values → no\n * wrapper → byte-identical behaviour to before.\n */\n\n/** Style keys only a motion.* element understands (translated into\n * `transform`) — a plain DOM element ignores them entirely. */\nconst MOTION_ONLY_KEYS = new Set([\n 'x', 'y', 'z',\n 'rotate', 'rotateX', 'rotateY', 'rotateZ',\n 'scale', 'scaleX', 'scaleY',\n 'skew', 'skewX', 'skewY',\n 'originX', 'originY', 'originZ',\n 'transformPerspective',\n]);\n\n/** Placement props describing the instance's slot in ITS PARENT's layout —\n * these must ride on whichever element is outermost (the wrapper, when one\n * exists), mirroring the design-instance wrapper/root split. */\nconst PLACEMENT_KEYS = new Set([\n 'position', 'left', 'top', 'right', 'bottom', 'inset',\n 'width', 'height', 'minWidth', 'minHeight', 'maxWidth', 'maxHeight',\n 'flex', 'flexGrow', 'flexShrink', 'flexBasis',\n 'order', 'alignSelf', 'justifySelf', 'zIndex',\n 'margin', 'marginTop', 'marginRight', 'marginBottom', 'marginLeft',\n 'gridColumn', 'gridRow', 'gridArea',\n]);\nexport default function withResponsiveProps<P extends Record<string, any>>(\n Component: ComponentType<P>\n): ComponentType<P & { 'data-responsive'?: string; __canvasViewportWidth?: number }> {\n // forwardRef: scroll effects target the instance with `ref={…}` for\n // `useScroll({ target })` — a plain function component would silently drop\n // it (framer then throws \"Target ref is defined but not hydrated\"). The ref\n // pins to the animated wrapper (a real DOM box = the component's exact\n // footprint), so scroll measurement works with the component untouched.\n return forwardRef(function ResponsiveSpark(props: any, fwdRef: any) {\n const canvasVpWidth = props.__canvasViewportWidth as number | undefined;\n const [windowWidth, setWindowWidth] = useState(\n typeof window !== 'undefined' ? window.innerWidth : 1440\n );\n\n useEffect(() => {\n if (canvasVpWidth !== undefined) return;\n const handler = () => setWindowWidth(window.innerWidth);\n window.addEventListener('resize', handler);\n return () => window.removeEventListener('resize', handler);\n }, [canvasVpWidth]);\n\n const vpWidth = canvasVpWidth ?? windowWidth;\n const responsiveStr = props['data-responsive'];\n let mergedProps = { ...props };\n\n if (responsiveStr) {\n try {\n const overrides = typeof responsiveStr === 'string'\n ? JSON.parse(responsiveStr) : responsiveStr;\n // _bp contains all viewport breakpoint widths for range computation.\n // Each breakpoint's range is (prev_bp, bp]. Prevents cascade.\n const allBp = Array.isArray(overrides._bp)\n ? overrides._bp : Object.keys(overrides).filter(k => k !== '_bp').map(Number);\n const sortedBp = [...allBp].sort((a, b) => a - b);\n let matchedBp;\n for (let i = 0; i < sortedBp.length; i++) {\n const lower = i > 0 ? sortedBp[i - 1] : 0;\n if (vpWidth > lower && vpWidth <= sortedBp[i]) {\n matchedBp = sortedBp[i];\n break;\n }\n }\n if (matchedBp !== undefined && overrides[matchedBp]) {\n const ov = overrides[matchedBp];\n // A Scroll Variant binds `initialVariant={…Sv}` and OWNS it at runtime (it morphs the\n // variant on scroll). The per-viewport `data-responsive` entry must NOT override that\n // here — otherwise it freezes the variant on replicas and the morph never plays. The\n // per-viewport variant CHOICE still drives the canvas + seeds the Sv's resting; only\n // the runtime merge skips `initialVariant`. (No scroll variant → unchanged behaviour.)\n if (props['data-scroll-variant'] && ov && typeof ov === 'object' && 'initialVariant' in ov) {\n const { initialVariant: _skip, ...rest } = ov;\n mergedProps = { ...mergedProps, ...rest };\n } else {\n mergedProps = { ...mergedProps, ...ov };\n }\n }\n } catch {}\n }\n\n delete mergedProps['data-responsive'];\n delete mergedProps['__canvasViewportWidth'];\n\n // ── Animated-style socket (see header comment) ──\n // A forwarded ref ALSO forces the wrapper: it's the scroll-effect target,\n // which must resolve to a real DOM box even when the style carries no\n // animated values yet.\n const style = mergedProps.style as Record<string, any> | undefined;\n let needsWrapper = fwdRef != null;\n if (!needsWrapper && style) {\n for (const k of Object.keys(style)) {\n if (MOTION_ONLY_KEYS.has(k) || isMotionValue(style[k])) { needsWrapper = true; break; }\n }\n }\n if (needsWrapper) {\n const wrapperStyle: Record<string, any> = {};\n const innerStyle: Record<string, any> = {};\n for (const [k, v] of Object.entries(style ?? {})) {\n if (MOTION_ONLY_KEYS.has(k) || PLACEMENT_KEYS.has(k) || isMotionValue(v)) wrapperStyle[k] = v;\n else innerStyle[k] = v;\n }\n // The inner component fills the wrapper — but only along axes the\n // wrapper actually sized (code-component instances always carry\n // definite dims; the guard keeps an unsized axis hugging content).\n if ('width' in wrapperStyle) innerStyle.width = '100%';\n if ('height' in wrapperStyle) innerStyle.height = '100%';\n const { style: _split, ...rest } = mergedProps;\n delete rest.ref; // React 19 passes `ref` as a prop — never forward it inward\n return (\n <motion.div ref={fwdRef} style={wrapperStyle}>\n <Component {...rest} style={innerStyle} />\n </motion.div>\n );\n }\n\n return <Component {...mergedProps} />;\n }) as any;\n}\n","'use client';\n\nimport { useEffect, useRef, useSyncExternalStore, type ComponentType } from 'react';\nimport { motion, AnimatePresence, useMotionValue, useSpring } from 'framer-motion';\n\nexport type CursorMode = 'follow' | 'replace';\nexport type CursorSide = 'top' | 'bottom' | 'left' | 'right';\nexport type CursorAlign = 'start' | 'center' | 'end';\n\nexport interface CursorTransition {\n type?: 'spring' | 'tween' | 'instant';\n stiffness?: number;\n damping?: number;\n mass?: number;\n duration?: number;\n ease?: string;\n}\n\nexport interface CursorOpts<P = any> {\n variant?: string;\n mode?: CursorMode;\n /**\n * Which side of the mouse the cursor wrapper anchors to (Follow mode).\n * Replace mode ignores side / align / offset — it auto-centers on the mouse.\n */\n side?: CursorSide;\n /**\n * Alignment along the perpendicular axis to `side`.\n * top/bottom: start = left, center = horizontal center, end = right.\n * left/right: start = top, center = vertical center, end = bottom.\n */\n align?: CursorAlign;\n offsetX?: number;\n offsetY?: number;\n transition?: CursorTransition;\n props?: Partial<P>;\n /**\n * Wrapper width / height applied to the cursor's outer motion.div. Useful\n * for code components (canvases, sparks) that fill their parent — without\n * this they'd render at their intrinsic size, which is often the whole\n * viewport. Plain numbers are interpreted as px; pass a string ('100%',\n * '4rem') to use other CSS units.\n */\n width?: number | string;\n height?: number | string;\n /**\n * When true, fade/scale on enter and exit via AnimatePresence. Default\n * false: appear and disappear instantly. The follow movement is always\n * smoothed by the spring config above — `enterExit` only controls the\n * mount/unmount transition.\n */\n enterExit?: boolean;\n}\n\ninterface ActiveCursor {\n key: number;\n Component: ComponentType<any>;\n opts: CursorOpts;\n}\n\n// ─── Global store (vanilla, no React) ───────────────────────────────────────\nlet _active: ActiveCursor | null = null;\nconst _listeners = new Set<() => void>();\n\n// STABLE key per cursor COMPONENT (not per enter event). The old\n// `key: ++_nextKey` per mouseenter forced React to fully REMOUNT the cursor\n// component on every hover transition. Cursor components are typically design\n// components (LayoutGroup + layout motion nodes + variant background images),\n// so scrolling with the pointer over a stack of cursor-hosting elements fired\n// an enter/leave storm → remount storm → framer-motion projection re-registers\n// + image repaints + forced reflows piled onto the main thread — the page\n// froze for seconds (live find 2026-07-07). With a per-Component key, moving\n// between hosts that share a cursor UPDATES the mounted component in place —\n// the per-instance `variant` lands through `initialVariant`, which the design\n// component's internal sync effect animates. A DIFFERENT component still\n// remounts (key changes).\nconst _componentKeys = new WeakMap<ComponentType<any>, number>();\nlet _nextComponentKey = 0;\nfunction _keyFor(c: ComponentType<any>): number {\n let k = _componentKeys.get(c);\n if (k === undefined) {\n k = ++_nextComponentKey;\n _componentKeys.set(c, k);\n }\n return k;\n}\n\n// Pending deactivate from a mouseleave. Scrolling re-hit-tests the pointer, so\n// leave/enter alternate rapidly while the page moves under the mouse; clearing\n// the cursor synchronously on every leave caused an unmount per row boundary.\n// A short grace window absorbs the churn: a follow-up enter cancels the clear\n// (and, same component, is a pure prop update). A REAL exit clears once, ~90ms\n// later — imperceptible.\nlet _pendingClear: ReturnType<typeof setTimeout> | null = null;\n\nfunction _setActive(next: ActiveCursor | null) {\n _active = next;\n _listeners.forEach((l) => l());\n}\n\nfunction _subscribe(l: () => void) {\n _listeners.add(l);\n return () => { _listeners.delete(l); };\n}\n\nfunction _getActive() {\n return _active;\n}\n\n/**\n * Spread the return value into an element to give it a component cursor.\n * Returns onMouseEnter/onMouseLeave handlers that push/pop the global store.\n *\n * <button {...withCursor(Pointer, { mode: 'follow', transition: { type: 'spring', stiffness: 300 } })}>\n */\nexport function withCursor<P>(Component: ComponentType<P>, opts: CursorOpts<P> = {}) {\n return {\n onMouseEnter: () => {\n if (_pendingClear !== null) {\n clearTimeout(_pendingClear);\n _pendingClear = null;\n }\n _setActive({ key: _keyFor(Component as ComponentType<any>), Component: Component as ComponentType<any>, opts });\n },\n onMouseLeave: () => {\n if (_pendingClear !== null) clearTimeout(_pendingClear);\n _pendingClear = setTimeout(() => {\n _pendingClear = null;\n _setActive(null);\n }, 90);\n },\n };\n}\n\n// ─── Portal (mount once in LayoutClient) ────────────────────────────────────\n\nfunction _springConfig(t?: CursorTransition) {\n if (!t || t.type === 'instant') return { stiffness: 1000, damping: 50, mass: 0.1 };\n if (t.type === 'tween' && t.duration) {\n // Map a tween duration to roughly-equivalent spring values.\n const stiffness = Math.max(50, 400 / Math.max(0.1, t.duration));\n return { stiffness, damping: 30, mass: 1 };\n }\n return {\n stiffness: t.stiffness ?? 300,\n damping: t.damping ?? 30,\n mass: t.mass ?? 1,\n };\n}\n\nexport function CursorPortal() {\n const cursor = useSyncExternalStore(_subscribe, _getActive, _getActive);\n\n const x = useMotionValue(0);\n const y = useMotionValue(0);\n const sx = useSpring(x, _springConfig(cursor?.opts.transition));\n const sy = useSpring(y, _springConfig(cursor?.opts.transition));\n\n // One persistent listener; offsets read through a ref so an active-cursor\n // change never re-registers it (the old `[cursor]` dep re-added the listener\n // on every hover transition).\n const offsetRef = useRef({ x: 0, y: 0 });\n offsetRef.current = { x: cursor?.opts.offsetX ?? 0, y: cursor?.opts.offsetY ?? 0 };\n useEffect(() => {\n const onMove = (e: MouseEvent) => {\n x.set(e.clientX + offsetRef.current.x);\n y.set(e.clientY + offsetRef.current.y);\n };\n window.addEventListener('mousemove', onMove, { passive: true });\n return () => window.removeEventListener('mousemove', onMove);\n }, [x, y]);\n\n // Keyed on the MODE, not the whole active object: writing\n // `document.body.style.cursor` invalidates style for the entire document,\n // and the old `[cursor]` dep re-ran the write on every hover transition —\n // one full-page style recalc per row boundary while scrolling.\n const mode = cursor?.opts.mode;\n useEffect(() => {\n if (mode === 'replace') {\n const prev = document.body.style.cursor;\n document.body.style.cursor = 'none';\n return () => { document.body.style.cursor = prev; };\n }\n }, [mode]);\n\n // Wrapper width/height — numbers become px, strings pass through. Falls\n // back to undefined so intrinsic sizing kicks in if the user hasn't set it.\n const wrapW = typeof cursor?.opts.width === 'number' ? cursor.opts.width + 'px' : cursor?.opts.width;\n const wrapH = typeof cursor?.opts.height === 'number' ? cursor.opts.height + 'px' : cursor?.opts.height;\n\n // The OUTER motion.div carries the spring x/y (mouse position). The INNER\n // div applies a percentage transform for side+align (or auto-center in\n // Replace mode). Splitting them avoids fighting with framer-motion's own\n // transform handling on the x/y motion values.\n const outerStyle = {\n position: 'fixed' as const,\n top: 0,\n left: 0,\n x: sx,\n y: sy,\n pointerEvents: 'none' as const,\n zIndex: 9999,\n };\n const innerTransform = _innerTransform(cursor?.opts);\n const innerStyle = {\n width: wrapW,\n height: wrapH,\n transform: innerTransform,\n };\n\n // Default: instant in/out (no AnimatePresence wrapping). Wrap only when\n // the active cursor opts in via `enterExit: true` — keeps mount/unmount\n // snappy by default and avoids the brief fade-out from the previous cursor\n // when hovering between adjacent elements.\n // `opts.variant` → the design component's `initialVariant` prop. Without\n // this the variant picked in the editor (master call or per-instance\n // `<prop>Opts` override) was stored but NEVER applied — every hover showed\n // the cursor component's default variant (live find 2026-07-06). A fresh\n // `key` per hover means the component mounts with the right variant; its\n // internal `useEffect(() => setVariant(initialVariant), [initialVariant])`\n // covers any same-mount opts change.\n const variantProps = cursor?.opts.variant ? { initialVariant: cursor.opts.variant } : {};\n\n if (!cursor?.opts.enterExit) {\n return cursor ? (\n <motion.div key={cursor.key} style={outerStyle}>\n <div style={innerStyle}>\n <cursor.Component {...(cursor.opts.props ?? {})} {...variantProps} />\n </div>\n </motion.div>\n ) : null;\n }\n\n return (\n <AnimatePresence>\n {cursor && (\n <motion.div\n key={cursor.key}\n style={outerStyle}\n initial={{ opacity: 0, scale: 0.8 }}\n animate={{ opacity: 1, scale: 1 }}\n exit={{ opacity: 0, scale: 0.8 }}\n >\n <div style={innerStyle}>\n <cursor.Component {...(cursor.opts.props ?? {})} {...variantProps} />\n </div>\n </motion.div>\n )}\n </AnimatePresence>\n );\n}\n\n/**\n * Build the inner-wrapper transform from side + align + mode. Pure CSS\n * percentage translates so it works regardless of whether width/height are\n * set explicitly. Replace mode auto-centers; Follow mode anchors a corner /\n * edge / center based on the chosen side and alignment.\n */\nfunction _innerTransform(opts?: CursorOpts) {\n if (!opts || opts.mode === 'replace') return 'translate(-50%, -50%)';\n const side = opts.side ?? 'bottom';\n const align = opts.align ?? 'center';\n let tx = 0;\n let ty = 0;\n if (side === 'top') ty = -100;\n else if (side === 'left') tx = -100;\n // 'bottom' and 'right' default to 0 on the main axis.\n // Align controls the perpendicular axis.\n if (side === 'top' || side === 'bottom') {\n if (align === 'center') tx = -50;\n else if (align === 'end') tx = -100;\n } else {\n if (align === 'center') ty = -50;\n else if (align === 'end') ty = -100;\n }\n return 'translate(' + tx + '%, ' + ty + '%)';\n}\n","'use client';\n\n/**\n * `useStaticCanvas()` — returns `true` when the component is being rendered\n * inside the Revyme canvas editor, `false` in the live preview, published\n * site, or any other consumer environment.\n *\n * Sparks / code components use this to skip GPU-expensive animation work\n * (continuous rAF loops, big CSS blur layers, WebGL frames) on the editor\n * canvas where the user only needs a representative still — paint once,\n * stop. The full animated version still runs in preview and production.\n *\n * Mechanics: this default implementation always returns `false`. The canvas\n * editor's spark loader (`code-component-runtime.ts` MODULE_MAP) overrides\n * the export at compile time so it returns `true` in the canvas iframe and\n * `false` in the spark editor's preview pane (which sets `previewMode`).\n *\n * Mirrors Framer's `useIsStaticRenderer` pattern.\n */\nexport function useStaticCanvas(): boolean {\n return false;\n}\n","// sketch-draw.ts — Runtime player for Revyme sketch draw animations.\n//\n// Replays a brush-stroke sketch over time by feeding the original\n// pointer samples (persisted on each `<path>` as a `data-points`\n// attribute) back through perfect-freehand's `getStroke` at\n// progressively-increasing slice lengths. The result is the visible\n// equivalent of watching the user draw the sketch.\n//\n// Why a runtime function instead of an inline useEffect block in the\n// generated source: the orchestrator is ~80 LOC of imperative timing\n// + easing + RAF logic. Inlining it in every page that has a sketch\n// animation buries the page's actual logic. Living in\n// `@revyme/runtime` means the generated source is just one line:\n//\n// useEffect(() => playSketchDraw(el, opts), []);\n//\n// which reads the same way as `withResponsiveProps` / `withCursor`\n// already do for other generated patterns.\n\nimport { getStroke } from 'perfect-freehand';\n\nexport type SketchAnimMode = 'sequential' | 'staggered' | 'simultaneous';\nexport type SketchAnimTrigger = 'mount' | 'inView' | 'hover' | 'tap';\n\nexport interface SketchAnimTransition {\n type: 'tween' | 'spring';\n duration?: number;\n ease?: string;\n stiffness?: number;\n damping?: number;\n mass?: number;\n}\n\nexport interface SketchAnimOpts {\n trigger?: SketchAnimTrigger;\n mode?: SketchAnimMode;\n /** Multiplier on per-stroke duration. Per-stroke duration scales\n * with point count so a long stroke takes longer than a flick;\n * this dials the overall pace. */\n durationScale?: number;\n /** 0–1, only meaningful in staggered mode. 0 = fully sequential,\n * 1 = fully simultaneous. */\n stagger?: number;\n transition?: SketchAnimTransition;\n /** Brush size used for the intermediate-frame outline replay. The\n * final-frame `d` is restored from source so the end state is\n * pixel-exact regardless of this value. */\n brushSize?: number;\n}\n\nconst DEFAULT_OPTS: Required<Omit<SketchAnimOpts, 'transition'>> & { transition: SketchAnimTransition } = {\n trigger: 'inView',\n mode: 'sequential',\n durationScale: 1,\n stagger: 0.5,\n transition: { type: 'tween', duration: 1, ease: 'easeOut' },\n brushSize: 8,\n};\n\nfunction applyEase(t: number, transition: SketchAnimTransition): number {\n if (transition.type === 'spring') {\n const damping = transition.damping ?? 10;\n const stiffness = transition.stiffness ?? 100;\n const dampedT = 1 - Math.exp(-damping * t * 0.1);\n const oscillation = Math.cos(t * Math.sqrt(stiffness) * 0.3);\n return Math.min(1, dampedT * (1 - 0.1 * oscillation * (1 - t)));\n }\n switch (transition.ease ?? 'easeOut') {\n case 'linear': return t;\n case 'easeIn': return t * t;\n case 'easeOut': return 1 - (1 - t) * (1 - t);\n case 'easeInOut': return t < 0.5 ? 2 * t * t : 1 - Math.pow(-2 * t + 2, 2) / 2;\n case 'circIn': return 1 - Math.sqrt(1 - t * t);\n case 'circOut': return Math.sqrt(1 - Math.pow(t - 1, 2));\n case 'backOut': {\n const c1 = 1.70158;\n const c3 = c1 + 1;\n return 1 + c3 * Math.pow(t - 1, 3) + c1 * Math.pow(t - 1, 2);\n }\n default: return 1 - (1 - t) * (1 - t);\n }\n}\n\nfunction parsePoints(raw: string): number[][] {\n if (!raw) return [];\n return raw.split(/\\s+/).filter(Boolean).map(s => {\n const [x, y, p] = s.split(',');\n return [parseFloat(x) || 0, parseFloat(y) || 0, p != null ? parseFloat(p) : 0.5];\n });\n}\n\nfunction outlineToD(outline: number[][]): string {\n if (outline.length === 0) return '';\n let d = `M ${outline[0][0].toFixed(2)} ${outline[0][1].toFixed(2)}`;\n for (let i = 1; i < outline.length; i++) {\n d += ` L ${outline[i][0].toFixed(2)} ${outline[i][1].toFixed(2)}`;\n }\n return d + ' Z';\n}\n\n/**\n * Play a sketch draw animation on the given wrapper SVG. Pass the\n * options the generator emitted in source.\n *\n * Returns a cleanup function — wire as your useEffect's return value\n * so re-mounts cancel an in-flight animation cleanly:\n *\n * useEffect(() => playSketchDraw(svgEl, opts), []);\n *\n * If `wrapperEl` is null or the wrapper has no path children with\n * `data-points`, this is a no-op and returns a noop cleanup.\n */\nexport function playSketchDraw(\n wrapperEl: SVGSVGElement | null,\n userOpts: SketchAnimOpts = {},\n): () => void {\n const noop = () => {};\n if (!wrapperEl) return noop;\n const opts = { ...DEFAULT_OPTS, ...userOpts, transition: { ...DEFAULT_OPTS.transition, ...userOpts.transition } };\n\n const paths = Array.from(wrapperEl.querySelectorAll('path[data-points]')) as SVGPathElement[];\n if (paths.length === 0) return noop;\n\n // Snapshot the final d so the last frame is pixel-exact regardless\n // of the replay-with-default-brush approximation we use during\n // intermediate frames.\n const finalDs = paths.map(p => p.getAttribute('d') || '');\n const pointsList = paths.map(p => parsePoints(p.getAttribute('data-points') || ''));\n\n // Hide everything up front so the first frame doesn't flash.\n paths.forEach(p => p.setAttribute('d', ''));\n\n // Per-stroke duration — point count drives length so a long stroke\n // takes longer than a flick.\n const baseDur = (opts.transition.duration ?? 1) * 1000 * opts.durationScale;\n const maxPoints = pointsList.reduce((m, p) => Math.max(m, p.length), 1);\n const perStrokeDur = pointsList.map(p => baseDur * (p.length / maxPoints));\n const startMs: number[] = [];\n let cursor = 0;\n for (let i = 0; i < paths.length; i++) {\n if (opts.mode === 'simultaneous') {\n startMs.push(0);\n } else if (opts.mode === 'staggered') {\n const overlap = Math.max(0, Math.min(1, opts.stagger));\n const start = i === 0 ? 0 : startMs[i - 1] + perStrokeDur[i - 1] * (1 - overlap);\n startMs.push(start);\n } else {\n // sequential\n startMs.push(cursor);\n cursor += perStrokeDur[i];\n }\n }\n\n let cancelled = false;\n let rafId = 0;\n let started = false;\n let cleanupTrigger: (() => void) | null = null;\n let startTs = 0;\n\n const tick = (now: number) => {\n if (cancelled) return;\n const elapsed = now - startTs;\n let allDone = true;\n for (let i = 0; i < paths.length; i++) {\n const local = elapsed - startMs[i];\n if (local < 0) { allDone = false; continue; }\n const t = Math.min(1, local / Math.max(1, perStrokeDur[i]));\n if (t < 1) allDone = false;\n let d: string;\n if (t >= 1) {\n d = finalDs[i];\n } else {\n const eased = applyEase(t, opts.transition);\n const sliceCount = Math.max(2, Math.floor(pointsList[i].length * eased));\n const subset = pointsList[i].slice(0, sliceCount);\n if (subset.length < 2) {\n d = '';\n } else {\n const outline = getStroke(subset, {\n size: opts.brushSize, thinning: 0.5, smoothing: 0.5, streamline: 0.5,\n });\n d = outlineToD(outline);\n }\n }\n paths[i].setAttribute('d', d);\n }\n if (!allDone) rafId = requestAnimationFrame(tick);\n };\n\n const start = () => {\n if (started) return;\n started = true;\n startTs = performance.now();\n rafId = requestAnimationFrame(tick);\n };\n\n if (opts.trigger === 'inView') {\n const obs = new IntersectionObserver((entries) => {\n if (entries.some(e => e.isIntersecting)) {\n start();\n obs.disconnect();\n }\n }, { threshold: 0.2 });\n obs.observe(wrapperEl);\n cleanupTrigger = () => obs.disconnect();\n } else if (opts.trigger === 'hover') {\n const onEnter = () => start();\n wrapperEl.addEventListener('mouseenter', onEnter);\n cleanupTrigger = () => wrapperEl.removeEventListener('mouseenter', onEnter);\n } else if (opts.trigger === 'tap') {\n const onTap = () => start();\n wrapperEl.addEventListener('click', onTap);\n cleanupTrigger = () => wrapperEl.removeEventListener('click', onTap);\n } else {\n // mount\n start();\n }\n\n return () => {\n cancelled = true;\n cancelAnimationFrame(rafId);\n cleanupTrigger?.();\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAM,mBAAmB,IAAI,IAAI;CAC/B;CAAK;CAAK;CACV;CAAU;CAAW;CAAW;CAChC;CAAS;CAAU;CACnB;CAAQ;CAAS;CACjB;CAAW;CAAW;CACtB;CACD,CAAC;;;;AAKF,IAAM,iBAAiB,IAAI,IAAI;CAC7B;CAAY;CAAQ;CAAO;CAAS;CAAU;CAC9C;CAAS;CAAU;CAAY;CAAa;CAAY;CACxD;CAAQ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O;AAGT,cAAa;AACX,cAAY;AACZ,uBAAqB,MAAM;AAC3B,oBAAkB"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/withResponsiveProps.tsx","../src/cursor-runtime.tsx","../src/useStaticCanvas.ts","../src/split-text.tsx","../src/sketch-draw.ts"],"sourcesContent":["'use client';\n\nimport { useState, useEffect, forwardRef, type ComponentType } from 'react';\nimport { motion, isMotionValue } from 'framer-motion';\n\n/**\n * HOC that reads a `data-responsive` JSON prop and merges per-viewport overrides.\n * Usage: `export default withResponsiveProps(MyComponent)`\n *\n * On the canvas, CodeComponentHost injects `__canvasViewportWidth` to simulate viewport size.\n * In production, uses `window.innerWidth`.\n *\n * data-responsive='{\"768\":{\"fontSize\":32},\"375\":{\"fontSize\":24}}'\n * Breakpoints are max-width: if viewport <= 768, the 768 overrides apply.\n *\n * ANIMATED-STYLE SOCKET (Framer parity): the editor expresses instance\n * animation effects (Appear, scroll scrubs, …) as framer MotionValues bound\n * into the instance's `style` prop — `style={{ opacity: <mv>, y: <mv> }}`.\n * Design components consume them natively (their roots are motion.* and\n * spread `...style`), but a CODE component's root is a plain element: a\n * MotionValue arrives as an un-serialisable object (the style is dropped)\n * and motion-only keys like `y` aren't CSS at all — the effect silently\n * dies at the component boundary (live find 2026-07-14: Appear on a\n * Marquee). When animated values or motion-only keys are present, the HOC\n * renders a motion.div WRAPPER that carries them (plus the placement props\n * that describe the instance's slot in its parent), and hands the wrapped\n * component a clean static style. Framer does exactly this — the platform\n * owns an animatable container around every code component, so component\n * authors never deal with animation plumbing. No animated values → no\n * wrapper → byte-identical behaviour to before.\n */\n\n/** Style keys only a motion.* element understands (translated into\n * `transform`) — a plain DOM element ignores them entirely. */\nconst MOTION_ONLY_KEYS = new Set([\n 'x', 'y', 'z',\n 'rotate', 'rotateX', 'rotateY', 'rotateZ',\n 'scale', 'scaleX', 'scaleY',\n 'skew', 'skewX', 'skewY',\n 'originX', 'originY', 'originZ',\n 'transformPerspective',\n]);\n\n/** Placement props describing the instance's slot in ITS PARENT's layout —\n * these must ride on whichever element is outermost (the wrapper, when one\n * exists), mirroring the design-instance wrapper/root split. */\nconst PLACEMENT_KEYS = new Set([\n 'position', 'left', 'top', 'right', 'bottom', 'inset',\n 'width', 'height', 'minWidth', 'minHeight', 'maxWidth', 'maxHeight',\n 'flex', 'flexGrow', 'flexShrink', 'flexBasis',\n 'order', 'alignSelf', 'justifySelf', 'zIndex',\n 'margin', 'marginTop', 'marginRight', 'marginBottom', 'marginLeft',\n 'gridColumn', 'gridRow', 'gridArea',\n]);\nexport default function withResponsiveProps<P extends Record<string, any>>(\n Component: ComponentType<P>\n): ComponentType<P & { 'data-responsive'?: string; __canvasViewportWidth?: number }> {\n // forwardRef: scroll effects target the instance with `ref={…}` for\n // `useScroll({ target })` — a plain function component would silently drop\n // it (framer then throws \"Target ref is defined but not hydrated\"). The ref\n // pins to the animated wrapper (a real DOM box = the component's exact\n // footprint), so scroll measurement works with the component untouched.\n return forwardRef(function ResponsiveSpark(props: any, fwdRef: any) {\n const canvasVpWidth = props.__canvasViewportWidth as number | undefined;\n const [windowWidth, setWindowWidth] = useState(\n typeof window !== 'undefined' ? window.innerWidth : 1440\n );\n\n useEffect(() => {\n if (canvasVpWidth !== undefined) return;\n const handler = () => setWindowWidth(window.innerWidth);\n window.addEventListener('resize', handler);\n return () => window.removeEventListener('resize', handler);\n }, [canvasVpWidth]);\n\n const vpWidth = canvasVpWidth ?? windowWidth;\n const responsiveStr = props['data-responsive'];\n let mergedProps = { ...props };\n\n if (responsiveStr) {\n try {\n const overrides = typeof responsiveStr === 'string'\n ? JSON.parse(responsiveStr) : responsiveStr;\n // _bp contains all viewport breakpoint widths for range computation.\n // Each breakpoint's range is (prev_bp, bp]. Prevents cascade.\n const allBp = Array.isArray(overrides._bp)\n ? overrides._bp : Object.keys(overrides).filter(k => k !== '_bp').map(Number);\n const sortedBp = [...allBp].sort((a, b) => a - b);\n let matchedBp;\n for (let i = 0; i < sortedBp.length; i++) {\n const lower = i > 0 ? sortedBp[i - 1] : 0;\n if (vpWidth > lower && vpWidth <= sortedBp[i]) {\n matchedBp = sortedBp[i];\n break;\n }\n }\n if (matchedBp !== undefined && overrides[matchedBp]) {\n const ov = overrides[matchedBp];\n // A Scroll Variant binds `initialVariant={…Sv}` and OWNS it at runtime (it morphs the\n // variant on scroll). The per-viewport `data-responsive` entry must NOT override that\n // here — otherwise it freezes the variant on replicas and the morph never plays. The\n // per-viewport variant CHOICE still drives the canvas + seeds the Sv's resting; only\n // the runtime merge skips `initialVariant`. (No scroll variant → unchanged behaviour.)\n if (props['data-scroll-variant'] && ov && typeof ov === 'object' && 'initialVariant' in ov) {\n const { initialVariant: _skip, ...rest } = ov;\n mergedProps = { ...mergedProps, ...rest };\n } else {\n mergedProps = { ...mergedProps, ...ov };\n }\n }\n } catch {}\n }\n\n delete mergedProps['data-responsive'];\n delete mergedProps['__canvasViewportWidth'];\n\n // ── Animated-style socket (see header comment) ──\n // A forwarded ref ALSO forces the wrapper: it's the scroll-effect target,\n // which must resolve to a real DOM box even when the style carries no\n // animated values yet.\n const style = mergedProps.style as Record<string, any> | undefined;\n let needsWrapper = fwdRef != null;\n if (!needsWrapper && style) {\n for (const k of Object.keys(style)) {\n if (MOTION_ONLY_KEYS.has(k) || isMotionValue(style[k])) { needsWrapper = true; break; }\n }\n }\n if (needsWrapper) {\n const wrapperStyle: Record<string, any> = {};\n const innerStyle: Record<string, any> = {};\n for (const [k, v] of Object.entries(style ?? {})) {\n if (MOTION_ONLY_KEYS.has(k) || PLACEMENT_KEYS.has(k) || isMotionValue(v)) wrapperStyle[k] = v;\n else innerStyle[k] = v;\n }\n // The inner component fills the wrapper — but only along axes the\n // wrapper actually sized (code-component instances always carry\n // definite dims; the guard keeps an unsized axis hugging content).\n if ('width' in wrapperStyle) innerStyle.width = '100%';\n if ('height' in wrapperStyle) innerStyle.height = '100%';\n // The wrapper OWNS the instance's slot (all placement keys moved onto\n // it) — the inner root must re-base INTO the wrapper. Design-component\n // masters bake `position: 'absolute'` on their root (canvas master\n // tiling) and rely on the instance style overriding it via the trailing\n // `...style` spread; with the split the position key never reaches them,\n // so the root absolute-positioned inside a zero-size wrapper and\n // vanished (live find 2026-07-28: Sign Up button instance inside an\n // AnimatePresence popLayout header — popLayout's ref forces the\n // wrapper). Position is a PLACEMENT key, so innerStyle can never carry\n // its own — always re-base.\n innerStyle.position = 'relative';\n const { style: _split, ...rest } = mergedProps;\n delete rest.ref; // React 19 passes `ref` as a prop — never forward it inward\n return (\n <motion.div ref={fwdRef} style={wrapperStyle}>\n <Component {...rest} style={innerStyle} />\n </motion.div>\n );\n }\n\n return <Component {...mergedProps} />;\n }) as any;\n}\n","'use client';\n\nimport { useEffect, useRef, useSyncExternalStore, type ComponentType } from 'react';\nimport { motion, AnimatePresence, useMotionValue, useSpring } from 'framer-motion';\n\nexport type CursorMode = 'follow' | 'replace';\nexport type CursorSide = 'top' | 'bottom' | 'left' | 'right';\nexport type CursorAlign = 'start' | 'center' | 'end';\n\nexport interface CursorTransition {\n type?: 'spring' | 'tween' | 'instant';\n stiffness?: number;\n damping?: number;\n mass?: number;\n duration?: number;\n ease?: string;\n}\n\nexport interface CursorOpts<P = any> {\n variant?: string;\n mode?: CursorMode;\n /**\n * Which side of the mouse the cursor wrapper anchors to (Follow mode).\n * Replace mode ignores side / align / offset — it auto-centers on the mouse.\n */\n side?: CursorSide;\n /**\n * Alignment along the perpendicular axis to `side`.\n * top/bottom: start = left, center = horizontal center, end = right.\n * left/right: start = top, center = vertical center, end = bottom.\n */\n align?: CursorAlign;\n offsetX?: number;\n offsetY?: number;\n transition?: CursorTransition;\n props?: Partial<P>;\n /**\n * Wrapper width / height applied to the cursor's outer motion.div. Useful\n * for code components (canvases, sparks) that fill their parent — without\n * this they'd render at their intrinsic size, which is often the whole\n * viewport. Plain numbers are interpreted as px; pass a string ('100%',\n * '4rem') to use other CSS units.\n */\n width?: number | string;\n height?: number | string;\n /**\n * When true, fade/scale on enter and exit via AnimatePresence. Default\n * false: appear and disappear instantly. The follow movement is always\n * smoothed by the spring config above — `enterExit` only controls the\n * mount/unmount transition.\n */\n enterExit?: boolean;\n}\n\ninterface ActiveCursor {\n key: number;\n Component: ComponentType<any>;\n opts: CursorOpts;\n}\n\n// ─── Global store (vanilla, no React) ───────────────────────────────────────\nlet _active: ActiveCursor | null = null;\nconst _listeners = new Set<() => void>();\n\n// STABLE key per cursor COMPONENT (not per enter event). The old\n// `key: ++_nextKey` per mouseenter forced React to fully REMOUNT the cursor\n// component on every hover transition. Cursor components are typically design\n// components (LayoutGroup + layout motion nodes + variant background images),\n// so scrolling with the pointer over a stack of cursor-hosting elements fired\n// an enter/leave storm → remount storm → framer-motion projection re-registers\n// + image repaints + forced reflows piled onto the main thread — the page\n// froze for seconds (live find 2026-07-07). With a per-Component key, moving\n// between hosts that share a cursor UPDATES the mounted component in place —\n// the per-instance `variant` lands through `initialVariant`, which the design\n// component's internal sync effect animates. A DIFFERENT component still\n// remounts (key changes).\nconst _componentKeys = new WeakMap<ComponentType<any>, number>();\nlet _nextComponentKey = 0;\nfunction _keyFor(c: ComponentType<any>): number {\n let k = _componentKeys.get(c);\n if (k === undefined) {\n k = ++_nextComponentKey;\n _componentKeys.set(c, k);\n }\n return k;\n}\n\n// Pending deactivate from a mouseleave. Scrolling re-hit-tests the pointer, so\n// leave/enter alternate rapidly while the page moves under the mouse; clearing\n// the cursor synchronously on every leave caused an unmount per row boundary.\n// A short grace window absorbs the churn: a follow-up enter cancels the clear\n// (and, same component, is a pure prop update). A REAL exit clears once, ~90ms\n// later — imperceptible.\nlet _pendingClear: ReturnType<typeof setTimeout> | null = null;\n\nfunction _setActive(next: ActiveCursor | null) {\n _active = next;\n _listeners.forEach((l) => l());\n}\n\nfunction _subscribe(l: () => void) {\n _listeners.add(l);\n return () => { _listeners.delete(l); };\n}\n\nfunction _getActive() {\n return _active;\n}\n\n/**\n * Spread the return value into an element to give it a component cursor.\n * Returns onMouseEnter/onMouseLeave handlers that push/pop the global store.\n *\n * <button {...withCursor(Pointer, { mode: 'follow', transition: { type: 'spring', stiffness: 300 } })}>\n */\nexport function withCursor<P>(Component: ComponentType<P>, opts: CursorOpts<P> = {}) {\n return {\n onMouseEnter: () => {\n if (_pendingClear !== null) {\n clearTimeout(_pendingClear);\n _pendingClear = null;\n }\n _setActive({ key: _keyFor(Component as ComponentType<any>), Component: Component as ComponentType<any>, opts });\n },\n onMouseLeave: () => {\n if (_pendingClear !== null) clearTimeout(_pendingClear);\n _pendingClear = setTimeout(() => {\n _pendingClear = null;\n _setActive(null);\n }, 90);\n },\n };\n}\n\n// ─── Portal (mount once in LayoutClient) ────────────────────────────────────\n\nfunction _springConfig(t?: CursorTransition) {\n if (!t || t.type === 'instant') return { stiffness: 1000, damping: 50, mass: 0.1 };\n if (t.type === 'tween' && t.duration) {\n // Map a tween duration to roughly-equivalent spring values.\n const stiffness = Math.max(50, 400 / Math.max(0.1, t.duration));\n return { stiffness, damping: 30, mass: 1 };\n }\n return {\n stiffness: t.stiffness ?? 300,\n damping: t.damping ?? 30,\n mass: t.mass ?? 1,\n };\n}\n\nexport function CursorPortal() {\n const cursor = useSyncExternalStore(_subscribe, _getActive, _getActive);\n\n const x = useMotionValue(0);\n const y = useMotionValue(0);\n const sx = useSpring(x, _springConfig(cursor?.opts.transition));\n const sy = useSpring(y, _springConfig(cursor?.opts.transition));\n\n // One persistent listener; offsets read through a ref so an active-cursor\n // change never re-registers it (the old `[cursor]` dep re-added the listener\n // on every hover transition).\n const offsetRef = useRef({ x: 0, y: 0 });\n offsetRef.current = { x: cursor?.opts.offsetX ?? 0, y: cursor?.opts.offsetY ?? 0 };\n useEffect(() => {\n const onMove = (e: MouseEvent) => {\n x.set(e.clientX + offsetRef.current.x);\n y.set(e.clientY + offsetRef.current.y);\n };\n window.addEventListener('mousemove', onMove, { passive: true });\n return () => window.removeEventListener('mousemove', onMove);\n }, [x, y]);\n\n // Keyed on the MODE, not the whole active object: writing\n // `document.body.style.cursor` invalidates style for the entire document,\n // and the old `[cursor]` dep re-ran the write on every hover transition —\n // one full-page style recalc per row boundary while scrolling.\n const mode = cursor?.opts.mode;\n useEffect(() => {\n if (mode === 'replace') {\n const prev = document.body.style.cursor;\n document.body.style.cursor = 'none';\n return () => { document.body.style.cursor = prev; };\n }\n }, [mode]);\n\n // Wrapper width/height — numbers become px, strings pass through. Falls\n // back to undefined so intrinsic sizing kicks in if the user hasn't set it.\n const wrapW = typeof cursor?.opts.width === 'number' ? cursor.opts.width + 'px' : cursor?.opts.width;\n const wrapH = typeof cursor?.opts.height === 'number' ? cursor.opts.height + 'px' : cursor?.opts.height;\n\n // The OUTER motion.div carries the spring x/y (mouse position). The INNER\n // div applies a percentage transform for side+align (or auto-center in\n // Replace mode). Splitting them avoids fighting with framer-motion's own\n // transform handling on the x/y motion values.\n const outerStyle = {\n position: 'fixed' as const,\n top: 0,\n left: 0,\n x: sx,\n y: sy,\n pointerEvents: 'none' as const,\n zIndex: 9999,\n };\n const innerTransform = _innerTransform(cursor?.opts);\n const innerStyle = {\n width: wrapW,\n height: wrapH,\n transform: innerTransform,\n };\n\n // Default: instant in/out (no AnimatePresence wrapping). Wrap only when\n // the active cursor opts in via `enterExit: true` — keeps mount/unmount\n // snappy by default and avoids the brief fade-out from the previous cursor\n // when hovering between adjacent elements.\n // `opts.variant` → the design component's `initialVariant` prop. Without\n // this the variant picked in the editor (master call or per-instance\n // `<prop>Opts` override) was stored but NEVER applied — every hover showed\n // the cursor component's default variant (live find 2026-07-06). A fresh\n // `key` per hover means the component mounts with the right variant; its\n // internal `useEffect(() => setVariant(initialVariant), [initialVariant])`\n // covers any same-mount opts change.\n const variantProps = cursor?.opts.variant ? { initialVariant: cursor.opts.variant } : {};\n\n if (!cursor?.opts.enterExit) {\n return cursor ? (\n <motion.div key={cursor.key} style={outerStyle}>\n <div style={innerStyle}>\n <cursor.Component {...(cursor.opts.props ?? {})} {...variantProps} />\n </div>\n </motion.div>\n ) : null;\n }\n\n return (\n <AnimatePresence>\n {cursor && (\n <motion.div\n key={cursor.key}\n style={outerStyle}\n initial={{ opacity: 0, scale: 0.8 }}\n animate={{ opacity: 1, scale: 1 }}\n exit={{ opacity: 0, scale: 0.8 }}\n >\n <div style={innerStyle}>\n <cursor.Component {...(cursor.opts.props ?? {})} {...variantProps} />\n </div>\n </motion.div>\n )}\n </AnimatePresence>\n );\n}\n\n/**\n * Build the inner-wrapper transform from side + align + mode. Pure CSS\n * percentage translates so it works regardless of whether width/height are\n * set explicitly. Replace mode auto-centers; Follow mode anchors a corner /\n * edge / center based on the chosen side and alignment.\n */\nfunction _innerTransform(opts?: CursorOpts) {\n if (!opts || opts.mode === 'replace') return 'translate(-50%, -50%)';\n const side = opts.side ?? 'bottom';\n const align = opts.align ?? 'center';\n let tx = 0;\n let ty = 0;\n if (side === 'top') ty = -100;\n else if (side === 'left') tx = -100;\n // 'bottom' and 'right' default to 0 on the main axis.\n // Align controls the perpendicular axis.\n if (side === 'top' || side === 'bottom') {\n if (align === 'center') tx = -50;\n else if (align === 'end') tx = -100;\n } else {\n if (align === 'center') ty = -50;\n else if (align === 'end') ty = -100;\n }\n return 'translate(' + tx + '%, ' + ty + '%)';\n}\n","'use client';\n\n/**\n * `useStaticCanvas()` — returns `true` when the component is being rendered\n * inside the Revyme canvas editor, `false` in the live preview, published\n * site, or any other consumer environment.\n *\n * Sparks / code components use this to skip GPU-expensive animation work\n * (continuous rAF loops, big CSS blur layers, WebGL frames) on the editor\n * canvas where the user only needs a representative still — paint once,\n * stop. The full animated version still runs in preview and production.\n *\n * Mechanics: this default implementation always returns `false`. The canvas\n * editor's spark loader (`code-component-runtime.ts` MODULE_MAP) overrides\n * the export at compile time so it returns `true` in the canvas iframe and\n * `false` in the spark editor's preview pane (which sets `previewMode`).\n *\n * Mirrors Framer's `useIsStaticRenderer` pattern.\n */\nexport function useStaticCanvas(): boolean {\n return false;\n}\n","'use client';\n\n// split-text.tsx — `<RevymeSplitText>`: the runtime half of Revyme's Text effect.\n//\n// WHY THIS EXISTS (2026-07-31). Text effects used to be split at CODEGEN time: the\n// generator wrote N `<motion.span>` elements — one per character — straight into the\n// user's page source. That cannot work for text that isn't known until render:\n// `{item.title}` from a CMS row, `{t('key')}` from i18n, `{propName}` from a component\n// variable. The generator saw an expression, not a string, and escaped it per character\n// into `&#123;item.title&#125;`, so every CMS row rendered the literal text `{item.title}`.\n//\n// Splitting at RENDER time removes the whole class of problem: by the time this component\n// runs, `children` is already the resolved string. It also collapses ~600 lines of\n// generator (four span builders, scroll-hook injection, canvas dormancy) into one prop.\n//\n// HARD CONSTRAINT — the split must be a PURE function of props, computed DURING RENDER.\n// Published sites are SSR'd; a split deferred to an effect would emit a bare string on the\n// server and spans on the client, i.e. a hydration mismatch. Nothing here measures the DOM\n// or reads `window` outside an effect/lazy-initialiser.\n\nimport * as React from 'react';\nimport { motion, useInView, useScroll, useTransform, type MotionValue } from 'framer-motion';\n\n// ─── Spec ────────────────────────────────────────────────────────────────────\n\nexport type SplitTextScope = { query: string } | { variant: string };\n\n/** Structurally `TextAnimConfig` from the builder (canvas-poc/src/editor/tools/\n * AnimationTool/motion/text-anim-presets.ts). Kept in sync by a type-assignability\n * test in canvas-poc — a field added there without a counterpart here fails the build. */\nexport interface SplitTextSpec {\n /** STRUCTURAL — resolved from the BASE spec only, never from a scope override, so the\n * emitted tree is identical on server and client. */\n animationType?: 'character' | 'word' | 'line' | 'full';\n /** STRUCTURAL — wraps each unit in an overflow-hidden clip (\"cut-off\" reveal). */\n mask?: boolean;\n trigger?: 'view' | 'scroll';\n /** Scroll mode only — viewport position (% from top) where the reveal starts / completes. */\n scrollStart?: number;\n scrollEnd?: number;\n opacity?: number;\n scale?: number;\n blur?: number;\n rotateX?: number;\n rotateY?: number;\n rotateZ?: number;\n skewX?: number;\n skewY?: number;\n /** Strings keep their unit. '100%' resolves against the unit's OWN box, which is what\n * makes a masked reveal correct at every type size — a px offset masks correctly at\n * one breakpoint only. */\n x?: number | string;\n y?: number | string;\n /** Stagger between units, seconds. */\n delay?: number;\n transition?: {\n type?: 'spring' | 'tween';\n stiffness?: number;\n damping?: number;\n mass?: number;\n duration?: number;\n bounce?: number;\n ease?: string | number[];\n /** Initial delay before the first unit, seconds. */\n delay?: number;\n };\n /** Per-viewport / per-variant value overrides. First match wins (matches the builder's\n * `resolveTextAnimForScope`). Structural fields in an override are ignored. */\n responsive?: Array<{ scope: SplitTextScope; config: Partial<SplitTextSpec> }>;\n}\n\nexport interface RevymeSplitTextProps {\n spec?: SplitTextSpec;\n /** Active component variant — only needed when `spec.responsive` has `{variant}` scopes. */\n variant?: string;\n children?: React.ReactNode;\n}\n\n// ─── Helpers ─────────────────────────────────────────────────────────────────\n\nconst WRAP_PLAIN: React.CSSProperties = { whiteSpace: 'nowrap' };\n/** paddingBottom/marginBottom cancel out — zero layout cost. The padding keeps descenders\n * (g, y, p) from being shaved by the clip AND leaves the sliver IntersectionObserver needs\n * when a unit is offset a full 100% (otherwise it sits entirely outside the clip). */\nconst WRAP_MASK: React.CSSProperties = {\n whiteSpace: 'nowrap', display: 'inline-block', overflow: 'hidden',\n paddingBottom: '0.14em', marginBottom: '-0.14em',\n};\n\n/** The editor persists a custom cubic-bezier as the STRING \"[0.22, 1, 0.36, 1]\" (that's what\n * the TransitionPanel curve editor writes). framer accepts a named easing or a real array —\n * handed the string it throws `Invalid easing type` and unmounts the tree. Codegen normalises\n * this too; the runtime keeps it so hand-written source still works. */\nfunction normalizeEase(e: string | number[] | undefined): string | number[] | undefined {\n if (e === undefined || Array.isArray(e)) return e;\n const s = String(e).trim();\n if (!s.startsWith('[')) return s;\n const n = s.replace(/[[\\]]/g, '').split(',').map((v) => parseFloat(v.trim()));\n return n.length === 4 && n.every(Number.isFinite) ? n : undefined;\n}\n\n/** Collapse React children to a plain string, or null when they can't be split.\n *\n * `null` (a real element child — a styled `<span>` mark, an icon) means \"render verbatim,\n * unsplit\" rather than mangling rich content. Everything the generator used to normalise at\n * build time — `{item.title}`, `{t('key')}`, `{\"a\\nb\"}`, `a<br/>b` — arrives here already\n * resolved to a string or a `<br />`, so one function covers all of it. */\nfunction flattenToText(node: React.ReactNode): string | null {\n if (node === null || node === undefined || node === false || node === true) return '';\n if (typeof node === 'string') return node;\n if (typeof node === 'number') return String(node);\n if (Array.isArray(node)) {\n let out = '';\n for (const child of node) {\n const part = flattenToText(child);\n if (part === null) return null;\n out += part;\n }\n return out;\n }\n if (React.isValidElement(node)) {\n const type = (node as React.ReactElement).type;\n if (type === 'br') return '\\n';\n if (type === React.Fragment) return flattenToText((node.props as any)?.children);\n return null; // a real element → not splittable\n }\n return null;\n}\n\n/** Active `responsive` entry index, or -1 for the base spec.\n *\n * The `matchMedia` read is a LAZY useState initialiser, not a post-mount effect: framer\n * captures `initial` once at mount, so starting at `false` and correcting later makes the\n * responsive branch permanently lose to the base. Same shape as the builder's generated\n * `useMediaQuery` (canvas-poc/src/code/generation/scoped-expr.ts). */\nfunction useActiveScopeIndex(spec: SplitTextSpec, variant?: string): number {\n const entries = spec.responsive;\n const compute = React.useCallback((): number => {\n if (!entries || entries.length === 0) return -1;\n for (let i = 0; i < entries.length; i++) {\n const scope = entries[i].scope;\n if ('variant' in scope) {\n if (variant !== undefined && scope.variant === variant) return i;\n } else if (typeof window !== 'undefined' && typeof window.matchMedia === 'function') {\n if (window.matchMedia(scope.query).matches) return i;\n }\n }\n return -1;\n }, [entries, variant]);\n\n const [idx, setIdx] = React.useState(compute);\n\n React.useEffect(() => {\n setIdx(compute());\n if (!entries || typeof window === 'undefined' || typeof window.matchMedia !== 'function') return;\n const lists = entries\n .map((e) => ('query' in e.scope ? window.matchMedia(e.scope.query) : null))\n .filter(Boolean) as MediaQueryList[];\n if (lists.length === 0) return;\n const onChange = () => setIdx(compute());\n for (const l of lists) l.addEventListener('change', onChange);\n return () => { for (const l of lists) l.removeEventListener('change', onChange); };\n }, [entries, compute]);\n\n return idx;\n}\n\nconst RESTING: Record<string, number> = { opacity: 1, scale: 1, rotateX: 0, rotateY: 0, rotateZ: 0, skewX: 0, skewY: 0, x: 0, y: 0 };\nconst CHANNELS = ['opacity', 'scale', 'rotateX', 'rotateY', 'rotateZ', 'skewX', 'skewY', 'x', 'y'] as const;\n\n/** The animated-from state. Mirrors the builder's `buildHiddenState`: a channel is animated\n * only when the spec sets it to something other than its resting value. */\nfunction hiddenState(s: SplitTextSpec): Record<string, any> {\n const out: Record<string, any> = {};\n for (const k of CHANNELS) {\n const v = s[k];\n if (v !== undefined && v !== RESTING[k]) out[k] = v;\n }\n if (s.blur !== undefined && s.blur !== 0) out.filter = `blur(${s.blur}px)`;\n return out;\n}\n\nfunction visibleState(s: SplitTextSpec): Record<string, any> {\n const out: Record<string, any> = {};\n for (const k of CHANNELS) {\n const v = s[k];\n if (v !== undefined && v !== RESTING[k]) out[k] = RESTING[k];\n }\n if (s.blur !== undefined && s.blur !== 0) out.filter = 'blur(0px)';\n return out;\n}\n\n/** `'100%'` → `'0%'`, `24` → `0`. Keeps the unit so a percentage offset scrubs correctly. */\nfunction restingOf(from: number | string, key: string): number | string {\n if (typeof from === 'number') return RESTING[key] ?? 0;\n const m = String(from).match(/^(-?[\\d.]+)(.*)$/);\n return m ? `${RESTING[key] ?? 0}${m[2]}` : (RESTING[key] ?? 0);\n}\n\ninterface Unit { key: string; inner: string; display: 'inline-block' | 'block'; index: number }\n\ntype Node = { t: 'unit'; u: Unit } | { t: 'br'; k: string } | { t: 'text'; k: string; v: string }\n | { t: 'wrap'; k: string; kids: Node[] };\n\n/** Split `text` into render nodes. Structure mirrors the old codegen splitter exactly, so the\n * emitted DOM is unchanged from the build-time era. Keys are pure functions of index → SSR\n * and CSR agree. */\nfunction buildNodes(text: string, animationType: SplitTextSpec['animationType'], mask: boolean): { nodes: Node[]; count: number } {\n const nodes: Node[] = [];\n let i = 0;\n const lines = text.split('\\n');\n\n if (animationType === 'line') {\n for (let li = 0; li < lines.length; li++) {\n if (li > 0) nodes.push({ t: 'br', k: `br${li}` });\n nodes.push({ t: 'unit', u: { key: `u${i}`, inner: lines[li], display: 'block', index: i } });\n i++;\n }\n return { nodes, count: i };\n }\n if (animationType === 'full') {\n nodes.push({ t: 'unit', u: { key: 'u0', inner: text, display: 'inline-block', index: 0 } });\n return { nodes, count: 1 };\n }\n\n for (let li = 0; li < lines.length; li++) {\n if (li > 0) nodes.push({ t: 'br', k: `br${li}` });\n const words = lines[li].split(' ');\n for (let wi = 0; wi < words.length; wi++) {\n if (wi > 0) nodes.push({ t: 'text', k: `sp${li}-${wi}`, v: ' ' });\n const word = words[wi];\n if (!word) continue;\n if (animationType === 'word') {\n const u: Node = { t: 'unit', u: { key: `u${i}`, inner: word, display: 'inline-block', index: i } };\n i++;\n nodes.push(mask ? { t: 'wrap', k: `w${li}-${wi}`, kids: [u] } : u);\n } else {\n const kids: Node[] = [];\n for (const ch of word) {\n kids.push({ t: 'unit', u: { key: `u${i}`, inner: ch, display: 'inline-block', index: i } });\n i++;\n }\n nodes.push({ t: 'wrap', k: `w${li}-${wi}`, kids });\n }\n }\n }\n return { nodes, count: i };\n}\n\n// ─── Scroll unit ─────────────────────────────────────────────────────────────\n\n/** One scroll-scrubbed unit. Split into its own component because `useTransform` must be\n * called once per animated channel and that count is data-driven — calling them in a loop\n * inside the parent would violate the rules of hooks. The parent keys each instance by a\n * channel fingerprint, so a spec change REMOUNTS rather than reordering hooks. */\nfunction ScrollUnit({ progress, range, channels, display, children }: {\n progress: MotionValue<number>;\n range: [number, number];\n channels: Array<{ key: string; from: number | string; to: number | string }>;\n display: string;\n children: React.ReactNode;\n}) {\n const style: Record<string, any> = { display };\n for (const c of channels) {\n // eslint-disable-next-line react-hooks/rules-of-hooks -- count is fixed per mount; see above\n style[c.key] = useTransform(progress, range, [c.from as never, c.to as never]);\n }\n return <motion.span style={style as React.CSSProperties}>{children}</motion.span>;\n}\n\n// ─── Component ───────────────────────────────────────────────────────────────\n\nexport function RevymeSplitText({ spec, variant, children }: RevymeSplitTextProps): React.ReactElement {\n const base: SplitTextSpec = spec ?? {};\n const hostRef = React.useRef<HTMLSpanElement>(null);\n\n const scopeIdx = useActiveScopeIndex(base, variant);\n const resolved: SplitTextSpec = React.useMemo(() => {\n const r = scopeIdx >= 0 && base.responsive\n ? { ...base, ...base.responsive[scopeIdx].config }\n : base;\n // Structural fields come from the BASE, always — the tree must not depend on a scope,\n // or server and client can disagree about the DOM (not just about style values).\n return { ...r, animationType: base.animationType, mask: base.mask, responsive: base.responsive };\n }, [base, scopeIdx]);\n\n const animationType = base.animationType ?? 'character';\n const mask = !!base.mask;\n const text = flattenToText(children);\n\n // ONE observer for the whole run, not one per character. Besides being N× cheaper, this\n // structurally avoids the deadlock the per-character form had: a masked unit offset out of\n // its own overflow-hidden clip has intersection ratio 0 and never fires.\n const inView = useInView(hostRef, { once: true, amount: 0 });\n\n // Called unconditionally so the hook count never changes when a scope flips view↔scroll.\n const startFrac = Math.min(1, Math.max(0, (resolved.scrollStart ?? 90) / 100));\n const endFrac = Math.min(1, Math.max(0, (resolved.scrollEnd ?? 35) / 100));\n const { scrollYProgress } = useScroll({\n target: hostRef,\n offset: [`start ${startFrac}`, `start ${endFrac}`] as never,\n });\n\n const { nodes, count } = React.useMemo(\n () => buildNodes(text ?? '', animationType, mask),\n [text, animationType, mask],\n );\n\n // Not splittable (a styled span, an icon) → render verbatim rather than mangling it.\n if (text === null) return <span ref={hostRef}>{children}</span>;\n\n const isScroll = resolved.trigger === 'scroll';\n const hidden = hiddenState(resolved);\n const visible = visibleState(resolved);\n const stagger = resolved.delay ?? 0.05;\n const initialDelay = resolved.transition?.delay ?? 0;\n const tr = resolved.transition\n ? { ...resolved.transition, ease: normalizeEase(resolved.transition.ease), delay: undefined } as any\n : { type: 'spring' as const, stiffness: 300, damping: 30 } as any;\n\n const channels = isScroll\n ? Object.entries(hidden).map(([key, from]) => ({\n key,\n from: from as number | string,\n to: key === 'filter' ? 'blur(0px)' : restingOf(from as number | string, key),\n }))\n : [];\n const fingerprint = channels.map((c) => c.key).join('|');\n\n const renderUnit = (u: Unit): React.ReactElement => {\n if (isScroll) {\n const start = count > 1 ? Math.round((u.index / (count - 1)) * 0.6 * 1000) / 1000 : 0;\n const end = Math.min(1, Math.round((start + 0.4) * 1000) / 1000);\n return (\n <ScrollUnit\n key={`${fingerprint}#${u.key}`}\n progress={scrollYProgress}\n range={[start, end]}\n channels={channels}\n display={u.display}\n >{u.inner}</ScrollUnit>\n );\n }\n return (\n <motion.span\n key={u.key}\n style={{ display: u.display }}\n initial={hidden}\n animate={inView ? visible : hidden}\n transition={{ ...tr, delay: Math.round((initialDelay + u.index * stagger) * 1000) / 1000 }}\n >{u.inner}</motion.span>\n );\n };\n\n const render = (n: Node): React.ReactNode => {\n if (n.t === 'br') return <br key={n.k} />;\n if (n.t === 'text') return n.v;\n if (n.t === 'wrap') return <span key={n.k} style={mask ? WRAP_MASK : WRAP_PLAIN}>{n.kids.map(render)}</span>;\n return renderUnit(n.u);\n };\n\n return (\n <span ref={hostRef} style={{ display: animationType === 'line' ? 'block' : 'inline' }}>\n {nodes.map(render)}\n </span>\n );\n}\n\nexport default RevymeSplitText;\n","// sketch-draw.ts — Runtime player for Revyme sketch draw animations.\n//\n// Replays a brush-stroke sketch over time by feeding the original\n// pointer samples (persisted on each `<path>` as a `data-points`\n// attribute) back through perfect-freehand's `getStroke` at\n// progressively-increasing slice lengths. The result is the visible\n// equivalent of watching the user draw the sketch.\n//\n// Why a runtime function instead of an inline useEffect block in the\n// generated source: the orchestrator is ~80 LOC of imperative timing\n// + easing + RAF logic. Inlining it in every page that has a sketch\n// animation buries the page's actual logic. Living in\n// `@revyme/runtime` means the generated source is just one line:\n//\n// useEffect(() => playSketchDraw(el, opts), []);\n//\n// which reads the same way as `withResponsiveProps` / `withCursor`\n// already do for other generated patterns.\n\nimport { getStroke } from 'perfect-freehand';\n\nexport type SketchAnimMode = 'sequential' | 'staggered' | 'simultaneous';\nexport type SketchAnimTrigger = 'mount' | 'inView' | 'hover' | 'tap';\n\nexport interface SketchAnimTransition {\n type: 'tween' | 'spring';\n duration?: number;\n ease?: string;\n stiffness?: number;\n damping?: number;\n mass?: number;\n}\n\nexport interface SketchAnimOpts {\n trigger?: SketchAnimTrigger;\n mode?: SketchAnimMode;\n /** Multiplier on per-stroke duration. Per-stroke duration scales\n * with point count so a long stroke takes longer than a flick;\n * this dials the overall pace. */\n durationScale?: number;\n /** 0–1, only meaningful in staggered mode. 0 = fully sequential,\n * 1 = fully simultaneous. */\n stagger?: number;\n transition?: SketchAnimTransition;\n /** Brush size used for the intermediate-frame outline replay. The\n * final-frame `d` is restored from source so the end state is\n * pixel-exact regardless of this value. */\n brushSize?: number;\n}\n\nconst DEFAULT_OPTS: Required<Omit<SketchAnimOpts, 'transition'>> & { transition: SketchAnimTransition } = {\n trigger: 'inView',\n mode: 'sequential',\n durationScale: 1,\n stagger: 0.5,\n transition: { type: 'tween', duration: 1, ease: 'easeOut' },\n brushSize: 8,\n};\n\nfunction applyEase(t: number, transition: SketchAnimTransition): number {\n if (transition.type === 'spring') {\n const damping = transition.damping ?? 10;\n const stiffness = transition.stiffness ?? 100;\n const dampedT = 1 - Math.exp(-damping * t * 0.1);\n const oscillation = Math.cos(t * Math.sqrt(stiffness) * 0.3);\n return Math.min(1, dampedT * (1 - 0.1 * oscillation * (1 - t)));\n }\n switch (transition.ease ?? 'easeOut') {\n case 'linear': return t;\n case 'easeIn': return t * t;\n case 'easeOut': return 1 - (1 - t) * (1 - t);\n case 'easeInOut': return t < 0.5 ? 2 * t * t : 1 - Math.pow(-2 * t + 2, 2) / 2;\n case 'circIn': return 1 - Math.sqrt(1 - t * t);\n case 'circOut': return Math.sqrt(1 - Math.pow(t - 1, 2));\n case 'backOut': {\n const c1 = 1.70158;\n const c3 = c1 + 1;\n return 1 + c3 * Math.pow(t - 1, 3) + c1 * Math.pow(t - 1, 2);\n }\n default: return 1 - (1 - t) * (1 - t);\n }\n}\n\nfunction parsePoints(raw: string): number[][] {\n if (!raw) return [];\n return raw.split(/\\s+/).filter(Boolean).map(s => {\n const [x, y, p] = s.split(',');\n return [parseFloat(x) || 0, parseFloat(y) || 0, p != null ? parseFloat(p) : 0.5];\n });\n}\n\nfunction outlineToD(outline: number[][]): string {\n if (outline.length === 0) return '';\n let d = `M ${outline[0][0].toFixed(2)} ${outline[0][1].toFixed(2)}`;\n for (let i = 1; i < outline.length; i++) {\n d += ` L ${outline[i][0].toFixed(2)} ${outline[i][1].toFixed(2)}`;\n }\n return d + ' Z';\n}\n\n/**\n * Play a sketch draw animation on the given wrapper SVG. Pass the\n * options the generator emitted in source.\n *\n * Returns a cleanup function — wire as your useEffect's return value\n * so re-mounts cancel an in-flight animation cleanly:\n *\n * useEffect(() => playSketchDraw(svgEl, opts), []);\n *\n * If `wrapperEl` is null or the wrapper has no path children with\n * `data-points`, this is a no-op and returns a noop cleanup.\n */\nexport function playSketchDraw(\n wrapperEl: SVGSVGElement | null,\n userOpts: SketchAnimOpts = {},\n): () => void {\n const noop = () => {};\n if (!wrapperEl) return noop;\n const opts = { ...DEFAULT_OPTS, ...userOpts, transition: { ...DEFAULT_OPTS.transition, ...userOpts.transition } };\n\n const paths = Array.from(wrapperEl.querySelectorAll('path[data-points]')) as SVGPathElement[];\n if (paths.length === 0) return noop;\n\n // Snapshot the final d so the last frame is pixel-exact regardless\n // of the replay-with-default-brush approximation we use during\n // intermediate frames.\n const finalDs = paths.map(p => p.getAttribute('d') || '');\n const pointsList = paths.map(p => parsePoints(p.getAttribute('data-points') || ''));\n\n // Hide everything up front so the first frame doesn't flash.\n paths.forEach(p => p.setAttribute('d', ''));\n\n // Per-stroke duration — point count drives length so a long stroke\n // takes longer than a flick.\n const baseDur = (opts.transition.duration ?? 1) * 1000 * opts.durationScale;\n const maxPoints = pointsList.reduce((m, p) => Math.max(m, p.length), 1);\n const perStrokeDur = pointsList.map(p => baseDur * (p.length / maxPoints));\n const startMs: number[] = [];\n let cursor = 0;\n for (let i = 0; i < paths.length; i++) {\n if (opts.mode === 'simultaneous') {\n startMs.push(0);\n } else if (opts.mode === 'staggered') {\n const overlap = Math.max(0, Math.min(1, opts.stagger));\n const start = i === 0 ? 0 : startMs[i - 1] + perStrokeDur[i - 1] * (1 - overlap);\n startMs.push(start);\n } else {\n // sequential\n startMs.push(cursor);\n cursor += perStrokeDur[i];\n }\n }\n\n let cancelled = false;\n let rafId = 0;\n let started = false;\n let cleanupTrigger: (() => void) | null = null;\n let startTs = 0;\n\n const tick = (now: number) => {\n if (cancelled) return;\n const elapsed = now - startTs;\n let allDone = true;\n for (let i = 0; i < paths.length; i++) {\n const local = elapsed - startMs[i];\n if (local < 0) { allDone = false; continue; }\n const t = Math.min(1, local / Math.max(1, perStrokeDur[i]));\n if (t < 1) allDone = false;\n let d: string;\n if (t >= 1) {\n d = finalDs[i];\n } else {\n const eased = applyEase(t, opts.transition);\n const sliceCount = Math.max(2, Math.floor(pointsList[i].length * eased));\n const subset = pointsList[i].slice(0, sliceCount);\n if (subset.length < 2) {\n d = '';\n } else {\n const outline = getStroke(subset, {\n size: opts.brushSize, thinning: 0.5, smoothing: 0.5, streamline: 0.5,\n });\n d = outlineToD(outline);\n }\n }\n paths[i].setAttribute('d', d);\n }\n if (!allDone) rafId = requestAnimationFrame(tick);\n };\n\n const start = () => {\n if (started) return;\n started = true;\n startTs = performance.now();\n rafId = requestAnimationFrame(tick);\n };\n\n if (opts.trigger === 'inView') {\n const obs = new IntersectionObserver((entries) => {\n if (entries.some(e => e.isIntersecting)) {\n start();\n obs.disconnect();\n }\n }, { threshold: 0.2 });\n obs.observe(wrapperEl);\n cleanupTrigger = () => obs.disconnect();\n } else if (opts.trigger === 'hover') {\n const onEnter = () => start();\n wrapperEl.addEventListener('mouseenter', onEnter);\n cleanupTrigger = () => wrapperEl.removeEventListener('mouseenter', onEnter);\n } else if (opts.trigger === 'tap') {\n const onTap = () => start();\n wrapperEl.addEventListener('click', onTap);\n cleanupTrigger = () => wrapperEl.removeEventListener('click', onTap);\n } else {\n // mount\n start();\n }\n\n return () => {\n cancelled = true;\n cancelAnimationFrame(rafId);\n cleanup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W,IAAK,CAAC;AACtB,MAAI,QAAQ,UAAU;AACtB,yBAAuB,IAAI,YAAY;YAC9B,KAAK,YAAY,SAAS;EACnC,MAAM,gBAAgB,OAAO;AAC7B,YAAU,iBAAiB,cAAc,QAAQ;AACjD,yBAAuB,UAAU,oBAAoB,cAAc,QAAQ;YAClE,KAAK,YAAY,OAAO;EACjC,MAAM,cAAc,OAAO;AAC3B,YAAU,iBAAiB,SAAS,MAAM;AAC1C,yBAAuB,UAAU,oBAAoB,SAAS,MAAM;OAGpE,QAAO;AAGT,cAAa;AACX,cAAY;AACZ,uBAAqB,MAAM;AAC3B,oBAAkB"}
@@ -0,0 +1,60 @@
1
+ import * as React from 'react';
2
+ export type SplitTextScope = {
3
+ query: string;
4
+ } | {
5
+ variant: string;
6
+ };
7
+ /** Structurally `TextAnimConfig` from the builder (canvas-poc/src/editor/tools/
8
+ * AnimationTool/motion/text-anim-presets.ts). Kept in sync by a type-assignability
9
+ * test in canvas-poc — a field added there without a counterpart here fails the build. */
10
+ export interface SplitTextSpec {
11
+ /** STRUCTURAL — resolved from the BASE spec only, never from a scope override, so the
12
+ * emitted tree is identical on server and client. */
13
+ animationType?: 'character' | 'word' | 'line' | 'full';
14
+ /** STRUCTURAL — wraps each unit in an overflow-hidden clip ("cut-off" reveal). */
15
+ mask?: boolean;
16
+ trigger?: 'view' | 'scroll';
17
+ /** Scroll mode only — viewport position (% from top) where the reveal starts / completes. */
18
+ scrollStart?: number;
19
+ scrollEnd?: number;
20
+ opacity?: number;
21
+ scale?: number;
22
+ blur?: number;
23
+ rotateX?: number;
24
+ rotateY?: number;
25
+ rotateZ?: number;
26
+ skewX?: number;
27
+ skewY?: number;
28
+ /** Strings keep their unit. '100%' resolves against the unit's OWN box, which is what
29
+ * makes a masked reveal correct at every type size — a px offset masks correctly at
30
+ * one breakpoint only. */
31
+ x?: number | string;
32
+ y?: number | string;
33
+ /** Stagger between units, seconds. */
34
+ delay?: number;
35
+ transition?: {
36
+ type?: 'spring' | 'tween';
37
+ stiffness?: number;
38
+ damping?: number;
39
+ mass?: number;
40
+ duration?: number;
41
+ bounce?: number;
42
+ ease?: string | number[];
43
+ /** Initial delay before the first unit, seconds. */
44
+ delay?: number;
45
+ };
46
+ /** Per-viewport / per-variant value overrides. First match wins (matches the builder's
47
+ * `resolveTextAnimForScope`). Structural fields in an override are ignored. */
48
+ responsive?: Array<{
49
+ scope: SplitTextScope;
50
+ config: Partial<SplitTextSpec>;
51
+ }>;
52
+ }
53
+ export interface RevymeSplitTextProps {
54
+ spec?: SplitTextSpec;
55
+ /** Active component variant — only needed when `spec.responsive` has `{variant}` scopes. */
56
+ variant?: string;
57
+ children?: React.ReactNode;
58
+ }
59
+ export declare function RevymeSplitText({ spec, variant, children }: RevymeSplitTextProps): React.ReactElement;
60
+ export default RevymeSplitText;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revyme/runtime",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -38,4 +38,4 @@
38
38
  "typescript": "^5.9.3",
39
39
  "vite": "^8.0.1"
40
40
  }
41
- }
41
+ }
package/src/index.ts CHANGED
@@ -21,6 +21,12 @@ export {
21
21
  type CursorOpts,
22
22
  } from './cursor-runtime';
23
23
  export { useStaticCanvas } from './useStaticCanvas';
24
+ export {
25
+ RevymeSplitText,
26
+ type SplitTextSpec,
27
+ type SplitTextScope,
28
+ type RevymeSplitTextProps,
29
+ } from './split-text';
24
30
  export {
25
31
  playSketchDraw,
26
32
  type SketchAnimOpts,
@@ -0,0 +1,369 @@
1
+ 'use client';
2
+
3
+ // split-text.tsx — `<RevymeSplitText>`: the runtime half of Revyme's Text effect.
4
+ //
5
+ // WHY THIS EXISTS (2026-07-31). Text effects used to be split at CODEGEN time: the
6
+ // generator wrote N `<motion.span>` elements — one per character — straight into the
7
+ // user's page source. That cannot work for text that isn't known until render:
8
+ // `{item.title}` from a CMS row, `{t('key')}` from i18n, `{propName}` from a component
9
+ // variable. The generator saw an expression, not a string, and escaped it per character
10
+ // into `&#123;item.title&#125;`, so every CMS row rendered the literal text `{item.title}`.
11
+ //
12
+ // Splitting at RENDER time removes the whole class of problem: by the time this component
13
+ // runs, `children` is already the resolved string. It also collapses ~600 lines of
14
+ // generator (four span builders, scroll-hook injection, canvas dormancy) into one prop.
15
+ //
16
+ // HARD CONSTRAINT — the split must be a PURE function of props, computed DURING RENDER.
17
+ // Published sites are SSR'd; a split deferred to an effect would emit a bare string on the
18
+ // server and spans on the client, i.e. a hydration mismatch. Nothing here measures the DOM
19
+ // or reads `window` outside an effect/lazy-initialiser.
20
+
21
+ import * as React from 'react';
22
+ import { motion, useInView, useScroll, useTransform, type MotionValue } from 'framer-motion';
23
+
24
+ // ─── Spec ────────────────────────────────────────────────────────────────────
25
+
26
+ export type SplitTextScope = { query: string } | { variant: string };
27
+
28
+ /** Structurally `TextAnimConfig` from the builder (canvas-poc/src/editor/tools/
29
+ * AnimationTool/motion/text-anim-presets.ts). Kept in sync by a type-assignability
30
+ * test in canvas-poc — a field added there without a counterpart here fails the build. */
31
+ export interface SplitTextSpec {
32
+ /** STRUCTURAL — resolved from the BASE spec only, never from a scope override, so the
33
+ * emitted tree is identical on server and client. */
34
+ animationType?: 'character' | 'word' | 'line' | 'full';
35
+ /** STRUCTURAL — wraps each unit in an overflow-hidden clip ("cut-off" reveal). */
36
+ mask?: boolean;
37
+ trigger?: 'view' | 'scroll';
38
+ /** Scroll mode only — viewport position (% from top) where the reveal starts / completes. */
39
+ scrollStart?: number;
40
+ scrollEnd?: number;
41
+ opacity?: number;
42
+ scale?: number;
43
+ blur?: number;
44
+ rotateX?: number;
45
+ rotateY?: number;
46
+ rotateZ?: number;
47
+ skewX?: number;
48
+ skewY?: number;
49
+ /** Strings keep their unit. '100%' resolves against the unit's OWN box, which is what
50
+ * makes a masked reveal correct at every type size — a px offset masks correctly at
51
+ * one breakpoint only. */
52
+ x?: number | string;
53
+ y?: number | string;
54
+ /** Stagger between units, seconds. */
55
+ delay?: number;
56
+ transition?: {
57
+ type?: 'spring' | 'tween';
58
+ stiffness?: number;
59
+ damping?: number;
60
+ mass?: number;
61
+ duration?: number;
62
+ bounce?: number;
63
+ ease?: string | number[];
64
+ /** Initial delay before the first unit, seconds. */
65
+ delay?: number;
66
+ };
67
+ /** Per-viewport / per-variant value overrides. First match wins (matches the builder's
68
+ * `resolveTextAnimForScope`). Structural fields in an override are ignored. */
69
+ responsive?: Array<{ scope: SplitTextScope; config: Partial<SplitTextSpec> }>;
70
+ }
71
+
72
+ export interface RevymeSplitTextProps {
73
+ spec?: SplitTextSpec;
74
+ /** Active component variant — only needed when `spec.responsive` has `{variant}` scopes. */
75
+ variant?: string;
76
+ children?: React.ReactNode;
77
+ }
78
+
79
+ // ─── Helpers ─────────────────────────────────────────────────────────────────
80
+
81
+ const WRAP_PLAIN: React.CSSProperties = { whiteSpace: 'nowrap' };
82
+ /** paddingBottom/marginBottom cancel out — zero layout cost. The padding keeps descenders
83
+ * (g, y, p) from being shaved by the clip AND leaves the sliver IntersectionObserver needs
84
+ * when a unit is offset a full 100% (otherwise it sits entirely outside the clip). */
85
+ const WRAP_MASK: React.CSSProperties = {
86
+ whiteSpace: 'nowrap', display: 'inline-block', overflow: 'hidden',
87
+ paddingBottom: '0.14em', marginBottom: '-0.14em',
88
+ };
89
+
90
+ /** The editor persists a custom cubic-bezier as the STRING "[0.22, 1, 0.36, 1]" (that's what
91
+ * the TransitionPanel curve editor writes). framer accepts a named easing or a real array —
92
+ * handed the string it throws `Invalid easing type` and unmounts the tree. Codegen normalises
93
+ * this too; the runtime keeps it so hand-written source still works. */
94
+ function normalizeEase(e: string | number[] | undefined): string | number[] | undefined {
95
+ if (e === undefined || Array.isArray(e)) return e;
96
+ const s = String(e).trim();
97
+ if (!s.startsWith('[')) return s;
98
+ const n = s.replace(/[[\]]/g, '').split(',').map((v) => parseFloat(v.trim()));
99
+ return n.length === 4 && n.every(Number.isFinite) ? n : undefined;
100
+ }
101
+
102
+ /** Collapse React children to a plain string, or null when they can't be split.
103
+ *
104
+ * `null` (a real element child — a styled `<span>` mark, an icon) means "render verbatim,
105
+ * unsplit" rather than mangling rich content. Everything the generator used to normalise at
106
+ * build time — `{item.title}`, `{t('key')}`, `{"a\nb"}`, `a<br/>b` — arrives here already
107
+ * resolved to a string or a `<br />`, so one function covers all of it. */
108
+ function flattenToText(node: React.ReactNode): string | null {
109
+ if (node === null || node === undefined || node === false || node === true) return '';
110
+ if (typeof node === 'string') return node;
111
+ if (typeof node === 'number') return String(node);
112
+ if (Array.isArray(node)) {
113
+ let out = '';
114
+ for (const child of node) {
115
+ const part = flattenToText(child);
116
+ if (part === null) return null;
117
+ out += part;
118
+ }
119
+ return out;
120
+ }
121
+ if (React.isValidElement(node)) {
122
+ const type = (node as React.ReactElement).type;
123
+ if (type === 'br') return '\n';
124
+ if (type === React.Fragment) return flattenToText((node.props as any)?.children);
125
+ return null; // a real element → not splittable
126
+ }
127
+ return null;
128
+ }
129
+
130
+ /** Active `responsive` entry index, or -1 for the base spec.
131
+ *
132
+ * The `matchMedia` read is a LAZY useState initialiser, not a post-mount effect: framer
133
+ * captures `initial` once at mount, so starting at `false` and correcting later makes the
134
+ * responsive branch permanently lose to the base. Same shape as the builder's generated
135
+ * `useMediaQuery` (canvas-poc/src/code/generation/scoped-expr.ts). */
136
+ function useActiveScopeIndex(spec: SplitTextSpec, variant?: string): number {
137
+ const entries = spec.responsive;
138
+ const compute = React.useCallback((): number => {
139
+ if (!entries || entries.length === 0) return -1;
140
+ for (let i = 0; i < entries.length; i++) {
141
+ const scope = entries[i].scope;
142
+ if ('variant' in scope) {
143
+ if (variant !== undefined && scope.variant === variant) return i;
144
+ } else if (typeof window !== 'undefined' && typeof window.matchMedia === 'function') {
145
+ if (window.matchMedia(scope.query).matches) return i;
146
+ }
147
+ }
148
+ return -1;
149
+ }, [entries, variant]);
150
+
151
+ const [idx, setIdx] = React.useState(compute);
152
+
153
+ React.useEffect(() => {
154
+ setIdx(compute());
155
+ if (!entries || typeof window === 'undefined' || typeof window.matchMedia !== 'function') return;
156
+ const lists = entries
157
+ .map((e) => ('query' in e.scope ? window.matchMedia(e.scope.query) : null))
158
+ .filter(Boolean) as MediaQueryList[];
159
+ if (lists.length === 0) return;
160
+ const onChange = () => setIdx(compute());
161
+ for (const l of lists) l.addEventListener('change', onChange);
162
+ return () => { for (const l of lists) l.removeEventListener('change', onChange); };
163
+ }, [entries, compute]);
164
+
165
+ return idx;
166
+ }
167
+
168
+ const RESTING: Record<string, number> = { opacity: 1, scale: 1, rotateX: 0, rotateY: 0, rotateZ: 0, skewX: 0, skewY: 0, x: 0, y: 0 };
169
+ const CHANNELS = ['opacity', 'scale', 'rotateX', 'rotateY', 'rotateZ', 'skewX', 'skewY', 'x', 'y'] as const;
170
+
171
+ /** The animated-from state. Mirrors the builder's `buildHiddenState`: a channel is animated
172
+ * only when the spec sets it to something other than its resting value. */
173
+ function hiddenState(s: SplitTextSpec): Record<string, any> {
174
+ const out: Record<string, any> = {};
175
+ for (const k of CHANNELS) {
176
+ const v = s[k];
177
+ if (v !== undefined && v !== RESTING[k]) out[k] = v;
178
+ }
179
+ if (s.blur !== undefined && s.blur !== 0) out.filter = `blur(${s.blur}px)`;
180
+ return out;
181
+ }
182
+
183
+ function visibleState(s: SplitTextSpec): Record<string, any> {
184
+ const out: Record<string, any> = {};
185
+ for (const k of CHANNELS) {
186
+ const v = s[k];
187
+ if (v !== undefined && v !== RESTING[k]) out[k] = RESTING[k];
188
+ }
189
+ if (s.blur !== undefined && s.blur !== 0) out.filter = 'blur(0px)';
190
+ return out;
191
+ }
192
+
193
+ /** `'100%'` → `'0%'`, `24` → `0`. Keeps the unit so a percentage offset scrubs correctly. */
194
+ function restingOf(from: number | string, key: string): number | string {
195
+ if (typeof from === 'number') return RESTING[key] ?? 0;
196
+ const m = String(from).match(/^(-?[\d.]+)(.*)$/);
197
+ return m ? `${RESTING[key] ?? 0}${m[2]}` : (RESTING[key] ?? 0);
198
+ }
199
+
200
+ interface Unit { key: string; inner: string; display: 'inline-block' | 'block'; index: number }
201
+
202
+ type Node = { t: 'unit'; u: Unit } | { t: 'br'; k: string } | { t: 'text'; k: string; v: string }
203
+ | { t: 'wrap'; k: string; kids: Node[] };
204
+
205
+ /** Split `text` into render nodes. Structure mirrors the old codegen splitter exactly, so the
206
+ * emitted DOM is unchanged from the build-time era. Keys are pure functions of index → SSR
207
+ * and CSR agree. */
208
+ function buildNodes(text: string, animationType: SplitTextSpec['animationType'], mask: boolean): { nodes: Node[]; count: number } {
209
+ const nodes: Node[] = [];
210
+ let i = 0;
211
+ const lines = text.split('\n');
212
+
213
+ if (animationType === 'line') {
214
+ for (let li = 0; li < lines.length; li++) {
215
+ if (li > 0) nodes.push({ t: 'br', k: `br${li}` });
216
+ nodes.push({ t: 'unit', u: { key: `u${i}`, inner: lines[li], display: 'block', index: i } });
217
+ i++;
218
+ }
219
+ return { nodes, count: i };
220
+ }
221
+ if (animationType === 'full') {
222
+ nodes.push({ t: 'unit', u: { key: 'u0', inner: text, display: 'inline-block', index: 0 } });
223
+ return { nodes, count: 1 };
224
+ }
225
+
226
+ for (let li = 0; li < lines.length; li++) {
227
+ if (li > 0) nodes.push({ t: 'br', k: `br${li}` });
228
+ const words = lines[li].split(' ');
229
+ for (let wi = 0; wi < words.length; wi++) {
230
+ if (wi > 0) nodes.push({ t: 'text', k: `sp${li}-${wi}`, v: ' ' });
231
+ const word = words[wi];
232
+ if (!word) continue;
233
+ if (animationType === 'word') {
234
+ const u: Node = { t: 'unit', u: { key: `u${i}`, inner: word, display: 'inline-block', index: i } };
235
+ i++;
236
+ nodes.push(mask ? { t: 'wrap', k: `w${li}-${wi}`, kids: [u] } : u);
237
+ } else {
238
+ const kids: Node[] = [];
239
+ for (const ch of word) {
240
+ kids.push({ t: 'unit', u: { key: `u${i}`, inner: ch, display: 'inline-block', index: i } });
241
+ i++;
242
+ }
243
+ nodes.push({ t: 'wrap', k: `w${li}-${wi}`, kids });
244
+ }
245
+ }
246
+ }
247
+ return { nodes, count: i };
248
+ }
249
+
250
+ // ─── Scroll unit ─────────────────────────────────────────────────────────────
251
+
252
+ /** One scroll-scrubbed unit. Split into its own component because `useTransform` must be
253
+ * called once per animated channel and that count is data-driven — calling them in a loop
254
+ * inside the parent would violate the rules of hooks. The parent keys each instance by a
255
+ * channel fingerprint, so a spec change REMOUNTS rather than reordering hooks. */
256
+ function ScrollUnit({ progress, range, channels, display, children }: {
257
+ progress: MotionValue<number>;
258
+ range: [number, number];
259
+ channels: Array<{ key: string; from: number | string; to: number | string }>;
260
+ display: string;
261
+ children: React.ReactNode;
262
+ }) {
263
+ const style: Record<string, any> = { display };
264
+ for (const c of channels) {
265
+ // eslint-disable-next-line react-hooks/rules-of-hooks -- count is fixed per mount; see above
266
+ style[c.key] = useTransform(progress, range, [c.from as never, c.to as never]);
267
+ }
268
+ return <motion.span style={style as React.CSSProperties}>{children}</motion.span>;
269
+ }
270
+
271
+ // ─── Component ───────────────────────────────────────────────────────────────
272
+
273
+ export function RevymeSplitText({ spec, variant, children }: RevymeSplitTextProps): React.ReactElement {
274
+ const base: SplitTextSpec = spec ?? {};
275
+ const hostRef = React.useRef<HTMLSpanElement>(null);
276
+
277
+ const scopeIdx = useActiveScopeIndex(base, variant);
278
+ const resolved: SplitTextSpec = React.useMemo(() => {
279
+ const r = scopeIdx >= 0 && base.responsive
280
+ ? { ...base, ...base.responsive[scopeIdx].config }
281
+ : base;
282
+ // Structural fields come from the BASE, always — the tree must not depend on a scope,
283
+ // or server and client can disagree about the DOM (not just about style values).
284
+ return { ...r, animationType: base.animationType, mask: base.mask, responsive: base.responsive };
285
+ }, [base, scopeIdx]);
286
+
287
+ const animationType = base.animationType ?? 'character';
288
+ const mask = !!base.mask;
289
+ const text = flattenToText(children);
290
+
291
+ // ONE observer for the whole run, not one per character. Besides being N× cheaper, this
292
+ // structurally avoids the deadlock the per-character form had: a masked unit offset out of
293
+ // its own overflow-hidden clip has intersection ratio 0 and never fires.
294
+ const inView = useInView(hostRef, { once: true, amount: 0 });
295
+
296
+ // Called unconditionally so the hook count never changes when a scope flips view↔scroll.
297
+ const startFrac = Math.min(1, Math.max(0, (resolved.scrollStart ?? 90) / 100));
298
+ const endFrac = Math.min(1, Math.max(0, (resolved.scrollEnd ?? 35) / 100));
299
+ const { scrollYProgress } = useScroll({
300
+ target: hostRef,
301
+ offset: [`start ${startFrac}`, `start ${endFrac}`] as never,
302
+ });
303
+
304
+ const { nodes, count } = React.useMemo(
305
+ () => buildNodes(text ?? '', animationType, mask),
306
+ [text, animationType, mask],
307
+ );
308
+
309
+ // Not splittable (a styled span, an icon) → render verbatim rather than mangling it.
310
+ if (text === null) return <span ref={hostRef}>{children}</span>;
311
+
312
+ const isScroll = resolved.trigger === 'scroll';
313
+ const hidden = hiddenState(resolved);
314
+ const visible = visibleState(resolved);
315
+ const stagger = resolved.delay ?? 0.05;
316
+ const initialDelay = resolved.transition?.delay ?? 0;
317
+ const tr = resolved.transition
318
+ ? { ...resolved.transition, ease: normalizeEase(resolved.transition.ease), delay: undefined } as any
319
+ : { type: 'spring' as const, stiffness: 300, damping: 30 } as any;
320
+
321
+ const channels = isScroll
322
+ ? Object.entries(hidden).map(([key, from]) => ({
323
+ key,
324
+ from: from as number | string,
325
+ to: key === 'filter' ? 'blur(0px)' : restingOf(from as number | string, key),
326
+ }))
327
+ : [];
328
+ const fingerprint = channels.map((c) => c.key).join('|');
329
+
330
+ const renderUnit = (u: Unit): React.ReactElement => {
331
+ if (isScroll) {
332
+ const start = count > 1 ? Math.round((u.index / (count - 1)) * 0.6 * 1000) / 1000 : 0;
333
+ const end = Math.min(1, Math.round((start + 0.4) * 1000) / 1000);
334
+ return (
335
+ <ScrollUnit
336
+ key={`${fingerprint}#${u.key}`}
337
+ progress={scrollYProgress}
338
+ range={[start, end]}
339
+ channels={channels}
340
+ display={u.display}
341
+ >{u.inner}</ScrollUnit>
342
+ );
343
+ }
344
+ return (
345
+ <motion.span
346
+ key={u.key}
347
+ style={{ display: u.display }}
348
+ initial={hidden}
349
+ animate={inView ? visible : hidden}
350
+ transition={{ ...tr, delay: Math.round((initialDelay + u.index * stagger) * 1000) / 1000 }}
351
+ >{u.inner}</motion.span>
352
+ );
353
+ };
354
+
355
+ const render = (n: Node): React.ReactNode => {
356
+ if (n.t === 'br') return <br key={n.k} />;
357
+ if (n.t === 'text') return n.v;
358
+ if (n.t === 'wrap') return <span key={n.k} style={mask ? WRAP_MASK : WRAP_PLAIN}>{n.kids.map(render)}</span>;
359
+ return renderUnit(n.u);
360
+ };
361
+
362
+ return (
363
+ <span ref={hostRef} style={{ display: animationType === 'line' ? 'block' : 'inline' }}>
364
+ {nodes.map(render)}
365
+ </span>
366
+ );
367
+ }
368
+
369
+ export default RevymeSplitText;
@@ -137,6 +137,17 @@ export default function withResponsiveProps<P extends Record<string, any>>(
137
137
  // definite dims; the guard keeps an unsized axis hugging content).
138
138
  if ('width' in wrapperStyle) innerStyle.width = '100%';
139
139
  if ('height' in wrapperStyle) innerStyle.height = '100%';
140
+ // The wrapper OWNS the instance's slot (all placement keys moved onto
141
+ // it) — the inner root must re-base INTO the wrapper. Design-component
142
+ // masters bake `position: 'absolute'` on their root (canvas master
143
+ // tiling) and rely on the instance style overriding it via the trailing
144
+ // `...style` spread; with the split the position key never reaches them,
145
+ // so the root absolute-positioned inside a zero-size wrapper and
146
+ // vanished (live find 2026-07-28: Sign Up button instance inside an
147
+ // AnimatePresence popLayout header — popLayout's ref forces the
148
+ // wrapper). Position is a PLACEMENT key, so innerStyle can never carry
149
+ // its own — always re-base.
150
+ innerStyle.position = 'relative';
140
151
  const { style: _split, ...rest } = mergedProps;
141
152
  delete rest.ref; // React 19 passes `ref` as a prop — never forward it inward
142
153
  return (