@@ -14,53 +14,32 @@ this program. If not, see <https://www.gnu.org/licenses/>.
1414-->
1515
1616<script lang =" ts" >
17- import { keyboardContext } from " $lib/keyboard"
18- import type { KeyboardLayout } from " $lib/keyboard/metadata"
17+ import {
18+ displayLayoutContext ,
19+ type DisplayLayout ,
20+ } from " $lib/configurator/context.svelte"
1921 import { unitToEM , unitToStyle } from " $lib/ui"
2022 import { cn , type WithoutChildren } from " $lib/utils"
2123 import type { Snippet } from " svelte"
2224 import type { HTMLAttributes } from " svelte/elements"
2325
2426 const {
2527 class : className,
26- layout = keyboardContext .get (). metadata . layout ,
28+ displayLayout = displayLayoutContext .get (),
2729 keyGenerator,
2830 ... props
2931 }: WithoutChildren <HTMLAttributes <HTMLDivElement >> & {
30- layout ? : KeyboardLayout
32+ displayLayout ? : DisplayLayout
3133 keyGenerator? : Snippet <[number ]>
3234 } = $props ()
3335
3436 let containerWidth = $state (0 )
3537 let containerHeight = $state (0 )
3638
37- const { keyboardWidth, keyboardHeight, coordinates } = $derived .by (() => {
38- const ret = {
39- keyboardWidth: 0 ,
40- keyboardHeight: 0 ,
41- coordinates: [] as { x: number ; y: number }[],
42- }
43- const position = { x: 0 , y: 0 }
44-
45- for (const row of layout ) {
46- for (const { w, h, x, y } of row ) {
47- position .x += x
48- position .y += y
49- ret .keyboardWidth = Math .max (ret .keyboardWidth , position .x + w )
50- ret .keyboardHeight = Math .max (ret .keyboardHeight , position .y + h )
51- ret .coordinates .push ({ ... position })
52- position .x += w
53- }
54- position .x = 0
55- position .y ++
56- }
57-
58- return ret
59- })
6039 const fontSize = $derived (
6140 Math .min (
62- containerWidth / unitToEM (keyboardWidth ),
63- containerHeight / unitToEM (keyboardHeight ),
41+ containerWidth / unitToEM (displayLayout . width ),
42+ containerHeight / unitToEM (displayLayout . height ),
6443 ),
6544 )
6645 </script >
@@ -76,13 +55,10 @@ this program. If not, see <https://www.gnu.org/licenses/>.
7655 <div class =" absolute inset-0 grid place-items-center" >
7756 <div
7857 class =" relative"
79- style ={unitToStyle (keyboardWidth , keyboardHeight )}
58+ style ={unitToStyle (displayLayout . width , displayLayout . height )}
8059 >
81- {#each layout .flat () as { key, w, h }, i (i )}
82- <div
83- class =" absolute p-0.5"
84- style ={unitToStyle (w , h , coordinates [i ].x , coordinates [i ].y )}
85- >
60+ {#each displayLayout .displayKeys as { key, w, h, x, y }, i (i )}
61+ <div class ="absolute p-0.5" style ={unitToStyle (w , h , x , y )}>
8662 {@render keyGenerator ?.(key )}
8763 </div >
8864 {/each }
0 commit comments