lilact 0.29.1 → 0.29.3

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 (36) hide show
  1. package/dist/lilact.development.js +192 -134
  2. package/dist/lilact.development.js.map +3 -3
  3. package/dist/lilact.development.min.js +23 -23
  4. package/dist/lilact.development.min.js.map +3 -3
  5. package/dist/lilact.production.min.js +23 -23
  6. package/docs/classes/accessories.ErrorBoundary.html +8 -8
  7. package/docs/classes/accessories.Suspense.html +7 -7
  8. package/docs/classes/components.Component.html +11 -11
  9. package/docs/classes/components.HTMLComponent.html +11 -11
  10. package/docs/classes/components.RootComponent.html +11 -11
  11. package/docs/functions/components.cloneComponent.html +1 -1
  12. package/docs/functions/components.createComponent.html +1 -1
  13. package/docs/functions/components.createPortal.html +1 -1
  14. package/docs/functions/components.createRoot.html +1 -1
  15. package/docs/functions/components.memo.html +1 -1
  16. package/docs/functions/components.render.html +1 -1
  17. package/docs/functions/run.lazy.html +1 -1
  18. package/docs/functions/run.require.html +1 -1
  19. package/docs/functions/run.run.html +1 -1
  20. package/docs/functions/run.runScripts.html +1 -1
  21. package/docs/static/index.html +1 -1
  22. package/docs/static/lilact.development.js +192 -134
  23. package/docs/static/lilact.development.js.map +3 -3
  24. package/docs/static/lilact.development.min.js +23 -23
  25. package/docs/static/lilact.development.min.js.map +3 -3
  26. package/docs/static/lilact.production.min.js +23 -23
  27. package/docs/variables/components.cloneElement.html +1 -1
  28. package/examples/index.html +1 -1
  29. package/examples/lilact.development.js +192 -134
  30. package/examples/lilact.development.js.map +3 -3
  31. package/examples/lilact.development.min.js +23 -23
  32. package/examples/lilact.development.min.js.map +3 -3
  33. package/examples/lilact.production.min.js +23 -23
  34. package/package.json +1 -1
  35. package/src/components.jsx +109 -45
  36. package/src/run.jsx +150 -132
@@ -463,18 +463,18 @@ function sheetForTag(tag) {
463
463
  }
464
464
  return void 0;
465
465
  }
466
- function createStyleElement(options) {
466
+ function createStyleElement(options2) {
467
467
  var tag = document.createElement("style");
468
- tag.setAttribute("data-emotion", options.key);
469
- if (options.nonce !== void 0) {
470
- tag.setAttribute("nonce", options.nonce);
468
+ tag.setAttribute("data-emotion", options2.key);
469
+ if (options2.nonce !== void 0) {
470
+ tag.setAttribute("nonce", options2.nonce);
471
471
  }
472
472
  tag.appendChild(document.createTextNode(""));
473
473
  tag.setAttribute("data-s", "");
474
474
  return tag;
475
475
  }
476
476
  var StyleSheet = /* @__PURE__ */ (function() {
477
- function StyleSheet2(options) {
477
+ function StyleSheet2(options2) {
478
478
  var _this = this;
479
479
  this._insertTag = function(tag) {
480
480
  var before;
@@ -492,14 +492,14 @@ var StyleSheet = /* @__PURE__ */ (function() {
492
492
  _this.container.insertBefore(tag, before);
493
493
  _this.tags.push(tag);
494
494
  };
495
- this.isSpeedy = options.speedy === void 0 ? !isDevelopment : options.speedy;
495
+ this.isSpeedy = options2.speedy === void 0 ? !isDevelopment : options2.speedy;
496
496
  this.tags = [];
497
497
  this.ctr = 0;
498
- this.nonce = options.nonce;
499
- this.key = options.key;
500
- this.container = options.container;
501
- this.prepend = options.prepend;
502
- this.insertionPoint = options.insertionPoint;
498
+ this.nonce = options2.nonce;
499
+ this.key = options2.key;
500
+ this.container = options2.container;
501
+ this.prepend = options2.prepend;
502
+ this.insertionPoint = options2.insertionPoint;
503
503
  this.before = null;
504
504
  }
505
505
  var _proto = StyleSheet2.prototype;
@@ -1187,8 +1187,8 @@ var prefixer = function prefixer2(element, index2, children, callback) {
1187
1187
  }
1188
1188
  };
1189
1189
  var defaultStylisPlugins = [prefixer];
1190
- var createCache = function createCache2(options) {
1191
- var key = options.key;
1190
+ var createCache = function createCache2(options2) {
1191
+ var key = options2.key;
1192
1192
  if (key === "css") {
1193
1193
  var ssrStyles = document.querySelectorAll("style[data-emotion]:not([data-s])");
1194
1194
  Array.prototype.forEach.call(ssrStyles, function(node3) {
@@ -1200,12 +1200,12 @@ var createCache = function createCache2(options) {
1200
1200
  node3.setAttribute("data-s", "");
1201
1201
  });
1202
1202
  }
1203
- var stylisPlugins = options.stylisPlugins || defaultStylisPlugins;
1203
+ var stylisPlugins = options2.stylisPlugins || defaultStylisPlugins;
1204
1204
  var inserted = {};
1205
1205
  var container2;
1206
1206
  var nodesToHydrate = [];
1207
1207
  {
1208
- container2 = options.container || document.head;
1208
+ container2 = options2.container || document.head;
1209
1209
  Array.prototype.forEach.call(
1210
1210
  // this means we will ignore elements which don't have a space in them which
1211
1211
  // means that the style elements we're looking at are only Emotion 11 server-rendered style elements
@@ -1243,12 +1243,12 @@ var createCache = function createCache2(options) {
1243
1243
  sheet: new StyleSheet({
1244
1244
  key,
1245
1245
  container: container2,
1246
- nonce: options.nonce,
1247
- speedy: options.speedy,
1248
- prepend: options.prepend,
1249
- insertionPoint: options.insertionPoint
1246
+ nonce: options2.nonce,
1247
+ speedy: options2.speedy,
1248
+ prepend: options2.prepend,
1249
+ insertionPoint: options2.insertionPoint
1250
1250
  }),
1251
- nonce: options.nonce,
1251
+ nonce: options2.nonce,
1252
1252
  inserted,
1253
1253
  registered: {},
1254
1254
  insert: _insert
@@ -1569,8 +1569,8 @@ function merge(registered, css2, className) {
1569
1569
  }
1570
1570
  return rawClassName + css2(registeredStyles);
1571
1571
  }
1572
- var createEmotion = function createEmotion2(options) {
1573
- var cache2 = createCache(options);
1572
+ var createEmotion = function createEmotion2(options2) {
1573
+ var cache2 = createCache(options2);
1574
1574
  cache2.sheet.speedy = function(value) {
1575
1575
  this.isSpeedy = value;
1576
1576
  };
@@ -2365,6 +2365,32 @@ __export(components_exports, {
2365
2365
  update_timeout: () => update_timeout
2366
2366
  });
2367
2367
  var SVG_NS = "http://www.w3.org/2000/svg";
2368
+ function getComponentEntity(entity) {
2369
+ return entity?.[MEMOIZED] ? entity.component : entity;
2370
+ }
2371
+ function replaceComponentEntity(comp, nextEntity) {
2372
+ const core = comp?.[CORE];
2373
+ if (!core || typeof nextEntity !== "function") {
2374
+ return;
2375
+ }
2376
+ const oldEntity = getComponentEntity(core.entity);
2377
+ const newEntity = getComponentEntity(nextEntity);
2378
+ if (oldEntity === newEntity) {
2379
+ return;
2380
+ }
2381
+ const oldIsClass = isClass(oldEntity);
2382
+ const newIsClass = isClass(newEntity);
2383
+ if (oldIsClass !== newIsClass) {
2384
+ return false;
2385
+ }
2386
+ if (newIsClass) {
2387
+ Object.setPrototypeOf(comp, newEntity.prototype);
2388
+ } else {
2389
+ comp.render = newEntity.bind(comp);
2390
+ }
2391
+ core.entity = newEntity;
2392
+ return true;
2393
+ }
2368
2394
  var ComponentCache = class {
2369
2395
  constructor(owner) {
2370
2396
  __publicField(this, "owner");
@@ -2373,32 +2399,35 @@ var ComponentCache = class {
2373
2399
  __publicField(this, "pick_index", 0);
2374
2400
  this.owner = owner;
2375
2401
  }
2376
- pick(key, construct_func) {
2402
+ pick(key, construct_func, nextEntity) {
2377
2403
  var _a;
2378
2404
  let comp;
2379
- let buck = this.current_map.get(key);
2380
- if (buck && buck.length > buck[IDX]) {
2381
- comp = buck[buck[IDX]];
2382
- buck[IDX]++;
2383
- buck = this.new_map.get(key);
2384
- if (buck !== void 0) {
2385
- buck.push(comp);
2405
+ let bucket = this.current_map.get(key);
2406
+ const reusable = bucket && bucket.length > bucket[IDX];
2407
+ if (reusable) {
2408
+ comp = bucket[bucket[IDX]];
2409
+ bucket[IDX]++;
2410
+ const oldEntity = getComponentEntity(comp?.[CORE]?.entity);
2411
+ const newEntity = getComponentEntity(nextEntity);
2412
+ const incompatible = typeof oldEntity === "function" && typeof newEntity === "function" && isClass(oldEntity) !== isClass(newEntity);
2413
+ if (incompatible) {
2414
+ comp = construct_func();
2386
2415
  } else {
2387
- buck = [comp];
2388
- this.new_map.set(key, buck);
2389
- buck[IDX] = 0;
2416
+ replaceComponentEntity(comp, nextEntity);
2390
2417
  }
2391
2418
  } else {
2392
2419
  comp = construct_func();
2393
- buck = this.new_map.get(key);
2394
- if (buck !== void 0) {
2395
- buck.push(comp);
2396
- } else {
2397
- buck = [comp];
2398
- this.new_map.set(key, buck);
2399
- buck[IDX] = 0;
2400
- }
2401
- if (comp[CORE]) (_a = comp[CORE]).parent ?? (_a.parent = this.owner);
2420
+ }
2421
+ bucket = this.new_map.get(key);
2422
+ if (bucket !== void 0) {
2423
+ bucket.push(comp);
2424
+ } else {
2425
+ bucket = [comp];
2426
+ this.new_map.set(key, bucket);
2427
+ bucket[IDX] = 0;
2428
+ }
2429
+ if (comp[CORE]) {
2430
+ (_a = comp[CORE]).parent ?? (_a.parent = this.owner);
2402
2431
  }
2403
2432
  return comp;
2404
2433
  }
@@ -2867,15 +2896,20 @@ function constructFunc(core, parent) {
2867
2896
  function prepareCore(parent, core) {
2868
2897
  try {
2869
2898
  parent.cache ?? (parent.cache = new ComponentCache(parent));
2870
- core = parent.cache.pick(
2871
- core[TEXT2] === void 0 ? core?.props?.key : ":text:",
2872
- () => core[TEXT2] !== void 0 || core instanceof ComponentCore ? core : constructFunc(core, parent)[CORE]
2899
+ const isText = core[TEXT2] !== void 0;
2900
+ const key = isText ? ":text:" : core.props?.key;
2901
+ const entity = isText || core instanceof ComponentCore ? void 0 : core.entity;
2902
+ return parent.cache.pick(
2903
+ key,
2904
+ () => isText || core instanceof ComponentCore ? core : constructFunc(core, parent)[CORE],
2905
+ entity
2873
2906
  );
2874
- return core;
2875
2907
  } catch (e) {
2876
2908
  if (core?.component?.componentDidCatch) {
2877
2909
  core.component.componentDidCatch(e);
2878
- } else throw e;
2910
+ } else {
2911
+ throw e;
2912
+ }
2879
2913
  }
2880
2914
  }
2881
2915
  function doUpdates() {
@@ -3211,6 +3245,7 @@ var events_set = /* @__PURE__ */ new Set([
3211
3245
  "onsearch",
3212
3246
  "onselect",
3213
3247
  "onsubmit",
3248
+ "oncancel",
3214
3249
  "onkeydown",
3215
3250
  "onkeypress",
3216
3251
  "onkeyup",
@@ -3695,22 +3730,111 @@ function createModule(path2, {
3695
3730
  required_scripts[path2] = module2;
3696
3731
  return module2;
3697
3732
  }
3698
- function makeImportsObject(mod) {
3699
- mod.importsObject ?? (mod.importsObject = {});
3700
- for (const path2 in mod.meta.imports) {
3701
- let exps = required_scripts[path2];
3702
- let imps = mod.meta.imports[path2];
3703
- if (!exps) {
3704
- exps = lilact_default.require(path2, { requirer: mod });
3733
+ function loadModule(path2, options2 = {}) {
3734
+ if (lilact_default.importObjectPaths?.[path2]) {
3735
+ return lilact_default.importObjectPaths[path2];
3736
+ }
3737
+ if (options2.requirer?.path) {
3738
+ path2 = joinPaths(options2.requirer.path, path2);
3739
+ }
3740
+ const loadAsync = Boolean(lilact_default[LAZY]) || Boolean(options2.isLazy);
3741
+ const module2 = getOrCreateModule(path2, {});
3742
+ if (module2.loaded && !options2.forceReload) {
3743
+ return module2.exports;
3744
+ }
3745
+ if (path2.startsWith("#")) {
3746
+ const element = document.getElementById(path2.slice(1));
3747
+ if (!element) {
3748
+ throw report(
3749
+ new Error(`Required element not found (${path2})`),
3750
+ path2
3751
+ );
3705
3752
  }
3753
+ return run(
3754
+ element.textContent || "",
3755
+ path2,
3756
+ { forceReload: options2.forceReload }
3757
+ );
3758
+ }
3759
+ if (loadAsync) {
3760
+ lilact_default[LAZY] = false;
3761
+ if (module2.request && !options2.forceReload) {
3762
+ return module2.request;
3763
+ }
3764
+ return loadAsyncResource(path2, module2, options2);
3765
+ }
3766
+ const resolved = lilact_default.resolver?.(path2);
3767
+ if (resolved != null) {
3768
+ if (path2.endsWith(".css")) {
3769
+ injectGlobal(String(resolved));
3770
+ module2.code = String(resolved);
3771
+ module2.loaded = true;
3772
+ return void 0;
3773
+ }
3774
+ return run(
3775
+ String(resolved),
3776
+ path2,
3777
+ { forceReload: options2.forceReload }
3778
+ );
3779
+ }
3780
+ const request = new XMLHttpRequest();
3781
+ try {
3782
+ request.open("GET", path2, false);
3783
+ request.send(null);
3784
+ } catch (value) {
3785
+ throw report(value, path2);
3786
+ }
3787
+ if (request.status >= 200 && request.status < 300) {
3788
+ if (path2.endsWith(".css")) {
3789
+ module2.code = request.responseText;
3790
+ injectGlobal(module2.code);
3791
+ module2.loaded = true;
3792
+ return void 0;
3793
+ }
3794
+ return run(
3795
+ request.responseText,
3796
+ path2,
3797
+ { forceReload: true }
3798
+ );
3799
+ }
3800
+ throw report(
3801
+ new Error(
3802
+ `Unable to load ${path2}: HTTP ${request.status || 0}`
3803
+ ),
3804
+ path2
3805
+ );
3806
+ }
3807
+ function require2(path2) {
3808
+ let options2 = {};
3809
+ if (arguments.length === 2 && arguments[1] && typeof arguments[1] === "object") {
3810
+ options2 = arguments[1];
3811
+ }
3812
+ return loadModule(path2, options2);
3813
+ }
3814
+ function makeImportsObject(mod, options2 = {}) {
3815
+ mod.importsObject = {};
3816
+ for (const path2 in mod.meta.imports) {
3817
+ const imps = mod.meta.imports[path2];
3818
+ const exps = loadModule(path2, {
3819
+ requirer: mod,
3820
+ forceReload: options2.forceReload
3821
+ });
3706
3822
  for (const i2 in imps.named_imports) {
3707
3823
  if (i2 === "") continue;
3708
- const j = imps.named_imports[i2];
3709
- if (!exps.hasOwnProperty(j)) throw new Error(`Imported module does not export any "${i2}".`);
3710
- mod.importsObject[i2] = exps[j];
3824
+ const exportedName = imps.named_imports[i2];
3825
+ if (!Object.prototype.hasOwnProperty.call(exps, exportedName)) {
3826
+ throw new Error(
3827
+ `Imported module does not export any "${i2}".`
3828
+ );
3829
+ }
3830
+ mod.importsObject[i2] = exps[exportedName];
3711
3831
  }
3712
3832
  for (const i2 of imps.import_defaults) {
3713
- if (!exps.hasOwnProperty("default")) throw new Error(`Imported module does not export a default.`);
3833
+ if (!Object.prototype.hasOwnProperty.call(exps, "default")) {
3834
+ throw new Error(
3835
+ `Imported module does not export a default.`
3836
+ );
3837
+ }
3714
3838
  mod.importsObject[i2] = exps.default;
3715
3839
  }
3716
3840
  for (const i2 of imps.import_stars) {
@@ -3718,7 +3842,7 @@ function makeImportsObject(mod) {
3718
3842
  }
3719
3843
  }
3720
3844
  }
3721
- function run(jsx, path = `InlineJSX-${++lilact_default.eval_num}`, {} = {}) {
3845
+ function run(jsx, path = `InlineJSX-${++lilact_default.eval_num}`, options = {}) {
3722
3846
  let module = required_scripts[path];
3723
3847
  if (!module) {
3724
3848
  module = createModule(path, {
@@ -3763,7 +3887,7 @@ function run(jsx, path = `InlineJSX-${++lilact_default.eval_num}`, {} = {}) {
3763
3887
  globalThis.Lilact = lilact_default;
3764
3888
  globalThis.createComponent = lilact_default.createComponent;
3765
3889
  globalThis.Fragment = lilact_default.Fragment;
3766
- makeImportsObject(module);
3890
+ makeImportsObject(module, options);
3767
3891
  lilact_default.scriptImportsObject = module.importsObject;
3768
3892
  const result = eval(processed);
3769
3893
  module.loaded = true;
@@ -3775,10 +3899,10 @@ function run(jsx, path = `InlineJSX-${++lilact_default.eval_num}`, {} = {}) {
3775
3899
  throw error2;
3776
3900
  }
3777
3901
  }
3778
- function getOrCreateModule(path2, options = {}) {
3779
- return required_scripts[path2] || createModule(path2, options);
3902
+ function getOrCreateModule(path2, options2 = {}) {
3903
+ return required_scripts[path2] || createModule(path2, options2);
3780
3904
  }
3781
- function loadAsyncResource(path2, module2) {
3905
+ function loadAsyncResource(path2, module2, options2 = {}) {
3782
3906
  let source;
3783
3907
  try {
3784
3908
  const resolved = lilact_default.resolver?.(path2);
@@ -3812,7 +3936,7 @@ function loadAsyncResource(path2, module2) {
3812
3936
  module2.loaded = true;
3813
3937
  return void 0;
3814
3938
  }
3815
- return run(module2.code, path2, {});
3939
+ return run(module2.code, path2, options2);
3816
3940
  }).then((result2) => result2?.default ?? result2).catch((error2) => {
3817
3941
  module2.error = report(error2, path2);
3818
3942
  throw module2.error;
@@ -3824,72 +3948,6 @@ function loadAsyncResource(path2, module2) {
3824
3948
  module2.request = request;
3825
3949
  return request;
3826
3950
  }
3827
- function require2(path2) {
3828
- let options = {};
3829
- if (arguments.length === 2 && arguments[1] && typeof arguments[1] === "object") {
3830
- options = arguments[1];
3831
- }
3832
- if (lilact_default.importObjectPaths?.[path2]) {
3833
- return lilact_default.importObjectPaths[path2];
3834
- }
3835
- if (options?.requirer?.path) {
3836
- path2 = joinPaths(options.requirer.path, path2);
3837
- }
3838
- const loadAsync = Boolean(lilact_default[LAZY]) || Boolean(options.isLazy);
3839
- const module2 = getOrCreateModule(path2, {});
3840
- if (module2.loaded && !options.forceReload) {
3841
- return module2.exports;
3842
- }
3843
- if (path2.startsWith("#")) {
3844
- const element = document.getElementById(path2.slice(1));
3845
- if (!element) {
3846
- throw report(
3847
- new Error(`Required element not found (${path2})`),
3848
- path2
3849
- );
3850
- }
3851
- return run(element.textContent || "", path2, { forceReload: options.forceReload });
3852
- }
3853
- if (loadAsync) {
3854
- lilact_default[LAZY] = false;
3855
- if (module2.request) {
3856
- return module2.request;
3857
- }
3858
- return loadAsyncResource(path2, module2);
3859
- }
3860
- const resolved = lilact_default.resolver?.(path2);
3861
- if (resolved != null) {
3862
- if (path2.endsWith(".css")) {
3863
- injectGlobal(String(resolved));
3864
- module2.code = String(resolved);
3865
- module2.loaded = true;
3866
- return void 0;
3867
- }
3868
- return run(String(resolved), path2, { forceReload: options.forceReload });
3869
- }
3870
- const request = new XMLHttpRequest();
3871
- try {
3872
- request.open("GET", path2, false);
3873
- request.send(null);
3874
- } catch (value) {
3875
- throw report(value, path2);
3876
- }
3877
- if (request.status >= 200 && request.status < 300) {
3878
- if (path2.endsWith(".css")) {
3879
- module2.code = request.responseText;
3880
- injectGlobal(module2.code);
3881
- module2.loaded = true;
3882
- return void 0;
3883
- }
3884
- return run(request.responseText, path2, { forceReload: true });
3885
- }
3886
- throw report(
3887
- new Error(
3888
- `Unable to load ${path2}: HTTP ${request.status || 0}`
3889
- ),
3890
- path2
3891
- );
3892
- }
3893
3951
  function lazy(factory) {
3894
3952
  let status = "pending";
3895
3953
  let result2;
@@ -4342,10 +4400,10 @@ function wrapListener(fn, opts = {}) {
4342
4400
  }
4343
4401
  };
4344
4402
  }
4345
- function addWrappedEventListener(target, type, fn, options = {}) {
4346
- const handler = wrapListener(fn, options);
4347
- target.addEventListener(type, handler, options);
4348
- return () => target.removeEventListener(type, handler, options);
4403
+ function addWrappedEventListener(target, type, fn, options2 = {}) {
4404
+ const handler = wrapListener(fn, options2);
4405
+ target.addEventListener(type, handler, options2);
4406
+ return () => target.removeEventListener(type, handler, options2);
4349
4407
  }
4350
4408
 
4351
4409
  // .tmp/src/redux.jsx