Skip to content

Commit

Permalink
refactor: cleaning up code
Browse files Browse the repository at this point in the history
  • Loading branch information
pecoram committed Nov 5, 2024
1 parent b23fc3a commit 19800a8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
15 changes: 7 additions & 8 deletions src/core/renderers/canvas/internal/C2DShaderUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {
} from '../shaders/UnsupportedShader.js';
import { formatRgba, parseColorRgba } from './ColorUtils.js';

type Direction = 'Top' | 'Right' | 'Bottom' | 'Left';

/**
* Extract `RoundedRectangle` shader radius to apply as a clipping
*/
Expand Down Expand Up @@ -56,7 +58,7 @@ export function getRadius(quad: QuadOptions): RadiusEffectProps['radius'] {
* Extract `RoundedRectangle` shader radius to apply as a clipping */
export function getBorder(
quad: QuadOptions,
direction: '' | 'Top' | 'Right' | 'Bottom' | 'Left' = '',
direction: '' | Direction = '',
): BorderEffectProps | undefined {
if (quad.shader instanceof UnsupportedShader) {
const shType = quad.shader.shType;
Expand All @@ -65,15 +67,12 @@ export function getBorder(
| EffectDescUnion[]
| undefined;

if (effects) {
if (effects && effects.length) {
const effect = effects.find((effect: EffectDescUnion) => {
return effect.type === `border${direction}` && effect?.props;
return effect.type === `border${direction}` && effect.props;
});

return (
(effect && effect.type === `border${direction}` && effect.props) ||
undefined
);
return effect && effect.props;
}
}
}
Expand All @@ -89,7 +88,7 @@ export function strokeLine(
height: number,
lineWidth = 0,
color: number | undefined,
direction: 'Top' | 'Right' | 'Bottom' | 'Left',
direction: Direction,
) {
if (!lineWidth) {
return;
Expand Down
5 changes: 4 additions & 1 deletion src/core/renderers/webgl/WebGlCoreCtxTexture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ export class WebGlCoreCtxTexture extends CoreContextTexture {
this._nativeCtxTexture = this.createNativeCtxTexture();
if (this._nativeCtxTexture === null) {
this._state = 'failed';
this.textureSource.setState('failed', new Error('Could not create WebGL Texture'));
this.textureSource.setState(
'failed',
new Error('Could not create WebGL Texture'),
);
console.error('Could not create WebGL Texture');
return;
}
Expand Down

0 comments on commit 19800a8

Please sign in to comment.