ctx-core 5.25.5 → 5.26.0

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.
@@ -8,3 +8,8 @@ export declare function html_style_(...style_def_a:html_attr_def_T[]):string
8
8
  export declare function html_style__(
9
9
  ...memo_style_def_a:html_attr_def_T[]
10
10
  ):(...style_def_a:html_attr_def_T[])=>string
11
+ export declare function background_image_style_(background_url:string):string
12
+ export declare function background_image_style_o_(background_url:string):{
13
+ 'background-image': string
14
+ }
15
+ export declare function html_style_url_(url:string):string
@@ -1,6 +1,5 @@
1
1
  /// <reference types="../attr/index.d.ts" />
2
2
  import { isArray } from '../isArray/index.js'
3
- const eol_semicolon_regex = /;\s*$/
4
3
  /**
5
4
  * Returns class style attribute from obj
6
5
  * @param {attr_def_T}style_def_a
@@ -9,39 +8,54 @@ const eol_semicolon_regex = /;\s*$/
9
8
  * style_({position: 'absolute, left: '5px'}) // returns 'position: absolute; left: 5px;'
10
9
  */
11
10
  export function html_style_(...style_def_a) {
12
- const a = []
13
- for (let i = 0; i < style_def_a.length; i++) {
14
- const style_def = style_def_a[i]
11
+ let a = []
12
+ for (let style_def of style_def_a) {
15
13
  if (typeof style_def === 'string') {
16
- a.push(semicolon__style_(style_def))
14
+ a.push(style_def.replace(/;$/, '') + ';')
17
15
  } else if (isArray(style_def)) {
18
- a.push(...style_def.map($=>semicolon__style_($)))
16
+ a.push(...style_def.map($=>$.replace(/;$/, '') + ';'))
19
17
  } else if (typeof style_def === 'object') {
20
18
  for (let key in style_def) {
21
19
  const val = style_def[key]
22
- if (val != null) a.push(`${key}: ${val};`)
20
+ if (val != null) a.push(`${key}:${val};`)
23
21
  }
24
22
  }
25
23
  }
26
24
  return a.join(' ')
27
25
  }
28
26
  /**
29
- * @param {string}style
27
+ * @param {attr_def_T}memo_style_def_a
28
+ * @returns {(...style_def_a:string[])=>string}
29
+ * @private
30
+ */
31
+ export function html_style__(memo_style_def_a) {
32
+ return (...style_a)=>html_style_(memo_style_def_a, ...style_a)
33
+ }
34
+ /**
35
+ * @param {string}background_url
30
36
  * @returns {string}
31
37
  * @private
32
38
  */
33
- function semicolon__style_(style) {
34
- return (
35
- eol_semicolon_regex.test(style)
36
- ? style
37
- : `${style};`
38
- )
39
+ export function background_image_style_(background_url) {
40
+ return html_style_({
41
+ 'background-image': html_style_url_(background_url)
42
+ })
39
43
  }
40
44
  /**
41
- * @param {attr_def_T}memo_style_def_a
42
- * @returns {(...style_def_a:string[])=>string}
45
+ * @param {string}background_url
46
+ * @returns {{'background-image': string}}
43
47
  * @private
44
48
  */
45
- export function html_style__(memo_style_def_a) {
46
- return (...style_a)=>html_style_(memo_style_def_a, ...style_a)
49
+ export function background_image_style_o_(background_url) {
50
+ return {
51
+ 'background-image': html_style_url_(background_url)
52
+ }
53
+ }
54
+ /**
55
+ * @param {string}url
56
+ * @returns {string}
57
+ * @private
58
+ */
59
+ export function html_style_url_(url) {
60
+ return 'url(' + '\'' + url + '\')'
47
61
  }
@@ -1,6 +1,12 @@
1
1
  import { test } from 'uvu'
2
2
  import { equal } from 'uvu/assert'
3
- import { html_style_, html_style__ } from './index.js'
3
+ import {
4
+ background_image_style_,
5
+ background_image_style_o_,
6
+ html_style_,
7
+ html_style__,
8
+ html_style_url_
9
+ } from './index.js'
4
10
  test('html_style_', ()=>{
5
11
  equal(
6
12
  html_style_('display: block', 'position: absolute'),
@@ -13,37 +19,37 @@ test('html_style_', ()=>{
13
19
  position: 'absolute',
14
20
  top: null,
15
21
  }),
16
- 'display: block; position: absolute;')
22
+ 'display: block; position:absolute;')
17
23
  equal(
18
24
  html_style_({
19
25
  display: 'block',
20
26
  top: null,
21
27
  }, 'position: absolute'),
22
- 'display: block; position: absolute;')
28
+ 'display:block; position: absolute;')
23
29
  equal(
24
30
  html_style_({
25
31
  display: 'block',
26
32
  top: null,
27
33
  }, ['position: absolute']),
28
- 'display: block; position: absolute;')
34
+ 'display:block; position: absolute;')
29
35
  equal(
30
36
  html_style_({
31
37
  display: 'block',
32
38
  top: null,
33
39
  }, ['position: absolute; top: 0']),
34
- 'display: block; position: absolute; top: 0;')
40
+ 'display:block; position: absolute; top: 0;')
35
41
  equal(
36
42
  html_style_({
37
43
  display: 'block',
38
44
  top: null,
39
45
  }, ['position: absolute; top: 0']),
40
- 'display: block; position: absolute; top: 0;')
46
+ 'display:block; position: absolute; top: 0;')
41
47
  equal(
42
48
  html_style_({
43
49
  display: 'block',
44
50
  top: null,
45
51
  }, ['position: absolute; top: 0;']),
46
- 'display: block; position: absolute; top: 0;')
52
+ 'display:block; position: absolute; top: 0;')
47
53
  })
