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