solely 0.0.10 → 0.0.11

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/README.md CHANGED
@@ -1 +1,148 @@
1
- # dev
1
+ # Solely
2
+
3
+ ## 项目简介
4
+
5
+ 在当今的软件开发领域,前端框架的选择对于项目的成功至关重要。我们注意到,市面上的许多前端框架虽然功能强大,但往往过于复杂,与原生JavaScript(JS)或TypeScript(TS)的写法差异较大,这不仅增加了开发者的学习成本,也不利于技术的积累和迁移。特别是对于小型项目,这些框架的全面性反而导致了资源的浪费,因为它们往往包含了许多项目并不需要的复杂功能。
6
+
7
+ 为了解决这一问题,我们开发了一款简单而高效的前端框架。它的核心优势在于:
8
+
9
+ 1. **简化复杂性**:我们的框架设计简洁,易于上手,与原生JS/TS的写法保持一致,便于技术积累。
10
+ 2. **专注核心功能**:针对小型项目,我们的框架专注于提供必要的响应式功能,避免了不必要的功能堆砌,从而减少了项目的臃肿。
11
+ 3. **性能优化**:轻量级的设计减少了资源消耗,提高了项目运行效率。
12
+ 4. **技术兼容性**:与原生JS/TS的高兼容性,使得开发者可以在不同项目间轻松迁移和应用技术。
13
+ 5. **高度定制性**:根据项目需求灵活定制功能,避免功能浪费。
14
+
15
+ 我们致力于持续优化框架,确保它能够适应不断变化的前端开发需求,并根据用户反馈进行调整和改进。我们的目标是提供一个既满足小型项目需求,又不牺牲性能和易用性的前端解决方案。
16
+
17
+ ## 安装
18
+
19
+ ```shell
20
+ npm i solely
21
+ ```
22
+
23
+ ## 语法规则
24
+
25
+ ### 响应式数据
26
+
27
+ solely 中内置了响应式数据 $data,每当 $data 中的数据更改时它也会同步更新页面。
28
+
29
+ ### 模板语法
30
+
31
+ 使用 solely,通过基于 HTML 的模板语法,能够精准地将数据绑定到呈现的 DOM 上。solely 的所有模板都是语法正确的 HTML,可被标准的浏览器和 HTML 解析器顺利解析。
32
+
33
+ ### 文本插值
34
+
35
+ 文本插值是最基础的数据绑定形式,使用双大括号语法。在这些语法中,this 指向 Element 实例。为了简化书写,可以省略 $data 前面的 this,两种写法在功能上等同:
36
+
37
+ ```html
38
+ <div>消息: {{ this.$data.msg }}</div>
39
+ <div>消息: {{ $data.msg }}</div>
40
+ ```
41
+
42
+ 双大括号标签会被替换为 Element 实例中 $data.msg 的值。同时每次 $data.msg 属性更改时它也会同步更新。
43
+
44
+ ### Attribute 绑定
45
+
46
+ 双大括号不能在 HTML attributes 中使用。想要响应式地绑定一个 attribute,应该使用 s-[attribute] 指令,即在需要绑定的属性前面添加 s- 前缀:
47
+
48
+ ```html
49
+ <div s-id="$data.id"></div>
50
+ ```
51
+
52
+ s-[attribute] 指令指示 solely 将元素的 id attribute 与组件的 $data.id 属性保持一致。
53
+
54
+ **注意:** s-[attribute] 也可以用于 Class 与 Style 绑定,如 s-class、s-style 等。
55
+
56
+ ### 布尔型 Attribute​
57
+
58
+ 布尔型 attribute 依据 true / false 值来决定 attribute 是否应该存在于该元素上。如:checked、 disabled、 readOnly、selected 等
59
+ s-[attribute] 在这种场景下的行为略有不同:
60
+
61
+ ```html
62
+ <button s-disabled="$data.disabled">Button</button>
63
+ ```
64
+
65
+ 当 $data.disabled 为真值时,元素会包含这个 disabled attribute。而当其为其他假值时 attribute 将被忽略。
66
+
67
+ ### 使用 JavaScript 表达式 ​
68
+
69
+ 至此,我们仅在模板中绑定了一些简单的属性名。但是 solely 实际上在所有的数据绑定中都支持除了 eval、Function、setTimeout、setInterval 等部分不安全代码除外,所有的 JavaScript 表达式。
70
+
71
+ ```html
72
+ <div>{{ $data.number + 1 }}</div>
73
+
74
+ <div>{{ $data.ok ? 'YES' : 'NO' }}</div>
75
+
76
+ <div>{{ this.getMessage() }}</div>
77
+ ```
78
+
79
+ ```ts
80
+ @CustomElement({
81
+ // 模块名称
82
+ tagName: "sample-message",
83
+ // html模板字符串
84
+ template: template,
85
+ })
86
+ export class SampleMessage extends BaseElement {
87
+ constructor() {
88
+ super();
89
+ }
90
+
91
+ // 初始化函数
92
+ async onInit() {
93
+ this.$data = {
94
+ number: 1,
95
+ ok: true,
96
+ };
97
+ }
98
+
99
+ getMessage() {
100
+ return "message";
101
+ }
102
+ // 其他内容
103
+ }
104
+ ```
105
+
106
+ **注意:** 绑定在表达式中的方法在组件每次更新时都会被重新调用,因此不应该产生任何副作用,比如改变数据或触发异步操作。
107
+
108
+ ### 事件绑定
109
+
110
+ solely 采用与标签中直接绑定事件相同的方式,不需要进行额外的处理。与文本插值和 Attribute 绑定相同,this 和$data 也已经内置,不同的是,value 也可以直接被使用。
111
+
112
+ ```html
113
+ <button onclick="$data.count++">Add 1</button>
114
+ <input
115
+ type="search"
116
+ placeholder="搜索"
117
+ s-value="$data.searchText"
118
+ onchange="$data.searchText=value"
119
+ />
120
+ <button onclick="this.search()">搜索</button>
121
+ ```
122
+
123
+ ### 条件判断
124
+
125
+ solely 引入了 `<If>` 标签,基于 `condition` 关键字绑定的表达式值的真假性,有条件地渲染元素或模板片段。该标签不会在 HTML 中渲染,只控制内部元素的展示。
126
+
127
+ ```html
128
+ <If condition="$data.if">
129
+ <div>内容1</div>
130
+ <div>内容2</div>
131
+ <div>内容3</div>
132
+ </If>
133
+ ```
134
+
135
+ ### 列表渲染
136
+
137
+ solely 引入了 `<For>` 标签,根据由 `each` 关键字绑定的表达式值返回的数组来渲染列表。`item` 关键字是迭代的别名,默认为 `item`,但可以通过为其赋值进行修改。标签内部的元素可以使用 `item` 关键字绑定的内容,使用 `index` 关键字绑定内容的索引。该标签不会在 HTML 中渲染,只控制内部元素的展示。
138
+
139
+ ```html
140
+ <For each="$data.f" item="i">
141
+ <For each="$data.e">
142
+ <div>For 外层 {{i}} 内层 {{item}}</div>
143
+ <button onclick="this.onClick(i,item)">点击</button>
144
+ </For>
145
+ </For>
146
+ <!-- 使用index指定索引 -->
147
+ <For each="$data.pages" item="page" index="i"></For>
148
+ ```
@@ -1,5 +1,6 @@
1
1
  export interface Manifest {
2
2
  tagName: string;
3
3
  template?: string;
4
+ className?: string;
4
5
  }
