@lvce-editor/renderer-process 30.36.2 → 30.37.0
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/rendererProcessMain.js +64 -0
- package/package.json +1 -1
|
@@ -5416,6 +5416,62 @@ const take = (uid, transactionId) => {
|
|
|
5416
5416
|
|
|
5417
5417
|
const rememberFocus = rememberFocus$1;
|
|
5418
5418
|
|
|
5419
|
+
const getColor = ($Parent, className) => {
|
|
5420
|
+
const $Probe = document.createElement('span');
|
|
5421
|
+
$Probe.className = className;
|
|
5422
|
+
$Probe.hidden = true;
|
|
5423
|
+
$Parent.append($Probe);
|
|
5424
|
+
const color = getComputedStyle($Probe).color;
|
|
5425
|
+
$Probe.remove();
|
|
5426
|
+
return color;
|
|
5427
|
+
};
|
|
5428
|
+
const getColors = ($Parent, rectangles) => {
|
|
5429
|
+
const colors = new Map();
|
|
5430
|
+
for (const rectangle of rectangles) {
|
|
5431
|
+
if (!colors.has(rectangle.className)) {
|
|
5432
|
+
colors.set(rectangle.className, getColor($Parent, rectangle.className));
|
|
5433
|
+
}
|
|
5434
|
+
}
|
|
5435
|
+
return colors;
|
|
5436
|
+
};
|
|
5437
|
+
const getOrCreateCanvas = ($Parent, className) => {
|
|
5438
|
+
const existing = $Parent.querySelector(`:scope > canvas.${className}`);
|
|
5439
|
+
if (existing) {
|
|
5440
|
+
return existing;
|
|
5441
|
+
}
|
|
5442
|
+
const $Canvas = document.createElement('canvas');
|
|
5443
|
+
$Canvas.className = className;
|
|
5444
|
+
$Canvas.ariaHidden = 'true';
|
|
5445
|
+
$Parent.append($Canvas);
|
|
5446
|
+
return $Canvas;
|
|
5447
|
+
};
|
|
5448
|
+
const renderCanvas$1 = ($Viewlet, selector, canvasClassName, width, height, rectangles, revision) => {
|
|
5449
|
+
const $Parent = $Viewlet.matches(selector) ? $Viewlet : $Viewlet.querySelector(selector);
|
|
5450
|
+
if (!$Parent) {
|
|
5451
|
+
return;
|
|
5452
|
+
}
|
|
5453
|
+
const $Canvas = getOrCreateCanvas($Parent, canvasClassName);
|
|
5454
|
+
const devicePixelRatio = globalThis.devicePixelRatio || 1;
|
|
5455
|
+
$Canvas.width = Math.round(width * devicePixelRatio);
|
|
5456
|
+
$Canvas.height = Math.round(height * devicePixelRatio);
|
|
5457
|
+
$Canvas.style.width = `${width}px`;
|
|
5458
|
+
$Canvas.style.height = `${height}px`;
|
|
5459
|
+
$Canvas.dataset.renderRevision = revision;
|
|
5460
|
+
$Canvas.dataset.rectangleCount = String(rectangles.length);
|
|
5461
|
+
const context = $Canvas.getContext('2d');
|
|
5462
|
+
if (!context) {
|
|
5463
|
+
return;
|
|
5464
|
+
}
|
|
5465
|
+
context.resetTransform();
|
|
5466
|
+
context.clearRect(0, 0, $Canvas.width, $Canvas.height);
|
|
5467
|
+
context.scale(devicePixelRatio, devicePixelRatio);
|
|
5468
|
+
const colors = getColors($Parent, rectangles);
|
|
5469
|
+
for (const rectangle of rectangles) {
|
|
5470
|
+
context.fillStyle = colors.get(rectangle.className) || 'currentColor';
|
|
5471
|
+
context.fillRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
|
|
5472
|
+
}
|
|
5473
|
+
};
|
|
5474
|
+
|
|
5419
5475
|
const handleImageLoad = event => {
|
|
5420
5476
|
const $ImagePreviewImage = event.target;
|
|
5421
5477
|
const $ImagePreviewCaption = $ImagePreviewImage.nextSibling;
|
|
@@ -9487,6 +9543,13 @@ const setProperty = (id, selector, property, value) => {
|
|
|
9487
9543
|
}
|
|
9488
9544
|
$Element[property] = value;
|
|
9489
9545
|
};
|
|
9546
|
+
const renderCanvas = (id, selector, canvasClassName, width, height, rectangles, revision) => {
|
|
9547
|
+
const instance = get$9(id);
|
|
9548
|
+
if (!instance) {
|
|
9549
|
+
return;
|
|
9550
|
+
}
|
|
9551
|
+
renderCanvas$1(instance.state.$Viewlet, selector, canvasClassName, width, height, rectangles, revision);
|
|
9552
|
+
};
|
|
9490
9553
|
const commandHandlers = {
|
|
9491
9554
|
'Css.addCssStyleSheet': addCssStyleSheet,
|
|
9492
9555
|
'Viewlet.addCss': addCssStyleSheet,
|
|
@@ -9510,6 +9573,7 @@ const commandHandlers = {
|
|
|
9510
9573
|
'Viewlet.patchCss': patchCssStyleSheet,
|
|
9511
9574
|
'Viewlet.registerEventListeners': registerEventListeners,
|
|
9512
9575
|
'Viewlet.removeKeyBindings': removeKeyBindings,
|
|
9576
|
+
'Viewlet.renderCanvas': renderCanvas,
|
|
9513
9577
|
'Viewlet.replaceChildren': replaceChildren,
|
|
9514
9578
|
'Viewlet.send': invoke,
|
|
9515
9579
|
'Viewlet.setBounds': setBounds$1,
|