flet-box 1.0.6 → 1.0.8

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.
Files changed (162) hide show
  1. package/README.md +28 -1
  2. package/bin/cli.js +90 -11
  3. package/bin/commands/auditFix.js +682 -0
  4. package/bin/commands/checkApi.js +20 -6
  5. package/bin/commands/checkUi.js +1369 -0
  6. package/bin/commands/create.js +86 -12
  7. package/bin/commands/createBundle.js +75 -1
  8. package/bin/commands/images.js +349 -0
  9. package/bin/commands/pruneAssets.js +170 -0
  10. package/bin/commands/release.js +34 -1
  11. package/bin/commands/runCloudflare.js +47 -9
  12. package/bin/commands/runServer.js +91 -25
  13. package/bin/commands/toPng.js +346 -0
  14. package/bin/commands/unpack.js +1173 -0
  15. package/bin/ota/loader.js +90 -0
  16. package/bin/utils/appSources.js +101 -0
  17. package/bin/utils/bundleConfig.js +166 -0
  18. package/bin/utils/dtsProps.js +147 -0
  19. package/bin/utils/imageTools.js +271 -0
  20. package/bin/utils/images/bmp.js +99 -0
  21. package/bin/utils/images/gif.js +244 -0
  22. package/bin/utils/images/index.js +163 -0
  23. package/bin/utils/images/jpeg.js +643 -0
  24. package/bin/utils/images/png.js +486 -0
  25. package/bin/utils/images/unsupported.js +29 -0
  26. package/bin/utils/neutralise.js +109 -6
  27. package/bin/utils/pwaShell.js +137 -0
  28. package/bin/utils/templates.js +1653 -471
  29. package/docs/README.md +2 -0
  30. package/docs/cli/README.md +144 -1
  31. package/docs/guides/README.md +2 -0
  32. package/docs/guides/clean-ui.md +211 -0
  33. package/docs/guides/minification-and-protection.md +1 -1
  34. package/docs/guides/online-updates.md +105 -9
  35. package/docs/tools/README.md +1 -1
  36. package/docs/tools/animation.md +1 -1
  37. package/docs/tools/markdown.md +3 -3
  38. package/docs/tools/theme.md +41 -1
  39. package/docs/widget/Accordion.md +4 -0
  40. package/docs/widget/AdMob.md +5 -1
  41. package/docs/widget/AdSense.md +4 -0
  42. package/docs/widget/AnimatedBox.md +7 -3
  43. package/docs/widget/AnimatedText.md +4 -0
  44. package/docs/widget/Audio.md +5 -1
  45. package/docs/widget/Avatar.md +15 -3
  46. package/docs/widget/Badge.md +4 -0
  47. package/docs/widget/Button.md +4 -0
  48. package/docs/widget/COMMON_PROPS.md +52 -0
  49. package/docs/widget/Card.md +4 -0
  50. package/docs/widget/Carousel.md +4 -0
  51. package/docs/widget/Chart.md +4 -0
  52. package/docs/widget/Checkbox.md +4 -0
  53. package/docs/widget/Chip.md +4 -0
  54. package/docs/widget/CircularBar.md +4 -0
  55. package/docs/widget/CircularChart.md +4 -0
  56. package/docs/widget/CodeViewer.md +4 -0
  57. package/docs/widget/Column.md +4 -0
  58. package/docs/widget/Container.md +4 -0
  59. package/docs/widget/DataTable.md +4 -0
  60. package/docs/widget/Divider.md +4 -0
  61. package/docs/widget/DraggBox.md +6 -2
  62. package/docs/widget/Dropdown.md +6 -0
  63. package/docs/widget/DroppBox.md +5 -1
  64. package/docs/widget/FloatingActionButton.md +4 -0
  65. package/docs/widget/GridView.md +4 -0
  66. package/docs/widget/Icon.md +4 -0
  67. package/docs/widget/Image.md +14 -3
  68. package/docs/widget/Input.md +4 -0
  69. package/docs/widget/Inspector.md +2 -2
  70. package/docs/widget/InstallButton.md +4 -0
  71. package/docs/widget/ListTile.md +4 -0
  72. package/docs/widget/ListView.md +4 -0
  73. package/docs/widget/Maps.md +191 -0
  74. package/docs/widget/Markdown.md +4 -0
  75. package/docs/widget/MatrixRain.md +4 -0
  76. package/docs/widget/Pagination.md +4 -0
  77. package/docs/widget/ParallaxBox.md +4 -0
  78. package/docs/widget/ProgressBar.md +4 -0
  79. package/docs/widget/QRCode.md +4 -0
  80. package/docs/widget/README.md +12 -10
  81. package/docs/widget/Radio.md +5 -1
  82. package/docs/widget/Rating.md +4 -0
  83. package/docs/widget/Row.md +4 -0
  84. package/docs/widget/Skeleton.md +4 -0
  85. package/docs/widget/Slider.md +4 -0
  86. package/docs/widget/Stack.md +4 -0
  87. package/docs/widget/Stepper.md +4 -0
  88. package/docs/widget/Switch.md +4 -0
  89. package/docs/widget/Tabs.md +5 -5
  90. package/docs/widget/Text.md +4 -0
  91. package/docs/widget/Tooltip.md +14 -13
  92. package/docs/widget/TreeView.md +4 -0
  93. package/docs/widget/Video.md +6 -2
  94. package/package.json +2 -2
  95. package/src/animations/AnimatedBox.js +4 -1
  96. package/src/animations/MatrixRain.js +3 -3
  97. package/src/core/hmr-client.js +129 -34
  98. package/src/index.d.ts +195 -7
  99. package/src/index.js +2 -0
  100. package/src/navigations/AppBar.js +22 -16
  101. package/src/navigations/BottomNavigation.js +8 -13
  102. package/src/navigations/CollapsibleSideBar.js +30 -8
  103. package/src/navigations/Drawer.js +25 -15
  104. package/src/navigations/DrawerItem.js +3 -1
  105. package/src/navigations/Scaffold.js +26 -12
  106. package/src/navigations/Tabs.js +104 -59
  107. package/src/tools/color.js +54 -0
  108. package/src/tools/index.js +9 -1
  109. package/src/tools/scale.js +41 -0
  110. package/src/tools/shadow.js +20 -0
  111. package/src/utils/index.js +1 -0
  112. package/src/utils/readableInk.js +19 -0
  113. package/src/utils/syntaxHighlight.js +78 -10
  114. package/src/utils/themes.js +217 -54
  115. package/src/utils/units.js +33 -11
  116. package/src/widget-factory/effects.js +56 -5
  117. package/src/widget-factory/processProps.js +10 -1
  118. package/src/widget-factory/remTool.js +15 -29
  119. package/src/widget-factory/stackPosition.js +18 -3
  120. package/src/widget-factory/translateProps.js +60 -1
  121. package/src/widgets/Accordion.js +20 -23
  122. package/src/widgets/AdMob.js +7 -2
  123. package/src/widgets/Avatar.js +236 -133
  124. package/src/widgets/Badge.js +3 -2
  125. package/src/widgets/BottomSheet.js +14 -13
  126. package/src/widgets/Button.js +69 -30
  127. package/src/widgets/Card.js +6 -2
  128. package/src/widgets/Carousel.js +12 -10
  129. package/src/widgets/Chart.js +28 -5
  130. package/src/widgets/Checkbox.js +76 -18
  131. package/src/widgets/Chip.js +31 -10
  132. package/src/widgets/CircularBar.js +7 -7
  133. package/src/widgets/CircularChart.js +26 -8
  134. package/src/widgets/CodeViewer.js +93 -20
  135. package/src/widgets/Container.js +13 -0
  136. package/src/widgets/DataTable.js +17 -11
  137. package/src/widgets/DraggBox.js +2 -1
  138. package/src/widgets/Dropdown.js +59 -14
  139. package/src/widgets/DroppBox.js +4 -2
  140. package/src/widgets/FloatingActionButton.js +13 -7
  141. package/src/widgets/Icon.js +3 -1
  142. package/src/widgets/Image.js +102 -3
  143. package/src/widgets/Input.js +30 -23
  144. package/src/widgets/Inspector.js +54 -1
  145. package/src/widgets/InstallButton.js +6 -4
  146. package/src/widgets/ListTile.js +4 -3
  147. package/src/widgets/ListView.js +30 -12
  148. package/src/widgets/Maps.js +1495 -0
  149. package/src/widgets/Markdown.js +37 -26
  150. package/src/widgets/Modal.js +14 -11
  151. package/src/widgets/Pagination.js +16 -11
  152. package/src/widgets/ProgressBar.js +6 -4
  153. package/src/widgets/Radio.js +73 -15
  154. package/src/widgets/Rating.js +24 -6
  155. package/src/widgets/Skeleton.js +31 -31
  156. package/src/widgets/Slider.js +29 -18
  157. package/src/widgets/SnackBar.js +35 -39
  158. package/src/widgets/Stepper.js +13 -9
  159. package/src/widgets/Switch.js +59 -18
  160. package/src/widgets/Tooltip.js +24 -12
  161. package/src/widgets/TreeView.js +27 -15
  162. package/src/widgets/index.js +1 -0
