Repository: edenvidal/States Branch: master Commit: 22c0aab87ec6 Files: 81 Total size: 283.4 KB Directory structure: gitextract_mwlr0ef8/ ├── .gitignore ├── Plugin/ │ ├── Debug.xcconfig │ ├── LICENSE │ ├── README.md │ ├── Release.xcconfig │ ├── States/ │ │ ├── Info.plist │ │ ├── NSArray+HigherOrder.h │ │ ├── NSArray+HigherOrder.m │ │ ├── NSArray+Indexes.h │ │ ├── NSArray+Indexes.m │ │ ├── STArtboard.h │ │ ├── STColorFactory.h │ │ ├── STColorFactory.m │ │ ├── STCommand.h │ │ ├── STDocument.h │ │ ├── STHeaderView.h │ │ ├── STHeaderView.m │ │ ├── STLayer.h │ │ ├── STLayerState.h │ │ ├── STLayerState.m │ │ ├── STPage.h │ │ ├── STPlaceholderView.h │ │ ├── STPlaceholderView.m │ │ ├── STSketch.h │ │ ├── STSketch.m │ │ ├── STSketchPluginContext.h │ │ ├── STSketchPluginContext.m │ │ ├── STStateDescription.h │ │ ├── STStateDescription.m │ │ ├── STStatefulArtboard+Backend.h │ │ ├── STStatefulArtboard+Backend.m │ │ ├── STStatefulArtboard+Snapshots.h │ │ ├── STStatefulArtboard+Snapshots.m │ │ ├── STStatefulArtboard.h │ │ ├── STStatefulArtboard.m │ │ ├── STTableCellView.h │ │ ├── STTableCellView.m │ │ ├── STTableRowView.h │ │ ├── STTableRowView.m │ │ ├── STTableView.h │ │ ├── STTableView.m │ │ ├── STTextField.h │ │ ├── STTextField.m │ │ ├── STUpdateButton.h │ │ ├── STUpdateButton.m │ │ ├── STWindow.h │ │ ├── STWindow.m │ │ ├── StatesController+ContextMenu.h │ │ ├── StatesController+ContextMenu.m │ │ ├── StatesController+Decisions.h │ │ ├── StatesController+Decisions.m │ │ ├── StatesController+DragNDrop.h │ │ ├── StatesController+DragNDrop.m │ │ ├── StatesController+Naming.h │ │ ├── StatesController+Naming.m │ │ ├── StatesController.h │ │ ├── StatesController.m │ │ └── StatesWindow.xib │ ├── States.xcodeproj/ │ │ ├── project.pbxproj │ │ ├── project.xcworkspace/ │ │ │ └── contents.xcworkspacedata │ │ └── xcshareddata/ │ │ └── xcschemes/ │ │ ├── States for Beta.xcscheme │ │ └── States.xcscheme │ ├── Versioning.xcconfig │ ├── lib/ │ │ └── runtime.js │ ├── manifest.json │ ├── plugin.js │ └── vendor/ │ ├── Aspects.h │ └── Aspects.m ├── States.sketchplugin/ │ └── Contents/ │ ├── Resources/ │ │ └── States.bundle/ │ │ └── Contents/ │ │ ├── Info.plist │ │ ├── MacOS/ │ │ │ └── States │ │ ├── Resources/ │ │ │ ├── StatesWindow.nib │ │ │ └── dirty.tiff │ │ └── _CodeSignature/ │ │ └── CodeResources │ └── Sketch/ │ ├── lib/ │ │ └── runtime.js │ ├── manifest.json │ └── plugin.js ├── css/ │ ├── normalize.css │ ├── states.webflow.css │ └── webflow.css ├── index.html └── js/ └── webflow.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ States.sketchplugin.zip ================================================ FILE: Plugin/Debug.xcconfig ================================================ // Debug.xcconfig // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #include "Versioning.xcconfig" OTHER_LDFLAGS = $(inherited) -Wl,-source_version -Wl,${IEXP_SOURCE_VERSION} ================================================ FILE: Plugin/LICENSE ================================================ MIT License Copyright (c) 2016 Eden Vidal Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: Plugin/README.md ================================================ # States of the artboard — Sketch Plugin Create different states and switch between them easily. Just like layer comps for Sketch. - Define different positions and toggle visibility of your layers. - Create new states and update changes. - Create pages with new artboards from your states. - Since symbols are artboards, you can create states for them too. - And yes — The states are saved on your file. Boom. ![How it works](https://daks2k3a4ib2z.cloudfront.net/574f0289c3c4633629a7737b/5766c49dc26632fe609656f1_Animation3_03.gif) ================================================ FILE: Plugin/Release.xcconfig ================================================ // Release.xcconfig // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #include "Versioning.xcconfig" OTHER_LDFLAGS = $(inherited) -Wl,-source_version -Wl,${IEXP_SOURCE_VERSION} ================================================ FILE: Plugin/States/Info.plist ================================================ CFBundleDevelopmentRegion en CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName $(PRODUCT_NAME) CFBundlePackageType BNDL CFBundleShortVersionString 1.0.0 CFBundleSignature ???? CFBundleVersion 1 NSHumanReadableCopyright Copyright © 2016 Eden Vidal. All rights reserved. NSPrincipalClass ================================================ FILE: Plugin/States/NSArray+HigherOrder.h ================================================ // NSArray+HigherOrder.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. @import Foundation; @interface NSArray (HigherOrder) - (nonnull NSArray *)st_map: (nonnull id _Nonnull (^)(id _Nonnull obj))mapper; - (nonnull NSArray *)st_filter: (nonnull BOOL (^)(id _Nonnull obj))block; @end ================================================ FILE: Plugin/States/NSArray+HigherOrder.m ================================================ // NSArray+HigherOrder.m // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #import "NSArray+HigherOrder.h" @implementation NSArray (HigherOrder) - (NSArray *)st_map: (nonnull id _Nonnull (^)(id _Nonnull obj))mapper { NSMutableArray *result = [NSMutableArray arrayWithCapacity: self.count]; [self enumerateObjectsUsingBlock: ^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { [result addObject: mapper(obj)]; }]; return result; } - (NSArray *)st_filter: (BOOL (^)(id))block { NSMutableArray *new = [NSMutableArray array]; [self enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *stop) { if (block(obj)) [new addObject: obj]; }]; return new; } @end ================================================ FILE: Plugin/States/NSArray+Indexes.h ================================================ // NSArray+Indexes.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. @import Foundation; @interface NSArray (Indexes) - (nonnull NSIndexSet *)st_indexesOfObjects: (nonnull NSArray *)subarray; @end ================================================ FILE: Plugin/States/NSArray+Indexes.m ================================================ // NSArray+Indexes.m // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #import "NSArray+Indexes.h" @implementation NSArray (Indexes) - (nonnull NSIndexSet *)st_indexesOfObjects: (nonnull NSArray *)subarray { return [self indexesOfObjectsPassingTest: ^BOOL(id obj, NSUInteger idx, BOOL * stop) { return [subarray containsObject: obj]; }]; } @end ================================================ FILE: Plugin/States/STArtboard.h ================================================ // STArtboard.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. @import Foundation; @protocol STLayer; @protocol STArtboard @optional - (NSArray >*)children; - (void)setName: (NSString *)name; - (NSString *)name; - (instancetype)copy; @end ================================================ FILE: Plugin/States/STColorFactory.h ================================================ // STColorFactory.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. @import Cocoa; /// Keeps all of the custom colors for this project @interface STColorFactory : NSObject // Table View Colors + (NSColor *)selectedTableViewRowColor; + (NSColor *)selectedInactiveTableViewRowColor; + (NSColor *)mainTableViewRowColor; + (NSColor *)secondaryTableViewRowColor; + (NSColor *)tableViewBackgroundColor; + (NSColor *)tableViewCellTextRegularColor; + (NSColor *)tableViewCellTextSelectedColorWithAlpha: (CGFloat)alpha; + (NSColor *)tableViewCellTextInactiveSelectedColorWithAlpha: (CGFloat)alpha; // Header Colors + (NSColor *)headerViewBackgroundColor; + (NSColor *)headerViewBorderColor; // Placeholder Colors + (NSColor *)placeholderViewBackground; @end ================================================ FILE: Plugin/States/STColorFactory.m ================================================ // STColorFactory.m // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. // #import "STColorFactory.h" @implementation STColorFactory + (NSColor *)selectedTableViewRowColor { return [NSColor colorWithRed: 110.f/255.f green: 157.f/255.f blue: 228.f/255.f alpha: 1.0f]; } + (NSColor *)selectedInactiveTableViewRowColor { return [NSColor colorWithRed: 200.f/255.f green: 200.f/255.f blue: 200.f/255.f alpha: 1.0f]; } + (NSColor *)tableViewBackgroundColor { return [NSColor colorWithRed: 236.f/255.f green: 236.f/255.f blue: 236.f/255.f alpha: 1.0f]; } + (NSColor *)mainTableViewRowColor { return [NSColor colorWithRed: 240.f/255.f green: 240.f/255.f blue: 240.f/255.f alpha: 1.0f]; } + (NSColor *)secondaryTableViewRowColor { return [NSColor colorWithRed: 235.f/255.f green: 235.f/255.f blue: 235.f/255.f alpha: 1.0f]; } + (NSColor *)tableViewCellTextRegularColor { return [NSColor controlTextColor]; } + (NSColor *)tableViewCellTextSelectedColorWithAlpha: (CGFloat)alpha { return [NSColor colorWithWhite: 10 alpha: alpha]; } + (NSColor *)tableViewCellTextInactiveSelectedColorWithAlpha: (CGFloat)alpha { return [NSColor colorWithWhite: 5 alpha: alpha]; } + (NSColor *)headerViewBackgroundColor { return [NSColor colorWithRed: 243.f/255.f green: 243.f/255.f blue: 243.f/255.f alpha: 1.0f]; } + (NSColor *)headerViewBorderColor { return [NSColor colorWithRed: 184.f/255.f green: 184.f/255.f blue: 184.f/255.f alpha: 1.0f]; } + (NSColor *)placeholderViewBackground { return [NSColor colorWithRed: 236.f/255.f green: 236.f/255.f blue: 236.f/255.f alpha: 1.0f]; } @end ================================================ FILE: Plugin/States/STCommand.h ================================================ // STCommand.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. @import Foundation; #import "STLayer.h" @protocol STCommand @optional - (void)setValue: (id)value forKey: (id )key onLayer: (id )layer; - (id)valueForKey: (id )key onLayer: (id )layer; @end ================================================ FILE: Plugin/States/STDocument.h ================================================ // STDocument.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. @import Foundation; #import "STPage.h" @protocol STDocumentData - (void)addPage: (id )page; - (void)deselectAllLayers; @end @protocol STDocument @optional - (void)setCurrentPage: (id )page; - (id )currentPage; - (id)window; - (id )documentData; - (void)setSelectedLayers: (NSArray *)layers; @end ================================================ FILE: Plugin/States/STHeaderView.h ================================================ // STHeaderView.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. @import Cocoa; /// A header view with a custom background color @interface STHeaderView : NSView @end ================================================ FILE: Plugin/States/STHeaderView.m ================================================ // STHeaderView.m // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #import "STColorFactory.h" #import "STHeaderView.h" #define kHeaderViewBorderWidth (1.0f) @implementation STHeaderView - (void)awakeFromNib { self.wantsLayer = YES; } - (BOOL)wantsUpdateLayer { return YES; } - (void)updateLayer { // Setup a background self.layer.backgroundColor = [STColorFactory headerViewBackgroundColor].CGColor; // Draw a border at the buttom of the header CALayer *buttomBorder = [CALayer layer]; buttomBorder.borderColor = [STColorFactory headerViewBorderColor].CGColor; buttomBorder.borderWidth = kHeaderViewBorderWidth; buttomBorder.frame = CGRectMake(0, 0, CGRectGetWidth(self.frame), kHeaderViewBorderWidth); [self.layer addSublayer: buttomBorder]; } @end ================================================ FILE: Plugin/States/STLayer.h ================================================ // STLayer.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. @import Foundation; @protocol STAbsoluteRect; @protocol STLayer @optional - (BOOL)isVisible; - (void)setIsVisible: (BOOL)visible; - (id )absoluteRect; - (void)copyToLayer: (id )newParent beforeLayer: (id )sibling; @end @protocol STFrame @optional - (CGRect)rect; - (CGFloat)x; - (CGFloat)y; - (void)setX: (CGFloat)x; - (void)setY: (CGFloat)y; @end @protocol STAbsoluteRect @optional - (CGRect)absoluteRect; - (void)setX: (CGFloat)x; - (void)setY: (CGFloat)y; @end ================================================ FILE: Plugin/States/STLayerState.h ================================================ // STLayerState.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. @import Foundation; @protocol STLayer; /// Incapsulates a state of a single layer: its frame and visibility status @interface STLayerState : NSObject @property (readonly) NSRect frame; @property (readonly) BOOL visible; - (instancetype)initWithFrame: (NSRect)aFrame visibilityStatus: (BOOL)visible; + (instancetype)stateWithFrame: (NSRect)aFrame visibilityStatus: (BOOL)visible; - (NSDictionary *)dictionaryRepresentation; - (instancetype)initWithDictionary: (NSDictionary *)dictionary; @end /// Applies the given layer state to the given layer @interface STLayerStateApplier : NSObject + (void)apply: (STLayerState *)state toLayer: (id )layer; @end /// Returns the current layer's state @interface STLayerStateFetcher : NSObject + (STLayerState *)fetchStateFromLayer: (id )layer; @end /// Verifies that the given layer conforms to the given state @interface STLayerStateExaminer : NSObject + (BOOL)layer: (id )layer conformsToState: (STLayerState *)state; @end ================================================ FILE: Plugin/States/STLayerState.m ================================================ // STLayerState.m // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #import "STLayer.h" #import "STLayerState.h" @implementation STLayerState - (instancetype)initWithFrame: (NSRect)aFrame visibilityStatus: (BOOL)visible { if ((self = [super init])) { _frame = aFrame; _visible = visible; } return self; } + (instancetype)stateWithFrame: (NSRect)aFrame visibilityStatus: (BOOL)visible { return [[[self class] alloc] initWithFrame: aFrame visibilityStatus: visible]; } - (NSDictionary *)dictionaryRepresentation { return @{ @"frame" : NSStringFromRect(_frame), @"visible" : @(_visible) }; } - (instancetype)initWithDictionary: (NSDictionary *)dictionary { NSParameterAssert(dictionary[@"frame"]); NSParameterAssert(dictionary[@"visible"]); return [self initWithFrame: NSRectFromString(dictionary[@"frame"]) visibilityStatus: [dictionary[@"visible"] boolValue]]; } - (BOOL)isEqual: (id)object { typeof(self) another = object; if (![another isKindOfClass: [self class]]) { return NO; } if (!NSEqualRects(_frame, another.frame)) { return NO; } if (_visible != another.visible) { return NO; } return YES; } - (NSUInteger)hash { return NSStringFromRect(_frame).hash + @(_visible).hash; } - (NSString *)description { return [NSString stringWithFormat: @"<%@: %p> (frame = %@, visible = %@)", NSStringFromClass([self class]), (void *)self, NSStringFromRect(_frame), _visible ? @"YES" : @"NO"]; } @end @implementation STLayerStateApplier + (void)apply: (STLayerState *)state toLayer: (id )layer { layer.isVisible = state.visible; id frame = [layer performSelector: @selector(frame)]; frame.x = state.frame.origin.x; frame.y = state.frame.origin.y; } @end @implementation STLayerStateFetcher : NSObject + (STLayerState *)fetchStateFromLayer: (id )layer { id frameObject = [layer performSelector: @selector(frame)]; return [[STLayerState alloc] initWithFrame: NSRectFromCGRect(frameObject.rect) visibilityStatus: layer.isVisible]; } @end @implementation STLayerStateExaminer : NSObject + (BOOL)layer: (id )layer conformsToState: (STLayerState *)state { id frameObject = [layer performSelector: @selector(frame)]; NSRect layerRect = NSRectFromCGRect(frameObject.rect); if (layer.isVisible != state.visible) { return NO; } if (!NSEqualPoints(layerRect.origin, state.frame.origin)) { return NO; } return YES; } @end ================================================ FILE: Plugin/States/STPage.h ================================================ // STPage.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. @import Foundation; #import "STArtboard.h" @protocol STPage @optional + (instancetype)page; - (instancetype)copy; - (id )currentArtboard; - (NSArray *)artboards; - (void)enumerateLayersWithOptions: (int)options block: (void(^)(id layer))block; - (void)addLayers: (NSArray *)layers; - (void)removeLayer: (id )layer; - (void)selectLayers: (NSArray *)layers; - (void)setName: (NSString *)name; - (NSString *)name; - (void)setPageDelegate: (id)pageDelegate; - (id)pageDelegate; - (void)setGrid: (id)grid; - (id)grid; - (void)setLayout: (id)layout; - (id)layout; - (void)setScrollOrigin: (CGPoint)scrollOrigin; - (CGPoint)scrollOrigin; - (void)setZoomValue: (CGFloat)zoomValue; - (CGFloat)zoomValue; @end ================================================ FILE: Plugin/States/STPlaceholderView.h ================================================ // STPlaceholderView.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. @import Cocoa; /// A simple placeholder view that covers the main table view when there's no artboard selected @interface STPlaceholderView : NSView @end ================================================ FILE: Plugin/States/STPlaceholderView.m ================================================ // STPlaceholderView.m // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #import "STColorFactory.h" #import "STPlaceholderView.h" @implementation STPlaceholderView - (void)awakeFromNib { self.wantsLayer = YES; } - (BOOL)wantsUpdateLayer { return YES; } - (void)updateLayer { self.layer.backgroundColor = [STColorFactory placeholderViewBackground].CGColor; } @end ================================================ FILE: Plugin/States/STSketch.h ================================================ // STSketch.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. @import Cocoa; #import "STStateDescription.h" #import "STDocument.h" #import "STSketchPluginContext.h" @protocol SketchNotificationsListener @required - (void)currentArtboardDidChange; - (void)currentArtboardUnselected; - (void)currentDocumentUpdated; @end /// The bridge between Sketch and our plugin. Provides info about current document as well /// as various notifications available for SketchNotificationsListener @interface STSketch : NSObject /// Information about the curent document: the document itself, current page and artboard + (id )currentDocument; + (id )currentPage; + (id )currentArtboard; /// Use this observer to subscribe to various Sketch notifications. See SketchNotificationsListener /// for more details + (instancetype)notificationObserver; - (void)addListener: (id )listener; /// We must save a plugin context in order to perform some layer modifications (i.e. use plugin command) /// IMPORTANT: You must set this context via -setPluginContext: method before calling any other methods /// of this class. + (void)setPluginContextDictionary: (NSDictionary *)contextDictionary; + (STSketchPluginContext *)pluginContext; /// Toggles the plugin's menu item's titles between "Show States" and "Hide States" + (void)toggleStatesPluginName; @end ================================================ FILE: Plugin/States/STSketch.m ================================================ // STSketch.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #import #import "Aspects.h" #import "STSketch.h" #import "STStatefulArtboard.h" @interface STSketch() @property (strong) NSHashTable *listeners; @end @implementation STSketch + (instancetype)notificationObserver { static STSketch *observer = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ observer = [STSketch new]; observer.listeners = [NSHashTable weakObjectsHashTable]; [observer injectIntoMSDocument]; }); return observer; } - (void)addListener: (id)listener { [_listeners addObject: listener]; } #pragma mark - + (id )currentDocument { return [NSClassFromString(@"MSDocument") currentDocument]; } + (id )currentPage { return [[self currentDocument] currentPage]; } + (id )currentArtboard { id raw = [[self currentPage] currentArtboard]; if (!raw) { return nil; } return [[STStatefulArtboard alloc] initWithArtboard: raw context: [self pluginContext]]; } #pragma mark - + (void)setPluginContextDictionary: (NSDictionary *)contextDictionary; { STSketchPluginContext *context = [[STSketchPluginContext alloc] initWithData: contextDictionary]; objc_setAssociatedObject(self, @selector(pluginContext), context, OBJC_ASSOCIATION_RETAIN); } + (instancetype)pluginContext { id context = objc_getAssociatedObject(self, @selector(pluginContext)); NSAssert(context != nil, @"You must set pluginContext via [%@ setPluginContext:] method before calling any other methods of this class", [self class]); return context; } #pragma mark - + (void)toggleStatesPluginName { NSMenu *pluginsMenu = [[NSApp menu] itemWithTitle: @"Plugins"].submenu; NSMenuItem *currentStatesItem = nil; if ((currentStatesItem = [pluginsMenu itemWithTitle: @"Show States"])) { currentStatesItem.title = @"Hide States"; } else if ((currentStatesItem = [pluginsMenu itemWithTitle: @"Hide States"])) { currentStatesItem.title = @"Show States"; } else { NSAssert(currentStatesItem, @"Could not find States plugin menu item inside Plugins menu"); } } #pragma mark - /// Inject ourselves into Sketch internals to receive notifications about artboard selection /// and document changes - (void)injectIntoMSDocument { Class MSDocument = NSClassFromString(@"MSDocument"); Class _MSLayer = NSClassFromString(@"_MSLayer"); Class MSPage = NSClassFromString(@"MSPage"); Class _MSImmutableLayer = NSClassFromString(@"_MSImmutableLayer"); [[NSNotificationCenter defaultCenter] addObserverForName: NSWindowWillCloseNotification object: [[STSketch currentDocument] window] queue: [NSOperationQueue mainQueue] usingBlock: ^(NSNotification * _Nonnull note) { for (id listener in [_listeners allObjects]) { [listener currentArtboardUnselected]; } }]; SEL currentArtboardDidChangeSelector = NSSelectorFromString(@"currentArtboardDidChange"); [MSDocument aspect_hookSelector: currentArtboardDidChangeSelector withOptions: AspectPositionAfter usingBlock: ^(id aspectInfo) { NSAssert(aspectInfo.instance == [STSketch currentDocument], @"Unexpected artboard selection update from a secondary document"); for (id listener in [_listeners allObjects]) { [listener currentArtboardDidChange]; } } error: NULL]; [MSDocument aspect_hookSelector: @selector(windowDidBecomeKey:) withOptions: AspectPositionAfter usingBlock: ^(id aspectInfo) { // Wait until the next run loop iteration to let Sketch switch to a new document dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ for (id listener in [_listeners allObjects]) { [listener currentArtboardDidChange]; } }); } error: NULL]; /// XXX SEL setCurrentArtboard = NSSelectorFromString(@"setCurrentArtboard:"); [MSPage aspect_hookSelector: setCurrentArtboard withOptions: AspectPositionAfter usingBlock: ^(id aspectInfo) { id artboard = [[aspectInfo arguments] firstObject]; for (id listener in [_listeners allObjects]) { if (!artboard) { [listener currentArtboardUnselected]; } else { [listener currentArtboardDidChange]; } } } error: NULL]; Class MSDocumentData = NSClassFromString(@"MSDocumentData"); SEL changeSelectionTo = NSSelectorFromString(@"changeSelectionTo:"); [MSDocumentData aspect_hookSelector: changeSelectionTo withOptions: AspectPositionAfter usingBlock: ^(id aspectInfo) { NSArray *selection = [[aspectInfo arguments] firstObject]; if (![selection isKindOfClass: [NSArray class]]) { return; } for (id listener in [_listeners allObjects]) { if (selection.count != 0) { [listener currentArtboardDidChange]; } } } error: NULL]; /// XXX void (^documentUpdateHandler)(void) = ^(void) { for (id listener in [_listeners allObjects]) { [listener currentDocumentUpdated]; } }; // XXX SEL layerPositionPossiblyChanged = NSSelectorFromString(@"layerPositionPossiblyChanged"); [MSDocument aspect_hookSelector: layerPositionPossiblyChanged withOptions: AspectPositionAfter usingBlock: ^(id aspectInfo) { id doc = aspectInfo.instance; if ([[doc currentPage] currentArtboard] == [[STSketch currentPage] currentArtboard]) { documentUpdateHandler(); } } error: NULL]; // XXX [MSDocument aspect_hookSelector: NSSelectorFromString(@"undoAction:") withOptions: AspectPositionAfter usingBlock: ^(id aspectInfo) { id doc = aspectInfo.instance; if ([[doc currentPage] currentArtboard] == [[STSketch currentPage] currentArtboard]) { documentUpdateHandler(); } } error: NULL]; /// XXX SEL setIsVisible = NSSelectorFromString(@"setIsVisible:"); [_MSImmutableLayer aspect_hookSelector: setIsVisible withOptions: AspectPositionAfter usingBlock: ^(id aspectInfo) { documentUpdateHandler(); } error: NULL]; [_MSLayer aspect_hookSelector: setIsVisible withOptions: AspectPositionAfter usingBlock: ^(id aspectInfo) { documentUpdateHandler(); } error: NULL]; } @end ================================================ FILE: Plugin/States/STSketchPluginContext.h ================================================ // SketchPluginContext.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. @import Foundation; #import "STDocument.h" #import "STCommand.h" /// Encapsulate a Sketch plugin context dictionary @interface STSketchPluginContext : NSObject @property (readonly, strong) id pluginBundle; @property (readonly, strong) id document; @property (readonly, strong) id command; - (instancetype)initWithData: (NSDictionary *)data; @end ================================================ FILE: Plugin/States/STSketchPluginContext.m ================================================ // SketchPluginContext.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #import "STSketchPluginContext.h" @interface STSketchPluginContext() @property (readwrite, strong) id pluginBundle; @property (readwrite, strong) id document; @property (readwrite, strong) id command; @end @implementation STSketchPluginContext - (instancetype)initWithData: (NSDictionary *)data { if ((self = [super init])) { _pluginBundle = data[@"plugin"]; _document = data[@"document"]; _command = data[@"command"]; } return self; } @end ================================================ FILE: Plugin/States/STStateDescription.h ================================================ // STStateDescription.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. @import Foundation; /// Represents a State model. Each state has a title and an unique identifier. @interface STStateDescription : NSObject @property (readonly, copy) NSString *title; @property (readonly, copy) NSUUID *UUID; /// Returns a new state description with the given title and random UUID - (instancetype)initWithTitle: (NSString *)title; /// Returns a new state description from the given dictionary. /// Expected keys: "title" and "UUID". - (instancetype)initWithDictionary: (NSDictionary *)dictionaryRepresentation; /// Returns a copy of the current state with the same UUID but different title. You're supposed /// to replace all copies of the old state with the new one. - (instancetype)stateByAlteringTitle: (NSString *)title; /// Returns a new state with random UUID and title equal to the current state's title with " Copy" suffix - (instancetype)duplicate; /// Returns a dictionary representation of this state model - (NSDictionary *)dictionaryRepresentation; @end ================================================ FILE: Plugin/States/STStateDescription.m ================================================ // STStateDescription.m // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #import "STStateDescription.h" @interface STStateDescription() @property (readwrite, copy) NSString *title; @property (readwrite, copy) NSUUID *UUID; @end @implementation STStateDescription - (instancetype)initWithTitle: (NSString *)title { if ((self = [super init])) { self.UUID = [NSUUID UUID]; self.title = title; } return self; } - (instancetype)initWithTitle: (NSString *)title UUID: (NSUUID *)UUID { if ((self = [self initWithTitle: title])) { self.UUID = UUID; } return self; } - (instancetype)initWithDictionary: (NSDictionary *)dictionaryRepresentation { NSParameterAssert(dictionaryRepresentation[@"title"] != nil); NSParameterAssert(dictionaryRepresentation[@"UUID"] != nil); NSString *title = dictionaryRepresentation[@"title"]; NSUUID *UUID = [[NSUUID alloc] initWithUUIDString: dictionaryRepresentation[@"UUID"]]; return [self initWithTitle: title UUID: UUID]; } - (NSDictionary *)dictionaryRepresentation { return @{ @"title": self.title, @"UUID" : self.UUID.UUIDString }; } - (instancetype)stateByAlteringTitle: (NSString *)title { STStateDescription *newState = [[STStateDescription alloc] initWithTitle: title]; newState.UUID = self.UUID; return newState; } - (instancetype)duplicate { return [[STStateDescription alloc] initWithTitle: self.title]; } - (BOOL)isEqual: (id)object { typeof(self) another = object; if (![another isKindOfClass: [self class]]) { return NO; } if (![another.UUID isEqual: self.UUID]) { return NO; } if (![another.title isEqualToString: self.title]) { return NO; } return YES; } - (NSUInteger)hash { return self.UUID.hash + self.title.hash; } - (NSString *)description { return [NSString stringWithFormat: @"<%@: %p> (UUID = %@, title = \"%@\" @ %p)", NSStringFromClass([self class]), (void *)self, self.UUID.UUIDString, self.title, (void *)self.title]; } @end ================================================ FILE: Plugin/States/STStatefulArtboard+Backend.h ================================================ // STStatefulArtboard+Backend.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #import "STStatefulArtboard.h" /// STStatefulArtboard extension that allows to save data inside Sketch metadata @interface STStatefulArtboard (Backend) - (nonnull NSArray *)artboardStatesData; - (void)setArtboardStatesData: (nonnull NSArray *)newData; - (nonnull NSDictionary *)artboardCurrentStateData; - (void)setArtboardCurrentStateData: (nonnull NSDictionary *)newData; - (nonnull NSDictionary *)metadataForLayer: (nonnull id )layer; - (void)setMedatada: (nonnull NSDictionary *)newMetadata forLayer: (nonnull id )layer; - (nonnull NSDictionary *)artboardDefaultStateData; - (void)setArtboardDefaultStateData: (nonnull NSDictionary *)newData; @end ================================================ FILE: Plugin/States/STStatefulArtboard+Backend.m ================================================ // STStatefulArtboard+Backend.m // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #import "STStatefulArtboard+Backend.h" static NSString const *const kSTStatefulArtboardStatesKey = @"x-states-states"; static NSString const *const kSTStatefulArtboardStateValuesKey = @"x-states-state-values"; static NSString const *const kSTStatefulArtboardCurrentStateKey = @"x-states-current-state"; static NSString const *const kSTStatefulArtboardDefaultStateKey = @"x-states-default-state"; @implementation STStatefulArtboard (Backend) - (NSArray *)artboardStatesData { return [[self.context command] valueForKey: kSTStatefulArtboardStatesKey onLayer: _internal] ?: @[]; } - (void)setArtboardStatesData: (NSArray *)newData { [[self.context command] setValue: newData forKey: kSTStatefulArtboardStatesKey onLayer: _internal]; } - (NSDictionary *)artboardCurrentStateData { return [[self.context command] valueForKey: kSTStatefulArtboardCurrentStateKey onLayer: _internal] ?: @{}; } - (void)setArtboardCurrentStateData: (NSDictionary *)newData { [[self.context command] setValue: newData forKey: kSTStatefulArtboardCurrentStateKey onLayer: _internal]; } - (NSDictionary *)metadataForLayer: (id )layer { return [[self.context command] valueForKey: kSTStatefulArtboardStateValuesKey onLayer: layer] ?: @{}; } - (void)setMedatada: (NSDictionary *)newMetadata forLayer: (id )layer { [[self.context command] setValue: newMetadata forKey: kSTStatefulArtboardStateValuesKey onLayer: layer]; } - (nonnull NSDictionary *)artboardDefaultStateData { return [[self.context command] valueForKey: kSTStatefulArtboardDefaultStateKey onLayer: _internal] ?: @{}; } - (void)setArtboardDefaultStateData: (nonnull NSDictionary *)newData { [[self.context command] setValue: newData forKey: kSTStatefulArtboardDefaultStateKey onLayer: _internal]; } @end ================================================ FILE: Plugin/States/STStatefulArtboard+Snapshots.h ================================================ // STStatefulArtboard+Snapshots.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #import "STStatefulArtboard.h" @interface STStatefulArtboard (Snapshots) /// Returns a new artboard reflecting the given state. All states metadata will be lost (i.e. it /// will be "clean" snapshot) - (id )snapshotForState: (STStateDescription *)state; @end ================================================ FILE: Plugin/States/STStatefulArtboard+Snapshots.m ================================================ // STStatefulArtboard+Snapshots.m // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #import "STLayerState.h" #import "NSArray+HigherOrder.h" #import "STStatefulArtboard+Backend.h" #import "STStatefulArtboard+Snapshots.h" @implementation STStatefulArtboard (Snapshots) - (id )snapshotForState: (STStateDescription *)state { NSParameterAssert([self.allStates containsObject: state]); id snapshotInternal = [_internal copy]; snapshotInternal.name = state.title; STStatefulArtboard *snapshot = [[STStatefulArtboard alloc] initWithArtboard: snapshotInternal context: self.context]; [snapshot applyState: state]; [snapshot removeAllStates]; return snapshotInternal; } @end ================================================ FILE: Plugin/States/STStatefulArtboard.h ================================================ // StatefulArtboard.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. @import Foundation; #import "STStateDescription.h" #import "STSketchPluginContext.h" #import "STArtboard.h" /// A wrapper around Sketch's artboard which provides methods for manipulating its state @interface STStatefulArtboard : NSObject { @protected id _internal; } @property (readonly, strong) STSketchPluginContext *context; @property (readonly, strong) NSArray *allStates; @property (readonly, strong) STStateDescription *currentState; @property (readonly, strong) STStateDescription *defaultState; - (instancetype)initWithArtboard: (id )artboard context: (STSketchPluginContext *)context; /// Verifies that all of this artboard's child layers conforms to the given state model - (BOOL)conformsToState: (STStateDescription *)state; /// Restore artboard state from `state` - (void)applyState: (STStateDescription *)state; /// Save current artboard state - (void)updateCurrentState; /// Inserts a new state model into this artboard's metadata. This new state model will represent /// the current state of the artboard - (void)insertNewState: (STStateDescription *)newState; /// Rewrites all child layers attribites so that the `destination` state becomes equal to the `source` one - (void)copyState: (STStateDescription *)source toState: (STStateDescription *)destination; /// Update the given state's name in this artboard's metadata - (STStateDescription *)updateName: (NSString *)newName forState: (STStateDescription *)existingState; /// Changes the order of the states in this artboard. A passed array must include all of the states /// of this artboard and nothing else - (void)reorderStates: (NSArray *)allStatesInNewOrder; /// Completely removes the given state from this artboard - (void)removeState: (STStateDescription *)stateToRemove; /// Wipes all of the states - (void)removeAllStates; /// WARNING: you're not suppposed to call this method. It's here just so -[StatesContoller createNewState:] /// may call it and workaround a major performance issue with applying states on really big artboards. /// Eventually this method will go away. - (void)setCurrentState: (STStateDescription *)currentState; @end ================================================ FILE: Plugin/States/STStatefulArtboard.m ================================================ // StatefulArtboard.m // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #import "STStatefulArtboard.h" #import "STStatefulArtboard+Backend.h" #import "STLayerState.h" #import "NSArray+HigherOrder.h" #define kArtboardDefaultStateTitle @"Initial State" @implementation STStatefulArtboard - (instancetype)initWithArtboard: (id )artboard context: (STSketchPluginContext *)context { NSParameterAssert(artboard != nil); NSParameterAssert(context != nil); if ((self = [super init])) { _internal = artboard; _context = context; [self createDefaultStateIfNeeded]; } return self; } - (void)createDefaultStateIfNeeded { if (self.allStates.count > 0) { // Backwards compatibility if (!self.defaultState) { [self setDefaultState: self.allStates.firstObject]; } } else { STStateDescription *defaultState = [[STStateDescription alloc] initWithTitle: kArtboardDefaultStateTitle]; [self insertNewState: defaultState]; [self setCurrentState: defaultState]; [self setDefaultState: defaultState]; } } #pragma mark - STLayer - (NSArray > *)children { return [[_internal children] st_filter: ^BOOL(id child) { return [child class] != NSClassFromString(@"MSArtboardGroup"); }]; } #pragma mark - Actions - (BOOL)conformsToState: (STStateDescription *)state { if (![self.allStates containsObject: state]) { return NO; } __block BOOL result = YES; [[self children] enumerateObjectsUsingBlock: ^(id layer, NSUInteger idx, BOOL *stop) { NSDictionary *metadata = [self metadataForLayer: layer][state.UUID.UUIDString]; if (metadata.count == 0) { result = NO; *stop = YES; return; } STLayerState *layerState = [[STLayerState alloc] initWithDictionary: metadata]; if (!layerState || ![STLayerStateExaminer layer: layer conformsToState: layerState]) { result = NO; *stop = YES; } }]; return result; } - (void)removeAllStates { [self setArtboardStatesData: @[]]; [self setArtboardCurrentStateData: @{}]; [self setArtboardDefaultStateData: @{}]; [[self children] enumerateObjectsUsingBlock: ^(id layer, NSUInteger idx, BOOL *stop) { [self setMedatada: @{} forLayer: layer]; }]; // Re-create the initial state [self createDefaultStateIfNeeded]; } - (void)removeState: (STStateDescription *)stateToRemove { NSParameterAssert(stateToRemove != nil); if ([stateToRemove isEqual: self.currentState]) { NSInteger idx = [self.allStates indexOfObject: self.currentState]; NSInteger previousStateIdx = idx - 1; NSInteger nextStateIdx = idx + 1; if (previousStateIdx >= 0) { [self applyState: self.allStates[previousStateIdx]]; } else if (nextStateIdx < self.allStates.count) { [self applyState: self.allStates[nextStateIdx]]; } else { [self setArtboardCurrentStateData: @{}]; } } // 1) Remove from artboard state descriptions NSArray *statesToKeep = [[self artboardStatesData] st_filter: ^BOOL(NSDictionary *item) { return [item isNotEqualTo: stateToRemove.dictionaryRepresentation]; }]; [self setArtboardStatesData: statesToKeep]; // 2) Remove this state's metadata from layers [[self children] enumerateObjectsUsingBlock: ^(id layer, NSUInteger idx, BOOL *stop) { NSDictionary *metadata = [self metadataForLayer: layer]; NSArray *keysToKeep = [metadata.allKeys st_filter: ^BOOL(NSString *key) { return [key isNotEqualTo: stateToRemove.UUID.UUIDString]; }]; [self setMedatada: [metadata dictionaryWithValuesForKeys: keysToKeep] forLayer: layer]; }]; } - (void)applyState: (STStateDescription *)state { NSParameterAssert([self.allStates containsObject: state]); [[self children] enumerateObjectsUsingBlock: ^(id layer, NSUInteger idx, BOOL *stop) { NSDictionary *metadata = [self metadataForLayer: layer][state.UUID.UUIDString]; if (metadata.count == 0) { return; } STLayerState *layerState = [[STLayerState alloc] initWithDictionary: metadata]; NSAssert(layerState != nil, @"Requested state values are missing from layer's metadata"); [STLayerStateApplier apply: layerState toLayer: layer]; }]; self.currentState = state; } - (void)updateCurrentState { STStateDescription *state = self.currentState; NSParameterAssert(self.currentState != nil); [[self children] enumerateObjectsUsingBlock: ^(id layer, NSUInteger idx, BOOL *stop) { NSMutableDictionary *newMetadata = [[self metadataForLayer: layer] mutableCopy]; STLayerState *layerState = [STLayerStateFetcher fetchStateFromLayer: layer]; newMetadata[state.UUID.UUIDString] = [layerState dictionaryRepresentation]; [self setMedatada: newMetadata forLayer: layer]; }]; } - (void)copyState: (STStateDescription *)source toState: (STStateDescription *)destination { NSParameterAssert([self.allStates containsObject: source]); NSParameterAssert([self.allStates containsObject: destination]); // Copy all of the child layers metadata from `source` state to `destination` [[self children] enumerateObjectsUsingBlock: ^(id layer, NSUInteger idx, BOOL *stop) { NSMutableDictionary *newMetadata = [[self metadataForLayer: layer] mutableCopy]; NSAssert(newMetadata[source.UUID.UUIDString], @"The source state metadata doesn't exists on layer %@", layer); newMetadata[destination.UUID.UUIDString] = newMetadata[source.UUID.UUIDString]; [self setMedatada: newMetadata forLayer: layer]; }]; } - (void)insertNewState: (STStateDescription *)newState { NSParameterAssert(![self.allStates containsObject: newState]); // 1) insert this new state into the artboard's registry NSArray *oldRawStates = [self artboardStatesData]; [self setArtboardStatesData: [oldRawStates arrayByAddingObject: newState.dictionaryRepresentation]]; // 2) update all child layer with the new state: it will be a current layer snapshot [[self children] enumerateObjectsUsingBlock: ^(id layer, NSUInteger idx, BOOL *stop) { // TODO: this is the same code as in -updateCurrentState (just replace state <-> newState) NSMutableDictionary *newMetadata = [[self metadataForLayer: layer] mutableCopy]; STLayerState *layerState = [STLayerStateFetcher fetchStateFromLayer: layer]; newMetadata[newState.UUID.UUIDString] = [layerState dictionaryRepresentation]; [self setMedatada: newMetadata forLayer: layer]; }]; if (!self.currentState) { [self setCurrentState: newState]; } } - (STStateDescription *)updateName: (NSString *)newName forState: (STStateDescription *)oldState { NSParameterAssert([self.allStates containsObject: oldState]); STStateDescription *newState = [oldState stateByAlteringTitle: newName]; NSMutableArray *stateRegistry = [[self artboardStatesData] mutableCopy]; NSUInteger idx = [stateRegistry indexOfObject: oldState.dictionaryRepresentation]; NSAssert(idx != NSNotFound, @"Could not find the given state"); // Modify a states registry [stateRegistry replaceObjectAtIndex: idx withObject: newState.dictionaryRepresentation]; [self setArtboardStatesData: stateRegistry]; // What if we rename the default state? if ([oldState isEqual: self.defaultState]) { [self updateDefaultState: newState]; } // Also update the current state if needed if ([oldState isEqual: self.currentState]) { [self setCurrentState: newState]; } return newState; } - (void)reorderStates: (NSArray *)allStatesInNewOrder { NSAssert([[NSSet setWithArray: self.allStates] isEqualToSet: [NSSet setWithArray: allStatesInNewOrder]], @"Invalid argument"); [self setAllStates: allStatesInNewOrder]; } #pragma mark - Artboard State Metadata - (NSArray *)allStates { return [[self artboardStatesData] st_map: ^STStateDescription *(NSDictionary *model) { return [[STStateDescription alloc] initWithDictionary: model]; }]; } - (STStateDescription *)currentState { NSDictionary *currentStateData = [self artboardCurrentStateData]; if (currentStateData.count == 0) { return nil; } return [[STStateDescription alloc] initWithDictionary: currentStateData]; } - (STStateDescription *)defaultState { NSDictionary *defaultStateDictionary = [self artboardDefaultStateData]; if (defaultStateDictionary.count == 0) { return nil; } return [[STStateDescription alloc] initWithDictionary: defaultStateDictionary]; } #pragma mark - Internal Metadata - (void)setAllStates: (NSArray *)allStates { NSArray *rawStates = [allStates st_map: ^NSDictionary *(STStateDescription *state) { return [state dictionaryRepresentation]; }]; [self setArtboardStatesData: rawStates]; } - (void)setCurrentState: (STStateDescription *)newCurrentState { NSParameterAssert([self.allStates containsObject: newCurrentState]); NSDictionary *state = [newCurrentState dictionaryRepresentation]; [self setArtboardCurrentStateData: state]; } - (void)setDefaultState: (STStateDescription *)defaultState { NSParameterAssert(self.defaultState == nil); NSDictionary *stateDictionary = [defaultState dictionaryRepresentation]; [self setArtboardDefaultStateData: stateDictionary]; } - (void)updateDefaultState: (STStateDescription *)defaultState { NSDictionary *stateDictionary = [defaultState dictionaryRepresentation]; [self setArtboardDefaultStateData: stateDictionary]; } @end ================================================ FILE: Plugin/States/STTableCellView.h ================================================ // STTableCellView.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. @import Cocoa; #import "STUpdateButton.h" @class STTableCellView; @protocol STTableCellViewDelegate @required - (BOOL)cellViewRepresentsCurrentItem: (STTableCellView *)cellView; - (BOOL)isSingleRowSelected; @end /// A cell view that sets custom text field colors depending on whether it represents the current /// state model or not @interface STTableCellView : NSTableCellView @property (weak) id delegate; @property (weak) IBOutlet STUpdateButton *updateButton; @end ================================================ FILE: Plugin/States/STTableCellView.m ================================================ // STTableCellView.m // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #import "STColorFactory.h" #import "STTableCellView.h" @implementation STTableCellView - (void)setBackgroundStyle: (NSBackgroundStyle)backgroundStyle { [super setBackgroundStyle: backgroundStyle]; if (backgroundStyle == NSBackgroundStyleLight) { self.textField.textColor = [STColorFactory tableViewCellTextRegularColor]; } else { BOOL singleSelection = [self.delegate isSingleRowSelected]; if (singleSelection || [self.delegate cellViewRepresentsCurrentItem: self]) { self.textField.textColor = [STColorFactory tableViewCellTextSelectedColorWithAlpha: 1.0f]; } else { self.textField.textColor = [STColorFactory tableViewCellTextSelectedColorWithAlpha: 0.5f]; } } } @end ================================================ FILE: Plugin/States/STTableRowView.h ================================================ // STTableRowView.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. @import Cocoa; /// A row view that draws custom background and selection rectangles @interface STTableRowView : NSTableRowView @property (readonly, weak) NSTableView *tableView; - (instancetype)initWithTableView: (NSTableView *)containingTableView; @end ================================================ FILE: Plugin/States/STTableRowView.m ================================================ // STTableRowView.m // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #import "STColorFactory.h" #import "STTableRowView.h" #import "STTableCellView.h" @interface STTableRowView() @property (readwrite, weak) NSTableView *tableView; @end @implementation STTableRowView - (instancetype)initWithTableView: (NSTableView *)containingTableView { if ((self = [super initWithFrame: NSZeroRect])) { _tableView = containingTableView; } return self; } - (void)drawBackgroundInRect: (NSRect)dirtyRect { [super drawBackgroundInRect: dirtyRect]; NSInteger row = [self.tableView rowForView: self]; if (row % 2 == 0) { [[STColorFactory mainTableViewRowColor] setFill]; } else { [[STColorFactory secondaryTableViewRowColor] setFill]; } NSBezierPath *path = [NSBezierPath bezierPathWithRect: dirtyRect]; [path fill]; } - (void)drawSelectionInRect: (NSRect)dirtyRect { [super drawBackgroundInRect: dirtyRect]; if (self.emphasized) { [[STColorFactory selectedTableViewRowColor] setFill]; } else { [[STColorFactory selectedInactiveTableViewRowColor] setFill]; } NSBezierPath *path = [NSBezierPath bezierPathWithRect: dirtyRect]; [path fill]; } @end ================================================ FILE: Plugin/States/STTableView.h ================================================ // STTableView.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. @import Cocoa; /// A table view that disables navigation with arrow keys and draws a custom background @interface STTableView : NSTableView @end ================================================ FILE: Plugin/States/STTableView.m ================================================ // STTableView.m // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #import "STColorFactory.h" #import "STTableView.h" @implementation STTableView - (void)keyDown: (NSEvent *)theEvent { NSString *characters = [theEvent charactersIgnoringModifiers]; unichar code = [characters characterAtIndex: 0]; // Disable arrow keys navigation switch (code) { case NSUpArrowFunctionKey: case NSDownArrowFunctionKey: case NSLeftArrowFunctionKey: case NSRightArrowFunctionKey: return; default: [super keyDown: theEvent]; } } - (void)drawBackgroundInClipRect: (NSRect)clipRect { [super drawBackgroundInClipRect: clipRect]; [[STColorFactory tableViewBackgroundColor] setFill]; NSBezierPath *path = [NSBezierPath bezierPathWithRect: clipRect]; [path fill]; } @end ================================================ FILE: Plugin/States/STTextField.h ================================================ // STTextField.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. @import Cocoa; @protocol STTextFieldFirstResponderDelegate @optional - (void)textFieldBecomeFirstResponder: (NSTextField *)textField; @end /// A text field that notifies its delegate that it has became firt responder @interface STTextField : NSTextField @property (weak) id firstResponderDelegate; @end ================================================ FILE: Plugin/States/STTextField.m ================================================ // STTextField.m // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #import "STColorFactory.h" #import "STTextField.h" @implementation STTextField - (BOOL)becomeFirstResponder { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ self.textColor = [STColorFactory tableViewCellTextRegularColor]; }); BOOL result = [super becomeFirstResponder]; if (result && [self.delegate respondsToSelector: @selector(textFieldBecomeFirstResponder:)]) { [self.firstResponderDelegate textFieldBecomeFirstResponder: self]; } return result; } @end ================================================ FILE: Plugin/States/STUpdateButton.h ================================================ // STUpdateButton.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. @import Cocoa; typedef void (^STUpdateButtonAnimationCompletion)(void); /// A simple button that may rotate its image clockwise @interface STUpdateButton : NSButton - (void)spinWithCompletion: (STUpdateButtonAnimationCompletion)completion; @end ================================================ FILE: Plugin/States/STUpdateButton.m ================================================ // STUpdateButton.m // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. @import QuartzCore; #import "STUpdateButton.h" @interface STUpdateButton() { STUpdateButtonAnimationCompletion _completion; } @end @implementation STUpdateButton - (instancetype)init { if ((self = [super init])) { self.wantsLayer = YES; } return self; } - (void)spinWithCompletion: (STUpdateButtonAnimationCompletion)completion { if (!CGPointEqualToPoint(self.layer.anchorPoint, CGPointMake(0.5, 0.5))) { [self fixAnchorPoint]; } // Rotate 360° clockwise CABasicAnimation *spinningAnimation = [CABasicAnimation animationWithKeyPath: @"transform.rotation"]; spinningAnimation.fromValue = @(0.0f); spinningAnimation.toValue = @(-2 * M_PI); spinningAnimation.duration = 0.5f; spinningAnimation.delegate = self; _completion = (__bridge STUpdateButtonAnimationCompletion)(_Block_copy((__bridge const void *)(completion))); [self.layer addAnimation: spinningAnimation forKey: nil]; } - (void)animationDidStop: (CAAnimation *)animation finished: (BOOL)flag { if (_completion) { _completion(); _Block_release((__bridge const void *)(_completion)); } } - (void)fixAnchorPoint { CGRect frame = self.layer.frame; CGPoint center = CGPointMake(CGRectGetMidX(frame), CGRectGetMidY(frame)); self.layer.position = center; self.layer.anchorPoint = CGPointMake(0.5, 0.5); } @end ================================================ FILE: Plugin/States/STWindow.h ================================================ // STWindow.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. @import Cocoa; /// A panel which is movable by its background @interface STWindow : NSPanel @end ================================================ FILE: Plugin/States/STWindow.m ================================================ // STWindow.m // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #import "STWindow.h" @implementation STWindow - (BOOL)canBecomeKeyWindow { return YES; } - (BOOL)isMovableByWindowBackground { return YES; } @end ================================================ FILE: Plugin/States/StatesController+ContextMenu.h ================================================ // StatesController+ContextMenu.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #import "StatesController.h" /// A category that builds a context menu for selected rows @interface StatesController (ContextMenu) - (void)menuNeedsUpdate: (NSMenu *)menu; @end ================================================ FILE: Plugin/States/StatesController+ContextMenu.m ================================================ // StatesController+ContextMenu.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #import "STStateDescription.h" #import "STStatefulArtboard.h" #import "StatesController+ContextMenu.h" @implementation StatesController (ContextMenu) - (void)menuNeedsUpdate: (NSMenu *)menu { [menu removeAllItems]; NSInteger clickedRow = [self.tableView clickedRow]; if (clickedRow < 0 || clickedRow >= _artboard.allStates.count) { return; } NSArray *selectedStates = [_artboard.allStates objectsAtIndexes: [self.tableView selectedRowIndexes]]; if (selectedStates.count == 0) { return; } STStateDescription *clickedState = _artboard.allStates[clickedRow]; // We're clicking an a row that isn't part of current selection: show a menu just for this one row if (![selectedStates containsObject: clickedState]) { selectedStates = @[clickedState]; } // TODO?: add support for updating non-current states as well. Need to figure out // when "updating" them means though. Maybe just rewriting them to reflect current artboard properties? if (selectedStates.count == 1 && [clickedState isEqualTo: _artboard.currentState]) { [menu addItem: [self updateCurrentStateMenuItem]]; } [menu addItem: [self duplicateMenuItemForStates: selectedStates]]; [menu addItem: [NSMenuItem separatorItem]]; [menu addItem: [self createPageMenuItemForStates: selectedStates]]; if (selectedStates.count > 1 || [selectedStates.firstObject isNotEqualTo: _artboard.defaultState]) { [menu addItem: [NSMenuItem separatorItem]]; [menu addItem: [self deleteMenuItemForStates: selectedStates]]; } } #pragma mark Menu Items - (NSMenuItem *)updateCurrentStateMenuItem { NSMenuItem *item = [[NSMenuItem alloc] initWithTitle: @"Update" action: @selector(updateCurrentState:) keyEquivalent: @""]; item.target = self; return item; } - (NSMenuItem *)duplicateMenuItemForStates: (NSArray *)subjects { NSMenuItem *item = [[NSMenuItem alloc] initWithTitle: @"Duplicate" action: @selector(duplicateStates:) keyEquivalent: @""]; item.target = self; item.representedObject = subjects; return item; } - (NSMenuItem *)createPageMenuItemForStates: (NSArray *)subjects { NSMenuItem *item = [[NSMenuItem alloc] initWithTitle: @"Create Page" action: @selector(createPageFromStates:) keyEquivalent: @""]; item.target = self; item.representedObject = subjects; return item; } - (NSMenuItem *)deleteMenuItemForStates: (NSArray *)subjects { NSMenuItem *item = [[NSMenuItem alloc] initWithTitle: @"Delete" action: @selector(deleteStates:) keyEquivalent: @""]; item.target = self; item.representedObject = subjects; return item; } @end ================================================ FILE: Plugin/States/StatesController+Decisions.h ================================================ // StatesController+Decisions.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #import "StatesController.h" @class STStateDescription; /// A category that asks user's confirmation for (likely) destructive events @interface StatesController (Decisions) - (BOOL)shouldSwitchToState: (STStateDescription *)newState fromState: (STStateDescription *)oldState; - (BOOL)shoulRemoveStates: (NSArray *)states; @end ================================================ FILE: Plugin/States/StatesController+Decisions.m ================================================ // StatesController+Decisions.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #import "STStateDescription.h" #import "STStatefulArtboard.h" #import "NSArray+HigherOrder.h" #import "StatesController+Decisions.h" #define kNumberOfStatesToShowInDeleteAlert (10) @implementation StatesController (Decisions) - (BOOL)shouldSwitchToState: (STStateDescription *)newState fromState: (STStateDescription *)oldState { // If there aren't any changes then the switch is safe if ([_artboard conformsToState: oldState]) { return YES; } // When we're switching to the same state it means we're to reset all of the changes // made to this state if ([oldState isEqual: newState]) { NSAlert *alert = [[NSAlert alloc] init]; alert.messageText = [NSString stringWithFormat: @"Do you want to revert any changes made to state \"%@\"?", oldState.title]; [alert addButtonWithTitle: @"Revert changes"]; [alert addButtonWithTitle: @"Cancel"]; NSModalResponse response = [alert runModal]; switch (response) { case NSAlertFirstButtonReturn: // "Revert": allow to re-apply this state return YES; case NSAlertSecondButtonReturn: // "Cancel": do nothing return NO; default: return NO; } } else { // Otherwise it's just a regular switch between different states NSAlert *alert = [[NSAlert alloc] init]; alert.messageText = [NSString stringWithFormat: @"Update changes to state \"%@\" before switching to \"%@\"?", oldState.title, newState.title]; [alert addButtonWithTitle: @"Update"]; [alert addButtonWithTitle: @"Cancel"]; [alert addButtonWithTitle: @"Don’t Update"]; NSModalResponse response = [alert runModal]; switch (response) { case NSAlertFirstButtonReturn: // "Update": update the current state and switch to a new one [_artboard updateCurrentState]; return YES; case NSAlertSecondButtonReturn: // "Cancel": do nothing return NO; case NSAlertThirdButtonReturn: // "Do not update": so to say, just switch to the new state return YES; default: return NO; } } } - (BOOL)shoulRemoveStates: (NSArray *)states { NSParameterAssert(states.count > 0); NSArray *titles = [states st_map: ^NSString *(STStateDescription *state) { return [NSString stringWithFormat: @"\t• %@", state.title]; }]; if (titles.count > kNumberOfStatesToShowInDeleteAlert) { NSInteger total = titles.count; titles = [titles subarrayWithRange: NSMakeRange(0, kNumberOfStatesToShowInDeleteAlert)]; titles = [titles arrayByAddingObject: [NSString stringWithFormat: @"\t(and %ld more)", total-kNumberOfStatesToShowInDeleteAlert]]; } NSAlert *alert = [[NSAlert alloc] init]; if (titles.count == 1) { alert.messageText = [NSString stringWithFormat: @"Do you want to delete state \"%@\"?", states.firstObject.title]; } else { alert.messageText = [NSString stringWithFormat: @"Do you want to delete the following states:\n%@", [titles componentsJoinedByString: @"\n"]]; } alert.informativeText = @"All of the settings on this state will also be removed."; [alert addButtonWithTitle: @"Cancel"]; [alert addButtonWithTitle: @"Delete"]; NSModalResponse response = [alert runModal]; switch (response) { case NSAlertFirstButtonReturn: // "Cancel" return NO; case NSAlertSecondButtonReturn: // "Delete" return YES; default: return NO; } } @end ================================================ FILE: Plugin/States/StatesController+DragNDrop.h ================================================ // StatesController+DragNDrop.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #import "StatesController.h" @interface StatesController (DragNDrop) - (void)registerTableViewForDragNDrop; // This category also implements the following NSTableViewDataSources methods: - (BOOL)tableView: (NSTableView *)tableView writeRowsWithIndexes: (NSIndexSet *)rowIndexes toPasteboard: (NSPasteboard *)pboard; - (NSDragOperation)tableView: (NSTableView *)tableView validateDrop: (id )info proposedRow: (NSInteger)row proposedDropOperation: (NSTableViewDropOperation)dropOperation; - (BOOL)tableView: (NSTableView *)tableView acceptDrop: (id )info row: (NSInteger)row dropOperation: (NSTableViewDropOperation)dropOperation; @end ================================================ FILE: Plugin/States/StatesController+DragNDrop.m ================================================ // StatesController+DragNDrop.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #import "STStatefulArtboard.h" #import "StatesController+DragNDrop.h" NSString * const kStatesControllerDraggedType = @"StatesControllerDraggedType"; @implementation StatesController (DragNDrop) - (void)registerTableViewForDragNDrop; { [self.tableView registerForDraggedTypes: @[kStatesControllerDraggedType]]; } - (BOOL)tableView: (NSTableView *)tableView writeRowsWithIndexes: (NSIndexSet *)rowIndexes toPasteboard: (NSPasteboard *)pboard { NSData *indexesData = [NSKeyedArchiver archivedDataWithRootObject: rowIndexes]; [pboard declareTypes: @[kStatesControllerDraggedType] owner: self]; [pboard setData: indexesData forType: kStatesControllerDraggedType]; return YES; } - (NSDragOperation)tableView: (NSTableView *)tableView validateDrop: (id )info proposedRow: (NSInteger)row proposedDropOperation: (NSTableViewDropOperation)dropOperation { if (dropOperation == NSTableViewDropAbove) { [info setAnimatesToDestination: YES]; return NSDragOperationMove; } return NSDragOperationNone; } - (BOOL)tableView: (NSTableView *)tableView acceptDrop: (id )info row: (NSInteger)row dropOperation: (NSTableViewDropOperation)dropOperation { NSData *data = [[info draggingPasteboard] dataForType: kStatesControllerDraggedType]; NSIndexSet *sourceIndexes = [NSKeyedUnarchiver unarchiveObjectWithData: data]; // // FIXME: support dragging multiple items // NSUInteger destination = MIN(MAX(row, 0), _artboard.allStates.count-1); NSMutableArray *states = [_artboard.allStates mutableCopy]; NSUInteger source = sourceIndexes.firstIndex; // 1) model updates id draggedState = [states objectAtIndex: source]; [states removeObjectAtIndex: source]; [states insertObject: draggedState atIndex: destination]; [_artboard reorderStates: states]; // 2) table view updates [tableView moveRowAtIndex: source toIndex: destination]; return YES; } @end ================================================ FILE: Plugin/States/StatesController+Naming.h ================================================ // StatesController+Naming.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #import "StatesController.h" @class STStateDescription; /// Naming things is the second hard thing in programming @interface StatesController (Naming) /// Enumerates names such as "State", "State 1", "State 2" etc and returns the first available one - (NSString *)newStateNameInStates: (NSArray *)existingStates; /// Returns a name for a new page containing shapshots of the given states - (NSString *)pageNameForStates: (NSArray *)states sourcePage: (id )sourcePage; @end ================================================ FILE: Plugin/States/StatesController+Naming.m ================================================ // StatesController+Naming.m // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #import "STPage.h" #import "STStateDescription.h" #import "NSArray+HigherOrder.h" #import "StatesController+Naming.h" @implementation StatesController (Naming) /// Enumerates names such as "State", "State 1", "State 2" etc and returns the first available one - (NSString *)newStateNameInStates: (NSArray *)existingStates { static NSString *template = @"State"; NSSet *matchedNames = [NSSet setWithArray: [existingStates st_map: ^NSString *(STStateDescription *state) { return state.title; }]]; NSInteger idx = 1; NSString *newName = template; while ([matchedNames containsObject: newName]) { newName = [NSString stringWithFormat: @"%@ %ld", template, idx++]; } return newName; } - (NSString *)pageNameForStates: (NSArray *)states sourcePage: (id )sourcePage; { NSString *titles = [[states st_map: ^NSString *(STStateDescription *state) { return state.title; }] componentsJoinedByString: @", "]; return [NSString stringWithFormat: @"%@ :: %@ [Snapshots for %@]", sourcePage.name, [sourcePage currentArtboard].name, titles]; } @end ================================================ FILE: Plugin/States/StatesController.h ================================================ // StatesController.h // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. @import Cocoa; @class STStatefulArtboard; @class STUpdateButton; @class STTableCellView; /// So here you are, looking for a challenge. This one is responsible for managing the states /// table view and responding to user's actions by modifing current artboard. /// /// It's huge and ungly. But I tried my best to make this controller as stateless (such irony!) as /// possible so at least one could easily refactor different bits into separate classes 🌟 @interface StatesController : NSWindowController { @protected STStatefulArtboard *_artboard; } @property (weak) IBOutlet NSTableView *tableView; @property (weak) IBOutlet STUpdateButton *addNewStateButton; @property (weak) IBOutlet NSView *placeholderView; + (instancetype)defaultController; /// Creates a new state - (void)createNewState: (id)sender; /// Update the current state: make it reflect current artboard attributes - (void)updateCurrentState: (NSMenuItem *)sender; /// Create duplicates for all selected states - (void)duplicateStates: (NSMenuItem *)sender; /// Create a one page containing as many artboards as selected states: each of them will contain /// a snapshot of the current artboard in a corresponding state - (void)createPageFromStates: (NSMenuItem *)sender; /// Delete all selected states - (void)deleteStates: (NSMenuItem *)sender; @end ================================================ FILE: Plugin/States/StatesController.m ================================================ // StatesController.m // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. #import "STPage.h" #import "STSketch.h" #import "STTextField.h" #import "STTableRowView.h" #import "STColorFactory.h" #import "STTableCellView.h" #import "NSArray+Indexes.h" #import "STStatefulArtboard.h" #import "NSArray+HigherOrder.h" #import "STStatefulArtboard+Snapshots.h" #import "StatesController.h" #import "StatesController+Naming.h" #import "StatesController+Decisions.h" #import "StatesController+DragNDrop.h" #import "StatesController+ContextMenu.h" @interface StatesController() @end @implementation StatesController + (instancetype)defaultController { static StatesController *controller = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ controller = [[StatesController alloc] init]; [[STSketch notificationObserver] addListener: controller]; }); return controller; } - (NSString *)windowNibName { return @"StatesWindow"; } - (void)awakeFromNib { [(NSPanel *)self.window setWorksWhenModal: NO]; [(NSPanel *)self.window setFloatingPanel: YES]; /// NOTE: these two images are from Sketch self.addNewStateButton.image = [NSImage imageNamed: @"pages_add"]; self.addNewStateButton.alternateImage = [NSImage imageNamed: @"pages_add_pressed"]; self.addNewStateButton.toolTip = @"Add a new state which will reflect the current artboard parameters"; self.tableView.menu = [NSMenu new]; self.tableView.menu.delegate = self; self.tableView.action = @selector(singleClicked:); self.tableView.doubleAction = @selector(doubleClicked:); [self registerTableViewForDragNDrop]; [self resetArtboard: [STSketch currentArtboard]]; } - (void)resetArtboard: (STStatefulArtboard *)artboard { _artboard = artboard; [self.tableView reloadData]; if (!_artboard) { self.placeholderView.hidden = NO; self.addNewStateButton.enabled = NO; return; } self.placeholderView.hidden = YES; self.addNewStateButton.enabled = YES; // Pre-select the current state (if any) NSUInteger currentStateIndex = [_artboard.allStates indexOfObject: _artboard.currentState]; if (currentStateIndex != NSNotFound) { [self.tableView selectRowIndexes: [NSIndexSet indexSetWithIndex: currentStateIndex] byExtendingSelection: NO]; } } #pragma mark - SketchNotificationsListener - (void)currentArtboardDidChange { [self resetArtboard: [STSketch currentArtboard]]; } - (void)currentArtboardUnselected { [self resetArtboard: nil]; } - (void)currentDocumentUpdated { if (!_artboard.currentState) { return; } [self resetDirtyMarkOnStates]; } #pragma mark - Dirty States - (void)resetDirtyMarkOnStates { // Show or hide an update button depending on a situation [_artboard.allStates enumerateObjectsUsingBlock: ^(STStateDescription *state, NSUInteger idx, BOOL *stop) { STTableCellView *cell = [self.tableView viewAtColumn: 0 row: idx makeIfNecessary: NO]; if ([state isEqualTo: _artboard.currentState] && ([self.tableView editedRow] != idx)) { cell.updateButton.animator.hidden = [_artboard conformsToState: state]; } else { cell.updateButton.animator.hidden = YES; } }]; } #pragma mark - STTableCellViewDelegate - (BOOL)cellViewRepresentsCurrentItem: (STTableCellView *)cellView { NSInteger idx = [_artboard.allStates indexOfObject: _artboard.currentState]; if (!_artboard || idx == NSNotFound) { return NO; } return cellView == [self.tableView viewAtColumn: 0 row: idx makeIfNecessary: NO]; } - (BOOL)isSingleRowSelected { return [self.tableView selectedRowIndexes].count == 1; } #pragma mark - User Actions - (IBAction)createNewState: (id)sender { NSString *newStateName = [self newStateNameInStates: _artboard.allStates]; STStateDescription *state = [[STStateDescription alloc] initWithTitle: newStateName]; [_artboard insertNewState: state]; // Update the table view NSInteger newIndex = _artboard.allStates.count-1; [self.tableView insertRowsAtIndexes: [NSIndexSet indexSetWithIndex: newIndex] withAnimation: NSTableViewAnimationEffectFade]; // No need to ask user about switching, since the settings are already saved in this new state [self.tableView selectRowIndexes: [NSIndexSet indexSetWithIndex: newIndex] byExtendingSelection: NO]; // HACK: we avoid re-apply the same artboard properties again which can take a lot of time on big // artboards by setting the current state directly instead of calling -applyState:. // This is a workaround and should be removed as soon as we find a proper solution to our // performance issues [_artboard setCurrentState: state]; [self resetDirtyMarkOnStates]; // Move focus to the row to allow user to immdiately change the title value [self.tableView editColumn: 0 row: newIndex withEvent: nil select: YES]; } - (IBAction)updateCurrentState: (NSMenuItem *)sender { NSInteger idx = [_artboard.allStates indexOfObject: _artboard.currentState]; NSParameterAssert(idx != NSNotFound); STTableCellView *cell = [self.tableView viewAtColumn: 0 row: idx makeIfNecessary: NO]; // Animations first! __block BOOL animationCompleted = NO; [cell.updateButton spinWithCompletion: ^{ [self resetDirtyMarkOnStates]; animationCompleted = YES; }]; // Then actually update the model [_artboard updateCurrentState]; // Finally we double check that the update button may be hiden safely if (animationCompleted) { [self resetDirtyMarkOnStates]; } } - (IBAction)duplicateStates: (NSMenuItem *)sender { NSArray *originals = sender.representedObject; NSParameterAssert([originals isKindOfClass: [NSArray class]]); // Create a copy for every original state passed by sender [originals enumerateObjectsUsingBlock: ^(STStateDescription *state, NSUInteger idx, BOOL *stop) { NSString *duplicateTitle = [NSString stringWithFormat: @"%@ copy", state.title]; STStateDescription *duplicate = [[STStateDescription alloc] initWithTitle: duplicateTitle]; [_artboard insertNewState: duplicate]; [_artboard copyState: state toState: duplicate]; }]; // Update the table view to reveal this new states NSRange newStatesRange = NSMakeRange(_artboard.allStates.count-1, originals.count); NSIndexSet *newIndexes = [NSIndexSet indexSetWithIndexesInRange: newStatesRange]; [self.tableView insertRowsAtIndexes: newIndexes withAnimation: NSTableViewAnimationEffectFade]; } - (void)createPageFromStates: (NSMenuItem *)sender { NSArray *selectedStates = sender.representedObject; NSParameterAssert([selectedStates isKindOfClass: [NSArray class]]); // 1) Create a new page id currentPage = [STSketch currentPage]; id newPage = [NSClassFromString(@"MSPage") page]; NSAssert(newPage != nil, @"+[MSPage page] returned nil. Is this method still available?"); newPage.name = [self pageNameForStates: selectedStates sourcePage: currentPage]; // XXX: MSPage's pageDelegate property doesn't exist since 3.9 if ([newPage respondsToSelector: @selector(pageDelegate)]) { newPage.pageDelegate = currentPage.pageDelegate; } newPage.grid = currentPage.grid; newPage.layout = currentPage.layout; // 2) for each selected state we create a "snapshot" artboard and copy it to this new page NSArray *artboards = [selectedStates st_map: ^id(STStateDescription *state) { return [_artboard snapshotForState: state]; }]; // 2.1) we want these artboards to be aligned in a line with a little space in between items CGFloat gap = 200.f; __block CGPoint location = CGPointZero; [artboards enumerateObjectsUsingBlock: ^(id artboard, NSUInteger idx, BOOL *stop) { if (idx == 0) { location = [[artboard absoluteRect] absoluteRect].origin; } [[artboard absoluteRect] setX: location.x]; location.x += [[artboard absoluteRect] absoluteRect].size.width + gap; }]; [newPage addLayers: artboards]; // 3) Insert this new page into the document [[[STSketch currentDocument] documentData] addPage: newPage]; // 3.1) adjust scroll and zoom to match the source page newPage.scrollOrigin = currentPage.scrollOrigin; newPage.zoomValue = currentPage.zoomValue; // 3.2) mark this new page as current [STSketch currentDocument].currentPage = newPage; // 4) Select the first available artboard on a new page if (newPage.artboards.count > 0) { [[[STSketch currentDocument] documentData] deselectAllLayers]; [newPage selectLayers: @[newPage.artboards.firstObject]]; } } - (IBAction)deleteStates: (NSMenuItem *)sender { NSMutableArray *statesToDelete = [sender.representedObject mutableCopy]; NSParameterAssert([statesToDelete isKindOfClass: [NSArray class]]); // We can not remove the default state so just remove if from the proposed set of states [statesToDelete removeObject: _artboard.defaultState]; if (![self shoulRemoveStates: statesToDelete]) { return; } NSIndexSet *indexesToDelete = [_artboard.allStates st_indexesOfObjects: statesToDelete]; // 1) remove states from data model [statesToDelete enumerateObjectsUsingBlock: ^(STStateDescription *state, NSUInteger idx, BOOL *stop) { [_artboard removeState: state]; }]; // 2) remove corresponding rows from table view [self.tableView removeRowsAtIndexes: indexesToDelete withAnimation: NSTableViewAnimationEffectFade]; // 3) update table view selection NSInteger newCurrentState = [_artboard.allStates indexOfObject: _artboard.currentState]; if (newCurrentState != NSNotFound) { [self.tableView selectRowIndexes: [NSIndexSet indexSetWithIndex: newCurrentState] byExtendingSelection: NO]; } } /// Single click switches current state - (void)singleClicked: (id)sender { // Ignore clicks when multiple rows are selected if ([self.tableView selectedRowIndexes].count > 1) { return; } NSInteger row = [self.tableView clickedRow]; if (row < 0 || row >= _artboard.allStates.count) { return; } STStateDescription *newState = _artboard.allStates[row]; if (!newState) { return; } // Clicking on the same state will drop any current changes so we ask user about it if ([newState isEqualTo: _artboard.currentState]) { if ([self shouldSwitchToState: _artboard.currentState fromState: _artboard.currentState]) { [_artboard applyState: newState]; } return; } // -tableView:shouldSelectRow: has been called already so we just check if the target row // is selected and apply the new state accordingly. if ([self.tableView isRowSelected: row]) { [_artboard applyState: newState]; [self resetDirtyMarkOnStates]; } } /// Double click makes a state title text fiels editable - (void)doubleClicked: (id)sender { // Ignore clicks when multiple rows are selected if ([self.tableView selectedRowIndexes].count > 1) { return; } NSInteger row = [self.tableView clickedRow]; if (row < 0 || row >= _artboard.allStates.count) { return; } [self.tableView editColumn: 0 row: row withEvent: nil select: YES]; } #pragma mark User Did Commit New State Title - (void)controlTextDidEndEditing: (NSNotification *)obj { NSTextView *editor = [obj.userInfo valueForKey: @"NSFieldEditor"]; NSInteger updatedRow = [self.tableView rowForView: editor]; if (updatedRow < 0 || updatedRow >= _artboard.allStates.count) { return; } NSString *newTitle = [[editor string] stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]]; // We either commit the change or just reset the row if user input is invalid if (newTitle.length > 0) { [_artboard updateName: newTitle forState: _artboard.allStates[updatedRow]]; } else { [self.tableView reloadDataForRowIndexes: [NSIndexSet indexSetWithIndex: updatedRow] columnIndexes: [NSIndexSet indexSetWithIndex: 0]]; } // Don't forget about the update button we've hidden [self resetDirtyMarkOnStates]; } /// Hide an update button when a state title is being edited - (void)textFieldBecomeFirstResponder: (NSTextField *)textField { NSInteger row = [self.tableView rowForView: textField]; if (row < 0 || row >= _artboard.allStates.count) { return; } STTableCellView *cell = [self.tableView viewAtColumn: 0 row: row makeIfNecessary:NO]; cell.updateButton.hidden = YES; } #pragma mark - NSTableViewDataSource & NSTableViewDelegate - (NSInteger)numberOfRowsInTableView: (NSTableView *)tableView { return _artboard.allStates.count; } - (NSView *)tableView: (NSTableView *)tableView viewForTableColumn: (NSTableColumn *)tableColumn row: (NSInteger)row { STStateDescription *state = _artboard.allStates[row]; if (!state) { return nil; } STTableCellView *cellView = [tableView makeViewWithIdentifier: @"StateCell" owner: nil]; if (!cellView) { return nil; } cellView.delegate = self; // Setup text field cellView.textField.stringValue = state.title; cellView.textField.delegate = self; ((STTextField *)cellView.textField).firstResponderDelegate = self; // Setup update button cellView.updateButton.action = @selector(updateCurrentState:); cellView.updateButton.target = self; // Toggle update button's visibility if ([[tableView selectedRowIndexes] containsIndex: row]) { cellView.updateButton.hidden = [_artboard conformsToState: state]; } else { cellView.updateButton.hidden = YES; } return cellView; } #pragma mark Selection Filter - (NSIndexSet *)tableView: (NSTableView *)tableView selectionIndexesForProposedSelection: (NSIndexSet *)proposedSelectionIndexes { // Don't allow table view to reset selection automatically from multiple rows to "nothing". In // this case it will select the last row which may not represent the current state if ([tableView selectedRowIndexes].count > 1 && proposedSelectionIndexes.count == 0) { NSInteger currentRow = [_artboard.allStates indexOfObject: _artboard.currentState]; if (currentRow != NSNotFound) { return [NSIndexSet indexSetWithIndex: currentRow]; } else { return [NSIndexSet indexSet]; } } // Redraw the already selected row when we're dropping multiselection to just this one row if ([tableView selectedRowIndexes].count > 1 && proposedSelectionIndexes.count == 1) { STStateDescription *newState = _artboard.allStates[proposedSelectionIndexes.firstIndex]; if (![self shouldSwitchToState: newState fromState: _artboard.currentState]) { return [NSIndexSet indexSet]; } dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self.tableView rowViewAtRow: proposedSelectionIndexes.firstIndex makeIfNecessary: NO].needsDisplay = YES; }); return proposedSelectionIndexes; } // Always allow to expand selection. Note that we don't switch states in this case if (proposedSelectionIndexes.count > 1) { return proposedSelectionIndexes; } // Always allow initial selection if (self.tableView.selectedRowIndexes.count == 0) { return proposedSelectionIndexes; } // Don't allow to drop selection from one row to zero if (proposedSelectionIndexes.count == 0) { return [NSIndexSet indexSet]; } // So we're switching from one state to another; ask user about this STStateDescription *oldState = _artboard.allStates[tableView.selectedRowIndexes.firstIndex]; STStateDescription *newState = _artboard.allStates[proposedSelectionIndexes.firstIndex]; if ([self shouldSwitchToState: newState fromState: oldState]) { return proposedSelectionIndexes; } return [NSIndexSet indexSet]; } - (void)tableViewSelectionDidChange:(NSNotification *)notification { // Update cell views for current selection state (e.g. set text color, etc) [_artboard.allStates enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL * stop) { NSTableCellView *view = [self.tableView viewAtColumn: 0 row: idx makeIfNecessary: NO]; view.backgroundStyle = view.backgroundStyle; }]; } #pragma mark Row Coloring - (NSTableRowView *)tableView: (NSTableView *)tableView rowViewForRow: (NSInteger)row { return [[STTableRowView alloc] initWithTableView: tableView]; } @end ================================================ FILE: Plugin/States/StatesWindow.xib ================================================ ================================================ FILE: Plugin/States.xcodeproj/project.pbxproj ================================================ // !$*UTF8*$! { archiveVersion = 1; classes = { }; objectVersion = 46; objects = { /* Begin PBXBuildFile section */ 0A12AE5E1D13A62300CBB026 /* STStatefulArtboard+Snapshots.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A12AE5D1D13A62300CBB026 /* STStatefulArtboard+Snapshots.m */; }; 0A2C50EA1D09C87800CB3C9F /* STWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A2C50E91D09C87800CB3C9F /* STWindow.m */; }; 0A3CBDB31D0A61C40016EFD8 /* STTableRowView.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A3CBDB21D0A61C40016EFD8 /* STTableRowView.m */; }; 0A3CBDB61D0A6BB10016EFD8 /* STColorFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A3CBDB51D0A6BB10016EFD8 /* STColorFactory.m */; }; 0A3CEE731D055B6F008A4BB0 /* StatesController+Naming.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A3CEE721D055B6F008A4BB0 /* StatesController+Naming.m */; }; 0A3CEE761D055C5E008A4BB0 /* StatesController+Decisions.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A3CEE751D055C5E008A4BB0 /* StatesController+Decisions.m */; }; 0A3CEE791D05693E008A4BB0 /* StatesController+ContextMenu.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A3CEE781D05693E008A4BB0 /* StatesController+ContextMenu.m */; }; 0A4BDCAE1CFEBDC600D3584F /* STSketch.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A4BDCAD1CFEBDC600D3584F /* STSketch.m */; }; 0A4BDCB61CFEC5C200D3584F /* Aspects.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A4BDCB51CFEC5C200D3584F /* Aspects.m */; }; 0A4BDCBA1CFED17200D3584F /* STSketchPluginContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A4BDCB91CFED17200D3584F /* STSketchPluginContext.m */; }; 0A7160F31D09279C008A3F78 /* STUpdateButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A7160F21D09279C008A3F78 /* STUpdateButton.m */; }; 0A9BE3C61D06F89E00257F99 /* dirty.png in Resources */ = {isa = PBXBuildFile; fileRef = 0A9BE3C41D06F89E00257F99 /* dirty.png */; }; 0A9BE3C71D06F89E00257F99 /* dirty@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 0A9BE3C51D06F89E00257F99 /* dirty@2x.png */; }; 0A9C85941D0B001B00231073 /* STPlaceholderView.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A9C85931D0B001B00231073 /* STPlaceholderView.m */; }; 0A9CBE3E1D09D8C700748DFA /* STTableCellView.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A9CBE3D1D09D8C700748DFA /* STTableCellView.m */; }; 0A9CBE411D09DEFB00748DFA /* STHeaderView.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A9CBE401D09DEFB00748DFA /* STHeaderView.m */; }; 0AAB1C541CFF33C8006512AF /* STLayerState.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AAB1C531CFF33C8006512AF /* STLayerState.m */; }; 0AAB1C5B1CFF3D56006512AF /* STStateDescription.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AAB1C5A1CFF3D56006512AF /* STStateDescription.m */; }; 0AAB1C5E1CFF40CA006512AF /* STStatefulArtboard.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AAB1C5D1CFF40CA006512AF /* STStatefulArtboard.m */; }; 0AB737AC1D04512600E79D3D /* STTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AB737AB1D04512600E79D3D /* STTableView.m */; }; 0AC4CD911D0BDDD000829E45 /* STTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AC4CD901D0BDDD000829E45 /* STTextField.m */; }; 0AC4CD941D0BE52300829E45 /* NSArray+HigherOrder.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AC4CD931D0BE52300829E45 /* NSArray+HigherOrder.m */; }; 0AD7BE051CFDE548003C77BB /* StatesController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AD7BE041CFDE548003C77BB /* StatesController.m */; }; 0AD7BE0B1CFDF088003C77BB /* StatesWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 0AD7BE0A1CFDF088003C77BB /* StatesWindow.xib */; }; 0AE014F61D0EA24C00F39C32 /* NSArray+Indexes.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AE014F51D0EA24C00F39C32 /* NSArray+Indexes.m */; }; 0AE014F91D0EB3EA00F39C32 /* StatesController+DragNDrop.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AE014F81D0EB3EA00F39C32 /* StatesController+DragNDrop.m */; }; 0AE8BF421D02FC6E00E0C4A8 /* STStatefulArtboard+Backend.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AE8BF411D02FC6E00E0C4A8 /* STStatefulArtboard+Backend.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ 0A12AE5C1D13A62300CBB026 /* STStatefulArtboard+Snapshots.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "STStatefulArtboard+Snapshots.h"; sourceTree = ""; }; 0A12AE5D1D13A62300CBB026 /* STStatefulArtboard+Snapshots.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "STStatefulArtboard+Snapshots.m"; sourceTree = ""; }; 0A291EA81D59BF6E0003F2A3 /* Versioning.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Versioning.xcconfig; sourceTree = ""; }; 0A291EAB1D59C0A10003F2A3 /* Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = ""; }; 0A291EAD1D59C0AA0003F2A3 /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = ""; }; 0A2C50E81D09C87800CB3C9F /* STWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STWindow.h; sourceTree = ""; }; 0A2C50E91D09C87800CB3C9F /* STWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STWindow.m; sourceTree = ""; }; 0A3CBDB11D0A61C40016EFD8 /* STTableRowView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STTableRowView.h; sourceTree = ""; }; 0A3CBDB21D0A61C40016EFD8 /* STTableRowView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STTableRowView.m; sourceTree = ""; }; 0A3CBDB41D0A6BB10016EFD8 /* STColorFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STColorFactory.h; sourceTree = ""; }; 0A3CBDB51D0A6BB10016EFD8 /* STColorFactory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STColorFactory.m; sourceTree = ""; }; 0A3CE5971CFCBB6800B8C552 /* States.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = States.bundle; sourceTree = BUILT_PRODUCTS_DIR; }; 0A3CE59A1CFCBB6800B8C552 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 0A3CE5A01CFCBBCD00B8C552 /* manifest.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = manifest.json; sourceTree = ""; }; 0A3CEE711D055B6F008A4BB0 /* StatesController+Naming.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = "StatesController+Naming.h"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; 0A3CEE721D055B6F008A4BB0 /* StatesController+Naming.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = "StatesController+Naming.m"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; 0A3CEE741D055C5E008A4BB0 /* StatesController+Decisions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = "StatesController+Decisions.h"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; 0A3CEE751D055C5E008A4BB0 /* StatesController+Decisions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = "StatesController+Decisions.m"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; 0A3CEE771D05693E008A4BB0 /* StatesController+ContextMenu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = "StatesController+ContextMenu.h"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; 0A3CEE781D05693E008A4BB0 /* StatesController+ContextMenu.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = "StatesController+ContextMenu.m"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; 0A4BDCAC1CFEBDC600D3584F /* STSketch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STSketch.h; sourceTree = ""; }; 0A4BDCAD1CFEBDC600D3584F /* STSketch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STSketch.m; sourceTree = ""; }; 0A4BDCB41CFEC5C200D3584F /* Aspects.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Aspects.h; path = vendor/Aspects.h; sourceTree = ""; }; 0A4BDCB51CFEC5C200D3584F /* Aspects.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Aspects.m; path = vendor/Aspects.m; sourceTree = ""; }; 0A4BDCB81CFED17200D3584F /* STSketchPluginContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STSketchPluginContext.h; sourceTree = ""; }; 0A4BDCB91CFED17200D3584F /* STSketchPluginContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STSketchPluginContext.m; sourceTree = ""; }; 0A7160F11D09279C008A3F78 /* STUpdateButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STUpdateButton.h; sourceTree = ""; }; 0A7160F21D09279C008A3F78 /* STUpdateButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STUpdateButton.m; sourceTree = ""; }; 0A7E78FF1CFED94800CAB318 /* runtime.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; name = runtime.js; path = lib/runtime.js; sourceTree = ""; }; 0A9BE3C41D06F89E00257F99 /* dirty.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = dirty.png; sourceTree = ""; }; 0A9BE3C51D06F89E00257F99 /* dirty@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "dirty@2x.png"; sourceTree = ""; }; 0A9C85921D0B001B00231073 /* STPlaceholderView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STPlaceholderView.h; sourceTree = ""; }; 0A9C85931D0B001B00231073 /* STPlaceholderView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STPlaceholderView.m; sourceTree = ""; }; 0A9CBE3C1D09D8C700748DFA /* STTableCellView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STTableCellView.h; sourceTree = ""; }; 0A9CBE3D1D09D8C700748DFA /* STTableCellView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STTableCellView.m; sourceTree = ""; }; 0A9CBE3F1D09DEFB00748DFA /* STHeaderView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STHeaderView.h; sourceTree = ""; }; 0A9CBE401D09DEFB00748DFA /* STHeaderView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STHeaderView.m; sourceTree = ""; }; 0AAB1C4A1CFF2FEB006512AF /* STPage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STPage.h; sourceTree = ""; }; 0AAB1C4B1CFF2FF6006512AF /* STDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STDocument.h; sourceTree = ""; }; 0AAB1C4C1CFF2FFE006512AF /* STLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STLayer.h; sourceTree = ""; }; 0AAB1C4D1CFF3006006512AF /* STArtboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STArtboard.h; sourceTree = ""; }; 0AAB1C501CFF3217006512AF /* STCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STCommand.h; sourceTree = ""; }; 0AAB1C521CFF33C8006512AF /* STLayerState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STLayerState.h; sourceTree = ""; }; 0AAB1C531CFF33C8006512AF /* STLayerState.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STLayerState.m; sourceTree = ""; }; 0AAB1C591CFF3D56006512AF /* STStateDescription.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STStateDescription.h; sourceTree = ""; }; 0AAB1C5A1CFF3D56006512AF /* STStateDescription.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STStateDescription.m; sourceTree = ""; }; 0AAB1C5C1CFF40CA006512AF /* STStatefulArtboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STStatefulArtboard.h; sourceTree = ""; }; 0AAB1C5D1CFF40CA006512AF /* STStatefulArtboard.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STStatefulArtboard.m; sourceTree = ""; }; 0AB737AA1D04512600E79D3D /* STTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STTableView.h; sourceTree = ""; }; 0AB737AB1D04512600E79D3D /* STTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STTableView.m; sourceTree = ""; }; 0AC4CD8F1D0BDDD000829E45 /* STTextField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STTextField.h; sourceTree = ""; }; 0AC4CD901D0BDDD000829E45 /* STTextField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STTextField.m; sourceTree = ""; }; 0AC4CD921D0BE52300829E45 /* NSArray+HigherOrder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+HigherOrder.h"; sourceTree = ""; }; 0AC4CD931D0BE52300829E45 /* NSArray+HigherOrder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+HigherOrder.m"; sourceTree = ""; }; 0AD7BE031CFDE548003C77BB /* StatesController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = StatesController.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; 0AD7BE041CFDE548003C77BB /* StatesController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = StatesController.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; 0AD7BE081CFDE680003C77BB /* plugin.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; lineEnding = 0; path = plugin.js; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.javascript; }; 0AD7BE0A1CFDF088003C77BB /* StatesWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = StatesWindow.xib; sourceTree = ""; }; 0AE014F41D0EA24C00F39C32 /* NSArray+Indexes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+Indexes.h"; sourceTree = ""; }; 0AE014F51D0EA24C00F39C32 /* NSArray+Indexes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+Indexes.m"; sourceTree = ""; }; 0AE014F71D0EB3EA00F39C32 /* StatesController+DragNDrop.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "StatesController+DragNDrop.h"; sourceTree = ""; }; 0AE014F81D0EB3EA00F39C32 /* StatesController+DragNDrop.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "StatesController+DragNDrop.m"; sourceTree = ""; }; 0AE8BF401D02FC6E00E0C4A8 /* STStatefulArtboard+Backend.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "STStatefulArtboard+Backend.h"; sourceTree = ""; }; 0AE8BF411D02FC6E00E0C4A8 /* STStatefulArtboard+Backend.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "STStatefulArtboard+Backend.m"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ 0A3CE5941CFCBB6800B8C552 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ 0A291EAA1D59C0820003F2A3 /* Build Configuration */ = { isa = PBXGroup; children = ( 0A291EA81D59BF6E0003F2A3 /* Versioning.xcconfig */, 0A291EAB1D59C0A10003F2A3 /* Debug.xcconfig */, 0A291EAD1D59C0AA0003F2A3 /* Release.xcconfig */, ); name = "Build Configuration"; sourceTree = ""; }; 0A3CE58E1CFCBB6800B8C552 = { isa = PBXGroup; children = ( 0A291EAA1D59C0820003F2A3 /* Build Configuration */, 0A3CE5A01CFCBBCD00B8C552 /* manifest.json */, 0AD7BE071CFDE658003C77BB /* JS */, 0A3CE5991CFCBB6800B8C552 /* Native Code */, 0AE8BF431D030E7C00E0C4A8 /* Helpers */, 0A9BE3C31D06F89E00257F99 /* Images */, 0A4BDCB01CFEC37000D3584F /* Vendor */, 0A3CE5981CFCBB6800B8C552 /* Products */, ); sourceTree = ""; }; 0A3CE5981CFCBB6800B8C552 /* Products */ = { isa = PBXGroup; children = ( 0A3CE5971CFCBB6800B8C552 /* States.bundle */, ); name = Products; sourceTree = ""; }; 0A3CE5991CFCBB6800B8C552 /* Native Code */ = { isa = PBXGroup; children = ( 0A3CE59A1CFCBB6800B8C552 /* Info.plist */, 0A3CBDB41D0A6BB10016EFD8 /* STColorFactory.h */, 0A3CBDB51D0A6BB10016EFD8 /* STColorFactory.m */, 0AAB1C5F1CFF4AE8006512AF /* Controller */, 0A7160F41D0927A5008A3F78 /* Views */, 0A3CEE7A1D0569DF008A4BB0 /* Artboards */, 0AAB1C511CFF33B8006512AF /* Wrappers */, 0AAB1C4E1CFF31C1006512AF /* Sketch Protocols */, ); name = "Native Code"; path = States; sourceTree = ""; }; 0A3CEE7A1D0569DF008A4BB0 /* Artboards */ = { isa = PBXGroup; children = ( 0AAB1C5C1CFF40CA006512AF /* STStatefulArtboard.h */, 0AAB1C5D1CFF40CA006512AF /* STStatefulArtboard.m */, 0A12AE5C1D13A62300CBB026 /* STStatefulArtboard+Snapshots.h */, 0A12AE5D1D13A62300CBB026 /* STStatefulArtboard+Snapshots.m */, 0AE8BF401D02FC6E00E0C4A8 /* STStatefulArtboard+Backend.h */, 0AE8BF411D02FC6E00E0C4A8 /* STStatefulArtboard+Backend.m */, ); name = Artboards; sourceTree = ""; }; 0A4BDCB01CFEC37000D3584F /* Vendor */ = { isa = PBXGroup; children = ( 0A4BDCB41CFEC5C200D3584F /* Aspects.h */, 0A4BDCB51CFEC5C200D3584F /* Aspects.m */, ); name = Vendor; sourceTree = ""; }; 0A7160F41D0927A5008A3F78 /* Views */ = { isa = PBXGroup; children = ( 0A7160F11D09279C008A3F78 /* STUpdateButton.h */, 0A7160F21D09279C008A3F78 /* STUpdateButton.m */, 0AB737AA1D04512600E79D3D /* STTableView.h */, 0AB737AB1D04512600E79D3D /* STTableView.m */, 0A9CBE3C1D09D8C700748DFA /* STTableCellView.h */, 0A9CBE3D1D09D8C700748DFA /* STTableCellView.m */, 0AC4CD8F1D0BDDD000829E45 /* STTextField.h */, 0AC4CD901D0BDDD000829E45 /* STTextField.m */, 0A3CBDB11D0A61C40016EFD8 /* STTableRowView.h */, 0A3CBDB21D0A61C40016EFD8 /* STTableRowView.m */, 0A2C50E81D09C87800CB3C9F /* STWindow.h */, 0A2C50E91D09C87800CB3C9F /* STWindow.m */, 0A9CBE3F1D09DEFB00748DFA /* STHeaderView.h */, 0A9CBE401D09DEFB00748DFA /* STHeaderView.m */, 0A9C85921D0B001B00231073 /* STPlaceholderView.h */, 0A9C85931D0B001B00231073 /* STPlaceholderView.m */, ); name = Views; sourceTree = ""; }; 0A7E79001CFEDA1500CAB318 /* lib */ = { isa = PBXGroup; children = ( 0A7E78FF1CFED94800CAB318 /* runtime.js */, ); name = lib; sourceTree = ""; }; 0A9BE3C31D06F89E00257F99 /* Images */ = { isa = PBXGroup; children = ( 0A9BE3C41D06F89E00257F99 /* dirty.png */, 0A9BE3C51D06F89E00257F99 /* dirty@2x.png */, ); path = Images; sourceTree = ""; }; 0AAB1C4E1CFF31C1006512AF /* Sketch Protocols */ = { isa = PBXGroup; children = ( 0AAB1C4A1CFF2FEB006512AF /* STPage.h */, 0AAB1C4B1CFF2FF6006512AF /* STDocument.h */, 0AAB1C4C1CFF2FFE006512AF /* STLayer.h */, 0AAB1C4D1CFF3006006512AF /* STArtboard.h */, 0AAB1C501CFF3217006512AF /* STCommand.h */, ); name = "Sketch Protocols"; sourceTree = ""; }; 0AAB1C511CFF33B8006512AF /* Wrappers */ = { isa = PBXGroup; children = ( 0A4BDCAC1CFEBDC600D3584F /* STSketch.h */, 0A4BDCAD1CFEBDC600D3584F /* STSketch.m */, 0AAB1C521CFF33C8006512AF /* STLayerState.h */, 0AAB1C531CFF33C8006512AF /* STLayerState.m */, 0AAB1C591CFF3D56006512AF /* STStateDescription.h */, 0AAB1C5A1CFF3D56006512AF /* STStateDescription.m */, 0A4BDCB81CFED17200D3584F /* STSketchPluginContext.h */, 0A4BDCB91CFED17200D3584F /* STSketchPluginContext.m */, ); name = Wrappers; sourceTree = ""; }; 0AAB1C5F1CFF4AE8006512AF /* Controller */ = { isa = PBXGroup; children = ( 0AD7BE0A1CFDF088003C77BB /* StatesWindow.xib */, 0AD7BE031CFDE548003C77BB /* StatesController.h */, 0AD7BE041CFDE548003C77BB /* StatesController.m */, 0A3CEE711D055B6F008A4BB0 /* StatesController+Naming.h */, 0A3CEE721D055B6F008A4BB0 /* StatesController+Naming.m */, 0A3CEE741D055C5E008A4BB0 /* StatesController+Decisions.h */, 0A3CEE751D055C5E008A4BB0 /* StatesController+Decisions.m */, 0A3CEE771D05693E008A4BB0 /* StatesController+ContextMenu.h */, 0A3CEE781D05693E008A4BB0 /* StatesController+ContextMenu.m */, 0AE014F71D0EB3EA00F39C32 /* StatesController+DragNDrop.h */, 0AE014F81D0EB3EA00F39C32 /* StatesController+DragNDrop.m */, ); name = Controller; sourceTree = ""; }; 0AD7BE071CFDE658003C77BB /* JS */ = { isa = PBXGroup; children = ( 0AD7BE081CFDE680003C77BB /* plugin.js */, 0A7E79001CFEDA1500CAB318 /* lib */, ); name = JS; sourceTree = ""; }; 0AE8BF431D030E7C00E0C4A8 /* Helpers */ = { isa = PBXGroup; children = ( 0AC4CD921D0BE52300829E45 /* NSArray+HigherOrder.h */, 0AC4CD931D0BE52300829E45 /* NSArray+HigherOrder.m */, 0AE014F41D0EA24C00F39C32 /* NSArray+Indexes.h */, 0AE014F51D0EA24C00F39C32 /* NSArray+Indexes.m */, ); name = Helpers; path = States; sourceTree = ""; }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ 0A3CE5961CFCBB6800B8C552 /* States */ = { isa = PBXNativeTarget; buildConfigurationList = 0A3CE59D1CFCBB6800B8C552 /* Build configuration list for PBXNativeTarget "States" */; buildPhases = ( 0A291EA71D59BE830003F2A3 /* Set Info for Source Version Load Command */, 0A3CE5931CFCBB6800B8C552 /* Sources */, 0A3CE5941CFCBB6800B8C552 /* Frameworks */, 0A3CE5951CFCBB6800B8C552 /* Resources */, 0AD7BE061CFDE5A2003C77BB /* Build Sketch plugin */, ); buildRules = ( ); dependencies = ( ); name = States; productName = States; productReference = 0A3CE5971CFCBB6800B8C552 /* States.bundle */; productType = "com.apple.product-type.bundle"; }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ 0A3CE58F1CFCBB6800B8C552 /* Project object */ = { isa = PBXProject; attributes = { LastUpgradeCheck = 0730; ORGANIZATIONNAME = "Internals Exposed"; TargetAttributes = { 0A3CE5961CFCBB6800B8C552 = { CreatedOnToolsVersion = 7.3; }; }; }; buildConfigurationList = 0A3CE5921CFCBB6800B8C552 /* Build configuration list for PBXProject "States" */; compatibilityVersion = "Xcode 3.2"; developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( en, ); mainGroup = 0A3CE58E1CFCBB6800B8C552; productRefGroup = 0A3CE5981CFCBB6800B8C552 /* Products */; projectDirPath = ""; projectRoot = ""; targets = ( 0A3CE5961CFCBB6800B8C552 /* States */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ 0A3CE5951CFCBB6800B8C552 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( 0A9BE3C71D06F89E00257F99 /* dirty@2x.png in Resources */, 0A9BE3C61D06F89E00257F99 /* dirty.png in Resources */, 0AD7BE0B1CFDF088003C77BB /* StatesWindow.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ 0A291EA71D59BE830003F2A3 /* Set Info for Source Version Load Command */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); name = "Set Info for Source Version Load Command"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "VERSIONING_XCCONFIG_FILE=\"${PROJECT_DIR}/Versioning.xcconfig\"\nPROJECT_VERSION=$(/usr/libexec/PlistBuddy -c \"Print CFBundleShortVersionString\" \"${PROJECT_DIR}/${INFOPLIST_FILE}\")\necho \"IEXP_SOURCE_VERSION = $PROJECT_VERSION\" > $VERSIONING_XCCONFIG_FILE"; showEnvVarsInLog = 0; }; 0AD7BE061CFDE5A2003C77BB /* Build Sketch plugin */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); name = "Build Sketch plugin"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "PLUGIN_DIR=\"$BUILT_PRODUCTS_DIR/$PROJECT_NAME\".sketchplugin\n# 1) create a .sketchplugin directory with the following subdirs:\n# ./Contents/Sketch\n# ./Contents/Sketch/lib\n# ./Contents/Resources\nrm -Rf \"$PLUGIN_DIR\"\nmkdir \"$PLUGIN_DIR\" && cd $_\nmkdir ./Contents && cd $_\nmkdir -p ./Sketch/lib\nmkdir ./Resources\n# 2) copy files into .sketchplugin:\n# ./Contents/Sketch/manifest.json\n# ./Contents/Sketch/*.js\n# ./Contents/Sketch/lib/*.js\n# ./Contents/Resources/States.bundle\ncp \"$PROJECT_DIR/manifest.json\" ./Sketch\ncp \"$PROJECT_DIR/\"*.js ./Sketch\ncp \"$PROJECT_DIR/lib/\"*.js ./Sketch/lib\ncp -R \"$BUILT_PRODUCTS_DIR/$EXECUTABLE_NAME.bundle\" ./Resources\n# 3) Symlink our target into Sketch's Plugins directory\ncd ~/Library/Application\\ Support/com.bohemiancoding.sketch3/Plugins\nrm -f \"$EXECUTABLE_NAME\".sketchplugin\nln -s \"$PLUGIN_DIR\" \"$EXECUTABLE_NAME\".sketchplugin\n# 4) Done! 🎉"; }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ 0A3CE5931CFCBB6800B8C552 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( 0AD7BE051CFDE548003C77BB /* StatesController.m in Sources */, 0A3CEE761D055C5E008A4BB0 /* StatesController+Decisions.m in Sources */, 0AC4CD911D0BDDD000829E45 /* STTextField.m in Sources */, 0AAB1C541CFF33C8006512AF /* STLayerState.m in Sources */, 0A4BDCAE1CFEBDC600D3584F /* STSketch.m in Sources */, 0A9CBE411D09DEFB00748DFA /* STHeaderView.m in Sources */, 0A3CBDB61D0A6BB10016EFD8 /* STColorFactory.m in Sources */, 0A3CEE731D055B6F008A4BB0 /* StatesController+Naming.m in Sources */, 0A3CEE791D05693E008A4BB0 /* StatesController+ContextMenu.m in Sources */, 0A12AE5E1D13A62300CBB026 /* STStatefulArtboard+Snapshots.m in Sources */, 0AC4CD941D0BE52300829E45 /* NSArray+HigherOrder.m in Sources */, 0A9CBE3E1D09D8C700748DFA /* STTableCellView.m in Sources */, 0AAB1C5B1CFF3D56006512AF /* STStateDescription.m in Sources */, 0AE8BF421D02FC6E00E0C4A8 /* STStatefulArtboard+Backend.m in Sources */, 0AAB1C5E1CFF40CA006512AF /* STStatefulArtboard.m in Sources */, 0AE014F91D0EB3EA00F39C32 /* StatesController+DragNDrop.m in Sources */, 0A4BDCBA1CFED17200D3584F /* STSketchPluginContext.m in Sources */, 0AE014F61D0EA24C00F39C32 /* NSArray+Indexes.m in Sources */, 0AB737AC1D04512600E79D3D /* STTableView.m in Sources */, 0A9C85941D0B001B00231073 /* STPlaceholderView.m in Sources */, 0A7160F31D09279C008A3F78 /* STUpdateButton.m in Sources */, 0A4BDCB61CFEC5C200D3584F /* Aspects.m in Sources */, 0A2C50EA1D09C87800CB3C9F /* STWindow.m in Sources */, 0A3CBDB31D0A61C40016EFD8 /* STTableRowView.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ /* Begin XCBuildConfiguration section */ 0A3CE59B1CFCBB6800B8C552 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", ); GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; MACOSX_DEPLOYMENT_TARGET = 10.10; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; }; name = Debug; }; 0A3CE59C1CFCBB6800B8C552 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; MACOSX_DEPLOYMENT_TARGET = 10.10; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; }; name = Release; }; 0A3CE59E1CFCBB6800B8C552 /* Debug */ = { isa = XCBuildConfiguration; baseConfigurationReference = 0A291EAB1D59C0A10003F2A3 /* Debug.xcconfig */; buildSettings = { CODE_SIGN_IDENTITY = "Developer ID Application: Dmitry Rodionov (C6QG5C28K7)"; COMBINE_HIDPI_IMAGES = YES; INFOPLIST_FILE = States/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Bundles"; OTHER_LDFLAGS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = "com.edenvidal.states-for-sketch"; PRODUCT_NAME = States; SKIP_INSTALL = YES; WRAPPER_EXTENSION = bundle; }; name = Debug; }; 0A3CE59F1CFCBB6800B8C552 /* Release */ = { isa = XCBuildConfiguration; baseConfigurationReference = 0A291EAD1D59C0AA0003F2A3 /* Release.xcconfig */; buildSettings = { CODE_SIGN_IDENTITY = "Developer ID Application: Dmitry Rodionov (C6QG5C28K7)"; COMBINE_HIDPI_IMAGES = YES; INFOPLIST_FILE = States/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Bundles"; OTHER_LDFLAGS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = "com.edenvidal.states-for-sketch"; PRODUCT_NAME = States; SKIP_INSTALL = YES; WRAPPER_EXTENSION = bundle; }; name = Release; }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ 0A3CE5921CFCBB6800B8C552 /* Build configuration list for PBXProject "States" */ = { isa = XCConfigurationList; buildConfigurations = ( 0A3CE59B1CFCBB6800B8C552 /* Debug */, 0A3CE59C1CFCBB6800B8C552 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; 0A3CE59D1CFCBB6800B8C552 /* Build configuration list for PBXNativeTarget "States" */ = { isa = XCConfigurationList; buildConfigurations = ( 0A3CE59E1CFCBB6800B8C552 /* Debug */, 0A3CE59F1CFCBB6800B8C552 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; rootObject = 0A3CE58F1CFCBB6800B8C552 /* Project object */; } ================================================ FILE: Plugin/States.xcodeproj/project.xcworkspace/contents.xcworkspacedata ================================================ ================================================ FILE: Plugin/States.xcodeproj/xcshareddata/xcschemes/States for Beta.xcscheme ================================================ ================================================ FILE: Plugin/States.xcodeproj/xcshareddata/xcschemes/States.xcscheme ================================================ ================================================ FILE: Plugin/Versioning.xcconfig ================================================ IEXP_SOURCE_VERSION = 1.0.0 ================================================ FILE: Plugin/lib/runtime.js ================================================ // runtime.js // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. (function(){ this.runtime = {}; /// This function fetches the plugin path from a current script path this.runtime.pluginPath = function() { var result = [NSString stringWithString: coscript.env().scriptURL.path()]; while(result.lastPathComponent().pathExtension() != "sketchplugin"){ result = result.stringByDeletingLastPathComponent(); } return result; } /// This function loads a bundle with the given name located in Resources directory /// of this plugin this.runtime.loadBundle = function(bundleName) { var bundlePath = runtime.pluginPath() + "/Contents/Resources/" + bundleName; var bundle = [NSBundle bundleWithPath: bundlePath]; bundle.load(); } })(); ================================================ FILE: Plugin/manifest.json ================================================ { "name": "States", "description": "Create different artboard states and switch between them easily", "author": "Eden Vidal", "homepage": "http://edenvidal.com", "version": "1.0.0", "identifier": "com.edenvidal.states-for-sketch", "compatibleVersion": 3, "bundleVersion": 1, "commands": [{ "name": "Show States", "identifier": "show-states", "script": "plugin.js", "handler": "showStatesWindow" }], "menu": { "items": ["show-states"], "isRoot": true } } ================================================ FILE: Plugin/plugin.js ================================================ // plugin.js // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. @import "lib/runtime.js" function showStatesWindow(context) { if (NSClassFromString("STStatesController") == null) { runtime.loadBundle("States.bundle"); [STSketch setPluginContextDictionary: context]; } var controller = [StatesController defaultController]; if ([[controller window] isVisible]) { [[controller window] close]; } else { [controller showWindow: nil]; } [STSketch toggleStatesPluginName]; } ================================================ FILE: Plugin/vendor/Aspects.h ================================================ // // Aspects.h // Aspects - A delightful, simple library for aspect oriented programming. // // Copyright (c) 2014 Peter Steinberger. Licensed under the MIT license. // #import typedef NS_OPTIONS(NSUInteger, AspectOptions) { AspectPositionAfter = 0, /// Called after the original implementation (default) AspectPositionInstead = 1, /// Will replace the original implementation. AspectPositionBefore = 2, /// Called before the original implementation. AspectOptionAutomaticRemoval = 1 << 3 /// Will remove the hook after the first execution. }; /// Opaque Aspect Token that allows to deregister the hook. @protocol AspectToken /// Deregisters an aspect. /// @return YES if deregistration is successful, otherwise NO. - (BOOL)remove; @end /// The AspectInfo protocol is the first parameter of our block syntax. @protocol AspectInfo /// The instance that is currently hooked. - (id)instance; /// The original invocation of the hooked method. - (NSInvocation *)originalInvocation; /// All method arguments, boxed. This is lazily evaluated. - (NSArray *)arguments; @end /** Aspects uses Objective-C message forwarding to hook into messages. This will create some overhead. Don't add aspects to methods that are called a lot. Aspects is meant for view/controller code that is not called a 1000 times per second. Adding aspects returns an opaque token which can be used to deregister again. All calls are thread safe. */ @interface NSObject (Aspects) /// Adds a block of code before/instead/after the current `selector` for a specific class. /// /// @param block Aspects replicates the type signature of the method being hooked. /// The first parameter will be `id`, followed by all parameters of the method. /// These parameters are optional and will be filled to match the block signature. /// You can even use an empty block, or one that simple gets `id`. /// /// @note Hooking static methods is not supported. /// @return A token which allows to later deregister the aspect. + (id)aspect_hookSelector:(SEL)selector withOptions:(AspectOptions)options usingBlock:(id)block error:(NSError **)error; /// Adds a block of code before/instead/after the current `selector` for a specific instance. - (id)aspect_hookSelector:(SEL)selector withOptions:(AspectOptions)options usingBlock:(id)block error:(NSError **)error; @end typedef NS_ENUM(NSUInteger, AspectErrorCode) { AspectErrorSelectorBlacklisted, /// Selectors like release, retain, autorelease are blacklisted. AspectErrorDoesNotRespondToSelector, /// Selector could not be found. AspectErrorSelectorDeallocPosition, /// When hooking dealloc, only AspectPositionBefore is allowed. AspectErrorSelectorAlreadyHookedInClassHierarchy, /// Statically hooking the same method in subclasses is not allowed. AspectErrorFailedToAllocateClassPair, /// The runtime failed creating a class pair. AspectErrorMissingBlockSignature, /// The block misses compile time signature info and can't be called. AspectErrorIncompatibleBlockSignature, /// The block signature does not match the method or is too large. AspectErrorRemoveObjectAlreadyDeallocated = 100 /// (for removing) The object hooked is already deallocated. }; extern NSString *const AspectErrorDomain; ================================================ FILE: Plugin/vendor/Aspects.m ================================================ // // Aspects.m // Aspects - A delightful, simple library for aspect oriented programming. // // Copyright (c) 2014 Peter Steinberger. Licensed under the MIT license. // #import "Aspects.h" #import #import #import #define AspectLog(...) //#define AspectLog(...) do { NSLog(__VA_ARGS__); }while(0) #define AspectLogError(...) do { NSLog(__VA_ARGS__); }while(0) // Block internals. typedef NS_OPTIONS(int, AspectBlockFlags) { AspectBlockFlagsHasCopyDisposeHelpers = (1 << 25), AspectBlockFlagsHasSignature = (1 << 30) }; typedef struct _AspectBlock { __unused Class isa; AspectBlockFlags flags; __unused int reserved; void (__unused *invoke)(struct _AspectBlock *block, ...); struct { unsigned long int reserved; unsigned long int size; // requires AspectBlockFlagsHasCopyDisposeHelpers void (*copy)(void *dst, const void *src); void (*dispose)(const void *); // requires AspectBlockFlagsHasSignature const char *signature; const char *layout; } *descriptor; // imported variables } *AspectBlockRef; @interface AspectInfo : NSObject - (id)initWithInstance:(__unsafe_unretained id)instance invocation:(NSInvocation *)invocation; @property (nonatomic, unsafe_unretained, readonly) id instance; @property (nonatomic, strong, readonly) NSArray *arguments; @property (nonatomic, strong, readonly) NSInvocation *originalInvocation; @end // Tracks a single aspect. @interface AspectIdentifier : NSObject + (instancetype)identifierWithSelector:(SEL)selector object:(id)object options:(AspectOptions)options block:(id)block error:(NSError **)error; - (BOOL)invokeWithInfo:(id)info; @property (nonatomic, assign) SEL selector; @property (nonatomic, strong) id block; @property (nonatomic, strong) NSMethodSignature *blockSignature; @property (nonatomic, weak) id object; @property (nonatomic, assign) AspectOptions options; @end // Tracks all aspects for an object/class. @interface AspectsContainer : NSObject - (void)addAspect:(AspectIdentifier *)aspect withOptions:(AspectOptions)injectPosition; - (BOOL)removeAspect:(id)aspect; - (BOOL)hasAspects; @property (atomic, copy) NSArray *beforeAspects; @property (atomic, copy) NSArray *insteadAspects; @property (atomic, copy) NSArray *afterAspects; @end @interface AspectTracker : NSObject - (id)initWithTrackedClass:(Class)trackedClass; @property (nonatomic, strong) Class trackedClass; @property (nonatomic, readonly) NSString *trackedClassName; @property (nonatomic, strong) NSMutableSet *selectorNames; @property (nonatomic, strong) NSMutableDictionary *selectorNamesToSubclassTrackers; - (void)addSubclassTracker:(AspectTracker *)subclassTracker hookingSelectorName:(NSString *)selectorName; - (void)removeSubclassTracker:(AspectTracker *)subclassTracker hookingSelectorName:(NSString *)selectorName; - (BOOL)subclassHasHookedSelectorName:(NSString *)selectorName; - (NSSet *)subclassTrackersHookingSelectorName:(NSString *)selectorName; @end @interface NSInvocation (Aspects) - (NSArray *)aspects_arguments; @end #define AspectPositionFilter 0x07 #define AspectError(errorCode, errorDescription) do { \ AspectLogError(@"Aspects: %@", errorDescription); \ if (error) { *error = [NSError errorWithDomain:AspectErrorDomain code:errorCode userInfo:@{NSLocalizedDescriptionKey: errorDescription}]; }}while(0) NSString *const AspectErrorDomain = @"AspectErrorDomain"; static NSString *const AspectsSubclassSuffix = @"_Aspects_"; static NSString *const AspectsMessagePrefix = @"aspects_"; @implementation NSObject (Aspects) /////////////////////////////////////////////////////////////////////////////////////////// #pragma mark - Public Aspects API + (id)aspect_hookSelector:(SEL)selector withOptions:(AspectOptions)options usingBlock:(id)block error:(NSError **)error { return aspect_add((id)self, selector, options, block, error); } /// @return A token which allows to later deregister the aspect. - (id)aspect_hookSelector:(SEL)selector withOptions:(AspectOptions)options usingBlock:(id)block error:(NSError **)error { return aspect_add(self, selector, options, block, error); } /////////////////////////////////////////////////////////////////////////////////////////// #pragma mark - Private Helper static id aspect_add(id self, SEL selector, AspectOptions options, id block, NSError **error) { NSCParameterAssert(self); NSCParameterAssert(selector); NSCParameterAssert(block); __block AspectIdentifier *identifier = nil; aspect_performLocked(^{ if (aspect_isSelectorAllowedAndTrack(self, selector, options, error)) { AspectsContainer *aspectContainer = aspect_getContainerForObject(self, selector); identifier = [AspectIdentifier identifierWithSelector:selector object:self options:options block:block error:error]; if (identifier) { [aspectContainer addAspect:identifier withOptions:options]; // Modify the class to allow message interception. aspect_prepareClassAndHookSelector(self, selector, error); } } }); return identifier; } static BOOL aspect_remove(AspectIdentifier *aspect, NSError **error) { NSCAssert([aspect isKindOfClass:AspectIdentifier.class], @"Must have correct type."); __block BOOL success = NO; aspect_performLocked(^{ id self = aspect.object; // strongify if (self) { AspectsContainer *aspectContainer = aspect_getContainerForObject(self, aspect.selector); success = [aspectContainer removeAspect:aspect]; aspect_cleanupHookedClassAndSelector(self, aspect.selector); // destroy token aspect.object = nil; aspect.block = nil; aspect.selector = NULL; }else { NSString *errrorDesc = [NSString stringWithFormat:@"Unable to deregister hook. Object already deallocated: %@", aspect]; AspectError(AspectErrorRemoveObjectAlreadyDeallocated, errrorDesc); } }); return success; } static void aspect_performLocked(dispatch_block_t block) { static OSSpinLock aspect_lock = OS_SPINLOCK_INIT; OSSpinLockLock(&aspect_lock); block(); OSSpinLockUnlock(&aspect_lock); } static SEL aspect_aliasForSelector(SEL selector) { NSCParameterAssert(selector); return NSSelectorFromString([AspectsMessagePrefix stringByAppendingFormat:@"_%@", NSStringFromSelector(selector)]); } static NSMethodSignature *aspect_blockMethodSignature(id block, NSError **error) { AspectBlockRef layout = (__bridge void *)block; if (!(layout->flags & AspectBlockFlagsHasSignature)) { NSString *description = [NSString stringWithFormat:@"The block %@ doesn't contain a type signature.", block]; AspectError(AspectErrorMissingBlockSignature, description); return nil; } void *desc = layout->descriptor; desc += 2 * sizeof(unsigned long int); if (layout->flags & AspectBlockFlagsHasCopyDisposeHelpers) { desc += 2 * sizeof(void *); } if (!desc) { NSString *description = [NSString stringWithFormat:@"The block %@ doesn't has a type signature.", block]; AspectError(AspectErrorMissingBlockSignature, description); return nil; } const char *signature = (*(const char **)desc); return [NSMethodSignature signatureWithObjCTypes:signature]; } static BOOL aspect_isCompatibleBlockSignature(NSMethodSignature *blockSignature, id object, SEL selector, NSError **error) { NSCParameterAssert(blockSignature); NSCParameterAssert(object); NSCParameterAssert(selector); BOOL signaturesMatch = YES; NSMethodSignature *methodSignature = [[object class] instanceMethodSignatureForSelector:selector]; if (blockSignature.numberOfArguments > methodSignature.numberOfArguments) { signaturesMatch = NO; }else { if (blockSignature.numberOfArguments > 1) { const char *blockType = [blockSignature getArgumentTypeAtIndex:1]; if (blockType[0] != '@') { signaturesMatch = NO; } } // Argument 0 is self/block, argument 1 is SEL or id. We start comparing at argument 2. // The block can have less arguments than the method, that's ok. if (signaturesMatch) { for (NSUInteger idx = 2; idx < blockSignature.numberOfArguments; idx++) { const char *methodType = [methodSignature getArgumentTypeAtIndex:idx]; const char *blockType = [blockSignature getArgumentTypeAtIndex:idx]; // Only compare parameter, not the optional type data. if (!methodType || !blockType || methodType[0] != blockType[0]) { signaturesMatch = NO; break; } } } } if (!signaturesMatch) { NSString *description = [NSString stringWithFormat:@"Block signature %@ doesn't match %@.", blockSignature, methodSignature]; AspectError(AspectErrorIncompatibleBlockSignature, description); return NO; } return YES; } /////////////////////////////////////////////////////////////////////////////////////////// #pragma mark - Class + Selector Preparation static BOOL aspect_isMsgForwardIMP(IMP impl) { return impl == _objc_msgForward #if !defined(__arm64__) || impl == (IMP)_objc_msgForward_stret #endif ; } static IMP aspect_getMsgForwardIMP(NSObject *self, SEL selector) { IMP msgForwardIMP = _objc_msgForward; #if !defined(__arm64__) // As an ugly internal runtime implementation detail in the 32bit runtime, we need to determine of the method we hook returns a struct or anything larger than id. // https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/LowLevelABI/000-Introduction/introduction.html // https://github.com/ReactiveCocoa/ReactiveCocoa/issues/783 // http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042e/IHI0042E_aapcs.pdf (Section 5.4) Method method = class_getInstanceMethod(self.class, selector); const char *encoding = method_getTypeEncoding(method); BOOL methodReturnsStructValue = encoding[0] == _C_STRUCT_B; if (methodReturnsStructValue) { @try { NSUInteger valueSize = 0; NSGetSizeAndAlignment(encoding, &valueSize, NULL); if (valueSize == 1 || valueSize == 2 || valueSize == 4 || valueSize == 8) { methodReturnsStructValue = NO; } } @catch (__unused NSException *e) {} } if (methodReturnsStructValue) { msgForwardIMP = (IMP)_objc_msgForward_stret; } #endif return msgForwardIMP; } static void aspect_prepareClassAndHookSelector(NSObject *self, SEL selector, NSError **error) { NSCParameterAssert(selector); Class klass = aspect_hookClass(self, error); Method targetMethod = class_getInstanceMethod(klass, selector); IMP targetMethodIMP = method_getImplementation(targetMethod); if (!aspect_isMsgForwardIMP(targetMethodIMP)) { // Make a method alias for the existing method implementation, it not already copied. const char *typeEncoding = method_getTypeEncoding(targetMethod); SEL aliasSelector = aspect_aliasForSelector(selector); if (![klass instancesRespondToSelector:aliasSelector]) { __unused BOOL addedAlias = class_addMethod(klass, aliasSelector, method_getImplementation(targetMethod), typeEncoding); NSCAssert(addedAlias, @"Original implementation for %@ is already copied to %@ on %@", NSStringFromSelector(selector), NSStringFromSelector(aliasSelector), klass); } // We use forwardInvocation to hook in. class_replaceMethod(klass, selector, aspect_getMsgForwardIMP(self, selector), typeEncoding); AspectLog(@"Aspects: Installed hook for -[%@ %@].", klass, NSStringFromSelector(selector)); } } // Will undo the runtime changes made. static void aspect_cleanupHookedClassAndSelector(NSObject *self, SEL selector) { NSCParameterAssert(self); NSCParameterAssert(selector); Class klass = object_getClass(self); BOOL isMetaClass = class_isMetaClass(klass); if (isMetaClass) { klass = (Class)self; } // Check if the method is marked as forwarded and undo that. Method targetMethod = class_getInstanceMethod(klass, selector); IMP targetMethodIMP = method_getImplementation(targetMethod); if (aspect_isMsgForwardIMP(targetMethodIMP)) { // Restore the original method implementation. const char *typeEncoding = method_getTypeEncoding(targetMethod); SEL aliasSelector = aspect_aliasForSelector(selector); Method originalMethod = class_getInstanceMethod(klass, aliasSelector); IMP originalIMP = method_getImplementation(originalMethod); NSCAssert(originalMethod, @"Original implementation for %@ not found %@ on %@", NSStringFromSelector(selector), NSStringFromSelector(aliasSelector), klass); class_replaceMethod(klass, selector, originalIMP, typeEncoding); AspectLog(@"Aspects: Removed hook for -[%@ %@].", klass, NSStringFromSelector(selector)); } // Deregister global tracked selector aspect_deregisterTrackedSelector(self, selector); // Get the aspect container and check if there are any hooks remaining. Clean up if there are not. AspectsContainer *container = aspect_getContainerForObject(self, selector); if (!container.hasAspects) { // Destroy the container aspect_destroyContainerForObject(self, selector); // Figure out how the class was modified to undo the changes. NSString *className = NSStringFromClass(klass); if ([className hasSuffix:AspectsSubclassSuffix]) { Class originalClass = NSClassFromString([className stringByReplacingOccurrencesOfString:AspectsSubclassSuffix withString:@""]); NSCAssert(originalClass != nil, @"Original class must exist"); object_setClass(self, originalClass); AspectLog(@"Aspects: %@ has been restored.", NSStringFromClass(originalClass)); // We can only dispose the class pair if we can ensure that no instances exist using our subclass. // Since we don't globally track this, we can't ensure this - but there's also not much overhead in keeping it around. //objc_disposeClassPair(object.class); }else { // Class is most likely swizzled in place. Undo that. if (isMetaClass) { aspect_undoSwizzleClassInPlace((Class)self); }else if (self.class != klass) { aspect_undoSwizzleClassInPlace(klass); } } } } /////////////////////////////////////////////////////////////////////////////////////////// #pragma mark - Hook Class static Class aspect_hookClass(NSObject *self, NSError **error) { NSCParameterAssert(self); Class statedClass = self.class; Class baseClass = object_getClass(self); NSString *className = NSStringFromClass(baseClass); // Already subclassed if ([className hasSuffix:AspectsSubclassSuffix]) { return baseClass; // We swizzle a class object, not a single object. }else if (class_isMetaClass(baseClass)) { return aspect_swizzleClassInPlace((Class)self); // Probably a KVO'ed class. Swizzle in place. Also swizzle meta classes in place. }else if (statedClass != baseClass) { return aspect_swizzleClassInPlace(baseClass); } // Default case. Create dynamic subclass. const char *subclassName = [className stringByAppendingString:AspectsSubclassSuffix].UTF8String; Class subclass = objc_getClass(subclassName); if (subclass == nil) { subclass = objc_allocateClassPair(baseClass, subclassName, 0); if (subclass == nil) { NSString *errrorDesc = [NSString stringWithFormat:@"objc_allocateClassPair failed to allocate class %s.", subclassName]; AspectError(AspectErrorFailedToAllocateClassPair, errrorDesc); return nil; } aspect_swizzleForwardInvocation(subclass); aspect_hookedGetClass(subclass, statedClass); aspect_hookedGetClass(object_getClass(subclass), statedClass); objc_registerClassPair(subclass); } object_setClass(self, subclass); return subclass; } static NSString *const AspectsForwardInvocationSelectorName = @"__aspects_forwardInvocation:"; static void aspect_swizzleForwardInvocation(Class klass) { NSCParameterAssert(klass); // If there is no method, replace will act like class_addMethod. IMP originalImplementation = class_replaceMethod(klass, @selector(forwardInvocation:), (IMP)__ASPECTS_ARE_BEING_CALLED__, "v@:@"); if (originalImplementation) { class_addMethod(klass, NSSelectorFromString(AspectsForwardInvocationSelectorName), originalImplementation, "v@:@"); } AspectLog(@"Aspects: %@ is now aspect aware.", NSStringFromClass(klass)); } static void aspect_undoSwizzleForwardInvocation(Class klass) { NSCParameterAssert(klass); Method originalMethod = class_getInstanceMethod(klass, NSSelectorFromString(AspectsForwardInvocationSelectorName)); Method objectMethod = class_getInstanceMethod(NSObject.class, @selector(forwardInvocation:)); // There is no class_removeMethod, so the best we can do is to retore the original implementation, or use a dummy. IMP originalImplementation = method_getImplementation(originalMethod ?: objectMethod); class_replaceMethod(klass, @selector(forwardInvocation:), originalImplementation, "v@:@"); AspectLog(@"Aspects: %@ has been restored.", NSStringFromClass(klass)); } static void aspect_hookedGetClass(Class class, Class statedClass) { NSCParameterAssert(class); NSCParameterAssert(statedClass); Method method = class_getInstanceMethod(class, @selector(class)); IMP newIMP = imp_implementationWithBlock(^(id self) { return statedClass; }); class_replaceMethod(class, @selector(class), newIMP, method_getTypeEncoding(method)); } /////////////////////////////////////////////////////////////////////////////////////////// #pragma mark - Swizzle Class In Place static void _aspect_modifySwizzledClasses(void (^block)(NSMutableSet *swizzledClasses)) { static NSMutableSet *swizzledClasses; static dispatch_once_t pred; dispatch_once(&pred, ^{ swizzledClasses = [NSMutableSet new]; }); @synchronized(swizzledClasses) { block(swizzledClasses); } } static Class aspect_swizzleClassInPlace(Class klass) { NSCParameterAssert(klass); NSString *className = NSStringFromClass(klass); _aspect_modifySwizzledClasses(^(NSMutableSet *swizzledClasses) { if (![swizzledClasses containsObject:className]) { aspect_swizzleForwardInvocation(klass); [swizzledClasses addObject:className]; } }); return klass; } static void aspect_undoSwizzleClassInPlace(Class klass) { NSCParameterAssert(klass); NSString *className = NSStringFromClass(klass); _aspect_modifySwizzledClasses(^(NSMutableSet *swizzledClasses) { if ([swizzledClasses containsObject:className]) { aspect_undoSwizzleForwardInvocation(klass); [swizzledClasses removeObject:className]; } }); } /////////////////////////////////////////////////////////////////////////////////////////// #pragma mark - Aspect Invoke Point // This is a macro so we get a cleaner stack trace. #define aspect_invoke(aspects, info) \ for (AspectIdentifier *aspect in aspects) {\ [aspect invokeWithInfo:info];\ if (aspect.options & AspectOptionAutomaticRemoval) { \ aspectsToRemove = [aspectsToRemove?:@[] arrayByAddingObject:aspect]; \ } \ } // This is the swizzled forwardInvocation: method. static void __ASPECTS_ARE_BEING_CALLED__(__unsafe_unretained NSObject *self, SEL selector, NSInvocation *invocation) { NSCParameterAssert(self); NSCParameterAssert(invocation); SEL originalSelector = invocation.selector; SEL aliasSelector = aspect_aliasForSelector(invocation.selector); invocation.selector = aliasSelector; AspectsContainer *objectContainer = objc_getAssociatedObject(self, aliasSelector); AspectsContainer *classContainer = aspect_getContainerForClass(object_getClass(self), aliasSelector); AspectInfo *info = [[AspectInfo alloc] initWithInstance:self invocation:invocation]; NSArray *aspectsToRemove = nil; // Before hooks. aspect_invoke(classContainer.beforeAspects, info); aspect_invoke(objectContainer.beforeAspects, info); // Instead hooks. BOOL respondsToAlias = YES; if (objectContainer.insteadAspects.count || classContainer.insteadAspects.count) { aspect_invoke(classContainer.insteadAspects, info); aspect_invoke(objectContainer.insteadAspects, info); }else { Class klass = object_getClass(invocation.target); do { if ((respondsToAlias = [klass instancesRespondToSelector:aliasSelector])) { [invocation invoke]; break; } }while (!respondsToAlias && (klass = class_getSuperclass(klass))); } // After hooks. aspect_invoke(classContainer.afterAspects, info); aspect_invoke(objectContainer.afterAspects, info); // If no hooks are installed, call original implementation (usually to throw an exception) if (!respondsToAlias) { invocation.selector = originalSelector; SEL originalForwardInvocationSEL = NSSelectorFromString(AspectsForwardInvocationSelectorName); if ([self respondsToSelector:originalForwardInvocationSEL]) { ((void( *)(id, SEL, NSInvocation *))objc_msgSend)(self, originalForwardInvocationSEL, invocation); }else { [self doesNotRecognizeSelector:invocation.selector]; } } // Remove any hooks that are queued for deregistration. [aspectsToRemove makeObjectsPerformSelector:@selector(remove)]; } #undef aspect_invoke /////////////////////////////////////////////////////////////////////////////////////////// #pragma mark - Aspect Container Management // Loads or creates the aspect container. static AspectsContainer *aspect_getContainerForObject(NSObject *self, SEL selector) { NSCParameterAssert(self); SEL aliasSelector = aspect_aliasForSelector(selector); AspectsContainer *aspectContainer = objc_getAssociatedObject(self, aliasSelector); if (!aspectContainer) { aspectContainer = [AspectsContainer new]; objc_setAssociatedObject(self, aliasSelector, aspectContainer, OBJC_ASSOCIATION_RETAIN); } return aspectContainer; } static AspectsContainer *aspect_getContainerForClass(Class klass, SEL selector) { NSCParameterAssert(klass); AspectsContainer *classContainer = nil; do { classContainer = objc_getAssociatedObject(klass, selector); if (classContainer.hasAspects) break; }while ((klass = class_getSuperclass(klass))); return classContainer; } static void aspect_destroyContainerForObject(id self, SEL selector) { NSCParameterAssert(self); SEL aliasSelector = aspect_aliasForSelector(selector); objc_setAssociatedObject(self, aliasSelector, nil, OBJC_ASSOCIATION_RETAIN); } /////////////////////////////////////////////////////////////////////////////////////////// #pragma mark - Selector Blacklist Checking static NSMutableDictionary *aspect_getSwizzledClassesDict() { static NSMutableDictionary *swizzledClassesDict; static dispatch_once_t pred; dispatch_once(&pred, ^{ swizzledClassesDict = [NSMutableDictionary new]; }); return swizzledClassesDict; } static BOOL aspect_isSelectorAllowedAndTrack(NSObject *self, SEL selector, AspectOptions options, NSError **error) { static NSSet *disallowedSelectorList; static dispatch_once_t pred; dispatch_once(&pred, ^{ disallowedSelectorList = [NSSet setWithObjects:@"retain", @"release", @"autorelease", @"forwardInvocation:", nil]; }); // Check against the blacklist. NSString *selectorName = NSStringFromSelector(selector); if ([disallowedSelectorList containsObject:selectorName]) { NSString *errorDescription = [NSString stringWithFormat:@"Selector %@ is blacklisted.", selectorName]; AspectError(AspectErrorSelectorBlacklisted, errorDescription); return NO; } // Additional checks. AspectOptions position = options&AspectPositionFilter; if ([selectorName isEqualToString:@"dealloc"] && position != AspectPositionBefore) { NSString *errorDesc = @"AspectPositionBefore is the only valid position when hooking dealloc."; AspectError(AspectErrorSelectorDeallocPosition, errorDesc); return NO; } if (![self respondsToSelector:selector] && ![self.class instancesRespondToSelector:selector]) { NSString *errorDesc = [NSString stringWithFormat:@"Unable to find selector -[%@ %@].", NSStringFromClass(self.class), selectorName]; AspectError(AspectErrorDoesNotRespondToSelector, errorDesc); return NO; } // Search for the current class and the class hierarchy IF we are modifying a class object if (class_isMetaClass(object_getClass(self))) { Class klass = [self class]; NSMutableDictionary *swizzledClassesDict = aspect_getSwizzledClassesDict(); Class currentClass = [self class]; AspectTracker *tracker = swizzledClassesDict[currentClass]; if ([tracker subclassHasHookedSelectorName:selectorName]) { NSSet *subclassTracker = [tracker subclassTrackersHookingSelectorName:selectorName]; NSSet *subclassNames = [subclassTracker valueForKey:@"trackedClassName"]; NSString *errorDescription = [NSString stringWithFormat:@"Error: %@ already hooked subclasses: %@. A method can only be hooked once per class hierarchy.", selectorName, subclassNames]; AspectError(AspectErrorSelectorAlreadyHookedInClassHierarchy, errorDescription); return NO; } do { tracker = swizzledClassesDict[currentClass]; if ([tracker.selectorNames containsObject:selectorName]) { if (klass == currentClass) { // Already modified and topmost! return YES; } NSString *errorDescription = [NSString stringWithFormat:@"Error: %@ already hooked in %@. A method can only be hooked once per class hierarchy.", selectorName, NSStringFromClass(currentClass)]; AspectError(AspectErrorSelectorAlreadyHookedInClassHierarchy, errorDescription); return NO; } } while ((currentClass = class_getSuperclass(currentClass))); // Add the selector as being modified. currentClass = klass; AspectTracker *subclassTracker = nil; do { tracker = swizzledClassesDict[currentClass]; if (!tracker) { tracker = [[AspectTracker alloc] initWithTrackedClass:currentClass]; swizzledClassesDict[(id)currentClass] = tracker; } if (subclassTracker) { [tracker addSubclassTracker:subclassTracker hookingSelectorName:selectorName]; } else { [tracker.selectorNames addObject:selectorName]; } // All superclasses get marked as having a subclass that is modified. subclassTracker = tracker; }while ((currentClass = class_getSuperclass(currentClass))); } else { return YES; } return YES; } static void aspect_deregisterTrackedSelector(id self, SEL selector) { if (!class_isMetaClass(object_getClass(self))) return; NSMutableDictionary *swizzledClassesDict = aspect_getSwizzledClassesDict(); NSString *selectorName = NSStringFromSelector(selector); Class currentClass = [self class]; AspectTracker *subclassTracker = nil; do { AspectTracker *tracker = swizzledClassesDict[currentClass]; if (subclassTracker) { [tracker removeSubclassTracker:subclassTracker hookingSelectorName:selectorName]; } else { [tracker.selectorNames removeObject:selectorName]; } if (tracker.selectorNames.count == 0 && tracker.selectorNamesToSubclassTrackers) { [swizzledClassesDict removeObjectForKey:currentClass]; } subclassTracker = tracker; }while ((currentClass = class_getSuperclass(currentClass))); } @end @implementation AspectTracker - (id)initWithTrackedClass:(Class)trackedClass { if (self = [super init]) { _trackedClass = trackedClass; _selectorNames = [NSMutableSet new]; _selectorNamesToSubclassTrackers = [NSMutableDictionary new]; } return self; } - (BOOL)subclassHasHookedSelectorName:(NSString *)selectorName { return self.selectorNamesToSubclassTrackers[selectorName] != nil; } - (void)addSubclassTracker:(AspectTracker *)subclassTracker hookingSelectorName:(NSString *)selectorName { NSMutableSet *trackerSet = self.selectorNamesToSubclassTrackers[selectorName]; if (!trackerSet) { trackerSet = [NSMutableSet new]; self.selectorNamesToSubclassTrackers[selectorName] = trackerSet; } [trackerSet addObject:subclassTracker]; } - (void)removeSubclassTracker:(AspectTracker *)subclassTracker hookingSelectorName:(NSString *)selectorName { NSMutableSet *trackerSet = self.selectorNamesToSubclassTrackers[selectorName]; [trackerSet removeObject:subclassTracker]; if (trackerSet.count == 0) { [self.selectorNamesToSubclassTrackers removeObjectForKey:selectorName]; } } - (NSSet *)subclassTrackersHookingSelectorName:(NSString *)selectorName { NSMutableSet *hookingSubclassTrackers = [NSMutableSet new]; for (AspectTracker *tracker in self.selectorNamesToSubclassTrackers[selectorName]) { if ([tracker.selectorNames containsObject:selectorName]) { [hookingSubclassTrackers addObject:tracker]; } [hookingSubclassTrackers unionSet:[tracker subclassTrackersHookingSelectorName:selectorName]]; } return hookingSubclassTrackers; } - (NSString *)trackedClassName { return NSStringFromClass(self.trackedClass); } - (NSString *)description { return [NSString stringWithFormat:@"<%@: %@, trackedClass: %@, selectorNames:%@, subclass selector names: %@>", self.class, self, NSStringFromClass(self.trackedClass), self.selectorNames, self.selectorNamesToSubclassTrackers.allKeys]; } @end /////////////////////////////////////////////////////////////////////////////////////////// #pragma mark - NSInvocation (Aspects) @implementation NSInvocation (Aspects) // Thanks to the ReactiveCocoa team for providing a generic solution for this. - (id)aspect_argumentAtIndex:(NSUInteger)index { const char *argType = [self.methodSignature getArgumentTypeAtIndex:index]; // Skip const type qualifier. if (argType[0] == _C_CONST) argType++; #define WRAP_AND_RETURN(type) do { type val = 0; [self getArgument:&val atIndex:(NSInteger)index]; return @(val); } while (0) if (strcmp(argType, @encode(id)) == 0 || strcmp(argType, @encode(Class)) == 0) { __autoreleasing id returnObj; [self getArgument:&returnObj atIndex:(NSInteger)index]; return returnObj; } else if (strcmp(argType, @encode(SEL)) == 0) { SEL selector = 0; [self getArgument:&selector atIndex:(NSInteger)index]; return NSStringFromSelector(selector); } else if (strcmp(argType, @encode(Class)) == 0) { __autoreleasing Class theClass = Nil; [self getArgument:&theClass atIndex:(NSInteger)index]; return theClass; // Using this list will box the number with the appropriate constructor, instead of the generic NSValue. } else if (strcmp(argType, @encode(char)) == 0) { WRAP_AND_RETURN(char); } else if (strcmp(argType, @encode(int)) == 0) { WRAP_AND_RETURN(int); } else if (strcmp(argType, @encode(short)) == 0) { WRAP_AND_RETURN(short); } else if (strcmp(argType, @encode(long)) == 0) { WRAP_AND_RETURN(long); } else if (strcmp(argType, @encode(long long)) == 0) { WRAP_AND_RETURN(long long); } else if (strcmp(argType, @encode(unsigned char)) == 0) { WRAP_AND_RETURN(unsigned char); } else if (strcmp(argType, @encode(unsigned int)) == 0) { WRAP_AND_RETURN(unsigned int); } else if (strcmp(argType, @encode(unsigned short)) == 0) { WRAP_AND_RETURN(unsigned short); } else if (strcmp(argType, @encode(unsigned long)) == 0) { WRAP_AND_RETURN(unsigned long); } else if (strcmp(argType, @encode(unsigned long long)) == 0) { WRAP_AND_RETURN(unsigned long long); } else if (strcmp(argType, @encode(float)) == 0) { WRAP_AND_RETURN(float); } else if (strcmp(argType, @encode(double)) == 0) { WRAP_AND_RETURN(double); } else if (strcmp(argType, @encode(BOOL)) == 0) { WRAP_AND_RETURN(BOOL); } else if (strcmp(argType, @encode(bool)) == 0) { WRAP_AND_RETURN(BOOL); } else if (strcmp(argType, @encode(char *)) == 0) { WRAP_AND_RETURN(const char *); } else if (strcmp(argType, @encode(void (^)(void))) == 0) { __unsafe_unretained id block = nil; [self getArgument:&block atIndex:(NSInteger)index]; return [block copy]; } else { NSUInteger valueSize = 0; NSGetSizeAndAlignment(argType, &valueSize, NULL); unsigned char valueBytes[valueSize]; [self getArgument:valueBytes atIndex:(NSInteger)index]; return [NSValue valueWithBytes:valueBytes objCType:argType]; } return nil; #undef WRAP_AND_RETURN } - (NSArray *)aspects_arguments { NSMutableArray *argumentsArray = [NSMutableArray array]; for (NSUInteger idx = 2; idx < self.methodSignature.numberOfArguments; idx++) { [argumentsArray addObject:[self aspect_argumentAtIndex:idx] ?: NSNull.null]; } return [argumentsArray copy]; } @end /////////////////////////////////////////////////////////////////////////////////////////// #pragma mark - AspectIdentifier @implementation AspectIdentifier + (instancetype)identifierWithSelector:(SEL)selector object:(id)object options:(AspectOptions)options block:(id)block error:(NSError **)error { NSCParameterAssert(block); NSCParameterAssert(selector); NSMethodSignature *blockSignature = aspect_blockMethodSignature(block, error); // TODO: check signature compatibility, etc. if (!aspect_isCompatibleBlockSignature(blockSignature, object, selector, error)) { return nil; } AspectIdentifier *identifier = nil; if (blockSignature) { identifier = [AspectIdentifier new]; identifier.selector = selector; identifier.block = block; identifier.blockSignature = blockSignature; identifier.options = options; identifier.object = object; // weak } return identifier; } - (BOOL)invokeWithInfo:(id)info { NSInvocation *blockInvocation = [NSInvocation invocationWithMethodSignature:self.blockSignature]; NSInvocation *originalInvocation = info.originalInvocation; NSUInteger numberOfArguments = self.blockSignature.numberOfArguments; // Be extra paranoid. We already check that on hook registration. if (numberOfArguments > originalInvocation.methodSignature.numberOfArguments) { AspectLogError(@"Block has too many arguments. Not calling %@", info); return NO; } // The `self` of the block will be the AspectInfo. Optional. if (numberOfArguments > 1) { [blockInvocation setArgument:&info atIndex:1]; } void *argBuf = NULL; for (NSUInteger idx = 2; idx < numberOfArguments; idx++) { const char *type = [originalInvocation.methodSignature getArgumentTypeAtIndex:idx]; NSUInteger argSize; NSGetSizeAndAlignment(type, &argSize, NULL); if (!(argBuf = reallocf(argBuf, argSize))) { AspectLogError(@"Failed to allocate memory for block invocation."); return NO; } [originalInvocation getArgument:argBuf atIndex:idx]; [blockInvocation setArgument:argBuf atIndex:idx]; } [blockInvocation invokeWithTarget:self.block]; if (argBuf != NULL) { free(argBuf); } return YES; } - (NSString *)description { return [NSString stringWithFormat:@"<%@: %p, SEL:%@ object:%@ options:%tu block:%@ (#%tu args)>", self.class, self, NSStringFromSelector(self.selector), self.object, self.options, self.block, self.blockSignature.numberOfArguments]; } - (BOOL)remove { return aspect_remove(self, NULL); } @end /////////////////////////////////////////////////////////////////////////////////////////// #pragma mark - AspectsContainer @implementation AspectsContainer - (BOOL)hasAspects { return self.beforeAspects.count > 0 || self.insteadAspects.count > 0 || self.afterAspects.count > 0; } - (void)addAspect:(AspectIdentifier *)aspect withOptions:(AspectOptions)options { NSParameterAssert(aspect); NSUInteger position = options&AspectPositionFilter; switch (position) { case AspectPositionBefore: self.beforeAspects = [(self.beforeAspects ?:@[]) arrayByAddingObject:aspect]; break; case AspectPositionInstead: self.insteadAspects = [(self.insteadAspects?:@[]) arrayByAddingObject:aspect]; break; case AspectPositionAfter: self.afterAspects = [(self.afterAspects ?:@[]) arrayByAddingObject:aspect]; break; } } - (BOOL)removeAspect:(id)aspect { for (NSString *aspectArrayName in @[NSStringFromSelector(@selector(beforeAspects)), NSStringFromSelector(@selector(insteadAspects)), NSStringFromSelector(@selector(afterAspects))]) { NSArray *array = [self valueForKey:aspectArrayName]; NSUInteger index = [array indexOfObjectIdenticalTo:aspect]; if (array && index != NSNotFound) { NSMutableArray *newArray = [NSMutableArray arrayWithArray:array]; [newArray removeObjectAtIndex:index]; [self setValue:newArray forKey:aspectArrayName]; return YES; } } return NO; } - (NSString *)description { return [NSString stringWithFormat:@"<%@: %p, before:%@, instead:%@, after:%@>", self.class, self, self.beforeAspects, self.insteadAspects, self.afterAspects]; } @end /////////////////////////////////////////////////////////////////////////////////////////// #pragma mark - AspectInfo @implementation AspectInfo @synthesize arguments = _arguments; - (id)initWithInstance:(__unsafe_unretained id)instance invocation:(NSInvocation *)invocation { NSCParameterAssert(instance); NSCParameterAssert(invocation); if (self = [super init]) { _instance = instance; _originalInvocation = invocation; } return self; } - (NSArray *)arguments { // Lazily evaluate arguments, boxing is expensive. if (!_arguments) { _arguments = self.originalInvocation.aspects_arguments; } return _arguments; } @end ================================================ FILE: States.sketchplugin/Contents/Resources/States.bundle/Contents/Info.plist ================================================ BuildMachineOSBuild 15G31 CFBundleDevelopmentRegion en CFBundleExecutable States CFBundleIdentifier com.edenvidal.states-for-sketch CFBundleInfoDictionaryVersion 6.0 CFBundleName States CFBundlePackageType BNDL CFBundleShortVersionString 1.0.0 CFBundleSignature ???? CFBundleSupportedPlatforms MacOSX CFBundleVersion 1 DTCompiler com.apple.compilers.llvm.clang.1_0 DTPlatformBuild 7D1014 DTPlatformVersion GM DTSDKBuild 15E60 DTSDKName macosx10.11 DTXcode 0731 DTXcodeBuild 7D1014 NSHumanReadableCopyright Copyright © 2016 Eden Vidal. All rights reserved. ================================================ FILE: States.sketchplugin/Contents/Resources/States.bundle/Contents/_CodeSignature/CodeResources ================================================ files Resources/StatesWindow.nib tPNG8G23xzx2FF9fJkMeLlowPCg= Resources/dirty.tiff OigIS04hpst041DCQF9TZTP28HM= files2 Resources/StatesWindow.nib hash tPNG8G23xzx2FF9fJkMeLlowPCg= hash2 R+X7XpAk5/v35Io50Z1VeFKd+JD0rIEYCGO62q9luas= Resources/dirty.tiff hash OigIS04hpst041DCQF9TZTP28HM= hash2 7KCD71Cxnh0qc7BUXhpJv/M2LHesZc1jZI4/QyOsTC0= rules ^Resources/ ^Resources/.*\.lproj/ optional weight 1000 ^Resources/.*\.lproj/locversion.plist$ omit weight 1100 ^version.plist$ rules2 .*\.dSYM($|/) weight 11 ^(.*/)?\.DS_Store$ omit weight 2000 ^(Frameworks|SharedFrameworks|PlugIns|Plug-ins|XPCServices|Helpers|MacOS|Library/(Automator|Spotlight|LoginItems))/ nested weight 10 ^.* ^Info\.plist$ omit weight 20 ^PkgInfo$ omit weight 20 ^Resources/ weight 20 ^Resources/.*\.lproj/ optional weight 1000 ^Resources/.*\.lproj/locversion.plist$ omit weight 1100 ^[^/]+$ nested weight 10 ^embedded\.provisionprofile$ weight 20 ^version\.plist$ weight 20 ================================================ FILE: States.sketchplugin/Contents/Sketch/lib/runtime.js ================================================ // runtime.js // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. (function(){ this.runtime = {}; /// This function fetches the plugin path from a current script path this.runtime.pluginPath = function() { var result = [NSString stringWithString: coscript.env().scriptURL.path()]; while(result.lastPathComponent().pathExtension() != "sketchplugin"){ result = result.stringByDeletingLastPathComponent(); } return result; } /// This function loads a bundle with the given name located in Resources directory /// of this plugin this.runtime.loadBundle = function(bundleName) { var bundlePath = runtime.pluginPath() + "/Contents/Resources/" + bundleName; var bundle = [NSBundle bundleWithPath: bundlePath]; bundle.load(); } })(); ================================================ FILE: States.sketchplugin/Contents/Sketch/manifest.json ================================================ { "name": "States", "description": "Create different artboard states and switch between them easily", "author": "Eden Vidal", "homepage": "http://edenvidal.com", "version": "1.0.0", "identifier": "com.edenvidal.states-for-sketch", "compatibleVersion": 3, "bundleVersion": 1, "commands": [{ "name": "Show States", "identifier": "show-states", "script": "plugin.js", "handler": "showStatesWindow" }], "menu": { "items": ["show-states"], "isRoot": true } } ================================================ FILE: States.sketchplugin/Contents/Sketch/plugin.js ================================================ // plugin.js // Copyright (c) 2016 Eden Vidal // // This software may be modified and distributed under the terms // of the MIT license. See the LICENSE file for details. @import "lib/runtime.js" function showStatesWindow(context) { if (NSClassFromString("STStatesController") == null) { runtime.loadBundle("States.bundle"); [STSketch setPluginContextDictionary: context]; } var controller = [StatesController defaultController]; if ([[controller window] isVisible]) { [[controller window] close]; } else { [controller showWindow: nil]; } [STSketch toggleStatesPluginName]; } ================================================ FILE: css/normalize.css ================================================ /*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */ /** * 1. Set default font family to sans-serif. * 2. Prevent iOS and IE text size adjust after device orientation change, * without disabling user zoom. */ html { font-family: sans-serif; /* 1 */ -ms-text-size-adjust: 100%; /* 2 */ -webkit-text-size-adjust: 100%; /* 2 */ } /** * Remove default margin. */ body { margin: 0; } /* HTML5 display definitions ========================================================================== */ /** * Correct `block` display not defined for any HTML5 element in IE 8/9. * Correct `block` display not defined for `details` or `summary` in IE 10/11 * and Firefox. * Correct `block` display not defined for `main` in IE 11. */ article, aside, details, figcaption, figure, footer, header, hgroup, main, menu, nav, section, summary { display: block; } /** * 1. Correct `inline-block` display not defined in IE 8/9. * 2. Normalize vertical alignment of `progress` in Chrome, Firefox, and Opera. */ audio, canvas, progress, video { display: inline-block; /* 1 */ vertical-align: baseline; /* 2 */ } /** * Prevent modern browsers from displaying `audio` without controls. * Remove excess height in iOS 5 devices. */ audio:not([controls]) { display: none; height: 0; } /** * Address `[hidden]` styling not present in IE 8/9/10. * Hide the `template` element in IE 8/9/10/11, Safari, and Firefox < 22. */ [hidden], template { display: none; } /* Links ========================================================================== */ /** * Remove the gray background color from active links in IE 10. */ a { background-color: transparent; } /** * Improve readability of focused elements when they are also in an * active/hover state. */ a:active, a:hover { outline: 0; } /* Text-level semantics ========================================================================== */ /** * Address styling not present in IE 8/9/10/11, Safari, and Chrome. */ abbr[title] { border-bottom: 1px dotted; } /** * Address style set to `bolder` in Firefox 4+, Safari, and Chrome. */ b, strong { font-weight: bold; } /** * Address styling not present in Safari and Chrome. */ dfn { font-style: italic; } /** * Address variable `h1` font-size and margin within `section` and `article` * contexts in Firefox 4+, Safari, and Chrome. */ h1 { font-size: 2em; margin: 0.67em 0; } /** * Address styling not present in IE 8/9. */ mark { background: #ff0; color: #000; } /** * Address inconsistent and variable font size in all browsers. */ small { font-size: 80%; } /** * Prevent `sub` and `sup` affecting `line-height` in all browsers. */ sub, sup { font-size: 75%; line-height: 0; position: relative; vertical-align: baseline; } sup { top: -0.5em; } sub { bottom: -0.25em; } /* Embedded content ========================================================================== */ /** * Remove border when inside `a` element in IE 8/9/10. */ img { border: 0; } /** * Correct overflow not hidden in IE 9/10/11. */ svg:not(:root) { overflow: hidden; } /* Grouping content ========================================================================== */ /** * Address margin not present in IE 8/9 and Safari. */ figure { margin: 1em 40px; } /** * Address differences between Firefox and other browsers. */ hr { box-sizing: content-box; height: 0; } /** * Contain overflow in all browsers. */ pre { overflow: auto; } /** * Address odd `em`-unit font size rendering in all browsers. */ code, kbd, pre, samp { font-family: monospace, monospace; font-size: 1em; } /* Forms ========================================================================== */ /** * Known limitation: by default, Chrome and Safari on OS X allow very limited * styling of `select`, unless a `border` property is set. */ /** * 1. Correct color not being inherited. * Known issue: affects color of disabled elements. * 2. Correct font properties not being inherited. * 3. Address margins set differently in Firefox 4+, Safari, and Chrome. */ button, input, optgroup, select, textarea { color: inherit; /* 1 */ font: inherit; /* 2 */ margin: 0; /* 3 */ } /** * Address `overflow` set to `hidden` in IE 8/9/10/11. */ button { overflow: visible; } /** * Address inconsistent `text-transform` inheritance for `button` and `select`. * All other form control elements do not inherit `text-transform` values. * Correct `button` style inheritance in Firefox, IE 8/9/10/11, and Opera. * Correct `select` style inheritance in Firefox. */ button, select { text-transform: none; } /** * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio` * and `video` controls. * 2. Correct inability to style clickable `input` types in iOS. * 3. Improve usability and consistency of cursor style between image-type * `input` and others. * 4. CUSTOM FOR WEBFLOW: Removed the input[type="submit"] selector to reduce * specificity and defer to the .w-button selector */ button, html input[type="button"], input[type="reset"] { -webkit-appearance: button; /* 2 */ cursor: pointer; /* 3 */ } /** * Re-set default cursor for disabled elements. */ button[disabled], html input[disabled] { cursor: default; } /** * Remove inner padding and border in Firefox 4+. */ button::-moz-focus-inner, input::-moz-focus-inner { border: 0; padding: 0; } /** * Address Firefox 4+ setting `line-height` on `input` using `!important` in * the UA stylesheet. */ input { line-height: normal; } /** * It's recommended that you don't attempt to style these elements. * Firefox's implementation doesn't respect box-sizing, padding, or width. * * 1. Address box sizing set to `content-box` in IE 8/9/10. * 2. Remove excess padding in IE 8/9/10. */ input[type="checkbox"], input[type="radio"] { box-sizing: border-box; /* 1 */ padding: 0; /* 2 */ } /** * Fix the cursor style for Chrome's increment/decrement buttons. For certain * `font-size` values of the `input`, it causes the cursor style of the * decrement button to change from `default` to `text`. */ input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { height: auto; } /** * 1. CUSTOM FOR WEBFLOW: changed from `textfield` to `none` to normalize iOS rounded input * 2. CUSTOM FOR WEBFLOW: box-sizing: content-box rule removed * (similar to normalize.css >=4.0.0) */ input[type="search"] { -webkit-appearance: none; /* 1 */ } /** * Remove inner padding and search cancel button in Safari and Chrome on OS X. * Safari (but not Chrome) clips the cancel button when the search input has * padding (and `textfield` appearance). */ input[type="search"]::-webkit-search-cancel-button, input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; } /** * Define consistent border, margin, and padding. */ fieldset { border: 1px solid #c0c0c0; margin: 0 2px; padding: 0.35em 0.625em 0.75em; } /** * 1. Correct `color` not being inherited in IE 8/9/10/11. * 2. Remove padding so people aren't caught out if they zero out fieldsets. */ legend { border: 0; /* 1 */ padding: 0; /* 2 */ } /** * Remove default vertical scrollbar in IE 8/9/10/11. */ textarea { overflow: auto; } /** * Don't inherit the `font-weight` (applied by a rule above). * NOTE: the default cannot safely be changed in Chrome and Safari on OS X. */ optgroup { font-weight: bold; } /* Tables ========================================================================== */ /** * Remove most spacing between table cells. */ table { border-collapse: collapse; border-spacing: 0; } td, th { padding: 0; } ================================================ FILE: css/states.webflow.css ================================================ body { background-color: #f2f2f2; color: #333; font-size: 16px; line-height: 20px; } h1 { margin-top: 20px; font-size: 74px; line-height: 72px; font-weight: 400; } h2 { margin-top: 20px; margin-bottom: 20px; font-family: 'Playfair Display', sans-serif; font-size: 23px; line-height: 32px; font-weight: 400; letter-spacing: 0.2px; } h3 { margin-top: 20px; margin-bottom: 10px; font-family: 'Playfair Display', sans-serif; font-size: 24px; line-height: 30px; } h5 { margin-top: 10px; margin-bottom: 10px; font-family: 'Playfair Display', sans-serif; font-size: 14px; line-height: 20px; font-style: italic; font-weight: 400; } p { margin-top: 20px; margin-bottom: 20px; color: rgba(0, 0, 0, .5); } a { clear: left; color: #fff; text-decoration: underline; } img { display: inline-block; max-width: 100%; } .section { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; height: 100vh; padding: 8%; -webkit-box-orient: horizontal; -webkit-box-direction: normal; -webkit-flex-direction: row; -ms-flex-direction: row; flex-direction: row; -webkit-justify-content: space-around; -ms-flex-pack: distribute; justify-content: space-around; -webkit-flex-wrap: nowrap; -ms-flex-wrap: nowrap; flex-wrap: nowrap; -webkit-box-align: stretch; -webkit-align-items: stretch; -ms-flex-align: stretch; align-items: stretch; -webkit-align-content: center; -ms-flex-line-pack: center; align-content: center; font-weight: 400; } .section.black { background-color: #000; } .section.black.bg { background-color: #000; background-image: -webkit-linear-gradient(270deg, transparent, rgba(0, 0, 0, .5) 80%, #000), url('../images/mate.gif'); background-image: linear-gradient(180deg, transparent, rgba(0, 0, 0, .5) 80%, #000), url('../images/mate.gif'); background-position: 0px 0px, 50% 50%; background-repeat: repeat, no-repeat; background-attachment: scroll, fixed; } .section.black.bg2 { background-image: -webkit-linear-gradient(90deg, transparent, #000), url('../images/mate.gif'); background-image: linear-gradient(0deg, transparent, #000), url('../images/mate.gif'); background-position: 0px 0px, 50% 50%; background-repeat: repeat, no-repeat; background-attachment: scroll, fixed; } .section.artboard { background-image: url('../images/Animation2.gif'); background-position: 50% 50%; background-repeat: no-repeat; background-attachment: fixed; } ._33 { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; height: 100%; -webkit-box-orient: vertical; -webkit-box-direction: normal; -webkit-flex-direction: column; -ms-flex-direction: column; flex-direction: column; -webkit-box-pack: center; -webkit-justify-content: center; -ms-flex-pack: center; justify-content: center; -webkit-flex-wrap: nowrap; -ms-flex-wrap: nowrap; flex-wrap: nowrap; -webkit-box-align: start; -webkit-align-items: flex-start; -ms-flex-align: start; align-items: flex-start; -webkit-align-content: flex-start; -ms-flex-line-pack: start; align-content: flex-start; -webkit-box-flex: 1; -webkit-flex: 1; -ms-flex: 1; flex: 1; } .button { border: 5px solid #000; background-color: transparent; color: #000; font-size: 18px; } .button.white { padding: 9px 15px; border-color: #fff; color: #fff; } .white { color: #fff; font-weight: 400; } .white.bold { font-weight: 700; } .white.space { margin-bottom: 36px; } .bold { color: #fff; font-weight: 400; } ._75 { width: 75%; -webkit-align-self: center; -ms-flex-item-align: center; align-self: center; } ._25 { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; width: 25%; -webkit-box-orient: vertical; -webkit-box-direction: normal; -webkit-flex-direction: column; -ms-flex-direction: column; flex-direction: column; -webkit-box-align: start; -webkit-align-items: flex-start; -ms-flex-align: start; align-items: flex-start; -webkit-align-self: center; -ms-flex-item-align: center; align-self: center; } ._25.bottom { -webkit-align-self: flex-end; -ms-flex-item-align: end; align-self: flex-end; } ._25.long { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; -webkit-box-orient: vertical; -webkit-box-direction: normal; -webkit-flex-direction: column; -ms-flex-direction: column; flex-direction: column; -webkit-box-pack: justify; -webkit-justify-content: space-between; -ms-flex-pack: justify; justify-content: space-between; -webkit-align-self: stretch; -ms-flex-item-align: stretch; align-self: stretch; } .social { position: fixed; top: 0px; right: 0px; display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; padding: 25px; opacity: 0.5; -webkit-transition: opacity 200ms ease; transition: opacity 200ms ease; } .social:hover { opacity: 1; } .icon { margin-right: 25px; } ._50 { -webkit-align-self: flex-end; -ms-flex-item-align: end; align-self: flex-end; -webkit-flex-basis: 50%; -ms-flex-preferred-size: 50%; flex-basis: 50%; text-align: center; } .center { float: none; text-align: center; } .red { background-color: red; } .link { color: #000; } .link-2 { border-bottom: 1px solid #000; } .none { margin-bottom: 20px; text-decoration: none; } html.w-mod-js *[data-ix="display-none"] { display: none; } @media (max-width: 991px) { .section { height: 100%; -webkit-box-orient: vertical; -webkit-box-direction: normal; -webkit-flex-direction: column; -ms-flex-direction: column; flex-direction: column; } .section.artboard { background-image: none; background-position: 0px 0px; background-repeat: repeat; background-attachment: scroll; } ._75 { width: 100%; } ._25 { width: 100%; } ._25.bottom { margin-bottom: 5%; } } ================================================ FILE: css/webflow.css ================================================ @font-face { font-family: 'webflow-icons'; src: url("data:application/x-font-ttf;charset=utf-8;base64,AAEAAAALAIAAAwAwT1MvMg8SBiUAAAC8AAAAYGNtYXDpP+a4AAABHAAAAFxnYXNwAAAAEAAAAXgAAAAIZ2x5ZmhS2XEAAAGAAAADHGhlYWQTFw3HAAAEnAAAADZoaGVhCXYFgQAABNQAAAAkaG10eCe4A1oAAAT4AAAAMGxvY2EDtALGAAAFKAAAABptYXhwABAAPgAABUQAAAAgbmFtZSoCsMsAAAVkAAABznBvc3QAAwAAAAAHNAAAACAAAwP4AZAABQAAApkCzAAAAI8CmQLMAAAB6wAzAQkAAAAAAAAAAAAAAAAAAAABEAAAAAAAAAAAAAAAAAAAAABAAADpAwPA/8AAQAPAAEAAAAABAAAAAAAAAAAAAAAgAAAAAAADAAAAAwAAABwAAQADAAAAHAADAAEAAAAcAAQAQAAAAAwACAACAAQAAQAg5gPpA//9//8AAAAAACDmAOkA//3//wAB/+MaBBcIAAMAAQAAAAAAAAAAAAAAAAABAAH//wAPAAEAAAAAAAAAAAACAAA3OQEAAAAAAQAAAAAAAAAAAAIAADc5AQAAAAABAAAAAAAAAAAAAgAANzkBAAAAAAEBIAAAAyADgAAFAAAJAQcJARcDIP5AQAGA/oBAAcABwED+gP6AQAABAOAAAALgA4AABQAAEwEXCQEH4AHAQP6AAYBAAcABwED+gP6AQAAAAwDAAOADQALAAA8AHwAvAAABISIGHQEUFjMhMjY9ATQmByEiBh0BFBYzITI2PQE0JgchIgYdARQWMyEyNj0BNCYDIP3ADRMTDQJADRMTDf3ADRMTDQJADRMTDf3ADRMTDQJADRMTAsATDSANExMNIA0TwBMNIA0TEw0gDRPAEw0gDRMTDSANEwAAAAABAJ0AtAOBApUABQAACQIHCQEDJP7r/upcAXEBcgKU/usBFVz+fAGEAAAAAAL//f+9BAMDwwAEAAkAABcBJwEXAwE3AQdpA5ps/GZsbAOabPxmbEMDmmz8ZmwDmvxmbAOabAAAAgAA/8AEAAPAAB0AOwAABSInLgEnJjU0Nz4BNzYzMTIXHgEXFhUUBw4BBwYjNTI3PgE3NjU0Jy4BJyYjMSIHDgEHBhUUFx4BFxYzAgBqXV6LKCgoKIteXWpqXV6LKCgoKIteXWpVSktvICEhIG9LSlVVSktvICEhIG9LSlVAKCiLXl1qal1eiygoKCiLXl1qal1eiygoZiEgb0tKVVVKS28gISEgb0tKVVVKS28gIQABAAABwAIAA8AAEgAAEzQ3PgE3NjMxFSIHDgEHBhUxIwAoKIteXWpVSktvICFmAcBqXV6LKChmISBvS0pVAAAAAgAA/8AFtgPAADIAOgAAARYXHgEXFhUUBw4BBwYHIxUhIicuAScmNTQ3PgE3NjMxOAExNDc+ATc2MzIXHgEXFhcVATMJATMVMzUEjD83NlAXFxYXTjU1PQL8kz01Nk8XFxcXTzY1PSIjd1BQWlJJSXInJw3+mdv+2/7c25MCUQYcHFg5OUA/ODlXHBwIAhcXTzY1PTw1Nk8XF1tQUHcjIhwcYUNDTgL+3QFt/pOTkwABAAAAAQAAmM7nP18PPPUACwQAAAAAANciZKUAAAAA1yJkpf/9/70FtgPDAAAACAACAAAAAAAAAAEAAAPA/8AAAAW3//3//QW2AAEAAAAAAAAAAAAAAAAAAAAMBAAAAAAAAAAAAAAAAgAAAAQAASAEAADgBAAAwAQAAJ0EAP/9BAAAAAQAAAAFtwAAAAAAAAAKABQAHgAyAEYAjACiAL4BFgE2AY4AAAABAAAADAA8AAMAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAADgCuAAEAAAAAAAEADQAAAAEAAAAAAAIABwCWAAEAAAAAAAMADQBIAAEAAAAAAAQADQCrAAEAAAAAAAUACwAnAAEAAAAAAAYADQBvAAEAAAAAAAoAGgDSAAMAAQQJAAEAGgANAAMAAQQJAAIADgCdAAMAAQQJAAMAGgBVAAMAAQQJAAQAGgC4AAMAAQQJAAUAFgAyAAMAAQQJAAYAGgB8AAMAAQQJAAoANADsd2ViZmxvdy1pY29ucwB3AGUAYgBmAGwAbwB3AC0AaQBjAG8AbgBzVmVyc2lvbiAxLjAAVgBlAHIAcwBpAG8AbgAgADEALgAwd2ViZmxvdy1pY29ucwB3AGUAYgBmAGwAbwB3AC0AaQBjAG8AbgBzd2ViZmxvdy1pY29ucwB3AGUAYgBmAGwAbwB3AC0AaQBjAG8AbgBzUmVndWxhcgBSAGUAZwB1AGwAYQByd2ViZmxvdy1pY29ucwB3AGUAYgBmAGwAbwB3AC0AaQBjAG8AbgBzRm9udCBnZW5lcmF0ZWQgYnkgSWNvTW9vbi4ARgBvAG4AdAAgAGcAZQBuAGUAcgBhAHQAZQBkACAAYgB5ACAASQBjAG8ATQBvAG8AbgAuAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==") format('truetype'); font-weight: normal; font-style: normal; } [class^="w-icon-"], [class*=" w-icon-"] { /* use !important to prevent issues with browser extensions that change fonts */ font-family: 'webflow-icons' !important; speak: none; font-style: normal; font-weight: normal; font-variant: normal; text-transform: none; line-height: 1; /* Better Font Rendering =========== */ -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } .w-icon-slider-right:before { content: "\e600"; } .w-icon-slider-left:before { content: "\e601"; } .w-icon-nav-menu:before { content: "\e602"; } .w-icon-arrow-down:before, .w-icon-dropdown-toggle:before { content: "\e603"; } .w-icon-file-upload-remove:before { content: "\e900"; } .w-icon-file-upload-icon:before { content: "\e903"; } * { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } html { height: 100%; } body { margin: 0; min-height: 100%; background-color: #fff; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; color: #333; } img { max-width: 100%; vertical-align: middle; display: inline-block; } html.w-mod-touch * { background-attachment: scroll !important; } .w-block { display: block; } .w-inline-block { max-width: 100%; display: inline-block; } .w-clearfix:before, .w-clearfix:after { content: " "; display: table; } .w-clearfix:after { clear: both; } .w-hidden { display: none; } .w-button { display: inline-block; padding: 9px 15px; background-color: #3898EC; color: white; border: 0; line-height: inherit; text-decoration: none; cursor: pointer; border-radius: 0; } input.w-button { -webkit-appearance: button; } html[data-w-dynpage] [data-w-cloak] { color: transparent !important; } .w-webflow-badge, .w-webflow-badge * { position: static; left: auto; top: auto; right: auto; bottom: auto; z-index: auto; display: block; visibility: visible; overflow: visible; overflow-x: visible; overflow-y: visible; box-sizing: border-box; width: auto; height: auto; max-height: none; max-width: none; min-height: 0; min-width: 0; margin: 0; padding: 0; float: none; clear: none; border: 0 none transparent; border-radius: 0; background: none; background-image: none; background-position: 0% 0%; background-size: auto auto; background-repeat: repeat; background-origin: padding-box; background-clip: border-box; background-attachment: scroll; background-color: transparent; box-shadow: none; opacity: 1.0; transform: none; transition: none; direction: ltr; font-family: inherit; font-weight: inherit; color: inherit; font-size: inherit; line-height: inherit; font-style: inherit; font-variant: inherit; text-align: inherit; letter-spacing: inherit; text-decoration: inherit; text-indent: 0; text-transform: inherit; list-style-type: disc; text-shadow: none; font-smoothing: auto; vertical-align: baseline; cursor: inherit; white-space: inherit; word-break: normal; word-spacing: normal; word-wrap: normal; } .w-webflow-badge { position: fixed !important; display: inline-block !important; visibility: visible !important; opacity: 1 !important; z-index: 2147483647 !important; top: auto !important; right: 12px !important; bottom: 12px !important; left: auto !important; color: #AAADB0 !important; background-color: #fff !important; border-radius: 3px !important; padding: 6px 8px 6px 6px !important; font-size: 12px !important; opacity: 1.0 !important; line-height: 14px !important; text-decoration: none !important; transform: none !important; margin: 0 !important; width: auto !important; height: auto !important; overflow: visible !important; white-space: nowrap; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1), 0px 1px 3px rgba(0, 0, 0, 0.1); } .w-webflow-badge > img { display: inline-block !important; visibility: visible !important; opacity: 1 !important; vertical-align: middle !important; } h1, h2, h3, h4, h5, h6 { font-weight: bold; margin-bottom: 10px; } h1 { font-size: 38px; line-height: 44px; margin-top: 20px; } h2 { font-size: 32px; line-height: 36px; margin-top: 20px; } h3 { font-size: 24px; line-height: 30px; margin-top: 20px; } h4 { font-size: 18px; line-height: 24px; margin-top: 10px; } h5 { font-size: 14px; line-height: 20px; margin-top: 10px; } h6 { font-size: 12px; line-height: 18px; margin-top: 10px; } p { margin-top: 0; margin-bottom: 10px; } blockquote { margin: 0 0 10px 0; padding: 10px 20px; border-left: 5px solid #E2E2E2; font-size: 18px; line-height: 22px; } figure { margin: 0; margin-bottom: 10px; } figcaption { margin-top: 5px; text-align: center; } ul, ol { margin-top: 0px; margin-bottom: 10px; padding-left: 40px; } .w-list-unstyled { padding-left: 0; list-style: none; } .w-embed:before, .w-embed:after { content: " "; display: table; } .w-embed:after { clear: both; } .w-video { width: 100%; position: relative; padding: 0; } .w-video iframe, .w-video object, .w-video embed { position: absolute; top: 0; left: 0; width: 100%; height: 100%; } fieldset { padding: 0; margin: 0; border: 0; } button, html input[type="button"], input[type="reset"] { border: 0; cursor: pointer; -webkit-appearance: button; } .w-form { margin: 0 0 15px; } .w-form-done { display: none; padding: 20px; text-align: center; background-color: #dddddd; } .w-form-fail { display: none; margin-top: 10px; padding: 10px; background-color: #ffdede; } label { display: block; margin-bottom: 5px; font-weight: bold; } .w-input, .w-select { display: block; width: 100%; height: 38px; padding: 8px 12px; margin-bottom: 10px; font-size: 14px; line-height: 1.428571429; color: #333333; vertical-align: middle; background-color: #ffffff; border: 1px solid #cccccc; } .w-input:-moz-placeholder, .w-select:-moz-placeholder { color: #999; } .w-input::-moz-placeholder, .w-select::-moz-placeholder { color: #999; opacity: 1; } .w-input:-ms-input-placeholder, .w-select:-ms-input-placeholder { color: #999; } .w-input::-webkit-input-placeholder, .w-select::-webkit-input-placeholder { color: #999; } .w-input:focus, .w-select:focus { border-color: #3898EC; outline: 0; } .w-input[disabled], .w-select[disabled], .w-input[readonly], .w-select[readonly], fieldset[disabled] .w-input, fieldset[disabled] .w-select { cursor: not-allowed; background-color: #eeeeee; } textarea.w-input, textarea.w-select { height: auto; } .w-select { background-image: -webkit-linear-gradient(white 0%, #f3f3f3 100%); background-image: linear-gradient(white 0%, #f3f3f3 100%); } .w-select[multiple] { height: auto; } .w-form-label { display: inline-block; cursor: pointer; font-weight: normal; margin-bottom: 0px; } .w-checkbox, .w-radio { display: block; margin-bottom: 5px; padding-left: 20px; } .w-checkbox:before, .w-radio:before, .w-checkbox:after, .w-radio:after { content: " "; display: table; } .w-checkbox:after, .w-radio:after { clear: both; } .w-checkbox-input, .w-radio-input { margin: 4px 0 0; margin-top: 1px \9; line-height: normal; float: left; margin-left: -20px; } .w-radio-input { margin-top: 3px; } .w-file-upload { display: block; margin-bottom: 10px; } .w-file-upload-input { width: 0.1px; height: 0.1px; opacity: 0; overflow: hidden; position: absolute; z-index: -100; } .w-file-upload-default, .w-file-upload-uploading, .w-file-upload-success { display: inline-block; color: #333333; } .w-file-upload-error { display: block; margin-top: 10px; } .w-file-upload-default.w-hidden, .w-file-upload-uploading.w-hidden, .w-file-upload-error.w-hidden, .w-file-upload-success.w-hidden { display: none; } .w-file-upload-uploading-btn { display: flex; font-size: 14px; font-weight: normal; cursor: pointer; margin: 0; padding: 8px 12px; border: 1px solid #cccccc; background-color: #fafafa; } .w-file-upload-uploading-bg-img { display: inline-block; padding-left: 40px; background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzMCAzMCI+PHBhdGggZmlsbD0iY3VycmVudENvbG9yIiBvcGFjaXR5PSIuMiIgZD0iTTE1IDMwYTE1IDE1IDAgMSAxIDAtMzAgMTUgMTUgMCAwIDEgMCAzMHptMC0zYTEyIDEyIDAgMSAwIDAtMjQgMTIgMTIgMCAwIDAgMCAyNHoiLz48cGF0aCBmaWxsPSJjdXJyZW50Q29sb3IiIG9wYWNpdHk9Ii43NSIgZD0iTTAgMTVBMTUgMTUgMCAwIDEgMTUgMHYzQTEyIDEyIDAgMCAwIDMgMTVIMHoiPjxhbmltYXRlVHJhbnNmb3JtIGF0dHJpYnV0ZU5hbWU9InRyYW5zZm9ybSIgYXR0cmlidXRlVHlwZT0iWE1MIiBkdXI9IjAuNnMiIGZyb209IjAgMTUgMTUiIHJlcGVhdENvdW50PSJpbmRlZmluaXRlIiB0bz0iMzYwIDE1IDE1IiB0eXBlPSJyb3RhdGUiLz48L3BhdGg+PC9zdmc+"); background-position: 12px 50%; background-size: 20px 20px; background-repeat: no-repeat; } .w-file-upload-file { display: flex; flex-grow: 1; justify-content: space-between; margin: 0; padding: 8px 9px 8px 11px; border: 1px solid #cccccc; background-color: #fafafa; } .w-file-upload-file-name { font-size: 14px; font-weight: normal; display: block; } .w-file-remove-link { margin-top: 3px; margin-left: 10px; width: auto; height: auto; padding: 3px; display: block; cursor: pointer; } .w-icon-file-upload-remove { margin: auto; font-size: 10px; } .w-file-upload-error-msg { display: inline-block; color: #ea384c; padding: 2px 0; } .w-file-upload-info { display: inline-block; line-height: 38px; padding: 0 12px; } .w-file-upload-label { display: inline-block; font-size: 14px; font-weight: normal; cursor: pointer; margin: 0; padding: 8px 12px; border: 1px solid #cccccc; background-color: #fafafa; } .w-file-upload-label-bg-img { padding-left: 40px; background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyMCAxNCI+PHBhdGggZmlsbD0iY3VycmVudENvbG9yIiBkPSJNMTUuOTIgNS4wMmE0LjUgNC41IDAgMCAxIC4wOCA4Ljk1VjE0SDRhNCA0IDAgMSAxIDAtOCA2IDYgMCAwIDEgMTEuOTItLjk4ek0xMSA5aDNsLTQtNS00IDVoM3YyaDJWOXoiLz48L3N2Zz4="); background-position: 12px 50%; background-size: 20px 20px; background-repeat: no-repeat; } .w-icon-file-upload-icon, .w-icon-file-upload-uploading { display: inline-block; margin-right: 8px; width: 20px; } .w-icon-file-upload-uploading { height: 20px; } .w-container { margin-left: auto; margin-right: auto; max-width: 940px; } .w-container:before, .w-container:after { content: " "; display: table; } .w-container:after { clear: both; } .w-container .w-row { margin-left: -10px; margin-right: -10px; } .w-row:before, .w-row:after { content: " "; display: table; } .w-row:after { clear: both; } .w-row .w-row { margin-left: 0; margin-right: 0; } .w-col { position: relative; float: left; width: 100%; min-height: 1px; padding-left: 10px; padding-right: 10px; } .w-col .w-col { padding-left: 0; padding-right: 0; } .w-col-1 { width: 8.33333333%; } .w-col-2 { width: 16.66666667%; } .w-col-3 { width: 25%; } .w-col-4 { width: 33.33333333%; } .w-col-5 { width: 41.66666667%; } .w-col-6 { width: 50%; } .w-col-7 { width: 58.33333333%; } .w-col-8 { width: 66.66666667%; } .w-col-9 { width: 75%; } .w-col-10 { width: 83.33333333%; } .w-col-11 { width: 91.66666667%; } .w-col-12 { width: 100%; } .w-hidden-main { display: none !important; } @media screen and (max-width: 991px) { .w-container { max-width: 728px; } .w-hidden-main { display: inherit !important; } .w-hidden-medium { display: none !important; } .w-col-medium-1 { width: 8.33333333%; } .w-col-medium-2 { width: 16.66666667%; } .w-col-medium-3 { width: 25%; } .w-col-medium-4 { width: 33.33333333%; } .w-col-medium-5 { width: 41.66666667%; } .w-col-medium-6 { width: 50%; } .w-col-medium-7 { width: 58.33333333%; } .w-col-medium-8 { width: 66.66666667%; } .w-col-medium-9 { width: 75%; } .w-col-medium-10 { width: 83.33333333%; } .w-col-medium-11 { width: 91.66666667%; } .w-col-medium-12 { width: 100%; } .w-col-stack { width: 100%; left: auto; right: auto; } } @media screen and (max-width: 767px) { .w-hidden-main { display: inherit !important; } .w-hidden-medium { display: inherit !important; } .w-hidden-small { display: none !important; } .w-row, .w-container .w-row { margin-left: 0; margin-right: 0; } .w-col { width: 100%; left: auto; right: auto; } .w-col-small-1 { width: 8.33333333%; } .w-col-small-2 { width: 16.66666667%; } .w-col-small-3 { width: 25%; } .w-col-small-4 { width: 33.33333333%; } .w-col-small-5 { width: 41.66666667%; } .w-col-small-6 { width: 50%; } .w-col-small-7 { width: 58.33333333%; } .w-col-small-8 { width: 66.66666667%; } .w-col-small-9 { width: 75%; } .w-col-small-10 { width: 83.33333333%; } .w-col-small-11 { width: 91.66666667%; } .w-col-small-12 { width: 100%; } } @media screen and (max-width: 479px) { .w-container { max-width: none; } .w-hidden-main { display: inherit !important; } .w-hidden-medium { display: inherit !important; } .w-hidden-small { display: inherit !important; } .w-hidden-tiny { display: none !important; } .w-col { width: 100%; } .w-col-tiny-1 { width: 8.33333333%; } .w-col-tiny-2 { width: 16.66666667%; } .w-col-tiny-3 { width: 25%; } .w-col-tiny-4 { width: 33.33333333%; } .w-col-tiny-5 { width: 41.66666667%; } .w-col-tiny-6 { width: 50%; } .w-col-tiny-7 { width: 58.33333333%; } .w-col-tiny-8 { width: 66.66666667%; } .w-col-tiny-9 { width: 75%; } .w-col-tiny-10 { width: 83.33333333%; } .w-col-tiny-11 { width: 91.66666667%; } .w-col-tiny-12 { width: 100%; } } .w-widget { position: relative; } .w-widget-map { width: 100%; height: 400px; } .w-widget-map label { width: auto; display: inline; } .w-widget-map img { max-width: inherit; } .w-widget-map .gm-style-iw { width: 90% !important; height: auto !important; top: 7px !important; left: 6% !important; display: inline; text-align: center; overflow: hidden; } .w-widget-map .gm-style-iw + div { display: none; } .w-widget-twitter { overflow: hidden; } .w-widget-twitter-count-shim { display: inline-block; vertical-align: top; position: relative; width: 28px; height: 20px; text-align: center; background: white; border: #758696 solid 1px; border-radius: 3px; } .w-widget-twitter-count-shim * { pointer-events: none; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .w-widget-twitter-count-shim .w-widget-twitter-count-inner { position: relative; font-size: 15px; line-height: 12px; text-align: center; color: #999; font-family: serif; } .w-widget-twitter-count-shim .w-widget-twitter-count-clear { position: relative; display: block; } .w-widget-twitter-count-shim.w--large { width: 36px; height: 28px; margin-left: 7px; } .w-widget-twitter-count-shim.w--large .w-widget-twitter-count-inner { font-size: 18px; line-height: 18px; } .w-widget-twitter-count-shim:not(.w--vertical) { margin-left: 5px; margin-right: 8px; } .w-widget-twitter-count-shim:not(.w--vertical).w--large { margin-left: 6px; } .w-widget-twitter-count-shim:not(.w--vertical):before, .w-widget-twitter-count-shim:not(.w--vertical):after { top: 50%; left: 0; border: solid transparent; content: " "; height: 0; width: 0; position: absolute; pointer-events: none; } .w-widget-twitter-count-shim:not(.w--vertical):before { border-color: rgba(117, 134, 150, 0); border-right-color: #5d6c7b; border-width: 4px; margin-left: -9px; margin-top: -4px; } .w-widget-twitter-count-shim:not(.w--vertical).w--large:before { border-width: 5px; margin-left: -10px; margin-top: -5px; } .w-widget-twitter-count-shim:not(.w--vertical):after { border-color: rgba(255, 255, 255, 0); border-right-color: white; border-width: 4px; margin-left: -8px; margin-top: -4px; } .w-widget-twitter-count-shim:not(.w--vertical).w--large:after { border-width: 5px; margin-left: -9px; margin-top: -5px; } .w-widget-twitter-count-shim.w--vertical { width: 61px; height: 33px; margin-bottom: 8px; } .w-widget-twitter-count-shim.w--vertical:before, .w-widget-twitter-count-shim.w--vertical:after { top: 100%; left: 50%; border: solid transparent; content: " "; height: 0; width: 0; position: absolute; pointer-events: none; } .w-widget-twitter-count-shim.w--vertical:before { border-color: rgba(117, 134, 150, 0); border-top-color: #5d6c7b; border-width: 5px; margin-left: -5px; } .w-widget-twitter-count-shim.w--vertical:after { border-color: rgba(255, 255, 255, 0); border-top-color: white; border-width: 4px; margin-left: -4px; } .w-widget-twitter-count-shim.w--vertical .w-widget-twitter-count-inner { font-size: 18px; line-height: 22px; } .w-widget-twitter-count-shim.w--vertical.w--large { width: 76px; } .w-widget-gplus { overflow: hidden; } .w-background-video { position: relative; overflow: hidden; height: 500px; color: white; } .w-background-video > video { background-size: cover; background-position: 50% 50%; position: absolute; right: -100%; bottom: -100%; top: -100%; left: -100%; margin: auto; min-width: 100%; min-height: 100%; z-index: -100; } .w-background-video > video::-webkit-media-controls-start-playback-button { display: none !important; -webkit-appearance: none; } .w-slider { position: relative; height: 300px; text-align: center; background: #dddddd; clear: both; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); tap-highlight-color: rgba(0, 0, 0, 0); } .w-slider-mask { position: relative; display: block; overflow: hidden; z-index: 1; left: 0; right: 0; height: 100%; white-space: nowrap; } .w-slide { position: relative; display: inline-block; vertical-align: top; width: 100%; height: 100%; white-space: normal; text-align: left; } .w-slider-nav { position: absolute; z-index: 2; top: auto; right: 0; bottom: 0; left: 0; margin: auto; padding-top: 10px; height: 40px; text-align: center; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); tap-highlight-color: rgba(0, 0, 0, 0); } .w-slider-nav.w-round > div { border-radius: 100%; } .w-slider-nav.w-num > div { width: auto; height: auto; padding: 0.2em 0.5em; font-size: inherit; line-height: inherit; } .w-slider-nav.w-shadow > div { box-shadow: 0 0 3px rgba(51, 51, 51, 0.4); } .w-slider-nav-invert { color: #fff; } .w-slider-nav-invert > div { background-color: rgba(34, 34, 34, 0.4); } .w-slider-nav-invert > div.w-active { background-color: #222; } .w-slider-dot { position: relative; display: inline-block; width: 1em; height: 1em; background-color: rgba(255, 255, 255, 0.4); cursor: pointer; margin: 0 3px 0.5em; transition: background-color 100ms, color 100ms; } .w-slider-dot.w-active { background-color: #fff; } .w-slider-arrow-left, .w-slider-arrow-right { position: absolute; width: 80px; top: 0; right: 0; bottom: 0; left: 0; margin: auto; cursor: pointer; overflow: hidden; color: white; font-size: 40px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); tap-highlight-color: rgba(0, 0, 0, 0); -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .w-slider-arrow-left [class^="w-icon-"], .w-slider-arrow-right [class^="w-icon-"], .w-slider-arrow-left [class*=" w-icon-"], .w-slider-arrow-right [class*=" w-icon-"] { position: absolute; } .w-slider-arrow-left { z-index: 3; right: auto; } .w-slider-arrow-right { z-index: 4; left: auto; } .w-icon-slider-left, .w-icon-slider-right { top: 0; right: 0; bottom: 0; left: 0; margin: auto; width: 1em; height: 1em; } .w-dropdown { display: inline-block; position: relative; text-align: left; margin-left: auto; margin-right: auto; z-index: 900; } .w-dropdown-btn, .w-dropdown-toggle, .w-dropdown-link { position: relative; vertical-align: top; text-decoration: none; color: #222222; padding: 20px; text-align: left; margin-left: auto; margin-right: auto; white-space: nowrap; } .w-dropdown-toggle { -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; display: inline-block; cursor: pointer; padding-right: 40px; } .w-icon-dropdown-toggle { position: absolute; top: 0; right: 0; bottom: 0; margin: auto; margin-right: 20px; width: 1em; height: 1em; } .w-dropdown-list { position: absolute; background: #dddddd; display: none; min-width: 100%; } .w-dropdown-list.w--open { display: block; } .w-dropdown-link { padding: 10px 20px; display: block; color: #222222; } .w-dropdown-link.w--current { color: #0082f3; } .w-nav[data-collapse="all"] .w-dropdown, .w-nav[data-collapse="all"] .w-dropdown-toggle { display: block; } .w-nav[data-collapse="all"] .w-dropdown-list { position: static; } @media screen and (max-width: 991px) { .w-nav[data-collapse="medium"] .w-dropdown, .w-nav[data-collapse="medium"] .w-dropdown-toggle { display: block; } .w-nav[data-collapse="medium"] .w-dropdown-list { position: static; } } @media screen and (max-width: 767px) { .w-nav[data-collapse="small"] .w-dropdown, .w-nav[data-collapse="small"] .w-dropdown-toggle { display: block; } .w-nav[data-collapse="small"] .w-dropdown-list { position: static; } .w-nav-brand { padding-left: 10px; } } @media screen and (max-width: 479px) { .w-nav[data-collapse="tiny"] .w-dropdown, .w-nav[data-collapse="tiny"] .w-dropdown-toggle { display: block; } .w-nav[data-collapse="tiny"] .w-dropdown-list { position: static; } } /** * ## Note * Safari (on both iOS and OS X) does not handle viewport units (vh, vw) well. * For example percentage units do not work on descendants of elements that * have any dimensions expressed in viewport units. It also doesn’t handle them at * all in `calc()`. */ /** * Wrapper around all lightbox elements * * 1. Since the lightbox can receive focus, IE also gives it an outline. * 2. Fixes flickering on Chrome when a transition is in progress * underneath the lightbox. */ .w-lightbox-backdrop { color: #000; cursor: auto; font-family: serif; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; list-style: disc; text-align: start; text-indent: 0; text-shadow: none; text-transform: none; visibility: visible; white-space: normal; word-break: normal; word-spacing: normal; word-wrap: normal; position: fixed; top: 0; right: 0; bottom: 0; left: 0; color: #fff; font-family: "Helvetica Neue", Helvetica, Ubuntu, "Segoe UI", Verdana, sans-serif; font-size: 17px; line-height: 1.2; font-weight: 300; text-align: center; background: rgba(0, 0, 0, 0.9); z-index: 2000; outline: 0; /* 1 */ opacity: 0; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; -webkit-tap-highlight-color: transparent; -webkit-transform: translate(0, 0); /* 2 */ } /** * Neat trick to bind the rubberband effect to our canvas instead of the whole * document on iOS. It also prevents a bug that causes the document underneath to scroll. */ .w-lightbox-backdrop, .w-lightbox-container { height: 100%; overflow: auto; -webkit-overflow-scrolling: touch; } .w-lightbox-content { position: relative; height: 100vh; overflow: hidden; } .w-lightbox-view { position: absolute; width: 100vw; height: 100vh; opacity: 0; } .w-lightbox-view:before { content: ""; height: 100vh; } /* .w-lightbox-content */ .w-lightbox-group, .w-lightbox-group .w-lightbox-view, .w-lightbox-group .w-lightbox-view:before { height: 86vh; } .w-lightbox-frame, .w-lightbox-view:before { display: inline-block; vertical-align: middle; } /* * 1. Remove default margin set by user-agent on the
element. */ .w-lightbox-figure { position: relative; margin: 0; /* 1 */ } .w-lightbox-group .w-lightbox-figure { cursor: pointer; } /** * IE adds image dimensions as width and height attributes on the IMG tag, * but we need both width and height to be set to auto to enable scaling. */ .w-lightbox-img { width: auto; height: auto; max-width: none; } /** * 1. Reset if style is set by user on "All Images" */ .w-lightbox-image { display: block; float: none; /* 1 */ max-width: 100vw; max-height: 100vh; } .w-lightbox-group .w-lightbox-image { max-height: 86vh; } .w-lightbox-caption { position: absolute; right: 0; bottom: 0; left: 0; padding: .5em 1em; background: rgba(0, 0, 0, 0.4); text-align: left; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; } .w-lightbox-embed { position: absolute; top: 0; right: 0; bottom: 0; left: 0; width: 100%; height: 100%; } .w-lightbox-control { position: absolute; top: 0; width: 4em; background-size: 24px; background-repeat: no-repeat; background-position: center; cursor: pointer; -webkit-transition: all .3s; transition: all .3s; } .w-lightbox-left { display: none; bottom: 0; left: 0; /* */ background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9Ii0yMCAwIDI0IDQwIiB3aWR0aD0iMjQiIGhlaWdodD0iNDAiPjxnIHRyYW5zZm9ybT0icm90YXRlKDQ1KSI+PHBhdGggZD0ibTAgMGg1djIzaDIzdjVoLTI4eiIgb3BhY2l0eT0iLjQiLz48cGF0aCBkPSJtMSAxaDN2MjNoMjN2M2gtMjZ6IiBmaWxsPSIjZmZmIi8+PC9nPjwvc3ZnPg=="); } .w-lightbox-right { display: none; right: 0; bottom: 0; /* */ background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9Ii00IDAgMjQgNDAiIHdpZHRoPSIyNCIgaGVpZ2h0PSI0MCI+PGcgdHJhbnNmb3JtPSJyb3RhdGUoNDUpIj48cGF0aCBkPSJtMC0waDI4djI4aC01di0yM2gtMjN6IiBvcGFjaXR5PSIuNCIvPjxwYXRoIGQ9Im0xIDFoMjZ2MjZoLTN2LTIzaC0yM3oiIGZpbGw9IiNmZmYiLz48L2c+PC9zdmc+"); } /* * Without specifying the with and height inside the SVG, all versions of IE render the icon too small. * The bug does not seem to manifest itself if the elements are tall enough such as the above arrows. * (http://stackoverflow.com/questions/16092114/background-size-differs-in-internet-explorer) */ .w-lightbox-close { right: 0; height: 2.6em; /* */ background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9Ii00IDAgMTggMTciIHdpZHRoPSIxOCIgaGVpZ2h0PSIxNyI+PGcgdHJhbnNmb3JtPSJyb3RhdGUoNDUpIj48cGF0aCBkPSJtMCAwaDd2LTdoNXY3aDd2NWgtN3Y3aC01di03aC03eiIgb3BhY2l0eT0iLjQiLz48cGF0aCBkPSJtMSAxaDd2LTdoM3Y3aDd2M2gtN3Y3aC0zdi03aC03eiIgZmlsbD0iI2ZmZiIvPjwvZz48L3N2Zz4="); background-size: 18px; } /** * 1. All IE versions add extra space at the bottom without this. */ .w-lightbox-strip { position: absolute; bottom: 0; left: 0; right: 0; padding: 0 1vh; line-height: 0; /* 1 */ white-space: nowrap; overflow-x: auto; overflow-y: hidden; } /* * 1. We use content-box to avoid having to do `width: calc(10vh + 2vw)` * which doesn’t work in Safari anyway. * 2. Chrome renders images pixelated when switching to GPU. Making sure * the parent is also rendered on the GPU (by setting translate3d for * example) fixes this behavior. */ .w-lightbox-item { display: inline-block; width: 10vh; padding: 2vh 1vh; box-sizing: content-box; /* 1 */ cursor: pointer; -webkit-transform: translate3d(0, 0, 0); /* 2 */ } .w-lightbox-active { opacity: .3; } .w-lightbox-thumbnail { position: relative; height: 10vh; background: #222; overflow: hidden; } .w-lightbox-thumbnail-image { position: absolute; top: 0; left: 0; } .w-lightbox-thumbnail .w-lightbox-tall { top: 50%; width: 100%; -webkit-transform: translate(0, -50%); -ms-transform: translate(0, -50%); transform: translate(0, -50%); } .w-lightbox-thumbnail .w-lightbox-wide { left: 50%; height: 100%; -webkit-transform: translate(-50%, 0); -ms-transform: translate(-50%, 0); transform: translate(-50%, 0); } /* * Spinner * * Absolute pixel values are used to avoid rounding errors that would cause * the white spinning element to be misaligned with the track. */ .w-lightbox-spinner { position: absolute; top: 50%; left: 50%; box-sizing: border-box; width: 40px; height: 40px; margin-top: -20px; margin-left: -20px; border: 5px solid rgba(0, 0, 0, 0.4); border-radius: 50%; -webkit-animation: spin .8s infinite linear; animation: spin .8s infinite linear; } .w-lightbox-spinner:after { content: ""; position: absolute; top: -4px; right: -4px; bottom: -4px; left: -4px; border: 3px solid transparent; border-bottom-color: #fff; border-radius: 50%; } /* * Utility classes */ .w-lightbox-hide { display: none; } .w-lightbox-noscroll { overflow: hidden; } @media (min-width: 768px) { .w-lightbox-content { height: 96vh; margin-top: 2vh; } .w-lightbox-view, .w-lightbox-view:before { height: 96vh; } /* .w-lightbox-content */ .w-lightbox-group, .w-lightbox-group .w-lightbox-view, .w-lightbox-group .w-lightbox-view:before { height: 84vh; } .w-lightbox-image { max-width: 96vw; max-height: 96vh; } .w-lightbox-group .w-lightbox-image { max-width: 82.3vw; max-height: 84vh; } .w-lightbox-left, .w-lightbox-right { display: block; opacity: .5; } .w-lightbox-close { opacity: .8; } .w-lightbox-control:hover { opacity: 1; } } .w-lightbox-inactive, .w-lightbox-inactive:hover { opacity: 0; } .w-richtext:before, .w-richtext:after { content: " "; display: table; } .w-richtext:after { clear: both; } .w-richtext[contenteditable="true"]:before, .w-richtext[contenteditable="true"]:after { white-space: initial; } .w-richtext ol, .w-richtext ul { overflow: hidden; } .w-richtext .w-richtext-figure-selected.w-richtext-figure-type-video div:before, .w-richtext .w-richtext-figure-selected[data-rt-type="video"] div:before { outline: 2px solid #2895f7; } .w-richtext .w-richtext-figure-selected.w-richtext-figure-type-image div, .w-richtext .w-richtext-figure-selected[data-rt-type="image"] div { outline: 2px solid #2895f7; } .w-richtext figure.w-richtext-figure-type-video > div:before, .w-richtext figure[data-rt-type="video"] > div:before { content: ''; position: absolute; display: none; left: 0; top: 0; right: 0; bottom: 0; z-index: 1; } .w-richtext figure { position: relative; max-width: 60%; } .w-richtext figure > div:before { cursor: default!important; } .w-richtext figure img { width: 100%; } .w-richtext figure figcaption.w-richtext-figcaption-placeholder { opacity: 0.6; } .w-richtext figure div { /* fix incorrectly sized selection border in the data manager */ font-size: 0px; color: transparent; } .w-richtext figure.w-richtext-figure-type-image, .w-richtext figure[data-rt-type="image"] { display: table; } .w-richtext figure.w-richtext-figure-type-image > div, .w-richtext figure[data-rt-type="image"] > div { display: inline-block; } .w-richtext figure.w-richtext-figure-type-image > figcaption, .w-richtext figure[data-rt-type="image"] > figcaption { display: table-caption; caption-side: bottom; } .w-richtext figure.w-richtext-figure-type-video, .w-richtext figure[data-rt-type="video"] { width: 60%; height: 0; } .w-richtext figure.w-richtext-figure-type-video iframe, .w-richtext figure[data-rt-type="video"] iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; } .w-richtext figure.w-richtext-figure-type-video > div, .w-richtext figure[data-rt-type="video"] > div { width: 100%; } .w-richtext figure.w-richtext-align-center { margin-right: auto; margin-left: auto; clear: both; } .w-richtext figure.w-richtext-align-center.w-richtext-figure-type-image > div, .w-richtext figure.w-richtext-align-center[data-rt-type="image"] > div { max-width: 100%; } .w-richtext figure.w-richtext-align-normal { clear: both; } .w-richtext figure.w-richtext-align-fullwidth { width: 100%; max-width: 100%; text-align: center; clear: both; display: block; margin-right: auto; margin-left: auto; } .w-richtext figure.w-richtext-align-fullwidth > div { display: inline-block; /* padding-bottom is used for aspect ratios in video figures we want the div to inherit that so hover/selection borders in the designer-canvas fit right*/ padding-bottom: inherit; } .w-richtext figure.w-richtext-align-fullwidth > figcaption { display: block; } .w-richtext figure.w-richtext-align-floatleft { float: left; margin-right: 15px; clear: none; } .w-richtext figure.w-richtext-align-floatright { float: right; margin-left: 15px; clear: none; } .w-nav { position: relative; background: #dddddd; z-index: 1000; } .w-nav:before, .w-nav:after { content: " "; display: table; } .w-nav:after { clear: both; } .w-nav-brand { position: relative; float: left; text-decoration: none; color: #333333; } .w-nav-link { position: relative; display: inline-block; vertical-align: top; text-decoration: none; color: #222222; padding: 20px; text-align: left; margin-left: auto; margin-right: auto; } .w-nav-link.w--current { color: #0082f3; } .w-nav-menu { position: relative; float: right; } .w--nav-menu-open { display: block !important; position: absolute; top: 100%; left: 0; right: 0; background: #C8C8C8; text-align: center; overflow: visible; min-width: 200px; } .w--nav-link-open { display: block; position: relative; } .w-nav-overlay { position: absolute; overflow: hidden; display: none; top: 100%; left: 0; right: 0; width: 100%; } .w-nav-overlay .w--nav-menu-open { top: 0; } .w-nav[data-animation="over-left"] .w-nav-overlay { width: auto; } .w-nav[data-animation="over-left"] .w-nav-overlay, .w-nav[data-animation="over-left"] .w--nav-menu-open { right: auto; z-index: 1; top: 0; } .w-nav[data-animation="over-right"] .w-nav-overlay { width: auto; } .w-nav[data-animation="over-right"] .w-nav-overlay, .w-nav[data-animation="over-right"] .w--nav-menu-open { left: auto; z-index: 1; top: 0; } .w-nav-button { position: relative; float: right; padding: 18px; font-size: 24px; display: none; cursor: pointer; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); tap-highlight-color: rgba(0, 0, 0, 0); -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .w-nav-button.w--open { background-color: #C8C8C8; color: white; } .w-nav[data-collapse="all"] .w-nav-menu { display: none; } .w-nav[data-collapse="all"] .w-nav-button { display: block; } @media screen and (max-width: 991px) { .w-nav[data-collapse="medium"] .w-nav-menu { display: none; } .w-nav[data-collapse="medium"] .w-nav-button { display: block; } } @media screen and (max-width: 767px) { .w-nav[data-collapse="small"] .w-nav-menu { display: none; } .w-nav[data-collapse="small"] .w-nav-button { display: block; } .w-nav-brand { padding-left: 10px; } } @media screen and (max-width: 479px) { .w-nav[data-collapse="tiny"] .w-nav-menu { display: none; } .w-nav[data-collapse="tiny"] .w-nav-button { display: block; } } .w-tabs { position: relative; } .w-tabs:before, .w-tabs:after { content: " "; display: table; } .w-tabs:after { clear: both; } .w-tab-menu { position: relative; } .w-tab-link { position: relative; display: inline-block; vertical-align: top; text-decoration: none; padding: 9px 30px; text-align: left; cursor: pointer; color: #222222; background-color: #dddddd; } .w-tab-link.w--current { background-color: #C8C8C8; } .w-tab-content { position: relative; display: block; overflow: hidden; } .w-tab-pane { position: relative; display: none; } .w--tab-active { display: block; } @media screen and (max-width: 479px) { .w-tab-link { display: block; } } .w-ix-emptyfix:after { content: ""; } @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } .w-dyn-empty { padding: 10px; background-color: #dddddd; } .w-dyn-bind-empty { display: none !important; } .w-condition-invisible { display: none !important; } ================================================ FILE: index.html ================================================ States of the artboard - Sketch Plugin

States
of the
artboard

See how it works

Sketch Plugin

Create different states and switch between them easily. Just like layer comps for Sketch.

Define different positions and toggle visibility of your layers.

Create new states and update changes. Create pages with new artboards from your states.

Created with love for the design community and the good people of the earth.

Read the post on Medium

By Eden Vidal

Please let me know if this works for you and how – any feedback, ideas, or bugs.

================================================ FILE: js/webflow.js ================================================ /*! * Webflow: Front-end site library * @license MIT * Inline scripts may access the api using an async handler: * var Webflow = Webflow || []; * Webflow.push(readyFunction); */!function(t){var e={};function n(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:i})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=2)}([function(t,e,n){var i={},r={},o=[],s=window.Webflow||[],a=window.jQuery,u=a(window),c=a(document),l=a.isFunction,f=i._=n(4),h=n(1)&&a.tram,d=!1,p=!1;function v(t){i.env()&&(l(t.design)&&u.on("__wf_design",t.design),l(t.preview)&&u.on("__wf_preview",t.preview)),l(t.destroy)&&u.on("__wf_destroy",t.destroy),t.ready&&l(t.ready)&&function(t){if(d)return void t.ready();if(f.contains(o,t.ready))return;o.push(t.ready)}(t)}function m(t){l(t.design)&&u.off("__wf_design",t.design),l(t.preview)&&u.off("__wf_preview",t.preview),l(t.destroy)&&u.off("__wf_destroy",t.destroy),t.ready&&l(t.ready)&&function(t){o=f.filter(o,function(e){return e!==t.ready})}(t)}h.config.hideBackface=!1,h.config.keepInherited=!0,i.define=function(t,e,n){r[t]&&m(r[t]);var i=r[t]=e(a,f,n)||{};return v(i),i},i.require=function(t){return r[t]},i.push=function(t){d?l(t)&&t():s.push(t)},i.env=function(t){var e=window.__wf_design,n=void 0!==e;return t?"design"===t?n&&e:"preview"===t?n&&!e:"slug"===t?n&&window.__wf_slug:"editor"===t?window.WebflowEditor:"test"===t?window.__wf_test:"frame"===t?window!==window.top:void 0:n};var w,g=navigator.userAgent.toLowerCase(),b=i.env.touch="ontouchstart"in window||window.DocumentTouch&&document instanceof window.DocumentTouch,y=i.env.chrome=/chrome/.test(g)&&/Google/.test(navigator.vendor)&&parseInt(g.match(/chrome\/(\d+)\./)[1],10),x=i.env.ios=/(ipod|iphone|ipad)/.test(g);i.env.safari=/safari/.test(g)&&!y&&!x,b&&c.on("touchstart mousedown",function(t){w=t.target}),i.validClick=b?function(t){return t===w||a.contains(t,w)}:function(){return!0};var _,k="resize.webflow orientationchange.webflow load.webflow";function z(t,e){var n=[],i={};return i.up=f.throttle(function(t){f.each(n,function(e){e(t)})}),t&&e&&t.on(e,i.up),i.on=function(t){"function"==typeof t&&(f.contains(n,t)||n.push(t))},i.off=function(t){n=arguments.length?f.filter(n,function(e){return e!==t}):[]},i}function T(t){l(t)&&t()}function E(){_&&(_.reject(),u.off("load",_.resolve)),_=new a.Deferred,u.on("load",_.resolve)}i.resize=z(u,k),i.scroll=z(u,"scroll.webflow resize.webflow orientationchange.webflow load.webflow"),i.redraw=z(),i.location=function(t){window.location=t},i.env()&&(i.location=function(){}),i.ready=function(){d=!0,p?(p=!1,f.each(r,v)):f.each(o,T),f.each(s,T),i.resize.up()},i.load=function(t){_.then(t)},i.destroy=function(t){t=t||{},p=!0,u.triggerHandler("__wf_destroy"),null!=t.domready&&(d=t.domready),f.each(r,m),i.resize.off(),i.scroll.off(),i.redraw.off(),o=[],s=[],"pending"===_.state()&&E()},a(i.ready),E(),t.exports=window.Webflow=i},function(t,e){var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};window.tram=function(t){function e(t,e){return(new L.Bare).init(t,e)}function i(t){return t.replace(/[A-Z]/g,function(t){return"-"+t.toLowerCase()})}function r(t){var e=parseInt(t.slice(1),16);return[e>>16&255,e>>8&255,255&e]}function o(t,e,n){return"#"+(1<<24|t<<16|e<<8|n).toString(16).slice(1)}function s(){}function a(t,e,n){c("Units do not match ["+t+"]: "+e+", "+n)}function u(t,e,n){if(void 0!==e&&(n=e),void 0===t)return n;var i=n;return J.test(t)||!V.test(t)?i=parseInt(t,10):V.test(t)&&(i=1e3*parseFloat(t)),0>i&&(i=0),i==i?i:n}function c(t){X.debug&&window&&window.console.warn(t)}var l=function(t,e,i){function r(t){return"object"==(void 0===t?"undefined":n(t))}function o(t){return"function"==typeof t}function s(){}return function n(a,u){function c(){var t=new l;return o(t.init)&&t.init.apply(t,arguments),t}function l(){}u===i&&(u=a,a=Object),c.Bare=l;var f,h=s[t]=a[t],d=l[t]=c[t]=new s;return d.constructor=c,c.mixin=function(e){return l[t]=c[t]=n(c,e)[t],c},c.open=function(t){if(f={},o(t)?f=t.call(c,d,h,c,a):r(t)&&(f=t),r(f))for(var n in f)e.call(f,n)&&(d[n]=f[n]);return o(d.init)||(d.init=a),c},c.open(u)}}("prototype",{}.hasOwnProperty),f={ease:["ease",function(t,e,n,i){var r=(t/=i)*t,o=r*t;return e+n*(-2.75*o*r+11*r*r+-15.5*o+8*r+.25*t)}],"ease-in":["ease-in",function(t,e,n,i){var r=(t/=i)*t,o=r*t;return e+n*(-1*o*r+3*r*r+-3*o+2*r)}],"ease-out":["ease-out",function(t,e,n,i){var r=(t/=i)*t,o=r*t;return e+n*(.3*o*r+-1.6*r*r+2.2*o+-1.8*r+1.9*t)}],"ease-in-out":["ease-in-out",function(t,e,n,i){var r=(t/=i)*t,o=r*t;return e+n*(2*o*r+-5*r*r+2*o+2*r)}],linear:["linear",function(t,e,n,i){return n*t/i+e}],"ease-in-quad":["cubic-bezier(0.550, 0.085, 0.680, 0.530)",function(t,e,n,i){return n*(t/=i)*t+e}],"ease-out-quad":["cubic-bezier(0.250, 0.460, 0.450, 0.940)",function(t,e,n,i){return-n*(t/=i)*(t-2)+e}],"ease-in-out-quad":["cubic-bezier(0.455, 0.030, 0.515, 0.955)",function(t,e,n,i){return(t/=i/2)<1?n/2*t*t+e:-n/2*(--t*(t-2)-1)+e}],"ease-in-cubic":["cubic-bezier(0.550, 0.055, 0.675, 0.190)",function(t,e,n,i){return n*(t/=i)*t*t+e}],"ease-out-cubic":["cubic-bezier(0.215, 0.610, 0.355, 1)",function(t,e,n,i){return n*((t=t/i-1)*t*t+1)+e}],"ease-in-out-cubic":["cubic-bezier(0.645, 0.045, 0.355, 1)",function(t,e,n,i){return(t/=i/2)<1?n/2*t*t*t+e:n/2*((t-=2)*t*t+2)+e}],"ease-in-quart":["cubic-bezier(0.895, 0.030, 0.685, 0.220)",function(t,e,n,i){return n*(t/=i)*t*t*t+e}],"ease-out-quart":["cubic-bezier(0.165, 0.840, 0.440, 1)",function(t,e,n,i){return-n*((t=t/i-1)*t*t*t-1)+e}],"ease-in-out-quart":["cubic-bezier(0.770, 0, 0.175, 1)",function(t,e,n,i){return(t/=i/2)<1?n/2*t*t*t*t+e:-n/2*((t-=2)*t*t*t-2)+e}],"ease-in-quint":["cubic-bezier(0.755, 0.050, 0.855, 0.060)",function(t,e,n,i){return n*(t/=i)*t*t*t*t+e}],"ease-out-quint":["cubic-bezier(0.230, 1, 0.320, 1)",function(t,e,n,i){return n*((t=t/i-1)*t*t*t*t+1)+e}],"ease-in-out-quint":["cubic-bezier(0.860, 0, 0.070, 1)",function(t,e,n,i){return(t/=i/2)<1?n/2*t*t*t*t*t+e:n/2*((t-=2)*t*t*t*t+2)+e}],"ease-in-sine":["cubic-bezier(0.470, 0, 0.745, 0.715)",function(t,e,n,i){return-n*Math.cos(t/i*(Math.PI/2))+n+e}],"ease-out-sine":["cubic-bezier(0.390, 0.575, 0.565, 1)",function(t,e,n,i){return n*Math.sin(t/i*(Math.PI/2))+e}],"ease-in-out-sine":["cubic-bezier(0.445, 0.050, 0.550, 0.950)",function(t,e,n,i){return-n/2*(Math.cos(Math.PI*t/i)-1)+e}],"ease-in-expo":["cubic-bezier(0.950, 0.050, 0.795, 0.035)",function(t,e,n,i){return 0===t?e:n*Math.pow(2,10*(t/i-1))+e}],"ease-out-expo":["cubic-bezier(0.190, 1, 0.220, 1)",function(t,e,n,i){return t===i?e+n:n*(1-Math.pow(2,-10*t/i))+e}],"ease-in-out-expo":["cubic-bezier(1, 0, 0, 1)",function(t,e,n,i){return 0===t?e:t===i?e+n:(t/=i/2)<1?n/2*Math.pow(2,10*(t-1))+e:n/2*(2-Math.pow(2,-10*--t))+e}],"ease-in-circ":["cubic-bezier(0.600, 0.040, 0.980, 0.335)",function(t,e,n,i){return-n*(Math.sqrt(1-(t/=i)*t)-1)+e}],"ease-out-circ":["cubic-bezier(0.075, 0.820, 0.165, 1)",function(t,e,n,i){return n*Math.sqrt(1-(t=t/i-1)*t)+e}],"ease-in-out-circ":["cubic-bezier(0.785, 0.135, 0.150, 0.860)",function(t,e,n,i){return(t/=i/2)<1?-n/2*(Math.sqrt(1-t*t)-1)+e:n/2*(Math.sqrt(1-(t-=2)*t)+1)+e}],"ease-in-back":["cubic-bezier(0.600, -0.280, 0.735, 0.045)",function(t,e,n,i,r){return void 0===r&&(r=1.70158),n*(t/=i)*t*((r+1)*t-r)+e}],"ease-out-back":["cubic-bezier(0.175, 0.885, 0.320, 1.275)",function(t,e,n,i,r){return void 0===r&&(r=1.70158),n*((t=t/i-1)*t*((r+1)*t+r)+1)+e}],"ease-in-out-back":["cubic-bezier(0.680, -0.550, 0.265, 1.550)",function(t,e,n,i,r){return void 0===r&&(r=1.70158),(t/=i/2)<1?n/2*t*t*((1+(r*=1.525))*t-r)+e:n/2*((t-=2)*t*((1+(r*=1.525))*t+r)+2)+e}]},h={"ease-in-back":"cubic-bezier(0.600, 0, 0.735, 0.045)","ease-out-back":"cubic-bezier(0.175, 0.885, 0.320, 1)","ease-in-out-back":"cubic-bezier(0.680, 0, 0.265, 1)"},d=document,p=window,v="bkwld-tram",m=/[\-\.0-9]/g,w=/[A-Z]/,g="number",b=/^(rgb|#)/,y=/(em|cm|mm|in|pt|pc|px)$/,x=/(em|cm|mm|in|pt|pc|px|%)$/,_=/(deg|rad|turn)$/,k="unitless",z=/(all|none) 0s ease 0s/,T=/^(width|height)$/,E=" ",q=d.createElement("a"),O=["Webkit","Moz","O","ms"],A=["-webkit-","-moz-","-o-","-ms-"],S=function(t){if(t in q.style)return{dom:t,css:t};var e,n,i="",r=t.split("-");for(e=0;ec&&(c=t.span),t.stop(),t.animate(e)},function(t){"wait"in t&&(c=u(t.wait,0))}),h.call(this),c>0&&(this.timer=new N({duration:c,context:this}),this.active=!0,e&&(this.timer.complete=s));var p=this,v=!1,m={};B(function(){d.call(p,t,function(t){t.active&&(v=!0,m[t.name]=t.nextStyle)}),v&&p.$el.css(m)})}}}function s(){if(this.timer&&this.timer.destroy(),this.active=!1,this.queue.length){var t=this.queue.shift();o.call(this,t.options,!0,t.args)}}function a(t){var e;this.timer&&this.timer.destroy(),this.queue=[],this.active=!1,"string"==typeof t?(e={})[t]=1:e="object"==(void 0===t?"undefined":n(t))&&null!=t?t:this.props,d.call(this,e,p),h.call(this)}function l(){a.call(this),this.el.style.display="none"}function f(){this.el.offsetHeight}function h(){var t,e,n=[];for(t in this.upstream&&n.push(this.upstream),this.props)(e=this.props[t]).active&&n.push(e.string);n=n.join(","),this.style!==n&&(this.style=n,this.el.style[$.transition.dom]=n)}function d(t,e,n){var o,s,a,u,c=e!==p,l={};for(o in t)a=t[o],o in Q?(l.transform||(l.transform={}),l.transform[o]=a):(w.test(o)&&(o=i(o)),o in W?l[o]=a:(u||(u={}),u[o]=a));for(o in l){if(a=l[o],!(s=this.props[o])){if(!c)continue;s=r.call(this,o)}e.call(this,s,a)}n&&u&&n.call(this,u)}function p(t){t.stop()}function m(t,e){t.set(e)}function g(t){this.$el.css(t)}function b(t,n){e[t]=function(){return this.children?function(t,e){var n,i=this.children.length;for(n=0;i>n;n++)t.apply(this.children[n],e);return this}.call(this,n,arguments):(this.el&&n.apply(this,arguments),this)}}e.init=function(e){if(this.$el=t(e),this.el=this.$el[0],this.props={},this.queue=[],this.style="",this.active=!1,X.keepInherited&&!X.fallback){var n=G(this.el,"transition");n&&!z.test(n)&&(this.upstream=n)}$.backface&&X.hideBackface&&Y(this.el,$.backface.css,"hidden")},b("add",r),b("start",o),b("wait",function(t){t=u(t,0),this.active?this.queue.push({options:t}):(this.timer=new N({duration:t,context:this,complete:s}),this.active=!0)}),b("then",function(t){return this.active?(this.queue.push({options:t,args:arguments}),void(this.timer.complete=s)):c("No active transition timer. Use start() or wait() before then().")}),b("next",s),b("stop",a),b("set",function(t){a.call(this,t),d.call(this,t,m,g)}),b("show",function(t){"string"!=typeof t&&(t="block"),this.el.style.display=t}),b("hide",l),b("redraw",f),b("destroy",function(){a.call(this),t.removeData(this.el,v),this.$el=this.el=null})}),L=l(F,function(e){function n(e,n){var i=t.data(e,v)||t.data(e,v,new F.Bare);return i.el||i.init(e),n?i.start(n):i}e.init=function(e,i){var r=t(e);if(!r.length)return this;if(1===r.length)return n(r[0],i);var o=[];return r.each(function(t,e){o.push(n(e,i))}),this.children=o,this}}),D=l(function(t){function e(){var t=this.get();this.update("auto");var e=this.get();return this.update(t),e}function i(t){var e=/rgba?\((\d+),\s*(\d+),\s*(\d+)/.exec(t);return(e?o(e[1],e[2],e[3]):t).replace(/#(\w)(\w)(\w)$/,"#$1$1$2$2$3$3")}var r=500,s="ease",a=0;t.init=function(t,e,n,i){this.$el=t,this.el=t[0];var o=e[0];n[2]&&(o=n[2]),Z[o]&&(o=Z[o]),this.name=o,this.type=n[1],this.duration=u(e[1],this.duration,r),this.ease=function(t,e,n){return void 0!==e&&(n=e),t in f?t:n}(e[2],this.ease,s),this.delay=u(e[3],this.delay,a),this.span=this.duration+this.delay,this.active=!1,this.nextStyle=null,this.auto=T.test(this.name),this.unit=i.unit||this.unit||X.defaultUnit,this.angle=i.angle||this.angle||X.defaultAngle,X.fallback||i.fallback?this.animate=this.fallback:(this.animate=this.transition,this.string=this.name+E+this.duration+"ms"+("ease"!=this.ease?E+f[this.ease][0]:"")+(this.delay?E+this.delay+"ms":""))},t.set=function(t){t=this.convert(t,this.type),this.update(t),this.redraw()},t.transition=function(t){this.active=!0,t=this.convert(t,this.type),this.auto&&("auto"==this.el.style[this.name]&&(this.update(this.get()),this.redraw()),"auto"==t&&(t=e.call(this))),this.nextStyle=t},t.fallback=function(t){var n=this.el.style[this.name]||this.convert(this.get(),this.type);t=this.convert(t,this.type),this.auto&&("auto"==n&&(n=this.convert(this.get(),this.type)),"auto"==t&&(t=e.call(this))),this.tween=new C({from:n,to:t,duration:this.duration,delay:this.delay,ease:this.ease,update:this.update,context:this})},t.get=function(){return G(this.el,this.name)},t.update=function(t){Y(this.el,this.name,t)},t.stop=function(){(this.active||this.nextStyle)&&(this.active=!1,this.nextStyle=null,Y(this.el,this.name,this.get()));var t=this.tween;t&&t.context&&t.destroy()},t.convert=function(t,e){if("auto"==t&&this.auto)return t;var r,o="number"==typeof t,s="string"==typeof t;switch(e){case g:if(o)return t;if(s&&""===t.replace(m,""))return+t;r="number(unitless)";break;case b:if(s){if(""===t&&this.original)return this.original;if(e.test(t))return"#"==t.charAt(0)&&7==t.length?t:i(t)}r="hex or rgb string";break;case y:if(o)return t+this.unit;if(s&&e.test(t))return t;r="number(px) or string(unit)";break;case x:if(o)return t+this.unit;if(s&&e.test(t))return t;r="number(px) or string(unit or %)";break;case _:if(o)return t+this.angle;if(s&&e.test(t))return t;r="number(deg) or string(angle)";break;case k:if(o)return t;if(s&&x.test(t))return t;r="number(unitless) or string(unit or %)"}return function(t,e){c("Type warning: Expected: ["+t+"] Got: ["+(void 0===e?"undefined":n(e))+"] "+e)}(r,t),t},t.redraw=function(){this.el.offsetHeight}}),I=l(D,function(t,e){t.init=function(){e.init.apply(this,arguments),this.original||(this.original=this.convert(this.get(),b))}}),P=l(D,function(t,e){t.init=function(){e.init.apply(this,arguments),this.animate=this.fallback},t.get=function(){return this.$el[this.name]()},t.update=function(t){this.$el[this.name](t)}}),H=l(D,function(t,e){function n(t,e){var n,i,r,o,s;for(n in t)r=(o=Q[n])[0],i=o[1]||n,s=this.convert(t[n],r),e.call(this,i,s,r)}t.init=function(){e.init.apply(this,arguments),this.current||(this.current={},Q.perspective&&X.perspective&&(this.current.perspective=X.perspective,Y(this.el,this.name,this.style(this.current)),this.redraw()))},t.set=function(t){n.call(this,t,function(t,e){this.current[t]=e}),Y(this.el,this.name,this.style(this.current)),this.redraw()},t.transition=function(t){var e=this.values(t);this.tween=new U({current:this.current,values:e,duration:this.duration,delay:this.delay,ease:this.ease});var n,i={};for(n in this.current)i[n]=n in e?e[n]:this.current[n];this.active=!0,this.nextStyle=this.style(i)},t.fallback=function(t){var e=this.values(t);this.tween=new U({current:this.current,values:e,duration:this.duration,delay:this.delay,ease:this.ease,update:this.update,context:this})},t.update=function(){Y(this.el,this.name,this.style(this.current))},t.style=function(t){var e,n="";for(e in t)n+=e+"("+t[e]+") ";return n},t.values=function(t){var e,i={};return n.call(this,t,function(t,n,r){i[t]=n,void 0===this.current[t]&&(e=0,~t.indexOf("scale")&&(e=1),this.current[t]=this.convert(e,r))}),i}}),C=l(function(e){function n(){var t,e,i,r=u.length;if(r)for(B(n),e=R(),t=r;t--;)(i=u[t])&&i.render(e)}var i={ease:f.ease[1],from:0,to:1};e.init=function(t){this.duration=t.duration||0,this.delay=t.delay||0;var e=t.ease||i.ease;f[e]&&(e=f[e][1]),"function"!=typeof e&&(e=i.ease),this.ease=e,this.update=t.update||s,this.complete=t.complete||s,this.context=t.context||this,this.name=t.name;var n=t.from,r=t.to;void 0===n&&(n=i.from),void 0===r&&(r=i.to),this.unit=t.unit||"","number"==typeof n&&"number"==typeof r?(this.begin=n,this.change=r-n):this.format(r,n),this.value=this.begin+this.unit,this.start=R(),!1!==t.autoplay&&this.play()},e.play=function(){var t;this.active||(this.start||(this.start=R()),this.active=!0,t=this,1===u.push(t)&&B(n))},e.stop=function(){var e,n,i;this.active&&(this.active=!1,e=this,(i=t.inArray(e,u))>=0&&(n=u.slice(i+1),u.length=i,n.length&&(u=u.concat(n))))},e.render=function(t){var e,n=t-this.start;if(this.delay){if(n<=this.delay)return;n-=this.delay}if(n').attr("href","https://webflow.com?utm_campaign=brandjs"),i=t("").attr("src","https://d1otoma47x30pg.cloudfront.net/img/webflow-badge-icon.60efbf6ec9.svg").css({marginRight:"8px",width:"16px"}),s=t("").attr("src","https://d1otoma47x30pg.cloudfront.net/img/webflow-badge-text.6faa6a38cd.svg"),n.append(i,s),n[0]),h(),setTimeout(h,500),t(r).off(l,f).on(l,f))},n})},function(t,e,n){var i=window.$,r=n(1)&&i.tram; /*! * Webflow._ (aka) Underscore.js 1.6.0 (custom build) * _.each * _.map * _.find * _.filter * _.any * _.contains * _.delay * _.defer * _.throttle (webflow) * _.debounce * _.keys * _.has * _.now * * http://underscorejs.org * (c) 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors * Underscore may be freely distributed under the MIT license. * @license MIT */ t.exports=function(){var t={VERSION:"1.6.0-Webflow"},e={},n=Array.prototype,i=Object.prototype,o=Function.prototype,s=(n.push,n.slice),a=(n.concat,i.toString,i.hasOwnProperty),u=n.forEach,c=n.map,l=(n.reduce,n.reduceRight,n.filter),f=(n.every,n.some),h=n.indexOf,d=(n.lastIndexOf,Array.isArray,Object.keys),p=(o.bind,t.each=t.forEach=function(n,i,r){if(null==n)return n;if(u&&n.forEach===u)n.forEach(i,r);else if(n.length===+n.length){for(var o=0,s=n.length;o/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var m=/(.)^/,w={"'":"'","\\":"\\","\r":"r","\n":"n","\u2028":"u2028","\u2029":"u2029"},g=/\\|'|\r|\n|\u2028|\u2029/g,b=function(t){return"\\"+w[t]};return t.template=function(e,n,i){!n&&i&&(n=i),n=t.defaults({},n,t.templateSettings);var r=RegExp([(n.escape||m).source,(n.interpolate||m).source,(n.evaluate||m).source].join("|")+"|$","g"),o=0,s="__p+='";e.replace(r,function(t,n,i,r,a){return s+=e.slice(o,a).replace(g,b),o=a+t.length,n?s+="'+\n((__t=("+n+"))==null?'':_.escape(__t))+\n'":i?s+="'+\n((__t=("+i+"))==null?'':__t)+\n'":r&&(s+="';\n"+r+"\n__p+='"),t}),s+="';\n",n.variable||(s="with(obj||{}){\n"+s+"}\n"),s="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+s+"return __p;\n";try{var a=new Function(n.variable||"obj","_",s)}catch(t){throw t.source=s,t}var u=function(e){return a.call(this,e,t)},c=n.variable||"obj";return u.source="function("+c+"){\n"+s+"}",u},t}()},function(t,e,n){var i=n(0),r=n(6);i.define("ix",t.exports=function(t,e){var n,o,s={},a=t(window),u=".w-ix",c=t.tram,l=i.env,f=l(),h=l.chrome&&l.chrome<35,d="none 0s ease 0s",p=t(),v={},m=[],w=[],g=[],b=1,y={tabs:".w-tab-link, .w-tab-pane",dropdown:".w-dropdown",slider:".w-slide",navbar:".w-nav"};function x(t){t&&(v={},e.each(t,function(t){v[t.slug]=t.value}),_())}function _(){!function(){var e=t("[data-ix]");if(!e.length)return;e.each(T),e.each(k),m.length&&(i.scroll.on(E),setTimeout(E,1));w.length&&i.load(q);g.length&&setTimeout(O,b)}(),r.init(),i.redraw.up()}function k(n,o){var a=t(o),c=a.attr("data-ix"),l=v[c];if(l){var h=l.triggers;h&&(s.style(a,l.style),e.each(h,function(t){var e={},n=t.type,o=t.stepsB&&t.stepsB.length;function s(){A(t,a,{group:"A"})}function c(){A(t,a,{group:"B"})}if("load"!==n){if("click"===n)return a.on("click"+u,function(n){i.validClick(n.currentTarget)&&("#"===a.attr("href")&&n.preventDefault(),A(t,a,{group:e.clicked?"B":"A"}),o&&(e.clicked=!e.clicked))}),void(p=p.add(a));if("hover"===n)return a.on("mouseenter"+u,s),a.on("mouseleave"+u,c),void(p=p.add(a));if("scroll"!==n){var l=y[n];if(l){var h=a.closest(l);return h.on(r.types.INTRO,s).on(r.types.OUTRO,c),void(p=p.add(h))}}else m.push({el:a,trigger:t,state:{active:!1},offsetTop:z(t.offsetTop),offsetBot:z(t.offsetBot)})}else t.preload&&!f?w.push(s):g.push(s)}))}}function z(t){if(!t)return 0;t=String(t);var e=parseInt(t,10);return e!=e?0:(t.indexOf("%")>0&&(e/=100)>=1&&(e=.999),e)}function T(e,n){t(n).off(u)}function E(){for(var t=a.scrollTop(),e=a.height(),n=m.length,i=0;i0&&(h*=e),d<1&&d>0&&(d*=e);var p=l+f-h>=t&&l+d<=t+e;p!==c.active&&((!1!==p||u)&&(c.active=p,A(s,o,{group:p?"A":"B"})))}}function q(){for(var t=w.length,e=0;e=0)){var s=t(e);if(0===i.indexOf("#")&&h.test(i)){var a=t(i);a.length&&r.push({link:s,sec:a,active:!1})}else if("#"!==i&&""!==i){var u=l.href===c.href||i===o||d.test(i)&&p.test(o);w(s,f,u)}}}function m(){var t=a.scrollTop(),n=a.height();e.each(r,function(e){var i=e.link,r=e.sec,o=r.offset().top,s=r.outerHeight(),a=.5*n,u=r.is(":visible")&&o+s-a>=t&&o+a<=t+n;e.active!==u&&(e.active=u,w(i,f,u))})}function w(t,e,n){var i=t.hasClass(e);n&&i||(n||i)&&(n?t.addClass(e):t.removeClass(e))}return s.ready=s.design=s.preview=function(){n=u&&i.env("design"),o=i.env("slug")||c.pathname||"",i.scroll.off(m),r=[];for(var t=document.links,e=0;e .header, "+c+" > .w-nav:not([data-no-scroll])"),f="fixed"===l.css("position")?l.outerHeight():0;n.setTimeout(function(){!function(e,i){var r=t(n).scrollTop(),o=e.offset().top-i;if("mid"===e.data("scroll")){var s=t(n).height()-i,a=e.outerHeight();a0)&&(u=e)}),Date.now||(Date.now=function(){return(new Date).getTime()});var c=Date.now(),l=n.requestAnimationFrame||n.mozRequestAnimationFrame||n.webkitRequestAnimationFrame||function(t){n.setTimeout(t,15)},f=(472.143*Math.log(Math.abs(r-o)+125)-2e3)*u;!function t(){var e=Date.now()-c;n.scroll(0,function(t,e,n,i){if(n>i)return e;return t+(e-t)*(r=n/i,r<.5?4*r*r*r:(r-1)*(2*r-2)*(2*r-2)+1);var r}(r,o,e,f)),e<=f&&l(t)}()}(u,f)},a?0:300)}}}return{ready:function(){r.hash&&a(r.hash.substring(1));var n=r.href.split("#")[0];e.on("click","a",function(e){if(!(i.env("design")||window.$.mobile&&t(e.currentTarget).hasClass("ui-link")))if("#"!==this.getAttribute("href")){var r=this.href.split("#"),o=r[0]===n?r[1]:null;o&&a(o,e)}else e.preventDefault()})}}})},function(t,e,n){n(0).define("touch",t.exports=function(t){var e={},n=!document.addEventListener,i=window.getSelection;function r(e,n,i){var r=t.Event(e,{originalEvent:n});t(n.target).trigger(r,i)}return n&&(t.event.special.tap={bindType:"click",delegateType:"click"}),e.init=function(e){return n?null:(e="string"==typeof e?t(e).get(0):e)?new function(t){var e,n,o,s=!1,a=!1,u=!1,c=Math.min(Math.round(.04*window.innerWidth),40);function l(t){var i=t.touches;i&&i.length>1||(s=!0,a=!1,i?(u=!0,e=i[0].clientX,n=i[0].clientY):(e=t.clientX,n=t.clientY),o=e)}function f(t){if(s){if(u&&"mousemove"===t.type)return t.preventDefault(),void t.stopPropagation();var l=t.touches,f=l?l[0].clientX:t.clientX,h=l?l[0].clientY:t.clientY,p=f-o;o=f,Math.abs(p)>c&&i&&""===String(i())&&(r("swipe",t,{direction:p>0?"right":"left"}),d()),(Math.abs(f-e)>10||Math.abs(h-n)>10)&&(a=!0)}}function h(t){if(s){if(s=!1,u&&"mouseup"===t.type)return t.preventDefault(),t.stopPropagation(),void(u=!1);a||r("tap",t)}}function d(){s=!1}t.addEventListener("touchstart",l,!1),t.addEventListener("touchmove",f,!1),t.addEventListener("touchend",h,!1),t.addEventListener("touchcancel",d,!1),t.addEventListener("mousedown",l,!1),t.addEventListener("mousemove",f,!1),t.addEventListener("mouseup",h,!1),t.addEventListener("mouseout",d,!1),this.destroy=function(){t.removeEventListener("touchstart",l,!1),t.removeEventListener("touchmove",f,!1),t.removeEventListener("touchend",h,!1),t.removeEventListener("touchcancel",d,!1),t.removeEventListener("mousedown",l,!1),t.removeEventListener("mousemove",f,!1),t.removeEventListener("mouseup",h,!1),t.removeEventListener("mouseout",d,!1),t=null}}(e):null},e.instance=e.init(document),e})}]);/** * ---------------------------------------------------------------------- * Webflow: Interactions: Init */ Webflow.require('ix').init([ {"slug":"new-interaction","name":"New Interaction","value":{"style":{},"triggers":[{"type":"click","stepsA":[{"display":"flex"}],"stepsB":[]}]}}, {"slug":"display-none","name":"Display None","value":{"style":{"display":"none"},"triggers":[]}} ]);