1 ;; SPDX-License-Identifier: BSD-3-Clause
3 (in-package #:parenscript
)
5 ;; Utilities for accessing standard DOM functionality in a Lispier, PSier way.
7 (defpsmacro inner-html
(el)
8 `(@ ,el
'inner-h-t-m-l
))
10 (defpsmacro uri-encode
(str)
11 `(if (null ,str
) "" (encode-u-r-i-component ,str
)))
13 (defpsmacro attribute
(el attr
)
14 `((@ ,el
'get-attribute
) ,attr
))
16 (defun assert-is-one-of (val options
)
17 (unless (member val options
)
18 (error "~s is not one of ~s" val options
)))
20 (defpsmacro offset
(what el
)
22 `(offset ,(eval what
) ,el
)
24 ((:top
:left
:height
:width
) `(@ ,el
,(intern (format nil
"OFFSET-~a" what
))))
25 (:right
`(+ (offset :left
,el
) (offset :width
,el
)))
26 (:bottom
`(+ (offset :top
,el
) (offset :height
,el
)))
27 (:hcenter
`(+ (offset :left
,el
) (/ (offset :width
,el
) 2)))
28 (:vcenter
`(+ (offset :top
,el
) (/ (offset :height
,el
) 2)))
29 (t (error "The OFFSET macro doesn't accept ~s as a key." what
)))))
31 (defpsmacro scroll
(what el
)
32 (assert-is-one-of what
'(:top
:left
:right
:bottom
:width
:height
))
33 (cond ((member what
'(:top
:left
:width
:height
))
34 `(@ ,el
,(intern (format nil
"SCROLL-~a" what
))))
36 `(+ (scroll :left
,el
) (offset :width
,el
)))
38 `(+ (scroll :top
,el
) (offset :height
,el
)))))
40 (defpsmacro inner
(what el
)
41 (assert-is-one-of what
'(:width
:height
))
42 `(@ ,el
,(intern (format nil
"INNER-~a" what
))))
44 (defpsmacro client
(what el
)
45 (assert-is-one-of what
'(:width
:height
))
46 `(@ ,el
,(intern (format nil
"CLIENT-~a" what
))))