Skip to content

Commit

Permalink
docs: update preview example
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin committed Nov 1, 2023
1 parent 516c447 commit d80e3ab
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 23 deletions.
45 changes: 30 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,26 @@ content of `index.html`:
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Svg Document</title>
<script type="module" src="http://localhost:12345/all-in-one.bundle.js" id="typst"></script>
</head>
<body>
<script type="module" src="http://localhost:12345/all-in-one.bundle.js" id="typst"></script>
<textarea id="input" style="width: 100%"></textarea>
<div id="content"></div>
<script>
const input = document.getElementById('input');
input.value = 'Hello, Typst!';
document.getElementById('typst').addEventListener('load', function () {
$typst.svg({ mainContent: 'Hello, World!' }).then(svg => {
console.log(`rendered! SvgElement { len: ${svg.length} }`);
// append svg text
document.getElementById('content').innerHTML = svg;
});
const compile = function (mainContent) {
$typst.svg({ mainContent }).then(svg => {
console.log(`rendered! SvgElement { len: ${svg.length} }`);
// append svg text
document.getElementById('content').innerHTML = svg;
});
};
input.oninput = () => compile(input.value);
compile(input.value);
});
</script>
<div id="content"></div>
</body>
</html>
```
Expand All @@ -166,14 +173,18 @@ You can also load the all-in-one bundle file and wasm modules from [jsdelivr](ht
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Svg Document</title>
</head>
<body>
<script
type="module"
src="https://cdn.jsdelivr.net/npm/@myriaddreamin/typst.ts/dist/esm/contrib/all-in-one-lite.bundle.js"
id="typst"
></script>
</head>
<body>
<textarea id="input" style="width: 100%"></textarea>
<div id="content"></div>
<script>
const input = document.getElementById('input');
input.value = 'Hello, Typst!';
document.getElementById('typst').addEventListener('load', function () {
$typst.setCompilerInitOptions({
getModule: () =>
Expand All @@ -183,14 +194,18 @@ You can also load the all-in-one bundle file and wasm modules from [jsdelivr](ht
getModule: () =>
'https://cdn.jsdelivr.net/npm/@myriaddreamin/typst-ts-renderer/pkg/typst_ts_renderer_bg.wasm',
});
$typst.svg({ mainContent: 'Hello, World!' }).then(svg => {
console.log(`rendered! SvgElement { len: ${svg.length} }`);
// append svg text
document.getElementById('content').innerHTML = svg;
});
const compile = function (mainContent) {
$typst.svg({ mainContent }).then(svg => {
console.log(`rendered! SvgElement { len: ${svg.length} }`);
// append svg text
document.getElementById('content').innerHTML = svg;
});
};
input.oninput = () => compile(input.value);
compile(input.value);
});
</script>
<div id="content"></div>
</body>
</html>
```
Expand Down
3 changes: 3 additions & 0 deletions github-pages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<li style="padding: 10px 40px">
<a href="/typst.ts/">Typst.ts</a>
</li>
<li style="padding: 10px 40px">
<a href="/typst.ts/preview.html">Preview Demo</a>
</li>
<li style="padding: 10px 40px">
<a href="/typst.ts/">Packages</a>
</li>
Expand Down
41 changes: 41 additions & 0 deletions github-pages/preview.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Svg Document</title>
<script
type="module"
src="https://cdn.jsdelivr.net/npm/@myriaddreamin/typst.ts/dist/esm/contrib/all-in-one-lite.bundle.js"
id="typst"
></script>
</head>
<body>
<textarea id="input" style="width: 100%"></textarea>
<div id="content"></div>
<script>
const input = document.getElementById('input');
input.value = 'Hello, Typst!';
document.getElementById('typst').addEventListener('load', function () {
$typst.setCompilerInitOptions({
getModule: () =>
'https://cdn.jsdelivr.net/npm/@myriaddreamin/typst-ts-web-compiler/pkg/typst_ts_web_compiler_bg.wasm',
});
$typst.setRendererInitOptions({
getModule: () =>
'https://cdn.jsdelivr.net/npm/@myriaddreamin/typst-ts-renderer/pkg/typst_ts_renderer_bg.wasm',
});

const compile = function (mainContent) {
$typst.svg({ mainContent }).then(svg => {
console.log(`rendered! SvgElement { len: ${svg.length} }`);
// append svg text
document.getElementById('content').innerHTML = svg;
});
};
input.oninput = () => compile(input.value);
compile(input.value);
});
</script>
</body>
</html>
24 changes: 16 additions & 8 deletions packages/typst.ts/examples/cdn.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Svg Document</title>
</head>
<body>
<script
type="module"
src="https://cdn.jsdelivr.net/npm/@myriaddreamin/typst.ts/dist/esm/contrib/all-in-one-lite.bundle.js"
id="typst"
></script>
</head>
<body>
<textarea id="input" style="width: 100%"></textarea>
<div id="content"></div>
<script>
const input = document.getElementById('input');
input.value = 'Hello, Typst!';
document.getElementById('typst').addEventListener('load', function () {
$typst.setCompilerInitOptions({
getModule: () =>
Expand All @@ -21,13 +25,17 @@
getModule: () =>
'https://cdn.jsdelivr.net/npm/@myriaddreamin/typst-ts-renderer/pkg/typst_ts_renderer_bg.wasm',
});
$typst.svg({ mainContent: 'Hello, World!' }).then(svg => {
console.log(`rendered! SvgElement { len: ${svg.length} }`);
// append svg text
document.getElementById('content').innerHTML = svg;
});

const compile = function (mainContent) {
$typst.svg({ mainContent }).then(svg => {
console.log(`rendered! SvgElement { len: ${svg.length} }`);
// append svg text
document.getElementById('content').innerHTML = svg;
});
};
input.oninput = () => compile(input.value);
compile(input.value);
});
</script>
<div id="content"></div>
</body>
</html>

0 comments on commit d80e3ab

Please sign in to comment.