@danielgindi/dom-utils 1.0.2 → 1.0.6

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.
package/lib/Css.js CHANGED
@@ -27,6 +27,8 @@ const getCssProps = function (el, props) {
27
27
  if (val < 0)
28
28
  val = 0;
29
29
  }
30
+
31
+ val += 'px';
30
32
  }
31
33
 
32
34
  res[prop] = val;
@@ -363,6 +365,46 @@ const anchoredPosition = function (el, xSpec, ySpec, size, rtl) {
363
365
  };
364
366
  };
365
367
 
368
+ const timeToMs = (value) => {
369
+ if (!value) {
370
+ return;
371
+ }
372
+
373
+ let isMs = value.endsWith('ms');
374
+ return parseFloat(value) * (isMs ? 1 : 1000);
375
+ };
376
+
377
+ const isTimeString = (value) => {
378
+ return /^-?(0?\.)?\d+m?s$/.test(value);
379
+ };
380
+
381
+ const parseSingleTransition = (transition) => {
382
+ let parts = transition.split(/\s+/),
383
+ name = parts[0],
384
+ duration = parts[1],
385
+ timingFunctionOrDelay = parts[2],
386
+ delay = parts[3];
387
+
388
+ if (isTimeString(timingFunctionOrDelay)) {
389
+ return {
390
+ delay: timeToMs(timingFunctionOrDelay),
391
+ duration: timeToMs(duration),
392
+ name: name,
393
+ };
394
+ }
395
+
396
+ return {
397
+ delay: timeToMs(delay),
398
+ duration: timeToMs(duration),
399
+ name: name,
400
+ timingFunction: timingFunctionOrDelay,
401
+ };
402
+ };
403
+
404
+ const parseTransition = (transition) => {
405
+ return transition.match(/([^,()]|\([^)]*\))+/g).map(value => value.trim()).filter(value => value.length > 0).map(parseSingleTransition);
406
+ };
407
+
366
408
  export {
367
409
  getCssProps,
368
410
  setCssProps,
@@ -374,4 +416,8 @@ export {
374
416
  getPseudoElementHeight,
375
417
  getElementOffset,
376
418
  anchoredPosition,
419
+ parseTransition,
420
+ parseSingleTransition,
421
+ isTimeString,
422
+ timeToMs,
377
423
  };
package/lib/Dom.js CHANGED
@@ -38,7 +38,7 @@ const setElementAttrs = function (el, attrs) {
38
38
  el.innerHTML = String(value);
39
39
  else if (key === 'css' && 'style' in el)
40
40
  setCssProps(el, value);
41
- else if (key === 'readOnly' || key === 'tabIndex' || key === 'textContent')
41
+ else if (key in el && key !== 'style')
42
42
  el[key] = value;
43
43
  else el.setAttribute(key, String(value));
44
44
  }
@@ -115,10 +115,18 @@ const next = function (el, selector) {
115
115
  return null;
116
116
  };
117
117
 
118
+ const unwrapChildren = function (el) {
119
+ let parent = el.parentNode;
120
+ while (el.firstChild)
121
+ parent.insertBefore(el.firstChild, el);
122
+ parent.removeChild(el);
123
+ };
124
+
118
125
  export {
119
126
  createElement,
120
127
  setElementAttrs,
121
128
  closestUntil,
122
129
  prev,
123
130
  next,
131
+ unwrapChildren,
124
132
  };
package/lib/DomCompat.js CHANGED
@@ -57,13 +57,13 @@ const before = function (before, ...nodes) {
57
57
  if (nodes.length === 0) return;
58
58
 
59
59
  if ('before' in before) {
60
- after.before(...nodes);
60
+ before.before(...nodes);
61
61
  } else {
62
62
  if (nodes.length === 1) {
63
63
  let node = nodes[0];
64
64
  const isNode = node instanceof Node;
65
65
  node = isNode ? node : document.createTextNode(String(node));
66
- after.parentNode.insertBefore(node, before);
66
+ before.parentNode.insertBefore(node, before);
67
67
  } else {
68
68
  let docFrag = document.createDocumentFragment();
69
69
 
@@ -91,7 +91,10 @@ const after = function (after, ...nodes) {
91
91
  let node = nodes[0];
92
92
  const isNode = node instanceof Node;
93
93
  node = isNode ? node : document.createTextNode(String(node));
94
- after.parentNode.insertBefore(node, after.nextSibling);
94
+
95
+ if (after.nextSibling)
96
+ after.parentNode.insertBefore(node, after.nextSibling);
97
+ else after.parentNode.appendChild(node);
95
98
  } else {
96
99
  let docFrag = document.createDocumentFragment();
97
100
 
@@ -108,7 +111,7 @@ const after = function (after, ...nodes) {
108
111
  };
109
112
 
110
113
  /**
111
- * @param {ParentNode} parent
114
+ * @param {ParentNode|Element} parent
112
115
  * @param {(Node|string)[]} nodes
113
116
  */
114
117
  const prepend = function (parent, ...nodes) {
@@ -141,7 +144,7 @@ const prepend = function (parent, ...nodes) {
141
144
  };
142
145
 
143
146
  /**
144
- * @param {ParentNode} parent
147
+ * @param {ParentNode|Element} parent
145
148
  * @param {(Node|string)[]} nodes
146
149
  */
147
150
  const append = function (parent, ...nodes) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielgindi/dom-utils",
3
- "version": "1.0.2",
3
+ "version": "1.0.6",
4
4
  "description": "A collection of dom utilities. So you can work natively with the dom without dom frameworks.",
5
5
  "main": "dist/lib.cjs.min.js",
6
6
  "module": "lib/index.js",
@@ -28,19 +28,19 @@
28
28
  "homepage": "https://github.com/danielgindi/dom-utils#readme",
29
29
  "license": "MIT",
30
30
  "devDependencies": {
31
- "@babel/core": "^7.12.10",
32
- "@babel/preset-env": "^7.12.11",
33
- "@babel/runtime": "^7.12.5",
31
+ "@babel/core": "^7.15.8",
32
+ "@babel/preset-env": "^7.15.8",
33
+ "@babel/runtime": "^7.15.3",
34
34
  "babelify": "^10.0.0",
35
- "core-js": "^3.8.1",
36
- "eslint": "^7.17.0",
37
- "fs-extra": "^9.0.1",
38
- "husky": "^5.1.3",
35
+ "core-js": "^3.18.2",
36
+ "eslint": "^7.32.0",
37
+ "fs-extra": "^10.0.0",
38
+ "husky": "^7.0.2",
39
39
  "pinst": "^2.1.4",
40
- "rollup": "^2.35.1",
41
- "rollup-plugin-babel": "^4.4.0",
42
- "rollup-plugin-commonjs": "^10.1.0",
43
- "rollup-plugin-node-resolve": "^5.2.0",
40
+ "rollup": "^2.58.0",
41
+ "@rollup/plugin-babel": "^5.3.0",
42
+ "@rollup/plugin-commonjs": "^21.0.0",
43
+ "@rollup/plugin-node-resolve": "^13.0.4",
44
44
  "rollup-plugin-terser": "^7.0.2"
45
45
  },
46
46
  "dependencies": {}