@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/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 ? AttributeView<T['attributes']> : undefined
636
+ attributes: T['attributes'] extends AttributeSchema
637
+ ? Prettify<AttributeView<T['attributes']>>
638
+ : {}
637
639
  interleavedAttributes: T['interleavedAttributes'] extends InterleavedAttributeSchema
638
- ? InterleavedAttributeView<T['interleavedAttributes']>
639
- : undefined
640
- buffers: T['buffers'] extends BufferSchema ? BufferView<T['buffers']> : undefined
641
- uniforms: T['uniforms'] extends UniformSchema ? UniformView<T['uniforms']> : never
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 = GLSLTag | UniformTag | AttributeTag | InterleaveTag | string | number | symbol
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 GLSLTag<TSlots extends GLSLSlot[] = GLSLSlot[]> {
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 UniformTag<
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 UniformTagFn<TKind extends UniformKind> {
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<UniformTag<TKey, TKind, TDefinition>>
687
- <const TName extends string | symbol>(key: TName): Prettify<UniformTag<TName, TKind>>
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 AttributeTag<
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 AttributeTagFn<TKey extends AttributeKind> {
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<AttributeTag<TName, TKey, TDefinition['instanced']>>
706
- <TName extends string | symbol>(key: TName): Prettify<AttributeTag<TName, TKey, undefined>>
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 InterleaveTag<
718
+ export type InterleaveToken<
710
719
  TKey extends string | symbol = string | symbol,
711
- TLayout extends Array<AttributeTag<string | symbol, AttributeKind, undefined>> = Array<
712
- AttributeTag<string | symbol, AttributeKind, undefined>
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 GLSLTagToSchema<TTag extends GLSLTag> =
724
- FlattenSlots<TTag> extends infer TSlots
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], UniformTag> as K['key']]: Prettify<Omit<K, 'name' | 'type'>>
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], AttributeTag> as K['key']]: Prettify<Omit<K, 'name' | 'type'>>
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], InterleaveTag> as K['key']]: Prettify<Omit<K, 'name' | 'type'>>
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 GLSLTag<infer TSlots>
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 GLSLTag
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
- uniforms: DeepMerge<
763
- [ShallowMerge<[TVertex['uniforms'], TFragment['uniforms']]>, TOverrides['uniforms']]
764
- >
765
- attributes: DeepMerge<
766
- [ShallowMerge<[TVertex['attributes'], TFragment['attributes']]>, TOverrides['attributes']]
767
- >
768
- interleavedAttributes: DeepMerge<
769
- [
770
- ShallowMerge<[TVertex['interleavedAttributes'], TFragment['interleavedAttributes']]>,
771
- TOverrides['interleavedAttributes'],
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 GLSLTag,
778
- TFragment extends GLSLTag,
779
- TOverrides extends ViewSchemaPartial,
802
+ TVertex extends GLSL,
803
+ TFragment extends GLSL,
804
+ TOverrideSchema extends ViewSchemaPartial | undefined,
780
805
  > =
781
806
  MergeGLSLSchema<
782
- GLSLTagToSchema<TVertex>,
783
- GLSLTagToSchema<TFragment>,
784
- TOverrides
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