-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor cleanups and refactors to accomodate.
- Loading branch information
Showing
15 changed files
with
1,297 additions
and
2,288 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React, {FC, useMemo} from 'react'; | ||
|
||
import {Default} from './presets'; | ||
|
||
import './style.css'; | ||
import Scene from '@/components/Scene'; | ||
import {baseCSSProps, divCss, multCss} from '@/util/css'; | ||
import {ComicProps} from '@/util/types'; | ||
|
||
const Comic: FC<ComicProps> = ({color, dimensions, layout, scenes}) => { | ||
const {width, height, thickness} = dimensions ?? Default.dimensions; | ||
|
||
const comicStyle = baseCSSProps({ | ||
width, | ||
height, | ||
thickness, | ||
color, | ||
}); | ||
|
||
const panels = useMemo(() => { | ||
const normalized = layout.flatMap(r => { | ||
const total = r.reduce((t, n) => t + n, 0); | ||
return r.map(ogN => ogN / (total || 1)); | ||
}); | ||
|
||
return ( | ||
<div className="row"> | ||
{normalized.map((nf, idx) => { | ||
const sp = scenes[idx]; | ||
const normalizedProps = sp | ||
? { | ||
...sp, | ||
dimensions: { | ||
...sp.dimensions, | ||
width: multCss(sp.dimensions?.width ?? '', nf), | ||
height: divCss(dimensions?.height ?? '', layout.length || 1), | ||
}, | ||
} | ||
: undefined; | ||
return normalizedProps && <Scene key={`scene-${idx}`} {...normalizedProps} />; | ||
})} | ||
</div> | ||
); | ||
}, [dimensions?.height, layout, scenes]); | ||
|
||
return ( | ||
<div className="container" style={comicStyle}> | ||
{panels} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Comic; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export {default} from './Comic'; | ||
export * as ComicPresets from './presets'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {StickPresets} from '@/components/Stick'; | ||
import {ComicProps} from '@/util/types'; | ||
|
||
const DEFAULT_COMIC_SIZE = '50vmin'; | ||
|
||
export const Default: Required<ComicProps> = { | ||
color: StickPresets.Default.color, | ||
dimensions: { | ||
width: DEFAULT_COMIC_SIZE, | ||
height: DEFAULT_COMIC_SIZE, | ||
thickness: StickPresets.Default.dimensions.thickness, | ||
}, | ||
id: '', | ||
scenes: [], | ||
layout: [], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.container { | ||
width: var(--w, 100%); | ||
height: var(--h, 100%); | ||
position: relative; | ||
outline: var(--t, 2px) solid var(--c, #888888); | ||
margin: 3rem auto; | ||
} | ||
|
||
.row { | ||
display: flex; | ||
flex-direction: row; | ||
flex-wrap: wrap; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React, {FC} from 'react'; | ||
|
||
import {Default} from './presets'; | ||
|
||
import './style.css'; | ||
import Stick from '@/components/Stick'; | ||
import {baseCSSProps} from '@/util/css'; | ||
import {SceneProps} from '@/util/types'; | ||
|
||
const Scene: FC<SceneProps> = ({color, dimensions, sticks}) => { | ||
const {width, height, thickness} = dimensions ?? Default.dimensions; | ||
|
||
const sceneStyle = baseCSSProps({ | ||
width, | ||
height, | ||
thickness, | ||
color, | ||
}); | ||
|
||
return ( | ||
<div className="container" style={sceneStyle}> | ||
{sticks?.map((stickProps, idx) => ( | ||
<Stick {...stickProps} key={`stick-${idx}-${stickProps.id}`} /> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Scene; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export {default} from './Scene'; | ||
export * as ScenePresets from './presets'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import {StickPresets} from '@/components/Stick'; | ||
import {divCss, offsetVar} from '@/util/css'; | ||
import {Coordinates, SceneProps} from '@/util/types'; | ||
|
||
const DEFAULT_SCENE_SIZE = '100%'; | ||
|
||
export const Default: Required<SceneProps> = { | ||
color: StickPresets.Default.color, | ||
dimensions: { | ||
width: DEFAULT_SCENE_SIZE, | ||
height: DEFAULT_SCENE_SIZE, | ||
thickness: StickPresets.Default.dimensions.thickness, | ||
}, | ||
id: '', | ||
sticks: [], | ||
}; | ||
|
||
const H = 'h'; | ||
const W = 'w'; | ||
const OP = '0%'; | ||
|
||
export const Directions: Record<string, Coordinates> = { | ||
C: { | ||
x: divCss(offsetVar(W), 2), | ||
y: divCss(offsetVar(H), 2), | ||
}, | ||
SW: { | ||
x: OP, | ||
y: offsetVar(H), | ||
}, | ||
W: { | ||
x: OP, | ||
y: divCss(offsetVar(H), 2), | ||
}, | ||
NW: { | ||
x: OP, | ||
y: OP, | ||
}, | ||
N: { | ||
x: divCss(offsetVar(W), 2), | ||
y: OP, | ||
}, | ||
NE: { | ||
x: offsetVar(W), | ||
y: OP, | ||
}, | ||
E: { | ||
x: offsetVar(W), | ||
y: divCss(offsetVar(H), 2), | ||
}, | ||
SE: { | ||
x: offsetVar(W), | ||
y: offsetVar(H), | ||
}, | ||
S: { | ||
x: divCss(offsetVar(W), 2), | ||
y: offsetVar(H), | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.container { | ||
width: var(--w, 100%); | ||
height: var(--h, 100%); | ||
position: relative; | ||
outline: var(--t, 2px) solid var(--c, #888888); | ||
margin: auto; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export {default as Comic, ComicPresets} from './Comic'; | ||
export {default as Scene, ScenePresets} from './Scene'; | ||
export {default as Stick, StickPresets} from './Stick'; |
Oops, something went wrong.