Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Library of functions for building browser apps.
This is not a framework, it's just where things I've been using a lot lately end up.
Might be useful to you if you like typescript and you like everything to just be functions that deal with simple data
Also exports TS typings
const elements = [
header(
h1(
img( { src: '/img/logo.svg', alt: 'My Logo' } ),
'My App'
)
),
main(
section(
{ class: 'copy' },
h2( 'About' ),
p( 'Hullo wurld' )
)
),
footer(
p( 'Copy me' )
)
]
const drawingEl = svg(
{
viewBox: [ 0, 0, 100, 100 ].join( ' ' )
},
rect({ x: 0, y: 0, width: 100, height: 100, fill: 'red' }),
circle({ x: 50, y: 50, r: 50, fill: 'yellow' })
)
document.body.append( ...elements, drawingEl )
const logoEl = strictSelect( 'img' )
const logoImageData = await drawingMapper.htmlImage.imageData( logoEl )
const backgroundImageData = await drawingMapper.svg.imageData( drawingEl )
pasteImageData( logoImageData, backgroundImageData )
const newLogoEl = await drawingMapper.imageData.htmlImage( backgroundImageData )
logoEl.before( newLogoEl )
logoEl.remove()
drawingEl.remove()
A slew of junk I use is exported by /src/index.ts
:
Exports all elements currently named in typescript's HTMLElementTagNameMap
import { div, span } from 'dom-app'
const el = div( { id: 'foo' }, span( 'Hello' ), ' World' )
Attributes are a Record<string,any>
and values are converted to string via
value => String( value )
, with the following exception
If the key is style
and the value is not a string, the value is expected to be
a Partial<CSSStyleDeclaration>
:
const el = div(
{
id: 'foo',
style: {
color: 'blue',
paddingLeft: '1rem'
}
},
'Hello'
)
If you can't find a tag there may be a namespace clash or the tagname matches a reserved word:
$s
- clashes with the SVG factory function name$var
- clashes with reserved wordThere are helper functions for creating custom tags, text nodes and fragments:
import { h, text, fragment } from 'dom-app'
const contents = fragment(
text( 'Hello' ), ' World'
)
const el = h( 'custom-tagname', { id: 'foo' }, contents )
Exports all elements currently named in typescript's SVGElementTagNameMap
import { svg, rect, circle } from 'dom-app'
const el = svg(
{
viewBox: [ 0, 0, 100, 100 ].join( ' ' )
},
rect({ x: 0, y: 0, width: 100, height: 100, fill: 'red' }),
circle({ x: 50, y: 50, r: 50, fill: 'yellow' })
)
Renamed:
$a
- clashes with HTML a
function$script
- clashes with HTML script
function$style
- clashes with HTML style
function$switch
- clashes with reserved word$text
- clashes with text
, the TextNode
factory functionCustom SVG element:
import { s } from 'dom-app'
const el = s( 'custom-tagname', { id: 'foo' } )
Set attributes on existing element:
import { attr } from 'dom-app'
const themeAttr = {
style: {
backgroundColor: 'green',
color: 'yellow'
}
}
// element, then any number of attribute records
attr( el, { id: 'foo' }, themeAttr )
Instead of returning null, throw an error if the querySelector doesn't match anything:
import { strictSelect, ul, li } from 'dom-app'
const myList = ul(
li( 'Bread' ),
li( 'Eggs' )
)
const firstLi = strictSelect( 'li', myList )
// omit the parent argument to search the document - this will throw as we have
// not appended myList to the document
const listEl = strictSelect( 'ul' )
async
functions that convert between different DOM drawing types
The types it can map between are:
export type DrawingMapFromType = {
imageSource: CanvasImageSource
htmlImage: HTMLImageElement
canvas: HTMLCanvasElement
context: CanvasRenderingContext2D
imageData: ImageData
blob: Blob
svg: SVGSVGElement
dataUrl: string
size: Size
}
The API is called like:
import { drawingMapper, loadHtmlImage } from 'dom-app'
const imgEl = await loadHtmlImage( 'test.png' )
const canvasEl = await drawingMapper.htmlImage.canvas( imgEl )
const blob = await drawingMapper.canvas.blob( canvasEl )
You can convert from any format to any other, but converting from size to anything will result in a blank image/canvas/etc
Most of the packages from @rgba-image
except
for the resizing stuff because I don't trust it
Some functions are renamed for clarity:
export { copy as copyImageData } from '@rgba-image/copy'
export { paste as pasteImageData } from '@rgba-image/paste'
export { fill as fillImageData } from '@rgba-image/fill'
export { clone as cloneImageData } from '@rgba-image/clone'
const { App } = require( 'dom-app' )
A whole bunch of stuff - document later
MIT License
Copyright (c) 2021 Nik Coughlin
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Library for building browser apps
The npm package dom-app receives a total of 1 weekly downloads. As such, dom-app popularity was classified as not popular.
We found that dom-app demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.