-
Notifications
You must be signed in to change notification settings - Fork 1
/
plistData.js
377 lines (342 loc) · 13.5 KB
/
plistData.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
exports.PlistCenter = function (plist) {
this.plist = plist
let objects = plist["com.apple.ibtool.document.objects"]
let hierarchys = plist["com.apple.ibtool.document.hierarchy"]
let connections = plist["com.apple.ibtool.document.connections"]
//生成ID-name表
var name_ID_Dic = new Array()
for (connectionKey in connections) {
let connection = connections[connectionKey]
if (connection["type"] == "IBCocoaTouchOutletConnection") {
let destinationID = connection["destination-id"]
let name = connection["label"]
name_ID_Dic[destinationID] = name
}
}
this.name_ID_Dic = name_ID_Dic
//生成一张view层次图
var hieDic = new Array()
for (var i = 0; i < hierarchys.length; i++) {
var hierarch = hierarchys[i]
let partHieDic = generateHierarchFrom(hierarch)
for (key in partHieDic) {
hieDic[key] = partHieDic[key]
}
}
//生成一张可以根据ID查询归属controller的图
var controllerHieDic = []
for (var i = 0; i < hierarchys.length; i++) {
var hierarch = hierarchys[i]
let hieID = hierarch['object-id']
let allHieID = getAllHierarchIDFrom(hierarch)
controllerHieDic[hieID] = allHieID
}
this.getFatherOf = function (id_lu) {
return hieDic[id_lu]
}
this.getHieIDArrOf = function (id_lu) {
return controllerHieDic[id_lu]
}
this.getControlOf = function (id_lu) {
for (key in controllerHieDic) {
let array = controllerHieDic[key]
if (array.indexOf(id_lu) >= 0) {
return key
}
}
}
this.isCustomClassOf = function (id_lu) {
let object = objects[id_lu]
var objectClass = object["ibExternalCustomClassName"]
if (typeof (objectClass) == "undefined") {
return false
}
return true
}
this.getClassOf = function (id_lu) {
let object = objects[id_lu]
var objectClass = object["ibExternalCustomClassName"]
if (typeof (objectClass) == "undefined") {
objectClass = object["class"]
objectClass = objectClass.substring(2, objectClass.length)
}
return objectClass
}
this.getNameOf = function (id_lu) {
var name = this.name_ID_Dic[id_lu]
if (typeof (id_lu) == 'undefined') {
console.log("get name of id 出现空")
}
if (typeof (name) == "undefined") {
let type = this.getTypeOf(id_lu)
if (type == this.ObjectType.View) {
let isRootView = this.isRootViewOf(id_lu)
if (isRootView == true) {
name = "view"
return name
}
}
let objectID = id_lu.replace(/-/g, '')
let objectClass = this.getClassOf(id_lu)
let isCustomClass = this.isCustomClassOf(id_lu)
if (isCustomClass == true) {
name = objectClass.toLowerCase() + objectID.toLowerCase()
} else {
let prefix = objectClass.substring(2, objectClass.length)
prefix = prefix.substring(0, 1).toLowerCase() + prefix.substring(1, prefix.length)
name = prefix + objectID
}
//如果该id是一个view,应该判断是否是根view
}
return name
}
this.ObjectType = {
Controller: "Controller",
View: "View",
Constrain: "Constrain",
LayoutGuide: "LayoutGuide",
SafeAreaGuide: "SafeAreaGuide", //view的guide,自动定义为safe area guide
Other: "Other"
}
//IB中全部view类型
//不全待补 05-06
let viewClassArray = ["IBUILabel", "IBUIButton", "IBUITextField", "IBUISlider", "IBUISwitch", "IBUIActivityIndicatorView", "IBUIProgressView", "IBUIPageControl", "IBUIStepper", "IBUIHorizontalStackView", "IBUIVerticalStackView", "IBUITableView", "IBUITableViewCell", "IBUIImageView", "IBUICollectionView", "IBUICollectionViewCell", "IBUICollectionReuseableView", "IBUITextView", "IBUIScrollView", "IBUIDatePicker", "IBUIPickerView", "IBUIVisualEffectView", "IBMKMapView", "IBMTKView", "IBGLKView", "IBUIWebView", "IBUINavigationBar", "IBUINavigationItem", "IBUIToolbar", "IBUIBarButtonItem", "IBUITabBar", "IBUITabBarItem", "IBUISearchBar", "IBUIView", "IBUIContainerView", "IBUITableViewCellContentView", "IBUISegmentedControl", "IBUIPageControl"]
//controller是全的
let controlClassArray = ["IBUIViewController", "IBUINavigationController", "IBUITableViewController", "IBUICollectionViewController", "IBUITabBarController", "IBUISplitViewController", "IBUIPageViewController", "IBUIGLKitViewController", "IBUIAVKitPlayerViewController"]
//手势
this.getTypeOf = function (id_lu) {
let object = objects[id_lu]
var objectClass = object["class"]
if (viewClassArray.indexOf(objectClass) >= 0) {
return this.ObjectType.View
} else if (controlClassArray.indexOf(objectClass) >= 0) {
return this.ObjectType.Controller
} else if (objectClass == "IBLayoutConstraint") {
return this.ObjectType.Constrain
} else if (objectClass == "IBUIViewControllerAutolayoutGuide") {
return this.ObjectType.LayoutGuide
} else if (objectClass == "IBUIViewAutolayoutGuide") {
return this.ObjectType.SafeAreaGuide
}
return this.ObjectType.Other
}
/*****************************controller相关方法***********************************/
this.getActionsOf = function (id_lu) {
//从connection里取
var arrOfConnection = []
let type = this.getTypeOf(id_lu)
if (type == this.ObjectType.Controller) {
for (key in connections) {
let connection = connections[key]
let desID = connection["destination-id"]
let connectionType = connection["type"]
if (desID == id_lu && connectionType == "IBCocoaTouchEventConnection") {
arrOfConnection.push(connection)
}
}
} else {
console.log("不能controller,不能取action")
}
return arrOfConnection
}
this.getRootViewOf = function (id_lu) {
//hierarchys
let type = this.getTypeOf(id_lu)
if (type == this.ObjectType.Controller) {
for (var i = 0; i < hierarchys.length; i++) {
var hierarch = hierarchys[i]
let hierarchID = hierarch["object-id"]
if (hierarchID == id_lu) {
var children = hierarch["children"]
for (var j = 0; j < children.length; j++) {
var controlChild = children[i]
let controlChildName = controlChild['label']
let arrayOfBlack = ['Top Layout Guide', 'Bottom Layout Guide', 'Navigation Item']
if (arrayOfBlack.indexOf(controlChildName) >= 0) {
//不是rootview
} else {
return controlChild['object-id']
}
}
break
}
}
}
}
/*****************************constraint相关方法***********************************/
this.getConstraintItemNameOf = function (id_lu, isFirstItem) {
let object = objects[id_lu]
var itemTagName
if (isFirstItem == true) {
itemTagName = "firstItem"
} else {
itemTagName = "secondItem"
}
let itemObject = object[itemTagName]
if (typeof (itemObject) == "undefined") {
return
}
let itemID = itemObject["ObjectID"]
let typeOfItem = this.getTypeOf(itemID)
if (typeOfItem == this.ObjectType.View) {
var itemName = this.getNameOf(itemID)
return itemName
} else if (typeOfItem == this.ObjectType.Constrain) {
return "SomeConstrain"
} else if (typeOfItem == this.ObjectType.LayoutGuide) {
return "view.layoutMarginsGuide"
} else if (typeOfItem == this.ObjectType.SafeAreaGuide) {
return "self.safeAreaLayoutGuide"
} else if (typeOfItem == this.ObjectType.Controller) {
return "SomeController"
} else {
let object = objects[itemID]
var objectClass = object["class"]
return "UnknowType" + itemID + objectClass
}
}
this.getConstraintAttriOf = function (id_lu, isFirstItem) {
let object = objects[id_lu]
var itemTagName
if (isFirstItem == true) {
itemTagName = "firstAttribute"
} else {
itemTagName = "secondAttribute"
}
let itemAttri = object[itemTagName]
if (itemAttri == 1) {
return 'left'
} else if (itemAttri == 2) {
return 'right'
} else if (itemAttri == 3) {
return 'top'
} else if (itemAttri == 4) {
return 'bottom'
} else if (itemAttri == 5) {
return 'leading'
} else if (itemAttri == 6) {
return 'trailing'
} else if (itemAttri == 7) {
return 'width'
} else if (itemAttri == 8) {
return 'height'
} else if (itemAttri == 9) {
return 'centerX'
} else if (itemAttri == 10) {
return 'centerY'
} else {
return itemAttri + ""
}
}
this.getConstraintContantOf = function (id_lu) {
let object = objects[id_lu]
return object["constant"]["value"]
}
this.getConstraintMultiplierOf = function (id_lu) {
let object = objects[id_lu]
return object["multiplier"]
}
/*****************************view相关方法***********************************/
this.isRootViewOf = function (id_lu) {
let id_father = this.getFatherOf(id_lu)
if (typeof (id_father) != "undefined") {
let fatherType = this.getTypeOf(id_father)
if (fatherType == this.ObjectType.Controller) {
return true
}
}
return false
}
//系统自动生成的类,代补全
let systemGenViewClassArray = ["UITableViewCell", "UICollectionViewCell"]
this.isSystemGenerateOf = function (id_lu) {
//判断是否该view是系统自动生成的
let type = this.getTypeOf(id_lu)
if (type == this.ObjectType.View) {
let isRootView = this.isRootViewOf(id_lu)
if (isRootView == true) {
return true
} else {
let id_father = this.getFatherOf(id_lu)
if (typeof (id_father) == "undefined") {
return true
}
let className = this.getClassOf(id_lu)
if (systemGenViewClassArray.indexOf(className) >= 0) {
return true
}
}
return false
}
}
//中间不可见view
let invisibleMiddleViewClassArray = ["UITableViewCellContentView"]
this.isInvisibleMiddleViewOf = function (id_lu) {
//用在add subview中,寻找合适的father view
let className = this.getClassOf(id_lu)
if (invisibleMiddleViewClassArray.indexOf(className) >= 0) {
return true
}
return false
}
//合适的father view
this.getFatherNameOf = function (id_lu) {
var fatherID = this.getFatherOf(id_lu)
while (this.isInvisibleMiddleViewOf(fatherID)) {
//
}
}
//私有方法
function generateHierarchFrom(hierarchy) {
var hieDicl = []
let curID = hierarchy["object-id"]
let children = hierarchy["children"]
if (typeof (children) != "undefined") {
for (var i = 0; i < children.length; i++) {
let child = children[i]
let childID = child["object-id"]
hieDicl[childID] = curID
let hieDicOfChild = generateHierarchFrom(child)
for (key in hieDicOfChild) {
hieDicl[key] = hieDicOfChild[key]
}
}
}
return hieDicl
}
function getAllHierarchIDFrom(hierarchy) {
var hieArr = []
let children = hierarchy["children"]
if (typeof (children) != "undefined") {
for (var i = 0; i < children.length; i++) {
let child = children[i]
let childID = child["object-id"]
hieArr.push(childID)
let allHieIDOfChild = getAllHierarchIDFrom(child)
hieArr = hieArr.concat(allHieIDOfChild)
}
}
return hieArr
}
//生成一张可以根据ID查询constrain的图
var viewContrainDic = []
for (key in objects) {
let type = this.getTypeOf(key)
if (type == this.ObjectType.Constrain) {
if (typeof (key) != "undefined") {
let firstItemID = objects[key]['firstItem']['ObjectID']
var array = viewContrainDic[firstItemID]
if (typeof (array) == 'undefined') {
array = []
}
array.push(key)
viewContrainDic[firstItemID] = array
} else {
console.log("遍历object出现key是空的情况")
}
}
}
this.getConstraintOf = function (id_lu) {
return viewContrainDic[id_lu]
}
}