Full Code of edenvidal/States for AI

master 22c0aab87ec6 cached
81 files
283.4 KB
85.2k tokens
61 symbols
1 requests
Download .txt
Showing preview only (305K chars total). Download the full file or copy to clipboard to get everything.
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 <edenvidal@gmail.com>

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
================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleDevelopmentRegion</key>
	<string>en</string>
	<key>CFBundleExecutable</key>
	<string>$(EXECUTABLE_NAME)</string>
	<key>CFBundleIdentifier</key>
	<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>$(PRODUCT_NAME)</string>
	<key>CFBundlePackageType</key>
	<string>BNDL</string>
	<key>CFBundleShortVersionString</key>
	<string>1.0.0</string>
	<key>CFBundleSignature</key>
	<string>????</string>
	<key>CFBundleVersion</key>
	<string>1</string>
	<key>NSHumanReadableCopyright</key>
	<string>Copyright © 2016 Eden Vidal. All rights reserved.</string>
	<key>NSPrincipalClass</key>
	<string></string>
</dict>
</plist>


================================================
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 <NSObject, STLayer>
@optional

- (NSArray <id <STLayer>>*)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 <NSObject>
@optional

- (void)setValue: (id)value forKey: (id <NSCopying>)key onLayer: (id <STLayer>)layer;
- (id)valueForKey: (id <NSCopying>)key onLayer: (id <STLayer>)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 <NSObject>

- (void)addPage: (id <STPage>)page;
- (void)deselectAllLayers;

@end

@protocol STDocument <NSObject>
@optional

- (void)setCurrentPage: (id <STPage>)page;
- (id <STPage>)currentPage;

- (id)window;

- (id <STDocumentData>)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 <NSObject>
@optional

- (BOOL)isVisible;
- (void)setIsVisible: (BOOL)visible;
- (id <STAbsoluteRect>)absoluteRect;

- (void)copyToLayer: (id <STLayer>)newParent beforeLayer: (id <STLayer>)sibling;

@end

@protocol STFrame <NSObject>
@optional

- (CGRect)rect;

- (CGFloat)x;
- (CGFloat)y;

- (void)setX: (CGFloat)x;
- (void)setY: (CGFloat)y;

@end

@protocol STAbsoluteRect <NSObject>
@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 <NSString *, id> *)dictionaryRepresentation;
- (instancetype)initWithDictionary: (NSDictionary <NSString *, id> *)dictionary;

@end

/// Applies the given layer state to the given layer
@interface STLayerStateApplier : NSObject
+ (void)apply: (STLayerState *)state toLayer: (id <STLayer>)layer;
@end

/// Returns the current layer's state
@interface STLayerStateFetcher : NSObject
+ (STLayerState *)fetchStateFromLayer: (id <STLayer>)layer;
@end

/// Verifies that the given layer conforms to the given state
@interface STLayerStateExaminer : NSObject
+ (BOOL)layer: (id <STLayer>)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 <NSString *, id> *)dictionaryRepresentation
{
	return @{
		@"frame" : NSStringFromRect(_frame),
		@"visible" : @(_visible)
	};
}

- (instancetype)initWithDictionary: (NSDictionary <NSString *, id> *)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 <STLayer>)layer
{
	layer.isVisible = state.visible;

	id <STFrame> frame = [layer performSelector: @selector(frame)];
	frame.x = state.frame.origin.x;
	frame.y = state.frame.origin.y;
}

@end

@implementation STLayerStateFetcher : NSObject

+ (STLayerState *)fetchStateFromLayer: (id <STLayer>)layer
{
	id <STFrame> frameObject = [layer performSelector: @selector(frame)];
	return [[STLayerState alloc] initWithFrame: NSRectFromCGRect(frameObject.rect)
							  visibilityStatus: layer.isVisible];
}

@end

@implementation STLayerStateExaminer : NSObject

+ (BOOL)layer: (id <STLayer>)layer conformsToState: (STLayerState *)state
{
	id <STFrame> 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 <NSObject, STLayer>
@optional

+ (instancetype)page;
- (instancetype)copy;

- (id <STArtboard>)currentArtboard;
- (NSArray *)artboards;

- (void)enumerateLayersWithOptions: (int)options block: (void(^)(id <STLayer> layer))block;

- (void)addLayers: (NSArray *)layers;
- (void)removeLayer: (id <STLayer>)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 <NSObject>
@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 <STDocument>)currentDocument;
+ (id <STPage>)currentPage;
+ (id <STArtboard>)currentArtboard;

/// Use this observer to subscribe to various Sketch notifications. See SketchNotificationsListener
/// for more details
+ (instancetype)notificationObserver;
- (void)addListener: (id <SketchNotificationsListener>)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 <objc/runtime.h>
#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 <STDocument>)currentDocument
{
	return [NSClassFromString(@"MSDocument") currentDocument];
}

+ (id <STPage>)currentPage
{
	return [[self currentDocument] currentPage];
}

+ (id <STArtboard>)currentArtboard
{
	id <STArtboard> 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 <SketchNotificationsListener> listener in [_listeners allObjects]) {
			 [listener currentArtboardUnselected];
		 }
	}];

	SEL currentArtboardDidChangeSelector = NSSelectorFromString(@"currentArtboardDidChange");
	[MSDocument aspect_hookSelector: currentArtboardDidChangeSelector withOptions: AspectPositionAfter usingBlock: ^(id<AspectInfo> aspectInfo)
	 {
		 NSAssert(aspectInfo.instance == [STSketch currentDocument],
				  @"Unexpected artboard selection update from a secondary document");
		 for (id <SketchNotificationsListener> listener in [_listeners allObjects]) {
			 [listener currentArtboardDidChange];
		 }
	 } error: NULL];

	[MSDocument aspect_hookSelector: @selector(windowDidBecomeKey:) withOptions: AspectPositionAfter usingBlock: ^(id<AspectInfo> 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 <SketchNotificationsListener> listener in [_listeners allObjects]) {
				 [listener currentArtboardDidChange];
			 }
		 });
	 } error: NULL];

	/// XXX
	SEL setCurrentArtboard = NSSelectorFromString(@"setCurrentArtboard:");
	[MSPage aspect_hookSelector: setCurrentArtboard withOptions: AspectPositionAfter usingBlock: ^(id<AspectInfo> aspectInfo)
	 {
		 id artboard = [[aspectInfo arguments] firstObject];
		 for (id <SketchNotificationsListener> 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> aspectInfo)
	 {
		 NSArray *selection = [[aspectInfo arguments] firstObject];
		 if (![selection isKindOfClass: [NSArray class]]) {
			 return;
		 }
		 for (id <SketchNotificationsListener> listener in [_listeners allObjects]) {
			 if (selection.count != 0) {
				[listener currentArtboardDidChange];
			 }
		 }
	 } error: NULL];


	/// XXX
	void (^documentUpdateHandler)(void) = ^(void) {
		for (id <SketchNotificationsListener> listener in [_listeners allObjects]) {
			[listener currentDocumentUpdated];
		}
	};

	// XXX
	SEL layerPositionPossiblyChanged = NSSelectorFromString(@"layerPositionPossiblyChanged");
	[MSDocument aspect_hookSelector: layerPositionPossiblyChanged withOptions: AspectPositionAfter usingBlock: ^(id<AspectInfo> aspectInfo)
	 {
		 id <STDocument> doc = aspectInfo.instance;
		 if ([[doc currentPage] currentArtboard] == [[STSketch currentPage] currentArtboard]) {
			 documentUpdateHandler();
		 }
	 } error: NULL];

	// XXX
	[MSDocument aspect_hookSelector: NSSelectorFromString(@"undoAction:") withOptions: AspectPositionAfter usingBlock: ^(id<AspectInfo> aspectInfo)
	 {
		 id <STDocument> 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> aspectInfo)
	 {
		 documentUpdateHandler();
	 } error: NULL];

	[_MSLayer aspect_hookSelector: setIsVisible withOptions: AspectPositionAfter usingBlock: ^(id<AspectInfo> 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 <STDocument> document;
@property (readonly, strong) id <STCommand> 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 <STDocument> document;
@property (readwrite, strong) id <STCommand> 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 <NSString *, id> *)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 <NSString *, id> *)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 <NSString *, id> *)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 <NSString *, id> *)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 <NSDictionary *> *)artboardStatesData;
- (void)setArtboardStatesData: (nonnull NSArray <NSDictionary *> *)newData;

- (nonnull NSDictionary <NSString *, id> *)artboardCurrentStateData;
- (void)setArtboardCurrentStateData: (nonnull NSDictionary <NSString *, id> *)newData;

