mirror of
https://github.com/slidevjs/rough-notation.git
synced 2026-01-14 17:44:21 +01:00
feat: improve build tools, expose types
This commit is contained in:
4
src/constants.ts
Normal file
4
src/constants.ts
Normal 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
2
src/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './types'
|
||||
export * from './rough-notation'
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
Reference in New Issue
Block a user