@bigmistqke/view.gl 0.1.7 → 0.1.9
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/.claude/settings.local.json +2 -1
- package/README.md +83 -42
- package/dev/src/examples/bezier.ts +3 -2
- package/dev/src/examples/game-of-life.ts +13 -30
- package/dev/src/examples/glsl-composition.ts +3 -3
- package/dev/src/examples/grid.ts +20 -14
- package/dev/src/examples/pix-sim.ts +29 -22
- package/dev/src/examples/ray-casting.ts +455 -0
- package/dev/src/examples/sdf.ts +98 -0
- package/dev/src/examples/symbol.ts +2 -2
- package/dev/src/index.ts +12 -11
- package/dev/src/utils.ts +18 -4
- package/dist/index.d.mts +2 -2
- package/dist/tag.d.mts +86 -69
- package/dist/tag.mjs +78 -37
- package/dist/tag.mjs.map +1 -1
- package/dist/{types-C4TRuvYh.d.mts → types-DaV9McmR.d.mts} +40 -33
- package/package.json +1 -1
- package/src/tag.ts +128 -59
- package/src/types.ts +76 -49
- package/test/tag.test.ts +697 -6
package/src/types.ts
CHANGED
|
@@ -416,7 +416,7 @@ export interface AttributeMethods<T = AttributeKind> {
|
|
|
416
416
|
}
|
|
417
417
|
|
|
418
418
|
export type AttributeView<T extends AttributeSchema> = {
|
|
419
|
-
[K in keyof T]: AttributeMethods<T[K]['kind']
|
|
419
|
+
[K in keyof T]: Prettify<AttributeMethods<T[K]['kind']>>
|
|
420
420
|
}
|
|
421
421
|
|
|
422
422
|
/**********************************************************************************/
|
|
@@ -633,12 +633,14 @@ export interface ViewSchemaPartial {
|
|
|
633
633
|
}
|
|
634
634
|
|
|
635
635
|
export type View<T extends ViewSchema = ViewSchema> = {
|
|
636
|
-
attributes: T['attributes'] extends AttributeSchema
|
|
636
|
+
attributes: T['attributes'] extends AttributeSchema
|
|
637
|
+
? Prettify<AttributeView<T['attributes']>>
|
|
638
|
+
: {}
|
|
637
639
|
interleavedAttributes: T['interleavedAttributes'] extends InterleavedAttributeSchema
|
|
638
|
-
? InterleavedAttributeView<T['interleavedAttributes']
|
|
639
|
-
:
|
|
640
|
-
buffers: T['buffers'] extends BufferSchema ? BufferView<T['buffers']
|
|
641
|
-
uniforms: T['uniforms'] extends UniformSchema ? UniformView<T['uniforms']
|
|
640
|
+
? Prettify<InterleavedAttributeView<T['interleavedAttributes']>>
|
|
641
|
+
: {}
|
|
642
|
+
buffers: T['buffers'] extends BufferSchema ? Prettify<BufferView<T['buffers']>> : {}
|
|
643
|
+
uniforms: T['uniforms'] extends UniformSchema ? Prettify<UniformView<T['uniforms']>> : {}
|
|
642
644
|
}
|
|
643
645
|
|
|
644
646
|
/**********************************************************************************/
|
|
@@ -652,17 +654,24 @@ export interface GLSLResult {
|
|
|
652
654
|
schema: ViewSchema
|
|
653
655
|
}
|
|
654
656
|
|
|
655
|
-
type GLSLSlotItem =
|
|
657
|
+
type GLSLSlotItem =
|
|
658
|
+
| GLSL
|
|
659
|
+
| UniformToken
|
|
660
|
+
| AttributeToken
|
|
661
|
+
| InterleaveToken
|
|
662
|
+
| string
|
|
663
|
+
| number
|
|
664
|
+
| symbol
|
|
656
665
|
|
|
657
666
|
export type GLSLSlot = GLSLSlotItem | Array<GLSLSlotItem>
|
|
658
667
|
|
|
659
|
-
export interface
|
|
668
|
+
export interface GLSL<TSlots extends GLSLSlot[] = GLSLSlot[]> {
|
|
660
669
|
type: 'glsl'
|
|
661
670
|
template: TemplateStringsArray
|
|
662
671
|
slots: TSlots
|
|
663
672
|
}
|
|
664
673
|
|
|
665
|
-
export type
|
|
674
|
+
export type UniformToken<
|
|
666
675
|
TKey extends string | symbol = string | symbol,
|
|
667
676
|
TKind extends UniformKind = UniformKind,
|
|
668
677
|
TDefinition extends Partial<UniformDefinition> = UniformDefinition,
|
|
@@ -679,37 +688,37 @@ export type UniformTag<
|
|
|
679
688
|
key: TKey
|
|
680
689
|
}
|
|
681
690
|
|
|
682
|
-
export interface
|
|
691
|
+
export interface UniformTokenFn<TKind extends UniformKind> {
|
|
683
692
|
<const TKey extends string | symbol, const TDefinition extends Omit<UniformDefinition, 'kind'>>(
|
|
684
693
|
key: TKey,
|
|
685
694
|
TDefinition: TDefinition,
|
|
686
|
-
): Prettify<
|
|
687
|
-
<const TName extends string | symbol>(key: TName): Prettify<
|
|
695
|
+
): Prettify<UniformToken<TKey, TKind, TDefinition>>
|
|
696
|
+
<const TName extends string | symbol>(key: TName): Prettify<UniformToken<TName, TKind>>
|
|
688
697
|
}
|
|
689
698
|
|
|
690
|
-
export interface
|
|
699
|
+
export interface AttributeToken<
|
|
691
700
|
TKey extends string | symbol = string | symbol,
|
|
692
701
|
TKind extends AttributeKind = AttributeKind,
|
|
693
702
|
TInstanced extends boolean | undefined = boolean | undefined,
|
|
694
703
|
> {
|
|
695
704
|
type: 'attribute'
|
|
696
705
|
kind: TKind
|
|
697
|
-
instanced: TInstanced
|
|
706
|
+
instanced: TInstanced extends boolean ? boolean : false
|
|
698
707
|
key: TKey
|
|
699
708
|
}
|
|
700
709
|
|
|
701
|
-
export interface
|
|
710
|
+
export interface AttributeTokenFn<TKey extends AttributeKind> {
|
|
702
711
|
<TName extends string | symbol, TDefinition extends Omit<AttributeDefinition, 'kind'>>(
|
|
703
712
|
key: TName,
|
|
704
713
|
options: TDefinition,
|
|
705
|
-
): Prettify<
|
|
706
|
-
<TName extends string | symbol>(key: TName): Prettify<
|
|
714
|
+
): Prettify<AttributeToken<TName, TKey, TDefinition['instanced']>>
|
|
715
|
+
<TName extends string | symbol>(key: TName): Prettify<AttributeToken<TName, TKey, undefined>>
|
|
707
716
|
}
|
|
708
717
|
|
|
709
|
-
export type
|
|
718
|
+
export type InterleaveToken<
|
|
710
719
|
TKey extends string | symbol = string | symbol,
|
|
711
|
-
TLayout extends Array<
|
|
712
|
-
|
|
720
|
+
TLayout extends Array<AttributeToken<string | symbol, AttributeKind, undefined>> = Array<
|
|
721
|
+
AttributeToken<string | symbol, AttributeKind, undefined>
|
|
713
722
|
>,
|
|
714
723
|
TDefinition extends Omit<AttributeDefinition, 'kind'> = Omit<AttributeDefinition, 'kind'>,
|
|
715
724
|
> = TDefinition & {
|
|
@@ -720,34 +729,36 @@ export type InterleaveTag<
|
|
|
720
729
|
}
|
|
721
730
|
}
|
|
722
731
|
|
|
723
|
-
export type
|
|
724
|
-
FlattenSlots<
|
|
732
|
+
export type GLSLToSchema<T extends GLSL> =
|
|
733
|
+
FlattenSlots<T> extends infer TSlots
|
|
725
734
|
? TSlots extends Array<any>
|
|
726
735
|
? GLSLSlotsToSchema<TSlots>
|
|
727
736
|
: never
|
|
728
737
|
: never
|
|
729
738
|
|
|
739
|
+
export type GLSLToView<T extends GLSL> = View<GLSLToSchema<T>>
|
|
740
|
+
|
|
730
741
|
export type GLSLSlotsToSchema<TSlots extends Array<GLSLSlot>> = {
|
|
731
742
|
uniforms: {
|
|
732
|
-
[K in Extract<TSlots[number],
|
|
743
|
+
[K in Extract<TSlots[number], UniformToken> as K['key']]: Prettify<Omit<K, 'name' | 'type'>>
|
|
733
744
|
}
|
|
734
745
|
attributes: {
|
|
735
|
-
[K in Extract<TSlots[number],
|
|
746
|
+
[K in Extract<TSlots[number], AttributeToken> as K['key']]: Prettify<Omit<K, 'name' | 'type'>>
|
|
736
747
|
}
|
|
737
748
|
interleavedAttributes: {
|
|
738
|
-
[K in Extract<TSlots[number],
|
|
749
|
+
[K in Extract<TSlots[number], InterleaveToken> as K['key']]: Prettify<Omit<K, 'name' | 'type'>>
|
|
739
750
|
}
|
|
740
751
|
}
|
|
741
752
|
|
|
742
753
|
type FlattenSlots<T> =
|
|
743
|
-
T extends
|
|
754
|
+
T extends GLSL<infer TSlots>
|
|
744
755
|
? _FlattenSlots<TSlots>
|
|
745
756
|
: T extends Array<GLSLSlot>
|
|
746
757
|
? _FlattenSlots<T>
|
|
747
758
|
: never
|
|
748
759
|
|
|
749
760
|
type _FlattenSlots<T extends Array<GLSLSlot>> = T extends [infer First, ...infer Rest]
|
|
750
|
-
? First extends
|
|
761
|
+
? First extends GLSL
|
|
751
762
|
? [...FlattenSlots<First>, ...FlattenSlots<Rest>]
|
|
752
763
|
: First extends unknown[]
|
|
753
764
|
? [...FlattenSlots<First>, ...FlattenSlots<Rest>]
|
|
@@ -757,35 +768,51 @@ type _FlattenSlots<T extends Array<GLSLSlot>> = T extends [infer First, ...infer
|
|
|
757
768
|
export type MergeGLSLSchema<
|
|
758
769
|
TVertex extends ViewSchema,
|
|
759
770
|
TFragment extends ViewSchema,
|
|
760
|
-
TOverrides extends ViewSchemaPartial = {},
|
|
761
|
-
> =
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
771
|
+
TOverrides extends ViewSchemaPartial | undefined = {},
|
|
772
|
+
> = TOverrides extends ViewSchemaPartial
|
|
773
|
+
? {
|
|
774
|
+
uniforms: Prettify<
|
|
775
|
+
DeepMerge<
|
|
776
|
+
[ShallowMerge<[TVertex['uniforms'], TFragment['uniforms']]>, TOverrides['uniforms']]
|
|
777
|
+
>
|
|
778
|
+
>
|
|
779
|
+
attributes: Prettify<
|
|
780
|
+
DeepMerge<
|
|
781
|
+
[ShallowMerge<[TVertex['attributes'], TFragment['attributes']]>, TOverrides['attributes']]
|
|
782
|
+
>
|
|
783
|
+
>
|
|
784
|
+
interleavedAttributes: Prettify<
|
|
785
|
+
DeepMerge<
|
|
786
|
+
[
|
|
787
|
+
ShallowMerge<[TVertex['interleavedAttributes'], TFragment['interleavedAttributes']]>,
|
|
788
|
+
TOverrides['interleavedAttributes'],
|
|
789
|
+
]
|
|
790
|
+
>
|
|
791
|
+
>
|
|
792
|
+
}
|
|
793
|
+
: {
|
|
794
|
+
uniforms: Prettify<ShallowMerge<[TVertex['uniforms'], TFragment['uniforms']]>>
|
|
795
|
+
attributes: Prettify<ShallowMerge<[TVertex['attributes'], TFragment['attributes']]>>
|
|
796
|
+
interleavedAttributes: Prettify<
|
|
797
|
+
ShallowMerge<[TVertex['interleavedAttributes'], TFragment['interleavedAttributes']]>
|
|
798
|
+
>
|
|
799
|
+
}
|
|
775
800
|
|
|
776
801
|
export type CompileResult<
|
|
777
|
-
TVertex extends
|
|
778
|
-
TFragment extends
|
|
779
|
-
|
|
802
|
+
TVertex extends GLSL,
|
|
803
|
+
TFragment extends GLSL,
|
|
804
|
+
TOverrideSchema extends ViewSchemaPartial | undefined,
|
|
780
805
|
> =
|
|
781
806
|
MergeGLSLSchema<
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
807
|
+
GLSLToSchema<TVertex>,
|
|
808
|
+
GLSLToSchema<TFragment>,
|
|
809
|
+
TOverrideSchema
|
|
785
810
|
> extends infer TSchema extends ViewSchema
|
|
786
811
|
? {
|
|
787
812
|
program: WebGLProgram
|
|
788
813
|
schema: TSchema
|
|
789
|
-
view: View<TSchema
|
|
814
|
+
view: Prettify<View<TSchema>>
|
|
815
|
+
vertex: string
|
|
816
|
+
fragment: string
|
|
790
817
|
}
|
|
791
818
|
: never
|