bruh 1.9.1 → 1.9.2-types.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/README.md CHANGED
@@ -44,3 +44,5 @@ developers who know what they are doing - a group which you might fit into.
44
44
  # Where is the documentation?
45
45
 
46
46
  [Right here](https://technicalsource.dev/bruh)
47
+
48
+ https://codesandbox.io/s/github/Technical-Source/bruh/tree/main/packages/create-bruh/vite
package/dist/bruh.es.js CHANGED
@@ -257,6 +257,7 @@ var index = /* @__PURE__ */ Object.freeze({
257
257
  });
258
258
  const isReactive = Symbol.for("bruh reactive");
259
259
  const isMetaNode = Symbol.for("bruh meta node");
260
+ const isMetaTextNode = Symbol.for("bruh meta text node");
260
261
  const isMetaElement = Symbol.for("bruh meta element");
261
262
  const isMetaNodeChild = (x) => (x == null ? void 0 : x[isMetaNode]) || (x == null ? void 0 : x[isReactive]) || x instanceof Node || Array.isArray(x) || x == null || !(typeof x === "function" || typeof x === "object");
262
263
  const toNode = (x) => {
@@ -303,7 +304,7 @@ class MetaTextNode {
303
304
  return this;
304
305
  }
305
306
  }
306
- _c = isMetaNode, _d = isMetaElement;
307
+ _c = isMetaNode, _d = isMetaTextNode;
307
308
  class MetaElement {
308
309
  constructor(name, namespace) {
309
310
  __publicField(this, _e, true);
@@ -1 +1 @@
1
- {"version":3,"file":"bruh.es.js","sources":["../src/dom/live-fragment.mjs","../src/reactive/index.mjs","../src/util/index.mjs","../src/dom/index.browser.mjs"],"sourcesContent":["// Lightweight and performant DOM fragment that keeps its place,\n// useful for grouping siblings without making a parent element.\n// Not a true analog of the DocumentFragment, because the implementation\n// would be infeasible with that scope, adding a performance penalty as well.\n// Works as long as the start & end placeholders are siblings in that order\n// and they do not overlap other LiveFragment's:\n// Works: (start A)(start B)(end B)(end A)\n// Fails: (start A)(start B)(end A)(end B)\n// Also, make sure not to call .normalize() on the parent element,\n// because that would ruin the placeholders.\nexport class LiveFragment {\n startMarker = document.createTextNode(\"\")\n endMarker = document.createTextNode(\"\")\n\n static from(firstNode, lastNode) {\n const liveFragment = new this()\n firstNode.before(liveFragment.startMarker)\n lastNode.after(liveFragment.endMarker)\n return liveFragment\n }\n\n before(...xs) {\n this.startMarker.before(...xs)\n }\n\n prepend(...xs) {\n this.startMarker.after(...xs)\n }\n\n append(...xs) {\n this.endMarker.before(...xs)\n }\n\n after(...xs) {\n this.endMarker.after(...xs)\n }\n\n remove() {\n const range = document.createRange()\n range.setStartBefore(this.startMarker)\n range.setEndAfter(this.endMarker)\n range.deleteContents()\n }\n\n replaceChildren(...xs) {\n const range = document.createRange()\n range.setStartAfter(this.startMarker)\n range.setEndBefore(this.endMarker)\n range.deleteContents()\n this.startMarker.after(...xs)\n }\n\n replaceWith(...xs) {\n this.endMarker.after(...xs)\n this.remove()\n }\n\n get childNodes() {\n const childNodes = []\n\n for (\n let currentNode = this.startMarker.nextSibling;\n currentNode != this.endMarker && currentNode;\n currentNode = currentNode.nextSibling\n )\n childNodes.push(currentNode)\n\n return childNodes\n }\n\n get children() {\n return this.childNodes\n .filter(node => node instanceof HTMLElement)\n }\n}\n","const isReactive = Symbol.for(\"bruh reactive\")\n\n// A super simple and performant reactive value implementation\nexport class SimpleReactive {\n [isReactive] = true\n\n #value\n #reactions = new Set()\n\n constructor(value) {\n this.#value = value\n }\n\n get value() {\n return this.#value\n }\n\n set value(newValue) {\n if (newValue === this.#value)\n return\n\n this.#value = newValue\n for (const reaction of this.#reactions)\n reaction()\n }\n\n addReaction(reaction) {\n this.#reactions.add(reaction)\n\n return () =>\n this.#reactions.delete(reaction)\n }\n}\n\n// A reactive implementation for building functional reactive graphs\n// Ensures state consistency, minimal node updates, and transparent update batching\nexport class FunctionalReactive {\n [isReactive] = true\n\n #value\n #reactions = new Set()\n\n // For derived nodes, f is the derivation function\n #f\n // Source nodes are 0 deep in the derivation graph\n // This is for topological sort\n #depth = 0\n // All nodes have a set of derivatives that update when the node changes\n #derivatives = new Set()\n\n // Keep track of all the pending changes from the value setter\n static #settersQueue = new Map()\n // A queue of derivatives to potentially update, sorted into sets by depth\n // This starts with depth 1 and can potentially have holes\n static #derivativesQueue = []\n // A queue of reactions to run after the graph is fully updated\n static #reactionsQueue = []\n\n constructor(x, f) {\n if (!f) {\n this.#value = x\n return\n }\n\n this.#value = f()\n this.#f = f\n this.#depth = Math.max(...x.map(d => d.#depth)) + 1\n\n x.forEach(d => d.#derivatives.add(this))\n }\n\n get value() {\n // If there are any pending updates, go ahead and apply them first\n // It's ok that there's already a microtask queued for this\n if (FunctionalReactive.#settersQueue.size)\n FunctionalReactive.applyUpdates()\n\n return this.#value\n }\n\n set value(newValue) {\n // Only allow souce nodes to be directly updated\n if (this.#depth !== 0)\n return\n\n // Unless asked for earlier, these updates are just queued up until the microtasks run\n if (!FunctionalReactive.#settersQueue.size)\n queueMicrotask(FunctionalReactive.applyUpdates)\n\n FunctionalReactive.#settersQueue.set(this, newValue)\n }\n\n addReaction(reaction) {\n this.#reactions.add(reaction)\n\n return () =>\n this.#reactions.delete(reaction)\n }\n\n // Apply an update for a node and queue its derivatives if it actually changed\n #applyUpdate(newValue) {\n if (newValue === this.#value)\n return\n\n this.#value = newValue\n FunctionalReactive.#reactionsQueue.push(...this.#reactions)\n\n const queue = FunctionalReactive.#derivativesQueue\n for (const derivative of this.#derivatives) {\n const depth = derivative.#depth\n if (!queue[depth])\n queue[depth] = new Set()\n\n queue[depth].add(derivative)\n }\n }\n\n // Apply pending updates from actually changed source nodes\n static applyUpdates() {\n if (!FunctionalReactive.#settersQueue.size)\n return\n\n // Bootstrap by applying the updates from the pending setters\n for (const [sourceNode, newValue] of FunctionalReactive.#settersQueue.entries())\n sourceNode.#applyUpdate(newValue)\n FunctionalReactive.#settersQueue.clear()\n\n // Iterate down the depths, ignoring holes\n // Note that both the queue (Array) and each depth Set iterators update as items are added\n for (const depthSet of FunctionalReactive.#derivativesQueue) if (depthSet)\n for (const derivative of depthSet)\n derivative.#applyUpdate(derivative.#f())\n FunctionalReactive.#derivativesQueue.length = 0\n\n // Call all reactions now that the graph has a fully consistent state\n for (const reaction of FunctionalReactive.#reactionsQueue)\n reaction()\n FunctionalReactive.#reactionsQueue.length = 0\n }\n}\n\n// A little convenience function\nexport const r = (x, f) => new FunctionalReactive(x, f)\n\n// Do something with a value, updating if it is reactive\nexport const reactiveDo = (x, f) => {\n if (x?.[isReactive]) {\n f(x.value)\n return x.addReaction(() => f(x.value))\n }\n\n f(x)\n}\n","// Create a pipeline with an initial value and a series of functions\nexport const pipe = (x, ...fs) =>\n fs.reduce((y, f) => f(y), x)\n\n// Dispatch a custom event to (capturing) and from (bubbling) a target (usually a DOM node)\n// Returns false if the event was cancelled (preventDefault()) and true otherwise\nexport const dispatch = (target, type, options) =>\n target.dispatchEvent(\n // Default to behave like most DOM events\n new CustomEvent(type, {\n bubbles: true,\n cancelable: true,\n composed: true,\n ...options\n })\n )\n\n// Inspired by https://antfu.me/posts/destructuring-with-object-or-array#take-away\n// Creates an object that is both destructable with {...} and [...]\n// Useful for writing library functions à la react-use & vueuse\nexport const createDestructable = (object, iterable) => {\n const destructable = {\n ...object,\n [Symbol.iterator]: () => iterable[Symbol.iterator]()\n }\n\n Object.defineProperty(destructable, Symbol.iterator, {\n enumerable: false\n })\n\n return destructable\n}\n\n// A function that acts like Maybe.from(x).ifExists(existsThen).ifEmpty(emptyThen)\n// Except we just use an array in place of a true Maybe type\n// This is useful for setting and removing reactive attributes\nexport const maybeDo = (existsThen, emptyThen) => x => {\n if (Array.isArray(x)) {\n if (x.length)\n existsThen(x[0])\n else\n emptyThen()\n }\n else\n existsThen(x)\n}\n\n// Creates an object (as a Proxy) that acts as a function\n// So functionAsObject(f).property is equivalent to f(\"property\")\n// This is can be useful when combined with destructuring syntax, e.g.:\n// const { html, head, title, body, main, h1, p } = functionAsObject(e)\nexport const functionAsObject = f =>\n new Proxy({}, {\n get: (_, property) => f(property)\n })\n","import { LiveFragment } from \"./live-fragment.mjs\"\nimport { reactiveDo } from \"../reactive/index.mjs\"\nimport { maybeDo } from \"../util/index.mjs\"\n\nconst isReactive = Symbol.for(\"bruh reactive\")\nconst isMetaNode = Symbol.for(\"bruh meta node\")\nconst isMetaTextNode = Symbol.for(\"bruh meta text node\")\nconst isMetaElement = Symbol.for(\"bruh meta element\")\n\n// A basic check for if a value is allowed as a meta node's child\n// It's responsible for quickly checking the type, not deep validation\nconst isMetaNodeChild = x =>\n // meta nodes, reactives, and DOM nodes\n x?.[isMetaNode] ||\n x?.[isReactive] ||\n x instanceof Node ||\n // Any array, just assume it contains valid children\n Array.isArray(x) ||\n // Allow nullish\n x == null ||\n // Disallow functions and objects\n !(typeof x === \"function\" || typeof x === \"object\")\n // Everything else can be a child when stringified\n\nconst toNode = x => {\n if (x[isMetaNode])\n return x.node\n\n if (x instanceof Node)\n return x\n\n return document.createTextNode(x)\n}\n\nexport const childrenToNodes = children =>\n children\n .flat(Infinity)\n .flatMap(child => {\n if (!child[isReactive])\n return [toNode(child)]\n\n if (Array.isArray(child.value)) {\n const liveFragment = new LiveFragment()\n child.addReaction(() => {\n liveFragment.replaceChildren(...childrenToNodes(child.value))\n })\n return [liveFragment.startMarker, ...childrenToNodes(child.value), liveFragment.endMarker]\n }\n\n let node = toNode(child.value)\n child.addReaction(() => {\n const oldNode = node\n node = toNode(child.value)\n oldNode.replaceWith(node)\n })\n return [node]\n })\n\n\n\n// Meta Nodes\n\nexport class MetaTextNode {\n [isMetaNode] = true;\n [isMetaElement] = true\n\n node\n\n constructor(textContent) {\n if (!textContent[isReactive]) {\n this.node = document.createTextNode(textContent)\n return\n }\n\n this.node = document.createTextNode(textContent.value)\n textContent.addReaction(() => {\n this.node.textContent = textContent.value\n })\n }\n\n addProperties(properties = {}) {\n Object.assign(this.node, properties)\n\n return this\n }\n}\n\nexport class MetaElement {\n [isMetaNode] = true;\n [isMetaElement] = true\n\n node\n\n constructor(name, namespace) {\n this.node =\n namespace\n ? document.createElementNS(namespace, name)\n : document.createElement ( name)\n }\n\n static from(element) {\n const result = new this(\"div\")\n result.node = element\n return result\n }\n\n addProperties(properties = {}) {\n Object.assign(this.node, properties)\n\n return this\n }\n\n addAttributes(attributes = {}) {\n for (const name in attributes)\n reactiveDo(attributes[name],\n maybeDo(\n value => this.node.setAttribute (name, value),\n () => this.node.removeAttribute(name)\n )\n )\n\n return this\n }\n\n addDataAttributes(dataAttributes = {}) {\n for (const name in dataAttributes)\n reactiveDo(dataAttributes[name],\n maybeDo(\n value => this.node.dataset[name] = value,\n () => delete this.node.dataset[name]\n )\n )\n\n return this\n }\n\n addStyles(styles = {}) {\n for (const property in styles)\n reactiveDo(styles[property],\n maybeDo(\n value => this.node.style.setProperty (property, value),\n () => this.node.style.removeProperty(property)\n )\n )\n\n return this\n }\n\n toggleClasses(classes = {}) {\n for (const name in classes)\n reactiveDo(classes[name],\n value => this.node.classList.toggle(name, value)\n )\n\n return this\n }\n\n before(...xs) {\n this.node.before(...childrenToNodes(xs))\n }\n\n prepend(...xs) {\n this.node.prepend(...childrenToNodes(xs))\n }\n\n append(...xs) {\n this.node.append(...childrenToNodes(xs))\n }\n\n after(...xs) {\n this.node.after(...childrenToNodes(xs))\n }\n\n replaceChildren(...xs) {\n this.node.replaceChildren(...childrenToNodes(xs))\n }\n\n replaceWith(...xs) {\n this.node.replaceWith(...childrenToNodes(xs))\n }\n}\n\n\n\n// Convenience functions\n\nexport const hydrateTextNodes = () => {\n const tagged = {}\n const bruhTextNodes = document.getElementsByTagName(\"bruh-textnode\")\n\n for (const bruhTextNode of bruhTextNodes) {\n const textNode = document.createTextNode(bruhTextNode.textContent)\n\n if (bruhTextNode.dataset.tag)\n tagged[bruhTextNode.dataset.tag] = textNode\n\n bruhTextNode.replaceWith(textNode)\n }\n\n return tagged\n}\n\nconst createMetaTextNode = textContent =>\n new MetaTextNode(textContent)\n\nconst createMetaElement = (name, namespace) => (...variadic) => {\n const meta = new MetaElement(name, namespace)\n\n // Implement optional attributes as first argument\n if (!isMetaNodeChild(variadic[0])) {\n const [attributes, ...children] = variadic\n meta.addAttributes(attributes)\n meta.append(children)\n }\n else {\n meta.append(variadic)\n }\n\n return meta\n}\n\n// JSX integration\nconst createMetaElementJSX = (nameOrComponent, attributesOrProps, ...children) => {\n // If we are making a html element\n // This is likely when the jsx tag name begins with a lowercase character\n if (typeof nameOrComponent == \"string\") {\n const meta = new MetaElement(nameOrComponent)\n\n // These are attributes then, but they might be null/undefined\n meta.addAttributes(attributesOrProps || {})\n meta.append(children)\n\n return meta\n }\n\n // It must be a component, then\n // Bruh components are just functions that return meta elements\n // Due to JSX, this would mean a function with only one parameter - a \"props\" object\n // This object includes the all of the attributes and a \"children\" key\n return nameOrComponent( Object.assign({}, attributesOrProps, { children }) )\n}\n\n// These will be called with short names\nexport {\n createMetaTextNode as t,\n createMetaElement as e,\n createMetaElementJSX as h\n}\n\n// The JSX fragment is made into a bruh fragment (just an array)\nexport const JSXFragment = ({ children }) => children\n"],"names":["isReactive"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAUO,mBAAmB;AAAA,EAAnB,cAVP;AAWE,uCAAc,SAAS,eAAe;AACtC,qCAAc,SAAS,eAAe;AAAA;AAAA,SAE/B,KAAK,WAAW,UAAU;AAC/B,UAAM,gBAAe,IAAI;AACzB,cAAU,OAAO,cAAa;AAC9B,aAAS,MAAM,cAAa;AAC5B,WAAO;AAAA;AAAA,EAGT,UAAU,IAAI;AACZ,SAAK,YAAY,OAAO,GAAG;AAAA;AAAA,EAG7B,WAAW,IAAI;AACb,SAAK,YAAY,MAAM,GAAG;AAAA;AAAA,EAG5B,UAAU,IAAI;AACZ,SAAK,UAAU,OAAO,GAAG;AAAA;AAAA,EAG3B,SAAS,IAAI;AACX,SAAK,UAAU,MAAM,GAAG;AAAA;AAAA,EAG1B,SAAS;AACP,UAAM,QAAQ,SAAS;AACvB,UAAM,eAAe,KAAK;AAC1B,UAAM,YAAY,KAAK;AACvB,UAAM;AAAA;AAAA,EAGR,mBAAmB,I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,QAAM,OAAO,IAAI,YAAY,MAAM;AAGnC,MAAI,CAAC,gBAAgB,SAAS,KAAK;AACjC,UAAM,CAAC,eAAe,YAAY;AAClC,SAAK,cAAc;AACnB,SAAK,OAAO;AAAA,SAET;AACH,SAAK,OAAO;AAAA;AAGd,SAAO;AAAA;AAIT,MAAM,uBAAuB,CAAC,iBAAiB,sBAAsB,aAAa;AAGhF,MAAI,OAAO,mBAAmB,UAAU;AACtC,UAAM,OAAO,IAAI,YAAY;AAG7B,SAAK,cAAc,qBAAqB;AACxC,SAAK,OAAO;AAEZ,WAAO;AAAA;AAOT,SAAO,gBAAiB,OAAO,OAAO,IAAI,mBAAmB,EAAE;AAAA;AAW1D,MAAM,cAAc,CAAC,EAAE,eAAe;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"bruh.es.js","sources":["../src/dom/live-fragment.mjs","../src/reactive/index.mjs","../src/util/index.mjs","../src/dom/index.browser.mjs"],"sourcesContent":["// Lightweight and performant DOM fragment that keeps its place,\n// useful for grouping siblings without making a parent element.\n// Not a true analog of the DocumentFragment, because the implementation\n// would be infeasible with that scope, adding a performance penalty as well.\n// Works as long as the start & end placeholders are siblings in that order\n// and they do not overlap other LiveFragment's:\n// Works: (start A)(start B)(end B)(end A)\n// Fails: (start A)(start B)(end A)(end B)\n// Also, make sure not to call .normalize() on the parent element,\n// because that would ruin the placeholders.\nexport class LiveFragment {\n startMarker = document.createTextNode(\"\")\n endMarker = document.createTextNode(\"\")\n\n static from(firstNode, lastNode) {\n const liveFragment = new this()\n firstNode.before(liveFragment.startMarker)\n lastNode.after(liveFragment.endMarker)\n return liveFragment\n }\n\n before(...xs) {\n this.startMarker.before(...xs)\n }\n\n prepend(...xs) {\n this.startMarker.after(...xs)\n }\n\n append(...xs) {\n this.endMarker.before(...xs)\n }\n\n after(...xs) {\n this.endMarker.after(...xs)\n }\n\n remove() {\n const range = document.createRange()\n range.setStartBefore(this.startMarker)\n range.setEndAfter(this.endMarker)\n range.deleteContents()\n }\n\n replaceChildren(...xs) {\n const range = document.createRange()\n range.setStartAfter(this.startMarker)\n range.setEndBefore(this.endMarker)\n range.deleteContents()\n this.startMarker.after(...xs)\n }\n\n replaceWith(...xs) {\n this.endMarker.after(...xs)\n this.remove()\n }\n\n get childNodes() {\n const childNodes = []\n\n for (\n let currentNode = this.startMarker.nextSibling;\n currentNode != this.endMarker && currentNode;\n currentNode = currentNode.nextSibling\n )\n childNodes.push(currentNode)\n\n return childNodes\n }\n\n get children() {\n return this.childNodes\n .filter(node => node instanceof HTMLElement)\n }\n}\n","/** @typedef { import(\"./index\") } */\n\nconst isReactive = Symbol.for(\"bruh reactive\")\n\n// A super simple and performant reactive value implementation\nexport class SimpleReactive {\n [isReactive] = true\n\n #value\n #reactions = new Set()\n\n constructor(value) {\n this.#value = value\n }\n\n get value() {\n return this.#value\n }\n\n set value(newValue) {\n if (newValue === this.#value)\n return\n\n this.#value = newValue\n for (const reaction of this.#reactions)\n reaction()\n }\n\n addReaction(reaction) {\n this.#reactions.add(reaction)\n\n return () =>\n this.#reactions.delete(reaction)\n }\n}\n\n// A reactive implementation for building functional reactive graphs\n// Ensures state consistency, minimal node updates, and transparent update batching\nexport class FunctionalReactive {\n [isReactive] = true\n\n #value\n #reactions = new Set()\n\n // For derived nodes, f is the derivation function\n #f\n // Source nodes are 0 deep in the derivation graph\n // This is for topological sort\n #depth = 0\n // All nodes have a set of derivatives that update when the node changes\n #derivatives = new Set()\n\n // Keep track of all the pending changes from the value setter\n static #settersQueue = new Map()\n // A queue of derivatives to potentially update, sorted into sets by depth\n // This starts with depth 1 and can potentially have holes\n static #derivativesQueue = []\n // A queue of reactions to run after the graph is fully updated\n static #reactionsQueue = []\n\n constructor(x, f) {\n if (!f) {\n this.#value = x\n return\n }\n\n this.#value = f()\n this.#f = f\n this.#depth = Math.max(...x.map(d => d.#depth)) + 1\n\n x.forEach(d => d.#derivatives.add(this))\n }\n\n get value() {\n // If there are any pending updates, go ahead and apply them first\n // It's ok that there's already a microtask queued for this\n if (FunctionalReactive.#settersQueue.size)\n FunctionalReactive.applyUpdates()\n\n return this.#value\n }\n\n set value(newValue) {\n // Only allow souce nodes to be directly updated\n if (this.#depth !== 0)\n return\n\n // Unless asked for earlier, these updates are just queued up until the microtasks run\n if (!FunctionalReactive.#settersQueue.size)\n queueMicrotask(FunctionalReactive.applyUpdates)\n\n FunctionalReactive.#settersQueue.set(this, newValue)\n }\n\n addReaction(reaction) {\n this.#reactions.add(reaction)\n\n return () =>\n this.#reactions.delete(reaction)\n }\n\n // Apply an update for a node and queue its derivatives if it actually changed\n #applyUpdate(newValue) {\n if (newValue === this.#value)\n return\n\n this.#value = newValue\n FunctionalReactive.#reactionsQueue.push(...this.#reactions)\n\n const queue = FunctionalReactive.#derivativesQueue\n for (const derivative of this.#derivatives) {\n const depth = derivative.#depth\n if (!queue[depth])\n queue[depth] = new Set()\n\n queue[depth].add(derivative)\n }\n }\n\n // Apply pending updates from actually changed source nodes\n static applyUpdates() {\n if (!FunctionalReactive.#settersQueue.size)\n return\n\n // Bootstrap by applying the updates from the pending setters\n for (const [sourceNode, newValue] of FunctionalReactive.#settersQueue.entries())\n sourceNode.#applyUpdate(newValue)\n FunctionalReactive.#settersQueue.clear()\n\n // Iterate down the depths, ignoring holes\n // Note that both the queue (Array) and each depth Set iterators update as items are added\n for (const depthSet of FunctionalReactive.#derivativesQueue) if (depthSet)\n for (const derivative of depthSet)\n derivative.#applyUpdate(derivative.#f())\n FunctionalReactive.#derivativesQueue.length = 0\n\n // Call all reactions now that the graph has a fully consistent state\n for (const reaction of FunctionalReactive.#reactionsQueue)\n reaction()\n FunctionalReactive.#reactionsQueue.length = 0\n }\n}\n\n// A little convenience function\nexport const r = (x, f) => new FunctionalReactive(x, f)\n\n// Do something with a value, updating if it is reactive\nexport const reactiveDo = (x, f) => {\n if (x?.[isReactive]) {\n f(x.value)\n return x.addReaction(() => f(x.value))\n }\n\n f(x)\n}\n","// Create a pipeline with an initial value and a series of functions\nexport const pipe = (x, ...fs) =>\n fs.reduce((y, f) => f(y), x)\n\n// Dispatch a custom event to (capturing) and from (bubbling) a target (usually a DOM node)\n// Returns false if the event was cancelled (preventDefault()) and true otherwise\nexport const dispatch = (target, type, options) =>\n target.dispatchEvent(\n // Default to behave like most DOM events\n new CustomEvent(type, {\n bubbles: true,\n cancelable: true,\n composed: true,\n ...options\n })\n )\n\n// Inspired by https://antfu.me/posts/destructuring-with-object-or-array#take-away\n// Creates an object that is both destructable with {...} and [...]\n// Useful for writing library functions à la react-use & vueuse\nexport const createDestructable = (object, iterable) => {\n const destructable = {\n ...object,\n [Symbol.iterator]: () => iterable[Symbol.iterator]()\n }\n\n Object.defineProperty(destructable, Symbol.iterator, {\n enumerable: false\n })\n\n return destructable\n}\n\n// A function that acts like Maybe.from(x).ifExists(existsThen).ifEmpty(emptyThen)\n// Except we just use an array in place of a true Maybe type\n// This is useful for setting and removing reactive attributes\nexport const maybeDo = (existsThen, emptyThen) => x => {\n if (Array.isArray(x)) {\n if (x.length)\n existsThen(x[0])\n else\n emptyThen()\n }\n else\n existsThen(x)\n}\n\n// Creates an object (as a Proxy) that acts as a function\n// So functionAsObject(f).property is equivalent to f(\"property\")\n// This is can be useful when combined with destructuring syntax, e.g.:\n// const { html, head, title, body, main, h1, p } = functionAsObject(e)\nexport const functionAsObject = f =>\n new Proxy({}, {\n get: (_, property) => f(property)\n })\n","/** @typedef { import(\"./index.browser\") } */\n\nimport { LiveFragment } from \"./live-fragment.mjs\"\nimport { reactiveDo } from \"../reactive/index.mjs\"\nimport { maybeDo } from \"../util/index.mjs\"\n\nconst isReactive = Symbol.for(\"bruh reactive\")\nconst isMetaNode = Symbol.for(\"bruh meta node\")\nconst isMetaTextNode = Symbol.for(\"bruh meta text node\")\nconst isMetaElement = Symbol.for(\"bruh meta element\")\n\n// A basic check for if a value is allowed as a meta node's child\n// It's responsible for quickly checking the type, not deep validation\nconst isMetaNodeChild = x =>\n // meta nodes, reactives, and DOM nodes\n x?.[isMetaNode] ||\n x?.[isReactive] ||\n x instanceof Node ||\n // Any array, just assume it contains valid children\n Array.isArray(x) ||\n // Allow nullish\n x == null ||\n // Disallow functions and objects\n !(typeof x === \"function\" || typeof x === \"object\")\n // Everything else can be a child when stringified\n\nconst toNode = x => {\n if (x[isMetaNode])\n return x.node\n\n if (x instanceof Node)\n return x\n\n return document.createTextNode(x)\n}\n\nexport const childrenToNodes = children =>\n children\n .flat(Infinity)\n .flatMap(child => {\n if (!child[isReactive])\n return [toNode(child)]\n\n if (Array.isArray(child.value)) {\n const liveFragment = new LiveFragment()\n child.addReaction(() => {\n liveFragment.replaceChildren(...childrenToNodes(child.value))\n })\n return [liveFragment.startMarker, ...childrenToNodes(child.value), liveFragment.endMarker]\n }\n\n let node = toNode(child.value)\n child.addReaction(() => {\n const oldNode = node\n node = toNode(child.value)\n oldNode.replaceWith(node)\n })\n return [node]\n })\n\n\n\n// Meta Nodes\n\nexport class MetaTextNode {\n [isMetaNode] = true;\n [isMetaTextNode] = true\n\n node\n\n constructor(textContent) {\n if (!textContent[isReactive]) {\n this.node = document.createTextNode(textContent)\n return\n }\n\n this.node = document.createTextNode(textContent.value)\n textContent.addReaction(() => {\n this.node.textContent = textContent.value\n })\n }\n\n addProperties(properties = {}) {\n Object.assign(this.node, properties)\n\n return this\n }\n}\n\nexport class MetaElement {\n [isMetaNode] = true;\n [isMetaElement] = true\n\n node\n\n constructor(name, namespace) {\n this.node =\n namespace\n ? document.createElementNS(namespace, name)\n : document.createElement ( name)\n }\n\n static from(element) {\n const result = new this(\"div\")\n result.node = element\n return result\n }\n\n addProperties(properties = {}) {\n Object.assign(this.node, properties)\n\n return this\n }\n\n addAttributes(attributes = {}) {\n for (const name in attributes)\n reactiveDo(attributes[name],\n maybeDo(\n value => this.node.setAttribute (name, value),\n () => this.node.removeAttribute(name)\n )\n )\n\n return this\n }\n\n addDataAttributes(dataAttributes = {}) {\n for (const name in dataAttributes)\n reactiveDo(dataAttributes[name],\n maybeDo(\n value => this.node.dataset[name] = value,\n () => delete this.node.dataset[name]\n )\n )\n\n return this\n }\n\n addStyles(styles = {}) {\n for (const property in styles)\n reactiveDo(styles[property],\n maybeDo(\n value => this.node.style.setProperty (property, value),\n () => this.node.style.removeProperty(property)\n )\n )\n\n return this\n }\n\n toggleClasses(classes = {}) {\n for (const name in classes)\n reactiveDo(classes[name],\n value => this.node.classList.toggle(name, value)\n )\n\n return this\n }\n\n before(...xs) {\n this.node.before(...childrenToNodes(xs))\n }\n\n prepend(...xs) {\n this.node.prepend(...childrenToNodes(xs))\n }\n\n append(...xs) {\n this.node.append(...childrenToNodes(xs))\n }\n\n after(...xs) {\n this.node.after(...childrenToNodes(xs))\n }\n\n replaceChildren(...xs) {\n this.node.replaceChildren(...childrenToNodes(xs))\n }\n\n replaceWith(...xs) {\n this.node.replaceWith(...childrenToNodes(xs))\n }\n}\n\n\n\n// Convenience functions\n\nexport const hydrateTextNodes = () => {\n const tagged = {}\n const bruhTextNodes = document.getElementsByTagName(\"bruh-textnode\")\n\n for (const bruhTextNode of bruhTextNodes) {\n const textNode = document.createTextNode(bruhTextNode.textContent)\n\n if (bruhTextNode.dataset.tag)\n tagged[bruhTextNode.dataset.tag] = textNode\n\n bruhTextNode.replaceWith(textNode)\n }\n\n return tagged\n}\n\nconst createMetaTextNode = textContent =>\n new MetaTextNode(textContent)\n\nconst createMetaElement = (name, namespace) => (...variadic) => {\n const meta = new MetaElement(name, namespace)\n\n // Implement optional attributes as first argument\n if (!isMetaNodeChild(variadic[0])) {\n const [attributes, ...children] = variadic\n meta.addAttributes(attributes)\n meta.append(children)\n }\n else {\n meta.append(variadic)\n }\n\n return meta\n}\n\n// JSX integration\nconst createMetaElementJSX = (nameOrComponent, attributesOrProps, ...children) => {\n // If we are making a html element\n // This is likely when the jsx tag name begins with a lowercase character\n if (typeof nameOrComponent == \"string\") {\n const meta = new MetaElement(nameOrComponent)\n\n // These are attributes then, but they might be null/undefined\n meta.addAttributes(attributesOrProps || {})\n meta.append(children)\n\n return meta\n }\n\n // It must be a component, then\n // Bruh components are just functions that return meta elements\n // Due to JSX, this would mean a function with only one parameter - a \"props\" object\n // This object includes the all of the attributes and a \"children\" key\n return nameOrComponent( Object.assign({}, attributesOrProps, { children }) )\n}\n\n// These will be called with short names\nexport {\n createMetaTextNode as t,\n createMetaElement as e,\n createMetaElementJSX as h\n}\n\n// The JSX fragment is made into a bruh fragment (just an array)\nexport const JSXFragment = ({ children }) => children\n"],"names":["isReactive"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAUO,mBAAmB;AAAA,EAAnB,cAVP;AAWE,uCAAc,SAAS,eAAe;AACtC,qCAAc,SAAS,eAAe;AAAA;AAAA,SAE/B,KAAK,WAAW,UAAU;AAC/B,UAAM,gBAAe,IAAI;AACzB,cAAU,OAAO,cAAa;AAC9B,aAAS,MAAM,cAAa;AAC5B,WAAO;AAAA;AAAA,EAGT,UAAU,IAAI;AACZ,SAAK,YAAY,OAAO,GAAG;AAAA;AAAA,EAG7B,WAAW,IAAI;AACb,SAAK,YAAY,MAAM,GAAG;AAAA;AAAA,EAG5B,UAAU,IAAI;AACZ,SAAK,UAAU,OAAO,GAAG;AAAA;AAAA,EAG3B,SAAS,IAAI;AACX,SAAK,UAAU,MAAM,GAAG;AAAA;AAAA,EAG1B,SAAS;AACP,UAAM,QAAQ,SAAS;AACvB,UAAM,eAAe,KAAK;AAC1B,UAAM,YAAY,KAAK;AACvB,UAAM;AAAA;AAAA,EAGR,mBAAmB,IAAI;AACrB,UAAM,QAAQ,SAAS;AACvB,UAAM,cAAc,KAAK;AACzB,UAAM,aAAa,KAAK;AACxB,UAAM;AACN,SAAK,YAAY,MAAM,GAAG;AAAA;AAAA,EAG5B,eAAe,IAAI;AACjB,SAAK,UAAU,MAAM,GAAG;AACxB,SAAK;AAAA;AAAA,MAGH,aAAa;AACf,UAAM,aAAa;AAEnB,aACM,cAAc,KAAK,YAAY,aACnC,eAAe,KAAK,aAAa,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AO,mBAAmB,UAAU;AACtC,UAAM,OAAO,IAAI,YAAY;AAG7B,SAAK,cAAc,qBAAqB;AACxC,SAAK,OAAO;AAEZ,WAAO;AAAA;AAOT,SAAO,gBAAiB,OAAO,OAAO,IAAI,mBAAmB,EAAE;AAAA;AAW1D,MAAM,cAAc,CAAC,EAAE,eAAe;;;;;;;;;;;;;;"}
package/dist/bruh.umd.js CHANGED
@@ -1,2 +1,2 @@
1
- var oe=Object.defineProperty,se=Object.defineProperties;var ae=Object.getOwnPropertyDescriptors;var B=Object.getOwnPropertySymbols;var ie=Object.prototype.hasOwnProperty,de=Object.prototype.propertyIsEnumerable;var P=(o,s,i)=>s in o?oe(o,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):o[s]=i,_=(o,s)=>{for(var i in s||(s={}))ie.call(s,i)&&P(o,i,s[i]);if(B)for(var i of B(s))de.call(s,i)&&P(o,i,s[i]);return o},J=(o,s)=>se(o,ae(s));var l=(o,s,i)=>(P(o,typeof s!="symbol"?s+"":s,i),i),C=(o,s,i)=>{if(!s.has(o))throw TypeError("Cannot "+i)};var a=(o,s,i)=>(C(o,s,"read from private field"),i?i.call(o):s.get(o)),u=(o,s,i)=>{if(s.has(o))throw TypeError("Cannot add the same private member more than once");s instanceof WeakSet?s.add(o):s.set(o,i)},m=(o,s,i,v)=>(C(o,s,"write to private field"),v?v.call(o,i):s.set(o,i),i);var W=(o,s,i)=>(C(o,s,"access private method"),i);(function(o,s){typeof exports=="object"&&typeof module!="undefined"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(o=typeof globalThis!="undefined"?globalThis:o||self,s(o.bruh={}))})(this,function(o){var ce,b,M,ue,p,S,w,g,E,f,N,T,j,Q,le,he,fe,pe;"use strict";class s{constructor(){l(this,"startMarker",document.createTextNode(""));l(this,"endMarker",document.createTextNode(""))}static from(e,t){const n=new this;return e.before(n.startMarker),t.after(n.endMarker),n}before(...e){this.startMarker.before(...e)}prepend(...e){this.startMarker.after(...e)}append(...e){this.endMarker.before(...e)}after(...e){this.endMarker.after(...e)}remove(){const e=document.createRange();e.setStartBefore(this.startMarker),e.setEndAfter(this.endMarker),e.deleteContents()}replaceChildren(...e){const t=document.createRange();t.setStartAfter(this.startMarker),t.setEndBefore(this.endMarker),t.deleteContents(),this.startMarker.after(...e)}replaceWith(...e){this.endMarker.after(...e),this.remove()}get childNodes(){const e=[];for(let t=this.startMarker.nextSibling;t!=this.endMarker&&t;t=t.nextSibling)e.push(t);return e}get children(){return this.childNodes.filter(e=>e instanceof HTMLElement)}}var i=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",LiveFragment:s});const v=Symbol.for("bruh reactive");class X{constructor(e){l(this,ce,!0);u(this,b,void 0);u(this,M,new Set);m(this,b,e)}get value(){return a(this,b)}set value(e){if(e!==a(this,b)){m(this,b,e);for(const t of a(this,M))t()}}addReaction(e){return a(this,M).add(e),()=>a(this,M).delete(e)}}ce=v,b=new WeakMap,M=new WeakMap;const d=class{constructor(e,t){u(this,j);l(this,ue,!0);u(this,p,void 0);u(this,S,new Set);u(this,w,void 0);u(this,g,0);u(this,E,new Set);if(!t){m(this,p,e);return}m(this,p,t()),m(this,w,t),m(this,g,Math.max(...e.map(n=>a(n,g)))+1),e.forEach(n=>a(n,E).add(this))}get value(){return a(d,f).size&&d.applyUpdates(),a(this,p)}set value(e){a(this,g)===0&&(a(d,f).size||queueMicrotask(d.applyUpdates),a(d,f).set(this,e))}addReaction(e){return a(this,S).add(e),()=>a(this,S).delete(e)}static applyUpdates(){var e,t,n;if(!!a(d,f).size){for(const[c,k]of a(d,f).entries())W(e=c,j,Q).call(e,k);a(d,f).clear();for(const c of a(d,N))if(c)for(const k of c)W(n=k,j,Q).call(n,a(t=k,w).call(t));a(d,N).length=0;for(const c of a(d,T))c();a(d,T).length=0}}};let y=d;ue=v,p=new WeakMap,S=new WeakMap,w=new WeakMap,g=new WeakMap,E=new WeakMap,f=new WeakMap,N=new WeakMap,T=new WeakMap,j=new WeakSet,Q=function(e){if(e===a(this,p))return;m(this,p,e),a(d,T).push(...a(this,S));const t=a(d,N);for(const n of a(this,E)){const c=a(n,g);t[c]||(t[c]=new Set),t[c].add(n)}},u(y,f,new Map),u(y,N,[]),u(y,T,[]);const q=(r,e)=>new y(r,e),A=(r,e)=>{if(r==null?void 0:r[v])return e(r.value),r.addReaction(()=>e(r.value));e(r)};var $=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",SimpleReactive:X,FunctionalReactive:y,r:q,reactiveDo:A});const H=(r,...e)=>e.reduce((t,n)=>n(t),r),I=(r,e,t)=>r.dispatchEvent(new CustomEvent(e,_({bubbles:!0,cancelable:!0,composed:!0},t))),G=(r,e)=>{const t=J(_({},r),{[Symbol.iterator]:()=>e[Symbol.iterator]()});return Object.defineProperty(t,Symbol.iterator,{enumerable:!1}),t},R=(r,e)=>t=>{Array.isArray(t)?t.length?r(t[0]):e():r(t)},K=r=>new Proxy({},{get:(e,t)=>r(t)});var Y=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",pipe:H,dispatch:I,createDestructable:G,maybeDo:R,functionAsObject:K});const z=Symbol.for("bruh reactive"),O=Symbol.for("bruh meta node"),L=Symbol.for("bruh meta element"),Z=r=>(r==null?void 0:r[O])||(r==null?void 0:r[z])||r instanceof Node||Array.isArray(r)||r==null||!(typeof r=="function"||typeof r=="object"),D=r=>r[O]?r.node:r instanceof Node?r:document.createTextNode(r),h=r=>r.flat(1/0).flatMap(e=>{if(!e[z])return[D(e)];if(Array.isArray(e.value)){const n=new s;return e.addReaction(()=>{n.replaceChildren(...h(e.value))}),[n.startMarker,...h(e.value),n.endMarker]}let t=D(e.value);return e.addReaction(()=>{const n=t;t=D(e.value),n.replaceWith(t)}),[t]});class U{constructor(e){l(this,le,!0);l(this,he,!0);l(this,"node");if(!e[z]){this.node=document.createTextNode(e);return}this.node=document.createTextNode(e.value),e.addReaction(()=>{this.node.textContent=e.value})}addProperties(e={}){return Object.assign(this.node,e),this}}le=O,he=L;class F{constructor(e,t){l(this,fe,!0);l(this,pe,!0);l(this,"node");this.node=t?document.createElementNS(t,e):document.createElement(e)}static from(e){const t=new this("div");return t.node=e,t}addProperties(e={}){return Object.assign(this.node,e),this}addAttributes(e={}){for(const t in e)A(e[t],R(n=>this.node.setAttribute(t,n),()=>this.node.removeAttribute(t)));return this}addDataAttributes(e={}){for(const t in e)A(e[t],R(n=>this.node.dataset[t]=n,()=>delete this.node.dataset[t]));return this}addStyles(e={}){for(const t in e)A(e[t],R(n=>this.node.style.setProperty(t,n),()=>this.node.style.removeProperty(t)));return this}toggleClasses(e={}){for(const t in e)A(e[t],n=>this.node.classList.toggle(t,n));return this}before(...e){this.node.before(...h(e))}prepend(...e){this.node.prepend(...h(e))}append(...e){this.node.append(...h(e))}after(...e){this.node.after(...h(e))}replaceChildren(...e){this.node.replaceChildren(...h(e))}replaceWith(...e){this.node.replaceWith(...h(e))}}fe=O,pe=L;const V=()=>{const r={},e=document.getElementsByTagName("bruh-textnode");for(const t of e){const n=document.createTextNode(t.textContent);t.dataset.tag&&(r[t.dataset.tag]=n),t.replaceWith(n)}return r},x=r=>new U(r),ee=(r,e)=>(...t)=>{const n=new F(r,e);if(Z(t[0]))n.append(t);else{const[c,...k]=t;n.addAttributes(c),n.append(k)}return n},te=(r,e,...t)=>{if(typeof r=="string"){const n=new F(r);return n.addAttributes(e||{}),n.append(t),n}return r(Object.assign({},e,{children:t}))},re=({children:r})=>r;var ne=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",childrenToNodes:h,MetaTextNode:U,MetaElement:F,hydrateTextNodes:V,t:x,e:ee,h:te,JSXFragment:re});o.dom=ne,o.liveFragment=i,o.reactive=$,o.util=Y,Object.defineProperty(o,"__esModule",{value:!0}),o[Symbol.toStringTag]="Module"});
1
+ var se=Object.defineProperty,ae=Object.defineProperties;var ie=Object.getOwnPropertyDescriptors;var U=Object.getOwnPropertySymbols;var de=Object.prototype.hasOwnProperty,ce=Object.prototype.propertyIsEnumerable;var P=(o,s,i)=>s in o?se(o,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):o[s]=i,_=(o,s)=>{for(var i in s||(s={}))de.call(s,i)&&P(o,i,s[i]);if(U)for(var i of U(s))ce.call(s,i)&&P(o,i,s[i]);return o},B=(o,s)=>ae(o,ie(s));var l=(o,s,i)=>(P(o,typeof s!="symbol"?s+"":s,i),i),C=(o,s,i)=>{if(!s.has(o))throw TypeError("Cannot "+i)};var a=(o,s,i)=>(C(o,s,"read from private field"),i?i.call(o):s.get(o)),u=(o,s,i)=>{if(s.has(o))throw TypeError("Cannot add the same private member more than once");s instanceof WeakSet?s.add(o):s.set(o,i)},m=(o,s,i,v)=>(C(o,s,"write to private field"),v?v.call(o,i):s.set(o,i),i);var W=(o,s,i)=>(C(o,s,"access private method"),i);(function(o,s){typeof exports=="object"&&typeof module!="undefined"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(o=typeof globalThis!="undefined"?globalThis:o||self,s(o.bruh={}))})(this,function(o){var ue,b,M,le,p,S,w,g,E,f,N,T,j,J,he,fe,pe,me;"use strict";class s{constructor(){l(this,"startMarker",document.createTextNode(""));l(this,"endMarker",document.createTextNode(""))}static from(e,t){const n=new this;return e.before(n.startMarker),t.after(n.endMarker),n}before(...e){this.startMarker.before(...e)}prepend(...e){this.startMarker.after(...e)}append(...e){this.endMarker.before(...e)}after(...e){this.endMarker.after(...e)}remove(){const e=document.createRange();e.setStartBefore(this.startMarker),e.setEndAfter(this.endMarker),e.deleteContents()}replaceChildren(...e){const t=document.createRange();t.setStartAfter(this.startMarker),t.setEndBefore(this.endMarker),t.deleteContents(),this.startMarker.after(...e)}replaceWith(...e){this.endMarker.after(...e),this.remove()}get childNodes(){const e=[];for(let t=this.startMarker.nextSibling;t!=this.endMarker&&t;t=t.nextSibling)e.push(t);return e}get children(){return this.childNodes.filter(e=>e instanceof HTMLElement)}}var i=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",LiveFragment:s});const v=Symbol.for("bruh reactive");class Q{constructor(e){l(this,ue,!0);u(this,b,void 0);u(this,M,new Set);m(this,b,e)}get value(){return a(this,b)}set value(e){if(e!==a(this,b)){m(this,b,e);for(const t of a(this,M))t()}}addReaction(e){return a(this,M).add(e),()=>a(this,M).delete(e)}}ue=v,b=new WeakMap,M=new WeakMap;const d=class{constructor(e,t){u(this,j);l(this,le,!0);u(this,p,void 0);u(this,S,new Set);u(this,w,void 0);u(this,g,0);u(this,E,new Set);if(!t){m(this,p,e);return}m(this,p,t()),m(this,w,t),m(this,g,Math.max(...e.map(n=>a(n,g)))+1),e.forEach(n=>a(n,E).add(this))}get value(){return a(d,f).size&&d.applyUpdates(),a(this,p)}set value(e){a(this,g)===0&&(a(d,f).size||queueMicrotask(d.applyUpdates),a(d,f).set(this,e))}addReaction(e){return a(this,S).add(e),()=>a(this,S).delete(e)}static applyUpdates(){var e,t,n;if(!!a(d,f).size){for(const[c,k]of a(d,f).entries())W(e=c,j,J).call(e,k);a(d,f).clear();for(const c of a(d,N))if(c)for(const k of c)W(n=k,j,J).call(n,a(t=k,w).call(t));a(d,N).length=0;for(const c of a(d,T))c();a(d,T).length=0}}};let y=d;le=v,p=new WeakMap,S=new WeakMap,w=new WeakMap,g=new WeakMap,E=new WeakMap,f=new WeakMap,N=new WeakMap,T=new WeakMap,j=new WeakSet,J=function(e){if(e===a(this,p))return;m(this,p,e),a(d,T).push(...a(this,S));const t=a(d,N);for(const n of a(this,E)){const c=a(n,g);t[c]||(t[c]=new Set),t[c].add(n)}},u(y,f,new Map),u(y,N,[]),u(y,T,[]);const X=(r,e)=>new y(r,e),A=(r,e)=>{if(r==null?void 0:r[v])return e(r.value),r.addReaction(()=>e(r.value));e(r)};var q=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",SimpleReactive:Q,FunctionalReactive:y,r:X,reactiveDo:A});const $=(r,...e)=>e.reduce((t,n)=>n(t),r),H=(r,e,t)=>r.dispatchEvent(new CustomEvent(e,_({bubbles:!0,cancelable:!0,composed:!0},t))),I=(r,e)=>{const t=B(_({},r),{[Symbol.iterator]:()=>e[Symbol.iterator]()});return Object.defineProperty(t,Symbol.iterator,{enumerable:!1}),t},R=(r,e)=>t=>{Array.isArray(t)?t.length?r(t[0]):e():r(t)},G=r=>new Proxy({},{get:(e,t)=>r(t)});var K=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",pipe:$,dispatch:H,createDestructable:I,maybeDo:R,functionAsObject:G});const z=Symbol.for("bruh reactive"),O=Symbol.for("bruh meta node"),Y=Symbol.for("bruh meta text node"),Z=Symbol.for("bruh meta element"),V=r=>(r==null?void 0:r[O])||(r==null?void 0:r[z])||r instanceof Node||Array.isArray(r)||r==null||!(typeof r=="function"||typeof r=="object"),D=r=>r[O]?r.node:r instanceof Node?r:document.createTextNode(r),h=r=>r.flat(1/0).flatMap(e=>{if(!e[z])return[D(e)];if(Array.isArray(e.value)){const n=new s;return e.addReaction(()=>{n.replaceChildren(...h(e.value))}),[n.startMarker,...h(e.value),n.endMarker]}let t=D(e.value);return e.addReaction(()=>{const n=t;t=D(e.value),n.replaceWith(t)}),[t]});class L{constructor(e){l(this,he,!0);l(this,fe,!0);l(this,"node");if(!e[z]){this.node=document.createTextNode(e);return}this.node=document.createTextNode(e.value),e.addReaction(()=>{this.node.textContent=e.value})}addProperties(e={}){return Object.assign(this.node,e),this}}he=O,fe=Y;class F{constructor(e,t){l(this,pe,!0);l(this,me,!0);l(this,"node");this.node=t?document.createElementNS(t,e):document.createElement(e)}static from(e){const t=new this("div");return t.node=e,t}addProperties(e={}){return Object.assign(this.node,e),this}addAttributes(e={}){for(const t in e)A(e[t],R(n=>this.node.setAttribute(t,n),()=>this.node.removeAttribute(t)));return this}addDataAttributes(e={}){for(const t in e)A(e[t],R(n=>this.node.dataset[t]=n,()=>delete this.node.dataset[t]));return this}addStyles(e={}){for(const t in e)A(e[t],R(n=>this.node.style.setProperty(t,n),()=>this.node.style.removeProperty(t)));return this}toggleClasses(e={}){for(const t in e)A(e[t],n=>this.node.classList.toggle(t,n));return this}before(...e){this.node.before(...h(e))}prepend(...e){this.node.prepend(...h(e))}append(...e){this.node.append(...h(e))}after(...e){this.node.after(...h(e))}replaceChildren(...e){this.node.replaceChildren(...h(e))}replaceWith(...e){this.node.replaceWith(...h(e))}}pe=O,me=Z;const x=()=>{const r={},e=document.getElementsByTagName("bruh-textnode");for(const t of e){const n=document.createTextNode(t.textContent);t.dataset.tag&&(r[t.dataset.tag]=n),t.replaceWith(n)}return r},ee=r=>new L(r),te=(r,e)=>(...t)=>{const n=new F(r,e);if(V(t[0]))n.append(t);else{const[c,...k]=t;n.addAttributes(c),n.append(k)}return n},re=(r,e,...t)=>{if(typeof r=="string"){const n=new F(r);return n.addAttributes(e||{}),n.append(t),n}return r(Object.assign({},e,{children:t}))},ne=({children:r})=>r;var oe=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",childrenToNodes:h,MetaTextNode:L,MetaElement:F,hydrateTextNodes:x,t:ee,e:te,h:re,JSXFragment:ne});o.dom=oe,o.liveFragment=i,o.reactive=q,o.util=K,Object.defineProperty(o,"__esModule",{value:!0}),o[Symbol.toStringTag]="Module"});
2
2
  //# sourceMappingURL=bruh.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bruh.umd.js","sources":["../src/dom/live-fragment.mjs","../src/reactive/index.mjs","../src/util/index.mjs","../src/dom/index.browser.mjs"],"sourcesContent":["// Lightweight and performant DOM fragment that keeps its place,\n// useful for grouping siblings without making a parent element.\n// Not a true analog of the DocumentFragment, because the implementation\n// would be infeasible with that scope, adding a performance penalty as well.\n// Works as long as the start & end placeholders are siblings in that order\n// and they do not overlap other LiveFragment's:\n// Works: (start A)(start B)(end B)(end A)\n// Fails: (start A)(start B)(end A)(end B)\n// Also, make sure not to call .normalize() on the parent element,\n// because that would ruin the placeholders.\nexport class LiveFragment {\n startMarker = document.createTextNode(\"\")\n endMarker = document.createTextNode(\"\")\n\n static from(firstNode, lastNode) {\n const liveFragment = new this()\n firstNode.before(liveFragment.startMarker)\n lastNode.after(liveFragment.endMarker)\n return liveFragment\n }\n\n before(...xs) {\n this.startMarker.before(...xs)\n }\n\n prepend(...xs) {\n this.startMarker.after(...xs)\n }\n\n append(...xs) {\n this.endMarker.before(...xs)\n }\n\n after(...xs) {\n this.endMarker.after(...xs)\n }\n\n remove() {\n const range = document.createRange()\n range.setStartBefore(this.startMarker)\n range.setEndAfter(this.endMarker)\n range.deleteContents()\n }\n\n replaceChildren(...xs) {\n const range = document.createRange()\n range.setStartAfter(this.startMarker)\n range.setEndBefore(this.endMarker)\n range.deleteContents()\n this.startMarker.after(...xs)\n }\n\n replaceWith(...xs) {\n this.endMarker.after(...xs)\n this.remove()\n }\n\n get childNodes() {\n const childNodes = []\n\n for (\n let currentNode = this.startMarker.nextSibling;\n currentNode != this.endMarker && currentNode;\n currentNode = currentNode.nextSibling\n )\n childNodes.push(currentNode)\n\n return childNodes\n }\n\n get children() {\n return this.childNodes\n .filter(node => node instanceof HTMLElement)\n }\n}\n","const isReactive = Symbol.for(\"bruh reactive\")\n\n// A super simple and performant reactive value implementation\nexport class SimpleReactive {\n [isReactive] = true\n\n #value\n #reactions = new Set()\n\n constructor(value) {\n this.#value = value\n }\n\n get value() {\n return this.#value\n }\n\n set value(newValue) {\n if (newValue === this.#value)\n return\n\n this.#value = newValue\n for (const reaction of this.#reactions)\n reaction()\n }\n\n addReaction(reaction) {\n this.#reactions.add(reaction)\n\n return () =>\n this.#reactions.delete(reaction)\n }\n}\n\n// A reactive implementation for building functional reactive graphs\n// Ensures state consistency, minimal node updates, and transparent update batching\nexport class FunctionalReactive {\n [isReactive] = true\n\n #value\n #reactions = new Set()\n\n // For derived nodes, f is the derivation function\n #f\n // Source nodes are 0 deep in the derivation graph\n // This is for topological sort\n #depth = 0\n // All nodes have a set of derivatives that update when the node changes\n #derivatives = new Set()\n\n // Keep track of all the pending changes from the value setter\n static #settersQueue = new Map()\n // A queue of derivatives to potentially update, sorted into sets by depth\n // This starts with depth 1 and can potentially have holes\n static #derivativesQueue = []\n // A queue of reactions to run after the graph is fully updated\n static #reactionsQueue = []\n\n constructor(x, f) {\n if (!f) {\n this.#value = x\n return\n }\n\n this.#value = f()\n this.#f = f\n this.#depth = Math.max(...x.map(d => d.#depth)) + 1\n\n x.forEach(d => d.#derivatives.add(this))\n }\n\n get value() {\n // If there are any pending updates, go ahead and apply them first\n // It's ok that there's already a microtask queued for this\n if (FunctionalReactive.#settersQueue.size)\n FunctionalReactive.applyUpdates()\n\n return this.#value\n }\n\n set value(newValue) {\n // Only allow souce nodes to be directly updated\n if (this.#depth !== 0)\n return\n\n // Unless asked for earlier, these updates are just queued up until the microtasks run\n if (!FunctionalReactive.#settersQueue.size)\n queueMicrotask(FunctionalReactive.applyUpdates)\n\n FunctionalReactive.#settersQueue.set(this, newValue)\n }\n\n addReaction(reaction) {\n this.#reactions.add(reaction)\n\n return () =>\n this.#reactions.delete(reaction)\n }\n\n // Apply an update for a node and queue its derivatives if it actually changed\n #applyUpdate(newValue) {\n if (newValue === this.#value)\n return\n\n this.#value = newValue\n FunctionalReactive.#reactionsQueue.push(...this.#reactions)\n\n const queue = FunctionalReactive.#derivativesQueue\n for (const derivative of this.#derivatives) {\n const depth = derivative.#depth\n if (!queue[depth])\n queue[depth] = new Set()\n\n queue[depth].add(derivative)\n }\n }\n\n // Apply pending updates from actually changed source nodes\n static applyUpdates() {\n if (!FunctionalReactive.#settersQueue.size)\n return\n\n // Bootstrap by applying the updates from the pending setters\n for (const [sourceNode, newValue] of FunctionalReactive.#settersQueue.entries())\n sourceNode.#applyUpdate(newValue)\n FunctionalReactive.#settersQueue.clear()\n\n // Iterate down the depths, ignoring holes\n // Note that both the queue (Array) and each depth Set iterators update as items are added\n for (const depthSet of FunctionalReactive.#derivativesQueue) if (depthSet)\n for (const derivative of depthSet)\n derivative.#applyUpdate(derivative.#f())\n FunctionalReactive.#derivativesQueue.length = 0\n\n // Call all reactions now that the graph has a fully consistent state\n for (const reaction of FunctionalReactive.#reactionsQueue)\n reaction()\n FunctionalReactive.#reactionsQueue.length = 0\n }\n}\n\n// A little convenience function\nexport const r = (x, f) => new FunctionalReactive(x, f)\n\n// Do something with a value, updating if it is reactive\nexport const reactiveDo = (x, f) => {\n if (x?.[isReactive]) {\n f(x.value)\n return x.addReaction(() => f(x.value))\n }\n\n f(x)\n}\n","// Create a pipeline with an initial value and a series of functions\nexport const pipe = (x, ...fs) =>\n fs.reduce((y, f) => f(y), x)\n\n// Dispatch a custom event to (capturing) and from (bubbling) a target (usually a DOM node)\n// Returns false if the event was cancelled (preventDefault()) and true otherwise\nexport const dispatch = (target, type, options) =>\n target.dispatchEvent(\n // Default to behave like most DOM events\n new CustomEvent(type, {\n bubbles: true,\n cancelable: true,\n composed: true,\n ...options\n })\n )\n\n// Inspired by https://antfu.me/posts/destructuring-with-object-or-array#take-away\n// Creates an object that is both destructable with {...} and [...]\n// Useful for writing library functions à la react-use & vueuse\nexport const createDestructable = (object, iterable) => {\n const destructable = {\n ...object,\n [Symbol.iterator]: () => iterable[Symbol.iterator]()\n }\n\n Object.defineProperty(destructable, Symbol.iterator, {\n enumerable: false\n })\n\n return destructable\n}\n\n// A function that acts like Maybe.from(x).ifExists(existsThen).ifEmpty(emptyThen)\n// Except we just use an array in place of a true Maybe type\n// This is useful for setting and removing reactive attributes\nexport const maybeDo = (existsThen, emptyThen) => x => {\n if (Array.isArray(x)) {\n if (x.length)\n existsThen(x[0])\n else\n emptyThen()\n }\n else\n existsThen(x)\n}\n\n// Creates an object (as a Proxy) that acts as a function\n// So functionAsObject(f).property is equivalent to f(\"property\")\n// This is can be useful when combined with destructuring syntax, e.g.:\n// const { html, head, title, body, main, h1, p } = functionAsObject(e)\nexport const functionAsObject = f =>\n new Proxy({}, {\n get: (_, property) => f(property)\n })\n","import { LiveFragment } from \"./live-fragment.mjs\"\nimport { reactiveDo } from \"../reactive/index.mjs\"\nimport { maybeDo } from \"../util/index.mjs\"\n\nconst isReactive = Symbol.for(\"bruh reactive\")\nconst isMetaNode = Symbol.for(\"bruh meta node\")\nconst isMetaTextNode = Symbol.for(\"bruh meta text node\")\nconst isMetaElement = Symbol.for(\"bruh meta element\")\n\n// A basic check for if a value is allowed as a meta node's child\n// It's responsible for quickly checking the type, not deep validation\nconst isMetaNodeChild = x =>\n // meta nodes, reactives, and DOM nodes\n x?.[isMetaNode] ||\n x?.[isReactive] ||\n x instanceof Node ||\n // Any array, just assume it contains valid children\n Array.isArray(x) ||\n // Allow nullish\n x == null ||\n // Disallow functions and objects\n !(typeof x === \"function\" || typeof x === \"object\")\n // Everything else can be a child when stringified\n\nconst toNode = x => {\n if (x[isMetaNode])\n return x.node\n\n if (x instanceof Node)\n return x\n\n return document.createTextNode(x)\n}\n\nexport const childrenToNodes = children =>\n children\n .flat(Infinity)\n .flatMap(child => {\n if (!child[isReactive])\n return [toNode(child)]\n\n if (Array.isArray(child.value)) {\n const liveFragment = new LiveFragment()\n child.addReaction(() => {\n liveFragment.replaceChildren(...childrenToNodes(child.value))\n })\n return [liveFragment.startMarker, ...childrenToNodes(child.value), liveFragment.endMarker]\n }\n\n let node = toNode(child.value)\n child.addReaction(() => {\n const oldNode = node\n node = toNode(child.value)\n oldNode.replaceWith(node)\n })\n return [node]\n })\n\n\n\n// Meta Nodes\n\nexport class MetaTextNode {\n [isMetaNode] = true;\n [isMetaElement] = true\n\n node\n\n constructor(textContent) {\n if (!textContent[isReactive]) {\n this.node = document.createTextNode(textContent)\n return\n }\n\n this.node = document.createTextNode(textContent.value)\n textContent.addReaction(() => {\n this.node.textContent = textContent.value\n })\n }\n\n addProperties(properties = {}) {\n Object.assign(this.node, properties)\n\n return this\n }\n}\n\nexport class MetaElement {\n [isMetaNode] = true;\n [isMetaElement] = true\n\n node\n\n constructor(name, namespace) {\n this.node =\n namespace\n ? document.createElementNS(namespace, name)\n : document.createElement ( name)\n }\n\n static from(element) {\n const result = new this(\"div\")\n result.node = element\n return result\n }\n\n addProperties(properties = {}) {\n Object.assign(this.node, properties)\n\n return this\n }\n\n addAttributes(attributes = {}) {\n for (const name in attributes)\n reactiveDo(attributes[name],\n maybeDo(\n value => this.node.setAttribute (name, value),\n () => this.node.removeAttribute(name)\n )\n )\n\n return this\n }\n\n addDataAttributes(dataAttributes = {}) {\n for (const name in dataAttributes)\n reactiveDo(dataAttributes[name],\n maybeDo(\n value => this.node.dataset[name] = value,\n () => delete this.node.dataset[name]\n )\n )\n\n return this\n }\n\n addStyles(styles = {}) {\n for (const property in styles)\n reactiveDo(styles[property],\n maybeDo(\n value => this.node.style.setProperty (property, value),\n () => this.node.style.removeProperty(property)\n )\n )\n\n return this\n }\n\n toggleClasses(classes = {}) {\n for (const name in classes)\n reactiveDo(classes[name],\n value => this.node.classList.toggle(name, value)\n )\n\n return this\n }\n\n before(...xs) {\n this.node.before(...childrenToNodes(xs))\n }\n\n prepend(...xs) {\n this.node.prepend(...childrenToNodes(xs))\n }\n\n append(...xs) {\n this.node.append(...childrenToNodes(xs))\n }\n\n after(...xs) {\n this.node.after(...childrenToNodes(xs))\n }\n\n replaceChildren(...xs) {\n this.node.replaceChildren(...childrenToNodes(xs))\n }\n\n replaceWith(...xs) {\n this.node.replaceWith(...childrenToNodes(xs))\n }\n}\n\n\n\n// Convenience functions\n\nexport const hydrateTextNodes = () => {\n const tagged = {}\n const bruhTextNodes = document.getElementsByTagName(\"bruh-textnode\")\n\n for (const bruhTextNode of bruhTextNodes) {\n const textNode = document.createTextNode(bruhTextNode.textContent)\n\n if (bruhTextNode.dataset.tag)\n tagged[bruhTextNode.dataset.tag] = textNode\n\n bruhTextNode.replaceWith(textNode)\n }\n\n return tagged\n}\n\nconst createMetaTextNode = textContent =>\n new MetaTextNode(textContent)\n\nconst createMetaElement = (name, namespace) => (...variadic) => {\n const meta = new MetaElement(name, namespace)\n\n // Implement optional attributes as first argument\n if (!isMetaNodeChild(variadic[0])) {\n const [attributes, ...children] = variadic\n meta.addAttributes(attributes)\n meta.append(children)\n }\n else {\n meta.append(variadic)\n }\n\n return meta\n}\n\n// JSX integration\nconst createMetaElementJSX = (nameOrComponent, attributesOrProps, ...children) => {\n // If we are making a html element\n // This is likely when the jsx tag name begins with a lowercase character\n if (typeof nameOrComponent == \"string\") {\n const meta = new MetaElement(nameOrComponent)\n\n // These are attributes then, but they might be null/undefined\n meta.addAttributes(attributesOrProps || {})\n meta.append(children)\n\n return meta\n }\n\n // It must be a component, then\n // Bruh components are just functions that return meta elements\n // Due to JSX, this would mean a function with only one parameter - a \"props\" object\n // This object includes the all of the attributes and a \"children\" key\n return nameOrComponent( Object.assign({}, attributesOrProps, { children }) )\n}\n\n// These will be called with short names\nexport {\n createMetaTextNode as t,\n createMetaElement as e,\n createMetaElementJSX as h\n}\n\n// The JSX fragment is made into a bruh fragment (just an array)\nexport const JSXFragment = ({ children }) => children\n"],"names":["isReactive"],"mappings":"woCAUO,OAAmB,CAAnB,cACL,qBAAc,SAAS,eAAe,KACtC,mBAAc,SAAS,eAAe,WAE/B,MAAK,EAAW,EAAU,CAC/B,KAAM,GAAe,GAAI,MACzB,SAAU,OAAO,EAAa,aAC9B,EAAS,MAAM,EAAa,WACrB,EAGT,UAAU,EAAI,CACZ,KAAK,YAAY,OAAO,GAAG,GAG7B,WAAW,EAAI,CACb,KAAK,YAAY,MAAM,GAAG,GAG5B,UAAU,EAAI,CACZ,KAAK,UAAU,OAAO,GAAG,GAG3B,SAAS,EAAI,CACX,KAAK,UAAU,MAAM,GAAG,GAG1B,QAAS,CACP,KAAM,GAAQ,SAAS,cACvB,EAAM,eAAe,KAAK,aAC1B,EAAM,YAAY,KAAK,WACvB,EAAM,iBAGR,mBAAmB,EAAI,CACrB,KAAM,GAAQ,SAAS,cACvB,EAAM,cAAc,KAAK,aACzB,EAAM,aAAa,KAAK,WACxB,EAAM,iBACN,KAAK,YAAY,MAAM,GAAG,GAG5B,eAAe,EAAI,CACjB,KAAK,UAAU,MAAM,GAAG,GACxB,KAAK,YAGH,aAAa,CACf,KAAM,GAAa,GAEnB,OACM,GAAc,KAAK,YAAY,YACn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Eb,GAAoB,CAAC,EAAM,IAAc,IAAI,IAAa,CAC9D,KAAM,GAAO,GAAI,GAAY,EAAM,GAGnC,GAAK,EAAgB,EAAS,IAM5B,EAAK,OAAO,OANqB,CACjC,KAAM,CAAC,KAAe,GAAY,EAClC,EAAK,cAAc,GACnB,EAAK,OAAO,GAMd,MAAO,IAIH,GAAuB,CAAC,EAAiB,KAAsB,IAAa,CAGhF,GAAI,MAAO,IAAmB,SAAU,CACtC,KAAM,GAAO,GAAI,GAAY,GAG7B,SAAK,cAAc,GAAqB,IACxC,EAAK,OAAO,GAEL,EAOT,MAAO,GAAiB,OAAO,OAAO,GAAI,EAAmB,CAAE,eAWpD,GAAc,CAAC,CAAE,cAAe"}
