wuira 0.1.10 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,16 @@
1
+ import type { CellProps } from "../ui/Cell";
2
+ import type { Element } from "../ui/primitives/jsx";
3
+ import type { Anchor } from "../types/Position";
4
+ import { MeasuredCell } from "../ui/layout/measureLayout";
5
+ import type { RenderedCell } from "./types";
6
+ export declare function prepareLayout(element: Element, parent: wuiraNativeFrame, mountedFrames: ReadonlyMap<CellProps, wuiraNativeFrame>): {
7
+ measured: MeasuredCell;
8
+ protectedTree: boolean;
9
+ };
10
+ export declare function createFrames(measured: MeasuredCell, parent: wuiraNativeFrame, mountedFrames: ReadonlyMap<CellProps, wuiraNativeFrame>): {
11
+ root: wuiraNativeFrame;
12
+ pending: RenderedCell[];
13
+ frames: Map<CellProps, wuiraNativeFrame>;
14
+ };
15
+ export declare function resolveAnchors(pending: RenderedCell[], frames: ReadonlyMap<CellProps, wuiraNativeFrame>): Map<wuiraNativeFrame, wuiraNativeFrame>;
16
+ export declare function applyPosition(item: RenderedCell, anchors: ReadonlyMap<wuiraNativeFrame, wuiraNativeFrame>, root: wuiraNativeFrame, rootAnchor?: Anchor): void;
@@ -0,0 +1,594 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ -- Lua Library inline imports
3
+ local function __TS__Class(self)
4
+ local c = {prototype = {}}
5
+ c.prototype.__index = c.prototype
6
+ c.prototype.constructor = c
7
+ return c
8
+ end
9
+
10
+ local __TS__Symbol, Symbol
11
+ do
12
+ local symbolMetatable = {__tostring = function(self)
13
+ return ("Symbol(" .. (self.description or "")) .. ")"
14
+ end}
15
+ function __TS__Symbol(description)
16
+ return setmetatable({description = description}, symbolMetatable)
17
+ end
18
+ Symbol = {
19
+ asyncDispose = __TS__Symbol("Symbol.asyncDispose"),
20
+ dispose = __TS__Symbol("Symbol.dispose"),
21
+ iterator = __TS__Symbol("Symbol.iterator"),
22
+ hasInstance = __TS__Symbol("Symbol.hasInstance"),
23
+ species = __TS__Symbol("Symbol.species"),
24
+ toStringTag = __TS__Symbol("Symbol.toStringTag")
25
+ }
26
+ end
27
+
28
+ local __TS__Iterator
29
+ do
30
+ local function iteratorGeneratorStep(self)
31
+ local co = self.____coroutine
32
+ local status, value = coroutine.resume(co)
33
+ if not status then
34
+ error(value, 0)
35
+ end
36
+ if coroutine.status(co) == "dead" then
37
+ return
38
+ end
39
+ return true, value
40
+ end
41
+ local function iteratorIteratorStep(self)
42
+ local result = self:next()
43
+ if result.done then
44
+ return
45
+ end
46
+ return true, result.value
47
+ end
48
+ local function iteratorStringStep(self, index)
49
+ index = index + 1
50
+ if index > #self then
51
+ return
52
+ end
53
+ return index, string.sub(self, index, index)
54
+ end
55
+ function __TS__Iterator(iterable)
56
+ if type(iterable) == "string" then
57
+ return iteratorStringStep, iterable, 0
58
+ elseif iterable.____coroutine ~= nil then
59
+ return iteratorGeneratorStep, iterable
60
+ elseif iterable[Symbol.iterator] then
61
+ local iterator = iterable[Symbol.iterator](iterable)
62
+ return iteratorIteratorStep, iterator
63
+ else
64
+ return ipairs(iterable)
65
+ end
66
+ end
67
+ end
68
+
69
+ local function __TS__New(target, ...)
70
+ local instance = setmetatable({}, target.prototype)
71
+ instance:____constructor(...)
72
+ return instance
73
+ end
74
+
75
+ local Set
76
+ do
77
+ Set = __TS__Class()
78
+ Set.name = "Set"
79
+ function Set.prototype.____constructor(self, values)
80
+ self[Symbol.toStringTag] = "Set"
81
+ self.size = 0
82
+ self.nextKey = {}
83
+ self.previousKey = {}
84
+ if values == nil then
85
+ return
86
+ end
87
+ local iterable = values
88
+ if iterable[Symbol.iterator] then
89
+ local iterator = iterable[Symbol.iterator](iterable)
90
+ while true do
91
+ local result = iterator:next()
92
+ if result.done then
93
+ break
94
+ end
95
+ self:add(result.value)
96
+ end
97
+ else
98
+ local array = values
99
+ for ____, value in ipairs(array) do
100
+ self:add(value)
101
+ end
102
+ end
103
+ end
104
+ function Set.prototype.add(self, value)
105
+ local isNewValue = not self:has(value)
106
+ if isNewValue then
107
+ self.size = self.size + 1
108
+ end
109
+ if self.firstKey == nil then
110
+ self.firstKey = value
111
+ self.lastKey = value
112
+ elseif isNewValue then
113
+ self.nextKey[self.lastKey] = value
114
+ self.previousKey[value] = self.lastKey
115
+ self.lastKey = value
116
+ end
117
+ return self
118
+ end
119
+ function Set.prototype.clear(self)
120
+ self.nextKey = {}
121
+ self.previousKey = {}
122
+ self.firstKey = nil
123
+ self.lastKey = nil
124
+ self.size = 0
125
+ end
126
+ function Set.prototype.delete(self, value)
127
+ local contains = self:has(value)
128
+ if contains then
129
+ self.size = self.size - 1
130
+ local next = self.nextKey[value]
131
+ local previous = self.previousKey[value]
132
+ if next ~= nil and previous ~= nil then
133
+ self.nextKey[previous] = next
134
+ self.previousKey[next] = previous
135
+ elseif next ~= nil then
136
+ self.firstKey = next
137
+ self.previousKey[next] = nil
138
+ elseif previous ~= nil then
139
+ self.lastKey = previous
140
+ self.nextKey[previous] = nil
141
+ else
142
+ self.firstKey = nil
143
+ self.lastKey = nil
144
+ end
145
+ self.nextKey[value] = nil
146
+ self.previousKey[value] = nil
147
+ end
148
+ return contains
149
+ end
150
+ function Set.prototype.forEach(self, callback)
151
+ for ____, key in __TS__Iterator(self:keys()) do
152
+ callback(nil, key, key, self)
153
+ end
154
+ end
155
+ function Set.prototype.has(self, value)
156
+ return self.nextKey[value] ~= nil or self.lastKey == value
157
+ end
158
+ Set.prototype[Symbol.iterator] = function(self)
159
+ return self:values()
160
+ end
161
+ function Set.prototype.entries(self)
162
+ local function getFirstKey()
163
+ return self.firstKey
164
+ end
165
+ local nextKey = self.nextKey
166
+ local key
167
+ local started = false
168
+ return {
169
+ [Symbol.iterator] = function(self)
170
+ return self
171
+ end,
172
+ next = function(self)
173
+ if not started then
174
+ started = true
175
+ key = getFirstKey(nil)
176
+ else
177
+ key = nextKey[key]
178
+ end
179
+ return {done = not key, value = {key, key}}
180
+ end
181
+ }
182
+ end
183
+ function Set.prototype.keys(self)
184
+ local function getFirstKey()
185
+ return self.firstKey
186
+ end
187
+ local nextKey = self.nextKey
188
+ local key
189
+ local started = false
190
+ return {
191
+ [Symbol.iterator] = function(self)
192
+ return self
193
+ end,
194
+ next = function(self)
195
+ if not started then
196
+ started = true
197
+ key = getFirstKey(nil)
198
+ else
199
+ key = nextKey[key]
200
+ end
201
+ return {done = not key, value = key}
202
+ end
203
+ }
204
+ end
205
+ function Set.prototype.values(self)
206
+ local function getFirstKey()
207
+ return self.firstKey
208
+ end
209
+ local nextKey = self.nextKey
210
+ local key
211
+ local started = false
212
+ return {
213
+ [Symbol.iterator] = function(self)
214
+ return self
215
+ end,
216
+ next = function(self)
217
+ if not started then
218
+ started = true
219
+ key = getFirstKey(nil)
220
+ else
221
+ key = nextKey[key]
222
+ end
223
+ return {done = not key, value = key}
224
+ end
225
+ }
226
+ end
227
+ function Set.prototype.union(self, other)
228
+ local result = __TS__New(Set, self)
229
+ for ____, item in __TS__Iterator(other) do
230
+ result:add(item)
231
+ end
232
+ return result
233
+ end
234
+ function Set.prototype.intersection(self, other)
235
+ local result = __TS__New(Set)
236
+ for ____, item in __TS__Iterator(self) do
237
+ if other:has(item) then
238
+ result:add(item)
239
+ end
240
+ end
241
+ return result
242
+ end
243
+ function Set.prototype.difference(self, other)
244
+ local result = __TS__New(Set, self)
245
+ for ____, item in __TS__Iterator(other) do
246
+ result:delete(item)
247
+ end
248
+ return result
249
+ end
250
+ function Set.prototype.symmetricDifference(self, other)
251
+ local result = __TS__New(Set, self)
252
+ for ____, item in __TS__Iterator(other) do
253
+ if self:has(item) then
254
+ result:delete(item)
255
+ else
256
+ result:add(item)
257
+ end
258
+ end
259
+ return result
260
+ end
261
+ function Set.prototype.isSubsetOf(self, other)
262
+ for ____, item in __TS__Iterator(self) do
263
+ if not other:has(item) then
264
+ return false
265
+ end
266
+ end
267
+ return true
268
+ end
269
+ function Set.prototype.isSupersetOf(self, other)
270
+ for ____, item in __TS__Iterator(other) do
271
+ if not self:has(item) then
272
+ return false
273
+ end
274
+ end
275
+ return true
276
+ end
277
+ function Set.prototype.isDisjointFrom(self, other)
278
+ for ____, item in __TS__Iterator(self) do
279
+ if other:has(item) then
280
+ return false
281
+ end
282
+ end
283
+ return true
284
+ end
285
+ Set[Symbol.species] = Set
286
+ end
287
+
288
+ local Map
289
+ do
290
+ Map = __TS__Class()
291
+ Map.name = "Map"
292
+ function Map.prototype.____constructor(self, entries)
293
+ self[Symbol.toStringTag] = "Map"
294
+ self.items = {}
295
+ self.size = 0
296
+ self.nextKey = {}
297
+ self.previousKey = {}
298
+ if entries == nil then
299
+ return
300
+ end
301
+ local iterable = entries
302
+ if iterable[Symbol.iterator] then
303
+ local iterator = iterable[Symbol.iterator](iterable)
304
+ while true do
305
+ local result = iterator:next()
306
+ if result.done then
307
+ break
308
+ end
309
+ local value = result.value
310
+ self:set(value[1], value[2])
311
+ end
312
+ else
313
+ local array = entries
314
+ for ____, kvp in ipairs(array) do
315
+ self:set(kvp[1], kvp[2])
316
+ end
317
+ end
318
+ end
319
+ function Map.prototype.clear(self)
320
+ self.items = {}
321
+ self.nextKey = {}
322
+ self.previousKey = {}
323
+ self.firstKey = nil
324
+ self.lastKey = nil
325
+ self.size = 0
326
+ end
327
+ function Map.prototype.delete(self, key)
328
+ local contains = self:has(key)
329
+ if contains then
330
+ self.size = self.size - 1
331
+ local next = self.nextKey[key]
332
+ local previous = self.previousKey[key]
333
+ if next ~= nil and previous ~= nil then
334
+ self.nextKey[previous] = next
335
+ self.previousKey[next] = previous
336
+ elseif next ~= nil then
337
+ self.firstKey = next
338
+ self.previousKey[next] = nil
339
+ elseif previous ~= nil then
340
+ self.lastKey = previous
341
+ self.nextKey[previous] = nil
342
+ else
343
+ self.firstKey = nil
344
+ self.lastKey = nil
345
+ end
346
+ self.nextKey[key] = nil
347
+ self.previousKey[key] = nil
348
+ end
349
+ self.items[key] = nil
350
+ return contains
351
+ end
352
+ function Map.prototype.forEach(self, callback)
353
+ for ____, key in __TS__Iterator(self:keys()) do
354
+ callback(nil, self.items[key], key, self)
355
+ end
356
+ end
357
+ function Map.prototype.get(self, key)
358
+ return self.items[key]
359
+ end
360
+ function Map.prototype.has(self, key)
361
+ return self.nextKey[key] ~= nil or self.lastKey == key
362
+ end
363
+ function Map.prototype.set(self, key, value)
364
+ local isNewValue = not self:has(key)
365
+ if isNewValue then
366
+ self.size = self.size + 1
367
+ end
368
+ self.items[key] = value
369
+ if self.firstKey == nil then
370
+ self.firstKey = key
371
+ self.lastKey = key
372
+ elseif isNewValue then
373
+ self.nextKey[self.lastKey] = key
374
+ self.previousKey[key] = self.lastKey
375
+ self.lastKey = key
376
+ end
377
+ return self
378
+ end
379
+ Map.prototype[Symbol.iterator] = function(self)
380
+ return self:entries()
381
+ end
382
+ function Map.prototype.entries(self)
383
+ local function getFirstKey()
384
+ return self.firstKey
385
+ end
386
+ local items = self.items
387
+ local nextKey = self.nextKey
388
+ local key
389
+ local started = false
390
+ return {
391
+ [Symbol.iterator] = function(self)
392
+ return self
393
+ end,
394
+ next = function(self)
395
+ if not started then
396
+ started = true
397
+ key = getFirstKey(nil)
398
+ else
399
+ key = nextKey[key]
400
+ end
401
+ return {done = not key, value = {key, items[key]}}
402
+ end
403
+ }
404
+ end
405
+ function Map.prototype.keys(self)
406
+ local function getFirstKey()
407
+ return self.firstKey
408
+ end
409
+ local nextKey = self.nextKey
410
+ local key
411
+ local started = false
412
+ return {
413
+ [Symbol.iterator] = function(self)
414
+ return self
415
+ end,
416
+ next = function(self)
417
+ if not started then
418
+ started = true
419
+ key = getFirstKey(nil)
420
+ else
421
+ key = nextKey[key]
422
+ end
423
+ return {done = not key, value = key}
424
+ end
425
+ }
426
+ end
427
+ function Map.prototype.values(self)
428
+ local function getFirstKey()
429
+ return self.firstKey
430
+ end
431
+ local items = self.items
432
+ local nextKey = self.nextKey
433
+ local key
434
+ local started = false
435
+ return {
436
+ [Symbol.iterator] = function(self)
437
+ return self
438
+ end,
439
+ next = function(self)
440
+ if not started then
441
+ started = true
442
+ key = getFirstKey(nil)
443
+ else
444
+ key = nextKey[key]
445
+ end
446
+ return {done = not key, value = items[key]}
447
+ end
448
+ }
449
+ end
450
+ Map[Symbol.species] = Map
451
+ end
452
+ -- End of Lua Library inline imports
453
+ local ____exports = {}
454
+ local ____SecureButton = require("platform.SecureButton")
455
+ local validateSecureButton = ____SecureButton.validateSecureButton
456
+ local ____measureLayout = require("ui.layout.measureLayout")
457
+ local measureLayout = ____measureLayout.measureLayout
458
+ local ____widgets = require("rendering.widgets")
459
+ local createWidget = ____widgets.createWidget
460
+ function ____exports.prepareLayout(self, element, parent, mountedFrames)
461
+ local rootProps = element.props
462
+ local measured = measureLayout(
463
+ nil,
464
+ element,
465
+ {
466
+ width = rootProps.width == "inherit" and parent:GetWidth() or nil,
467
+ height = rootProps.height == "inherit" and parent:GetHeight() or nil
468
+ }
469
+ )
470
+ local ____temp_3 = parent ~= UIParent
471
+ if ____temp_3 then
472
+ local ____this_1
473
+ ____this_1 = parent
474
+ local ____opt_0 = ____this_1.IsProtected
475
+ local ____temp_2 = ____opt_0 and ____opt_0(____this_1)
476
+ if ____temp_2 == nil then
477
+ ____temp_2 = false
478
+ end
479
+ ____temp_3 = ____temp_2
480
+ end
481
+ local protectedTree = ____temp_3
482
+ local seen = __TS__New(Set)
483
+ local function validate(self, item)
484
+ if seen:has(item.cell.props) or mountedFrames:has(item.cell.props) then
485
+ error("A Cell can only be mounted once at a time")
486
+ end
487
+ seen:add(item.cell.props)
488
+ if item.cell.kind == "secureButton" then
489
+ protectedTree = true
490
+ validateSecureButton(nil, item.cell.props)
491
+ end
492
+ for ____, child in ipairs(item.children) do
493
+ validate(nil, child)
494
+ end
495
+ end
496
+ validate(nil, measured)
497
+ if protectedTree and InCombatLockdown() then
498
+ error("SecureButton: mount protected UI outside combat")
499
+ end
500
+ return {measured = measured, protectedTree = protectedTree}
501
+ end
502
+ function ____exports.createFrames(self, measured, parent, mountedFrames)
503
+ local frames = __TS__New(Map)
504
+ local pending = {}
505
+ local function create(self, measured, parent, placement)
506
+ local ____measured_4 = measured
507
+ local cell = ____measured_4.cell
508
+ local width = ____measured_4.width
509
+ local height = ____measured_4.height
510
+ if frames:has(cell.props) or mountedFrames:has(cell.props) then
511
+ error("A Cell can only be mounted once at a time")
512
+ end
513
+ local frame = createWidget(nil, cell, parent)
514
+ frames:set(cell.props, frame)
515
+ pending[#pending + 1] = {
516
+ cell = cell,
517
+ width = width,
518
+ height = height,
519
+ margin = measured.margin,
520
+ frame = frame,
521
+ parent = parent,
522
+ placement = placement
523
+ }
524
+ frame:SetSize(width, height)
525
+ do
526
+ local index = 0
527
+ while index < #measured.children do
528
+ local ____create_8 = create
529
+ local ____measured_children_index_7 = measured.children[index + 1]
530
+ local ____opt_5 = measured.placements
531
+ ____create_8(nil, ____measured_children_index_7, frame, ____opt_5 and ____opt_5[index + 1])
532
+ index = index + 1
533
+ end
534
+ end
535
+ return frame
536
+ end
537
+ local root = create(nil, measured, parent)
538
+ return {root = root, pending = pending, frames = frames}
539
+ end
540
+ function ____exports.resolveAnchors(self, pending, frames)
541
+ local anchors = __TS__New(Map)
542
+ for ____, item in ipairs(pending) do
543
+ local position = item.cell.props
544
+ if item.placement ~= nil then
545
+ anchors:set(item.frame, item.parent)
546
+ elseif position.mode == "absolute" then
547
+ anchors:set(item.frame, UIParent)
548
+ else
549
+ local target = position.relativeTo == nil and item.parent or frames:get(position.relativeTo.props)
550
+ if target == nil then
551
+ error("relativeTo must reference a Cell in the same mounted tree")
552
+ end
553
+ if target == item.frame then
554
+ error("A Cell cannot anchor to itself")
555
+ end
556
+ anchors:set(item.frame, target)
557
+ end
558
+ end
559
+ for ____, item in ipairs(pending) do
560
+ local target = anchors:get(item.frame)
561
+ while target ~= nil do
562
+ if target == item.frame then
563
+ error("Cell positioning contains an anchor cycle")
564
+ end
565
+ target = anchors:get(target)
566
+ end
567
+ end
568
+ return anchors
569
+ end
570
+ function ____exports.applyPosition(self, item, anchors, root, rootAnchor)
571
+ local position = item.cell.props
572
+ local target = anchors:get(item.frame)
573
+ local ____opt_9 = item.placement
574
+ local x = ____opt_9 and ____opt_9.x or (position.mode == "absolute" and position.x or position.offset.x)
575
+ local ____opt_11 = item.placement
576
+ local y = ____opt_11 and ____opt_11.y or (position.mode == "absolute" and position.y or position.offset.y)
577
+ local ____temp_13
578
+ if item.frame == root then
579
+ ____temp_13 = rootAnchor
580
+ else
581
+ ____temp_13 = nil
582
+ end
583
+ local overrideAnchor = ____temp_13
584
+ local anchor = overrideAnchor or (item.placement ~= nil and "TOPLEFT" or (position.anchor or "TOPLEFT"))
585
+ local relativeAnchor = overrideAnchor or (item.placement ~= nil and "TOPLEFT" or (position.relativeAnchor or anchor))
586
+ item.frame:SetPoint(
587
+ anchor,
588
+ target,
589
+ relativeAnchor,
590
+ x + item.margin.left,
591
+ -(y + item.margin.top)
592
+ )
593
+ end
594
+ return ____exports
@@ -0,0 +1,2 @@
1
+ import type { MountedTree, RenderedCell } from "./types";
2
+ export declare function renderProgress(item: RenderedCell, tree: MountedTree, onActiveChange: (active: boolean) => void): void;