Prolog "react"

Admin User, created Apr 17. 2025
         
/**
* This file provides dom writing predicates.
*
* Warranty & Liability
* To the extent permitted by applicable law and unless explicitly
* otherwise agreed upon, XLOG Technologies AG makes no warranties
* regarding the provided information. XLOG Technologies AG assumes
* no liability that any problems might be solved with the information
* provided by XLOG Technologies AG.
*
* Rights & License
* All industrial property rights regarding the information - copyright
* and patent rights in particular - are the sole property of XLOG
* Technologies AG. If the company was not the originator of some
* excerpts, XLOG Technologies AG has at least obtained the right to
* reproduce, change and translate the information.
*
* Reproduction is restricted to the whole unaltered document. Reproduction
* of the information is only allowed for non-commercial uses. Selling,
* giving away or letting of the execution of the library is prohibited.
* The library can be distributed as part of your applications and libraries
* for execution provided this comment remains unchanged.
*
* Restrictions
* Only to be distributed with programs that add significant and primary
* functionality to the library. Not to be distributed with additional
* software intended to replace any components of the library.
*
* Trademarks
* Jekejeke is a registered trademark of XLOG Technologies AG.
*/
:- ensure_loaded(library(misc/markup)).
/*******************************************************************/
/* Output Clear */
/*******************************************************************/
/**
* clear:
* The predicate clears the content of the cursor.
*/
% clear
clear :-
dom_cell_current(Elem),
dom_cell_clear(Elem).
/**
* goto(I):
* The predicate changes the cursor to the element with id I.
*/
% goto(+Atom)
goto(Id) :-
flush_output,
dom_cell_goto(Id, Elem),
dom_cell_set(Elem).
/*******************************************************************/
/* Event Handler */
/*******************************************************************/
/**
* bind(T, P, G):
* bind(C, T, P, G):
* The predicate succeeds. As a side effect it adds a type T stackless
* event handler with formal event parameter P and callback goal G
* to the cursor. The quaternary predicate allows specifiying an element.
*/
% bind(+Atom, +Term, +Goal)
bind(Type, Para, Goal) :-
dom_cell_current(Elem),
sys_listen(Elem, Type, Para, Goal, 0).
% bind(+Element, +Atom, +Term, +Goal)
bind(Elem, Type, Para, Goal) :-
sys_listen(Elem, Type, Para, Goal, 0).
/**
* listen(T, P, G, L):
* listen(C, T, P, G, L):
* The predicate succeeds. As a side effect it adds a type T stackless
* event handler with formal event parameter P and callback goal G to
* the cursor. The event handler behaves according to the option list L.
* The quinary predicate allows specifiying an element.
*/
% listen(+Atom, +Term, +Goal, +List)
listen(Type, Para, Goal, Opts) :-
dom_cell_current(Elem),
sys_listen_opts(Opts, 0, Flags),
sys_listen(Elem, Type, Para, Goal, Flags).
% listen(+Element, +Atom, +Term, +Goal, +List)
listen(Elem, Type, Para, Goal, Opts) :-
sys_listen_opts(Opts, 0, Flags),
sys_listen(Elem, Type, Para, Goal, Flags).
% sys_listen(+Element, +Atom, +Term, +Goal, +Integer)
sys_listen(Elem, Type, Para, Goal, Flags) :- Flags /\ 2 =:= 0, !,
sys_frost_horn((''(Para) :- Goal), Native),
dom_cell_listen(Elem, Type, Native, Flags).
sys_listen(Elem, Type, Para, Goal, Flags) :-
sys_frost_horn((''(Para) :- Goal), Native),
dom_cell_promise(Elem, Type, Native, Flags, Q),
'$YIELD'(Q).
/*******************************************************************/
/* Listen Options */
/*******************************************************************/
/**
* sys_listen_opts(L, F, G):
* The predicate succeeds in G with the options L starting with defaults F.
*/
% sys_listen_opts(+List, +Integer, -Integer)
sys_listen_opts(V, _, _) :- var(V),
throw(error(instantiation_error,_)).
sys_listen_opts([X|L], I, O) :- !,
sys_listen_opt(X, I, H),
sys_listen_opts(L, H, O).
sys_listen_opts([], H, H) :- !.
sys_listen_opts(L, _, _) :-
throw(error(type_error(list,L),_)).
% sys_listen_opt(+Option, +Integer, -Integer)
sys_listen_opt(V, _, _) :- var(V),
throw(error(instantiation_error,_)).
sys_listen_opt(capture(B), F, G) :- !,
sys_opt_boolean(B, 1, F, G).
sys_listen_opt(block(B), F, G) :- !,
sys_opt_boolean(B, 2, F, G).
sys_listen_opt(O, _, _) :-
throw(error(type_error(svg_option,O),_)).
/*******************************************************************/
/* Foreign Predicates */
/*******************************************************************/
% dom_cell_clear(E):
% defined in foreign(misc/emitlib)
% dom_cell_goto(I, E):
% defined in foreign(misc/emitlib)
% dom_cell_listen(E, T, N, F):
% defined in foreign(misc/emitlib)
% dom_cell_promise(E, T, N, F, Q):
% defined in foreign(misc/emitlib)
% dom_prevent_default(E):
% defined in foreign(misc/emitlib)
% dom_stop_propagation(E):
% defined in foreign(misc/emitlib)
% ir_float_current(K, O, V):
% defined in foreign(misc/emitlib)
% ir_float_set(K, O, V):
% defined in foreign(misc/emitlib)
:- ensure_loaded(foreign(misc/emitlib)).