pencil.js
Version:
Nice modular interactive 2D drawing library.
121 lines (120 loc) • 3.12 kB
TypeScript
/**
* Background pattern filing
* @class
*/
export default class Pattern {
/**
* @typedef {Object} PatternOptions
* @prop {String} [repeat=Pattern.repetition.repeat] - Repetition rule
* @prop {PositionDefinition} [origin=new Position()] - Relative offset
* @prop {Number|PositionDefinition} [scale=1] - Scaling ratio or a pair of value for horizontal and vertical scaling
*/
/**
* @return {PatternOptions}
*/
static get defaultOptions(): {
/**
* - Repetition rule
*/
repeat?: string;
/**
* - Relative offset
*/
origin?: PositionDefinition;
/**
* - Scaling ratio or a pair of value for horizontal and vertical scaling
*/
scale?: number | PositionDefinition;
};
/**
* @typedef {Object} PatternRepetitions
* @prop {String} repeat -
* @prop {String} x -
* @prop {String} y -
* @prop {String} none -
*/
/**
* @return {PatternRepetitions}
*/
static get repetition(): {
/**
* -
*/
repeat: string;
/**
* -
*/
x: string;
/**
* -
*/
y: string;
/**
* -
*/
none: string;
};
/**
* Pattern constructor
* @param {HTMLImageElement|Image|HTMLCanvasElement|OffScreenCanvas} source - Source of the pattern
* @param {PatternOptions} options - Some options
*/
constructor(source: HTMLImageElement | Image | HTMLCanvasElement | OffScreenCanvas, options: {
/**
* - Repetition rule
*/
repeat?: string;
/**
* - Relative offset
*/
origin?: PositionDefinition;
/**
* - Scaling ratio or a pair of value for horizontal and vertical scaling
*/
scale?: number | PositionDefinition;
});
options: {
/**
* - Repetition rule
*/
repeat?: string;
/**
* - Relative offset
*/
origin?: PositionDefinition;
/**
* - Scaling ratio or a pair of value for horizontal and vertical scaling
*/
scale?: number | PositionDefinition;
};
/**
* @param {HTMLImageElement|Image} newSource - New source for the pattern
*/
set source(newSource: HTMLImageElement | Image);
/**
* @return {HTMLImageElement}
*/
get source(): HTMLImageElement;
/**
* @return {Number}
*/
get width(): number;
/**
* @return {Number}
*/
get height(): number;
/**
* Return the pattern object
* @param {CanvasRenderingContext2D} ctx - Drawing context
* @return {CanvasPattern}
*/
toString(ctx: CanvasRenderingContext2D): CanvasPattern;
[sourceKey]: HTMLImageElement | (Image & HTMLCanvasElement) | (Image & OffScreenCanvas);
}
import Image from "@pencil.js/image";
/**
* @module Pattern
*/
declare const sourceKey: unique symbol;
import OffScreenCanvas from "@pencil.js/offscreen-canvas";
export {};