wv-element% coding

This commit is contained in:
2026-03-09 21:06:06 +01:00
parent 587c306218
commit 35f5a8f60d

View File

@@ -82,6 +82,7 @@
webview-remove-class! webview-remove-class!
webview-set-style! webview-set-style!
webview-unset-style! webview-unset-style!
webview-get-style
webview-set-attr! webview-set-attr!
webview-attr webview-attr
@@ -741,6 +742,39 @@
) )
) )
(define/contract (webview-get-style wv selector styles)
(-> wv? (or/c symbol? string?) (or/c symbol? list-of-symbol?) (or/c list? hash?))
(let ((sel (if (symbol? selector)
(format "#~a" selector)
selector))
(cl (mk-js-array (if (symbol? styles)
(list styles)
styles)))
)
(let ((r (webview-call-js wv
(with-selector sel
(format
(js-code
"function(id, el) {"
" let cl = ~a;"
" let r = {};"
" cl.forEach(function(st) {"
" let stl = window.getComputedStyle(el);"
" r[st] = stl[st];"
" });"
" return { id: id, style: r };"
"}") cl))
)))
(let ((h (hash-ref r 'with-ids)))
(let ((l (map (λ (e) (cons (string->symbol (hash-ref e 'id)) (hash-ref e 'style))) h)))
(if (symbol? selector)
(cdr (car l))
l)))
)
)
)
(define/contract (webview-unset-style! wv selector style-entries) (define/contract (webview-unset-style! wv selector style-entries)
(-> wv? (or/c symbol? string?) (or/c symbol? list-of-symbol?) hash?) (-> wv? (or/c symbol? string?) (or/c symbol? list-of-symbol?) hash?)
(let ((sel (if (symbol? selector) (let ((sel (if (symbol? selector)