wip(shared): Working on custom layout
This commit is contained in:
parent
f4ee97a626
commit
34c8a6b2a5
13 changed files with 357 additions and 0 deletions
|
@ -0,0 +1,76 @@
|
|||
|
||||
const name = 'Pages Plugin'
|
||||
const version = '1.0.0'
|
||||
const sizes = {
|
||||
a4: [ 210, 297 ],
|
||||
a3: [ 297, 420 ],
|
||||
a2: [ 420, 594 ],
|
||||
a1: [ 594, 841 ],
|
||||
a0: [ 841, 1188 ],
|
||||
letter: [ 215.9, 279.4 ],
|
||||
tabloid: [ 279.4, 431.8 ],
|
||||
}
|
||||
|
||||
const drawPage = (x, y, size, orientation) => {
|
||||
//
|
||||
}
|
||||
|
||||
const pagesPlugin = (size='a4', orientation='portrait') => ({
|
||||
name,
|
||||
version,
|
||||
hooks: {
|
||||
postLayout: function(pattern) {
|
||||
// Add part
|
||||
pattern.parts.pages = pattern.Part('pages')
|
||||
// Keep part out of layout
|
||||
pattern.parts.pages.layout = false
|
||||
// Add pages
|
||||
const { macro } = pattern.parts.pages.shorthand()
|
||||
const { height, width } = pattern
|
||||
macro('addPages', { size, orientation, height, width })
|
||||
}
|
||||
},
|
||||
macros: {
|
||||
addPages: function(so) {
|
||||
const ls = so.orientation === 'landscape'
|
||||
const w = sizes[so.size][ls ? 1 : 0]
|
||||
const h = sizes[so.size][ls ? 0 : 1]
|
||||
const cols = Math.ceil(so.width / w)
|
||||
const rows = Math.ceil(so.height / h)
|
||||
const { points, Point, paths, Path } = this.shorthand()
|
||||
let x = 0
|
||||
let y = 0
|
||||
let count = 0
|
||||
for (let row=0;row<rows;row++) {
|
||||
x=0
|
||||
for (let col=0;col<cols;col++) {
|
||||
count++
|
||||
points[`_pages__row${row}-col${col}-tl`] = new Point(x,y)
|
||||
points[`_pages__row${row}-col${col}-tr`] = new Point(x+w,y)
|
||||
points[`_pages__row${row}-col${col}-br`] = new Point(x+w,y+h)
|
||||
points[`_pages__row${row}-col${col}-bl`] = new Point(x,y+h)
|
||||
points[`_pages__row${row}-col${col}-circle`] = new Point(x+w/2,y+h/2-24)
|
||||
.attr('data-circle', 42)
|
||||
.attr('data-circle-class', 'stroke-4xl muted')
|
||||
points[`_pages__row${row}-col${col}-text`] = new Point(x+w/2,y+h/2)
|
||||
.attr('data-text', `${count}`)
|
||||
.attr('data-text-class', 'text-4xl center bold muted')
|
||||
|
||||
paths[`_pages__row${row}-col${col}`] = new Path()
|
||||
.move(points[`_pages__row${row}-col${col}-tl`])
|
||||
.line(points[`_pages__row${row}-col${col}-bl`])
|
||||
.line(points[`_pages__row${row}-col${col}-br`])
|
||||
.line(points[`_pages__row${row}-col${col}-tr`])
|
||||
.close()
|
||||
.attr('class', 'fill-fabric')
|
||||
.attr('style', `stroke-opacity: 0; fill-opacity: ${(col+row)%2===0 ? 0.03 : 0.09};`)
|
||||
x += w
|
||||
}
|
||||
y += h
|
||||
}
|
||||
this.pages = { cols, rows, count: (cols+1)*(rows+1) }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export default pagesPlugin
|
Loading…
Add table
Add a link
Reference in a new issue