EN | 中文
Use the render function to create a document flow in the canvas and quickly implement the layout.
If there is a problem in use, check the code in the example, click to view DEMO
view basic element, similar to divtext text supports automatic line wrapping and over omitted functions, currently text is implemented as inline-blockimagesrcmodesupports aspectFit and aspectFill, other css features are the same as web supportload` event to monitor image loading and drawing completionscroll-view scroll container, you need to set direction in the style to support x, y, xy, and set the specific size. Set renderOnDemand to draw only the visible partUse numbers where the attribute uses pixels
display block | inline-block | flex, text is inline by defaultwidth auto 100% Number This box model uses border-box and cannot be modifiedheightflex flex does not support auto, use width directly for fixed widthminWidth maxWidth minHeight maxHeight If the specific width is set, the height will not take effectmargin marginLeft,marginRight,marginTop,marginBottom margin supports array abbreviations such as [10,20] [10,20,10,20]paddingLeft,paddingRight,paddingTop,paddingBottom Same as abovebackgroundColorborderRadiusborderWidth borderTopWidth ... Set the thin border directly to 0.5borderColorlineHeight font related only valid in textcolorfontSizetextAlign left right centertextIndent NumberverticalAlign top middle bottomjustifyContent flex-start center flex-end flex layout align horizontallymaxLine maximum number of lines, exceeding the automatic ellipsis, only supports use in textwhiteSpace normal nowrap controls line breaks, not fontsflexDirectionborderStyle dash Array See ctx.setLineDash() for detailsshadowBlur set the shadow will automatically add overflow:hidden;shadowColorshadowOffsetXshadowOffsetYposition static ʻabsolute`Number`npm install easy-canvas-layout --save
import easyCanvas from'easy-canvas-layout'
// create a layer bind with ctx
const layer = easyCanvas.createLayer(ctx, {
dpr: 2,
width: 300,
height: 600,
})
// create a node tree
// c(tag,options,children)
const node = easyCanvas.createElement((c) => {
return c('view', {
styles: {backgroundColor:'#000' }, // style
attrs:(), // attributes such as src
on:{} // events such as click load
},
[
c('text',{color:'#fff'},'Hello World')
])
})
// mount
node.mount(layer)
...
function button(c,text){
return c(
'view',
{
styles: {
backgroundColor:'#ff6c79',
borderRadius: 10,
borderColor:'#fff',
display:'inline-block',
margin: 2,
padding:[0,10]
},
},
[
c(
'text',
{
styles: {
lineHeight: 20,
color:'#fff',
textAlign:'center',
fontSize: 11,
},
},
text
),
]
)
}
easyCanvas.component('button',(opt,children,c) => button(c,children))
const node = easyCanvas.createElement((c) => {
return c('view',{},[
c('button',(),'This is a global component')
])
})
...
Copyright (c) 2020 Gitjinfeiyang
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTW
$ claude mcp add easy-canvas \
-- python -m otcore.mcp_server <graph>