- (nonnull NSDictionary <NSString *, id> *)metadataForLayer: (nonnull id <STLayer>)layer;
- (void)setMedatada: (nonnull NSDictionary <NSString *, id> *)newMetadata forLayer: (nonnull id <STLayer>)layer;

- (nonnull NSDictionary <NSString *, id> *)artboardDefaultStateData;
- (void)setArtboardDefaultStateData: (nonnull NSDictionary <NSString *, id> *)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 <NSDictionary *> *)artboardStatesData
{
	return [[self.context command] valueForKey: kSTStatefulArtboardStatesKey onLayer: _internal] ?: @[];
}

- (void)setArtboardStatesData: (NSArray <NSDictionary *> *)newData
{
	[[self.context command] setValue: newData forKey: kSTStatefulArtboardStatesKey onLayer: _internal];
}

- (NSDictionary <NSString *, id> *)artboardCurrentStateData
{
	return [[self.context command] valueForKey: kSTStatefulArtboardCurrentStateKey onLayer: _internal] ?: @{};
}

- (void)setArtboardCurrentStateData: (NSDictionary <NSString *, id> *)newData
{
	[[self.context command] setValue: newData forKey: kSTStatefulArtboardCurrentStateKey onLayer: _internal];
}

- (NSDictionary <NSString *, id> *)metadataForLayer: (id <STLayer>)layer
{
	return [[self.context command] valueForKey: kSTStatefulArtboardStateValuesKey onLayer: layer] ?: @{};
}

- (void)setMedatada: (NSDictionary <NSString *, id> *)newMetadata forLayer: (id <STLayer>)layer
{
	[[self.context command] setValue: newMetadata forKey: kSTStatefulArtboardStateValuesKey onLayer: layer];
}

- (nonnull NSDictionary <NSString *, id> *)artboardDefaultStateData
{
	return [[self.context command] valueForKey: kSTStatefulArtboardDefaultStateKey onLayer: _internal] ?: @{};
}

- (void)setArtboardDefaultStateData: (nonnull NSDictionary <NSString *, id> *)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 <STArtboard>)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 <STArtboard>)snapshotForState: (STStateDescription *)state
{
	NSParameterAssert([self.allStates containsObject: state]);

	id <STArtboard> 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 <STArtboard>
{
@protected
	id <STArtboard> _internal;
}
@property (readonly, strong) STSketchPluginContext *context;
@property (readonly, strong) NSArray <STStateDescription *> *allStates;
@property (readonly, strong) STStateDescription *currentState;
@property (readonly, strong) STStateDescription *defaultState;

- (instancetype)initWithArtboard: (id <STArtboard>)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 <STStateDescription *> *)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 <STArtboard>)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 <id <STLayer>> *)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<STLayer> 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<STLayer> 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<STLayer> 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<STLayer> 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<STLayer> 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<STLayer> 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<STLayer> 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 <STStateDescription *> *)allStatesInNewOrder
{
	NSAssert([[NSSet setWithArray: self.allStates] isEqualToSet: [NSSet setWithArray: allStatesInNewOrder]],
			 @"Invalid argument");
	[self setAllStates: allStatesInNewOrder];
}

#pragma mark - Artboard State Metadata

- (NSArray <STStateDescription *> *)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<STStateDescription *> *)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 <NSObject>
@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 <STTableCellViewDelegate> 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 <NSObject>
@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 <STTextFieldFirstResponderDelegate> 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) <NSMenuDelegate>

- (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 <STStateDescription *>*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 <STStateDescription *> *)subjects
{
	NSMenuItem *item = [[NSMenuItem alloc] initWithTitle: @"Duplicate"
												  action: @selector(duplicateStates:)
										   keyEquivalent: @""];
	item.target = self;
	item.representedObject = subjects;
	return item;
}

- (NSMenuItem *)createPageMenuItemForStates: (NSArray <STStateDescription *> *)subjects
{
	NSMenuItem *item = [[NSMenuItem alloc] initWithTitle: @"Create Page"
												  action: @selector(createPageFromStates:)
										   keyEquivalent: @""];
	item.target = self;
	item.representedObject = subjects;
	return item;
}

- (NSMenuItem *)deleteMenuItemForStates: (NSArray <STStateDescription *> *)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 <STStateDescription *> *)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 <STStateDescription *> *)states
{
	NSParameterAssert(states.count > 0);

	NSArray <NSString *>*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 <NSDraggingInfo>)info proposedRow: (NSInteger)row proposedDropOperation: (NSTableViewDropOperation)dropOperation;

- (BOOL)tableView: (NSTableView *)tableView acceptDrop: (id <NSDraggingInfo>)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 <NSDraggingInfo>)info proposedRow: (NSInteger)row proposedDropOperation: (NSTableViewDropOperation)dropOperation
{
	if (dropOperation == NSTableViewDropAbove) {
		[info setAnimatesToDestination: YES];
		return NSDragOperationMove;
	}
	return NSDragOperationNone;
}

- (BOOL)tableView: (NSTableView *)tableView acceptDrop: (id <NSDraggingInfo>)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 <STStateDescription *> *)existingStates;

