If I do
It is hard to follow what you are doing there is no "rasterizeStyle()" there is a "rasterize(targer) where targer is a RasterizeType ENTIRELAYER. or FILLCONTENT, or LAYERCLIPPINGPATH, or LINKEDLAYERS, or SHAPE, or TEXTCONTENTS. There is also a "rasterizeAllLayers()".
And "crop()" would I believe be invalid as well crop requires a bounds to crop to. "crop(bounds[, angle][, width][, height]) where bounds is an array of 4 UnitValue
So how the corp is done depends on the bounds you use. I you crop to the layers bounds any layer style effect that fall outside the layers bounds would be clipped by the document cropped canvas size which is now the same as your layers bounds.. Effects like drop shadows would be lost for there is no canvas for the shadow to fall on.
Your taking the code too literal. I have defined a rasterizeStyle from the script inspector. It does what one does in PS manually.
Yes, crop requires the bounds.
You are right. I realized too that I simply was passing layer.Bounds to crop after the trim or rasterization and they were probably modified. I will have to create extra code to allow for either case(expanding the bounds or keep it to the original)... depending on the case I want. This should solve my problem but requires me to specify which images will have which approach. (essentially save the bounds before I do any rasterizeStyle and pass to crop)
So effectively I need
bounds = layer.Bounds;
crop(bounds); // before it was crop(layer.Bounds) and layer.Bounds was modified by the rasterizeStyle().
I haven't implement it and it will crop my FX on some images that are "within" the canvas. I think I can write a routine to calculate the correct bounds though and that should fix my problem.
One problem what my layer masks were all white outside the canvas but I didn't know. I have to create correctly by creating the selection for what I want to keep then creating the layer. The selection should be white and everything else black. if I invert the select and fill with black paint then everything outside the canvas is white and won't be clipped(even though it may look the same visual in the layers list).
Your title states
To me that is your opinion because of your Idea of what you want. You sometime want style that fall outside of a layers bounds and sometimes you don't. You may be able to create both versions for a single layer document. However when there are many layers that have layer style that fall outside of the layer's bounds some will fall fall on other layers and empty canvas. Trim and Crop work on the document composite. Even if you can get the bounds of all the layers that make the composite and crop to that bounds you will not eliminate all styles that are outside the layer they are on.
IMO Trim does cropping the way you check trim away and works correctly. It will not trim off effects like drop shadows. If you do not want effects that fall outside layers bounds you need to turn the style effects visibility off..