@@ -0,0 +1,163 @@
1
+ /**
2
+ * @file bin/utils/images/index.js
3
+ * @description Format sniffing and decoding for `flet-box to-png`.
4
+ *
5
+ * A file is identified by its leading bytes, never by its extension: an asset
6
+ * called `logo.jpg` that is really a PNG is a real thing in a real project, and
7
+ * converting it by extension would write a PNG with the wrong pixels.
8
+ *
9
+ * Everything here is Node core plus the decoders in this folder. The formats
10
+ * that cannot be decoded without a third-party library — WebP's lossy VP8
11
+ * codec, AVIF/HEIF which are whole video containers, SVG which is vector and
12
+ * needs a rasteriser, TIFF, ICO — are reported as declined, with the reason, by
13
+ * the command that uses this module.
14
+ */
15
+
16
+ import { decodePng, encodePng } from "./png.js";
17
+ import { decodeJpeg } from "./jpeg.js";
18
+ import { decodeBmp } from "./bmp.js";
19
+ import { decodeGif } from "./gif.js";
20
+ import UnsupportedImage from "./unsupported.js";
21
+
22
+ export { UnsupportedImage };
23
+
24
+ /**
25
+ * Names the format behind a file's first bytes.
26
+ *
27
+ * @param {Buffer} buf
28
+ * @returns {"png"|"jpeg"|"bmp"|"gif"|"webp"|"avif"|"tiff"|"ico"|"svg"|"unknown"}
29
+ */
30
+ export const sniffFormat = (buf) => {
31
+ if (buf.length < 12) return "unknown";
32
+ if (buf[0] === 0x89 && buf[1] === 0x50 && buf[2] === 0x4e && buf[3] === 0x47) return "png";
33
+ if (buf[0] === 0xff && buf[1] === 0xd8 && buf[2] === 0xff) return "jpeg";
34
+ if (buf[0] === 0x42 && buf[1] === 0x4d) return "bmp";
35
+ if (buf.toString("ascii", 0, 3) === "GIF") return "gif";
36
+ if (buf.toString("ascii", 0, 4) === "RIFF" && buf.toString("ascii", 8, 12) === "WEBP") return "webp";
37
+ if (buf.toString("ascii", 4, 8) === "ftyp") {
38
+ const brand = buf.toString("ascii", 8, 12);
39
+ if (/^(avif|avis|heic|heix|hevc|mif1|msf1)$/.test(brand)) return "avif";
40
+ }
41
+ if (buf[0] === 0x49 && buf[1] === 0x49 && buf[2] === 0x2a) return "tiff";
42
+ if (buf[0] === 0x4d && buf[1] === 0x4d && buf[2] === 0x00) return "tiff";
43
+ if (buf.readUInt16LE(0) === 0 && buf.readUInt16LE(2) === 1) return "ico";
44
+ const head = buf.toString("utf8", 0, Math.min(buf.length, 256)).trimStart();
45
+ if (head.startsWith("<svg") || head.startsWith("<?xml")) return "svg";
46
+ return "unknown";
47
+ };
48
+
49
+ /**
50
+ * Reads the size and the transparency of a PNG or JPEG from its header, without
51
+ * decoding a single pixel.
52
+ *
53
+ * This exists for the commands that only need to *know* a picture: a budget
54
+ * search wants the frame width to resize from and whether an alpha plane has to
55
+ * survive, and both are in the first bytes. It also covers the files the full
56
+ * decoder declines by rule — a progressive JPEG is a browser-standard export from
57
+ * Photoshop or macOS, and `decodeJpeg` stops at multi-scan coding because that is
58
+ * the honest thing to do in a lossless converter.
59
+ *
60
+ * @param {Buffer} buf - File bytes.
61
+ * @returns {{format: string, width: number, height: number, hasAlpha: boolean|null, note?: string}}
62
+ * @throws {UnsupportedImage} When the format has no readable header here.
63
+ */
64
+ export const readImageHeader = (buf) => {
65
+ const format = sniffFormat(buf);
66
+
67
+ if (format === "png") {
68
+ if (buf.length < 26) throw new UnsupportedImage("PNG", "the header is truncated");
69
+ const width = buf.readUInt32BE(16);
70
+ const height = buf.readUInt32BE(20);
71
+ const colorType = buf[25];
72
+ // Chunks run to the end of the file; only `tRNS` matters, and a palette or a
73
+ // grey/RGB file with one is as transparent as colour type 6.
74
+ let tRNS = false;
75
+ let at = 8;
76
+ while (at + 8 <= buf.length) {
77
+ const fourcc = buf.toString("ascii", at, at + 4);
78
+ const size = buf.readUInt32LE(at + 4);
79
+ if (fourcc === "tRNS") tRNS = true;
80
+ if (fourcc === "IHDR" && buf[at + 8 + 1] !== 0) {
81
+ throw new UnsupportedImage("PNG", "Adam7 interlacing is not implemented");
82
+ }
83
+ if (fourcc === "IDAT") break;
84
+ at += 8 + size + 12;
85
+ }
86
+ return {
87
+ format,
88
+ width,
89
+ height,
90
+ hasAlpha: colorType === 4 || colorType === 6 || tRNS,
91
+ note: tRNS && colorType !== 4 && colorType !== 6 ? "tRNS" : undefined,
92
+ };
93
+ }
94
+
95
+ if (format === "jpeg") {
96
+ let at = 2;
97
+ while (at + 9 < buf.length) {
98
+ if (buf[at] !== 0xff) {
99
+ at++;
100
+ continue;
101
+ }
102
+ const marker = buf[at + 1];
103
+ if (marker === 0x00 || marker === 0x01 || (marker >= 0xd0 && marker <= 0xd9)) {
104
+ at += 2;
105
+ continue;
106
+ }
107
+ // Start-of-frame markers carry the dimensions at the same offsets whether
108
+ // the scan is baseline (0xC0), progressive (0xC2) or lossless (0xC3).
109
+ if (marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8) {
110
+ return {
111
+ format,
112
+ height: buf.readUInt16BE(at + 5),
113
+ width: buf.readUInt16BE(at + 7),
114
+ hasAlpha: false, // JPEG has no alpha channel in any of its codings
115
+ note: marker === 0xc2 ? "progressive" : marker === 0xc3 ? "lossless" : undefined,
116
+ };
117
+ }
118
+ at += 2 + buf.readUInt16BE(at + 2);
119
+ }
120
+ throw new UnsupportedImage("JPEG", "no start-of-frame marker was found");
121
+ }
122
+
123
+ throw new UnsupportedImage(format.toUpperCase(), "this tool reads no header for that format");
124
+ };
125
+
126
+ /**
127
+ * Decodes an image of any supported format into RGBA.
128
+ *
129
+ * @param {Buffer} buf - File bytes.
130
+ * @returns {{ format: string, width: number, height: number, rgba: Buffer, note?: string }}
131
+ * @throws {UnsupportedImage} For a format this tool declines.
132
+ * @throws {Error} For a file that claims to be supported but is broken.
133
+ */
134
+ export const decodeImage = (buf) => {
135
+ const format = sniffFormat(buf);
136
+ switch (format) {
137
+ case "png":
138
+ return { format, ...decodePng(buf) };
139
+ case "jpeg":
140
+ return { format, ...decodeJpeg(buf) };
141
+ case "bmp":
142
+ return { format, ...decodeBmp(buf) };
143
+ case "gif":
144
+ return { format, ...decodeGif(buf) };
145
+ case "webp":
146
+ throw new UnsupportedImage(
147
+ "WebP",
148
+ "lossy VP8 needs a video codec; shrink it with `flet-box images` instead",
149
+ );
150
+ case "avif":
151
+ throw new UnsupportedImage("AVIF/HEIF", "these are video containers, not still images");
152
+ case "tiff":
153
+ throw new UnsupportedImage("TIFF", "its tag layout is not implemented here");
154
+ case "ico":
155
+ throw new UnsupportedImage("ICO", "an icon sheet holds several images; extract the frame you want first");
156
+ case "svg":
157
+ throw new UnsupportedImage("SVG", "it is vector art and needs a rasteriser, not a decoder");
158
+ default:
159
+ throw new UnsupportedImage("unknown format", "the leading bytes match no image this tool can read");
160
+ }
161
+ };
162
+
163
+ export { decodePng, encodePng, decodeJpeg, decodeBmp, decodeGif };