aboutsummaryrefslogtreecommitdiff
path: root/src/Utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/Utils.ts')
-rw-r--r--src/Utils.ts31
1 files changed, 12 insertions, 19 deletions
diff --git a/src/Utils.ts b/src/Utils.ts
index 330ca59f9..4e4414a93 100644
--- a/src/Utils.ts
+++ b/src/Utils.ts
@@ -157,23 +157,19 @@ export namespace Utils {
const isTransparentFunctionHack = 'isTransparent(__value__)';
export const noRecursionHack = '__noRecursion';
- export const noDragsDocFilter = 'noDragDocs::any::check';
+
+ // special case filters
+ export const noDragDocsFilter = 'noDragDocs::any::check';
+ export const TransparentBackgroundFilter = `backgroundColor::${isTransparentFunctionHack},${noRecursionHack}::check`; // bcz: hack. noRecursion should probably be either another ':' delimited field, or it should be a modifier to the comparision (eg., check, x, etc) field
+ export const OpaqueBackgroundFilter = `backgroundColor::${isTransparentFunctionHack},${noRecursionHack}::x`; // bcz: hack. noRecursion should probably be either another ':' delimited field, or it should be a modifier to the comparision (eg., check, x, etc) field
+
export function IsRecursiveFilter(val: string) {
return !val.includes(noRecursionHack);
}
- export function HasTransparencyFilter(val: string) {
- return val.includes(isTransparentFunctionHack);
- }
- export function IsTransparentFilter() {
- // bcz: isTransparent(__value__) is a hack. it would be nice to have acual functions be parsed, but now Doc.matchFieldValue is hardwired to recognize just this one
- return `backgroundColor::${isTransparentFunctionHack},${noRecursionHack}::check`; // bcz: hack. noRecursion should probably be either another ':' delimited field, or it should be a modifier to the comparision (eg., check, x, etc) field
- }
- export function IsOpaqueFilter() {
- // bcz: isTransparent(__value__) is a hack. it would be nice to have acual functions be parsed, but now Doc.matchFieldValue is hardwired to recognize just this one
- return `backgroundColor::${isTransparentFunctionHack},${noRecursionHack}::x`; // bcz: hack. noRecursion should probably be either another ':' delimited field, or it should be a modifier to the comparision (eg., check, x, etc) field
- }
- export function IsPropUnsetFilter(prop: string) {
- return `${prop}::any,${noRecursionHack}::unset`;
+ export function HasFunctionFilter(val: string) {
+ if (val.includes(isTransparentFunctionHack)) return (color: string) => color !== '' && DashColor(color).alpha() !== 1;
+ // add other function filters here...
+ return undefined;
}
export function toRGBAstr(col: { r: number; g: number; b: number; a?: number }) {
@@ -758,12 +754,9 @@ export function DashColor(color: string) {
}
export function lightOrDark(color: any) {
- if (color === 'transparent' || !color) return Colors.DARK_GRAY;
+ if (color === 'transparent' || !color) return Colors.BLACK;
if (color.startsWith?.('linear')) return Colors.BLACK;
- const nonAlphaColor = color.startsWith('#') ? (color as string).substring(0, 7) : color.startsWith('rgba') ? color.replace(/,.[^,]*\)/, ')').replace('rgba', 'rgb') : color;
- const col = DashColor(nonAlphaColor).rgb();
- const colsum = col.red() + col.green() + col.blue();
- if (colsum / col.alpha() > 400 || col.alpha() < 0.25) return Colors.DARK_GRAY;
+ if (DashColor(color).isLight()) return Colors.BLACK;
return Colors.WHITE;
}