frontend-hamroun 1.1.8 → 1.1.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.
@@ -8,7 +8,7 @@ export declare class Component {
8
8
  setState(newState: any): Promise<void>;
9
9
  private _replayEvents;
10
10
  private _deepCloneWithEvents;
11
- update(): Promise<Text | HTMLElement>;
11
+ update(): Promise<HTMLElement | Text>;
12
12
  private _updateElement;
13
13
  render(): any;
14
14
  }
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});async function m(t){if(console.log("Creating element from:",t),t==null)return document.createTextNode("");if(typeof t=="string"||typeof t=="number")return document.createTextNode(String(t));if(typeof t.type=="function"){const c=t.type(t.props||{});return m(c)}const e=document.createElement(t.type),r=t.props||{};if(r.children){const c=Array.isArray(r.children)?r.children:[r.children];for(const n of c){const o=await m(n);e.appendChild(o)}}return Object.entries(r).forEach(([c,n])=>{if(c!=="children")if(c.startsWith("on")&&typeof n=="function"){const o=c.toLowerCase().substring(2);e.addEventListener(o,n)}else c==="style"&&typeof n=="object"?Object.assign(e.style,n):typeof n!="object"&&typeof n!="function"&&e.setAttribute(c,String(n))}),e}let h=[],a=!1;function w(t){if(a){h.push(t);return}a=!0;try{for(t();h.length>0;){const e=h.shift();e==null||e()}}finally{a=!1}}function A(){return a}let s=0;const d=new Map,i=new Map,l=new Map,p=new Map,y=new Map;let g=null,b=null,E=null;function U(t,e,r){g=t,b=r,E=e}function B(){return s++,i.set(s,0),s}function I(){s=0}function S(t){if(!s)throw new Error("useState must be called within a render");d.has(s)||d.set(s,[]);const e=d.get(s),r=i.get(s);r>=e.length&&e.push(t);const c=e[r],n=o=>{const u=typeof o=="function"?o(e[r]):o;e[r]!==u&&(e[r]=u,A()?w(()=>M(s)):M(s))};return i.set(s,r+1),[c,n]}function T(t,e){if(!s)throw new Error("useEffect must be called within a render");const r=i.get(s);l.has(s)||l.set(s,[]);const c=l.get(s),n=c[r];(!n||!e||!n.deps||e.some((o,u)=>o!==n.deps[u]))&&(n!=null&&n.cleanup&&n.cleanup(),queueMicrotask(()=>{const o=t()||void 0;c[r]={cleanup:o,deps:e}})),i.set(s,r+1)}function R(t,e){if(!s)throw new Error("useMemo must be called within a render");const r=i.get(s);p.has(s)||p.set(s,[]);const c=p.get(s),n=c[r];if(!n||e&&e.some((o,u)=>!Object.is(o,n.deps[u]))){const o=t();return c[r]={value:o,deps:e},i.set(s,r+1),o}return i.set(s,r+1),n.value}function F(t){if(!s)throw new Error("useRef must be called within a render");const e=i.get(s);y.has(s)||y.set(s,[]);const r=y.get(s);if(e>=r.length){const n={current:t};return r.push(n),i.set(s,e+1),n}const c=r[e];return i.set(s,e+1),c}async function M(t){try{const e=l.get(t);e&&(e.forEach(r=>{r.cleanup&&r.cleanup()}),l.set(t,[])),g&&b&&E&&await g(E,b)}catch(e){console.error("Error during rerender:",e)}}function L(){const[t,e]=S(null);return[t,()=>e(null)]}const f=new Map;function D(t){const e=Symbol();return f.set(e,t),{Provider:({value:c,children:n})=>{const o=f.get(e);return Object.is(o,c)||f.set(e,c),n},Consumer:({children:c})=>{const n=f.get(e);return c(n)},useSelector:c=>{const n=f.get(e);return R(()=>c(n),[n])},_id:e}}function H(t){return f.get(t._id)}function O(t,e){const r=Object.keys(t).filter(n=>n!=="children"),c=Object.keys(e).filter(n=>n!=="children");return r.length!==c.length?!1:r.every(n=>t[n]===e[n])}function K(t,e){return t==null||e==null?t!==e:typeof t!=typeof e?!0:typeof e=="string"||typeof e=="number"?t!==e:e.type!==t.type?!0:!O(t.props,e.props)}function V(t,e){return!O(t,e)}let x=!1;async function _(t,e){x=!0;try{await j(t,e)}finally{x=!1}}async function j(t,e){if(!e)throw new Error("Container element is null");console.log("Rendering to:",e.id),w(async()=>{const r=B();try{U(j,t,e);const c=await m(t);x||(e.innerHTML=""),e.appendChild(c)}finally{I()}})}const C=(t,e,r)=>({type:t,props:{...e,children:e!=null&&e.children?Array.isArray(e.children)?e.children:[e.children]:[]},key:r}),q=C,P=C,Q=Symbol("Fragment");exports.Fragment=Q;exports.batchUpdates=w;exports.createContext=D;exports.diff=K;exports.hydrate=_;exports.jsx=C;exports.jsxDEV=P;exports.jsxs=q;exports.render=j;exports.shouldComponentUpdate=V;exports.useContext=H;exports.useEffect=T;exports.useErrorBoundary=L;exports.useMemo=R;exports.useRef=F;exports.useState=S;
2
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/jsx-runtime.ts","../src/batch.ts","../src/hooks.ts","../src/context.ts","../src/vdom.ts","../src/index.ts"],"sourcesContent":["import type { Component } from './component';\r\n\r\ninterface VNode {\r\n type: string | Function;\r\n props: Record<string, any>;\r\n}\r\n\r\nexport function jsx(type: string | Function, props: any): VNode {\r\n console.log('JSX Transform:', { type, props });\r\n const processedProps = { ...props };\r\n \r\n // Handle children properly\r\n if (arguments.length > 2) {\r\n processedProps.children = Array.prototype.slice.call(arguments, 2);\r\n }\r\n \r\n return { type, props: processedProps };\r\n}\r\n\r\nexport { jsx as jsxs, jsx as jsxDEV };\r\nexport const Fragment = ({ children }: { children: any }) => children;\r\n\r\nexport async function createElement(vnode: any): Promise<HTMLElement | Text> {\r\n console.log('Creating element from:', vnode);\r\n\r\n // Handle null or undefined\r\n if (vnode == null) {\r\n return document.createTextNode('');\r\n }\r\n\r\n // Handle primitive types (string, number)\r\n if (typeof vnode === 'string' || typeof vnode === 'number') {\r\n return document.createTextNode(String(vnode));\r\n }\r\n\r\n // Handle functional components\r\n if (typeof vnode.type === 'function') {\r\n const result = vnode.type(vnode.props || {});\r\n return createElement(result);\r\n }\r\n\r\n // Handle regular DOM elements\r\n const element = document.createElement(vnode.type);\r\n const props = vnode.props || {};\r\n\r\n // Handle children\r\n if (props.children) {\r\n const children = Array.isArray(props.children) ? props.children : [props.children];\r\n for (const child of children) {\r\n const childElement = await createElement(child);\r\n element.appendChild(childElement);\r\n }\r\n }\r\n\r\n // Handle other props\r\n Object.entries(props).forEach(([key, value]) => {\r\n if (key === 'children') return;\r\n \r\n if (key.startsWith('on') && typeof value === 'function') {\r\n // Handle event listeners\r\n const eventName = key.toLowerCase().substring(2);\r\n element.addEventListener(eventName, value as EventListener);\r\n } else if (key === 'style' && typeof value === 'object') {\r\n // Handle style object\r\n Object.assign(element.style, value);\r\n } else if (typeof value !== 'object' && typeof value !== 'function') {\r\n // Handle regular attributes\r\n element.setAttribute(key, String(value));\r\n }\r\n });\r\n\r\n return element;\r\n}\r\n","type BatchCallback = () => void;\r\nlet batchQueue: BatchCallback[] = [];\r\nlet isBatchingUpdates = false;\r\n\r\nexport function batchUpdates(callback: BatchCallback) {\r\n if (isBatchingUpdates) {\r\n batchQueue.push(callback);\r\n return;\r\n }\r\n\r\n isBatchingUpdates = true;\r\n try {\r\n callback();\r\n while (batchQueue.length > 0) {\r\n const queuedCallback = batchQueue.shift();\r\n queuedCallback?.();\r\n }\r\n } finally {\r\n isBatchingUpdates = false;\r\n }\r\n}\r\n\r\nexport function isBatching() {\r\n return isBatchingUpdates;\r\n}\r\n","import { createElement } from './jsx-runtime';\r\nimport { batchUpdates, isBatching } from './batch';\r\nimport { diff } from './vdom';\r\n\r\nlet currentRender: number = 0;\r\nconst states = new Map<number, any[]>();\r\nconst stateIndices = new Map<number, number>();\r\nconst effects = new Map<number, Effect[]>();\r\nconst memos = new Map<number, { value: any; deps: any[] }[]>();\r\nconst refs = new Map<number, any[]>();\r\n\r\ninterface Effect {\r\n cleanup?: () => void;\r\n deps?: any[];\r\n}\r\n\r\n// Add at the top with other declarations\r\nlet globalRenderCallback: ((element: any, container: HTMLElement) => void) | null = null;\r\nlet globalContainer: HTMLElement | null = null;\r\nlet currentElement: any = null;\r\n\r\nexport function setRenderCallback(\r\n callback: (element: any, container: HTMLElement) => void,\r\n element: any,\r\n container: HTMLElement\r\n) {\r\n globalRenderCallback = callback;\r\n globalContainer = container;\r\n currentElement = element;\r\n}\r\n\r\nexport function prepareRender() {\r\n currentRender++;\r\n stateIndices.set(currentRender, 0);\r\n return currentRender;\r\n}\r\n\r\nexport function finishRender() {\r\n currentRender = 0;\r\n}\r\n\r\nexport function useState<T>(initial: T): [T, (value: T | ((prev: T) => T)) => void] {\r\n if (!currentRender) {\r\n throw new Error('useState must be called within a render');\r\n }\r\n\r\n if (!states.has(currentRender)) {\r\n states.set(currentRender, []);\r\n }\r\n\r\n const componentStates = states.get(currentRender)!;\r\n const index = stateIndices.get(currentRender)!;\r\n \r\n if (index >= componentStates.length) {\r\n componentStates.push(initial);\r\n }\r\n\r\n const state = componentStates[index];\r\n const setState = (newValue: T | ((prev: T) => T)) => {\r\n const nextValue = typeof newValue === 'function' \r\n ? (newValue as Function)(componentStates[index])\r\n : newValue;\r\n\r\n if (componentStates[index] === nextValue) return; // Skip if value hasn't changed\r\n \r\n componentStates[index] = nextValue;\r\n \r\n if (isBatching()) {\r\n batchUpdates(() => rerender(currentRender));\r\n } else {\r\n rerender(currentRender);\r\n }\r\n };\r\n\r\n stateIndices.set(currentRender, index + 1);\r\n return [state, setState];\r\n}\r\n\r\nexport function useEffect(callback: () => (() => void) | void, deps?: any[]) {\r\n if (!currentRender) throw new Error('useEffect must be called within a render');\r\n \r\n const effectIndex = stateIndices.get(currentRender)!;\r\n \r\n if (!effects.has(currentRender)) {\r\n effects.set(currentRender, []);\r\n }\r\n\r\n const componentEffects = effects.get(currentRender)!;\r\n const prevEffect = componentEffects[effectIndex];\r\n \r\n // Run effect if deps changed\r\n if (!prevEffect || !deps || !prevEffect.deps || \r\n deps.some((dep, i) => dep !== prevEffect.deps![i])) {\r\n \r\n // Cleanup previous effect\r\n if (prevEffect?.cleanup) {\r\n prevEffect.cleanup();\r\n }\r\n\r\n // Schedule new effect\r\n queueMicrotask(() => {\r\n const cleanup = callback() || undefined;\r\n componentEffects[effectIndex] = { cleanup: cleanup, deps };\r\n });\r\n }\r\n \r\n stateIndices.set(currentRender, effectIndex + 1);\r\n}\r\n\r\nexport function useMemo<T>(factory: () => T, deps: any[]): T {\r\n if (!currentRender) throw new Error('useMemo must be called within a render');\r\n \r\n const memoIndex = stateIndices.get(currentRender)!;\r\n \r\n if (!memos.has(currentRender)) {\r\n memos.set(currentRender, []);\r\n }\r\n\r\n const componentMemos = memos.get(currentRender)!;\r\n const prevMemo = componentMemos[memoIndex];\r\n \r\n if (!prevMemo || (deps && deps.some((dep, i) => !Object.is(dep, prevMemo.deps[i])))) {\r\n const value = factory();\r\n componentMemos[memoIndex] = { value, deps };\r\n stateIndices.set(currentRender, memoIndex + 1);\r\n return value;\r\n }\r\n\r\n stateIndices.set(currentRender, memoIndex + 1);\r\n return prevMemo.value;\r\n}\r\n\r\nexport function useRef<T>(initial: T) {\r\n if (!currentRender) throw new Error('useRef must be called within a render');\r\n \r\n const refIndex = stateIndices.get(currentRender)!;\r\n \r\n if (!refs.has(currentRender)) {\r\n refs.set(currentRender, []);\r\n }\r\n\r\n const componentRefs = refs.get(currentRender)!;\r\n if (refIndex >= componentRefs.length) {\r\n // Initialize with an object that has a current property\r\n const ref = { current: initial };\r\n componentRefs.push(ref);\r\n stateIndices.set(currentRender, refIndex + 1);\r\n return ref;\r\n }\r\n\r\n const ref = componentRefs[refIndex];\r\n stateIndices.set(currentRender, refIndex + 1);\r\n return ref;\r\n}\r\n\r\n// Add a map to track component DOM nodes\r\nconst componentNodes = new Map<Function, Node>();\r\n\r\nasync function rerender(rendererId: number) {\r\n try {\r\n // Clean up effects\r\n const componentEffects = effects.get(rendererId);\r\n if (componentEffects) {\r\n componentEffects.forEach(effect => {\r\n if (effect.cleanup) effect.cleanup();\r\n });\r\n effects.set(rendererId, []);\r\n }\r\n\r\n if (globalRenderCallback && globalContainer && currentElement) {\r\n await globalRenderCallback(currentElement, globalContainer);\r\n }\r\n } catch (error) {\r\n console.error('Error during rerender:', error);\r\n }\r\n}\r\n\r\n// Add new hook for error boundaries\r\nexport function useErrorBoundary(): [Error | null, () => void] {\r\n const [error, setError] = useState<Error | null>(null);\r\n return [error, () => setError(null)];\r\n}\r\n\r\n// Remove withHooks export\r\n","import { useMemo } from \"./hooks\";\r\n\r\nconst contexts = new Map<symbol, any>();\r\nlet currentRender: Function | null = null;\r\n\r\nexport interface Context<T> {\r\n Provider: (props: { value: T; children?: any }) => any;\r\n Consumer: (props: { children: (value: T) => any }) => any;\r\n _id: symbol;\r\n useSelector: <S>(selector: (state: T) => S) => S;\r\n}\r\n\r\nexport function createContext<T>(defaultValue: T): Context<T> {\r\n const id = Symbol();\r\n contexts.set(id, defaultValue);\r\n \r\n const useSelector = <S>(selector: (state: T) => S): S => {\r\n const value = contexts.get(id);\r\n return useMemo(() => selector(value), [value]);\r\n };\r\n\r\n return {\r\n Provider: ({ value, children }) => {\r\n const prevValue = contexts.get(id);\r\n if (!Object.is(prevValue, value)) {\r\n contexts.set(id, value);\r\n }\r\n return children;\r\n },\r\n Consumer: ({ children }) => {\r\n const value = contexts.get(id);\r\n return children(value);\r\n },\r\n useSelector,\r\n _id: id\r\n };\r\n}\r\n\r\nexport function useContext<T>(context: Context<T>): T {\r\n return contexts.get(context._id);\r\n}\r\n","interface VNode {\r\n type: string | Function;\r\n props: Record<string, any>;\r\n key?: string | number;\r\n}\r\n\r\nfunction arePropsEqual(oldProps: any, newProps: any): boolean {\r\n const oldKeys = Object.keys(oldProps).filter(k => k !== 'children');\r\n const newKeys = Object.keys(newProps).filter(k => k !== 'children');\r\n \r\n if (oldKeys.length !== newKeys.length) return false;\r\n return oldKeys.every(key => oldProps[key] === newProps[key]);\r\n}\r\n\r\nexport function diff(oldNode: VNode | any, newNode: VNode | any): boolean {\r\n if (oldNode == null || newNode == null) return oldNode !== newNode;\r\n if (typeof oldNode !== typeof newNode) return true;\r\n if (typeof newNode === 'string' || typeof newNode === 'number')\r\n return oldNode !== newNode;\r\n if (newNode.type !== oldNode.type) return true;\r\n return !arePropsEqual(oldNode.props, newNode.props);\r\n}\r\n\r\nexport function shouldComponentUpdate(oldProps: any, newProps: any): boolean {\r\n return !arePropsEqual(oldProps, newProps);\r\n}\r\n","import { createElement } from './jsx-runtime';\r\nimport { prepareRender, finishRender, setRenderCallback } from './hooks';\r\nimport { batchUpdates } from './batch';\r\n\r\nexport { \r\n useState, \r\n useEffect, \r\n useMemo, \r\n useRef,\r\n useErrorBoundary \r\n} from './hooks';\r\n\r\nexport { createContext, useContext } from './context';\r\nexport { batchUpdates } from './batch';\r\n\r\nlet isHydrating = false;\r\n\r\nexport async function hydrate(element: any, container: HTMLElement) {\r\n isHydrating = true;\r\n try {\r\n await render(element, container);\r\n } finally {\r\n isHydrating = false;\r\n }\r\n}\r\n\r\nexport async function render(element: any, container: HTMLElement | null) {\r\n if (!container) {\r\n throw new Error('Container element is null');\r\n }\r\n\r\n console.log('Rendering to:', container.id);\r\n \r\n batchUpdates(async () => {\r\n const rendererId = prepareRender();\r\n try {\r\n setRenderCallback(render, element, container);\r\n const domNode = await createElement(element);\r\n \r\n if (!isHydrating) {\r\n container.innerHTML = '';\r\n }\r\n container.appendChild(domNode);\r\n \r\n } finally {\r\n finishRender();\r\n }\r\n });\r\n}\r\n\r\nexport { diff, shouldComponentUpdate } from './vdom';\r\n\r\n// Add JSX runtime\r\nexport const jsx = (type: any, props: any, key?: any) => ({\r\n type,\r\n props: {\r\n ...props,\r\n children: props?.children ? \r\n Array.isArray(props.children) ? props.children : [props.children]\r\n : []\r\n },\r\n key\r\n});\r\n\r\nexport const jsxs = jsx;\r\nexport const jsxDEV = jsx; // Add development runtime\r\nexport const Fragment = Symbol('Fragment');\r\n\r\n"],"names":["createElement","vnode","result","element","props","children","child","childElement","key","value","eventName","batchQueue","isBatchingUpdates","batchUpdates","callback","queuedCallback","isBatching","currentRender","states","stateIndices","effects","memos","refs","globalRenderCallback","globalContainer","currentElement","setRenderCallback","container","prepareRender","finishRender","useState","initial","componentStates","index","state","setState","newValue","nextValue","rerender","useEffect","deps","effectIndex","componentEffects","prevEffect","dep","i","cleanup","useMemo","factory","memoIndex","componentMemos","prevMemo","useRef","refIndex","componentRefs","ref","rendererId","effect","error","useErrorBoundary","setError","contexts","createContext","defaultValue","id","prevValue","selector","useContext","context","arePropsEqual","oldProps","newProps","oldKeys","k","newKeys","diff","oldNode","newNode","shouldComponentUpdate","isHydrating","hydrate","render","domNode","jsx","type","jsxs","jsxDEV","Fragment"],"mappings":"gFAsBA,eAAsBA,EAAcC,EAAyC,CAI3E,GAHQ,QAAA,IAAI,yBAA0BA,CAAK,EAGvCA,GAAS,KACJ,OAAA,SAAS,eAAe,EAAE,EAInC,GAAI,OAAOA,GAAU,UAAY,OAAOA,GAAU,SAChD,OAAO,SAAS,eAAe,OAAOA,CAAK,CAAC,EAI1C,GAAA,OAAOA,EAAM,MAAS,WAAY,CACpC,MAAMC,EAASD,EAAM,KAAKA,EAAM,OAAS,CAAA,CAAE,EAC3C,OAAOD,EAAcE,CAAM,CAC7B,CAGA,MAAMC,EAAU,SAAS,cAAcF,EAAM,IAAI,EAC3CG,EAAQH,EAAM,OAAS,GAG7B,GAAIG,EAAM,SAAU,CACZ,MAAAC,EAAW,MAAM,QAAQD,EAAM,QAAQ,EAAIA,EAAM,SAAW,CAACA,EAAM,QAAQ,EACjF,UAAWE,KAASD,EAAU,CACtB,MAAAE,EAAe,MAAMP,EAAcM,CAAK,EAC9CH,EAAQ,YAAYI,CAAY,CAClC,CACF,CAGO,cAAA,QAAQH,CAAK,EAAE,QAAQ,CAAC,CAACI,EAAKC,CAAK,IAAM,CAC9C,GAAID,IAAQ,WAEZ,GAAIA,EAAI,WAAW,IAAI,GAAK,OAAOC,GAAU,WAAY,CAEvD,MAAMC,EAAYF,EAAI,YAAY,EAAE,UAAU,CAAC,EACvCL,EAAA,iBAAiBO,EAAWD,CAAsB,CACjD,MAAAD,IAAQ,SAAW,OAAOC,GAAU,SAEtC,OAAA,OAAON,EAAQ,MAAOM,CAAK,EACzB,OAAOA,GAAU,UAAY,OAAOA,GAAU,YAEvDN,EAAQ,aAAaK,EAAK,OAAOC,CAAK,CAAC,CACzC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AAAE,EAAO9E,EAAcwB,EAA+B,CACxE,GAAI,CAACA,EACG,MAAA,IAAI,MAAM,2BAA2B,EAGrC,QAAA,IAAI,gBAAiBA,EAAU,EAAE,EAEzCd,EAAa,SAAY,CACvB,MAAM2C,EAAa5B,IACf,GAAA,CACgBF,EAAAuD,EAAQ9E,EAASwB,CAAS,EACtC,MAAAuD,EAAU,MAAMlF,EAAcG,CAAO,EAEtC4E,IACHpD,EAAU,UAAY,IAExBA,EAAU,YAAYuD,CAAO,CAAA,QAE7B,CACarD,GACf,CAAA,CACD,CACH,CAKO,MAAMsD,EAAM,CAACC,EAAWhF,EAAYI,KAAe,CACxD,KAAA4E,EACA,MAAO,CACL,GAAGhF,EACH,SAAUA,GAAA,MAAAA,EAAO,SACf,MAAM,QAAQA,EAAM,QAAQ,EAAIA,EAAM,SAAW,CAACA,EAAM,QAAQ,EAC9D,CAAC,CACP,EACA,IAAAI,CACF,GAEa6E,EAAOF,EACPG,EAASH,EACTI,EAAW,OAAO,UAAU"}
package/dist/index.d.ts CHANGED
@@ -2,4 +2,21 @@ export { useState, useEffect, useMemo, useRef, useErrorBoundary } from './hooks'
2
2
  export { createContext, useContext } from './context';
3
3
  export { batchUpdates } from './batch';
4
4
  export declare function hydrate(element: any, container: HTMLElement): Promise<void>;
5
- export declare function render(element: any, container: HTMLElement): Promise<void>;
5
+ export declare function render(element: any, container: HTMLElement | null): Promise<void>;
6
+ export { diff, shouldComponentUpdate } from './vdom';
7
+ export declare const jsx: (type: any, props: any, key?: any) => {
8
+ type: any;
9
+ props: any;
10
+ key: any;
11
+ };
12
+ export declare const jsxs: (type: any, props: any, key?: any) => {
13
+ type: any;
14
+ props: any;
15
+ key: any;
16
+ };
17
+ export declare const jsxDEV: (type: any, props: any, key?: any) => {
18
+ type: any;
19
+ props: any;
20
+ key: any;
21
+ };
22
+ export declare const Fragment: unique symbol;
@@ -0,0 +1,201 @@
1
+ async function d(t) {
2
+ if (console.log("Creating element from:", t), t == null)
3
+ return document.createTextNode("");
4
+ if (typeof t == "string" || typeof t == "number")
5
+ return document.createTextNode(String(t));
6
+ if (typeof t.type == "function") {
7
+ const c = t.type(t.props || {});
8
+ return d(c);
9
+ }
10
+ const e = document.createElement(t.type), r = t.props || {};
11
+ if (r.children) {
12
+ const c = Array.isArray(r.children) ? r.children : [r.children];
13
+ for (const n of c) {
14
+ const i = await d(n);
15
+ e.appendChild(i);
16
+ }
17
+ }
18
+ return Object.entries(r).forEach(([c, n]) => {
19
+ if (c !== "children")
20
+ if (c.startsWith("on") && typeof n == "function") {
21
+ const i = c.toLowerCase().substring(2);
22
+ e.addEventListener(i, n);
23
+ } else
24
+ c === "style" && typeof n == "object" ? Object.assign(e.style, n) : typeof n != "object" && typeof n != "function" && e.setAttribute(c, String(n));
25
+ }), e;
26
+ }
27
+ let h = [], a = !1;
28
+ function M(t) {
29
+ if (a) {
30
+ h.push(t);
31
+ return;
32
+ }
33
+ a = !0;
34
+ try {
35
+ for (t(); h.length > 0; ) {
36
+ const e = h.shift();
37
+ e == null || e();
38
+ }
39
+ } finally {
40
+ a = !1;
41
+ }
42
+ }
43
+ function R() {
44
+ return a;
45
+ }
46
+ let s = 0;
47
+ const p = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map();
48
+ let g = null, b = null, E = null;
49
+ function O(t, e, r) {
50
+ g = t, b = r, E = e;
51
+ }
52
+ function A() {
53
+ return s++, o.set(s, 0), s;
54
+ }
55
+ function I() {
56
+ s = 0;
57
+ }
58
+ function B(t) {
59
+ if (!s)
60
+ throw new Error("useState must be called within a render");
61
+ p.has(s) || p.set(s, []);
62
+ const e = p.get(s), r = o.get(s);
63
+ r >= e.length && e.push(t);
64
+ const c = e[r], n = (i) => {
65
+ const f = typeof i == "function" ? i(e[r]) : i;
66
+ e[r] !== f && (e[r] = f, R() ? M(() => x(s)) : x(s));
67
+ };
68
+ return o.set(s, r + 1), [c, n];
69
+ }
70
+ function T(t, e) {
71
+ if (!s)
72
+ throw new Error("useEffect must be called within a render");
73
+ const r = o.get(s);
74
+ l.has(s) || l.set(s, []);
75
+ const c = l.get(s), n = c[r];
76
+ (!n || !e || !n.deps || e.some((i, f) => i !== n.deps[f])) && (n != null && n.cleanup && n.cleanup(), queueMicrotask(() => {
77
+ const i = t() || void 0;
78
+ c[r] = { cleanup: i, deps: e };
79
+ })), o.set(s, r + 1);
80
+ }
81
+ function L(t, e) {
82
+ if (!s)
83
+ throw new Error("useMemo must be called within a render");
84
+ const r = o.get(s);
85
+ y.has(s) || y.set(s, []);
86
+ const c = y.get(s), n = c[r];
87
+ if (!n || e && e.some((i, f) => !Object.is(i, n.deps[f]))) {
88
+ const i = t();
89
+ return c[r] = { value: i, deps: e }, o.set(s, r + 1), i;
90
+ }
91
+ return o.set(s, r + 1), n.value;
92
+ }
93
+ function U(t) {
94
+ if (!s)
95
+ throw new Error("useRef must be called within a render");
96
+ const e = o.get(s);
97
+ m.has(s) || m.set(s, []);
98
+ const r = m.get(s);
99
+ if (e >= r.length) {
100
+ const n = { current: t };
101
+ return r.push(n), o.set(s, e + 1), n;
102
+ }
103
+ const c = r[e];
104
+ return o.set(s, e + 1), c;
105
+ }
106
+ async function x(t) {
107
+ try {
108
+ const e = l.get(t);
109
+ e && (e.forEach((r) => {
110
+ r.cleanup && r.cleanup();
111
+ }), l.set(t, [])), g && b && E && await g(E, b);
112
+ } catch (e) {
113
+ console.error("Error during rerender:", e);
114
+ }
115
+ }
116
+ function F() {
117
+ const [t, e] = B(null);
118
+ return [t, () => e(null)];
119
+ }
120
+ const u = /* @__PURE__ */ new Map();
121
+ function H(t) {
122
+ const e = Symbol();
123
+ return u.set(e, t), {
124
+ Provider: ({ value: c, children: n }) => {
125
+ const i = u.get(e);
126
+ return Object.is(i, c) || u.set(e, c), n;
127
+ },
128
+ Consumer: ({ children: c }) => {
129
+ const n = u.get(e);
130
+ return c(n);
131
+ },
132
+ useSelector: (c) => {
133
+ const n = u.get(e);
134
+ return L(() => c(n), [n]);
135
+ },
136
+ _id: e
137
+ };
138
+ }
139
+ function K(t) {
140
+ return u.get(t._id);
141
+ }
142
+ function j(t, e) {
143
+ const r = Object.keys(t).filter((n) => n !== "children"), c = Object.keys(e).filter((n) => n !== "children");
144
+ return r.length !== c.length ? !1 : r.every((n) => t[n] === e[n]);
145
+ }
146
+ function _(t, e) {
147
+ return t == null || e == null ? t !== e : typeof t != typeof e ? !0 : typeof e == "string" || typeof e == "number" ? t !== e : e.type !== t.type ? !0 : !j(t.props, e.props);
148
+ }
149
+ function q(t, e) {
150
+ return !j(t, e);
151
+ }
152
+ let w = !1;
153
+ async function D(t, e) {
154
+ w = !0;
155
+ try {
156
+ await C(t, e);
157
+ } finally {
158
+ w = !1;
159
+ }
160
+ }
161
+ async function C(t, e) {
162
+ if (!e)
163
+ throw new Error("Container element is null");
164
+ console.log("Rendering to:", e.id), M(async () => {
165
+ const r = A();
166
+ try {
167
+ O(C, t, e);
168
+ const c = await d(t);
169
+ w || (e.innerHTML = ""), e.appendChild(c);
170
+ } finally {
171
+ I();
172
+ }
173
+ });
174
+ }
175
+ const S = (t, e, r) => ({
176
+ type: t,
177
+ props: {
178
+ ...e,
179
+ children: e != null && e.children ? Array.isArray(e.children) ? e.children : [e.children] : []
180
+ },
181
+ key: r
182
+ }), Q = S, V = S, W = Symbol("Fragment");
183
+ export {
184
+ W as Fragment,
185
+ M as batchUpdates,
186
+ H as createContext,
187
+ _ as diff,
188
+ D as hydrate,
189
+ S as jsx,
190
+ V as jsxDEV,
191
+ Q as jsxs,
192
+ C as render,
193
+ q as shouldComponentUpdate,
194
+ K as useContext,
195
+ T as useEffect,
196
+ F as useErrorBoundary,
197
+ L as useMemo,
198
+ U as useRef,
199
+ B as useState
200
+ };
201
+ //# sourceMappingURL=index.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.es.js","sources":["../src/jsx-runtime.ts","../src/batch.ts","../src/hooks.ts","../src/context.ts","../src/vdom.ts","../src/index.ts"],"sourcesContent":["import type { Component } from './component';\r\n\r\ninterface VNode {\r\n type: string | Function;\r\n props: Record<string, any>;\r\n}\r\n\r\nexport function jsx(type: string | Function, props: any): VNode {\r\n console.log('JSX Transform:', { type, props });\r\n const processedProps = { ...props };\r\n \r\n // Handle children properly\r\n if (arguments.length > 2) {\r\n processedProps.children = Array.prototype.slice.call(arguments, 2);\r\n }\r\n \r\n return { type, props: processedProps };\r\n}\r\n\r\nexport { jsx as jsxs, jsx as jsxDEV };\r\nexport const Fragment = ({ children }: { children: any }) => children;\r\n\r\nexport async function createElement(vnode: any): Promise<HTMLElement | Text> {\r\n console.log('Creating element from:', vnode);\r\n\r\n // Handle null or undefined\r\n if (vnode == null) {\r\n return document.createTextNode('');\r\n }\r\n\r\n // Handle primitive types (string, number)\r\n if (typeof vnode === 'string' || typeof vnode === 'number') {\r\n return document.createTextNode(String(vnode));\r\n }\r\n\r\n // Handle functional components\r\n if (typeof vnode.type === 'function') {\r\n const result = vnode.type(vnode.props || {});\r\n return createElement(result);\r\n }\r\n\r\n // Handle regular DOM elements\r\n const element = document.createElement(vnode.type);\r\n const props = vnode.props || {};\r\n\r\n // Handle children\r\n if (props.children) {\r\n const children = Array.isArray(props.children) ? props.children : [props.children];\r\n for (const child of children) {\r\n const childElement = await createElement(child);\r\n element.appendChild(childElement);\r\n }\r\n }\r\n\r\n // Handle other props\r\n Object.entries(props).forEach(([key, value]) => {\r\n if (key === 'children') return;\r\n \r\n if (key.startsWith('on') && typeof value === 'function') {\r\n // Handle event listeners\r\n const eventName = key.toLowerCase().substring(2);\r\n element.addEventListener(eventName, value as EventListener);\r\n } else if (key === 'style' && typeof value === 'object') {\r\n // Handle style object\r\n Object.assign(element.style, value);\r\n } else if (typeof value !== 'object' && typeof value !== 'function') {\r\n // Handle regular attributes\r\n element.setAttribute(key, String(value));\r\n }\r\n });\r\n\r\n return element;\r\n}\r\n","type BatchCallback = () => void;\r\nlet batchQueue: BatchCallback[] = [];\r\nlet isBatchingUpdates = false;\r\n\r\nexport function batchUpdates(callback: BatchCallback) {\r\n if (isBatchingUpdates) {\r\n batchQueue.push(callback);\r\n return;\r\n }\r\n\r\n isBatchingUpdates = true;\r\n try {\r\n callback();\r\n while (batchQueue.length > 0) {\r\n const queuedCallback = batchQueue.shift();\r\n queuedCallback?.();\r\n }\r\n } finally {\r\n isBatchingUpdates = false;\r\n }\r\n}\r\n\r\nexport function isBatching() {\r\n return isBatchingUpdates;\r\n}\r\n","import { createElement } from './jsx-runtime';\r\nimport { batchUpdates, isBatching } from './batch';\r\nimport { diff } from './vdom';\r\n\r\nlet currentRender: number = 0;\r\nconst states = new Map<number, any[]>();\r\nconst stateIndices = new Map<number, number>();\r\nconst effects = new Map<number, Effect[]>();\r\nconst memos = new Map<number, { value: any; deps: any[] }[]>();\r\nconst refs = new Map<number, any[]>();\r\n\r\ninterface Effect {\r\n cleanup?: () => void;\r\n deps?: any[];\r\n}\r\n\r\n// Add at the top with other declarations\r\nlet globalRenderCallback: ((element: any, container: HTMLElement) => void) | null = null;\r\nlet globalContainer: HTMLElement | null = null;\r\nlet currentElement: any = null;\r\n\r\nexport function setRenderCallback(\r\n callback: (element: any, container: HTMLElement) => void,\r\n element: any,\r\n container: HTMLElement\r\n) {\r\n globalRenderCallback = callback;\r\n globalContainer = container;\r\n currentElement = element;\r\n}\r\n\r\nexport function prepareRender() {\r\n currentRender++;\r\n stateIndices.set(currentRender, 0);\r\n return currentRender;\r\n}\r\n\r\nexport function finishRender() {\r\n currentRender = 0;\r\n}\r\n\r\nexport function useState<T>(initial: T): [T, (value: T | ((prev: T) => T)) => void] {\r\n if (!currentRender) {\r\n throw new Error('useState must be called within a render');\r\n }\r\n\r\n if (!states.has(currentRender)) {\r\n states.set(currentRender, []);\r\n }\r\n\r\n const componentStates = states.get(currentRender)!;\r\n const index = stateIndices.get(currentRender)!;\r\n \r\n if (index >= componentStates.length) {\r\n componentStates.push(initial);\r\n }\r\n\r\n const state = componentStates[index];\r\n const setState = (newValue: T | ((prev: T) => T)) => {\r\n const nextValue = typeof newValue === 'function' \r\n ? (newValue as Function)(componentStates[index])\r\n : newValue;\r\n\r\n if (componentStates[index] === nextValue) return; // Skip if value hasn't changed\r\n \r\n componentStates[index] = nextValue;\r\n \r\n if (isBatching()) {\r\n batchUpdates(() => rerender(currentRender));\r\n } else {\r\n rerender(currentRender);\r\n }\r\n };\r\n\r\n stateIndices.set(currentRender, index + 1);\r\n return [state, setState];\r\n}\r\n\r\nexport function useEffect(callback: () => (() => void) | void, deps?: any[]) {\r\n if (!currentRender) throw new Error('useEffect must be called within a render');\r\n \r\n const effectIndex = stateIndices.get(currentRender)!;\r\n \r\n if (!effects.has(currentRender)) {\r\n effects.set(currentRender, []);\r\n }\r\n\r\n const componentEffects = effects.get(currentRender)!;\r\n const prevEffect = componentEffects[effectIndex];\r\n \r\n // Run effect if deps changed\r\n if (!prevEffect || !deps || !prevEffect.deps || \r\n deps.some((dep, i) => dep !== prevEffect.deps![i])) {\r\n \r\n // Cleanup previous effect\r\n if (prevEffect?.cleanup) {\r\n prevEffect.cleanup();\r\n }\r\n\r\n // Schedule new effect\r\n queueMicrotask(() => {\r\n const cleanup = callback() || undefined;\r\n componentEffects[effectIndex] = { cleanup: cleanup, deps };\r\n });\r\n }\r\n \r\n stateIndices.set(currentRender, effectIndex + 1);\r\n}\r\n\r\nexport function useMemo<T>(factory: () => T, deps: any[]): T {\r\n if (!currentRender) throw new Error('useMemo must be called within a render');\r\n \r\n const memoIndex = stateIndices.get(currentRender)!;\r\n \r\n if (!memos.has(currentRender)) {\r\n memos.set(currentRender, []);\r\n }\r\n\r\n const componentMemos = memos.get(currentRender)!;\r\n const prevMemo = componentMemos[memoIndex];\r\n \r\n if (!prevMemo || (deps && deps.some((dep, i) => !Object.is(dep, prevMemo.deps[i])))) {\r\n const value = factory();\r\n componentMemos[memoIndex] = { value, deps };\r\n stateIndices.set(currentRender, memoIndex + 1);\r\n return value;\r\n }\r\n\r\n stateIndices.set(currentRender, memoIndex + 1);\r\n return prevMemo.value;\r\n}\r\n\r\nexport function useRef<T>(initial: T) {\r\n if (!currentRender) throw new Error('useRef must be called within a render');\r\n \r\n const refIndex = stateIndices.get(currentRender)!;\r\n \r\n if (!refs.has(currentRender)) {\r\n refs.set(currentRender, []);\r\n }\r\n\r\n const componentRefs = refs.get(currentRender)!;\r\n if (refIndex >= componentRefs.length) {\r\n // Initialize with an object that has a current property\r\n const ref = { current: initial };\r\n componentRefs.push(ref);\r\n stateIndices.set(currentRender, refIndex + 1);\r\n return ref;\r\n }\r\n\r\n const ref = componentRefs[refIndex];\r\n stateIndices.set(currentRender, refIndex + 1);\r\n return ref;\r\n}\r\n\r\n// Add a map to track component DOM nodes\r\nconst componentNodes = new Map<Function, Node>();\r\n\r\nasync function rerender(rendererId: number) {\r\n try {\r\n // Clean up effects\r\n const componentEffects = effects.get(rendererId);\r\n if (componentEffects) {\r\n componentEffects.forEach(effect => {\r\n if (effect.cleanup) effect.cleanup();\r\n });\r\n effects.set(rendererId, []);\r\n }\r\n\r\n if (globalRenderCallback && globalContainer && currentElement) {\r\n await globalRenderCallback(currentElement, globalContainer);\r\n }\r\n } catch (error) {\r\n console.error('Error during rerender:', error);\r\n }\r\n}\r\n\r\n// Add new hook for error boundaries\r\nexport function useErrorBoundary(): [Error | null, () => void] {\r\n const [error, setError] = useState<Error | null>(null);\r\n return [error, () => setError(null)];\r\n}\r\n\r\n// Remove withHooks export\r\n","import { useMemo } from \"./hooks\";\r\n\r\nconst contexts = new Map<symbol, any>();\r\nlet currentRender: Function | null = null;\r\n\r\nexport interface Context<T> {\r\n Provider: (props: { value: T; children?: any }) => any;\r\n Consumer: (props: { children: (value: T) => any }) => any;\r\n _id: symbol;\r\n useSelector: <S>(selector: (state: T) => S) => S;\r\n}\r\n\r\nexport function createContext<T>(defaultValue: T): Context<T> {\r\n const id = Symbol();\r\n contexts.set(id, defaultValue);\r\n \r\n const useSelector = <S>(selector: (state: T) => S): S => {\r\n const value = contexts.get(id);\r\n return useMemo(() => selector(value), [value]);\r\n };\r\n\r\n return {\r\n Provider: ({ value, children }) => {\r\n const prevValue = contexts.get(id);\r\n if (!Object.is(prevValue, value)) {\r\n contexts.set(id, value);\r\n }\r\n return children;\r\n },\r\n Consumer: ({ children }) => {\r\n const value = contexts.get(id);\r\n return children(value);\r\n },\r\n useSelector,\r\n _id: id\r\n };\r\n}\r\n\r\nexport function useContext<T>(context: Context<T>): T {\r\n return contexts.get(context._id);\r\n}\r\n","interface VNode {\r\n type: string | Function;\r\n props: Record<string, any>;\r\n key?: string | number;\r\n}\r\n\r\nfunction arePropsEqual(oldProps: any, newProps: any): boolean {\r\n const oldKeys = Object.keys(oldProps).filter(k => k !== 'children');\r\n const newKeys = Object.keys(newProps).filter(k => k !== 'children');\r\n \r\n if (oldKeys.length !== newKeys.length) return false;\r\n return oldKeys.every(key => oldProps[key] === newProps[key]);\r\n}\r\n\r\nexport function diff(oldNode: VNode | any, newNode: VNode | any): boolean {\r\n if (oldNode == null || newNode == null) return oldNode !== newNode;\r\n if (typeof oldNode !== typeof newNode) return true;\r\n if (typeof newNode === 'string' || typeof newNode === 'number')\r\n return oldNode !== newNode;\r\n if (newNode.type !== oldNode.type) return true;\r\n return !arePropsEqual(oldNode.props, newNode.props);\r\n}\r\n\r\nexport function shouldComponentUpdate(oldProps: any, newProps: any): boolean {\r\n return !arePropsEqual(oldProps, newProps);\r\n}\r\n","import { createElement } from './jsx-runtime';\r\nimport { prepareRender, finishRender, setRenderCallback } from './hooks';\r\nimport { batchUpdates } from './batch';\r\n\r\nexport { \r\n useState, \r\n useEffect, \r\n useMemo, \r\n useRef,\r\n useErrorBoundary \r\n} from './hooks';\r\n\r\nexport { createContext, useContext } from './context';\r\nexport { batchUpdates } from './batch';\r\n\r\nlet isHydrating = false;\r\n\r\nexport async function hydrate(element: any, container: HTMLElement) {\r\n isHydrating = true;\r\n try {\r\n await render(element, container);\r\n } finally {\r\n isHydrating = false;\r\n }\r\n}\r\n\r\nexport async function render(element: any, container: HTMLElement | null) {\r\n if (!container) {\r\n throw new Error('Container element is null');\r\n }\r\n\r\n console.log('Rendering to:', container.id);\r\n \r\n batchUpdates(async () => {\r\n const rendererId = prepareRender();\r\n try {\r\n setRenderCallback(render, element, container);\r\n const domNode = await createElement(element);\r\n \r\n if (!isHydrating) {\r\n container.innerHTML = '';\r\n }\r\n container.appendChild(domNode);\r\n \r\n } finally {\r\n finishRender();\r\n }\r\n });\r\n}\r\n\r\nexport { diff, shouldComponentUpdate } from './vdom';\r\n\r\n// Add JSX runtime\r\nexport const jsx = (type: any, props: any, key?: any) => ({\r\n type,\r\n props: {\r\n ...props,\r\n children: props?.children ? \r\n Array.isArray(props.children) ? props.children : [props.children]\r\n : []\r\n },\r\n key\r\n});\r\n\r\nexport const jsxs = jsx;\r\nexport const jsxDEV = jsx; // Add development runtime\r\nexport const Fragment = Symbol('Fragment');\r\n\r\n"],"names":["createElement","vnode","result","element","props","children","child","childElement","key","value","eventName","batchQueue","isBatchingUpdates","batchUpdates","callback","queuedCallback","isBatching","currentRender","states","stateIndices","effects","memos","refs","globalRenderCallback","globalContainer","currentElement","setRenderCallback","container","prepareRender","finishRender","useState","initial","componentStates","index","state","setState","newValue","nextValue","rerender","useEffect","deps","effectIndex","componentEffects","prevEffect","dep","i","cleanup","useMemo","factory","memoIndex","componentMemos","prevMemo","useRef","refIndex","componentRefs","ref","rendererId","effect","error","useErrorBoundary","setError","contexts","createContext","defaultValue","id","prevValue","selector","useContext","context","arePropsEqual","oldProps","newProps","oldKeys","k","newKeys","diff","oldNode","newNode","shouldComponentUpdate","isHydrating","hydrate","render","domNode","jsx","type","jsxs","jsxDEV","Fragment"],"mappings":"AAsBA,eAAsBA,EAAcC,GAAyC;AAI3E,MAHQ,QAAA,IAAI,0BAA0BA,CAAK,GAGvCA,KAAS;AACJ,WAAA,SAAS,eAAe,EAAE;AAInC,MAAI,OAAOA,KAAU,YAAY,OAAOA,KAAU;A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I,CAACA;AACG,UAAA,IAAI,MAAM,2BAA2B;AAGrC,UAAA,IAAI,iBAAiBA,EAAU,EAAE,GAEzCd,EAAa,YAAY;AACvB,UAAM2C,IAAa5B;AACf,QAAA;AACgB,MAAAF,EAAAuD,GAAQ9E,GAASwB,CAAS;AACtC,YAAAuD,IAAU,MAAMlF,EAAcG,CAAO;AAE3C,MAAK4E,MACHpD,EAAU,YAAY,KAExBA,EAAU,YAAYuD,CAAO;AAAA,IAAA,UAE7B;AACa,MAAArD;IACf;AAAA,EAAA,CACD;AACH;AAKO,MAAMsD,IAAM,CAACC,GAAWhF,GAAYI,OAAe;AAAA,EACxD,MAAA4E;AAAA,EACA,OAAO;AAAA,IACL,GAAGhF;AAAA,IACH,UAAUA,KAAA,QAAAA,EAAO,WACf,MAAM,QAAQA,EAAM,QAAQ,IAAIA,EAAM,WAAW,CAACA,EAAM,QAAQ,IAC9D,CAAC;AAAA,EACP;AAAA,EACA,KAAAI;AACF,IAEa6E,IAAOF,GACPG,IAASH,GACTI,IAAW,OAAO,UAAU;"}
@@ -7,4 +7,4 @@ export { jsx as jsxs, jsx as jsxDEV };
7
7
  export declare const Fragment: ({ children }: {
8
8
  children: any;
9
9
  }) => any;
10
- export declare function createElement(vnode: VNode | any): Promise<Node>;
10
+ export declare function createElement(vnode: any): Promise<HTMLElement | Text>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frontend-hamroun",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "A lightweight frontend framework with hooks and virtual DOM",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -19,14 +19,18 @@
19
19
  "import": "./dist/index.es.js",
20
20
  "require": "./dist/index.js",
21
21
  "default": "./dist/index.es.js"
22
- }
22
+ },
23
+ "./package.json": "./package.json"
23
24
  },
