1.1.0 • Published 6 years ago

page-wrapping v1.1.0

Weekly downloads
84,610
License
MIT
Repository
-
Last release
6 years ago

page-wrapping

npm Travis

Generic page wrapping algorithm proposal.

How it works

import wrapPage from 'page-wrapping'

// Create node instance.
// It can be whatever type of construction you want, but should always if support Node interface (see below).
const node = Node({ left: 20, top: 20, width: 100, height: 100 })

// Start page wrapping process.
// You should pass as first argument the page children (in this case only one node),
// and as second argument the page height used to wrap the elements.
await wrapPage([node], 40)

// [
//   { left: 20, top: 20, width: 100, height: 20 },
//   { left: 20, top: 0, width: 100, height: 40 },
//   { left: 20, top: 0, width: 100, height: 40 }
// ]

Node interface

PropertyDescriptionType
leftNode x coordinateNumber
topNode y coordinateNumber
widthNode widthNumber
heightNode heightNumber
minPresenceAheadPresence ahead of element to not to breakNumber
wrapWhether a node should be able to split in two or moreBoolean
breakWhether a node should create a page breakBoolean
fixedWhether a node should repeat throughout all pagesBoolean
parentNode pointer to parentNode
childrenChildren nodesArray
appendChildAdd node as childrenFunction
removeDetach node from parenFunction
cloneReturns a copy of target nodeFunction
nodeWillWrapCallback before element wrap. Can return promiseFunction
onNodeSplitCallback after element is split in twoFunction
isEmptyReturns if node is empty or notFunction