@lvce-editor/renderer-process 30.36.1 → 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.
@@ -1221,13 +1221,14 @@ const unwrapItemString = async item => {
1221
1221
  const unwrapItemFile = async item => {
1222
1222
  // @ts-ignore
1223
1223
  if (item.getAsFileSystemHandle) {
1224
+ const nativeFile = item.getAsFile();
1224
1225
  // @ts-ignore
1225
- const file = await item.getAsFileSystemHandle();
1226
+ const fileHandle = await item.getAsFileSystemHandle();
1226
1227
  return {
1227
- file: item.getAsFile(),
1228
+ file: nativeFile,
1228
1229
  kind: 'file',
1229
1230
  type: item.type,
1230
- value: file
1231
+ value: fileHandle
1231
1232
  };
1232
1233
  }
1233
1234
  const file = item.getAsFile();
@@ -368,13 +368,14 @@ const unwrapItemString = async item => {
368
368
  const unwrapItemFile = async item => {
369
369
  // @ts-ignore
370
370
  if (item.getAsFileSystemHandle) {
371
+ const nativeFile = item.getAsFile();
371
372
  // @ts-ignore
372
- const file = await item.getAsFileSystemHandle();
373
+ const fileHandle = await item.getAsFileSystemHandle();
373
374
  return {
374
- file: item.getAsFile(),
375
+ file: nativeFile,
375
376
  kind: 'file',
376
377
  type: item.type,
377
- value: file
378
+ value: fileHandle
378
379
  };
379
380
  }
380
381
  const file = item.getAsFile();
@@ -1977,8 +1978,57 @@ const downloadFile = (fileName, url) => {
1977
1978
  a.click();
1978
1979
  };
1979
1980
 
1980
- const get$5 = ids => {
1981
- return getFileHandles$1(ids);
1981
+ const isFile = value => {
1982
+ return value instanceof File;
1983
+ };
1984
+
1985
+ const getFilePathElectron = async file => {
1986
+ if (!isFile(file)) {
1987
+ throw new TypeError(`file must be of type File`);
1988
+ }
1989
+ if (!globalThis.electronGlobals) {
1990
+ throw new Error(`electron globals are not available`);
1991
+ }
1992
+ const filePath = globalThis.electronGlobals.getPathForFile(file);
1993
+ return filePath;
1994
+ };
1995
+
1996
+ const isFileSystemFileHandle = value => {
1997
+ if (!value || typeof value !== 'object') {
1998
+ return false;
1999
+ }
2000
+ const candidate = value;
2001
+ return candidate.kind === 'file' && typeof candidate.getFile === 'function';
2002
+ };
2003
+ const getNativeFile = async item => {
2004
+ if (item.kind === 'file-legacy') {
2005
+ return item.value instanceof File ? item.value : undefined;
2006
+ }
2007
+ if (item.file instanceof File) {
2008
+ return item.file;
2009
+ }
2010
+ if (isFileSystemFileHandle(item.value)) {
2011
+ return item.value.getFile();
2012
+ }
2013
+ return undefined;
2014
+ };
2015
+ const addElectronPath = async item => {
2016
+ if (!globalThis.electronGlobals) {
2017
+ return item;
2018
+ }
2019
+ const file = await getNativeFile(item);
2020
+ if (!file) {
2021
+ return item;
2022
+ }
2023
+ const path = await getFilePathElectron(file);
2024
+ return {
2025
+ ...item,
2026
+ path
2027
+ };
2028
+ };
2029
+ const get$5 = async ids => {
2030
+ const items = await getFileHandles$1(ids);
2031
+ return Promise.all(items.map(addElectronPath));
1982
2032
  };
1983
2033
 
1984
2034
  const showDirectoryPicker = options => {
@@ -5366,6 +5416,62 @@ const take = (uid, transactionId) => {
5366
5416
 
5367
5417
  const rememberFocus = rememberFocus$1;
5368
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
+
5369
5475
  const handleImageLoad = event => {
5370
5476
  const $ImagePreviewImage = event.target;
5371
5477
  const $ImagePreviewCaption = $ImagePreviewImage.nextSibling;
@@ -9437,6 +9543,13 @@ const setProperty = (id, selector, property, value) => {
9437
9543
  }
9438
9544
  $Element[property] = value;
9439
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
+ };
9440
9553
  const commandHandlers = {
9441
9554
  'Css.addCssStyleSheet': addCssStyleSheet,
9442
9555
  'Viewlet.addCss': addCssStyleSheet,
@@ -9460,6 +9573,7 @@ const commandHandlers = {
9460
9573
  'Viewlet.patchCss': patchCssStyleSheet,
9461
9574
  'Viewlet.registerEventListeners': registerEventListeners,
9462
9575
  'Viewlet.removeKeyBindings': removeKeyBindings,
9576
+ 'Viewlet.renderCanvas': renderCanvas,
9463
9577
  'Viewlet.replaceChildren': replaceChildren,
9464
9578
  'Viewlet.send': invoke,
9465
9579
  'Viewlet.setBounds': setBounds$1,
@@ -9576,21 +9690,6 @@ const unmock = () => {
9576
9690
  Element.prototype.releasePointerCapture = originalPointerCapture.releasePointerCapture;
9577
9691
  };
9578
9692
 
9579
- const isFile = value => {
9580
- return value instanceof File;
9581
- };
9582
-
9583
- const getFilePathElectron = async file => {
9584
- if (!isFile(file)) {
9585
- throw new TypeError(`file must be of type File`);
9586
- }
9587
- if (!globalThis.electronGlobals) {
9588
- throw new Error(`electron globals are not available`);
9589
- }
9590
- const filePath = globalThis.electronGlobals.getPathForFile(file);
9591
- return filePath;
9592
- };
9593
-
9594
9693
  const forwardRendererWorkerCommand = (method, ...params) => {
9595
9694
  send$1(method, ...params);
9596
9695
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/renderer-process",
3
- "version": "30.36.1",
3
+ "version": "30.37.0",
4
4
  "keywords": [
5
5
  "lvce-editor",
6
6
  "renderer-process"