glass-easel-miniprogram-adapter 0.10.2 → 0.11.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.
- package/dist/glass_easel_miniprogram_adapter.d.ts +22 -7
- package/dist/glass_easel_miniprogram_adapter.es.js +1 -1
- package/dist/glass_easel_miniprogram_adapter.es.js.map +1 -1
- package/dist/glass_easel_miniprogram_adapter.js +1 -1
- package/dist/glass_easel_miniprogram_adapter.js.map +1 -1
- package/package.json +4 -4
- package/src/builder/base_behavior_builder.ts +19 -1
- package/src/builder/behavior_builder.ts +25 -3
- package/src/builder/component_builder.ts +25 -3
- package/src/selector_query.ts +24 -0
- package/tests/selector.test.ts +26 -0
- package/tests/space.test.ts +24 -0
|
@@ -10,6 +10,7 @@ type SelectorQueryFields = {
|
|
|
10
10
|
size?: boolean;
|
|
11
11
|
scrollOffset?: boolean;
|
|
12
12
|
properties?: string[];
|
|
13
|
+
context?: boolean;
|
|
13
14
|
};
|
|
14
15
|
type SelectorQueryResult<T extends SelectorQueryFields> = {
|
|
15
16
|
id: T['id'] extends true ? string : undefined;
|
|
@@ -54,6 +55,9 @@ type ScrollOffset = {
|
|
|
54
55
|
scrollWidth: number;
|
|
55
56
|
scrollHeight: number;
|
|
56
57
|
};
|
|
58
|
+
type ContextResult = {
|
|
59
|
+
context: unknown;
|
|
60
|
+
};
|
|
57
61
|
declare class NodesRef<S extends boolean> {
|
|
58
62
|
private _$sq;
|
|
59
63
|
private _$comp;
|
|
@@ -63,6 +67,7 @@ declare class NodesRef<S extends boolean> {
|
|
|
63
67
|
fields<T extends SelectorQueryFields>(fields: T, cb?: (res: S extends true ? SelectorQueryResult<T> : SelectorQueryResult<T>[]) => void): SelectorQuery;
|
|
64
68
|
boundingClientRect(cb?: (res: S extends true ? BoundingClientRect : BoundingClientRect[]) => void): SelectorQuery;
|
|
65
69
|
scrollOffset(cb?: (res: S extends true ? ScrollOffset : ScrollOffset[]) => void): SelectorQuery;
|
|
70
|
+
context(cb?: (res: S extends true ? ContextResult : any[]) => void): SelectorQuery;
|
|
66
71
|
}
|
|
67
72
|
declare class SelectorQuery {
|
|
68
73
|
private _$comp;
|
|
@@ -489,9 +494,9 @@ declare class BaseBehaviorBuilder<TPrevData extends DataList$3 = Empty$3, TData
|
|
|
489
494
|
}>(traitBehavior: TraitBehavior<TIn, any>, impl: TIn): ResolveBehaviorBuilder<this, TChainingFilter>;
|
|
490
495
|
/** Add external classes */
|
|
491
496
|
externalClasses(list: string[]): this;
|
|
492
|
-
/** Set the export value when the component is being selected */
|
|
493
497
|
export<TNewComponentExport>(f: (this: GeneralComponent, source: GeneralComponent | null) => TNewComponentExport): ResolveBehaviorBuilder<BaseBehaviorBuilder<TPrevData, TData, TProperty, TMethod, TChainingFilter, TPendingChainingFilter, TNewComponentExport, TExtraThisFields>, TChainingFilter>;
|
|
494
498
|
data<T extends DataList$3>(gen: () => typeUtils.NewFieldList<AllData<TData, TProperty>, T>): ResolveBehaviorBuilder<BaseBehaviorBuilder<T, TData & T, TProperty, TMethod, TChainingFilter, TPendingChainingFilter, TComponentExport, TExtraThisFields>, TChainingFilter>;
|
|
499
|
+
staticData<T extends DataList$3>(data: typeUtils.NewFieldList<AllData<TData, TProperty>, T>): ResolveBehaviorBuilder<BaseBehaviorBuilder<T, TData & T, TProperty, TMethod, TChainingFilter, TPendingChainingFilter, TComponentExport, TExtraThisFields>, TChainingFilter>;
|
|
495
500
|
property<N extends string, T extends PropertyType$2, V extends PropertyTypeToValueType$2<T>>(name: N, def: N extends keyof (TData & TProperty) ? never : typeUtils.PropertyListItem<T, V>): ResolveBehaviorBuilder<BaseBehaviorBuilder<TPrevData, TData, TProperty & Record<N, unknown extends V ? T : typeUtils.PropertyOption<T, V>>, TMethod, TChainingFilter, TPendingChainingFilter, TComponentExport, TExtraThisFields>, TChainingFilter>;
|
|
496
501
|
/**
|
|
497
502
|
* Add some public methods
|
|
@@ -555,9 +560,15 @@ declare class BehaviorBuilder<TPrevData extends DataList$2 = Empty$2, TData exte
|
|
|
555
560
|
* Add some template data fields
|
|
556
561
|
*
|
|
557
562
|
* It does not support raw data, but a `gen` function which returns the new data fields.
|
|
558
|
-
* The `gen` function executes once during component creation.
|
|
563
|
+
* The `gen` function executes once during component instance creation.
|
|
559
564
|
*/
|
|
560
565
|
data<T extends DataList$2>(gen: () => typeUtils.NewFieldList<AllData<TData, TProperty>, T>): ResolveBehaviorBuilder<BehaviorBuilder<T, TData & T, TProperty, TMethod, TChainingFilter, TPendingChainingFilter, TComponentExport, TExtraThisFields>, TChainingFilter>;
|
|
566
|
+
/**
|
|
567
|
+
* Add some template data fields
|
|
568
|
+
*
|
|
569
|
+
* The data should be JSON-compatible, and will be cloned during component creation.
|
|
570
|
+
*/
|
|
571
|
+
staticData<T extends DataList$2>(data: typeUtils.NewFieldList<AllData<TData, TProperty>, T>): ResolveBehaviorBuilder<BehaviorBuilder<T, TData & T, TProperty, TMethod, TChainingFilter, TPendingChainingFilter, TComponentExport, TExtraThisFields>, TChainingFilter>;
|
|
561
572
|
/**
|
|
562
573
|
* Add a single property
|
|
563
574
|
*
|
|
@@ -574,8 +585,7 @@ declare class BehaviorBuilder<TPrevData extends DataList$2 = Empty$2, TData exte
|
|
|
574
585
|
* Execute a function while component instance creation
|
|
575
586
|
*
|
|
576
587
|
* A `BuilderContext` is provided to tweak the component creation progress.
|
|
577
|
-
* The return value is used as the "export" value of the behavior
|
|
578
|
-
* which can be imported by other behaviors.
|
|
588
|
+
* The return value is used as the "export" value of the behavior.
|
|
579
589
|
*/
|
|
580
590
|
init<TExport extends Record<string, TaggedMethod$1<(...args: any[]) => any>> | void>(func: (this: Component<TData, TProperty, TMethod, TComponentExport, TExtraThisFields>, builderContext: BuilderContext<TPrevData, TProperty, Component<TData, TProperty, TMethod, TComponentExport, TExtraThisFields>>) => TExport): ResolveBehaviorBuilder<BehaviorBuilder<TPrevData, TData, TProperty, TMethod & (TExport extends void ? Empty$2 : {
|
|
581
591
|
[K in keyof TExport]: UnTaggedMethod$1<TExport[K]>;
|
|
@@ -624,9 +634,15 @@ declare class ComponentBuilder<TPrevData extends DataList$1 = Empty$1, TData ext
|
|
|
624
634
|
* Add some template data fields
|
|
625
635
|
*
|
|
626
636
|
* It does not support raw data, but a `gen` function which returns the new data fields.
|
|
627
|
-
* The `gen` function executes once during component creation.
|
|
637
|
+
* The `gen` function executes once during component instance creation.
|
|
628
638
|
*/
|
|
629
639
|
data<T extends DataList$1>(gen: () => typeUtils.NewFieldList<AllData<TData, TProperty>, T>): ResolveBehaviorBuilder<ComponentBuilder<T, TData & T, TProperty, TMethod, TChainingFilter, TPendingChainingFilter, TComponentExport, TExtraThisFields>, TChainingFilter>;
|
|
640
|
+
/**
|
|
641
|
+
* Add some template data fields
|
|
642
|
+
*
|
|
643
|
+
* The data should be JSON-compatible, and will be cloned during component creation.
|
|
644
|
+
*/
|
|
645
|
+
staticData<T extends DataList$1>(data: typeUtils.NewFieldList<AllData<TData, TProperty>, T>): ResolveBehaviorBuilder<ComponentBuilder<T, TData & T, TProperty, TMethod, TChainingFilter, TPendingChainingFilter, TComponentExport, TExtraThisFields>, TChainingFilter>;
|
|
630
646
|
/**
|
|
631
647
|
* Add a single property
|
|
632
648
|
*
|
|
@@ -643,8 +659,7 @@ declare class ComponentBuilder<TPrevData extends DataList$1 = Empty$1, TData ext
|
|
|
643
659
|
* Execute a function while component instance creation
|
|
644
660
|
*
|
|
645
661
|
* A `BuilderContext` is provided to tweak the component creation progress.
|
|
646
|
-
* The return value is used as the "export" value of the behavior
|
|
647
|
-
* which can be imported by other behaviors.
|
|
662
|
+
* The return value is used as the "export" value of the behavior.
|
|
648
663
|
*/
|
|
649
664
|
init<TExport extends Record<string, TaggedMethod<(...args: any[]) => any>> | void>(func: (this: Component<TData, TProperty, TMethod, TComponentExport, TExtraThisFields>, builderContext: BuilderContext<TPrevData, TProperty, Component<TData, TProperty, TMethod, TComponentExport, TExtraThisFields>>) => TExport): ResolveBehaviorBuilder<ComponentBuilder<TPrevData, TData, TProperty, TMethod & (TExport extends void ? Empty$1 : {
|
|
650
665
|
[K in keyof TExport]: UnTaggedMethod<TExport[K]>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import*as e from"glass-easel";import{typeUtils as t}from"glass-easel";export{e as glassEasel};class i{constructor(e,t){this._$env=e,this._$=t}registerStyleSheetContent(e,t){this._$.registerStyleSheetContent(e,t)}createRoot(e,t,i,s){if(this._$env!==t._$env)throw new Error("The code space is not in the same environment as the backend");return new o(this._$,e,t,i,s)}}class o{constructor(t,i,o,s,r){if(this._$comp=o.getComponentSpace().createComponentByUrl(i,s,r||null,t),o.isMainSpace()){const e=o.getStyleSheet("app");if(void 0!==e){const i=o._$styleIsolationMap[this._$comp.is];"isolated"!==i&&"apply-shared"!==i&&"shared"!==i||t.appendStyleSheetPath(e,o._$sharedStyleScope)}}const n=i=>{const{styleScope:o}=i.getComponentOptions(),s=i.behavior.ownerSpace.__wxCodeSpace,r=null==s?void 0:s.getStyleSheet(i.is);void 0!==r&&t.appendStyleSheetPath(r,null!=o?o:e.StyleScopeManager.globalScope())};this._$comp.getRootBehavior().getComponentDependencies().forEach(n),n(this._$comp.getComponentDefinition())}get(){return this._$comp.getMethodCaller()}getComponent(){return this._$comp}attach(t,i){e.Element.replaceDocumentElement(this._$comp,t,i)}release(){e.Element.pretendDetached(this._$comp),this._$comp.destroyBackendElement()}}const s=(e,t)=>{let i=!1,o=e.length;const s=new Array(o);e.forEach(((e,r)=>{e((e=>{s[r]=e,o-=1,0===o&&i&&t(s)}))})),i=!0,0===o&&setTimeout((()=>{t(s)}),0)};class r{constructor(e,t,i,o){this._$sq=e,this._$comp=t,this._$sel=i,this._$single=o}fields(e,t=(()=>{})){return this._$sq._$push(this._$sel,this._$comp,this._$single,e,t),this._$sq}boundingClientRect(e=(()=>{})){return this._$sq._$push(this._$sel,this._$comp,this._$single,{id:!0,dataset:!0,rect:!0,size:!0},e),this._$sq}scrollOffset(e=(()=>{})){return this._$sq._$push(this._$sel,this._$comp,this._$single,{id:!0,dataset:!0,scrollOffset:!0},e),this._$sq}}class n{constructor(e){this._$comp=e,this._$queue=[]}in(e){return this._$comp=e,this}select(e){return new r(this,this._$comp,e,!0)}selectAll(e){return new r(this,this._$comp,e,!1)}selectViewport(){return new r(this,this._$comp,null,!0)}_$push(e,t,i,o,s){this._$queue.push({component:t,selector:e,single:i,fields:o,cb:s})}exec(t=(()=>{})){const i=this._$queue;s(i.map((t=>i=>{const{component:o,selector:r,single:n,fields:a,cb:l}=t;if(null===r){const e={};s([t=>{const i=o._$.getBackendContext(),s=i?i.getWindowWidth():0,r=i?i.getWindowHeight():0;if(a.id&&(e.id=""),a.dataset&&(e.dataset={}),a.mark&&(e.mark={}),a.rect&&(e.left=0,e.top=0,e.right=s,e.bottom=r),a.size&&(e.width=s,e.height=r),a.scrollOffset){let i=o._$.general();for(;i.ownerShadowRoot;)i=i.ownerShadowRoot.getHostNode();i.getBoundingClientRect((({left:i,top:o,width:s,height:r})=>{e.scrollLeft=i,e.scrollTop=o,e.scrollWidth=s,e.scrollHeight=r,t(void 0)}))}else t(void 0)}],(()=>{l(e),i(e)}))}else{const t=(t,i)=>{const o={};a.id&&(o.id=t.id),a.dataset&&(o.dataset=t.dataset),a.mark&&(o.mark=t.collectMarks()),s([e=>{a.rect||a.size?t.getBoundingClientRect((t=>{a.rect&&(o.left=t.left,o.top=t.top,o.right=t.left+t.width,o.bottom=t.top+t.height),a.size&&(o.width=t.width,o.height=t.height),e(void 0)})):e(void 0)},e=>{a.scrollOffset?t.getScrollOffset((t=>{o.scrollLeft=t.scrollLeft,o.scrollTop=t.scrollTop,o.scrollWidth=t.scrollWidth,o.scrollHeight=t.scrollHeight,e(void 0)})):e(void 0)}],(()=>{a.properties&&e.Component.isComponent(t)&&a.properties.forEach((i=>{if(e.Component.hasProperty(t,i)){const s=t.getComponentOptions().propertyPassingDeepCopy,r=t.data[i];s===e.DeepCopyKind.None?o[i]=r:s===e.DeepCopyKind.Simple?o[i]=e.dataUtils.simpleDeepCopy(r):s===e.DeepCopyKind.SimpleWithRecursion&&(o[i]=e.dataUtils.deepCopy(r,!0))}})),i(o)}))};if(n){const e=o._$.getShadowRoot().querySelector(r);e?t(e,(e=>{l(e),i(e)})):setTimeout((()=>{l(null),i(null)}),0)}else{const e=o._$.getShadowRoot().querySelectorAll(r);s(e.map((e=>i=>{t(e,(e=>{i(e)}))})),(e=>{l(e),i(e)}))}}})),t)}}const a={left:0,top:0,right:0,bottom:0};class l{constructor(e,t,i,o){this._$selector=null,this._$margins=null,this._$observers=[],this._$comp=e,this._$thresholds=t,this._$initialRatio=i,this._$observeAll=o}relativeTo(e,t){return this._$selector=e,this._$margins=null!=t?t:a,this}relativeToViewport(e){return this._$selector=null,this._$margins=null!=e?e:a,this}observe(e,t){const i=this._$comp._$.getShadowRoot();let o,s;if(i)if(this._$observeAll)o=i.querySelectorAll(e);else{const t=i.querySelector(e);o=null===t?[]:[t]}else o=[];if(null!==this._$selector&&i){const e=i.querySelector(this._$selector);null===e||(s=e)}else s=null;if(!this._$margins)throw new Error("`relativeTo` or `relativeToViewport` should be called before observe");const{left:r,top:n,right:a,bottom:l}=this._$margins,h=`${n}px ${a}px ${l}px ${r}px`;o.forEach((e=>{let i=this._$initialRatio;const o=e.createIntersectionObserver(s,h,this._$thresholds,(e=>{if(null!==i){let t=0;for(;t<this._$thresholds.length;t+=1){const o=this._$thresholds[t];if(i!==e.intersectionRatio&&(i-o)*(e.intersectionRatio-o)<=0)break}if(i=null,t<this._$thresholds.length)return}t(e)}));null===o||this._$observers.push(o)}))}disconnect(){const e=this._$observers;this._$observers=[],e.forEach((e=>e.disconnect()))}}class h{constructor(e){this._$observer=null,this._$comp=e}observe(e,t){var i,o;this._$observer&&this._$observer.disconnect(),this._$observer=(null===(o=null===(i=this._$comp._$.getBackendContext())||void 0===i?void 0:i.createMediaQueryObserver)||void 0===o?void 0:o.call(i,e,t))||null}disconnect(){this._$observer&&this._$observer.disconnect(),this._$observer=null}}const c=(e,t,i)=>{var o;const s=t.asInstanceOf(i._$);if(null===s)return;const r=s.getRootBehavior().ownerSpace,n=s.getMethodCaller(),a=n instanceof d?n:null,l=e._$.getRootBehavior().ownerSpace,h=r!==l?null:a,c=null===(o=null==a?void 0:a._$export)||void 0===o?void 0:o.call(a,r!==l?null:e);return void 0===c?h:c},p=(t,i)=>{var o;if(e.Component.isComponent(i)){const e=i.getRootBehavior().ownerSpace,s=i.getMethodCaller(),r=s instanceof d?s:null,n=t._$.getRootBehavior().ownerSpace,a=e!==n?null:r,l=null===(o=null==r?void 0:r._$export)||void 0===o?void 0:o.call(r,e!==n?null:t);return void 0===l?a:l}};class d{get is(){return this._$.is}set is(e){Object.defineProperty(this,"is",{value:e,writable:!0,enumerable:!0,configurable:!0})}get id(){return this._$.id}set id(e){Object.defineProperty(this,"id",{value:e,writable:!0,enumerable:!0,configurable:!0})}get dataset(){return this._$.dataset}set dataset(e){Object.defineProperty(this,"dataset",{value:e,writable:!0,enumerable:!0,configurable:!0})}get data(){return this._$.data}set data(e){Object.defineProperty(this,"data",{value:e,writable:!0,enumerable:!0,configurable:!0})}get properties(){return this._$.data}set properties(e){Object.defineProperty(this,"properties",{value:e,writable:!0,enumerable:!0,configurable:!0})}groupSetData(t){e.safeCallback("GroupSetData Callback",t,this,[],this._$)}setData(t,i){this._$.setData(t),i&&e.triggerRender(this._$,(()=>{e.safeCallback("SetData Callback",i,this,[],this._$)}))}updateData(e){this._$.updateData(e)}replaceDataOnPath(e,t){this._$.replaceDataOnPath(e,t)}spliceArrayDataOnPath(e,t,i,o){this._$.spliceArrayDataOnPath(e,t,i,o)}applyDataUpdates(){this._$.applyDataUpdates()}groupUpdates(t){return this._$.groupUpdates((()=>e.safeCallback("GroupUpdates Callback",t,this,[],this._$)))}hasBehavior(e){return this._$.hasBehavior(e._$)}traitBehavior(e){return this._$.traitBehavior(e._$)}triggerEvent(e,t,i){return this._$.triggerEvent(e,t,i)}createSelectorQuery(){return new n(this)}createIntersectionObserver(e){return new l(this,(null==e?void 0:e.thresholds)||[0],(null==e?void 0:e.initialRatio)||0,(null==e?void 0:e.observeAll)||!1)}createMediaQueryObserver(){return new h(this)}selectComponent(e,t){var i,o;const s=this._$.getShadowRoot().querySelector(e);return null===s?null:t?null!==(i=c(this,s,t))&&void 0!==i?i:null:null!==(o=p(this,s))&&void 0!==o?o:null}selectAllComponents(e,t){const i=this._$.getShadowRoot().querySelectorAll(e),o=[];return i.forEach((e=>{const i=t?c(this,e,t):p(this,e);void 0!==i&&o.push(i)})),o}selectOwnerComponent(e){var t,i,o;const s=null===(t=this._$.ownerShadowRoot)||void 0===t?void 0:t.getHostNode();return void 0===s?null:e?null!==(i=c(this,s,e))&&void 0!==i?i:null:null!==(o=p(this,s))&&void 0!==o?o:null}getRelationNodes(e){return this._$.getRelationNodes(e).map((e=>e.getMethodCaller()))}general(){return this}asInstanceOf(e){return this._$.asInstanceOf(e._$)?this:null}}class u{constructor(e,t){this.proto=Object.create(d.prototype),Object.assign(this.proto,e),this.proto._$export=t}derive(){return Object.create(this.proto)}}var _=Object.freeze({__proto__:null,ComponentCaller:d,ComponentProto:u});class ${constructor(e,t,i,o,s){if(this._$=e,this._$chainingFilter=o,this._$export=s,void 0!==i){const e=t.map((e=>{var t;return null!==(t=e._$bindedDefinitionFilter)&&void 0!==t?t:null}));this._$bindedDefinitionFilter=t=>{i(t,e)}}}}class g{constructor(e){this._$=e}}class v{constructor(e){this._$=e}}var m=Object.freeze({__proto__:null,Behavior:$,ComponentType:g,TraitBehavior:v});class f{constructor(){this._$parents=[]}implement(e,t){return this._$.implement(e._$,t),this}externalClasses(e){return this._$.externalClasses(e),this}export(e){return this._$export=e,this}data(e){return this._$.data(e),this}property(e,t){return this._$.property(e,t),this}methods(e){return this._$.methods(e),this}observer(e,t,i=!1){return this._$.observer(e,t,i),this}lifetime(e,t,i=!1){return this._$.lifetime(e,t,i),this}pageLifetime(e,t,i=!1){return this._$.pageLifetime(e,t,i),this}relation(e,t){const i=t.target instanceof $||t.target instanceof g?t.target._$:t.target;return this._$.relation(e,{target:i,type:t.type,linked:t.linked,linkChanged:t.linkChanged,unlinked:t.unlinked,linkFailed:t.linkFailed}),this}init(t){return this._$.init((function({data:i,setData:o,implement:s,relation:r,observer:n,lifetime:a,pageLifetime:l,method:h,listener:c}){const p=this,d=t.call(p,{self:p,data:i,setData:(t,i)=>{o(t),i&&e.triggerRender(p._$,(()=>{i()}))},implement:(e,t)=>{s(e._$,t)},relation:e=>{if(e.target instanceof v)return r({target:e.target._$,type:e.type,linked:e.linked,linkChanged:e.linkChanged,unlinked:e.unlinked,linkFailed:e.linkFailed});const t=e.target instanceof $||e.target instanceof g?e.target._$:e.target;return r({target:t,type:e.type,linked:e.linked,linkChanged:e.linkChanged,unlinked:e.unlinked,linkFailed:e.linkFailed})},observer:n,lifetime:a,pageLifetime:l,method:h,listener:c});if(d){const t=Object.keys(d);for(let i=0;i<t.length;i+=1){const o=t[i],s=d[o];e.Component.isTaggedMethod(s)&&(p[o]=s)}}return d})),this}definition(e){var t;null===(t=e.behaviors)||void 0===t||t.forEach((t=>{var i;return null===(i=t._$bindedDefinitionFilter)||void 0===i?void 0:i.call(t,e)}));const i=this._$,{behaviors:o,properties:s,data:r,observers:n,methods:a,created:l,attached:h,ready:c,moved:p,detached:d,lifetimes:u,pageLifetimes:_,relations:$,externalClasses:g,export:v}=e;if(null==o||o.forEach((e=>{this._$parents.push(e),i.behavior(e._$)})),void 0!==r&&("function"==typeof r?i.data(r):i.staticData(r)),void 0!==s){const e=Object.keys(s);for(let t=0;t<e.length;t+=1){const o=e[t];i.property(o,s[o])}}if(void 0!==n)if(Array.isArray(n))for(let e=0;e<n.length;e+=1){const{fields:t,observer:o}=n[e];i.observer(t||"**",o)}else{const e=Object.keys(n);for(let t=0;t<e.length;t+=1){const o=e[t],s=n[o];i.observer(o,s)}}if(a&&i.methods(a),l&&void 0===(null==u?void 0:u.created)&&i.lifetime("created",l,!0),h&&void 0===(null==u?void 0:u.attached)&&i.lifetime("attached",h,!0),c&&void 0===(null==u?void 0:u.ready)&&i.lifetime("ready",c,!0),p&&void 0===(null==u?void 0:u.moved)&&i.lifetime("moved",p,!0),d&&void 0===(null==u?void 0:u.detached)&&i.lifetime("detached",d,!0),u){const e=Object.keys(u);for(let t=0;t<e.length;t+=1){const o=e[t],s=u[o];i.lifetime(o,s,!0)}}if(_){const e=Object.keys(_);for(let t=0;t<e.length;t+=1){const o=e[t],s=_[o];i.pageLifetime(o,s,!0)}}if($){const e=Object.keys($);for(let t=0;t<e.length;t+=1){const o=e[t],s=$[o];i.relation(o,s)}}return g&&i.externalClasses(g),v&&(this._$export=v),this}}class S extends f{static create(e){const t=new S;return t._$codeSpace=e,t._$=e.getComponentSpace().defineWithMethodCaller(),t}chainingFilter(e){return this._$chainingFilter=e,this}behavior(e){return this._$parents.push(e),this._$=this._$.behavior(e._$),e._$chainingFilter?e._$chainingFilter(this):this}export(e){return super.export(e)}data(e){return super.data(e)}property(e,t){return super.property(e,t)}methods(e){return super.methods(e)}init(e){return super.init(e)}definition(e){return super.definition(e),e.definitionFilter&&(this._$definitionFilter=e.definitionFilter),this}register(){return new $(this._$.registerBehavior(),this._$parents,this._$definitionFilter,this._$chainingFilter,this._$export)}extraThisFieldsType(){return this}}class y extends f{static create(e,t,i){const o=new y,s=e._$overallBehavior;return o._$codeSpace=e,o._$=e.getComponentSpace().defineWithMethodCaller(t||""),o._$is=t||"",o._$alias=i,o._$.methodCallerInit((function(){const e=this;let t=o._$proto;if(void 0===t){const i=e.getComponentDefinition().behavior.getMethods();t=o._$proto=new u(i,o._$export)}const i=t.derive();return i._$=e,i})),s&&o._$.behavior(s),o}options(e){return this._$options=e,this}behavior(e){return this._$parents.push(e),this._$=this._$.behavior(e._$),e._$export&&(this._$export=e._$export),e._$chainingFilter?e._$chainingFilter(this):this}export(e){return this._$export=e,this}data(e){return super.data(e)}property(e,t){return super.property(e,t)}methods(e){return super.methods(e)}init(e){return super.init(e)}definition(e){return super.definition(e),e.options&&this.options(e.options),this}pageDefinition(t){const i=Object.create(null),o={methods:{}},s=Object.keys(t);for(let e=0;e<s.length;e+=1){const r=s[e];"data"===r?o.data=t.data:"function"==typeof t[r]?o.methods[r]=t[r]:"methods"===r?i.methods=t.methods:o[r]=t[r]}this.definition(o);const r=Object.keys(o);for(let e=0;e<r.length;e+=1){const t=r[e];"data"!==t&&"methods"!==t&&"behaviors"!==t&&(i[t]=o[t])}return this._$.init((function(){Object.assign(this,e.dataUtils.simpleDeepCopy(i))})),this}register(){var e;const t=this._$is,i=this._$codeSpace,[o,s]=i.prepareComponentOptions(t,this._$options);this._$.options(o);const r=i.getComponentStaticConfig(t),n=null==r?void 0:r.usingComponents,a=null==r?void 0:r.componentGenerics,l=null==r?void 0:r.componentPlaceholder;n&&this._$.usingComponents(n),a&&this._$.generics(a),l&&this._$.placeholders(l);const h=i.getCompiledTemplate(t);h&&this._$.template(h),i._$styleIsolationMap[t]=s;const c=this._$.registerComponent();return null===(e=this._$alias)||void 0===e||e.forEach((e=>{this._$codeSpace.getComponentSpace().exportComponent(e,this._$is)})),new g(c)}extraThisFieldsType(){return this}}var b=Object.freeze({__proto__:null,BehaviorBuilder:S,ComponentBuilder:y});const C=()=>Math.floor(4294967296*(1+Math.random())).toString(16).slice(1);class w{constructor(t,i,o,s){this._$overallBehavior=null,this._$env=t,this._$isMainSpace=i,this.space=new e.ComponentSpace("",null==s?void 0:s.space,null==s?void 0:s.space.styleScopeManager),this.space.__wxCodeSpace=this,this.styleScopeManager=this.space.styleScopeManager,this.staticConfigMap=Object.create(null),this.styleSheetMap=Object.create(null),this.compiledTemplateMap=Object.create(null),this.waitingAliasMap=Object.create(null),Object.keys(o).forEach((e=>{const t=o[e];this.waitingAliasMap[t]?this.waitingAliasMap[t].push(e):this.waitingAliasMap[t]=[e]})),this._$sharedStyleScope=this.styleScopeManager.register(""),this.space.setSharedStyleScope(this._$sharedStyleScope),this._$styleIsolationMap=Object.create(null)}isMainSpace(){return this._$isMainSpace}getComponentSpace(){return this.space}setOverallBehavior(e){this._$overallBehavior=e}importCodeSpace(e,t,i=!1){const o=this._$env.getCodeSpace(e);if(!o)throw new Error(`There is no space "${e}" in the environment`);t&&this.space.importSpace(`plugin://${t}`,o.space,!1),i&&this.space.importSpace(`plugin-private://${e}`,o.space,!0)}addStyleSheet(e,t,i){this.styleSheetMap[e]={url:t,styleScopeName:i}}getStyleSheet(e){var t;return null===(t=this.styleSheetMap[e])||void 0===t?void 0:t.url}getStyleScopeName(e){var t;return null===(t=this.styleSheetMap[e])||void 0===t?void 0:t.styleScopeName}addCompiledTemplate(e,t){this.compiledTemplateMap[e]=t}getCompiledTemplate(e){return this.compiledTemplateMap[e]}addComponentStaticConfig(e,t){this.staticConfigMap[e]=t}getComponentStaticConfig(e){return this.staticConfigMap[e]}prepareComponentOptions(e,t){const i=this.staticConfigMap[e],o=null==i?void 0:i.pureDataPattern,s=o?new RegExp(o):null==t?void 0:t.pureDataPattern,r=null==i?void 0:i.addGlobalClass;let n,a,l=null==i?void 0:i.styleIsolation;void 0===l&&(l=(null==i?void 0:i.component)?r?"apply-shared":"isolated":"shared"),"apply-shared"===l||"page-apply-shared"===l?(n=this.styleScopeManager.register(this.getStyleScopeName(e)||`__${C()}`),a=this._$sharedStyleScope):n="shared"!==l&&"page-shared"!==l||!this._$isMainSpace?this.styleScopeManager.register(this.getStyleScopeName(e)||`__${C()}`):this._$sharedStyleScope;return[{idPrefixGenerator:C,multipleSlots:null==t?void 0:t.multipleSlots,dynamicSlots:null==t?void 0:t.dynamicSlots,pureDataPattern:s,virtualHost:null==t?void 0:t.virtualHost,styleScope:n,extraStyleScope:a,dataDeepCopy:null==t?void 0:t.dataDeepCopy,propertyPassingDeepCopy:null==t?void 0:t.propertyPassingDeepCopy,propertyEarlyInit:null==t?void 0:t.propertyEarlyInit},l]}globalComponentEnv(e,t,i){return this.componentEnv(t,(({Page:t,Component:o,Behavior:s})=>{const r=e.Page,n=e.Component,a=e.Behavior;e.Page=t,e.Component=o,e.Behavior=s;const l=i();return e.Page=r,e.Component=n,e.Behavior=a,l}))}componentEnv(e,t){const i=this;function o(e){return void 0!==e?i.behavior().definition(e).register():i.behavior()}return o.trait=i.traitBehavior.bind(i),t({Page:function(t){return i.component(e).pageDefinition(t).register()},Component:function(t){return void 0!==t?i.component(e).definition(t).register():i.component(e)},Behavior:o})}component(e){return y.create(this,e,this.waitingAliasMap[e])}behavior(){return S.create(this)}traitBehavior(e){return new v(void 0===e?this.space.defineTraitBehavior():this.space.defineTraitBehavior(e))}}class O{constructor(){this.codeSpaceMap=Object.create(null),this.globalCodeSpace=new w(this,!1,{})}getGlobalCodeSpace(){return this.globalCodeSpace}associateBackend(t){const o=null!=t?t:new e.CurrentWindowBackendContext;return new i(this,o)}createCodeSpace(e,t,i=Object.create(null)){const o=new w(this,t,i,this.globalCodeSpace);return this.codeSpaceMap[e]=o,o}getCodeSpace(e){return this.codeSpaceMap[e]}}var k;!function(e){e.Isolated="isolated",e.ApplyShared="apply-shared",e.Shared="shared",e.PageIsolated="page-isolated",e.PageApplyShared="page-apply-shared",e.PageShared="page-shared"}(k||(k={}));var M=Object.freeze({__proto__:null,get StyleIsolation(){return k},utils:t});export{i as AssociatedBackend,w as CodeSpace,O as MiniProgramEnv,o as Root,m as behavior,b as builder,_ as component,M as types};
|
|
1
|
+
import*as e from"glass-easel";import{typeUtils as t}from"glass-easel";export{e as glassEasel};class i{constructor(e,t){this._$env=e,this._$=t}registerStyleSheetContent(e,t){this._$.registerStyleSheetContent(e,t)}createRoot(e,t,i,o){if(this._$env!==t._$env)throw new Error("The code space is not in the same environment as the backend");return new s(this._$,e,t,i,o)}}class s{constructor(t,i,s,o,r){if(this._$comp=s.getComponentSpace().createComponentByUrl(i,o,r||null,t),s.isMainSpace()){const e=s.getStyleSheet("app");if(void 0!==e){const i=s._$styleIsolationMap[this._$comp.is];"isolated"!==i&&"apply-shared"!==i&&"shared"!==i||t.appendStyleSheetPath(e,s._$sharedStyleScope)}}const n=i=>{const{styleScope:s}=i.getComponentOptions(),o=i.behavior.ownerSpace.__wxCodeSpace,r=null==o?void 0:o.getStyleSheet(i.is);void 0!==r&&t.appendStyleSheetPath(r,null!=s?s:e.StyleScopeManager.globalScope())};this._$comp.getRootBehavior().getComponentDependencies().forEach(n),n(this._$comp.getComponentDefinition())}get(){return this._$comp.getMethodCaller()}getComponent(){return this._$comp}attach(t,i){e.Element.replaceDocumentElement(this._$comp,t,i)}release(){e.Element.pretendDetached(this._$comp),this._$comp.destroyBackendElement()}}const o=(e,t)=>{let i=!1,s=e.length;const o=new Array(s);e.forEach(((e,r)=>{e((e=>{o[r]=e,s-=1,0===s&&i&&t(o)}))})),i=!0,0===s&&setTimeout((()=>{t(o)}),0)};class r{constructor(e,t,i,s){this._$sq=e,this._$comp=t,this._$sel=i,this._$single=s}fields(e,t=(()=>{})){return this._$sq._$push(this._$sel,this._$comp,this._$single,e,t),this._$sq}boundingClientRect(e=(()=>{})){return this._$sq._$push(this._$sel,this._$comp,this._$single,{id:!0,dataset:!0,rect:!0,size:!0},e),this._$sq}scrollOffset(e=(()=>{})){return this._$sq._$push(this._$sel,this._$comp,this._$single,{id:!0,dataset:!0,scrollOffset:!0},e),this._$sq}context(e=(()=>{})){return this._$sq._$push(this._$sel,this._$comp,this._$single,{context:!0},e),this._$sq}}class n{constructor(e){this._$comp=e,this._$queue=[]}in(e){return this._$comp=e,this}select(e){return new r(this,this._$comp,e,!0)}selectAll(e){return new r(this,this._$comp,e,!1)}selectViewport(){return new r(this,this._$comp,null,!0)}_$push(e,t,i,s,o){this._$queue.push({component:t,selector:e,single:i,fields:s,cb:o})}exec(t=(()=>{})){const i=this._$queue;o(i.map((t=>i=>{const{component:s,selector:r,single:n,fields:a,cb:l}=t;if(null===r){const e={};o([t=>{const i=s._$.getBackendContext(),o=i?i.getWindowWidth():0,r=i?i.getWindowHeight():0;if(a.id&&(e.id=""),a.dataset&&(e.dataset={}),a.mark&&(e.mark={}),a.rect&&(e.left=0,e.top=0,e.right=o,e.bottom=r),a.size&&(e.width=o,e.height=r),a.scrollOffset){let i=s._$.general();for(;i.ownerShadowRoot;)i=i.ownerShadowRoot.getHostNode();i.getBoundingClientRect((({left:i,top:s,width:o,height:r})=>{e.scrollLeft=i,e.scrollTop=s,e.scrollWidth=o,e.scrollHeight=r,t(void 0)}))}else t(void 0)}],(()=>{l(e),i(e)}))}else{const t=(t,i)=>{const s={};a.id&&(s.id=t.id),a.dataset&&(s.dataset=t.dataset),a.mark&&(s.mark=t.collectMarks()),o([e=>{a.rect||a.size?t.getBoundingClientRect((t=>{a.rect&&(s.left=t.left,s.top=t.top,s.right=t.left+t.width,s.bottom=t.top+t.height),a.size&&(s.width=t.width,s.height=t.height),e(void 0)})):e(void 0)},e=>{a.scrollOffset?t.getScrollOffset((t=>{s.scrollLeft=t.scrollLeft,s.scrollTop=t.scrollTop,s.scrollWidth=t.scrollWidth,s.scrollHeight=t.scrollHeight,e(void 0)})):e(void 0)},e=>{a.context?t.getContext((t=>{s.context=t,e(void 0)})):e(void 0)}],(()=>{a.properties&&e.Component.isComponent(t)&&a.properties.forEach((i=>{if(e.Component.hasProperty(t,i)){const o=t.getComponentOptions().propertyPassingDeepCopy,r=t.data[i];o===e.DeepCopyKind.None?s[i]=r:o===e.DeepCopyKind.Simple?s[i]=e.dataUtils.simpleDeepCopy(r):o===e.DeepCopyKind.SimpleWithRecursion&&(s[i]=e.dataUtils.deepCopy(r,!0))}})),i(s)}))};if(n){const e=s._$.getShadowRoot().querySelector(r);e?t(e,(e=>{l(e),i(e)})):setTimeout((()=>{l(null),i(null)}),0)}else{const e=s._$.getShadowRoot().querySelectorAll(r);o(e.map((e=>i=>{t(e,(e=>{i(e)}))})),(e=>{l(e),i(e)}))}}})),t)}}const a={left:0,top:0,right:0,bottom:0};class l{constructor(e,t,i,s){this._$selector=null,this._$margins=null,this._$observers=[],this._$comp=e,this._$thresholds=t,this._$initialRatio=i,this._$observeAll=s}relativeTo(e,t){return this._$selector=e,this._$margins=null!=t?t:a,this}relativeToViewport(e){return this._$selector=null,this._$margins=null!=e?e:a,this}observe(e,t){const i=this._$comp._$.getShadowRoot();let s,o;if(i)if(this._$observeAll)s=i.querySelectorAll(e);else{const t=i.querySelector(e);s=null===t?[]:[t]}else s=[];if(null!==this._$selector&&i){const e=i.querySelector(this._$selector);null===e||(o=e)}else o=null;if(!this._$margins)throw new Error("`relativeTo` or `relativeToViewport` should be called before observe");const{left:r,top:n,right:a,bottom:l}=this._$margins,h=`${n}px ${a}px ${l}px ${r}px`;s.forEach((e=>{let i=this._$initialRatio;const s=e.createIntersectionObserver(o,h,this._$thresholds,(e=>{if(null!==i){let t=0;for(;t<this._$thresholds.length;t+=1){const s=this._$thresholds[t];if(i!==e.intersectionRatio&&(i-s)*(e.intersectionRatio-s)<=0)break}if(i=null,t<this._$thresholds.length)return}t(e)}));null===s||this._$observers.push(s)}))}disconnect(){const e=this._$observers;this._$observers=[],e.forEach((e=>e.disconnect()))}}class h{constructor(e){this._$observer=null,this._$comp=e}observe(e,t){var i,s;this._$observer&&this._$observer.disconnect(),this._$observer=(null===(s=null===(i=this._$comp._$.getBackendContext())||void 0===i?void 0:i.createMediaQueryObserver)||void 0===s?void 0:s.call(i,e,t))||null}disconnect(){this._$observer&&this._$observer.disconnect(),this._$observer=null}}const c=(e,t,i)=>{var s;const o=t.asInstanceOf(i._$);if(null===o)return;const r=o.getRootBehavior().ownerSpace,n=o.getMethodCaller(),a=n instanceof d?n:null,l=e._$.getRootBehavior().ownerSpace,h=r!==l?null:a,c=null===(s=null==a?void 0:a._$export)||void 0===s?void 0:s.call(a,r!==l?null:e);return void 0===c?h:c},p=(t,i)=>{var s;if(e.Component.isComponent(i)){const e=i.getRootBehavior().ownerSpace,o=i.getMethodCaller(),r=o instanceof d?o:null,n=t._$.getRootBehavior().ownerSpace,a=e!==n?null:r,l=null===(s=null==r?void 0:r._$export)||void 0===s?void 0:s.call(r,e!==n?null:t);return void 0===l?a:l}};class d{get is(){return this._$.is}set is(e){Object.defineProperty(this,"is",{value:e,writable:!0,enumerable:!0,configurable:!0})}get id(){return this._$.id}set id(e){Object.defineProperty(this,"id",{value:e,writable:!0,enumerable:!0,configurable:!0})}get dataset(){return this._$.dataset}set dataset(e){Object.defineProperty(this,"dataset",{value:e,writable:!0,enumerable:!0,configurable:!0})}get data(){return this._$.data}set data(e){Object.defineProperty(this,"data",{value:e,writable:!0,enumerable:!0,configurable:!0})}get properties(){return this._$.data}set properties(e){Object.defineProperty(this,"properties",{value:e,writable:!0,enumerable:!0,configurable:!0})}groupSetData(t){e.safeCallback("GroupSetData Callback",t,this,[],this._$)}setData(t,i){this._$.setData(t),i&&e.triggerRender(this._$,(()=>{e.safeCallback("SetData Callback",i,this,[],this._$)}))}updateData(e){this._$.updateData(e)}replaceDataOnPath(e,t){this._$.replaceDataOnPath(e,t)}spliceArrayDataOnPath(e,t,i,s){this._$.spliceArrayDataOnPath(e,t,i,s)}applyDataUpdates(){this._$.applyDataUpdates()}groupUpdates(t){return this._$.groupUpdates((()=>e.safeCallback("GroupUpdates Callback",t,this,[],this._$)))}hasBehavior(e){return this._$.hasBehavior(e._$)}traitBehavior(e){return this._$.traitBehavior(e._$)}triggerEvent(e,t,i){return this._$.triggerEvent(e,t,i)}createSelectorQuery(){return new n(this)}createIntersectionObserver(e){return new l(this,(null==e?void 0:e.thresholds)||[0],(null==e?void 0:e.initialRatio)||0,(null==e?void 0:e.observeAll)||!1)}createMediaQueryObserver(){return new h(this)}selectComponent(e,t){var i,s;const o=this._$.getShadowRoot().querySelector(e);return null===o?null:t?null!==(i=c(this,o,t))&&void 0!==i?i:null:null!==(s=p(this,o))&&void 0!==s?s:null}selectAllComponents(e,t){const i=this._$.getShadowRoot().querySelectorAll(e),s=[];return i.forEach((e=>{const i=t?c(this,e,t):p(this,e);void 0!==i&&s.push(i)})),s}selectOwnerComponent(e){var t,i,s;const o=null===(t=this._$.ownerShadowRoot)||void 0===t?void 0:t.getHostNode();return void 0===o?null:e?null!==(i=c(this,o,e))&&void 0!==i?i:null:null!==(s=p(this,o))&&void 0!==s?s:null}getRelationNodes(e){return this._$.getRelationNodes(e).map((e=>e.getMethodCaller()))}general(){return this}asInstanceOf(e){return this._$.asInstanceOf(e._$)?this:null}}class u{constructor(e,t){this.proto=Object.create(d.prototype),Object.assign(this.proto,e),this.proto._$export=t}derive(){return Object.create(this.proto)}}var _=Object.freeze({__proto__:null,ComponentCaller:d,ComponentProto:u});class ${constructor(e,t,i,s,o){if(this._$=e,this._$chainingFilter=s,this._$export=o,void 0!==i){const e=t.map((e=>{var t;return null!==(t=e._$bindedDefinitionFilter)&&void 0!==t?t:null}));this._$bindedDefinitionFilter=t=>{i(t,e)}}}}class g{constructor(e){this._$=e}}class v{constructor(e){this._$=e}}var m=Object.freeze({__proto__:null,Behavior:$,ComponentType:g,TraitBehavior:v});class f{constructor(){this._$parents=[]}implement(e,t){return this._$.implement(e._$,t),this}externalClasses(e){return this._$.externalClasses(e),this}export(e){return this._$export=e,this}data(e){return this._$.data(e),this}staticData(e){return this._$.staticData(e),this}property(e,t){return this._$.property(e,t),this}methods(e){return this._$.methods(e),this}observer(e,t,i=!1){return this._$.observer(e,t,i),this}lifetime(e,t,i=!1){return this._$.lifetime(e,t,i),this}pageLifetime(e,t,i=!1){return this._$.pageLifetime(e,t,i),this}relation(e,t){const i=t.target instanceof $||t.target instanceof g?t.target._$:t.target;return this._$.relation(e,{target:i,type:t.type,linked:t.linked,linkChanged:t.linkChanged,unlinked:t.unlinked,linkFailed:t.linkFailed}),this}init(t){return this._$.init((function({data:i,setData:s,implement:o,relation:r,observer:n,lifetime:a,pageLifetime:l,method:h,listener:c}){const p=this,d=t.call(p,{self:p,data:i,setData:(t,i)=>{s(t),i&&e.triggerRender(p._$,(()=>{i()}))},implement:(e,t)=>{o(e._$,t)},relation:e=>{if(e.target instanceof v)return r({target:e.target._$,type:e.type,linked:e.linked,linkChanged:e.linkChanged,unlinked:e.unlinked,linkFailed:e.linkFailed});const t=e.target instanceof $||e.target instanceof g?e.target._$:e.target;return r({target:t,type:e.type,linked:e.linked,linkChanged:e.linkChanged,unlinked:e.unlinked,linkFailed:e.linkFailed})},observer:n,lifetime:a,pageLifetime:l,method:h,listener:c});if(d){const t=Object.keys(d);for(let i=0;i<t.length;i+=1){const s=t[i],o=d[s];e.Component.isTaggedMethod(o)&&(p[s]=o)}}return d})),this}definition(e){var t;null===(t=e.behaviors)||void 0===t||t.forEach((t=>{var i;return null===(i=t._$bindedDefinitionFilter)||void 0===i?void 0:i.call(t,e)}));const i=this._$,{behaviors:s,properties:o,data:r,observers:n,methods:a,created:l,attached:h,ready:c,moved:p,detached:d,lifetimes:u,pageLifetimes:_,relations:$,externalClasses:g,export:v}=e;if(null==s||s.forEach((e=>{this._$parents.push(e),i.behavior(e._$)})),void 0!==r&&("function"==typeof r?i.data(r):i.staticData(r)),void 0!==o){const e=Object.keys(o);for(let t=0;t<e.length;t+=1){const s=e[t];i.property(s,o[s])}}if(void 0!==n)if(Array.isArray(n))for(let e=0;e<n.length;e+=1){const{fields:t,observer:s}=n[e];i.observer(t||"**",s)}else{const e=Object.keys(n);for(let t=0;t<e.length;t+=1){const s=e[t],o=n[s];i.observer(s,o)}}if(a&&i.methods(a),l&&void 0===(null==u?void 0:u.created)&&i.lifetime("created",l,!0),h&&void 0===(null==u?void 0:u.attached)&&i.lifetime("attached",h,!0),c&&void 0===(null==u?void 0:u.ready)&&i.lifetime("ready",c,!0),p&&void 0===(null==u?void 0:u.moved)&&i.lifetime("moved",p,!0),d&&void 0===(null==u?void 0:u.detached)&&i.lifetime("detached",d,!0),u){const e=Object.keys(u);for(let t=0;t<e.length;t+=1){const s=e[t],o=u[s];i.lifetime(s,o,!0)}}if(_){const e=Object.keys(_);for(let t=0;t<e.length;t+=1){const s=e[t],o=_[s];i.pageLifetime(s,o,!0)}}if($){const e=Object.keys($);for(let t=0;t<e.length;t+=1){const s=e[t],o=$[s];i.relation(s,o)}}return g&&i.externalClasses(g),v&&(this._$export=v),this}}class S extends f{static create(e){const t=new S;return t._$codeSpace=e,t._$=e.getComponentSpace().defineWithMethodCaller(),t}chainingFilter(e){return this._$chainingFilter=e,this}behavior(e){return this._$parents.push(e),this._$=this._$.behavior(e._$),e._$chainingFilter?e._$chainingFilter(this):this}export(e){return super.export(e)}data(e){return super.data(e)}staticData(e){return super.staticData(e)}property(e,t){return super.property(e,t)}methods(e){return super.methods(e)}init(e){return super.init(e)}definition(e){return super.definition(e),e.definitionFilter&&(this._$definitionFilter=e.definitionFilter),this}register(){return new $(this._$.registerBehavior(),this._$parents,this._$definitionFilter,this._$chainingFilter,this._$export)}extraThisFieldsType(){return this}}class y extends f{static create(e,t,i){const s=new y,o=e._$overallBehavior;return s._$codeSpace=e,s._$=e.getComponentSpace().defineWithMethodCaller(t||""),s._$is=t||"",s._$alias=i,s._$.methodCallerInit((function(){const e=this;let t=s._$proto;if(void 0===t){const i=e.getComponentDefinition().behavior.getMethods();t=s._$proto=new u(i,s._$export)}const i=t.derive();return i._$=e,i})),o&&s._$.behavior(o),s}options(e){return this._$options=e,this}behavior(e){return this._$parents.push(e),this._$=this._$.behavior(e._$),e._$export&&(this._$export=e._$export),e._$chainingFilter?e._$chainingFilter(this):this}export(e){return this._$export=e,this}data(e){return super.data(e)}staticData(e){return super.staticData(e)}property(e,t){return super.property(e,t)}methods(e){return super.methods(e)}init(e){return super.init(e)}definition(e){return super.definition(e),e.options&&this.options(e.options),this}pageDefinition(t){const i=Object.create(null),s={methods:{}},o=Object.keys(t);for(let e=0;e<o.length;e+=1){const r=o[e];"data"===r?s.data=t.data:"function"==typeof t[r]?s.methods[r]=t[r]:"methods"===r?i.methods=t.methods:s[r]=t[r]}this.definition(s);const r=Object.keys(s);for(let e=0;e<r.length;e+=1){const t=r[e];"data"!==t&&"methods"!==t&&"behaviors"!==t&&(i[t]=s[t])}return this._$.init((function(){Object.assign(this,e.dataUtils.simpleDeepCopy(i))})),this}register(){var e;const t=this._$is,i=this._$codeSpace,[s,o]=i.prepareComponentOptions(t,this._$options);this._$.options(s);const r=i.getComponentStaticConfig(t),n=null==r?void 0:r.usingComponents,a=null==r?void 0:r.componentGenerics,l=null==r?void 0:r.componentPlaceholder;n&&this._$.usingComponents(n),a&&this._$.generics(a),l&&this._$.placeholders(l);const h=i.getCompiledTemplate(t);h&&this._$.template(h),i._$styleIsolationMap[t]=o;const c=this._$.registerComponent();return null===(e=this._$alias)||void 0===e||e.forEach((e=>{this._$codeSpace.getComponentSpace().exportComponent(e,this._$is)})),new g(c)}extraThisFieldsType(){return this}}var b=Object.freeze({__proto__:null,BehaviorBuilder:S,ComponentBuilder:y});const C=()=>Math.floor(4294967296*(1+Math.random())).toString(16).slice(1);class w{constructor(t,i,s,o){this._$overallBehavior=null,this._$env=t,this._$isMainSpace=i,this.space=new e.ComponentSpace("",null==o?void 0:o.space,null==o?void 0:o.space.styleScopeManager),this.space.__wxCodeSpace=this,this.styleScopeManager=this.space.styleScopeManager,this.staticConfigMap=Object.create(null),this.styleSheetMap=Object.create(null),this.compiledTemplateMap=Object.create(null),this.waitingAliasMap=Object.create(null),Object.keys(s).forEach((e=>{const t=s[e];this.waitingAliasMap[t]?this.waitingAliasMap[t].push(e):this.waitingAliasMap[t]=[e]})),this._$sharedStyleScope=this.styleScopeManager.register(""),this.space.setSharedStyleScope(this._$sharedStyleScope),this._$styleIsolationMap=Object.create(null)}isMainSpace(){return this._$isMainSpace}getComponentSpace(){return this.space}setOverallBehavior(e){this._$overallBehavior=e}importCodeSpace(e,t,i=!1){const s=this._$env.getCodeSpace(e);if(!s)throw new Error(`There is no space "${e}" in the environment`);t&&this.space.importSpace(`plugin://${t}`,s.space,!1),i&&this.space.importSpace(`plugin-private://${e}`,s.space,!0)}addStyleSheet(e,t,i){this.styleSheetMap[e]={url:t,styleScopeName:i}}getStyleSheet(e){var t;return null===(t=this.styleSheetMap[e])||void 0===t?void 0:t.url}getStyleScopeName(e){var t;return null===(t=this.styleSheetMap[e])||void 0===t?void 0:t.styleScopeName}addCompiledTemplate(e,t){this.compiledTemplateMap[e]=t}getCompiledTemplate(e){return this.compiledTemplateMap[e]}addComponentStaticConfig(e,t){this.staticConfigMap[e]=t}getComponentStaticConfig(e){return this.staticConfigMap[e]}prepareComponentOptions(e,t){const i=this.staticConfigMap[e],s=null==i?void 0:i.pureDataPattern,o=s?new RegExp(s):null==t?void 0:t.pureDataPattern,r=null==i?void 0:i.addGlobalClass;let n,a,l=null==i?void 0:i.styleIsolation;void 0===l&&(l=(null==i?void 0:i.component)?r?"apply-shared":"isolated":"shared"),"apply-shared"===l||"page-apply-shared"===l?(n=this.styleScopeManager.register(this.getStyleScopeName(e)||`__${C()}`),a=this._$sharedStyleScope):n="shared"!==l&&"page-shared"!==l||!this._$isMainSpace?this.styleScopeManager.register(this.getStyleScopeName(e)||`__${C()}`):this._$sharedStyleScope;return[{idPrefixGenerator:C,multipleSlots:null==t?void 0:t.multipleSlots,dynamicSlots:null==t?void 0:t.dynamicSlots,pureDataPattern:o,virtualHost:null==t?void 0:t.virtualHost,styleScope:n,extraStyleScope:a,dataDeepCopy:null==t?void 0:t.dataDeepCopy,propertyPassingDeepCopy:null==t?void 0:t.propertyPassingDeepCopy,propertyEarlyInit:null==t?void 0:t.propertyEarlyInit},l]}globalComponentEnv(e,t,i){return this.componentEnv(t,(({Page:t,Component:s,Behavior:o})=>{const r=e.Page,n=e.Component,a=e.Behavior;e.Page=t,e.Component=s,e.Behavior=o;const l=i();return e.Page=r,e.Component=n,e.Behavior=a,l}))}componentEnv(e,t){const i=this;function s(e){return void 0!==e?i.behavior().definition(e).register():i.behavior()}return s.trait=i.traitBehavior.bind(i),t({Page:function(t){return i.component(e).pageDefinition(t).register()},Component:function(t){return void 0!==t?i.component(e).definition(t).register():i.component(e)},Behavior:s})}component(e){return y.create(this,e,this.waitingAliasMap[e])}behavior(){return S.create(this)}traitBehavior(e){return new v(void 0===e?this.space.defineTraitBehavior():this.space.defineTraitBehavior(e))}}class O{constructor(){this.codeSpaceMap=Object.create(null),this.globalCodeSpace=new w(this,!1,{})}getGlobalCodeSpace(){return this.globalCodeSpace}associateBackend(t){const s=null!=t?t:new e.CurrentWindowBackendContext;return new i(this,s)}createCodeSpace(e,t,i=Object.create(null)){const s=new w(this,t,i,this.globalCodeSpace);return this.codeSpaceMap[e]=s,s}getCodeSpace(e){return this.codeSpaceMap[e]}}var k;!function(e){e.Isolated="isolated",e.ApplyShared="apply-shared",e.Shared="shared",e.PageIsolated="page-isolated",e.PageApplyShared="page-apply-shared",e.PageShared="page-shared"}(k||(k={}));var M=Object.freeze({__proto__:null,get StyleIsolation(){return k},utils:t});export{i as AssociatedBackend,w as CodeSpace,O as MiniProgramEnv,s as Root,m as behavior,b as builder,_ as component,M as types};
|
|
2
2
|
//# sourceMappingURL=glass_easel_miniprogram_adapter.es.js.map
|