material 0.7.2 → 0.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/LICENSE +9 -18
  2. package/index.js +26 -48
  3. package/package.json +4 -12
  4. package/src/card.js +0 -5
  5. package/src/checkbox.js +48 -52
  6. package/src/element/insert.js +6 -4
  7. package/src/list.js +1 -3
  8. package/src/loader.js +88 -0
  9. package/src/module/attach.js +3 -9
  10. package/src/module/attributes.js +7 -14
  11. package/src/module/build.js +1 -3
  12. package/src/module/cookie.js +24 -0
  13. package/src/module/dom.js +1 -0
  14. package/src/module/last.js +6 -16
  15. package/src/module/numabbr.js +24 -0
  16. package/src/module/object.js +2 -2
  17. package/src/module/passive.js +1 -1
  18. package/src/module/remove.js +3 -38
  19. package/src/module/request.js +32 -0
  20. package/src/module/ripple.js +2 -1
  21. package/src/module/touch.js +1 -1
  22. package/src/module/utils.js +0 -31
  23. package/src/module/viewport.js +4 -10
  24. package/src/navigation.js +53 -4
  25. package/src/skin/material/button/action.sass +6 -6
  26. package/src/skin/material/button/button.sass +6 -6
  27. package/src/skin/material/button/file.sass +1 -1
  28. package/src/skin/material/button/floating.sass +5 -5
  29. package/src/skin/material/button/raised.sass +5 -5
  30. package/src/skin/material/button/stroked.sass +5 -5
  31. package/src/skin/material/component/navigation.sass +6 -2
  32. package/src/skin/material/control/checkbox.sass +21 -21
  33. package/src/skin/material/module/ripple.sass +1 -1
  34. package/src/snackbar.js +4 -2
  35. package/src/styles/M3/abstracts/variables.sass +44 -0
  36. package/src/styles/M3/app/index.sass +19 -0
  37. package/src/styles/M3/base/body.sass +55 -0
  38. package/src/styles/M3/base/elevation.sass +50 -0
  39. package/src/styles/M3/base/grid.sass +63 -0
  40. package/src/styles/M3/base/typo.sass +107 -0
  41. package/src/styles/M3/components/button.sass +39 -0
  42. package/src/styles/M3/modules/ripple.sass +9 -0
  43. package/src/styles/M3/navigation/rail.sass +93 -0
  44. package/src/styles/M3/themes/classic.sass +2 -0
  45. package/src/styles/M3/view/view.sass +2 -0
  46. package/src/tabs.js +2 -3
  47. package/src/view.js +1 -2
  48. package/dist/demo-bundle.js +0 -2281
  49. package/dist/demo-bundle.js.map +0 -7
  50. package/dist/demo.css +0 -93
  51. package/dist/demo.css.map +0 -7
  52. package/dist/demo.html +0 -24
  53. package/dist/demo.js +0 -159
  54. package/dist/icon/accessibility.svg +0 -5
  55. package/dist/icon/apps.svg +0 -5
  56. package/dist/icon/happy.svg +0 -6
  57. package/dist/icon/link.svg +0 -5
  58. package/dist/icon/more.svg +0 -5
  59. package/dist/icon/navi.svg +0 -5
  60. package/dist/icon/phone.svg +0 -6
  61. package/dist/icon/share.svg +0 -6
  62. package/dist/icon/side.svg +0 -5
  63. package/dist/icon/star.svg +0 -7
  64. package/dist/icon/star_border.svg +0 -6
  65. package/dist/material.css +0 -2429
  66. package/dist/material.css.map +0 -7
  67. package/dist/styles/demo.sass +0 -110
  68. package/dist/styles.css +0 -23
  69. package/esbuild.js +0 -22
  70. package/esbuild.watch.js +0 -25
  71. package/src/container.js +0 -66
  72. package/src/field/email.js +0 -24
  73. package/src/field/image.js +0 -59
package/LICENSE CHANGED
@@ -1,20 +1,11 @@
1
- The MIT License (MIT)
1
+ This program is free software: you can redistribute it and/or modify
2
+ it under the terms of the GNU General Public License as published by
3
+ the Free Software Foundation, under the terms of the GNU General Public License as published by the Free Software Foundation, version 3 of the License.
2
4
 
3
- Copyright (c) 2019 2nd Floor
5
+ This program is distributed in the hope that it will be useful,
6
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
7
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8
+ GNU General Public License for more details.
4
9
 
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of
6
- this software and associated documentation files (the "Software"), to deal in
7
- the Software without restriction, including without limitation the rights to
8
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
- the Software, and to permit persons to whom the Software is furnished to do so,
10
- subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10
+ You should have received a copy of the GNU General Public License
11
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
package/index.js CHANGED
@@ -1,32 +1,40 @@
1
1
  import AppBar from './src/appbar'
2
+ import Badge from './src/badge'
2
3
  import Button from './src/button'
3
4
  import Card from './src/card'
5
+ import Checkbox from './src/checkbox'
4
6
  import Component from './src/component'
5
- import DateHour from './src/control/datehour'
7
+ import DateHour from './src/datehour'
6
8
  import Dialog from './src/dialog'
7
- import File from './src/control/file'
8
- import Loading from './src/control/loading'
9
- import Menu from './src/control/menu'
10
- import Select from './src/select'
11
- import Selecter from './src/control/selecter'
12
- import Snackbar from './src/snackbar'
13
- import Switch from './src/switch'
14
- import Switcher from './src/control/switcher'
15
- import Text from './src/text'
16
- import Textfield from './src/textfield'
9
+ import Drawer from './src/drawer'
17
10
  import Element from './src/element'
11
+ import File from './src/file'
12
+ import Form from './src/form'
13
+ import Image from './src/image'
18
14
  import Layout from './src/layout'
19
15
  import List from './src/list'
20
- import Tabview from './src/tabview'
16
+ import Loading from './src/loading'
17
+ import Menu from './src/menu'
18
+ import Navigation from './src/navigation'
19
+ import Progress from './src/progress'
20
+ import Select from './src/select'
21
+ import Selecter from './src/selecter'
22
+ import Snackbar from './src/snackbar'
23
+ import Slider from './src/slider'
24
+ import Switch from './src/switch'
25
+ import Switcher from './src/switcher'
26
+ import Tabs from './src/tabs'
21
27
  import TabView from './src/tabview'
22
28
  import Text from './src/text'
29
+ import Textfield from './src/textfield'
23
30
  import Toolbar from './src/toolbar'
24
31
  import Tooltip from './src/tooltip'
32
+ import View from './src/view'
25
33
  import attach from './src/module/attach'
26
34
  import attributes from './src/module/attributes'
27
35
  import build from './src/module/build'
28
36
  import dataset from './src/module/dataset'
29
- import display from './src/module/display'
37
+ import display from './src/mixin/display'
30
38
  import events from './src/module/attach'
31
39
  import emitter from './src/module/emitter'
32
40
  import jsonToHTML from './src/module/jsontohtml'
@@ -35,39 +43,9 @@ import observer from './src/module/observer'
35
43
  import smoothscroll from './src/module/smoothscroll'
36
44
 
37
45
  export {
38
- AppBar
39
- Button,
40
- DateHour,
41
- Datehour,
42
- Dialog,
43
- Card,
44
- Component,
45
- Element,
46
- File,
47
- Loading,
48
- Menu,
49
- Select,
50
- Selecter,
51
- Snackbar,
52
- Switch,
53
- Switcher,
54
- Tabview,
55
- TabView,
56
- Text,
57
- Textfield,
58
- Toolbar,
59
- Tooltip,
60
- Layout,
61
- List,
62
- attach,
63
- attributes,
64
- build,
65
- dataset,
66
- display,
67
- events,
68
- emitter,
69
- jsonToHTML,
70
- mediator,
71
- observer,
72
- smoothscroll
46
+ AppBar, Button, Card, Checkbox, Component, DateHour, Dialog, Drawer, Element,
47
+ File, Form, Image, Layout, List, Loading, Menu, Navigation, Progress, Select,
48
+ Selecter, Slider, Snackbar, Switch, Switcher, Tabs, TabView, Text, Textfield, Toolbar, Tooltip,
49
+ View, attach, attributes, build, dataset, display, events, emitter, jsonToHTML, mediator,
50
+ observer, smoothscroll
73
51
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "material",
3
- "version": "0.7.2",
4
- "description": "A lightweight implementation of Material Design Components - ES6",
3
+ "version": "0.7.5",
4
+ "description": "A lightweight implementation of Material Design Components for the web - ES6",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "repository": {
@@ -9,26 +9,18 @@
9
9
  "url": "git+ssh://git@gitlab.com/alkaloid/material.git"
10
10
  },
11
11
  "author": "Jérôme Vial <jerome.vial@gmail.com>",
12
- "license": "MIT",
12
+ "license": "GPL-3",
13
13
  "bugs": {
14
14
  "url": "https://gitlab.com/alkaloid/material/issues"
15
15
  },
16
16
  "homepage": "https://gitlab.com/alkaloid/material",
17
17
  "keywords": [
18
- "lightweight material design ui component es6 vanilla javascript"
18
+ "lightweight material design ui component web es6 vanilla javascript"
19
19
  ],
20
20
  "devDependencies": {
21
- "esbuild": "^0.14.47",
22
- "esbuild-plugin-svg": "^0.1.0",
23
- "@jgoz/esbuild-plugin-livereload": "^2.0.3",
24
21
  "standard": "^10.0.3"
25
22
  },
26
23
  "scripts": {
27
- "build": "node ./esbuild.js",
28
- "build:watch": "node ./esbuild.watch.js",
29
- "styles": "sass --watch dist/styles/demo.sass:dist/demo.css",
30
- "watch": "npm-run-all --parallel reload dev",
31
- "docs": "jsdoc src -r -d docs",
32
24
  "test": "echo \"Error: no test specified\" && exit 1"
33
25
  }
34
26
  }
