ewvjs 1.0.13 → 1.0.15

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/js/api.js CHANGED
@@ -6,15 +6,116 @@ window.ewvjs = {
6
6
  _returnValuesCallbacks: {},
7
7
 
8
8
  _hookDrag: function () {
9
+ var lastClickTime = 0;
9
10
  window.addEventListener('mousedown', function (e) {
11
+ if (e.target.closest('.ewvjs-no-drag-region')) {
12
+ return;
13
+ }
10
14
  if (e.target.classList.contains('ewvjs-drag-region') || e.target.closest('.ewvjs-drag-region')) {
11
15
  if (e.button === 0) { // Left click
12
- window.chrome.webview.postMessage("drag");
16
+ var now = e.timeStamp;
17
+ if (now - lastClickTime < 200) {
18
+ if (window.__isWindowMaximized) {
19
+ window.restore();
20
+ } else {
21
+ window.maximize();
22
+ }
23
+ lastClickTime = 0;
24
+ } else {
25
+ window.chrome.webview.postMessage("drag");
26
+ lastClickTime = now;
27
+ }
13
28
  }
14
29
  }
15
30
  });
16
31
  },
17
32
 
33
+ _hookResize: function () {
34
+ var resizeBorder = 8;
35
+ var styleEl = null;
36
+
37
+ function getDirection(e) {
38
+ if (!window.__isTitleBarDisabled || window.__isWindowMaximized) return null;
39
+
40
+ var x = e.clientX;
41
+ var y = e.clientY;
42
+ var w = window.innerWidth;
43
+ var h = window.innerHeight;
44
+
45
+ var onLeft = x < resizeBorder;
46
+ var onRight = x > w - resizeBorder;
47
+ var onTop = y < resizeBorder;
48
+ var onBottom = y > h - resizeBorder;
49
+
50
+ if (onTop && onLeft) return "topleft";
51
+ if (onTop && onRight) return "topright";
52
+ if (onBottom && onLeft) return "bottomleft";
53
+ if (onBottom && onRight) return "bottomright";
54
+ if (onTop) return "top";
55
+ if (onBottom) return "bottom";
56
+ if (onLeft) return "left";
57
+ if (onRight) return "right";
58
+ return null;
59
+ }
60
+
61
+ function setOverrideCursor(cursor) {
62
+ if (!styleEl) {
63
+ styleEl = document.getElementById("ewvjs-cursor-override-style");
64
+ if (!styleEl) {
65
+ styleEl = document.createElement("style");
66
+ styleEl.id = "ewvjs-cursor-override-style";
67
+ styleEl.type = "text/css";
68
+ (document.head || document.documentElement).appendChild(styleEl);
69
+ }
70
+ }
71
+ var css = "* { cursor: " + cursor + " !important; }";
72
+ if (styleEl.textContent !== css) {
73
+ styleEl.textContent = css;
74
+ }
75
+ if (document.documentElement.style.getPropertyValue("cursor") !== cursor) {
76
+ document.documentElement.style.setProperty("cursor", cursor, "important");
77
+ }
78
+ }
79
+
80
+ function clearOverrideCursor() {
81
+ if (styleEl) {
82
+ styleEl.textContent = "";
83
+ } else {
84
+ var el = document.getElementById("ewvjs-cursor-override-style");
85
+ if (el) {
86
+ el.textContent = "";
87
+ }
88
+ }
89
+ if (document.documentElement.style.getPropertyValue("cursor")) {
90
+ document.documentElement.style.removeProperty("cursor");
91
+ }
92
+ }
93
+
94
+ window.addEventListener('mousemove', function (e) {
95
+ var dir = getDirection(e);
96
+ if (dir) {
97
+ var cursor = "";
98
+ if (dir === "top" || dir === "bottom") cursor = "ns-resize";
99
+ else if (dir === "left" || dir === "right") cursor = "ew-resize";
100
+ else if (dir === "topleft" || dir === "bottomright") cursor = "nwse-resize";
101
+ else if (dir === "topright" || dir === "bottomleft") cursor = "nesw-resize";
102
+
103
+ setOverrideCursor(cursor);
104
+ } else {
105
+ clearOverrideCursor();
106
+ }
107
+ }, true);
108
+
109
+ window.addEventListener('mousedown', function (e) {
110
+ var dir = getDirection(e);
111
+ if (dir && e.button === 0) {
112
+ e.preventDefault();
113
+ e.stopPropagation();
114
+ window.chrome.webview.postMessage("resize:" + dir);
115
+ }
116
+ }, true);
117
+ },
118
+
18
119
  _createApi: function (funcList) {
19
120
  function sanitize_params(params) {
20
121
  var reservedWords = [
@@ -263,6 +364,7 @@ window.ewvjs._hookConsole = function () {
263
364
 
264
365
  window.ewvjs._hookConsole();
265
366
  window.ewvjs._hookDrag();
367
+ window.ewvjs._hookResize();
266
368
 
267
369
  // Add window state methods directly to window object
268
370
  window.close = function () {
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ewvjs",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "Embedded WebView for JavaScript - Edge WebView2 bindings for Node.js",
5
5
  "workspaces": [
6
6
  "packages/*"