@yoamigo.com/core 0.1.8 → 0.1.9
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/index.js +74 -0
- package/dist/lib.js +74 -0
- package/package.json +7 -6
package/dist/index.js
CHANGED
|
@@ -198,6 +198,11 @@ var BuilderSelectionManager = class {
|
|
|
198
198
|
case "CLEAR_SELECTIONS":
|
|
199
199
|
this.clearAllSelections();
|
|
200
200
|
break;
|
|
201
|
+
case "REQUEST_REGION_SCREENSHOT":
|
|
202
|
+
if (data.region) {
|
|
203
|
+
this.captureRegionScreenshot(data.region);
|
|
204
|
+
}
|
|
205
|
+
break;
|
|
201
206
|
}
|
|
202
207
|
});
|
|
203
208
|
}
|
|
@@ -278,6 +283,9 @@ var BuilderSelectionManager = class {
|
|
|
278
283
|
this.sendToParent({ type: "SHIFT_KEY_PRESSED" });
|
|
279
284
|
}
|
|
280
285
|
}
|
|
286
|
+
if (e.key === "Escape") {
|
|
287
|
+
this.sendToParent({ type: "ESCAPE_KEY_PRESSED" });
|
|
288
|
+
}
|
|
281
289
|
};
|
|
282
290
|
/**
|
|
283
291
|
* Check if element matches any selectable selector
|
|
@@ -564,6 +572,72 @@ var BuilderSelectionManager = class {
|
|
|
564
572
|
container.style.height = `${rect.height}px`;
|
|
565
573
|
});
|
|
566
574
|
};
|
|
575
|
+
/**
|
|
576
|
+
* Capture a region of the page as a screenshot
|
|
577
|
+
* Uses html2canvas to render the page and then crops to the specified region
|
|
578
|
+
*/
|
|
579
|
+
async captureRegionScreenshot(region) {
|
|
580
|
+
try {
|
|
581
|
+
console.log("[BuilderSelection] Capturing region screenshot:", region);
|
|
582
|
+
const html2canvas = (await import("html2canvas")).default;
|
|
583
|
+
const overlays = document.querySelectorAll(".builder-selection-container, #builder-hover-overlay");
|
|
584
|
+
overlays.forEach((el) => {
|
|
585
|
+
;
|
|
586
|
+
el.style.display = "none";
|
|
587
|
+
});
|
|
588
|
+
const canvas = await html2canvas(document.body, {
|
|
589
|
+
scale: window.devicePixelRatio || 1,
|
|
590
|
+
logging: false,
|
|
591
|
+
useCORS: true,
|
|
592
|
+
allowTaint: true,
|
|
593
|
+
backgroundColor: null
|
|
594
|
+
// Preserve transparency if any
|
|
595
|
+
});
|
|
596
|
+
overlays.forEach((el) => {
|
|
597
|
+
;
|
|
598
|
+
el.style.display = "";
|
|
599
|
+
});
|
|
600
|
+
const scale = window.devicePixelRatio || 1;
|
|
601
|
+
const scaledRegion = {
|
|
602
|
+
x: Math.round(region.x * scale),
|
|
603
|
+
y: Math.round(region.y * scale),
|
|
604
|
+
width: Math.round(region.width * scale),
|
|
605
|
+
height: Math.round(region.height * scale)
|
|
606
|
+
};
|
|
607
|
+
const croppedCanvas = document.createElement("canvas");
|
|
608
|
+
croppedCanvas.width = scaledRegion.width;
|
|
609
|
+
croppedCanvas.height = scaledRegion.height;
|
|
610
|
+
const ctx = croppedCanvas.getContext("2d");
|
|
611
|
+
if (!ctx) {
|
|
612
|
+
throw new Error("Failed to get canvas context");
|
|
613
|
+
}
|
|
614
|
+
ctx.drawImage(
|
|
615
|
+
canvas,
|
|
616
|
+
scaledRegion.x,
|
|
617
|
+
scaledRegion.y,
|
|
618
|
+
scaledRegion.width,
|
|
619
|
+
scaledRegion.height,
|
|
620
|
+
0,
|
|
621
|
+
0,
|
|
622
|
+
scaledRegion.width,
|
|
623
|
+
scaledRegion.height
|
|
624
|
+
);
|
|
625
|
+
const dataUrl = croppedCanvas.toDataURL("image/png", 0.9);
|
|
626
|
+
console.log("[BuilderSelection] Region screenshot captured, size:", dataUrl.length);
|
|
627
|
+
this.sendToParent({
|
|
628
|
+
type: "REGION_SCREENSHOT_READY",
|
|
629
|
+
dataUrl,
|
|
630
|
+
region
|
|
631
|
+
});
|
|
632
|
+
} catch (error) {
|
|
633
|
+
console.error("[BuilderSelection] Region screenshot failed:", error);
|
|
634
|
+
this.sendToParent({
|
|
635
|
+
type: "REGION_SCREENSHOT_ERROR",
|
|
636
|
+
error: error instanceof Error ? error.message : "Screenshot capture failed",
|
|
637
|
+
region
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
}
|
|
567
641
|
renderSelectionIndicator(element, selectionId, color) {
|
|
568
642
|
const rect = element.getBoundingClientRect();
|
|
569
643
|
const container = document.createElement("div");
|
package/dist/lib.js
CHANGED
|
@@ -157,6 +157,11 @@ var BuilderSelectionManager = class {
|
|
|
157
157
|
case "CLEAR_SELECTIONS":
|
|
158
158
|
this.clearAllSelections();
|
|
159
159
|
break;
|
|
160
|
+
case "REQUEST_REGION_SCREENSHOT":
|
|
161
|
+
if (data.region) {
|
|
162
|
+
this.captureRegionScreenshot(data.region);
|
|
163
|
+
}
|
|
164
|
+
break;
|
|
160
165
|
}
|
|
161
166
|
});
|
|
162
167
|
}
|
|
@@ -237,6 +242,9 @@ var BuilderSelectionManager = class {
|
|
|
237
242
|
this.sendToParent({ type: "SHIFT_KEY_PRESSED" });
|
|
238
243
|
}
|
|
239
244
|
}
|
|
245
|
+
if (e.key === "Escape") {
|
|
246
|
+
this.sendToParent({ type: "ESCAPE_KEY_PRESSED" });
|
|
247
|
+
}
|
|
240
248
|
};
|
|
241
249
|
/**
|
|
242
250
|
* Check if element matches any selectable selector
|
|
@@ -523,6 +531,72 @@ var BuilderSelectionManager = class {
|
|
|
523
531
|
container.style.height = `${rect.height}px`;
|
|
524
532
|
});
|
|
525
533
|
};
|
|
534
|
+
/**
|
|
535
|
+
* Capture a region of the page as a screenshot
|
|
536
|
+
* Uses html2canvas to render the page and then crops to the specified region
|
|
537
|
+
*/
|
|
538
|
+
async captureRegionScreenshot(region) {
|
|
539
|
+
try {
|
|
540
|
+
console.log("[BuilderSelection] Capturing region screenshot:", region);
|
|
541
|
+
const html2canvas = (await import("html2canvas")).default;
|
|
542
|
+
const overlays = document.querySelectorAll(".builder-selection-container, #builder-hover-overlay");
|
|
543
|
+
overlays.forEach((el) => {
|
|
544
|
+
;
|
|
545
|
+
el.style.display = "none";
|
|
546
|
+
});
|
|
547
|
+
const canvas = await html2canvas(document.body, {
|
|
548
|
+
scale: window.devicePixelRatio || 1,
|
|
549
|
+
logging: false,
|
|
550
|
+
useCORS: true,
|
|
551
|
+
allowTaint: true,
|
|
552
|
+
backgroundColor: null
|
|
553
|
+
// Preserve transparency if any
|
|
554
|
+
});
|
|
555
|
+
overlays.forEach((el) => {
|
|
556
|
+
;
|
|
557
|
+
el.style.display = "";
|
|
558
|
+
});
|
|
559
|
+
const scale = window.devicePixelRatio || 1;
|
|
560
|
+
const scaledRegion = {
|
|
561
|
+
x: Math.round(region.x * scale),
|
|
562
|
+
y: Math.round(region.y * scale),
|
|
563
|
+
width: Math.round(region.width * scale),
|
|
564
|
+
height: Math.round(region.height * scale)
|
|
565
|
+
};
|
|
566
|
+
const croppedCanvas = document.createElement("canvas");
|
|
567
|
+
croppedCanvas.width = scaledRegion.width;
|
|
568
|
+
croppedCanvas.height = scaledRegion.height;
|
|
569
|
+
const ctx = croppedCanvas.getContext("2d");
|
|
570
|
+
if (!ctx) {
|
|
571
|
+
throw new Error("Failed to get canvas context");
|
|
572
|
+
}
|
|
573
|
+
ctx.drawImage(
|
|
574
|
+
canvas,
|
|
575
|
+
scaledRegion.x,
|
|
576
|
+
scaledRegion.y,
|
|
577
|
+
scaledRegion.width,
|
|
578
|
+
scaledRegion.height,
|
|
579
|
+
0,
|
|
580
|
+
0,
|
|
581
|
+
scaledRegion.width,
|
|
582
|
+
scaledRegion.height
|
|
583
|
+
);
|
|
584
|
+
const dataUrl = croppedCanvas.toDataURL("image/png", 0.9);
|
|
585
|
+
console.log("[BuilderSelection] Region screenshot captured, size:", dataUrl.length);
|
|
586
|
+
this.sendToParent({
|
|
587
|
+
type: "REGION_SCREENSHOT_READY",
|
|
588
|
+
dataUrl,
|
|
589
|
+
region
|
|
590
|
+
});
|
|
591
|
+
} catch (error) {
|
|
592
|
+
console.error("[BuilderSelection] Region screenshot failed:", error);
|
|
593
|
+
this.sendToParent({
|
|
594
|
+
type: "REGION_SCREENSHOT_ERROR",
|
|
595
|
+
error: error instanceof Error ? error.message : "Screenshot capture failed",
|
|
596
|
+
region
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
}
|
|
526
600
|
renderSelectionIndicator(element, selectionId, color) {
|
|
527
601
|
const rect = element.getBoundingClientRect();
|
|
528
602
|
const container = document.createElement("div");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yoamigo.com/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "Core components, router, and utilities for YoAmigo templates",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -63,6 +63,7 @@
|
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"clsx": "^2.1.1",
|
|
66
|
+
"html2canvas": "^1.4.1",
|
|
66
67
|
"preact": "^10.27.2",
|
|
67
68
|
"wouter": "^3.8.0"
|
|
68
69
|
},
|
|
@@ -87,18 +88,18 @@
|
|
|
87
88
|
"vite": "^7.2.4"
|
|
88
89
|
},
|
|
89
90
|
"peerDependencies": {
|
|
90
|
-
"@vitejs/plugin-react": "^5.0.0",
|
|
91
91
|
"@preact/preset-vite": "^2.0.0",
|
|
92
|
-
"react": "^18.0.0 || ^19.0.0",
|
|
93
|
-
"react-dom": "^18.0.0 || ^19.0.0",
|
|
94
|
-
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0",
|
|
95
92
|
"@tiptap/core": "^3.0.0",
|
|
96
93
|
"@tiptap/extension-link": "^3.0.0",
|
|
97
94
|
"@tiptap/extension-text-style": "^3.0.0",
|
|
98
95
|
"@tiptap/pm": "^3.0.0",
|
|
99
96
|
"@tiptap/react": "^3.0.0",
|
|
100
97
|
"@tiptap/starter-kit": "^3.0.0",
|
|
101
|
-
"
|
|
98
|
+
"@vitejs/plugin-react": "^5.0.0",
|
|
99
|
+
"dompurify": "^3.0.0",
|
|
100
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
101
|
+
"react-dom": "^18.0.0 || ^19.0.0",
|
|
102
|
+
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
|
|
102
103
|
},
|
|
103
104
|
"peerDependenciesMeta": {
|
|
104
105
|
"react": {
|