f_dot 0.0.2 → 0.0.3

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.
@@ -9,12 +9,29 @@
9
9
 
10
10
  import * as f_dot_canvas from "./canvas.js"
11
11
 
12
+ const fDotLinks = [
13
+ "f_dot",
14
+ "projector_link",
15
+ "editor_link",
16
+ "history_link",
17
+ ]
18
+
19
+ var fDotLinkClickListener;
20
+
12
21
  var ws;
13
22
  var connectDelay = 4444;
14
23
  var autoReconnect = true;
15
24
  var connectTimer = null;
16
- var counter = 0;
17
25
  var lastMessageWasTimeout = false;
26
+ var singleInputMode = false;
27
+ var linkBaton = "f_dot";
28
+ var submitProjectionMovementTimeout;
29
+ var submitCameraMovementTimeout;
30
+ var projectionMovement = {
31
+ x: 0,
32
+ y: 0,
33
+ z: 0
34
+ };
18
35
 
19
36
  function escapeHtml(unsafe) {
20
37
  return String(unsafe ?? '')
@@ -25,8 +42,61 @@ function escapeHtml(unsafe) {
25
42
  .replace(/'/g, ''');
26
43
  }
27
44
 
45
+ function scrollDisplayIntoView() {
46
+ setTimeout(function() {
47
+ document.getElementById('display').scrollIntoView({
48
+ block: "end"
49
+ });
50
+ }, 111);
51
+ }
52
+
28
53
  function sendControl(event) {
29
- ws.send(JSON.stringify({"uuid": event.target.getAttribute("id")})+"\n");
54
+ if (singleInputMode) {
55
+ submitSingleInput(event);
56
+ } else {
57
+ ws.send(JSON.stringify({"uuid": event.target.getAttribute("id")})+"\n");
58
+ }
59
+ }
60
+
61
+ function submitSingleInput(event) {
62
+ ws.send(JSON.stringify({"uuid": event.target.getAttribute("id"), "new_value": event.target.value})+"\n");
63
+ }
64
+
65
+ function submitProjectionMovement() {
66
+ if (!isProjecting()) {
67
+ console.error("cannot submit projection movement from here!");
68
+ return;
69
+ }
70
+
71
+ if (submitProjectionMovementTimeout) {
72
+ clearTimeout(submitProjectionMovementTimeout);
73
+ }
74
+ submitProjectionMovementTimeout = setTimeout(function() {
75
+ console.info("submitProjectionMovement:", projectionMovement);
76
+ ws.send(JSON.stringify({"uuid": f_dot_canvas.projectedFrom()["uuid"], "position": projectionMovement})+"\n");
77
+ }, 111);
78
+ }
79
+
80
+ function submitCameraMovement(cameraPosition, cameraRotation) {
81
+ if (!isProjecting()) {
82
+ console.error("cannot submit projection movement from here!");
83
+ return;
84
+ }
85
+
86
+ if (submitCameraMovementTimeout) {
87
+ clearTimeout(submitCameraMovementTimeout);
88
+ }
89
+ submitCameraMovementTimeout = setTimeout(function() {
90
+ console.info("submitCameraMovement:", cameraPosition);
91
+ ws.send(JSON.stringify({
92
+ "position": {x: cameraPosition.x, y: cameraPosition.y, z: cameraPosition.z},
93
+ "rotation": {x: cameraRotation.x, y: cameraRotation.y, z: cameraRotation.z},
94
+ })+"\n");
95
+ }, 111);
96
+ }
97
+
98
+ function isProjecting() {
99
+ return document.getElementById('projector_link').className.includes("baton");
30
100
  }
31
101
 
32
102
  function onclose(event) {
@@ -92,46 +162,59 @@ function onmessage(event) {
92
162
  return; // Don't log as regular message
93
163
  }
94
164
 
95
- console.log("event_data", event.data);
165
+ if (typeof event.data !== "string" || event.data.length == 0) {
166
+ return;
167
+ }
96
168
  // rely on json parser exception
97
169
  try {
98
- // if pars-able, it is implicitly controls
170
+ // if pars-able, it is implicitly controls or canvas
99
171
  var parsed = JSON.parse(event.data);
100
- var controlsHtml = "";
101
- for(i = 0; i < parsed.length; i++) {
102
- if (typeof parsed[i].type !== "undefined") {
103
- // value input
104
- switch(parsed[i].type) {
105
- case "text":
106
- controlsHtml = controlsHtml + `<input id="${parsed[i].uuid}" type="${parsed[i].type}" placeholder="enter value for ${escapeHtml(parsed[i].name)}"></input>`
107
- break;
108
- default:
109
- break;
110
- }
111
-
112
- } else {
113
- // default menu options
114
- controlsHtml = controlsHtml + `<button id="${parsed[i].uuid}"><pre>${escapeHtml(parsed[i].name)}</pre></button>`;
115
- }
172
+ if (Array.isArray(parsed)) {
173
+ // if array, controls
174
+ document.getElementById('controls').innerHTML = generateControls(parsed);
175
+ } else {
176
+ // if object, canvas
177
+ document.getElementById('projector_link').click();
178
+ f_dot_canvas.load(parsed, submitCameraMovement);
179
+ projectionMovement = f_dot_canvas.projectedFrom()["position"]
180
+ clearControlsBaton();
116
181
  }
117
- document.getElementById('controls').innerHTML = controlsHtml;
118
182
 
119
183
  var buttons = document.getElementById("controls").children; // HTMLCollection
120
184
  for (var i = 0; i < buttons.length; i++) {
121
- buttons.item(i).addEventListener("click", sendControl);
185
+ var htmlEl = buttons.item(i)
186
+ switch(htmlEl.tagName) {
187
+ case "BUTTON":
188
+ htmlEl.addEventListener("click", sendControl);
189
+ break;
190
+ case "INPUT":
191
+ htmlEl.addEventListener("keydown", onSingleInputKeydown);
192
+ htmlEl.focus();
193
+ break;
194
+ default:
195
+ break;
196
+ }
197
+ }
198
+ if (isProjecting()) {
199
+ clearControlsBaton();
200
+ } else {
201
+ moveBaton();
122
202
  }
123
- moveBaton();
124
203
  } catch (error) {
125
- // otherwise assume display
126
- var node = document.createElement("div");
127
- node.className = "display_text";
128
- node.textContent = event.data;
129
- document.getElementById('display').appendChild(node);
130
- setTimeout(function() {
131
- document.getElementById('display').scrollIntoView({
132
- block: "end"
133
- });
134
- }, 42);
204
+ console.info("onmessage json parser error:", error);
205
+ if (!error.message.toLowerCase().includes("json.parse") &&
206
+ !error.message.toLowerCase().includes("json parse error")
207
+ ) {
208
+ console.error("onmessage parse error!", error);
209
+ console.error("onmessage data:", event.data);
210
+ } else {
211
+ // otherwise assume display
212
+ var node = document.createElement("div");
213
+ node.className = "display_text";
214
+ node.innerHTML = escapeHtml(event.data);
215
+ document.getElementById('display').appendChild(node);
216
+ scrollDisplayIntoView();
217
+ }
135
218
  }
136
219
  }
137
220
 
@@ -140,7 +223,7 @@ function onerror(event) {
140
223
  clearTimeout(connectTimer);
141
224
 
142
225
  if (autoReconnect) {
143
- lconsole.og('unable to connect, retrying in ' + (connectDelay / 1000) + ' seconds', 'error');
226
+ console.log('unable to connect, retrying in ' + (connectDelay / 1000) + ' seconds', 'error');
144
227
  connectTimer = setTimeout(connect, connectDelay);
145
228
  } else {
146
229
  console.info('disconnected');
@@ -153,17 +236,49 @@ export function connect() {
153
236
  // reset timeout flag for new connection
154
237
  lastMessageWasTimeout = false;
155
238
 
156
- ws = new WebSocket("ws://localhost:8080/render")
157
- // location.protocol === 'https:'
158
- // ? 'wss://' + window.location.host + "/render"
159
- // : 'ws://' + window.location.host + "/render"
160
- // );
239
+ ws = new WebSocket(
240
+ location.protocol === 'https:'
241
+ ? 'wss://' + window.location.host + "/render"
242
+ : 'ws://' + window.location.host + "/render"
243
+ );
161
244
  ws.onopen = onopen;
162
245
  ws.onmessage = onmessage;
163
246
  ws.onerror = onerror;
164
247
  }
165
248
 
249
+ function generateControls(controls) {
250
+ if (!Array.isArray(controls)) {
251
+ console.error("invalid controls!", controls);
252
+ return;
253
+ }
254
+ var controlsHtml = "";
255
+ singleInputMode = false;
256
+ for(var i = 0; i < controls.length; i++) {
257
+ if (typeof controls[i].type !== "undefined") {
258
+ singleInputMode = true;
259
+ // value input
260
+ switch(controls[i].type) {
261
+ case "text":
262
+ controlsHtml = controlsHtml + `<input id="${controls[i].uuid}" type="${controls[i].type}" placeholder="${escapeHtml(controls[i].name)}"></input>`
263
+ break;
264
+ default:
265
+ break;
266
+ }
267
+
268
+ } else {
269
+ // default menu options
270
+ controlsHtml = controlsHtml + `<button id="${controls[i].uuid}"><pre>${escapeHtml(controls[i].name)}</pre></button>`;
271
+ }
272
+ }
273
+
274
+ return controlsHtml;
275
+ }
276
+
166
277
  function moveBaton(reverse) {
278
+ if (isProjecting()) {
279
+ return;
280
+ }
281
+
167
282
  var currentHolder = null;
168
283
  var nextHolder = null;
169
284
 
@@ -201,9 +316,51 @@ function batonSelected() {
201
316
  }
202
317
  }
203
318
 
204
- function processKeyboardInput(event) {
319
+ function clearControlsBaton() {
320
+ const buttons = document.getElementById("controls").children; // HTMLCollection
321
+ for (var i = 0; i < buttons.length; i++) {
322
+ buttons.item(i).className = "";
323
+ }
324
+ }
325
+
326
+ function onSingleInputKeydown(event) {
327
+ if (!singleInputMode) {
328
+ console.error("invalid call to onSingleInputKeydown!");
329
+ return
330
+ }
331
+
332
+ const key = event.key.toLowerCase();
333
+ console.info(`onSingleInputKeydown: event.key = "${key}"`);
334
+ switch(key) {
335
+ case "enter":
336
+ if (typeof event.target.value === 'string') {
337
+ event.target.value = event.target.value.trim();
338
+ sendControl(event);
339
+ } else {
340
+ console.error("invalid new_value!", event.target.value);
341
+ }
342
+ break;
343
+ default:
344
+ console.info(event.target.value);
345
+ break;
346
+ }
347
+ }
348
+
349
+ function onDocumentKeyPress(event) {
350
+ if (singleInputMode) {
351
+ return;
352
+ }
353
+
354
+ let projectorHandled = false;
355
+ if (isProjecting()) {
356
+ projectorHandled = f_dot_canvas.handleKeyPress(event)
357
+ }
358
+ if (projectorHandled) {
359
+ return;
360
+ }
361
+
205
362
  const key = event.key.toLowerCase();
206
- console.info(`processKeyboardInput: event.key = "${key}"`);
363
+ console.info(`onDocumentKeyPress: event.key = "${key}"`);
207
364
  switch(key) {
208
365
  case "tab":
209
366
  console.info("tab key pressed!");
@@ -211,25 +368,64 @@ function processKeyboardInput(event) {
211
368
  moveBaton();
212
369
  break;
213
370
  case "enter":
371
+ event.preventDefault();
214
372
  batonSelected();
215
373
  break;
216
374
  case "w":
217
375
  case "arrowup":
218
- console.info("up key pressed!");
376
+ if (isProjecting()) {
377
+ // move projected glyph
378
+ projectionMovement.x += f_dot_canvas.MOVE_STEP;
379
+ submitProjectionMovement();
380
+ }
381
+ event.preventDefault();
219
382
  break;
220
383
  case "a":
221
384
  case "arrowleft":
222
- console.info("left key pressed!");
223
- moveBaton(true);
385
+ event.preventDefault();
386
+ if (isProjecting()) {
387
+ // move projected glyph
388
+ projectionMovement.y += f_dot_canvas.MOVE_STEP;
389
+ submitProjectionMovement();
390
+ } else {
391
+ moveBaton(true);
392
+ }
224
393
  break;
225
394
  case "s":
226
395
  case "arrowdown":
227
- console.info("down key pressed!");
396
+ if (isProjecting()) {
397
+ // move projected glyph
398
+ projectionMovement.x -= f_dot_canvas.MOVE_STEP;
399
+ submitProjectionMovement();
400
+ }
401
+ event.preventDefault();
228
402
  break;
229
403
  case "d":
230
404
  case "arrowright":
231
- console.info("right key pressed!");
232
- moveBaton();
405
+ event.preventDefault();
406
+ if (isProjecting()) {
407
+ // move projected glyph
408
+ projectionMovement.y -= f_dot_canvas.MOVE_STEP;
409
+ submitProjectionMovement();
410
+ } else {
411
+ moveBaton();
412
+ }
413
+ break;
414
+ case "z":
415
+ event.preventDefault();
416
+ if (isProjecting()) {
417
+ // move projected glyph
418
+ projectionMovement.z -= f_dot_canvas.MOVE_STEP;
419
+ submitProjectionMovement();
420
+ }
421
+ break;
422
+ case "x":
423
+ event.preventDefault();
424
+ if (isProjecting()) {
425
+ // move projected glyph
426
+ projectionMovement.z += f_dot_canvas.MOVE_STEP;
427
+ submitProjectionMovement();
428
+ }
233
429
  break;
234
430
  default:
235
431
  break;
@@ -238,13 +434,77 @@ function processKeyboardInput(event) {
238
434
 
239
435
  function fDotMenuButtonClick(event) {
240
436
  console.info("fDotMenuButtonClick(event)", event);
241
- f_dot_canvas.toggleVisible();
437
+ let fDotMenuContainer = document.getElementById("f_dot_menu_container");
438
+ if (fDotMenuContainer.className.includes("hidden")) {
439
+ fDotMenuContainer.style["z-index"] = 11;
440
+ fDotMenuContainer.className = "";
441
+ } else {
442
+ fDotMenuContainer.className = "hidden";
443
+ setTimeout(function() {
444
+ fDotMenuContainer.style["z-index"] = -9;
445
+ }, 555);
446
+ }
447
+ }
448
+
449
+ function fDotLinkClick(event) {
450
+ console.info("fDotLinkClick(event)", event);
451
+ var newBaton = event.target.id.replace("_link", "");
452
+ if (newBaton !== "f_dot") {
453
+ document.getElementById("f_dot_link").style.display = "block";
454
+ document.getElementById("controls").className = "hidden";
455
+ fDotLinkClickListener = document.getElementById("f_dot_link").addEventListener('click', fDotLinkClick);
456
+ document.getElementById("display").style.display = "none";
457
+ document.getElementById("browser_container").style.display = "block";
458
+ // load view
459
+ switch(newBaton) {
460
+ case "projector":
461
+ canvas
462
+ document.getElementById("browser_container").style.display = "none";
463
+ document.getElementById("canvas").style.display = "block";
464
+ if (!f_dot_canvas.isLoaded()) {
465
+ f_dot_canvas.clear();
466
+ }
467
+ break;
468
+ case "editor":
469
+ // load editor
470
+ document.getElementById("canvas").style.display = "none";
471
+ document.getElementById("browser").src = "http://127.0.0.1:8443";
472
+ break;
473
+ case "history":
474
+ // load history
475
+ document.getElementById("canvas").style.display = "none";
476
+ document.getElementById("browser").src = "http://127.0.0.1:2997";
477
+ break;
478
+ default:
479
+ break;
480
+ }
481
+ } else {
482
+ document.getElementById("display").style.display = "block";
483
+ document.getElementById("f_dot_link").removeEventListener(fDotLinkClickListener, fDotLinkClick);
484
+ document.getElementById("f_dot_link").style.display = "none";
485
+ document.getElementById("browser_container").style.display = "none";
486
+ document.getElementById("canvas").style.display = "none";
487
+ document.getElementById("controls").className = "";
488
+ scrollDisplayIntoView();
489
+ }
490
+
491
+ document.getElementById(`${linkBaton}_link`).className = "";
492
+ linkBaton = newBaton;
493
+ event.target.className = "baton";
494
+ document.getElementById("f_dot_menu_container").className = "hidden";
242
495
  }
243
496
 
244
497
  export function configureDom() {
245
498
  // configure keyboard input processing
246
- document.addEventListener('keydown', processKeyboardInput);
499
+ document.addEventListener('keydown', onDocumentKeyPress);
247
500
 
248
501
  // configure menu button click
249
- document.getElementById("f_dot_menu_button").addEventListener('click', fDotMenuButtonClick);
502
+ const b = document.getElementById("f_dot_menu_button");
503
+ b.addEventListener('click', fDotMenuButtonClick);
504
+
505
+ fDotLinks.forEach((k) => {
506
+ if (k !== "f_dot") {
507
+ document.getElementById(k).addEventListener('click', fDotLinkClick);
508
+ }
509
+ });
250
510
  }
@@ -1,64 +1,197 @@
1
+ html, body {
2
+ background: black;
3
+ color: white;
4
+ /*<thumb-color> <track-background-color>*/
5
+ scrollbar-color: darkslategrey black;
6
+ font-family: menlo;
7
+ margin: 0;
8
+ }
9
+ #f_dot_contents {
10
+ position: relative;
11
+ anchor-scope: all;
12
+ }
13
+ #browser_container {
14
+ position: fixed;
15
+ top: 6vh;
16
+ left: 0;
17
+ right: 0;
18
+ bottom: 0;
19
+ }
20
+ #canvas {
21
+ position: fixed;
22
+ top: 0;
23
+ left: 0;
24
+ right: 0;
25
+ bottom: 0;
26
+
27
+ #canvas_empty {
28
+ margin: 0vh 11vh;
29
+ text-align: center;
30
+ white-space: pre-line;
31
+ font-size: 2vh;
32
+ line-height: 8vh;
33
+ }
34
+
35
+ .glyph {
36
+ background: white;
37
+ color: black;
38
+ font-size: 1rem;
39
+ padding: 1rem;
40
+
41
+ &:hover {
42
+ border: dotted 1px blue;
43
+ }
44
+ }
45
+
46
+ /* .perspecticus {
47
+
48
+ } */
49
+
50
+ .objecticus {
51
+ background: darkgrey;
52
+ color: darkblue;
53
+ }
54
+ }
55
+ #browser {
56
+ display: block;
57
+ width: 100%;
58
+ height: 100%;
59
+ border: none;
60
+ }
1
61
  #display {
2
- margin-bottom: 3.7rem;
3
- padding-bottom: 8px;
4
- scroll-margin-bottom: 4rem;
62
+ margin-top: 6vh;
63
+ margin-bottom: 9vh;
64
+ scroll-margin-bottom: 9vh;
5
65
  }
6
66
  #controls {
7
- background: white;
8
- overflow-x: scroll;
67
+ background: black;
68
+ overflow-x: auto;
69
+ scrollbar-color: darkslategrey black;
9
70
  display: flex;
10
71
  position: fixed;
11
72
  border-top: 2px dotted darkslategrey;
12
73
  bottom: 0;
13
74
  left: 0;
14
75
  right: 0;
76
+ top: unset;
77
+ transition-property: top;
78
+ transition-duration: 111ms;
79
+ transition-timing-function: ease-in;
80
+ transition-delay: 0s;
81
+
82
+ &.hidden {
83
+ top: 100vh;
84
+ }
15
85
  }
16
86
  #f_dot_menu_button {
17
- -webkit-user-select: none; /* Safari */
87
+ -webkit-user-select: none;
18
88
  user-select: none;
19
- font-size: 2vw;
20
- color: darkslategray;
89
+ z-index: 11;
90
+ font-size: 4vh;
91
+ font-weight: bolder;
92
+ color: white;
21
93
  position: fixed;
22
- right: 4vw;
94
+ right: 0;
23
95
  overflow: hidden;
24
96
  cursor: default;
25
- background: white;
26
- padding: 17px;
27
- border-bottom: 1px solid black;
28
- border-right: 1px dotted black;
29
- border-left: 1px dotted green;
30
- border-top: 1px dashed gold;
31
- opacity: 0.42;
97
+ background: rgba(55, 55, 55, 0.77);
98
+ padding: 0.5vh 4vw;
99
+ border: 1px dotted white;
100
+ top: 0;
101
+ left: 0;
102
+ text-align: center;
32
103
  }
33
104
  #f_dot_menu_button:hover {
34
- opacity: 1;
105
+ color: black;
106
+ background: white;
107
+ }
108
+ #f_dot_menu_container {
109
+ z-index: 11;
110
+ background: rgba(255, 255, 255, 0.55);
111
+ display: flex;
112
+ flex-direction: column;
113
+ position: fixed;
114
+ left: 0;
115
+ text-align: center;
116
+ right: 0;
117
+ top: 6vh;
118
+ transition-property: opacity;
119
+ transition-duration: 111ms;
120
+ transition-timing-function: ease-in;
121
+ transition-delay: 0s;
122
+ }
123
+ #f_dot_menu_container.hidden {
124
+ opacity: 0;
125
+ }
126
+ #f_dot_menu_container a {
127
+ font-size: 4vh;
128
+ margin: 1vw;
129
+ background: rgba(22,22 ,22, 0.77);
130
+ transition-property: margin;
131
+ transition-duration: 444ms;
132
+ transition-timing-function: ease-out;
133
+ transition-delay: 0s;
134
+ color: white;
135
+ text-decoration: none;
136
+ padding: 2vh 3vw;
137
+ }
138
+ #f_dot_menu_container a.baton {
139
+ background: black;
140
+ color: white;
141
+ }
142
+ #f_dot_menu_container a:hover {
143
+ background: rgba(255, 255, 255, 0.55);
144
+ color: black;
145
+ transition-property: color;
146
+ transition-duration: 222;
147
+ transition-timing-function: ease-out;
148
+ transition-delay: 0s;
149
+ }
150
+ #f_dot_menu_container.hidden a {
151
+ margin: -6vw;
35
152
  }
