init
This commit is contained in:
19
miniprogram/miniprogram_npm/tdesign-miniprogram/common/shared/calendar/index.d.ts
vendored
Normal file
19
miniprogram/miniprogram_npm/tdesign-miniprogram/common/shared/calendar/index.d.ts
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import type { TDate, TCalendarType, TCalendarValue } from './type';
|
||||
export default class TCalendar {
|
||||
firstDayOfWeek: number;
|
||||
value: TCalendarValue | TCalendarValue[];
|
||||
type: TCalendarType;
|
||||
minDate: Date;
|
||||
maxDate: Date;
|
||||
format: (day: TDate) => TDate;
|
||||
constructor(options?: {});
|
||||
getTrimValue(): Date | Date[];
|
||||
getDays(weekdays: string[]): any[];
|
||||
getMonths(): any[];
|
||||
select({ cellType, year, month, date }: {
|
||||
cellType: any;
|
||||
year: any;
|
||||
month: any;
|
||||
date: any;
|
||||
}): Date | TCalendarValue[];
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
import{getDateRect,isSameDate,getMonthDateRect,isValidDate,getDate}from"../date";export default class TCalendar{constructor(e={}){this.type="single",Object.assign(this,e),this.minDate||(this.minDate=getDate()),this.maxDate||(this.maxDate=getDate(6))}getTrimValue(){const{value:e,type:t}=this,a=e=>e instanceof Date?e:"number"==typeof e?new Date(e):new Date;if("single"===t&&isValidDate(e))return a(e);if("multiple"===t||"range"===t){if(Array.isArray(e)){return e.every((e=>isValidDate(e)))?e.map((e=>a(e))):[]}return[]}}getDays(e){const t=[];let a=this.firstDayOfWeek%7;for(;t.length<7;)t.push(e[a]),a=(a+1)%7;return t}getMonths(){const e=[],t=this.getTrimValue(),{minDate:a,maxDate:i,type:r,format:s}=this,n=getDateRect(a);let{year:m,month:l}=n;const{time:o}=n,{year:D,month:h,time:u}=getDateRect(i),y=(e,a,i)=>{const s=new Date(e,a,i,23,59,59);if("single"===r&&t&&isSameDate({year:e,month:a,date:i},t))return"selected";if("multiple"===r&&t){if(t.some((t=>isSameDate({year:e,month:a,date:i},t))))return"selected"}if("range"===r&&t&&Array.isArray(t)){const[r,n]=t;if(r&&isSameDate({year:e,month:a,date:i},r))return"start";if(n&&isSameDate({year:e,month:a,date:i},n))return"end";if(r&&n&&s.getTime()>r.getTime()&&s.getTime()<n.getTime())return"centre"}const n=new Date(e,a,i,0,0,0);return s.getTime()<o||n.getTime()>u?"disabled":""};for(;m<D||m===D&&l<=h;){const t=getMonthDateRect(new Date(m,l,1)),a=[];for(let e=1;e<=31&&!(e>t.lastDate);e+=1){const t={date:new Date(m,l,e),day:e,type:y(m,l,e)};a.push(s?s(t):t)}e.push({year:m,month:l,months:a,weekdayOfFirstDay:t.weekdayOfFirstDay});const i=getDateRect(new Date(m,l+1,1));m=i.year,l=i.month}return e}select({cellType:e,year:t,month:a,date:i}){const{type:r}=this,s=this.getTrimValue();if("disabled"===e)return;const n=new Date(t,a,i);if(this.value=n,"range"===r&&Array.isArray(s))1===s.length&&n>s[0]?this.value=[s[0],n]:this.value=[n];else if("multiple"===r&&Array.isArray(s)){const e=[...s],t=s.findIndex((e=>isSameDate(e,n)));t>-1?e.splice(t,1):e.push(n),this.value=e}return this.value}}
|
||||
11
miniprogram/miniprogram_npm/tdesign-miniprogram/common/shared/calendar/type.d.ts
vendored
Normal file
11
miniprogram/miniprogram_npm/tdesign-miniprogram/common/shared/calendar/type.d.ts
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
export declare type TCalendarValue = number | Date;
|
||||
export declare type TDateType = 'selected' | 'disabled' | 'start' | 'centre' | 'end' | '';
|
||||
export declare type TCalendarType = 'single' | 'multiple' | 'range';
|
||||
export interface TDate {
|
||||
date: Date;
|
||||
day: number;
|
||||
type: TDateType;
|
||||
className?: string;
|
||||
prefix?: string;
|
||||
suffix?: string;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export{};
|
||||
7
miniprogram/miniprogram_npm/tdesign-miniprogram/common/shared/color-picker/cmyk.d.ts
vendored
Normal file
7
miniprogram/miniprogram_npm/tdesign-miniprogram/common/shared/color-picker/cmyk.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
export declare const rgb2cmyk: (red: number, green: number, blue: number) => number[];
|
||||
export declare const cmyk2rgb: (cyan: number, magenta: number, yellow: number, black: number) => {
|
||||
r: number;
|
||||
g: number;
|
||||
b: number;
|
||||
};
|
||||
export declare const cmykInputToColor: (input: string) => string;
|
||||
@@ -0,0 +1 @@
|
||||
export const rgb2cmyk=(t,r,e)=>{let n=0,o=0,c=0,a=0;const s=parseInt(`${t}`.replace(/\s/g,""),10),m=parseInt(`${r}`.replace(/\s/g,""),10),u=parseInt(`${e}`.replace(/\s/g,""),10);if(0===s&&0===m&&0===u)return a=1,[0,0,0,1];n=1-s/255,o=1-m/255,c=1-u/255;const p=Math.min(n,Math.min(o,c));return n=(n-p)/(1-p),o=(o-p)/(1-p),c=(c-p)/(1-p),a=p,[n,o,c,a]};export const cmyk2rgb=(t,r,e,n)=>{let o=t/100,c=r/100,a=e/100;const s=n/100;o=o*(1-s)+s,c=c*(1-s)+s,a=a*(1-s)+s;let m=1-o,u=1-c,p=1-a;return m=Math.round(255*m),u=Math.round(255*u),p=Math.round(255*p),{r:m,g:u,b:p}};const REG_CMYK_STRING=/cmyk\((\d+%?),(\d+%?),(\d+%?),(\d+%?)\)/,toNumber=t=>Math.max(0,Math.min(255,parseInt(t,10)));export const cmykInputToColor=t=>{if(/cmyk/i.test(t)){const r=t.replace(/\s/g,"").match(REG_CMYK_STRING),e=toNumber(r[1]),n=toNumber(r[2]),o=toNumber(r[3]),c=toNumber(r[4]),{r:a,g:s,b:m}=cmyk2rgb(e,n,o,c);return`rgb(${a}, ${s}, ${m})`}return t};
|
||||
107
miniprogram/miniprogram_npm/tdesign-miniprogram/common/shared/color-picker/color.d.ts
vendored
Normal file
107
miniprogram/miniprogram_npm/tdesign-miniprogram/common/shared/color-picker/color.d.ts
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
import tinyColor from 'tinycolor2/esm/tinycolor';
|
||||
import { GradientColors, GradientColorPoint } from './gradient';
|
||||
export interface ColorObject {
|
||||
alpha: number;
|
||||
css: string;
|
||||
hex: string;
|
||||
hex8: string;
|
||||
hsl: string;
|
||||
hsla: string;
|
||||
hsv: string;
|
||||
hsva: string;
|
||||
rgb: string;
|
||||
rgba: string;
|
||||
saturation: number;
|
||||
value: number;
|
||||
isGradient: boolean;
|
||||
linearGradient?: string;
|
||||
}
|
||||
interface ColorStates {
|
||||
s: number;
|
||||
v: number;
|
||||
h: number;
|
||||
a: number;
|
||||
}
|
||||
interface GradientStates {
|
||||
colors: GradientColorPoint[];
|
||||
degree: number;
|
||||
selectedId: string;
|
||||
css?: string;
|
||||
}
|
||||
export declare const gradientColors2string: (object: GradientColors) => string;
|
||||
export declare const getColorWithoutAlpha: (color: string) => any;
|
||||
export declare const genId: () => string;
|
||||
export declare const genGradientPoint: (left: number, color: string) => GradientColorPoint;
|
||||
export declare class Color {
|
||||
states: ColorStates;
|
||||
originColor: string;
|
||||
isGradient: boolean;
|
||||
gradientStates: GradientStates;
|
||||
constructor(input: string);
|
||||
update(input: string): void;
|
||||
get saturation(): number;
|
||||
set saturation(value: number);
|
||||
get value(): number;
|
||||
set value(value: number);
|
||||
get hue(): number;
|
||||
set hue(value: number);
|
||||
get alpha(): number;
|
||||
set alpha(value: number);
|
||||
get rgb(): string;
|
||||
get rgba(): string;
|
||||
get hsv(): string;
|
||||
get hsva(): string;
|
||||
get hsl(): string;
|
||||
get hsla(): string;
|
||||
get hex(): any;
|
||||
get hex8(): any;
|
||||
get cmyk(): string;
|
||||
get css(): string;
|
||||
get linearGradient(): string;
|
||||
get gradientColors(): GradientColorPoint[];
|
||||
set gradientColors(colors: GradientColorPoint[]);
|
||||
get gradientSelectedId(): string;
|
||||
set gradientSelectedId(id: string);
|
||||
get gradientDegree(): number;
|
||||
set gradientDegree(degree: number);
|
||||
get gradientSelectedPoint(): GradientColorPoint;
|
||||
getFormatsColorMap(): {
|
||||
HEX: any;
|
||||
CMYK: string;
|
||||
RGB: string;
|
||||
RGBA: string;
|
||||
HSL: string;
|
||||
HSLA: string;
|
||||
HSV: string;
|
||||
HSVA: string;
|
||||
CSS: string;
|
||||
HEX8: any;
|
||||
};
|
||||
updateCurrentGradientColor(): false | this;
|
||||
updateStates(input: string): void;
|
||||
getRgba(): {
|
||||
r: number;
|
||||
g: number;
|
||||
b: number;
|
||||
a: tinyColor.ColorFormats.RGBA;
|
||||
};
|
||||
getCmyk(): {
|
||||
c: number;
|
||||
m: number;
|
||||
y: number;
|
||||
k: number;
|
||||
};
|
||||
getHsva(): tinyColor.ColorFormats.HSVA;
|
||||
getHsla(): tinyColor.ColorFormats.HSLA;
|
||||
equals(color: string): boolean;
|
||||
static isValid(color: string): boolean;
|
||||
static hsva2color(h: number, s: number, v: number, a: number): any;
|
||||
static hsla2color(h: number, s: number, l: number, a: number): any;
|
||||
static rgba2color(r: number, g: number, b: number, a: number): any;
|
||||
static hex2color(hex: string, a: number): any;
|
||||
static object2color(object: any, format: string): any;
|
||||
static isGradientColor: (input: string) => boolean;
|
||||
static compare: (color1: string, color2: string) => boolean;
|
||||
}
|
||||
export declare const getColorObject: (color: Color) => ColorObject;
|
||||
export default Color;
|
||||
File diff suppressed because one or more lines are too long
12
miniprogram/miniprogram_npm/tdesign-miniprogram/common/shared/color-picker/gradient.d.ts
vendored
Normal file
12
miniprogram/miniprogram_npm/tdesign-miniprogram/common/shared/color-picker/gradient.d.ts
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
export interface GradientColorPoint {
|
||||
id?: string;
|
||||
color?: string;
|
||||
left?: number;
|
||||
}
|
||||
export interface GradientColors {
|
||||
points: GradientColorPoint[];
|
||||
degree: number;
|
||||
}
|
||||
export declare const isGradientColor: (input: string) => null | RegExpExecArray;
|
||||
export declare const parseGradientString: (input: string) => GradientColors | boolean;
|
||||
export default parseGradientString;
|
||||
@@ -0,0 +1 @@
|
||||
import tinyColor from"tinycolor2/esm/tinycolor";import{isString,isNull}from"../../validator";const combineRegExp=(e,t)=>{let o="";for(let t=0;t<e.length;t+=1)isString(e[t])?o+=e[t]:o+=e[t].source;return new RegExp(o,t)},generateRegExp=()=>{const e=/\s*,\s*/,t=/(?:[+-]?\d*\.?\d+)(?:%|[a-z]+)?/,o=combineRegExp(["(?:",/#(?:[a-f0-9]{6}|[a-f0-9]{3})/,"|","(?:rgb|hsl)",/\(\s*(?:\d{1,3}\s*,\s*){2}\d{1,3}\s*\)/,"|","(?:rgba|hsla)",/\(\s*(?:\d{1,3}\s*,\s*){2}\d{1,3}\s*,\s*\d*\.?\d+\)/,"|",/[_a-z-][_a-z0-9-]*/,")"],""),r=combineRegExp([o,"(?:\\s+",t,"(?:\\s+",t,")?)?"],""),i=combineRegExp(["(?:",r,e,")*",r],""),n=combineRegExp(["(?:(",/(?:[+-]?\d*\.?\d+)(?:deg|grad|rad|turn)/,")|",/to\s+((?:(?:left|right|top|bottom)(?:\s+(?:top|bottom|left|right))?))/,")"],"");return{gradientSearch:combineRegExp(["(?:(",n,")",e,")?(",i,")"],"gi"),colorStopSearch:combineRegExp(["\\s*(",o,")","(?:\\s+","(",t,"))?","(?:",e,"\\s*)?"],"gi")}},parseGradient=(e,t)=>{let o,r,i;e.gradientSearch.lastIndex=0;const n=e.gradientSearch.exec(t);if(!isNull(n))for(o={original:n[0],colorStopList:[]},n[1]&&(o.line=n[1]),n[2]&&(o.angle=n[2]),n[3]&&(o.sideCorner=n[3]),e.colorStopSearch.lastIndex=0,r=e.colorStopSearch.exec(n[4]);!isNull(r);)i={color:r[1]},r[2]&&(i.position=r[2]),o.colorStopList.push(i),r=e.colorStopSearch.exec(n[4]);return o},REGEXP_LIB=generateRegExp(),REG_GRADIENT=/.*gradient\s*\(((?:\([^)]*\)|[^)(]*)*)\)/gim;export const isGradientColor=e=>(REG_GRADIENT.lastIndex=0,REG_GRADIENT.exec(e));const sideCornerDegreeMap={top:0,right:90,bottom:180,left:270,"top left":225,"left top":225,"top right":135,"right top":135,"bottom left":315,"left bottom":315,"bottom right":45,"right bottom":45};export const parseGradientString=e=>{const t=isGradientColor(e);if(!t)return!1;const o={points:[],degree:0},r=parseGradient(REGEXP_LIB,t[1]);if(r.original.trim()!==t[1].trim())return!1;const i=r.colorStopList.map((({color:e,position:t})=>{const o=Object.create(null);return o.color=tinyColor(e).toRgbString(),o.left=parseFloat(t),o}));o.points=i;let n=parseInt(r.angle,10);return Number.isNaN(n)&&(n=sideCornerDegreeMap[r.sideCorner]||90),o.degree=n,o};export default parseGradientString;
|
||||
3
miniprogram/miniprogram_npm/tdesign-miniprogram/common/shared/color-picker/index.d.ts
vendored
Normal file
3
miniprogram/miniprogram_npm/tdesign-miniprogram/common/shared/color-picker/index.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from './cmyk';
|
||||
export * from './color';
|
||||
export * from './gradient';
|
||||
@@ -0,0 +1 @@
|
||||
export*from"./cmyk";export*from"./color";export*from"./gradient";
|
||||
21
miniprogram/miniprogram_npm/tdesign-miniprogram/common/shared/date.d.ts
vendored
Normal file
21
miniprogram/miniprogram_npm/tdesign-miniprogram/common/shared/date.d.ts
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
export declare type CompareDate = Date | number | {
|
||||
year: number;
|
||||
month: number;
|
||||
date: number;
|
||||
};
|
||||
export declare const getDateRect: (date: Date | number) => {
|
||||
year: number;
|
||||
month: number;
|
||||
date: number;
|
||||
day: number;
|
||||
time: number;
|
||||
};
|
||||
export declare const isSameDate: (date1: CompareDate, date2: CompareDate) => boolean;
|
||||
export declare const getMonthDateRect: (date: Date | number) => {
|
||||
year: number;
|
||||
month: number;
|
||||
weekdayOfFirstDay: number;
|
||||
lastDate: number;
|
||||
};
|
||||
export declare const isValidDate: (val: any) => boolean;
|
||||
export declare const getDate: (...args: any[]) => any;
|
||||
@@ -0,0 +1 @@
|
||||
export const getDateRect=e=>{const t=new Date(e);return{year:t.getFullYear(),month:t.getMonth(),date:t.getDate(),day:t.getDay(),time:t.getTime()}};export const isSameDate=(e,t)=>{(e instanceof Date||"number"==typeof e)&&(e=getDateRect(e)),(t instanceof Date||"number"==typeof t)&&(t=getDateRect(t));return["year","month","date"].every((a=>e[a]===t[a]))};export const getMonthDateRect=e=>{const{year:t,month:a}=getDateRect(e);return{year:t,month:a,weekdayOfFirstDay:new Date(t,a,1).getDay(),lastDate:new Date(+new Date(t,a+1,1)-864e5).getDate()}};export const isValidDate=e=>"number"==typeof e||e instanceof Date;export const getDate=(...e)=>{const t=new Date;if(0===e.length)return t;if(1===e.length&&e[0]<=1e3){const{year:a,month:n,date:r}=getDateRect(t);return new Date(a,n+e[0],r)}return Date.apply(null,e)};
|
||||
Reference in New Issue
Block a user