hyperbook 0.90.0 → 0.91.1

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.
@@ -3,6 +3,9 @@
3
3
  border-radius: 8px;
4
4
  background: #1e1e1e;
5
5
  overflow: hidden;
6
+ display: flex;
7
+ flex-direction: column;
8
+ height: var(--onlineide-height, calc(100dvh - 80px));
6
9
 
7
10
  .jo_iconButton.img_whole-window-dark {
8
11
  display: none;
@@ -15,6 +18,11 @@
15
18
  }
16
19
  }
17
20
 
21
+ .directive-onlineide .java-online {
22
+ flex: 1;
23
+ min-height: 0;
24
+ }
25
+
18
26
  .directive-onlineide .menu {
19
27
  display: flex;
20
28
  border-top: 1px solid var(--color-spacer);
@@ -27,7 +27,107 @@ hyperbook.p5 = (function () {
27
27
  return sketchCode;
28
28
  };
29
29
 
30
+ function setupSplitter(elem, container, editorContainer, splitter) {
31
+ if (!container || !editorContainer || !splitter) return;
32
+
33
+ const minPanelSize = 120;
34
+
35
+ const getIsHorizontal = () =>
36
+ getComputedStyle(elem).flexDirection.startsWith("row");
37
+
38
+ const applySplitSize = (rawSize, isHorizontal) => {
39
+ const total = isHorizontal ? elem.clientWidth : elem.clientHeight;
40
+ const splitterSize = isHorizontal ? splitter.offsetWidth : splitter.offsetHeight;
41
+ const maxSize = Math.max(minPanelSize, total - splitterSize - minPanelSize);
42
+ const clamped = Math.max(minPanelSize, Math.min(rawSize, maxSize));
43
+ container.style.flex = `0 0 ${clamped}px`;
44
+ return clamped;
45
+ };
46
+
47
+ const applyStoredSplitSize = () => {
48
+ const isHorizontal = getIsHorizontal();
49
+ elem.classList.toggle("split-horizontal", isHorizontal);
50
+ elem.classList.toggle("split-vertical", !isHorizontal);
51
+ const key = isHorizontal ? "splitHorizontal" : "splitVertical";
52
+ const rawStored = Number(elem.dataset[key]);
53
+ if (!Number.isFinite(rawStored) || rawStored <= 0) {
54
+ container.style.flex = "";
55
+ return;
56
+ }
57
+ applySplitSize(rawStored, isHorizontal);
58
+ };
59
+
60
+ applyStoredSplitSize();
61
+
62
+ splitter.addEventListener("pointerdown", (event) => {
63
+ event.preventDefault();
64
+ splitter.setPointerCapture(event.pointerId);
65
+
66
+ const isHorizontal = getIsHorizontal();
67
+ const key = isHorizontal ? "splitHorizontal" : "splitVertical";
68
+ const startPointer = isHorizontal ? event.clientX : event.clientY;
69
+ const startSize = isHorizontal
70
+ ? container.getBoundingClientRect().width
71
+ : container.getBoundingClientRect().height;
72
+
73
+ elem.classList.add("resizing");
74
+
75
+ const onPointerMove = (moveEvent) => {
76
+ const pointer = isHorizontal ? moveEvent.clientX : moveEvent.clientY;
77
+ const delta = pointer - startPointer;
78
+ const size = applySplitSize(startSize + delta, isHorizontal);
79
+ elem.dataset[key] = String(Math.round(size));
80
+ };
81
+
82
+ const onPointerUp = () => {
83
+ elem.classList.remove("resizing");
84
+ splitter.removeEventListener("pointermove", onPointerMove);
85
+ splitter.removeEventListener("pointerup", onPointerUp);
86
+ splitter.removeEventListener("pointercancel", onPointerUp);
87
+ };
88
+
89
+ splitter.addEventListener("pointermove", onPointerMove);
90
+ splitter.addEventListener("pointerup", onPointerUp);
91
+ splitter.addEventListener("pointercancel", onPointerUp);
92
+ });
93
+
94
+ window.addEventListener("resize", applyStoredSplitSize);
95
+ }
96
+
97
+ const updateFullscreenButtonState = (elem, button) => {
98
+ if (!elem || !button) return;
99
+ const isFullscreen = document.fullscreenElement === elem;
100
+ const label = hyperbook.i18n.get("ide-fullscreen-enter");
101
+ button.textContent = "⛶";
102
+ button.title = label;
103
+ button.setAttribute("aria-label", label);
104
+ button.classList.toggle("active", isFullscreen);
105
+ };
106
+
107
+ const toggleFullscreen = async (elem) => {
108
+ if (!elem) return;
109
+ if (document.fullscreenElement === elem) {
110
+ await document.exitFullscreen();
111
+ return;
112
+ }
113
+ await elem.requestFullscreen();
114
+ };
115
+
116
+ const syncFullscreenButtons = () => {
117
+ const elems = document.querySelectorAll(".directive-p5");
118
+ elems.forEach((elem) => {
119
+ const fullscreen = elem.querySelector("button.fullscreen");
120
+ updateFullscreenButtonState(elem, fullscreen);
121
+ });
122
+ };
123
+
30
124
  function initElement(elem) {
125
+ if (elem.getAttribute("data-p5-initialized") === "true") return;
126
+ elem.setAttribute("data-p5-initialized", "true");
127
+
128
+ const container = elem.querySelector(".container");
129
+ const editorContainer = elem.querySelector(".editor-container");
130
+ const splitter = elem.querySelector(".splitter");
31
131
  const editor = elem.getElementsByClassName("editor")[0];
32
132
  /** @type {HTMLButtonElement} */
33
133
  const update = elem.getElementsByClassName("update")[0];
@@ -37,6 +137,18 @@ hyperbook.p5 = (function () {
37
137
  const copyEl = elem.getElementsByClassName("copy")[0];
38
138
  const resetEl = elem.getElementsByClassName("reset")[0];
39
139
  const downloadEl = elem.getElementsByClassName("download")[0];
140
+ const fullscreenEl = elem.getElementsByClassName("fullscreen")[0];
141
+
142
+ setupSplitter(elem, container, editorContainer, splitter);
143
+
144
+ fullscreenEl?.addEventListener("click", async () => {
145
+ try {
146
+ await toggleFullscreen(elem);
147
+ } catch (error) {
148
+ console.error(error.message);
149
+ }
150
+ });
151
+ updateFullscreenButtonState(elem, fullscreenEl);
40
152
 
41
153
  if (frame) {
42
154
  frame.srcdoc = frame.srcdoc.replaceAll(
@@ -117,6 +229,7 @@ hyperbook.p5 = (function () {
117
229
  });
118
230
 
119
231
  observer.observe(document.body, { childList: true, subtree: true });
232
+ document.addEventListener("fullscreenchange", syncFullscreenButtons);
120
233
 
121
234
  return { init };
122
235
  })();
@@ -13,6 +13,8 @@ code-input {
13
13
 
14
14
  .directive-p5 .container {
15
15
  width: 100%;
16
+ min-height: 120px;
17
+ min-width: 120px;
16
18
  border: 1px solid var(--color-spacer);
17
19
  border-radius: 8px;
18
20
  overflow: hidden;
@@ -22,7 +24,50 @@ code-input {
22
24
  width: 100%;
23
25
  display: flex;
24
26
  flex-direction: column;
25
- height: 400px;
27
+ min-height: 120px;
28
+ min-width: 120px;
29
+ flex: 1 1 0;
30
+ }
31
+
32
+ .directive-p5:not(.standalone) {
33
+ height: var(--p5-height, calc(100dvh - 80px));
34
+ }
35
+
36
+ .directive-p5:not(.standalone) .container {
37
+ flex: 1 1 0;
38
+ }
39
+
40
+ .directive-p5 .splitter {
41
+ background: var(--color-spacer);
42
+ border-radius: 999px;
43
+ flex-shrink: 0;
44
+ touch-action: none;
45
+ opacity: 0.45;
46
+ transition: opacity 0.15s ease-in-out;
47
+ }
48
+
49
+ .directive-p5 .splitter:hover {
50
+ opacity: 0.65;
51
+ }
52
+
53
+ .directive-p5.split-vertical .splitter {
54
+ width: 100%;
55
+ height: 4px;
56
+ cursor: row-resize;
57
+ }
58
+
59
+ .directive-p5.split-horizontal .splitter {
60
+ width: 4px;
61
+ height: 100%;
62
+ cursor: col-resize;
63
+ }
64
+
65
+ .directive-p5.resizing {
66
+ user-select: none;
67
+ }
68
+
69
+ .directive-p5.resizing .splitter {
70
+ opacity: 0.75;
26
71
  }
27
72
 
28
73
  .directive-p5 .editor {
@@ -38,6 +83,7 @@ code-input {
38
83
  border-bottom: none;
39
84
  border-bottom-left-radius: 0;
40
85
  border-bottom-right-radius: 0;
86
+ overflow: hidden;
41
87
  }
42
88
 
43
89
  .directive-p5 .buttons.bottom {
@@ -58,10 +104,17 @@ code-input {
58
104
  cursor: pointer;
59
105
  }
60
106
 
61
- .directive-p5 .buttons:last-child {
107
+ .directive-p5 .buttons button:last-child {
62
108
  border-right: none;
63
109
  }
64
110
 
111
+ .directive-p5 button.fullscreen {
112
+ flex: 0 0 auto;
113
+ min-width: 42px;
114
+ width: 42px;
115
+ padding: 8px 0;
116
+ }
117
+
65
118
  .directive-p5 button:hover {
66
119
  background-color: var(--color-spacer);
67
120
  }
@@ -76,10 +129,21 @@ code-input {
76
129
  margin: 0 auto;
77
130
  }
78
131
 
132
+ .directive-p5:fullscreen {
133
+ width: 100vw;
134
+ height: 100dvh !important;
135
+ padding: 12px;
136
+ box-sizing: border-box;
137
+ background-color: var(--color-background, var(--color--background, #fff));
138
+ }
139
+
140
+ .directive-p5:fullscreen::backdrop {
141
+ background-color: var(--color-background, var(--color--background, #fff));
142
+ }
143
+
79
144
  @media screen and (min-width: 1024px) {
80
145
  .directive-p5:not(.standalone) {
81
146
  flex-direction: row;
82
- height: calc(100dvh - 128px);
83
147
  .container {
84
148
  flex: 1;
85
149
  height: 100% !important;