@vanillaskyai/video 0.10.22 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/CHANGELOG.md +74 -1
  2. package/PUBLIC-API.md +45 -438
  3. package/README.md +57 -96
  4. package/dist/builtin-metadata-OT6V7TB4.js +8 -0
  5. package/dist/{chapter-title-2JVDU62E.js → chapter-title-2RCXX7SN.js} +1 -2
  6. package/dist/{chunk-PDQFQIQW.js → chunk-3EQ6PVWL.js} +1 -1
  7. package/dist/chunk-4G4JBMCM.js +37 -0
  8. package/dist/{chunk-7AA2JWHZ.js → chunk-5DOQTIMD.js} +6 -6
  9. package/dist/chunk-666HGTVZ.js +41 -0
  10. package/dist/{chunk-7M56IUUX.js → chunk-6Z3ID54H.js} +0 -18
  11. package/dist/{chunk-5BSJLT6H.js → chunk-E7FHBLAC.js} +16 -29
  12. package/dist/chunk-HIQM4J3U.js +30 -0
  13. package/dist/chunk-ISWQ6T5X.js +36 -0
  14. package/dist/{chunk-224QNWRA.js → chunk-K5J7ESRO.js} +1 -10
  15. package/dist/chunk-KMVRBUL5.js +50 -0
  16. package/dist/chunk-NM4CXXZY.js +25 -0
  17. package/dist/{chunk-44WND2VP.js → chunk-V2CP7PVY.js} +19 -63
  18. package/dist/{chunk-3O7OMMMF.js → chunk-WZESNEPT.js} +0 -1
  19. package/dist/{chunk-RXTN2CW6.js → chunk-Z3DLSLAJ.js} +1 -1
  20. package/dist/cinema-media-YZ2UANJG.js +365 -0
  21. package/dist/cli.js +154 -1753
  22. package/dist/{compose-video-BH5K6XWT.js → compose-video-H2YUQDUY.js} +4 -4
  23. package/dist/{events-B4YCc4vc.d.ts → events-BZAfl0Dm.d.ts} +1 -1
  24. package/dist/index.d.ts +2 -2
  25. package/dist/index.js +4 -6
  26. package/dist/preload-media-23JXUFCF.js +77 -0
  27. package/dist/react.d.ts +39 -15
  28. package/dist/react.js +1350 -739
  29. package/dist/scene-validation-SGLLLFY5.js +9 -0
  30. package/dist/server.d.ts +67 -117
  31. package/dist/server.js +262 -614
  32. package/dist/test.d.ts +2 -2
  33. package/dist/test.js +21 -21
  34. package/dist/{text-stream-LD364KBI.js → text-stream-SOVLYR2L.js} +2 -2
  35. package/dist/{types-BqB8zC9u.d.ts → types-CG-kPI81.d.ts} +3 -1
  36. package/dist/{types-DdZw4GRQ.d.ts → types-ht-Zw3Wv.d.ts} +1 -1
  37. package/docs/agent-integration.md +19 -64
  38. package/docs/architecture.md +82 -87
  39. package/docs/customization.md +49 -66
  40. package/docs/development.md +18 -17
  41. package/docs/errors.md +4 -4
  42. package/docs/getting-started.md +74 -93
  43. package/docs/media-and-audio.md +9 -7
  44. package/docs/performance.md +11 -6
  45. package/docs/persistence.md +3 -7
  46. package/docs/production.md +4 -15
  47. package/docs/prompt-and-input.md +1 -2
  48. package/docs/provider-integration.md +134 -181
  49. package/docs/reference/protocol.md +5 -14
  50. package/docs/reference/provider-adapters.md +21 -13
  51. package/docs/security.md +1 -14
  52. package/docs/testing.md +56 -123
  53. package/package.json +5 -27
  54. package/starters/video-chat/.env.example +12 -4
  55. package/starters/video-chat/.env.native.example +13 -0
  56. package/starters/video-chat/README.md +72 -11
  57. package/starters/video-chat/package.json +1 -1
  58. package/starters/video-chat/providers/text-native.ts +94 -0
  59. package/starters/video-chat/providers/text.ts +19 -0
  60. package/starters/video-chat/providers/transcription.ts +32 -0
  61. package/starters/video-chat/providers/video-custom.ts +45 -0
  62. package/starters/video-chat/providers/video-delivery.ts +57 -0
  63. package/starters/video-chat/providers/video-google.ts +48 -0
  64. package/starters/video-chat/providers/video-job.ts +103 -0
  65. package/starters/video-chat/providers/video-runway.ts +45 -0
  66. package/starters/video-chat/providers/video.ts +39 -63
  67. package/starters/video-chat/server.ts +3 -29
  68. package/starters/video-chat/vite.config.ts +2 -8
  69. package/styles/video-chat.css +8 -105
  70. package/dist/builtin-server-W4PLJUZ5.js +0 -8
  71. package/dist/catalog-types-WTbLP6Jh.d.ts +0 -78
  72. package/dist/check-runtime.d.ts +0 -15
  73. package/dist/check-runtime.js +0 -96
  74. package/dist/chunk-2E6T633S.js +0 -27
  75. package/dist/chunk-4YM2M62S.js +0 -13
  76. package/dist/chunk-4ZJLPHBV.js +0 -684
  77. package/dist/chunk-5JBMYQP6.js +0 -156
  78. package/dist/chunk-73NTSFFI.js +0 -81
  79. package/dist/chunk-EGVQODKU.js +0 -83
  80. package/dist/chunk-HFVNAPHZ.js +0 -35
  81. package/dist/chunk-IIN5M5HW.js +0 -697
  82. package/dist/chunk-IQMYK5DX.js +0 -133
  83. package/dist/chunk-IR44XKBI.js +0 -46
  84. package/dist/chunk-JKVOBTRO.js +0 -145
  85. package/dist/chunk-LVM5Q2DL.js +0 -68
  86. package/dist/chunk-M4QTEJTK.js +0 -709
  87. package/dist/chunk-QSBDB4J2.js +0 -16
  88. package/dist/chunk-R3XAOMKP.js +0 -29
  89. package/dist/chunk-SPVTJH3F.js +0 -24
  90. package/dist/chunk-YAHT3LST.js +0 -663
  91. package/dist/chunk-ZD2VTUYR.js +0 -28
  92. package/dist/cinema-media-HYCDG65Z.js +0 -11
  93. package/dist/comparison-XXAP4S4J.js +0 -36
  94. package/dist/editorial-timeline-VUQC6KPA.js +0 -42
  95. package/dist/key-figure-4TJK7HLT.js +0 -29
  96. package/dist/kit-DrRpdn0p.d.ts +0 -79
  97. package/dist/mobile-message-FIHAO6XC.js +0 -49
  98. package/dist/preload-media-LJXWKTWG.js +0 -57
  99. package/dist/quote-GRPIYKQJ.js +0 -32
  100. package/dist/system-prompt-AG26KJAA.js +0 -12
  101. package/dist/template-catalog.d.ts +0 -400
  102. package/dist/template-catalog.js +0 -6
  103. package/dist/templates.d.ts +0 -25
  104. package/dist/templates.js +0 -102
  105. package/dist/validate-4OUD2CLX.js +0 -10
  106. package/docs/concepts.md +0 -107
  107. package/docs/custom-templates.md +0 -346
  108. package/docs/immersive-interface.md +0 -86
  109. package/docs/maintainers/cinematic-migration.md +0 -38
  110. package/docs/motion-and-effects.md +0 -109
  111. package/docs/reference/design-system.html +0 -125
  112. package/docs/responsive-orientation.md +0 -37
  113. package/docs/streaming-protocol.md +0 -15
  114. package/examples/custom-template/README.md +0 -19
  115. package/examples/custom-template/minimal-text.tsx +0 -82
  116. package/examples/custom-template/structured-data.tsx +0 -104
  117. package/registry/items/backgrounds.json +0 -70
  118. package/registry/items/chapterTitle.json +0 -80
  119. package/registry/items/cinemaMedia.json +0 -136
  120. package/registry/items/comparison.json +0 -168
  121. package/registry/items/editorialTimeline.json +0 -172
  122. package/registry/items/keyFigure.json +0 -162
  123. package/registry/items/mobileMessage.json +0 -153
  124. package/registry/items/motion.json +0 -45
  125. package/registry/items/quote.json +0 -161
  126. package/registry/items/template-context.json +0 -31
  127. package/registry/items/theme.json +0 -47
  128. package/registry/items/typography.json +0 -47
@@ -1,47 +0,0 @@
1
- {
2
- "$schema": "https://ui.shadcn.com/schema/registry-item.json",
3
- "name": "typography",
4
- "type": "registry:lib",
5
- "title": "Typography",
6
- "description": "Fit text to a fixed frame and give it a complete kinetic lifecycle.",
7
- "registryDependencies": [
8
- "@vanillasky/motion"
9
- ],
10
- "files": [
11
- {
12
- "path": "src/visual-system/typography/index.ts",
13
- "type": "registry:lib",
14
- "target": "vanillasky/typography/index.ts",
15
- "content": "/** Text fitting, formatting, timing, and kinetic type lifecycles. */\nexport * from \"../scene-templates/text-utils\";\nexport * from \"../scene-templates/text-archetypes\";\n"
16
- },
17
- {
18
- "path": "src/visual-system/scene-templates/text-archetypes.ts",
19
- "type": "registry:lib",
20
- "target": "vanillasky/scene-templates/text-archetypes.ts",
21
- "content": "/**\n * Text archetypes — 7 complete lifecycles (entrance + hold + exit).\n *\n * Each archetype is a single named effect that owns its full lifecycle: how\n * text arrives, how it sits, how it leaves. The AI picks one name and that's\n * the whole package.\n *\n * Motion design principles applied per archetype:\n * - Distinct easing per phase (entrance ≠ exit, archetype-tuned)\n * - Anticipation / overshoot where the role calls for it\n * - Hold-phase breathing — no dead frames, ever\n * - Compound motion — multiple properties (scale, opacity, translate,\n * letter-spacing) move together with subtle offsets\n * - Exits are absolute-timed (in seconds), not a fixed % of scene, so\n * motion stays readable on long scenes too\n *\n * Filter:blur is unavailable (template determinism), so depth illusions are\n * carried by scale magnitude + letter-spacing + opacity ramp shape.\n */\n\nimport {\n interpolate,\n spring,\n Easing,\n SPRING_CRISP,\n} from \"../motion\";\n\n// ─── Archetype names ────────────────────────────────────────────\n\nexport const TEXT_ARCHETYPES = [\n \"subtle\",\n \"typewriter\",\n \"wordStagger\",\n \"slam\",\n \"cinematic\",\n \"heroWord\",\n] as const;\n\nexport type TextArchetype = (typeof TEXT_ARCHETYPES)[number];\nexport type TextCanvas = \"tight\" | \"open\";\nexport type TextRole = \"hook\" | \"body\" | \"closer\";\n\n/**\n * Normalize an input to a valid TextArchetype. Handles:\n * - undefined / null / empty → \"subtle\"\n * - already-valid archetype name → unchanged\n * - unknown string → \"subtle\" fallback\n */\nexport function normalizeArchetype(input: unknown): TextArchetype {\n if (typeof input !== \"string\" || input.length === 0) return \"subtle\";\n if ((TEXT_ARCHETYPES as readonly string[]).includes(input)) return input as TextArchetype;\n return \"subtle\";\n}\n\n// ─── Spec data ──────────────────────────────────────────────────\n\nexport interface ArchetypeSpec {\n name: TextArchetype;\n description: string;\n /** Entrance phase duration in seconds. */\n entrance: number;\n /** Exit phase duration in seconds. */\n exit: number;\n /** Where this archetype is allowed to run. */\n allowedCanvas: TextCanvas[];\n /** Suggested role(s) in the video arc. */\n roles: TextRole[];\n /** Font-size multiplier envelope vs. the slot's natural body size. */\n sizeRange: [number, number];\n /**\n * Minimum DURATION the effect itself needs (seconds), with SHORT text.\n * For text-dependent archetypes (typewriter, wordStagger, heroWord) the\n * actual minimum scales with content length — use `minDurationFor()` for\n * an accurate per-text computation.\n */\n minDuration: number;\n /**\n * Maximum DURATION the effect itself uses (seconds). On a longer scene,\n * the effect runs for at most this long, then disappears — leaving the\n * remaining scene time for the AI to fill with another effect. Prevents\n * \"ages to build up\" on long scenes.\n *\n * If text is so long that `minDurationFor()` exceeds this value, the\n * minimum wins (text needs the time).\n */\n maxDuration: number;\n}\n\n// Timings tuned to research findings (Material 3 motion tokens, AE motion-design\n// conventions, \"exits faster than entrances by 60–75%\" rule). Values target\n// 2.5s scene by default; phase math scales for longer scenes.\nexport const ARCHETYPE_SPECS: Record<TextArchetype, ArchetypeSpec> = {\n subtle: {\n name: \"subtle\",\n description: \"Quiet caption. Visual is the star, text supports.\",\n entrance: 0.5,\n exit: 0.7,\n allowedCanvas: [\"tight\", \"open\"],\n roles: [\"body\", \"closer\"],\n sizeRange: [0.7, 1.0],\n minDuration: 1.5,\n maxDuration: 5,\n },\n typewriter: {\n name: \"typewriter\",\n description: \"Char-by-char reveal with blinking cursor. Slide-left cascade exit, top line first.\",\n entrance: 1.2,\n exit: 0.85,\n allowedCanvas: [\"tight\", \"open\"],\n roles: [\"body\", \"hook\"],\n sizeRange: [0.8, 1.0],\n minDuration: 1.8,\n maxDuration: 6,\n },\n wordStagger: {\n name: \"wordStagger\",\n description: \"Sequential word build with active-word focus. Slide-left cascade exit, top line first.\",\n entrance: 1.4,\n exit: 0.7,\n allowedCanvas: [\"tight\", \"open\"],\n roles: [\"body\"],\n sizeRange: [0.8, 1.0],\n minDuration: 1.8,\n maxDuration: 6,\n },\n slam: {\n name: \"slam\",\n description: \"In-place impact with violent squash-and-stretch, frame shake, and letter crunch.\",\n entrance: 0.5,\n exit: 0.5,\n allowedCanvas: [\"tight\", \"open\"],\n roles: [\"hook\", \"body\"],\n sizeRange: [0.9, 1.2],\n minDuration: 1.2,\n maxDuration: 4,\n },\n cinematic: {\n name: \"cinematic\",\n description: \"Trailer FlyIn from depth → recedes back into background.\",\n entrance: 0.7,\n exit: 0.8,\n allowedCanvas: [\"open\"],\n roles: [\"hook\", \"body\", \"closer\"],\n sizeRange: [0.9, 1.1],\n minDuration: 1.8,\n maxDuration: 6,\n },\n heroWord: {\n name: \"heroWord\",\n description: \"Single word fills frame. Simple fast exit so words get the most time.\",\n entrance: 0.35,\n exit: 0.25,\n allowedCanvas: [\"open\"],\n roles: [\"hook\", \"body\", \"closer\"],\n sizeRange: [2.0, 3.0],\n minDuration: 1.0,\n maxDuration: 5,\n },\n};\n\n// ─── Lifecycle constants ────────────────────────────────────────\n\nconst ENTRANCE_START = 0.02;\n// Phase caps prevent very short scenes from making in/out exceed the scene.\nconst ENTRANCE_PHASE_CAP = 0.4;\nconst EXIT_PHASE_CAP = 0.4;\n\n// ─── Render output shapes ───────────────────────────────────────\n\nexport interface BlockStyle {\n opacity: number;\n transform: string;\n letterSpacing?: string;\n /**\n * `willChange` hint to keep the layer GPU-composited during animation.\n * Used by cinematic where the scale-collapse needs to stay smooth on\n * mobile Safari (which otherwise downgrades the layer mid-animation).\n */\n willChange?: string;\n}\n\nexport interface PerWordStyle {\n text: string;\n style: BlockStyle;\n}\n\nexport type ArchetypeRender =\n | { kind: \"block\"; block: BlockStyle; text: string }\n | {\n kind: \"typewriter\";\n visibleChars: number;\n cursor: boolean;\n opacity: number;\n transform: string;\n /**\n * Per-character exit overrides — present during the exit phase to\n * drive a slide-left cascade in reading order. One entry per char\n * in `text`. Undefined during entrance/hold.\n */\n charExits?: { opacity: number; translateX: number }[];\n }\n | {\n kind: \"words\";\n words: PerWordStyle[];\n blockOpacity: number;\n blockTransform: string;\n }\n | {\n kind: \"hero\";\n word: string;\n index: number;\n total: number;\n opacity: number;\n transform: string;\n letterSpacing?: string;\n };\n\n// ─── Phase + timing helpers ─────────────────────────────────────\n\ninterface Phases {\n entrancePhase: number;\n exitPhase: number;\n exitStart: number;\n inExit: boolean;\n}\n\nfunction computePhases(\n spec: ArchetypeSpec,\n sceneDuration: number,\n progress: number,\n phaseScale = 1,\n): Phases {\n // `phaseScale` is style.motion (calm 1.4 / normal 1 / punchy 0.7). It\n // stretches or compresses how much of the scene the entrance and exit\n // occupy; the caps below still bound them, so a calm video never spends\n // the whole scene animating in.\n const entrancePhase = Math.min(ENTRANCE_PHASE_CAP, (spec.entrance * phaseScale) / sceneDuration);\n const exitPhase = Math.min(EXIT_PHASE_CAP, (spec.exit * phaseScale) / sceneDuration);\n const exitStart = 1 - exitPhase;\n return { entrancePhase, exitPhase, exitStart, inExit: progress >= exitStart };\n}\n\nfunction rawEntrance(progress: number, entrancePhase: number, startAt = ENTRANCE_START): number {\n return interpolate(progress, [startAt, startAt + entrancePhase], [0, 1], {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n });\n}\n\nfunction rawExit(progress: number, exitStart: number): number {\n if (progress < exitStart) return 0;\n return interpolate(progress, [exitStart, 1], [0, 1], {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n });\n}\n\n// Normalized hold time 0→1 over the hold phase; 0 outside.\nfunction holdT(\n progress: number,\n entrancePhase: number,\n exitStart: number,\n startAt = ENTRANCE_START,\n): number {\n const holdStart = startAt + entrancePhase;\n if (progress < holdStart || progress > exitStart || exitStart <= holdStart) return 0;\n return (progress - holdStart) / (exitStart - holdStart);\n}\n\n// Sine breathe — returns offset around 0; magnitude is peak-to-peak.\nfunction breathe(t: number, magnitude: number, cycles = 1): number {\n return (Math.sin(t * Math.PI * 2 * cycles) * magnitude) / 2;\n}\n\n// ─── Renderer ───────────────────────────────────────────────────\n\nexport function renderArchetype(\n archetypeRaw: TextArchetype | string | undefined,\n progress: number,\n scale: number,\n text: string,\n sceneDuration: number,\n /** style.motion's phase multiplier. 1 (the default) is the authored timing. */\n phaseScale = 1,\n /** Optional transition-safe clock for entrance/exit motion only. */\n motionProgress = progress,\n): ArchetypeRender {\n const archetype = normalizeArchetype(archetypeRaw);\n const spec = ARCHETYPE_SPECS[archetype];\n const phases = computePhases(spec, sceneDuration, motionProgress, phaseScale);\n // Semantic reveals stay on raw time even if a custom host supplies a\n // different presentation clock. VideoFrame itself preserves the same\n // complete 0→1 timeline for both clocks.\n const presentationProgress = Math.max(progress, motionProgress);\n\n switch (archetype) {\n case \"subtle\":\n return renderSubtle(motionProgress, scale, text, phases);\n case \"typewriter\":\n return renderTypewriter(presentationProgress, motionProgress, scale, text, phases, sceneDuration);\n case \"wordStagger\":\n return renderWordStagger(presentationProgress, motionProgress, scale, text, sceneDuration);\n case \"slam\":\n return renderSlam(motionProgress, scale, text, phases);\n case \"cinematic\":\n return renderCinematic(motionProgress, scale, text, phases);\n case \"heroWord\":\n return renderHeroWord(presentationProgress, motionProgress, text, phases);\n }\n}\n\n// ─── subtle ─────────────────────────────────────────────────────\n// Pure fade in / fade out — true to the name. No translation, no breathe,\n// no transition jump. The supporting caption that doesn't compete with the\n// visual. Only thing animating is opacity.\nfunction renderSubtle(\n progress: number,\n _scale: number,\n text: string,\n phases: Phases,\n): ArchetypeRender {\n const raw = rawEntrance(progress, phases.entrancePhase);\n const ex = rawExit(progress, phases.exitStart);\n\n const opacityIn = Easing.out(Easing.cubic)(raw);\n const opacityOut = 1 - Easing.in(Easing.cubic)(ex);\n const opacity = opacityIn * (phases.inExit ? opacityOut : 1);\n\n return {\n kind: \"block\",\n block: {\n opacity,\n transform: \"none\",\n },\n text,\n };\n}\n\n// ─── typewriter ─────────────────────────────────────────────────\n// Char reveal with deterministic cursor blink. Exit slides each char off\n// the left edge in reading order — same cascade pattern as wordStagger\n// (top line clears first by virtue of reading-order index ascending).\nfunction renderTypewriter(\n progress: number,\n motionProgress: number,\n scale: number,\n text: string,\n phases: Phases,\n sceneDuration: number,\n): ArchetypeRender {\n const raw = rawEntrance(progress, phases.entrancePhase);\n\n // Constant typing pace — linear, no easing. Decelerating eases make the\n // last chars feel sluggish, which kills the typewriter rhythm.\n const visibleChars = Math.max(0, Math.floor(raw * text.length));\n\n // Time-based 1.5Hz blink (OS terminal convention). Stays consistent\n // regardless of scene length.\n const seconds = progress * sceneDuration;\n const cursorOn = Math.sin(seconds * Math.PI * 3) > 0;\n const stillTyping = visibleChars < text.length;\n\n // Entry opacity ramps fast (we want chars solid as they appear).\n const opacityIn = Math.min(1, raw * 8);\n\n // Cursor visible during typing and the tail of the hold; gone on exit.\n const cursor = cursorOn && (stillTyping || (!phases.inExit && opacityIn > 0.5));\n\n // Per-character exit cascade — slides each char left, staggered by\n // reading-order index. Compresses if the exit window can't fit the full\n // sequence (very long text on a short scene).\n let charExits: { opacity: number; translateX: number }[] | undefined;\n if (phases.inExit && text.length > 0) {\n const STAGGER_OUT = 0.025;\n const PER_CHAR_OUT = 0.30;\n const SLIDE_LEFT_DISTANCE = 350 * scale;\n const actualExitSec = phases.exitPhase * sceneDuration;\n const idealExitSec = (text.length - 1) * STAGGER_OUT + PER_CHAR_OUT;\n const outScale = Math.min(1, actualExitSec / idealExitSec);\n const stagOutNorm = (STAGGER_OUT * outScale) / sceneDuration;\n const perCharOutNorm = (PER_CHAR_OUT * outScale) / sceneDuration;\n\n charExits = Array.from({ length: text.length }, (_, i) => {\n const charExitStart = phases.exitStart + i * stagOutNorm;\n const charExitEnd = charExitStart + perCharOutNorm;\n const charExitRaw = interpolate(motionProgress, [charExitStart, charExitEnd], [0, 1], {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n });\n const charExitEased = Easing.in(Easing.cubic)(charExitRaw);\n return {\n opacity: 1 - charExitEased,\n translateX: -charExitEased * SLIDE_LEFT_DISTANCE,\n };\n });\n }\n\n return {\n kind: \"typewriter\",\n visibleChars,\n cursor,\n opacity: opacityIn,\n transform: \"none\",\n charExits,\n };\n}\n\n// ─── wordStagger ────────────────────────────────────────────────\n// Dynamic entrance: total time depends on word count (more words = more\n// time to read each one), bounded so it doesn't run forever on long scenes\n// or get crammed on short ones. As the NEXT word arrives, prior words dim\n// to ~45% opacity — the kinetic-typography \"active word\" focus.\n// Exit slides each word off the left edge in reading order. Words wrap via\n// CSS so we never know line breaks at render time, but indices ARE in\n// reading order — staggering by index gives a top-line-first cascade for\n// free: words on line 1 occupy the lowest indices, so they exit before\n// any word on line 2.\nfunction renderWordStagger(\n progress: number,\n motionProgress: number,\n scale: number,\n text: string,\n sceneDuration: number,\n): ArchetypeRender {\n const words = text.split(/\\s+/).filter(Boolean);\n const wordCount = Math.max(words.length, 1);\n\n // Per-word timing constants (seconds). Min/max stagger keeps the cadence\n // in the Hollywood-typography sweet spot (~280–450ms per word land)\n // regardless of scene length.\n const STAGGER_MIN = 0.28;\n const STAGGER_MAX = 0.45;\n const PER_WORD_ANIM = 0.5;\n\n // Floor entrance using the minimum stagger.\n const minEntrance = (wordCount - 1) * STAGGER_MIN + PER_WORD_ANIM;\n\n // Target: ~55% of the scene for entrance, so longer scenes get a longer\n // build-up. Without this the entrance feels rushed against the long hold.\n const TARGET_ENTRANCE_FRACTION = 0.55;\n const targetEntrance = sceneDuration * TARGET_ENTRANCE_FRACTION;\n\n // Ceiling: leave room for exit + meaningful hold so the FINAL word sits\n // as the focal point.\n const exitSec = ARCHETYPE_SPECS.wordStagger.exit;\n const minHold = 0.5;\n const maxEntrance = Math.max(0.6, sceneDuration - exitSec - minHold);\n\n // Pick proportional target, bounded by [minEntrance, maxEntrance].\n let entranceSec = Math.min(maxEntrance, Math.max(minEntrance, targetEntrance));\n\n // Cap the implied per-word stagger at STAGGER_MAX so words don't sit too\n // long between lands on very long scenes.\n if (wordCount > 1) {\n const impliedStagger = (entranceSec - PER_WORD_ANIM) / (wordCount - 1);\n if (impliedStagger > STAGGER_MAX) {\n entranceSec = (wordCount - 1) * STAGGER_MAX + PER_WORD_ANIM;\n }\n }\n\n // Recompute phases for this archetype (overrides default phases).\n const entrancePhase = entranceSec / sceneDuration;\n const exitPhase = Math.min(0.4, exitSec / sceneDuration);\n const exitStart = 1 - exitPhase;\n\n // Word entrance window: each word's own animation gets PER_WORD_ANIM\n // seconds, the rest of entrancePhase is the staggered offset distribution.\n const staggerIn =\n wordCount > 1 ? (entranceSec - PER_WORD_ANIM) / (wordCount - 1) / sceneDuration : 0;\n const wordEntranceDur = PER_WORD_ANIM / sceneDuration;\n\n // Per-word exit cadence. STAGGER_OUT is short so words within a single\n // wrapped line clear nearly together — the perceived gap between lines\n // comes from the words *between* line breaks, not the per-word delay.\n // Compress proportionally if the scene's exit window can't fit the full\n // cascade (e.g. very short scene with many words).\n const STAGGER_OUT = 0.06;\n const PER_WORD_OUT = 0.32;\n const SLIDE_LEFT_DISTANCE = 350 * scale;\n const actualExitSec = exitPhase * sceneDuration;\n const idealExitSec = (wordCount - 1) * STAGGER_OUT + PER_WORD_OUT;\n const outScale = Math.min(1, actualExitSec / idealExitSec);\n const stagOutNorm = (STAGGER_OUT * outScale) / sceneDuration;\n const perWordOutNorm = (PER_WORD_OUT * outScale) / sceneDuration;\n\n const ht = holdT(motionProgress, entrancePhase, exitStart);\n\n // Active-word focus: previous words dim to ACTIVE_DIM as the next word\n // arrives — reads as a \"grey\" handoff via opacity reduction, directs\n // attention to the latest word without making prior ones unreadable.\n // Bumped from 0.70 → 0.85: 70% became muddy on busy photo backgrounds\n // (especially mid-tone areas where the dimmed white blends into the bg).\n // 85% keeps the active-word hierarchy while staying legible on media.\n const ACTIVE_DIM = 0.85;\n\n const perWord = words.map((w, i) => {\n // Entrance window for THIS word\n const wordStart = ENTRANCE_START + i * staggerIn;\n const wordEnd = wordStart + wordEntranceDur;\n const wordRaw = interpolate(progress, [wordStart, wordEnd], [0, 1], {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n });\n const sp = spring(wordRaw, SPRING_CRISP);\n const yIn = interpolate(sp, [0, 1], [55 * scale, 0]);\n const rotIn = interpolate(sp, [0, 1], [-3, 0]);\n const opacityIn = Math.min(1, wordRaw * 7);\n\n // Subtle hold breathe (won't even register but keeps each word \"alive\")\n const yBreathe = breathe(ht, 1 * scale, 1) * Math.cos((i / wordCount) * Math.PI);\n\n // Dim instantly when the NEXT word starts entering — tiny 50ms ramp so\n // the transition isn't a hard cut, but visually reads as \"snaps to grey\n // the moment the new word appears.\"\n let dimProgress = 0;\n if (i < words.length - 1) {\n const nextStart = ENTRANCE_START + (i + 1) * staggerIn;\n const SNAP_RAMP = 0.02; // ~50ms at 2.5s scene\n dimProgress = interpolate(progress, [nextStart, nextStart + SNAP_RAMP], [0, 1], {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n });\n }\n const focusOpacity = 1 - dimProgress * (1 - ACTIVE_DIM);\n\n // Per-word exit: each word starts sliding left at exitStart + i*stagOut,\n // accelerates with ease-in-cubic so it feels yanked off-frame.\n const wordExitStart = exitStart + i * stagOutNorm;\n const wordExitEnd = wordExitStart + perWordOutNorm;\n const wordExitRaw = interpolate(motionProgress, [wordExitStart, wordExitEnd], [0, 1], {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n });\n const wordExitEased = Easing.in(Easing.cubic)(wordExitRaw);\n const exitX = -wordExitEased * SLIDE_LEFT_DISTANCE;\n const isExiting = wordExitRaw > 0;\n\n // Final composition\n const opacity = opacityIn * focusOpacity * (1 - wordExitEased);\n const y = yIn + (isExiting ? 0 : yBreathe);\n const rot = isExiting ? 0 : rotIn;\n\n return {\n text: w,\n style: {\n opacity,\n transform: `translate(${exitX}px, ${y}px) rotate(${rot}deg)`,\n },\n };\n });\n\n return {\n kind: \"words\",\n words: perWord,\n blockOpacity: 1,\n blockTransform: \"none\",\n };\n}\n\n// ─── slam ──────────────────────────────────────────────────\n// In-place impact, NOT a depth/zoom motion (cinematic already owns that\n// lane). Word appears at readable size and HITS — drama lives in the\n// squash-and-stretch arc:\n// approach pose (vertically stretched, scaleY > 1, scaleX < 1)\n// → impact (violent horizontal pancake, scaleX 1.22 / scaleY 0.74,\n// frame shake + letter crunch firing simultaneously)\n// → rebound (counter-stretched scaleY 1.12 / scaleX 0.94)\n// → damped settle to 1.0\n// No vertical translation — the squash arc + camera shake + tilt kick\n// carry the impact without any top-to-bottom drop.\nfunction renderSlam(\n progress: number,\n scale: number,\n text: string,\n phases: Phases,\n): ArchetypeRender {\n const raw = rawEntrance(progress, phases.entrancePhase);\n const ex = rawExit(progress, phases.exitStart);\n const ht = holdT(progress, phases.entrancePhase, phases.exitStart);\n\n // Squash-and-stretch arc. Keyframes (raw): 0 = approach pose, 0.30 =\n // impact, 0.45 = rebound, 0.60 = secondary oscillation, 1.0 = rest.\n // scaleX/scaleY are anti-correlated at every keyframe — that's what\n // sells \"weight\" vs. cinematic's uniform scale collapse.\n const sxIn = interpolate(raw, [0, 0.30, 0.45, 0.60, 1.0], [0.92, 1.22, 0.94, 1.02, 1.0]);\n const syIn = interpolate(raw, [0, 0.30, 0.45, 0.60, 1.0], [1.18, 0.74, 1.12, 0.99, 1.0]);\n // Tilt-and-correct: small entry tilt, levels at impact, micro overshoot.\n const rotIn = interpolate(raw, [0, 0.30, 0.45, 1.0], [-1.5, 0, 0.8, 0]);\n // Transient letter crunch AT impact, releases open by rebound. Distinct\n // from cinematic's wide→tight gradual tracking collapse.\n const lsInEm = interpolate(raw, [0, 0.20, 0.30, 0.45, 1.0], [0, -0.04, -0.06, 0, 0]);\n\n // Camera shake — full intensity at impact, fast decay over the next 20%\n // of entrance. Sin/cos at offset frequencies feel noisy while staying\n // deterministic for export.\n const shakeWindow = Math.max(0, 1 - Math.max(0, raw - 0.30) / 0.20);\n const shakeX = Math.sin(raw * 70) * 14 * scale * shakeWindow;\n const shakeY = Math.cos(raw * 80) * 10 * scale * shakeWindow;\n\n // Punchy opacity ramp so text is solid through the size change.\n const opacityIn = Math.min(1, raw * 8);\n\n // Hold: gentle 0.8% uniform scale breathe.\n const sBreathe = 1 + breathe(ht, 0.008, 1);\n\n // Exit: ease-in-expo shrink + late-bias fade — decisive leave.\n const easedExit = Easing.in(Easing.exp)(ex);\n const sOut = interpolate(easedExit, [0, 1], [1, 0.85]);\n const opacityOut = interpolate(ex, [0, 0.55, 1], [1, 0.8, 0], {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n });\n\n const sx = phases.inExit ? sOut : sxIn * sBreathe;\n const sy = phases.inExit ? sOut : syIn * sBreathe;\n const tx = phases.inExit ? 0 : shakeX;\n const ty = phases.inExit ? 0 : shakeY;\n const rot = phases.inExit ? 0 : rotIn;\n const ls = phases.inExit ? 0 : lsInEm;\n const opacity = opacityIn * (phases.inExit ? opacityOut : 1);\n\n return {\n kind: \"block\",\n block: {\n opacity,\n transform: `translate(${tx}px, ${ty}px) rotate(${rot}deg) scale(${sx}, ${sy})`,\n letterSpacing: `${ls}em`,\n },\n text,\n };\n}\n\n// ─── cinematic ──────────────────────────────────────────────────\n// Hollywood Movie-Trailer FlyIn (vuild-style without filter:blur).\n// Entry: ease-out-circ — weighty deceleration, classic cinema arrival.\n// Scale 3.0 → 1.0, tracking +40 → 0 (letters wide-spaced from depth\n// collapse to readable). Slow opacity ramp finishes by progress 0.4\n// so text becomes \"real\" as it nears the camera plane.\n// Hold: ±0.6px tracking wobble + 1% scale breathe.\n// Exit: ease-in-expo — text holds, then RECEDES into the background.\n// Scale 1.0 → 0.4 (zooms out / shrinks away), tracking spreads back\n// out (0 → +24) like objects dissipating into the distance, opacity\n// holds high then drops late so the recede motion stays visible.\nfunction renderCinematic(\n progress: number,\n scale: number,\n text: string,\n phases: Phases,\n): ArchetypeRender {\n const raw = rawEntrance(progress, phases.entrancePhase);\n const ex = rawExit(progress, phases.exitStart);\n\n // Entry: ease-out-circle — slow start (text far away), strong deceleration into place\n const easedIn = Easing.out(Easing.circle)(raw);\n const sIn = interpolate(easedIn, [0, 1], [3.0, 1]);\n const yIn = interpolate(easedIn, [0, 1], [18 * scale, 0]);\n // Slow opacity ramp — text becomes \"real\" only as it approaches the camera\n const opacityIn = interpolate(raw, [0, 0.4], [0, 1], {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n });\n\n // No hold-phase breathing — subpixel rendering on tiny scale changes\n // reads as jitter on stable text. Cinematic holds dead-still during the\n // visible phase.\n\n // Exit: ease-in-expo — held, then RECEDES into the background\n const easedExit = Easing.in(Easing.exp)(ex);\n const sOut = interpolate(easedExit, [0, 1], [1, 0.4]);\n // Subtle drift back/up to reinforce \"going away\"\n const yOut = interpolate(easedExit, [0, 1], [0, -10 * scale]);\n // Opacity holds 100% for first 50% of exit, then drops to 0\n const opacityOut = interpolate(ex, [0, 0.5, 1], [1, 0.85, 0], {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n });\n\n const s = phases.inExit ? sOut : sIn;\n const y = phases.inExit ? yOut : yIn;\n const opacity = opacityIn * (phases.inExit ? opacityOut : 1);\n\n // No CSS filter. Earlier iterations layered a ~2.5px gaussian blur at the\n // lifecycle edges for a Hollywood motion-blur feel, but iOS Safari is\n // notoriously bad at compositing `filter` with an animating `transform` —\n // the zoom would stall mid-motion on mobile while desktop and the\n // server-side Puppeteer export rendered fine. The cinematic effect's\n // identity is the scale collapse + slow opacity ramp + ease-out-circ\n // timing, all of which work without the filter. willChange hints both\n // properties are animating so the browser keeps the layer GPU-composited.\n return {\n kind: \"block\",\n block: {\n opacity,\n transform: `translateY(${y}px) scale(${s})`,\n willChange: \"transform, opacity\",\n },\n text,\n };\n}\n\n// ─── heroWord ───────────────────────────────────────────────────\n// One word at a time, each lands with anticipation overshoot. Mid-sequence\n// words hand off with brief brightness flash before fade. Final word's exit\n// participates in the global exit window — scales up + fades for the finale.\nfunction renderHeroWord(\n progress: number,\n motionProgress: number,\n text: string,\n phases: Phases,\n): ArchetypeRender {\n const words = text.split(/\\s+/).filter(Boolean);\n if (words.length === 0) {\n return { kind: \"hero\", word: \"\", index: 0, total: 0, opacity: 0, transform: \"scale(1)\" };\n }\n\n // Words occupy the time between entrance start and exit start.\n const sequenceStart = ENTRANCE_START + phases.entrancePhase * 0.2;\n const sequenceEnd = phases.exitStart;\n const sequenceDur = Math.max(0.01, sequenceEnd - sequenceStart);\n // Determine active word.\n const localProgress = Math.max(0, Math.min(0.999, (progress - sequenceStart) / sequenceDur));\n const idx = Math.min(words.length - 1, Math.floor(localProgress / (1 / words.length)));\n const local = (localProgress * words.length) - idx;\n const isLast = idx === words.length - 1;\n\n // Per-word entrance: anticipation + spring overshoot\n const ENTER_FRAC = 0.28;\n const HOLD_FRAC = 0.55;\n const HANDOFF_FRAC = 0.85;\n\n let scale: number;\n let opacity: number;\n\n if (local < ENTER_FRAC) {\n const entRaw = local / ENTER_FRAC;\n const sp = spring(entRaw, SPRING_CRISP);\n // Overshoot: 0.5 → 1.06 → 1.0\n scale = sp < 0.7 ? interpolate(sp, [0, 0.7], [0.5, 1.06]) : interpolate(sp, [0.7, 1], [1.06, 1.0]);\n opacity = Math.min(1, entRaw * 6);\n } else if (local < HOLD_FRAC) {\n // Hold: 0.5% breathe per word\n const ht = (local - ENTER_FRAC) / (HOLD_FRAC - ENTER_FRAC);\n scale = 1 + breathe(ht, 0.01, 1);\n opacity = 1;\n } else if (local < HANDOFF_FRAC && !isLast) {\n // Brief brightness pulse + fade for handoff to next word\n const handoffRaw = (local - HOLD_FRAC) / (HANDOFF_FRAC - HOLD_FRAC);\n scale = interpolate(handoffRaw, [0, 1], [1, 1.04]);\n // Pulse: 1 → 1.15 (brightness via opacity > 1 is faked by holding 1) → fade\n opacity = handoffRaw < 0.3 ? 1 : interpolate(handoffRaw, [0.3, 1], [1, 0]);\n } else if (!isLast) {\n // Trailing nothing-frame for non-last words\n scale = 1.04;\n opacity = 0;\n } else {\n // Last word: hold until global exit kicks in\n scale = 1;\n opacity = 1;\n }\n\n // Last word participates in the global exit — simple fast fade with a\n // tiny scale lift. No anticipation, no tracking compression: the goal is\n // to give the WORDS the most time, not the exit animation.\n if (isLast && phases.inExit) {\n const ex = rawExit(motionProgress, phases.exitStart);\n const easedExit = Easing.in(Easing.cubic)(ex);\n scale = interpolate(easedExit, [0, 1], [1, 1.08]);\n opacity = 1 - easedExit;\n }\n\n return {\n kind: \"hero\",\n word: words[idx],\n index: idx,\n total: words.length,\n opacity,\n transform: `scale(${scale})`,\n };\n}\n\n// ─── Effect duration helpers ────────────────────────────────────\n//\n// Per-archetype min/max DURATION (seconds) — the time the effect itself\n// uses, not the scene length. On long scenes the effect runs at most for\n// `maxDuration` and then disappears, signaling the AI to fill the rest\n// with another effect.\n//\n// - minDurationFor(archetype, text): minimum effect duration accounting\n// for text length (text-dependent archetypes scale up).\n// - effectiveDuration(archetype, text, sceneDuration): how long the\n// effect actually runs in the given scene — bounded by [minFor, max].\n// - canFit(items, sceneSeconds): whether a sequence of (archetype, text)\n// plays fits within a scene.\n\nconst TYPEWRITER_SEC_PER_CHAR = 0.08; // matches the linear char reveal pace\nconst HEROWORD_PER_WORD_SLOT = 0.6; // each word in heroWord needs ~0.6s on screen\nconst WORDSTAGGER_MIN_HOLD = 0.5; // matches renderWordStagger's minHold\n\n/**\n * Compute the minimum DURATION (seconds) the effect needs for this text.\n * Text-dependent archetypes scale up; others return their static\n * spec.minDuration.\n */\nexport function minDurationFor(archetype: TextArchetype, text: string): number {\n const spec = ARCHETYPE_SPECS[archetype];\n const wordCount = Math.max(1, text.split(/\\s+/).filter(Boolean).length);\n\n switch (archetype) {\n case \"typewriter\": {\n const revealSec = Math.max(0.6, text.length * TYPEWRITER_SEC_PER_CHAR);\n return revealSec + 0.3 + spec.exit;\n }\n case \"wordStagger\": {\n return (wordCount - 1) * 0.28 + 0.5 + WORDSTAGGER_MIN_HOLD + spec.exit;\n }\n case \"heroWord\": {\n return wordCount * HEROWORD_PER_WORD_SLOT + spec.exit;\n }\n default:\n return spec.minDuration;\n }\n}\n\n/**\n * How long the effect actually runs inside a given scene. The effect uses\n * at most spec.maxDuration; if the scene is shorter than that, it uses\n * the scene length; if the text needs more (long typewriter, many words),\n * the minimum wins.\n *\n * On long scenes, sceneDuration > effectiveDuration(...) means the AI\n * has remaining time to fill with another effect.\n */\nexport function effectiveDuration(\n archetype: TextArchetype,\n text: string,\n sceneDuration: number,\n): number {\n const spec = ARCHETYPE_SPECS[archetype];\n const minFor = minDurationFor(archetype, text);\n const cappedMax = Math.max(spec.maxDuration, minFor);\n return Math.min(sceneDuration, cappedMax);\n}\n\nexport interface ArchetypePlay {\n archetype: TextArchetype;\n text: string;\n}\n\n/**\n * Whether a sequence of archetype plays fits in the given scene duration.\n * Used by the AI/tool layer to validate before committing to a plan.\n *\n * @example\n * canFit(\n * [\n * { archetype: \"subtle\", text: \"Hi\" },\n * { archetype: \"heroWord\", text: \"Launch\" },\n * ],\n * 4.0,\n * ); // → true if both fit; false otherwise\n */\nexport function canFit(items: ArchetypePlay[], sceneSeconds: number): boolean {\n const total = items.reduce(\n (sum, item) => sum + minDurationFor(item.archetype, item.text),\n 0,\n );\n return total <= sceneSeconds;\n}\n\n/**\n * Total minimum seconds for a sequence — useful when canFit returns false\n * and you need to know how much time is missing.\n */\nexport function totalMinDurationFor(items: ArchetypePlay[]): number {\n return items.reduce(\n (sum, item) => sum + minDurationFor(item.archetype, item.text),\n 0,\n );\n}\n"
22
- },
23
- {
24
- "path": "src/visual-system/scene-templates/text-utils.ts",
25
- "type": "registry:lib",
26
- "target": "vanillasky/scene-templates/text-utils.ts",
27
- "content": "/**\n * Shared text utilities. Kept intentionally small.\n */\n\n/**\n * Return the first pipe-delimited text segment. Template variables use pipes\n * for explicit text segmentation. For values without `|` this is a no-op.\n */\nexport function stripPipe(text: string): string {\n const idx = text.indexOf(\"|\");\n return idx === -1 ? text : text.slice(0, idx);\n}\n\n/**\n * Responsive font size for caption-style text — used by chart-counter to\n * size its sub-label below the big number. Mirrors the prior helper from\n * the deleted text-entrance module so behavior is preserved.\n *\n * @param text the text to size\n * @param width render width (1080 portrait, smaller in preview)\n * @param role \"headline\" or \"subtitle\" — biases the curve\n * @param height optional height for proper short-edge scaling\n */\nexport function getResponsiveFontSize(\n text: string,\n width: number,\n role: \"headline\" | \"subtitle\" = \"headline\",\n height?: number,\n): number {\n const s = height ? Math.min(width, height) / 1080 : width / 1080;\n const words = text.split(/\\s+/).filter(Boolean).length;\n const chars = text.length;\n\n if (role === \"subtitle\") {\n if (chars > 60) return 24 * s;\n if (chars > 30) return 28 * s;\n return 32 * s;\n }\n\n if (words <= 2 && chars <= 12) return Math.max(36 * s, 96 * s);\n if (words <= 3 && chars <= 20) return Math.max(36 * s, 80 * s);\n if (words <= 5 && chars <= 35) return Math.max(36 * s, 64 * s);\n if (words <= 8 && chars <= 60) return Math.max(36 * s, 48 * s);\n return 36 * s;\n}\n\n/**\n * Shrink `baseFontSize` so that `text` rendered at that size fits within\n * `maxWidth` pixels on one line. Returns the original size if the text\n * already fits; otherwise scales proportionally down to `minScale × base`.\n *\n * Approach: estimate text width as `chars × fontSize × charWidthRatio`.\n * 0.55 is a safe over-estimate for Helvetica/Arial-family sans-serif at\n * normal weights — picks slightly smaller than strictly necessary so URLs\n * with wide caps (W, M) still fit. Override `charWidthRatio` for narrower\n * fonts (e.g. condensed) or wider ones (display).\n *\n * Used by templates with fixed-width containers that can overflow on long\n * AI-generated copy (URLs in cta-*, prompt text in promptInput, caller\n * name in incomingCall). Cheap, deterministic, no canvas measurement —\n * runs identically in renderToStaticMarkup and in the browser.\n */\nexport function fitTextSize(\n text: string,\n baseFontSize: number,\n maxWidth: number,\n opts?: { minScale?: number; charWidthRatio?: number },\n): number {\n if (!text) return baseFontSize;\n const minScale = opts?.minScale ?? 0.5;\n const charWidthRatio = opts?.charWidthRatio ?? 0.55;\n const estWidth = text.length * baseFontSize * charWidthRatio;\n if (estWidth <= maxWidth) return baseFontSize;\n const scaled = (maxWidth / estWidth) * baseFontSize;\n return Math.max(scaled, baseFontSize * minScale);\n}\n\n/**\n * Compact a number for social-style counters (likes, replies, views).\n * Match TweetCard.formatCount — kept in sync. See that function for the\n * boundary-rounding rationale (never let the leading number reach 4\n * digits; 999,999 rolls up to \"1M\", not \"1000K\").\n */\nexport function formatCompact(n: number): string {\n if (!Number.isFinite(n)) return String(n);\n const abs = Math.abs(n);\n const sign = n < 0 ? \"-\" : \"\";\n if (abs < 1_000) return `${sign}${Math.round(abs)}`;\n if (abs < 10_000) {\n const rounded = Number((abs / 1_000).toFixed(1));\n if (rounded < 10) return `${sign}${rounded.toString().replace(/\\.0$/, \"\")}K`;\n }\n if (abs < 1_000_000) {\n const k = Math.round(abs / 1_000);\n if (k < 1_000) return `${sign}${k}K`;\n }\n if (abs < 10_000_000) {\n const rounded = Number((abs / 1_000_000).toFixed(1));\n if (rounded < 10) return `${sign}${rounded.toString().replace(/\\.0$/, \"\")}M`;\n }\n if (abs < 1_000_000_000) {\n const m = Math.round(abs / 1_000_000);\n if (m < 1_000) return `${sign}${m}M`;\n }\n return `${sign}${(abs / 1_000_000_000).toFixed(1).replace(/\\.0$/, \"\")}B`;\n}\n"
28
- }
29
- ],
30
- "meta": {
31
- "vanillasky": {
32
- "layer": "lib",
33
- "tier": "free",
34
- "domain": "typography",
35
- "level": "composed",
36
- "audiences": [
37
- "custom-scenes",
38
- "react-developers"
39
- ],
40
- "dependencies": [
41
- "motion"
42
- ],
43
- "useWhen": "Use it for any text-led scene where copy must fit a known box, animate as a coherent lifecycle, or be checked against a fixed scene duration.",
44
- "avoidWhen": "Do not shrink copy indefinitely or choose an archetype without checking its allowed canvas and minimum duration."
45
- }
46
- }
47
- }