lilact 0.31.15 → 0.31.18

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.
Files changed (54) hide show
  1. package/bin/bundle.cjs +1 -1
  2. package/dist/lilact.development.js +406 -393
  3. package/dist/lilact.development.js.map +4 -4
  4. package/dist/lilact.development.min.js +35 -35
  5. package/dist/lilact.development.min.js.map +4 -4
  6. package/dist/lilact.production.min.js +38 -38
  7. package/docs/assets/hierarchy.js +1 -1
  8. package/docs/assets/navigation.js +1 -1
  9. package/docs/assets/search.js +1 -1
  10. package/docs/classes/accessories.ErrorBoundary.html +11 -11
  11. package/docs/classes/accessories.Suspense.html +10 -10
  12. package/docs/classes/components.Component.html +11 -11
  13. package/docs/classes/components.HTMLComponent.html +11 -11
  14. package/docs/classes/components.RootComponent.html +11 -11
  15. package/docs/functions/accessories.DragHandle.html +1 -1
  16. package/docs/functions/accessories.Spinner.html +1 -1
  17. package/docs/functions/components.cloneComponent.html +1 -1
  18. package/docs/functions/components.createComponent.html +1 -1
  19. package/docs/functions/components.createPortal.html +1 -1
  20. package/docs/functions/components.createRoot.html +1 -1
  21. package/docs/functions/components.memo.html +1 -1
  22. package/docs/functions/components.render.html +1 -1
  23. package/docs/functions/hooks.useLocalStorage.html +2 -2
  24. package/docs/functions/run.lazy.html +1 -1
  25. package/docs/functions/run.require.html +1 -1
  26. package/docs/functions/run.run.html +1 -1
  27. package/docs/functions/run.runScripts.html +1 -1
  28. package/docs/hierarchy.html +1 -1
  29. package/docs/modules/components.html +1 -1
  30. package/docs/static/index.html +1 -1
  31. package/docs/static/lilact.development.js +406 -393
  32. package/docs/static/lilact.development.js.map +4 -4
  33. package/docs/static/lilact.development.min.js +35 -35
  34. package/docs/static/lilact.development.min.js.map +4 -4
  35. package/docs/static/lilact.production.min.js +38 -38
  36. package/docs/variables/accessories.SplitPane.html +1 -1
  37. package/docs/variables/components.cloneElement.html +1 -1
  38. package/examples/index.html +1 -1
  39. package/examples/lilact.development.js +406 -393
  40. package/examples/lilact.development.js.map +4 -4
  41. package/examples/lilact.development.min.js +35 -35
  42. package/examples/lilact.development.min.js.map +4 -4
  43. package/examples/lilact.production.min.js +38 -38
  44. package/package.json +2 -2
  45. package/scripts/build.mjs +1 -1
  46. package/src/accessories.jsx +4 -2
  47. package/src/cache.jsx +299 -0
  48. package/src/components.jsx +6 -1042
  49. package/src/core.jsx +794 -0
  50. package/src/hooks.jsx +2 -2
  51. package/src/run.jsx +2 -1
  52. package/src/symbols.jsx +0 -2
  53. package/docs/functions/components.replaceAllComponentInstances.html +0 -1
  54. package/docs/functions/components.replaceComponentEntity.html +0 -1
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "lilact",
3
- "version": "0.31.15",
3
+ "version": "0.31.18",
4
4
  "description": "A Little React/JSX Runtime Implementation for Browser",
5
5
  "repository": "github:arashkazemi/lilact",
6
- "homepage": "https://arashkazemi.github.io/lilact/",
6
+ "homepage": "https://lilact.dev",
7
7
  "keywords": [
8
8
  "jsx",
9
9
  "transpiler",
package/scripts/build.mjs CHANGED
@@ -104,7 +104,7 @@ await esbuild.build({
104
104
  platform: "browser",
105
105
 
106
106
  outfile: `dist/${outFile}`,
107
- target: "es2020",
107
+ target: "es2018",
108
108
  sourcemap: mode === "development",
109
109
 
110
110
  minify,
@@ -32,7 +32,9 @@
32
32
  import { useEffect, useLayoutEffect, useMemo, useRef, useState, useImperativeHandle, useCallback } from "./hooks.jsx";
33
33
  import { Children, forwardRef, isThenable } from "./misc.jsx";
34
34
 
35
- import {Component} from "./components.jsx"
35
+ import {Component} from "./components.jsx";
36
+
37
+ import {cx} from "@emotion/css";
36
38
 
37
39
  /**
38
40
  * A CSS-only loading spinner component.
@@ -787,7 +789,7 @@ export const SplitPane = forwardRef(function SplitPane(
787
789
  return (
788
790
  <div
789
791
  ref={containerRef}
790
- className={className}
792
+ className={cx(className, dragging && 'dragging')}
791
793
  style={{
792
794
  position: "relative",
793
795
  width: "100%",
package/src/cache.jsx ADDED
@@ -0,0 +1,299 @@
1
+ /*
2
+
3
+ Lilact
4
+ Copyright (C) 2024-2026 Arash Kazemi <contact.arash.kazemi@gmail.com>
5
+ All rights reserved.
6
+
7
+ BSD-2-Clause
8
+
9
+ Redistribution and use in source and binary forms, with or without
10
+ modification, are permitted provided that the following conditions are met:
11
+
12
+ * Redistributions of source code must retain the above copyright
13
+ notice, this list of conditions and the following disclaimer.
14
+ * Redistributions in binary form must reproduce the above copyright
15
+ notice, this list of conditions and the following disclaimer in the
16
+ documentation and/or other materials provided with the distribution.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
+ ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
22
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+
29
+ */
30
+
31
+ import Lilact, {isClass} from './lilact.jsx';
32
+
33
+ import { IDX, MEMOIZED } from "./symbols.jsx"
34
+
35
+
36
+ function getComponentEntity(entity) {
37
+ return entity?.[MEMOIZED] ? entity.component : entity;
38
+ }
39
+
40
+ const hotEntityAliases = new Map();
41
+ const hotEntityCacheTokens = new WeakMap();
42
+
43
+ function getHotEntityCacheToken(entity) {
44
+ entity = getComponentEntity(entity);
45
+
46
+ if (typeof entity !== "function") {
47
+ return entity;
48
+ }
49
+
50
+ let token = hotEntityCacheTokens.get(entity);
51
+
52
+ if (!token) {
53
+ const resolved = resolveHotEntity(entity);
54
+ token = hotEntityCacheTokens.get(resolved) || {};
55
+ hotEntityCacheTokens.set(entity, token);
56
+ hotEntityCacheTokens.set(resolved, token);
57
+ }
58
+
59
+ return token;
60
+ }
61
+
62
+ export function resolveHotEntity(entity) {
63
+ entity = getComponentEntity(entity);
64
+
65
+ const visited = new Set();
66
+
67
+ while (
68
+ typeof entity === "function" &&
69
+ hotEntityAliases.has(entity) &&
70
+ !visited.has(entity)
71
+ ) {
72
+ visited.add(entity);
73
+ entity = hotEntityAliases.get(entity);
74
+ }
75
+
76
+ return entity;
77
+ }
78
+
79
+ const componentInstances = new Map();
80
+
81
+ export function registerComponentCore(core) {
82
+ const entity = getComponentEntity(core.entity);
83
+
84
+ if (typeof entity !== "function") return;
85
+
86
+ let instances = componentInstances.get(entity);
87
+
88
+ if (!instances) {
89
+ instances = new Set();
90
+ componentInstances.set(entity, instances);
91
+ }
92
+
93
+ instances.add(core);
94
+ core.registered_entity = entity;
95
+ }
96
+
97
+ export function unregisterComponentCore(core) {
98
+ const entity = core.registered_entity;
99
+ if (!entity) return;
100
+
101
+ const instances = componentInstances.get(entity);
102
+
103
+ if (instances) {
104
+ instances.delete(core);
105
+
106
+ if (instances.size === 0) {
107
+ componentInstances.delete(entity);
108
+ }
109
+ }
110
+
111
+ delete core.registered_entity;
112
+ }
113
+
114
+ function moveComponentCore(core, oldEntity, newEntity) {
115
+ const oldInstances = componentInstances.get(oldEntity);
116
+
117
+ if (oldInstances) {
118
+ oldInstances.delete(core);
119
+
120
+ if (oldInstances.size === 0) {
121
+ componentInstances.delete(oldEntity);
122
+ }
123
+ }
124
+
125
+ let newInstances = componentInstances.get(newEntity);
126
+
127
+ if (!newInstances) {
128
+ newInstances = new Set();
129
+ componentInstances.set(newEntity, newInstances);
130
+ }
131
+
132
+ newInstances.add(core);
133
+ core.registered_entity = newEntity;
134
+ }
135
+
136
+ function replaceComponentEntity(componentCore, nextEntity) {
137
+ if (!componentCore || typeof nextEntity !== "function") {
138
+ return false;
139
+ }
140
+
141
+ const oldEntity = getComponentEntity(componentCore.entity);
142
+ const newEntity = resolveHotEntity(nextEntity);
143
+
144
+ const cacheToken = hotEntityCacheTokens.get(oldEntity) || hotEntityCacheTokens.get(newEntity) || {};
145
+
146
+ hotEntityCacheTokens.set(oldEntity, cacheToken);
147
+ hotEntityCacheTokens.set(newEntity, cacheToken);
148
+
149
+ if (oldEntity === newEntity) {
150
+ return true;
151
+ }
152
+
153
+ const component = componentCore.component;
154
+
155
+ if (!component) {
156
+ return false;
157
+ }
158
+
159
+ if (
160
+ typeof oldEntity !== "function" ||
161
+ typeof newEntity !== "function" ||
162
+ isClass(oldEntity) !== isClass(newEntity)
163
+ ) {
164
+ return false;
165
+ }
166
+
167
+ if (isClass(newEntity)) {
168
+ Object.setPrototypeOf(component, newEntity.prototype);
169
+ } else {
170
+ component.render = newEntity.bind(component);
171
+ }
172
+
173
+ componentCore.entity = newEntity;
174
+ moveComponentCore(componentCore, oldEntity, newEntity);
175
+
176
+ return true;
177
+ }
178
+
179
+ export function replaceAllComponentInstances(oldEntity, newEntity)
180
+ {
181
+ oldEntity = getComponentEntity(oldEntity);
182
+ newEntity = getComponentEntity(newEntity);
183
+
184
+ if (
185
+ typeof oldEntity !== "function" ||
186
+ typeof newEntity !== "function"
187
+ ) {
188
+ return 0;
189
+ }
190
+
191
+ newEntity = resolveHotEntity(newEntity);
192
+
193
+ if (oldEntity === newEntity) {
194
+ return 0;
195
+ }
196
+
197
+ const cacheToken = hotEntityCacheTokens.get(oldEntity) || hotEntityCacheTokens.get(newEntity) || {};
198
+
199
+ hotEntityCacheTokens.set(oldEntity, cacheToken);
200
+ hotEntityCacheTokens.set(newEntity, cacheToken);
201
+
202
+ hotEntityAliases.set(oldEntity, newEntity);
203
+
204
+ const instances = componentInstances.get(oldEntity);
205
+
206
+ if (!instances) {
207
+ return 0;
208
+ }
209
+
210
+ let count = 0;
211
+
212
+ for (const core of [...instances]) {
213
+ if (!replaceComponentEntity(core, newEntity)) {
214
+ continue;
215
+ }
216
+
217
+ core.apply(core.props, core.state);
218
+ count++;
219
+ }
220
+
221
+ return count;
222
+ }
223
+
224
+
225
+
226
+ export class ComponentCache
227
+ {
228
+ owner;
229
+ current_map = new Map;
230
+ new_map = new Map;
231
+ pick_index = 0;
232
+
233
+ constructor(owner)
234
+ {
235
+ this.owner = owner;
236
+ }
237
+
238
+ pick(key, construct_func, nextEntity) {
239
+ let componentCore;
240
+ let bucket = this.current_map.get(key);
241
+
242
+ if (bucket && bucket.length > bucket[IDX]) {
243
+ componentCore = bucket[bucket[IDX]];
244
+ bucket[IDX]++;
245
+
246
+ const oldEntity = getComponentEntity(componentCore.entity);
247
+ const newEntity = resolveHotEntity(nextEntity);
248
+
249
+ const incompatible =
250
+ typeof oldEntity !== typeof newEntity ||
251
+ (
252
+ typeof oldEntity === "function" &&
253
+ isClass(oldEntity) !== isClass(newEntity)
254
+ );
255
+
256
+ if (incompatible) {
257
+ componentCore = construct_func();
258
+ } else if (newEntity) {
259
+ replaceComponentEntity(componentCore, newEntity);
260
+ }
261
+ } else {
262
+ componentCore = construct_func();
263
+ }
264
+
265
+ bucket = this.new_map.get(key);
266
+
267
+ if (bucket) {
268
+ bucket.push(componentCore);
269
+ } else {
270
+ bucket = [componentCore];
271
+ this.new_map.set(key, bucket);
272
+ bucket[IDX] = 0;
273
+ }
274
+
275
+ if (componentCore) {
276
+ componentCore.parent ??= this.owner;
277
+ }
278
+
279
+ return componentCore;
280
+ }
281
+
282
+ commit()
283
+ {
284
+ this.current_map.forEach( (arr)=>{
285
+ arr.slice(arr[IDX]).forEach((ex)=>{
286
+ if(ex.cleanup) {
287
+ ex.cleanup();
288
+ }
289
+ if(ex.element && !ex.portal) {
290
+ ex.element?.remove?.();
291
+ }
292
+ });
293
+ });
294
+
295
+ this.current_map = this.new_map;
296
+ this.new_map = new Map;
297
+ }
298
+
299
+ }