24
25
  "bin": {
25
26
  "frontend-hamroun": "./bin/cli.js",
26
27
  "create-frontend-app": "./bin/cli.js"
27
28
  },
28
29
  "scripts": {
29
- "build": "vite build && tsc --emitDeclarationOnly",
30
+ "dev": "npx concurrently \"npm:dev:lib\" \"npm:dev:test\"",
31
+ "dev:lib": "vite build --watch",
32
+ "dev:test": "vite serve test",
33
+ "build": "vite build --config vite.config.ts && tsc --project tsconfig.build.json",
30
34
  "clean": "node -e \"if(require('fs').existsSync('dist')) require('fs').rmSync('dist',{recursive:true})\"",
31
35
  "prepublishOnly": "npm run clean && npm run build"
32
36
  },
@@ -44,14 +48,13 @@
44
48
  "url": "your-repo-url"
45
49
  },
46
50
  "devDependencies": {
47
- "@types/react": "^19.0.8",
48
- "@vitejs/plugin-react": "^4.0.4",
49
51
  "nanospinner": "^1.1.0",
50
52
  "terser": "^5.38.1",
51
53
  "typescript": "^5.0.0",
52
54
  "vite": "^4.4.9",
53
55
  "vite-plugin-dts": "^4.5.0",
54
- "vitest": "^0.34.0"
56
+ "vitest": "^0.34.0",
57
+ "concurrently": "^8.2.2"
55
58
  },
