-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added document file render helper
- Loading branch information
1 parent
f13b5cc
commit 6dd9c3a
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
export { default as renderDocumentFile } from './render-document-file'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { fragment } from 'xmlbuilder2'; | ||
|
||
import template from '../../template/document.template'; | ||
|
||
const VNode = require('virtual-dom/vnode/vnode'); | ||
const VText = require('virtual-dom/vnode/vtext'); | ||
|
||
const convertHTML = require('html-to-vdom')({ | ||
VNode, | ||
VText, | ||
}); | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
function convertVTreeToXML(vNode, xmlFragment) { | ||
if (!vNode) { | ||
// eslint-disable-next-line no-useless-return | ||
return; | ||
} | ||
// eslint-disable-next-line no-empty | ||
if (vNode.type === 'VirtualText') { | ||
} | ||
} | ||
|
||
function renderDocumentFile(documentOptions, htmlString) { | ||
const { orientation, margins } = documentOptions; | ||
const width = orientation === 'landscape' ? 15840 : 12240; | ||
const height = orientation === 'landscape' ? 12240 : 15840; | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
const vTree = convertHTML(htmlString); | ||
|
||
const xmlFragment = fragment(); | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
const xmlString = convertVTreeToXML(vTree, xmlFragment); | ||
|
||
return template(width, height, orientation, margins); | ||
} | ||
|
||
export default renderDocumentFile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters