dom_tools
library
Classes
AnyUriPolicy
Allows anu Uri policy.
CanvasImageViewer
An image viewer that can render points, rectangles, clip and grid over.
Color
Represents a color.
CSSAnimationConfig
CSSAnimationConfigElements
CSS animation configuration for a List<Element> .
CSSAnimationConfigGroup
CSS animation configuration for a group of CSSAnimationConfig .
CSSThemeSet
A Theme set, with multiples themes.
CSSValueBase
DataAssets
A collections of assets (DataURL, Blob, MediaSource) that can be accessed
by an ObjectURL
, avoiding usage and encoding to data URL (base64).
DataStorage
Represents a persistent storage in the browser.
DOMTreeReferenceMap <V >
A TreeReferenceMap
for DOM Nodes.
FilterResult
Filter result.
HSLColor
A color represented using alpha , hue , saturation , and lightness .
HSVColor
A color represented using alpha , hue , saturation , and value .
ImagePerspectiveFilter
A filter that applies a perspective to an image.
ImagePerspectiveFilterCache
A cache for perspective filers.
ImageScaledCache
A cache for scaled images.
JSONObject
Base class for an Object that can be converted to JSON.
JSONTransformer
Label <T extends num >
State
A state stored in DataStorage .
StorageValue
Represents a value stored in State .
StyleColor
Specifies a CSS color.
TAsList
TAsMap
TAsString
Converts JSON node to a String .
TConcatenation
Concatenate transformations
TDecodeJSON
Converts JSON node decoding to a JSON tree.
TEncodeJSON
Converts JSON node encoding to a JSON String .
TextStyle
Specifies a CSS text style.
TListValue
Transforms JSON node to a List index value.
TLowerCase
Converts JSON node to a Lower Case String .
TMapEntry
Converts JSON node to a MapEntry .
TMapValue
Transforms JSON node to a Map key value.
TOperation
Base class for operations.
TrackElementInViewport
Tracks a DOM Element to identify when its visible in viewport.
TrackElementResize
Tracks a DOM Element to identify when its size changes.
TrackElementValue
Tracks a DOM Element to identify when a value changes.
TSplit
Converts JSON node, splitting to a List<String> .
TString
A text String .
TTrim
Converts JSON node to a Trimmed String .
TUpperCase
Converts JSON node to an Upper Case String .
ViewerElement <T >
Represents an element in the CanvasImageViewer .
Functions
addCSSCode (String cssCode )
→ Future <bool >
Adds a CSS code (cssCode
) into DOM.
addCssSource (String cssSource , {int ? insertIndex })
→ Future <bool >
Add a CSS path using a link
element into head
DOM node.
addElementsClasses (Iterable <Element > elements , Iterable <String > classes )
→ bool
Add to elements
a set of classes
. Will remove classes starting with '!'.
addJavaScriptCode (String scriptCode )
→ Future <bool >
Adds a JavaScript code (scriptCode
) into DOM.
addJavaScriptSource (String scriptSource , {bool addToBody = false , bool async = false })
→ Future <bool >
Adds a JavaScript path (scriptSource
] into DOM.
addJSFunction (String name , List <String > parameters , String body )
→ Future <bool >
Adds a JavaScript function into DOM.
animateCSSSequence (Iterable <CSSAnimationConfig > animationsConfig , {Duration ? initialDelay , int ? repeat , bool ? repeatInfinity })
→ Future <void > ?
Sames animateCSS
but runs animationsConfig
in sequence;
appendElementInnerHTML (Element element , String html , {NodeValidator ? validator })
→ void
Appends to the inner HTML of element
with parsed result of html
.
applyCSS (CssStyleDeclaration css , Element element , [ ])
→ bool
Applies css
to element
and extraElements
list if present.
applyPerspective (CanvasImageSource image , List <Point <num > > perspective )
→ FilterResult ?
Apply perspective
filter to image
.
asCssStyleDeclaration (dynamic css )
→ CssStyleDeclaration
Parses dynamic css
as CssStyleDeclaration .
blockHorizontalScrollTraverse (Element element )
→ void
Blocks a scroll event in the horizontal direction that traverses the element
.
blockHorizontalScrollTraverseEvent (Element element , WheelEvent wheelEvent )
→ bool
Blocks a wheelEvent
in the horizontal direction that traverses the element
.
blockScrollTraverse (Element element )
→ void
Blocks a scroll event in the vertical and horizontal directions that traverses the element
.
blockVerticalScrollTraverse (Element element )
→ void
Blocks a scroll event in the vertical direction that traverses the element
.
blockVerticalScrollTraverseEvent (Element element , WheelEvent wheelEvent )
→ bool
Blocks a wheelEvent
in the vertical direction that traverses the element
.
buildMetaContent (Map <String , String ? > map )
→ String
Builds a meta
content from map
.
callJSFunction (String method , [List ? args ])
→ dynamic
Calls JavaScript a function method
with args
.
callJSObjectMethod (Object o , String method , [List ? args ])
→ dynamic
Calls JavaScript a method
in object o
with args
.
canvasToImageElement (CanvasElement canvas , [String ? mimeType , num ? quality ])
→ ImageElement
Converts canvas
to ImageElement
clearSelections ()
→ void
Clears selected text in vieport.
copyElementToClipboard (Element element )
→ bool
Copies element
text to Clipboard.
copyPoints (List <Point <num > > points )
→ List <Point <num > >
Makes a copy of points
.
createDiv ([bool inline = false , String ? html , NodeValidator ? validator ])
→ DivElement
Creates a div
.
inline
If true
sets display: inline-block
.
html
The HTML to parse as content.
createDivInline ([String ? html ])
→ DivElement
Creates a div
with display: inline-block
.
createDivInlineBlock ()
→ DivElement
Creates a div
with display: inline-block
.
createHTML ([String ? html , NodeValidator ? validator ])
→ Element
Creates a HTML Element . Returns 1st node form parsed HTML.
createImageElementFromBase64 (String ? base64 , [String ? mimeType ])
→ ImageElement ?
Creates an image from a Base-64 with mimeType
.
createImageElementFromFile (File file )
→ Future <ImageElement >
Creates an image from a file
.
createLabel ([String ? html , NodeValidator ? validator ])
→ LabelElement
Creates a label
element.
createScaledImage (CanvasImageSource image , int width , int height , double scale )
→ CanvasImageSource
Creates a new image from image
, of width
and height
,
to a scale
.
createSpan ([String ? html , NodeValidator ? validator ])
→ SpanElement
Creates a span
element.
createStandardNodeValidator ({bool svg = true , bool allowSvgForeignObject = false })
→ NodeValidatorBuilder
cropImage (CanvasImageSource image , int x , int y , int width , int height )
→ CanvasElement ?
Crops the image
using coordinates x
, y
, width
and height
,
returning new image (CanvasElement ).
cropImageByRectangle (CanvasImageSource image , Rectangle <num > ? crop )
→ CanvasElement ?
Crops an image using a Rectangle (crop
),
delegating to method cropImage ,
dataURLToBlob (DataURLBase64 dataURL )
→ Blob
Converts a dataURL
to a Blob .
defineCSS (CssStyleDeclaration ? currentCSS , CssStyleDeclaration ? appendCSS , [dynamic defaultCSS ])
→ CssStyleDeclaration
Defines a new CssStyleDeclaration merging currentCSS
and appendCSS
.
detectTouchDevice ()
→ TouchDeviceDetection ?
Starts touch device detection. Returns the current status.
disableDoubleClicks ()
→ void
Disables browser double clicks/tap.
disableScrolling ()
→ void
Disables scrolling in browser.
disableZooming ()
→ void
Disables browser zooming.
downloadBlob (Blob blob , String fileName )
→ void
Downloads blob
of type mimeType
, saving a file with fileName
.
downloadBytes (List <int > bytes , MimeType mimeType , String fileName )
→ void
Downloads bytes
of type mimeType
, saving a file with fileName
.
downloadContent (List <String > content , MimeType mimeType , String fileName )
→ void
Downloads content
of type mimeType
, saving a file with fileName
.
downloadDataURL (DataURLBase64 dataURL , String fileName )
→ void
Downloads dataURL
, saving a file with fileName
.
elementMatchesAttribute (Element element , String attributeName , dynamic attributeValue )
→ bool
Returns true
if element
matches attributeName
and attributeValue
.
elementMatchesAttributes (Element element , Map <String , dynamic > attributes )
→ bool
Returns true
if element
matches attributes
.
elementOnLoad (ImageElement img )
→ Future <bool >
Returns a Future<bool> for when img
loads.
enableScrolling ()
→ void
Enables scrolling in browser.
evalJS (String scriptCode )
→ dynamic
Call eval()
with the content of scriptCode
and returns the result.
getAllCssRuleBySelector (Pattern targetSelector , CssStyleSheet ? sheet )
→ List <CssRule >
Returns a List<CssRule> for targetSelector
.
getAllCssStyleSheet ()
→ List <CssStyleSheet >
Returns all current CssStyleSheet .
getAllMediaCssRule (String mediaCondition )
→ List <CssMediaRule >
Returns a list of @media CssRule with mediaCondition
.
getAllOutOfViewportMediaCssRule (int viewportWidth , dynamic viewportHeight )
→ List <CssMediaRule >
Returns all CssMediaRule not applied for viewportWidth
and viewportHeight
.
getAllOutOfViewportMediaCssRuleAsClassRule (int viewportWidth , dynamic viewportHeight , String targetClass )
→ List <String >
Transforms all CssMediaRule to targetClass
rule not applied for viewportWidth
and viewportHeight
.
getAllViewportMediaCssRule (int viewportWidth , dynamic viewportHeight )
→ List <CssMediaRule >
Returns all CssMediaRule applied for viewportWidth
viewportHeight
.
getAllViewportMediaCssRuleAsClassRule (int viewportWidth , dynamic viewportHeight , String targetClass )
→ List <String >
Transforms all CssMediaRule to targetClass
rule applied for viewportWidth
and viewportHeight
.
getAnchorElementByHREF (String href )
→ AnchorElement ?
Selects an AnchorElement in DOM with href
.
getComputedStyle ({Element ? parent , Element ? element , String ? classes , String ? style , bool ? hidden })
→ CssStyleDeclaration
Returns a CssStyleDeclaration from an element.
getElementAllCssProperties (Element element )
→ List <String >
Returns a list of CSS properties associated with element
getElementAllCssRule (Element element )
→ List <CssRule >
Returns a list of CssRule associated with element
.
getElementAttribute (Element element , Object ? key )
→ String ?
Returns element
attribute with key
.
getElementAttributeRegExp (Element element , RegExp key )
→ String ?
Returns element
attribute with RegExp key
.
getElementAttributeStr (Element element , String key )
→ String ?
Returns element
attribute with String key
.
getElementByHREF (String tag , String href )
→ Element ?
Selects an Element in DOM with tag
and href
.
getElementBySRC (String tag , String src )
→ Element ?
Selects an Element in DOM with tag
and src
.
getElementByValues <V > (String tag , ElementValueGetter getter , List <V > values , [ElementValueGetter ? getter2 , List <V > ? values2 ])
→ Element ?
selects in DOM an Element with tag
and one of values
provided by getter
.
getElementDocumentPosition (Element element )
→ Pair<num >
Returns the X and Y position of Element int the Document .
getElementHeight (Element element , [int ? def ])
→ int ?
Returns element
height. Tries to use 'offsetHeight' or 'style.height' values.
getElementHREF (Element element )
→ String ?
Returns href
value for different Element types.
getElementPreComputedStyle (Element element )
→ CssStyleDeclaration
Returns a CssStyleDeclaration of the pre-computed CSS properties of element
.
getElementSRC (Element element )
→ String ?
Returns src
value for different Element types.
getElementsWithAttributes (String tag , Map <String , dynamic > matchAttributes )
→ List <Element >
Selects elements from DOM with tag
and matches attribute.
getElementTagName (Node node )
→ String ?
Returns the node
tag name.
Returns null if node
is not an Element .
getElementValue (Element element , [String ? def ])
→ String ?
Gets the element
value depending of identified type.
getElementWidth (Element element , [int ? def ])
→ int ?
Returns element
width. Tries to use 'offsetWidth' or 'style.width' values.
getElementZIndex (Element ? element , [String ? def ])
→ String ?
Returns the element
z-index
or element.parent
z-index
recursively.
getFileMimeType (File file , [String accept = '' ])
→ MimeType?
Returns the file
MimeType
.
getImageDimension (CanvasImageSource image )
→ Rectangle <int > ?
Gets the width and height from image
(CanvasImageSource ).
getLinkElementByHREF (String href , [String ? rel ])
→ LinkElement ?
Selects an LinkElement in DOM with href
.
getMetaTagsContentWithName (String name )
→ List <String ? >
Returns a list of meta
contet with name
.
getMetaTagsWithName (String name )
→ List <Element >
Returns a list of meta
Element with name
.
getParentElement (Element element , {bool validator (Element parent )?, int maxLevels = 1000 })
→ Element ?
Returns the parent of element
applying validator
and maxLevels
.
getScriptElementBySRC (String src )
→ ScriptElement ?
Selects an ScriptElement in DOM with src
.
getURLData (String url , {String ? user , String ? password , bool withCredentials = true })
→ Future <Uint8List >
Makes a HTTP request and returns url
content as Uint8List .
getVisibleNode (Element ? element )
→ Element ?
Get the first visible element in the hierarchy.
htmlToText (String html , [NodeValidator ? validator ])
→ String ?
Transform html
to plain text.
isCssEmpty (CssStyleDeclaration css )
→ bool
Returns true
if CssStyleDeclaration is empty.
isCssNotEmpty (CssStyleDeclaration css )
→ bool
Returns true
if CssStyleDeclaration is not empty.
isElementWithHREF (Element element )
→ bool
Returns true
if element
type can have href
attribute.
isElementWithSRC (Element element )
→ bool
Returns true
if element
type can have src
attribute.
isInDOM (dynamic element )
→ bool
Returns true
if element
is in DOM tree.
isInlineElement (DivElement element , {bool checkBootstrapClasses = true })
→ bool
Returns true
if element
display
property is inline.
isInViewport (Element element , {bool fully = false })
→ bool
Returns true
if element
is visible in viewport.
isMobileAppStatusBarTranslucent ()
→ bool
Returns true
if meta
tag of name apple-mobile-web-app-status-bar-style
is translucent
.
isNodeInDOM (Node node )
→ bool
Returns true
if node
is in DOM tree.
isOrientationInLandscapeMode ()
→ bool
Returns true
if device orientation is in Landscape mode.
isOrientationInPortraitMode ()
→ bool
Returns true
if device orientation is in Portrait mode.
isSafariIOS ()
→ bool
jsArrayToList (JsArray ? a )
→ List ?
Converts a JsArray a
to a List .
Also converts values using jsToDart .
jsObjectKeys (JsObject o )
→ List <String >
Returns the keys of JsObject o
.
jsObjectToMap (JsObject ? o )
→ Map ?
Converts a JsObject o
to a Map .
Also converts keys and values using jsToDart .
jsToDart (Object ? o )
→ Object ?
Converts o
to Dart primitives or collections.
lerpDouble (num a , num b , double t )
→ double ?
loadCSS (String cssClassPrefix , Map <String , CSSValueBase > ? css )
→ void
Loads css
dynamically.
mapJSFunction (String jsFunctionName , MappedFunction f )
→ void
Maps a JavaScript function to a Dart function.
markdownToDiv (String markdown , {bool normalize = true , Iterable <BlockSyntax > ? blockSyntaxes , Iterable <InlineSyntax > ? inlineSyntaxes , ExtensionSet? extensionSet , Resolver? linkResolver , Resolver? imageLinkResolver , bool inlineOnly = false })
→ DivElement
Converts a markdown
document into a HTML in a div node.
markdownToHtml (String markdown , {bool normalize = true , Iterable <BlockSyntax > ? blockSyntaxes , Iterable <InlineSyntax > ? inlineSyntaxes , ExtensionSet? extensionSet , Resolver? linkResolver , Resolver? imageLinkResolver , bool inlineOnly = false })
→ String
Converts a markdown
document into a HTML string.
measureText (String text , {required String fontFamily , required Object fontSize , bool bold = false })
→ Dimension?
nodeTreeContains (Node rootNode , Node target )
→ bool
Returns true
if rootNode
contains target
.
nodeTreeContainsAny (Node rootNode , Iterable <Node > list )
→ bool
Returns true
if rootNode
contains any Node in list
.
normalizeIndent (String text )
→ String
Normalizes a indent, removing the common/global indent of the code.
numsToPoints (List <num > perspective )
→ List <Point <num > >
Converts a List<num> , as pairs, to a List<Point> .
onOrientationchange (EventListener listener )
→ bool
Attaches listener
to orientationchange
event.
parseCSSLength (String cssValue , {String ? unit , int ? def , bool allowPXWithoutSuffix = false })
→ num ?
Parses a CSS length, using optional unit
.
parseCssRuleSelectors (CssRule cssRule )
→ List <String >
Parses the selectors of cssRule
.
parseCssRuleTextProperties (String ? cssRuleText )
→ String
Returns a list of properties of the CssRule text.
parseCssRuleTextSelectors (String ? cssRuleText )
→ List <String >
Returns a list of selectors of the CssRule text.
parseMetaContent (String content )
→ Map <String , String ? >
Parses a meta
content to Map<String,String> .
prefetchHref (String href , {int ? insertIndex , bool ? preLoad })
→ Future <bool >
Prefetch a HREF using a link
element into head
DOM node.
readFileDataAsArrayBuffer (File file )
→ Future <Uint8List ? >
Reads file
as Uint8List .
readFileDataAsBase64 (File file )
→ Future <String ? >
Reads file
as Base64 String .
readFileDataAsDataURLBase64 (File file , [String accept = '' ])
→ Future <String ? >
Reads file
as DATA URL Base64 String .
readFileDataAsText (File file )
→ Future <String ? >
Reads file
as text.
readFileInputElementAsArrayBuffer (FileUploadInputElement ? input , [bool removeExifFromImage = false ])
→ Future <Uint8List ? >
Reads selected file of input
as Uint8List .
readFileInputElementAsBase64 (FileUploadInputElement ? input , [bool removeExifFromImage = false ])
→ Future <String ? >
Reads selected file of input
as Base64.
readFileInputElementAsDataURLBase64 (FileUploadInputElement ? input , [bool removeExifFromImage = false ])
→ Future <String ? >
Reads selected file of input
as DATA URL Base64.
readFileInputElementAsString (FileUploadInputElement ? input , [bool removeExifFromImage = false ])
→ Future <String ? >
Reads selected file of input
as String .
redirectOnTouchEndToMouseEvent (Element element )
→ void
Redirects element.onTouchEnd
to element.onMouseUp
as MouseEvent .
redirectOnTouchMoveToMouseEvent (Element element )
→ void
Redirects element.onTouchMove
to element.onMouseMove
as MouseEvent .
redirectOnTouchStartToMouseEvent (Element element )
→ void
Redirects element.onTouchStart
to element.onMouseDown
as MouseEvent .
reloadAssets (Map <String , String > assetsURLAndTag , {Duration ? timeout })
→ Future <bool >
Reloads an asset (img, audi or video), forcing reload of asset URL.
reloadIframe (IFrameElement iFrame , [bool ? forceGet ])
→ Future <bool >
Reloads an IFrame document.
removeElementBackgroundBlur (Element element , [int ? blurSize ])
→ void
Removes element
background blur effect, set by setElementBackgroundBlur .
removeElementScrollColors (Element element )
→ List <String > ?
Removes element
scroll colors CSS properties set by setElementScrollColors .
removeExifFromImageFile (File file )
→ Future <String ? >
Removes Exif from JPEG file
.
replaceElement (Node n1 , Node n2 )
→ bool
Replaces n1
with n2
in n1
parent.
resetZoom ()
→ void
Resets viewport zoom.
rotateCanvasImageSource (CanvasImageSource image , int width , int height , [dynamic angleDegree = 90 ])
→ CanvasElement
Rotates image
(a CanvasImageSource ) with angleDegree
.
rotateImageElement (ImageElement image , [dynamic angleDegree = 90 ])
→ CanvasElement
Rotates image
with angleDegree
.
scalePoints (List <Point <num > > points , double scale )
→ List <Point <num > >
Scales points
to scale
.
scalePointsXY (List <Point <num > > points , double scaleX , double scaleY )
→ List <Point <num > >
Scales points
to scaleX
and scaleY
.
scrollTo (num ? x , num ? y , {bool smooth = true , int ? delayMs , Object ? scrollable })
→ void
Scrolls viewport to x
,y
.
scrollToBottom ({bool smooth = true , int ? delayMs })
→ void
Scrolls viewport to the bottom.
scrollToElement (Element element , {bool centered = true , bool vertical = true , bool horizontal = true , bool smooth = true , int ? translateX , int ? translateY , Object ? scrollable })
→ void
Scrolls the viewport to the element
.
scrollToLeft ({bool smooth = true , int ? delayMs })
→ void
Scrolls viewport to the left border.
scrollToRight ({bool smooth = true , int ? delayMs })
→ void
Scrolls viewport to the right border.
scrollToTop ({bool smooth = true , int y = 0 , bool fixSafariIOS = false , int ? delayMs })
→ void
Scrolls viewport to the top.
scrollToTopDelayed (int delayMs )
→ void
Use scrollToTop instead.
selectCssRuleWithSelector (Pattern targetSelector )
→ List <CssRule >
Returns a list of CssRule with targetSelector
patterns.
setDivCentered (DivElement div , {bool centerVertically = true , bool centerHorizontally = true , bool checkBootstrapClasses = true })
→ void
Sets div
as centered content, using display
property as table
and sub
div elements display
property as table-cell
.
setElementBackgroundBlur (Element element , [int ? blurSize ])
→ void
Sets element
background as a blur effect of size blurSize
.
Uses CSS property backdrop-filter
.
setElementHREF (Element element , String href )
→ bool
Sets element
href
depending of the identified type.
setElementInnerHTML (Element element , String html , {NodeValidator ? validator })
→ void
Sets the inner HTML of element
with parsed result of html
.
setElementScrollColors (Element element , int scrollWidth , String scrollButtonColor , [String ? scrollBgColor ])
→ String ?
Sets element
scroll colors, using standard CSS property scrollbar-color
and webkit pseudo element ::-webkit-scrollbar-thumb
and ::-webkit-scrollbar-track
setElementSRC (Element element , String src )
→ bool
Sets the element
src
depending of the identified type.
setElementValue (Element ? element , String value )
→ bool
Sets the element
value
depending of the identified type.
setMetaViewportScale ({String ? minimumScale , String ? maximumScale })
→ bool
Sets the meta
viewport with minimumScale
and maximumScale
.
setTreeElementsBackgroundBlur (Element element , String className )
→ void
setTreeElementsDivCentered (Element element , String className , {bool centerVertically = true , bool centerHorizontally = true })
→ void
Set all element
sub div with className
to centered content.
setZoom (String zoom )
→ void
Sets the viewport zoom
.
showDialogElement (Element content , {double ? transparency , String ? padding })
→ DivElement
Shows an Element dialog.
showDialogHTML (String ? html , {double ? transparency , String ? padding , NodeValidator ? validator })
→ DivElement ?
Shows a html
dialog.
showDialogImage (String src )
→ void
Shows an image (src
) dialog.
showDialogText (String ? text , {double ? transparency , String ? padding })
→ DivElement ?
Shows a text dialog.
toCanvasElement (CanvasImageSource imageSource , int width , int height )
→ CanvasElement
Converts imageSource
to CanvasElement .
toDataURLBase64 (String ? mediaType , String base64 )
→ String
Builds a DATA URL string.
toHTML (Element element )
→ String
Converts element
to HTML.
touchEventToMouseEvent (TouchEvent event )
→ MouseEvent ?
Converts a TouchEvent event
to a MouseEvent .
translatePoints (List <Point <num > > points , num x , num y )
→ List <Point <num > >
Translate pints
in x
and y
.