@@ -13,8 +13,6 @@ import i18n from 'i18next';
1313import enBack from "../locales/en/apback.json" ;
1414import { registerWindow , SVG , Svg } from "@svgdotjs/svg.js" ;
1515import { APRenderRep , type IRenderOptions , addPrefix , render } from "@abstractplay/renderer" ;
16- import { customAlphabet } from "nanoid" ;
17- const nanoid = customAlphabet ( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" , 5 ) ;
1816
1917const REGION = "us-east-1" ;
2018const s3 = new S3Client ( { region : REGION } ) ;
@@ -53,10 +51,17 @@ type SamplerEntry = {
5351 completed : ReservoirSampler < GameRec > ;
5452}
5553
56- const randomInt = ( max : number , min = 1 ) : number => {
57- min = Math . ceil ( min ) ;
58- max = Math . floor ( max ) ;
59- return Math . floor ( Math . random ( ) * ( max - min + 1 ) ) + min ;
54+ async function makeIdGenerator ( ) {
55+ // Dynamically import nanoid
56+ const { customAlphabet } = await import ( 'nanoid' ) ;
57+
58+ // Create a generator with your custom alphabet
59+ const alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' ;
60+ const length = 5 ;
61+
62+ const generate = customAlphabet ( alphabet , length ) ;
63+
64+ return generate ;
6065}
6166
6267export const handler : Handler = async ( event : any , context ?: any ) => {
@@ -283,6 +288,7 @@ export const handler: Handler = async (event: any, context?: any) => {
283288 console . log ( "Thumbnails stored" ) ;
284289
285290 // pre-render light and dark mode versions of the SVGs
291+ console . log ( "Attempting to pre-render light/dark SVGs" ) ;
286292 const contextLight = {
287293 background : "#fff" ,
288294 strokes : "#000" ,
@@ -303,15 +309,16 @@ export const handler: Handler = async (event: any, context?: any) => {
303309 [ "light" , contextLight ] ,
304310 [ "dark" , contextDark ] ,
305311 ] ) ;
306- // eslint-disable-next-line @typescript-eslint/no-var-requires
307- const { createSVGWindow } = require ( "svgdom" ) ;
312+ const generateId = await makeIdGenerator ( ) ;
313+ const svgdom = await import ( 'svgdom' ) ;
314+ const { createSVGWindow } = svgdom ;
308315 const window = createSVGWindow ( ) ;
309316 const document = window . document ;
310317
311318 // register window and document
312319 registerWindow ( window , document ) ;
313320 for ( const [ meta , json ] of allRecs . entries ( ) ) {
314- const prefix = nanoid ( ) ;
321+ const prefix = generateId ( ) ;
315322 for ( const [ name , context ] of contexts . entries ( ) ) {
316323 const canvas = SVG ( document . documentElement ) as Svg ;
317324 const opts : IRenderOptions = { prefix, target : canvas , colourContext : context } ;
@@ -328,6 +335,7 @@ export const handler: Handler = async (event: any, context?: any) => {
328335 }
329336 }
330337 }
338+ console . log ( "Pre-rendering complete" )
331339
332340 // invalidate CloudFront distribution
333341 const cfParams : CreateInvalidationCommandInput = {
0 commit comments