{
  "id": "template_base",
  "name": "Spring Button",
  "width": 760,
  "height": 380,
  "backgroundColor": "#f7f5f0",
  "opacity": 1,
  "objects": [
    {
      "id": "stage",
      "name": "Stage",
      "type": "Group",
      "transform": {
        "x": 0,
        "y": 0,
        "rotation": 0,
        "scale_x": 1,
        "scale_y": 1,
        "opacity": 1,
        "skew_x": 0,
        "skew_y": 0
      },
      "width": 760,
      "height": 380,
      "geometry": {
        "type": "Rectangle",
        "width": 760,
        "height": 380,
        "cornerRadius": 0
      },
      "cornerRadius": 0,
      "children": [],
      "clipContent": true,
      "style": {
        "fill": {
          "type": "Solid",
          "color": "#f7f5f0",
          "opacity": 0
        },
        "effects": [
          {
            "id": "fx_mvmhql0o",
            "type": "CustomEffect",
            "name": "Spring Button",
            "isEnabled": true,
            "params": {},
            "code": "/* Shared by every motion-ui effect (prepended to each one).\n   Rules for this file and the effects: the .bexode compiler minifies effect\n   code, so use explicit semicolons, block comments only, and never write a\n   minus followed by a negative value (it collapses to a decrement). */\n\n/* Read a live state-machine input, falling back to a default. */\nfunction inp(env, name, fallback) {\n  const v = env.inputs ? env.inputs[name] : undefined;\n  if (v === undefined || v === null || v === '') return fallback;\n  if (typeof fallback === 'number') {\n    const n = Number(v);\n    return isFinite(n) ? n : fallback;\n  }\n  if (typeof fallback === 'boolean') return v === true || v === 1 || v === 'true';\n  return v;\n}\n\n/* '#rgb' / '#rrggbb' to [r, g, b]; anything else falls back to white. */\nfunction rgbOf(hex) {\n  let h = String(hex || '').trim().replace('#', '');\n  if (h.length === 3) h = h[0] + h[0] + h[1] + h[1] + h[2] + h[2];\n  if (!/^[0-9a-fA-F]{6}$/.test(h)) return [255, 255, 255];\n  const n = parseInt(h, 16);\n  return [(n >> 16) & 255, (n >> 8) & 255, n & 255];\n}\n\nfunction rgba(hex, a) {\n  const c = rgbOf(hex);\n  return 'rgba(' + c[0] + ',' + c[1] + ',' + c[2] + ',' + Math.max(0, Math.min(1, a)) + ')';\n}\n\nfunction mix(a, b, t) {\n  const x = rgbOf(a), y = rgbOf(b);\n  const r = Math.round(x[0] + (y[0] - x[0]) * t);\n  const g = Math.round(x[1] + (y[1] - x[1]) * t);\n  const bl = Math.round(x[2] + (y[2] - x[2]) * t);\n  return '#' + ((1 << 24) + (r << 16) + (g << 8) + bl).toString(16).slice(1);\n}\n\n/* A soft round glow, rendered once per colour and blitted with drawImage\n   (much cheaper than shadowBlur on every particle). */\nconst __glows = {};\nfunction glowSprite(hex) {\n  if (__glows[hex]) return __glows[hex];\n  const s = 64;\n  const c = document.createElement('canvas');\n  c.width = s; c.height = s;\n  const g = c.getContext('2d');\n  const gr = g.createRadialGradient(s / 2, s / 2, 0, s / 2, s / 2, s / 2);\n  gr.addColorStop(0, rgba(hex, 1));\n  gr.addColorStop(0.18, rgba(hex, 0.55));\n  gr.addColorStop(0.45, rgba(hex, 0.14));\n  gr.addColorStop(1, rgba(hex, 0));\n  g.fillStyle = gr;\n  g.fillRect(0, 0, s, s);\n  __glows[hex] = c;\n  return c;\n}\n\nfunction glow(ctx, hex, x, y, r, a) {\n  if (r <= 0 || a <= 0) return;\n  ctx.globalAlpha = Math.min(1, a);\n  ctx.drawImage(glowSprite(hex), x - r, y - r, r * 2, r * 2);\n  ctx.globalAlpha = 1;\n}\n\n/* Frame clock: seconds since start and a clamped delta. */\nfunction tick(S) {\n  const now = performance.now();\n  if (!S.t0) { S.t0 = now; S.last = now; }\n  S.dt = Math.min(0.05, Math.max(0.001, (now - S.last) / 1000));\n  S.last = now;\n  S.age = (now - S.t0) / 1000;\n  return S.dt;\n}\n\n/* Deterministic pseudo-random so layouts are stable across resizes. */\nfunction rng(seed) {\n  let s = seed >>> 0 || 1;\n  return function () {\n    s = (s * 1664525 + 1013904223) >>> 0;\n    return s / 4294967296;\n  };\n}\n\nfunction ease(x) { return x < 0.5 ? 4 * x * x * x : 1 + (Math.pow(2 * x - 2, 3)) / 2; }\nfunction clamp(v, a, b) { return v < a ? a : v > b ? b : v; }\n\nconst SANS = 'Inter, Helvetica, Arial, sans-serif';\nconst MONO = 'ui-monospace, Menlo, monospace';\n\nfunction roundRect(ctx, x, y, w, h, r) {\n  r = Math.min(r, w / 2, h / 2);\n  ctx.beginPath();\n  ctx.moveTo(x + r, y);\n  ctx.arcTo(x + w, y, x + w, y + h, r);\n  ctx.arcTo(x + w, y + h, x, y + h, r);\n  ctx.arcTo(x, y + h, x, y, r);\n  ctx.arcTo(x, y, x + w, y, r);\n  ctx.closePath();\n}\n\n/* Shared backdrop: flat colour, soft vignette and fine grain. */\nfunction backdrop(ctx, W, H, bg, tint, amt) {\n  ctx.fillStyle = bg;\n  ctx.fillRect(0, 0, W, H);\n  if (tint && amt > 0) {\n    const gr = ctx.createRadialGradient(W / 2, H * 0.45, 0, W / 2, H * 0.45, Math.max(W, H) * 0.7);\n    gr.addColorStop(0, rgba(tint, 0.10 * amt));\n    gr.addColorStop(1, rgba(tint, 0));\n    ctx.fillStyle = gr;\n    ctx.fillRect(0, 0, W, H);\n  }\n  const vg = ctx.createRadialGradient(W / 2, H / 2, Math.min(W, H) * 0.3, W / 2, H / 2, Math.max(W, H) * 0.8);\n  vg.addColorStop(0, 'rgba(0,0,0,0)');\n  vg.addColorStop(1, 'rgba(0,0,0,0.45)');\n  ctx.fillStyle = vg;\n  ctx.fillRect(0, 0, W, H);\n}\n\n/* Greedy word wrap with the current ctx.font. */\nfunction wrap(ctx, text, maxW) {\n  const out = [];\n  String(text).split('\\n').forEach(function (para) {\n    const words = para.split(' ');\n    let cur = '';\n    for (let i = 0; i < words.length; i++) {\n      const next = cur ? cur + ' ' + words[i] : words[i];\n      if (cur && ctx.measureText(next).width > maxW) { out.push(cur); cur = words[i]; } else cur = next;\n    }\n    out.push(cur);\n  });\n  return out;\n}\n\n/* Largest font size (up to max) at which text wraps into maxLines within maxW. */\nfunction fitFont(ctx, text, weight, family, maxW, maxLines, max, min) {\n  let fs = max;\n  while (fs > min) {\n    ctx.font = weight + ' ' + fs + 'px ' + family;\n    if (wrap(ctx, text, maxW).length <= maxLines) break;\n    fs = fs * 0.92;\n  }\n  ctx.font = weight + ' ' + fs + 'px ' + family;\n  return fs;\n}\n\n/* Smoothed pointer that idles along a slow figure-eight when the cursor is away. */\nfunction follow(S, env, W, H, k) {\n  const pt = env.pointer || {};\n  const t = S.age || 0;\n  const tx = pt.isHovered ? pt.localX : W / 2 + Math.sin(t * 0.37) * W * 0.3;\n  const ty = pt.isHovered ? pt.localY : H / 2 + Math.sin(t * 0.74) * H * 0.22;\n  if (S.px === undefined) { S.px = tx; S.py = ty; }\n  S.px += (tx - S.px) * Math.min(1, S.dt * (k || 6));\n  S.py += (ty - S.py) * Math.min(1, S.dt * (k || 6));\n  S.inside = !!pt.isHovered;\n  return pt;\n}\n\n/* Optional centred headline over a background effect. */\nfunction title(ctx, W, H, text, sub, ink, accent, bg) {\n  if (!text) return;\n  if (bg) {\n    /* Soft scrim so the headline reads over busy motion. */\n    const sc = ctx.createRadialGradient(W / 2, H / 2, 0, W / 2, H / 2, Math.min(W * 0.5, 560));\n    sc.addColorStop(0, rgba(bg, 0.72));\n    sc.addColorStop(1, rgba(bg, 0));\n    ctx.fillStyle = sc;\n    ctx.fillRect(0, 0, W, H);\n  }\n  ctx.textAlign = 'center';\n  ctx.textBaseline = 'alphabetic';\n  const maxW = Math.min(W * 0.86, 900);\n  const fs = fitFont(ctx, text, 600, SANS, maxW, 2, clamp(W * 0.065, 26, 72), 16);\n  const lines = wrap(ctx, text, maxW);\n  const lh = fs * 1.08;\n  const y0 = H / 2 - (lines.length * lh) / 2 + fs * 0.8 - (sub ? fs * 0.35 : 0);\n  ctx.fillStyle = ink;\n  lines.forEach(function (l, i) { ctx.fillText(l, W / 2, y0 + i * lh); });\n  if (sub) {\n    ctx.font = '500 ' + clamp(fs * 0.24, 11, 15) + 'px ' + MONO;\n    ctx.fillStyle = rgba(accent, 0.85);\n    ctx.fillText(String(sub).toUpperCase(), W / 2, y0 + (lines.length - 1) * lh + fs * 0.9);\n  }\n}\n\n/* Spring action button: press and hold compresses it, release springs past\n   rest, and the HUD names the state. Stiffness and damping are live inputs. */\nlet S = null;\n\nfunction render(ctx, env) {\n  const W = env.width, H = env.height;\n  if (!S) {\n    S = { scale: 1, vel: 0, press: 0, pv: 0, tiltX: 0, tiltY: 0, down: false, rings: [], sparks: [], flash: 0 };\n  }\n  const dt = tick(S);\n  const u = clamp(Math.min(W, H) / 360, 0.72, 1.55);\n  const label = String(inp(env, 'label', 'Deploy component'));\n  const stiffness = clamp(inp(env, 'stiffness', 340), 60, 720);\n  const damping = clamp(inp(env, 'damping', 22), 4, 60);\n  const accent = inp(env, 'accent', '#ff4a1c');\n  const bg = inp(env, 'bg', '#f7f5f0');\n  const ink = inp(env, 'ink', '#171310');\n  const pt = env.pointer || {};\n  const down = !!(pt.isDown || pt.down);\n  const hovered = !!pt.isHovered;\n  const cx = W / 2, cy = H / 2;\n\n  ctx.save();\n  ctx.translate(0 - W / 2, 0 - H / 2);\n\n  ctx.fillStyle = bg;\n  ctx.fillRect(0, 0, W, H);\n\n  const gs = Math.max(24, 34 * u);\n  ctx.strokeStyle = rgba(ink, 0.055);\n  ctx.lineWidth = 1;\n  ctx.beginPath();\n  for (let x = (W / 2) % gs; x < W; x += gs) { ctx.moveTo(x, 0); ctx.lineTo(x, H); }\n  for (let y = (H / 2) % gs; y < H; y += gs) { ctx.moveTo(0, y); ctx.lineTo(W, y); }\n  ctx.stroke();\n\n  const rad = ctx.createRadialGradient(cx, cy, 0, cx, cy, Math.max(W, H) * 0.62);\n  rad.addColorStop(0, rgba(accent, 0.16));\n  rad.addColorStop(0.45, rgba(accent, 0.05));\n  rad.addColorStop(1, rgba(accent, 0));\n  ctx.fillStyle = rad;\n  ctx.fillRect(0, 0, W, H);\n\n  ctx.font = '700 ' + Math.round(18 * u) + 'px ' + SANS;\n  const tw = ctx.measureText(label).width;\n  const bw = Math.max(250 * u, tw + 96 * u);\n  const bh = Math.max(58 * u, 64 * u);\n  const halfW = bw / 2, halfH = bh / 2;\n\n  const dx = hovered ? pt.localX - cx : 0;\n  const dy = hovered ? pt.localY - cy : 0;\n  const over = hovered && Math.abs(dx) < halfW + 22 * u && Math.abs(dy) < halfH + 22 * u;\n\n  const tx = over ? clamp(dx / (halfW + 40 * u), 0 - 1, 1) * 3.2 * u : 0;\n  const ty = over ? clamp(dy / (halfH + 40 * u), 0 - 1, 1) * 2.4 * u : 0;\n  S.tiltX += (tx - S.tiltX) * Math.min(1, dt * 9);\n  S.tiltY += (ty - S.tiltY) * Math.min(1, dt * 9);\n\n  const target = over && down ? 0.9 : over ? 1.035 : 1;\n  S.vel += ((target - S.scale) * stiffness - S.vel * damping) * dt;\n  S.scale += S.vel * dt;\n\n  const ptar = over && down ? 1 : 0;\n  S.pv += ((ptar - S.press) * stiffness * 0.8 - S.pv * damping) * dt;\n  S.press = clamp(S.press + S.pv * dt, 0, 1.3);\n\n  if (S.down && !down && over) {\n    S.vel += 2.4;\n    S.flash = 1;\n    for (let i = 0; i < 10; i++) {\n      const a = (i / 10) * Math.PI * 2 + Math.random() * 0.4;\n      const sp = (120 + Math.random() * 220) * u;\n      S.sparks.push({\n        x: cx + Math.cos(a) * halfW * 0.5,\n        y: cy + Math.sin(a) * halfH * 0.4,\n        vx: Math.cos(a) * sp,\n        vy: Math.sin(a) * sp,\n        life: 1,\n        r: (1.5 + Math.random() * 2.2) * u,\n      });\n    }\n    S.rings.push({ r: halfH * 0.6, life: 1 });\n    if (typeof env.emit === 'function') env.emit('press');\n  }\n  S.down = down;\n\n  const sx = S.scale * (1 + S.press * 0.055);\n  const sy = S.scale * (1 - S.press * 0.04);\n  const drop = (1 - S.press) * 12 * u + 3 * u;\n\n  glow(ctx, accent, cx, cy + 6 * u, bw * 0.62, 0.35 + S.flash * 0.25);\n\n  ctx.save();\n  ctx.translate(cx + S.tiltX, cy + S.tiltY + S.press * 2.4 * u);\n  ctx.rotate((S.tiltX / u) * 0.0035);\n  ctx.scale(sx, sy);\n\n  ctx.shadowColor = rgba('#1a0f08', 0.26);\n  ctx.shadowBlur = (26 - S.press * 14) * u;\n  ctx.shadowOffsetY = drop;\n  roundRect(ctx, 0 - halfW, 0 - halfH, bw, bh, halfH);\n  const g = ctx.createLinearGradient(0 - halfW, 0 - halfH, halfW, halfH);\n  g.addColorStop(0, mix(accent, '#ffffff', 0.22));\n  g.addColorStop(0.48, accent);\n  g.addColorStop(1, mix(accent, '#000000', 0.16));\n  ctx.fillStyle = g;\n  ctx.fill();\n  ctx.shadowColor = 'transparent';\n  ctx.shadowBlur = 0;\n  ctx.shadowOffsetY = 0;\n\n  const gl = ctx.createLinearGradient(0, 0 - halfH, 0, 0);\n  gl.addColorStop(0, 'rgba(255,255,255,0.34)');\n  gl.addColorStop(1, 'rgba(255,255,255,0)');\n  ctx.fillStyle = gl;\n  roundRect(ctx, 0 - halfW + 3 * u, 0 - halfH + 3 * u, bw - 6 * u, bh * 0.5, halfH);\n  ctx.fill();\n\n  ctx.strokeStyle = 'rgba(255,255,255,0.34)';\n  ctx.lineWidth = 1.2 * u;\n  roundRect(ctx, 0 - halfW + 0.6 * u, 0 - halfH + 0.6 * u, bw - 1.2 * u, bh - 1.2 * u, halfH);\n  ctx.stroke();\n\n  ctx.font = '700 ' + Math.round(18 * u) + 'px ' + SANS;\n  ctx.textAlign = 'center';\n  ctx.textBaseline = 'middle';\n  ctx.fillStyle = '#ffffff';\n  ctx.fillText(label, 0 - 10 * u, 1 * u);\n\n  const ax = halfW - 30 * u;\n  ctx.strokeStyle = 'rgba(255,255,255,0.9)';\n  ctx.lineWidth = 2 * u;\n  ctx.lineCap = 'round';\n  ctx.beginPath();\n  ctx.moveTo(ax - 7 * u, 0);\n  ctx.lineTo(ax + 5 * u, 0);\n  ctx.moveTo(ax + 1 * u, 0 - 5 * u);\n  ctx.lineTo(ax + 5 * u, 0);\n  ctx.lineTo(ax + 1 * u, 5 * u);\n  ctx.stroke();\n  ctx.restore();\n\n  for (let i = S.rings.length - 1; i >= 0; i--) {\n    const q = S.rings[i];\n    q.r += bw * 0.55 * dt;\n    q.life -= dt * 1.6;\n    if (q.life <= 0) { S.rings.splice(i, 1); continue; }\n    ctx.globalAlpha = clamp(q.life, 0, 1) * 0.5;\n    ctx.strokeStyle = accent;\n    ctx.lineWidth = 2 * u * q.life;\n    ctx.beginPath();\n    ctx.ellipse(cx, cy, q.r, q.r * 0.38, 0, 0, Math.PI * 2);\n    ctx.stroke();\n    ctx.globalAlpha = 1;\n  }\n\n  for (let i = S.sparks.length - 1; i >= 0; i--) {\n    const q = S.sparks[i];\n    q.vy += 420 * u * dt;\n    q.vx *= 0.98;\n    q.vy *= 0.98;\n    q.x += q.vx * dt;\n    q.y += q.vy * dt;\n    q.life -= dt * 1.4;\n    if (q.life <= 0) { S.sparks.splice(i, 1); continue; }\n    ctx.globalAlpha = clamp(q.life, 0, 1);\n    ctx.fillStyle = i % 2 ? accent : mix(accent, '#ffffff', 0.7);\n    ctx.beginPath();\n    ctx.arc(q.x, q.y, q.r, 0, Math.PI * 2);\n    ctx.fill();\n    ctx.globalAlpha = 1;\n  }\n\n  const state = over && down ? 'Pressed' : Math.abs(S.scale - 1) > 0.012 || Math.abs(S.vel) > 0.08 ? 'Spring back' : 'Idle';\n  ctx.font = '600 ' + Math.round(10.5 * u) + 'px ' + MONO;\n  ctx.textAlign = 'left';\n  ctx.textBaseline = 'alphabetic';\n  ctx.fillStyle = rgba(ink, 0.48);\n  ctx.fillText('STATE', 26 * u, H - 44 * u);\n  ctx.fillStyle = ink;\n  ctx.fillText(state.toUpperCase(), 26 * u, H - 28 * u);\n  ctx.fillStyle = rgba(ink, 0.48);\n  ctx.textAlign = 'right';\n  ctx.fillText('SPRING', W - 26 * u, H - 44 * u);\n  ctx.fillStyle = ink;\n  ctx.fillText('k ' + Math.round(stiffness) + '   c ' + Math.round(damping), W - 26 * u, H - 28 * u);\n\n  ctx.textAlign = 'center';\n  ctx.font = '500 ' + Math.round(11 * u) + 'px ' + MONO;\n  ctx.fillStyle = rgba(ink, 0.4);\n  ctx.fillText(over ? 'release to fire press' : 'press and hold the button', cx, H - 10 * u);\n\n  S.flash = Math.max(0, S.flash - dt * 2.2);\n\n  ctx.restore();\n}\n"
          }
        ]
      },
      "layoutProps": {
        "layoutSizingHorizontal": "fill",
        "layoutSizingVertical": "fill"
      },
      "zIndex": 1,
      "interactions": []
    }
  ],
  "animations": [],
  "stateMachine": {
    "inputs": [
      {
        "id": "in_label",
        "name": "label",
        "value": {
          "type": "Text",
          "value": "Deploy component"
        }
      },
      {
        "id": "in_stiffness",
        "name": "stiffness",
        "value": {
          "type": "Number",
          "value": 340,
          "defaultValue": 340
        }
      },
      {
        "id": "in_damping",
        "name": "damping",
        "value": {
          "type": "Number",
          "value": 22,
          "defaultValue": 22
        }
      },
      {
        "id": "in_accent",
        "name": "accent",
        "value": {
          "type": "Text",
          "value": "#ff4a1c"
        }
      },
      {
        "id": "in_bg",
        "name": "bg",
        "value": {
          "type": "Text",
          "value": "#f7f5f0"
        }
      },
      {
        "id": "in_ink",
        "name": "ink",
        "value": {
          "type": "Text",
          "value": "#171310"
        }
      }
    ],
    "layers": [
      {
        "name": "Base Layer",
        "entryStateId": "state_idle",
        "states": [
          {
            "id": "state_idle",
            "name": "Idle",
            "transitions": []
          }
        ]
      }
    ]
  },
  "inputs": [],
  "fit": "Layout",
  "responsive": {
    "enabled": true,
    "mode": "constraint",
    "width": {
      "type": "fixed"
    },
    "height": {
      "type": "fixed"
    },
    "maintainAspectRatio": false,
    "scaleObjects": false,
    "breakpoints": [
      {
        "id": "bp_mobile",
        "name": "Mobile",
        "minWidth": 0,
        "maxWidth": 599
      },
      {
        "id": "bp_tablet",
        "name": "Tablet",
        "minWidth": 600,
        "maxWidth": 1023
      },
      {
        "id": "bp_desktop",
        "name": "Desktop",
        "minWidth": 1024
      }
    ]
  },
  "baseWidth": 760,
  "baseHeight": 380,
  "layoutProps": {
    "mode": "linear",
    "direction": "vertical",
    "gap": 0,
    "padding": {
      "top": 0,
      "right": 0,
      "bottom": 0,
      "left": 0
    },
    "alignItems": "stretch",
    "layoutSizingHorizontal": "fixed",
    "layoutSizingVertical": "fixed"
  },
  "x": -380,
  "y": -190,
  "cornerRadius": 0,
  "physics": {
    "enabled": false,
    "gravity": {
      "x": 0,
      "y": 9.8
    }
  },
  "animationFlow": [],
  "navigation": [],
  "stateVariables": [
    {
      "id": "in_label",
      "name": "label",
      "type": "Text",
      "value": "Deploy component"
    },
    {
      "id": "in_stiffness",
      "name": "stiffness",
      "type": "Number",
      "value": 340
    },
    {
      "id": "in_damping",
      "name": "damping",
      "type": "Number",
      "value": 22
    },
    {
      "id": "in_accent",
      "name": "accent",
      "type": "Text",
      "value": "#ff4a1c"
    },
    {
      "id": "in_bg",
      "name": "bg",
      "type": "Text",
      "value": "#f7f5f0"
    },
    {
      "id": "in_ink",
      "name": "ink",
      "type": "Text",
      "value": "#171310"
    }
  ]
}
