lilact 0.29.2 → 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 (35) hide show
  1. package/dist/lilact.development.js +106 -71
  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.run.html +1 -1
  19. package/docs/functions/run.runScripts.html +1 -1
  20. package/docs/static/index.html +1 -1
  21. package/docs/static/lilact.development.js +106 -71
  22. package/docs/static/lilact.development.js.map +3 -3
  23. package/docs/static/lilact.development.min.js +23 -23
  24. package/docs/static/lilact.development.min.js.map +3 -3
  25. package/docs/static/lilact.production.min.js +23 -23
  26. package/docs/variables/components.cloneElement.html +1 -1
  27. package/examples/index.html +1 -1
  28. package/examples/lilact.development.js +106 -71
  29. package/examples/lilact.development.js.map +3 -3
  30. package/examples/lilact.development.min.js +23 -23
  31. package/examples/lilact.development.min.js.map +3 -3
  32. package/examples/lilact.production.min.js +23 -23
  33. package/package.json +1 -1
  34. package/src/components.jsx +108 -44
  35. package/src/run.jsx +41 -46
@@ -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() {
@@ -3696,16 +3730,16 @@ function createModule(path2, {
3696
3730
  required_scripts[path2] = module2;
3697
3731
  return module2;
3698
3732
  }
3699
- function loadModule(path2, options = {}) {
3733
+ function loadModule(path2, options2 = {}) {
3700
3734
  if (lilact_default.importObjectPaths?.[path2]) {
3701
3735
  return lilact_default.importObjectPaths[path2];
3702
3736
  }
3703
- if (options.requirer?.path) {
3704
- path2 = joinPaths(options.requirer.path, path2);
3737
+ if (options2.requirer?.path) {
3738
+ path2 = joinPaths(options2.requirer.path, path2);
3705
3739
  }
3706
- const loadAsync = Boolean(lilact_default[LAZY]) || Boolean(options.isLazy);
3740
+ const loadAsync = Boolean(lilact_default[LAZY]) || Boolean(options2.isLazy);
3707
3741
  const module2 = getOrCreateModule(path2, {});
3708
- if (module2.loaded && !options.forceReload) {
3742
+ if (module2.loaded && !options2.forceReload) {
3709
3743
  return module2.exports;
3710
3744
  }
3711
3745
  if (path2.startsWith("#")) {
@@ -3719,15 +3753,15 @@ function loadModule(path2, options = {}) {
3719
3753
  return run(
3720
3754
  element.textContent || "",
3721
3755
  path2,
3722
- { forceReload: options.forceReload }
3756
+ { forceReload: options2.forceReload }
3723
3757
  );
3724
3758
  }
3725
3759
  if (loadAsync) {
3726
3760
  lilact_default[LAZY] = false;
3727
- if (module2.request) {
3761
+ if (module2.request && !options2.forceReload) {
3728
3762
  return module2.request;
3729
3763
  }
3730
- return loadAsyncResource(path2, module2);
3764
+ return loadAsyncResource(path2, module2, options2);
3731
3765
  }
3732
3766
  const resolved = lilact_default.resolver?.(path2);
3733
3767
  if (resolved != null) {
@@ -3740,7 +3774,7 @@ function loadModule(path2, options = {}) {
3740
3774
  return run(
3741
3775
  String(resolved),
3742
3776
  path2,
3743
- { forceReload: options.forceReload }
3777
+ { forceReload: options2.forceReload }
3744
3778
  );
3745
3779
  }
3746
3780
  const request = new XMLHttpRequest();
@@ -3771,18 +3805,19 @@ function loadModule(path2, options = {}) {
3771
3805
  );
3772
3806
  }
3773
3807
  function require2(path2) {
3774
- let options = {};
3808
+ let options2 = {};
3775
3809
  if (arguments.length === 2 && arguments[1] && typeof arguments[1] === "object") {
3776
- options = arguments[1];
3810
+ options2 = arguments[1];
3777
3811
  }
3778
- return loadModule(path2, options);
3812
+ return loadModule(path2, options2);
3779
3813
  }
3780
- function makeImportsObject(mod) {
3814
+ function makeImportsObject(mod, options2 = {}) {
3781
3815
  mod.importsObject = {};
3782
3816
  for (const path2 in mod.meta.imports) {
3783
3817
  const imps = mod.meta.imports[path2];
3784
3818
  const exps = loadModule(path2, {
3785
- requirer: mod
3819
+ requirer: mod,
3820
+ forceReload: options2.forceReload
3786
3821
  });
3787
3822
  for (const i2 in imps.named_imports) {
3788
3823
  if (i2 === "") continue;
@@ -3807,7 +3842,7 @@ function makeImportsObject(mod) {
3807
3842
  }
3808
3843
  }
3809
3844
  }
3810
- function run(jsx, path = `InlineJSX-${++lilact_default.eval_num}`, {} = {}) {
3845
+ function run(jsx, path = `InlineJSX-${++lilact_default.eval_num}`, options = {}) {
3811
3846
  let module = required_scripts[path];
3812
3847
  if (!module) {
3813
3848
  module = createModule(path, {
@@ -3852,7 +3887,7 @@ function run(jsx, path = `InlineJSX-${++lilact_default.eval_num}`, {} = {}) {
3852
3887
  globalThis.Lilact = lilact_default;
3853
3888
  globalThis.createComponent = lilact_default.createComponent;
3854
3889
  globalThis.Fragment = lilact_default.Fragment;
3855
- makeImportsObject(module);
3890
+ makeImportsObject(module, options);
3856
3891
  lilact_default.scriptImportsObject = module.importsObject;
3857
3892
  const result = eval(processed);
3858
3893
  module.loaded = true;
@@ -3864,10 +3899,10 @@ function run(jsx, path = `InlineJSX-${++lilact_default.eval_num}`, {} = {}) {
3864
3899
  throw error2;
3865
3900
  }
3866
3901
  }
3867
- function getOrCreateModule(path2, options = {}) {
3868
- return required_scripts[path2] || createModule(path2, options);
3902
+ function getOrCreateModule(path2, options2 = {}) {
3903
+ return required_scripts[path2] || createModule(path2, options2);
3869
3904
  }
3870
- function loadAsyncResource(path2, module2) {
3905
+ function loadAsyncResource(path2, module2, options2 = {}) {
3871
3906
  let source;
3872
3907
  try {
3873
3908
  const resolved = lilact_default.resolver?.(path2);
@@ -3901,7 +3936,7 @@ function loadAsyncResource(path2, module2) {
3901
3936
  module2.loaded = true;
3902
3937
  return void 0;
3903
3938
  }
3904
- return run(module2.code, path2, {});
3939
+ return run(module2.code, path2, options2);
3905
3940
  }).then((result2) => result2?.default ?? result2).catch((error2) => {
3906
3941
  module2.error = report(error2, path2);
3907
3942
  throw module2.error;
@@ -4365,10 +4400,10 @@ function wrapListener(fn, opts = {}) {
4365
4400
  }
4366
4401
  };
4367
4402
  }
4368
- function addWrappedEventListener(target, type, fn, options = {}) {
4369
- const handler = wrapListener(fn, options);
4370
- target.addEventListener(type, handler, options);
4371
- 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);
4372
4407
  }
4373
4408
 
4374
4409
  // .tmp/src/redux.jsx