@@ -3,7 +3,6 @@ import type { Identifier, NbtTag, Random } from 'deepslate'
33import { Matrix3 , Matrix4 , NbtByte , NbtCompound , NbtDouble , NbtInt , NbtList , NbtString , Vector } from 'deepslate'
44import type { mat3 } from 'gl-matrix'
55import { quat , vec2 } from 'gl-matrix'
6- import yaml from 'js-yaml'
76import { route } from 'preact-router'
87import rfdc from 'rfdc'
98import type { ConfigGenerator } from './Config.js'
@@ -100,74 +99,6 @@ export function changeUrl({ path, search, hash, replace }: { path?: string, sear
10099 route ( url , replace )
101100}
102101
103- export function parseFrontMatter ( source : string ) : Record < string , any > {
104- const data = yaml . load ( source . substring ( 3 , source . indexOf ( '---' , 3 ) ) )
105- if ( ! isObject ( data ) ) return { }
106- return data
107- }
108-
109- export function versionContent ( content : string , version : string ) {
110- let cursor = 0
111- while ( true ) {
112- const start = content . indexOf ( '{#' , cursor )
113- if ( start < 0 ) {
114- break
115- }
116- const end = findMatchingClose ( content , start + 2 )
117- const vStart = content . indexOf ( '#[' , start + 1 )
118- let sub = ''
119- if ( vStart >= 0 && vStart < end ) {
120- const vEnd = content . indexOf ( ']' , vStart + 2 )
121- const v = content . substring ( vStart + 2 , vEnd )
122- if ( v === version ) {
123- sub = content . substring ( vEnd + 1 , end ) . trim ( )
124- }
125- } else {
126- const key = content . substring ( start + 2 , end )
127- const versionConfig = config . versions . find ( v => v . id === version )
128- sub = ( {
129- version : versionConfig ?. id ,
130- pack_format : versionConfig ?. pack_format . toString ( ) ,
131- } as Record < string , string | undefined > ) [ key ] ?? ''
132- }
133- content = content . substring ( 0 , start ) + sub + content . substring ( end + 2 )
134- cursor = start
135-
136- }
137- return content
138- }
139-
140- function findMatchingClose ( source : string , index : number ) {
141- let depth = 0
142- let iteration = 0
143- while ( iteration ++ < 1000 ) {
144- const close = source . indexOf ( '#}' , index )
145- const open = source . indexOf ( '{#' , index )
146- if ( close < 0 ) {
147- console . warn ( 'Missing closing bracket' )
148- return source . length
149- }
150- if ( open < 0 ) {
151- if ( depth === 0 ) {
152- return close
153- } else {
154- depth -= 1
155- index = close + 2
156- }
157- } else if ( open < close ) {
158- depth += 1
159- index = open + 2
160- } else if ( depth === 0 ) {
161- return close
162- } else {
163- depth -= 1
164- index = close + 2
165- }
166- }
167- console . warn ( 'Exceeded max iterations while finding closing bracket' )
168- return source . length
169- }
170-
171102export type Color = [ number , number , number ]
172103
173104export function stringToColor ( str : string ) : Color {
@@ -198,32 +129,6 @@ export function clamp(a: number, b: number, c: number) {
198129 return Math . max ( b , Math . min ( a , c ) )
199130}
200131
201- export function clampedLerp ( a : number , b : number , c : number ) : number {
202- if ( c < 0 ) {
203- return a
204- } else if ( c > 1 ) {
205- return b
206- } else {
207- return lerp ( c , a , b )
208- }
209- }
210-
211- export function lerp ( a : number , b : number , c : number ) : number {
212- return b + a * ( c - b )
213- }
214-
215- export function lerp2 ( a : number , b : number , c : number , d : number , e : number , f : number ) : number {
216- return lerp ( b , lerp ( a , c , d ) , lerp ( a , e , f ) )
217- }
218-
219- export function lerp3 ( a : number , b : number , c : number , d : number , e : number , f : number , g : number , h : number , i : number , j : number , k : number ) {
220- return lerp ( c , lerp2 ( a , b , d , e , f , g ) , lerp2 ( a , b , h , i , j , k ) )
221- }
222-
223- export function smoothstep ( x : number ) : number {
224- return x * x * x * ( x * ( x * 6 - 15 ) + 10 )
225- }
226-
227132export function message ( e : unknown ) : string {
228133 if ( e instanceof Error ) return e . message
229134 return `${ e } `
0 commit comments