olova 2.0.11 → 2.0.13

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.
@@ -1,18 +1,18 @@
1
- name: Publish to NPM
2
-
3
- on:
4
- push:
5
- branches: [ main ]
6
-
7
- jobs:
8
- publish:
9
- runs-on: ubuntu-latest
10
- steps:
11
- - uses: actions/checkout@v2
12
- - uses: actions/setup-node@v2
13
- with:
14
- node-version: '14'
15
- registry-url: 'https://registry.npmjs.org'
16
- - run: yarn publish
17
- env:
18
- NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
1
+ name: Publish to NPM
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+
7
+ jobs:
8
+ publish:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v2
12
+ - uses: actions/setup-node@v2
13
+ with:
14
+ node-version: '14'
15
+ registry-url: 'https://registry.npmjs.org'
16
+ - run: yarn publish
17
+ env:
18
+ NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
package/README.md CHANGED
@@ -1,54 +1 @@
1
- # Olova JavaScript Framework
2
-
3
- Olova is a lightweight and reactive JavaScript framework that simplifies UI
4
- development with a clean, intuitive syntax. It provides a reactivity system and
5
- hooks to manage state and side effects, allowing developers to build modern web
6
- applications with ease.
7
-
8
- ## Features
9
-
10
- - **State Management**: Use the `State` hook to manage reactive state in your
11
- components.
12
- - **Side Effects**: Use the `Effect` hook to run side effects in response to
13
- state changes.
14
- - **JSX-style Syntax**: Write UI components using a simple, declarative
15
- JSX-style syntax.
16
- - **Reactivity**: Automatically re-render components when state changes.
17
-
18
- ## Installation
19
-
20
- To get started with Olova, first install the core library via npm or yarn.
21
-
22
- ```bash
23
- npm install olova
24
- ```
25
-
26
- or
27
-
28
- ```bash
29
- yarn add olova
30
- ```
31
-
32
- ## Example Usage
33
-
34
- Here is an example of a basic component in Olova:
35
-
36
- ```js
37
- import Olova, { State, Effect } from "olova";
38
-
39
- export default function Home() {
40
- const [count, setCount] = State(0);
41
-
42
- Effect(() => {
43
- console.log("Home is rendered");
44
- console.log(count);
45
- }, [count]);
46
-
47
- return (
48
- <>
49
- <h1>{count}</h1>
50
- <button onClick={() => setCount(count + 1)}>Increment</button>
51
- </>
52
- );
53
- }
54
- ```
1
+
package/dist/olova.d.ts CHANGED
@@ -1 +1 @@
1
- declare module "olova";
1
+ declare module "olova";
package/dist/olova.js CHANGED
@@ -1 +1 @@
1
- import{createSignal as $state}from"./hooks/createSignal";import{createEffect as $effect}from"./hooks/createEffect";import{createMemo as $memo}from"./hooks/createMemo";import{createRef as $ref}from"./hooks/createRef";function h(e,t={},...n){if(e===h.Fragment){const e=document.createDocumentFragment(),t=n.flat();for(let n=0;n<t.length;n++){const o=t[n];if("function"==typeof o){const t=document.createTextNode("");$effect((()=>{const n=o();if(Array.isArray(n)){const o=t.previousSibling;o&&o.remove();const r=document.createDocumentFragment();for(let e=0;e<n.length;e++){const t=n[e];r.appendChild(t instanceof Node?t:document.createTextNode(String(t)))}e.insertBefore(r,t)}else t.textContent=String(n)})),e.appendChild(t)}else o instanceof Node?e.appendChild(o):null!=o&&e.appendChild(document.createTextNode(String(o)))}return e}const o="function"==typeof e?e(t):document.createElement(e);if("function"!=typeof e){if(t){const e=Object.entries(t);for(let t=0;t<e.length;t++){const[n,r]=e[t];"ref"===n?queueMicrotask((()=>{r&&"object"==typeof r&&(r.current=o)})):n.startsWith("on")?o.addEventListener(n.slice(2).toLowerCase(),r):"style"===n&&"object"==typeof r?Object.assign(o.style,r):"className"===n?o.className=r:o.setAttribute(n,r)}}const e=document.createTextNode(""),r=n.flat();for(let t=0;t<r.length;t++){const n=r[t];if("function"==typeof n)$effect((()=>{const t=n();if(Array.isArray(t)){o.textContent="";const e=document.createDocumentFragment();for(let n=0;n<t.length;n++){const o=t[n];e.appendChild(o instanceof Node?o:document.createTextNode(String(o)))}o.appendChild(e)}else e.textContent=String(t),e.parentNode||o.appendChild(e)}));else if(Array.isArray(n)){const e=document.createDocumentFragment();for(let t=0;t<n.length;t++){const o=n[t];o instanceof Node?e.appendChild(o):null!=o&&e.appendChild(document.createTextNode(String(o)))}o.appendChild(e)}else n instanceof Node?o.appendChild(n):null!=n&&o.appendChild(document.createTextNode(String(n)))}}return o}h.Fragment=Symbol("Fragment");const Fragment=h.Fragment;export{h,$state,$effect,$memo,Fragment,$ref};
1
+ let BATCH_UPDATES=Symbol("BATCH_UPDATES"),SIGNAL_TYPE=Symbol("SIGNAL_TYPE");class SubscriptionManager{constructor(){this.globalSubs=new Set,this.propSubs=new Map,this.weakPropSubs=new WeakMap,this.dependencies=new WeakMap,this.batchMode=!1,this.pendingDeps=new Set}subscribe(e,t){if(!t)return;this.dependencies.has(t)||this.dependencies.set(t,new Set);let n=this.dependencies.get(t);if(!n.has(e)){if(n.add(e),!e)return void this.globalSubs.add(t);let r="object"==typeof e?this.weakPropSubs:this.propSubs;r.has(e)||r.set(e,new Set),r.get(e).add(t)}}notify(e,t=new Set){if(this.batchMode)return this.pendingDeps.add(e),t;if(e){let n=this.propSubs.get(e);if(n&&this.notifyDependentSubs(n,e,t),"object"==typeof e){let n=this.weakPropSubs.get(e);n&&this.notifyDependentSubs(n,e,t)}}return this.notifyDependentSubs(this.globalSubs,e,t),t}startBatch(){this.batchMode=!0,this.pendingDeps.clear()}endBatch(){this.batchMode=!1;let e=new Set;for(let t of this.pendingDeps)this.notify(t,e);return this.pendingDeps.clear(),e}notifyDependentSubs(e,t,n){for(let r of e)if(!n.has(r)){let e=this.dependencies.get(r);(!t||!e||e.has(t))&&(r(),n.add(r))}}cleanup(e){if(e)for(let[t,n]of(this.propSubs.delete(e),this.dependencies))n.delete(e),0===n.size&&this.dependencies.delete(t)}}class BatchQueue{constructor(){this.updates=new Map,this.priorities=new Map,this.timeouts=new Map,this.debounceTime=16}add(e,t,n=0,r=!1){if(r)return this.timeouts.has(e)&&clearTimeout(this.timeouts.get(e)),void this.timeouts.set(e,setTimeout((()=>{this.addImmediate(e,t,n),this.timeouts.delete(e)}),this.debounceTime));this.addImmediate(e,t,n)}addImmediate(e,t,n){if(this.updates.has(e)){let r=this.updates.get(e),i=this.priorities.get(e)||0;"object"==typeof r&&"object"==typeof t&&(t={...r,...t}),n=Math.max(i,n)}this.updates.set(e,t),this.priorities.set(e,n)}process(e){if(0!==this.updates.size){if(this.timeouts.size>0)return void Promise.all(Array.from(this.timeouts.values()).map((e=>new Promise((t=>{let n=setInterval((()=>{this.timeouts.has(e)||(clearInterval(n),t())}),0)}))))).then((()=>this.processImmediate(e)));this.processImmediate(e)}}processImmediate(e){let t=[...this.updates.entries()].sort(((e,t)=>(this.priorities.get(t[0])||0)-(this.priorities.get(e[0])||0)));e.startBatch();let n=new Set;for(let[r,i]of t)"function"==typeof i&&i(),e.notify(r,n);e.endBatch(),this.updates.clear(),this.priorities.clear()}clear(){this.timeouts.forEach((e=>clearTimeout(e))),this.timeouts.clear(),this.updates.clear(),this.priorities.clear()}}let createSignal=(e,t={})=>{let{equals:n=Object.is,immediate:r=!0,batched:i=!1,debounce:o=!1}=t,a=e,l=new SubscriptionManager,s=new BatchQueue,c=e=>{let t=getCurrentContext();return t&&l.subscribe(e,t),e?a[e]:a};return c[BATCH_UPDATES]=()=>(l.startBatch(),()=>{l.endBatch(),s.clear()}),c[SIGNAL_TYPE]=!0,[c,(e,t,r=0)=>{let c="function"==typeof e?e(t?a[t]:a):e;(t?!n(a[t],c):!n(a,c))&&(a=t?{...a,[t]:c}:c,i?(s.add(t,c,r,o),queueMicrotask((()=>{s.process(l)}))):l.notify(t))}]};function createEffect(e,t={defer:!1}){let n=null,r=new Set,i=()=>{n&&n(),r.clear(),currentContext=i;try{n=e()||null}finally{currentContext=null}};return t.defer||i(),i}function createMemo(e,t={}){let[n,r]=createSignal(void 0,t),i=!1,o=new Set;return createEffect((()=>{o.clear();let a=e();i&&t.equals&&t.equals(n(),a)||(r(a),i=!0)})),n}function createResource(e,t={}){let{initialValue:n=null,cacheTime:r=5e3,retries:i=3,retryDelay:o=1e3,lazy:a=!1}=t,[l,s]=createSignal(n),[c,d]=createSignal(!1),[u,f]=createSignal(null),h=new Map,p=new Map,m=0,g=e=>{e?(h.delete(e),p.has(e)&&(clearTimeout(p.get(e)),p.delete(e))):(h.clear(),p.forEach((e=>clearTimeout(e))),p.clear())},y=async t=>{let n=JSON.stringify(t);if(h.has(n))return h.get(n);d(!0),f(null),m=0;let a=async()=>{try{let i=await e(t);return s(i),h.set(n,i),r>0&&p.set(n,setTimeout((()=>g(n)),r)),i}catch(e){if(m<i)return await new Promise((e=>setTimeout(e,o*++m))),a();throw f(e),e}finally{d(!1)}};return a()};return a||y(),{data:l,loading:c,error:u,refetch:y,clearCache:g}}let eventDelegation=new Map;function delegateEvent(e,t,n){if(!eventDelegation.has(e)){let t=t=>{let n=eventDelegation.get(e);for(let[e,r]of n)t.target.matches(e)&&r(t)};document.addEventListener(e,t),eventDelegation.set(e,new Map)}eventDelegation.get(e).set(t,n)}function h(e,t,...n){let r="http://www.w3.org/2000/svg",i=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","text","tspan","defs","use","mask","clipPath"]);if("function"==typeof e)return e({...t,children:n});if(e===Fragment){let e=document.createDocumentFragment();return n.flat().forEach((t=>{let n=processChild(t);n&&e.appendChild(n)})),e}if("string"!=typeof e)throw Error(`Invalid element type: ${e}`);let o=i.has(e.toLowerCase())||t&&t.xmlns===r,a=o?document.createElementNS(r,e):document.createElement(e);if(t)for(let[e,n]of Object.entries(t))if("ref"===e)"function"==typeof n?n(a):n&&(n.current=a);else if(e.startsWith("on")){let t=e.slice(2).toLowerCase();a.addEventListener(t,n)}else if("style"===e)"string"==typeof n?a.style.cssText=n:Object.assign(a.style,n);else if("classList"===e){if(Array.isArray(n))a.classList.add(...n.filter(Boolean));else if("object"==typeof n)for(let[e,t]of Object.entries(n))t?a.classList.add(e):a.classList.remove(e)}else"class"===e||"className"===e?a.setAttribute("class",n):["key"].includes(e)||("function"==typeof n&&n[SIGNAL_TYPE]?createEffect((()=>{o?a.setAttribute(e,n()):a[e]=n()})):o?!0===n?a.setAttribute(e,""):!1!==n&&null!=n&&a.setAttribute(e,n):a[e]=n);return n.flat().forEach((e=>{if(null==e)return;let t=processChild(e);t&&(o&&t instanceof SVGElement||t instanceof Node?a.appendChild(t):a.appendChild(document.createTextNode(String(t))))})),a}let Fragment=Symbol("Fragment");function render(e,t,n={}){let{hydrate:r=!1,onError:i=console.error,suspense:o=!0,beforeMount:a,afterMount:l}=n;if(!r)for(;t.firstChild;)t.removeChild(t.firstChild);let[s]=createSignal(null),c=s[BATCH_UPDATES]();a?.();try{let n=e();if(o&&n instanceof Promise)return void n.then((e=>{mountChildren(e,t,r),l?.()})).catch(i);mountChildren(n,t,r),l?.()}catch(e){i(e)}finally{c()}return()=>{for(;t.firstChild;)t.removeChild(t.firstChild)}}function mountChildren(e,t,n){if(!e)return;let r=Array.isArray(e)?e.flat(1/0):[e],i=Array.from(t.childNodes),o=0;if(r.filter(Boolean).forEach((e=>{"string"==typeof e||"number"==typeof e?n&&i[o]?.nodeType===Node.TEXT_NODE?i[o].textContent=String(e):t.appendChild(document.createTextNode(String(e))):e instanceof Node?n&&i[o]?e.isEqualNode(i[o])||t.replaceChild(e,i[o]):t.appendChild(e):Array.isArray(e)?mountChildren(e,t,n):e&&"object"==typeof e&&t.appendChild(document.createTextNode(JSON.stringify(e))),o++})),!n)for(;o<i.length;)t.removeChild(i[o]),o++}let currentContext=null,getCurrentContext=()=>currentContext;function createContext(e){let t=Symbol("context");return{Provider({value:e,children:n}){let r=useContext(t);return currentContext=e,currentContext=r,n},Context:t,defaultValue:e}}function useContext(e){return currentContext||e.defaultValue}function ErrorBoundary({fallback:e,children:t}){try{return t}catch(t){return e(t)}}function lazy(e){let t=null,n=null;return function(r){if(!t)throw n||(n=e().then((e=>{t=e.default||e}))),n;return h(t,r)}}"undefined"!=typeof window?(window.h=h,window.Fragment=Fragment):"undefined"!=typeof global&&(global.h=h,global.Fragment=Fragment);export default{h:h,Fragment:Fragment};let processChild=e=>{if(null==e||!1===e||!0===e)return null;let t=()=>{let e=Math.random().toString(36).slice(2,8),t=document.createComment(`start:${e}`),n=document.createComment(`end:${e}`),r=document.createDocumentFragment();return r.appendChild(t),r.appendChild(n),{fragment:r,startNode:t,endNode:n}};if("function"==typeof e){let{fragment:n,startNode:r,endNode:i}=t(),o=null,a=null;return createEffect((()=>{let t=(e[SIGNAL_TYPE],e());if((null==t||!1===t||!0===t)&&(t=null),t===a)return;if(o){if(o.nodeType===Node.TEXT_NODE&&("string"==typeof t||"number"==typeof t)){let e=String(t);return o.textContent!==e&&(o.textContent=e),void(a=t)}if(o instanceof Element&&t instanceof Element&&o.tagName===t.tagName){let e=o.attributes,n=t.attributes;for(let n of e)t.hasAttribute(n.name)||o.removeAttribute(n.name);for(let e of n)o.getAttribute(e.name)!==e.value&&o.setAttribute(e.name,e.value);if(o.childNodes.length===t.childNodes.length){let e=!1;for(let n=0;n<o.childNodes.length;n++){let r=o.childNodes[n],i=t.childNodes[n];if(r.nodeType!==Node.TEXT_NODE||i.nodeType!==Node.TEXT_NODE){e=!0;break}r.textContent!==i.textContent&&(r.textContent=i.textContent)}if(!e)return void(a=t)}}}let n=i.parentNode,l=document.createDocumentFragment();if(null!=t){let e=processContent(t);e&&l.appendChild(e)}if(r.nextSibling!==i){let e=r.nextSibling,t=[];for(;e&&e!==i;)t.push(e),e=e.nextSibling;t.forEach((e=>e.remove()))}l.firstChild?(n.insertBefore(l,i),o=r.nextSibling):o=null,a=t})),n}if(Array.isArray(e)){let{fragment:n,startNode:r,endNode:i}=t(),o=[],a=new Map;return createEffect((()=>{let t=e.filter(Boolean);if(0===t.length){if(0===o.length)return;let e=r.nextSibling,t=[];for(;e&&e!==i;)t.push(e),e=e.nextSibling;return t.forEach((e=>e.remove())),o=[],void a.clear()}if(o.length===t.length&&o.length<5){let e=!1,n=[],a=r.nextSibling;for(;a&&a!==i;)n.push(a),a=a.nextSibling;for(let r=0;r<t.length;r++){let i=o[r],a=t[r],l=n[r];if(i!==a){if(l.nodeType!==Node.TEXT_NODE||"string"!=typeof a&&"number"!=typeof a){e=!0;break}l.textContent=String(a)}}if(!e)return void(o=[...t])}let n=document.createDocumentFragment(),l=new Map;t.forEach(((e,t)=>{let r,i=e?.key||`${typeof e}:${String(e)}`;a.has(i)?(r=a.get(i),a.delete(i)):r=processChild(e),r&&(l.set(i,r),n.appendChild(r))})),a.clear(),a=l;let s=r.nextSibling,c=[];for(;s&&s!==i;)c.push(s),s=s.nextSibling;c.forEach((e=>e.remove())),i.parentNode.insertBefore(n,i),o=[...t]})),n}return e instanceof Node?e:document.createTextNode(String(e))},processContent=e=>{if(Array.isArray(e)){let t=document.createDocumentFragment();return e.forEach((e=>{let n=processChild(e);n&&t.appendChild(n)})),t}return e instanceof Node?e:document.createTextNode(String(e))};export{createSignal,createEffect,createMemo,createResource,createContext,useContext,h,Fragment,render,ErrorBoundary,lazy};