retold-remote 0.0.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.
Files changed (41) hide show
  1. package/LICENSE +21 -0
  2. package/css/retold-remote.css +83 -0
  3. package/html/codejar.js +511 -0
  4. package/html/index.html +23 -0
  5. package/package.json +68 -0
  6. package/server.js +43 -0
  7. package/source/Pict-Application-RetoldRemote-Configuration.json +7 -0
  8. package/source/Pict-Application-RetoldRemote.js +622 -0
  9. package/source/Pict-RetoldRemote-Bundle.js +14 -0
  10. package/source/cli/RetoldRemote-CLI-Program.js +15 -0
  11. package/source/cli/RetoldRemote-CLI-Run.js +3 -0
  12. package/source/cli/RetoldRemote-Server-Setup.js +257 -0
  13. package/source/cli/commands/RetoldRemote-Command-Serve.js +87 -0
  14. package/source/providers/Pict-Provider-GalleryFilterSort.js +597 -0
  15. package/source/providers/Pict-Provider-GalleryNavigation.js +819 -0
  16. package/source/providers/Pict-Provider-RetoldRemote.js +273 -0
  17. package/source/providers/Pict-Provider-RetoldRemoteIcons.js +640 -0
  18. package/source/providers/Pict-Provider-RetoldRemoteTheme.js +879 -0
  19. package/source/server/RetoldRemote-MediaService.js +536 -0
  20. package/source/server/RetoldRemote-PathRegistry.js +121 -0
  21. package/source/server/RetoldRemote-ThumbnailCache.js +89 -0
  22. package/source/server/RetoldRemote-ToolDetector.js +78 -0
  23. package/source/views/PictView-Remote-Gallery.js +1437 -0
  24. package/source/views/PictView-Remote-ImageViewer.js +363 -0
  25. package/source/views/PictView-Remote-Layout.js +420 -0
  26. package/source/views/PictView-Remote-MediaViewer.js +530 -0
  27. package/source/views/PictView-Remote-SettingsPanel.js +318 -0
  28. package/source/views/PictView-Remote-TopBar.js +206 -0
  29. package/web-application/codejar.js +511 -0
  30. package/web-application/css/retold-remote.css +83 -0
  31. package/web-application/index.html +23 -0
  32. package/web-application/js/pict.min.js +12 -0
  33. package/web-application/js/pict.min.js.map +1 -0
  34. package/web-application/retold-remote.compatible.js +5764 -0
  35. package/web-application/retold-remote.compatible.js.map +1 -0
  36. package/web-application/retold-remote.compatible.min.js +120 -0
  37. package/web-application/retold-remote.compatible.min.js.map +1 -0
  38. package/web-application/retold-remote.js +5763 -0
  39. package/web-application/retold-remote.js.map +1 -0
  40. package/web-application/retold-remote.min.js +120 -0
  41. package/web-application/retold-remote.min.js.map +1 -0
