Skip to content

Commit

Permalink
Merge pull request #228 from ocsigen/wasm
Browse files Browse the repository at this point in the history
Wasm support
  • Loading branch information
balat authored Sep 28, 2024
2 parents 97fae04 + ad94b74 commit b975917
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 28 deletions.
2 changes: 1 addition & 1 deletion opam
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ build: [ make "-j%{jobs}%" ]
install: [ make "install" ]
depends: [
"ocaml" {>= "4.08.0"}
"js_of_ocaml" {>= "4.1.0"}
"js_of_ocaml" {>= "5.5.0"}
"eliom" {>= "11.0.0"}
"calendar" {>= "2.0.0"}
]
7 changes: 4 additions & 3 deletions src/widgets/ot_carousel.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ let%shared default_make_transform ~vertical ?(delta = 0) pos =
let%client ot_swiping = "ot-swiping"

[%%client
let now () = (new%js Js.date_now)##getTime /. 1000.
let now () = Js.to_float (new%js Js.date_now)##getTime /. 1000.
let average_time = 0.1

(* the time, in seconds,
Expand Down Expand Up @@ -284,8 +284,9 @@ let%shared make ?(a = []) ?(vertical = false) ?(position = 0)
(Js.Unsafe.coerce d2'##.style)##.webkitTransform := s;
let move =
not
(before == (Js.Unsafe.coerce d2'##.style)##.transform
|| before == (Js.Unsafe.coerce d2'##.style)##.webkitTransform)
(Js.strict_equals before (Js.Unsafe.coerce d2'##.style)##.transform
|| Js.strict_equals before
(Js.Unsafe.coerce d2'##.style)##.webkitTransform)
in
let step = React.Step.create () in
pos_set ~step pos;
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/ot_lib.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ let%client window_scrolls ?(ios_html_scroll_hack = false) ?use_capture handler =
(fun () -> stop_thread (); Lwt.cancel !cur; Lwt.return_unit)

let%client rec in_ancestors ~elt ~ancestor =
elt == (ancestor : Dom_html.element Js.t)
|| (not (elt == Dom_html.document##.body))
Js.strict_equals elt (ancestor : Dom_html.element Js.t)
|| (not (Js.strict_equals elt Dom_html.document##.body))
&& Js.Opt.case elt##.parentNode
(fun () -> false)
(fun parent ->
Expand Down
8 changes: 5 additions & 3 deletions src/widgets/ot_nodeready.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ open Js_of_ocaml
let debug = false

let rec node_in_document node =
node == (Dom_html.document :> Dom.node Js.t)
Js.strict_equals node (Dom_html.document :> Dom.node Js.t)
|| Js.Opt.case node##.parentNode (fun () -> false) node_in_document

type t =
Expand Down Expand Up @@ -81,7 +81,9 @@ let nodeready n =
else (
if !watched = [] then observer##observe Dom_html.document config;
try
let {thread} = List.find (fun {node} -> n == node) !watched in
let {thread} =
List.find (fun {node} -> Js.strict_equals n node) !watched
in
log ~n "already being watched";
thread
with Not_found ->
Expand All @@ -93,7 +95,7 @@ let nodeready n =
in
Eliom_client.Page_status.ondead ~stop (fun () ->
let instances_of_node, rest =
List.partition (fun {node} -> n == node) !watched
List.partition (fun {node} -> Js.strict_equals n node) !watched
in
watched := rest;
instances_of_node
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/ot_picture_uploader.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,8 @@ let%shared cropper ~(image : Dom_html.element Js.t Eliom_client_value.t)
[%client
(fun () ->
let bb = ~%image##getBoundingClientRect in
let bb_w = bb##.right -. bb##.left in
let bb_h = bb##.bottom -. bb##.top in
let bb_w = Js.to_float bb##.right -. Js.to_float bb##.left in
let bb_h = Js.to_float bb##.bottom -. Js.to_float bb##.top in
let w, h =
match ~%ratio with
| Some ratio ->
Expand Down
6 changes: 3 additions & 3 deletions src/widgets/ot_pulltorefresh.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ module Make (Conf : CONF) = struct
Conf.set_state @@ Some Succeeded;
js_container##.style##.transform := Js.string "translateY(0)";
refreshFlag := false))
700.)
(Js.float 700.))
(*if the page refreshing finishes instantaneously,
setTimeout is used to show the animation*)
else (
Expand All @@ -123,7 +123,7 @@ module Make (Conf : CONF) = struct
ignore
(Dom_html.window##setTimeout
(Js.wrap_callback (fun () -> refreshFlag := false))
500.));
(Js.float 500.)));
Lwt.return_unit)

let scroll_back () =
Expand All @@ -136,7 +136,7 @@ module Make (Conf : CONF) = struct
ignore
(Dom_html.window##setTimeout
(Js.wrap_callback (fun () -> refreshFlag := false))
500.))
(Js.float 500.)))

let touchend_handler ev _ =
if !top && !distance > 0. && !dragStart >= 0
Expand Down
8 changes: 4 additions & 4 deletions src/widgets/ot_size.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,18 @@ let client_width ?(with_margin = false) elt =

let client_page_top ?with_margin elt =
client_top ?with_margin elt
-. Dom_html.document##.body##getBoundingClientRect##.top
-. Js.to_float Dom_html.document##.body##getBoundingClientRect##.top

let client_page_left ?with_margin elt =
client_left elt ?with_margin
-. Dom_html.document##.body##getBoundingClientRect##.left
-. Js.to_float Dom_html.document##.body##getBoundingClientRect##.left

let client_page_bottom ?with_margin elt =
Dom_html.document##.body##getBoundingClientRect##.bottom
Js.to_float Dom_html.document##.body##getBoundingClientRect##.bottom
-. client_bottom ?with_margin elt

let client_page_right ?with_margin elt =
Dom_html.document##.body##getBoundingClientRect##.left
Js.to_float Dom_html.document##.body##getBoundingClientRect##.left
-. client_right elt ?with_margin

let pageYOffset () =
Expand Down
13 changes: 8 additions & 5 deletions src/widgets/ot_time_picker.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ let%client ( >>! ) = Js.Opt.iter
let%client wrap_touch_aux ev f =
ev##.currentTarget >>! fun a ->
let r = a##getBoundingClientRect in
let ox = r##.left and ox' = r##.right and oy = r##.top and oy' = r##.bottom in
let ox = Js.to_float r##.left
and ox' = Js.to_float r##.right
and oy = Js.to_float r##.top
and oy' = Js.to_float r##.bottom in
assert (ox' >= ox);
assert (oy' >= oy);
Js.Optdef.iter ev ##. changedTouches ## (item 0) @@ fun touch0 ->
Expand All @@ -231,10 +234,10 @@ let%client wrap_touch_24h ~ends ev f_e f_b =
let%client wrap_click_aux ev f =
ev##.currentTarget >>! fun a ->
let r = a##getBoundingClientRect in
let ox = r##.left
and ox' = r##.right
and oy = r##.top
and oy' = r##.bottom
let ox = Js.to_float r##.left
and ox' = Js.to_float r##.right
and oy = Js.to_float r##.top
and oy' = Js.to_float r##.bottom
and x = ev##.clientX
and y = ev##.clientY in
assert (ox' > ox);
Expand Down
8 changes: 4 additions & 4 deletions src/widgets/ot_tip.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ let%client display ?(container_a = [a_class ["ot-tip-container"]])
let d_height = float @@ Dom_html.window##.innerHeight in
let d_width = float Dom_html.document##.documentElement##.clientWidth in
let o_bounds = origin##getBoundingClientRect in
let o_left = o_bounds##.left in
let o_right = o_bounds##.right in
let o_left = Js.to_float o_bounds##.left in
let o_right = Js.to_float o_bounds##.right in
let o_to_right = d_width -. o_right in
let o_top = o_bounds##.top in
let o_top = Js.to_float o_bounds##.top in
let o_to_top = d_height -. o_top in
let o_bottom = o_bounds##.bottom in
let o_bottom = Js.to_float o_bounds##.bottom in
let o_to_bottom = d_height -. o_bottom in
let o_width = o_right -. o_left in
let o_center_to_left = (o_right +. o_left) /. 2. in
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/ot_tongue.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type%shared tongue =
; px_signal_before : int React.S.t Eliom_client_value.t
; px_signal_after : int React.S.t Eliom_client_value.t }

let%client now () = (new%js Js.date_now)##getTime /. 1000.
let%client now () = Js.to_float (new%js Js.date_now)##getTime /. 1000.

let%client clX ev =
Js.Optdef.case
Expand Down

0 comments on commit b975917

Please sign in to comment.