Skip to content

Commit 29e78bb

Browse files
committed
feat: <canvas>
1 parent 58de42c commit 29e78bb

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

packages/widget/src/canvas.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { type } from 'arktype'
2+
import { defineComponent } from 'sciux-laplace'
3+
4+
const CanvasType = type({
5+
width: 'number',
6+
height: 'number',
7+
origin: 'number[]',
8+
})
9+
10+
export default defineComponent<'canvas', typeof CanvasType.infer>((attrs) => {
11+
return {
12+
name: 'canvas',
13+
attrs: CanvasType,
14+
defaults: {
15+
origin: [0, 0],
16+
},
17+
setup(children) {
18+
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
19+
svg.setAttribute('viewBox', `0 0 ${attrs.width.value} ${attrs.height.value}`)
20+
svg.setAttribute('width', '100%')
21+
svg.style.aspectRatio = (attrs.width.value / attrs.height.value).toString()
22+
const root = document.createElementNS('http://www.w3.org/2000/svg', 'g')
23+
root.setAttribute('transform', `translate(${attrs.origin.value.join(',')})`)
24+
root.append(...children())
25+
svg.append(root)
26+
return svg
27+
},
28+
}
29+
})

packages/widget/src/table.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/**
2+
* `<table>` component examples
3+
* ```
4+
* <table caption="The table description" align="horizon" :columns="3">
5+
* <link>a link could be a part of item</link>
6+
* <canvas></canvas> // A canvas also could
7+
* Hello world! // A pure-text node also
8+
* // Auto enter to next table line because the max columns is `3`
9+
* <each-node-can-be/>
10+
* </table>
11+
* ```
12+
*/
13+
114
import { size } from '@sciux/layout'
215
import { type } from 'arktype'
316
import { defineComponent, toValue } from 'sciux-laplace'

0 commit comments

Comments
 (0)