Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For PSD.js, publish dist folder instead of CoffeeScript for portability #293

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/psd.coffee
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# A general purpose parser for Photoshop files. PSDs are broken up in to 4 logical sections:
# the header, resources, the layer mask (including layers), and the preview image. We parse
# each of these sections in order.
#
#
# ## NodeJS Examples
#
#
# ** Parsing asynchronously **
# ``` coffeescript
# PSD.open('path/to/file.psd').then (psd) ->
# console.log psd.tree().export()
# ```
#
#
# ** Parsing synchronously **
# ``` coffeescript
# psd = PSD.fromFile('path/to/file.psd')
# psd.parse()
# console.log psd.tree().export()
# ```
#
#
RSVP = require 'rsvp'
{Module} = require 'coffeescript-module'

Expand All @@ -38,6 +38,7 @@ module.exports = class PSD extends Module
# the PSD object. However, if you already have the PSD data stored as a Uint8Array,
# you can instantiate the PSD object directly.
constructor: (data) ->
super()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to do this to resolve errors such as:

ERROR in ./lib/psd/blend_mode.coffee
Module build failed (from ./node_modules/coffee-loader/dist/cjs.js):
CoffeeScriptError: ./psd.js/lib/psd/blend_mode.coffee:43:5: error: Can't reference 'this' before calling super in derived class constructors
    @blendKey = null
    ^
    at Object.loader (./psd.js/node_modules/coffee-loader/dist/index.js:33:14)
 @ ./lib/psd/layer/blend_modes.coffee 3:12-43
 @ ./lib/psd/layer.coffee 71:17-54
 @ ./lib/psd/layer_mask.coffee 7:8-33
 @ ./lib/psd.coffee 34:12-46

@file = new File(data)
@parsed = false
@header = null
Expand Down
1 change: 1 addition & 0 deletions lib/psd/blend_mode.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module.exports = class BlendMode extends Module
}

constructor: (@file) ->
super()
# The 4 character key for the blending mode.
@blendKey = null

Expand Down
6 changes: 3 additions & 3 deletions lib/psd/channel_image.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ImageFormat = require './image_format.coffee'

# Represents an image for a single layer, which differs slightly in format from
# the full size preview image.
#
#
# The full preview at the end of the PSD document has the same compression for all
# channels, whereas layer images define the compression per color channel. The
# dimensions can also differ per channel if we're parsing mask data (channel ID < -1).
Expand All @@ -14,13 +14,13 @@ module.exports = class ChannelImage extends Image

# Creates a new ChannelImage.
constructor: (file, header, @layer) ->

super(file, header)
# We copy the layer's width and height to private variables because, as you'll see below,
# the dimensions can change if we're parsing a mask channel.
@_width = @layer.width
@_height = @layer.height

super(file, header)

@channelsInfo = @layer.channelsInfo
@hasMask = _.some @channelsInfo, (c) -> c.id < -1
@opacity = @layer.opacity / 255.0
Expand Down
1 change: 1 addition & 0 deletions lib/psd/header.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ module.exports = class Header extends Module
# Creates a new Header.
# @param [File] file The PSD file.
constructor: (@file) ->
super()

# Parses the header data.
parse: ->
Expand Down
5 changes: 3 additions & 2 deletions lib/psd/image.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = class Image extends Module
@includes ImageMode.RGB
@includes ImageMode.CMYK
@includes Export.PNG

# Images can be 1 of 4 different compression types. RLE is the most prevalent, followed by
# RAW. ZIP compression only happens under special circumstances, and is somewhat rare.
COMPRESSIONS = [
Expand All @@ -26,6 +26,7 @@ module.exports = class Image extends Module
]

constructor: (@file, @header) ->
super()
# We can easily calculate the number of pixels with the width and height.
@numPixels = @width() * @height()
@numPixels *= 2 if @depth() is 16
Expand Down Expand Up @@ -86,7 +87,7 @@ module.exports = class Image extends Module

# Parses the compression mode.
parseCompression: -> @file.readShort()

# Parses the image data based on the compression mode.
parseImageData: ->
switch @compression
Expand Down
3 changes: 2 additions & 1 deletion lib/psd/layer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = class Layer extends Module
@includes require('./layer/channel_image.coffee')

constructor: (@file, @header) ->
super()
@mask = {}
@blendingRanges = {}
@adjustments = {}
Expand All @@ -24,7 +25,7 @@ module.exports = class Layer extends Module

@infoKeys = []

# The layer's name can come from one of two places, depending on
# The layer's name can come from one of two places, depending on
# what version of Photoshop was used to create the PSD.
Object.defineProperty @, 'name',
get: ->
Expand Down
13 changes: 7 additions & 6 deletions lib/psd/node.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# tree representation of the document structure. Every layer and group is a node in
# the document tree. All common functionality is here, and both layers and groups extend
# this class with specialized functionality.
#
#
# While you can access the layer data directly, the Node interface provides a somewhat
# higher-level API that makes it easier and less verbose to access the wealth of
# information that's stored in each PSD.
Expand All @@ -27,6 +27,7 @@ module.exports = class Node extends Module
# Every node gets a reference to the layer/group and its parent, which allows us to
# traverse the tree structure. It also builds references to all of its children.
constructor: (@layer, @parent = null) ->
super()
@layer.node = @
@_children = []

Expand Down Expand Up @@ -75,18 +76,18 @@ module.exports = class Node extends Module

# **All properties should be accessed through `get()`**. While many things can be
# accessed without it, using `get()` provides 2 things:
#
#
# * Consistency
# * Access to both data on the Node and the Layer through the same interface.
#
#
# This makes it much cleaner to access stuff like layer info blocks, since you just
# give the name of the block you want to access. For example:
#
#
# ``` coffeescript
# node.get('typeTool').export()
#
#
# # vs
#
#
# node.layer.typeTool().export()
# ```
get: (prop) ->
Expand Down
7 changes: 4 additions & 3 deletions lib/psd/nodes/root.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ module.exports = class Root extends Node

type: 'root'

constructor: (@psd) ->
super Root.layerForPsd(@psd)
constructor: (psd) ->
super Root.layerForPsd(psd)
@psd = psd
@buildHeirarchy()

documentDimensions: -> [
Expand Down Expand Up @@ -56,4 +57,4 @@ module.exports = class Root extends Node
else
currentGroup.children().push new Layer(layer, currentGroup)

@updateDimensions()
@updateDimensions()
Loading