nine-9 1.8.0 → 1.8.1
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/dist/index.js +672 -1
- package/dist/index.js.map +1 -0
- package/dist/test.d.ts +2 -0
- package/dist/test.js +583 -0
- package/dist/test.js.map +1 -0
- package/package.json +43 -42
package/dist/index.js
CHANGED
|
@@ -1 +1,672 @@
|
|
|
1
|
-
"use strict";var $=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var ne=Object.prototype.hasOwnProperty;var L=(e,t)=>{for(var n in t)$(e,n,{get:t[n],enumerable:!0})},oe=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of re(t))!ne.call(e,o)&&o!==n&&$(e,o,{get:()=>t[o],enumerable:!(r=te(t,o))||r.enumerable});return e};var se=e=>oe($({},"__esModule",{value:!0}),e);var ue={};L(ue,{$:()=>B,EventSubcriber:()=>S,assets:()=>Z,attachUUID:()=>W,camelToHyphen:()=>h,createArray:()=>j,createComponent:()=>H,defineEvent:()=>E,examples:()=>ee,flagment:()=>J,hostdown:()=>V,hyphenToCamel:()=>ae,normalizePropertyDescriptor:()=>M,pipeExtract:()=>N,putIntoArray:()=>U,rawProperty:()=>q,render:()=>P,styleSet:()=>w,sync:()=>g,tree:()=>m,typedIsArray:()=>pe,validateStore:()=>z,when:()=>k,wrap:()=>b});module.exports=se(ue);var S=class{subcribers=[];emitting=!1;subcribe(t,n=!1){this.subcribers.push({callback:t,once:n})}emit(...t){if(this.emitting)return;this.emitting=!0;let n=[];for(let r of this.subcribers)n.push(r.callback(...t));return this.emitting=!1,n}};function h(e){return e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}function ae(e){return e.replace(/-([a-z])/g,t=>t[1].toUpperCase())}function pe(e){return Array.isArray(e)}function U(e){return[...Array.isArray(e)?e:[e]]}function j(e,t){return new Array(e).fill(0).map(t)}var O=Symbol("HostTreeFlag"),_=Symbol("ComponentInstanceFlag"),y=Symbol("WrapperFlag");function R(e,t){return Object.assign(e,{[t]:!0})}function d(e,t){return e!=null&&typeof e=="object"&&Object.hasOwn(e,t)&&e[t]===!0}function m(e){let t=typeof e=="string"?document.createElement(e):e,n={treeUpdated:new S,attributeUpdated:new S,initialized:new S,preventEvent:new S},r=new Proxy(R({element:t,hooks:n,append(...o){for(let s of o)if(d(s,y)){let p=[],a=new Comment("Tree anchor");t.appendChild(a);let i=l=>{let f=[...Array.isArray(l)?l:[l]].reverse(),u=[];for(let c of f){let T=P(c);u.push(T),t.insertBefore(T.element,a.nextSibling)}for(let c of p)c.element.remove();n.treeUpdated.emit(u,p),p=u};s.event.subcribe(i),i(s.get())}else{let p=s;for(let a of U(p))t.appendChild(P(a).element)}return r},use(o){if(t instanceof HTMLElement){let s=p=>{for(let[a,i]of Object.entries(p))t.style.setProperty(h(String(a)),i)};d(o,y)?(o.event.subcribe(p=>s(p.rules)),s(o.get().rules)):s(o.rules)}return r},on(o,s,p){return t instanceof EventTarget&&t.addEventListener(o,a=>{let i=n.event.emit(o,s);i&&!i.some(Boolean)&&s(a)},p),r}},O),{get(o,s,p){return Reflect.has(o,s)?Reflect.get(o,s,p):a=>{let i=(l,f)=>{Object.hasOwn(t,s)&&(t[s]=l),t instanceof Element&&t.setAttribute(h(s),String(l)),n.attributeUpdated.emit(s,l,f)};return d(a,y)?(a.event.subcribe(i),i(a.get(),a.get())):i(a,a),r}}});return Promise.resolve().then(()=>n.initialized.emit(r)),r}var C=class extends Error{},D=class extends Error{},A=class extends Error{},K=class extends Error{},I=class extends Error{};function b(e,t){let n=["push","pop","shift","unshift","splice","sort","reverse"],r=i=>{if(!Array.isArray(i))return i;let{proxy:l,revoke:f}=Proxy.revocable(i,{get(u,c,T){if(n.includes(c)){let v=Reflect.get(u,c,T);return typeof v=="function"?(...Q)=>{let x=a.get();if(Array.isArray(x)){x=[...x];let F=v.call(u,...Q);return a.event.emit(a.get(),x),F}}:Reflect.get(u,c,T)}else return Reflect.get(u,c,T)},set(u,c,T,v){if(Reflect.get(u,c,v)!==T){let x=a.get();if(Array.isArray(x)){x=[...x];let F=Reflect.set(u,c,T,v);return a.event.emit(a.get(),x),F}}return Reflect.set(u,c,T,v)}});return s=f,l},o=new S,s=null,p=r(e),a=R({get(){return p},set(i){if(p!==i){let l=p;Array.isArray(l)&&s?(l=[...l],s(),p=r(i)):p=i,this.event.emit(i,l)}},updateOnly(){this.event.emit(this.get(),this.get())},event:o},y);return{...a,...t??{}}}function g(e,t=[]){let n=b(e()),r=()=>{let o=e();n.get()!==o&&n.set(o)};for(let o of t)d(o,y)&&o.event.subcribe(r);return n}function k(e,t,n=[]){return g(()=>{let r;return typeof e=="function"?r=e():r=e.get(),[r?t():null]},[...n,...d(e,y)?[e]:[]])}function q(){return e=>e}function M(e){return Object.assign({validate:()=>!0,transform:t=>t,shadow:null,required:!1,downloadable:!0,uploadable:!1},e)}function z(e){for(let t in e){let n=e[t];if(n.shadow){if(n.required)throw new A(`The required property ${t} can't have a shadow.`);if(n.validate&&!n.validate(n.shadow))throw new C(`The shadow of ${t} can't pass the validation.`)}}}function V(e,t){e||(e={});let n={};for(let r in t){let o=M(t[r]),s=a=>{if(d(n[r],y))n[r].set(a);else{let i=b(a);n[r]=i,i.event.subcribe(l=>{if(!(!d(e[r],y)||!d(n[r],y))&&n[r].get()!==e[r].get()){if(!o.uploadable)throw new K(`Property ${r} isn't uploadable but being set.`);e[r].set(l)}})}},p=(a,i)=>{if(!i&&!o.downloadable){console.warn(`Property ${r} isn't downloadable but being emitted.`);return}if(!o.validate(a))throw new C(`The input value of ${r} can't pass the validation.`);s(o.transform(a))};if(!Object.hasOwn(e,r)){if(o.required)throw new D(`Missing a required property ${r}.`);s(o.shadow);continue}d(e[r],y)?(e[r].event.subcribe(a=>p(a,!1)),p(e[r].get(),!0)):p(e[r],!0)}return n}function N(e){return typeof e=="function"?()=>b(e()):d(e,y)?N(e):()=>b(e)}function P(e){let t;if(e instanceof Node)t=m(e);else if(typeof e=="string"||typeof e=="number"||typeof e=="boolean"||typeof e=="bigint")t=m(new Text(String(e)));else if(d(e,_))t=e.$;else if(e==null)t=m(new Comment("Empty tree context"));else if(d(e,O))t=e;else throw new I(`Failed to render ${e} into a Node.`);return t}function B(e){return e}function J(e){return`nine_${e.replaceAll("-","_")}`}function W(e,t){for(let n of[e,...e.childNodes])n instanceof HTMLElement&&(n.dataset[J(t)]="true"),n!==e&&n.childNodes.length>0&&W(n,t);return e}function H(e,t){z(e.props??{});let n=Object.fromEntries(Object.entries(e.props??{}).map(([p,a])=>[p,M(a)])),r=crypto.randomUUID(),o=J(r);if(e.styles)for(let p of e.styles)p.apply(`[data-${o}="true"]`);return Object.assign((p,a)=>{let i=t(V(p,n),N(a),(f,u)=>{let c=e.events?.find(T=>T.name===f);if(!c)throw new TypeError(`No events named ${f} to emit.`);l.element.dispatchEvent(new CustomEvent(f,{detail:u,bubbles:c.bubbleable,cancelable:!1}))}),l=P(i);return W(l.element,r),l.hooks.treeUpdated.subcribe(f=>f.forEach(u=>W(u.element,r))),R({mount(f){let u=typeof f=="string"?[...document.querySelectorAll(f)]:[f];for(let c of u)c.appendChild(l.element)},on(f,u){return l.on(f,c=>c instanceof CustomEvent?u(c.detail):null),this},$:l},_)},{props:n,events:e.events})}function w(e){let t={},n=new Proxy({rules:t,selector:e,apply(r){let o=document.createElement("style");document.head.appendChild(o),o.textContent=`${this.selectorString(r)}{${this.ruleString()}}`},ruleString(){return Object.entries(t).map(([r,o])=>`${h(String(r))}:${o};`).join("")},selectorString(r){return(this.selector||"")+(r||"")||"*"}},{get(r,o,s){return Reflect.has(r,o)?Reflect.get(r,o,s):p=>(t[o]=String(p),n)}});return n}function E(e,t){return{name:e,...t??{}}}var Z={};L(Z,{logo:()=>G});var G={};L(G,{default:()=>le});var le='data:image/svg+xml,<svg width="337" height="395" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" overflow="hidden"><defs><filter id="fx0" x="-10%" y="-10%" width="120%" height="120%" filterUnits="userSpaceOnUse" primitiveUnits="userSpaceOnUse"><feComponentTransfer color-interpolation-filters="sRGB"><feFuncR type="discrete" tableValues="1 1"/><feFuncG type="discrete" tableValues="0.752941 0.752941"/><feFuncB type="discrete" tableValues="0 0"/><feFuncA type="linear" slope="0.4" intercept="0"/></feComponentTransfer><feGaussianBlur stdDeviation="0 0"/></filter><clipPath id="clip1"><rect x="119" y="90" width="93" height="142"/></clipPath></defs><g transform="translate(-119 -128)"><g clip-path="url(%23clip1)" filter="url(%23fx0)" transform="translate(125 135)"><g><path d="M37.352-111.688C33.9173-107.395 32.2-101.261 32.2-93.288 32.2-85.4373 33.9173-79.5493 37.352-75.624 40.7867-71.6987 45.5093-69.736 51.52-69.736 60.5973-69.736 68.08-74.6427 73.968-84.456 71.76-107.027 63.9707-118.312 50.6-118.312 45.3253-118.312 40.9093-116.104 37.352-111.688ZM84.088-16.008C74.0293-3.61867 61.5787 2.576 46.736 2.576 32.016 2.576 21.5893-0.797334 15.456-7.544 13.3707-9.26133 11.96-8.34133 11.224-4.784 10.12-10.1813 11.96-15.5787 16.744-20.976 21.528-26.496 25.944-27.4773 29.992-23.92 31.832-20.976 36.9227-19.504 45.264-19.504 53.6053-19.504 60.352-23.0613 65.504-30.176 70.7787-37.4133 73.4773-45.8773 73.6-55.568 73.8453-58.6347 75.1333-60.1067 77.464-59.984 75.3787-63.4187 72.128-63.296 67.712-59.616 63.4187-56.0587 58.7573-53.2987 53.728-51.336 53.6053-50.7227 51.152-50.416 46.368-50.416 34.592-50.416 25.1467-54.0347 18.032-61.272 10.9173-68.632 7.36-79.1813 7.36-92.92 7.36-106.781 11.4693-117.883 19.688-126.224 28.0293-134.565 38.2107-138.736 50.232-138.736 64.216-138.736 75.8693-133.032 85.192-121.624 94.5147-110.339 99.176-93.0427 99.176-69.736 99.176-46.4293 94.1467-28.52 84.088-16.008Z" fill="%23ED7D31" transform="translate(111.796 229)"/></g></g><text fill="%23ED7D31" font-family="Swei Fist Sans CJK JP,Swei Fist Sans CJK JP_MSFontService,sans-serif" font-weight="700" font-size="184" transform="translate(229.799 357)">9</text></g></svg>';var X=H({props:{value:{validate:Number.isInteger,transform:Number,required:!1,shadow:0,downloadable:!0,uploadable:!0}},events:[E("up",{template:{arg1:0,arg2:!1},bubbleable:!0}),E("down",{template:{arg3:"sb",arg4:Symbol()},bubbleable:!0})]},e=>{let t=g(()=>e.value.get()*2,[e.value]);return m("div").use(w().fontSize("20px").padding("10px")).append("\u6572\u6728\u9C7C",m("br"),m("button").on("click",()=>e.value.set(e.value.get()+1)).append("\u70B9\u51FB\u52A0\u4E00"),m("button").on("click",()=>e.value.set(e.value.get()-1)).append("\u70B9\u51FB\u51CF\u4E00"),m("br"),"\u5F53\u524D\u503C\uFF1A",e.value,"\u53CC\u500D\u503C\uFF1A",t,g(()=>j(t.get(),()=>m("div").append("\u4F60\u70B9\u4E86\u4E00\u4E0B")),[t]),k(()=>e.value.get()>10,()=>m("p").append("count > 10 \u65F6\u663E\u793A"),[e.value]))});var Y=H({props:{items:{transform:q(),shadow:["OptionA","OptionB","OptionC"]},value:{transform:Number,uploadable:!0,required:!0}},events:[E("select",{template:0}),E("toggleState",{template:!1})],styles:[w(".item").backgroundColor("blue").color("white"),w(".flexdown").display("flex").flexDirection("column")]},(e,t,n)=>{let r=b(!1),o=s=>{e.value.set(s),r.set(!1),n("select",e.value.get())};return r.event.subcribe(s=>n("toggleState",s)),m("div").class("flexdown").ariaAtomic("false").append(m("span").class("item").use(w().backgroundColor("red")).append(g(()=>e.items.get()[e.value.get()],[e.items,e.value])).on("click",()=>r.set(!r.get())),t(),k(r,()=>m("div").class("flexdown").append(g(()=>e.items.get().map((s,p)=>m("span").class("item").append(s).on("click",()=>o(p))),[e.items]))))});var ee={Counter:X,Selector:Y};window.__NINE_ENV__?.mode==="development"&&console.warn("[Nine-9] Initialized in development mode.");0&&(module.exports={$,EventSubcriber,assets,attachUUID,camelToHyphen,createArray,createComponent,defineEvent,examples,flagment,hostdown,hyphenToCamel,normalizePropertyDescriptor,pipeExtract,putIntoArray,rawProperty,render,styleSet,sync,tree,typedIsArray,validateStore,when,wrap});
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
$: () => $,
|
|
24
|
+
EventSubcriber: () => EventSubcriber,
|
|
25
|
+
assets: () => assets_exports,
|
|
26
|
+
attachUUID: () => attachUUID,
|
|
27
|
+
camelToHyphen: () => camelToHyphen,
|
|
28
|
+
createArray: () => createArray,
|
|
29
|
+
createComponent: () => createComponent,
|
|
30
|
+
defineEvent: () => defineEvent,
|
|
31
|
+
examples: () => examples_default,
|
|
32
|
+
flagment: () => flagment,
|
|
33
|
+
hostdown: () => hostdown,
|
|
34
|
+
hyphenToCamel: () => hyphenToCamel,
|
|
35
|
+
normalizePropertyDescriptor: () => normalizePropertyDescriptor,
|
|
36
|
+
pipeExtract: () => pipeExtract,
|
|
37
|
+
putIntoArray: () => putIntoArray,
|
|
38
|
+
rawProperty: () => rawProperty,
|
|
39
|
+
render: () => render,
|
|
40
|
+
styleSet: () => styleSet,
|
|
41
|
+
sync: () => sync,
|
|
42
|
+
tree: () => tree,
|
|
43
|
+
typedIsArray: () => typedIsArray,
|
|
44
|
+
validateStore: () => validateStore,
|
|
45
|
+
when: () => when,
|
|
46
|
+
wrap: () => wrap
|
|
47
|
+
});
|
|
48
|
+
module.exports = __toCommonJS(index_exports);
|
|
49
|
+
|
|
50
|
+
// src/channel/event-subcriber.ts
|
|
51
|
+
var EventSubcriber = class {
|
|
52
|
+
subcribers = [];
|
|
53
|
+
emitting = false;
|
|
54
|
+
subcribe(callback, once = false) {
|
|
55
|
+
this.subcribers.push({
|
|
56
|
+
callback,
|
|
57
|
+
once
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
emit(...data) {
|
|
61
|
+
if (this.emitting) return;
|
|
62
|
+
this.emitting = true;
|
|
63
|
+
const result = [];
|
|
64
|
+
for (const subcriber of this.subcribers) {
|
|
65
|
+
result.push(subcriber.callback(...data));
|
|
66
|
+
}
|
|
67
|
+
this.emitting = false;
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// src/util/char.ts
|
|
73
|
+
function camelToHyphen(str) {
|
|
74
|
+
return str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
|
75
|
+
}
|
|
76
|
+
function hyphenToCamel(str) {
|
|
77
|
+
return str.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/util/array.ts
|
|
81
|
+
function typedIsArray(arr) {
|
|
82
|
+
return Array.isArray(arr);
|
|
83
|
+
}
|
|
84
|
+
function putIntoArray(data) {
|
|
85
|
+
return [...Array.isArray(data) ? data : [data]];
|
|
86
|
+
}
|
|
87
|
+
function createArray(length, filler) {
|
|
88
|
+
return new Array(length).fill(0).map(filler);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/constants/flags.ts
|
|
92
|
+
var HOST_TREE = /* @__PURE__ */ Symbol("HostTreeFlag");
|
|
93
|
+
var COMPONENT_INSTANCE = /* @__PURE__ */ Symbol("ComponentInstanceFlag");
|
|
94
|
+
var WRAPPER = /* @__PURE__ */ Symbol("WrapperFlag");
|
|
95
|
+
function attachFlag(data, flag) {
|
|
96
|
+
return Object.assign(data, { [flag]: true });
|
|
97
|
+
}
|
|
98
|
+
function matchFlag(data, flag) {
|
|
99
|
+
return data !== null && data !== void 0 && typeof data === "object" && Object.hasOwn(data, flag) && data[flag] === true;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/dom/tree.ts
|
|
103
|
+
function tree(data) {
|
|
104
|
+
const element = typeof data === "string" ? document.createElement(data) : data;
|
|
105
|
+
const hooks = {
|
|
106
|
+
treeUpdated: new EventSubcriber(),
|
|
107
|
+
attributeUpdated: new EventSubcriber(),
|
|
108
|
+
initialized: new EventSubcriber(),
|
|
109
|
+
preventEvent: new EventSubcriber()
|
|
110
|
+
};
|
|
111
|
+
const context = new Proxy(attachFlag({
|
|
112
|
+
element,
|
|
113
|
+
hooks,
|
|
114
|
+
append(...children) {
|
|
115
|
+
for (const child of children) {
|
|
116
|
+
if (matchFlag(child, WRAPPER)) {
|
|
117
|
+
let oldChildren = [];
|
|
118
|
+
const baseAnchor = new Comment("Tree anchor");
|
|
119
|
+
element.appendChild(baseAnchor);
|
|
120
|
+
const update = (newTrees) => {
|
|
121
|
+
const normalizedTrees = [...Array.isArray(newTrees) ? newTrees : [newTrees]].reverse();
|
|
122
|
+
const newChildren = [];
|
|
123
|
+
for (const newTree of normalizedTrees) {
|
|
124
|
+
const child2 = render(newTree);
|
|
125
|
+
newChildren.push(child2);
|
|
126
|
+
element.insertBefore(child2.element, baseAnchor.nextSibling);
|
|
127
|
+
}
|
|
128
|
+
for (const oldChild of oldChildren) {
|
|
129
|
+
oldChild.element.remove();
|
|
130
|
+
}
|
|
131
|
+
hooks.treeUpdated.emit(newChildren, oldChildren);
|
|
132
|
+
oldChildren = newChildren;
|
|
133
|
+
};
|
|
134
|
+
child.event.subcribe(update);
|
|
135
|
+
update(child.get());
|
|
136
|
+
} else {
|
|
137
|
+
const children2 = child;
|
|
138
|
+
for (const child2 of putIntoArray(children2)) {
|
|
139
|
+
element.appendChild(render(child2).element);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return context;
|
|
144
|
+
},
|
|
145
|
+
use(styleSet2) {
|
|
146
|
+
if (element instanceof HTMLElement) {
|
|
147
|
+
const update = (rules) => {
|
|
148
|
+
for (const [key, value] of Object.entries(rules)) {
|
|
149
|
+
element.style.setProperty(camelToHyphen(String(key)), value);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
if (matchFlag(styleSet2, WRAPPER)) {
|
|
153
|
+
styleSet2.event.subcribe((newData) => update(newData.rules));
|
|
154
|
+
update(styleSet2.get().rules);
|
|
155
|
+
} else {
|
|
156
|
+
update(styleSet2.rules);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return context;
|
|
160
|
+
},
|
|
161
|
+
on(key, handler, options) {
|
|
162
|
+
if (element instanceof EventTarget) {
|
|
163
|
+
element.addEventListener(key, (e) => {
|
|
164
|
+
const emitResult = hooks.preventEvent.emit(key, handler);
|
|
165
|
+
if (emitResult && !emitResult.some(Boolean)) {
|
|
166
|
+
handler(e);
|
|
167
|
+
}
|
|
168
|
+
}, options);
|
|
169
|
+
}
|
|
170
|
+
return context;
|
|
171
|
+
}
|
|
172
|
+
}, HOST_TREE), {
|
|
173
|
+
get(target, p, receiver) {
|
|
174
|
+
if (Reflect.has(target, p)) {
|
|
175
|
+
return Reflect.get(target, p, receiver);
|
|
176
|
+
} else {
|
|
177
|
+
return (data2) => {
|
|
178
|
+
const update = (newData, oldData) => {
|
|
179
|
+
if (Object.hasOwn(element, p)) {
|
|
180
|
+
element[p] = newData;
|
|
181
|
+
}
|
|
182
|
+
if (element instanceof Element) {
|
|
183
|
+
element.setAttribute(camelToHyphen(p), String(newData));
|
|
184
|
+
}
|
|
185
|
+
hooks.attributeUpdated.emit(p, newData, oldData);
|
|
186
|
+
};
|
|
187
|
+
if (matchFlag(data2, WRAPPER)) {
|
|
188
|
+
data2.event.subcribe(update);
|
|
189
|
+
update(data2.get(), data2.get());
|
|
190
|
+
} else {
|
|
191
|
+
update(data2, data2);
|
|
192
|
+
}
|
|
193
|
+
return context;
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
Promise.resolve().then(() => hooks.initialized.emit(context));
|
|
199
|
+
return context;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// src/exceptions/index.ts
|
|
203
|
+
var ValidationFailed = class extends Error {
|
|
204
|
+
};
|
|
205
|
+
var MissingFieldError = class extends Error {
|
|
206
|
+
};
|
|
207
|
+
var ConflictionError = class extends Error {
|
|
208
|
+
};
|
|
209
|
+
var AccessError = class extends Error {
|
|
210
|
+
};
|
|
211
|
+
var BrokenRendererError = class extends Error {
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// src/dom/reactive.ts
|
|
215
|
+
function wrap(initialData, wrapperOptions) {
|
|
216
|
+
const arrayActions = ["push", "pop", "shift", "unshift", "splice", "sort", "reverse"];
|
|
217
|
+
const patch = (data) => {
|
|
218
|
+
if (!Array.isArray(data)) {
|
|
219
|
+
return data;
|
|
220
|
+
}
|
|
221
|
+
const { proxy, revoke: newRevoke } = Proxy.revocable(data, {
|
|
222
|
+
get(target, p, receiver) {
|
|
223
|
+
if (arrayActions.includes(p)) {
|
|
224
|
+
const originalMethod = Reflect.get(target, p, receiver);
|
|
225
|
+
if (typeof originalMethod === "function") {
|
|
226
|
+
return (...args) => {
|
|
227
|
+
let oldData = wrapper.get();
|
|
228
|
+
if (Array.isArray(oldData)) {
|
|
229
|
+
oldData = [...oldData];
|
|
230
|
+
const result = originalMethod.call(target, ...args);
|
|
231
|
+
wrapper.event.emit(wrapper.get(), oldData);
|
|
232
|
+
return result;
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
} else return Reflect.get(target, p, receiver);
|
|
236
|
+
} else {
|
|
237
|
+
return Reflect.get(target, p, receiver);
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
set(target, p, newValue, receiver) {
|
|
241
|
+
const oldValue = Reflect.get(target, p, receiver);
|
|
242
|
+
if (oldValue !== newValue) {
|
|
243
|
+
let oldData = wrapper.get();
|
|
244
|
+
if (Array.isArray(oldData)) {
|
|
245
|
+
oldData = [...oldData];
|
|
246
|
+
const result = Reflect.set(target, p, newValue, receiver);
|
|
247
|
+
wrapper.event.emit(wrapper.get(), oldData);
|
|
248
|
+
return result;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return Reflect.set(target, p, newValue, receiver);
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
oldRevoke = newRevoke;
|
|
255
|
+
return proxy;
|
|
256
|
+
};
|
|
257
|
+
const event = new EventSubcriber();
|
|
258
|
+
let oldRevoke = null;
|
|
259
|
+
let currentData = patch(initialData);
|
|
260
|
+
const wrapper = attachFlag({
|
|
261
|
+
get() {
|
|
262
|
+
return currentData;
|
|
263
|
+
},
|
|
264
|
+
set(newData) {
|
|
265
|
+
if (currentData !== newData) {
|
|
266
|
+
let oldData = currentData;
|
|
267
|
+
if (Array.isArray(oldData) && oldRevoke) {
|
|
268
|
+
oldData = [...oldData];
|
|
269
|
+
oldRevoke();
|
|
270
|
+
currentData = patch(newData);
|
|
271
|
+
} else {
|
|
272
|
+
currentData = newData;
|
|
273
|
+
}
|
|
274
|
+
;
|
|
275
|
+
this.event.emit(newData, oldData);
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
updateOnly() {
|
|
279
|
+
this.event.emit(this.get(), this.get());
|
|
280
|
+
},
|
|
281
|
+
event
|
|
282
|
+
}, WRAPPER);
|
|
283
|
+
return { ...wrapper, ...wrapperOptions ?? {} };
|
|
284
|
+
}
|
|
285
|
+
function sync(effectRenderer, dependencies = []) {
|
|
286
|
+
const internalWrapper = wrap(effectRenderer());
|
|
287
|
+
const update = () => {
|
|
288
|
+
const newData = effectRenderer();
|
|
289
|
+
const currentData = internalWrapper.get();
|
|
290
|
+
const hasChanged = currentData !== newData;
|
|
291
|
+
if (hasChanged) {
|
|
292
|
+
internalWrapper.set(newData);
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
for (const dependency of dependencies) {
|
|
296
|
+
if (!matchFlag(dependency, WRAPPER)) continue;
|
|
297
|
+
dependency.event.subcribe(update);
|
|
298
|
+
}
|
|
299
|
+
return internalWrapper;
|
|
300
|
+
}
|
|
301
|
+
function when(condition, tree2, dependencies = []) {
|
|
302
|
+
return sync(() => {
|
|
303
|
+
let result;
|
|
304
|
+
if (typeof condition === "function") {
|
|
305
|
+
result = condition();
|
|
306
|
+
} else {
|
|
307
|
+
result = condition.get();
|
|
308
|
+
}
|
|
309
|
+
return [result ? tree2() : null];
|
|
310
|
+
}, [...dependencies, ...matchFlag(condition, WRAPPER) ? [condition] : []]);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// src/dom/property.ts
|
|
314
|
+
function rawProperty() {
|
|
315
|
+
return (x) => x;
|
|
316
|
+
}
|
|
317
|
+
function normalizePropertyDescriptor(descriptor) {
|
|
318
|
+
return Object.assign({
|
|
319
|
+
validate: () => true,
|
|
320
|
+
transform: (x) => x,
|
|
321
|
+
shadow: null,
|
|
322
|
+
required: false,
|
|
323
|
+
downloadable: true,
|
|
324
|
+
uploadable: false
|
|
325
|
+
}, descriptor);
|
|
326
|
+
}
|
|
327
|
+
function validateStore(store) {
|
|
328
|
+
for (const propertyKey in store) {
|
|
329
|
+
const descriptor = store[propertyKey];
|
|
330
|
+
if (descriptor.shadow) {
|
|
331
|
+
if (descriptor.required) {
|
|
332
|
+
throw new ConflictionError(`The required property ${propertyKey} can't have a shadow.`);
|
|
333
|
+
}
|
|
334
|
+
if (descriptor.validate && !descriptor.validate(descriptor.shadow)) {
|
|
335
|
+
throw new ValidationFailed(`The shadow of ${propertyKey} can't pass the validation.`);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
function hostdown(upstream, store) {
|
|
341
|
+
if (!upstream) upstream = {};
|
|
342
|
+
const downstream = {};
|
|
343
|
+
for (const propertyKey in store) {
|
|
344
|
+
const descriptor = normalizePropertyDescriptor(store[propertyKey]);
|
|
345
|
+
const setValue = (newValue) => {
|
|
346
|
+
if (matchFlag(downstream[propertyKey], WRAPPER)) {
|
|
347
|
+
downstream[propertyKey].set(newValue);
|
|
348
|
+
} else {
|
|
349
|
+
const wrapper = wrap(newValue);
|
|
350
|
+
downstream[propertyKey] = wrapper;
|
|
351
|
+
wrapper.event.subcribe((newData) => {
|
|
352
|
+
if (!matchFlag(upstream[propertyKey], WRAPPER) || !matchFlag(downstream[propertyKey], WRAPPER)) return;
|
|
353
|
+
if (downstream[propertyKey].get() === upstream[propertyKey].get()) return;
|
|
354
|
+
if (!descriptor.uploadable) throw new AccessError(`Property ${propertyKey} isn't uploadable but being set.`);
|
|
355
|
+
upstream[propertyKey].set(newData);
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
const update = (inputValue, firstSet) => {
|
|
360
|
+
if (!firstSet && !descriptor.downloadable) {
|
|
361
|
+
console.warn(`Property ${propertyKey} isn't downloadable but being emitted.`);
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
if (!descriptor.validate(inputValue)) {
|
|
365
|
+
throw new ValidationFailed(`The input value of ${propertyKey} can't pass the validation.`);
|
|
366
|
+
}
|
|
367
|
+
setValue(descriptor.transform(inputValue));
|
|
368
|
+
};
|
|
369
|
+
if (!Object.hasOwn(upstream, propertyKey)) {
|
|
370
|
+
if (descriptor.required) {
|
|
371
|
+
throw new MissingFieldError(`Missing a required property ${propertyKey}.`);
|
|
372
|
+
}
|
|
373
|
+
setValue(descriptor.shadow);
|
|
374
|
+
continue;
|
|
375
|
+
}
|
|
376
|
+
if (matchFlag(upstream[propertyKey], WRAPPER)) {
|
|
377
|
+
upstream[propertyKey].event.subcribe((e) => update(e, false));
|
|
378
|
+
update(upstream[propertyKey].get(), true);
|
|
379
|
+
} else {
|
|
380
|
+
update(upstream[propertyKey], true);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
return downstream;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// src/dom/slot.ts
|
|
387
|
+
function pipeExtract(input) {
|
|
388
|
+
if (typeof input === "function") {
|
|
389
|
+
return () => wrap(input());
|
|
390
|
+
} else if (matchFlag(input, WRAPPER)) {
|
|
391
|
+
return pipeExtract(input);
|
|
392
|
+
} else return () => wrap(input);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// src/dom/component.ts
|
|
396
|
+
function render(nodeTree) {
|
|
397
|
+
let result;
|
|
398
|
+
if (nodeTree instanceof Node) {
|
|
399
|
+
result = tree(nodeTree);
|
|
400
|
+
} else if (typeof nodeTree === "string" || typeof nodeTree === "number" || typeof nodeTree === "boolean" || typeof nodeTree === "bigint") {
|
|
401
|
+
result = tree(new Text(String(nodeTree)));
|
|
402
|
+
} else if (matchFlag(nodeTree, COMPONENT_INSTANCE)) {
|
|
403
|
+
result = nodeTree.$;
|
|
404
|
+
} else if (nodeTree === null || nodeTree === void 0) {
|
|
405
|
+
result = tree(new Comment("Empty tree context"));
|
|
406
|
+
} else if (matchFlag(nodeTree, HOST_TREE)) {
|
|
407
|
+
result = nodeTree;
|
|
408
|
+
} else {
|
|
409
|
+
throw new BrokenRendererError(`Failed to render ${nodeTree} into a Node.`);
|
|
410
|
+
}
|
|
411
|
+
return result;
|
|
412
|
+
}
|
|
413
|
+
function $(data) {
|
|
414
|
+
return data;
|
|
415
|
+
}
|
|
416
|
+
function flagment(uuid) {
|
|
417
|
+
return `nine_${uuid.replaceAll("-", "_")}`;
|
|
418
|
+
}
|
|
419
|
+
function attachUUID(root, uuid) {
|
|
420
|
+
for (const node of [root, ...root.childNodes]) {
|
|
421
|
+
if (node instanceof HTMLElement) {
|
|
422
|
+
node.dataset[flagment(uuid)] = "true";
|
|
423
|
+
}
|
|
424
|
+
if (node !== root && node.childNodes.length > 0) {
|
|
425
|
+
attachUUID(node, uuid);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
return root;
|
|
429
|
+
}
|
|
430
|
+
function createComponent(options, internalRenderer) {
|
|
431
|
+
validateStore(options.props ?? {});
|
|
432
|
+
const propStore = Object.fromEntries(
|
|
433
|
+
Object.entries(options.props ?? {}).map(([key, value]) => [
|
|
434
|
+
key,
|
|
435
|
+
normalizePropertyDescriptor(value)
|
|
436
|
+
])
|
|
437
|
+
);
|
|
438
|
+
const rawComponentUUID = crypto.randomUUID();
|
|
439
|
+
const flagmentedUUID = flagment(rawComponentUUID);
|
|
440
|
+
if (options.styles) {
|
|
441
|
+
for (const styleSet2 of options.styles) {
|
|
442
|
+
styleSet2.apply(`[data-${flagmentedUUID}="true"]`);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
const entryRenderer = (props, slot) => {
|
|
446
|
+
const nodeTree = internalRenderer(hostdown(props, propStore), pipeExtract(slot), (key, data) => {
|
|
447
|
+
const targetEvent = options.events?.find((e) => e.name === key);
|
|
448
|
+
if (!targetEvent) throw new TypeError(`No events named ${key} to emit.`);
|
|
449
|
+
hostTree.element.dispatchEvent(new CustomEvent(key, {
|
|
450
|
+
detail: data,
|
|
451
|
+
bubbles: targetEvent.bubbleable,
|
|
452
|
+
cancelable: false
|
|
453
|
+
}));
|
|
454
|
+
});
|
|
455
|
+
const hostTree = render(nodeTree);
|
|
456
|
+
attachUUID(hostTree.element, rawComponentUUID);
|
|
457
|
+
hostTree.hooks.treeUpdated.subcribe((newTrees) => newTrees.forEach((tree2) => attachUUID(tree2.element, rawComponentUUID)));
|
|
458
|
+
return attachFlag({
|
|
459
|
+
mount(to) {
|
|
460
|
+
const targets = typeof to === "string" ? [...document.querySelectorAll(to)] : [to];
|
|
461
|
+
for (const target of targets) {
|
|
462
|
+
target.appendChild(hostTree.element);
|
|
463
|
+
}
|
|
464
|
+
},
|
|
465
|
+
on(key, handler) {
|
|
466
|
+
hostTree.on(key, (event) => event instanceof CustomEvent ? handler(event.detail) : null);
|
|
467
|
+
return this;
|
|
468
|
+
},
|
|
469
|
+
$: hostTree
|
|
470
|
+
}, COMPONENT_INSTANCE);
|
|
471
|
+
};
|
|
472
|
+
return Object.assign(entryRenderer, {
|
|
473
|
+
props: propStore,
|
|
474
|
+
events: options.events
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// src/dom/style.ts
|
|
479
|
+
function styleSet(selector) {
|
|
480
|
+
const rules = {};
|
|
481
|
+
const context = new Proxy({
|
|
482
|
+
rules,
|
|
483
|
+
selector,
|
|
484
|
+
apply(selector2) {
|
|
485
|
+
const style = document.createElement("style");
|
|
486
|
+
document.head.appendChild(style);
|
|
487
|
+
style.textContent = `${this.selectorString(selector2)}{${this.ruleString()}}`;
|
|
488
|
+
},
|
|
489
|
+
ruleString() {
|
|
490
|
+
return Object.entries(rules).map(([key, value]) => `${camelToHyphen(String(key))}:${value};`).join("");
|
|
491
|
+
},
|
|
492
|
+
selectorString(selector2) {
|
|
493
|
+
return (this.selector || "") + (selector2 || "") || "*";
|
|
494
|
+
}
|
|
495
|
+
}, {
|
|
496
|
+
get(target, p, receiver) {
|
|
497
|
+
if (Reflect.has(target, p)) {
|
|
498
|
+
return Reflect.get(target, p, receiver);
|
|
499
|
+
} else {
|
|
500
|
+
return (data) => {
|
|
501
|
+
rules[p] = String(data);
|
|
502
|
+
return context;
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
return context;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// src/dom/event.ts
|
|
511
|
+
function defineEvent(name, options) {
|
|
512
|
+
return { name, ...options ?? {} };
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// src/assets/index.ts
|
|
516
|
+
var assets_exports = {};
|
|
517
|
+
__export(assets_exports, {
|
|
518
|
+
logo: () => logo_exports
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
// src/assets/logo.svg
|
|
522
|
+
var logo_exports = {};
|
|
523
|
+
__export(logo_exports, {
|
|
524
|
+
default: () => logo_default
|
|
525
|
+
});
|
|
526
|
+
var logo_default = 'data:image/svg+xml,<svg width="337" height="395" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" overflow="hidden"><defs><filter id="fx0" x="-10%" y="-10%" width="120%" height="120%" filterUnits="userSpaceOnUse" primitiveUnits="userSpaceOnUse"><feComponentTransfer color-interpolation-filters="sRGB"><feFuncR type="discrete" tableValues="1 1"/><feFuncG type="discrete" tableValues="0.752941 0.752941"/><feFuncB type="discrete" tableValues="0 0"/><feFuncA type="linear" slope="0.4" intercept="0"/></feComponentTransfer><feGaussianBlur stdDeviation="0 0"/></filter><clipPath id="clip1"><rect x="119" y="90" width="93" height="142"/></clipPath></defs><g transform="translate(-119 -128)"><g clip-path="url(%23clip1)" filter="url(%23fx0)" transform="translate(125 135)"><g><path d="M37.352-111.688C33.9173-107.395 32.2-101.261 32.2-93.288 32.2-85.4373 33.9173-79.5493 37.352-75.624 40.7867-71.6987 45.5093-69.736 51.52-69.736 60.5973-69.736 68.08-74.6427 73.968-84.456 71.76-107.027 63.9707-118.312 50.6-118.312 45.3253-118.312 40.9093-116.104 37.352-111.688ZM84.088-16.008C74.0293-3.61867 61.5787 2.576 46.736 2.576 32.016 2.576 21.5893-0.797334 15.456-7.544 13.3707-9.26133 11.96-8.34133 11.224-4.784 10.12-10.1813 11.96-15.5787 16.744-20.976 21.528-26.496 25.944-27.4773 29.992-23.92 31.832-20.976 36.9227-19.504 45.264-19.504 53.6053-19.504 60.352-23.0613 65.504-30.176 70.7787-37.4133 73.4773-45.8773 73.6-55.568 73.8453-58.6347 75.1333-60.1067 77.464-59.984 75.3787-63.4187 72.128-63.296 67.712-59.616 63.4187-56.0587 58.7573-53.2987 53.728-51.336 53.6053-50.7227 51.152-50.416 46.368-50.416 34.592-50.416 25.1467-54.0347 18.032-61.272 10.9173-68.632 7.36-79.1813 7.36-92.92 7.36-106.781 11.4693-117.883 19.688-126.224 28.0293-134.565 38.2107-138.736 50.232-138.736 64.216-138.736 75.8693-133.032 85.192-121.624 94.5147-110.339 99.176-93.0427 99.176-69.736 99.176-46.4293 94.1467-28.52 84.088-16.008Z" fill="%23ED7D31" transform="translate(111.796 229)"/></g></g><text fill="%23ED7D31" font-family="Swei Fist Sans CJK JP,Swei Fist Sans CJK JP_MSFontService,sans-serif" font-weight="700" font-size="184" transform="translate(229.799 357)">9</text></g></svg>';
|
|
527
|
+
|
|
528
|
+
// src/examples/Counter.ts
|
|
529
|
+
var Counter_default = createComponent({
|
|
530
|
+
//创建组件
|
|
531
|
+
props: {
|
|
532
|
+
value: {
|
|
533
|
+
//参数名
|
|
534
|
+
validate: Number.isInteger,
|
|
535
|
+
//验证器
|
|
536
|
+
transform: Number,
|
|
537
|
+
//转换器
|
|
538
|
+
required: false,
|
|
539
|
+
//是否必填
|
|
540
|
+
shadow: 0,
|
|
541
|
+
//默认值
|
|
542
|
+
downloadable: true,
|
|
543
|
+
//(上游→下游)
|
|
544
|
+
uploadable: true
|
|
545
|
+
//(下游→上游),v-model双向绑定
|
|
546
|
+
}
|
|
547
|
+
},
|
|
548
|
+
events: [
|
|
549
|
+
defineEvent("up", {
|
|
550
|
+
template: {
|
|
551
|
+
arg1: 0,
|
|
552
|
+
arg2: false
|
|
553
|
+
},
|
|
554
|
+
bubbleable: true
|
|
555
|
+
}),
|
|
556
|
+
defineEvent("down", {
|
|
557
|
+
template: {
|
|
558
|
+
arg3: "sb",
|
|
559
|
+
arg4: /* @__PURE__ */ Symbol()
|
|
560
|
+
},
|
|
561
|
+
bubbleable: true
|
|
562
|
+
})
|
|
563
|
+
]
|
|
564
|
+
}, (props) => {
|
|
565
|
+
const doubled = sync(() => props.value.get() * 2, [props.value]);
|
|
566
|
+
return tree("div").use(styleSet().fontSize("20px").padding("10px")).append(
|
|
567
|
+
"\u6572\u6728\u9C7C",
|
|
568
|
+
tree("br"),
|
|
569
|
+
tree("button").on("click", () => props.value.set(props.value.get() + 1)).append("\u70B9\u51FB\u52A0\u4E00"),
|
|
570
|
+
tree("button").on("click", () => props.value.set(props.value.get() - 1)).append("\u70B9\u51FB\u51CF\u4E00"),
|
|
571
|
+
tree("br"),
|
|
572
|
+
"\u5F53\u524D\u503C\uFF1A",
|
|
573
|
+
$(props.value),
|
|
574
|
+
//引用响应式的值,类似模板语法{{ count }}
|
|
575
|
+
"\u53CC\u500D\u503C\uFF1A",
|
|
576
|
+
$(doubled),
|
|
577
|
+
$(sync(
|
|
578
|
+
//只要是能渲染的东西,就能进行响应式引用
|
|
579
|
+
() => createArray(
|
|
580
|
+
doubled.get(),
|
|
581
|
+
() => tree("div").append("\u4F60\u70B9\u4E86\u4E00\u4E0B")
|
|
582
|
+
),
|
|
583
|
+
[doubled]
|
|
584
|
+
)),
|
|
585
|
+
//列表渲染v-for
|
|
586
|
+
when(
|
|
587
|
+
() => props.value.get() > 10,
|
|
588
|
+
() => tree("p").append("count > 10 \u65F6\u663E\u793A"),
|
|
589
|
+
[props.value]
|
|
590
|
+
)
|
|
591
|
+
//条件渲染v-if
|
|
592
|
+
);
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
// src/examples/Selector.ts
|
|
596
|
+
var Selector_default = createComponent({
|
|
597
|
+
props: {
|
|
598
|
+
items: {
|
|
599
|
+
transform: rawProperty(),
|
|
600
|
+
shadow: ["OptionA", "OptionB", "OptionC"]
|
|
601
|
+
},
|
|
602
|
+
value: {
|
|
603
|
+
transform: Number,
|
|
604
|
+
uploadable: true,
|
|
605
|
+
required: true
|
|
606
|
+
}
|
|
607
|
+
},
|
|
608
|
+
events: [
|
|
609
|
+
defineEvent("select", { template: 0 }),
|
|
610
|
+
defineEvent("toggleState", { template: false })
|
|
611
|
+
],
|
|
612
|
+
styles: [
|
|
613
|
+
styleSet(".item").backgroundColor("blue").color("white"),
|
|
614
|
+
styleSet(".flexdown").display("flex").flexDirection("column")
|
|
615
|
+
]
|
|
616
|
+
}, (props, slot, emit) => {
|
|
617
|
+
const showing = wrap(false);
|
|
618
|
+
const select = (index) => {
|
|
619
|
+
props.value.set(index);
|
|
620
|
+
showing.set(false);
|
|
621
|
+
emit("select", props.value.get());
|
|
622
|
+
};
|
|
623
|
+
showing.event.subcribe((e) => emit("toggleState", e));
|
|
624
|
+
return tree("div").class("flexdown").ariaAtomic("false").append(
|
|
625
|
+
tree("span").class("item").use(styleSet().backgroundColor("red")).append($(sync(() => props.items.get()[props.value.get()], [props.items, props.value]))).on("click", () => showing.set(!showing.get())),
|
|
626
|
+
slot(),
|
|
627
|
+
when(
|
|
628
|
+
showing,
|
|
629
|
+
() => tree("div").class("flexdown").append(
|
|
630
|
+
$(sync(() => props.items.get().map(
|
|
631
|
+
(label, index) => tree("span").class("item").append(label).on("click", () => select(index))
|
|
632
|
+
), [props.items]))
|
|
633
|
+
)
|
|
634
|
+
)
|
|
635
|
+
);
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
// src/examples/index.ts
|
|
639
|
+
var examples_default = { Counter: Counter_default, Selector: Selector_default };
|
|
640
|
+
|
|
641
|
+
// src/index.ts
|
|
642
|
+
if (window.__NINE_ENV__?.mode === "development") {
|
|
643
|
+
console.warn("[Nine-9] Initialized in development mode.");
|
|
644
|
+
}
|
|
645
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
646
|
+
0 && (module.exports = {
|
|
647
|
+
$,
|
|
648
|
+
EventSubcriber,
|
|
649
|
+
assets,
|
|
650
|
+
attachUUID,
|
|
651
|
+
camelToHyphen,
|
|
652
|
+
createArray,
|
|
653
|
+
createComponent,
|
|
654
|
+
defineEvent,
|
|
655
|
+
examples,
|
|
656
|
+
flagment,
|
|
657
|
+
hostdown,
|
|
658
|
+
hyphenToCamel,
|
|
659
|
+
normalizePropertyDescriptor,
|
|
660
|
+
pipeExtract,
|
|
661
|
+
putIntoArray,
|
|
662
|
+
rawProperty,
|
|
663
|
+
render,
|
|
664
|
+
styleSet,
|
|
665
|
+
sync,
|
|
666
|
+
tree,
|
|
667
|
+
typedIsArray,
|
|
668
|
+
validateStore,
|
|
669
|
+
when,
|
|
670
|
+
wrap
|
|
671
|
+
});
|
|
672
|
+
//# sourceMappingURL=index.js.map
|