@fluixi/devtools 1.0.0-alpha.108 → 1.0.0-alpha.110
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/dist/callsite.mjs +4 -63
- package/dist/change-view.mjs +6 -106
- package/dist/chunk-235BSS43.mjs +185 -0
- package/dist/chunk-2ACSNLS6.mjs +87 -0
- package/dist/chunk-2VDMQ3VF.mjs +520 -0
- package/dist/chunk-33U2S43X.mjs +121 -0
- package/dist/chunk-B3SAJ7QG.mjs +72 -0
- package/dist/chunk-BTCWJTXR.mjs +216 -0
- package/dist/chunk-CPZWLBCQ.mjs +35 -0
- package/dist/chunk-D25KZZBZ.mjs +212 -0
- package/dist/chunk-EBSROPWJ.mjs +314 -0
- package/dist/chunk-F664XLZL.mjs +743 -0
- package/dist/chunk-FY5K3QVT.mjs +35 -0
- package/dist/chunk-GDQXCOQB.mjs +43 -0
- package/dist/chunk-JLNWT36I.mjs +118 -0
- package/dist/chunk-JTHAZJJZ.mjs +780 -0
- package/dist/chunk-L6XQGNMW.mjs +106 -0
- package/dist/chunk-MN6O673L.mjs +90 -0
- package/dist/chunk-NDUBBBNL.mjs +70 -0
- package/dist/chunk-NT7YMK77.mjs +157 -0
- package/dist/chunk-NVULLJDH.mjs +120 -0
- package/dist/chunk-NWLSDERQ.mjs +68 -0
- package/dist/chunk-OPIGF5XB.mjs +184 -0
- package/dist/chunk-P5I7DWFX.mjs +292 -0
- package/dist/chunk-PSSBFXBD.mjs +155 -0
- package/dist/chunk-PTQ5VCYE.mjs +103 -0
- package/dist/chunk-UAEJ3N7F.mjs +76 -0
- package/dist/chunk-V6DKWEYD.mjs +67 -0
- package/dist/chunk-VO2V7AC5.mjs +80 -0
- package/dist/chunk-WGQH7RUW.mjs +25 -0
- package/dist/chunk-Z6KYHEKY.mjs +64 -0
- package/dist/copy.mjs +3 -39
- package/dist/describe.mjs +3 -31
- package/dist/detail-panel.cjs +2 -1
- package/dist/detail-panel.d.ts.map +1 -1
- package/dist/detail-panel.js +1 -0
- package/dist/detail-panel.mjs +6 -280
- package/dist/diff.mjs +4 -201
- package/dist/dom.mjs +7 -176
- package/dist/export.mjs +6 -207
- package/dist/float.mjs +5 -206
- package/dist/format.mjs +5 -151
- package/dist/graph-view.mjs +9 -875
- package/dist/highlight.mjs +6 -113
- package/dist/history.cjs +14 -2
- package/dist/history.d.ts +8 -1
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +15 -2
- package/dist/history.mjs +4 -70
- package/dist/hook.cjs +26 -1
- package/dist/hook.d.ts +4 -0
- package/dist/hook.d.ts.map +1 -1
- package/dist/hook.js +13 -0
- package/dist/hook.mjs +16 -1719
- package/dist/index.cjs +34 -5
- package/dist/index.mjs +106 -4673
- package/dist/inspector.mjs +11 -677
- package/dist/instrument.mjs +9 -486
- package/dist/kind-filter.mjs +6 -148
- package/dist/menu.mjs +4 -116
- package/dist/observe.cjs +15 -1
- package/dist/observe.d.ts +2 -0
- package/dist/observe.d.ts.map +1 -1
- package/dist/observe.js +3 -0
- package/dist/observe.mjs +14 -1510
- package/dist/palette.mjs +6 -28
- package/dist/path.mjs +3 -21
- package/dist/plugin.mjs +9 -57
- package/dist/plugins/context.mjs +6 -71
- package/dist/plugins/directives.mjs +8 -68
- package/dist/plugins/index.cjs +1 -1
- package/dist/plugins/index.mjs +13 -136
- package/dist/source.mjs +12 -93
- package/dist/timeline.cjs +5 -2
- package/dist/timeline.d.ts.map +1 -1
- package/dist/timeline.js +5 -1
- package/dist/timeline.mjs +7 -323
- package/dist/tree.mjs +11 -558
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/value-pane.mjs +6 -196
- package/dist/wire.cjs +1 -1
- package/dist/wire.mjs +6 -86
- package/package.json +3 -3
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {
|
|
2
|
+
registerDevtoolsPlugin
|
|
3
|
+
} from "./chunk-V6DKWEYD.mjs";
|
|
4
|
+
|
|
5
|
+
// src/plugins/directives.ts
|
|
6
|
+
var NAME = "directives";
|
|
7
|
+
function directivesOn(extra) {
|
|
8
|
+
return extra?.[NAME] ?? [];
|
|
9
|
+
}
|
|
10
|
+
function directiveBadge(notes) {
|
|
11
|
+
if (!notes.length) return void 0;
|
|
12
|
+
const first = notes[0];
|
|
13
|
+
const short = first.kind === "ref" ? "ref" : label(first);
|
|
14
|
+
return notes.length > 1 ? `${short} +${notes.length - 1}` : short;
|
|
15
|
+
}
|
|
16
|
+
function directiveRows(notes) {
|
|
17
|
+
return notes.map((note) => ({
|
|
18
|
+
label: label(note),
|
|
19
|
+
value: note.element,
|
|
20
|
+
...note.at ? { at: note.at } : {}
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
var label = (note) => note.kind === "ref" ? `ref ${note.name}` : `${note.kind}:${note.name}`;
|
|
24
|
+
var directivesPlugin = {
|
|
25
|
+
name: NAME,
|
|
26
|
+
collect(ctx) {
|
|
27
|
+
ctx.onDirective((report) => {
|
|
28
|
+
if (!report.target) return;
|
|
29
|
+
const held = ctx.elementAnnotation(report.target) ?? [];
|
|
30
|
+
const already = held.some((n) => n.kind === report.kind && n.name === report.name);
|
|
31
|
+
if (already) return;
|
|
32
|
+
held.push({
|
|
33
|
+
kind: report.kind,
|
|
34
|
+
name: report.name,
|
|
35
|
+
element: report.element,
|
|
36
|
+
...report.at ? { at: report.at } : {}
|
|
37
|
+
});
|
|
38
|
+
ctx.annotateElement(report.target, held);
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
rows(node) {
|
|
42
|
+
const notes = node.extra?.[NAME];
|
|
43
|
+
if (!notes?.length) return [];
|
|
44
|
+
return notes.map((note) => ({
|
|
45
|
+
label: label(note),
|
|
46
|
+
value: note.element,
|
|
47
|
+
...note.at ? { at: note.at } : {}
|
|
48
|
+
}));
|
|
49
|
+
},
|
|
50
|
+
elementRows(extra) {
|
|
51
|
+
return directiveRows(directivesOn(extra));
|
|
52
|
+
},
|
|
53
|
+
elementBadge(extra) {
|
|
54
|
+
return directiveBadge(directivesOn(extra));
|
|
55
|
+
},
|
|
56
|
+
badge(node) {
|
|
57
|
+
const notes = node.extra?.[NAME];
|
|
58
|
+
if (!notes?.length) return void 0;
|
|
59
|
+
const first = notes[0];
|
|
60
|
+
const short = first.kind === "ref" ? "ref" : label(first);
|
|
61
|
+
return notes.length > 1 ? `${short} +${notes.length - 1}` : short;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
registerDevtoolsPlugin(directivesPlugin);
|
|
65
|
+
|
|
66
|
+
export {
|
|
67
|
+
NAME,
|
|
68
|
+
directivesOn,
|
|
69
|
+
directiveBadge,
|
|
70
|
+
directiveRows,
|
|
71
|
+
directivesPlugin
|
|
72
|
+
};
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import {
|
|
2
|
+
toCommits
|
|
3
|
+
} from "./chunk-2ACSNLS6.mjs";
|
|
4
|
+
import {
|
|
5
|
+
CHANGE_CSS,
|
|
6
|
+
changeRows,
|
|
7
|
+
handleCopyClick
|
|
8
|
+
} from "./chunk-UAEJ3N7F.mjs";
|
|
9
|
+
|
|
10
|
+
// src/timeline.ts
|
|
11
|
+
var escape = (text) => text.replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]);
|
|
12
|
+
var clock = (t) => {
|
|
13
|
+
const d = new Date(t);
|
|
14
|
+
const pad = (n, width = 2) => String(n).padStart(width, "0");
|
|
15
|
+
return `${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}.${pad(d.getMilliseconds(), 3)}`;
|
|
16
|
+
};
|
|
17
|
+
function subject(commit, nameOf) {
|
|
18
|
+
if (commit.mark) return commit.mark.label ?? "marked";
|
|
19
|
+
if (!commit.cause) return commit.commit === 0 ? "first render" : "continued";
|
|
20
|
+
return nameOf(commit.cause);
|
|
21
|
+
}
|
|
22
|
+
function change(commit) {
|
|
23
|
+
if (commit.mark) return "";
|
|
24
|
+
const cause = commit.cause;
|
|
25
|
+
if (!cause || cause.from === void 0 || cause.to === void 0) return "";
|
|
26
|
+
return `${cause.from} → ${cause.to}`;
|
|
27
|
+
}
|
|
28
|
+
function detail(commit, nameOf) {
|
|
29
|
+
const lines = [`${subject(commit, nameOf)} ${change(commit)}`.trim()];
|
|
30
|
+
const named = (kind, verb) => {
|
|
31
|
+
const ids = commit.events.filter((e) => e.kind === kind && e !== commit.cause).map(nameOf);
|
|
32
|
+
if (ids.length) lines.push(`${verb}: ${[...new Set(ids)].join(", ")}`);
|
|
33
|
+
};
|
|
34
|
+
named("ran", "ran");
|
|
35
|
+
named("write", "written");
|
|
36
|
+
named("created", "made");
|
|
37
|
+
named("disposed", "gone");
|
|
38
|
+
return lines.join("\n");
|
|
39
|
+
}
|
|
40
|
+
function summary(commit) {
|
|
41
|
+
const counts = { ran: 0, created: 0, disposed: 0, write: 0, mark: 0 };
|
|
42
|
+
for (const event of commit.events) counts[event.kind]++;
|
|
43
|
+
const writes = counts.write - (commit.cause ? 1 : 0);
|
|
44
|
+
return [
|
|
45
|
+
counts.ran && `${counts.ran} ran`,
|
|
46
|
+
writes > 0 && `${writes} written`,
|
|
47
|
+
counts.created && `${counts.created} made`,
|
|
48
|
+
counts.disposed && `${counts.disposed} gone`
|
|
49
|
+
].filter(Boolean).join(" · ");
|
|
50
|
+
}
|
|
51
|
+
function createTimeline(host, options = {}) {
|
|
52
|
+
const empty = options.empty ?? "nothing has happened yet";
|
|
53
|
+
const limit = options.limit ?? 100;
|
|
54
|
+
let events = [];
|
|
55
|
+
let seen = -1;
|
|
56
|
+
let selected = null;
|
|
57
|
+
let filter = "";
|
|
58
|
+
let signature = "";
|
|
59
|
+
let paused = false;
|
|
60
|
+
host.innerHTML = '<div class="tl-head"><input class="tl-filter" type="search" placeholder="filter by name or value" aria-label="Filter the timeline" /><button type="button" class="tl-pause" title="Stop taking new updates, so the list holds still while you read it">❚❚</button></div><div class="tl-list"></div>';
|
|
61
|
+
const input = host.querySelector(".tl-filter");
|
|
62
|
+
const list = host.querySelector(".tl-list");
|
|
63
|
+
const pause = host.querySelector(".tl-pause");
|
|
64
|
+
const all = () => toCommits(events).slice(-limit).reverse();
|
|
65
|
+
const idsOf = (commit) => {
|
|
66
|
+
const ids = /* @__PURE__ */ new Set();
|
|
67
|
+
for (const event of commit.events) {
|
|
68
|
+
ids.add(event.id);
|
|
69
|
+
if (event.by !== void 0) ids.add(event.by);
|
|
70
|
+
}
|
|
71
|
+
return [...ids];
|
|
72
|
+
};
|
|
73
|
+
const haystack = (commit, nameOf) => `${detail(commit, nameOf)} ${summary(commit)}`.toLowerCase();
|
|
74
|
+
const shown = (nameOf) => filter ? all().filter((c) => haystack(c, nameOf).includes(filter)) : all();
|
|
75
|
+
input.addEventListener("input", () => {
|
|
76
|
+
filter = input.value.trim().toLowerCase();
|
|
77
|
+
signature = "";
|
|
78
|
+
});
|
|
79
|
+
const showPaused = () => {
|
|
80
|
+
pause.textContent = paused ? "▶" : "❚❚";
|
|
81
|
+
pause.classList.toggle("on", paused);
|
|
82
|
+
pause.title = paused ? "Taking updates again" : "Stop taking new updates, so the list holds still while you read it";
|
|
83
|
+
};
|
|
84
|
+
pause.addEventListener("click", () => {
|
|
85
|
+
paused = !paused;
|
|
86
|
+
showPaused();
|
|
87
|
+
signature = "";
|
|
88
|
+
});
|
|
89
|
+
list.addEventListener("click", (e) => {
|
|
90
|
+
if (handleCopyClick(e)) return;
|
|
91
|
+
const row = e.target?.closest?.(".tl-commit");
|
|
92
|
+
if (!row) return;
|
|
93
|
+
const number = Number(row.dataset.commit);
|
|
94
|
+
if (e.target.classList.contains("tl-more")) {
|
|
95
|
+
const full = all().find((c) => c.commit === number);
|
|
96
|
+
if (full) options.onExpand?.(full);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
selected = selected === number ? null : number;
|
|
100
|
+
const commit = all().find((c) => c.commit === selected) ?? null;
|
|
101
|
+
options.onSelect?.(commit ? idsOf(commit) : [], commit);
|
|
102
|
+
signature = "";
|
|
103
|
+
});
|
|
104
|
+
return {
|
|
105
|
+
setPaused(next) {
|
|
106
|
+
paused = next;
|
|
107
|
+
showPaused();
|
|
108
|
+
signature = "";
|
|
109
|
+
},
|
|
110
|
+
get paused() {
|
|
111
|
+
return paused;
|
|
112
|
+
},
|
|
113
|
+
push(incoming) {
|
|
114
|
+
if (paused) return;
|
|
115
|
+
let added = false;
|
|
116
|
+
for (const event of incoming) {
|
|
117
|
+
if (event.seq <= seen) continue;
|
|
118
|
+
events.push(event);
|
|
119
|
+
seen = event.seq;
|
|
120
|
+
added = true;
|
|
121
|
+
}
|
|
122
|
+
if (!added) return;
|
|
123
|
+
if (events.length > limit * 40) events = events.slice(-limit * 40);
|
|
124
|
+
},
|
|
125
|
+
render(graph) {
|
|
126
|
+
const nameOf = (e) => graph.get(e.id)?.label ?? e.label ?? `#${e.id}`;
|
|
127
|
+
const rows = shown(nameOf);
|
|
128
|
+
const next = `${seen}|${selected ?? ""}|${filter}|${rows.length}|${graph.size}`;
|
|
129
|
+
if (next === signature) return;
|
|
130
|
+
signature = next;
|
|
131
|
+
if (!rows.length) {
|
|
132
|
+
list.innerHTML = `<span class="tl-empty">${escape(filter ? "nothing matches" : empty)}</span>`;
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
list.innerHTML = rows.map((commit) => {
|
|
136
|
+
const open = commit.commit === selected;
|
|
137
|
+
const did = summary(commit);
|
|
138
|
+
const moved = change(commit);
|
|
139
|
+
const parts = [
|
|
140
|
+
["ran", "ran"],
|
|
141
|
+
["write", "written"],
|
|
142
|
+
["created", "made"],
|
|
143
|
+
["disposed", "gone"]
|
|
144
|
+
];
|
|
145
|
+
const body = parts.map(([kind, verb]) => {
|
|
146
|
+
const names = [
|
|
147
|
+
...new Set(
|
|
148
|
+
commit.events.filter((e) => e.kind === kind && e !== commit.cause).map(nameOf)
|
|
149
|
+
)
|
|
150
|
+
];
|
|
151
|
+
return names.length ? `<div class="tl-part"><span class="tl-verb">${verb}</span> ${escape(names.join(", "))}</div>` : "";
|
|
152
|
+
}).join("");
|
|
153
|
+
return `<div class="tl-commit${open ? " selected" : ""}" data-commit="${commit.commit}" title="${escape(detail(commit, nameOf))}"><div class="tl-line"><span class="tl-caret">${open ? "▾" : "▸"}</span><span class="tl-time">${clock(commit.t)}</span><span class="tl-name">${escape(subject(commit, nameOf))}</span>` + (did ? `<span class="tl-did">${escape(did)}</span>` : "") + "</div>" + // Open, the value gets the width and wraps.
|
|
154
|
+
(open ? `<div class="tl-body">${moved ? `<div class="tl-change">${escape(moved)}</div>` : ""}${changeRows(commit.cause?.change, 6)}${body}${// Only worth offering when there is more than the row can hold.
|
|
155
|
+
options.onExpand && (commit.cause?.change || commit.events.length > 6) ? '<button type="button" class="tl-more">open in full</button>' : ""}</div>` : "") + "</div>";
|
|
156
|
+
}).join("");
|
|
157
|
+
},
|
|
158
|
+
selected() {
|
|
159
|
+
const commit = all().find((c) => c.commit === selected);
|
|
160
|
+
return commit ? idsOf(commit) : [];
|
|
161
|
+
},
|
|
162
|
+
clear() {
|
|
163
|
+
events = [];
|
|
164
|
+
seen = -1;
|
|
165
|
+
selected = null;
|
|
166
|
+
signature = "";
|
|
167
|
+
list.innerHTML = `<span class="tl-empty">${escape(empty)}</span>`;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
var TIMELINE_CSS = `
|
|
172
|
+
.tl-head { position: relative; display: flex; gap: 4px; padding: 0 .25rem; }
|
|
173
|
+
.tl-pause {
|
|
174
|
+
position: absolute; right: .4rem; top: 40%; transform: translateY(-50%);
|
|
175
|
+
flex: none; width: 26px; cursor: pointer; font: inherit; font-size: 10px;
|
|
176
|
+
border: 1px solid var(--fx-line, #ffffff1f); border-radius: 4px;
|
|
177
|
+
background: transparent; color: var(--fx-muted, #8a90a2);
|
|
178
|
+
}
|
|
179
|
+
.tl-pause:hover { color: var(--fx-label, #e7e9ee); }
|
|
180
|
+
.tl-pause.on { color: var(--fx-accent, #5eead4); border-color: var(--fx-accent, #5eead4); }
|
|
181
|
+
.tl-filter {
|
|
182
|
+
flex: 1; min-width: 0; box-sizing: border-box; padding: 3px 6px;
|
|
183
|
+
font: inherit; font-size: 11.5px; border-radius: 4px;
|
|
184
|
+
border: 1px solid var(--fx-line, #ffffff1f);
|
|
185
|
+
background: var(--fx-input, transparent); color: var(--fx-label, #e7e9ee);
|
|
186
|
+
padding-inline-end: 2rem;
|
|
187
|
+
}
|
|
188
|
+
.tl-empty { color: var(--fx-muted, #8a90a2); font-size: 12px; }
|
|
189
|
+
.tl-commit { padding: 4px 6px; border-radius: 4px; cursor: pointer; font-size: 11.5px; }
|
|
190
|
+
.tl-commit:hover { background: var(--fx-hover, #ffffff10); }
|
|
191
|
+
.tl-commit.selected { background: var(--fx-selected, #ffffff1a); }
|
|
192
|
+
.tl-line { display: flex; align-items: baseline; gap: 6px; }
|
|
193
|
+
.tl-caret { color: var(--fx-muted, #8a90a2); font-size: 9px; flex: none; }
|
|
194
|
+
.tl-time { font-family: ui-monospace, monospace; font-size: 10px; color: var(--fx-muted, #8a90a2); flex: none; }
|
|
195
|
+
.tl-name { color: var(--fx-label, #e7e9ee); font-family: ui-monospace, monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
196
|
+
.tl-did { margin-left: auto; color: var(--fx-muted, #8a90a2); flex: none; }
|
|
197
|
+
.tl-body { margin: 3px 0 2px 15px; }
|
|
198
|
+
/* Wraps: an open entry exists to show the whole value. */
|
|
199
|
+
.tl-change {
|
|
200
|
+
font-family: ui-monospace, monospace; font-size: 11px;
|
|
201
|
+
color: var(--fx-accent, #5eead4); overflow-wrap: anywhere; white-space: pre-wrap;
|
|
202
|
+
}
|
|
203
|
+
.tl-part { margin-top: 2px; color: var(--fx-label, #e7e9ee); font-size: 11px; overflow-wrap: anywhere; }
|
|
204
|
+
.tl-verb { color: var(--fx-muted, #8a90a2); }
|
|
205
|
+
.tl-more {
|
|
206
|
+
margin-top: 5px; padding: 2px 8px; font: inherit; font-size: 10.5px; cursor: pointer;
|
|
207
|
+
border: 1px solid var(--fx-line, #ffffff1f); border-radius: 4px;
|
|
208
|
+
background: transparent; color: var(--fx-muted, #8a90a2);
|
|
209
|
+
}
|
|
210
|
+
.tl-more:hover { color: var(--fx-label, #e7e9ee); }
|
|
211
|
+
${CHANGE_CSS}`;
|
|
212
|
+
|
|
213
|
+
export {
|
|
214
|
+
createTimeline,
|
|
215
|
+
TIMELINE_CSS
|
|
216
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// src/describe.ts
|
|
2
|
+
var MAX_CLASSES = 2;
|
|
3
|
+
function textOwner(node) {
|
|
4
|
+
const parent = node.parentElement;
|
|
5
|
+
return parent ? `text in ${describeElement(parent)}` : "text";
|
|
6
|
+
}
|
|
7
|
+
function describeElement(el) {
|
|
8
|
+
const tag = el.tagName.toLowerCase();
|
|
9
|
+
const id = el.id ? `#${el.id}` : "";
|
|
10
|
+
const raw = typeof el.className === "string" ? el.className : el.getAttribute("class") ?? "";
|
|
11
|
+
const classes = raw.split(/\s+/).filter(Boolean).slice(0, MAX_CLASSES).map((c) => `.${c}`).join("");
|
|
12
|
+
return `${tag}${id}${classes}`;
|
|
13
|
+
}
|
|
14
|
+
function describeNode(target) {
|
|
15
|
+
const node = target;
|
|
16
|
+
if (!node || typeof node.nodeType !== "number") return "detached";
|
|
17
|
+
switch (node.nodeType) {
|
|
18
|
+
case 1:
|
|
19
|
+
return describeElement(node);
|
|
20
|
+
case 3:
|
|
21
|
+
return textOwner(node);
|
|
22
|
+
case 8: {
|
|
23
|
+
const parent = node.parentElement;
|
|
24
|
+
return parent ? `slot in ${describeElement(parent)}` : "slot";
|
|
25
|
+
}
|
|
26
|
+
case 11:
|
|
27
|
+
return "fragment";
|
|
28
|
+
default:
|
|
29
|
+
return node.nodeName?.toLowerCase() ?? "node";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export {
|
|
34
|
+
describeNode
|
|
35
|
+
};
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
// src/float.ts
|
|
2
|
+
var MIN_W = 240;
|
|
3
|
+
var MIN_H = 160;
|
|
4
|
+
function draggable(handle, onMove, onStart) {
|
|
5
|
+
handle.addEventListener("pointerdown", (event) => {
|
|
6
|
+
if (event.button !== 0) return;
|
|
7
|
+
if (event.target.closest("button")) return;
|
|
8
|
+
event.preventDefault();
|
|
9
|
+
handle.setPointerCapture(event.pointerId);
|
|
10
|
+
const fromX = event.clientX;
|
|
11
|
+
const fromY = event.clientY;
|
|
12
|
+
onStart?.();
|
|
13
|
+
const move = (e) => onMove(e.clientX - fromX, e.clientY - fromY);
|
|
14
|
+
const stop = () => {
|
|
15
|
+
handle.removeEventListener("pointermove", move);
|
|
16
|
+
handle.removeEventListener("pointerup", stop);
|
|
17
|
+
handle.removeEventListener("pointercancel", stop);
|
|
18
|
+
handle.removeEventListener("lostpointercapture", stop);
|
|
19
|
+
if (handle.hasPointerCapture(event.pointerId)) handle.releasePointerCapture(event.pointerId);
|
|
20
|
+
};
|
|
21
|
+
handle.addEventListener("pointermove", move);
|
|
22
|
+
handle.addEventListener("pointerup", stop);
|
|
23
|
+
handle.addEventListener("pointercancel", stop);
|
|
24
|
+
handle.addEventListener("lostpointercapture", stop);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
var opened = 0;
|
|
28
|
+
function floatCard(doc, title, at) {
|
|
29
|
+
const card = doc.createElement("div");
|
|
30
|
+
card.className = "fx-float";
|
|
31
|
+
const spot = at ?? {
|
|
32
|
+
x: 60 + opened % 4 * 28,
|
|
33
|
+
y: 60 + opened % 4 * 28,
|
|
34
|
+
width: 360,
|
|
35
|
+
height: 280
|
|
36
|
+
};
|
|
37
|
+
opened += 1;
|
|
38
|
+
const bar = doc.createElement("div");
|
|
39
|
+
bar.className = "fx-float-bar";
|
|
40
|
+
const name = doc.createElement("span");
|
|
41
|
+
name.textContent = title;
|
|
42
|
+
bar.append(name);
|
|
43
|
+
card.append(bar);
|
|
44
|
+
let x = spot.x;
|
|
45
|
+
let y = spot.y;
|
|
46
|
+
let w = spot.width;
|
|
47
|
+
let h = spot.height;
|
|
48
|
+
const apply = () => {
|
|
49
|
+
const view = doc.defaultView;
|
|
50
|
+
const vw = view?.innerWidth ?? w;
|
|
51
|
+
const vh = view?.innerHeight ?? h;
|
|
52
|
+
w = Math.min(Math.max(MIN_W, w), vw);
|
|
53
|
+
h = Math.min(Math.max(MIN_H, h), vh);
|
|
54
|
+
x = Math.min(Math.max(0, x), Math.max(0, vw - w));
|
|
55
|
+
y = Math.min(Math.max(0, y), Math.max(0, vh - h));
|
|
56
|
+
card.style.left = `${x}px`;
|
|
57
|
+
card.style.top = `${y}px`;
|
|
58
|
+
card.style.width = `${w}px`;
|
|
59
|
+
card.style.height = `${h}px`;
|
|
60
|
+
};
|
|
61
|
+
let from = { x, y, w, h };
|
|
62
|
+
const remember = () => {
|
|
63
|
+
from = { x, y, w, h };
|
|
64
|
+
};
|
|
65
|
+
for (const edge of ["n", "s", "e", "w", "ne", "nw", "se", "sw"]) {
|
|
66
|
+
const handle = doc.createElement("div");
|
|
67
|
+
handle.className = `fx-float-h fx-float-${edge}`;
|
|
68
|
+
card.append(handle);
|
|
69
|
+
draggable(
|
|
70
|
+
handle,
|
|
71
|
+
(dx, dy) => {
|
|
72
|
+
if (edge.includes("e")) w = from.w + dx;
|
|
73
|
+
if (edge.includes("s")) h = from.h + dy;
|
|
74
|
+
if (edge.includes("w")) {
|
|
75
|
+
w = Math.max(MIN_W, from.w - dx);
|
|
76
|
+
x = from.x + from.w - w;
|
|
77
|
+
}
|
|
78
|
+
if (edge.includes("n")) {
|
|
79
|
+
h = Math.max(MIN_H, from.h - dy);
|
|
80
|
+
y = from.y + from.h - h;
|
|
81
|
+
}
|
|
82
|
+
apply();
|
|
83
|
+
},
|
|
84
|
+
remember
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
draggable(
|
|
88
|
+
bar,
|
|
89
|
+
(dx, dy) => {
|
|
90
|
+
x = from.x + dx;
|
|
91
|
+
y = from.y + dy;
|
|
92
|
+
apply();
|
|
93
|
+
},
|
|
94
|
+
remember
|
|
95
|
+
);
|
|
96
|
+
apply();
|
|
97
|
+
return { card, bar, remove: () => card.remove() };
|
|
98
|
+
}
|
|
99
|
+
function makeFloatable(pane, options) {
|
|
100
|
+
const doc = pane.ownerDocument;
|
|
101
|
+
let card = null;
|
|
102
|
+
let home = null;
|
|
103
|
+
const button = doc.createElement("button");
|
|
104
|
+
button.type = "button";
|
|
105
|
+
button.className = "fx-float-btn";
|
|
106
|
+
button.textContent = "⇱";
|
|
107
|
+
button.title = `Float ${options.title}`;
|
|
108
|
+
pane.classList.add("fx-floatable");
|
|
109
|
+
pane.append(button);
|
|
110
|
+
const keep = new MutationObserver(() => {
|
|
111
|
+
if (button.parentNode !== pane) pane.append(button);
|
|
112
|
+
});
|
|
113
|
+
keep.observe(pane, { childList: true });
|
|
114
|
+
function dock() {
|
|
115
|
+
if (!card || !home) return;
|
|
116
|
+
home.parent.insertBefore(pane, home.before);
|
|
117
|
+
card.remove();
|
|
118
|
+
card = null;
|
|
119
|
+
home = null;
|
|
120
|
+
pane.classList.remove("fx-floated");
|
|
121
|
+
button.textContent = "⇱";
|
|
122
|
+
button.title = `Float ${options.title}`;
|
|
123
|
+
options.onChange?.(false);
|
|
124
|
+
}
|
|
125
|
+
function float() {
|
|
126
|
+
if (card || !pane.parentNode) return;
|
|
127
|
+
home = { parent: pane.parentNode, before: pane.nextSibling };
|
|
128
|
+
const built = floatCard(doc, options.title, options.at);
|
|
129
|
+
card = built.card;
|
|
130
|
+
card.append(pane);
|
|
131
|
+
doc.body.appendChild(card);
|
|
132
|
+
pane.classList.add("fx-floated");
|
|
133
|
+
button.textContent = "⇲";
|
|
134
|
+
button.title = `Put ${options.title} back`;
|
|
135
|
+
options.onChange?.(true);
|
|
136
|
+
}
|
|
137
|
+
button.addEventListener("click", (event) => {
|
|
138
|
+
event.stopPropagation();
|
|
139
|
+
if (card) dock();
|
|
140
|
+
else float();
|
|
141
|
+
});
|
|
142
|
+
return {
|
|
143
|
+
get floating() {
|
|
144
|
+
return card !== null;
|
|
145
|
+
},
|
|
146
|
+
toggle() {
|
|
147
|
+
if (card) dock();
|
|
148
|
+
else float();
|
|
149
|
+
return card !== null;
|
|
150
|
+
},
|
|
151
|
+
dock,
|
|
152
|
+
destroy() {
|
|
153
|
+
keep.disconnect();
|
|
154
|
+
dock();
|
|
155
|
+
button.remove();
|
|
156
|
+
pane.classList.remove("fx-floatable");
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
var FLOAT_CSS = `
|
|
161
|
+
.fx-floatable { position: relative; }
|
|
162
|
+
.fx-float-btn {
|
|
163
|
+
position: absolute; top: 2px; right: 2px; z-index: 5;
|
|
164
|
+
width: 18px; height: 18px; padding: 0; line-height: 1;
|
|
165
|
+
font-size: 11px; color: var(--fx-muted, #8a90a2);
|
|
166
|
+
background: var(--fx-panel, #14161c);
|
|
167
|
+
border: 1px solid var(--fx-line, #262a35); border-radius: 4px;
|
|
168
|
+
cursor: pointer; opacity: 0; transition: opacity .12s;
|
|
169
|
+
}
|
|
170
|
+
.fx-floatable:hover .fx-float-btn, .fx-float-btn:focus-visible { opacity: 1; }
|
|
171
|
+
.fx-float-btn:hover { color: var(--fx-accent, #5eead4); border-color: var(--fx-accent, #5eead4); }
|
|
172
|
+
|
|
173
|
+
.fx-float {
|
|
174
|
+
position: fixed; z-index: 60; display: flex; flex-direction: column;
|
|
175
|
+
background: var(--fx-panel, #14161c);
|
|
176
|
+
border: 1px solid var(--fx-line, #262a35); border-radius: 8px;
|
|
177
|
+
box-shadow: 0 12px 34px rgba(0, 0, 0, .5); overflow: hidden;
|
|
178
|
+
}
|
|
179
|
+
.fx-float-bar {
|
|
180
|
+
display: flex; align-items: center; padding: 4px 8px; cursor: move;
|
|
181
|
+
font-size: 11px; color: var(--fx-muted, #8a90a2);
|
|
182
|
+
background: var(--fx-bg, #0f1115); border-bottom: 1px solid var(--fx-line, #262a35);
|
|
183
|
+
user-select: none;
|
|
184
|
+
}
|
|
185
|
+
/* The pane fills the card, whatever it was sized to in the layout it came from. */
|
|
186
|
+
.fx-float > .fx-floated {
|
|
187
|
+
flex: 1; min-height: 0; width: auto; height: auto; overflow: auto;
|
|
188
|
+
}
|
|
189
|
+
/* Edges and corners. Thin, and over everything, so a card can be resized from whichever
|
|
190
|
+
side is reachable. */
|
|
191
|
+
.fx-float-h { position: absolute; z-index: 1; }
|
|
192
|
+
.fx-float-n, .fx-float-s { left: 8px; right: 8px; height: 6px; cursor: ns-resize; }
|
|
193
|
+
.fx-float-e, .fx-float-w { top: 8px; bottom: 8px; width: 6px; cursor: ew-resize; }
|
|
194
|
+
.fx-float-n { top: -3px; }
|
|
195
|
+
.fx-float-s { bottom: -3px; }
|
|
196
|
+
.fx-float-e { right: -3px; }
|
|
197
|
+
.fx-float-w { left: -3px; }
|
|
198
|
+
.fx-float-ne, .fx-float-nw, .fx-float-se, .fx-float-sw { width: 14px; height: 14px; }
|
|
199
|
+
.fx-float-nw { top: -3px; left: -3px; cursor: nwse-resize; }
|
|
200
|
+
.fx-float-ne { top: -3px; right: -3px; cursor: nesw-resize; }
|
|
201
|
+
.fx-float-sw { bottom: -3px; left: -3px; cursor: nesw-resize; }
|
|
202
|
+
.fx-float-se {
|
|
203
|
+
bottom: 0; right: 0; cursor: nwse-resize;
|
|
204
|
+
background: linear-gradient(135deg, transparent 50%, var(--fx-line, #262a35) 50%);
|
|
205
|
+
}
|
|
206
|
+
`;
|
|
207
|
+
|
|
208
|
+
export {
|
|
209
|
+
floatCard,
|
|
210
|
+
makeFloatable,
|
|
211
|
+
FLOAT_CSS
|
|
212
|
+
};
|