5
6
  export declare const CustomElement: (manifest: Manifest) => ClassDecorator;
package/dist/solely.js CHANGED
@@ -1,8 +1,8 @@
1
- var R = (e) => {
1
+ var M = (e) => {
2
2
  throw TypeError(e);
3
3
  };
4
- var S = (e, t, n) => t.has(e) || R("Cannot " + n);
5
- var h = (e, t, n) => (S(e, t, "read from private field"), n ? n.call(e) : t.get(e)), y = (e, t, n) => t.has(e) ? R("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, n), g = (e, t, n, s) => (S(e, t, "write to private field"), s ? s.call(e, n) : t.set(e, n), n), k = (e, t, n) => (S(e, t, "access private method"), n);
4
+ var S = (e, t, n) => t.has(e) || M("Cannot " + n);
5
+ var h = (e, t, n) => (S(e, t, "read from private field"), n ? n.call(e) : t.get(e)), y = (e, t, n) => t.has(e) ? M("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, n), g = (e, t, n, s) => (S(e, t, "write to private field"), s ? s.call(e, n) : t.set(e, n), n), k = (e, t, n) => (S(e, t, "access private method"), n);
6
6
  const Q = /<!--(?:.|\s)*?-->|<[a-zA-Z0-9\-/](?:"[^"]*"|'[^']*'|[^'">])*>/g, X = /<\/?([^\s]+?)[/\s>]/, J = /\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g, K = ["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"], w = /\{\{(.+?)\}\}/g;
7
7
  function Z(e) {
8
8
  return e.replace(/>\s+</g, "><").replace(/\s+/g, " ");
@@ -21,8 +21,8 @@ function G(e, t) {
21
21
  if (r === null) break;
22
22
  if (!r[0].trim()) continue;
23
23
  const [a, i] = r[1] ? r[1].trim().split("=") : [r[2], r[3].trim().slice(1, -1)];
24
- if (Y.includes(a) || a.startsWith("on-"))
25
- s.on[a.startsWith("on-") ? a.slice(3) : a.slice(2)] = j(e, `return (${i})`);
24
+ if (U.includes(a) || a.startsWith("on-"))
25
+ s.on[a.startsWith("on-") ? a.slice(3) : a.slice(2)] = R(e, `return (${i})`);
26
26
  else if (a.startsWith("s-")) {
27
27
  const m = a.slice(2);
28
28
  switch (m) {
@@ -47,12 +47,12 @@ function G(e, t) {
47
47
  o.lastIndex--;
48
48
  }
49
49
  if (n === "For" ? s.fn = (r) => f(e, s.attrs.each, r) : (n === "If" || n === "ElseIf") && (s.fn = (r) => f(e, s.attrs.condition, r)), s.model) {
50
- const r = s.model.replace("this.", "").replace("$data.", ""), a = (m) => f(e, `$data.${r}`, m), i = (m) => j(e, `$data.${r}=${m}`);
50
+ const r = s.model.replace("this.", "").replace("$data.", ""), a = (m) => f(e, `$data.${r}`, m), i = (m) => R(e, `$data.${r}=${m}`);
51
51
  n === "input" ? s.attrs.type === "checkbox" || s.attrs.type === "radio" ? (s.props.checked = a, s.on.change = i("checked")) : (s.props.value = a, s.on.input = i("value")) : n === "textarea" ? (s.props.value = a, s.on.input = i("value")) : n === "select" && (s.props.value = a, s.on.change = i("value"));
52
52
  }
53
53
  return s;
54
54
  }
55
- function U(e, t) {
55
+ function N(e, t) {
56
56
  const n = [];
57
57
  if (!t) return n;
58
58
  t = Z(t);
@@ -67,7 +67,7 @@ function U(e, t) {
67
67
  const c = t.substring(a, m).trim();
68
68
  if (c) {
69
69
  w.lastIndex = 0;
70
- const A = !w.test(c) ? c : ($) => c.replace(w, (M, C) => f(e, C, $));
70
+ const A = !w.test(c) ? c : ($) => c.replace(w, (L, C) => f(e, C, $));
71
71
  l.push({
72
72
  rootId: 0,
73
73
  tagName: "text",
@@ -115,7 +115,7 @@ const f = (e, t, n) => {
115
115
  } catch (s) {
116
116
  console.error(s);
117
117
  }
118
- }, j = (e, t) => (n, s) => P(["$data", "event", "value", "checked", ...s.map((r) => r.item), t]).bind(e)(e.$data, n, n.target.value, n.target.checked, ...s.map((r) => r.value)), Y = [
118
+ }, R = (e, t) => (n, s) => P(["$data", "event", "value", "checked", ...s.map((r) => r.item), t]).bind(e)(e.$data, n, n.target.value, n.target.checked, ...s.map((r) => r.value)), U = [
119
119
  "onabort",
120
120
  "onautocomplete",
121
121
  "onautocompleteerror",
@@ -178,7 +178,7 @@ const f = (e, t, n) => {
178
178
  "ontoggle",
179
179
  "onvolumechange",
180
180
  "onwaiting"
181
- ], N = /* @__PURE__ */ (() => {
181
+ ], Y = /* @__PURE__ */ (() => {
182
182
  const e = typeof requestAnimationFrame == "function" ? (t) => requestAnimationFrame(t) : typeof Promise < "u" ? (t) => Promise.resolve().then(t) : (t) => setTimeout(t, 0);
183
183
  return (t, ...n) => {
184
184
  if (typeof t != "function")
@@ -304,8 +304,8 @@ const et = "http://www.w3.org/1999/xlink", nt = "http://www.w3.org/2000/xmlns/",
304
304
  l + 1 < t.length && ht(t[l + 1]) && !u && (b(e, t[l + 1].children, n, s, !1, !0), u = !0), l++;
305
305
  } else if (c.tagName === "For") {
306
306
  const { item: u = "item", index: A = "index" } = c.attrs;
307
- (c.fn(n) || []).forEach((M, C) => {
308
- const B = { item: u, value: M, index: A, valueIndex: C };
307
+ (c.fn(n) || []).forEach((L, C) => {
308
+ const B = { item: u, value: L, index: A, valueIndex: C };
309
309
  b(e, c.children, [...n, B], s, !1);
310
310
  });
311
311
  } else {
@@ -333,7 +333,7 @@ const et = "http://www.w3.org/1999/xlink", nt = "http://www.w3.org/2000/xmlns/",
333
333
  const c = n[o];
334
334
  I(e, c), o++;
335
335
  }
336
- }, L = (e, t, n = []) => {
336
+ }, j = (e, t, n = []) => {
337
337
  if (!t || t.length === 0) return [];
338
338
  const s = [];
339
339
  return b(s, t || [], [], 0, !0), z(e, n, s), s;
@@ -347,8 +347,10 @@ class yt extends HTMLElement {
347
347
  y(this, E, []);
348
348
  y(this, d, []);
349
349
  y(this, v, !1);
350
- const n = this._manifest;
351
- n != null && n.template && typeof n.template == "string" && g(this, E, U(this, n.template));
350
+ const n = this._manifest || {};
351
+ n.template && typeof n.template == "string" && g(this, E, N(this, n.template)), (n.className || n.tagName || "").split(" ").forEach((o) => {
352
+ this.classList.add(o);
353
+ });
352
354
  }
353
355
  get $data() {
354
356
  let n = h(this, x);
@@ -358,7 +360,7 @@ class yt extends HTMLElement {
358
360
  g(this, x, n), k(this, p, F).call(this);
359
361
  }
360
362
  connectedCallback() {
361
- g(this, d, L(this, h(this, E), h(this, d))), this.onInit();
363
+ g(this, d, j(this, h(this, E), h(this, d))), this.onInit();
362
364
  }
363
365
  onInit() {
364
366
  }
@@ -375,8 +377,8 @@ x = new WeakMap(), E = new WeakMap(), d = new WeakMap(), v = new WeakMap(), p =
375
377
  set: (s, o, r) => (s[o] !== r && (s[o] = r, k(this, p, F).call(this)), !0)
376
378
  });
377
379
  }, F = function() {
378
- h(this, v) || (g(this, v, !0), N(() => {
379
- g(this, d, L(this, h(this, E), h(this, d))), g(this, v, !1);
380
+ h(this, v) || (g(this, v, !0), Y(() => {
381
+ g(this, d, j(this, h(this, E), h(this, d))), g(this, v, !1);
380
382
  }));
381
383
  };
382
384
  const bt = (e) => (t) => {
@@ -393,8 +395,8 @@ export {
393
395
  bt as CustomElement,
394
396
  P as createFunction,
395
397
  q as isObject,
396
- Y as listeners,
397
- U as parseHtml,
398
- L as patch,
399
- N as runInAsyncQueue
398
+ U as listeners,
399
+ N as parseHtml,
400
+ j as patch,
401
+ Y as runInAsyncQueue
400
402
  };
@@ -1 +1 @@
1
- (function(i,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(i=typeof globalThis<"u"?globalThis:i||self,f(i.solely={}))})(this,function(i){"use strict";var G=i=>{throw TypeError(i)};var O=(i,f,h)=>f.has(i)||G("Cannot "+h);var b=(i,f,h)=>(O(i,f,"read from private field"),h?h.call(i):f.get(i)),I=(i,f,h)=>f.has(i)?G("Cannot add the same private member more than once"):f instanceof WeakSet?f.add(i):f.set(i,h),E=(i,f,h,S)=>(O(i,f,"write to private field"),S?S.call(i,h):f.set(i,h),h),C=(i,f,h)=>(O(i,f,"access private method"),h);var x,k,y,A,g,P,q;const f=/<!--(?:.|\s)*?-->|<[a-zA-Z0-9\-/](?:"[^"]*"|'[^']*'|[^'">])*>/g,h=/<\/?([^\s]+?)[/\s>]/,S=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g,U=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],w=/\{\{(.+?)\}\}/g;function Y(e){return e.replace(/>\s+</g,"><").replace(/\s+/g," ")}function N(e,t){const n=(t.match(h)||[])[1]||"",s={rootId:0,tagName:n,attrs:{},props:{},on:{},children:[]},r=new RegExp(S);for(;;){const o=r.exec(t);if(o===null)break;if(!o[0].trim())continue;const[a,l]=o[1]?o[1].trim().split("="):[o[2],o[3].trim().slice(1,-1)];if(D.includes(a)||a.startsWith("on-"))s.on[a.startsWith("on-")?a.slice(3):a.slice(2)]=B(e,`return (${l})`);else if(a.startsWith("s-")){const p=a.slice(2);switch(p){case"model":s.model=l;break;case"style":s.styles=u=>d(e,l,u);break;case"class":s.classes=u=>d(e,l,u);break;case"readonly":s.props.readOnly=u=>d(e,l,u);break;default:s.props[p]=u=>d(e,l,u);break}}else s.attrs[a]=l;r.lastIndex--}if(n==="For"?s.fn=o=>d(e,s.attrs.each,o):(n==="If"||n==="ElseIf")&&(s.fn=o=>d(e,s.attrs.condition,o)),s.model){const o=s.model.replace("this.","").replace("$data.",""),a=p=>d(e,`$data.${o}`,p),l=p=>B(e,`$data.${o}=${p}`);n==="input"?s.attrs.type==="checkbox"||s.attrs.type==="radio"?(s.props.checked=a,s.on.change=l("checked")):(s.props.value=a,s.on.input=l("value")):n==="textarea"?(s.props.value=a,s.on.input=l("value")):n==="select"&&(s.props.value=a,s.on.change=l("value"))}return s}function V(e,t){const n=[];if(!t)return n;t=Y(t);const s=[],r=[],o=()=>{var l;return s.length===0?n:(l=s[s.length-1]).children||(l.children=[])};let a=0;return t.replace(f,(l,p)=>{const u=o();if(p>a){const c=t.substring(a,p).trim();if(c){w.lastIndex=0;const T=!w.test(c)?c:R=>c.replace(w,(Z,L)=>d(e,L,R));u.push({rootId:0,tagName:"text",attrs:{},props:{},on:{},content:T,children:[]})}}if(a=p+l.length,l.startsWith("<!--")&&l.endsWith("-->"))u.push({rootId:0,tagName:"comment",attrs:{},props:{},on:{},content:l.slice(4,-3),children:[]});else if(l.startsWith("</")){const c=r.pop();for(;s.length>0&&s[s.length-1].tagName!==c;)s.pop();s.pop()}else{const c=N(e,l),m=l.endsWith("/>")||U.includes(c.tagName);u.push(c),m||(s.push(c),r.push(c.tagName))}return""}),t.length>a&&n.push({rootId:0,tagName:"text",attrs:{},props:{},on:{},content:t.substring(a).trim(),children:[]}),n}const d=(e,t,n)=>{try{return W(["$data",...n.map(r=>r.item),`return (${t})`]).bind(e)(e.$data,...n.map(r=>r.value))}catch(s){console.error(s)}},B=(e,t)=>(n,s)=>W(["$data","event","value","checked",...s.map(o=>o.item),t]).bind(e)(e.$data,n,n.target.value,n.target.checked,...s.map(o=>o.value)),D=["onabort","onautocomplete","onautocompleteerror","onblur","oncancel","oncanplay","oncanplaythrough","onchange","onclick","onclose","oncontextmenu","oncuechange","ondblclick","ondrag","ondragend","ondragenter","ondragexit","ondragleave","ondragover","ondragstart","ondrop","ondurationchange","onemptied","onended","onerror","onfocus","oninput","oninvalid","onkeydown","onkeypress","onkeyup","onload","onloadeddata","onloadedmetadata","onloadstart","onmousedown","onmouseenter","onmouseleave","onmousemove","onmouseout","onmouseover","onmouseup","onwheel","onpause","onplay","onplaying","onprogress","onratechange","onreset","onresize","onscroll","onseeked","onseeking","onselect","onshow","onstalled","onsubmit","onsuspend","ontimeupdate","ontoggle","onvolumechange","onwaiting"],Q=(()=>{const e=typeof requestAnimationFrame=="function"?t=>requestAnimationFrame(t):typeof Promise<"u"?t=>Promise.resolve().then(t):t=>setTimeout(t,0);return(t,...n)=>{if(typeof t!="function")throw new Error("runInAsyncQueue expects a function as its first argument");e(()=>t(...n))}})(),F={};function W(e){const t=e.join(",");if(!F[t]){const n=e[e.length-1];if(n.trim()==="")throw new Error("Function body is empty");if(tt(n))throw new Error("Input contains potentially dangerous code: "+n);const s=new Function(...e);F[t]=s}return F[t]}function tt(e){return["eval","Function","setTimeout","setInterval","window","global","require","XMLHttpRequest","fetch","console","debugger","process","document","importScripts","String.raw","Object.prototype","JSON.parse"].some(n=>e.includes(n))}const et="http://www.w3.org/1999/xlink",nt="http://www.w3.org/2000/xmlns/",st="http://www.w3.org/XML/1998/namespace",ot="http://www.w3.org/2000/svg",_=e=>typeof e.content=="function"?e.content(e.loops||[]):e.content||"",rt=e=>{const t=_(e),n=e.elm;n.textContent!==t&&(n.textContent=t)},z=(e,t,n=[])=>{Object.keys(t).forEach(s=>{const r=t[s](n);e[s]!==r&&(e[s]=r)})},X=(e,t)=>{const{styles:n,attrs:s,loops:r=[]}=t;if(!n)return;const o=[];s!=null&&s.style&&o.push(s.style);const a=n(r);o.push(...at(a)),e.style.cssText=o.join(";")},J=(e,t)=>{const{classes:n,attrs:s,loops:r=[]}=t;if(!n)return;const o=[];s!=null&&s.class&&o.push(...s.class.split(" ").filter(l=>l!==""));const a=n(r);o.push(...ct(a)),e.className=Array.from(new Set(o)).join(" ")},at=e=>typeof e=="object"&&!Array.isArray(e)?Object.keys(e).map(t=>`${t}:${e[t]}`):typeof e=="string"?[e]:Array.isArray(e)?e.flatMap(t=>typeof t=="string"?[t]:Object.keys(t).map(n=>`${n}:${t[n]}`)):[],ct=e=>typeof e=="object"&&!Array.isArray(e)?Object.keys(e).filter(t=>e[t]).map(t=>t):typeof e=="string"?e.split(" ").filter(t=>t!==""):Array.isArray(e)?e.flatMap(t=>typeof t=="string"?t.split(" ").filter(n=>n!==""):Object.keys(t).filter(n=>t[n])):[],it=(e,t)=>{const n=t.elm;z(n,t.props,t.loops),J(n,t),X(n,t),K(n,e.children,t.children)},lt=(e,t)=>{switch(t.elm=e.elm,t.tagName){case"comment":break;case"text":rt(t);break;case"slot":break;default:it(e,t);break}},j=(e,t,n)=>{n?e.insertBefore(t,n):e.appendChild(t)},ut=(e,t,n)=>{const s=_(t),r=document.createTextNode(s);t.elm=r,j(e,r,n)},ft=(e,t,n)=>{const s=t.content,r=document.createComment(s);t.elm=r,j(e,r,n)},mt=(e,t,n,s)=>{t.tagName==="svg"&&(s=ot);const r=s?document.createElementNS(s,t.tagName):document.createElement(t.tagName);Object.keys(t.attrs).forEach(o=>{const a=t.attrs[o]||"";o.charAt(0)!=="x"?r.setAttribute(o,a):o.startsWith("xml:")?r.setAttributeNS(st,o,a):o.startsWith("xlink:")?r.setAttributeNS(et,o,a):o.startsWith("xmlns:")?r.setAttributeNS(nt,o,a):r.setAttribute(o,a)}),Object.keys(t.on).forEach(o=>{r.addEventListener(o,a=>t.on[o](a,t.loops||[]),!1)}),z(r,t.props,t.loops),J(r,t),X(r,t),t.elm=r,j(e,r,n),t.tagName==="foreignObject"&&(s=void 0),t.children.forEach(o=>{$(r,o,void 0,s)})},$=(e,t,n,s)=>{switch(t.tagName){case"comment":ft(e,t,n);break;case"text":ut(e,t,n);break;default:mt(e,t,n,s);break}},pt=e=>e&&(e.tagName==="ElseIf"||e.tagName==="comment"),ht=e=>e&&e.tagName==="Else",v=(e,t,n=[],s=0,r=!0,o=!1)=>{var a,l,p;for(let u=0;u<t.length;u++){const c=t[u];if(c.tagName==="If"){let m=!1;for(((a=c.fn)==null?void 0:a.call(c,n))&&(v(e,c.children,n,s,!1,!0),m=!0);u+1<t.length&&pt(t[u+1]);)((p=(l=t[u+1]).fn)==null?void 0:p.call(l,n))&&!m&&(v(e,t[u+1].children,n,s,!1,!0),m=!0),u++;u+1<t.length&&ht(t[u+1])&&!m&&(v(e,t[u+1].children,n,s,!1,!0),m=!0),u++}else if(c.tagName==="For"){const{item:m="item",index:T="index"}=c.attrs;(c.fn(n)||[]).forEach((Z,L)=>{const bt={item:m,value:Z,index:T,valueIndex:L};v(e,c.children,[...n,bt],s,!1)})}else{const m={...c,loops:n,children:[],rootId:s,isIf:o};v(m.children,c.children,n),e.push(m)}r&&s++}},K=(e,t,n)=>{var o,a,l,p,u;let s=0,r=0;for(;s<t.length&&r<n.length;){const c=t[s],m=n[r];c.rootId===m.rootId?(m.isIf?((o=c.elm)==null||o.remove(),$(e,m,(a=t[s+1])==null?void 0:a.elm)):lt(c,m),r++,s++):c.rootId>m.rootId?((l=c.elm)==null||l.remove(),s++):($(e,m,(p=t[s+1])==null?void 0:p.elm),r++)}for(;s<t.length;)(u=t[s].elm)==null||u.remove(),s++;for(;r<n.length;){const c=n[r];$(e,c),r++}},H=(e,t,n=[])=>{if(!t||t.length===0)return[];const s=[];return v(s,t||[],[],0,!0),K(e,n,s),s},M=e=>typeof e=="object"&&e!=null;class dt extends HTMLElement{constructor(){super();I(this,g);I(this,x,{});I(this,k,[]);I(this,y,[]);I(this,A,!1);const n=this._manifest;n!=null&&n.template&&typeof n.template=="string"&&E(this,k,V(this,n.template))}get $data(){let n=b(this,x);return M(n)&&(n=C(this,g,P).call(this,n)),n}set $data(n){E(this,x,n),C(this,g,q).call(this)}connectedCallback(){E(this,y,H(this,b(this,k),b(this,y))),this.onInit()}onInit(){}disconnectedCallback(){console.log("disconnectedCallback")}}x=new WeakMap,k=new WeakMap,y=new WeakMap,A=new WeakMap,g=new WeakSet,P=function(n){return new Proxy(n,{get:(s,r)=>{let o=s[r];return M(o)&&(o=C(this,g,P).call(this,o)),o},set:(s,r,o)=>(s[r]!==o&&(s[r]=o,C(this,g,q).call(this)),!0)})},q=function(){b(this,A)||(E(this,A,!0),Q(()=>{E(this,y,H(this,b(this,k),b(this,y))),E(this,A,!1)}))};const gt=e=>t=>{if(customElements.get(e.tagName)){console.warn(`标签名称 "${e.tagName}" 已经被注册`);return}return t.prototype._manifest=yt(e),customElements.define(e.tagName,t),t},yt=e=>(e=Object.assign({hasConfig:!1},e),e);i.BaseElement=dt,i.CustomElement=gt,i.createFunction=W,i.isObject=M,i.listeners=D,i.parseHtml=V,i.patch=H,i.runInAsyncQueue=Q,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
1
+ (function(i,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(i=typeof globalThis<"u"?globalThis:i||self,f(i.solely={}))})(this,function(i){"use strict";var G=i=>{throw TypeError(i)};var O=(i,f,h)=>f.has(i)||G("Cannot "+h);var b=(i,f,h)=>(O(i,f,"read from private field"),h?h.call(i):f.get(i)),I=(i,f,h)=>f.has(i)?G("Cannot add the same private member more than once"):f instanceof WeakSet?f.add(i):f.set(i,h),E=(i,f,h,S)=>(O(i,f,"write to private field"),S?S.call(i,h):f.set(i,h),h),C=(i,f,h)=>(O(i,f,"access private method"),h);var x,k,y,A,g,P,q;const f=/<!--(?:.|\s)*?-->|<[a-zA-Z0-9\-/](?:"[^"]*"|'[^']*'|[^'">])*>/g,h=/<\/?([^\s]+?)[/\s>]/,S=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g,N=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],w=/\{\{(.+?)\}\}/g;function U(e){return e.replace(/>\s+</g,"><").replace(/\s+/g," ")}function Y(e,t){const n=(t.match(h)||[])[1]||"",s={rootId:0,tagName:n,attrs:{},props:{},on:{},children:[]},r=new RegExp(S);for(;;){const o=r.exec(t);if(o===null)break;if(!o[0].trim())continue;const[a,l]=o[1]?o[1].trim().split("="):[o[2],o[3].trim().slice(1,-1)];if(D.includes(a)||a.startsWith("on-"))s.on[a.startsWith("on-")?a.slice(3):a.slice(2)]=B(e,`return (${l})`);else if(a.startsWith("s-")){const p=a.slice(2);switch(p){case"model":s.model=l;break;case"style":s.styles=u=>d(e,l,u);break;case"class":s.classes=u=>d(e,l,u);break;case"readonly":s.props.readOnly=u=>d(e,l,u);break;default:s.props[p]=u=>d(e,l,u);break}}else s.attrs[a]=l;r.lastIndex--}if(n==="For"?s.fn=o=>d(e,s.attrs.each,o):(n==="If"||n==="ElseIf")&&(s.fn=o=>d(e,s.attrs.condition,o)),s.model){const o=s.model.replace("this.","").replace("$data.",""),a=p=>d(e,`$data.${o}`,p),l=p=>B(e,`$data.${o}=${p}`);n==="input"?s.attrs.type==="checkbox"||s.attrs.type==="radio"?(s.props.checked=a,s.on.change=l("checked")):(s.props.value=a,s.on.input=l("value")):n==="textarea"?(s.props.value=a,s.on.input=l("value")):n==="select"&&(s.props.value=a,s.on.change=l("value"))}return s}function V(e,t){const n=[];if(!t)return n;t=U(t);const s=[],r=[],o=()=>{var l;return s.length===0?n:(l=s[s.length-1]).children||(l.children=[])};let a=0;return t.replace(f,(l,p)=>{const u=o();if(p>a){const c=t.substring(a,p).trim();if(c){w.lastIndex=0;const T=!w.test(c)?c:L=>c.replace(w,(Z,R)=>d(e,R,L));u.push({rootId:0,tagName:"text",attrs:{},props:{},on:{},content:T,children:[]})}}if(a=p+l.length,l.startsWith("<!--")&&l.endsWith("-->"))u.push({rootId:0,tagName:"comment",attrs:{},props:{},on:{},content:l.slice(4,-3),children:[]});else if(l.startsWith("</")){const c=r.pop();for(;s.length>0&&s[s.length-1].tagName!==c;)s.pop();s.pop()}else{const c=Y(e,l),m=l.endsWith("/>")||N.includes(c.tagName);u.push(c),m||(s.push(c),r.push(c.tagName))}return""}),t.length>a&&n.push({rootId:0,tagName:"text",attrs:{},props:{},on:{},content:t.substring(a).trim(),children:[]}),n}const d=(e,t,n)=>{try{return W(["$data",...n.map(r=>r.item),`return (${t})`]).bind(e)(e.$data,...n.map(r=>r.value))}catch(s){console.error(s)}},B=(e,t)=>(n,s)=>W(["$data","event","value","checked",...s.map(o=>o.item),t]).bind(e)(e.$data,n,n.target.value,n.target.checked,...s.map(o=>o.value)),D=["onabort","onautocomplete","onautocompleteerror","onblur","oncancel","oncanplay","oncanplaythrough","onchange","onclick","onclose","oncontextmenu","oncuechange","ondblclick","ondrag","ondragend","ondragenter","ondragexit","ondragleave","ondragover","ondragstart","ondrop","ondurationchange","onemptied","onended","onerror","onfocus","oninput","oninvalid","onkeydown","onkeypress","onkeyup","onload","onloadeddata","onloadedmetadata","onloadstart","onmousedown","onmouseenter","onmouseleave","onmousemove","onmouseout","onmouseover","onmouseup","onwheel","onpause","onplay","onplaying","onprogress","onratechange","onreset","onresize","onscroll","onseeked","onseeking","onselect","onshow","onstalled","onsubmit","onsuspend","ontimeupdate","ontoggle","onvolumechange","onwaiting"],Q=(()=>{const e=typeof requestAnimationFrame=="function"?t=>requestAnimationFrame(t):typeof Promise<"u"?t=>Promise.resolve().then(t):t=>setTimeout(t,0);return(t,...n)=>{if(typeof t!="function")throw new Error("runInAsyncQueue expects a function as its first argument");e(()=>t(...n))}})(),F={};function W(e){const t=e.join(",");if(!F[t]){const n=e[e.length-1];if(n.trim()==="")throw new Error("Function body is empty");if(tt(n))throw new Error("Input contains potentially dangerous code: "+n);const s=new Function(...e);F[t]=s}return F[t]}function tt(e){return["eval","Function","setTimeout","setInterval","window","global","require","XMLHttpRequest","fetch","console","debugger","process","document","importScripts","String.raw","Object.prototype","JSON.parse"].some(n=>e.includes(n))}const et="http://www.w3.org/1999/xlink",nt="http://www.w3.org/2000/xmlns/",st="http://www.w3.org/XML/1998/namespace",ot="http://www.w3.org/2000/svg",_=e=>typeof e.content=="function"?e.content(e.loops||[]):e.content||"",rt=e=>{const t=_(e),n=e.elm;n.textContent!==t&&(n.textContent=t)},z=(e,t,n=[])=>{Object.keys(t).forEach(s=>{const r=t[s](n);e[s]!==r&&(e[s]=r)})},X=(e,t)=>{const{styles:n,attrs:s,loops:r=[]}=t;if(!n)return;const o=[];s!=null&&s.style&&o.push(s.style);const a=n(r);o.push(...at(a)),e.style.cssText=o.join(";")},J=(e,t)=>{const{classes:n,attrs:s,loops:r=[]}=t;if(!n)return;const o=[];s!=null&&s.class&&o.push(...s.class.split(" ").filter(l=>l!==""));const a=n(r);o.push(...ct(a)),e.className=Array.from(new Set(o)).join(" ")},at=e=>typeof e=="object"&&!Array.isArray(e)?Object.keys(e).map(t=>`${t}:${e[t]}`):typeof e=="string"?[e]:Array.isArray(e)?e.flatMap(t=>typeof t=="string"?[t]:Object.keys(t).map(n=>`${n}:${t[n]}`)):[],ct=e=>typeof e=="object"&&!Array.isArray(e)?Object.keys(e).filter(t=>e[t]).map(t=>t):typeof e=="string"?e.split(" ").filter(t=>t!==""):Array.isArray(e)?e.flatMap(t=>typeof t=="string"?t.split(" ").filter(n=>n!==""):Object.keys(t).filter(n=>t[n])):[],it=(e,t)=>{const n=t.elm;z(n,t.props,t.loops),J(n,t),X(n,t),K(n,e.children,t.children)},lt=(e,t)=>{switch(t.elm=e.elm,t.tagName){case"comment":break;case"text":rt(t);break;case"slot":break;default:it(e,t);break}},j=(e,t,n)=>{n?e.insertBefore(t,n):e.appendChild(t)},ut=(e,t,n)=>{const s=_(t),r=document.createTextNode(s);t.elm=r,j(e,r,n)},ft=(e,t,n)=>{const s=t.content,r=document.createComment(s);t.elm=r,j(e,r,n)},mt=(e,t,n,s)=>{t.tagName==="svg"&&(s=ot);const r=s?document.createElementNS(s,t.tagName):document.createElement(t.tagName);Object.keys(t.attrs).forEach(o=>{const a=t.attrs[o]||"";o.charAt(0)!=="x"?r.setAttribute(o,a):o.startsWith("xml:")?r.setAttributeNS(st,o,a):o.startsWith("xlink:")?r.setAttributeNS(et,o,a):o.startsWith("xmlns:")?r.setAttributeNS(nt,o,a):r.setAttribute(o,a)}),Object.keys(t.on).forEach(o=>{r.addEventListener(o,a=>t.on[o](a,t.loops||[]),!1)}),z(r,t.props,t.loops),J(r,t),X(r,t),t.elm=r,j(e,r,n),t.tagName==="foreignObject"&&(s=void 0),t.children.forEach(o=>{$(r,o,void 0,s)})},$=(e,t,n,s)=>{switch(t.tagName){case"comment":ft(e,t,n);break;case"text":ut(e,t,n);break;default:mt(e,t,n,s);break}},pt=e=>e&&(e.tagName==="ElseIf"||e.tagName==="comment"),ht=e=>e&&e.tagName==="Else",v=(e,t,n=[],s=0,r=!0,o=!1)=>{var a,l,p;for(let u=0;u<t.length;u++){const c=t[u];if(c.tagName==="If"){let m=!1;for(((a=c.fn)==null?void 0:a.call(c,n))&&(v(e,c.children,n,s,!1,!0),m=!0);u+1<t.length&&pt(t[u+1]);)((p=(l=t[u+1]).fn)==null?void 0:p.call(l,n))&&!m&&(v(e,t[u+1].children,n,s,!1,!0),m=!0),u++;u+1<t.length&&ht(t[u+1])&&!m&&(v(e,t[u+1].children,n,s,!1,!0),m=!0),u++}else if(c.tagName==="For"){const{item:m="item",index:T="index"}=c.attrs;(c.fn(n)||[]).forEach((Z,R)=>{const bt={item:m,value:Z,index:T,valueIndex:R};v(e,c.children,[...n,bt],s,!1)})}else{const m={...c,loops:n,children:[],rootId:s,isIf:o};v(m.children,c.children,n),e.push(m)}r&&s++}},K=(e,t,n)=>{var o,a,l,p,u;let s=0,r=0;for(;s<t.length&&r<n.length;){const c=t[s],m=n[r];c.rootId===m.rootId?(m.isIf?((o=c.elm)==null||o.remove(),$(e,m,(a=t[s+1])==null?void 0:a.elm)):lt(c,m),r++,s++):c.rootId>m.rootId?((l=c.elm)==null||l.remove(),s++):($(e,m,(p=t[s+1])==null?void 0:p.elm),r++)}for(;s<t.length;)(u=t[s].elm)==null||u.remove(),s++;for(;r<n.length;){const c=n[r];$(e,c),r++}},H=(e,t,n=[])=>{if(!t||t.length===0)return[];const s=[];return v(s,t||[],[],0,!0),K(e,n,s),s},M=e=>typeof e=="object"&&e!=null;class dt extends HTMLElement{constructor(){super();I(this,g);I(this,x,{});I(this,k,[]);I(this,y,[]);I(this,A,!1);const n=this._manifest||{};n.template&&typeof n.template=="string"&&E(this,k,V(this,n.template)),(n.className||n.tagName||"").split(" ").forEach(r=>{this.classList.add(r)})}get $data(){let n=b(this,x);return M(n)&&(n=C(this,g,P).call(this,n)),n}set $data(n){E(this,x,n),C(this,g,q).call(this)}connectedCallback(){E(this,y,H(this,b(this,k),b(this,y))),this.onInit()}onInit(){}disconnectedCallback(){console.log("disconnectedCallback")}}x=new WeakMap,k=new WeakMap,y=new WeakMap,A=new WeakMap,g=new WeakSet,P=function(n){return new Proxy(n,{get:(s,r)=>{let o=s[r];return M(o)&&(o=C(this,g,P).call(this,o)),o},set:(s,r,o)=>(s[r]!==o&&(s[r]=o,C(this,g,q).call(this)),!0)})},q=function(){b(this,A)||(E(this,A,!0),Q(()=>{E(this,y,H(this,b(this,k),b(this,y))),E(this,A,!1)}))};const gt=e=>t=>{if(customElements.get(e.tagName)){console.warn(`标签名称 "${e.tagName}" 已经被注册`);return}return t.prototype._manifest=yt(e),customElements.define(e.tagName,t),t},yt=e=>(e=Object.assign({hasConfig:!1},e),e);i.BaseElement=dt,i.CustomElement=gt,i.createFunction=W,i.isObject=M,i.listeners=D,i.parseHtml=V,i.patch=H,i.runInAsyncQueue=Q,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "solely",
3
3
  "private": false,
4
- "version": "0.0.10",
4
+ "version": "0.0.11",
5
5
  "type": "module",
6
6
  "module": "./dist/solely.js",
7
7
  "types": "./dist/solely.d.ts",