@lvce-editor/preview-sandbox-worker 2.3.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.
@@ -1583,7 +1583,7 @@ const dispatchClickEvent = (element, window, clientX = 0, clientY = 0) => {
1583
1583
  dispatchEvent(element, clickEvent);
1584
1584
  };
1585
1585
 
1586
- const handleClickLocal = (uid, hdId, clientX, clientY) => {
1586
+ const handleClickLocal = (uid, hdId, clientX, clientY, x, y) => {
1587
1587
  const happyDomInstance = get(uid);
1588
1588
  if (!happyDomInstance) {
1589
1589
  return;
@@ -1592,16 +1592,36 @@ const handleClickLocal = (uid, hdId, clientX, clientY) => {
1592
1592
  if (!element) {
1593
1593
  return;
1594
1594
  }
1595
- dispatchClickEvent(element, happyDomInstance.window, clientX, clientY);
1596
- const elementMap = Object.create(null);
1597
- set$1(uid, {
1598
- document: happyDomInstance.document,
1599
- elementMap,
1600
- 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
1601
1608
  });
1609
+ dispatchEvent(element, contextmenuEvent);
1610
+ };
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);
1602
1622
  };
1603
- const handleClick = (uid, hdId, clientX = 0, clientY = 0) => {
1604
- return handleClickLocal(uid, hdId, clientX, clientY);
1623
+ const handleContextmenu = (uid, hdId, clientX = 0, clientY = 0, x = 0, y = 0) => {
1624
+ return handleContextmenuLocal(uid, hdId, clientX, clientY, x, y);
1605
1625
  };
1606
1626
 
1607
1627
  const dispatchInputEvent = (element, window) => {
@@ -1725,6 +1745,30 @@ const handleMousedown = (uid, hdId, clientX, clientY) => {
1725
1745
  return handleMousedownLocal(uid, hdId, clientX, clientY);
1726
1746
  };
1727
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
+
1728
1772
  /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
1729
1773
 
1730
1774
  const dispatchMousemoveEvent = (element, window, clientX = 0, clientY = 0) => {
@@ -1753,6 +1797,54 @@ const handleMousemove = (uid, hdId, clientX, clientY, x, y) => {
1753
1797
  return handleMousemoveLocal(uid, hdId, clientX, clientY, x, y);
1754
1798
  };
1755
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
+
1756
1848
  const dispatchMouseupEvent = (element, window, clientX = 0, clientY = 0) => {
1757
1849
  const mouseupEvent = new window.MouseEvent('mouseup', {
1758
1850
  bubbles: true,
@@ -1777,6 +1869,161 @@ const handleMouseup = (uid, hdId, clientX, clientY) => {
1777
1869
  return handleMouseupLocal(uid, hdId, clientX, clientY);
1778
1870
  };
1779
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
+
1780
2027
  function getDefaultExportFromCjs (x) {
1781
2028
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
1782
2029
  }
@@ -89768,6 +90015,52 @@ const patchCanvasElements = async (document, uid) => {
89768
90015
  element.__offscreenCanvas.height = heightValue;
89769
90016
  }
89770
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
+ };
89771
90064
  instances.push({
89772
90065
  dataId,
89773
90066
  dimensions,
@@ -89793,6 +90086,7 @@ const updateContent = async (uid, width, height, content, scripts) => {
89793
90086
  error
89794
90087
  } = executeScripts(happyDomWindow, happyDomDocument, scripts, width, height);
89795
90088
  const elementMap = Object.create(null);
90089
+ serialize(happyDomDocument, elementMap);
89796
90090
  set$1(uid, {
89797
90091
  document: happyDomDocument,
89798
90092
  elementMap,
@@ -89845,13 +90139,22 @@ const commandMap = {
89845
90139
  'SandBox.executeCallback': executeCallback,
89846
90140
  'SandBox.getSerializedDom': getSerializedDom,
89847
90141
  'SandBox.handleClick': handleClick,
90142
+ 'SandBox.handleContextMenu': handleContextmenu,
89848
90143
  'SandBox.handleInput': handleInput,
89849
90144
  'SandBox.handleKeyDown': handleKeydown,
89850
90145
  'SandBox.handleKeyUp': handleKeyup,
89851
90146
  'SandBox.handleMessagePort': handleMessagePort,
89852
90147
  'SandBox.handleMousedown': handleMousedown,
90148
+ 'SandBox.handleMouseleave': handleMouseleave,
89853
90149
  'SandBox.handleMousemove': handleMousemove,
90150
+ 'SandBox.handleMouseout': handleMouseout,
90151
+ 'SandBox.handleMouseover': handleMouseover,
89854
90152
  'SandBox.handleMouseup': handleMouseup,
90153
+ 'SandBox.handlePointerdown': handlePointerdown,
90154
+ 'SandBox.handlePointermove': handlePointermove,
90155
+ 'SandBox.handlePointerout': handlePointerout,
90156
+ 'SandBox.handlePointerover': handlePointerover,
90157
+ 'SandBox.handlePointerup': handlePointerup,
89855
90158
  'SandBox.loadContent': loadContent,
89856
90159
  'SandBox.resize': resize,
89857
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.3.0",
3
+ "version": "3.0.0",
4
4
  "description": "Preview SandBox Worker",
5
5
  "repository": {
6
6
  "type": "git",