@dvina/widget-kit 0.0.33 → 0.0.34

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.
@@ -0,0 +1 @@
1
+ "use strict";(()=>{var A=/^[A-Za-z0-9_.:-]{1,128}$/;function x(o,t){if(typeof t!="string"||!A.test(t))throw new Error(`A ${o} is 1\u2013128 letters, digits or . _ : - ("${String(t)}" is not).`)}function J(o,t){return o===t?0:o==null?1:t==null||o<t?-1:1}function T(o,t){let i=null,s=null,l=[],f=0,p=!1,a=new Set,c=()=>a.forEach(n=>n());function u(n=!1){return i&&!n?Promise.resolve(i):(s&&!n||(s=o.read().then(d=>{s=null,i={version:d.version,collections:structuredClone(d.collections)};for(let{op:r}of l)v(r);return c(),i},d=>{throw s=null,d})),s)}function v(n){var r,e;if(!i)return;let d=(r=i.collections)[e=n.collection]??(r[e]={});n.op==="delete"?delete d[n.id]:n.op==="set"?d[n.id]=structuredClone(n.doc??{}):d[n.id]={...d[n.id]??{},...structuredClone(n.doc??{})}}async function b(){var d;if(f=0,p||l.length===0)return;p=!0;let n=l;l=[];try{let r=await o.apply(n.map(({op:e})=>e));if(i){i.version=r.version;for(let{collection:e,id:g,doc:y}of r.changed){let m=(d=i.collections)[e]??(d[e]={});y===null?delete m[g]:m[g]=y}for(let{op:e}of l)v(e)}n.forEach(({settle:e})=>e()),c()}catch(r){let e=r instanceof Error?r:new Error(String(r));n.forEach(({settle:g})=>g(e)),t(e),await u(!0).catch(()=>{})}finally{p=!1,l.length&&E()}}function E(){f||(f=window.setTimeout(()=>void b(),300))}async function C(n){return x("collection",n.collection),x("document id",n.id),await u(),new Promise((d,r)=>{v(n),l.push({op:n,settle:e=>e?r(e):d()}),c(),E()})}return{load:u,refresh(){i&&!p&&l.length===0&&u(!0).catch(()=>{})},collection(n){x("collection",n);let d=()=>i?.collections[n]??{};return Object.freeze({async get(r){await u();let e=d()[r];return e?{...structuredClone(e),id:r}:null},async list(r={}){await u();let e=Object.entries(d()).map(([h,S])=>({...structuredClone(S),id:h})),{where:g,orderBy:y,limit:m}=r;if(typeof g=="function"?e=e.filter(g):g&&(e=e.filter(h=>Object.entries(g).every(([S,D])=>h[S]===D))),y){let[h,S]=Array.isArray(y)?y:[y,"asc"];e.sort((D,_)=>J(D[h],_[h])*(S==="desc"?-1:1))}return typeof m=="number"?e.slice(0,Math.max(0,m)):e},set:(r,e)=>C({op:"set",collection:n,id:r,doc:e}),update:(r,e)=>C({op:"update",collection:n,id:r,doc:e}),delete:r=>C({op:"delete",collection:n,id:r}),subscribe(r){return a.add(r),()=>a.delete(r)}})}}}var k="_kv";function O(o,t=()=>{}){let i=T(o,t),s=()=>i.refresh();window.addEventListener("focus",s),document.addEventListener("visibilitychange",()=>document.visibilityState==="visible"&&s());let l=Object.freeze({collection:a=>i.collection(a)}),f=()=>i.collection(k),p=Object.freeze({async get(a){return(await f().get(a))?.value},set:(a,c)=>f().set(a,{value:c}),delete:a=>f().delete(a),async list(a={}){return(await f().list()).map(u=>u.id).filter(u=>!a.prefix||u.startsWith(a.prefix))}});return{db:l,storage:p}}var V="dvina-seed",W="dvina:file:",w=o=>typeof o=="object"&&o!==null&&!Array.isArray(o);function L(o=document){try{let t=JSON.parse(o.getElementById(V)?.textContent??"null");return!w(t)||typeof t.fileId!="string"||!w(t.collections)?null:{fileId:t.fileId,artifactId:typeof t.artifactId=="string"?t.artifactId:void 0,version:typeof t.version=="number"?t.version:0,collections:t.collections}}catch{return null}}function R(){try{return window.localStorage}catch{return null}}function I(o,t){try{let i=JSON.parse(o?.getItem(t)??"null");return w(i)&&typeof i.version=="number"&&w(i.collections)?i:null}catch{return null}}function j(o,t){let i=R(),s=I(i,t)??{version:o?.version??0,collections:structuredClone(o?.collections??{})};function l(){try{i?.setItem(t,JSON.stringify(s))}catch{}}let f=()=>s=I(i,t)??s;return{read:async()=>structuredClone(f()),apply:async p=>{f();let a=p.map(c=>{var v,b;let u=(v=s.collections)[b=c.collection]??(v[b]={});return c.op==="delete"?delete u[c.id]:c.op==="set"?u[c.id]=structuredClone(c.doc??{}):u[c.id]={...u[c.id]??{},...structuredClone(c.doc??{})},{collection:c.collection,id:c.id,doc:u[c.id]??null}});return s={...s,version:s.version+1},l(),{version:s.version,changed:structuredClone(a)}}}}function P(o=window){if(o.dvina||o.__dvinaFrame)return;let t=null,i=()=>{let l=L(o.document),f=W+(l?.fileId??`path:${o.location.pathname}`);return O(j(l,f),p=>console.error("[dvina] a write failed:",p.message))},s=l=>l!=="db"&&l!=="storage"?Promise.resolve(null):(t??(t=i()),Promise.resolve(l==="db"?t.db:t.storage));o.dvina=Object.freeze({use:s})}P();})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dvina/widget-kit",
3
- "version": "0.0.33",
3
+ "version": "0.0.34",
4
4
  "description": "Dvina's design kit for generated widgets: its tokens, one stylesheet for HTML and React, a small script, React components, and the composer of a saved widget's page.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -20,6 +20,11 @@
20
20
  "import": "./dist/compose.js",
21
21
  "default": "./dist/compose.js"
22
22
  },
23
+ "./db": {
24
+ "types": "./dist/db.d.ts",
25
+ "import": "./dist/db.js",
26
+ "default": "./dist/db.js"
27
+ },
23
28
  "./compile": {
24
29
  "types": "./dist/compile.d.ts",
25
30
  "import": "./dist/compile.js",