aboutsummaryrefslogtreecommitdiff
path: root/src/client/util
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2023-12-29 01:01:55 -0500
committerbobzel <zzzman@gmail.com>2023-12-29 01:01:55 -0500
commit865478933af8166cb699cbe4a2653aa52423dedb (patch)
tree57dedd5dfe4349432a7c445f408f9e675f1f53df /src/client/util
parentdf2fc3f11e3b474144db5062620c9f65ca857203 (diff)
fixed dropping images from web. fixed exif data on images and autorotating exif rotated images. fixed selecting on web pages, and resizing web pages upward so that pointer events aren't grabbed.
Diffstat (limited to 'src/client/util')
-rw-r--r--src/client/util/Import & Export/ImageUtils.ts41
1 files changed, 23 insertions, 18 deletions
diff --git a/src/client/util/Import & Export/ImageUtils.ts b/src/client/util/Import & Export/ImageUtils.ts
index 55d37f544..d99828956 100644
--- a/src/client/util/Import & Export/ImageUtils.ts
+++ b/src/client/util/Import & Export/ImageUtils.ts
@@ -4,28 +4,33 @@ import { Cast, StrCast, NumCast } from '../../../fields/Types';
import { Networking } from '../../Network';
import { Id } from '../../../fields/FieldSymbols';
import { Utils } from '../../../Utils';
+import { DocData } from '../../../fields/DocSymbols';
export namespace ImageUtils {
- export const ExtractExif = async (document: Doc): Promise<boolean> => {
+ export type imgInfo = {
+ contentSize: number;
+ nativeWidth: number;
+ nativeHeight: number;
+ source: string;
+ exifData: { error: string | undefined; data: string };
+ };
+ export const ExtractImgInfo = async (document: Doc): Promise<imgInfo | undefined> => {
const field = Cast(document.data, ImageField);
- if (!field) {
- return false;
+ return field ? await Networking.PostToServer('/inspectImage', { source: field.url.href }) : undefined;
+ };
+
+ export const AssignImgInfo = (document: Doc, data?: imgInfo) => {
+ if (data) {
+ data.nativeWidth && (document._height = (NumCast(document._width) * data.nativeHeight) / data.nativeWidth);
+ const proto = document[DocData];
+ const field = Doc.LayoutFieldKey(document);
+ proto[`${field}_nativeWidth`] = data.nativeWidth;
+ proto[`${field}_nativeHeight`] = data.nativeHeight;
+ proto[`${field}_path`] = data.source;
+ proto[`${field}_exif`] = JSON.stringify(data.exifData.data);
+ proto[`${field}_contentSize`] = data.contentSize ? data.contentSize : undefined;
}
- const source = field.url.href;
- const {
- contentSize,
- nativeWidth,
- nativeHeight,
- exifData: { error, data },
- } = await Networking.PostToServer('/inspectImage', { source });
- document.exif = error || Doc.Get.FromJson({ data });
- const proto = Doc.GetProto(document);
- nativeWidth && (document._height = (NumCast(document._width) * nativeHeight) / nativeWidth);
- proto['data_nativeWidth'] = nativeWidth;
- proto['data_nativeHeight'] = nativeHeight;
- proto['data-path'] = source;
- proto.data_contentSize = contentSize ? contentSize : undefined;
- return data !== undefined;
+ return document;
};
export const ExportHierarchyToFileSystem = async (collection: Doc): Promise<void> => {