bruh 1.13.1 → 2.0.0-beta.1
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/browser/jsx-runtime.mjs +2 -0
- package/dist/browser/jsx-runtime.mjs.map +1 -0
- package/dist/browser.mjs +174 -0
- package/dist/browser.mjs.map +1 -0
- package/dist/cli/node.mjs +16 -0
- package/dist/cli/node.mjs.map +1 -0
- package/dist/components/aside-toc.mjs +162 -0
- package/dist/components/aside-toc.mjs.map +1 -0
- package/dist/components/custom-elements.mjs +52 -0
- package/dist/components/custom-elements.mjs.map +1 -0
- package/dist/components/intl/date-time.mjs +219 -0
- package/dist/components/intl/date-time.mjs.map +1 -0
- package/dist/components/intl/display-name.mjs +71 -0
- package/dist/components/intl/display-name.mjs.map +1 -0
- package/dist/components/intl/language-picker.mjs +102 -0
- package/dist/components/intl/language-picker.mjs.map +1 -0
- package/dist/components/intl/list.mjs +80 -0
- package/dist/components/intl/list.mjs.map +1 -0
- package/dist/components/intl/number.mjs +118 -0
- package/dist/components/intl/number.mjs.map +1 -0
- package/dist/components/intl/plural.mjs +82 -0
- package/dist/components/intl/plural.mjs.map +1 -0
- package/dist/components/intl/utils.mjs +197 -0
- package/dist/components/intl/utils.mjs.map +1 -0
- package/dist/components/optimized-picture/hydrate.mjs +10 -0
- package/dist/components/optimized-picture/hydrate.mjs.map +1 -0
- package/dist/components/optimized-picture/server.mjs +28 -0
- package/dist/components/optimized-picture/server.mjs.map +1 -0
- package/dist/components/utils.mjs +4 -0
- package/dist/components/utils.mjs.map +1 -0
- package/dist/media/images/node.mjs +41 -0
- package/dist/media/images/node.mjs.map +1 -0
- package/dist/polyfills/weakref.mjs +16 -0
- package/dist/polyfills/weakref.mjs.map +1 -0
- package/dist/reactive/sync/transport/websocket/browser.mjs +52 -0
- package/dist/reactive/sync/transport/websocket/browser.mjs.map +1 -0
- package/dist/reactive.mjs +160 -0
- package/dist/reactive.mjs.map +1 -0
- package/dist/server/jsx-runtime.mjs +2 -0
- package/dist/server/jsx-runtime.mjs.map +1 -0
- package/dist/server.mjs +346 -0
- package/dist/server.mjs.map +1 -0
- package/dist/types/cli/index.d.mts +2 -0
- package/dist/types/components/aside-toc/index.d.ts +45 -0
- package/dist/types/components/custom-elements.d.mts +83 -0
- package/dist/types/components/intl/date-time.d.ts +138 -0
- package/dist/types/components/intl/display-name.d.ts +45 -0
- package/dist/types/components/intl/language-picker.d.ts +35 -0
- package/dist/types/components/intl/list.d.ts +41 -0
- package/dist/types/components/intl/number.d.ts +81 -0
- package/dist/types/components/intl/plural.d.ts +60 -0
- package/dist/types/components/intl/utils.d.mts +30 -0
- package/dist/types/components/optimized-picture/hydrate.d.mts +2 -0
- package/dist/types/components/optimized-picture/server.d.ts +8 -0
- package/dist/types/components/utils.d.mts +5 -0
- package/dist/types/dom/browser/jsx-runtime.d.mts +3 -0
- package/dist/types/dom/index.browser.d.mts +127 -0
- package/dist/types/dom/index.server.d.mts +174 -0
- package/dist/types/dom/server/jsx-runtime.d.mts +3 -0
- package/dist/types/dom/types.d.mts +9 -0
- package/dist/types/media/images.node.d.mts +1 -0
- package/dist/types/polyfills/weakref.d.mts +4 -0
- package/dist/types/reactive/index.d.mts +91 -0
- package/dist/types/reactive/sync/transport/websocket/browser.d.mts +11 -0
- package/dist/types/utils/browser.d.mts +2 -0
- package/dist/types/utils/index.d.mts +122 -0
- package/dist/utils/browser.mjs +27 -0
- package/dist/utils/browser.mjs.map +1 -0
- package/dist/utils.mjs +287 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +122 -19
- package/dist/bruh.es.js +0 -226
- package/dist/bruh.es.js.map +0 -1
- package/dist/bruh.umd.js +0 -2
- package/dist/bruh.umd.js.map +0 -1
- package/src/cli/index.mjs +0 -19
- package/src/components/optimized-picture/hydrate.mjs +0 -10
- package/src/components/optimized-picture/render.mjs +0 -26
- package/src/dom/index.browser.mjs +0 -270
- package/src/dom/index.server.mjs +0 -280
- package/src/index.browser.mjs +0 -3
- package/src/media/images.node.mjs +0 -70
- package/src/reactive/index.mjs +0 -160
- package/src/util/index.mjs +0 -42
package/src/reactive/index.mjs
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
export const isReactive = Symbol.for("bruh reactive")
|
|
2
|
-
|
|
3
|
-
// A super simple and performant reactive value implementation
|
|
4
|
-
export class SimpleReactive {
|
|
5
|
-
[isReactive] = true
|
|
6
|
-
|
|
7
|
-
#value
|
|
8
|
-
#reactions = new Set()
|
|
9
|
-
|
|
10
|
-
constructor(value) {
|
|
11
|
-
this.#value = value
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
get value() {
|
|
15
|
-
return this.#value
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
set value(newValue) {
|
|
19
|
-
if (newValue === this.#value)
|
|
20
|
-
return
|
|
21
|
-
|
|
22
|
-
this.#value = newValue
|
|
23
|
-
for (const reaction of this.#reactions)
|
|
24
|
-
reaction()
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
addReaction(reaction) {
|
|
28
|
-
this.#reactions.add(reaction)
|
|
29
|
-
|
|
30
|
-
return () =>
|
|
31
|
-
this.#reactions.delete(reaction)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// A reactive implementation for building functional reactive graphs
|
|
36
|
-
// Ensures state consistency, minimal node updates, and transparent update batching
|
|
37
|
-
export class FunctionalReactive {
|
|
38
|
-
[isReactive] = true
|
|
39
|
-
|
|
40
|
-
#value
|
|
41
|
-
#reactions = new Set()
|
|
42
|
-
|
|
43
|
-
// For derived nodes, f is the derivation function
|
|
44
|
-
#f
|
|
45
|
-
// Source nodes are 0 deep in the derivation graph
|
|
46
|
-
// This is for topological sort
|
|
47
|
-
#depth = 0
|
|
48
|
-
// All nodes have a set of derivatives that update when the node changes
|
|
49
|
-
#derivatives = new Set()
|
|
50
|
-
|
|
51
|
-
// Keep track of all the pending changes from the value setter
|
|
52
|
-
static #settersQueue = new Map()
|
|
53
|
-
// A queue of derivatives to potentially update, sorted into sets by depth
|
|
54
|
-
// This starts with depth 1 and can potentially have holes
|
|
55
|
-
static #derivativesQueue = []
|
|
56
|
-
// A queue of reactions to run after the graph is fully updated
|
|
57
|
-
static #reactionsQueue = []
|
|
58
|
-
|
|
59
|
-
constructor(x, f) {
|
|
60
|
-
if (!f) {
|
|
61
|
-
this.#value = x
|
|
62
|
-
return
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
this.#value = f()
|
|
66
|
-
this.#f = f
|
|
67
|
-
this.#depth = Math.max(...x.map(d => d.#depth)) + 1
|
|
68
|
-
|
|
69
|
-
x.forEach(d => d.#derivatives.add(this))
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
get value() {
|
|
73
|
-
// If there are any pending updates
|
|
74
|
-
if (FunctionalReactive.#settersQueue.size) {
|
|
75
|
-
// Heuristic quick invalidation for derived nodes
|
|
76
|
-
// Apply updates now, it's ok that there's already a microtask queued for this
|
|
77
|
-
if (this.#depth !== 0)
|
|
78
|
-
FunctionalReactive.applyUpdates()
|
|
79
|
-
// If this is a source node that was updated, just return that
|
|
80
|
-
// new value without actually updating any derived nodes yet
|
|
81
|
-
else if (FunctionalReactive.#settersQueue.has(this))
|
|
82
|
-
return FunctionalReactive.#settersQueue.get(this)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return this.#value
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
set value(newValue) {
|
|
89
|
-
// Only allow source nodes to be directly updated
|
|
90
|
-
if (this.#depth !== 0)
|
|
91
|
-
return
|
|
92
|
-
|
|
93
|
-
// Unless asked for earlier, these updates are just queued up until the microtasks run
|
|
94
|
-
if (!FunctionalReactive.#settersQueue.size)
|
|
95
|
-
queueMicrotask(FunctionalReactive.applyUpdates)
|
|
96
|
-
|
|
97
|
-
FunctionalReactive.#settersQueue.set(this, newValue)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
addReaction(reaction) {
|
|
101
|
-
this.#reactions.add(reaction)
|
|
102
|
-
|
|
103
|
-
return () =>
|
|
104
|
-
this.#reactions.delete(reaction)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Apply an update for a node and queue its derivatives if it actually changed
|
|
108
|
-
#applyUpdate(newValue) {
|
|
109
|
-
if (newValue === this.#value)
|
|
110
|
-
return
|
|
111
|
-
|
|
112
|
-
this.#value = newValue
|
|
113
|
-
FunctionalReactive.#reactionsQueue.push(...this.#reactions)
|
|
114
|
-
|
|
115
|
-
const queue = FunctionalReactive.#derivativesQueue
|
|
116
|
-
for (const derivative of this.#derivatives) {
|
|
117
|
-
const depth = derivative.#depth
|
|
118
|
-
if (!queue[depth])
|
|
119
|
-
queue[depth] = new Set()
|
|
120
|
-
|
|
121
|
-
queue[depth].add(derivative)
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// Apply pending updates from actually changed source nodes
|
|
126
|
-
static applyUpdates() {
|
|
127
|
-
if (!FunctionalReactive.#settersQueue.size)
|
|
128
|
-
return
|
|
129
|
-
|
|
130
|
-
// Bootstrap by applying the updates from the pending setters
|
|
131
|
-
for (const [sourceNode, newValue] of FunctionalReactive.#settersQueue.entries())
|
|
132
|
-
sourceNode.#applyUpdate(newValue)
|
|
133
|
-
FunctionalReactive.#settersQueue.clear()
|
|
134
|
-
|
|
135
|
-
// Iterate down the depths, ignoring holes
|
|
136
|
-
// Note that both the queue (Array) and each depth Set iterators update as items are added
|
|
137
|
-
for (const depthSet of FunctionalReactive.#derivativesQueue) if (depthSet)
|
|
138
|
-
for (const derivative of depthSet)
|
|
139
|
-
derivative.#applyUpdate(derivative.#f())
|
|
140
|
-
FunctionalReactive.#derivativesQueue.length = 0
|
|
141
|
-
|
|
142
|
-
// Call all reactions now that the graph has a fully consistent state
|
|
143
|
-
for (const reaction of FunctionalReactive.#reactionsQueue)
|
|
144
|
-
reaction()
|
|
145
|
-
FunctionalReactive.#reactionsQueue.length = 0
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// A little convenience function
|
|
150
|
-
export const r = (x, f) => new FunctionalReactive(x, f)
|
|
151
|
-
|
|
152
|
-
// Do something with a value, updating if it is reactive
|
|
153
|
-
export const reactiveDo = (x, f) => {
|
|
154
|
-
if (x?.[isReactive]) {
|
|
155
|
-
f(x.value)
|
|
156
|
-
return x.addReaction(() => f(x.value))
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
f(x)
|
|
160
|
-
}
|
package/src/util/index.mjs
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
// Create a pipeline with an initial value and a series of functions
|
|
2
|
-
export const pipe = (x, ...fs) =>
|
|
3
|
-
fs.reduce((y, f) => f(y), x)
|
|
4
|
-
|
|
5
|
-
// Dispatch a custom event to (capturing) and from (bubbling) a target (usually a DOM node)
|
|
6
|
-
// Returns false if the event was cancelled (preventDefault()) and true otherwise
|
|
7
|
-
// Note that this is synchronous
|
|
8
|
-
export const dispatch = (target, type, options) =>
|
|
9
|
-
target.dispatchEvent(
|
|
10
|
-
// Default to behave like most DOM events
|
|
11
|
-
new CustomEvent(type, {
|
|
12
|
-
bubbles: true,
|
|
13
|
-
cancelable: true,
|
|
14
|
-
composed: true,
|
|
15
|
-
...options
|
|
16
|
-
})
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
// Inspired by https://antfu.me/posts/destructuring-with-object-or-array#take-away
|
|
20
|
-
// Creates an object that is both destructable with {...} and [...]
|
|
21
|
-
// Useful for writing library functions à la react-use & vueuse
|
|
22
|
-
export const createDestructable = (object, iterable) => {
|
|
23
|
-
const destructable = {
|
|
24
|
-
...object,
|
|
25
|
-
[Symbol.iterator]: () => iterable[Symbol.iterator]()
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
Object.defineProperty(destructable, Symbol.iterator, {
|
|
29
|
-
enumerable: false
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
return destructable
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Creates an object (as a Proxy) that acts as a function
|
|
36
|
-
// So functionAsObject(f).property is equivalent to f("property")
|
|
37
|
-
// This is can be useful when combined with destructuring syntax, e.g.:
|
|
38
|
-
// const { html, head, title, body, main, h1, p } = functionAsObject(e)
|
|
39
|
-
export const functionAsObject = f =>
|
|
40
|
-
new Proxy({}, {
|
|
41
|
-
get: (_, property) => f(property)
|
|
42
|
-
})
|