@fabwcie/free-drawing / utils/library
utils/library
Classes
Library
Defined in: packages/free-drawing/src/utils/library.ts:88
Library of a drawer (drawer.library): shapes saved as items (add) inserted again in any drawing (insert), kept in the browser (<localStorageKey>-library, shared by the drawings of the drawer), exported and imported as .freedrawinglib files; library.change event on each change
Constructors
Constructor
new Library(
drawer):Library
Defined in: packages/free-drawing/src/utils/library.ts:100
Library kept in the browser
Parameters
drawer
Drawer whose shapes are saved and receiving the inserted ones
Returns
Properties
drawer
drawer:
Drawer
Defined in: packages/free-drawing/src/utils/library.ts:90
Drawer whose shapes are saved and receiving the inserted ones
Accessors
items
Get Signature
get items(): readonly
LibraryItem[]
Defined in: packages/free-drawing/src/utils/library.ts:119
Items of the library, oldest first
Returns
readonly LibraryItem[]
Items (not to modify: use add, remove, rename, setItems)
Methods
_changed()
private_changed():void
Defined in: packages/free-drawing/src/utils/library.ts:389
Library changed: kept in the browser (toast when the storage is full), library.change event
Returns
void
_defaultName()
private_defaultName(shapes):string
Defined in: packages/free-drawing/src/utils/library.ts:406
Name of a new item: the first line of the text of its shape or the name of its shape, else its number of shapes
Parameters
shapes
Saved shapes
Returns
string
Name in the current language
_forget()
_forget():
void
Defined in: packages/free-drawing/src/utils/library.ts:358
Items forgotten with the library removed from the browser (Drawer.clearStoredData): nothing written, library.change event
Returns
void
_key()
private_key():string
Defined in: packages/free-drawing/src/utils/library.ts:368
Key of the library in the browser storage: shared by the drawings of the drawer
Returns
string
localStorage key
_read()
private_read():LibraryItem[]
Defined in: packages/free-drawing/src/utils/library.ts:376
Items kept in the browser
Returns
Valid items, none when missing or invalid
add()
add(
shapes?,name?):LibraryItem|null
Defined in: packages/free-drawing/src/utils/library.ts:129
Save shapes as a new item: the shapes, their texts, groups and frames with their shapes, files of their images
Parameters
shapes?
DrawingShape[] = ...
Shapes to save (selection by default)
name?
string
Name of the item, by default the name of its shape (its text) or the number of its shapes
Returns
LibraryItem | null
New item, null without shape
exportFile()
exportFile(
name?):Promise<void>
Defined in: packages/free-drawing/src/utils/library.ts:340
Save the library in a .freedrawinglib file, with the save dialog of the browser when available, else downloaded
Parameters
name?
string = 'library'
File name without extension
Returns
Promise<void>
getPreview()
getPreview(
item):string
Defined in: packages/free-drawing/src/utils/library.ts:268
Preview of an item: svg image of its shapes (fonts of the page not loaded in it), kept until the item is removed
Parameters
item
Item of the library
Returns
string
Data URL of the svg image
import()
import(
json):number
Defined in: packages/free-drawing/src/utils/library.ts:307
Add the items of a library file, items already in the library (same id) left out
Parameters
json
string
Content of a .freedrawinglib file
Returns
number
Number of items added
Throws
not a library file
importFile()
importFile():
Promise<void>
Defined in: packages/free-drawing/src/utils/library.ts:321
Import a library file chosen by the user, toast of the items added or of the error
Returns
Promise<void>
insert()
insert(
item,center?):DrawingShape[]
Defined in: packages/free-drawing/src/utils/library.ts:199
Insert the shapes of an item in the drawing (new ids, links of its arrows and texts of its shapes kept between them), centered on a point, in the frame there, selected with the selection tool: one change
Parameters
item
string | LibraryItem
Item or its id
center?
Vector2d
Center of the inserted shapes in drawing coordinates, center of the view by default
Returns
Inserted shapes, none for an unknown item
remove()
remove(
id):void
Defined in: packages/free-drawing/src/utils/library.ts:160
Remove an item
Parameters
id
string
Id of the item
Returns
void
rename()
rename(
id,name):void
Defined in: packages/free-drawing/src/utils/library.ts:173
Rename an item
Parameters
id
string
Id of the item
name
string
New name (empty: name kept)
Returns
void
setItems()
setItems(
items):void
Defined in: packages/free-drawing/src/utils/library.ts:186
Replace the items (library of an app: account, server...), invalid ones left out
Parameters
items
Items of the library, oldest first
Returns
void
toFile()
toFile():
LibraryFile
Defined in: packages/free-drawing/src/utils/library.ts:297
Content of a library file of the items
Returns
Library file (.freedrawinglib JSON)
Variables
libraryDragType
constlibraryDragType:"application/x-free-drawing-library"='application/x-free-drawing-library'
Defined in: packages/free-drawing/src/utils/library.ts:24
Type of the data of an item of the library dragged onto the drawing
libraryFileExtension
constlibraryFileExtension:".freedrawinglib"='.freedrawinglib'
Defined in: packages/free-drawing/src/utils/library.ts:21
Extension of library files
Functions
parseLibraryFile()
parseLibraryFile(
json):LibraryItem[]
Defined in: packages/free-drawing/src/utils/library.ts:68
Items of a library file (or of the library kept in the browser)
Parameters
json
string
Content of a .freedrawinglib file
Returns
Valid items, invalid ones left out
Throws
not a library file
parseLibraryItem()
parseLibraryItem(
value):LibraryItem|null
Defined in: packages/free-drawing/src/utils/library.ts:41
Item of a library read from storage or a file (not trusted): only drawing shapes, as in drawing files
Parameters
value
unknown
Item to check
Returns
LibraryItem | null
Item with valid shapes and files, null without id or shapes