UNPKG

@egjs/preact-flicking

Version:

Everyday 30 million people experience. It's reliable, flexible and extendable carousel.

1,417 lines (1,282 loc) 525 kB
/* Copyright (c) 2021-present NAVER Corp. name: @egjs/preact-flicking license: MIT author: NAVER Corp. repository: https://github.com/naver/egjs-flicking/blob/master/packages/preact-flicking version: 4.14.0 */ 'use strict'; var React = require('preact'); var t,u,r,o=0,i=[],c=React.options.__b,f=React.options.__r,e=React.options.diffed,a=React.options.__c,v=React.options.unmount;function m(t,r){React.options.__h&&React.options.__h(u,t,o||r),o=0;var i=u.__H||(u.__H={__:[],__h:[]});return t>=i.__.length&&i.__.push({}),i.__[t]}function l(n){return o=1,p(w,n)}function p(n,r,o){var i=m(t++,2);return i.t=n,i.__c||(i.__=[o?o(r):w(void 0,r),function(n){var t=i.t(i.__[0],n);i.__[0]!==t&&(i.__=[t,i.__[1]],i.__c.setState({}));}],i.__c=u),i.__}function y(r,o){var i=m(t++,3);!React.options.__s&&k(i.__H,o)&&(i.__=r,i.__H=o,u.__H.__h.push(i));}function h(r,o){var i=m(t++,4);!React.options.__s&&k(i.__H,o)&&(i.__=r,i.__H=o,u.__h.push(i));}function s(n){return o=5,d(function(){return {current:n}},[])}function _(n,t,u){o=6,h(function(){"function"==typeof n?n(t()):n&&(n.current=t());},null==u?u:u.concat(n));}function d(n,u){var r=m(t++,7);return k(r.__H,u)&&(r.__=n(),r.__H=u,r.__h=n),r.__}function A(n,t){return o=8,d(function(){return n},t)}function F(n){var r=u.context[n.__c],o=m(t++,9);return o.c=n,r?(null==o.__&&(o.__=!0,r.sub(u)),r.props.value):n.__}function T(t,u){React.options.useDebugValue&&React.options.useDebugValue(u?u(t):t);}function x(){var t;for(i.sort(function(n,t){return n.__v.__b-t.__v.__b});t=i.pop();)if(t.__P)try{t.__H.__h.forEach(g),t.__H.__h.forEach(j),t.__H.__h=[];}catch(u){t.__H.__h=[],React.options.__e(u,t.__v);}}React.options.__b=function(n){u=null,c&&c(n);},React.options.__r=function(n){f&&f(n),t=0;var r=(u=n.__c).__H;r&&(r.__h.forEach(g),r.__h.forEach(j),r.__h=[]);},React.options.diffed=function(t){e&&e(t);var o=t.__c;o&&o.__H&&o.__H.__h.length&&(1!==i.push(o)&&r===React.options.requestAnimationFrame||((r=React.options.requestAnimationFrame)||function(n){var t,u=function(){clearTimeout(r),b&&cancelAnimationFrame(t),setTimeout(n);},r=setTimeout(u,100);b&&(t=requestAnimationFrame(u));})(x)),u=null;},React.options.__c=function(t,u){u.some(function(t){try{t.__h.forEach(g),t.__h=t.__h.filter(function(n){return !n.__||j(n)});}catch(r){u.some(function(n){n.__h&&(n.__h=[]);}),u=[],React.options.__e(r,t.__v);}}),a&&a(t,u);},React.options.unmount=function(t){v&&v(t);var u,r=t.__c;r&&r.__H&&(r.__H.__.forEach(function(n){try{g(n);}catch(n){u=n;}}),u&&React.options.__e(u,r.__v));};var b="function"==typeof requestAnimationFrame;function g(n){var t=u,r=n.__c;"function"==typeof r&&(n.__c=void 0,r()),u=t;}function j(n){var t=u;n.__c=n.__(),u=t;}function k(n,t){return !n||n.length!==t.length||t.some(function(t,u){return t!==n[u]})}function w(n,t){return "function"==typeof t?t(n):t} function S(n,t){for(var e in t)n[e]=t[e];return n}function C(n,t){for(var e in n)if("__source"!==e&&!(e in t))return !0;for(var r in t)if("__source"!==r&&n[r]!==t[r])return !0;return !1}function E(n){this.props=n;}function g$1(n,t){function e(n){var e=this.props.ref,r=e==n.ref;return !r&&e&&(e.call?e(null):e.current=null),t?!t(this.props,n)||!r:C(this.props,n)}function r(t){return this.shouldComponentUpdate=e,React.createElement(n,t)}return r.displayName="Memo("+(n.displayName||n.name)+")",r.prototype.isReactComponent=!0,r.__f=!0,r}(E.prototype=new React.Component).isPureReactComponent=!0,E.prototype.shouldComponentUpdate=function(n,t){return C(this.props,n)||C(this.state,t)};var w$1=React.options.__b;React.options.__b=function(n){n.type&&n.type.__f&&n.ref&&(n.props.ref=n.ref,n.ref=null),w$1&&w$1(n);};var R="undefined"!=typeof Symbol&&Symbol.for&&Symbol.for("react.forward_ref")||3911;function x$1(n){function t(t,e){var r=S({},t);return delete r.ref,n(r,(e=t.ref||e)&&("object"!=typeof e||"current"in e)?e:null)}return t.$$typeof=R,t.render=t,t.prototype.isReactComponent=t.__f=!0,t.displayName="ForwardRef("+(n.displayName||n.name)+")",t}var N=function(n,t){return null==n?null:React.toChildArray(React.toChildArray(n).map(t))},k$1={map:N,forEach:N,count:function(n){return n?React.toChildArray(n).length:0},only:function(n){var t=React.toChildArray(n);if(1!==t.length)throw "Children.only";return t[0]},toArray:React.toChildArray},A$1=React.options.__e;React.options.__e=function(n,t,e){if(n.then)for(var r,u=t;u=u.__;)if((r=u.__c)&&r.__c)return null==t.__e&&(t.__e=e.__e,t.__k=e.__k),r.__c(n,t);A$1(n,t,e);};var O=React.options.unmount;function L(){this.__u=0,this.t=null,this.__b=null;}function U(n){var t=n.__.__c;return t&&t.__e&&t.__e(n)}function F$1(n){var t,e,r;function u(u){if(t||(t=n()).then(function(n){e=n.default||n;},function(n){r=n;}),r)throw r;if(!e)throw t;return React.createElement(e,u)}return u.displayName="Lazy",u.__f=!0,u}function M(){this.u=null,this.o=null;}React.options.unmount=function(n){var t=n.__c;t&&t.__R&&t.__R(),t&&!0===n.__h&&(n.type=null),O&&O(n);},(L.prototype=new React.Component).__c=function(n,t){var e=t.__c,r=this;null==r.t&&(r.t=[]),r.t.push(e);var u=U(r.__v),o=!1,i=function(){o||(o=!0,e.__R=null,u?u(l):l());};e.__R=i;var l=function(){if(!--r.__u){if(r.state.__e){var n=r.state.__e;r.__v.__k[0]=function n(t,e,r){return t&&(t.__v=null,t.__k=t.__k&&t.__k.map(function(t){return n(t,e,r)}),t.__c&&t.__c.__P===e&&(t.__e&&r.insertBefore(t.__e,t.__d),t.__c.__e=!0,t.__c.__P=r)),t}(n,n.__c.__P,n.__c.__O);}var t;for(r.setState({__e:r.__b=null});t=r.t.pop();)t.forceUpdate();}},c=!0===t.__h;r.__u++||c||r.setState({__e:r.__b=r.__v.__k[0]}),n.then(i,i);},L.prototype.componentWillUnmount=function(){this.t=[];},L.prototype.render=function(n,t){if(this.__b){if(this.__v.__k){var e=document.createElement("div"),r=this.__v.__k[0].__c;this.__v.__k[0]=function n(t,e,r){return t&&(t.__c&&t.__c.__H&&(t.__c.__H.__.forEach(function(n){"function"==typeof n.__c&&n.__c();}),t.__c.__H=null),null!=(t=S({},t)).__c&&(t.__c.__P===r&&(t.__c.__P=e),t.__c=null),t.__k=t.__k&&t.__k.map(function(t){return n(t,e,r)})),t}(this.__b,e,r.__O=r.__P);}this.__b=null;}var u=t.__e&&React.createElement(React.Fragment,null,n.fallback);return u&&(u.__h=null),[React.createElement(React.Fragment,null,t.__e?null:n.children),u]};var T$1=function(n,t,e){if(++e[1]===e[0]&&n.o.delete(t),n.props.revealOrder&&("t"!==n.props.revealOrder[0]||!n.o.size))for(e=n.u;e;){for(;e.length>3;)e.pop()();if(e[1]<e[0])break;n.u=e=e[2];}};function D(n){return this.getChildContext=function(){return n.context},n.children}function I(n){var t=this,e=n.i;t.componentWillUnmount=function(){React.render(null,t.l),t.l=null,t.i=null;},t.i&&t.i!==e&&t.componentWillUnmount(),n.__v?(t.l||(t.i=e,t.l={nodeType:1,parentNode:e,childNodes:[],appendChild:function(n){this.childNodes.push(n),t.i.appendChild(n);},insertBefore:function(n,e){this.childNodes.push(n),t.i.appendChild(n);},removeChild:function(n){this.childNodes.splice(this.childNodes.indexOf(n)>>>1,1),t.i.removeChild(n);}}),React.render(React.createElement(D,{context:t.context},n.__v),t.l)):t.l&&t.componentWillUnmount();}function W(n,t){return React.createElement(I,{__v:n,i:t})}(M.prototype=new React.Component).__e=function(n){var t=this,e=U(t.__v),r=t.o.get(n);return r[0]++,function(u){var o=function(){t.props.revealOrder?(r.push(u),T$1(t,n,r)):u();};e?e(o):o();}},M.prototype.render=function(n){this.u=null,this.o=new Map;var t=React.toChildArray(n.children);n.revealOrder&&"b"===n.revealOrder[0]&&t.reverse();for(var e=t.length;e--;)this.o.set(t[e],this.u=[1,0,this.u]);return n.children},M.prototype.componentDidUpdate=M.prototype.componentDidMount=function(){var n=this;this.o.forEach(function(t,e){T$1(n,e,t);});};var j$1="undefined"!=typeof Symbol&&Symbol.for&&Symbol.for("react.element")||60103,P=/^(?:accent|alignment|arabic|baseline|cap|clip(?!PathU)|color|dominant|fill|flood|font|glyph(?!R)|horiz|marker(?!H|W|U)|overline|paint|stop|strikethrough|stroke|text(?!L)|underline|unicode|units|v|vector|vert|word|writing|x(?!C))[A-Z]/,V="undefined"!=typeof document,z=function(n){return ("undefined"!=typeof Symbol&&"symbol"==typeof Symbol()?/fil|che|rad/i:/fil|che|ra/i).test(n)};function B(n,t,e){return null==t.__k&&(t.textContent=""),React.render(n,t),"function"==typeof e&&e(),n?n.__c:null}function $(n,t,e){return React.hydrate(n,t),"function"==typeof e&&e(),n?n.__c:null}React.Component.prototype.isReactComponent={},["componentWillMount","componentWillReceiveProps","componentWillUpdate"].forEach(function(n){Object.defineProperty(React.Component.prototype,n,{configurable:!0,get:function(){return this["UNSAFE_"+n]},set:function(t){Object.defineProperty(this,n,{configurable:!0,writable:!0,value:t});}});});var H=React.options.event;function Z(){}function Y(){return this.cancelBubble}function q(){return this.defaultPrevented}React.options.event=function(n){return H&&(n=H(n)),n.persist=Z,n.isPropagationStopped=Y,n.isDefaultPrevented=q,n.nativeEvent=n};var G,J={configurable:!0,get:function(){return this.class}},K=React.options.vnode;React.options.vnode=function(n){var t=n.type,e=n.props,r=e;if("string"==typeof t){var u=-1===t.indexOf("-");for(var o in r={},e){var i=e[o];V&&"children"===o&&"noscript"===t||"value"===o&&"defaultValue"in e&&null==i||("defaultValue"===o&&"value"in e&&null==e.value?o="value":"download"===o&&!0===i?i="":/ondoubleclick/i.test(o)?o="ondblclick":/^onchange(textarea|input)/i.test(o+t)&&!z(e.type)?o="oninput":/^onfocus$/i.test(o)?o="onfocusin":/^onblur$/i.test(o)?o="onfocusout":/^on(Ani|Tra|Tou|BeforeInp)/.test(o)?o=o.toLowerCase():u&&P.test(o)?o=o.replace(/[A-Z0-9]/,"-$&").toLowerCase():null===i&&(i=void 0),r[o]=i);}"select"==t&&r.multiple&&Array.isArray(r.value)&&(r.value=React.toChildArray(e.children).forEach(function(n){n.props.selected=-1!=r.value.indexOf(n.props.value);})),"select"==t&&null!=r.defaultValue&&(r.value=React.toChildArray(e.children).forEach(function(n){n.props.selected=r.multiple?-1!=r.defaultValue.indexOf(n.props.value):r.defaultValue==n.props.value;})),n.props=r,e.class!=e.className&&(J.enumerable="className"in e,null!=e.className&&(r.class=e.className),Object.defineProperty(r,"className",J));}n.$$typeof=j$1,K&&K(n);};var Q=React.options.__r;React.options.__r=function(n){Q&&Q(n),G=n.__c;};var X={ReactCurrentDispatcher:{current:{readContext:function(n){return G.__n[n.__c].props.value}}}};function tn(n){return React.createElement.bind(null,n)}function en(n){return !!n&&n.$$typeof===j$1}function rn(n){return en(n)?React.cloneElement.apply(null,arguments):n}function un(n){return !!n.__k&&(React.render(null,n),!0)}function on(n){return n&&(n.base||1===n.nodeType&&n)||null}var ln=function(n,t){return n(t)},cn=function(n,t){return n(t)};var React__default = {useState:l,useReducer:p,useEffect:y,useLayoutEffect:h,useRef:s,useImperativeHandle:_,useMemo:d,useCallback:A,useContext:F,useDebugValue:T,version:"17.0.2",Children:k$1,render:B,hydrate:$,unmountComponentAtNode:un,createPortal:W,createElement:React.createElement,createContext:React.createContext,createFactory:tn,cloneElement:rn,createRef:React.createRef,Fragment:React.Fragment,isValidElement:en,findDOMNode:on,Component:React.Component,PureComponent:E,memo:g$1,forwardRef:x$1,flushSync:cn,unstable_batchedUpdates:ln,StrictMode:React.Fragment,Suspense:L,SuspenseList:M,lazy:F$1,__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED:X}; /* Copyright (c) NAVER Corp. name: @egjs/component license: MIT author: NAVER Corp. repository: https://github.com/naver/egjs-component version: 3.0.4 */ /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ function __values(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); } function __read(o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; } function __spread() { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; } /* * Copyright (c) 2015 NAVER Corp. * egjs projects are licensed under the MIT license */ var isUndefined = function (value) { return typeof value === "undefined"; }; // This class name is not matched to file name intentionally /** * Event class to provide additional properties * @ko Component에서 추가적인 프로퍼티를 제공하는 이벤트 클래스 */ var ComponentEvent = /*#__PURE__*/function () { /** * Create a new instance of ComponentEvent. * @ko ComponentEvent의 새로운 인스턴스를 생성한다. * @param eventType The name of the event.<ko>이벤트 이름.</ko> * @param props An object that contains additional event properties.<ko>추가적인 이벤트 프로퍼티 오브젝트.</ko> */ function ComponentEvent(eventType, props) { var e_1, _a; this._canceled = false; if (props) { try { for (var _b = __values(Object.keys(props)), _c = _b.next(); !_c.done; _c = _b.next()) { var key = _c.value; // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment this[key] = props[key]; } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } finally { if (e_1) throw e_1.error; } } } this.eventType = eventType; } /** * Stop the event. {@link ComponentEvent#isCanceled} will return `true` after. * @ko 이벤트를 중단한다. 이후 {@link ComponentEvent#isCanceled}가 `true`를 반환한다. */ var __proto = ComponentEvent.prototype; __proto.stop = function () { this._canceled = true; }; /** * Returns a boolean value that indicates whether {@link ComponentEvent#stop} is called before. * @ko {@link ComponentEvent#stop}이 호출되었는지 여부를 반환한다. * @return {boolean} A boolean value that indicates whether {@link ComponentEvent#stop} is called before.<ko>이전에 {@link ComponentEvent#stop}이 불려졌는지 여부를 반환한다.</ko> */ __proto.isCanceled = function () { return this._canceled; }; return ComponentEvent; }(); /** * A class used to manage events in a component * @ko 컴포넌트의 이벤트을 관리할 수 있게 하는 클래스 */ var Component = /*#__PURE__*/function () { /** * @support {"ie": "7+", "ch" : "latest", "ff" : "latest", "sf" : "latest", "edge" : "latest", "ios" : "7+", "an" : "2.1+ (except 3.x)"} */ function Component() { this._eventHandler = {}; } /** * Trigger a custom event. * @ko 커스텀 이벤트를 발생시킨다 * @param {string | ComponentEvent} event The name of the custom event to be triggered or an instance of the ComponentEvent<ko>발생할 커스텀 이벤트의 이름 또는 ComponentEvent의 인스턴스</ko> * @param {any[]} params Event data to be sent when triggering a custom event <ko>커스텀 이벤트가 발생할 때 전달할 데이터</ko> * @return An instance of the component itself<ko>컴포넌트 자신의 인스턴스</ko> * @example * ```ts * import Component, { ComponentEvent } from "@egjs/component"; * * class Some extends Component<{ * beforeHi: ComponentEvent<{ foo: number; bar: string }>; * hi: { foo: { a: number; b: boolean } }; * someEvent: (foo: number, bar: string) => void; * someOtherEvent: void; // When there's no event argument * }> { * some(){ * if(this.trigger("beforeHi")){ // When event call to stop return false. * this.trigger("hi");// fire hi event. * } * } * } * * const some = new Some(); * some.on("beforeHi", e => { * if(condition){ * e.stop(); // When event call to stop, `hi` event not call. * } * // `currentTarget` is component instance. * console.log(some === e.currentTarget); // true * * typeof e.foo; // number * typeof e.bar; // string * }); * some.on("hi", e => { * typeof e.foo.b; // boolean * }); * // If you want to more know event design. You can see article. * // https://github.com/naver/egjs-component/wiki/How-to-make-Component-event-design%3F * ``` */ var __proto = Component.prototype; __proto.trigger = function (event) { var params = []; for (var _i = 1; _i < arguments.length; _i++) { params[_i - 1] = arguments[_i]; } var eventName = event instanceof ComponentEvent ? event.eventType : event; var handlers = __spread(this._eventHandler[eventName] || []); if (handlers.length <= 0) { return this; } if (event instanceof ComponentEvent) { event.currentTarget = this; handlers.forEach(function (handler) { handler(event); }); } else { handlers.forEach(function (handler) { // eslint-disable-next-line @typescript-eslint/no-unsafe-call handler.apply(void 0, __spread(params)); }); } return this; }; /** * Executed event just one time. * @ko 이벤트가 한번만 실행된다. * @param {string} eventName The name of the event to be attached or an event name - event handler mapped object.<ko>등록할 이벤트의 이름 또는 이벤트 이름-핸들러 오브젝트</ko> * @param {function} handlerToAttach The handler function of the event to be attached <ko>등록할 이벤트의 핸들러 함수</ko> * @return An instance of the component itself<ko>컴포넌트 자신의 인스턴스</ko> * @example * ```ts * import Component, { ComponentEvent } from "@egjs/component"; * * class Some extends Component<{ * hi: ComponentEvent; * }> { * hi() { * alert("hi"); * } * thing() { * this.once("hi", this.hi); * } * } * * var some = new Some(); * some.thing(); * some.trigger(new ComponentEvent("hi")); * // fire alert("hi"); * some.trigger(new ComponentEvent("hi")); * // Nothing happens * ``` */ __proto.once = function (eventName, handlerToAttach) { var _this = this; if (typeof eventName === "object" && isUndefined(handlerToAttach)) { var eventHash = eventName; for (var key in eventHash) { this.once(key, eventHash[key]); } return this; } else if (typeof eventName === "string" && typeof handlerToAttach === "function") { var listener_1 = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } // eslint-disable-next-line @typescript-eslint/no-unsafe-call handlerToAttach.apply(void 0, __spread(args)); _this.off(eventName, listener_1); }; this.on(eventName, listener_1); } return this; }; /** * Checks whether an event has been attached to a component. * @ko 컴포넌트에 이벤트가 등록됐는지 확인한다. * @param {string} eventName The name of the event to be attached <ko>등록 여부를 확인할 이벤트의 이름</ko> * @return {boolean} Indicates whether the event is attached. <ko>이벤트 등록 여부</ko> * @example * ```ts * import Component from "@egjs/component"; * * class Some extends Component<{ * hi: void; * }> { * some() { * this.hasOn("hi");// check hi event. * } * } * ``` */ __proto.hasOn = function (eventName) { return !!this._eventHandler[eventName]; }; /** * Attaches an event to a component. * @ko 컴포넌트에 이벤트를 등록한다. * @param {string} eventName The name of the event to be attached or an event name - event handler mapped object.<ko>등록할 이벤트의 이름 또는 이벤트 이름-핸들러 오브젝트</ko> * @param {function} handlerToAttach The handler function of the event to be attached <ko>등록할 이벤트의 핸들러 함수</ko> * @return An instance of a component itself<ko>컴포넌트 자신의 인스턴스</ko> * @example * ```ts * import Component, { ComponentEvent } from "@egjs/component"; * * class Some extends Component<{ * hi: void; * }> { * hi() { * console.log("hi"); * } * some() { * this.on("hi",this.hi); //attach event * } * } * ``` */ __proto.on = function (eventName, handlerToAttach) { if (typeof eventName === "object" && isUndefined(handlerToAttach)) { var eventHash = eventName; for (var name in eventHash) { this.on(name, eventHash[name]); } return this; } else if (typeof eventName === "string" && typeof handlerToAttach === "function") { var handlerList = this._eventHandler[eventName]; if (isUndefined(handlerList)) { this._eventHandler[eventName] = []; handlerList = this._eventHandler[eventName]; } handlerList.push(handlerToAttach); } return this; }; /** * Detaches an event from the component.<br/>If the `eventName` is not given this will detach all event handlers attached.<br/>If the `handlerToDetach` is not given, this will detach all event handlers for `eventName`. * @ko 컴포넌트에 등록된 이벤트를 해제한다.<br/>`eventName`이 주어지지 않았을 경우 모든 이벤트 핸들러를 제거한다.<br/>`handlerToAttach`가 주어지지 않았을 경우 `eventName`에 해당하는 모든 이벤트 핸들러를 제거한다. * @param {string?} eventName The name of the event to be detached <ko>해제할 이벤트의 이름</ko> * @param {function?} handlerToDetach The handler function of the event to be detached <ko>해제할 이벤트의 핸들러 함수</ko> * @return An instance of a component itself <ko>컴포넌트 자신의 인스턴스</ko> * @example * ```ts * import Component, { ComponentEvent } from "@egjs/component"; * * class Some extends Component<{ * hi: void; * }> { * hi() { * console.log("hi"); * } * some() { * this.off("hi",this.hi); //detach event * } * } * ``` */ __proto.off = function (eventName, handlerToDetach) { var e_1, _a; // Detach all event handlers. if (isUndefined(eventName)) { this._eventHandler = {}; return this; } // Detach all handlers for eventname or detach event handlers by object. if (isUndefined(handlerToDetach)) { if (typeof eventName === "string") { delete this._eventHandler[eventName]; return this; } else { var eventHash = eventName; for (var name in eventHash) { this.off(name, eventHash[name]); } return this; } } // Detach single event handler var handlerList = this._eventHandler[eventName]; if (handlerList) { var idx = 0; try { for (var handlerList_1 = __values(handlerList), handlerList_1_1 = handlerList_1.next(); !handlerList_1_1.done; handlerList_1_1 = handlerList_1.next()) { var handlerFunction = handlerList_1_1.value; if (handlerFunction === handlerToDetach) { handlerList.splice(idx, 1); if (handlerList.length <= 0) { delete this._eventHandler[eventName]; } break; } idx++; } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (handlerList_1_1 && !handlerList_1_1.done && (_a = handlerList_1.return)) _a.call(handlerList_1); } finally { if (e_1) throw e_1.error; } } } return this; }; /** * Version info string * @ko 버전정보 문자열 * @name VERSION * @static * @example * Component.VERSION; // ex) 3.0.0 * @memberof Component */ Component.VERSION = "3.0.4"; return Component; }(); /* * Copyright (c) 2015 NAVER Corp. * egjs projects are licensed under the MIT license */ // eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-unsafe-assignment var ComponentEvent$1 = ComponentEvent; /* Copyright (c) 2019-present NAVER Corp. name: @egjs/list-differ license: MIT author: NAVER Corp. repository: https://github.com/naver/egjs-list-differ version: 1.0.1 */ /* egjs-list-differ Copyright (c) 2019-present NAVER Corp. MIT license */ var PolyMap = /*#__PURE__*/ function () { function PolyMap() { this.keys = []; this.values = []; } var __proto = PolyMap.prototype; __proto.get = function (key) { return this.values[this.keys.indexOf(key)]; }; __proto.set = function (key, value) { var keys = this.keys; var values = this.values; var prevIndex = keys.indexOf(key); var index = prevIndex === -1 ? keys.length : prevIndex; keys[index] = key; values[index] = value; }; return PolyMap; }(); /* egjs-list-differ Copyright (c) 2019-present NAVER Corp. MIT license */ var HashMap = /*#__PURE__*/ function () { function HashMap() { this.object = {}; } var __proto = HashMap.prototype; __proto.get = function (key) { return this.object[key]; }; __proto.set = function (key, value) { this.object[key] = value; }; return HashMap; }(); /* egjs-list-differ Copyright (c) 2019-present NAVER Corp. MIT license */ var SUPPORT_MAP = typeof Map === "function"; /* egjs-list-differ Copyright (c) 2019-present NAVER Corp. MIT license */ var Link = /*#__PURE__*/ function () { function Link() {} var __proto = Link.prototype; __proto.connect = function (prevLink, nextLink) { this.prev = prevLink; this.next = nextLink; prevLink && (prevLink.next = this); nextLink && (nextLink.prev = this); }; __proto.disconnect = function () { // In double linked list, diconnect the interconnected relationship. var prevLink = this.prev; var nextLink = this.next; prevLink && (prevLink.next = nextLink); nextLink && (nextLink.prev = prevLink); }; __proto.getIndex = function () { var link = this; var index = -1; while (link) { link = link.prev; ++index; } return index; }; return Link; }(); /* egjs-list-differ Copyright (c) 2019-present NAVER Corp. MIT license */ function orderChanged(changed, fixed) { // It is roughly in the order of these examples. // 4, 6, 0, 2, 1, 3, 5, 7 var fromLinks = []; // 0, 1, 2, 3, 4, 5, 6, 7 var toLinks = []; changed.forEach(function (_a) { var from = _a[0], to = _a[1]; var link = new Link(); fromLinks[from] = link; toLinks[to] = link; }); // `fromLinks` are connected to each other by double linked list. fromLinks.forEach(function (link, i) { link.connect(fromLinks[i - 1]); }); return changed.filter(function (_, i) { return !fixed[i]; }).map(function (_a, i) { var from = _a[0], to = _a[1]; if (from === to) { return [0, 0]; } var fromLink = fromLinks[from]; var toLink = toLinks[to - 1]; var fromIndex = fromLink.getIndex(); // Disconnect the link connected to `fromLink`. fromLink.disconnect(); // Connect `fromLink` to the right of `toLink`. if (!toLink) { fromLink.connect(undefined, fromLinks[0]); } else { fromLink.connect(toLink, toLink.next); } var toIndex = fromLink.getIndex(); return [fromIndex, toIndex]; }); } var Result = /*#__PURE__*/ function () { function Result(prevList, list, added, removed, changed, maintained, changedBeforeAdded, fixed) { this.prevList = prevList; this.list = list; this.added = added; this.removed = removed; this.changed = changed; this.maintained = maintained; this.changedBeforeAdded = changedBeforeAdded; this.fixed = fixed; } var __proto = Result.prototype; Object.defineProperty(__proto, "ordered", { get: function () { if (!this.cacheOrdered) { this.caculateOrdered(); } return this.cacheOrdered; }, enumerable: true, configurable: true }); Object.defineProperty(__proto, "pureChanged", { get: function () { if (!this.cachePureChanged) { this.caculateOrdered(); } return this.cachePureChanged; }, enumerable: true, configurable: true }); __proto.caculateOrdered = function () { var ordered = orderChanged(this.changedBeforeAdded, this.fixed); var changed = this.changed; var pureChanged = []; this.cacheOrdered = ordered.filter(function (_a, i) { var from = _a[0], to = _a[1]; var _b = changed[i], fromBefore = _b[0], toBefore = _b[1]; if (from !== to) { pureChanged.push([fromBefore, toBefore]); return true; } }); this.cachePureChanged = pureChanged; }; return Result; }(); /** * * @memberof eg.ListDiffer * @static * @function * @param - Previous List <ko> 이전 목록 </ko> * @param - List to Update <ko> 업데이트 할 목록 </ko> * @param - This callback function returns the key of the item. <ko> 아이템의 키를 반환하는 콜백 함수입니다.</ko> * @return - Returns the diff between `prevList` and `list` <ko> `prevList`와 `list`의 다른 점을 반환한다.</ko> * @example * import { diff } from "@egjs/list-differ"; * // script => eg.ListDiffer.diff * const result = diff([0, 1, 2, 3, 4, 5], [7, 8, 0, 4, 3, 6, 2, 1], e => e); * // List before update * // [1, 2, 3, 4, 5] * console.log(result.prevList); * // Updated list * // [4, 3, 6, 2, 1] * console.log(result.list); * // Index array of values added to `list` * // [0, 1, 5] * console.log(result.added); * // Index array of values removed in `prevList` * // [5] * console.log(result.removed); * // An array of index pairs of `prevList` and `list` with different indexes from `prevList` and `list` * // [[0, 2], [4, 3], [3, 4], [2, 6], [1, 7]] * console.log(result.changed); * // The subset of `changed` and an array of index pairs that moved data directly. Indicate an array of absolute index pairs of `ordered`.(Formatted by: Array<[index of prevList, index of list]>) * // [[4, 3], [3, 4], [2, 6]] * console.log(result.pureChanged); * // An array of index pairs to be `ordered` that can synchronize `list` before adding data. (Formatted by: Array<[prevIndex, nextIndex]>) * // [[4, 1], [4, 2], [4, 3]] * console.log(result.ordered); * // An array of index pairs of `prevList` and `list` that have not been added/removed so data is preserved * // [[0, 2], [4, 3], [3, 4], [2, 6], [1, 7]] * console.log(result.maintained); */ function diff(prevList, list, findKeyCallback) { var mapClass = SUPPORT_MAP ? Map : findKeyCallback ? HashMap : PolyMap; var callback = findKeyCallback || function (e) { return e; }; var added = []; var removed = []; var maintained = []; var prevKeys = prevList.map(callback); var keys = list.map(callback); var prevKeyMap = new mapClass(); var keyMap = new mapClass(); var changedBeforeAdded = []; var fixed = []; var removedMap = {}; var changed = []; var addedCount = 0; var removedCount = 0; // Add prevKeys and keys to the hashmap. prevKeys.forEach(function (key, prevListIndex) { prevKeyMap.set(key, prevListIndex); }); keys.forEach(function (key, listIndex) { keyMap.set(key, listIndex); }); // Compare `prevKeys` and `keys` and add them to `removed` if they are not in `keys`. prevKeys.forEach(function (key, prevListIndex) { var listIndex = keyMap.get(key); // In prevList, but not in list, it is removed. if (typeof listIndex === "undefined") { ++removedCount; removed.push(prevListIndex); } else { removedMap[listIndex] = removedCount; } }); // Compare `prevKeys` and `keys` and add them to `added` if they are not in `prevKeys`. keys.forEach(function (key, listIndex) { var prevListIndex = prevKeyMap.get(key); // In list, but not in prevList, it is added. if (typeof prevListIndex === "undefined") { added.push(listIndex); ++addedCount; } else { maintained.push([prevListIndex, listIndex]); removedCount = removedMap[listIndex] || 0; changedBeforeAdded.push([prevListIndex - removedCount, listIndex - addedCount]); fixed.push(listIndex === prevListIndex); if (prevListIndex !== listIndex) { changed.push([prevListIndex, listIndex]); } } }); // Sort by ascending order of 'to(list's index). removed.reverse(); return new Result(prevList, list, added, removed, changed, maintained, changedBeforeAdded, fixed); } /** * A module that checks diff when values are added, removed, or changed in an array. * @ko 배열 또는 오브젝트에서 값이 추가되거나 삭제되거나 순서가 변경사항을 체크하는 모듈입니다. * @memberof eg */ var ListDiffer = /*#__PURE__*/ function () { /** * @param - Initializing Data Array. <ko> 초기 설정할 데이터 배열.</ko> * @param - This callback function returns the key of the item. <ko> 아이템의 키를 반환하는 콜백 함수입니다.</ko> * @example * import ListDiffer from "@egjs/list-differ"; * // script => eg.ListDiffer * const differ = new ListDiffer([0, 1, 2, 3, 4, 5], e => e); * const result = differ.update([7, 8, 0, 4, 3, 6, 2, 1]); * // List before update * // [1, 2, 3, 4, 5] * console.log(result.prevList); * // Updated list * // [4, 3, 6, 2, 1] * console.log(result.list); * // Index array of values added to `list`. * // [0, 1, 5] * console.log(result.added); * // Index array of values removed in `prevList`. * // [5] * console.log(result.removed); * // An array of index pairs of `prevList` and `list` with different indexes from `prevList` and `list`. * // [[0, 2], [4, 3], [3, 4], [2, 6], [1, 7]] * console.log(result.changed); * // The subset of `changed` and an array of index pairs that moved data directly. Indicate an array of absolute index pairs of `ordered`.(Formatted by: Array<[index of prevList, index of list]>) * // [[4, 3], [3, 4], [2, 6]] * console.log(result.pureChanged); * // An array of index pairs to be `ordered` that can synchronize `list` before adding data. (Formatted by: Array<[prevIndex, nextIndex]>) * // [[4, 1], [4, 2], [4, 3]] * console.log(result.ordered); * // An array of index pairs of `prevList` and `list` that have not been added/removed so data is preserved. * // [[0, 2], [4, 3], [3, 4], [2, 6], [1, 7]] * console.log(result.maintained); */ function ListDiffer(list, findKeyCallback) { if (list === void 0) { list = []; } this.findKeyCallback = findKeyCallback; this.list = [].slice.call(list); } /** * Update list. * @ko 리스트를 업데이트를 합니다. * @param - List to update <ko> 업데이트할 리스트 </ko> * @return - Returns the results of an update from `prevList` to `list`.<ko> `prevList`에서 `list`로 업데이트한 결과를 반환한다. </ko> */ var __proto = ListDiffer.prototype; __proto.update = function (list) { var newData = [].slice.call(list); var result = diff(this.list, newData, this.findKeyCallback); this.list = newData; return result; }; return ListDiffer; }(); /* Copyright (c) 2015 NAVER Corp. name: @egjs/agent license: MIT author: NAVER Corp. repository: git+https://github.com/naver/agent.git version: 2.4.3 */ function some(arr, callback) { var length = arr.length; for (var i = 0; i < length; ++i) { if (callback(arr[i], i)) { return true; } } return false; } function find(arr, callback) { var length = arr.length; for (var i = 0; i < length; ++i) { if (callback(arr[i], i)) { return arr[i]; } } return null; } function getUserAgentString(agent) { var userAgent = agent; if (typeof userAgent === "undefined") { if (typeof navigator === "undefined" || !navigator) { return ""; } userAgent = navigator.userAgent || ""; } return userAgent.toLowerCase(); } function execRegExp(pattern, text) { try { return new RegExp(pattern, "g").exec(text); } catch (e) { return null; } } function hasUserAgentData() { if (typeof navigator === "undefined" || !navigator || !navigator.userAgentData) { return false; } var userAgentData = navigator.userAgentData; var brands = userAgentData.brands || userAgentData.uaList; return !!(brands && brands.length); } function findVersion(versionTest, userAgent) { var result = execRegExp("(" + versionTest + ")((?:\\/|\\s|:)([0-9|\\.|_]+))", userAgent); return result ? result[3] : ""; } function convertVersion(text) { return text.replace(/_/g, "."); } function findPreset(presets, userAgent) { var userPreset = null; var version = "-1"; some(presets, function (preset) { var result = execRegExp("(" + preset.test + ")((?:\\/|\\s|:)([0-9|\\.|_]+))?", userAgent); if (!result || preset.brand) { return false; } userPreset = preset; version = result[3] || "-1"; if (preset.versionAlias) { version = preset.versionAlias; } else if (preset.versionTest) { version = findVersion(preset.versionTest.toLowerCase(), userAgent) || version; } version = convertVersion(version); return true; }); return { preset: userPreset, version: version }; } function findPresetBrand(presets, brands) { var brandInfo = { brand: "", version: "-1" }; some(presets, function (preset) { var result = findBrand(brands, preset); if (!result) { return false; } brandInfo.brand = preset.id; brandInfo.version = preset.versionAlias || result.version; return brandInfo.version !== "-1"; }); return brandInfo; } function findBrand(brands, preset) { return find(brands, function (_a) { var brand = _a.brand; return execRegExp("" + preset.test, brand.toLowerCase()); }); } var BROWSER_PRESETS = [{ test: "phantomjs", id: "phantomjs" }, { test: "whale", id: "whale" }, { test: "edgios|edge|edg", id: "edge" }, { test: "msie|trident|windows phone", id: "ie", versionTest: "iemobile|msie|rv" }, { test: "miuibrowser", id: "miui browser" }, { test: "samsungbrowser", id: "samsung internet" }, { test: "samsung", id: "samsung internet", versionTest: "version" }, { test: "chrome|crios", id: "chrome" }, { test: "firefox|fxios", id: "firefox" }, { test: "android", id: "android browser", versionTest: "version" }, { test: "safari|iphone|ipad|ipod", id: "safari", versionTest: "version" }]; // chromium's engine(blink) is based on applewebkit 537.36. var CHROMIUM_PRESETS = [{ test: "(?=.*applewebkit/(53[0-7]|5[0-2]|[0-4]))(?=.*\\schrome)", id: "chrome", versionTest: "chrome" }, { test: "chromium", id: "chrome" }, { test: "whale", id: "chrome", versionAlias: "-1", brand: true }]; var WEBKIT_PRESETS = [{ test: "applewebkit", id: "webkit", versionTest: "applewebkit|safari" }]; var WEBVIEW_PRESETS = [{ test: "(?=(iphone|ipad))(?!(.*version))", id: "webview" }, { test: "(?=(android|iphone|ipad))(?=.*(naver|daum|; wv))", id: "webview" }, { // test webview test: "webview", id: "webview" }]; var OS_PRESETS = [{ test: "windows phone", id: "windows phone" }, { test: "windows 2000", id: "window", versionAlias: "5.0" }, { test: "windows nt", id: "window" }, { test: "win32|windows", id: "window" }, { test: "iphone|ipad|ipod", id: "ios", versionTest: "iphone os|cpu os" }, { test: "macos|macintel|mac os x", id: "mac" }, { test: "android|linux armv81", id: "android" }, { test: "tizen", id: "tizen" }, { test: "webos|web0s", id: "webos" }]; function isWebView(userAgent) { return !!findPreset(WEBVIEW_PRESETS, userAgent).preset; } function getLegacyAgent(userAgent) { var nextAgent = getUserAgentString(userAgent); var isMobile = !!/mobi/g.exec(nextAgent); var browser = { name: "unknown", version: "-1", majorVersion: -1, webview: isWebView(nextAgent), chromium: false, chromiumVersion: "-1", webkit: false, webkitVersion: "-1" }; var os = { name: "unknown", version: "-1", majorVersion: -1 }; var _a = findPreset(BROWSER_PRESETS, nextAgent), browserPreset = _a.preset, browserVersion = _a.version; var _b = findPreset(OS_PRESETS, nextAgent), osPreset = _b.preset, osVersion = _b.version; var chromiumPreset = findPreset(CHROMIUM_PRESETS, nextAgent); browser.chromium = !!chromiumPreset.preset; browser.chromiumVersion = chromiumPreset.version; if (!browser.chromium) { var webkitPreset = findPreset(WEBKIT_PRESETS, nextAgent); browser.webkit = !!webkitPreset.preset; browser.webkitVersion = webkitPreset.version; } if (osPreset) { os.name = osPreset.id; os.version = osVersion; os.majorVersion = parseInt(osVersion, 10); } if (browserPreset) { browser.name = browserPreset.id; browser.version = browserVersion; // Early whale bugs if (browser.webview && os.name === "ios" && browser.name !== "safari") { browser.webview = false; } } browser.majorVersion = parseInt(browser.version, 10); return { browser: browser, os: os, isMobile: isMobile, isHints: false }; } function getClientHintsAgent(osData) { var userAgentData = navigator.userAgentData; var brands = (userAgentData.uaList || userAgentData.brands).slice(); var fullVersionList = osData && osData.fullVersionList; var isMobile = userAgentData.mobile || false; var firstBrand = brands[0]; var platform = (osData && osData.platform || userAgentData.platform || navigator.platform).toLowerCase(); var browser = { name: firstBrand.brand, version: firstBrand.version, majorVersion: -1, webkit: false, webkitVersion: "-1", chromium: false, chromiumVersion: "-1", webview: !!findPresetBrand(WEBVIEW_PRESETS, brands).brand || isWebView(getUserAgentString()) }; var os = { name: "unknown", version: "-1", majorVersion: -1 }; browser.webkit = !browser.chromium && some(WEBKIT_PRESETS, function (preset) { return findBrand(brands, preset); }); var chromiumBrand = findPresetBrand(CHROMIUM_PRESETS, brands); browser.chromium = !!chromiumBrand.brand; browser.chromiumVersion = chromiumBrand.version; if (!browser.chromium) { var webkitBrand = findPresetBrand(WEBKIT_PRESETS, brands); browser.webkit = !!webkitBrand.brand; browser.webkitVersion = webkitBrand.version; } var platfomResult = find(OS_PRESETS, function (preset) { return new RegExp("" + preset.test, "g").exec(platform); }); os.name = platfomResult ? platfomResult.id : ""; if (osData) { os.version = osData.platformVersion; } if (fullVersionList && fullVersionList.length) { var browserBrandByFullVersionList = findPresetBrand(BROWSER_PRESETS, fullVersionList); browser.name = browserBrandByFullVersionList.brand || browser.name; browser.version = browserBrandByFullVersionList.version || browser.version; } else { var browserBrand = findPresetBrand(BROWSER_PRESETS, brands); browser.name = browserBrand.brand || browser.name; browser.version = browserBrand.brand && osData ? osData.uaFullVersion : browserBrand.version; } if (browser.webkit) { os.name = isMobile ? "ios" : "mac"; } if (os.name === "ios" && browser.webview) { browser.version = "-1"; } os.version = convertVersion(os.version); browser.version = convertVersion(browser.version); os.majorVersion = parseInt(os.version, 10); browser.majorVersion = parseInt(browser.version, 10); return { browser: browser, os: os, isMobile: isMobile, isHints: true }; } /** * Extracts browser and operating system information from the user agent string. * @ko 유저 에이전트 문자열에서 브라우저와 운영체제 정보를 추출한다. * @function eg.agent#agent * @param - user agent string to parse <ko>파싱할 유저에이전트 문자열</ko> * @return - agent Info <ko> 에이전트 정보 </ko> * @example import agent from "@egjs/agent"; // eg.agent(); const { os, browser, isMobile } = agent(); */ function agent(userAgent) { if (typeof userAgent === "undefined" && hasUserAgentData()) { return getClientHintsAgent(); } else { return getLegacyAgent(userAgent); } } /* Copyright (c) 2022-present NAVER Corp. name: @cfcs/core license: MIT author: NAVER Crop. repository: https://github.com/naver/cfcs/tree/main/packages/core version: 0.1.0 */ /** * cfcs * Copyright (c) 2022-present NAVER Corp. * MIT license */ /** * @hidden */ function keys(obj) { return Object.keys(obj); } /** * cfcs * Copyright (c) 2022-present NAVER Corp. * MIT license */ var OBSERVERS_PATH = "__observers__"; var COMPUTED_PATH = "__computed__"; var CFCS_DETECTED_DEPENDENCIES_VERSION = 1; var CFCS_DETECTED_DEPENDENCIES = "__CFCS_DETECTED_DEPENDENCIES__"; /****************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; } || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } /** * cfcs * Copyright (c) 2022-present NAVER Corp. * MIT license */ function getDetectedStack() { // Version issues do not occur when you access the native object in the global. Object[CFCS_DETECTED_DEPENDENCIES] = Object[CFCS_DETECTED_DEPENDENCIES] || {}; var versionList = Object[CFCS_DETECTED_DEPENDENCIES]; versionList[CFCS_DETECTED_DEPENDENCIES_VERSION] = versionList[CFCS_DETECTED_DEPENDENCIES_VERSION] || []; return versionList[CFCS_DETECTED_DEPENDENCIES_VERSION]; } function getCurrentDetected() { var stack = getDetectedStack(); return stack[stack.length - 1]; } function detectDependencies(host) { var stack = getDetectedStack(); var observers = []; var detected = { host: host, observers: observers, push: function (observer) { if (host !== observer && observers.indexOf(observer) === -1) { observers.push(observer); } } }; stack.push(detected); return detected; } function endDetectDependencies() { var stack = getDetectedStack(); return stack.pop(); } /** * cfcs * Copyright (c) 2022-present NAVER Corp. * MIT license */ /** * Creates a mutable ref object. You can access the `.current` value and detect the value change through `.subscribe`. * @category Reactive * @see observe */ var Observer = /*#__PURE__*/ function () { /** * */ function Observer(value) { this._emitter = new Component(); this._current = value; } var __proto = Observer.prototype; Object.defineProperty(__proto, "current", { /** * return the current value. */ get: function () { var currentDetected = getCurrentDetected(); currentDetected === null || currentDetected === void 0 ? void 0 : currentDetected.push(this); return this._current; }, set: function (value) { this._setCurrent(value); }, enumerable: false, configurable: true }); /** * When the current value changes, the callback function is called. */ __proto.subscribe = function (callback) { this.current; this._emitter.on("update", callback); return this; }; /** * Cancel the registered subscription through callback. */ __proto.unsubscribe = function (callback) { this._emitter.off("update", callback); return this; }; __proto._setCurrent = function (value) { var prevValue = this._current; var isUpdate = value !== prevValue; this._current = value; if (isUpdate) { this._emitter.trigger("update", value, prevValue); } }; /** * @hidden */ __proto.toString = function () { return "".concat(this.current); }; /** * @hidden */ __proto.valueOf = function () { return this.current; }; return Observer; }(); /** * @category Reactive * @hidden */ var ComputedObserver = /*#__PURE__*/ function (_super) { __extends(ComputedObserver, _super); /** * @description Creates a new computed observer from the values of other observers. * It is read-only and if you change the value of the observer used inside the callback, its value will be automatically updated. * @param _computedCallback A function for observers to be computed. */ function ComputedObserver(_computedCallback) { var _this = _super.call(this) || this; _this._computedCallback = _computedCallback; _this._registered = []; _this._onCheckUpdate = function () { _this._setCurrent(_this.current); }; _this._current = _this.current; return _this; } var __pr