feat: improve build tools, expose types

This commit is contained in:
Anthony Fu
2024-02-21 11:41:57 +01:00
parent 668ba82ac8
commit a540447a45
9 changed files with 2030 additions and 527 deletions

4
src/constants.ts Normal file
View File

@@ -0,0 +1,4 @@
export const SVG_NS = 'http://www.w3.org/2000/svg';
export const DEFAULT_ANIMATION_DURATION = 800;

2
src/index.ts Normal file
View File

@@ -0,0 +1,2 @@
export * from './types'
export * from './rough-notation'

View File

@@ -1,12 +1,25 @@
import { Rect, RoughAnnotationConfig, SVG_NS, FullPadding, BracketType } from './model.js';
import { SVG_NS } from './constants'
import { Rect, RoughAnnotationConfig, FullPadding, BracketType } from "./types";
import { ResolvedOptions, OpSet } from 'roughjs/bin/core';
import { line, rectangle, ellipse, linearPath } from 'roughjs/bin/renderer';
import { RoughGenerator } from 'roughjs/bin/generator';
import { Point } from 'roughjs/bin/geometry';
type RoughOptionsType = 'highlight' | 'single' | 'double';
let defaultOptions: ResolvedOptions | null = null;
function getDefaultOptions(): ResolvedOptions {
if (!defaultOptions) {
const gen = new RoughGenerator();
defaultOptions = gen.defaultOptions;
}
return defaultOptions;
}
function getOptions(type: RoughOptionsType, seed: number): ResolvedOptions {
return {
...getDefaultOptions(),
maxRandomnessOffset: 2,
roughness: type === 'highlight' ? 3 : 1.5,
bowing: 1,
@@ -22,7 +35,7 @@ function getOptions(type: RoughOptionsType, seed: number): ResolvedOptions {
dashOffset: -1,
dashGap: -1,
zigzagOffset: -1,
combineNestedSvgPaths: false,
// combineNestedSvgPaths: false,
disableMultiStroke: type !== 'double',
disableMultiStrokeFill: false,
seed
@@ -262,4 +275,4 @@ function opsToPath(opList: OpSet[]): string[] {
}
}
return paths;
}
}

View File

@@ -1,10 +1,9 @@
import { Rect, RoughAnnotationConfig, RoughAnnotation, SVG_NS, RoughAnnotationGroup, DEFAULT_ANIMATION_DURATION } from './model.js';
import { SVG_NS, DEFAULT_ANIMATION_DURATION } from './constants';
import { Rect, RoughAnnotationConfig, RoughAnnotation, RoughAnnotationGroup, AnnotationState } from "./types";
import { renderAnnotation } from './render.js';
import { ensureKeyframes } from './keyframes.js';
import { randomSeed } from 'roughjs/bin/math';
type AnnotationState = 'unattached' | 'not-showing' | 'showing';
class RoughAnnotationImpl implements RoughAnnotation {
private _state: AnnotationState = 'unattached';
private _config: RoughAnnotationConfig;
@@ -276,4 +275,4 @@ export function annotationGroup(annotations: RoughAnnotation[]): RoughAnnotation
}
}
};
}
}

View File

@@ -1,7 +1,3 @@
export const SVG_NS = 'http://www.w3.org/2000/svg';
export const DEFAULT_ANIMATION_DURATION = 800;
export interface Rect {
x: number;
y: number;
@@ -22,7 +18,7 @@ export interface RoughAnnotationConfig extends RoughAnnotationConfigBase {
export interface RoughAnnotationConfigBase {
animate?: boolean; // defaults to true
animationDuration?: number; // defaulst to 1000ms
animationDuration?: number; // defaults to 1000ms
color?: string; // defaults to currentColor
strokeWidth?: number; // default based on type
padding?: RoughPadding; // defaults to 5px
@@ -40,4 +36,6 @@ export interface RoughAnnotation extends RoughAnnotationConfigBase {
export interface RoughAnnotationGroup {
show(): void;
hide(): void;
}
}
export type AnnotationState = 'unattached' | 'not-showing' | 'showing';