lilact 0.28.5 → 0.29.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 (45) hide show
  1. package/dist/lilact.development.js +215 -172
  2. package/dist/lilact.development.js.map +3 -3
  3. package/dist/lilact.development.min.js +33 -33
  4. package/dist/lilact.development.min.js.map +3 -3
  5. package/dist/lilact.production.min.js +33 -33
  6. package/docs/assets/navigation.js +1 -1
  7. package/docs/assets/search.js +1 -1
  8. package/docs/classes/accessories.ErrorBoundary.html +8 -8
  9. package/docs/classes/accessories.Suspense.html +7 -7
  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/components.cloneComponent.html +1 -1
  14. package/docs/functions/components.createComponent.html +1 -1
  15. package/docs/functions/components.createPortal.html +1 -1
  16. package/docs/functions/components.createRoot.html +1 -1
  17. package/docs/functions/components.memo.html +1 -1
  18. package/docs/functions/components.render.html +1 -1
  19. package/docs/functions/errors.asError.html +1 -0
  20. package/docs/functions/run.lazy.html +1 -1
  21. package/docs/functions/run.require.html +1 -1
  22. package/docs/functions/run.run.html +1 -1
  23. package/docs/functions/run.runScripts.html +1 -1
  24. package/docs/modules/errors.html +1 -1
  25. package/docs/static/index.html +3 -4
  26. package/docs/static/lilact.development.js +215 -172
  27. package/docs/static/lilact.development.js.map +3 -3
  28. package/docs/static/lilact.development.min.js +33 -33
  29. package/docs/static/lilact.development.min.js.map +3 -3
  30. package/docs/static/lilact.production.min.js +33 -33
  31. package/docs/variables/components.cloneElement.html +1 -1
  32. package/docs/variables/errors.blocksInfo.html +1 -0
  33. package/examples/index.html +3 -4
  34. package/examples/lilact.development.js +215 -172
  35. package/examples/lilact.development.js.map +3 -3
  36. package/examples/lilact.development.min.js +33 -33
  37. package/examples/lilact.development.min.js.map +3 -3
  38. package/examples/lilact.production.min.js +33 -33
  39. package/package.json +1 -1
  40. package/src/components.jsx +104 -115
  41. package/src/errors.jsx +4 -4
  42. package/src/expscan.js +40 -15
  43. package/src/jsx.js +67 -38
  44. package/src/run.jsx +51 -40
  45. package/docs/variables/errors.blocks_info.html +0 -1