/// Returns a name for a new page containing shapshots of the given states
- (NSString *)pageNameForStates: (NSArray <STStateDescription *> *)states sourcePage: (id <STPage>)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 <STStateDescription *> *)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 <STStateDescription *> *)states sourcePage: (id <STPage>)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
<NSTableViewDelegate, NSTableViewDataSource, NSTextFieldDelegate>
{
@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()
<SketchNotificationsListener, STTextFieldFirstResponderDelegate, STTableCellViewDelegate>
@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 <STStateDescription *> *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 <STStateDescription *> *selectedStates = sender.representedObject;
	NSParameterAssert([selectedStates isKindOfClass: [NSArray class]]);

	// 1) Create a new page
	id <STPage> currentPage = [STSketch currentPage];
	id <STPage> 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<STArtboard>(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 <STArtboard> 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 <STStateDescription *> *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
================================================
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15G31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
    <dependencies>
        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
    </dependencies>
    <objects>
        <customObject id="-2" userLabel="File's Owner" customClass="StatesController">
            <connections>
                <outlet property="addNewStateButton" destination="bUH-iu-jsD" id="oP9-Tp-6VA"/>
                <outlet property="placeholderView" destination="kJ8-YS-tjE" id="Idz-y3-8vD"/>
                <outlet property="tableView" destination="07i-xc-XA3" id="kdR-uW-6yA"/>
                <outlet property="window" destination="4Mh-eW-Wya" id="xdh-bH-0LV"/>
            </connections>
        </customObject>
        <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
        <customObject id="-3" userLabel="Application" customClass="NSObject"/>
        <window title="State of the artboard" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" hidesOnDeactivate="YES" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" animationBehavior="utilityWindow" frameAutosaveName="" id="4Mh-eW-Wya" customClass="STWindow">
            <windowStyleMask key="styleMask" closable="YES" resizable="YES" utility="YES"/>
            <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
            <rect key="contentRect" x="120" y="64" width="200" height="209"/>
            <rect key="screenRect" x="0.0" y="0.0" width="1280" height="777"/>
            <value key="minSize" type="size" width="200" height="209"/>
            <value key="maxSize" type="size" width="400" height="450"/>
            <view key="contentView" wantsLayer="YES" id="AC7-AO-h07">
                <rect key="frame" x="0.0" y="0.0" width="200" height="209"/>
                <autoresizingMask key="autoresizingMask"/>
                <subviews>
                    <scrollView wantsLayer="YES" borderType="none" autohidesScrollers="YES" horizontalLineScroll="26" horizontalPageScroll="10" verticalLineScroll="26" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="OXZ-wQ-2LX" userLabel="Scroll View &gt; Table View">
                        <rect key="frame" x="0.0" y="-1" width="201" height="181"/>
                        <clipView key="contentView" wantsLayer="YES" copiesOnScroll="NO" id="6Tk-AU-SVX">
                            <rect key="frame" x="0.0" y="0.0" width="201" height="181"/>
                            <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                            <subviews>
                                <tableView wantsLayer="YES" verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" alternatingRowBackgroundColors="YES" columnReordering="NO" columnResizing="NO" emptySelection="NO" autosaveColumns="NO" typeSelect="NO" rowHeight="24" rowSizeStyle="automatic" viewBased="YES" id="07i-xc-XA3" customClass="STTableView">
                                    <rect key="frame" x="0.0" y="0.0" width="201" height="0.0"/>
                                    <autoresizingMask key="autoresizingMask"/>
                                    <size key="intercellSpacing" width="3" height="2"/>
                                    <color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
                                    <color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
                                    <tableColumns>
                                        <tableColumn width="198" minWidth="40" maxWidth="1000" id="7M1-UH-Ceh">
                                            <tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" title="States">
                                                <font key="font" metaFont="smallSystem"/>
                                                <color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
                                                <color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
                                            </tableHeaderCell>
                                            <textFieldCell key="dataCell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" title="Text Cell" id="O8Z-y2-TwS">
                                                <font key="font" metaFont="system"/>
                                                <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
                                                <color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
                                            </textFieldCell>
                                            <tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
                                            <prototypeCellViews>
                                                <tableCellView identifier="StateCell" wantsLayer="YES" id="Ayr-wq-u12" customClass="STTableCellView">
                                                    <rect key="frame" x="1" y="1" width="198" height="24"/>
                                                    <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                                    <subviews>
                                                        <textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="CCU-9b-be0" userLabel="Text label" customClass="STTextField">
                                                            <rect key="frame" x="13" y="4" width="177" height="15"/>
                                                            <textFieldCell key="cell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" title="Table View Cell" id="1ZX-ey-inf">
                                                                <font key="font" size="11" name="HelveticaNeue"/>
                                                                <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
                                                                <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
                                                            </textFieldCell>
                                                        </textField>
                                                        <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="dNP-7B-gk9" customClass="STUpdateButton">
                                                            <rect key="frame" x="175" y="3" width="18" height="18"/>
                                                            <constraints>
                                                                <constraint firstAttribute="height" constant="18" id="fdz-Jt-1Bm"/>
                                                                <constraint firstAttribute="width" constant="18" id="qma-Em-KlE"/>
                                                            </constraints>
                                                            <buttonCell key="cell" type="roundRect" bezelStyle="roundedRect" image="dirty" imagePosition="overlaps" alignment="center" state="on" inset="2" id="qRB-58-GY4">
                                                                <behavior key="behavior" lightByContents="YES"/>
                                                                <font key="font" metaFont="cellTitle"/>
                                                            </buttonCell>
                                                        </button>
                                                    </subviews>
                                                    <constraints>
                                                        <constraint firstItem="dNP-7B-gk9" firstAttribute="centerY" secondItem="Ayr-wq-u12" secondAttribute="centerY" id="Dmh-AX-n9z"/>
                                                        <constraint firstAttribute="trailing" secondItem="CCU-9b-be0" secondAttribute="trailing" constant="10" id="X45-p6-dfd"/>
                                                        <constraint firstItem="CCU-9b-be0" firstAttribute="centerY" secondItem="Ayr-wq-u12" secondAttribute="centerY" id="fcY-uv-GVj"/>
                                                        <constraint firstItem="CCU-9b-be0" firstAttribute="leading" secondItem="Ayr-wq-u12" secondAttribute="leading" constant="15" id="wp3-cE-vYB"/>
                                                        <constraint firstAttribute="trailing" secondItem="dNP-7B-gk9" secondAttribute="trailing" constant="5" id="yfV-py-4GB"/>
                                                    </constraints>
                                                    <connections>
                                                        <outlet property="textField" destination="CCU-9b-be0" id="jwf-IV-Cmi"/>
                                                        <outlet property="updateButton" destination="dNP-7B-gk9" id="LVz-bM-gDT"/>
                                                    </connections>
                                                </tableCellView>
                                            </prototypeCellViews>
                                        </tableColumn>
                                    </tableColumns>
                                    <connections>
                                        <outlet property="dataSource" destination="-2" id="Zq2-Ir-6MC"/>
                                        <outlet property="delegate" destination="-2" id="oXL-e8-I5y"/>
                                    </connections>
                                </tableView>
                            </subviews>
                            <color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
                        </clipView>
                        <scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="0to-v7-jGH">
                            <rect key="frame" x="1" y="7" width="0.0" height="16"/>
                            <autoresizingMask key="autoresizingMask"/>
                        </scroller>
                        <scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="NO" id="euO-nB-O4Y">
                            <rect key="frame" x="224" y="17" width="15" height="102"/>
                            <autoresizingMask key="autoresizingMask"/>
                        </scroller>
                    </scrollView>
                    <customView translatesAutoresizingMaskIntoConstraints="NO" id="ix5-5p-Z47" userLabel="Header" customClass="STHeaderView">
                        <rect key="frame" x="0.0" y="180" width="200" height="29"/>
                        <subviews>
                            <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="UmN-oM-s3R">
                                <rect key="frame" x="8" y="4" width="141" height="20"/>
                                <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="States" id="r2q-s2-7mS">
                                    <font key="font" size="11" name="HelveticaNeue-Medium"/>
                                    <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
                                    <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
                                </textFieldCell>
                            </textField>
                            <button focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="bUH-iu-jsD">
                                <rect key="frame" x="177" y="7" width="15" height="15"/>
                                <constraints>
                                    <constraint firstAttribute="width" constant="15" id="K4H-bj-a6y"/>
                                </constraints>
                                <buttonCell key="cell" type="roundRect" bezelStyle="roundedRect" image="NSAddTemplate" imagePosition="overlaps" alignment="center" controlSize="mini" state="on" focusRingType="none" imageScaling="proportionallyDown" inset="2" id="UKR-xN-a3S">
                                    <behavior key="behavior" lightByContents="YES"/>
                                    <font key="font" metaFont="miniSystem"/>
                                </buttonCell>
                                <connections>
                                    <action selector="createNewState:" target="-2" id="cjU-27-vdh"/>
                                </connections>
                            </button>
                        </subviews>
                        <constraints>
                            <constraint firstItem="bUH-iu-jsD" firstAttribute="top" secondItem="ix5-5p-Z47" secondAttribute="top" constant="7" id="EJe-Bg-j8P"/>
                            <constraint firstItem="UmN-oM-s3R" firstAttribute="centerY" secondItem="bUH-iu-jsD" secondAttribute="centerY" constant="0.5" id="Vam-G2-haU"/>
                            <constraint firstItem="UmN-oM-s3R" firstAttribute="centerY" secondItem="ix5-5p-Z47" secondAttribute="centerY" constant="0.5" id="dSa-qb-KDV"/>
                            <constraint firstItem="UmN-oM-s3R" firstAttribute="leading" secondItem="ix5-5p-Z47" secondAttribute="leading" constant="10" id="p0l-kg-ihF"/>
                            <constraint firstItem="UmN-oM-s3R" firstAttribute="top" secondItem="ix5-5p-Z47" secondAttribute="top" constant="5" id="tcK-Kp-oPm"/>
                            <constraint firstItem="bUH-iu-jsD" firstAttribute="leading" secondItem="UmN-oM-s3R" secondAttribute="trailing" constant="30" id="xvC-Gc-zRQ"/>
                            <constraint firstAttribute="height" constant="29" id="zUC-Ev-mtC"/>
                            <constraint firstAttribute="trailing" secondItem="bUH-iu-jsD" secondAttribute="trailing" constant="8" id="ze3-HS-OV2"/>
                        </constraints>
                    </customView>
                    <customView translatesAutoresizingMaskIntoConstraints="NO" id="kJ8-YS-tjE" userLabel="Placeholder" customClass="STPlaceholderView">
                        <rect key="frame" x="0.0" y="0.0" width="200" height="180"/>
                        <subviews>
                            <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="gP8-61-j5v">
                                <rect key="frame" x="58" y="83" width="85" height="15"/>
                                <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="Select Artboard" id="lLG-eO-fVS">
                                    <font key="font" size="11" name="HelveticaNeue"/>
                                    <color key="textColor" name="controlShadowColor" catalog="System" colorSpace="catalog"/>
                                    <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
                                </textFieldCell>
                            </textField>
                        </subviews>
                        <constraints>
                            <constraint firstItem="gP8-61-j5v" firstAttribute="centerY" secondItem="kJ8-YS-tjE" secondAttribute="centerY" id="RTa-qh-s78"/>
                            <constraint firstItem="gP8-61-j5v" firstAttribute="centerX" secondItem="kJ8-YS-tjE" secondAttribute="centerX" id="fcm-fJ-MBY"/>
                        </constraints>
                    </customView>
                </subviews>
                <constraints>
                    <constraint firstItem="kJ8-YS-tjE" firstAttribute="leading" secondItem="OXZ-wQ-2LX" secondAttribute="leading" id="5gV-iM-yRK"/>
                    <constraint firstItem="ix5-5p-Z47" firstAttribute="trailing" secondItem="kJ8-YS-tjE" secondAttribute="trailing" id="CEK-fC-EX7"/>
                    <constraint firstItem="OXZ-wQ-2LX" firstAttribute="top" secondItem="kJ8-YS-tjE" secondAttribute="top" id="RGI-BC-b7M"/>
                    <constraint firstItem="kJ8-YS-tjE" firstAttribute="centerX" secondItem="OXZ-wQ-2LX" secondAttribute="centerX" id="akp-07-RRn"/>
                    <constraint firstItem="ix5-5p-Z47" firstAttribute="top" secondItem="AC7-AO-h07" secondAttribute="top" id="g4V-kq-nBF"/>
                    <constraint firstItem="OXZ-wQ-2LX" firstAttribute="top" secondItem="ix5-5p-Z47" secondAttribute="bottom" id="ieD-j5-hmN"/>
                    <constraint firstItem="OXZ-wQ-2LX" firstAttribute="leading" secondItem="AC7-AO-h07" secondAttribute="leading" id="kea-YR-61J"/>
                    <constraint firstAttribute="bottom" secondItem="OXZ-wQ-2LX" secondAttribute="bottom" constant="-1" id="nJS-vU-NZ4"/>
                    <constraint firstAttribute="trailing" secondItem="OXZ-wQ-2LX" secondAttribute="trailing" constant="-1" id="rua-FM-uAa"/>
                    <constraint firstItem="ix5-5p-Z47" firstAttribute="leading" secondItem="kJ8-YS-tjE" secondAttribute="leading" id="tdl-jz-NsO"/>
                    <constraint firstItem="kJ8-YS-tjE" firstAttribute="centerY" secondItem="OXZ-wQ-2LX" secondAttribute="centerY" id="uAc-eO-kV4"/>
                </constraints>
            </view>
            <point key="canvasLocation" x="-1136" y="222.5"/>
        </window>
    </objects>
    <resources>
        <image name="NSAddTemplate" width="11" height="11"/>
        <image name="dirty" width="12" height="12"/>
    </resources>
</document>


================================================
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 = "<group>"; };
		0A12AE5D1D13A62300CBB026 /* STStatefulArtboard+Snapshots.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "STStatefulArtboard+Snapshots.m"; sourceTree = "<group>"; };
		0A291EA81D59BF6E0003F2A3 /* Versioning.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Versioning.xcconfig; sourceTree = "<group>"; };
		0A291EAB1D59C0A10003F2A3 /* Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = "<group>"; };
		0A291EAD1D59C0AA0003F2A3 /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = "<group>"; };
		0A2C50E81D09C87800CB3C9F /* STWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STWindow.h; sourceTree = "<group>"; };
		0A2C50E91D09C87800CB3C9F /* STWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STWindow.m; sourceTree = "<group>"; };
		0A3CBDB11D0A61C40016EFD8 /* STTableRowView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STTableRowView.h; sourceTree = "<group>"; };
		0A3CBDB21D0A61C40016EFD8 /* STTableRowView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STTableRowView.m; sourceTree = "<group>"; };
		0A3CBDB41D0A6BB10016EFD8 /* STColorFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STColorFactory.h; sourceTree = "<group>"; };
		0A3CBDB51D0A6BB10016EFD8 /* STColorFactory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STColorFactory.m; sourceTree = "<group>"; };
		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 = "<group>"; };
		0A3CE5A01CFCBBCD00B8C552 /* manifest.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = manifest.json; sourceTree = "<group>"; };
		0A3CEE711D055B6F008A4BB0 /* StatesController+Naming.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = "StatesController+Naming.h"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
		0A3CEE721D055B6F008A4BB0 /* StatesController+Naming.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = "StatesController+Naming.m"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
		0A3CEE741D055C5E008A4BB0 /* StatesController+Decisions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = "StatesController+Decisions.h"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
		0A3CEE751D055C5E008A4BB0 /* StatesController+Decisions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = "StatesController+Decisions.m"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
		0A3CEE771D05693E008A4BB0 /* StatesController+ContextMenu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = "StatesController+ContextMenu.h"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
		0A3CEE781D05693E008A4BB0 /* StatesController+ContextMenu.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = "StatesController+ContextMenu.m"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
		0A4BDCAC1CFEBDC600D3584F /* STSketch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STSketch.h; sourceTree = "<group>"; };
		0A4BDCAD1CFEBDC600D3584F /* STSketch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STSketch.m; sourceTree = "<group>"; };
		0A4BDCB41CFEC5C200D3584F /* Aspects.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Aspects.h; path = vendor/Aspects.h; sourceTree = "<group>"; };
		0A4BDCB51CFEC5C200D3584F /* Aspects.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Aspects.m; path = vendor/Aspects.m; sourceTree = "<group>"; };
		0A4BDCB81CFED17200D3584F /* STSketchPluginContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STSketchPluginContext.h; sourceTree = "<group>"; };
		0A4BDCB91CFED17200D3584F /* STSketchPluginContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STSketchPluginContext.m; sourceTree = "<group>"; };
		0A7160F11D09279C008A3F78 /* STUpdateButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STUpdateButton.h; sourceTree = "<group>"; };
		0A7160F21D09279C008A3F78 /* STUpdateButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STUpdateButton.m; sourceTree = "<group>"; };
		0A7E78FF1CFED94800CAB318 /* runtime.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; name = runtime.js; path = lib/runtime.js; sourceTree = "<group>"; };
		0A9BE3C41D06F89E00257F99 /* dirty.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = dirty.png; sourceTree = "<group>"; };
		0A9BE3C51D06F89E00257F99 /* dirty@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "dirty@2x.png"; sourceTree = "<group>"; };
		0A9C85921D0B001B00231073 /* STPlaceholderView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STPlaceholderView.h; sourceTree = "<group>"; };
		0A9C85931D0B001B00231073 /* STPlaceholderView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STPlaceholderView.m; sourceTree = "<group>"; };
		0A9CBE3C1D09D8C700748DFA /* STTableCellView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STTableCellView.h; sourceTree = "<group>"; };
		0A9CBE3D1D09D8C700748DFA /* STTableCellView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STTableCellView.m; sourceTree = "<group>"; };
		0A9CBE3F1D09DEFB00748DFA /* STHeaderView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STHeaderView.h; sourceTree = "<group>"; };
		0A9CBE401D09DEFB00748DFA /* STHeaderView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STHeaderView.m; sourceTree = "<group>"; };
		0AAB1C4A1CFF2FEB006512AF /* STPage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STPage.h; sourceTree = "<group>"; };
		0AAB1C4B1CFF2FF6006512AF /* STDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STDocument.h; sourceTree = "<group>"; };
		0AAB1C4C1CFF2FFE006512AF /* STLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STLayer.h; sourceTree = "<group>"; };
		0AAB1C4D1CFF3006006512AF /* STArtboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STArtboard.h; sourceTree = "<group>"; };
		0AAB1C501CFF3217006512AF /* STCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STCommand.h; sourceTree = "<group>"; };
		0AAB1C521CFF33C8006512AF /* STLayerState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STLayerState.h; sourceTree = "<group>"; };
		0AAB1C531CFF33C8006512AF /* STLayerState.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STLayerState.m; sourceTree = "<group>"; };
		0AAB1C591CFF3D56006512AF /* STStateDescription.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STStateDescription.h; sourceTree = "<group>"; };
		0AAB1C5A1CFF3D56006512AF /* STStateDescription.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STStateDescription.m; sourceTree = "<group>"; };
		0AAB1C5C1CFF40CA006512AF /* STStatefulArtboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STStatefulArtboard.h; sourceTree = "<group>"; };
		0AAB1C5D1CFF40CA006512AF /* STStatefulArtboard.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STStatefulArtboard.m; sourceTree = "<group>"; };
		0AB737AA1D04512600E79D3D /* STTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STTableView.h; sourceTree = "<group>"; };
		0AB737AB1D04512600E79D3D /* STTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STTableView.m; sourceTree = "<group>"; };
		0AC4CD8F1D0BDDD000829E45 /* STTextField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STTextField.h; sourceTree = "<group>"; };
		0AC4CD901D0BDDD000829E45 /* STTextField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STTextField.m; sourceTree = "<group>"; };
		0AC4CD921D0BE52300829E45 /* NSArray+HigherOrder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+HigherOrder.h"; sourceTree = "<group>"; };
		0AC4CD931D0BE52300829E45 /* NSArray+HigherOrder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+HigherOrder.m"; sourceTree = "<group>"; };
		0AD7BE031CFDE548003C77BB /* StatesController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = StatesController.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
		0AD7BE041CFDE548003C77BB /* StatesController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = StatesController.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
		0AD7BE081CFDE680003C77BB /* plugin.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; lineEnding = 0; path = plugin.js; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.javascript; };
		0AD7BE0A1CFDF088003C77BB /* StatesWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = StatesWindow.xib; sourceTree = "<group>"; };
		0AE014F41D0EA24C00F39C32 /* NSArray+Indexes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+Indexes.h"; sourceTree = "<group>"; };
		0AE014F51D0EA24C00F39C32 /* NSArray+Indexes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+Indexes.m"; sourceTree = "<group>"; };
		0AE014F71D0EB3EA00F39C32 /* StatesController+DragNDrop.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "StatesController+DragNDrop.h"; sourceTree = "<group>"; };
		0AE014F81D0EB3EA00F39C32 /* StatesController+DragNDrop.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "StatesController+DragNDrop.m"; sourceTree = "<group>"; };
		0AE8BF401D02FC6E00E0C4A8 /* STStatefulArtboard+Backend.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "STStatefulArtboard+Backend.h"; sourceTree = "<group>"; };
		0AE8BF411D02FC6E00E0C4A8 /* STStatefulArtboard+Backend.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "STStatefulArtboard+Backend.m"; sourceTree = "<group>"; };
/* 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 = "<group>";
		};
		0A3CE58E1CFCBB6800B8C552 = {
			isa = PBXGroup;
			children = (
				0A291EAA1D59C0820003F2A3 /* Build Configuration */,
				0A3CE5A01CFCBBCD00B8C552 /* manifest.json */,
				0AD7BE071CFDE658003C77BB /* JS */,
				0A3CE5991CFCBB6800B8C552 /* Native Code */,
				0AE8BF431D030E7C00E0C4A8 /* Helpers */,
				0A9BE3C31D06F89E00257F99 /* Images */,
				0A4BDCB01CFEC37000D3584F /* Vendor */,
				0A3CE5981CFCBB6800B8C552 /* Products */,
			);
			sourceTree = "<group>";
		};
		0A3CE5981CFCBB6800B8C552 /* Products */ = {
			isa = PBXGroup;
			children = (
				0A3CE5971CFCBB6800B8C552 /* States.bundle */,
			);
			name = Products;
			sourceTree = "<group>";
		};
		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 = "<group>";
		};
		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 = "<group>";
		};
		0A4BDCB01CFEC37000D3584F /* Vendor */ = {
			isa = PBXGroup;
			children = (
				0A4BDCB41CFEC5C200D3584F /* Aspects.h */,
				0A4BDCB51CFEC5C200D3584F /* Aspects.m */,
			);
			name = Vendor;
			sourceTree = "<group>";
		};
		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 = "<group>";
		};
		0A7E79001CFEDA1500CAB318 /* lib */ = {
			isa = PBXGroup;
			children = (
				0A7E78FF1CFED94800CAB318 /* runtime.js */,
			);
			name = lib;
			sourceTree = "<group>";
		};
		0A9BE3C31D06F89E00257F99 /* Images */ = {
			isa = PBXGroup;
			children = (
				0A9BE3C41D06F89E00257F99 /* dirty.png */,
				0A9BE3C51D06F89E00257F99 /* dirty@2x.png */,
			);
			path = Images;
			sourceTree = "<group>";
		};
		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 = "<group>";
		};
		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 = "<group>";
		};
		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 = "<group>";
		};
		0AD7BE071CFDE658003C77BB /* JS */ = {
			isa = PBXGroup;
			children = (
				0AD7BE081CFDE680003C77BB /* plugin.js */,
				0A7E79001CFEDA1500CAB318 /* lib */,
			);
			name = JS;
			sourceTree = "<group>";
		};
		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 = "<group>";
		};
