-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
852 lines (643 loc) · 26.6 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
<!DOCTYPE html>
<html hidden lang="en">
<head>
<link rel="icon" href="data:,">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover">
<meta name="theme-color" content="transparent">
<meta name="format-detection" content="telephone=no">
<script>'use strict';
window.g_app = {
modifiedAt: document.lastModified,
launchedAt: performance.now(),
};
</script>
<script type="module">
const app = window.g_app;
window.addEventListener('load', () => {
const s = window.document.createElement('script');
s.setAttribute('async', '');
s.setAttribute('id', 'REMOVE');
s.setAttribute('src', 'data:text/javascript;base64,d2luZG93LmdfYXBwLm1haW4oKTsKLy8jIHNvdXJjZVVSTD1odHRwczovL2RlbW8uY3Jvc3NwbGF0Zm9ybXVpLmNvbS8obG9hZHNwbGl0KQ==');
window.document.head.appendChild(s);
});
{ // UUID Generator
const lut = Array(256).fill().map((_, i) => (i < 16 ? '0' : '') + (i).toString(16));
const _ = app.uuid = {
random128: () => {
const dvals = new Uint32Array(4);
crypto.getRandomValues(dvals);
return dvals;
},
formatUuid: ([d0, d1, d2, d3]) =>
lut[d0 & 0xff] + lut[d0 >> 8 & 0xff] + lut[d0 >> 16 & 0xff] + lut[d0 >> 24 & 0xff] + '-' +
lut[d1 & 0xff] + lut[d1 >> 8 & 0xff] + '-' +
lut[d1 >> 16 & 0x0f | 0x40] + lut[d1 >> 24 & 0xff] + '-' +
lut[d2 & 0x3f | 0x80] + lut[d2 >> 8 & 0xff] + '-' +
lut[d2 >> 16 & 0xff] + lut[d2 >> 24 & 0xff] +
lut[d3 & 0xff] + lut[d3 >> 8 & 0xff] +
lut[d3 >> 16 & 0xff] + lut[d3 >> 24 & 0xff],
uuid: () => _.formatUuid(_.random128())
};
}
app.runId = app.uuid.random128();
app.main = () => {
const s = window.document.getElementById('REMOVE');
document.head.removeChild(s);
const app = window.g_app;
// Access root element
const rootElt = window.g_app.rootElt = window.document.getElementById('root');
// Split script here so other microtasks can be run after a lenghty OpenGL init
setTimeout(() => {
// At start, window.document.activeElement equals null
// window.document.activeElement equals body starting from here
app.startedWithActiveElement = window.document.activeElement;
app.startedWithFocus = window.document.hasFocus();
// Enabling drag and drop support
window.document.getElementById('root').addEventListener('dragover', e => {
e.preventDefault();
});
window.document.body.addEventListener('keyup', e => {
// Fullscreen mode by hitting the 'f' key on the keyboard
if (e.key === 'f') {
e.preventDefault();
e.stopPropagation();
const rfs = document.documentElement.requestFullscreen || document.documentElement.webkitRequestFullscreen;
if (rfs) {
rfs.apply(document.documentElement);
}
}
}, true);
window.addEventListener('unload', () => {
window.g_app = null;
// In mobile Safari, we have to call takeHeapSnapshot in order to unload WASM (and supposedly other resources)
if (console.takeHeapSnapshot) {
console.takeHeapSnapshot('unload');
}
}, true);
window.addEventListener('blur', e => {
console.log('blur', window.document.activeElement, window.document.hasFocus());
}, true);
window.addEventListener('focus', e => {
console.log('focus', window.document.activeElement, window.document.hasFocus());
}, true);
window.addEventListener('touchstart', e => {
if (e.target.nodeName === 'DIV' || e.target.id === 'root' || e.target.nodeName === 'H1' || e.target === window.document.body || e.target === window.document.documentElement) {
e.stopPropagation();
e.preventDefault();
} else {
console.log(e);
}
}, { capture: true, passive: false });
window.addEventListener('touchmove', e => {
if (e.target.nodeName === 'DIV' || e.target.id === 'root' || e.target.nodeName === 'H1' || e.target === window.document.body || e.target === window.document.documentElement) {
const width = window.innerWidth;
const height = window.innerWidth;
e.stopPropagation();
e.preventDefault();
} else {
console.log(e);
}
}, { capture: true, passive: false });
// window.addEventListener('mouseup', e => {});
window.addEventListener('touchend', e => {
if (e.target.nodeName === 'DIV' || e.target.id === 'root' || e.target.nodeName === 'H1' || e.target === window.document.body || e.target === window.document.documentElement) {
e.stopPropagation();
e.preventDefault();
// Note this must happen in this microtask,
// otherwise the keyboard won't appear
if (e.target.nodeName === 'H1') {
window.g_app.editText();
}
} else {
console.log(e);
}
}, { capture: true, passive: false });
const updateVisibleSizeInfo = (w, h) => {
window.document.documentElement.style.setProperty('--visible-width', w + 'px');
window.document.documentElement.style.setProperty('--visible-height', h + 'px');
};
app.fitTextareaInVisibleViewport = (visibleHeight, visibleWidth = window.innerWidth) => {
window.g_app.rootElt.setAttribute('height', window.devicePixelRatio * visibleHeight + 'px');
window.g_app.rootElt.setAttribute('width', window.devicePixelRatio * visibleWidth + 'px');
window.g_app.rootElt.style.height = visibleHeight + 'px';
window.g_app.rootElt.style.width = visibleWidth + 'px';
updateVisibleSizeInfo(visibleWidth, visibleHeight);
if (window.g_app.textboxElt) {
window.g_app.textboxElt.style.height = visibleHeight + 'px';
window.g_app.textboxElt.style.minHeight = visibleHeight + 'px';
}
// These are only when the textarea is active!
// On blur these must return to their empty size values.
window.document.documentElement.className = 'with-virtual-keyboard';
if (window.g_app.textboxElt) {
window.g_app.textboxElt.style.width = visibleWidth + 'px';
}
};
// On iOS, it doing setup, so the promise will be resolved when it completes.
window.addEventListener('scroll', e => {
if (e.target !== window.document) {
return;
}
if (window.g_trackFocusHappens) {
window.g_trackFocusHappens = false;
// To keep everything visible inside of the viewport when typing:
window.g_app.rootElt.style.transform = 'translate3d(0px, ' + window.document.scrollingElement.scrollTop + 'px, 0px)';
window.g_app.textboxElt.style.transform = 'translate3d(0px, 0px, 1px)';
let visibleHeight = (window.g_trackFocusHappensScreenBase || window.innerHeight) - window.document.scrollingElement.scrollTop;
if (window.innerHeight < visibleHeight) {
visibleHeight = window.innerHeight;
}
console.log('fitting in...', visibleHeight, window.document.scrollingElement.scrollTop, window.g_trackFocusHappensScreenBase);
window.g_trackFocusHappensScreenBase = 0;
window.g_app.fitTextareaInVisibleViewport(visibleHeight);
}
if (window.document.scrollingElement.scrollTop) {
console.log('restoring scroll pos...');
setTimeout(() => {
window.scrollTo(0, 0);
}, 300);
} else {
// To keep everything visible inside of the viewport when typing:
window.g_app.rootElt.style.transform = 'translate3d(0px, 0px, 0px)';
window.g_app.textboxElt.style.transform = 'translate3d(0px, 0px, 1px)';
}
}, true);
// On Android, we can get actual height only after 'resize' event if keyboard was appeared on the page reload!
window.addEventListener('resize', () => {
setTimeout(() => {
window.g_app.fitTextareaInVisibleViewport(window.innerHeight);
}, 100);
//window.console.log(window.performance.now(), 'resize', window.innerHeight, window.document.scrollingElement.scrollHeight,
// window.innerWidth, window.document.scrollingElement.scrollWidth, window.orientation);
if (window.navigator.platform === 'iPhone' || window.navigator.platform === 'iPad') {
// Dismiss the virtual keyboard if any resize happens, otherwise it'll break the layout.
// TODO: exclude this when resize happens on the initial keyboard activation.
//if (window.g_app.textboxElt && !window.g_app.textboxElt.hidden) {
// window.g_app.textboxElt.blur();
//}
}
}, true);
window.addEventListener('orientationchange', () => {
//console.log('orientationchange', window.innerHeight, window.document.scrollingElement.scrollHeight,
// window.innerWidth, window.document.scrollingElement.scrollWidth, window.orientation);
if (window.navigator.platform === 'iPhone' || window.navigator.platform === 'iPad') {
// Dismiss the virtual keyboard if any resize happens, otherwise it'll break the layout
if (window.g_app.textboxElt && !textboxElt.hidden) {
window.g_app.textboxElt.blur();
}
}
if ((window.orientation === 0 || window.orientation === 180) && window.navigator.appVersion.indexOf('Android') !== -1) {
// On Android, when rotating back to portrait from landscape, it's necessary to put the width to the low size,
// otherwise Android will scale the viewport to the smaller size
//window.g_skipOneResizeToPreventFontBoosting = true;
window.g_app.fitTextareaInVisibleViewport(window.innerHeight, window.innerHeight);
} else {
window.g_app.fitTextareaInVisibleViewport(window.innerHeight);
}
}, true);
// setTimeout() is necessary because on iOS window.innerHeight is bigger than visible area until the animation frame finishes
if (window.orientation && (window.orientation === -90 || window.orientation === 90)) {
// Only in landscape mode on iOS Safari,
// after the first requestAnimationFrame() and plus 10 milliseconds, Safari seems to report real
// visible area's height as window.innerHeight, and so we're ready to render the page!
window.setTimeout(() => {
//updateVisibleSizeInfo(window.innerWidth, window.innerHeight);
window.g_app.fitTextareaInVisibleViewport(window.innerHeight, window.innerWidth);
}, 10);
} else {
// updateVisibleSizeInfo(window.innerWidth, window.innerHeight);
window.g_app.fitTextareaInVisibleViewport(window.innerHeight, window.innerWidth);
}
window.document.documentElement.hidden = false;
window.document.body.hidden = false;
if (window.scrollY) {
window.scrollTo(0, 0);
}
app.devicePixelRatio = window.devicePixelRatio;
const width = window.innerWidth;
const height = window.innerHeight;
const rootElt = app.rootElt;
// --------------------------------------
// MAIN APP CODE
/*
const Zero = (c) => ({ c, v: 0 });
const One = (c) => ({ c, v: 1 });
const Dc = (c) => ({c});
const Unknown = (c) => ({});
function Mux () {
// Inputs
this.a = Dc;
this.b = Dc;
this.c = Dc;
// Output (ultimate reconnector)
this.x = (c) => this.c(c).v ? this.b(c) : this.a(c);
}
* /
function And ({ deps: { Mux, Zero }}) {
// Inputs
this.a = Dc;
this.b = Dc;
// Dependencies - this is a dep input. Could be a factory:
// given a ref exists, new connection should be made
// Object can do that totally locally ("prototype-like" base inheritance,
// it only changes configuration for the router to add corresponting routing table)
const mux0 = new Mux();
// Connections
mux0.a = Zero;
mux0.b = (c) => this.b(c);
mux0.c = (c) => this.a(c);
// Output (also is an additional connection)
this.x = (c) => mux0.x(c);
// Object itself is a function too ('read')
}
function Xor () {
// Internal interface: dependency types
const Dc = this.giveMeDcDependency();
const Mux = this.giveMeMuxDependency();
const Zero = this.giveMeZeroDependency();
const One = this.giveMeOneDependency();
// Inputs
this.a = Dc;
this.b = Dc;
// Dependencies
const mux0 = new Mux();
const mux1 = new Mux();
// Connections
mux0.a = One;
mux0.b = Zero;
mux0.c = (c) => this.b(c);
mux1.a = (c) => this.b(c);
mux1.b = (c) => mux0.x(c);
mux1.c = (c) => this.a(c);
// Output (also is an additional connection)
this.x = (c) => mux1.x(c);
// Object itself is a function too ('read')
}
const ProtoCell = {
// Inputs
giveMeTheSourceCode: Dc,
// Object itself is a function too ('read')
// Only output
accessCellInterface (c) {
// Read a pre-exiting input
const sourceCode = this.giveMeTheSourceCode(c);
// Self-reprogram (making dependencies resolved)
const updater = new Function(sourceCode);
updater.apply(this);
return this;
}
};
// This source code gets applied as a response
const muxSourceCode = `
// Internal interface is empty (this is an atomic/elementary cell).
// Internal interface: dependency types
const Dc = this.giveMeDcDependency();
// External interface membrane: 3 added inputs
this.a = Dc;
this.b = Dc;
this.c = Dc;
// External interface membrane: 1 added output (also is an additional connection)
// ultimate reconnector
this.x = (c) => this.c(c).v ? this.b(c) : this.a(c);
// TODO: reprogram instead of c ? b : c - needs a stack of single-use copies per causal tag
// Reprogrammed into "1"
//this.x = (c) => this.b(c);
// Reprogrammed into "0"
//this.x = (c) => this.a(c);
`;
// This source code gets applied as a response
const adderSourceCode = `
// Internal interface: dependency types
const Dc = this.giveMeDcDependency();
const Xor = this.giveMeXorDependency();
const And = this.giveMeAndDependency();
const Mux = this.giveMeMuxDependency();
const Zero = this.giveMeZeroDependency();
const One = this.giveMeOneDependency();
// Internal interface: 4 membranes
const xor0 = new Xor({ deps: { Mux, Zero, One }});
const xor1 = new Xor({ deps: { Mux, Zero, One }});
const xor2 = new Xor({ deps: { Mux, Zero, One }});
const and0 = new And({ deps: { Mux, Zero }});
// External interface membrane: 2 added inputs
this.a = [Dc, Dc];
this.b = [Dc, Dc];
// External interface membrane: 1 added output (also is an additional connection)
this.s = [Dc, Dc];
// Connections: 10 added connections: "2-bit adder circuit w/o carry"
xor0.a = (c) => this.a[0](c);
xor0.b = (c) => this.b[0](c);
xor1.a = (c) => this.a[1](c);
xor1.b = (c) => this.b[1](c);
xor2.a = (c) => and0.x(c);
xor2.b = (c) => xor1.x(c);
and0.a = (c) => this.a[0](c);
and0.b = (c) => this.b[0](c);
this.s[0] = (c) => xor0.x(c);
this.s[1] = (c) => xor2.x(c);
`;
const a0 = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1];
const a1 = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1];
const b0 = [0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1];
const b1 = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1];
const e0 = [0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1];
const e1 = [0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1];
const toVal = (arr) => (c) => arr[c] ? One(c) : Zero(c);
const createAnAdder = ({ causalTag, ProtoCell, Dc, Xor, And, Mux, Zero, One }) => {
// Create a copy of a ProtoCell
const protoCell = { ...ProtoCell };
protoCell.giveMeTheSourceCode = (c) => adderSourceCode;
// Provide dependencies as inputs (todo: rewrite them to be routing tables)
protoCell.giveMeDcDependency = (c) => Dc;
protoCell.giveMeXorDependency = (c) => Xor;
protoCell.giveMeAndDependency = (c) => And;
protoCell.giveMeMuxDependency = (c) => Mux;
protoCell.giveMeZeroDependency = (c) => Zero;
protoCell.giveMeOneDependency = (c) => One;
// Changes the object and returns 'this'
const protoCellMutatedIntoAdder = protoCell.accessCellInterface(causalTag);
return protoCellMutatedIntoAdder;
};
const createAMux = ({ causalTag, ProtoCell, Dc }) => {
// Create a copy of a ProtoCell
const protoCell = { ...ProtoCell };
protoCell.giveMeTheSourceCode = (c) => muxSourceCode;
// Provide dependencies as inputs (todo: rewrite them to be routing tables)
protoCell.giveMeDcDependency = (c) => Dc;
// Changes the object and returns 'this'
const protoCellMutatedIntoMux = protoCell.accessCellInterface(causalTag);
return protoCellMutatedIntoMux;
};
*/
const theApp = {
membrane ({ cause, user }) {
return this;
}
};
app.render = () => {
/*
const protoCellMutatedIntoAdder = createAnAdder({ causalTag: 1, ProtoCell, Dc, Xor, And,
Mux: createAMux({ causalTag: 1, ProtoCell, Dc }),
Zero, One });
// Connect inputs:
protoCellMutatedIntoAdder.a = [toVal(a0), toVal(a1)];
protoCellMutatedIntoAdder.b = [toVal(b0), toVal(b1)];
let result = '';
// Partially ordered acyclic causal graph node.
for (let causalTag = 0; causalTag < 16; ++causalTag) {
// Read outputs:
const s0 = protoCellMutatedIntoAdder.s[0](causalTag);
const s1 = protoCellMutatedIntoAdder.s[1](causalTag);
// Print formatting
const a = a0[causalTag] + 2 * a1[causalTag];
const b = b0[causalTag] + 2 * b1[causalTag];
result += `<div style="margin: 16px;">${ a } + ${ b } = ${ s0.v + 2 * s1.v }</div>`;
}
*/
// At startup, proto-cell membrane output port's data bits are plugged in into the OS,
// so the OS can pull these bits describing the internal state of the cell.
// Initial app must have its input port connected to the OS, so it can be programmed.
// The app must be allowed to ask questions like,
// - What is my port configuration?
// - What are my dependencies?
// - What is my routing table?
//
// This port data is a typed image, consisting out of many one-bit functions.
// Calling it as a single function pulls all containing data bits in separate threads as function
// calls, having the same user ID and causal tag (request ID):
const initialOutputPortProvidedForOsConsumption = ({ cause, user }) => {};
// Launch: pull the output port's data to request contents of the app's membrane (it tells us
// when new ports added / removed / provided to the inner ownership):
// Output ports contain information about ports on the membrane;
// about routing circuit inside;
// about provided types (available on the membrane)
// storage of a type can be serialized - structural transfer,
// takes a series of elementary commands (can target an empty proto-cell's input,
// and it will make it a copy of the original cell)
let cause = 1;
let user = 'OS';
// Calling a function is equivalent to reading data on that port.
// Please, note that we only fetch changes. State snapshots must be implemented explicitly
// as a substructure with a history trail allowing to retrieve pre-existing state (not a default feature).
// So, initially, this call does nothing, even inside of the app there is an internal structure:
const result = initialOutputPortProvidedForOsConsumption({ cause, user });
rootElt.innerHTML = `
<h1 style="margin: 12px;">Reprogrammable JS set ${ window.g_app.modifiedAt }</h1>
${ result }
<h1 style="position: absolute; bottom: 0; left: 0;">LB</h1>
<h1 style="position: absolute; bottom: 0; right: 0;">RB</h1>
`;
}
// --------------------------------------
// First render
requestAnimationFrame(window.g_app.render);
}, 0);
const createTextbox = () => {
const textboxElt = window.document.createElement('textarea');
/*
window.subListeners({
textarea: textboxElt,
});
*/
textboxElt.hidden = true;
// textboxElt.setAttribute('style', 'width: ' + window.innerWidth + 'px; height: 16px; min-height: 16px;');
textboxElt.style.width = window.innerWidth + 'px';
textboxElt.style.height = '16px';
textboxElt.style.minHeight = '16px';
// textboxElt.style.maxHeight = '99999px';
// This is how we enable passwords!
// textboxElt.style['-webkit-text-security'] = 'circle';
// For email addresses, URLs, etc.
// Options are:
// - none
// - sentences: Automatically capitalize the first letter of sentences.
// - words: Automatically capitalize the first letter of words.
// - characters: Automatically capitalize all characters.
// should be disabled for emails and passwords!
textboxElt.setAttribute('autocapitalize', 'sentences');
// Android supports this beautifully, Safari support will come.
// Because keyboard type switch might be costly, we can just keep the standard keyboard for all fields.
// textboxElt.setAttribute('inputmode', 'numeric');
// Multiline hints are not supported (it's wrapped on next lines though):
textboxElt.setAttribute('placeholder', 'Please, type here some multiple lines. Thank you!');
textboxElt.setAttribute('spellcheck', 'false');
// Never allow any autocomplete! Unfortunately, on iOS, enabling this
// feature makes the virtual keyboard to have an unpredictable and dynamic height.
textboxElt.setAttribute('autocomplete', 'off');
// This works on iOS, but the VK gets a dynamic height, we must avoid these 2
// textboxElt.setAttribute('autocomplete', 'email');
// textboxElt.setAttribute('autocomplete', 'name');
textboxElt.style.transform = 'translate3d(0px, 0px, 1px)';
// textboxElt.innerText = (() => { let a = ''; for (let i = 0; i < 2000; ++i) a += '\\n'; return a; })();
/*
const formElt = window.document.createElement('form');
formElt.setAttribute('action', '.');
formElt.appendChild(textboxElt);
window.document.body.appendChild(formElt);
*/
window.document.body.appendChild(textboxElt);
let autofocusHappened = true;
const editText = () => {
// console.log('BASE', window.document.scrollingElement.scrollHeight);
// console.log('MARGIN-TOP', window.innerHeight);
// window.document.body.style.overflow = 'hidden';
// window.document.documentElement.style.overflow = 'hidden';
if (!textboxElt.hidden) {
console.log('double edit text');
return;
}
// iOS Safari only:
if (window.navigator.platform === 'iPhone' || window.navigator.platform === 'iPad') {
if (window.orientation === 90 || window.orientation === -90) {
window.g_trackFocusHappensScreenBase = window.document.scrollingElement.scrollHeight;
} else {
if (window.document.scrollingElement.scrollHeight < window.innerHeight) {
window.g_trackFocusHappensScreenBase = window.document.scrollingElement.scrollHeight;
} else {
window.g_trackFocusHappensScreenBase = window.innerHeight;
}
}
// window.innerHeight is not enough to make correct amount of scrolling in the landscape mode,
// so we add 80 px to it.
textboxElt.style.transform = 'translate3d(0px, ' + (window.innerHeight + 80) + 'px, 1px)';
}
textboxElt.hidden = false;
// textboxElt.value = '';
// window.document.body.appendChild(textboxElt);
autofocusHappened = false;
textboxElt.focus();
};
let textboxTouchesCount = 0;
let textboxTouchedAtYcoord = -10000;
textboxElt.addEventListener('touchstart', e => {
textboxTouchesCount += e.changedTouches.length;
if (textboxTouchesCount > 1) {
e.stopPropagation();
e.preventDefault();
console.log('start canceled');
} else {
textboxTouchedAtYcoord = e.changedTouches[0].clientY;
}
}, { capture: true, passive: false });
textboxElt.addEventListener('touchmove', e => {
const newY = e.changedTouches[0].clientY;
if (textboxElt.scrollTop <= 0 && textboxTouchedAtYcoord < newY ||
textboxElt.scrollTop >= textboxElt.scrollHeight - textboxElt.clientHeight && textboxTouchedAtYcoord > newY) {
e.stopPropagation();
e.preventDefault();
console.log('move canceled', textboxTouchedAtYcoord, newY);
textboxTouchedAtYcoord = newY;
}
}, { capture: true, passive: false });
textboxElt.addEventListener('touchend', e => {
if (textboxTouchesCount > 1) {
e.stopPropagation();
e.preventDefault();
console.log('end canceled');
}
textboxTouchesCount -= e.changedTouches.length;
}, { capture: true, passive: false });
textboxElt.addEventListener('blur', () => {
console.log('blur', window.innerHeight, window.document.scrollingElement.scrollTop);
// iOS Safari only:
if (window.navigator.platform === 'iPhone' || window.navigator.platform === 'iPad') {
textboxElt.style.transform = 'translate3d(0px, ' + (window.innerHeight + 80) + 'px, 1px)';
}
textboxElt.hidden = true;
// textboxElt.parentElement.removeChild(textboxElt);
window.g_app.fitTextareaInVisibleViewport(window.innerHeight);
}, true);
textboxElt.addEventListener('focus', e => {
if (autofocusHappened) {
// e.stopPropagation();
// e.preventDefault();
textboxElt.blur();
return;
} else {
autofocusHappened = true;
}
// iOS Safari only:
if (window.navigator.platform === 'iPhone' || window.navigator.platform === 'iPad') {
console.log('focus');
window.g_trackFocusHappens = true;
} else if (window.navigator.appVersion.indexOf('Android') !== -1) {
// When we receive the 'resize' event we must set the textarea size correctly!
window.g_androidTextareaSizeOnResize = true;
console.log(window.innerHeight);
} else {
// Desktop full-screen browser
window.document.body.style.overflow = 'hidden';
window.document.documentElement.style.overflow = 'hidden';
window.g_app.fitTextareaInVisibleViewport(window.innerHeight);
}
}, false);
window.g_app.textboxElt = textboxElt;
window.g_app.editText = editText;
};
window.g_app.createTextbox = createTextbox;
// Create a hidden textboxElt otherwise it won't appear on touchend:
if (!window.g_app.textboxElt) {
window.g_app.createTextbox();
}
}
</script><style>
html {
--visible-width: 16px;
--visible-height: 16px;
transform-style: preserve-3d;
}
html, body {
overflow: visible;
height: 0px;
width: 0px;
background-color: transparent !important;
}
html.with-virtual-keyboard, html.with-virtual-keyboard > body {
height: var(--visible-height);
min-height: var(--visible-height);
width: var(--visible-width);
}
body {
overflow: hidden;
margin: 0px;
}
html, body, #root, textarea {
-webkit-text-size-adjust: 100%;
text-size-adjust: 100%;
max-height: 999999px;
-webkit-touch-callout: none;
-webkit-tap-highlight-color: rgba(0,0,0,0);
}
textarea:focus {
outline-offset: 0px;
}
:focus {
outline: none;
}
textarea::placeholder {
color: #88cc88;
}
textarea {
-webkit-overflow-scrolling : touch !important;
outline: none;
border: none;
border-width: 0px;
border-radius: 0px;
border-image-width: 0px;
background-color: transparent;
resize: none;
padding: 0px;
font-size: 36px;
line-height: 42px;
}
#root {
transform: translate3d(0px, 0px, 0px);
position: absolute;
top: 0px;
left: 0px;
}
h1 {
margin: 0;
}
</style></head><body><div id="root" width="16px" height="16px" draggable="true"></div><input hidden="" id="1" type="file" style="position: absolute; min-height: 44px; width: 200px; background-color: red; transform: translate3d(0, 0, 2px);"></body></html>