48
54
  test('html_style__', ()=>{
49
55
  equal(
@@ -57,36 +63,53 @@ test('html_style__', ()=>{
57
63
  position: 'absolute',
58
64
  top: null,
59
65
  }),
60
- 'display: block; position: absolute;')
66
+ 'display: block; position:absolute;')
61
67
  equal(
62
68
  html_style__({
63
69
  display: 'block',
64
70
  top: null,
65
71
  })('position: absolute'),
66
- 'display: block; position: absolute;')
72
+ 'display:block; position: absolute;')
67
73
  equal(
68
74
  html_style__({
69
75
  display: 'block',
70
76
  top: null,
71
77
  })(['position: absolute']),
72
- 'display: block; position: absolute;')
78
+ 'display:block; position: absolute;')
73
79
  equal(
74
80
  html_style__({
75
81
  display: 'block',
76
82
  top: null,
77
83
  })(['position: absolute; top: 0']),
78
- 'display: block; position: absolute; top: 0;')
84
+ 'display:block; position: absolute; top: 0;')
79
85
  equal(
80
86
  html_style__({
81
87
  display: 'block',
82
88
  top: null,
83
89
  })(['position: absolute; top: 0']),
84
- 'display: block; position: absolute; top: 0;')
90
+ 'display:block; position: absolute; top: 0;')
85
91
  equal(
86
92
  html_style__({
87
93
  display: 'block',
88
94
  top: null,
89
95
  })(['position: absolute; top: 0;']),
90
- 'display: block; position: absolute; top: 0;')
96
+ 'display:block; position: absolute; top: 0;')
97
+ })
98
+ test('background_image_style_', ()=>{
99
+ equal(
100
+ background_image_style_('/foo/bar.svg'),
101
+ "background-image:url('/foo/bar.svg');")
102
+ })
103
+ test('background_image_style_o_', ()=>{
104
+ equal(
105
+ background_image_style_o_('/foo/bar.svg'),
106
+ {
107
+ 'background-image': "url('/foo/bar.svg')"
108
+ })
109
+ })
110
+ test('style_url_', ()=>{
111
+ equal(
112
+ html_style_url_('/foo/bar.svg'),
113
+ "url('/foo/bar.svg')")
91
114
  })
92
115
  test.run()
@@ -0,0 +1,2 @@
1
+ export declare function px_rem_(px?:number):number
2
+ export { px_rem_ as _px_rem, }
@@ -0,0 +1,5 @@
1
+ import { rem_px_ } from '../rem_px/index.js'
2
+ export function px_rem_(px = 16) {
3
+ return px / rem_px_(1)
4
+ }
5
+ export { px_rem_ as _px_rem, }
package/html/index.d.ts CHANGED
@@ -3,7 +3,7 @@ import { html_attr_, raw__html_attr_ } from '../all/html_attr/index.js'
3
3
  import { html_attrs_ } from '../all/html_attrs/index.js'
4
4
  import { html_class_, html_class__ } from '../all/html_class/index.js'
5
5
  import { html_dataset__data_attrs_ } from '../all/html_dataset__data_attrs/index.js'
6
- import { html_style_, html_style__ } from '../all/html_style/index.js'
6
+ import { html_style_, html_style__, html_style_url_ } from '../all/html_style/index.js'
7
7
  import { html_style__assign } from '../all/html_style__assign/index.js'
8
8
  import { html_styles_o_ } from '../all/html_styles_o/index.js'
9
9
  import { js_html_ } from '../all/js_html/index.js'
@@ -25,7 +25,7 @@ export { html_attrs_ as attrs_, html_attrs_ as _attrs }
25
25
  export { html_class_ as class_, html_class_ as _class, }
26
26
  export { html_class__ as class__, html_class__ as class_2, }
27
27
  export { html_dataset__data_attrs_ as dataset__data_attrs_ }
28
- export { html_style_ as style_, html_style_ as _style, }
28
+ export { html_style_ as style_, html_style_ as _style, html_style_url_ as style_url_ }
29
29
  export { html_style__ as style__, html_style__ as style_2, }
30
30
  export {
31
31
  html_style__assign as assign_style,
package/html/index.js CHANGED
@@ -3,7 +3,7 @@ import { html_attr_, raw__html_attr_ } from '../all/html_attr/index.js'
3
3
  import { html_attrs_ } from '../all/html_attrs/index.js'
4
4
  import { html_class_, html_class__ } from '../all/html_class/index.js'
5
5
  import { html_dataset__data_attrs_ } from '../all/html_dataset__data_attrs/index.js'
6
- import { html_style_, html_style__ } from '../all/html_style/index.js'
6
+ import { html_style_, html_style__, html_style_url_ } from '../all/html_style/index.js'
7
7
  import { html_style__assign } from '../all/html_style__assign/index.js'
8
8
  import { html_styles_o_ } from '../all/html_styles_o/index.js'
9
9
  import { js_html_ } from '../all/js_html/index.js'
@@ -25,7 +25,7 @@ export { html_attrs_ as attrs_, html_attrs_ as _attrs }
25
25
  export { html_class_ as class_, html_class_ as _class, }
26
26
  export { html_class__ as class__, html_class__ as class_2, }
27
27
  export { html_dataset__data_attrs_ as dataset__data_attrs_ }
28
- export { html_style_ as style_, html_style_ as _style, }
28
+ export { html_style_ as style_, html_style_ as _style, html_style_url_ as style_url_ }
29
29
  export { html_style__ as style__, html_style__ as style_2, }
30
30
  export {
31
31
  html_style__assign as assign_style,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ctx-core",
3
- "version": "5.25.5",
3
+ "version": "5.26.0",
4
4
  "description": "ctx-core core library",
5
5
  "keywords": [
6
6
  "ctx-core",