/* 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
================================================
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
   version = "1.0">
   <FileRef
      location = "self:/Users/rodionovd/Code/Contracting/States/States.xcodeproj">
   </FileRef>
</Workspace>


================================================
FILE: Plugin/States.xcodeproj/xcshareddata/xcschemes/States for Beta.xcscheme
================================================
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
   LastUpgradeVersion = "0730"
   version = "1.3">
   <BuildAction
      parallelizeBuildables = "YES"
      buildImplicitDependencies = "YES">
      <BuildActionEntries>
         <BuildActionEntry
            buildForTesting = "YES"
            buildForRunning = "YES"
            buildForProfiling = "YES"
            buildForArchiving = "YES"
            buildForAnalyzing = "YES">
            <BuildableReference
               BuildableIdentifier = "primary"
               BlueprintIdentifier = "0A3CE5961CFCBB6800B8C552"
               BuildableName = "States.bundle"
               BlueprintName = "States"
               ReferencedContainer = "container:States.xcodeproj">
            </BuildableReference>
         </BuildActionEntry>
      </BuildActionEntries>
   </BuildAction>
   <TestAction
      buildConfiguration = "Debug"
      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
      shouldUseLaunchSchemeArgsEnv = "YES">
      <Testables>
      </Testables>
      <AdditionalOptions>
      </AdditionalOptions>
   </TestAction>
   <LaunchAction
      buildConfiguration = "Debug"
      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
      launchStyle = "0"
      useCustomWorkingDirectory = "NO"
      ignoresPersistentStateOnLaunch = "NO"
      debugDocumentVersioning = "YES"
      debugServiceExtension = "internal"
      allowLocationSimulation = "YES">
      <PathRunnable
         runnableDebuggingMode = "0"
         BundleIdentifier = "com.bohemiancoding.sketch3.beta"
         FilePath = "/Applications/Sketch Beta.app">
      </PathRunnable>
      <MacroExpansion>
         <BuildableReference
            BuildableIdentifier = "primary"
            BlueprintIdentifier = "0A3CE5961CFCBB6800B8C552"
            BuildableName = "States.bundle"
            BlueprintName = "States"
            ReferencedContainer = "container:States.xcodeproj">
         </BuildableReference>
      </MacroExpansion>
      <AdditionalOptions>
      </AdditionalOptions>
   </LaunchAction>
   <ProfileAction
      buildConfiguration = "Release"
      shouldUseLaunchSchemeArgsEnv = "YES"
      savedToolIdentifier = ""
      useCustomWorkingDirectory = "NO"
      debugDocumentVersioning = "YES">
      <MacroExpansion>
         <BuildableReference
            BuildableIdentifier = "primary"
            BlueprintIdentifier = "0A3CE5961CFCBB6800B8C552"
            BuildableName = "States.bundle"
            BlueprintName = "States"
            ReferencedContainer = "container:States.xcodeproj">
         </BuildableReference>
      </MacroExpansion>
   </ProfileAction>
   <AnalyzeAction
      buildConfiguration = "Debug">
   </AnalyzeAction>
   <ArchiveAction
      buildConfiguration = "Release"
      revealArchiveInOrganizer = "YES">
   </ArchiveAction>
</Scheme>


================================================
FILE: Plugin/States.xcodeproj/xcshareddata/xcschemes/States.xcscheme
================================================
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
   LastUpgradeVersion = "0730"
   version = "1.3">
   <BuildAction
      parallelizeBuildables = "YES"
      buildImplicitDependencies = "YES">
      <BuildActionEntries>
         <BuildActionEntry
            buildForTesting = "YES"
            buildForRunning = "YES"
            buildForProfiling = "YES"
            buildForArchiving = "YES"
            buildForAnalyzing = "YES">
            <BuildableReference
               BuildableIdentifier = "primary"
               BlueprintIdentifier = "0A3CE5961CFCBB6800B8C552"
               BuildableName = "States.bundle"
               BlueprintName = "States"
               ReferencedContainer = "container:States.xcodeproj">
            </BuildableReference>
         </BuildActionEntry>
      </BuildActionEntries>
   </BuildAction>
   <TestAction
      buildConfiguration = "Debug"
      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
      shouldUseLaunchSchemeArgsEnv = "YES">
      <Testables>
      </Testables>
      <AdditionalOptions>
      </AdditionalOptions>
   </TestAction>
   <LaunchAction
      buildConfiguration = "Debug"
      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
      launchStyle = "0"
      useCustomWorkingDirectory = "NO"
      ignoresPersistentStateOnLaunch = "NO"
      debugDocumentVersioning = "YES"
      debugServiceExtension = "internal"
      allowLocationSimulation = "YES">
      <PathRunnable
         runnableDebuggingMode = "0"
         BundleIdentifier = "com.bohemiancoding.sketch3"
         FilePath = "/Applications/Sketch.app">
      </PathRunnable>
      <MacroExpansion>
         <BuildableReference
            BuildableIdentifier = "primary"
            BlueprintIdentifier = "0A3CE5961CFCBB6800B8C552"
            BuildableName = "States.bundle"
            BlueprintName = "States"
            ReferencedContainer = "container:States.xcodeproj">
         </BuildableReference>
      </MacroExpansion>
      <AdditionalOptions>
      </AdditionalOptions>
   </LaunchAction>
   <ProfileAction
      buildConfiguration = "Release"
      shouldUseLaunchSchemeArgsEnv = "YES"
      savedToolIdentifier = ""
      useCustomWorkingDirectory = "NO"
      debugDocumentVersioning = "YES">
      <MacroExpansion>
         <BuildableReference
            BuildableIdentifier = "primary"
            BlueprintIdentifier = "0A3CE5961CFCBB6800B8C552"
            BuildableName = "States.bundle"
            BlueprintName = "States"
            ReferencedContainer = "container:States.xcodeproj">
         </BuildableReference>
      </MacroExpansion>
   </ProfileAction>
   <AnalyzeAction
      buildConfiguration = "Debug">
   </AnalyzeAction>
   <ArchiveAction
      buildConfiguration = "Release"
      revealArchiveInOrganizer = "YES">
   </ArchiveAction>
</Scheme>


================================================
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 <Foundation/Foundation.h>

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 <NSObject>

/// 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 <NSObject>

/// 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<AspectInfo>`, 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<AspectInfo>`.
///
/// @note Hooking static methods is not supported.
/// @return A token which allows to later deregister the aspect.
+ (id<AspectToken>)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<AspectToken>)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 <libkern/OSAtomic.h>
#import <objc/runtime.h>
#import <objc/message.h>

#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 <AspectInfo>
- (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<AspectInfo>)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<AspectToken>)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<AspectToken>)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<AspectInfo>. 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<NSObject> 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<NSCopying>)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<AspectInfo>)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
================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>BuildMachineOSBuild</key>
	<string>15G31</string>
	<key>CFBundleDevelopmentRegion</key>
	<string>en</string>
	<key>CFBundleExecutable</key>
	<string>States</string>
	<key>CFBundleIdentifier</key>
	<string>com.edenvidal.states-for-sketch</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>States</string>
	<key>CFBundlePackageType</key>
	<string>BNDL</string>
	<key>CFBundleShortVersionString</key>
	<string>1.0.0</string>
	<key>CFBundleSignature</key>
	<string>????</string>
	<key>CFBundleSupportedPlatforms</key>
	<array>
		<string>MacOSX</string>
	</array>
	<key>CFBundleVersion</key>
	<string>1</string>
	<key>DTCompiler</key>
	<string>com.apple.compilers.llvm.clang.1_0</string>
	<key>DTPlatformBuild</key>
	<string>7D1014</string>
	<key>DTPlatformVersion</key>
	<string>GM</string>
	<key>DTSDKBuild</key>
	<string>15E60</string>
	<key>DTSDKName</key>
	<string>macosx10.11</string>
	<key>DTXcode</key>
	<string>0731</string>
	<key>DTXcodeBuild</key>
	<string>7D1014</string>
	<key>NSHumanReadableCopyright</key>
	<string>Copyright © 2016 Eden Vidal. All rights reserved.</string>
</dict>
</plist>


================================================
FILE: States.sketchplugin/Contents/Resources/States.bundle/Contents/_CodeSignature/CodeResources
================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>files</key>
	<dict>
		<key>Resources/StatesWindow.nib</key>
		<data>
		tPNG8G23xzx2FF9fJkMeLlowPCg=
		</data>
		<key>Resources/dirty.tiff</key>
		<data>
		OigIS04hpst041DCQF9TZTP28HM=
		</data>
	</dict>
	<key>files2</key>
	<dict>
		<key>Resources/StatesWindow.nib</key>
		<dict>
			<key>hash</key>
			<data>
			tPNG8G23xzx2FF9fJkMeLlowPCg=
			</data>
			<key>hash2</key>
			<data>
			R+X7XpAk5/v35Io50Z1VeFKd+JD0rIEYCGO62q9luas=
			</data>
		</dict>
		<key>Resources/dirty.tiff</key>
		<dict>
			<key>hash</key>
			<data>
			OigIS04hpst041DCQF9TZTP28HM=
			</data>
			<key>hash2</key>
			<data>
			7KCD71Cxnh0qc7BUXhpJv/M2LHesZc1jZI4/QyOsTC0=
			</data>
		</dict>
	</dict>
	<key>rules</key>
	<dict>
		<key>^Resources/</key>
		<true/>
		<key>^Resources/.*\.lproj/</key>
		<dict>
			<key>optional</key>
			<true/>
			<key>weight</key>
			<real>1000</real>
		</dict>
		<key>^Resources/.*\.lproj/locversion.plist$</key>
		<dict>
			<key>omit</key>
			<true/>
			<key>weight</key>
			<real>1100</real>
		</dict>
		<key>^version.plist$</key>
		<true/>
	</dict>
	<key>rules2</key>
	<dict>
		<key>.*\.dSYM($|/)</key>
		<dict>
			<key>weight</key>
			<real>11</real>
		</dict>
		<key>^(.*/)?\.DS_Store$</key>
		<dict>
			<key>omit</key>
			<true/>
			<key>weight</key>
			<real>2000</real>
		</dict>
		<key>^(Frameworks|SharedFrameworks|PlugIns|Plug-ins|XPCServices|Helpers|MacOS|Library/(Automator|Spotlight|LoginItems))/</key>
		<dict>
			<key>nested</key>
			<true/>
			<key>weight</key>
			<real>10</real>
		</dict>
		<key>^.*</key>
		<true/>
		<key>^Info\.plist$</key>
		<dict>
			<key>omit</key>
			<true/>
			<key>weight</key>
			<real>20</real>
		</dict>
		<key>^PkgInfo$</key>
		<dict>
			<key>omit</key>
			<true/>
			<key>weight</key>
			<
