Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.

Commit d38d387

Browse files
committed
Beszer APIs have changed
1 parent 83b9e9e commit d38d387

File tree

4 files changed

+5934
-321
lines changed

4 files changed

+5934
-321
lines changed
Lines changed: 185 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,185 @@
1-
var that=this;function __skpm_run(e,t){that.context=t;var r=function(e){var t={};function r(n){if(t[n])return t[n].exports;var a=t[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,r),a.l=!0,a.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t){Object.defineProperty(t,"__esModule",{value:!0});var r="-",n="∩",a=function(e,t,r,n){if(!((c=e)&&c.isKindOfClass(NSNull)||!c)){e.setStyle(t.style());for(var a=e.splitPathsIntoShapes(),o=a.count(),u=new Array(o),s=o-1;s>=0;s--){var i=a[s];i.setName(t.name()+" "+n+" "+r.name()+(s>0?" "+s:"")),u[s]=i}return u}var c},o=function(e,t,o){var u=e.bezierPathWithTransforms(),s=t.bezierPathWithTransforms(),i=null;switch(o){case r:i=u.booleanSubtractWith(s);break;case n:i=u.booleanIntersectWith(s)}if(i){var c=MSShapeGroup.shapeWithBezierPath(i);switch(o){case r:return a(c,e,t,o);case n:return a(c,t,e,o)}}return null};t.default=function(e){var t=e.selection,u=t.count();if(u>=2){var s=[],i=function(e){for(var t=e[0],n="",a=e.count()-1;a>0;a--)t=MSShapeGroup.shapeWithBezierPath(t.bezierPathWithTransforms().booleanSubtractWith(e[a].bezierPathWithTransforms())),n+=(""!=n?" "+r+" ":"")+e[a].name();return t.setName(n),t.setStyle(e[0].style()),t}(t);s.push(a(i,t[0],i,r));for(var c=1;c<u;c++)s.push(o(t[c],t[0],r)),s.push(o(t[0],t[c],n)),t[c].removeFromParent();s=[].concat.apply([],s.filter(function(e){return e})),t[0].parentGroup().insertLayers_afterLayer(s,t[0]),e.document.currentPage().changeSelectionBySelectingLayers(s),t[0].removeFromParent()}else e.document.showMessage("Select more than one shape")}}]);"default"===e&&"function"==typeof r?r(t):r[e](t)}that.onRun=__skpm_run.bind(this,"default");
1+
var that = this;
2+
function __skpm_run (key, context) {
3+
that.context = context;
4+
5+
var exports =
6+
/******/ (function(modules) { // webpackBootstrap
7+
/******/ // The module cache
8+
/******/ var installedModules = {};
9+
/******/
10+
/******/ // The require function
11+
/******/ function __webpack_require__(moduleId) {
12+
/******/
13+
/******/ // Check if module is in cache
14+
/******/ if(installedModules[moduleId]) {
15+
/******/ return installedModules[moduleId].exports;
16+
/******/ }
17+
/******/ // Create a new module (and put it into the cache)
18+
/******/ var module = installedModules[moduleId] = {
19+
/******/ i: moduleId,
20+
/******/ l: false,
21+
/******/ exports: {}
22+
/******/ };
23+
/******/
24+
/******/ // Execute the module function
25+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
26+
/******/
27+
/******/ // Flag the module as loaded
28+
/******/ module.l = true;
29+
/******/
30+
/******/ // Return the exports of the module
31+
/******/ return module.exports;
32+
/******/ }
33+
/******/
34+
/******/
35+
/******/ // expose the modules object (__webpack_modules__)
36+
/******/ __webpack_require__.m = modules;
37+
/******/
38+
/******/ // expose the module cache
39+
/******/ __webpack_require__.c = installedModules;
40+
/******/
41+
/******/ // define getter function for harmony exports
42+
/******/ __webpack_require__.d = function(exports, name, getter) {
43+
/******/ if(!__webpack_require__.o(exports, name)) {
44+
/******/ Object.defineProperty(exports, name, {
45+
/******/ configurable: false,
46+
/******/ enumerable: true,
47+
/******/ get: getter
48+
/******/ });
49+
/******/ }
50+
/******/ };
51+
/******/
52+
/******/ // getDefaultExport function for compatibility with non-harmony modules
53+
/******/ __webpack_require__.n = function(module) {
54+
/******/ var getter = module && module.__esModule ?
55+
/******/ function getDefault() { return module['default']; } :
56+
/******/ function getModuleExports() { return module; };
57+
/******/ __webpack_require__.d(getter, 'a', getter);
58+
/******/ return getter;
59+
/******/ };
60+
/******/
61+
/******/ // Object.prototype.hasOwnProperty.call
62+
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
63+
/******/
64+
/******/ // __webpack_public_path__
65+
/******/ __webpack_require__.p = "";
66+
/******/
67+
/******/ // Load entry module and return exports
68+
/******/ return __webpack_require__(__webpack_require__.s = 0);
69+
/******/ })
70+
/************************************************************************/
71+
/******/ ([
72+
/* 0 */
73+
/***/ (function(module, exports) {
74+
75+
Object.defineProperty(exports, "__esModule", {
76+
value: true
77+
});
78+
var isNullOrNil = function isNullOrNil(value) {
79+
if (value && value.isKindOfClass(NSNull)) {
80+
return true;
81+
} else if (value) {
82+
return false;
83+
}
84+
return true;
85+
};
86+
87+
var ops = {
88+
SUBTRACT: "-",
89+
INTERSECT: "∩"
90+
};
91+
92+
var splitAndStylePath = function splitAndStylePath(sg, shape1, shape2, op) {
93+
if (!isNullOrNil(sg)) {
94+
sg.setStyle(shape1.style());
95+
var splitNS = sg.splitPathsIntoShapes();
96+
var count = splitNS.count();
97+
var splitJS = new Array(count);
98+
for (var i = count - 1; i >= 0; i--) {
99+
var shape = splitNS[i];
100+
shape.setName(shape1.name() + " " + op + " " + shape2.name() + (i > 0 ? " " + i : ""));
101+
splitJS[i] = shape;
102+
}
103+
return splitJS;
104+
}
105+
};
106+
107+
var shapeGroupFromOp = function shapeGroupFromOp(shape1, shape2, op) {
108+
var path1 = shape1.pathInFrameWithTransforms(),
109+
path2 = shape2.pathInFrameWithTransforms(),
110+
newPath = null;
111+
switch (op) {
112+
case ops.SUBTRACT:
113+
newPath = path1.booleanSubtractWith(path2);
114+
break;
115+
case ops.INTERSECT:
116+
newPath = path1.booleanIntersectWith(path2);
117+
break;
118+
}
119+
if (newPath) {
120+
var sg = MSShapeGroup.shapeWithBezierPath(newPath);
121+
switch (op) {
122+
case ops.SUBTRACT:
123+
return splitAndStylePath(sg, shape1, shape2, op);
124+
break;
125+
case ops.INTERSECT:
126+
return splitAndStylePath(sg, shape2, shape1, op);
127+
break;
128+
}
129+
}
130+
return null;
131+
};
132+
133+
var baseShapeBySubtractingOthers = function baseShapeBySubtractingOthers(selection) {
134+
var shape = selection[0];
135+
var layers = selection.count();
136+
var name = "";
137+
138+
for (var i = layers - 1; i > 0; i--) {
139+
shape = MSShapeGroup.shapeWithBezierPath(shape.pathInFrameWithTransforms().booleanSubtractWith(selection[i].pathInFrameWithTransforms()));
140+
name += (name != "" ? " " + ops.SUBTRACT + " " : "") + selection[i].name();
141+
}
142+
shape.setName(name);
143+
shape.setStyle(selection[0].style());
144+
return shape;
145+
};
146+
147+
var separate = function separate(context) {
148+
var selection = context.selection;
149+
var layers = selection.count();
150+
151+
if (layers >= 2) {
152+
var separatedShapeGroups = [];
153+
154+
var baseShape = baseShapeBySubtractingOthers(selection, layers);
155+
separatedShapeGroups.push(splitAndStylePath(baseShape, selection[0], baseShape, ops.SUBTRACT));
156+
157+
for (var i = 1; i < layers; i++) {
158+
separatedShapeGroups.push(shapeGroupFromOp(selection[i], selection[0], ops.SUBTRACT));
159+
separatedShapeGroups.push(shapeGroupFromOp(selection[0], selection[i], ops.INTERSECT));
160+
selection[i].removeFromParent();
161+
}
162+
separatedShapeGroups = [].concat.apply([], separatedShapeGroups.filter(function (layer) {
163+
return layer;
164+
}));
165+
166+
selection[0].parentGroup().insertLayers_afterLayer(separatedShapeGroups, selection[0]);
167+
context.document.currentPage().changeSelectionBySelectingLayers(separatedShapeGroups);
168+
169+
selection[0].removeFromParent();
170+
} else {
171+
context.document.showMessage("Select more than one shape");
172+
}
173+
};
174+
175+
exports["default"] = separate;
176+
177+
/***/ })
178+
/******/ ]);
179+
if (key === 'default' && typeof exports === 'function') {
180+
exports(context);
181+
} else {
182+
exports[key](context);
183+
}
184+
}
185+
that['onRun'] = __skpm_run.bind(this, 'default')

0 commit comments

Comments
 (0)