@@ -0,0 +1,511 @@
1
+ /**
2
+ * CodeJar - a micro code editor for the browser.
3
+ * MIT License - https://github.com/antonmedv/codejar
4
+ *
5
+ * This is a UMD/IIFE wrapper of the CodeJar ESM module so it can be
6
+ * loaded with a plain <script> tag and exposes window.CodeJar.
7
+ */
8
+ (function (global) {
9
+ const globalWindow = window;
10
+ function CodeJar(editor, highlight, opt = {}) {
11
+ const options = {
12
+ tab: '\t',
13
+ indentOn: /[({\[]$/,
14
+ moveToNewLine: /^[)}\]]/,
15
+ spellcheck: false,
16
+ catchTab: true,
17
+ preserveIdent: true,
18
+ addClosing: true,
19
+ history: true,
20
+ window: globalWindow,
21
+ autoclose: {
22
+ open: `([{'"`,
23
+ close: `)]}'"`
24
+ },
25
+ ...opt,
26
+ };
27
+ const window = options.window;
28
+ const document = window.document;
29
+ const listeners = [];
30
+ const history = [];
31
+ let at = -1;
32
+ let focus = false;
33
+ let onUpdate = () => void 0;
34
+ let prev;
35
+ editor.setAttribute('contenteditable', 'plaintext-only');
36
+ editor.setAttribute('spellcheck', options.spellcheck ? 'true' : 'false');
37
+ editor.style.outline = 'none';
38
+ editor.style.overflowWrap = 'break-word';
39
+ editor.style.overflowY = 'auto';
40
+ editor.style.whiteSpace = 'pre-wrap';
41
+ const doHighlight = (editor, pos) => {
42
+ highlight(editor, pos);
43
+ };
44
+ const matchFirefoxVersion = window.navigator.userAgent.match(/Firefox\/([0-9]+)\./);
45
+ const firefoxVersion = matchFirefoxVersion
46
+ ? parseInt(matchFirefoxVersion[1])
47
+ : 0;
48
+ let isLegacy = false;
49
+ if (editor.contentEditable !== "plaintext-only" || firefoxVersion >= 136)
50
+ isLegacy = true;
51
+ if (isLegacy)
52
+ editor.setAttribute("contenteditable", "true");
53
+ const debounceHighlight = debounce(() => {
54
+ const pos = save();
55
+ doHighlight(editor, pos);
56
+ restore(pos);
57
+ }, 30);
58
+ let recording = false;
59
+ const shouldRecord = (event) => {
60
+ return !isUndo(event) && !isRedo(event)
61
+ && event.key !== 'Meta'
62
+ && event.key !== 'Control'
63
+ && event.key !== 'Alt'
64
+ && !event.key.startsWith('Arrow');
65
+ };
66
+ const debounceRecordHistory = debounce((event) => {
67
+ if (shouldRecord(event)) {
68
+ recordHistory();
69
+ recording = false;
70
+ }
71
+ }, 300);
72
+ const on = (type, fn) => {
73
+ listeners.push([type, fn]);
74
+ editor.addEventListener(type, fn);
75
+ };
76
+ on('keydown', event => {
77
+ if (event.defaultPrevented)
78
+ return;
79
+ prev = toString();
80
+ if (options.preserveIdent)
81
+ handleNewLine(event);
82
+ else
83
+ legacyNewLineFix(event);
84
+ if (options.catchTab)
85
+ handleTabCharacters(event);
86
+ if (options.addClosing)
87
+ handleSelfClosingCharacters(event);
88
+ if (options.history) {
89
+ handleUndoRedo(event);
90
+ if (shouldRecord(event) && !recording) {
91
+ recordHistory();
92
+ recording = true;
93
+ }
94
+ }
95
+ if (isLegacy && !isCopy(event))
96
+ restore(save());
97
+ });
98
+ on('keyup', event => {
99
+ if (event.defaultPrevented)
100
+ return;
101
+ if (event.isComposing)
102
+ return;
103
+ if (prev !== toString())
104
+ debounceHighlight();
105
+ debounceRecordHistory(event);
106
+ onUpdate(toString());
107
+ });
108
+ on('focus', _event => {
109
+ focus = true;
110
+ });
111
+ on('blur', _event => {
112
+ focus = false;
113
+ });
114
+ on('paste', event => {
115
+ recordHistory();
116
+ handlePaste(event);
117
+ recordHistory();
118
+ onUpdate(toString());
119
+ });
120
+ on('cut', event => {
121
+ recordHistory();
122
+ handleCut(event);
123
+ recordHistory();
124
+ onUpdate(toString());
125
+ });
126
+ function save() {
127
+ const s = getSelection();
128
+ const pos = { start: 0, end: 0, dir: undefined };
129
+ let { anchorNode, anchorOffset, focusNode, focusOffset } = s;
130
+ if (!anchorNode || !focusNode)
131
+ throw 'error1';
132
+ if (anchorNode === editor && focusNode === editor) {
133
+ pos.start = (anchorOffset > 0 && editor.textContent) ? editor.textContent.length : 0;
134
+ pos.end = (focusOffset > 0 && editor.textContent) ? editor.textContent.length : 0;
135
+ pos.dir = (focusOffset >= anchorOffset) ? '->' : '<-';
136
+ return pos;
137
+ }
138
+ if (anchorNode.nodeType === Node.ELEMENT_NODE) {
139
+ const node = document.createTextNode('');
140
+ anchorNode.insertBefore(node, anchorNode.childNodes[anchorOffset]);
141
+ anchorNode = node;
142
+ anchorOffset = 0;
143
+ }
144
+ if (focusNode.nodeType === Node.ELEMENT_NODE) {
145
+ const node = document.createTextNode('');
146
+ focusNode.insertBefore(node, focusNode.childNodes[focusOffset]);
147
+ focusNode = node;
148
+ focusOffset = 0;
149
+ }
150
+ visit(editor, el => {
151
+ if (el === anchorNode && el === focusNode) {
152
+ pos.start += anchorOffset;
153
+ pos.end += focusOffset;
154
+ pos.dir = anchorOffset <= focusOffset ? '->' : '<-';
155
+ return 'stop';
156
+ }
157
+ if (el === anchorNode) {
158
+ pos.start += anchorOffset;
159
+ if (!pos.dir) {
160
+ pos.dir = '->';
161
+ }
162
+ else {
163
+ return 'stop';
164
+ }
165
+ }
166
+ else if (el === focusNode) {
167
+ pos.end += focusOffset;
168
+ if (!pos.dir) {
169
+ pos.dir = '<-';
170
+ }
171
+ else {
172
+ return 'stop';
173
+ }
174
+ }
175
+ if (el.nodeType === Node.TEXT_NODE) {
176
+ if (pos.dir != '->')
177
+ pos.start += el.nodeValue.length;
178
+ if (pos.dir != '<-')
179
+ pos.end += el.nodeValue.length;
180
+ }
181
+ });
182
+ editor.normalize();
183
+ return pos;
184
+ }
185
+ function restore(pos) {
186
+ const s = getSelection();
187
+ let startNode, startOffset = 0;
188
+ let endNode, endOffset = 0;
189
+ if (!pos.dir)
190
+ pos.dir = '->';
191
+ if (pos.start < 0)
192
+ pos.start = 0;
193
+ if (pos.end < 0)
194
+ pos.end = 0;
195
+ if (pos.dir == '<-') {
196
+ const { start, end } = pos;
197
+ pos.start = end;
198
+ pos.end = start;
199
+ }
200
+ let current = 0;
201
+ visit(editor, el => {
202
+ if (el.nodeType !== Node.TEXT_NODE)
203
+ return;
204
+ const len = (el.nodeValue || '').length;
205
+ if (current + len > pos.start) {
206
+ if (!startNode) {
207
+ startNode = el;
208
+ startOffset = pos.start - current;
209
+ }
210
+ if (current + len > pos.end) {
211
+ endNode = el;
212
+ endOffset = pos.end - current;
213
+ return 'stop';
214
+ }
215
+ }
216
+ current += len;
217
+ });
218
+ if (!startNode)
219
+ startNode = editor, startOffset = editor.childNodes.length;
220
+ if (!endNode)
221
+ endNode = editor, endOffset = editor.childNodes.length;
222
+ if (pos.dir == '<-') {
223
+ [startNode, startOffset, endNode, endOffset] = [endNode, endOffset, startNode, startOffset];
224
+ }
225
+ {
226
+ const startEl = uneditable(startNode);
227
+ if (startEl) {
228
+ const node = document.createTextNode('');
229
+ startEl.parentNode?.insertBefore(node, startEl);
230
+ startNode = node;
231
+ startOffset = 0;
232
+ }
233
+ const endEl = uneditable(endNode);
234
+ if (endEl) {
235
+ const node = document.createTextNode('');
236
+ endEl.parentNode?.insertBefore(node, endEl);
237
+ endNode = node;
238
+ endOffset = 0;
239
+ }
240
+ }
241
+ s.setBaseAndExtent(startNode, startOffset, endNode, endOffset);
242
+ editor.normalize();
243
+ }
244
+ function uneditable(node) {
245
+ while (node && node !== editor) {
246
+ if (node.nodeType === Node.ELEMENT_NODE) {
247
+ const el = node;
248
+ if (el.getAttribute('contenteditable') == 'false') {
249
+ return el;
250
+ }
251
+ }
252
+ node = node.parentNode;
253
+ }
254
+ }
255
+ function beforeCursor() {
256
+ const s = getSelection();
257
+ const r0 = s.getRangeAt(0);
258
+ const r = document.createRange();
259
+ r.selectNodeContents(editor);
260
+ r.setEnd(r0.startContainer, r0.startOffset);
261
+ return r.toString();
262
+ }
263
+ function afterCursor() {
264
+ const s = getSelection();
265
+ const r0 = s.getRangeAt(0);
266
+ const r = document.createRange();
267
+ r.selectNodeContents(editor);
268
+ r.setStart(r0.endContainer, r0.endOffset);
269
+ return r.toString();
270
+ }
271
+ function handleNewLine(event) {
272
+ if (event.key === 'Enter') {
273
+ const before = beforeCursor();
274
+ const after = afterCursor();
275
+ let [padding] = findPadding(before);
276
+ let newLinePadding = padding;
277
+ if (options.indentOn.test(before)) {
278
+ newLinePadding += options.tab;
279
+ }
280
+ if (newLinePadding.length > 0) {
281
+ preventDefault(event);
282
+ event.stopPropagation();
283
+ insert('\n' + newLinePadding);
284
+ }
285
+ else {
286
+ legacyNewLineFix(event);
287
+ }
288
+ if (newLinePadding !== padding && options.moveToNewLine.test(after)) {
289
+ const pos = save();
290
+ insert('\n' + padding);
291
+ restore(pos);
292
+ }
293
+ }
294
+ }
295
+ function legacyNewLineFix(event) {
296
+ if (isLegacy && event.key === 'Enter') {
297
+ preventDefault(event);
298
+ event.stopPropagation();
299
+ if (afterCursor() == '') {
300
+ insert('\n ');
301
+ const pos = save();
302
+ pos.start = --pos.end;
303
+ restore(pos);
304
+ }
305
+ else {
306
+ insert('\n');
307
+ }
308
+ }
309
+ }
310
+ function handleSelfClosingCharacters(event) {
311
+ const open = options.autoclose.open;
312
+ const close = options.autoclose.close;
313
+ if (open.includes(event.key)) {
314
+ preventDefault(event);
315
+ const pos = save();
316
+ const wrapText = pos.start == pos.end ? '' : getSelection().toString();
317
+ const text = event.key + wrapText + (close[open.indexOf(event.key)] ?? "");
318
+ insert(text);
319
+ pos.start++;
320
+ pos.end++;
321
+ restore(pos);
322
+ }
323
+ }
324
+ function handleTabCharacters(event) {
325
+ if (event.key === 'Tab') {
326
+ preventDefault(event);
327
+ if (event.shiftKey) {
328
+ const before = beforeCursor();
329
+ let [padding, start] = findPadding(before);
330
+ if (padding.length > 0) {
331
+ const pos = save();
332
+ const len = Math.min(options.tab.length, padding.length);
333
+ restore({ start, end: start + len });
334
+ document.execCommand('delete');
335
+ pos.start -= len;
336
+ pos.end -= len;
337
+ restore(pos);
338
+ }
339
+ }
340
+ else {
341
+ insert(options.tab);
342
+ }
343
+ }
344
+ }
345
+ function handleUndoRedo(event) {
346
+ if (isUndo(event)) {
347
+ preventDefault(event);
348
+ at--;
349
+ const record = history[at];
350
+ if (record) {
351
+ editor.innerHTML = record.html;
352
+ restore(record.pos);
353
+ }
354
+ if (at < 0)
355
+ at = 0;
356
+ }
357
+ if (isRedo(event)) {
358
+ preventDefault(event);
359
+ at++;
360
+ const record = history[at];
361
+ if (record) {
362
+ editor.innerHTML = record.html;
363
+ restore(record.pos);
364
+ }
365
+ if (at >= history.length)
366
+ at--;
367
+ }
368
+ }
369
+ function recordHistory() {
370
+ if (!focus)
371
+ return;
372
+ const html = editor.innerHTML;
373
+ const pos = save();
374
+ const lastRecord = history[at];
375
+ if (lastRecord) {
376
+ if (lastRecord.html === html
377
+ && lastRecord.pos.start === pos.start
378
+ && lastRecord.pos.end === pos.end)
379
+ return;
380
+ }
381
+ at++;
382
+ history[at] = { html, pos };
383
+ history.splice(at + 1);
384
+ const maxHistory = 300;
385
+ if (at > maxHistory) {
386
+ at = maxHistory;
387
+ history.splice(0, 1);
388
+ }
389
+ }
390
+ function handlePaste(event) {
391
+ if (event.defaultPrevented)
392
+ return;
393
+ preventDefault(event);
394
+ const originalEvent = event.originalEvent ?? event;
395
+ const text = originalEvent.clipboardData.getData('text/plain').replace(/\r\n?/g, '\n');
396
+ const pos = save();
397
+ insert(text);
398
+ doHighlight(editor);
399
+ restore({
400
+ start: Math.min(pos.start, pos.end) + text.length,
401
+ end: Math.min(pos.start, pos.end) + text.length,
402
+ dir: '<-',
403
+ });
404
+ }
405
+ function handleCut(event) {
406
+ const pos = save();
407
+ const selection = getSelection();
408
+ const originalEvent = event.originalEvent ?? event;
409
+ originalEvent.clipboardData.setData('text/plain', selection.toString());
410
+ document.execCommand('delete');
411
+ doHighlight(editor);
412
+ restore({
413
+ start: Math.min(pos.start, pos.end),
414
+ end: Math.min(pos.start, pos.end),
415
+ dir: '<-',
416
+ });
417
+ preventDefault(event);
418
+ }
419
+ function visit(editor, visitor) {
420
+ const queue = [];
421
+ if (editor.firstChild)
422
+ queue.push(editor.firstChild);
423
+ let el = queue.pop();
424
+ while (el) {
425
+ if (visitor(el) === 'stop')
426
+ break;
427
+ if (el.nextSibling)
428
+ queue.push(el.nextSibling);
429
+ if (el.firstChild)
430
+ queue.push(el.firstChild);
431
+ el = queue.pop();
432
+ }
433
+ }
434
+ function isCtrl(event) {
435
+ return event.metaKey || event.ctrlKey;
436
+ }
437
+ function isUndo(event) {
438
+ return isCtrl(event) && !event.shiftKey && getKeyCode(event) === 'Z';
439
+ }
440
+ function isRedo(event) {
441
+ return isCtrl(event) && event.shiftKey && getKeyCode(event) === 'Z';
442
+ }
443
+ function isCopy(event) {
444
+ return isCtrl(event) && getKeyCode(event) === 'C';
445
+ }
446
+ function getKeyCode(event) {
447
+ let key = event.key || event.keyCode || event.which;
448
+ if (!key)
449
+ return undefined;
450
+ return (typeof key === 'string' ? key : String.fromCharCode(key)).toUpperCase();
451
+ }
452
+ function insert(text) {
453
+ text = text
454
+ .replace(/&/g, '&amp;')
455
+ .replace(/</g, '&lt;')
456
+ .replace(/>/g, '&gt;')
457
+ .replace(/"/g, '&quot;')
458
+ .replace(/'/g, '&#039;');
459
+ document.execCommand('insertHTML', false, text);
460
+ }
461
+ function debounce(cb, wait) {
462
+ let timeout = 0;
463
+ return (...args) => {
464
+ clearTimeout(timeout);
465
+ timeout = window.setTimeout(() => cb(...args), wait);
466
+ };
467
+ }
468
+ function findPadding(text) {
469
+ let i = text.length - 1;
470
+ while (i >= 0 && text[i] !== '\n')
471
+ i--;
472
+ i++;
473
+ let j = i;
474
+ while (j < text.length && /[ \t]/.test(text[j]))
475
+ j++;
476
+ return [text.substring(i, j) || '', i, j];
477
+ }
478
+ function toString() {
479
+ return editor.textContent || '';
480
+ }
481
+ function preventDefault(event) {
482
+ event.preventDefault();
483
+ }
484
+ function getSelection() {
485
+ return editor.getRootNode().getSelection();
486
+ }
487
+ return {
488
+ updateOptions(newOptions) {
489
+ Object.assign(options, newOptions);
490
+ },
491
+ updateCode(code, callOnUpdate = true) {
492
+ editor.textContent = code;
493
+ doHighlight(editor);
494
+ callOnUpdate && onUpdate(code);
495
+ },
496
+ onUpdate(callback) {
497
+ onUpdate = callback;
498
+ },
499
+ toString,
500
+ save,
501
+ restore,
502
+ recordHistory,
503
+ destroy() {
504
+ for (let [type, fn] of listeners) {
505
+ editor.removeEventListener(type, fn);
506
+ }
507
+ },
508
+ };
509
+ }
510
+ global.CodeJar = CodeJar;
511
+ })(typeof window !== 'undefined' ? window : this);
@@ -0,0 +1,83 @@
1
+ /* Retold Remote -- Base Styles */
2
+
3
+ *,
4
+ *::before,
5
+ *::after
6
+ {
7
+ box-sizing: border-box;
8
+ }
9
+
10
+ html, body
11
+ {
12
+ margin: 0;
13
+ padding: 0;
14
+ height: 100%;
15
+ overflow: hidden;
16
+ background: var(--retold-bg-primary);
17
+ color: var(--retold-text-primary);
18
+ font-family: var(--retold-font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif);
19
+ font-size: 14px;
20
+ line-height: 1.5;
21
+ -webkit-font-smoothing: antialiased;
22
+ -moz-osx-font-smoothing: grayscale;
23
+ }
24
+
25
+ /* Scrollbar styling */
26
+ ::-webkit-scrollbar
27
+ {
28
+ width: 8px;
29
+ height: 8px;
30
+ }
31
+
32
+ ::-webkit-scrollbar-track
33
+ {
34
+ background: var(--retold-bg-primary);
35
+ }
36
+
37
+ ::-webkit-scrollbar-thumb
38
+ {
39
+ background: var(--retold-scrollbar);
40
+ border-radius: 4px;
41
+ }
42
+
43
+ ::-webkit-scrollbar-thumb:hover
44
+ {
45
+ background: var(--retold-scrollbar-hover);
46
+ }
47
+
48
+ /* Selection colors */
49
+ ::selection
50
+ {
51
+ background: var(--retold-selection-bg);
52
+ color: var(--retold-text-primary);
53
+ }
54
+
55
+ /* Focus outline */
56
+ :focus-visible
57
+ {
58
+ outline: 2px solid var(--retold-focus-outline);
59
+ outline-offset: 2px;
60
+ }
61
+
62
+ /* Fullscreen styles for the viewer */
63
+ #RetoldRemote-Viewer-Container:fullscreen
64
+ {
65
+ background: #000;
66
+ }
67
+
68
+ #RetoldRemote-Viewer-Container:fullscreen .retold-remote-viewer-header
69
+ {
70
+ position: absolute;
71
+ top: 0;
72
+ left: 0;
73
+ right: 0;
74
+ background: rgba(0, 0, 0, 0.8);
75
+ opacity: 0;
76
+ transition: opacity 0.3s;
77
+ z-index: 10;
78
+ }
79
+
80
+ #RetoldRemote-Viewer-Container:fullscreen:hover .retold-remote-viewer-header
81
+ {
82
+ opacity: 1;
83
+ }
@@ -0,0 +1,23 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Retold Remote</title>
7
+ <link rel="stylesheet" href="css/retold-remote.css">
8
+ <style id="PICT-CSS"></style>
9
+ </head>
10
+ <body>
11
+ <div id="ContentEditor-Application-Container"></div>
12
+
13
+ <!-- Pict framework -->
14
+ <script src="js/pict.min.js"></script>
15
+ <!-- CodeJar (code editor engine for pict-section-code) -->
16
+ <script src="codejar.js"></script>
17
+ <!-- Retold Remote application bundle -->
18
+ <script src="retold-remote.min.js"></script>
19
+ <script>
20
+ Pict.safeLoadPictApplication(RetoldRemoteApplication, 2);
21
+ </script>
22
+ </body>
23
+ </html>