malinajs 0.6.57 → 0.6.60

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/compile.js CHANGED
@@ -18,9 +18,10 @@ function assert(x, info) {
18
18
  }
19
19
 
20
20
  function toCamelCase(name) {
21
- assert(name[name.length - 1] !== '-', 'Wrong name');
22
- return name.replace(/(?<!-)(\-\w)/g, function(part) {
23
- return part[1].toUpperCase();
21
+ assert(last(name) !== '-', 'Wrong name');
22
+ return name.replace(/(.\-\w)/g, function(part) {
23
+ if(part[0] == '-') return part;
24
+ return part[0] + part[2].toUpperCase();
24
25
  });
25
26
  }
26
27
  function Q(s) {
@@ -3869,6 +3870,7 @@ function processCSS() {
3869
3870
  }
3870
3871
  } else cleanSelectorItems.push(s);
3871
3872
  }
3873
+ while(cleanSelectorItems.length && ['WhiteSpace', 'Combinator'].includes(cleanSelectorItems[0].type)) cleanSelectorItems.shift();
3872
3874
  while(cleanSelectorItems.length && ['WhiteSpace', 'Combinator'].includes(last(cleanSelectorItems).type)) cleanSelectorItems.pop();
3873
3875
  if(!cleanSelectorItems.length || globalBlock) { // fully global?
3874
3876
  assert(origin.length);
@@ -4025,7 +4027,10 @@ function makeDom(data) {
4025
4027
  let n = new Node(e.name, {__node: e});
4026
4028
  e.attributes.forEach(a => {
4027
4029
  if(a.name == 'class') {
4028
- if(a.value != null) n.className += ' ' + a.value;
4030
+ if(a.value != null) {
4031
+ if(a.value.includes('{')) n.dynClass = true;
4032
+ else n.className += ' ' + a.value;
4033
+ }
4029
4034
  n.attributes[a.name] = a.value;
4030
4035
  } else if(a.name == 'id') n.attributes.id = n.id = a.value;
4031
4036
  else if(a.name.startsWith('class:')) {
@@ -4102,12 +4107,16 @@ Node.prototype.getElementsByClassName = function(names) {
4102
4107
  if(names.length != 1) throw 'Not supported';
4103
4108
  let cls = names[0];
4104
4109
 
4110
+ let rx = RegExp('(^|\\s)' + cls + '(\\s|$)', 'i');
4105
4111
  let result = [];
4106
- this.childNodes.forEach(n => {
4107
- let rx = RegExp('(^|\\s)' + cls + '(\\s|$)', 'i');
4108
- if(rx.test(n.className)) result.push(n);
4109
- result.push.apply(result, n.getElementsByClassName(cls));
4110
- });
4112
+ const walk = (node) => {
4113
+ node.childNodes.forEach(n => {
4114
+ if(n.dynClass) result.push(n);
4115
+ else if(rx.test(n.className)) result.push(n);
4116
+ walk(n);
4117
+ });
4118
+ };
4119
+ walk(this);
4111
4120
  return result;
4112
4121
  };
4113
4122
 
package/malina.js CHANGED
@@ -19,9 +19,10 @@
19
19
  }
20
20
 
21
21
  function toCamelCase(name) {
22
- assert(name[name.length - 1] !== '-', 'Wrong name');
23
- return name.replace(/(?<!-)(\-\w)/g, function(part) {
24
- return part[1].toUpperCase();
22
+ assert(last(name) !== '-', 'Wrong name');
23
+ return name.replace(/(.\-\w)/g, function(part) {
24
+ if(part[0] == '-') return part;
25
+ return part[0] + part[2].toUpperCase();
25
26
  });
26
27
  }
27
28
  function Q(s) {
@@ -3870,6 +3871,7 @@
3870
3871
  }
3871
3872
  } else cleanSelectorItems.push(s);
3872
3873
  }
3874
+ while(cleanSelectorItems.length && ['WhiteSpace', 'Combinator'].includes(cleanSelectorItems[0].type)) cleanSelectorItems.shift();
3873
3875
  while(cleanSelectorItems.length && ['WhiteSpace', 'Combinator'].includes(last(cleanSelectorItems).type)) cleanSelectorItems.pop();
3874
3876
  if(!cleanSelectorItems.length || globalBlock) { // fully global?
3875
3877
  assert(origin.length);
@@ -4026,7 +4028,10 @@
4026
4028
  let n = new Node(e.name, {__node: e});
4027
4029
  e.attributes.forEach(a => {
4028
4030
  if(a.name == 'class') {
4029
- if(a.value != null) n.className += ' ' + a.value;
4031
+ if(a.value != null) {
4032
+ if(a.value.includes('{')) n.dynClass = true;
4033
+ else n.className += ' ' + a.value;
4034
+ }
4030
4035
  n.attributes[a.name] = a.value;
4031
4036
  } else if(a.name == 'id') n.attributes.id = n.id = a.value;
4032
4037
  else if(a.name.startsWith('class:')) {
@@ -4103,12 +4108,16 @@
4103
4108
  if(names.length != 1) throw 'Not supported';
4104
4109
  let cls = names[0];
4105
4110
 
4111
+ let rx = RegExp('(^|\\s)' + cls + '(\\s|$)', 'i');
4106
4112
  let result = [];
4107
- this.childNodes.forEach(n => {
4108
- let rx = RegExp('(^|\\s)' + cls + '(\\s|$)', 'i');
4109
- if(rx.test(n.className)) result.push(n);
4110
- result.push.apply(result, n.getElementsByClassName(cls));
4111
- });
4113
+ const walk = (node) => {
4114
+ node.childNodes.forEach(n => {
4115
+ if(n.dynClass) result.push(n);
4116
+ else if(rx.test(n.className)) result.push(n);
4117
+ walk(n);
4118
+ });
4119
+ };
4120
+ walk(this);
4112
4121
  return result;
4113
4122
  };
4114
4123
 
@@ -5917,7 +5926,7 @@
5917
5926
  return {event, fn};
5918
5927
  }
5919
5928
 
5920
- const version = '0.6.57';
5929
+ const version = '0.6.60';
5921
5930
 
5922
5931
 
5923
5932
  async function compile(source, config = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "malinajs",
3
- "version": "0.6.57",
3
+ "version": "0.6.60",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "prepare": "npm run build",
package/readme.md CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  ## Malina.js
3
3
 
4
- <img align="right" width="200" height="200" src="malinajs2.png" />
4
+ <img align="right" width="200" height="200" src="https://github.com/malinajs/malinajs/raw/master/malinajs2.png" />
5
5
 
6
6
  Malina.js builds your web-application to use it **without framework on frontend side**. Therefore your web-app becomes thinner and faster, and the application itself consist of **vanilla JavaScript**, look at [examples](https://malinajs.github.io/repl/). [TodoMVC example](https://malina-todomvc.surge.sh) **2.7kb** (gzipped) and [source code](https://github.com/malinajs/todomvc)
7
7
 
package/runtime.js CHANGED
@@ -748,6 +748,18 @@ const unwrapProps = (cd, props, fn) => {
748
748
  }
749
749
  };
750
750
 
751
+
752
+ const mount = (label, component, option) => {
753
+ const app = component(label, option);
754
+ const destroy = () => label.textContent = '';
755
+
756
+ if(app?._d) {
757
+ app._d.push(destroy);
758
+ return app;
759
+ }
760
+ return {destroy};
761
+ };
762
+
751
763
  function $$htmlBlock($cd, tag, fn) {
752
764
  let lastElement;
753
765
  let create = (html) => {
@@ -947,4 +959,4 @@ function $$eachBlock($parentCD, label, onlyChild, fn, getKey, itemTemplate, bind
947
959
  }, {ro: true, cmp: $$compareArray});
948
960
  }
949
961
 
950
- export { $$addEventForComponent, $$awaitBlock, $$cloneDeep, $$compareArray, $$compareDeep, $$deepComparator, $$eachBlock, $$htmlBlock, $$htmlToFragment, $$htmlToFragmentClean, $$ifBlock, $$removeElements, $$removeItem, $ChangeDetector, $base, $context, $digest, $insertElementByOption, $makeEmitter, $onDestroy, $onMount, $readOnlyBase, $tick, $watch, $watchReadOnly, __app_onerror, __bindActionSubscribe, addClass, addEvent, addStyles, attachAnchor, attachSlot, attachSlotBase, attchExportedFragment, autoSubscribe, bindAction, bindAttribute, bindAttributeBase, bindClass, bindInput, bindStyle, bindText, callComponent, cd_onDestroy, childNodes, cloneDeep, configure, createTextNode, current_component, eachDefaultKey, exportFragment, fire, firstChild, getFinalLabel, insertAfter, isArray, isFunction, keyComparator, makeClassResolver, makeComponent, makeExternalProperty, makeSlot, makeSlotStatic, noop, observeProps, prefixPush, removeElementsBetween, setClassToElement, spreadAttributes, svgToFragment, unwrapProps };
962
+ export { $$addEventForComponent, $$awaitBlock, $$cloneDeep, $$compareArray, $$compareDeep, $$deepComparator, $$eachBlock, $$htmlBlock, $$htmlToFragment, $$htmlToFragmentClean, $$ifBlock, $$removeElements, $$removeItem, $ChangeDetector, $base, $context, $digest, $insertElementByOption, $makeEmitter, $onDestroy, $onMount, $readOnlyBase, $tick, $watch, $watchReadOnly, __app_onerror, __bindActionSubscribe, addClass, addEvent, addStyles, attachAnchor, attachSlot, attachSlotBase, attchExportedFragment, autoSubscribe, bindAction, bindAttribute, bindAttributeBase, bindClass, bindInput, bindStyle, bindText, callComponent, cd_onDestroy, childNodes, cloneDeep, configure, createTextNode, current_component, eachDefaultKey, exportFragment, fire, firstChild, getFinalLabel, insertAfter, isArray, isFunction, keyComparator, makeClassResolver, makeComponent, makeExternalProperty, makeSlot, makeSlotStatic, mount, noop, observeProps, prefixPush, removeElementsBetween, setClassToElement, spreadAttributes, svgToFragment, unwrapProps };