@jogak/core 0.1.0-alpha.7.1 → 0.1.0-alpha.9

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.
@@ -18,5 +18,19 @@ export declare const RESOLVED_VIRTUAL_ENTRY_PREFIX: string;
18
18
  /** Global css 모듈 — 사용자 globalCss를 import한다 (알파.6, opt-in). */
19
19
  export declare const VIRTUAL_GLOBAL_CSS_ID = "virtual:jogak/global-css";
20
20
  export declare const RESOLVED_VIRTUAL_GLOBAL_CSS_ID: string;
21
+ /**
22
+ * Preview frame entry (알파.8) — 사용자 vite scope의 iframe entry.
23
+ * jogakPreviewFramePlugin이 emit. 사용자 vite의 module graph에 포함되어
24
+ * 사용자 plugins(@tailwindcss/vite 등)가 정상 처리.
25
+ */
26
+ export declare const VIRTUAL_PREVIEW_ENTRY_ID = "virtual:jogak/preview-entry";
27
+ export declare const RESOLVED_VIRTUAL_PREVIEW_ENTRY_ID: string;
28
+ /**
29
+ * Preview-scope의 사용자 globalCss (알파.8) — 알파.6의 `virtual:jogak/global-css`는
30
+ * jogak SPA scope. 본 모듈은 사용자 vite scope의 preview-frame entry용.
31
+ * jogakPreviewFramePlugin이 emit.
32
+ */
33
+ export declare const VIRTUAL_PREVIEW_GLOBAL_CSS_ID = "virtual:jogak/preview-global-css";
34
+ export declare const RESOLVED_VIRTUAL_PREVIEW_GLOBAL_CSS_ID: string;
21
35
  export declare function idToSlug(id: string): string;
