12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879open!CoreopenJs_of_ocamlmoduleStyle_sheet=structclasstypet=objectmethodreplaceSync:Js.js_stringJs.t->unitJs.methendlett:tJs.tJs.constr=Js.Unsafe.global##._CSSStyleSheetletappend:tJs.t->unit=Js.Unsafe.pure_js_expr{js|
(function (style_sheet) {
// push doesn't work because this field is really weird.
document.adoptedStyleSheets =
Array.prototype.concat.apply(document.adoptedStyleSheets, [style_sheet]);
})
|js};;endletall_css=refReversed_list.[]letglobal_style_sheet=refNoneletto_string()=!all_css|>Reversed_list.rev|>String.concat~sep:"\n"letprint_for_testing=letregex=Re.Str.regexp"_hash_\\([a-z0-9]+\\)*"infun()->to_string()|>Re.Str.global_replaceregex"_hash_replaced_in_test"|>print_endline;;letinstall_in_dom()=letstyle_sheet=new%jsStyle_sheet.tinStyle_sheet.appendstyle_sheet;style_sheet##replaceSync(Js.string(to_string()));global_style_sheet:=Somestyle_sheet;;(* If the ref-cell is None, then we don't need to do anything
because all the contents will be loaded when [install_in_dom]
is called. *)letmaybe_update_in_dom()=match!global_style_sheetwith|Somestyle_sheet->style_sheet##replaceSync(Js.string(to_string()))|None->();;letappenda=(all_css:=Reversed_list.(a::!all_css));maybe_update_in_dom();;let()=letready_state=Option.try_with(fun()->Dom_html.document##.readyState|>Js.to_string)inmatchready_statewith|Some("interactive"|"complete")->install_in_dom()|Some("loading"|_)->let_id:Dom_html.event_listener_id=Dom_html.addEventListenerWithOptions~passive:Js._true~capture:Js._false~once:Js._trueDom_html.windowDom_html.Event.domContentLoaded(Dom.handler(fun_->install_in_dom();Js._true))in()|None->();;modulePrivate=structletappend=appendend