@designtools/next-plugin 0.1.3 → 0.1.7

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