/
js_utils.ml
1258 lines (1171 loc) · 46.5 KB
/
js_utils.ml
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
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(* This file is part of Learn-OCaml.
*
* Copyright (C) 2015 OCamlPro: Grégoire Henry, Çağdaş Bozman.
* Copyright (C) 2012 Vincent Balat, Benedikt Becker (for the 'Manip' module)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published by
* the Free Software Foundation, with linking exception;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. *)
open Js_of_ocaml
open Js_of_ocaml_tyxml
let doc = Dom_html.document
let window = Dom_html.window
(* let loc = Js.Unsafe.variable "location" *)
let alert s = window##(alert (Js.string s))
let confirm s = Js.to_bool (window##(confirm (Js.string s)))
let js_log obj = Firebug.console##(log obj)
let js_debug obj = Firebug.console##(debug obj)
let js_warn obj = Firebug.console##(warn obj)
let js_error obj = Firebug.console##(error obj)
let rec pos8_to_pos16 line c8 i8 i16 stop_before =
if i8 >= c8 || i8 >= String.length line then i16 else
let di8, di16 = match line.[i8] with
| '\x00' .. '\x7F' -> 1, 1
| '\xC2' .. '\xDF' -> 2, 1
| '\xE0' .. '\xEF' -> 3, 1
| '\xF0' .. '\xF4' -> 4, 2
| _ -> 1, 1 in
if stop_before && i8 <= c8 && c8 < i8 + di8 then i16
else pos8_to_pos16 line c8 (i8+di8) (i16+di16) stop_before
let pos8_to_pos16 ?(stop_before = true) line c8 =
pos8_to_pos16 line c8 0 0 stop_before
let log fmt =
Format.kfprintf
(fun _ -> Firebug.console##(log (Js.string (Format.flush_str_formatter ()))))
Format.str_formatter
fmt
let debug fmt =
Format.kfprintf
(fun _ -> Firebug.console##(debug (Js.string (Format.flush_str_formatter ()))))
Format.str_formatter
fmt
let warn fmt =
Format.kfprintf
(fun _ -> Firebug.console##(warn (Js.string (Format.flush_str_formatter ()))))
Format.str_formatter
fmt
let error fmt =
Format.kfprintf
(fun _ -> Firebug.console##(error (Js.string (Format.flush_str_formatter ()))))
Format.str_formatter
fmt
let reload () = window##.location##reload
let get_lang () =
match Js.Optdef. to_option (Dom_html.window##.navigator##.language) with
| Some l -> Some (Js.to_string l)
| None ->
match Js.Optdef.to_option (Dom_html.window##.navigator##.userLanguage)
with
| Some l -> Some (Js.to_string l)
| None -> None
module Manip = struct
let option_map f = function None -> None | Some x -> Some (f x)
exception Error of string
let manip_error fmt =
Format.ksprintf
(fun s -> debug "%s" s; raise (Error s))
fmt
open Tyxml_js
let id x = x
let get_node = Html5.toelt
let get_elt name elt : Dom_html.element Js.t =
Js.Opt.case
(Dom_html.CoerceTo.element (Html5.toelt elt))
(fun () ->
manip_error
"Cannot call %s on a node which is not an element"
name)
id
let html_doc_constr : Dom_html.document Js.constr =
Js.Unsafe.global##._HTMLDocument
let document elt =
let elt = get_elt "document" elt in
let rec loop (elt : Dom.node Js.t) =
if Js.instanceof elt html_doc_constr
then (Obj.magic elt : Dom_html.document Js.t)
else
Js.Opt.case
(elt##.parentNode)
(fun () -> (Obj.magic elt : Dom_html.document Js.t))
loop
in
loop (elt : Dom_html.element Js.t :> Dom.node Js.t)
let window elt =
let doc = document elt in
(Obj.magic doc)##.defaultView
let clone ?(deep=false) elt =
let elt = get_elt "clone" elt in
Obj.magic (elt##(cloneNode (Js.bool deep)))
let setInnerHtml elt s =
let elt = get_elt "setInnerHtml" elt in
elt##.innerHTML := Js.string s
let setInnerText elt s =
let elt = get_elt "setInnerText" elt in
elt##.textContent := Js.some (Js.string s)
let hasClass elt s =
let elt = get_elt "addClass" elt in
Js.to_bool
elt##.classList##(contains (Js.string s))
let addClass elt s =
let elt = get_elt "addClass" elt in
elt##.classList##(add (Js.string s))
let removeClass elt s =
let elt = get_elt "removeClass" elt in
elt##.classList##(remove (Js.string s))
let toggleClass elt s =
let elt = get_elt "toggleClass" elt in
Js.to_bool
elt##.classList##(toggle (Js.string s))
let raw_appendChild ?before node elt2 =
match before with
| None -> ignore(node##(appendChild (get_node elt2)))
| Some elt3 ->
let node3 = get_node elt3 in
ignore(node##(insertBefore (get_node elt2) (Js.some node3)))
let raw_appendChildren ?before node elts =
match before with
| None ->
List.iter (fun elt2 -> ignore(node##(appendChild (get_node elt2)))) elts
| Some elt3 ->
let node3 = get_node elt3 in
List.iter (fun elt2 -> ignore(node##(insertBefore (get_node elt2) (Js.some node3)))) elts
let raw_insertChildAfter node1 node2 elt3 =
Js.Opt.case
(node2##.nextSibling)
(fun () ->
ignore(node1##(appendChild (get_node elt3))))
(fun node2 ->
ignore(node1##(insertBefore (get_node elt3) (Js.some node2))))
let raw_insertChildrenAfter node1 node2 elts =
Js.Opt.case
(node2##.nextSibling)
(fun () ->
List.iter (fun elt3 ->
ignore(node1##(appendChild (get_node elt3)))))
(fun node2 ->
List.iter (fun elt3 ->
ignore(node1##(insertBefore (get_node elt3) (Js.some node2)))))
elts
let raw_removeChild node1 elt2 =
let node2 = get_node elt2 in
ignore(node1##(removeChild node2))
let raw_replaceChild node1 elt2 elt3 =
let node2 = get_node elt2 in
ignore(node1##replaceChild node2 (get_node elt3))
let raw_removeChildren node =
let childrens = Dom.list_of_nodeList (node##.childNodes) in
List.iter (fun c -> ignore(node##(removeChild c))) childrens
let raw_replaceChildren node elts =
raw_removeChildren node;
List.iter (fun elt -> ignore(node##(appendChild (get_node elt)))) elts
let nth elt n =
let node = get_node elt in
let res = Js.Opt.bind (node##.childNodes##(item n)) (fun node ->
Js.Opt.map (Dom.CoerceTo.element node) (fun node ->
Of_dom.of_element (Dom_html.element node)
)
) in
Js.Opt.to_option res
let by_id n =
let res = Js.Opt.bind (Dom_html.window##.document##(getElementById (Js.string n))) (fun node ->
Js.Opt.map (Dom.CoerceTo.element node) (fun node ->
Of_dom.of_element (Dom_html.element node)
)
) in
Js.Opt.to_option res
let by_classname n =
Dom.list_of_nodeList
(Dom_html.window##.document##(getElementsByClassName (Js.string n)))
|> List.map (fun n -> Of_dom.of_element (Dom_html.element n))
(* let rec tolist acc n =
* if n < 0 then acc
* else
* let acc =
* Js.Opt.case (nodelist##item n)
* (fun () -> acc)
* (fun node -> Of_dom.of_element (Dom_html.element node) :: acc)
* in
* tolist acc (n-1)
* in
* tolist [] nodelist##.length *)
let childLength elt =
let node = get_node elt in
node##.childNodes##.length
let appendChild ?before elt1 elt2 =
let node = get_node elt1 in
raw_appendChild ?before node elt2
let appendChildren ?before elt1 elts =
let node = get_node elt1 in
raw_appendChildren ?before node elts
let insertChildAfter elt1 elt2 elt3 =
let node1 = get_node elt1 in
let node2 = get_node elt2 in
raw_insertChildAfter node1 node2 elt3
let insertChildrenAfter elt1 elt2 elts =
let node1 = get_node elt1 in
let node2 = get_node elt2 in
raw_insertChildrenAfter node1 node2 elts
let removeChild elt1 elt2 =
let node1 = get_node elt1 in
raw_removeChild node1 elt2
let removeSelf elt =
let node = get_node elt in
let res = Js.Opt.bind (node##.parentNode) (fun node ->
Js.Opt.map (Dom.CoerceTo.element node) (fun node ->
Of_dom.of_element (Dom_html.element node)
)
) in
Js.Opt.iter res (fun p -> removeChild p elt)
let appendChildFirst p c =
let before = nth p 0 in
appendChild ?before p c
let replaceChild elt1 elt2 elt3 =
let node1 = get_node elt1 in
raw_replaceChild node1 elt2 elt3
let replaceSelf elt1 elt2 =
Js.Opt.iter (get_node elt1)##.parentNode @@ fun parent ->
raw_replaceChild parent elt2 elt1
let removeChildren elt =
let node = get_node elt in
raw_removeChildren node
let replaceChildren elt elts =
let node = get_node elt in
raw_replaceChildren node elts
let children elt =
let node = get_node elt in
List.map Html5.tot (Dom.list_of_nodeList (node##.childNodes))
let appendToBody ?before elt2 =
let body = (Of_dom.of_body Dom_html.window##.document##.body) in
appendChild ?before body elt2
let appendToHead ?before elt2 =
let head = (Of_dom.of_head Dom_html.window##.document##.head) in
appendChild ?before head elt2
let get_elt_input name elt : Dom_html.inputElement Js.t =
Js.Opt.case
(Dom_html.CoerceTo.input (get_elt name elt))
(fun () -> failwith (Printf.sprintf "Non 'input' node (%s)" name))
id
let get_elt_select name elt : Dom_html.selectElement Js.t =
Js.Opt.case
(Dom_html.CoerceTo.select (get_elt name elt))
(fun () -> failwith (Printf.sprintf "Non 'select' node (%s)" name))
id
let get_elt_textarea name elt : Dom_html.textAreaElement Js.t =
Js.Opt.case
(Dom_html.CoerceTo.textarea (get_elt name elt))
(fun () -> failwith (Printf.sprintf "Non element node (%s)" name))
id
let get_elt_img name elt : Dom_html.imageElement Js.t =
Js.Opt.case
(Dom_html.CoerceTo.img (get_elt name elt))
(fun () -> failwith (Printf.sprintf "Non element node (%s)" name))
id
let scrollIntoView ?(bottom = false) elt =
let elt = get_elt "Css.background" elt in
elt##(scrollIntoView (Js.bool (not bottom)))
type disable = < disabled: bool Js.t Js.prop >
let get_disable_elt name elt : disable Js.t =
if Js.undefined == (Js.Unsafe.coerce @@ Html5.toelt elt)##.disabled then
manip_error
"Cannot call %s on a node without a 'disable' property"
name;
Js.Unsafe.coerce @@ Html5.toelt elt
let disable elt =
let elt = get_disable_elt "disable" elt in
elt##.disabled := Js._true
let enable elt =
let elt = get_disable_elt "enable" elt in
elt##.disabled := Js._false
type focus = < focus: unit Js.meth >
let get_focus_elt name elt : focus Js.t =
if Js.undefined == (Js.Unsafe.coerce @@ Html5.toelt elt)##.focus then
manip_error
"Cannot call %s on a node without a 'focus' property"
name;
Js.Unsafe.coerce @@ Html5.toelt elt
let focus elt =
let elt = get_focus_elt "focus" elt in
elt##focus
type blur = < blur: unit Js.meth >
let get_blur_elt name elt : blur Js.t =
if Js.undefined == (Js.Unsafe.coerce @@ Html5.toelt elt)##.blur then
manip_error
"Cannot call %s on a node without a 'blur' property"
name;
Js.Unsafe.coerce @@ Html5.toelt elt
let blur elt =
let elt = get_blur_elt "blur" elt in
elt##blur
type value = < value: Js.js_string Js.t Js.prop >
let get_value_elt name elt : value Js.t =
if Js.undefined == (Js.Unsafe.coerce @@ Html5.toelt elt)##.value then
manip_error
"Cannot call %s on a node without a 'value' property"
name;
Js.Unsafe.coerce @@ Html5.toelt elt
let value elt =
let elt = get_value_elt "value" elt in
Js.to_string elt##.value
module Elt = struct
let body =
try Of_dom.of_body (Dom_html.window##.document##.body)
with _ -> Obj.magic Js.undefined (* For workers... *)
let active () =
(Js.Unsafe.coerce Dom_html.window##.document)##.activeElement
end
module Ev = struct
type ('a, 'b) ev = 'a Html5.elt -> ('b Js.t -> bool) -> unit
type ('a,'b) ev_unit = 'a Html5.elt -> ('b Js.t -> unit) -> unit
let bool_cb f = Dom_html.handler (fun e -> Js.bool (f e))
let onkeyup elt f =
let elt = get_elt "Ev.onkeyup" elt in
elt##.onkeyup := (bool_cb f)
let onkeydown elt f =
let elt = get_elt "Ev.onkeydown" elt in
elt##.onkeydown := (bool_cb f)
let onmouseup elt f =
let elt = get_elt "Ev.onmouseup" elt in
elt##.onmouseup := (bool_cb f)
let onmousedown elt f =
let elt = get_elt "Ev.onmousedown" elt in
elt##.onmousedown := (bool_cb f)
let onmouseout elt f =
let elt = get_elt "Ev.onmouseout" elt in
elt##.onmouseout := (bool_cb f)
let onmouseover elt f =
let elt = get_elt "Ev.onmouseover" elt in
elt##.onmouseover := (bool_cb f)
let onclick elt f =
let elt = get_elt "Ev.onclick" elt in
elt##.onclick := (bool_cb f)
let ondblclick elt f =
let elt = get_elt "Ev.ondblclick" elt in
elt##.ondblclick := (bool_cb f)
let onload elt f =
let elt = get_elt_img "Ev.onload" elt in
elt##.onload := (bool_cb f)
let onerror elt f =
let elt = get_elt_img "Ev.onerror" elt in
elt##.onerror := (bool_cb f)
let onabort elt f =
let elt = get_elt_img "Ev.onabort" elt in
elt##.onabort := (bool_cb f)
let onfocus elt f =
let elt = get_elt_input "Ev.onfocus" elt in
elt##.onfocus := (bool_cb f)
let onblur elt f =
let elt = get_elt_input "Ev.onblur" elt in
elt##.onblur := (bool_cb f)
let onfocus_textarea elt f =
let elt = get_elt_textarea "Ev.onfocus" elt in
elt##.onfocus := (bool_cb f)
let onblur_textarea elt f =
let elt = get_elt_textarea "Ev.onblur" elt in
elt##.onblur := (bool_cb f)
let onscroll elt f =
let elt = get_elt "Ev.onscroll" elt in
elt##.onscroll := (bool_cb f)
let onreturn elt f =
let f ev =
let key = ev##.keyCode in
if key = 13 then f ev;
true in
onkeydown elt f
let onchange elt f =
let elt = get_elt_input "Ev.onchange" elt in
elt##.onchange := (bool_cb f)
let onchange_select elt f =
let elt = get_elt_select "Ev.onchange_select" elt in
elt##.onchange := (bool_cb f)
let oninput elt f =
let elt = get_elt_input "Ev.oninput" elt in
elt##.oninput := (bool_cb f)
end
module Attr = struct
let clientWidth elt =
let elt = get_elt "Attr.clientWidth" elt in
elt##.clientWidth
let clientHeight elt =
let elt = get_elt "Attr.clientHeight" elt in
elt##.clientHeight
let offsetWidth elt =
let elt = get_elt "Attr.offsetWidth" elt in
elt##.offsetWidth
let offsetHeight elt =
let elt = get_elt "Attr.offsetHeight" elt in
elt##.offsetHeight
let clientLeft elt =
let elt = get_elt "Attr.clientLeft" elt in
elt##.clientLeft
let clientTop elt =
let elt = get_elt "Attr.clientTop" elt in
elt##.clientTop
end
module Css = struct
let background elt =
let elt = get_elt "Css.background" elt in
Js.to_bytestring (elt##.style##.background)
let backgroundAttachment elt =
let elt = get_elt "Css.backgroundAttachment" elt in
Js.to_bytestring (elt##.style##.backgroundAttachment)
let backgroundColor elt =
let elt = get_elt "Css.backgroundColor" elt in
Js.to_bytestring (elt##.style##.backgroundColor)
let backgroundImage elt =
let elt = get_elt "Css.backgroundImage" elt in
Js.to_bytestring (elt##.style##.backgroundImage)
let backgroundPosition elt =
let elt = get_elt "Css.backgroundPosition" elt in
Js.to_bytestring (elt##.style##.backgroundPosition)
let backgroundRepeat elt =
let elt = get_elt "Css.backgroundRepeat" elt in
Js.to_bytestring (elt##.style##.backgroundRepeat)
let border elt =
let elt = get_elt "Css.border" elt in
Js.to_bytestring (elt##.style##.border)
let borderBottom elt =
let elt = get_elt "Css.borderBottom" elt in
Js.to_bytestring (elt##.style##.borderBottom)
let borderBottomColor elt =
let elt = get_elt "Css.borderBottomColor" elt in
Js.to_bytestring (elt##.style##.borderBottomColor)
let borderBottomStyle elt =
let elt = get_elt "Css.borderBottomStyle" elt in
Js.to_bytestring (elt##.style##.borderBottomStyle)
let borderBottomWidth elt =
let elt = get_elt "Css.borderBottomWidth" elt in
Js.to_bytestring (elt##.style##.borderBottomWidth)
let borderBottomWidthPx elt =
let elt = get_elt "Css.borderBottomWidthPx" elt in
Js.parseInt (elt##.style##.borderBottomWidth)
let borderCollapse elt =
let elt = get_elt "Css.borderCollapse" elt in
Js.to_bytestring (elt##.style##.borderCollapse)
let borderColor elt =
let elt = get_elt "Css.borderColor" elt in
Js.to_bytestring (elt##.style##.borderColor)
let borderLeft elt =
let elt = get_elt "Css.borderLeft" elt in
Js.to_bytestring (elt##.style##.borderLeft)
let borderLeftColor elt =
let elt = get_elt "Css.borderLeftColor" elt in
Js.to_bytestring (elt##.style##.borderLeftColor)
let borderLeftStyle elt =
let elt = get_elt "Css.borderLeftStyle" elt in
Js.to_bytestring (elt##.style##.borderLeftStyle)
let borderLeftWidth elt =
let elt = get_elt "Css.borderLeftWidth" elt in
Js.to_bytestring (elt##.style##.borderLeftWidth)
let borderLeftWidthPx elt =
let elt = get_elt "Css.borderLeftWidthPx" elt in
Js.parseInt (elt##.style##.borderLeftWidth)
let borderRight elt =
let elt = get_elt "Css.borderRight" elt in
Js.to_bytestring (elt##.style##.borderRight)
let borderRightColor elt =
let elt = get_elt "Css.borderRightColor" elt in
Js.to_bytestring (elt##.style##.borderRightColor)
let borderRightStyle elt =
let elt = get_elt "Css.borderRightStyle" elt in
Js.to_bytestring (elt##.style##.borderRightStyle)
let borderRightWidth elt =
let elt = get_elt "Css.borderRightWidth" elt in
Js.to_bytestring (elt##.style##.borderRightWidth)
let borderRightWidthPx elt =
let elt = get_elt "Css.borderRightWidthPx" elt in
Js.parseInt (elt##.style##.borderRightWidth)
let borderSpacing elt =
let elt = get_elt "Css.borderSpacing" elt in
Js.to_bytestring (elt##.style##.borderSpacing)
let borderStyle elt =
let elt = get_elt "Css.borderStyle" elt in
Js.to_bytestring (elt##.style##.borderStyle)
let borderTop elt =
let elt = get_elt "Css.borderTop" elt in
Js.to_bytestring (elt##.style##.borderTop)
let borderTopColor elt =
let elt = get_elt "Css.borderTopColor" elt in
Js.to_bytestring (elt##.style##.borderTopColor)
let borderTopStyle elt =
let elt = get_elt "Css.borderTopStyle" elt in
Js.to_bytestring (elt##.style##.borderTopStyle)
let borderTopWidth elt =
let elt = get_elt "Css.borderTopWidth" elt in
Js.to_bytestring (elt##.style##.borderTopWidth)
let borderTopWidthPx elt =
let elt = get_elt "Css.borderTopWidthPx" elt in
Js.parseInt (elt##.style##.borderTopWidth)
let borderWidth elt =
let elt = get_elt "Css.borderWidth" elt in
Js.to_bytestring (elt##.style##.borderWidth)
let borderWidthPx elt =
let elt = get_elt "Css.borderWidthPx" elt in
Js.parseInt (elt##.style##.borderWidth)
let bottom elt =
let elt = get_elt "Css.bottom" elt in
Js.to_bytestring (elt##.style##.bottom)
let captionSide elt =
let elt = get_elt "Css.captionSide" elt in
Js.to_bytestring (elt##.style##.captionSide)
let clear elt =
let elt = get_elt "Css.clear" elt in
Js.to_bytestring (elt##.style##.clear)
let clip elt =
let elt = get_elt "Css.clip" elt in
Js.to_bytestring (elt##.style##.clip)
let color elt =
let elt = get_elt "Css.color" elt in
Js.to_bytestring (elt##.style##.color)
let content elt =
let elt = get_elt "Css.content" elt in
Js.to_bytestring (elt##.style##.content)
let counterIncrement elt =
let elt = get_elt "Css.counterIncrement" elt in
Js.to_bytestring (elt##.style##.counterIncrement)
let counterReset elt =
let elt = get_elt "Css.counterReset" elt in
Js.to_bytestring (elt##.style##.counterReset)
let cssFloat elt =
let elt = get_elt "Css.cssFloat" elt in
Js.to_bytestring (elt##.style##.cssFloat)
let cssText elt =
let elt = get_elt "Css.cssText" elt in
Js.to_bytestring (elt##.style##.cssText)
let cursor elt =
let elt = get_elt "Css.cursor" elt in
Js.to_bytestring (elt##.style##.cursor)
let direction elt =
let elt = get_elt "Css.direction" elt in
Js.to_bytestring (elt##.style##.direction)
let display elt =
let elt = get_elt "Css.display" elt in
Js.to_bytestring (elt##.style##.display)
let emptyCells elt =
let elt = get_elt "Css.emptyCells" elt in
Js.to_bytestring (elt##.style##.emptyCells)
let font elt =
let elt = get_elt "Css.font" elt in
Js.to_bytestring (elt##.style##.font)
let fontFamily elt =
let elt = get_elt "Css.fontFamily" elt in
Js.to_bytestring (elt##.style##.fontFamily)
let fontSize elt =
let elt = get_elt "Css.fontSize" elt in
Js.to_bytestring (elt##.style##.fontSize)
let fontStyle elt =
let elt = get_elt "Css.fontStyle" elt in
Js.to_bytestring (elt##.style##.fontStyle)
let fontVariant elt =
let elt = get_elt "Css.fontVariant" elt in
Js.to_bytestring (elt##.style##.fontVariant)
let fontWeight elt =
let elt = get_elt "Css.fontWeight" elt in
Js.to_bytestring (elt##.style##.fontWeight)
let height elt =
let elt = get_elt "Css.height" elt in
Js.to_bytestring (elt##.style##.height)
let heightPx elt =
let elt = get_elt "Css.heightPx" elt in
Js.parseInt (elt##.style##.height)
let left elt =
let elt = get_elt "Css.left" elt in
Js.to_bytestring (elt##.style##.left)
let leftPx elt =
let elt = get_elt "Css.leftPx" elt in
Js.parseInt (elt##.style##.left)
let letterSpacing elt =
let elt = get_elt "Css.letterSpacing" elt in
Js.to_bytestring (elt##.style##.letterSpacing)
let lineHeight elt =
let elt = get_elt "Css.lineHeight" elt in
Js.to_bytestring (elt##.style##.lineHeight)
let listStyle elt =
let elt = get_elt "Css.listStyle" elt in
Js.to_bytestring (elt##.style##.listStyle)
let listStyleImage elt =
let elt = get_elt "Css.listStyleImage" elt in
Js.to_bytestring (elt##.style##.listStyleImage)
let listStylePosition elt =
let elt = get_elt "Css.listStylePosition" elt in
Js.to_bytestring (elt##.style##.listStylePosition)
let listStyleType elt =
let elt = get_elt "Css.listStyleType" elt in
Js.to_bytestring (elt##.style##.listStyleType)
let margin elt =
let elt = get_elt "Css.margin" elt in
Js.to_bytestring (elt##.style##.margin)
let marginBottom elt =
let elt = get_elt "Css.marginBottom" elt in
Js.to_bytestring (elt##.style##.marginBottom)
let marginBottomPx elt =
let elt = get_elt "Css.marginBottomPx" elt in
Js.parseInt (elt##.style##.marginBottom)
let marginLeft elt =
let elt = get_elt "Css.marginLeft" elt in
Js.to_bytestring (elt##.style##.marginLeft)
let marginLeftPx elt =
let elt = get_elt "Css.marginLeftPx" elt in
Js.parseInt (elt##.style##.marginLeft)
let marginRight elt =
let elt = get_elt "Css.marginRight" elt in
Js.to_bytestring (elt##.style##.marginRight)
let marginRightPx elt =
let elt = get_elt "Css.marginRightPx" elt in
Js.parseInt (elt##.style##.marginRight)
let marginTop elt =
let elt = get_elt "Css.marginTop" elt in
Js.to_bytestring (elt##.style##.marginTop)
let marginTopPx elt =
let elt = get_elt "Css.marginTopPx" elt in
Js.parseInt (elt##.style##.marginTop)
let maxHeight elt =
let elt = get_elt "Css.maxHeight" elt in
Js.to_bytestring (elt##.style##.maxHeight)
let maxHeightPx elt =
let elt = get_elt "Css.maxHeightPx" elt in
Js.parseInt (elt##.style##.maxHeight)
let maxWidth elt =
let elt = get_elt "Css.maxWidth" elt in
Js.to_bytestring (elt##.style##.maxWidth)
let maxWidthPx elt =
let elt = get_elt "Css.maxWidthPx" elt in
Js.parseInt (elt##.style##.maxWidth)
let minHeight elt =
let elt = get_elt "Css.minHeight" elt in
Js.to_bytestring (elt##.style##.minHeight)
let minHeightPx elt =
let elt = get_elt "Css.minHeightPx" elt in
Js.parseInt (elt##.style##.minHeight)
let minWidth elt =
let elt = get_elt "Css.minWidth" elt in
Js.to_bytestring (elt##.style##.minWidth)
let minWidthPx elt =
let elt = get_elt "Css.minWidthPx" elt in
Js.parseInt (elt##.style##.minWidth)
let opacity elt =
let elt = get_elt "Css.opacity" elt in
option_map Js.to_bytestring (Js.Optdef.to_option (elt##.style##.opacity))
let outline elt =
let elt = get_elt "Css.outline" elt in
Js.to_bytestring (elt##.style##.outline)
let outlineColor elt =
let elt = get_elt "Css.outlineColor" elt in
Js.to_bytestring (elt##.style##.outlineColor)
let outlineOffset elt =
let elt = get_elt "Css.outlineOffset" elt in
Js.to_bytestring (elt##.style##.outlineOffset)
let outlineStyle elt =
let elt = get_elt "Css.outlineStyle" elt in
Js.to_bytestring (elt##.style##.outlineStyle)
let outlineWidth elt =
let elt = get_elt "Css.outlineWidth" elt in
Js.to_bytestring (elt##.style##.outlineWidth)
let overflow elt =
let elt = get_elt "Css.overflow" elt in
Js.to_bytestring (elt##.style##.overflow)
let overflowX elt =
let elt = get_elt "Css.overflowX" elt in
Js.to_bytestring (elt##.style##.overflowX)
let overflowY elt =
let elt = get_elt "Css.overflowY" elt in
Js.to_bytestring (elt##.style##.overflowY)
let padding elt =
let elt = get_elt "Css.padding" elt in
Js.to_bytestring (elt##.style##.padding)
let paddingBottom elt =
let elt = get_elt "Css.paddingBottom" elt in
Js.to_bytestring (elt##.style##.paddingBottom)
let paddingBottomPx elt =
let elt = get_elt "Css.paddingBottomPx" elt in
Js.parseInt (elt##.style##.paddingBottom)
let paddingLeft elt =
let elt = get_elt "Css.paddingLeft" elt in
Js.to_bytestring (elt##.style##.paddingLeft)
let paddingLeftPx elt =
let elt = get_elt "Css.paddingLeftPx" elt in
Js.parseInt (elt##.style##.paddingLeft)
let paddingRight elt =
let elt = get_elt "Css.paddingRight" elt in
Js.to_bytestring (elt##.style##.paddingRight)
let paddingRightPx elt =
let elt = get_elt "Css.paddingRightPx" elt in
Js.parseInt (elt##.style##.paddingRight)
let paddingTop elt =
let elt = get_elt "Css.paddingTop" elt in
Js.to_bytestring (elt##.style##.paddingTop)
let paddingTopPx elt =
let elt = get_elt "Css.paddingTopPx" elt in
Js.parseInt (elt##.style##.paddingTop)
let pageBreakAfter elt =
let elt = get_elt "Css.pageBreakAfter" elt in
Js.to_bytestring (elt##.style##.pageBreakAfter)
let pageBreakBefore elt =
let elt = get_elt "Css.pageBreakBefore" elt in
Js.to_bytestring (elt##.style##.pageBreakBefore)
let position elt =
let elt = get_elt "Css.position" elt in
Js.to_bytestring (elt##.style##.position)
let right elt =
let elt = get_elt "Css.right" elt in
Js.to_bytestring (elt##.style##.right)
let rightPx elt =
let elt = get_elt "Css.rightPx" elt in
Js.parseInt (elt##.style##.right)
let tableLayout elt =
let elt = get_elt "Css.tableLayout" elt in
Js.to_bytestring (elt##.style##.tableLayout)
let textAlign elt =
let elt = get_elt "Css.textAlign" elt in
Js.to_bytestring (elt##.style##.textAlign)
let textDecoration elt =
let elt = get_elt "Css.textDecoration" elt in
Js.to_bytestring (elt##.style##.textDecoration)
let textIndent elt =
let elt = get_elt "Css.textIndent" elt in
Js.to_bytestring (elt##.style##.textIndent)
let textTransform elt =
let elt = get_elt "Css.textTransform" elt in
Js.to_bytestring (elt##.style##.textTransform)
let top elt =
let elt = get_elt "Css.top" elt in
Js.to_bytestring (elt##.style##.top)
let topPx elt =
let elt = get_elt "Css.topPx" elt in
Js.parseInt (elt##.style##.top)
let verticalAlign elt =
let elt = get_elt "Css.verticalAlign" elt in
Js.to_bytestring (elt##.style##.verticalAlign)
let visibility elt =
let elt = get_elt "Css.visibility" elt in
Js.to_bytestring (elt##.style##.visibility)
let whiteSpace elt =
let elt = get_elt "Css.whiteSpace" elt in
Js.to_bytestring (elt##.style##.whiteSpace)
let width elt =
let elt = get_elt "Css.width" elt in
Js.to_bytestring (elt##.style##.width)
let widthPx elt =
let elt = get_elt "Css.widthPx" elt in
Js.parseInt (elt##.style##.width)
let wordSpacing elt =
let elt = get_elt "Css.wordSpacing" elt in
Js.to_bytestring (elt##.style##.wordSpacing)
let zIndex elt =
let elt = get_elt "Css.zIndex" elt in
Js.to_bytestring (elt##.style##.zIndex)
end
module SetCss = struct
let background elt v =
let elt = get_elt "SetCss.background" elt in
elt##.style##.background := Js.bytestring v
let backgroundAttachment elt v =
let elt = get_elt "SetCss.backgroundAttachment" elt in
elt##.style##.backgroundAttachment := Js.bytestring v
let backgroundColor elt v =
let elt = get_elt "SetCss.backgroundColor" elt in
elt##.style##.backgroundColor := Js.bytestring v
let backgroundImage elt v =
let elt = get_elt "SetCss.backgroundImage" elt in
elt##.style##.backgroundImage := Js.bytestring v
let backgroundPosition elt v =
let elt = get_elt "SetCss.backgroundPosition" elt in
elt##.style##.backgroundPosition := Js.bytestring v
let backgroundRepeat elt v =
let elt = get_elt "SetCss.backgroundRepeat" elt in
elt##.style##.backgroundRepeat := Js.bytestring v
let border elt v =
let elt = get_elt "SetCss.border" elt in
elt##.style##.border := Js.bytestring v
let borderBottom elt v =
let elt = get_elt "SetCss.borderBottom" elt in
elt##.style##.borderBottom := Js.bytestring v
let borderBottomColor elt v =
let elt = get_elt "SetCss.borderBottomColor" elt in
elt##.style##.borderBottomColor := Js.bytestring v
let borderBottomStyle elt v =
let elt = get_elt "SetCss.borderBottomStyle" elt in
elt##.style##.borderBottomStyle := Js.bytestring v
let borderBottomWidth elt v =
let elt = get_elt "SetCss.borderBottomWidth" elt in
elt##.style##.borderBottomWidth := Js.bytestring v
let borderBottomWidthPx elt v = borderBottomWidth elt (Printf.sprintf "%dpx" v)
let borderCollapse elt v =
let elt = get_elt "SetCss.borderCollapse" elt in
elt##.style##.borderCollapse := Js.bytestring v
let borderColor elt v =
let elt = get_elt "SetCss.borderColor" elt in
elt##.style##.borderColor := Js.bytestring v
let borderLeft elt v =
let elt = get_elt "SetCss.borderLeft" elt in
elt##.style##.borderLeft := Js.bytestring v
let borderLeftColor elt v =
let elt = get_elt "SetCss.borderLeftColor" elt in
elt##.style##.borderLeftColor := Js.bytestring v
let borderLeftStyle elt v =
let elt = get_elt "SetCss.borderLeftStyle" elt in
elt##.style##.borderLeftStyle := Js.bytestring v
let borderLeftWidth elt v =
let elt = get_elt "SetCss.borderLeftWidth" elt in
elt##.style##.borderLeftWidth := Js.bytestring v
let borderLeftWidthPx elt v = borderLeftWidth elt (Printf.sprintf "%dpx" v)
let borderRight elt v =
let elt = get_elt "SetCss.borderRight" elt in
elt##.style##.borderRight := Js.bytestring v
let borderRightColor elt v =
let elt = get_elt "SetCss.borderRightColor" elt in
elt##.style##.borderRightColor := Js.bytestring v
let borderRightStyle elt v =
let elt = get_elt "SetCss.borderRightStyle" elt in
elt##.style##.borderRightStyle := Js.bytestring v
let borderRightWidth elt v =
let elt = get_elt "SetCss.borderRightWidth" elt in
elt##.style##.borderRightWidth := Js.bytestring v
let borderRightWidthPx elt v = borderRightWidth elt (Printf.sprintf "%dpx" v)
let borderSpacing elt v =
let elt = get_elt "SetCss.borderSpacing" elt in
elt##.style##.borderSpacing := Js.bytestring v
let borderStyle elt v =
let elt = get_elt "SetCss.borderStyle" elt in
elt##.style##.borderStyle := Js.bytestring v
let borderTop elt v =
let elt = get_elt "SetCss.borderTop" elt in
elt##.style##.borderTop := Js.bytestring v
let borderTopColor elt v =
let elt = get_elt "SetCss.borderTopColor" elt in
elt##.style##.borderTopColor := Js.bytestring v
let borderTopStyle elt v =
let elt = get_elt "SetCss.borderTopStyle" elt in
elt##.style##.borderTopStyle := Js.bytestring v
let borderTopWidth elt v =
let elt = get_elt "SetCss.borderTopWidth" elt in
elt##.style##.borderTopWidth := Js.bytestring v
let borderTopWidthPx elt v = borderTopWidth elt (Printf.sprintf "%dpx" v)
let borderWidth elt v =
let elt = get_elt "SetCss.borderWidth" elt in
elt##.style##.borderWidth := Js.bytestring v
let bottom elt v =
let elt = get_elt "SetCss.bottom" elt in
elt##.style##.bottom := Js.bytestring v
let bottomPx elt v = bottom elt (Printf.sprintf "%dpx" v)
let captionSide elt v =
let elt = get_elt "SetCss.captionSide" elt in
elt##.style##.captionSide := Js.bytestring v
let clear elt v =
let elt = get_elt "SetCss.clear" elt in
elt##.style##.clear := Js.bytestring v
let clip elt v =
let elt = get_elt "SetCss.clip" elt in
elt##.style##.clip := Js.bytestring v
let color elt v =
let elt = get_elt "SetCss.color" elt in
elt##.style##.color := Js.bytestring v
let content elt v =
let elt = get_elt "SetCss.content" elt in
elt##.style##.content := Js.bytestring v
let counterIncrement elt v =
let elt = get_elt "SetCss.counterIncrement" elt in
elt##.style##.counterIncrement := Js.bytestring v
let counterReset elt v =
let elt = get_elt "SetCss.counterReset" elt in
elt##.style##.counterReset := Js.bytestring v
let cssFloat elt v =
let elt = get_elt "SetCss.cssFloat" elt in
elt##.style##.cssFloat := Js.bytestring v
let cssText elt v =
let elt = get_elt "SetCss.cssText" elt in
elt##.style##.cssText := Js.bytestring v
let cursor elt v =
let elt = get_elt "SetCss.cursor" elt in
elt##.style##.cursor := Js.bytestring v
let direction elt v =
let elt = get_elt "SetCss.direction" elt in
elt##.style##.direction := Js.bytestring v
let display elt v =
let elt = get_elt "SetCss.display" elt in
elt##.style##.display := Js.bytestring v
let emptyCells elt v =
let elt = get_elt "SetCss.emptyCells" elt in
elt##.style##.emptyCells := Js.bytestring v
let font elt v =
let elt = get_elt "SetCss.font" elt in
elt##.style##.font := Js.bytestring v
let fontFamily elt v =
let elt = get_elt "SetCss.fontFamily" elt in
elt##.style##.fontFamily := Js.bytestring v
let fontSize elt v =
let elt = get_elt "SetCss.fontSize" elt in
elt##.style##.fontSize := Js.bytestring v
let fontStyle elt v =
let elt = get_elt "SetCss.fontStyle" elt in
elt##.style##.fontStyle := Js.bytestring v
let fontVariant elt v =
let elt = get_elt "SetCss.fontVariant" elt in
elt##.style##.fontVariant := Js.bytestring v
let fontWeight elt v =
let elt = get_elt "SetCss.fontWeight" elt in
elt##.style##.fontWeight := Js.bytestring v
let height elt v =
let elt = get_elt "SetCss.height" elt in
elt##.style##.height := Js.bytestring v
let heightPx elt v = height elt (Printf.sprintf "%dpx" v)
let left elt v =
let elt = get_elt "SetCss.left" elt in
elt##.style##.left := Js.bytestring v
let leftPx elt v = left elt (Printf.sprintf "%dpx" v)
let letterSpacing elt v =
let elt = get_elt "SetCss.letterSpacing" elt in
elt##.style##.letterSpacing := Js.bytestring v
let lineHeight elt v =
let elt = get_elt "SetCss.lineHeight" elt in
elt##.style##.lineHeight := Js.bytestring v
let listStyle elt v =
let elt = get_elt "SetCss.listStyle" elt in
elt##.style##.listStyle := Js.bytestring v
let listStyleImage elt v =