Download .txt
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
Download .txt
SYMBOL INDEX (61 symbols across 4 files)

FILE: Plugin/States/STStatefulArtboard.h
  function interface (line 14) | interface STStatefulArtboard : NSObject <STArtboard>

FILE: Plugin/plugin.js
  function showStatesWindow (line 9) | function showStatesWindow(context)

FILE: States.sketchplugin/Contents/Sketch/plugin.js
  function showStatesWindow (line 9) | function showStatesWindow(context)

FILE: js/webflow.js
  function n (line 7) | function n(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{...
  function v (line 7) | function v(t){i.env()&&(l(t.design)&&u.on("__wf_design",t.design),l(t.pr...
  function m (line 7) | function m(t){l(t.design)&&u.off("__wf_design",t.design),l(t.preview)&&u...
  function z (line 7) | function z(t,e){var n=[],i={};return i.up=f.throttle(function(t){f.each(...
  function T (line 7) | function T(t){l(t)&&t()}
  function E (line 7) | function E(){_&&(_.reject(),u.off("load",_.resolve)),_=new a.Deferred,u....
  function e (line 7) | function e(t,e){return(new L.Bare).init(t,e)}
  function i (line 7) | function i(t){return t.replace(/[A-Z]/g,function(t){return"-"+t.toLowerC...
  function r (line 7) | function r(t){var e=parseInt(t.slice(1),16);return[e>>16&255,e>>8&255,25...
  function o (line 7) | function o(t,e,n){return"#"+(1<<24|t<<16|e<<8|n).toString(16).slice(1)}
  function s (line 7) | function s(){}
  function a (line 7) | function a(t,e,n){c("Units do not match ["+t+"]: "+e+", "+n)}
  function u (line 7) | function u(t,e,n){if(void 0!==e&&(n=e),void 0===t)return n;var i=n;retur...
  function c (line 7) | function c(t){X.debug&&window&&window.console.warn(t)}
  function r (line 7) | function r(t){return"object"==(void 0===t?"undefined":n(t))}
  function o (line 7) | function o(t){return"function"==typeof t}
  function s (line 7) | function s(){}
  function c (line 7) | function c(){var t=new l;return o(t.init)&&t.init.apply(t,arguments),t}
  function l (line 7) | function l(){}
  function r (line 7) | function r(t,e){var n=function(t){for(var e=-1,n=t?t.length:0,i=[];++e<n...
  function o (line 7) | function o(t,e,i){if(t){var o=void 0===t?"undefined":n(t);if(e||(this.ti...
  function s (line 7) | function s(){if(this.timer&&this.timer.destroy(),this.active=!1,this.que...
  function a (line 7) | function a(t){var e;this.timer&&this.timer.destroy(),this.queue=[],this....
  function l (line 7) | function l(){a.call(this),this.el.style.display="none"}
  function f (line 7) | function f(){this.el.offsetHeight}
  function h (line 7) | function h(){var t,e,n=[];for(t in this.upstream&&n.push(this.upstream),...
  function d (line 7) | 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.t...
  function p (line 7) | function p(t){t.stop()}
  function m (line 7) | function m(t,e){t.set(e)}
  function g (line 7) | function g(t){this.$el.css(t)}
  function b (line 7) | function b(t,n){e[t]=function(){return this.children?function(t,e){var n...
  function n (line 7) | function n(e,n){var i=t.data(e,v)||t.data(e,v,new F.Bare);return i.el||i...
  function e (line 7) | function e(){var t=this.get();this.update("auto");var e=this.get();retur...
  function i (line 7) | function i(t){var e=/rgba?\((\d+),\s*(\d+),\s*(\d+)/.exec(t);return(e?o(...
  function n (line 7) | 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....
  function n (line 7) | function n(){var t,e,i,r=u.length;if(r)for(B(n),e=R(),t=r;t--;)(i=u[t])&...
  function f (line 7) | function f(){var n=r.fullScreen||r.mozFullScreen||r.webkitIsFullScreen||...
  function h (line 7) | function h(){var t=s.children(a),n=t.length&&t.get(0)===e,r=i.env("edito...
  function x (line 29) | function x(t){t&&(v={},e.each(t,function(t){v[t.slug]=t.value}),_())}
  function _ (line 29) | function _(){!function(){var e=t("[data-ix]");if(!e.length)return;e.each...
  function k (line 29) | function k(n,o){var a=t(o),c=a.attr("data-ix"),l=v[c];if(l){var h=l.trig...
  function z (line 29) | function z(t){if(!t)return 0;t=String(t);var e=parseInt(t,10);return e!=...
  function T (line 29) | function T(e,n){t(n).off(u)}
  function E (line 29) | function E(){for(var t=a.scrollTop(),e=a.height(),n=m.length,i=0;i<n;i++...
  function q (line 29) | function q(){for(var t=w.length,e=0;e<t;e++)w[e]()}
  function O (line 29) | function O(){for(var t=g.length,e=0;e<t;e++)g[e]()}
  function A (line 29) | function A(e,i,r,o){var s=(r=r||{}).done,a=e.preserve3d;if(!n||r.force){...
  function S (line 29) | function S(t,e,n){var r="add",o="start";n.start&&(r=o="then");var s=e.tr...
  function $ (line 29) | function $(t,e){var n=e&&e.omit3d,i={},r=!1;for(var o in t)"transition"!...
  function v (line 29) | function v(e){var i=n&&e.getAttribute("href-disabled")||e.getAttribute("...
  function m (line 29) | function m(){var t=a.scrollTop(),n=a.height();e.each(r,function(e){var i...
  function w (line 29) | function w(t,e,n){var i=t.hasClass(e);n&&i||(n||i)&&(n?t.addClass(e):t.r...
  function a (line 29) | function a(e,a){if(s.test(e)){var u=t("#"+e);if(u.length){if(a&&(a.preve...
  function r (line 29) | function r(e,n,i){var r=t.Event(e,{originalEvent:n});t(n.target).trigger...
  function l (line 29) | function l(t){var i=t.touches;i&&i.length>1||(s=!0,a=!1,i?(u=!0,e=i[0].c...
  function f (line 29) | function f(t){if(s){if(u&&"mousemove"===t.type)return t.preventDefault()...
  function h (line 29) | function h(t){if(s){if(s=!1,u&&"mouseup"===t.type)return t.preventDefaul...
  function d (line 29) | function d(){s=!1}
Condensed preview — 81 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (310K chars).
[
  {
    "path": ".gitignore",
    "chars": 25,
    "preview": "\nStates.sketchplugin.zip\n"
  },
  {
    "path": "Plugin/Debug.xcconfig",
    "chars": 286,
    "preview": "// Debug.xcconfig\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms\n/"
  },
  {
    "path": "Plugin/LICENSE",
    "chars": 1088,
    "preview": "MIT License\n\nCopyright (c) 2016 Eden Vidal <edenvidal@gmail.com>\n\nPermission is hereby granted, free of charge, to any p"
  },
  {
    "path": "Plugin/README.md",
    "chars": 546,
    "preview": "# States of the artboard — Sketch Plugin\n\nCreate different states and switch between them easily. Just like layer comps "
  },
  {
    "path": "Plugin/Release.xcconfig",
    "chars": 288,
    "preview": "// Release.xcconfig\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms"
  },
  {
    "path": "Plugin/States/Info.plist",
    "chars": 888,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/P"
  },
  {
    "path": "Plugin/States/NSArray+HigherOrder.h",
    "chars": 400,
    "preview": "// NSArray+HigherOrder.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the "
  },
  {
    "path": "Plugin/States/NSArray+HigherOrder.m",
    "chars": 792,
    "preview": "// NSArray+HigherOrder.m\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the "
  },
  {
    "path": "Plugin/States/NSArray+Indexes.h",
    "chars": 312,
    "preview": "// NSArray+Indexes.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the term"
  },
  {
    "path": "Plugin/States/NSArray+Indexes.m",
    "chars": 462,
    "preview": "// NSArray+Indexes.m\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the term"
  },
  {
    "path": "Plugin/States/STArtboard.h",
    "chars": 391,
    "preview": "// STArtboard.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms\n// "
  },
  {
    "path": "Plugin/States/STColorFactory.h",
    "chars": 876,
    "preview": "// STColorFactory.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms"
  },
  {
    "path": "Plugin/States/STColorFactory.m",
    "chars": 1695,
    "preview": "// STColorFactory.m\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms"
  },
  {
    "path": "Plugin/States/STCommand.h",
    "chars": 420,
    "preview": "// STCommand.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms\n// o"
  },
  {
    "path": "Plugin/States/STDocument.h",
    "chars": 545,
    "preview": "// STDocument.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms\n// "
  },
  {
    "path": "Plugin/States/STHeaderView.h",
    "chars": 281,
    "preview": "// STHeaderView.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms\n/"
  },
  {
    "path": "Plugin/States/STHeaderView.m",
    "chars": 878,
    "preview": "// STHeaderView.m\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms\n/"
  },
  {
    "path": "Plugin/States/STLayer.h",
    "chars": 718,
    "preview": "// STLayer.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms\n// of "
  },
  {
    "path": "Plugin/States/STLayerState.h",
    "chars": 1210,
    "preview": "// STLayerState.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms\n/"
  },
  {
    "path": "Plugin/States/STLayerState.m",
    "chars": 2594,
    "preview": "// STLayerState.m\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms\n/"
  },
  {
    "path": "Plugin/States/STPage.h",
    "chars": 936,
    "preview": "// STPage.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms\n// of t"
  },
  {
    "path": "Plugin/States/STPlaceholderView.h",
    "chars": 338,
    "preview": "// STPlaceholderView.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the te"
  },
  {
    "path": "Plugin/States/STPlaceholderView.m",
    "chars": 482,
    "preview": "// STPlaceholderView.m\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the te"
  },
  {
    "path": "Plugin/States/STSketch.h",
    "chars": 1518,
    "preview": "// STSketch.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms\n// of"
  },
  {
    "path": "Plugin/States/STSketch.m",
    "chars": 6500,
    "preview": "// STSketch.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms\n// of"
  },
  {
    "path": "Plugin/States/STSketchPluginContext.h",
    "chars": 560,
    "preview": "// SketchPluginContext.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the "
  },
  {
    "path": "Plugin/States/STSketchPluginContext.m",
    "chars": 664,
    "preview": "// SketchPluginContext.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the "
  },
  {
    "path": "Plugin/States/STStateDescription.h",
    "chars": 1208,
    "preview": "// STStateDescription.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the t"
  },
  {
    "path": "Plugin/States/STStateDescription.m",
    "chars": 2086,
    "preview": "// STStateDescription.m\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the t"
  },
  {
    "path": "Plugin/States/STStatefulArtboard+Backend.h",
    "chars": 1004,
    "preview": "// STStatefulArtboard+Backend.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed und"
  },
  {
    "path": "Plugin/States/STStatefulArtboard+Backend.m",
    "chars": 2107,
    "preview": "// STStatefulArtboard+Backend.m\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed und"
  },
  {
    "path": "Plugin/States/STStatefulArtboard+Snapshots.h",
    "chars": 468,
    "preview": "// STStatefulArtboard+Snapshots.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed u"
  },
  {
    "path": "Plugin/States/STStatefulArtboard+Snapshots.m",
    "chars": 888,
    "preview": "// STStatefulArtboard+Snapshots.m\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed u"
  },
  {
    "path": "Plugin/States/STStatefulArtboard.h",
    "chars": 2401,
    "preview": "// StatefulArtboard.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the ter"
  },
  {
    "path": "Plugin/States/STStatefulArtboard.m",
    "chars": 9335,
    "preview": "// StatefulArtboard.m\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the ter"
  },
  {
    "path": "Plugin/States/STTableCellView.h",
    "chars": 694,
    "preview": "// STTableCellView.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the term"
  },
  {
    "path": "Plugin/States/STTableCellView.m",
    "chars": 879,
    "preview": "// STTableCellView.m\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the term"
  },
  {
    "path": "Plugin/States/STTableRowView.h",
    "chars": 438,
    "preview": "// STTableRowView.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms"
  },
  {
    "path": "Plugin/States/STTableRowView.m",
    "chars": 1270,
    "preview": "// STTableRowView.m\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms"
  },
  {
    "path": "Plugin/States/STTableView.h",
    "chars": 323,
    "preview": "// STTableView.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms\n//"
  },
  {
    "path": "Plugin/States/STTableView.m",
    "chars": 886,
    "preview": "// STTableView.m\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms\n//"
  },
  {
    "path": "Plugin/States/STTextField.h",
    "chars": 532,
    "preview": "// STTextField.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms\n//"
  },
  {
    "path": "Plugin/States/STTextField.m",
    "chars": 708,
    "preview": "// STTextField.m\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms\n//"
  },
  {
    "path": "Plugin/States/STUpdateButton.h",
    "chars": 429,
    "preview": "// STUpdateButton.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms"
  },
  {
    "path": "Plugin/States/STUpdateButton.m",
    "chars": 1478,
    "preview": "// STUpdateButton.m\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms"
  },
  {
    "path": "Plugin/States/STWindow.h",
    "chars": 272,
    "preview": "// STWindow.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms\n// of"
  },
  {
    "path": "Plugin/States/STWindow.m",
    "chars": 326,
    "preview": "// STWindow.m\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms\n// of"
  },
  {
    "path": "Plugin/States/StatesController+ContextMenu.h",
    "chars": 391,
    "preview": "// StatesController+ContextMenu.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed u"
  },
  {
    "path": "Plugin/States/StatesController+ContextMenu.m",
    "chars": 2940,
    "preview": "// StatesController+ContextMenu.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed u"
  },
  {
    "path": "Plugin/States/StatesController+Decisions.h",
    "chars": 547,
    "preview": "// StatesController+Decisions.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed und"
  },
  {
    "path": "Plugin/States/StatesController+Decisions.m",
    "chars": 3558,
    "preview": "// StatesController+Decisions.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed und"
  },
  {
    "path": "Plugin/States/StatesController+DragNDrop.h",
    "chars": 865,
    "preview": "// StatesController+DragNDrop.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed und"
  },
  {
    "path": "Plugin/States/StatesController+DragNDrop.m",
    "chars": 2086,
    "preview": "// StatesController+DragNDrop.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed und"
  },
  {
    "path": "Plugin/States/StatesController+Naming.h",
    "chars": 720,
    "preview": "// StatesController+Naming.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under "
  },
  {
    "path": "Plugin/States/StatesController+Naming.m",
    "chars": 1309,
    "preview": "// StatesController+Naming.m\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under "
  },
  {
    "path": "Plugin/States/StatesController.h",
    "chars": 1570,
    "preview": "// StatesController.h\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the ter"
  },
  {
    "path": "Plugin/States/StatesController.m",
    "chars": 16078,
    "preview": "// StatesController.m\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the ter"
  },
  {
    "path": "Plugin/States/StatesWindow.xib",
    "chars": 18497,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<document type=\"com.apple.InterfaceBuilder3.Cocoa.XIB\" version=\"3"
  },
  {
    "path": "Plugin/States.xcodeproj/project.pbxproj",
    "chars": 33889,
    "preview": "// !$*UTF8*$!\n{\n\tarchiveVersion = 1;\n\tclasses = {\n\t};\n\tobjectVersion = 46;\n\tobjects = {\n\n/* Begin PBXBuildFile section *"
  },
  {
    "path": "Plugin/States.xcodeproj/project.xcworkspace/contents.xcworkspacedata",
    "chars": 192,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Workspace\n   version = \"1.0\">\n   <FileRef\n      location = \"self:/Users/rodionov"
  },
  {
    "path": "Plugin/States.xcodeproj/xcshareddata/xcschemes/States for Beta.xcscheme",
    "chars": 3026,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Scheme\n   LastUpgradeVersion = \"0730\"\n   version = \"1.3\">\n   <BuildAction\n      "
  },
  {
    "path": "Plugin/States.xcodeproj/xcshareddata/xcschemes/States.xcscheme",
    "chars": 3016,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Scheme\n   LastUpgradeVersion = \"0730\"\n   version = \"1.3\">\n   <BuildAction\n      "
  },
  {
    "path": "Plugin/Versioning.xcconfig",
    "chars": 28,
    "preview": "IEXP_SOURCE_VERSION = 1.0.0\n"
  },
  {
    "path": "Plugin/lib/runtime.js",
    "chars": 863,
    "preview": "// runtime.js\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms\n// of"
  },
  {
    "path": "Plugin/manifest.json",
    "chars": 479,
    "preview": "{\n\t\"name\": \"States\",\n\t\"description\": \"Create different artboard states and switch between them easily\",\n\t\"author\": \"Eden"
  },
  {
    "path": "Plugin/plugin.js",
    "chars": 598,
    "preview": "// plugin.js\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms\n// of "
  },
  {
    "path": "Plugin/vendor/Aspects.h",
    "chars": 3669,
    "preview": "//\n//  Aspects.h\n//  Aspects - A delightful, simple library for aspect oriented programming.\n//\n//  Copyright (c) 2014 P"
  },
  {
    "path": "Plugin/vendor/Aspects.m",
    "chars": 39187,
    "preview": "//\n//  Aspects.m\n//  Aspects - A delightful, simple library for aspect oriented programming.\n//\n//  Copyright (c) 2014 P"
  },
  {
    "path": "States.sketchplugin/Contents/Resources/States.bundle/Contents/Info.plist",
    "chars": 1334,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/P"
  },
  {
    "path": "States.sketchplugin/Contents/Resources/States.bundle/Contents/_CodeSignature/CodeResources",
    "chars": 2628,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/P"
  },
  {
    "path": "States.sketchplugin/Contents/Sketch/lib/runtime.js",
    "chars": 863,
    "preview": "// runtime.js\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms\n// of"
  },
  {
    "path": "States.sketchplugin/Contents/Sketch/manifest.json",
    "chars": 479,
    "preview": "{\n\t\"name\": \"States\",\n\t\"description\": \"Create different artboard states and switch between them easily\",\n\t\"author\": \"Eden"
  },
  {
    "path": "States.sketchplugin/Contents/Sketch/plugin.js",
    "chars": 598,
    "preview": "// plugin.js\n// Copyright (c) 2016 Eden Vidal\n//\n// This software may be modified and distributed under the terms\n// of "
  },
  {
    "path": "css/normalize.css",
    "chars": 7772,
    "preview": "/*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */\n/**\n * 1. Set default font family to sans-s"
  },
  {
    "path": "css/states.webflow.css",
    "chars": 6048,
    "preview": "body {\n  background-color: #f2f2f2;\n  color: #333;\n  font-size: 16px;\n  line-height: 20px;\n}\n\nh1 {\n  margin-top: 20px;\n "
  },
  {
    "path": "css/webflow.css",
    "chars": 40092,
    "preview": "@font-face {\n  font-family: 'webflow-icons';\n  src: url(\"data:application/x-font-ttf;charset=utf-8;base64,AAEAAAALAIAAAw"
  },
  {
    "path": "index.html",
    "chars": 7517,
    "preview": "<!DOCTYPE html>\n<!--  Last Published: Thu Aug 09 2018 08:47:02 GMT+0000 (UTC)  -->\n<html data-wf-page=\"574f0289c3c463362"
  },
  {
    "path": "js/webflow.js",
    "chars": 35917,
    "preview": "/*!\n * Webflow: Front-end site library\n * @license MIT\n * Inline scripts may access the api using an async handler:\n *  "
  }
]

// ... and 3 more files (download for full content)

About this extraction

This page contains the full source code of the edenvidal/States GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 81 files (283.4 KB), approximately 85.2k tokens, and a symbol index with 61 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!