-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Improve chunking, vite preproccessing
- Loading branch information
Showing
12 changed files
with
85 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,81 @@ | ||
import Logger from '$lib/logger'; | ||
|
||
import Alert from 'pixelarticons/svg/alert.svg'; | ||
import ArrowBarUp from 'pixelarticons/svg/arrow-bar-up.svg'; | ||
import ArrowLeft from 'pixelarticons/svg/arrow-left.svg'; | ||
import ArrowRight from 'pixelarticons/svg/arrow-right.svg'; | ||
import Cast from 'pixelarticons/svg/cast.svg'; | ||
import CloseBox from 'pixelarticons/svg/close-box.svg'; | ||
import Code from 'pixelarticons/svg/code.svg'; | ||
import Copy from 'pixelarticons/svg/copy.svg'; | ||
import Downasaur from 'pixelarticons/svg/downasaur.svg'; | ||
import Link from 'pixelarticons/svg/link.svg'; | ||
import MailArrowRight from 'pixelarticons/svg/mail-arrow-right.svg'; | ||
import Menu from 'pixelarticons/svg/menu.svg'; | ||
import MoonStars from 'pixelarticons/svg/moon-stars.svg'; | ||
import Open from 'pixelarticons/svg/open.svg'; | ||
import Reload from 'pixelarticons/svg/reload.svg'; | ||
import Save from 'pixelarticons/svg/save.svg'; | ||
import Script from 'pixelarticons/svg/script.svg'; | ||
import Sun from 'pixelarticons/svg/sun.svg'; | ||
|
||
import type { PixelIcon } from '$types'; | ||
|
||
const iconNames = [ | ||
'alert', | ||
'arrow-bar-up', | ||
'arrow-left', | ||
'arrow-right', | ||
'cast', | ||
'close-box', | ||
'code', | ||
'copy', | ||
'downasaur', | ||
'link', | ||
'mail-arrow-right', | ||
'menu', | ||
'moon-stars', | ||
'open', | ||
'reload', | ||
'save', | ||
'script', | ||
'sun' | ||
] as const; | ||
|
||
const iconMap = new Map([ | ||
['alert', Alert], | ||
['arrow-bar-up', ArrowBarUp], | ||
['arrow-left', ArrowLeft], | ||
['arrow-right', ArrowRight], | ||
['cast', Cast], | ||
['close-box', CloseBox], | ||
['code', Code], | ||
['copy', Copy], | ||
['downasaur', Downasaur], | ||
['link', Link], | ||
['mail-arrow-right', MailArrowRight], | ||
['menu', Menu], | ||
['moon-stars', MoonStars], | ||
['open', Open], | ||
['reload', Reload], | ||
['save', Save], | ||
['script', Script], | ||
['sun', Sun] | ||
]) satisfies Map<(typeof iconNames)[number], PixelIcon>; | ||
|
||
const transformName = (name: string) => { | ||
return name | ||
.replace(/([a-z])([A-Z])/g, '$1-$2') | ||
.replace(/([A-Z])([A-Z])(?=[a-z])/g, '$1-$2') | ||
.replace(/([a-zA-Z])(\d)/g, '$1-$2') | ||
.replace(/([a-z])([A-Z])|([A-Z])([A-Z](?=[a-z]))|([a-zA-Z])(\d)/g, '$1$3$5-$2$4$6') | ||
.toLowerCase(); | ||
}; | ||
|
||
const iconProxy = new Proxy( | ||
new Map<string, PixelIcon>([ | ||
['alert', Alert], | ||
['sun', Sun], | ||
['moon-stars', MoonStars] | ||
]), | ||
{ | ||
get: (target, prop) => { | ||
switch (prop) { | ||
case 'get': { | ||
return (iconName: string) => { | ||
iconName = transformName(iconName); | ||
if (!target.has(iconName)) { | ||
return import(`../../node_modules/pixelarticons/svg/${iconName}.svg`) | ||
.then((res: { default: PixelIcon } | undefined) => { | ||
if (!res) { | ||
Logger.error(`Icon ${iconName} not found`); | ||
return target.get('alert'); | ||
} | ||
target.set(iconName, res.default); | ||
return res.default; | ||
}) | ||
.catch(() => target.get('alert')); | ||
} | ||
return target.get(iconName); | ||
}; | ||
} | ||
default: { | ||
return undefined; | ||
} | ||
} | ||
} | ||
const getIcon = (iconName: string) => { | ||
const name = transformName(iconName) as (typeof iconNames)[number]; | ||
if (!iconMap.has(name)) { | ||
Logger.error(`Icon ${name} not found`); | ||
return iconMap.get('alert'); | ||
} | ||
) as unknown as { | ||
get: (iconName: string) => PixelIcon; | ||
return iconMap.get(name); | ||
}; | ||
|
||
export default iconProxy; | ||
export default { get: getIcon }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.