### Bootstrap Development Setup Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/README.md Starts a development server that rebuilds the application on file changes. Ideal for active development. ```bash npm run dev ``` -------------------------------- ### Usage Example Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/os-homedir/readme.md Use the os-homedir package to get the current user's home directory. This example demonstrates the basic import and function call. ```javascript const osHomedir = require('os-homedir'); console.log(osHomedir()); //=> '/Users/sindresorhus' ``` -------------------------------- ### Run Static File Server Example Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/http2/README.md Execute the example static file server script located in the 'example' directory. ```bash $ node ./example/server.js ``` -------------------------------- ### Grunt Connect Server with Default Options Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/grunt-contrib-connect/README.md Start a static web server using all default options by providing an empty configuration object for the target. This is useful for quick setups where default behavior is sufficient. ```js // Project configuration. grunt.initConfig({ connect: { uses_defaults: {} } }); ``` -------------------------------- ### Install serve-static Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/serve-static/README.md Install the serve-static module using npm. ```sh $ npm install serve-static ``` -------------------------------- ### Install to-fast-properties Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/to-fast-properties/readme.md Install the package using npm. ```bash $ npm install --save to-fast-properties ``` -------------------------------- ### Install binary-extensions Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/binary-extensions/readme.md Install the package using npm. ```bash $ npm install binary-extensions ``` -------------------------------- ### Example: Get Header Entries for Popup Menu Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/diagram-js/coverage/lcov-report/lib/features/popup-menu/PopupMenuProvider.js.html Demonstrates how to create header entries for the popup menu. These can include buttons with specific actions and active states. ```javascript PopupMenuProvider.getHeaderEntries = function(element) {}; ``` ```javascript PopupMenuProvider.getHeaderEntries = function(element) { var headerEntries = [{ id: 'my-button', className: 'icon-button', title: 'My button', active: true, action: function() { alert('Button has been clicked'); } }]; return headerEntries; }; ``` -------------------------------- ### Install babel-plugin-syntax-async-functions Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/babel-plugin-syntax-async-functions/README.md Install the plugin using npm. ```sh $ npm install babel-plugin-syntax-async-functions ``` -------------------------------- ### Install serve-index Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/serve-index/README.md Install the serve-index module using npm. ```sh $ npm install serve-index ``` -------------------------------- ### Install process-nextick-args Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/process-nextick-args/readme.md Install the process-nextick-args module using npm. ```bash npm install --save process-nextick-args ``` -------------------------------- ### Install on-finished Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/on-finished/README.md Install the on-finished module using npm. ```sh $ npm install on-finished ``` -------------------------------- ### Install and Build Docs Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/base/node_modules/is-descriptor/README.md Installs the necessary tools globally and then runs the verb command to generate documentation. ```sh $ npm install -g verbose/verb#dev verb-generate-readme && verb ``` -------------------------------- ### Install Portscanner with npm Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/portscanner/README.md Install the portscanner module using npm. This is the initial setup step. ```bash npm install portscanner ``` -------------------------------- ### Get start segment bendpoints Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/diagram-js/coverage/lcov-report/lib/layout/ManhattanLayout.js.html Calculates the bendpoints for the initial segment of a connection, starting from point 'a' towards point 'b'. ```javascript function getStartSegment(a, b, directions) { return getSegmentBendpoints(a, b, directions); } ``` -------------------------------- ### Install pkg-up Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/pkg-up/readme.md Install the pkg-up module using npm. ```bash $ npm install --save pkg-up ``` -------------------------------- ### Example: Get Entries for Popup Menu Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/diagram-js/coverage/lcov-report/lib/features/popup-menu/PopupMenuProvider.js.html Provides an example of how to define entries for the popup menu. Each entry has an id, label, class, and an action. ```javascript PopupMenuProvider.getEntries = function(element) {}; ``` ```javascript PopupMenuProvider.getEntries = function(element) { var entries = [{ id: 'alert', label: 'Alert element ID', className: 'alert', action: function () { alert(element.id); } }]; return entries; } ``` -------------------------------- ### CLI Usage Example Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/browserify-incremental/README.md Demonstrates basic command-line usage with react and output file specification. The second command shows the speed improvement after the initial build. ```bash $ browserifyinc -r react -o output/bundle.js -v 556200 bytes written to output/bundle.js (1.38 seconds) $ browserifyinc -r react -o output/bundle.js -v 556200 bytes written to output/bundle.js (0.13 seconds) ``` -------------------------------- ### Install array-find-index Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/array-find-index/readme.md Install the package using npm. ```bash $ npm install --save array-find-index ``` -------------------------------- ### Install spdx-license-ids Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/spdx-license-ids/README.md Install the spdx-license-ids package using npm. ```bash npm install spdx-license-ids ``` -------------------------------- ### Run Command Line Client Example Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/http2/README.md Use the example command-line client to download a file from the server. The downloaded file is saved to /tmp/server.js. ```bash $ node ./example/client.js 'https://localhost:8080/server.js' >/tmp/server.js ``` -------------------------------- ### Browser HTTP GET Request Example Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/stream-http/README.md Demonstrates how to perform an HTTP GET request in the browser using the stream-http module and handle the response data. ```javascript http.get('/bundle.js', function (res) { var div = document.getElementById('result'); div.innerHTML += 'GET /beep
'; res.on('data', function (buf) { div.innerHTML += buf; }); res.on('end', function () { div.innerHTML += '
__END__'; }) }) ``` -------------------------------- ### Install websocket-extensions Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/websocket-extensions/README.md Install the websocket-extensions library using npm. ```bash $ npm install websocket-extensions ``` -------------------------------- ### Install and Help Command Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/dateformat/Readme.md Installs the dateformat package and shows the help command. ```bash $ npm install dateformat $ dateformat --help ``` -------------------------------- ### Enable Info Level Logging for Example Client Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/http2/README.md Run the example client with 'info' level logging enabled by setting the HTTP2_LOG environment variable. Output is redirected to /dev/null. ```bash $ HTTP2_LOG=info node ./example/client.js 'https://localhost:8080/server.js' >/dev/null ``` -------------------------------- ### Dragging Integration Example Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/diagram-js/coverage/lcov-report/lib/features/dragging/Dragging.js.html Example of integrating the dragging feature into a custom component using event bus listeners for drag start, move, and element clicks to initiate dragging. ```javascript function MyDragComponent(eventBus, dragging) { eventBus.on('mydrag.start', function(event) { console.log('yes, we start dragging'); }); eventBus.on('mydrag.move', function(event) { console.log('canvas local coordinates', event.x, event.y, event.dx, event.dy); // local drag data is passed with the event event.context.foo; // "BAR" // the original mouse event, too event.originalEvent; // MouseEvent(...) }); eventBus.on('element.click', function(event) { dragging.init(event, 'mydrag', { cursor: 'grabbing', data: { context: { foo: "BAR" } } }); }); } ``` -------------------------------- ### Array.find() and Array.findIndex() Examples Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/core-js/README.md Use find() to get the first element that satisfies a provided testing function, and findIndex() to get its index. Returns undefined or -1 if no element is found. ```javascript function isOdd(val){ return val % 2; } [4, 8, 15, 16, 23, 42].find(isOdd); // => 15 [4, 8, 15, 16, 23, 42].findIndex(isOdd); // => 2 [4, 8, 15, 16, 23, 42].find(isNaN); // => undefined [4, 8, 15, 16, 23, 42].findIndex(isNaN); // => -1 ``` -------------------------------- ### Base.js Initialization with Config and Options Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/base/README.md Illustrates initializing a Base instance with both configuration and options objects. ```javascript // initialize with `config` and `options` var app = new Base({isApp: true}, {abc: true}); app.set('foo', 'bar'); // values defined with the given `config` object will be on the root of the instance console.log(app.baz); //=> undefined console.log(app.foo); //=> 'bar' // or use `.get` console.log(app.get('isApp')); //=> true console.log(app.get('foo')); //=> 'bar' // values defined with the given `options` object will be on `app.options console.log(app.options.abc); //=> true ``` -------------------------------- ### Initiating the Simulator Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/hammerjs/tests/manual/simulator.html Calls the function to start the gesture simulation process after all setup is complete. ```javascript startSimulator(); ``` -------------------------------- ### Reflect.ownKeys Example Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/core-js/README.md Demonstrates how to get all own property keys of an object, including Symbols, using Reflect.ownKeys. ```javascript var O = {a: 1}; Object.defineProperty(O, 'b', {value: 2}); O[Symbol('c')] = 3; Reflect.ownKeys(O); // => ['a', 'b', Symbol(c)] ``` -------------------------------- ### Installing and Testing Connect Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/connect/README.md Standard commands to install project dependencies and run the test suite. ```bash npm install npm test ``` -------------------------------- ### Install read-pkg-up Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/read-pkg-up/readme.md Install the read-pkg-up package using npm. ```bash $ npm install --save read-pkg-up ``` -------------------------------- ### Install and Hook Function in Node.js Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/hooker/README.md Install the Hooker module using npm and then hook a function like Math.max to log the number of arguments passed. This example demonstrates basic usage in a Node.js environment. ```javascript var hooker = require('hooker'); hooker.hook(Math, "max", function() { console.log(arguments.length + " arguments passed"); }); Math.max(5, 6, 7) // logs: "3 arguments passed", returns 7 ``` -------------------------------- ### Run CLI Example Source: https://github.com/cpn-io/cpn-js/blob/master/test/angular-tree-component/README.md Run the CLI example to test your code locally. Ensure port 4200 is available before running. ```bash $ npm run example:cli # Wait until webpack finishes and http://localhost:4200 is available $ npm run test:dev ``` -------------------------------- ### Install os-homedir Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/os-homedir/readme.md Install the os-homedir package using npm. ```bash $ npm install --save os-homedir ``` -------------------------------- ### Array.fill() Example Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/core-js/README.md Use fill() to populate an array with a static value from a start index to an end index. ```javascript Array(5).fill(42); // => [42, 42, 42, 42, 42] ``` -------------------------------- ### Build Documentation with verb Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/arr-union/README.md Instructions for installing the verb package and running the documentation build process. ```sh $ npm i verb && npm run docs ``` -------------------------------- ### All Options in Use Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/load-grunt-tasks/readme.md An example showcasing the usage of multiple options simultaneously: pattern, config, scope, and requireResolution. ```javascript require('load-grunt-tasks')(grunt, { pattern: 'grunt-contrib-*', config: '../package.json', scope: 'devDependencies', requireResolution: true }); ``` -------------------------------- ### Symbol.for and Symbol.keyFor Example Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/core-js/README.md Illustrates how to use Symbol.for to create or retrieve a global symbol and Symbol.keyFor to get its key. ```javascript var symbol = Symbol.for('key'); symbol === Symbol.for('key'); // true Symbol.keyFor(symbol); // 'key' ``` -------------------------------- ### Enable Info Level Logging for Example Server Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/http2/README.md Run the example server with 'info' level logging enabled by setting the HTTP2_LOG environment variable. ```bash $ HTTP2_LOG=info node ./example/server.js ``` -------------------------------- ### Make an HTTP/2 Request Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/http2/README.md Example of making a simple HTTP/2 GET request to a specified URL and piping the response to standard output. ```javascript require('http2').get('https://localhost:8080/', function(response) { response.pipe(process.stdout); }); ``` -------------------------------- ### core-js Map Usage Examples Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/core-js/README.md Demonstrates various ways to use the core-js Map, including setting, getting, checking size, and iterating. ```javascript var a = [1]; var map = new Map([['a', 1], [42, 2]]); map.set(a, 3).set(true, 4); console.log(map.size); // => 4 console.log(map.has(a)); // => true console.log(map.has([1])); // => false console.log(map.get(a)); // => 3 map.forEach(function(val, key){ console.log(val); // => 1, 2, 3, 4 console.log(key); // => 'a', 42, [1], true }); map.delete(a); console.log(map.size); // => 3 console.log(map.get(a)); // => undefined console.log(Array.from(map)); // => [['a', 1], [42, 2], [true, 4]] ``` ```javascript var map = new Map([['a', 1], ['b', 2], ['c', 3]]); for(var [key, val] of map){ console.log(key); // => 'a', 'b', 'c' console.log(val); // => 1, 2, 3 } for(var val of map.values())console.log(val); // => 1, 2, 3 for(var key of map.keys())console.log(key); // => 'a', 'b', 'c' for(var [key, val] of map.entries()){ console.log(key); // => 'a', 'b', 'c' console.log(val); // => 1, 2, 3 } ``` -------------------------------- ### Usage Example Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/resolve-pkg/readme.md Demonstrates resolving a package path using `resolve-pkg` and contrasts it with `require.resolve()` when a package lacks a main entry point. ```js const resolvePkg = require('resolve-pkg'); // $ npm install --save-dev grunt-svgmin resolvePkg('grunt-svgmin/tasks', {cwd: __dirname}); //=> '/Users/sindresorhus/unicorn/node_modules/grunt-svgmin/tasks' // fails here as grunt tasks usually don't have a defined main entry point require.resolve('grunt-svgmin/tasks'); //=> Error: Cannot find module 'grunt-svgmin' ``` -------------------------------- ### Object.keys and Object.getPrototypeOf Examples Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/core-js/README.md Illustrates using Object.keys to get an array of an object's own enumerable property names and Object.getPrototypeOf to retrieve its prototype. ```javascript Object.keys('qwe'); // => ['0', '1', '2'] Object.getPrototypeOf('qwe') === String.prototype; // => true ``` -------------------------------- ### Run CLI Example (Windows) Source: https://github.com/cpn-io/cpn-js/blob/master/test/angular-tree-component/README.md Alternative command for Windows users to run the CLI example if the standard command fails. ```bash npm run example:cli:win ``` -------------------------------- ### Get Docking Point Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/diagram-js/coverage/lcov-report/lib/layout/ConnectionDocking.js.html Determines the docking point for a connection on a given shape. It identifies the start or end waypoint based on the dockStart flag. ```javascript ConnectionDocking.prototype.getDockingPoint = function(connection, shape, dockStart) { var waypoints = connection.waypoints, dockingIdx, dockingPoint; dockingIdx = dockStart ? 0 : waypoints.length - 1; dockingPoint = waypoints[dockingIdx]; return { point: dockingPoint, actual: dockingPoint, idx: dockingIdx }; }; ``` -------------------------------- ### Using Base.js Plugins Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/base/README.md Demonstrates how to create and use a simple plugin with a Base instance. ```javascript var base = new Base(); function plugin(base) { // do plugin stuff, in pure JavaScript } // use the plugin base.use(plugin); ``` -------------------------------- ### RANGE Token Example Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/ret/README.md The RANGE token is used within SET tokens to define a character range, specifying the start and end character codes. ```json { "type": ret.types.RANGE, "from": 97, "to": 122, } ``` -------------------------------- ### Create an HTTP/2 Server Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/http2/README.md Example of creating a basic HTTP/2 server that responds with 'Hello world!' to all requests. Requires SSL key and certificate files. ```javascript var options = { key: fs.readFileSync('./example/localhost.key'), cert: fs.readFileSync('./example/localhost.crt') }; require('http2').createServer(options, function(request, response) { response.end('Hello world!'); }).listen(8080); ``` -------------------------------- ### Generate documentation with verb Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/is-extglob/README.md Install verb and verb-generate-readme globally, then run verb to generate the documentation. ```sh $ npm install -g verb verb-generate-readme && verb ``` -------------------------------- ### Lo-Dash-FP/Ramda Integration Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/underscore.string/README.markdown Use underscore.string with functional programming libraries like Ramda or Lo-Dash-FP by installing and requiring underscore.string.fp. This example demonstrates filtering an array of strings. ```javascript var S = require('underscore.string.fp'); var filter = require('lodash-fp').filter; var filter = require('ramda').filter; filter(S.startsWith('.'), [ '.vimrc', 'foo.md', '.zshrc' ]); // => ['.vimrc', '.zshrc'] ``` -------------------------------- ### Set and Map .of and .from Examples Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/core-js/README.md Shows how to create Sets and Maps using the .of and .from static methods, including mapping functions for .from. ```javascript Set.of(1, 2, 3, 2, 1); // => Set {1, 2, 3} Map.from([[1, 2], [3, 4]], ([key, val]) => [key ** 2, val ** 2]); // => Map {1: 4, 9: 16} ``` -------------------------------- ### Get Last Child Node Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/snapdragon-node/README.md Retrieves the last child node in the node's children list. Returns undefined if the node has no children. This example is repeated. ```javascript var foo = new Node({type: 'foo'}); var bar = new Node({type: 'bar'}); var baz = new Node({type: 'baz'}); var qux = new Node({type: 'qux'}); foo.push(bar); foo.push(baz); foo.push(qux); console.log(foo.last.type) // 'qux' ``` -------------------------------- ### core-js WeakMap Usage Examples Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/core-js/README.md Demonstrates core-js WeakMap usage, including setting, getting, and checking for keys, as well as using it for private property storage. ```javascript var a = [1] , b = [2] , c = [3]; var wmap = new WeakMap([[a, 1], [b, 2]]); wmap.set(c, 3).set(b, 4); console.log(wmap.has(a)); // => true console.log(wmap.has([1])); // => false console.log(wmap.get(a)); // => 1 wmap.delete(a); console.log(wmap.get(a)); // => undefined ``` ```javascript // Private properties store: var Person = (function(){ var names = new WeakMap; function Person(name){ names.set(this, name); } Person.prototype.getName = function(){ return names.get(this); }; return Person; })(); var person = new Person('Vasya'); console.log(person.getName()); // => 'Vasya' for(var key in person)console.log(key); // => only 'getName' ``` -------------------------------- ### Component Installation Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/isarray/README.md Install the isarray package using component for front-end projects. ```bash $ component install juliangruber/isarray ``` -------------------------------- ### Example HTML Structure Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/vm-browserify/readme.markdown This HTML sets up the basic structure for the example, including loading jQuery and the bundled JavaScript file. ```html result = ``` -------------------------------- ### Find Closest Parent Element Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/closest/README.md Demonstrates how to use the 'closest' function to find parent elements. The first example checks for the 'html' tag starting from the body. The second checks if the body itself matches the selector when 'checkSelf' is true. The third example shows that searching for 'html' from the documentElement returns null if 'checkSelf' is not explicitly true. ```javascript var closest = require('cosest'); closest(document.body, 'html') === document.documentElement closest(document.body, 'body', true) === document.body closest(document.documentElement, 'html') == null ``` -------------------------------- ### Install verb for building docs Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/map-cache/README.md Install the verb package to generate documentation. ```sh $ npm install verb && npm run docs ``` -------------------------------- ### Usage Example Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/collection-visit/README.md Demonstrates how to use the `visit` function to set properties on a context object. It shows how to handle both individual key-value pairs and object literals for setting data. ```js var visit = require('collection-visit'); var ctx = { data: {}, set: function (key, value) { if (typeof key === 'object') { visit(ctx, 'set', key); } else { ctx.data[key] = value; } } }; ctx.set('a', 'a'); ctx.set('b', 'b'); ctx.set('c', 'c'); ctx.set({d: {e: 'f'}}); console.log(ctx.data); //=> {a: 'a', b: 'b', c: 'c', d: { e: 'f' }}; ``` -------------------------------- ### Get mid segment bendpoints Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/diagram-js/coverage/lcov-report/lib/layout/ManhattanLayout.js.html Calculates the bendpoints for the middle segment(s) of a connection, connecting the end of the start segment to the beginning of the end segment. It adjusts directions based on turn information. ```javascript function getMidSegment(startSegment, endSegment) { var startDirection = startSegment.directions.split(':')[1], endDirection = endSegment.directions.split(':')[0]; if (startSegment.turnNextDirections) { startDirection = startDirection == 'h' ? 'v' : 'h'; } if (endSegment.turnNextDirections) { endDirection = endDirection == 'h' ? 'v' : 'h'; } var directions = startDirection + ':' + endDirection; var bendpoints = getBendpoints( startSegment.waypoints[startSegment.waypoints.length - 1], endSegment.waypoints[0], directions ); return { waypoints: bendpoints, directions: directions }; } ``` -------------------------------- ### Get Cropped Waypoints Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/diagram-js/coverage/lcov-report/lib/layout/CroppingConnectionDocking.js.html Calculates and returns the cropped waypoints for a connection, excluding segments that overlap with the source or target shapes. It uses docking points to determine the start and end of the cropped path. ```javascript CroppingConnectionDocking.prototype.getCroppedWaypoints = function(connection, source, target) { source = source || connection.source; target = target || connection.target; var sourceDocking = this.getDockingPoint(connection, source, true), targetDocking = this.getDockingPoint(connection, target); var croppedWaypoints = connection.waypoints.slice(sourceDocking.idx + 1, targetDocking.idx); croppedWaypoints.unshift(dockingToPoint(sourceDocking)); croppedWaypoints.push(dockingToPoint(targetDocking)); return croppedWaypoints; }; ``` -------------------------------- ### Configure Overlay Defaults Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/diagram-js/coverage/lcov-report/lib/features/overlays/Overlays.js.html Shows how to configure default overlay settings during tool initialization. This example sets default zoom constraints and scaling behavior for all overlays. ```javascript { overlays: { defaults: { show: { minZoom: 0.7, maxZoom: 5.0 }, scale: { min: 1 } } } } ``` -------------------------------- ### Creating a Custom Hash Stream with hash-base Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/hash-base/README.md This example shows how to create a custom hash stream by inheriting from HashBase. It defines a simple XOR sum hash function. Ensure 'hash-base' and 'inherits' are installed. ```javascript const HashBase = require('hash-base') const inherits = require('inherits') // our hash function is XOR sum of all bytes function MyHash () { HashBase.call(this, 1) // in bytes this._sum = 0x00 } inherits(MyHash, HashBase) MyHash.prototype._update = function () { for (let i = 0; i < this._block.length; ++i) this._sum ^= this._block[i] } MyHash.prototype._digest = function () { return this._sum } const data = Buffer.from([ 0x00, 0x42, 0x01 ]) const hash = new MyHash().update(data).digest() console.log(hash) // => 67 ``` -------------------------------- ### Install and Run Benchmarks Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/braces/README.md Commands to install development dependencies and run the benchmark suite for braces.js. ```bash npm i -d && npm benchmark ``` -------------------------------- ### Install Dependencies and Run Tests Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/base/node_modules/is-descriptor/README.md Installs project dependencies and then executes the test suite. ```sh $ npm install && npm test ``` -------------------------------- ### Iterator Helper Functions with core-js Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/core-js/README.md Provides examples of using `core.isIterable`, `core.getIterator`, and `core.getIteratorMethod` to check for iterability, obtain iterators, and get the iterator method for various data types, including the `arguments` object. ```javascript var list = (function(){ return arguments; })(1, 2, 3); console.log(core.isIterable(list)); // true; var iter = core.getIterator(list); console.log(iter.next().value); // 1 console.log(iter.next().value); // 2 console.log(iter.next().value); // 3 console.log(iter.next().value); // undefined core.getIterator({}); // TypeError: [object Object] is not iterable! ``` ```javascript var iterFn = core.getIteratorMethod(list); console.log(typeof iterFn); // 'function' var iter = iterFn.call(list); console.log(iter.next().value); // 1 console.log(iter.next().value); // 2 console.log(iter.next().value); // 3 console.log(iter.next().value); // undefined console.log(core.getIteratorMethod({})); // undefined ``` -------------------------------- ### Create AST Node in Parser Visitor Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/snapdragon-node/README.md Example of creating a new AST node within a snapdragon parser's visitor function. It demonstrates how to get the current position, match a pattern, and return a new node with its position set. ```js var Node = require('snapdragon-node'); var Snapdragon = require('snapdragon'); var snapdragon = new Snapdragon(); // example usage inside a parser visitor function snapdragon.parser.set('foo', function() { // get the current "start" position var pos = this.position(); // returns the match if regex matches the substring // at the current position on `parser.input` var match = this.match(/foo/); if (match) { // call "pos" on the node, to set the start and end // positions, and return the node to push it onto the AST // (snapdragon will push the node onto the correct // nodes array, based on the stack) return pos(new Node({type: 'bar', val: match[0]})); } }); ``` -------------------------------- ### Example using map-visit and object-visit Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/map-visit/README.md Illustrates using `mapVisit` and `visit` for more advanced object manipulation, including simulating event emissions on property assignment. This approach provides greater control over the assignment process. ```js var mapVisit = require('map-visit'); var visit = require('object-visit'); var obj = { data: {}, set: function (key, value) { if (Array.isArray(key)) { mapVisit(obj, 'set', key); } else if (typeof key === 'object') { visit(obj, 'set', key); } else { // simulate an event-emitter console.log('emit', key, value); obj.data[key] = value; } } }; obj.set('a', 'a'); obj.set([{b: 'b'}, {c: 'c'}]); obj.set({d: {e: 'f'}}); obj.set({g: 'h', i: 'j', k: 'l'}); console.log(obj.data); ``` -------------------------------- ### Usage Example: Get and Check typeof Helper Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/babel-helpers/README.md Demonstrates how to import babel-helpers, retrieve a specific helper function (e.g., 'typeof'), and use babel-types to check its nature. This is useful for understanding and manipulating Babel's internal helper functions. ```js import * as helpers from 'babel-helpers'; import * as t from 'babel-types'; const typeofHelper = helpers.get('typeof'); t.isExpressionStatement(typeofHelper); // true ``` -------------------------------- ### Basic Base.js Usage Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/base/README.md A minimal example demonstrating how to instantiate Base and use the set/get methods. ```javascript var Base = require('base'); var app = new Base(); app.set('foo', 'bar'); console.log(app.foo); //=> 'bar' ``` -------------------------------- ### Install send via npm Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/send/README.md Install the send library using the npm install command. ```bash npm install send ``` -------------------------------- ### Basic send Example Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/send/README.md A minimal example demonstrating how to use the 'send' module to serve files based on the request URL's pathname. Requires 'http' and 'parseurl' modules. ```javascript var http = require('http') var parseUrl = require('parseurl') var send = require('send') var server = http.createServer(function onRequest (req, res) { send(req, parseUrl(req).pathname).pipe(res) }) server.listen(3000) ``` -------------------------------- ### Install encodeurl with npm Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/encodeurl/README.md Install the encodeurl module locally using the npm install command. ```sh npm install encodeurl ``` -------------------------------- ### Install core-js Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/core-js/README.md Instructions for installing core-js using npm or bower. ```bash npm i core-js bower install core.js ``` -------------------------------- ### NPM Installation Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/sprintf-js/README.md Shows how to install the sprintf-js library using npm. ```bash npm install sprintf-js ``` -------------------------------- ### Install CoffeeScript Locally Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/coffeescript/README.md Install CoffeeScript locally by cloning the repository and using the 'cake install' command. ```shell git clone https://github.com/jashkenas/coffeescript.git sudo coffeescript/bin/cake install ``` -------------------------------- ### Install etag module Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/etag/README.md Install the etag module using npm. This command installs the package locally in your project. ```sh npm install etag ``` -------------------------------- ### Example Output 1 Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/detective/node_modules/minimist/readme.markdown Demonstrates the output of basic argument parsing with simple flags. ```bash $ node example/parse.js -a beep -b boop { _: [], a: 'beep', b: 'boop' } ``` -------------------------------- ### Install duplexer2 via npm Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/duplexer2/README.md Installs the duplexer2 package using npm. Ensure you have Node.js and npm installed. ```bash $ npm i duplexer2 ``` -------------------------------- ### Install fresh module Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/fresh/README.md Install the fresh module using npm. This command is used for local installation of npm packages. ```bash npm install fresh ``` -------------------------------- ### Install ieee754 Module Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/ieee754/README.md Install the ieee754 module using npm. This command downloads and installs the package into your project's node_modules directory. ```bash npm install ieee754 ``` -------------------------------- ### Install ee-first Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/ee-first/README.md Install the ee-first module using npm. ```sh $ npm install ee-first ``` -------------------------------- ### Install undeclared-identifiers Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/undeclared-identifiers/README.md Install the package using npm. ```bash npm install undeclared-identifiers ``` -------------------------------- ### Install snapdragon with npm Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/snapdragon/README.md Install the snapdragon library using npm. This is the initial step before using the library in your project. ```sh npm install --save snapdragon ``` -------------------------------- ### Install setprototypeof Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/setprototypeof/README.md Install the package using npm. ```bash $ npm install --save setprototypeof ``` -------------------------------- ### Installation with npm Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/balanced-match/README.md Shows the command to install the balanced-match package using npm. ```bash npm install balanced-match ``` -------------------------------- ### Install remove-trailing-separator Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/remove-trailing-separator/readme.md Install the package using npm. ```bash npm install remove-trailing-separator ``` -------------------------------- ### Bower Installation Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/sprintf-js/README.md Shows how to install the sprintf-js library using Bower. ```bash bower install sprintf ``` -------------------------------- ### Install micromatch Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/micromatch/README.md Install micromatch using npm. ```sh npm install --save micromatch ``` -------------------------------- ### Install get-assigned-identifiers Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/get-assigned-identifiers/README.md Install the package using npm. ```bash npm install get-assigned-identifiers ``` -------------------------------- ### Install escape-string-regexp Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/escape-string-regexp/readme.md Install the package using npm. ```bash $ npm install --save escape-string-regexp ``` -------------------------------- ### Create Sample Distribution Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/README.md Builds the sample distribution files located in the 'dist' folder. Execute this command to generate the distribution. ```bash npm run all ``` -------------------------------- ### Basic Dependency Injection Example Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/didi/README.md Demonstrates how to define modules, create an injector, and invoke a function with injected dependencies. Use this to set up your application's dependency graph. ```javascript var Car = function(engine) { this.start = function() { engine.start(); }; }; var createPetrolEngine = function(power) { return { start: function() { console.log('Starting engine with ' + power + 'hp'); } }; }; // a module is just a plain JavaScript object // it is a recipe for the injector, how to instantiate stuff var module = { // if an object asks for 'car', the injector will call new Car(...) to produce it 'car': ['type', Car], // if an object asks for 'engine', the injector will call createPetrolEngine(...) to produce it 'engine': ['factory', createPetrolEngine], // if an object asks for 'power', the injector will give it number 1184 'power': ['value', 1184] // probably Bugatti Veyron }; var di = require('di'); var injector = new di.Injector([module]); injector.invoke(function(car) { car.start(); }); ``` -------------------------------- ### Install babel-plugin-transform-strict-mode Source: https://github.com/cpn-io/cpn-js/blob/master/test/test-diagram-js/node_modules/babel-plugin-transform-strict-mode/README.md Installs the plugin using npm. ```sh npm install --save-dev babel-plugin-transform-strict-mode ```