Skip to content

Script Library

The Script Library is a standalone repo (Script-Library) containing pre-built JavaScript scripts for the Creative Engine flow system. Scripts are authored with JSDoc metadata, built into a manifest, and served from CDN. The Builder (Application-Frontend) consumes the manifest so designers can select and configure scripts without writing code.

Architecture

Script-Library repo
  └─ scripts/           ← .js files with JSDoc headers
  └─ build/             ← generate-manifest.js
  └─ dist/              ← built output (manifest + scripts)

        ↓ deploy (Cloudflare Pages, auto on push to main)

CDN: script-library.pages.dev
  ├─ script-library.json          ← manifest (all script metadata)
  └─ scripts/{category}/{name}.js ← script source files

        ↓ fetched at runtime

Application-Frontend (src/services/scriptLibrary.ts)
  ├─ getManifest()       → fetches + caches manifest
  ├─ getScriptSource()   → fetches + caches individual script source
  └─ assembleScript()    → wraps source with PARAMS injection

        ↓ used by

LibraryScriptOp.vue (flow operator in the Builder)
  ├─ Shows script picker (SearchableDropdown)
  ├─ Renders param form based on manifest metadata
  └─ Calls assembleScript() → saves assembled <script> to operator body

How Scripts Reach the Creative

  1. Authoring — Designer selects a script and configures params in the Builder's LibraryScriptOp
  2. AssemblyassembleScript() prepends const PARAMS = {...}; to the script source and wraps it in a <script> tag
  3. Storage — The assembled script is saved to the operator's body.inputText.value (same field as custom scripts)
  4. Publishing — The Creative Composer bakes the script into the published creative. Published creatives have no runtime CDN dependency — the script source is embedded at publish time
  5. Execution — The Creative Engine executes the script when the flow reaches the operator, same as any custom script

Deployment

Hosted on Cloudflare Pages. Pushes to main auto-deploy:

AssetURL
Manifesthttps://script-library.pages.dev/script-library.json
Scriptshttps://script-library.pages.dev/scripts/{category}/{name}.js

Local development: The Frontend uses http://localhost:8090 when running in dev mode (see CDN_BASE in scriptLibrary.ts). Run a local server from the Script-Library dist/ folder on port 8090 to test changes before deploying.

Update Flow

To update a script in production:

  1. Edit the script in Script-Library/scripts/{category}/{name}.js
  2. Run npm run build to regenerate the manifest and dist
  3. Push/merge to main → Cloudflare Pages auto-deploys
  4. The Builder fetches the updated manifest and source on next load
  5. Existing published creatives are NOT affected — they have the script baked in. Only newly published (or re-published) creatives will use the updated script

Writing Scripts

Each script is a .js file in scripts/ with a JSDoc metadata header:

js
/**
 * @script Image Swap with Delay
 * @description Swaps an image element after a configurable delay
 * @requires image
 * @param {element} targetElement - Element to swap
 * @param {url} imageUrl - URL of the new image
 * @param {number} delayMs - Delay before swap in milliseconds (default: 0)
 * @param {select} easing - Easing function
 * @option easing linear - Linear
 * @option easing easeOut - Ease Out
 */

const target = PARAMS.targetElement
const url = PARAMS.imageUrl
// script logic...

Metadata Tags

TagPurpose
@scriptDisplay name in the Builder dropdown
@descriptionShown below the dropdown when selected
@requiresFilters visibility — script only shown if the creative has this block/operator type (e.g. answer, image). Does NOT affect execution
@paramDefines a configurable parameter
@optionDefines options for select type params

Parameter Types

TypeBuilder UIPARAMS Value
stringText inputFree text
numberNumber inputNumeric value
booleanToggle switchtrue / false
urlText input with URL validationURL string
colorColor pickerHex string
selectDropdown (options via @option tags)Selected option value
elementTargetOpSelector (element picker)Element abbreviation (e.g. "bg1", "t1")
element-listMulti-select element pickerArray of abbreviations
element-pairsSource → Target mapping UIArray of { source, target } objects
blockBlock/step picker dropdownBlock key from the flow
videoVideo upload with thumbnailCloudflare Stream UID

Parameter Rules

  • Parameters without (default: ...) are required — the Builder validates them before saving
  • Parameters with (default: ...) are optional and use that default value
  • select type requires @option paramKey value - Label tags
  • Access all parameters via the global PARAMS object at runtime

Available Globals

Scripts execute through the Engine's Tag/Script pipeline and have access to:

  • PARAMS — Object containing all configured parameter values
  • DATASTORE — Creative state
  • changeImage(abbrev, url), changeText(abbrev, text), changeUrl(abbrev, url), changeVideo(abbrev, url)
  • showHideFunctions.hideElement(abbrev), showHideFunctions.showElement(abbrev)
  • resetCreative(), restartFlow()
  • ANALYTICS.sendEvent({...})

Key Source Files

FileRepoPurpose
scripts/flow/choice-click-target.jsScript-LibraryMaps button clicks to choice clicks for analytics tracking (see analytics/visual-element-tracking-gap.md)
scripts/{category}/*.jsScript-LibraryScript source files
build/generate-manifest.jsScript-LibraryParses JSDoc → generates manifest
src/services/scriptLibrary.tsApplication-FrontendCDN fetch, caching, assembly
src/pages/.../operators/LibraryScriptOp.vueApplication-FrontendBuilder UI for script selection and param configuration

Script Categories

Scripts are organized into subdirectories under scripts/:

CategoryPurpose
flowFlow logic -- choice routing, conditional branching, button-to-choice mapping
visualVisual effects — image swaps, responsive adjustments
high-impactHigh-impact format integrations — skin placements

Internal documentation