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,137 @@
1
+ /**
2
+ * @file bin/utils/pwaShell.js
3
+ * @description Two build-time corrections that make a bundle deployable as a PWA
4
+ * on a static host, which is where every generated app actually ends up
5
+ * (GitHub Pages, S3, any bucket under `/repo/`).
6
+ *
7
+ * Neither can be left to the app author to remember, because both fail silently
8
+ * on the developer's own machine and only show up once deployed:
9
+ *
10
+ * 1. `writeSpaFallback` — a single-page app has routes the host does not know.
11
+ * GitHub Pages has no rewrite rule, so a refresh on `/repo/menu` is answered
12
+ * with Pages' own "Page not found": the app looks broken exactly on the
13
+ * entry point a shared link or a reload produces. `404.html` is the portable
14
+ * remedy: every static host serves that file for a missing path, so copying
15
+ * the built shell over it hands the deep link to the router instead.
16
+ *
17
+ * 2. `normaliseManifest` — a generated `manifest.json` says `"start_url": "/"`
18
+ * and `"scope": "/"`. Resolved against the manifest's own URL that is the
19
+ * host root, i.e. `https://user.github.io/`, which is outside the app's
20
+ * directory and outside its service worker's scope. Chrome then refuses to
21
+ * offer the install at all: the site renders, works offline, and never shows
22
+ * "Add to Home Screen". Icons have the quieter version of the same bug — a
23
+ * copied logo declared as `192x192` that is really 512 px wide.
24
+ *
25
+ * Both only touch the bundle output. The project's own `manifest.json` and
26
+ * `index.html` stay host-agnostic so the same folder still runs on `:8000`.
27
+ */
28
+
29
+ import fs from "fs";
30
+ import path from "path";
31
+
32
+ /**
33
+ * Read the intrinsic size of a PNG from its IHDR chunk.
34
+ *
35
+ * @param {string} filePath - Absolute path to the candidate icon.
36
+ * @returns {{width: number, height: number}|null} Nothing for a non-PNG file.
37
+ */
38
+ export const pngDimensions = (filePath) => {
39
+ const header = Buffer.alloc(24);
40
+ let handle;
41
+ try {
42
+ handle = fs.openSync(filePath, "r");
43
+ if (fs.readSync(handle, header, 0, 24, 0) !== 24) return null;
44
+ } catch {
45
+ return null;
46
+ } finally {
47
+ if (handle !== undefined) fs.closeSync(handle);
48
+ }
49
+
50
+ const isPng =
51
+ header[0] === 0x89 &&
52
+ header.subarray(12, 16).toString("ascii") === "IHDR";
53
+ if (!isPng) return null;
54
+ return { width: header.readUInt32BE(16), height: header.readUInt32BE(20) };
55
+ };
56
+
57
+ /**
58
+ * Make the bundled `manifest.json` launch and stay inside the app it ships with.
59
+ *
60
+ * `start_url` and `scope` are resolved against the manifest URL, so `"/"` means
61
+ * the host root. Rewriting only that value (and an empty string) to `"./"` keeps
62
+ * a root-hosted app identical to what it was while pulling a sub-path app back
63
+ * inside its own directory; any other value is a deliberate base path and is left
64
+ * alone. Each icon's declared `sizes` is corrected to the pixels the file really
65
+ * has, which is also what makes the 192 px requirement provable to the browser.
66
+ *
67
+ * @param {string} targetDir - Absolute path of the bundle directory.
68
+ * @returns {string[]} Human-readable description of each correction made.
69
+ */
70
+ export const normaliseManifest = (targetDir) => {
71
+ const manifestPath = path.join(targetDir, "manifest.json");
72
+ if (!fs.existsSync(manifestPath)) return [];
73
+
74
+ let raw;
75
+ try {
76
+ raw = fs.readFileSync(manifestPath, "utf8");
77
+ } catch {
78
+ return [];
79
+ }
80
+
81
+ let manifest;
82
+ try {
83
+ manifest = JSON.parse(raw);
84
+ } catch {
85
+ return [];
86
+ }
87
+
88
+ const changes = [];
89
+
90
+ // "/" escapes the app on a sub-path host; "" is the same mistake written
91
+ // differently. Anything else was typed on purpose.
92
+ for (const field of ["start_url", "scope"]) {
93
+ if (manifest[field] === "/" || manifest[field] === "") {
94
+ manifest[field] = "./";
95
+ changes.push(`${field}: "/" → "./"`);
96
+ }
97
+ }
98
+
99
+ if (Array.isArray(manifest.icons)) {
100
+ for (const icon of manifest.icons) {
101
+ if (!icon || typeof icon.src !== "string") continue;
102
+ // Strip any query/hash and the leading "./" before hitting the disk; the
103
+ // bundle keeps icons relative to its own directory.
104
+ const clean = icon.src.split(/[?#]/)[0].replace(/^\.\//, "");
105
+ const size = pngDimensions(path.join(targetDir, clean));
106
+ if (!size) continue;
107
+ const actual = `${size.width}x${size.height}`;
108
+ if (icon.sizes !== actual) {
109
+ const declared = icon.sizes;
110
+ icon.sizes = actual;
111
+ changes.push(`${clean}: sizes now ${actual} (was ${declared})`);
112
+ }
113
+ }
114
+ }
115
+
116
+ if (changes.length) {
117
+ fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2) + "\n");
118
+ }
119
+ return changes;
120
+ };
121
+
122
+ /**
123
+ * Copy the finished shell to `404.html` so unknown paths serve the app.
124
+ *
125
+ * Called last, after the OTA loader is wired and the share tags are absolute, so
126
+ * the fallback document is byte-identical to `index.html` and boots the same
127
+ * bundle. Idempotent: rebuilding the project always rewrites it.
128
+ *
129
+ * @param {string} targetDir - Absolute path of the bundle directory.
130
+ * @returns {boolean} False when there is no `index.html` to copy.
131
+ */
132
+ export const writeSpaFallback = (targetDir) => {
133
+ const index = path.join(targetDir, "index.html");
134
+ if (!fs.existsSync(index)) return false;
135
+ fs.copyFileSync(index, path.join(targetDir, "404.html"));
136
+ return true;
137
+ };