You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pollen/library/css/math.rkt

21 lines
619 B
Racket

11 years ago
#lang racket/base
(require "core.rkt")
(struct cssq (num unit)
#:methods gen:custom-write
[(define write-proc
(λ(x port mode) (display (format "~a~a" (cssq-num x) (cssq-unit x)) port)))])
(define (string->cssq str)
(apply cssq
(let ([str (string-trim str "s" #:left? #f)])
(regexp-split #px"(?<=[.\\d])(?=[A-Za-z])" str))))
(define (css+ left right)
(string->cssq (format "~a~a" (apply + (map string->number (list (cssq-num left) (cssq-num right))))(cssq-unit left))))
(module+ main
(define q1 (string->cssq "51.2rems"))
(define q2 (string->cssq "10rem"))
(css+ q1 q2))