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