@lvce-editor/preview-sandbox-worker 3.1.0 → 3.2.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.
@@ -1343,6 +1343,32 @@ const TAGS_TO_SKIP_TAG_ONLY = new Set(['html', 'body', 'head']);
1343
1343
 
1344
1344
  // Tags where we extract content as CSS
1345
1345
  const CSS_TAGS = new Set(['style']);
1346
+ const serializeAttributeName = attrName => {
1347
+ if (attrName === 'class') {
1348
+ return 'className';
1349
+ }
1350
+ if (attrName === 'type') {
1351
+ return 'inputType';
1352
+ }
1353
+ return attrName;
1354
+ };
1355
+ const applyAllowedAttributes = (targetNode, sourceNode) => {
1356
+ const {
1357
+ attributes
1358
+ } = sourceNode;
1359
+ if (!attributes) {
1360
+ return;
1361
+ }
1362
+ for (let i = 0; i < attributes.length; i++) {
1363
+ const attr = attributes[i];
1364
+ const attrName = attr.name;
1365
+ if (isDefaultAllowedAttribute(attrName, [])) {
1366
+ const finalName = serializeAttributeName(attrName);
1367
+ targetNode[finalName] = attr.value;
1368
+ }
1369
+ }
1370
+ };
1371
+
1346
1372
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
1347
1373
  const serializeNode = (node, dom, css, context) => {
1348
1374
  const {
@@ -1398,6 +1424,7 @@ const serializeNode = (node, dom, css, context) => {
1398
1424
  type: Reference,
1399
1425
  uid: node.__canvasId
1400
1426
  };
1427
+ applyAllowedAttributes(refNode, node);
1401
1428
  if (context.elementMap) {
1402
1429
  context.elementMap[node.__canvasId + ''] = node;
1403
1430
  }
@@ -1410,26 +1437,7 @@ const serializeNode = (node, dom, css, context) => {
1410
1437
  childCount: 0,
1411
1438
  type: getVirtualDomTag(tagName)
1412
1439
  };
1413
-
1414
- // Copy allowed attributes
1415
- const {
1416
- attributes
1417
- } = node;
1418
- if (attributes) {
1419
- for (let i = 0; i < attributes.length; i++) {
1420
- const attr = attributes[i];
1421
- const attrName = attr.name;
1422
- if (isDefaultAllowedAttribute(attrName, [])) {
1423
- let finalName = attrName;
1424
- if (attrName === 'class') {
1425
- finalName = 'className';
1426
- } else if (attrName === 'type') {
1427
- finalName = 'inputType';
1428
- }
1429
- newNode[finalName] = attr.value;
1430
- }
1431
- }
1432
- }
1440
+ applyAllowedAttributes(newNode, node);
1433
1441
 
1434
1442
  // Assign element tracking ID for interactivity
1435
1443
  const hdId = String(context.nextId++);
@@ -89681,17 +89689,19 @@ const createLocalStorage = () => {
89681
89689
  return localStorage;
89682
89690
  };
89683
89691
 
89684
- const getGlobals = (width, height) => {
89692
+ const getGlobals = (width, height, devicePixelRatio = 1) => {
89685
89693
  const localStorage = createLocalStorage();
89686
89694
  return {
89687
89695
  globalGlobals: {
89688
89696
  alert: alert,
89697
+ devicePixelRatio,
89689
89698
  innerHeight: height,
89690
89699
  innerWidth: width,
89691
89700
  localStorage
89692
89701
  },
89693
89702
  windowGlobals: {
89694
89703
  alert: alert,
89704
+ devicePixelRatio,
89695
89705
  innerHeight: height,
89696
89706
  innerWidth: width
89697
89707
  }
@@ -89801,12 +89811,12 @@ const setGlobals = (window, globalGlobals, windowGlobals) => {
89801
89811
  /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
89802
89812
  /* eslint-disable @typescript-eslint/no-implied-eval */
89803
89813
 
89804
- const executeScripts = (window, document, scripts, width = 0, height = 0) => {
89814
+ const executeScripts = (window, document, scripts, width = 0, height = 0, devicePixelRatio = 1) => {
89805
89815
  exposeCanvasGlobals(window, document);
89806
89816
  const {
89807
89817
  globalGlobals,
89808
89818
  windowGlobals
89809
- } = getGlobals(width, height);
89819
+ } = getGlobals(width, height, devicePixelRatio);
89810
89820
  setGlobals(window, globalGlobals, windowGlobals);
89811
89821
  let firstError = null;
89812
89822
  let firstCodeFrame = '';
@@ -89918,6 +89928,9 @@ const toNumber = value => {
89918
89928
 
89919
89929
  /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
89920
89930
 
89931
+ const reflectCanvasDimensionAttribute = (element, name, value) => {
89932
+ element.setAttribute(name, String(value));
89933
+ };
89921
89934
  const patchCanvasElements = async (document, uid) => {
89922
89935
  const canvasElements = document.querySelectorAll('canvas');
89923
89936
  if (canvasElements.length === 0) {
@@ -89965,6 +89978,7 @@ const patchCanvasElements = async (document, uid) => {
89965
89978
  get: () => widthValue,
89966
89979
  set: newWidth => {
89967
89980
  widthValue = toNumber(newWidth);
89981
+ reflectCanvasDimensionAttribute(element, 'width', widthValue);
89968
89982
  // @ts-ignore
89969
89983
  element.__offscreenCanvas.width = widthValue;
89970
89984
  }
@@ -89978,6 +89992,7 @@ const patchCanvasElements = async (document, uid) => {
89978
89992
  get: () => heightValue,
89979
89993
  set: newHeight => {
89980
89994
  heightValue = toNumber(newHeight);
89995
+ reflectCanvasDimensionAttribute(element, 'height', heightValue);
89981
89996
  // @ts-ignore
89982
89997
  element.__offscreenCanvas.height = heightValue;
89983
89998
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/preview-sandbox-worker",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "Preview SandBox Worker",
5
5
  "repository": {
6
6
  "type": "git",