@designtools/next-plugin 0.1.2
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/chunk-Y6FXYEAI.mjs +10 -0
- package/dist/codecanvas-mount-loader.d.mts +15 -0
- package/dist/codecanvas-mount-loader.d.ts +15 -0
- package/dist/codecanvas-mount-loader.js +51 -0
- package/dist/codecanvas-mount-loader.mjs +32 -0
- package/dist/codecanvas.d.mts +3 -0
- package/dist/codecanvas.d.ts +3 -0
- package/dist/codecanvas.js +426 -0
- package/dist/codecanvas.mjs +403 -0
- package/dist/codesurface-mount-loader.d.mts +15 -0
- package/dist/codesurface-mount-loader.d.ts +15 -0
- package/dist/codesurface-mount-loader.js +51 -0
- package/dist/codesurface-mount-loader.mjs +32 -0
- package/dist/codesurface.d.mts +3 -0
- package/dist/codesurface.d.ts +3 -0
- package/dist/codesurface.js +460 -0
- package/dist/codesurface.mjs +437 -0
- package/dist/index.d.mts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +77 -0
- package/dist/index.mjs +44 -0
- package/dist/loader.d.mts +17 -0
- package/dist/loader.d.ts +17 -0
- package/dist/loader.js +113 -0
- package/dist/loader.mjs +86 -0
- package/package.json +28 -0
- package/src/codesurface-mount-loader.ts +51 -0
- package/src/codesurface.tsx +452 -0
- package/src/index.ts +54 -0
- package/src/loader.ts +125 -0
- package/tsconfig.json +8 -0
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/codesurface.tsx
|
|
22
|
+
var codesurface_exports = {};
|
|
23
|
+
__export(codesurface_exports, {
|
|
24
|
+
CodeSurface: () => CodeSurface
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(codesurface_exports);
|
|
27
|
+
var import_react = require("react");
|
|
28
|
+
function CodeSurface() {
|
|
29
|
+
const stateRef = (0, import_react.useRef)({
|
|
30
|
+
selectionMode: false,
|
|
31
|
+
hoveredElement: null,
|
|
32
|
+
selectedElement: null,
|
|
33
|
+
selectedDomPath: null,
|
|
34
|
+
overlayRafId: null,
|
|
35
|
+
inlineStyleBackups: /* @__PURE__ */ new Map(),
|
|
36
|
+
tokenValueBackups: /* @__PURE__ */ new Map(),
|
|
37
|
+
tokenPreviewValues: /* @__PURE__ */ new Map(),
|
|
38
|
+
tokenPreviewStyle: null,
|
|
39
|
+
highlightOverlay: null,
|
|
40
|
+
tooltip: null,
|
|
41
|
+
selectedOverlay: null
|
|
42
|
+
});
|
|
43
|
+
(0, import_react.useEffect)(() => {
|
|
44
|
+
const s = stateRef.current;
|
|
45
|
+
s.highlightOverlay = document.createElement("div");
|
|
46
|
+
s.highlightOverlay.id = "tool-highlight";
|
|
47
|
+
Object.assign(s.highlightOverlay.style, {
|
|
48
|
+
position: "fixed",
|
|
49
|
+
pointerEvents: "none",
|
|
50
|
+
border: "2px solid #3b82f6",
|
|
51
|
+
backgroundColor: "rgba(59, 130, 246, 0.08)",
|
|
52
|
+
borderRadius: "2px",
|
|
53
|
+
zIndex: "99999",
|
|
54
|
+
display: "none",
|
|
55
|
+
transition: "all 0.1s ease"
|
|
56
|
+
});
|
|
57
|
+
document.body.appendChild(s.highlightOverlay);
|
|
58
|
+
s.tooltip = document.createElement("div");
|
|
59
|
+
s.tooltip.id = "tool-tooltip";
|
|
60
|
+
Object.assign(s.tooltip.style, {
|
|
61
|
+
position: "fixed",
|
|
62
|
+
pointerEvents: "none",
|
|
63
|
+
backgroundColor: "#1e1e2e",
|
|
64
|
+
color: "#cdd6f4",
|
|
65
|
+
padding: "3px 8px",
|
|
66
|
+
borderRadius: "4px",
|
|
67
|
+
fontSize: "11px",
|
|
68
|
+
fontFamily: "ui-monospace, monospace",
|
|
69
|
+
zIndex: "100000",
|
|
70
|
+
display: "none",
|
|
71
|
+
whiteSpace: "nowrap",
|
|
72
|
+
boxShadow: "0 2px 8px rgba(0,0,0,0.3)"
|
|
73
|
+
});
|
|
74
|
+
document.body.appendChild(s.tooltip);
|
|
75
|
+
s.selectedOverlay = document.createElement("div");
|
|
76
|
+
s.selectedOverlay.id = "tool-selected";
|
|
77
|
+
Object.assign(s.selectedOverlay.style, {
|
|
78
|
+
position: "fixed",
|
|
79
|
+
pointerEvents: "none",
|
|
80
|
+
border: "2px solid #f59e0b",
|
|
81
|
+
backgroundColor: "rgba(245, 158, 11, 0.06)",
|
|
82
|
+
borderRadius: "2px",
|
|
83
|
+
zIndex: "99998",
|
|
84
|
+
display: "none"
|
|
85
|
+
});
|
|
86
|
+
document.body.appendChild(s.selectedOverlay);
|
|
87
|
+
function getElementName(el) {
|
|
88
|
+
const slot = el.getAttribute("data-slot");
|
|
89
|
+
if (slot) return slot.charAt(0).toUpperCase() + slot.slice(1);
|
|
90
|
+
return `<${el.tagName.toLowerCase()}>`;
|
|
91
|
+
}
|
|
92
|
+
function getDomPath(el) {
|
|
93
|
+
const parts = [];
|
|
94
|
+
let current = el;
|
|
95
|
+
while (current && current !== document.body) {
|
|
96
|
+
const parent = current.parentElement;
|
|
97
|
+
if (parent) {
|
|
98
|
+
const idx = Array.from(parent.children).indexOf(current) + 1;
|
|
99
|
+
parts.unshift(`${current.tagName.toLowerCase()}:nth-child(${idx})`);
|
|
100
|
+
} else {
|
|
101
|
+
parts.unshift(current.tagName.toLowerCase());
|
|
102
|
+
}
|
|
103
|
+
current = current.parentElement;
|
|
104
|
+
}
|
|
105
|
+
return parts.join(" > ");
|
|
106
|
+
}
|
|
107
|
+
function positionOverlay(overlay, rect) {
|
|
108
|
+
Object.assign(overlay.style, {
|
|
109
|
+
left: `${rect.left}px`,
|
|
110
|
+
top: `${rect.top}px`,
|
|
111
|
+
width: `${rect.width}px`,
|
|
112
|
+
height: `${rect.height}px`,
|
|
113
|
+
display: "block"
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function findSelectableElement(target) {
|
|
117
|
+
let el = target;
|
|
118
|
+
while (el && el !== document.body) {
|
|
119
|
+
if (el.getAttribute("data-slot")) return el;
|
|
120
|
+
el = el.parentElement;
|
|
121
|
+
}
|
|
122
|
+
return target;
|
|
123
|
+
}
|
|
124
|
+
const relevantProps = [
|
|
125
|
+
"display",
|
|
126
|
+
"position",
|
|
127
|
+
"top",
|
|
128
|
+
"right",
|
|
129
|
+
"bottom",
|
|
130
|
+
"left",
|
|
131
|
+
"z-index",
|
|
132
|
+
"overflow",
|
|
133
|
+
"overflow-x",
|
|
134
|
+
"overflow-y",
|
|
135
|
+
"flex-direction",
|
|
136
|
+
"flex-wrap",
|
|
137
|
+
"justify-content",
|
|
138
|
+
"align-items",
|
|
139
|
+
"align-self",
|
|
140
|
+
"flex-grow",
|
|
141
|
+
"flex-shrink",
|
|
142
|
+
"flex-basis",
|
|
143
|
+
"order",
|
|
144
|
+
"grid-template-columns",
|
|
145
|
+
"grid-template-rows",
|
|
146
|
+
"gap",
|
|
147
|
+
"row-gap",
|
|
148
|
+
"column-gap",
|
|
149
|
+
"width",
|
|
150
|
+
"height",
|
|
151
|
+
"min-width",
|
|
152
|
+
"min-height",
|
|
153
|
+
"max-width",
|
|
154
|
+
"max-height",
|
|
155
|
+
"margin-top",
|
|
156
|
+
"margin-right",
|
|
157
|
+
"margin-bottom",
|
|
158
|
+
"margin-left",
|
|
159
|
+
"padding-top",
|
|
160
|
+
"padding-right",
|
|
161
|
+
"padding-bottom",
|
|
162
|
+
"padding-left",
|
|
163
|
+
"font-family",
|
|
164
|
+
"font-size",
|
|
165
|
+
"font-weight",
|
|
166
|
+
"line-height",
|
|
167
|
+
"letter-spacing",
|
|
168
|
+
"text-align",
|
|
169
|
+
"text-decoration",
|
|
170
|
+
"text-transform",
|
|
171
|
+
"color",
|
|
172
|
+
"white-space",
|
|
173
|
+
"background-color",
|
|
174
|
+
"background-image",
|
|
175
|
+
"background-size",
|
|
176
|
+
"background-position",
|
|
177
|
+
"border-top-width",
|
|
178
|
+
"border-right-width",
|
|
179
|
+
"border-bottom-width",
|
|
180
|
+
"border-left-width",
|
|
181
|
+
"border-style",
|
|
182
|
+
"border-color",
|
|
183
|
+
"border-top-left-radius",
|
|
184
|
+
"border-top-right-radius",
|
|
185
|
+
"border-bottom-right-radius",
|
|
186
|
+
"border-bottom-left-radius",
|
|
187
|
+
"opacity",
|
|
188
|
+
"box-shadow",
|
|
189
|
+
"transform",
|
|
190
|
+
"transition"
|
|
191
|
+
];
|
|
192
|
+
const inheritableProps = [
|
|
193
|
+
"color",
|
|
194
|
+
"font-family",
|
|
195
|
+
"font-size",
|
|
196
|
+
"font-weight",
|
|
197
|
+
"line-height",
|
|
198
|
+
"letter-spacing",
|
|
199
|
+
"text-align",
|
|
200
|
+
"text-transform",
|
|
201
|
+
"white-space"
|
|
202
|
+
];
|
|
203
|
+
function extractElementData(el) {
|
|
204
|
+
const computed = getComputedStyle(el);
|
|
205
|
+
const rect = el.getBoundingClientRect();
|
|
206
|
+
const computedStyles = {};
|
|
207
|
+
for (const prop of relevantProps) {
|
|
208
|
+
computedStyles[prop] = computed.getPropertyValue(prop);
|
|
209
|
+
}
|
|
210
|
+
const parentComputedStyles = {};
|
|
211
|
+
const parentEl = el.parentElement;
|
|
212
|
+
if (parentEl) {
|
|
213
|
+
const parentComputed = getComputedStyle(parentEl);
|
|
214
|
+
for (const prop of inheritableProps) {
|
|
215
|
+
parentComputedStyles[prop] = parentComputed.getPropertyValue(prop);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
const attributes = {};
|
|
219
|
+
for (const attr of Array.from(el.attributes)) {
|
|
220
|
+
if (attr.name.startsWith("data-")) {
|
|
221
|
+
attributes[attr.name] = attr.value;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
let sourceFile = null;
|
|
225
|
+
let sourceLine = null;
|
|
226
|
+
let sourceCol = null;
|
|
227
|
+
const dataSource = el.getAttribute("data-source");
|
|
228
|
+
if (dataSource) {
|
|
229
|
+
const lastColon = dataSource.lastIndexOf(":");
|
|
230
|
+
const secondLastColon = dataSource.lastIndexOf(":", lastColon - 1);
|
|
231
|
+
if (secondLastColon > 0) {
|
|
232
|
+
sourceFile = dataSource.slice(0, secondLastColon);
|
|
233
|
+
sourceLine = parseInt(dataSource.slice(secondLastColon + 1, lastColon), 10);
|
|
234
|
+
sourceCol = parseInt(dataSource.slice(lastColon + 1), 10);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
let instanceSourceFile = null;
|
|
238
|
+
let instanceSourceLine = null;
|
|
239
|
+
let instanceSourceCol = null;
|
|
240
|
+
let componentName = null;
|
|
241
|
+
const instanceSource = el.getAttribute("data-instance-source");
|
|
242
|
+
if (instanceSource && el.getAttribute("data-slot")) {
|
|
243
|
+
const lc = instanceSource.lastIndexOf(":");
|
|
244
|
+
const slc = instanceSource.lastIndexOf(":", lc - 1);
|
|
245
|
+
if (slc > 0) {
|
|
246
|
+
instanceSourceFile = instanceSource.slice(0, slc);
|
|
247
|
+
instanceSourceLine = parseInt(instanceSource.slice(slc + 1, lc), 10);
|
|
248
|
+
instanceSourceCol = parseInt(instanceSource.slice(lc + 1), 10);
|
|
249
|
+
}
|
|
250
|
+
const slot = el.getAttribute("data-slot") || "";
|
|
251
|
+
componentName = slot.split("-").map((s2) => s2.charAt(0).toUpperCase() + s2.slice(1)).join("");
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
tag: el.tagName.toLowerCase(),
|
|
255
|
+
className: (el.getAttribute("class") || "").trim(),
|
|
256
|
+
computedStyles,
|
|
257
|
+
parentComputedStyles,
|
|
258
|
+
boundingRect: rect,
|
|
259
|
+
domPath: getDomPath(el),
|
|
260
|
+
textContent: (el.textContent || "").trim().slice(0, 100),
|
|
261
|
+
attributes,
|
|
262
|
+
sourceFile,
|
|
263
|
+
sourceLine,
|
|
264
|
+
sourceCol,
|
|
265
|
+
instanceSourceFile,
|
|
266
|
+
instanceSourceLine,
|
|
267
|
+
instanceSourceCol,
|
|
268
|
+
componentName
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
function selectElement(el) {
|
|
272
|
+
s.selectedElement = el;
|
|
273
|
+
s.selectedDomPath = getDomPath(el);
|
|
274
|
+
const data = extractElementData(el);
|
|
275
|
+
if (s.selectedOverlay) {
|
|
276
|
+
positionOverlay(s.selectedOverlay, data.boundingRect);
|
|
277
|
+
}
|
|
278
|
+
startOverlayTracking();
|
|
279
|
+
window.parent.postMessage({ type: "tool:elementSelected", data }, "*");
|
|
280
|
+
}
|
|
281
|
+
function reselectCurrentElement() {
|
|
282
|
+
if (!s.selectedDomPath) return;
|
|
283
|
+
const el = document.querySelector(s.selectedDomPath);
|
|
284
|
+
if (el) {
|
|
285
|
+
s.selectedElement = el;
|
|
286
|
+
const data = extractElementData(el);
|
|
287
|
+
if (s.selectedOverlay) {
|
|
288
|
+
positionOverlay(s.selectedOverlay, data.boundingRect);
|
|
289
|
+
}
|
|
290
|
+
window.parent.postMessage({ type: "tool:elementSelected", data }, "*");
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function startOverlayTracking() {
|
|
294
|
+
if (s.overlayRafId) cancelAnimationFrame(s.overlayRafId);
|
|
295
|
+
let lastRect = "";
|
|
296
|
+
function tick() {
|
|
297
|
+
if (s.selectedElement && s.selectedOverlay) {
|
|
298
|
+
if (!document.contains(s.selectedElement)) {
|
|
299
|
+
if (s.selectedDomPath) {
|
|
300
|
+
const newEl = document.querySelector(s.selectedDomPath);
|
|
301
|
+
if (newEl) {
|
|
302
|
+
s.selectedElement = newEl;
|
|
303
|
+
reselectCurrentElement();
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (s.selectedElement && document.contains(s.selectedElement)) {
|
|
308
|
+
const rect = s.selectedElement.getBoundingClientRect();
|
|
309
|
+
const key = `${rect.left},${rect.top},${rect.width},${rect.height}`;
|
|
310
|
+
if (key !== lastRect) {
|
|
311
|
+
lastRect = key;
|
|
312
|
+
positionOverlay(s.selectedOverlay, rect);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
s.overlayRafId = requestAnimationFrame(tick);
|
|
317
|
+
}
|
|
318
|
+
tick();
|
|
319
|
+
}
|
|
320
|
+
function onMouseMove(e) {
|
|
321
|
+
if (!s.selectionMode || !s.highlightOverlay || !s.tooltip) return;
|
|
322
|
+
const el = document.elementFromPoint(e.clientX, e.clientY);
|
|
323
|
+
if (!el || el === s.highlightOverlay || el === s.tooltip || el === s.selectedOverlay) return;
|
|
324
|
+
const selectable = findSelectableElement(el);
|
|
325
|
+
if (selectable === s.hoveredElement) return;
|
|
326
|
+
s.hoveredElement = selectable;
|
|
327
|
+
const rect = selectable.getBoundingClientRect();
|
|
328
|
+
positionOverlay(s.highlightOverlay, rect);
|
|
329
|
+
const name = getElementName(selectable);
|
|
330
|
+
s.tooltip.textContent = name;
|
|
331
|
+
s.tooltip.style.display = "block";
|
|
332
|
+
s.tooltip.style.left = `${rect.left}px`;
|
|
333
|
+
s.tooltip.style.top = `${Math.max(0, rect.top - 24)}px`;
|
|
334
|
+
}
|
|
335
|
+
function onMouseLeave() {
|
|
336
|
+
if (!s.highlightOverlay || !s.tooltip) return;
|
|
337
|
+
s.highlightOverlay.style.display = "none";
|
|
338
|
+
s.tooltip.style.display = "none";
|
|
339
|
+
s.hoveredElement = null;
|
|
340
|
+
}
|
|
341
|
+
function onClick(e) {
|
|
342
|
+
if (!s.selectionMode) return;
|
|
343
|
+
e.preventDefault();
|
|
344
|
+
e.stopPropagation();
|
|
345
|
+
const el = document.elementFromPoint(e.clientX, e.clientY);
|
|
346
|
+
if (!el || el === s.highlightOverlay || el === s.tooltip || el === s.selectedOverlay) return;
|
|
347
|
+
const selectable = findSelectableElement(el);
|
|
348
|
+
selectElement(selectable);
|
|
349
|
+
}
|
|
350
|
+
function onMessage(e) {
|
|
351
|
+
const msg = e.data;
|
|
352
|
+
if (!msg || !msg.type || !msg.type.startsWith("tool:")) return;
|
|
353
|
+
switch (msg.type) {
|
|
354
|
+
case "tool:enterSelectionMode":
|
|
355
|
+
s.selectionMode = true;
|
|
356
|
+
document.body.style.cursor = "crosshair";
|
|
357
|
+
break;
|
|
358
|
+
case "tool:exitSelectionMode":
|
|
359
|
+
s.selectionMode = false;
|
|
360
|
+
document.body.style.cursor = "";
|
|
361
|
+
if (s.highlightOverlay) s.highlightOverlay.style.display = "none";
|
|
362
|
+
if (s.tooltip) s.tooltip.style.display = "none";
|
|
363
|
+
s.hoveredElement = null;
|
|
364
|
+
break;
|
|
365
|
+
case "tool:previewInlineStyle": {
|
|
366
|
+
if (s.selectedElement && s.selectedElement instanceof HTMLElement) {
|
|
367
|
+
const prop = msg.property;
|
|
368
|
+
const value = msg.value;
|
|
369
|
+
if (!s.inlineStyleBackups.has(prop)) {
|
|
370
|
+
s.inlineStyleBackups.set(prop, s.selectedElement.style.getPropertyValue(prop));
|
|
371
|
+
}
|
|
372
|
+
s.selectedElement.style.setProperty(prop, value, "important");
|
|
373
|
+
}
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
case "tool:revertInlineStyles": {
|
|
377
|
+
if (s.selectedElement && s.selectedElement instanceof HTMLElement) {
|
|
378
|
+
for (const [prop, original] of s.inlineStyleBackups) {
|
|
379
|
+
if (original) {
|
|
380
|
+
s.selectedElement.style.setProperty(prop, original);
|
|
381
|
+
} else {
|
|
382
|
+
s.selectedElement.style.removeProperty(prop);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
s.inlineStyleBackups.clear();
|
|
386
|
+
}
|
|
387
|
+
break;
|
|
388
|
+
}
|
|
389
|
+
case "tool:previewTokenValue": {
|
|
390
|
+
const prop = msg.property;
|
|
391
|
+
const value = msg.value;
|
|
392
|
+
s.tokenPreviewValues.set(prop, value);
|
|
393
|
+
if (!s.tokenPreviewStyle) {
|
|
394
|
+
s.tokenPreviewStyle = document.createElement("style");
|
|
395
|
+
s.tokenPreviewStyle.id = "codesurface-token-preview";
|
|
396
|
+
document.head.appendChild(s.tokenPreviewStyle);
|
|
397
|
+
}
|
|
398
|
+
const cssRules = [];
|
|
399
|
+
for (const [k, v] of s.tokenPreviewValues) {
|
|
400
|
+
if (k.startsWith("--shadow")) {
|
|
401
|
+
const cls = k.slice(2);
|
|
402
|
+
cssRules.push(`.${cls}, [class*="${cls}"] { box-shadow: ${v} !important; }`);
|
|
403
|
+
} else {
|
|
404
|
+
cssRules.push(`*, *::before, *::after { ${k}: ${v} !important; }`);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
s.tokenPreviewStyle.textContent = cssRules.join("\n");
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
case "tool:revertTokenValues": {
|
|
411
|
+
if (s.tokenPreviewStyle) {
|
|
412
|
+
s.tokenPreviewStyle.remove();
|
|
413
|
+
s.tokenPreviewStyle = null;
|
|
414
|
+
}
|
|
415
|
+
s.tokenPreviewValues.clear();
|
|
416
|
+
s.tokenValueBackups.clear();
|
|
417
|
+
break;
|
|
418
|
+
}
|
|
419
|
+
case "tool:reselectElement":
|
|
420
|
+
reselectCurrentElement();
|
|
421
|
+
break;
|
|
422
|
+
case "tool:setTheme":
|
|
423
|
+
if (msg.theme === "dark") {
|
|
424
|
+
document.documentElement.classList.add("dark");
|
|
425
|
+
} else {
|
|
426
|
+
document.documentElement.classList.remove("dark");
|
|
427
|
+
}
|
|
428
|
+
break;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
function notifyPathChanged() {
|
|
432
|
+
const fullPath = window.location.pathname + window.location.search + window.location.hash;
|
|
433
|
+
window.parent.postMessage({ type: "tool:pathChanged", path: fullPath }, "*");
|
|
434
|
+
}
|
|
435
|
+
document.addEventListener("mousemove", onMouseMove, true);
|
|
436
|
+
document.addEventListener("mouseleave", onMouseLeave);
|
|
437
|
+
document.addEventListener("click", onClick, true);
|
|
438
|
+
window.addEventListener("message", onMessage);
|
|
439
|
+
window.addEventListener("popstate", notifyPathChanged);
|
|
440
|
+
window.parent.postMessage({ type: "tool:injectedReady" }, "*");
|
|
441
|
+
notifyPathChanged();
|
|
442
|
+
return () => {
|
|
443
|
+
document.removeEventListener("mousemove", onMouseMove, true);
|
|
444
|
+
document.removeEventListener("mouseleave", onMouseLeave);
|
|
445
|
+
document.removeEventListener("click", onClick, true);
|
|
446
|
+
window.removeEventListener("message", onMessage);
|
|
447
|
+
window.removeEventListener("popstate", notifyPathChanged);
|
|
448
|
+
if (s.overlayRafId) cancelAnimationFrame(s.overlayRafId);
|
|
449
|
+
s.tokenPreviewStyle?.remove();
|
|
450
|
+
s.highlightOverlay?.remove();
|
|
451
|
+
s.tooltip?.remove();
|
|
452
|
+
s.selectedOverlay?.remove();
|
|
453
|
+
};
|
|
454
|
+
}, []);
|
|
455
|
+
return null;
|
|
456
|
+
}
|
|
457
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
458
|
+
0 && (module.exports = {
|
|
459
|
+
CodeSurface
|
|
460
|
+
});
|