;; Pretext demo — DOM-free text layout
;;
;; Visual-first: shows typeset text, then explains how.
;; Uses measure-text (perform) for glyph measurement.
;; Compute positioned word data for one line.
(defcomp
  (&key lines max-width line-height n-words label)
  (let
    ((lh (or line-height 24)) (n-lines (len lines)))
    (div
      :class "relative rounded-lg border border-stone-200 bg-white overflow-hidden"
      (when
        label
        (div
          :class "px-4 pt-3 pb-1"
          (span
            :class "text-xs font-medium uppercase tracking-wide text-stone-400"
            label)))
      (div
        :style (str
          "position:relative;height:"
          (* n-lines lh)
          "px;padding:12px 16px;")
        (map
          (fn
            (line)
            (let
              ((y (get line :y)))
              (map
                (fn
                  (pw)
                  (span
                    :style (str
                      "position:absolute;left:"
                      (+ (get pw :x) 16)
                      "px;top:"
                      (+ y 12)
                      "px;font-size:15px;line-height:"
                      lh
                      "px;white-space:nowrap;")
                    (get pw :word)))
                (get line :words))))
          lines))
      (div
        :class "px-4 py-2 border-t border-stone-100 bg-stone-50 flex justify-between"
        (span
          :class "text-xs text-stone-400"
          (str n-lines " lines, " n-words " words"))
        (span :class "text-xs text-stone-400" (str "width: " max-width "px"))))))
