@lightningjs/renderer 0.3.6 → 0.4.1
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/exports/core-api.d.ts +1 -0
- package/dist/exports/core-api.js +1 -0
- package/dist/exports/core-api.js.map +1 -1
- package/dist/exports/main-api.d.ts +1 -0
- package/dist/src/core/CoreShaderManager.d.ts +28 -1
- package/dist/src/core/CoreShaderManager.js +51 -1
- package/dist/src/core/CoreShaderManager.js.map +1 -1
- package/dist/src/core/animations/CoreAnimation.d.ts +3 -3
- package/dist/src/core/animations/CoreAnimation.js +5 -4
- package/dist/src/core/animations/CoreAnimation.js.map +1 -1
- package/dist/src/core/renderers/webgl/shaders/DynamicShader.d.ts +5 -28
- package/dist/src/core/renderers/webgl/shaders/DynamicShader.js +9 -9
- package/dist/src/core/renderers/webgl/shaders/DynamicShader.js.map +1 -1
- package/dist/src/core/renderers/webgl/shaders/effects/FadeOutEffect.d.ts +24 -0
- package/dist/src/core/renderers/webgl/shaders/effects/FadeOutEffect.js.map +1 -1
- package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.d.ts +1 -1
- package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.js +2 -9
- package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.js.map +1 -1
- package/dist/src/core/renderers/webgl/shaders/effects/RadiusEffect.d.ts +15 -0
- package/dist/src/core/renderers/webgl/shaders/effects/RadiusEffect.js.map +1 -1
- package/dist/src/core/text-rendering/renderers/CanvasTextRenderer.js +3 -2
- package/dist/src/core/text-rendering/renderers/CanvasTextRenderer.js.map +1 -1
- package/dist/src/main-api/INode.d.ts +2 -2
- package/dist/src/main-api/RendererMain.d.ts +1 -1
- package/dist/src/main-api/RendererMain.js.map +1 -1
- package/dist/src/render-drivers/main/MainOnlyNode.d.ts +2 -2
- package/dist/src/render-drivers/main/MainOnlyNode.js.map +1 -1
- package/dist/src/render-drivers/threadx/ThreadXMainNode.d.ts +2 -2
- package/dist/src/render-drivers/threadx/ThreadXMainNode.js.map +1 -1
- package/dist/src/render-drivers/threadx/worker/ThreadXRendererNode.js.map +1 -1
- package/dist/tsconfig.dist.tsbuildinfo +1 -1
- package/exports/core-api.ts +1 -0
- package/exports/main-api.ts +1 -0
- package/package.json +2 -2
- package/src/core/CoreShaderManager.ts +90 -2
- package/src/core/animations/CoreAnimation.ts +7 -6
- package/src/core/renderers/webgl/shaders/DynamicShader.ts +22 -22
- package/src/core/renderers/webgl/shaders/effects/FadeOutEffect.ts +24 -0
- package/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.ts +3 -10
- package/src/core/renderers/webgl/shaders/effects/RadiusEffect.ts +15 -0
- package/src/core/text-rendering/renderers/CanvasTextRenderer.ts +4 -2
- package/src/main-api/INode.ts +2 -2
- package/src/main-api/RendererMain.ts +1 -1
- package/src/render-drivers/main/MainOnlyNode.ts +2 -2
- package/src/render-drivers/threadx/ThreadXMainNode.ts +2 -2
- package/src/render-drivers/threadx/worker/ThreadXRendererNode.ts +2 -2
|
@@ -22,10 +22,26 @@ import type { CoreShader } from './renderers/CoreShader.js';
|
|
|
22
22
|
|
|
23
23
|
import { DefaultShader } from './renderers/webgl/shaders/DefaultShader.js';
|
|
24
24
|
import { DefaultShaderBatched } from './renderers/webgl/shaders/DefaultShaderBatched.js';
|
|
25
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
DynamicShader,
|
|
27
|
+
type DynamicShaderProps,
|
|
28
|
+
} from './renderers/webgl/shaders/DynamicShader.js';
|
|
26
29
|
import { RoundedRectangle } from './renderers/webgl/shaders/RoundedRectangle.js';
|
|
27
30
|
import { SdfShader } from './renderers/webgl/shaders/SdfShader.js';
|
|
28
31
|
|
|
32
|
+
import { RadiusEffect } from './renderers/webgl/shaders/effects/RadiusEffect.js';
|
|
33
|
+
import { BorderEffect } from './renderers/webgl/shaders/effects/BorderEffect.js';
|
|
34
|
+
import { LinearGradientEffect } from './renderers/webgl/shaders/effects/LinearGradientEffect.js';
|
|
35
|
+
import { GrayscaleEffect } from './renderers/webgl/shaders/effects/GrayscaleEffect.js';
|
|
36
|
+
import { BorderRightEffect } from './renderers/webgl/shaders/effects/BorderRightEffect.js';
|
|
37
|
+
import { BorderTopEffect } from './renderers/webgl/shaders/effects/BorderTopEffect.js';
|
|
38
|
+
import { BorderBottomEffect } from './renderers/webgl/shaders/effects/BorderBottomEffect.js';
|
|
39
|
+
import { BorderLeftEffect } from './renderers/webgl/shaders/effects/BorderLeftEffect.js';
|
|
40
|
+
import { GlitchEffect } from './renderers/webgl/shaders/effects/GlitchEffect.js';
|
|
41
|
+
import { FadeOutEffect } from './renderers/webgl/shaders/effects/FadeOutEffect.js';
|
|
42
|
+
import { RadialGradientEffect } from './renderers/webgl/shaders/effects/RadialGradientEffect.js';
|
|
43
|
+
import type { WebGlCoreRenderer } from './renderers/webgl/WebGlCoreRenderer.js';
|
|
44
|
+
|
|
29
45
|
export interface ShaderMap {
|
|
30
46
|
DefaultShader: typeof DefaultShader;
|
|
31
47
|
DefaultShaderBatched: typeof DefaultShaderBatched;
|
|
@@ -39,12 +55,26 @@ export type ShaderNode<Type extends keyof ShaderMap> = {
|
|
|
39
55
|
props: Record<string, unknown>;
|
|
40
56
|
};
|
|
41
57
|
|
|
58
|
+
export interface EffectMap {
|
|
59
|
+
radius: typeof RadiusEffect;
|
|
60
|
+
border: typeof BorderEffect;
|
|
61
|
+
borderBottom: typeof BorderBottomEffect;
|
|
62
|
+
borderLeft: typeof BorderLeftEffect;
|
|
63
|
+
borderRight: typeof BorderRightEffect;
|
|
64
|
+
borderTop: typeof BorderTopEffect;
|
|
65
|
+
fadeOut: typeof FadeOutEffect;
|
|
66
|
+
linearGradient: typeof LinearGradientEffect;
|
|
67
|
+
radialGradient: typeof RadialGradientEffect;
|
|
68
|
+
grayscale: typeof GrayscaleEffect;
|
|
69
|
+
glitch: typeof GlitchEffect;
|
|
70
|
+
}
|
|
71
|
+
|
|
42
72
|
export class CoreShaderManager {
|
|
43
73
|
protected shCache: Map<string, InstanceType<ShaderMap[keyof ShaderMap]>> =
|
|
44
74
|
new Map();
|
|
45
75
|
protected shConstructors: Partial<ShaderMap> = {};
|
|
46
76
|
protected attachedShader: CoreShader | null = null;
|
|
47
|
-
|
|
77
|
+
protected effectConstructors: Partial<EffectMap> = {};
|
|
48
78
|
renderer!: CoreRenderer;
|
|
49
79
|
|
|
50
80
|
constructor() {
|
|
@@ -53,6 +83,18 @@ export class CoreShaderManager {
|
|
|
53
83
|
this.registerShaderType('RoundedRectangle', RoundedRectangle);
|
|
54
84
|
this.registerShaderType('DynamicShader', DynamicShader);
|
|
55
85
|
this.registerShaderType('SdfShader', SdfShader);
|
|
86
|
+
|
|
87
|
+
this.registerEffectType('border', BorderEffect);
|
|
88
|
+
this.registerEffectType('borderBottom', BorderBottomEffect);
|
|
89
|
+
this.registerEffectType('borderLeft', BorderLeftEffect);
|
|
90
|
+
this.registerEffectType('borderRight', BorderRightEffect);
|
|
91
|
+
this.registerEffectType('borderTop', BorderTopEffect);
|
|
92
|
+
this.registerEffectType('fadeOut', FadeOutEffect);
|
|
93
|
+
this.registerEffectType('linearGradient', LinearGradientEffect);
|
|
94
|
+
this.registerEffectType('radialGradient', RadialGradientEffect);
|
|
95
|
+
this.registerEffectType('grayscale', GrayscaleEffect);
|
|
96
|
+
this.registerEffectType('glitch', GlitchEffect);
|
|
97
|
+
this.registerEffectType('radius', RadiusEffect);
|
|
56
98
|
}
|
|
57
99
|
|
|
58
100
|
registerShaderType<Type extends keyof ShaderMap>(
|
|
@@ -62,6 +104,13 @@ export class CoreShaderManager {
|
|
|
62
104
|
this.shConstructors[shType] = shClass;
|
|
63
105
|
}
|
|
64
106
|
|
|
107
|
+
registerEffectType<Type extends keyof EffectMap>(
|
|
108
|
+
effectType: Type,
|
|
109
|
+
effectClass: EffectMap[Type],
|
|
110
|
+
): void {
|
|
111
|
+
this.effectConstructors[effectType] = effectClass;
|
|
112
|
+
}
|
|
113
|
+
|
|
65
114
|
loadShader<Type extends keyof ShaderMap>(
|
|
66
115
|
shType: Type,
|
|
67
116
|
props?: ExtractProps<ShaderMap[Type]>,
|
|
@@ -73,6 +122,11 @@ export class CoreShaderManager {
|
|
|
73
122
|
if (!ShaderClass) {
|
|
74
123
|
throw new Error(`Shader type "${shType as string}" is not registered`);
|
|
75
124
|
}
|
|
125
|
+
|
|
126
|
+
if (shType === 'DynamicShader') {
|
|
127
|
+
return this.loadDynamicShader(props!);
|
|
128
|
+
}
|
|
129
|
+
|
|
76
130
|
const resolvedProps = ShaderClass.resolveDefaults(
|
|
77
131
|
props as Record<string, unknown>,
|
|
78
132
|
);
|
|
@@ -98,6 +152,40 @@ export class CoreShaderManager {
|
|
|
98
152
|
};
|
|
99
153
|
}
|
|
100
154
|
|
|
155
|
+
loadDynamicShader<Type extends keyof ShaderMap>(
|
|
156
|
+
props: DynamicShaderProps,
|
|
157
|
+
): ShaderNode<Type> {
|
|
158
|
+
if (!this.renderer) {
|
|
159
|
+
throw new Error(`Renderer is not been defined`);
|
|
160
|
+
}
|
|
161
|
+
const resolvedProps = DynamicShader.resolveDefaults(
|
|
162
|
+
props as Record<string, unknown>,
|
|
163
|
+
this.effectConstructors,
|
|
164
|
+
);
|
|
165
|
+
const cacheKey = DynamicShader.makeCacheKey(
|
|
166
|
+
resolvedProps,
|
|
167
|
+
this.effectConstructors,
|
|
168
|
+
);
|
|
169
|
+
if (cacheKey && this.shCache.has(cacheKey)) {
|
|
170
|
+
return {
|
|
171
|
+
shader: this.shCache.get(cacheKey) as InstanceType<ShaderMap[Type]>,
|
|
172
|
+
props: resolvedProps,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
const shader = new DynamicShader(
|
|
176
|
+
this.renderer as WebGlCoreRenderer,
|
|
177
|
+
props,
|
|
178
|
+
this.effectConstructors,
|
|
179
|
+
);
|
|
180
|
+
if (cacheKey) {
|
|
181
|
+
this.shCache.set(cacheKey, shader);
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
shader: shader as InstanceType<ShaderMap[Type]>,
|
|
185
|
+
props: resolvedProps,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
101
189
|
useShader(shader: CoreShader): void {
|
|
102
190
|
if (this.attachedShader === shader) {
|
|
103
191
|
return;
|
|
@@ -23,7 +23,7 @@ import { getTimingFunction } from '../utils.js';
|
|
|
23
23
|
import { mergeColorProgress } from '../../utils.js';
|
|
24
24
|
import { EventEmitter } from '../../common/EventEmitter.js';
|
|
25
25
|
|
|
26
|
-
export interface
|
|
26
|
+
export interface AnimationSettings {
|
|
27
27
|
duration: number;
|
|
28
28
|
delay: number;
|
|
29
29
|
easing: string;
|
|
@@ -42,7 +42,7 @@ export class CoreAnimation extends EventEmitter {
|
|
|
42
42
|
constructor(
|
|
43
43
|
private node: CoreNode,
|
|
44
44
|
private props: Partial<INodeAnimatableProps>,
|
|
45
|
-
public settings: Partial<
|
|
45
|
+
public settings: Partial<AnimationSettings>,
|
|
46
46
|
) {
|
|
47
47
|
super();
|
|
48
48
|
this.propStartValues = {};
|
|
@@ -78,7 +78,7 @@ export class CoreAnimation extends EventEmitter {
|
|
|
78
78
|
(Object.keys(this.props) as Array<keyof INodeAnimatableProps>).forEach(
|
|
79
79
|
(propName) => {
|
|
80
80
|
// set the start value to the current value
|
|
81
|
-
const startValue = this.
|
|
81
|
+
const startValue = this.props[propName];
|
|
82
82
|
const endValue = this.propStartValues[propName] as number;
|
|
83
83
|
|
|
84
84
|
// swap the start and end values
|
|
@@ -87,8 +87,10 @@ export class CoreAnimation extends EventEmitter {
|
|
|
87
87
|
},
|
|
88
88
|
);
|
|
89
89
|
|
|
90
|
-
// restore stop method
|
|
91
|
-
this.settings.
|
|
90
|
+
// restore stop method if we are not looping
|
|
91
|
+
if (!this.settings.loop) {
|
|
92
|
+
this.settings.stopMethod = false;
|
|
93
|
+
}
|
|
92
94
|
}
|
|
93
95
|
|
|
94
96
|
applyEasing(p: number, s: number, e: number): number {
|
|
@@ -96,7 +98,6 @@ export class CoreAnimation extends EventEmitter {
|
|
|
96
98
|
}
|
|
97
99
|
|
|
98
100
|
update(dt: number) {
|
|
99
|
-
// finish if no duration is provided
|
|
100
101
|
const { duration, loop, easing } = this.settings;
|
|
101
102
|
if (!duration) {
|
|
102
103
|
this.emit('finished', {});
|
|
@@ -37,6 +37,7 @@ import { BorderLeftEffect } from './effects/BorderLeftEffect.js';
|
|
|
37
37
|
import { GlitchEffect } from './effects/GlitchEffect.js';
|
|
38
38
|
import { FadeOutEffect } from './effects/FadeOutEffect.js';
|
|
39
39
|
import { RadialGradientEffect } from './effects/RadialGradientEffect.js';
|
|
40
|
+
import type { EffectMap } from '../../../CoreShaderManager.js';
|
|
40
41
|
|
|
41
42
|
/**
|
|
42
43
|
* Allows the `keyof EffectMap` to be mapped over and form an discriminated
|
|
@@ -82,20 +83,6 @@ export interface DynamicShaderProps
|
|
|
82
83
|
effects?: EffectDesc[];
|
|
83
84
|
}
|
|
84
85
|
|
|
85
|
-
export interface EffectMap {
|
|
86
|
-
radius: typeof RadiusEffect;
|
|
87
|
-
border: typeof BorderEffect;
|
|
88
|
-
borderBottom: typeof BorderBottomEffect;
|
|
89
|
-
borderLeft: typeof BorderLeftEffect;
|
|
90
|
-
borderRight: typeof BorderRightEffect;
|
|
91
|
-
borderTop: typeof BorderTopEffect;
|
|
92
|
-
fadeOut: typeof FadeOutEffect;
|
|
93
|
-
linearGradient: typeof LinearGradientEffect;
|
|
94
|
-
radialGradient: typeof RadialGradientEffect;
|
|
95
|
-
grayscale: typeof GrayscaleEffect;
|
|
96
|
-
glitch: typeof GlitchEffect;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
86
|
const Effects = {
|
|
100
87
|
radius: RadiusEffect,
|
|
101
88
|
border: BorderEffect,
|
|
@@ -120,8 +107,12 @@ export interface SpecificEffectDesc<
|
|
|
120
107
|
export class DynamicShader extends WebGlCoreShader {
|
|
121
108
|
effects: Array<InstanceType<EffectMap[keyof EffectMap]>> = [];
|
|
122
109
|
|
|
123
|
-
constructor(
|
|
124
|
-
|
|
110
|
+
constructor(
|
|
111
|
+
renderer: WebGlCoreRenderer,
|
|
112
|
+
props: DynamicShaderProps,
|
|
113
|
+
effectContructors: Partial<EffectMap>,
|
|
114
|
+
) {
|
|
115
|
+
const shader = DynamicShader.createShader(props, effectContructors);
|
|
125
116
|
super({
|
|
126
117
|
renderer,
|
|
127
118
|
attributes: ['a_position', 'a_textureCoordinate', 'a_color'],
|
|
@@ -170,7 +161,10 @@ export class DynamicShader extends WebGlCoreShader {
|
|
|
170
161
|
});
|
|
171
162
|
}
|
|
172
163
|
|
|
173
|
-
static createShader(
|
|
164
|
+
static createShader(
|
|
165
|
+
props: DynamicShaderProps,
|
|
166
|
+
effectContructors: Partial<EffectMap>,
|
|
167
|
+
) {
|
|
174
168
|
//counts duplicate effects
|
|
175
169
|
const effectNameCount: Record<string, number> = {};
|
|
176
170
|
const methods: Record<string, string> = {};
|
|
@@ -181,7 +175,7 @@ export class DynamicShader extends WebGlCoreShader {
|
|
|
181
175
|
const uFx: Record<string, unknown>[] = [];
|
|
182
176
|
|
|
183
177
|
const effects = props.effects!.map((effect) => {
|
|
184
|
-
const baseClass =
|
|
178
|
+
const baseClass = effectContructors[effect.type]!;
|
|
185
179
|
const key = baseClass.getEffectKey(effect.props || {});
|
|
186
180
|
|
|
187
181
|
effectNameCount[key] = effectNameCount[key] ? ++effectNameCount[key] : 1;
|
|
@@ -208,7 +202,7 @@ export class DynamicShader extends WebGlCoreShader {
|
|
|
208
202
|
let effectMethods = '';
|
|
209
203
|
|
|
210
204
|
uFx?.forEach((fx) => {
|
|
211
|
-
const fxClass =
|
|
205
|
+
const fxClass = effectContructors[fx.type as keyof EffectMap]!;
|
|
212
206
|
const fxProps = fxClass.resolveDefaults(
|
|
213
207
|
(fx.props ?? {}) as Record<string, unknown>,
|
|
214
208
|
);
|
|
@@ -360,11 +354,14 @@ export class DynamicShader extends WebGlCoreShader {
|
|
|
360
354
|
|
|
361
355
|
static override resolveDefaults(
|
|
362
356
|
props: DynamicShaderProps,
|
|
357
|
+
effectContructors?: Partial<EffectMap>,
|
|
363
358
|
): Required<DynamicShaderProps> {
|
|
364
359
|
return {
|
|
365
360
|
effects: (props.effects ?? []).map((effect) => ({
|
|
366
361
|
type: effect.type,
|
|
367
|
-
props:
|
|
362
|
+
props: effectContructors![effect.type]!.resolveDefaults(
|
|
363
|
+
effect.props || {},
|
|
364
|
+
),
|
|
368
365
|
})) as MapEffectDescs<keyof EffectMap>[],
|
|
369
366
|
$dimensions: {
|
|
370
367
|
width: 0,
|
|
@@ -374,10 +371,13 @@ export class DynamicShader extends WebGlCoreShader {
|
|
|
374
371
|
};
|
|
375
372
|
}
|
|
376
373
|
|
|
377
|
-
static override makeCacheKey(
|
|
374
|
+
static override makeCacheKey(
|
|
375
|
+
props: DynamicShaderProps,
|
|
376
|
+
effectContructors?: Partial<EffectMap>,
|
|
377
|
+
): string {
|
|
378
378
|
let fx = '';
|
|
379
379
|
props.effects?.forEach((effect) => {
|
|
380
|
-
const baseClass =
|
|
380
|
+
const baseClass = effectContructors![effect.type]!;
|
|
381
381
|
const key = baseClass.getEffectKey(effect.props || {});
|
|
382
382
|
fx += `,${key}`;
|
|
383
383
|
});
|
|
@@ -22,7 +22,31 @@ import {
|
|
|
22
22
|
type ShaderEffectUniforms,
|
|
23
23
|
} from './ShaderEffect.js';
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Properties of the {@link FadeOutEffect}
|
|
27
|
+
*
|
|
28
|
+
*/
|
|
25
29
|
export interface FadeOutEffectProps extends DefaultEffectProps {
|
|
30
|
+
/**
|
|
31
|
+
* Fade around the edges of the node
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* You can input an array with a length of up to four or a number.
|
|
35
|
+
*
|
|
36
|
+
* array length 4:
|
|
37
|
+
* [top, right, bottom, left]
|
|
38
|
+
*
|
|
39
|
+
* array length 2:
|
|
40
|
+
* [20, 40] -> [20(top), 40(right), 20(bottom), 40(left)]
|
|
41
|
+
*
|
|
42
|
+
* array length 3:
|
|
43
|
+
* [20, 40, 60] -> [20(top), 40(right), 60(bottom), 20(left)]
|
|
44
|
+
*
|
|
45
|
+
* number:
|
|
46
|
+
* 30 -> [30, 30, 30, 30]
|
|
47
|
+
*
|
|
48
|
+
* @default 10
|
|
49
|
+
*/
|
|
26
50
|
fade?: number | number[];
|
|
27
51
|
}
|
|
28
52
|
|
|
@@ -34,7 +34,7 @@ export interface LinearGradientEffectProps extends DefaultEffectProps {
|
|
|
34
34
|
*/
|
|
35
35
|
colors?: number[];
|
|
36
36
|
/**
|
|
37
|
-
* Angle of the LinearGradientEffect
|
|
37
|
+
* Angle of the LinearGradientEffect, Angle in Radians
|
|
38
38
|
*
|
|
39
39
|
* @default 0
|
|
40
40
|
*/
|
|
@@ -137,11 +137,6 @@ export class LinearGradientEffect extends ShaderEffect {
|
|
|
137
137
|
return mix(higher, lower, 1.0);
|
|
138
138
|
}
|
|
139
139
|
`,
|
|
140
|
-
degToRad: `
|
|
141
|
-
float function(float d) {
|
|
142
|
-
return d * (PI / 180.0);
|
|
143
|
-
}
|
|
144
|
-
`,
|
|
145
140
|
calcPoint: `
|
|
146
141
|
vec2 function(float d, float angle) {
|
|
147
142
|
return d * vec2(cos(angle), sin(angle)) + (u_dimensions * 0.5);
|
|
@@ -162,12 +157,10 @@ export class LinearGradientEffect extends ShaderEffect {
|
|
|
162
157
|
static override onColorize = (props: LinearGradientEffectProps) => {
|
|
163
158
|
const colors = props.colors!.length || 1;
|
|
164
159
|
return `
|
|
165
|
-
float
|
|
166
|
-
float a = $degToRad(d);
|
|
160
|
+
float a = angle - (PI / 180.0 * 90.0);
|
|
167
161
|
float lineDist = abs(u_dimensions.x * cos(a)) + abs(u_dimensions.y * sin(a));
|
|
168
|
-
|
|
169
162
|
vec2 f = $calcPoint(lineDist * 0.5, a);
|
|
170
|
-
vec2 t = $calcPoint(lineDist * 0.5,
|
|
163
|
+
vec2 t = $calcPoint(lineDist * 0.5, a + PI);
|
|
171
164
|
vec2 gradVec = t - f;
|
|
172
165
|
float dist = dot(v_textureCoordinate.xy * u_dimensions - f, gradVec) / dot(gradVec, gradVec);
|
|
173
166
|
|
|
@@ -29,6 +29,21 @@ export interface RadiusEffectProps extends DefaultEffectProps {
|
|
|
29
29
|
/**
|
|
30
30
|
* Corner radius, in pixels, to cut out of the corners
|
|
31
31
|
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* You can input an array with a length of up to four or a number.
|
|
34
|
+
*
|
|
35
|
+
* array length 4:
|
|
36
|
+
* [topLeft, topRight, bottomRight, bottomLeft]
|
|
37
|
+
*
|
|
38
|
+
* array length 2:
|
|
39
|
+
* [20, 40] -> [20(topLeft), 40(topRight), 20(bottomRight), 40(bottomLeft)]
|
|
40
|
+
*
|
|
41
|
+
* array length 3:
|
|
42
|
+
* [20, 40, 60] -> [20(topLeft), 40(topRight), 60(bottomRight), 20(bottomLeft)]
|
|
43
|
+
*
|
|
44
|
+
* number:
|
|
45
|
+
* 30 -> [30, 30, 30, 30]
|
|
46
|
+
*
|
|
32
47
|
* @default 10
|
|
33
48
|
*/
|
|
34
49
|
radius?: number | number[];
|
|
@@ -42,11 +42,13 @@ import {
|
|
|
42
42
|
type TrProps,
|
|
43
43
|
} from './TextRenderer.js';
|
|
44
44
|
|
|
45
|
+
const resolvedGlobal = typeof self === 'undefined' ? globalThis : self;
|
|
46
|
+
|
|
45
47
|
/**
|
|
46
48
|
* Global font set regardless of if run in the main thread or a web worker
|
|
47
49
|
*/
|
|
48
|
-
const globalFontSet = ((
|
|
49
|
-
(
|
|
50
|
+
const globalFontSet = ((resolvedGlobal.document as any)?.fonts ||
|
|
51
|
+
(resolvedGlobal as any).fonts) as FontFaceSet;
|
|
50
52
|
|
|
51
53
|
declare module './TextRenderer.js' {
|
|
52
54
|
interface TextRendererMap {
|
package/src/main-api/INode.ts
CHANGED
|
@@ -24,7 +24,7 @@ import type {
|
|
|
24
24
|
TextRendererMap,
|
|
25
25
|
TrProps,
|
|
26
26
|
} from '../core/text-rendering/renderers/TextRenderer.js';
|
|
27
|
-
import type {
|
|
27
|
+
import type { AnimationSettings } from '../core/animations/CoreAnimation.js';
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Writable properties of a Node.
|
|
@@ -399,7 +399,7 @@ export interface INode extends INodeWritableProps, IEventEmitter<INodeEvents> {
|
|
|
399
399
|
readonly children: INode[];
|
|
400
400
|
animate(
|
|
401
401
|
props: Partial<INodeAnimatableProps>,
|
|
402
|
-
settings: Partial<
|
|
402
|
+
settings: Partial<AnimationSettings>,
|
|
403
403
|
): IAnimationController;
|
|
404
404
|
destroy(): void;
|
|
405
405
|
flush(): void;
|
|
@@ -229,7 +229,7 @@ export interface RendererMainSettings {
|
|
|
229
229
|
export class RendererMain {
|
|
230
230
|
readonly root: INode | null = null;
|
|
231
231
|
readonly driver: IRenderDriver;
|
|
232
|
-
|
|
232
|
+
readonly canvas: HTMLCanvasElement;
|
|
233
233
|
readonly settings: Readonly<Required<RendererMainSettings>>;
|
|
234
234
|
private nodes: Map<number, INode> = new Map();
|
|
235
235
|
private nextTextureId = 1;
|
|
@@ -33,7 +33,7 @@ import type {
|
|
|
33
33
|
ShaderRef,
|
|
34
34
|
TextureRef,
|
|
35
35
|
} from '../../main-api/RendererMain.js';
|
|
36
|
-
import type {
|
|
36
|
+
import type { AnimationSettings } from '../../core/animations/CoreAnimation.js';
|
|
37
37
|
import { EventEmitter } from '../../common/EventEmitter.js';
|
|
38
38
|
import type {
|
|
39
39
|
TextureFailedEventHandler,
|
|
@@ -422,7 +422,7 @@ export class MainOnlyNode extends EventEmitter implements INode {
|
|
|
422
422
|
|
|
423
423
|
animate(
|
|
424
424
|
props: Partial<INodeAnimatableProps>,
|
|
425
|
-
settings: Partial<
|
|
425
|
+
settings: Partial<AnimationSettings>,
|
|
426
426
|
): IAnimationController {
|
|
427
427
|
const animation = new CoreAnimation(this.coreNode, props, settings);
|
|
428
428
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
|
@@ -28,7 +28,7 @@ import { assertTruthy } from '../../utils.js';
|
|
|
28
28
|
import type { NodeStruct } from './NodeStruct.js';
|
|
29
29
|
import { SharedNode } from './SharedNode.js';
|
|
30
30
|
import { ThreadXMainAnimationController } from './ThreadXMainAnimationController.js';
|
|
31
|
-
import type {
|
|
31
|
+
import type { AnimationSettings } from '../../core/animations/CoreAnimation.js';
|
|
32
32
|
|
|
33
33
|
export class ThreadXMainNode extends SharedNode implements INode {
|
|
34
34
|
private nextAnimationId = 1;
|
|
@@ -97,7 +97,7 @@ export class ThreadXMainNode extends SharedNode implements INode {
|
|
|
97
97
|
|
|
98
98
|
animate(
|
|
99
99
|
props: Partial<INodeAnimatableProps>,
|
|
100
|
-
settings: Partial<
|
|
100
|
+
settings: Partial<AnimationSettings>,
|
|
101
101
|
): IAnimationController {
|
|
102
102
|
const id = this.nextAnimationId++;
|
|
103
103
|
this.emit('createAnimation', { id, props, settings });
|
|
@@ -29,7 +29,7 @@ import { CoreAnimationController } from '../../../core/animations/CoreAnimationC
|
|
|
29
29
|
import type { Texture } from '../../../core/textures/Texture.js';
|
|
30
30
|
import { CoreNode } from '../../../core/CoreNode.js';
|
|
31
31
|
import type { ShaderRef, TextureRef } from '../../../main-api/RendererMain.js';
|
|
32
|
-
import type {
|
|
32
|
+
import type { AnimationSettings } from '../../../core/animations/CoreAnimation.js';
|
|
33
33
|
import type { Dimensions } from '../../../common/CommonTypes.js';
|
|
34
34
|
|
|
35
35
|
export class ThreadXRendererNode extends SharedNode {
|
|
@@ -78,7 +78,7 @@ export class ThreadXRendererNode extends SharedNode {
|
|
|
78
78
|
const animation = new CoreAnimation(
|
|
79
79
|
this.coreNode,
|
|
80
80
|
props as Partial<INodeAnimatableProps>,
|
|
81
|
-
settings as Partial<
|
|
81
|
+
settings as Partial<AnimationSettings>,
|
|
82
82
|
);
|
|
83
83
|
animation.on('finished', () => {
|
|
84
84
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|