Skip to content

Commit

Permalink
Snapshot HTML produces invalid html file with Jupyter Notebook versio…
Browse files Browse the repository at this point in the history
…n 7 #450
  • Loading branch information
artur-trzesiok committed Jul 3, 2024
1 parent a4dc589 commit 7cefa09
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 28 deletions.
13 changes: 7 additions & 6 deletions js/src/core/lib/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ const fflate = require('fflate');
const requireJsSource = require('../../../../node_modules/requirejs/require?raw');
const fflateJsSource = require('../../../../node_modules/fflate/umd/index?raw');
const fileLoader = require('./helpers/fileLoader');
const templateStandalone = require('./snapshot_standalone.txt');
const templateOnline = require('./snapshot_online.txt');
const templateInline = require('./snapshot_inline.txt');
const templateStandalone = require('./snapshot_standalone').default;
const templateOnline = require('./snapshot_online').default;
const templateInline = require('./snapshot_inline').default;
const semverRange = require('../../version').version;
const buffer = require('./helpers/buffer');

Expand All @@ -26,7 +26,8 @@ if (typeof (sourceCode) === 'undefined') {
}

if (typeof (path) !== 'undefined') {
path = path.replace('k3d.js', 'standalone.js').replace('index.js', 'standalone.js');
path = path.replaceAll('\\\\', '/').replaceAll('\\', '/');
path = path.split('/').slice(0, -1).join('/') + '/standalone.js';
} else {
// use npm repository
path = `https://unpkg.com/k3d@${semverRange}/dist/standalone.js`;
Expand Down Expand Up @@ -68,7 +69,7 @@ function getHTMLSnapshot(K3D, compressionLevel) {
}

function handleFileSelect(K3D, evt) {
const {files} = evt.dataTransfer;
const { files } = evt.dataTransfer;
const HTMLSnapshotReader = new FileReader();
const BinarySnapshotReader = new FileReader();
const STLReader = new FileReader();
Expand Down Expand Up @@ -141,7 +142,7 @@ function snapshotGUI(gui, K3D) {
filename = `${K3D.parameters.name}.html`;
}

data = new Blob([data], {type: 'text/plain;charset=utf-8'});
data = new Blob([data], { type: 'text/plain;charset=utf-8' });
FileSaver.saveAs(data, filename);
},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div id="canvasTarget_[ID]" class="k3d_plot" style="position: relative;"></div>
export default `<div id="canvasTarget_[ID]" class="k3d_plot" style="position: relative;"></div>
<script>
var K3DInstance;
Expand Down Expand Up @@ -26,7 +26,7 @@
try {
document.getElementById('canvasTarget_[ID]').style.cssText = [
`height:[HEIGHT]px`,
'height:[HEIGHT]px',
'position: relative',
].join(';');
Expand Down Expand Up @@ -64,4 +64,4 @@
} else {
loadK3D();
}
</script>
</script>`;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!doctype html>
export default `<!doctype html>
<html>
<head>
<meta charset="utf-8">
Expand Down Expand Up @@ -54,4 +54,4 @@
});
</script>
</body>
</html>
</html>`;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!doctype html>
export default `<!doctype html>
<html>
<head>
<meta charset="utf-8">
Expand Down Expand Up @@ -62,4 +62,4 @@
});
</script>
</body>
</html>
</html>`;
44 changes: 29 additions & 15 deletions js/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,14 @@ module.exports = [
{
entry: './src/standalone.js',
output:
{
filename: 'standalone.js',
path: `${__dirname}/../k3d/static`,
library: 'k3d',
libraryTarget: 'amd',
publicPath: `https://unpkg.com/k3d@${version}/dist/`,
},
{
filename: 'standalone.js',
path: `${__dirname}/../k3d/static`,
library: 'k3d',
libraryTarget: 'amd',
publicPath: `https://unpkg.com/k3d@${version}/dist/`,
},
mode,
devtool: 'source-map',
module: {
rules,
},
Expand All @@ -133,15 +132,30 @@ module.exports = [
{
entry: './src/standalone.js',
output:
{
filename: 'standalone.js',
path: `${__dirname}/dist/`,
library: 'k3d',
libraryTarget: 'amd',
publicPath: `https://unpkg.com/k3d@${version}/dist/`,
{
filename: 'standalone.js',
path: `${__dirname}/dist/`,
library: 'k3d',
libraryTarget: 'amd',
publicPath: `https://unpkg.com/k3d@${version}/dist/`,
},
mode,
module: {
rules,
},
plugins,
},
{
entry: './src/standalone.js',
output:
{
filename: 'standalone.js',
path: `${__dirname}/../k3d/labextension/static/`,
library: 'k3d',
libraryTarget: 'amd',
publicPath: `https://unpkg.com/k3d@${version}/dist/`,
},
mode,
devtool: 'source-map',
module: {
rules,
},
Expand Down

0 comments on commit 7cefa09

Please sign in to comment.