@lvce-editor/preview-sandbox-worker 2.2.0 → 3.0.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.
@@ -1066,6 +1066,7 @@ const Span$1 = 8;
1066
1066
  const Table$1 = 9;
1067
1067
  const TBody$1 = 10;
1068
1068
  const Td$1 = 11;
1069
+ const Text = 12;
1069
1070
  const Th$1 = 13;
1070
1071
  const THead$1 = 14;
1071
1072
  const Tr$1 = 15;
@@ -1177,8 +1178,6 @@ const set$1 = (uid, instance) => {
1177
1178
  states$1.set(uid, instance);
1178
1179
  };
1179
1180
 
1180
- const Text = 12;
1181
-
1182
1181
  const text = data => {
1183
1182
  return {
1184
1183
  childCount: 0,
@@ -1584,7 +1583,7 @@ const dispatchClickEvent = (element, window, clientX = 0, clientY = 0) => {
1584
1583
  dispatchEvent(element, clickEvent);
1585
1584
  };
1586
1585
 
1587
- const handleClickLocal = (uid, hdId, clientX, clientY) => {
1586
+ const handleClickLocal = (uid, hdId, clientX, clientY, x, y) => {
1588
1587
  const happyDomInstance = get(uid);
1589
1588
  if (!happyDomInstance) {
1590
1589
  return;
@@ -1593,16 +1592,36 @@ const handleClickLocal = (uid, hdId, clientX, clientY) => {
1593
1592
  if (!element) {
1594
1593
  return;
1595
1594
  }
1596
- dispatchClickEvent(element, happyDomInstance.window, clientX, clientY);
1597
- const elementMap = Object.create(null);
1598
- set$1(uid, {
1599
- document: happyDomInstance.document,
1600
- elementMap,
1601
- window: happyDomInstance.window
1595
+ const adjustedClientX = clientX - x;
1596
+ const adjustedClientY = clientY - y;
1597
+ dispatchClickEvent(element, happyDomInstance.window, adjustedClientX, adjustedClientY);
1598
+ };
1599
+ const handleClick = (uid, hdId, clientX = 0, clientY = 0, x = 0, y = 0) => {
1600
+ return handleClickLocal(uid, hdId, clientX, clientY, x, y);
1601
+ };
1602
+
1603
+ const dispatchContextmenuEvent = (element, window, clientX = 0, clientY = 0) => {
1604
+ const contextmenuEvent = new window.MouseEvent('contextmenu', {
1605
+ bubbles: true,
1606
+ clientX,
1607
+ clientY
1602
1608
  });
1609
+ dispatchEvent(element, contextmenuEvent);
1603
1610
  };
1604
- const handleClick = (uid, hdId, clientX = 0, clientY = 0) => {
1605
- return handleClickLocal(uid, hdId, clientX, clientY);
1611
+
1612
+ const handleContextmenuLocal = (uid, hdId, clientX, clientY, x, y) => {
1613
+ const happyDomInstance = get(uid);
1614
+ if (!happyDomInstance) {
1615
+ return;
1616
+ }
1617
+ const element = happyDomInstance.elementMap[hdId];
1618
+ if (!element) {
1619
+ return;
1620
+ }
1621
+ dispatchContextmenuEvent(element, happyDomInstance.window, clientX - x, clientY - y);
1622
+ };
1623
+ const handleContextmenu = (uid, hdId, clientX = 0, clientY = 0, x = 0, y = 0) => {
1624
+ return handleContextmenuLocal(uid, hdId, clientX, clientY, x, y);
1606
1625
  };
1607
1626
 
1608
1627
  const dispatchInputEvent = (element, window) => {
@@ -1726,6 +1745,30 @@ const handleMousedown = (uid, hdId, clientX, clientY) => {
1726
1745
  return handleMousedownLocal(uid, hdId, clientX, clientY);
1727
1746
  };
1728
1747
 
1748
+ const dispatchMouseleaveEvent = (element, window, clientX = 0, clientY = 0) => {
1749
+ const mouseleaveEvent = new window.MouseEvent('mouseleave', {
1750
+ bubbles: false,
1751
+ clientX,
1752
+ clientY
1753
+ });
1754
+ dispatchEvent(element, mouseleaveEvent);
1755
+ };
1756
+
1757
+ const handleMouseleaveLocal = (uid, hdId, clientX, clientY, x, y) => {
1758
+ const happyDomInstance = get(uid);
1759
+ if (!happyDomInstance) {
1760
+ return;
1761
+ }
1762
+ const element = happyDomInstance.elementMap[hdId];
1763
+ if (!element) {
1764
+ return;
1765
+ }
1766
+ dispatchMouseleaveEvent(element, happyDomInstance.window, clientX - x, clientY - y);
1767
+ };
1768
+ const handleMouseleave = (uid, hdId, clientX = 0, clientY = 0, x = 0, y = 0) => {
1769
+ return handleMouseleaveLocal(uid, hdId, clientX, clientY, x, y);
1770
+ };
1771
+
1729
1772
  /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
1730
1773
 
1731
1774
  const dispatchMousemoveEvent = (element, window, clientX = 0, clientY = 0) => {
@@ -1754,6 +1797,54 @@ const handleMousemove = (uid, hdId, clientX, clientY, x, y) => {
1754
1797
  return handleMousemoveLocal(uid, hdId, clientX, clientY, x, y);
1755
1798
  };
1756
1799
 
1800
+ const dispatchMouseoutEvent = (element, window, clientX = 0, clientY = 0) => {
1801
+ const mouseoutEvent = new window.MouseEvent('mouseout', {
1802
+ bubbles: true,
1803
+ clientX,
1804
+ clientY
1805
+ });
1806
+ dispatchEvent(element, mouseoutEvent);
1807
+ };
1808
+
1809
+ const handleMouseoutLocal = (uid, hdId, clientX, clientY, x, y) => {
1810
+ const happyDomInstance = get(uid);
1811
+ if (!happyDomInstance) {
1812
+ return;
1813
+ }
1814
+ const element = happyDomInstance.elementMap[hdId];
1815
+ if (!element) {
1816
+ return;
1817
+ }
1818
+ dispatchMouseoutEvent(element, happyDomInstance.window, clientX - x, clientY - y);
1819
+ };
1820
+ const handleMouseout = (uid, hdId, clientX = 0, clientY = 0, x = 0, y = 0) => {
1821
+ return handleMouseoutLocal(uid, hdId, clientX, clientY, x, y);
1822
+ };
1823
+
1824
+ const dispatchMouseoverEvent = (element, window, clientX = 0, clientY = 0) => {
1825
+ const mouseoverEvent = new window.MouseEvent('mouseover', {
1826
+ bubbles: true,
1827
+ clientX,
1828
+ clientY
1829
+ });
1830
+ dispatchEvent(element, mouseoverEvent);
1831
+ };
1832
+
1833
+ const handleMouseoverLocal = (uid, hdId, clientX, clientY, x, y) => {
1834
+ const happyDomInstance = get(uid);
1835
+ if (!happyDomInstance) {
1836
+ return;
1837
+ }
1838
+ const element = happyDomInstance.elementMap[hdId];
1839
+ if (!element) {
1840
+ return;
1841
+ }
1842
+ dispatchMouseoverEvent(element, happyDomInstance.window, clientX - x, clientY - y);
1843
+ };
1844
+ const handleMouseover = (uid, hdId, clientX = 0, clientY = 0, x = 0, y = 0) => {
1845
+ return handleMouseoverLocal(uid, hdId, clientX, clientY, x, y);
1846
+ };
1847
+
1757
1848
  const dispatchMouseupEvent = (element, window, clientX = 0, clientY = 0) => {
1758
1849
  const mouseupEvent = new window.MouseEvent('mouseup', {
1759
1850
  bubbles: true,
@@ -1778,6 +1869,161 @@ const handleMouseup = (uid, hdId, clientX, clientY) => {
1778
1869
  return handleMouseupLocal(uid, hdId, clientX, clientY);
1779
1870
  };
1780
1871
 
1872
+ const getPointerEventConstructor$4 = window => {
1873
+ return window.PointerEvent || window.MouseEvent;
1874
+ };
1875
+ const dispatchPointerdownEvent = (element, window, clientX = 0, clientY = 0) => {
1876
+ const PointerEventConstructor = getPointerEventConstructor$4(window);
1877
+ const pointerdownEvent = new PointerEventConstructor('pointerdown', {
1878
+ bubbles: true,
1879
+ clientX,
1880
+ clientY,
1881
+ isPrimary: true,
1882
+ pointerId: 1,
1883
+ pointerType: 'mouse'
1884
+ });
1885
+ dispatchEvent(element, pointerdownEvent);
1886
+ };
1887
+
1888
+ const handlePointerdownLocal = (uid, hdId, clientX, clientY, x, y) => {
1889
+ const happyDomInstance = get(uid);
1890
+ if (!happyDomInstance) {
1891
+ return;
1892
+ }
1893
+ const element = happyDomInstance.elementMap[hdId];
1894
+ if (!element) {
1895
+ return;
1896
+ }
1897
+ dispatchPointerdownEvent(element, happyDomInstance.window, clientX - x, clientY - y);
1898
+ };
1899
+ const handlePointerdown = (uid, hdId, clientX = 0, clientY = 0, x = 0, y = 0) => {
1900
+ return handlePointerdownLocal(uid, hdId, clientX, clientY, x, y);
1901
+ };
1902
+
1903
+ const getPointerEventConstructor$3 = window => {
1904
+ return window.PointerEvent || window.MouseEvent;
1905
+ };
1906
+ const dispatchPointermoveEvent = (element, window, clientX = 0, clientY = 0) => {
1907
+ const PointerEventConstructor = getPointerEventConstructor$3(window);
1908
+ const pointermoveEvent = new PointerEventConstructor('pointermove', {
1909
+ bubbles: true,
1910
+ clientX,
1911
+ clientY,
1912
+ isPrimary: true,
1913
+ pointerId: 1,
1914
+ pointerType: 'mouse'
1915
+ });
1916
+ dispatchEvent(element, pointermoveEvent);
1917
+ };
1918
+
1919
+ const handlePointermoveLocal = (uid, hdId, clientX, clientY, x, y) => {
1920
+ const happyDomInstance = get(uid);
1921
+ if (!happyDomInstance) {
1922
+ return;
1923
+ }
1924
+ const element = happyDomInstance.elementMap[hdId];
1925
+ if (!element) {
1926
+ return;
1927
+ }
1928
+ dispatchPointermoveEvent(element, happyDomInstance.window, clientX - x, clientY - y);
1929
+ };
1930
+ const handlePointermove = (uid, hdId, clientX = 0, clientY = 0, x = 0, y = 0) => {
1931
+ return handlePointermoveLocal(uid, hdId, clientX, clientY, x, y);
1932
+ };
1933
+
1934
+ const getPointerEventConstructor$2 = window => {
1935
+ return window.PointerEvent || window.MouseEvent;
1936
+ };
1937
+ const dispatchPointeroutEvent = (element, window, clientX = 0, clientY = 0) => {
1938
+ const PointerEventConstructor = getPointerEventConstructor$2(window);
1939
+ const pointeroutEvent = new PointerEventConstructor('pointerout', {
1940
+ bubbles: true,
1941
+ clientX,
1942
+ clientY,
1943
+ isPrimary: true,
1944
+ pointerId: 1,
1945
+ pointerType: 'mouse'
1946
+ });
1947
+ dispatchEvent(element, pointeroutEvent);
1948
+ };
1949
+
1950
+ const handlePointeroutLocal = (uid, hdId, clientX, clientY, x, y) => {
1951
+ const happyDomInstance = get(uid);
1952
+ if (!happyDomInstance) {
1953
+ return;
1954
+ }
1955
+ const element = happyDomInstance.elementMap[hdId];
1956
+ if (!element) {
1957
+ return;
1958
+ }
1959
+ dispatchPointeroutEvent(element, happyDomInstance.window, clientX - x, clientY - y);
1960
+ };
1961
+ const handlePointerout = (uid, hdId, clientX = 0, clientY = 0, x = 0, y = 0) => {
1962
+ return handlePointeroutLocal(uid, hdId, clientX, clientY, x, y);
1963
+ };
1964
+
1965
+ const getPointerEventConstructor$1 = window => {
1966
+ return window.PointerEvent || window.MouseEvent;
1967
+ };
1968
+ const dispatchPointeroverEvent = (element, window, clientX = 0, clientY = 0) => {
1969
+ const PointerEventConstructor = getPointerEventConstructor$1(window);
1970
+ const pointeroverEvent = new PointerEventConstructor('pointerover', {
1971
+ bubbles: true,
1972
+ clientX,
1973
+ clientY,
1974
+ isPrimary: true,
1975
+ pointerId: 1,
1976
+ pointerType: 'mouse'
1977
+ });
1978
+ dispatchEvent(element, pointeroverEvent);
1979
+ };
1980
+
1981
+ const handlePointeroverLocal = (uid, hdId, clientX, clientY, x, y) => {
1982
+ const happyDomInstance = get(uid);
1983
+ if (!happyDomInstance) {
1984
+ return;
1985
+ }
1986
+ const element = happyDomInstance.elementMap[hdId];
1987
+ if (!element) {
1988
+ return;
1989
+ }
1990
+ dispatchPointeroverEvent(element, happyDomInstance.window, clientX - x, clientY - y);
1991
+ };
1992
+ const handlePointerover = (uid, hdId, clientX = 0, clientY = 0, x = 0, y = 0) => {
1993
+ return handlePointeroverLocal(uid, hdId, clientX, clientY, x, y);
1994
+ };
1995
+
1996
+ const getPointerEventConstructor = window => {
1997
+ return window.PointerEvent || window.MouseEvent;
1998
+ };
1999
+ const dispatchPointerupEvent = (element, window, clientX = 0, clientY = 0) => {
2000
+ const PointerEventConstructor = getPointerEventConstructor(window);
2001
+ const pointerupEvent = new PointerEventConstructor('pointerup', {
2002
+ bubbles: true,
2003
+ clientX,
2004
+ clientY,
2005
+ isPrimary: true,
2006
+ pointerId: 1,
2007
+ pointerType: 'mouse'
2008
+ });
2009
+ dispatchEvent(element, pointerupEvent);
2010
+ };
2011
+
2012
+ const handlePointerupLocal = (uid, hdId, clientX, clientY, x, y) => {
2013
+ const happyDomInstance = get(uid);
2014
+ if (!happyDomInstance) {
2015
+ return;
2016
+ }
2017
+ const element = happyDomInstance.elementMap[hdId];
2018
+ if (!element) {
2019
+ return;
2020
+ }
2021
+ dispatchPointerupEvent(element, happyDomInstance.window, clientX - x, clientY - y);
2022
+ };
2023
+ const handlePointerup = (uid, hdId, clientX = 0, clientY = 0, x = 0, y = 0) => {
2024
+ return handlePointerupLocal(uid, hdId, clientX, clientY, x, y);
2025
+ };
2026
+
1781
2027
  function getDefaultExportFromCjs (x) {
1782
2028
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
1783
2029
  }
@@ -89769,6 +90015,52 @@ const patchCanvasElements = async (document, uid) => {
89769
90015
  element.__offscreenCanvas.height = heightValue;
89770
90016
  }
89771
90017
  });
90018
+ Object.defineProperty(element, 'clientWidth', {
90019
+ configurable: true,
90020
+ enumerable: true,
90021
+ get: () => widthValue
90022
+ });
90023
+ Object.defineProperty(element, 'clientHeight', {
90024
+ configurable: true,
90025
+ enumerable: true,
90026
+ get: () => heightValue
90027
+ });
90028
+ Object.defineProperty(element, 'offsetWidth', {
90029
+ configurable: true,
90030
+ enumerable: true,
90031
+ get: () => widthValue
90032
+ });
90033
+ Object.defineProperty(element, 'offsetHeight', {
90034
+ configurable: true,
90035
+ enumerable: true,
90036
+ get: () => heightValue
90037
+ });
90038
+
90039
+ // @ts-ignore
90040
+ element.getBoundingClientRect = () => {
90041
+ return {
90042
+ bottom: heightValue,
90043
+ height: heightValue,
90044
+ left: 0,
90045
+ right: widthValue,
90046
+ toJSON: () => {
90047
+ return {
90048
+ bottom: heightValue,
90049
+ height: heightValue,
90050
+ left: 0,
90051
+ right: widthValue,
90052
+ top: 0,
90053
+ width: widthValue,
90054
+ x: 0,
90055
+ y: 0
90056
+ };
90057
+ },
90058
+ top: 0,
90059
+ width: widthValue,
90060
+ x: 0,
90061
+ y: 0
90062
+ };
90063
+ };
89772
90064
  instances.push({
89773
90065
  dataId,
89774
90066
  dimensions,
@@ -89794,6 +90086,7 @@ const updateContent = async (uid, width, height, content, scripts) => {
89794
90086
  error
89795
90087
  } = executeScripts(happyDomWindow, happyDomDocument, scripts, width, height);
89796
90088
  const elementMap = Object.create(null);
90089
+ serialize(happyDomDocument, elementMap);
89797
90090
  set$1(uid, {
89798
90091
  document: happyDomDocument,
89799
90092
  elementMap,
@@ -89846,13 +90139,22 @@ const commandMap = {
89846
90139
  'SandBox.executeCallback': executeCallback,
89847
90140
  'SandBox.getSerializedDom': getSerializedDom,
89848
90141
  'SandBox.handleClick': handleClick,
90142
+ 'SandBox.handleContextMenu': handleContextmenu,
89849
90143
  'SandBox.handleInput': handleInput,
89850
90144
  'SandBox.handleKeyDown': handleKeydown,
89851
90145
  'SandBox.handleKeyUp': handleKeyup,
89852
90146
  'SandBox.handleMessagePort': handleMessagePort,
89853
90147
  'SandBox.handleMousedown': handleMousedown,
90148
+ 'SandBox.handleMouseleave': handleMouseleave,
89854
90149
  'SandBox.handleMousemove': handleMousemove,
90150
+ 'SandBox.handleMouseout': handleMouseout,
90151
+ 'SandBox.handleMouseover': handleMouseover,
89855
90152
  'SandBox.handleMouseup': handleMouseup,
90153
+ 'SandBox.handlePointerdown': handlePointerdown,
90154
+ 'SandBox.handlePointermove': handlePointermove,
90155
+ 'SandBox.handlePointerout': handlePointerout,
90156
+ 'SandBox.handlePointerover': handlePointerover,
90157
+ 'SandBox.handlePointerup': handlePointerup,
89856
90158
  'SandBox.loadContent': loadContent,
89857
90159
  'SandBox.resize': resize,
89858
90160
  'SandBox.terminate': terminate
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/preview-sandbox-worker",
3
- "version": "2.2.0",
3
+ "version": "3.0.0",
4
4
  "description": "Preview SandBox Worker",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,9 +9,5 @@
9
9
  "license": "MIT",
10
10
  "author": "Lvce Editor",
11
11
  "type": "module",
12
- "main": "dist/previewSandBoxWorkerMain.js",
13
- "dependencies": {
14
- "@lvce-editor/virtual-dom-worker": "^8.9.0",
15
- "happy-dom-without-node": "^14.12.3"
16
- }
12
+ "main": "dist/previewSandBoxWorkerMain.js"
17
13
  }