36
153
  div.display_text {
37
154
  overflow-y: auto;
38
- border-left: solid 1px blue;
155
+ border-left: solid 0.1em rgba(0, 0, 242, 0.42);
156
+ border-top: dotted 1px rgba(77, 77, 77, 0.77);
157
+ padding-top: 8px;
158
+ padding-bottom: 8px;
39
159
  padding-left: 4px;
160
+ font-size: 1.4rem;
40
161
  }
41
- button, input {
162
+ input {
163
+ width: 100%;
164
+ font-weight: normal;
165
+ color: black;
166
+ background: gray;
167
+ font-size: 1em;
168
+ padding: 5px;
169
+ }
170
+ button {
42
171
  background: transparent;
43
172
  border: none;
44
173
  border-left: 1px dotted purple;
45
174
  font-weight: bolder;
46
- color: black;
175
+ color: white;
47
176
  }
48
- button:hover, button.baton {
49
- background-color: darkslategray;
177
+ button:hover {
178
+ background-color: darkgrey;
50
179
  color: white;
180
+ opacity: 0.5;
181
+ }
182
+ button.baton {
183
+ background-color: white;
184
+ color: black;
51
185
  }
52
186
  button pre {
53
187
  pointer-events: none;
54
188
  background-color: transparent;
55
189
  color: inherit;
56
- padding: 4px 17px;
190
+ padding: 0 1vw;
191
+ font-size: 2vh;
192
+ line-height: 0;
193
+ font-weight: lighter;
194
+ font-style: normal;
195
+ letter-spacing: 1px;
196
+ margin: 3vh 2vw;
57
197
  }
58
-
59
- canvas {
60
- position: absolute;
61
- z-index: 9;
62
- right: 0;
63
- bottom: 0;
64
- }