Skip to content

Commit

Permalink
feat: responsive
Browse files Browse the repository at this point in the history
  • Loading branch information
guiseek committed Aug 23, 2024
1 parent 5e0049c commit 3dd90f3
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 28 deletions.
17 changes: 17 additions & 0 deletions src/app/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {dispatch} from '@websqnl/event-flow'
import {Toolbar} from '../features/toolbar'
import {canvas} from '../features/canvas'
import {throttle} from '@shared/utils'
import {windowResize} from './events'

export const app = () => {
const toolbar = new Toolbar()

const getSize = () => Math.min(innerWidth, innerHeight)

dispatch(windowResize(getSize()))

onresize = throttle(() => dispatch(windowResize(getSize())), 250)

root.append(toolbar, canvas)
}
4 changes: 4 additions & 0 deletions src/app/events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {createEvent, createListener} from '@websqnl/event-flow'

export const windowResize = createEvent('window.resize')
export const onWindowResize = createListener('window.resize')
1 change: 1 addition & 0 deletions src/app/handlers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './on-window-resize';
15 changes: 15 additions & 0 deletions src/app/handlers/on-window-resize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {dispatch} from '@websqnl/event-flow'
import {onWindowResize} from '../events'
import {canvasUpdateSize} from '@features/canvas'

onWindowResize((size) => {
const ideal = size < 1080 ? 540 : 1080
const {clientWidth: w, clientHeight: h} = root

dispatch(canvasUpdateSize({current: {w, h}, ideal}))

document.documentElement.style.setProperty(
'--cf-canvas-max-size',
`${ideal}px`
)
})
3 changes: 3 additions & 0 deletions src/app/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './handlers';
export * from './app';
export * from './events';
23 changes: 0 additions & 23 deletions src/features/app.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/features/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './toolbar';
export * from './canvas';
export * from './layers';
export * from './toolbar';
export * from './app';
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {loadFont} from '@shared/utils'
import {app} from './features'
import {app} from './app'
import './style.scss'

loadFont('Mukta', [400, 600, 800]).then(app)
2 changes: 2 additions & 0 deletions src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
--cf-onprimary-rgb: 255, 255 255;
--cf-surface-rgb: 250, 250, 250;
--cf-onsurface-rgb: 16, 16, 16;

--cf-canvas-max-size: 1080px;
}

html,
Expand Down
4 changes: 2 additions & 2 deletions src/styles/_canvas.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ canvas {
width: calc(100vw - 1em);
height: calc(100vw - 1em);

max-width: 540px;
max-height: 540px;
max-width: var(--cf-canvas-max-size);
max-height: var(--cf-canvas-max-size);

background-color: #e0e0e050;
background-image: linear-gradient(45deg, #cccccc50 25%, transparent 25%),
Expand Down
2 changes: 2 additions & 0 deletions src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ interface StateEventMap {
'toolbar.select.image': void
'toolbar.select.text': void
'toolbar.selected': ToolbarAction

'window.resize': number
}

interface Size {
Expand Down

0 comments on commit 3dd90f3

Please sign in to comment.