Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
0918nobita committed May 11, 2024
1 parent 5669be3 commit 2fdadf3
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/code-block-processor/code-block.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<script lang="ts">
import { onMount } from 'svelte';
import { type Segment, splitSentenceIntoSegments } from './split-sentence';
import * as styles from './style.css';
export let source: string;
let segments: Segment[] = [];
onMount(() => {
segments = splitSentenceIntoSegments(source.trim());
});
</script>

<div lang="zh-CN" class={styles.container}>
<div aria-hidden="true" class={styles.pinyinLine}>
<!-- hidden blocks -->
</div>
<div class={styles.zhCharLine}>
{#each segments as segment}
{#if segment.type === 'zh'}
<!-- zh blocks -->
{segment.zhChars}
{:else}
<span class={styles.visibleNonZhBlock}>{segment.nonZhChars}</span>
{/if}
{/each}
</div>
</div>
12 changes: 12 additions & 0 deletions src/playground.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { type HanziWriterOptions, default as HW } from 'hanzi-writer';

import CodeBlock from './code-block-processor/code-block.svelte';

const hwOptions: Partial<HanziWriterOptions> = {
width: 100,
height: 100,
Expand Down Expand Up @@ -31,3 +33,13 @@ btn.addEventListener('click', async () => {

await c2Writer.animateCharacter();
});

const app = document.createElement('div');
document.body.appendChild(app);

new CodeBlock({
target: app,
props: {
source: '你好!初次见面',
},
});
8 changes: 8 additions & 0 deletions svelte.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";

/** @type {import('@sveltejs/vite-plugin-svelte').Options} */
const config = {
preprocess: vitePreprocess(),
};

export default config;
3 changes: 3 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { svelte } from '@sveltejs/vite-plugin-svelte';
import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';
import { defineConfig } from 'vite';

Expand All @@ -20,6 +21,8 @@ export default defineConfig({
},
},
plugins: [
svelte(),

vanillaExtractPlugin({
identifiers: ({ hash }) => `zhongwenBlock_${hash}`,
}),
Expand Down

0 comments on commit 2fdadf3

Please sign in to comment.