shaderkit 0.1.9 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs DELETED
@@ -1,987 +0,0 @@
1
- const WGSL_KEYWORDS = [
2
- // 5.2.6 Vector Types
3
- "vec2",
4
- "vec2i",
5
- "vec2u",
6
- "vec2f",
7
- "vec2h",
8
- "vec3",
9
- "vec3i",
10
- "vec3u",
11
- "vec3f",
12
- "vec3h",
13
- "vec4",
14
- "vec4i",
15
- "vec4u",
16
- "vec4f",
17
- "vec4h",
18
- // 5.2.7 Matrix Types
19
- "mat2x2",
20
- "mat2x2f",
21
- "mat2x2h",
22
- "mat2x3",
23
- "mat2x3f",
24
- "mat2x3h",
25
- "mat2x4",
26
- "mat2x4f",
27
- "mat2x4h",
28
- "mat3x2",
29
- "mat3x2f",
30
- "mat3x2h",
31
- "mat3x3",
32
- "mat3x3f",
33
- "mat3x3h",
34
- "mat3x4",
35
- "mat3x4f",
36
- "mat3x4h",
37
- "mat4x2",
38
- "mat4x2f",
39
- "mat4x2h",
40
- "mat4x3",
41
- "mat4x3f",
42
- "mat4x3h",
43
- "mat4x4",
44
- "mat4x4f",
45
- "mat4x4h",
46
- // 15.1.1 Type-defining Keywords
47
- "array",
48
- "atomic",
49
- "bool",
50
- "f32",
51
- "f16",
52
- "i32",
53
- // 'mat2x2',
54
- // 'mat2x3',
55
- // 'mat2x4',
56
- // 'mat3x2',
57
- // 'mat3x3',
58
- // 'mat3x4',
59
- // 'mat4x2',
60
- // 'mat4x3',
61
- // 'mat4x4',
62
- "ptr",
63
- "sampler",
64
- "sampler_comparison",
65
- "texture_1d",
66
- "texture_2d",
67
- "texture_2d_array",
68
- "texture_3d",
69
- "texture_cube",
70
- "texture_cube_array",
71
- "texture_multisampled_2d",
72
- "texture_storage_1d",
73
- "texture_storage_2d",
74
- "texture_storage_2d_array",
75
- "texture_storage_3d",
76
- "texture_depth_2d",
77
- "texture_depth_2d_array",
78
- "texture_depth_cube",
79
- "texture_depth_cube_array",
80
- "texture_depth_multisampled_2d",
81
- "u32",
82
- // 'vec2',
83
- // 'vec3',
84
- // 'vec4',
85
- // 15.1.2 Other Keywords
86
- "alias",
87
- "bitcast",
88
- "break",
89
- "case",
90
- "const",
91
- "const_assert",
92
- "continue",
93
- "continuing",
94
- "default",
95
- "discard",
96
- "else",
97
- "enable",
98
- "false",
99
- "fn",
100
- "for",
101
- "if",
102
- "let",
103
- "loop",
104
- "override",
105
- "return",
106
- "struct",
107
- "switch",
108
- "true",
109
- "var",
110
- "while",
111
- // 15.2 Reserved Words
112
- "Hullshader",
113
- "NULL",
114
- "Self",
115
- "abstract",
116
- "active",
117
- "alignas",
118
- "alignof",
119
- "as",
120
- "asm",
121
- "asm_fragment",
122
- "async",
123
- "attribute",
124
- "auto",
125
- "await",
126
- "become",
127
- "bf16",
128
- "binding_array",
129
- "cast",
130
- "catch",
131
- "class",
132
- "co_await",
133
- "co_return",
134
- "co_yield",
135
- "coherent",
136
- "column_major",
137
- "common",
138
- "compile",
139
- "compile_fragment",
140
- "concept",
141
- "const_cast",
142
- "consteval",
143
- "constexpr",
144
- "constinit",
145
- "crate",
146
- "debugger",
147
- "decltype",
148
- "delete",
149
- "demote",
150
- "demote_to_helper",
151
- "do",
152
- "dynamic_cast",
153
- "enum",
154
- "explicit",
155
- "export",
156
- "extends",
157
- "extern",
158
- "external",
159
- "f64",
160
- "fallthrough",
161
- "filter",
162
- "final",
163
- "finally",
164
- "friend",
165
- "from",
166
- "fxgroup",
167
- "get",
168
- "goto",
169
- "groupshared",
170
- "handle",
171
- "highp",
172
- "i16",
173
- "i64",
174
- "i8",
175
- "impl",
176
- "implements",
177
- "import",
178
- "inline",
179
- "instanceof",
180
- "interface",
181
- "layout",
182
- "lowp",
183
- "macro",
184
- "macro_rules",
185
- "match",
186
- "mediump",
187
- "meta",
188
- "mod",
189
- "module",
190
- "move",
191
- "mut",
192
- "mutable",
193
- "namespace",
194
- "new",
195
- "nil",
196
- "noexcept",
197
- "noinline",
198
- "nointerpolation",
199
- "noperspective",
200
- "null",
201
- "nullptr",
202
- "of",
203
- "operator",
204
- "package",
205
- "packoffset",
206
- "partition",
207
- "pass",
208
- "patch",
209
- "pixelfragment",
210
- "precise",
211
- "precision",
212
- "premerge",
213
- "priv",
214
- "protected",
215
- "pub",
216
- "public",
217
- "quat",
218
- "readonly",
219
- "ref",
220
- "regardless",
221
- "register",
222
- "reinterpret_cast",
223
- "requires",
224
- "resource",
225
- "restrict",
226
- "self",
227
- "set",
228
- "shared",
229
- "sizeof",
230
- "smooth",
231
- "snorm",
232
- "static",
233
- "static_assert",
234
- "static_cast",
235
- "std",
236
- "subroutine",
237
- "super",
238
- "target",
239
- "template",
240
- "this",
241
- "thread_local",
242
- "throw",
243
- "trait",
244
- "try",
245
- "type",
246
- "typedef",
247
- "typeid",
248
- "typename",
249
- "typeof",
250
- "u16",
251
- "u64",
252
- "u8",
253
- "union",
254
- "unless",
255
- "unorm",
256
- "unsafe",
257
- "unsized",
258
- "use",
259
- "using",
260
- "varying",
261
- "virtual",
262
- "volatile",
263
- "wgsl",
264
- "where",
265
- "with",
266
- "writeonly",
267
- "yield",
268
- // 15.4 Context-Dependent Name Tokens - Attributes
269
- "@align",
270
- "@binding",
271
- "@builtin",
272
- "@compute",
273
- "@const",
274
- "@fragment",
275
- "@group",
276
- "@id",
277
- "@interpolate",
278
- "@invariant",
279
- "@location",
280
- "@size",
281
- "@vertex",
282
- "@workgroup_size",
283
- // 15.4 Context-Dependent Name Tokens - Interpolation Types
284
- "perspective",
285
- "linear",
286
- "flat",
287
- // 15.4 Context-Dependent Name Tokens - Interpolation Sampling
288
- "center",
289
- "centroid",
290
- "sample",
291
- // 15.4 Context-Dependent Name Tokens - Built-in Values
292
- "vertex_index",
293
- "instance_index",
294
- "position",
295
- "front_facing",
296
- "frag_depth",
297
- "local_invocation_id",
298
- "local_invocation_index",
299
- "global_invocation_id",
300
- "workgroup_id",
301
- "num_workgroups",
302
- "sample_index",
303
- "sample_mask",
304
- // 15.4 Context-Dependent Name Tokens - Access Modes
305
- "read",
306
- "write",
307
- "read_write",
308
- // 15.4 Context-Dependent Name Tokens - Address Spaces
309
- "function",
310
- "private",
311
- "workgroup",
312
- "uniform",
313
- "storage",
314
- // 15.4 Context-Dependent Name Tokens - Texel Formats
315
- "rgba8unorm",
316
- "rgba8snorm",
317
- "rgba8uint",
318
- "rgba8sint",
319
- "rgba16uint",
320
- "rgba16sint",
321
- "rgba16float",
322
- "r32uint",
323
- "r32sint",
324
- "r32float",
325
- "rg32uint",
326
- "rg32sint",
327
- "rg32float",
328
- "rgba32uint",
329
- "rgba32sint",
330
- "rgba32float",
331
- "bgra8unorm",
332
- // 15.4 Context-Dependent Name Tokens - Extensions
333
- "f16",
334
- // v1 optional
335
- // 17.1 Logical Built-in Functions
336
- "all",
337
- "any",
338
- "select",
339
- // 17.2 Array Built-in Functions
340
- "arrayLength",
341
- // 17.3 Numeric Built-in Functions
342
- "abs",
343
- "acos",
344
- "acosh",
345
- "asin",
346
- "asinh",
347
- "atan",
348
- "atanh",
349
- "atan2",
350
- "ceil",
351
- "clamp",
352
- "cos",
353
- "cosh",
354
- "countLeadingZeros",
355
- "countOneBits",
356
- "countTrailingZeros",
357
- "cross",
358
- "degrees",
359
- "determinant",
360
- "distance",
361
- "dot",
362
- "exp",
363
- "exp2",
364
- "extractBits",
365
- "faceForward",
366
- "firstLeadingBit",
367
- "firstTrailingBit",
368
- "floor",
369
- "fma",
370
- "fract",
371
- "frexp",
372
- "insertBits",
373
- "inverseSqrt",
374
- "ldexp",
375
- "length",
376
- "log",
377
- "log2",
378
- "max",
379
- "min",
380
- "mix",
381
- "modf",
382
- "normalize",
383
- "pow",
384
- "quantizeToF16",
385
- "radians",
386
- "reflect",
387
- "refract",
388
- "reverseBits",
389
- "round",
390
- "saturate",
391
- "sign",
392
- "sin",
393
- "sinh",
394
- "smoothstep",
395
- "sqrt",
396
- "step",
397
- "tan",
398
- "tanh",
399
- "transpose",
400
- "trunc",
401
- // 17.4 Derivative Built-in Functions
402
- "dpdx",
403
- "dpdxCoarse",
404
- "dpdxFine",
405
- "dpdy",
406
- "dpdyCoarse",
407
- "dpdyFine",
408
- "fwidth",
409
- "fwidthCoarse",
410
- "fwidthFine",
411
- // 17.5 Texture Built-in Functions
412
- "textureDimensions",
413
- "textureGather",
414
- "textureGatherCompare",
415
- "textureLoad",
416
- "textureNumLayers",
417
- "textureNumLevels",
418
- "textureNumSamples",
419
- "textureSample",
420
- "textureSampleBias",
421
- "textureSampleCompare",
422
- "textureSampleCompareLevel",
423
- "textureSampleGrad",
424
- "textureSampleLevel",
425
- "textureSampleBaseClampToEdge",
426
- // 17.6 Atomic Built-in Functions
427
- "atomicLoad",
428
- "atomicStore",
429
- "atomicAdd",
430
- "atomicSub",
431
- "atomicMax",
432
- "atomicMin",
433
- "atomicAnd",
434
- "atomicOr",
435
- "atomicXor",
436
- "atomicExchange",
437
- "atomicCompareExchangeWeak",
438
- // 17.7 Data Packing Built-in Functions
439
- "pack4x8snorm",
440
- "pack4x8unorm",
441
- "pack2x16snorm",
442
- "pack2x16unorm",
443
- "pack2x16float",
444
- // 17.8 Data Unpacking Built-in Functions
445
- "unpack4x8snorm",
446
- "unpack4x8unorm",
447
- "unpack2x16snorm",
448
- "unpack2x16unorm",
449
- "unpack2x16float",
450
- // 17.9 Synchronization Built-in Functions
451
- "storageBarrier",
452
- "workgroupBarrier",
453
- "workgroupUniformLoad"
454
- ];
455
- const GLSL_KEYWORDS = [
456
- // 3.8 Keywords
457
- "const",
458
- "uniform",
459
- "layout",
460
- "centroid",
461
- "flat",
462
- "smooth",
463
- "break",
464
- "continue",
465
- "do",
466
- "for",
467
- "while",
468
- "switch",
469
- "case",
470
- "default",
471
- "if",
472
- "else",
473
- "in",
474
- "out",
475
- "inout",
476
- "float",
477
- "int",
478
- "void",
479
- "bool",
480
- "true",
481
- "false",
482
- "invariant",
483
- "discard",
484
- "return",
485
- "mat2",
486
- "mat3",
487
- "mat4",
488
- "mat2x2",
489
- "mat2x3",
490
- "mat2x4",
491
- "mat3x2",
492
- "mat3x3",
493
- "mat3x4",
494
- "mat4x2",
495
- "mat4x3",
496
- "mat4x4",
497
- "vec2",
498
- "vec3",
499
- "vec4",
500
- "ivec2",
501
- "ivec3",
502
- "ivec4",
503
- "bvec2",
504
- "bvec3",
505
- "bvec4",
506
- "uint",
507
- "uvec2",
508
- "uvec3",
509
- "uvec4",
510
- "lowp",
511
- "mediump",
512
- "highp",
513
- "precision",
514
- "sampler2D",
515
- "sampler3D",
516
- "samplerCube",
517
- "sampler2DShadow",
518
- "samplerCubeShadow",
519
- "sampler2DArray",
520
- "sampler2DArrayShadow",
521
- "isampler2D",
522
- "isampler3D",
523
- "isamplerCube",
524
- "isampler2DArray",
525
- "usampler2D",
526
- "usampler3D",
527
- "usamplerCube",
528
- "usampler2DArray",
529
- "struct",
530
- // 3.8 Keywords - Reserved for future use
531
- "attribute",
532
- "varying",
533
- "coherent",
534
- "volatile",
535
- "restrict",
536
- "readonly",
537
- "writeonly",
538
- "resource",
539
- "atomic_uint",
540
- "noperspective",
541
- "patch",
542
- "sample",
543
- "subroutine",
544
- "common",
545
- "partition",
546
- "active",
547
- "asm",
548
- "class",
549
- "union",
550
- "enum",
551
- "typedef",
552
- "template",
553
- "this",
554
- "goto",
555
- "inline",
556
- "noinline",
557
- "volatile",
558
- "public",
559
- "static",
560
- "extern",
561
- "external",
562
- "interface",
563
- "long",
564
- "short",
565
- "double",
566
- "half",
567
- "fixed",
568
- "unsigned",
569
- "superp",
570
- "input",
571
- "output",
572
- "hvec2",
573
- "hvec3",
574
- "hvec4",
575
- "dvec2",
576
- "dvec3",
577
- "dvec4",
578
- "fvec2",
579
- "fvec3",
580
- "fvec4",
581
- "sampler3DRect",
582
- "filter",
583
- "image1D",
584
- "image2D",
585
- "image3D",
586
- "imageCube",
587
- "iimage1D",
588
- "iimage2D",
589
- "iimage3D",
590
- "iimageCube",
591
- "uimage1D",
592
- "uimage2D",
593
- "uimage3D",
594
- "uimageCube",
595
- "image1DArray",
596
- "image2DArray",
597
- "iimage1DArray",
598
- "iimage2DArray",
599
- "uimage1DArray",
600
- "uimage2DArray",
601
- "imageBuffer",
602
- "iimageBuffer",
603
- "uimageBuffer",
604
- "sampler1D",
605
- "sampler1DShadow",
606
- "sampler1DArray",
607
- "sampler1DArrayShadow",
608
- "isampler1D",
609
- "isampler1DArray",
610
- "usampler1D",
611
- "usampler1DArray",
612
- "sampler2DRect",
613
- "sampler2DRectShadow",
614
- "isampler2DRect",
615
- "usampler2DRect",
616
- "samplerBuffer",
617
- "isamplerBuffer",
618
- "usamplerBuffer",
619
- "sampler2DMS",
620
- "isampler2DMS",
621
- "usampler2DMS",
622
- "sampler2DMSArray",
623
- "isampler2DMSArray",
624
- "usampler2DMSArray",
625
- "sizeof",
626
- "cast",
627
- "namespace",
628
- "using",
629
- // 3.5 Preprocessor
630
- "#define",
631
- "#undef",
632
- "#if",
633
- "#ifdef",
634
- "#ifndef",
635
- "#else",
636
- "#elif",
637
- "#endif",
638
- "#error",
639
- "#pragma",
640
- "#extension",
641
- "#version",
642
- "#line",
643
- // 3.5 Preprocessor - Operators
644
- "defined",
645
- // 3.5 Preprocessor - Macros
646
- "__LINE__",
647
- "__FILE__",
648
- "__VERSION__",
649
- "GL_ES",
650
- // 7.1 Vertex Shader Special Variables
651
- "gl_VertexID",
652
- "gl_InstanceID",
653
- "gl_Position",
654
- "gl_PointSize",
655
- // 7.2 Fragment Shader Special Variables
656
- "gl_FragCoord",
657
- "gl_FrontFacing",
658
- "gl_FragDepth",
659
- "gl_PointCoord",
660
- // 7.3 Built-in Constants
661
- "gl_MaxVertexAttribs",
662
- "gl_MaxVertexUniformVectors",
663
- "gl_MaxVertexOutputVectors",
664
- "gl_MaxFragmentInputVectors",
665
- "gl_MaxVertexTextureImageUnits",
666
- "gl_MaxCombinedTextureImageUnits",
667
- "gl_MaxTextureImageUnits",
668
- "gl_MaxFragmentUniformVectors",
669
- "gl_MaxDrawBuffers",
670
- "gl_MinProgramTexelOffset",
671
- "gl_MaxProgramTexelOffset",
672
- // 7.4 Built-in Uniform State
673
- "gl_DepthRangeParameters",
674
- "gl_DepthRange",
675
- // 8.1 Angle and Trigonometry Functions
676
- "radians",
677
- "degrees",
678
- "sin",
679
- "cos",
680
- "tan",
681
- "asin",
682
- "acos",
683
- "atan",
684
- "sinh",
685
- "cosh",
686
- "tanh",
687
- "asinh",
688
- "acosh",
689
- "atanh",
690
- // 8.2 Exponential Functions
691
- "pow",
692
- "exp",
693
- "log",
694
- "exp2",
695
- "log2",
696
- "sqrt",
697
- "inversesqrt",
698
- // 8.3 Common Functions
699
- "abs",
700
- "sign",
701
- "floor",
702
- "trunc",
703
- "round",
704
- "roundEven",
705
- "ceil",
706
- "fract",
707
- "mod",
708
- "modf",
709
- "min",
710
- "max",
711
- "clamp",
712
- "mix",
713
- "step",
714
- "smoothstep",
715
- "isnan",
716
- "isinf",
717
- "floatBitsToInt",
718
- "floatBitsToUint",
719
- "intBitsToFloat",
720
- "uintBitsToFloat",
721
- // 8.4 Floating-Point Pack and Unpack Functions
722
- "packSnorm2x16",
723
- "unpackSnorm2x16",
724
- "packUnorm2x16",
725
- "unpackUnorm2x16",
726
- "packHalf2x16",
727
- "unpackHalf2x16",
728
- // 8.5 Geometric Functions
729
- "length",
730
- "distance",
731
- "dot",
732
- "cross",
733
- "normalize",
734
- "faceforward",
735
- "reflect",
736
- "refract",
737
- "matrixCompMult",
738
- "outerProduct",
739
- "transpose",
740
- "determinant",
741
- "inverse",
742
- // 8.7 Vector Relational Functions
743
- "lessThan",
744
- "lessThanEqual",
745
- "greaterThan",
746
- "greaterThanEqual",
747
- "equal",
748
- "notEqual",
749
- "any",
750
- "all",
751
- "not",
752
- // 8.8 Texture Lookup Functions
753
- "textureSize",
754
- "texture",
755
- "textureProj",
756
- "textureLod",
757
- "textureOffset",
758
- "texelFetch",
759
- "texelFetchOffset",
760
- "textureProjOffset",
761
- "textureLodOffset",
762
- "textureProjLod",
763
- "textureProjLodOffset",
764
- "textureGrad",
765
- "textureGradOffset",
766
- "textureProjGrad",
767
- "textureProjGradOffset",
768
- // 8.9 Fragment Processing Functions
769
- "dFdx",
770
- "dFdy",
771
- "fwidth",
772
- // Additional directives
773
- "#include",
774
- // WEBGL_multi_draw https://registry.khronos.org/webgl/extensions/WEBGL_multi_draw
775
- "gl_DrawID",
776
- // vertex only
777
- // OVR_multiview2 https://registry.khronos.org/webgl/extensions/OVR_multiview2
778
- // OCULUS_multiview https://github.com/KhronosGroup/WebGL/issues/2912
779
- "gl_ViewID_OVR",
780
- "GL_OVR_multiview2"
781
- ];
782
- const SYMBOLS = [
783
- // Comments
784
- "//",
785
- "/*",
786
- "*/",
787
- // Punctuation
788
- ":",
789
- ",",
790
- ".",
791
- "{",
792
- "[",
793
- "(",
794
- "?",
795
- "}",
796
- "]",
797
- ")",
798
- ";",
799
- // Unary
800
- "~",
801
- "--",
802
- "++",
803
- "!",
804
- // Binary
805
- "&",
806
- "|",
807
- "^",
808
- "/",
809
- "==",
810
- ">",
811
- ">=",
812
- "<",
813
- "<=",
814
- "&&",
815
- "||",
816
- "^^",
817
- "-",
818
- "*",
819
- "!=",
820
- "+",
821
- "%",
822
- "<<",
823
- ">>",
824
- // Binary assignment
825
- "=",
826
- "+=",
827
- "&=",
828
- "|=",
829
- "^=",
830
- "/=",
831
- "*=",
832
- "%=",
833
- "<<=",
834
- ">>=",
835
- "-="
836
- ];
837
- const GLSL_SYMBOLS = [
838
- ...SYMBOLS,
839
- // Preprocessor
840
- "#",
841
- // Line continuation
842
- "\\"
843
- ];
844
- const WGSL_SYMBOLS = [
845
- ...SYMBOLS,
846
- // Function arrow
847
- "->",
848
- // Attribute
849
- "@"
850
- ];
851
- const isWGSL = RegExp.prototype.test.bind(/\bfn\s+\w+\s*\(|\b(var|let)\s+\w+\s*[:=]/);
852
- const isFloat = RegExp.prototype.test.bind(/\.|[eEpP][-+]?\d|[fFhH]$/);
853
- const isBool = RegExp.prototype.test.bind(/^(true|false)$/);
854
- const ZERO = 48;
855
- const NINE = 57;
856
- const A = 65;
857
- const Z = 90;
858
- const LF = 10;
859
- const CR = 13;
860
- const TAB = 9;
861
- const SPACE = 32;
862
- const PLUS = 43;
863
- const MINUS = 45;
864
- const DOT = 46;
865
- const UNDERSCORE = 95;
866
- const SLASH = 47;
867
- const STAR = 42;
868
- const HASH = 35;
869
- const AT = 64;
870
- const isDigit = (c) => ZERO <= c && c <= NINE;
871
- const isAlpha = (c) => (c &= ~32, A <= c && c <= Z);
872
- const isLine = (c) => c === LF || c === CR;
873
- const isSpace = (c) => isLine(c) || c === TAB || c === SPACE;
874
- const isNumber = (c) => isAlpha(c) || isDigit(c) || c === PLUS || c === MINUS || c === DOT;
875
- const isIdent = (c) => isAlpha(c) || isDigit(c) || c === UNDERSCORE;
876
- const isMacro = (c) => c === HASH || c === AT;
877
- function tokenize(code, index = 0) {
878
- const tokens = [];
879
- let prev = -1;
880
- const [KEYWORDS, SYMBOLS2] = isWGSL(code) ? [WGSL_KEYWORDS, WGSL_SYMBOLS] : [GLSL_KEYWORDS, GLSL_SYMBOLS];
881
- while (index < code.length) {
882
- let value = code[index];
883
- const char = code.charCodeAt(index++);
884
- if (isSpace(char)) {
885
- while (isSpace(code.charCodeAt(index)))
886
- value += code[index++];
887
- tokens.push({ type: "whitespace", value });
888
- } else if (isDigit(char)) {
889
- while (isNumber(code.charCodeAt(index)))
890
- value += code[index++];
891
- if (isFloat(value))
892
- tokens.push({ type: "float", value });
893
- else
894
- tokens.push({ type: "int", value });
895
- } else if (isIdent(char)) {
896
- while (isIdent(code.charCodeAt(index)))
897
- value += code[index++];
898
- if (isBool(value))
899
- tokens.push({ type: "bool", value });
900
- else if (KEYWORDS.includes(isMacro(prev) ? String.fromCharCode(prev) + value : value))
901
- tokens.push({ type: "keyword", value });
902
- else
903
- tokens.push({ type: "identifier", value });
904
- } else if (char === SLASH && (code.charCodeAt(index) === SLASH || code.charCodeAt(index) === STAR)) {
905
- const terminator = code.charCodeAt(index) === STAR ? "*/" : "\n";
906
- while (!value.endsWith(terminator))
907
- value += code[index++];
908
- tokens.push({ type: "comment", value });
909
- } else {
910
- for (const symbol of SYMBOLS2) {
911
- if (symbol.length > value.length && code.startsWith(symbol, index - 1))
912
- value = symbol;
913
- }
914
- index += value.length - 1;
915
- tokens.push({ type: "symbol", value });
916
- }
917
- prev = char;
918
- }
919
- return tokens;
920
- }
921
- const isWord = RegExp.prototype.test.bind(/^\w/);
922
- const isSymbol = RegExp.prototype.test.bind(/[^\w\\]/);
923
- const isName = RegExp.prototype.test.bind(/^[_A-Za-z]/);
924
- const isStorage = RegExp.prototype.test.bind(/^(uniform|in|out|attribute|varying|,)$/);
925
- function minify(code, { mangle = false, mangleMap = /* @__PURE__ */ new Map(), mangleExternals = false } = {}) {
926
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
927
- code = code.replace(/(^\s*#[^\\]*?)(\n|\/[\/\*])/gm, "$1\\$2");
928
- const exclude = new Set(mangleMap.values());
929
- const tokens = tokenize(code).filter((token) => token.type !== "whitespace" && token.type !== "comment");
930
- let mangleIndex = 0;
931
- let blockIndex = null;
932
- let minified = "";
933
- for (let i = 0; i < tokens.length; i++) {
934
- const token = tokens[i];
935
- if (isWord(token.value) && isWord((_a = tokens[i - 1]) == null ? void 0 : _a.value))
936
- minified += " ";
937
- if (token.value === "{" && isName((_b = tokens[i - 1]) == null ? void 0 : _b.value))
938
- blockIndex = i - 1;
939
- else if (token.value === "}")
940
- blockIndex = null;
941
- if (isSymbol(token.value) && (((_c = tokens[i - 2]) == null ? void 0 : _c.value) === "#" && ((_d = tokens[i - 1]) == null ? void 0 : _d.value) === "include" || ((_e = tokens[i - 3]) == null ? void 0 : _e.value) === "#" && ((_f = tokens[i - 2]) == null ? void 0 : _f.value) === "define"))
942
- minified += " ";
943
- if (token.type === "identifier" && // Filter variable names
944
- token.value !== "main" && (typeof mangle === "boolean" ? mangle : mangle(token, i, tokens))) {
945
- let renamed = mangleMap.get(token.value);
946
- if (
947
- // no-op
948
- !renamed && // Skip struct properties
949
- blockIndex == null && // Is declaration, reference, namespace, or comma-separated list
950
- (isName((_g = tokens[i - 1]) == null ? void 0 : _g.value) || // uniform Type { ... } name;
951
- ((_h = tokens[i - 1]) == null ? void 0 : _h.value) === "}" && ((_i = tokens[i + 1]) == null ? void 0 : _i.value) === ";" || // float foo, bar;
952
- ((_j = tokens[i - 1]) == null ? void 0 : _j.value) === "," || // fn (arg: type) -> void
953
- ((_k = tokens[i + 1]) == null ? void 0 : _k.value) === ":") && // Skip shader externals when disabled
954
- (mangleExternals || !isStorage((_l = tokens[i - 1]) == null ? void 0 : _l.value) && !isStorage((_m = tokens[i - 2]) == null ? void 0 : _m.value))
955
- ) {
956
- while (!renamed || exclude.has(renamed)) {
957
- renamed = "";
958
- mangleIndex++;
959
- let j = mangleIndex;
960
- while (j > 0) {
961
- renamed = String.fromCharCode(97 + (j - 1) % 26) + renamed;
962
- j = Math.floor(j / 26);
963
- }
964
- }
965
- mangleMap.set(token.value, renamed);
966
- }
967
- minified += renamed != null ? renamed : token.value;
968
- } else {
969
- if (token.value === "#" && ((_n = tokens[i - 1]) == null ? void 0 : _n.value) !== "\\")
970
- minified += "\n#";
971
- else if (token.value === "\\")
972
- minified += "\n";
973
- else
974
- minified += token.value;
975
- }
976
- }
977
- return minified.trim();
978
- }
979
- export {
980
- GLSL_KEYWORDS,
981
- GLSL_SYMBOLS,
982
- WGSL_KEYWORDS,
983
- WGSL_SYMBOLS,
984
- minify,
985
- tokenize
986
- };
987
- //# sourceMappingURL=index.mjs.map