@opentui/core 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/3d.js CHANGED
@@ -19581,16 +19581,6 @@ function parseColor(color) {
19581
19581
  }
19582
19582
  return color;
19583
19583
  }
19584
- async function loadTemplate(filePath, params) {
19585
- const template = await Bun.file(filePath).text();
19586
- return template.replace(/\${(\w+)}/g, (match, key) => params[key] || match);
19587
- }
19588
- function fixPaths(paths) {
19589
- if (process.env.BUN_PACKER_BUNDLE) {
19590
- return Object.fromEntries(Object.entries(paths).map(([key, value]) => [key, value.replace("../", "")]));
19591
- }
19592
- return paths;
19593
- }
19594
19584
 
19595
19585
  // src/types.ts
19596
19586
  class RGBA {
@@ -31407,16 +31397,211 @@ var Jimp = createJimp({
31407
31397
  });
31408
31398
 
31409
31399
  // src/3d/shaders/supersampling.wgsl
31410
- var supersampling_default = "./supersampling-jw3fem06.wgsl";
31400
+ var supersampling_default = `struct CellResult {
31401
+ bg: vec4<f32>, // Background RGBA (16 bytes)
31402
+ fg: vec4<f32>, // Foreground RGBA (16 bytes)
31403
+ char: u32, // Unicode character code (4 bytes)
31404
+ _padding1: u32, // Padding (4 bytes)
31405
+ _padding2: u32, // Extra padding (4 bytes)
31406
+ _padding3: u32, // Extra padding (4 bytes) - total now 48 bytes (16-byte aligned)
31407
+ };
31408
+
31409
+ struct CellBuffer {
31410
+ cells: array<CellResult>
31411
+ };
31412
+
31413
+ struct SuperSamplingParams {
31414
+ width: u32, // Canvas width in pixels
31415
+ height: u32, // Canvas height in pixels
31416
+ sampleAlgo: u32, // 0 = standard 2x2, 1 = pre-squeezed horizontal blend
31417
+ _padding: u32, // Padding for 16-byte alignment
31418
+ };
31419
+
31420
+ @group(0) @binding(0) var inputTexture: texture_2d<f32>;
31421
+ @group(0) @binding(1) var<storage, read_write> output: CellBuffer;
31422
+ @group(0) @binding(2) var<uniform> params: SuperSamplingParams;
31423
+
31424
+ // Quadrant character lookup table (same as Zig implementation)
31425
+ const quadrantChars = array<u32, 16>(
31426
+ 32u, // ' ' - 0000
31427
+ 0x2597u, // \u2597 - 0001 BR
31428
+ 0x2596u, // \u2596 - 0010 BL
31429
+ 0x2584u, // \u2584 - 0011 Lower Half Block
31430
+ 0x259Du, // \u259D - 0100 TR
31431
+ 0x2590u, // \u2590 - 0101 Right Half Block
31432
+ 0x259Eu, // \u259E - 0110 TR+BL
31433
+ 0x259Fu, // \u259F - 0111 TR+BL+BR
31434
+ 0x2598u, // \u2598 - 1000 TL
31435
+ 0x259Au, // \u259A - 1001 TL+BR
31436
+ 0x258Cu, // \u258C - 1010 Left Half Block
31437
+ 0x2599u, // \u2599 - 1011 TL+BL+BR
31438
+ 0x2580u, // \u2580 - 1100 Upper Half Block
31439
+ 0x259Cu, // \u259C - 1101 TL+TR+BR
31440
+ 0x259Bu, // \u259B - 1110 TL+TR+BL
31441
+ 0x2588u // \u2588 - 1111 Full Block
31442
+ );
31443
+
31444
+ const inv_255: f32 = 1.0 / 255.0;
31445
+
31446
+ fn getPixelColor(pixelX: u32, pixelY: u32) -> vec4<f32> {
31447
+ if (pixelX >= params.width || pixelY >= params.height) {
31448
+ return vec4<f32>(0.0, 0.0, 0.0, 1.0); // Black for out-of-bounds
31449
+ }
31450
+
31451
+ // textureLoad automatically handles format conversion to RGBA
31452
+ return textureLoad(inputTexture, vec2<i32>(i32(pixelX), i32(pixelY)), 0);
31453
+ }
31454
+
31455
+ fn colorDistance(a: vec4<f32>, b: vec4<f32>) -> f32 {
31456
+ let diff = a.rgb - b.rgb;
31457
+ return dot(diff, diff);
31458
+ }
31459
+
31460
+ fn luminance(color: vec4<f32>) -> f32 {
31461
+ return 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b;
31462
+ }
31463
+
31464
+ fn closestColorIndex(pixel: vec4<f32>, candA: vec4<f32>, candB: vec4<f32>) -> u32 {
31465
+ return select(1u, 0u, colorDistance(pixel, candA) <= colorDistance(pixel, candB));
31466
+ }
31467
+
31468
+ fn averageColor(pixels: array<vec4<f32>, 4>) -> vec4<f32> {
31469
+ return (pixels[0] + pixels[1] + pixels[2] + pixels[3]) * 0.25;
31470
+ }
31471
+
31472
+ fn blendColors(color1: vec4<f32>, color2: vec4<f32>) -> vec4<f32> {
31473
+ let a1 = color1.a;
31474
+ let a2 = color2.a;
31475
+
31476
+ if (a1 == 0.0 && a2 == 0.0) {
31477
+ return vec4<f32>(0.0, 0.0, 0.0, 0.0);
31478
+ }
31479
+
31480
+ let outAlpha = a1 + a2 - a1 * a2;
31481
+ if (outAlpha == 0.0) {
31482
+ return vec4<f32>(0.0, 0.0, 0.0, 0.0);
31483
+ }
31484
+
31485
+ let rgb = (color1.rgb * a1 + color2.rgb * a2 * (1.0 - a1)) / outAlpha;
31486
+
31487
+ return vec4<f32>(rgb, outAlpha);
31488
+ }
31489
+
31490
+ fn averageColorsWithAlpha(pixels: array<vec4<f32>, 4>) -> vec4<f32> {
31491
+ let blend1 = blendColors(pixels[0], pixels[1]);
31492
+ let blend2 = blendColors(pixels[2], pixels[3]);
31493
+
31494
+ return blendColors(blend1, blend2);
31495
+ }
31496
+
31497
+ fn renderQuadrantBlock(pixels: array<vec4<f32>, 4>) -> CellResult {
31498
+ var maxDist: f32 = colorDistance(pixels[0], pixels[1]);
31499
+ var pIdxA: u32 = 0u;
31500
+ var pIdxB: u32 = 1u;
31501
+
31502
+ for (var i: u32 = 0u; i < 4u; i++) {
31503
+ for (var j: u32 = i + 1u; j < 4u; j++) {
31504
+ let dist = colorDistance(pixels[i], pixels[j]);
31505
+ if (dist > maxDist) {
31506
+ pIdxA = i;
31507
+ pIdxB = j;
31508
+ maxDist = dist;
31509
+ }
31510
+ }
31511
+ }
31512
+
31513
+ let pCandA = pixels[pIdxA];
31514
+ let pCandB = pixels[pIdxB];
31515
+
31516
+ var chosenDarkColor: vec4<f32>;
31517
+ var chosenLightColor: vec4<f32>;
31518
+
31519
+ if (luminance(pCandA) <= luminance(pCandB)) {
31520
+ chosenDarkColor = pCandA;
31521
+ chosenLightColor = pCandB;
31522
+ } else {
31523
+ chosenDarkColor = pCandB;
31524
+ chosenLightColor = pCandA;
31525
+ }
31526
+
31527
+ var quadrantBits: u32 = 0u;
31528
+ let bitValues = array<u32, 4>(8u, 4u, 2u, 1u); // TL, TR, BL, BR
31529
+
31530
+ for (var i: u32 = 0u; i < 4u; i++) {
31531
+ if (closestColorIndex(pixels[i], chosenDarkColor, chosenLightColor) == 0u) {
31532
+ quadrantBits |= bitValues[i];
31533
+ }
31534
+ }
31535
+
31536
+ // Construct result
31537
+ var result: CellResult;
31538
+
31539
+ if (quadrantBits == 0u) { // All light
31540
+ result.char = 32u; // Space character
31541
+ result.fg = chosenDarkColor;
31542
+ result.bg = averageColorsWithAlpha(pixels);
31543
+ } else if (quadrantBits == 15u) { // All dark
31544
+ result.char = quadrantChars[15]; // Full block
31545
+ result.fg = averageColorsWithAlpha(pixels);
31546
+ result.bg = chosenLightColor;
31547
+ } else { // Mixed pattern
31548
+ result.char = quadrantChars[quadrantBits];
31549
+ result.fg = chosenDarkColor;
31550
+ result.bg = chosenLightColor;
31551
+ }
31552
+ result._padding1 = 0u;
31553
+ result._padding2 = 0u;
31554
+ result._padding3 = 0u;
31555
+
31556
+ return result;
31557
+ }
31558
+
31559
+ @compute @workgroup_size(\${WORKGROUP_SIZE}, \${WORKGROUP_SIZE}, 1)
31560
+ fn main(@builtin(global_invocation_id) id: vec3<u32>) {
31561
+ let cellX = id.x;
31562
+ let cellY = id.y;
31563
+ let bufferWidthCells = (params.width + 1u) / 2u;
31564
+ let bufferHeightCells = (params.height + 1u) / 2u;
31565
+
31566
+ if (cellX >= bufferWidthCells || cellY >= bufferHeightCells) {
31567
+ return;
31568
+ }
31569
+
31570
+ let renderX = cellX * 2u;
31571
+ let renderY = cellY * 2u;
31572
+
31573
+ var pixelsRgba: array<vec4<f32>, 4>;
31574
+
31575
+ if (params.sampleAlgo == 1u) {
31576
+ let topColor = getPixelColor(renderX, renderY);
31577
+ let topColor2 = getPixelColor(renderX + 1u, renderY);
31578
+
31579
+ let blendedTop = blendColors(topColor, topColor2);
31580
+
31581
+ let bottomColor = getPixelColor(renderX, renderY + 1u);
31582
+ let bottomColor2 = getPixelColor(renderX + 1u, renderY + 1u);
31583
+ let blendedBottom = blendColors(bottomColor, bottomColor2);
31584
+
31585
+ pixelsRgba[0] = blendedTop; // TL
31586
+ pixelsRgba[1] = blendedTop; // TR
31587
+ pixelsRgba[2] = blendedBottom; // BL
31588
+ pixelsRgba[3] = blendedBottom; // BR
31589
+ } else {
31590
+ pixelsRgba[0] = getPixelColor(renderX, renderY); // TL
31591
+ pixelsRgba[1] = getPixelColor(renderX + 1u, renderY); // TR
31592
+ pixelsRgba[2] = getPixelColor(renderX, renderY + 1u); // BL
31593
+ pixelsRgba[3] = getPixelColor(renderX + 1u, renderY + 1u); // BR
31594
+ }
31595
+
31596
+ let cellResult = renderQuadrantBlock(pixelsRgba);
31597
+
31598
+ let outputIndex = cellY * bufferWidthCells + cellX;
31599
+ output.cells[outputIndex] = cellResult;
31600
+ }`;
31411
31601
 
31412
31602
  // src/3d/canvas.ts
31413
- var filePaths = fixPaths({
31414
- shaderPath: supersampling_default
31415
- });
31416
31603
  var WORKGROUP_SIZE = 4;
31417
- var SUPERSAMPLING_COMPUTE_SHADER = await loadTemplate(filePaths.shaderPath, {
31418
- WORKGROUP_SIZE: WORKGROUP_SIZE.toString()
31419
- });
31604
+ var SUPERSAMPLING_COMPUTE_SHADER = supersampling_default.replace(/\${WORKGROUP_SIZE}/g, WORKGROUP_SIZE.toString());
31420
31605
  var SuperSampleAlgorithm;
31421
31606
  ((SuperSampleAlgorithm2) => {
31422
31607
  SuperSampleAlgorithm2[SuperSampleAlgorithm2["STANDARD"] = 0] = "STANDARD";
@@ -33791,6 +33976,18 @@ function parseJustify(value) {
33791
33976
  return Justify.FlexStart;
33792
33977
  }
33793
33978
  }
33979
+ function parsePositionType(value) {
33980
+ switch (value.toLowerCase()) {
33981
+ case "static":
33982
+ return PositionType.Static;
33983
+ case "relative":
33984
+ return PositionType.Relative;
33985
+ case "absolute":
33986
+ return PositionType.Absolute;
33987
+ default:
33988
+ return PositionType.Static;
33989
+ }
33990
+ }
33794
33991
 
33795
33992
  // src/Renderable.ts
33796
33993
  var renderableNumber = 1;
@@ -34101,8 +34298,8 @@ class Renderable extends EventEmitter3 {
34101
34298
  this.layoutNode.setHeight(options.height);
34102
34299
  }
34103
34300
  this._positionType = options.position ?? "relative";
34104
- if (this._positionType === "absolute") {
34105
- node.setPositionType(PositionType.Absolute);
34301
+ if (this._positionType !== "relative") {
34302
+ node.setPositionType(parsePositionType(this._positionType));
34106
34303
  }
34107
34304
  const hasPositionProps = options.top !== undefined || options.right !== undefined || options.bottom !== undefined || options.left !== undefined;
34108
34305
  if (hasPositionProps) {
@@ -34161,6 +34358,14 @@ class Renderable extends EventEmitter3 {
34161
34358
  node.setPadding(Edge2.Left, options.paddingLeft);
34162
34359
  }
34163
34360
  }
34361
+ set position(positionType) {
34362
+ if (this._positionType === positionType)
34363
+ return;
34364
+ this._positionType = positionType;
34365
+ this.layoutNode.yogaNode.setPositionType(parsePositionType(positionType));
34366
+ this.needsUpdate();
34367
+ this._yogaPerformancePositionUpdated = true;
34368
+ }
34164
34369
  setPosition(position) {
34165
34370
  this._position = { ...this._position, ...position };
34166
34371
  this.updateYogaPosition(position);
@@ -35368,6 +35573,77 @@ var BorderCharArrays = {
35368
35573
  rounded: borderCharsToArray(BorderChars.rounded),
35369
35574
  heavy: borderCharsToArray(BorderChars.heavy)
35370
35575
  };
35576
+ // src/lib/styled-text.ts
35577
+ var textEncoder = new TextEncoder;
35578
+
35579
+ class StyledText {
35580
+ chunks;
35581
+ _plainText = "";
35582
+ constructor(chunks) {
35583
+ this.chunks = chunks;
35584
+ for (let i = 0;i < chunks.length; i++) {
35585
+ this._plainText += chunks[i].plainText;
35586
+ }
35587
+ }
35588
+ toString() {
35589
+ return this._plainText;
35590
+ }
35591
+ _chunksToPlainText() {
35592
+ this._plainText = "";
35593
+ for (const chunk of this.chunks) {
35594
+ this._plainText += chunk.plainText;
35595
+ }
35596
+ }
35597
+ insert(chunk, index) {
35598
+ const originalLength = this.chunks.length;
35599
+ if (index === undefined) {
35600
+ this.chunks.push(chunk);
35601
+ } else {
35602
+ this.chunks.splice(index, 0, chunk);
35603
+ }
35604
+ if (index === undefined || index === originalLength) {
35605
+ this._plainText += chunk.plainText;
35606
+ } else {
35607
+ this._chunksToPlainText();
35608
+ }
35609
+ }
35610
+ remove(chunk) {
35611
+ const originalLength = this.chunks.length;
35612
+ const index = this.chunks.indexOf(chunk);
35613
+ if (index === -1)
35614
+ return;
35615
+ this.chunks.splice(index, 1);
35616
+ if (index === originalLength - 1) {
35617
+ this._plainText = this._plainText.slice(0, this._plainText.length - chunk.plainText.length);
35618
+ } else {
35619
+ this._chunksToPlainText();
35620
+ }
35621
+ }
35622
+ replace(chunk, oldChunk) {
35623
+ const index = this.chunks.indexOf(oldChunk);
35624
+ if (index === -1)
35625
+ return;
35626
+ this.chunks.splice(index, 1, chunk);
35627
+ if (index === this.chunks.length - 1) {
35628
+ this._plainText = this._plainText.slice(0, this._plainText.length - oldChunk.plainText.length) + chunk.plainText;
35629
+ } else {
35630
+ this._chunksToPlainText();
35631
+ }
35632
+ }
35633
+ }
35634
+ function stringToStyledText(content) {
35635
+ const textEncoder2 = new TextEncoder;
35636
+ const chunk = {
35637
+ __isChunk: true,
35638
+ text: textEncoder2.encode(content),
35639
+ plainText: content
35640
+ };
35641
+ return new StyledText([chunk]);
35642
+ }
35643
+ var templateCache = new WeakMap;
35644
+
35645
+ // src/lib/hast-styled-text.ts
35646
+ var textEncoder2 = new TextEncoder;
35371
35647
  // src/buffer.ts
35372
35648
  var fbIdCounter = 0;
35373
35649
  function isRGBAWithAlpha(color) {
@@ -35748,35 +36024,6 @@ class TimelineEngine {
35748
36024
  }
35749
36025
  }
35750
36026
  var engine = new TimelineEngine;
35751
- // src/lib/styled-text.ts
35752
- var textEncoder = new TextEncoder;
35753
-
35754
- class StyledText {
35755
- chunks;
35756
- _length;
35757
- _plainText;
35758
- constructor(chunks, length, plainText) {
35759
- this.chunks = chunks;
35760
- this._length = length;
35761
- this._plainText = plainText;
35762
- }
35763
- toString() {
35764
- return this._plainText;
35765
- }
35766
- get length() {
35767
- return this._length;
35768
- }
35769
- }
35770
- function stringToStyledText(content) {
35771
- const textEncoder2 = new TextEncoder;
35772
- const chunk = {
35773
- __isChunk: true,
35774
- text: textEncoder2.encode(content),
35775
- plainText: content
35776
- };
35777
- return new StyledText([chunk], content.length, content);
35778
- }
35779
- var templateCache = new WeakMap;
35780
36027
  // src/lib/selection.ts
35781
36028
  class Selection {
35782
36029
  _anchor;
@@ -37681,8 +37928,6 @@ class TextRenderable extends Renderable {
37681
37928
  set content(value) {
37682
37929
  this._text = typeof value === "string" ? stringToStyledText(value) : value;
37683
37930
  this.updateTextInfo();
37684
- this.setupMeasureFunc();
37685
- this.needsUpdate();
37686
37931
  }
37687
37932
  get fg() {
37688
37933
  return this._defaultFg;
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 opentui
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/Renderable.d.ts CHANGED
@@ -126,6 +126,7 @@ export declare abstract class Renderable extends EventEmitter {
126
126
  private ensureZIndexSorted;
127
127
  private setupYogaProperties;
128
128
  private setupMarginAndPadding;
129
+ set position(positionType: PositionTypeString);
129
130
  setPosition(position: Position): void;
130
131
  private updateYogaPosition;
131
132
  set flexGrow(grow: number);
package/index.d.ts CHANGED
@@ -12,3 +12,4 @@ export * from "./lib/selection";
12
12
  export * from "./renderer";
13
13
  export * from "./renderables";
14
14
  export * from "./zig";
15
+ export * from "./console";