Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript Declaration #2

Open
ariutta opened this issue Mar 10, 2017 · 1 comment
Open

TypeScript Declaration #2

ariutta opened this issue Mar 10, 2017 · 1 comment

Comments

@ariutta
Copy link

ariutta commented Mar 10, 2017

Hello,

I found this library useful and wrote up a TypeScript declaration for it. Would you like to include it in this library?

// TODO how does CSSProperties compare to CSSStyleDeclaration from typescript's lib.dom.d.ts?
import {CSSProperties} from 'typestyle/lib/types';

interface NonNestedPlainObject {
		// TODO should this include null and/or undefined?
		[key: string]: string | number | boolean;
}

export interface SvgTextOpts {
		text: string;

		// TODO the definition for document.getElementById incorrectly says it only returns HTMLElement,
		// but 'element' below should really be just SVGElement. The union with HTMLElement is a kludge.
		element?: SVGElement | HTMLElement;
		// 'svg' below should really be just SVGSVGElement. See comment above.
		svg?: SVGSVGElement | HTMLElement;

		x?: number; // default: 0
		y?: number; // default: 0
		width?: number; // default: 'auto'
		height?: number; // default: 'auto'
		maxWidth?: number; // default: 'auto'
		maxHeight?: number; // default: 'auto'
		outerWidth?: number; // default: 'auto'
		outerHeight?: number; // default: 'auto'
		maxLines?: number; // default: Infinity
		align?: 'left' | 'center' | 'right'; // default: 'left'
		verticalAlign?: 'top' | 'middle' | 'bottom'; // default: 'top'
		textOverflow: 'ellipsis' | 'clip' | string;
		selectorNamespace?: string;
		className?: string;
		style?: CSSProperties;
		styleElement?: HTMLStyleElement; // default: first style element
		attrs?: NonNestedPlainObject; // TODO what should the type be?
		rect?: NonNestedPlainObject;
		padding?: number | string;
		margin?: number | string;
}

export default class SvgText {
		svg: SVGSVGElement;
		style: HTMLStyleElement;
		constructor(svgTextOpts: SvgTextOpts)
		writeStyle(selector: string, css: CSSProperties, style: HTMLStyleElement)
		forIllustrator(textWeb: SVGTextElement, textAi: SVGTextElement, postScriptFontName: string)
}

export interface SvgUtil {
		toJs(prop: string): keyof CSSProperties;
		toCss(prop: keyof CSSProperties): string;

		// TODO neither lib.dom.ts nor typestyle types have the CSS formatted properties, e.g.,
		// {"vertical-align": 'baseline' | 'sub' | ...},
		// but that's what NonNestedPlainObject should actually be here.
		normalizeKeys(object: CSSProperties | NonNestedPlainObject, style: 'css' | 'js'): NonNestedPlainObject | CSSProperties; // style default: 'css'


		// TODO this should actually be something like "keyof SVGElementTagNameMap", but that doesn't exist in lib.dom.d.ts
		createElement<K extends keyof ElementTagNameMap>(name: K, attrs: NonNestedPlainObject): ElementTagNameMap[K] & SVGElement;

		isPosNum(value: any): boolean;
		minNum(...params: any[]): number | 'auto';
		maxNum(...params: any[]): number | 'auto';
		autoNum(value: string | number, altNum: number): number;
		toArrayLen4(value: number | undefined | null | string): [number, number, number, number];
}
@adrianlafond
Copy link
Contributor

Thanks! Sorry for the horrifically tardy reply. I'll look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants