@1337exp/taoux 0.0.0-stage → 0.1.0
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 +27 -0
- package/LICENSE +21 -0
- package/README.md +137 -2
- package/README.ru.md +140 -0
- package/dist/camera.d.ts +22 -0
- package/dist/camera.js +38 -0
- package/dist/camera.js.map +1 -0
- package/dist/canvas/TaoxCanvas.vue.d.ts +37 -0
- package/dist/canvas/host.d.ts +138 -0
- package/dist/canvas/index.d.ts +3 -0
- package/dist/canvas/useCanvasGestures.d.ts +44 -0
- package/dist/canvas.css +55 -0
- package/dist/canvas.js +696 -0
- package/dist/canvas.js.map +1 -0
- package/dist/chunks/curveeditor-goX9maE5.js +759 -0
- package/dist/chunks/curveeditor-goX9maE5.js.map +1 -0
- package/dist/curve.d.ts +53 -0
- package/dist/curve.js +81 -0
- package/dist/curve.js.map +1 -0
- package/dist/curveeditor/TaoxCurveEditor.vue.d.ts +74 -0
- package/dist/curveeditor/index.d.ts +3 -0
- package/dist/curveeditor/ops.d.ts +63 -0
- package/dist/curveeditor.css +115 -0
- package/dist/curveeditor.js +1 -0
- package/dist/curvefield/TaoxCurveField.vue.d.ts +64 -0
- package/dist/curvefield/index.d.ts +2 -0
- package/dist/curvefield/labels.d.ts +13 -0
- package/dist/curvefield.css +57 -0
- package/dist/curvefield.js +252 -0
- package/dist/curvefield.js.map +1 -0
- package/dist/ease.d.ts +62 -0
- package/dist/ease.js +157 -0
- package/dist/ease.js.map +1 -0
- package/dist/edgescroll.d.ts +77 -0
- package/dist/edgescroll.js +78 -0
- package/dist/edgescroll.js.map +1 -0
- package/dist/file.d.ts +10 -0
- package/dist/file.js +22 -0
- package/dist/file.js.map +1 -0
- package/dist/gestures.d.ts +174 -0
- package/dist/gestures.js +229 -0
- package/dist/gestures.js.map +1 -0
- package/dist/gradienteditor/TaoxGradientEditor.vue.d.ts +48 -0
- package/dist/gradienteditor/index.d.ts +2 -0
- package/dist/gradienteditor/ops.d.ts +83 -0
- package/dist/gradienteditor.css +81 -0
- package/dist/gradienteditor.js +337 -0
- package/dist/gradienteditor.js.map +1 -0
- package/dist/history.d.ts +42 -0
- package/dist/history.js +89 -0
- package/dist/history.js.map +1 -0
- package/dist/i18n.d.ts +51 -0
- package/dist/i18n.js +102 -0
- package/dist/i18n.js.map +1 -0
- package/dist/ids.d.ts +5 -0
- package/dist/ids.js +17 -0
- package/dist/ids.js.map +1 -0
- package/dist/links/TaoxLinks.vue.d.ts +14 -0
- package/dist/links/index.d.ts +2 -0
- package/dist/links/types.d.ts +37 -0
- package/dist/links.css +80 -0
- package/dist/links.js +72 -0
- package/dist/links.js.map +1 -0
- package/dist/num.d.ts +35 -0
- package/dist/num.js +60 -0
- package/dist/num.js.map +1 -0
- package/dist/palette.d.ts +34 -0
- package/dist/palette.js +41 -0
- package/dist/palette.js.map +1 -0
- package/dist/pins.d.ts +66 -0
- package/dist/pins.js +83 -0
- package/dist/pins.js.map +1 -0
- package/dist/playback/core.d.ts +81 -0
- package/dist/playback/index.d.ts +2 -0
- package/dist/playback/use.d.ts +38 -0
- package/dist/playback.js +199 -0
- package/dist/playback.js.map +1 -0
- package/dist/session.d.ts +125 -0
- package/dist/session.js +195 -0
- package/dist/session.js.map +1 -0
- package/dist/snap.d.ts +24 -0
- package/dist/snap.js +34 -0
- package/dist/snap.js.map +1 -0
- package/dist/storage.d.ts +16 -0
- package/dist/storage.js +30 -0
- package/dist/storage.js.map +1 -0
- package/dist/touch.d.ts +9 -0
- package/dist/touch.js +20 -0
- package/dist/touch.js.map +1 -0
- package/dist/wheel.d.ts +31 -0
- package/dist/wheel.js +47 -0
- package/dist/wheel.js.map +1 -0
- package/package.json +183 -4
- package/theme/taoui.css +43 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
The first public release.
|
|
6
|
+
|
|
7
|
+
### Modules
|
|
8
|
+
|
|
9
|
+
- **Primitives:** `camera`, `history`, `storage`, `file`, `snap`, `wheel`, `edgescroll`, `gestures`, `touch`, `curve`, `ids`, `ease`, `num`, `i18n`.
|
|
10
|
+
- **Composite:** `session`, `palette`, `pins`, `playback` (`createPlayback`, `usePlayback`), and the Vue modules `links`, `canvas`, `curveeditor`, `gradienteditor`.
|
|
11
|
+
- **Tier 2, on TaoUI:** `curvefield` (`TaoxCurveField`): a curve with time, value, transition (`ease`), snapping, remove and reset fields.
|
|
12
|
+
- **Curve editor:** grid, snapping, bounds, decimals, auto-scroll at the edge, per-segment easing with Bezier handles, guides (`off`, `lines`, `values`), keyboard.
|
|
13
|
+
|
|
14
|
+
### TaoUI
|
|
15
|
+
|
|
16
|
+
- **The TaoUI bridge:** `import '@1337exp/taoux/taoui.css'` points every `--tx-*` colour variable at a `--tao-*` token, so the editors follow the TaoUI theme (dark, light, your own). Plain CSS, zero specificity, no dependency on TaoUI. `tests/bridge.test.ts` keeps it complete.
|
|
17
|
+
- Built and tested against TaoUI 3.3.1 (peer range `^3.2.1`, optional).
|
|
18
|
+
|
|
19
|
+
### Packaging
|
|
20
|
+
|
|
21
|
+
- `sideEffects` lists the CSS files, so bundlers keep `import '@1337exp/taoux/canvas.css'`.
|
|
22
|
+
- `npm run smoke` installs the packed tarball into a throwaway Vue + Vite app next to TaoUI, imports every module by its public path and builds it (also runs in CI).
|
|
23
|
+
|
|
24
|
+
### Sandbox
|
|
25
|
+
|
|
26
|
+
- English and Russian, a dark / light switch, relative paths for hosting in a sub-folder (`npm run sandbox:build`).
|
|
27
|
+
- `npm run media` captures the screenshots and clips in `docs/media` from the sandbox.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 1337exp
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,138 @@
|
|
|
1
|
-
|
|
1
|
+
<h1 align="center">TaoUX</h1>
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p align="center">
|
|
4
|
+
<b>Interaction building blocks for Vue apps.</b><br>
|
|
5
|
+
Import only what you need, bring your own design.
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<a href="https://www.npmjs.com/package/@1337exp/taoux"><img src="https://img.shields.io/npm/v/@1337exp/taoux?color=cb3837&logo=npm" alt="npm"></a>
|
|
10
|
+
<a href="https://github.com/1337exp/taoux/actions/workflows/ci.yml"><img src="https://github.com/1337exp/taoux/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
11
|
+
<a href="https://github.com/1337exp/taoux/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/@1337exp/taoux" alt="license"></a>
|
|
12
|
+
<img src="https://img.shields.io/badge/Vue-3-42b883?logo=vuedotjs&logoColor=white" alt="Vue 3">
|
|
13
|
+
<img src="https://img.shields.io/badge/types-included-3178c6?logo=typescript&logoColor=white" alt="TypeScript">
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
<p align="center">
|
|
17
|
+
<b>English</b> · <a href="https://github.com/1337exp/taoux/blob/main/README.ru.md">Русский</a> ·
|
|
18
|
+
<a href="#with-taoui">With TaoUI</a> ·
|
|
19
|
+
<a href="#modules">Modules</a> ·
|
|
20
|
+
<a href="#sandbox">Sandbox</a> ·
|
|
21
|
+
<a href="CHANGELOG.md">Changelog</a>
|
|
22
|
+
</p>
|
|
23
|
+
|
|
24
|
+
<p align="center">
|
|
25
|
+
<img src="https://raw.githubusercontent.com/1337exp/taoux/main/docs/media/screenshots/overview-dark.webp" alt="TaoUX curve editors in the dark theme" width="860">
|
|
26
|
+
</p>
|
|
27
|
+
|
|
28
|
+
## Why TaoUX
|
|
29
|
+
|
|
30
|
+
- **Pay for what you use.** Every module is its own subpath import with its own entry point: `import { zoomAt } from '@1337exp/taoux/camera'`. `sideEffects` is declared, the rest tree-shakes.
|
|
31
|
+
- **Logic first.** The core of a module (camera maths, history, easing, playback) is plain TypeScript with no Vue or DOM unless that is its job, and it is unit-tested that way. Components are thin shells on top.
|
|
32
|
+
- **Your design.** Components are styled by `--tx-*` CSS variables with sensible dark defaults. No design system is required.
|
|
33
|
+
- **Works with TaoUI in one line.** `import '@1337exp/taoux/taoui.css'` and the editors follow the TaoUI theme. [Details below.](#with-taoui)
|
|
34
|
+
- **Typed i18n, undo/redo, autosave, playback** and the other things every editor-like app ends up writing again.
|
|
35
|
+
|
|
36
|
+
<table>
|
|
37
|
+
<tr>
|
|
38
|
+
<td width="50%"><img src="https://raw.githubusercontent.com/1337exp/taoux/main/docs/media/clips/curveeditor.webp" alt="Curve editor: dragging and adding points"><br><sub><b>curveeditor</b> — grid, snapping, bounds, Bezier handles, keyboard</sub></td>
|
|
39
|
+
<td width="50%"><img src="https://raw.githubusercontent.com/1337exp/taoux/main/docs/media/clips/gradienteditor.webp" alt="Gradient editor: adding and moving stops"><br><sub><b>gradienteditor</b> — stops, handles, <code>gradientCss</code></sub></td>
|
|
40
|
+
</tr>
|
|
41
|
+
<tr>
|
|
42
|
+
<td><img src="https://raw.githubusercontent.com/1337exp/taoux/main/docs/media/clips/playback.webp" alt="Playback: TaoTimeline driven by usePlayback"><br><sub><b>playback</b> — time, loop, speed, seeking; <code>usePlayback</code> + TaoUI <code>TaoTimeline</code></sub></td>
|
|
43
|
+
<td><img src="https://raw.githubusercontent.com/1337exp/taoux/main/docs/media/clips/curvefield.webp" alt="TaoxCurveField: a curve with TaoUI fields"><br><sub><b>curvefield</b> — a curve with TaoUI fields in one component</sub></td>
|
|
44
|
+
</tr>
|
|
45
|
+
</table>
|
|
46
|
+
|
|
47
|
+
## Install
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npm install @1337exp/taoux
|
|
51
|
+
npm install @1337exp/taoui # optional: only for curvefield and the TaoUI bridge
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Peers: `vue ^3.4` (for the Vue modules) and, optionally, `@1337exp/taoui ^3.2.1`. Modules without Vue need nothing.
|
|
55
|
+
ESM only. Import by subpath; there is no root entry on purpose, so nothing you do not import can end up in your bundle.
|
|
56
|
+
|
|
57
|
+
## With TaoUI
|
|
58
|
+
|
|
59
|
+
TaoUX and [TaoUI](https://www.npmjs.com/package/@1337exp/taoui) are two separate packages: TaoUX has no buttons or fields of its own, TaoUI knows nothing about TaoUX. Joining them takes two things, and the first is one line:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import '@1337exp/taoui/styles.css';
|
|
63
|
+
import '@1337exp/taoux/taoui.css'; // the bridge: --tx-* → --tao-*, the editors follow the TaoUI theme
|
|
64
|
+
import '@1337exp/taoux/curveeditor.css'; // styles of a Vue module are imported explicitly
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`taoui.css` is plain CSS with zero specificity and no dependency on TaoUI, so any rule of yours wins. Values then travel through `v-model`: `usePlayback` drives `TaoTimeline`, a TaoUI field edits a curve point, a TaoUI slider sets the opacity of a gradient stop. With code: [docs/taoui.md](docs/taoui.md). Without the bridge the editors keep their dark defaults; `TaoxCurveField` (built from TaoUI components) follows the theme by itself.
|
|
68
|
+
|
|
69
|
+
<a id="modules"></a>
|
|
70
|
+
|
|
71
|
+
## Modules
|
|
72
|
+
|
|
73
|
+
Every module is its own subpath import, so only what you actually use ends up in the build:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { zoomAt } from '@1337exp/taoux/camera';
|
|
77
|
+
import { History } from '@1337exp/taoux/history';
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
| Module | What it does | Depends on |
|
|
81
|
+
|---|---|---|
|
|
82
|
+
| `camera` | canvas camera: pan, zoom around the cursor, screen ↔ world | nothing |
|
|
83
|
+
| `history` | undo/redo on string snapshots, rapid edits merged into one step | nothing |
|
|
84
|
+
| `storage` | autosave to localStorage without exceptions | nothing |
|
|
85
|
+
| `file` | download text as a file, size limit | DOM |
|
|
86
|
+
| `snap` | soft snapping to a grid with a threshold that follows the camera zoom | nothing |
|
|
87
|
+
| `wheel` | wheel/trackpad → pan or zoom (like Figma) | nothing |
|
|
88
|
+
| `edgescroll` | auto-scroll speed near an edge and a ready loop, `createEdgeScroller` (canvas, curve editors, any drag) | nothing |
|
|
89
|
+
| `gestures` | touch gestures: tap, double tap, long press, pinch | nothing |
|
|
90
|
+
| `touch` | `coarse`: is there a coarse pointer (a finger) | vue (peer) |
|
|
91
|
+
| `curve` | link paths: bezier between pins, arrowheads of constant screen size | nothing |
|
|
92
|
+
| `ids` | `uid(prefix, taken)` | nothing |
|
|
93
|
+
| `ease` | easing functions between curve points: 8 families × in / out / in-out, `linear`, `step`, cubic Bezier; `easeValue`, `isEase` (the editor draws with it, a runtime evaluates with it) | nothing |
|
|
94
|
+
| `num` | small numeric helpers: `clamp`, `roundTo`, `snapTo`, `niceStep`, `ticks` (shared by the curve, gradient and playback modules) | nothing |
|
|
95
|
+
| `session` | document lifecycle: history, autosave, files, restore, notices | vue (peer) |
|
|
96
|
+
| `palette` | search and groups of nodes for a palette | nothing |
|
|
97
|
+
| `links` (Vue) | links layer: SVG from ready geometry, `--tx-link-*` | vue (peer) |
|
|
98
|
+
| `canvas` (Vue) | canvas: mouse and touch gestures, wheel, auto-scroll, keys; the `CanvasHost` contract | vue (peer) |
|
|
99
|
+
| `curveeditor` (Vue) | curve editor plot: grid, snapping, bounds, decimals, auto-scroll at the edge; point operations; per-segment transitions with Bezier handles; keyboard (Tab, arrows, Shift, Insert, Delete) | vue (peer) |
|
|
100
|
+
| `curvefield` (Vue, tier 2) | `TaoxCurveField`: a curve with fields on TaoUI components: point time and value, transition to the next point (`ease`), snapping, remove and reset; labels come from the app | vue, **@1337exp/taoui** (peer) |
|
|
101
|
+
| `gradienteditor` (Vue) | gradient bar with stop handles; stop operations, `gradientCss`; keyboard (Tab, arrows, Home/End, Insert, Delete) | vue (peer) |
|
|
102
|
+
| `playback` | playback model: time, pause, loop, speed, seeking; `createPlayback` without Vue and `usePlayback` for a component | vue (peer, for `usePlayback`) |
|
|
103
|
+
| `pins` | row pin positions measured from the DOM: `usePinMeasure`, `createPinRegistry` | vue (peer) |
|
|
104
|
+
| `i18n` | typed i18n: `createI18n({ locales, fallback, storageKey })` | vue (peer, optional) |
|
|
105
|
+
|
|
106
|
+
Vue modules (`links`, `canvas`, `curveeditor`, `curvefield`, `gradienteditor`) need their styles imported explicitly: `import '@1337exp/taoux/canvas.css'`. Composite modules (session, palette, links, canvas, pins, curveeditor, gradienteditor, playback) import only primitives. Tier 2, fields (`curvefield`), assemble composites into a ready field on TaoUI components: it is the only tier allowed to import TaoUI, which is why `@1337exp/taoui` is an optional peer dependency. `curvefield` needs both `curveeditor.css` and `curvefield.css`. The `tiers.test.ts` test guards all of that. The canvas contract is described in [docs/canvas.md](docs/canvas.md) ([Русский](docs/canvas.ru.md)); transitions between curve points are in [docs/ease.md](docs/ease.md) ([Русский](docs/ease.ru.md)).
|
|
107
|
+
|
|
108
|
+
The rule: a module lands here when a second project needs it. A module's core knows nothing about Vue or the DOM unless that is its job.
|
|
109
|
+
|
|
110
|
+
## Development
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
npm install
|
|
114
|
+
npm test # vitest
|
|
115
|
+
npm run typecheck
|
|
116
|
+
npm run build # dist/ (vite + tsc declarations)
|
|
117
|
+
npm run smoke # pack, install into a throwaway app next to TaoUI, build it
|
|
118
|
+
npm run sandbox # the sandbox: http://localhost:5300, pages from sandbox/
|
|
119
|
+
npm run dev # watch: rebuild JS and declarations
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
A new module is a file `src/<name>.ts` (or a folder with `index.ts`) and an entry in `exports` in `package.json`; the `exports.test.ts` test makes sure they match. More in [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
123
|
+
|
|
124
|
+
Working against a local checkout instead of npm: put `"@1337exp/taoux": "file:../taoux"` into the project's `package.json` (edits are visible at once after `npm run dev` here). Then the consumer's `vite.config.ts` needs `resolve: { dedupe: ['vue'] }` and its `tsconfig.json` needs `"vue": ["./node_modules/vue"]` in `paths`, otherwise the linked package gets its own copy of Vue and reactivity breaks. A normal install from npm needs none of this.
|
|
125
|
+
|
|
126
|
+
## Sandbox
|
|
127
|
+
|
|
128
|
+
The `sandbox/` folder is a demo and a testing ground: pages import the modules straight from `src/`, with no build. It holds `curveeditor`, `curvefield`, `gradienteditor`, `slider`, `color` and `playback`, with an EN / RU switch and a dark / light switch (the TaoUI theme, through the bridge). A new page is `sandbox/<name>.html` + `.ts` + a demo `.vue` and a link in `sandbox/index.html`. `npm run sandbox:build` makes a static copy with relative paths, ready for any folder (for example `/sandbox/taoux/`).
|
|
129
|
+
|
|
130
|
+
Screenshots and clips in this README come from the sandbox: see [docs/media](docs/media/README.md).
|
|
131
|
+
|
|
132
|
+
## Contributing
|
|
133
|
+
|
|
134
|
+
Issues and pull requests are welcome, see [CONTRIBUTING.md](CONTRIBUTING.md). Security reports: [SECURITY.md](SECURITY.md).
|
|
135
|
+
|
|
136
|
+
## License
|
|
137
|
+
|
|
138
|
+
[MIT](LICENSE) © 2026 1337exp
|
package/README.ru.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
<h1 align="center">TaoUX</h1>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<b>Блоки взаимодействия для Vue-приложений.</b><br>
|
|
5
|
+
Импортируйте только нужное, дизайн приносите свой.
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<a href="https://www.npmjs.com/package/@1337exp/taoux"><img src="https://img.shields.io/npm/v/@1337exp/taoux?color=cb3837&logo=npm" alt="npm"></a>
|
|
10
|
+
<a href="https://github.com/1337exp/taoux/actions/workflows/ci.yml"><img src="https://github.com/1337exp/taoux/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
11
|
+
<a href="https://github.com/1337exp/taoux/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/@1337exp/taoux" alt="license"></a>
|
|
12
|
+
<img src="https://img.shields.io/badge/Vue-3-42b883?logo=vuedotjs&logoColor=white" alt="Vue 3">
|
|
13
|
+
<img src="https://img.shields.io/badge/types-included-3178c6?logo=typescript&logoColor=white" alt="TypeScript">
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
<p align="center">
|
|
17
|
+
<a href="https://github.com/1337exp/taoux/blob/main/README.md">English</a> · <b>Русский</b> ·
|
|
18
|
+
<a href="#с-taoui">С TaoUI</a> ·
|
|
19
|
+
<a href="#модули">Модули</a> ·
|
|
20
|
+
<a href="#песочница">Песочница</a> ·
|
|
21
|
+
<a href="CHANGELOG.md">Список изменений</a>
|
|
22
|
+
</p>
|
|
23
|
+
|
|
24
|
+
<p align="center">
|
|
25
|
+
<img src="https://raw.githubusercontent.com/1337exp/taoux/main/docs/media/screenshots/overview-dark.webp" alt="Редакторы кривой TaoUX в тёмной теме" width="860">
|
|
26
|
+
</p>
|
|
27
|
+
|
|
28
|
+
## Почему TaoUX
|
|
29
|
+
|
|
30
|
+
- **Платите только за используемое.** Каждый модуль это свой subpath-импорт и своя точка входа: `import { zoomAt } from '@1337exp/taoux/camera'`. `sideEffects` объявлен, остальное режется tree-shaking'ом.
|
|
31
|
+
- **Сначала логика.** Ядро модуля (математика камеры, история, easing, воспроизведение) это обычный TypeScript без Vue и DOM, если это не его задача, и тесты написаны именно так. Компоненты тонкая оболочка сверху.
|
|
32
|
+
- **Ваш дизайн.** Компоненты настраиваются CSS-переменными `--tx-*` с разумными тёмными значениями по умолчанию. Дизайн-система не обязательна.
|
|
33
|
+
- **С TaoUI в одну строку.** `import '@1337exp/taoux/taoui.css'`, и редакторы следуют теме TaoUI. [Подробности ниже.](#с-taoui)
|
|
34
|
+
- **Типизированный i18n, undo/redo, автосохранение, воспроизведение** и остальное, что каждое приложение-редактор пишет заново.
|
|
35
|
+
|
|
36
|
+
<table>
|
|
37
|
+
<tr>
|
|
38
|
+
<td width="50%"><img src="https://raw.githubusercontent.com/1337exp/taoux/main/docs/media/clips/curveeditor.webp" alt="Редактор кривой: перетаскивание и добавление точек"><br><sub><b>curveeditor</b> — сетка, шаг, границы, ручки Безье, клавиатура</sub></td>
|
|
39
|
+
<td width="50%"><img src="https://raw.githubusercontent.com/1337exp/taoux/main/docs/media/clips/gradienteditor.webp" alt="Редактор градиента: добавление и перемещение остановок"><br><sub><b>gradienteditor</b> — остановки, ручки, <code>gradientCss</code></sub></td>
|
|
40
|
+
</tr>
|
|
41
|
+
<tr>
|
|
42
|
+
<td><img src="https://raw.githubusercontent.com/1337exp/taoux/main/docs/media/clips/playback.webp" alt="Воспроизведение: TaoTimeline ведёт usePlayback"><br><sub><b>playback</b> — время, цикл, скорость, перемотка; <code>usePlayback</code> + <code>TaoTimeline</code> из TaoUI</sub></td>
|
|
43
|
+
<td><img src="https://raw.githubusercontent.com/1337exp/taoux/main/docs/media/clips/curvefield.webp" alt="TaoxCurveField: кривая с полями TaoUI"><br><sub><b>curvefield</b> — кривая с полями TaoUI в одном компоненте</sub></td>
|
|
44
|
+
</tr>
|
|
45
|
+
</table>
|
|
46
|
+
|
|
47
|
+
## Установка
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npm install @1337exp/taoux
|
|
51
|
+
npm install @1337exp/taoui # по желанию: только для curvefield и моста к TaoUI
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Peer-зависимости: `vue ^3.4` (для Vue-модулей) и, по желанию, `@1337exp/taoui ^3.2.1`. Модулям без Vue ничего не нужно.
|
|
55
|
+
Только ESM. Импорт по subpath; корневой точки входа нет намеренно, чтобы в сборку не попало ничего неимпортированного.
|
|
56
|
+
|
|
57
|
+
## С TaoUI
|
|
58
|
+
|
|
59
|
+
TaoUX и [TaoUI](https://www.npmjs.com/package/@1337exp/taoui) это два отдельных пакета: у TaoUX нет своих кнопок и полей, а TaoUI ничего не знает про TaoUX. Связать их это две вещи, и первая делается одной строкой:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import '@1337exp/taoui/styles.css';
|
|
63
|
+
import '@1337exp/taoux/taoui.css'; // мост: --tx-* → --tao-*, редакторы следуют теме TaoUI
|
|
64
|
+
import '@1337exp/taoux/curveeditor.css'; // стили Vue-модуля подключаются явно
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`taoui.css` это обычный CSS с нулевой специфичностью и без зависимости от TaoUI, поэтому любое ваше правило главнее. Дальше значения ходят через `v-model`: `usePlayback` ведёт `TaoTimeline`, поле TaoUI правит точку кривой, слайдер TaoUI задаёт прозрачность остановки градиента. С кодом: [docs/taoui.ru.md](docs/taoui.ru.md). Без моста редакторы остаются с тёмными значениями по умолчанию; `TaoxCurveField` (собран из компонентов TaoUI) подстраивается под тему сам.
|
|
68
|
+
|
|
69
|
+
<a id="модули"></a>
|
|
70
|
+
|
|
71
|
+
## Модули
|
|
72
|
+
|
|
73
|
+
Каждый модуль — отдельный subpath-импорт, поэтому в сборку попадает только то, что реально используется:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { zoomAt } from '@1337exp/taoux/camera';
|
|
77
|
+
import { History } from '@1337exp/taoux/history';
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
| Модуль | Что делает | Зависимости |
|
|
81
|
+
|---|---|---|
|
|
82
|
+
| `camera` | камера холста: pan, zoom вокруг курсора, экран ↔ мир | нет |
|
|
83
|
+
| `history` | undo/redo на снимках-строках со склейкой частых правок | нет |
|
|
84
|
+
| `storage` | автосохранение в localStorage без исключений | нет |
|
|
85
|
+
| `file` | скачивание текста как файла, лимит размера | DOM |
|
|
86
|
+
| `snap` | мягкая привязка к сетке с порогом по масштабу камеры | нет |
|
|
87
|
+
| `wheel` | колесо/тачпад → pan или zoom (как в Figma) | нет |
|
|
88
|
+
| `edgescroll` | скорость автопрокрутки у края и готовый цикл `createEdgeScroller` (холст, редакторы кривых и любое перетаскивание) | нет |
|
|
89
|
+
| `gestures` | сенсорные жесты: тап, двойной тап, долгое нажатие, щипок | нет |
|
|
90
|
+
| `touch` | `coarse` — есть ли грубый указатель (палец) | vue (peer) |
|
|
91
|
+
| `curve` | пути связей: безье между пинами, стрелки постоянного экранного размера | нет |
|
|
92
|
+
| `ids` | `uid(prefix, taken)` | нет |
|
|
93
|
+
| `ease` | функции движения между точками кривой: 8 семейств × in / out / in-out, `linear`, `step`, кубический Безье; `easeValue`, `isEase` (редактор рисует ими, рантайм считает ими же) | нет |
|
|
94
|
+
| `num` | мелкая числовая математика: `clamp`, `roundTo`, `snapTo`, `niceStep`, `ticks` (общая для кривой, градиента и воспроизведения) | нет |
|
|
95
|
+
| `session` | жизненный цикл документа: история, автосохранение, файлы, восстановление, уведомления | vue (peer) |
|
|
96
|
+
| `palette` | поиск и группы нод для палитры | нет |
|
|
97
|
+
| `links` (Vue) | слой связей: SVG из готовой геометрии, `--tx-link-*` | vue (peer) |
|
|
98
|
+
| `canvas` (Vue) | холст: жесты мыши и сенсора, колесо, автопрокрутка, клавиши; контракт `CanvasHost` | vue (peer) |
|
|
99
|
+
| `curveeditor` (Vue) | поле редактора кривой: сетка, шаг, границы, знаки, автопрокрутка у края; операции над точками; переходы между точками с ручками Безье; клавиатура (Tab, стрелки, Shift, Insert, Delete) | vue (peer) |
|
|
100
|
+
| `curvefield` (Vue, ярус 2) | `TaoxCurveField`: кривая с полями на компонентах TaoUI: время и значение точки, переход к следующей точке (`ease`), шаг, удаление и сброс; надписи задаёт приложение | vue, **@1337exp/taoui** (peer) |
|
|
101
|
+
| `gradienteditor` (Vue) | полоса градиента с ручками остановок; операции над остановками, `gradientCss`; клавиатура (Tab, стрелки, Home/End, Insert, Delete) | vue (peer) |
|
|
102
|
+
| `playback` | модель воспроизведения: время, пауза, цикл, скорость, перемотка; `createPlayback` без Vue и `usePlayback` для компонента | vue (peer, для `usePlayback`) |
|
|
103
|
+
| `pins` | позиции пинов-строк, измеренные по DOM: `usePinMeasure`, `createPinRegistry` | vue (peer) |
|
|
104
|
+
| `i18n` | типизированный i18n: `createI18n({ locales, fallback, storageKey })` | vue (peer, опционально) |
|
|
105
|
+
|
|
106
|
+
Vue-модули (`links`, `canvas`, `curveeditor`, `curvefield`, `gradienteditor`) требуют явного импорта стилей: `import '@1337exp/taoux/canvas.css'`. Составные модули (session, palette, links, canvas, pins, curveeditor, gradienteditor, playback) импортируют только примитивы. Ярус 2, поля (`curvefield`), собирает составные модули в готовое поле на компонентах TaoUI: только ему можно импортировать TaoUI, поэтому `@1337exp/taoui` это необязательная peer-зависимость. Для `curvefield` нужны оба файла стилей, `curveeditor.css` и `curvefield.css`. Всё это охраняет тест `tiers.test.ts`; контракт холста описан в [docs/canvas.ru.md](docs/canvas.ru.md), переходы между точками кривой в [docs/ease.ru.md](docs/ease.ru.md).
|
|
107
|
+
|
|
108
|
+
Правило: модуль попадает сюда, когда он понадобился во втором проекте. Ядро модулей не знает про Vue и DOM, если это не их задача.
|
|
109
|
+
|
|
110
|
+
## Разработка
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
npm install
|
|
114
|
+
npm test # vitest
|
|
115
|
+
npm run typecheck
|
|
116
|
+
npm run build # dist/ (vite + tsc declarations)
|
|
117
|
+
npm run smoke # упаковать, поставить во временное приложение рядом с TaoUI, собрать
|
|
118
|
+
npm run sandbox # песочница: http://localhost:5300, страницы из sandbox/
|
|
119
|
+
npm run dev # watch: пересборка JS и деклараций
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Новый модуль: файл `src/<имя>.ts` (или папка с `index.ts`) и запись в `exports` в `package.json`; тест `exports.test.ts` следит, чтобы они совпадали. Подробнее: [CONTRIBUTING.ru.md](CONTRIBUTING.ru.md).
|
|
123
|
+
|
|
124
|
+
Работа с локальной копией вместо npm: в `package.json` проекта `"@1337exp/taoux": "file:../taoux"` (правки видны сразу после `npm run dev` здесь). Тогда в `vite.config.ts` потребителя нужен `resolve: { dedupe: ['vue'] }`, а в `tsconfig.json` в `paths` строка `"vue": ["./node_modules/vue"]`: иначе у слинкованного пакета своя копия Vue и реактивность ломается. Обычной установке из npm ничего из этого не нужно.
|
|
125
|
+
|
|
126
|
+
<a id="песочница"></a>
|
|
127
|
+
|
|
128
|
+
## Песочница
|
|
129
|
+
|
|
130
|
+
Папка `sandbox/` это демо и поле для проверки: страницы подключают модули прямо из `src/`, без сборки. Сейчас там `curveeditor`, `curvefield`, `gradienteditor`, `slider`, `color` и `playback`, с переключателем языка (EN / RU) и темы (тёмная / светлая: тема TaoUI через мост). Новая страница = `sandbox/<имя>.html` + `.ts` + демо `.vue` и ссылка в `sandbox/index.html`. `npm run sandbox:build` собирает статическую копию с относительными путями, её можно положить в любую папку (например, `/sandbox/taoux/`).
|
|
131
|
+
|
|
132
|
+
Скриншоты и ролики в этом README сняты с песочницы: см. [docs/media](docs/media/README.md).
|
|
133
|
+
|
|
134
|
+
## Участие в проекте
|
|
135
|
+
|
|
136
|
+
Issues и pull request'ы приветствуются, см. [CONTRIBUTING.ru.md](CONTRIBUTING.ru.md). Об уязвимостях: [SECURITY.md](SECURITY.md).
|
|
137
|
+
|
|
138
|
+
## Лицензия
|
|
139
|
+
|
|
140
|
+
[MIT](LICENSE) © 2026 1337exp
|
package/dist/camera.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Camera: screen point = world * z + (x, y).
|
|
3
|
+
* Screen coordinates here are relative to the top-left corner of the canvas.
|
|
4
|
+
* Камера: экранная точка = мировая * z + (x, y).
|
|
5
|
+
* Экранные координаты здесь — относительно левого верхнего угла холста.
|
|
6
|
+
*/
|
|
7
|
+
export interface Camera {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
z: number;
|
|
11
|
+
}
|
|
12
|
+
export declare const MIN_ZOOM = 0.2;
|
|
13
|
+
export declare const MAX_ZOOM = 2;
|
|
14
|
+
export declare const createCamera: () => Camera;
|
|
15
|
+
export declare function screenToWorld(cam: Camera, sx: number, sy: number): [number, number];
|
|
16
|
+
export declare function worldToScreen(cam: Camera, wx: number, wy: number): [number, number];
|
|
17
|
+
export declare function panBy(cam: Camera, dx: number, dy: number): Camera;
|
|
18
|
+
/**
|
|
19
|
+
* Zoom by `factor`; the point under the cursor (sx, sy) stays where it is.
|
|
20
|
+
* Масштаб в `factor` раз; точка под курсором (sx, sy) остаётся на месте.
|
|
21
|
+
*/
|
|
22
|
+
export declare function zoomAt(cam: Camera, sx: number, sy: number, factor: number): Camera;
|
package/dist/camera.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//#region src/camera.ts
|
|
2
|
+
var MIN_ZOOM = .2;
|
|
3
|
+
var MAX_ZOOM = 2;
|
|
4
|
+
var createCamera = () => ({
|
|
5
|
+
x: 0,
|
|
6
|
+
y: 0,
|
|
7
|
+
z: 1
|
|
8
|
+
});
|
|
9
|
+
function screenToWorld(cam, sx, sy) {
|
|
10
|
+
return [(sx - cam.x) / cam.z, (sy - cam.y) / cam.z];
|
|
11
|
+
}
|
|
12
|
+
function worldToScreen(cam, wx, wy) {
|
|
13
|
+
return [wx * cam.z + cam.x, wy * cam.z + cam.y];
|
|
14
|
+
}
|
|
15
|
+
function panBy(cam, dx, dy) {
|
|
16
|
+
return {
|
|
17
|
+
...cam,
|
|
18
|
+
x: cam.x + dx,
|
|
19
|
+
y: cam.y + dy
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Zoom by `factor`; the point under the cursor (sx, sy) stays where it is.
|
|
24
|
+
* Масштаб в `factor` раз; точка под курсором (sx, sy) остаётся на месте.
|
|
25
|
+
*/
|
|
26
|
+
function zoomAt(cam, sx, sy, factor) {
|
|
27
|
+
const z = Math.min(2, Math.max(MIN_ZOOM, cam.z * factor));
|
|
28
|
+
const k = z / cam.z;
|
|
29
|
+
return {
|
|
30
|
+
x: sx - (sx - cam.x) * k,
|
|
31
|
+
y: sy - (sy - cam.y) * k,
|
|
32
|
+
z
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { MAX_ZOOM, MIN_ZOOM, createCamera, panBy, screenToWorld, worldToScreen, zoomAt };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=camera.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"camera.js","names":[],"sources":["../src/camera.ts"],"sourcesContent":["/**\n * Camera: screen point = world * z + (x, y).\n * Screen coordinates here are relative to the top-left corner of the canvas.\n * Камера: экранная точка = мировая * z + (x, y).\n * Экранные координаты здесь — относительно левого верхнего угла холста.\n */\nexport interface Camera {\n x: number;\n y: number;\n z: number;\n}\n\nexport const MIN_ZOOM = 0.2;\nexport const MAX_ZOOM = 2;\n\nexport const createCamera = (): Camera => ({ x: 0, y: 0, z: 1 });\n\nexport function screenToWorld(cam: Camera, sx: number, sy: number): [number, number] {\n return [(sx - cam.x) / cam.z, (sy - cam.y) / cam.z];\n}\n\nexport function worldToScreen(cam: Camera, wx: number, wy: number): [number, number] {\n return [wx * cam.z + cam.x, wy * cam.z + cam.y];\n}\n\nexport function panBy(cam: Camera, dx: number, dy: number): Camera {\n return { ...cam, x: cam.x + dx, y: cam.y + dy };\n}\n\n/**\n * Zoom by `factor`; the point under the cursor (sx, sy) stays where it is.\n * Масштаб в `factor` раз; точка под курсором (sx, sy) остаётся на месте.\n */\nexport function zoomAt(cam: Camera, sx: number, sy: number, factor: number): Camera {\n const z = Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, cam.z * factor));\n const k = z / cam.z;\n return { x: sx - (sx - cam.x) * k, y: sy - (sy - cam.y) * k, z };\n}\n"],"mappings":";AAYA,IAAa,WAAW;AACxB,IAAa,WAAW;AAExB,IAAa,sBAA8B;CAAE,GAAG;CAAG,GAAG;CAAG,GAAG;AAAE;AAE9D,SAAgB,cAAc,KAAa,IAAY,IAA8B;CACjF,OAAO,EAAE,KAAK,IAAI,KAAK,IAAI,IAAI,KAAK,IAAI,KAAK,IAAI,CAAC;AACtD;AAEA,SAAgB,cAAc,KAAa,IAAY,IAA8B;CACjF,OAAO,CAAC,KAAK,IAAI,IAAI,IAAI,GAAG,KAAK,IAAI,IAAI,IAAI,CAAC;AAClD;AAEA,SAAgB,MAAM,KAAa,IAAY,IAAoB;CAC/D,OAAO;EAAE,GAAG;EAAK,GAAG,IAAI,IAAI;EAAI,GAAG,IAAI,IAAI;CAAG;AAClD;;;;;AAMA,SAAgB,OAAO,KAAa,IAAY,IAAY,QAAwB;CAChF,MAAM,IAAI,KAAK,IAAA,GAAc,KAAK,IAAI,UAAU,IAAI,IAAI,MAAM,CAAC;CAC/D,MAAM,IAAI,IAAI,IAAI;CAClB,OAAO;EAAE,GAAG,MAAM,KAAK,IAAI,KAAK;EAAG,GAAG,MAAM,KAAK,IAAI,KAAK;EAAG;CAAE;AACnE"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { CanvasHost, CanvasOptions } from './host';
|
|
2
|
+
declare const __VLS_export: <P>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
3
|
+
props: import("vue").PublicProps & __VLS_PrettifyLocal<{
|
|
4
|
+
/**
|
|
5
|
+
* The bridge to the app. Must be a stable object: the canvas takes it once.
|
|
6
|
+
* Мост к приложению. Должен быть стабильным объектом: холст берёт его один раз.
|
|
7
|
+
*/
|
|
8
|
+
host: CanvasHost<P>;
|
|
9
|
+
options: CanvasOptions<P>;
|
|
10
|
+
/**
|
|
11
|
+
* The step of the fine background grid, world units.
|
|
12
|
+
* Шаг мелкой сетки на фоне, мировые единицы.
|
|
13
|
+
*/
|
|
14
|
+
grid?: number;
|
|
15
|
+
}> & (typeof globalThis extends {
|
|
16
|
+
__VLS_PROPS_FALLBACK: infer P_1;
|
|
17
|
+
} ? P_1 : {});
|
|
18
|
+
expose: (exposed: import("vue").ShallowUnwrapRef<{
|
|
19
|
+
root: import("vue").Ref<HTMLElement | null, HTMLElement | null>;
|
|
20
|
+
}>) => void;
|
|
21
|
+
attrs: any;
|
|
22
|
+
slots: {
|
|
23
|
+
default?: (props: {}) => any;
|
|
24
|
+
} & {
|
|
25
|
+
overlay?: (props: {}) => any;
|
|
26
|
+
};
|
|
27
|
+
emit: {};
|
|
28
|
+
}>) => import("vue").VNode & {
|
|
29
|
+
__ctx?: NonNullable<Awaited<typeof __VLS_setup>>;
|
|
30
|
+
};
|
|
31
|
+
declare const _default: typeof __VLS_export;
|
|
32
|
+
export default _default;
|
|
33
|
+
type __VLS_PrettifyLocal<T> = (T extends any ? {
|
|
34
|
+
[K in keyof T]: T[K];
|
|
35
|
+
} : {
|
|
36
|
+
[K in keyof T as K]: T[K];
|
|
37
|
+
}) & {};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import type { Camera } from '../camera';
|
|
2
|
+
/**
|
|
3
|
+
* A mutable tuple: app stores accept exactly these.
|
|
4
|
+
* Изменяемый кортеж: сторы приложений принимают именно такие.
|
|
5
|
+
*/
|
|
6
|
+
export type Point = [number, number];
|
|
7
|
+
export interface Size {
|
|
8
|
+
w: number;
|
|
9
|
+
h: number;
|
|
10
|
+
}
|
|
11
|
+
export interface Rect extends Size {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Which side or corner is dragged: compass directions.
|
|
17
|
+
* За какую грань или угол тянут: стороны света.
|
|
18
|
+
*/
|
|
19
|
+
export type ResizeEdge = 'n' | 's' | 'e' | 'w' | 'ne' | 'nw' | 'se' | 'sw';
|
|
20
|
+
/**
|
|
21
|
+
* What the canvas asks to do on a double click or a double tap.
|
|
22
|
+
* Что холст просит сделать по двойному клику или двойному тапу.
|
|
23
|
+
*/
|
|
24
|
+
export type ActivateTarget = {
|
|
25
|
+
kind: 'link';
|
|
26
|
+
id: string;
|
|
27
|
+
at: Point;
|
|
28
|
+
} | {
|
|
29
|
+
kind: 'handle';
|
|
30
|
+
nodeId: string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Dragging out a link. `P` is a pin address: opaque for the canvas, only the app understands it.
|
|
34
|
+
* Протягивание связи. `P` — адрес пина: для холста непрозрачный, его понимает только приложение.
|
|
35
|
+
*/
|
|
36
|
+
export interface ConnectHost<P> {
|
|
37
|
+
/**
|
|
38
|
+
* The pin being dragged from (null when nothing is being dragged).
|
|
39
|
+
* Пин, с которого тянут (null, если сейчас не тянут).
|
|
40
|
+
*/
|
|
41
|
+
readonly origin: P | null;
|
|
42
|
+
start(pin: P, cursor: Point): void;
|
|
43
|
+
update(cursor: Point, target: P | null): void;
|
|
44
|
+
/**
|
|
45
|
+
* Finish on `target`; true if a link was created.
|
|
46
|
+
* Завершить на `target`; true, если связь создана.
|
|
47
|
+
*/
|
|
48
|
+
finish(target: P | null): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* The gesture was aborted: the drag is discarded without a link.
|
|
51
|
+
* Жест оборван: протягивание отбрасывается без связи.
|
|
52
|
+
*/
|
|
53
|
+
cancel(): void;
|
|
54
|
+
}
|
|
55
|
+
export interface ResizeHost {
|
|
56
|
+
rectOf(nodeId: string): Rect | null;
|
|
57
|
+
/**
|
|
58
|
+
* `start` is the rectangle at the moment of grabbing, (dx, dy) is the mouse shift since then in world units.
|
|
59
|
+
* `start` — прямоугольник в момент захвата, (dx, dy) — сдвиг мыши с тех пор в мировых единицах.
|
|
60
|
+
*/
|
|
61
|
+
from(nodeId: string, edge: ResizeEdge, start: Rect, dx: number, dy: number, snap: boolean): void;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Everything the canvas needs from the app. The canvas does not know the data model (nodes, links, pins, file):
|
|
65
|
+
* it parses gestures and calls these methods. Readable members must be reactive (getters over store state).
|
|
66
|
+
* Всё, что холсту нужно от приложения. Модель данных (ноды, связи, пины, файл) холст не знает:
|
|
67
|
+
* он разбирает жесты и зовёт эти методы. Читаемые члены должны быть реактивными (геттеры над состоянием стора).
|
|
68
|
+
*/
|
|
69
|
+
export interface CanvasHost<P = unknown> {
|
|
70
|
+
readonly camera: Camera;
|
|
71
|
+
setCamera(camera: Camera): void;
|
|
72
|
+
/**
|
|
73
|
+
* The canvas reports its size in px (needed to place new nodes at the screen centre).
|
|
74
|
+
* Холст сообщает свой размер в px (нужен, чтобы ставить новые ноды в центр экрана).
|
|
75
|
+
*/
|
|
76
|
+
setViewport(size: Size): void;
|
|
77
|
+
readonly selection: ReadonlySet<string>;
|
|
78
|
+
setSelection(ids: Iterable<string>): void;
|
|
79
|
+
toggleSelected(nodeId: string): void;
|
|
80
|
+
selectConnection(id: string | null): void;
|
|
81
|
+
/**
|
|
82
|
+
* The node that was grabbed goes on top of the others.
|
|
83
|
+
* Нода, за которую взялись, ложится поверх остальных.
|
|
84
|
+
*/
|
|
85
|
+
raise?(nodeId: string): void;
|
|
86
|
+
beginDrag(primary: string): void;
|
|
87
|
+
moveSelected(dx: number, dy: number, snap: boolean): void;
|
|
88
|
+
endDrag(): void;
|
|
89
|
+
/**
|
|
90
|
+
* The gesture is over: the state goes into history as one step.
|
|
91
|
+
* Жест закончен: состояние идёт в историю как один шаг.
|
|
92
|
+
*/
|
|
93
|
+
commit(): void;
|
|
94
|
+
undo(): void;
|
|
95
|
+
redo(): void;
|
|
96
|
+
removeSelected(): void;
|
|
97
|
+
readonly paletteOpen: boolean;
|
|
98
|
+
openPalette(screen: Point, world: Point, origin: P | null): void;
|
|
99
|
+
closePalette(): void;
|
|
100
|
+
connect?: ConnectHost<P>;
|
|
101
|
+
resize?: ResizeHost;
|
|
102
|
+
activate?(target: ActivateTarget): void;
|
|
103
|
+
/**
|
|
104
|
+
* Grid snapping is on (Alt turns it off for the moment).
|
|
105
|
+
* Привязка к сетке включена (Alt на время отключает).
|
|
106
|
+
*/
|
|
107
|
+
readonly snapEnabled?: boolean;
|
|
108
|
+
/**
|
|
109
|
+
* The touch "Select" mode: one finger draws a frame, a tap adds to the selection.
|
|
110
|
+
* Сенсорный режим «Выделение»: один палец рисует рамку, тап добавляет в выделение.
|
|
111
|
+
*/
|
|
112
|
+
readonly selectMode?: boolean;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* How the canvas finds pins in the DOM. The rest of the DOM contract the app's node view must keep:
|
|
116
|
+
* `data-node-id` on the node root; `data-conn-id` on the link line (set by `TaoxLinks`); `data-resize="n|s|e|w|ne|nw|se|sw"`
|
|
117
|
+
* on the handles; `data-node-container` on the root of a container node (only its strip counts for the selection frame);
|
|
118
|
+
* `data-node-handle` on the strip a node is dragged by (a double click on it calls `activate`).
|
|
119
|
+
* Как холст находит пины в DOM. Остальной DOM-контракт, который обязан соблюдать вид ноды приложения:
|
|
120
|
+
* `data-node-id` на корне ноды; `data-conn-id` на линии связи (ставит `TaoxLinks`); `data-resize="n|s|e|w|ne|nw|se|sw"`
|
|
121
|
+
* на ручках; `data-node-container` на корне ноды-контейнера (в рамку выделения попадает только её полоса);
|
|
122
|
+
* `data-node-handle` на полосе, за которую тянут ноду (по двойному клику по ней вызывается `activate`).
|
|
123
|
+
*/
|
|
124
|
+
export interface CanvasOptions<P> {
|
|
125
|
+
/**
|
|
126
|
+
* The pin at the element under the pointer (by the `data-*` the app's node view sets).
|
|
127
|
+
* Пин у элемента под указателем (по `data-*`, которые ставит вид ноды приложения).
|
|
128
|
+
*/
|
|
129
|
+
pinAt(target: EventTarget | null): P | null;
|
|
130
|
+
/**
|
|
131
|
+
* The pin nearest to a point: for example, the side of a node whose body a link was released over. Without it `pinAt` is used.
|
|
132
|
+
* Пин, ближайший к точке: например, сторона ноды, над телом которой отпустили связь. Без него берётся `pinAt`.
|
|
133
|
+
*/
|
|
134
|
+
pinNear?(point: {
|
|
135
|
+
clientX: number;
|
|
136
|
+
clientY: number;
|
|
137
|
+
}): P | null;
|
|
138
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type Ref } from 'vue';
|
|
2
|
+
import type { CanvasHost, CanvasOptions } from './host';
|
|
3
|
+
/**
|
|
4
|
+
* The selection frame in client coordinates.
|
|
5
|
+
* Рамка выделения в клиентских координатах.
|
|
6
|
+
*/
|
|
7
|
+
export interface Marquee {
|
|
8
|
+
x0: number;
|
|
9
|
+
y0: number;
|
|
10
|
+
x1: number;
|
|
11
|
+
y1: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The canvas gesture machine: mouse, touch (tap, double tap, long press, pinch), wheel, auto-scroll at the edge,
|
|
15
|
+
* keys. It does not know the data model: the app decides through `host`.
|
|
16
|
+
* The host is taken once at creation: it must be a stable object.
|
|
17
|
+
* Машина жестов холста: мышь, сенсор (тап, двойной тап, долгое нажатие, щипок), колесо, автопрокрутка у края,
|
|
18
|
+
* клавиши. Не знает модель данных: решения принимает приложение через `host`.
|
|
19
|
+
* Хост берётся один раз при создании: он должен быть стабильным объектом.
|
|
20
|
+
*/
|
|
21
|
+
export declare function useCanvasGestures<P>(root: Ref<HTMLElement | null>, host: CanvasHost<P>, options: CanvasOptions<P>): {
|
|
22
|
+
marquee: Ref<{
|
|
23
|
+
x0: number;
|
|
24
|
+
y0: number;
|
|
25
|
+
x1: number;
|
|
26
|
+
y1: number;
|
|
27
|
+
} | null, Marquee | {
|
|
28
|
+
x0: number;
|
|
29
|
+
y0: number;
|
|
30
|
+
x1: number;
|
|
31
|
+
y1: number;
|
|
32
|
+
} | null>;
|
|
33
|
+
debug: boolean;
|
|
34
|
+
debugText: Ref<string, string>;
|
|
35
|
+
handlers: {
|
|
36
|
+
onPointerDown: (e: PointerEvent) => void;
|
|
37
|
+
onPointerMove: (e: PointerEvent) => void;
|
|
38
|
+
onPointerUp: (e: PointerEvent) => void;
|
|
39
|
+
onPointerCancel: (e: PointerEvent) => void;
|
|
40
|
+
onLostCapture: () => void;
|
|
41
|
+
onWheel: (e: WheelEvent) => void;
|
|
42
|
+
onDblClick: (e: MouseEvent) => void;
|
|
43
|
+
};
|
|
44
|
+
};
|