Skip to content

Commit

Permalink
dev(proj): chore fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin committed Nov 4, 2023
1 parent cfa47d5 commit 862c20e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
32 changes: 12 additions & 20 deletions projects/cetz-editor/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Cetz Editor</title>
<script>
window.script$jsYamlLoad = new Promise(resolve => {
window.script$jsYamlLoadResolve = resolve;
});
</script>
<script id="script-main" type="module" src="/dist/esm/index.mjs"></script>
<link rel="stylesheet" href="typst-style.css" />
<script src="https://cdn.jsdelivr.net/npm/monaco-editor@0.33.0/dev/vs/loader.min.js"></script>
Expand Down Expand Up @@ -40,19 +35,16 @@
<span>from</span>
<div class="flex-row" style="display: inline-flex; justify-content:
space-around; gap: 5px">
<select id="definition-source-selector"
class="editor-code-select" style="width: 5em;">
<select id="definition-source-selector" class="editor-code-select" style="width: 5em;">
<option value="builtin">Builtin</option>
<option value="url">Url</option>
<option value="file">File</option>
</select>
<input id="definition-source-value"
class="editor-input-box" type="text"
placeholder="https://..." />
<button id="definition-source-confirm"
class="editor-input-button">Pull</button>
</div>
<input id="definition-source-value" class="editor-input-box" type="text"
placeholder="https://..." />
<button id="definition-source-confirm" class="editor-input-button">Pull</button>
</div>
</div>
<div class="editor-action-group">
<span>element:</span>
<div class="flex-row" style="display: inline-flex; justify-content:
Expand Down Expand Up @@ -144,14 +136,14 @@
language: 'typst',
theme: 'tokyo-night',
'semanticHighlighting.enabled': true,
"bracketPairColorization.enabled": true,
"bracketPairColorization.enabled": true,
});
const mainEditor = monaco.editor.create(document.getElementById('main-editor'), {
value: '',
language: 'typst',
theme: 'tokyo-night',
'semanticHighlighting.enabled': true,
"bracketPairColorization.enabled": true,
"bracketPairColorization.enabled": true,
});
$preview.bindElement(document.getElementById('preview-panel'), v => mainEditor.setValue(v));
document.getElementById('export-svg').addEventListener('click', () => {
Expand Down Expand Up @@ -288,8 +280,8 @@
line(start, end, name: "t", mark: mark)
content("t", inner-text)
}`;
definitionEditor.setValue(builtinDefinitions);
mainEditor.setValue(`#{
definitionEditor.setValue(builtinDefinitions);
mainEditor.setValue(`#{
make-ins("c0", (0, 0), "x-circle", (rad: 50))
make-ins("c1", (50, 50), "x-rect", (x: 100))
make-ins("c2", (200, 0), "x-circle", (rad: 50))
Expand All @@ -302,8 +294,8 @@
triggerSyncMain();

previewSelector.onchange = () => {
console.log('previewSelector.value', previewSelector.value);
$preview.doSelectDef(previewSelector.value);
console.log('previewSelector.value', previewSelector.value);
$preview.doSelectDef(previewSelector.value);
};

$preview.doSelectDef('');
Expand All @@ -312,7 +304,7 @@
definitionSourceSelector.onchange = () => {
if (definitionSourceSelector.value === 'builtin' || definitionSourceSelector.value === 'file') {
checkDefinitionSource();
}
}
};
});
};
Expand Down
5 changes: 4 additions & 1 deletion projects/cetz-editor/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@myriaddreamin/cetz-editor",
"private": true,
"version": "0.4.0",
"version": "0.4.1-rc1",
"description": "Simple visualized cetz editor",
"author": "Myriad Dreamin <camiyoru@gmail.com>",
"license": "Apache-2.0",
Expand All @@ -21,6 +21,9 @@
"@myriaddreamin/typst-ts-web-compiler": "*"
},
"devDependencies": {
"@myriaddreamin/typst.ts": "*",
"@myriaddreamin/typst-ts-renderer": "*",
"@myriaddreamin/typst-ts-web-compiler": "*",
"vite": "^4.3.9",
"vite-plugin-singlefile": "^0.13.5",
"vitest": "^0.32.2"
Expand Down
14 changes: 8 additions & 6 deletions projects/cetz-editor/src/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -682,9 +682,11 @@ import cetz.draw: *
let args = '';
const argEntries = Object.entries(ins.args ?? {});
if (argEntries.length) {
args = ' args:';
for (const [k, v] of argEntries) {
args += `\n ${k}: ${v}`;
if (args) {
args += ', ';
}
args += `${k}: ${v}`;
}
}
let [x, y] = ins.pos;
Expand All @@ -696,7 +698,7 @@ import cetz.draw: *
// [${x}, ${y}]`);
x = Math.round(x * 1000) / 1000;
y = Math.round(y * 1000) / 1000;
data.push(`make-ins("${ins.name}", (${x}, ${y}), ${ins.type}, (${args}))`);
data.push(`make-ins("${ins.name}", (${x}, ${y}), "${ins.type}", (${args}))`);
}
this.updateMainContent(`#{
${data.join(INEW_LINE)}
Expand Down Expand Up @@ -971,7 +973,7 @@ import cetz.draw: *

let j = skipIdent(i);
if (i === j) {
throw new Error(`expected ident at ${i}`);
throw new Error(`expected ident at ${i} ${s.slice(i)}`);
}

const ident = s.slice(i, j);
Expand Down Expand Up @@ -1083,7 +1085,7 @@ import cetz.draw: *
}

function parseMainContent() {
// console.log('parseMainContent', s);
console.log('parseMainContent', s);
const instances: any[] = [];
let i = 0;
i = eatToken(skipSpaces(i), '#');
Expand Down Expand Up @@ -1111,7 +1113,7 @@ import cetz.draw: *
}
j = skipIdent(i);
if (i === j) {
throw new Error(`expected ident at ${i}`);
throw new Error(`expected ident at ${i} ${s.slice(i)}`);
}
let ident = s.slice(i, j);
i = skipSpaces(j);
Expand Down

0 comments on commit 862c20e

Please sign in to comment.