glre 0.14.0 → 0.16.0

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/package.json CHANGED
@@ -1,67 +1,67 @@
1
- {
2
- "name": "glre",
3
- "author": "tseijp",
4
- "license": "MIT",
5
- "version": "0.14.0",
6
- "module": "index.js",
7
- "types": "index.ts",
8
- "main": "index.cjs.js",
9
- "umd": "index.develop.js",
10
- "private": false,
11
- "sideEffect": false,
12
- "publishConfig": {
13
- "access": "public"
14
- },
15
- "dependencies": {
16
- "reev": "0.10.0",
17
- "refr": "0.3.0"
18
- },
19
- "keywords": [
20
- "glsl",
21
- "webgl",
22
- "hooks",
23
- "react",
24
- "reactjs",
25
- "reactive",
26
- "solid",
27
- "solidjs",
28
- "typescript"
29
- ],
30
- "peerDependencies": {
31
- "expo": "*",
32
- "expo-gl": "*",
33
- "react": ">=16.8",
34
- "react-dom": ">=16.8",
35
- "solid-js": "*"
36
- },
37
- "peerDependenciesMeta": {
38
- "expo": {
39
- "optional": true
40
- },
41
- "expo-gl": {
42
- "optional": true
43
- },
44
- "react": {
45
- "optional": true
46
- },
47
- "react-dom": {
48
- "optional": true
49
- },
50
- "solid-js": {
51
- "optional": true
52
- }
53
- },
54
- "files": [
55
- "index.js",
56
- "index.cjs.js",
57
- "index.develop.js",
58
- "index.product.js",
59
- "index.ts",
60
- "native.ts",
61
- "qwik.ts",
62
- "react.ts",
63
- "solid.ts",
64
- "types.ts",
65
- "utils.ts"
66
- ]
67
- }
1
+ {
2
+ "name": "glre",
3
+ "author": "tseijp",
4
+ "license": "MIT",
5
+ "version": "0.16.0",
6
+ "module": "index.js",
7
+ "types": "index.ts",
8
+ "main": "index.cjs.js",
9
+ "umd": "index.develop.js",
10
+ "private": false,
11
+ "sideEffect": false,
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "dependencies": {
16
+ "reev": "0.10.0",
17
+ "refr": "0.3.0"
18
+ },
19
+ "keywords": [
20
+ "glsl",
21
+ "webgl",
22
+ "hooks",
23
+ "react",
24
+ "reactjs",
25
+ "reactive",
26
+ "solid",
27
+ "solidjs",
28
+ "typescript"
29
+ ],
30
+ "peerDependencies": {
31
+ "expo": "*",
32
+ "expo-gl": "*",
33
+ "react": ">=16.8",
34
+ "react-dom": ">=16.8",
35
+ "solid-js": "*"
36
+ },
37
+ "peerDependenciesMeta": {
38
+ "expo": {
39
+ "optional": true
40
+ },
41
+ "expo-gl": {
42
+ "optional": true
43
+ },
44
+ "react": {
45
+ "optional": true
46
+ },
47
+ "react-dom": {
48
+ "optional": true
49
+ },
50
+ "solid-js": {
51
+ "optional": true
52
+ }
53
+ },
54
+ "files": [
55
+ "index.js",
56
+ "index.cjs.js",
57
+ "index.develop.js",
58
+ "index.product.js",
59
+ "index.ts",
60
+ "native.ts",
61
+ "qwik.ts",
62
+ "react.ts",
63
+ "solid.ts",
64
+ "types.ts",
65
+ "utils.ts"
66
+ ]
67
+ }
package/qwik.ts CHANGED
@@ -1,42 +1,42 @@
1
- import { useSignal, useVisibleTask$, $ } from '@builder.io/qwik'
2
- import { gl } from './index'
3
- import { frame } from 'refr'
4
- import type { GL } from './types'
5
- import type { Fun } from 'reev/types'
6
-
7
- export function useGL(props?: any, self = $(gl) as unknown as GL) {
8
- const ref = useSignal<Element>()
9
- useVisibleTask$(({ cleanup }) => {
10
- self(props)
11
- self.el = self.target = ref.value
12
- self.gl = self.target.getContext('webgl2')
13
- self.init()
14
- self.resize()
15
- frame.start()
16
- window.addEventListener('resize', self.resize)
17
- window.addEventListener('mousemove', self.mousemove)
18
- cleanup(() => {
19
- self.clean()
20
- window.removeEventListener('resize', self.resize)
21
- window.removeEventListener('mousemove', self.mousemove)
22
- })
23
- })
24
- return self
25
- }
26
-
27
- export function useTexture(props: any, self = gl) {
28
- return self?.texture(props)
29
- }
30
-
31
- export function useAttribute(props: any, self = gl) {
32
- return self.attribute(props)
33
- }
34
-
35
- export function useUniform(props: any, self = gl) {
36
- return self.uniform(props)
37
- }
38
-
39
- export function useFrame(fun: Fun, self = gl) {
40
- useTask$(() => self.frame(fun))
41
- return self
42
- }
1
+ import { useSignal, useVisibleTask$, $ } from '@builder.io/qwik'
2
+ import { gl } from './index'
3
+ import { frame } from 'refr'
4
+ import type { GL } from './types'
5
+ import type { Fun } from 'reev/types'
6
+
7
+ export function useGL(props?: any, self = $(gl) as unknown as GL) {
8
+ const ref = useSignal<Element>()
9
+ useVisibleTask$(({ cleanup }) => {
10
+ self(props)
11
+ self.el = self.target = ref.value
12
+ self.gl = self.target.getContext('webgl2')
13
+ self.init()
14
+ self.resize()
15
+ frame.start()
16
+ window.addEventListener('resize', self.resize)
17
+ window.addEventListener('mousemove', self.mousemove)
18
+ cleanup(() => {
19
+ self.clean()
20
+ window.removeEventListener('resize', self.resize)
21
+ window.removeEventListener('mousemove', self.mousemove)
22
+ })
23
+ })
24
+ return self
25
+ }
26
+
27
+ export function useTexture(props: any, self = gl) {
28
+ return self?.texture(props)
29
+ }
30
+
31
+ export function useAttribute(props: any, self = gl) {
32
+ return self.attribute(props)
33
+ }
34
+
35
+ export function useUniform(props: any, self = gl) {
36
+ return self.uniform(props)
37
+ }
38
+
39
+ export function useFrame(fun: Fun, self = gl) {
40
+ useTask$(() => self.frame(fun))
41
+ return self
42
+ }
package/react.ts CHANGED
@@ -1,59 +1,66 @@
1
- import { useState, useEffect, useMemo } from 'react'
2
- import { gl } from './index'
3
- import { frame } from 'refr'
4
- import { mutable } from 'reev'
5
- import type { GL } from './types'
6
- import type { Fun } from 'refr'
7
- import type { MutableArgs } from 'reev/types'
8
-
9
- export const useMutable = <T extends object>(...args: MutableArgs<T>) => {
10
- const [memo] = useState(() => mutable<T>())
11
- return memo(...args)
12
- }
13
-
14
- export const useGL = (props: Partial<GL> = {}, self = gl) => {
15
- const memo1 = useMutable(props) as Partial<GL>
16
- const memo2 = useMutable({
17
- ref(target: unknown) {
18
- if (target) {
19
- self.target = target
20
- self.mount()
21
- } else self.clean()
22
- },
23
- mount() {
24
- self.el = self.target
25
- self.gl = self.target.getContext('webgl2')
26
- self.init()
27
- self.resize()
28
- frame.start()
29
- window.addEventListener('resize', self.resize)
30
- window.addEventListener('mousemove', self.mousemove)
31
- },
32
- clean() {
33
- frame.cancel()
34
- window.removeEventListener('resize', self.resize)
35
- window.removeEventListener('mousemove', self.mousemove)
36
- },
37
- }) as Partial<GL>
38
-
39
- return useMemo(() => self(memo2)(memo1), [self, memo1, memo2])
40
- }
41
-
42
- export function useTexture(props: any, self = gl) {
43
- return self.texture(props)
44
- }
45
-
46
- export function useAttribute(props: any, self = gl) {
47
- return self.attribute(props)
48
- }
49
-
50
- export function useUniform(props: any, self = gl) {
51
- return self.uniform(props)
52
- }
53
-
54
- export function useFrame(fun: Fun, self = gl) {
55
- const ref = useMutable(fun)
56
- useEffect(() => self.frame(fun), [])
57
- useEffect(() => () => self.frame(ref), [])
58
- return self
59
- }
1
+ import { useState, useEffect, useMemo } from 'react'
2
+ import { createTF, gl } from './index'
3
+ import { frame } from 'refr'
4
+ import { mutable } from 'reev'
5
+ import type { GL } from './types'
6
+ import type { Fun } from 'refr'
7
+ import type { MutableArgs } from 'reev/types'
8
+
9
+ export const useMutable = <T extends object>(...args: MutableArgs<T>) => {
10
+ const [memo] = useState(() => mutable<T>())
11
+ return memo(...args)
12
+ }
13
+
14
+ export const useGL = (props: Partial<GL> = {}, self = gl) => {
15
+ const memo1 = useMutable(props) as Partial<GL>
16
+ const memo2 = useMutable({
17
+ ref(target: unknown) {
18
+ if (target) {
19
+ self.target = target
20
+ self.mount()
21
+ } else self.clean()
22
+ },
23
+ mount() {
24
+ self.el = self.target
25
+ self.gl = self.target.getContext('webgl2')
26
+ self.init()
27
+ self.resize()
28
+ frame.start()
29
+ window.addEventListener('resize', self.resize)
30
+ self.el.addEventListener('mousemove', self.mousemove)
31
+ },
32
+ clean() {
33
+ self(memo2)(memo1)
34
+ frame.cancel()
35
+ window.removeEventListener('resize', self.resize)
36
+ },
37
+ }) as Partial<GL>
38
+
39
+ return useMemo(() => self(memo2)(memo1), [self, memo1, memo2])
40
+ }
41
+
42
+ export const useTF = (props: Partial<GL>, self = gl) => {
43
+ const memo = useMutable(props) as Partial<GL>
44
+ const tf = useMemo(() => createTF(memo, self), [memo, self])
45
+ useEffect(() => void tf.mount() || tf.clean, [self])
46
+ return tf
47
+ }
48
+
49
+ export function useTexture(props: any, self = gl) {
50
+ return self.texture(props)
51
+ }
52
+
53
+ export function useAttribute(props: any, self = gl) {
54
+ return self.attribute(props)
55
+ }
56
+
57
+ export function useUniform(props: any, self = gl) {
58
+ return self.uniform(props)
59
+ }
60
+
61
+ export function useFrame(fun: Fun, self = gl) {
62
+ const ref = useMutable(fun)
63
+ useEffect(() => self.frame(fun), [])
64
+ useEffect(() => () => self.frame(ref), [])
65
+ return self
66
+ }
package/solid.ts CHANGED
@@ -1,45 +1,51 @@
1
- import { onMount, onCleanup } from 'solid-js'
2
- import { frame } from 'refr'
3
- import { gl } from './index'
4
- import type { Fun } from 'reev/types'
5
-
6
- export function createGL(props?: any, self = gl) {
7
- onCleanup(self.clean)
8
-
9
- return self({
10
- ref(target: unknown) {
11
- if (target) {
12
- self.target = target
13
- self.mount()
14
- }
15
- },
16
- mount() {
17
- self(props)
18
- self.el = self.target
19
- self.gl = self.target.getContext('webgl2')
20
- self.init()
21
- self.resize()
22
- frame.start()
23
- window.addEventListener('resize', self.resize)
24
- window.addEventListener('mousemove', self.mousemove)
25
- },
26
- clean() {
27
- self(props)
28
- frame.cancel()
29
- window.removeEventListener('resize', self.resize)
30
- window.removeEventListener('mousemove', self.mousemove)
31
- },
32
- })
33
- }
34
-
35
- export function onFrame(fun: Fun, self = gl) {
36
- onMount(() => self('render', fun))
37
- }
38
-
39
- export function setTexture(props: any, self = gl) {
40
- return self.texture(props)
41
- }
42
-
43
- export function setAttribute(props: any, self = gl) {
44
- return self.attribute(props)
45
- }
1
+ import { onMount, onCleanup } from 'solid-js'
2
+ import { frame } from 'refr'
3
+ import { gl } from './index'
4
+ import type { Fun } from 'reev/types'
5
+
6
+ export function createGL(props?: any, self = gl) {
7
+ const memo = {
8
+ ref(target: unknown) {
9
+ if (target) {
10
+ self.target = target
11
+ self.mount()
12
+ }
13
+ },
14
+ mount() {
15
+ self.el = self.target
16
+ self.gl = self.target.getContext('webgl2')
17
+ self.init()
18
+ self.resize()
19
+ frame.start()
20
+ window.addEventListener('resize', self.resize)
21
+ window.addEventListener('mousemove', self.mousemove)
22
+ },
23
+ clean() {
24
+ self(props)(memo)
25
+ frame.cancel()
26
+ window.removeEventListener('resize', self.resize)
27
+ window.removeEventListener('mousemove', self.mousemove)
28
+ },
29
+ }
30
+ onCleanup(self.clean)
31
+ return self(props)(memo)
32
+ }
33
+
34
+ export const createTF = (props: any, self = gl) => {
35
+ const tf = createTF(props, self)
36
+ onMount(() => tf.mount())
37
+ onCleanup(() => tf.clean())
38
+ return tf
39
+ }
40
+
41
+ export function onFrame(fun: Fun, self = gl) {
42
+ onMount(() => self('render', fun))
43
+ }
44
+
45
+ export function setTexture(props: any, self = gl) {
46
+ return self.texture(props)
47
+ }
48
+
49
+ export function setAttribute(props: any, self = gl) {
50
+ return self.attribute(props)
51
+ }
package/types.ts CHANGED
@@ -1,98 +1,101 @@
1
- import type { Queue } from 'refr/types'
2
- import type { Nested, EventState } from 'reev/types'
3
-
4
- export type Uniform = number | number[]
5
-
6
- export type Attribute = number[]
7
-
8
- export type Attributes = Record<string, Attribute>
9
-
10
- export type Uniforms = Record<string, Uniform>
11
-
12
- export type GL = EventState<{
13
- /**
14
- * initial value
15
- */
16
- id: string
17
- size: [number, number]
18
- mouse: [number, number]
19
- count: number
20
- vs: string
21
- fs: string
22
- vert: string
23
- frag: string
24
- vertex: string
25
- fragment: string
26
- int: PrecisionMode
27
- float: PrecisionMode
28
- sampler2D: PrecisionMode
29
- samplerCube: PrecisionMode
30
- lastActiveUnit: number
31
-
32
- /**
33
- * core state
34
- */
35
- gl: any
36
- pg: any
37
- el: any
38
- frame: Queue
39
- target: any
40
- stride: Nested<number>
41
- // @TODO Nested<(key: string, value: number: number[], ibo: number[]) => number>
42
- location: Nested<any>
43
- activeUnit: Nested<number>
44
- default: any
45
-
46
- /**
47
- * events
48
- */
49
- ref?: any
50
- init(varying?: string[]): void
51
- mount(): void
52
- clean(): void
53
- render(): void
54
- mousemove(e: Event): void
55
- resize(e?: Event, width?: number, height?: number): void
56
- load(e?: Event, image?: HTMLImageElement): void
57
-
58
- /**
59
- * setter
60
- */
61
- _uniform(key: string, value: Uniform): GL
62
- uniform(key: string, value: Uniform): GL
63
- uniform(target: { [key: string]: Uniform }): GL
64
- _texture(key: string, value: string): GL
65
- texture(key: string, value: string): GL
66
- texture(target: { [key: string]: string }): GL
67
- _attribute(key: string, value: Attribute, iboValue?: Attribute): GL
68
- attribute(key: string, value: Attribute, iboValue?: Attribute): GL
69
- attribute(target: { [key: string]: Attribute }): GL
70
- // config(key?: keyof GL, value?: GL[keyof GL]): GL
71
- // config(target?: Partial<GL>): GL
72
-
73
- /**
74
- * short hands
75
- */
76
- clear(key?: GLClearMode): void
77
- viewport(size?: [number, number]): void
78
- drawArrays(key?: GLDrawMode): void
79
- drawElements(key?: GLDrawMode): void
80
- }>
81
-
82
- export type PrecisionMode = 'highp' | 'mediump' | 'lowp'
83
-
84
- export type GLClearMode =
85
- | 'COLOR_BUFFER_BIT'
86
- | 'DEPTH_BUFFER_BIT'
87
- | 'STENCIL_BUFFER_BIT'
88
-
89
- export type GLDrawMode =
90
- | 'POINTS'
91
- | 'LINE_STRIP'
92
- | 'LINE_LOOP'
93
- | 'LINES'
94
- | 'TRIANGLE_STRIP'
95
- | 'TRIANGLE_FAN'
96
- | 'TRIANGLES'
97
-
98
- export type GLDrawType = 'UNSIGNED_BYTE' | 'UNSIGNED_SHORT' | 'UNSIGNED_INT'
1
+ import type { Queue } from 'refr/types'
2
+ import type { Nested, EventState } from 'reev/types'
3
+
4
+ export type Uniform = number | number[]
5
+
6
+ export type Attribute = number[]
7
+
8
+ export type Attributes = Record<string, Attribute>
9
+
10
+ export type Uniforms = Record<string, Uniform>
11
+
12
+ export type GL = EventState<{
13
+ /**
14
+ * initial value
15
+ */
16
+ id: string
17
+ width: number
18
+ height: number
19
+ size: [number, number]
20
+ mouse: [number, number]
21
+ count: number
22
+ vs: string
23
+ fs: string
24
+ vert: string
25
+ frag: string
26
+ vertex: string
27
+ fragment: string
28
+ varying: string
29
+ int: PrecisionMode
30
+ float: PrecisionMode
31
+ sampler2D: PrecisionMode
32
+ samplerCube: PrecisionMode
33
+ lastActiveUnit: number
34
+
35
+ /**
36
+ * core state
37
+ */
38
+ gl: any
39
+ pg: any
40
+ el: any
41
+ frame: Queue
42
+ target: any
43
+ stride: Nested<number>
44
+ // @TODO Nested<(key: string, value: number: number[], ibo: number[]) => number>
45
+ location: Nested<any>
46
+ activeUnit: Nested<number>
47
+ default: any
48
+
49
+ /**
50
+ * events
51
+ */
52
+ ref?: any
53
+ init(varying?: string[]): void
54
+ mount(): void
55
+ clean(): void
56
+ render(): void
57
+ mousemove(e: Event): void
58
+ resize(e?: Event, width?: number, height?: number): void
59
+ load(e?: Event, image?: HTMLImageElement): void
60
+
61
+ /**
62
+ * setter
63
+ */
64
+ _uniform(key: string, value: Uniform): GL
65
+ uniform(key: string, value: Uniform): GL
66
+ uniform(target: { [key: string]: Uniform }): GL
67
+ _texture(key: string, value: string): GL
68
+ texture(key: string, value: string): GL
69
+ texture(target: { [key: string]: string }): GL
70
+ _attribute(key: string, value: Attribute, iboValue?: Attribute): GL
71
+ attribute(key: string, value: Attribute, iboValue?: Attribute): GL
72
+ attribute(target: { [key: string]: Attribute }): GL
73
+ // config(key?: keyof GL, value?: GL[keyof GL]): GL
74
+ // config(target?: Partial<GL>): GL
75
+
76
+ /**
77
+ * short hands
78
+ */
79
+ clear(key?: GLClearMode): void
80
+ viewport(size?: [number, number]): void
81
+ drawArrays(key?: GLDrawMode): void
82
+ drawElements(key?: GLDrawMode): void
83
+ }>
84
+
85
+ export type PrecisionMode = 'highp' | 'mediump' | 'lowp'
86
+
87
+ export type GLClearMode =
88
+ | 'COLOR_BUFFER_BIT'
89
+ | 'DEPTH_BUFFER_BIT'
90
+ | 'STENCIL_BUFFER_BIT'
91
+
92
+ export type GLDrawMode =
93
+ | 'POINTS'
94
+ | 'LINE_STRIP'
95
+ | 'LINE_LOOP'
96
+ | 'LINES'
97
+ | 'TRIANGLE_STRIP'
98
+ | 'TRIANGLE_FAN'
99
+ | 'TRIANGLES'
100
+
101
+ export type GLDrawType = 'UNSIGNED_BYTE' | 'UNSIGNED_SHORT' | 'UNSIGNED_INT'