@craft-native/svelte

中文文档
0.0.413发布于 2026/11/01MITTypeScriptESM + CJS零依赖构建来源已验证

Svelte bindings for Craft framework

原始使用文档
文档目录10 节
  1. Installation
  2. Usage
  3. Stores
  4. Window Management
  5. Haptic Action
  6. Toast
  7. File System
  8. Database
  9. HTTP
  10. License

@craft-native/svelte

Svelte bindings for the Craft framework using stores and actions.

Installation

npm install @craft-native/svelte

The package includes its TypeScript source for bundlers that select the svelte export condition. Other consumers use the compiled ESM or CommonJS entry in dist. Both entries expose the same stores and actions.

Usage

Stores

<script>
  import { craft, isReady, platform } from '@craft-native/svelte';
</script>

{#if $isReady}
  <p>Platform: {$platform?.platform}</p>
{/if}

Window Management

<script>
  import { windowActions, isFullscreen } from '@craft-native/svelte';
</script>

<button on:click={windowActions.maximize}>Maximize</button>
<button on:click={windowActions.toggleFullscreen}>
  {$isFullscreen ? 'Exit' : 'Enter'} Fullscreen
</button>

Haptic Action

<script>
  import { haptic } from '@craft-native/svelte';
</script>

<button use:haptic={'impact_medium'}>Tap Me</button>

Toast

<script>
  import { showToast } from '@craft-native/svelte';
</script>

<button on:click={() => showToast('Hello!')}>Show Toast</button>

File System

<script>
  import { filesystem } from '@craft-native/svelte';

  let content = '';

  async function load() {
    content = await filesystem.readFile('/path/to/file.txt');
  }

  async function save() {
    await filesystem.writeFile('/path/to/file.txt', content);
  }
</script>

<textarea bind:value={content} />
<button on:click={load}>Load</button>
<button on:click={save}>Save</button>

Database

<script>
  import { onMount } from 'svelte';
  import { createDatabase } from '@craft-native/svelte';

  const db = createDatabase('/path/to/db.sqlite');
  let todos = [];

  onMount(async () => {
    todos = await db.query('SELECT * FROM todos');
  });
</script>

<ul>
  {#each todos as todo}
    <li>{todo.title}</li>
  {/each}
</ul>

HTTP

<script>
  import { http } from '@craft-native/svelte';

  let data = null;

  async function loadData() {
    data = await http.fetch('https://api.example.com/data');
  }
</script>

<button on:click={loadData}>Load Data</button>
{#if data}
  <pre>{JSON.stringify(data, null, 2)}</pre>
{/if}

License

MIT

版本与发布记录

@craft-native/svelte 共发布 212 个版本,首次发布于 2026/08/23;过去 12 个月发布了 212 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.0.413latest2026/11/012 天前
0.0.4112026/10/312 天前
0.0.4102026/10/312 天前
0.0.4092026/10/313 天前
0.0.4082026/10/313 天前
0.0.3962026/10/313 天前

关于 @craft-native/svelte 的常见问题

@craft-native/svelte 是什么?

用于Craft框架的细长绑定

如何安装 @craft-native/svelte?

在项目目录运行 npm install @craft-native/svelte,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:svelte(^3.0.0 || ^4.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@craft-native/svelte 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@craft-native/svelte 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@craft-native/svelte 可以商用吗?

@craft-native/svelte 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@craft-native/svelte 还在维护吗?

最新版本 0.0.413 发布于 2026/11/01(2 天前);至今共发布 212 个版本,其中过去 12 个月发布了 212 个;首次发布于 2026/08/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。