Commitf87769c7Recorded25 Feb 2026Repositorysigil-css
Add procedure specs to app and css packages
Changed
src/sigil/css.sgl | 32 ++++++++++++++++++++++++++++----
1 file changed, 28 insertions(+), 4 deletions(-)Diff
src/sigil/css.sglmodified
@@ -193,6 +193,7 @@
193
;;; (background "#007bff")) 194
;;; ``` 195
(define (css-sel . selectors)+196
(: string? ... -> string?) 197
(string-join selectors ", ")) 198
199
;; Append a suffix to each selector in a (possibly compound) selector.@@ -282,6 +283,7 @@
283
;;; (css ".content" (width "100%"))) 284
;;; ``` 285
(define (css-media query . rules)+286
(: string? any? ... -> list?) 287
(make-media query rules)) 288
289
;;; Create a CSS `@import` rule.@@ -293,6 +295,7 @@
295
;;; ; => "@import url('https://...');" 296
;;; ``` 297
(define (css-import url)+298
(: string? -> list?) 299
(make-import url)) 300
301
;;; Insert raw CSS string.@@ -304,6 +307,7 @@
307
;;; (css-raw "/* Legacy browser support */") 308
;;; ``` 309
(define (css-raw str)+310
(: string? -> list?) 311
(make-raw str)) 312
313
;;; Define a CSS keyframes animation.@@ -354,6 +358,7 @@
358
;;; ; => ":root {\n --primary: #007bff;\n}\n\n.button {\n ..." 359
;;; ``` 360
(define (css->string . fragments)+361
(: any? ... -> string?) 362
(let ((out (open-output-string))) 363
(for-each 364
(lambda (frag)@@ -487,6 +492,7 @@
492
493
;;; Render single rule (for debugging) 494
(define (css-rule->string rule)+495
(: list? -> string?) 496
(css->string rule)) 497
498
@@ -505,6 +511,7 @@
511
;;; '(accent "#f0c040"))) 512
;;; ``` 513
(define (make-theme . pairs)+514
(: list? ... -> list?) 515
(map (lambda (p) (cons (car p) (cadr p))) pairs)) 516
517
;;; Get a value from a theme by key.@@ -515,6 +522,7 @@
522
;;; (theme-ref dark-theme 'bg) ; => "#0a0a0a" 523
;;; ``` 524
(define (theme-ref theme key)+525
(: list? symbol? -> any?) 526
(let ((pair (assoc key theme))) 527
(if pair (cdr pair) #f))) 528
@@ -524,6 +532,7 @@
532
;;; (theme-var 'bg) ; => "var(--bg)" 533
;;; ``` 534
(define (theme-var key)+535
(: symbol? -> string?) 536
(string-append "var(--" (symbol->string key) ")")) 537
538
;;; Convert a theme to CSS custom properties.@@ -533,6 +542,7 @@
542
;;; ; Creates :root { --bg: #0a0a0a; --fg: #e0e0e0; ... } 543
;;; ``` 544
(define (theme->css-vars theme)+545
(: list? -> list?) 546
;; Build vars structure directly (can't apply a macro) 547
(%make-vars 548
(map (lambda (pair)@@ -548,6 +558,7 @@
558
;;; Most properties are defined directly in `css` rules, but this 559
;;; can be useful for dynamic property generation. 560
(define (prop name value)+561
(: any? any? -> list?) 562
(list name value)) 563
564
;;; Add `!important` to a value.@@ -557,6 +568,7 @@
568
;;; ; => .override { color: red !important; } 569
;;; ``` 570
(define (important value)+571
(: any? -> string?) 572
(string-append (%value->string value) " !important")) 573
574
;;; Unit helpers for common CSS units.@@ -567,10 +579,18 @@
579
;;; (rem 2) ; => "2rem" 580
;;; (% 50) ; => "50%" 581
;;; ```−570
(define (px n) (string-append (number->string n) "px"))−571
(define (em n) (string-append (number->string n) "em"))−572
(define (rem n) (string-append (number->string n) "rem"))−573
(define (% n) (string-append (number->string n) "%"))+582
(define (px n)+583
(: number? -> string?)+584
(string-append (number->string n) "px"))+585
(define (em n)+586
(: number? -> string?)+587
(string-append (number->string n) "em"))+588
(define (rem n)+589
(: number? -> string?)+590
(string-append (number->string n) "rem"))+591
(define (% n)+592
(: number? -> string?)+593
(string-append (number->string n) "%")) 594
595
;;; Color helpers for CSS color functions. 596
;;;@@ -580,12 +600,15 @@
600
;;; (hsl 200 50 60) ; => "hsl(200, 50%, 60%)" 601
;;; ``` 602
(define (rgb r g b)+603
(: number? number? number? -> string?) 604
(format "rgb(~a, ~a, ~a)" r g b)) 605
606
(define (rgba r g b a)+607
(: number? number? number? number? -> string?) 608
(format "rgba(~a, ~a, ~a, ~a)" r g b a)) 609
610
(define (hsl h s l)+611
(: number? number? number? -> string?) 612
(format "hsl(~a, ~a%, ~a%)" h s l)) 613
614
@@ -605,6 +628,7 @@
628
;;; (css->string button-styles) 629
;;; ``` 630
(define (css-combine . fragments)+631
(: any? ... -> list?) 632
fragments) 633
634
))