repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
openbio
github_2023
vanxh
typescript
QrCode.constructor
public constructor( // The version number of this QR Code, which is between 1 and 40 (inclusive). // This determines the size of this barcode. public readonly version: int, // The error correction level used in this QR Code. public readonly errorCorrectionLevel: QrCode.Ecc, dataCod...
// A mid-level API is the encodeSegments() function.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L180-L232
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrCode.getModule
public getModule(x: int, y: int): boolean { return ( 0 <= x && x < this.size && 0 <= y && y < this.size && this.modules[y][x] ); }
// If the given coordinates are out of bounds, then false (light) is returned.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L239-L243
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrCode.getModules
public getModules() { return this.modules; }
// Modified to expose modules for easy access
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L246-L248
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrCode.drawFunctionPatterns
private drawFunctionPatterns(): void { // Draw horizontal and vertical timing patterns for (let i = 0; i < this.size; i++) { this.setFunctionModule(6, i, i % 2 == 0); this.setFunctionModule(i, 6, i % 2 == 0); } // Draw 3 finder patterns (all corners except bottom right; overwrit...
// Reads this object's version field, and draws and marks all function modules.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L253-L285
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrCode.drawFormatBits
private drawFormatBits(mask: int): void { // Calculate error correction code and pack bits const data: int = (this.errorCorrectionLevel.formatBits << 3) | mask; // errCorrLvl is uint2, mask is uint3 let rem: int = data; for (let i = 0; i < 10; i++) rem = (rem << 1) ^ ((rem >>> 9) * 0x537); ...
// based on the given mask and this object's error correction level field.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L289-L312
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrCode.drawVersion
private drawVersion(): void { if (this.version < 7) return; // Calculate error correction code and pack bits let rem: int = this.version; // version is uint6, in the range [7, 40] for (let i = 0; i < 12; i++) rem = (rem << 1) ^ ((rem >>> 11) * 0x1f25); const bits: int = (this.version << 1...
// based on this object's version field, iff 7 <= version <= 40.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L316-L333
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrCode.drawFinderPattern
private drawFinderPattern(x: int, y: int): void { for (let dy = -4; dy <= 4; dy++) { for (let dx = -4; dx <= 4; dx++) { const dist: int = Math.max(Math.abs(dx), Math.abs(dy)); // Chebyshev/infinity norm const xx: int = x + dx; const yy: int = y + dy; if (0 <= xx && ...
// with the center module at (x, y). Modules can be out of bounds.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L337-L347
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrCode.drawAlignmentPattern
private drawAlignmentPattern(x: int, y: int): void { for (let dy = -2; dy <= 2; dy++) { for (let dx = -2; dx <= 2; dx++) this.setFunctionModule( x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) != 1, ); } }
// at (x, y). All modules must be in bounds.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L351-L360
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrCode.setFunctionModule
private setFunctionModule(x: int, y: int, isDark: boolean): void { this.modules[y][x] = isDark; this.isFunction[y][x] = true; }
// Only used by the constructor. Coordinates must be in bounds.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L364-L367
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrCode.addEccAndInterleave
private addEccAndInterleave(data: Readonly<Array<byte>>): Array<byte> { const ver: int = this.version; const ecl: QrCode.Ecc = this.errorCorrectionLevel; if (data.length != QrCode.getNumDataCodewords(ver, ecl)) throw new RangeError("Invalid argument"); // Calculate parameter numbers ...
// codewords appended to it, based on this object's version and error correction level.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L373-L414
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrCode.drawCodewords
private drawCodewords(data: Readonly<Array<byte>>): void { if ( data.length != Math.floor(QrCode.getNumRawDataModules(this.version) / 8) ) throw new RangeError("Invalid argument"); let i: int = 0; // Bit index into the data // Do the funny zigzag scan for (let right = this....
// data area of this QR Code. Function modules need to be marked off before this is called.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L418-L444
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrCode.applyMask
private applyMask(mask: int): void { if (mask < 0 || mask > 7) throw new RangeError("Mask value out of range"); for (let y = 0; y < this.size; y++) { for (let x = 0; x < this.size; x++) { let invert: boolean; switch (mask) { case 0: invert = (x + y) % 2 ...
// QR Code needs exactly one (not zero, two, etc.) mask applied.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L451-L488
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrCode.getPenaltyScore
private getPenaltyScore(): int { let result: int = 0; // Adjacent modules in row having same color, and finder-like patterns for (let y = 0; y < this.size; y++) { let runColor = false; let runX = 0; const runHistory = [0, 0, 0, 0, 0, 0, 0]; for (let x = 0; x < this.siz...
// This is used by the automatic mask choice algorithm to find the mask pattern that yields the lowest score.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L492-L566
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrCode.getAlignmentPatternPositions
private getAlignmentPatternPositions(): Array<int> { if (this.version == 1) return []; else { const numAlign: int = Math.floor(this.version / 7) + 2; const step: int = this.version == 32 ? 26 : Math.ceil((this.version * 4 + 4) / (numAlign * 2 - 2)) * 2; ...
// This could be implemented as lookup table of 40 variable-length lists of integers.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L573-L586
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrCode.getNumRawDataModules
private static getNumRawDataModules(ver: int): int { if (ver < QrCode.MIN_VERSION || ver > QrCode.MAX_VERSION) throw new RangeError("Version number out of range"); let result: int = (16 * ver + 128) * ver + 64; if (ver >= 2) { const numAlign: int = Math.floor(ver / 7) + 2; resu...
// The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L591-L602
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrCode.getNumDataCodewords
private static getNumDataCodewords(ver: int, ecl: QrCode.Ecc): int { return ( Math.floor(QrCode.getNumRawDataModules(ver) / 8) - QrCode.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver] * QrCode.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver] ); }
// This stateless pure function could be implemented as a (40*4)-cell lookup table.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L607-L613
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrCode.reedSolomonComputeDivisor
private static reedSolomonComputeDivisor(degree: int): Array<byte> { if (degree < 1 || degree > 255) throw new RangeError("Degree out of range"); // Polynomial coefficients are stored from highest to lowest power, excluding the leading term which is always 1. // For example the polynomial x^3 ...
// implemented as a lookup table over all possible parameter values, instead of as an algorithm.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L617-L639
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrCode.reedSolomonComputeRemainder
private static reedSolomonComputeRemainder( data: Readonly<Array<byte>>, divisor: Readonly<Array<byte>>, ): Array<byte> { const result: Array<byte> = divisor.map((_) => 0); for (const b of data) { // Polynomial division const factor: byte = b ^ result.shift()!; result...
// Returns the Reed-Solomon error correction codeword for the given data and divisor polynomials.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L642-L656
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrCode.reedSolomonMultiply
private static reedSolomonMultiply(x: byte, y: byte): byte { if (x >>> 8 != 0 || y >>> 8 != 0) throw new RangeError("Byte out of range"); // Russian peasant multiplication let z: int = 0; for (let i = 7; i >= 0; i--) { z = (z << 1) ^ ((z >>> 7) * 0x11d); z ^= ((y >>> i) &...
// are unsigned 8-bit integers. This could be implemented as a lookup table of 256*256 entries of uint8.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L660-L671
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrCode.finderPenaltyCountPatterns
private finderPenaltyCountPatterns(runHistory: Readonly<Array<int>>): int { const n: int = runHistory[1]; assert(n <= this.size * 3); const core: boolean = n > 0 && runHistory[2] == n && runHistory[3] == n * 3 && runHistory[4] == n && runHistory[5] == n; r...
// returns either 0, 1, or 2. A helper function for getPenaltyScore().
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L675-L688
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrCode.finderPenaltyTerminateAndCount
private finderPenaltyTerminateAndCount( currentRunColor: boolean, currentRunLength: int, runHistory: Array<int>, ): int { if (currentRunColor) { // Terminate dark run this.finderPenaltyAddHistory(currentRunLength, runHistory); currentRunLength = 0; } curre...
// Must be called at the end of a line (row or column) of modules. A helper function for getPenaltyScore().
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L691-L704
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrCode.finderPenaltyAddHistory
private finderPenaltyAddHistory( currentRunLength: int, runHistory: Array<int>, ): void { if (runHistory[0] == 0) currentRunLength += this.size; // Add light border to initial run runHistory.pop(); runHistory.unshift(currentRunLength); }
// Pushes the given value to the front and drops the last value. A helper function for getPenaltyScore().
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L707-L714
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
appendBits
function appendBits(val: int, len: int, bb: Array<bit>): void { if (len < 0 || len > 31 || val >>> len != 0) throw new RangeError("Value out of range"); for ( let i = len - 1; i >= 0; i-- // Append bit by bit ) bb.push((val >>> i) & 1); }
// Appends the given number of low-order bits of the given value
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L781-L790
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
getBit
function getBit(x: int, i: int): boolean { return ((x >>> i) & 1) != 0; }
// Returns true iff the i'th bit of x is set to 1.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L793-L795
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
assert
function assert(cond: boolean): void { if (!cond) throw new Error("Assertion error"); }
// Throws an exception if the given condition is false.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L798-L800
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrSegment.makeBytes
public static makeBytes(data: Readonly<Array<byte>>): QrSegment { const bb: Array<bit> = []; for (const b of data) appendBits(b, 8, bb); return new QrSegment(QrSegment.Mode.BYTE, data.length, bb); }
// can be converted to UTF-8 bytes and encoded as a byte mode segment.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L821-L825
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrSegment.makeNumeric
public static makeNumeric(digits: string): QrSegment { if (!QrSegment.isNumeric(digits)) throw new RangeError("String contains non-numeric characters"); const bb: Array<bit> = []; for (let i = 0; i < digits.length; ) { // Consume up to 3 digits per iteration const n: int = Math...
// Returns a segment representing the given string of decimal digits encoded in numeric mode.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L828-L839
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrSegment.makeAlphanumeric
public static makeAlphanumeric(text: string): QrSegment { if (!QrSegment.isAlphanumeric(text)) throw new RangeError( "String contains unencodable characters in alphanumeric mode", ); const bb: Array<bit> = []; let i: int; for (i = 0; i + 2 <= text.length; i += 2) { ...
// dollar, percent, asterisk, plus, hyphen, period, slash, colon.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L844-L866
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrSegment.makeSegments
public static makeSegments(text: string): Array<QrSegment> { // Select the most efficient segment encoding automatically if (text == "") return []; else if (QrSegment.isNumeric(text)) return [QrSegment.makeNumeric(text)]; else if (QrSegment.isAlphanumeric(text)) return [QrSegment.makeAlp...
// The result may use various segment modes and switch modes to optimize the length of the bit stream.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L870-L877
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrSegment.makeEci
public static makeEci(assignVal: int): QrSegment { const bb: Array<bit> = []; if (assignVal < 0) throw new RangeError("ECI assignment value out of range"); else if (assignVal < 1 << 7) appendBits(assignVal, 8, bb); else if (assignVal < 1 << 14) { appendBits(0b10, 2, bb); ...
// (ECI) designator with the given assignment value.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L881-L894
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrSegment.isNumeric
public static isNumeric(text: string): boolean { return QrSegment.NUMERIC_REGEX.test(text); }
// A string is encodable iff each character is in the range 0 to 9.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L898-L900
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrSegment.isAlphanumeric
public static isAlphanumeric(text: string): boolean { return QrSegment.ALPHANUMERIC_REGEX.test(text); }
// (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L905-L907
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrSegment.constructor
public constructor( // The mode indicator of this segment. public readonly mode: QrSegment.Mode, // The length of this segment's unencoded data. Measured in characters for // numeric/alphanumeric/kanji mode, bytes for byte mode, and 0 for ECI mode. // Always zero or positive. Not the same...
// but the constraint isn't checked. The given bit buffer is cloned and stored.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L914-L928
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrSegment.getData
public getData(): Array<bit> { return this.bitData.slice(); // Make defensive copy }
// Returns a new copy of the data bits of this segment.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L933-L935
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrSegment.getTotalBits
public static getTotalBits( segs: Readonly<Array<QrSegment>>, version: int, ): number { let result = 0; for (const seg of segs) { const ccbits: int = seg.mode.numCharCountBits(version); if (seg.numChars >= 1 << ccbits) return Infinity; // The segment's length doesn't fit the ...
// the given version. The result is infinity if a segment has too many characters to fit its length field.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L939-L950
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
QrSegment.toUtf8ByteArray
private static toUtf8ByteArray(str: string): Array<byte> { str = encodeURI(str); const result: Array<byte> = []; for (let i = 0; i < str.length; i++) { if (str.charAt(i) != "%") result.push(str.charCodeAt(i)); else { result.push(parseInt(str.substr(i + 1, 2), 16)); ...
// Returns a new array of bytes representing the given string encoded in UTF-8.
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L953-L964
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
Ecc.constructor
private constructor( // In the range 0 to 3 (unsigned 2-bit integer). public readonly ordinal: int, // (Package-private) In the range 0 to 3 (unsigned 2-bit integer). public readonly formatBits: int, ) {}
/*-- Constructor and fields --*/
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L1000-L1005
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
Mode.constructor
private constructor( // The mode indicator bits, which is a uint4 value (range 0 to 15). public readonly modeBits: int, // Number of character count bits for three different version ranges. private readonly numBitsCharCount: [int, int, int], ) {}
/*-- Constructor and fields --*/
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L1028-L1033
242e7224198e706b35017f2f9852b2a1bbe69b7f
openbio
github_2023
vanxh
typescript
Mode.numCharCountBits
public numCharCountBits(ver: int): int { return this.numBitsCharCount[Math.floor((ver + 7) / 17)]; }
// this mode in a QR Code at the given version number. The result is in the range [0, 16].
https://github.com/vanxh/openbio/blob/242e7224198e706b35017f2f9852b2a1bbe69b7f/src/lib/qr/generator.tsx#L1039-L1041
242e7224198e706b35017f2f9852b2a1bbe69b7f
ComfyUIMini
github_2023
ImDarkTom
typescript
showResolutionSelector
function showResolutionSelector(nodeId: string) { document.body.classList.add('locked'); elements.resolutionSelector.classList.remove('hidden'); elements.resolutionSelector.dataset.nodeId = nodeId; elements.resolutionSelectorOverlay.classList.remove('hidden'); }
/** * * @param nodeId The id of the node to change the width and height of through the input. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/client/public/js/modules/resolutionSelector.ts#L52-L57
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
WorkflowEditor.constructor
constructor( containerElem: HTMLElement, workflowObject: WorkflowInstance | null, titleInput: HTMLInputElement, descriptionInput: HTMLTextAreaElement ) { this.containerElem = containerElem; this.titleInput = titleInput; this.descriptionInput = descriptionInput...
/** * * @param containerElem The container element in which all of the inputs will be renderered. * @param workflowObject The workflow object to render. * @param titleInput The title input element. * @param descriptionInput The description input element. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/client/public/js/modules/workflowEditor.ts#L20-L34
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
WorkflowEditor.renderWorkflow
public async renderWorkflow() { this.ensureWorkflowObject(); this.inputCount = 0; const blankMetadata: WorkflowMetadata = { title: 'My Workflow', description: '', format_version: '2', input_options: [], }; const jsonMetadata = thi...
/** * Renders the workflow inputs. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/client/public/js/modules/workflowEditor.ts#L39-L60
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
WorkflowEditor.updateJsonWithUserInput
public updateJsonWithUserInput(): WorkflowWithMetadata { this.ensureWorkflowObject(); const inputOptionsList = []; const modifiedWorkflow = this.workflowObject.workflow; const allInputs = this.containerElem.querySelectorAll('.input-item'); for (const inputContainer of allInput...
/** * Updates a workflow object with data from the inputs. * * @returns The exported workflow object. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/client/public/js/modules/workflowEditor.ts#L67-L125
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
WorkflowEditor.ensureWorkflowObject
private ensureWorkflowObject(): asserts this is { workflowObject: WorkflowWithMetadata } { if (this.workflowObject === null) { throw new Error('Workflow object is null'); } }
/** * Asserts that the workflow object is not null. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/client/public/js/modules/workflowEditor.ts#L130-L134
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
WorkflowEditor.renderAllInputs
private async renderAllInputs() { this.ensureWorkflowObject(); // TODO: Replace with function that gets all inputs not just ones in metadata const allUserInputOptions = this.workflowObject.getInputOptionsList(); for (const userInputOptions of allUserInputOptions) { const co...
/** * Loops through every node and renders each input. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/client/public/js/modules/workflowEditor.ts#L139-L163
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
WorkflowEditor.getComfyMetadataForInputType
private async getComfyMetadataForInputType( inputType: string, nodeId: string ): Promise<NormalisedComfyInputInfo | null> { this.ensureWorkflowObject(); if (!this.comfyInputsInfo) { const comfyObjectMetadata = await fetch('/comfyui/inputsinfo'); const comfyOb...
/** * Gets the `/objectinfo` metadata for a given input id and node id. * * @param inputType The type of node input. e.g. `seed`, `scheduler`, `ckpt_name`. * @param nodeId The ID of the node in the workflow. * @returns The metadata for the input type or null if not found. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/client/public/js/modules/workflowEditor.ts#L172-L200
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
WorkflowEditor.renderInput
private async renderInput( userInputOptions: InputOption, comfyInputTypeMetadata: NormalisedComfyInputInfo, defaultValue: string, nodeClass: string ) { this.inputCount += 1; const nodeId = userInputOptions.node_id; const inputNameInNode = userInputOptions.inp...
/** * Renders an input based off of input options. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/client/public/js/modules/workflowEditor.ts#L205-L252
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
WorkflowEditor.renderDefaultValueInput
private static renderDefaultValueInput( inputConfig: NormalisedComfyInputInfo, idPrefix: string, defaultValue: string ): string { const inputDefault = defaultValue ?? inputConfig.default ?? ''; let inputHTML = `<label for="${idPrefix}-default">Default</label>`; swit...
/** * Renders a default value input for a input, differs based on input type. * * @param inputConfig The config for the input. * @param idPrefix The id prefix for each element in the input. * @param defaultValue The default value for the input from the workflow object. * @returns The rende...
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/client/public/js/modules/workflowEditor.ts#L262-L295
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
WorkflowEditor.startInputEventListeners
private startInputEventListeners() { this.containerElem.addEventListener('click', (e: MouseEvent) => { const target = e.target; if (!target || !(target instanceof HTMLElement)) { return; } const targetHasClass = (className: string) => target.clas...
/** * Adds event listeners to the input container which allow for interaction. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/client/public/js/modules/workflowEditor.ts#L300-L318
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
WorkflowEditor.moveUp
private static moveUp(item: HTMLElement | null) { if (!item) { return; } if (!item.parentNode) { return; } const previousItem = item.previousElementSibling; if (previousItem) { item.parentNode.insertBefore(item, previousItem); ...
/** * Move an input up. * * @param item The input container. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/client/public/js/modules/workflowEditor.ts#L325-L339
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
WorkflowEditor.moveDown
private static moveDown(item: HTMLElement | null) { if (!item) { return; } if (!item.parentNode) { return; } const nextItem = item.nextElementSibling; if (nextItem) { item.parentNode.insertBefore(nextItem, item); } }
/** * Move an input down. * * @param item The input container. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/client/public/js/modules/workflowEditor.ts#L346-L360
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
WorkflowEditor.hideInput
private static hideInput(hideButtonElement: HTMLElement) { if (hideButtonElement.classList.contains('hide')) { hideButtonElement.classList.add('eye'); hideButtonElement.classList.remove('hide'); const inputOptionsContainer = hideButtonElement.closest('.input-item'); ...
/** * Hides an input after the eye icon is clicked. * * @param hideButtonElement The hide button element. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/client/public/js/modules/workflowEditor.ts#L367-L401
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
getElementOrThrow
function getElementOrThrow(selector: string): HTMLElement { const element = document.querySelector(selector) as HTMLElement; if (!element) { throw new Error(`Element not found: ${selector}`); } return element; }
/** * * @param {string} selector The CSS selector of the element to get. * @returns {HTMLElement} The element found by the selector. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/client/public/js/pages/import.ts#L11-L19
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
fetchLocalWorkflow
function fetchLocalWorkflow(): WorkflowWithMetadata { const localWorkflow = getLocalWorkflow(workflowIdentifier); if (!localWorkflow) { const errorMessage = `Workflow '${workflowIdentifier}' not found.`; openPopupWindow(errorMessage, PopupWindowType.ERROR); throw new Error(errorMessage)...
/** * Fetches the current local workflow from localStorage. * If the workflow is not found, an error is thrown. * * @returns The workflow object */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/client/public/js/pages/workflow.ts#L85-L95
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
startEventListeners
function startEventListeners() { elements.runButton.addEventListener('click', runWorkflow); elements.cancelRunButton.addEventListener('click', cancelRun); elements.inputsContainer.addEventListener('click', handleInputContainerClick); elements.allFileInputs.forEach((element) => fileUploadEventListener(...
/** * Starts the event listeners for the various elements on the page. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/client/public/js/pages/workflow.ts#L100-L114
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
collapseElement
function collapseElement(element: HTMLElement) { element.style.height = `${element.scrollHeight}px`; element.classList.add('collapsing'); requestAnimationFrame(() => { element.style.height = '0'; }); element.addEventListener('transitionend', function handler() { element.classList....
/** * Collapses an element, element has to have a style for the hidden class variant. * @param element The element to collapse. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/client/public/js/pages/workflow.ts#L154-L169
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
imageSelectEventListener
function imageSelectEventListener(selectElement: HTMLSelectElement) { selectElement.addEventListener('change', (e: Event) => { const target = e.target as HTMLSelectElement; const selectedOption = target.options[target.selectedIndex]; const selectedValue = selectedOption.value; if (...
/** * Handles updating the preview for a image select element. * * @param selectElement The select element to listen to. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/client/public/js/pages/workflow.ts#L197-L217
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
fileUploadEventListener
function fileUploadEventListener(inputElement: HTMLElement) { inputElement.addEventListener('change', async (e) => { const target = e.target; if (!target || !(target instanceof HTMLInputElement)) { return; } if (!target.files) { return; } if...
/** * Handles uploading an image file to the server for image select inputs. * * @param inputElement The file input element to listen to. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/client/public/js/pages/workflow.ts#L224-L274
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
addOptionToSelect
function addOptionToSelect(selectElem: HTMLSelectElement, option: string) { const optionElem = document.createElement('option'); optionElem.value = option; optionElem.textContent = option; selectElem.appendChild(optionElem); }
/** * Adds a new select option to a select element. * Used to add new images to existing selects when a new image is uploaded for image inputs. * * @param selectElem The select to add the option to. * @param option The option to add. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/client/public/js/pages/workflow.ts#L283-L289
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
handleInputContainerClick
function handleInputContainerClick(event: MouseEvent) { const target = event.target as HTMLElement; if (target.classList.contains('randomise-input-toggle')) { toggleRandomiseInput(target); } else if (target.classList.contains('randomise-now-button')) { const parentNode = target.parentNode; ...
/** * Handles clicks on elements inside the input container. * * @param event The click mouse event. * @returns Nothing. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/client/public/js/pages/workflow.ts#L297-L319
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
toggleRandomiseInput
function toggleRandomiseInput(toggleElement: HTMLElement) { const toggleElemContainer = toggleElement.parentNode as HTMLElement; const randomiseOff = toggleElemContainer.classList.contains('randomise-off'); if (randomiseOff) { toggleElemContainer.classList.remove('randomise-off'); } else { ...
/** * Toggles on/off the randomisation of an input on workflow run. * * @param toggleElement The toggle element that was clicked. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/client/public/js/pages/workflow.ts#L326-L336
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
randomiseInput
function randomiseInput(inputId: string) { const input = document.getElementById(inputId); if (!input) { console.error('Input not found'); return; } const min = input.getAttribute('min'); const max = input.getAttribute('max'); const step = input.getAttribute('step') || '1'; ...
/** * Randomises an input field. * * @param inputId The input to randomise. * @returns Nothing. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/client/public/js/pages/workflow.ts#L344-L364
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
generateRandomNum
function generateRandomNum(min: number, max: number, step: number): number { const range = (max - min) / step; return Math.min(min + step * Math.floor(Math.random() * range), max); }
/** * Generates a random number between min and max with a step. * * @param min The minimum value. * @param max The maximum value. * @param step The step size i.e. the difference between each number. * @returns The random number generated. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/client/public/js/pages/workflow.ts#L374-L377
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
generateSeed
function generateSeed() { return Math.floor(Math.random() * 1e16) .toString() .padStart(16, '0'); }
/** * Generates a random number seed. * * @returns A random seed. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/client/public/js/pages/workflow.ts#L384-L388
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
setProgressBar
function setProgressBar(type: 'total' | 'current', percentage: string) { const textElem = type === 'total' ? elements.progressBar.total.textElem : elements.progressBar.current.textElem; const barElem = type === 'total' ? elements.progressBar.total.innerElem : elements.progressBar.current.innerElem; textEle...
/** * Updates a progress bar with a new percentage. * Percentage should include the % symbol. * * @param type Which progress bar to change. * @param percentage What percentage to set the progress bar to. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/client/public/js/pages/workflow.ts#L397-L403
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
handleWebSocketMessage
function handleWebSocketMessage(event: MessageEvent<any>) { const message = JSON.parse(event.data); switch (message.type) { case 'progress': updateProgressBars(message.data); break; case 'preview': updateImagePreview(message.data); break; ...
// TODO: Setup type for message for both client and server
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/client/public/js/pages/workflow.ts#L464-L494
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
getGalleryPageData
function getGalleryPageData(page = 0, subfolder = '', itemsPerPage = 20) { const imageOutputPath = config.get('output_dir'); if (!imageOutputPath || !(typeof imageOutputPath === 'string')) { return { error: 'Output directory not set properly in config.', scanned: { subfolders: [...
/** * @typedef {object} GalleryImageData * @property {string} path - The ComfyUIMini url path for the image file. * @property {number} time - Latest file modification time in ms since Unix epoch. * @property {string} timeText - Human-readable relative time since last image mofification, e.g. '2 hour(s) ago'. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/server/utils/galleryUtils.ts#L68-L143
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
logOptional
function logOptional(type: string, message: string) { const optionalLogConfigs: OptionalLogConfig | undefined = config.get('optional_log'); if (!optionalLogConfigs || optionalLogConfigs[type] === undefined) { return; } if (optionalLogConfigs[type]) { logger.optional(message); } }
/** * Logs an optional message depending on if the `type` is set to true in the config. * * @param type Type of optional log from config. * @param message Text to log. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/server/utils/logger.ts#L56-L66
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
getNormalisedInfo
function getNormalisedInfo(inputInfo: any): NormalisedComfyInputInfo { const normalisedInfo: Partial<NormalisedComfyInputInfo> = { userAccessible: false, }; if (Array.isArray(inputInfo[0])) { normalisedInfo.userAccessible = true; normalisedInfo.type = 'ARRAY'; normalisedInfo...
/** * ComfyUI uses weirdly different formats for each input type, * e.g. For most inputs, `inputInfo[0]` is a string containing the input type, for arrays, its the list of options. * * However, arrays may also *sometimes* have a second element with other options such as `tooltip`, `default`, or `image_upload` * th...
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/server/utils/objectInfoUtils.ts#L48-L83
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
checkForWorkflowsFolder
function checkForWorkflowsFolder() { if (!fs.existsSync(paths.workflows)) { logger.warn(`Server workflows folder path from config not found, attempting to create...`); try { fs.mkdirSync(paths.workflows); logger.success(`Server workflows folder created at '${paths.workflows}...
/** * Checks if the server workflows folder path exists, if not, tries to creates it. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/server/utils/workflowUtils.ts#L31-L46
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
getWorkflowFolderJsonFiles
function getWorkflowFolderJsonFiles(): string[] { const filesList = fs.readdirSync(paths.workflows); const jsonFilesList = filesList.filter((file) => path.extname(file).toLowerCase() === '.json'); return jsonFilesList; }
/** * Reads the server workflows folder for JSON files. * * @returns {string[]} An array of JSON filenames in the workflows folder. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/server/utils/workflowUtils.ts#L53-L58
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
checkIfObjectIsValidWorkflow
function checkIfObjectIsValidWorkflow(workflowJson: { [key: string]: any }): boolean { if (typeof workflowJson !== 'object') { return false; } for (const key of Object.keys(workflowJson)) { const node = workflowJson[key]; if (node && typeof node === 'object' && 'inputs' in node && ...
/** * Checks if a JSON workflow object is a valid ComfyUI workflow. * * @param {object} workflowJson The workflow object. * @returns {boolean} True if workflow is a valid ComfyUI workflow, otherwise false. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/server/utils/workflowUtils.ts#L66-L80
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
getServerWorkflowMetadata
function getServerWorkflowMetadata(jsonFileList: string[]): ServerWorkflowMetadataList { const accumulatedWorkflowMetadata: ServerWorkflowMetadataList = {}; for (const jsonFilename of jsonFileList) { const jsonFileContents = fs.readFileSync(path.join(paths.workflows, jsonFilename), 'utf8'); con...
/** * Attempts to get text metadata for all workflows in the server workflows folder. * * @param {string[]} jsonFileList List of JSON files in the workflows folder. * @returns {ServerWorkflowMetadataList} An object containing the metadata for each workflow. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/server/utils/workflowUtils.ts#L88-L128
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
generateWorkflowMetadataAndSaveToFile
function generateWorkflowMetadataAndSaveToFile(workflowObjectWithoutMetadata: Workflow, workflowFilename: string) { if (config.get('auto_convert_comfyui_workflows') === false) { return; } const validateErrorMessage = WorkflowInstance.validateWorkflowObject(workflowObjectWithoutMetadata, true); ...
/** * Auto-generates metadata for a workflow object and saves it to a new file with a [CONVERTED] prefix while keeping a backup of the original file. * * @param {Workflow} workflowObjectWithoutMetadata The workflow object without metadata. * @param {string} workflowFilename The filename of the workflow in the workf...
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/server/utils/workflowUtils.ts#L136-L161
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
writeConvertedWorkflowToFile
function writeConvertedWorkflowToFile(workflowObject: object, originalWorkflowFilename: string) { fs.writeFileSync( path.join(paths.workflows, `[CONVERTED] ${originalWorkflowFilename}`), JSON.stringify(workflowObject, null, 2), 'utf8' ); fs.renameSync( path.join(paths.workfl...
/** * Saves a converted workflow to a new file with a [CONVERTED] prefix while keeping a backup of the original file. * * @param {object} workflowObject The new workflow object with metadata. * @param {string} originalWorkflowFilename The original filename of the workflow. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/server/utils/workflowUtils.ts#L169-L180
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
readServerWorkflow
function readServerWorkflow(filename: string): WorkflowWithMetadata | WorkflowFileReadError { try { const workflowFilePath = path.join(paths.workflows, filename); const fileContents = fs.readFileSync(workflowFilePath); const workflowObject = JSON.parse(fileContents.toString()); retu...
/** * * @param {string} filename The server workflow filename. * @returns {Record<string, object>|WorkflowFileReadError} The workflow object, or an object with an error type if there was an error. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/server/utils/workflowUtils.ts#L187-L210
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
writeServerWorkflow
function writeServerWorkflow(filename: string, workflowObject: object): boolean { try { fs.writeFileSync(path.join(paths.workflows, filename), JSON.stringify(workflowObject, null, 2), 'utf8'); return true; } catch (error) { console.error('Error when saving workflow to file:', error); ...
/** * Saves a workflow object into a file in the server workflows folder. * * @param {string} filename The filename to save the workflow to. * @param {object} workflowObject The workflow object to convert into a JSON and save. * @returns {boolean} Whether or not the workflow was successfully saved. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/server/utils/workflowUtils.ts#L219-L227
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
handleComfyWsMessage
function handleComfyWsMessage(clientWs: WebSocket, comfyWs: WebSocket, data: WebSocket.Data, isBinary: boolean) { if (!Buffer.isBuffer(data)) { logger.warn('Recieved non-buffer data from ComfyUI websocket:', data); return; } if (isBinary) { try { handleSendImageBuffer(cl...
/** * Handles recieving messages from ComfyUI WebSocket. * @param clientWs The WebSocket connection to the frontend client. * @param comfyWs The WebSocket connection to the ComfyUI instance. * @param data The data recieved from the ComfyUI WebSocket. * @param isBinary Whether the data is binary or not, i.e. if it ...
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/server/utils/comfyAPIUtils/generateImage/ws/onMessage.ts#L11-L30
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
formatVersion
function formatVersion(versionString: string): string { return versionString .replace('v', '') .replace(/-[a-z0-9]+$/, '') .replace(/-/g, '.'); }
/** * Converts a ComfyUI version string to a semver-compatible version string. * * E.g. `v0.2.2-84-gd1cdf51` becomes `0.2.2.84`. * * @param versionString The input version string. * @returns The semver-compatible version string. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/server/utils/comfyAPIUtils/startupCheck/formatVersion.ts#L9-L14
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
comfyUICheck
async function comfyUICheck() { let comfyUIVersion = null; let comfyUIVersionRequirement = false; const minComfyUIVersion: string = config.get('developer.min_comfyui_version'); if (!minComfyUIVersion) { logger.warn('No minimum ComfyUI version specified in config.'); return; } ...
/** * Check if ComfyUI is running and meets minimum required version. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/server/utils/comfyAPIUtils/startupCheck/index.ts#L10-L73
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
versionCheck
function versionCheck(version: string, versionRequirement: string): boolean { const versionSplit = version.split('.'); const versionRequirementSplit = versionRequirement.split('.'); for (const versionPart in versionSplit) { if (parseInt(versionSplit[versionPart]) > parseInt(versionRequirementSplit[...
/** * Compares `version` with `versionRequirement`. * * @param version The version string, e.g., `v0.2.2-84-gd1cdf51`. * @param versionRequirement The required version string, e.g., `0.2.2-49`. * @returns True if `version` is greater than or equal to `versionRequirement`. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/server/utils/comfyAPIUtils/startupCheck/versionCheck.ts#L8-L19
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
WorkflowInstance.getNode
public getNode(nodeId: string): WorkflowNode { return this.workflow[nodeId]; }
/** * Gets a node based off node ID. * * @param nodeId The id of the node to get. * @returns The workflow node. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/shared/classes/Workflow.ts#L52-L54
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
WorkflowInstance.getInputOptionsList
public getInputOptionsList(): InputOption[] { return this.workflow._comfyuimini_meta.input_options.map((inputOption) => ({ title: inputOption.title, node_id: inputOption.node_id, input_name_in_node: inputOption.input_name_in_node, disabled: inputOption.disabled ??...
/** * Gets the list of options for every input in the user metadata. * * @returns The list of options for each input in the workflow. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/shared/classes/Workflow.ts#L61-L68
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
WorkflowInstance.validateWorkflowObject
public static validateWorkflowObject(workflow: AnyWorkflow, returnErrorMessage: boolean = false): string | void { try { if (!workflow || typeof workflow !== 'object') { throw new Error('Invalid workflow: must be a non-null object'); } if (Object.keys(workflow...
/** * Checks if a workflow is valid. * * @param workflow The workflow to validate. * @param returnErrorMessage If true, returns a string with the error message instead of throwing an error. * @returns Error message string if `returnErrorMessage` is true, otherwise throws an error. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/shared/classes/Workflow.ts#L81-L105
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
WorkflowInstance.validateNode
private static validateNode(node: WorkflowNode, nodeId: string): void { if (nodeId.startsWith('_')) { return; } if (typeof node !== 'object') { throw new Error(`Invalid workflow: node '${nodeId}' is not an object`); } if (Object.keys(node).length === 0) ...
/** * Checks if a node is valid. * * @param node The node to validate. * @param nodeId The ID of the node. * @returns Throws an error if the node is invalid. Otherwise, returns nothing. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/shared/classes/Workflow.ts#L114-L142
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
WorkflowInstance.generateMetadataForWorkflow
public static generateMetadataForWorkflow(workflow: Workflow, filename?: string): WorkflowWithMetadata { const metadata: WorkflowMetadata = { title: filename ?? 'Unnamed Workflow', description: '', format_version: '2', input_options: [], }; for (c...
/** * Auto-generates metadata for a workflow object. * * @param workflow The workflow to generate metadata for. * @param filename The optional filename to use for the title of the workflow. * @returns The workflow with the generated metadata. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/shared/classes/Workflow.ts#L151-L185
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
WorkflowInstance.setWorkflowObject
private setWorkflowObject(workflow: AnyWorkflow): void { WorkflowInstance.validateWorkflowObject(workflow); if (WorkflowInstance.workflowHasMetadata(workflow)) { this.workflow = workflow; } else { this.workflow = WorkflowInstance.generateMetadataForWorkflow(workflow); ...
/** * Validates and sets the workflow object to be used throughout the class. * * @param workflow The workflow object to set as the new workflow. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/shared/classes/Workflow.ts#L196-L204
85707e2e3100a73fc8d191d513dd2c3a67a7e418
ComfyUIMini
github_2023
ImDarkTom
typescript
WorkflowInstance.workflowHasMetadata
private static workflowHasMetadata(workflow: AnyWorkflow): workflow is WorkflowWithMetadata { return (workflow as WorkflowWithMetadata)._comfyuimini_meta !== undefined; }
/** * Assert if a workflow has metadata. * * @param workflow The workflow to check metadata for. * @returns Assertion if the workflow has metadata, and is therefore an instance of WorkflowWithMetadata. */
https://github.com/ImDarkTom/ComfyUIMini/blob/85707e2e3100a73fc8d191d513dd2c3a67a7e418/src/shared/classes/Workflow.ts#L212-L214
85707e2e3100a73fc8d191d513dd2c3a67a7e418
eastworld
github_2023
mluogh
typescript
AgentDefinitionsService.createAgent
public static createAgent( gameUuid: string, agentName: string, ): CancelablePromise<AgentDef> { return __request(OpenAPI, { method: 'POST', url: '/game/{game_uuid}/agent/create', path: { 'game_uuid': gameUuid, }, qu...
/** * Create Agent Def * @param gameUuid * @param agentName * @returns AgentDef Successful Response * @throws ApiError */
https://github.com/mluogh/eastworld/blob/70afa3c1983954fa8bd46edd09e391e51cec4bc2/app/src/client/services/AgentDefinitionsService.ts#L20-L37
70afa3c1983954fa8bd46edd09e391e51cec4bc2
eastworld
github_2023
mluogh
typescript
AgentDefinitionsService.listAgents
public static listAgents( gameUuid: string, ): CancelablePromise<Array<AgentDef>> { return __request(OpenAPI, { method: 'GET', url: '/game/{game_uuid}/agent/list', path: { 'game_uuid': gameUuid, }, errors: { ...
/** * Get Games List * @param gameUuid * @returns AgentDef Successful Response * @throws ApiError */
https://github.com/mluogh/eastworld/blob/70afa3c1983954fa8bd46edd09e391e51cec4bc2/app/src/client/services/AgentDefinitionsService.ts#L45-L58
70afa3c1983954fa8bd46edd09e391e51cec4bc2
eastworld
github_2023
mluogh
typescript
AgentDefinitionsService.getAgent
public static getAgent( gameUuid: string, agentUuid: string, ): CancelablePromise<AgentDef> { return __request(OpenAPI, { method: 'GET', url: '/game/{game_uuid}/agent/{agent_uuid}', path: { 'game_uuid': gameUuid, 'agent_uuid...
/** * Get Agent Def * @param gameUuid * @param agentUuid * @returns AgentDef Successful Response * @throws ApiError */
https://github.com/mluogh/eastworld/blob/70afa3c1983954fa8bd46edd09e391e51cec4bc2/app/src/client/services/AgentDefinitionsService.ts#L67-L82
70afa3c1983954fa8bd46edd09e391e51cec4bc2
eastworld
github_2023
mluogh
typescript
AgentDefinitionsService.updateAgent
public static updateAgent( gameUuid: string, agentUuid: string, requestBody: AgentDef, ): CancelablePromise<AgentDef> { return __request(OpenAPI, { method: 'PUT', url: '/game/{game_uuid}/agent/{agent_uuid}', path: { 'game_uuid': gam...
/** * Update Agent Def * @param gameUuid * @param agentUuid * @param requestBody * @returns AgentDef Successful Response * @throws ApiError */
https://github.com/mluogh/eastworld/blob/70afa3c1983954fa8bd46edd09e391e51cec4bc2/app/src/client/services/AgentDefinitionsService.ts#L92-L110
70afa3c1983954fa8bd46edd09e391e51cec4bc2
eastworld
github_2023
mluogh
typescript
AgentDefinitionsService.deleteAgent
public static deleteAgent( gameUuid: string, agentUuid: string, ): CancelablePromise<any> { return __request(OpenAPI, { method: 'DELETE', url: '/game/{game_uuid}/agent/{agent_uuid}', path: { 'game_uuid': gameUuid, 'agent_uui...
/** * Delete Agent Def * @param gameUuid * @param agentUuid * @returns any Successful Response * @throws ApiError */
https://github.com/mluogh/eastworld/blob/70afa3c1983954fa8bd46edd09e391e51cec4bc2/app/src/client/services/AgentDefinitionsService.ts#L119-L134
70afa3c1983954fa8bd46edd09e391e51cec4bc2
eastworld
github_2023
mluogh
typescript
GameDefinitionsService.createGame
public static createGame( gameName: string, ): CancelablePromise<GameDef> { return __request(OpenAPI, { method: 'POST', url: '/game/create', query: { 'game_name': gameName, }, errors: { 422: `Validation Error...
/** * Create Game Def * @param gameName * @returns GameDef Successful Response * @throws ApiError */
https://github.com/mluogh/eastworld/blob/70afa3c1983954fa8bd46edd09e391e51cec4bc2/app/src/client/services/GameDefinitionsService.ts#L21-L34
70afa3c1983954fa8bd46edd09e391e51cec4bc2
eastworld
github_2023
mluogh
typescript
GameDefinitionsService.listGames
public static listGames(): CancelablePromise<Array<GameDefSummary>> { return __request(OpenAPI, { method: 'GET', url: '/game/list', }); }
/** * Get Games List * @returns GameDefSummary Successful Response * @throws ApiError */
https://github.com/mluogh/eastworld/blob/70afa3c1983954fa8bd46edd09e391e51cec4bc2/app/src/client/services/GameDefinitionsService.ts#L41-L46
70afa3c1983954fa8bd46edd09e391e51cec4bc2
eastworld
github_2023
mluogh
typescript
GameDefinitionsService.getGame
public static getGame( uuid: string, ): CancelablePromise<GameDef> { return __request(OpenAPI, { method: 'GET', url: '/game/{uuid}', path: { 'uuid': uuid, }, errors: { 422: `Validation Error`, }, ...
/** * Get Game Def * @param uuid * @returns GameDef Successful Response * @throws ApiError */
https://github.com/mluogh/eastworld/blob/70afa3c1983954fa8bd46edd09e391e51cec4bc2/app/src/client/services/GameDefinitionsService.ts#L54-L67
70afa3c1983954fa8bd46edd09e391e51cec4bc2
eastworld
github_2023
mluogh
typescript
GameDefinitionsService.deleteGame
public static deleteGame( uuid: string, ): CancelablePromise<any> { return __request(OpenAPI, { method: 'DELETE', url: '/game/{uuid}', path: { 'uuid': uuid, }, errors: { 422: `Validation Error`, }...
/** * Delete Game Def * @param uuid * @returns any Successful Response * @throws ApiError */
https://github.com/mluogh/eastworld/blob/70afa3c1983954fa8bd46edd09e391e51cec4bc2/app/src/client/services/GameDefinitionsService.ts#L75-L88
70afa3c1983954fa8bd46edd09e391e51cec4bc2
eastworld
github_2023
mluogh
typescript
GameDefinitionsService.getLore
public static getLore( uuid: string, ): CancelablePromise<Array<Lore>> { return __request(OpenAPI, { method: 'GET', url: '/game/{uuid}/lore', path: { 'uuid': uuid, }, errors: { 422: `Validation Error`, ...
/** * Get Game Lore * @param uuid * @returns Lore Successful Response * @throws ApiError */
https://github.com/mluogh/eastworld/blob/70afa3c1983954fa8bd46edd09e391e51cec4bc2/app/src/client/services/GameDefinitionsService.ts#L96-L109
70afa3c1983954fa8bd46edd09e391e51cec4bc2
eastworld
github_2023
mluogh
typescript
GameDefinitionsService.getGameJson
public static getGameJson( uuid: string, ): CancelablePromise<any> { return __request(OpenAPI, { method: 'GET', url: '/game/{uuid}/json', path: { 'uuid': uuid, }, errors: { 422: `Validation Error`, ...
/** * Get Game Def Json * @param uuid * @returns any Successful Response * @throws ApiError */
https://github.com/mluogh/eastworld/blob/70afa3c1983954fa8bd46edd09e391e51cec4bc2/app/src/client/services/GameDefinitionsService.ts#L117-L130
70afa3c1983954fa8bd46edd09e391e51cec4bc2
eastworld
github_2023
mluogh
typescript
GameDefinitionsService.createGameJson
public static createGameJson( jsonedGame: string, ): CancelablePromise<any> { return __request(OpenAPI, { method: 'PUT', url: '/game/json', query: { 'jsoned_game': jsonedGame, }, errors: { 422: `Validation Er...
/** * Update Game Def Json * @param jsonedGame * @returns any Successful Response * @throws ApiError */
https://github.com/mluogh/eastworld/blob/70afa3c1983954fa8bd46edd09e391e51cec4bc2/app/src/client/services/GameDefinitionsService.ts#L138-L151
70afa3c1983954fa8bd46edd09e391e51cec4bc2