sketchmark 0.1.6 → 0.1.7

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.
@@ -5244,89 +5244,6 @@ var AIDiagram = (function (exports) {
5244
5244
  }
5245
5245
  }
5246
5246
 
5247
- // ============================================================
5248
- // sketchmark — Encrypted sharing
5249
- // Diagram DSL is encrypted in the browser.
5250
- // The server stores an opaque blob it cannot read.
5251
- // The decryption key lives only in the URL fragment (#key=...).
5252
- // ============================================================
5253
- const WORKER_URL = 'https://sketchmark.anmism.workers.dev';
5254
- // ── Crypto helpers ────────────────────────────────────────
5255
- async function generateKey() {
5256
- return crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, true, // extractable so we can export to URL
5257
- ['encrypt', 'decrypt']);
5258
- }
5259
- async function keyToBase64(key) {
5260
- const raw = await crypto.subtle.exportKey('raw', key);
5261
- return btoa(String.fromCharCode(...new Uint8Array(raw)));
5262
- }
5263
- async function base64ToKey(b64) {
5264
- const raw = Uint8Array.from(atob(b64), c => c.charCodeAt(0));
5265
- return crypto.subtle.importKey('raw', raw, { name: 'AES-GCM' }, false, // not extractable on the receiving end
5266
- ['decrypt']);
5267
- }
5268
- // ── Encrypt ───────────────────────────────────────────────
5269
- async function encryptDSL(dsl, key) {
5270
- const iv = crypto.getRandomValues(new Uint8Array(12));
5271
- const encoded = new TextEncoder().encode(dsl);
5272
- const encrypted = await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, key, encoded);
5273
- // prepend iv to the blob: [ iv (12 bytes) | ciphertext ]
5274
- const result = new Uint8Array(12 + encrypted.byteLength);
5275
- result.set(iv, 0);
5276
- result.set(new Uint8Array(encrypted), 12);
5277
- return result;
5278
- }
5279
- // ── Decrypt ───────────────────────────────────────────────
5280
- async function decryptBlob(blob, key) {
5281
- const iv = blob.slice(0, 12);
5282
- const ciphertext = blob.slice(12);
5283
- const decrypted = await crypto.subtle.decrypt({ name: 'AES-GCM', iv }, key, ciphertext);
5284
- return new TextDecoder().decode(decrypted);
5285
- }
5286
- // ── Public API ────────────────────────────────────────────
5287
- /**
5288
- * Encrypt DSL, upload to worker, return shareable URL.
5289
- * The URL fragment (#key=...) never reaches the server.
5290
- */
5291
- async function shareDiagram(dsl) {
5292
- const key = await generateKey();
5293
- const blob = await encryptDSL(dsl, key);
5294
- const keyB64 = await keyToBase64(key);
5295
- const res = await fetch(`${WORKER_URL}/api/blob`, {
5296
- method: 'POST',
5297
- headers: { 'Content-Type': 'application/octet-stream' },
5298
- body: blob.buffer,
5299
- });
5300
- if (!res.ok)
5301
- throw new Error(`Upload failed: ${res.status}`);
5302
- const { id } = await res.json();
5303
- // key goes into the fragment — browser never sends this to any server
5304
- return `${window.location.origin}/sketchmark/playground.html?s=${id}#key=${keyB64}`;
5305
- }
5306
- /**
5307
- * Read ?s= and #key= from the current URL, fetch + decrypt the diagram.
5308
- * Returns null if no share params found.
5309
- */
5310
- async function loadSharedDiagram() {
5311
- const params = new URLSearchParams(window.location.search);
5312
- const id = params.get('s');
5313
- if (!id)
5314
- return null;
5315
- // key is in the fragment — parse manually, not via URLSearchParams
5316
- // (URLSearchParams on hash strips the #)
5317
- const fragment = window.location.hash.slice(1);
5318
- const keyMatch = fragment.match(/key=([^&]+)/);
5319
- if (!keyMatch)
5320
- return null;
5321
- const keyB64 = keyMatch[1];
5322
- const res = await fetch(`${WORKER_URL}/api/blob/${id}`);
5323
- if (!res.ok)
5324
- throw new Error('Diagram not found or expired');
5325
- const blob = await res.arrayBuffer();
5326
- const key = await base64ToKey(keyB64);
5327
- return decryptBlob(blob, key);
5328
- }
5329
-
5330
5247
  // ============================================================
5331
5248
  // sketchmark — Public API
5332
5249
  // ============================================================
@@ -5418,7 +5335,6 @@ var AIDiagram = (function (exports) {
5418
5335
  exports.lerp = lerp;
5419
5336
  exports.listThemes = listThemes;
5420
5337
  exports.loadFont = loadFont;
5421
- exports.loadSharedDiagram = loadSharedDiagram;
5422
5338
  exports.markdownMap = markdownMap;
5423
5339
  exports.nodeMap = nodeMap;
5424
5340
  exports.parse = parse;
@@ -5429,7 +5345,6 @@ var AIDiagram = (function (exports) {
5429
5345
  exports.renderToSVG = renderToSVG;
5430
5346
  exports.resolveFont = resolveFont;
5431
5347
  exports.resolvePalette = resolvePalette;
5432
- exports.shareDiagram = shareDiagram;
5433
5348
  exports.sleep = sleep;
5434
5349
  exports.svgToPNGDataURL = svgToPNGDataURL;
5435
5350
  exports.svgToString = svgToString;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "sketchmark",
3
- "version": "0.1.6",
4
- "description": "Convert AI-friendly DSL text into beautiful hand-drawn diagrams using rough.js. Supports SVG, Canvas, animations, and export.",
3
+ "version": "0.1.7",
4
+ "description": "A plain-text DSL for hand-drawn diagrams. Write boxes, edges, and groups as code — renders sketchy SVG/Canvas via rough.js with a built-in step-by-step animation system.",
5
5
  "keywords": [
6
6
  "diagram",
7
7
  "dsl",