Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

minitel-standalone

Package Overview
Dependencies
Maintainers
0
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

minitel-standalone - npm Package Compare versions

Comparing version 1.8.3 to 1.9.0

8

dist/abstract/minitelobject.d.ts

@@ -15,2 +15,10 @@ /// <reference types="node" />

defaultAttributes: T;
getDimensions(attributes: T, inheritMe: Partial<T>): ({
width: number;
height: number;
});
getDimensionsWrapper(inheritedAttributes: Partial<T>, forcedAttributes?: Partial<T>): ({
width: number;
height: number;
});
constructor(children: MinitelObject[], attributes: Partial<T>, minitel: Minitel);

@@ -17,0 +25,0 @@ appendChild(child: MinitelObject): void;

@@ -11,2 +11,17 @@ "use strict";

class MinitelObject extends node_events_1.EventEmitter {
getDimensions(attributes, inheritMe) {
console.warn('getDimensions was not implemented on this component INFORMA GET YOUR SHIT TOGETHER');
const tempRender = this.render(attributes, inheritMe);
return { width: tempRender.width, height: tempRender.height };
}
getDimensionsWrapper(inheritedAttributes, forcedAttributes) {
const attributes = Object.assign(Object.assign(Object.assign(Object.assign({}, this.defaultAttributes), inheritedAttributes), this.attributes), forcedAttributes);
const pad = utils_js_1.padding.normalise(attributes.pad);
attributes.width = attributes.width != null ? utils_js_1.padding.exludeX(attributes.width, pad) : null;
attributes.height = attributes.height != null ? utils_js_1.padding.exludeY(attributes.height, pad) : null;
let result = this.getDimensions(attributes, (0, utils_js_1.inheritedProps)(Object.assign(Object.assign(Object.assign({}, inheritedAttributes), this.attributes), forcedAttributes)));
result.height += pad[0] + pad[2];
result.width += pad[1] + pad[3];
return result;
}
constructor(children, attributes, minitel) {

@@ -13,0 +28,0 @@ super();

4

dist/abstract/textnode.d.ts

@@ -8,4 +8,8 @@ import { MinitelObject } from './minitelobject.js';

constructor(text: string, attributes: Partial<MinitelObjectAttributes>, minitel: Minitel);
getDimensions(attributes: MinitelObjectAttributes, inheritMe: Partial<MinitelObjectAttributes>): {
width: number;
height: number;
};
render(attributes: MinitelObjectAttributes, inheritMe: Partial<MinitelObjectAttributes>): RichCharGrid;
renderLines(inheritedAttributes: Partial<MinitelObjectAttributes>, forcedAttributes: Partial<RenderLinesAttributes>): RichCharGrid[];
}

@@ -16,2 +16,25 @@ "use strict";

}
getDimensions(attributes, inheritMe) {
let text = this.text;
const width = attributes.width;
const xScalingFactor = attributes.doubleWidth ? 2 : 1;
const yScalingFactor = attributes.doubleHeight ? 2 : 1;
if (width != null) {
const actualWidth = Math.floor(width / xScalingFactor);
switch (attributes.wrap) {
case 'word-break':
text = (0, word_wrap_1.default)(text, { indent: '', width: actualWidth, cut: true });
break;
case 'word-wrap':
text = (0, word_wrap_1.default)(text, { indent: '', width: actualWidth });
break;
case 'clip':
text = text.split('\n').map((v) => v.slice(0, actualWidth)).join('\n');
break;
}
}
const lines = text.split(/\r?\n/g);
const concreteWidth = Math.max(...lines.map((v) => v.length * xScalingFactor));
return { width: concreteWidth, height: lines.length * yScalingFactor };
}
render(attributes, inheritMe) {

@@ -18,0 +41,0 @@ let text = this.text;

@@ -8,2 +8,6 @@ import { MinitelObject } from '../abstract/minitelobject.js';

constructor(children: never[] | undefined, attributes: Partial<T>, minitel: Minitel);
getDimensions(attributes: ContainerAttributes, inheritMe: Partial<ContainerAttributes>): {
width: number;
height: number;
};
render(attributes: ContainerAttributes, inheritMe: Partial<ContainerAttributes>): import("../richchargrid.js").RichCharGrid;

@@ -10,0 +14,0 @@ }

@@ -18,2 +18,5 @@ "use strict";

}
getDimensions(attributes, inheritMe) {
return this.children[0].getDimensionsWrapper(inheritMe, Object.assign(Object.assign({}, (attributes.width != null ? { width: attributes.width } : {})), (attributes.height != null ? { height: attributes.height } : {})));
}
render(attributes, inheritMe) {

@@ -20,0 +23,0 @@ const fillChar = new richchar_js_1.RichChar(attributes.fillChar, attributes).noSize();

@@ -18,2 +18,6 @@ import { Focusable, FocusableAttributes } from '../abstract/focusable.js';

constructor(children: [], attributes: Partial<InputAttributes>, minitel: Minitel);
getDimensions(attributes: InputAttributes, inheritMe: Partial<InputAttributes>): {
width: number;
height: number;
};
set value(newValue: string);

@@ -20,0 +24,0 @@ get value(): string;

@@ -21,2 +21,5 @@ "use strict";

}
getDimensions(attributes, inheritMe) {
return { width: attributes.width, height: attributes.height };
}
set value(newValue) {

@@ -23,0 +26,0 @@ const oldValue = this._value;

5

dist/components/minitel.d.ts

@@ -31,2 +31,6 @@ /// <reference types="node" />

constructor(stream: Duplex, settings: Partial<MinitelSettings>);
getDimensions(): {
width: number;
height: number;
};
readyAsync(): Promise<void>;

@@ -42,4 +46,3 @@ invalidateRender(): void;

queueCommandAsync(command: string, expected: string | RegExp): Promise<string>;
requestAnimationFrame(callback: (isArtificial: boolean) => any): void;
get colors(): number[][];
}

@@ -121,2 +121,5 @@ "use strict";

}
getDimensions() {
return { width: 40, height: 24 + +this.settings.statusBar };
}
readyAsync() {

@@ -133,7 +136,5 @@ return __awaiter(this, void 0, void 0, function* () {

let renderGrid;
const { width, height } = this.getDimensions();
try {
renderGrid = this.renderWrapper({}, {
width: 40,
height: 24 + +this.settings.statusBar,
});
renderGrid = this.renderWrapper({}, { width, height });
}

@@ -148,4 +149,4 @@ catch (err) {

}
renderGrid.setHeight(24 + +this.settings.statusBar, 'start', new richchar_js_1.RichChar(' '));
renderGrid.setWidth(40, 'start', new richchar_js_1.RichChar(' '));
renderGrid.setHeight(height, 'start', new richchar_js_1.RichChar(' '));
renderGrid.setWidth(width, 'start', new richchar_js_1.RichChar(' '));
this.handleFocus();

@@ -259,5 +260,3 @@ const outputString = ['\x14\x1e'];

// this.stream.write('\x0c');
const renderMe = this.renderString();
this.stream.write(renderMe);
setTimeout((function () { this.emit('frame', false); }).bind(this), renderMe.length * (8000 / (this.speed || 300)));
this.stream.write(this.renderString());
}

@@ -272,6 +271,2 @@ queueCommand(command, expected, callback = ((_arg0) => { })) {

}
requestAnimationFrame(callback) {
this.once('frame', callback);
setTimeout((function () { callback(false); this.off('frame', callback); }).bind(this), 100);
}
get colors() {

@@ -278,0 +273,0 @@ if (this.model === 'Bs0') {

@@ -10,3 +10,7 @@ import { MinitelObject } from '../abstract/minitelobject.js';

constructor(children: TextNode[], attributes: Partial<MinitelObjectAttributes>, minitel: Minitel);
getDimensions(attributes: MinitelObjectAttributes, inheritMe: Partial<MinitelObjectAttributes>): {
width: number;
height: number;
};
render(attributes: MinitelObjectAttributes, inheritMe: Partial<MinitelObjectAttributes>): RichCharGrid;
}

@@ -16,2 +16,20 @@ "use strict";

}
getDimensions(attributes, inheritMe) {
const lines = [new richchargrid_js_1.RichCharGrid([[]])]; // Again, if someone smarter than me can figure out an elegant way, suit urself
for (let child of this.children) {
const render = child.renderLines(inheritMe, {
width: attributes.width,
forcedIndent: lines.at(-1).width,
});
const newMaxIdx = lines.length - 1;
for (let lineIdx in render) {
if (+lineIdx !== 0) {
lines[newMaxIdx + +lineIdx] = new richchargrid_js_1.RichCharGrid([[]]);
}
lines[newMaxIdx + +lineIdx].mergeX(render[+lineIdx], 'end');
}
}
const width = attributes.width || Math.max(...lines.map((v) => v.width));
return { width, height: lines.reduce((p, v) => p + v.height, 0) };
}
render(attributes, inheritMe) {

@@ -18,0 +36,0 @@ const fillChar = new richchar_js_1.RichChar(attributes.fillChar, attributes).noSize();

@@ -26,2 +26,6 @@ import { Focusable } from '../abstract/focusable.js';

unmount(): void;
getDimensions(attributes: ScrollableAttributes, inheritMe: Partial<ScrollableAttributes>): {
width: number;
height: number;
};
render(attributes: ScrollableAttributes, inheritMe: Partial<ScrollableAttributes>): RichCharGrid;

@@ -28,0 +32,0 @@ get disabled(): boolean;

@@ -95,2 +95,46 @@ "use strict";

}
getDimensions(attributes, inheritMe) {
const childrenDimensionsFirstTry = this.children[0].getDimensionsWrapper(inheritMe);
let renderAttributes = attributes;
let autoedX = false;
let autoedY = false;
if (attributes.width != null && attributes.height != null && attributes.overflowY !== 'hidden') {
if (attributes.height != null) {
if (attributes.overflowY === 'auto') {
renderAttributes = Object.assign(Object.assign({}, attributes), { width: attributes.overflowX === 'hidden' ? attributes.width : null, height: null });
const possibleRender = super.getDimensions(renderAttributes, inheritMe);
if (possibleRender.height <= attributes.height)
autoedY = true;
}
if (!autoedY) {
const width = attributes.width != null && attributes.overflowX === 'hidden'
? attributes.width - 1
: null;
renderAttributes = Object.assign(Object.assign({}, attributes), { width, height: null });
}
}
}
else {
if (attributes.width != null) {
if (attributes.overflowX === 'auto') {
renderAttributes = Object.assign(Object.assign({}, attributes), { height: attributes.height, width: null });
const possibleRender = super.getDimensions(renderAttributes, inheritMe);
if (possibleRender.width <= attributes.width)
autoedX = true;
}
if (!autoedX) {
const height = attributes.height != null ? attributes.height - 1 : null;
renderAttributes = Object.assign(Object.assign({}, attributes), { height, width: null });
}
}
}
const dimensions = super.getDimensions(renderAttributes, inheritMe);
if (attributes.overflowY !== 'hidden' && attributes.overflowY !== 'noscrollbar' && !autoedY && attributes.height != null) {
dimensions.width += 1;
}
if (attributes.overflowX !== 'hidden' && attributes.overflowX !== 'noscrollbar' && !autoedX && attributes.width != null) {
dimensions.height += 1;
}
return dimensions;
}
render(attributes, inheritMe) {

@@ -100,19 +144,12 @@ // now its 3 am and i don't know how i'll read back

const fillChar = new richchar_js_1.RichChar(attributes.fillChar, attributes);
let render;
let renderAttributes = attributes;
let autoedX = false;
let autoedY = false;
if (attributes.width == null && attributes.height == null) {
render = super.render(attributes, inheritMe);
}
else if (attributes.overflowY !== 'hidden') {
if (attributes.height == null) {
render = super.render(attributes, inheritMe);
}
else {
if (attributes.width != null && attributes.height != null && attributes.overflowY !== 'hidden') {
if (attributes.height != null) {
if (attributes.overflowY === 'auto') {
const possibleRender = super.render(Object.assign(Object.assign({}, attributes), { width: attributes.overflowX === 'hidden' ? attributes.width : null, height: null }), inheritMe);
if (possibleRender.height <= attributes.height) {
render = possibleRender;
renderAttributes = Object.assign(Object.assign({}, attributes), { width: attributes.overflowX === 'hidden' ? attributes.width : null, height: null });
const possibleRender = super.getDimensions(renderAttributes, inheritMe);
if (possibleRender.height <= attributes.height)
autoedY = true;
}
}

@@ -123,3 +160,3 @@ if (!autoedY) {

: null;
render = super.render(Object.assign(Object.assign({}, attributes), { width, height: null }), inheritMe);
renderAttributes = Object.assign(Object.assign({}, attributes), { width, height: null });
}

@@ -129,20 +166,16 @@ }

else {
if (attributes.width == null) {
render = super.render(attributes, inheritMe);
}
else {
if (attributes.width != null) {
if (attributes.overflowX === 'auto') {
const possibleRender = super.render(Object.assign(Object.assign({}, attributes), { height: attributes.height, width: null }), inheritMe);
if (possibleRender.width <= attributes.width) {
render = possibleRender;
renderAttributes = Object.assign(Object.assign({}, attributes), { height: attributes.height, width: null });
const possibleRender = super.getDimensions(renderAttributes, inheritMe);
if (possibleRender.width <= attributes.width)
autoedX = true;
}
}
if (!autoedX) {
const height = attributes.height != null ? attributes.height - 1 : null;
render = super.render(Object.assign(Object.assign({}, attributes), { height, width: null }), inheritMe);
renderAttributes = Object.assign(Object.assign({}, attributes), { height, width: null });
}
}
}
const finalRender = render; // Source: Trust me bro
const finalRender = super.render(renderAttributes, inheritMe); // Source: Trust me bro
const originalWidth = finalRender.width;

@@ -149,0 +182,0 @@ const originalHeight = finalRender.height;

@@ -9,4 +9,8 @@ import { MinitelObject } from "../abstract/minitelobject";

constructor(children: (TextNode | Span)[], attributes: Partial<MinitelObjectAttributes>, minitel: Minitel);
getDimensions(attributes: MinitelObjectAttributes, inheritMe: Partial<MinitelObjectAttributes>): {
width: number;
height: number;
};
render(attributes: MinitelObjectAttributes, inheritMe: Partial<MinitelObjectAttributes>): RichCharGrid;
renderLines(inheritedAttributes: Partial<MinitelObjectAttributes>, forcedAttributes: Partial<RenderLinesAttributes>): RichCharGrid[];
}

@@ -16,2 +16,20 @@ "use strict";

}
getDimensions(attributes, inheritMe) {
const lines = [new richchargrid_1.RichCharGrid([[]])];
for (let child of this.children) {
const render = child.renderLines(inheritMe, {
width: attributes.width,
forcedIndent: lines.at(-1).width,
});
const newMaxIdx = lines.length - 1;
for (let lineIdx in render) {
if (+lineIdx !== 0) {
lines[newMaxIdx + +lineIdx] = new richchargrid_1.RichCharGrid([[]]);
}
lines[newMaxIdx + +lineIdx].mergeX(render[+lineIdx], 'end');
}
}
const width = attributes.width || Math.max(...lines.map((v) => v.width));
return { width, height: lines.reduce((p, v) => p + v.height, 0) };
}
render(attributes, inheritMe) {

@@ -18,0 +36,0 @@ const fillChar = new richchar_1.RichChar(attributes.fillChar, attributes).noSize();

@@ -9,2 +9,6 @@ import { MinitelObject } from '../abstract/minitelobject.js';

constructor(children: MinitelObject[], attributes: Partial<MinitelObjectAttributes>, minitel: Minitel);
getDimensions(attributes: XJoinAttributes, inheritMe: Partial<XJoinAttributes>): {
width: number;
height: number;
};
render(attributes: XJoinAttributes, inheritMe: Partial<XJoinAttributes>): RichCharGrid;

@@ -11,0 +15,0 @@ }

@@ -13,6 +13,44 @@ "use strict";

}
getDimensions(attributes, inheritMe) {
const heightIfStretch = attributes.height || this.children.reduce((p, c) => {
const h = c.getDimensionsWrapper(inheritMe).height;
if (h == null)
return p;
return Math.max(p, h);
}, -Infinity);
let cumulatedWidth = 0;
const rendersNoFlexGrow = this.children.map((v) => {
if (v.attributes.flexGrow)
return null;
const render = v.getDimensionsWrapper(inheritMe, Object.assign({}, (attributes.heightAlign === 'stretch' ? { height: heightIfStretch } : {})));
cumulatedWidth += render.width;
return render;
});
const flexGrowTotal = this.children.reduce((p, c) => p + +(c.attributes.flexGrow || 0), 0);
const remainingSpace = attributes.width != null ? attributes.width - cumulatedWidth : null;
const unitOfFlexGrowSpace = remainingSpace != null ? remainingSpace / flexGrowTotal : null;
let usedRemainingSpace = 0;
const rendersYesFlexGrow = this.children.map((v) => {
if (!v.attributes.flexGrow)
return null;
if (unitOfFlexGrowSpace != null && remainingSpace != null) {
const prevUsedRemSpace = usedRemainingSpace;
usedRemainingSpace += unitOfFlexGrowSpace;
return v.getDimensionsWrapper(inheritMe, Object.assign(Object.assign({}, (attributes.heightAlign === 'stretch' ? { height: heightIfStretch } : {})), { width: Math.round(usedRemainingSpace) - Math.round(prevUsedRemSpace) }));
}
return v.getDimensionsWrapper(inheritMe);
});
const dimensions = rendersNoFlexGrow.map((v, i) => v != null ? v : rendersYesFlexGrow[i]);
const { gap } = attributes;
const width = attributes.width
|| (typeof gap === 'number' ? gap : 0) * this.children.length + dimensions.reduce((p, v) => p + v.width, 0);
const height = attributes.heightAlign === 'stretch'
? heightIfStretch
: attributes.height || Math.max(...dimensions.map((v) => v.height));
return { width, height };
}
render(attributes, inheritMe) {
const fillChar = new richchar_js_1.RichChar(attributes.fillChar, attributes).noSize();
const heightIfStretch = attributes.height || this.children.reduce((p, c) => {
const h = c.renderWrapper(inheritMe).height;
const h = c.getDimensionsWrapper(inheritMe).height;
if (h == null)

@@ -19,0 +57,0 @@ return p;

@@ -9,2 +9,6 @@ import { MinitelObject } from '../abstract/minitelobject.js';

constructor(children: MinitelObject[], attributes: Partial<MinitelObjectAttributes>, minitel: Minitel);
getDimensions(attributes: YJoinAttributes, inheritMe: Partial<YJoinAttributes>): {
width: number;
height: number;
};
render(attributes: YJoinAttributes, inheritMe: Partial<YJoinAttributes>): RichCharGrid;

@@ -11,0 +15,0 @@ }

@@ -13,6 +13,44 @@ "use strict";

}
getDimensions(attributes, inheritMe) {
const widthIfStretch = attributes.width || this.children.reduce((p, c) => {
const w = c.getDimensionsWrapper(inheritMe).width;
if (w == null)
return p;
return Math.max(p, w);
}, -Infinity);
let cumulatedHeight = 0;
const rendersNoFlexGrow = this.children.map((v) => {
if (v.attributes.flexGrow)
return null;
const render = v.getDimensionsWrapper(inheritMe, Object.assign({}, (attributes.widthAlign === 'stretch' ? { width: widthIfStretch } : {})));
cumulatedHeight += render.height;
return render;
});
const flexGrowTotal = this.children.reduce((p, c) => p + +(c.attributes.flexGrow || 0), 0);
const remainingSpace = attributes.height != null ? attributes.height - cumulatedHeight : null;
const unitOfFlexGrowSpace = remainingSpace != null ? remainingSpace / flexGrowTotal : null;
let usedRemainingSpace = 0;
const rendersYesFlexGrow = this.children.map((v) => {
if (!v.attributes.flexGrow)
return null;
if (unitOfFlexGrowSpace != null && remainingSpace != null) {
const prevUsedRemSpace = usedRemainingSpace;
usedRemainingSpace += unitOfFlexGrowSpace;
return v.getDimensionsWrapper(inheritMe, Object.assign(Object.assign({}, (attributes.widthAlign === 'stretch' ? { width: widthIfStretch } : {})), { height: Math.round(usedRemainingSpace) - Math.round(prevUsedRemSpace) }));
}
return v.getDimensionsWrapper(inheritMe);
});
const dimensions = rendersNoFlexGrow.map((v, i) => v != null ? v : rendersYesFlexGrow[i]);
const { gap } = attributes;
const height = attributes.height
|| (typeof gap === 'number' ? gap : 0) * this.children.length + dimensions.reduce((p, v) => p + v.height, 0);
const width = attributes.widthAlign === 'stretch'
? widthIfStretch
: attributes.width || Math.max(...dimensions.map((v) => v.width));
return { width, height };
}
render(attributes, inheritMe) {
const fillChar = new richchar_js_1.RichChar(attributes.fillChar, attributes).noSize();
const widthIfStretch = attributes.width || this.children.reduce((p, c) => {
const w = c.renderWrapper(inheritMe).width;
const w = c.getDimensionsWrapper(inheritMe).width;
if (w == null)

@@ -19,0 +57,0 @@ return p;

@@ -9,2 +9,6 @@ import { MinitelObject } from '../abstract/minitelobject.js';

constructor(children: MinitelObject[], attributes: Partial<ZJoinAttributes>, minitel: Minitel);
getDimensions(attributes: ZJoinAttributes, inheritMe: Partial<ZJoinAttributes>): {
width: number;
height: number;
};
render(attributes: ZJoinAttributes, inheritMe: Partial<ZJoinAttributes>): RichCharGrid;

@@ -11,0 +15,0 @@ }

@@ -12,2 +12,8 @@ "use strict";

}
getDimensions(attributes, inheritMe) {
const dimensions = this.children.map((v) => v.getDimensionsWrapper(inheritMe, Object.assign({ width: attributes.width, height: attributes.height }, (attributes.inheritTransparency ? { fillChar: '\x09' } : {}))));
const width = Math.max(...dimensions.map((v) => v.width));
const height = Math.max(...dimensions.map((v) => v.height));
return { width, height };
}
render(attributes, inheritMe) {

@@ -14,0 +20,0 @@ const fillChar = new richchar_js_1.RichChar(attributes.fillChar, attributes).noSize();

{
"name": "minitel-standalone",
"version": "1.8.3",
"version": "1.9.0",
"description": "A standalone package for minitel components",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -28,2 +28,28 @@ import { EventEmitter } from 'node:events';

defaultAttributes: T = MinitelObject.defaultAttributes as T;
getDimensions(attributes: T, inheritMe: Partial<T>): ({ width: number, height: number }) {
const tempRender = this.render(attributes, inheritMe);
return { width: tempRender.width, height: tempRender.height };
}
getDimensionsWrapper(inheritedAttributes: Partial<T>, forcedAttributes?: Partial<T>): ({ width: number, height: number }) {
const attributes: T = {
...this.defaultAttributes,
...inheritedAttributes,
...this.attributes,
...forcedAttributes,
};
const pad = padding.normalise(attributes.pad);
attributes.width = attributes.width != null ? padding.exludeX(attributes.width, pad) : null;
attributes.height = attributes.height != null ? padding.exludeY(attributes.height, pad) : null;
let result = this.getDimensions(attributes, inheritedProps({
...inheritedAttributes,
...this.attributes,
...forcedAttributes,
}));
result.height += pad[0] + pad[2];
result.width += pad[1] + pad[3];
return result;
}
constructor(children: MinitelObject[], attributes: Partial<T>, minitel: Minitel) {

@@ -30,0 +56,0 @@ super();

@@ -14,2 +14,27 @@ import { MinitelObject } from './minitelobject.js';

}
getDimensions(attributes: MinitelObjectAttributes, inheritMe: Partial<MinitelObjectAttributes>): { width: number; height: number; } {
let text = this.text;
const width = attributes.width;
const xScalingFactor = attributes.doubleWidth ? 2 : 1;
const yScalingFactor = attributes.doubleHeight ? 2 : 1;
if (width != null) {
const actualWidth = Math.floor(width / xScalingFactor);
switch (attributes.wrap) {
case 'word-break':
text = wrap(text, { indent: '', width: actualWidth, cut: true });
break;
case 'word-wrap':
text = wrap(text, { indent: '', width: actualWidth });
break;
case 'clip':
text = text.split('\n').map((v) => v.slice(0, actualWidth)).join('\n');
break;
}
}
const lines = text.split(/\r?\n/g);
const concreteWidth = Math.max(...lines.map((v) => v.length * xScalingFactor));
return { width: concreteWidth, height: lines.length * yScalingFactor };
}
render(attributes: MinitelObjectAttributes, inheritMe: Partial<MinitelObjectAttributes>) {

@@ -77,2 +102,2 @@ let text = this.text;

}
}
}

@@ -21,2 +21,8 @@ import { MinitelObject } from '../abstract/minitelobject.js';

}
getDimensions(attributes: ContainerAttributes, inheritMe: Partial<ContainerAttributes>): { width: number; height: number; } {
return this.children[0].getDimensionsWrapper(inheritMe, {
...(attributes.width != null ? { width: attributes.width } : {}),
...(attributes.height != null ? { height: attributes.height } : {}),
});
}
render(attributes: ContainerAttributes, inheritMe: Partial<ContainerAttributes>) {

@@ -23,0 +29,0 @@ const fillChar = new RichChar(attributes.fillChar, attributes).noSize();

@@ -42,2 +42,5 @@ import { Focusable, FocusableAttributes } from '../abstract/focusable.js';

}
getDimensions(attributes: InputAttributes, inheritMe: Partial<InputAttributes>): { width: number; height: number; } {
return { width: attributes.width!, height: attributes.height! }
}
set value(newValue: string) {

@@ -44,0 +47,0 @@ const oldValue = this._value;

@@ -156,2 +156,5 @@ import { Duplex } from 'stream';

}
getDimensions() {
return { width: 40, height: 24 + +this.settings.statusBar };
}
async readyAsync() {

@@ -166,7 +169,7 @@ await Promise.all(this.tillReady);

let renderGrid;
const { width, height } = this.getDimensions();
try {
renderGrid = this.renderWrapper({}, {
width: 40,
height: 24 + +this.settings.statusBar,
});
renderGrid = this.renderWrapper({}, { width, height });
} catch (err) {

@@ -180,4 +183,4 @@ if (err instanceof InvalidRender) {

renderGrid.setHeight(24 + +this.settings.statusBar, 'start', new RichChar(' '));
renderGrid.setWidth(40, 'start', new RichChar(' '));
renderGrid.setHeight(height, 'start', new RichChar(' '));
renderGrid.setWidth(width, 'start', new RichChar(' '));

@@ -320,5 +323,3 @@ this.handleFocus();

// this.stream.write('\x0c');
const renderMe = this.renderString();
this.stream.write(renderMe);
setTimeout((function (this: Minitel) { this.emit('frame', false) }).bind(this), renderMe.length * (8000 / (this.speed || 300)));
this.stream.write(this.renderString());
}

@@ -335,6 +336,2 @@ queueCommand(command: string, expected: string | RegExp, callback: ((_arg0: string) => any) = ((_arg0: string) => {})) {

}
requestAnimationFrame(callback: (isArtificial: boolean) => any) {
this.once('frame', callback);
setTimeout((function (this: Minitel) { callback(false); this.off('frame', callback) }).bind(this), 100);
}
get colors() {

@@ -341,0 +338,0 @@ if (this.model === 'Bs0') {

@@ -20,2 +20,22 @@ import { MinitelObject } from '../abstract/minitelobject.js';

}
getDimensions(attributes: MinitelObjectAttributes, inheritMe: Partial<MinitelObjectAttributes>) {
const lines = [new RichCharGrid([[]])]; // Again, if someone smarter than me can figure out an elegant way, suit urself
for (let child of this.children) {
const render = child.renderLines(inheritMe, {
width: attributes.width,
forcedIndent: lines.at(-1)!.width,
});
const newMaxIdx = lines.length - 1;
for (let lineIdx in render) {
if (+lineIdx !== 0) {
lines[newMaxIdx + +lineIdx] = new RichCharGrid([[]]);
}
lines[newMaxIdx + +lineIdx].mergeX(render[+lineIdx], 'end');
}
}
const width = attributes.width || Math.max(...lines.map((v) => v.width));
return { width, height: lines.reduce((p, v) => p + v.height, 0) };
}
render(attributes: MinitelObjectAttributes, inheritMe: Partial<MinitelObjectAttributes>) {

@@ -22,0 +42,0 @@ const fillChar = new RichChar(attributes.fillChar, attributes).noSize();

@@ -106,2 +106,60 @@ import { Focusable } from '../abstract/focusable.js';

}
getDimensions(attributes: ScrollableAttributes, inheritMe: Partial<ScrollableAttributes>) {
const childrenDimensionsFirstTry = this.children[0].getDimensionsWrapper(inheritMe);
let renderAttributes = attributes;
let autoedX = false;
let autoedY = false;
if (attributes.width != null && attributes.height != null && attributes.overflowY !== 'hidden') {
if (attributes.height != null) {
if (attributes.overflowY === 'auto') {
renderAttributes = {
...attributes,
width: attributes.overflowX === 'hidden' ? attributes.width : null,
height: null,
};
const possibleRender = super.getDimensions(renderAttributes, inheritMe);
if (possibleRender.height <= attributes.height) autoedY = true;
}
if (!autoedY) {
const width = attributes.width != null && attributes.overflowX === 'hidden'
? attributes.width - 1
: null;
renderAttributes = { ...attributes, width, height: null };
}
}
} else {
if (attributes.width != null) {
if (attributes.overflowX === 'auto') {
renderAttributes = {
...attributes,
height: attributes.height,
width: null,
};
const possibleRender = super.getDimensions(renderAttributes, inheritMe);
if (possibleRender.width <= attributes.width) autoedX = true;
}
if (!autoedX) {
const height = attributes.height != null ? attributes.height - 1 : null;
renderAttributes = { ...attributes, height, width: null };
}
}
}
const dimensions = super.getDimensions(renderAttributes, inheritMe);
if (attributes.overflowY !== 'hidden' && attributes.overflowY !== 'noscrollbar' && !autoedY && attributes.height != null) {
dimensions.width += 1;
}
if (attributes.overflowX !== 'hidden' && attributes.overflowX !== 'noscrollbar' && !autoedX && attributes.width != null) {
dimensions.height += 1;
}
return dimensions;
}
render(attributes: ScrollableAttributes, inheritMe: Partial<ScrollableAttributes>) {

@@ -113,3 +171,3 @@ // now its 3 am and i don't know how i'll read back

let render: RichCharGrid;
let renderAttributes = attributes;

@@ -119,18 +177,12 @@ let autoedX = false;

if (attributes.width == null && attributes.height == null) {
render = super.render(attributes, inheritMe);
} else if (attributes.overflowY !== 'hidden') {
if (attributes.height == null) {
render = super.render(attributes, inheritMe);
} else {
if (attributes.width != null && attributes.height != null && attributes.overflowY !== 'hidden') {
if (attributes.height != null) {
if (attributes.overflowY === 'auto') {
const possibleRender = super.render({
renderAttributes = {
...attributes,
width: attributes.overflowX === 'hidden' ? attributes.width : null,
height: null,
}, inheritMe);
if (possibleRender.height <= attributes.height) {
render = possibleRender;
autoedY = true;
}
};
const possibleRender = super.getDimensions(renderAttributes, inheritMe);
if (possibleRender.height <= attributes.height) autoedY = true;
}

@@ -143,19 +195,15 @@

render = super.render({ ...attributes, width, height: null }, inheritMe);
renderAttributes = { ...attributes, width, height: null };
}
}
} else {
if (attributes.width == null) {
render = super.render(attributes, inheritMe);
} else {
if (attributes.width != null) {
if (attributes.overflowX === 'auto') {
const possibleRender = super.render({
renderAttributes = {
...attributes,
height: attributes.height,
width: null,
}, inheritMe);
if (possibleRender.width <= attributes.width) {
render = possibleRender;
autoedX = true;
}
};
const possibleRender = super.getDimensions(renderAttributes, inheritMe);
if (possibleRender.width <= attributes.width) autoedX = true;
}

@@ -166,7 +214,7 @@

render = super.render({ ...attributes, height, width: null }, inheritMe);
renderAttributes = { ...attributes, height, width: null };
}
}
}
const finalRender = render!; // Source: Trust me bro
const finalRender = super.render(renderAttributes, inheritMe); // Source: Trust me bro

@@ -173,0 +221,0 @@ const originalWidth = finalRender.width;

@@ -20,2 +20,23 @@ import { MinitelObject } from "../abstract/minitelobject";

getDimensions(attributes: MinitelObjectAttributes, inheritMe: Partial<MinitelObjectAttributes>): { width: number; height: number; } {
const lines = [new RichCharGrid([[]])];
for (let child of this.children) {
const render = child.renderLines(inheritMe, { // Someone smarter than me will figure out something better than this
width: attributes.width,
forcedIndent: lines.at(-1)!.width,
});
const newMaxIdx = lines.length - 1;
for (let lineIdx in render) {
if (+lineIdx !== 0) {
lines[newMaxIdx + +lineIdx] = new RichCharGrid([[]]);
}
lines[newMaxIdx + +lineIdx].mergeX(render[+lineIdx], 'end');
}
}
const width = attributes.width || Math.max(...lines.map((v) => v.width));
return { width, height: lines.reduce((p, v) => p + v.height, 0) };
}
render(attributes: MinitelObjectAttributes, inheritMe: Partial<MinitelObjectAttributes>) {

@@ -22,0 +43,0 @@ const fillChar = new RichChar(attributes.fillChar, attributes).noSize();

@@ -5,3 +5,3 @@ import { MinitelObject } from '../abstract/minitelobject.js';

import { Align, MinitelObjectAttributes } from '../types.js';
import { alignInvrt, inheritedProps } from '../utils.js';
import { alignInvrt } from '../utils.js';
import type { Minitel } from './minitel.js';

@@ -20,2 +20,53 @@

}
getDimensions(attributes: XJoinAttributes, inheritMe: Partial<XJoinAttributes>): { width: number; height: number; } {
const heightIfStretch = attributes.height || this.children.reduce((p, c) => {
const h = c.getDimensionsWrapper(inheritMe).height;
if (h == null) return p;
return Math.max(p, h);
}, -Infinity);
let cumulatedWidth = 0;
const rendersNoFlexGrow = this.children.map((v) => {
if (v.attributes.flexGrow) return null;
const render = v.getDimensionsWrapper(inheritMe, {
...(attributes.heightAlign === 'stretch' ? { height: heightIfStretch } : {}),
});
cumulatedWidth += render.width;
return render;
});
const flexGrowTotal = this.children.reduce((p, c) => p + +(c.attributes.flexGrow || 0), 0);
const remainingSpace = attributes.width != null ? attributes.width - cumulatedWidth : null;
const unitOfFlexGrowSpace = remainingSpace != null ? remainingSpace / flexGrowTotal : null;
let usedRemainingSpace = 0;
const rendersYesFlexGrow = this.children.map((v) => {
if (!v.attributes.flexGrow) return null;
if (unitOfFlexGrowSpace != null && remainingSpace != null) {
const prevUsedRemSpace = usedRemainingSpace;
usedRemainingSpace += unitOfFlexGrowSpace;
return v.getDimensionsWrapper(inheritMe, {
...(attributes.heightAlign === 'stretch' ? { height: heightIfStretch } : {}),
width: Math.round(usedRemainingSpace) - Math.round(prevUsedRemSpace),
});
}
return v.getDimensionsWrapper(inheritMe);
});
const dimensions = rendersNoFlexGrow.map((v, i) => v != null ? v : rendersYesFlexGrow[i]) as { width: number; height: number; }[];
const { gap } = attributes;
const width = attributes.width
|| (typeof gap === 'number' ? gap : 0) * this.children.length + dimensions.reduce((p, v) => p + v.width, 0);
const height = attributes.heightAlign === 'stretch'
? heightIfStretch
: attributes.height || Math.max(...dimensions.map((v) => v.height));
return { width, height };
}
render(attributes: XJoinAttributes, inheritMe: Partial<XJoinAttributes>) {

@@ -25,3 +76,3 @@ const fillChar = new RichChar(attributes.fillChar, attributes).noSize();

const heightIfStretch = attributes.height || this.children.reduce((p, c) => {
const h = c.renderWrapper(inheritMe).height;
const h = c.getDimensionsWrapper(inheritMe).height;
if (h == null) return p;

@@ -28,0 +79,0 @@ return Math.max(p, h);

@@ -19,2 +19,53 @@ import { MinitelObject } from '../abstract/minitelobject.js';

}
getDimensions(attributes: YJoinAttributes, inheritMe: Partial<YJoinAttributes>): { width: number; height: number; } {
const widthIfStretch = attributes.width || this.children.reduce((p, c) => {
const w = c.getDimensionsWrapper(inheritMe).width;
if (w == null) return p;
return Math.max(p, w);
}, -Infinity);
let cumulatedHeight = 0;
const rendersNoFlexGrow = this.children.map((v) => {
if (v.attributes.flexGrow) return null;
const render = v.getDimensionsWrapper(inheritMe, {
...(attributes.widthAlign === 'stretch' ? { width: widthIfStretch } : {}),
});
cumulatedHeight += render.height;
return render;
});
const flexGrowTotal = this.children.reduce((p, c) => p + +(c.attributes.flexGrow || 0), 0);
const remainingSpace = attributes.height != null ? attributes.height - cumulatedHeight : null;
const unitOfFlexGrowSpace = remainingSpace != null ? remainingSpace / flexGrowTotal : null;
let usedRemainingSpace = 0;
const rendersYesFlexGrow = this.children.map((v) => {
if (!v.attributes.flexGrow) return null;
if (unitOfFlexGrowSpace != null && remainingSpace != null) {
const prevUsedRemSpace = usedRemainingSpace;
usedRemainingSpace += unitOfFlexGrowSpace;
return v.getDimensionsWrapper(inheritMe, {
...(attributes.widthAlign === 'stretch' ? { width: widthIfStretch } : {}),
height: Math.round(usedRemainingSpace) - Math.round(prevUsedRemSpace),
});
}
return v.getDimensionsWrapper(inheritMe);
});
const dimensions = rendersNoFlexGrow.map((v, i) => v != null ? v : rendersYesFlexGrow[i]) as { width: number; height: number; }[];
const { gap } = attributes;
const height = attributes.height
|| (typeof gap === 'number' ? gap : 0) * this.children.length + dimensions.reduce((p, v) => p + v.height, 0);
const width = attributes.widthAlign === 'stretch'
? widthIfStretch
: attributes.width || Math.max(...dimensions.map((v) => v.width));
return { width, height };
}
render(attributes: YJoinAttributes, inheritMe: Partial<YJoinAttributes>) {

@@ -24,3 +75,3 @@ const fillChar = new RichChar(attributes.fillChar, attributes).noSize();

const widthIfStretch = attributes.width || this.children.reduce((p, c) => {
const w = c.renderWrapper(inheritMe).width;
const w = c.getDimensionsWrapper(inheritMe).width;
if (w == null) return p;

@@ -27,0 +78,0 @@ return Math.max(p, w);

@@ -19,2 +19,14 @@ import { MinitelObject } from '../abstract/minitelobject.js';

}
getDimensions(attributes: ZJoinAttributes, inheritMe: Partial<ZJoinAttributes>): { width: number; height: number; } {
const dimensions = this.children.map((v) => v.getDimensionsWrapper(inheritMe, {
width: attributes.width,
height: attributes.height,
...(attributes.inheritTransparency ? { fillChar: '\x09' } : {}),
}));
const width = Math.max(...dimensions.map((v) => v.width));
const height = Math.max(...dimensions.map((v) => v.height));
return { width, height };
}
render(attributes: ZJoinAttributes, inheritMe: Partial<ZJoinAttributes>) {

@@ -21,0 +33,0 @@ const fillChar = new RichChar(attributes.fillChar, attributes).noSize();

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc