Commit b15f5211 authored by Fred Chasen's avatar Fred Chasen

Init

parents
File added
{
"presets": [["@babel/preset-env", {
"useBuiltIns": "usage"
}]],
"plugins": ["@babel/plugin-transform-runtime"]
}
lib
dist
node_modules
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Pagedjs Previewer</title>
<meta content="width=device-width, initial-scale=1" name="viewport">
<script src="node_modules/pagedjs/dist/paged.js"></script>
<script src="dist/main.js"></script>
<style>
@media screen {
body {
background-color: whitesmoke;
}
.pagedjs_page {
background-color: #fdfdfd;
margin: 10px auto;
flex: none;
box-shadow: 0 0 0 1px rgba(0, 0,0,0.2);
}
}
</style>
</head>
<body>
</body>
</html>
This diff is collapsed.
{
"name": "pagedjs-previewer",
"version": "0.0.1",
"description": "Previewer for Pagedjs",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "./node_modules/.bin/webpack-dev-server",
"compile": "./node_modules/.bin/babel src/ -d lib/",
"watch": "./node_modules/.bin/babel src/ -w -d lib/",
"build": "./node_modules/.bin/webpack",
"prepare": "npm run compile && npm run build"
},
"repository": {
"type": "git",
"url": "https://gitlab.pagedmedia.org/tools/previewer.git"
},
"author": "fchasen@gmail.com",
"license": "MIT",
"dependencies": {
"@babel/polyfill": "^7.0.0",
"@babel/runtime": "^7.1.2",
"pagedjs": "^0.1.15"
},
"devDependencies": {
"@babel/cli": "^7.1.2",
"@babel/core": "^7.1.2",
"@babel/plugin-transform-runtime": "^7.1.0",
"@babel/preset-env": "^7.1.0",
"babel-loader": "^8.0.4",
"http-server": "^0.11.1",
"webpack": "^4.20.2",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.9"
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
let ready = new Promise(function(resolve, reject){
if (document.readyState === "interactive" || document.readyState === "complete") {
resolve(document.readyState);
return;
}
document.onreadystatechange = function ($) {
if (document.readyState === "interactive") {
resolve(document.readyState);
}
}
});
ready.then(async function () {
// Create a new Previewer
let previewer = new Paged.Previewer();
// Get the URL to load
let params = URLSearchParams && new URLSearchParams(document.location.search.substring(1));
let url = params && params.get("url") && decodeURIComponent(params.get("url"));
if (!url) {
console.error("No 'url' parameter given.");
return;
}
// Fetch and Parse Contents
let html = await fetch(url)
.then(response => response.text())
.then(str => (new DOMParser()).parseFromString(str, "text/html"))
// Gather all stylesheets from html document
let hrefs = previewer.removeStyles(html);
// Add a stylesheet url in params
let stylesheet = params && params.get("stylesheet") && decodeURIComponent(params.get("stylesheet"));
if (stylesheet) {
hrefs.push(stylesheet);
}
// Push all body elements to a document fragment
let content = html.querySelectorAll('body > *');
let fragment = document.createDocumentFragment();
for (let i = 0; i < content.length; i++) {
fragment.appendChild(content[i]);
}
// Run the Paged Preview
let done = await previewer.preview(fragment, hrefs, document.body);
});
const path = require('path');
module.exports = {
entry: path.join(__dirname, 'src/index.js'),
output: {
path: path.join(__dirname, 'dist'),
filename: 'main.js'
},
module: {
rules: [{
test: /\.js/,
exclude: /node_modules/,
use: [{
loader: 'babel-loader'
}]
}]
},
plugins: [],
stats: {
colors: true
},
devtool: 'source-map'
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment