lilact 0.14.2 → 0.15.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.
Files changed (65) hide show
  1. package/dist/lilact.development.js +326 -221
  2. package/dist/lilact.development.js.map +1 -1
  3. package/dist/lilact.development.min.js +1 -1
  4. package/dist/lilact.development.min.js.LICENSE.txt +6 -0
  5. package/dist/lilact.development.min.js.map +1 -1
  6. package/dist/lilact.production.min.js +1 -1
  7. package/dist/lilact.production.min.js.map +1 -1
  8. package/docs/classes/accessories.ErrorBoundary.html +11 -11
  9. package/docs/classes/accessories.Suspense.html +10 -10
  10. package/docs/classes/components.Component.html +11 -11
  11. package/docs/classes/components.HTMLComponent.html +11 -11
  12. package/docs/classes/components.RootComponent.html +11 -11
  13. package/docs/functions/accessories.DragHandle.html +1 -1
  14. package/docs/functions/accessories.Spinner.html +1 -1
  15. package/docs/functions/components.createComponent.html +1 -1
  16. package/docs/functions/components.createRoot.html +1 -1
  17. package/docs/functions/components.render.html +1 -1
  18. package/docs/functions/hooks.createContext.html +1 -1
  19. package/docs/functions/hooks.useActionState.html +1 -1
  20. package/docs/functions/hooks.useCallback.html +1 -1
  21. package/docs/functions/hooks.useContext.html +1 -1
  22. package/docs/functions/hooks.useDeferredValue.html +1 -1
  23. package/docs/functions/hooks.useEffect.html +1 -1
  24. package/docs/functions/hooks.useHook.html +1 -1
  25. package/docs/functions/hooks.useId.html +1 -1
  26. package/docs/functions/hooks.useImperativeHandle.html +1 -1
  27. package/docs/functions/hooks.useLayoutEffect.html +1 -1
  28. package/docs/functions/hooks.useLocalStorage.html +1 -1
  29. package/docs/functions/hooks.useMemo.html +1 -1
  30. package/docs/functions/hooks.useReducer.html +1 -1
  31. package/docs/functions/hooks.useRef.html +1 -1
  32. package/docs/functions/hooks.useState.html +1 -1
  33. package/docs/functions/hooks.useTransition.html +1 -1
  34. package/docs/functions/redux.Provider.html +1 -1
  35. package/docs/functions/redux.combineReducers.html +1 -1
  36. package/docs/functions/redux.connect.html +1 -1
  37. package/docs/functions/redux.useDispatch.html +1 -1
  38. package/docs/functions/redux.useSelector.html +1 -1
  39. package/docs/functions/redux.useStore.html +1 -1
  40. package/docs/functions/run.lazy.html +1 -1
  41. package/docs/functions/run.require.html +3 -3
  42. package/docs/functions/run.run.html +1 -1
  43. package/docs/functions/run.runScripts.html +3 -3
  44. package/docs/functions/timers.timeoutPromise.html +133 -2
  45. package/docs/static/lilact.development.js +326 -221
  46. package/docs/static/lilact.development.min.js +1 -1
  47. package/docs/static/lilact.production.min.js +1 -1
  48. package/docs/variables/accessories.SplitPane.html +1 -1
  49. package/package.json +1 -1
  50. package/root/lilact.development.js +326 -221
  51. package/root/lilact.development.min.js +1 -1
  52. package/root/lilact.production.min.js +1 -1
  53. package/src/accessories.jsx +14 -17
  54. package/src/components.jsx +6 -7
  55. package/src/hooks.jsx +25 -24
  56. package/src/lilact.jsx +8 -8
  57. package/src/loader.cjs +1 -1
  58. package/src/misc.jsx +1 -4
  59. package/src/redux.jsx +13 -11
  60. package/src/router.jsx +1 -1
  61. package/src/run.jsx +19 -16
  62. package/src/symbols.jsx +64 -0
  63. package/src/timers.jsx +6 -6
  64. package/src/transition.jsx +4 -4
  65. package/webpack.config.js +7 -3
@@ -29,14 +29,11 @@
29
29
  */
30
30
 
31
31
 
32
- import { useEffect, useLayoutEffect, useMemo, useRef, useState, useImperativeHandle } from "./hooks.jsx";
33
- import { Children, forwardRef } from "./misc.jsx";
32
+ import { useEffect, useLayoutEffect, useMemo, useRef, useState, useImperativeHandle, useCallback } from "./hooks.jsx";
33
+ import { Children, forwardRef, isThenable } from "./misc.jsx";
34
34
 
35
-
36
- import {isThenable} from "./misc.jsx"
37
35
  import {setTimeout, clearTimeout} from "./timers.jsx"
38
36
  import {Component} from "./components.jsx"
39
- import {useCallback} from './hooks.jsx'
40
37
  import {emotion} from "./lilact.jsx"
41
38
  const {css,cx} = emotion;
42
39
 
@@ -167,7 +164,7 @@ export class Suspense extends Component
167
164
 
168
165
  /** @ignore */
169
166
  static getDerivedStateFromError(error) {
170
- if (Lilact.isThenable(error)) {
167
+ if (isThenable(error)) {
171
168
  // signal to call componentDidCatch where we handle the thenable
172
169
  return null;
173
170
  }
@@ -177,7 +174,7 @@ export class Suspense extends Component
177
174
 
178
175
  /** @ignore */
179
176
  componentDidCatch(error) {
180
- if (!Lilact.isThenable(error)) return;
177
+ if (!isThenable(error)) return;
181
178
 
182
179
  const promise = error;
183
180
 
@@ -191,10 +188,10 @@ export class Suspense extends Component
191
188
  const delay = Math.max(0, this.props.minDelay);
192
189
  // Ensure no leftover timers
193
190
  if (this._delayTimer) {
194
- Lilact.clearTimeout(this._delayTimer);
191
+ clearTimeout(this._delayTimer);
195
192
  this._delayTimer = null;
196
193
  }
197
- this._delayTimer = Lilact.setTimeout(() => {
194
+ this._delayTimer = setTimeout(() => {
198
195
  this._delayTimer = null;
199
196
  this._fallbackShownAt = Date.now();
200
197
  this.setState({ showingFallback: true });
@@ -211,11 +208,11 @@ export class Suspense extends Component
211
208
  /** @ignore */
212
209
  _clearTimers() {
213
210
  if (this._delayTimer) {
214
- Lilact.clearTimeout(this._delayTimer);
211
+ clearTimeout(this._delayTimer);
215
212
  this._delayTimer = null;
216
213
  }
217
214
  if (this._minShowTimer) {
218
- Lilact.clearTimeout(this._minShowTimer);
215
+ clearTimeout(this._minShowTimer);
219
216
  this._minShowTimer = null;
220
217
  }
221
218
  }
@@ -228,10 +225,10 @@ export class Suspense extends Component
228
225
  if (this._pending.size === 1) {
229
226
  const delay = Math.max(0, this.props.minDelay);
230
227
  if (this._delayTimer) {
231
- Lilact.clearTimeout(this._delayTimer);
228
+ clearTimeout(this._delayTimer);
232
229
  this._delayTimer = null;
233
230
  }
234
- this._delayTimer = Lilact.setTimeout(() => {
231
+ this._delayTimer = setTimeout(() => {
235
232
  this._delayTimer = null;
236
233
  this._fallbackShownAt = Date.now();
237
234
  this.setState({ showingFallback: true });
@@ -247,7 +244,7 @@ export class Suspense extends Component
247
244
  if (this._pending.size === 0) {
248
245
  // cancel delay if fallback hasn't shown yet
249
246
  if (this._delayTimer) {
250
- Lilact.clearTimeout(this._delayTimer);
247
+ clearTimeout(this._delayTimer);
251
248
  this._delayTimer = null;
252
249
  // fallback never shown; just ensure state is not showing
253
250
  this.setState({ showingFallback: false });
@@ -262,10 +259,10 @@ export class Suspense extends Component
262
259
  this.setState({ showingFallback: false });
263
260
  } else {
264
261
  if (this._minShowTimer) {
265
- Lilact.clearTimeout(this._minShowTimer);
262
+ clearTimeout(this._minShowTimer);
266
263
  this._minShowTimer = null;
267
264
  }
268
- this._minShowTimer = Lilact.setTimeout(() => {
265
+ this._minShowTimer = setTimeout(() => {
269
266
  this._minShowTimer = null;
270
267
  this.setState({ showingFallback: false });
271
268
  }, remaining);
@@ -279,7 +276,7 @@ export class Suspense extends Component
279
276
 
280
277
  /** @ignore */
281
278
  componentDidCatch(error, info) {
282
- if (!Lilact.isThenable(error)) return;
279
+ if (!isThenable(error)) return;
283
280
  this._attachPromise(error);
284
281
  }
285
282
 
@@ -28,9 +28,8 @@
28
28
 
29
29
  */
30
30
 
31
- ʔ defineSymbols ( "LILACT", [ "CORE", "COMPONENT", "TEXT", "IS_ZOMBIE", "IDX", "CHILD_CLASS_ADDENDUM", "MEMOIZED"] ) ʔ
32
-
33
- import {shallowEqual} from "./misc.jsx";
31
+ import { CORE, COMPONENT, TEXT, IS_ZOMBIE, IDX, CHILD_CLASS_ADDENDUM, MEMOIZED } from "./symbols.jsx"
32
+ import { shallowEqual } from "./misc.jsx";
34
33
 
35
34
  /*
36
35
  ComponentCache is for internal use. It is the heart of the JSX runtime,
@@ -163,7 +162,7 @@ class ComponentCore
163
162
  // }
164
163
 
165
164
  /*if(do_rerender)*/ {
166
- ʔ if(DEBUG) {
165
+ if(DEBUG) {
167
166
 
168
167
  if(this.entity?.propTypes) {
169
168
  Lilact.PropTypes.checkPropTypes(this.entity.propTypes, this.props, 'prop', this.entity.name);
@@ -172,7 +171,7 @@ class ComponentCore
172
171
  Lilact.PropTypes.checkPropTypes(this.component.propTypes, this.props, 'prop', this.component.name);
173
172
  }
174
173
 
175
- ʔ }
174
+ }
176
175
  if(typeof(next_state)==='function') next_state = next_state(this.state);
177
176
 
178
177
  if(this.component.constructor.defaultProps) {
@@ -473,9 +472,9 @@ class ComponentCore
473
472
  this.element.onsubmit = undefined;
474
473
  }
475
474
 
476
- ʔ if(DEBUG) {
475
+ if(DEBUG) {
477
476
  //this.element.setAttribute('key', this.props.key);
478
- ʔ }
477
+ }
479
478
 
480
479
  this.updateElementClass(patch);
481
480
  }
package/src/hooks.jsx CHANGED
@@ -28,7 +28,9 @@
28
28
 
29
29
  */
30
30
 
31
- ʔ defineSymbols ( "LILACT", [ "CORE", "COMPONENT" ] ) ʔ
31
+ import { isEmpty } from "./misc.jsx"
32
+
33
+ import { CORE, COMPONENT } from "./symbols.jsx"
32
34
 
33
35
 
34
36
  /**
@@ -57,9 +59,9 @@ export function useHook()
57
59
  */
58
60
  export function useState(initialValue)
59
61
  {
60
- const hk = Lilact.useHook();
62
+ const hk = useHook();
61
63
 
62
- if( Lilact.isEmpty(hk) ) {
64
+ if( isEmpty(hk) ) {
63
65
  if(typeof(initialValue)==='function') hk.value = initialValue();
64
66
  else hk.value = initialValue;
65
67
 
@@ -88,9 +90,9 @@ export function useCallback(callback, deps=undefined)
88
90
  throw new Error("Callback dependencies must be an array or omitted.");
89
91
  }
90
92
 
91
- const hk = Lilact.useHook();
93
+ const hk = useHook();
92
94
 
93
- if( !Lilact.isEmpty(hk) ) {
95
+ if( !isEmpty(hk) ) {
94
96
  if(deps!==undefined && hk?.deps!==undefined && Lilact.shallowEqual(deps, hk.deps)) {
95
97
  return hk.callback;
96
98
  }
@@ -154,9 +156,9 @@ export function useContext(context)
154
156
  */
155
157
  export function useId(prefix="N")
156
158
  {
157
- const hk = Lilact.useHook();
159
+ const hk = useHook();
158
160
 
159
- if( Lilact.isEmpty(hk) ) {
161
+ if( isEmpty(hk) ) {
160
162
  hk.id = prefix+Lilact.id_num++;
161
163
  }
162
164
 
@@ -170,9 +172,9 @@ export function useId(prefix="N")
170
172
  */
171
173
  export function useTransition()
172
174
  {
173
- const hk = Lilact.useHook();
175
+ const hk = useHook();
174
176
 
175
- if( Lilact.isEmpty(hk) ) {
177
+ if( isEmpty(hk) ) {
176
178
  hk.count=0;
177
179
 
178
180
  hk.func =
@@ -210,7 +212,7 @@ export function useTransition()
210
212
  export function useLocalStorage(key, initialValue)
211
213
  {
212
214
 
213
- const hk = Lilact.useHook();
215
+ const hk = useHook();
214
216
  let val;
215
217
 
216
218
  try {
@@ -225,7 +227,7 @@ export function useLocalStorage(key, initialValue)
225
227
  localStorage[key] = JSON.stringify(val);
226
228
  }
227
229
 
228
- if( Lilact.isEmpty(hk) ) {
230
+ if( isEmpty(hk) ) {
229
231
  hk.value = val;
230
232
  hk.set_func = function(core, hk, val) {
231
233
 
@@ -253,9 +255,9 @@ export function useLocalStorage(key, initialValue)
253
255
  */
254
256
  export function useRef(initialValue = null)
255
257
  {
256
- const hk = Lilact.useHook();
258
+ const hk = useHook();
257
259
 
258
- if( Lilact.isEmpty(hk) ) {
260
+ if( isEmpty(hk) ) {
259
261
  hk.current = initialValue;
260
262
  }
261
263
 
@@ -275,9 +277,9 @@ export function useLayoutEffect(effect, deps=undefined)
275
277
  throw new Error("Layout effect dependencies must be an array or omitted.");
276
278
  }
277
279
 
278
- const hk = Lilact.useHook();
280
+ const hk = useHook();
279
281
 
280
- if( !Lilact.isEmpty(hk) ) {
282
+ if( !isEmpty(hk) ) {
281
283
  if(deps!==undefined && hk?.deps!==undefined && Lilact.shallowEqual(deps, hk.deps)) return;
282
284
  }
283
285
 
@@ -303,9 +305,9 @@ export function useEffect(effect, deps=undefined)
303
305
  throw new Error("Effect dependencies must be an array or omitted.");
304
306
  }
305
307
 
306
- const hk = Lilact.useHook();
308
+ const hk = useHook();
307
309
 
308
- if( !Lilact.isEmpty(hk) ) {
310
+ if( !isEmpty(hk) ) {
309
311
  if(deps!==undefined && hk?.deps!==undefined && Lilact.shallowEqual(deps, hk.deps)) return;
310
312
  }
311
313
 
@@ -331,9 +333,9 @@ export function useMemo(factory,deps=undefined)
331
333
  throw new Error("Memo dependencies must be an array or omitted.");
332
334
  }
333
335
 
334
- const hk = Lilact.useHook();
336
+ const hk = useHook();
335
337
 
336
- if( !Lilact.isEmpty(hk) ) {
338
+ if( !isEmpty(hk) ) {
337
339
  if(deps!==undefined && hk?.deps!==undefined && Lilact.shallowEqual(deps, hk.deps)) {
338
340
  return hk.value;
339
341
  }
@@ -354,10 +356,10 @@ export function useMemo(factory,deps=undefined)
354
356
  */
355
357
  export function useActionState(action, initialState)
356
358
  {
357
- const hk = Lilact.useHook();
359
+ const hk = useHook();
358
360
  const [is_pending, tran_start_func] = Lilact.useTransition();
359
361
 
360
- if( Lilact.isEmpty(hk) ) {
362
+ if( isEmpty(hk) ) {
361
363
 
362
364
  hk.state = initialState;
363
365
 
@@ -389,9 +391,9 @@ export function useActionState(action, initialState)
389
391
  */
390
392
  export function useReducer(reducer, initialArg, init)
391
393
  {
392
- const hk = Lilact.useHook();
394
+ const hk = useHook();
393
395
 
394
- if( Lilact.isEmpty(hk) ) {
396
+ if( isEmpty(hk) ) {
395
397
  hk.reducer = reducer;
396
398
  hk.state = init?init(initialArg):initialArg;
397
399
  hk.dispatch = function(core, hk, action) {
@@ -400,7 +402,6 @@ export function useReducer(reducer, initialArg, init)
400
402
  hk.state = newst;
401
403
  core.component.forceUpdate();
402
404
  }
403
-
404
405
  }.bind(undefined, Lilact.current_component[0], hk);
405
406
  }
406
407
 
package/src/lilact.jsx CHANGED
@@ -92,7 +92,7 @@ export {transpileJSX, transpilerConfig} from "./jsx";
92
92
  export const Lilact =
93
93
  {
94
94
 
95
- VERSION: "beta.14",
95
+ VERSION: "beta.15",
96
96
 
97
97
  // Configuration
98
98
 
@@ -132,16 +132,16 @@ document.addEventListener('DOMContentLoaded', () => {
132
132
  Lilact.runScripts();
133
133
  });
134
134
 
135
- ʔ if(DEBUG) {
136
- window.addEventListener('error', (e) => {
137
- Lilact.globalErrorHandler(e);
138
- });
139
- ʔ }
135
+ if(DEBUG) {
136
+ window.addEventListener('error', (e) => {
137
+ Lilact.globalErrorHandler(e);
138
+ });
139
+ }
140
140
 
141
- ʔ if(DEBUG) {
141
+ if(DEBUG) {
142
142
  console.log(`Lilact (Version: ${Lilact.VERSION}) - Debug Mode`);
143
143
  console.log(`Copyright(C) 2024-2026 Arash Kazemi <contact.arash.kazemi@gmail.com>`);
144
- ʔ }
144
+ }
145
145
 
146
146
  export default Lilact;
147
147
 
package/src/loader.cjs CHANGED
@@ -43,7 +43,7 @@ module.exports = function loader(source) {
43
43
  // transpilerConfig
44
44
  // });
45
45
 
46
- console.log("Transpiling", DEBUG, this.resource);
46
+ console.log("Transpiling", this.resource);
47
47
  source = transpileJSX(source,
48
48
  {
49
49
  path: this.resource,
package/src/misc.jsx CHANGED
@@ -31,7 +31,7 @@
31
31
  import Lilact from './lilact.jsx';
32
32
 
33
33
 
34
- ʔ defineSymbols ( "LILACT", [ "CORE", "COMPONENT", "MEMOIZED"] ) ʔ
34
+ import { CORE, COMPONENT, MEMOIZED } from "./symbols.jsx"
35
35
 
36
36
 
37
37
  const typeOf = (input) => {
@@ -338,9 +338,6 @@ export function toBool(value) {
338
338
 
339
339
  // Internals
340
340
 
341
- /** @ignore */
342
- export const required_scripts = {};
343
-
344
341
  /** @ignore */
345
342
  export let update_timeout = undefined;
346
343
  /** @ignore */
package/src/redux.jsx CHANGED
@@ -28,8 +28,10 @@
28
28
 
29
29
  */
30
30
 
31
+ import { createContext, useContext, useRef, useState, useEffect } from './hooks.jsx'
32
+ import { shallowEqual } from './misc.jsx'
31
33
 
32
- ʔ defineSymbols ( "LILACT", [ "CORE" ] ) ʔ
34
+ import { CORE } from "./symbols.jsx"
33
35
 
34
36
  let ReduxContext;
35
37
 
@@ -42,7 +44,7 @@ let ReduxContext;
42
44
  */
43
45
  export function Provider({ store, children })
44
46
  {
45
- ReduxContext ??= Lilact.createContext(null);
47
+ ReduxContext ??= createContext(null);
46
48
  return (
47
49
  <ReduxContext.Provider value={store}>{children}</ReduxContext.Provider>
48
50
  );
@@ -55,7 +57,7 @@ export function Provider({ store, children })
55
57
  */
56
58
  export function useStore()
57
59
  {
58
- const store = Lilact.useContext(ReduxContext);
60
+ const store = useContext(ReduxContext);
59
61
  if (!store) {
60
62
  throw new Error("Could not find Redux store in context. <Provider> is missing.");
61
63
  }
@@ -70,7 +72,7 @@ export function useStore()
70
72
  */
71
73
  export function useDispatch()
72
74
  {
73
- const store = Lilact.useStore();
75
+ const store = useStore();
74
76
  return store.dispatch;
75
77
  }
76
78
 
@@ -82,17 +84,17 @@ export function useDispatch()
82
84
  * @returns The selected slice of state.
83
85
  */
84
86
  export function useSelector(selector, equalityFn = (a, b) => a === b) {
85
- const store = Lilact.useStore();
86
- const latestSelected = Lilact.useRef();
87
- const selectorRef = Lilact.useRef(selector);
87
+ const store = useStore();
88
+ const latestSelected = useRef();
89
+ const selectorRef = useRef(selector);
88
90
  selectorRef.current = selector;
89
91
 
90
- const [selected, setSelected] = Lilact.useState(() => selector(store.getState()));
92
+ const [selected, setSelected] = useState(() => selector(store.getState()));
91
93
 
92
94
  // Keep ref in sync for the subscription callback
93
95
  latestSelected.current = selected;
94
96
 
95
- Lilact.useEffect(() => {
97
+ useEffect(() => {
96
98
  function checkForUpdates() {
97
99
  const nextSelected = selectorRef.current(store.getState());
98
100
  if (!equalityFn(latestSelected.current, nextSelected)) {
@@ -127,7 +129,7 @@ export function connect(mapStateToProps, mapDispatchToProps)
127
129
  return function wrapWithConnect(WrappedComponent) {
128
130
 
129
131
  function ConnectedComponent(props) {
130
- const store = Lilact.useStore();
132
+ const store = useStore();
131
133
 
132
134
  let dispatchProps = { dispatch: store.dispatch };
133
135
 
@@ -148,7 +150,7 @@ export function connect(mapStateToProps, mapDispatchToProps)
148
150
  const selector = (state) => mapStateToProps(state, props);
149
151
 
150
152
  // todo: is shallowEqual enough?
151
- stateProps = Lilact.useSelector(selector, Lilact.shallowEqual) || {};
153
+ stateProps = useSelector(selector, shallowEqual) || {};
152
154
  }
153
155
 
154
156
  const mergedProps = { ...props, ...stateProps, ...dispatchProps };
package/src/router.jsx CHANGED
@@ -28,7 +28,7 @@
28
28
 
29
29
  */
30
30
 
31
- ʔ defineSymbols ( "LILACT", [ "CORE", "COMPONENT" ] ) ʔ
31
+ import { CORE, COMPONENT } from "./symbols.jsx"
32
32
 
33
33
  import {createContext, useContext, useState, useCallback, useEffect} from "./hooks.jsx"
34
34
  import {Children} from "./misc.jsx"
package/src/run.jsx CHANGED
@@ -27,10 +27,13 @@
27
27
  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
28
 
29
29
  */
30
+ import Lilact from './lilact.jsx';
30
31
 
31
- ʔ defineSymbols ( "LILACT", [ "CORE", "COMPONENT", "LAZY" ] ) ʔ
32
+ import { CORE, COMPONENT, LAZY } from "./symbols.jsx"
32
33
 
33
- import Lilact from './lilact.jsx';
34
+
35
+ /** @ignore */
36
+ export const required_scripts = {};
34
37
 
35
38
 
36
39
  /**
@@ -49,7 +52,7 @@ export function run(jsx, path=`InlineJSX-${++Lilact.eval_num}`, is_inline=true)
49
52
  let processed;
50
53
 
51
54
 
52
- Lilact.required_scripts[path] = {
55
+ required_scripts[path] = {
53
56
  mappings,
54
57
  module,
55
58
  is_inline,
@@ -76,9 +79,9 @@ export function run(jsx, path=`InlineJSX-${++Lilact.eval_num}`, is_inline=true)
76
79
  throw e;
77
80
  }
78
81
 
79
- ʔ if(DEBUG) {
80
- Lilact.required_scripts[path].processed = processed;
81
- ʔ }
82
+ if(DEBUG) {
83
+ required_scripts[path].processed = processed;
84
+ }
82
85
 
83
86
  processed += "\n//# sourceURL=eval:/" + path;
84
87
 
@@ -105,11 +108,11 @@ export function run(jsx, path=`InlineJSX-${++Lilact.eval_num}`, is_inline=true)
105
108
  /**
106
109
  * Loads a jsx script from a path. All scripts can access Lilact namespace as a global object.
107
110
  *
108
- * `Lilact.require` loads synchronously, as it is expected to be loaded on the next instruction.
111
+ * `require` loads synchronously, as it is expected to be loaded on the next instruction.
109
112
  *
110
113
  * As running the transpiled scripts rely on `new Function`, it is not possible to use module imports
111
114
  * and exports. So to import you should use `const {useState} = Lilact` convention. And to
112
- * export, you should use `module.exports = ...`. `Lilact.require` returns `module.exports` value
115
+ * export, you should use `module.exports = ...`. `require` returns `module.exports` value
113
116
  * so you can import different modules using the convention above.
114
117
  *
115
118
  * If the path is in the format #id, it will query the document for a script element with the given
@@ -126,14 +129,14 @@ export function run(jsx, path=`InlineJSX-${++Lilact.eval_num}`, is_inline=true)
126
129
  */
127
130
  export function require(path, forceUpdate)
128
131
  {
129
- if(Lilact.required_scripts[path] && !forceUpdate) return Lilact.required_scripts[path].module.exports;
132
+ if(required_scripts[path] && !forceUpdate) return required_scripts[path].module.exports;
130
133
 
131
134
  if(path[0]==='#') {
132
135
 
133
136
  const el = document.getElementById(path);
134
137
 
135
138
  if(el) {
136
- return Lilact.run(el.innerText, path);
139
+ return run(el.innerText, path);
137
140
  }
138
141
 
139
142
  }
@@ -146,7 +149,7 @@ export function require(path, forceUpdate)
146
149
  return res.text();
147
150
  })
148
151
  .then(res => {
149
- res = Lilact.run(res, path, false);
152
+ res = run(res, path, false);
150
153
  // todo: this is for the lazy, so we detect default, should we do it in sync mode too?
151
154
  return res?.default ?? res;
152
155
  })
@@ -162,7 +165,7 @@ export function require(path, forceUpdate)
162
165
  request.open("GET", path, false);
163
166
  request.send(null);
164
167
  if (request.status === 200) {
165
- return Lilact.run(request.responseText, path, false);
168
+ return run(request.responseText, path, false);
166
169
  }
167
170
  }
168
171
 
@@ -230,8 +233,8 @@ function scanScriptTagsWithType() {
230
233
  * Scans the whole documents and runs all the script elements with type `text/jsx`.
231
234
  * It is automatically attached to document.onload when Lilact is loaded.
232
235
  *
233
- * If element src is set, it will be loaded via `Lilact.require`.
234
- * If element has inner content, it will be executed via `Lilact.run`.
236
+ * If element src is set, it will be loaded via `require`.
237
+ * If element has inner content, it will be executed via `run`.
235
238
  *
236
239
  * If both are present, first the src is loaded and then the inner content is executed.
237
240
  *
@@ -244,8 +247,8 @@ export function runScripts()
244
247
  const scripts = scanScriptTagsWithType();
245
248
 
246
249
  for(const s of scripts) {
247
- if(s.src) Lilact.require(s.src);
248
- if(s.content) Lilact.run(s.content);
250
+ if(s.src) require(s.src);
251
+ if(s.content) run(s.content);
249
252
  }
250
253
  }
251
254
 
@@ -0,0 +1,64 @@
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
+
32
+ export const [
33
+ CORE,
34
+ COMPONENT,
35
+ TEXT,
36
+ IS_ZOMBIE,
37
+ IDX,
38
+ CHILD_CLASS_ADDENDUM,
39
+ MEMOIZED,
40
+ LAZY,
41
+
42
+ DUE,
43
+ REPEAT,
44
+ CLEARED,
45
+ INTERVAL,
46
+ CALLBACK,
47
+ ARGS
48
+ ] =
49
+ [
50
+ Symbol.for('LILACT:CORE'),
51
+ Symbol.for('LILACT:COMPONENT'),
52
+ Symbol.for('LILACT:TEXT'),
53
+ Symbol.for('LILACT:IS_ZOMBIE'),
54
+ Symbol.for('LILACT:IDX'),
55
+ Symbol.for('LILACT:CHILD_CLASS_ADDENDUM'),
56
+ Symbol.for('LILACT:MEMOIZED'),
57
+
58
+ Symbol.for('LILACT:TIMERS:DUE'),
59
+ Symbol.for('LILACT:TIMERS:REPEAT'),
60
+ Symbol.for('LILACT:TIMERS:CLEARED'),
61
+ Symbol.for('LILACT:TIMERS:INTERVAL'),
62
+ Symbol.for('LILACT:TIMERS:CALLBACK'),
63
+ Symbol.for('LILACT:TIMERS:ARGS')
64
+ ];
package/src/timers.jsx CHANGED
@@ -33,7 +33,7 @@
33
33
  //ʔ outputJS('./dist/timers.js');
34
34
 
35
35
 
36
- ʔ defineSymbols("LILACT:TIMERS", ["CORE", "IDX", "DUE", "REPEAT", "CLEARED", "INTERVAL", "CALLBACK", "ARGS"] ) ʔ
36
+ import { IDX, DUE, REPEAT, CLEARED, INTERVAL, CALLBACK, ARGS } from "./symbols.jsx"
37
37
 
38
38
  /**
39
39
  * Timer helpers for a promise-friendly timer framework.
@@ -254,10 +254,10 @@ export function clearInterval(id)
254
254
  */
255
255
  export function grabTimers()
256
256
  {
257
- globalThis.setTimeout = this.setTimeout;
258
- globalThis.setInterval = this.setInterval;
259
- globalThis.clearTimeout = this.clearTimeout;
260
- globalThis.clearInterval = this.clearInterval;
257
+ globalThis.setTimeout = Lilact.setTimeout;
258
+ globalThis.setInterval = Lilact.setInterval;
259
+ globalThis.clearTimeout = Lilact.clearTimeout;
260
+ globalThis.clearInterval = Lilact.clearInterval;
261
261
  }
262
262
 
263
263
  /**
@@ -277,7 +277,7 @@ export function releaseTimers()
277
277
  * @param {number} duration - Delay in milliseconds.
278
278
  * @returns {Promise} Promise that resolves after the delay.
279
279
  */
280
- export function timeoutPromise(duration=0, timerSource=this)
280
+ export function timeoutPromise(duration=0, timerSource=Lilact)
281
281
  {
282
282
  let id, resolve, reject;
283
283
 
@@ -27,8 +27,11 @@
27
27
  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
28
 
29
29
  */
30
+ import { setTimeout, clearTimeout } from "./timers.jsx"
31
+ import { Children } from "./misc.jsx"
32
+ import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "./hooks.jsx"
30
33
 
31
- ʔ defineSymbols ( "LILACT", [ "CORE", "COMPONENT", "CHILD_CLASS_ADDENDUM" ] ) ʔ
34
+ import { CORE, COMPONENT, CHILD_CLASS_ADDENDUM } from "./symbols.jsx"
32
35
 
33
36
  /* States */
34
37
  const UNMOUNTED = "unmounted";
@@ -37,9 +40,6 @@ const ENTERING = "entering";
37
40
  const ENTERED = "entered";
38
41
  const EXITING = "exiting";
39
42
 
40
- import { setTimeout, clearTimeout} from "./timers.jsx"
41
- import { Children } from "./misc.jsx"
42
- import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "./hooks.jsx"
43
43
 
44
44
  /**
45
45
  * Transition component that manages enter/exit lifecycle and calls callbacks based on state changes.