1
+ "use strict" ;
2
+ exports . id = 142 ;
3
+ exports . ids = [ 142 ] ;
4
+ exports . modules = {
5
+
6
+ /***/ 7142 :
7
+ /***/ ( ( __unused_webpack_module , __webpack_exports__ , __webpack_require__ ) => {
8
+
9
+ // ESM COMPAT FLAG
10
+ __webpack_require__ . r ( __webpack_exports__ ) ;
11
+
12
+ // EXPORTS
13
+ __webpack_require__ . d ( __webpack_exports__ , {
14
+ "createGif" : ( ) => ( /* binding */ createGif )
15
+ } ) ;
16
+
17
+ // EXTERNAL MODULE: external "fs"
18
+ var external_fs_ = __webpack_require__ ( 7147 ) ;
19
+ var external_fs_default = /*#__PURE__*/ __webpack_require__ . n ( external_fs_ ) ;
20
+ // EXTERNAL MODULE: external "path"
21
+ var external_path_ = __webpack_require__ ( 1017 ) ;
22
+ var external_path_default = /*#__PURE__*/ __webpack_require__ . n ( external_path_ ) ;
23
+ // EXTERNAL MODULE: external "child_process"
24
+ var external_child_process_ = __webpack_require__ ( 2081 ) ;
25
+ // EXTERNAL MODULE: external "canvas"
26
+ var external_canvas_ = __webpack_require__ ( 1576 ) ;
27
+ // EXTERNAL MODULE: ../types/grid.ts
28
+ var types_grid = __webpack_require__ ( 2881 ) ;
29
+ ; // CONCATENATED MODULE: ../draw/pathRoundedRect.ts
30
+ const pathRoundedRect_pathRoundedRect = ( ctx , width , height , borderRadius ) => {
31
+ ctx . moveTo ( borderRadius , 0 ) ;
32
+ ctx . arcTo ( width , 0 , width , height , borderRadius ) ;
33
+ ctx . arcTo ( width , height , 0 , height , borderRadius ) ;
34
+ ctx . arcTo ( 0 , height , 0 , 0 , borderRadius ) ;
35
+ ctx . arcTo ( 0 , 0 , width , 0 , borderRadius ) ;
36
+ } ;
37
+
38
+ ; // CONCATENATED MODULE: ../draw/drawGrid.ts
39
+
40
+
41
+ const drawGrid_drawGrid = ( ctx , grid , cells , o ) => {
42
+ for ( let x = grid . width ; x -- ; )
43
+ for ( let y = grid . height ; y -- ; ) {
44
+ if ( ! cells || cells . some ( ( c ) => c . x === x && c . y === y ) ) {
45
+ const c = ( 0 , types_grid /* getColor */ . Lq ) ( grid , x , y ) ;
46
+ // @ts -ignore
47
+ const color = ! c ? o . colorEmpty : o . colorDots [ c ] ;
48
+ ctx . save ( ) ;
49
+ ctx . translate ( x * o . sizeCell + ( o . sizeCell - o . sizeDot ) / 2 , y * o . sizeCell + ( o . sizeCell - o . sizeDot ) / 2 ) ;
50
+ ctx . fillStyle = color ;
51
+ ctx . strokeStyle = o . colorDotBorder ;
52
+ ctx . lineWidth = 1 ;
53
+ ctx . beginPath ( ) ;
54
+ pathRoundedRect_pathRoundedRect ( ctx , o . sizeDot , o . sizeDot , o . sizeDotBorderRadius ) ;
55
+ ctx . fill ( ) ;
56
+ ctx . stroke ( ) ;
57
+ ctx . closePath ( ) ;
58
+ ctx . restore ( ) ;
59
+ }
60
+ }
61
+ } ;
62
+
63
+ ; // CONCATENATED MODULE: ../draw/drawSnake.ts
64
+
65
+
66
+ const drawSnake_drawSnake = ( ctx , snake , o ) => {
67
+ const cells = snakeToCells ( snake ) ;
68
+ for ( let i = 0 ; i < cells . length ; i ++ ) {
69
+ const u = ( i + 1 ) * 0.6 ;
70
+ ctx . save ( ) ;
71
+ ctx . fillStyle = o . colorSnake ;
72
+ ctx . translate ( cells [ i ] . x * o . sizeCell + u , cells [ i ] . y * o . sizeCell + u ) ;
73
+ ctx . beginPath ( ) ;
74
+ pathRoundedRect ( ctx , o . sizeCell - u * 2 , o . sizeCell - u * 2 , ( o . sizeCell - u * 2 ) * 0.25 ) ;
75
+ ctx . fill ( ) ;
76
+ ctx . restore ( ) ;
77
+ }
78
+ } ;
79
+ const lerp = ( k , a , b ) => ( 1 - k ) * a + k * b ;
80
+ const clamp = ( x , a , b ) => Math . max ( a , Math . min ( b , x ) ) ;
81
+ const drawSnakeLerp = ( ctx , snake0 , snake1 , k , o ) => {
82
+ const m = 0.8 ;
83
+ const n = snake0 . length / 2 ;
84
+ for ( let i = 0 ; i < n ; i ++ ) {
85
+ const u = ( i + 1 ) * 0.6 * ( o . sizeCell / 16 ) ;
86
+ const a = ( 1 - m ) * ( i / Math . max ( n - 1 , 1 ) ) ;
87
+ const ki = clamp ( ( k - a ) / m , 0 , 1 ) ;
88
+ const x = lerp ( ki , snake0 [ i * 2 + 0 ] , snake1 [ i * 2 + 0 ] ) - 2 ;
89
+ const y = lerp ( ki , snake0 [ i * 2 + 1 ] , snake1 [ i * 2 + 1 ] ) - 2 ;
90
+ ctx . save ( ) ;
91
+ ctx . fillStyle = o . colorSnake ;
92
+ ctx . translate ( x * o . sizeCell + u , y * o . sizeCell + u ) ;
93
+ ctx . beginPath ( ) ;
94
+ pathRoundedRect_pathRoundedRect ( ctx , o . sizeCell - u * 2 , o . sizeCell - u * 2 , ( o . sizeCell - u * 2 ) * 0.25 ) ;
95
+ ctx . fill ( ) ;
96
+ ctx . restore ( ) ;
97
+ }
98
+ } ;
99
+
100
+ ; // CONCATENATED MODULE: ../draw/drawWorld.ts
101
+
102
+
103
+ const drawStack = ( ctx , stack , max , width , o ) => {
104
+ ctx . save ( ) ;
105
+ const m = width / max ;
106
+ for ( let i = 0 ; i < stack . length ; i ++ ) {
107
+ // @ts -ignore
108
+ ctx . fillStyle = o . colorDots [ stack [ i ] ] ;
109
+ ctx . fillRect ( i * m , 0 , m + width * 0.005 , 10 ) ;
110
+ }
111
+ ctx . restore ( ) ;
112
+ } ;
113
+ const drawWorld = ( ctx , grid , cells , snake , stack , o ) => {
114
+ ctx . save ( ) ;
115
+ ctx . translate ( 1 * o . sizeCell , 2 * o . sizeCell ) ;
116
+ drawGrid ( ctx , grid , cells , o ) ;
117
+ drawSnake ( ctx , snake , o ) ;
118
+ ctx . restore ( ) ;
119
+ ctx . save ( ) ;
120
+ ctx . translate ( o . sizeCell , ( grid . height + 4 ) * o . sizeCell ) ;
121
+ const max = grid . data . reduce ( ( sum , x ) => sum + + ! ! x , stack . length ) ;
122
+ drawStack ( ctx , stack , max , grid . width * o . sizeCell , o ) ;
123
+ ctx . restore ( ) ;
124
+ // ctx.save();
125
+ // ctx.translate(o.sizeCell + 100, (grid.height + 4) * o.sizeCell + 100);
126
+ // ctx.scale(0.6, 0.6);
127
+ // drawCircleStack(ctx, stack, o);
128
+ // ctx.restore();
129
+ } ;
130
+ const drawLerpWorld = ( ctx , grid , cells , snake0 , snake1 , stack , k , o ) => {
131
+ ctx . save ( ) ;
132
+ ctx . translate ( 1 * o . sizeCell , 2 * o . sizeCell ) ;
133
+ drawGrid_drawGrid ( ctx , grid , cells , o ) ;
134
+ drawSnakeLerp ( ctx , snake0 , snake1 , k , o ) ;
135
+ ctx . translate ( 0 , ( grid . height + 2 ) * o . sizeCell ) ;
136
+ const max = grid . data . reduce ( ( sum , x ) => sum + + ! ! x , stack . length ) ;
137
+ drawStack ( ctx , stack , max , grid . width * o . sizeCell , o ) ;
138
+ ctx . restore ( ) ;
139
+ } ;
140
+ const getCanvasWorldSize = ( grid , o ) => {
141
+ const width = o . sizeCell * ( grid . width + 2 ) ;
142
+ const height = o . sizeCell * ( grid . height + 4 ) + 30 ;
143
+ return { width, height } ;
144
+ } ;
145
+
146
+ // EXTERNAL MODULE: ../types/snake.ts
147
+ var types_snake = __webpack_require__ ( 9347 ) ;
148
+ ; // CONCATENATED MODULE: ../solver/step.ts
149
+
150
+
151
+ const step = ( grid , stack , snake ) => {
152
+ const x = ( 0 , types_snake /* getHeadX */ . If ) ( snake ) ;
153
+ const y = ( 0 , types_snake /* getHeadY */ . IP ) ( snake ) ;
154
+ const color = ( 0 , types_grid /* getColor */ . Lq ) ( grid , x , y ) ;
155
+ if ( ( 0 , types_grid /* isInside */ . V0 ) ( grid , x , y ) && ! ( 0 , types_grid /* isEmpty */ . xb ) ( color ) ) {
156
+ stack . push ( color ) ;
157
+ ( 0 , types_grid /* setColorEmpty */ . Dy ) ( grid , x , y ) ;
158
+ }
159
+ } ;
160
+
161
+ // EXTERNAL MODULE: ../../node_modules/tmp/lib/tmp.js
162
+ var tmp = __webpack_require__ ( 6382 ) ;
163
+ // EXTERNAL MODULE: external "gifsicle"
164
+ var external_gifsicle_ = __webpack_require__ ( 542 ) ;
165
+ var external_gifsicle_default = /*#__PURE__*/ __webpack_require__ . n ( external_gifsicle_ ) ;
166
+ // EXTERNAL MODULE: ../../node_modules/gif-encoder-2/index.js
167
+ var gif_encoder_2 = __webpack_require__ ( 3561 ) ;
168
+ var gif_encoder_2_default = /*#__PURE__*/ __webpack_require__ . n ( gif_encoder_2 ) ;
169
+ ; // CONCATENATED MODULE: ../gif-creator/index.ts
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+ // @ts -ignore
180
+
181
+ const withTmpDir = async ( handler ) => {
182
+ const { name : dir , removeCallback : cleanUp } = tmp . dirSync ( {
183
+ unsafeCleanup : true ,
184
+ } ) ;
185
+ try {
186
+ return await handler ( dir ) ;
187
+ }
188
+ finally {
189
+ cleanUp ( ) ;
190
+ }
191
+ } ;
192
+ const createGif = async ( grid0 , cells , chain , drawOptions , animationOptions ) => withTmpDir ( async ( dir ) => {
193
+ const { width, height } = getCanvasWorldSize ( grid0 , drawOptions ) ;
194
+ const canvas = ( 0 , external_canvas_ . createCanvas ) ( width , height ) ;
195
+ const ctx = canvas . getContext ( "2d" ) ;
196
+ const grid = ( 0 , types_grid /* copyGrid */ . VJ ) ( grid0 ) ;
197
+ const stack = [ ] ;
198
+ const encoder = new ( gif_encoder_2_default ( ) ) ( width , height , "neuquant" , true ) ;
199
+ encoder . setRepeat ( 0 ) ;
200
+ encoder . setDelay ( animationOptions . frameDuration ) ;
201
+ encoder . start ( ) ;
202
+ for ( let i = 0 ; i < chain . length ; i += 1 ) {
203
+ const snake0 = chain [ i ] ;
204
+ const snake1 = chain [ Math . min ( chain . length - 1 , i + 1 ) ] ;
205
+ step ( grid , stack , snake0 ) ;
206
+ for ( let k = 0 ; k < animationOptions . step ; k ++ ) {
207
+ ctx . clearRect ( 0 , 0 , width , height ) ;
208
+ ctx . fillStyle = "#fff" ;
209
+ ctx . fillRect ( 0 , 0 , width , height ) ;
210
+ drawLerpWorld ( ctx , grid , cells , snake0 , snake1 , stack , k / animationOptions . step , drawOptions ) ;
211
+ encoder . addFrame ( ctx ) ;
212
+ }
213
+ }
214
+ const outFileName = external_path_default ( ) . join ( dir , "out.gif" ) ;
215
+ const optimizedFileName = external_path_default ( ) . join ( dir , "out.optimized.gif" ) ;
216
+ encoder . finish ( ) ;
217
+ external_fs_default ( ) . writeFileSync ( outFileName , encoder . out . getData ( ) ) ;
218
+ ( 0 , external_child_process_ . execFileSync ) ( ( external_gifsicle_default ( ) ) , [
219
+ //
220
+ "--optimize=3" ,
221
+ "--color-method=diversity" ,
222
+ "--colors=18" ,
223
+ outFileName ,
224
+ [ "--output" , optimizedFileName ] ,
225
+ ] . flat ( ) ) ;
226
+ return external_fs_default ( ) . readFileSync ( optimizedFileName ) ;
227
+ } ) ;
228
+
229
+
230
+ /***/ } )
231
+
232
+ } ;
233
+ ;
0 commit comments