1
+ {"version":3,"file":"bruh.umd.js","sources":["../src/dom/live-fragment.mjs","../src/reactive/index.mjs","../src/util/index.mjs","../src/dom/index.browser.mjs"],"sourcesContent":["// Lightweight and performant DOM fragment that keeps its place,\n// useful for grouping siblings without making a parent element.\n// Not a true analog of the DocumentFragment, because the implementation\n// would be infeasible with that scope, adding a performance penalty as well.\n// Works as long as the start & end placeholders are siblings in that order\n// and they do not overlap other LiveFragment's:\n// Works: (start A)(start B)(end B)(end A)\n// Fails: (start A)(start B)(end A)(end B)\n// Also, make sure not to call .normalize() on the parent element,\n// because that would ruin the placeholders.\nexport class LiveFragment {\n startMarker = document.createTextNode(\"\")\n endMarker = document.createTextNode(\"\")\n\n static from(firstNode, lastNode) {\n const liveFragment = new this()\n firstNode.before(liveFragment.startMarker)\n lastNode.after(liveFragment.endMarker)\n return liveFragment\n }\n\n before(...xs) {\n this.startMarker.before(...xs)\n }\n\n prepend(...xs) {\n this.startMarker.after(...xs)\n }\n\n append(...xs) {\n this.endMarker.before(...xs)\n }\n\n after(...xs) {\n this.endMarker.after(...xs)\n }\n\n remove() {\n const range = document.createRange()\n range.setStartBefore(this.startMarker)\n range.setEndAfter(this.endMarker)\n range.deleteContents()\n }\n\n replaceChildren(...xs) {\n const range = document.createRange()\n range.setStartAfter(this.startMarker)\n range.setEndBefore(this.endMarker)\n range.deleteContents()\n this.startMarker.after(...xs)\n }\n\n replaceWith(...xs) {\n this.endMarker.after(...xs)\n this.remove()\n }\n\n get childNodes() {\n const childNodes = []\n\n for (\n let currentNode = this.startMarker.nextSibling;\n currentNode != this.endMarker && currentNode;\n currentNode = currentNode.nextSibling\n )\n childNodes.push(currentNode)\n\n return childNodes\n }\n\n get children() {\n return this.childNodes\n .filter(node => node instanceof HTMLElement)\n }\n}\n","/** @typedef { import(\"./index\") } */\n\nconst isReactive = Symbol.for(\"bruh reactive\")\n\n// A super simple and performant reactive value implementation\nexport class SimpleReactive {\n [isReactive] = true\n\n #value\n #reactions = new Set()\n\n constructor(value) {\n this.#value = value\n }\n\n get value() {\n return this.#value\n }\n\n set value(newValue) {\n if (newValue === this.#value)\n return\n\n this.#value = newValue\n for (const reaction of this.#reactions)\n reaction()\n }\n\n addReaction(reaction) {\n this.#reactions.add(reaction)\n\n return () =>\n this.#reactions.delete(reaction)\n }\n}\n\n// A reactive implementation for building functional reactive graphs\n// Ensures state consistency, minimal node updates, and transparent update batching\nexport class FunctionalReactive {\n [isReactive] = true\n\n #value\n #reactions = new Set()\n\n // For derived nodes, f is the derivation function\n #f\n // Source nodes are 0 deep in the derivation graph\n // This is for topological sort\n #depth = 0\n // All nodes have a set of derivatives that update when the node changes\n #derivatives = new Set()\n\n // Keep track of all the pending changes from the value setter\n static #settersQueue = new Map()\n // A queue of derivatives to potentially update, sorted into sets by depth\n // This starts with depth 1 and can potentially have holes\n static #derivativesQueue = []\n // A queue of reactions to run after the graph is fully updated\n static #reactionsQueue = []\n\n constructor(x, f) {\n if (!f) {\n this.#value = x\n return\n }\n\n this.#value = f()\n this.#f = f\n this.#depth = Math.max(...x.map(d => d.#depth)) + 1\n\n x.forEach(d => d.#derivatives.add(this))\n }\n\n get value() {\n // If there are any pending updates, go ahead and apply them first\n // It's ok that there's already a microtask queued for this\n if (FunctionalReactive.#settersQueue.size)\n FunctionalReactive.applyUpdates()\n\n return this.#value\n }\n\n set value(newValue) {\n // Only allow souce nodes to be directly updated\n if (this.#depth !== 0)\n return\n\n // Unless asked for earlier, these updates are just queued up until the microtasks run\n if (!FunctionalReactive.#settersQueue.size)\n queueMicrotask(FunctionalReactive.applyUpdates)\n\n FunctionalReactive.#settersQueue.set(this, newValue)\n }\n\n addReaction(reaction) {\n this.#reactions.add(reaction)\n\n return () =>\n this.#reactions.delete(reaction)\n }\n\n // Apply an update for a node and queue its derivatives if it actually changed\n #applyUpdate(newValue) {\n if (newValue === this.#value)\n return\n\n this.#value = newValue\n FunctionalReactive.#reactionsQueue.push(...this.#reactions)\n\n const queue = FunctionalReactive.#derivativesQueue\n for (const derivative of this.#derivatives) {\n const depth = derivative.#depth\n if (!queue[depth])\n queue[depth] = new Set()\n\n queue[depth].add(derivative)\n }\n }\n\n // Apply pending updates from actually changed source nodes\n static applyUpdates() {\n if (!FunctionalReactive.#settersQueue.size)\n return\n\n // Bootstrap by applying the updates from the pending setters\n for (const [sourceNode, newValue] of FunctionalReactive.#settersQueue.entries())\n sourceNode.#applyUpdate(newValue)\n FunctionalReactive.#settersQueue.clear()\n\n // Iterate down the depths, ignoring holes\n // Note that both the queue (Array) and each depth Set iterators update as items are added\n for (const depthSet of FunctionalReactive.#derivativesQueue) if (depthSet)\n for (const derivative of depthSet)\n derivative.#applyUpdate(derivative.#f())\n FunctionalReactive.#derivativesQueue.length = 0\n\n // Call all reactions now that the graph has a fully consistent state\n for (const reaction of FunctionalReactive.#reactionsQueue)\n reaction()\n FunctionalReactive.#reactionsQueue.length = 0\n }\n}\n\n// A little convenience function\nexport const r = (x, f) => new FunctionalReactive(x, f)\n\n// Do something with a value, updating if it is reactive\nexport const reactiveDo = (x, f) => {\n if (x?.[isReactive]) {\n f(x.value)\n return x.addReaction(() => f(x.value))\n }\n\n f(x)\n}\n","// Create a pipeline with an initial value and a series of functions\nexport const pipe = (x, ...fs) =>\n fs.reduce((y, f) => f(y), x)\n\n// Dispatch a custom event to (capturing) and from (bubbling) a target (usually a DOM node)\n// Returns false if the event was cancelled (preventDefault()) and true otherwise\nexport const dispatch = (target, type, options) =>\n target.dispatchEvent(\n // Default to behave like most DOM events\n new CustomEvent(type, {\n bubbles: true,\n cancelable: true,\n composed: true,\n ...options\n })\n )\n\n// Inspired by https://antfu.me/posts/destructuring-with-object-or-array#take-away\n// Creates an object that is both destructable with {...} and [...]\n// Useful for writing library functions à la react-use & vueuse\nexport const createDestructable = (object, iterable) => {\n const destructable = {\n ...object,\n [Symbol.iterator]: () => iterable[Symbol.iterator]()\n }\n\n Object.defineProperty(destructable, Symbol.iterator, {\n enumerable: false\n })\n\n return destructable\n}\n\n// A function that acts like Maybe.from(x).ifExists(existsThen).ifEmpty(emptyThen)\n// Except we just use an array in place of a true Maybe type\n// This is useful for setting and removing reactive attributes\nexport const maybeDo = (existsThen, emptyThen) => x => {\n if (Array.isArray(x)) {\n if (x.length)\n existsThen(x[0])\n else\n emptyThen()\n }\n else\n existsThen(x)\n}\n\n// Creates an object (as a Proxy) that acts as a function\n// So functionAsObject(f).property is equivalent to f(\"property\")\n// This is can be useful when combined with destructuring syntax, e.g.:\n// const { html, head, title, body, main, h1, p } = functionAsObject(e)\nexport const functionAsObject = f =>\n new Proxy({}, {\n get: (_, property) => f(property)\n })\n","/** @typedef { import(\"./index.browser\") } */\n\nimport { LiveFragment } from \"./live-fragment.mjs\"\nimport { reactiveDo } from \"../reactive/index.mjs\"\nimport { maybeDo } from \"../util/index.mjs\"\n\nconst isReactive = Symbol.for(\"bruh reactive\")\nconst isMetaNode = Symbol.for(\"bruh meta node\")\nconst isMetaTextNode = Symbol.for(\"bruh meta text node\")\nconst isMetaElement = Symbol.for(\"bruh meta element\")\n\n// A basic check for if a value is allowed as a meta node's child\n// It's responsible for quickly checking the type, not deep validation\nconst isMetaNodeChild = x =>\n // meta nodes, reactives, and DOM nodes\n x?.[isMetaNode] ||\n x?.[isReactive] ||\n x instanceof Node ||\n // Any array, just assume it contains valid children\n Array.isArray(x) ||\n // Allow nullish\n x == null ||\n // Disallow functions and objects\n !(typeof x === \"function\" || typeof x === \"object\")\n // Everything else can be a child when stringified\n\nconst toNode = x => {\n if (x[isMetaNode])\n return x.node\n\n if (x instanceof Node)\n return x\n\n return document.createTextNode(x)\n}\n\nexport const childrenToNodes = children =>\n children\n .flat(Infinity)\n .flatMap(child => {\n if (!child[isReactive])\n return [toNode(child)]\n\n if (Array.isArray(child.value)) {\n const liveFragment = new LiveFragment()\n child.addReaction(() => {\n liveFragment.replaceChildren(...childrenToNodes(child.value))\n })\n return [liveFragment.startMarker, ...childrenToNodes(child.value), liveFragment.endMarker]\n }\n\n let node = toNode(child.value)\n child.addReaction(() => {\n const oldNode = node\n node = toNode(child.value)\n oldNode.replaceWith(node)\n })\n return [node]\n })\n\n\n\n// Meta Nodes\n\nexport class MetaTextNode {\n [isMetaNode] = true;\n [isMetaTextNode] = true\n\n node\n\n constructor(textContent) {\n if (!textContent[isReactive]) {\n this.node = document.createTextNode(textContent)\n return\n }\n\n this.node = document.createTextNode(textContent.value)\n textContent.addReaction(() => {\n this.node.textContent = textContent.value\n })\n }\n\n addProperties(properties = {}) {\n Object.assign(this.node, properties)\n\n return this\n }\n}\n\nexport class MetaElement {\n [isMetaNode] = true;\n [isMetaElement] = true\n\n node\n\n constructor(name, namespace) {\n this.node =\n namespace\n ? document.createElementNS(namespace, name)\n : document.createElement ( name)\n }\n\n static from(element) {\n const result = new this(\"div\")\n result.node = element\n return result\n }\n\n addProperties(properties = {}) {\n Object.assign(this.node, properties)\n\n return this\n }\n\n addAttributes(attributes = {}) {\n for (const name in attributes)\n reactiveDo(attributes[name],\n maybeDo(\n value => this.node.setAttribute (name, value),\n () => this.node.removeAttribute(name)\n )\n )\n\n return this\n }\n\n addDataAttributes(dataAttributes = {}) {\n for (const name in dataAttributes)\n reactiveDo(dataAttributes[name],\n maybeDo(\n value => this.node.dataset[name] = value,\n () => delete this.node.dataset[name]\n )\n )\n\n return this\n }\n\n addStyles(styles = {}) {\n for (const property in styles)\n reactiveDo(styles[property],\n maybeDo(\n value => this.node.style.setProperty (property, value),\n () => this.node.style.removeProperty(property)\n )\n )\n\n return this\n }\n\n toggleClasses(classes = {}) {\n for (const name in classes)\n reactiveDo(classes[name],\n value => this.node.classList.toggle(name, value)\n )\n\n return this\n }\n\n before(...xs) {\n this.node.before(...childrenToNodes(xs))\n }\n\n prepend(...xs) {\n this.node.prepend(...childrenToNodes(xs))\n }\n\n append(...xs) {\n this.node.append(...childrenToNodes(xs))\n }\n\n after(...xs) {\n this.node.after(...childrenToNodes(xs))\n }\n\n replaceChildren(...xs) {\n this.node.replaceChildren(...childrenToNodes(xs))\n }\n\n replaceWith(...xs) {\n this.node.replaceWith(...childrenToNodes(xs))\n }\n}\n\n\n\n// Convenience functions\n\nexport const hydrateTextNodes = () => {\n const tagged = {}\n const bruhTextNodes = document.getElementsByTagName(\"bruh-textnode\")\n\n for (const bruhTextNode of bruhTextNodes) {\n const textNode = document.createTextNode(bruhTextNode.textContent)\n\n if (bruhTextNode.dataset.tag)\n tagged[bruhTextNode.dataset.tag] = textNode\n\n bruhTextNode.replaceWith(textNode)\n }\n\n return tagged\n}\n\nconst createMetaTextNode = textContent =>\n new MetaTextNode(textContent)\n\nconst createMetaElement = (name, namespace) => (...variadic) => {\n const meta = new MetaElement(name, namespace)\n\n // Implement optional attributes as first argument\n if (!isMetaNodeChild(variadic[0])) {\n const [attributes, ...children] = variadic\n meta.addAttributes(attributes)\n meta.append(children)\n }\n else {\n meta.append(variadic)\n }\n\n return meta\n}\n\n// JSX integration\nconst createMetaElementJSX = (nameOrComponent, attributesOrProps, ...children) => {\n // If we are making a html element\n // This is likely when the jsx tag name begins with a lowercase character\n if (typeof nameOrComponent == \"string\") {\n const meta = new MetaElement(nameOrComponent)\n\n // These are attributes then, but they might be null/undefined\n meta.addAttributes(attributesOrProps || {})\n meta.append(children)\n\n return meta\n }\n\n // It must be a component, then\n // Bruh components are just functions that return meta elements\n // Due to JSX, this would mean a function with only one parameter - a \"props\" object\n // This object includes the all of the attributes and a \"children\" key\n return nameOrComponent( Object.assign({}, attributesOrProps, { children }) )\n}\n\n// These will be called with short names\nexport {\n createMetaTextNode as t,\n createMetaElement as e,\n createMetaElementJSX as h\n}\n\n// The JSX fragment is made into a bruh fragment (just an array)\nexport const JSXFragment = ({ children }) => children\n"],"names":["isReactive"],"mappings":"woCAUO,OAAmB,CAAnB,cACL,qBAAc,SAAS,eAAe,KACtC,mBAAc,SAAS,eAAe,WAE/B,MAAK,EAAW,EAAU,CAC/B,KAAM,GAAe,GAAI,MACzB,SAAU,OAAO,EAAa,aAC9B,EAAS,MAAM,EAAa,WACrB,EAGT,UAAU,EAAI,CACZ,KAAK,YAAY,OAAO,GAAG,GAG7B,WAAW,EAAI,CACb,KAAK,YAAY,MAAM,GAAG,GAG5B,UAAU,EAAI,CACZ,KAAK,UAAU,OAAO,GAAG,GAG3B,SAAS,EAAI,CACX,KAAK,UAAU,MAAM,GAAG,GAG1B,QAAS,CACP,KAAM,GAAQ,SAAS,cACvB,EAAM,eAAe,KAAK,aAC1B,EAAM,YAAY,KAAK,WACvB,EAAM,iBAGR,mBAAmB,EAAI,CACrB,KAAM,GAAQ,SAAS,cACvB,EAAM,cAAc,KAAK,aACzB,EAAM,aAAa,KAAK,WACxB,EAAM,iBACN,KAAK,YAAY,MAAM,GAAG,GAG5B,eAAe,EAAI,CACjB,KAAK,UAAU,MAAM,GAAG,GACxB,KAAK,YAGH,aAAa,CACf,KAAM,GAAa,GAEnB,OACM,GAAc,KAAK,YAAY,YACnC,GAAe,KAAK,WAAa,EACjC,EAAc,EAAY,YAE1B,EAAW,KAAK,GAElB,MAAO,MAGL,WAAW,CACb,MAAO,MAAK,WACT,OAAO,GAAQ,YAAgB,kGCtEtC,KAAMA,GAAa,OAAO,IAAI,iBAGvB,OAAqB,CAM1B,YAAY,EAAO,CALlBA,UAAc,IAEf,iBACA,SAAa,GAAI,MAGf,OAAK,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GAAuB,CAAC,EAAiB,KAAsB,IAAa,CAGhF,GAAI,MAAO,IAAmB,SAAU,CACtC,KAAM,GAAO,GAAI,GAAY,GAG7B,SAAK,cAAc,GAAqB,IACxC,EAAK,OAAO,GAEL,EAOT,MAAO,GAAiB,OAAO,OAAO,GAAI,EAAmB,CAAE,eAWpD,GAAc,CAAC,CAAE,cAAe"}
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "library",
11
11
  "modern"