@@ -2452,104 +2452,97 @@ var ComponentCore = class {
2452
2452
  */
2453
2453
  // TODO: should componentDidUpdate be called after arranging/appending the outlet or before?
2454
2454
  apply(next_props = this.props, next_state = this.next_state || this.state) {
2455
- let do_rerender = true;
2456
- if (this.outlet && this?.[MEMOIZED]) {
2457
- if (shallowEqual(this.props, next_props, "children") && shallowEqual(this.props?.children, next_props?.children)) {
2458
- do_rerender = false;
2459
- }
2460
- }
2461
- if (do_rerender) {
2462
- if (true) {
2463
- if (this.entity?.propTypes) {
2464
- PropTypes.checkPropTypes(this.entity.propTypes, this.props, "prop", this.entity.name);
2465
- } else if (this.component?.propTypes) {
2466
- PropTypes.checkPropTypes(this.component.propTypes, this.props, "prop", this.component.name);
2455
+ try {
2456
+ let do_rerender = true;
2457
+ if (this.outlet && this?.[MEMOIZED]) {
2458
+ if (shallowEqual(this.props, next_props, "children") && shallowEqual(this.props?.children, next_props?.children)) {
2459
+ do_rerender = false;
2467
2460
  }
2468
2461
  }
2469
- if (typeof next_state === "function") next_state = next_state(this.state);
2470
- if (this.component.constructor.defaultProps) {
2471
- next_props = { ...this.component.constructor.defaultProps, ...next_props };
2472
- }
2473
- if (this?.parent?.component?.context || this?.parent?.component?.getChildContext) {
2474
- this.context = { ...this.parent.component.context, ...this.parent.component.getChildContext?.() };
2475
- if (this.component.constructor.contextTypes) {
2476
- PropTypes.checkPropTypes(this.component.constructor.contextTypes, this.context, "context", this.entity.name);
2462
+ if (do_rerender) {
2463
+ if (true) {
2464
+ if (this.entity?.propTypes) {
2465
+ PropTypes.checkPropTypes(this.entity.propTypes, this.props, "prop", this.entity.name);
2466
+ } else if (this.component?.propTypes) {
2467
+ PropTypes.checkPropTypes(this.component.propTypes, this.props, "prop", this.component.name);
2468
+ }
2477
2469
  }
2478
- }
2479
- if (this.component.shouldComponentUpdate && !this.component.shouldComponentUpdate(next_state, next_props, this.context)) return;
2480
- if (typeof this.entity === "string") {
2481
- if (!(this.element instanceof Element)) {
2482
- if (this.is_svg || this.container.is_svg) {
2483
- this.is_svg = true;
2484
- this.element = document.createElementNS(SVG_NS, this.entity);
2470
+ if (typeof next_state === "function") next_state = next_state(this.state);
2471
+ if (this.component.constructor.defaultProps) {
2472
+ next_props = { ...this.component.constructor.defaultProps, ...next_props };
2473
+ }
2474
+ if (this?.parent?.component?.context || this?.parent?.component?.getChildContext) {
2475
+ this.context = { ...this.parent.component.context, ...this.parent.component.getChildContext?.() };
2476
+ if (this.component.constructor.contextTypes) {
2477
+ PropTypes.checkPropTypes(this.component.constructor.contextTypes, this.context, "context", this.entity.name);
2478
+ }
2479
+ }
2480
+ if (this.component.shouldComponentUpdate && !this.component.shouldComponentUpdate(next_state, next_props, this.context)) return;
2481
+ if (typeof this.entity === "string") {
2482
+ if (!(this.element instanceof Element)) {
2483
+ if (this.is_svg || this.container.is_svg) {
2484
+ this.is_svg = true;
2485
+ this.element = document.createElementNS(SVG_NS, this.entity);
2486
+ } else {
2487
+ this.element = document.createElement(this.entity);
2488
+ }
2489
+ if (next_props?.defaultValue) this.element.value = String(next_props.defaultValue).slice(0, next_props?.maxLength);
2490
+ if (next_props?.defaultChecked) this.element.checked = next_props.defaultChecked;
2491
+ }
2492
+ this.element[COMPONENT] = this.component;
2493
+ }
2494
+ if (next_props.ref) {
2495
+ if (typeof next_props.ref === "function") {
2496
+ next_props.ref(this.element || this.component);
2485
2497
  } else {
2486
- this.element = document.createElement(this.entity);
2498
+ next_props.ref.current = this.element || this.component;
2487
2499
  }
2488
- if (next_props?.defaultValue) this.element.value = String(next_props.defaultValue).slice(0, next_props?.maxLength);
2489
- if (next_props?.defaultChecked) this.element.checked = next_props.defaultChecked;
2490
2500
  }
2491
- this.element[COMPONENT] = this.component;
2492
- }
2493
- if (next_props.ref) {
2494
- if (typeof next_props.ref === "function") {
2495
- next_props.ref(this.element || this.component);
2496
- } else {
2497
- next_props.ref.current = this.element || this.component;
2501
+ if (next_props !== void 0 && this.component.componentWillReceiveProps) {
2502
+ this.component.componentWillReceiveProps(next_props);
2498
2503
  }
2499
- }
2500
- if (next_props !== void 0 && this.component.componentWillReceiveProps) {
2501
- this.component.componentWillReceiveProps(next_props);
2502
- }
2503
- if (this.component.componentWillUpdate) {
2504
- this.component.componentWillUpdate(next_props, next_state);
2505
- }
2506
- const prev_state = this.state, prev_props = this.props;
2507
- if (this.element) {
2508
- this.updateElementProps(next_props);
2509
- }
2510
- this.props = next_props;
2511
- if (typeof this.next_state === "object") {
2512
- if (!this.state) this.state = { ...next_state };
2513
- else Object.assign(this.state, next_state);
2514
- } else if (this.next_state !== void 0) throw new Error("Component.setState only accepts objects or functions is new state.");
2515
- if (this.next_state) delete this.next_state;
2516
- if (this.hooks !== void 0) {
2517
- this.hook_index = 0;
2518
- lilact_default.current_component = [this, lilact_default.current_component];
2519
- try {
2520
- this.outlet = this.component.render(next_props, { current: this.element || this.component });
2521
- } catch (e) {
2522
- renderErrorHandler(this, e);
2504
+ if (this.component.componentWillUpdate) {
2505
+ this.component.componentWillUpdate(next_props, next_state);
2523
2506
  }
2524
- lilact_default.current_component = lilact_default.current_component[1];
2525
- } else {
2526
- try {
2507
+ const prev_state = this.state, prev_props = this.props;
2508
+ if (this.element) {
2509
+ this.updateElementProps(next_props);
2510
+ }
2511
+ this.props = next_props;
2512
+ if (typeof this.next_state === "object") {
2513
+ if (!this.state) this.state = { ...next_state };
2514
+ else Object.assign(this.state, next_state);
2515
+ } else if (this.next_state !== void 0) throw new Error("Component.setState only accepts objects or functions is new state.");
2516
+ if (this.next_state) delete this.next_state;
2517
+ if (this.hooks !== void 0) {
2518
+ this.hook_index = 0;
2519
+ lilact_default.current_component = [this, lilact_default.current_component];
2520
+ this.outlet = this.component.render(next_props, { current: this.element || this.component });
2521
+ lilact_default.current_component = lilact_default.current_component[1];
2522
+ } else {
2527
2523
  this.outlet = this.component.render({ current: this.element || this.component });
2528
- } catch (e) {
2529
- renderErrorHandler(this, e);
2530
2524
  }
2531
- }
2532
- if (this?.portal) {
2533
- this.element = this.portal;
2534
- }
2535
- if (this.outlet?.constructor?.name !== "Array") {
2536
- this.outlet = [this.outlet];
2537
- }
2538
- this.outlet = [...this.outlet];
2539
- for (let i2 = 0; i2 < this.outlet.length; i2++) {
2540
- let item = this.outlet[i2];
2541
- if (item === void 0 || item === null || typeof item === "boolean") {
2542
- this.outlet.splice(i2, 1);
2543
- i2--;
2544
- } else if (typeof item === "function") {
2545
- const res = this.childFunctionHandler(item);
2546
- this.outlet.splice(i2, 1, res);
2547
- i2--;
2548
- } else if (item.constructor.name === "Array") {
2549
- this.outlet.splice(i2, 1, ...item);
2550
- i2--;
2525
+ if (this?.portal) {
2526
+ this.element = this.portal;
2527
+ }
2528
+ if (this.outlet?.constructor?.name !== "Array") {
2529
+ this.outlet = [this.outlet];
2551
2530
  } else {
2552
- try {
2531
+ this.outlet = [...this.outlet];
2532
+ }
2533
+ for (let i2 = 0; i2 < this.outlet.length; i2++) {
2534
+ let item = this.outlet[i2];
2535
+ if (item === void 0 || item === null || typeof item === "boolean") {
2536
+ this.outlet.splice(i2, 1);
2537
+ i2--;
2538
+ } else if (typeof item === "function") {
2539
+ const res = this.childFunctionHandler(item);
2540
+ this.outlet.splice(i2, 1, res);
2541
+ i2--;
2542
+ } else if (item.constructor.name === "Array") {
2543
+ this.outlet.splice(i2, 1, ...item);
2544
+ i2--;
2545
+ } else {
2553
2546
  const core = prepareCore(this, item);
2554
2547
  this.outlet[i2] = core;
2555
2548
  if (core[TEXT2] === void 0) {
@@ -2564,17 +2557,17 @@ var ComponentCore = class {
2564
2557
  core[TEXT2] = item[TEXT2];
2565
2558
  }
2566
2559
  }
2567
- } catch (e) {
2568
- renderErrorHandler(this, e);
2569
2560
  }
2570
2561
  }
2562
+ if (this.cache) this.cache.commit();
2563
+ if (this.element) this.arrangeOutlet();
2564
+ if (this.component.componentDidUpdate) {
2565
+ this.component.componentDidUpdate(prev_props, prev_state, this.last_snapshot);
2566
+ }
2567
+ if (this.last_snapshot) delete this.last_snapshot;
2571
2568
  }
2572
- if (this.cache) this.cache.commit();
2573
- if (this.element) this.arrangeOutlet();
2574
- if (this.component.componentDidUpdate) {
2575
- this.component.componentDidUpdate(prev_props, prev_state, this.last_snapshot);
2576
- }
2577
- if (this.last_snapshot) delete this.last_snapshot;
2569
+ } catch (e) {
2570
+ renderErrorHandler(this, e);
2578
2571
  }
2579
2572
  }
2580
2573
  async cleanup() {
@@ -2771,7 +2764,7 @@ var ComponentCore = class {
2771
2764
  core.container = this.element ? this : this.container;
2772
2765
  core.container.appendElement(core);
2773
2766
  } else {
2774
- if (core.arrangeOutlet) core.arrangeOutlet();
2767
+ if (core.arrangeOutlet && core.outlet) core.arrangeOutlet();
2775
2768
  if (!core?.mounted) {
2776
2769
  core.mounted = true;
2777
2770
  if (core?.component?.componentDidMount) {
@@ -3679,17 +3672,14 @@ function report(value, path2) {
3679
3672
  }
3680
3673
  var required_scripts = {};
3681
3674
  function createModule(path2, {
3682
- code: code2 = "",
3683
- isInline: isInline2 = false,
3684
- isModule: isModule2 = true
3675
+ code: code2 = ""
3685
3676
  } = {}) {
3686
3677
  const module2 = {
3687
3678
  path: path2,
3688
3679
  code: String(code2),
3689
3680
  mappings: [],
3681
+ meta: {},
3690
3682
  exports: {},
3691
- isInline: isInline2,
3692
- isModule: isModule2,
3693
3683
  // True only after the module has been successfully evaluated.
3694
3684
  loaded: false,
3695
3685
  // The promise for the request currently loading this resource.
@@ -3700,38 +3690,57 @@ function createModule(path2, {
3700
3690
  required_scripts[path2] = module2;
3701
3691
  return module2;
3702
3692
  }
3703
- function run(jsx, path = `InlineJSX-${++lilact_default.eval_num}`, {
3704
- isInline = true,
3705
- isModule = true,
3706
- hotReload = true
3707
- } = {}) {
3693
+ function makeImportsObject(mod) {
3694
+ mod.importsObject ?? (mod.importsObject = {});
3695
+ for (const path2 in mod.meta.imports) {
3696
+ let exps = required_scripts[path2];
3697
+ let imps = mod.meta.imports[path2];
3698
+ if (!exps) {
3699
+ exps = lilact_default.require(path2, { requirer: mod });
3700
+ }
3701
+ for (const i2 in imps.named_imports) {
3702
+ if (i2 === "") continue;
3703
+ const j = imps.named_imports[i2];
3704
+ if (!exps.hasOwnProperty(j)) throw new Error(`Imported module does not export any "${i2}".`);
3705
+ mod.importsObject[i2] = exps[j];
3706
+ }
3707
+ for (const i2 of imps.import_defaults) {
3708
+ if (!exps.hasOwnProperty("default")) throw new Error(`Imported module does not export a default.`);
3709
+ mod.importsObject[i2] = exps.default;
3710
+ }
3711
+ for (const i2 of imps.import_stars) {
3712
+ mod.importsObject[i2] = { ...exps };
3713
+ }
3714
+ }
3715
+ }
3716
+ function run(jsx, path = `InlineJSX-${++lilact_default.eval_num}`, {} = {}) {
3708
3717
  let module = required_scripts[path];
3709
3718
  if (!module) {
3710
3719
  module = createModule(path, {
3711
- code: jsx,
3712
- isInline,
3713
- isModule
3720
+ code: jsx
3714
3721
  });
3715
3722
  } else {
3716
3723
  module.path = path;
3717
3724
  module.code = String(jsx);
3718
3725
  module.mappings = [];
3719
3726
  module.exports = {};
3720
- module.isInline = isInline;
3721
- module.isModule = isModule;
3722
3727
  module.loaded = false;
3723
3728
  module.error = void 0;
3729
+ module.importsObject = void 0;
3730
+ module.meta = {};
3724
3731
  }
3725
3732
  let processed;
3726
3733
  try {
3727
3734
  processed = lilact_default.transpileJSX(String(jsx), {
3728
3735
  path,
3729
3736
  mappings: module.mappings,
3737
+ meta: module.meta,
3730
3738
  factory: "createComponent",
3731
3739
  appendSourcemap: true,
3732
3740
  injectTraceLabels: true,
3733
- produceCJS: true,
3734
- blocks_info: lilact_default.blocks_info
3741
+ produceCJS: false,
3742
+ referentiateImports: true,
3743
+ blocksInfo: lilact_default.blocksInfo
3735
3744
  });
3736
3745
  } catch (value) {
3737
3746
  const error2 = asError(value);
@@ -3746,10 +3755,11 @@ function run(jsx, path = `InlineJSX-${++lilact_default.eval_num}`, {
3746
3755
  lilact_default.scanBlockLabels(processed, path);
3747
3756
  }
3748
3757
  try {
3749
- new Function(processed);
3750
3758
  globalThis.Lilact = lilact_default;
3751
3759
  globalThis.createComponent = lilact_default.createComponent;
3752
3760
  globalThis.Fragment = lilact_default.Fragment;
3761
+ if (!module.importsObject) makeImportsObject(module);
3762
+ lilact_default.scriptImportsObject = module.importsObject;
3753
3763
  const result = eval(processed);
3754
3764
  module.loaded = true;
3755
3765
  return isEmpty(module.exports) ? result : module.exports;
@@ -3797,10 +3807,7 @@ function loadAsyncResource(path2, module2) {
3797
3807
  module2.loaded = true;
3798
3808
  return void 0;
3799
3809
  }
3800
- return run(module2.code, path2, {
3801
- isInline: false,
3802
- isModule: true
3803
- });
3810
+ return run(module2.code, path2, {});
3804
3811
  }).then((result2) => result2?.default ?? result2).catch((error2) => {
3805
3812
  module2.error = report(error2, path2);
3806
3813
  throw module2.error;
@@ -3820,15 +3827,12 @@ function require2(path2) {
3820
3827
  if (lilact_default.importObjectPaths?.[path2]) {
3821
3828
  return lilact_default.importObjectPaths[path2];
3822
3829
  }
3823
- if (options.requirer?.path) {
3830
+ if (options?.requirer?.path) {
3824
3831
  path2 = joinPaths(options.requirer.path, path2);
3825
3832
  }
3826
3833
  const loadAsync = Boolean(lilact_default[LAZY]) || Boolean(options.isLazy);
3827
- const module2 = getOrCreateModule(path2, {
3828
- isInline: false,
3829
- isModule: true
3830
- });
3831
- if (module2.loaded && !options.forceUpdate) {
3834
+ const module2 = getOrCreateModule(path2, {});
3835
+ if (module2.loaded && !options.forceReload) {
3832
3836
  return module2.exports;
3833
3837
  }
3834
3838
  if (path2.startsWith("#")) {
@@ -3839,7 +3843,7 @@ function require2(path2) {
3839
3843
  path2
3840
3844
  );
3841
3845
  }
3842
- return run(element.textContent || "", path2);
3846
+ return run(element.textContent || "", path2, { forceReload: options.forceReload });
3843
3847
  }
3844
3848
  if (loadAsync) {
3845
3849
  lilact_default[LAZY] = false;
@@ -3856,10 +3860,7 @@ function require2(path2) {
3856
3860
  module2.loaded = true;
3857
3861
  return void 0;
3858
3862
  }
3859
- return run(String(resolved), path2, {
3860
- isInline: false,
3861
- isModule: true
3862
- });
3863
+ return run(String(resolved), path2, { forceReload: options.forceReload });
3863
3864
  }
3864
3865
  const request = new XMLHttpRequest();
3865
3866
  try {
@@ -3875,10 +3876,7 @@ function require2(path2) {
3875
3876
  module2.loaded = true;
3876
3877
  return void 0;
3877
3878
  }
3878
- return run(request.responseText, path2, {
3879
- isInline: false,
3880
- isModule: true
3881
- });
3879
+ return run(request.responseText, path2, { forceReload: options.forceReload });
3882
3880
  }
3883
3881
  throw report(
3884
3882
  new Error(
@@ -4661,7 +4659,8 @@ function animationFramePromise() {
4661
4659
  // .tmp/src/errors.jsx
4662
4660
  var errors_exports = {};
4663
4661
  __export(errors_exports, {
4664
- blocks_info: () => blocks_info,
4662
+ asError: () => asError2,
4663
+ blocksInfo: () => blocksInfo,
4665
4664
  error: () => error,
4666
4665
  globalErrorHandler: () => globalErrorHandler,
4667
4666
  scanBlockLabels: () => scanBlockLabels,
@@ -4725,7 +4724,7 @@ function traceBlock(error2) {
4725
4724
  }
4726
4725
  function blockInfo(error2) {
4727
4726
  const trace = traceBlock(error2);
4728
- return trace == null ? null : lilact_default.blocks_info?.labels?.[trace];
4727
+ return trace == null ? null : lilact_default.blocksInfo?.labels?.[trace];
4729
4728
  }
4730
4729
  function mapLocation(mappings, line2, column2) {
4731
4730
  if (!Array.isArray(mappings) || !mappings.length || !Number.isFinite(line2) || !Number.isFinite(column2)) {
@@ -4884,7 +4883,7 @@ function scanBlockLabels(code2, path2) {
4884
4883
  for (const match2 of String(code2).matchAll(
4885
4884
  /LILACTBLOCK(\d+):(\d+),(\d+):([^*]+)\*\//gm
4886
4885
  )) {
4887
- lilact_default.blocks_info.labels[match2[1]] = {
4886
+ lilact_default.blocksInfo.labels[match2[1]] = {
4888
4887
  path: path2,
4889
4888
  line: Number(match2[2]),
4890
4889
  column: Number(match2[3]),
@@ -4892,7 +4891,7 @@ function scanBlockLabels(code2, path2) {
4892
4891
  };
4893
4892
  }
4894
4893
  }
4895
- var blocks_info = {
4894
+ var blocksInfo = {
4896
4895
  counter: 0,
4897
4896
  labels: {}
4898
4897
  };
@@ -5769,7 +5768,7 @@ function generateSequence(arr, labeler2 = labeler2.bind(null, null)) {
5769
5768
  }
5770
5769
  var import_export_regexp = /(?:i[C \n]*(?:(?:I|J|(?:\*[C \n]*a[C \n]*I))[C \n]*,[C \n]*)*(?:(?:(?:I(?:[C \n]*a[C \n]*I)?)|J|(?:\*[C \n]*a[C \n]*I))[C \n]*f[C \n]*)?S)|(?:e[C \n]*(?:(?:[*J][C \n]*f[C \n]*S)|(?:d[C \n]*[IFJ])|J|(?:[VF][c \n]*I)|I))|(?:r[c \n]*P)/mg;
5771
5770
  var props_regexp = /O[C \n]*(?:[Id](?:[C \n]*a[C \n]*I)?[C \n]*,[C \n]*)*(?:I(?:[C \n]*a[C \n]*I)?)[C \n]*O/mg;
5772
- function processImportExports(node3, jsx2) {
5771
+ function processImportExports(node3, jsx2, meta) {
5773
5772
  const s = generateSequence(
5774
5773
  node3.out,
5775
5774
  labeler.bind(
@@ -5814,6 +5813,8 @@ function processImportExports(node3, jsx2) {
5814
5813
  }
5815
5814
  }
5816
5815
  begins.push(node3.end);
5816
+ meta.imports ?? (meta.imports = {});
5817
+ const imported_names = /* @__PURE__ */ new Set();
5817
5818
  for (const m of s.matchAll(import_export_regexp)) {
5818
5819
  if (m[0].startsWith("r")) {
5819
5820
  const req = m[0];
@@ -5827,9 +5828,9 @@ function processImportExports(node3, jsx2) {
5827
5828
  skip_spaces(-1);
5828
5829
  if (s[i2] === ".") continue;
5829
5830
  const src = jsx2.substring(node3.out[m.index + imp.length - 1].begin, node3.out[m.index + imp.length - 1].end);
5830
- const imports = {};
5831
- let star_imports = [];
5832
- let import_alls = [];
5831
+ const named_imports = {};
5832
+ let import_stars = [];
5833
+ let import_defaults = [];
5833
5834
  for (i2 = m.index + 1; i2 < m.index + imp.length - 1; i2++) {
5834
5835
  node3.out.splice(m.index, 1, {
5835
5836
  type: "import",
@@ -5842,7 +5843,7 @@ function processImportExports(node3, jsx2) {
5842
5843
  case ",":
5843
5844
  break;
5844
5845
  case "I": {
5845
- import_alls.push(node3.out[i2]);
5846
+ import_defaults.push(node3.out[i2]);
5846
5847
  continue;
5847
5848
  }
5848
5849
  case "J": {
@@ -5864,10 +5865,10 @@ function processImportExports(node3, jsx2) {
5864
5865
  if (sj[j] === "a") {
5865
5866
  j++;
5866
5867
  while (sj[j] === " " || sj[j] === "\n" || sj[j] === "C") j++;
5867
- imports[ps[j]] = prop;
5868
+ named_imports[ps[j]] = prop;
5868
5869
  j++;
5869
5870
  } else {
5870
- imports[prop] = prop;
5871
+ named_imports[prop] = prop;
5871
5872
  }
5872
5873
  }
5873
5874
  continue;
@@ -5877,7 +5878,7 @@ function processImportExports(node3, jsx2) {
5877
5878
  skip_spaces();
5878
5879
  i2++;
5879
5880
  skip_spaces();
5880
- star_imports.push(node3.out[i2]);
5881
+ import_stars.push(node3.out[i2]);
5881
5882
  continue;
5882
5883
  }
5883
5884
  case "S":
@@ -5885,28 +5886,31 @@ function processImportExports(node3, jsx2) {
5885
5886
  node3.out[i2] = null;
5886
5887
  }
5887
5888
  let cjs = "";
5888
- for (const s2 of star_imports) {
5889
+ for (const s2 of import_stars) {
5889
5890
  cjs += `const ${s2} = require(${src},{requirer:module});
5890
5891
  `;
5892
+ imported_names.add(s2);
5891
5893
  }
5892
- for (const s2 of import_alls) {
5894
+ for (const s2 of import_defaults) {
5893
5895
  cjs += `const ${s2} = require(${src},{requirer:module, checkExport: ['default']}).default;
5894
5896
  `;
5897
+ imported_names.add(s2);
5895
5898
  }
5896
- if (Object.keys(imports).length) {
5899
+ if (Object.keys(named_imports).length) {
5897
5900
  let o = "{";
5898
5901
  let ls = "[";
5899
- for (const p in imports) {
5902
+ for (const p in named_imports) {
5903
+ imported_names.add(p);
5900
5904
  if (o.length > 1) {
5901
5905
  o += ",";
5902
5906
  ls += ",";
5903
5907
  }
5904
- if (p === imports[p]) {
5908
+ if (p === named_imports[p]) {
5905
5909
  o += p;
5906
5910
  ls += `'${p}'`;
5907
5911
  } else {
5908
- o += p + ":" + imports[p];
5909
- ls += `'${imports[p]}'`;
5912
+ o += p + ":" + named_imports[p];
5913
+ ls += `'${named_imports[p]}'`;
5910
5914
  }
5911
5915
  }
5912
5916
  o += "}";
@@ -5914,11 +5918,20 @@ function processImportExports(node3, jsx2) {
5914
5918
  cjs += `const ${o} = require(${src}, {checkExport: ${ls},requirer:module})`;
5915
5919
  } else if (cjs.length === 0) {
5916
5920
  cjs += `require(${src},{requirer:module})`;
5921
+ named_imports[""] = src;
5917
5922
  }
5918
5923
  node3.out[m.index].cjs = cjs;
5919
5924
  continue;
5920
5925
  }
5921
5926
  }
5927
+ const ss = src.slice(1, src.length - 1);
5928
+ if (meta.imports[ss]) {
5929
+ meta.imports[ss] = {
5930
+ import_stars: [...meta.imports[ss].import_stars, ...import_stars],
5931
+ import_defaults: [...meta.imports[ss].import_defaults, ...import_defaults],
5932
+ named_imports: { ...meta.imports[ss].named_imports, ...named_imports }
5933
+ };
5934
+ } else meta.imports[ss] = { import_stars, import_defaults, named_imports };
5922
5935
  } else {
5923
5936
  const exp = m[0];
5924
5937
  node3.out.splice(m.index, 1, {
@@ -6032,13 +6045,17 @@ function processImportExports(node3, jsx2) {
6032
6045
  }
6033
6046
  }
6034
6047
  }
6048
+ if (meta.imported_names) {
6049
+ meta.imported_names = /* @__PURE__ */ new Set([...meta.imported_names, ...imported_names]);
6050
+ } else {
6051
+ meta.imported_names = imported_names;
6052
+ }
6035
6053
  }
6036
6054
 
6037
6055
  // .tmp/src/jsx.js
6038
6056
  var transpilerConfig = {
6039
6057
  setBlockLabels: true,
6040
6058
  enableLabelStack: false,
6041
- injectLabels: true,
6042
6059
  // todo: alt+shift+7 on apple abc extended layout is better i think,
6043
6060
  // but my current editor doesn't support syntax highlighting with it.
6044
6061
  preprocessorDelimiter: "\u0294"
@@ -6596,7 +6613,7 @@ function parseJS(code2, index2 = 0, is_block = false, container2) {
6596
6613
  if (container2) container2.children.push(b2);
6597
6614
  return b2;
6598
6615
  }
6599
- function labelFunctions(node3, eols, blocks_info2) {
6616
+ function labelFunctions(node3, eols, blocksInfo2) {
6600
6617
  node3.already_labeled = true;
6601
6618
  function getNext(i3, step = 1) {
6602
6619
  while ((i3 += step) < node3.children.length && i3 >= 0) {
@@ -6625,11 +6642,11 @@ function labelFunctions(node3, eols, blocks_info2) {
6625
6642
  if (nxt === null) continue;
6626
6643
  if (transpilerConfig.injectTraceLabels && typeof nxt === "object" && nxt.type === "js") {
6627
6644
  const begin = getRowCol(eols, chi);
6628
- nxt.children.splice(1, 0, `/*LILACTBLOCK${++blocks_info2.counter}:${begin}:${label}*/try{`);
6645
+ nxt.children.splice(1, 0, `/*LILACTBLOCK${++blocksInfo2.counter}:${begin}:${label}*/try{`);
6629
6646
  if (transpilerConfig.enableLabelStack) {
6630
- nxt.children.splice(nxt.children.length - 1, 0, `} catch(e){ if(typeof(e)!=='object') e=new Error(e);e.lilact_trace=[${blocks_info2.counter},e.lilact_trace];throw e}`);
6647
+ nxt.children.splice(nxt.children.length - 1, 0, `} catch(e){ if(typeof(e)!=='object') e=new Error(e);e.lilact_trace=[${blocksInfo2.counter},e.lilact_trace];throw e}`);
6631
6648
  } else {
6632
- nxt.children.splice(nxt.children.length - 1, 0, `} catch(e){ if(typeof(e)!=='object') e=new Error(e);e.lilact_trace=${blocks_info2.counter};throw e}`);
6649
+ nxt.children.splice(nxt.children.length - 1, 0, `} catch(e){ if(typeof(e)!=='object') e=new Error(e);e.lilact_trace=${blocksInfo2.counter};throw e}`);
6633
6650
  }
6634
6651
  chi += 2;
6635
6652
  }
@@ -6643,19 +6660,19 @@ function labelFunctions(node3, eols, blocks_info2) {
6643
6660
  nxt.children.splice(
6644
6661
  1,
6645
6662
  0,
6646
- `/*LILACTBLOCK${++blocks_info2.counter}:${begin}:<ARROW>*/try {`
6663
+ `/*LILACTBLOCK${++blocksInfo2.counter}:${begin}:<ARROW>*/try {`
6647
6664
  );
6648
6665
  if (transpilerConfig.enableLabelStack) {
6649
6666
  nxt.children.splice(
6650
6667
  nxt.children.length - 1,
6651
6668
  0,
6652
- `} catch(e){if(typeof(e)!=='object') e=new Error(e);e.lilact_trace=[${blocks_info2.counter},e.lilact_trace];throw e}`
6669
+ `} catch(e){if(typeof(e)!=='object') e=new Error(e);e.lilact_trace=[${blocksInfo2.counter},e.lilact_trace];throw e}`
6653
6670
  );
6654
6671
  } else {
6655
6672
  nxt.children.splice(
6656
6673
  nxt.children.length - 1,
6657
6674
  0,
6658
- `} catch(e){if(typeof(e)!=='object') e=new Error(e);e.lilact_trace=${blocks_info2.counter};throw e}`
6675
+ `} catch(e){if(typeof(e)!=='object') e=new Error(e);e.lilact_trace=${blocksInfo2.counter};throw e}`
6659
6676
  );
6660
6677
  }
6661
6678
  }
@@ -6749,13 +6766,19 @@ function transpileJSX(jsx2, {
6749
6766
  injectTraceLabels = false,
6750
6767
  discardComments = false,
6751
6768
  produceCJS = false,
6769
+ referentiateImports = false,
6770
+ importsObject = "Lilact.scriptImportsObject",
6771
+ // first letter must be capital so components work as expected
6772
+ importsObjectVar = "LilactImports",
6773
+ // first letter must be capital so components work as expected
6752
6774
  logErrors = false,
6753
6775
  // lilact internal
6754
- blocks_info: blocks_info2 = {
6776
+ mappings = [],
6777
+ meta,
6778
+ blocksInfo: blocksInfo2 = {
6755
6779
  labels: {},
6756
6780
  counter: 0
6757
- },
6758
- mappings = []
6781
+ }
6759
6782
  } = {}) {
6760
6783
  transpilerConfig.preprocessorDelimiter ?? (transpilerConfig.preprocessorDelimiter = "\u0294");
6761
6784
  transpilerConfig.injectTraceLabels ?? (transpilerConfig.injectTraceLabels = injectTraceLabels);
@@ -6817,18 +6840,31 @@ function transpileJSX(jsx2, {
6817
6840
  }
6818
6841
  node3.children = node3.children.filter((x) => x !== "");
6819
6842
  if (transpilerConfig.setBlockLabels && !node3.already_labeled) {
6820
- labelFunctions(node3, eols, blocks_info2);
6843
+ labelFunctions(node3, eols, blocksInfo2);
6821
6844
  }
6822
6845
  }
6823
6846
  };
6824
6847
  prepare(json);
6825
6848
  preprocessPragmas(json);
6849
+ const flattened_nodes = [];
6826
6850
  const codify = (outlen, node3, is_attr = false, is_xml = false) => {
6827
- if (typeof node3 !== "object") return node3;
6851
+ flattened_nodes.push(node3);
6852
+ if (typeof node3 !== "object") {
6853
+ if (referentiateImports && typeof node3 === "string") {
6854
+ if (meta?.imported_names.has(node3)) {
6855
+ let j = flattened_nodes.length - 2;
6856
+ while (typeof flattened_nodes[j] === "string" && flattened_nodes[j].trim() === "" || typeof flattened_nodes[j] === "object" && flattened_nodes[j].type === "comment") j--;
6857
+ if (typeof flattened_nodes[j] !== "string" || flattened_nodes[j] !== ".") {
6858
+ return importsObjectVar + "." + node3;
6859
+ }
6860
+ }
6861
+ }
6862
+ return node3;
6863
+ }
6828
6864
  if (node3 === null) return "";
6829
6865
  node3.out_index = outlen;
6830
6866
  if (node3.type === "string") return jsx2.substring(node3.begin, node3.end);
6831
- if (node3.type === "import") return node3.cjs;
6867
+ if (node3.type === "import") return referentiateImports ? "" : node3.cjs;
6832
6868
  if (node3.type === "export") return node3.cjs;
6833
6869
  if (node3.type === "regex") return jsx2.substring(node3.begin, node3.end);
6834
6870
  if (node3.type === "comment") return discardComments || is_attr ? "" : jsx2.substring(node3.begin, node3.end);
@@ -6836,7 +6872,7 @@ function transpileJSX(jsx2, {
6836
6872
  if (node3.type === "parenthesis") {
6837
6873
  let out2 = "(";
6838
6874
  if (node3.out) {
6839
- if (produceCJS) processImportExports(node3, jsx2);
6875
+ if (produceCJS || referentiateImports) processImportExports(node3, jsx2, meta);
6840
6876
  for (const ch2 of node3.out) {
6841
6877
  out2 += codify(outlen + out2.length - 1, ch2);
6842
6878
  }
@@ -6846,7 +6882,7 @@ function transpileJSX(jsx2, {
6846
6882
  if (node3.type === "js") {
6847
6883
  let out2 = "";
6848
6884
  if (node3.out) {
6849
- if (produceCJS) processImportExports(node3, jsx2);
6885
+ if (produceCJS || referentiateImports) processImportExports(node3, jsx2, meta);
6850
6886
  for (const ch2 of node3.out) {
6851
6887
  if (is_xml && ch2.type === "comment") continue;
6852
6888
  out2 += codify(outlen + out2.length - (is_attr ? 1 : 0), ch2);
@@ -6861,6 +6897,9 @@ function transpileJSX(jsx2, {
6861
6897
  return out2;
6862
6898
  }
6863
6899
  if (node3.type === "xml") {
6900
+ if (referentiateImports && meta?.imported_names?.has(node3.tag) && node3.tag[0] === node3.tag[0].toUpperCase()) {
6901
+ node3.tag = importsObjectVar + "." + node3.tag;
6902
+ }
6864
6903
  if (node3.tag.length === 0) {
6865
6904
  node3.tag = fragment;
6866
6905
  } else if (node3.tag[0] !== node3.tag[0].toUpperCase()) {
@@ -6896,14 +6935,17 @@ function transpileJSX(jsx2, {
6896
6935
  };
6897
6936
  let out = "";
6898
6937
  if (injectTraceLabels) {
6899
- out = `/*LILACTBLOCK${++blocks_info2.counter}:0,0:<EXEC>*/try{`;
6938
+ out = `/*LILACTBLOCK${++blocksInfo2.counter}:0,0:<EXEC>*/try{`;
6939
+ }
6940
+ if (referentiateImports) {
6941
+ out += `const ${importsObjectVar} = ${importsObject};`;
6900
6942
  }
6901
6943
  out += codify(out.length, json);
6902
6944
  if (injectTraceLabels) {
6903
6945
  if (transpilerConfig.enableLabelStack) {
6904
- out += `}catch(e){ if(typeof(e)!=='object') e=new Error(e);e.lilact_trace=[${blocks_info2.counter},e.lilact_trace];throw e}`;
6946
+ out += `}catch(e){ if(typeof(e)!=='object') e=new Error(e);e.lilact_trace=[${blocksInfo2.counter},e.lilact_trace];throw e}`;
6905
6947
  } else {
6906
- out += `}catch(e){ if(typeof(e)!=='object') e=new Error(e);e.lilact_trace=${blocks_info2.counter};throw e}`;
6948
+ out += `}catch(e){ if(typeof(e)!=='object') e=new Error(e);e.lilact_trace=${blocksInfo2.counter};throw e}`;
6907
6949
  }
6908
6950
  }
6909
6951
  const inline_sm = generateSourceMap(json, path2, eols, scanEOLs(out), mappings);
@@ -7013,7 +7055,8 @@ export {
7013
7055
  TransitionGroup,
7014
7056
  addWrappedEventListener,
7015
7057
  animationFramePromise,
7016
- blocks_info,
7058
+ asError2 as asError,
7059
+ blocksInfo,
7017
7060
  boolean_html_attributes_set,
7018
7061
  capture_events_set,
7019
7062
  clearInterval,