@neuroplastio/xterm-addon-hotty 0.1.0-next.2 → 0.1.0-next.3
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/README.md +10 -0
- package/dist/hotty-xterm.js +64 -25
- package/dist/hotty-xterm.js.map +3 -3
- package/dist/types/steps.d.ts +9 -0
- package/dist/types/surface.d.ts +15 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -183,6 +183,16 @@ runs programs for whoever connects.
|
|
|
183
183
|
click where it began. A second finger ends it with `dragend` and no
|
|
184
184
|
target, and nothing more is heard until every finger lifts. A long press,
|
|
185
185
|
or Alt held at the touch, never drags. Any other touch pans as below.
|
|
186
|
+
|
|
187
|
+
An element that also has `data-steps="<x> [<y>]"` (whole numbers, 0 for
|
|
188
|
+
none along that axis) says where in it the pointer is: every event of a
|
|
189
|
+
drag of it carries `x` and `y`, the pointer's step along its border box
|
|
190
|
+
(`getBoundingClientRect`, as it is at each move), rounded to the nearest
|
|
191
|
+
and clamped to 0 and the count, wherever the pointer or the finger is.
|
|
192
|
+
A `drag` also goes out each time the step changes. The counts are read
|
|
193
|
+
when the drag starts; once the element has left the document, the step
|
|
194
|
+
stays as it last was, as it does in a `dragend` that ends a drag early.
|
|
195
|
+
The capabilities report `steps: true`.
|
|
186
196
|
- **Presses** (SPEC §5.2, §9: `p=1` on `a=place`). Every primary press of a
|
|
187
197
|
mouse or a pen in the window reports `press` on its pointerdown, before
|
|
188
198
|
the drag and the focus it causes; a tap reports it on the mousedown the
|
package/dist/hotty-xterm.js
CHANGED
|
@@ -683,6 +683,21 @@ var Touch = class {
|
|
|
683
683
|
}
|
|
684
684
|
};
|
|
685
685
|
|
|
686
|
+
// src/steps.ts
|
|
687
|
+
function parseSteps(value) {
|
|
688
|
+
if (value === null) return null;
|
|
689
|
+
const words = value.trim().split(/\s+/);
|
|
690
|
+
if (words.length > 2 || !words.every((w) => /^[0-9]+$/.test(w))) return null;
|
|
691
|
+
const [x, y = 0] = words.map(Number);
|
|
692
|
+
if (!Number.isSafeInteger(x) || !Number.isSafeInteger(y) || x === 0 && y === 0) return null;
|
|
693
|
+
return [x, y];
|
|
694
|
+
}
|
|
695
|
+
function stepAt(offset, size, count) {
|
|
696
|
+
if (!(size > 0)) return 0;
|
|
697
|
+
const at = Math.min(Math.max(offset / size, 0), 1) * count;
|
|
698
|
+
return Math.min(Math.floor(at + 0.5), count);
|
|
699
|
+
}
|
|
700
|
+
|
|
686
701
|
// src/resolver.ts
|
|
687
702
|
var DROP = /* @__PURE__ */ new Set(["script", "iframe", "frame", "frameset", "object", "embed", "applet", "base", "meta", "portal", "fencedframe"]);
|
|
688
703
|
var DROP_ATTRS = /* @__PURE__ */ new Set(["srcdoc", "autofocus", "http-equiv", "ping", "nonce", "integrity"]);
|
|
@@ -2289,25 +2304,49 @@ var Surface = class {
|
|
|
2289
2304
|
if (!id) return;
|
|
2290
2305
|
const [c, r] = this.cellOf(e);
|
|
2291
2306
|
const keys = keysOf(e);
|
|
2292
|
-
|
|
2293
|
-
this.
|
|
2307
|
+
const d = { pointer: e.pointerId, start: id, steps: stepsOf(start), target: id, c, r, keys, step: {} };
|
|
2308
|
+
d.step = this.stepIn(d, e.clientX, e.clientY);
|
|
2309
|
+
this.drag = d;
|
|
2310
|
+
this.emit("dragstart", id, { c, r, keys, ...d.step });
|
|
2294
2311
|
try {
|
|
2295
2312
|
this.doc.documentElement.setPointerCapture(e.pointerId);
|
|
2296
2313
|
} catch {
|
|
2297
2314
|
}
|
|
2298
2315
|
}
|
|
2299
|
-
/** A move during a drag
|
|
2300
|
-
* while it has none, each time its cell does. */
|
|
2316
|
+
/** A move during a drag (`moveDrag`). */
|
|
2301
2317
|
onDragMove(e) {
|
|
2302
2318
|
const d = this.drag;
|
|
2303
2319
|
if (!d || e.pointerId !== d.pointer) return;
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2320
|
+
this.moveDrag(d, e.clientX, e.clientY, keysOf(e));
|
|
2321
|
+
}
|
|
2322
|
+
/** The pointer or the finger of a drag moved to (x, y) of the document:
|
|
2323
|
+
* an event each time its target changes, while it has none each time its
|
|
2324
|
+
* cell does, and each time its step does (SPEC §9.1); one for a move that
|
|
2325
|
+
* changes more than one. */
|
|
2326
|
+
moveDrag(d, x, y, keys) {
|
|
2327
|
+
const [c, r] = this.cellAt(x, y);
|
|
2328
|
+
const target = this.dragTarget(this.elementAtPoint(x, y, c, r));
|
|
2329
|
+
const step = this.stepIn(d, x, y);
|
|
2330
|
+
if (target !== d.target || target === "" && (c !== d.c || r !== d.r) || step.x !== d.step.x || step.y !== d.step.y) {
|
|
2331
|
+
this.emit("drag", target, { c, r, keys, ...step });
|
|
2309
2332
|
}
|
|
2310
|
-
Object.assign(d, { target, c, r, keys });
|
|
2333
|
+
Object.assign(d, { target, c, r, keys, step });
|
|
2334
|
+
}
|
|
2335
|
+
/**
|
|
2336
|
+
* Where (x, y) of the document is in the element a drag started on, in
|
|
2337
|
+
* its steps (SPEC §9.1): measured against its border box where the user
|
|
2338
|
+
* sees it now, wherever the point is, and as they last were once the
|
|
2339
|
+
* element has left the document. None when it has no steps.
|
|
2340
|
+
*/
|
|
2341
|
+
stepIn(d, x, y) {
|
|
2342
|
+
const s = d.steps;
|
|
2343
|
+
if (!s) return {};
|
|
2344
|
+
if (!s.el.isConnected) return d.step;
|
|
2345
|
+
const box = s.el.getBoundingClientRect();
|
|
2346
|
+
const step = {};
|
|
2347
|
+
if (s.x) step.x = stepAt(x - box.left, box.width, s.x);
|
|
2348
|
+
if (s.y) step.y = stepAt(y - box.top, box.height, s.y);
|
|
2349
|
+
return step;
|
|
2311
2350
|
}
|
|
2312
2351
|
/** The release ends the drag, wherever it is. Where it began, it is the
|
|
2313
2352
|
* click it would have been without the drag; anywhere else, no click. */
|
|
@@ -2318,7 +2357,7 @@ var Surface = class {
|
|
|
2318
2357
|
const [c, r] = this.cellOf(e);
|
|
2319
2358
|
const at = this.elementAt(e, c, r);
|
|
2320
2359
|
const target = this.dragTarget(at);
|
|
2321
|
-
this.emit("dragend", target, { c, r, keys: keysOf(e) });
|
|
2360
|
+
this.emit("dragend", target, { c, r, keys: keysOf(e), ...this.stepIn(d, e.clientX, e.clientY) });
|
|
2322
2361
|
this.dragReleased = true;
|
|
2323
2362
|
setTimeout(() => this.dragReleased = false, 0);
|
|
2324
2363
|
if (target === d.start && at) this.reportClick(ancestry(at));
|
|
@@ -2331,13 +2370,13 @@ var Surface = class {
|
|
|
2331
2370
|
/**
|
|
2332
2371
|
* Ends a drag under way without a release (SPEC §9.1: its placement went
|
|
2333
2372
|
* away, a new document came, or the pointer was lost): `dragend` with no
|
|
2334
|
-
* target, at the last cell the program heard of.
|
|
2373
|
+
* target, at the last cell and step the program heard of.
|
|
2335
2374
|
*/
|
|
2336
2375
|
cancelDrag() {
|
|
2337
2376
|
const d = this.drag;
|
|
2338
2377
|
if (!d) return;
|
|
2339
2378
|
this.dropDrag();
|
|
2340
|
-
this.emit("dragend", "", { c: d.c, r: d.r, keys: d.keys });
|
|
2379
|
+
this.emit("dragend", "", { c: d.c, r: d.r, keys: d.keys, ...d.step });
|
|
2341
2380
|
}
|
|
2342
2381
|
/** Ends a drag under way, silently (a detached or deleted surface). */
|
|
2343
2382
|
dropDrag() {
|
|
@@ -2454,25 +2493,20 @@ var Surface = class {
|
|
|
2454
2493
|
const [c, r] = this.cellAt(begin.x, begin.y);
|
|
2455
2494
|
const keys = keysOf(begin);
|
|
2456
2495
|
this.reportPress(e);
|
|
2457
|
-
|
|
2458
|
-
this.
|
|
2496
|
+
const d = { pointer: NaN, start: id, steps: stepsOf(start), target: id, c, r, keys, step: {} };
|
|
2497
|
+
d.step = this.stepIn(d, begin.x, begin.y);
|
|
2498
|
+
this.drag = d;
|
|
2499
|
+
this.emit("dragstart", id, { c, r, keys, ...d.step });
|
|
2459
2500
|
this.pressAt(e);
|
|
2460
2501
|
const t = [...e.changedTouches][0];
|
|
2461
2502
|
if (t) this.touchDragMove(t.clientX, t.clientY, e);
|
|
2462
2503
|
return true;
|
|
2463
2504
|
}
|
|
2464
2505
|
/** A touch drag's finger moved to (x, y) of the document: as a pointer's
|
|
2465
|
-
* move (`
|
|
2506
|
+
* move (`moveDrag`). */
|
|
2466
2507
|
touchDragMove(x, y, e) {
|
|
2467
2508
|
const d = this.drag;
|
|
2468
|
-
if (
|
|
2469
|
-
const [c, r] = this.cellAt(x, y);
|
|
2470
|
-
const target = this.dragTarget(this.elementAtPoint(x, y, c, r));
|
|
2471
|
-
const keys = keysOf(e);
|
|
2472
|
-
if (target !== d.target || target === "" && (c !== d.c || r !== d.r)) {
|
|
2473
|
-
this.emit("drag", target, { c, r, keys });
|
|
2474
|
-
}
|
|
2475
|
-
Object.assign(d, { target, c, r, keys });
|
|
2509
|
+
if (d) this.moveDrag(d, x, y, keysOf(e));
|
|
2476
2510
|
}
|
|
2477
2511
|
/** A touch drag's finger lifted at (x, y): as a pointer's release
|
|
2478
2512
|
* (`onDragUp`), a click where it began. */
|
|
@@ -2483,7 +2517,7 @@ var Surface = class {
|
|
|
2483
2517
|
const [c, r] = this.cellAt(x, y);
|
|
2484
2518
|
const at = this.elementAtPoint(x, y, c, r);
|
|
2485
2519
|
const target = this.dragTarget(at);
|
|
2486
|
-
this.emit("dragend", target, { c, r, keys: keysOf(e) });
|
|
2520
|
+
this.emit("dragend", target, { c, r, keys: keysOf(e), ...this.stepIn(d, x, y) });
|
|
2487
2521
|
this.dragReleased = true;
|
|
2488
2522
|
setTimeout(() => this.dragReleased = false, 0);
|
|
2489
2523
|
if (target === d.start && at) this.reportClick(ancestry(at));
|
|
@@ -2973,6 +3007,10 @@ function isElement(n) {
|
|
|
2973
3007
|
function listens(el, what) {
|
|
2974
3008
|
return (el.getAttribute("data-on") ?? "").split(/\s+/).includes(what);
|
|
2975
3009
|
}
|
|
3010
|
+
function stepsOf(el) {
|
|
3011
|
+
const n = parseSteps(el.getAttribute("data-steps"));
|
|
3012
|
+
return n && { el, x: n[0], y: n[1] };
|
|
3013
|
+
}
|
|
2976
3014
|
function ancestry(el) {
|
|
2977
3015
|
const out = [];
|
|
2978
3016
|
for (let n = el; n; n = n.parentElement) out.push(n);
|
|
@@ -3516,6 +3554,7 @@ var HottyAddon = class {
|
|
|
3516
3554
|
limits: { resources: this.store.quota, surfaces: this.opts.maxSurfaces },
|
|
3517
3555
|
net: this.policy,
|
|
3518
3556
|
scroll: true,
|
|
3557
|
+
steps: true,
|
|
3519
3558
|
host: HOST,
|
|
3520
3559
|
version: VERSION
|
|
3521
3560
|
};
|