12
12
  ],
13
- "version": "1.9.1",
13
+ "version": "1.9.2-types.0",
14
14
  "license": "MIT",
15
15
  "author": {
16
16
  "name": "Daniel Ethridge",
@@ -0,0 +1,113 @@
1
+ import { Reactive } from "../reactive"
2
+
3
+ declare type MaybeReactiveRecord<T> = Record<string, T | Reactive<T>>
4
+
5
+ declare const isReactive: unique symbol
6
+ declare const isMetaNode: unique symbol
7
+ declare const isMetaTextNode: unique symbol
8
+ declare const isMetaElement: unique symbol
9
+
10
+ declare type Stringifyable = { toString: () => string }
11
+
12
+ declare type NonReactiveMetaNodeChild =
13
+ | MetaNode
14
+ | Node
15
+ | string
16
+ | number
17
+ | Array<NonReactiveMetaNodeChild>
18
+
19
+ export declare type MetaNodeChild =
20
+ | NonReactiveMetaNodeChild
21
+ | Reactive<NonReactiveMetaNodeChild>
22
+
23
+ export declare type childrenToNodes = (children: Array<MetaNodeChild>) => Array<Node>
24
+
25
+ export declare type MetaNode = {
26
+ [isMetaNode]: true
27
+ node: Node
28
+ addProperties: (properties: object) => MetaNode
29
+ }
30
+
31
+ export declare class MetaTextNode implements MetaNode {
32
+ constructor(value: string)
33
+
34
+ [isMetaNode]: true
35
+ [isMetaTextNode]: true
36
+ node: Text
37
+ addProperties: (properties: object) => MetaNode
38
+ }
39
+
40
+ export declare class MetaElement implements MetaNode {
41
+ constructor(name: string, namespace?: string)
42
+
43
+ static from: (element: Element) => MetaElement
44
+
45
+ [isMetaNode]: true
46
+ [isMetaElement]: true
47
+ node: Element
48
+ addProperties: (properties: object) => MetaNode
49
+
50
+ addAttributes: (attributes: MaybeReactiveRecord<Stringifyable | void>) => MetaNode
51
+ addDataAttributes: (dataAttributes: MaybeReactiveRecord<Stringifyable | void>) => MetaNode
52
+ addStyles: (styles: MaybeReactiveRecord<Stringifyable | void>) => MetaNode
53
+ toggleClasses: (classes: MaybeReactiveRecord<boolean>) => MetaNode
54
+
55
+ before: (...children: Array<MetaNodeChild>) => MetaNode
56
+ prepend: (...children: Array<MetaNodeChild>) => MetaNode
57
+ append: (...children: Array<MetaNodeChild>) => MetaNode
58
+ after: (...children: Array<MetaNodeChild>) => MetaNode
59
+ replaceChildren: (...children: Array<MetaNodeChild>) => MetaNode
60
+ replaceWith: (...children: Array<MetaNodeChild>) => MetaNode
61
+ }
62
+
63
+ export declare class MetaHTMLElement<Name extends keyof HTMLElementTagNameMap> extends MetaElement {
64
+ constructor(name: Name, namespace?: "http://www.w3.org/1999/xhtml")
65
+ node: HTMLElementTagNameMap[Name]
66
+ }
67
+ export declare class MetaSVGElement<Name extends keyof SVGElementTagNameMap> extends MetaElement {
68
+ constructor(name: Name, namespace: "http://www.w3.org/2000/svg")
69
+ node: SVGElementTagNameMap[Name]
70
+ }
71
+
72
+ export declare const hydrateTextNodes: () => Record<string, Text>
73
+
74
+ declare const createMetaTextNode: (value: string) => MetaTextNode
75
+
76
+ declare const createMetaElement: {
77
+ <Name extends keyof HTMLElementTagNameMap>
78
+ (name: Name, namespace?: "http://www.w3.org/1999/xhtml"): {
79
+ ( ...children: Array<MetaNodeChild>): MetaHTMLElement<Name>
80
+ (attributes: MaybeReactiveRecord<Stringifyable | void>, ...children: Array<MetaNodeChild>): MetaHTMLElement<Name>
81
+ }
82
+
83
+ <Name extends keyof SVGElementTagNameMap>
84
+ (name: Name, namespace: "http://www.w3.org/2000/svg"): {
85
+ ( ...children: Array<MetaNodeChild>): MetaSVGElement<Name>
86
+ (attributes: MaybeReactiveRecord<Stringifyable | void>, ...children: Array<MetaNodeChild>): MetaSVGElement<Name>
87
+ }
88
+
89
+ (name: string, namespace?: string): {
90
+ ( ...children: Array<MetaNodeChild>): MetaNode
91
+ (attributes: MaybeReactiveRecord<Stringifyable | void>, ...children: Array<MetaNodeChild>): MetaNode
92
+ }
93
+ }
94
+
95
+ declare const createMetaElementJSX: {
96
+ <Name extends keyof HTMLElementTagNameMap>
97
+ (name: Name, attributes: MaybeReactiveRecord<Stringifyable | void>, ...children: Array<MetaNodeChild>): MetaHTMLElement<Name>
98
+
99
+ <Props, Child, ReturnType>
100
+ (
101
+ component: (propsAndChildren: Props & { children: Array<Child> }) => ReturnType,
102
+ props: Props,
103
+ ...children: Array<Child>
104
+ ): ReturnType
105
+ }
106
+
107
+ export {
108
+ createMetaTextNode as t,
109
+ createMetaElement as e,
110
+ createMetaElementJSX as h
111
+ }
112
+
113
+ declare const JSXFragment: <Child>(argument: { children: Array<Child> }) => Array<Child>
@@ -1,3 +1,5 @@
1
+ /** @typedef { import("./index.browser") } */
2
+
1
3
  import { LiveFragment } from "./live-fragment.mjs"
2
4
  import { reactiveDo } from "../reactive/index.mjs"
3
5
  import { maybeDo } from "../util/index.mjs"
@@ -61,8 +63,8 @@ export const childrenToNodes = children =>
61
63
  // Meta Nodes
62
64
 
63
65
  export class MetaTextNode {
64
- [isMetaNode] = true;
65
- [isMetaElement] = true
66
+ [isMetaNode] = true;
67
+ [isMetaTextNode] = true
66
68
 
67
69
  node
68
70
 
@@ -6,11 +6,6 @@ export declare type Reactive<T> = {
6
6
  addReaction: (reaction: Function) => Function
7
7
  }
8
8
 
9
- export declare const reactiveDo: {
10
- <T>(reactive: Reactive<T>, f: (value: T) => unknown): Function
11
- <T>(value: T, f: (value: T) => unknown): void
12
- }
13
-
14
9
  export declare class SimpleReactive<T> implements Reactive<T> {
15
10
  constructor(value: T)
16
11
 
@@ -34,3 +29,8 @@ export declare const r: {
34
29
  <T>(value: T): FunctionalReactive<T>
35
30
  <T>(dependencies: Array<FunctionalReactive<unknown>>, f: () => T): FunctionalReactive<T>
36
31
  }
32
+
33
+ export declare const reactiveDo: {
34
+ <T>(reactive: Reactive<T>, f: (value: T) => unknown): Function
35
+ <T>(value: T, f: (value: T) => unknown): void
36
+ }
@@ -1,3 +1,5 @@
1
+ /** @typedef { import("./index") } */
2
+
1
3
  const isReactive = Symbol.for("bruh reactive")
2
4
 
3
5
  // A super simple and performant reactive value implementation