Skip to content

Commit 64dcf02

Browse files
committed
format files back to 80 width as default
1 parent b50a247 commit 64dcf02

File tree

6 files changed

+192
-54
lines changed

6 files changed

+192
-54
lines changed

.prettierrc.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"trailingComma": "all",
33
"singleQuote": true,
4-
"semi": true,
5-
"printWidth": 120
4+
"semi": true
65
}

src/core/elementNode.ts

Lines changed: 112 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ import type {
4949
} from '@lightningjs/renderer';
5050
import { assertTruthy } from '@lightningjs/renderer/utils';
5151
import { NodeType } from './nodeTypes.js';
52-
import { ForwardFocusHandler, setActiveElement, FocusNode } from './focusManager.js';
52+
import {
53+
ForwardFocusHandler,
54+
setActiveElement,
55+
FocusNode,
56+
} from './focusManager.js';
5357
import simpleAnimation, { SimpleAnimationSettings } from './animation.js';
5458

5559
let layoutRunQueued = false;
@@ -73,7 +77,11 @@ function runLayout() {
7377
}
7478
}
7579

76-
const parseAndAssignShaderProps = (prefix: string, obj: Record<string, any>, props: Record<string, any> = {}) => {
80+
const parseAndAssignShaderProps = (
81+
prefix: string,
82+
obj: Record<string, any>,
83+
props: Record<string, any> = {},
84+
) => {
7785
if (!obj) return;
7886
props[prefix] = obj;
7987
Object.entries(obj).forEach(([key, value]) => {
@@ -172,7 +180,12 @@ declare global {
172180
}
173181

174182
export type RendererNode = AddColorString<
175-
Partial<NewOmit<INode, 'parent' | 'shader' | 'src' | 'children' | 'id' | 'removeChild'>>
183+
Partial<
184+
NewOmit<
185+
INode,
186+
'parent' | 'shader' | 'src' | 'children' | 'id' | 'removeChild'
187+
>
188+
>
176189
>;
177190
export interface ElementNode extends RendererNode, FocusNode {
178191
[key: string]: unknown;
@@ -257,7 +270,10 @@ export interface ElementNode extends RendererNode, FocusNode {
257270
/**
258271
* The underlying Lightning Renderer node object. This is where the properties are ultimately set for rendering.
259272
*/
260-
lng: Partial<ElementNode> | IRendererNode | (IRendererTextNode & { shader?: any });
273+
lng:
274+
| Partial<ElementNode>
275+
| IRendererNode
276+
| (IRendererTextNode & { shader?: any });
261277
/**
262278
* A reference to the `ElementNode` instance. Can be an object or a callback function.
263279
*/
@@ -413,7 +429,13 @@ export interface ElementNode extends RendererNode, FocusNode {
413429
*
414430
* @see @see https://lightning-tv.github.io/solid/#/flow/layout?id=flex
415431
*/
416-
justifyContent?: 'flexStart' | 'flexEnd' | 'center' | 'spaceBetween' | 'spaceAround' | 'spaceEvenly';
432+
justifyContent?:
433+
| 'flexStart'
434+
| 'flexEnd'
435+
| 'center'
436+
| 'spaceBetween'
437+
| 'spaceAround'
438+
| 'spaceEvenly';
417439
/**
418440
* Applies a linear gradient effect to the element.
419441
*
@@ -497,7 +519,10 @@ export interface ElementNode extends RendererNode, FocusNode {
497519
*
498520
* @see https://lightning-tv.github.io/solid/#/essentials/transitions?id=transitions-animations
499521
*/
500-
transition?: Record<string, AnimationSettings | undefined | true | false> | true | false;
522+
transition?:
523+
| Record<string, AnimationSettings | undefined | true | false>
524+
| true
525+
| false;
501526
/**
502527
* Optional handlers for animation events.
503528
*
@@ -650,7 +675,10 @@ export class ElementNode extends Object {
650675
}
651676

652677
this._fontWeight = v;
653-
const weight = (Config.fontWeightAlias && (Config.fontWeightAlias[v as string] as number | string)) ?? v;
678+
const weight =
679+
(Config.fontWeightAlias &&
680+
(Config.fontWeightAlias[v as string] as number | string)) ??
681+
v;
654682
(this.lng as any).fontFamily = `${this.fontFamily}${weight}`;
655683
}
656684

@@ -667,7 +695,10 @@ export class ElementNode extends Object {
667695
return this._fontFamily || Config.fontSettings?.fontFamily;
668696
}
669697

670-
insertChild(node: ElementNode | ElementText | TextNode, beforeNode?: ElementNode | ElementText | TextNode | null) {
698+
insertChild(
699+
node: ElementNode | ElementText | TextNode,
700+
beforeNode?: ElementNode | ElementText | TextNode | null,
701+
) {
671702
// always remove nodes if they have a parent - for back swap of node
672703
// this will then put the node at the end of the array when re-added
673704
if (node.parent) {
@@ -716,16 +747,22 @@ export class ElementNode extends Object {
716747
return undefined;
717748
}
718749

719-
set shader(shaderProps: IRendererShader | [kind: string, props: IRendererShaderProps]) {
720-
this.lng.shader = isArray(shaderProps) ? renderer.createShader(...shaderProps) : shaderProps;
750+
set shader(
751+
shaderProps: IRendererShader | [kind: string, props: IRendererShaderProps],
752+
) {
753+
this.lng.shader = isArray(shaderProps)
754+
? renderer.createShader(...shaderProps)
755+
: shaderProps;
721756
}
722757

723758
_sendToLightningAnimatable(name: string, value: number) {
724759
if (
725760
this.transition &&
726761
this.rendered &&
727762
Config.animationsEnabled &&
728-
(this.transition === true || this.transition[name] || this.transition[getPropertyAlias(name)])
763+
(this.transition === true ||
764+
this.transition[name] ||
765+
this.transition[getPropertyAlias(name)])
729766
) {
730767
const animationSettings =
731768
this.transition === true || this.transition[name] === true
@@ -737,20 +774,29 @@ export class ElementNode extends Object {
737774
this,
738775
name,
739776
value,
740-
animationSettings || (this.animationSettings as SimpleAnimationSettings),
777+
animationSettings ||
778+
(this.animationSettings as SimpleAnimationSettings),
741779
);
742780
simpleAnimation.register(renderer.stage);
743781
return;
744782
} else {
745-
const animationController = this.animate({ [name]: value }, animationSettings);
783+
const animationController = this.animate(
784+
{ [name]: value },
785+
animationSettings,
786+
);
746787

747788
if (this.onAnimation) {
748-
const animationEvents = Object.keys(this.onAnimation) as AnimationEvents[];
789+
const animationEvents = Object.keys(
790+
this.onAnimation,
791+
) as AnimationEvents[];
749792
for (const event of animationEvents) {
750793
const handler = this.onAnimation[event];
751-
animationController.on(event, (controller: IAnimationController, props?: any) => {
752-
handler!.call(this, controller, name, value, props);
753-
});
794+
animationController.on(
795+
event,
796+
(controller: IAnimationController, props?: any) => {
797+
handler!.call(this, controller, name, value, props);
798+
},
799+
);
754800
}
755801
}
756802

@@ -765,11 +811,18 @@ export class ElementNode extends Object {
765811
props: Partial<INodeAnimateProps<CoreShaderNode>>,
766812
animationSettings?: AnimationSettings,
767813
): IAnimationController {
768-
isDev && assertTruthy(this.rendered, 'Node must be rendered before animating');
769-
return (this.lng as IRendererNode).animate(props, animationSettings || this.animationSettings || {});
814+
isDev &&
815+
assertTruthy(this.rendered, 'Node must be rendered before animating');
816+
return (this.lng as IRendererNode).animate(
817+
props,
818+
animationSettings || this.animationSettings || {},
819+
);
770820
}
771821

772-
chain(props: Partial<INodeAnimateProps<CoreShaderNode>>, animationSettings?: AnimationSettings) {
822+
chain(
823+
props: Partial<INodeAnimateProps<CoreShaderNode>>,
824+
animationSettings?: AnimationSettings,
825+
) {
773826
if (this._animationRunning) {
774827
this._animationQueue = [];
775828
this._animationRunning = false;
@@ -778,7 +831,8 @@ export class ElementNode extends Object {
778831
if (animationSettings) {
779832
this._animationQueueSettings = animationSettings;
780833
} else if (!this._animationQueueSettings) {
781-
this._animationQueueSettings = animationSettings || this.animationSettings;
834+
this._animationQueueSettings =
835+
animationSettings || this.animationSettings;
782836
}
783837
animationSettings = animationSettings || this._animationQueueSettings;
784838
this._animationQueue = this._animationQueue || [];
@@ -790,7 +844,9 @@ export class ElementNode extends Object {
790844
let animation = this._animationQueue!.shift();
791845
while (animation) {
792846
this._animationRunning = true;
793-
await this.animate(animation.props, animation.animationSettings).start().waitUntilStopped();
847+
await this.animate(animation.props, animation.animationSettings)
848+
.start()
849+
.waitUntilStopped();
794850
animation = this._animationQueue!.shift();
795851
}
796852
this._animationRunning = false;
@@ -822,7 +878,8 @@ export class ElementNode extends Object {
822878
return;
823879
}
824880
} else {
825-
const focusedIndex = typeof this.forwardFocus === 'number' ? this.forwardFocus : null;
881+
const focusedIndex =
882+
typeof this.forwardFocus === 'number' ? this.forwardFocus : null;
826883
const nodes = this.children;
827884
if (focusedIndex !== null && focusedIndex < nodes.length) {
828885
const child = nodes[focusedIndex];
@@ -946,7 +1003,9 @@ export class ElementNode extends Object {
9461003
}
9471004

9481005
set states(states: NodeStates) {
949-
this._states = this._states ? this._states.merge(states) : new States(this._stateChanged.bind(this), states);
1006+
this._states = this._states
1007+
? this._states.merge(states)
1008+
: new States(this._stateChanged.bind(this), states);
9501009
if (this.rendered) {
9511010
this._stateChanged();
9521011
}
@@ -1014,7 +1073,8 @@ export class ElementNode extends Object {
10141073

10151074
const flexChanged = this.display === 'flex' && calculateFlex(this);
10161075
layoutQueue.delete(this);
1017-
const onLayoutChanged = isFunc(this.onLayout) && this.onLayout.call(this, this);
1076+
const onLayoutChanged =
1077+
isFunc(this.onLayout) && this.onLayout.call(this, this);
10181078

10191079
if ((flexChanged || onLayoutChanged) && this.parent) {
10201080
addToLayoutQueue(this.parent);
@@ -1071,7 +1131,9 @@ export class ElementNode extends Object {
10711131
let newStyles: Styles;
10721132
if (numStates === 1) {
10731133
newStyles = this[states[0] as keyof Styles] as Styles;
1074-
newStyles = stylesToUndo ? { ...stylesToUndo, ...newStyles } : newStyles;
1134+
newStyles = stylesToUndo
1135+
? { ...stylesToUndo, ...newStyles }
1136+
: newStyles;
10751137
} else {
10761138
newStyles = states.reduce((acc, state) => {
10771139
const styles = this[state];
@@ -1186,13 +1248,17 @@ export class ElementNode extends Object {
11861248
}
11871249

11881250
if (!textProps.maxWidth) {
1189-
textProps.maxWidth = parentWidth - textProps.x! - (textProps.marginRight || 0);
1251+
textProps.maxWidth =
1252+
parentWidth - textProps.x! - (textProps.marginRight || 0);
11901253
}
11911254

11921255
if (textProps.contain === 'both' && !textProps.maxHeight) {
1193-
textProps.maxHeight = parentHeight - textProps.y! - (textProps.marginBottom || 0);
1256+
textProps.maxHeight =
1257+
parentHeight - textProps.y! - (textProps.marginBottom || 0);
11941258
} else if (textProps.maxLines === 1) {
1195-
textProps.maxHeight = (textProps.maxHeight || textProps.lineHeight || textProps.fontSize) as number;
1259+
textProps.maxHeight = (textProps.maxHeight ||
1260+
textProps.lineHeight ||
1261+
textProps.fontSize) as number;
11961262
}
11971263

11981264
textProps.w = textProps.h = undefined;
@@ -1204,7 +1270,9 @@ export class ElementNode extends Object {
12041270
}
12051271

12061272
isDev && log('Rendering: ', this, props);
1207-
node.lng = renderer.createTextNode(props as unknown as IRendererTextNodeProps);
1273+
node.lng = renderer.createTextNode(
1274+
props as unknown as IRendererTextNodeProps,
1275+
);
12081276
if (parent.requiresLayout()) {
12091277
if (!textProps.maxWidth || !textProps.maxHeight) {
12101278
node._layoutOnLoad();
@@ -1334,7 +1402,9 @@ function createRawShaderAccessor<T>(key: keyof StyleEffects) {
13341402
};
13351403
}
13361404

1337-
function shaderAccessor<T extends Record<string, any> | number>(key: 'border' | 'shadow' | 'rounded') {
1405+
function shaderAccessor<T extends Record<string, any> | number>(
1406+
key: 'border' | 'shadow' | 'rounded',
1407+
) {
13381408
return {
13391409
set(this: ElementNode, value: T) {
13401410
let target = this.lng.shader || {};
@@ -1343,12 +1413,17 @@ function shaderAccessor<T extends Record<string, any> | number>(key: 'border' |
13431413
if (this.lng.shader?.program) {
13441414
target = this.lng.shader.props;
13451415
const transitionKey = key === 'rounded' ? 'borderRadius' : key;
1346-
if (this.transition && (this.transition === true || this.transition[transitionKey])) {
1416+
if (
1417+
this.transition &&
1418+
(this.transition === true || this.transition[transitionKey])
1419+
) {
13471420
target = {};
13481421
animationSettings =
13491422
this.transition === true || this.transition[transitionKey] === true
13501423
? undefined
1351-
: (this.transition[transitionKey] as undefined | AnimationSettings);
1424+
: (this.transition[transitionKey] as
1425+
| undefined
1426+
| AnimationSettings);
13521427
}
13531428
}
13541429

@@ -1388,6 +1463,8 @@ Object.defineProperties(ElementNode.prototype, {
13881463
rounded: shaderAccessor<BorderRadius>('rounded'),
13891464
// Alias for rounded
13901465
borderRadius: shaderAccessor<BorderRadius>('rounded'),
1391-
linearGradient: createRawShaderAccessor<LinearGradientProps>('linearGradient'),
1392-
radialGradient: createRawShaderAccessor<RadialGradientProps>('radialGradient'),
1466+
linearGradient:
1467+
createRawShaderAccessor<LinearGradientProps>('linearGradient'),
1468+
radialGradient:
1469+
createRawShaderAccessor<RadialGradientProps>('radialGradient'),
13931470
});

src/core/intrinsicTypes.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import {
99
ShaderRoundedProps,
1010
ShaderShadowProps,
1111
} from './shaders.js';
12-
import { EventHandlers, DefaultKeyMap, KeyHoldMap, FocusNode } from './focusKeyTypes.js';
12+
import {
13+
EventHandlers,
14+
DefaultKeyMap,
15+
KeyHoldMap,
16+
FocusNode,
17+
} from './focusKeyTypes.js';
1318
import type { JSXElement } from 'solid-js';
1419

1520
export type AnimationSettings = Partial<lngr.AnimationSettings>;
@@ -47,7 +52,9 @@ export type RemoveUnderscoreProps<T> = {
4752
[K in keyof T as K extends `_${string}` ? never : K]: T[K];
4853
};
4954

50-
type RendererText = AddColorString<Partial<Omit<lngr.ITextNodeProps, 'debug' | 'shader' | 'parent'>>>;
55+
type RendererText = AddColorString<
56+
Partial<Omit<lngr.ITextNodeProps, 'debug' | 'shader' | 'parent'>>
57+
>;
5158

5259
type CleanElementNode = NewOmit<
5360
RemoveUnderscoreProps<ElementNode>,
@@ -73,7 +80,10 @@ type CleanElementNode = NewOmit<
7380
>;
7481
/** Node text, children of a ElementNode of type TextNode */
7582
export interface ElementText
76-
extends NewOmit<ElementNode, '_type' | 'parent' | 'children' | 'src' | 'scale' | 'fontFamily'>,
83+
extends NewOmit<
84+
ElementNode,
85+
'_type' | 'parent' | 'children' | 'src' | 'scale' | 'fontFamily'
86+
>,
7787
NewOmit<RendererText, 'x' | 'y' | 'w' | 'h'> {
7888
_type: 'textNode';
7989
parent?: ElementNode;
@@ -97,7 +107,14 @@ export interface NodeProps
97107
Partial<
98108
NewOmit<
99109
CleanElementNode,
100-
'children' | 'text' | 'lng' | 'rendered' | 'renderer' | 'emit' | 'preFlexwidth' | 'preFlexHeight'
110+
| 'children'
111+
| 'text'
112+
| 'lng'
113+
| 'rendered'
114+
| 'renderer'
115+
| 'emit'
116+
| 'preFlexwidth'
117+
| 'preFlexHeight'
101118
>
102119
> {
103120
states?: NodeStates;
@@ -172,7 +189,10 @@ type EventPayloadMap = {
172189

173190
type NodeEvents = keyof EventPayloadMap;
174191

175-
type EventHandler<E extends NodeEvents> = (target: ElementNode, event?: EventPayloadMap[E]) => void;
192+
type EventHandler<E extends NodeEvents> = (
193+
target: ElementNode,
194+
event?: EventPayloadMap[E],
195+
) => void;
176196

177197
export type OnEvent = Partial<{
178198
[K in NodeEvents]: EventHandler<K>;

0 commit comments

Comments
 (0)