1/// <reference path="../../../../../../../../global.d.ts" /> 2/// <reference path="../../../../../../../../iu.d.ts" /> 3function _assert_this_initialized(self) { 4 if (self === void 0) { 5 throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); 6 } 7 return self; 8} 9function _class_call_check(instance, Constructor) { 10 if (!(instance instanceof Constructor)) { 11 throw new TypeError("Cannot call a class as a function"); 12 } 13} 14function _defineProperties(target, props) { 15 for(var i = 0; i < props.length; i++){ 16 var descriptor = props[i]; 17 descriptor.enumerable = descriptor.enumerable || false; 18 descriptor.configurable = true; 19 if ("value" in descriptor) descriptor.writable = true; 20 Object.defineProperty(target, descriptor.key, descriptor); 21 } 22} 23function _create_class(Constructor, protoProps, staticProps) { 24 if (protoProps) _defineProperties(Constructor.prototype, protoProps); 25 if (staticProps) _defineProperties(Constructor, staticProps); 26 return Constructor; 27} 28function _define_property(obj, key, value) { 29 if (key in obj) { 30 Object.defineProperty(obj, key, { 31 value: value, 32 enumerable: true, 33 configurable: true, 34 writable: true 35 }); 36 } else { 37 obj[key] = value; 38 } 39 return obj; 40} 41function _get_prototype_of(o) { 42 _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) { 43 return o.__proto__ || Object.getPrototypeOf(o); 44 }; 45 return _get_prototype_of(o); 46} 47function _inherits(subClass, superClass) { 48 if (typeof superClass !== "function" && superClass !== null) { 49 throw new TypeError("Super expression must either be null or a function"); 50 } 51 subClass.prototype = Object.create(superClass && superClass.prototype, { 52 constructor: { 53 value: subClass, 54 writable: true, 55 configurable: true 56 } 57 }); 58 if (superClass) _set_prototype_of(subClass, superClass); 59} 60function _possible_constructor_return(self, call) { 61 if (call && (_type_of(call) === "object" || typeof call === "function")) { 62 return call; 63 } 64 return _assert_this_initialized(self); 65} 66function _set_prototype_of(o, p) { 67 _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) { 68 o.__proto__ = p; 69 return o; 70 }; 71 return _set_prototype_of(o, p); 72} 73function _type_of(obj) { 74 "@swc/helpers - typeof"; 75 return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; 76} 77function _is_native_reflect_construct() { 78 if (typeof Reflect === "undefined" || !Reflect.construct) return false; 79 if (Reflect.construct.sham) return false; 80 if (typeof Proxy === "function") return true; 81 try { 82 Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {})); 83 return true; 84 } catch (e) { 85 return false; 86 } 87} 88function _create_super(Derived) { 89 var hasNativeReflectConstruct = _is_native_reflect_construct(); 90 return function _createSuperInternal() { 91 var Super = _get_prototype_of(Derived), result; 92 if (hasNativeReflectConstruct) { 93 var NewTarget = _get_prototype_of(this).constructor; 94 result = Reflect.construct(Super, arguments, NewTarget); 95 } else { 96 result = Super.apply(this, arguments); 97 } 98 return _possible_constructor_return(this, result); 99 }; 100} 101import { Controller } from "@hotwired/stimulus"; 102import { FloatingPopover } from "../../lib/floating-popover.js"; 103import { HoverTooltip } from "../../lib/hover-tooltip.js"; 104var _class = /*#__PURE__*/ function(Controller) { 105 "use strict"; 106 _inherits(_class, Controller); 107 var _super = _create_super(_class); 108 function _class() { 109 _class_call_check(this, _class); 110 var _this; 111 _this = _super.apply(this, arguments); 112 _define_property(_assert_this_initialized(_this), "popover", void 0); 113 _define_property(_assert_this_initialized(_this), "tooltip", null); 114 return _this; 115 } 116 _create_class(_class, [ 117 { 118 key: "connect", 119 value: function connect() { 120 var _this = this; 121 this.popover = new FloatingPopover({ 122 reference: this.chipTarget, 123 floating: this.popoverTarget, 124 placement: "top-start", 125 strategy: "fixed", 126 onShow: function() { 127 var _this_tooltip; 128 (_this_tooltip = _this.tooltip) === null || _this_tooltip === void 0 ? void 0 : _this_tooltip.hide(); 129 _this.chipTarget.classList.add("ai-tools-counter__chip--active"); 130 _this.dispatch("popover-opened", { 131 detail: { 132 source: _this.element 133 }, 134 prefix: "ai-tool", 135 bubbles: true 136 }); 137 }, 138 onHide: function() { 139 _this.chipTarget.classList.remove("ai-tools-counter__chip--active"); 140 } 141 }); 142 if (this.configValue.title) { 143 this.tooltip = new HoverTooltip({ 144 reference: this.chipTarget, 145 text: this.configValue.title,
146 suppressWhen: function() { 147 return _this.popover.isOpen(); 148 } 149 }); 150 } 151 this.syncDom(); 152 this.emitTokensState(); 153 } 154 }, 155 { 156 key: "disconnect", 157 value: function disconnect() { 158 var _this_tooltip; 159 this.popover.destroy(); 160 (_this_tooltip = this.tooltip) === null || _this_tooltip === void 0 ? void 0 : _this_tooltip.destroy(); 161 } 162 }, 163 { 164 key: "toggle", 165 value: function toggle(event) { 166 event.stopPropagation(); 167 this.popover.toggle(); 168 } 169 }, 170 { 171 /** Singleton: вÑзÑваеÑÑÑ Ð¸Ð· ai-tools, когда оÑкÑÑÑ popover дÑÑгого tool'а. */ key: "closePopover", 172 value: function closePopover() { 173 this.popover.hide(); 174 } 175 }, 176 { 177 key: "decrement", 178 value: function decrement() { 179 this.valueValue = this.clamp(this.valueValue - this.configValue.step); 180 } 181 }, 182 { 183 key: "increment", 184 value: function increment() { 185 this.valueValue = this.clamp(this.valueValue + this.configValue.step); 186 } 187 }, 188 { 189 key: "onInput", 190 value: function onInput() { 191 if (!this.inputTarget.validity.rangeOverflow) { 192 return; 193 } 194 this.inputTarget.value = String(this.configValue.max); 195 this.valueValue = this.configValue.max; 196 } 197 }, 198 { 199 key: "onInputBlur", 200 value: function onInputBlur() { 201 var raw = this.inputTarget.value.trim(); 202 var parsed = Number.parseInt(raw, 10); 203 if (Number.isNaN(parsed)) { 204 this.syncDom(); 205 return; 206 } 207 this.valueValue = this.clamp(parsed); 208 } 209 }, 210 { 211 key: "onInputEnter", 212 value: function onInputEnter(event) { 213 event.preventDefault(); 214 this.onInputBlur(); 215 } 216 }, 217 { 218 key: "valueValueChanged", 219 value: function valueValueChanged() { 220 this.syncDom(); 221 this.emitTokensState(); 222 } 223 }, 224 { 225 key: "emitTokensState", 226 value: function emitTokensState() { 227 var _this_configValue = this.configValue, id = _this_configValue.id, tokensPrice = _this_configValue.tokensPrice; 228 if (typeof tokensPrice !== "number" || tokensPrice <= 0) return; 229 this.dispatch("tokens-state", { 230 detail: { 231 sourceId: id, 232 kind: "counter", 233 value: this.valueValue, 234 tokensPrice: tokensPrice 235 }, 236 prefix: "ai-tool", 237 bubbles: true 238 }); 239 } 240 }, 241 { 242 key: "syncDom", 243 value: function syncDom() { 244 var value = this.valueValue; 245 var _this_configValue = this.configValue, min = _this_configValue.min, max = _this_configValue.max; 246 if (this.hasChipLabelTarget) { 247 this.chipLabelTarget.textContent = String(value); 248 } 249 if (this.hasInputTarget && this.inputTarget.value !== String(value)) { 250 this.inputTarget.value = String(value); 251 } 252 if (this.hasHiddenInputTarget) { 253 this.hiddenInputTarget.value = String(value); 254 } 255 if (this.hasDecBtnTarget) { 256 this.decBtnTarget.disabled = value <= min; 257 } 258 if (this.hasIncBtnTarget) { 259 this.incBtnTarget.disabled = value >= max; 260 } 261 } 262 }, 263 { 264 key: "clamp", 265 value: function clamp(n) { 266 var _this_configValue = this.configValue, min = _this_configValue.min, max = _this_configValue.max; 267 if (n < min) return min; 268 if (n > max) return max; 269 return n; 270 } 271 } 272 ]); 273 return _class; 274}(Controller); 275_define_property(_class, "targets", [ 276 "chip", 277 "chipLabel", 278 "popover", 279 "decBtn", 280 "incBtn", 281 "input", 282 "hiddenInput" 283]); 284_define_property(_class, "values", { 285 config: { 286 type: Object, 287 default: {} 288 }, 289 value: { 290 type: Number, 291 default: 0 292 } 293}); 294export { _class as default };
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.