gsap-utils
Official GSAP skill for gsap.utils — clamp, mapRange, normalize, interpolate, random, snap, toArray, wrap, pipe. Use when the user asks about gsap.utils, clamp, mapRange, random, snap, toArray, wrap, or helper utilities in GSAP.
1How It Works & Mechanism
Position gsap.utils as a "pure-function utility toolbox requiring no registration" and explain its injection points within animation workflows (function-based values, ScrollTrigger/Observer callbacks).
**gsap.utils** provides pure helpers; no need to register.
Standardize the invocation paradigm of "omitting values returns a reusable function", while highlighting the sole exception of passing true to random().
If you omit that argument, the util returns a **function** that accepts the value later.
Provide concrete "input → output comments" for each function as behavioral specifications (essentially verifiable micro-tests), allowing the model to align its semantics with concrete examples.
gsap.utils.clamp(0, 100, 150); // 100
Break down distribute() into tabular configuration parameters (base, amount, each, from, grid, axis, ease), representing the internal distribution engine of GSAP stagger.
**Returns a function** that assigns a value to each target based on its position in the array (or in a grid).
Introduce selector(scope) as the official primitive for an in-component "selector sandbox", aligning with the scoping disciplines of gsap-react and gsap-frameworks.
Returns a scoped selector function that finds elements only within the given element (or ref).
Dedicate a section to unit and color parsing: getUnit, unitize, and splitColor handle inputs beyond pure numbers, clarifying that mapRange and normalize do not perform unit conversions.
❌ Assume **mapRange** / **normalize** handle units; they work on numbers.
2Core Capabilities
3External Dependencies
| Kind | Dependency / Endpoint |
|---|---|
| package | gsap(utils 为内核自带命名空间,无需注册) |
| network | distribute() 官方文档 |
| network | random() 官方文档 |
| network | splitColor() 官方文档 与 HelperFunctions 列表页 |
4Recommended Governance & Evidence
- SKILL.md: Pure prompt instructions and rule text with no script execution or external impact
5Second-Pass Verification
- [ok] 目录资产面:仅 SKILL.md — skills/gsap-utils/ 下唯一文件 SKILL.md(12,093 B);无 scripts/、references/、数据文件。
- [ok] external_deps 逐条核实 — gsap 包依赖证据取自 README 安装段;三条 gsap.com 链接(distribute、random()、HelperFunctions)+ splitColor 链接在内文中逐字命中。
- [ok] 函数签名与示例输出是否与官方语义一致 — 抽查 clamp(0,100,150)=100、mapRange(0,100,0,500,50)=250、normalize(0,100,50)=0.5、snap(10,23)=20、wrap(0,360,370)=10、wrapYoyo(0,100,150)=50,均与 GSAP 官方 API 语义吻合,无编造。
- [ok] 「random 是唯一例外」的说法是否可复核 — 原文明确「This is the only util that uses `true` for the function form instead of omitting the value.」并给出 random(-200,500,10,true) 示例,叙述自洽。
- [ok] 安全反例搜索 — token 扫描:curl/wget/fetch(/XMLHttpRequest/exec(/child_process/process.env/.env/API_KEY/secret 零命中;无混淆代码(该文件只有短代码块)。
- [ok] 与 gsap-react / gsap-frameworks 的 scoping 叙述是否一致 — 本文件「Use **gsap.utils.selector(scope)** in components so selectors are scoped to a container or ref.」与 gsap-react 的「always pass scope」、gsap-frameworks 的「Do not use global selectors」同向。
- [ok] 元数据与 pin — frontmatter license: MIT;本地 HEAD = aed9cfd3277740755f6bfc1155c7aa645403b760;GitHub API stars 15326、pushed_at 2026-07-29T17:36:08Z。
- [ok] 无夸大检查 — description 只声明「Official GSAP skill for gsap.utils …」,文件内容即函数清单与示例,无越界承诺(不宣称性能优化或自动重构)。
6Verdict & Scenarios
55bd8167106fd1d2…