22
36
  export declare function slugToId(slug: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jogak/core",
3
- "version": "0.1.0-alpha.7.1",
3
+ "version": "0.1.0-alpha.9",
4
4
  "description": "Core types, registry, and Vite plugin for Jogak — a lightweight Storybook alternative.",
5
5
  "keywords": [
6
6
  "jogak",
@@ -25,14 +25,14 @@
25
25
  },
26
26
  "type": "module",
27
27
  "sideEffects": false,
28
- "main": "./dist/index.js",
28
+ "main": "./dist/index.cjs",
29
29
  "module": "./dist/index.mjs",
30
30
  "types": "./dist/index.d.ts",
31
31
  "exports": {
32
32
  ".": {
33
33
  "types": "./dist/index.d.ts",
34
34
  "import": "./dist/index.mjs",
35
- "require": "./dist/index.js"
35
+ "require": "./dist/index.cjs"
36
36
  },
37
37
  "./vite": {
38
38
  "types": "./dist/vite/plugin.d.ts",
@@ -41,6 +41,11 @@
41
41
  "./build": {
42
42
  "types": "./dist/build/index.d.ts",
43
43
  "import": "./dist/build/index.mjs"
44
+ },
45
+ "./server": {
46
+ "types": "./dist/server.d.ts",
47
+ "import": "./dist/server.mjs",
48
+ "require": "./dist/server.cjs"
44
49
  }
45
50
  },
46
51
  "files": [
package/dist/index.js DELETED
@@ -1 +0,0 @@
1
- "use strict";var V=Object.defineProperty;var U=i=>{throw TypeError(i)};var G=(i,t,e)=>t in i?V(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var I=(i,t,e)=>G(i,typeof t!="symbol"?t+"":t,e),z=(i,t,e)=>t.has(i)||U("Cannot "+e);var s=(i,t,e)=>(z(i,t,"read from private field"),e?e.call(i):t.get(i)),u=(i,t,e)=>t.has(i)?U("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(i):t.set(i,e),d=(i,t,e,n)=>(z(i,t,"write to private field"),n?n.call(i,e):t.set(i,e),e),f=(i,t,e)=>(z(i,t,"access private method"),e);var J=(i,t,e,n)=>({set _(r){d(i,t,r,e)},get _(){return s(i,t,n)}});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class F extends Error{constructor(e){super(`[jogak] Unknown entry id: ${e}`);I(this,"id");this.name="UnknownEntryError",this.id=e}}var a,C,b,v,k,E,w,j,A,T,l,m,M,q;class ${constructor(){u(this,l);u(this,a,new Map);u(this,C);u(this,b,new Set);u(this,v);u(this,k);u(this,E);u(this,w);u(this,j);u(this,A,!1);u(this,T,!1)}register(t){const e=H(t);f(this,l,q).call(this,()=>{this.registerMeta(e),this.hydrateEntry(t.id,t.jogaks,t.meta.component)})}unregister(t){const e=s(this,a).get(t);e!==void 0&&(e.kind==="pending"&&e.reject(new F(t)),s(this,a).delete(t),f(this,l,m).call(this))}get(t){const e=s(this,a).get(t);return(e==null?void 0:e.kind)==="hydrated"?e.entry:void 0}getAll(){if(s(this,E)!==void 0)return s(this,E);const t=[];for(const n of f(this,l,M).call(this)){const r=s(this,a).get(n);(r==null?void 0:r.kind)==="hydrated"&&t.push(r.entry)}const e=t;return d(this,E,e),e}search(t){const e=t.toLowerCase();return this.getAll().filter(n=>n.title.toLowerCase().includes(e))}getTree(){if(s(this,w)!==void 0)return s(this,w);const t={};for(const e of this.getAll()){const n=e.title.split("/");let r=t;for(let h=0;h<n.length-1;h++){const c=n[h];if(c===void 0)continue;const g=r[c];(g===void 0||"id"in g)&&(r[c]={}),r=r[c]}const o=n[n.length-1];o!==void 0&&(r[o]=e)}return d(this,w,t),t}clear(){if(s(this,a).size!==0){for(const t of s(this,a).values())t.kind==="pending"&&t.reject(new Error("[jogak] registry cleared"));s(this,a).clear(),f(this,l,m).call(this)}}get size(){let t=0;for(const e of s(this,a).values())e.kind==="hydrated"&&t++;return t}registerMeta(t){const e=s(this,a).get(t.id);if(e===void 0){s(this,a).set(t.id,{kind:"meta",meta:t}),f(this,l,m).call(this);return}if(e.kind==="meta"){s(this,a).set(t.id,{kind:"meta",meta:t}),f(this,l,m).call(this);return}if(e.kind==="pending"){s(this,a).set(t.id,{kind:"pending",meta:t,promise:e.promise,resolve:e.resolve,reject:e.reject}),f(this,l,m).call(this);return}const n={...e.entry,title:t.title,filePath:t.filePath,source:t.source,meta:N(t,e.entry.meta.component)};s(this,a).set(t.id,{kind:"hydrated",meta:t,entry:n}),f(this,l,m).call(this)}hydrateEntry(t,e,n){const r=s(this,a).get(t);let o;r===void 0?(console.warn(`[jogak] hydrateEntry called for unknown id "${t}" — synthesizing minimal meta`),o={id:t,title:t,jogakNames:e.map(c=>c.name),autoArgTypes:{},userArgTypes:{},source:"",filePath:"",metaExtras:{}}):o=r.meta;const h={id:o.id,title:o.title,jogaks:e,meta:N(o,n),...o.filePath?{filePath:o.filePath}:{},...o.source?{source:o.source}:{}};if((r==null?void 0:r.kind)==="pending"){s(this,a).set(t,{kind:"hydrated",meta:o,entry:h}),f(this,l,m).call(this),r.resolve(h);return}s(this,a).set(t,{kind:"hydrated",meta:o,entry:h}),f(this,l,m).call(this)}invalidateEntry(t){const e=s(this,a).get(t);e===void 0||e.kind!=="hydrated"||(s(this,a).set(t,{kind:"meta",meta:e.meta}),f(this,l,m).call(this))}requestEntry(t){const e=s(this,a).get(t);if(e===void 0)return Promise.reject(new F(t));if(e.kind==="hydrated")return Promise.resolve(e.entry);if(e.kind==="pending")return e.promise;const n=s(this,C);if(n===void 0)return Promise.reject(new Error("[jogak] entry loader not set — virtual:jogak index module did not load"));let r,o;const h=new Promise((c,g)=>{r=c,o=g});return s(this,a).set(t,{kind:"pending",meta:e.meta,promise:h,resolve:r,reject:o}),n(t).then(()=>{const c=s(this,a).get(t);(c==null?void 0:c.kind)!=="hydrated"&&o(new Error(`[jogak] entry module loaded but did not hydrate: ${t}`))},c=>{const g=c instanceof Error?c:new Error(String(c)),p=s(this,a).get(t);(p==null?void 0:p.kind)==="pending"&&p.promise===h&&s(this,a).set(t,{kind:"meta",meta:e.meta}),o(g)}),h}getAllMeta(){if(s(this,v)!==void 0)return s(this,v);const t=[];for(const n of f(this,l,M).call(this)){const r=s(this,a).get(n);r!==void 0&&t.push(r.meta)}const e=t;return d(this,v,e),e}getMetaTree(){if(s(this,k)!==void 0)return s(this,k);const t={};for(const e of f(this,l,M).call(this)){const n=s(this,a).get(e);if(n===void 0)continue;const r=n.meta,o=r.title.split("/");let h=t;for(let g=0;g<o.length-1;g++){const p=o[g];if(p===void 0)continue;const R=h[p];(R===void 0||"id"in R)&&(h[p]={}),h=h[p]}const c=o[o.length-1];c!==void 0&&(h[c]=r)}return d(this,k,t),t}getEntryState(t){const e=s(this,a).get(t);return e===void 0?"unknown":e.kind}setEntryLoader(t){d(this,C,t)}subscribe(t){s(this,b).add(t);let e=!0;return()=>{e&&(e=!1,s(this,b).delete(t))}}}a=new WeakMap,C=new WeakMap,b=new WeakMap,v=new WeakMap,k=new WeakMap,E=new WeakMap,w=new WeakMap,j=new WeakMap,A=new WeakMap,T=new WeakMap,l=new WeakSet,m=function(){if(d(this,v,void 0),d(this,k,void 0),d(this,E,void 0),d(this,w,void 0),d(this,j,void 0),s(this,A)){d(this,T,!0);return}const t=Array.from(s(this,b));for(const e of t)try{e()}catch(n){console.error("[jogak] subscribe listener threw:",n)}},M=function(){if(s(this,j)!==void 0)return s(this,j);const t=[];for(const[n,r]of s(this,a))t.push({id:n,title:r.meta.title});t.sort(K);const e=t.map(n=>n.id);return d(this,j,e),e},q=function(t){if(s(this,A)){t();return}d(this,A,!0),d(this,T,!1);try{t()}finally{d(this,A,!1),s(this,T)&&(d(this,T,!1),f(this,l,m).call(this))}};function H(i){const t=i.meta.argTypes??{};return{id:i.id,title:i.title,jogakNames:i.jogaks.map(e=>e.name),autoArgTypes:{},userArgTypes:t,source:i.source??"",filePath:i.filePath??"",metaExtras:{...i.meta.tags!==void 0?{tags:i.meta.tags}:{},...i.meta.parameters!==void 0?{parameters:i.meta.parameters}:{}}}}function N(i,t){const e={...i.autoArgTypes};for(const n of Object.keys(i.userArgTypes)){const r=i.userArgTypes[n];r!==void 0&&(e[n]={...e[n],...r})}return{title:i.title,component:t,argTypes:e,...i.metaExtras.tags!==void 0?{tags:i.metaExtras.tags}:{},...i.metaExtras.parameters!==void 0?{parameters:i.metaExtras.parameters}:{}}}function K(i,t){const e=i.title.localeCompare(t.title,"en",{sensitivity:"base",numeric:!0});return e!==0?e:i.id.localeCompare(t.id,"en",{sensitivity:"base",numeric:!0})}const Q=new $;var y,P,S,x,L;class D{constructor(){u(this,x);u(this,y,[]);u(this,P,new Set);u(this,S,1)}emit(t,e){const n={id:J(this,S)._++,name:t,args:e,timestamp:Date.now()};d(this,y,[...s(this,y),n]),f(this,x,L).call(this)}subscribe(t){return s(this,P).add(t),t(s(this,y)),()=>{s(this,P).delete(t)}}clear(){s(this,y).length!==0&&(d(this,y,[]),f(this,x,L).call(this))}getLogs(){return s(this,y)}}y=new WeakMap,P=new WeakMap,S=new WeakMap,x=new WeakSet,L=function(){for(const t of s(this,P))t(s(this,y))};const O=new D;function B(i,t=O){return(...e)=>{t.emit(i,e)}}function W(i,t,e=O){const n={...i};for(const r of Object.keys(t)){const o=t[r];if(o===void 0)continue;const h=o.action!==void 0&&o.action!==!1,c=o.type==="function";if(!h&&!c||typeof n[r]=="function")continue;const g=typeof o.action=="string"?o.action:r;n[r]=B(g,e)}return n}function X(i){return i}exports.ActionChannel=D;exports.ComponentRegistry=$;exports.UnknownEntryError=F;exports.action=B;exports.defaultActionChannel=O;exports.defaultRegistry=Q;exports.defineJogakConfig=X;exports.injectActions=W;
@@ -1,47 +0,0 @@
1
- "use strict";var K=Object.create;var L=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var X=Object.getPrototypeOf,Y=Object.prototype.hasOwnProperty;var H=(e,t,s,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of W(t))!Y.call(e,a)&&a!==s&&L(e,a,{get:()=>t[a],enumerable:!(o=q(t,a))||o.enumerable});return e};var z=(e,t,s)=>(s=e!=null?K(X(e)):{},H(t||!e||!e.__esModule?L(s,"default",{value:e,enumerable:!0}):s,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("node:path"),_=require("node:fs"),k=require("node:fs/promises"),R=require("../extractor-client-CiWszHel.cjs"),Q=["@jogak/core","@jogak/react","@jogak/web-components","@jogak/next"];async function P(e){try{const o=await k.stat(e);if(!o.isDirectory())return o.mtimeMs}catch{return 0}let t=0,s;try{s=await k.readdir(e)}catch{return 0}for(const o of s){const a=f.join(e,o);try{const l=await k.stat(a);if(l.isDirectory()){const y=await P(a);y>t&&(t=y)}else l.mtimeMs>t&&(t=l.mtimeMs)}catch{continue}}return t}async function Z(e){const t=f.resolve(e.root,"node_modules/.vite/deps");if(!_.existsSync(t))return{purged:!1};const s=f.join(t,"_metadata.json");if(!_.existsSync(s))return{purged:!1};let o;try{o=(await k.stat(s)).mtimeMs}catch(l){return e.logger.warn(`[jogak] cache validation: failed to stat _metadata.json (${l.message})`),{purged:!1}}const a=e.packages??Q;for(const l of a){const y=f.resolve(e.root,"node_modules",l,"dist");if(!_.existsSync(y))continue;let h;try{h=await P(y)}catch(w){e.logger.warn(`[jogak] cache validation: failed to walk ${l}/dist (${w.message})`);continue}if(h>o+1e3)try{return await k.rm(t,{recursive:!0,force:!0}),e.logger.info(`[jogak] vite deps cache invalidated (stale): ${l} dist newer than cache`),{purged:!0,reason:l}}catch(w){return e.logger.warn(`[jogak] cache validation: failed to purge ${t} (${w.message})`),{purged:!1}}}return{purged:!1}}const ee=["src/index.css","src/main.css","src/styles.css","src/styles/globals.css","src/styles/index.css","src/app/globals.css","src/global.css","src/app.css"];function te(e){for(const t of ee){const s=f.resolve(e,t);if(_.existsSync(s))return[s]}return[]}function re(e,t){if(e===void 0||e===!1)return[];if(e===!0)return te(t);if(typeof e=="string")return e.length>0?[f.resolve(t,e)]:[];const s=[];for(const o of e)typeof o=="string"&&o.length>0&&s.push(f.resolve(t,o));return s}function se(e){return e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/^\s*\/\/.*$/gm,"")}function oe(e){if(_.existsSync(e))try{const t=_.readFileSync(e,"utf8");return JSON.parse(se(t))}catch{return}}function ne(e,t,s){if(!e.endsWith("/*")||!t.endsWith("/*"))return;const o=e.slice(0,-2),a=f.resolve(s,t.slice(0,-2));return[o,a]}function ae(e,t){var a,l;const s={},o=new Set([e,f.resolve(t,"tsconfig.app.json")]);for(const y of o){const h=oe(y);if(h===void 0)continue;const w=(a=h.compilerOptions)==null?void 0:a.paths;if(w===void 0)continue;const d=((l=h.compilerOptions)==null?void 0:l.baseUrl)??".",p=f.resolve(f.dirname(y),d);for(const[S,b]of Object.entries(w)){const x=b[0];if(x===void 0)continue;const C=ne(S,x,p);if(C===void 0)continue;const[A,r]=C;s[A]===void 0&&(s[A]=r)}}return s}const F="virtual:jogak",M="\0"+F,G="virtual:jogak/entry/",O="\0"+G,U="virtual:jogak/global-css",$="\0"+U;function ie(e){return Buffer.from(e,"utf8").toString("base64url")}function ce(e){return Buffer.from(e,"base64url").toString("utf8")}function D(e){return{title:e.title,jogakNamesKey:[...e.jogakNames].sort().join("|")}}function le(e,t){return e!==void 0&&e.title===t.title&&e.jogakNamesKey===t.jogakNamesKey}function ue(e={}){const{patterns:t=["src/**/*.jogak.ts","src/**/*.jogak.tsx"],codeTheme:s="vsDark"}=e,o=e.cwd,a=e.tsConfigFilePath,l=e.disableCacheValidation===!0,y=e.resolveAlias,h=e.globalCss,w=e.previewIsolation??"shadow";let d,p,S;const b=new Map,x=new Map,C=new Map;async function A(){const{glob:r}=await import("glob"),g=S??process.cwd(),n=(await r(t,{cwd:g,absolute:!0})).sort(),u=[];b.clear(),x.clear();for(const i of n){let v="";try{v=await k.readFile(i,"utf8")}catch{continue}let j={},c=null;if(p!==void 0){try{j=await p.extract(i)}catch{j={}}try{c=await p.extractMeta(i)}catch{c=null}}if(c===null)continue;const m=c.title;b.set(m,i),x.set(i,m);const T={id:m,title:c.title,jogakNames:c.jogakNames,autoArgTypes:j,userArgTypes:c.userArgTypes,source:v,filePath:i,metaExtras:c.metaExtras};C.set(i,D(T)),u.push({id:m,filePath:i,meta:T})}return u}return{name:"vite-plugin-jogak",config(){const r=o??process.cwd(),g=a??f.resolve(r,"tsconfig.json"),n=ae(g,r),u={};if(y!==void 0)for(const[v,j]of Object.entries(y))u[v]=f.resolve(r,j);const i={...n,...u};if(Object.keys(i).length!==0)return{resolve:{alias:i}}},async configResolved(r){S=o??r.root,r.command==="serve"&&!l&&await Z({root:r.root,logger:{info:n=>r.logger.info(n),warn:n=>r.logger.warn(n)}});const g=a??f.resolve(S,"tsconfig.json");p=_.existsSync(g)?R.createPropsExtractor({tsConfigFilePath:g}):R.createPropsExtractor()},configureServer(r){d=r},buildEnd(){p==null||p.releaseCache()},resolveId(r){if(r===F)return M;if(r===U)return $;if(r.startsWith(G))return"\0"+r},async load(r){if(r===$){const g=S??process.cwd(),n=re(h,g);return n.length===0?`// [jogak] globalCss not configured or no candidates found.
2
- export {}
3
- `:`${n.map(i=>`import ${JSON.stringify(i)}`).join(`
4
- `)}
5
- export {}
6
- `}if(r===M){const n=(await A()).map(u=>u.meta);return`import { defaultRegistry } from '@jogak/core'
7
-
8
- const _entryLoader = (slug) =>
9
- import(/* @vite-ignore */ '/@id/__x00__virtual:jogak/entry/' + slug)
10
- defaultRegistry.setEntryLoader((id) => {
11
- const slug = ${de()}
12
- return _entryLoader(slug(id))
13
- })
14
-
15
- const _metas = ${JSON.stringify(n)}
16
-
17
- for (const m of _metas) defaultRegistry.registerMeta(m)
18
-
19
- export const _jogakCodeTheme = ${JSON.stringify(s)}
20
- export const _jogakPreviewIsolation = ${JSON.stringify(w)}
21
- export const _jogakMetas = _metas
22
- `}if(r.startsWith(O)){const g=r.slice(O.length),n=ce(g);let u=b.get(n);return u===void 0&&(await A(),u=b.get(n)),u===void 0?`// [jogak] unknown entry id: ${JSON.stringify(n)}
23
- export {}
24
- `:`import * as _user from ${JSON.stringify(u)}
25
- import { defaultRegistry } from '@jogak/core'
26
-
27
- const _meta = _user.default
28
- const _named = { ..._user }
29
- delete _named.default
30
- const _jogaks = Object.values(_named).filter(
31
- (v) => v !== null && typeof v === 'object' && typeof v.name === 'string'
32
- )
33
- defaultRegistry.hydrateEntry(${JSON.stringify(n)}, _jogaks, _meta?.component)
34
-
35
- if (import.meta.hot) {
36
- import.meta.hot.accept()
37
- }
38
-
39
- export {}
40
- `}},async handleHotUpdate({file:r,modules:g}){const n=/\.jogak\.(tsx?|jsx?)$/.test(r),u=/\.(tsx?|jsx?)$/.test(r)&&!n;if(!n&&!u||d===void 0||!n)return;const i=d.moduleGraph.getModuleById(M),v=x.get(r),j=v!==void 0?O+ie(v):void 0,c=j!==void 0?d.moduleGraph.getModuleById(j):void 0;let m=null,T={},E="";if(p!==void 0){try{m=await p.extractMeta(r)}catch{m=null}try{T=await p.extract(r)}catch{T={}}try{E=await k.readFile(r,"utf8")}catch{E=""}}if(m===null){i!==void 0&&d.moduleGraph.invalidateModule(i),c!==void 0&&d.moduleGraph.invalidateModule(c),d.ws.send({type:"full-reload"});return}const N=D(m),V=C.get(r),J=le(V,N);if(C.set(r,N),!J||v===void 0){i!==void 0&&d.moduleGraph.invalidateModule(i),c!==void 0&&d.moduleGraph.invalidateModule(c),d.ws.send({type:"full-reload"});return}const B={id:v,title:m.title,jogakNames:m.jogakNames,autoArgTypes:T,userArgTypes:m.userArgTypes,source:E,filePath:r,metaExtras:m.metaExtras};c!==void 0&&d.moduleGraph.invalidateModule(c),d.ws.send({type:"custom",event:"jogak:meta-update",data:{id:v,meta:B}});const I=[...g];return c!==void 0&&!I.includes(c)&&I.push(c),I}}}function de(){return`(rawId) => {
41
- if (typeof Buffer !== 'undefined') return Buffer.from(rawId, 'utf8').toString('base64url')
42
- // 브라우저 폴백: btoa는 binary string 기준이라 UTF-8을 한번 인코딩해야 한다.
43
- const enc = new TextEncoder().encode(rawId)
44
- let bin = ''
45
- for (let i = 0; i < enc.length; i++) bin += String.fromCharCode(enc[i])
46
- return btoa(bin).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '')
47
- }`}exports.jogak=ue;
File without changes