flavor-code 1.3.22 → 1.3.23

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.
@@ -1523,6 +1523,16 @@ function isBridgeMethod(value, method) {
1523
1523
  && typeof value[method] === "function";
1524
1524
  }
1525
1525
 
1526
+ function safeDataForType(pasteboard, type) {
1527
+ try {
1528
+ return isBridgeMethod(pasteboard, "dataForType")
1529
+ ? pasteboard.dataForType(type)
1530
+ : null;
1531
+ } catch (error) {
1532
+ return null;
1533
+ }
1534
+ }
1535
+
1526
1536
  function pngDataFromTiff(tiff) {
1527
1537
  if (!isBridgeMethod(tiff, "base64EncodedStringWithOptions")) {
1528
1538
  return null;
@@ -1562,35 +1572,111 @@ function base64FromData(data) {
1562
1572
  }
1563
1573
  }
1564
1574
 
1565
- try {
1566
- const pasteboard = $.NSPasteboard.generalPasteboard;
1567
- let encoded = null;
1568
- if (isBridgeMethod(pasteboard, "dataForType")) {
1569
- encoded = base64FromData(pasteboard.dataForType($.NSPasteboardTypePNG));
1570
- if (!encoded) {
1571
- encoded = base64FromData(
1572
- pngDataFromTiff(pasteboard.dataForType($.NSPasteboardTypeTIFF))
1573
- );
1575
+ function firstReadableObject(pasteboard, objectClass) {
1576
+ try {
1577
+ if (!isBridgeMethod(pasteboard, "readObjectsForClassesOptions")) {
1578
+ return null;
1574
1579
  }
1580
+ const classes = $.NSArray.arrayWithObject(objectClass);
1581
+ const objects = pasteboard.readObjectsForClassesOptions(classes, $({}));
1582
+ return objects === null || objects === undefined ? null : objects.firstObject;
1583
+ } catch (error) {
1584
+ return null;
1575
1585
  }
1586
+ }
1576
1587
 
1577
- // Some macOS applications do not advertise a direct public.png or
1578
- // public.tiff payload. NSImage can ask AppKit to read any image type the
1579
- // pasteboard promises (for example PDF, HEIC, or a lazily supplied image),
1580
- // after which TIFFRepresentation gives us a stable raster conversion path.
1581
- if (!encoded) {
1588
+ function imageFromWholePasteboard(pasteboard) {
1589
+ try {
1582
1590
  const image = $.NSImage.alloc.initWithPasteboard(pasteboard);
1583
- if (image !== null && image !== undefined) {
1584
- encoded = base64FromData(pngDataFromTiff(image.TIFFRepresentation));
1591
+ return image === null || image === undefined ? null : image;
1592
+ } catch (error) {
1593
+ return null;
1594
+ }
1595
+ }
1596
+
1597
+ function imageFromFileUrl(pasteboard) {
1598
+ try {
1599
+ const url = firstReadableObject(pasteboard, $.NSURL);
1600
+ if (url === null || url === undefined || !url.isFileURL) {
1601
+ return null;
1585
1602
  }
1603
+ const image = $.NSImage.alloc.initWithContentsOfURL(url);
1604
+ return image === null || image === undefined ? null : image;
1605
+ } catch (error) {
1606
+ return null;
1586
1607
  }
1587
- if (!encoded) {
1588
- $.exit(3);
1608
+ }
1609
+
1610
+ function base64FromImage(image) {
1611
+ try {
1612
+ return image === null || image === undefined
1613
+ ? null
1614
+ : base64FromData(pngDataFromTiff(image.TIFFRepresentation));
1615
+ } catch (error) {
1616
+ return null;
1617
+ }
1618
+ }
1619
+
1620
+ function pasteboardTypeNames(pasteboard) {
1621
+ try {
1622
+ const types = pasteboard.types;
1623
+ if (!isBridgeMethod(types, "objectAtIndex")) {
1624
+ return [];
1625
+ }
1626
+ const count = Number(types.count);
1627
+ const names = [];
1628
+ for (let index = 0; index < count; index += 1) {
1629
+ const name = ObjC.unwrap(types.objectAtIndex(index));
1630
+ if (typeof name === "string") {
1631
+ names.push(name);
1632
+ }
1633
+ }
1634
+ return names;
1635
+ } catch (error) {
1636
+ return [];
1637
+ }
1638
+ }
1639
+
1640
+ const pasteboard = $.NSPasteboard.generalPasteboard;
1641
+ let encoded = base64FromData(safeDataForType(pasteboard, $("public.png")));
1642
+
1643
+ if (!encoded) {
1644
+ encoded = base64FromData(
1645
+ pngDataFromTiff(safeDataForType(pasteboard, $("public.tiff")))
1646
+ );
1647
+ }
1648
+
1649
+ // Ask AppKit for objects conforming to NSPasteboardReading. This covers image
1650
+ // formats and lazy providers that do not expose direct PNG/TIFF NSData.
1651
+ if (!encoded) {
1652
+ encoded = base64FromImage(firstReadableObject(pasteboard, $.NSImage));
1653
+ }
1654
+
1655
+ if (!encoded) {
1656
+ encoded = base64FromImage(imageFromWholePasteboard(pasteboard));
1657
+ }
1658
+
1659
+ // Finder copies files as file URLs instead of image bytes. Load the first
1660
+ // local file through NSImage, which also rejects non-image files.
1661
+ if (!encoded) {
1662
+ encoded = base64FromImage(imageFromFileUrl(pasteboard));
1663
+ }
1664
+
1665
+ if (!encoded) {
1666
+ const types = pasteboardTypeNames(pasteboard);
1667
+ const advertisedImage = types.some(function (type) {
1668
+ return /image|png|tiff|jpeg|jpg|heic|gif|webp|bmp|pdf|file-url|filenames/i.test(type);
1669
+ });
1670
+ if (advertisedImage) {
1671
+ throw new Error(
1672
+ "Clipboard advertises image or file data but AppKit could not decode it. Types: "
1673
+ + types.join(", ")
1674
+ );
1589
1675
  }
1590
- console.log(encoded);
1591
- } catch (error) {
1592
1676
  $.exit(3);
1593
1677
  }
1678
+
1679
+ console.log(encoded);
1594
1680
  `.trim();
1595
1681
  function shouldReadClipboardImage(input, key, isPasted) {
1596
1682
  return (key.ctrl || key.meta === true) && input.toLowerCase() === "v" || isPasted && input.length === 0;
package/dist/cli-main.js CHANGED
@@ -882,7 +882,7 @@ async function runInteractiveCli(props) {
882
882
  const [{ render, AlternateScreen }, { createElement }, { App }] = await Promise.all([
883
883
  import("./claude-ink-6CEG2XZZ.js"),
884
884
  import("react"),
885
- import("./app-MWGRT3BJ.js")
885
+ import("./app-NTEUPJKJ.js")
886
886
  ]);
887
887
  const instance = await render(createElement(
888
888
  AlternateScreen,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flavor-code",
3
- "version": "1.3.22",
3
+ "version": "1.3.23",
4
4
  "author": "YachuanWzh",
5
5
  "type": "module",
6
6
  "publishConfig": {