/
Selectors.jsfl
1511 lines (1314 loc) · 40.1 KB
/
Selectors.jsfl
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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ------------------------------------------------------------------------------------------------------------------------
//
// ██████ ██ ██
// ██ ██ ██
// ██ █████ ██ █████ █████ █████ █████ ████ █████
// ██████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
// ██ █████ ██ █████ ██ ██ ██ ██ ██ █████
// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
// ██████ █████ ██ █████ █████ ████ █████ ██ █████
//
// ------------------------------------------------------------------------------------------------------------------------
// Selectors
/**
* Selectors
* @overview Static repository of tests used by the Selector class
* @instance
*/
xjsfl.init(this, ['Context', 'Iterators', 'Selector', 'Utils']);
// ----------------------------------------------------------------------------------------------------
// # Main Selectors class
Selectors =
{
/**
*
* @param expression {String} A CSS expression
* @param items {Array} An array of items to filter
* @param scope {Object} A valid scope reference. Valid types are Library, Document, Timeline, Layer, Frame
* @param debug {Boolean} An optional flag to print Selector information to the Output panel
* @returns {Array} An array of elements, items, etc
*/
select:function(expression, items, scope, debug)
{
// --------------------------------------------------------------------------------
// setup
// define selection type from scope
var matches = String(scope).match(/(Library|Document|Timeline|Layer|Frame)/);
if(matches)
{
var types =
{
'Library': 'Item',
'Document': 'Element',
'Timeline': 'Layer',
'Layer': 'Frame'
}
var type = types[matches[1]];
}
else
{
throw new TypeError('TypeError: Invalid scope "' +scope+ '" supplied to Selector.select()');
}
// --------------------------------------------------------------------------------
// process expression
// exit early if universal selector is supplied
if(expression === '*')
{
return items;
}
// sort items if type is Item and expression contains an oreder-relevent selector type
if(type === 'Item' && /:(first|last|even|odd|nth)\b/.test(expression))
{
items = Utils.sortOn(items, 'name', true);
}
// break up any comma-delimited expressions into an array of discrete expressions
var expressions = Utils.parseExpression(expression);
// get items
var results = [];
for each (var expression in expressions)
{
// parse rule into selector array
var selectors = this.parse(expression, type);
// set up debug
Selectors.debug = debug;
// get items
var _results = Selectors.test(selectors, items, scope)
// append to existing results array
results = results.concat(_results);
}
// ensure items are unique
results = Utils.toUniqueArray(results);
// return
return results;
},
/**
* Registers a custom selector
* @param {String} pattern The pattern of the selector. Valid values are ":type" or "[attribute]"
* @param {Function} callback A pseudo callback of the format function(item){ return state }
* @param {Function} callback An attribute callback of the format function(item){ return value }
* @param {String} type The type of selector. Valid values are Library|Document|Timeline|Layer|Frame
*/
register:function(pattern, callback, type)
{
// variables
pattern = String(pattern);
var matches = pattern.match(/([:\[])(\w+)/);
var group;
// test for valid selector
if(matches)
{
// error if wrong type
if( ! /^(item|element)$/.test(type) )
{
throw new Error('Error in Selectors.register(): Invalid type "' +type+ '" supplied');
}
// OK, extract the selector
var selector = matches[2];
// :pseudo selector
if(matches[1] == ':')
{
group = 'pseudo';
}
// [attribute] selector
else if(matches[1] == '[')
{
group = 'custom';
}
// assign
Selectors[type][group][selector] = callback;
// return
return Selectors;
}
else
{
throw new Error('Error in Selectors.register(): Invalid pattern "' +pattern+ '" supplied');
}
},
/**
* parse a selector expression into selectors - also called from :not()
* @param expression {String} A CSS expression
* @param type {String} The type of parse, e.g. Item, Element, etc
* @returns
*/
parse:function(expression, type)
{
// --------------------------------------------------------------------------------
// setup
// chunker
/*
# type example
-------------------------------------------------
1: combo :not(selector)
2: type :not
3: selector :bitmap
4: name this is a name
5: path /this is/a path
6: Class .Class
7: package .com.domain.package.Class
8: pseudo :type
9: attribute [attribute=value]
10: name attribute
11: operand =
12: value value
*/
var chunker = /(:([\-\w]+)\((.+)\))|([A-Za-z0-9_*][^:\[]*)|\/([\-\w\s\/_*{|}]+)|\.([*A-Z][\w*]+)|\.([a-z][\w.*]+)|:([a-z]\w+)|\[(([\w\.]+)([\^$*!=<>]{1,2})?(.+?)?)\]/g;
// 1 2 3 4 5 6 7 8 9 10 11 12
// variables
var exec,
selector,
selectors = [],
object = Selectors[type.toLowerCase()],
core = Selectors.core;
// debug
//trace('\n\n\n\n--------------------------------------------------------------------------------\n' + expression + '\n--------------------------------------------------------------------------------')
// --------------------------------------------------------------------------------
// parse
while(exec = chunker.exec(expression))
{
// --------------------------------------------------------------------------------
// setup
// debug
//inspect(exec);
//trace(limit++);
// create
selector = new Selector(exec[0]);
// --------------------------------------------------------------------------------
// create selector
// note - selector params[0] is always null, as the Selector will populate it with the relevent values itself
// 1: combo ":not(:bitmap)"
if(exec[1])
{
selector.type = 'combo';
selector.name = exec[2];
selector.method = core.combo[selector.name];
selector.params = [null, Selector.makeRX(exec[3], selector)];
selector.params = [null, exec[3], type];
}
// 4: name "Item_03"
else if(exec[4])
{
selector.type = 'filter';
selector.name = 'name';
selector.method = object.filter.name;
selector.params = [null, Selector.makeRX(exec[4], selector), selector.range];
}
// 5: path "/path/to/item" (can only be Library or Stage)
else if(exec[5])
{
selector.type = 'filter';
selector.name = 'path';
selector.method = object.filter.path;
selector.params = [null, Selector.makeRX(exec[5].replace(/(^\/+|\/+$)/g, ''), selector), selector.range];
}
// 6: Class ".Class"
else if(exec[6])
{
selector.type = 'filter';
selector.name = 'Class';
selector.method = object.filter.Class;
selector.params = [null, Selector.makeRX(exec[6], selector)];
}
// 7: package ".com.domain.package.Class"
else if(exec[7])
{
selector.type = 'filter';
selector.name = 'Package';
selector.method = object.filter.Package;
selector.params = [null, Selector.makeRX(exec[7], selector)];
}
// 8: pseudo ":type"
else if(exec[8])
{
// variables
var method;
var name = exec[8];
// type
if(/instance|symbol|bitmap|sound|embeddedvideo|linkedvideo|video|compiledclip|text|folder|static|dynamic|input|primitive|group|shape|movieclip|graphic|button/.test(name))
{
selector.type = 'type';
selector.params = [null, name];
method = object.filter.type;
}
// find
else if(/selected|children|descendants|parent|first|last|even|odd|random/.test(name))
{
selector.type = 'find';
selector.params = [null];
method = object.find[name] || core.find[name];
}
// pseudo, i.e. /exported|empty|animated|keyframed|scripted|audible|filtered|tinted|component/
// custom, i.e. /any|custom|values|which|need|to|have|been|registered/
else
{
selector.type = 'pseudo';
selector.params = [null, name];
method = object.pseudo[name] || core.pseudo[name];
}
// assign
selector.name = name;
selector.method = method;
}
// 9: attribute "[attribute=value]"
else if(exec[9])
{
// selector properties
selector.type = 'filter';
selector.name = 'attribute';
selector.method = core.filter.attribute;
// attribute components
var attName = exec[10];
var attOperand = exec[11];
var attValue = exec[12];
var val = parseFloat(attValue);
// parse numeric values
if( ! isNaN(val) )// /<>/.test(attOperand)
{
attValue = val;
}
else
{
attValue = /[\*{}]/.test(attValue) ? Selector.makeRX(attValue, selector) : attValue;
}
// assign
selector.params = [null, attName, attOperand, attValue, selector.range, object.custom];
}
else
{
throw new TypeError('TypeError in Selectors.parse(): Unrecognised pattern "' +selector.pattern+ '"');
}
// --------------------------------------------------------------------------------
// assign selector, or throw error
//trace('TYPE:' + selector);
// finally, add selector
if(selector.method)
{
selectors.push(selector);
}
else
{
throw new TypeError('TypeError: Unrecognised selector "' +selector.pattern+ '" in ' +type+ 'Selector function');
}
}
// debug
//inspect(selectors, 'SELECTORS');
if(selectors.length == 0)
{
//throw new Error('Error: The selector expression "' +expression+ '" is not valid');
}
// return
return selectors;
},
/**
* Tests the selectors against the supplied items and returns matches
* @param selectors {Array} An array of Selector instances
* @param items {Array} An array of items to filter
* @param scope {Object} A valid scope reference. Valid types are Library, Document, Timeline, Layer, Frame
* @returns {Array} An array of elements, items, etc
*/
test:function(selectors, items, scope)
{
// exit early if no valid selectors
if(selectors.length === 0)
{
return [];
}
// debug
if(Selectors.debug)
{
inspect(selectors, 'Selectors');
}
// loop over all selectors
for each(var selector in selectors)
{
// store temporary items as we find and filter
var temp = [];
// if the task is find or combo: filter items as a group, with any extra processing taking place in the testing function
if(selector.type === 'find' || selector.type === 'combo')
{
temp = selector.filter(items, scope);
}
// otherwise: filter items by testing each item individually
else
{
var state;
for each(var item in items)
{
state = selector.test(item, scope);
if(state)
{
temp.push(item);
}
}
}
// update items with temp items
items = temp;
// exit early if 0 items
if(items.length == 0)
{
break;
}
}
// return
return items;
},
toString:function()
{
return '[class Selectors]';
}
}
// ------------------------------------------------------------------------------------------------------------------------
//
// ██████ ██████ ██
// ██ ██ ██
// ██ █████ ████ █████ ██ █████ █████ █████ █████
// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
// ██ ██ ██ ██ █████ ██ █████ █████ ██ █████
// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
// ██████ █████ ██ █████ ██ █████ █████ ████ █████
//
// ------------------------------------------------------------------------------------------------------------------------
// # Core Tests
Selectors.core =
{
// # Filter
filter:
{
/**
* Test an attribute of an object against a value or callback
* @param item {Object} The item to test
* @param name {String} The name of the attribute
* @param operand {String} The operand type. Acceptable string values are =, !=, ^=, $=, *=. Acceptable numeric values are =, !=, >, >=, <, <=
* @param value {String} The String value to test against
* @param value {Number} The Number value to test against
* @param range {Object} A range object with .min and .max values
* @param custom {Object} The Selectors.<type>.custom object which contains custom callbacks
* @returns {Boolean} True if the test passes
*/
attribute:function(item, name, operand, value, range, custom)
{
//trace('Testing attribute: ' + [item, name, operand, value, range, custom]);
// variables
var callback, prop;
// get a deep property if there are periods in the name
if(name.indexOf('.') !== -1)
{
prop = Utils.getDeepValue(item, name);
}
// otherwise...
else
{
// get a native property
if(name in item)
{
prop = item[name];
}
// grab a custom property using callbacks
else
{
callback = custom[name];
if( ! callback )
{
throw new ReferenceError('A callback for the custom attribute "' +name+ '" has not been registered');
}
prop = callback.call(this, item);
}
}
// no operand, just test for property
if(operand == '')
{
return callback ? prop : name in item;
}
// numeric operand (>, >=, <, <=)
if(typeof value === 'number' && range == undefined)
{
//trace('NUMERIC')
switch(operand)
{
case '=': return prop == value;
case '!=': return prop != value;
case '<': return prop < value;
case '<=': return prop <= value;
case '>': return prop > value;
case '>=': return prop >= value;
}
}
// range comparison (={min|max} converted to range object {min:n, max:m})
// NOTE: this does not handle mixed values, like 'star1' to 'star5'
if(range)
{
//trace('RANGE');
return prop >= range.min && prop <= range.max;
}
// the last two comparisons are string-based, so cast the property to a String
prop = String(prop);
// RegExp comparison (^=, $=, *=)
if(operand === '^=' || operand === '$=' || operand === '*=')
{
//trace('CONTAINS, STARTS OR ENDS WITH')
var rxStr = operand === '^='
? '^' + value
: operand === '$='
? value + '$'
: value;
var rx = new RegExp(rxStr)
return rx.test(prop);
}
// test for wildcards
if(value instanceof RegExp)
{
//trace('REGEXP')
switch(operand)
{
case '=': return value.test(prop);
case '!=': return ! value.test(prop);
default: return false;
}
}
// finally, string operand (=, !=)
switch(operand)
{
case '=': return prop === value;
case '!=': return prop !== value;
default: return false;
}
}
},
// # Math
math:
{
/**
* Returns items within a min and max range value
* @param {String} str A numeric value
* @param {Object} range A Range object with .min and .max values
* @returns {Boolean} true or false depending if the value was was within the range
*/
range:function(str, range)
{
var value = parseFloat(str);
return value >= range.min && value <= range.max;
/*
var matches = String(value).match(/([\d+\.])/);
if(matches)
{
value = parseFloat(matches[1]);
return value >= range.min && value <= range.max;
}
return false;
*/
}
},
// # Find
find:
{
/**
* Returns the first item of the supplied items
* @param {Array} items An Array of Items
* @returns {Item} A single Item
*/
first:function(items)
{
return [items.shift()];
},
/**
* Returns the last item of the supplied items
* @param {Array} items An Array of Items
* @returns {Item} A single Item
*/
last:function(items)
{
return [items.pop()];
},
/**
* Finds every even index of the supplied items
* @param {Item} parents An Array of folder parent items
* @returns {Array} An Array of items
*/
even:function(items)
{
return Selectors.core.combo.nth(items, 'even');
},
/**
* Finds every odd index of the supplied items
* @param {Item} parents An Array of folder parent items
* @returns {Array} An Array of items
*/
odd:function(items)
{
return Selectors.core.combo.nth(items, 'odd');
},
/**
* Finds a random selection of items from the supplied items
* @param {Item} parents An Array of folder parent items
* @param {Number} amount An amount from 0-1 which indicates the probability of a match
* @returns {Array} An Array of items
*/
random:function(items, amount)
{
amount = amount || 0.5;
var arr = [];
for each(var item in items)
{
if(Math.random() < amount)
{
arr.push(item);
}
}
return arr;
},
},
pseudo:
{
},
// # Combo
combo:
{
/**
* Returns the opposite value to that of the supplied expression
* @param {Array} items An Array of items
* @param {String} expression The CSS expression to negate
* @param {String} type The type of selection
* @returns {Array} An Array of items
*/
not:function(items, expression, type)
{
// create new selector(s) with supplied :not(expr) expression
var selectors = Selectors.parse(expression, type);
// negate all selectors
var selector;
for each(selector in selectors)
{
selector.keep = false;
}
// get the items with the new selecor
var newItems = Selectors.test(selectors, items, this);
// compare to items in
return newItems
},
//TODO contains() functionality - should this be custom per type, i.e. items, elements, frames?
/**
*
* @param selector
* @returns
*/
contains:function(items, expression, type)
{
throw new ReferenceError('The :contains() selector is not implemented yet');
return items;
},
has:function(items, expression, type)
{
throw new ReferenceError('The :has() selector is not implemented yet');
return items;
},
/**
* Randomly returns items according to a 0.0 - 1.0 theshold
* @param {Array} items An Array of items
* @param {String} expression An expression of the format 0.0 to 1.0
* @param {String} type Description
* @returns {Array} An Array of items
*/
random:function(items, expression, type)
{
var amount = parseFloat(expression);
return Selectors.core.find.random(items, amount);
},
/**
* Finds every n-th child of the supplied items
* @param {Item} items An Array of items
* @param {String} expression An expression of the format (event|odd|random), 3, 3n, 3n+3, 3n-3
* @returns {Array} An Array of items
*/
nth:function(items, expression, type)
{
// variables
var fn;
// parse expression
var matches = String(expression).match(/(odd|even|random)|(\d+)n?([\-+])?(\d+)?/);
if (matches != null)
{
// debug
//inspect(matches)
// matches
/*
0 1 2 3 4
odd odd
even even
random random
3 3
3n 3
3n+1 3 + 1
3n-1 3 - 1
*/
// even / odd / random
if(matches[1])
{
var fns =
{
odd: function(i){ return i % 2 == 0},
even: function(i){ return i % 2 == 1},
random: function(){ return Math.random() < 0.5 }
}
fn = fns[matches[1]];
}
// nth, nth repeated, nth repeated and offset
else if(matches[2])
{
// variables
var index = parseInt(matches[2]);
var operator = matches[3] == '-' ? -1 : 1;
var offset = matches[4] ? parseInt(matches[4]) * operator : 0;
// a single numeric match only
if(matches[0].indexOf('n') === -1)
{
var item = items[index - 1];
return [item];
}
// a multiple match plus modifiers
else
{
fn = function(i){ return (i + 1 - offset) % index === 0; }
}
}
}
// start matching
var arr = [];
for (var i = 0; i < items.length; i++)
{
if(fn(i))
{
var item = items[i];
if(item !== undefined)
{
arr.push(items[i]);
}
}
}
return arr;
},
}
}
// ------------------------------------------------------------------------------------------------------------------------
//
// ██████ ██ ██ ██████ ██
// ██ ██ ██ ██ ██
// ██ ██ █████ ████████ █████ █████ █████ ██ █████ █████ █████ █████
// █████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
// ██ ██ █████ ██ ██ ██ █████ ██ ██ ██ ██ █████ █████ ██ █████
// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
// ██████ ██ █████ ██ ██ ██ █████ ██ ██ ████ ██ █████ █████ ████ █████
//
// ------------------------------------------------------------------------------------------------------------------------
// # Element Tests
Selectors.element =
{
/**
* Registers a custom selector with the Selectors.element object
* @param {String} pattern The selector expression
* @param {Function} callback A custom funtion to test elements with
* @returns {Selectors} The original Selectors Object
*/
register:function(pattern, callback)
{
return Selectors.register(pattern, callback, 'element');
},
// # Filters
filter:
{
/**
*
* @param item {Element} An Element
* @param rx {RegExp} A regular expression to match against the item name
* @returns {Boolean} True if matched, false if failed
*/
name:function(item, rx, range)
{
return Selectors.item.filter.path(item, rx, range);
},
/**
*
* @param item {Element} An Element
* @param rx {RegExp} A regular expression to match against the item path
* @returns {Boolean} True if matched, false if failed
*/
path:function(item, rx, range)
{
if(item.libraryItem)
{
return Selectors.item.filter.path(item.libraryItem, rx, range);
}
else
{
return false;
}
},
/**
*
* @param item {Element} An Element
* @param type {String} A valid Item itemType
* @returns {Boolean} True if matched, false if failed
*/
type:function(item, type)
{
switch(item.elementType)
{
// --------------------------------------------------------------------------------
// instance: symbol, bitmap, embedded video, linked video, video, compiled clip
//TODO Add video
case 'instance':
// symbol: button, movieclip, graphic
if(item.symbolType)
{
if(type === 'symbol')
{
return true;
}
return type === 'instance' || item.symbolType.replace(/ /g, '') === type;
}
// instance
return type === 'instance' || item.instanceType.replace(/ /g, '') === type;
break;
// --------------------------------------------------------------------------------
// text: text, static, dynamic, input
case 'text':
if(type === 'text')
{
return true;
}
return item.textType.replace(/ /g, '') === type;
break;
// --------------------------------------------------------------------------------
// shape: primitive, group, shape
case 'shape':
if(item.isRectangleObject || item.isOvalObject)
{
return type === 'primitive';
}
if(item.isGroup)
{
return type === 'group';
}
return type === 'shape';
break;
}
return false;
},
/**
*
* @param item {Element} A library Item instance
* @param rx {RegExp} A regular expression to match against the item's full linkageClassName
* @returns {Boolean} True if matched, false if failed
*/
Package:function(item, rx)
{
return item.libraryItem && Selectors.item.filter.Package(item.libraryItem, rx);
},
/**
*
* @param item {Element} A library Item instance
* @param rx {RegExp} A regular expression to match against the Class component of the item'slinkageClassName
* @returns {Boolean} True if matched, false if failed
*/
Class:function(item, rx)
{
return item.libraryItem && Selectors.item.filter.Class(item.libraryItem, rx);
},
},
// # Find
find:
{
selected:function(items)
{
var selection = this.selection; // this refers to $dom
return items.filter(function(element) { return selection.indexOf(element) !== -1 } );
}
},
// # Psuedo
pseudo:
{
/**
*
* @param item
* @returns
*/
empty:function(element)
{
if(element.symbolType)
{
return Selectors.timeline.pseudo.empty(element.libraryItem.timeline);
}
return false;
},
/**
*
* @param element
* @returns
*/
animated:function(element)
{
if(element.symbolType)
{
return Selectors.timeline.pseudo.animated(element.libraryItem.timeline);
}
return false;
},
/**
*
* @param element
* @returns
*/
keyframed:function(element)
{
if(element.symbolType)