diff --git a/.dumirc.ts b/.dumirc.ts index ff8b2ae..8ed82c5 100644 --- a/.dumirc.ts +++ b/.dumirc.ts @@ -13,6 +13,7 @@ export default defineConfig({ '@zhst/func': path.join(__dirname, 'packages/func/src'), '@zhst/biz': path.join(__dirname, 'packages/biz/src'), '@zhst/meta': path.join(__dirname, 'packages/meta/src'), + '@zhst/request': path.join(__dirname, 'packages/request/src'), }, resolve: { docDirs: ['docs'], @@ -21,6 +22,9 @@ export default defineConfig({ { type: 'utils', dir: 'packages/func/src' }, { type: 'biz', dir: 'packages/biz/src' }, { type: 'meta', dir: 'packages/meta/src' }, + { type: 'request', dir: 'packages/request/src' }, + { type: 'constants', dir: 'packages/constants/src' }, + { type: 'types', dir: 'packages/types/src' }, ], }, monorepoRedirect: { diff --git a/docs/index.md b/docs/index.md index d5e9a0a..89c3fc3 100644 --- a/docs/index.md +++ b/docs/index.md @@ -20,6 +20,79 @@ features: description: 原子组件库 --- +## 目录结构 + + + + + ## 本文档食用说明 目前在开发中的项目为:@zhst/bizs、@zhst/hooks、@zhst/meta、@zhst/func。 diff --git a/packages/biz/package.json b/packages/biz/package.json index 75ab54b..856a801 100644 --- a/packages/biz/package.json +++ b/packages/biz/package.json @@ -15,7 +15,7 @@ "lib/**/style/*", "*.less" ], - "main": "lib/index.tsx", + "main": "lib/index.js", "module": "es/index.js", "typings": "es/index.d.ts", "exports": { @@ -32,6 +32,9 @@ "access": "public", "registry": "http://10.0.0.77:4874" }, + "devDependencies": { + "@zhst/types": "workspace:^" + }, "dependencies": { "@zhst/func": "workspace:^", "@zhst/hooks": "workspace:^", diff --git a/packages/biz/src/BigImageModal/index.less b/packages/biz/src/BigImageModal/index.less index b26c6c8..2253df2 100644 --- a/packages/biz/src/BigImageModal/index.less +++ b/packages/biz/src/BigImageModal/index.less @@ -67,256 +67,7 @@ margin-bottom: 24px; } } -.zhst-image__img-view { - position: relative; - width: calc(100% - 46px - 46px - 20px - 20px); - height: 100%; - margin: 0 66px; - &-opt { - position: absolute; - z-index: 99; - top: 0; - } - - &-crop-opt { - position: absolute; - z-index: 99; - top: 0; - right: 0; - } - - &-align { - position: absolute; - top: 0; - left: 0; - pointer-events: none; - } - - &-main { - // height: 532px; - width: 100%; - height: 100%; - - &--cursor { - & canvas { - cursor: pointer !important; - } - } - } - - &-screenshot { - position: absolute; - z-index: 10; - } - - &-attach { - position: absolute; - z-index: 11; - bottom: 0; - - // left: 78px; - left: 0; - min-width: 120px; - height: 202px; - transition: all 200ms; - - &--fixed { - width: 152px !important; - background-color: #fff; - } - - &--zoomin { - height: 532px; - - &--fixed { - width: 398px !important; - } - } - - &__tab { - position: absolute; - top: 0; - left: 0; - display: flex; - - &-item { - display: flex; - width: 30px; - height: 24px; - align-items: center; - justify-content: center; - background: #000; - color: #fff; - cursor: pointer; - font-size: 12px; - opacity: 0.5; - transition: all 200ms; - - &--select { - width: 48px; - height: 34px; - background: #09f; - opacity: 1; - } - } - } - - &__scale { - position: absolute; - top: 4px; - right: 4px; - display: flex; - width: 30px; - height: 30px; - align-items: center; - justify-content: center; - background: rgb(0 0 0 / 60%); - border-radius: 100%; - cursor: pointer; - line-height: 30px; - text-align: center; - } - - &__img { - height: 100%; - object-fit: contain; - - &--fixed { - width: 100%; - object-fit: contain; - } - } - } -} - -.zhst-image__video-view { - position: relative; - overflow: hidden; - width: 100%; - height: 532px; - background-color: #333; - - // &-flv { - // width: 85%; - // } - &-screenshot { - position: absolute; - z-index: 10; - } - - &-crop-container { - position: absolute; - top: 0; - right: 0; - bottom: 0; - left: 0; - } - - &-align { - position: absolute; - top: 0; - left: 0; - pointer-events: none; - } - - &-opt { - position: absolute; - z-index: 99; - bottom: 0; - display: flex; - width: 100%; - height: 32px; - box-sizing: border-box; - align-items: center; - padding: 0 12px; - background-color: rgb(0 0 0 / 80%); - line-height: 32px; - - &>div:first-child { - display: flex; - align-items: center; - margin-right: 12px; - } - - &>div:last-child { - display: flex; - align-items: center; - margin-left: 12px; - } - - &-range { - display: flex; - height: 32px; - flex: 1; - align-items: center; - line-height: 32px; - text-align: center; - - &>div:first-child { - flex: 1; - } - - &>div:last-child { - width: 100px; - margin-left: 8px; - color: #fff; - } - } - } - - &__player-mask { - position: absolute; - z-index: 99; - top: 0; - right: 0; - bottom: 0; - left: 0; - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - background-color: rgb(4 4 4 / 70%); - - &--bg { - z-index: 999; - background-color: rgb(4 4 4 / 100%); - } - - i { - cursor: pointer; - } - - &-title { - margin-top: 12px; - color: #fff; - text-align: center; - - & a { - color: #09f; - cursor: pointer; - text-decoration: underline; - } - } - } - - &__icon-wraper { - display: flex; - width: 80px; - height: 80px; - align-items: center; - justify-content: center; - background-color: rgb(255 255 255 / 10%); - border-radius: 50%; - cursor: pointer; - line-height: 80px; - text-align: center; - - // &:hover { - // background: #0099ff; - // } - } -} .zhst-image__tool { display: flex; @@ -553,57 +304,6 @@ } } -.zhst-image__btn-group { - // display: flex; - width: 30px; - box-shadow: 0 2px 6px 0 rgb(0 0 0 / 40%); - - &__item { - display: flex; - width: 30px; - height: 30px; - align-items: center; - justify-content: center; - background: #000; - - &>button { - padding: 0; - color: #fff; - - &:hover { - color: #09f; - } - - &:active { - color: #09f; - } - - &:focus { - color: #fff; - } - - &>span { - display: flex; - } - } - - &--active { - &>button { - color: #09f; - } - } - } - - &--circle { - background-color: none; - box-shadow: none; - } - - &--circle &__item { - margin-bottom: 4px; - border-radius: 50%; - } -} .zhst-image__compater-view { display: flex; @@ -962,78 +662,6 @@ } } -.zhst-image__score { - display: flex; - flex-direction: column; - align-items: center; - - &-box { - position: relative; - display: flex; - box-sizing: border-box; - align-items: center; - justify-content: center; - margin-bottom: 12px; - border-radius: 50%; - - &-bg { - display: flex; - overflow: hidden; - box-sizing: border-box; - align-items: flex-end; - justify-content: center; - border: 2px solid #fff; - background-color: #fff; - border-radius: 50%; - - &-inner { - width: 100% !important; - height: 0; - } - } - } - - &-score { - position: absolute; - top: 50%; - left: 50%; - color: rgb(0 0 0 / 88%); - font-size: 28px; - transform: translate(-50%, -50%); - } - - &-text { - width: 54px; - height: 24px; - color: rgb(0 0 0 / 88%); - font-size: 18px; - line-height: 24px; - } -} - -.zhst-image__CornerScore { - position: absolute; - right: 0; - bottom: 0; - width: 56px; - height: 22px; - line-height: 22px; - text-align: right; - vertical-align: bottom; - padding-right: 1px; - background-size: 100%; - background-image: url('./images/percent_background.png'); - z-index: 99; - - &>span { - padding-right: 6px; - line-height: 22px; - font-size: 12px; - vertical-align: middle; - color: rgba(255, 255, 255, 1); - } -} - .zhst-image__attributePanel { margin: 0 66px; background: #f6f6f6; diff --git a/packages/biz/src/adapter/BigImageModalAdapter/index.tsx b/packages/biz/src/adapter/BigImageModalAdapter/index.tsx index a499b78..3aa70ec 100644 --- a/packages/biz/src/adapter/BigImageModalAdapter/index.tsx +++ b/packages/biz/src/adapter/BigImageModalAdapter/index.tsx @@ -2,7 +2,7 @@ * 适配老的大屏组件数据格式传入 */ import React from 'react'; -import { AlgorithmVersionStr, HumanProperty, ObjectType, Rect, ViewOption, AlignType, IScreenshotButtonProp, ODRECT } from './interface' +import { AlgorithmVersionStr, HumanProperty, ObjectType, Rect, ViewOption, AlignType, IScreenshotButtonProp, ODRECT } from '@zhst/types' export type TAB_TYPE = 'COMPATER' | 'NORMAL' | 'TRACK'; export type MODEL_TYPE = 'VIDEO' | 'IMAGE'; diff --git a/packages/biz/src/adapter/BigImageModalAdapter/interface.d.ts b/packages/biz/src/adapter/BigImageModalAdapter/interface.d.ts deleted file mode 100644 index 6ba15d7..0000000 --- a/packages/biz/src/adapter/BigImageModalAdapter/interface.d.ts +++ /dev/null @@ -1,217 +0,0 @@ -export type CamerasStatusList = [string[], string[], string[]]; - -export type Rect = { x: number; y: number; w: number; h: number }; - -export type StatusList = { - taskOverview: any; - taskIndex: { - deviceId: string; - solutionId: string; - }; -}[]; - -export enum OperationType { - OPERATION_TYPE_UNKNOW, // 未知状态,传该值会报错 - OPERATION_TYPE_START, - OPERATION_TYPE_STOP -} - - -export enum AlgorithmVersion { - VERSION_MGN_BNN, // MGN+BNN算法 - VERSION_BNN_PRO, // BNNPRO算法 - VERSION_BNN_PRO_ATTR, // BNNPROATTR算法 - VERSION_BNN_PRO_ATTR_SCORE, // BNNPROATTR算法 - VERSION_FACE, // 人脸算法 - VERSION_HEAD, // 头肩算法 - VERSION_NON_MOTOR_VEHICLE, // 非机动车的算法 - VERSION_REID_HEAD_ATTR, // 形体头肩属性三种特征融合的算法 - VERSION_MOTOR_VEHICLE, // 机动车的算法 -} - -export enum AlgorithmVersionStr { - VERSION_MGN_BNN = 'VERSION_MGN_BNN', // MGN+BNN算法 - VERSION_BNN_PRO = 'VERSION_BNN_PRO', // BNNPRO算法 - VERSION_BNN_PRO_ATTR = 'VERSION_BNN_PRO_ATTR', // BNNPROATTR算法 - VERSION_BNN_PRO_ATTR_SCORE = 'VERSION_BNN_PRO_ATTR_SCORE', // BNNPROATTR算法 - VERSION_FACE = 'VERSION_FACE', // 人脸算法 - VERSION_HEAD = 'VERSION_HEAD', // 头肩算法 - VERSION_NON_MOTOR_VEHICLE = 'VERSION_NON_MOTOR_VEHICLE', // 非机动车的算法 - VERSION_REID_HEAD_ATTR = 'VERSION_REID_HEAD_ATTR', // 形体头肩属性三种特征融合的算法 - VERSION_MOTOR_VEHICLE = 'VERSION_MOTOR_VEHICLE', // 机动车的算法 -} - -类型枚举 -export enum ObjectType { - OBJECT_TYPE_NULL, - OBJECT_TYPE_PEDESTRAIN, - OBJECT_TYPE_BICYCLE, - OBJECT_TYPE_CAR, - OBJECT_TYPE_MOTORBIKE, - OBJECT_TYPE_AEROPLANE, - OBJECT_TYPE_BUS, - OBJECT_TYPE_TRAIN, - OBJECT_TYPE_TRUCK, - OBJECT_TYPE_MOTOR_RIDER, - OBJECT_TYPE_BIKE_RIDER, - OBJECT_TYPE_MAX, - OBJECT_TYPE_FACE = 101, -} - -// 性别 -export enum Gender { - GENDER_NONE = 'GENDER_NONE', - GENDER_MAN = 'GENDER_MAN', - GENDER_WOMAN = 'GENDER_WOMAN', -} - -// 年龄 -export enum Age { - AGE_ALL = 'AGE_ALL', - AGE_ZERO = 'AGE_ZERO', - AGE_OVERENGHTEEN = 'AGE_OVERENGHTEEN', - AGE_OVERSIXTY = 'AGE_OVERSIXTY', -} - -// 戴帽子状态 -export enum Hat { - HAT_ALL = 'HAT_ALL', - HAT_NONE = 'HAT_NONE', - HAT_OWNED = 'HAT_OWNED', -} - -// 颜色 -export enum Color { - COLOR_ALL = 'COLOR_ALL', - COLOR_BLACK = 'COLOR_BLACK', - COLOR_WHITE = 'COLOR_WHITE', - COLOR_GRAY = 'COLOR_GRAY', - COLOR_BROWN = 'COLOR_BROWN', - COLOR_PINK = 'COLOR_PINK', - COLOR_REDANDORANGE = 'COLOR_REDANDORANGE', - COLOR_YELLOW = 'COLOR_YELLOW', - COLOR_GREEN = 'COLOR_GREEN', - COLOR_BLUE = 'COLOR_BLUE', - COLOR_PURPLE = 'COLOR_PURPLE', -} - -// 背包 -export enum Package { - PACKAGE_ALL = 'PACKAGE_ALL', - PACKAGE_HANDBAG = 'PACKAGE_HANDBAG', - PACKAGE_BACKPACK = 'PACKAGE_BACKPACK', - PACKAGE_SHOULDERBAG = 'PACKAGE_SHOULDERBAG', - PACKAGE_OTHER = 'PACKAGE_OTHER', - PACKAGE_NONE = 'PACKAGE_NONE', -} - -// 行走模式 -export enum WalkPattern { - WALKPATTERN_ALL = 'WALKPATTERN_ALL', - WALKPATTERN_WALK = 'WALKPATTERN_WALK', - WALKPATTERN_RIDING = 'WALKPATTERN_RIDING', -} - -// 人类属性 -export interface HumanProperty { - age: Age; - downColor: Color; - gender: Gender; - hat: Hat; - package: Package; - upColor: Color; - walkPattern: WalkPattern; -} - -// 人类属性枚举 -export interface EnumHumanProperty { - Gender: typeof Gender; - Age: typeof Age; - Hat: typeof Hat; - Color: typeof Color; - Package: typeof Package; - WalkPattern: typeof WalkPattern; -} - -export interface IScreenshotButtonProp { - model: 'VIDEO' | 'IMAGE'; - getCropInfo: () => Promise; - setShowCrop: React.Dispatch>; - cropType: typeof cropType[number]; - selectAlgorithmVersion: number; -} - -export interface AlignType { - /** - * move point of source node to align with point of target node. - * Such as ['tr','cc'], align top right point of source node with center point of target node. - * Point can be 't'(top), 'b'(bottom), 'c'(center), 'l'(left), 'r'(right) */ - points?: AlignPoint[]; - /** - * offset source node by offset[0] in x and offset[1] in y. - * If offset contains percentage string value, it is relative to sourceNode region. - */ - offset?: number[]; - /** - * offset target node by offset[0] in x and offset[1] in y. - * If targetOffset contains percentage string value, it is relative to targetNode region. - */ - targetOffset?: number[]; - /** - * If adjustX field is true, will adjust source node in x direction if source node is invisible. - * If adjustY field is true, will adjust source node in y direction if source node is invisible. - */ - overflow?: { - adjustX?: boolean | number; - adjustY?: boolean | number; - }; - /** - * Whether use css right instead of left to position - */ - useCssRight?: boolean; - /** - * Whether use css bottom instead of top to position - */ - useCssBottom?: boolean; - /** - * Whether use css transform instead of left/top/right/bottom to position if browser supports. - * Defaults to false. - */ - useCssTransform?: boolean; - ignoreShake?: boolean; -} - -export type ODRECT = { - topleft: { - x: number; - y: number; - }; - width: number; - height: number; -}; - -export interface ViewOption { - /* 图片url */ - image?: string | HTMLImageElement; - - /* 缩放灵敏度(0,1],default: 0.1 */ - wheelZoomRatio?: number; - - /* - * 是否允许缩放 - * @default: true - */ - scaleAble?: boolean; - - /* - * 是否允许拖拽 - * @default: true - */ - dragAble?: boolean; - - /* - * fit scale 作为 最小缩放 - * @default: false - */ - fitScaleAsMinScale?: boolean; -} diff --git a/packages/biz/src/global.d.ts b/packages/constants/es/user/index.d.ts similarity index 100% rename from packages/biz/src/global.d.ts rename to packages/constants/es/user/index.d.ts diff --git a/packages/types/src/index.tsx b/packages/constants/es/user/index.js similarity index 100% rename from packages/types/src/index.tsx rename to packages/constants/es/user/index.js diff --git a/packages/constants/lib/user/index.d.ts b/packages/constants/lib/user/index.d.ts new file mode 100644 index 0000000..e69de29 diff --git a/packages/constants/lib/user/index.js b/packages/constants/lib/user/index.js new file mode 100644 index 0000000..e69de29 diff --git a/packages/constants/src/index.md b/packages/constants/src/index.md index 6ee14d4..ddf2e95 100644 --- a/packages/constants/src/index.md +++ b/packages/constants/src/index.md @@ -1,6 +1,6 @@ --- nav: - title: 业务组件 + title: 其它 order: 1 title: 快速上手 --- diff --git a/packages/constants/src/user/index.ts b/packages/constants/src/user/index.ts new file mode 100644 index 0000000..e69de29 diff --git a/packages/func/es/camera/constants.d.ts b/packages/func/es/camera/constants.d.ts deleted file mode 100644 index 0658bd8..0000000 --- a/packages/func/es/camera/constants.d.ts +++ /dev/null @@ -1,41 +0,0 @@ -/** - * 设备类型枚举 - */ -export declare const DeviceType: { - VMS: string; - DIR: string; - CAMERA: string; -}; -export declare const LOCAL_KEY = "local"; -export declare const DIRE_CONNECT_KEY = "direconnect"; -export declare const BOX_LIST_KEY = "boxlist"; -export declare enum VmsplatformOpt { - VMSPLATFORMOPT_ID = 0, - VMSPLATFORMOPT_PLATFORMNAME = 1, - VMSPLATFORMOPT_PLUGINNAME = 2, - VMSPLATFORMOPT_IP = 3, - VMSPLATFORMOPT_PORT = 4, - VMSPLATFORMOPT_USERNAME = 5, - VMSPLATFORMOPT_PASSWORD = 6 -} -export declare enum OPT { - OR = 0, - AND = 1, - ORNOT = 2, - ANDNOT = 3 -} -export declare enum DevicemanagerCameraType { - DEVICEMANAGER_CAMERA_TYPE_DEFAULT = 0, - DEVICEMANAGER_CAMERA_TYPE_NORMAL = 1, - DEVICEMANAGER_CAMERA_TYPE_1400 = 97, - DEVICEMANAGER_CAMERA_TYPE_DHGRABBER = 98, - DEVICEMANAGER_CAMERA_TYPE_HKGRABBER = 99, - DEVICEMANAGER_CAMERA_TYPE_LOCAL = 100 -} -export declare const BOX_DIRECONNECT_PLATFORM_FILTER: { - filtervmsplatformList: { - opt: OPT; - vmsplatformOpt: VmsplatformOpt; - value: string; - }[]; -}; diff --git a/packages/func/es/camera/index.d.ts b/packages/func/es/camera/index.d.ts deleted file mode 100644 index c47dcdd..0000000 --- a/packages/func/es/camera/index.d.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { DevicemanagerCameraType } from './constants'; -export declare const isFaceCamera: (type: DevicemanagerCameraType) => boolean; -/** - * - * @param value 传入的数据 可以是 item(camera/vms/dirs)/ deviceID - * @param isId - */ -export declare function getDeviceType(value: { - [x: string]: any; - id: any; -} | string): any; -/** - * 后端设备id/vmsid/dirid是三张表 合并在一起不保证唯一 前端生成唯一key - * @param id 设备id - * @param type 设备类型 - */ -export declare function deviceIDToDeviceKey(id: any, type: string, vmsId?: any): string; -/** - * 后端设备id/vmsid/dirid是三张表 合并在一起不保证唯一 前端生成唯一key - * @param item camera/vms/dirs - */ -export declare function deviceToDeviceKey(item: { - [x: string]: any; - id: any; -}): string; -/** - * 设备树key 转 后端设备原始id dirid是string/vms&camera 是number 和后端保持一致 - * @param deviceKey 设备树的id - */ -export declare function deviceKeyToDeviceId(deviceKey: { - split: (arg0: string) => [any, any]; -}): any; -export declare const getVmsIdByDeviceId: (key: string) => string; -/** - * 通过设备id或设备key在树里面找摄像头 - * @param ids cameraId - * @param deviceTree 树 - * @param type "id" | "key" - */ -export declare const findCamerasByInDeviceTree: (ids: never[] | undefined, deviceTree: any, type?: string) => any[]; diff --git a/packages/func/es/file/index.d.ts b/packages/func/es/file/index.d.ts deleted file mode 100644 index 09e2615..0000000 --- a/packages/func/es/file/index.d.ts +++ /dev/null @@ -1,61 +0,0 @@ -/** - * - * @param url 需要转为图片的链接 - * @returns 图片的 dom - */ -export declare const urlToImg: (url: string) => Promise; -export declare const base64DecodeImageKey: (base64ImgKey: string) => string; -/** - * 通过url获取图片的base64字符串 - * @param src 图片链接 - * @param outputFormat 图片格式 - * @returns base64 @string - */ -export declare const getBase64ByUrl: (src: string | URL, outputFormat?: string) => Promise; -/** - * 把文件转base64 - * @param file @file 文件 - * @returns @string - */ -export declare const fileToBase64: (file: any) => Promise; -/** - * - * @param image @file 图片文件 - * @param width @number 宽度 - * @param height @number 高度 - * @returns @string base64 - */ -export declare const getBase64Image: (image: any, width?: any, height?: any) => string; -/** - * 通过图片获取base64 - * @param src 图片地址 - * @returns @string - */ -export declare const getBase64ByImage: (src: string) => Promise; -/** - * url转base64 - * @param {String} url - url地址 - */ -export declare const urlToBase64V2: (url: string) => Promise; -/** - * base64转Blob - * @param {String} base64 - base64 - */ -export declare function base64toBlob(base64: string): Blob | undefined; -/** - * 图片集打包压缩下载 - * 1. url -> base64 -> blob - * 2. 将blob加入jsZip文件夹内,用file-saver保存 - * @param {Array<{url:string,name:string}>} imgDataList - * @param {string} zipName - */ -export declare const downloadPackageImages: (imgDataList: string | any[], zipName: string) => Promise; -export declare function getFileSize(size: number): string; -export declare const dataURLToBlob: (dataurl: string) => Blob; -/** - * key 转 http 链接 - * @param originImgkey 图片的值 ,可以是 base64 也可以是 http链接 - * @param host 图片的域值 - * @returns {string} - */ -export declare const generateImg: (imgKey: string, host?: string) => string; diff --git a/packages/func/es/file/index.js b/packages/func/es/file/index.js index 474136a..e495fba 100644 --- a/packages/func/es/file/index.js +++ b/packages/func/es/file/index.js @@ -343,4 +343,18 @@ export var generateImg = function generateImg(_imgKey) { imgUrl = ''; } return imgUrl; +}; + +/** + * 获取指定字符串后面的部分 + * @param imageKey v1_开头的字符串 + * @returns + */ +export var getImageKey = function getImageKey(imageKey, preFix) { + var splitIndex = preFix || 'v1_'; + if (imageKey.startsWith(splitIndex)) { + return window.atob(imageKey.split(splitIndex)[1]).replace('_', '/'); + } else { + return imageKey; + } }; \ No newline at end of file diff --git a/packages/func/es/index.d.ts b/packages/func/es/index.d.ts deleted file mode 100644 index b792dee..0000000 --- a/packages/func/es/index.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -export * from 'lodash-es'; -export * from './file'; -export * from './map'; -export * from './performance'; -export * from './string'; -export * from './number'; -export * from './time'; -export * from './utils'; -export * from './camera'; diff --git a/packages/func/es/index.js b/packages/func/es/index.js index 6267c03..598dbef 100644 --- a/packages/func/es/index.js +++ b/packages/func/es/index.js @@ -6,4 +6,5 @@ export * from "./string"; export * from "./number"; export * from "./time"; export * from "./utils"; -export * from "./camera"; \ No newline at end of file +export * from "./camera"; +export * from "./math"; \ No newline at end of file diff --git a/packages/func/es/map/index.d.ts b/packages/func/es/map/index.d.ts deleted file mode 100644 index 08fa4a2..0000000 --- a/packages/func/es/map/index.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * 获取经纬信息 - * @param lngLat 位置信息 - * @returns @object { long, lat } - */ -export declare const fixedLngLat: (lngLat?: string) => string; -export declare const transformLngLat: (lngLat?: string) => { - longitude: number; - latitude: number; -} | null; diff --git a/packages/func/es/math/index.js b/packages/func/es/math/index.js new file mode 100644 index 0000000..16da47f --- /dev/null +++ b/packages/func/es/math/index.js @@ -0,0 +1,413 @@ +var _ALGORITHM_VERSION; +function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } +function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; } +function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } +function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } +function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } +function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } +function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } +function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } +function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } +function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } +function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +import { cloneDeep, get, isNull, isString } from 'lodash-es'; +import { dataURLToBlob, generateImg, urlToImg } from "../file"; +var proto = { + Common: { + AlgorithmVersion: { + VERSION_REID_HEAD_ATTR: '形体', + VERSION_FACE: '人脸', + VERSION_NON_MOTOR_VEHICLE: '非机动车' + } + } +}; +export var ALGORITHM_VERSION = (_ALGORITHM_VERSION = {}, _defineProperty(_ALGORITHM_VERSION, '7', '形体'), _defineProperty(_ALGORITHM_VERSION, '4', '人脸'), _defineProperty(_ALGORITHM_VERSION, '6', '非机动车'), _ALGORITHM_VERSION); +export var algorithmVersions = _toConsumableArray(Object.keys(ALGORITHM_VERSION)); +export var getBikeExtendRect = function getBikeExtendRect(rect, maxW) { + var newRect = _objectSpread({}, rect); + //向上扩大一倍 + var oldY = cloneDeep(rect.y); + newRect.y = newRect.y - newRect.h < 0 ? 0 : newRect.y - newRect.h; + newRect.h += oldY - newRect.y; + var newX = Math.round(newRect.x - newRect.w * 0.15); + if (newX < 0) { + newX = 0; + } + var newW = newRect.x - newX + newRect.w + Math.round(newRect.w * 0.15); + if (newX + newW > maxW) { + newW = maxW - newX; + } + newRect.x = newX; + newRect.w = newW; + return newRect; +}; +export var getOtherExtendRect = function getOtherExtendRect(srcRect, maxW, maxH, type) { + var wExtendRadio = 0.25; + var upExtendRadio = 0.25; + var downExtendRadio = 0.25; + var fixPersonExtend = true; + var nx = 0; + var nw = 0; + nx = srcRect.x - Math.round(srcRect.w * wExtendRadio); + if (nx < 0) { + nx = 0; + } + nw = srcRect.x - nx + srcRect.w + Math.round(srcRect.w * wExtendRadio); + if (nx + nw > maxW) { + nw = maxW - nx; + } + var ny = 0; + var nh = 0; + ny = srcRect.y - Math.round(upExtendRadio * srcRect.h); + if (ny < 0) { + ny = 0; + } + nh = srcRect.y - ny + srcRect.h + Math.round(srcRect.h * downExtendRadio); + if (ny + nh > maxH) { + nh = maxH - ny; + } + var newRect = { + x: nx, + y: ny, + w: nw, + h: nh + }; + if ((type === proto.Common.AlgorithmVersion.VERSION_REID_HEAD_ATTR || type === proto.Common.AlgorithmVersion.VERSION_FACE) && fixPersonExtend) { + var fixW = Math.round(nh * 0.75); + if (nw < fixW) { + // 应该扩展宽度 + var newX = nx + Math.round(nw / 2.0 - 0.5 * fixW); + if (newX < 0) { + newX = 0; + } + var newW = fixW; + if (newW + newX > maxW) { + newW = maxW - newX; + } + newRect = { + x: newX, + y: ny, + w: newW, + h: nh + }; + } else if (nw > fixW) { + // 应该扩展高度 + var fixH = Math.round(nw * 1.333); + var newY = ny + Math.round(nh / 2.0 - 0.5 * fixH); + if (newY < 0) { + newY = 0; + } + var newH = fixH; + if (newY + newH > maxH) { + newH = maxH - newY; + } + newRect = { + x: nx, + y: newY, + w: nw, + h: newH + }; + } + } + return newRect; +}; +export var getNormalization = function getNormalization(srcRect, maxW, maxH) { + var newRect = _objectSpread({}, srcRect); + newRect.x = srcRect.x / maxW; + newRect.y = srcRect.y / maxH; + newRect.w = srcRect.w / maxW; + newRect.h = srcRect.h / maxH; + if (newRect.x + newRect.w > 1) { + newRect.w = 1 - newRect.x; + } + if (newRect.y + newRect.h > 1) { + newRect.h = 1 - newRect.y; + } + return newRect; +}; +//传入od框 穿出 od扩展框 +export var getExtendRect = function getExtendRect(normalizationRect, imgW, imgH, type) { + var rect = { + x: normalizationRect.x * imgW, + y: normalizationRect.y * imgH, + w: normalizationRect.w * imgW, + h: normalizationRect.h * imgH + }; + var newRect; + if (type === proto.Common.AlgorithmVersion.VERSION_NON_MOTOR_VEHICLE) { + newRect = getBikeExtendRect(rect, imgW); + } else { + newRect = getOtherExtendRect(rect, imgW, imgH, type); + } + newRect = getNormalization(newRect, imgW, imgH); + return newRect; +}; +export var getTransformRect = function getTransformRect(image, transform, rect) { + var canvasRect = { + x: rect.x, + y: rect.y, + x2: rect.x + rect.w, + y2: rect.h + rect.y + }; + //1.转成缩放前的坐标 + var translateX = transform.translateX, + translateY = transform.translateY, + scale = transform.scale, + rotate = transform.rotate; + var originAxisRect = { + x: (canvasRect.x - translateX) / scale, + y: (canvasRect.y - translateY) / scale, + x2: (canvasRect.x2 - translateX) / scale, + y2: (canvasRect.y2 - translateY) / scale + }; + //2.转成图片坐标 + //不考虑旋转 图片原点就是坐标原点 + var imgAxisRect = originAxisRect; + //但是旋转90度后图片不在坐标原点 加上这部分diff + if (rotate % 180 !== 0) { + //90度调整偏移量 + var offsetX = -(image.height - image.width) / 2; + var offsetY = -(image.width - image.height) / 2; + imgAxisRect = { + x: originAxisRect.x - offsetX, + y: originAxisRect.y - offsetY, + x2: originAxisRect.x2 - offsetX, + y2: originAxisRect.y2 - offsetY + }; + } + //3.限制框不要超出图片 + var imgW = image.width; + var imgH = image.height; + if (rotate % 180 !== 0) { + var _ref = [imgH, imgW]; + imgW = _ref[0]; + imgH = _ref[1]; + } + imgAxisRect.x = Math.min(imgW, Math.max(imgAxisRect.x, 0)); + imgAxisRect.y = Math.min(imgH, Math.max(imgAxisRect.y, 0)); + imgAxisRect.x2 = Math.min(imgW, Math.max(imgAxisRect.x2, 0)); + imgAxisRect.y2 = Math.min(imgH, Math.max(imgAxisRect.y2, 0)); + //获取归一化坐标 + var endRect = { + x: imgAxisRect.x2 > imgAxisRect.x ? imgAxisRect.x : imgAxisRect.x2, + y: imgAxisRect.y2 > imgAxisRect.y ? imgAxisRect.y : imgAxisRect.y2, + w: Math.abs(imgAxisRect.x2 - imgAxisRect.x), + h: Math.abs(imgAxisRect.y2 - imgAxisRect.y) + }; + return getNormalization(endRect, imgW, imgH); +}; + +//旋转图片后转成file 对象 +export var getRotateImg = function getRotateImg(image, rotate) { + var _commonCanvas$parentN; + var imgW = image.width; + var imgH = image.height; + if (rotate % 180 !== 0) { + var _ref2 = [imgH, imgW]; + imgW = _ref2[0]; + imgH = _ref2[1]; + } + var commonCanvas = document.createElement('canvas'); + commonCanvas.width = imgW; + commonCanvas.height = imgH; + commonCanvas.style.display = 'none'; + document.body.appendChild(commonCanvas); + var commonCtx = commonCanvas.getContext('2d'); + //移动到图片中心 旋转 + + commonCtx === null || commonCtx === void 0 || commonCtx.save(); + if (rotate % 180 !== 0) { + //90度调整偏移量 + commonCtx === null || commonCtx === void 0 || commonCtx.translate((image.height - image.width) / 2, (image.width - image.height) / 2); + } + commonCtx === null || commonCtx === void 0 || commonCtx.translate(image.width / 2, image.height / 2); + commonCtx === null || commonCtx === void 0 || commonCtx.rotate(rotate / 180 * Math.PI); + commonCtx === null || commonCtx === void 0 || commonCtx.translate(-image.width / 2, -image.height / 2); + commonCtx === null || commonCtx === void 0 || commonCtx.drawImage(image, 0, 0); + commonCtx === null || commonCtx === void 0 || commonCtx.restore(); + var dataUrl = commonCanvas.toDataURL('image/jpeg'); + var blobData = dataURLToBlob(dataUrl); + var file = new window.File([blobData], "".concat(new Date().getTime()), { + type: 'image/jpeg' + }); + (_commonCanvas$parentN = commonCanvas.parentNode) === null || _commonCanvas$parentN === void 0 || _commonCanvas$parentN.removeChild(commonCanvas); + return file; +}; + +/** + * + * @param originData + * @returns + */ +export var getOdRect = function getOdRect(originData) { + var data = get(originData, 'objects', []).filter(function (v) { + return !isNull(get(v, 'infoOnSource.bboxInFrame.bboxRatio')); + }).map(function (v, index) { + // objectId==0 特征没有提取到过滤1掉 + var rect = get(v, 'infoOnSource.bboxInFrame.bboxRatio'); + var extendBox = get(v, 'infoOnSource.bboxInFrame.extendBoxRatio'); + var frameTimestamp = get(v, 'timestamp'); //时间戳创建档案的时候需要 + var qualityScore = get(v, 'qualityScore'); + var algorithmVersion = get(v, 'objectType') === 'OBJECT_TYPE_PEDESTRAIN' ? 'VERSION_REID_HEAD_ATTR' : get(v, 'objectType') === 'OBJECT_TYPE_FACE' ? 'VERSION_FACE' : 'VERSION_REID_HEAD_ATTR'; + var featureData = get(v, 'feature', []).filter(function (v) { + return v.type === 'FEATURE_TYPE_BYTE'; + }); + var objectRectIndex = algorithmVersion === 'VERSION_FACE' ? 0 : 1; + var objectType = get(v, 'objectType'); + var objectId = get(v, 'objectIndex.objectId'); + var sourceObjectId = get(v, 'sourceObjectId'); + return { + x: rect.x, + y: rect.y, + w: rect.w, + h: rect.h, + // faceCorrectImage: faceCorrectImage, + id: index, + qualityScore: qualityScore, + algorithmVersion: algorithmVersion, + featureData: get(featureData, '0.featureByte'), + objectRectIndex: objectRectIndex, + objectType: objectType, + objectId: objectId, + frameTimestamp: frameTimestamp, + sourceObjectId: sourceObjectId, + extendBox: extendBox + }; + }); + if (data.length > 0) { + data = data.filter(function (v) { + return v.objectId !== '0'; + }); + } else { + throw new Error('empty'); + } + return data; +}; + +//档案库od +export var getOdRectV2 = function getOdRectV2(originData) { + // const fileKey = 'v1_' + window.btoa('public_' + imgKey.split('public/')[1]); + var resp = originData.odv2Result[0]; + var subObjects = []; //形体 + var data = get(resp, 'objects', []).filter(function (v) { + return !isNull(get(v, 'subObjects[0].infoOnSource.bboxInFrame.bboxRatio')); + }).map(function (v, index) { + var rect = get(v, 'infoOnSource.bboxInFrame.bboxRatio'); + var qualityScore = get(v, 'qualityScore'); + var algorithmVersion = get(v, 'objectType'); + var featrueData = get(v, 'feature', []).filter(function (v) { + return v.name === 'feature-body' || v.name === 'feature-face'; + }); + var objectRectIndex = algorithmVersion === 'OBJECT_TYPE_FACE' ? 0 : 1; + var objectType = get(v, 'objectType'); + var objectId = get(v, 'objectIndex.objectId'); + //如果存在subObjects的数组不为null表示形体里面带人脸,人脸的od框也要显示出来 + if (get(v, 'subObjects', []).length) { + get(v, 'subObjects', []).forEach(function (e) { + var rect = get(e, 'infoOnSource.bboxInFrame.bboxRatio'); + var qualityScore = get(e, 'qualityScore'); + var algorithmVersion = get(e, 'objectType'); + var featrueData = get(e, 'feature', []).filter(function (v) { + return v.name === 'feature-body' || v.name === 'feature-face'; + }); + var objectRectIndex = algorithmVersion === 'OBJECT_TYPE_FACE' ? 0 : 1; + var objectType = get(e, 'objectType'); + var objectId = get(e, 'objectIndex.objectId'); + subObjects.push({ + x: rect.x, + y: rect.y, + w: rect.w, + h: rect.h, + id: index, + qualityScore: qualityScore, + algorithmVersion: algorithmVersion, + featrueData: featrueData.length ? featrueData[0].featureByte : '', + objectRectIndex: objectRectIndex, + objectType: objectType, + objectId: objectId + }); + }); + } + return { + x: rect.x, + y: rect.y, + w: rect.w, + h: rect.h, + id: index, + qualityScore: qualityScore, + algorithmVersion: algorithmVersion, + featrueData: featrueData[0].featureByte, + objectRectIndex: objectRectIndex, + objectType: objectType, + objectId: objectId + }; + }); + var brr = data.concat(subObjects).map(function (v, vs) { + if (String(v.id)) { + v.id = vs; + } + return v; + }); + if (brr.length > 0) { + console.log(brr, 'data111'); + } else { + throw new Error('empty'); + } + console.log(brr); + return brr; +}; + +//获取图片 + +export var getFileByRect = /*#__PURE__*/function () { + var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(img, odRect) { + var _commonCanvas$parentN2; + var image, url, commonCanvas, commonCtx, base64, blobData, file; + return _regeneratorRuntime().wrap(function _callee$(_context) { + while (1) switch (_context.prev = _context.next) { + case 0: + if (!isString(img)) { + _context.next = 9; + break; + } + url = generateImg(img); + console.log(url, '获取图片'); + _context.next = 5; + return urlToImg(url); + case 5: + image = _context.sent; + console.log(image, '获取的图片'); + _context.next = 10; + break; + case 9: + image = img; + case 10: + commonCanvas = document.createElement('canvas'); + commonCanvas.width = odRect.w * image.width; + commonCanvas.height = odRect.h * image.height; + commonCanvas.style.display = 'none'; + document.body.appendChild(commonCanvas); + commonCtx = commonCanvas.getContext('2d'); + commonCtx === null || commonCtx === void 0 || commonCtx.translate(-odRect.x * image.width, -odRect.y * image.height); + commonCtx === null || commonCtx === void 0 || commonCtx.drawImage(image, 0, 0); + base64 = commonCanvas.toDataURL('image/jpeg'); + blobData = dataURLToBlob(base64); + commonCanvas === null || commonCanvas === void 0 || (_commonCanvas$parentN2 = commonCanvas.parentNode) === null || _commonCanvas$parentN2 === void 0 || _commonCanvas$parentN2.removeChild(commonCanvas); + file = new window.File([blobData], "".concat(new Date().getTime()), { + type: 'image/jpeg' + }); + return _context.abrupt("return", file); + case 23: + case "end": + return _context.stop(); + } + }, _callee); + })); + return function getFileByRect(_x, _x2) { + return _ref3.apply(this, arguments); + }; +}(); \ No newline at end of file diff --git a/packages/func/es/number/index.d.ts b/packages/func/es/number/index.d.ts deleted file mode 100644 index 704d582..0000000 --- a/packages/func/es/number/index.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * 设置数据的精度 - * @param originNumber - * @param accuracy 精度 以原点为中心向左为正,向右为负, - * @param isCeil 是否为向上取整 - * @returns number - */ -export declare const setNumberAccuracy: (originNumber: number, accuracy?: number, isCeil?: boolean) => number; diff --git a/packages/func/es/performance/index.d.ts b/packages/func/es/performance/index.d.ts deleted file mode 100644 index 22dd838..0000000 --- a/packages/func/es/performance/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare const speedConvert: (bps: number, contertUnit?: number) => string; diff --git a/packages/func/es/string/index.d.ts b/packages/func/es/string/index.d.ts deleted file mode 100644 index a209796..0000000 --- a/packages/func/es/string/index.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -export declare const getStrLength: (str: string) => number; -/** - * js截取字符串,中英文都能用 - * @param str:需要截取的字符串 - * @param len: 需要截取的长度 - */ -export declare const cutStr: (str: string, len: number) => string | String | undefined; diff --git a/packages/func/es/time/index.d.ts b/packages/func/es/time/index.d.ts deleted file mode 100644 index b96cf6c..0000000 --- a/packages/func/es/time/index.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -export declare const formateDuration: (diff: number) => string; -export declare function generateTime(): { - startDateTime: number; - endDateTime: number; -}; diff --git a/packages/func/es/upload/index.js b/packages/func/es/upload/index.js new file mode 100644 index 0000000..6157f92 --- /dev/null +++ b/packages/func/es/upload/index.js @@ -0,0 +1,117 @@ +function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } +function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; } +function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } +function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } +import dayjs from "dayjs"; +import { getFileSuffix, getImageSuffixByFileType } from "../utils"; +import base64 from "base-64"; +import { v4 as uuidV4 } from 'uuid'; +import { get } from "lodash-es"; + +//小文件上传走s3 +var defaultBucket = 'public'; +export var commonUpload = /*#__PURE__*/function () { + var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(file) { + var option, + type, + _option$bucket, + bucket, + _option$dir, + dir, + _option$withSuFuffix, + withSuFuffix, + prefix, + fileSuffix, + fileType, + imageSuffix, + key, + imgKey, + _args2 = arguments; + return _regeneratorRuntime().wrap(function _callee2$(_context2) { + while (1) switch (_context2.prev = _context2.next) { + case 0: + option = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {}; + type = _args2.length > 2 ? _args2[2] : undefined; + _option$bucket = option.bucket, bucket = _option$bucket === void 0 ? defaultBucket : _option$bucket, _option$dir = option.dir, dir = _option$dir === void 0 ? 'file' : _option$dir, _option$withSuFuffix = option.withSuFuffix, withSuFuffix = _option$withSuFuffix === void 0 ? false : _option$withSuFuffix; + prefix = "".concat(dayjs().format('YYYYMMDD')); + fileSuffix = withSuFuffix ? getFileSuffix(get(file, 'name')) : ''; + fileType = file['type'].split('/', 2); + imageSuffix = ''; + if (fileType['0'] === 'image') { + imageSuffix = getImageSuffixByFileType(fileType['1']); + } + key = "".concat(prefix, "/").concat(dir ? "".concat(dir, "/") : '').concat(uuidV4()).concat(!fileSuffix ? '' : ".".concat(fileSuffix)); + imgKey = "".concat(bucket, "_").concat(bucket, "_").concat(key).concat(imageSuffix); //后端约定 见https://docs.qq.com/doc/DUklodHNxUGl2U3NM》 + if (!(type === 'upload')) { + _context2.next = 13; + break; + } + imgKey = "v1_".concat(base64.encode(imgKey)); + return _context2.abrupt("return", new Promise(function (resolve) { + var reader = new FileReader(); + reader.readAsDataURL(file); + reader.onload = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() { + var _reader$result; + return _regeneratorRuntime().wrap(function _callee$(_context) { + while (1) switch (_context.prev = _context.next) { + case 0: + if (!reader.result) { + _context.next = 4; + break; + } + _context.next = 3; + return doRequest({ + method: 'PUT', + url: '/singer.FileServerService/PutObject', + data: { + version: 1, + bucket: defaultBucket, + objectName: "".concat(bucket, "_").concat(key).concat(imageSuffix), + // fileData: reader.result, + putObjectOption: { + contentType: file.type + }, + fileDataBase64: (_reader$result = reader.result) === null || _reader$result === void 0 ? void 0 : _reader$result.split(';base64,')[1] + } + }); + case 3: + resolve(imgKey); + case 4: + case "end": + return _context.stop(); + } + }, _callee); + })); + })); + case 13: + case "end": + return _context2.stop(); + } + }, _callee2); + })); + return function commonUpload(_x) { + return _ref.apply(this, arguments); + }; +}(); +export var upload = /*#__PURE__*/function () { + var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(file) { + var option, + _args3 = arguments; + return _regeneratorRuntime().wrap(function _callee3$(_context3) { + while (1) switch (_context3.prev = _context3.next) { + case 0: + option = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {}; + _context3.next = 3; + return commonUpload(file, option, 'upload'); + case 3: + return _context3.abrupt("return", _context3.sent); + case 4: + case "end": + return _context3.stop(); + } + }, _callee3); + })); + return function upload(_x2) { + return _ref3.apply(this, arguments); + }; +}(); \ No newline at end of file diff --git a/packages/func/es/utils/index.d.ts b/packages/func/es/utils/index.d.ts deleted file mode 100644 index 2ae2b65..0000000 --- a/packages/func/es/utils/index.d.ts +++ /dev/null @@ -1,20 +0,0 @@ -export { default as isChrome } from './isChrome'; -export declare const matchS3Prefix: (str: string) => boolean; -/** - * 通过文件名获取文件类型 - * @param fileName 文件名称 - * @returns 文件类型 - */ -export declare const getFileSuffix: (fileName: string) => string; -/** - * 通过类型获取文件名 - * @param type 类型 - * @returns - */ -export declare const getImageSuffixByFileType: (type: string) => string; -export declare function getChromeVersion(): number | false; -export declare const nextTick: (func: (value: void) => void | PromiseLike) => void; -export declare const loop: (items: string | any[], callback: (arg0: any) => any) => void; -export declare const addEventListener: (target: any, eventType: string, cb: any, option?: any) => { - remove: () => void; -}; diff --git a/packages/func/es/utils/index.js b/packages/func/es/utils/index.js index 6a087d6..4316375 100644 --- a/packages/func/es/utils/index.js +++ b/packages/func/es/utils/index.js @@ -1,3 +1,4 @@ +import { isNumber } from 'lodash-es'; import ReactDOM from 'react-dom'; export { default as isChrome } from "./isChrome"; export var matchS3Prefix = function matchS3Prefix(str) { @@ -103,4 +104,41 @@ export var addEventListener = function addEventListener(target, eventType, cb, o } } }; -}; \ No newline at end of file +}; + +/** + * Get transforms base on the given object. + * @param {Object} obj - The target object. + * @returns {string} A string contains transform values. + */ +export function getTransforms(_ref) { + var rotate = _ref.rotate, + scaleX = _ref.scaleX, + scaleY = _ref.scaleY, + translateX = _ref.translateX, + translateY = _ref.translateY; + var values = []; + if (isNumber(translateX) && translateX !== 0) { + values.push("translateX(".concat(translateX, "px)")); + } + if (isNumber(translateY) && translateY !== 0) { + values.push("translateY(".concat(translateY, "px)")); + } + + // Rotate should come first before scale to match orientation transform + if (isNumber(rotate) && rotate !== 0) { + values.push("rotate(".concat(rotate, "deg)")); + } + if (isNumber(scaleX) && scaleX !== 1) { + values.push("scaleX(".concat(scaleX, ")")); + } + if (isNumber(scaleY) && scaleY !== 1) { + values.push("scaleY(".concat(scaleY, ")")); + } + var transform = values.length ? values.join(' ') : 'none'; + return { + WebkitTransform: transform, + msTransform: transform, + transform: transform + }; +} \ No newline at end of file diff --git a/packages/func/es/utils/isChrome.d.ts b/packages/func/es/utils/isChrome.d.ts deleted file mode 100644 index 2d07ceb..0000000 --- a/packages/func/es/utils/isChrome.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export declare const isBrowser: boolean; -declare const isChrome: () => boolean; -export default isChrome; diff --git a/packages/func/lib/camera/constants.d.ts b/packages/func/lib/camera/constants.d.ts deleted file mode 100644 index 0658bd8..0000000 --- a/packages/func/lib/camera/constants.d.ts +++ /dev/null @@ -1,41 +0,0 @@ -/** - * 设备类型枚举 - */ -export declare const DeviceType: { - VMS: string; - DIR: string; - CAMERA: string; -}; -export declare const LOCAL_KEY = "local"; -export declare const DIRE_CONNECT_KEY = "direconnect"; -export declare const BOX_LIST_KEY = "boxlist"; -export declare enum VmsplatformOpt { - VMSPLATFORMOPT_ID = 0, - VMSPLATFORMOPT_PLATFORMNAME = 1, - VMSPLATFORMOPT_PLUGINNAME = 2, - VMSPLATFORMOPT_IP = 3, - VMSPLATFORMOPT_PORT = 4, - VMSPLATFORMOPT_USERNAME = 5, - VMSPLATFORMOPT_PASSWORD = 6 -} -export declare enum OPT { - OR = 0, - AND = 1, - ORNOT = 2, - ANDNOT = 3 -} -export declare enum DevicemanagerCameraType { - DEVICEMANAGER_CAMERA_TYPE_DEFAULT = 0, - DEVICEMANAGER_CAMERA_TYPE_NORMAL = 1, - DEVICEMANAGER_CAMERA_TYPE_1400 = 97, - DEVICEMANAGER_CAMERA_TYPE_DHGRABBER = 98, - DEVICEMANAGER_CAMERA_TYPE_HKGRABBER = 99, - DEVICEMANAGER_CAMERA_TYPE_LOCAL = 100 -} -export declare const BOX_DIRECONNECT_PLATFORM_FILTER: { - filtervmsplatformList: { - opt: OPT; - vmsplatformOpt: VmsplatformOpt; - value: string; - }[]; -}; diff --git a/packages/func/lib/camera/constants.js b/packages/func/lib/camera/constants.js deleted file mode 100644 index efd28fa..0000000 --- a/packages/func/lib/camera/constants.js +++ /dev/null @@ -1,90 +0,0 @@ -var __defProp = Object.defineProperty; -var __getOwnPropDesc = Object.getOwnPropertyDescriptor; -var __getOwnPropNames = Object.getOwnPropertyNames; -var __hasOwnProp = Object.prototype.hasOwnProperty; -var __export = (target, all) => { - for (var name in all) - __defProp(target, name, { get: all[name], enumerable: true }); -}; -var __copyProps = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames(from)) - if (!__hasOwnProp.call(to, key) && key !== except) - __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); - } - return to; -}; -var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); - -// src/camera/constants.ts -var constants_exports = {}; -__export(constants_exports, { - BOX_DIRECONNECT_PLATFORM_FILTER: () => BOX_DIRECONNECT_PLATFORM_FILTER, - BOX_LIST_KEY: () => BOX_LIST_KEY, - DIRE_CONNECT_KEY: () => DIRE_CONNECT_KEY, - DeviceType: () => DeviceType, - DevicemanagerCameraType: () => DevicemanagerCameraType, - LOCAL_KEY: () => LOCAL_KEY, - OPT: () => OPT, - VmsplatformOpt: () => VmsplatformOpt -}); -module.exports = __toCommonJS(constants_exports); -var DeviceType = { - VMS: "vms", - DIR: "dir", - CAMERA: "camera" -}; -var LOCAL_KEY = "local"; -var DIRE_CONNECT_KEY = "direconnect"; -var BOX_LIST_KEY = "boxlist"; -var VmsplatformOpt = /* @__PURE__ */ ((VmsplatformOpt2) => { - VmsplatformOpt2[VmsplatformOpt2["VMSPLATFORMOPT_ID"] = 0] = "VMSPLATFORMOPT_ID"; - VmsplatformOpt2[VmsplatformOpt2["VMSPLATFORMOPT_PLATFORMNAME"] = 1] = "VMSPLATFORMOPT_PLATFORMNAME"; - VmsplatformOpt2[VmsplatformOpt2["VMSPLATFORMOPT_PLUGINNAME"] = 2] = "VMSPLATFORMOPT_PLUGINNAME"; - VmsplatformOpt2[VmsplatformOpt2["VMSPLATFORMOPT_IP"] = 3] = "VMSPLATFORMOPT_IP"; - VmsplatformOpt2[VmsplatformOpt2["VMSPLATFORMOPT_PORT"] = 4] = "VMSPLATFORMOPT_PORT"; - VmsplatformOpt2[VmsplatformOpt2["VMSPLATFORMOPT_USERNAME"] = 5] = "VMSPLATFORMOPT_USERNAME"; - VmsplatformOpt2[VmsplatformOpt2["VMSPLATFORMOPT_PASSWORD"] = 6] = "VMSPLATFORMOPT_PASSWORD"; - return VmsplatformOpt2; -})(VmsplatformOpt || {}); -var OPT = /* @__PURE__ */ ((OPT2) => { - OPT2[OPT2["OR"] = 0] = "OR"; - OPT2[OPT2["AND"] = 1] = "AND"; - OPT2[OPT2["ORNOT"] = 2] = "ORNOT"; - OPT2[OPT2["ANDNOT"] = 3] = "ANDNOT"; - return OPT2; -})(OPT || {}); -var DevicemanagerCameraType = /* @__PURE__ */ ((DevicemanagerCameraType2) => { - DevicemanagerCameraType2[DevicemanagerCameraType2["DEVICEMANAGER_CAMERA_TYPE_DEFAULT"] = 0] = "DEVICEMANAGER_CAMERA_TYPE_DEFAULT"; - DevicemanagerCameraType2[DevicemanagerCameraType2["DEVICEMANAGER_CAMERA_TYPE_NORMAL"] = 1] = "DEVICEMANAGER_CAMERA_TYPE_NORMAL"; - DevicemanagerCameraType2[DevicemanagerCameraType2["DEVICEMANAGER_CAMERA_TYPE_1400"] = 97] = "DEVICEMANAGER_CAMERA_TYPE_1400"; - DevicemanagerCameraType2[DevicemanagerCameraType2["DEVICEMANAGER_CAMERA_TYPE_DHGRABBER"] = 98] = "DEVICEMANAGER_CAMERA_TYPE_DHGRABBER"; - DevicemanagerCameraType2[DevicemanagerCameraType2["DEVICEMANAGER_CAMERA_TYPE_HKGRABBER"] = 99] = "DEVICEMANAGER_CAMERA_TYPE_HKGRABBER"; - DevicemanagerCameraType2[DevicemanagerCameraType2["DEVICEMANAGER_CAMERA_TYPE_LOCAL"] = 100] = "DEVICEMANAGER_CAMERA_TYPE_LOCAL"; - return DevicemanagerCameraType2; -})(DevicemanagerCameraType || {}); -var BOX_DIRECONNECT_PLATFORM_FILTER = { - filtervmsplatformList: [ - { - opt: 0 /* OR */, - vmsplatformOpt: 1 /* VMSPLATFORMOPT_PLATFORMNAME */, - value: "direconnect" - }, - { - opt: 0 /* OR */, - vmsplatformOpt: 1 /* VMSPLATFORMOPT_PLATFORMNAME */, - value: "boxlist" - } - ] -}; -// Annotate the CommonJS export names for ESM import in node: -0 && (module.exports = { - BOX_DIRECONNECT_PLATFORM_FILTER, - BOX_LIST_KEY, - DIRE_CONNECT_KEY, - DeviceType, - DevicemanagerCameraType, - LOCAL_KEY, - OPT, - VmsplatformOpt -}); diff --git a/packages/func/lib/camera/index.d.ts b/packages/func/lib/camera/index.d.ts deleted file mode 100644 index c47dcdd..0000000 --- a/packages/func/lib/camera/index.d.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { DevicemanagerCameraType } from './constants'; -export declare const isFaceCamera: (type: DevicemanagerCameraType) => boolean; -/** - * - * @param value 传入的数据 可以是 item(camera/vms/dirs)/ deviceID - * @param isId - */ -export declare function getDeviceType(value: { - [x: string]: any; - id: any; -} | string): any; -/** - * 后端设备id/vmsid/dirid是三张表 合并在一起不保证唯一 前端生成唯一key - * @param id 设备id - * @param type 设备类型 - */ -export declare function deviceIDToDeviceKey(id: any, type: string, vmsId?: any): string; -/** - * 后端设备id/vmsid/dirid是三张表 合并在一起不保证唯一 前端生成唯一key - * @param item camera/vms/dirs - */ -export declare function deviceToDeviceKey(item: { - [x: string]: any; - id: any; -}): string; -/** - * 设备树key 转 后端设备原始id dirid是string/vms&camera 是number 和后端保持一致 - * @param deviceKey 设备树的id - */ -export declare function deviceKeyToDeviceId(deviceKey: { - split: (arg0: string) => [any, any]; -}): any; -export declare const getVmsIdByDeviceId: (key: string) => string; -/** - * 通过设备id或设备key在树里面找摄像头 - * @param ids cameraId - * @param deviceTree 树 - * @param type "id" | "key" - */ -export declare const findCamerasByInDeviceTree: (ids: never[] | undefined, deviceTree: any, type?: string) => any[]; diff --git a/packages/func/lib/camera/index.js b/packages/func/lib/camera/index.js deleted file mode 100644 index b7ae6f1..0000000 --- a/packages/func/lib/camera/index.js +++ /dev/null @@ -1,143 +0,0 @@ -var __defProp = Object.defineProperty; -var __getOwnPropDesc = Object.getOwnPropertyDescriptor; -var __getOwnPropNames = Object.getOwnPropertyNames; -var __hasOwnProp = Object.prototype.hasOwnProperty; -var __export = (target, all) => { - for (var name in all) - __defProp(target, name, { get: all[name], enumerable: true }); -}; -var __copyProps = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames(from)) - if (!__hasOwnProp.call(to, key) && key !== except) - __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); - } - return to; -}; -var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); - -// src/camera/index.ts -var camera_exports = {}; -__export(camera_exports, { - deviceIDToDeviceKey: () => deviceIDToDeviceKey, - deviceKeyToDeviceId: () => deviceKeyToDeviceId, - deviceToDeviceKey: () => deviceToDeviceKey, - findCamerasByInDeviceTree: () => findCamerasByInDeviceTree, - getDeviceType: () => getDeviceType, - getVmsIdByDeviceId: () => getVmsIdByDeviceId, - isFaceCamera: () => isFaceCamera -}); -module.exports = __toCommonJS(camera_exports); -var import_lodash_es = require("lodash-es"); -var import_utils = require("../utils"); -var import_constants = require("./constants"); -var isFaceCamera = (type) => { - return [ - import_constants.DevicemanagerCameraType.DEVICEMANAGER_CAMERA_TYPE_1400, - import_constants.DevicemanagerCameraType.DEVICEMANAGER_CAMERA_TYPE_HKGRABBER, - import_constants.DevicemanagerCameraType.DEVICEMANAGER_CAMERA_TYPE_DHGRABBER - ].includes(type); -}; -function getDeviceType(value) { - let type; - let isDeviceKey = (0, import_lodash_es.isString)(value); - if (isDeviceKey) { - type = value.split("_")[0]; - } else { - if ((0, import_lodash_es.has)(value, "longitude")) { - type = import_constants.DeviceType["CAMERA"]; - } - if ((0, import_lodash_es.has)(value, "ip")) { - type = import_constants.DeviceType["VMS"]; - } - if (!type) { - type = import_constants.DeviceType["DIR"]; - } - } - return type; -} -function deviceIDToDeviceKey(id, type, vmsId) { - if (type == import_constants.DeviceType["DIR"]) { - return `${type}_${id}_${vmsId}`; - } else { - return `${type}_${id}`; - } -} -function deviceToDeviceKey(item) { - let deviceKey = ""; - let type = getDeviceType(item); - if (!type) { - console.error("device type is null!"); - } - switch (type) { - case import_constants.DeviceType["DIR"]: - { - let dirId = item["dirid"] || item["dirId"]; - if (!dirId && dirId !== 0) { - console.error("dirId type is null!"); - } - let vmsId = (0, import_lodash_es.get)(item, "extendInfo.vmsPlatformId"); - if (!vmsId && vmsId !== 0) { - console.error("vmsId type is null!"); - } - deviceKey = `${type}_${dirId}_${vmsId}`; - } - break; - case import_constants.DeviceType["VMS"]: - deviceKey = `${type}_${item["id"]}`; - break; - case import_constants.DeviceType["CAMERA"]: - { - let vmsId = (0, import_lodash_es.get)(item, "extendInfo.vmsPlatformId"); - if (!vmsId && vmsId !== 0) { - console.error("vmsId type is null!"); - } - deviceKey = `${type}_${item.id}`; - } - break; - } - return deviceKey; -} -function deviceKeyToDeviceId(deviceKey) { - let [type, id] = deviceKey.split("_"); - return type === import_constants.DeviceType["DIR"] ? id : Number(id); -} -var getVmsIdByDeviceId = (key) => { - const type = getDeviceType(key); - let vmsId = ""; - switch (type) { - case import_constants.DeviceType["CAMERA"]: - case import_constants.DeviceType["DIR"]: - vmsId = key.split("_")[2]; - break; - case import_constants.DeviceType["VMS"]: - vmsId = key.split("_")[1]; - break; - } - if (!vmsId) { - console.error("vmsid is null!"); - } - return vmsId; -}; -var findCamerasByInDeviceTree = (ids = [], deviceTree, type = "id") => { - let cameraInfoList = []; - let _ids = ids.map((v) => String(v)); - (0, import_utils.loop)(deviceTree, (item) => { - let isCamera = getDeviceType((0, import_lodash_es.get)(item, "key", "")) === import_constants.DeviceType["CAMERA"]; - let isMatch = type === "key" ? _ids.includes((0, import_lodash_es.get)(item, "key")) : _ids.includes(`${(0, import_lodash_es.get)(item, "origin.id")}`); - if (isCamera && isMatch) { - cameraInfoList.push(item); - } - }); - return cameraInfoList; -}; -// Annotate the CommonJS export names for ESM import in node: -0 && (module.exports = { - deviceIDToDeviceKey, - deviceKeyToDeviceId, - deviceToDeviceKey, - findCamerasByInDeviceTree, - getDeviceType, - getVmsIdByDeviceId, - isFaceCamera -}); diff --git a/packages/func/lib/file/index.d.ts b/packages/func/lib/file/index.d.ts deleted file mode 100644 index 09e2615..0000000 --- a/packages/func/lib/file/index.d.ts +++ /dev/null @@ -1,61 +0,0 @@ -/** - * - * @param url 需要转为图片的链接 - * @returns 图片的 dom - */ -export declare const urlToImg: (url: string) => Promise; -export declare const base64DecodeImageKey: (base64ImgKey: string) => string; -/** - * 通过url获取图片的base64字符串 - * @param src 图片链接 - * @param outputFormat 图片格式 - * @returns base64 @string - */ -export declare const getBase64ByUrl: (src: string | URL, outputFormat?: string) => Promise; -/** - * 把文件转base64 - * @param file @file 文件 - * @returns @string - */ -export declare const fileToBase64: (file: any) => Promise; -/** - * - * @param image @file 图片文件 - * @param width @number 宽度 - * @param height @number 高度 - * @returns @string base64 - */ -export declare const getBase64Image: (image: any, width?: any, height?: any) => string; -/** - * 通过图片获取base64 - * @param src 图片地址 - * @returns @string - */ -export declare const getBase64ByImage: (src: string) => Promise; -/** - * url转base64 - * @param {String} url - url地址 - */ -export declare const urlToBase64V2: (url: string) => Promise; -/** - * base64转Blob - * @param {String} base64 - base64 - */ -export declare function base64toBlob(base64: string): Blob | undefined; -/** - * 图片集打包压缩下载 - * 1. url -> base64 -> blob - * 2. 将blob加入jsZip文件夹内,用file-saver保存 - * @param {Array<{url:string,name:string}>} imgDataList - * @param {string} zipName - */ -export declare const downloadPackageImages: (imgDataList: string | any[], zipName: string) => Promise; -export declare function getFileSize(size: number): string; -export declare const dataURLToBlob: (dataurl: string) => Blob; -/** - * key 转 http 链接 - * @param originImgkey 图片的值 ,可以是 base64 也可以是 http链接 - * @param host 图片的域值 - * @returns {string} - */ -export declare const generateImg: (imgKey: string, host?: string) => string; diff --git a/packages/func/lib/file/index.js b/packages/func/lib/file/index.js deleted file mode 100644 index ea403cf..0000000 --- a/packages/func/lib/file/index.js +++ /dev/null @@ -1,280 +0,0 @@ -var __create = Object.create; -var __defProp = Object.defineProperty; -var __getOwnPropDesc = Object.getOwnPropertyDescriptor; -var __getOwnPropNames = Object.getOwnPropertyNames; -var __getProtoOf = Object.getPrototypeOf; -var __hasOwnProp = Object.prototype.hasOwnProperty; -var __export = (target, all) => { - for (var name in all) - __defProp(target, name, { get: all[name], enumerable: true }); -}; -var __copyProps = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames(from)) - if (!__hasOwnProp.call(to, key) && key !== except) - __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); - } - return to; -}; -var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( - // If the importer is in node compatibility mode or this is not an ESM - // file that has been converted to a CommonJS file using a Babel- - // compatible transform (i.e. "__esModule" has not been set), then set - // "default" to the CommonJS "module.exports" for node compatibility. - isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, - mod -)); -var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); - -// src/file/index.ts -var file_exports = {}; -__export(file_exports, { - base64DecodeImageKey: () => base64DecodeImageKey, - base64toBlob: () => base64toBlob, - dataURLToBlob: () => dataURLToBlob, - downloadPackageImages: () => downloadPackageImages, - fileToBase64: () => fileToBase64, - generateImg: () => generateImg, - getBase64ByImage: () => getBase64ByImage, - getBase64ByUrl: () => getBase64ByUrl, - getBase64Image: () => getBase64Image, - getFileSize: () => getFileSize, - urlToBase64V2: () => urlToBase64V2, - urlToImg: () => urlToImg -}); -module.exports = __toCommonJS(file_exports); -var import_base_64 = __toESM(require("base-64")); -var import_jszip = __toESM(require("jszip")); -var import_file_saver = __toESM(require("file-saver")); -var import_utils = require("../utils"); -var import_lodash_es = require("lodash-es"); -var urlToImg = (url) => { - const resImage = new Promise((resolve) => { - const image = new Image(); - image.crossOrigin = ""; - image.src = url; - image.onload = () => { - resolve(image); - }; - }); - return resImage; -}; -var base64DecodeImageKey = (base64ImgKey) => { - let tempStr = base64ImgKey; - if ((0, import_utils.matchS3Prefix)(tempStr)) { - tempStr = tempStr.replace(/^v[0-9]_/, ""); - tempStr = import_base_64.default.decode(tempStr); - } - const [bucket, ...pathArr] = tempStr.split("_"); - return tempStr = `${bucket}/${pathArr.join("_")}`; -}; -var getBase64ByUrl = function(src, outputFormat = "image/png") { - return new Promise((resolve, reject) => { - const xhr = new XMLHttpRequest(); - xhr.open("GET", src, true); - xhr.responseType = "arraybuffer"; - xhr.onload = function(e) { - if (Number(xhr.status) === 200) { - const uInt8Array = new Uint8Array(xhr.response); - let i = uInt8Array.length; - const binaryString = new Array(i); - while (i--) { - binaryString[i] = String.fromCharCode(uInt8Array[i]); - } - const data = binaryString.join(""); - const base64 = window.btoa(data); - const dataUrl = "data:" + (outputFormat || "image/png") + ";base64," + base64; - resolve(dataUrl); - } else { - reject(e); - } - }; - xhr.onerror = (e) => { - reject(e); - }; - xhr.send(); - }); -}; -var fileToBase64 = (file) => { - return new Promise((resolve, reject) => { - const reader = new FileReader(); - reader.readAsDataURL(file); - reader.onload = function(e) { - resolve(e == null ? void 0 : e.target.result); - }; - reader.onerror = function(e) { - reject(e); - }; - }); -}; -var getBase64Image = (image, width, height) => { - const canvas = document.createElement("canvas"); - canvas.width = width !== void 0 ? width : image.width; - canvas.height = height !== void 0 ? height : image.height; - const ctx = canvas.getContext("2d"); - ctx == null ? void 0 : ctx.drawImage(image, 0, 0, canvas.width, canvas.height); - const ext = image.src.substring(image.src.lastIndexOf(".") + 1).toLowerCase(); - const dataURL = canvas.toDataURL("image/" + ext); - return dataURL; -}; -var getBase64ByImage = function(src) { - return new Promise((resolve, reject) => { - const image = new Image(); - const timestamp = (/* @__PURE__ */ new Date()).getTime(); - const imgUrl = src + "?" + timestamp; - image.src = imgUrl; - image.onload = function() { - function getBase64Image2(img) { - const canvas = document.createElement("canvas"); - canvas.width = img.width; - canvas.height = img.height; - const ctx = canvas.getContext("2d"); - ctx == null ? void 0 : ctx.drawImage(img, 0, 0, img.width, img.height); - const ext = img.src.substring(img.src.lastIndexOf(".") + 1).toLowerCase(); - const dataURL = canvas.toDataURL("image/" + ext); - return dataURL; - } - const base64 = getBase64Image2(image); - resolve(base64); - }; - image.onerror = (e) => { - reject(e); - }; - }); -}; -var urlToBase64V2 = (url) => { - return new Promise((resolve, reject) => { - let image = new Image(); - image.onload = function() { - var _a; - let canvas = document.createElement("canvas"); - canvas.width = image.naturalWidth; - canvas.height = image.naturalHeight; - (_a = canvas == null ? void 0 : canvas.getContext("2d")) == null ? void 0 : _a.drawImage(image, 0, 0); - let result = canvas.toDataURL("image/png"); - resolve(result); - }; - const imgUrl = url; - image.setAttribute("crossOrigin", "Anonymous"); - image.src = imgUrl; - image.onerror = () => { - reject(new Error("Images fail to load")); - }; - }).catch((error) => { - throw new Error(error); - }); -}; -function base64toBlob(base64) { - if (!base64) - return; - var arr = base64.split(","), mime = arr[0].match(/:(.*?);/)[1], bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n); - while (n--) { - u8arr[n] = bstr.charCodeAt(n); - } - return new Blob([u8arr], { type: mime }); -} -var downloadPackageImages = async (imgDataList, zipName) => { - let imgDataDownLoadList = []; - let imgBlobList = []; - let imageSuffix = []; - let zip = new import_jszip.default(); - let img = zip.folder(zipName); - try { - for (let i2 = 0; i2 < imgDataList.length; i2++) { - let src = imgDataList[i2].url; - let suffix = src.substring(src.lastIndexOf(".")); - let base64ByUrl = await urlToBase64V2(imgDataList[i2].url); - if (!base64ByUrl) - continue; - let blob = base64toBlob(base64ByUrl); - imgDataDownLoadList.push(imgDataList[i2]); - imgBlobList.push(blob); - imageSuffix.push(suffix); - } - if (imgBlobList.length === 0) - throw new Error("The number of pictures is zero !"); - if (imgBlobList.length > 0) { - for (var i = 0; i < imgBlobList.length; i++) { - img == null ? void 0 : img.file( - imgDataDownLoadList[i].name + (0, import_lodash_es.get)(imageSuffix, `.${i}`, imageSuffix[0]), - // @ts-ignore - imgBlobList[i], - { - base64: true - } - ); - } - } - zip.generateAsync({ type: "blob" }).then(function(content) { - import_file_saver.default.saveAs(content, zipName + ".zip"); - }); - } catch (error) { - throw new Error(error); - } -}; -function getFileSize(size) { - if (!size) - return ""; - var num = 1024; - if (size < num) - return size + "B"; - if (size < Math.pow(num, 2)) - return (size / num).toFixed(2) + "K"; - if (size < Math.pow(num, 3)) - return (size / Math.pow(num, 2)).toFixed(2) + "M"; - if (size < Math.pow(num, 4)) - return (size / Math.pow(num, 3)).toFixed(2) + "G"; - return (size / Math.pow(num, 4)).toFixed(2) + "T"; -} -var dataURLToBlob = (dataurl) => { - const arr = dataurl.split(","); - const mime = arr[0].match(/:(.*?);/)[1]; - const bstr = atob(arr[1]); - let n = bstr.length; - const u8arr = new Uint8Array(n); - while (n--) { - u8arr[n] = bstr.charCodeAt(n); - } - return new Blob([u8arr], { type: mime }); -}; -var generateImg = (_imgKey, host = "http://10.0.0.120") => { - let imgKey = _imgKey; - let imgUrl = ""; - if (!imgKey) - return ""; - if (/^(http:|https:)/.test(imgKey)) { - return imgKey; - } - try { - if ((0, import_utils.matchS3Prefix)(imgKey)) { - imgKey = base64DecodeImageKey(imgKey); - if (imgKey.endsWith("/")) { - const i = imgKey.substring(0, imgKey.length - 1); - imgKey = i; - } - } - imgUrl = `${host}/file/${imgKey}`; - if (_imgKey.includes("v3")) { - imgUrl = `${host}/minio/${imgKey}`; - } - } catch (error) { - console.error(error); - imgUrl = ""; - } - return imgUrl; -}; -// Annotate the CommonJS export names for ESM import in node: -0 && (module.exports = { - base64DecodeImageKey, - base64toBlob, - dataURLToBlob, - downloadPackageImages, - fileToBase64, - generateImg, - getBase64ByImage, - getBase64ByUrl, - getBase64Image, - getFileSize, - urlToBase64V2, - urlToImg -}); diff --git a/packages/func/lib/index.d.ts b/packages/func/lib/index.d.ts deleted file mode 100644 index b792dee..0000000 --- a/packages/func/lib/index.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -export * from 'lodash-es'; -export * from './file'; -export * from './map'; -export * from './performance'; -export * from './string'; -export * from './number'; -export * from './time'; -export * from './utils'; -export * from './camera'; diff --git a/packages/func/lib/index.js b/packages/func/lib/index.js deleted file mode 100644 index b5affba..0000000 --- a/packages/func/lib/index.js +++ /dev/null @@ -1,39 +0,0 @@ -var __defProp = Object.defineProperty; -var __getOwnPropDesc = Object.getOwnPropertyDescriptor; -var __getOwnPropNames = Object.getOwnPropertyNames; -var __hasOwnProp = Object.prototype.hasOwnProperty; -var __copyProps = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames(from)) - if (!__hasOwnProp.call(to, key) && key !== except) - __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); - } - return to; -}; -var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default")); -var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); - -// src/index.ts -var src_exports = {}; -module.exports = __toCommonJS(src_exports); -__reExport(src_exports, require("lodash-es"), module.exports); -__reExport(src_exports, require("./file"), module.exports); -__reExport(src_exports, require("./map"), module.exports); -__reExport(src_exports, require("./performance"), module.exports); -__reExport(src_exports, require("./string"), module.exports); -__reExport(src_exports, require("./number"), module.exports); -__reExport(src_exports, require("./time"), module.exports); -__reExport(src_exports, require("./utils"), module.exports); -__reExport(src_exports, require("./camera"), module.exports); -// Annotate the CommonJS export names for ESM import in node: -0 && (module.exports = { - ...require("lodash-es"), - ...require("./file"), - ...require("./map"), - ...require("./performance"), - ...require("./string"), - ...require("./number"), - ...require("./time"), - ...require("./utils"), - ...require("./camera") -}); diff --git a/packages/func/lib/map/index.d.ts b/packages/func/lib/map/index.d.ts deleted file mode 100644 index 08fa4a2..0000000 --- a/packages/func/lib/map/index.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * 获取经纬信息 - * @param lngLat 位置信息 - * @returns @object { long, lat } - */ -export declare const fixedLngLat: (lngLat?: string) => string; -export declare const transformLngLat: (lngLat?: string) => { - longitude: number; - latitude: number; -} | null; diff --git a/packages/func/lib/map/index.js b/packages/func/lib/map/index.js deleted file mode 100644 index 39c614a..0000000 --- a/packages/func/lib/map/index.js +++ /dev/null @@ -1,54 +0,0 @@ -var __defProp = Object.defineProperty; -var __getOwnPropDesc = Object.getOwnPropertyDescriptor; -var __getOwnPropNames = Object.getOwnPropertyNames; -var __hasOwnProp = Object.prototype.hasOwnProperty; -var __export = (target, all) => { - for (var name in all) - __defProp(target, name, { get: all[name], enumerable: true }); -}; -var __copyProps = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames(from)) - if (!__hasOwnProp.call(to, key) && key !== except) - __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); - } - return to; -}; -var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); - -// src/map/index.ts -var map_exports = {}; -__export(map_exports, { - fixedLngLat: () => fixedLngLat, - transformLngLat: () => transformLngLat -}); -module.exports = __toCommonJS(map_exports); -var fixedLngLat = (lngLat) => { - if (!lngLat) { - return ""; - } - const lngLatArr = lngLat.split(","); - const longitude = Number(lngLatArr[0]).toFixed(6); - const latitude = Number(lngLatArr[1]).toFixed(6); - if (lngLatArr.length < 2) { - return ""; - } - return `${longitude},${latitude}`; -}; -var transformLngLat = (lngLat) => { - if (lngLat) { - const lngLatArr = lngLat ? lngLat.split(",") : []; - const longitude = Number(lngLatArr[0]); - const latitude = Number(lngLatArr[1]); - if (lngLatArr.length < 2) { - return null; - } - return { longitude, latitude }; - } - return null; -}; -// Annotate the CommonJS export names for ESM import in node: -0 && (module.exports = { - fixedLngLat, - transformLngLat -}); diff --git a/packages/func/lib/number/index.d.ts b/packages/func/lib/number/index.d.ts deleted file mode 100644 index 704d582..0000000 --- a/packages/func/lib/number/index.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * 设置数据的精度 - * @param originNumber - * @param accuracy 精度 以原点为中心向左为正,向右为负, - * @param isCeil 是否为向上取整 - * @returns number - */ -export declare const setNumberAccuracy: (originNumber: number, accuracy?: number, isCeil?: boolean) => number; diff --git a/packages/func/lib/number/index.js b/packages/func/lib/number/index.js deleted file mode 100644 index 49e00e0..0000000 --- a/packages/func/lib/number/index.js +++ /dev/null @@ -1,45 +0,0 @@ -var __defProp = Object.defineProperty; -var __getOwnPropDesc = Object.getOwnPropertyDescriptor; -var __getOwnPropNames = Object.getOwnPropertyNames; -var __hasOwnProp = Object.prototype.hasOwnProperty; -var __export = (target, all) => { - for (var name in all) - __defProp(target, name, { get: all[name], enumerable: true }); -}; -var __copyProps = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames(from)) - if (!__hasOwnProp.call(to, key) && key !== except) - __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); - } - return to; -}; -var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); - -// src/number/index.ts -var number_exports = {}; -__export(number_exports, { - setNumberAccuracy: () => setNumberAccuracy -}); -module.exports = __toCommonJS(number_exports); -var setNumberAccuracy = (originNumber, accuracy = 0, isCeil = true) => { - if (originNumber === 0) { - return 0; - } - let returnData = 0; - if (isCeil) { - returnData = Math.ceil(originNumber / Math.pow(10, accuracy)) * Math.pow(10, accuracy); - } else { - returnData = Math.floor(originNumber / Math.pow(10, accuracy)) * Math.pow(10, accuracy); - } - if (accuracy < 0) { - returnData = Number(returnData.toFixed(-accuracy)); - } else { - returnData = Number(returnData.toFixed(0)); - } - return returnData; -}; -// Annotate the CommonJS export names for ESM import in node: -0 && (module.exports = { - setNumberAccuracy -}); diff --git a/packages/func/lib/performance/index.d.ts b/packages/func/lib/performance/index.d.ts deleted file mode 100644 index 22dd838..0000000 --- a/packages/func/lib/performance/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare const speedConvert: (bps: number, contertUnit?: number) => string; diff --git a/packages/func/lib/performance/index.js b/packages/func/lib/performance/index.js deleted file mode 100644 index 1d12f21..0000000 --- a/packages/func/lib/performance/index.js +++ /dev/null @@ -1,41 +0,0 @@ -var __defProp = Object.defineProperty; -var __getOwnPropDesc = Object.getOwnPropertyDescriptor; -var __getOwnPropNames = Object.getOwnPropertyNames; -var __hasOwnProp = Object.prototype.hasOwnProperty; -var __export = (target, all) => { - for (var name in all) - __defProp(target, name, { get: all[name], enumerable: true }); -}; -var __copyProps = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames(from)) - if (!__hasOwnProp.call(to, key) && key !== except) - __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); - } - return to; -}; -var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); - -// src/performance/index.ts -var performance_exports = {}; -__export(performance_exports, { - speedConvert: () => speedConvert -}); -module.exports = __toCommonJS(performance_exports); -var speedConvert = (bps, contertUnit = 8) => { - if (bps === void 0) - return `0KB/s`; - const byte = bps / contertUnit; - if (bps > 1024 * 1024 * 1024) { - return `${(byte / 1024 / 1024 / 1024).toFixed(2)}GB/s`; - } else if (byte > 1024 * 1024) { - return `${(byte / 1024 / 1024).toFixed(2)}MB/s`; - } else if (byte > 1024) { - return `${(byte / 1024).toFixed(2)}KB/s`; - } - return `${byte}KB/s`; -}; -// Annotate the CommonJS export names for ESM import in node: -0 && (module.exports = { - speedConvert -}); diff --git a/packages/func/lib/string/index.d.ts b/packages/func/lib/string/index.d.ts deleted file mode 100644 index a209796..0000000 --- a/packages/func/lib/string/index.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -export declare const getStrLength: (str: string) => number; -/** - * js截取字符串,中英文都能用 - * @param str:需要截取的字符串 - * @param len: 需要截取的长度 - */ -export declare const cutStr: (str: string, len: number) => string | String | undefined; diff --git a/packages/func/lib/string/index.js b/packages/func/lib/string/index.js deleted file mode 100644 index 4297b5a..0000000 --- a/packages/func/lib/string/index.js +++ /dev/null @@ -1,62 +0,0 @@ -var __defProp = Object.defineProperty; -var __getOwnPropDesc = Object.getOwnPropertyDescriptor; -var __getOwnPropNames = Object.getOwnPropertyNames; -var __hasOwnProp = Object.prototype.hasOwnProperty; -var __export = (target, all) => { - for (var name in all) - __defProp(target, name, { get: all[name], enumerable: true }); -}; -var __copyProps = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames(from)) - if (!__hasOwnProp.call(to, key) && key !== except) - __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); - } - return to; -}; -var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); - -// src/string/index.ts -var string_exports = {}; -__export(string_exports, { - cutStr: () => cutStr, - getStrLength: () => getStrLength -}); -module.exports = __toCommonJS(string_exports); -var getStrLength = function(str) { - var realLength = 0, len = str.length, charCode = -1; - for (var i = 0; i < len; i++) { - charCode = str.charCodeAt(i); - if (charCode >= 0 && charCode <= 128) - realLength += 1; - else - realLength += 2; - } - return realLength; -}; -var cutStr = function cutstr(str, len) { - var str_length = 0; - var str_len = 0; - let str_cut = new String(); - str_len = str.length; - for (var i = 0; i < str_len; i++) { - let a = str.charAt(i); - str_length++; - if (escape(a).length > 4) { - str_length++; - } - str_cut = str_cut.concat(a); - if (str_length >= len) { - str_cut = str_cut.concat("..."); - return str_cut; - } - } - if (str_length < len) { - return str; - } -}; -// Annotate the CommonJS export names for ESM import in node: -0 && (module.exports = { - cutStr, - getStrLength -}); diff --git a/packages/func/lib/time/index.d.ts b/packages/func/lib/time/index.d.ts deleted file mode 100644 index b96cf6c..0000000 --- a/packages/func/lib/time/index.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -export declare const formateDuration: (diff: number) => string; -export declare function generateTime(): { - startDateTime: number; - endDateTime: number; -}; diff --git a/packages/func/lib/time/index.js b/packages/func/lib/time/index.js deleted file mode 100644 index 9f2cfa6..0000000 --- a/packages/func/lib/time/index.js +++ /dev/null @@ -1,66 +0,0 @@ -var __create = Object.create; -var __defProp = Object.defineProperty; -var __getOwnPropDesc = Object.getOwnPropertyDescriptor; -var __getOwnPropNames = Object.getOwnPropertyNames; -var __getProtoOf = Object.getPrototypeOf; -var __hasOwnProp = Object.prototype.hasOwnProperty; -var __export = (target, all) => { - for (var name in all) - __defProp(target, name, { get: all[name], enumerable: true }); -}; -var __copyProps = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames(from)) - if (!__hasOwnProp.call(to, key) && key !== except) - __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); - } - return to; -}; -var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( - // If the importer is in node compatibility mode or this is not an ESM - // file that has been converted to a CommonJS file using a Babel- - // compatible transform (i.e. "__esModule" has not been set), then set - // "default" to the CommonJS "module.exports" for node compatibility. - isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, - mod -)); -var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); - -// src/time/index.ts -var time_exports = {}; -__export(time_exports, { - formateDuration: () => formateDuration, - generateTime: () => generateTime -}); -module.exports = __toCommonJS(time_exports); -var import_dayjs = __toESM(require("dayjs")); -var formateDuration = (diff) => { - var days = Math.floor(diff / (24 * 3600 * 1e3)); - var leave1 = diff % (24 * 3600 * 1e3); - var hours = Math.floor(leave1 / (3600 * 1e3)); - var leave2 = leave1 % (3600 * 1e3); - var minutes = Math.floor(leave2 / (60 * 1e3)); - var leave3 = leave2 % (60 * 1e3); - var seconds = Math.round(leave3 / 1e3); - var returnStr = seconds + "秒"; - if (minutes > 0) { - returnStr = minutes + "分"; - } - if (hours > 0) { - returnStr = hours + "小时"; - } - if (days > 0) { - returnStr = days + "天"; - } - return returnStr; -}; -function generateTime() { - let endDateTime = (0, import_dayjs.default)().endOf("day").unix(); - let startDateTime = (0, import_dayjs.default)().startOf("day").unix(); - return { startDateTime, endDateTime }; -} -// Annotate the CommonJS export names for ESM import in node: -0 && (module.exports = { - formateDuration, - generateTime -}); diff --git a/packages/func/lib/utils/index.d.ts b/packages/func/lib/utils/index.d.ts deleted file mode 100644 index 2ae2b65..0000000 --- a/packages/func/lib/utils/index.d.ts +++ /dev/null @@ -1,20 +0,0 @@ -export { default as isChrome } from './isChrome'; -export declare const matchS3Prefix: (str: string) => boolean; -/** - * 通过文件名获取文件类型 - * @param fileName 文件名称 - * @returns 文件类型 - */ -export declare const getFileSuffix: (fileName: string) => string; -/** - * 通过类型获取文件名 - * @param type 类型 - * @returns - */ -export declare const getImageSuffixByFileType: (type: string) => string; -export declare function getChromeVersion(): number | false; -export declare const nextTick: (func: (value: void) => void | PromiseLike) => void; -export declare const loop: (items: string | any[], callback: (arg0: any) => any) => void; -export declare const addEventListener: (target: any, eventType: string, cb: any, option?: any) => { - remove: () => void; -}; diff --git a/packages/func/lib/utils/index.js b/packages/func/lib/utils/index.js deleted file mode 100644 index 51894d5..0000000 --- a/packages/func/lib/utils/index.js +++ /dev/null @@ -1,138 +0,0 @@ -var __create = Object.create; -var __defProp = Object.defineProperty; -var __getOwnPropDesc = Object.getOwnPropertyDescriptor; -var __getOwnPropNames = Object.getOwnPropertyNames; -var __getProtoOf = Object.getPrototypeOf; -var __hasOwnProp = Object.prototype.hasOwnProperty; -var __export = (target, all) => { - for (var name in all) - __defProp(target, name, { get: all[name], enumerable: true }); -}; -var __copyProps = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames(from)) - if (!__hasOwnProp.call(to, key) && key !== except) - __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); - } - return to; -}; -var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( - // If the importer is in node compatibility mode or this is not an ESM - // file that has been converted to a CommonJS file using a Babel- - // compatible transform (i.e. "__esModule" has not been set), then set - // "default" to the CommonJS "module.exports" for node compatibility. - isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, - mod -)); -var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); - -// src/utils/index.ts -var utils_exports = {}; -__export(utils_exports, { - addEventListener: () => addEventListener, - getChromeVersion: () => getChromeVersion, - getFileSuffix: () => getFileSuffix, - getImageSuffixByFileType: () => getImageSuffixByFileType, - isChrome: () => import_isChrome.default, - loop: () => loop, - matchS3Prefix: () => matchS3Prefix, - nextTick: () => nextTick -}); -module.exports = __toCommonJS(utils_exports); -var import_react_dom = __toESM(require("react-dom")); -var import_isChrome = __toESM(require("./isChrome")); -var matchS3Prefix = (str) => { - return /^v[0-9]_/.test(str); -}; -var getFileSuffix = (fileName) => { - const splitArr = fileName.split("."); - return splitArr.length < 2 ? "" : splitArr[splitArr.length - 1]; -}; -var getImageSuffixByFileType = (type) => { - let imageSuffix = ""; - switch (type) { - case "jpeg": { - imageSuffix = ".jpg"; - break; - } - case "gif": { - imageSuffix = ".gif"; - break; - } - case "png": { - imageSuffix = ".png"; - break; - } - case "vnd.wap.wbmp": { - imageSuffix = ".wbmp"; - break; - } - case "x-up-wpng": { - imageSuffix = ".wpng"; - break; - } - case "nbmp": { - imageSuffix = ".nbmp"; - break; - } - } - return imageSuffix; -}; -function getChromeVersion() { - const arr = navigator.userAgent.split(" "); - let chromeVersion = ""; - for (let i = 0; i < arr.length; i++) { - if (/chrome/i.test(arr[i])) - chromeVersion = arr[i]; - } - if (chromeVersion) { - return Number(chromeVersion.split("/")[1].split(".")[0]); - } else { - return false; - } -} -var nextTick = (func) => { - if (queueMicrotask) { - queueMicrotask(func); - return; - } - Promise.resolve().then(func); -}; -var loop = (items, callback) => { - for (let i = 0; i < items.length; i++) { - const element = items[i]; - let isBreak = callback(element); - if (isBreak) { - return; - } - if (element["children"]) { - loop(element["children"], callback); - } - } -}; -var addEventListener = (target, eventType, cb, option) => { - const callback = import_react_dom.default.unstable_batchedUpdates ? function run(e) { - import_react_dom.default.unstable_batchedUpdates(cb, e); - } : cb; - if (target.addEventListener) { - target.addEventListener(eventType, callback, option); - } - return { - remove: () => { - if (target.removeEventListener) { - target.removeEventListener(eventType, callback); - } - } - }; -}; -// Annotate the CommonJS export names for ESM import in node: -0 && (module.exports = { - addEventListener, - getChromeVersion, - getFileSuffix, - getImageSuffixByFileType, - isChrome, - loop, - matchS3Prefix, - nextTick -}); diff --git a/packages/func/lib/utils/isChrome.d.ts b/packages/func/lib/utils/isChrome.d.ts deleted file mode 100644 index 2d07ceb..0000000 --- a/packages/func/lib/utils/isChrome.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export declare const isBrowser: boolean; -declare const isChrome: () => boolean; -export default isChrome; diff --git a/packages/func/lib/utils/isChrome.js b/packages/func/lib/utils/isChrome.js deleted file mode 100644 index 7bc4e87..0000000 --- a/packages/func/lib/utils/isChrome.js +++ /dev/null @@ -1,42 +0,0 @@ -var __defProp = Object.defineProperty; -var __getOwnPropDesc = Object.getOwnPropertyDescriptor; -var __getOwnPropNames = Object.getOwnPropertyNames; -var __hasOwnProp = Object.prototype.hasOwnProperty; -var __export = (target, all) => { - for (var name in all) - __defProp(target, name, { get: all[name], enumerable: true }); -}; -var __copyProps = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames(from)) - if (!__hasOwnProp.call(to, key) && key !== except) - __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); - } - return to; -}; -var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); - -// src/utils/isChrome.ts -var isChrome_exports = {}; -__export(isChrome_exports, { - default: () => isChrome_default, - isBrowser: () => isBrowser -}); -module.exports = __toCommonJS(isChrome_exports); -var isBrowser = !!(typeof window !== "undefined" && window); -var isChrome = () => { - const winNav = isBrowser && window.navigator; - const vendorName = winNav && winNav.vendor; - const userAgent = winNav && winNav.userAgent; - const isChromium = isBrowser && typeof chrome !== "undefined"; - const isOpera = isBrowser && typeof opr !== "undefined"; - const isIEedge = userAgent && userAgent.indexOf("Edge") > -1; - const isIOSChrome = !!(userAgent && userAgent.match("CriOS")); - const isDesktopChrome = isChromium && vendorName === "Google Inc." && !isOpera && !isIEedge; - return isIOSChrome || isDesktopChrome; -}; -var isChrome_default = isChrome; -// Annotate the CommonJS export names for ESM import in node: -0 && (module.exports = { - isBrowser -}); diff --git a/packages/func/package.json b/packages/func/package.json index c864c09..83e18e6 100644 --- a/packages/func/package.json +++ b/packages/func/package.json @@ -13,10 +13,11 @@ "lib/**/style/*", "*.less" ], - "main": "lib/index.tsx", + "main": "lib/index.js", "module": "es/index.js", "typings": "es/index.d.ts", "exports": { + "./*": "./*", "./package.json": "./package.json" }, "files": [ @@ -32,15 +33,19 @@ "registry": "http://10.0.0.77:4874" }, "dependencies": { + "@zhst/request": "workspace:^", "base-64": "^1.0.0", "dayjs": "^1.11.10", "file-saver": "^2.0.5", "jszip": "^3.10.1", - "lodash-es": "^4.17.21" + "lodash-es": "^4.17.21", + "uuid": "^9.0.1" }, "devDependencies": { "@types/base-64": "^1.0.2", "@types/file-saver": "^2.0.7", - "@types/lodash-es": "^4.17.12" + "@types/lodash-es": "^4.17.12", + "@types/uuid": "^9.0.7", + "@zhst/types": "workspace:^" } } diff --git a/packages/func/src/file/index.ts b/packages/func/src/file/index.ts index 671dc5c..20b93ec 100644 --- a/packages/func/src/file/index.ts +++ b/packages/func/src/file/index.ts @@ -2,7 +2,8 @@ import Base64 from 'base-64' import JSZip from 'jszip'; import FileSaver from 'file-saver'; import { matchS3Prefix } from '../utils' -import { get } from 'lodash-es'; +import { get, isString } from 'lodash-es'; +import { Rect } from '@zhst/types' /** * @@ -296,3 +297,49 @@ export const generateImg: (imgKey: string, host?: string) => string = (_imgKey, } return imgUrl; }; + +/** + * 获取指定字符串后面的部分 + * @param imageKey v1_开头的字符串 + * @returns + */ +export const getImageKey = (imageKey: string, preFix?: string) => { + const splitIndex = preFix || 'v1_'; + if (imageKey.startsWith(splitIndex)) { + return window.atob(imageKey.split(splitIndex)[1]).replace('_', '/'); + } else { + return imageKey; + } +}; + +/** + * 获取图片 + * @param img 图片的url链接 + * @param odRect + * @returns file + */ +export const getFileByRect = async (img: string, odRect: Rect) => { + let image; + + if (isString(img)) { + const url = generateImg(img); + image = await urlToImg(url); + } else { + image = img; + } + const commonCanvas = document.createElement('canvas'); + commonCanvas.width = odRect.w * image.width; + commonCanvas.height = odRect.h * image.height; + commonCanvas.style.display = 'none'; + document.body.appendChild(commonCanvas); + const commonCtx = commonCanvas.getContext('2d'); + commonCtx?.translate(-odRect.x * image.width, -odRect.y * image.height); + commonCtx?.drawImage(image, 0, 0); + const base64 = commonCanvas.toDataURL('image/jpeg'); + const blobData = dataURLToBlob(base64); + commonCanvas.parentNode?.removeChild(commonCanvas); + const file = new window.File([blobData], `${new Date().getTime()}`, { + type: 'image/jpeg', + }); + return file; +}; diff --git a/packages/func/src/index.ts b/packages/func/src/index.ts index 5b729a0..7dd46b2 100644 --- a/packages/func/src/index.ts +++ b/packages/func/src/index.ts @@ -7,3 +7,5 @@ export * from './number' export * from './time' export * from './utils' export * from './camera' +export * from './math' +export * from './upload' diff --git a/packages/func/src/math/index.ts b/packages/func/src/math/index.ts new file mode 100644 index 0000000..fb4d317 --- /dev/null +++ b/packages/func/src/math/index.ts @@ -0,0 +1,448 @@ +import { cloneDeep, get, isNull, isNumber, isString } from 'lodash-es'; +import { dataURLToBlob, generateImg, urlToImg } from '../file'; +import { IOdRectOrigin, Rect } from '@zhst/types'; + +const proto = { + Common: { + AlgorithmVersion: { + VERSION_REID_HEAD_ATTR: '形体', + VERSION_FACE: '人脸', + VERSION_NON_MOTOR_VEHICLE: '非机动车', + }, + }, +}; +export const ALGORITHM_VERSION = { + ['7']: '形体', + ['4']: '人脸', + ['6']: '非机动车', +}; + +export const algorithmVersions = [...Object.keys(ALGORITHM_VERSION)] + +export const getBikeExtendRect = (rect: Rect, maxW: number) => { + const newRect = { ...rect }; + //向上扩大一倍 + const oldY = cloneDeep(rect.y); + newRect.y = newRect.y - newRect.h < 0 ? 0 : newRect.y - newRect.h; + newRect.h += oldY - newRect.y; + + let newX = Math.round(newRect.x - newRect.w * 0.15); + if (newX < 0) { + newX = 0; + } + let newW = newRect.x - newX + newRect.w + Math.round(newRect.w * 0.15); + if (newX + newW > maxW) { + newW = maxW - newX; + } + newRect.x = newX; + newRect.w = newW; + + return newRect; +}; + +export const getOtherExtendRect = (srcRect, maxW, maxH, type) => { + const wExtendRadio = 0.25; + const upExtendRadio = 0.25; + const downExtendRadio = 0.25; + const fixPersonExtend = true; + + let nx = 0; + let nw = 0; + + nx = srcRect.x - Math.round(srcRect.w * wExtendRadio); + if (nx < 0) { + nx = 0; + } + nw = srcRect.x - nx + srcRect.w + Math.round(srcRect.w * wExtendRadio); + if (nx + nw > maxW) { + nw = maxW - nx; + } + + let ny = 0; + let nh = 0; + ny = srcRect.y - Math.round(upExtendRadio * srcRect.h); + if (ny < 0) { + ny = 0; + } + nh = srcRect.y - ny + srcRect.h + Math.round(srcRect.h * downExtendRadio); + if (ny + nh > maxH) { + nh = maxH - ny; + } + + let newRect = { + x: nx, + y: ny, + w: nw, + h: nh, + }; + if ( + (type === proto.Common.AlgorithmVersion.VERSION_REID_HEAD_ATTR || + type === proto.Common.AlgorithmVersion.VERSION_FACE) && + fixPersonExtend + ) { + const fixW = Math.round(nh * 0.75); + if (nw < fixW) { + // 应该扩展宽度 + let newX = nx + Math.round(nw / 2.0 - 0.5 * fixW); + if (newX < 0) { + newX = 0; + } + let newW = fixW; + if (newW + newX > maxW) { + newW = maxW - newX; + } + + newRect = { + x: newX, + y: ny, + w: newW, + h: nh, + }; + } else if (nw > fixW) { + // 应该扩展高度 + const fixH = Math.round(nw * 1.333); + let newY = ny + Math.round(nh / 2.0 - 0.5 * fixH); + if (newY < 0) { + newY = 0; + } + let newH = fixH; + if (newY + newH > maxH) { + newH = maxH - newY; + } + newRect = { + x: nx, + y: newY, + w: nw, + h: newH, + }; + } + } + return newRect; +}; + +export const getNormalization = (srcRect: Rect, maxW: number, maxH: number) => { + const newRect = { + ...srcRect, + }; + newRect.x = srcRect.x / maxW; + newRect.y = srcRect.y / maxH; + newRect.w = srcRect.w / maxW; + newRect.h = srcRect.h / maxH; + if (newRect.x + newRect.w > 1) { + newRect.w = 1 - newRect.x; + } + if (newRect.y + newRect.h > 1) { + newRect.h = 1 - newRect.y; + } + return newRect; +}; +//传入od框 穿出 od扩展框 +export const getExtendRect = (normalizationRect: Rect, imgW: number, imgH: number, type: string) => { + const rect = { + x: normalizationRect.x * imgW, + y: normalizationRect.y * imgH, + w: normalizationRect.w * imgW, + h: normalizationRect.h * imgH, + }; + + let newRect; + if (type === proto.Common.AlgorithmVersion.VERSION_NON_MOTOR_VEHICLE) { + newRect = getBikeExtendRect(rect, imgW); + } else { + newRect = getOtherExtendRect(rect, imgW, imgH, type); + } + newRect = getNormalization(newRect, imgW, imgH); + return newRect; +}; + +export const getTransformRect = (image: { height: number; width: number; }, transform: { translateX: any; translateY: any; scale: any; rotate: any; }, rect: Rect) => { + const canvasRect = { + x: rect.x, + y: rect.y, + x2: rect.x + rect.w, + y2: rect.h + rect.y, + }; + //1.转成缩放前的坐标 + const { translateX, translateY, scale, rotate } = transform; + const originAxisRect = { + x: (canvasRect.x - translateX) / scale, + y: (canvasRect.y - translateY) / scale, + x2: (canvasRect.x2 - translateX) / scale, + y2: (canvasRect.y2 - translateY) / scale, + }; + //2.转成图片坐标 + //不考虑旋转 图片原点就是坐标原点 + let imgAxisRect = originAxisRect; + //但是旋转90度后图片不在坐标原点 加上这部分diff + if (rotate % 180 !== 0) { + //90度调整偏移量 + const offsetX = -(image.height - image.width) / 2; + const offsetY = -(image.width - image.height) / 2; + imgAxisRect = { + x: originAxisRect.x - offsetX, + y: originAxisRect.y - offsetY, + x2: originAxisRect.x2 - offsetX, + y2: originAxisRect.y2 - offsetY, + }; + } + //3.限制框不要超出图片 + let imgW = image.width; + let imgH = image.height; + if (rotate % 180 !== 0) { + [imgW, imgH] = [imgH, imgW]; + } + imgAxisRect.x = Math.min(imgW, Math.max(imgAxisRect.x, 0)); + imgAxisRect.y = Math.min(imgH, Math.max(imgAxisRect.y, 0)); + imgAxisRect.x2 = Math.min(imgW, Math.max(imgAxisRect.x2, 0)); + imgAxisRect.y2 = Math.min(imgH, Math.max(imgAxisRect.y2, 0)); + //获取归一化坐标 + const endRect = { + x: imgAxisRect.x2 > imgAxisRect.x ? imgAxisRect.x : imgAxisRect.x2, + y: imgAxisRect.y2 > imgAxisRect.y ? imgAxisRect.y : imgAxisRect.y2, + w: Math.abs(imgAxisRect.x2 - imgAxisRect.x), + h: Math.abs(imgAxisRect.y2 - imgAxisRect.y), + }; + + return getNormalization(endRect, imgW, imgH); +}; + +//旋转图片后转成file 对象 +export const getRotateImg = (image: HTMLImageElement, rotate: number) => { + let imgW = image.width; + let imgH = image.height; + if (rotate % 180 !== 0) { + [imgW, imgH] = [imgH, imgW]; + } + const commonCanvas = document.createElement('canvas'); + commonCanvas.width = imgW; + commonCanvas.height = imgH; + commonCanvas.style.display = 'none'; + document.body.appendChild(commonCanvas); + const commonCtx = commonCanvas.getContext('2d'); + //移动到图片中心 旋转 + + commonCtx?.save(); + if (rotate % 180 !== 0) { + //90度调整偏移量 + commonCtx?.translate((image.height - image.width) / 2, (image.width - image.height) / 2); + } + commonCtx?.translate(image.width / 2, image.height / 2); + commonCtx?.rotate((rotate / 180) * Math.PI); + commonCtx?.translate(-image.width / 2, -image.height / 2); + commonCtx?.drawImage(image, 0, 0); + commonCtx?.restore(); + + const dataUrl = commonCanvas.toDataURL('image/jpeg'); + const blobData = dataURLToBlob(dataUrl); + const file = new window.File([blobData], `${new Date().getTime()}`, { + type: 'image/jpeg', + }); + commonCanvas.parentNode?.removeChild(commonCanvas); + return file; +}; + +/** + * 格式化工具 + * @param originData + * @returns + */ +export const getOdRect = (originData: IOdRectOrigin) => { + let data = get(originData, 'objects', []) + .filter((v: any) => !isNull(get(v, 'infoOnSource.bboxInFrame.bboxRatio'))) + .map((v: any, index: any) => { + // objectId==0 特征没有提取到过滤1掉 + const rect = get(v, 'infoOnSource.bboxInFrame.bboxRatio'); + const extendBox = get(v, 'infoOnSource.bboxInFrame.extendBoxRatio'); + const frameTimestamp = get(v, 'timestamp'); //时间戳创建档案的时候需要 + const qualityScore = get(v, 'qualityScore'); + const algorithmVersion = + get(v, 'objectType') === 'OBJECT_TYPE_PEDESTRAIN' + ? 'VERSION_REID_HEAD_ATTR' + : get(v, 'objectType') === 'OBJECT_TYPE_FACE' + ? 'VERSION_FACE' + : 'VERSION_REID_HEAD_ATTR'; + const featureData = get(v, 'feature', []).filter( + (v: any) => v.type === 'FEATURE_TYPE_BYTE' + ); + const objectRectIndex = algorithmVersion === 'VERSION_FACE' ? 0 : 1; + const objectType = get(v, 'objectType'); + const objectId = get(v, 'objectIndex.objectId'); + const sourceObjectId = get(v, 'sourceObjectId'); + return { + x: rect.x, + y: rect.y, + w: rect.w, + h: rect.h, + // faceCorrectImage: faceCorrectImage, + id: index, + qualityScore: qualityScore, + algorithmVersion: algorithmVersion, + featureData: get(featureData, '0.featureByte'), + objectRectIndex: objectRectIndex, + objectType: objectType, + objectId: objectId, + frameTimestamp: frameTimestamp, + sourceObjectId: sourceObjectId, + extendBox: extendBox, + }; + }); + if (data.length > 0) { + data = data.filter((v: { objectId: string; }) => v.objectId !== '0'); + } else { + throw new Error('empty'); + } + return data; +}; + +//档案库od +export const getOdRectV2 = (originData: { odv2Result: any[]; }) => { + // const fileKey = 'v1_' + window.btoa('public_' + imgKey.split('public/')[1]); + const resp = originData.odv2Result[0]; + const subObjects: { x: any; y: any; w: any; h: any; id: any; qualityScore: any; algorithmVersion: any; featrueData: any; objectRectIndex: number; objectType: any; objectId: any; }[] = []; //形体 + const data = get(resp, 'objects', []) + .filter((v) => !isNull(get(v, 'subObjects[0].infoOnSource.bboxInFrame.bboxRatio'))) + .map((v, index) => { + const rect = get(v, 'infoOnSource.bboxInFrame.bboxRatio'); + const qualityScore = get(v, 'qualityScore'); + const algorithmVersion = get(v, 'objectType'); + const featrueData = get(v, 'feature', []).filter( + (v) => v.name === 'feature-body' || v.name === 'feature-face' + ); + const objectRectIndex = algorithmVersion === 'OBJECT_TYPE_FACE' ? 0 : 1; + const objectType = get(v, 'objectType'); + const objectId = get(v, 'objectIndex.objectId'); + //如果存在subObjects的数组不为null表示形体里面带人脸,人脸的od框也要显示出来 + if (get(v, 'subObjects', []).length) { + get(v, 'subObjects', []).forEach((e) => { + const rect = get(e, 'infoOnSource.bboxInFrame.bboxRatio'); + const qualityScore = get(e, 'qualityScore'); + const algorithmVersion = get(e, 'objectType'); + const featrueData = get(e, 'feature', []).filter( + (v: { name: string; }) => v.name === 'feature-body' || v.name === 'feature-face' + ); + const objectRectIndex = algorithmVersion === 'OBJECT_TYPE_FACE' ? 0 : 1; + const objectType = get(e, 'objectType'); + const objectId = get(e, 'objectIndex.objectId'); + subObjects.push({ + x: rect.x, + y: rect.y, + w: rect.w, + h: rect.h, + id: index, + qualityScore: qualityScore, + algorithmVersion: algorithmVersion, + featrueData: featrueData.length ? featrueData[0].featureByte : '', + objectRectIndex: objectRectIndex, + objectType: objectType, + objectId, + }); + }); + } + return { + x: rect.x, + y: rect.y, + w: rect.w, + h: rect.h, + id: index, + qualityScore: qualityScore, + algorithmVersion: algorithmVersion, + featrueData: featrueData[0].featureByte, + objectRectIndex: objectRectIndex, + objectType: objectType, + objectId: objectId, + }; + }); + const brr = data.concat(subObjects).map((v: { id: any; }, vs: any) => { + if (String(v.id)) { + v.id = vs; + } + return v; + }); + if (brr.length > 0) { + console.log(brr, 'data111'); + } else { + throw new Error('empty'); + } + console.log(brr); + return brr; +}; + +//获取图片 + +export const getFileByRect = async (img: any, odRect: Rect) => { + let image; + if (isString(img)) { + const url = generateImg(img); + console.log(url, '获取图片'); + image = await urlToImg(url); + console.log(image, '获取的图片'); + } else { + image = img; + } + const commonCanvas = document.createElement('canvas'); + commonCanvas.width = odRect.w * image.width; + commonCanvas.height = odRect.h * image.height; + commonCanvas.style.display = 'none'; + document.body.appendChild(commonCanvas); + const commonCtx = commonCanvas.getContext('2d'); + commonCtx?.translate(-odRect.x * image.width, -odRect.y * image.height); + commonCtx?.drawImage(image, 0, 0); + const base64 = commonCanvas.toDataURL('image/jpeg'); + const blobData = dataURLToBlob(base64); + commonCanvas?.parentNode?.removeChild(commonCanvas); + const file = new window.File([blobData], `${new Date().getTime()}`, { + type: 'image/jpeg', + }); + return file; +}; + + +/** + * Get transforms base on the given object. + * @param {Object} obj - The target object. + * @returns {string} A string contains transform values. + */ +export function getTransforms({ + rotate, + scaleX, + scaleY, + translateX, + translateY, +}: { + rotate?: number; + scaleX?: number; + scaleY?: number; + translateX?: number; + translateY?: number; +}) { + const values = []; + + if (isNumber(translateX) && translateX !== 0) { + values.push(`translateX(${translateX}px)`); + } + + if (isNumber(translateY) && translateY !== 0) { + values.push(`translateY(${translateY}px)`); + } + + // Rotate should come first before scale to match orientation transform + if (isNumber(rotate) && rotate !== 0) { + values.push(`rotate(${rotate}deg)`); + } + + if (isNumber(scaleX) && scaleX !== 1) { + values.push(`scaleX(${scaleX})`); + } + + if (isNumber(scaleY) && scaleY !== 1) { + values.push(`scaleY(${scaleY})`); + } + + const transform = values.length ? values.join(' ') : 'none'; + + return { + WebkitTransform: transform, + msTransform: transform, + transform, + }; +} diff --git a/packages/func/src/number/index.ts b/packages/func/src/number/index.ts index 27d3321..2978eb8 100644 --- a/packages/func/src/number/index.ts +++ b/packages/func/src/number/index.ts @@ -25,3 +25,14 @@ export const setNumberAccuracy = (originNumber: number, accuracy = 0, isCeil = t } return returnData; }; + +/** + * 获取数字 + * @param number 需要校验的数值 + * @returns @number + */ +export const toRealNumber = (number: any) => { + if (isNaN(number) || number === Infinity) { + return 0; + } else return number; +}; diff --git a/packages/func/src/time/index.ts b/packages/func/src/time/index.ts index c70c161..e0f5c52 100644 --- a/packages/func/src/time/index.ts +++ b/packages/func/src/time/index.ts @@ -47,3 +47,14 @@ export function generateTime() { let startDateTime = dayjs().startOf('day').unix(); return { startDateTime, endDateTime }; } + +/** + * 格式化时间为 00:00 + * @param seconds 时间,单位秒 + * @returns + */ +export function formatDurationTime(seconds: number) { + var minutes = Math.floor(seconds / 60) || 0; + var remainingSeconds = Math.floor(seconds % 60); + return (minutes < 10 ? `0${minutes}` : minutes) + ":" + (remainingSeconds < 10 ? "0" : "") + remainingSeconds; +} diff --git a/packages/func/src/upload/index.ts b/packages/func/src/upload/index.ts new file mode 100644 index 0000000..1224ba3 --- /dev/null +++ b/packages/func/src/upload/index.ts @@ -0,0 +1,58 @@ +import dayjs from "dayjs"; +import { getFileSuffix, getImageSuffixByFileType } from "../utils"; +import base64 from "base-64"; +import { v4 as uuidV4 } from 'uuid' +import { get } from "lodash-es"; +import request from '@zhst/request' + +//小文件上传走s3 +const defaultBucket = 'public'; +type uploadOption = { + bucket?: string; + dir?: string; + withSuFuffix?: boolean; +}; + +export const commonUpload = async (file: File, option: uploadOption = {}, type: string) => { + const { bucket = defaultBucket, dir = 'file', withSuFuffix = false } = option; + const prefix = `${dayjs().format('YYYYMMDD')}`; + const fileSuffix = withSuFuffix ? getFileSuffix(get(file, 'name')) : ''; + const fileType = file['type'].split('/', 2); + let imageSuffix = ''; + if (fileType['0'] === 'image') { + imageSuffix = getImageSuffixByFileType(fileType['1']); + } + + const key = `${prefix}/${dir ? `${dir}/` : ''}${uuidV4()}${!fileSuffix ? '' : `.${fileSuffix}`}`; + let imgKey = `${bucket}_${bucket}_${key}${imageSuffix}`; //后端约定 见https://docs.qq.com/doc/DUklodHNxUGl2U3NM》 + if (type === 'upload') { + imgKey = `v1_${base64.encode(imgKey)}`; + return new Promise((resolve) => { + const reader = new FileReader(); + reader.readAsDataURL(file); + reader.onload = async () => { + if (reader.result) { + await request({ + method: 'PUT', + url: '/singer.FileServerService/PutObject', + data: { + version: 1, + bucket: defaultBucket, + objectName: `${bucket}_${key}${imageSuffix}`, + // fileData: reader.result, + putObjectOption: { + contentType: file.type, + }, + fileDataBase64: reader.result?.split(';base64,')[1], + }, + }); + resolve(imgKey); + } + }; + }); + } +}; + +export const upload = async (file: File, option: uploadOption = {}) => { + return await commonUpload(file, option, 'upload'); +}; diff --git a/packages/func/src/utils/index.ts b/packages/func/src/utils/index.ts index bb2f557..18e20e9 100644 --- a/packages/func/src/utils/index.ts +++ b/packages/func/src/utils/index.ts @@ -1,3 +1,4 @@ +import { isNumber } from 'lodash-es'; import ReactDOM from 'react-dom'; export { default as isChrome } from './isChrome'; @@ -90,7 +91,7 @@ export const loop = (items: string | any[], callback: (arg0: any) => any) => { } }; -export const addEventListener = (target: any, eventType: string, cb: any, option?: any) => { +export const addEventListenerWrapper = (target: any, eventType: string, cb: any, option?: any) => { /* eslint camelcase: 2 */ const callback = ReactDOM.unstable_batchedUpdates ? function run(e: any) { @@ -109,3 +110,54 @@ export const addEventListener = (target: any, eventType: string, cb: any, option }, }; } + + +/** + * Get transforms base on the given object. + * @param {Object} obj - The target object. + * @returns {string} A string contains transform values. + */ +export function getTransforms({ + rotate, + scaleX, + scaleY, + translateX, + translateY, +}: { + rotate?: number; + scaleX?: number; + scaleY?: number; + translateX?: number; + translateY?: number; +}) { + const values = []; + + if (isNumber(translateX) && translateX !== 0) { + values.push(`translateX(${translateX}px)`); + } + + if (isNumber(translateY) && translateY !== 0) { + values.push(`translateY(${translateY}px)`); + } + + // Rotate should come first before scale to match orientation transform + if (isNumber(rotate) && rotate !== 0) { + values.push(`rotate(${rotate}deg)`); + } + + if (isNumber(scaleX) && scaleX !== 1) { + values.push(`scaleX(${scaleX})`); + } + + if (isNumber(scaleY) && scaleY !== 1) { + values.push(`scaleY(${scaleY})`); + } + + const transform = values.length ? values.join(' ') : 'none'; + + return { + WebkitTransform: transform, + msTransform: transform, + transform, + }; +} diff --git a/packages/hooks/package.json b/packages/hooks/package.json index c8e7af2..1c0dba5 100644 --- a/packages/hooks/package.json +++ b/packages/hooks/package.json @@ -13,7 +13,7 @@ "lib/**/style/*", "*.less" ], - "main": "lib/index.tsx", + "main": "lib/index.js", "module": "es/index.js", "typings": "es/index.d.ts", "exports": { @@ -31,6 +31,9 @@ "access": "public", "registry": "http://10.0.0.77:4874" }, + "devDependencies": { + "@zhst/types": "workspace:^" + }, "dependencies": { "@zhst/func": "workspace:^", "ahooks": "^3.7.8", diff --git a/packages/material/package.json b/packages/material/package.json index c8431cf..93f39cf 100644 --- a/packages/material/package.json +++ b/packages/material/package.json @@ -16,7 +16,7 @@ "lib/**/style/*", "*.less" ], - "main": "lib/index.tsx", + "main": "lib/index.js", "module": "es/index.js", "typings": "es/index.d.ts", "files": [ diff --git a/packages/meta/package.json b/packages/meta/package.json index 1f16a8a..511d81a 100644 --- a/packages/meta/package.json +++ b/packages/meta/package.json @@ -14,7 +14,7 @@ "lib/**/style/*", "*.less" ], - "main": "lib/index.tsx", + "main": "lib/index.js", "module": "es/index.js", "typings": "es/index.d.ts", "exports": { @@ -32,13 +32,20 @@ "access": "public", "registry": "http://10.0.0.77:4874" }, + "devDependencies": { + "@zhst/types": "workspace:^" + }, "dependencies": { "@turf/boolean-point-in-polygon": "^6.5.0", "@turf/turf": "^6.5.0", + "@types/downloadjs": "^1.4.6", "@zhst/func": "workspace:^", "@zhst/hooks": "workspace:^", "antd": "^5.12.5", "classnames": "^2.5.1", + "downloadjs": "^1.4.7", + "flv.js": "^1.6.2", + "rc-align": "^4.0.15", "rc-util": "^5.38.1", "react": "^18.0.0", "react-dom": "^18.0.0" diff --git a/packages/meta/src/BigImagePreview/components/BtnGroup/index.less b/packages/meta/src/BigImagePreview/components/BtnGroup/index.less new file mode 100644 index 0000000..db03187 --- /dev/null +++ b/packages/meta/src/BigImagePreview/components/BtnGroup/index.less @@ -0,0 +1,51 @@ +.zhst-image__btn-group { + // display: flex; + width: 30px; + box-shadow: 0 2px 6px 0 rgb(0 0 0 / 40%); + + &__item { + display: flex; + width: 30px; + height: 30px; + align-items: center; + justify-content: center; + background: #000; + + &>button { + padding: 0; + color: #fff; + + &:hover { + color: #09f; + } + + &:active { + color: #09f; + } + + &:focus { + color: #fff; + } + + &>span { + display: flex; + } + } + + &--active { + &>button { + color: #09f; + } + } + } + + &--circle { + background-color: none; + box-shadow: none; + } + + &--circle &__item { + margin-bottom: 4px; + border-radius: 50%; + } +} diff --git a/packages/meta/src/BigImagePreview/components/BtnGroup/index.tsx b/packages/meta/src/BigImagePreview/components/BtnGroup/index.tsx new file mode 100644 index 0000000..ba70c12 --- /dev/null +++ b/packages/meta/src/BigImagePreview/components/BtnGroup/index.tsx @@ -0,0 +1,57 @@ +import React, { MouseEvent } from 'react'; +import classNames from 'classnames'; +import { Button, Tooltip, TooltipProps } from 'antd'; +import Icon from '../../../iconfont'; +import './index.less'; + +const componentName = `zhst-image__btn-group`; + +export interface BtnGroupProps { + className: string; + dataSource: Array<{ key: string; icon: string; title: string }>; + onClick: (v: string, e: MouseEvent) => void; + selectKey?: string; + circle?: boolean; + placement?: TooltipProps['placement']; +} +export const BtnGroup: React.FC = (props) => { + const { dataSource, onClick, className, circle, selectKey = '', placement = 'right' } = props; + + return ( +
+ {dataSource.map(({ key, icon, title }) => { + const isSelect = key === selectKey; + return ( + +
+ +
+
+ ); + })} +
+ ); +}; + +BtnGroup.displayName = 'BtnGroup'; + +export default BtnGroup; diff --git a/packages/meta/src/BigImagePreview/components/ScreenhotButtons/index.less b/packages/meta/src/BigImagePreview/components/ScreenhotButtons/index.less new file mode 100644 index 0000000..ca407fa --- /dev/null +++ b/packages/meta/src/BigImagePreview/components/ScreenhotButtons/index.less @@ -0,0 +1,21 @@ +.bigImageWrapper--v2__screenshot { + min-width: 90px; + background: rgb(0 0 0 / 50%); + border-radius: 0; + + &>button { + width: 100%; + color: #fff !important; + font-family: 'Microsoft YaHei'; + font-size: 12px !important; + border-radius: 0; + + &>span { + color: #fff; + } + + &:hover { + background-color: #09f !important; + } + } +} diff --git a/packages/meta/src/BigImagePreview/components/ScreenhotButtons/index.tsx b/packages/meta/src/BigImagePreview/components/ScreenhotButtons/index.tsx new file mode 100644 index 0000000..8ce3fdb --- /dev/null +++ b/packages/meta/src/BigImagePreview/components/ScreenhotButtons/index.tsx @@ -0,0 +1,106 @@ +import React from'react' +import { Button } from 'antd'; +import classNames from 'classnames'; +import type { AlgorithmVersion } from '@zhst/types' +import { IBigImageOpt } from '@zhst/types/BigImageModal' +import './index.less'; + +const componentName = 'bigImageWrapper--v2'; + +interface IScreenShotButton { + getCropInfo: () => void + setShowCrop: any + cropType: string + selectAlgorithmVersion: AlgorithmVersion +} + +const getScreenshotButtonRender = (arg: { + disableBtn: number[]; + onBigImageActionClick: (type: number, item: any) => void; +}) => { + const { disableBtn = [], onBigImageActionClick } = arg; + return (param: IScreenShotButton) => { + const { getCropInfo, setShowCrop, cropType, selectAlgorithmVersion } = param; + let isAuto = cropType === 'AUTO'; + + return ( +
+ {!disableBtn.includes(IBigImageOpt['ADD_HISTORY_WITH_CROP']) && isAuto && ( + + )} + {!disableBtn.includes(IBigImageOpt['ADD_HISTORY_WITH_CROP_BODY']) && !isAuto && ( + + )} + {!disableBtn.includes(IBigImageOpt['ADD_HISTORY_WITH_CROP_VEHICLE']) && !isAuto && ( + + )} + {!disableBtn.includes(IBigImageOpt['ADD_HISTORY_WITH_CROP_ARCHIVE']) && + selectAlgorithmVersion !== 0 && ( + + )} + +
+ ); + }; +}; + +export default getScreenshotButtonRender; diff --git a/packages/meta/src/BigImagePreview/index.less b/packages/meta/src/BigImagePreview/index.less new file mode 100644 index 0000000..829ebe1 --- /dev/null +++ b/packages/meta/src/BigImagePreview/index.less @@ -0,0 +1,129 @@ +.zhst-image__img-view { + position: relative; + width: calc(100%); + height: 100%; + + &__face-score { + position: absolute; + right: 20px; + bottom: 80px; + color: red; + font-family: 'Microsoft YaHei'; + font-size: 19px; + font-weight: bold; + } + + &-opt { + position: absolute; + z-index: 99; + top: 0; + } + + &-crop-opt { + position: absolute; + z-index: 99; + top: 0; + right: 0; + } + + &-align { + position: absolute; + top: 0; + left: 0; + pointer-events: none; + } + + &-main { + width: 100%; + height: 100%; + font-size: 0; + + &--cursor { + & canvas { + min-height: 320px; + cursor: pointer; + } + } + } + + &-screenshot { + position: absolute; + z-index: 10; + } + + &-attach { + position: absolute; + z-index: 11; + bottom: 0; + + // left: 78px; + left: 0; + min-width: 120px; + height: 202px; + transition: all 200ms; + + &--fixed { + } + + &--zoomin { + height: 100%; + + &--fixed { + } + } + + &__tab { + position: absolute; + top: 0; + left: 0; + display: flex; + + &-item { + display: flex; + width: 30px; + height: 24px; + align-items: center; + justify-content: center; + background: #000; + color: #fff; + cursor: pointer; + font-size: 12px; + opacity: 0.5; + transition: all 200ms; + + &--select { + width: 48px; + height: 34px; + background: #09f; + opacity: 1; + } + } + } + + &__scale { + position: absolute; + top: 4px; + right: 4px; + display: flex; + width: 30px; + height: 30px; + align-items: center; + justify-content: center; + background: rgb(0 0 0 / 60%); + border-radius: 100%; + cursor: pointer; + line-height: 30px; + text-align: center; + } + + &__img { + height: 100%; + object-fit: contain; + + &--fixed { + width: 100%; + object-fit: contain; + } + } + } +} diff --git a/packages/meta/src/BigImagePreview/index.md b/packages/meta/src/BigImagePreview/index.md new file mode 100644 index 0000000..c968aee --- /dev/null +++ b/packages/meta/src/BigImagePreview/index.md @@ -0,0 +1,62 @@ +--- +nav: + title: 元组件 + order: 1 +group: + title: 通用 + order: 3 +--- + +# BigImagePreview 大图预览组件 + +```jsx +import React, { useState, useRef } from 'react'; +import { Button, Space } from 'antd' +import { BigImagePreview } from '@zhst/meta' + + +const props = { + imageKey:"http://10.0.0.120:30003/file/singer-20240110/1/5/1744894622934503424.jpg", + odRect:{ + "x":0.5445312, + "y":0.19166666, + "w":0.08671875, + "h":0.40138888 + }, + heigth: '500px', + attachImg: [ + { + "url": "http://10.0.0.120:30003/file/singer-20240110/1/5/1744894622695428096.jpg","label": "形体" + },{ + "url": "http://10.0.0.120:30003/file/singer-20240110/1/5/1744894588427964418.jpg", + "label": "人脸" + } + ], + score: 0.891417, + objects: [{"objectIndex":{"objectId":"1745329264976201728","solutionId":"0","deviceId":"0","fragmentId":"0"},"objectType":"OBJECT_TYPE_PEDESTRAIN","sourceObjectId":"0","level":0,"confidence":0.8910453,"pathInfo":null,"frameInfo":{"frameId":"0","frameTimestamp":"1704953898021","width":0,"height":0,"originWidth":0,"originHeight":0,"offsetTime":"0","skipNumber":"0"},"deviceInfo":null,"infoOnSource":{"bboxInSource":null,"bboxInFrame":{"bbox":null,"bboxRatio":{"x":0.69192713,"y":0.53585213,"w":0.031508446,"h":0.12733544},"extendBbox":null,"extendBoxRatio":null},"countInSource":0,"indexInSource":0},"qualityScore":0,"frameImage":null,"objectImage":null,"objectExtImage":null,"feature":[{"name":"feature-body","type":"FEATURE_TYPE_BYTE","featureId":"0","featureByte":"","featureBool":[],"featureUint8":[],"featureUint16":[],"featureUint32":[],"featureUint64":[],"featureInt8":[],"featureInt16":[],"featureInt32":[],"featureInt64":[],"featureFloat32":[],"featureString":[]},{"name":"property-body","type":"FEATURE_TYPE_FLOAT32","featureId":"0","featureByte":"","featureBool":[],"featureUint8":[],"featureUint16":[],"featureUint32":[],"featureUint64":[],"featureInt8":[],"featureInt16":[],"featureInt32":[],"featureInt64":[],"featureFloat32":[0.8251953,0.40527344,0.4567871,0.20178223,0.26220703,0.5083008,0.36499023,0.045196533,0.92822266,0.08300781,0.9663086,0.71533203,0.112976074,0.3935547,0.25048828,0.11694336,0.5317383,0.26293945,0.13134766,0.11657715,0.4868164,0.3647461,0.06903076,0.234375,0.84472656,0.07684326,0.08227539,0.035827637,0.11315918,0.0637207,0.1850586,0.057495117,0.9013672,0.15673828,0.14099121,0.040618896,0.08270264,0.076538086,0.828125,0.055419922,0.038391113,0.03137207,0.07574463,0.08105469,0.05340576,0.023330688,0.25561523,0.05090332,0.17480469,0.73779297,0.49169922,0.63500977,0.033691406],"featureString":[]}],"subObjects":[]},{"objectIndex":{"objectId":"1745329264976201729","solutionId":"0","deviceId":"0","fragmentId":"0"},"objectType":"OBJECT_TYPE_PEDESTRAIN","sourceObjectId":"0","level":0,"confidence":0.74931294,"pathInfo":null,"frameInfo":{"frameId":"0","frameTimestamp":"1704953898021","width":0,"height":0,"originWidth":0,"originHeight":0,"offsetTime":"0","skipNumber":"0"},"deviceInfo":null,"infoOnSource":{"bboxInSource":null,"bboxInFrame":{"bbox":null,"bboxRatio":{"x":0.73869747,"y":0.5493781,"w":0.025924563,"h":0.11845186},"extendBbox":null,"extendBoxRatio":null},"countInSource":0,"indexInSource":0},"qualityScore":0,"frameImage":null,"objectImage":null,"objectExtImage":null,"feature":[{"name":"feature-body","type":"FEATURE_TYPE_BYTE","featureId":"0","featureByte":"","featureBool":[],"featureUint8":[],"featureUint16":[],"featureUint32":[],"featureUint64":[],"featureInt8":[],"featureInt16":[],"featureInt32":[],"featureInt64":[],"featureFloat32":[],"featureString":[]},{"name":"property-body","type":"FEATURE_TYPE_FLOAT32","featureId":"0","featureByte":"","featureBool":[],"featureUint8":[],"featureUint16":[],"featureUint32":[],"featureUint64":[],"featureInt8":[],"featureInt16":[],"featureInt32":[],"featureInt64":[],"featureFloat32":[0.41308594,0.33789062,0.5917969,0.17590332,0.7392578,0.3046875,0.5053711,0.017181396,0.94677734,0.19189453,0.8696289,0.21728516,0.14611816,0.27514648,0.5161133,0.49414062,0.77978516,0.25952148,0.26586914,0.07751465,0.15344238,0.2680664,0.82958984,0.13134766,0.41992188,0.118774414,0.04046631,0.13342285,0.16113281,0.16186523,0.07922363,0.044525146,0.9760742,0.19250488,0.22131348,0.044921875,0.046539307,0.040161133,0.9453125,0.04751587,0.1361084,0.013069153,0.049316406,0.0385437,0.06903076,0.056762695,0.047790527,0.09057617,0.58691406,0.2607422,0.6953125,0.4946289,0.1303711],"featureString":[]}],"subObjects":[]}] +} + +export default () => { + const imgRef = useRef(null) + + return ( + + + + + + + + ) +} +``` + +| 参数名 | 参数类型 | 参数说明 | +| ------ | -------- | ---- | +| imageKey | string(必填) | 当前大图链接 | +| odRect | { x: number; y: number; w: number; h: number } | 圈选矩形 | +|height|string(选填)|高度| +|width|string(选填)|宽度| +|score|string(选填)|相似度| +|attachImg|{ url: string; label: string; }[](选填)|缩略图| +|objects | IOdRectOrigin[] | 编辑状态参数 | diff --git a/packages/meta/src/BigImagePreview/index.tsx b/packages/meta/src/BigImagePreview/index.tsx new file mode 100644 index 0000000..36dc99f --- /dev/null +++ b/packages/meta/src/BigImagePreview/index.tsx @@ -0,0 +1,540 @@ +import React, { useEffect, ReactElement, useState, useCallback, useRef, useImperativeHandle } from 'react'; +import classNames from 'classnames'; +import { useLatest } from '@zhst/hooks'; +import { + get, + pick, + isNull, + generateImg, + dataURLToBlob, + getOdRect, + getExtendRect, + getTransformRect, + getRotateImg, + getTransforms, + addEventListenerWrapper, + upload, + getFileByRect +} from '@zhst/func'; +import Align from 'rc-align'; +import { Button } from 'antd'; +import type { Rect, IScreenshotButtonProp, ODRECT, AlignType, ViewOption, IOdRectOrigin } from '@zhst/types' +import Icon from '../iconfont'; +import { + Cropper, + Viewer, + EVENT_VIEWER_TRANSFORM_CHANGE, + EVENT_VIEWER_READY, + EVENT_CROP_START, + EVENT_CROP_END, +} from '../ImageEditor'; +import BtnGroup from './components/BtnGroup'; +import './index.less' +import getScreenshotButtonRender from './components/ScreenhotButtons'; + +const componentName = `zhst-image__img-view`; + +export const CROP_TYPE = { + CUSTOM: 'CSUTOM', + AUTO: 'AUTO', +}; + +export const defaultAlignOption = { + points: ['bl', 'br'], + offset: [6, 0], + overflow: { + adjustX: true, + adjustY: true, + }, +}; + +export interface ImgViewProps extends React.HTMLAttributes { + imageKey: string; //不在监听url变化 更新走销毁 + odRect: ODRECT; + attachImg?: Array<{ label: string; url: string }>; // 缩略图列表 + showAttachImgLabel: boolean; // 是否显示缩略图 + showOpt: boolean; // 是否显示操作面板 + width?: string | number; + height?: string | number; + /* 截图渲染 */ + screenshotButtonAlign: AlignType; + screenshotButtonRender: (screenshotButtonProp: IScreenshotButtonProp) => ReactElement; + hideLeftTopBtn?: boolean; + score?: number; + viewOption?: ViewOption; + objects: IOdRectOrigin[] +} +export interface ImgViewRef { + /* 图片实例 */ + imgInsRef: React.MutableRefObject; + /* 切换编辑模式 */ + setShowCrop: React.Dispatch>; +} + +const cropBtnDataSource = [ + { + key: 'close', + icon: 'icon-danchuangguanbi', + title: '退出', + }, + { + key: 'autoCrop', + icon: 'icon-zidong', + title: '智能框选', + }, + { + key: 'customCrop', + icon: 'icon-shoudong', + title: '手动框选', + }, +]; + +const operateBtnDataSource = [ + { + key: 'zoomOut', + icon: 'icon-fangda', + title: '放大', + }, + { + key: 'zoomIn', + icon: 'icon-suoxiao', + title: '缩小', + }, + { + key: 'reset', + icon: 'icon-zhongzhi3', + title: '重置图片', + }, +]; + +export const ImgView = React.forwardRef((props, ref) => { + const { + imageKey, + width, + height, + odRect, + score = 0, + attachImg = [], + objects = [], + showOpt = false, + showAttachImgLabel = true, + screenshotButtonAlign = defaultAlignOption, + screenshotButtonRender = getScreenshotButtonRender({ + onBigImageActionClick: () => {}, + disableBtn: [], + }), + hideLeftTopBtn = true, + viewOption = {} + } = props; + const imgContainerRef = React.useRef(null); + const [isReady, setIsReady] = useState(false); + + console.log('props', props) + + const init = useCallback(($container: null) => { + imgContainerRef.current = $container; + setIsReady(true); + }, []); + // ============================= viewer ========================= + const imgInsRef = useRef(null); + const [isImgReady, setIsImgReady] = useState(false); + + useEffect(() => { + if (!isReady) return; + const handleReady = addEventListenerWrapper(imgContainerRef.current, EVENT_VIEWER_READY, () => { + setIsImgReady(true); + }); + const handleTransformChange = addEventListenerWrapper( + imgContainerRef.current, + EVENT_VIEWER_TRANSFORM_CHANGE, + () => { + } + ); + imgInsRef.current = new Viewer(imgContainerRef.current, { + ...viewOption, + fitScaleAsMinScale: true, + image: generateImg(imageKey), + }); + return () => { + handleReady?.remove(); + handleTransformChange?.remove(); + imgInsRef?.current?.destroy?.(); + imgInsRef.current = null; + }; + }, [isReady, imageKey]); + + // ============================= viewer操作按钮 ========================= + const handleOptClick = (v: string) => { + switch (v) { + case 'zoomOut': + imgInsRef?.current?.scaleTo?.(0.1); + break; + case 'zoomIn': + imgInsRef?.current?.scaleTo?.(-0.1); + break; + case 'reset': + imgInsRef?.current?.reset?.(-0.1); + break; + } + }; + + // ============================= cropper ========================= + // 手动截图相关参数 + const cropInsRef = useRef(null); + const [showCrop, setShowCrop] = useState(showOpt); + const [cropType, setCropType] = useState(CROP_TYPE['AUTO']); + + // 自动截图相关参数 + const [odList, setOdList] = useState([]); + const [extendOdList, setExtendOdList] = useState([]); + const [selectRectId, setSelectRectId] = useState(null); + + // 定位按钮相关参数 + const aliginContainerRef = useRef(null); + const alignRef = useRef(null); + const [cropRect, setCropRect] = useState(null); + + // 选中的版本号 + const [selectAlgorithmVersion, setSelectAlgorithmVersion] = useState(null); + const handlerCropStartRef = useRef(null); + const handlerCropEndRef = useRef(null); + const handleShapeSelectRef = useRef(null); + + useEffect(() => { + initData(objects) + return () => { + imgInsRef.current?.clearShape?.(); + handlerCropStartRef.current?.remove(); + handlerCropEndRef.current?.remove(); + handleShapeSelectRef.current?.remove(); + cropInsRef?.current?.destroy?.(); + cropInsRef.current = null; + }; + }, [isImgReady, showCrop, cropType]); + + const initData = (_objects: IOdRectOrigin[]) => { + const imgIns = imgInsRef.current; + //清理crop + setCropRect(null); + if (!isImgReady) return; + if (!showCrop) { + imgIns?.addShape?.({ + x: get(odRect, 'x', 0), + y: get(odRect, 'y', 0), + w: get(odRect, 'w', 0), + h: get(odRect, 'h', 0), + selectAble: false, + }); + return; + } + if (cropType === CROP_TYPE['AUTO']) { + const handleGetOD = (odList: any) => { + const imgSize = imgIns.getImgSize(); + const shapeList = odList.map((rect: { [x: string]: any; algorithmVersion: any; }) => ({ + ...rect, + selectAble: true, + id: rect['id'], + algorithmVersion: rect.algorithmVersion, + })); + imgIns.replaceShape(shapeList); + //顺便吧扩展框拿到 + const extendRect = shapeList.map((rect: { algorithmVersion: string; }) => { + const extendRect = getExtendRect(rect, imgSize.w, imgSize.h, rect.algorithmVersion); + return { ...rect, ...extendRect }; + }); + setExtendOdList(extendRect); + imgIns.replaceShape(shapeList); + handleShapeSelectRef.current = addEventListenerWrapper(imgContainerRef.current, 'shape-select', (e) => { + const id = e.detail; + setSelectRectId(id); + const selectShape = shapeList.find((v) => v['id'] === id); + if (selectShape) { + setSelectAlgorithmVersion(selectShape['algorithmVersion']); + //换算成屏幕坐标 + const axisRect = imgIns.imgRectAxisToCanvasAxisRect(selectShape); + const rect = { + x: axisRect.x2 > axisRect.x ? axisRect.x : axisRect.x2, + y: axisRect.y2 > axisRect.y ? axisRect.y : axisRect.y2, + w: Math.abs(axisRect.x2 - axisRect.x), + h: Math.abs(axisRect.y2 - axisRect.y), + }; + setCropRect(rect); + } else { + // @ts-ignore + setCropRect(null); + } + }); + }; + const rect = getOdRect({ objects }) + setOdList(rect); + handleGetOD(rect); + } + + if (cropType === CROP_TYPE['CUSTOM']) { + // 手动框选状态预先清除imgIns + imgIns?.clearShape?.(); + handlerCropStartRef.current = addEventListenerWrapper(imgContainerRef.current, EVENT_CROP_START, (event) => { + setSelectAlgorithmVersion(null); + setCropRect(null); + }); + handlerCropEndRef.current = addEventListenerWrapper(imgContainerRef.current, EVENT_CROP_END, (event) => { + const data = event.detail; + setSelectAlgorithmVersion(null); + setCropRect({ + x: data.left, + y: data.top, + w: data.width, + h: data.height, + }); + alignRef?.current?.forceAlign?.(); + }); + cropInsRef.current = new Cropper(imgContainerRef.current, { + showMask: true, + viewer: imgIns, + }); + } + } + + // 获取框选的截图框信息 + const latestCropType = useLatest(cropType); + const latestImgKey = useLatest(imageKey); + const latestCropRect = useLatest(cropRect); + const getCropInfo = async () => { + const cropType = latestCropType.current; + const cropRect = latestCropRect.current; + const imgIns = imgInsRef.current; + const transform = imgIns.targetTransform; + let newImgKey = latestImgKey.current; + let rectList = []; + let extendRectList = []; + let selectIndex = 0; + switch (cropType) { + case CROP_TYPE['AUTO']: + const shapes = imgIns.getSelectShape(); + const shapeIds = shapes.map((v) => v['id']); + rectList = odList + .filter((v) => shapeIds.includes(v['id'])) + .map((item: any) => { + if ( + item.algorithmVersion === 'OBJECT_TYPE_FACE' || + item.objectType === 'OBJECT_TYPE_FACE' + ) { + if (!isNull(item.extendBox)) { + return { + ...item, + w: get(item, 'extendBox.w'), + h: get(item, 'extendBox.h'), + x: get(item, 'extendBox.x'), + y: get(item, 'extendBox.y'), + }; + } + } else { + return item; + } + }); + extendRectList = extendOdList + .filter((v) => shapeIds.includes(v['id'])) + .map((v) => pick(v, ['x', 'y', 'w', 'h', 'algorithmVersion', 'id'])); + selectIndex = rectList.findIndex((v) => v['id'] === selectRectId); + break; + default: + //获取旋转过的坐标 + const newRect = getTransformRect(imgIns.image, transform, cropRect); + //判断是不是旋转过 + if (get(transform, 'rotate', 0) % 360 != 0) { + const data = getRotateImg(imgIns.image, get(transform, 'rotate', 0)); + //在画布上画旋转后的图片 + newImgKey = await upload(data); + } + rectList.push(newRect); + extendRectList.push(newRect); + break; + } + //扩展框获取imgkey + await Promise.all( + extendRectList.map(async (rect, index) => { + const file = await getFileByRect(imgIns.image, rect); + const imgKey = await upload(file); + extendRectList[index] = { ...rect, imgKey }; + }) + ); + //人脸图获取矫正图 + await Promise.all( + rectList.map(async (rect, index) => { + const faceCorrectImage = rect['faceCorrectImage']; + let faceCorrectImageKey; + if (faceCorrectImage) { + const base64 = `data:image/jpg;base64,${faceCorrectImage}`; + const blobData = dataURLToBlob(base64); + const file = new window.File([blobData], `${new Date().getTime()}`); + faceCorrectImageKey = await upload(file); + } + const newRect = { + ...rect, + ...(faceCorrectImageKey ? { faceCorrectImageKey } : {}), + }; + delete newRect['faceCorrectImage']; + rectList[index] = newRect; + }) + ); + return { rectList, extendRectList, selectIndex, imgKey: newImgKey }; + }; + + // 操作界面判断 + const handleCropBtnClick = (v: string) => { + switch (v) { + case 'close': + setShowCrop(false); + break; + case 'autoCrop': + setCropType(CROP_TYPE['AUTO']); + break; + case 'customCrop': + setCropType(CROP_TYPE['CUSTOM']); + break; + } + }; + + // ============================= attact img ========================= + const showAttachImg = attachImg.length !== 0; + const [selectAttachImgIndex, setSelectAttachImgIndex] = useState(0); + const [isZoomin, setIsZoomin] = useState(false); + + // ============================== Ref =============================== + useImperativeHandle(ref, () => ({ + imgInsRef, + setShowCrop, + initData, + })); + + return ( +
+ {/*场景图大图 */} +
+ {/* 图片操作 */} + {!hideLeftTopBtn && ( + + )} + {showCrop && ( + + )} + {showCrop && cropRect && screenshotButtonRender && ( + <> +
+ + {screenshotButtonRender({ + model: 'IMAGE', + getCropInfo, + setShowCrop, + cropType, + selectAlgorithmVersion, + })} + + + )} + {/* 场景图小图 */} + {showAttachImg && !showCrop && ( +
+
+ {showAttachImgLabel + ? attachImg.map(({ label, url }, index) => ( +
{ + setSelectAttachImgIndex(index); + }} + > + {label} +
+ )) + : null} +
+
+ +
+ +
+ )} +
{`人脸质量分:${(score as number).toFixed(2)}`}
+
+ ); +}); + +ImgView.displayName = 'ImgView'; + +export default ImgView; diff --git a/packages/meta/src/ImageEditor/cropper/event.ts b/packages/meta/src/ImageEditor/cropper/event.ts index 28036a1..09b4cd6 100644 --- a/packages/meta/src/ImageEditor/cropper/event.ts +++ b/packages/meta/src/ImageEditor/cropper/event.ts @@ -1,6 +1,6 @@ //@ts-nocheck import { addClass, removeClass } from 'rc-util/lib/Dom/class'; -import { addEventlistener, isNumber, get } from '@zhst/func'; +import { addEventListenerWrapper, isNumber, get } from '@zhst/func'; import warn from 'rc-util/lib/warn'; import { getData, getPointer, getOffset, dispatchEvent } from '../utils'; import { @@ -36,13 +36,13 @@ export default { bind() { const { container, element, eventHandleList = [], option } = this; - const handleCropStart = addEventlistener( + const handleCropStart = addEventListenerWrapper( container, EVENT_POINTER_DOWN, this.onCropStart.bind(this) ); eventHandleList.push(handleCropStart); - const handleCropMove = addEventlistener( + const handleCropMove = addEventListenerWrapper( element.ownerDocument, EVENT_POINTER_MOVE, this.onCropMove.bind(this) @@ -51,7 +51,7 @@ export default { EVENT_POINTER_UP.trim() .split(REGEXP_SPACES) .forEach((eventName) => { - const handleCropEnd = addEventlistener( + const handleCropEnd = addEventListenerWrapper( element.ownerDocument, eventName, this.onCropEnd.bind(this) diff --git a/packages/meta/src/ImageEditor/cropper/viewerBridge.ts b/packages/meta/src/ImageEditor/cropper/viewerBridge.ts index 43662ef..ec9159c 100644 --- a/packages/meta/src/ImageEditor/cropper/viewerBridge.ts +++ b/packages/meta/src/ImageEditor/cropper/viewerBridge.ts @@ -1,5 +1,5 @@ //@ts-nocheck -import {addEventlistener} from '@zhst/func'; +import {addEventListenerWrapper} from '@zhst/func'; import { EVENT_WHEEL } from './constants'; import { EVENT_VIEWER_TRANSFORM_CHANGE } from '../viewer/constants'; @@ -10,12 +10,12 @@ export default { if (this.options.viewer) { const viewer = this.options.viewer; //添加缩放事件 - const handleWhele = addEventlistener(container, EVENT_WHEEL, this.onWheel.bind(this)); + const handleWhele = addEventListenerWrapper(container, EVENT_WHEEL, this.onWheel.bind(this)); eventHandleList.push(handleWhele); //添加事件监听 获取limit crop box & 渲染canvas this.onTransformChange(viewer); this.limited = true; - const handleTransformChange = addEventlistener( + const handleTransformChange = addEventListenerWrapper( viewer.element, EVENT_VIEWER_TRANSFORM_CHANGE, (event) => { diff --git a/packages/meta/src/ImageEditor/viewer/event.ts b/packages/meta/src/ImageEditor/viewer/event.ts index 810b980..de1cd71 100644 --- a/packages/meta/src/ImageEditor/viewer/event.ts +++ b/packages/meta/src/ImageEditor/viewer/event.ts @@ -1,5 +1,5 @@ //@ts-nocheck -import { isNumber, get, addEventListener } from '@zhst/func'; +import { isNumber, get, addEventListenerWrapper } from '@zhst/func'; import { addClass, removeClass } from 'rc-util/lib/Dom/class.js'; import guid from 'rc-util/lib/guid'; import warn from 'rc-util/lib/warn'; @@ -33,19 +33,19 @@ export default { //图片事件 const scaleAble = get(options, 'scaleAble', true); if (scaleAble) { - const handleWhele = addEventListener(canvas, EVENT_WHEEL, this.onWheel.bind(this)); + const handleWhele = addEventListenerWrapper(canvas, EVENT_WHEEL, this.onWheel.bind(this)); eventHandleList.push(handleWhele); } const dragAble = get(options, 'dragAble', true); if (dragAble) { - const handleDragStart = addEventListener( + const handleDragStart = addEventListenerWrapper( canvas, EVENT_POINTER_DOWN, this.onDragStart.bind(this) ); - eventHandleList.push(addEventListener); - const handleDragMove = addEventListener( + eventHandleList.push(addEventListenerWrapper); + const handleDragMove = addEventListenerWrapper( element.ownerDocument, EVENT_POINTER_MOVE, this.onDragMove.bind(this) @@ -54,7 +54,7 @@ export default { EVENT_POINTER_UP.trim() .split(REGEXP_SPACES) .forEach((eventName) => { - const handleDragEnd = addEventListener( + const handleDragEnd = addEventListenerWrapper( element.ownerDocument, eventName, this.onDragEnd.bind(this) @@ -64,11 +64,11 @@ export default { } //rect事件 - const handleClick = addEventListener(canvas, EVENT_CLICK, this.onClick.bind(this)); + const handleClick = addEventListenerWrapper(canvas, EVENT_CLICK, this.onClick.bind(this)); eventHandleList.push(handleClick); - // const handleLeveal = addEventListener(canvas, EVENT_LEAVEL, this.onLeavel.bind(this)); + // const handleLeveal = addEventListenerWrapper(canvas, EVENT_LEAVEL, this.onLeavel.bind(this)); // eventHandleList.push(handleLeveal); - // const handleEnter = addEventListener(canvas, EVENT_ENTER, this.onEnter.bind(this)); + // const handleEnter = addEventListenerWrapper(canvas, EVENT_ENTER, this.onEnter.bind(this)); // eventHandleList.push(handleEnter); }, unbind() { diff --git a/packages/meta/src/ImagePreview/index.tsx b/packages/meta/src/ImagePreview/index.tsx index 1986e10..03e8d5c 100644 --- a/packages/meta/src/ImagePreview/index.tsx +++ b/packages/meta/src/ImagePreview/index.tsx @@ -1,5 +1,5 @@ import React, { useRef, useState, FC, useEffect, useCallback } from 'react' -import { generateImg, get, addEventListener } from '@zhst/func'; +import { generateImg, get, addEventListenerWrapper } from '@zhst/func'; import { useUpdateEffect } from '@zhst/hooks'; import { Button } from 'antd'; import classNames from 'classnames' @@ -43,7 +43,7 @@ const CompaterImage: FC = (props) => { useEffect(() => { setShowUrl(url); - const handleTransformChange = addEventListener( + const handleTransformChange = addEventListenerWrapper( imgContainerRef.current, 'viewer-transform-change', (event: any) => { diff --git a/packages/meta/src/VideoPlayer/components/FlvPlayer/index.tsx b/packages/meta/src/VideoPlayer/components/FlvPlayer/index.tsx new file mode 100644 index 0000000..edc23e5 --- /dev/null +++ b/packages/meta/src/VideoPlayer/components/FlvPlayer/index.tsx @@ -0,0 +1,116 @@ +import React, { Component, CSSProperties } from 'react'; +import flvjs from 'flv.js'; +import { isEqual } from '@zhst/func'; + +export const FLV_EVENT = flvjs.Events; + +export interface VideoPlayerProps { + className: string; + style?: CSSProperties; + type: string; + isLive?: boolean; + cors?: boolean; + withCredentials?: boolean; + playId?: number; + + hasAudio?: boolean; + hasVideo?: boolean; + + duration?: number; + filesize?: number; + url?: string; + autoPlay?: boolean; + onCreat?: any; + + /** + * @see https://github.com/Bilibili/flv.js/blob/master/docs/api.md#config + */ + config: object; +} + +export default class VideoPlayer extends Component { + state = { + curPlayUrl: '', + shouldReinit: false, + }; + flvPlayer = null; + videoElement = null; + + static getDerivedStateFromProps = (nextProps: { url?: any; playId?: any; }, prevState: { curPlayUrl?: any; playId?: any; }) => { + const { playId = 0 } = nextProps; + const { playId: prePlayId = 0 } = prevState; + + if (nextProps.url !== undefined) { + if (!isEqual(nextProps.url, prevState.curPlayUrl) || !isEqual(playId, prePlayId)) { + return { + playId: playId, + curPlayUrl: nextProps.url, + shouldReinit: true, + }; + } + } + // 否则,对于state不进行任何操作 + return null; + }; + + initFlv = ($video: null) => { + this.videoElement = $video; + const { className, autoPlay = true, config = {}, onCreat, playId, ...others } = this.props; + + if ($video) { + + if (flvjs.isSupported() && this.props.url && this.props.url !== '') { + const reload = () => { + + if (this.flvPlayer && this.flvPlayer.destroy) { + try { + this.flvPlayer?.destroy(); + } catch (error) { + console.error(error); + } + } + let flvPlayer = flvjs.createPlayer({ ...others }, config); + flvPlayer.attachMediaElement($video); + flvPlayer.load(); + this.flvPlayer = flvPlayer; + this.flvPlayer.reload = reload; + onCreat && onCreat(this.flvPlayer, $video); + }; + reload(); + onCreat && onCreat(this.flvPlayer, $video); + } + } + }; + + componentWillUnmount() { + if (this.flvPlayer) { + this.flvPlayer?.unload(); + this.flvPlayer?.detachMediaElement(); + } + } + componentDidUpdate() { + if (this.state.shouldReinit) { + this.setState({ shouldReinit: false }); + this.initFlv(this.videoElement); + } + } + render() { + const { className, style } = this.props; + return ( +