@ts-charts/drag 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/LICENSE.md +21 -0
- package/README.md +153 -0
- package/dist/constant.d.ts +1 -0
- package/dist/drag.d.ts +1 -0
- package/dist/event.d.ts +41 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/nodrag.d.ts +2 -0
- package/dist/noevent.d.ts +11 -0
- package/package.json +25 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Open Web Foundation
|
|
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
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
<p align="center"><img src=".github/art/cover.jpg" alt="Social Card of this repo"></p>
|
|
2
|
+
|
|
3
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
4
|
+
[![GitHub Actions][github-actions-src]][github-actions-href]
|
|
5
|
+
[![Commitizen friendly][commitizen-src]][commitizen-href]
|
|
6
|
+
<!-- [![npm downloads][npm-downloads-src]][npm-downloads-href] -->
|
|
7
|
+
<!-- [![Codecov][codecov-src]][codecov-href] -->
|
|
8
|
+
|
|
9
|
+
# ts-charts
|
|
10
|
+
|
|
11
|
+
> A complete TypeScript rewrite of D3.js โ fully typed, zero dependencies, Bun-first.
|
|
12
|
+
|
|
13
|
+
All 30 D3.js packages, rewritten from the ground up in TypeScript with `isolatedDeclarations` support. Ships as a single umbrella package or 30+ individually installable sub-packages.
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- ๐ท **Fully Typed** โ strict TypeScript with `isolatedDeclarations: true`, no `any` leaks
|
|
18
|
+
- ๐ฆ **Zero Dependencies** โ no external runtime dependencies, everything inlined
|
|
19
|
+
- โก **Bun-First** โ optimized for Bun, works in all modern browsers
|
|
20
|
+
- ๐ณ **Tree-Shakeable** โ ESM-only, import only what you need
|
|
21
|
+
- ๐งช **3,500+ Tests** โ comprehensive test suite ported from D3, all passing
|
|
22
|
+
- ๐ฏ **D3 API Compatible** โ drop-in replacement for D3.js
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# install the umbrella package (everything)
|
|
28
|
+
bun add ts-charts
|
|
29
|
+
|
|
30
|
+
# or install individual packages
|
|
31
|
+
bun add @ts-charts/scale
|
|
32
|
+
bun add @ts-charts/selection
|
|
33
|
+
bun add @ts-charts/shape
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
// import everything
|
|
40
|
+
import { scaleLinear, line, select } from 'ts-charts'
|
|
41
|
+
|
|
42
|
+
// or import from individual packages
|
|
43
|
+
import { scaleLinear } from '@ts-charts/scale'
|
|
44
|
+
import { line } from '@ts-charts/shape'
|
|
45
|
+
import { select } from '@ts-charts/selection'
|
|
46
|
+
|
|
47
|
+
// create a linear scale
|
|
48
|
+
const x = scaleLinear()
|
|
49
|
+
.domain([0, 100])
|
|
50
|
+
.range([0, 960])
|
|
51
|
+
|
|
52
|
+
// create a line generator
|
|
53
|
+
const myLine = line()
|
|
54
|
+
.x((d: [number, number]) => x(d[0]))
|
|
55
|
+
.y((d: [number, number]) => d[1])
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Packages
|
|
59
|
+
|
|
60
|
+
| Package | Description |
|
|
61
|
+
|---------|-------------|
|
|
62
|
+
| `@ts-charts/array` | Array manipulation, statistics, histograms, bisection |
|
|
63
|
+
| `@ts-charts/axis` | SVG axis generators for scales |
|
|
64
|
+
| `@ts-charts/brush` | 1D and 2D brush selections |
|
|
65
|
+
| `@ts-charts/chord` | Chord diagram layout and ribbon generator |
|
|
66
|
+
| `@ts-charts/color` | Color spaces: RGB, HSL, Lab, HCL, Cubehelix |
|
|
67
|
+
| `@ts-charts/contour` | Contour polygons and density estimation |
|
|
68
|
+
| `@ts-charts/delaunay` | Delaunay triangulation and Voronoi diagrams |
|
|
69
|
+
| `@ts-charts/dispatch` | Named event dispatching |
|
|
70
|
+
| `@ts-charts/drag` | Drag-and-drop interaction |
|
|
71
|
+
| `@ts-charts/dsv` | CSV and TSV parsing and formatting |
|
|
72
|
+
| `@ts-charts/ease` | Easing functions for transitions |
|
|
73
|
+
| `@ts-charts/fetch` | Convenience wrappers for the Fetch API |
|
|
74
|
+
| `@ts-charts/force` | Force-directed graph layout |
|
|
75
|
+
| `@ts-charts/format` | Number formatting (SI, fixed, currency, etc.) |
|
|
76
|
+
| `@ts-charts/geo` | Geographic projections and path generators |
|
|
77
|
+
| `@ts-charts/hierarchy` | Tree, treemap, pack, and partition layouts |
|
|
78
|
+
| `@ts-charts/interpolate` | Value interpolation for animations |
|
|
79
|
+
| `@ts-charts/path` | SVG path serialization |
|
|
80
|
+
| `@ts-charts/polygon` | Polygon area, centroid, convex hull |
|
|
81
|
+
| `@ts-charts/quadtree` | 2D spatial indexing |
|
|
82
|
+
| `@ts-charts/random` | Random number generators for various distributions |
|
|
83
|
+
| `@ts-charts/scale` | Scales: linear, log, ordinal, time, etc. |
|
|
84
|
+
| `@ts-charts/scale-chromatic` | Color schemes: sequential, diverging, categorical |
|
|
85
|
+
| `@ts-charts/selection` | DOM selection and manipulation |
|
|
86
|
+
| `@ts-charts/shape` | Shape generators: line, area, arc, pie, stack |
|
|
87
|
+
| `@ts-charts/time` | Time intervals and rounding |
|
|
88
|
+
| `@ts-charts/time-format` | Date/time parsing and formatting |
|
|
89
|
+
| `@ts-charts/timer` | Efficient animation scheduling via `requestAnimationFrame` |
|
|
90
|
+
| `@ts-charts/transition` | Animated transitions on selections |
|
|
91
|
+
| `@ts-charts/zoom` | Pan and zoom interaction |
|
|
92
|
+
|
|
93
|
+
## Testing
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
bun test
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Changelog
|
|
100
|
+
|
|
101
|
+
Please see our [releases][releases-href] page for more information on what has changed recently.
|
|
102
|
+
|
|
103
|
+
## Contributing
|
|
104
|
+
|
|
105
|
+
Please see [CONTRIBUTING][contributing-href] for details.
|
|
106
|
+
|
|
107
|
+
## Community
|
|
108
|
+
|
|
109
|
+
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
|
|
110
|
+
|
|
111
|
+
[Discussions on GitHub][discussions-href]
|
|
112
|
+
|
|
113
|
+
For casual chit-chat with others using this package:
|
|
114
|
+
|
|
115
|
+
[Join the Stacks Discord Server][discord-href]
|
|
116
|
+
|
|
117
|
+
## Postcardware
|
|
118
|
+
|
|
119
|
+
"Software that is free, but hopes for a postcard." We love receiving postcards from around the world showing where Stacks is being used! We showcase them on our website too.
|
|
120
|
+
|
|
121
|
+
Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States ๐
|
|
122
|
+
|
|
123
|
+
## Sponsors
|
|
124
|
+
|
|
125
|
+
We would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.
|
|
126
|
+
|
|
127
|
+
- [JetBrains][jetbrains-href]
|
|
128
|
+
- [The Solana Foundation][solana-href]
|
|
129
|
+
|
|
130
|
+
## License
|
|
131
|
+
|
|
132
|
+
The MIT License (MIT). Please see [LICENSE][license-href] for more information.
|
|
133
|
+
|
|
134
|
+
Made with ๐
|
|
135
|
+
|
|
136
|
+
<!-- Badges -->
|
|
137
|
+
[npm-version-src]: https://img.shields.io/npm/v/ts-charts?style=flat-square
|
|
138
|
+
[npm-version-href]: https://npmjs.com/package/ts-charts
|
|
139
|
+
[github-actions-src]: https://img.shields.io/github/actions/workflow/status/stacksjs/ts-charts/ci.yml?style=flat-square&branch=main
|
|
140
|
+
[github-actions-href]: https://github.com/stacksjs/ts-charts/actions?query=workflow%3Aci
|
|
141
|
+
|
|
142
|
+
[commitizen-src]: https://img.shields.io/badge/commitizen-friendly-brightgreen.svg
|
|
143
|
+
[commitizen-href]: http://commitizen.github.io/cz-cli/
|
|
144
|
+
[releases-href]: https://github.com/stacksjs/ts-charts/releases
|
|
145
|
+
[contributing-href]: .github/CONTRIBUTING.md
|
|
146
|
+
[discussions-href]: https://github.com/stacksjs/ts-charts/discussions
|
|
147
|
+
[discord-href]: https://discord.gg/stacksjs
|
|
148
|
+
[jetbrains-href]: https://www.jetbrains.com/
|
|
149
|
+
[solana-href]: https://solana.com/
|
|
150
|
+
[license-href]: LICENSE.md
|
|
151
|
+
|
|
152
|
+
<!-- [codecov-src]: https://img.shields.io/codecov/c/gh/stacksjs/ts-charts/main?style=flat-square
|
|
153
|
+
[codecov-href]: https://codecov.io/gh/stacksjs/ts-charts -->
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function constant<T>(x: T): () => T;
|
package/dist/drag.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function drag(): any;
|
package/dist/event.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
declare interface DragDispatch {
|
|
2
|
+
on(...args: unknown[]): unknown
|
|
3
|
+
}
|
|
4
|
+
export declare class DragEvent {
|
|
5
|
+
readonly type: string;
|
|
6
|
+
readonly sourceEvent: Event;
|
|
7
|
+
readonly subject: { x: number; y: number } | undefined;
|
|
8
|
+
readonly target: unknown;
|
|
9
|
+
readonly identifier: string | number;
|
|
10
|
+
readonly active: number;
|
|
11
|
+
readonly x: number;
|
|
12
|
+
readonly y: number;
|
|
13
|
+
readonly dx: number;
|
|
14
|
+
readonly dy: number;
|
|
15
|
+
readonly private _: DragDispatch;
|
|
16
|
+
constructor(type: string, {
|
|
17
|
+
sourceEvent,
|
|
18
|
+
subject,
|
|
19
|
+
target,
|
|
20
|
+
identifier,
|
|
21
|
+
active,
|
|
22
|
+
x,
|
|
23
|
+
y,
|
|
24
|
+
dx,
|
|
25
|
+
dy,
|
|
26
|
+
dispatch,
|
|
27
|
+
}: {
|
|
28
|
+
sourceEvent: Event
|
|
29
|
+
// eslint-disable-next-line pickier/no-unused-vars, max-statements-per-line
|
|
30
|
+
subject?: { x: number; y: number }
|
|
31
|
+
target: unknown
|
|
32
|
+
identifier: string | number
|
|
33
|
+
active: number
|
|
34
|
+
x: number
|
|
35
|
+
y: number
|
|
36
|
+
dx: number
|
|
37
|
+
dy: number
|
|
38
|
+
dispatch: DragDispatch
|
|
39
|
+
});
|
|
40
|
+
on(args: unknown[]): unknown;
|
|
41
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var $f={name:"",value:()=>{}};function Bf(f,w){return f.trim().split(/^|\s+/).map((E)=>{let q="",T=E.indexOf(".");if(T>=0)q=E.slice(T+1),E=E.slice(0,T);if(E&&!w.hasOwnProperty(E))throw Error(`unknown type: ${E}`);return{type:E,name:q}})}function Df(f,w){for(let E=0,q=f.length;E<q;++E){let T=f[E];if(T.name===w)return T.value}}function If(f,w,E){for(let q=0,T=f.length;q<T;++q)if(f[q].name===w){f[q]=$f,f=f.slice(0,q).concat(f.slice(q+1));break}if(E!=null)f.push({name:w,value:E});return f}class h{_;constructor(f){this._=f}on(f,w){let E=Bf(`${f}`,this._),q,T=-1,N=E.length;if(arguments.length<2){while(++T<N)if(q=E[T].type,q){let A=Df(this._[q],E[T].name);if(A)return A}return}if(w!=null&&typeof w!=="function")throw Error(`invalid callback: ${w}`);while(++T<N){let A=E[T];if(q=A.type)this._[q]=If(this._[q],A.name,w??null);else if(w==null)for(q in this._)this._[q]=If(this._[q],A.name,null)}return this}copy(){let f={};for(let w of Object.keys(this._))f[w]=this._[w].slice();return new h(f)}call(f,w,...E){if(!this._.hasOwnProperty(f))throw Error(`unknown type: ${f}`);let q=this._[f];for(let T=0,N=q.length;T<N;++T)q[T].value.apply(w,E)}apply(f,w,E){if(!this._.hasOwnProperty(f))throw Error(`unknown type: ${f}`);let q=this._[f];for(let T=0,N=q.length;T<N;++T)q[T].value.apply(w,E)}static[Symbol.hasInstance](f){return f!=null&&typeof f==="object"&&Object.getPrototypeOf(f)===h.prototype}}function e(...f){let w={};for(let E=0,q=f.length;E<q;++E){let T=`${f[E]}`;if(!T||T in w||/[\s.]/.test(T))throw Error(`illegal type: ${T}`);w[T]=[]}return new h(w)}var ff="http://www.w3.org/1999/xhtml",Kf={svg:"http://www.w3.org/2000/svg",xhtml:"http://www.w3.org/1999/xhtml",xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"},u=Kf;function V(f){let w=f=`${f}`,E=w.indexOf(":");if(E>=0&&(w=f.slice(0,E))!=="xmlns")f=f.slice(E+1);return u.hasOwnProperty(w)?{space:u[w],local:f}:f}function xf(f){return function(){let w=this.ownerDocument||this.document||document,E=this.namespaceURI;return E===ff&&w.documentElement.namespaceURI===ff?w.createElement(f):E?w.createElementNS(E,f):w.createElement(f)}}function Gf(f){return function(){return(this.ownerDocument||this.document||document).createElementNS(f.space,f.local)}}function S(f){let w=V(f);return(typeof w==="object"?Gf:xf)(w)}function Rf(){return}function b(f){return f==null?Rf:function(){return this.querySelector(f)||void 0}}function _f(){return[]}function v(f){return f==null?_f:function(){return this.querySelectorAll(f)}}function i(f){return function(){return this.matches(f)}}function wf(f){return function(w){return w.matches(f)}}function g(f){return f.ownerDocument&&f.ownerDocument.defaultView||f.document&&f||f.defaultView}function s(f){return f==null?[]:Array.isArray(f)?f:Array.from(f)}function Ef(f){return function(){return f}}function y(f){return Array(f.length)}class r{ownerDocument;namespaceURI;_next;_parent;__data__;constructor(f,w){this.ownerDocument=f.ownerDocument,this.namespaceURI=f.namespaceURI,this._next=null,this._parent=f,this.__data__=w}appendChild(f){return this._parent.insertBefore(f,this._next)}insertBefore(f,w){return this._parent.insertBefore(f,w)}querySelector(f){return this._parent.querySelector(f)}querySelectorAll(f){return this._parent.querySelectorAll(f)}}var Tf=[null];function Lf(f){return function(){this.removeAttribute(f)}}function Cf(f){return function(){this.removeAttributeNS(f.space,f.local)}}function Vf(f,w){return function(){this.setAttribute(f,`${w}`)}}function Sf(f,w){return function(){this.setAttributeNS(f.space,f.local,`${w}`)}}function kf(f,w){return function(){let E=w.apply(this,arguments);if(E==null)this.removeAttribute(f);else this.setAttribute(f,String(E))}}function jf(f,w){return function(){let E=w.apply(this,arguments);if(E==null)this.removeAttributeNS(f.space,f.local);else this.setAttributeNS(f.space,f.local,String(E))}}function Ff(f){return function(){this.style.removeProperty(f)}}function hf(f,w,E){return function(){this.style.setProperty(f,w,E)}}function bf(f,w,E){return function(){let q=w.apply(this,arguments);if(q==null)this.style.removeProperty(f);else this.style.setProperty(f,`${q}`,E)}}function Mf(f,w){let E=f.style.getPropertyValue(w);if(E!=null&&E!=="")return`${E}`;let q=g(f)||(typeof window<"u"?window:void 0);if(!q||typeof q.getComputedStyle!=="function")return"";let T=q.getComputedStyle(f,null).getPropertyValue(w);return T!=null&&T!==""?`${T}`:""}function gf(f){return function(){delete this[f]}}function yf(f,w){return function(){this[f]=w}}function rf(f,w){return function(){let E=w.apply(this,arguments);if(E==null)delete this[f];else this[f]=E}}function zf(f){return f.trim().split(/^|\s+/)}function qf(f){return f.classList||new Of(f)}class Of{_node;_names;constructor(f){this._node=f,this._names=zf(f.getAttribute("class")||"")}add(f){if(this._names.indexOf(f)<0)this._names.push(f),this._node.setAttribute("class",this._names.join(" "))}remove(f){let w=this._names.indexOf(f);if(w>=0)this._names.splice(w,1),this._node.setAttribute("class",this._names.join(" "))}contains(f){return this._names.indexOf(f)>=0}}function Xf(f,w){let E=qf(f),q=-1,T=w.length;while(++q<T)E.add(w[q])}function Jf(f,w){let E=qf(f),q=-1,T=w.length;while(++q<T)E.remove(w[q])}function cf(f){return function(){Xf(this,f)}}function mf(f){return function(){Jf(this,f)}}function df(f,w){return function(){(w.apply(this,arguments)?Xf:Jf)(this,f)}}function lf(){this.textContent=""}function uf(f){return function(){this.textContent=`${f}`}}function vf(f){return function(){let w=f.apply(this,arguments);this.textContent=w==null?"":`${w}`}}function sf(){this.innerHTML=""}function pf(f){return function(){this.innerHTML=f}}function of(f){return function(){let w=f.apply(this,arguments);this.innerHTML=w==null?"":w}}function tf(){if(this.nextSibling)this.parentNode.appendChild(this)}function nf(){if(this.previousSibling)this.parentNode.insertBefore(this,this.parentNode.firstChild)}function af(){let f=this.parentNode;if(f)f.removeChild(this)}function ef(){let f=this.cloneNode(!1),w=this.parentNode;return w?w.insertBefore(f,this.nextSibling):f}function fw(){let f=this.cloneNode(!0),w=this.parentNode;return w?w.insertBefore(f,this.nextSibling):f}function ww(f,w){return function(E){let q=this||w||E.currentTarget;f.call(q,E,q?.__data__)}}function Ew(f){return f.trim().split(/^|\s+/).map(function(w){let E="",q=w.indexOf(".");if(q>=0)E=w.slice(q+1),w=w.slice(0,q);return{type:w,name:E}})}function Tw(f){return function(){let w=this.__on;if(!w)return;let E=-1;for(let q=0,T=w.length,N;q<T;++q)if(N=w[q],(!f.type||N.type===f.type)&&N.name===f.name)this.removeEventListener(N.type,N.listener,N.options);else w[++E]=N;if(++E)w.length=E;else delete this.__on}}function qw(f,w,E){return function(){let q=this.__on,T,N=ww(w,this);if(q){for(let A=0,W=q.length;A<W;++A)if((T=q[A]).type===f.type&&T.name===f.name){this.removeEventListener(T.type,T.listener,T.options),this.addEventListener(T.type,T.listener=N,T.options=E),T.value=w;return}}if(this.addEventListener(f.type,N,E),T={type:f.type,name:f.name,value:w,listener:N,options:E},!q)this.__on=[T];else q.push(T)}}function Pf(f,w,E){let q=g(f)||(typeof window<"u"?window:void 0),T;if(q&&typeof q.CustomEvent==="function")T=new q.CustomEvent(w,E);else if(typeof CustomEvent==="function")T=new CustomEvent(w,E);else{let N=(q||window).document.createEvent("Event");if(E)N.initEvent(w,E.bubbles??!1,E.cancelable??!1),N.detail=E.detail;else N.initEvent(w,!1,!1);T=N}f.dispatchEvent(T)}function Nw(f,w){return function(){return Pf(this,f,w)}}function Aw(f,w){return function(){return Pf(this,f,w.apply(this,arguments))}}function Uw(f,w,E,q,T,N){let A=0,W,H=w.length,I=N.length;for(;A<I;++A)if(W=w[A])W.__data__=N[A],q[A]=W;else E[A]=new r(f,N[A]);for(;A<H;++A)if(W=w[A])T[A]=W}function Ww(f,w,E,q,T,N,A){let W,H,I=new Map,M=w.length,Q=N.length,O=Array(M),X;for(W=0;W<M;++W)if(H=w[W])if(O[W]=X=A.call(H,H.__data__,W,w)+"",I.has(X))T[W]=H;else I.set(X,H);for(W=0;W<Q;++W)if(X=A.call(f,N[W],W,N)+"",H=I.get(X)){q[W]=H;let $=H;$.__data__=N[W],I.delete(X)}else E[W]=new r(f,N[W]);for(W=0;W<M;++W)if((H=w[W])&&I.get(O[W])===H)T[W]=H}function Hw(f){return f.__data__}function Iw(f){return typeof f==="object"&&"length"in f?f:Array.from(f)}function Mw(f){return function(){return s(f.apply(this,arguments))}}var zw=Array.prototype.find;function Ow(f){return function(){return zw.call(this.children,f)}}function Xw(){return this.firstElementChild??this.children[0]??null}var Jw=Array.prototype.filter;function Pw(){return Array.from(this.children)}function Qw(f){return function(){return Jw.call(this.children,f)}}function Yw(f,w){return f<w?-1:f>w?1:f>=w?0:NaN}function Zw(){return null}class Y{_groups;_parents;_enter;_exit;constructor(f,w){this._groups=f,this._parents=w}get parents(){return this._parents}select(f){if(typeof f!=="function")f=b(f);let w=this._groups,E=w.length,q=Array(E);for(let T=0;T<E;++T){let N=w[T],A=N.length,W=q[T]=Array(A);for(let H=0;H<A;++H){let I,M;if((I=N[H])&&(M=f.call(I,I.__data__,H,N))){if("__data__"in I)M.__data__=I.__data__;W[H]=M}}}return new Y(q,this._parents)}selectAll(f){if(typeof f==="function")f=Mw(f);else f=v(f);let w=this._groups,E=w.length,q=[],T=[];for(let N=0;N<E;++N){let A=w[N],W=A.length;for(let H=0;H<W;++H){let I;if(I=A[H])q.push(f.call(I,I.__data__,H,A)),T.push(I)}}return new Y(q,T)}selectChild(f){return this.select(f==null?Xw:Ow(typeof f==="function"?f:wf(f)))}selectChildren(f){return this.selectAll(f==null?Pw:Qw(typeof f==="function"?f:wf(f)))}filter(f){if(typeof f!=="function")f=i(f);let w=this._groups,E=w.length,q=Array(E);for(let T=0;T<E;++T){let N=w[T],A=N.length,W=q[T]=[];for(let H=0;H<A;++H){let I;if((I=N[H])&&f.call(I,I.__data__,H,N))W.push(I)}}return new Y(q,this._parents)}data(f,w){if(f===void 0)return Array.from(this,Hw);let E=this._parents,q=this._groups;if(typeof f!=="function")f=Ef(f);let T=q.length,N=Array(T),A=Array(T),W=Array(T);for(let I=0;I<T;++I){let M=E[I],Q=q[I],O=Q.length,X=Iw(f.call(M,M&&M.__data__,I,E)),$=X.length,j=A[I]=Array($),F=N[I]=Array($),m=W[I]=Array(O);if(w)Ww(M,Q,j,F,m,Array.from(X),w);else Uw(M,Q,j,F,m,Array.from(X));for(let G=0,R=0,U,z;G<$;++G)if(U=j[G]){if(G>=R)R=G+1;while(!(z=F[R])&&++R<$);U._next=z||null}}let H=new Y(N,E);return H._enter=A,H._exit=W,H}enter(){return new Y(this._enter||this._groups.map(y),this._parents)}exit(){return new Y(this._exit||this._groups.map(y),this._parents)}join(f,w,E){let q=this.enter(),T=this,N=this.exit();if(typeof f==="function"){if(q=f(q),q)q=q.selection?q.selection():q}else q=q.append(`${f}`);if(w!=null){if(T=w(T),T)T=T.selection?T.selection():T}if(E==null)N.remove();else E(N);return q&&T?q.merge(T).order():T}merge(f){let w="selection"in f&&typeof f.selection==="function"?f.selection():f,E=this._groups,q=w._groups,T=E.length,N=q.length,A=Math.min(T,N),W=Array(T),H=0;for(;H<A;++H){let I=E[H],M=q[H],Q=I.length,O=W[H]=Array(Q);for(let X=0;X<Q;++X){let $;if($=I[X]||M[X])O[X]=$}}for(;H<T;++H)W[H]=E[H];return new Y(W,this._parents)}selection(){return this}order(){let f=this._groups;for(let w=-1,E=f.length;++w<E;){let q=f[w];for(let T=q.length-1,N=q[T],A;--T>=0;)if(A=q[T]){if(N&&A.compareDocumentPosition(N)^4){let W=N.parentNode;if(W)W.insertBefore(A,N)}N=A}}return this}sort(f){if(!f)f=Yw;function w(N,A){return N&&A?f(N.__data__,A.__data__):Number(!N)-Number(!A)}let E=this._groups,q=E.length,T=Array(q);for(let N=0;N<q;++N){let A=E[N],W=A.length,H=T[N]=Array(W);for(let I=0;I<W;++I){let M=A[I];if(M)H[I]=M}H.sort(w)}return new Y(T,this._parents).order()}call(f,...w){return f.call(null,this,...w),this}nodes(){return Array.from(this)}node(){let f=this._groups;for(let w=0,E=f.length;w<E;++w){let q=f[w];for(let T=0,N=q.length;T<N;++T){let A=q[T];if(A)return A}}return null}size(){let f=0;for(let w of this)++f;return f}empty(){return!this.node()}each(f){let w=this._groups;for(let E=0,q=w.length;E<q;++E){let T=w[E];for(let N=0,A=T.length;N<A;++N){let W=T[N];if(W)f.call(W,W.__data__,N,T)}}return this}attr(f,w){let E=V(f);if(arguments.length<2){let q=this.node();return typeof E==="object"?q.getAttributeNS(E.space,E.local):q.getAttribute(E)}return this.each((w==null?typeof E==="object"?Cf:Lf:typeof w==="function"?typeof E==="object"?jf:kf:typeof E==="object"?Sf:Vf)(E,w))}style(f,w,E){if(arguments.length>1)return this.each((w==null?Ff:typeof w==="function"?bf:hf)(f,w,E==null?"":E));return Mf(this.node(),f)}property(f,w){if(arguments.length>1)return this.each((w==null?gf:typeof w==="function"?rf:yf)(f,w));return this.node()[f]}classed(f,w){let E=zf(`${f}`);if(arguments.length<2){let q=qf(this.node()),T=-1,N=E.length;while(++T<N)if(!q.contains(E[T]))return!1;return!0}return this.each((typeof w==="function"?df:w?cf:mf)(E,w))}text(f){if(arguments.length)return this.each(f==null?lf:(typeof f==="function"?vf:uf)(f));return this.node().textContent}html(f){if(arguments.length)return this.each(f==null?sf:(typeof f==="function"?of:pf)(f));return this.node().innerHTML}raise(){return this.each(tf)}lower(){return this.each(nf)}append(f){let w=typeof f==="function"?f:S(f);return this.select(function(){return this.appendChild(w.apply(this,arguments))})}insert(f,w){let E=typeof f==="function"?f:S(f),q=w==null?Zw:typeof w==="function"?w:b(w);return this.select(function(){return this.insertBefore(E.apply(this,arguments),q.apply(this,arguments)||null)})}remove(){return this.each(af)}clone(f){return this.select(f?fw:ef)}datum(f){if(arguments.length)return this.property("__data__",f);return this.node().__data__}on(f,w,E){let q=Ew(`${f}`),T=q.length;if(arguments.length<2){let A=this.node().__on;if(A)for(let W=0,H=A.length,I;W<H;++W)for(let M=0;M<T;++M){let Q=q[M];if(I=A[W],Q.type===I.type&&Q.name===I.name)return I.value}return}let N=w?qw:Tw;for(let A=0;A<T;++A)this.each(N(q[A],w,E));return this}dispatch(f,w){return this.each((typeof w==="function"?Aw:Nw)(f,w))}*[Symbol.iterator](){let f=this._groups;for(let w=0,E=f.length;w<E;++w){let q=f[w];for(let T=0,N=q.length;T<N;++T){let A=q[T];if(A)yield A}}}}function D(f){return typeof f==="string"?new Y([[document.querySelector(f)]],[document.documentElement]):new Y([[f]],Tf)}function p(f){let w;while(w=f.sourceEvent)f=w;return f}function _(f,w){let E=p(f);if(w===void 0)w=E.currentTarget;if(w){let q=w.ownerSVGElement||w;if("createSVGPoint"in q){let T=q.createSVGPoint();return T.x=E.clientX,T.y=E.clientY,T=T.matrixTransform(w.getScreenCTM().inverse()),[T.x,T.y]}if(w.getBoundingClientRect){let T=w.getBoundingClientRect();return[E.clientX-T.left-w.clientLeft,E.clientY-T.top-w.clientTop]}}return[E.pageX,E.pageY]}var Qf={passive:!1},L={capture:!0,passive:!1};function o(f){f.stopImmediatePropagation()}function K(f){f.preventDefault(),f.stopImmediatePropagation()}function t(f){let w=f.document.documentElement,E=D(f).on("dragstart.drag",K,L);if("onselectstart"in w)E.on("selectstart.drag",K,L);else w.__noselect=w.style.MozUserSelect,w.style.MozUserSelect="none"}function Nf(f,w){let E=f.document.documentElement,q=D(f).on("dragstart.drag",null);if(w)q.on("click.drag",K,L),setTimeout(function(){q.on("click.drag",null)},0);if("onselectstart"in E)q.on("selectstart.drag",null);else E.style.MozUserSelect=E.__noselect,delete E.__noselect}function k(f){return()=>f}class c{type;active;x;y;dx;dy;constructor(f,{sourceEvent:w,subject:E,target:q,identifier:T,active:N,x:A,y:W,dx:H,dy:I,dispatch:M}){Object.defineProperties(this,{type:{value:f,enumerable:!0,configurable:!0},sourceEvent:{value:w,enumerable:!0,configurable:!0},subject:{value:E,enumerable:!0,configurable:!0},target:{value:q,enumerable:!0,configurable:!0},identifier:{value:T,enumerable:!0,configurable:!0},active:{value:N,enumerable:!0,configurable:!0},x:{value:A,enumerable:!0,configurable:!0},y:{value:W,enumerable:!0,configurable:!0},dx:{value:H,enumerable:!0,configurable:!0},dy:{value:I,enumerable:!0,configurable:!0},_:{value:M}})}on(...f){let w=this._.on.apply(this._,f);return w===this._?this:w}}function $w(f){return!f.ctrlKey&&!f.button}function Bw(){return this.parentNode}function Dw(f,w){return w==null?{x:f.x,y:f.y}:w}function Kw(){return!!(navigator.maxTouchPoints||("ontouchstart"in this))}function Yf(){let f=$w,w=Bw,E=Dw,q=Kw,T={},N=e("start","drag","end"),A=0,W,H,I,M,Q=0;function O(U){U.on("mousedown.drag",X).filter(q).on("touchstart.drag",F).on("touchmove.drag",m,Qf).on("touchend.drag touchcancel.drag",G).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function X(U,z){if(M||!f.call(this,U,z))return;let J=R(this,w.call(this,U,z),U,z,"mouse");if(!J)return;D(U.view).on("mousemove.drag",$,L).on("mouseup.drag",j,L),t(U.view),o(U),I=!1,W=U.clientX,H=U.clientY,J("start",U)}function $(U){if(K(U),!I){let z=U.clientX-W,J=U.clientY-H;I=z*z+J*J>Q}T.mouse("drag",U)}function j(U){D(U.view).on("mousemove.drag mouseup.drag",null),Nf(U.view,I),K(U),T.mouse("end",U)}function F(U,z){if(!f.call(this,U,z))return;let J=U.changedTouches,P=w.call(this,U,z),Z=J.length,x,C;for(x=0;x<Z;++x)if(C=R(this,P,U,z,J[x].identifier,J[x]))o(U),C("start",U,J[x])}function m(U){let z=U.changedTouches,J=z.length,P,Z;for(P=0;P<J;++P)if(Z=T[z[P].identifier])K(U),Z("drag",U,z[P])}function G(U){let z=U.changedTouches,J=z.length,P,Z;if(M)clearTimeout(M);M=setTimeout(function(){M=null},500);for(P=0;P<J;++P)if(Z=T[z[P].identifier])o(U),Z("end",U,z[P])}function R(U,z,J,P,Z,x){let C=N.copy(),B=_(x||J,z),Af,Uf,d;if((d=E.call(U,new c("beforestart",{sourceEvent:J,target:O,identifier:Z,active:A,x:B[0],y:B[1],dx:0,dy:0,dispatch:C}),P))==null)return;return Af=d.x-B[0]||0,Uf=d.y-B[1]||0,function Zf(n,a,Wf){let Hf=B,l;switch(n){case"start":T[Z]=Zf,l=A++;break;case"end":delete T[Z],--A,B=_(Wf||a,z),l=A;break;case"drag":B=_(Wf||a,z),l=A;break}C.call(n,U,new c(n,{sourceEvent:a,subject:d,target:O,identifier:Z,active:l,x:B[0]+Af,y:B[1]+Uf,dx:B[0]-Hf[0],dy:B[1]-Hf[1],dispatch:C}),P)}}return O.filter=function(U){return arguments.length?(f=typeof U==="function"?U:k(!!U),O):f},O.container=function(U){return arguments.length?(w=typeof U==="function"?U:k(U),O):w},O.subject=function(U){return arguments.length?(E=typeof U==="function"?U:k(U),O):E},O.touchable=function(U){return arguments.length?(q=typeof U==="function"?U:k(!!U),O):q},O.on=function(...U){let z=N.on.apply(N,U);return z===N?O:z},O.clickDistance=function(U){return arguments.length?(Q=(U=+U)*U,O):Math.sqrt(Q)},O}export{Nf as dragEnable,t as dragDisable,Yf as drag};
|
package/dist/nodrag.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function nopropagation(event: Event): void;
|
|
2
|
+
export declare function noevent(event: Event): void;
|
|
3
|
+
// These are typically used in conjunction with noevent to ensure that we can
|
|
4
|
+
// preventDefault on the event.
|
|
5
|
+
export declare const nonpassive: {
|
|
6
|
+
passive: false
|
|
7
|
+
};
|
|
8
|
+
export declare const nonpassivecapture: {
|
|
9
|
+
capture: true;
|
|
10
|
+
passive: false
|
|
11
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ts-charts/drag",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"import": "./src/index.ts"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"module": "./src/index.ts",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "bun --bun build.ts",
|
|
18
|
+
"prepublishOnly": "bun --bun run build",
|
|
19
|
+
"test": "bun test"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@ts-charts/dispatch": "0.1.0",
|
|
23
|
+
"@ts-charts/selection": "0.1.0"
|
|
24
|
+
}
|
|
25
|
+
}
|