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

refactor: default exports were replaced with named #1619

Merged
merged 1 commit into from Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 9 additions & 6 deletions README.md
Expand Up @@ -46,8 +46,8 @@ npm i canvg
Basic module exports:

```js
export default Canvg;
export {
Canvg,
presets
};
```
Expand All @@ -57,7 +57,7 @@ export {
### Example

```js
import Canvg from 'canvg';
import { Canvg } from 'canvg';

let v = null;

Expand All @@ -82,7 +82,8 @@ window.onbeforeunload = () => {
</summary>

```js
import Canvg, {
import {
Canvg,
presets
} from 'canvg';

Expand Down Expand Up @@ -126,7 +127,8 @@ import {
} from 'xmldom';
import * as canvas from 'canvas';
import fetch from 'node-fetch';
import Canvg, {
import {
Canvg,
presets
} from 'canvg';

Expand Down Expand Up @@ -163,7 +165,8 @@ const preset = presets.node({
</summary>

```js
import Canvg, {
import {
Canvg,
presets
} from 'canvg';

Expand Down Expand Up @@ -206,7 +209,7 @@ self.onmessage = async (event) => {

```html
<script type="module">
import Canvg from 'https://cdn.skypack.dev/canvg';
import { Canvg } from 'https://cdn.skypack.dev/canvg';

window.onload = () => {
const canvas = document.querySelector('canvas');
Expand Down
2 changes: 1 addition & 1 deletion src/BoundingBox.ts
@@ -1,5 +1,5 @@

export default class BoundingBox {
export class BoundingBox {
constructor(
public x1 = Number.NaN,
public y1 = Number.NaN,
Expand Down
12 changes: 7 additions & 5 deletions src/Canvg.ts
@@ -1,11 +1,13 @@
import { RenderingContext2D } from './types'
import Parser, { IParserOptions } from './Parser'
import Screen, {
import { IParserOptions, Parser } from './Parser'
import {
IScreenOptions,
IScreenStartOptions
IScreenStartOptions,
Screen
} from './Screen'
import Document, {
import {
IDocumentOptions,
Document,
SVGElement
} from './Document'

Expand All @@ -19,7 +21,7 @@ export interface IOptions extends IParserOptions,
/**
* SVG renderer on canvas.
*/
export default class Canvg {
export class Canvg {
/**
* Create Canvg instance from SVG source string or URL.
* @param ctx - Rendering context.
Expand Down
14 changes: 7 additions & 7 deletions src/Document/AElement.ts
@@ -1,12 +1,12 @@
import { RenderingContext2D } from '../types'
import Property from '../Property'
import Font from '../Font'
import BoundingBox from '../BoundingBox'
import Document from './Document'
import TextElement from './TextElement'
import GElement from './GElement'
import { Property } from '../Property'
import { Font } from '../Font'
import { BoundingBox } from '../BoundingBox'
import { Document } from './Document'
import { TextElement } from './TextElement'
import { GElement } from './GElement'

export default class AElement extends TextElement {
export class AElement extends TextElement {
type = 'a'
protected readonly hasText: boolean
protected readonly text: string
Expand Down
4 changes: 2 additions & 2 deletions src/Document/AnimateColorElement.ts
@@ -1,7 +1,7 @@
import RGBColor from 'rgbcolor'
import AnimateElement from './AnimateElement'
import { AnimateElement } from './AnimateElement'

export default class AnimateColorElement extends AnimateElement {
export class AnimateColorElement extends AnimateElement {
type = 'animateColor'

calcValue() {
Expand Down
8 changes: 4 additions & 4 deletions src/Document/AnimateElement.ts
@@ -1,14 +1,14 @@
import Property from '../Property'
import Document from './Document'
import Element from './Element'
import { Property } from '../Property'
import { Document } from './Document'
import { Element } from './Element'

export interface IProgress {
from?: Property
to?: Property
progress: number
}

export default class AnimateElement extends Element {
export class AnimateElement extends Element {
type = 'animate'
protected readonly begin: number
protected readonly maxDuration: number
Expand Down
4 changes: 2 additions & 2 deletions src/Document/AnimateTransformElement.ts
@@ -1,7 +1,7 @@
import { toNumbers } from '../util'
import AnimateElement from './AnimateElement'
import { AnimateElement } from './AnimateElement'

export default class AnimateTransformElement extends AnimateElement {
export class AnimateTransformElement extends AnimateElement {
type = 'animateTransform'

calcValue() {
Expand Down
6 changes: 3 additions & 3 deletions src/Document/CircleElement.ts
@@ -1,8 +1,8 @@
import { RenderingContext2D } from '../types'
import BoundingBox from '../BoundingBox'
import PathElement from './PathElement'
import { BoundingBox } from '../BoundingBox'
import { PathElement } from './PathElement'

export default class CircleElement extends PathElement {
export class CircleElement extends PathElement {
type = 'circle'

path(ctx: RenderingContext2D) {
Expand Down
8 changes: 4 additions & 4 deletions src/Document/ClipPathElement.ts
@@ -1,13 +1,13 @@
import { RenderingContext2D } from '../types'
import Transform from '../Transform'
import Element from './Element'
import UseElement from './UseElement'
import { Transform } from '../Transform'
import { Element } from './Element'
import { UseElement } from './UseElement'

const noop = () => {
// NOOP
}

export default class ClipPathElement extends Element {
export class ClipPathElement extends Element {
type = 'clipPath'

apply(ctx: RenderingContext2D) {
Expand Down
4 changes: 2 additions & 2 deletions src/Document/DefsElement.ts
@@ -1,6 +1,6 @@
import Element from './Element'
import { Element } from './Element'

export default class DefsElement extends Element {
export class DefsElement extends Element {
type = 'defs'

render() {
Expand Down
4 changes: 2 additions & 2 deletions src/Document/DescElement.ts
@@ -1,5 +1,5 @@
import Element from './Element'
import { Element } from './Element'

export default class DescElement extends Element {
export class DescElement extends Element {
type = 'desc'
}
25 changes: 14 additions & 11 deletions src/Document/Document.ts
@@ -1,14 +1,17 @@
/* eslint-disable @typescript-eslint/no-use-before-define */
import Canvg from '../Canvg'
import Screen, { IScreenViewBoxConfig } from '../Screen'
import Property from '../Property'
import SVGFontLoader from '../SVGFontLoader'
import Element from './Element'
import UnknownElement from './UnknownElement'
import TextNode from './TextNode'
import ImageElement from './ImageElement'
import SVGElement from './SVGElement'
import elementTypes, { AnyElement } from './elements'
import { Canvg } from '../Canvg'
import { IScreenViewBoxConfig, Screen } from '../Screen'
import { Property } from '../Property'
import { SVGFontLoader } from '../SVGFontLoader'
import { Element } from './Element'
import { UnknownElement } from './UnknownElement'
import { TextNode } from './TextNode'
import { ImageElement } from './ImageElement'
import { SVGElement } from './SVGElement'
import {
AnyElement,
elements as elementTypes
} from './elements'

/**
* Function to create new canvas.
Expand Down Expand Up @@ -76,7 +79,7 @@ async function createImage(src: string, anonymousCrossOrigin = false) {
})
}

export default class Document {
export class Document {
static readonly createCanvas = createCanvas
static readonly createImage = createImage
static readonly elementTypes = elementTypes
Expand Down
18 changes: 9 additions & 9 deletions src/Document/Element.ts
@@ -1,14 +1,14 @@
import { RenderingContext2D } from '../types'
import { normalizeAttributeName } from '../util'
import Property from '../Property'
import Transform from '../Transform'
import Document from './Document'
import ClipPathElement from './ClipPathElement'
import MaskElement from './MaskElement'
import FilterElement from './FilterElement'
import PathElement from './PathElement'

export default abstract class Element {
import { Property } from '../Property'
import { Transform } from '../Transform'
import { Document } from './Document'
import { ClipPathElement } from './ClipPathElement'
import { MaskElement } from './MaskElement'
import { FilterElement } from './FilterElement'
import { PathElement } from './PathElement'

export abstract class Element {
static readonly ignoreChildTypes = ['title']

readonly type: string
Expand Down
6 changes: 3 additions & 3 deletions src/Document/EllipseElement.ts
@@ -1,8 +1,8 @@
import { RenderingContext2D } from '../types'
import BoundingBox from '../BoundingBox'
import PathElement from './PathElement'
import { BoundingBox } from '../BoundingBox'
import { PathElement } from './PathElement'

export default class EllipseElement extends PathElement {
export class EllipseElement extends PathElement {
type = 'ellipse'

path(ctx: RenderingContext2D) {
Expand Down
6 changes: 3 additions & 3 deletions src/Document/FeColorMatrixElement.ts
@@ -1,7 +1,7 @@
import { RenderingContext2D } from '../types'
import { toNumbers } from '../util'
import Document from './Document'
import Element from './Element'
import { Document } from './Document'
import { Element } from './Element'

function imGet(
img: Uint8ClampedArray,
Expand Down Expand Up @@ -45,7 +45,7 @@ function c(
return m1 + Math.cos(a) * m2 + Math.sin(a) * m3
}

export default class FeColorMatrixElement extends Element {
export class FeColorMatrixElement extends Element {
type = 'feColorMatrix'
protected readonly matrix: number[]
protected readonly includeOpacity: boolean
Expand Down
4 changes: 2 additions & 2 deletions src/Document/FeCompositeElement.ts
@@ -1,7 +1,7 @@
import { RenderingContext2D } from '../types'
import Element from './Element'
import { Element } from './Element'

export default class FeCompositeElement extends Element {
export class FeCompositeElement extends Element {
type = 'feComposite'

apply(
Expand Down
6 changes: 3 additions & 3 deletions src/Document/FeDropShadowElement.ts
@@ -1,8 +1,8 @@
import { RenderingContext2D } from '../types'
import Document from './Document'
import Element from './Element'
import { Document } from './Document'
import { Element } from './Element'

export default class FeDropShadowElement extends Element {
export class FeDropShadowElement extends Element {
type = 'feDropShadow'

constructor(
Expand Down
6 changes: 3 additions & 3 deletions src/Document/FeGaussianBlurElement.ts
@@ -1,9 +1,9 @@
import { canvasRGBA } from 'stackblur-canvas'
import { RenderingContext2D } from '../types'
import Document from './Document'
import Element from './Element'
import { Document } from './Document'
import { Element } from './Element'

export default class FeGaussianBlurElement extends Element {
export class FeGaussianBlurElement extends Element {
type = 'feGaussianBlur'
readonly extraFilterDistance: number
protected readonly blurRadius: number
Expand Down
4 changes: 2 additions & 2 deletions src/Document/FeMorphologyElement.ts
@@ -1,7 +1,7 @@
import { RenderingContext2D } from '../types'
import Element from './Element'
import { Element } from './Element'

export default class FeMorphologyElement extends Element {
export class FeMorphologyElement extends Element {
type = 'feMorphology'

apply(
Expand Down
8 changes: 4 additions & 4 deletions src/Document/FilterElement.ts
@@ -1,9 +1,9 @@
import { RenderingContext2D } from '../types'
import Element from './Element'
import PathElement from './PathElement'
import FeGaussianBlurElement from './FeGaussianBlurElement'
import { Element } from './Element'
import { PathElement } from './PathElement'
import { FeGaussianBlurElement } from './FeGaussianBlurElement'

export default class FilterElement extends Element {
export class FilterElement extends Element {
static ignoreStyles = [
'filter',
'transform',
Expand Down
12 changes: 6 additions & 6 deletions src/Document/FontElement.ts
@@ -1,10 +1,10 @@
import Document from './Document'
import Element from './Element'
import FontFaceElement from './FontFaceElement'
import MissingGlyphElement from './MissingGlyphElement'
import GlyphElement from './GlyphElement'
import { Document } from './Document'
import { Element } from './Element'
import { FontFaceElement } from './FontFaceElement'
import { MissingGlyphElement } from './MissingGlyphElement'
import { GlyphElement } from './GlyphElement'

export default class FontElement extends Element {
export class FontElement extends Element {
type = 'font'
readonly isArabic: boolean
readonly missingGlyph: MissingGlyphElement
Expand Down
6 changes: 3 additions & 3 deletions src/Document/FontFaceElement.ts
@@ -1,7 +1,7 @@
import Document from './Document'
import Element from './Element'
import { Document } from './Document'
import { Element } from './Element'

export default class FontFaceElement extends Element {
export class FontFaceElement extends Element {
type = 'font-face'
readonly ascent: number
readonly descent: number
Expand Down
8 changes: 4 additions & 4 deletions src/Document/GElement.ts
@@ -1,9 +1,9 @@
import { RenderingContext2D } from '../types'
import BoundingBox from '../BoundingBox'
import PathElement from './PathElement'
import RenderedElement from './RenderedElement'
import { BoundingBox } from '../BoundingBox'
import { PathElement } from './PathElement'
import { RenderedElement } from './RenderedElement'

export default class GElement extends RenderedElement {
export class GElement extends RenderedElement {
type = 'g'

getBoundingBox(ctx: RenderingContext2D) {
Expand Down