@gridland/core 0.2.29 → 0.2.30

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.
package/dist/index.js CHANGED
@@ -28805,167 +28805,17 @@ var OptimizedBuffer2 = class _OptimizedBuffer {
28805
28805
  }
28806
28806
  };
28807
28807
 
28808
- // ../../opentui/packages/core/src/renderables/composition/vnode.ts
28809
- import util from "node:util";
28810
- var BrandedVNode = /* @__PURE__ */ Symbol.for("@opentui/core/VNode");
28811
- function isRenderableConstructor(value) {
28812
- return typeof value === "function" && value.prototype && Renderable3.prototype.isPrototypeOf(value.prototype);
28813
- }
28814
- function flattenChildren(children) {
28815
- const result = [];
28816
- for (const child of children) {
28817
- if (Array.isArray(child)) {
28818
- result.push(...flattenChildren(child));
28819
- } else if (child !== null && child !== void 0 && child !== false) {
28820
- result.push(child);
28821
- }
28822
- }
28823
- return result;
28824
- }
28825
- function h(type, props, ...children) {
28826
- if (typeof type !== "function") {
28827
- throw new TypeError("h() received an invalid vnode type");
28828
- }
28829
- const vnode = {
28830
- [BrandedVNode]: true,
28831
- type,
28832
- props,
28833
- children: flattenChildren(children),
28834
- __pendingCalls: []
28835
- };
28836
- if (isRenderableConstructor(type)) {
28837
- return new Proxy(vnode, {
28838
- get(target, prop, receiver) {
28839
- if (prop in target) {
28840
- return Reflect.get(target, prop, receiver);
28841
- }
28842
- if (typeof prop === "string") {
28843
- const prototype = type.prototype;
28844
- const hasMethod = prototype && (typeof prototype[prop] === "function" || Object.getOwnPropertyDescriptor(prototype, prop) || Object.getOwnPropertyDescriptor(Object.getPrototypeOf(prototype), prop));
28845
- if (hasMethod) {
28846
- return (...args) => {
28847
- target.__pendingCalls = target.__pendingCalls || [];
28848
- target.__pendingCalls.push({ method: prop, args });
28849
- return target;
28850
- };
28851
- }
28852
- }
28853
- return Reflect.get(target, prop, receiver);
28854
- },
28855
- set(target, prop, value, receiver) {
28856
- if (typeof prop === "string" && isRenderableConstructor(type)) {
28857
- const prototype = type.prototype;
28858
- const descriptor = Object.getOwnPropertyDescriptor(prototype, prop) || Object.getOwnPropertyDescriptor(Object.getPrototypeOf(prototype), prop);
28859
- if (descriptor && descriptor.set) {
28860
- target.__pendingCalls = target.__pendingCalls || [];
28861
- target.__pendingCalls.push({ method: prop, args: [value], isProperty: true });
28862
- return true;
28863
- }
28864
- }
28865
- return Reflect.set(target, prop, value, receiver);
28866
- }
28867
- });
28868
- }
28869
- return vnode;
28808
+ // ../../opentui/packages/core/src/renderable-brand.ts
28809
+ var BrandedRenderable = /* @__PURE__ */ Symbol.for("@opentui/core/Renderable");
28810
+ function isRenderable2(obj) {
28811
+ return !!obj?.[BrandedRenderable];
28870
28812
  }
28871
- function isVNode(node) {
28872
- return node && node[BrandedVNode];
28813
+ var _maybeMakeRenderable = null;
28814
+ function registerMaybeMakeRenderable(fn) {
28815
+ _maybeMakeRenderable = fn;
28873
28816
  }
28874
28817
  function maybeMakeRenderable(ctx, node) {
28875
- if (isRenderable(node)) return node;
28876
- if (isVNode(node)) return instantiate(ctx, node);
28877
- if (process.env.NODE_ENV !== "production") {
28878
- console.warn("maybeMakeRenderable received an invalid node", util.inspect(node, { depth: 2 }));
28879
- }
28880
- return null;
28881
- }
28882
- function wrapWithDelegates(instance, delegateMap) {
28883
- if (!delegateMap || Object.keys(delegateMap).length === 0) return instance;
28884
- const descendantCache = /* @__PURE__ */ new Map();
28885
- const getDescendant = (id) => {
28886
- if (descendantCache.has(id)) {
28887
- const cached = descendantCache.get(id);
28888
- if (cached !== void 0) {
28889
- return cached;
28890
- }
28891
- }
28892
- const descendant = instance.findDescendantById(id);
28893
- if (descendant) {
28894
- descendantCache.set(id, descendant);
28895
- }
28896
- return descendant;
28897
- };
28898
- const proxy = new Proxy(instance, {
28899
- get(target, prop, receiver) {
28900
- if (typeof prop === "string" && delegateMap[prop]) {
28901
- const host = getDescendant(delegateMap[prop]);
28902
- if (host) {
28903
- const value = host[prop];
28904
- if (typeof value === "function") {
28905
- return value.bind(host);
28906
- }
28907
- return value;
28908
- }
28909
- }
28910
- return Reflect.get(target, prop, receiver);
28911
- },
28912
- set(target, prop, value, receiver) {
28913
- if (typeof prop === "string" && delegateMap[prop]) {
28914
- const host = getDescendant(delegateMap[prop]);
28915
- if (host) {
28916
- return Reflect.set(host, prop, value);
28917
- }
28918
- }
28919
- return Reflect.set(target, prop, value, receiver);
28920
- }
28921
- });
28922
- return proxy;
28923
- }
28924
- function instantiate(ctx, node) {
28925
- if (isRenderable(node)) return node;
28926
- if (!node || typeof node !== "object") {
28927
- throw new TypeError("mount() received an invalid vnode");
28928
- }
28929
- const vnode = node;
28930
- const { type, props } = vnode;
28931
- const children = flattenChildren(vnode.children || []);
28932
- const delegateMap = vnode.__delegateMap;
28933
- if (isRenderableConstructor(type)) {
28934
- const instance = new type(ctx, props || {});
28935
- for (const child of children) {
28936
- if (isRenderable(child)) {
28937
- instance.add(child);
28938
- } else {
28939
- const mounted = instantiate(ctx, child);
28940
- instance.add(mounted);
28941
- }
28942
- }
28943
- const delegatedInstance = wrapWithDelegates(instance, delegateMap);
28944
- const pendingCalls = vnode.__pendingCalls;
28945
- if (pendingCalls) {
28946
- for (const call of pendingCalls) {
28947
- if (call.isProperty) {
28948
- ;
28949
- delegatedInstance[call.method] = call.args[0];
28950
- } else {
28951
- ;
28952
- delegatedInstance[call.method].apply(delegatedInstance, call.args);
28953
- }
28954
- }
28955
- }
28956
- return delegatedInstance;
28957
- }
28958
- const resolved = type(props || {}, children);
28959
- const inst = instantiate(ctx, resolved);
28960
- return wrapWithDelegates(inst, delegateMap);
28961
- }
28962
- function delegate(mapping, vnode) {
28963
- if (isRenderable(vnode)) {
28964
- return wrapWithDelegates(vnode, mapping);
28965
- }
28966
- if (!vnode || typeof vnode !== "object") return vnode;
28967
- vnode.__delegateMap = { ...vnode.__delegateMap || {}, ...mapping };
28968
- return vnode;
28818
+ return _maybeMakeRenderable?.(ctx, node) ?? null;
28969
28819
  }
28970
28820
 
28971
28821
  // ../../opentui/packages/core/src/lib/renderable.validations.ts
@@ -29042,7 +28892,6 @@ function isSizeType(value) {
29042
28892
  }
29043
28893
 
29044
28894
  // ../../opentui/packages/core/src/Renderable.ts
29045
- var BrandedRenderable = /* @__PURE__ */ Symbol.for("@opentui/core/Renderable");
29046
28895
  var LayoutEvents = /* @__PURE__ */ ((LayoutEvents2) => {
29047
28896
  LayoutEvents2["LAYOUT_CHANGED"] = "layout-changed";
29048
28897
  LayoutEvents2["ADDED"] = "added";
@@ -29055,9 +28904,6 @@ var RenderableEvents = /* @__PURE__ */ ((RenderableEvents2) => {
29055
28904
  RenderableEvents2["BLURRED"] = "blurred";
29056
28905
  return RenderableEvents2;
29057
28906
  })(RenderableEvents || {});
29058
- function isRenderable(obj) {
29059
- return !!obj?.[BrandedRenderable];
29060
- }
29061
28907
  var BaseRenderable = class _BaseRenderable extends EventEmitter4 {
29062
28908
  [BrandedRenderable] = true;
29063
28909
  static renderableNumber = 1;
@@ -33681,6 +33527,170 @@ var RootTextNodeRenderable = class extends TextNodeRenderable {
33681
33527
  }
33682
33528
  };
33683
33529
 
33530
+ // ../../opentui/packages/core/src/renderables/composition/vnode.ts
33531
+ import util from "node:util";
33532
+ var BrandedVNode = /* @__PURE__ */ Symbol.for("@opentui/core/VNode");
33533
+ function isRenderableConstructor(value) {
33534
+ return typeof value === "function" && value.prototype && !!value.prototype[BrandedRenderable];
33535
+ }
33536
+ function flattenChildren(children) {
33537
+ const result = [];
33538
+ for (const child of children) {
33539
+ if (Array.isArray(child)) {
33540
+ result.push(...flattenChildren(child));
33541
+ } else if (child !== null && child !== void 0 && child !== false) {
33542
+ result.push(child);
33543
+ }
33544
+ }
33545
+ return result;
33546
+ }
33547
+ function h(type, props, ...children) {
33548
+ if (typeof type !== "function") {
33549
+ throw new TypeError("h() received an invalid vnode type");
33550
+ }
33551
+ const vnode = {
33552
+ [BrandedVNode]: true,
33553
+ type,
33554
+ props,
33555
+ children: flattenChildren(children),
33556
+ __pendingCalls: []
33557
+ };
33558
+ if (isRenderableConstructor(type)) {
33559
+ return new Proxy(vnode, {
33560
+ get(target, prop, receiver) {
33561
+ if (prop in target) {
33562
+ return Reflect.get(target, prop, receiver);
33563
+ }
33564
+ if (typeof prop === "string") {
33565
+ const prototype = type.prototype;
33566
+ const hasMethod = prototype && (typeof prototype[prop] === "function" || Object.getOwnPropertyDescriptor(prototype, prop) || Object.getOwnPropertyDescriptor(Object.getPrototypeOf(prototype), prop));
33567
+ if (hasMethod) {
33568
+ return (...args) => {
33569
+ target.__pendingCalls = target.__pendingCalls || [];
33570
+ target.__pendingCalls.push({ method: prop, args });
33571
+ return target;
33572
+ };
33573
+ }
33574
+ }
33575
+ return Reflect.get(target, prop, receiver);
33576
+ },
33577
+ set(target, prop, value, receiver) {
33578
+ if (typeof prop === "string" && isRenderableConstructor(type)) {
33579
+ const prototype = type.prototype;
33580
+ const descriptor = Object.getOwnPropertyDescriptor(prototype, prop) || Object.getOwnPropertyDescriptor(Object.getPrototypeOf(prototype), prop);
33581
+ if (descriptor && descriptor.set) {
33582
+ target.__pendingCalls = target.__pendingCalls || [];
33583
+ target.__pendingCalls.push({ method: prop, args: [value], isProperty: true });
33584
+ return true;
33585
+ }
33586
+ }
33587
+ return Reflect.set(target, prop, value, receiver);
33588
+ }
33589
+ });
33590
+ }
33591
+ return vnode;
33592
+ }
33593
+ function isVNode(node) {
33594
+ return node && node[BrandedVNode];
33595
+ }
33596
+ function maybeMakeRenderable2(ctx, node) {
33597
+ if (isRenderable2(node)) return node;
33598
+ if (isVNode(node)) return instantiate(ctx, node);
33599
+ if (process.env.NODE_ENV !== "production") {
33600
+ console.warn("maybeMakeRenderable received an invalid node", util.inspect(node, { depth: 2 }));
33601
+ }
33602
+ return null;
33603
+ }
33604
+ registerMaybeMakeRenderable(maybeMakeRenderable2);
33605
+ function wrapWithDelegates(instance, delegateMap) {
33606
+ if (!delegateMap || Object.keys(delegateMap).length === 0) return instance;
33607
+ const descendantCache = /* @__PURE__ */ new Map();
33608
+ const getDescendant = (id) => {
33609
+ if (descendantCache.has(id)) {
33610
+ const cached = descendantCache.get(id);
33611
+ if (cached !== void 0) {
33612
+ return cached;
33613
+ }
33614
+ }
33615
+ const descendant = instance.findDescendantById(id);
33616
+ if (descendant) {
33617
+ descendantCache.set(id, descendant);
33618
+ }
33619
+ return descendant;
33620
+ };
33621
+ const proxy = new Proxy(instance, {
33622
+ get(target, prop, receiver) {
33623
+ if (typeof prop === "string" && delegateMap[prop]) {
33624
+ const host = getDescendant(delegateMap[prop]);
33625
+ if (host) {
33626
+ const value = host[prop];
33627
+ if (typeof value === "function") {
33628
+ return value.bind(host);
33629
+ }
33630
+ return value;
33631
+ }
33632
+ }
33633
+ return Reflect.get(target, prop, receiver);
33634
+ },
33635
+ set(target, prop, value, receiver) {
33636
+ if (typeof prop === "string" && delegateMap[prop]) {
33637
+ const host = getDescendant(delegateMap[prop]);
33638
+ if (host) {
33639
+ return Reflect.set(host, prop, value);
33640
+ }
33641
+ }
33642
+ return Reflect.set(target, prop, value, receiver);
33643
+ }
33644
+ });
33645
+ return proxy;
33646
+ }
33647
+ function instantiate(ctx, node) {
33648
+ if (isRenderable2(node)) return node;
33649
+ if (!node || typeof node !== "object") {
33650
+ throw new TypeError("mount() received an invalid vnode");
33651
+ }
33652
+ const vnode = node;
33653
+ const { type, props } = vnode;
33654
+ const children = flattenChildren(vnode.children || []);
33655
+ const delegateMap = vnode.__delegateMap;
33656
+ if (isRenderableConstructor(type)) {
33657
+ const instance = new type(ctx, props || {});
33658
+ for (const child of children) {
33659
+ if (isRenderable2(child)) {
33660
+ instance.add(child);
33661
+ } else {
33662
+ const mounted = instantiate(ctx, child);
33663
+ instance.add(mounted);
33664
+ }
33665
+ }
33666
+ const delegatedInstance = wrapWithDelegates(instance, delegateMap);
33667
+ const pendingCalls = vnode.__pendingCalls;
33668
+ if (pendingCalls) {
33669
+ for (const call of pendingCalls) {
33670
+ if (call.isProperty) {
33671
+ ;
33672
+ delegatedInstance[call.method] = call.args[0];
33673
+ } else {
33674
+ ;
33675
+ delegatedInstance[call.method].apply(delegatedInstance, call.args);
33676
+ }
33677
+ }
33678
+ }
33679
+ return delegatedInstance;
33680
+ }
33681
+ const resolved = type(props || {}, children);
33682
+ const inst = instantiate(ctx, resolved);
33683
+ return wrapWithDelegates(inst, delegateMap);
33684
+ }
33685
+ function delegate(mapping, vnode) {
33686
+ if (isRenderable2(vnode)) {
33687
+ return wrapWithDelegates(vnode, mapping);
33688
+ }
33689
+ if (!vnode || typeof vnode !== "object") return vnode;
33690
+ vnode.__delegateMap = { ...vnode.__delegateMap || {}, ...mapping };
33691
+ return vnode;
33692
+ }
33693
+
33684
33694
  // ../../opentui/packages/core/src/renderables/composition/constructs.ts
33685
33695
  function Generic(props, ...children) {
33686
33696
  return h(VRenderable, props || {}, ...children);
@@ -48052,7 +48062,7 @@ function setProperty(instance, type, propKey, propValue, oldPropValue) {
48052
48062
  }
48053
48063
  break;
48054
48064
  case "focused":
48055
- if (isRenderable(instance)) {
48065
+ if (isRenderable2(instance)) {
48056
48066
  if (!!propValue) {
48057
48067
  instance.focus();
48058
48068
  } else {
@@ -48528,7 +48538,7 @@ export {
48528
48538
  hexToRgb,
48529
48539
  hsvToRgb,
48530
48540
  instantiate,
48531
- isRenderable,
48541
+ isRenderable2 as isRenderable,
48532
48542
  isStyledText,
48533
48543
  isTextNodeRenderable,
48534
48544
  isVNode,
@@ -48536,7 +48546,7 @@ export {
48536
48546
  italic,
48537
48547
  link,
48538
48548
  magenta,
48539
- maybeMakeRenderable,
48549
+ maybeMakeRenderable2 as maybeMakeRenderable,
48540
48550
  measureText,
48541
48551
  nonAlphanumericKeys,
48542
48552
  parseAlign,