ewvjs 1.0.13 → 1.0.14

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