defuss 1.2.3 → 1.3.0
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.
- package/dist/{index-BILpZg_l.d.ts → index-Csvo7Gd8.d.ts} +13 -10
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/render/client.cjs +1 -1
- package/dist/render/client.cjs.map +1 -1
- package/dist/render/client.d.cts +4 -3
- package/dist/render/client.d.ts +4 -3
- package/dist/render/client.mjs +1 -1
- package/dist/render/client.mjs.map +1 -1
- package/dist/render/index.cjs +1 -1
- package/dist/render/index.cjs.map +1 -1
- package/dist/render/index.d.cts +1 -1
- package/dist/render/index.d.ts +1 -1
- package/dist/render/index.mjs +1 -1
- package/dist/render/index.mjs.map +1 -1
- package/dist/render/server.cjs +1 -1
- package/dist/render/server.cjs.map +1 -1
- package/dist/render/server.d.cts +2 -2
- package/dist/render/server.d.ts +2 -2
- package/dist/render/server.mjs +1 -1
- package/package.json +1 -1
|
@@ -121,15 +121,15 @@ interface KeyFrameProperties {
|
|
|
121
121
|
'99%'?: Partial<CSSProperties>;
|
|
122
122
|
'100%'?: Partial<CSSProperties>;
|
|
123
123
|
}
|
|
124
|
-
type
|
|
125
|
-
interface Ref {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
124
|
+
type RefUpdateFn<D> = (state: D) => void;
|
|
125
|
+
interface Ref<T = null | Node | Element | Text, D = unknown> {
|
|
126
|
+
$subscriberFns: RefUpdateFn<D>[];
|
|
127
|
+
current: T;
|
|
128
|
+
update: RefUpdateFn<D>;
|
|
129
|
+
subscribe: (refUpdateFn: RefUpdateFn<D>) => () => void;
|
|
129
130
|
}
|
|
130
|
-
type VRef = (el: Element) => void;
|
|
131
131
|
interface VAttributes {
|
|
132
|
-
ref?: Ref
|
|
132
|
+
ref?: Ref;
|
|
133
133
|
key?: string;
|
|
134
134
|
}
|
|
135
135
|
interface VNodeAttributes extends VAttributes {
|
|
@@ -585,7 +585,7 @@ declare global {
|
|
|
585
585
|
ontransitionendcapture?: TransitionEventHandler;
|
|
586
586
|
}
|
|
587
587
|
interface DOMAttributes extends VAttributes, DOMAttributeEventHandlersLowerCase {
|
|
588
|
-
ref?: Ref
|
|
588
|
+
ref?: Ref;
|
|
589
589
|
onMount?: Function;
|
|
590
590
|
onLoad?: GenericEventHandler;
|
|
591
591
|
onLoadCapture?: GenericEventHandler;
|
|
@@ -890,7 +890,7 @@ declare global {
|
|
|
890
890
|
itemref?: string;
|
|
891
891
|
}
|
|
892
892
|
interface HTMLAttributes extends HTMLAttributesLowerCase, DOMAttributes {
|
|
893
|
-
ref?: Ref
|
|
893
|
+
ref?: Ref;
|
|
894
894
|
dangerouslySetInnerHTML?: {
|
|
895
895
|
__html: string;
|
|
896
896
|
};
|
|
@@ -1204,6 +1204,7 @@ declare global {
|
|
|
1204
1204
|
interface Props {
|
|
1205
1205
|
children?: VNodeChildren;
|
|
1206
1206
|
ref?: Ref;
|
|
1207
|
+
key?: string;
|
|
1207
1208
|
}
|
|
1208
1209
|
type RenderNodeInput = VNode | string | undefined;
|
|
1209
1210
|
type RenderInput = RenderNodeInput | Array<RenderNodeInput>;
|
|
@@ -1225,8 +1226,10 @@ interface Dequery {
|
|
|
1225
1226
|
toggleClass(className: string): Dequery;
|
|
1226
1227
|
on(eventName: string, handler: EventListener): Dequery;
|
|
1227
1228
|
off(eventName: string, handler: EventListener): Dequery;
|
|
1229
|
+
append(content: string | Element | DocumentFragment | Element[]): Dequery;
|
|
1228
1230
|
}
|
|
1229
1231
|
|
|
1232
|
+
declare function createRef<T extends Node | Element | Text | null = null, D = unknown>(refUpdateFn?: RefUpdateFn<D>): Ref<T, D>;
|
|
1230
1233
|
declare const jsx: (type: VNodeType | Function | any, attributes: (JSX.HTMLAttributes & JSX.SVGAttributes & Record<string, any>) | null) => Array<VNode> | VNode;
|
|
1231
1234
|
declare const getRenderer: (document: Document) => DomAbstractionImpl;
|
|
1232
1235
|
declare const renderIsomorphic: (virtualNode: VNode | undefined | string | Array<VNode | undefined | string>, parentDomElement: Element | Document | Dequery | undefined, globals: Globals) => Array<Element | Text | undefined> | Element | Text | undefined;
|
|
@@ -1234,4 +1237,4 @@ declare const Fragment: (props: VNode) => VNodeChildren | undefined;
|
|
|
1234
1237
|
declare const jsxs: (type: VNodeType | Function | any, attributes: (JSX.HTMLAttributes & JSX.SVGAttributes & Record<string, any>) | null) => Array<VNode> | VNode;
|
|
1235
1238
|
declare const jsxDEV: (type: VNodeType | Function | any, attributes: (JSX.HTMLAttributes & JSX.SVGAttributes & Record<string, any>) | null) => Array<VNode> | VNode;
|
|
1236
1239
|
|
|
1237
|
-
export { type CSSProperties as C, type Dequery as D, type FontFaceProperties as F, type Globals as G, type KeyFrameProperties as K, type Props as P, type RenderInput as R, type
|
|
1240
|
+
export { type CSSProperties as C, type Dequery as D, type FontFaceProperties as F, type Globals as G, type KeyFrameProperties as K, type Props as P, type RenderInput as R, type VAttributes as V, type RenderResult as a, type RefUpdateFn as b, type Ref as c, type VNodeAttributes as d, type VNode as e, type VNodeType as f, type VNodeKey as g, type VNodeRefObject as h, type VNodeRefCallback as i, type VNodeRef as j, type VNodeChild as k, type VNodeChildren as l, type Children as m, type DomAbstractionImpl as n, type RenderNodeInput as o, type RenderResultNode as p, createRef as q, jsx as r, getRenderer as s, renderIsomorphic as t, Fragment as u, jsxs as v, jsxDEV as w };
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var n=(t,e)=>u(t,"name",{value:e,configurable:!0});var o=require("./render/index.cjs");const d=n((t,e)=>{t.classList.contains(e)||t.classList.add(e)},"addSingleClass"),l=n((t,e)=>r=>{if(Array.isArray(r))for(let s=0;s<r.length;s++)d(t,r[s]);else d(t,r);return e},"addClass"),f=n((t,e)=>{t.classList.contains(e)&&t.classList.remove(e)},"removeSingleClass"),p=n((t,e)=>r=>{if(Array.isArray(r))for(let s=0;s<r.length;s++)f(t,r[s]);else f(t,r);return e},"removeClass"),h=n((t,e)=>r=>(t.classList.toggle(r),e),"toggleClass"),m=n(t=>e=>t.classList.contains(e),"hasClass"),y=n((t,e)=>(r,s)=>typeof s>"u"?t.getAttribute(r):(t.setAttribute(r,s),e),"attr"),C=n((t,e)=>r=>{const s=t.type==="checkbox";return typeof r>"u"?s?t.checked:t.value:(s?t.checked=r:t.value=r,e)},"val"),g=n((t,e)=>()=>(t.innerHTML="",e),"empty"),v=n((t,e)=>r=>(typeof r=="string"?t.innerHTML=r:(g(t,e)(),t.appendChild(o.renderIsomorphic(r,t,globalThis))),e),"html"),w=n((t,e)=>r=>(t.textContent=r,e),"text"),S=n((t,e)=>()=>(t.parentNode&&t.parentNode.removeChild(t),e),"remove"),x=n(t=>e=>{let r=e;return e instanceof Node||(r=o.renderIsomorphic(e,t,globalThis)),t.parentNode&&t.parentNode.replaceChild(r,t),r},"replaceWith"),A=n((t,e)=>(r,s)=>(t.removeEventListener(r,s),e),"off"),I=n((t,e)=>(r,s)=>(t.addEventListener(r,s),e),"on"),b=n((t,e)=>r=>(typeof r=="string"?t.insertAdjacentHTML("beforeend",r):r instanceof Element||r instanceof DocumentFragment?t.appendChild(r):Array.isArray(r)&&r.forEach(s=>{s instanceof Element&&t.appendChild(s)}),e),"append"),L=n(t=>{let e={},r=t?.current||t;return typeof t=="string"&&(r=document.querySelector(t)),e={el:r,attr:y(r,e),val:C(r,e),empty:g(r,e),html:v(r,e),text:w(r,e),remove:S(r,e),replaceWith:x(r),addClass:l(r,e),removeClass:p(r,e),toggleClass:h(r,e),hasClass:m(r),on:I(r,e),off:A(r,e),append:b(r,e)},e},"$"),E=n(()=>{const t=new Map;return{clear:n(()=>{t.clear()},"clear"),getItem:n(e=>t.get(String(e))??null,"getItem"),removeItem:n(e=>{t.delete(String(e))},"removeItem"),setItem:n((e,r)=>{t.set(String(e),r)},"setItem")}},"newInMemoryGenericStorageBackend"),j=E();class i{static{n(this,"WebStorageProvider")}storage;constructor(e){this.storage=e||j}get(e,r,s){const c=this.storage.getItem(e);if(c===null)return r;let a=JSON.parse(c);return s&&(a=s(e,a)),a}set(e,r,s){s&&(r=s(e,r)),this.storage.setItem(e,JSON.stringify(r))}remove(e){this.storage.removeItem(e)}removeAll(){this.storage.clear()}get backendApi(){return this.storage}}const P=n((t,e)=>{switch(t){case"session":return new i(window.sessionStorage);case"local":return new i(window.localStorage)}return new i},"getPersistenceProvider$1"),k=n((t,e)=>new i,"getPersistenceProvider"),D=n(()=>typeof window>"u"||typeof window.document>"u","isServer"),M=n((t="local",e)=>D()?k():P(t),"cache");exports.Fragment=o.Fragment,exports.createRef=o.createRef,exports.getRenderer=o.getRenderer,exports.jsx=o.jsx,exports.jsxDEV=o.jsxDEV,exports.jsxs=o.jsxs,exports.renderIsomorphic=o.renderIsomorphic,exports.$=L,exports.cache=M;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/dequery/css.ts","../src/dequery/dom.ts","../src/dequery/query.ts","../src/cache/isomporphic/memory.ts","../src/cache/client/index.ts","../src/cache/server/index.ts","../src/cache/runtime.ts","../src/cache/index.ts"],"sourcesContent":["import type { Dequery } from \"./types.js\";\n\nexport const addSingleClass = (el: Element, className: string) => {\n if (!el.classList.contains(className)) {\n el.classList.add(className);\n }\n};\n\nexport const addClass = (el: Element, impl: Dequery) => (className: Array<string> | string) => {\n if (Array.isArray(className)) {\n for (let i = 0; i < className.length; i++) {\n addSingleClass(el, className[i]);\n }\n } else {\n addSingleClass(el, className);\n }\n return impl;\n};\n\nexport const removeSingleClass = (el: Element, className: string) => {\n if (el.classList.contains(className)) {\n el.classList.remove(className);\n }\n};\n\nexport const removeClass = (el: Element, impl: Dequery) => (className: Array<string> | string) => {\n if (Array.isArray(className)) {\n for (let i = 0; i < className.length; i++) {\n removeSingleClass(el, className[i]);\n }\n } else {\n removeSingleClass(el, className);\n }\n return impl;\n};\n\nexport const toggleClass = (el: Element, impl: Dequery) => (className: string) => {\n el.classList.toggle(className);\n return impl;\n};\n\nexport const hasClass = (el: Element) => (className: string) => el.classList.contains(className);","import { renderIsomorphic, type Globals } from \"../render/index.js\";\nimport type { RenderInput } from \"../render/types.js\";\nimport type { Dequery } from \"./types.js\";\n\nexport const attr = (el: Element, impl: Dequery) => (name: string, value?: any) => {\n if (typeof value === 'undefined') return el.getAttribute(name);\n el.setAttribute(name, value);\n return impl;\n};\n\nexport const val = (el: Element, impl: Dequery) => (value?: any) => {\n const isCheckbox = (el as any).type === 'checkbox';\n if (typeof value === 'undefined') {\n return isCheckbox ? (el as any).checked : (el as any).value;\n }\n if (isCheckbox) {\n (el as any).checked = value;\n } else {\n (el as any).value = value;\n }\n return impl;\n};\n\nexport const empty = (el: Element, impl: Dequery) => () => {\n el.innerHTML = '';\n return impl;\n};\n\nexport const html = (el: Element, impl: Dequery) => (vdomOrHTML: RenderInput|string) => {\n\n if (typeof vdomOrHTML === 'string') {\n el.innerHTML = vdomOrHTML;\n } else {\n // remove all children\n empty(el, impl)();\n el.appendChild(renderIsomorphic(vdomOrHTML, el, globalThis as Globals) as Node);\n }\n return impl;\n};\n\nexport const text = (el: Element, impl: Dequery) => (text: string) => {\n el.textContent = text;\n return impl;\n};\n\nexport const remove = (el: Element, impl: Dequery) => () => {\n if (el.parentNode) el.parentNode.removeChild(el);\n return impl;\n};\n\nexport const replaceWith = (el: Element) => (vdomOrNode: RenderInput|Node) => {\n\n // assume it's a Node\n let newEl: Node = vdomOrNode as Node;\n\n // but if it's not, lets construct one from VDOM\n if (!(vdomOrNode instanceof Node)) {\n newEl = renderIsomorphic(vdomOrNode, el, globalThis as Globals) as Node;\n }\n\n // replace the old element with the new one\n if (el.parentNode) {\n el.parentNode.replaceChild(newEl, el);\n }\n return newEl;\n};\n\nexport const off = (target: Element | Window, impl: Dequery) => (eventName: string, handler: EventListener) => {\n target.removeEventListener(eventName, handler);\n return impl;\n};\n\nexport const on = (target: Element | Window, impl: Dequery) => (eventName: string, handler: EventListener) => {\n target.addEventListener(eventName, handler);\n return impl;\n};","import type { Ref } from \"../render/types.js\";\nimport { addClass, hasClass, removeClass, toggleClass } from \"./css.js\";\nimport { attr, val, empty, html, remove, replaceWith, on, off, text } from \"./dom.js\";\nimport type { Dequery } from \"./types.js\";\n\nexport const $ = (elOrRef: Element|Ref|string): Dequery => {\n\n let impl: Dequery = {} as Dequery;\n\n // unwrap the Ref's current value if it exists\n let el: Element = (elOrRef as Ref)?.current || elOrRef;\n\n // if it's a string, assume it's a selector\n if (typeof elOrRef === 'string') {\n el = document.querySelector(elOrRef) as Element;\n }\n\n impl = {\n el,\n attr: attr(el, impl),\n val: val(el, impl),\n empty: empty(el, impl),\n html: html(el, impl),\n text: text(el, impl),\n remove: remove(el, impl),\n replaceWith: replaceWith(el),\n addClass: addClass(el, impl),\n removeClass: removeClass(el, impl),\n toggleClass: toggleClass(el, impl),\n hasClass: hasClass(el),\n on: on(el, impl),\n off: off(el, impl),\n };\n return impl;\n};","import type { PersistenceProviderImpl } from '../provider.js'\nimport type { GenericLocalStorage } from './generic.js'\nimport type { MiddlewareFn } from '../provider.js'\n\nexport type MemoryProviderOptions = {}\n\nexport const newInMemoryGenericStorageBackend = <T = string>(): GenericLocalStorage<T> => {\n const cache = new Map<string, T>()\n return {\n clear: (): void => {\n cache.clear()\n },\n\n getItem: (key: string): T | null => {\n return cache.get(String(key)) ?? null\n },\n\n removeItem: (key: string): void => {\n cache.delete(String(key))\n },\n\n setItem: (key: string, value: T): void => {\n cache.set(String(key), value)\n },\n }\n}\n\n/** global in-memory storage backend */\nexport const memory = newInMemoryGenericStorageBackend()\n\n/** a simple, serverless and high-performance key/value storage engine */\nexport class WebStorageProvider<T> implements PersistenceProviderImpl<T> {\n protected storage: GenericLocalStorage<string>;\n\n constructor(storage?: GenericLocalStorage<string>) {\n this.storage = storage || memory;\n }\n\n get(key: string, defaultValue: T, middlewareFn?: MiddlewareFn<T>): T {\n const rawValue = this.storage.getItem(key);\n\n if (rawValue === null) return defaultValue;\n\n let value: T = JSON.parse(rawValue);\n\n if (middlewareFn) {\n value = middlewareFn(key, value);\n }\n return value;\n }\n\n set(key: string, value: T, middlewareFn?: MiddlewareFn<T>): void {\n if (middlewareFn) {\n value = middlewareFn(key, value);\n }\n this.storage.setItem(key, JSON.stringify(value));\n }\n\n remove(key: string): void {\n this.storage.removeItem(key);\n }\n\n removeAll(): void {\n this.storage.clear();\n }\n\n get backendApi(): GenericLocalStorage<string> {\n return this.storage;\n }\n}\n\nexport interface MemoryStorage<T> extends PersistenceProviderImpl<T> {\n backendApi: Omit<Omit<Storage, 'key'>, 'length'>\n}\n\nexport interface WebStorage<T> extends PersistenceProviderImpl<T> {\n backendApi: Storage\n}\n","import { WebStorageProvider } from '../isomporphic/memory.js'\nimport type { PersistenceProvider, PersistenceProviderImpl, PersistenceProviderOptions } from '../provider.js'\n\n/** returns the default persistence provider for each runtime environment */\nexport const getPersistenceProvider = <T>(\n provider: PersistenceProvider,\n _options?: PersistenceProviderOptions,\n): PersistenceProviderImpl<T> => {\n switch (provider) {\n case 'session':\n return new WebStorageProvider<T>(window.sessionStorage)\n case 'local':\n return new WebStorageProvider<T>(window.localStorage)\n }\n return new WebStorageProvider<T>() // memory\n}\n","import { WebStorageProvider } from '../isomporphic/memory.js'\nimport type { PersistenceProvider, PersistenceProviderImpl, PersistenceProviderOptions } from '../provider.js'\n\n/** returns the default persistence provider for each runtime environment */\nexport const getPersistenceProvider = <T>(\n _provider: PersistenceProvider,\n _options?: PersistenceProviderOptions,\n): PersistenceProviderImpl<T> => {\n return new WebStorageProvider<T>()\n}\n","//export const isBrowser = (): boolean => typeof window !== \"undefined\" && typeof window.document !== \"undefined\";\n\nexport const isServer = (): boolean => typeof window === \"undefined\" || typeof window.document === \"undefined\";\n\n//export const isWebWorker = (): boolean => typeof self === \"object\" && self.constructor?.name === \"DedicatedWorkerGlobalScope\";","import type { PersistenceProvider, PersistenceProviderImpl, PersistenceProviderOptions } from './provider.js'\nimport { getPersistenceProvider as getPersistenceProviderClient } from './client/index.js'\nimport { getPersistenceProvider as getPersistenceProviderServer } from './server/index.js'\nimport { isServer } from './runtime.js'\n\n/** returns the persistence provider (isomorphic) */\nexport const cache = <T>(\n provider: PersistenceProvider = 'local',\n options?: PersistenceProviderOptions,\n): PersistenceProviderImpl<T> => {\n if (isServer()) {\n return getPersistenceProviderServer(provider, options)\n } else {\n return getPersistenceProviderClient(provider, options)\n }\n}\n\nexport * from './provider.js'\n"],"names":["renderIsomorphic","getPersistenceProvider","getPersistenceProviderServer","getPersistenceProviderClient"],"mappings":";;;;AACO,MAAM,cAAc,GAAG,CAAC,EAAE,EAAE,SAAS,KAAK;AACjD,EAAE,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;AACzC,IAAI,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC;AAC/B;AACA,CAAC;AACM,MAAM,QAAQ,GAAG,CAAC,EAAE,EAAE,IAAI,KAAK,CAAC,SAAS,KAAK;AACrD,EAAE,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;AAChC,IAAI,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AAC/C,MAAM,cAAc,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;AACtC;AACA,GAAG,MAAM;AACT,IAAI,cAAc,CAAC,EAAE,EAAE,SAAS,CAAC;AACjC;AACA,EAAE,OAAO,IAAI;AACb,CAAC;AACM,MAAM,iBAAiB,GAAG,CAAC,EAAE,EAAE,SAAS,KAAK;AACpD,EAAE,IAAI,EAAE,CAAC,SAA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IAAI,kBAAkB,EAAE;AACjC,CAAC;;ACRM,MAAM,sBAAsB,GAAG,CAAC,SAAS,EAAE,QAAQ,KAAK;AAC/D,EAAE,OAAO,IAAI,kBAAkB,EAAE;AACjC,CAAC;;ACHM,MAAM,QAAQ,GAAG,MAAM,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,WAAW;;ACGzF,MAAC,KAAK,GAAG,CAAC,QAAQ,GAAG,OAAO,EAAE,OAAO,KAAK;AACtD,EAAE,IAAI,QAAQ,EAAE,EAAE;AAClB,IAAI,OAAOC,sBAA4B,CAAkB,CAAC;AAC1D,GAAG,MAAM;AACT,IAAI,OAAOC,wBAA4B,CAAC,QAAiB,CAAC;AAC1D;AACA;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/dequery/css.ts","../src/dequery/dom.ts","../src/dequery/query.ts","../src/cache/isomporphic/memory.ts","../src/cache/client/index.ts","../src/cache/server/index.ts","../src/cache/runtime.ts","../src/cache/index.ts"],"sourcesContent":["import type { Dequery } from \"./types.js\";\n\nexport const addSingleClass = (el: Element, className: string) => {\n if (!el.classList.contains(className)) {\n el.classList.add(className);\n }\n};\n\nexport const addClass = (el: Element, impl: Dequery) => (className: Array<string> | string) => {\n if (Array.isArray(className)) {\n for (let i = 0; i < className.length; i++) {\n addSingleClass(el, className[i]);\n }\n } else {\n addSingleClass(el, className);\n }\n return impl;\n};\n\nexport const removeSingleClass = (el: Element, className: string) => {\n if (el.classList.contains(className)) {\n el.classList.remove(className);\n }\n};\n\nexport const removeClass = (el: Element, impl: Dequery) => (className: Array<string> | string) => {\n if (Array.isArray(className)) {\n for (let i = 0; i < className.length; i++) {\n removeSingleClass(el, className[i]);\n }\n } else {\n removeSingleClass(el, className);\n }\n return impl;\n};\n\nexport const toggleClass = (el: Element, impl: Dequery) => (className: string) => {\n el.classList.toggle(className);\n return impl;\n};\n\nexport const hasClass = (el: Element) => (className: string) => el.classList.contains(className);","import { renderIsomorphic, type Globals } from \"../render/index.js\";\nimport type { RenderInput } from \"../render/types.js\";\nimport type { Dequery } from \"./types.js\";\n\nexport const attr = (el: Element, impl: Dequery) => (name: string, value?: any) => {\n if (typeof value === 'undefined') return el.getAttribute(name);\n el.setAttribute(name, value);\n return impl;\n};\n\nexport const val = (el: Element, impl: Dequery) => (value?: any) => {\n const isCheckbox = (el as any).type === 'checkbox';\n if (typeof value === 'undefined') {\n return isCheckbox ? (el as any).checked : (el as any).value;\n }\n if (isCheckbox) {\n (el as any).checked = value;\n } else {\n (el as any).value = value;\n }\n return impl;\n};\n\nexport const empty = (el: Element, impl: Dequery) => () => {\n el.innerHTML = '';\n return impl;\n};\n\nexport const html = (el: Element, impl: Dequery) => (vdomOrHTML: RenderInput|string) => {\n\n if (typeof vdomOrHTML === 'string') {\n el.innerHTML = vdomOrHTML;\n } else {\n // remove all children\n empty(el, impl)();\n el.appendChild(renderIsomorphic(vdomOrHTML, el, globalThis as Globals) as Node);\n }\n return impl;\n};\n\nexport const text = (el: Element, impl: Dequery) => (text: string) => {\n el.textContent = text;\n return impl;\n};\n\nexport const remove = (el: Element, impl: Dequery) => () => {\n if (el.parentNode) el.parentNode.removeChild(el);\n return impl;\n};\n\nexport const replaceWith = (el: Element) => (vdomOrNode: RenderInput|Node) => {\n\n // assume it's a Node\n let newEl: Node = vdomOrNode as Node;\n\n // but if it's not, lets construct one from VDOM\n if (!(vdomOrNode instanceof Node)) {\n newEl = renderIsomorphic(vdomOrNode, el, globalThis as Globals) as Node;\n }\n\n // replace the old element with the new one\n if (el.parentNode) {\n el.parentNode.replaceChild(newEl, el);\n }\n return newEl;\n};\n\nexport const off = (target: Element | Window, impl: Dequery) => (eventName: string, handler: EventListener) => {\n target.removeEventListener(eventName, handler);\n return impl;\n};\n\nexport const on = (target: Element | Window, impl: Dequery) => (eventName: string, handler: EventListener) => {\n target.addEventListener(eventName, handler);\n return impl;\n};\n\nexport const append = (el: Element, impl: Dequery) => {\n return (content: string | Element | DocumentFragment | Array<Element>) => {\n if (typeof content === 'string') {\n el.insertAdjacentHTML('beforeend', content);\n } else if (content instanceof Element) {\n el.appendChild(content);\n } else if (content instanceof DocumentFragment) {\n el.appendChild(content);\n } else if (Array.isArray(content)) {\n content.forEach((child) => {\n if (child instanceof Element) {\n el.appendChild(child);\n }\n });\n }\n return impl;\n };\n};","import type { Ref } from \"../render/types.js\";\nimport { addClass, hasClass, removeClass, toggleClass } from \"./css.js\";\nimport { attr, val, empty, html, remove, replaceWith, on, off, text, append } from \"./dom.js\";\nimport type { Dequery } from \"./types.js\";\n\nexport const $ = (elOrRef: Element|Ref|string): Dequery => {\n\n let impl: Dequery = {} as Dequery;\n\n // unwrap the Ref's current value if it exists\n let el = ((elOrRef as Ref)?.current || elOrRef) as Element;\n\n // TODO: needs serious rework to support multiple elements\n\n // if it's a string, assume it's a selector\n if (typeof elOrRef === 'string') {\n el = document.querySelector(elOrRef) as Element;\n }\n\n // TODO: needs rework to support waiting for elements when selecting\n impl = {\n el,\n attr: attr(el, impl),\n val: val(el, impl),\n empty: empty(el, impl),\n html: html(el, impl),\n text: text(el, impl),\n remove: remove(el, impl),\n replaceWith: replaceWith(el),\n addClass: addClass(el, impl),\n removeClass: removeClass(el, impl),\n toggleClass: toggleClass(el, impl),\n hasClass: hasClass(el),\n on: on(el, impl),\n off: off(el, impl),\n append: append(el, impl),\n };\n return impl;\n};","import type { PersistenceProviderImpl } from '../provider.js'\nimport type { GenericLocalStorage } from './generic.js'\nimport type { MiddlewareFn } from '../provider.js'\n\nexport type MemoryProviderOptions = {}\n\nexport const newInMemoryGenericStorageBackend = <T = string>(): GenericLocalStorage<T> => {\n const cache = new Map<string, T>()\n return {\n clear: (): void => {\n cache.clear()\n },\n\n getItem: (key: string): T | null => {\n return cache.get(String(key)) ?? null\n },\n\n removeItem: (key: string): void => {\n cache.delete(String(key))\n },\n\n setItem: (key: string, value: T): void => {\n cache.set(String(key), value)\n },\n }\n}\n\n/** global in-memory storage backend */\nexport const memory = newInMemoryGenericStorageBackend()\n\n/** a simple, serverless and high-performance key/value storage engine */\nexport class WebStorageProvider<T> implements PersistenceProviderImpl<T> {\n protected storage: GenericLocalStorage<string>;\n\n constructor(storage?: GenericLocalStorage<string>) {\n this.storage = storage || memory;\n }\n\n get(key: string, defaultValue: T, middlewareFn?: MiddlewareFn<T>): T {\n const rawValue = this.storage.getItem(key);\n\n if (rawValue === null) return defaultValue;\n\n let value: T = JSON.parse(rawValue);\n\n if (middlewareFn) {\n value = middlewareFn(key, value);\n }\n return value;\n }\n\n set(key: string, value: T, middlewareFn?: MiddlewareFn<T>): void {\n if (middlewareFn) {\n value = middlewareFn(key, value);\n }\n this.storage.setItem(key, JSON.stringify(value));\n }\n\n remove(key: string): void {\n this.storage.removeItem(key);\n }\n\n removeAll(): void {\n this.storage.clear();\n }\n\n get backendApi(): GenericLocalStorage<string> {\n return this.storage;\n }\n}\n\nexport interface MemoryStorage<T> extends PersistenceProviderImpl<T> {\n backendApi: Omit<Omit<Storage, 'key'>, 'length'>\n}\n\nexport interface WebStorage<T> extends PersistenceProviderImpl<T> {\n backendApi: Storage\n}\n","import { WebStorageProvider } from '../isomporphic/memory.js'\nimport type { PersistenceProvider, PersistenceProviderImpl, PersistenceProviderOptions } from '../provider.js'\n\n/** returns the default persistence provider for each runtime environment */\nexport const getPersistenceProvider = <T>(\n provider: PersistenceProvider,\n _options?: PersistenceProviderOptions,\n): PersistenceProviderImpl<T> => {\n switch (provider) {\n case 'session':\n return new WebStorageProvider<T>(window.sessionStorage)\n case 'local':\n return new WebStorageProvider<T>(window.localStorage)\n }\n return new WebStorageProvider<T>() // memory\n}\n","import { WebStorageProvider } from '../isomporphic/memory.js'\nimport type { PersistenceProvider, PersistenceProviderImpl, PersistenceProviderOptions } from '../provider.js'\n\n/** returns the default persistence provider for each runtime environment */\nexport const getPersistenceProvider = <T>(\n _provider: PersistenceProvider,\n _options?: PersistenceProviderOptions,\n): PersistenceProviderImpl<T> => {\n return new WebStorageProvider<T>()\n}\n","//export const isBrowser = (): boolean => typeof window !== \"undefined\" && typeof window.document !== \"undefined\";\n\nexport const isServer = (): boolean => typeof window === \"undefined\" || typeof window.document === \"undefined\";\n\n//export const isWebWorker = (): boolean => typeof self === \"object\" && self.constructor?.name === \"DedicatedWorkerGlobalScope\";","import type { PersistenceProvider, PersistenceProviderImpl, PersistenceProviderOptions } from './provider.js'\nimport { getPersistenceProvider as getPersistenceProviderClient } from './client/index.js'\nimport { getPersistenceProvider as getPersistenceProviderServer } from './server/index.js'\nimport { isServer } from './runtime.js'\n\n/** returns the persistence provider (isomorphic) */\nexport const cache = <T>(\n provider: PersistenceProvider = 'local',\n options?: PersistenceProviderOptions,\n): PersistenceProviderImpl<T> => {\n if (isServer()) {\n return getPersistenceProviderServer(provider, options)\n } else {\n return getPersistenceProviderClient(provider, options)\n }\n}\n\nexport * from './provider.js'\n"],"names":["renderIsomorphic","getPersistenceProvider","getPersistenceProviderServer","getPersistenceProviderClient"],"mappings":";;;;AACO,MAAM,cAAc,GAAG,CAAC,EAAE,EAAE,SAAS,KAAK;AACjD,EAAE,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;AACzC,IAAI,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC;AAC/B;AACA,CAAC;AACM,MAAM,QAAQ,GAAG,CAAC,EAAE,EAAE,IAAI,KAAK,CAAC,SAAS,KAAK;AACrD,EAAE,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;AAChC,IAAI,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AAC/C,MAAM,cAAc,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;AACtC;AACA,GAAG,MAAM;AACT,IAAI,cAAc,CAAC,EAAE,EAAE,SAAS,CAAC;AACjC;AACA,EAAE,OAAO,IA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B,CAAC;AAC1D,GAAG,MAAM;AACT,IAAI,OAAOC,wBAA4B,CAAC,QAAiB,CAAC;AAC1D;AACA;;;;;;;;;;;;"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { C as CSSProperties, m as Children, n as DomAbstractionImpl, F as FontFaceProperties,
|
|
1
|
+
import { c as Ref, D as Dequery } from './index-Csvo7Gd8.js';
|
|
2
|
+
export { C as CSSProperties, m as Children, n as DomAbstractionImpl, F as FontFaceProperties, u as Fragment, G as Globals, K as KeyFrameProperties, P as Props, b as RefUpdateFn, R as RenderInput, o as RenderNodeInput, a as RenderResult, p as RenderResultNode, V as VAttributes, e as VNode, d as VNodeAttributes, k as VNodeChild, l as VNodeChildren, g as VNodeKey, j as VNodeRef, i as VNodeRefCallback, h as VNodeRefObject, f as VNodeType, q as createRef, s as getRenderer, r as jsx, w as jsxDEV, v as jsxs, t as renderIsomorphic } from './index-Csvo7Gd8.js';
|
|
3
3
|
import * as CSS from 'csstype';
|
|
4
4
|
export { CSS };
|
|
5
5
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { C as CSSProperties, m as Children, n as DomAbstractionImpl, F as FontFaceProperties,
|
|
1
|
+
import { c as Ref, D as Dequery } from './index-Csvo7Gd8.js';
|
|
2
|
+
export { C as CSSProperties, m as Children, n as DomAbstractionImpl, F as FontFaceProperties, u as Fragment, G as Globals, K as KeyFrameProperties, P as Props, b as RefUpdateFn, R as RenderInput, o as RenderNodeInput, a as RenderResult, p as RenderResultNode, V as VAttributes, e as VNode, d as VNodeAttributes, k as VNodeChild, l as VNodeChildren, g as VNodeKey, j as VNodeRef, i as VNodeRefCallback, h as VNodeRefObject, f as VNodeType, q as createRef, s as getRenderer, r as jsx, w as jsxDEV, v as jsxs, t as renderIsomorphic } from './index-Csvo7Gd8.js';
|
|
3
3
|
import * as CSS from 'csstype';
|
|
4
4
|
export { CSS };
|
|
5
5
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var l=Object.defineProperty;var n=(t,e)=>l(t,"name",{value:e,configurable:!0});import{renderIsomorphic as a}from"./render/index.mjs";import{Fragment as V,createRef as $,getRenderer as q,jsx as B,jsxDEV as G,jsxs as H}from"./render/index.mjs";const f=n((t,e)=>{t.classList.contains(e)||t.classList.add(e)},"addSingleClass"),u=n((t,e)=>r=>{if(Array.isArray(r))for(let s=0;s<r.length;s++)f(t,r[s]);else f(t,r);return e},"addClass"),d=n((t,e)=>{t.classList.contains(e)&&t.classList.remove(e)},"removeSingleClass"),p=n((t,e)=>r=>{if(Array.isArray(r))for(let s=0;s<r.length;s++)d(t,r[s]);else d(t,r);return e},"removeClass"),h=n((t,e)=>r=>(t.classList.toggle(r),e),"toggleClass"),m=n(t=>e=>t.classList.contains(e),"hasClass"),y=n((t,e)=>(r,s)=>typeof s>"u"?t.getAttribute(r):(t.setAttribute(r,s),e),"attr"),C=n((t,e)=>r=>{const s=t.type==="checkbox";return typeof r>"u"?s?t.checked:t.value:(s?t.checked=r:t.value=r,e)},"val"),g=n((t,e)=>()=>(t.innerHTML="",e),"empty"),v=n((t,e)=>r=>(typeof r=="string"?t.innerHTML=r:(g(t,e)(),t.appendChild(a(r,t,globalThis))),e),"html"),w=n((t,e)=>r=>(t.textContent=r,e),"text"),S=n((t,e)=>()=>(t.parentNode&&t.parentNode.removeChild(t),e),"remove"),A=n(t=>e=>{let r=e;return e instanceof Node||(r=a(e,t,globalThis)),t.parentNode&&t.parentNode.replaceChild(r,t),r},"replaceWith"),x=n((t,e)=>(r,s)=>(t.removeEventListener(r,s),e),"off"),b=n((t,e)=>(r,s)=>(t.addEventListener(r,s),e),"on"),L=n((t,e)=>r=>(typeof r=="string"?t.insertAdjacentHTML("beforeend",r):r instanceof Element||r instanceof DocumentFragment?t.appendChild(r):Array.isArray(r)&&r.forEach(s=>{s instanceof Element&&t.appendChild(s)}),e),"append"),I=n(t=>{let e={},r=t?.current||t;return typeof t=="string"&&(r=document.querySelector(t)),e={el:r,attr:y(r,e),val:C(r,e),empty:g(r,e),html:v(r,e),text:w(r,e),remove:S(r,e),replaceWith:A(r),addClass:u(r,e),removeClass:p(r,e),toggleClass:h(r,e),hasClass:m(r),on:b(r,e),off:x(r,e),append:L(r,e)},e},"$"),E=n(()=>{const t=new Map;return{clear:n(()=>{t.clear()},"clear"),getItem:n(e=>t.get(String(e))??null,"getItem"),removeItem:n(e=>{t.delete(String(e))},"removeItem"),setItem:n((e,r)=>{t.set(String(e),r)},"setItem")}},"newInMemoryGenericStorageBackend"),P=E();class o{static{n(this,"WebStorageProvider")}storage;constructor(e){this.storage=e||P}get(e,r,s){const c=this.storage.getItem(e);if(c===null)return r;let i=JSON.parse(c);return s&&(i=s(e,i)),i}set(e,r,s){s&&(r=s(e,r)),this.storage.setItem(e,JSON.stringify(r))}remove(e){this.storage.removeItem(e)}removeAll(){this.storage.clear()}get backendApi(){return this.storage}}const j=n((t,e)=>{switch(t){case"session":return new o(window.sessionStorage);case"local":return new o(window.localStorage)}return new o},"getPersistenceProvider$1"),k=n((t,e)=>new o,"getPersistenceProvider"),M=n(()=>typeof window>"u"||typeof window.document>"u","isServer"),T=n((t="local",e)=>M()?k():j(t),"cache");export{I as $,V as Fragment,T as cache,$ as createRef,q as getRenderer,B as jsx,G as jsxDEV,H as jsxs,a as renderIsomorphic};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/dequery/css.ts","../src/dequery/dom.ts","../src/dequery/query.ts","../src/cache/isomporphic/memory.ts","../src/cache/client/index.ts","../src/cache/server/index.ts","../src/cache/runtime.ts","../src/cache/index.ts"],"sourcesContent":["import type { Dequery } from \"./types.js\";\n\nexport const addSingleClass = (el: Element, className: string) => {\n if (!el.classList.contains(className)) {\n el.classList.add(className);\n }\n};\n\nexport const addClass = (el: Element, impl: Dequery) => (className: Array<string> | string) => {\n if (Array.isArray(className)) {\n for (let i = 0; i < className.length; i++) {\n addSingleClass(el, className[i]);\n }\n } else {\n addSingleClass(el, className);\n }\n return impl;\n};\n\nexport const removeSingleClass = (el: Element, className: string) => {\n if (el.classList.contains(className)) {\n el.classList.remove(className);\n }\n};\n\nexport const removeClass = (el: Element, impl: Dequery) => (className: Array<string> | string) => {\n if (Array.isArray(className)) {\n for (let i = 0; i < className.length; i++) {\n removeSingleClass(el, className[i]);\n }\n } else {\n removeSingleClass(el, className);\n }\n return impl;\n};\n\nexport const toggleClass = (el: Element, impl: Dequery) => (className: string) => {\n el.classList.toggle(className);\n return impl;\n};\n\nexport const hasClass = (el: Element) => (className: string) => el.classList.contains(className);","import { renderIsomorphic, type Globals } from \"../render/index.js\";\nimport type { RenderInput } from \"../render/types.js\";\nimport type { Dequery } from \"./types.js\";\n\nexport const attr = (el: Element, impl: Dequery) => (name: string, value?: any) => {\n if (typeof value === 'undefined') return el.getAttribute(name);\n el.setAttribute(name, value);\n return impl;\n};\n\nexport const val = (el: Element, impl: Dequery) => (value?: any) => {\n const isCheckbox = (el as any).type === 'checkbox';\n if (typeof value === 'undefined') {\n return isCheckbox ? (el as any).checked : (el as any).value;\n }\n if (isCheckbox) {\n (el as any).checked = value;\n } else {\n (el as any).value = value;\n }\n return impl;\n};\n\nexport const empty = (el: Element, impl: Dequery) => () => {\n el.innerHTML = '';\n return impl;\n};\n\nexport const html = (el: Element, impl: Dequery) => (vdomOrHTML: RenderInput|string) => {\n\n if (typeof vdomOrHTML === 'string') {\n el.innerHTML = vdomOrHTML;\n } else {\n // remove all children\n empty(el, impl)();\n el.appendChild(renderIsomorphic(vdomOrHTML, el, globalThis as Globals) as Node);\n }\n return impl;\n};\n\nexport const text = (el: Element, impl: Dequery) => (text: string) => {\n el.textContent = text;\n return impl;\n};\n\nexport const remove = (el: Element, impl: Dequery) => () => {\n if (el.parentNode) el.parentNode.removeChild(el);\n return impl;\n};\n\nexport const replaceWith = (el: Element) => (vdomOrNode: RenderInput|Node) => {\n\n // assume it's a Node\n let newEl: Node = vdomOrNode as Node;\n\n // but if it's not, lets construct one from VDOM\n if (!(vdomOrNode instanceof Node)) {\n newEl = renderIsomorphic(vdomOrNode, el, globalThis as Globals) as Node;\n }\n\n // replace the old element with the new one\n if (el.parentNode) {\n el.parentNode.replaceChild(newEl, el);\n }\n return newEl;\n};\n\nexport const off = (target: Element | Window, impl: Dequery) => (eventName: string, handler: EventListener) => {\n target.removeEventListener(eventName, handler);\n return impl;\n};\n\nexport const on = (target: Element | Window, impl: Dequery) => (eventName: string, handler: EventListener) => {\n target.addEventListener(eventName, handler);\n return impl;\n};","import type { Ref } from \"../render/types.js\";\nimport { addClass, hasClass, removeClass, toggleClass } from \"./css.js\";\nimport { attr, val, empty, html, remove, replaceWith, on, off, text } from \"./dom.js\";\nimport type { Dequery } from \"./types.js\";\n\nexport const $ = (elOrRef: Element|Ref|string): Dequery => {\n\n let impl: Dequery = {} as Dequery;\n\n // unwrap the Ref's current value if it exists\n let el: Element = (elOrRef as Ref)?.current || elOrRef;\n\n // if it's a string, assume it's a selector\n if (typeof elOrRef === 'string') {\n el = document.querySelector(elOrRef) as Element;\n }\n\n impl = {\n el,\n attr: attr(el, impl),\n val: val(el, impl),\n empty: empty(el, impl),\n html: html(el, impl),\n text: text(el, impl),\n remove: remove(el, impl),\n replaceWith: replaceWith(el),\n addClass: addClass(el, impl),\n removeClass: removeClass(el, impl),\n toggleClass: toggleClass(el, impl),\n hasClass: hasClass(el),\n on: on(el, impl),\n off: off(el, impl),\n };\n return impl;\n};","import type { PersistenceProviderImpl } from '../provider.js'\nimport type { GenericLocalStorage } from './generic.js'\nimport type { MiddlewareFn } from '../provider.js'\n\nexport type MemoryProviderOptions = {}\n\nexport const newInMemoryGenericStorageBackend = <T = string>(): GenericLocalStorage<T> => {\n const cache = new Map<string, T>()\n return {\n clear: (): void => {\n cache.clear()\n },\n\n getItem: (key: string): T | null => {\n return cache.get(String(key)) ?? null\n },\n\n removeItem: (key: string): void => {\n cache.delete(String(key))\n },\n\n setItem: (key: string, value: T): void => {\n cache.set(String(key), value)\n },\n }\n}\n\n/** global in-memory storage backend */\nexport const memory = newInMemoryGenericStorageBackend()\n\n/** a simple, serverless and high-performance key/value storage engine */\nexport class WebStorageProvider<T> implements PersistenceProviderImpl<T> {\n protected storage: GenericLocalStorage<string>;\n\n constructor(storage?: GenericLocalStorage<string>) {\n this.storage = storage || memory;\n }\n\n get(key: string, defaultValue: T, middlewareFn?: MiddlewareFn<T>): T {\n const rawValue = this.storage.getItem(key);\n\n if (rawValue === null) return defaultValue;\n\n let value: T = JSON.parse(rawValue);\n\n if (middlewareFn) {\n value = middlewareFn(key, value);\n }\n return value;\n }\n\n set(key: string, value: T, middlewareFn?: MiddlewareFn<T>): void {\n if (middlewareFn) {\n value = middlewareFn(key, value);\n }\n this.storage.setItem(key, JSON.stringify(value));\n }\n\n remove(key: string): void {\n this.storage.removeItem(key);\n }\n\n removeAll(): void {\n this.storage.clear();\n }\n\n get backendApi(): GenericLocalStorage<string> {\n return this.storage;\n }\n}\n\nexport interface MemoryStorage<T> extends PersistenceProviderImpl<T> {\n backendApi: Omit<Omit<Storage, 'key'>, 'length'>\n}\n\nexport interface WebStorage<T> extends PersistenceProviderImpl<T> {\n backendApi: Storage\n}\n","import { WebStorageProvider } from '../isomporphic/memory.js'\nimport type { PersistenceProvider, PersistenceProviderImpl, PersistenceProviderOptions } from '../provider.js'\n\n/** returns the default persistence provider for each runtime environment */\nexport const getPersistenceProvider = <T>(\n provider: PersistenceProvider,\n _options?: PersistenceProviderOptions,\n): PersistenceProviderImpl<T> => {\n switch (provider) {\n case 'session':\n return new WebStorageProvider<T>(window.sessionStorage)\n case 'local':\n return new WebStorageProvider<T>(window.localStorage)\n }\n return new WebStorageProvider<T>() // memory\n}\n","import { WebStorageProvider } from '../isomporphic/memory.js'\nimport type { PersistenceProvider, PersistenceProviderImpl, PersistenceProviderOptions } from '../provider.js'\n\n/** returns the default persistence provider for each runtime environment */\nexport const getPersistenceProvider = <T>(\n _provider: PersistenceProvider,\n _options?: PersistenceProviderOptions,\n): PersistenceProviderImpl<T> => {\n return new WebStorageProvider<T>()\n}\n","//export const isBrowser = (): boolean => typeof window !== \"undefined\" && typeof window.document !== \"undefined\";\n\nexport const isServer = (): boolean => typeof window === \"undefined\" || typeof window.document === \"undefined\";\n\n//export const isWebWorker = (): boolean => typeof self === \"object\" && self.constructor?.name === \"DedicatedWorkerGlobalScope\";","import type { PersistenceProvider, PersistenceProviderImpl, PersistenceProviderOptions } from './provider.js'\nimport { getPersistenceProvider as getPersistenceProviderClient } from './client/index.js'\nimport { getPersistenceProvider as getPersistenceProviderServer } from './server/index.js'\nimport { isServer } from './runtime.js'\n\n/** returns the persistence provider (isomorphic) */\nexport const cache = <T>(\n provider: PersistenceProvider = 'local',\n options?: PersistenceProviderOptions,\n): PersistenceProviderImpl<T> => {\n if (isServer()) {\n return getPersistenceProviderServer(provider, options)\n } else {\n return getPersistenceProviderClient(provider, options)\n }\n}\n\nexport * from './provider.js'\n"],"names":["getPersistenceProvider","getPersistenceProviderServer","getPersistenceProviderClient"],"mappings":";;;AACO,MAAM,cAAc,GAAG,CAAC,EAAE,EAAE,SAAS,KAAK;AACjD,EAAE,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;AACzC,IAAI,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC;AAC/B;AACA,CAAC;AACM,MAAM,QAAQ,GAAG,CAAC,EAAE,EAAE,IAAI,KAAK,CAAC,SAAS,KAAK;AACrD,EAAE,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;AAChC,IAAI,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AA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AAG,CAAC,QAAQ,EAAE,QAAQ,KAAK;AAC9D,EAAE,QAAQ,QAAQ;AAClB,IAAI,KAAK,SAAS;AAClB,MAAM,OAAO,IAAI,kBAAkB,CAAC,MAAM,CAAC,cAAc,CAAC;AAC1D,IAAI,KAAK,OAAO;AAChB,MAAM,OAAO,IAAI,kBAAkB,CAAC,MAAM,CAAC,YAAY,CAAC;AACxD;AACA,EAAE,OAAO,IAAI,kBAAkB,EAAE;AACjC,CAAC;;ACRM,MAAM,sBAAsB,GAAG,CAAC,SAAS,EAAE,QAAQ,KAAK;AAC/D,EAAE,OAAO,IAAI,kBAAkB,EAAE;AACjC,CAAC;;ACHM,MAAM,QAAQ,GAAG,MAAM,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,WAAW;;ACGzF,MAAC,KAAK,GAAG,CAAC,QAAQ,GAAG,OAAO,EAAE,OAAO,KAAK;AACtD,EAAE,IAAI,QAAQ,EAAE,EAAE;AAClB,IAAI,OAAOC,sBAA4B,CAAkB,CAAC;AAC1D,GAAG,MAAM;AACT,IAAI,OAAOC,wBAA4B,CAAC,QAAiB,CAAC;AAC1D;AACA;;;;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/dequery/css.ts","../src/dequery/dom.ts","../src/dequery/query.ts","../src/cache/isomporphic/memory.ts","../src/cache/client/index.ts","../src/cache/server/index.ts","../src/cache/runtime.ts","../src/cache/index.ts"],"sourcesContent":["import type { Dequery } from \"./types.js\";\n\nexport const addSingleClass = (el: Element, className: string) => {\n if (!el.classList.contains(className)) {\n el.classList.add(className);\n }\n};\n\nexport const addClass = (el: Element, impl: Dequery) => (className: Array<string> | string) => {\n if (Array.isArray(className)) {\n for (let i = 0; i < className.length; i++) {\n addSingleClass(el, className[i]);\n }\n } else {\n addSingleClass(el, className);\n }\n return impl;\n};\n\nexport const removeSingleClass = (el: Element, className: string) => {\n if (el.classList.contains(className)) {\n el.classList.remove(className);\n }\n};\n\nexport const removeClass = (el: Element, impl: Dequery) => (className: Array<string> | string) => {\n if (Array.isArray(className)) {\n for (let i = 0; i < className.length; i++) {\n removeSingleClass(el, className[i]);\n }\n } else {\n removeSingleClass(el, className);\n }\n return impl;\n};\n\nexport const toggleClass = (el: Element, impl: Dequery) => (className: string) => {\n el.classList.toggle(className);\n return impl;\n};\n\nexport const hasClass = (el: Element) => (className: string) => el.classList.contains(className);","import { renderIsomorphic, type Globals } from \"../render/index.js\";\nimport type { RenderInput } from \"../render/types.js\";\nimport type { Dequery } from \"./types.js\";\n\nexport const attr = (el: Element, impl: Dequery) => (name: string, value?: any) => {\n if (typeof value === 'undefined') return el.getAttribute(name);\n el.setAttribute(name, value);\n return impl;\n};\n\nexport const val = (el: Element, impl: Dequery) => (value?: any) => {\n const isCheckbox = (el as any).type === 'checkbox';\n if (typeof value === 'undefined') {\n return isCheckbox ? (el as any).checked : (el as any).value;\n }\n if (isCheckbox) {\n (el as any).checked = value;\n } else {\n (el as any).value = value;\n }\n return impl;\n};\n\nexport const empty = (el: Element, impl: Dequery) => () => {\n el.innerHTML = '';\n return impl;\n};\n\nexport const html = (el: Element, impl: Dequery) => (vdomOrHTML: RenderInput|string) => {\n\n if (typeof vdomOrHTML === 'string') {\n el.innerHTML = vdomOrHTML;\n } else {\n // remove all children\n empty(el, impl)();\n el.appendChild(renderIsomorphic(vdomOrHTML, el, globalThis as Globals) as Node);\n }\n return impl;\n};\n\nexport const text = (el: Element, impl: Dequery) => (text: string) => {\n el.textContent = text;\n return impl;\n};\n\nexport const remove = (el: Element, impl: Dequery) => () => {\n if (el.parentNode) el.parentNode.removeChild(el);\n return impl;\n};\n\nexport const replaceWith = (el: Element) => (vdomOrNode: RenderInput|Node) => {\n\n // assume it's a Node\n let newEl: Node = vdomOrNode as Node;\n\n // but if it's not, lets construct one from VDOM\n if (!(vdomOrNode instanceof Node)) {\n newEl = renderIsomorphic(vdomOrNode, el, globalThis as Globals) as Node;\n }\n\n // replace the old element with the new one\n if (el.parentNode) {\n el.parentNode.replaceChild(newEl, el);\n }\n return newEl;\n};\n\nexport const off = (target: Element | Window, impl: Dequery) => (eventName: string, handler: EventListener) => {\n target.removeEventListener(eventName, handler);\n return impl;\n};\n\nexport const on = (target: Element | Window, impl: Dequery) => (eventName: string, handler: EventListener) => {\n target.addEventListener(eventName, handler);\n return impl;\n};\n\nexport const append = (el: Element, impl: Dequery) => {\n return (content: string | Element | DocumentFragment | Array<Element>) => {\n if (typeof content === 'string') {\n el.insertAdjacentHTML('beforeend', content);\n } else if (content instanceof Element) {\n el.appendChild(content);\n } else if (content instanceof DocumentFragment) {\n el.appendChild(content);\n } else if (Array.isArray(content)) {\n content.forEach((child) => {\n if (child instanceof Element) {\n el.appendChild(child);\n }\n });\n }\n return impl;\n };\n};","import type { Ref } from \"../render/types.js\";\nimport { addClass, hasClass, removeClass, toggleClass } from \"./css.js\";\nimport { attr, val, empty, html, remove, replaceWith, on, off, text, append } from \"./dom.js\";\nimport type { Dequery } from \"./types.js\";\n\nexport const $ = (elOrRef: Element|Ref|string): Dequery => {\n\n let impl: Dequery = {} as Dequery;\n\n // unwrap the Ref's current value if it exists\n let el = ((elOrRef as Ref)?.current || elOrRef) as Element;\n\n // TODO: needs serious rework to support multiple elements\n\n // if it's a string, assume it's a selector\n if (typeof elOrRef === 'string') {\n el = document.querySelector(elOrRef) as Element;\n }\n\n // TODO: needs rework to support waiting for elements when selecting\n impl = {\n el,\n attr: attr(el, impl),\n val: val(el, impl),\n empty: empty(el, impl),\n html: html(el, impl),\n text: text(el, impl),\n remove: remove(el, impl),\n replaceWith: replaceWith(el),\n addClass: addClass(el, impl),\n removeClass: removeClass(el, impl),\n toggleClass: toggleClass(el, impl),\n hasClass: hasClass(el),\n on: on(el, impl),\n off: off(el, impl),\n append: append(el, impl),\n };\n return impl;\n};","import type { PersistenceProviderImpl } from '../provider.js'\nimport type { GenericLocalStorage } from './generic.js'\nimport type { MiddlewareFn } from '../provider.js'\n\nexport type MemoryProviderOptions = {}\n\nexport const newInMemoryGenericStorageBackend = <T = string>(): GenericLocalStorage<T> => {\n const cache = new Map<string, T>()\n return {\n clear: (): void => {\n cache.clear()\n },\n\n getItem: (key: string): T | null => {\n return cache.get(String(key)) ?? null\n },\n\n removeItem: (key: string): void => {\n cache.delete(String(key))\n },\n\n setItem: (key: string, value: T): void => {\n cache.set(String(key), value)\n },\n }\n}\n\n/** global in-memory storage backend */\nexport const memory = newInMemoryGenericStorageBackend()\n\n/** a simple, serverless and high-performance key/value storage engine */\nexport class WebStorageProvider<T> implements PersistenceProviderImpl<T> {\n protected storage: GenericLocalStorage<string>;\n\n constructor(storage?: GenericLocalStorage<string>) {\n this.storage = storage || memory;\n }\n\n get(key: string, defaultValue: T, middlewareFn?: MiddlewareFn<T>): T {\n const rawValue = this.storage.getItem(key);\n\n if (rawValue === null) return defaultValue;\n\n let value: T = JSON.parse(rawValue);\n\n if (middlewareFn) {\n value = middlewareFn(key, value);\n }\n return value;\n }\n\n set(key: string, value: T, middlewareFn?: MiddlewareFn<T>): void {\n if (middlewareFn) {\n value = middlewareFn(key, value);\n }\n this.storage.setItem(key, JSON.stringify(value));\n }\n\n remove(key: string): void {\n this.storage.removeItem(key);\n }\n\n removeAll(): void {\n this.storage.clear();\n }\n\n get backendApi(): GenericLocalStorage<string> {\n return this.storage;\n }\n}\n\nexport interface MemoryStorage<T> extends PersistenceProviderImpl<T> {\n backendApi: Omit<Omit<Storage, 'key'>, 'length'>\n}\n\nexport interface WebStorage<T> extends PersistenceProviderImpl<T> {\n backendApi: Storage\n}\n","import { WebStorageProvider } from '../isomporphic/memory.js'\nimport type { PersistenceProvider, PersistenceProviderImpl, PersistenceProviderOptions } from '../provider.js'\n\n/** returns the default persistence provider for each runtime environment */\nexport const getPersistenceProvider = <T>(\n provider: PersistenceProvider,\n _options?: PersistenceProviderOptions,\n): PersistenceProviderImpl<T> => {\n switch (provider) {\n case 'session':\n return new WebStorageProvider<T>(window.sessionStorage)\n case 'local':\n return new WebStorageProvider<T>(window.localStorage)\n }\n return new WebStorageProvider<T>() // memory\n}\n","import { WebStorageProvider } from '../isomporphic/memory.js'\nimport type { PersistenceProvider, PersistenceProviderImpl, PersistenceProviderOptions } from '../provider.js'\n\n/** returns the default persistence provider for each runtime environment */\nexport const getPersistenceProvider = <T>(\n _provider: PersistenceProvider,\n _options?: PersistenceProviderOptions,\n): PersistenceProviderImpl<T> => {\n return new WebStorageProvider<T>()\n}\n","//export const isBrowser = (): boolean => typeof window !== \"undefined\" && typeof window.document !== \"undefined\";\n\nexport const isServer = (): boolean => typeof window === \"undefined\" || typeof window.document === \"undefined\";\n\n//export const isWebWorker = (): boolean => typeof self === \"object\" && self.constructor?.name === \"DedicatedWorkerGlobalScope\";","import type { PersistenceProvider, PersistenceProviderImpl, PersistenceProviderOptions } from './provider.js'\nimport { getPersistenceProvider as getPersistenceProviderClient } from './client/index.js'\nimport { getPersistenceProvider as getPersistenceProviderServer } from './server/index.js'\nimport { isServer } from './runtime.js'\n\n/** returns the persistence provider (isomorphic) */\nexport const cache = <T>(\n provider: PersistenceProvider = 'local',\n options?: PersistenceProviderOptions,\n): PersistenceProviderImpl<T> => {\n if (isServer()) {\n return getPersistenceProviderServer(provider, options)\n } else {\n return getPersistenceProviderClient(provider, options)\n }\n}\n\nexport * from './provider.js'\n"],"names":["getPersistenceProvider","getPersistenceProviderServer","getPersistenceProviderClient"],"mappings":";;;AACO,MAAM,cAAc,GAAG,CAAC,EAAE,EAAE,SAAS,KAAK;AACjD,EAAE,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;AACzC,IAAI,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC;AAC/B;AACA,CAAC;AACM,MAAM,QAAQ,GAAG,CAAC,EAAE,EAAE,IAAI,KAAK,CAAC,SAAS,KAAK;AACrD,EAAE,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;AAChC,IAAI,KAAK,IAAI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;;ACHM,MAAM,QAAQ,GAAG,MAAM,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,WAAW;;ACGzF,MAAC,KAAK,GAAG,CAAC,QAAQ,GAAG,OAAO,EAAE,OAAO,KAAK;AACtD,EAAE,IAAI,QAAQ,EAAE,EAAE;AAClB,IAAI,OAAOC,sBAA4B,CAAkB,CAAC;AAC1D,GAAG,MAAM;AACT,IAAI,OAAOC,wBAA4B,CAAC,QAAiB,CAAC;AAC1D;AACA;;;;"}
|
package/dist/render/client.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var f=Object.defineProperty;var d=(e,n)=>f(e,"name",{value:n,configurable:!0});var t=require("./index.cjs");const h=d((e,n=document.documentElement)=>t.renderIsomorphic(e,n,window),"render"),m=d(e=>new XMLSerializer().serializeToString(e),"renderToString"),u=d((e,n)=>{if(e.length!==n.length)throw new Error("[defuss] Hydration failed. Number of VNodes from CSR does not match the number of DOM elements rendered in SSR.");for(let o=0;o<e.length;o++){const r=e[o],s=n[o];if(r.type){r.attributes.ref&&(r.attributes.ref.current=s);for(const a of Object.keys(r.attributes))if(a.startsWith("on")){let i=a.substring(2).toLowerCase();const c=i.indexOf("capture");c>-1&&(i=i.substring(0,c)),s.addEventListener(i,r.attributes[a])}r.attributes?.onMount&&r.attributes.onMount(s),r.children&&u(r.children,Array.from(s.childNodes))}}},"hydrate");exports.Fragment=t.Fragment,exports.createRef=t.createRef,exports.getRenderer=t.getRenderer,exports.jsx=t.jsx,exports.jsxDEV=t.jsxDEV,exports.jsxs=t.jsxs,exports.renderIsomorphic=t.renderIsomorphic,exports.hydrate=u,exports.render=h,exports.renderToString=m;
|
|
2
2
|
//# sourceMappingURL=client.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.cjs","sources":["../../src/render/client.ts"],"sourcesContent":["import type { Dequery } from '../dequery/types.js'\nimport { renderIsomorphic } from './isomorph.js'\nimport type { RenderInput, RenderResult } from './types.js'\n\nexport const render = <T extends RenderInput>(\n virtualNode: T,\n parentDomElement: Element | Document | Dequery = document.documentElement,\n): RenderResult<T> => renderIsomorphic(virtualNode, parentDomElement, window) as any\n\nexport const renderToString = (el: Node) => new XMLSerializer().serializeToString(el)\n\nexport * from './index.js'\n"],"names":["renderIsomorphic"],"mappings":";;;;AAEY,MAAC,MAAM,GAAG,CAAC,WAAW,EAAE,gBAAgB,GAAG,QAAQ,CAAC,eAAe,KAAKA,sBAAgB,CAAC,WAAW,EAAE,gBAAgB,EAAE,MAAM;AAC9H,MAAC,cAAc,GAAG,CAAC,EAAE,KAAK,IAAI,aAAa,EAAE,CAAC,iBAAiB,CAAC,EAAE
|
|
1
|
+
{"version":3,"file":"client.cjs","sources":["../../src/render/client.ts"],"sourcesContent":["import type { Dequery } from '../dequery/types.js'\nimport { renderIsomorphic } from './isomorph.js'\nimport type { RenderInput, RenderResult, VNode } from './types.js'\n\nexport const render = <T extends RenderInput>(\n virtualNode: T,\n parentDomElement: Element | Document | Dequery = document.documentElement,\n): RenderResult<T> => renderIsomorphic(virtualNode, parentDomElement, window) as any\n\nexport const renderToString = (el: Node) => new XMLSerializer().serializeToString(el)\n\n// 1. any item in roots that has a ref object needs to update ref.current to the actual DOM element\n// 2. any event listener must be attached to the actual DOM element\n// 3. onMount needs to be called with the actual DOM element, if registered\nexport const hydrate = (nodes: Array<VNode>, elements: Array<HTMLElement|Text|Node>) => {\n\n if (nodes.length !== elements.length) {\n throw new Error('[defuss] Hydration failed. Number of VNodes from CSR does not match the number of DOM elements rendered in SSR.');\n }\n\n for (let i = 0; i < nodes.length; i++) {\n\n const node = nodes[i];\n const element = elements[i];\n\n if (!node.type) {\n // skip scalar values, must be a valid VNode\n continue;\n }\n\n //console.log('hydrating', node, 'vs', element);\n\n if (node.attributes.ref) {\n node.attributes.ref.current = element;\n }\n\n for (const key of Object.keys(node.attributes)) {\n if (key.startsWith('on')) {\n // cut away 'on' from the beginning of the event name\n // was: 'onClick' -> now: 'click'\n let eventName = key.substring(2).toLowerCase();\n const capturePos = eventName.indexOf('capture')\n const doCapture = capturePos > -1\n\n if (doCapture) {\n // cut away 'Capture' from the end of the event name\n // was: 'clickCapture' -> now: 'click'\n eventName = eventName.substring(0, capturePos)\n }\n // register event listeners for interactivity\n element.addEventListener(eventName, node.attributes[key]);\n }\n }\n\n if (node.attributes?.onMount) {\n // call onMount with the actual DOM element\n node.attributes.onMount(element);\n }\n\n if (node.children) {\n // recursively hydrate children\n hydrate(node.children as Array<VNode>, Array.from(element.childNodes));\n }\n }\n}\n\nexport * from './index.js'\n"],"names":["renderIsomorphic"],"mappings":";;;;AAEY,MAAC,MAAM,GAAG,CAAC,WAAW,EAAE,gBAAgB,GAAG,QAAQ,CAAC,eAAe,KAAKA,sBAAgB,CAAC,WAAW,EAAE,gBAAgB,EAAE,MAAM;AAC9H,MAAC,cAAc,GAAG,CAAC,EAAE,KAAK,IAAI,aAAa,EAAE,CAAC,iBAAiB,CAAC,EAAE;AAClE,MAAC,OAAO,GAAG,CAAC,KAAK,EAAE,QAAQ,KAAK;AAC5C,EAAE,IAAI,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,EAAE;AACxC,IAAI,MAAM,IAAI,KAAK,CAAC,iHAAiH,CAAC;AACtI;AACA,EAAE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AACzC,IAAI,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC;AACzB,IAAI,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC;AAC/B,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;AACpB,MAAM;AACN;AACA,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE;AAC7B,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,GAAG,OAAO;AAC3C;AACA,IAAI,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;AACpD,MAAM,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;AAChC,QAAQ,IAAI,SAAS,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE;AACtD,QAAQ,MAAM,UAAU,GAAG,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC;AACvD,QAAQ,MAAM,SAAS,GAAG,UAAU,GAAG,CAAC,CAAC;AACzC,QAAQ,IAAI,SAAS,EAAE;AACvB,UAAU,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,UAAU,CAAC;AACxD;AACA,QAAQ,OAAO,CAAC,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AACjE;AACA;AACA,IAAI,IAAI,IAAI,CAAC,UAAU,EAAE,OAAO,EAAE;AAClC,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC;AACtC;AACA,IAAI,IAAI,IAAI,CAAC,QAAQ,EAAE;AACvB,MAAM,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AAC5D;AACA;AACA;;;;;;;;;;;;;"}
|
package/dist/render/client.d.cts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { R as RenderInput, D as Dequery, a as RenderResult } from '../index-
|
|
2
|
-
export { C as CSSProperties, m as Children, n as DomAbstractionImpl, F as FontFaceProperties,
|
|
1
|
+
import { R as RenderInput, D as Dequery, a as RenderResult, e as VNode } from '../index-Csvo7Gd8.js';
|
|
2
|
+
export { C as CSSProperties, m as Children, n as DomAbstractionImpl, F as FontFaceProperties, u as Fragment, G as Globals, K as KeyFrameProperties, P as Props, c as Ref, b as RefUpdateFn, o as RenderNodeInput, p as RenderResultNode, V as VAttributes, d as VNodeAttributes, k as VNodeChild, l as VNodeChildren, g as VNodeKey, j as VNodeRef, i as VNodeRefCallback, h as VNodeRefObject, f as VNodeType, q as createRef, s as getRenderer, r as jsx, w as jsxDEV, v as jsxs, t as renderIsomorphic } from '../index-Csvo7Gd8.js';
|
|
3
3
|
import * as CSS from 'csstype';
|
|
4
4
|
export { CSS };
|
|
5
5
|
|
|
6
6
|
declare const render: <T extends RenderInput>(virtualNode: T, parentDomElement?: Element | Document | Dequery) => RenderResult<T>;
|
|
7
7
|
declare const renderToString: (el: Node) => string;
|
|
8
|
+
declare const hydrate: (nodes: Array<VNode>, elements: Array<HTMLElement | Text | Node>) => void;
|
|
8
9
|
|
|
9
|
-
export { RenderInput, RenderResult, render, renderToString };
|
|
10
|
+
export { RenderInput, RenderResult, VNode, hydrate, render, renderToString };
|
package/dist/render/client.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { R as RenderInput, D as Dequery, a as RenderResult } from '../index-
|
|
2
|
-
export { C as CSSProperties, m as Children, n as DomAbstractionImpl, F as FontFaceProperties,
|
|
1
|
+
import { R as RenderInput, D as Dequery, a as RenderResult, e as VNode } from '../index-Csvo7Gd8.js';
|
|
2
|
+
export { C as CSSProperties, m as Children, n as DomAbstractionImpl, F as FontFaceProperties, u as Fragment, G as Globals, K as KeyFrameProperties, P as Props, c as Ref, b as RefUpdateFn, o as RenderNodeInput, p as RenderResultNode, V as VAttributes, d as VNodeAttributes, k as VNodeChild, l as VNodeChildren, g as VNodeKey, j as VNodeRef, i as VNodeRefCallback, h as VNodeRefObject, f as VNodeType, q as createRef, s as getRenderer, r as jsx, w as jsxDEV, v as jsxs, t as renderIsomorphic } from '../index-Csvo7Gd8.js';
|
|
3
3
|
import * as CSS from 'csstype';
|
|
4
4
|
export { CSS };
|
|
5
5
|
|
|
6
6
|
declare const render: <T extends RenderInput>(virtualNode: T, parentDomElement?: Element | Document | Dequery) => RenderResult<T>;
|
|
7
7
|
declare const renderToString: (el: Node) => string;
|
|
8
|
+
declare const hydrate: (nodes: Array<VNode>, elements: Array<HTMLElement | Text | Node>) => void;
|
|
8
9
|
|
|
9
|
-
export { RenderInput, RenderResult, render, renderToString };
|
|
10
|
+
export { RenderInput, RenderResult, VNode, hydrate, render, renderToString };
|
package/dist/render/client.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var u=Object.defineProperty;var s=(e,r)=>u(e,"name",{value:r,configurable:!0});import{renderIsomorphic as f}from"./index.mjs";import{Fragment as x,createRef as y,getRenderer as S,jsx as j,jsxDEV as C,jsxs as E}from"./index.mjs";const m=s((e,r=document.documentElement)=>f(e,r,window),"render"),l=s(e=>new XMLSerializer().serializeToString(e),"renderToString"),c=s((e,r)=>{if(e.length!==r.length)throw new Error("[defuss] Hydration failed. Number of VNodes from CSR does not match the number of DOM elements rendered in SSR.");for(let n=0;n<e.length;n++){const t=e[n],o=r[n];if(t.type){t.attributes.ref&&(t.attributes.ref.current=o);for(const a of Object.keys(t.attributes))if(a.startsWith("on")){let i=a.substring(2).toLowerCase();const d=i.indexOf("capture");d>-1&&(i=i.substring(0,d)),o.addEventListener(i,t.attributes[a])}t.attributes?.onMount&&t.attributes.onMount(o),t.children&&c(t.children,Array.from(o.childNodes))}}},"hydrate");export{x as Fragment,y as createRef,S as getRenderer,c as hydrate,j as jsx,C as jsxDEV,E as jsxs,m as render,f as renderIsomorphic,l as renderToString};
|
|
2
2
|
//# sourceMappingURL=client.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.mjs","sources":["../../src/render/client.ts"],"sourcesContent":["import type { Dequery } from '../dequery/types.js'\nimport { renderIsomorphic } from './isomorph.js'\nimport type { RenderInput, RenderResult } from './types.js'\n\nexport const render = <T extends RenderInput>(\n virtualNode: T,\n parentDomElement: Element | Document | Dequery = document.documentElement,\n): RenderResult<T> => renderIsomorphic(virtualNode, parentDomElement, window) as any\n\nexport const renderToString = (el: Node) => new XMLSerializer().serializeToString(el)\n\nexport * from './index.js'\n"],"names":[],"mappings":";;;AAEY,MAAC,MAAM,GAAG,CAAC,WAAW,EAAE,gBAAgB,GAAG,QAAQ,CAAC,eAAe,KAAK,gBAAgB,CAAC,WAAW,EAAE,gBAAgB,EAAE,MAAM;AAC9H,MAAC,cAAc,GAAG,CAAC,EAAE,KAAK,IAAI,aAAa,EAAE,CAAC,iBAAiB,CAAC,EAAE;;;;"}
|
|
1
|
+
{"version":3,"file":"client.mjs","sources":["../../src/render/client.ts"],"sourcesContent":["import type { Dequery } from '../dequery/types.js'\nimport { renderIsomorphic } from './isomorph.js'\nimport type { RenderInput, RenderResult, VNode } from './types.js'\n\nexport const render = <T extends RenderInput>(\n virtualNode: T,\n parentDomElement: Element | Document | Dequery = document.documentElement,\n): RenderResult<T> => renderIsomorphic(virtualNode, parentDomElement, window) as any\n\nexport const renderToString = (el: Node) => new XMLSerializer().serializeToString(el)\n\n// 1. any item in roots that has a ref object needs to update ref.current to the actual DOM element\n// 2. any event listener must be attached to the actual DOM element\n// 3. onMount needs to be called with the actual DOM element, if registered\nexport const hydrate = (nodes: Array<VNode>, elements: Array<HTMLElement|Text|Node>) => {\n\n if (nodes.length !== elements.length) {\n throw new Error('[defuss] Hydration failed. Number of VNodes from CSR does not match the number of DOM elements rendered in SSR.');\n }\n\n for (let i = 0; i < nodes.length; i++) {\n\n const node = nodes[i];\n const element = elements[i];\n\n if (!node.type) {\n // skip scalar values, must be a valid VNode\n continue;\n }\n\n //console.log('hydrating', node, 'vs', element);\n\n if (node.attributes.ref) {\n node.attributes.ref.current = element;\n }\n\n for (const key of Object.keys(node.attributes)) {\n if (key.startsWith('on')) {\n // cut away 'on' from the beginning of the event name\n // was: 'onClick' -> now: 'click'\n let eventName = key.substring(2).toLowerCase();\n const capturePos = eventName.indexOf('capture')\n const doCapture = capturePos > -1\n\n if (doCapture) {\n // cut away 'Capture' from the end of the event name\n // was: 'clickCapture' -> now: 'click'\n eventName = eventName.substring(0, capturePos)\n }\n // register event listeners for interactivity\n element.addEventListener(eventName, node.attributes[key]);\n }\n }\n\n if (node.attributes?.onMount) {\n // call onMount with the actual DOM element\n node.attributes.onMount(element);\n }\n\n if (node.children) {\n // recursively hydrate children\n hydrate(node.children as Array<VNode>, Array.from(element.childNodes));\n }\n }\n}\n\nexport * from './index.js'\n"],"names":[],"mappings":";;;AAEY,MAAC,MAAM,GAAG,CAAC,WAAW,EAAE,gBAAgB,GAAG,QAAQ,CAAC,eAAe,KAAK,gBAAgB,CAAC,WAAW,EAAE,gBAAgB,EAAE,MAAM;AAC9H,MAAC,cAAc,GAAG,CAAC,EAAE,KAAK,IAAI,aAAa,EAAE,CAAC,iBAAiB,CAAC,EAAE;AAClE,MAAC,OAAO,GAAG,CAAC,KAAK,EAAE,QAAQ,KAAK;AAC5C,EAAE,IAAI,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,EAAE;AACxC,IAAI,MAAM,IAAI,KAAK,CAAC,iHAAiH,CAAC;AACtI;AACA,EAAE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AACzC,IAAI,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC;AACzB,IAAI,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC;AAC/B,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;AACpB,MAAM;AACN;AACA,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE;AAC7B,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,GAAG,OAAO;AAC3C;AACA,IAAI,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;AACpD,MAAM,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;AAChC,QAAQ,IAAI,SAAS,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE;AACtD,QAAQ,MAAM,UAAU,GAAG,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC;AACvD,QAAQ,MAAM,SAAS,GAAG,UAAU,GAAG,CAAC,CAAC;AACzC,QAAQ,IAAI,SAAS,EAAE;AACvB,UAAU,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,UAAU,CAAC;AACxD;AACA,QAAQ,OAAO,CAAC,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AACjE;AACA;AACA,IAAI,IAAI,IAAI,CAAC,UAAU,EAAE,OAAO,EAAE;AAClC,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC;AACtC;AACA,IAAI,IAAI,IAAI,CAAC,QAAQ,EAAE;AACvB,MAAM,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AAC5D;AACA;AACA;;;;"}
|
package/dist/render/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var a=Object.defineProperty;var i=(r,s)=>a(r,"name",{value:s,configurable:!0});const g="class",y="xlink",T="xmlns",x="ref",h={[T]:"http://www.w3.org/2000/xmlns/",[y]:"http://www.w3.org/1999/xlink",svg:"http://www.w3.org/2000/svg"},d=i(r=>r&&typeof r=="object"&&!r.attributes&&!r.type&&!r.children,"isJSXComment"),b=i(r=>r.filter(s=>!d(s)),"filterComments");function w(r){const s={$subscriberFns:[],current:null,update:i(e=>{s.$subscriberFns.forEach(t=>t(e))},"update"),subscribe:i(e=>(s.$subscriberFns.push(e),()=>{const t=s.$subscriberFns.indexOf(e);t!==-1&&s.$subscriberFns.splice(t,1)}),"subscribe")};return typeof r=="function"&&s.subscribe(r),s}i(w,"createRef");const u=i((r,s)=>{s={...s};let e=(s?.children?[].concat(s.children):[]).filter(Boolean);return delete s?.children,e=b([].concat.apply([],e)),r==="fragment"?b(e):typeof r=="function"?r({children:e,...s}):{type:r,attributes:s,children:e}},"jsx"),l=i(r=>{const s={hasElNamespace:i(e=>e.namespaceURI===h.svg,"hasElNamespace"),hasSvgNamespace:i((e,t)=>s.hasElNamespace(e)&&t!=="STYLE"&&t!=="SCRIPT","hasSvgNamespace"),createElementOrElements:i((e,t)=>Array.isArray(e)?s.createChildElements(e,t):typeof e<"u"?s.createElement(e,t):s.createTextNode("",t),"createElementOrElements"),createElement:i((e,t)=>{let n;return e.type.toUpperCase()==="SVG"||t&&s.hasSvgNamespace(t,e.type.toUpperCase())?n=r.createElementNS(h.svg,e.type):n=r.createElement(e.type),e.attributes&&(s.setAttributes(e.attributes,n),e.attributes.dangerouslySetInnerHTML&&(n.innerHTML=e.attributes.dangerouslySetInnerHTML.__html)),e.children&&s.createChildElements(e.children,n),t&&(t.appendChild(n),typeof n.$onMount=="function"&&n.$onMount()),n},"createElement"),createTextNode:i((e,t)=>{const n=r.createTextNode(e.toString());return t&&t.appendChild(n),n},"createTextNode"),createChildElements:i((e,t)=>{const n=[];for(let o=0;o<e.length;o++){const c=e[o];c===null||typeof c!="object"&&typeof c!="function"?n.push(s.createTextNode((typeof c>"u"||c===null?"":c).toString(),t)):n.push(s.createElement(c,t))}return n},"createChildElements"),setAttribute:i((e,t,n)=>{if(typeof t>"u"||e==="dangerouslySetInnerHTML")return;if(e===x&&typeof t!="function"&&(t.current=n),e.startsWith("on")&&typeof t=="function"){let c=e.substring(2).toLowerCase();const f=c.indexOf("capture"),p=f>-1;c==="mount"&&(n.$onMount=t),p&&(c=c.substring(0,f)),n.addEventListener(c,t,p);return}e==="className"&&(e=g),e===g&&Array.isArray(t)&&(t=t.join(" "));const o=e.match(/[A-Z]/)?.index;if(s.hasElNamespace(n)&&o){const c=e.substring(0,o).toLowerCase(),f=e.substring(o,e.length).toLowerCase(),p=h[c]||null;n.setAttributeNS(p,c===y||c==="xmlns"?`${c}:${f}`:e,t)}else if(e==="style"&&typeof t!="string"){const c=Object.keys(t);for(let f=0;f<c.length;f++)n.style[c[f]]=t[c[f]]}else typeof t=="boolean"?n[e]=t:n.setAttribute(e,t)},"setAttribute"),setAttributes:i((e,t)=>{const n=Object.keys(e);for(let o=0;o<n.length;o++)s.setAttribute(n[o],e[n[o]],t)},"setAttributes")};return s},"getRenderer"),A=i((r,s,e)=>{const t=s.el||s;return typeof r=="string"?l(e.window.document).createTextNode(r,t):l(e.window.document).createElementOrElements(r,t)},"renderIsomorphic"),E=i(r=>r.children,"Fragment"),S=u,C=u;exports.Fragment=E,exports.createRef=w,exports.getRenderer=l,exports.jsx=u,exports.jsxDEV=C,exports.jsxs=S,exports.renderIsomorphic=A;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/render/isomorph.ts"],"sourcesContent":["import type { Dequery } from '../dequery/types.js'\nimport type { VNodeChild, VNodeChildren, VNode, VNodeType, Ref, VNodeAttributes, DomAbstractionImpl, Globals } from './types.js'\n\nconst CLASS_ATTRIBUTE_NAME = 'class'\nconst XLINK_ATTRIBUTE_NAME = 'xlink'\nconst XMLNS_ATTRIBUTE_NAME = 'xmlns'\nconst REF_ATTRIBUTE_NAME = 'ref'\n\nconst nsMap = {\n [XMLNS_ATTRIBUTE_NAME]: 'http://www.w3.org/2000/xmlns/',\n [XLINK_ATTRIBUTE_NAME]: 'http://www.w3.org/1999/xlink',\n svg: 'http://www.w3.org/2000/svg',\n}\n\n// If a JSX comment is written, it looks like: { /* this */ }\n// Therefore, it turns into: {}, which is detected here\nconst isJSXComment = (node: VNode): boolean =>\n /* v8 ignore next */\n node && typeof node === 'object' && !node.attributes && !node.type && !node.children\n\n// Filters comments and undefines like: ['a', 'b', false, {}] to: ['a', 'b', false]\nconst filterComments = (children: Array<VNode> | Array<VNodeChild>) =>\n children.filter((child: VNodeChild) => !isJSXComment(child as VNode))\n\nconst onUpdateFn = function (this: Ref, callback: Function) {\n this.update = callback as any\n}\n\nexport const jsx = (\n type: VNodeType | Function | any,\n attributes: (JSX.HTMLAttributes & JSX.SVGAttributes & Record<string, any>) | null,\n): Array<VNode> | VNode => {\n // extract children from attributes and ensure it's always an array\n const { children: rawChildren = [], ...restAttributes } = attributes || {};\n const childrenArray = Array.isArray(rawChildren) ? rawChildren : [rawChildren];\n\n const children = filterComments(\n ([] as Array<VNodeChildren>).concat(...childrenArray as any) as Array<VNodeChildren>,\n );\n\n // effectively unwrap by directly returning the children\n if (type === 'fragment') {\n return filterComments(children) as Array<VNode>;\n }\n\n // it's a component, divide and conquer children\n if (typeof type === 'function') {\n if (restAttributes.ref) {\n (restAttributes.ref as Ref)!.onUpdate = onUpdateFn.bind(restAttributes.ref as Ref) as any;\n }\n\n return type({\n children,\n ...restAttributes,\n });\n }\n\n return {\n type,\n attributes: restAttributes as any,\n children,\n };\n}\n\nexport const getRenderer = (document: Document): DomAbstractionImpl => {\n // DOM abstraction layer for manipulation\n const renderer = {\n hasElNamespace: (domElement: Element | Document): boolean => (domElement as Element).namespaceURI === nsMap.svg,\n\n hasSvgNamespace: (parentElement: Element | Document, type: string): boolean =>\n renderer.hasElNamespace(parentElement) && type !== 'STYLE' && type !== 'SCRIPT',\n\n createElementOrElements: (\n virtualNode: VNode | undefined | Array<VNode | undefined | string>,\n parentDomElement?: Element | Document,\n ): Array<Element | Text | undefined> | Element | Text | undefined => {\n if (Array.isArray(virtualNode)) {\n return renderer.createChildElements(virtualNode, parentDomElement)\n }\n if (typeof virtualNode !== 'undefined') {\n return renderer.createElement(virtualNode, parentDomElement)\n }\n // undefined virtualNode -> e.g. when a tsx variable is used in markup which is undefined\n return renderer.createTextNode('', parentDomElement)\n },\n\n createElement: (virtualNode: VNode, parentDomElement?: Element | Document): Element | undefined => {\n let newEl: Element\n\n if (\n virtualNode.type.toUpperCase() === 'SVG' ||\n (parentDomElement && renderer.hasSvgNamespace(parentDomElement, virtualNode.type.toUpperCase()))\n ) {\n newEl = document.createElementNS(nsMap.svg, virtualNode.type as string)\n } else {\n newEl = document.createElement(virtualNode.type as string)\n }\n\n if (virtualNode.attributes) {\n renderer.setAttributes(virtualNode.attributes, newEl as Element)\n\n // Apply dangerouslySetInnerHTML if provided\n if (virtualNode.attributes.dangerouslySetInnerHTML) {\n newEl.innerHTML = virtualNode.attributes.dangerouslySetInnerHTML.__html;\n }\n }\n\n if (virtualNode.children) {\n renderer.createChildElements(virtualNode.children, newEl as Element)\n }\n\n\n if (parentDomElement) {\n parentDomElement.appendChild(newEl)\n\n // check for a lifecycle \"onMount\" hook and call it\n if (typeof (newEl as any).$onMount === 'function') {\n ;(newEl as any).$onMount!()\n }\n }\n return newEl as Element\n },\n\n createTextNode: (text: string, domElement?: Element | Document): Text => {\n const node = document.createTextNode(text.toString())\n\n if (domElement) {\n domElement.appendChild(node)\n }\n return node\n },\n\n createChildElements: (\n virtualChildren: VNodeChildren,\n domElement?: Element | Document,\n ): Array<Element | Text | undefined> => {\n const children: Array<Element | Text | undefined> = []\n\n for (let i = 0; i < virtualChildren.length; i++) {\n const virtualChild = virtualChildren[i]\n if (virtualChild === null || (typeof virtualChild !== 'object' && typeof virtualChild !== 'function')) {\n children.push(\n renderer.createTextNode(\n (typeof virtualChild === 'undefined' || virtualChild === null ? '' : virtualChild!).toString(),\n domElement,\n ),\n )\n } else {\n children.push(renderer.createElement(virtualChild as VNode, domElement))\n }\n }\n return children\n },\n\n setAttribute: (name: string, value: any, domElement: Element) => {\n // attributes not set (undefined) are ignored; use null value to reset an attributes state\n if (typeof value === 'undefined') return\n if (name === 'children' || name === 'dangerouslySetInnerHTML') return;\n\n // save ref as { current: DOMElement } in ref object\n // allows for ref={someRef}\n if (name === REF_ATTRIBUTE_NAME && typeof value !== 'function') {\n value.current = domElement\n } else if (name === REF_ATTRIBUTE_NAME && typeof value === 'function') {\n // allow for functional ref's like: render(<div ref={(el) => console.log('got el', el)} />)\n value(domElement)\n }\n\n if (name.startsWith('on') && typeof value === 'function') {\n let eventName = name.substring(2).toLowerCase()\n const capturePos = eventName.indexOf('capture')\n const doCapture = capturePos > -1\n\n if (eventName === 'mount') {\n ;(domElement as any).$onMount = value\n }\n\n // onClickCapture={...} support\n if (doCapture) {\n eventName = eventName.substring(0, capturePos)\n }\n domElement.addEventListener(eventName, value, doCapture)\n return\n }\n\n // transforms className=\"...\" -> class=\"...\"\n // allows for React TSX to work seamlessly\n if (name === 'className') {\n name = CLASS_ATTRIBUTE_NAME\n }\n\n // transforms class={['a', 'b']} into class=\"a b\"\n if (name === CLASS_ATTRIBUTE_NAME && Array.isArray(value)) {\n value = value.join(' ')\n }\n\n const nsEndIndex = name.match(/[A-Z]/)?.index\n if (renderer.hasElNamespace(domElement) && nsEndIndex) {\n const ns = name.substring(0, nsEndIndex).toLowerCase()\n const attrName = name.substring(nsEndIndex, name.length).toLowerCase()\n const namespace = nsMap[ns as keyof typeof nsMap] || null\n domElement.setAttributeNS(\n namespace,\n ns === XLINK_ATTRIBUTE_NAME || ns === 'xmlns' ? `${ns}:${attrName}` : name,\n value,\n )\n } else if (name === 'style' && typeof value !== 'string') {\n const propNames = Object.keys(value)\n\n // allows for style={{ margin: 10 }} etc.\n for (let i = 0; i < propNames.length; i++) {\n ;(domElement as HTMLElement).style[propNames[i] as any] = value[propNames[i]]\n }\n } else if (typeof value === 'boolean') {\n // for cases like <button checked={false} />\n ;(domElement as any)[name] = value\n } else {\n // for any other case\n domElement.setAttribute(name, value)\n }\n },\n\n setAttributes: (attributes: VNodeAttributes, domElement: Element) => {\n const attrNames = Object.keys(attributes)\n for (let i = 0; i < attrNames.length; i++) {\n renderer.setAttribute(attrNames[i], attributes[attrNames[i]], domElement)\n }\n },\n }\n return renderer\n}\n\nexport const renderIsomorphic = (\n virtualNode: VNode | undefined | string | Array<VNode | undefined | string>,\n parentDomElement: Element | Document | Dequery | undefined,\n globals: Globals,\n): Array<Element | Text | undefined> | Element | Text | undefined => {\n\n const parentEl = (parentDomElement as Dequery).el as Element || parentDomElement\n\n if (typeof virtualNode === 'string') {\n return getRenderer(globals.window.document).createTextNode(virtualNode, parentEl)\n }\n return getRenderer(globals.window.document).createElementOrElements(virtualNode, parentEl)\n}\n\nexport const Fragment = (props: VNode) => props.children\nexport const jsxs = jsx\nexport const jsxDEV = jsx\n\nexport default {\n jsx,\n Fragment,\n renderIsomorphic,\n getRenderer,\n onUpdateFn,\n\n // implementing the full standard\n // https://github.com/reactjs/rfcs/blob/createlement-rfc/text/0000-create-element-changes.md\n jsxs,\n jsxDEV,\n};"],"names":[],"mappings":";;AACA,MAAM,oBAAoB,GAAG,OAAO;AACpC,MAAM,oBAAoB,GAAG,OAAO;AACpC,MAAM,oBAAoB,GAAG,OAAO;AACpC,MAAM,kBAAkB,GAAG,KAAK;AAChC,MAAM,KAAK,GAAG;AACd,EAAE,CAAC,oBAAoB,GAAG,+BAA+B;AACzD,EAAE,CAAC,oBAAoB,GAAG,8BAA8B;AACxD,EAAE,GAAG,EAAE;AACP,CAAC;AACD,MAAM,YAAY,GAAG,CAAC,IAAI;AAC1B;AACA,EAAE,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC;AAC9E,CAAC;AACD,MAAM,cAAc,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC,MAAM,CAAC,CAAC,KAAK,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;AACrF,MAAM,UAAU,GAAG,SAAS,QAAQ,EAAE;AACtC,EAAE,IAAI,CAAC,MAAM,GAAG,QAAQ;AACxB,CAAC;AACW,MAAC,GAAG,GAAG,CAAC,IAAI,EAAE,UAAU,KAAK;AACzC,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,GAAG,EAAE,EAAE,GAAG,cAAc,EAAE,GAAG,UAAU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AAS,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC;AACjF;AACA;AACA,GAAG;AACH,EAAE,OAAO,QAAQ;AACjB;AACY,MAAC,gBAAgB,GAAG,CAAC,WAAW,EAAE,gBAAgB,EAAE,OAAO,KAAK;AAC5E,EAAE,MAAM,QAAQ,GAAG,gBAAgB,CAAC,EAAE,IAAI,gBAAgB;AAC1D,EAAE,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE;AACvC,IAAI,OAAO,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,cAAc,CAAC,WAAW,EAAE,QAAQ,CAAC;AACrF;AACA,EAAE,OAAO,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,uBAAuB,CAAC,WAAW,EAAE,QAAQ,CAAC;AAC5F;AACY,MAAC,QAAQ,GAAG,CAAC,KAAK,KAAK,KAAK,CAAC;AAC7B,MAAC,IAAI,GAAG;AACR,MAAC,MAAM,GAAG;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/render/isomorph.ts"],"sourcesContent":["import type { Dequery } from '../dequery/types.js'\nimport type { VNodeChild, VNodeChildren, VNode, VNodeType, Ref, VNodeAttributes, DomAbstractionImpl, Globals, RefUpdateFn } from './types.js'\n\nconst CLASS_ATTRIBUTE_NAME = 'class'\nconst XLINK_ATTRIBUTE_NAME = 'xlink'\nconst XMLNS_ATTRIBUTE_NAME = 'xmlns'\nconst REF_ATTRIBUTE_NAME = 'ref'\n\nconst nsMap = {\n [XMLNS_ATTRIBUTE_NAME]: 'http://www.w3.org/2000/xmlns/',\n [XLINK_ATTRIBUTE_NAME]: 'http://www.w3.org/1999/xlink',\n svg: 'http://www.w3.org/2000/svg',\n}\n\n// If a JSX comment is written, it looks like: { /* this */ }\n// Therefore, it turns into: {}, which is detected here\nconst isJSXComment = (node: VNode): boolean =>\n /* v8 ignore next */\n node && typeof node === 'object' && !node.attributes && !node.type && !node.children\n\n// Filters comments and undefines like: ['a', 'b', false, {}] to: ['a', 'b', false]\nconst filterComments = (children: Array<VNode> | Array<VNodeChild>) =>\n children.filter((child: VNodeChild) => !isJSXComment(child as VNode))\n\nexport function createRef<T extends Node | Element | Text | null = null, D = unknown>(refUpdateFn?: RefUpdateFn<D>): Ref<T, D> {\n const ref: Ref<T, D> = { \n $subscriberFns: [],\n current: null as T,\n update: (state: D) => {\n ref.$subscriberFns.forEach(fn => fn(state));\n },\n subscribe: (refUpdateFn: RefUpdateFn<D>) => {\n ref.$subscriberFns.push(refUpdateFn);\n // unsubscribe function\n return () => {\n const index = ref.$subscriberFns.indexOf(refUpdateFn);\n if (index !== -1) {\n ref.$subscriberFns.splice(index, 1);\n }\n }\n },\n }\n\n if (typeof refUpdateFn === 'function') {\n ref.subscribe(refUpdateFn);\n }\n return ref;\n}\n\nexport const jsx = (\n type: VNodeType | Function | any,\n attributes: (JSX.HTMLAttributes & JSX.SVGAttributes & Record<string, any>) | null,\n): Array<VNode> | VNode => {\n\n // clone attributes as well\n attributes = { ...attributes }\n\n // extract children from attributes and ensure it's always an array\n let children: Array<VNodeChild> = (attributes?.children ? [].concat(attributes.children) : []).filter(Boolean);\n delete attributes?.children;\n\n children = filterComments(\n // Implementation to flatten virtual node children structures like:\n // [<p>1</p>, [<p>2</p>,<p>3</p>]] to: [<p>1</p>,<p>2</p>,<p>3</p>]\n ([] as Array<VNodeChildren>).concat.apply([], children as any) as Array<VNodeChildren>,\n )\n\n // effectively unwrap by directly returning the children\n if (type === 'fragment') {\n return filterComments(children) as Array<VNode>;\n }\n\n // it's a component, divide and conquer children\n if (typeof type === 'function') {\n return type({\n children,\n ...attributes,\n })\n }\n\n return {\n type,\n attributes,\n children,\n };\n}\n\nexport const getRenderer = (document: Document): DomAbstractionImpl => {\n // DOM abstraction layer for manipulation\n const renderer = {\n hasElNamespace: (domElement: Element | Document): boolean => (domElement as Element).namespaceURI === nsMap.svg,\n\n hasSvgNamespace: (parentElement: Element | Document, type: string): boolean =>\n renderer.hasElNamespace(parentElement) && type !== 'STYLE' && type !== 'SCRIPT',\n\n createElementOrElements: (\n virtualNode: VNode | undefined | Array<VNode | undefined | string>,\n parentDomElement?: Element | Document,\n ): Array<Element | Text | undefined> | Element | Text | undefined => {\n if (Array.isArray(virtualNode)) {\n return renderer.createChildElements(virtualNode, parentDomElement)\n }\n if (typeof virtualNode !== 'undefined') {\n return renderer.createElement(virtualNode, parentDomElement)\n }\n // undefined virtualNode -> e.g. when a tsx variable is used in markup which is undefined\n return renderer.createTextNode('', parentDomElement)\n },\n\n createElement: (virtualNode: VNode, parentDomElement?: Element | Document): Element | undefined => {\n let newEl: Element\n\n if (\n virtualNode.type.toUpperCase() === 'SVG' ||\n (parentDomElement && renderer.hasSvgNamespace(parentDomElement, virtualNode.type.toUpperCase()))\n ) {\n newEl = document.createElementNS(nsMap.svg, virtualNode.type as string)\n } else {\n newEl = document.createElement(virtualNode.type as string)\n }\n\n if (virtualNode.attributes) {\n renderer.setAttributes(virtualNode.attributes, newEl as Element)\n\n // Apply dangerouslySetInnerHTML if provided\n if (virtualNode.attributes.dangerouslySetInnerHTML) {\n newEl.innerHTML = virtualNode.attributes.dangerouslySetInnerHTML.__html;\n }\n }\n\n if (virtualNode.children) {\n renderer.createChildElements(virtualNode.children, newEl as Element)\n }\n\n\n if (parentDomElement) {\n parentDomElement.appendChild(newEl)\n\n // check for a lifecycle \"onMount\" hook and call it\n if (typeof (newEl as any).$onMount === 'function') {\n ;(newEl as any).$onMount!()\n }\n }\n return newEl as Element\n },\n\n createTextNode: (text: string, domElement?: Element | Document): Text => {\n const node = document.createTextNode(text.toString())\n\n if (domElement) {\n domElement.appendChild(node)\n }\n return node\n },\n\n createChildElements: (\n virtualChildren: VNodeChildren,\n domElement?: Element | Document,\n ): Array<Element | Text | undefined> => {\n const children: Array<Element | Text | undefined> = []\n\n for (let i = 0; i < virtualChildren.length; i++) {\n const virtualChild = virtualChildren[i]\n if (virtualChild === null || (typeof virtualChild !== 'object' && typeof virtualChild !== 'function')) {\n children.push(\n renderer.createTextNode(\n (typeof virtualChild === 'undefined' || virtualChild === null ? '' : virtualChild!).toString(),\n domElement,\n ),\n )\n } else {\n children.push(renderer.createElement(virtualChild as VNode, domElement))\n }\n }\n return children\n },\n\n setAttribute: (name: string, value: any, domElement: Element) => {\n // attributes not set (undefined) are ignored; use null value to reset an attributes state\n if (typeof value === 'undefined') return\n if (name === 'dangerouslySetInnerHTML') return;\n\n // save ref as { current: DOMElement } in ref object\n // allows for ref={someRef}\n if (name === REF_ATTRIBUTE_NAME && typeof value !== 'function') {\n value.current = domElement\n }/* else if (name === REF_ATTRIBUTE_NAME && typeof value === 'function') {\n // allow for functional ref's like: render(<div ref={(el) => console.log('got el', el)} />)\n value(domElement)\n }*/\n\n if (name.startsWith('on') && typeof value === 'function') {\n\n let eventName = name.substring(2).toLowerCase()\n const capturePos = eventName.indexOf('capture')\n const doCapture = capturePos > -1\n\n if (eventName === 'mount') {\n ;(domElement as any).$onMount = value // lifecycle hook\n }\n\n // onClickCapture={...} support\n if (doCapture) {\n eventName = eventName.substring(0, capturePos)\n\n // mark this event as a capture event to be registered correctly in hydration phase\n //domElement.setAttribute(`data-defuss-capture-${eventName}`, \"true\")\n }\n domElement.addEventListener(eventName, value, doCapture)\n return\n }\n\n // transforms className=\"...\" -> class=\"...\"\n // allows for React JSX to work seamlessly\n if (name === 'className') {\n name = CLASS_ATTRIBUTE_NAME\n }\n\n // transforms class={['a', 'b']} into class=\"a b\"\n if (name === CLASS_ATTRIBUTE_NAME && Array.isArray(value)) {\n value = value.join(' ')\n }\n\n const nsEndIndex = name.match(/[A-Z]/)?.index\n if (renderer.hasElNamespace(domElement) && nsEndIndex) {\n const ns = name.substring(0, nsEndIndex).toLowerCase()\n const attrName = name.substring(nsEndIndex, name.length).toLowerCase()\n const namespace = nsMap[ns as keyof typeof nsMap] || null\n domElement.setAttributeNS(\n namespace,\n ns === XLINK_ATTRIBUTE_NAME || ns === 'xmlns' ? `${ns}:${attrName}` : name,\n value,\n )\n } else if (name === 'style' && typeof value !== 'string') {\n const propNames = Object.keys(value)\n\n // allows for style={{ margin: 10 }} etc.\n for (let i = 0; i < propNames.length; i++) {\n ;(domElement as HTMLElement).style[propNames[i] as any] = value[propNames[i]]\n }\n } else if (typeof value === 'boolean') {\n // for cases like <button checked={false} />\n ;(domElement as any)[name] = value\n } else {\n // for any other case\n domElement.setAttribute(name, value)\n }\n },\n\n setAttributes: (attributes: VNodeAttributes, domElement: Element) => {\n const attrNames = Object.keys(attributes)\n for (let i = 0; i < attrNames.length; i++) {\n renderer.setAttribute(attrNames[i], attributes[attrNames[i]], domElement)\n }\n },\n }\n return renderer\n}\n\nexport const renderIsomorphic = (\n virtualNode: VNode | undefined | string | Array<VNode | undefined | string>,\n parentDomElement: Element | Document | Dequery | undefined,\n globals: Globals,\n): Array<Element | Text | undefined> | Element | Text | undefined => {\n\n const parentEl = (parentDomElement as Dequery).el as Element || parentDomElement\n\n if (typeof virtualNode === 'string') {\n return getRenderer(globals.window.document).createTextNode(virtualNode, parentEl)\n }\n return getRenderer(globals.window.document).createElementOrElements(virtualNode, parentEl)\n}\n\n// --- JSX standard (necessary exports for jsx-runtime)\nexport const Fragment = (props: VNode) => props.children\nexport const jsxs = jsx\nexport const jsxDEV = jsx\n\nexport default {\n jsx,\n Fragment,\n renderIsomorphic,\n getRenderer,\n\n // implementing the full standard\n // https://github.com/reactjs/rfcs/blob/createlement-rfc/text/0000-create-element-changes.md\n jsxs,\n jsxDEV,\n};"],"names":[],"mappings":";;AACA,MAAM,oBAAoB,GAAG,OAAO;AACpC,MAAM,oBAAoB,GAAG,OAAO;AACpC,MAAM,oBAAoB,GAAG,OAAO;AACpC,MAAM,kBAAkB,GAAG,KAAK;AAChC,MAAM,KAAK,GAAG;AACd,EAAE,CAAC,oBAAoB,GAAG,+BAA+B;AACzD,EAAE,CAAC,oBAAoB,GA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AAK;AAC5E,EAAE,MAAM,QAAQ,GAAG,gBAAgB,CAAC,EAAE,IAAI,gBAAgB;AAC1D,EAAE,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE;AACvC,IAAI,OAAO,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,cAAc,CAAC,WAAW,EAAE,QAAQ,CAAC;AACrF;AACA,EAAE,OAAO,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,uBAAuB,CAAC,WAAW,EAAE,QAAQ,CAAC;AAC5F;AACY,MAAC,QAAQ,GAAG,CAAC,KAAK,KAAK,KAAK,CAAC;AAC7B,MAAC,IAAI,GAAG;AACR,MAAC,MAAM,GAAG;;;;;;;;;;"}
|
package/dist/render/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { C as CSSProperties, m as Children, n as DomAbstractionImpl, F as FontFaceProperties,
|
|
1
|
+
export { C as CSSProperties, m as Children, n as DomAbstractionImpl, F as FontFaceProperties, u as Fragment, G as Globals, K as KeyFrameProperties, P as Props, c as Ref, b as RefUpdateFn, R as RenderInput, o as RenderNodeInput, a as RenderResult, p as RenderResultNode, V as VAttributes, e as VNode, d as VNodeAttributes, k as VNodeChild, l as VNodeChildren, g as VNodeKey, j as VNodeRef, i as VNodeRefCallback, h as VNodeRefObject, f as VNodeType, q as createRef, s as getRenderer, r as jsx, w as jsxDEV, v as jsxs, t as renderIsomorphic } from '../index-Csvo7Gd8.js';
|
|
2
2
|
import * as CSS from 'csstype';
|
|
3
3
|
export { CSS };
|
package/dist/render/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { C as CSSProperties, m as Children, n as DomAbstractionImpl, F as FontFaceProperties,
|
|
1
|
+
export { C as CSSProperties, m as Children, n as DomAbstractionImpl, F as FontFaceProperties, u as Fragment, G as Globals, K as KeyFrameProperties, P as Props, c as Ref, b as RefUpdateFn, R as RenderInput, o as RenderNodeInput, a as RenderResult, p as RenderResultNode, V as VAttributes, e as VNode, d as VNodeAttributes, k as VNodeChild, l as VNodeChildren, g as VNodeKey, j as VNodeRef, i as VNodeRefCallback, h as VNodeRefObject, f as VNodeType, q as createRef, s as getRenderer, r as jsx, w as jsxDEV, v as jsxs, t as renderIsomorphic } from '../index-Csvo7Gd8.js';
|
|
2
2
|
import * as CSS from 'csstype';
|
|
3
3
|
export { CSS };
|
package/dist/render/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var T=Object.defineProperty;var i=(r,s)=>T(r,"name",{value:s,configurable:!0});const y="class",b="xlink",a="xmlns",w="ref",h={[a]:"http://www.w3.org/2000/xmlns/",[b]:"http://www.w3.org/1999/xlink",svg:"http://www.w3.org/2000/svg"},A=i(r=>r&&typeof r=="object"&&!r.attributes&&!r.type&&!r.children,"isJSXComment"),g=i(r=>r.filter(s=>!A(s)),"filterComments");function x(r){const s={$subscriberFns:[],current:null,update:i(e=>{s.$subscriberFns.forEach(t=>t(e))},"update"),subscribe:i(e=>(s.$subscriberFns.push(e),()=>{const t=s.$subscriberFns.indexOf(e);t!==-1&&s.$subscriberFns.splice(t,1)}),"subscribe")};return typeof r=="function"&&s.subscribe(r),s}i(x,"createRef");const u=i((r,s)=>{s={...s};let e=(s?.children?[].concat(s.children):[]).filter(Boolean);return delete s?.children,e=g([].concat.apply([],e)),r==="fragment"?g(e):typeof r=="function"?r({children:e,...s}):{type:r,attributes:s,children:e}},"jsx"),l=i(r=>{const s={hasElNamespace:i(e=>e.namespaceURI===h.svg,"hasElNamespace"),hasSvgNamespace:i((e,t)=>s.hasElNamespace(e)&&t!=="STYLE"&&t!=="SCRIPT","hasSvgNamespace"),createElementOrElements:i((e,t)=>Array.isArray(e)?s.createChildElements(e,t):typeof e<"u"?s.createElement(e,t):s.createTextNode("",t),"createElementOrElements"),createElement:i((e,t)=>{let n;return e.type.toUpperCase()==="SVG"||t&&s.hasSvgNamespace(t,e.type.toUpperCase())?n=r.createElementNS(h.svg,e.type):n=r.createElement(e.type),e.attributes&&(s.setAttributes(e.attributes,n),e.attributes.dangerouslySetInnerHTML&&(n.innerHTML=e.attributes.dangerouslySetInnerHTML.__html)),e.children&&s.createChildElements(e.children,n),t&&(t.appendChild(n),typeof n.$onMount=="function"&&n.$onMount()),n},"createElement"),createTextNode:i((e,t)=>{const n=r.createTextNode(e.toString());return t&&t.appendChild(n),n},"createTextNode"),createChildElements:i((e,t)=>{const n=[];for(let o=0;o<e.length;o++){const c=e[o];c===null||typeof c!="object"&&typeof c!="function"?n.push(s.createTextNode((typeof c>"u"||c===null?"":c).toString(),t)):n.push(s.createElement(c,t))}return n},"createChildElements"),setAttribute:i((e,t,n)=>{if(typeof t>"u"||e==="dangerouslySetInnerHTML")return;if(e===w&&typeof t!="function"&&(t.current=n),e.startsWith("on")&&typeof t=="function"){let c=e.substring(2).toLowerCase();const f=c.indexOf("capture"),p=f>-1;c==="mount"&&(n.$onMount=t),p&&(c=c.substring(0,f)),n.addEventListener(c,t,p);return}e==="className"&&(e=y),e===y&&Array.isArray(t)&&(t=t.join(" "));const o=e.match(/[A-Z]/)?.index;if(s.hasElNamespace(n)&&o){const c=e.substring(0,o).toLowerCase(),f=e.substring(o,e.length).toLowerCase(),p=h[c]||null;n.setAttributeNS(p,c===b||c==="xmlns"?`${c}:${f}`:e,t)}else if(e==="style"&&typeof t!="string"){const c=Object.keys(t);for(let f=0;f<c.length;f++)n.style[c[f]]=t[c[f]]}else typeof t=="boolean"?n[e]=t:n.setAttribute(e,t)},"setAttribute"),setAttributes:i((e,t)=>{const n=Object.keys(e);for(let o=0;o<n.length;o++)s.setAttribute(n[o],e[n[o]],t)},"setAttributes")};return s},"getRenderer"),d=i((r,s,e)=>{const t=s.el||s;return typeof r=="string"?l(e.window.document).createTextNode(r,t):l(e.window.document).createElementOrElements(r,t)},"renderIsomorphic"),E=i(r=>r.children,"Fragment"),S=u,C=u;export{E as Fragment,x as createRef,l as getRenderer,u as jsx,C as jsxDEV,S as jsxs,d as renderIsomorphic};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/render/isomorph.ts"],"sourcesContent":["import type { Dequery } from '../dequery/types.js'\nimport type { VNodeChild, VNodeChildren, VNode, VNodeType, Ref, VNodeAttributes, DomAbstractionImpl, Globals } from './types.js'\n\nconst CLASS_ATTRIBUTE_NAME = 'class'\nconst XLINK_ATTRIBUTE_NAME = 'xlink'\nconst XMLNS_ATTRIBUTE_NAME = 'xmlns'\nconst REF_ATTRIBUTE_NAME = 'ref'\n\nconst nsMap = {\n [XMLNS_ATTRIBUTE_NAME]: 'http://www.w3.org/2000/xmlns/',\n [XLINK_ATTRIBUTE_NAME]: 'http://www.w3.org/1999/xlink',\n svg: 'http://www.w3.org/2000/svg',\n}\n\n// If a JSX comment is written, it looks like: { /* this */ }\n// Therefore, it turns into: {}, which is detected here\nconst isJSXComment = (node: VNode): boolean =>\n /* v8 ignore next */\n node && typeof node === 'object' && !node.attributes && !node.type && !node.children\n\n// Filters comments and undefines like: ['a', 'b', false, {}] to: ['a', 'b', false]\nconst filterComments = (children: Array<VNode> | Array<VNodeChild>) =>\n children.filter((child: VNodeChild) => !isJSXComment(child as VNode))\n\nconst onUpdateFn = function (this: Ref, callback: Function) {\n this.update = callback as any\n}\n\nexport const jsx = (\n type: VNodeType | Function | any,\n attributes: (JSX.HTMLAttributes & JSX.SVGAttributes & Record<string, any>) | null,\n): Array<VNode> | VNode => {\n // extract children from attributes and ensure it's always an array\n const { children: rawChildren = [], ...restAttributes } = attributes || {};\n const childrenArray = Array.isArray(rawChildren) ? rawChildren : [rawChildren];\n\n const children = filterComments(\n ([] as Array<VNodeChildren>).concat(...childrenArray as any) as Array<VNodeChildren>,\n );\n\n // effectively unwrap by directly returning the children\n if (type === 'fragment') {\n return filterComments(children) as Array<VNode>;\n }\n\n // it's a component, divide and conquer children\n if (typeof type === 'function') {\n if (restAttributes.ref) {\n (restAttributes.ref as Ref)!.onUpdate = onUpdateFn.bind(restAttributes.ref as Ref) as any;\n }\n\n return type({\n children,\n ...restAttributes,\n });\n }\n\n return {\n type,\n attributes: restAttributes as any,\n children,\n };\n}\n\nexport const getRenderer = (document: Document): DomAbstractionImpl => {\n // DOM abstraction layer for manipulation\n const renderer = {\n hasElNamespace: (domElement: Element | Document): boolean => (domElement as Element).namespaceURI === nsMap.svg,\n\n hasSvgNamespace: (parentElement: Element | Document, type: string): boolean =>\n renderer.hasElNamespace(parentElement) && type !== 'STYLE' && type !== 'SCRIPT',\n\n createElementOrElements: (\n virtualNode: VNode | undefined | Array<VNode | undefined | string>,\n parentDomElement?: Element | Document,\n ): Array<Element | Text | undefined> | Element | Text | undefined => {\n if (Array.isArray(virtualNode)) {\n return renderer.createChildElements(virtualNode, parentDomElement)\n }\n if (typeof virtualNode !== 'undefined') {\n return renderer.createElement(virtualNode, parentDomElement)\n }\n // undefined virtualNode -> e.g. when a tsx variable is used in markup which is undefined\n return renderer.createTextNode('', parentDomElement)\n },\n\n createElement: (virtualNode: VNode, parentDomElement?: Element | Document): Element | undefined => {\n let newEl: Element\n\n if (\n virtualNode.type.toUpperCase() === 'SVG' ||\n (parentDomElement && renderer.hasSvgNamespace(parentDomElement, virtualNode.type.toUpperCase()))\n ) {\n newEl = document.createElementNS(nsMap.svg, virtualNode.type as string)\n } else {\n newEl = document.createElement(virtualNode.type as string)\n }\n\n if (virtualNode.attributes) {\n renderer.setAttributes(virtualNode.attributes, newEl as Element)\n\n // Apply dangerouslySetInnerHTML if provided\n if (virtualNode.attributes.dangerouslySetInnerHTML) {\n newEl.innerHTML = virtualNode.attributes.dangerouslySetInnerHTML.__html;\n }\n }\n\n if (virtualNode.children) {\n renderer.createChildElements(virtualNode.children, newEl as Element)\n }\n\n\n if (parentDomElement) {\n parentDomElement.appendChild(newEl)\n\n // check for a lifecycle \"onMount\" hook and call it\n if (typeof (newEl as any).$onMount === 'function') {\n ;(newEl as any).$onMount!()\n }\n }\n return newEl as Element\n },\n\n createTextNode: (text: string, domElement?: Element | Document): Text => {\n const node = document.createTextNode(text.toString())\n\n if (domElement) {\n domElement.appendChild(node)\n }\n return node\n },\n\n createChildElements: (\n virtualChildren: VNodeChildren,\n domElement?: Element | Document,\n ): Array<Element | Text | undefined> => {\n const children: Array<Element | Text | undefined> = []\n\n for (let i = 0; i < virtualChildren.length; i++) {\n const virtualChild = virtualChildren[i]\n if (virtualChild === null || (typeof virtualChild !== 'object' && typeof virtualChild !== 'function')) {\n children.push(\n renderer.createTextNode(\n (typeof virtualChild === 'undefined' || virtualChild === null ? '' : virtualChild!).toString(),\n domElement,\n ),\n )\n } else {\n children.push(renderer.createElement(virtualChild as VNode, domElement))\n }\n }\n return children\n },\n\n setAttribute: (name: string, value: any, domElement: Element) => {\n // attributes not set (undefined) are ignored; use null value to reset an attributes state\n if (typeof value === 'undefined') return\n if (name === 'children' || name === 'dangerouslySetInnerHTML') return;\n\n // save ref as { current: DOMElement } in ref object\n // allows for ref={someRef}\n if (name === REF_ATTRIBUTE_NAME && typeof value !== 'function') {\n value.current = domElement\n } else if (name === REF_ATTRIBUTE_NAME && typeof value === 'function') {\n // allow for functional ref's like: render(<div ref={(el) => console.log('got el', el)} />)\n value(domElement)\n }\n\n if (name.startsWith('on') && typeof value === 'function') {\n let eventName = name.substring(2).toLowerCase()\n const capturePos = eventName.indexOf('capture')\n const doCapture = capturePos > -1\n\n if (eventName === 'mount') {\n ;(domElement as any).$onMount = value\n }\n\n // onClickCapture={...} support\n if (doCapture) {\n eventName = eventName.substring(0, capturePos)\n }\n domElement.addEventListener(eventName, value, doCapture)\n return\n }\n\n // transforms className=\"...\" -> class=\"...\"\n // allows for React TSX to work seamlessly\n if (name === 'className') {\n name = CLASS_ATTRIBUTE_NAME\n }\n\n // transforms class={['a', 'b']} into class=\"a b\"\n if (name === CLASS_ATTRIBUTE_NAME && Array.isArray(value)) {\n value = value.join(' ')\n }\n\n const nsEndIndex = name.match(/[A-Z]/)?.index\n if (renderer.hasElNamespace(domElement) && nsEndIndex) {\n const ns = name.substring(0, nsEndIndex).toLowerCase()\n const attrName = name.substring(nsEndIndex, name.length).toLowerCase()\n const namespace = nsMap[ns as keyof typeof nsMap] || null\n domElement.setAttributeNS(\n namespace,\n ns === XLINK_ATTRIBUTE_NAME || ns === 'xmlns' ? `${ns}:${attrName}` : name,\n value,\n )\n } else if (name === 'style' && typeof value !== 'string') {\n const propNames = Object.keys(value)\n\n // allows for style={{ margin: 10 }} etc.\n for (let i = 0; i < propNames.length; i++) {\n ;(domElement as HTMLElement).style[propNames[i] as any] = value[propNames[i]]\n }\n } else if (typeof value === 'boolean') {\n // for cases like <button checked={false} />\n ;(domElement as any)[name] = value\n } else {\n // for any other case\n domElement.setAttribute(name, value)\n }\n },\n\n setAttributes: (attributes: VNodeAttributes, domElement: Element) => {\n const attrNames = Object.keys(attributes)\n for (let i = 0; i < attrNames.length; i++) {\n renderer.setAttribute(attrNames[i], attributes[attrNames[i]], domElement)\n }\n },\n }\n return renderer\n}\n\nexport const renderIsomorphic = (\n virtualNode: VNode | undefined | string | Array<VNode | undefined | string>,\n parentDomElement: Element | Document | Dequery | undefined,\n globals: Globals,\n): Array<Element | Text | undefined> | Element | Text | undefined => {\n\n const parentEl = (parentDomElement as Dequery).el as Element || parentDomElement\n\n if (typeof virtualNode === 'string') {\n return getRenderer(globals.window.document).createTextNode(virtualNode, parentEl)\n }\n return getRenderer(globals.window.document).createElementOrElements(virtualNode, parentEl)\n}\n\nexport const Fragment = (props: VNode) => props.children\nexport const jsxs = jsx\nexport const jsxDEV = jsx\n\nexport default {\n jsx,\n Fragment,\n renderIsomorphic,\n getRenderer,\n onUpdateFn,\n\n // implementing the full standard\n // https://github.com/reactjs/rfcs/blob/createlement-rfc/text/0000-create-element-changes.md\n jsxs,\n jsxDEV,\n};"],"names":[],"mappings":"AACA,MAAM,oBAAoB,GAAG,OAAO;AACpC,MAAM,o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AAO,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,uBAAuB,CAAC,WAAW,EAAE,QAAQ,CAAC;AAC5F;AACY,MAAC,QAAQ,GAAG,CAAC,KAAK,KAAK,KAAK,CAAC;AAC7B,MAAC,IAAI,GAAG;AACR,MAAC,MAAM,GAAG;;;;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/render/isomorph.ts"],"sourcesContent":["import type { Dequery } from '../dequery/types.js'\nimport type { VNodeChild, VNodeChildren, VNode, VNodeType, Ref, VNodeAttributes, DomAbstractionImpl, Globals, RefUpdateFn } from './types.js'\n\nconst CLASS_ATTRIBUTE_NAME = 'class'\nconst XLINK_ATTRIBUTE_NAME = 'xlink'\nconst XMLNS_ATTRIBUTE_NAME = 'xmlns'\nconst REF_ATTRIBUTE_NAME = 'ref'\n\nconst nsMap = {\n [XMLNS_ATTRIBUTE_NAME]: 'http://www.w3.org/2000/xmlns/',\n [XLINK_ATTRIBUTE_NAME]: 'http://www.w3.org/1999/xlink',\n svg: 'http://www.w3.org/2000/svg',\n}\n\n// If a JSX comment is written, it looks like: { /* this */ }\n// Therefore, it turns into: {}, which is detected here\nconst isJSXComment = (node: VNode): boolean =>\n /* v8 ignore next */\n node && typeof node === 'object' && !node.attributes && !node.type && !node.children\n\n// Filters comments and undefines like: ['a', 'b', false, {}] to: ['a', 'b', false]\nconst filterComments = (children: Array<VNode> | Array<VNodeChild>) =>\n children.filter((child: VNodeChild) => !isJSXComment(child as VNode))\n\nexport function createRef<T extends Node | Element | Text | null = null, D = unknown>(refUpdateFn?: RefUpdateFn<D>): Ref<T, D> {\n const ref: Ref<T, D> = { \n $subscriberFns: [],\n current: null as T,\n update: (state: D) => {\n ref.$subscriberFns.forEach(fn => fn(state));\n },\n subscribe: (refUpdateFn: RefUpdateFn<D>) => {\n ref.$subscriberFns.push(refUpdateFn);\n // unsubscribe function\n return () => {\n const index = ref.$subscriberFns.indexOf(refUpdateFn);\n if (index !== -1) {\n ref.$subscriberFns.splice(index, 1);\n }\n }\n },\n }\n\n if (typeof refUpdateFn === 'function') {\n ref.subscribe(refUpdateFn);\n }\n return ref;\n}\n\nexport const jsx = (\n type: VNodeType | Function | any,\n attributes: (JSX.HTMLAttributes & JSX.SVGAttributes & Record<string, any>) | null,\n): Array<VNode> | VNode => {\n\n // clone attributes as well\n attributes = { ...attributes }\n\n // extract children from attributes and ensure it's always an array\n let children: Array<VNodeChild> = (attributes?.children ? [].concat(attributes.children) : []).filter(Boolean);\n delete attributes?.children;\n\n children = filterComments(\n // Implementation to flatten virtual node children structures like:\n // [<p>1</p>, [<p>2</p>,<p>3</p>]] to: [<p>1</p>,<p>2</p>,<p>3</p>]\n ([] as Array<VNodeChildren>).concat.apply([], children as any) as Array<VNodeChildren>,\n )\n\n // effectively unwrap by directly returning the children\n if (type === 'fragment') {\n return filterComments(children) as Array<VNode>;\n }\n\n // it's a component, divide and conquer children\n if (typeof type === 'function') {\n return type({\n children,\n ...attributes,\n })\n }\n\n return {\n type,\n attributes,\n children,\n };\n}\n\nexport const getRenderer = (document: Document): DomAbstractionImpl => {\n // DOM abstraction layer for manipulation\n const renderer = {\n hasElNamespace: (domElement: Element | Document): boolean => (domElement as Element).namespaceURI === nsMap.svg,\n\n hasSvgNamespace: (parentElement: Element | Document, type: string): boolean =>\n renderer.hasElNamespace(parentElement) && type !== 'STYLE' && type !== 'SCRIPT',\n\n createElementOrElements: (\n virtualNode: VNode | undefined | Array<VNode | undefined | string>,\n parentDomElement?: Element | Document,\n ): Array<Element | Text | undefined> | Element | Text | undefined => {\n if (Array.isArray(virtualNode)) {\n return renderer.createChildElements(virtualNode, parentDomElement)\n }\n if (typeof virtualNode !== 'undefined') {\n return renderer.createElement(virtualNode, parentDomElement)\n }\n // undefined virtualNode -> e.g. when a tsx variable is used in markup which is undefined\n return renderer.createTextNode('', parentDomElement)\n },\n\n createElement: (virtualNode: VNode, parentDomElement?: Element | Document): Element | undefined => {\n let newEl: Element\n\n if (\n virtualNode.type.toUpperCase() === 'SVG' ||\n (parentDomElement && renderer.hasSvgNamespace(parentDomElement, virtualNode.type.toUpperCase()))\n ) {\n newEl = document.createElementNS(nsMap.svg, virtualNode.type as string)\n } else {\n newEl = document.createElement(virtualNode.type as string)\n }\n\n if (virtualNode.attributes) {\n renderer.setAttributes(virtualNode.attributes, newEl as Element)\n\n // Apply dangerouslySetInnerHTML if provided\n if (virtualNode.attributes.dangerouslySetInnerHTML) {\n newEl.innerHTML = virtualNode.attributes.dangerouslySetInnerHTML.__html;\n }\n }\n\n if (virtualNode.children) {\n renderer.createChildElements(virtualNode.children, newEl as Element)\n }\n\n\n if (parentDomElement) {\n parentDomElement.appendChild(newEl)\n\n // check for a lifecycle \"onMount\" hook and call it\n if (typeof (newEl as any).$onMount === 'function') {\n ;(newEl as any).$onMount!()\n }\n }\n return newEl as Element\n },\n\n createTextNode: (text: string, domElement?: Element | Document): Text => {\n const node = document.createTextNode(text.toString())\n\n if (domElement) {\n domElement.appendChild(node)\n }\n return node\n },\n\n createChildElements: (\n virtualChildren: VNodeChildren,\n domElement?: Element | Document,\n ): Array<Element | Text | undefined> => {\n const children: Array<Element | Text | undefined> = []\n\n for (let i = 0; i < virtualChildren.length; i++) {\n const virtualChild = virtualChildren[i]\n if (virtualChild === null || (typeof virtualChild !== 'object' && typeof virtualChild !== 'function')) {\n children.push(\n renderer.createTextNode(\n (typeof virtualChild === 'undefined' || virtualChild === null ? '' : virtualChild!).toString(),\n domElement,\n ),\n )\n } else {\n children.push(renderer.createElement(virtualChild as VNode, domElement))\n }\n }\n return children\n },\n\n setAttribute: (name: string, value: any, domElement: Element) => {\n // attributes not set (undefined) are ignored; use null value to reset an attributes state\n if (typeof value === 'undefined') return\n if (name === 'dangerouslySetInnerHTML') return;\n\n // save ref as { current: DOMElement } in ref object\n // allows for ref={someRef}\n if (name === REF_ATTRIBUTE_NAME && typeof value !== 'function') {\n value.current = domElement\n }/* else if (name === REF_ATTRIBUTE_NAME && typeof value === 'function') {\n // allow for functional ref's like: render(<div ref={(el) => console.log('got el', el)} />)\n value(domElement)\n }*/\n\n if (name.startsWith('on') && typeof value === 'function') {\n\n let eventName = name.substring(2).toLowerCase()\n const capturePos = eventName.indexOf('capture')\n const doCapture = capturePos > -1\n\n if (eventName === 'mount') {\n ;(domElement as any).$onMount = value // lifecycle hook\n }\n\n // onClickCapture={...} support\n if (doCapture) {\n eventName = eventName.substring(0, capturePos)\n\n // mark this event as a capture event to be registered correctly in hydration phase\n //domElement.setAttribute(`data-defuss-capture-${eventName}`, \"true\")\n }\n domElement.addEventListener(eventName, value, doCapture)\n return\n }\n\n // transforms className=\"...\" -> class=\"...\"\n // allows for React JSX to work seamlessly\n if (name === 'className') {\n name = CLASS_ATTRIBUTE_NAME\n }\n\n // transforms class={['a', 'b']} into class=\"a b\"\n if (name === CLASS_ATTRIBUTE_NAME && Array.isArray(value)) {\n value = value.join(' ')\n }\n\n const nsEndIndex = name.match(/[A-Z]/)?.index\n if (renderer.hasElNamespace(domElement) && nsEndIndex) {\n const ns = name.substring(0, nsEndIndex).toLowerCase()\n const attrName = name.substring(nsEndIndex, name.length).toLowerCase()\n const namespace = nsMap[ns as keyof typeof nsMap] || null\n domElement.setAttributeNS(\n namespace,\n ns === XLINK_ATTRIBUTE_NAME || ns === 'xmlns' ? `${ns}:${attrName}` : name,\n value,\n )\n } else if (name === 'style' && typeof value !== 'string') {\n const propNames = Object.keys(value)\n\n // allows for style={{ margin: 10 }} etc.\n for (let i = 0; i < propNames.length; i++) {\n ;(domElement as HTMLElement).style[propNames[i] as any] = value[propNames[i]]\n }\n } else if (typeof value === 'boolean') {\n // for cases like <button checked={false} />\n ;(domElement as any)[name] = value\n } else {\n // for any other case\n domElement.setAttribute(name, value)\n }\n },\n\n setAttributes: (attributes: VNodeAttributes, domElement: Element) => {\n const attrNames = Object.keys(attributes)\n for (let i = 0; i < attrNames.length; i++) {\n renderer.setAttribute(attrNames[i], attributes[attrNames[i]], domElement)\n }\n },\n }\n return renderer\n}\n\nexport const renderIsomorphic = (\n virtualNode: VNode | undefined | string | Array<VNode | undefined | string>,\n parentDomElement: Element | Document | Dequery | undefined,\n globals: Globals,\n): Array<Element | Text | undefined> | Element | Text | undefined => {\n\n const parentEl = (parentDomElement as Dequery).el as Element || parentDomElement\n\n if (typeof virtualNode === 'string') {\n return getRenderer(globals.window.document).createTextNode(virtualNode, parentEl)\n }\n return getRenderer(globals.window.document).createElementOrElements(virtualNode, parentEl)\n}\n\n// --- JSX standard (necessary exports for jsx-runtime)\nexport const Fragment = (props: VNode) => props.children\nexport const jsxs = jsx\nexport const jsxDEV = jsx\n\nexport default {\n jsx,\n Fragment,\n renderIsomorphic,\n getRenderer,\n\n // implementing the full standard\n // https://github.com/reactjs/rfcs/blob/createlement-rfc/text/0000-create-element-changes.md\n jsxs,\n jsxDEV,\n};"],"names":[],"mappings":"AACA,MAAM,oBAAoB,GAAG,OAAO;AACpC,MAAM,oBAAoB,GAAG,OAAO;AACpC,MAAM,oBAAoB,GAAG,OAAO;AACpC,MAAM,kBAAkB,GAAG,KAAK;AAChC,MAAM,KAAK,GAAG;AACd,EAAE,CAAC,oBAAoB,GAAG,+BAA+B;AACzD,EAAE,CAAC,oBAAoB,GAAG,8BAA8B;AACxD,EAAE,GAAG,EAAE;AACP,CAAC;AACD,MAAM,YAAY,GAAG,CAAC,IAAI;AAC1B;AACA,EAAE,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC;AAC9E,CAAC;AACD,MAAM,cAAc,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC,MAAM,CAAC,CAAC,KAAK,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;AAC9E,SAAS,SAAS,CAAC,WAAW,EAAE;AACvC,EAAE,MAAM,GAAG,GAAG;AACd,IAAI,cAAc,EAAE,EAAE;AACtB,IAAI,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"}
|
package/dist/render/server.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var i=Object.defineProperty;var s=(e,r)=>i(e,"name",{value:r,configurable:!0});var g=require("linkedom"),
|
|
1
|
+
"use strict";var i=Object.defineProperty;var s=(e,r)=>i(e,"name",{value:r,configurable:!0});var g=require("linkedom"),t=require("./index.cjs");const m=s((e,r,o={})=>{const a=o.browserGlobals?o.browserGlobals:c(),d=l(o.createRoot,a);return r||(r=n(d)),t.renderIsomorphic(e,r,a)},"render"),n=s(e=>{const r=e.createElement("html");return e.appendChild(r),e.documentElement},"createRoot"),c=s(e=>g.parseHTML(e||""),"getBrowserGlobals"),l=s((e=!1,r)=>{const o=(r||c()).document;return e&&n(o),o},"getDocument"),u=s(e=>e.toString(),"renderToString");exports.Fragment=t.Fragment,exports.createRef=t.createRef,exports.getRenderer=t.getRenderer,exports.jsx=t.jsx,exports.jsxDEV=t.jsxDEV,exports.jsxs=t.jsxs,exports.renderIsomorphic=t.renderIsomorphic,exports.createRoot=n,exports.getBrowserGlobals=c,exports.getDocument=l,exports.render=m,exports.renderToString=u;
|
|
2
2
|
//# sourceMappingURL=server.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.cjs","sources":["../../src/render/server.ts"],"sourcesContent":["import { parseHTML } from 'linkedom'\nimport { renderIsomorphic } from './isomorph.js'\nimport type { RenderInput, RenderResult, Globals } from './types.js'\nimport type { Dequery } from '../dequery/types.js'\n\nexport interface RenderOptions {\n /** choose an arbitrary server-side DOM / Document implementation; this library defaults to 'linkedom'; default: undefined */\n browserGlobals?: Globals\n\n /** creates a synthetic <html> root element in case you want to render in isolation; default: false; also happens when parentDomElement isn't present */\n createRoot?: boolean\n}\n\nexport const render = <T extends RenderInput>(\n virtualNode: T,\n parentDomElement?: Element | Dequery,\n options: RenderOptions = {},\n): RenderResult<T> => {\n const browserGlobals = options.browserGlobals ? options.browserGlobals : getBrowserGlobals()\n const document = getDocument(options.createRoot, browserGlobals)\n\n if (!parentDomElement) {\n parentDomElement = createRoot(document)\n }\n return renderIsomorphic(virtualNode, parentDomElement, browserGlobals) as any\n}\n\nexport const createRoot = (document: Document): Element => {\n const htmlElement = document.createElement('html')\n document.appendChild(htmlElement)\n return document.documentElement\n}\n\nexport const getBrowserGlobals = (initialHtml?: string): Globals => parseHTML(initialHtml || '')\n\nexport const getDocument = (shouldCreateRoot = false, browserGlobals?: Globals): Document => {\n const document = (browserGlobals || getBrowserGlobals()).document\n if (shouldCreateRoot) {\n createRoot(document)\n return document\n }\n return document\n}\n\nexport const renderToString = (el: Node) => el.toString()\n\nexport * from './index.js'\n"],"names":["renderIsomorphic","parseHTML"],"mappings":";;;;;AAGY,MAAC,MAAM,GAAG,CAAC,WAAW,EAAE,gBAAgB,EAAE,OAAO,GAAG,EAAE,KAAK;AACvE,EAAE,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,GAAG,iBAAiB,EAAE;AAC9F,EAAE,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,UAAU,EAAE,cAAc,CAAC;AAClE,EAAE,IAAI,CAAC,gBAAgB,EAAE;AACzB,IAAI,gBAAgB,GAAG,UAAU,CAAC,QAAQ,CAAC;AAC3C;AACA,EAAE,OAAOA,sBAAgB,CAAC,WAAW,EAAE,gBAAgB,EAAE,cAAc,CAAC;AACxE;AACY,MAAC,UAAU,GAAG,CAAC,QAAQ,KAAK;AACxC,EAAE,MAAM,WAAW,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC;AACpD,EAAE,QAAQ,CAAC,WAAW,CAAC,WAAW,CAAC;AACnC,EAAE,OAAO,QAAQ,CAAC,eAAe;AACjC;AACY,MAAC,iBAAiB,GAAG,CAAC,WAAW,KAAKC,kBAAS,CAAC,WAAW,IAAI,EAAE;AACjE,MAAC,WAAW,GAAG,CAAC,gBAAgB,GAAG,KAAK,EAAE,cAAc,KAAK;AACzE,EAAE,MAAM,QAAQ,GAAG,CAAC,cAAc,IAAI,iBAAiB,EAAE,EAAE,QAAQ;AACnE,EAAE,IAAI,gBAAgB,EAAE;AACxB,IAAI,UAAU,CAAC,QAAQ,CAAC;AACxB,IAAI,OAAO,QAAQ;AACnB;AACA,EAAE,OAAO,QAAQ;AACjB;AACY,MAAC,cAAc,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,QAAQ
|
|
1
|
+
{"version":3,"file":"server.cjs","sources":["../../src/render/server.ts"],"sourcesContent":["import { parseHTML } from 'linkedom'\nimport { renderIsomorphic } from './isomorph.js'\nimport type { RenderInput, RenderResult, Globals } from './types.js'\nimport type { Dequery } from '../dequery/types.js'\n\nexport interface RenderOptions {\n /** choose an arbitrary server-side DOM / Document implementation; this library defaults to 'linkedom'; default: undefined */\n browserGlobals?: Globals\n\n /** creates a synthetic <html> root element in case you want to render in isolation; default: false; also happens when parentDomElement isn't present */\n createRoot?: boolean\n}\n\nexport const render = <T extends RenderInput>(\n virtualNode: T,\n parentDomElement?: Element | Dequery,\n options: RenderOptions = {},\n): RenderResult<T> => {\n const browserGlobals = options.browserGlobals ? options.browserGlobals : getBrowserGlobals()\n const document = getDocument(options.createRoot, browserGlobals)\n\n if (!parentDomElement) {\n parentDomElement = createRoot(document)\n }\n return renderIsomorphic(virtualNode, parentDomElement, browserGlobals) as any\n}\n\nexport const createRoot = (document: Document): Element => {\n const htmlElement = document.createElement('html')\n document.appendChild(htmlElement)\n return document.documentElement\n}\n\nexport const getBrowserGlobals = (initialHtml?: string): Globals => parseHTML(initialHtml || '')\n\nexport const getDocument = (shouldCreateRoot = false, browserGlobals?: Globals): Document => {\n const document = (browserGlobals || getBrowserGlobals()).document\n if (shouldCreateRoot) {\n createRoot(document)\n return document\n }\n return document\n}\n\nexport const renderToString = (el: Node) => el.toString()\n\nexport * from './index.js'\n"],"names":["renderIsomorphic","parseHTML"],"mappings":";;;;;AAGY,MAAC,MAAM,GAAG,CAAC,WAAW,EAAE,gBAAgB,EAAE,OAAO,GAAG,EAAE,KAAK;AACvE,EAAE,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,GAAG,iBAAiB,EAAE;AAC9F,EAAE,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,UAAU,EAAE,cAAc,CAAC;AAClE,EAAE,IAAI,CAAC,gBAAgB,EAAE;AACzB,IAAI,gBAAgB,GAAG,UAAU,CAAC,QAAQ,CAAC;AAC3C;AACA,EAAE,OAAOA,sBAAgB,CAAC,WAAW,EAAE,gBAAgB,EAAE,cAAc,CAAC;AACxE;AACY,MAAC,UAAU,GAAG,CAAC,QAAQ,KAAK;AACxC,EAAE,MAAM,WAAW,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC;AACpD,EAAE,QAAQ,CAAC,WAAW,CAAC,WAAW,CAAC;AACnC,EAAE,OAAO,QAAQ,CAAC,eAAe;AACjC;AACY,MAAC,iBAAiB,GAAG,CAAC,WAAW,KAAKC,kBAAS,CAAC,WAAW,IAAI,EAAE;AACjE,MAAC,WAAW,GAAG,CAAC,gBAAgB,GAAG,KAAK,EAAE,cAAc,KAAK;AACzE,EAAE,MAAM,QAAQ,GAAG,CAAC,cAAc,IAAI,iBAAiB,EAAE,EAAE,QAAQ;AACnE,EAAE,IAAI,gBAAgB,EAAE;AACxB,IAAI,UAAU,CAAC,QAAQ,CAAC;AACxB,IAAI,OAAO,QAAQ;AACnB;AACA,EAAE,OAAO,QAAQ;AACjB;AACY,MAAC,cAAc,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,QAAQ;;;;;;;;;;;;;;;"}
|
package/dist/render/server.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { G as Globals, R as RenderInput, D as Dequery, a as RenderResult } from '../index-
|
|
2
|
-
export { C as CSSProperties, m as Children, n as DomAbstractionImpl, F as FontFaceProperties,
|
|
1
|
+
import { G as Globals, R as RenderInput, D as Dequery, a as RenderResult } from '../index-Csvo7Gd8.js';
|
|
2
|
+
export { C as CSSProperties, m as Children, n as DomAbstractionImpl, F as FontFaceProperties, u as Fragment, K as KeyFrameProperties, P as Props, c as Ref, b as RefUpdateFn, o as RenderNodeInput, p as RenderResultNode, V as VAttributes, e as VNode, d as VNodeAttributes, k as VNodeChild, l as VNodeChildren, g as VNodeKey, j as VNodeRef, i as VNodeRefCallback, h as VNodeRefObject, f as VNodeType, q as createRef, s as getRenderer, r as jsx, w as jsxDEV, v as jsxs, t as renderIsomorphic } from '../index-Csvo7Gd8.js';
|
|
3
3
|
import * as CSS from 'csstype';
|
|
4
4
|
export { CSS };
|
|
5
5
|
|
package/dist/render/server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { G as Globals, R as RenderInput, D as Dequery, a as RenderResult } from '../index-
|
|
2
|
-
export { C as CSSProperties, m as Children, n as DomAbstractionImpl, F as FontFaceProperties,
|
|
1
|
+
import { G as Globals, R as RenderInput, D as Dequery, a as RenderResult } from '../index-Csvo7Gd8.js';
|
|
2
|
+
export { C as CSSProperties, m as Children, n as DomAbstractionImpl, F as FontFaceProperties, u as Fragment, K as KeyFrameProperties, P as Props, c as Ref, b as RefUpdateFn, o as RenderNodeInput, p as RenderResultNode, V as VAttributes, e as VNode, d as VNodeAttributes, k as VNodeChild, l as VNodeChildren, g as VNodeKey, j as VNodeRef, i as VNodeRefCallback, h as VNodeRefObject, f as VNodeType, q as createRef, s as getRenderer, r as jsx, w as jsxDEV, v as jsxs, t as renderIsomorphic } from '../index-Csvo7Gd8.js';
|
|
3
3
|
import * as CSS from 'csstype';
|
|
4
4
|
export { CSS };
|
|
5
5
|
|
package/dist/render/server.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var d=Object.defineProperty;var o=(r
|
|
1
|
+
var d=Object.defineProperty;var o=(e,r)=>d(e,"name",{value:r,configurable:!0});import{parseHTML as b}from"linkedom";import{renderIsomorphic as l}from"./index.mjs";import{Fragment as w,createRef as G,getRenderer as R,jsx as j,jsxDEV as E,jsxs as S}from"./index.mjs";const f=o((e,r,t={})=>{const c=t.browserGlobals?t.browserGlobals:n(),a=m(t.createRoot,c);return r||(r=s(a)),l(e,r,c)},"render"),s=o(e=>{const r=e.createElement("html");return e.appendChild(r),e.documentElement},"createRoot"),n=o(e=>b(e||""),"getBrowserGlobals"),m=o((e=!1,r)=>{const t=(r||n()).document;return e&&s(t),t},"getDocument"),u=o(e=>e.toString(),"renderToString");export{w as Fragment,G as createRef,s as createRoot,n as getBrowserGlobals,m as getDocument,R as getRenderer,j as jsx,E as jsxDEV,S as jsxs,f as render,l as renderIsomorphic,u as renderToString};
|
|
2
2
|
//# sourceMappingURL=server.mjs.map
|