@phun-ky/speccer 5.0.0 → 6.0.0

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.
Files changed (74) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dts/browser.d.ts +4 -0
  3. package/dts/enums/area.d.ts +16 -0
  4. package/dts/helpers/dissect/index.d.ts +1 -0
  5. package/dts/helpers/dissect/styles.d.ts +1 -0
  6. package/dts/helpers/typography/index.d.ts +2 -0
  7. package/dts/helpers/typography/position.d.ts +4 -0
  8. package/dts/helpers/typography/template.d.ts +1 -0
  9. package/dts/index.d.ts +53 -0
  10. package/dts/interfaces/global.d.ts +6 -0
  11. package/dts/lib/attributes.d.ts +2 -0
  12. package/dts/lib/classnames.d.ts +4 -0
  13. package/dts/lib/constants.d.ts +3 -0
  14. package/dts/lib/css.d.ts +6 -0
  15. package/dts/lib/debounce.d.ts +3 -0
  16. package/dts/lib/node.d.ts +2 -0
  17. package/dts/lib/number.d.ts +1 -0
  18. package/dts/lib/position.d.ts +6 -0
  19. package/dts/lib/resize.d.ts +1 -0
  20. package/dts/lib/styles.d.ts +2 -0
  21. package/dts/tasks/dissect.d.ts +2 -0
  22. package/dts/tasks/index.d.ts +4 -0
  23. package/dts/tasks/measure.d.ts +1 -0
  24. package/dts/tasks/spec.d.ts +2 -0
  25. package/dts/tasks/typography.d.ts +2 -0
  26. package/dts/types/css.d.ts +19 -0
  27. package/dts/types/speccer.d.ts +5 -0
  28. package/package.json +10 -3
  29. package/speccer.css +16 -19
  30. package/speccer.js +2 -1
  31. package/speccer.js.map +1 -0
  32. package/speccer.min.css +1 -1
  33. package/src/{browser.js → browser.ts} +16 -13
  34. package/src/enums/area.ts +17 -0
  35. package/src/helpers/dissect/index.ts +1 -0
  36. package/src/helpers/dissect/styles.ts +154 -0
  37. package/src/helpers/typography/index.ts +3 -0
  38. package/src/helpers/typography/position.ts +54 -0
  39. package/src/helpers/typography/template.ts +27 -0
  40. package/src/{index.js → index.ts} +17 -17
  41. package/src/interfaces/global.ts +7 -0
  42. package/src/lib/attributes.ts +18 -0
  43. package/src/lib/classnames.ts +43 -0
  44. package/src/lib/{constants.js → constants.ts} +3 -0
  45. package/src/lib/css.ts +45 -0
  46. package/src/lib/debounce.ts +29 -0
  47. package/src/lib/node.ts +8 -0
  48. package/src/lib/number.ts +4 -0
  49. package/src/lib/position.ts +16 -0
  50. package/src/lib/{resize.js → resize.ts} +5 -4
  51. package/src/lib/styles.ts +31 -0
  52. package/src/styles/index.styl +4 -0
  53. package/src/styles/spacing.styl +0 -10
  54. package/src/styles/typography.styl +11 -12
  55. package/src/tasks/dissect.ts +46 -0
  56. package/src/tasks/index.ts +7 -0
  57. package/src/tasks/measure.ts +82 -0
  58. package/src/tasks/spec.ts +170 -0
  59. package/src/tasks/typography.ts +45 -0
  60. package/src/types/css.ts +20 -0
  61. package/src/types/speccer.ts +6 -0
  62. package/tsconfig.json +21 -0
  63. package/tslint.json +23 -0
  64. package/src/dissect.js +0 -211
  65. package/src/lib/attributes.js +0 -13
  66. package/src/lib/classnames.js +0 -37
  67. package/src/lib/css.js +0 -37
  68. package/src/lib/debounce.js +0 -22
  69. package/src/lib/node.js +0 -7
  70. package/src/lib/number.js +0 -4
  71. package/src/lib/styles.js +0 -27
  72. package/src/measure.js +0 -99
  73. package/src/spec.js +0 -214
  74. package/src/typography.js +0 -141
