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