56
59
  "publishConfig": {
57
60
  "access": "public"
@@ -3,10 +3,10 @@
3
3
  <head>
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <title>Frontend Hamroun App</title>
6
+ <title>Frontend App</title>
7
7
  </head>
8
8
  <body>
9
9
  <div id="app"></div>
10
- <script type="module" src="/src/main.ts"></script>
10
+ <script type="module" src="/src/main.tsx"></script>
11
11
  </body>
12
12
  </html>
@@ -5,14 +5,16 @@
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
8
- "build": "vite build",
9
- "preview": "vite preview"
8
+ "build": "tsc && vite build",
9
+ "preview": "vite preview",
10
+ "lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0"
10
11
  },
11
12
  "dependencies": {
12
- "frontend-hamroun": "^1.0.0"
13
+ "frontend-hamroun": "latest"
13
14
  },
14
15
  "devDependencies": {
15
- "vite": "^4.4.9",
16
- "typescript": "^5.0.0"
16
+ "@types/node": "^20.0.0",
17
+ "typescript": "^5.0.0",
18
+ "vite": "^4.4.9"
17
19
  }
18
20
  }
@@ -0,0 +1,14 @@
1
+ import { useState } from 'frontend-hamroun';
2
+
3
+ export default function App() {
4
+ const [count, setCount] = useState(0);
5
+
6
+ return (
7
+ <div>
8
+ <h1>Count: {count}</h1>
9
+ <button onClick={() => setCount(c => c + 1)}>
10
+ Increment
11
+ </button>
12
+ </div>
13
+ );
14
+ }
@@ -0,0 +1,9 @@
1
+ import { render } from 'frontend-hamroun';
2
+ import App from './App';
3
+
4
+ const container = document.getElementById('app');
5
+ if (!container) {
6
+ throw new Error('#app element not found in document');
7
+ }
8
+
9
+ render(<App />, container);
@@ -0,0 +1,26 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "useDefineForClassFields": true,
5
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
6
+ "module": "ESNext",
7
+ "skipLibCheck": true,
8
+ "moduleResolution": "bundler",
9
+ "allowImportingTsExtensions": true,
10
+ "resolveJsonModule": true,
11
+ "isolatedModules": true,
12
+ "noEmit": true,
13
+ "jsx": "preserve",
14
+ "jsxFactory": "jsx",
15
+ "jsxFragmentFactory": "Fragment",
16
+ "strict": true,
17
+ "noUnusedLocals": true,
18
+ "noUnusedParameters": true,
19
+ "noFallthroughCasesInSwitch": true,
20
+ "paths": {
21
+ "@/*": ["./src/*"]
22
+ }
23
+ },
24
+ "include": ["src"],
25
+ "references": [{ "path": "./tsconfig.node.json" }]
26
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "compilerOptions": {
3
+ "composite": true,
4
+ "skipLibCheck": true,
5
+ "module": "ESNext",
6
+ "moduleResolution": "bundler",
7
+ "allowSyntheticDefaultImports": true
8
+ },
9
+ "include": ["vite.config.ts"]
10
+ }
@@ -0,0 +1,16 @@
1
+ import { defineConfig } from 'vite';
2
+ import { resolve } from 'path';
3
+
4
+ export default defineConfig({
5
+ resolve: {
6
+ alias: {
7
+ '@': '/src',
8
+ 'frontend-hamroun': resolve(__dirname, '../../src/index.ts')
9
+ }
10
+ },
11
+ esbuild: {
12
+ jsxFactory: 'jsx',
13
+ jsxFragment: 'Fragment',
14
+ jsxInject: `import { jsx, Fragment } from 'frontend-hamroun'`
15
+ }
16
+ });
@@ -1,192 +0,0 @@
1
- async function m(t) {
2
- var e;
3
- if (console.log("Creating element from:", t), t == null || typeof t == "boolean")
4
- return document.createTextNode("");
5
- if (typeof t == "number" || typeof t == "string")
6
- return document.createTextNode(String(t));
7
- if (Array.isArray(t)) {
8
- const r = document.createDocumentFragment();
9
- for (const s of t) {
10
- const n = await m(s);
11
- r.appendChild(n);
12
- }
13
- return r;
14
- }
15
- if ("type" in t && t.props !== void 0) {
16
- const { type: r, props: s } = t;
17
- if (typeof r == "function")
18
- try {
19
- const c = await r(s || {}), a = await m(c);
20
- return a instanceof Element && a.setAttribute("data-component-id", r.name || r.toString()), a;
21
- } catch (c) {
22
- return console.error("Error rendering component:", c), document.createTextNode("");
23
- }
24
- const n = document.createElement(r);
25
- for (const [c, a] of Object.entries(s || {}))
26
- if (c !== "children")
27
- if (c.startsWith("on") && typeof a == "function") {
28
- const f = c.toLowerCase().slice(2), S = (e = n.__events) == null ? void 0 : e[f];
29
- S && n.removeEventListener(f, S), n.addEventListener(f, a), n.__events || (n.__events = {}), n.__events[f] = a;
30
- } else
31
- c === "style" && typeof a == "object" ? Object.assign(n.style, a) : c === "className" ? n.setAttribute("class", String(a)) : c !== "key" && c !== "ref" && n.setAttribute(c, String(a));
32
- const i = s == null ? void 0 : s.children;
33
- if (i != null) {
34
- const c = Array.isArray(i) ? i.flat() : [i];
35
- for (const a of c) {
36
- const f = await m(a);
37
- n.appendChild(f);
38
- }
39
- }
40
- return n;
41
- }
42
- return document.createTextNode(String(t));
43
- }
44
- let h = [], p = !1;
45
- function _(t) {
46
- if (p) {
47
- h.push(t);
48
- return;
49
- }
50
- p = !0;
51
- try {
52
- for (t(); h.length > 0; ) {
53
- const e = h.shift();
54
- e == null || e();
55
- }
56
- } finally {
57
- p = !1;
58
- }
59
- }
60
- function R() {
61
- return p;
62
- }
63
- let o = 0;
64
- const g = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map(), w = /* @__PURE__ */ new Map();
65
- let b = null, E = null, x = null;
66
- function A(t, e, r) {
67
- b = t, E = r, x = e;
68
- }
69
- function T() {
70
- return o++, u.set(o, 0), o;
71
- }
72
- function j() {
73
- o = 0;
74
- }
75
- function v(t) {
76
- if (!o)
77
- throw new Error("useState must be called within a render");
78
- g.has(o) || g.set(o, []);
79
- const e = g.get(o), r = u.get(o);
80
- r >= e.length && e.push(t);
81
- const s = e[r], n = (i) => {
82
- const c = typeof i == "function" ? i(e[r]) : i;
83
- e[r] !== c && (e[r] = c, R() ? _(() => C(o)) : C(o));
84
- };
85
- return u.set(o, r + 1), [s, n];
86
- }
87
- function L(t, e) {
88
- if (!o)
89
- throw new Error("useEffect must be called within a render");
90
- const r = u.get(o);
91
- d.has(o) || d.set(o, []);
92
- const s = d.get(o), n = s[r];
93
- (!n || !e || !n.deps || e.some((i, c) => i !== n.deps[c])) && (n != null && n.cleanup && n.cleanup(), queueMicrotask(() => {
94
- const i = t() || void 0;
95
- s[r] = { cleanup: i, deps: e };
96
- })), u.set(o, r + 1);
97
- }
98
- function I(t, e) {
99
- if (!o)
100
- throw new Error("useMemo must be called within a render");
101
- const r = u.get(o);
102
- y.has(o) || y.set(o, []);
103
- const s = y.get(o), n = s[r];
104
- if (!n || e && e.some((i, c) => !Object.is(i, n.deps[c]))) {
105
- const i = t();
106
- return s[r] = { value: i, deps: e }, u.set(o, r + 1), i;
107
- }
108
- return u.set(o, r + 1), n.value;
109
- }
110
- function O(t) {
111
- if (!o)
112
- throw new Error("useRef must be called within a render");
113
- const e = u.get(o);
114
- w.has(o) || w.set(o, []);
115
- const r = w.get(o);
116
- if (e >= r.length) {
117
- const n = { current: t };
118
- return r.push(n), u.set(o, e + 1), n;
119
- }
120
- const s = r[e];
121
- return u.set(o, e + 1), s;
122
- }
123
- async function C(t) {
124
- try {
125
- const e = d.get(t);
126
- e && (e.forEach((r) => {
127
- r.cleanup && r.cleanup();
128
- }), d.set(t, [])), b && E && x && await b(x, E);
129
- } catch (e) {
130
- console.error("Error during rerender:", e);
131
- }
132
- }
133
- function k() {
134
- const [t, e] = v(null);
135
- return [t, () => e(null)];
136
- }
137
- const l = /* @__PURE__ */ new Map();
138
- function B(t) {
139
- const e = Symbol();
140
- return l.set(e, t), {
141
- Provider: ({ value: s, children: n }) => {
142
- const i = l.get(e);
143
- return Object.is(i, s) || l.set(e, s), n;
144
- },
145
- Consumer: ({ children: s }) => {
146
- const n = l.get(e);
147
- return s(n);
148
- },
149
- useSelector: (s) => {
150
- const n = l.get(e);
151
- return I(() => s(n), [n]);
152
- },
153
- _id: e
154
- };
155
- }
156
- function H(t) {
157
- return l.get(t._id);
158
- }
159
- let M = !1;
160
- async function U(t, e) {
161
- M = !0;
162
- try {
163
- await N(t, e);
164
- } finally {
165
- M = !1;
166
- }
167
- }
168
- async function N(t, e) {
169
- console.log("Rendering to:", e.id), _(async () => {
170
- const r = T();
171
- try {
172
- A(N, t, e);
173
- const s = await m(t);
174
- M || (e.innerHTML = ""), e.appendChild(s);
175
- } finally {
176
- j();
177
- }
178
- });
179
- }
180
- export {
181
- _ as batchUpdates,
182
- B as createContext,
183
- U as hydrate,
184
- N as render,
185
- H as useContext,
186
- L as useEffect,
187
- k as useErrorBoundary,
188
- I as useMemo,
189
- O as useRef,
190
- v as useState
191
- };
192
- //# sourceMappingURL=frontend-hamroun.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"frontend-hamroun.js","sources":["../src/jsx-runtime.ts","../src/batch.ts","../src/hooks.ts","../src/context.ts","../src/index.ts"],"sourcesContent":["import type { Component } from './component';\r\n\r\ninterface VNode {\r\n type: string | Function;\r\n props: Record<string, any>;\r\n}\r\n\r\nexport function jsx(type: string | Function, props: any): VNode {\r\n console.log('JSX Transform:', { type, props });\r\n const processedProps = { ...props };\r\n \r\n // Handle children properly\r\n if (arguments.length > 2) {\r\n processedProps.children = Array.prototype.slice.call(arguments, 2);\r\n }\r\n \r\n return { type, props: processedProps };\r\n}\r\n\r\nexport { jsx as jsxs, jsx as jsxDEV };\r\nexport const Fragment = ({ children }: { children: any }) => children;\r\n\r\nexport async function createElement(vnode: VNode | any): Promise<Node> {\r\n console.log('Creating element from:', vnode);\r\n\r\n // Handle primitives and null\r\n if (vnode == null) {\r\n return document.createTextNode('');\r\n }\r\n \r\n if (typeof vnode === 'boolean') {\r\n return document.createTextNode('');\r\n }\r\n\r\n if (typeof vnode === 'number' || typeof vnode === 'string') {\r\n return document.createTextNode(String(vnode));\r\n }\r\n\r\n // Handle arrays\r\n if (Array.isArray(vnode)) {\r\n const fragment = document.createDocumentFragment();\r\n for (const child of vnode) {\r\n const node = await createElement(child);\r\n fragment.appendChild(node);\r\n }\r\n return fragment;\r\n }\r\n\r\n // Handle VNode\r\n if ('type' in vnode && vnode.props !== undefined) {\r\n const { type, props } = vnode;\r\n \r\n // Handle function components\r\n if (typeof type === 'function') {\r\n try {\r\n const result = await type(props || {});\r\n const node = await createElement(result);\r\n if (node instanceof Element) {\r\n node.setAttribute('data-component-id', type.name || type.toString());\r\n }\r\n return node;\r\n } catch (error) {\r\n console.error('Error rendering component:', error);\r\n return document.createTextNode('');\r\n }\r\n }\r\n\r\n // Create DOM element\r\n const element = document.createElement(type as string);\r\n \r\n // Handle props\r\n for (const [key, value] of Object.entries(props || {})) {\r\n if (key === 'children') continue;\r\n if (key.startsWith('on') && typeof value === 'function') {\r\n const eventName = key.toLowerCase().slice(2);\r\n // Remove existing event listener if any\r\n const existingHandler = (element as any).__events?.[eventName];\r\n if (existingHandler) {\r\n element.removeEventListener(eventName, existingHandler);\r\n }\r\n \r\n // Add new event listener\r\n element.addEventListener(eventName, value as EventListener);\r\n if (!(element as any).__events) {\r\n (element as any).__events = {};\r\n }\r\n (element as any).__events[eventName] = value;\r\n } else if (key === 'style' && typeof value === 'object') {\r\n Object.assign(element.style, value);\r\n } else if (key === 'className') {\r\n element.setAttribute('class', String(value));\r\n } else if (key !== 'key' && key !== 'ref') {\r\n element.setAttribute(key, String(value));\r\n }\r\n }\r\n\r\n // Handle children\r\n const children = props?.children;\r\n if (children != null) {\r\n const childArray = Array.isArray(children) ? children.flat() : [children];\r\n for (const child of childArray) {\r\n const childNode = await createElement(child);\r\n element.appendChild(childNode);\r\n }\r\n }\r\n\r\n return element;\r\n }\r\n\r\n // Handle other objects by converting to string\r\n return document.createTextNode(String(vnode));\r\n}\r\n","type BatchCallback = () => void;\r\nlet batchQueue: BatchCallback[] = [];\r\nlet isBatchingUpdates = false;\r\n\r\nexport function batchUpdates(callback: BatchCallback) {\r\n if (isBatchingUpdates) {\r\n batchQueue.push(callback);\r\n return;\r\n }\r\n\r\n isBatchingUpdates = true;\r\n try {\r\n callback();\r\n while (batchQueue.length > 0) {\r\n const queuedCallback = batchQueue.shift();\r\n queuedCallback?.();\r\n }\r\n } finally {\r\n isBatchingUpdates = false;\r\n }\r\n}\r\n\r\nexport function isBatching() {\r\n return isBatchingUpdates;\r\n}\r\n","import { createElement } from './jsx-runtime';\r\nimport { batchUpdates, isBatching } from './batch';\r\nimport { diff } from './vdom';\r\n\r\nlet currentRender: number = 0;\r\nconst states = new Map<number, any[]>();\r\nconst stateIndices = new Map<number, number>();\r\nconst effects = new Map<number, Effect[]>();\r\nconst memos = new Map<number, { value: any; deps: any[] }[]>();\r\nconst refs = new Map<number, any[]>();\r\n\r\ninterface Effect {\r\n cleanup?: () => void;\r\n deps?: any[];\r\n}\r\n\r\n// Add at the top with other declarations\r\nlet globalRenderCallback: ((element: any, container: HTMLElement) => void) | null = null;\r\nlet globalContainer: HTMLElement | null = null;\r\nlet currentElement: any = null;\r\n\r\nexport function setRenderCallback(\r\n callback: (element: any, container: HTMLElement) => void,\r\n element: any,\r\n container: HTMLElement\r\n) {\r\n globalRenderCallback = callback;\r\n globalContainer = container;\r\n currentElement = element;\r\n}\r\n\r\nexport function prepareRender() {\r\n currentRender++;\r\n stateIndices.set(currentRender, 0);\r\n return currentRender;\r\n}\r\n\r\nexport function finishRender() {\r\n currentRender = 0;\r\n}\r\n\r\nexport function useState<T>(initial: T): [T, (value: T | ((prev: T) => T)) => void] {\r\n if (!currentRender) {\r\n throw new Error('useState must be called within a render');\r\n }\r\n\r\n if (!states.has(currentRender)) {\r\n states.set(currentRender, []);\r\n }\r\n\r\n const componentStates = states.get(currentRender)!;\r\n const index = stateIndices.get(currentRender)!;\r\n \r\n if (index >= componentStates.length) {\r\n componentStates.push(initial);\r\n }\r\n\r\n const state = componentStates[index];\r\n const setState = (newValue: T | ((prev: T) => T)) => {\r\n const nextValue = typeof newValue === 'function' \r\n ? (newValue as Function)(componentStates[index])\r\n : newValue;\r\n\r\n if (componentStates[index] === nextValue) return; // Skip if value hasn't changed\r\n \r\n componentStates[index] = nextValue;\r\n \r\n if (isBatching()) {\r\n batchUpdates(() => rerender(currentRender));\r\n } else {\r\n rerender(currentRender);\r\n }\r\n };\r\n\r\n stateIndices.set(currentRender, index + 1);\r\n return [state, setState];\r\n}\r\n\r\nexport function useEffect(callback: () => (() => void) | void, deps?: any[]) {\r\n if (!currentRender) throw new Error('useEffect must be called within a render');\r\n \r\n const effectIndex = stateIndices.get(currentRender)!;\r\n \r\n if (!effects.has(currentRender)) {\r\n effects.set(currentRender, []);\r\n }\r\n\r\n const componentEffects = effects.get(currentRender)!;\r\n const prevEffect = componentEffects[effectIndex];\r\n \r\n // Run effect if deps changed\r\n if (!prevEffect || !deps || !prevEffect.deps || \r\n deps.some((dep, i) => dep !== prevEffect.deps![i])) {\r\n \r\n // Cleanup previous effect\r\n if (prevEffect?.cleanup) {\r\n prevEffect.cleanup();\r\n }\r\n\r\n // Schedule new effect\r\n queueMicrotask(() => {\r\n const cleanup = callback() || undefined;\r\n componentEffects[effectIndex] = { cleanup: cleanup, deps };\r\n });\r\n }\r\n \r\n stateIndices.set(currentRender, effectIndex + 1);\r\n}\r\n\r\nexport function useMemo<T>(factory: () => T, deps: any[]): T {\r\n if (!currentRender) throw new Error('useMemo must be called within a render');\r\n \r\n const memoIndex = stateIndices.get(currentRender)!;\r\n \r\n if (!memos.has(currentRender)) {\r\n memos.set(currentRender, []);\r\n }\r\n\r\n const componentMemos = memos.get(currentRender)!;\r\n const prevMemo = componentMemos[memoIndex];\r\n \r\n if (!prevMemo || (deps && deps.some((dep, i) => !Object.is(dep, prevMemo.deps[i])))) {\r\n const value = factory();\r\n componentMemos[memoIndex] = { value, deps };\r\n stateIndices.set(currentRender, memoIndex + 1);\r\n return value;\r\n }\r\n\r\n stateIndices.set(currentRender, memoIndex + 1);\r\n return prevMemo.value;\r\n}\r\n\r\nexport function useRef<T>(initial: T) {\r\n if (!currentRender) throw new Error('useRef must be called within a render');\r\n \r\n const refIndex = stateIndices.get(currentRender)!;\r\n \r\n if (!refs.has(currentRender)) {\r\n refs.set(currentRender, []);\r\n }\r\n\r\n const componentRefs = refs.get(currentRender)!;\r\n if (refIndex >= componentRefs.length) {\r\n // Initialize with an object that has a current property\r\n const ref = { current: initial };\r\n componentRefs.push(ref);\r\n stateIndices.set(currentRender, refIndex + 1);\r\n return ref;\r\n }\r\n\r\n const ref = componentRefs[refIndex];\r\n stateIndices.set(currentRender, refIndex + 1);\r\n return ref;\r\n}\r\n\r\n// Add a map to track component DOM nodes\r\nconst componentNodes = new Map<Function, Node>();\r\n\r\nasync function rerender(rendererId: number) {\r\n try {\r\n // Clean up effects\r\n const componentEffects = effects.get(rendererId);\r\n if (componentEffects) {\r\n componentEffects.forEach(effect => {\r\n if (effect.cleanup) effect.cleanup();\r\n });\r\n effects.set(rendererId, []);\r\n }\r\n\r\n if (globalRenderCallback && globalContainer && currentElement) {\r\n await globalRenderCallback(currentElement, globalContainer);\r\n }\r\n } catch (error) {\r\n console.error('Error during rerender:', error);\r\n }\r\n}\r\n\r\n// Add new hook for error boundaries\r\nexport function useErrorBoundary(): [Error | null, () => void] {\r\n const [error, setError] = useState<Error | null>(null);\r\n return [error, () => setError(null)];\r\n}\r\n\r\n// Remove withHooks export\r\n","import { useMemo } from \"./hooks\";\r\n\r\nconst contexts = new Map<symbol, any>();\r\nlet currentRender: Function | null = null;\r\n\r\nexport interface Context<T> {\r\n Provider: (props: { value: T; children?: any }) => any;\r\n Consumer: (props: { children: (value: T) => any }) => any;\r\n _id: symbol;\r\n useSelector: <S>(selector: (state: T) => S) => S;\r\n}\r\n\r\nexport function createContext<T>(defaultValue: T): Context<T> {\r\n const id = Symbol();\r\n contexts.set(id, defaultValue);\r\n \r\n const useSelector = <S>(selector: (state: T) => S): S => {\r\n const value = contexts.get(id);\r\n return useMemo(() => selector(value), [value]);\r\n };\r\n\r\n return {\r\n Provider: ({ value, children }) => {\r\n const prevValue = contexts.get(id);\r\n if (!Object.is(prevValue, value)) {\r\n contexts.set(id, value);\r\n }\r\n return children;\r\n },\r\n Consumer: ({ children }) => {\r\n const value = contexts.get(id);\r\n return children(value);\r\n },\r\n useSelector,\r\n _id: id\r\n };\r\n}\r\n\r\nexport function useContext<T>(context: Context<T>): T {\r\n return contexts.get(context._id);\r\n}\r\n","import { createElement } from './jsx-runtime';\r\nimport { prepareRender, finishRender, setRenderCallback } from './hooks';\r\nimport { batchUpdates } from './batch';\r\n\r\nexport { \r\n useState, \r\n useEffect, \r\n useMemo, \r\n useRef,\r\n useErrorBoundary \r\n} from './hooks';\r\n\r\nexport { createContext, useContext } from './context';\r\nexport { batchUpdates } from './batch';\r\n\r\nlet isHydrating = false;\r\n\r\nexport async function hydrate(element: any, container: HTMLElement) {\r\n isHydrating = true;\r\n try {\r\n await render(element, container);\r\n } finally {\r\n isHydrating = false;\r\n }\r\n}\r\n\r\nexport async function render(element: any, container: HTMLElement) {\r\n console.log('Rendering to:', container.id);\r\n \r\n batchUpdates(async () => {\r\n const rendererId = prepareRender();\r\n try {\r\n setRenderCallback(render, element, container);\r\n const domNode = await createElement(element);\r\n \r\n if (!isHydrating) {\r\n container.innerHTML = '';\r\n }\r\n container.appendChild(domNode);\r\n \r\n } finally {\r\n finishRender();\r\n }\r\n });\r\n}\r\n\r\n"],"names":["createElement","vnode","_a","fragment","child","node","type","props","result","error","element","key","value","eventName","existingHandler","children","childArray","childNode","batchQueue","isBatchingUpdates","batchUpdates","callback","queuedCallback","isBatching","currentRender","states","stateIndices","effects","memos","refs","globalRenderCallback","globalContainer","currentElement","setRenderCallback","container","prepareRender","finishRender","useState","initial","componentStates","index","state","setState","newValue","nextValue","rerender","useEffect","deps","effectIndex","componentEffects","prevEffect","dep","i","cleanup","useMemo","factory","memoIndex","componentMemos","prevMemo","useRef","refIndex","componentRefs","ref","rendererId","effect","useErrorBoundary","setError","contexts","createContext","defaultValue","id","prevValue","selector","useContext","context","isHydrating","hydrate","render","domNode"],"mappings":"AAsBA,eAAsBA,EAAcC,GAAmC;AAAvE,MAAAC;AAQM,MAPI,QAAA,IAAI,0BAA0BD,CAAK,GAGvCA,KAAS,QAIT,OAAOA,KAAU;AACZ,WAAA,SAAS,eAAe,EAAE;AAGnC,MAAI,OAAOA,KAAU,YAAY,OAAOA,KAAU;AAChD,WAAO,SAAS,eAAe,OAAOA,CAAK,CAAC;AAI1C,MAAA,MAAM,QAAQA,CAAK,GAAG;AAClB,UAAAE,IAAW,SAAS;AAC1B,eAAWC,KAASH,GAAO;AACnB,YAAAI,IAAO,MAAML,EAAcI,CAAK;AACtC,MAAAD,EAAS,YAAYE,CAAI;AAAA,IAC3B;AACO,WAAAF;AAAA,EACT;AAGA,MAAI,UAAUF,KAASA,EAAM,UAAU,QAAW;AAC1C,UAAA,EAAE,MAAAK,GAAM,OAAAC,EAAU,IAAAN;AAGpB,QAAA,OAAOK,KAAS;AACd,UAAA;AACF,cAAME,IAAS,MAAMF,EAAKC,KAAS,CAAE,CAAA,GAC/BF,IAAO,MAAML,EAAcQ,CAAM;AACvC,eAAIH,aAAgB,WAClBA,EAAK,aAAa,qBAAqBC,EAAK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AzD,GAAO,UAAAG,QAAe;AAC3B,YAAAwD,IAAYJ,EAAS,IAAIG,CAAE;AACjC,aAAK,OAAO,GAAGC,GAAW3D,CAAK,KACpBuD,EAAA,IAAIG,GAAI1D,CAAK,GAEjBG;AAAA,IACT;AAAA,IACA,UAAU,CAAC,EAAE,UAAAA,QAAe;AACpB,YAAAH,IAAQuD,EAAS,IAAIG,CAAE;AAC7B,aAAOvD,EAASH,CAAK;AAAA,IACvB;AAAA,IACA,aAjBkB,CAAI4D,MAAiC;AACjD,YAAA5D,IAAQuD,EAAS,IAAIG,CAAE;AAC7B,aAAOhB,EAAQ,MAAMkB,EAAS5D,CAAK,GAAG,CAACA,CAAK,CAAC;AAAA,IAAA;AAAA,IAgB7C,KAAK0D;AAAA,EAAA;AAET;AAEO,SAASG,EAAcC,GAAwB;AAC7C,SAAAP,EAAS,IAAIO,EAAQ,GAAG;AACjC;ACzBA,IAAIC,IAAc;AAEI,eAAAC,EAAQlE,GAAcwB,GAAwB;AACpD,EAAAyC,IAAA;AACV,MAAA;AACI,UAAAE,EAAOnE,GAASwB,CAAS;AAAA,EAAA,UAC/B;AACc,IAAAyC,IAAA;AAAA,EAChB;AACF;AAEsB,eAAAE,EAAOnE,GAAcwB,GAAwB;AACzD,UAAA,IAAI,iBAAiBA,EAAU,EAAE,GAEzCd,EAAa,YAAY;AACvB,UAAM2C,IAAa5B;AACf,QAAA;AACgB,MAAAF,EAAA4C,GAAQnE,GAASwB,CAAS;AACtC,YAAA4C,IAAU,MAAM9E,EAAcU,CAAO;AAE3C,MAAKiE,MACHzC,EAAU,YAAY,KAExBA,EAAU,YAAY4C,CAAO;AAAA,IAAA,UAE7B;AACa,MAAA1C;IACf;AAAA,EAAA,CACD;AACH;"}
@@ -1,26 +0,0 @@
1
- import { useState } from 'frontend-hamroun';
2
-
3
- export default function App() {
4
- const [count, setCount] = useState(0);
5
-
6
- return {
7
- type: 'div',
8
- props: {
9
- children: [
10
- {
11
- type: 'h1',
12
- props: {
13
- children: 'Frontend Hamroun App'
14
- }
15
- },
16
- {
17
- type: 'button',
18
- props: {
19
- onClick: () => setCount(count + 1),
20
- children: `Count: ${count}`
21
- }
22
- }
23
- ]
24
- }
25
- };
26
- }
@@ -1,4 +0,0 @@
1
- import { render } from 'frontend-hamroun';
2
- import App from './App';
3
-
4
- render(App(), document.getElementById('app')!);