Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/core/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ export const SHADERS_ENABLED =
typeof SOLIDTV_DISABLE_SHADERS === 'undefined' ||
SOLIDTV_DISABLE_SHADERS !== true;

/**
* True when the DOM renderer is both built in (`DOM_RENDERING`) and turned on
* at runtime (`Config.domRendererEnabled`). `Config.domRendererEnabled` is
* mutable up until the renderer starts, so this is a function rather than a
* constant.
*/
export const isDomRendererActive = () =>
DOM_RENDERING && Config.domRendererEnabled;

/**
RUNTIME LIGHTNING CONFIGURATION \
This configuration can be set at runtime, but it is recommended to set it
Expand Down
4 changes: 2 additions & 2 deletions src/core/dom-renderer/domRendererUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import * as lng from '@solidtv/renderer';
import { Config } from '../config.js';
import { DOMNode } from './domRenderer.js';
import { isFunc } from '../utils.js';
import { isFunction } from '../utils.js';

// #region Color & Gradient Utils

Expand Down Expand Up @@ -160,7 +160,7 @@ export function applyEasing(
easing: string | lng.TimingFunction,
progress: number,
): number {
if (isFunc(easing)) {
if (isFunction(easing)) {
return easing(progress);
}

Expand Down
20 changes: 12 additions & 8 deletions src/core/elementNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const calculateFlex = import.meta.env?.VITE_USE_NEW_FLEX
import {
log,
isArray,
isFunc,
keyExists,
isINode,
isElementNode,
Expand All @@ -34,7 +33,12 @@ import {
isFunction,
spliceItem,
} from './utils.js';
import { Config, DOM_RENDERING, isDev, SHADERS_ENABLED } from './config.js';
import {
Config,
isDev,
SHADERS_ENABLED,
isDomRendererActive,
} from './config.js';
import type {
RendererMain,
INode,
Expand Down Expand Up @@ -106,7 +110,7 @@ function runPostMutation() {
// Phase 1: delete-flush
if (elementDeleteQueue.length > 0) {
for (const el of elementDeleteQueue) {
if (Number(el._queueDelete) < 0) {
if ((el._queueDelete ?? 0) < 0) {
el.destroy();
}
el._queueDelete = undefined;
Expand Down Expand Up @@ -838,7 +842,7 @@ export class ElementNode {
if (this.rendered) {
if (!this.lng.shader) {
this.lng.shader = Config.convertToShader(this, target);
} else if (DOM_RENDERING && Config.domRendererEnabled) {
} else if (isDomRendererActive()) {
// eslint-disable-next-line no-self-assign -- lng.shader is a setter, force style update
this.lng.shader = this.lng.shader;
}
Expand Down Expand Up @@ -1104,7 +1108,7 @@ export class ElementNode {
if (this.rendered) {
// can be 0
if (this.forwardFocus !== undefined) {
if (isFunc(this.forwardFocus)) {
if (isFunction(this.forwardFocus)) {
if (this.forwardFocus.call(this, this) !== false) {
return;
}
Expand Down Expand Up @@ -1370,7 +1374,7 @@ export class ElementNode {
const flexChanged = this.display === 'flex' && calculateFlex(this);
layoutQueue.delete(this);
const onLayoutChanged =
isFunc(this.onLayout) && this.onLayout.call(this, this);
isFunction(this.onLayout) && this.onLayout.call(this, this);

if ((flexChanged || onLayoutChanged) && this.parent) {
addToLayoutQueue(this.parent);
Expand All @@ -1382,7 +1386,7 @@ export class ElementNode {
if (c.display === 'flex' && isElementNode(c)) {
// calculating directly to prevent infinite loops recalculating parents
calculateFlex(c);
isFunc(c.onLayout) && c.onLayout.call(c, c);
isFunction(c.onLayout) && c.onLayout.call(c, c);
addToLayoutQueue(this);
}
});
Expand Down Expand Up @@ -1795,7 +1799,7 @@ export function shaderAccessor<T extends Record<string, any> | number>(
if (this.rendered) {
if (!this.lng.shader) {
this.lng.shader = Config.convertToShader(this, target);
} else if (DOM_RENDERING && Config.domRendererEnabled) {
} else if (isDomRendererActive()) {
// eslint-disable-next-line no-self-assign -- lng.shader is a setter, force style update
this.lng.shader = this.lng.shader;
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/lightningInit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as lng from '@solidtv/renderer';
import { Config, DOM_RENDERING } from './config.js';
import { isDomRendererActive } from './config.js';
import { DOMRendererMain, loadFontToDom } from './dom-renderer/domRenderer.js';
import { DomRendererMainSettings } from './dom-renderer/domRendererTypes.js';
import { FontLoadOptions } from './intrinsicTypes.js';
Expand All @@ -14,7 +14,7 @@ export function startLightningRenderer(
options: lng.RendererMainSettings | DomRendererMainSettings,
rootId: string | HTMLElement = 'app',
) {
const enableDomRenderer = DOM_RENDERING && Config.domRendererEnabled;
const enableDomRenderer = isDomRendererActive();

renderer = enableDomRenderer
? new DOMRendererMain(options, rootId)
Expand All @@ -23,7 +23,7 @@ export function startLightningRenderer(
}

export async function loadFonts(fonts: FontLoadOptions[]) {
const enableDomRenderer = DOM_RENDERING && Config.domRendererEnabled;
const enableDomRenderer = isDomRendererActive();
await Promise.all(
fonts.map((font) => {
// WebGL — SDF
Expand Down
20 changes: 10 additions & 10 deletions src/core/shaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export {
};
export { WebGlShader };

import { Config, DOM_RENDERING, SHADERS_ENABLED } from './config.js';
import { SHADERS_ENABLED, isDomRendererActive } from './config.js';
import type { CoreShaderManager } from './intrinsicTypes.js';
import { IRendererShaderManager } from './dom-renderer/domRendererTypes.js';

Expand Down Expand Up @@ -122,17 +122,17 @@ function toValidVec4(value: unknown): Vec4 {
export function registerDefaultShaderRounded(
shManager: IRendererShaderManager,
) {
if (SHADERS_ENABLED && !(DOM_RENDERING && Config.domRendererEnabled))
if (SHADERS_ENABLED && !isDomRendererActive())
shManager.registerShaderType('rounded', defaultShaderRounded);
}
export function registerDefaultShaderShadow(shManager: CoreShaderManager) {
if (SHADERS_ENABLED && !(DOM_RENDERING && Config.domRendererEnabled))
if (SHADERS_ENABLED && !isDomRendererActive())
shManager.registerShaderType('shadow', defaultShaderShadow);
}
export function registerDefaultShaderRoundedWithBorder(
shManager: CoreShaderManager,
) {
if (SHADERS_ENABLED && !(DOM_RENDERING && Config.domRendererEnabled))
if (SHADERS_ENABLED && !isDomRendererActive())
shManager.registerShaderType(
'roundedWithBorder',
defaultShaderRoundedWithBorder,
Expand All @@ -141,7 +141,7 @@ export function registerDefaultShaderRoundedWithBorder(
export function registerDefaultShaderRoundedWithShadow(
shManager: CoreShaderManager,
) {
if (SHADERS_ENABLED && !(DOM_RENDERING && Config.domRendererEnabled))
if (SHADERS_ENABLED && !isDomRendererActive())
shManager.registerShaderType(
'roundedWithShadow',
defaultShaderRoundedWithShadow,
Expand All @@ -150,31 +150,31 @@ export function registerDefaultShaderRoundedWithShadow(
export function registerDefaultShaderRoundedWithBorderAndShadow(
shManager: CoreShaderManager,
) {
if (SHADERS_ENABLED && !(DOM_RENDERING && Config.domRendererEnabled))
if (SHADERS_ENABLED && !isDomRendererActive())
shManager.registerShaderType(
'roundedWithBorderWithShadow',
defaultShaderRoundedWithBorderAndShadow,
);
}
export function registerDefaultShaderHolePunch(shManager: CoreShaderManager) {
if (SHADERS_ENABLED && !(DOM_RENDERING && Config.domRendererEnabled))
if (SHADERS_ENABLED && !isDomRendererActive())
shManager.registerShaderType('holePunch', defaultShaderHolePunch);
}
export function registerDefaultShaderRadialGradient(
shManager: CoreShaderManager,
) {
if (SHADERS_ENABLED && !(DOM_RENDERING && Config.domRendererEnabled))
if (SHADERS_ENABLED && !isDomRendererActive())
shManager.registerShaderType('radialGradient', defaultShaderRadialGradient);
}
export function registerDefaultShaderLinearGradient(
shManager: CoreShaderManager,
) {
if (SHADERS_ENABLED && !(DOM_RENDERING && Config.domRendererEnabled))
if (SHADERS_ENABLED && !isDomRendererActive())
shManager.registerShaderType('linearGradient', defaultShaderLinearGradient);
}

export function registerDefaultShaders(shManager: CoreShaderManager) {
if (SHADERS_ENABLED && !(DOM_RENDERING && Config.domRendererEnabled)) {
if (SHADERS_ENABLED && !isDomRendererActive()) {
registerDefaultShaderRounded(shManager);
registerDefaultShaderShadow(shManager);
registerDefaultShaderRoundedWithBorder(shManager);
Expand Down
3 changes: 0 additions & 3 deletions src/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ export function log(
}
}

export const isFunc = (obj: unknown): obj is CallableFunction =>
obj instanceof Function;

// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
export const isFunction = (obj: unknown): obj is Function =>
typeof obj === 'function';
Expand Down
8 changes: 4 additions & 4 deletions src/primitives/useMouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ElementNode,
activeElement,
isElementNode,
isFunc,
isFunction,
rootNode,
} from '../index.js';
import { makeEventListener } from '@solid-primitives/event-listener';
Expand Down Expand Up @@ -128,7 +128,7 @@ function findElementByActiveElement(e: MouseEvent): ElementNode | null {
let parent = active?.parent;
while (parent) {
if (
isFunc(parent.onMouseClick) &&
isFunction(parent.onMouseClick) &&
testCollision(
px,
py,
Expand Down Expand Up @@ -167,10 +167,10 @@ function handleElementClick(
pressedElementRef.current = null;
}

if (isFunc(clickedElement.onMouseClick)) {
if (isFunction(clickedElement.onMouseClick)) {
clickedElement.onMouseClick(e, clickedElement);
return;
} else if (isFunc(clickedElement.onEnter)) {
} else if (isFunction(clickedElement.onEnter)) {
clickedElement.onEnter();
return;
}
Expand Down
Loading