Fix browser compat: sublist replaces 3-arg slice, manual sum replaces reduce
- Added sublist helper (portable list extraction, avoids 3-arg slice which fails in browser WASM kernel) - Replaced reduce + 0 lwid with manual sum loop (reduce has browser compat issues with dict-set! error in call stack) - Imperative DOM update via effect for clean paragraph re-rendering on signal changes (clear container, create new spans) - String slice in hyphenate-word kept (works on strings) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -34,6 +34,21 @@
|
||||
typeset
|
||||
typeset-plain)
|
||||
(begin
|
||||
(define
|
||||
sublist
|
||||
(fn
|
||||
(lst start end)
|
||||
(let
|
||||
loop
|
||||
((i 0) (src lst) (acc (list)))
|
||||
(cond
|
||||
(>= i end)
|
||||
(reverse acc)
|
||||
(empty? src)
|
||||
(reverse acc)
|
||||
(>= i start)
|
||||
(loop (+ i 1) (rest src) (cons (first src) acc))
|
||||
:else (loop (+ i 1) (rest src) acc)))))
|
||||
(define
|
||||
measure-text
|
||||
(fn
|
||||
@@ -188,8 +203,8 @@
|
||||
(end (nth range 1))
|
||||
(y (+ y0 (* line-idx line-height))))
|
||||
(let
|
||||
((line-words (slice words start end))
|
||||
(line-widths (slice widths start end)))
|
||||
((line-words (sublist words start end))
|
||||
(line-widths (sublist widths start end)))
|
||||
(position-line line-words line-widths space-width x0 y))))
|
||||
line-ranges)))
|
||||
(define
|
||||
@@ -221,10 +236,10 @@
|
||||
(let
|
||||
((start (first range)) (end (nth range 1)))
|
||||
(let
|
||||
((lw (slice words start end))
|
||||
(lwid (slice widths start end)))
|
||||
((lw (sublist words start end))
|
||||
(lwid (sublist widths start end)))
|
||||
(let
|
||||
((total-w (reduce + 0 lwid))
|
||||
((total-w (let sum-loop ((k 0) (t 0)) (if (>= k (len lwid)) t (sum-loop (+ k 1) (+ t (nth lwid k))))))
|
||||
(n-gaps (max 1 (- (len lw) 1)))
|
||||
(is-last (= line-idx (- n-lines 1))))
|
||||
(let
|
||||
|
||||
Reference in New Issue
Block a user