package/speccer.min.css CHANGED
@@ -1 +1 @@
1
- .ph.speccer{--ph-speccer-color-padding:#db6fff66;--ph-speccer-color-padding-hover:#db6fff;--ph-speccer-color-margin:#fff76f66;--ph-speccer-color-margin-hover:#fff76f;--ph-speccer-color-text-light:#fff;--ph-speccer-color-text-dark:#333;--ph-speccer-color-contrast:#ff3aa8;--ph-speccer-spacing-color:var(--ph-speccer-color-contrast);--ph-speccer-measure-color:red;--ph-speccer-pin-color:var(--ph-speccer-color-contrast);--ph-speccer-typography-background-color:#fff;--ph-speccer-typography-color-property:#3f85f2;--ph-speccer-typography-color-text:#57575b;--ph-speccer-typography-color-value:var(--ph-speccer-color-contrast);--ph-speccer-depth-opacity-400:0.4;--ph-speccer-font-family:"Menlo for Powerline","Menlo Regular for Powerline","DejaVu Sans Mono",Consolas,Monaco,"Andale Mono","Ubuntu Mono",monospace;--ph-speccer-font-size:12px;--ph-speccer-line-height:12px;--ph-speccer-pin-size:24px;--ph-speccer-pin-space:48px;--ph-speccer-line-width:1px;--ph-speccer-line-width-negative:-1px;--ph-speccer-measure-size:8px}.ph.speccer,.ph.speccer:after,.ph.speccer:before{box-sizing:border-box;font-family:var(--ph-speccer-font-family)!important;font-size:12px;line-height:12px;pointer-events:none;user-select:none;z-index:99999}.ph.speccer,.ph.speccer.dissection,.ph.speccer:after,.ph.speccer:before{align-items:center;display:flex;justify-content:center;position:absolute}.ph.speccer.dissection{background-color:var(--ph-speccer-pin-color);border-radius:100%;box-sizing:initial;color:var(--ph-speccer-color-text-light);font-family:sans-serif;font-size:16px;font-weight:400;height:var(--ph-speccer-pin-size);line-height:150%;width:var(--ph-speccer-pin-size);z-index:100000}.ph.speccer.dissection:after{background-color:var(--ph-speccer-pin-color);content:"";height:var(--ph-speccer-pin-space);position:absolute;top:100%;width:var(--ph-speccer-line-width);z-index:99999}.ph.speccer.dissection.outline.left:after{height:var(--ph-speccer-line-width);left:100%;top:50%;width:var(--ph-speccer-pin-space)}.ph.speccer.dissection.outline.right:after{height:var(--ph-speccer-line-width);right:100%;top:50%;width:var(--ph-speccer-pin-space)}.ph.speccer.dissection.outline.enclose{background-color:initial;border:var(--ph-speccer-line-width) solid var(--ph-speccer-pin-color);border-radius:0;color:var(--ph-speccer-measure-color)}.ph.speccer.dissection.outline.enclose.right:after{left:calc(100% + var(--ph-speccer-pin-space) + var(--ph-speccer-line-width));right:auto}.ph.speccer.dissection.outline.enclose.right:before{left:100%;right:auto}.ph.speccer.dissection.outline.enclose.left:after{left:calc(var(--ph-speccer-line-width-negative) - var(--ph-speccer-pin-size) - var(--ph-speccer-pin-space));right:auto}.ph.speccer.dissection.outline.enclose.left:before{left:auto;right:100%}.ph.speccer.dissection.outline.enclose.top:after{bottom:auto;top:calc(var(--ph-speccer-line-width-negative) - var(--ph-speccer-pin-size) - var(--ph-speccer-pin-space))}.ph.speccer.dissection.outline.enclose.top:before{bottom:100%;top:auto}.ph.speccer.dissection.outline.enclose.bottom:after{bottom:auto;top:calc(100% + var(--ph-speccer-pin-space) + var(--ph-speccer-line-width))}.ph.speccer.dissection.outline.enclose.bottom:before{bottom:auto;top:100%}.ph.speccer.dissection.outline.full{background-color:initial;border:var(--ph-speccer-line-width) solid var(--ph-speccer-pin-color);border-radius:0;color:var(--ph-speccer-measure-color)}.ph.speccer.dissection.outline.full.right{border-left:none}.ph.speccer.dissection.outline.full.right:after{left:calc(8px + var(--ph-speccer-pin-space))}.ph.speccer.dissection.outline.full.right:before{left:100%}.ph.speccer.dissection.outline.full.left{border-right:none}.ph.speccer.dissection.outline.full.left:after{left:calc(-8px - var(--ph-speccer-pin-space))}.ph.speccer.dissection.outline.full.left:before{right:100%}.ph.speccer.dissection.outline.full.top{border-bottom:none}.ph.speccer.dissection.outline.full.top:after{top:calc(-8px - var(--ph-speccer-pin-space))}.ph.speccer.dissection.outline.full.top:before{bottom:100%}.ph.speccer.dissection.outline.full.bottom{border-top:none}.ph.speccer.dissection.outline.full.bottom:after{top:calc(8px + var(--ph-speccer-pin-space))}.ph.speccer.dissection.outline.full.bottom:before{top:100%}.ph.speccer.dissection.outline.bottom:after{height:var(--ph-speccer-pin-space);right:50%;top:calc(-100% - var(--ph-speccer-pin-space)/2);width:var(--ph-speccer-line-width)}.ph.speccer.dissection.outline.top:after,.ph.speccer.dissection.outline:after{height:var(--ph-speccer-pin-space);right:50%;top:100%;width:var(--ph-speccer-line-width)}[data-anatomy-section]{counter-reset:type}.ph.speccer.dissection.outline.full.left,.ph.speccer.dissection.outline.full.right{width:8px}.ph.speccer.dissection.outline.full.bottom,.ph.speccer.dissection.outline.full.top{height:8px}.ph.speccer.dissection.outline.full.bottom:after,.ph.speccer.dissection.outline.full.left:after,.ph.speccer.dissection.outline.full.right:after,.ph.speccer.dissection.outline.full.top:after{align-items:center;background-color:var(--ph-speccer-pin-color);border-radius:100%;color:var(--ph-speccer-color-text-light);content:attr(data-dissection-counter);display:flex;font-size:16px;height:var(--ph-speccer-pin-size);justify-content:center;line-height:150%;position:absolute;width:var(--ph-speccer-pin-size);z-index:100000}.ph.speccer.dissection.outline.full.left:after,.ph.speccer.dissection.outline.full.right:after{top:50%;transform:translateY(-50%)}.ph.speccer.dissection.outline.full.bottom:after,.ph.speccer.dissection.outline.full.top:after{left:50%;transform:translateX(-50%)}.ph.speccer.dissection.outline.full.bottom:before,.ph.speccer.dissection.outline.full.left:before,.ph.speccer.dissection.outline.full.right:before,.ph.speccer.dissection.outline.full.top:before{background-color:var(--ph-speccer-pin-color);content:"";display:block;position:absolute;z-index:100000}.ph.speccer.dissection.outline.full.left:before,.ph.speccer.dissection.outline.full.right:before{height:var(--ph-speccer-line-width);top:50%;transform:translateY(-50%);width:calc(var(--ph-speccer-pin-space) + var(--ph-speccer-line-width))}.ph.speccer.dissection.outline.full.bottom:before,.ph.speccer.dissection.outline.full.top:before{height:calc(var(--ph-speccer-pin-space) + var(--ph-speccer-line-width));left:50%;transform:translateX(-50%);width:var(--ph-speccer-line-width)}.ph.speccer.dissection.outline.enclose.left,.ph.speccer.dissection.outline.enclose.right{width:8px}.ph.speccer.dissection.outline.enclose.bottom,.ph.speccer.dissection.outline.enclose.top{height:8px}.ph.speccer.dissection.outline.enclose.bottom:after,.ph.speccer.dissection.outline.enclose.left:after,.ph.speccer.dissection.outline.enclose.right:after,.ph.speccer.dissection.outline.enclose.top:after{align-items:center;background-color:var(--ph-speccer-pin-color);border-radius:100%;color:var(--ph-speccer-color-text-light);content:attr(data-dissection-counter);display:flex;font-size:16px;height:var(--ph-speccer-pin-size);justify-content:center;line-height:150%;position:absolute;width:var(--ph-speccer-pin-size);z-index:100000}.ph.speccer.dissection.outline.enclose.left:after,.ph.speccer.dissection.outline.enclose.right:after{top:50%;transform:translateY(-50%)}.ph.speccer.dissection.outline.enclose.bottom:after,.ph.speccer.dissection.outline.enclose.top:after{left:50%;transform:translateX(-50%)}.ph.speccer.dissection.outline.enclose.bottom:before,.ph.speccer.dissection.outline.enclose.left:before,.ph.speccer.dissection.outline.enclose.right:before,.ph.speccer.dissection.outline.enclose.top:before{background-color:var(--ph-speccer-pin-color);content:"";display:block;position:absolute;z-index:100000}.ph.speccer.dissection.outline.enclose.left:before,.ph.speccer.dissection.outline.enclose.right:before{height:var(--ph-speccer-line-width);top:50%;transform:translateY(-50%);width:calc(var(--ph-speccer-pin-space) + var(--ph-speccer-line-width))}.ph.speccer.dissection.outline.enclose.bottom:before,.ph.speccer.dissection.outline.enclose.top:before{height:calc(var(--ph-speccer-pin-space) + var(--ph-speccer-line-width));left:50%;transform:translateX(-50%);width:var(--ph-speccer-line-width)}.ph.speccer.spacing{border:var(--ph-speccer-line-width) solid #0000;pointer-events:auto;transition:none}.ph.speccer.spacing:hover{border:var(--ph-speccer-line-width) solid var(--ph-speccer-color-text-dark)}.is-specced:hover~.ph.speccer.spacing.margin{background-color:var(--ph-speccer-color-margin-hover)}.is-specced:hover~.ph.speccer.spacing.padding{background-color:var(--ph-speccer-color-padding-hover);color:var(--ph-speccer-color-text-light)}.ph.speccer.spacing.margin{background-color:var(--ph-speccer-color-margin);color:var(--ph-speccer-color-text-dark)}.ph.speccer.spacing.padding{background-color:var(--ph-speccer-color-padding);color:var(--ph-speccer-spacing-color)}.ph.speccer.spacing.margin.bottom:after,.ph.speccer.spacing.margin.top:after{border-bottom:var(--ph-speccer-line-width) solid var(--ph-speccer-color-text-dark);border-top:var(--ph-speccer-line-width) solid var(--ph-speccer-color-text-dark);content:"";height:100%;left:40%;position:absolute;transition:none;width:9px}.ph.speccer.spacing.margin.bottom:before,.ph.speccer.spacing.margin.top:before{border-left:var(--ph-speccer-line-width) solid var(--ph-speccer-color-text-dark);content:"";height:100%;left:40%;margin-left:4px;position:absolute;transition:none;width:0}.ph.speccer.spacing.margin.left:after,.ph.speccer.spacing.margin.right:after{border-left:var(--ph-speccer-line-width) solid var(--ph-speccer-color-text-dark);border-right:var(--ph-speccer-line-width) solid var(--ph-speccer-color-text-dark);content:"";height:9px;position:absolute;top:10%;transition:none;width:100%}.ph.speccer.spacing.margin.left:before,.ph.speccer.spacing.margin.right:before{border-top:var(--ph-speccer-line-width) solid var(--ph-speccer-color-text-dark);content:"";height:0;margin-top:4px;position:absolute;top:10%;transition:none;width:100%}.ph.speccer.spacing.padding.bottom:after,.ph.speccer.spacing.padding.top:after{border-bottom:var(--ph-speccer-line-width) solid var(--ph-speccer-spacing-color);border-top:var(--ph-speccer-line-width) solid var(--ph-speccer-spacing-color);content:"";height:100%;left:40%;position:absolute;transition:none;width:9px}.ph.speccer.spacing.padding.bottom:before,.ph.speccer.spacing.padding.top:before{border-left:var(--ph-speccer-line-width) solid var(--ph-speccer-spacing-color);content:"";height:100%;left:40%;margin-left:4px;position:absolute;transition:none;width:0}.ph.speccer.spacing.padding.left:after,.ph.speccer.spacing.padding.right:after{border-left:var(--ph-speccer-line-width) solid var(--ph-speccer-spacing-color);border-right:var(--ph-speccer-line-width) solid var(--ph-speccer-spacing-color);content:"";height:9px;position:absolute;top:10%;transition:none;width:100%}.ph.speccer.spacing.padding.left:before,.ph.speccer.spacing.padding.right:before{border-top:var(--ph-speccer-line-width) solid var(--ph-speccer-spacing-color);content:"";height:0;margin-top:4px;position:absolute;top:10%;transition:none;width:100%}.ph.speccer.typography{background-color:var(--ph-speccer-typography-background-color);color:var(--ph-speccer-typography-color-text);display:block;font-size:12px;line-height:140%;max-width:none;min-width:320px;padding:8px 24px;text-align:left;width:auto}.ph.speccer.typography,.ph.speccer.typography:hover{border:var(--ph-speccer-line-width) solid var(--ph-speccer-pin-color)}.ph.speccer.typography:after{background-color:var(--ph-speccer-pin-color);content:"";display:block;position:absolute}.ph.speccer.typography.left:after,.ph.speccer.typography:after{height:var(--ph-speccer-line-width);left:100%;top:50%;transform:translateY(-50%);width:48px}.ph.speccer.typography.right:after{height:var(--ph-speccer-line-width);left:auto;right:100%;top:50%;transform:translateY(-50%);width:48px}.ph.speccer.typography.top:after{top:100%}.ph.speccer.typography.bottom:after,.ph.speccer.typography.top:after{height:48px;left:50%;right:auto;transform:translateX(-50%);width:var(--ph-speccer-line-width)}.ph.speccer.typography.bottom:after{bottom:100%;top:auto}.ph.speccer.typography .speccer-styles{font-size:12px;line-height:140%;list-style:none;margin:0;padding:0 0 0 1rem;width:100%}.ph.speccer.typography .speccer-styles .property{color:var(--ph-speccer-typography-color-property);font-size:12px;font-weight:400;margin:0;padding:0;text-align:left}.ph.speccer.typography .speccer-styles>li{border:none;color:var(--ph-speccer-typography-color-value);font-size:12px;font-weight:400;list-style:none;margin:0;padding:0;text-align:left}.ph.speccer.measure.width{border:var(--ph-speccer-line-width) solid var(--ph-speccer-measure-color);border-bottom:none;color:var(--ph-speccer-measure-color);height:var(--ph-speccer-measure-size)}.ph.speccer.measure.width:after{content:attr(data-measure);position:absolute;top:calc(-100% - 10px)}.ph.speccer.measure.width.bottom{border:var(--ph-speccer-line-width) solid var(--ph-speccer-measure-color);border-top:none;color:var(--ph-speccer-measure-color)}.ph.speccer.measure.width.bottom:after{content:attr(data-measure);position:absolute;top:calc(100% + 5px)}.ph.speccer.measure.width.top{border:var(--ph-speccer-line-width) solid var(--ph-speccer-measure-color);border-bottom:none;color:var(--ph-speccer-measure-color)}.ph.speccer.measure.width.top:after{bottom:calc(100% + 5px);content:attr(data-measure);position:absolute}.ph.speccer.measure.height.left{border:var(--ph-speccer-line-width) solid var(--ph-speccer-measure-color);border-right:none;color:var(--ph-speccer-measure-color);width:var(--ph-speccer-measure-size)}.ph.speccer.measure.height.left:after{content:attr(data-measure);left:calc(-100% - 20px - var(--ph-speccer-line-width));position:absolute;top:50%;transform:translateY(-50%) rotate(-90deg)}.ph.speccer.measure.height.right{border:var(--ph-speccer-line-width) solid var(--ph-speccer-measure-color);border-left:none;color:var(--ph-speccer-measure-color);width:var(--ph-speccer-measure-size)}.ph.speccer.measure.height.right:after{content:attr(data-measure);left:calc(100% - var(--ph-speccer-measure-size));position:absolute;top:50%;transform:translateY(-50%) rotate(90deg)}
1
+ .ph.speccer{--ph-speccer-color-padding:#db6fff66;--ph-speccer-color-padding-hover:#db6fff;--ph-speccer-color-margin:#fff76f66;--ph-speccer-color-margin-hover:#fff76f;--ph-speccer-color-text-light:#fff;--ph-speccer-color-text-dark:#333;--ph-speccer-color-contrast:#ff3aa8;--ph-speccer-spacing-color:var(--ph-speccer-color-contrast);--ph-speccer-measure-color:red;--ph-speccer-pin-color:var(--ph-speccer-color-contrast);--ph-speccer-typography-background-color:#fff;--ph-speccer-typography-color-property:#3f85f2;--ph-speccer-typography-color-text:#57575b;--ph-speccer-typography-color-value:var(--ph-speccer-color-contrast);--ph-speccer-depth-opacity-400:0.4;--ph-speccer-font-family:"Menlo for Powerline","Menlo Regular for Powerline","DejaVu Sans Mono",Consolas,Monaco,"Andale Mono","Ubuntu Mono",monospace;--ph-speccer-font-size:12px;--ph-speccer-line-height:12px;--ph-speccer-pin-size:24px;--ph-speccer-pin-space:48px;--ph-speccer-line-width:1px;--ph-speccer-line-width-negative:-1px;--ph-speccer-measure-size:8px}body.ph{box-sizing:border-box;margin:12px;padding:12px}.ph.speccer,.ph.speccer:after,.ph.speccer:before{box-sizing:border-box;font-family:var(--ph-speccer-font-family)!important;font-size:12px;line-height:12px;pointer-events:none;user-select:none;z-index:99999}.ph.speccer,.ph.speccer.dissection,.ph.speccer:after,.ph.speccer:before{align-items:center;display:flex;justify-content:center;position:absolute}.ph.speccer.dissection{background-color:var(--ph-speccer-pin-color);border-radius:100%;box-sizing:initial;color:var(--ph-speccer-color-text-light);font-family:sans-serif;font-size:16px;font-weight:400;height:var(--ph-speccer-pin-size);line-height:150%;width:var(--ph-speccer-pin-size);z-index:100000}.ph.speccer.dissection:after{background-color:var(--ph-speccer-pin-color);content:"";height:var(--ph-speccer-pin-space);position:absolute;top:100%;width:var(--ph-speccer-line-width);z-index:99999}.ph.speccer.dissection.outline.left:after{height:var(--ph-speccer-line-width);left:100%;top:50%;width:var(--ph-speccer-pin-space)}.ph.speccer.dissection.outline.right:after{height:var(--ph-speccer-line-width);right:100%;top:50%;width:var(--ph-speccer-pin-space)}.ph.speccer.dissection.outline.enclose{background-color:initial;border:var(--ph-speccer-line-width) solid var(--ph-speccer-pin-color);border-radius:0;color:var(--ph-speccer-measure-color)}.ph.speccer.dissection.outline.enclose.right:after{left:calc(100% + var(--ph-speccer-pin-space) + var(--ph-speccer-line-width));right:auto}.ph.speccer.dissection.outline.enclose.right:before{left:100%;right:auto}.ph.speccer.dissection.outline.enclose.left:after{left:calc(var(--ph-speccer-line-width-negative) - var(--ph-speccer-pin-size) - var(--ph-speccer-pin-space));right:auto}.ph.speccer.dissection.outline.enclose.left:before{left:auto;right:100%}.ph.speccer.dissection.outline.enclose.top:after{bottom:auto;top:calc(var(--ph-speccer-line-width-negative) - var(--ph-speccer-pin-size) - var(--ph-speccer-pin-space))}.ph.speccer.dissection.outline.enclose.top:before{bottom:100%;top:auto}.ph.speccer.dissection.outline.enclose.bottom:after{bottom:auto;top:calc(100% + var(--ph-speccer-pin-space) + var(--ph-speccer-line-width))}.ph.speccer.dissection.outline.enclose.bottom:before{bottom:auto;top:100%}.ph.speccer.dissection.outline.full{background-color:initial;border:var(--ph-speccer-line-width) solid var(--ph-speccer-pin-color);border-radius:0;color:var(--ph-speccer-measure-color)}.ph.speccer.dissection.outline.full.right{border-left:none}.ph.speccer.dissection.outline.full.right:after{left:calc(8px + var(--ph-speccer-pin-space))}.ph.speccer.dissection.outline.full.right:before{left:100%}.ph.speccer.dissection.outline.full.left{border-right:none}.ph.speccer.dissection.outline.full.left:after{left:calc(-8px - var(--ph-speccer-pin-space))}.ph.speccer.dissection.outline.full.left:before{right:100%}.ph.speccer.dissection.outline.full.top{border-bottom:none}.ph.speccer.dissection.outline.full.top:after{top:calc(-8px - var(--ph-speccer-pin-space))}.ph.speccer.dissection.outline.full.top:before{bottom:100%}.ph.speccer.dissection.outline.full.bottom{border-top:none}.ph.speccer.dissection.outline.full.bottom:after{top:calc(8px + var(--ph-speccer-pin-space))}.ph.speccer.dissection.outline.full.bottom:before{top:100%}.ph.speccer.dissection.outline.bottom:after{height:var(--ph-speccer-pin-space);right:50%;top:calc(-100% - var(--ph-speccer-pin-space)/2);width:var(--ph-speccer-line-width)}.ph.speccer.dissection.outline.top:after,.ph.speccer.dissection.outline:after{height:var(--ph-speccer-pin-space);right:50%;top:100%;width:var(--ph-speccer-line-width)}[data-anatomy-section]{counter-reset:type}.ph.speccer.dissection.outline.full.left,.ph.speccer.dissection.outline.full.right{width:8px}.ph.speccer.dissection.outline.full.bottom,.ph.speccer.dissection.outline.full.top{height:8px}.ph.speccer.dissection.outline.full.bottom:after,.ph.speccer.dissection.outline.full.left:after,.ph.speccer.dissection.outline.full.right:after,.ph.speccer.dissection.outline.full.top:after{align-items:center;background-color:var(--ph-speccer-pin-color);border-radius:100%;color:var(--ph-speccer-color-text-light);content:attr(data-dissection-counter);display:flex;font-size:16px;height:var(--ph-speccer-pin-size);justify-content:center;line-height:150%;position:absolute;width:var(--ph-speccer-pin-size);z-index:100000}.ph.speccer.dissection.outline.full.left:after,.ph.speccer.dissection.outline.full.right:after{top:50%;transform:translateY(-50%)}.ph.speccer.dissection.outline.full.bottom:after,.ph.speccer.dissection.outline.full.top:after{left:50%;transform:translateX(-50%)}.ph.speccer.dissection.outline.full.bottom:before,.ph.speccer.dissection.outline.full.left:before,.ph.speccer.dissection.outline.full.right:before,.ph.speccer.dissection.outline.full.top:before{background-color:var(--ph-speccer-pin-color);content:"";display:block;position:absolute;z-index:100000}.ph.speccer.dissection.outline.full.left:before,.ph.speccer.dissection.outline.full.right:before{height:var(--ph-speccer-line-width);top:50%;transform:translateY(-50%);width:calc(var(--ph-speccer-pin-space) + var(--ph-speccer-line-width))}.ph.speccer.dissection.outline.full.bottom:before,.ph.speccer.dissection.outline.full.top:before{height:calc(var(--ph-speccer-pin-space) + var(--ph-speccer-line-width));left:50%;transform:translateX(-50%);width:var(--ph-speccer-line-width)}.ph.speccer.dissection.outline.enclose.left,.ph.speccer.dissection.outline.enclose.right{width:8px}.ph.speccer.dissection.outline.enclose.bottom,.ph.speccer.dissection.outline.enclose.top{height:8px}.ph.speccer.dissection.outline.enclose.bottom:after,.ph.speccer.dissection.outline.enclose.left:after,.ph.speccer.dissection.outline.enclose.right:after,.ph.speccer.dissection.outline.enclose.top:after{align-items:center;background-color:var(--ph-speccer-pin-color);border-radius:100%;color:var(--ph-speccer-color-text-light);content:attr(data-dissection-counter);display:flex;font-size:16px;height:var(--ph-speccer-pin-size);justify-content:center;line-height:150%;position:absolute;width:var(--ph-speccer-pin-size);z-index:100000}.ph.speccer.dissection.outline.enclose.left:after,.ph.speccer.dissection.outline.enclose.right:after{top:50%;transform:translateY(-50%)}.ph.speccer.dissection.outline.enclose.bottom:after,.ph.speccer.dissection.outline.enclose.top:after{left:50%;transform:translateX(-50%)}.ph.speccer.dissection.outline.enclose.bottom:before,.ph.speccer.dissection.outline.enclose.left:before,.ph.speccer.dissection.outline.enclose.right:before,.ph.speccer.dissection.outline.enclose.top:before{background-color:var(--ph-speccer-pin-color);content:"";display:block;position:absolute;z-index:100000}.ph.speccer.dissection.outline.enclose.left:before,.ph.speccer.dissection.outline.enclose.right:before{height:var(--ph-speccer-line-width);top:50%;transform:translateY(-50%);width:calc(var(--ph-speccer-pin-space) + var(--ph-speccer-line-width))}.ph.speccer.dissection.outline.enclose.bottom:before,.ph.speccer.dissection.outline.enclose.top:before{height:calc(var(--ph-speccer-pin-space) + var(--ph-speccer-line-width));left:50%;transform:translateX(-50%);width:var(--ph-speccer-line-width)}.ph.speccer.spacing{border:var(--ph-speccer-line-width) solid #0000;pointer-events:auto;transition:none}.ph.speccer.spacing:hover{border:var(--ph-speccer-line-width) solid var(--ph-speccer-color-text-dark)}.ph.speccer.spacing.margin{background-color:var(--ph-speccer-color-margin);color:var(--ph-speccer-color-text-dark)}.ph.speccer.spacing.padding{background-color:var(--ph-speccer-color-padding);color:var(--ph-speccer-spacing-color)}.ph.speccer.spacing.margin.bottom:after,.ph.speccer.spacing.margin.top:after{border-bottom:var(--ph-speccer-line-width) solid var(--ph-speccer-color-text-dark);border-top:var(--ph-speccer-line-width) solid var(--ph-speccer-color-text-dark);content:"";height:100%;left:40%;position:absolute;transition:none;width:9px}.ph.speccer.spacing.margin.bottom:before,.ph.speccer.spacing.margin.top:before{border-left:var(--ph-speccer-line-width) solid var(--ph-speccer-color-text-dark);content:"";height:100%;left:40%;margin-left:4px;position:absolute;transition:none;width:0}.ph.speccer.spacing.margin.left:after,.ph.speccer.spacing.margin.right:after{border-left:var(--ph-speccer-line-width) solid var(--ph-speccer-color-text-dark);border-right:var(--ph-speccer-line-width) solid var(--ph-speccer-color-text-dark);content:"";height:9px;position:absolute;top:10%;transition:none;width:100%}.ph.speccer.spacing.margin.left:before,.ph.speccer.spacing.margin.right:before{border-top:var(--ph-speccer-line-width) solid var(--ph-speccer-color-text-dark);content:"";height:0;margin-top:4px;position:absolute;top:10%;transition:none;width:100%}.ph.speccer.spacing.padding.bottom:after,.ph.speccer.spacing.padding.top:after{border-bottom:var(--ph-speccer-line-width) solid var(--ph-speccer-spacing-color);border-top:var(--ph-speccer-line-width) solid var(--ph-speccer-spacing-color);content:"";height:100%;left:40%;position:absolute;transition:none;width:9px}.ph.speccer.spacing.padding.bottom:before,.ph.speccer.spacing.padding.top:before{border-left:var(--ph-speccer-line-width) solid var(--ph-speccer-spacing-color);content:"";height:100%;left:40%;margin-left:4px;position:absolute;transition:none;width:0}.ph.speccer.spacing.padding.left:after,.ph.speccer.spacing.padding.right:after{border-left:var(--ph-speccer-line-width) solid var(--ph-speccer-spacing-color);border-right:var(--ph-speccer-line-width) solid var(--ph-speccer-spacing-color);content:"";height:9px;position:absolute;top:10%;transition:none;width:100%}.ph.speccer.spacing.padding.left:before,.ph.speccer.spacing.padding.right:before{border-top:var(--ph-speccer-line-width) solid var(--ph-speccer-spacing-color);content:"";height:0;margin-top:4px;position:absolute;top:10%;transition:none;width:100%}.ph.speccer.typography{background-color:var(--ph-speccer-typography-background-color);color:var(--ph-speccer-typography-color-text);display:block;font-size:10px;line-height:140%;max-width:none;padding:8px;text-align:left;width:auto}.ph.speccer.typography,.ph.speccer.typography:hover{border:var(--ph-speccer-line-width) solid var(--ph-speccer-pin-color)}.ph.speccer.typography:after{background-color:var(--ph-speccer-pin-color);content:"";display:block;position:absolute}.ph.speccer.typography.left:after,.ph.speccer.typography:after{left:100%}.ph.speccer.typography.left:after,.ph.speccer.typography.right:after,.ph.speccer.typography:after{height:var(--ph-speccer-line-width);top:50%;transform:translateY(-50%);width:var(--ph-speccer-pin-space)}.ph.speccer.typography.right:after{left:auto;right:100%}.ph.speccer.typography.top:after{top:100%}.ph.speccer.typography.bottom:after,.ph.speccer.typography.top:after{height:var(--ph-speccer-pin-space);left:50%;right:auto;transform:translateX(-50%);width:var(--ph-speccer-line-width)}.ph.speccer.typography.bottom:after{bottom:100%;top:auto}.ph.speccer.typography .speccer-styles{font-size:10px;line-height:140%;list-style:none;margin:0;padding:0 0 0 8px;width:100%}.ph.speccer.typography .speccer-styles .property{color:var(--ph-speccer-typography-color-property);font-size:10px;font-weight:400;margin:0;padding:0;text-align:left}.ph.speccer.typography .speccer-styles>li{border:none;color:var(--ph-speccer-typography-color-value);font-size:10px;font-weight:400;list-style:none;margin:0;padding:0;text-align:left}.ph.speccer.measure.width{border:var(--ph-speccer-line-width) solid var(--ph-speccer-measure-color);border-bottom:none;color:var(--ph-speccer-measure-color);height:var(--ph-speccer-measure-size)}.ph.speccer.measure.width:after{content:attr(data-measure);position:absolute;top:calc(-100% - 10px)}.ph.speccer.measure.width.bottom{border:var(--ph-speccer-line-width) solid var(--ph-speccer-measure-color);border-top:none;color:var(--ph-speccer-measure-color)}.ph.speccer.measure.width.bottom:after{content:attr(data-measure);position:absolute;top:calc(100% + 5px)}.ph.speccer.measure.width.top{border:var(--ph-speccer-line-width) solid var(--ph-speccer-measure-color);border-bottom:none;color:var(--ph-speccer-measure-color)}.ph.speccer.measure.width.top:after{bottom:calc(100% + 5px);content:attr(data-measure);position:absolute}.ph.speccer.measure.height.left{border:var(--ph-speccer-line-width) solid var(--ph-speccer-measure-color);border-right:none;color:var(--ph-speccer-measure-color);width:var(--ph-speccer-measure-size)}.ph.speccer.measure.height.left:after{content:attr(data-measure);left:calc(-100% - 20px - var(--ph-speccer-line-width));position:absolute;top:50%;transform:translateY(-50%) rotate(-90deg)}.ph.speccer.measure.height.right{border:var(--ph-speccer-line-width) solid var(--ph-speccer-measure-color);border-left:none;color:var(--ph-speccer-measure-color);width:var(--ph-speccer-measure-size)}.ph.speccer.measure.height.right:after{content:attr(data-measure);left:calc(100% - var(--ph-speccer-measure-size));position:absolute;top:50%;transform:translateY(-50%) rotate(90deg)}
@@ -2,13 +2,15 @@
2
2
  'use strict';
3
3
 
4
4
  import * as resize from './lib/resize';
5
- import * as spec from './spec';
6
- import * as measure from './measure';
7
- import * as dissect from './dissect';
5
+ import * as spec from './tasks/spec';
6
+ import * as measure from './tasks/measure';
7
+ import * as dissect from './tasks/dissect';
8
8
 
9
- export const dom = (speccer) => {
9
+ export const dom = (speccer: Function) => {
10
10
  if (document.readyState === 'loading') {
11
- document.addEventListener('DOMContentLoaded', speccer);
11
+ document.addEventListener('DOMContentLoaded', () => {
12
+ speccer();
13
+ });
12
14
  } else {
13
15
  // `DOMContentLoaded` already fired
14
16
  speccer();
@@ -17,9 +19,9 @@ export const dom = (speccer) => {
17
19
 
18
20
  export const lazy = () => {
19
21
  const _spec_observer = new IntersectionObserver((els, observer) => {
20
- els.forEach((el) => {
22
+ els.forEach((el: IntersectionObserverEntry) => {
21
23
  if (el.intersectionRatio > 0) {
22
- spec.element(el.target);
24
+ spec.element(el.target as HTMLElement);
23
25
  observer.unobserve(el.target);
24
26
  }
25
27
  });
@@ -32,7 +34,7 @@ export const lazy = () => {
32
34
  const _measure_observer = new IntersectionObserver((els, observer) => {
33
35
  els.forEach((el) => {
34
36
  if (el.intersectionRatio > 0) {
35
- measure.element(el.target);
37
+ measure.element(el.target as HTMLElement);
36
38
  observer.unobserve(el.target);
37
39
  }
38
40
  });
@@ -58,20 +60,21 @@ export const lazy = () => {
58
60
  });
59
61
  };
60
62
 
61
- export const manual = (speccer) => {
63
+ export const manual = (speccer: Function) => {
62
64
  window.speccer = speccer;
63
65
  };
64
66
 
65
- export const activate = (speccer) => {
67
+ export const activate = (speccer: Function) => {
66
68
  const _script = document.currentScript;
67
69
 
68
70
  if (_script) {
69
71
  const _speccer_script_src = _script.getAttribute('src');
70
72
 
71
73
  if (
72
- _speccer_script_src.indexOf('speccer.js') !== -1 ||
73
- // for codepen
74
- _speccer_script_src.indexOf('JaXpOK.js') !== -1
74
+ _speccer_script_src &&
75
+ (_speccer_script_src.indexOf('speccer.js') !== -1 ||
76
+ // for codepen
77
+ _speccer_script_src.indexOf('JaXpOK.js') !== -1)
75
78
  ) {
76
79
  if (_script.hasAttribute('data-manual')) {
77
80
  manual(speccer);
@@ -0,0 +1,17 @@
1
+ export enum SpeccerAreaEnum {
2
+ Empty = '',
3
+ Left = 'left',
4
+ Right = 'right',
5
+ Bottom = 'bottom',
6
+ Top = 'top',
7
+ }
8
+
9
+ export enum DissectAreaEnum {
10
+ Outline = 'outline',
11
+ Enclose = 'enclose',
12
+ Full = 'full',
13
+ Left = 'left',
14
+ Right = 'right',
15
+ Bottom = 'bottom',
16
+ Top = 'top',
17
+ }
@@ -0,0 +1 @@
1
+ export { styles } from './styles';
@@ -0,0 +1,154 @@
1
+ import * as css from '../../lib/css';
2
+ import * as number from '../../lib/number';
3
+ import { get_body_correction } from '../../lib/position';
4
+ import { get_horizontal_center_of_els, get_vertical_center_of_els } from '../../lib/position';
5
+ import { DissectAreaEnum } from '../../enums/area';
6
+
7
+ export const styles = (area: string, el: HTMLElement, dissectionEl: HTMLElement) => {
8
+ const _el_rect = el.getBoundingClientRect();
9
+ const SPECCER_PIN_SPACE = css.pinSpace(dissectionEl);
10
+ const _dissection_el_rect = dissectionEl.getBoundingClientRect();
11
+ const _body_correction = get_body_correction();
12
+ const _el_offset_top = el.offsetTop + _body_correction.top;
13
+ const _el_offset_left = el.offsetLeft + _body_correction.left;
14
+ const _left_layout_position_left = _el_offset_left - _dissection_el_rect.width - SPECCER_PIN_SPACE + 'px';
15
+ const _left_layout_position_top =
16
+ number.decimal(get_vertical_center_of_els(_el_offset_top, _dissection_el_rect, _el_rect)) + 'px';
17
+ const _right_layout_position_left = _el_offset_left + _el_rect.width + SPECCER_PIN_SPACE + 'px';
18
+ const _right_layout_position_top =
19
+ number.decimal(get_vertical_center_of_els(_el_offset_top, _dissection_el_rect, _el_rect)) + 'px';
20
+ const _top_layout_position_left =
21
+ number.decimal(get_horizontal_center_of_els(_el_offset_left, _dissection_el_rect, _el_rect)) + 'px';
22
+ const _top_layout_position_top = _el_offset_top - _dissection_el_rect.height - SPECCER_PIN_SPACE + 'px';
23
+ const _bottom_layout_position_left =
24
+ number.decimal(get_horizontal_center_of_els(_el_offset_left, _dissection_el_rect, _el_rect)) + 'px';
25
+ const _bottom_layout_position_top = _el_offset_top + _el_rect.height + SPECCER_PIN_SPACE + 'px';
26
+
27
+ let _dissection_styles = {};
28
+
29
+ if (area.indexOf(DissectAreaEnum.Outline) !== -1) {
30
+ if (area.indexOf(DissectAreaEnum.Left) !== -1) {
31
+ if (area.indexOf(DissectAreaEnum.Full) !== -1) {
32
+ _dissection_styles = {
33
+ left: _el_offset_left - 8 + 'px',
34
+ top: _el_offset_top + -1 + 'px',
35
+ height: _el_rect.height + 'px'
36
+ };
37
+ } else if (area.indexOf(DissectAreaEnum.Enclose) !== -1) {
38
+ _dissection_styles = {
39
+ left: _el_offset_left - 1 + 'px',
40
+ top: _el_offset_top + -1 + 'px',
41
+ height: _el_rect.height + 'px',
42
+ width: _el_rect.width + 'px'
43
+ };
44
+ } else {
45
+ _dissection_styles = {
46
+ left: _left_layout_position_left,
47
+ top: _left_layout_position_top
48
+ };
49
+ }
50
+ } else if (area.indexOf(DissectAreaEnum.Right) !== -1) {
51
+ if (area.indexOf(DissectAreaEnum.Full) !== -1) {
52
+ _dissection_styles = {
53
+ left: _el_offset_left + _el_rect.width + 'px',
54
+ top: _el_offset_top + -1 + 'px',
55
+ height: _el_rect.height + 'px'
56
+ };
57
+ } else if (area.indexOf(DissectAreaEnum.Enclose) !== -1) {
58
+ _dissection_styles = {
59
+ left: _el_offset_left + -1 + 'px',
60
+ top: _el_offset_top + -1 + 'px',
61
+ height: _el_rect.height + 'px',
62
+ width: _el_rect.width + 'px'
63
+ };
64
+ } else {
65
+ _dissection_styles = {
66
+ left: _right_layout_position_left,
67
+ top: _right_layout_position_top
68
+ };
69
+ }
70
+ } else if (area.indexOf(DissectAreaEnum.Top) !== -1) {
71
+ if (area.indexOf(DissectAreaEnum.Full) !== -1) {
72
+ _dissection_styles = {
73
+ top: _el_offset_top + -8 + 'px',
74
+ left: _el_offset_left + -1 + 'px',
75
+ width: _el_rect.width + 'px'
76
+ };
77
+ } else if (area.indexOf(DissectAreaEnum.Enclose) !== -1) {
78
+ _dissection_styles = {
79
+ top: _el_offset_top + -1 + 'px',
80
+ left: _el_offset_left + -1 + 'px',
81
+ height: _el_rect.height + 'px',
82
+ width: _el_rect.width + 'px'
83
+ };
84
+ } else {
85
+ _dissection_styles = {
86
+ left: _top_layout_position_left,
87
+ top: _top_layout_position_top
88
+ };
89
+ }
90
+ } else if (area.indexOf(DissectAreaEnum.Bottom) !== -1) {
91
+ if (area.indexOf(DissectAreaEnum.Full) !== -1) {
92
+ _dissection_styles = {
93
+ top: _el_offset_top + _el_rect.height + 'px',
94
+ left: _el_offset_left + -1 + 'px',
95
+ width: _el_rect.width + 'px'
96
+ };
97
+ } else if (area.indexOf(DissectAreaEnum.Enclose) !== -1) {
98
+ _dissection_styles = {
99
+ top: _el_offset_top + -1 + 'px',
100
+ left: _el_offset_left + -1 + 'px',
101
+ height: _el_rect.height + 'px',
102
+ width: _el_rect.width + 'px'
103
+ };
104
+ } else {
105
+ _dissection_styles = {
106
+ left: _bottom_layout_position_left,
107
+ top: _bottom_layout_position_top
108
+ };
109
+ }
110
+ } else {
111
+ if (area.indexOf(DissectAreaEnum.Full) !== -1) {
112
+ _dissection_styles = {
113
+ left: _el_offset_left + _el_rect.width + 'px',
114
+ top: _el_offset_top + 'px',
115
+ height: _el_rect.height + 'px'
116
+ };
117
+ } else if (area.indexOf(DissectAreaEnum.Enclose) !== -1) {
118
+ _dissection_styles = {
119
+ left: _el_offset_left + _el_rect.width + 'px',
120
+ top: _el_offset_top + -1 + 'px',
121
+ height: _el_rect.height + 'px',
122
+ width: _el_rect.width + 'px'
123
+ };
124
+ } else {
125
+ _dissection_styles = {
126
+ left: _left_layout_position_left,
127
+ top: _left_layout_position_top
128
+ };
129
+ }
130
+ }
131
+ } else {
132
+ if (area.indexOf(DissectAreaEnum.Full) !== -1) {
133
+ _dissection_styles = {
134
+ left: _el_offset_left - 8 + 'px',
135
+ top: _el_offset_top + -1 + 'px',
136
+ height: _el_rect.height + 'px'
137
+ };
138
+ } else if (area.indexOf(DissectAreaEnum.Enclose) !== -1) {
139
+ _dissection_styles = {
140
+ left: _el_offset_left - 1 + 'px',
141
+ top: _el_offset_top + -1 + 'px',
142
+ height: _el_rect.height + 'px',
143
+ width: _el_rect.width + 'px'
144
+ };
145
+ } else {
146
+ _dissection_styles = {
147
+ left: _left_layout_position_left,
148
+ top: _left_layout_position_top
149
+ };
150
+ }
151
+ }
152
+
153
+ return _dissection_styles;
154
+ };
@@ -0,0 +1,3 @@
1
+ export { position } from './position';
2
+
3
+ export { template } from './template';
@@ -0,0 +1,54 @@
1
+ import * as css from '../../lib/css';
2
+ import * as number from '../../lib/number';
3
+ import { get_body_correction } from '../../lib/position';
4
+ import { get_horizontal_center_of_els, get_vertical_center_of_els } from '../../lib/position';
5
+ import { SpeccerAreaEnum } from '../../enums/area';
6
+
7
+ export const position = (
8
+ area: string | null,
9
+ el: HTMLElement,
10
+ speccerEl: HTMLElement
11
+ ): { left: string; top: string } => {
12
+ const _el_rect = el.getBoundingClientRect();
13
+ const SPECCER_PIN_SPACE = css.pinSpace(speccerEl);
14
+ const _speccer_el_rect = speccerEl.getBoundingClientRect();
15
+ const _body_correction = get_body_correction();
16
+ const _el_offset_top = el.offsetTop + _body_correction.top;
17
+ const _el_offset_left = el.offsetLeft + _body_correction.left;
18
+ const _left_layout_position_left = _el_offset_left - _speccer_el_rect.width - SPECCER_PIN_SPACE + 'px';
19
+ const _left_layout_position_top =
20
+ number.decimal(get_vertical_center_of_els(_el_offset_top, _speccer_el_rect, _el_rect)) + 'px';
21
+ const _right_layout_position_left = _el_offset_left + _el_rect.width + SPECCER_PIN_SPACE + 'px';
22
+ const _right_layout_position_top =
23
+ number.decimal(get_vertical_center_of_els(_el_offset_top, _speccer_el_rect, _el_rect)) + 'px';
24
+ const _top_layout_position_left =
25
+ number.decimal(get_horizontal_center_of_els(_el_offset_left, _speccer_el_rect, _el_rect)) + 'px';
26
+ const _top_layout_position_top = _el_offset_top - _speccer_el_rect.height - SPECCER_PIN_SPACE + 'px';
27
+ const _bottom_layout_position_left =
28
+ number.decimal(get_horizontal_center_of_els(_el_offset_left, _speccer_el_rect, _el_rect)) + 'px';
29
+ const _bottom_layout_position_top = _el_offset_top + _el_rect.height + SPECCER_PIN_SPACE + 'px';
30
+
31
+ let _position = {
32
+ left: _left_layout_position_left,
33
+ top: _left_layout_position_top
34
+ };
35
+
36
+ if (area && area.indexOf(SpeccerAreaEnum.Right) !== -1) {
37
+ _position = {
38
+ left: _right_layout_position_left,
39
+ top: _right_layout_position_top
40
+ };
41
+ } else if (area && area.indexOf(SpeccerAreaEnum.Top) !== -1) {
42
+ _position = {
43
+ left: _top_layout_position_left,
44
+ top: _top_layout_position_top
45
+ };
46
+ } else if (area && area.indexOf(SpeccerAreaEnum.Bottom) !== -1) {
47
+ _position = {
48
+ left: _bottom_layout_position_left,
49
+ top: _bottom_layout_position_top
50
+ };
51
+ }
52
+
53
+ return _position;
54
+ };
@@ -0,0 +1,27 @@
1
+ import * as css from '../../lib/css';
2
+ import * as styles from '../../lib/styles';
3
+
4
+ export const template = async (el: HTMLElement): Promise<string> => {
5
+ const _el_styles = await styles.get(el);
6
+ const _styles = css.getTypography(_el_styles);
7
+
8
+ return (
9
+ `
10
+ ` +
11
+ 'font-styles: {' +
12
+ '<ul class="speccer-styles">' +
13
+ ` <li><span class="property">font-family:</span> ${_styles['fontFamily']};</li>` +
14
+ ` <li><span class="property">font-size:</span> ${_styles['fontSize']} / ${
15
+ parseInt(_styles['fontSize'], 10) / 16
16
+ }rem;</li>` +
17
+ ` <li><span class="property">font-weight:</span> ${_styles['fontWeight']};</li>` +
18
+ ` <li><span class="property">font-variation-settings:</span> ${_styles['fontVariationSettings']};</li>` +
19
+ ` <li><span class="property">line-height:</span> ${_styles['lineHeight']} / ${
20
+ parseInt(_styles['lineHeight'], 10) / 16
21
+ }rem;</li>` +
22
+ ` <li><span class="property">letter-spacing:</span> ${_styles['letterSpacing']};</li>` +
23
+ ` <li><span class="property">font-style:</span> ${_styles['fontStyle']};</li>` +
24
+ '</ul>' +
25
+ '}'
26
+ );
27
+ };
@@ -1,36 +1,36 @@
1
1
  /* eslint no-console:0 */
2
2
  'use strict';
3
3
 
4
+ import './interfaces/global';
4
5
  import * as __node from './lib/node';
5
- import * as __spacing from './spec';
6
- import * as __dissect from './dissect';
7
- import * as __measure from './measure';
8
- import * as __typography from './typography';
6
+ import * as __spacing from './tasks/spec';
7
+ import * as __dissect from './tasks/dissect';
8
+ import * as __measure from './tasks/measure';
9
+ import * as __typography from './tasks/typography';
9
10
  import * as __browser from './browser';
10
11
 
12
+ export const spacing = __spacing;
13
+
14
+ export const dissect = __dissect;
15
+
16
+ export const measure = __measure;
17
+
18
+ export const typography = __typography;
19
+
11
20
  const speccer = () => {
12
21
  __node.removeAll('.speccer');
13
- __node.removeAll('.dissection');
14
22
 
15
23
  const _els_to_be_specced = document.querySelectorAll('[data-speccer],[data-speccer] *:not(td)');
16
24
  const _els_to_be_measured = document.querySelectorAll('[data-speccer-measure]');
17
25
  const _els_to_be_typography_specced = document.querySelectorAll('[data-speccer-typography]');
18
26
  const _els_to_be_dissected = document.querySelectorAll('[data-anatomy-section] [data-anatomy]');
19
27
 
20
- _els_to_be_specced.forEach(__spacing.element);
21
- _els_to_be_measured.forEach(__measure.element);
22
- _els_to_be_typography_specced.forEach(__typography.element);
23
- _els_to_be_dissected.forEach(__dissect.element);
28
+ _els_to_be_specced.forEach(spacing.element);
29
+ _els_to_be_measured.forEach(measure.element);
30
+ _els_to_be_typography_specced.forEach(typography.element);
31
+ _els_to_be_dissected.forEach(dissect.element);
24
32
  };
25
33
 
26
- export const spacing = __spacing;
27
-
28
- export const dissect = __dissect;
29
-
30
- export const measure = __measure;
31
-
32
- export const typography = __typography;
33
-
34
34
  export default speccer;
35
35
 
36
36
  __browser.activate(speccer);
@@ -0,0 +1,7 @@
1
+ export {};
2
+
3
+ declare global {
4
+ interface Window {
5
+ speccer: any;
6
+ }
7
+ }
@@ -0,0 +1,18 @@
1
+ /* eslint no-console:0 */
2
+ 'use strict';
3
+
4
+ export const set = (el: HTMLElement, attrs: {}) => {
5
+ if (!el) return;
6
+
7
+ if (!attrs) return;
8
+
9
+ Object.keys(attrs).forEach((key) => el.setAttribute(key, attrs[key]));
10
+ };
11
+
12
+ export const remove = (el: HTMLElement, attrs: {}) => {
13
+ if (!el) return;
14
+
15
+ if (!attrs) return;
16
+
17
+ Object.keys(attrs).forEach((key) => el.removeAttribute(key));
18
+ };
@@ -0,0 +1,43 @@
1
+ /* eslint no-console:0 */
2
+ 'use strict';
3
+
4
+ export const set = (el: HTMLElement, cls: string, avoid = 'noop') => {
5
+ if (!el) return;
6
+
7
+ if (!cls || (cls && cls.length === 0)) return;
8
+
9
+ cls
10
+ .trim()
11
+ .split(' ')
12
+ .filter((cl) => cl !== avoid)
13
+ .forEach((cl) => el.classList.add(cl));
14
+ };
15
+
16
+ export const toggle = (el: HTMLElement, cls: string, avoid = 'noop') => {
17
+ if (!el) return;
18
+
19
+ if (!cls || (cls && cls.length === 0)) return;
20
+
21
+ cls
22
+ .trim()
23
+ .split(' ')
24
+ .filter((cl) => cl !== avoid)
25
+ .forEach((cl) => el.classList.toggle(cl));
26
+ };
27
+
28
+ export const remove = (el: HTMLElement, cls: string, avoid = 'noop') => {
29
+ if (!el) return;
30
+
31
+ if (!cls || (cls && cls.length === 0)) return;
32
+
33
+ cls
34
+ .trim()
35
+ .split(' ')
36
+ .filter((cl) => cl !== avoid)
37
+ .forEach((cl) => el.classList.remove(cl));
38
+ };
39
+
40
+ export const cx = (cls: string, cls_obj: {}): string =>
41
+ `${cls} ${Object.keys(cls_obj)
42
+ .filter((classname) => cls_obj[classname])
43
+ .join(' ')}`.trim();
@@ -2,4 +2,7 @@
2
2
  'use strict';
3
3
 
4
4
  export const SPECCER_LITERALS = [...'ABCDEFGHIJKLMNOPQRSTUVWXYZ'];
5
+
5
6
  export const SPECCER_TAGS_TO_AVOID = ['TR', 'TH', 'TD', 'TBODY', 'THEAD', 'TFOOT'];
7
+
8
+ export const SPECCER_DEFAULT_PIN_SPACE = 48;
package/src/lib/css.ts ADDED
@@ -0,0 +1,45 @@
1
+ /* eslint no-console:0 */
2
+ 'use strict';
3
+ import { SPECCER_DEFAULT_PIN_SPACE } from './constants';
4
+ import { SpacingCSSPropertiesType, TypographyCSSPropertiesType } from '../types/css';
5
+
6
+ export const getNumberValue = (value: string): number => parseInt(value, 10);
7
+
8
+ export const normalizeNumberValue = (value: string | number): number => {
9
+ const _value = parseFloat(value + '');
10
+
11
+ return (_value >= 0 && _value < 1) || (_value <= 0 && _value > -1) ? 0 : _value;
12
+ };
13
+
14
+ export const getSpacing = (style: SpacingCSSPropertiesType): SpacingCSSPropertiesType => {
15
+ const { marginTop, marginBottom, marginLeft, marginRight, paddingTop, paddingBottom, paddingLeft, paddingRight } =
16
+ style;
17
+
18
+ return {
19
+ marginTop,
20
+ marginBottom,
21
+ marginLeft,
22
+ marginRight,
23
+ paddingTop,
24
+ paddingBottom,
25
+ paddingLeft,
26
+ paddingRight
27
+ };
28
+ };
29
+
30
+ export const getTypography = (style: TypographyCSSPropertiesType): TypographyCSSPropertiesType => {
31
+ const { lineHeight, letterSpacing, fontFamily, fontSize, fontStyle, fontVariationSettings, fontWeight } = style;
32
+
33
+ return {
34
+ lineHeight,
35
+ letterSpacing,
36
+ fontFamily,
37
+ fontSize,
38
+ fontStyle,
39
+ fontVariationSettings,
40
+ fontWeight
41
+ };
42
+ };
43
+
44
+ export const pinSpace = (el: HTMLElement): number =>
45
+ getNumberValue(getComputedStyle(el).getPropertyValue('--ph-speccer-pin-space')) || SPECCER_DEFAULT_PIN_SPACE;
@@ -0,0 +1,29 @@
1
+ /* eslint no-console:0 */
2
+ 'use strict';
3
+
4
+ export const waitForFrame = () => new Promise(requestAnimationFrame);
5
+
6
+ const debounce = function (func: Function, wait: number, immediate?: boolean): Function {
7
+ let timeout: null | ReturnType<typeof setTimeout>;
8
+
9
+ return function (this: any) {
10
+ const context = this;
11
+ const args = arguments;
12
+ const later = function () {
13
+ timeout = null;
14
+
15
+ if (!immediate) func.apply(context, args);
16
+ };
17
+ const callNow = immediate && !timeout;
18
+
19
+ if (timeout) {
20
+ clearTimeout(timeout);
21
+ }
22
+
23
+ timeout = setTimeout(later, wait);
24
+
25
+ if (callNow) func.apply(context, args);
26
+ };
27
+ };
28
+
29
+ export default debounce;
@@ -0,0 +1,8 @@
1
+ export const after = (el: HTMLElement | null, newSibling: HTMLElement) =>
2
+ el && el.insertAdjacentElement('afterend', newSibling);
3
+
4
+ export const removeAll = (selector: string, el: Document = document) => {
5
+ [].forEach.call(el.querySelectorAll(selector), function (e: HTMLElement) {
6
+ e.remove();
7
+ });
8
+ };
@@ -0,0 +1,4 @@
1
+ /* eslint no-console:0 */
2
+ 'use strict';
3
+
4
+ export const decimal = (number: string | number, decimals = 3): string => parseFloat(number + '').toFixed(decimals);
@@ -0,0 +1,16 @@
1
+ export const get_horizontal_center_of_els = (modifier: number, startRect: DOMRect, targetRect: DOMRect): number =>
2
+ modifier - startRect.width / 2 + targetRect.width / 2;
3
+
4
+ export const get_vertical_center_of_els = (modifier: number, startRect: DOMRect, targetRect: DOMRect): number =>
5
+ modifier - startRect.height / 2 + targetRect.height / 2;
6
+
7
+ export const get_body_correction = () => {
8
+ const _body_style = getComputedStyle(document.body);
9
+ const _body_left_correction = parseInt(_body_style.paddingLeft) + parseInt(_body_style.marginLeft);
10
+ const _body_top_correction = parseInt(_body_style.paddingTop) + parseInt(_body_style.marginTop);
11
+
12
+ return {
13
+ top: _body_top_correction,
14
+ left: _body_left_correction
15
+ };
16
+ };
@@ -3,10 +3,11 @@
3
3
 
4
4
  import debounce from './debounce';
5
5
 
6
- export const activate = speccer => {
7
- const speccerEventFunc = debounce(() => {
8
- speccer();
9
- }, 300);
6
+ export const activate = (speccer: Function) => {
7
+ const speccerEventFunc = () =>
8
+ debounce(() => {
9
+ speccer();
10
+ }, 300);
10
11
 
11
12
  window.removeEventListener('resize', speccerEventFunc);
12
13
  window.addEventListener('resize', speccerEventFunc);