@symbo.ls/image-color-picker
Advanced tools
Comparing version 2.11.34 to 2.11.36
138
index.js
'use strict' | ||
import { Flex, CommonField, Upload, ClickableItem, Img, WiderButton } from '@symbo.ls/ui' | ||
import ColorThief from '@symbo.ls/colorthief' | ||
import { rgbArrayToHex } from '@symbo.ls/scratch' | ||
const colorThief = new ColorThief() | ||
const applyColorThief = (el, s) => { | ||
const { node } = el | ||
const done = colorThief.getPalette(node, 5) | ||
const arrs = done.map(v => '#' + rgbArrayToHex(v)) | ||
s.update(arrs) | ||
} | ||
const imgPicker = { | ||
props: ({ state }) => ({ | ||
hide: !state.imageUrl, | ||
position: 'absolute', | ||
inset: '0 0 0 0', | ||
width: 'I', | ||
height: 'H', | ||
borderRadius: 'A', | ||
overflow: 'hidden', | ||
zIndex: 2 | ||
}), | ||
img: { | ||
extend: Img, | ||
props: ({ state }) => ({ | ||
src: state.imageUrl, | ||
position: 'absolute', | ||
inset: '0 0 0 0', | ||
width: '100%' | ||
}), | ||
attr: { | ||
crossOrigin: 'Anonymous' | ||
}, | ||
on: { | ||
load: (ev, el, s) => { | ||
if (!s.imageUrl || s.imageUrl === s.__imageUrl) return | ||
s.__imageUrl = s.imageUrl | ||
applyColorThief(el, s) | ||
} | ||
} | ||
}, | ||
buttons: { | ||
props: { | ||
position: 'absolute', | ||
left: 'A1', | ||
bottom: 'A1', | ||
flexAlign: 'center flex-start', | ||
gap: 'X2', | ||
transition: 'B opacity' | ||
}, | ||
childExtend: [WiderButton, ClickableItem], | ||
delete: { | ||
props: { icon: 'trash' }, | ||
on: { | ||
click: (ev, el, s) => { | ||
ev.preventDefault() | ||
s.update({ imageUrl: null }) | ||
} | ||
} | ||
}, | ||
refresh: { props: { icon: 'sync' } | ||
} | ||
} | ||
} | ||
const upload = { | ||
extend: [Upload, Flex, ClickableItem], | ||
Icon: { }, | ||
P: { Span: null }, | ||
Input: { | ||
on: { | ||
change: (ev, el, s) => { | ||
// var files = ev.target.files | ||
// var file = files[0] | ||
// if (files && file) { | ||
// var reader = new window.FileReader() | ||
// reader.onload = function (readerEvt) { | ||
// var binaryString = readerEvt.target.result | ||
// const base = window.btoa(binaryString) | ||
// s.update({ imageUrl: base }) | ||
// const img = new Image(500, 500) | ||
// img.src = `data:image/png;base64, ${base}` | ||
// new ColorThief().getPalette(img) | ||
// .then(palette => { console.log(palette) }) | ||
// .catch(err => { console.log(err) }) | ||
// } | ||
// ColorThief.getPalette(img, 5) | ||
// .then(palette => { console.log(palette) }) | ||
// .catch(err => { console.log(err) }) | ||
// reader.readAsBinaryString(file) | ||
// } | ||
} | ||
} | ||
} | ||
} | ||
export const ImageColorPicker = { | ||
extend: [CommonField, Flex], | ||
props: { | ||
title: { text: 'Pick from the picture' }, | ||
element: { | ||
position: 'relative', | ||
upload: { | ||
border: 'none', | ||
background: 'gray1', | ||
padding: 'Z2 A2 Z2 Z2', | ||
gap: 'Z', | ||
flow: 'row', | ||
icon: { fontSize: 'H' }, | ||
p: { | ||
text: 'Upload or drop the image' | ||
} | ||
} | ||
} | ||
}, | ||
title: {}, | ||
element: { | ||
imgPicker, | ||
upload | ||
} | ||
} |
{ | ||
"name": "@symbo.ls/image-color-picker", | ||
"author": "symbo.ls", | ||
"version": "2.11.34", | ||
"version": "2.11.36", | ||
"repository": "https://github.com/symbo-ls/smbls", | ||
"main": "index.js", | ||
"gitHead": "a9875f5261165cbef5c9e6344f319636cb89c3f2" | ||
"dependencies": { | ||
"@symbo.ls/colorthief": "latest" | ||
}, | ||
"gitHead": "e2746630554e446c0b8530701f389f986e2bdd45" | ||
} |
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
693835
119
0
1
+ Added@symbo.ls/colorthief@latest
+ Added@symbo.ls/colorthief@2.3.5(transitive)
+ Added@symbo.ls/get-pixels@3.3.4(transitive)
+ Added@symbo.ls/quantize@1.2.2(transitive)
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addedcwise-compiler@1.1.3(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddata-uri-to-buffer@0.0.3(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addediota-array@1.0.0(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjpeg-js@0.4.4(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedndarray@1.0.19(transitive)
+ Addedndarray-pack@1.2.1(transitive)
+ Addednode-bitmap@0.0.1(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedomggif@1.0.10(transitive)
+ Addedparse-data-uri@0.2.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpngjs@3.4.0(transitive)
+ Addedpsl@1.10.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedthrough@2.3.8(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduniq@1.0.1(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)