Add Svelte docs site and WASM playground
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import NavTree from './NavTree.svelte';
|
||||
import Playground from './Playground.svelte';
|
||||
import { nav, renderMarkdown } from './lib/docs.js';
|
||||
|
||||
let route = parseRoute(location.hash);
|
||||
|
||||
onMount(() => {
|
||||
const onHashChange = () => (route = parseRoute(location.hash));
|
||||
addEventListener('hashchange', onHashChange);
|
||||
return () => removeEventListener('hashchange', onHashChange);
|
||||
});
|
||||
|
||||
$: isPlayground = route.kind === 'playground';
|
||||
$: currentSlug = route.slug ?? 'introduction';
|
||||
$: html = isPlayground ? '' : renderMarkdown(currentSlug);
|
||||
|
||||
function parseRoute(hash) {
|
||||
const raw = hash.replace(/^#\/?/, '');
|
||||
if (raw === 'playground') return { kind: 'playground' };
|
||||
if (raw.startsWith('docs/')) {
|
||||
return { kind: 'docs', slug: raw.slice('docs/'.length) || 'introduction' };
|
||||
}
|
||||
return { kind: 'docs', slug: 'introduction' };
|
||||
}
|
||||
</script>
|
||||
|
||||
<header class="topbar">
|
||||
<a class="brand" href="#/docs/introduction">Decodal</a>
|
||||
<nav class="topnav">
|
||||
<a href="#/docs/introduction">Docs</a>
|
||||
<a href="#/playground">Playground</a>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<div class="layout">
|
||||
<aside class="sidebar">
|
||||
<a class="sidebar-title" href="#/docs/index">Manual</a>
|
||||
<NavTree items={nav} active={currentSlug} />
|
||||
</aside>
|
||||
|
||||
<main class:playground={isPlayground}>
|
||||
{#if isPlayground}
|
||||
<Playground />
|
||||
{:else}
|
||||
<article class="markdown">
|
||||
{@html html}
|
||||
</article>
|
||||
{/if}
|
||||
</main>
|
||||
</div>
|
||||
@@ -0,0 +1,15 @@
|
||||
<script>
|
||||
export let items = [];
|
||||
export let active = '';
|
||||
</script>
|
||||
|
||||
<ul class="nav-tree">
|
||||
{#each items as item}
|
||||
<li>
|
||||
<a class:active={active === item.slug} href={`#/docs/${item.slug}`}>{item.title}</a>
|
||||
{#if item.children}
|
||||
<svelte:self items={item.children} {active} />
|
||||
{/if}
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
@@ -0,0 +1,81 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
const starter = `let
|
||||
Service = {
|
||||
name = String;
|
||||
port = Int & > 443 default 8443;
|
||||
feature.enable = Bool default true;
|
||||
};
|
||||
in
|
||||
Service & {
|
||||
name = "api";
|
||||
port = 9443;
|
||||
}
|
||||
`;
|
||||
|
||||
let source = starter;
|
||||
let output = '';
|
||||
let error = '';
|
||||
let ready = false;
|
||||
let loading = true;
|
||||
let evaluate;
|
||||
|
||||
onMount(async () => {
|
||||
try {
|
||||
const wasm = await import('./wasm/decodal_wasm.js');
|
||||
await wasm.default();
|
||||
evaluate = wasm.evaluate;
|
||||
ready = true;
|
||||
run();
|
||||
} catch (err) {
|
||||
error = `Failed to load WASM playground: ${err.message ?? err}`;
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
});
|
||||
|
||||
function run() {
|
||||
if (!evaluate) return;
|
||||
const result = JSON.parse(evaluate(source));
|
||||
if (result.ok) {
|
||||
output = result.output;
|
||||
error = '';
|
||||
} else {
|
||||
output = '';
|
||||
error = result.error;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<section class="playground-page">
|
||||
<div class="playground-header">
|
||||
<div>
|
||||
<h1>Playground</h1>
|
||||
<p>Evaluate Decodal directly in your browser through WebAssembly.</p>
|
||||
</div>
|
||||
<button on:click={run} disabled={!ready}>Run</button>
|
||||
</div>
|
||||
|
||||
{#if loading}
|
||||
<p class="status">Loading WASM...</p>
|
||||
{/if}
|
||||
|
||||
<div class="playground-grid">
|
||||
<label class="pane">
|
||||
<span>Input</span>
|
||||
<textarea bind:value={source} spellcheck="false" on:keydown={(event) => {
|
||||
if ((event.metaKey || event.ctrlKey) && event.key === 'Enter') run();
|
||||
}} />
|
||||
</label>
|
||||
|
||||
<section class="pane output-pane">
|
||||
<span>Output</span>
|
||||
{#if error}
|
||||
<pre class="error">{error}</pre>
|
||||
{:else}
|
||||
<pre>{output}</pre>
|
||||
{/if}
|
||||
</section>
|
||||
</div>
|
||||
</section>
|
||||
@@ -0,0 +1,108 @@
|
||||
import { marked } from 'marked';
|
||||
|
||||
const modules = import.meta.glob('../../../../doc/manual/souce/**/*.md', {
|
||||
query: '?raw',
|
||||
import: 'default',
|
||||
eager: true,
|
||||
});
|
||||
|
||||
export const docs = Object.fromEntries(
|
||||
Object.entries(modules).map(([path, content]) => {
|
||||
const slug = path
|
||||
.replace(/^\.\.\/\.\.\/\.\.\/\.\.\/doc\/manual\/souce\//, '')
|
||||
.replace(/\.md$/, '')
|
||||
.replace(/\/index$/, '');
|
||||
return [slug || 'index', content];
|
||||
}),
|
||||
);
|
||||
|
||||
export const nav = [
|
||||
{ title: 'Introduction', slug: 'introduction' },
|
||||
{
|
||||
title: 'Language Specification',
|
||||
slug: 'language',
|
||||
children: [
|
||||
{ title: 'Syntax', slug: 'language/syntax' },
|
||||
{
|
||||
title: 'Value',
|
||||
slug: 'language/value',
|
||||
children: [
|
||||
{ title: 'String', slug: 'language/value/string' },
|
||||
{ title: 'Int', slug: 'language/value/int' },
|
||||
{ title: 'Float', slug: 'language/value/float' },
|
||||
{ title: 'Bool', slug: 'language/value/bool' },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Expression',
|
||||
slug: 'language/expression',
|
||||
children: [
|
||||
{ title: 'Literal', slug: 'language/expression/literal' },
|
||||
{ title: 'Identifier', slug: 'language/expression/identifier' },
|
||||
{ title: 'Path Reference', slug: 'language/expression/path-reference' },
|
||||
{ title: 'Object', slug: 'language/expression/object' },
|
||||
{ title: 'Array', slug: 'language/expression/array' },
|
||||
{ title: 'Function', slug: 'language/expression/function' },
|
||||
{ title: 'Function Call', slug: 'language/expression/function-call' },
|
||||
{ title: 'Let', slug: 'language/expression/let' },
|
||||
{ title: 'Match', slug: 'language/expression/match' },
|
||||
{ title: 'Import', slug: 'language/expression/import' },
|
||||
{ title: 'Composition', slug: 'language/expression/composition' },
|
||||
{ title: 'Default', slug: 'language/expression/default' },
|
||||
{ title: 'String Interpolation', slug: 'language/expression/string-interpolation' },
|
||||
],
|
||||
},
|
||||
{ title: 'Constraints and Defaults', slug: 'language/constraints-and-defaults' },
|
||||
{ title: 'Composition Operators', slug: 'language/operators' },
|
||||
{ title: 'Functions', slug: 'language/functions' },
|
||||
{ title: 'Modules and Imports', slug: 'language/modules-and-imports' },
|
||||
{ title: 'Evaluation Semantics', slug: 'language/evaluation' },
|
||||
{ title: 'Materialization and Errors', slug: 'language/materialization-and-errors' },
|
||||
{ title: 'Naming', slug: 'language/naming' },
|
||||
{ title: 'Examples', slug: 'language/examples' },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Implementation Design',
|
||||
slug: 'design',
|
||||
children: [
|
||||
{ title: 'Execution Pipeline', slug: 'design/execution-pipeline' },
|
||||
{ title: 'Runtime Model', slug: 'design/runtime-model' },
|
||||
{ title: 'Thunk and Lazy Evaluation', slug: 'design/thunk-and-lazy-evaluation' },
|
||||
{ title: 'Composition and Materialization', slug: 'design/composition-and-materialization' },
|
||||
{ title: 'Diagnostics and Fallback', slug: 'design/diagnostics-and-fallback' },
|
||||
{ title: 'Embedding API', slug: 'design/embedding-api' },
|
||||
{ title: 'Features', slug: 'design/features' },
|
||||
],
|
||||
},
|
||||
{ title: 'Development', slug: 'development' },
|
||||
{ title: 'Open Issues', slug: 'open-issues' },
|
||||
];
|
||||
|
||||
marked.setOptions({
|
||||
gfm: true,
|
||||
mangle: false,
|
||||
headerIds: true,
|
||||
});
|
||||
|
||||
export function renderMarkdown(slug) {
|
||||
const source = docs[slug] ?? docs.index;
|
||||
const html = marked.parse(source ?? '# Not found\n');
|
||||
return html.replace(/href="([^"#][^"]*)\.md(#[^"]*)?"/g, (_all, href, hash = '') => {
|
||||
const target = normalizeDocLink(slug, href);
|
||||
return `href="#/docs/${target}${hash}"`;
|
||||
});
|
||||
}
|
||||
|
||||
function normalizeDocLink(currentSlug, href) {
|
||||
const base = currentSlug.includes('/') ? currentSlug.split('/').slice(0, -1) : [];
|
||||
const parts = [...base, ...href.split('/')];
|
||||
const out = [];
|
||||
for (const part of parts) {
|
||||
if (!part || part === '.') continue;
|
||||
if (part === '..') out.pop();
|
||||
else out.push(part);
|
||||
}
|
||||
if (out[out.length - 1] === 'index') out.pop();
|
||||
return out.join('/') || 'index';
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import App from './App.svelte';
|
||||
import './style.css';
|
||||
|
||||
const app = new App({
|
||||
target: document.getElementById('app'),
|
||||
});
|
||||
|
||||
export default app;
|
||||
@@ -0,0 +1,232 @@
|
||||
:root {
|
||||
color-scheme: light dark;
|
||||
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
||||
background: #f7f7f8;
|
||||
color: #1f2328;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #2563eb;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.topbar {
|
||||
align-items: center;
|
||||
background: #111827;
|
||||
color: white;
|
||||
display: flex;
|
||||
height: 56px;
|
||||
justify-content: space-between;
|
||||
padding: 0 24px;
|
||||
}
|
||||
|
||||
.brand {
|
||||
color: white;
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.topnav {
|
||||
display: flex;
|
||||
gap: 18px;
|
||||
}
|
||||
|
||||
.topnav a {
|
||||
color: #dbeafe;
|
||||
}
|
||||
|
||||
.layout {
|
||||
display: grid;
|
||||
grid-template-columns: 300px minmax(0, 1fr);
|
||||
min-height: calc(100vh - 56px);
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
background: #ffffff;
|
||||
border-right: 1px solid #e5e7eb;
|
||||
overflow: auto;
|
||||
padding: 22px 18px;
|
||||
}
|
||||
|
||||
.sidebar-title {
|
||||
color: #111827;
|
||||
display: block;
|
||||
font-weight: 700;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.nav-tree {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding-left: 0;
|
||||
}
|
||||
|
||||
.nav-tree .nav-tree {
|
||||
margin: 4px 0 6px 12px;
|
||||
}
|
||||
|
||||
.nav-tree a {
|
||||
border-radius: 6px;
|
||||
color: #374151;
|
||||
display: block;
|
||||
font-size: 14px;
|
||||
line-height: 1.35;
|
||||
padding: 4px 8px;
|
||||
}
|
||||
|
||||
.nav-tree a.active {
|
||||
background: #dbeafe;
|
||||
color: #1d4ed8;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
main {
|
||||
min-width: 0;
|
||||
padding: 36px;
|
||||
}
|
||||
|
||||
main.playground {
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.markdown {
|
||||
background: white;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 8px 24px rgb(15 23 42 / 0.05);
|
||||
margin: 0 auto;
|
||||
max-width: 920px;
|
||||
padding: 24px 36px 42px;
|
||||
}
|
||||
|
||||
.markdown h1,
|
||||
.markdown h2,
|
||||
.markdown h3 {
|
||||
color: #111827;
|
||||
}
|
||||
|
||||
.markdown pre,
|
||||
.pane pre {
|
||||
background: #0f172a;
|
||||
border-radius: 10px;
|
||||
color: #e5e7eb;
|
||||
overflow: auto;
|
||||
padding: 14px;
|
||||
}
|
||||
|
||||
.markdown code {
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
|
||||
}
|
||||
|
||||
.markdown :not(pre) > code {
|
||||
background: #eef2ff;
|
||||
border-radius: 4px;
|
||||
color: #3730a3;
|
||||
padding: 1px 4px;
|
||||
}
|
||||
|
||||
.playground-page {
|
||||
height: calc(100vh - 104px);
|
||||
}
|
||||
|
||||
.playground-header {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
.playground-header h1 {
|
||||
margin: 0 0 4px;
|
||||
}
|
||||
|
||||
.playground-header p {
|
||||
color: #4b5563;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
button {
|
||||
background: #2563eb;
|
||||
border: 0;
|
||||
border-radius: 8px;
|
||||
color: white;
|
||||
cursor: pointer;
|
||||
font-weight: 700;
|
||||
padding: 10px 18px;
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.playground-grid {
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
|
||||
height: calc(100% - 82px);
|
||||
}
|
||||
|
||||
.pane {
|
||||
background: white;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.pane > span {
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
color: #374151;
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
padding: 10px 12px;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
textarea {
|
||||
border: 0;
|
||||
flex: 1;
|
||||
font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
|
||||
outline: none;
|
||||
padding: 14px;
|
||||
resize: none;
|
||||
}
|
||||
|
||||
.output-pane pre {
|
||||
border-radius: 0;
|
||||
flex: 1;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.output-pane pre.error {
|
||||
color: #fecaca;
|
||||
}
|
||||
|
||||
.status {
|
||||
color: #4b5563;
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.layout {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
.sidebar {
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
border-right: 0;
|
||||
max-height: 260px;
|
||||
}
|
||||
.playground-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
# wasm-pack output is committed for the playground build.
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
|
||||
export function evaluate(source: string): string;
|
||||
|
||||
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
||||
|
||||
export interface InitOutput {
|
||||
readonly memory: WebAssembly.Memory;
|
||||
readonly evaluate: (a: number, b: number, c: number) => void;
|
||||
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
||||
readonly __wbindgen_export: (a: number, b: number) => number;
|
||||
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
||||
readonly __wbindgen_export3: (a: number, b: number, c: number) => void;
|
||||
}
|
||||
|
||||
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
||||
|
||||
/**
|
||||
* Instantiates the given `module`, which can either be bytes or
|
||||
* a precompiled `WebAssembly.Module`.
|
||||
*
|
||||
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
||||
*
|
||||
* @returns {InitOutput}
|
||||
*/
|
||||
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
||||
|
||||
/**
|
||||
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
||||
* for everything else, calls `WebAssembly.instantiate` directly.
|
||||
*
|
||||
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
||||
*
|
||||
* @returns {Promise<InitOutput>}
|
||||
*/
|
||||
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
||||
@@ -0,0 +1,212 @@
|
||||
/* @ts-self-types="./decodal_wasm.d.ts" */
|
||||
|
||||
/**
|
||||
* @param {string} source
|
||||
* @returns {string}
|
||||
*/
|
||||
export function evaluate(source) {
|
||||
let deferred2_0;
|
||||
let deferred2_1;
|
||||
try {
|
||||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
||||
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
wasm.evaluate(retptr, ptr0, len0);
|
||||
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
||||
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
||||
deferred2_0 = r0;
|
||||
deferred2_1 = r1;
|
||||
return getStringFromWasm0(r0, r1);
|
||||
} finally {
|
||||
wasm.__wbindgen_add_to_stack_pointer(16);
|
||||
wasm.__wbindgen_export3(deferred2_0, deferred2_1, 1);
|
||||
}
|
||||
}
|
||||
function __wbg_get_imports() {
|
||||
const import0 = {
|
||||
__proto__: null,
|
||||
};
|
||||
return {
|
||||
__proto__: null,
|
||||
"./decodal_wasm_bg.js": import0,
|
||||
};
|
||||
}
|
||||
|
||||
let cachedDataViewMemory0 = null;
|
||||
function getDataViewMemory0() {
|
||||
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
||||
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
||||
}
|
||||
return cachedDataViewMemory0;
|
||||
}
|
||||
|
||||
function getStringFromWasm0(ptr, len) {
|
||||
return decodeText(ptr >>> 0, len);
|
||||
}
|
||||
|
||||
let cachedUint8ArrayMemory0 = null;
|
||||
function getUint8ArrayMemory0() {
|
||||
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
||||
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
||||
}
|
||||
return cachedUint8ArrayMemory0;
|
||||
}
|
||||
|
||||
function passStringToWasm0(arg, malloc, realloc) {
|
||||
if (realloc === undefined) {
|
||||
const buf = cachedTextEncoder.encode(arg);
|
||||
const ptr = malloc(buf.length, 1) >>> 0;
|
||||
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
||||
WASM_VECTOR_LEN = buf.length;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
let len = arg.length;
|
||||
let ptr = malloc(len, 1) >>> 0;
|
||||
|
||||
const mem = getUint8ArrayMemory0();
|
||||
|
||||
let offset = 0;
|
||||
|
||||
for (; offset < len; offset++) {
|
||||
const code = arg.charCodeAt(offset);
|
||||
if (code > 0x7F) break;
|
||||
mem[ptr + offset] = code;
|
||||
}
|
||||
if (offset !== len) {
|
||||
if (offset !== 0) {
|
||||
arg = arg.slice(offset);
|
||||
}
|
||||
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
||||
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
||||
const ret = cachedTextEncoder.encodeInto(arg, view);
|
||||
|
||||
offset += ret.written;
|
||||
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
||||
}
|
||||
|
||||
WASM_VECTOR_LEN = offset;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
||||
cachedTextDecoder.decode();
|
||||
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
||||
let numBytesDecoded = 0;
|
||||
function decodeText(ptr, len) {
|
||||
numBytesDecoded += len;
|
||||
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
||||
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
||||
cachedTextDecoder.decode();
|
||||
numBytesDecoded = len;
|
||||
}
|
||||
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
||||
}
|
||||
|
||||
const cachedTextEncoder = new TextEncoder();
|
||||
|
||||
if (!('encodeInto' in cachedTextEncoder)) {
|
||||
cachedTextEncoder.encodeInto = function (arg, view) {
|
||||
const buf = cachedTextEncoder.encode(arg);
|
||||
view.set(buf);
|
||||
return {
|
||||
read: arg.length,
|
||||
written: buf.length
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
let WASM_VECTOR_LEN = 0;
|
||||
|
||||
let wasmModule, wasmInstance, wasm;
|
||||
function __wbg_finalize_init(instance, module) {
|
||||
wasmInstance = instance;
|
||||
wasm = instance.exports;
|
||||
wasmModule = module;
|
||||
cachedDataViewMemory0 = null;
|
||||
cachedUint8ArrayMemory0 = null;
|
||||
return wasm;
|
||||
}
|
||||
|
||||
async function __wbg_load(module, imports) {
|
||||
if (typeof Response === 'function' && module instanceof Response) {
|
||||
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
||||
try {
|
||||
return await WebAssembly.instantiateStreaming(module, imports);
|
||||
} catch (e) {
|
||||
const validResponse = module.ok && expectedResponseType(module.type);
|
||||
|
||||
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
||||
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
||||
|
||||
} else { throw e; }
|
||||
}
|
||||
}
|
||||
|
||||
const bytes = await module.arrayBuffer();
|
||||
return await WebAssembly.instantiate(bytes, imports);
|
||||
} else {
|
||||
const instance = await WebAssembly.instantiate(module, imports);
|
||||
|
||||
if (instance instanceof WebAssembly.Instance) {
|
||||
return { instance, module };
|
||||
} else {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
function expectedResponseType(type) {
|
||||
switch (type) {
|
||||
case 'basic': case 'cors': case 'default': return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function initSync(module) {
|
||||
if (wasm !== undefined) return wasm;
|
||||
|
||||
|
||||
if (module !== undefined) {
|
||||
if (Object.getPrototypeOf(module) === Object.prototype) {
|
||||
({module} = module)
|
||||
} else {
|
||||
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
||||
}
|
||||
}
|
||||
|
||||
const imports = __wbg_get_imports();
|
||||
if (!(module instanceof WebAssembly.Module)) {
|
||||
module = new WebAssembly.Module(module);
|
||||
}
|
||||
const instance = new WebAssembly.Instance(module, imports);
|
||||
return __wbg_finalize_init(instance, module);
|
||||
}
|
||||
|
||||
async function __wbg_init(module_or_path) {
|
||||
if (wasm !== undefined) return wasm;
|
||||
|
||||
|
||||
if (module_or_path !== undefined) {
|
||||
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
||||
({module_or_path} = module_or_path)
|
||||
} else {
|
||||
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
||||
}
|
||||
}
|
||||
|
||||
if (module_or_path === undefined) {
|
||||
module_or_path = new URL('decodal_wasm_bg.wasm', import.meta.url);
|
||||
}
|
||||
const imports = __wbg_get_imports();
|
||||
|
||||
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
||||
module_or_path = fetch(module_or_path);
|
||||
}
|
||||
|
||||
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
||||
|
||||
return __wbg_finalize_init(instance, module);
|
||||
}
|
||||
|
||||
export { initSync, __wbg_init as default };
|
||||
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
export const memory: WebAssembly.Memory;
|
||||
export const evaluate: (a: number, b: number, c: number) => void;
|
||||
export const __wbindgen_add_to_stack_pointer: (a: number) => number;
|
||||
export const __wbindgen_export: (a: number, b: number) => number;
|
||||
export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
||||
export const __wbindgen_export3: (a: number, b: number, c: number) => void;
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "decodal-wasm",
|
||||
"type": "module",
|
||||
"version": "0.1.0",
|
||||
"files": [
|
||||
"decodal_wasm_bg.wasm",
|
||||
"decodal_wasm.js",
|
||||
"decodal_wasm.d.ts"
|
||||
],
|
||||
"main": "decodal_wasm.js",
|
||||
"types": "decodal_wasm.d.ts",
|
||||
"sideEffects": [
|
||||
"./snippets/*"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user