phation 0.0.0-stage → 0.1.1
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/LICENSE.md +15 -0
- package/README.md +110 -2
- package/animate/core/feels.js +11 -0
- package/animate/core/recipes/index.js +84 -0
- package/animate/core/recipes/resolve.js +96 -0
- package/animate/detect.mjs +201 -0
- package/animate/index.mjs +266 -0
- package/audit.mjs +456 -0
- package/bin/cli.mjs +113 -0
- package/bin/server.mjs +147 -0
- package/data/entries.json +864 -0
- package/data/standard/CORE.md +21 -0
- package/data/standard/STANDARD.md +185 -0
- package/data/standard/claude/CLAUDE.block.md +5 -0
- package/data/standard/claude/SKILL.md +26 -0
- package/data/standard/codex/AGENTS.block.md +25 -0
- package/data/standard/cursor/phation.mdc +27 -0
- package/data/standard/meta.json +4 -0
- package/data/standard/vscode/phation.instructions.md +25 -0
- package/data/standard/windsurf/phation.md +26 -0
- package/lib.mjs +214 -0
- package/package.json +51 -4
- package/server.json +36 -0
- package/share.mjs +72 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Phation Standard (core)
|
|
2
|
+
|
|
3
|
+
Short rules for every motion task. The full standard (recipes, examples, accessibility code) is in `.phation/STANDARD.md`: open only the section you need (§3 recipes, §6 accessibility, §7 code). With the MCP server, `get_standard` with a section does the same.
|
|
4
|
+
|
|
5
|
+
**Workflow, token-lean:** `search_motions` → `add_motion` writes the file to disk, so never retype it → edit only its `MOTION` object, copy and styles → `audit_motion` with the actions that trigger it, fix blockers, re-run. A Studio link (`…/m/<slug>?…`) goes in `from`.
|
|
6
|
+
|
|
7
|
+
**Rules:** motion explains a change · one main motion at a time (secondary ≥ 80 ms later) · morph the touched element instead of cross-fading · animate transform and opacity only (`layout` / `layoutId` for size) · exits ≈ 0.7× enters · interruptible: springs for anything the user drives.
|
|
8
|
+
|
|
9
|
+
**Curves:** enter `0.16, 1, 0.3, 1` (default) · move `0.65, 0, 0.35, 1` (A → B on screen) · fade `0.4, 0, 0.2, 1` (opacity, colour) · exit `0.7, 0, 0.84, 0` (≤ 250 ms, leaves the screen) · overshoot `0.34, 1.56, 0.64, 1` (once per screen). Never linear for movement (spinners and marquees only).
|
|
10
|
+
|
|
11
|
+
**Springs (k / c / m):** snap 420 / 32 / 1 controls, pills, rolls · pop 400 / 20 / 1 small things appearing · soft 170 / 22 / 1 large surfaces · follow 420 / 34 / 0.6 pointer-following · bounce 160 / 14 / 1 one celebration per screen. Overshoot < 22 %. Close with ζ ≥ 1 (k220 c30).
|
|
12
|
+
|
|
13
|
+
**Durations:** micro 120–220 ms · small 300–450 · medium 450–650 · large 700–900 · scenic ≤ 1400. Moves over 60 px: 110 ms to 1.3 s. Hover in ≤ 300 ms. **Stagger:** letters 25–60 ms · items 35–80 · groups 100–300, whole stagger ≤ 400 ms.
|
|
14
|
+
|
|
15
|
+
**Never:** linear movement · pops and hard cuts (fade + 18–24 px rise instead) · overshoot over 22 % · animating width, height, top or left · ignoring reduced motion.
|
|
16
|
+
|
|
17
|
+
**Reduced motion (required):** with `useReducedMotion()`, swap the targets for a ≤ 150 ms fade and stop ambient loops. A shorter duration is not enough.
|
|
18
|
+
|
|
19
|
+
**Code:** values in one `export const MOTION = { … }`; durations as ms numbers (`fadeMs: 200`), converted at the call site; components accept `values` merged over `MOTION`. Keyboard parity for drag and hold; focus moves into opened surfaces and back.
|
|
20
|
+
|
|
21
|
+
**Report** the values you used and any rule you broke on purpose.
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# Phation Standard
|
|
2
|
+
|
|
3
|
+
> v1.0 · 2026-11-06 · approved by Pham Huy. Values come from the 35 Phation library entries.
|
|
4
|
+
|
|
5
|
+
You are writing UI motion for a product. Follow this standard whenever you add or change an animation, transition, hover, press, gesture response or loading state. When a rule here conflicts with a request, follow the request and say which rule you broke and why.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 1. Principles
|
|
10
|
+
|
|
11
|
+
1. **Motion explains a change.** Every animation answers "what just happened?" (cause → effect). If nothing changed, nothing moves. No decoration loops on product screens.
|
|
12
|
+
2. **One dominant motion at a time.** Secondary motion starts ≥ 80 ms after the main one and finishes before it.
|
|
13
|
+
3. **Continuity.** The element the user touched is the element that changes (morph it, grow it, move it). Do not cross-fade between two unrelated states when one element can become the other.
|
|
14
|
+
4. **Designed rest states.** The first and last frame of every motion are finished layouts. Never end mid-transition, clipped, or overlapping.
|
|
15
|
+
5. **Fast in, faster out.** Exits are about 0.7× the enter duration. Users wait for things to arrive, never for them to leave.
|
|
16
|
+
6. **Transform and opacity only.** Animate `transform` (x, y, scale, rotate) and `opacity`. Use layout animation (`layout`, `layoutId`) instead of animating width, height, top or left.
|
|
17
|
+
One exception: a small control (≤ 240 px wide) may morph its own `width` and `borderRadius`, as in the async button. Text inside it must fade out first, so nothing reflows on screen.
|
|
18
|
+
7. **Interruptible.** A new input cancels or redirects the running motion from where it is. Springs do this for free; prefer them for anything the user drives.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## 2. Tokens
|
|
23
|
+
|
|
24
|
+
### 2.1 Curves (cubic-bezier)
|
|
25
|
+
|
|
26
|
+
| Token | Value | Use for | Library uses |
|
|
27
|
+
|---|---|---|---|
|
|
28
|
+
| `enter` | `0.16, 1, 0.3, 1` | Default. Anything arriving, settling, expanding, revealing. | 23 |
|
|
29
|
+
| `move` | `0.65, 0, 0.35, 1` | A → B where both ends are on screen: wipes, sweeps, theme change, a surface leaving downward. | 7 |
|
|
30
|
+
| `fade` | `0.4, 0, 0.2, 1` | Opacity-only changes, colour changes, tick draws. | 1 |
|
|
31
|
+
| `exit` | `0.7, 0, 0.84, 0` | Short exits that leave the screen (≤ 250 ms). | — |
|
|
32
|
+
| `overshoot` | `0.34, 1.56, 0.64, 1` | One small landing overshoot on a single focal element. At most once per screen. | 1 |
|
|
33
|
+
|
|
34
|
+
Never use `linear` for movement. `linear` is allowed only for continuous ambient motion: spinners, marquees, a record turning.
|
|
35
|
+
|
|
36
|
+
> Surfaces that leave while still on screen (a sheet going down, a line rising out) use `move`. `exit` is only for short exits that leave the screen entirely.
|
|
37
|
+
|
|
38
|
+
### 2.2 Springs (stiffness k, damping c, mass m)
|
|
39
|
+
|
|
40
|
+
| Token | k / c / m | ζ | Feel | Use for | Library examples |
|
|
41
|
+
|---|---|---|---|---|---|
|
|
42
|
+
| `snap` | 420 / 32 / 1 | ≈ 0.78 | Quick, ~2 % overshoot, settles ~0.3 s | Controls: selection rings, tab pills, chips, toggles, swaps, digit rolls | date-chips, route-swap, digit-roll, finish-swatch |
|
|
43
|
+
| `pop` | 400 / 20 / 1 | ≈ 0.5 | One visible bounce (~16 %) | Small things appearing: ticks, dots, badges, a held-ring | hold-redeem check, size-slider ring |
|
|
44
|
+
| `soft` | 170 / 22 / 1 | ≈ 0.85 | Heavier, unhurried | Large surfaces: card flips, arms, sheets dragged by hand | hold-redeem flip, vinyl arm |
|
|
45
|
+
| `follow` | 420 / 34 / 0.6 | ≈ 1.0 | No overshoot, light lag | Pointer- or finger-following: cursors, magnetic pills, scrubbing | reel-card pill, circle-cursor, image-cursor |
|
|
46
|
+
| `bounce` | 160 / 14 / 1 | ≈ 0.55 | Playful (~13 %) | Brand or celebration moments only. **Max one per screen.** | search-radar bloom |
|
|
47
|
+
|
|
48
|
+
Rules:
|
|
49
|
+
- Overshoot stays under 22 % of travel (`snap` ≈ 2 %, `pop` ≈ 16 %).
|
|
50
|
+
- Close or cancel with a critically damped spring (ζ ≥ 1, e.g. k220 c30). Never bounce on the way out.
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
### 2.3 Durations (for curve-based motion)
|
|
54
|
+
|
|
55
|
+
| Size of change | Duration | Examples |
|
|
56
|
+
|---|---|---|
|
|
57
|
+
| Micro: press, icon swap, checkbox, label out | 120–220 ms | button press 160, icon morph 220, label out 120 |
|
|
58
|
+
| Small: chip, label roll, text rise, tooltip text | 300–450 ms | text rise 350, slot deal 350, label roll 450 |
|
|
59
|
+
| Medium: accordion, sheet, card morph, segment draw | 450–650 ms | unfold 500, morph 500, sheet up 620 |
|
|
60
|
+
| Large: card → full screen, photo slide, page | 700–900 ms | card → player 750, photo slide 800, wipe 900 |
|
|
61
|
+
| Scenic: brand intro, scene change, scroll tour | ≤ 1400 ms | scene zoom 1400, tracking settle 1100 |
|
|
62
|
+
|
|
63
|
+
- A move longer than 60 px must not take more than 1.3 s, or less than 110 ms.
|
|
64
|
+
- Exit ≈ 0.7× enter (sheet: up 620 / down 450).
|
|
65
|
+
- Hover responses ≤ 300 ms on the way in. Hover-out may be slower (≤ 600 ms) so the eye can follow.
|
|
66
|
+
|
|
67
|
+
### 2.4 Stagger
|
|
68
|
+
|
|
69
|
+
| Unit | Gap |
|
|
70
|
+
|---|---|
|
|
71
|
+
| Letters | 25–60 ms |
|
|
72
|
+
| Words, list items, tiles | 35–80 ms |
|
|
73
|
+
| Groups, sections, callouts | 100–300 ms |
|
|
74
|
+
|
|
75
|
+
- Keep the whole stagger under about 400 ms for UI. Brand moments may go up to 600 ms.
|
|
76
|
+
- Direction follows reading order or the cause (a wave starts where the user acted).
|
|
77
|
+
- Secondary text trails its headline by 80–250 ms and moves less (10 px vs 18 px).
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## 3. Recipes
|
|
82
|
+
|
|
83
|
+
Search the library first (MCP `search_motions`), add the closest entry with `add_motion` (the file is written for you, so do not retype it) and adapt it. If there is none, use these defaults.
|
|
84
|
+
|
|
85
|
+
| Pattern | Recipe | Library entry |
|
|
86
|
+
|---|---|---|
|
|
87
|
+
| Button press | scale 0.94–0.96 + ~12 % darker, 160 ms, back on release. `whileTap` / `whileHover` get their **own** `transition`; never let them inherit a longer one from the component. | button-press |
|
|
88
|
+
| Async button (buy, save, send) | Label out 120 ms → width morphs to a circle 500 ms `enter` → spinner → tick draws 300 ms → back. Same element throughout. | buy-morph |
|
|
89
|
+
| Bottom sheet / modal | Up 620 ms `0.2,0.9,0.25,1`, down 450 ms `move`, scrim 0 → 18 % black. Escape and scrim tap close it. | bottom-sheet |
|
|
90
|
+
| Tabs, chips, segmented control | Shared `layoutId` pill on `snap` | weather-switch, date-chips |
|
|
91
|
+
| Accordion | Height auto + fade 500 ms `enter`, icon turns 400 ms, one open at a time | capabilities-accordion |
|
|
92
|
+
| Number change | Each digit rolls on `snap`, 50 ms apart left → right; only changed digits move | digit-roll |
|
|
93
|
+
| List / grid arrive | y 18–24 px + fade, 400 ms `enter`, 35 ms stagger | card-stagger, word-cascade |
|
|
94
|
+
| Text reveal (headline) | Each line rises 110 % out of its own mask, 350 ms `enter`, 60 ms per line. Never fade type in. | mask-rise |
|
|
95
|
+
| Swap two values | Both travel past each other on one shared spring; the control rotates 180° | route-swap |
|
|
96
|
+
| Hover on a card | Image scale 1.06 over 900 ms, title rolls 600 ms `enter` | work-card-hover |
|
|
97
|
+
| Custom cursor | `follow` spring; shape morphs on `snap` | circle-cursor |
|
|
98
|
+
| Tooltip / hotspot | Springs out from its anchor on `snap`; the others dim to 35 % | product-hotspots |
|
|
99
|
+
| Destructive or deliberate action | Hold to confirm: linear progress fill (it is a progress bar, so linear is correct), drains back 350 ms `enter` | hold-redeem |
|
|
100
|
+
| Status change across many rows | Flip each tag 260 ms, 100 ms apart; swap content at the edge-on midpoint | tag-flip |
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## 4. Never (measured by `npx phation audit <url>`)
|
|
105
|
+
|
|
106
|
+
| Don't | Detected as |
|
|
107
|
+
|---|---|
|
|
108
|
+
| Linear easing on movement | ≥ 15 frames, travel > 12 px, constant speed |
|
|
109
|
+
| Things that pop | > 40 px jump or > 0.6 opacity jump in one frame |
|
|
110
|
+
| Hard cuts | A large element (> 6000 px²) appearing or vanishing at full opacity |
|
|
111
|
+
| Big overshoot | > 22 % of travel |
|
|
112
|
+
| Sluggish moves | > 60 px taking > 1.3 s |
|
|
113
|
+
| Snappy moves | > 60 px in < 110 ms |
|
|
114
|
+
| Layout-property animation | width, height, top or left changing on ≥ 8 frames |
|
|
115
|
+
| Dropped frames | > 5 % of frames over 25 ms |
|
|
116
|
+
| No response | Nothing moves after the user acts |
|
|
117
|
+
| Ignoring reduced motion | With `prefers-reduced-motion: reduce`, more than 30 % of the travel still plays |
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## 5. UI guardrails (motion does not excuse bad UI)
|
|
122
|
+
|
|
123
|
+
- Text contrast is at least 4.5 : 1, or 3 : 1 for text ≥ 24 px (18.6 px bold), at every frame, including over photos and moving backgrounds. Add a scrim if needed.
|
|
124
|
+
- No text below 10.5 px as shown.
|
|
125
|
+
- Touch targets are at least 24 px on the short side. Prefer 44 px on mobile.
|
|
126
|
+
- Images are never drawn above 1.3× their pixel size.
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## 6. Accessibility
|
|
131
|
+
|
|
132
|
+
- **`prefers-reduced-motion: reduce` is required, not optional.** Every component you write handles it: replace movement with a fade of ≤ 150 ms, stop ambient loops (spinners may keep turning), keep every state change visible.
|
|
133
|
+
|
|
134
|
+
Shortening the duration is not enough: the element must stop travelling. Swap the **targets**, not just the transition:
|
|
135
|
+
|
|
136
|
+
```jsx
|
|
137
|
+
import { useReducedMotion } from 'motion/react'
|
|
138
|
+
const reduce = useReducedMotion()
|
|
139
|
+
const fade = { duration: 0.15, ease: [0.4, 0, 0.2, 1] }
|
|
140
|
+
<motion.div
|
|
141
|
+
initial={reduce ? { opacity: 0 } : { y: '100%' }}
|
|
142
|
+
animate={reduce ? { opacity: 1, transition: fade } : { y: 0, transition: MOTION.open }}
|
|
143
|
+
exit={reduce ? { opacity: 0, transition: fade } : { y: '100%', transition: MOTION.close }}
|
|
144
|
+
/>
|
|
145
|
+
```
|
|
146
|
+
Width or height morphs need the same treatment: under reduce, jump to the end size and cross-fade the content.
|
|
147
|
+
- **Keyboard parity:** anything you can drag or hold can also be done with the keyboard (arrow keys for sliders, Space/Enter to hold or confirm).
|
|
148
|
+
- No flashing more than 3 times per second.
|
|
149
|
+
- Focus moves with the motion: when a sheet opens, focus goes into it; when it closes, focus returns to the trigger.
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## 7. Code conventions
|
|
154
|
+
|
|
155
|
+
Default stack: React + Motion (`import { motion } from 'motion/react'`).
|
|
156
|
+
|
|
157
|
+
```js
|
|
158
|
+
// Every animated component reads its values from one MOTION object.
|
|
159
|
+
export const MOTION = {
|
|
160
|
+
open: { type: 'spring', stiffness: 420, damping: 32, mass: 1 }, // snap
|
|
161
|
+
fade: [0.4, 0, 0.2, 1],
|
|
162
|
+
fadeMs: 200,
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
- **Names:** name keys after what they move (`open`, `rollMs`, `stagger`), not after the token. Comment which token they come from.
|
|
167
|
+
- **Units:** durations live in the object as numbers in **ms** with an `Ms` suffix (`fadeMs: 200`). Never store seconds or prebuilt `{ duration: 0.2 }` objects. Convert at the call site (`duration: m.fadeMs / 1000`), so Studio exports paste in unchanged.
|
|
168
|
+
- **Tuning:** components take `values` (or individual props) merged over `MOTION`, so Phation Studio exports paste straight in.
|
|
169
|
+
- **CSS:** when there is no JS, use the same tokens: `transition: transform 500ms cubic-bezier(0.16, 1, 0.3, 1)`.
|
|
170
|
+
- **Other platforms:** keep the same k / c / m. Reanimated: `withSpring(v, { stiffness, damping, mass })`. SwiftUI: `.interpolatingSpring(mass:stiffness:damping:)`.
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## 8. Workflow for the agent
|
|
175
|
+
|
|
176
|
+
1. **Find** the closest library entry (`search_motions`). `get_motion` gives its spec and `MOTION` values without the source; ask for `code: true` only if you must read it.
|
|
177
|
+
2. **Add, don't retype:** `add_motion` (or `npx phation add <slug>`) writes the file to disk. Edit only what differs: its `MOTION` object, copy, colours and props. If there is no entry, write the motion with the tokens and recipes above, with a `MOTION` object.
|
|
178
|
+
3. **Check** against sections 4–6 yourself: list each motion with its curve or spring, duration and why. Before you finish, confirm each item:
|
|
179
|
+
- [ ] reduced motion handled in every component you touched (§6)
|
|
180
|
+
- [ ] press and hover have their own short transitions (§3)
|
|
181
|
+
- [ ] durations in `MOTION` are ms numbers (§7)
|
|
182
|
+
- [ ] keyboard parity, and focus moves into opened surfaces and back (§6)
|
|
183
|
+
- [ ] no linear movement except ambient loops; exits ≈ 0.7× enters (§1, §2)
|
|
184
|
+
4. **Verify** when the app runs locally: `npx phation audit <url> --do click:<selector> …` (or the MCP tool `audit_motion`) with the actions that trigger the motion. Fix every blocker and every `ignores-reduced-motion`, then re-run until it passes.
|
|
185
|
+
5. **Report** to the user: what moves, the values used, and any rule you deliberately broke.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<!-- phation:start v1.0 — managed by `npx phation init claude`; edit outside the markers -->
|
|
2
|
+
## Motion
|
|
3
|
+
|
|
4
|
+
Before writing or changing any UI motion (animations, transitions, hover/press states, gestures, loading/success states), load the **phation** skill and follow it: use its curve, spring and duration tokens, put values in a `MOTION` object (ms), handle reduced motion, and report the values you used.
|
|
5
|
+
<!-- phation:end -->
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: phation
|
|
3
|
+
description: "Required for any UI motion work: Pham Huy's Phation standard (curve, spring and duration tokens, choreography, recipes, reduced motion). Use whenever adding or changing any UI animation, transition, hover or press state, gesture response, loading or success state, page or route transition, or when the user asks to make an interface feel smoother, more tactile, calmer, more alive or more polished, or asks to review or fix motion, including any code that uses motion/react, framer-motion, CSS transitions or keyframes."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Phation Standard (core)
|
|
7
|
+
|
|
8
|
+
Short rules for every motion task. The full standard (recipes, examples, accessibility code) is in `.phation/STANDARD.md`: open only the section you need (§3 recipes, §6 accessibility, §7 code). With the MCP server, `get_standard` with a section does the same.
|
|
9
|
+
|
|
10
|
+
**Workflow, token-lean:** `search_motions` → `add_motion` writes the file to disk, so never retype it → edit only its `MOTION` object, copy and styles → `audit_motion` with the actions that trigger it, fix blockers, re-run. A Studio link (`…/m/<slug>?…`) goes in `from`.
|
|
11
|
+
|
|
12
|
+
**Rules:** motion explains a change · one main motion at a time (secondary ≥ 80 ms later) · morph the touched element instead of cross-fading · animate transform and opacity only (`layout` / `layoutId` for size) · exits ≈ 0.7× enters · interruptible: springs for anything the user drives.
|
|
13
|
+
|
|
14
|
+
**Curves:** enter `0.16, 1, 0.3, 1` (default) · move `0.65, 0, 0.35, 1` (A → B on screen) · fade `0.4, 0, 0.2, 1` (opacity, colour) · exit `0.7, 0, 0.84, 0` (≤ 250 ms, leaves the screen) · overshoot `0.34, 1.56, 0.64, 1` (once per screen). Never linear for movement (spinners and marquees only).
|
|
15
|
+
|
|
16
|
+
**Springs (k / c / m):** snap 420 / 32 / 1 controls, pills, rolls · pop 400 / 20 / 1 small things appearing · soft 170 / 22 / 1 large surfaces · follow 420 / 34 / 0.6 pointer-following · bounce 160 / 14 / 1 one celebration per screen. Overshoot < 22 %. Close with ζ ≥ 1 (k220 c30).
|
|
17
|
+
|
|
18
|
+
**Durations:** micro 120–220 ms · small 300–450 · medium 450–650 · large 700–900 · scenic ≤ 1400. Moves over 60 px: 110 ms to 1.3 s. Hover in ≤ 300 ms. **Stagger:** letters 25–60 ms · items 35–80 · groups 100–300, whole stagger ≤ 400 ms.
|
|
19
|
+
|
|
20
|
+
**Never:** linear movement · pops and hard cuts (fade + 18–24 px rise instead) · overshoot over 22 % · animating width, height, top or left · ignoring reduced motion.
|
|
21
|
+
|
|
22
|
+
**Reduced motion (required):** with `useReducedMotion()`, swap the targets for a ≤ 150 ms fade and stop ambient loops. A shorter duration is not enough.
|
|
23
|
+
|
|
24
|
+
**Code:** values in one `export const MOTION = { … }`; durations as ms numbers (`fadeMs: 200`), converted at the call site; components accept `values` merged over `MOTION`. Keyboard parity for drag and hold; focus moves into opened surfaces and back.
|
|
25
|
+
|
|
26
|
+
**Report** the values you used and any rule you broke on purpose.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<!-- phation:start v1.0 — managed by `npx phation init codex`; edit outside the markers -->
|
|
2
|
+
## Motion (Phation Standard)
|
|
3
|
+
|
|
4
|
+
When adding or changing any UI animation, transition, hover or press state, gesture response, loading or success state, page or route transition, or when the user asks to make an interface feel smoother, more tactile, calmer, more alive or more polished, or asks to review or fix motion, follow this standard.
|
|
5
|
+
|
|
6
|
+
Short rules for every motion task. The full standard (recipes, examples, accessibility code) is in `.phation/STANDARD.md`: open only the section you need (§3 recipes, §6 accessibility, §7 code). With the MCP server, `get_standard` with a section does the same.
|
|
7
|
+
|
|
8
|
+
**Workflow, token-lean:** `search_motions` → `add_motion` writes the file to disk, so never retype it → edit only its `MOTION` object, copy and styles → `audit_motion` with the actions that trigger it, fix blockers, re-run. A Studio link (`…/m/<slug>?…`) goes in `from`.
|
|
9
|
+
|
|
10
|
+
**Rules:** motion explains a change · one main motion at a time (secondary ≥ 80 ms later) · morph the touched element instead of cross-fading · animate transform and opacity only (`layout` / `layoutId` for size) · exits ≈ 0.7× enters · interruptible: springs for anything the user drives.
|
|
11
|
+
|
|
12
|
+
**Curves:** enter `0.16, 1, 0.3, 1` (default) · move `0.65, 0, 0.35, 1` (A → B on screen) · fade `0.4, 0, 0.2, 1` (opacity, colour) · exit `0.7, 0, 0.84, 0` (≤ 250 ms, leaves the screen) · overshoot `0.34, 1.56, 0.64, 1` (once per screen). Never linear for movement (spinners and marquees only).
|
|
13
|
+
|
|
14
|
+
**Springs (k / c / m):** snap 420 / 32 / 1 controls, pills, rolls · pop 400 / 20 / 1 small things appearing · soft 170 / 22 / 1 large surfaces · follow 420 / 34 / 0.6 pointer-following · bounce 160 / 14 / 1 one celebration per screen. Overshoot < 22 %. Close with ζ ≥ 1 (k220 c30).
|
|
15
|
+
|
|
16
|
+
**Durations:** micro 120–220 ms · small 300–450 · medium 450–650 · large 700–900 · scenic ≤ 1400. Moves over 60 px: 110 ms to 1.3 s. Hover in ≤ 300 ms. **Stagger:** letters 25–60 ms · items 35–80 · groups 100–300, whole stagger ≤ 400 ms.
|
|
17
|
+
|
|
18
|
+
**Never:** linear movement · pops and hard cuts (fade + 18–24 px rise instead) · overshoot over 22 % · animating width, height, top or left · ignoring reduced motion.
|
|
19
|
+
|
|
20
|
+
**Reduced motion (required):** with `useReducedMotion()`, swap the targets for a ≤ 150 ms fade and stop ambient loops. A shorter duration is not enough.
|
|
21
|
+
|
|
22
|
+
**Code:** values in one `export const MOTION = { … }`; durations as ms numbers (`fadeMs: 200`), converted at the call site; components accept `values` merged over `MOTION`. Keyboard parity for drag and hold; focus moves into opened surfaces and back.
|
|
23
|
+
|
|
24
|
+
**Report** the values you used and any rule you broke on purpose.
|
|
25
|
+
<!-- phation:end -->
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "Phation standard. Apply when adding or changing any UI animation, transition, hover or press state, gesture response, loading or success state, page or route transition, or when the user asks to make an interface feel smoother, more tactile, calmer, more alive or more polished, or asks to review or fix motion."
|
|
3
|
+
globs: "**/*.{js,jsx,ts,tsx,vue,svelte,css,scss}"
|
|
4
|
+
alwaysApply: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Phation Standard (core)
|
|
8
|
+
|
|
9
|
+
Short rules for every motion task. The full standard (recipes, examples, accessibility code) is in `.phation/STANDARD.md`: open only the section you need (§3 recipes, §6 accessibility, §7 code). With the MCP server, `get_standard` with a section does the same.
|
|
10
|
+
|
|
11
|
+
**Workflow, token-lean:** `search_motions` → `add_motion` writes the file to disk, so never retype it → edit only its `MOTION` object, copy and styles → `audit_motion` with the actions that trigger it, fix blockers, re-run. A Studio link (`…/m/<slug>?…`) goes in `from`.
|
|
12
|
+
|
|
13
|
+
**Rules:** motion explains a change · one main motion at a time (secondary ≥ 80 ms later) · morph the touched element instead of cross-fading · animate transform and opacity only (`layout` / `layoutId` for size) · exits ≈ 0.7× enters · interruptible: springs for anything the user drives.
|
|
14
|
+
|
|
15
|
+
**Curves:** enter `0.16, 1, 0.3, 1` (default) · move `0.65, 0, 0.35, 1` (A → B on screen) · fade `0.4, 0, 0.2, 1` (opacity, colour) · exit `0.7, 0, 0.84, 0` (≤ 250 ms, leaves the screen) · overshoot `0.34, 1.56, 0.64, 1` (once per screen). Never linear for movement (spinners and marquees only).
|
|
16
|
+
|
|
17
|
+
**Springs (k / c / m):** snap 420 / 32 / 1 controls, pills, rolls · pop 400 / 20 / 1 small things appearing · soft 170 / 22 / 1 large surfaces · follow 420 / 34 / 0.6 pointer-following · bounce 160 / 14 / 1 one celebration per screen. Overshoot < 22 %. Close with ζ ≥ 1 (k220 c30).
|
|
18
|
+
|
|
19
|
+
**Durations:** micro 120–220 ms · small 300–450 · medium 450–650 · large 700–900 · scenic ≤ 1400. Moves over 60 px: 110 ms to 1.3 s. Hover in ≤ 300 ms. **Stagger:** letters 25–60 ms · items 35–80 · groups 100–300, whole stagger ≤ 400 ms.
|
|
20
|
+
|
|
21
|
+
**Never:** linear movement · pops and hard cuts (fade + 18–24 px rise instead) · overshoot over 22 % · animating width, height, top or left · ignoring reduced motion.
|
|
22
|
+
|
|
23
|
+
**Reduced motion (required):** with `useReducedMotion()`, swap the targets for a ≤ 150 ms fade and stop ambient loops. A shorter duration is not enough.
|
|
24
|
+
|
|
25
|
+
**Code:** values in one `export const MOTION = { … }`; durations as ms numbers (`fadeMs: 200`), converted at the call site; components accept `values` merged over `MOTION`. Keyboard parity for drag and hold; focus moves into opened surfaces and back.
|
|
26
|
+
|
|
27
|
+
**Report** the values you used and any rule you broke on purpose.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "1.0",
|
|
3
|
+
"when": "adding or changing any UI animation, transition, hover or press state, gesture response, loading or success state, page or route transition, or when the user asks to make an interface feel smoother, more tactile, calmer, more alive or more polished, or asks to review or fix motion"
|
|
4
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
applyTo: "**/*.{js,jsx,ts,tsx,vue,svelte,css,scss}"
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Phation Standard (core)
|
|
6
|
+
|
|
7
|
+
Short rules for every motion task. The full standard (recipes, examples, accessibility code) is in `.phation/STANDARD.md`: open only the section you need (§3 recipes, §6 accessibility, §7 code). With the MCP server, `get_standard` with a section does the same.
|
|
8
|
+
|
|
9
|
+
**Workflow, token-lean:** `search_motions` → `add_motion` writes the file to disk, so never retype it → edit only its `MOTION` object, copy and styles → `audit_motion` with the actions that trigger it, fix blockers, re-run. A Studio link (`…/m/<slug>?…`) goes in `from`.
|
|
10
|
+
|
|
11
|
+
**Rules:** motion explains a change · one main motion at a time (secondary ≥ 80 ms later) · morph the touched element instead of cross-fading · animate transform and opacity only (`layout` / `layoutId` for size) · exits ≈ 0.7× enters · interruptible: springs for anything the user drives.
|
|
12
|
+
|
|
13
|
+
**Curves:** enter `0.16, 1, 0.3, 1` (default) · move `0.65, 0, 0.35, 1` (A → B on screen) · fade `0.4, 0, 0.2, 1` (opacity, colour) · exit `0.7, 0, 0.84, 0` (≤ 250 ms, leaves the screen) · overshoot `0.34, 1.56, 0.64, 1` (once per screen). Never linear for movement (spinners and marquees only).
|
|
14
|
+
|
|
15
|
+
**Springs (k / c / m):** snap 420 / 32 / 1 controls, pills, rolls · pop 400 / 20 / 1 small things appearing · soft 170 / 22 / 1 large surfaces · follow 420 / 34 / 0.6 pointer-following · bounce 160 / 14 / 1 one celebration per screen. Overshoot < 22 %. Close with ζ ≥ 1 (k220 c30).
|
|
16
|
+
|
|
17
|
+
**Durations:** micro 120–220 ms · small 300–450 · medium 450–650 · large 700–900 · scenic ≤ 1400. Moves over 60 px: 110 ms to 1.3 s. Hover in ≤ 300 ms. **Stagger:** letters 25–60 ms · items 35–80 · groups 100–300, whole stagger ≤ 400 ms.
|
|
18
|
+
|
|
19
|
+
**Never:** linear movement · pops and hard cuts (fade + 18–24 px rise instead) · overshoot over 22 % · animating width, height, top or left · ignoring reduced motion.
|
|
20
|
+
|
|
21
|
+
**Reduced motion (required):** with `useReducedMotion()`, swap the targets for a ≤ 150 ms fade and stop ambient loops. A shorter duration is not enough.
|
|
22
|
+
|
|
23
|
+
**Code:** values in one `export const MOTION = { … }`; durations as ms numbers (`fadeMs: 200`), converted at the call site; components accept `values` merged over `MOTION`. Keyboard parity for drag and hold; focus moves into opened surfaces and back.
|
|
24
|
+
|
|
25
|
+
**Report** the values you used and any rule you broke on purpose.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
---
|
|
2
|
+
trigger: model_decision
|
|
3
|
+
description: "Phation standard. Apply when adding or changing any UI animation, transition, hover or press state, gesture response, loading or success state, page or route transition, or when the user asks to make an interface feel smoother, more tactile, calmer, more alive or more polished, or asks to review or fix motion."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Phation Standard (core)
|
|
7
|
+
|
|
8
|
+
Short rules for every motion task. The full standard (recipes, examples, accessibility code) is in `.phation/STANDARD.md`: open only the section you need (§3 recipes, §6 accessibility, §7 code). With the MCP server, `get_standard` with a section does the same.
|
|
9
|
+
|
|
10
|
+
**Workflow, token-lean:** `search_motions` → `add_motion` writes the file to disk, so never retype it → edit only its `MOTION` object, copy and styles → `audit_motion` with the actions that trigger it, fix blockers, re-run. A Studio link (`…/m/<slug>?…`) goes in `from`.
|
|
11
|
+
|
|
12
|
+
**Rules:** motion explains a change · one main motion at a time (secondary ≥ 80 ms later) · morph the touched element instead of cross-fading · animate transform and opacity only (`layout` / `layoutId` for size) · exits ≈ 0.7× enters · interruptible: springs for anything the user drives.
|
|
13
|
+
|
|
14
|
+
**Curves:** enter `0.16, 1, 0.3, 1` (default) · move `0.65, 0, 0.35, 1` (A → B on screen) · fade `0.4, 0, 0.2, 1` (opacity, colour) · exit `0.7, 0, 0.84, 0` (≤ 250 ms, leaves the screen) · overshoot `0.34, 1.56, 0.64, 1` (once per screen). Never linear for movement (spinners and marquees only).
|
|
15
|
+
|
|
16
|
+
**Springs (k / c / m):** snap 420 / 32 / 1 controls, pills, rolls · pop 400 / 20 / 1 small things appearing · soft 170 / 22 / 1 large surfaces · follow 420 / 34 / 0.6 pointer-following · bounce 160 / 14 / 1 one celebration per screen. Overshoot < 22 %. Close with ζ ≥ 1 (k220 c30).
|
|
17
|
+
|
|
18
|
+
**Durations:** micro 120–220 ms · small 300–450 · medium 450–650 · large 700–900 · scenic ≤ 1400. Moves over 60 px: 110 ms to 1.3 s. Hover in ≤ 300 ms. **Stagger:** letters 25–60 ms · items 35–80 · groups 100–300, whole stagger ≤ 400 ms.
|
|
19
|
+
|
|
20
|
+
**Never:** linear movement · pops and hard cuts (fade + 18–24 px rise instead) · overshoot over 22 % · animating width, height, top or left · ignoring reduced motion.
|
|
21
|
+
|
|
22
|
+
**Reduced motion (required):** with `useReducedMotion()`, swap the targets for a ≤ 150 ms fade and stop ambient loops. A shorter duration is not enough.
|
|
23
|
+
|
|
24
|
+
**Code:** values in one `export const MOTION = { … }`; durations as ms numbers (`fadeMs: 200`), converted at the call site; components accept `values` merged over `MOTION`. Keyboard parity for drag and hold; focus moves into opened surfaces and back.
|
|
25
|
+
|
|
26
|
+
**Report** the values you used and any rule you broke on purpose.
|
package/lib.mjs
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
// Phation core: shared by the MCP server (bin/server.mjs) and the CLI (bin/cli.mjs).
|
|
2
|
+
// Data comes from data/entries.json, exported from the library by scripts/export-entries.mjs.
|
|
3
|
+
import fs from 'fs'
|
|
4
|
+
import os from 'os'
|
|
5
|
+
import path from 'path'
|
|
6
|
+
import { fileURLToPath } from 'url'
|
|
7
|
+
import { decodeValues, applyValues, slugOfLink } from './share.mjs'
|
|
8
|
+
|
|
9
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
|
10
|
+
// The published package carries data/entries.json: metadata, specs and MOTION values, no source. A local checkout of the
|
|
11
|
+
// library also has data/entries.full.json (with source); PHATION_REMOTE=1 ignores it to test the published behaviour.
|
|
12
|
+
const FULL = path.join(HERE, 'data/entries.full.json')
|
|
13
|
+
const LOCAL = fs.existsSync(FULL) && !process.env.PHATION_REMOTE
|
|
14
|
+
const DATA = JSON.parse(fs.readFileSync(LOCAL ? FULL : path.join(HERE, 'data/entries.json'), 'utf8'))
|
|
15
|
+
export const ENTRIES = DATA.entries
|
|
16
|
+
export const CATEGORIES = DATA.categories
|
|
17
|
+
export const SITE = 'https://phation.app'
|
|
18
|
+
const API = process.env.PHATION_API || SITE
|
|
19
|
+
|
|
20
|
+
// ---------------- Pro license ----------------
|
|
21
|
+
// Free: list, search, show (spec + MOTION values), the standard, init. Pro: add, source, audit, animate.
|
|
22
|
+
// The key comes from PHATION_KEY or ~/.config/phation/license.json (written by `phation login <key>`).
|
|
23
|
+
const CONF = path.join(process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config'), 'phation', 'license.json')
|
|
24
|
+
const readConf = () => { try { return JSON.parse(fs.readFileSync(CONF, 'utf8')) } catch { return null } }
|
|
25
|
+
export const licenseKey = () => process.env.PHATION_KEY || readConf()?.key || null
|
|
26
|
+
export const PRO_HINT = 'This is part of Phation Pro. Get a license at https://phation.app/pricing, then run: npx phation login <license-key> (or set PHATION_KEY).'
|
|
27
|
+
async function api(pathname, key = licenseKey()) {
|
|
28
|
+
if (!key) throw new Error(PRO_HINT)
|
|
29
|
+
let r
|
|
30
|
+
try { r = await fetch(API + pathname, { headers: { Authorization: `Bearer ${key}`, 'User-Agent': 'phation-cli' } }) } catch { throw new Error(`Could not reach ${API}. Check your connection.`) }
|
|
31
|
+
const d = await r.json().catch(() => ({}))
|
|
32
|
+
if (r.status === 401) throw new Error(`Your license key was not accepted (wrong, refunded or expired). ${PRO_HINT}`)
|
|
33
|
+
if (!r.ok) throw new Error(d.message || `${API} answered ${r.status}.`)
|
|
34
|
+
return d
|
|
35
|
+
}
|
|
36
|
+
/** Check a key with phation.app and remember it. */
|
|
37
|
+
export async function login(key) {
|
|
38
|
+
const d = await api('/api/source?check=1', String(key || '').trim())
|
|
39
|
+
fs.mkdirSync(path.dirname(CONF), { recursive: true })
|
|
40
|
+
fs.writeFileSync(CONF, JSON.stringify({ key: String(key).trim(), email: d.email, kind: d.kind, until: d.until, checked: Date.now() }, null, 2), { mode: 0o600 })
|
|
41
|
+
return { email: d.email, kind: d.kind, until: d.until, file: CONF }
|
|
42
|
+
}
|
|
43
|
+
export function logout() { try { fs.rmSync(CONF) } catch {} return CONF }
|
|
44
|
+
/** Pro gate for local tools (audit, animate): a key checked online within 7 days, re-checked when older. */
|
|
45
|
+
export async function requirePro() {
|
|
46
|
+
if (LOCAL) return
|
|
47
|
+
const c = readConf(), key = licenseKey()
|
|
48
|
+
if (!key) throw new Error(PRO_HINT)
|
|
49
|
+
if (c?.key === key && Date.now() - (c.checked || 0) < 7 * 864e5) return
|
|
50
|
+
const d = await api('/api/source?check=1', key)
|
|
51
|
+
if (c?.key === key) fs.writeFileSync(CONF, JSON.stringify({ ...c, kind: d.kind, until: d.until, checked: Date.now() }, null, 2), { mode: 0o600 })
|
|
52
|
+
}
|
|
53
|
+
/** An entry's React source: local in a library checkout, otherwise from phation.app with the Pro key. */
|
|
54
|
+
export async function getCode(e) {
|
|
55
|
+
if (e.code) return e.code
|
|
56
|
+
return (await api(`/api/source?slug=${encodeURIComponent(e.slug)}`)).code
|
|
57
|
+
}
|
|
58
|
+
export const motionBlock = e => e.motion ?? ((e.code || '').match(/^export const MOTION = \{[\s\S]*?\n\}/m) || [''])[0]
|
|
59
|
+
|
|
60
|
+
// Words people use for a feeling, mapped to the words entries use for the mechanism.
|
|
61
|
+
const FEEL = {
|
|
62
|
+
tactile: ['press', 'spring', 'tap', 'scale', 'button', 'hold'], physical: ['spring', 'drag', 'flip', 'release'],
|
|
63
|
+
snappy: ['press', 'spring', 'snap'], calm: ['settle', 'ease', 'fade', 'sheet', 'no overshoot'], smooth: ['ease', 'settle', 'shared'],
|
|
64
|
+
playful: ['bounce', 'overshoot', 'pop', 'spring'], bouncy: ['bounce', 'overshoot', 'spring'], premium: ['wipe', 'settle', 'light sweep', 'tracking'],
|
|
65
|
+
alive: ['roll', 'digit', 'breath', 'pulse'], stepper: ['quantity', 'digit'], quantity: ['digit', 'total'], tab: ['chip', 'ring', 'shared', 'pill'], price: ['digit', 'roll', 'total', 'price'], number: ['digit', 'roll', 'count'], counter: ['digit', 'roll', 'count'],
|
|
66
|
+
checkout: ['buy', 'payment', 'sheet', 'price'], cart: ['quantity', 'digit', 'buy'], loading: ['spinner', 'morph', 'progress'], progress: ['morph', 'hold', 'fill'],
|
|
67
|
+
success: ['check', 'confirm', 'tick'], modal: ['sheet', 'scrim', 'expand'], drawer: ['sheet'], list: ['stagger', 'rows', 'list'], grid: ['stagger', 'grid'],
|
|
68
|
+
headline: ['word', 'mask', 'text', 'rise'], heading: ['word', 'mask', 'text'], title: ['word', 'mask', 'roll'], logo: ['wordmark', 'letters'],
|
|
69
|
+
hover: ['hover', 'cursor', 'magnetic'], cursor: ['cursor', 'follow'], swipe: ['drag', 'swipe', 'slider'], slider: ['slider', 'drag', 'snap'],
|
|
70
|
+
tabs: ['tab', 'chip', 'pill', 'shared'], toggle: ['switch', 'toggle', 'chip'], theme: ['day', 'night', 'theme'], dark: ['night', 'theme'],
|
|
71
|
+
onboarding: ['stagger', 'word', 'callout'], tooltip: ['hotspot', 'tooltip', 'callout'], chart: ['donut', 'draw', 'count'], voice: ['orb', 'listen', 'assistant'],
|
|
72
|
+
scroll: ['scroll', 'reveal'], reveal: ['reveal', 'mask', 'wipe', 'rise'], status: ['tag', 'flip', 'status', 'wave'], select: ['checkbox', 'chip', 'ring'],
|
|
73
|
+
}
|
|
74
|
+
const norm = s => String(s).toLowerCase()
|
|
75
|
+
const STOP = new Set('a an the it its this that these to for of and or with my our your their when on in into at as be is are was should could would make made feel feels feeling like more less some very really want need add use using please'.split(' '))
|
|
76
|
+
const words = s => norm(s).split(/[^a-z0-9]+/).filter(w => w.length > 1 && !STOP.has(w))
|
|
77
|
+
|
|
78
|
+
export function search(query = '', { category, limit = 8 } = {}) {
|
|
79
|
+
const q = words(query), expanded = new Set(q)
|
|
80
|
+
for (const w of q) for (const x of FEEL[w] || FEEL[w.replace(/s$/, '')] || []) expanded.add(x)
|
|
81
|
+
const scored = ENTRIES.filter(e => !category || norm(e.category) === norm(category)).map(e => {
|
|
82
|
+
const fields = [[e.name, 4], [(e.tags || []).join(' '), 3], [e.category, 2], [e.hint || '', 1], [e.description, 1.5], [Object.entries(e.spec).flat().join(' '), 1], [e.from, 0.5]]
|
|
83
|
+
let score = 0
|
|
84
|
+
for (const t of expanded) {
|
|
85
|
+
const direct = q.includes(t) ? 1 : 0.35
|
|
86
|
+
for (const [f, w] of fields) if (norm(f).includes(t)) score += w * direct
|
|
87
|
+
}
|
|
88
|
+
return { e, score }
|
|
89
|
+
})
|
|
90
|
+
const hits = q.length ? scored.filter(s => s.score > 0).sort((a, b) => b.score - a.score) : scored
|
|
91
|
+
return hits.slice(0, limit).map(({ e, score }) => ({ ...summary(e), score: Math.round(score * 10) / 10 }))
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export const summary = e => ({ slug: e.slug, name: e.name, category: e.category, tags: e.tags || [], description: e.description, interaction: e.hint, url: `${SITE}/m/${e.slug}` })
|
|
95
|
+
export const get = slug => ENTRIES.find(e => e.slug === slug) || null
|
|
96
|
+
|
|
97
|
+
export function suggest(slug) {
|
|
98
|
+
const s = norm(slug)
|
|
99
|
+
return ENTRIES.map(e => e.slug).filter(x => x.includes(s) || s.includes(x) || x.split('-').some(p => s.includes(p))).slice(0, 5)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Copies an entry into a project: the component file plus the media it references.
|
|
104
|
+
* @param {string} slug
|
|
105
|
+
* `from` = a Studio share link (or its query): its tuned values are written into the file's MOTION object.
|
|
106
|
+
* @param {{ projectRoot?: string, dir?: string, publicDir?: string, force?: boolean, from?: string }} opts
|
|
107
|
+
*/
|
|
108
|
+
export async function add(slug, { projectRoot = process.cwd(), dir = 'src/motion', publicDir = 'public', force = false, from } = {}) {
|
|
109
|
+
if (!slug && from) slug = slugOfLink(from)
|
|
110
|
+
const linked = from ? slugOfLink(from) : null
|
|
111
|
+
if (linked && slug && linked !== slug) throw new Error(`The link is for "${linked}", not "${slug}".`)
|
|
112
|
+
const e = get(slug)
|
|
113
|
+
if (!e) throw new Error(`No entry "${slug}".${suggest(slug).length ? ' Did you mean: ' + suggest(slug).join(', ') + '?' : ''}`)
|
|
114
|
+
const root = path.resolve(projectRoot)
|
|
115
|
+
if (!fs.existsSync(root)) throw new Error(`Project folder not found: ${root}`)
|
|
116
|
+
const target = path.join(root, dir, e.file)
|
|
117
|
+
if (fs.existsSync(target) && !force) throw new Error(`${path.relative(root, target)} already exists. Pass force to overwrite it.`)
|
|
118
|
+
let code = await getCode(e), tuned = null
|
|
119
|
+
fs.mkdirSync(path.dirname(target), { recursive: true })
|
|
120
|
+
if (from) {
|
|
121
|
+
const vals = decodeValues(from)
|
|
122
|
+
if (!Object.keys(vals).length) throw new Error('The link has no tuned values. Change something in the Studio, then press Share.')
|
|
123
|
+
const link = from.includes('://') ? from.trim() : `${SITE}/m/${e.slug}?${from.replace(/^[^?]*\?/, '')}`
|
|
124
|
+
const r = applyValues(code, vals, `tuned in Phation Studio: ${link}`)
|
|
125
|
+
code = r.code; tuned = { applied: r.applied, skipped: r.skipped }
|
|
126
|
+
}
|
|
127
|
+
fs.writeFileSync(target, code)
|
|
128
|
+
const written = [path.relative(root, target)]
|
|
129
|
+
for (const a of e.assets) {
|
|
130
|
+
const src = path.join(HERE, 'data/public', a), dst = path.join(root, publicDir, a)
|
|
131
|
+
if (fs.existsSync(dst) && !force) continue
|
|
132
|
+
fs.mkdirSync(path.dirname(dst), { recursive: true })
|
|
133
|
+
if (fs.existsSync(src)) fs.copyFileSync(src, dst)
|
|
134
|
+
else { // the published package has no media: fetch it from the site (they are public demo images)
|
|
135
|
+
const r = await fetch(SITE + a).catch(() => null)
|
|
136
|
+
if (!r?.ok) continue
|
|
137
|
+
fs.writeFileSync(dst, Buffer.from(await r.arrayBuffer()))
|
|
138
|
+
}
|
|
139
|
+
written.push(path.relative(root, dst))
|
|
140
|
+
}
|
|
141
|
+
// which runtime packages the project still needs
|
|
142
|
+
let have = {}
|
|
143
|
+
try { const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')); have = { ...pkg.dependencies, ...pkg.devDependencies } } catch {}
|
|
144
|
+
const pkgOf = d => d.startsWith('@') ? d.split('/').slice(0, 2).join('/') : d.split('/')[0]
|
|
145
|
+
const need = [...new Set(e.dependencies.map(pkgOf))].filter(d => !have[d])
|
|
146
|
+
const name = e.file.replace(/\.jsx?$/, '')
|
|
147
|
+
return {
|
|
148
|
+
entry: e.slug, files: written, missingPackages: need, tuned,
|
|
149
|
+
install: need.length ? `npm install ${need.join(' ')}` : null,
|
|
150
|
+
usage: `import ${name} from './${path.posix.join(dir.replace(/^src\/?/, ''), name)}'\n\n<${name} />`,
|
|
151
|
+
note: 'The demo plays its intro on mount. Its colours, type and copy are the source product\'s: adapt them to your design system and keep the motion values in the spec.',
|
|
152
|
+
spec: e.spec,
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// ---------------- Phation Standard (rules for coding agents) ----------------
|
|
157
|
+
const STD_DIR = path.join(HERE, 'data/standard')
|
|
158
|
+
export const STANDARD = fs.existsSync(path.join(STD_DIR, 'STANDARD.md')) ? fs.readFileSync(path.join(STD_DIR, 'STANDARD.md'), 'utf8') : ''
|
|
159
|
+
export const CORE = fs.existsSync(path.join(STD_DIR, 'CORE.md')) ? fs.readFileSync(path.join(STD_DIR, 'CORE.md'), 'utf8') : STANDARD
|
|
160
|
+
export const STANDARD_VERSION = fs.existsSync(path.join(STD_DIR, 'meta.json')) ? JSON.parse(fs.readFileSync(path.join(STD_DIR, 'meta.json'), 'utf8')).version : '0'
|
|
161
|
+
|
|
162
|
+
/** One section by number or heading words ("2.2", "springs", "accessibility"); the short core when omitted, everything with "all". */
|
|
163
|
+
export function standardSection(q) {
|
|
164
|
+
if (!q || String(q).toLowerCase().trim() === 'core') return CORE
|
|
165
|
+
if (String(q).toLowerCase().trim() === 'all') return STANDARD
|
|
166
|
+
const parts = STANDARD.split(/^(?=#{2,3} )/m), k = String(q).toLowerCase().trim()
|
|
167
|
+
const hit = parts.find(p => { const h = p.split('\n')[0].toLowerCase(); return h.replace(/^#+\s*/, '').startsWith(k) || h.includes(k) })
|
|
168
|
+
return hit ? hit.trim() : null
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// where each tool reads project rules from
|
|
172
|
+
export const TOOLS = {
|
|
173
|
+
claude: { file: '.claude/skills/phation/SKILL.md', src: 'claude/SKILL.md', label: 'Claude Code skill', also: ['claude-md', 'full'] },
|
|
174
|
+
'claude-md': { file: 'CLAUDE.md', src: 'claude/CLAUDE.block.md', label: 'CLAUDE.md pointer (always loaded, so the skill is used every time)', merge: true, hidden: true },
|
|
175
|
+
|
|
176
|
+
// the full standard, read by section only when needed (every rule file above carries just the ~600-token core)
|
|
177
|
+
full: { file: '.phation/STANDARD.md', src: 'STANDARD.md', label: 'Full standard (read on demand)', hidden: true },
|
|
178
|
+
cursor: { file: '.cursor/rules/phation.mdc', src: 'cursor/phation.mdc', label: 'Cursor rule', also: ['full'] },
|
|
179
|
+
codex: { file: 'AGENTS.md', src: 'codex/AGENTS.block.md', label: 'AGENTS.md section (Codex and other AGENTS.md readers)', merge: true, also: ['full'] },
|
|
180
|
+
windsurf: { file: '.windsurf/rules/phation.md', src: 'windsurf/phation.md', label: 'Windsurf rule', also: ['full'] },
|
|
181
|
+
vscode: { file: '.github/instructions/phation.instructions.md', src: 'vscode/phation.instructions.md', label: 'VS Code / Copilot instructions', also: ['full'] },
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Writes the standard into a project for one tool (or 'all').
|
|
186
|
+
* AGENTS.md is merged: only the block between the phation markers is replaced, the rest of the file is kept.
|
|
187
|
+
*/
|
|
188
|
+
export function install(tool = 'all', { projectRoot = process.cwd(), force = false } = {}) {
|
|
189
|
+
const base = tool === 'all' ? Object.keys(TOOLS).filter(n => !TOOLS[n].hidden) : [tool]
|
|
190
|
+
const names = [...new Set(base.flatMap(n => [n, ...[].concat(TOOLS[n]?.also || [])]))]
|
|
191
|
+
const bad = names.filter(n => !TOOLS[n] || (TOOLS[n].hidden && !base.some(b => [].concat(TOOLS[b]?.also || []).includes(n)))); if (bad.length) throw new Error(`Unknown tool "${bad[0]}". Use one of: ${Object.keys(TOOLS).filter(k => !TOOLS[k].hidden).join(', ')}, all`)
|
|
192
|
+
const root = path.resolve(projectRoot)
|
|
193
|
+
if (!fs.existsSync(root)) throw new Error(`Project folder not found: ${root}`)
|
|
194
|
+
const res = []
|
|
195
|
+
for (const n of names) {
|
|
196
|
+
const t = TOOLS[n], dst = path.join(root, t.file), txt = fs.readFileSync(path.join(STD_DIR, t.src), 'utf8')
|
|
197
|
+
fs.mkdirSync(path.dirname(dst), { recursive: true })
|
|
198
|
+
if (t.merge) {
|
|
199
|
+
const cur = fs.existsSync(dst) ? fs.readFileSync(dst, 'utf8') : ''
|
|
200
|
+
const re = /<!-- phation:start[\s\S]*?<!-- phation:end -->\n?/
|
|
201
|
+
const next = re.test(cur) ? cur.replace(re, txt) : (cur ? cur.replace(/\n*$/, '\n\n') : '# AGENTS.md\n\n') + txt
|
|
202
|
+
const state = !cur ? 'created' : re.test(cur) ? (cur === next ? 'unchanged' : 'updated') : 'added section'
|
|
203
|
+
if (cur !== next) fs.writeFileSync(dst, next)
|
|
204
|
+
res.push({ tool: n, label: t.label, file: t.file, state })
|
|
205
|
+
} else {
|
|
206
|
+
const cur = fs.existsSync(dst) ? fs.readFileSync(dst, 'utf8') : null
|
|
207
|
+
// overwrite only our own file (same name, starts with our header) unless forced
|
|
208
|
+
if (cur !== null && cur !== txt && !force && !/Phation/.test(cur)) { res.push({ tool: n, label: t.label, file: t.file, state: 'skipped: file exists and is not ours (pass force)' }); continue }
|
|
209
|
+
if (cur !== txt) fs.writeFileSync(dst, txt)
|
|
210
|
+
res.push({ tool: n, label: t.label, file: t.file, state: cur === null ? 'created' : cur === txt ? 'unchanged' : 'updated' })
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return { version: STANDARD_VERSION, results: res }
|
|
214
|
+
}
|