lilact 0.26.15 → 0.26.16

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 (34) hide show
  1. package/dist/lilact.development.js +526 -290
  2. package/dist/lilact.development.js.map +3 -3
  3. package/dist/lilact.development.min.js +63 -54
  4. package/dist/lilact.development.min.js.map +3 -3
  5. package/dist/lilact.production.min.js +63 -54
  6. package/docs/assets/navigation.js +1 -1
  7. package/docs/assets/search.js +1 -1
  8. package/docs/functions/errors.globalErrorHandler.html +2 -8
  9. package/docs/functions/errors.mapLocation.html +1 -0
  10. package/docs/functions/errors.scanBlockLabels.html +2 -0
  11. package/docs/functions/errors.traceError.html +3 -7
  12. package/docs/functions/run.lazy.html +2 -13
  13. package/docs/functions/run.require.html +2 -9
  14. package/docs/functions/run.run.html +2 -5
  15. package/docs/functions/run.runScripts.html +1 -7
  16. package/docs/functions/timers.timeoutPromise.html +2 -2
  17. package/docs/modules/errors.html +1 -1
  18. package/docs/static/lilact.development.js +526 -290
  19. package/docs/static/lilact.development.js.map +3 -3
  20. package/docs/static/lilact.development.min.js +63 -54
  21. package/docs/static/lilact.development.min.js.map +3 -3
  22. package/docs/static/lilact.production.min.js +63 -54
  23. package/docs/variables/errors.blocks_info.html +1 -0
  24. package/docs/variables/errors.error.html +1 -0
  25. package/examples/lilact.development.js +526 -290
  26. package/examples/lilact.development.js.map +3 -3
  27. package/examples/lilact.development.min.js +63 -54
  28. package/examples/lilact.development.min.js.map +3 -3
  29. package/examples/lilact.production.min.js +63 -54
  30. package/package.json +1 -1
  31. package/src/errors.jsx +525 -241
  32. package/src/jsx.js +2 -2
  33. package/src/lilact.jsx +1 -1
  34. package/src/run.jsx +347 -263
@@ -1417,9 +1417,9 @@ function handleInterpolation(mergedProps, registered, interpolation) {
1417
1417
  case "function": {
1418
1418
  if (mergedProps !== void 0) {
1419
1419
  var previousCursor = cursor;
1420
- var result = interpolation(mergedProps);
1420
+ var result2 = interpolation(mergedProps);
1421
1421
  cursor = previousCursor;
1422
- return handleInterpolation(mergedProps, registered, result);
1422
+ return handleInterpolation(mergedProps, registered, result2);
1423
1423
  }
1424
1424
  break;
1425
1425
  }
@@ -1927,8 +1927,8 @@ var forwardRef = (render2) => {
1927
1927
  };
1928
1928
  function getComponentByPointer() {
1929
1929
  let resolve_func;
1930
- const pr = new Promise((res2, rej) => {
1931
- resolve_func = res2;
1930
+ const pr = new Promise((res, rej) => {
1931
+ resolve_func = res;
1932
1932
  });
1933
1933
  function click_handler(event2) {
1934
1934
  event2.stopImmediatePropagation();
@@ -2528,8 +2528,8 @@ var ComponentCore = class {
2528
2528
  this.outlet.splice(i2, 1);
2529
2529
  i2--;
2530
2530
  } else if (typeof item === "function") {
2531
- const res2 = this.childFunctionHandler(item);
2532
- this.outlet.splice(i2, 1, res2);
2531
+ const res = this.childFunctionHandler(item);
2532
+ this.outlet.splice(i2, 1, res);
2533
2533
  i2--;
2534
2534
  } else if (item.constructor.name === "Array") {
2535
2535
  this.outlet.splice(i2, 1, ...item);
@@ -3601,181 +3601,263 @@ __export(run_exports, {
3601
3601
  runScripts: () => runScripts
3602
3602
  });
3603
3603
  function joinPaths(basePath, relativePath) {
3604
- const isAbs = relativePath.startsWith("/");
3604
+ const isAbsolute = relativePath.startsWith("/");
3605
3605
  const stack = [];
3606
- const parts = (isAbs ? "" : basePath).split("/").filter(Boolean);
3607
- for (const p of parts) stack.push(p);
3608
- if (!basePath.endsWith("/")) stack.pop();
3609
- const relParts = relativePath.split("/");
3610
- for (const p of relParts) {
3611
- if (p === "" || p === ".") continue;
3612
- if (p === "..") {
3606
+ const parts = (isAbsolute ? "" : basePath).split("/").filter(Boolean);
3607
+ for (const part of parts) {
3608
+ stack.push(part);
3609
+ }
3610
+ if (!basePath.endsWith("/")) {
3611
+ stack.pop();
3612
+ }
3613
+ for (const part of relativePath.split("/")) {
3614
+ if (part === "" || part === ".") continue;
3615
+ if (part === "..") {
3613
3616
  if (stack.length > 0) stack.pop();
3614
3617
  } else {
3615
- stack.push(p);
3618
+ stack.push(part);
3616
3619
  }
3617
3620
  }
3618
- return (isAbs ? "/" : "") + stack.join("/");
3621
+ return `${isAbsolute ? "/" : ""}${stack.join("/")}`;
3622
+ }
3623
+ function asError(value, fallbackMessage = "Unknown error") {
3624
+ if (value instanceof Error) return value;
3625
+ if (value && typeof value === "object") {
3626
+ if (value.error instanceof Error) return value.error;
3627
+ const error2 = new Error(
3628
+ value.message == null ? fallbackMessage : String(value.message)
3629
+ );
3630
+ if (value.name) error2.name = value.name;
3631
+ if (value.stack) {
3632
+ Object.defineProperty(error2, "stack", {
3633
+ value: value.stack,
3634
+ configurable: true
3635
+ });
3636
+ }
3637
+ for (const key of Object.keys(value)) {
3638
+ if (!(key in error2)) error2[key] = value[key];
3639
+ }
3640
+ return error2;
3641
+ }
3642
+ return new Error(
3643
+ value == null ? fallbackMessage : String(value)
3644
+ );
3645
+ }
3646
+ function attachPath(error2, path2) {
3647
+ const result2 = asError(error2);
3648
+ if (result2.fileName == null) result2.fileName = path2;
3649
+ return result2;
3650
+ }
3651
+ function reportRuntimeError(error2, path2) {
3652
+ const withPath = attachPath(error2, path2);
3653
+ if (typeof lilact_default.traceError === "function") {
3654
+ return lilact_default.traceError(withPath, path2);
3655
+ }
3656
+ lilact_default.error = withPath;
3657
+ return withPath;
3619
3658
  }
3620
3659
  var required_scripts = {};
3621
- function run(jsx, path = `InlineJSX-${++lilact_default.eval_num}`, { isInline, isModule } = { isInline: true, isModule: true }) {
3660
+ function run(jsx, path = `InlineJSX-${++lilact_default.eval_num}`, {
3661
+ isInline = true,
3662
+ isModule = true
3663
+ } = {}) {
3622
3664
  const mappings = [];
3623
3665
  const module = {
3624
3666
  mappings,
3625
3667
  isInline,
3668
+ isModule,
3626
3669
  path,
3627
- code: jsx,
3670
+ code: String(jsx),
3628
3671
  exports: {}
3629
3672
  };
3630
- let processed;
3631
3673
  required_scripts[path] = module;
3674
+ let processed;
3632
3675
  try {
3633
- processed = lilact_default.transpileJSX(
3634
- jsx,
3635
- {
3636
- path,
3637
- mappings,
3638
- factory: "createComponent",
3639
- appendSourcemap: false,
3640
- injectTraceLabels: true,
3641
- produceCJS: true,
3642
- blocks_info: lilact_default.blocks_info
3643
- }
3644
- );
3645
- } catch (e) {
3646
- lilact_default.error = e;
3647
- throw e;
3676
+ processed = lilact_default.transpileJSX(String(jsx), {
3677
+ path,
3678
+ mappings,
3679
+ factory: "createComponent",
3680
+ appendSourcemap: false,
3681
+ injectTraceLabels: true,
3682
+ produceCJS: true,
3683
+ blocks_info: lilact_default.blocks_info
3684
+ });
3685
+ } catch (error2) {
3686
+ const parserError = attachPath(error2, path);
3687
+ parserError.sourcePhase = "transpile";
3688
+ module.error = parserError;
3689
+ lilact_default.error = parserError;
3690
+ throw parserError;
3648
3691
  }
3649
3692
  if (true) {
3650
- required_scripts[path].processed = processed;
3693
+ module.processed = processed;
3694
+ }
3695
+ processed = `${processed}
3696
+ //# sourceURL=eval:/${path}`;
3697
+ if (typeof lilact_default.scanBlockLabels === "function") {
3698
+ lilact_default.scanBlockLabels(processed, path);
3651
3699
  }
3652
- processed += "\n//# sourceURL=eval:/" + path;
3653
- lilact_default.scanBlockLabels(processed, path);
3654
3700
  try {
3655
3701
  globalThis.Lilact = lilact_default;
3656
3702
  globalThis.createComponent = lilact_default.createComponent;
3657
3703
  globalThis.Fragment = lilact_default.Fragment;
3658
- const res = eval(processed);
3659
- if (!isEmpty(module.exports)) return module.exports;
3660
- return res;
3661
- } catch (e) {
3662
- e = lilact_default.traceError(e, path);
3663
- throw e;
3704
+ const result = eval(processed);
3705
+ if (!isEmpty(module.exports)) {
3706
+ return module.exports;
3707
+ }
3708
+ return result;
3709
+ } catch (error2) {
3710
+ const runtimeError = reportRuntimeError(error2, path);
3711
+ runtimeError.sourcePhase = "runtime";
3712
+ module.error = runtimeError;
3713
+ throw runtimeError;
3664
3714
  }
3665
3715
  }
3666
3716
  function require2(path2) {
3667
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
3668
- let forceUpdate, checkExport, requirer, isLazy;
3669
- if (arguments.length === 2 && typeof (arguments[1] === "object")) {
3670
- forceUpdate = (_a = arguments[1]) == null ? void 0 : _a.forceUpdate;
3671
- checkExport = (_b = arguments[1]) == null ? void 0 : _b.checkExport;
3672
- requirer = (_c = arguments[1]) == null ? void 0 : _c.requirer;
3673
- isLazy = (_d = arguments[1]) == null ? void 0 : _d.isLazy;
3674
- }
3675
- if ((_e = lilact_default.importObjectPaths) == null ? void 0 : _e[path2]) return lilact_default.importObjectPaths[path2];
3676
- if (required_scripts[path2] && !forceUpdate) return required_scripts[path2].exports;
3717
+ var _a, _b, _c, _d, _e, _f;
3718
+ let forceUpdate;
3719
+ let checkExport;
3720
+ let requirer;
3721
+ let isLazy;
3722
+ if (arguments.length === 2 && arguments[1] && typeof arguments[1] === "object") {
3723
+ forceUpdate = arguments[1].forceUpdate;
3724
+ checkExport = arguments[1].checkExport;
3725
+ requirer = arguments[1].requirer;
3726
+ isLazy = arguments[1].isLazy;
3727
+ }
3728
+ if ((_a = lilact_default.importObjectPaths) == null ? void 0 : _a[path2]) {
3729
+ return lilact_default.importObjectPaths[path2];
3730
+ }
3731
+ if (required_scripts[path2] && !forceUpdate) {
3732
+ return required_scripts[path2].exports;
3733
+ }
3677
3734
  if (path2[0] === "#") {
3678
- const el = document.getElementById(path2);
3679
- if (el) {
3680
- return run(el.innerText, path2);
3681
- }
3682
- throw new Error(`Required element not found (${path2})`);
3683
- } else {
3684
- if (requirer && requirer.path) {
3685
- path2 = joinPaths(requirer.path, path2);
3686
- }
3687
- if (((_f = lilact_default) == null ? void 0 : _f[LAZY]) || isLazy) {
3688
- lilact_default[LAZY] = false;
3689
- let p = (_h = (_g = lilact_default).resolver) == null ? void 0 : _h.call(_g, path2);
3690
- if (p) {
3691
- p = Promise.resolve(p);
3692
- } else {
3693
- p = fetch(path2).then((res2) => {
3694
- if (!res2.ok) throw new Error(`HTTP ${res2.status}`);
3695
- return res2.text();
3696
- });
3697
- }
3698
- return p.then((res2) => {
3699
- var _a2;
3700
- if (path2.endsWith(".css")) {
3701
- injectGlobal(res2);
3702
- return;
3735
+ const element = document.getElementById(path2.slice(1));
3736
+ if (!element) {
3737
+ const error3 = new Error(
3738
+ `Required element not found (${path2})`
3739
+ );
3740
+ error3.fileName = path2;
3741
+ throw error3;
3742
+ }
3743
+ return run(element.textContent || "", path2);
3744
+ }
3745
+ if (requirer == null ? void 0 : requirer.path) {
3746
+ path2 = joinPaths(requirer.path, path2);
3747
+ }
3748
+ const loadAsync = Boolean((_b = lilact_default) == null ? void 0 : _b[LAZY]) || Boolean(isLazy);
3749
+ if (loadAsync) {
3750
+ lilact_default[LAZY] = false;
3751
+ let request2 = (_d = (_c = lilact_default).resolver) == null ? void 0 : _d.call(_c, path2);
3752
+ if (request2 === void 0 || request2 === null) {
3753
+ request2 = fetch(path2).then((response) => {
3754
+ if (!response.ok) {
3755
+ const error3 = new Error(
3756
+ `Unable to load ${path2}: HTTP ${response.status}`
3757
+ );
3758
+ error3.fileName = path2;
3759
+ throw error3;
3703
3760
  }
3704
- res2 = run(res2, path2, { isInline: false });
3705
- return (_a2 = res2 == null ? void 0 : res2.default) != null ? _a2 : res2;
3706
- }).catch((err) => {
3707
- throw err;
3761
+ return response.text();
3708
3762
  });
3709
3763
  } else {
3710
- const p = (_j = (_i = lilact_default).resolver) == null ? void 0 : _j.call(_i, path2);
3711
- if (p) {
3712
- if (path2.endsWith(".css")) {
3713
- injectGlobal(p);
3714
- return;
3715
- }
3716
- return run(p, path2, { isInline: false });
3717
- } else {
3718
- const request = new XMLHttpRequest();
3719
- request.open("GET", path2, false);
3720
- request.send(null);
3721
- if (request.status === 200) {
3722
- if (path2.endsWith(".css")) {
3723
- injectGlobal(res);
3724
- return;
3725
- }
3726
- return run(request.responseText, path2, { isInline: false });
3727
- }
3764
+ request2 = Promise.resolve(request2);
3765
+ }
3766
+ return request2.then((source) => {
3767
+ if (path2.endsWith(".css")) {
3768
+ injectGlobal(String(source));
3769
+ return;
3728
3770
  }
3771
+ return run(String(source), path2, {
3772
+ isInline: false,
3773
+ isModule: true
3774
+ });
3775
+ }).then((result2) => {
3776
+ var _a2;
3777
+ if (path2.endsWith(".css")) return result2;
3778
+ return (_a2 = result2 == null ? void 0 : result2.default) != null ? _a2 : result2;
3779
+ }).catch((error3) => {
3780
+ throw reportRuntimeError(error3, path2);
3781
+ });
3782
+ }
3783
+ const resolved = (_f = (_e = lilact_default).resolver) == null ? void 0 : _f.call(_e, path2);
3784
+ if (resolved !== void 0 && resolved !== null) {
3785
+ if (path2.endsWith(".css")) {
3786
+ injectGlobal(String(resolved));
3787
+ return;
3729
3788
  }
3789
+ return run(String(resolved), path2, {
3790
+ isInline: false,
3791
+ isModule: true
3792
+ });
3730
3793
  }
3731
- throw new Error(`Required resource not found (${path2})`);
3794
+ const request = new XMLHttpRequest();
3795
+ try {
3796
+ request.open("GET", path2, false);
3797
+ request.send(null);
3798
+ } catch (error3) {
3799
+ throw reportRuntimeError(error3, path2);
3800
+ }
3801
+ if (request.status >= 200 && request.status < 300) {
3802
+ if (path2.endsWith(".css")) {
3803
+ injectGlobal(request.responseText);
3804
+ return;
3805
+ }
3806
+ return run(request.responseText, path2, {
3807
+ isInline: false,
3808
+ isModule: true
3809
+ });
3810
+ }
3811
+ const error2 = new Error(
3812
+ `Unable to load ${path2}: HTTP ${request.status || 0}`
3813
+ );
3814
+ error2.fileName = path2;
3815
+ throw error2;
3732
3816
  }
3733
3817
  function lazy(factory) {
3734
3818
  let status = "pending";
3735
- let result;
3819
+ let result2;
3736
3820
  lilact_default[LAZY] = true;
3737
- result = factory();
3738
- if (lilact_default.isThenable(result)) {
3739
- result.then(
3740
- (mod) => {
3821
+ try {
3822
+ result2 = factory();
3823
+ } catch (error2) {
3824
+ status = "error";
3825
+ result2 = error2;
3826
+ }
3827
+ if (lilact_default.isThenable(result2)) {
3828
+ result2.then(
3829
+ (module2) => {
3741
3830
  status = "success";
3742
- result = mod;
3743
- return result;
3831
+ result2 = module2;
3744
3832
  },
3745
- (err) => {
3833
+ (error2) => {
3746
3834
  status = "error";
3747
- result = err;
3748
- throw err;
3835
+ result2 = error2;
3749
3836
  }
3750
3837
  );
3751
- } else {
3838
+ } else if (status !== "error") {
3752
3839
  status = "success";
3753
3840
  }
3754
3841
  function LazyComponent(props) {
3755
- if (status === "pending") throw result;
3756
- if (status === "error") throw result;
3757
- const Component2 = result;
3842
+ if (status === "pending") throw result2;
3843
+ if (status === "error") throw result2;
3844
+ const Component2 = result2;
3758
3845
  return createComponent(Component2, { ...props });
3759
3846
  }
3760
3847
  return LazyComponent;
3761
3848
  }
3762
3849
  function scanScriptTagsWithType() {
3763
- const scripts = Array.from(
3850
+ return Array.from(
3764
3851
  document.querySelectorAll('script[type="text/jsx"]')
3765
- );
3766
- return scripts.map((el) => {
3767
- var _a, _b;
3768
- return {
3769
- src: (_a = el.getAttribute("src")) != null ? _a : null,
3770
- content: (_b = el.textContent) != null ? _b : ""
3771
- };
3772
- });
3852
+ ).map((element) => ({
3853
+ src: element.getAttribute("src"),
3854
+ content: element.textContent || ""
3855
+ }));
3773
3856
  }
3774
3857
  function runScripts() {
3775
- const scripts = scanScriptTagsWithType();
3776
- for (const s of scripts) {
3777
- if (s.src) require2(s.src);
3778
- if (s.content) run(s.content);
3858
+ for (const script of scanScriptTagsWithType()) {
3859
+ if (script.src) require2(script.src);
3860
+ if (script.content) run(script.content);
3779
3861
  }
3780
3862
  }
3781
3863
 
@@ -3922,8 +4004,8 @@ function releaseTimers() {
3922
4004
  }
3923
4005
  function timeoutPromise(duration = 0, timerSource = Lilact) {
3924
4006
  let id, resolve, reject;
3925
- const promise = new Promise((res2, rej) => {
3926
- resolve = res2;
4007
+ const promise = new Promise((res, rej) => {
4008
+ resolve = res;
3927
4009
  reject = rej;
3928
4010
  id = timerSource.setTimeout(() => {
3929
4011
  resolve();
@@ -4331,8 +4413,8 @@ function wrapListener(fn, opts = {}) {
4331
4413
  const currentTarget = this || nativeEvent.currentTarget || null;
4332
4414
  const sEvent = createSyntheticEvent(nativeEvent, currentTarget);
4333
4415
  try {
4334
- const result = fn(sEvent);
4335
- if (stopPropagationOnTrueReturn && result === true) {
4416
+ const result2 = fn(sEvent);
4417
+ if (stopPropagationOnTrueReturn && result2 === true) {
4336
4418
  sEvent.stopPropagation();
4337
4419
  }
4338
4420
  } finally {
@@ -4447,166 +4529,319 @@ __export(errors_exports, {
4447
4529
  blocks_info: () => blocks_info,
4448
4530
  error: () => error,
4449
4531
  globalErrorHandler: () => globalErrorHandler,
4532
+ mapLocation: () => mapLocation,
4450
4533
  scanBlockLabels: () => scanBlockLabels,
4451
4534
  traceError: () => traceError
4452
4535
  });
4453
- function getErrorLocation(err) {
4454
- if (err.lineno !== void 0 || err.line !== void 0 || err.lineNumber !== void 0) {
4455
- const l = err.lineNumber || err.lineno || err.line;
4456
- const c = err.columnNumber || err.colno || err.column;
4457
- return { line: l, col: c };
4536
+ function numberOrNull(value) {
4537
+ const n = Number(value);
4538
+ return Number.isFinite(n) ? n : null;
4539
+ }
4540
+ function firstNumber(...values) {
4541
+ for (const value of values) {
4542
+ const n = numberOrNull(value);
4543
+ if (n !== null) return n;
4458
4544
  }
4459
- let match2 = /:(\d+):(\d+)[\n].*/m.exec(err.stack);
4460
- if (match2 === null) {
4461
- match2 = /:(\d+):(\d+)\)\s+at .*/m.exec(err.stack);
4545
+ return null;
4546
+ }
4547
+ function asError2(value) {
4548
+ if (value instanceof Error) return value;
4549
+ if (value && typeof value === "object") {
4550
+ if (value.error instanceof Error) return value.error;
4551
+ const error2 = new Error(
4552
+ value.message == null ? String(value) : String(value.message)
4553
+ );
4554
+ if (value.name) error2.name = value.name;
4555
+ if (value.stack) error2.stack = value.stack;
4556
+ for (const key of Object.keys(value)) {
4557
+ if (!(key in error2)) error2[key] = value[key];
4558
+ }
4559
+ return error2;
4462
4560
  }
4463
- if (match2) {
4464
- return { line: parseInt(match2[1]), col: parseInt(match2[2]) };
4561
+ return new Error(String(value));
4562
+ }
4563
+ function isParserError(error2) {
4564
+ return (error2 == null ? void 0 : error2.name) === "JSXParserError";
4565
+ }
4566
+ function getErrorLocation(error2, { zeroBased = false } = {}) {
4567
+ const line2 = firstNumber(
4568
+ error2 == null ? void 0 : error2.lineNumber,
4569
+ error2 == null ? void 0 : error2.lineno,
4570
+ error2 == null ? void 0 : error2.line
4571
+ );
4572
+ const column2 = firstNumber(
4573
+ error2 == null ? void 0 : error2.columnNumber,
4574
+ error2 == null ? void 0 : error2.colno,
4575
+ error2 == null ? void 0 : error2.column
4576
+ );
4577
+ if (line2 !== null || column2 !== null) {
4578
+ return {
4579
+ line: line2 === null ? null : zeroBased ? line2 : Math.max(0, line2 - 1),
4580
+ col: column2 === null ? null : zeroBased ? column2 : Math.max(0, column2 - 1)
4581
+ };
4465
4582
  }
4466
4583
  return null;
4467
4584
  }
4468
- function parseEvalLocationFromStack(stack, urlPrefix = "eval:/") {
4469
- const raw = typeof stack === "string" ? stack : String(stack || "");
4470
- const lines = raw.split(/\r?\n/);
4471
- const re = new RegExp(`\\(?((?:${escapeRegExp(urlPrefix)})[^\\s):]+):(\\d+):(?:(\\d+))?\\)?$`);
4472
- for (const l of lines) {
4473
- const line2 = l.trim();
4474
- if (!line2.includes(urlPrefix)) continue;
4475
- const m = line2.match(re);
4476
- if (!m) continue;
4477
- const url = m[1];
4478
- const parsedLine = Number(m[2]);
4479
- const parsedCol = m[3] == null ? null : Number(m[3]);
4480
- if (Number.isFinite(parsedLine) && (parsedCol === null || Number.isFinite(parsedCol))) {
4481
- return { url, line: parsedLine, col: parsedCol, matched: line2 };
4482
- }
4483
- }
4484
- return { url: null, line: null, col: null, matched: null, stackPreview: lines.slice(0, 6).join("\n") };
4485
- }
4486
- function escapeRegExp(s) {
4487
- return String(s).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4488
- }
4489
- function mapLocation(mps, r, c) {
4490
- let map = null;
4491
- for (const i2 in mps) {
4492
- if (mps[i2][0] < r) continue;
4493
- if (mps[i2][0] > r || mps[i2][0] === r && mps[i2][1] >= c) {
4494
- map = mps[i2 - 1];
4495
- break;
4496
- }
4585
+ function sourceUrlFromStack(stack) {
4586
+ const text = typeof stack === "string" ? stack : "";
4587
+ const expression = /(?:^|[\s(@])((?:eval:\/)[\s\S]*):(\d+):(\d+)(?:\)?$)/;
4588
+ for (const line2 of text.split(/\r?\n/)) {
4589
+ const match2 = line2.trim().match(expression);
4590
+ if (!match2) continue;
4591
+ return {
4592
+ url: match2[1],
4593
+ line: Number(match2[2]),
4594
+ col: Number(match2[3])
4595
+ };
4497
4596
  }
4498
- if (!map) map = mps[mps.length - 1];
4499
- return { line: r - map[0] + map[2], col: r - map[0] === 0 ? map[3] : 0 };
4597
+ return null;
4500
4598
  }
4501
- function scanBlockLabels(code2, path2) {
4502
- const ls = Array.from(code2.matchAll(/LILACTBLOCK(\d+):(\d+),(\d+):([^*]+)\*\//mg));
4503
- ls.forEach(
4504
- (x) => {
4505
- lilact_default.blocks_info.labels[x[1]] = {
4506
- path: path2,
4507
- desc: x[4]
4508
- };
4599
+ function sourcePathFromEvalUrl(url) {
4600
+ if (typeof url !== "string") return null;
4601
+ if (url.startsWith("eval:/")) {
4602
+ return url.slice("eval:/".length);
4603
+ }
4604
+ if (url.startsWith("eval:")) {
4605
+ return url.slice("eval:".length).replace(/^\/+/, "");
4606
+ }
4607
+ return null;
4608
+ }
4609
+ function mapLocation(mappings2, generatedLine, generatedColumn) {
4610
+ if (!Array.isArray(mappings2) || mappings2.length === 0) {
4611
+ return {
4612
+ line: generatedLine,
4613
+ col: generatedColumn
4614
+ };
4615
+ }
4616
+ const line2 = Number(generatedLine);
4617
+ const col = Number(generatedColumn);
4618
+ if (!Number.isFinite(line2) || !Number.isFinite(col)) {
4619
+ return {
4620
+ line: null,
4621
+ col: null
4622
+ };
4623
+ }
4624
+ const validMappings = mappings2.filter(
4625
+ (mapping2) => Array.isArray(mapping2) && mapping2.length >= 4 && Number.isFinite(Number(mapping2[0])) && Number.isFinite(Number(mapping2[1])) && Number.isFinite(Number(mapping2[2])) && Number.isFinite(Number(mapping2[3]))
4626
+ ).slice().sort((a, b2) => {
4627
+ const lineDifference = Number(a[0]) - Number(b2[0]);
4628
+ if (lineDifference !== 0) {
4629
+ return lineDifference;
4509
4630
  }
4510
- );
4631
+ return Number(a[1]) - Number(b2[1]);
4632
+ });
4633
+ if (validMappings.length === 0) {
4634
+ return {
4635
+ line: line2,
4636
+ col
4637
+ };
4638
+ }
4639
+ let mapping = validMappings[0];
4640
+ for (const candidate of validMappings) {
4641
+ const generatedMappingLine = Number(candidate[0]);
4642
+ const generatedMappingColumn = Number(candidate[1]);
4643
+ if (generatedMappingLine < line2 || generatedMappingLine === line2 && generatedMappingColumn <= col) {
4644
+ mapping = candidate;
4645
+ continue;
4646
+ }
4647
+ break;
4648
+ }
4649
+ const mappingGeneratedLine = Number(mapping[0]);
4650
+ const mappingGeneratedColumn = Number(mapping[1]);
4651
+ const mappingSourceLine = Number(mapping[2]);
4652
+ const mappingSourceColumn = Number(mapping[3]);
4653
+ const sourceLine = mappingSourceLine + (line2 - mappingGeneratedLine);
4654
+ const sourceColumn = line2 === mappingGeneratedLine ? Math.max(
4655
+ 0,
4656
+ mappingSourceColumn + (col - mappingGeneratedColumn)
4657
+ ) : mappingSourceColumn;
4658
+ return {
4659
+ line: sourceLine,
4660
+ col: sourceColumn
4661
+ };
4511
4662
  }
4512
- function traceError(error2, run_path) {
4513
- var _a;
4514
- if (error2 == null ? void 0 : error2.is_traced) {
4515
- return error2;
4663
+ function getBlockTrace(error2) {
4664
+ const trace = error2 == null ? void 0 : error2.lilact_trace;
4665
+ if (Array.isArray(trace)) {
4666
+ return trace[0];
4516
4667
  }
4517
- const loc = parseEvalLocationFromStack(error2.stack);
4518
- const obj = {
4519
- fileName: ((_a = loc.url) == null ? void 0 : _a.slice(6)) || run_path || error2.fileName,
4520
- lineNumber: loc.line,
4521
- columnNumber: loc.col,
4522
- message: error2.message,
4523
- name: error2.name,
4524
- stack: error2.stack,
4525
- _error: error2,
4526
- is_traced: true
4668
+ return trace;
4669
+ }
4670
+ function getBlockInfo(error2) {
4671
+ var _a, _b, _c;
4672
+ const trace = getBlockTrace(error2);
4673
+ if (trace === void 0 || trace === null) {
4674
+ return null;
4675
+ }
4676
+ return (_c = (_b = (_a = lilact_default.blocks_info) == null ? void 0 : _a.labels) == null ? void 0 : _b[trace]) != null ? _c : null;
4677
+ }
4678
+ function applyBlockFallback(error2, result2, currentPath) {
4679
+ const block = getBlockInfo(error2);
4680
+ if (!block) return result2;
4681
+ if (block.path) {
4682
+ result2.fileName = block.path;
4683
+ } else if (!result2.fileName) {
4684
+ result2.fileName = currentPath;
4685
+ }
4686
+ if (Number.isFinite(block.line) && Number.isFinite(block.col)) {
4687
+ result2.lineNumber = block.line;
4688
+ result2.columnNumber = block.col;
4689
+ }
4690
+ if (block.desc) {
4691
+ result2.label = block.desc;
4692
+ }
4693
+ return result2;
4694
+ }
4695
+ function copyErrorMetadata(source, target) {
4696
+ if (!source || typeof source !== "object") return;
4697
+ for (const key of [
4698
+ "fileName",
4699
+ "lineNumber",
4700
+ "columnNumber",
4701
+ "lineno",
4702
+ "colno",
4703
+ "line",
4704
+ "column",
4705
+ "componentStackLog",
4706
+ "lilact_trace"
4707
+ ]) {
4708
+ if (source[key] !== void 0 && target[key] === void 0) {
4709
+ target[key] = source[key];
4710
+ }
4711
+ }
4712
+ }
4713
+ function traceError(value, runPath) {
4714
+ var _a, _b;
4715
+ if (value == null ? void 0 : value.isTraced) return value;
4716
+ const original = (value == null ? void 0 : value.error) instanceof Error ? value.error : asError2(value);
4717
+ const parserError = isParserError(original);
4718
+ const stackLocation = parserError ? null : sourceUrlFromStack(original.stack);
4719
+ const eventLocation = parserError ? getErrorLocation(original, { zeroBased: true }) : getErrorLocation(original);
4720
+ const result2 = {
4721
+ fileName: sourcePathFromEvalUrl(stackLocation == null ? void 0 : stackLocation.url) || original.fileName || runPath || null,
4722
+ lineNumber: (stackLocation == null ? void 0 : stackLocation.line) != null ? Math.max(0, stackLocation.line - 1) : (_a = eventLocation == null ? void 0 : eventLocation.line) != null ? _a : null,
4723
+ columnNumber: (stackLocation == null ? void 0 : stackLocation.col) != null ? Math.max(0, stackLocation.col - 1) : (_b = eventLocation == null ? void 0 : eventLocation.col) != null ? _b : null,
4724
+ message: original.message == null ? String(original) : String(original.message),
4725
+ name: original.name || "Error",
4726
+ stack: original.stack || null,
4727
+ _error: original,
4728
+ isTraced: true
4527
4729
  };
4528
- if (error2.name !== "JSXParseError") {
4529
- let mps;
4530
- if (loc.url) {
4531
- const rm = required_scripts[obj.fileName];
4532
- mps = rm.mappings;
4533
- const mloc = mapLocation(mps, obj.lineNumber - 1, obj.columnNumber - 1);
4534
- obj.lineNumber = mloc.line;
4535
- obj.columnNumber = mloc.col;
4536
- } else {
4537
- let loc2 = getErrorLocation(error2);
4538
- if (error2.lilact_trace !== void 0) {
4539
- let mps2;
4540
- let blk;
4541
- if (typeof error2.lilact_trace === "object") {
4542
- blk = lilact_default.blocks_info.labels[error2.lilact_trace[0]];
4543
- } else {
4544
- blk = lilact_default.blocks_info.labels[error2.lilact_trace];
4545
- }
4546
- if (blk) {
4547
- obj.fileName = blk.path;
4548
- obj.label = blk.label;
4549
- mps2 = required_scripts[blk.path].mappings;
4550
- loc2 = mapLocation(mps2, loc2.line - 1, loc2.col - 1);
4551
- }
4552
- }
4553
- obj.lineNumber = loc2.line;
4554
- obj.columnNumber = loc2.col;
4730
+ copyErrorMetadata(value, result2);
4731
+ copyErrorMetadata(original, result2);
4732
+ if (!parserError && (stackLocation == null ? void 0 : stackLocation.url)) {
4733
+ const module2 = required_scripts[result2.fileName];
4734
+ if (module2 == null ? void 0 : module2.mappings) {
4735
+ const mapped = mapLocation(
4736
+ module2.mappings,
4737
+ result2.lineNumber,
4738
+ result2.columnNumber
4739
+ );
4740
+ result2.lineNumber = mapped.line;
4741
+ result2.columnNumber = mapped.col;
4742
+ }
4743
+ }
4744
+ if (!parserError && !(stackLocation == null ? void 0 : stackLocation.url)) {
4745
+ applyBlockFallback(original, result2, runPath);
4746
+ }
4747
+ lilact_default.error = result2;
4748
+ return result2;
4749
+ }
4750
+ function escapeHtml(value) {
4751
+ return String(value != null ? value : "").replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
4752
+ }
4753
+ function sourceExcerpt(module2, zeroBasedLine) {
4754
+ var _a, _b, _c, _d;
4755
+ if (!module2 || !Number.isFinite(zeroBasedLine)) {
4756
+ return null;
4757
+ }
4758
+ const lines = String((_a = module2.code) != null ? _a : "").split(/\r?\n/);
4759
+ const before = (_b = lines[zeroBasedLine - 1]) != null ? _b : "";
4760
+ const current = (_c = lines[zeroBasedLine]) != null ? _c : "";
4761
+ const after = (_d = lines[zeroBasedLine + 1]) != null ? _d : "";
4762
+ return { before, current, after };
4763
+ }
4764
+ function globalErrorHandler(eventOrError) {
4765
+ var _a, _b;
4766
+ const raw = (eventOrError == null ? void 0 : eventOrError.error) instanceof Error ? eventOrError.error : (eventOrError == null ? void 0 : eventOrError.reason) !== void 0 ? eventOrError.reason : eventOrError;
4767
+ const runPath = (eventOrError == null ? void 0 : eventOrError.fileName) || null;
4768
+ const traced = traceError(raw, runPath);
4769
+ const module2 = required_scripts[traced.fileName];
4770
+ const excerpt = sourceExcerpt(module2, traced.lineNumber);
4771
+ const className = css(`
4772
+ background: linear-gradient(135deg, #fff2f2d4, #ffffffd4);
4773
+ backdrop-filter: blur(10px);
4774
+ border: 1px solid rgba(255,255,255,.25);
4775
+ border-radius: 5px;
4776
+ box-shadow: 0 10px 30px rgba(0,0,0,.35);
4777
+ overflow: hidden;
4778
+ min-width: 400px;
4779
+ width: 66%;
4780
+
4781
+ red {
4782
+ color: #d00;
4555
4783
  }
4784
+
4785
+ code {
4786
+ border: 1px solid #0003;
4787
+ overflow: auto;
4788
+ padding: 10px;
4789
+ display: block;
4790
+ }
4791
+ `);
4792
+ const dialog = document.createElement("dialog");
4793
+ dialog.className = className;
4794
+ const location = traced.fileName ? `At ${escapeHtml(traced.fileName)}` : "";
4795
+ const line2 = Number.isFinite(traced.lineNumber) ? `: Line ${traced.lineNumber + 1}` : "";
4796
+ const componentStack = ((_a = traced._error) == null ? void 0 : _a.componentStackLog) || ((_b = traced._error) == null ? void 0 : _b.componentStack) || "";
4797
+ dialog.innerHTML = `
4798
+ <h3><red>Error!</red></h3>
4799
+ <b>${location}${line2}</b><br><br>
4800
+ <b>${escapeHtml(traced.name)}</b>:
4801
+ <span>${escapeHtml(traced.message)}</span>
4802
+ <br><br>
4803
+
4804
+ ${excerpt ? "<code><pre></pre><red><pre></pre></red><pre></pre></code>" : ""}
4805
+
4806
+ ${componentStack ? `
4807
+ <br>
4808
+ Component Stack:
4809
+ <br>
4810
+ <code><pre>${escapeHtml(componentStack)}</pre></code>
4811
+ ` : ""}
4812
+ `;
4813
+ if (excerpt) {
4814
+ const pre = dialog.querySelectorAll("pre");
4815
+ pre[0].innerText = excerpt.before;
4816
+ pre[1].innerText = excerpt.current;
4817
+ pre[2].innerText = excerpt.after;
4818
+ }
4819
+ document.body.appendChild(dialog);
4820
+ if (typeof dialog.showModal === "function") {
4821
+ dialog.showModal();
4556
4822
  } else {
4557
- const loc2 = getErrorLocation(error2);
4558
- if (error2.fileName) obj.fileName = error2.fileName;
4559
- else if (run_path) obj.fileName = run_path;
4560
- obj.lineNumber = loc2.line;
4561
- obj.columnNumber = loc2.col;
4562
- }
4563
- lilact_default.error = obj;
4564
- return obj;
4565
- }
4566
- function globalErrorHandler(error2) {
4567
- if (error2.error) error2 = error2.error;
4568
- error2 = traceError(error2);
4569
- const cls = css(`
4570
- background: linear-gradient(135deg, #fff2f2d4, #ffffffd4);
4571
- backdrop-filter: blur(10px);
4572
- border: 1px solid rgba(255,255,255,.25);
4573
- border-radius: 5px;
4574
- box-shadow: 0 10px 30px rgba(0,0,0,.35);
4575
- overflow:hidden;
4576
- min-width: 400px;
4577
- width: 66%;
4578
- red {
4579
- color:#d00;
4580
- }
4581
- code {
4582
- border: 1px solid #0003;
4583
- overflow: auto;
4584
- padding: 10px;
4585
- display: block;
4586
- }
4587
- `);
4588
- const el = document.createElement("dialog");
4589
- el.className = cls;
4590
- el.innerHTML = `<h3 style=""><red>Error!</red></h3>
4591
- <b>${error2.fileName ? "At " + error2.fileName : ""}
4592
- ${Number.isFinite(error2.lineNumber) ? ": Line " + (error2.lineNumber + 1) : ""}</b><br><br>
4593
- <b>${error2.name}</b>:&nbsp;<span>${error2.message}</span><br><br>
4594
- ${required_scripts[error2.fileName] ? "<code><pre></pre><pre><red></red></pre><pre></pre></code>" : ""}
4595
- ${error2._error.componentStackLog ? "<br>Component Stack:<br><code><pre>" + error2._error.componentStackLog + "</pre></code>" : ""}
4596
- `;
4597
- document.body.appendChild(el);
4598
- const pres = el.querySelectorAll("pre");
4599
- if (required_scripts[error2.fileName]) {
4600
- const lines = required_scripts[error2.fileName].code.split("\n");
4601
- if (lines == null ? void 0 : lines[error2.lineNumber - 1])
4602
- pres[0].innerText = lines[error2.lineNumber - 1];
4603
- if (lines == null ? void 0 : lines[error2.lineNumber]) el.querySelector("pre red").innerText = lines[error2.lineNumber];
4604
- if (lines == null ? void 0 : lines[error2.lineNumber + 1])
4605
- pres[2].innerText = lines[error2.lineNumber + 1];
4606
- }
4607
- el.showModal();
4608
- }
4609
- var blocks_info = { counter: 0, labels: {} };
4823
+ dialog.setAttribute("open", "");
4824
+ }
4825
+ return traced;
4826
+ }
4827
+ function scanBlockLabels(code2, path2) {
4828
+ const labels = String(code2).matchAll(
4829
+ /LILACTBLOCK(\d+):(\d+),(\d+):([^*]+)\*\//gm
4830
+ );
4831
+ for (const match2 of labels) {
4832
+ const id = match2[1];
4833
+ lilact_default.blocks_info.labels[id] = {
4834
+ path: path2,
4835
+ line: Number(match2[2]),
4836
+ col: Number(match2[3]),
4837
+ desc: match2[4]
4838
+ };
4839
+ }
4840
+ }
4841
+ var blocks_info = {
4842
+ counter: 0,
4843
+ labels: {}
4844
+ };
4610
4845
  var error = null;
4611
4846
 
4612
4847
  // .tmp/src/router.jsx
@@ -4623,13 +4858,13 @@ __export(router_exports, {
4623
4858
  var RouterContext = createContext(null);
4624
4859
  var RouteContext = createContext({ params: {} });
4625
4860
  var createURL = (to) => typeof to === "string" ? to : (to.pathname || "") + (to.search || "") + (to.hash || "");
4626
- var escapeRegExp2 = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4861
+ var escapeRegExp = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4627
4862
  function HashRouter({ children, basename = "" }) {
4628
4863
  const readLocation = () => {
4629
4864
  var _a;
4630
4865
  const raw = window.location.hash || "#/";
4631
4866
  const full = raw.slice(1);
4632
- const baseRe = new RegExp("^" + escapeRegExp2(basename));
4867
+ const baseRe = new RegExp("^" + escapeRegExp(basename));
4633
4868
  const withoutBase = full.replace(baseRe, "") || "/";
4634
4869
  const [pathAndSearch, hashPart] = withoutBase.split("#");
4635
4870
  const [path2, search = ""] = pathAndSearch.split("?");
@@ -5306,14 +5541,14 @@ function encode(...value) {
5306
5541
  if (typeof value === "number") {
5307
5542
  return encode_integer(value);
5308
5543
  }
5309
- let result = "";
5544
+ let result2 = "";
5310
5545
  for (let i2 = 0; i2 < value.length; i2 += 1) {
5311
- result += encode_integer(value[i2]);
5546
+ result2 += encode_integer(value[i2]);
5312
5547
  }
5313
- return result;
5548
+ return result2;
5314
5549
  }
5315
5550
  function encode_integer(num) {
5316
- let result = "";
5551
+ let result2 = "";
5317
5552
  if (num < 0) {
5318
5553
  num = -num << 1 | 1;
5319
5554
  } else {
@@ -5325,9 +5560,9 @@ function encode_integer(num) {
5325
5560
  if (num > 0) {
5326
5561
  clamped |= 32;
5327
5562
  }
5328
- result += integer_to_char[clamped];
5563
+ result2 += integer_to_char[clamped];
5329
5564
  } while (num > 0);
5330
- return result;
5565
+ return result2;
5331
5566
  }
5332
5567
 
5333
5568
  // .tmp/src/expscan.js
@@ -6122,8 +6357,8 @@ function parseXML(code2, index2, container2, look_behind = false) {
6122
6357
  index2++;
6123
6358
  skip_spaces();
6124
6359
  while (code2[index2] === "/") {
6125
- const res3 = lookAhead(parseComment, code2, index2);
6126
- if (res3[0] > index2) index2 = res3[0];
6360
+ const res2 = lookAhead(parseComment, code2, index2);
6361
+ if (res2[0] > index2) index2 = res2[0];
6127
6362
  else index2++;
6128
6363
  skip_spaces();
6129
6364
  }
@@ -6172,8 +6407,8 @@ function parseXML(code2, index2, container2, look_behind = false) {
6172
6407
  if (container2) container2.children.push(b2);
6173
6408
  return b2;
6174
6409
  }
6175
- const res2 = lookAhead(parseComment, code2, index2);
6176
- if (res2[0] > index2) index2 = res2[0];
6410
+ const res = lookAhead(parseComment, code2, index2);
6411
+ if (res[0] > index2) index2 = res[0];
6177
6412
  else index2++;
6178
6413
  break;
6179
6414
  case ">":
@@ -6483,7 +6718,7 @@ function transpileJSX(jsx2, {
6483
6718
  const er = new Error(msg);
6484
6719
  if (logErrors) console.error(`JSXParserError: ${msg} [file ${path2} at line ${rc[0]}]`);
6485
6720
  [er.lineNumber, er.columnNumber] = rc;
6486
- er.name = "JSXParseError";
6721
+ er.name = "JSXParserError";
6487
6722
  er.fileName = path2;
6488
6723
  er.lilact_trace = "parse";
6489
6724
  throw er;
@@ -6674,7 +6909,7 @@ document.addEventListener("DOMContentLoaded", () => {
6674
6909
  });
6675
6910
  if (true) {
6676
6911
  window.addEventListener("unhandledrejection", (e) => {
6677
- Lilact2.globalErrorHandler(e.reason);
6912
+ Lilact2.globalErrorHandler(e);
6678
6913
  });
6679
6914
  window.addEventListener("error", (e) => {
6680
6915
  Lilact2.globalErrorHandler(e);
@@ -6764,6 +6999,7 @@ export {
6764
6999
  layout_effects,
6765
7000
  lazy,
6766
7001
  length_css_attributes_set,
7002
+ mapLocation,
6767
7003
  memo,
6768
7004
  passive_effects,
6769
7005
  pauseTimers,