fabric
Version:
Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.
1 lines • 2.48 kB
Source Map (JSON)
{"version":3,"file":"loadSVGFromString.mjs","sources":["../../../src/parser/loadSVGFromString.ts"],"sourcesContent":["import { getFabricWindow } from '../env';\nimport type { LoadImageOptions } from '../util/misc/objectEnlive';\nimport { parseSVGDocument } from './parseSVGDocument';\nimport type { SVGParsingOutput, TSvgReviverCallback } from './typedefs';\n\n/**\n * Takes string corresponding to an SVG document, and parses it into a set of fabric objects\n * @memberOf fabric\n * @param {String} string representing the svg\n * @param {TSvgParsedCallback} callback Invoked when the parsing is done, with null if parsing wasn't possible with the list of svg nodes.\n * {@link TSvgParsedCallback} also receives `allElements` array as the last argument. This is the full list of svg nodes available in the document.\n * You may want to use it if you are trying to regroup the objects as they were originally grouped in the SVG. ( This was the reason why it was added )\n * @param {TSvgReviverCallback} [reviver] Extra callback for further parsing of SVG elements, called after each fabric object has been created.\n * Takes as input the original svg element and the generated `FabricObject` as arguments. Used to inspect extra properties not parsed by fabric,\n * or extra custom manipulation\n * @param {Object} [options] Object containing options for parsing\n * @param {String} [options.crossOrigin] crossOrigin setting to use for external resources\n * @param {AbortSignal} [options.signal] handle aborting, see https://developer.mozilla.org/en-US/docs/Web/API/AbortController/signal\n */\nexport function loadSVGFromString(\n string: string,\n reviver?: TSvgReviverCallback,\n options?: LoadImageOptions,\n): Promise<SVGParsingOutput> {\n const parser = new (getFabricWindow().DOMParser)(),\n // should we use `image/svg+xml` here?\n doc = parser.parseFromString(string.trim(), 'text/xml');\n return parseSVGDocument(doc, reviver, options);\n}\n"],"names":["loadSVGFromString","string","reviver","options","parser","getFabricWindow","DOMParser","doc","parseFromString","trim","parseSVGDocument"],"mappings":";;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,iBAAiBA,CAC/BC,MAAc,EACdC,OAA6B,EAC7BC,OAA0B,EACC;EAC3B,MAAMC,MAAM,GAAG,KAAKC,eAAe,EAAE,CAACC,SAAS,GAAG;AAChD;AACAC,IAAAA,GAAG,GAAGH,MAAM,CAACI,eAAe,CAACP,MAAM,CAACQ,IAAI,EAAE,EAAE,UAAU,CAAC,CAAA;AACzD,EAAA,OAAOC,gBAAgB,CAACH,GAAG,EAAEL,OAAO,EAAEC,OAAO,CAAC,CAAA;AAChD;;;;"}