@gridland/utils 0.2.34 → 0.2.36
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 +172 -162
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -27675,166 +27675,17 @@ var OptimizedBuffer2 = class _OptimizedBuffer {
|
|
|
27675
27675
|
}
|
|
27676
27676
|
};
|
|
27677
27677
|
|
|
27678
|
-
// ../../opentui/packages/core/src/
|
|
27679
|
-
var
|
|
27680
|
-
function
|
|
27681
|
-
return
|
|
27682
|
-
}
|
|
27683
|
-
function flattenChildren(children) {
|
|
27684
|
-
const result = [];
|
|
27685
|
-
for (const child of children) {
|
|
27686
|
-
if (Array.isArray(child)) {
|
|
27687
|
-
result.push(...flattenChildren(child));
|
|
27688
|
-
} else if (child !== null && child !== void 0 && child !== false) {
|
|
27689
|
-
result.push(child);
|
|
27690
|
-
}
|
|
27691
|
-
}
|
|
27692
|
-
return result;
|
|
27693
|
-
}
|
|
27694
|
-
function h(type, props, ...children) {
|
|
27695
|
-
if (typeof type !== "function") {
|
|
27696
|
-
throw new TypeError("h() received an invalid vnode type");
|
|
27697
|
-
}
|
|
27698
|
-
const vnode = {
|
|
27699
|
-
[BrandedVNode]: true,
|
|
27700
|
-
type,
|
|
27701
|
-
props,
|
|
27702
|
-
children: flattenChildren(children),
|
|
27703
|
-
__pendingCalls: []
|
|
27704
|
-
};
|
|
27705
|
-
if (isRenderableConstructor(type)) {
|
|
27706
|
-
return new Proxy(vnode, {
|
|
27707
|
-
get(target, prop, receiver) {
|
|
27708
|
-
if (prop in target) {
|
|
27709
|
-
return Reflect.get(target, prop, receiver);
|
|
27710
|
-
}
|
|
27711
|
-
if (typeof prop === "string") {
|
|
27712
|
-
const prototype = type.prototype;
|
|
27713
|
-
const hasMethod = prototype && (typeof prototype[prop] === "function" || Object.getOwnPropertyDescriptor(prototype, prop) || Object.getOwnPropertyDescriptor(Object.getPrototypeOf(prototype), prop));
|
|
27714
|
-
if (hasMethod) {
|
|
27715
|
-
return (...args) => {
|
|
27716
|
-
target.__pendingCalls = target.__pendingCalls || [];
|
|
27717
|
-
target.__pendingCalls.push({ method: prop, args });
|
|
27718
|
-
return target;
|
|
27719
|
-
};
|
|
27720
|
-
}
|
|
27721
|
-
}
|
|
27722
|
-
return Reflect.get(target, prop, receiver);
|
|
27723
|
-
},
|
|
27724
|
-
set(target, prop, value, receiver) {
|
|
27725
|
-
if (typeof prop === "string" && isRenderableConstructor(type)) {
|
|
27726
|
-
const prototype = type.prototype;
|
|
27727
|
-
const descriptor = Object.getOwnPropertyDescriptor(prototype, prop) || Object.getOwnPropertyDescriptor(Object.getPrototypeOf(prototype), prop);
|
|
27728
|
-
if (descriptor && descriptor.set) {
|
|
27729
|
-
target.__pendingCalls = target.__pendingCalls || [];
|
|
27730
|
-
target.__pendingCalls.push({ method: prop, args: [value], isProperty: true });
|
|
27731
|
-
return true;
|
|
27732
|
-
}
|
|
27733
|
-
}
|
|
27734
|
-
return Reflect.set(target, prop, value, receiver);
|
|
27735
|
-
}
|
|
27736
|
-
});
|
|
27737
|
-
}
|
|
27738
|
-
return vnode;
|
|
27678
|
+
// ../../opentui/packages/core/src/renderable-brand.ts
|
|
27679
|
+
var BrandedRenderable = /* @__PURE__ */ Symbol.for("@opentui/core/Renderable");
|
|
27680
|
+
function isRenderable(obj) {
|
|
27681
|
+
return !!obj?.[BrandedRenderable];
|
|
27739
27682
|
}
|
|
27740
|
-
|
|
27741
|
-
|
|
27683
|
+
var _maybeMakeRenderable = null;
|
|
27684
|
+
function registerMaybeMakeRenderable(fn) {
|
|
27685
|
+
_maybeMakeRenderable = fn;
|
|
27742
27686
|
}
|
|
27743
27687
|
function maybeMakeRenderable(ctx, node) {
|
|
27744
|
-
|
|
27745
|
-
if (isVNode(node)) return instantiate(ctx, node);
|
|
27746
|
-
if (process.env.NODE_ENV !== "production") {
|
|
27747
|
-
console.warn("maybeMakeRenderable received an invalid node", node);
|
|
27748
|
-
}
|
|
27749
|
-
return null;
|
|
27750
|
-
}
|
|
27751
|
-
function wrapWithDelegates(instance, delegateMap) {
|
|
27752
|
-
if (!delegateMap || Object.keys(delegateMap).length === 0) return instance;
|
|
27753
|
-
const descendantCache = /* @__PURE__ */ new Map();
|
|
27754
|
-
const getDescendant = (id) => {
|
|
27755
|
-
if (descendantCache.has(id)) {
|
|
27756
|
-
const cached = descendantCache.get(id);
|
|
27757
|
-
if (cached !== void 0) {
|
|
27758
|
-
return cached;
|
|
27759
|
-
}
|
|
27760
|
-
}
|
|
27761
|
-
const descendant = instance.findDescendantById(id);
|
|
27762
|
-
if (descendant) {
|
|
27763
|
-
descendantCache.set(id, descendant);
|
|
27764
|
-
}
|
|
27765
|
-
return descendant;
|
|
27766
|
-
};
|
|
27767
|
-
const proxy = new Proxy(instance, {
|
|
27768
|
-
get(target, prop, receiver) {
|
|
27769
|
-
if (typeof prop === "string" && delegateMap[prop]) {
|
|
27770
|
-
const host = getDescendant(delegateMap[prop]);
|
|
27771
|
-
if (host) {
|
|
27772
|
-
const value = host[prop];
|
|
27773
|
-
if (typeof value === "function") {
|
|
27774
|
-
return value.bind(host);
|
|
27775
|
-
}
|
|
27776
|
-
return value;
|
|
27777
|
-
}
|
|
27778
|
-
}
|
|
27779
|
-
return Reflect.get(target, prop, receiver);
|
|
27780
|
-
},
|
|
27781
|
-
set(target, prop, value, receiver) {
|
|
27782
|
-
if (typeof prop === "string" && delegateMap[prop]) {
|
|
27783
|
-
const host = getDescendant(delegateMap[prop]);
|
|
27784
|
-
if (host) {
|
|
27785
|
-
return Reflect.set(host, prop, value);
|
|
27786
|
-
}
|
|
27787
|
-
}
|
|
27788
|
-
return Reflect.set(target, prop, value, receiver);
|
|
27789
|
-
}
|
|
27790
|
-
});
|
|
27791
|
-
return proxy;
|
|
27792
|
-
}
|
|
27793
|
-
function instantiate(ctx, node) {
|
|
27794
|
-
if (isRenderable(node)) return node;
|
|
27795
|
-
if (!node || typeof node !== "object") {
|
|
27796
|
-
throw new TypeError("mount() received an invalid vnode");
|
|
27797
|
-
}
|
|
27798
|
-
const vnode = node;
|
|
27799
|
-
const { type, props } = vnode;
|
|
27800
|
-
const children = flattenChildren(vnode.children || []);
|
|
27801
|
-
const delegateMap = vnode.__delegateMap;
|
|
27802
|
-
if (isRenderableConstructor(type)) {
|
|
27803
|
-
const instance = new type(ctx, props || {});
|
|
27804
|
-
for (const child of children) {
|
|
27805
|
-
if (isRenderable(child)) {
|
|
27806
|
-
instance.add(child);
|
|
27807
|
-
} else {
|
|
27808
|
-
const mounted = instantiate(ctx, child);
|
|
27809
|
-
instance.add(mounted);
|
|
27810
|
-
}
|
|
27811
|
-
}
|
|
27812
|
-
const delegatedInstance = wrapWithDelegates(instance, delegateMap);
|
|
27813
|
-
const pendingCalls = vnode.__pendingCalls;
|
|
27814
|
-
if (pendingCalls) {
|
|
27815
|
-
for (const call of pendingCalls) {
|
|
27816
|
-
if (call.isProperty) {
|
|
27817
|
-
;
|
|
27818
|
-
delegatedInstance[call.method] = call.args[0];
|
|
27819
|
-
} else {
|
|
27820
|
-
;
|
|
27821
|
-
delegatedInstance[call.method].apply(delegatedInstance, call.args);
|
|
27822
|
-
}
|
|
27823
|
-
}
|
|
27824
|
-
}
|
|
27825
|
-
return delegatedInstance;
|
|
27826
|
-
}
|
|
27827
|
-
const resolved = type(props || {}, children);
|
|
27828
|
-
const inst = instantiate(ctx, resolved);
|
|
27829
|
-
return wrapWithDelegates(inst, delegateMap);
|
|
27830
|
-
}
|
|
27831
|
-
function delegate(mapping, vnode) {
|
|
27832
|
-
if (isRenderable(vnode)) {
|
|
27833
|
-
return wrapWithDelegates(vnode, mapping);
|
|
27834
|
-
}
|
|
27835
|
-
if (!vnode || typeof vnode !== "object") return vnode;
|
|
27836
|
-
vnode.__delegateMap = { ...vnode.__delegateMap || {}, ...mapping };
|
|
27837
|
-
return vnode;
|
|
27688
|
+
return _maybeMakeRenderable?.(ctx, node) ?? null;
|
|
27838
27689
|
}
|
|
27839
27690
|
|
|
27840
27691
|
// ../../opentui/packages/core/src/lib/renderable.validations.ts
|
|
@@ -27911,7 +27762,6 @@ function isSizeType(value) {
|
|
|
27911
27762
|
}
|
|
27912
27763
|
|
|
27913
27764
|
// ../../opentui/packages/core/src/Renderable.ts
|
|
27914
|
-
var BrandedRenderable = /* @__PURE__ */ Symbol.for("@opentui/core/Renderable");
|
|
27915
27765
|
var LayoutEvents = /* @__PURE__ */ ((LayoutEvents2) => {
|
|
27916
27766
|
LayoutEvents2["LAYOUT_CHANGED"] = "layout-changed";
|
|
27917
27767
|
LayoutEvents2["ADDED"] = "added";
|
|
@@ -27924,9 +27774,6 @@ var RenderableEvents = /* @__PURE__ */ ((RenderableEvents2) => {
|
|
|
27924
27774
|
RenderableEvents2["BLURRED"] = "blurred";
|
|
27925
27775
|
return RenderableEvents2;
|
|
27926
27776
|
})(RenderableEvents || {});
|
|
27927
|
-
function isRenderable(obj) {
|
|
27928
|
-
return !!obj?.[BrandedRenderable];
|
|
27929
|
-
}
|
|
27930
27777
|
var BaseRenderable = class _BaseRenderable extends EventEmitter {
|
|
27931
27778
|
[BrandedRenderable] = true;
|
|
27932
27779
|
static renderableNumber = 1;
|
|
@@ -32643,6 +32490,169 @@ var RootTextNodeRenderable = class extends TextNodeRenderable {
|
|
|
32643
32490
|
}
|
|
32644
32491
|
};
|
|
32645
32492
|
|
|
32493
|
+
// ../../opentui/packages/core/src/renderables/composition/vnode.ts
|
|
32494
|
+
var BrandedVNode = /* @__PURE__ */ Symbol.for("@opentui/core/VNode");
|
|
32495
|
+
function isRenderableConstructor(value) {
|
|
32496
|
+
return typeof value === "function" && value.prototype && !!value.prototype[BrandedRenderable];
|
|
32497
|
+
}
|
|
32498
|
+
function flattenChildren(children) {
|
|
32499
|
+
const result = [];
|
|
32500
|
+
for (const child of children) {
|
|
32501
|
+
if (Array.isArray(child)) {
|
|
32502
|
+
result.push(...flattenChildren(child));
|
|
32503
|
+
} else if (child !== null && child !== void 0 && child !== false) {
|
|
32504
|
+
result.push(child);
|
|
32505
|
+
}
|
|
32506
|
+
}
|
|
32507
|
+
return result;
|
|
32508
|
+
}
|
|
32509
|
+
function h(type, props, ...children) {
|
|
32510
|
+
if (typeof type !== "function") {
|
|
32511
|
+
throw new TypeError("h() received an invalid vnode type");
|
|
32512
|
+
}
|
|
32513
|
+
const vnode = {
|
|
32514
|
+
[BrandedVNode]: true,
|
|
32515
|
+
type,
|
|
32516
|
+
props,
|
|
32517
|
+
children: flattenChildren(children),
|
|
32518
|
+
__pendingCalls: []
|
|
32519
|
+
};
|
|
32520
|
+
if (isRenderableConstructor(type)) {
|
|
32521
|
+
return new Proxy(vnode, {
|
|
32522
|
+
get(target, prop, receiver) {
|
|
32523
|
+
if (prop in target) {
|
|
32524
|
+
return Reflect.get(target, prop, receiver);
|
|
32525
|
+
}
|
|
32526
|
+
if (typeof prop === "string") {
|
|
32527
|
+
const prototype = type.prototype;
|
|
32528
|
+
const hasMethod = prototype && (typeof prototype[prop] === "function" || Object.getOwnPropertyDescriptor(prototype, prop) || Object.getOwnPropertyDescriptor(Object.getPrototypeOf(prototype), prop));
|
|
32529
|
+
if (hasMethod) {
|
|
32530
|
+
return (...args) => {
|
|
32531
|
+
target.__pendingCalls = target.__pendingCalls || [];
|
|
32532
|
+
target.__pendingCalls.push({ method: prop, args });
|
|
32533
|
+
return target;
|
|
32534
|
+
};
|
|
32535
|
+
}
|
|
32536
|
+
}
|
|
32537
|
+
return Reflect.get(target, prop, receiver);
|
|
32538
|
+
},
|
|
32539
|
+
set(target, prop, value, receiver) {
|
|
32540
|
+
if (typeof prop === "string" && isRenderableConstructor(type)) {
|
|
32541
|
+
const prototype = type.prototype;
|
|
32542
|
+
const descriptor = Object.getOwnPropertyDescriptor(prototype, prop) || Object.getOwnPropertyDescriptor(Object.getPrototypeOf(prototype), prop);
|
|
32543
|
+
if (descriptor && descriptor.set) {
|
|
32544
|
+
target.__pendingCalls = target.__pendingCalls || [];
|
|
32545
|
+
target.__pendingCalls.push({ method: prop, args: [value], isProperty: true });
|
|
32546
|
+
return true;
|
|
32547
|
+
}
|
|
32548
|
+
}
|
|
32549
|
+
return Reflect.set(target, prop, value, receiver);
|
|
32550
|
+
}
|
|
32551
|
+
});
|
|
32552
|
+
}
|
|
32553
|
+
return vnode;
|
|
32554
|
+
}
|
|
32555
|
+
function isVNode(node) {
|
|
32556
|
+
return node && node[BrandedVNode];
|
|
32557
|
+
}
|
|
32558
|
+
function maybeMakeRenderable2(ctx, node) {
|
|
32559
|
+
if (isRenderable(node)) return node;
|
|
32560
|
+
if (isVNode(node)) return instantiate(ctx, node);
|
|
32561
|
+
if (process.env.NODE_ENV !== "production") {
|
|
32562
|
+
console.warn("maybeMakeRenderable received an invalid node", node);
|
|
32563
|
+
}
|
|
32564
|
+
return null;
|
|
32565
|
+
}
|
|
32566
|
+
registerMaybeMakeRenderable(maybeMakeRenderable2);
|
|
32567
|
+
function wrapWithDelegates(instance, delegateMap) {
|
|
32568
|
+
if (!delegateMap || Object.keys(delegateMap).length === 0) return instance;
|
|
32569
|
+
const descendantCache = /* @__PURE__ */ new Map();
|
|
32570
|
+
const getDescendant = (id) => {
|
|
32571
|
+
if (descendantCache.has(id)) {
|
|
32572
|
+
const cached = descendantCache.get(id);
|
|
32573
|
+
if (cached !== void 0) {
|
|
32574
|
+
return cached;
|
|
32575
|
+
}
|
|
32576
|
+
}
|
|
32577
|
+
const descendant = instance.findDescendantById(id);
|
|
32578
|
+
if (descendant) {
|
|
32579
|
+
descendantCache.set(id, descendant);
|
|
32580
|
+
}
|
|
32581
|
+
return descendant;
|
|
32582
|
+
};
|
|
32583
|
+
const proxy = new Proxy(instance, {
|
|
32584
|
+
get(target, prop, receiver) {
|
|
32585
|
+
if (typeof prop === "string" && delegateMap[prop]) {
|
|
32586
|
+
const host = getDescendant(delegateMap[prop]);
|
|
32587
|
+
if (host) {
|
|
32588
|
+
const value = host[prop];
|
|
32589
|
+
if (typeof value === "function") {
|
|
32590
|
+
return value.bind(host);
|
|
32591
|
+
}
|
|
32592
|
+
return value;
|
|
32593
|
+
}
|
|
32594
|
+
}
|
|
32595
|
+
return Reflect.get(target, prop, receiver);
|
|
32596
|
+
},
|
|
32597
|
+
set(target, prop, value, receiver) {
|
|
32598
|
+
if (typeof prop === "string" && delegateMap[prop]) {
|
|
32599
|
+
const host = getDescendant(delegateMap[prop]);
|
|
32600
|
+
if (host) {
|
|
32601
|
+
return Reflect.set(host, prop, value);
|
|
32602
|
+
}
|
|
32603
|
+
}
|
|
32604
|
+
return Reflect.set(target, prop, value, receiver);
|
|
32605
|
+
}
|
|
32606
|
+
});
|
|
32607
|
+
return proxy;
|
|
32608
|
+
}
|
|
32609
|
+
function instantiate(ctx, node) {
|
|
32610
|
+
if (isRenderable(node)) return node;
|
|
32611
|
+
if (!node || typeof node !== "object") {
|
|
32612
|
+
throw new TypeError("mount() received an invalid vnode");
|
|
32613
|
+
}
|
|
32614
|
+
const vnode = node;
|
|
32615
|
+
const { type, props } = vnode;
|
|
32616
|
+
const children = flattenChildren(vnode.children || []);
|
|
32617
|
+
const delegateMap = vnode.__delegateMap;
|
|
32618
|
+
if (isRenderableConstructor(type)) {
|
|
32619
|
+
const instance = new type(ctx, props || {});
|
|
32620
|
+
for (const child of children) {
|
|
32621
|
+
if (isRenderable(child)) {
|
|
32622
|
+
instance.add(child);
|
|
32623
|
+
} else {
|
|
32624
|
+
const mounted = instantiate(ctx, child);
|
|
32625
|
+
instance.add(mounted);
|
|
32626
|
+
}
|
|
32627
|
+
}
|
|
32628
|
+
const delegatedInstance = wrapWithDelegates(instance, delegateMap);
|
|
32629
|
+
const pendingCalls = vnode.__pendingCalls;
|
|
32630
|
+
if (pendingCalls) {
|
|
32631
|
+
for (const call of pendingCalls) {
|
|
32632
|
+
if (call.isProperty) {
|
|
32633
|
+
;
|
|
32634
|
+
delegatedInstance[call.method] = call.args[0];
|
|
32635
|
+
} else {
|
|
32636
|
+
;
|
|
32637
|
+
delegatedInstance[call.method].apply(delegatedInstance, call.args);
|
|
32638
|
+
}
|
|
32639
|
+
}
|
|
32640
|
+
}
|
|
32641
|
+
return delegatedInstance;
|
|
32642
|
+
}
|
|
32643
|
+
const resolved = type(props || {}, children);
|
|
32644
|
+
const inst = instantiate(ctx, resolved);
|
|
32645
|
+
return wrapWithDelegates(inst, delegateMap);
|
|
32646
|
+
}
|
|
32647
|
+
function delegate(mapping, vnode) {
|
|
32648
|
+
if (isRenderable(vnode)) {
|
|
32649
|
+
return wrapWithDelegates(vnode, mapping);
|
|
32650
|
+
}
|
|
32651
|
+
if (!vnode || typeof vnode !== "object") return vnode;
|
|
32652
|
+
vnode.__delegateMap = { ...vnode.__delegateMap || {}, ...mapping };
|
|
32653
|
+
return vnode;
|
|
32654
|
+
}
|
|
32655
|
+
|
|
32646
32656
|
// ../../opentui/packages/core/src/renderables/composition/constructs.ts
|
|
32647
32657
|
function Generic(props, ...children) {
|
|
32648
32658
|
return h(VRenderable, props || {}, ...children);
|
|
@@ -41603,7 +41613,7 @@ export {
|
|
|
41603
41613
|
italic,
|
|
41604
41614
|
link,
|
|
41605
41615
|
magenta,
|
|
41606
|
-
maybeMakeRenderable,
|
|
41616
|
+
maybeMakeRenderable2 as maybeMakeRenderable,
|
|
41607
41617
|
measureText,
|
|
41608
41618
|
parseAlign,
|
|
41609
41619
|
parseAlignItems,
|