Skip to content

Commit

Permalink
chore: small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Jan 2, 2024
1 parent 330177f commit d421d1a
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/painter/Image.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default class Image {}
34 changes: 31 additions & 3 deletions src/painter/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import Component, { IComponentOptions } from '../share/Component'
import stripIndent from 'licia/stripIndent'
import $ from 'licia/$'

/** IOptions. */
export interface IOptions extends IComponentOptions {
/** Canvas width. */
width?: number
/** Canvas height. */
height?: number
}

Expand All @@ -13,9 +18,32 @@ export interface IOptions extends IComponentOptions {
* const painer = new LunaPainter(container)
*/
export default class Painter extends Component<IOptions> {
constructor(container: HTMLElement, options: IOptions) {
super(container, { compName: 'painer' }, options)
private $viewport: $.$
constructor(container: HTMLElement, options: IOptions = {}) {
super(container, { compName: 'painter' }, options)

this.initOptions(options, {})
this.initOptions(options, {
width: 800,
height: 600,
})

this.initTpl()

this.$viewport = this.find('.viewport')
}
private initTpl() {
const { width, height } = this.options

this.$container.html(
this.c(stripIndent`
<div class="viewport">
<div class="canvas-wrapper">
<div class="canvas-container">
<canvas width="${width}" height="${height}"></canvas>
</div>
</div>
</div>
`)
)
}
}
15 changes: 13 additions & 2 deletions src/painter/story.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import 'luna-painter'
import 'luna-painter.css'
import Painter from 'luna-painter.js'
import story from '../share/story'
import readme from './README.md'
import $ from 'licia/$'

const def = story(
'painter',
(container) => {
const painter = new Painter(container)
$(container).css({
width: '100%',
maxWidth: 1200,
height: 600,
margin: '0 auto',
})

const painter = new Painter(container, {
width: 512,
height: 512,
})

return painter
},
Expand Down
25 changes: 25 additions & 0 deletions src/painter/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@import '../share/mixin';

.luna-painter {
@include component();
}

.viewport {
width: 100%;
height: 100%;
overflow: auto;
background: #2b2b2b;
display: flex;
}

.canvas-wrapper {
margin: auto;
}

.canvas-container {
background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAAA3NCSVQICAjb4U/gAAAABlBMVEXMzMz////TjRV2AAAACXBIWXMAAArrAAAK6wGCiw1aAAAAHHRFWHRTb2Z0d2FyZQBBZG9iZSBGaXJld29ya3MgQ1M26LyyjAAAABFJREFUCJlj+M/AgBVhF/0PAH6/D/HkDxOGAAAAAElFTkSuQmCC');
}

.theme-dark {
color-scheme: dark;
}

0 comments on commit d421d1a

Please sign in to comment.