dom-render 1.0.96 → 1.0.98

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,5 +18,6 @@ export declare class Range implements Iterable<number> {
18
18
  readonly isRange = true;
19
19
  constructor(first: number, last: number, step?: number);
20
20
  [Symbol.iterator](): Iterator<number>;
21
+ map<U>(callbackfn: (value: number, index: number, array: number[]) => U, thisArg?: any): U[];
21
22
  static range(first: number | string, last?: number, step?: number): Range;
22
23
  }
@@ -23,10 +23,22 @@ var RangeIterator = /** @class */ (function () {
23
23
  r = new RangeResult(this._current, false);
24
24
  this._current += this._step;
25
25
  }
26
+ else if (this._first < this._last && this._current === this._last) {
27
+ r = new RangeResult(this._current, false);
28
+ this._current += this._step;
29
+ }
26
30
  else if (this._first > this._last && this._current > this._last) {
27
31
  r = new RangeResult(this._current, false);
28
32
  this._current -= this._step;
29
33
  }
34
+ else if (this._first > this._last && this._current === this._last) {
35
+ r = new RangeResult(this._current, false);
36
+ this._current -= this._step;
37
+ }
38
+ else if (this._current === this._last) {
39
+ r = new RangeResult(this._current, false);
40
+ this._current -= this._step;
41
+ }
30
42
  else {
31
43
  r = new RangeResult(undefined, true);
32
44
  }
@@ -46,6 +58,9 @@ var Range = /** @class */ (function () {
46
58
  Range.prototype[Symbol.iterator] = function () {
47
59
  return new RangeIterator(this.first, this.last, this.step);
48
60
  };
61
+ Range.prototype.map = function (callbackfn, thisArg) {
62
+ return Array.from(this).map(callbackfn);
63
+ };
49
64
  Range.range = function (first, last, step) {
50
65
  if (step === void 0) { step = 1; }
51
66
  if (typeof first === 'number' && last === undefined) {
@@ -5,11 +5,11 @@ import { RawSet } from '../rawsets/RawSet';
5
5
  import { Render } from '../rawsets/Render';
6
6
  import { Attrs } from '../rawsets/Attrs';
7
7
  import { Config } from '../configs/Config';
8
- export type OperatorAround = {
8
+ export interface OperatorAround {
9
9
  beforeAttr?: (value: string | null | undefined, opratorExecutor: OperatorExecuter) => string | null | undefined;
10
10
  before?: (data: any, opratorExecutor: OperatorExecuter) => any;
11
11
  after?: (data: any, opratorExecutor: OperatorExecuter) => void;
12
- };
12
+ }
13
13
  export declare enum ExecuteState {
14
14
  EXECUTE = 0,
15
15
  NO_EXECUTE = 1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dom-render",
3
- "version": "1.0.96",
3
+ "version": "1.0.98",
4
4
  "main": "DomRender.js",
5
5
  "license": "MIT",
6
6
  "description": "html view template engine",
@@ -58,8 +58,8 @@
58
58
  "bundle:watch": "rollup -c -w",
59
59
  "dev:start": "npm run start --workspace=dev",
60
60
  "dev:serve": "npm run serve --workspace=dev",
61
- "npm-build": "npm run build && cp package.json dist && cp .npmignore dist && cp README.MD dist && rm -rf dist/dist/bundle.js.map",
62
- "npm-publish": "npm run npm-build && npm publish ./dist",
61
+ "npm:build": "npm run build && cp package.json dist && cp .npmignore dist && cp README.MD dist && rm -rf dist/dist/bundle.js.map",
62
+ "npm:publish": "npm run npm:build && npm publish ./dist",
63
63
  "tsc": "tsc",
64
64
  "tsc:watch": "rm -rf ./dist && mkdir dist && cp package.json dist && tsc --watch --outDir dist --declarationDir dist --sourceMap true",
65
65
  "test": "jest --detectOpenHandles --forceExit"
@@ -68,9 +68,13 @@ export declare class RawSet {
68
68
  get isConnected(): boolean;
69
69
  getUsingTriggerVariables(config?: Config): Set<string>;
70
70
  render(obj: any, config: Config): Promise<RawSet[]>;
71
- static generateStyleSheetsLocal(): void;
71
+ /**
72
+ * @deprecated
73
+ * @param config
74
+ */
75
+ static generateStyleSheetsLocal(config: Config): void;
72
76
  static generateCSS(id: string, cssRule: CSSRule): void;
73
- static generateStyleTransform(styleBody: string | string[], id: string, styleTagWrap?: boolean): string;
77
+ static generateStyleTransform(styleBody: string | string[], componentKey: string, styleTagWrap?: boolean): string;
74
78
  applyEvent(obj: any, fragment?: DocumentFragment, config?: Config): void;
75
79
  getAttribute(element: Element, attr: string): string | null;
76
80
  getAttributeAndDelete(element: Element, attr: string): string | null;
package/rawsets/RawSet.js CHANGED
@@ -55,6 +55,9 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
55
55
  }
56
56
  return to.concat(ar || Array.prototype.slice.call(from));
57
57
  };
58
+ var __importDefault = (this && this.__importDefault) || function (mod) {
59
+ return (mod && mod.__esModule) ? mod : { "default": mod };
60
+ };
58
61
  Object.defineProperty(exports, "__esModule", { value: true });
59
62
  exports.RawSet = void 0;
60
63
  var RandomUtils_1 = require("../utils/random/RandomUtils");
@@ -82,6 +85,8 @@ var DestroyOptionType_1 = require("./DestroyOptionType");
82
85
  var RawSetType_1 = require("./RawSetType");
83
86
  var DrThisProperty_1 = require("../operators/DrThisProperty");
84
87
  var RawSetOperatorType_1 = require("./RawSetOperatorType");
88
+ var parse_1 = __importDefault(require("../css/parse"));
89
+ var stringify_1 = __importDefault(require("../css/stringify"));
85
90
  var RawSet = /** @class */ (function () {
86
91
  function RawSet(uuid, type, point, fragment, detect, data) {
87
92
  this.uuid = uuid;
@@ -281,7 +286,8 @@ var RawSet = /** @class */ (function () {
281
286
  }
282
287
  });
283
288
  // 중요 style isolation 나중에 :scope로 대체 가능할듯.
284
- RawSet.generateStyleSheetsLocal();
289
+ // 2023.9.4일 없앰 style 처음들어올때 처리하는걸로 바꿈
290
+ // RawSet.generateStyleSheetsLocal(config);
285
291
  for (_1 = 0, onThisComponentSetCallBacks_1 = onThisComponentSetCallBacks; _1 < onThisComponentSetCallBacks_1.length; _1++) {
286
292
  it_1 = onThisComponentSetCallBacks_1[_1];
287
293
  (_q = (_p = it_1.obj) === null || _p === void 0 ? void 0 : _p.onInitRender) === null || _q === void 0 ? void 0 : _q.call(_p);
@@ -331,8 +337,13 @@ var RawSet = /** @class */ (function () {
331
337
  });
332
338
  });
333
339
  };
334
- RawSet.generateStyleSheetsLocal = function () {
335
- Array.from(window.document.styleSheets).filter(function (it) { return it.ownerNode && it.ownerNode instanceof Element && it.ownerNode.hasAttribute('domstyle') && it.ownerNode.getAttribute('id') && !it.ownerNode.getAttribute('completed'); }).forEach(function (it) {
340
+ /**
341
+ * @deprecated
342
+ * @param config
343
+ */
344
+ RawSet.generateStyleSheetsLocal = function (config) {
345
+ // console.log('config.window.document.styleSheets---------', config.window.document.styleSheets);
346
+ Array.from(config.window.document.styleSheets).filter(function (it) { return it.ownerNode && it.ownerNode instanceof Element && it.ownerNode.hasAttribute('domstyle') && it.ownerNode.getAttribute('id') && !it.ownerNode.getAttribute('completed'); }).forEach(function (it) {
336
347
  var _a;
337
348
  var styleElement = it.ownerNode;
338
349
  var split = (_a = styleElement.getAttribute('id')) === null || _a === void 0 ? void 0 : _a.split('-');
@@ -381,13 +392,40 @@ var RawSet = /** @class */ (function () {
381
392
  }
382
393
  };
383
394
  // 중요 스타일 적용 부분
384
- RawSet.generateStyleTransform = function (styleBody, id, styleTagWrap) {
395
+ RawSet.generateStyleTransform = function (styleBody, componentKey, styleTagWrap) {
396
+ var _a;
385
397
  if (styleTagWrap === void 0) { styleTagWrap = true; }
386
398
  if (Array.isArray(styleBody)) {
387
399
  styleBody = styleBody.join('\n');
388
400
  }
401
+ var start = "#".concat(componentKey, "-start");
402
+ var end = "#".concat(componentKey, "-end");
403
+ var before = StringUtils_1.StringUtils.regexExecArrayReplace(styleBody, /(\$\{.*?\}\$)/g, function (data) {
404
+ return "var(--domrender-".concat(data[0], ")");
405
+ });
406
+ var cssobject = (0, parse_1.default)(before);
407
+ (_a = cssobject.stylesheet) === null || _a === void 0 ? void 0 : _a.rules.forEach(function (rule) {
408
+ var _a, _b;
409
+ var isRoot = (_a = rule.selectors) === null || _a === void 0 ? void 0 : _a.find(function (it) { return it.startsWith(':root'); });
410
+ if (rule.type === 'rule' && !isRoot) { // && !!isRoot
411
+ rule.selectors = (_b = rule.selectors) === null || _b === void 0 ? void 0 : _b.map(function (sit) {
412
+ var selectorText = ":is(".concat(start, " ~ *:not(").concat(start, " ~ ").concat(end, " ~ *))");
413
+ if (sit.startsWith('.')) {
414
+ return "".concat(selectorText).concat(sit, ", ").concat(selectorText, " ").concat(sit);
415
+ }
416
+ else {
417
+ var divText = "".concat(start, " ~ ").concat(sit, ":not(").concat(start, " ~ ").concat(end, " ~ *)");
418
+ return "".concat(selectorText, " ").concat(sit, ", ").concat(divText);
419
+ }
420
+ });
421
+ }
422
+ });
423
+ var stringify = (0, stringify_1.default)(cssobject);
424
+ var after = StringUtils_1.StringUtils.regexExecArrayReplace(stringify, /(var\(--domrender-(\$\{.*?\}\$)?\))/g, function (data) {
425
+ return data[2];
426
+ });
389
427
  if (styleTagWrap) {
390
- styleBody = "<style id='".concat(id, "-style' domstyle>").concat(styleBody, "</style>");
428
+ styleBody = "<style id='".concat(componentKey, "-style' domstyle>").concat(after, "</style>");
391
429
  }
392
430
  return styleBody;
393
431
  };
@@ -436,9 +474,8 @@ var RawSet = /** @class */ (function () {
436
474
  // 중요 important
437
475
  RawSet.checkPointCreates = function (element, obj, config) {
438
476
  var _a, _b, _c, _d, _e, _f, _g, _h;
439
- // console.log('start==========')
477
+ // const NodeFilter = (config.window as any).NodeFilter;
440
478
  var thisVariableName = element.__domrender_this_variable_name;
441
- // console.log('checkPointCreates thisVariableName', thisVariableName);
442
479
  var nodeIterator = config.window.document.createNodeIterator(element, NodeFilter.SHOW_ALL, {
443
480
  acceptNode: function (node) {
444
481
  var _a, _b, _c, _d, _e;
@@ -648,18 +685,19 @@ var RawSet = /** @class */ (function () {
648
685
  // let message = it.innerHTML;
649
686
  // })
650
687
  element.querySelectorAll("[".concat(RawSet.DR_PRE_NAME, "]")).forEach(function (it) {
651
- it.innerHTML = it.innerHTML.replace(/this/g, thisRandom);
688
+ it.innerHTML = it.innerHTML.replace(/@this@/g, thisRandom);
652
689
  });
653
690
  element.querySelectorAll("[".concat(RawSet.DR_THIS_NAME, "]")).forEach(function (it) {
654
691
  var message = it.innerHTML;
655
- StringUtils_1.StringUtils.regexExec(/([^(dr\-)])?this(?=.?)/g, message).reverse().forEach(function (it) {
692
+ // StringUtils.regexExec(/([^(dr\-)])?this(?=.?)/g, message).reverse().forEach(it => {
693
+ StringUtils_1.StringUtils.regexExec(/@this@/g, message).reverse().forEach(function (it) {
656
694
  var _a;
657
695
  message = message.substr(0, it.index) + message.substr(it.index).replace(it[0], "".concat((_a = it[1]) !== null && _a !== void 0 ? _a : '').concat(drThis));
658
696
  });
659
697
  it.innerHTML = message;
660
698
  });
661
699
  var message = element.innerHTML;
662
- StringUtils_1.StringUtils.regexExec(/([^(dr\-)])?this(?=.?)/g, message).reverse().forEach(function (it) {
700
+ StringUtils_1.StringUtils.regexExec(/@this@/g, message).reverse().forEach(function (it) {
663
701
  var _a;
664
702
  message = message.substr(0, it.index) + message.substr(it.index).replace(it[0], "".concat((_a = it[1]) !== null && _a !== void 0 ? _a : '').concat(drThis));
665
703
  });
@@ -668,10 +706,10 @@ var RawSet = /** @class */ (function () {
668
706
  };
669
707
  RawSet.drThisDecoding = function (element, thisRandom) {
670
708
  element.querySelectorAll("[".concat(RawSet.DR_PRE_NAME, "]")).forEach(function (it) {
671
- it.innerHTML = it.innerHTML.replace(RegExp(thisRandom, 'g'), 'this');
709
+ it.innerHTML = it.innerHTML.replace(RegExp(thisRandom, 'g'), '@this@');
672
710
  });
673
711
  element.querySelectorAll("[".concat(RawSet.DR_THIS_NAME, "]")).forEach(function (it) {
674
- it.innerHTML = it.innerHTML.replace(RegExp(thisRandom, 'g'), 'this');
712
+ it.innerHTML = it.innerHTML.replace(RegExp(thisRandom, 'g'), '@this@');
675
713
  });
676
714
  };
677
715
  RawSet.drFormOtherMoveAttr = function (element, as, to, config) {
@@ -803,6 +841,8 @@ var RawSet = /** @class */ (function () {
803
841
  n.querySelectorAll(EventManager_1.eventManager.attrNames.map(function (it) { return "[".concat(it, "]"); }).join(',')).forEach(function (it) {
804
842
  it.setAttribute(EventManager_1.EventManager.ownerVariablePathAttrName, 'this');
805
843
  });
844
+ // attribute
845
+ n.getAttributeNames().forEach(function (it) { return n.setAttribute(it, n.getAttribute(it).replace(/#this#/g, drThis)); });
806
846
  thisRandom = this.drThisEncoding(n, drThis);
807
847
  vars = this.drVarEncoding(n, drVarOption);
808
848
  this.drVarDecoding(n, vars);
@@ -852,10 +892,11 @@ var RawSet = /** @class */ (function () {
852
892
  callBack: function (element, obj, rawSet, attrs, config) {
853
893
  var _a, _b, _c, _d, _e, _f, _g;
854
894
  return __awaiter(this, void 0, void 0, function () {
855
- var stylePromises, templatePromise, _h, i_1, it_6, _j, _k, _l, _m, _o, domrenderComponents, componentKey, attribute, renderScript, render, constructor, constructorParam, script, param, instance, i, normalAttrMap, onCreate, createParam, script, applayTemplate, innerHTMLThisRandom, componentName, innerHTMLName, oninit, script, style, data, template_1;
895
+ var componentKey, stylePromises, templatePromise, _h, i_1, it_6, _j, _k, _l, _m, _o, domrenderComponents, attribute, renderScript, render, constructor, constructorParam, script, param, instance, i, normalAttrMap, onCreate, createParam, script, applayTemplate, innerHTMLThisRandom, componentName, innerHTMLName, oninit, script, style, data, template_1;
856
896
  return __generator(this, function (_p) {
857
897
  switch (_p.label) {
858
898
  case 0:
899
+ componentKey = rawSet.uuid;
859
900
  stylePromises = [];
860
901
  if (!(this.template && this.template.startsWith('lazy://'))) return [3 /*break*/, 2];
861
902
  return [4 /*yield*/, fetch(this.template.substring(6))];
@@ -908,7 +949,6 @@ var RawSet = /** @class */ (function () {
908
949
  obj.__domrender_components = {};
909
950
  }
910
951
  domrenderComponents = obj.__domrender_components;
911
- componentKey = rawSet.uuid;
912
952
  attribute = DomUtils_1.DomUtils.getAttributeToObject(element);
913
953
  renderScript = 'var $component = this.__render.component; var $element = this.__render.element; var $router = this.__render.router; var $innerHTML = this.__render.innerHTML; var $attribute = this.__render.attribute; var $creatorMetaData = this.__render.creatorMetaData;';
914
954
  render = Object.freeze({
@@ -1,9 +1,16 @@
1
1
  export declare class StorageUtils {
2
2
  static setLocalStorageItem(k: string, v: string | any, window: Window): void;
3
+ static setSessionStorageItem(k: string, v: string | any, window: Window): void;
3
4
  static getLocalStorageItem(k: string, window: Window): string | null;
5
+ static getSessionStorageItem(k: string, window: Window): string | null;
4
6
  static cutLocalStorageItem(k: string, window: Window): string | null;
7
+ static cutSessionStorageItem(k: string, window: Window): string | null;
5
8
  static removeLocalStorageItem(k: string, window: Window): void;
9
+ static removeSessionStorageItem(k: string, window: Window): void;
6
10
  static getLocalStorageJsonItem<T>(k: string, window: Window): T | undefined;
11
+ static getSessionStorageJsonItem<T>(k: string, window: Window): T | undefined;
7
12
  static cutLocalStorageJsonItem<T>(k: string, window: Window): T | undefined;
13
+ static cutSessionStorageJsonItem<T>(k: string, window: Window): T | undefined;
8
14
  static clearLocalStorage(window: Window): void;
15
+ static clearSessionStorage(window: Window): void;
9
16
  }
@@ -10,17 +10,34 @@ var StorageUtils = /** @class */ (function () {
10
10
  }
11
11
  window.localStorage.setItem(k, v);
12
12
  };
13
+ StorageUtils.setSessionStorageItem = function (k, v, window) {
14
+ if (typeof v === 'object') {
15
+ v = JSON.stringify(v);
16
+ }
17
+ window.sessionStorage.setItem(k, v);
18
+ };
13
19
  StorageUtils.getLocalStorageItem = function (k, window) {
14
20
  return window.localStorage.getItem(k);
15
21
  };
22
+ StorageUtils.getSessionStorageItem = function (k, window) {
23
+ return window.sessionStorage.getItem(k);
24
+ };
16
25
  StorageUtils.cutLocalStorageItem = function (k, window) {
17
26
  var data = StorageUtils.getLocalStorageItem(k, window);
18
27
  StorageUtils.removeLocalStorageItem(k, window);
19
28
  return data;
20
29
  };
30
+ StorageUtils.cutSessionStorageItem = function (k, window) {
31
+ var data = StorageUtils.getSessionStorageItem(k, window);
32
+ StorageUtils.removeSessionStorageItem(k, window);
33
+ return data;
34
+ };
21
35
  StorageUtils.removeLocalStorageItem = function (k, window) {
22
36
  return window.localStorage.removeItem(k);
23
37
  };
38
+ StorageUtils.removeSessionStorageItem = function (k, window) {
39
+ return window.sessionStorage.removeItem(k);
40
+ };
24
41
  StorageUtils.getLocalStorageJsonItem = function (k, window) {
25
42
  var item = window.localStorage.getItem(k);
26
43
  if (item) {
@@ -35,14 +52,36 @@ var StorageUtils = /** @class */ (function () {
35
52
  return undefined;
36
53
  }
37
54
  };
55
+ StorageUtils.getSessionStorageJsonItem = function (k, window) {
56
+ var item = window.sessionStorage.getItem(k);
57
+ if (item) {
58
+ try {
59
+ return JSON.parse(item);
60
+ }
61
+ catch (e) {
62
+ return undefined;
63
+ }
64
+ }
65
+ else {
66
+ return undefined;
67
+ }
68
+ };
38
69
  StorageUtils.cutLocalStorageJsonItem = function (k, window) {
39
70
  var item = StorageUtils.getLocalStorageJsonItem(k, window);
40
71
  StorageUtils.removeLocalStorageItem(k, window);
41
72
  return item;
42
73
  };
74
+ StorageUtils.cutSessionStorageJsonItem = function (k, window) {
75
+ var item = StorageUtils.getSessionStorageJsonItem(k, window);
76
+ StorageUtils.removeSessionStorageItem(k, window);
77
+ return item;
78
+ };
43
79
  StorageUtils.clearLocalStorage = function (window) {
44
80
  window.localStorage.clear();
45
81
  };
82
+ StorageUtils.clearSessionStorage = function (window) {
83
+ window.sessionStorage.clear();
84
+ };
46
85
  return StorageUtils;
47
86
  }());
48
87
  exports.StorageUtils = StorageUtils;
@@ -1,5 +1,6 @@
1
1
  export declare class StringUtils {
2
2
  static deleteEnter(data: string): string;
3
3
  static regexExec(regex: RegExp, text: string): RegExpExecArray[];
4
+ static regexExecArrayReplace(origin: string, regexpExecArrayOrRegex: RegExpExecArray[] | RegExp, replace: string | ((data: RegExpExecArray) => string)): string;
4
5
  static escapeSpecialCharacterRegExp(data: string): string;
5
6
  }
@@ -16,6 +16,23 @@ var StringUtils = /** @class */ (function () {
16
16
  }
17
17
  return usingVars;
18
18
  };
19
+ StringUtils.regexExecArrayReplace = function (origin, regexpExecArrayOrRegex, replace) {
20
+ var regexpExecArrays = Array.isArray(regexpExecArrayOrRegex) ? regexpExecArrayOrRegex : StringUtils.regexExec(regexpExecArrayOrRegex, origin);
21
+ regexpExecArrays.reverse().forEach(function (it) {
22
+ var r = typeof replace === 'string' ? replace : replace(it);
23
+ origin = origin.substr(0, it.index) + origin.substr(it.index).replace(it[0], r);
24
+ });
25
+ return origin;
26
+ };
27
+ // public static regexGroups(regex: RegExp, text: string) {
28
+ // const usingVars = [];
29
+ // let varExec = regex.exec(text)
30
+ // while (varExec) {
31
+ // usingVars.push(varExec)
32
+ // varExec = regex.exec(varExec.input)
33
+ // }
34
+ // return usingVars;
35
+ // }
19
36
  // public static betweenRegexpStr(start: string, end: string, data: string, flag = 'gm') {
20
37
  // const startEspace = StringUtils.escapeSpecialCharacterRegExp(start);
21
38
  // const reg = RegExp(`(${start}(?:(${start})??[^${startEspace}]*?${end}))`,flag);