@motion-proto/live-tokens 0.50.0 → 0.52.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/CHANGELOG.md +45 -0
- package/dist-plugin/adjust/index.d.cts +1 -1
- package/dist-plugin/adjust/index.d.ts +1 -1
- package/dist-plugin/{chunk-76TFDTJO.js → chunk-JIGIIE5P.js} +60 -132
- package/dist-plugin/{chunk-44RSTAII.js → chunk-TKZBVIW5.js} +33 -5
- package/dist-plugin/chunk-YR6GPXW2.js +129 -0
- package/dist-plugin/generateColorsAndType/index.cjs +87 -31
- package/dist-plugin/generateColorsAndType/index.d.cts +1 -1
- package/dist-plugin/generateColorsAndType/index.d.ts +1 -1
- package/dist-plugin/generateColorsAndType/index.js +22 -12
- package/dist-plugin/index.cjs +95 -55
- package/dist-plugin/index.js +5 -3
- package/dist-plugin/{themeTypes-DSwKq-bj.d.cts → themeTypes-Dky03HL9.d.cts} +18 -5
- package/dist-plugin/{themeTypes-DSwKq-bj.d.ts → themeTypes-Dky03HL9.d.ts} +18 -5
- package/dist-plugin/tokensCssMigrations/index.cjs +71 -5
- package/dist-plugin/tokensCssMigrations/index.d.cts +20 -9
- package/dist-plugin/tokensCssMigrations/index.d.ts +20 -9
- package/dist-plugin/tokensCssMigrations/index.js +4 -1
- package/package.json +4 -2
- package/src/editor/component-editor/NotificationEditor.svelte +6 -0
- package/src/editor/core/palettes/oklch.ts +3 -137
- package/src/editor/core/palettes/paletteDerivation.ts +79 -37
- package/src/editor/core/themes/generateColorsAndType.ts +18 -8
- package/src/editor/core/themes/themeTypes.ts +18 -6
- package/src/editor/docs/content/editing-tokens.md +6 -2
- package/src/editor/docs/content.generated.ts +1 -1
- package/src/editor/ui/BezierCurveEditor.svelte +90 -67
- package/src/editor/ui/PaletteEditor.svelte +150 -44
- package/src/editor/ui/Toggle.svelte +14 -2
- package/src/editor/ui/colors/ColorStory.svelte +12 -8
- package/src/editor/ui/curveEngine.ts +101 -21
- package/src/editor/ui/palette/OverridesPanel.svelte +19 -5
- package/src/editor/ui/palette/PaletteBase.svelte +17 -78
- package/src/editor/ui/palette/ScaleCurveEditor.svelte +109 -20
- package/src/editor/ui/palette/curveSummary.ts +20 -0
- package/src/editor/ui/palette/dockMagnify.ts +5 -13
- package/src/editor/ui/palette/paletteMath.ts +7 -4
- package/src/live-tokens/data/colors-and-type/autumn.json +528 -528
- package/src/live-tokens/data/colors-and-type/default.json +247 -247
- package/src/live-tokens/data/colors-and-type/halloween.json +532 -532
- package/src/live-tokens/data/colors-and-type/midnight-study.json +538 -538
- package/src/live-tokens/data/colors-and-type/ocean.json +521 -521
- package/src/live-tokens/data/colors-and-type/royal-velvet.json +532 -532
- package/src/live-tokens/data/colors-and-type/spring-meadow.json +504 -504
- package/src/live-tokens/data/colors-and-type/sunset.json +531 -531
- package/src/live-tokens/data/themes/autumn.json +527 -527
- package/src/live-tokens/data/themes/halloween.json +531 -531
- package/src/live-tokens/data/themes/midnight-study.json +537 -537
- package/src/live-tokens/data/themes/ocean.json +520 -520
- package/src/live-tokens/data/themes/royal-velvet.json +531 -531
- package/src/live-tokens/data/themes/spring-meadow.json +504 -504
- package/src/live-tokens/data/themes/sunset.json +531 -531
- package/src/live-tokens/data/tokens.generated.css +282 -282
- package/src/system/components/FloatingTokenTags.css +0 -1
- package/src/system/internal/backgroundContrast.ts +7 -0
- package/src/system/internal/oklch.ts +189 -0
- package/src/system/styles/tokens.css +283 -283
|
@@ -20,8 +20,12 @@ Success, Warning, Info, Danger, and a few more) has:
|
|
|
20
20
|
|
|
21
21
|
- **Base colour.** Pick a hex; the palette derives an 11-step ramp (100 to 950)
|
|
22
22
|
from it.
|
|
23
|
-
- **Curves.**
|
|
24
|
-
|
|
23
|
+
- **Curves.** Three curves shape the ramp, in stack order: Hue, Saturation,
|
|
24
|
+
Lightness. Drag the handles to bias it warmer or cooler, more or less
|
|
25
|
+
saturated, darker or lighter. Hue drifts the ramp's temperature without
|
|
26
|
+
moving contrast, because OKLCH hue rotation is close to lightness-preserving.
|
|
27
|
+
It holds ±45 degrees; a bigger shift belongs on the base colour or the
|
|
28
|
+
harmony axis.
|
|
25
29
|
- **Overrides.** Lock a single step to a hand-picked hex when the curve doesn't
|
|
26
30
|
land where you want.
|
|
27
31
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
export const docContent: Record<string, string> = {
|
|
5
5
|
"01-overview": "# Overview\n\nLive Tokens is a design system for building Svelte microsites quickly. You\nstyle your site by editing tokens and components in a live editor. When it looks right, you save the theme and ship it.\n\n## How it works\n\n- The editor runs in your dev server, on top of your real pages. You style in\n context, not in a separate sandbox.\n- Every change updates a CSS variable, so the page repaints instantly. No\n reload, no build step.\n- Saving writes a small JSON file into your project. Shipping bakes your chosen\n theme into a plain CSS file that the build bundles.\n- The editor is dev-only. Production ships plain CSS variables and the\n components you used, nothing else.\n\n## What you can edit\n\n- **Tokens**: the design-system primitives, colour palettes, type, spacing,\n radius, shadow, and gradients, that apply across your whole site.\n- **Components**: the package ships about 25 editable components (Button,\n IconButton, Card, Dialog, Table, and more). You style components by changing\n the tokens assigned to each property.\n\n## Where to go next\n\n- **[Getting started](getting-started.md)**: scaffold a project and make your\n first edit.\n- **[Editing tokens](editing-tokens.md)**: a tour of the editor.\n- **[Themes](themes-workflow.md)**: save, switch, and ship.\n- **[Creating components](creating-components.md)**: make your own components\n editable.\n",
|
|
6
6
|
"creating-components": "# Creating components\n\nThe package ships about 25 editable components. When you need one it doesn't\nhave, you can make your own Svelte component editable, so anyone using the\neditor can re-point its colours, type, and spacing without touching code.\n\nThe simplest way is to ask Claude. The package bundles a Claude Code skill that\nknows the conventions, writes the files, and checks the result for you.\n\n## Install the skills\n\n```bash\nnpx @motion-proto/live-tokens setup-claude\n```\n\nThis copies the bundled skills into your project's `.claude/skills/`. Once\nthey're there, Claude Code picks them up automatically.\n\n## Ask for a component\n\nDescribe what you want in plain English. Phrases like these trigger the skill:\n\n- \"Add a Toggle component to live-tokens\"\n- \"Make this Svelte component editable in the live-tokens editor\"\n- \"Create a Stat component with a value and a label\"\n\nClaude asks any clarifying questions it needs (which variants, which states,\nwhich parts), then writes the component, registers it with the editor, and runs\nits verification checklist. When it finishes, open `/live-tokens/components` to see your new\ncomponent in the editor and confirm everything works.\n\n## What you get\n\n- A runtime component whose editable properties default to your theme tokens.\n- An editor entry that appears under **Custom** in the `/live-tokens/components` view.\n- The naming and wiring handled for you, so the component fits the system.\n\nAdvanced authors who want to write a component by hand can read the naming and\nstate-model conventions shipped in the package\n(`src/system/styles/CONVENTIONS.md` and the skill's own `SKILL.md`).\n",
|
|
7
|
-
"editing-tokens": "# Editing tokens\n\nA tour of the editor. The page behind it repaints on every change; saving\nwrites a theme file you can reload later.\n\nThe editor has two views:\n\n- **Tokens**: the design-system primitives (colour, type, spacing, and so on).\n They apply everywhere your site uses them.\n- **Components**: per-component editors. Re-Assign what tokens a component uses\n without changing the underlying system.\n\nThis page covers **Tokens**. For components, see\n[Creating components](creating-components.md).\n\n## Palettes\n\nMost colour work happens here. Each palette (Brand, Accent, Neutral, Canvas,\nSuccess, Warning, Info, Danger, and a few more) has:\n\n- **Base colour.** Pick a hex; the palette derives an 11-step ramp (100 to 950)\n from it.\n- **Curves.**
|
|
7
|
+
"editing-tokens": "# Editing tokens\n\nA tour of the editor. The page behind it repaints on every change; saving\nwrites a theme file you can reload later.\n\nThe editor has two views:\n\n- **Tokens**: the design-system primitives (colour, type, spacing, and so on).\n They apply everywhere your site uses them.\n- **Components**: per-component editors. Re-Assign what tokens a component uses\n without changing the underlying system.\n\nThis page covers **Tokens**. For components, see\n[Creating components](creating-components.md).\n\n## Palettes\n\nMost colour work happens here. Each palette (Brand, Accent, Neutral, Canvas,\nSuccess, Warning, Info, Danger, and a few more) has:\n\n- **Base colour.** Pick a hex; the palette derives an 11-step ramp (100 to 950)\n from it.\n- **Curves.** Three curves shape the ramp, in stack order: Hue, Saturation,\n Lightness. Drag the handles to bias it warmer or cooler, more or less\n saturated, darker or lighter. Hue drifts the ramp's temperature without\n moving contrast, because OKLCH hue rotation is close to lightness-preserving.\n It holds ±45 degrees; a bigger shift belongs on the base colour or the\n harmony axis.\n- **Overrides.** Lock a single step to a hand-picked hex when the curve doesn't\n land where you want.\n\nEditing a palette base ripples through every colour that depends on it, in real\ntime. Colours use OKLCH, so the ramp stays perceptually even across hues\nwithout muddy mid-tones.\n\n## Type\n\n- **Fonts.** Add sources from Google Fonts, Adobe (Typekit), a CSS URL, or an\n inline `@font-face`. The font loads in the page as soon as you add it.\n- **Stacks.** Named font cascades you reference by token, such as a display\n stack and a body stack.\n- **Sizes and weights.** A t-shirt scale (xs, sm, md, lg, xl, 2xl…) for size and\n a numeric scale (100 to 900) for weight.\n\n## Spacing, radius, shadow\n\nNumeric scales with a slider per step.\n\n- **Spacing**: the padding, gap, and margin scale.\n- **Radius**: none through full.\n- **Shadow**: colour, offset, blur, spread, and opacity per step, with stacked\n shadows supported.\n\nChange a step and every element using it repaints.\n\n## Overlays and gradients\n\n- **Overlays** are translucent tints layered over surfaces, like the subtle\n tint a card gets on hover. Set a colour and opacity per state.\n- **Gradients** are reusable gradient tokens with a stop list and direction, for\n hero panels and accent backgrounds.\n\n## Columns\n\nThe page-grid overlay. Set column count, gutter, and outer margin, and toggle\nthe visual guide with `Cmd/Ctrl+G`. Pages built on the column system reflow\nlive.\n\n## Saving\n\nThe editor saves to your browser continuously, so work survives a reload\nmid-edit. Writing a file is a separate step: the **Theme** panel at the foot of\nthe sidebar has **Save**, **Save As**, and **Load**, and each theme is one JSON\nfile under `src/live-tokens/data/themes/`.\n\nThe header gives you undo/redo (`Cmd/Ctrl+Z`, `Cmd/Ctrl+Shift+Z`). You can keep\nmany themes side by side; one is open at a time, and only **Adopt** publishes\none. See [Themes](themes-workflow.md) for the full lifecycle.\n",
|
|
8
8
|
"getting-started": "# Getting started\n\nScaffold a live token site in a moments. You need Node 20 or later, a\npackage manager (npm, pnpm, or yarn), and a browser. Open claude code in your repo and start building.\n\n## Scaffold a new app\n\n```bash\nnpm create @motion-proto/live-tokens@latest my-app\ncd my-app\nnpm install\nnpm run dev\n```\n\nOpen the URL Vite prints (usually `http://localhost:5173`). You get a\none-page Svelte + Vite app that depends on the published package, with the\neditor wired up and the full component set ready to import.\n\n`npx @motion-proto/live-tokens create my-app` runs the same scaffold without\nthe initialiser package.\n\n### What the scaffold gives you\n\nEvery editable file lives under `src/` and is committed, so `npm install` and\nversion upgrades never touch your styles. The package code stays in\n`node_modules`.\n\n| Path | What it is |\n|------|------------|\n| `src/pages/Home.svelte` | The starter page. Replace it with your own content. |\n| `src/App.svelte` | Your routes. `<LiveTokensRouter>` adds dev-only routes under a reserved `/live-tokens/*` namespace: `/live-tokens/editor`, `/live-tokens/components`, and `/live-tokens/docs`. |\n| `src/system/styles/tokens.css` | Your base token vocabulary, hand-authored. |\n| `src/styles/site.css` | Themed page typography, yours to edit. |\n\n## Your first edit\n\n1. Run `npm run dev` and open the home page.\n2. Click **Open Token Editor**, or visit `/live-tokens/editor`. The editor opens beside\n the page.\n3. Open **Palettes**, pick **Brand**, and change the base hex. The page\n repaints as you type.\n4. In the **Theme** panel at the foot of the sidebar, choose **Save As**. Your\n theme appears as JSON under `src/live-tokens/data/themes/`.\n5. Reload. The editor reopens on your theme, so the page returns as you left\n it.\n\n## What you just changed\n\nEvery edit sets a CSS custom property on `:root`. Your components read those\nproperties through `var(--...)`. There is no token build step and no\npreprocessor rewriting your code: the page renders against plain CSS variables\nthe editor swaps live.\n\nTo ship, click **Adopt** in the Theme panel. That saves the open theme and bakes\nit into `src/live-tokens/data/tokens.generated.css`, which your build bundles\nalongside `tokens.css`. Adopt is the only action that changes what your site\nships, so try any look you like first. The editor itself never reaches\nproduction.\n\nAlready have a Svelte 5 + Vite app? The\n[README](https://github.com/motionproto/live-tokens#readme) covers installing\ninto an existing project.\n\n## Where to go next\n\n- **[Editing tokens](editing-tokens.md)**: a tour of the editor.\n- **[Themes](themes-workflow.md)**: save, switch, and ship.\n- **[Creating components](creating-components.md)**: make your own component\n editable.\n",
|
|
9
9
|
"themes-workflow": "# Themes\n\nSave your work, switch between looks, and ship one to production.\n\n## The Theme panel\n\nThe **Theme** panel at the foot of the editor sidebar holds the whole look:\ncolors, type, and a setting for every component you changed, in one file. It\ncarries the name the look ships under, whether production is running it, and\n**Adopt**. Two parts sit under it, each a read-out rather than a file to manage.\n\n- **Colors & Type** holds the design tokens. Components read those tokens to\n define their appearance. It names the two faces the page is showing.\n- **Components** counts how many components run something the theme does not\n carry, and opens the component editors.\n\nA theme holds its own copy of every part, so one theme can never break another.\n\n## How themes work\n\nA theme is a document, and the editor works the way any editor does.\n\n- **A theme** is a named JSON file in `src/live-tokens/data/themes/`. It carries\n the whole look: the colors and type plus a setting for every component you\n changed.\n- **The open theme** is the one the editor is working on, named in\n `themes/_active.json`. One at a time.\n- **Your unsaved edits** are what the page shows right now. The editor keeps\n them in your browser as you work and writes them to a buffer, `_working.json`,\n one slot per part of the look. **Save** captures that buffer into the open\n theme.\n- **The production theme** is the one your site ships, named in\n `themes/_production.json`. **Adopt** changes it; saving a preset in the Theme\n Picker performs that Adopt for you.\n\nAbsence is the answer for anything untouched: a buffer exists only where the\nlive look diverges from the active theme, so a newly opened theme has none.\n\n## Saving\n\nIn the Theme panel:\n\n- **Save** captures the look on screen into the open theme. Your colors and type\n go in as part of it, so there is nothing to save first.\n- **Save As** names a new theme. Use it for your first save and for forking.\n\nComponent editors keep their own unsaved state. If one or more components are\nwaiting when you use **Save**, **Save As**, or **Adopt**, the Theme panel offers\nto save all of them before continuing. You can accept once instead of visiting\neach component, or cancel to review them individually. A component editor's\n**Save As** creates a reusable component preset.\n\nNames are tidied to lowercase with hyphens, so \"My Brand!\" becomes `my-brand`,\nand a leading underscore is dropped: those names are reserved for the buffer.\n**Motion Proto** is the built-in theme and is read-only. You can always return\nto it, and the editor never overwrites it, so start your own with **Save As**.\n\n## Switching\n\n**Load**—or clicking the active theme's name—opens the Theme Picker. Picking a\ntheme shows it on the page as a preview with nothing written to disk, so you can\ntry each look and compare. **Save** in that window opens and adopts the previewed\ntheme in one step: the active pointer changes, the buffers clear, components it\ndoes not carry fall through to their defaults, the editor works on it, and\nproduction ships it. **Cancel** returns you to where you were. Previewing alone\nnever changes what your site ships.\n\n**Colors and type only. Keep my shapes.** narrows the load to the palette and\nthe fonts: your component settings stay as they are and the theme you have open\nstays open. Saved colors and type files are listed there too, marked *colors &\ntype*, and picking one is always that narrower load.\n\n## Shipping\n\n**Adopt**, in the Theme panel, is the \"ship it\" step, and it ships the whole\nlook. It saves the open theme, then bakes that theme into\n`src/live-tokens/data/tokens.generated.css`, which your build bundles alongside\n`tokens.css`: the colors and type plus every component the theme carries. Fonts\nregenerate to match. The line under the theme name says whether production is\nrunning this theme.\n\nProduction is one saved theme, so nothing else publishes. Trying a look, moving\na token, saving a theme: all of it leaves the generated CSS alone until you\nAdopt. A component editor's Adopt runs the same whole-look step, because a\ncomponent never ships alone. Adopting while Motion Proto is open saves your look\nas a theme of your own first, since the built-in one is read-only.\n\nProduction builds (`npm run build`) ship only that plain CSS and your\ncomponents. No editor, no JSON loading, no runtime indirection.\n\n## Keeping your work safe\n\nEverything under `src/live-tokens/data/` is plain JSON, so commit it. Themes show\nup as readable diffs you can review per branch, and the buffer shows up as the\nwork you have not saved into a theme yet. Nothing is backed up anywhere else:\ngit is your safety net. To experiment freely, **Save As** a new name first, then\nedit.\n\n## Where to go next\n\n- **[Where themes live](where-themes-live.md)**: the files behind all of this,\n and what writes each one.\n- **[Creating components](creating-components.md)**: make your own components\n editable in the same editor.\n",
|
|
10
10
|
"where-themes-live": "# Where themes live\n\nEverything the editor writes is plain JSON and CSS inside your project. There\nis no database and no hidden state: the files are the storage, and git is the\nhistory.\n\n## The data tree\n\n```\nsrc/live-tokens/data/\n themes/\n _active.json names the theme the editor has open\n _production.json names the theme your site ships\n default.json Motion Proto, the built-in look, rewritten at boot\n my-brand.json a saved theme: the whole look in one file\n colors-and-type/\n _working.json unsaved colors and type edits\n component-configs/\n button/\n default.json Button's shipped settings, derived at boot\n _working.json unsaved Button edits\n my-button.json a preset you saved from the Button editor\n tokens.generated.css the baked CSS your production build ships\nsrc/system/styles/\n tokens.css your token vocabulary, hand-authored, never written\n fonts.css font imports, rewritten when you Adopt\n```\n\nA saved theme carries the whole look by value: the colors and type plus a\nsetting for every component you changed. It depends on no other file, so\ndeleting anything else never breaks it.\n\n## What writes when\n\n- **Editing** changes the page through CSS variables. The editor keeps your\n edits in the browser as you work and writes them to the `_working.json`\n buffers when you save a component. When the Theme panel finds several dirty\n components, **Save all** writes those buffers together.\n- **Save** captures the buffers into the open theme's file. That file is the\n durable copy of your look; matching buffers are then removed.\n- **Load** clears the buffers and points `themes/_active.json` at the theme you\n picked. Live reads fall through to that file. Nothing else changes, so trying\n looks is free and ordinary switching changes only the pointer.\n- **Adopt** points `themes/_production.json` at the open theme, bakes it into\n `tokens.generated.css`, and rewrites `fonts.css` to match. It is the only\n action that changes what your site ships.\n\nThe `default.json` files are the shipped baseline. The editor derives them at\nboot and refreshes them when the package updates; it never saves your work\nover them.\n\nProjects upgraded from 0.48 may initially contain working files copied from the\nactive theme. On the first dev-server boot, exact copies are removed\nautomatically. Any file that differs is kept as unsaved work, so no migration\ncommand is required.\n\n## What to commit\n\nAll of it. The data tree is designed to live in git: themes diff readably, the\ntwo pointers say what is open and what ships, and a `_working.json` in a diff\nis exactly the work you have not yet saved into a theme. Nothing is backed up\nanywhere else.\n\n## Where to go next\n\n- **[Themes](themes-workflow.md)**: the workflow built on these files: saving,\n loading, and shipping.\n",
|
|
@@ -4,22 +4,25 @@
|
|
|
4
4
|
import {
|
|
5
5
|
type CurveAnchor, type CurveConfig,
|
|
6
6
|
CURVE_H, CURVE_PAD_Y, CURVE_Y_PAD,
|
|
7
|
-
isCornerAnchor,
|
|
7
|
+
isCornerAnchor, isAutoSmoothCurve, tangentAnchor, resmoothAnchor, resmoothAutoCurve,
|
|
8
|
+
curveXToSvg, curveYToSvg, svgToX, svgToY,
|
|
8
9
|
evalBezier, buildCurvePath, curveTemplates,
|
|
9
|
-
serializeCurve, deserializeCurve,
|
|
10
|
+
serializeCurve, deserializeCurve, clampAnchorsToRange,
|
|
10
11
|
} from './curveEngine';
|
|
11
12
|
import UIPillButton from './UIPillButton.svelte';
|
|
13
|
+
import Toggle from './Toggle.svelte';
|
|
12
14
|
|
|
13
15
|
interface Props {
|
|
14
16
|
anchors: CurveAnchor[];
|
|
15
17
|
cfg: CurveConfig;
|
|
16
18
|
stepCount: number;
|
|
17
|
-
padX?: number;
|
|
18
19
|
offset?: number;
|
|
19
20
|
defaultAnchors?: CurveAnchor[] | null;
|
|
20
21
|
lockedAnchorIndex?: number | null;
|
|
22
|
+
autoSmooth?: boolean;
|
|
21
23
|
onAnchorsChange?: (anchors: CurveAnchor[]) => void;
|
|
22
24
|
onOffsetChange?: (offset: number) => void;
|
|
25
|
+
onAutoSmoothChange?: (autoSmooth: boolean) => void;
|
|
23
26
|
onLockedAnchorUnlock?: (() => void) | null;
|
|
24
27
|
}
|
|
25
28
|
|
|
@@ -27,19 +30,36 @@
|
|
|
27
30
|
anchors,
|
|
28
31
|
cfg,
|
|
29
32
|
stepCount,
|
|
30
|
-
padX = 0,
|
|
31
33
|
offset = 0,
|
|
32
34
|
defaultAnchors = null,
|
|
33
35
|
lockedAnchorIndex = null,
|
|
36
|
+
autoSmooth = true,
|
|
34
37
|
onAnchorsChange = () => {},
|
|
35
38
|
onOffsetChange = () => {},
|
|
39
|
+
onAutoSmoothChange = () => {},
|
|
36
40
|
onLockedAnchorUnlock = null
|
|
37
41
|
}: Props = $props();
|
|
38
42
|
|
|
43
|
+
/** Every mutation the editor makes to anchor positions runs through here, so
|
|
44
|
+
* while auto smoothing is on the stored handles always equal the derived
|
|
45
|
+
* ones. That is what makes switching it off leave the shape untouched. */
|
|
46
|
+
function commit(updated: CurveAnchor[]) {
|
|
47
|
+
onAnchorsChange(autoSmooth ? resmoothAutoCurve(updated) : updated);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function setAutoSmooth(on: boolean) {
|
|
51
|
+
onAutoSmoothChange(on);
|
|
52
|
+
// Switching off is a no-op on the shape; switching on discards hand-dragged handles.
|
|
53
|
+
if (on) onAnchorsChange(resmoothAutoCurve(anchors));
|
|
54
|
+
}
|
|
55
|
+
|
|
39
56
|
function resetToDefault() {
|
|
40
57
|
if (!defaultAnchors) return;
|
|
58
|
+
// The default is a shape in its own right, so it lands verbatim rather than
|
|
59
|
+
// through `commit`, and auto smoothing follows whatever that shape already is.
|
|
41
60
|
onAnchorsChange(defaultAnchors.map(a => ({ ...a })));
|
|
42
61
|
onOffsetChange(0);
|
|
62
|
+
onAutoSmoothChange(isAutoSmoothCurve(defaultAnchors));
|
|
43
63
|
}
|
|
44
64
|
|
|
45
65
|
const CURVE_W_DEFAULT = 720;
|
|
@@ -50,6 +70,9 @@
|
|
|
50
70
|
const clipId = `curve-clip-${Math.random().toString(36).slice(2, 8)}`;
|
|
51
71
|
|
|
52
72
|
let w = $derived(dims);
|
|
73
|
+
// Half a step column. The graph spans the swatch row edge to edge, so without this
|
|
74
|
+
// inset the curve's ends sit on the outer edges of the end swatches, not over them.
|
|
75
|
+
let padX = $derived(stepCount > 1 ? w / (2 * stepCount) : 0);
|
|
53
76
|
let offsetPx = $derived(-(offset / ((cfg.yMax - cfg.yMin) * (1 + 2 * CURVE_Y_PAD))) * (CURVE_H - 2 * CURVE_PAD_Y));
|
|
54
77
|
|
|
55
78
|
function stepToX(index: number): number {
|
|
@@ -114,7 +137,7 @@
|
|
|
114
137
|
const { x, y } = svgCoords(e);
|
|
115
138
|
const newX = svgToX(x, w, padX);
|
|
116
139
|
const newY = Math.round(svgToY(y, cfg));
|
|
117
|
-
|
|
140
|
+
let updated = [...anchors];
|
|
118
141
|
|
|
119
142
|
if (kind === 'anchor') {
|
|
120
143
|
if (idx === lockedAnchorIndex) return; // locked: no x/y dragging
|
|
@@ -123,20 +146,28 @@
|
|
|
123
146
|
else if (idx === updated.length - 1) ax = 100;
|
|
124
147
|
else ax = Math.max(updated[idx - 1].x + 1, Math.min(updated[idx + 1].x - 1, ax));
|
|
125
148
|
updated[idx] = { ...updated[idx], x: ax, y: newY };
|
|
149
|
+
// The locked anchor took its tangent from the curve's shape at pin time and
|
|
150
|
+
// cannot be dragged, so nothing else refreshes it. Left stale it holds a flat
|
|
151
|
+
// shelf through the middle of a ramp the user has since moved under it.
|
|
152
|
+
if (lockedAnchorIndex != null && lockedAnchorIndex !== idx) {
|
|
153
|
+
updated = resmoothAnchor(updated, lockedAnchorIndex);
|
|
154
|
+
}
|
|
126
155
|
} else if (kind === 'handleOut') {
|
|
156
|
+
if (autoSmooth) onAutoSmoothChange(false);
|
|
127
157
|
const a = updated[idx];
|
|
128
158
|
const dx = newX - a.x, dy = newY - a.y;
|
|
129
159
|
updated[idx] = breakHandle
|
|
130
160
|
? { ...a, outDx: dx, outDy: dy }
|
|
131
161
|
: { ...a, outDx: dx, outDy: dy, inDx: -dx, inDy: -dy };
|
|
132
162
|
} else {
|
|
163
|
+
if (autoSmooth) onAutoSmoothChange(false);
|
|
133
164
|
const a = updated[idx];
|
|
134
165
|
const dx = newX - a.x, dy = newY - a.y;
|
|
135
166
|
updated[idx] = breakHandle
|
|
136
167
|
? { ...a, inDx: dx, inDy: dy }
|
|
137
168
|
: { ...a, inDx: dx, inDy: dy, outDx: -dx, outDy: -dy };
|
|
138
169
|
}
|
|
139
|
-
onAnchorsChange(updated);
|
|
170
|
+
if (kind === 'anchor') commit(updated); else onAnchorsChange(updated);
|
|
140
171
|
}
|
|
141
172
|
|
|
142
173
|
function handlePointerUp() {
|
|
@@ -184,7 +215,7 @@
|
|
|
184
215
|
x: Math.round(mx), y: Math.round(my),
|
|
185
216
|
inDx: r0x - mx, inDy: r0y - my, outDx: r1x - mx, outDy: r1y - my,
|
|
186
217
|
});
|
|
187
|
-
|
|
218
|
+
commit(updated);
|
|
188
219
|
}
|
|
189
220
|
|
|
190
221
|
function toggleAnchorSmooth(index: number) {
|
|
@@ -195,16 +226,16 @@
|
|
|
195
226
|
} else {
|
|
196
227
|
updated[index] = { ...a, inDx: 0, inDy: 0, outDx: 0, outDy: 0 };
|
|
197
228
|
}
|
|
198
|
-
|
|
229
|
+
commit(updated);
|
|
199
230
|
}
|
|
200
231
|
|
|
201
232
|
function removePoint(index: number) {
|
|
202
233
|
if (anchors.length <= 2) return;
|
|
203
|
-
|
|
234
|
+
commit(anchors.filter((_, i) => i !== index));
|
|
204
235
|
}
|
|
205
236
|
|
|
206
237
|
function applyTemplate(tpl: typeof curveTemplates[0]) {
|
|
207
|
-
|
|
238
|
+
commit(tpl.anchors(cfg));
|
|
208
239
|
}
|
|
209
240
|
|
|
210
241
|
// --- Shift (vertical offset) drag ---
|
|
@@ -238,7 +269,7 @@
|
|
|
238
269
|
|
|
239
270
|
async function copyToClipboard() {
|
|
240
271
|
try {
|
|
241
|
-
await navigator.clipboard.writeText(serializeCurve(anchors, offset));
|
|
272
|
+
await navigator.clipboard.writeText(serializeCurve(anchors, offset, autoSmooth));
|
|
242
273
|
} catch {
|
|
243
274
|
// clipboard write failed silently
|
|
244
275
|
}
|
|
@@ -249,8 +280,12 @@
|
|
|
249
280
|
const text = await navigator.clipboard.readText();
|
|
250
281
|
const data = deserializeCurve(text);
|
|
251
282
|
if (!data) return;
|
|
252
|
-
|
|
283
|
+
// Clamping can move an anchor off its own derived tangent, so the pasted
|
|
284
|
+
// flag only survives a paste the axis left alone.
|
|
285
|
+
const pasted = clampAnchorsToRange(data.anchors.map(a => ({ ...a })), cfg);
|
|
286
|
+
onAnchorsChange(pasted);
|
|
253
287
|
onOffsetChange(data.offset);
|
|
288
|
+
onAutoSmoothChange(data.autoSmooth && isAutoSmoothCurve(pasted));
|
|
254
289
|
} catch {
|
|
255
290
|
// clipboard read failed or permission denied
|
|
256
291
|
}
|
|
@@ -258,19 +293,6 @@
|
|
|
258
293
|
</script>
|
|
259
294
|
|
|
260
295
|
<div class="curve-panel">
|
|
261
|
-
<div class="curve-panel-header">
|
|
262
|
-
<span class="curve-panel-label">{cfg.label}</span>
|
|
263
|
-
<div class="curve-help">
|
|
264
|
-
<button class="curve-help-badge" type="button" aria-label="Curve editor help">
|
|
265
|
-
<i class="fas fa-circle-info" aria-hidden="true"></i>
|
|
266
|
-
</button>
|
|
267
|
-
<div class="curve-help-popover" role="tooltip">
|
|
268
|
-
<div><strong>Click</strong> path to add a point</div>
|
|
269
|
-
<div><strong>⌥ Click</strong> a point to remove</div>
|
|
270
|
-
<div><strong>Double-click</strong> a point to toggle smooth/corner</div>
|
|
271
|
-
</div>
|
|
272
|
-
</div>
|
|
273
|
-
</div>
|
|
274
296
|
<div class="curve-container">
|
|
275
297
|
<div class="curve-chart-overlay">
|
|
276
298
|
<UIPillButton
|
|
@@ -282,8 +304,19 @@
|
|
|
282
304
|
<svg viewBox="0 0 12 20" class="curve-tool-icon">
|
|
283
305
|
<path d="M6,2 L10,7 L7,7 L7,13 L10,13 L6,18 L2,13 L5,13 L5,7 L2,7 Z" />
|
|
284
306
|
</svg>
|
|
285
|
-
<span>Offset{offset !== 0 ? ` ${offset > 0 ? '+' : ''}${offset}` : ''}</span>
|
|
307
|
+
<span>Offset{offset !== 0 ? ` ${offset > 0 ? '+' : ''}${offset}${cfg.unit ?? ''}` : ''}</span>
|
|
286
308
|
</UIPillButton>
|
|
309
|
+
<div class="curve-help">
|
|
310
|
+
<button class="curve-help-badge" type="button" aria-label="Curve editor help">
|
|
311
|
+
<i class="fas fa-circle-info" aria-hidden="true"></i>
|
|
312
|
+
</button>
|
|
313
|
+
<div class="curve-help-popover" role="tooltip">
|
|
314
|
+
<div><strong>Click</strong> path to add a point</div>
|
|
315
|
+
<div><strong>⌥ Click</strong> a point to remove</div>
|
|
316
|
+
<div><strong>Double-click</strong> a point to toggle smooth/corner</div>
|
|
317
|
+
<div><strong>Drag a handle</strong> to leave auto smooth</div>
|
|
318
|
+
</div>
|
|
319
|
+
</div>
|
|
287
320
|
</div>
|
|
288
321
|
<svg
|
|
289
322
|
bind:this={svgEl}
|
|
@@ -314,10 +347,7 @@
|
|
|
314
347
|
|
|
315
348
|
<!-- Horizontal grid lines -->
|
|
316
349
|
{#each cfg.gridLines as gl}
|
|
317
|
-
<line x1={
|
|
318
|
-
{/each}
|
|
319
|
-
{#each cfg.dashedLines as dl}
|
|
320
|
-
<line x1={padX} y1={curveYToSvg(dl, cfg)} x2={w - padX} y2={curveYToSvg(dl, cfg)} class="curve-grid dashed" />
|
|
350
|
+
<line x1={0} y1={curveYToSvg(gl, cfg)} x2={w} y2={curveYToSvg(gl, cfg)} class="curve-grid" />
|
|
321
351
|
{/each}
|
|
322
352
|
|
|
323
353
|
<!-- Curve content group — offset vertically, clipped -->
|
|
@@ -418,19 +448,22 @@
|
|
|
418
448
|
<UIPillButton size="compact" variant="outline" title="Copy curve" onclick={copyToClipboard}>Copy</UIPillButton>
|
|
419
449
|
<UIPillButton size="compact" variant="outline" title="Paste curve" onclick={pasteFromClipboard}>Paste</UIPillButton>
|
|
420
450
|
</div>
|
|
421
|
-
<div class="curve-
|
|
422
|
-
{
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
451
|
+
<div class="curve-presets">
|
|
452
|
+
<Toggle checked={autoSmooth} label="Auto smooth" onchange={setAutoSmooth} />
|
|
453
|
+
<div class="curve-templates">
|
|
454
|
+
{#each curveTemplates as tpl}
|
|
455
|
+
<button
|
|
456
|
+
class="curve-template-btn"
|
|
457
|
+
type="button"
|
|
458
|
+
title={tpl.name}
|
|
459
|
+
onclick={() => applyTemplate(tpl)}
|
|
460
|
+
>
|
|
461
|
+
<svg viewBox="0 0 20 12" class="curve-template-icon">
|
|
462
|
+
<path d={tpl.icon} />
|
|
463
|
+
</svg>
|
|
464
|
+
</button>
|
|
465
|
+
{/each}
|
|
466
|
+
</div>
|
|
434
467
|
</div>
|
|
435
468
|
<div class="curve-toolbar-group">
|
|
436
469
|
{#if defaultAnchors}
|
|
@@ -449,18 +482,6 @@
|
|
|
449
482
|
gap: var(--ui-space-4);
|
|
450
483
|
}
|
|
451
484
|
|
|
452
|
-
.curve-panel-header {
|
|
453
|
-
display: flex;
|
|
454
|
-
align-items: center;
|
|
455
|
-
gap: var(--ui-space-6);
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
.curve-panel-label {
|
|
459
|
-
font-size: var(--ui-font-size-md);
|
|
460
|
-
font-weight: var(--ui-font-weight-semibold);
|
|
461
|
-
color: var(--ui-text-tertiary);
|
|
462
|
-
}
|
|
463
|
-
|
|
464
485
|
.curve-container {
|
|
465
486
|
position: relative;
|
|
466
487
|
width: 100%;
|
|
@@ -483,6 +504,7 @@
|
|
|
483
504
|
.curve-help {
|
|
484
505
|
position: relative;
|
|
485
506
|
margin-left: auto;
|
|
507
|
+
align-self: flex-start;
|
|
486
508
|
}
|
|
487
509
|
|
|
488
510
|
.curve-help-badge {
|
|
@@ -549,7 +571,7 @@
|
|
|
549
571
|
width: 100%;
|
|
550
572
|
height: 100%;
|
|
551
573
|
background: transparent;
|
|
552
|
-
border: 1px solid var(--ui-border-
|
|
574
|
+
border: 1px solid var(--ui-border-high);
|
|
553
575
|
border-radius: var(--ui-radius-sm);
|
|
554
576
|
cursor: crosshair;
|
|
555
577
|
display: block;
|
|
@@ -562,20 +584,15 @@
|
|
|
562
584
|
}
|
|
563
585
|
|
|
564
586
|
.curve-grid {
|
|
565
|
-
stroke: var(--ui-border-
|
|
566
|
-
stroke-width:
|
|
587
|
+
stroke: var(--ui-border-high);
|
|
588
|
+
stroke-width: 1;
|
|
567
589
|
vector-effect: non-scaling-stroke;
|
|
568
590
|
}
|
|
569
591
|
|
|
570
|
-
.curve-grid.dashed {
|
|
571
|
-
stroke-dasharray: 3 3;
|
|
572
|
-
}
|
|
573
|
-
|
|
574
592
|
.curve-step-line {
|
|
575
593
|
stroke: var(--ui-border-low);
|
|
576
|
-
stroke-width:
|
|
594
|
+
stroke-width: 1;
|
|
577
595
|
vector-effect: non-scaling-stroke;
|
|
578
|
-
|
|
579
596
|
}
|
|
580
597
|
|
|
581
598
|
.shift-overlay {
|
|
@@ -680,6 +697,12 @@
|
|
|
680
697
|
fill: currentColor;
|
|
681
698
|
}
|
|
682
699
|
|
|
700
|
+
.curve-presets {
|
|
701
|
+
display: flex;
|
|
702
|
+
align-items: center;
|
|
703
|
+
gap: var(--ui-space-12);
|
|
704
|
+
}
|
|
705
|
+
|
|
683
706
|
.curve-templates {
|
|
684
707
|
display: flex;
|
|
685
708
|
gap: var(--ui-space-2);
|
|
@@ -689,8 +712,8 @@
|
|
|
689
712
|
display: flex;
|
|
690
713
|
align-items: center;
|
|
691
714
|
justify-content: center;
|
|
692
|
-
width:
|
|
693
|
-
height:
|
|
715
|
+
width: 2.625rem;
|
|
716
|
+
height: 1.75rem;
|
|
694
717
|
padding: 0;
|
|
695
718
|
border: 1px solid var(--ui-border-low);
|
|
696
719
|
border-radius: var(--ui-radius-sm);
|
|
@@ -711,7 +734,7 @@
|
|
|
711
734
|
.curve-template-icon path {
|
|
712
735
|
fill: none;
|
|
713
736
|
stroke: var(--ui-text-tertiary);
|
|
714
|
-
stroke-width: 1
|
|
737
|
+
stroke-width: 1;
|
|
715
738
|
stroke-linecap: round;
|
|
716
739
|
stroke-linejoin: round;
|
|
717
740
|
}
|