about summary refs log tree commit diff
path: root/src/lib
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2023-01-26 12:36:27 -0600
committerPaul Frazee <pfrazee@gmail.com>2023-01-26 12:36:27 -0600
commit751dfb20fd0d316da396e3c4fc53aaaaa8041dd1 (patch)
tree55c23e901903cfa19b6b9acc264df0d0637d66f0 /src/lib
parentd6ec627c8cd32836e5ed494606318959ca17fca1 (diff)
downloadvoidsky-751dfb20fd0d316da396e3c4fc53aaaaa8041dd1.tar.zst
Add web polyfills
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/images.web.ts69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/lib/images.web.ts b/src/lib/images.web.ts
new file mode 100644
index 000000000..5158e005f
--- /dev/null
+++ b/src/lib/images.web.ts
@@ -0,0 +1,69 @@
+import {Share} from 'react-native'
+
+import * as Toast from '../view/com/util/Toast'
+
+export interface DownloadAndResizeOpts {
+  uri: string
+  width: number
+  height: number
+  mode: 'contain' | 'cover' | 'stretch'
+  maxSize: number
+  timeout: number
+}
+
+export interface Image {
+  path: string
+  mime: string
+  size: number
+  width: number
+  height: number
+}
+
+export async function downloadAndResize(_opts: DownloadAndResizeOpts) {
+  // TODO
+  throw new Error('TODO')
+}
+
+export interface ResizeOpts {
+  width: number
+  height: number
+  mode: 'contain' | 'cover' | 'stretch'
+  maxSize: number
+}
+
+export async function resize(
+  _localUri: string,
+  _opts: ResizeOpts,
+): Promise<Image> {
+  // TODO
+  throw new Error('TODO')
+}
+
+export async function compressIfNeeded(
+  _img: Image,
+  _maxSize: number,
+): Promise<Image> {
+  // TODO
+  throw new Error('TODO')
+}
+
+export interface Dim {
+  width: number
+  height: number
+}
+export function scaleDownDimensions(dim: Dim, max: Dim): Dim {
+  if (dim.width < max.width && dim.height < max.height) {
+    return dim
+  }
+  let wScale = dim.width > max.width ? max.width / dim.width : 1
+  let hScale = dim.height > max.height ? max.height / dim.height : 1
+  if (wScale < hScale) {
+    return {width: dim.width * wScale, height: dim.height * wScale}
+  }
+  return {width: dim.width * hScale, height: dim.height * hScale}
+}
+
+export const saveImageModal = async (_opts: {uri: string}) => {
+  // TODO
+  throw new Error('TODO')
+}