mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 05:17:53 +08:00
chore: cleanup font-variation-settings
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
import { Font as FontDefinition, FontVariationSettings as FontVariationSettingsType } from './font';
|
import { Font as FontDefinition, FontVariationSettingsType } from './font';
|
||||||
import { ParsedFont } from './font-interfaces';
|
import { ParsedFont } from './font-interfaces';
|
||||||
import { makeValidator, makeParser } from '../core/properties';
|
import { makeValidator, makeParser } from '../core/properties';
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ export abstract class Font implements FontDefinition {
|
|||||||
return this.fontWeight === FontWeight.SEMI_BOLD || this.fontWeight === FontWeight.BOLD || this.fontWeight === '700' || this.fontWeight === FontWeight.EXTRA_BOLD || this.fontWeight === FontWeight.BLACK;
|
return this.fontWeight === FontWeight.SEMI_BOLD || this.fontWeight === FontWeight.BOLD || this.fontWeight === '700' || this.fontWeight === FontWeight.EXTRA_BOLD || this.fontWeight === FontWeight.BLACK;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected constructor(public readonly fontFamily: string, public readonly fontSize: number, fontStyle?: FontStyleType, fontWeight?: FontWeightType, fontScale?: number, public readonly fontVariationSettings?: FontVariationSettingsType[]) {
|
protected constructor(public readonly fontFamily: string, public readonly fontSize: number, fontStyle?: FontStyleType, fontWeight?: FontWeightType, fontScale?: number, public readonly fontVariationSettings?: Array<FontVariationSettingsType>) {
|
||||||
this.fontStyle = fontStyle ?? FontStyle.NORMAL;
|
this.fontStyle = fontStyle ?? FontStyle.NORMAL;
|
||||||
this.fontWeight = fontWeight ?? FontWeight.NORMAL;
|
this.fontWeight = fontWeight ?? FontWeight.NORMAL;
|
||||||
this.fontScale = fontScale ?? 1;
|
this.fontScale = fontScale ?? 1;
|
||||||
@ -32,7 +32,7 @@ export abstract class Font implements FontDefinition {
|
|||||||
public abstract withFontWeight(weight: FontWeightType): Font;
|
public abstract withFontWeight(weight: FontWeightType): Font;
|
||||||
public abstract withFontSize(size: number): Font;
|
public abstract withFontSize(size: number): Font;
|
||||||
public abstract withFontScale(scale: number): Font;
|
public abstract withFontScale(scale: number): Font;
|
||||||
public abstract withFontVariationSettings(variationSettings: FontVariationSettingsType[] | null): Font;
|
public abstract withFontVariationSettings(variationSettings: Array<FontVariationSettingsType> | null): Font;
|
||||||
|
|
||||||
public static equals(value1: Font, value2: Font): boolean {
|
public static equals(value1: Font, value2: Font): boolean {
|
||||||
// both values are falsy
|
// both values are falsy
|
||||||
@ -74,7 +74,7 @@ export namespace FontWeight {
|
|||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||||
export namespace FontVariationSettings {
|
export namespace FontVariationSettings {
|
||||||
export function parse(fontVariationSettings: string): FontVariationSettingsType[] | null {
|
export function parse(fontVariationSettings: string): Array<FontVariationSettingsType> | null {
|
||||||
const allowedValues = ['normal', 'inherit', 'initial', 'revert', 'revert-layer', 'unset'];
|
const allowedValues = ['normal', 'inherit', 'initial', 'revert', 'revert-layer', 'unset'];
|
||||||
const lower = fontVariationSettings?.toLowerCase().trim();
|
const lower = fontVariationSettings?.toLowerCase().trim();
|
||||||
if (allowedValues.indexOf(lower) !== -1) {
|
if (allowedValues.indexOf(lower) !== -1) {
|
||||||
@ -83,7 +83,7 @@ export namespace FontVariationSettings {
|
|||||||
|
|
||||||
const chunks = lower.split(',');
|
const chunks = lower.split(',');
|
||||||
if (chunks.length) {
|
if (chunks.length) {
|
||||||
const parsed: FontVariationSettingsType[] = [];
|
const parsed: Array<FontVariationSettingsType> = [];
|
||||||
for (const chunk of chunks) {
|
for (const chunk of chunks) {
|
||||||
const axisChunks = chunk.trim();
|
const axisChunks = chunk.trim();
|
||||||
if (axisChunks.length === 2) {
|
if (axisChunks.length === 2) {
|
||||||
@ -94,17 +94,17 @@ export namespace FontVariationSettings {
|
|||||||
if (!isNaN(axisValue) && axisName.length === 6 && ((axisName.startsWith("'") && axisName.endsWith("'")) || (axisName.startsWith('"') && axisName.endsWith('"')))) {
|
if (!isNaN(axisValue) && axisName.length === 6 && ((axisName.startsWith("'") && axisName.endsWith("'")) || (axisName.startsWith('"') && axisName.endsWith('"')))) {
|
||||||
parsed.push({ axis: axisName, value: axisValue });
|
parsed.push({ axis: axisName, value: axisValue });
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid value (font-variation-settings): ' + fontVariationSettings);
|
console.error('Invalid value (font-variation-settings): ' + fontVariationSettings);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid value (font-variation-settings): ' + fontVariationSettings);
|
console.error('Invalid value (font-variation-settings): ' + fontVariationSettings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return parsed;
|
return parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error('Invalid value (font-variation-settings): ' + fontVariationSettings);
|
console.error('Invalid value (font-variation-settings): ' + fontVariationSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toString(fontVariationSettings: FontVariationSettingsType[] | null): string | null {
|
export function toString(fontVariationSettings: FontVariationSettingsType[] | null): string | null {
|
||||||
|
|||||||
@ -1,9 +1,7 @@
|
|||||||
import { Font as FontBase, parseFontFamily, genericFontFamilies, FontStyleType, FontWeight, FontWeightType, FontVariationSettingsType, FontVariationSettings } from './font-common';
|
import { Font as FontBase, parseFontFamily, genericFontFamilies, FontStyleType, FontWeight, FontWeightType, FontVariationSettingsType, FontVariationSettings } from './font-common';
|
||||||
import { Trace } from '../../trace';
|
import { Trace } from '../../trace';
|
||||||
import { SDK_VERSION } from '../../utils';
|
import { SDK_VERSION } from '../../utils';
|
||||||
import * as application from '../../application';
|
|
||||||
import * as fs from '../../file-system';
|
import * as fs from '../../file-system';
|
||||||
import { Trace } from '../../trace';
|
|
||||||
import { ad } from '../../utils';
|
import { ad } from '../../utils';
|
||||||
|
|
||||||
export * from './font-common';
|
export * from './font-common';
|
||||||
@ -17,7 +15,7 @@ export class Font extends FontBase {
|
|||||||
|
|
||||||
private _typeface: android.graphics.Typeface;
|
private _typeface: android.graphics.Typeface;
|
||||||
|
|
||||||
constructor(family: string, size: number, style?: FontStyleType, weight?: FontWeightType, fontVariationSettings?: FontVariationSettingsType[]) {
|
constructor(family: string, size: number, style?: FontStyleType, weight?: FontWeightType, fontVariationSettings?: Array<FontVariationSettingsType>) {
|
||||||
super(family, size, style, weight, 1, fontVariationSettings);
|
super(family, size, style, weight, 1, fontVariationSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +39,7 @@ export class Font extends FontBase {
|
|||||||
return new Font(this.fontFamily, this.fontSize, this.fontStyle, this.fontWeight, this.fontVariationSettings);
|
return new Font(this.fontFamily, this.fontSize, this.fontStyle, this.fontWeight, this.fontVariationSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public withFontVariationSettings(variationSettings: FontVariationSettingsType[] | null): Font {
|
public withFontVariationSettings(variationSettings: Array<FontVariationSettingsType> | null): Font {
|
||||||
return new Font(this.fontFamily, this.fontSize, this.fontStyle, this.fontWeight, variationSettings);
|
return new Font(this.fontFamily, this.fontSize, this.fontStyle, this.fontWeight, variationSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
10
packages/core/ui/styling/font.d.ts
vendored
10
packages/core/ui/styling/font.d.ts
vendored
@ -49,14 +49,14 @@ export namespace FontWeight {
|
|||||||
export function parse(value: string): FontWeightType;
|
export function parse(value: string): FontWeightType;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FontVariationSettings {
|
export type FontVariationSettingsType = {
|
||||||
axis: string;
|
axis: string;
|
||||||
value: number;
|
value: number;
|
||||||
}
|
};
|
||||||
|
|
||||||
export namespace FontVariationSettings {
|
export namespace FontVariationSettings {
|
||||||
export function parse(fontVariationSettings: string): FontVariationSettings[] | null;
|
export function parse(fontVariationSettings: string): Array<FontVariationSettingsType> | null;
|
||||||
export function toString(fontVariationSettings: FontVariationSettings[] | null): string | null;
|
export function toString(fontVariationSettings: Array<FontVariationSettingsType> | null): string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ParsedFont {
|
export interface ParsedFont {
|
||||||
@ -66,7 +66,7 @@ export interface ParsedFont {
|
|||||||
lineHeight?: string;
|
lineHeight?: string;
|
||||||
fontSize?: string;
|
fontSize?: string;
|
||||||
fontFamily?: string;
|
fontFamily?: string;
|
||||||
fontVariationSettings?: FontVariationSettings[];
|
fontVariationSettings?: Array<FontVariationSettingsType>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseFont(fontValue: string): ParsedFont;
|
export function parseFont(fontValue: string): ParsedFont;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { Font as FontBase, parseFontFamily, FontWeight, FontStyleType, FontWeightType, FontVariationSettingsType, FontVariationSettings } from './font-common';
|
import { Font as FontBase, parseFontFamily, FontWeight, FontStyleType, FontWeightType, FontVariationSettingsType, FontVariationSettings, fuzzySearch } from './font-common';
|
||||||
import { Trace } from '../../trace';
|
import { Trace } from '../../trace';
|
||||||
import * as fs from '../../file-system';
|
import * as fs from '../../file-system';
|
||||||
export * from './font-common';
|
export * from './font-common';
|
||||||
@ -7,7 +7,7 @@ interface FontDescriptor {
|
|||||||
fontFamily: string[];
|
fontFamily: string[];
|
||||||
fontSize: number;
|
fontSize: number;
|
||||||
fontWeight: number;
|
fontWeight: number;
|
||||||
fontVariationSettings: FontVariationSettingsType[] | null;
|
fontVariationSettings: Array<FontVariationSettingsType> | null;
|
||||||
isBold: boolean;
|
isBold: boolean;
|
||||||
isItalic: boolean;
|
isItalic: boolean;
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ function getUIFontCached(fontDescriptor: FontDescriptor) {
|
|||||||
export class Font extends FontBase {
|
export class Font extends FontBase {
|
||||||
public static default = new Font(undefined, undefined);
|
public static default = new Font(undefined, undefined);
|
||||||
|
|
||||||
constructor(family: string, size: number, style?: FontStyleType, weight?: FontWeightType, scale?: number, variationSettings?: FontVariationSettingsType[]) {
|
constructor(family: string, size: number, style?: FontStyleType, weight?: FontWeightType, scale?: number, variationSettings?: Array<FontVariationSettingsType>) {
|
||||||
super(family, size, style, weight, scale, variationSettings);
|
super(family, size, style, weight, scale, variationSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ export class Font extends FontBase {
|
|||||||
return new Font(this.fontFamily, this.fontSize, this.fontStyle, this.fontWeight, scale, this.fontVariationSettings);
|
return new Font(this.fontFamily, this.fontSize, this.fontStyle, this.fontWeight, scale, this.fontVariationSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public withFontVariationSettings(variationSettings: FontVariationSettingsType[] | null): Font {
|
public withFontVariationSettings(variationSettings: Array<FontVariationSettingsType> | null): Font {
|
||||||
return new Font(this.fontFamily, this.fontSize, this.fontStyle, this.fontWeight, this.fontScale, variationSettings);
|
return new Font(this.fontFamily, this.fontSize, this.fontStyle, this.fontWeight, this.fontScale, variationSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import { Style } from '../styling/style';
|
|||||||
import { Transformation, TransformationValue, TransformFunctionsInfo } from '../animation';
|
import { Transformation, TransformationValue, TransformFunctionsInfo } from '../animation';
|
||||||
|
|
||||||
import { Color } from '../../color';
|
import { Color } from '../../color';
|
||||||
import { Font, parseFont, FontStyle, FontWeight, FontVariationSettings } from '../../ui/styling/font';
|
import { Font, parseFont, FontStyle, FontWeight, FontVariationSettings, FontVariationSettingsType } from '../../ui/styling/font';
|
||||||
import { layout, hasDuplicates } from '../../utils';
|
import { layout, hasDuplicates } from '../../utils';
|
||||||
import { Background } from '../../ui/styling/background';
|
import { Background } from '../../ui/styling/background';
|
||||||
|
|
||||||
@ -1424,7 +1424,7 @@ const fontProperty = new ShorthandProperty<Style, string>({
|
|||||||
});
|
});
|
||||||
fontProperty.register(Style);
|
fontProperty.register(Style);
|
||||||
|
|
||||||
export const fontVariationSettingsProperty = new InheritedCssProperty<Style, FontVariationSettings[] | null>({
|
export const fontVariationSettingsProperty = new InheritedCssProperty<Style, Array<FontVariationSettingsType> | null>({
|
||||||
name: 'fontVariationSettings',
|
name: 'fontVariationSettings',
|
||||||
cssName: 'font-variation-settings',
|
cssName: 'font-variation-settings',
|
||||||
affectsLayout: global.isIOS,
|
affectsLayout: global.isIOS,
|
||||||
|
|||||||
Reference in New Issue
Block a user