package/src/card.js CHANGED
@@ -11,11 +11,6 @@ const defaults = {
11
11
  }
12
12
 
13
13
  class Card {
14
- /**
15
- * Constructor
16
- * @param {Object} options - Component options
17
- * @return {Object} Class instance
18
- */
19
14
  constructor (options) {
20
15
  this.init(options)
21
16
  this.build()
package/src/checkbox.js CHANGED
@@ -1,74 +1,67 @@
1
- import events from './mixin/events'
2
- import control from './mixin/control'
3
- import label from './mixin/label'
4
-
5
- import insert from './element/insert'
6
- import build from './element/build'
7
-
8
- import emitter from './module/emitter'
1
+ import EventEmitter from './mixin/events'
2
+ // import control from './mixin/control'
3
+ import build from './module/build'
9
4
  import attach from './module/attach'
10
5
  import * as css from './module/css'
11
6
 
12
7
  import icon from './skin/material/icon/checkbox.svg'
13
- // element related modules
14
-
15
- const defaults = {
16
- prefix: 'material',
17
- class: 'checkbox',
18
- type: 'control',
19
- // modules: [events, control, emitter, attach],
20
- build: ['$root.material-checkbox', {},
21
- ['input$input', {}],
22
- ['span$control.checkbox-control']
23
- ],
24
- events: [
25
- ['element.control.click', 'click', {}],
26
- ['element.label.click', 'toggle', {}],
27
- // for accessibility purpose
28
- // ['element.input.click', 'toggle', {}],
29
- ['element.input.focus', 'focus'],
30
- ['element.input.blur', 'blur'],
31
- ['element.input.keydown', 'keydown', {}]
32
- ]
33
- }
8
+
9
+ import Element from './element'
34
10
 
35
11
  class Checkbox {
12
+ static defaults = {
13
+ class: 'checkbox',
14
+ layout: [
15
+ [Element, 'input', { type: 'checkbox' } ],
16
+ [Element, 'control', { type: 'checkbox' } ],
17
+ [Element, 'label', { tag: 'label' }]
18
+ ],
19
+ events: [
20
+ ['ui.control.click', 'click'],
21
+ ['ui.label.click', 'toggle'],
22
+ // for accessibility purpose
23
+ // ['element.input.click', 'toggle'],
24
+ ['ui.input.focus', 'focus'],
25
+ ['ui.input.blur', 'blur'],
26
+ ['ui.input.keydown', 'keydown']
27
+ ]
28
+ }
29
+
36
30
  constructor (options) {
37
31
  this.init(options)
38
32
  this.build()
33
+ this.setup()
39
34
  this.attach()
40
-
41
- return this
42
35
  }
43
36
 
44
37
  init (options) {
45
38
  this.options = Object.assign({}, defaults, options || {})
46
- Object.assign(this, events, control, emitter, attach)
39
+ Object.assign(this, build, attach)
47
40
 
48
41
  return this
49
42
  }
50
43
 
51
- build () {
44
+ setup () {
52
45
  this.element = build(this.options.build)
53
46
  this.element = this.element.root
54
47
 
55
- this.element.control.innerHTML = icon
48
+ this.ui.control.innerHTML = icon
56
49
 
57
50
  const text = this.options.text || this.options.label
58
51
 
59
- this.element.label = label(this.element, text, this.options)
52
+ this.ui.label.innerHTML = text
60
53
 
61
- this.element.input.setAttribute('type', 'checkbox')
62
- this.element.input.setAttribute('name', this.options.name)
63
- this.element.input.setAttribute('aria-label', this.options.name)
54
+ this.ui.input.setAttribute('type', 'checkbox')
55
+ this.ui.input.setAttribute('name', this.options.name)
56
+ this.ui.input.setAttribute('aria-label', this.options.name)
64
57
 
65
58
  if (this.options.value) {
66
- this.element.input.setAttribute('value', this.options.value)
59
+ this.ui.input.setAttribute('value', this.options.value)
67
60
  }
68
61
 
69
62
  if (this.options.disabled) {
70
63
  this.disabled = this.options.disabled
71
- this.element.input.setAttribute('disabled', 'disabled')
64
+ this.ui.input.setAttribute('disabled', 'disabled')
72
65
  css.add(this.element, 'is-disabled')
73
66
  }
74
67
 
@@ -79,13 +72,6 @@ class Checkbox {
79
72
  if (this.options.value) {
80
73
  this.set('value', this.value)
81
74
  }
82
-
83
- // insert if container options is given
84
- if (this.options.container) {
85
- insert(this.element, this.options.container)
86
- }
87
-
88
- return this
89
75
  }
90
76
 
91
77
  set (prop, value) {
@@ -106,15 +92,25 @@ class Checkbox {
106
92
  return this
107
93
  }
108
94
 
109
- insert (container, context) {
110
- insert(this.element, container, context)
111
-
95
+ check (checked) {
96
+ if (checked === true) {
97
+ css.add(this.element, 'is-checked')
98
+ this.ui.input.checked = true
99
+ this.checked = true
100
+ this.emit('change', this.checked)
101
+ } else {
102
+ css.remove(this.element, 'is-checked')
103
+ this.ui.input.checked = false
104
+ this.checked = false
105
+ this.emit('change', this.checked)
106
+ }
112
107
  return this
113
108
  }
114
109
 
110
+
115
111
  click (e) {
116
112
  this.toggle(e)
117
- this.element.input.focus()
113
+ this.ui.input.focus()
118
114
 
119
115
  return this
120
116
  }
@@ -122,7 +118,7 @@ class Checkbox {
122
118
  setValue (value) {
123
119
  // console.log('setValue', value)
124
120
  this.value = value
125
- this.element.input.setAttribute('value', value)
121
+ this.ui.input.setAttribute('value', value)
126
122
 
127
123
  return this
128
124
  }
@@ -1,10 +1,12 @@
1
1
  import dom from '../module/dom'
2
2
 
3
- const insert = (element, container, context = 'bottom') => {
4
- if (!element || !container) return
3
+ const insert = (component, container, context = 'bottom') => {
4
+ // console.log('insert', component, container, context)
5
5
 
6
- element = element.root || element
7
- container = container.root || container
6
+ if (!component || !container) return
7
+
8
+ const element = component.element || component
9
+ container = container.element || container
8
10
 
9
11
  const contexts = ['top', 'bottom', 'after', 'before']
10
12
  const methods = ['prepend', 'append', 'after', 'before']
package/src/list.js CHANGED
@@ -1,4 +1,4 @@
1
- import * css from './module/css'
1
+ import * as css from './module/css'
2
2
 
3
3
  const defaults = {
4
4
  className: 'text',
@@ -10,8 +10,6 @@ class List {
10
10
  constructor (options) {
11
11
  this.options = Object.assign({}, defaults, options || {})
12
12
 
13
- // console.log('options', this.options)
14
-
15
13
  this.build()
16
14
 
17
15
  return this
package/src/loader.js ADDED
@@ -0,0 +1,88 @@
1
+ class Loader {
2
+ static defaults = {
3
+ class: 'loader'
4
+ }
5
+
6
+ constructor (options) {
7
+ this.options = Object.assign({}, Loader.defaults, options || {})
8
+
9
+ // Object.assign(this, attach, mediator, build)
10
+
11
+ this.build()
12
+
13
+ return this
14
+ }
15
+
16
+ build () {
17
+ this.element = document.createElement(this.options.tag || 'div')
18
+ this.element.classList.add(this.options.class || 'loader')
19
+
20
+ this.container = document.createElement('div')
21
+ this.container.classList.add('container')
22
+ this.element.appendChild(this.container)
23
+
24
+ const svg = `
25
+ <svg
26
+ version="1.1"
27
+ id="dc-spinner"
28
+ xmlns="http://www.w3.org/2000/svg"
29
+ x="0px" y="0px"
30
+ width:"38"
31
+ height:"38"
32
+ viewBox="0 0 38 38"
33
+ preserveAspectRatio="xMinYMin meet"
34
+ >
35
+ <path class="circles" d="M20,35c-8.271,0-15-6.729-15-15S11.729,5,20,5s15,6.729,15,15S28.271,35,20,35z M20,5.203
36
+ C11.841,5.203,5.203,11.841,5.203,20c0,8.159,6.638,14.797,14.797,14.797S34.797,28.159,34.797,20
37
+ C34.797,11.841,28.159,5.203,20,5.203z">
38
+ </path>
39
+
40
+ <path class="circles" d="M20,33.125c-7.237,0-13.125-5.888-13.125-13.125S12.763,6.875,20,6.875S33.125,12.763,33.125,20
41
+ S27.237,33.125,20,33.125z M20,7.078C12.875,7.078,7.078,12.875,7.078,20c0,7.125,5.797,12.922,12.922,12.922
42
+ S32.922,27.125,32.922,20C32.922,12.875,27.125,7.078,20,7.078z">
43
+ </path>
44
+
45
+ <path class="circletwo" stroke-width="0.6027" stroke-miterlimit="10" d="M5.203,20
46
+ c0-8.159,6.638-14.797,14.797-14.797V5C11.729,5,5,11.729,5,20s6.729,15,15,15v-0.203C11.841,34.797,5.203,28.159,5.203,20z">
47
+ <animateTransform
48
+ attributeName="transform"
49
+ type="rotate"
50
+ from="0 20 20"
51
+ to="360 20 20"
52
+ calcMode="spline"
53
+ keySplines="0.4, 0, 0.2, 1"
54
+ keyTimes="0;1"
55
+ dur="2s"
56
+ repeatCount="indefinite" />
57
+ </path>
58
+
59
+ <path class="circleone" stroke-width="0.2027" stroke-miterlimit="10" d="M7.078,20
60
+ c0-7.125,5.797-12.922,12.922-12.922V6.875C12.763,6.875,6.875,12.763,6.875,20S12.763,33.125,20,33.125v-0.203
61
+ C12.875,32.922,7.078,27.125,7.078,20z">
62
+ <animateTransform
63
+ attributeName="transform"
64
+ type="rotate"
65
+ from="0 20 20"
66
+ to="360 20 20"
67
+ dur="1.8s"
68
+ repeatCount="indefinite" />
69
+ </path>
70
+ </svg>`
71
+
72
+ this.container.innerHTML = svg
73
+ this.text = document.createElement(this.options.tag || 'span')
74
+ this.text.classList.add('text')
75
+ this.text.innerHTML = this.options.text
76
+ this.container.appendChild(this.text)
77
+ }
78
+
79
+ show () {
80
+ this.element.classList.add('show')
81
+ }
82
+
83
+ hide () {
84
+ this.element.classList.remove('show')
85
+ }
86
+ }
87
+
88
+ export default Loader
@@ -1,5 +1,5 @@
1
- // Assuming extract is imported or defined elsewhere
2
1
  import extract from './extract'
2
+ import last from './last'
3
3
 
4
4
  const attachModule = {
5
5
  attach (events) {
@@ -18,7 +18,7 @@ const attachModule = {
18
18
  keys.pop()
19
19
  }
20
20
 
21
- const bound = this.last(keys.join('.'))
21
+ const bound = last(keys.join('.'), this)
22
22
 
23
23
  let handler = null
24
24
 
@@ -45,14 +45,8 @@ const attachModule = {
45
45
  })
46
46
 
47
47
  return this
48
- },
49
-
50
- last (str) {
51
- if (!str) return this
52
- if (!str.includes('.')) return this[str]
53
-
54
- return str.split('.').reduce((acc, key) => acc[key], this)
55
48
  }
49
+
56
50
  }
57
51
 
58
52
  export default attachModule
@@ -1,21 +1,14 @@
1
1
  const special = ['required', 'disabled', 'multiple', 'checked']
2
2
 
3
- function attributes (element, o) {
4
- // console.log('attributes', o.attributes, element)
3
+ const attributes = (element, options) => {
4
+ if (!element || !options.attributes) return
5
5
 
6
- if (!element) return
7
-
8
- for (let i = 0; i < o.attributes.length; i++) {
9
- const attribute = o.attributes[i]
10
-
11
- if (o[attribute] && o[attribute] !== 'undefined') {
12
- if (special.indexOf(attribute) > -1) {
13
- element.setAttribute(attribute, attribute)
14
- } else {
15
- element.setAttribute(attribute, o[attribute])
16
- }
6
+ options.attributes.forEach(attribute => {
7
+ if (options[attribute] && String(options[attribute]) !== 'undefined') {
8
+ const value = special.includes(attribute) ? attribute : options[attribute]
9
+ element.setAttribute(attribute, value)
17
10
  }
18
- }
11
+ })
19
12
  }
20
13
 
21
14
  export default attributes
@@ -16,13 +16,11 @@ export default {
16
16
  css.add(this.element, this.options.class)
17
17
  }
18
18
 
19
- if (defaults.class === 'account') console.log('data')
20
-
21
19
  if (this.options.data) {
22
20
  dataset(this.element, this.options.data)
23
21
  }
24
22
 
25
- if (this.options.base === 'view') {
23
+ if (this.options.base === 'view' || this.options.base === 'app') {
26
24
  this.container = this.options.container || document.body
27
25
  } else {
28
26
  this.container = this.options.container
@@ -0,0 +1,24 @@
1
+ const cookie = {
2
+ set: (name, value, expire = 365) => {
3
+ const d = new Date()
4
+ d.setTime(d.getTime() + (expire * 24 * 60 * 60 * 1000))
5
+ const expires = `expires=${d.toUTCString()}`
6
+ document.cookie = `${name}=${value};${expires};path=/`
7
+ },
8
+ get: name => {
9
+ const nameEQ = `${name}=`
10
+ const ca = decodeURIComponent(document.cookie).split(';')
11
+
12
+ for (let c of ca) {
13
+ while (c.charAt(0) === ' ') c = c.substring(1)
14
+ if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length)
15
+ }
16
+
17
+ return ''
18
+ },
19
+ del: name => {
20
+ document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`
21
+ }
22
+ }
23
+
24
+ export default cookie
package/src/module/dom.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // DOM manipulation function
2
2
 
3
3
  function append (container, element) {
4
+ console.log(container, element)
4
5
  container.appendChild(element)
5
6
  return element
6
7
  }
@@ -1,18 +1,8 @@
1
- export default {
2
- (str) => {
3
- // console.log('_path', str)
4
- if (!str) return this
5
- else if (!str.match(/\./)) return this[str]
6
- var last
1
+ const last = (str, that) => {
2
+ if (!str) return that
3
+ if (!str.includes('.')) return that[str]
7
4
 
8
- var keys = str.split('.')
9
- for (var i = 0, l = keys.length; i < l; i++) {
10
- var key = keys[i]
11
-
12
- last = last || this
13
- last = last[key]
14
- }
15
-
16
- return last
17
- }
5
+ return str.split('.').reduce((acc, key) => acc[key], that)
18
6
  }
7
+
8
+ export default last
@@ -0,0 +1,24 @@
1
+ const numabbr = (number, decimals = 2) => {
2
+ const factor = Math.pow(10, decimals)
3
+ const abbrev = ['k', 'm', 'b', 't']
4
+
5
+ for (let i = abbrev.length - 1; i >= 0; i--) {
6
+ const size = Math.pow(10, (i + 1) * 3)
7
+
8
+ if (size <= number) {
9
+ let num = Math.round(number * factor / size) / factor
10
+
11
+ // Handle special case where we round up to the next abbreviation
12
+ if (num === 1000 && i < abbrev.length - 1) {
13
+ num = 1
14
+ i++
15
+ }
16
+
17
+ return `${num}${abbrev[i]}`
18
+ }
19
+ }
20
+
21
+ return number.toString()
22
+ }
23
+
24
+ export default numabbr
@@ -1,11 +1,11 @@
1
1
 
2
- function is (object) {
2
+ const is = (object) => {
3
3
  return object &&
4
4
  typeof object === 'object' &&
5
5
  Object.getPrototypeOf(object) === Object.getPrototypeOf({})
6
6
  }
7
7
 
8
- function byString (o, s) {
8
+ const byString = (o, s) => {
9
9
  s = s.replace(/\[(\w+)\]/g, '.$1') // convert indexes to properties
10
10
  s = s.replace(/^\./, '') // strip a leading dot
11
11
  const a = s.split('.')
@@ -1,4 +1,4 @@
1
- function passiveEvents () {
1
+ const passiveEvents = () => {
2
2
  let supportsPassive = false
3
3
 
4
4
  try {