routie dev init since i didn't adhere to any proper guidance up until now

This commit is contained in:
2026-04-29 22:27:29 -06:00
commit e1dabb71e2
15301 changed files with 3562618 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
declare const block: readonly ['top', 'bottom'];
declare const inline: readonly ['start', 'end', 'left', 'right'];
type Tblock = (typeof block)[number];
type Tinline = (typeof inline)[number];
export type Anchor = Tblock | Tinline | 'center' | 'center center' | `${Tblock} ${Tinline | 'center'}` | `${Tinline} ${Tblock | 'center'}`;
export type ParsedAnchor = {
side: 'center';
align: 'center';
} | {
side: Tblock;
align: 'left' | 'right' | 'center';
} | {
side: 'left' | 'right';
align: Tblock | 'center';
};
/** Parse a raw anchor string into an object */
export declare function parseAnchor(anchor: Anchor, isRtl: boolean): ParsedAnchor;
export declare function toPhysical(str: 'center' | Tblock | Tinline, isRtl: boolean): "bottom" | "center" | "left" | "right" | "top";
export declare function flipSide(anchor: ParsedAnchor): ParsedAnchor;
export declare function flipAlign(anchor: ParsedAnchor): ParsedAnchor;
export declare function flipCorner(anchor: ParsedAnchor): ParsedAnchor;
export declare function getAxis(anchor: ParsedAnchor): "x" | "y";
+54
View File
@@ -0,0 +1,54 @@
// Utilities
import { includes } from "./helpers.js";
const block = ['top', 'bottom'];
const inline = ['start', 'end', 'left', 'right'];
/** Parse a raw anchor string into an object */
export function parseAnchor(anchor, isRtl) {
let [side, align] = anchor.split(' ');
if (!align) {
align = includes(block, side) ? 'start' : includes(inline, side) ? 'top' : 'center';
}
return {
side: toPhysical(side, isRtl),
align: toPhysical(align, isRtl)
};
}
export function toPhysical(str, isRtl) {
if (str === 'start') return isRtl ? 'right' : 'left';
if (str === 'end') return isRtl ? 'left' : 'right';
return str;
}
export function flipSide(anchor) {
return {
side: {
center: 'center',
top: 'bottom',
bottom: 'top',
left: 'right',
right: 'left'
}[anchor.side],
align: anchor.align
};
}
export function flipAlign(anchor) {
return {
side: anchor.side,
align: {
center: 'center',
top: 'bottom',
bottom: 'top',
left: 'right',
right: 'left'
}[anchor.align]
};
}
export function flipCorner(anchor) {
return {
side: anchor.align,
align: anchor.side
};
}
export function getAxis(anchor) {
return includes(block, anchor.side) ? 'y' : 'x';
}
//# sourceMappingURL=anchor.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"anchor.js","names":["includes","block","inline","parseAnchor","anchor","isRtl","side","align","split","toPhysical","str","flipSide","center","top","bottom","left","right","flipAlign","flipCorner","getAxis"],"sources":["../../src/util/anchor.ts"],"sourcesContent":["// Utilities\nimport { includes } from '@/util/helpers'\n\nconst block = ['top', 'bottom'] as const\nconst inline = ['start', 'end', 'left', 'right'] as const\ntype Tblock = typeof block[number]\ntype Tinline = typeof inline[number]\nexport type Anchor =\n | Tblock\n | Tinline\n | 'center'\n | 'center center'\n | `${Tblock} ${Tinline | 'center'}`\n | `${Tinline} ${Tblock | 'center'}`\nexport type ParsedAnchor =\n | { side: 'center', align: 'center' }\n | { side: Tblock, align: 'left' | 'right' | 'center' }\n | { side: 'left' | 'right', align: Tblock | 'center' }\n\n/** Parse a raw anchor string into an object */\nexport function parseAnchor (anchor: Anchor, isRtl: boolean) {\n let [side, align] = anchor.split(' ') as [Tblock | Tinline | 'center', Tblock | Tinline | 'center' | undefined]\n if (!align) {\n align =\n includes(block, side) ? 'start'\n : includes(inline, side) ? 'top'\n : 'center'\n }\n\n return {\n side: toPhysical(side, isRtl),\n align: toPhysical(align, isRtl),\n } as ParsedAnchor\n}\n\nexport function toPhysical (str: 'center' | Tblock | Tinline, isRtl: boolean) {\n if (str === 'start') return isRtl ? 'right' : 'left'\n if (str === 'end') return isRtl ? 'left' : 'right'\n return str\n}\n\nexport function flipSide (anchor: ParsedAnchor) {\n return {\n side: {\n center: 'center',\n top: 'bottom',\n bottom: 'top',\n left: 'right',\n right: 'left',\n }[anchor.side],\n align: anchor.align,\n } as ParsedAnchor\n}\n\nexport function flipAlign (anchor: ParsedAnchor) {\n return {\n side: anchor.side,\n align: {\n center: 'center',\n top: 'bottom',\n bottom: 'top',\n left: 'right',\n right: 'left',\n }[anchor.align],\n } as ParsedAnchor\n}\n\nexport function flipCorner (anchor: ParsedAnchor) {\n return {\n side: anchor.align,\n align: anchor.side,\n } as ParsedAnchor\n}\n\nexport function getAxis (anchor: ParsedAnchor) {\n return includes(block, anchor.side) ? 'y' : 'x'\n}\n"],"mappings":"AAAA;AAAA,SACSA,QAAQ;AAEjB,MAAMC,KAAK,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAU;AACxC,MAAMC,MAAM,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAU;AAezD;AACA,OAAO,SAASC,WAAWA,CAAEC,MAAc,EAAEC,KAAc,EAAE;EAC3D,IAAI,CAACC,IAAI,EAAEC,KAAK,CAAC,GAAGH,MAAM,CAACI,KAAK,CAAC,GAAG,CAA2E;EAC/G,IAAI,CAACD,KAAK,EAAE;IACVA,KAAK,GACHP,QAAQ,CAACC,KAAK,EAAEK,IAAI,CAAC,GAAG,OAAO,GAC7BN,QAAQ,CAACE,MAAM,EAAEI,IAAI,CAAC,GAAG,KAAK,GAC9B,QAAQ;EACd;EAEA,OAAO;IACLA,IAAI,EAAEG,UAAU,CAACH,IAAI,EAAED,KAAK,CAAC;IAC7BE,KAAK,EAAEE,UAAU,CAACF,KAAK,EAAEF,KAAK;EAChC,CAAC;AACH;AAEA,OAAO,SAASI,UAAUA,CAAEC,GAAgC,EAAEL,KAAc,EAAE;EAC5E,IAAIK,GAAG,KAAK,OAAO,EAAE,OAAOL,KAAK,GAAG,OAAO,GAAG,MAAM;EACpD,IAAIK,GAAG,KAAK,KAAK,EAAE,OAAOL,KAAK,GAAG,MAAM,GAAG,OAAO;EAClD,OAAOK,GAAG;AACZ;AAEA,OAAO,SAASC,QAAQA,CAAEP,MAAoB,EAAE;EAC9C,OAAO;IACLE,IAAI,EAAE;MACJM,MAAM,EAAE,QAAQ;MAChBC,GAAG,EAAE,QAAQ;MACbC,MAAM,EAAE,KAAK;MACbC,IAAI,EAAE,OAAO;MACbC,KAAK,EAAE;IACT,CAAC,CAACZ,MAAM,CAACE,IAAI,CAAC;IACdC,KAAK,EAAEH,MAAM,CAACG;EAChB,CAAC;AACH;AAEA,OAAO,SAASU,SAASA,CAAEb,MAAoB,EAAE;EAC/C,OAAO;IACLE,IAAI,EAAEF,MAAM,CAACE,IAAI;IACjBC,KAAK,EAAE;MACLK,MAAM,EAAE,QAAQ;MAChBC,GAAG,EAAE,QAAQ;MACbC,MAAM,EAAE,KAAK;MACbC,IAAI,EAAE,OAAO;MACbC,KAAK,EAAE;IACT,CAAC,CAACZ,MAAM,CAACG,KAAK;EAChB,CAAC;AACH;AAEA,OAAO,SAASW,UAAUA,CAAEd,MAAoB,EAAE;EAChD,OAAO;IACLE,IAAI,EAAEF,MAAM,CAACG,KAAK;IAClBA,KAAK,EAAEH,MAAM,CAACE;EAChB,CAAC;AACH;AAEA,OAAO,SAASa,OAAOA,CAAEf,MAAoB,EAAE;EAC7C,OAAOJ,QAAQ,CAACC,KAAK,EAAEG,MAAM,CAACE,IAAI,CAAC,GAAG,GAAG,GAAG,GAAG;AACjD","ignoreList":[]}
+6
View File
@@ -0,0 +1,6 @@
import { Box } from './box.js';
/** @see https://stackoverflow.com/a/57876601/2074736 */
export declare function nullifyTransforms(el: HTMLElement): Box;
export declare function animate(el: Element, keyframes: Keyframe[] | PropertyIndexedKeyframes | null, options?: number | KeyframeAnimationOptions): Animation | {
finished: Promise<void>;
};
+61
View File
@@ -0,0 +1,61 @@
// Utilities
import { Box } from "./box.js";
/** @see https://stackoverflow.com/a/57876601/2074736 */
export function nullifyTransforms(el) {
const rect = new Box(el);
const style = getComputedStyle(el);
const tx = style.transform;
if (tx) {
let ta, sx, sy, dx, dy;
if (tx.startsWith('matrix3d(')) {
ta = tx.slice(9, -1).split(/, /);
sx = Number(ta[0]);
sy = Number(ta[5]);
dx = Number(ta[12]);
dy = Number(ta[13]);
} else if (tx.startsWith('matrix(')) {
ta = tx.slice(7, -1).split(/, /);
sx = Number(ta[0]);
sy = Number(ta[3]);
dx = Number(ta[4]);
dy = Number(ta[5]);
} else {
return new Box(rect);
}
const to = style.transformOrigin;
const x = rect.x - dx - (1 - sx) * parseFloat(to);
const y = rect.y - dy - (1 - sy) * parseFloat(to.slice(to.indexOf(' ') + 1));
const w = sx ? rect.width / sx : el.offsetWidth + 1;
const h = sy ? rect.height / sy : el.offsetHeight + 1;
return new Box({
x,
y,
width: w,
height: h
});
} else {
return new Box(rect);
}
}
export function animate(el, keyframes, options) {
if (typeof el.animate === 'undefined') return {
finished: Promise.resolve()
};
let animation;
try {
animation = el.animate(keyframes, options);
} catch (err) {
return {
finished: Promise.resolve()
};
}
if (typeof animation.finished === 'undefined') {
animation.finished = new Promise(resolve => {
animation.onfinish = () => {
resolve(animation);
};
});
}
return animation;
}
//# sourceMappingURL=animation.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"animation.js","names":["Box","nullifyTransforms","el","rect","style","getComputedStyle","tx","transform","ta","sx","sy","dx","dy","startsWith","slice","split","Number","to","transformOrigin","x","parseFloat","y","indexOf","w","width","offsetWidth","h","height","offsetHeight","animate","keyframes","options","finished","Promise","resolve","animation","err","onfinish"],"sources":["../../src/util/animation.ts"],"sourcesContent":["// Utilities\nimport { Box } from '@/util/box'\n\n/** @see https://stackoverflow.com/a/57876601/2074736 */\nexport function nullifyTransforms (el: HTMLElement): Box {\n const rect = new Box(el)\n const style = getComputedStyle(el)\n const tx = style.transform\n\n if (tx) {\n let ta, sx, sy, dx, dy\n if (tx.startsWith('matrix3d(')) {\n ta = tx.slice(9, -1).split(/, /)\n sx = Number(ta[0])\n sy = Number(ta[5])\n dx = Number(ta[12])\n dy = Number(ta[13])\n } else if (tx.startsWith('matrix(')) {\n ta = tx.slice(7, -1).split(/, /)\n sx = Number(ta[0])\n sy = Number(ta[3])\n dx = Number(ta[4])\n dy = Number(ta[5])\n } else {\n return new Box(rect)\n }\n\n const to = style.transformOrigin\n const x = rect.x - dx - (1 - sx) * parseFloat(to)\n const y = rect.y - dy - (1 - sy) * parseFloat(to.slice(to.indexOf(' ') + 1))\n const w = sx ? rect.width / sx : el.offsetWidth + 1\n const h = sy ? rect.height / sy : el.offsetHeight + 1\n\n return new Box({ x, y, width: w, height: h })\n } else {\n return new Box(rect)\n }\n}\n\nexport function animate (\n el: Element,\n keyframes: Keyframe[] | PropertyIndexedKeyframes | null,\n options?: number | KeyframeAnimationOptions\n) {\n if (typeof el.animate === 'undefined') return { finished: Promise.resolve() }\n\n let animation: Animation\n try {\n animation = el.animate(keyframes, options)\n } catch (err) {\n return { finished: Promise.resolve() }\n }\n\n if (typeof animation.finished === 'undefined') {\n (animation as any).finished = new Promise(resolve => {\n animation.onfinish = () => {\n resolve(animation)\n }\n })\n }\n\n return animation\n}\n"],"mappings":"AAAA;AAAA,SACSA,GAAG;AAEZ;AACA,OAAO,SAASC,iBAAiBA,CAAEC,EAAe,EAAO;EACvD,MAAMC,IAAI,GAAG,IAAIH,GAAG,CAACE,EAAE,CAAC;EACxB,MAAME,KAAK,GAAGC,gBAAgB,CAACH,EAAE,CAAC;EAClC,MAAMI,EAAE,GAAGF,KAAK,CAACG,SAAS;EAE1B,IAAID,EAAE,EAAE;IACN,IAAIE,EAAE,EAAEC,EAAE,EAAEC,EAAE,EAAEC,EAAE,EAAEC,EAAE;IACtB,IAAIN,EAAE,CAACO,UAAU,CAAC,WAAW,CAAC,EAAE;MAC9BL,EAAE,GAAGF,EAAE,CAACQ,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAACC,KAAK,CAAC,IAAI,CAAC;MAChCN,EAAE,GAAGO,MAAM,CAACR,EAAE,CAAC,CAAC,CAAC,CAAC;MAClBE,EAAE,GAAGM,MAAM,CAACR,EAAE,CAAC,CAAC,CAAC,CAAC;MAClBG,EAAE,GAAGK,MAAM,CAACR,EAAE,CAAC,EAAE,CAAC,CAAC;MACnBI,EAAE,GAAGI,MAAM,CAACR,EAAE,CAAC,EAAE,CAAC,CAAC;IACrB,CAAC,MAAM,IAAIF,EAAE,CAACO,UAAU,CAAC,SAAS,CAAC,EAAE;MACnCL,EAAE,GAAGF,EAAE,CAACQ,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAACC,KAAK,CAAC,IAAI,CAAC;MAChCN,EAAE,GAAGO,MAAM,CAACR,EAAE,CAAC,CAAC,CAAC,CAAC;MAClBE,EAAE,GAAGM,MAAM,CAACR,EAAE,CAAC,CAAC,CAAC,CAAC;MAClBG,EAAE,GAAGK,MAAM,CAACR,EAAE,CAAC,CAAC,CAAC,CAAC;MAClBI,EAAE,GAAGI,MAAM,CAACR,EAAE,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC,MAAM;MACL,OAAO,IAAIR,GAAG,CAACG,IAAI,CAAC;IACtB;IAEA,MAAMc,EAAE,GAAGb,KAAK,CAACc,eAAe;IAChC,MAAMC,CAAC,GAAGhB,IAAI,CAACgB,CAAC,GAAGR,EAAE,GAAG,CAAC,CAAC,GAAGF,EAAE,IAAIW,UAAU,CAACH,EAAE,CAAC;IACjD,MAAMI,CAAC,GAAGlB,IAAI,CAACkB,CAAC,GAAGT,EAAE,GAAG,CAAC,CAAC,GAAGF,EAAE,IAAIU,UAAU,CAACH,EAAE,CAACH,KAAK,CAACG,EAAE,CAACK,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5E,MAAMC,CAAC,GAAGd,EAAE,GAAGN,IAAI,CAACqB,KAAK,GAAGf,EAAE,GAAGP,EAAE,CAACuB,WAAW,GAAG,CAAC;IACnD,MAAMC,CAAC,GAAGhB,EAAE,GAAGP,IAAI,CAACwB,MAAM,GAAGjB,EAAE,GAAGR,EAAE,CAAC0B,YAAY,GAAG,CAAC;IAErD,OAAO,IAAI5B,GAAG,CAAC;MAAEmB,CAAC;MAAEE,CAAC;MAAEG,KAAK,EAAED,CAAC;MAAEI,MAAM,EAAED;IAAE,CAAC,CAAC;EAC/C,CAAC,MAAM;IACL,OAAO,IAAI1B,GAAG,CAACG,IAAI,CAAC;EACtB;AACF;AAEA,OAAO,SAAS0B,OAAOA,CACrB3B,EAAW,EACX4B,SAAuD,EACvDC,OAA2C,EAC3C;EACA,IAAI,OAAO7B,EAAE,CAAC2B,OAAO,KAAK,WAAW,EAAE,OAAO;IAAEG,QAAQ,EAAEC,OAAO,CAACC,OAAO,CAAC;EAAE,CAAC;EAE7E,IAAIC,SAAoB;EACxB,IAAI;IACFA,SAAS,GAAGjC,EAAE,CAAC2B,OAAO,CAACC,SAAS,EAAEC,OAAO,CAAC;EAC5C,CAAC,CAAC,OAAOK,GAAG,EAAE;IACZ,OAAO;MAAEJ,QAAQ,EAAEC,OAAO,CAACC,OAAO,CAAC;IAAE,CAAC;EACxC;EAEA,IAAI,OAAOC,SAAS,CAACH,QAAQ,KAAK,WAAW,EAAE;IAC5CG,SAAS,CAASH,QAAQ,GAAG,IAAIC,OAAO,CAACC,OAAO,IAAI;MACnDC,SAAS,CAACE,QAAQ,GAAG,MAAM;QACzBH,OAAO,CAACC,SAAS,CAAC;MACpB,CAAC;IACH,CAAC,CAAC;EACJ;EAEA,OAAOA,SAAS;AAClB","ignoreList":[]}
+2
View File
@@ -0,0 +1,2 @@
export declare function bindProps(el: HTMLElement, props: Record<string, any>): void;
export declare function unbindProps(el: HTMLElement, props: Record<string, any>): void;
+49
View File
@@ -0,0 +1,49 @@
// Utilities
import { eventName, isOn } from "./helpers.js";
const handlers = new WeakMap();
export function bindProps(el, props) {
Object.keys(props).forEach(k => {
if (isOn(k)) {
const name = eventName(k);
const handler = handlers.get(el);
if (props[k] == null) {
handler?.forEach(v => {
const [n, fn] = v;
if (n === name) {
el.removeEventListener(name, fn);
handler.delete(v);
}
});
} else if (!handler || ![...handler]?.some(v => v[0] === name && v[1] === props[k])) {
el.addEventListener(name, props[k]);
const _handler = handler || new Set();
_handler.add([name, props[k]]);
if (!handlers.has(el)) handlers.set(el, _handler);
}
} else {
if (props[k] == null) {
el.removeAttribute(k);
} else {
el.setAttribute(k, props[k]);
}
}
});
}
export function unbindProps(el, props) {
Object.keys(props).forEach(k => {
if (isOn(k)) {
const name = eventName(k);
const handler = handlers.get(el);
handler?.forEach(v => {
const [n, fn] = v;
if (n === name) {
el.removeEventListener(name, fn);
handler.delete(v);
}
});
} else {
el.removeAttribute(k);
}
});
}
//# sourceMappingURL=bindProps.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"bindProps.js","names":["eventName","isOn","handlers","WeakMap","bindProps","el","props","Object","keys","forEach","k","name","handler","get","v","n","fn","removeEventListener","delete","some","addEventListener","_handler","Set","add","has","set","removeAttribute","setAttribute","unbindProps"],"sources":["../../src/util/bindProps.ts"],"sourcesContent":["// Utilities\nimport { eventName, isOn } from '@/util/helpers'\n\nconst handlers = new WeakMap<HTMLElement, Set<[string, () => void]>>()\n\nexport function bindProps (el: HTMLElement, props: Record<string, any>) {\n Object.keys(props).forEach(k => {\n if (isOn(k)) {\n const name = eventName(k)\n const handler = handlers.get(el)\n if (props[k] == null) {\n handler?.forEach(v => {\n const [n, fn] = v\n if (n === name) {\n el.removeEventListener(name, fn)\n handler.delete(v)\n }\n })\n } else if (!handler || ![...handler]?.some(v => v[0] === name && v[1] === props[k])) {\n el.addEventListener(name, props[k])\n const _handler = handler || new Set()\n _handler.add([name, props[k]])\n if (!handlers.has(el)) handlers.set(el, _handler)\n }\n } else {\n if (props[k] == null) {\n el.removeAttribute(k)\n } else {\n el.setAttribute(k, props[k])\n }\n }\n })\n}\n\nexport function unbindProps (el: HTMLElement, props: Record<string, any>) {\n Object.keys(props).forEach(k => {\n if (isOn(k)) {\n const name = eventName(k)\n const handler = handlers.get(el)\n handler?.forEach(v => {\n const [n, fn] = v\n if (n === name) {\n el.removeEventListener(name, fn)\n handler.delete(v)\n }\n })\n } else {\n el.removeAttribute(k)\n }\n })\n}\n"],"mappings":"AAAA;AAAA,SACSA,SAAS,EAAEC,IAAI;AAExB,MAAMC,QAAQ,GAAG,IAAIC,OAAO,CAAyC,CAAC;AAEtE,OAAO,SAASC,SAASA,CAAEC,EAAe,EAAEC,KAA0B,EAAE;EACtEC,MAAM,CAACC,IAAI,CAACF,KAAK,CAAC,CAACG,OAAO,CAACC,CAAC,IAAI;IAC9B,IAAIT,IAAI,CAACS,CAAC,CAAC,EAAE;MACX,MAAMC,IAAI,GAAGX,SAAS,CAACU,CAAC,CAAC;MACzB,MAAME,OAAO,GAAGV,QAAQ,CAACW,GAAG,CAACR,EAAE,CAAC;MAChC,IAAIC,KAAK,CAACI,CAAC,CAAC,IAAI,IAAI,EAAE;QACpBE,OAAO,EAAEH,OAAO,CAACK,CAAC,IAAI;UACpB,MAAM,CAACC,CAAC,EAAEC,EAAE,CAAC,GAAGF,CAAC;UACjB,IAAIC,CAAC,KAAKJ,IAAI,EAAE;YACdN,EAAE,CAACY,mBAAmB,CAACN,IAAI,EAAEK,EAAE,CAAC;YAChCJ,OAAO,CAACM,MAAM,CAACJ,CAAC,CAAC;UACnB;QACF,CAAC,CAAC;MACJ,CAAC,MAAM,IAAI,CAACF,OAAO,IAAI,CAAC,CAAC,GAAGA,OAAO,CAAC,EAAEO,IAAI,CAACL,CAAC,IAAIA,CAAC,CAAC,CAAC,CAAC,KAAKH,IAAI,IAAIG,CAAC,CAAC,CAAC,CAAC,KAAKR,KAAK,CAACI,CAAC,CAAC,CAAC,EAAE;QACnFL,EAAE,CAACe,gBAAgB,CAACT,IAAI,EAAEL,KAAK,CAACI,CAAC,CAAC,CAAC;QACnC,MAAMW,QAAQ,GAAGT,OAAO,IAAI,IAAIU,GAAG,CAAC,CAAC;QACrCD,QAAQ,CAACE,GAAG,CAAC,CAACZ,IAAI,EAAEL,KAAK,CAACI,CAAC,CAAC,CAAC,CAAC;QAC9B,IAAI,CAACR,QAAQ,CAACsB,GAAG,CAACnB,EAAE,CAAC,EAAEH,QAAQ,CAACuB,GAAG,CAACpB,EAAE,EAAEgB,QAAQ,CAAC;MACnD;IACF,CAAC,MAAM;MACL,IAAIf,KAAK,CAACI,CAAC,CAAC,IAAI,IAAI,EAAE;QACpBL,EAAE,CAACqB,eAAe,CAAChB,CAAC,CAAC;MACvB,CAAC,MAAM;QACLL,EAAE,CAACsB,YAAY,CAACjB,CAAC,EAAEJ,KAAK,CAACI,CAAC,CAAC,CAAC;MAC9B;IACF;EACF,CAAC,CAAC;AACJ;AAEA,OAAO,SAASkB,WAAWA,CAAEvB,EAAe,EAAEC,KAA0B,EAAE;EACxEC,MAAM,CAACC,IAAI,CAACF,KAAK,CAAC,CAACG,OAAO,CAACC,CAAC,IAAI;IAC9B,IAAIT,IAAI,CAACS,CAAC,CAAC,EAAE;MACX,MAAMC,IAAI,GAAGX,SAAS,CAACU,CAAC,CAAC;MACzB,MAAME,OAAO,GAAGV,QAAQ,CAACW,GAAG,CAACR,EAAE,CAAC;MAChCO,OAAO,EAAEH,OAAO,CAACK,CAAC,IAAI;QACpB,MAAM,CAACC,CAAC,EAAEC,EAAE,CAAC,GAAGF,CAAC;QACjB,IAAIC,CAAC,KAAKJ,IAAI,EAAE;UACdN,EAAE,CAACY,mBAAmB,CAACN,IAAI,EAAEK,EAAE,CAAC;UAChCJ,OAAO,CAACM,MAAM,CAACJ,CAAC,CAAC;QACnB;MACF,CAAC,CAAC;IACJ,CAAC,MAAM;MACLT,EAAE,CAACqB,eAAe,CAAChB,CAAC,CAAC;IACvB;EACF,CAAC,CAAC;AACJ","ignoreList":[]}
+28
View File
@@ -0,0 +1,28 @@
export declare class Box {
x: number;
y: number;
width: number;
height: number;
constructor(args: Element | {
x: number;
y: number;
width: number;
height: number;
});
get top(): number;
get bottom(): number;
get left(): number;
get right(): number;
}
export declare function getOverflow(a: Box, b: Box): {
x: {
before: number;
after: number;
};
y: {
before: number;
after: number;
};
};
export declare function getTargetBox(target: HTMLElement | [x: number, y: number]): Box;
export declare function getElementBox(el: HTMLElement): Box;
+78
View File
@@ -0,0 +1,78 @@
export class Box {
constructor(args) {
const pageScale = document.body.currentCSSZoom ?? 1;
const isElement = args instanceof Element;
const factor = isElement ? 1 + (1 - pageScale) / pageScale : 1;
const {
x,
y,
width,
height
} = isElement ? args.getBoundingClientRect() : args;
this.x = x * factor;
this.y = y * factor;
this.width = width * factor;
this.height = height * factor;
}
get top() {
return this.y;
}
get bottom() {
return this.y + this.height;
}
get left() {
return this.x;
}
get right() {
return this.x + this.width;
}
}
export function getOverflow(a, b) {
return {
x: {
before: Math.max(0, b.left - a.left),
after: Math.max(0, a.right - b.right)
},
y: {
before: Math.max(0, b.top - a.top),
after: Math.max(0, a.bottom - b.bottom)
}
};
}
export function getTargetBox(target) {
if (Array.isArray(target)) {
const pageScale = document.body.currentCSSZoom ?? 1;
const factor = 1 + (1 - pageScale) / pageScale;
return new Box({
x: target[0] * factor,
y: target[1] * factor,
width: 0 * factor,
height: 0 * factor
});
} else {
return new Box(target);
}
}
export function getElementBox(el) {
if (el === document.documentElement) {
if (!visualViewport) {
return new Box({
x: 0,
y: 0,
width: document.documentElement.clientWidth,
height: document.documentElement.clientHeight
});
} else {
const pageScale = document.body.currentCSSZoom ?? 1;
return new Box({
x: visualViewport.scale > 1 ? 0 : visualViewport.offsetLeft,
y: visualViewport.scale > 1 ? 0 : visualViewport.offsetTop,
width: visualViewport.width * visualViewport.scale / pageScale,
height: visualViewport.height * visualViewport.scale / pageScale
});
}
} else {
return new Box(el);
}
}
//# sourceMappingURL=box.js.map
File diff suppressed because one or more lines are too long
+7
View File
@@ -0,0 +1,7 @@
/**
* WCAG 3.0 APCA perceptual contrast algorithm from https://github.com/Myndex/SAPC-APCA
* @licence https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
* @see https://www.w3.org/WAI/GL/task-forces/silver/wiki/Visual_Contrast_of_Text_Subgroup
*/
import type { RGB } from '../index.js';
export declare function APCAcontrast(text: RGB, background: RGB): number;
+88
View File
@@ -0,0 +1,88 @@
/**
* WCAG 3.0 APCA perceptual contrast algorithm from https://github.com/Myndex/SAPC-APCA
* @licence https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
* @see https://www.w3.org/WAI/GL/task-forces/silver/wiki/Visual_Contrast_of_Text_Subgroup
*/
// Types
// MAGICAL NUMBERS
// sRGB Conversion to Relative Luminance (Y)
// Transfer Curve (aka "Gamma") for sRGB linearization
// Simple power curve vs piecewise described in docs
// Essentially, 2.4 best models actual display
// characteristics in combination with the total method
const mainTRC = 2.4;
const Rco = 0.2126729; // sRGB Red Coefficient (from matrix)
const Gco = 0.7151522; // sRGB Green Coefficient (from matrix)
const Bco = 0.0721750; // sRGB Blue Coefficient (from matrix)
// For Finding Raw SAPC Contrast from Relative Luminance (Y)
// Constants for SAPC Power Curve Exponents
// One pair for normal text, and one for reverse
// These are the "beating heart" of SAPC
const normBG = 0.55;
const normTXT = 0.58;
const revTXT = 0.57;
const revBG = 0.62;
// For Clamping and Scaling Values
const blkThrs = 0.03; // Level that triggers the soft black clamp
const blkClmp = 1.45; // Exponent for the soft black clamp curve
const deltaYmin = 0.0005; // Lint trap
const scaleBoW = 1.25; // Scaling for dark text on light
const scaleWoB = 1.25; // Scaling for light text on dark
const loConThresh = 0.078; // Threshold for new simple offset scale
const loConFactor = 12.82051282051282; // = 1/0.078,
const loConOffset = 0.06; // The simple offset
const loClip = 0.001; // Output clip (lint trap #2)
export function APCAcontrast(text, background) {
// Linearize sRGB
const Rtxt = (text.r / 255) ** mainTRC;
const Gtxt = (text.g / 255) ** mainTRC;
const Btxt = (text.b / 255) ** mainTRC;
const Rbg = (background.r / 255) ** mainTRC;
const Gbg = (background.g / 255) ** mainTRC;
const Bbg = (background.b / 255) ** mainTRC;
// Apply the standard coefficients and sum to Y
let Ytxt = Rtxt * Rco + Gtxt * Gco + Btxt * Bco;
let Ybg = Rbg * Rco + Gbg * Gco + Bbg * Bco;
// Soft clamp Y when near black.
// Now clamping all colors to prevent crossover errors
if (Ytxt <= blkThrs) Ytxt += (blkThrs - Ytxt) ** blkClmp;
if (Ybg <= blkThrs) Ybg += (blkThrs - Ybg) ** blkClmp;
// Return 0 Early for extremely low ∆Y (lint trap #1)
if (Math.abs(Ybg - Ytxt) < deltaYmin) return 0.0;
// SAPC CONTRAST
let outputContrast; // For weighted final values
if (Ybg > Ytxt) {
// For normal polarity, black text on white
// Calculate the SAPC contrast value and scale
const SAPC = (Ybg ** normBG - Ytxt ** normTXT) * scaleBoW;
// NEW! SAPC SmoothScale™
// Low Contrast Smooth Scale Rollout to prevent polarity reversal
// and also a low clip for very low contrasts (lint trap #2)
// much of this is for very low contrasts, less than 10
// therefore for most reversing needs, only loConOffset is important
outputContrast = SAPC < loClip ? 0.0 : SAPC < loConThresh ? SAPC - SAPC * loConFactor * loConOffset : SAPC - loConOffset;
} else {
// For reverse polarity, light text on dark
// WoB should always return negative value.
const SAPC = (Ybg ** revBG - Ytxt ** revTXT) * scaleWoB;
outputContrast = SAPC > -loClip ? 0.0 : SAPC > -loConThresh ? SAPC - SAPC * loConFactor * loConOffset : SAPC + loConOffset;
}
return outputContrast * 100;
}
//# sourceMappingURL=APCA.js.map
File diff suppressed because one or more lines are too long
+3
View File
@@ -0,0 +1,3 @@
import type { LAB, XYZ } from '../colorUtils.js';
export declare function fromXYZ(xyz: XYZ): LAB;
export declare function toXYZ(lab: LAB): XYZ;
+17
View File
@@ -0,0 +1,17 @@
// Types
const delta = 0.20689655172413793; // 6÷29
const cielabForwardTransform = t => t > delta ** 3 ? Math.cbrt(t) : t / (3 * delta ** 2) + 4 / 29;
const cielabReverseTransform = t => t > delta ? t ** 3 : 3 * delta ** 2 * (t - 4 / 29);
export function fromXYZ(xyz) {
const transform = cielabForwardTransform;
const transformedY = transform(xyz[1]);
return [116 * transformedY - 16, 500 * (transform(xyz[0] / 0.95047) - transformedY), 200 * (transformedY - transform(xyz[2] / 1.08883))];
}
export function toXYZ(lab) {
const transform = cielabReverseTransform;
const Ln = (lab[0] + 16) / 116;
return [transform(Ln + lab[1] / 500) * 0.95047, transform(Ln), transform(Ln - lab[2] / 200) * 1.08883];
}
//# sourceMappingURL=transformCIELAB.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"transformCIELAB.js","names":["delta","cielabForwardTransform","t","Math","cbrt","cielabReverseTransform","fromXYZ","xyz","transform","transformedY","toXYZ","lab","Ln"],"sources":["../../../src/util/color/transformCIELAB.ts"],"sourcesContent":["// Types\nimport type { LAB, XYZ } from '../colorUtils'\n\nconst delta = 0.20689655172413793 // 6÷29\n\nconst cielabForwardTransform = (t: number): number => (\n t > delta ** 3\n ? Math.cbrt(t)\n : (t / (3 * delta ** 2)) + 4 / 29\n)\n\nconst cielabReverseTransform = (t: number): number => (\n t > delta\n ? t ** 3\n : (3 * delta ** 2) * (t - 4 / 29)\n)\n\nexport function fromXYZ (xyz: XYZ): LAB {\n const transform = cielabForwardTransform\n const transformedY = transform(xyz[1])\n\n return [\n 116 * transformedY - 16,\n 500 * (transform(xyz[0] / 0.95047) - transformedY),\n 200 * (transformedY - transform(xyz[2] / 1.08883)),\n ]\n}\n\nexport function toXYZ (lab: LAB): XYZ {\n const transform = cielabReverseTransform\n const Ln = (lab[0] + 16) / 116\n return [\n transform(Ln + lab[1] / 500) * 0.95047,\n transform(Ln),\n transform(Ln - lab[2] / 200) * 1.08883,\n ]\n}\n"],"mappings":"AAAA;;AAGA,MAAMA,KAAK,GAAG,mBAAmB,EAAC;;AAElC,MAAMC,sBAAsB,GAAIC,CAAS,IACvCA,CAAC,GAAGF,KAAK,IAAI,CAAC,GACVG,IAAI,CAACC,IAAI,CAACF,CAAC,CAAC,GACXA,CAAC,IAAI,CAAC,GAAGF,KAAK,IAAI,CAAC,CAAC,GAAI,CAAC,GAAG,EAClC;AAED,MAAMK,sBAAsB,GAAIH,CAAS,IACvCA,CAAC,GAAGF,KAAK,GACLE,CAAC,IAAI,CAAC,GACL,CAAC,GAAGF,KAAK,IAAI,CAAC,IAAKE,CAAC,GAAG,CAAC,GAAG,EAAE,CACnC;AAED,OAAO,SAASI,OAAOA,CAAEC,GAAQ,EAAO;EACtC,MAAMC,SAAS,GAAGP,sBAAsB;EACxC,MAAMQ,YAAY,GAAGD,SAAS,CAACD,GAAG,CAAC,CAAC,CAAC,CAAC;EAEtC,OAAO,CACL,GAAG,GAAGE,YAAY,GAAG,EAAE,EACvB,GAAG,IAAID,SAAS,CAACD,GAAG,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,GAAGE,YAAY,CAAC,EAClD,GAAG,IAAIA,YAAY,GAAGD,SAAS,CAACD,GAAG,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CACnD;AACH;AAEA,OAAO,SAASG,KAAKA,CAAEC,GAAQ,EAAO;EACpC,MAAMH,SAAS,GAAGH,sBAAsB;EACxC,MAAMO,EAAE,GAAG,CAACD,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,GAAG;EAC9B,OAAO,CACLH,SAAS,CAACI,EAAE,GAAGD,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,OAAO,EACtCH,SAAS,CAACI,EAAE,CAAC,EACbJ,SAAS,CAACI,EAAE,GAAGD,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,OAAO,CACvC;AACH","ignoreList":[]}
+3
View File
@@ -0,0 +1,3 @@
import type { RGB, XYZ } from '../colorUtils.js';
export declare function fromXYZ(xyz: XYZ): RGB;
export declare function toXYZ({ r, g, b }: RGB): XYZ;
+50
View File
@@ -0,0 +1,50 @@
// Utilities
import { clamp } from "../helpers.js"; // Types
// For converting XYZ to sRGB
const srgbForwardMatrix = [[3.2406, -1.5372, -0.4986], [-0.9689, 1.8758, 0.0415], [0.0557, -0.2040, 1.0570]];
// Forward gamma adjust
const srgbForwardTransform = C => C <= 0.0031308 ? C * 12.92 : 1.055 * C ** (1 / 2.4) - 0.055;
// For converting sRGB to XYZ
const srgbReverseMatrix = [[0.4124, 0.3576, 0.1805], [0.2126, 0.7152, 0.0722], [0.0193, 0.1192, 0.9505]];
// Reverse gamma adjust
const srgbReverseTransform = C => C <= 0.04045 ? C / 12.92 : ((C + 0.055) / 1.055) ** 2.4;
export function fromXYZ(xyz) {
const rgb = Array(3);
const transform = srgbForwardTransform;
const matrix = srgbForwardMatrix;
// Matrix transform, then gamma adjustment
for (let i = 0; i < 3; ++i) {
// Rescale back to [0, 255]
rgb[i] = Math.round(clamp(transform(matrix[i][0] * xyz[0] + matrix[i][1] * xyz[1] + matrix[i][2] * xyz[2])) * 255);
}
return {
r: rgb[0],
g: rgb[1],
b: rgb[2]
};
}
export function toXYZ({
r,
g,
b
}) {
const xyz = [0, 0, 0];
const transform = srgbReverseTransform;
const matrix = srgbReverseMatrix;
// Rescale from [0, 255] to [0, 1] then adjust sRGB gamma to linear RGB
r = transform(r / 255);
g = transform(g / 255);
b = transform(b / 255);
// Matrix color space transform
for (let i = 0; i < 3; ++i) {
xyz[i] = matrix[i][0] * r + matrix[i][1] * g + matrix[i][2] * b;
}
return xyz;
}
//# sourceMappingURL=transformSRGB.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"transformSRGB.js","names":["clamp","srgbForwardMatrix","srgbForwardTransform","C","srgbReverseMatrix","srgbReverseTransform","fromXYZ","xyz","rgb","Array","transform","matrix","i","Math","round","r","g","b","toXYZ"],"sources":["../../../src/util/color/transformSRGB.ts"],"sourcesContent":["// Utilities\nimport { clamp } from '@/util/helpers'\n\n// Types\nimport type { RGB, XYZ } from '../colorUtils'\n\n// For converting XYZ to sRGB\nconst srgbForwardMatrix = [\n [3.2406, -1.5372, -0.4986],\n [-0.9689, 1.8758, 0.0415],\n [0.0557, -0.2040, 1.0570],\n]\n\n// Forward gamma adjust\nconst srgbForwardTransform = (C: number): number => (\n C <= 0.0031308\n ? C * 12.92\n : 1.055 * C ** (1 / 2.4) - 0.055\n)\n\n// For converting sRGB to XYZ\nconst srgbReverseMatrix = [\n [0.4124, 0.3576, 0.1805],\n [0.2126, 0.7152, 0.0722],\n [0.0193, 0.1192, 0.9505],\n]\n\n// Reverse gamma adjust\nconst srgbReverseTransform = (C: number): number => (\n C <= 0.04045\n ? C / 12.92\n : ((C + 0.055) / 1.055) ** 2.4\n)\n\nexport function fromXYZ (xyz: XYZ): RGB {\n const rgb = Array(3)\n const transform = srgbForwardTransform\n const matrix = srgbForwardMatrix\n\n // Matrix transform, then gamma adjustment\n for (let i = 0; i < 3; ++i) {\n // Rescale back to [0, 255]\n rgb[i] = Math.round(clamp(transform(\n matrix[i][0] * xyz[0] +\n matrix[i][1] * xyz[1] +\n matrix[i][2] * xyz[2]\n )) * 255)\n }\n\n return {\n r: rgb[0],\n g: rgb[1],\n b: rgb[2],\n }\n}\n\nexport function toXYZ ({ r, g, b }: RGB): XYZ {\n const xyz: XYZ = [0, 0, 0]\n const transform = srgbReverseTransform\n const matrix = srgbReverseMatrix\n\n // Rescale from [0, 255] to [0, 1] then adjust sRGB gamma to linear RGB\n r = transform(r / 255)\n g = transform(g / 255)\n b = transform(b / 255)\n\n // Matrix color space transform\n for (let i = 0; i < 3; ++i) {\n xyz[i] = matrix[i][0] * r + matrix[i][1] * g + matrix[i][2] * b\n }\n\n return xyz\n}\n"],"mappings":"AAAA;AAAA,SACSA,KAAK,yBAEd;AAGA;AACA,MAAMC,iBAAiB,GAAG,CACxB,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,EAC1B,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EACzB,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAC1B;;AAED;AACA,MAAMC,oBAAoB,GAAIC,CAAS,IACrCA,CAAC,IAAI,SAAS,GACVA,CAAC,GAAG,KAAK,GACT,KAAK,GAAGA,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,GAAG,KAC9B;;AAED;AACA,MAAMC,iBAAiB,GAAG,CACxB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EACxB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EACxB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CACzB;;AAED;AACA,MAAMC,oBAAoB,GAAIF,CAAS,IACrCA,CAAC,IAAI,OAAO,GACRA,CAAC,GAAG,KAAK,GACT,CAAC,CAACA,CAAC,GAAG,KAAK,IAAI,KAAK,KAAK,GAC9B;AAED,OAAO,SAASG,OAAOA,CAAEC,GAAQ,EAAO;EACtC,MAAMC,GAAG,GAAGC,KAAK,CAAC,CAAC,CAAC;EACpB,MAAMC,SAAS,GAAGR,oBAAoB;EACtC,MAAMS,MAAM,GAAGV,iBAAiB;;EAEhC;EACA,KAAK,IAAIW,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAG,CAAC,EAAE,EAAEA,CAAC,EAAE;IAC1B;IACAJ,GAAG,CAACI,CAAC,CAAC,GAAGC,IAAI,CAACC,KAAK,CAACd,KAAK,CAACU,SAAS,CACjCC,MAAM,CAACC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAGL,GAAG,CAAC,CAAC,CAAC,GACrBI,MAAM,CAACC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAGL,GAAG,CAAC,CAAC,CAAC,GACrBI,MAAM,CAACC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAGL,GAAG,CAAC,CAAC,CACtB,CAAC,CAAC,GAAG,GAAG,CAAC;EACX;EAEA,OAAO;IACLQ,CAAC,EAAEP,GAAG,CAAC,CAAC,CAAC;IACTQ,CAAC,EAAER,GAAG,CAAC,CAAC,CAAC;IACTS,CAAC,EAAET,GAAG,CAAC,CAAC;EACV,CAAC;AACH;AAEA,OAAO,SAASU,KAAKA,CAAE;EAAEH,CAAC;EAAEC,CAAC;EAAEC;AAAO,CAAC,EAAO;EAC5C,MAAMV,GAAQ,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;EAC1B,MAAMG,SAAS,GAAGL,oBAAoB;EACtC,MAAMM,MAAM,GAAGP,iBAAiB;;EAEhC;EACAW,CAAC,GAAGL,SAAS,CAACK,CAAC,GAAG,GAAG,CAAC;EACtBC,CAAC,GAAGN,SAAS,CAACM,CAAC,GAAG,GAAG,CAAC;EACtBC,CAAC,GAAGP,SAAS,CAACO,CAAC,GAAG,GAAG,CAAC;;EAEtB;EACA,KAAK,IAAIL,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAG,CAAC,EAAE,EAAEA,CAAC,EAAE;IAC1BL,GAAG,CAACK,CAAC,CAAC,GAAGD,MAAM,CAACC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAGG,CAAC,GAAGJ,MAAM,CAACC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAGI,CAAC,GAAGL,MAAM,CAACC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAGK,CAAC;EACjE;EAEA,OAAOV,GAAG;AACZ","ignoreList":[]}
+58
View File
@@ -0,0 +1,58 @@
import type { Colors } from '../composables/theme.js';
export type XYZ = [number, number, number];
export type LAB = [number, number, number];
export type HSV = {
h: number;
s: number;
v: number;
a?: number;
};
export type RGB = {
r: number;
g: number;
b: number;
a?: number;
};
export type HSL = {
h: number;
s: number;
l: number;
a?: number;
};
export type Hex = string & {
__hexBrand: never;
};
export type Color = string | number | HSV | RGB | HSL;
export declare function isCssColor(color?: string | null | false): boolean;
export declare function isParsableColor(color: string): boolean;
export declare function parseColor(color: Color): RGB;
export declare function RGBToInt(color: RGB): number;
export declare function classToHex(color: string, colors: Record<string, Record<string, string>>, currentTheme: Partial<Colors>): string;
/** Converts HSVA to RGBA. Based on formula from https://en.wikipedia.org/wiki/HSL_and_HSV */
export declare function HSVtoRGB(hsva: HSV): RGB;
export declare function HSLtoRGB(hsla: HSL): RGB;
/** Converts RGBA to HSVA. Based on formula from https://en.wikipedia.org/wiki/HSL_and_HSV */
export declare function RGBtoHSV(rgba: RGB): HSV;
export declare function HSVtoHSL(hsva: HSV): HSL;
export declare function HSLtoHSV(hsl: HSL): HSV;
export declare function RGBtoCSS({ r, g, b, a }: RGB): string;
export declare function HSVtoCSS(hsva: HSV): string;
export declare function RGBtoHex({ r, g, b, a }: RGB): Hex;
export declare function HexToRGB(hex: Hex): RGB;
export declare function HexToHSV(hex: Hex): HSV;
export declare function HSVtoHex(hsva: HSV): Hex;
export declare function parseHex(hex: string): Hex;
export declare function parseGradient(gradient: string, colors: Record<string, Record<string, string>>, currentTheme: Partial<Colors>): string;
export declare function lighten(value: RGB, amount: number): RGB;
export declare function darken(value: RGB, amount: number): RGB;
/**
* Calculate the relative luminance of a given color
* @see https://www.w3.org/TR/WCAG20/#relativeluminancedef
*/
export declare function getLuma(color: Color): number;
/**
* Returns the contrast ratio (1-21) between two colors.
* @see https://www.w3.org/TR/WCAG20/#contrast-ratiodef
*/
export declare function getContrast(first: Color, second: Color): number;
export declare function hasLightForeground(color: Color): boolean;
+319
View File
@@ -0,0 +1,319 @@
// Utilities
import { APCAcontrast } from "./color/APCA.js";
import { consoleWarn } from "./console.js";
import { chunk, has, padEnd } from "./helpers.js";
import * as CIELAB from "./color/transformCIELAB.js";
import * as sRGB from "./color/transformSRGB.js"; // Types
export function isCssColor(color) {
return !!color && /^(#|var\(--|(rgb|hsl)a?\()/.test(color);
}
export function isParsableColor(color) {
return isCssColor(color) && !/^((rgb|hsl)a?\()?var\(--/.test(color);
}
const cssColorRe = /^(?<fn>(?:rgb|hsl)a?)\((?<values>.+)\)/;
const mappers = {
rgb: (r, g, b, a) => ({
r,
g,
b,
a
}),
rgba: (r, g, b, a) => ({
r,
g,
b,
a
}),
hsl: (h, s, l, a) => HSLtoRGB({
h,
s,
l,
a
}),
hsla: (h, s, l, a) => HSLtoRGB({
h,
s,
l,
a
}),
hsv: (h, s, v, a) => HSVtoRGB({
h,
s,
v,
a
}),
hsva: (h, s, v, a) => HSVtoRGB({
h,
s,
v,
a
})
};
export function parseColor(color) {
if (typeof color === 'number') {
if (isNaN(color) || color < 0 || color > 0xFFFFFF) {
// int can't have opacity
consoleWarn(`'${color}' is not a valid hex color`);
}
return {
r: (color & 0xFF0000) >> 16,
g: (color & 0xFF00) >> 8,
b: color & 0xFF
};
} else if (typeof color === 'string' && cssColorRe.test(color)) {
const {
groups
} = color.match(cssColorRe);
const {
fn,
values
} = groups;
const realValues = values.split(/,\s*|\s*\/\s*|\s+/).map((v, i) => {
if (v.endsWith('%') ||
// unitless slv are %
i > 0 && i < 3 && ['hsl', 'hsla', 'hsv', 'hsva'].includes(fn)) {
return parseFloat(v) / 100;
} else {
return parseFloat(v);
}
});
return mappers[fn](...realValues);
} else if (typeof color === 'string') {
let hex = color.startsWith('#') ? color.slice(1) : color;
if ([3, 4].includes(hex.length)) {
hex = hex.split('').map(char => char + char).join('');
} else if (![6, 8].includes(hex.length)) {
consoleWarn(`'${color}' is not a valid hex(a) color`);
}
const int = parseInt(hex, 16);
if (isNaN(int) || int < 0 || int > 0xFFFFFFFF) {
consoleWarn(`'${color}' is not a valid hex(a) color`);
}
return HexToRGB(hex);
} else if (typeof color === 'object') {
if (has(color, ['r', 'g', 'b'])) {
return color;
} else if (has(color, ['h', 's', 'l'])) {
return HSVtoRGB(HSLtoHSV(color));
} else if (has(color, ['h', 's', 'v'])) {
return HSVtoRGB(color);
}
}
throw new TypeError(`Invalid color: ${color == null ? color : String(color) || color.constructor.name}\nExpected #hex, #hexa, rgb(), rgba(), hsl(), hsla(), object or number`);
}
export function RGBToInt(color) {
return (color.r << 16) + (color.g << 8) + color.b;
}
export function classToHex(color, colors, currentTheme) {
const [colorName, colorModifier] = color.toString().trim().replace('-', '').split(' ', 2);
let hexColor = '';
if (colorName && colorName in colors) {
if (colorModifier && colorModifier in colors[colorName]) {
hexColor = colors[colorName][colorModifier];
} else if ('base' in colors[colorName]) {
hexColor = colors[colorName].base;
}
} else if (colorName && colorName in currentTheme) {
hexColor = currentTheme[colorName];
}
return hexColor;
}
/** Converts HSVA to RGBA. Based on formula from https://en.wikipedia.org/wiki/HSL_and_HSV */
export function HSVtoRGB(hsva) {
const {
h,
s,
v,
a
} = hsva;
const f = n => {
const k = (n + h / 60) % 6;
return v - v * s * Math.max(Math.min(k, 4 - k, 1), 0);
};
const rgb = [f(5), f(3), f(1)].map(v => Math.round(v * 255));
return {
r: rgb[0],
g: rgb[1],
b: rgb[2],
a
};
}
export function HSLtoRGB(hsla) {
return HSVtoRGB(HSLtoHSV(hsla));
}
/** Converts RGBA to HSVA. Based on formula from https://en.wikipedia.org/wiki/HSL_and_HSV */
export function RGBtoHSV(rgba) {
if (!rgba) return {
h: 0,
s: 1,
v: 1,
a: 1
};
const r = rgba.r / 255;
const g = rgba.g / 255;
const b = rgba.b / 255;
const max = Math.max(r, g, b);
const min = Math.min(r, g, b);
let h = 0;
if (max !== min) {
if (max === r) {
h = 60 * (0 + (g - b) / (max - min));
} else if (max === g) {
h = 60 * (2 + (b - r) / (max - min));
} else if (max === b) {
h = 60 * (4 + (r - g) / (max - min));
}
}
if (h < 0) h = h + 360;
const s = max === 0 ? 0 : (max - min) / max;
const hsv = [h, s, max];
return {
h: hsv[0],
s: hsv[1],
v: hsv[2],
a: rgba.a
};
}
export function HSVtoHSL(hsva) {
const {
h,
s,
v,
a
} = hsva;
const l = v - v * s / 2;
const sprime = l === 1 || l === 0 ? 0 : (v - l) / Math.min(l, 1 - l);
return {
h,
s: sprime,
l,
a
};
}
export function HSLtoHSV(hsl) {
const {
h,
s,
l,
a
} = hsl;
const v = l + s * Math.min(l, 1 - l);
const sprime = v === 0 ? 0 : 2 - 2 * l / v;
return {
h,
s: sprime,
v,
a
};
}
export function RGBtoCSS({
r,
g,
b,
a
}) {
return a === undefined ? `rgb(${r}, ${g}, ${b})` : `rgba(${r}, ${g}, ${b}, ${a})`;
}
export function HSVtoCSS(hsva) {
return RGBtoCSS(HSVtoRGB(hsva));
}
function toHex(v) {
const h = Math.round(v).toString(16);
return ('00'.substr(0, 2 - h.length) + h).toUpperCase();
}
export function RGBtoHex({
r,
g,
b,
a
}) {
return `#${[toHex(r), toHex(g), toHex(b), a !== undefined ? toHex(Math.round(a * 255)) : ''].join('')}`;
}
export function HexToRGB(hex) {
hex = parseHex(hex);
let [r, g, b, a] = chunk(hex, 2).map(c => parseInt(c, 16));
a = a === undefined ? a : a / 255;
return {
r,
g,
b,
a
};
}
export function HexToHSV(hex) {
const rgb = HexToRGB(hex);
return RGBtoHSV(rgb);
}
export function HSVtoHex(hsva) {
return RGBtoHex(HSVtoRGB(hsva));
}
export function parseHex(hex) {
if (hex.startsWith('#')) {
hex = hex.slice(1);
}
hex = hex.replace(/([^0-9a-f])/gi, 'F');
if (hex.length === 3 || hex.length === 4) {
hex = hex.split('').map(x => x + x).join('');
}
if (hex.length !== 6) {
hex = padEnd(padEnd(hex, 6), 8, 'F');
}
return hex;
}
export function parseGradient(gradient, colors, currentTheme) {
return gradient.replace(/([a-z]+(\s[a-z]+-[1-5])?)(?=$|,)/gi, x => {
return classToHex(x, colors, currentTheme) || x;
}).replace(/(rgba\()#[0-9a-f]+(?=,)/gi, x => {
return 'rgba(' + Object.values(HexToRGB(parseHex(x.replace(/rgba\(/, '')))).slice(0, 3).join(',');
});
}
export function lighten(value, amount) {
const lab = CIELAB.fromXYZ(sRGB.toXYZ(value));
lab[0] = lab[0] + amount * 10;
return sRGB.fromXYZ(CIELAB.toXYZ(lab));
}
export function darken(value, amount) {
const lab = CIELAB.fromXYZ(sRGB.toXYZ(value));
lab[0] = lab[0] - amount * 10;
return sRGB.fromXYZ(CIELAB.toXYZ(lab));
}
/**
* Calculate the relative luminance of a given color
* @see https://www.w3.org/TR/WCAG20/#relativeluminancedef
*/
export function getLuma(color) {
const rgb = parseColor(color);
return sRGB.toXYZ(rgb)[1];
}
/**
* Returns the contrast ratio (1-21) between two colors.
* @see https://www.w3.org/TR/WCAG20/#contrast-ratiodef
*/
export function getContrast(first, second) {
const l1 = getLuma(first);
const l2 = getLuma(second);
const light = Math.max(l1, l2);
const dark = Math.min(l1, l2);
return (light + 0.05) / (dark + 0.05);
}
export function hasLightForeground(color) {
const blackContrast = Math.abs(APCAcontrast(parseColor(0), parseColor(color)));
const whiteContrast = Math.abs(APCAcontrast(parseColor(0xffffff), parseColor(color)));
// TODO: warn about poor color selections
// const contrastAsText = Math.abs(APCAcontrast(colorVal, colorToInt(theme.colors.background)))
// const minContrast = Math.max(blackContrast, whiteContrast)
// if (minContrast < 60) {
// consoleInfo(`${key} theme color ${color} has poor contrast (${minContrast.toFixed()}%)`)
// } else if (contrastAsText < 60 && !['background', 'surface'].includes(color)) {
// consoleInfo(`${key} theme color ${color} has poor contrast as text (${contrastAsText.toFixed()}%)`)
// }
// Prefer white text if both have an acceptable contrast ratio
return whiteContrast > Math.min(blackContrast, 50);
}
//# sourceMappingURL=colorUtils.js.map
File diff suppressed because one or more lines are too long
+597
View File
@@ -0,0 +1,597 @@
export declare const red: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
export declare const pink: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
export declare const purple: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
export declare const deepPurple: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
export declare const indigo: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
export declare const blue: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
export declare const lightBlue: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
export declare const cyan: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
export declare const teal: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
export declare const green: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
export declare const lightGreen: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
export declare const lime: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
export declare const yellow: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
export declare const amber: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
export declare const orange: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
export declare const deepOrange: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
export declare const brown: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
};
export declare const blueGrey: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
};
export declare const grey: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
};
export declare const shades: {
black: string;
white: string;
transparent: string;
};
declare const _default: {
red: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
pink: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
purple: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
deepPurple: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
indigo: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
blue: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
lightBlue: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
cyan: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
teal: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
green: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
lightGreen: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
lime: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
yellow: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
amber: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
orange: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
deepOrange: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
accent1: string;
accent2: string;
accent3: string;
accent4: string;
};
brown: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
};
blueGrey: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
};
grey: {
base: string;
lighten5: string;
lighten4: string;
lighten3: string;
lighten2: string;
lighten1: string;
darken1: string;
darken2: string;
darken3: string;
darken4: string;
};
shades: {
black: string;
white: string;
transparent: string;
};
};
export default _default;
+320
View File
@@ -0,0 +1,320 @@
export const red = {
base: '#f44336',
lighten5: '#ffebee',
lighten4: '#ffcdd2',
lighten3: '#ef9a9a',
lighten2: '#e57373',
lighten1: '#ef5350',
darken1: '#e53935',
darken2: '#d32f2f',
darken3: '#c62828',
darken4: '#b71c1c',
accent1: '#ff8a80',
accent2: '#ff5252',
accent3: '#ff1744',
accent4: '#d50000'
};
export const pink = {
base: '#e91e63',
lighten5: '#fce4ec',
lighten4: '#f8bbd0',
lighten3: '#f48fb1',
lighten2: '#f06292',
lighten1: '#ec407a',
darken1: '#d81b60',
darken2: '#c2185b',
darken3: '#ad1457',
darken4: '#880e4f',
accent1: '#ff80ab',
accent2: '#ff4081',
accent3: '#f50057',
accent4: '#c51162'
};
export const purple = {
base: '#9c27b0',
lighten5: '#f3e5f5',
lighten4: '#e1bee7',
lighten3: '#ce93d8',
lighten2: '#ba68c8',
lighten1: '#ab47bc',
darken1: '#8e24aa',
darken2: '#7b1fa2',
darken3: '#6a1b9a',
darken4: '#4a148c',
accent1: '#ea80fc',
accent2: '#e040fb',
accent3: '#d500f9',
accent4: '#aa00ff'
};
export const deepPurple = {
base: '#673ab7',
lighten5: '#ede7f6',
lighten4: '#d1c4e9',
lighten3: '#b39ddb',
lighten2: '#9575cd',
lighten1: '#7e57c2',
darken1: '#5e35b1',
darken2: '#512da8',
darken3: '#4527a0',
darken4: '#311b92',
accent1: '#b388ff',
accent2: '#7c4dff',
accent3: '#651fff',
accent4: '#6200ea'
};
export const indigo = {
base: '#3f51b5',
lighten5: '#e8eaf6',
lighten4: '#c5cae9',
lighten3: '#9fa8da',
lighten2: '#7986cb',
lighten1: '#5c6bc0',
darken1: '#3949ab',
darken2: '#303f9f',
darken3: '#283593',
darken4: '#1a237e',
accent1: '#8c9eff',
accent2: '#536dfe',
accent3: '#3d5afe',
accent4: '#304ffe'
};
export const blue = {
base: '#2196f3',
lighten5: '#e3f2fd',
lighten4: '#bbdefb',
lighten3: '#90caf9',
lighten2: '#64b5f6',
lighten1: '#42a5f5',
darken1: '#1e88e5',
darken2: '#1976d2',
darken3: '#1565c0',
darken4: '#0d47a1',
accent1: '#82b1ff',
accent2: '#448aff',
accent3: '#2979ff',
accent4: '#2962ff'
};
export const lightBlue = {
base: '#03a9f4',
lighten5: '#e1f5fe',
lighten4: '#b3e5fc',
lighten3: '#81d4fa',
lighten2: '#4fc3f7',
lighten1: '#29b6f6',
darken1: '#039be5',
darken2: '#0288d1',
darken3: '#0277bd',
darken4: '#01579b',
accent1: '#80d8ff',
accent2: '#40c4ff',
accent3: '#00b0ff',
accent4: '#0091ea'
};
export const cyan = {
base: '#00bcd4',
lighten5: '#e0f7fa',
lighten4: '#b2ebf2',
lighten3: '#80deea',
lighten2: '#4dd0e1',
lighten1: '#26c6da',
darken1: '#00acc1',
darken2: '#0097a7',
darken3: '#00838f',
darken4: '#006064',
accent1: '#84ffff',
accent2: '#18ffff',
accent3: '#00e5ff',
accent4: '#00b8d4'
};
export const teal = {
base: '#009688',
lighten5: '#e0f2f1',
lighten4: '#b2dfdb',
lighten3: '#80cbc4',
lighten2: '#4db6ac',
lighten1: '#26a69a',
darken1: '#00897b',
darken2: '#00796b',
darken3: '#00695c',
darken4: '#004d40',
accent1: '#a7ffeb',
accent2: '#64ffda',
accent3: '#1de9b6',
accent4: '#00bfa5'
};
export const green = {
base: '#4caf50',
lighten5: '#e8f5e9',
lighten4: '#c8e6c9',
lighten3: '#a5d6a7',
lighten2: '#81c784',
lighten1: '#66bb6a',
darken1: '#43a047',
darken2: '#388e3c',
darken3: '#2e7d32',
darken4: '#1b5e20',
accent1: '#b9f6ca',
accent2: '#69f0ae',
accent3: '#00e676',
accent4: '#00c853'
};
export const lightGreen = {
base: '#8bc34a',
lighten5: '#f1f8e9',
lighten4: '#dcedc8',
lighten3: '#c5e1a5',
lighten2: '#aed581',
lighten1: '#9ccc65',
darken1: '#7cb342',
darken2: '#689f38',
darken3: '#558b2f',
darken4: '#33691e',
accent1: '#ccff90',
accent2: '#b2ff59',
accent3: '#76ff03',
accent4: '#64dd17'
};
export const lime = {
base: '#cddc39',
lighten5: '#f9fbe7',
lighten4: '#f0f4c3',
lighten3: '#e6ee9c',
lighten2: '#dce775',
lighten1: '#d4e157',
darken1: '#c0ca33',
darken2: '#afb42b',
darken3: '#9e9d24',
darken4: '#827717',
accent1: '#f4ff81',
accent2: '#eeff41',
accent3: '#c6ff00',
accent4: '#aeea00'
};
export const yellow = {
base: '#ffeb3b',
lighten5: '#fffde7',
lighten4: '#fff9c4',
lighten3: '#fff59d',
lighten2: '#fff176',
lighten1: '#ffee58',
darken1: '#fdd835',
darken2: '#fbc02d',
darken3: '#f9a825',
darken4: '#f57f17',
accent1: '#ffff8d',
accent2: '#ffff00',
accent3: '#ffea00',
accent4: '#ffd600'
};
export const amber = {
base: '#ffc107',
lighten5: '#fff8e1',
lighten4: '#ffecb3',
lighten3: '#ffe082',
lighten2: '#ffd54f',
lighten1: '#ffca28',
darken1: '#ffb300',
darken2: '#ffa000',
darken3: '#ff8f00',
darken4: '#ff6f00',
accent1: '#ffe57f',
accent2: '#ffd740',
accent3: '#ffc400',
accent4: '#ffab00'
};
export const orange = {
base: '#ff9800',
lighten5: '#fff3e0',
lighten4: '#ffe0b2',
lighten3: '#ffcc80',
lighten2: '#ffb74d',
lighten1: '#ffa726',
darken1: '#fb8c00',
darken2: '#f57c00',
darken3: '#ef6c00',
darken4: '#e65100',
accent1: '#ffd180',
accent2: '#ffab40',
accent3: '#ff9100',
accent4: '#ff6d00'
};
export const deepOrange = {
base: '#ff5722',
lighten5: '#fbe9e7',
lighten4: '#ffccbc',
lighten3: '#ffab91',
lighten2: '#ff8a65',
lighten1: '#ff7043',
darken1: '#f4511e',
darken2: '#e64a19',
darken3: '#d84315',
darken4: '#bf360c',
accent1: '#ff9e80',
accent2: '#ff6e40',
accent3: '#ff3d00',
accent4: '#dd2c00'
};
export const brown = {
base: '#795548',
lighten5: '#efebe9',
lighten4: '#d7ccc8',
lighten3: '#bcaaa4',
lighten2: '#a1887f',
lighten1: '#8d6e63',
darken1: '#6d4c41',
darken2: '#5d4037',
darken3: '#4e342e',
darken4: '#3e2723'
};
export const blueGrey = {
base: '#607d8b',
lighten5: '#eceff1',
lighten4: '#cfd8dc',
lighten3: '#b0bec5',
lighten2: '#90a4ae',
lighten1: '#78909c',
darken1: '#546e7a',
darken2: '#455a64',
darken3: '#37474f',
darken4: '#263238'
};
export const grey = {
base: '#9e9e9e',
lighten5: '#fafafa',
lighten4: '#f5f5f5',
lighten3: '#eeeeee',
lighten2: '#e0e0e0',
lighten1: '#bdbdbd',
darken1: '#757575',
darken2: '#616161',
darken3: '#424242',
darken4: '#212121'
};
export const shades = {
black: '#000000',
white: '#ffffff',
transparent: '#ffffff00'
};
export default {
red,
pink,
purple,
deepPurple,
indigo,
blue,
lightBlue,
cyan,
teal,
green,
lightGreen,
lime,
yellow,
amber,
orange,
deepOrange,
brown,
blueGrey,
grey,
shades
};
//# sourceMappingURL=colors.js.map
File diff suppressed because one or more lines are too long
+5
View File
@@ -0,0 +1,5 @@
export declare function consoleWarn(message: string): void;
export declare function consoleError(message: string): void;
export declare function deprecate(original: string, replacement: string | string[]): void;
export declare function breaking(original: string, replacement: string): void;
export declare function removed(original: string): void;
+21
View File
@@ -0,0 +1,21 @@
/* eslint-disable no-console */
// Utilities
import { warn } from 'vue';
export function consoleWarn(message) {
warn(`Vuetify: ${message}`);
}
export function consoleError(message) {
warn(`Vuetify error: ${message}`);
}
export function deprecate(original, replacement) {
replacement = Array.isArray(replacement) ? replacement.slice(0, -1).map(s => `'${s}'`).join(', ') + ` or '${replacement.at(-1)}'` : `'${replacement}'`;
warn(`[Vuetify UPGRADE] '${original}' is deprecated, use ${replacement} instead.`);
}
export function breaking(original, replacement) {
// warn(`[Vuetify BREAKING] '${original}' has been removed, use '${replacement}' instead. For more information, see the upgrade guide https://github.com/vuetifyjs/vuetify/releases/tag/v2.0.0#user-content-upgrade-guide`)
}
export function removed(original) {
// warn(`[Vuetify REMOVED] '${original}' has been removed. You can safely omit it.`)
}
//# sourceMappingURL=console.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"console.js","names":["warn","consoleWarn","message","consoleError","deprecate","original","replacement","Array","isArray","slice","map","s","join","at","breaking","removed"],"sources":["../../src/util/console.ts"],"sourcesContent":["/* eslint-disable no-console */\n\n// Utilities\nimport { warn } from 'vue'\n\nexport function consoleWarn (message: string): void {\n warn(`Vuetify: ${message}`)\n}\n\nexport function consoleError (message: string): void {\n warn(`Vuetify error: ${message}`)\n}\n\nexport function deprecate (original: string, replacement: string | string[]) {\n replacement = Array.isArray(replacement)\n ? replacement.slice(0, -1).map(s => `'${s}'`).join(', ') + ` or '${replacement.at(-1)}'`\n : `'${replacement}'`\n warn(`[Vuetify UPGRADE] '${original}' is deprecated, use ${replacement} instead.`)\n}\nexport function breaking (original: string, replacement: string) {\n // warn(`[Vuetify BREAKING] '${original}' has been removed, use '${replacement}' instead. For more information, see the upgrade guide https://github.com/vuetifyjs/vuetify/releases/tag/v2.0.0#user-content-upgrade-guide`)\n}\nexport function removed (original: string) {\n // warn(`[Vuetify REMOVED] '${original}' has been removed. You can safely omit it.`)\n}\n"],"mappings":"AAAA;;AAEA;AACA,SAASA,IAAI,QAAQ,KAAK;AAE1B,OAAO,SAASC,WAAWA,CAAEC,OAAe,EAAQ;EAClDF,IAAI,CAAC,YAAYE,OAAO,EAAE,CAAC;AAC7B;AAEA,OAAO,SAASC,YAAYA,CAAED,OAAe,EAAQ;EACnDF,IAAI,CAAC,kBAAkBE,OAAO,EAAE,CAAC;AACnC;AAEA,OAAO,SAASE,SAASA,CAAEC,QAAgB,EAAEC,WAA8B,EAAE;EAC3EA,WAAW,GAAGC,KAAK,CAACC,OAAO,CAACF,WAAW,CAAC,GACpCA,WAAW,CAACG,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAACC,GAAG,CAACC,CAAC,IAAI,IAAIA,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC,GAAG,QAAQN,WAAW,CAACO,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,GACtF,IAAIP,WAAW,GAAG;EACtBN,IAAI,CAAC,sBAAsBK,QAAQ,wBAAwBC,WAAW,WAAW,CAAC;AACpF;AACA,OAAO,SAASQ,QAAQA,CAAET,QAAgB,EAAEC,WAAmB,EAAE;EAC/D;AAAA;AAEF,OAAO,SAASS,OAAOA,CAAEV,QAAgB,EAAE;EACzC;AAAA","ignoreList":[]}
+104
View File
@@ -0,0 +1,104 @@
export declare function createSimpleFunctional(klass: string, tag?: string, name?: string): {
new (...args: any[]): import("vue").CreateComponentPublicInstanceWithMixins<{
style: string | false | import("vue").StyleValue[] | import("vue").CSSProperties | null;
tag: string;
} & {
class?: any;
} & {
$children?: {
default?: (() => import("vue").VNodeChild) | undefined;
} | {
$stable?: boolean;
} | (() => import("vue").VNodeChild) | import("vue").VNodeChild;
'v-slots'?: {
default?: false | (() => import("vue").VNodeChild) | undefined;
} | undefined;
} & {
"v-slot:default"?: false | (() => import("vue").VNodeChild) | undefined;
}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
}>, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, {
style: import("vue").StyleValue;
tag: string;
}, true, {}, import("vue").SlotsType<Partial<{
default: () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
}>[];
}>>, import("vue").GlobalComponents, import("vue").GlobalDirectives, string, {}, any, import("vue").ComponentProvideOptions, {
P: {};
B: {};
D: {};
C: {};
M: {};
Defaults: {};
}, {
style: string | false | import("vue").StyleValue[] | import("vue").CSSProperties | null;
tag: string;
} & {
class?: any;
} & {
$children?: {
default?: (() => import("vue").VNodeChild) | undefined;
} | {
$stable?: boolean;
} | (() => import("vue").VNodeChild) | import("vue").VNodeChild;
'v-slots'?: {
default?: false | (() => import("vue").VNodeChild) | undefined;
} | undefined;
} & {
"v-slot:default"?: false | (() => import("vue").VNodeChild) | undefined;
}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
}>, {}, {}, {}, {
style: import("vue").StyleValue;
tag: string;
}>;
__isFragment?: never;
__isTeleport?: never;
__isSuspense?: never;
} & import("vue").ComponentOptionsBase<{
style: string | false | import("vue").StyleValue[] | import("vue").CSSProperties | null;
tag: string;
} & {
class?: any;
} & {
$children?: {
default?: (() => import("vue").VNodeChild) | undefined;
} | {
$stable?: boolean;
} | (() => import("vue").VNodeChild) | import("vue").VNodeChild;
'v-slots'?: {
default?: false | (() => import("vue").VNodeChild) | undefined;
} | undefined;
} & {
"v-slot:default"?: false | (() => import("vue").VNodeChild) | undefined;
}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
}>, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, {
style: import("vue").StyleValue;
tag: string;
}, {}, string, import("vue").SlotsType<Partial<{
default: () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
}>[];
}>>, import("vue").GlobalComponents, import("vue").GlobalDirectives, string, import("vue").ComponentProvideOptions> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & import("./defineComponent.js").FilterPropsOptions<{
class: import("vue").PropType<any>;
style: {
type: import("vue").PropType<import("vue").StyleValue>;
default: null;
};
tag: {
type: StringConstructor;
default: string;
};
}, import("vue").ExtractPropTypes<{
class: import("vue").PropType<any>;
style: {
type: import("vue").PropType<import("vue").StyleValue>;
default: null;
};
tag: {
type: StringConstructor;
default: string;
};
}>>;
+27
View File
@@ -0,0 +1,27 @@
// Composables
import { makeComponentProps } from "../composables/component.js"; // Utilities
import { camelize, capitalize, h } from 'vue';
import { genericComponent } from "./defineComponent.js";
export function createSimpleFunctional(klass, tag = 'div', name) {
return genericComponent()({
name: name ?? capitalize(camelize(klass.replace(/__/g, '-'))),
props: {
tag: {
type: String,
default: tag
},
...makeComponentProps()
},
setup(props, {
slots
}) {
return () => {
return h(props.tag, {
class: [klass, props.class],
style: props.style
}, slots.default?.());
};
}
});
}
//# sourceMappingURL=createSimpleFunctional.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"createSimpleFunctional.js","names":["makeComponentProps","camelize","capitalize","h","genericComponent","createSimpleFunctional","klass","tag","name","replace","props","type","String","default","setup","slots","class","style"],"sources":["../../src/util/createSimpleFunctional.ts"],"sourcesContent":["// Composables\nimport { makeComponentProps } from '@/composables/component'\n\n// Utilities\nimport { camelize, capitalize, h } from 'vue'\nimport { genericComponent } from './defineComponent'\n\nexport function createSimpleFunctional (\n klass: string,\n tag = 'div',\n name?: string\n) {\n return genericComponent()({\n name: name ?? capitalize(camelize(klass.replace(/__/g, '-'))),\n\n props: {\n tag: {\n type: String,\n default: tag,\n },\n\n ...makeComponentProps(),\n },\n\n setup (props, { slots }) {\n return () => {\n return h(props.tag, {\n class: [klass, props.class],\n style: props.style,\n }, slots.default?.())\n }\n },\n })\n}\n"],"mappings":"AAAA;AAAA,SACSA,kBAAkB,uCAE3B;AACA,SAASC,QAAQ,EAAEC,UAAU,EAAEC,CAAC,QAAQ,KAAK;AAAA,SACpCC,gBAAgB;AAEzB,OAAO,SAASC,sBAAsBA,CACpCC,KAAa,EACbC,GAAG,GAAG,KAAK,EACXC,IAAa,EACb;EACA,OAAOJ,gBAAgB,CAAC,CAAC,CAAC;IACxBI,IAAI,EAAEA,IAAI,IAAIN,UAAU,CAACD,QAAQ,CAACK,KAAK,CAACG,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;IAE7DC,KAAK,EAAE;MACLH,GAAG,EAAE;QACHI,IAAI,EAAEC,MAAM;QACZC,OAAO,EAAEN;MACX,CAAC;MAED,GAAGP,kBAAkB,CAAC;IACxB,CAAC;IAEDc,KAAKA,CAAEJ,KAAK,EAAE;MAAEK;IAAM,CAAC,EAAE;MACvB,OAAO,MAAM;QACX,OAAOZ,CAAC,CAACO,KAAK,CAACH,GAAG,EAAE;UAClBS,KAAK,EAAE,CAACV,KAAK,EAAEI,KAAK,CAACM,KAAK,CAAC;UAC3BC,KAAK,EAAEP,KAAK,CAACO;QACf,CAAC,EAAEF,KAAK,CAACF,OAAO,GAAG,CAAC,CAAC;MACvB,CAAC;IACH;EACF,CAAC,CAAC;AACJ","ignoreList":[]}
+2
View File
@@ -0,0 +1,2 @@
export type ValueComparator = (a: any, b: any) => boolean;
export declare function deepEqual(a: any, b: any, recursionCache?: WeakMap<WeakKey, any>): boolean;
+43
View File
@@ -0,0 +1,43 @@
import { isPrimitive } from "./helpers.js";
function updateRecursionCache(a, b, cache, result) {
if (!cache || isPrimitive(a) || isPrimitive(b)) return;
const visitedObject = cache.get(a);
if (visitedObject) {
visitedObject.set(b, result);
} else {
const newCacheItem = new WeakMap();
newCacheItem.set(b, result);
cache.set(a, newCacheItem);
}
}
function findCachedComparison(a, b, cache) {
if (!cache || isPrimitive(a) || isPrimitive(b)) return null;
const r1 = cache.get(a)?.get(b);
if (typeof r1 === 'boolean') return r1;
const r2 = cache.get(b)?.get(a);
if (typeof r2 === 'boolean') return r2;
return null;
}
export function deepEqual(a, b, recursionCache = new WeakMap()) {
if (a === b) return true;
if (a instanceof Date && b instanceof Date && a.getTime() !== b.getTime()) {
// If the values are Date, compare them as timestamps
return false;
}
if (a !== Object(a) || b !== Object(b)) {
// If the values aren't objects, they were already checked for equality
return false;
}
const props = Object.keys(a);
if (props.length !== Object.keys(b).length) {
// Different number of props, don't bother to check
return false;
}
const cachedComparisonResult = findCachedComparison(a, b, recursionCache);
if (cachedComparisonResult) {
return cachedComparisonResult;
}
updateRecursionCache(a, b, recursionCache, true);
return props.every(p => deepEqual(a[p], b[p], recursionCache));
}
//# sourceMappingURL=deepEqual.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"deepEqual.js","names":["isPrimitive","updateRecursionCache","a","b","cache","result","visitedObject","get","set","newCacheItem","WeakMap","findCachedComparison","r1","r2","deepEqual","recursionCache","Date","getTime","Object","props","keys","length","cachedComparisonResult","every","p"],"sources":["../../src/util/deepEqual.ts"],"sourcesContent":["import { isPrimitive } from './helpers'\n\nfunction updateRecursionCache (a: any, b: any, cache: WeakMap<any, any>, result: boolean) {\n if (!cache || isPrimitive(a) || isPrimitive(b)) return\n\n const visitedObject = cache.get(a)\n if (visitedObject) {\n visitedObject.set(b, result)\n } else {\n const newCacheItem = new WeakMap()\n newCacheItem.set(b, result)\n cache.set(a, newCacheItem)\n }\n}\n\nfunction findCachedComparison (a: any, b: any, cache: WeakMap<any, any>): boolean | null {\n if (!cache || isPrimitive(a) || isPrimitive(b)) return null\n\n const r1 = cache.get(a)?.get(b)\n if (typeof r1 === 'boolean') return r1\n const r2 = cache.get(b)?.get(a)\n if (typeof r2 === 'boolean') return r2\n return null\n}\n\nexport type ValueComparator = (a: any, b: any) => boolean\n\nexport function deepEqual (a: any, b: any, recursionCache = new WeakMap()): boolean {\n if (a === b) return true\n\n if (\n a instanceof Date &&\n b instanceof Date &&\n a.getTime() !== b.getTime()\n ) {\n // If the values are Date, compare them as timestamps\n return false\n }\n\n if (a !== Object(a) || b !== Object(b)) {\n // If the values aren't objects, they were already checked for equality\n return false\n }\n\n const props = Object.keys(a)\n\n if (props.length !== Object.keys(b).length) {\n // Different number of props, don't bother to check\n return false\n }\n\n const cachedComparisonResult = findCachedComparison(a, b, recursionCache)\n if (cachedComparisonResult) {\n return cachedComparisonResult\n }\n\n updateRecursionCache(a, b, recursionCache, true)\n\n return props.every(p => deepEqual(a[p], b[p], recursionCache))\n}\n"],"mappings":"SAASA,WAAW;AAEpB,SAASC,oBAAoBA,CAAEC,CAAM,EAAEC,CAAM,EAAEC,KAAwB,EAAEC,MAAe,EAAE;EACxF,IAAI,CAACD,KAAK,IAAIJ,WAAW,CAACE,CAAC,CAAC,IAAIF,WAAW,CAACG,CAAC,CAAC,EAAE;EAEhD,MAAMG,aAAa,GAAGF,KAAK,CAACG,GAAG,CAACL,CAAC,CAAC;EAClC,IAAII,aAAa,EAAE;IACjBA,aAAa,CAACE,GAAG,CAACL,CAAC,EAAEE,MAAM,CAAC;EAC9B,CAAC,MAAM;IACL,MAAMI,YAAY,GAAG,IAAIC,OAAO,CAAC,CAAC;IAClCD,YAAY,CAACD,GAAG,CAACL,CAAC,EAAEE,MAAM,CAAC;IAC3BD,KAAK,CAACI,GAAG,CAACN,CAAC,EAAEO,YAAY,CAAC;EAC5B;AACF;AAEA,SAASE,oBAAoBA,CAAET,CAAM,EAAEC,CAAM,EAAEC,KAAwB,EAAkB;EACvF,IAAI,CAACA,KAAK,IAAIJ,WAAW,CAACE,CAAC,CAAC,IAAIF,WAAW,CAACG,CAAC,CAAC,EAAE,OAAO,IAAI;EAE3D,MAAMS,EAAE,GAAGR,KAAK,CAACG,GAAG,CAACL,CAAC,CAAC,EAAEK,GAAG,CAACJ,CAAC,CAAC;EAC/B,IAAI,OAAOS,EAAE,KAAK,SAAS,EAAE,OAAOA,EAAE;EACtC,MAAMC,EAAE,GAAGT,KAAK,CAACG,GAAG,CAACJ,CAAC,CAAC,EAAEI,GAAG,CAACL,CAAC,CAAC;EAC/B,IAAI,OAAOW,EAAE,KAAK,SAAS,EAAE,OAAOA,EAAE;EACtC,OAAO,IAAI;AACb;AAIA,OAAO,SAASC,SAASA,CAAEZ,CAAM,EAAEC,CAAM,EAAEY,cAAc,GAAG,IAAIL,OAAO,CAAC,CAAC,EAAW;EAClF,IAAIR,CAAC,KAAKC,CAAC,EAAE,OAAO,IAAI;EAExB,IACED,CAAC,YAAYc,IAAI,IACjBb,CAAC,YAAYa,IAAI,IACjBd,CAAC,CAACe,OAAO,CAAC,CAAC,KAAKd,CAAC,CAACc,OAAO,CAAC,CAAC,EAC3B;IACA;IACA,OAAO,KAAK;EACd;EAEA,IAAIf,CAAC,KAAKgB,MAAM,CAAChB,CAAC,CAAC,IAAIC,CAAC,KAAKe,MAAM,CAACf,CAAC,CAAC,EAAE;IACtC;IACA,OAAO,KAAK;EACd;EAEA,MAAMgB,KAAK,GAAGD,MAAM,CAACE,IAAI,CAAClB,CAAC,CAAC;EAE5B,IAAIiB,KAAK,CAACE,MAAM,KAAKH,MAAM,CAACE,IAAI,CAACjB,CAAC,CAAC,CAACkB,MAAM,EAAE;IAC1C;IACA,OAAO,KAAK;EACd;EAEA,MAAMC,sBAAsB,GAAGX,oBAAoB,CAACT,CAAC,EAAEC,CAAC,EAAEY,cAAc,CAAC;EACzE,IAAIO,sBAAsB,EAAE;IAC1B,OAAOA,sBAAsB;EAC/B;EAEArB,oBAAoB,CAACC,CAAC,EAAEC,CAAC,EAAEY,cAAc,EAAE,IAAI,CAAC;EAEhD,OAAOI,KAAK,CAACI,KAAK,CAACC,CAAC,IAAIV,SAAS,CAACZ,CAAC,CAACsB,CAAC,CAAC,EAAErB,CAAC,CAACqB,CAAC,CAAC,EAAET,cAAc,CAAC,CAAC;AAChE","ignoreList":[]}
+64
View File
@@ -0,0 +1,64 @@
import type { AllowedComponentProps, Component, ComponentCustomProps, ComponentInjectOptions, ComponentObjectPropsOptions, ComponentOptionsMixin, ComponentOptionsWithObjectProps, ComponentOptionsWithoutProps, ComponentPropsOptions, ComponentPublicInstance, ComputedOptions, DefineComponent, EmitsOptions, ExtractDefaultPropTypes, ExtractPropTypes, FunctionalComponent, MethodOptions, ObjectEmitsOptions, SlotsType, VNode, VNodeChild, VNodeProps } from 'vue';
export declare function defineComponent<Props = {}, RawBindings = {}, D = {}, C extends ComputedOptions = {}, M extends MethodOptions = {}, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = ComponentOptionsMixin, E extends EmitsOptions = {}, EE extends string = string, I extends {} = {}, II extends string = string, S extends SlotsType = {}>(options: ComponentOptionsWithoutProps<Props, RawBindings, D, C, M, Mixin, Extends, E, EE, I, II, S>): DefineComponent<Props, RawBindings, D, C, M, Mixin, Extends, E, EE>;
export declare function defineComponent<PropsOptions extends Readonly<ComponentPropsOptions>, RawBindings, D, C extends ComputedOptions = {}, M extends MethodOptions = {}, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = ComponentOptionsMixin, E extends EmitsOptions = {}, EE extends string = string, I extends {} = {}, II extends string = string, S extends SlotsType = {}>(options: ComponentOptionsWithObjectProps<PropsOptions, RawBindings, D, C, M, Mixin, Extends, E, EE, I, II, S>): DefineComponent<PropsOptions, RawBindings, D, C, M, Mixin, Extends, E, EE> & FilterPropsOptions<PropsOptions>;
type ToListeners<T extends string | number | symbol> = {
[K in T]: K extends `on${infer U}` ? Uncapitalize<U> : K;
}[T];
export type SlotsToProps<U extends RawSlots, T = MakeInternalSlots<U>> = {
$children?: (VNodeChild | (T extends {
default: infer V;
} ? V : {}) | {
[K in keyof T]?: T[K];
} | {
$stable?: boolean;
});
'v-slots'?: {
[K in keyof T]?: T[K] | false;
};
} & {
[K in keyof T as `v-slot:${K & string}`]?: T[K] | false;
};
type RawSlots = Record<string, unknown>;
type Slot<T> = [T] extends [never] ? () => VNodeChild : (arg: T) => VNodeChild;
type VueSlot<T> = [T] extends [never] ? () => VNode[] : (arg: T) => VNode[];
type MakeInternalSlots<T extends RawSlots> = {
[K in keyof T]: Slot<T[K]>;
};
type MakeSlots<T extends RawSlots> = {
[K in keyof T]: VueSlot<T[K]>;
};
export type GenericProps<Props, Slots extends Record<string, unknown>> = {
$props: Props & SlotsToProps<Slots>;
$slots: MakeSlots<Slots>;
};
type DefineComponentWithGenericProps<T extends (new (props: Record<string, any>, slots: RawSlots) => {
$props?: Record<string, any>;
})> = <PropsOptions extends Readonly<ComponentObjectPropsOptions>, RawBindings, D, C extends ComputedOptions = {}, M extends MethodOptions = {}, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = ComponentOptionsMixin, E extends EmitsOptions = Record<string, any>, EE extends string = string, I extends ComponentInjectOptions = {}, II extends string = string, Slots extends RawSlots = ConstructorParameters<T>[1], S extends SlotsType = SlotsType<Partial<MakeSlots<Slots>>>, III = InstanceType<T>, P = III extends Record<'$props', any> ? Omit<PropsOptions, keyof III['$props']> : PropsOptions, EEE extends EmitsOptions = E extends any[] ? E : III extends Record<'$props', any> ? Omit<E, ToListeners<keyof III['$props']>> : E, Base = DefineComponent<P, RawBindings, D, C, M, Mixin, Extends, EEE, EE, PublicProps, ExtractPropTypes<P> & ({} extends E ? {} : EmitsToProps<EEE>), ExtractDefaultPropTypes<P>, S>>(options: ComponentOptionsWithObjectProps<PropsOptions, RawBindings, D, C, M, Mixin, Extends, E, EE, I, II, S>) => Base & T & FilterPropsOptions<PropsOptions>;
type DefineComponentWithSlots<Slots extends RawSlots> = <PropsOptions extends Readonly<ComponentPropsOptions>, RawBindings, D, C extends ComputedOptions = {}, M extends MethodOptions = {}, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = ComponentOptionsMixin, E extends EmitsOptions = Record<string, any>, EE extends string = string, I extends ComponentInjectOptions = {}, II extends string = string, S extends SlotsType = SlotsType<Partial<MakeSlots<Slots>>>>(options: ComponentOptionsWithObjectProps<PropsOptions, RawBindings, D, C, M, Mixin, Extends, E, EE, I, II, S>) => DefineComponent<ExtractPropTypes<PropsOptions> & SlotsToProps<Slots>, RawBindings, D, C, M, Mixin, Extends, E, EE, PublicProps, ExtractPropTypes<PropsOptions> & SlotsToProps<Slots> & ({} extends E ? {} : EmitsToProps<E>), ExtractDefaultPropTypes<PropsOptions>, S> & FilterPropsOptions<PropsOptions>;
export declare function genericComponent(exposeDefaults?: boolean): DefineComponentWithSlots<{
default: never;
}>;
export declare function genericComponent<T extends (new (props: Record<string, any>, slots: any) => {
$props?: Record<string, any>;
})>(exposeDefaults?: boolean): DefineComponentWithGenericProps<T>;
export declare function genericComponent<Slots extends RawSlots>(exposeDefaults?: boolean): DefineComponentWithSlots<Slots>;
export declare function defineFunctionalComponent<T extends FunctionalComponent<Props>, PropsOptions = ComponentObjectPropsOptions, Defaults = ExtractDefaultPropTypes<PropsOptions>, Props = Readonly<ExtractPropTypes<PropsOptions>>>(props: PropsOptions, render: T): FunctionalComponent<Partial<Defaults> & Omit<Props, keyof Defaults>>;
type EmitsToProps<T extends EmitsOptions> = T extends string[] ? {
[K in string & `on${Capitalize<T[number]>}`]?: (...args: any[]) => any;
} : T extends ObjectEmitsOptions ? {
[K in string & `on${Capitalize<string & keyof T>}`]?: K extends `on${infer C}` ? T[Uncapitalize<C>] extends null ? (...args: any[]) => any : (...args: T[Uncapitalize<C>] extends (...args: infer P) => any ? P : never) => any : never;
} : {};
type PublicProps = VNodeProps & AllowedComponentProps & ComponentCustomProps;
export interface FilterPropsOptions<PropsOptions extends Readonly<ComponentPropsOptions>, Props = ExtractPropTypes<PropsOptions>> {
filterProps<T extends Partial<Props>, U extends Exclude<keyof Props, Exclude<keyof Props, keyof T>>>(props: T): Partial<Pick<T, U>>;
}
export type ComponentInstance<T> = T extends {
new (): ComponentPublicInstance<any, any, any>;
} ? InstanceType<T> : T extends FunctionalComponent<infer Props, infer Emits> ? ComponentPublicInstance<Props, {}, {}, {}, {}, ShortEmitsToObject<Emits>> : T extends Component<infer Props, infer RawBindings, infer D, infer C, infer M> ? ComponentPublicInstance<unknown extends Props ? {} : Props, unknown extends RawBindings ? {} : RawBindings, unknown extends D ? {} : D, C, M> : never;
type ShortEmitsToObject<E> = E extends Record<string, any[]> ? {
[K in keyof E]: (...args: E[K]) => any;
} : E;
export type JSXComponent<Props = any> = {
new (): ComponentPublicInstance<Props>;
} | FunctionalComponent<Props>;
+61
View File
@@ -0,0 +1,61 @@
// Composables
import { injectDefaults, internalUseDefaults } from "../composables/defaults.js"; // Utilities
import { defineComponent as _defineComponent // eslint-disable-line no-restricted-imports
} from 'vue';
import { consoleWarn } from "./console.js";
import { pick } from "./helpers.js";
import { propsFactory } from "./propsFactory.js"; // Types
// No props
// Object Props
// Implementation
export function defineComponent(options) {
options._setup = options._setup ?? options.setup;
if (!options.name) {
consoleWarn('The component is missing an explicit name, unable to generate default prop value');
return options;
}
if (options._setup) {
options.props = propsFactory(options.props ?? {}, options.name)();
const propKeys = Object.keys(options.props).filter(key => key !== 'class' && key !== 'style');
options.filterProps = function filterProps(props) {
return pick(props, propKeys);
};
options.props._as = String;
options.setup = function setup(props, ctx) {
const defaults = injectDefaults();
// Skip props proxy if defaults are not provided
if (!defaults.value) return options._setup(props, ctx);
const {
props: _props,
provideSubDefaults
} = internalUseDefaults(props, props._as ?? options.name, defaults);
const setupBindings = options._setup(_props, ctx);
provideSubDefaults();
return setupBindings;
};
}
return options;
}
// No argument - simple default slot
// Generic constructor argument - generic props and slots
// Slots argument - simple slots
// Implementation
export function genericComponent(exposeDefaults = true) {
return options => (exposeDefaults ? defineComponent : _defineComponent)(options);
}
export function defineFunctionalComponent(props, render) {
render.props = props;
return render;
}
// Adds a filterProps method to the component options
// https://github.com/vuejs/core/pull/10557
// not a vue Component
//# sourceMappingURL=defineComponent.js.map
File diff suppressed because one or more lines are too long
+6
View File
@@ -0,0 +1,6 @@
/**
* Returns:
* - 'null' if the node is not attached to the DOM
* - the root node (HTMLDocument | ShadowRoot) otherwise
*/
export declare function attachedRoot(node: Node): null | HTMLDocument | ShadowRoot;
+24
View File
@@ -0,0 +1,24 @@
/**
* Returns:
* - 'null' if the node is not attached to the DOM
* - the root node (HTMLDocument | ShadowRoot) otherwise
*/
export function attachedRoot(node) {
/* istanbul ignore next */
if (typeof node.getRootNode !== 'function') {
// Shadow DOM not supported (IE11), lets find the root of this node
while (node.parentNode) node = node.parentNode;
// The root parent is the document if the node is attached to the DOM
if (node !== document) return null;
return document;
}
const root = node.getRootNode();
// The composed root node is the document if the node is attached to the DOM
if (root !== document && root.getRootNode({
composed: true
}) !== document) return null;
return root;
}
//# sourceMappingURL=dom.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"dom.js","names":["attachedRoot","node","getRootNode","parentNode","document","root","composed"],"sources":["../../src/util/dom.ts"],"sourcesContent":["/**\n * Returns:\n * - 'null' if the node is not attached to the DOM\n * - the root node (HTMLDocument | ShadowRoot) otherwise\n */\nexport function attachedRoot (node: Node): null | HTMLDocument | ShadowRoot {\n /* istanbul ignore next */\n if (typeof node.getRootNode !== 'function') {\n // Shadow DOM not supported (IE11), lets find the root of this node\n while (node.parentNode) node = node.parentNode\n\n // The root parent is the document if the node is attached to the DOM\n if (node !== document) return null\n\n return document\n }\n\n const root = node.getRootNode()\n\n // The composed root node is the document if the node is attached to the DOM\n if (root !== document && root.getRootNode({ composed: true }) !== document) return null\n\n return root as HTMLDocument | ShadowRoot\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,YAAYA,CAAEC,IAAU,EAAoC;EAC1E;EACA,IAAI,OAAOA,IAAI,CAACC,WAAW,KAAK,UAAU,EAAE;IAC1C;IACA,OAAOD,IAAI,CAACE,UAAU,EAAEF,IAAI,GAAGA,IAAI,CAACE,UAAU;;IAE9C;IACA,IAAIF,IAAI,KAAKG,QAAQ,EAAE,OAAO,IAAI;IAElC,OAAOA,QAAQ;EACjB;EAEA,MAAMC,IAAI,GAAGJ,IAAI,CAACC,WAAW,CAAC,CAAC;;EAE/B;EACA,IAAIG,IAAI,KAAKD,QAAQ,IAAIC,IAAI,CAACH,WAAW,CAAC;IAAEI,QAAQ,EAAE;EAAK,CAAC,CAAC,KAAKF,QAAQ,EAAE,OAAO,IAAI;EAEvF,OAAOC,IAAI;AACb","ignoreList":[]}
+26
View File
@@ -0,0 +1,26 @@
import type { MaybeRefOrGetter } from 'vue';
export declare const standardEasing = "cubic-bezier(0.4, 0, 0.2, 1)";
export declare const deceleratedEasing = "cubic-bezier(0.0, 0, 0.2, 1)";
export declare const acceleratedEasing = "cubic-bezier(0.4, 0, 1, 1)";
export type EasingFunction = (n: number) => number;
export declare const easingPatterns: {
readonly linear: (t: number) => number;
readonly easeInQuad: (t: number) => number;
readonly easeOutQuad: (t: number) => number;
readonly easeInOutQuad: (t: number) => number;
readonly easeInCubic: (t: number) => number;
readonly easeOutCubic: (t: number) => number;
readonly easeInOutCubic: (t: number) => number;
readonly easeInQuart: (t: number) => number;
readonly easeOutQuart: (t: number) => number;
readonly easeInOutQuart: (t: number) => number;
readonly easeInQuint: (t: number) => number;
readonly easeOutQuint: (t: number) => number;
readonly easeInOutQuint: (t: number) => number;
readonly instant: (t: number) => number;
};
export type EasingOptions = {
duration?: number;
transition?: EasingFunction;
};
export declare function useTransition(source: MaybeRefOrGetter<number>, options: MaybeRefOrGetter<EasingOptions>): import("vue").ComputedRef<number>;
+59
View File
@@ -0,0 +1,59 @@
// Utilities
import { computed, shallowRef, toValue, watch } from 'vue';
import { clamp } from "./helpers.js";
import { PREFERS_REDUCED_MOTION } from "./globals.js"; // Types
export const standardEasing = 'cubic-bezier(0.4, 0, 0.2, 1)';
export const deceleratedEasing = 'cubic-bezier(0.0, 0, 0.2, 1)'; // Entering
export const acceleratedEasing = 'cubic-bezier(0.4, 0, 1, 1)'; // Leaving
export const easingPatterns = {
linear: t => t,
easeInQuad: t => t ** 2,
easeOutQuad: t => t * (2 - t),
easeInOutQuad: t => t < 0.5 ? 2 * t ** 2 : -1 + (4 - 2 * t) * t,
easeInCubic: t => t ** 3,
easeOutCubic: t => --t ** 3 + 1,
easeInOutCubic: t => t < 0.5 ? 4 * t ** 3 : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1,
easeInQuart: t => t ** 4,
easeOutQuart: t => 1 - --t ** 4,
easeInOutQuart: t => t < 0.5 ? 8 * t ** 4 : 1 - 8 * --t ** 4,
easeInQuint: t => t ** 5,
easeOutQuint: t => 1 + --t ** 5,
easeInOutQuint: t => t < 0.5 ? 16 * t ** 5 : 1 + 16 * --t ** 5,
instant: t => 1
};
export function useTransition(source, options) {
const defaultTransition = {
duration: 300,
transition: easingPatterns.easeInOutCubic
};
let raf = -1;
const outputRef = shallowRef(toValue(source));
watch(() => toValue(source), async to => {
cancelAnimationFrame(raf);
const easing = {
...defaultTransition,
...toValue(options)
};
await executeTransition(outputRef, outputRef.value, to, easing);
});
function executeTransition(out, from, to, options) {
const startTime = performance.now();
const ease = PREFERS_REDUCED_MOTION() ? easingPatterns.instant : options.transition ?? easingPatterns.easeInOutCubic;
return new Promise(resolve => {
raf = requestAnimationFrame(function step(currentTime) {
const timeElapsed = currentTime - startTime;
const progress = timeElapsed / options.duration;
out.value = from + (to - from) * ease(clamp(progress, 0, 1));
if (progress < 1) {
raf = requestAnimationFrame(step);
} else {
out.value = to;
resolve();
}
});
});
}
return computed(() => outputRef.value);
}
//# sourceMappingURL=easing.js.map
File diff suppressed because one or more lines are too long
+3
View File
@@ -0,0 +1,3 @@
type EventHandler = (event: Event) => any;
export declare function getPrefixedEventHandlers<T extends `:${string}`>(attrs: Record<string, any>, suffix: T, getData: EventHandler): Record<`${string}${T}`, EventHandler>;
+9
View File
@@ -0,0 +1,9 @@
// Utilities
import { callEvent, isOn } from "./helpers.js";
export function getPrefixedEventHandlers(attrs, suffix, getData) {
return Object.keys(attrs).filter(key => isOn(key) && key.endsWith(suffix)).reduce((acc, key) => {
acc[key.slice(0, -suffix.length)] = event => callEvent(attrs[key], event, getData(event));
return acc;
}, {});
}
//# sourceMappingURL=events.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"events.js","names":["callEvent","isOn","getPrefixedEventHandlers","attrs","suffix","getData","Object","keys","filter","key","endsWith","reduce","acc","slice","length","event"],"sources":["../../src/util/events.ts"],"sourcesContent":["// Utilities\nimport { callEvent, isOn } from '@/util/helpers'\n\ntype EventHandler = (event: Event) => any\n\nexport function getPrefixedEventHandlers<T extends `:${string}`> (\n attrs: Record<string, any>,\n suffix: T,\n getData: EventHandler\n): Record<`${string}${T}`, EventHandler> {\n return Object.keys(attrs)\n .filter(key => isOn(key) && key.endsWith(suffix))\n .reduce((acc: any, key) => {\n acc[key.slice(0, -suffix.length)] = (event: Event) => callEvent(attrs[key], event, getData(event))\n return acc\n }, {} as Record<`${string}${T}`, EventHandler>)\n}\n"],"mappings":"AAAA;AAAA,SACSA,SAAS,EAAEC,IAAI;AAIxB,OAAO,SAASC,wBAAwBA,CACtCC,KAA0B,EAC1BC,MAAS,EACTC,OAAqB,EACkB;EACvC,OAAOC,MAAM,CAACC,IAAI,CAACJ,KAAK,CAAC,CACtBK,MAAM,CAACC,GAAG,IAAIR,IAAI,CAACQ,GAAG,CAAC,IAAIA,GAAG,CAACC,QAAQ,CAACN,MAAM,CAAC,CAAC,CAChDO,MAAM,CAAC,CAACC,GAAQ,EAAEH,GAAG,KAAK;IACzBG,GAAG,CAACH,GAAG,CAACI,KAAK,CAAC,CAAC,EAAE,CAACT,MAAM,CAACU,MAAM,CAAC,CAAC,GAAIC,KAAY,IAAKf,SAAS,CAACG,KAAK,CAACM,GAAG,CAAC,EAAEM,KAAK,EAAEV,OAAO,CAACU,KAAK,CAAC,CAAC;IAClG,OAAOH,GAAG;EACZ,CAAC,EAAE,CAAC,CAA0C,CAAC;AACnD","ignoreList":[]}
+2
View File
@@ -0,0 +1,2 @@
export declare function getCurrentInstance(name: string, message?: string): import("vue").ComponentInternalInstance;
export declare function getCurrentInstanceName(name?: string): string;
+15
View File
@@ -0,0 +1,15 @@
// Utilities
import { getCurrentInstance as _getCurrentInstance } from 'vue';
import { toKebabCase } from "./helpers.js";
export function getCurrentInstance(name, message) {
const vm = _getCurrentInstance();
if (!vm) {
throw new Error(`[Vuetify] ${name} ${message || 'must be called from inside a setup function'}`);
}
return vm;
}
export function getCurrentInstanceName(name = 'composables') {
const vm = getCurrentInstance(name).type;
return toKebabCase(vm?.aliasName || vm?.name);
}
//# sourceMappingURL=getCurrentInstance.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"getCurrentInstance.js","names":["getCurrentInstance","_getCurrentInstance","toKebabCase","name","message","vm","Error","getCurrentInstanceName","type","aliasName"],"sources":["../../src/util/getCurrentInstance.ts"],"sourcesContent":["// Utilities\nimport { getCurrentInstance as _getCurrentInstance } from 'vue'\nimport { toKebabCase } from '@/util/helpers'\n\nexport function getCurrentInstance (name: string, message?: string) {\n const vm = _getCurrentInstance()\n\n if (!vm) {\n throw new Error(`[Vuetify] ${name} ${message || 'must be called from inside a setup function'}`)\n }\n\n return vm\n}\n\nexport function getCurrentInstanceName (name = 'composables') {\n const vm = getCurrentInstance(name).type\n\n return toKebabCase(vm?.aliasName || vm?.name)\n}\n"],"mappings":"AAAA;AACA,SAASA,kBAAkB,IAAIC,mBAAmB,QAAQ,KAAK;AAAA,SACtDC,WAAW;AAEpB,OAAO,SAASF,kBAAkBA,CAAEG,IAAY,EAAEC,OAAgB,EAAE;EAClE,MAAMC,EAAE,GAAGJ,mBAAmB,CAAC,CAAC;EAEhC,IAAI,CAACI,EAAE,EAAE;IACP,MAAM,IAAIC,KAAK,CAAC,aAAaH,IAAI,IAAIC,OAAO,IAAI,6CAA6C,EAAE,CAAC;EAClG;EAEA,OAAOC,EAAE;AACX;AAEA,OAAO,SAASE,sBAAsBA,CAAEJ,IAAI,GAAG,aAAa,EAAE;EAC5D,MAAME,EAAE,GAAGL,kBAAkB,CAACG,IAAI,CAAC,CAACK,IAAI;EAExC,OAAON,WAAW,CAACG,EAAE,EAAEI,SAAS,IAAIJ,EAAE,EAAEF,IAAI,CAAC;AAC/C","ignoreList":[]}
+3
View File
@@ -0,0 +1,3 @@
export declare function getScrollParent(el?: HTMLElement, includeHidden?: boolean): HTMLElement;
export declare function getScrollParents(el?: Element | null, stopAt?: Element | null): HTMLElement[];
export declare function hasScrollbar(el?: Element | null): boolean;
+30
View File
@@ -0,0 +1,30 @@
export function getScrollParent(el, includeHidden = false) {
while (el) {
if (includeHidden ? isPotentiallyScrollable(el) : hasScrollbar(el)) return el;
el = el.parentElement;
}
return document.scrollingElement;
}
export function getScrollParents(el, stopAt) {
const elements = [];
if (stopAt && el && !stopAt.contains(el)) return elements;
while (el) {
if (hasScrollbar(el)) elements.push(el);
if (el === stopAt) break;
el = el.parentElement;
}
return elements;
}
export function hasScrollbar(el) {
if (!el || el.nodeType !== Node.ELEMENT_NODE) return false;
const style = window.getComputedStyle(el);
const hasVerticalScrollbar = style.overflowY === 'scroll' || style.overflowY === 'auto' && el.scrollHeight > el.clientHeight;
const hasHorizontalScrollbar = style.overflowX === 'scroll' || style.overflowX === 'auto' && el.scrollWidth > el.clientWidth;
return hasVerticalScrollbar || hasHorizontalScrollbar;
}
function isPotentiallyScrollable(el) {
if (!el || el.nodeType !== Node.ELEMENT_NODE) return false;
const style = window.getComputedStyle(el);
return ['scroll', 'auto'].includes(style.overflowY);
}
//# sourceMappingURL=getScrollParent.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"getScrollParent.js","names":["getScrollParent","el","includeHidden","isPotentiallyScrollable","hasScrollbar","parentElement","document","scrollingElement","getScrollParents","stopAt","elements","contains","push","nodeType","Node","ELEMENT_NODE","style","window","getComputedStyle","hasVerticalScrollbar","overflowY","scrollHeight","clientHeight","hasHorizontalScrollbar","overflowX","scrollWidth","clientWidth","includes"],"sources":["../../src/util/getScrollParent.ts"],"sourcesContent":["export function getScrollParent (el?: HTMLElement, includeHidden = false) {\n while (el) {\n if (includeHidden ? isPotentiallyScrollable(el) : hasScrollbar(el)) return el\n el = el.parentElement!\n }\n\n return document.scrollingElement as HTMLElement\n}\n\nexport function getScrollParents (el?: Element | null, stopAt?: Element | null) {\n const elements: HTMLElement[] = []\n\n if (stopAt && el && !stopAt.contains(el)) return elements\n\n while (el) {\n if (hasScrollbar(el)) elements.push(el as HTMLElement)\n if (el === stopAt) break\n el = el.parentElement!\n }\n\n return elements\n}\n\nexport function hasScrollbar (el?: Element | null) {\n if (!el || el.nodeType !== Node.ELEMENT_NODE) return false\n\n const style = window.getComputedStyle(el)\n const hasVerticalScrollbar = style.overflowY === 'scroll' || (style.overflowY === 'auto' && el.scrollHeight > el.clientHeight)\n const hasHorizontalScrollbar = style.overflowX === 'scroll' || (style.overflowX === 'auto' && el.scrollWidth > el.clientWidth)\n return hasVerticalScrollbar || hasHorizontalScrollbar\n}\n\nfunction isPotentiallyScrollable (el?: Element | null) {\n if (!el || el.nodeType !== Node.ELEMENT_NODE) return false\n\n const style = window.getComputedStyle(el)\n return ['scroll', 'auto'].includes(style.overflowY)\n}\n"],"mappings":"AAAA,OAAO,SAASA,eAAeA,CAAEC,EAAgB,EAAEC,aAAa,GAAG,KAAK,EAAE;EACxE,OAAOD,EAAE,EAAE;IACT,IAAIC,aAAa,GAAGC,uBAAuB,CAACF,EAAE,CAAC,GAAGG,YAAY,CAACH,EAAE,CAAC,EAAE,OAAOA,EAAE;IAC7EA,EAAE,GAAGA,EAAE,CAACI,aAAc;EACxB;EAEA,OAAOC,QAAQ,CAACC,gBAAgB;AAClC;AAEA,OAAO,SAASC,gBAAgBA,CAAEP,EAAmB,EAAEQ,MAAuB,EAAE;EAC9E,MAAMC,QAAuB,GAAG,EAAE;EAElC,IAAID,MAAM,IAAIR,EAAE,IAAI,CAACQ,MAAM,CAACE,QAAQ,CAACV,EAAE,CAAC,EAAE,OAAOS,QAAQ;EAEzD,OAAOT,EAAE,EAAE;IACT,IAAIG,YAAY,CAACH,EAAE,CAAC,EAAES,QAAQ,CAACE,IAAI,CAACX,EAAiB,CAAC;IACtD,IAAIA,EAAE,KAAKQ,MAAM,EAAE;IACnBR,EAAE,GAAGA,EAAE,CAACI,aAAc;EACxB;EAEA,OAAOK,QAAQ;AACjB;AAEA,OAAO,SAASN,YAAYA,CAAEH,EAAmB,EAAE;EACjD,IAAI,CAACA,EAAE,IAAIA,EAAE,CAACY,QAAQ,KAAKC,IAAI,CAACC,YAAY,EAAE,OAAO,KAAK;EAE1D,MAAMC,KAAK,GAAGC,MAAM,CAACC,gBAAgB,CAACjB,EAAE,CAAC;EACzC,MAAMkB,oBAAoB,GAAGH,KAAK,CAACI,SAAS,KAAK,QAAQ,IAAKJ,KAAK,CAACI,SAAS,KAAK,MAAM,IAAInB,EAAE,CAACoB,YAAY,GAAGpB,EAAE,CAACqB,YAAa;EAC9H,MAAMC,sBAAsB,GAAGP,KAAK,CAACQ,SAAS,KAAK,QAAQ,IAAKR,KAAK,CAACQ,SAAS,KAAK,MAAM,IAAIvB,EAAE,CAACwB,WAAW,GAAGxB,EAAE,CAACyB,WAAY;EAC9H,OAAOP,oBAAoB,IAAII,sBAAsB;AACvD;AAEA,SAASpB,uBAAuBA,CAAEF,EAAmB,EAAE;EACrD,IAAI,CAACA,EAAE,IAAIA,EAAE,CAACY,QAAQ,KAAKC,IAAI,CAACC,YAAY,EAAE,OAAO,KAAK;EAE1D,MAAMC,KAAK,GAAGC,MAAM,CAACC,gBAAgB,CAACjB,EAAE,CAAC;EACzC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC0B,QAAQ,CAACX,KAAK,CAACI,SAAS,CAAC;AACrD","ignoreList":[]}
+6
View File
@@ -0,0 +1,6 @@
export declare const IN_BROWSER: boolean;
export declare const SUPPORTS_INTERSECTION: boolean;
export declare const SUPPORTS_TOUCH: boolean;
export declare const SUPPORTS_EYE_DROPPER: boolean;
export declare const SUPPORTS_MATCH_MEDIA: boolean;
export declare const PREFERS_REDUCED_MOTION: () => boolean;
+7
View File
@@ -0,0 +1,7 @@
export const IN_BROWSER = typeof window !== 'undefined';
export const SUPPORTS_INTERSECTION = IN_BROWSER && 'IntersectionObserver' in window;
export const SUPPORTS_TOUCH = IN_BROWSER && ('ontouchstart' in window || window.navigator.maxTouchPoints > 0);
export const SUPPORTS_EYE_DROPPER = IN_BROWSER && 'EyeDropper' in window;
export const SUPPORTS_MATCH_MEDIA = IN_BROWSER && 'matchMedia' in window && typeof window.matchMedia === 'function';
export const PREFERS_REDUCED_MOTION = () => SUPPORTS_MATCH_MEDIA && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
//# sourceMappingURL=globals.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"globals.js","names":["IN_BROWSER","window","SUPPORTS_INTERSECTION","SUPPORTS_TOUCH","navigator","maxTouchPoints","SUPPORTS_EYE_DROPPER","SUPPORTS_MATCH_MEDIA","matchMedia","PREFERS_REDUCED_MOTION","matches"],"sources":["../../src/util/globals.ts"],"sourcesContent":["export const IN_BROWSER = typeof window !== 'undefined'\nexport const SUPPORTS_INTERSECTION = IN_BROWSER && 'IntersectionObserver' in window\nexport const SUPPORTS_TOUCH = IN_BROWSER && ('ontouchstart' in window || window.navigator.maxTouchPoints > 0)\nexport const SUPPORTS_EYE_DROPPER = IN_BROWSER && 'EyeDropper' in window\nexport const SUPPORTS_MATCH_MEDIA = IN_BROWSER && 'matchMedia' in window && typeof window.matchMedia === 'function'\nexport const PREFERS_REDUCED_MOTION = () => (\n SUPPORTS_MATCH_MEDIA && window.matchMedia('(prefers-reduced-motion: reduce)').matches\n)\n"],"mappings":"AAAA,OAAO,MAAMA,UAAU,GAAG,OAAOC,MAAM,KAAK,WAAW;AACvD,OAAO,MAAMC,qBAAqB,GAAGF,UAAU,IAAI,sBAAsB,IAAIC,MAAM;AACnF,OAAO,MAAME,cAAc,GAAGH,UAAU,KAAK,cAAc,IAAIC,MAAM,IAAIA,MAAM,CAACG,SAAS,CAACC,cAAc,GAAG,CAAC,CAAC;AAC7G,OAAO,MAAMC,oBAAoB,GAAGN,UAAU,IAAI,YAAY,IAAIC,MAAM;AACxE,OAAO,MAAMM,oBAAoB,GAAGP,UAAU,IAAI,YAAY,IAAIC,MAAM,IAAI,OAAOA,MAAM,CAACO,UAAU,KAAK,UAAU;AACnH,OAAO,MAAMC,sBAAsB,GAAGA,CAAA,KACpCF,oBAAoB,IAAIN,MAAM,CAACO,UAAU,CAAC,kCAAkC,CAAC,CAACE,OAC/E","ignoreList":[]}
+135
View File
@@ -0,0 +1,135 @@
import type { ComponentInternalInstance, ComponentPublicInstance, ComputedGetter, InjectionKey, PropType, Ref, ToRef, VNode, VNodeArrayChildren, VNodeChild } from 'vue';
export declare function getNestedValue(obj: any, path: (string | number)[], fallback?: any): any;
export declare function getObjectValueByPath(obj: any, path?: string | null, fallback?: any): any;
export type SelectItemKey<T = Record<string, any>> = boolean | null | undefined | string | readonly (string | number)[] | ((item: T, fallback?: any) => any);
export declare function getPropertyFromItem(item: any, property: SelectItemKey, fallback?: any): any;
export declare function createRange(length: number, start?: number): number[];
export declare function getZIndex(el?: Element | null): number;
export declare function convertToUnit(str: number, unit?: string): string;
export declare function convertToUnit(str: string | number | null | undefined, unit?: string): string | undefined;
export declare function isObject(obj: any): obj is Record<string, any>;
export declare function isPlainObject(obj: any): obj is Record<string, any>;
export declare function refElement(obj?: ComponentPublicInstance<any> | HTMLElement): HTMLElement | undefined;
export declare const keyCodes: Readonly<{
enter: 13;
tab: 9;
delete: 46;
esc: 27;
space: 32;
up: 38;
down: 40;
left: 37;
right: 39;
end: 35;
home: 36;
del: 46;
backspace: 8;
insert: 45;
pageup: 33;
pagedown: 34;
shift: 16;
}>;
export declare const keyValues: Record<string, string>;
export declare function keys<O extends {}>(o: O): (keyof O)[];
export declare function has<T extends string>(obj: object, key: T[]): obj is Record<T, unknown>;
type MaybePick<T extends object, U extends Extract<keyof T, string>> = Record<string, unknown> extends T ? Partial<Pick<T, U>> : Pick<T, U>;
export declare function pick<T extends object, U extends Extract<keyof T, string>>(obj: T, paths: readonly U[]): MaybePick<T, U>;
export declare function pickWithRest<T extends object, U extends Extract<keyof T, string>, E extends Extract<keyof T, string>>(obj: T, paths: U[], exclude?: E[]): [yes: MaybePick<T, Exclude<U, E>>, no: Omit<T, Exclude<U, E>>];
export declare function pickWithRest<T extends object, U extends Extract<keyof T, string>, E extends Extract<keyof T, string>>(obj: T, paths: (U | RegExp)[], exclude?: E[]): [yes: Partial<T>, no: Partial<T>];
export declare function omit<T extends object, U extends Extract<keyof T, string>>(obj: T, exclude: U[]): Omit<T, U>;
export declare const isOn: (key: string) => boolean;
export declare function isComposingIgnoreKey(e: KeyboardEvent): boolean;
/**
* Filter attributes that should be applied to
* the root element of an input component. Remaining
* attributes should be passed to the <input> element inside.
*/
export declare function filterInputAttrs(attrs: Record<string, unknown>): Partial<Partial<Record<string, unknown>>>[];
/**
* Returns the set difference of B and A, i.e. the set of elements in B but not in A
*/
export declare function arrayDiff(a: any[], b: any[]): any[];
type IfAny<T, Y, N> = 0 extends (1 & T) ? Y : N;
export declare function wrapInArray<T>(v: T | null | undefined): T extends readonly any[] ? IfAny<T, T[], T> : NonNullable<T>[];
export declare function defaultFilter(value: any, search: string | null, item: any): boolean;
export declare function debounce(fn: Function, delay: MaybeRef<number>): {
(...args: any[]): void;
clear: () => void;
immediate: Function;
};
export declare function clamp(value: number, min?: number, max?: number): number;
export declare function getDecimals(value: number): number;
export declare function padEnd(str: string, length: number, char?: string): string;
export declare function padStart(str: string, length: number, char?: string): string;
export declare function chunk(str: string, size?: number): string[];
export declare function chunkArray(array: any[], size?: number): any[][];
export declare function humanReadableFileSize(bytes: number, base?: 1000 | 1024): string;
export declare function mergeDeep(source?: Record<string, any>, target?: Record<string, any>, arrayFn?: (a: unknown[], b: unknown[]) => unknown[], targetCondition?: (k: string, v: unknown) => boolean): Record<string, any>;
export declare function flattenFragments(nodes: VNode[]): VNode[];
export declare function toKebabCase(str?: string): string;
export declare namespace toKebabCase {
var cache: Map<string, string>;
}
export type MaybeRef<T> = T | Ref<T>;
export declare function findChildrenWithProvide(key: InjectionKey<any> | symbol, vnode?: VNodeChild): ComponentInternalInstance[];
export declare class CircularBuffer<T = never> {
#private;
readonly size: number;
constructor(size: number);
get isFull(): boolean;
push(val: T): void;
values(): T[];
clear(): void;
}
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
export declare function getEventCoordinates(e: MouseEvent | TouchEvent): {
clientX: number;
clientY: number;
};
type NotAUnion<T> = [T] extends [infer U] ? _NotAUnion<U, U> : never;
type _NotAUnion<T, U> = U extends any ? [T] extends [U] ? unknown : never : never;
type ToReadonlyRefs<T> = {
[K in keyof T]: Readonly<ToRef<T[K]>>;
};
/**
* Convert a computed ref to a record of refs.
* The getter function must always return an object with the same keys.
*/
export declare function destructComputed<T extends object>(getter: ComputedGetter<T & NotAUnion<T>>): ToReadonlyRefs<T>;
/** Array.includes but value can be any type */
export declare function includes(arr: readonly any[], val: any): boolean;
export declare function eventName(propName: string): string;
export type EventProp<T extends any[] = any[], F = (...args: T) => void> = F;
export declare const EventProp: <T extends any[] = any[]>() => PropType<EventProp<T>>;
export declare function hasEvent(props: Record<string, any>, name: string): boolean;
export declare function callEvent<T extends any[]>(handler: EventProp<T> | EventProp<T>[] | undefined, ...args: T): void;
export declare function focusableChildren(el: Element, filterByTabIndex?: boolean): HTMLElement[];
export declare function getNextElement(elements: HTMLElement[], location?: 'next' | 'prev', condition?: (el: HTMLElement) => boolean): HTMLElement;
export declare function focusChild(el: Element, location?: 'next' | 'prev' | 'first' | 'last' | number): void;
export declare function isEmpty(val: any): boolean;
export declare function noop(): void;
/** Returns null if the selector is not supported or we can't check */
export declare function matchesSelector(el: Element | undefined, selector: string): boolean | null;
export declare function ensureValidVNode(vnodes: VNodeArrayChildren): VNodeArrayChildren | null;
type Slot<T> = [T] extends [never] ? () => VNodeChild : (arg: T) => VNodeChild;
export declare function renderSlot<T>(slot: Slot<never> | undefined, fallback?: Slot<never> | undefined): VNodeChild;
export declare function renderSlot<T>(slot: Slot<T> | undefined, props: T, fallback?: Slot<T> | undefined): VNodeChild;
export declare function defer(timeout: number, cb: () => void): () => void;
export declare function isClickInsideElement(event: MouseEvent, targetDiv: HTMLElement): boolean;
export type TemplateRef = {
(target: Element | ComponentPublicInstance | null): void;
value: HTMLElement | ComponentPublicInstance | null | undefined;
readonly el: HTMLElement | undefined;
};
export declare function templateRef(): TemplateRef;
export declare function checkPrintable(e: KeyboardEvent): boolean;
export type Primitive = string | number | boolean | symbol | bigint;
export declare function isPrimitive(value: unknown): value is Primitive;
export declare function escapeForRegex(sign: string): string;
export declare function extractNumber(text: string, decimalDigitsLimit: number | null, decimalSeparator: string): string;
export declare function camelizeProps<T extends Record<string, unknown>>(props: T | null): T;
export declare function onlyDefinedProps(props: Record<string, any>): {
[k: string]: any;
};
export type NonEmptyArray<T> = [T, ...T[]];
export declare function deepToRaw<T extends {}>(value: T): T;
+548
View File
@@ -0,0 +1,548 @@
// Utilities
import { camelize, capitalize, Comment, Fragment, isProxy, isReactive, isRef, isVNode, reactive, shallowRef, toRaw, toRef, unref, watchEffect } from 'vue';
import { consoleError } from "./console.js";
import { IN_BROWSER } from "./globals.js"; // Types
export function getNestedValue(obj, path, fallback) {
const last = path.length - 1;
if (last < 0) return obj === undefined ? fallback : obj;
for (let i = 0; i < last; i++) {
if (obj == null) {
return fallback;
}
obj = obj[path[i]];
}
if (obj == null) return fallback;
return obj[path[last]] === undefined ? fallback : obj[path[last]];
}
export function getObjectValueByPath(obj, path, fallback) {
// credit: http://stackoverflow.com/questions/6491463/accessing-nested-javascript-objects-with-string-key#comment55278413_6491621
if (obj == null || !path || typeof path !== 'string') return fallback;
if (obj[path] !== undefined) return obj[path];
path = path.replace(/\[(\w+)\]/g, '.$1'); // convert indexes to properties
path = path.replace(/^\./, ''); // strip a leading dot
return getNestedValue(obj, path.split('.'), fallback);
}
export function getPropertyFromItem(item, property, fallback) {
if (property === true) return item === undefined ? fallback : item;
if (property == null || typeof property === 'boolean') return fallback;
if (item !== Object(item)) {
if (typeof property !== 'function') return fallback;
const value = property(item, fallback);
return typeof value === 'undefined' ? fallback : value;
}
if (typeof property === 'string') return getObjectValueByPath(item, property, fallback);
if (Array.isArray(property)) return getNestedValue(item, property, fallback);
if (typeof property !== 'function') return fallback;
const value = property(item, fallback);
return typeof value === 'undefined' ? fallback : value;
}
export function createRange(length, start = 0) {
return Array.from({
length
}, (v, k) => start + k);
}
export function getZIndex(el) {
if (!el || el.nodeType !== Node.ELEMENT_NODE) return 0;
const index = Number(window.getComputedStyle(el).getPropertyValue('z-index'));
if (!index) return getZIndex(el.parentNode);
return index;
}
export function convertToUnit(str, unit = 'px') {
if (str == null || str === '') {
return undefined;
}
const num = Number(str);
if (isNaN(num)) {
return String(str);
} else if (!isFinite(num)) {
return undefined;
} else {
return `${num}${unit}`;
}
}
export function isObject(obj) {
return obj !== null && typeof obj === 'object' && !Array.isArray(obj);
}
export function isPlainObject(obj) {
let proto;
return obj !== null && typeof obj === 'object' && ((proto = Object.getPrototypeOf(obj)) === Object.prototype || proto === null);
}
export function refElement(obj) {
if (obj && '$el' in obj) {
const el = obj.$el;
if (el?.nodeType === Node.TEXT_NODE) {
// Multi-root component, use the first element
return el.nextElementSibling;
}
return el;
}
return obj;
}
// KeyboardEvent.keyCode aliases
export const keyCodes = Object.freeze({
enter: 13,
tab: 9,
delete: 46,
esc: 27,
space: 32,
up: 38,
down: 40,
left: 37,
right: 39,
end: 35,
home: 36,
del: 46,
backspace: 8,
insert: 45,
pageup: 33,
pagedown: 34,
shift: 16
});
export const keyValues = Object.freeze({
enter: 'Enter',
tab: 'Tab',
delete: 'Delete',
esc: 'Escape',
space: 'Space',
up: 'ArrowUp',
down: 'ArrowDown',
left: 'ArrowLeft',
right: 'ArrowRight',
end: 'End',
home: 'Home',
del: 'Delete',
backspace: 'Backspace',
insert: 'Insert',
pageup: 'PageUp',
pagedown: 'PageDown',
shift: 'Shift'
});
export function keys(o) {
return Object.keys(o);
}
export function has(obj, key) {
return key.every(k => obj.hasOwnProperty(k));
}
// Array of keys
export function pick(obj, paths) {
const found = {};
for (const key of paths) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
found[key] = obj[key];
}
}
return found;
}
// Array of keys
// Array of keys or RegExp to test keys against
export function pickWithRest(obj, paths, exclude) {
const found = Object.create(null);
const rest = Object.create(null);
for (const key in obj) {
if (paths.some(path => path instanceof RegExp ? path.test(key) : path === key) && !exclude?.some(path => path === key)) {
found[key] = obj[key];
} else {
rest[key] = obj[key];
}
}
return [found, rest];
}
export function omit(obj, exclude) {
const clone = {
...obj
};
exclude.forEach(prop => delete clone[prop]);
return clone;
}
const onRE = /^on[^a-z]/;
export const isOn = key => onRE.test(key);
const bubblingEvents = ['onAfterscriptexecute', 'onAnimationcancel', 'onAnimationend', 'onAnimationiteration', 'onAnimationstart', 'onAuxclick', 'onBeforeinput', 'onBeforescriptexecute', 'onChange', 'onClick', 'onCompositionend', 'onCompositionstart', 'onCompositionupdate', 'onContextmenu', 'onCopy', 'onCut', 'onDblclick', 'onFocusin', 'onFocusout', 'onFullscreenchange', 'onFullscreenerror', 'onGesturechange', 'onGestureend', 'onGesturestart', 'onGotpointercapture', 'onInput', 'onKeydown', 'onKeypress', 'onKeyup', 'onLostpointercapture', 'onMousedown', 'onMousemove', 'onMouseout', 'onMouseover', 'onMouseup', 'onMousewheel', 'onPaste', 'onPointercancel', 'onPointerdown', 'onPointerenter', 'onPointerleave', 'onPointermove', 'onPointerout', 'onPointerover', 'onPointerup', 'onReset', 'onSelect', 'onSubmit', 'onTouchcancel', 'onTouchend', 'onTouchmove', 'onTouchstart', 'onTransitioncancel', 'onTransitionend', 'onTransitionrun', 'onTransitionstart', 'onWheel'];
const compositionIgnoreKeys = ['ArrowUp', 'ArrowDown', 'ArrowRight', 'ArrowLeft', 'Enter', 'Escape', 'Tab', ' '];
export function isComposingIgnoreKey(e) {
return e.isComposing && compositionIgnoreKeys.includes(e.key);
}
/**
* Filter attributes that should be applied to
* the root element of an input component. Remaining
* attributes should be passed to the <input> element inside.
*/
export function filterInputAttrs(attrs) {
const [events, props] = pickWithRest(attrs, [onRE]);
const inputEvents = omit(events, bubblingEvents);
const [rootAttrs, inputAttrs] = pickWithRest(props, ['class', 'style', 'id', 'inert', /^data-/]);
Object.assign(rootAttrs, events);
Object.assign(inputAttrs, inputEvents);
return [rootAttrs, inputAttrs];
}
/**
* Returns the set difference of B and A, i.e. the set of elements in B but not in A
*/
export function arrayDiff(a, b) {
const diff = [];
for (let i = 0; i < b.length; i++) {
if (!a.includes(b[i])) diff.push(b[i]);
}
return diff;
}
export function wrapInArray(v) {
return v == null ? [] : Array.isArray(v) ? v : [v];
}
export function defaultFilter(value, search, item) {
return value != null && search != null && typeof value !== 'boolean' && value.toString().toLocaleLowerCase().indexOf(search.toLocaleLowerCase()) !== -1;
}
export function debounce(fn, delay) {
let timeoutId = 0;
const wrap = (...args) => {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => fn(...args), unref(delay));
};
wrap.clear = () => {
clearTimeout(timeoutId);
};
wrap.immediate = fn;
return wrap;
}
export function clamp(value, min = 0, max = 1) {
return Math.max(min, Math.min(max, value));
}
export function getDecimals(value) {
const trimmedStr = value.toString().trim();
return trimmedStr.includes('.') ? trimmedStr.length - trimmedStr.indexOf('.') - 1 : 0;
}
export function padEnd(str, length, char = '0') {
return str + char.repeat(Math.max(0, length - str.length));
}
export function padStart(str, length, char = '0') {
return char.repeat(Math.max(0, length - str.length)) + str;
}
export function chunk(str, size = 1) {
const chunked = [];
let index = 0;
while (index < str.length) {
chunked.push(str.substr(index, size));
index += size;
}
return chunked;
}
export function chunkArray(array, size = 1) {
return Array.from({
length: Math.ceil(array.length / size)
}, (v, i) => array.slice(i * size, i * size + size));
}
export function humanReadableFileSize(bytes, base = 1000) {
if (bytes < base) {
return `${bytes} B`;
}
const prefix = base === 1024 ? ['Ki', 'Mi', 'Gi'] : ['k', 'M', 'G'];
let unit = -1;
while (Math.abs(bytes) >= base && unit < prefix.length - 1) {
bytes /= base;
++unit;
}
return `${bytes.toFixed(1)} ${prefix[unit]}B`;
}
export function mergeDeep(source = {}, target = {}, arrayFn, targetCondition) {
const out = {};
for (const key in source) {
out[key] = source[key];
}
for (const key in target) {
const targetProperty = target[key];
if (targetCondition && !targetCondition(key, targetProperty)) {
continue;
}
const sourceProperty = source[key];
// Only continue deep merging if
// both properties are plain objects
if (isPlainObject(sourceProperty) && isPlainObject(targetProperty)) {
out[key] = mergeDeep(sourceProperty, targetProperty, arrayFn, targetCondition);
continue;
}
if (arrayFn && Array.isArray(sourceProperty) && Array.isArray(targetProperty)) {
out[key] = arrayFn(sourceProperty, targetProperty);
continue;
}
out[key] = targetProperty;
}
return out;
}
export function flattenFragments(nodes) {
return nodes.map(node => {
if (node.type === Fragment) {
return flattenFragments(node.children);
} else {
return node;
}
}).flat();
}
export function toKebabCase(str = '') {
if (toKebabCase.cache.has(str)) return toKebabCase.cache.get(str);
const kebab = str.replace(/[^a-z]/gi, '-').replace(/\B([A-Z])/g, '-$1').toLowerCase();
toKebabCase.cache.set(str, kebab);
return kebab;
}
toKebabCase.cache = new Map();
export function findChildrenWithProvide(key, vnode) {
if (!vnode || typeof vnode !== 'object') return [];
if (Array.isArray(vnode)) {
return vnode.map(child => findChildrenWithProvide(key, child)).flat(1);
} else if (vnode.suspense) {
return findChildrenWithProvide(key, vnode.ssContent);
} else if (Array.isArray(vnode.children)) {
return vnode.children.map(child => findChildrenWithProvide(key, child)).flat(1);
} else if (vnode.component) {
if (Object.getOwnPropertyDescriptor(vnode.component.provides, key)) {
return [vnode.component];
} else if (vnode.component.subTree) {
return findChildrenWithProvide(key, vnode.component.subTree).flat(1);
}
}
return [];
}
export class CircularBuffer {
#arr = [];
#pointer = 0;
constructor(size) {
this.size = size;
}
get isFull() {
return this.#arr.length === this.size;
}
push(val) {
this.#arr[this.#pointer] = val;
this.#pointer = (this.#pointer + 1) % this.size;
}
values() {
return this.#arr.slice(this.#pointer).concat(this.#arr.slice(0, this.#pointer));
}
clear() {
this.#arr.length = 0;
this.#pointer = 0;
}
}
export function getEventCoordinates(e) {
if ('touches' in e) {
return {
clientX: e.touches[0].clientX,
clientY: e.touches[0].clientY
};
}
return {
clientX: e.clientX,
clientY: e.clientY
};
}
// Only allow a single return type
/**
* Convert a computed ref to a record of refs.
* The getter function must always return an object with the same keys.
*/
export function destructComputed(getter) {
const refs = reactive({});
watchEffect(() => {
const base = getter();
for (const key in base) {
refs[key] = base[key];
}
}, {
flush: 'sync'
});
const obj = {};
for (const key in refs) {
obj[key] = toRef(() => refs[key]);
}
return obj;
}
/** Array.includes but value can be any type */
export function includes(arr, val) {
return arr.includes(val);
}
export function eventName(propName) {
return propName[2].toLowerCase() + propName.slice(3);
}
// TODO: this should be an array but vue's types don't accept arrays: vuejs/core#8025
export const EventProp = () => [Function, Array];
export function hasEvent(props, name) {
name = 'on' + capitalize(name);
return !!(props[name] || props[`${name}Once`] || props[`${name}Capture`] || props[`${name}OnceCapture`] || props[`${name}CaptureOnce`]);
}
export function callEvent(handler, ...args) {
if (Array.isArray(handler)) {
for (const h of handler) {
h(...args);
}
} else if (typeof handler === 'function') {
handler(...args);
}
}
export function focusableChildren(el, filterByTabIndex = true) {
const targets = ['button', '[href]', 'input:not([type="hidden"])', 'select', 'textarea', 'details:not(:has(> summary))', 'details > summary', '[tabindex]', '[contenteditable]:not([contenteditable="false"])', 'audio[controls]', 'video[controls]'].map(s => `${s}${filterByTabIndex ? ':not([tabindex="-1"])' : ''}:not([disabled], [inert])`).join(', ');
let elements;
try {
elements = [...el.querySelectorAll(targets)];
} catch (err) {
consoleError(String(err));
return [];
}
return elements.filter(x => !x.closest('[inert]')) // does not have inert parent
.filter(x => !!x.offsetParent || x.getClientRects().length > 0) // is rendered
.filter(x => !x.parentElement?.closest('details:not([open])') || x.tagName === 'SUMMARY' && x.parentElement?.tagName === 'DETAILS');
}
export function getNextElement(elements, location, condition) {
let _el;
let idx = elements.indexOf(document.activeElement);
const inc = location === 'next' ? 1 : -1;
do {
idx += inc;
_el = elements[idx];
} while ((!_el || _el.offsetParent == null || !(condition?.(_el) ?? true)) && idx < elements.length && idx >= 0);
return _el;
}
export function focusChild(el, location) {
const focusable = focusableChildren(el);
if (location == null) {
if (el === document.activeElement || !el.contains(document.activeElement)) {
focusable[0]?.focus();
}
} else if (location === 'first') {
focusable[0]?.focus();
} else if (location === 'last') {
focusable.at(-1)?.focus();
} else if (typeof location === 'number') {
focusable[location]?.focus();
} else {
const _el = getNextElement(focusable, location);
if (_el) _el.focus();else focusChild(el, location === 'next' ? 'first' : 'last');
}
}
export function isEmpty(val) {
return val === null || val === undefined || typeof val === 'string' && val.trim() === '';
}
export function noop() {}
/** Returns null if the selector is not supported or we can't check */
export function matchesSelector(el, selector) {
const supportsSelector = IN_BROWSER && typeof CSS !== 'undefined' && typeof CSS.supports !== 'undefined' && CSS.supports(`selector(${selector})`);
if (!supportsSelector) return null;
try {
return !!el && el.matches(selector);
} catch (err) {
return null;
}
}
export function ensureValidVNode(vnodes) {
return vnodes.some(child => {
if (!isVNode(child)) return true;
if (child.type === Comment) return false;
return child.type !== Fragment || ensureValidVNode(child.children);
}) ? vnodes : null;
}
export function renderSlot(slot, props, fallback) {
// TODO: check if slot returns elements: #18308
return slot?.(props) ?? fallback?.(props);
}
export function defer(timeout, cb) {
if (!IN_BROWSER || timeout === 0) {
cb();
return () => {};
}
const timeoutId = window.setTimeout(cb, timeout);
return () => window.clearTimeout(timeoutId);
}
export function isClickInsideElement(event, targetDiv) {
const mouseX = event.clientX;
const mouseY = event.clientY;
const divRect = targetDiv.getBoundingClientRect();
const divLeft = divRect.left;
const divTop = divRect.top;
const divRight = divRect.right;
const divBottom = divRect.bottom;
return mouseX >= divLeft && mouseX <= divRight && mouseY >= divTop && mouseY <= divBottom;
}
export function templateRef() {
const el = shallowRef();
const fn = target => {
el.value = target;
};
Object.defineProperty(fn, 'value', {
enumerable: true,
get: () => el.value,
set: val => el.value = val
});
Object.defineProperty(fn, 'el', {
enumerable: true,
get: () => refElement(el.value)
});
return fn;
}
export function checkPrintable(e) {
const isPrintableChar = e.key.length === 1;
const noModifier = !e.ctrlKey && !e.metaKey && !e.altKey;
return isPrintableChar && noModifier;
}
export function isPrimitive(value) {
return typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint';
}
export function escapeForRegex(sign) {
return '\\^$*+?.()|{}[]'.includes(sign) ? `\\${sign}` : sign;
}
export function extractNumber(text, decimalDigitsLimit, decimalSeparator) {
const onlyValidCharacters = new RegExp(`[\\d\\-${escapeForRegex(decimalSeparator)}]`);
const cleanText = text.split('').filter(x => onlyValidCharacters.test(x)).filter((x, i, all) => i === 0 && /[-]/.test(x) ||
// sign allowed at the start
x === decimalSeparator && i === all.indexOf(x) ||
// decimal separator allowed only once
/\d/.test(x)).join('');
if (decimalDigitsLimit === 0) {
return cleanText.split(decimalSeparator)[0];
}
const decimalPart = new RegExp(`${escapeForRegex(decimalSeparator)}\\d`);
if (decimalDigitsLimit !== null && decimalPart.test(cleanText)) {
const parts = cleanText.split(decimalSeparator);
return [parts[0], parts[1].substring(0, decimalDigitsLimit)].join(decimalSeparator);
}
return cleanText;
}
export function camelizeProps(props) {
const out = {};
for (const prop in props) {
out[camelize(prop)] = props[prop];
}
return out;
}
export function onlyDefinedProps(props) {
const booleanAttributes = ['checked', 'disabled'];
return Object.fromEntries(Object.entries(props).filter(([key, v]) => booleanAttributes.includes(key) ? !!v : v !== undefined));
}
export function deepToRaw(value) {
const objectIterator = input => {
if (Array.isArray(input)) {
return input.map(item => objectIterator(item));
}
if (isRef(input) || isReactive(input) || isProxy(input)) {
return objectIterator(toRaw(input));
}
if (isPlainObject(input)) {
return Object.keys(input).reduce((acc, key) => {
acc[key] = objectIterator(input[key]);
return acc;
}, {});
}
return input;
};
return objectIterator(value);
}
//# sourceMappingURL=helpers.js.map
File diff suppressed because one or more lines are too long
+18
View File
@@ -0,0 +1,18 @@
export type IndentLinesVariant = 'default' | 'simple';
export type IndentLineType = 'leaf' | 'last-leaf' | 'line' | 'leaf-link' | 'none';
export type IndentLinesOptions = {
depth: number;
isLast: boolean;
isLastGroup: boolean;
leafLinks: boolean;
separateRoots: boolean;
parentIndentLines: IndentLineType[] | undefined;
variant: IndentLinesVariant | undefined;
};
export type IndentLines = {
leaf: IndentLineType[] | undefined;
node: IndentLineType[] | undefined;
children: IndentLineType[] | undefined;
footer: IndentLineType[] | undefined;
};
export declare function getIndentLines({ depth, isLast, isLastGroup, leafLinks, separateRoots, parentIndentLines, variant }: IndentLinesOptions): IndentLines;
+36
View File
@@ -0,0 +1,36 @@
// Types
export function getIndentLines({
depth,
isLast,
isLastGroup,
leafLinks,
separateRoots,
parentIndentLines,
variant
}) {
const isLastLeaf = isLast && (!isLastGroup || separateRoots || depth > 1);
if (!parentIndentLines || !depth) {
return {
leaf: undefined,
node: undefined,
children: parentIndentLines,
footer: parentIndentLines && (!isLastLeaf || variant === 'simple') ? [...parentIndentLines, separateRoots ? 'none' : 'line'] : ['none']
};
}
if (variant === 'simple') {
return {
leaf: [...parentIndentLines, 'line'],
node: [...parentIndentLines, 'line'],
children: [...parentIndentLines, 'line'],
footer: [...parentIndentLines, 'line', 'line']
};
}
return {
leaf: [...parentIndentLines, isLastLeaf ? 'last-leaf' : 'leaf', ...(leafLinks ? ['leaf-link'] : [])],
node: [...parentIndentLines, isLastLeaf ? 'last-leaf' : 'leaf'],
children: [...parentIndentLines, isLastLeaf ? 'none' : 'line'],
footer: [...parentIndentLines, isLastLeaf ? 'none' : 'line']
};
}
//# sourceMappingURL=indentLines.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"indentLines.js","names":["getIndentLines","depth","isLast","isLastGroup","leafLinks","separateRoots","parentIndentLines","variant","isLastLeaf","leaf","undefined","node","children","footer"],"sources":["../../src/util/indentLines.ts"],"sourcesContent":["// Types\nexport type IndentLinesVariant = 'default' | 'simple'\nexport type IndentLineType = 'leaf' | 'last-leaf' | 'line' | 'leaf-link' | 'none'\n\nexport type IndentLinesOptions = {\n depth: number\n isLast: boolean\n isLastGroup: boolean\n leafLinks: boolean\n separateRoots: boolean\n parentIndentLines: IndentLineType[] | undefined\n variant: IndentLinesVariant | undefined\n}\n\nexport type IndentLines = {\n leaf: IndentLineType[] | undefined\n node: IndentLineType[] | undefined\n children: IndentLineType[] | undefined\n footer: IndentLineType[] | undefined\n}\n\nexport function getIndentLines ({\n depth,\n isLast,\n isLastGroup,\n leafLinks,\n separateRoots,\n parentIndentLines,\n variant,\n}: IndentLinesOptions): IndentLines {\n const isLastLeaf = isLast && (!isLastGroup || separateRoots || depth > 1)\n\n if (!parentIndentLines || !depth) {\n return {\n leaf: undefined,\n node: undefined,\n children: parentIndentLines,\n footer: parentIndentLines && (!isLastLeaf || variant === 'simple')\n ? [...parentIndentLines, separateRoots ? 'none' : 'line']\n : ['none'],\n }\n }\n\n if (variant === 'simple') {\n return {\n leaf: [...parentIndentLines, 'line'],\n node: [...parentIndentLines, 'line'],\n children: [...parentIndentLines, 'line'],\n footer: [...parentIndentLines, 'line', 'line'],\n }\n }\n\n return {\n leaf: [\n ...parentIndentLines,\n isLastLeaf ? 'last-leaf' : 'leaf',\n ...leafLinks ? ['leaf-link'] as IndentLineType[] : [],\n ],\n node: [\n ...parentIndentLines,\n isLastLeaf ? 'last-leaf' : 'leaf',\n ],\n children: [\n ...parentIndentLines,\n isLastLeaf ? 'none' : 'line',\n ],\n footer: [\n ...parentIndentLines,\n isLastLeaf ? 'none' : 'line',\n ],\n }\n}\n"],"mappings":"AAAA;;AAqBA,OAAO,SAASA,cAAcA,CAAE;EAC9BC,KAAK;EACLC,MAAM;EACNC,WAAW;EACXC,SAAS;EACTC,aAAa;EACbC,iBAAiB;EACjBC;AACkB,CAAC,EAAe;EAClC,MAAMC,UAAU,GAAGN,MAAM,KAAK,CAACC,WAAW,IAAIE,aAAa,IAAIJ,KAAK,GAAG,CAAC,CAAC;EAEzE,IAAI,CAACK,iBAAiB,IAAI,CAACL,KAAK,EAAE;IAChC,OAAO;MACLQ,IAAI,EAAEC,SAAS;MACfC,IAAI,EAAED,SAAS;MACfE,QAAQ,EAAEN,iBAAiB;MAC3BO,MAAM,EAAEP,iBAAiB,KAAK,CAACE,UAAU,IAAID,OAAO,KAAK,QAAQ,CAAC,GAC9D,CAAC,GAAGD,iBAAiB,EAAED,aAAa,GAAG,MAAM,GAAG,MAAM,CAAC,GACvD,CAAC,MAAM;IACb,CAAC;EACH;EAEA,IAAIE,OAAO,KAAK,QAAQ,EAAE;IACxB,OAAO;MACLE,IAAI,EAAE,CAAC,GAAGH,iBAAiB,EAAE,MAAM,CAAC;MACpCK,IAAI,EAAE,CAAC,GAAGL,iBAAiB,EAAE,MAAM,CAAC;MACpCM,QAAQ,EAAE,CAAC,GAAGN,iBAAiB,EAAE,MAAM,CAAC;MACxCO,MAAM,EAAE,CAAC,GAAGP,iBAAiB,EAAE,MAAM,EAAE,MAAM;IAC/C,CAAC;EACH;EAEA,OAAO;IACLG,IAAI,EAAE,CACJ,GAAGH,iBAAiB,EACpBE,UAAU,GAAG,WAAW,GAAG,MAAM,EACjC,IAAGJ,SAAS,GAAG,CAAC,WAAW,CAAC,GAAuB,EAAE,EACtD;IACDO,IAAI,EAAE,CACJ,GAAGL,iBAAiB,EACpBE,UAAU,GAAG,WAAW,GAAG,MAAM,CAClC;IACDI,QAAQ,EAAE,CACR,GAAGN,iBAAiB,EACpBE,UAAU,GAAG,MAAM,GAAG,MAAM,CAC7B;IACDK,MAAM,EAAE,CACN,GAAGP,iBAAiB,EACpBE,UAAU,GAAG,MAAM,GAAG,MAAM;EAEhC,CAAC;AACH","ignoreList":[]}
+22
View File
@@ -0,0 +1,22 @@
export * from './anchor.js';
export * from './animation.js';
export * from './bindProps.js';
export * from './colorUtils.js';
export * from './console.js';
export * from './createSimpleFunctional.js';
export * from './deepEqual.js';
export * from './defineComponent.js';
export * from './dom.js';
export * from './easing.js';
export * from './events.js';
export * from './getCurrentInstance.js';
export * from './getScrollParent.js';
export * from './globals.js';
export * from './helpers.js';
export * from './indentLines.js';
export * from './injectSelf.js';
export * from './isFixedPosition.js';
export * from './propsFactory.js';
export * from './useRender.js';
export * from './timeUtils.js';
export * from './throttle.js';
+23
View File
@@ -0,0 +1,23 @@
export * from "./anchor.js";
export * from "./animation.js";
export * from "./bindProps.js";
export * from "./colorUtils.js";
export * from "./console.js";
export * from "./createSimpleFunctional.js";
export * from "./deepEqual.js";
export * from "./defineComponent.js";
export * from "./dom.js";
export * from "./easing.js";
export * from "./events.js";
export * from "./getCurrentInstance.js";
export * from "./getScrollParent.js";
export * from "./globals.js";
export * from "./helpers.js";
export * from "./indentLines.js";
export * from "./injectSelf.js";
export * from "./isFixedPosition.js";
export * from "./propsFactory.js";
export * from "./useRender.js";
export * from "./timeUtils.js";
export * from "./throttle.js";
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","names":[],"sources":["../../src/util/index.ts"],"sourcesContent":["export * from './anchor'\nexport * from './animation'\nexport * from './bindProps'\nexport * from './colorUtils'\nexport * from './console'\nexport * from './createSimpleFunctional'\nexport * from './deepEqual'\nexport * from './defineComponent'\nexport * from './dom'\nexport * from './easing'\nexport * from './events'\nexport * from './getCurrentInstance'\nexport * from './getScrollParent'\nexport * from './globals'\nexport * from './helpers'\nexport * from './indentLines'\nexport * from './injectSelf'\nexport * from './isFixedPosition'\nexport * from './propsFactory'\nexport * from './useRender'\nexport * from './timeUtils'\nexport * from './throttle'\n"],"mappings":"","ignoreList":[]}
+2
View File
@@ -0,0 +1,2 @@
import type { ComponentInternalInstance, InjectionKey } from 'vue';
export declare function injectSelf<T>(key: InjectionKey<T> | string, vm?: ComponentInternalInstance): T | undefined;
+13
View File
@@ -0,0 +1,13 @@
// Utilities
import { getCurrentInstance } from "./getCurrentInstance.js"; // Types
export function injectSelf(key, vm = getCurrentInstance('injectSelf')) {
const {
provides
} = vm;
if (provides && key in provides) {
// TS doesn't allow symbol as index type
return provides[key];
}
return undefined;
}
//# sourceMappingURL=injectSelf.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"injectSelf.js","names":["getCurrentInstance","injectSelf","key","vm","provides","undefined"],"sources":["../../src/util/injectSelf.ts"],"sourcesContent":["// Utilities\nimport { getCurrentInstance } from '@/util/getCurrentInstance'\n\n// Types\nimport type { ComponentInternalInstance, InjectionKey } from 'vue'\n\nexport function injectSelf<T>(key: InjectionKey<T> | string, vm?: ComponentInternalInstance): T | undefined\nexport function injectSelf (key: InjectionKey<any> | string, vm = getCurrentInstance('injectSelf')) {\n const { provides } = vm\n\n if (provides && (key as string | symbol) in provides) {\n // TS doesn't allow symbol as index type\n return provides[key as string]\n }\n return undefined\n}\n"],"mappings":"AAAA;AAAA,SACSA,kBAAkB,mCAE3B;AAIA,OAAO,SAASC,UAAUA,CAAEC,GAA+B,EAAEC,EAAE,GAAGH,kBAAkB,CAAC,YAAY,CAAC,EAAE;EAClG,MAAM;IAAEI;EAAS,CAAC,GAAGD,EAAE;EAEvB,IAAIC,QAAQ,IAAKF,GAAG,IAAwBE,QAAQ,EAAE;IACpD;IACA,OAAOA,QAAQ,CAACF,GAAG,CAAW;EAChC;EACA,OAAOG,SAAS;AAClB","ignoreList":[]}
+1
View File
@@ -0,0 +1 @@
export declare function isFixedPosition(el?: HTMLElement): boolean;
+10
View File
@@ -0,0 +1,10 @@
export function isFixedPosition(el) {
while (el) {
if (window.getComputedStyle(el).position === 'fixed') {
return true;
}
el = el.offsetParent;
}
return false;
}
//# sourceMappingURL=isFixedPosition.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"isFixedPosition.js","names":["isFixedPosition","el","window","getComputedStyle","position","offsetParent"],"sources":["../../src/util/isFixedPosition.ts"],"sourcesContent":["export function isFixedPosition (el?: HTMLElement) {\n while (el) {\n if (window.getComputedStyle(el).position === 'fixed') {\n return true\n }\n el = el.offsetParent as HTMLElement\n }\n return false\n}\n"],"mappings":"AAAA,OAAO,SAASA,eAAeA,CAAEC,EAAgB,EAAE;EACjD,OAAOA,EAAE,EAAE;IACT,IAAIC,MAAM,CAACC,gBAAgB,CAACF,EAAE,CAAC,CAACG,QAAQ,KAAK,OAAO,EAAE;MACpD,OAAO,IAAI;IACb;IACAH,EAAE,GAAGA,EAAE,CAACI,YAA2B;EACrC;EACA,OAAO,KAAK;AACd","ignoreList":[]}
+57
View File
@@ -0,0 +1,57 @@
import type { IfAny } from '@vue/shared';
import type { ComponentObjectPropsOptions, Prop, PropType } from 'vue';
/**
* Creates a factory function for props definitions.
* This is used to define props in a composable then override
* default values in an implementing component.
*
* @example Simplified signature
* (props: Props) => (defaults?: Record<keyof props, any>) => Props
*
* @example Usage
* const makeProps = propsFactory({
* foo: String,
* })
*
* defineComponent({
* props: {
* ...makeProps({
* foo: 'a',
* }),
* },
* setup (props) {
* // would be "string | undefined", now "string" because a default has been provided
* props.foo
* },
* }
*/
export declare function propsFactory<PropsOptions extends ComponentObjectPropsOptions>(props: PropsOptions, source: string): <Defaults extends PartialKeys<PropsOptions> = {}>(defaults?: Defaults) => AppendDefault<PropsOptions, Defaults>;
type AppendDefault<T extends ComponentObjectPropsOptions, D extends PartialKeys<T>> = {
[P in keyof T]-?: unknown extends D[P] ? T[P] : T[P] extends Record<string, unknown> ? Omit<T[P], 'type' | 'default'> & {
type: PropType<MergeTypeDefault<T[P], D[P]>>;
default: MergeDefault<T[P], D[P]>;
} : {
type: PropType<MergeTypeDefault<T[P], D[P]>>;
default: MergeDefault<T[P], D[P]>;
};
};
type MergeTypeDefault<T, D, P = InferPropType<T>> = unknown extends D ? P : (P | D);
type MergeDefault<T, D, P = InferPropType<T>> = unknown extends D ? P : (NonNullable<P> | D);
/**
* Like `Partial<T>` but doesn't care what the value is
*/
type PartialKeys<T> = {
[P in keyof T]?: unknown;
};
type InferPropType<T> = [T] extends [null] ? any : [T] extends [{
type: null | true;
}] ? any : [T] extends [ObjectConstructor | {
type: ObjectConstructor;
}] ? Record<string, any> : [T] extends [BooleanConstructor | {
type: BooleanConstructor;
}] ? boolean : [T] extends [DateConstructor | {
type: DateConstructor;
}] ? Date : [T] extends [(infer U)[] | {
type: (infer U)[];
}] ? U extends DateConstructor ? Date | InferPropType<U> : InferPropType<U> : [T] extends [Prop<infer V, infer D>] ? unknown extends V ? IfAny<V, V, D> : V : T;
+58
View File
@@ -0,0 +1,58 @@
// Types
// eslint-disable-line vue/prefer-import-from-vue
/**
* Creates a factory function for props definitions.
* This is used to define props in a composable then override
* default values in an implementing component.
*
* @example Simplified signature
* (props: Props) => (defaults?: Record<keyof props, any>) => Props
*
* @example Usage
* const makeProps = propsFactory({
* foo: String,
* })
*
* defineComponent({
* props: {
* ...makeProps({
* foo: 'a',
* }),
* },
* setup (props) {
* // would be "string | undefined", now "string" because a default has been provided
* props.foo
* },
* }
*/
export function propsFactory(props, source) {
return defaults => {
return Object.keys(props).reduce((obj, prop) => {
const isObjectDefinition = typeof props[prop] === 'object' && props[prop] != null && !Array.isArray(props[prop]);
const definition = isObjectDefinition ? props[prop] : {
type: props[prop]
};
if (defaults && prop in defaults) {
obj[prop] = {
...definition,
default: defaults[prop]
};
} else {
obj[prop] = definition;
}
if (source && !obj[prop].source) {
obj[prop].source = source;
}
return obj;
}, {});
};
}
/**
* Like `Partial<T>` but doesn't care what the value is
*/
// Copied from Vue
//# sourceMappingURL=propsFactory.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"propsFactory.js","names":["propsFactory","props","source","defaults","Object","keys","reduce","obj","prop","isObjectDefinition","Array","isArray","definition","type","default"],"sources":["../../src/util/propsFactory.ts"],"sourcesContent":["// Types\nimport type { IfAny } from '@vue/shared' // eslint-disable-line vue/prefer-import-from-vue\nimport type { ComponentObjectPropsOptions, Prop, PropType } from 'vue'\n\n/**\n * Creates a factory function for props definitions.\n * This is used to define props in a composable then override\n * default values in an implementing component.\n *\n * @example Simplified signature\n * (props: Props) => (defaults?: Record<keyof props, any>) => Props\n *\n * @example Usage\n * const makeProps = propsFactory({\n * foo: String,\n * })\n *\n * defineComponent({\n * props: {\n * ...makeProps({\n * foo: 'a',\n * }),\n * },\n * setup (props) {\n * // would be \"string | undefined\", now \"string\" because a default has been provided\n * props.foo\n * },\n * }\n */\n\nexport function propsFactory<\n PropsOptions extends ComponentObjectPropsOptions\n> (props: PropsOptions, source: string) {\n return <Defaults extends PartialKeys<PropsOptions> = {}>(\n defaults?: Defaults\n ): AppendDefault<PropsOptions, Defaults> => {\n return Object.keys(props).reduce<any>((obj, prop) => {\n const isObjectDefinition = typeof props[prop] === 'object' && props[prop] != null && !Array.isArray(props[prop])\n const definition = isObjectDefinition ? props[prop] : { type: props[prop] }\n\n if (defaults && prop in defaults) {\n obj[prop] = {\n ...definition,\n default: defaults[prop],\n }\n } else {\n obj[prop] = definition\n }\n\n if (source && !obj[prop].source) {\n obj[prop].source = source\n }\n\n return obj\n }, {})\n }\n}\n\ntype AppendDefault<T extends ComponentObjectPropsOptions, D extends PartialKeys<T>> = {\n [P in keyof T]-?: unknown extends D[P]\n ? T[P]\n : T[P] extends Record<string, unknown>\n ? Omit<T[P], 'type' | 'default'> & {\n type: PropType<MergeTypeDefault<T[P], D[P]>>\n default: MergeDefault<T[P], D[P]>\n }\n : {\n type: PropType<MergeTypeDefault<T[P], D[P]>>\n default: MergeDefault<T[P], D[P]>\n }\n}\n\ntype MergeTypeDefault<T, D, P = InferPropType<T>> = unknown extends D\n ? P\n : (P | D)\ntype MergeDefault<T, D, P = InferPropType<T>> = unknown extends D\n ? P\n : (NonNullable<P> | D)\n\n/**\n * Like `Partial<T>` but doesn't care what the value is\n */\ntype PartialKeys<T> = { [P in keyof T]?: unknown }\n\n// Copied from Vue\ntype InferPropType<T> = [T] extends [null]\n ? any // null & true would fail to infer\n : [T] extends [{ type: null | true }]\n // As TS issue https://github.com/Microsoft/TypeScript/issues/14829\n // somehow `ObjectConstructor` when inferred from { (): T } becomes `any`\n // `BooleanConstructor` when inferred from PropConstructor(with PropMethod) becomes `Boolean`\n ? any\n : [T] extends [ObjectConstructor | { type: ObjectConstructor }]\n ? Record<string, any>\n : [T] extends [BooleanConstructor | { type: BooleanConstructor }]\n ? boolean\n : [T] extends [DateConstructor | { type: DateConstructor }]\n ? Date\n : [T] extends [(infer U)[] | { type: (infer U)[] }]\n ? U extends DateConstructor\n ? Date | InferPropType<U>\n : InferPropType<U>\n : [T] extends [Prop<infer V, infer D>]\n ? unknown extends V\n ? IfAny<V, V, D>\n : V\n : T\n"],"mappings":"AAAA;AACyC;;AAGzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,SAASA,YAAYA,CAEzBC,KAAmB,EAAEC,MAAc,EAAE;EACtC,OACEC,QAAmB,IACuB;IAC1C,OAAOC,MAAM,CAACC,IAAI,CAACJ,KAAK,CAAC,CAACK,MAAM,CAAM,CAACC,GAAG,EAAEC,IAAI,KAAK;MACnD,MAAMC,kBAAkB,GAAG,OAAOR,KAAK,CAACO,IAAI,CAAC,KAAK,QAAQ,IAAIP,KAAK,CAACO,IAAI,CAAC,IAAI,IAAI,IAAI,CAACE,KAAK,CAACC,OAAO,CAACV,KAAK,CAACO,IAAI,CAAC,CAAC;MAChH,MAAMI,UAAU,GAAGH,kBAAkB,GAAGR,KAAK,CAACO,IAAI,CAAC,GAAG;QAAEK,IAAI,EAAEZ,KAAK,CAACO,IAAI;MAAE,CAAC;MAE3E,IAAIL,QAAQ,IAAIK,IAAI,IAAIL,QAAQ,EAAE;QAChCI,GAAG,CAACC,IAAI,CAAC,GAAG;UACV,GAAGI,UAAU;UACbE,OAAO,EAAEX,QAAQ,CAACK,IAAI;QACxB,CAAC;MACH,CAAC,MAAM;QACLD,GAAG,CAACC,IAAI,CAAC,GAAGI,UAAU;MACxB;MAEA,IAAIV,MAAM,IAAI,CAACK,GAAG,CAACC,IAAI,CAAC,CAACN,MAAM,EAAE;QAC/BK,GAAG,CAACC,IAAI,CAAC,CAACN,MAAM,GAAGA,MAAM;MAC3B;MAEA,OAAOK,GAAG;IACZ,CAAC,EAAE,CAAC,CAAC,CAAC;EACR,CAAC;AACH;;AAuBA;AACA;AACA;;AAGA","ignoreList":[]}
+4
View File
@@ -0,0 +1,4 @@
type Point = [x: number, y: number];
export declare function simpleArc(center: Point, r: number, startAngle: number, endAngle: number): string;
export declare function roundedArc(center: Point, radius: number, startAngle: number, endAngle: number, width: number, rounding: number): string;
+72
View File
@@ -0,0 +1,72 @@
/*
* Credits: Alexander Milevski https://github.com/w8r/svg-arc-corners
*/
function pointOnArc(center, radius, angle) {
const radians = (angle - 90) * Math.PI / 180.0;
return [center[0] + radius * Math.cos(radians), center[1] + radius * Math.sin(radians)];
}
function drawCircle([x, y], r, width) {
const innerRadius = r - width;
return ['M', x - r, y, 'A', r, r, 0, 1, 0, x + r, y, 'A', r, r, 0, 1, 0, x - r, y, 'M', x - innerRadius, y, 'A', innerRadius, innerRadius, 0, 1, 0, x + innerRadius, y, 'A', innerRadius, innerRadius, 0, 1, 0, x - innerRadius, y, 'Z'];
}
export function simpleArc(center, r, startAngle, endAngle) {
const start = pointOnArc(center, r, startAngle);
const end = pointOnArc(center, r, endAngle);
const sweep = endAngle - startAngle > 180 ? 1 : 0;
return [`M${start[0]} ${start[1]}`, `A${r} ${r} 0 ${sweep} 1 ${end[0]} ${end[1]}`, `L${center[0]} ${center[1]}Z`].join(' ');
}
export function roundedArc(center, radius, startAngle, endAngle, width, rounding) {
width = Math.min(radius, width);
if (Math.abs(endAngle - startAngle) === 360) {
return drawCircle(center, radius, width).join(' ');
}
if (rounding === 0 && radius === width) {
return simpleArc(center, radius, startAngle, endAngle);
}
const innerR = radius - width;
const circumference = Math.abs(endAngle - startAngle);
rounding = Math.min(width / 2, rounding);
if (360 * (rounding / (Math.PI * (radius - width))) > Math.abs(startAngle - endAngle)) {
rounding = circumference / 360 * innerR * Math.PI;
}
// inner and outer radiuses
const innerR2 = innerR + rounding;
const outerRadius = radius - rounding;
// butts corner points
const oStart = pointOnArc(center, outerRadius, startAngle);
const oEnd = pointOnArc(center, outerRadius, endAngle);
const iStart = pointOnArc(center, innerR2, startAngle);
const iEnd = pointOnArc(center, innerR2, endAngle);
const iSection = innerR ? 360 * (rounding / (2 * Math.PI * innerR)) : 0;
const oSection = 360 * (rounding / (2 * Math.PI * radius));
// arcs endpoints
const iArcStart = pointOnArc(center, innerR, startAngle + iSection);
const iArcEnd = pointOnArc(center, innerR, endAngle - iSection);
const oArcStart = pointOnArc(center, radius, startAngle + oSection);
const oArcEnd = pointOnArc(center, radius, endAngle - oSection);
const arcSweep1 = circumference > 180 + 2 * oSection ? 1 : 0;
const arcSweep2 = circumference > 180 + 2 * iSection ? 1 : 0;
return [
// begin path
'M', oStart[0], oStart[1],
// outer start corner
'A', rounding, rounding, 0, 0, 1, oArcStart[0], oArcStart[1],
// outer main arc
'A', radius, radius, 0, arcSweep1, 1, oArcEnd[0], oArcEnd[1],
// outer end corner
'A', rounding, rounding, 0, 0, 1, oEnd[0], oEnd[1],
// end butt
'L', iEnd[0], iEnd[1],
// inner end corner
'A', rounding, rounding, 0, 0, 1, iArcEnd[0], iArcEnd[1],
// inner arc
'A', innerR, innerR, 0, arcSweep2, 0, iArcStart[0], iArcStart[1],
// inner start corner
'A', rounding, rounding, 0, 0, 1, iStart[0], iStart[1], 'Z' // end path
].join(' ');
}
//# sourceMappingURL=svg-arc-corners.js.map
File diff suppressed because one or more lines are too long
+8
View File
@@ -0,0 +1,8 @@
export declare function throttle<T extends (...args: any[]) => any>(fn: T, delay: number, options?: {
leading: boolean;
trailing: boolean;
}): {
(...args: Parameters<T>): void | ReturnType<T>;
clear: () => void;
immediate: T;
};
+39
View File
@@ -0,0 +1,39 @@
export function throttle(fn, delay, options = {
leading: true,
trailing: true
}) {
let timeoutId = 0;
let lastExec = 0;
let throttling = false;
let start = 0;
function clear() {
clearTimeout(timeoutId);
throttling = false;
start = 0;
}
const wrap = (...args) => {
clearTimeout(timeoutId);
const now = Date.now();
if (!start) start = now;
const elapsed = now - Math.max(start, lastExec);
function invoke() {
lastExec = Date.now();
timeoutId = setTimeout(clear, delay);
fn(...args);
}
if (!throttling) {
throttling = true;
if (options.leading) {
invoke();
}
} else if (elapsed >= delay) {
invoke();
} else if (options.trailing) {
timeoutId = setTimeout(invoke, delay - elapsed);
}
};
wrap.clear = clear;
wrap.immediate = fn;
return wrap;
}
//# sourceMappingURL=throttle.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"throttle.js","names":["throttle","fn","delay","options","leading","trailing","timeoutId","lastExec","throttling","start","clear","clearTimeout","wrap","args","now","Date","elapsed","Math","max","invoke","setTimeout","immediate"],"sources":["../../src/util/throttle.ts"],"sourcesContent":["export function throttle<T extends (...args: any[]) => any> (\n fn: T,\n delay: number,\n options = { leading: true, trailing: true },\n) {\n let timeoutId = 0 as any\n let lastExec = 0\n let throttling = false\n let start = 0\n\n function clear () {\n clearTimeout(timeoutId)\n throttling = false\n start = 0\n }\n\n const wrap = (...args: Parameters<T>): void | ReturnType<T> => {\n clearTimeout(timeoutId)\n\n const now = Date.now()\n\n if (!start) start = now\n const elapsed = now - Math.max(start, lastExec)\n\n function invoke () {\n lastExec = Date.now()\n timeoutId = setTimeout(clear, delay)\n fn(...args)\n }\n\n if (!throttling) {\n throttling = true\n if (options.leading) {\n invoke()\n }\n } else if (elapsed >= delay) {\n invoke()\n } else if (options.trailing) {\n timeoutId = setTimeout(invoke, delay - elapsed)\n }\n }\n\n wrap.clear = clear\n wrap.immediate = fn\n return wrap\n}\n"],"mappings":"AAAA,OAAO,SAASA,QAAQA,CACtBC,EAAK,EACLC,KAAa,EACbC,OAAO,GAAG;EAAEC,OAAO,EAAE,IAAI;EAAEC,QAAQ,EAAE;AAAK,CAAC,EAC3C;EACA,IAAIC,SAAS,GAAG,CAAQ;EACxB,IAAIC,QAAQ,GAAG,CAAC;EAChB,IAAIC,UAAU,GAAG,KAAK;EACtB,IAAIC,KAAK,GAAG,CAAC;EAEb,SAASC,KAAKA,CAAA,EAAI;IAChBC,YAAY,CAACL,SAAS,CAAC;IACvBE,UAAU,GAAG,KAAK;IAClBC,KAAK,GAAG,CAAC;EACX;EAEA,MAAMG,IAAI,GAAGA,CAAC,GAAGC,IAAmB,KAA2B;IAC7DF,YAAY,CAACL,SAAS,CAAC;IAEvB,MAAMQ,GAAG,GAAGC,IAAI,CAACD,GAAG,CAAC,CAAC;IAEtB,IAAI,CAACL,KAAK,EAAEA,KAAK,GAAGK,GAAG;IACvB,MAAME,OAAO,GAAGF,GAAG,GAAGG,IAAI,CAACC,GAAG,CAACT,KAAK,EAAEF,QAAQ,CAAC;IAE/C,SAASY,MAAMA,CAAA,EAAI;MACjBZ,QAAQ,GAAGQ,IAAI,CAACD,GAAG,CAAC,CAAC;MACrBR,SAAS,GAAGc,UAAU,CAACV,KAAK,EAAER,KAAK,CAAC;MACpCD,EAAE,CAAC,GAAGY,IAAI,CAAC;IACb;IAEA,IAAI,CAACL,UAAU,EAAE;MACfA,UAAU,GAAG,IAAI;MACjB,IAAIL,OAAO,CAACC,OAAO,EAAE;QACnBe,MAAM,CAAC,CAAC;MACV;IACF,CAAC,MAAM,IAAIH,OAAO,IAAId,KAAK,EAAE;MAC3BiB,MAAM,CAAC,CAAC;IACV,CAAC,MAAM,IAAIhB,OAAO,CAACE,QAAQ,EAAE;MAC3BC,SAAS,GAAGc,UAAU,CAACD,MAAM,EAAEjB,KAAK,GAAGc,OAAO,CAAC;IACjD;EACF,CAAC;EAEDJ,IAAI,CAACF,KAAK,GAAGA,KAAK;EAClBE,IAAI,CAACS,SAAS,GAAGpB,EAAE;EACnB,OAAOW,IAAI;AACb","ignoreList":[]}
+1
View File
@@ -0,0 +1 @@
export declare function formatTime(seconds: number): string;
+4
View File
@@ -0,0 +1,4 @@
export function formatTime(seconds) {
return [Math.floor(seconds % 60), Math.floor(seconds / 60 % 60), Math.floor(seconds / 60 / 60 % 60)].filter((x, i) => i < 2 || x > 0).reverse().map(String).map((x, i) => i > 0 ? x.padStart(2, '0') : x).join(':');
}
//# sourceMappingURL=timeUtils.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"timeUtils.js","names":["formatTime","seconds","Math","floor","filter","x","i","reverse","map","String","padStart","join"],"sources":["../../src/util/timeUtils.ts"],"sourcesContent":["export function formatTime (seconds: number) {\n return [\n Math.floor(seconds % 60),\n Math.floor(seconds / 60 % 60),\n Math.floor(seconds / 60 / 60 % 60),\n ]\n .filter((x, i) => i < 2 || x > 0)\n .reverse()\n .map(String)\n .map((x, i) => i > 0 ? x.padStart(2, '0') : x)\n .join(':')\n}\n"],"mappings":"AAAA,OAAO,SAASA,UAAUA,CAAEC,OAAe,EAAE;EAC3C,OAAO,CACLC,IAAI,CAACC,KAAK,CAACF,OAAO,GAAG,EAAE,CAAC,EACxBC,IAAI,CAACC,KAAK,CAACF,OAAO,GAAG,EAAE,GAAG,EAAE,CAAC,EAC7BC,IAAI,CAACC,KAAK,CAACF,OAAO,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CACnC,CACEG,MAAM,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAKA,CAAC,GAAG,CAAC,IAAID,CAAC,GAAG,CAAC,CAAC,CAChCE,OAAO,CAAC,CAAC,CACTC,GAAG,CAACC,MAAM,CAAC,CACXD,GAAG,CAAC,CAACH,CAAC,EAAEC,CAAC,KAAKA,CAAC,GAAG,CAAC,GAAGD,CAAC,CAACK,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,GAAGL,CAAC,CAAC,CAC7CM,IAAI,CAAC,GAAG,CAAC;AACd","ignoreList":[]}
+2
View File
@@ -0,0 +1,2 @@
import type { VNode } from 'vue';
export declare function useRender(render: () => VNode): void;
+7
View File
@@ -0,0 +1,7 @@
// Utilities
import { getCurrentInstance } from "./getCurrentInstance.js"; // Types
export function useRender(render) {
const vm = getCurrentInstance('useRender');
vm.render = render;
}
//# sourceMappingURL=useRender.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"useRender.js","names":["getCurrentInstance","useRender","render","vm"],"sources":["../../src/util/useRender.ts"],"sourcesContent":["// Utilities\nimport { getCurrentInstance } from './getCurrentInstance'\n\n// Types\nimport type { VNode } from 'vue'\n\nexport function useRender (render: () => VNode): void {\n const vm = getCurrentInstance('useRender') as any\n vm.render = render\n}\n"],"mappings":"AAAA;AAAA,SACSA,kBAAkB,mCAE3B;AAGA,OAAO,SAASC,SAASA,CAAEC,MAAmB,EAAQ;EACpD,MAAMC,EAAE,GAAGH,kBAAkB,CAAC,WAAW,CAAQ;EACjDG,EAAE,CAACD,MAAM,GAAGA,MAAM;AACpB","ignoreList":[]}