claude-artifact-framework 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +96 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# claude-artifact-framework
|
|
2
|
+
|
|
3
|
+
Utilities for building apps inside Claude Artifacts: platform storage, reactive
|
|
4
|
+
state, and other primitives verified against the real runtime. Zero
|
|
5
|
+
dependencies, no build step — drop it into an artifact straight from a CDN.
|
|
6
|
+
|
|
7
|
+
## Usage via CDN
|
|
8
|
+
|
|
9
|
+
Everything is served through [jsDelivr](https://www.jsdelivr.com/), which
|
|
10
|
+
mirrors npm packages automatically.
|
|
11
|
+
|
|
12
|
+
### As a global script (`<script>` tag)
|
|
13
|
+
|
|
14
|
+
```html
|
|
15
|
+
<script src="https://cdn.jsdelivr.net/npm/claude-artifact-framework@0.2.0/dist/index.global.js"></script>
|
|
16
|
+
<script>
|
|
17
|
+
const { storage, createStore, createPersistedStore, createSharedStore } = ArtifactKit;
|
|
18
|
+
</script>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### As an ES module
|
|
22
|
+
|
|
23
|
+
```html
|
|
24
|
+
<script type="module">
|
|
25
|
+
import {
|
|
26
|
+
storage,
|
|
27
|
+
createStore,
|
|
28
|
+
createPersistedStore,
|
|
29
|
+
createSharedStore,
|
|
30
|
+
} from "https://cdn.jsdelivr.net/npm/claude-artifact-framework@0.2.0/dist/index.esm.js";
|
|
31
|
+
</script>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Pin a version (`@0.2.0`) for reproducible artifacts, or drop the version
|
|
35
|
+
(`claude-artifact-framework/dist/...`) to always get the latest release.
|
|
36
|
+
|
|
37
|
+
## `storage`
|
|
38
|
+
|
|
39
|
+
Thin wrapper over `window.storage`, the persistence API Claude injects into a
|
|
40
|
+
**published** Chat Artifact. Values are JSON-serialized for you. Two scopes:
|
|
41
|
+
personal (`storage.*`, one copy per viewer) and shared (`storage.shared.*`,
|
|
42
|
+
one copy for every viewer of the artifact).
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
await storage.set("theme", "dark");
|
|
46
|
+
await storage.get("theme", "light"); // "dark" — second arg is the fallback
|
|
47
|
+
await storage.list(); // ["theme", ...]
|
|
48
|
+
await storage.delete("theme");
|
|
49
|
+
|
|
50
|
+
await storage.shared.set("board", { count: 0 });
|
|
51
|
+
await storage.shared.get("board", null);
|
|
52
|
+
|
|
53
|
+
storage.available(); // false in draft mode / outside a Chat Artifact
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## `createStore(initialState)`
|
|
57
|
+
|
|
58
|
+
In-memory reactive store. No persistence.
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
const counter = createStore(0);
|
|
62
|
+
counter.subscribe((value) => console.log("count is now", value));
|
|
63
|
+
counter.set((n) => n + 1);
|
|
64
|
+
counter.get(); // 1
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## `createPersistedStore(key, initialState, options?)`
|
|
68
|
+
|
|
69
|
+
Same as `createStore`, but loads from `storage` once on creation and saves
|
|
70
|
+
(debounced) on every change. Personal scope only.
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
const prefs = createPersistedStore("prefs", { theme: "light" });
|
|
74
|
+
await prefs.ready; // resolves once the initial load finishes
|
|
75
|
+
prefs.set({ theme: "dark" }); // persisted automatically
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
`options.debounceMs` (default `300`) controls how long to wait after the last
|
|
79
|
+
change before writing to storage.
|
|
80
|
+
|
|
81
|
+
## `createSharedStore(key, initialState, options?)`
|
|
82
|
+
|
|
83
|
+
Same as `createPersistedStore`, but backed by `storage.shared` and polled on
|
|
84
|
+
an interval, so every viewer of a published artifact converges on the same
|
|
85
|
+
state.
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
const board = createSharedStore("board", { count: 0 }, { pollMs: 2000 });
|
|
89
|
+
await board.ready;
|
|
90
|
+
board.set({ count: board.get().count + 1 }); // pushed to every viewer
|
|
91
|
+
board.stop(); // stop polling, e.g. on teardown
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Conflict handling is last-write-wins: if two viewers change the same key
|
|
95
|
+
within one poll window, whichever write reaches storage last overwrites the
|
|
96
|
+
other. There is no merge/CRDT logic.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-artifact-framework",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Utilities for building apps inside Claude Artifacts: platform storage, chat tool-calling loops, and other primitives verified against the real runtime.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.esm.js",
|